]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.2-201204172135.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.2-201204172135.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 ddcb70a..32da20d 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 b3b7332..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 @@ -43,7 +47,7 @@ extern void __add_wrong_size(void)
9670 switch (sizeof(*(ptr))) { \
9671 case __X86_CASE_B: \
9672 asm volatile (lock #op "b %b0, %1\n" \
9673 - : "+r" (__ret), "+m" (*(ptr)) \
9674 + : "+q" (__ret), "+m" (*(ptr)) \
9675 : : "memory", "cc"); \
9676 break; \
9677 case __X86_CASE_W: \
9678 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9679 __ret; \
9680 })
9681
9682 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9683 + ({ \
9684 + __typeof__ (*(ptr)) __ret = (arg); \
9685 + switch (sizeof(*(ptr))) { \
9686 + case __X86_CASE_L: \
9687 + asm volatile (lock #op "l %0, %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 + case __X86_CASE_Q: \
9696 + asm volatile (lock #op "q %q0, %1\n" \
9697 + "jno 0f\n" \
9698 + "mov %0,%1\n" \
9699 + "int $4\n0:\n" \
9700 + _ASM_EXTABLE(0b, 0b) \
9701 + : "+r" (__ret), "+m" (*(ptr)) \
9702 + : : "memory", "cc"); \
9703 + break; \
9704 + default: \
9705 + __ ## op ## _check_overflow_wrong_size(); \
9706 + } \
9707 + __ret; \
9708 + })
9709 +
9710 /*
9711 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9712 * Since this is generally used to protect other memory information, we
9713 @@ -167,13 +199,16 @@ extern void __add_wrong_size(void)
9714 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9715 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9716
9717 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9718 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9719 +
9720 #define __add(ptr, inc, lock) \
9721 ({ \
9722 __typeof__ (*(ptr)) __ret = (inc); \
9723 switch (sizeof(*(ptr))) { \
9724 case __X86_CASE_B: \
9725 asm volatile (lock "addb %b1, %0\n" \
9726 - : "+m" (*(ptr)) : "ri" (inc) \
9727 + : "+m" (*(ptr)) : "qi" (inc) \
9728 : "memory", "cc"); \
9729 break; \
9730 case __X86_CASE_W: \
9731 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9732 index 8d67d42..183d0eb 100644
9733 --- a/arch/x86/include/asm/cpufeature.h
9734 +++ b/arch/x86/include/asm/cpufeature.h
9735 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9736 ".section .discard,\"aw\",@progbits\n"
9737 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9738 ".previous\n"
9739 - ".section .altinstr_replacement,\"ax\"\n"
9740 + ".section .altinstr_replacement,\"a\"\n"
9741 "3: movb $1,%0\n"
9742 "4:\n"
9743 ".previous\n"
9744 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9745 index e95822d..a90010e 100644
9746 --- a/arch/x86/include/asm/desc.h
9747 +++ b/arch/x86/include/asm/desc.h
9748 @@ -4,6 +4,7 @@
9749 #include <asm/desc_defs.h>
9750 #include <asm/ldt.h>
9751 #include <asm/mmu.h>
9752 +#include <asm/pgtable.h>
9753
9754 #include <linux/smp.h>
9755
9756 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9757
9758 desc->type = (info->read_exec_only ^ 1) << 1;
9759 desc->type |= info->contents << 2;
9760 + desc->type |= info->seg_not_present ^ 1;
9761
9762 desc->s = 1;
9763 desc->dpl = 0x3;
9764 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9765 }
9766
9767 extern struct desc_ptr idt_descr;
9768 -extern gate_desc idt_table[];
9769 extern struct desc_ptr nmi_idt_descr;
9770 -extern gate_desc nmi_idt_table[];
9771 -
9772 -struct gdt_page {
9773 - struct desc_struct gdt[GDT_ENTRIES];
9774 -} __attribute__((aligned(PAGE_SIZE)));
9775 -
9776 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9777 +extern gate_desc idt_table[256];
9778 +extern gate_desc nmi_idt_table[256];
9779
9780 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9781 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9782 {
9783 - return per_cpu(gdt_page, cpu).gdt;
9784 + return cpu_gdt_table[cpu];
9785 }
9786
9787 #ifdef CONFIG_X86_64
9788 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9789 unsigned long base, unsigned dpl, unsigned flags,
9790 unsigned short seg)
9791 {
9792 - gate->a = (seg << 16) | (base & 0xffff);
9793 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9794 + gate->gate.offset_low = base;
9795 + gate->gate.seg = seg;
9796 + gate->gate.reserved = 0;
9797 + gate->gate.type = type;
9798 + gate->gate.s = 0;
9799 + gate->gate.dpl = dpl;
9800 + gate->gate.p = 1;
9801 + gate->gate.offset_high = base >> 16;
9802 }
9803
9804 #endif
9805 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9806
9807 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9808 {
9809 + pax_open_kernel();
9810 memcpy(&idt[entry], gate, sizeof(*gate));
9811 + pax_close_kernel();
9812 }
9813
9814 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9815 {
9816 + pax_open_kernel();
9817 memcpy(&ldt[entry], desc, 8);
9818 + pax_close_kernel();
9819 }
9820
9821 static inline void
9822 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9823 default: size = sizeof(*gdt); break;
9824 }
9825
9826 + pax_open_kernel();
9827 memcpy(&gdt[entry], desc, size);
9828 + pax_close_kernel();
9829 }
9830
9831 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9832 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9833
9834 static inline void native_load_tr_desc(void)
9835 {
9836 + pax_open_kernel();
9837 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9838 + pax_close_kernel();
9839 }
9840
9841 static inline void native_load_gdt(const struct desc_ptr *dtr)
9842 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9843 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9844 unsigned int i;
9845
9846 + pax_open_kernel();
9847 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9848 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9849 + pax_close_kernel();
9850 }
9851
9852 #define _LDT_empty(info) \
9853 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9854 }
9855
9856 #ifdef CONFIG_X86_64
9857 -static inline void set_nmi_gate(int gate, void *addr)
9858 +static inline void set_nmi_gate(int gate, const void *addr)
9859 {
9860 gate_desc s;
9861
9862 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9863 }
9864 #endif
9865
9866 -static inline void _set_gate(int gate, unsigned type, void *addr,
9867 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9868 unsigned dpl, unsigned ist, unsigned seg)
9869 {
9870 gate_desc s;
9871 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9872 * Pentium F0 0F bugfix can have resulted in the mapped
9873 * IDT being write-protected.
9874 */
9875 -static inline void set_intr_gate(unsigned int n, void *addr)
9876 +static inline void set_intr_gate(unsigned int n, const void *addr)
9877 {
9878 BUG_ON((unsigned)n > 0xFF);
9879 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9880 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9881 /*
9882 * This routine sets up an interrupt gate at directory privilege level 3.
9883 */
9884 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9885 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9886 {
9887 BUG_ON((unsigned)n > 0xFF);
9888 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9889 }
9890
9891 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9892 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9893 {
9894 BUG_ON((unsigned)n > 0xFF);
9895 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9896 }
9897
9898 -static inline void set_trap_gate(unsigned int n, void *addr)
9899 +static inline void set_trap_gate(unsigned int n, const void *addr)
9900 {
9901 BUG_ON((unsigned)n > 0xFF);
9902 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9903 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9904 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9905 {
9906 BUG_ON((unsigned)n > 0xFF);
9907 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9908 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9909 }
9910
9911 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9912 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9913 {
9914 BUG_ON((unsigned)n > 0xFF);
9915 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9916 }
9917
9918 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9919 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9920 {
9921 BUG_ON((unsigned)n > 0xFF);
9922 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9923 }
9924
9925 +#ifdef CONFIG_X86_32
9926 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9927 +{
9928 + struct desc_struct d;
9929 +
9930 + if (likely(limit))
9931 + limit = (limit - 1UL) >> PAGE_SHIFT;
9932 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9933 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9934 +}
9935 +#endif
9936 +
9937 #endif /* _ASM_X86_DESC_H */
9938 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9939 index 278441f..b95a174 100644
9940 --- a/arch/x86/include/asm/desc_defs.h
9941 +++ b/arch/x86/include/asm/desc_defs.h
9942 @@ -31,6 +31,12 @@ struct desc_struct {
9943 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9944 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9945 };
9946 + struct {
9947 + u16 offset_low;
9948 + u16 seg;
9949 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9950 + unsigned offset_high: 16;
9951 + } gate;
9952 };
9953 } __attribute__((packed));
9954
9955 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9956 index 3778256..c5d4fce 100644
9957 --- a/arch/x86/include/asm/e820.h
9958 +++ b/arch/x86/include/asm/e820.h
9959 @@ -69,7 +69,7 @@ struct e820map {
9960 #define ISA_START_ADDRESS 0xa0000
9961 #define ISA_END_ADDRESS 0x100000
9962
9963 -#define BIOS_BEGIN 0x000a0000
9964 +#define BIOS_BEGIN 0x000c0000
9965 #define BIOS_END 0x00100000
9966
9967 #define BIOS_ROM_BASE 0xffe00000
9968 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9969 index 5f962df..7289f09 100644
9970 --- a/arch/x86/include/asm/elf.h
9971 +++ b/arch/x86/include/asm/elf.h
9972 @@ -238,7 +238,25 @@ extern int force_personality32;
9973 the loader. We need to make sure that it is out of the way of the program
9974 that it will "exec", and that there is sufficient room for the brk. */
9975
9976 +#ifdef CONFIG_PAX_SEGMEXEC
9977 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9978 +#else
9979 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9980 +#endif
9981 +
9982 +#ifdef CONFIG_PAX_ASLR
9983 +#ifdef CONFIG_X86_32
9984 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9985 +
9986 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9987 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9988 +#else
9989 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9990 +
9991 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9992 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9993 +#endif
9994 +#endif
9995
9996 /* This yields a mask that user programs can use to figure out what
9997 instruction set this CPU supports. This could be done in user space,
9998 @@ -291,9 +309,7 @@ do { \
9999
10000 #define ARCH_DLINFO \
10001 do { \
10002 - if (vdso_enabled) \
10003 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10004 - (unsigned long)current->mm->context.vdso); \
10005 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10006 } while (0)
10007
10008 #define AT_SYSINFO 32
10009 @@ -304,7 +320,7 @@ do { \
10010
10011 #endif /* !CONFIG_X86_32 */
10012
10013 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10014 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10015
10016 #define VDSO_ENTRY \
10017 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10018 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10019 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10020 #define compat_arch_setup_additional_pages syscall32_setup_pages
10021
10022 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10023 -#define arch_randomize_brk arch_randomize_brk
10024 -
10025 /*
10026 * True on X86_32 or when emulating IA32 on X86_64
10027 */
10028 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10029 index cc70c1c..d96d011 100644
10030 --- a/arch/x86/include/asm/emergency-restart.h
10031 +++ b/arch/x86/include/asm/emergency-restart.h
10032 @@ -15,6 +15,6 @@ enum reboot_type {
10033
10034 extern enum reboot_type reboot_type;
10035
10036 -extern void machine_emergency_restart(void);
10037 +extern void machine_emergency_restart(void) __noreturn;
10038
10039 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10040 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10041 index dbe82a5..c6d8a00 100644
10042 --- a/arch/x86/include/asm/floppy.h
10043 +++ b/arch/x86/include/asm/floppy.h
10044 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10045 }
10046
10047
10048 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10049 static unsigned long vdma_mem_alloc(unsigned long size)
10050 {
10051 return (unsigned long)vmalloc(size);
10052 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10053 index d09bb03..4ea4194 100644
10054 --- a/arch/x86/include/asm/futex.h
10055 +++ b/arch/x86/include/asm/futex.h
10056 @@ -12,16 +12,18 @@
10057 #include <asm/system.h>
10058
10059 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10060 + typecheck(u32 __user *, uaddr); \
10061 asm volatile("1:\t" insn "\n" \
10062 "2:\t.section .fixup,\"ax\"\n" \
10063 "3:\tmov\t%3, %1\n" \
10064 "\tjmp\t2b\n" \
10065 "\t.previous\n" \
10066 _ASM_EXTABLE(1b, 3b) \
10067 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10068 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10069 : "i" (-EFAULT), "0" (oparg), "1" (0))
10070
10071 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10072 + typecheck(u32 __user *, uaddr); \
10073 asm volatile("1:\tmovl %2, %0\n" \
10074 "\tmovl\t%0, %3\n" \
10075 "\t" insn "\n" \
10076 @@ -34,7 +36,7 @@
10077 _ASM_EXTABLE(1b, 4b) \
10078 _ASM_EXTABLE(2b, 4b) \
10079 : "=&a" (oldval), "=&r" (ret), \
10080 - "+m" (*uaddr), "=&r" (tem) \
10081 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10082 : "r" (oparg), "i" (-EFAULT), "1" (0))
10083
10084 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10085 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10086
10087 switch (op) {
10088 case FUTEX_OP_SET:
10089 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10090 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10091 break;
10092 case FUTEX_OP_ADD:
10093 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10094 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10095 uaddr, oparg);
10096 break;
10097 case FUTEX_OP_OR:
10098 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10099 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10100 return -EFAULT;
10101
10102 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10103 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10104 "2:\t.section .fixup, \"ax\"\n"
10105 "3:\tmov %3, %0\n"
10106 "\tjmp 2b\n"
10107 "\t.previous\n"
10108 _ASM_EXTABLE(1b, 3b)
10109 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10110 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10111 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10112 : "memory"
10113 );
10114 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10115 index eb92a6e..b98b2f4 100644
10116 --- a/arch/x86/include/asm/hw_irq.h
10117 +++ b/arch/x86/include/asm/hw_irq.h
10118 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10119 extern void enable_IO_APIC(void);
10120
10121 /* Statistics */
10122 -extern atomic_t irq_err_count;
10123 -extern atomic_t irq_mis_count;
10124 +extern atomic_unchecked_t irq_err_count;
10125 +extern atomic_unchecked_t irq_mis_count;
10126
10127 /* EISA */
10128 extern void eisa_set_level_irq(unsigned int irq);
10129 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10130 index 2479049..3fb9795 100644
10131 --- a/arch/x86/include/asm/i387.h
10132 +++ b/arch/x86/include/asm/i387.h
10133 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10134 {
10135 int err;
10136
10137 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10138 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10139 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10140 +#endif
10141 +
10142 /* See comment in fxsave() below. */
10143 #ifdef CONFIG_AS_FXSAVEQ
10144 asm volatile("1: fxrstorq %[fx]\n\t"
10145 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10146 {
10147 int err;
10148
10149 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10150 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10151 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10152 +#endif
10153 +
10154 /*
10155 * Clear the bytes not touched by the fxsave and reserved
10156 * for the SW usage.
10157 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10158 "emms\n\t" /* clear stack tags */
10159 "fildl %P[addr]", /* set F?P to defined value */
10160 X86_FEATURE_FXSAVE_LEAK,
10161 - [addr] "m" (tsk->thread.fpu.has_fpu));
10162 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10163
10164 return fpu_restore_checking(&tsk->thread.fpu);
10165 }
10166 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10167 static inline bool interrupted_user_mode(void)
10168 {
10169 struct pt_regs *regs = get_irq_regs();
10170 - return regs && user_mode_vm(regs);
10171 + return regs && user_mode(regs);
10172 }
10173
10174 /*
10175 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10176 index d8e8eef..99f81ae 100644
10177 --- a/arch/x86/include/asm/io.h
10178 +++ b/arch/x86/include/asm/io.h
10179 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10180
10181 #include <linux/vmalloc.h>
10182
10183 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10184 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10185 +{
10186 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10187 +}
10188 +
10189 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10190 +{
10191 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10192 +}
10193 +
10194 /*
10195 * Convert a virtual cached pointer to an uncached pointer
10196 */
10197 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10198 index bba3cf8..06bc8da 100644
10199 --- a/arch/x86/include/asm/irqflags.h
10200 +++ b/arch/x86/include/asm/irqflags.h
10201 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10202 sti; \
10203 sysexit
10204
10205 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10206 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10207 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10208 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10209 +
10210 #else
10211 #define INTERRUPT_RETURN iret
10212 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10213 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10214 index 5478825..839e88c 100644
10215 --- a/arch/x86/include/asm/kprobes.h
10216 +++ b/arch/x86/include/asm/kprobes.h
10217 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10218 #define RELATIVEJUMP_SIZE 5
10219 #define RELATIVECALL_OPCODE 0xe8
10220 #define RELATIVE_ADDR_SIZE 4
10221 -#define MAX_STACK_SIZE 64
10222 -#define MIN_STACK_SIZE(ADDR) \
10223 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10224 - THREAD_SIZE - (unsigned long)(ADDR))) \
10225 - ? (MAX_STACK_SIZE) \
10226 - : (((unsigned long)current_thread_info()) + \
10227 - THREAD_SIZE - (unsigned long)(ADDR)))
10228 +#define MAX_STACK_SIZE 64UL
10229 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10230
10231 #define flush_insn_slot(p) do { } while (0)
10232
10233 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10234 index 52d6640..136b3bd 100644
10235 --- a/arch/x86/include/asm/kvm_host.h
10236 +++ b/arch/x86/include/asm/kvm_host.h
10237 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10238 int (*check_intercept)(struct kvm_vcpu *vcpu,
10239 struct x86_instruction_info *info,
10240 enum x86_intercept_stage stage);
10241 -};
10242 +} __do_const;
10243
10244 struct kvm_arch_async_pf {
10245 u32 token;
10246 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10247 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10248
10249 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10250 - const void *val, int bytes);
10251 + const void *val, int bytes) __size_overflow(2);
10252 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10253
10254 extern bool tdp_enabled;
10255 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10256
10257 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10258 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10259 - const u8 *new, int bytes);
10260 + const u8 *new, int bytes) __size_overflow(2);
10261 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10262 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10263 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10264 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10265 index 9cdae5d..300d20f 100644
10266 --- a/arch/x86/include/asm/local.h
10267 +++ b/arch/x86/include/asm/local.h
10268 @@ -18,26 +18,58 @@ typedef struct {
10269
10270 static inline void local_inc(local_t *l)
10271 {
10272 - asm volatile(_ASM_INC "%0"
10273 + asm volatile(_ASM_INC "%0\n"
10274 +
10275 +#ifdef CONFIG_PAX_REFCOUNT
10276 + "jno 0f\n"
10277 + _ASM_DEC "%0\n"
10278 + "int $4\n0:\n"
10279 + _ASM_EXTABLE(0b, 0b)
10280 +#endif
10281 +
10282 : "+m" (l->a.counter));
10283 }
10284
10285 static inline void local_dec(local_t *l)
10286 {
10287 - asm volatile(_ASM_DEC "%0"
10288 + asm volatile(_ASM_DEC "%0\n"
10289 +
10290 +#ifdef CONFIG_PAX_REFCOUNT
10291 + "jno 0f\n"
10292 + _ASM_INC "%0\n"
10293 + "int $4\n0:\n"
10294 + _ASM_EXTABLE(0b, 0b)
10295 +#endif
10296 +
10297 : "+m" (l->a.counter));
10298 }
10299
10300 static inline void local_add(long i, local_t *l)
10301 {
10302 - asm volatile(_ASM_ADD "%1,%0"
10303 + asm volatile(_ASM_ADD "%1,%0\n"
10304 +
10305 +#ifdef CONFIG_PAX_REFCOUNT
10306 + "jno 0f\n"
10307 + _ASM_SUB "%1,%0\n"
10308 + "int $4\n0:\n"
10309 + _ASM_EXTABLE(0b, 0b)
10310 +#endif
10311 +
10312 : "+m" (l->a.counter)
10313 : "ir" (i));
10314 }
10315
10316 static inline void local_sub(long i, local_t *l)
10317 {
10318 - asm volatile(_ASM_SUB "%1,%0"
10319 + asm volatile(_ASM_SUB "%1,%0\n"
10320 +
10321 +#ifdef CONFIG_PAX_REFCOUNT
10322 + "jno 0f\n"
10323 + _ASM_ADD "%1,%0\n"
10324 + "int $4\n0:\n"
10325 + _ASM_EXTABLE(0b, 0b)
10326 +#endif
10327 +
10328 : "+m" (l->a.counter)
10329 : "ir" (i));
10330 }
10331 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10332 {
10333 unsigned char c;
10334
10335 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10336 + asm volatile(_ASM_SUB "%2,%0\n"
10337 +
10338 +#ifdef CONFIG_PAX_REFCOUNT
10339 + "jno 0f\n"
10340 + _ASM_ADD "%2,%0\n"
10341 + "int $4\n0:\n"
10342 + _ASM_EXTABLE(0b, 0b)
10343 +#endif
10344 +
10345 + "sete %1\n"
10346 : "+m" (l->a.counter), "=qm" (c)
10347 : "ir" (i) : "memory");
10348 return c;
10349 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10350 {
10351 unsigned char c;
10352
10353 - asm volatile(_ASM_DEC "%0; sete %1"
10354 + asm volatile(_ASM_DEC "%0\n"
10355 +
10356 +#ifdef CONFIG_PAX_REFCOUNT
10357 + "jno 0f\n"
10358 + _ASM_INC "%0\n"
10359 + "int $4\n0:\n"
10360 + _ASM_EXTABLE(0b, 0b)
10361 +#endif
10362 +
10363 + "sete %1\n"
10364 : "+m" (l->a.counter), "=qm" (c)
10365 : : "memory");
10366 return c != 0;
10367 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10368 {
10369 unsigned char c;
10370
10371 - asm volatile(_ASM_INC "%0; sete %1"
10372 + asm volatile(_ASM_INC "%0\n"
10373 +
10374 +#ifdef CONFIG_PAX_REFCOUNT
10375 + "jno 0f\n"
10376 + _ASM_DEC "%0\n"
10377 + "int $4\n0:\n"
10378 + _ASM_EXTABLE(0b, 0b)
10379 +#endif
10380 +
10381 + "sete %1\n"
10382 : "+m" (l->a.counter), "=qm" (c)
10383 : : "memory");
10384 return c != 0;
10385 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10386 {
10387 unsigned char c;
10388
10389 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10390 + asm volatile(_ASM_ADD "%2,%0\n"
10391 +
10392 +#ifdef CONFIG_PAX_REFCOUNT
10393 + "jno 0f\n"
10394 + _ASM_SUB "%2,%0\n"
10395 + "int $4\n0:\n"
10396 + _ASM_EXTABLE(0b, 0b)
10397 +#endif
10398 +
10399 + "sets %1\n"
10400 : "+m" (l->a.counter), "=qm" (c)
10401 : "ir" (i) : "memory");
10402 return c;
10403 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10404 #endif
10405 /* Modern 486+ processor */
10406 __i = i;
10407 - asm volatile(_ASM_XADD "%0, %1;"
10408 + asm volatile(_ASM_XADD "%0, %1\n"
10409 +
10410 +#ifdef CONFIG_PAX_REFCOUNT
10411 + "jno 0f\n"
10412 + _ASM_MOV "%0,%1\n"
10413 + "int $4\n0:\n"
10414 + _ASM_EXTABLE(0b, 0b)
10415 +#endif
10416 +
10417 : "+r" (i), "+m" (l->a.counter)
10418 : : "memory");
10419 return i + __i;
10420 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10421 index 593e51d..fa69c9a 100644
10422 --- a/arch/x86/include/asm/mman.h
10423 +++ b/arch/x86/include/asm/mman.h
10424 @@ -5,4 +5,14 @@
10425
10426 #include <asm-generic/mman.h>
10427
10428 +#ifdef __KERNEL__
10429 +#ifndef __ASSEMBLY__
10430 +#ifdef CONFIG_X86_32
10431 +#define arch_mmap_check i386_mmap_check
10432 +int i386_mmap_check(unsigned long addr, unsigned long len,
10433 + unsigned long flags);
10434 +#endif
10435 +#endif
10436 +#endif
10437 +
10438 #endif /* _ASM_X86_MMAN_H */
10439 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10440 index 5f55e69..e20bfb1 100644
10441 --- a/arch/x86/include/asm/mmu.h
10442 +++ b/arch/x86/include/asm/mmu.h
10443 @@ -9,7 +9,7 @@
10444 * we put the segment information here.
10445 */
10446 typedef struct {
10447 - void *ldt;
10448 + struct desc_struct *ldt;
10449 int size;
10450
10451 #ifdef CONFIG_X86_64
10452 @@ -18,7 +18,19 @@ typedef struct {
10453 #endif
10454
10455 struct mutex lock;
10456 - void *vdso;
10457 + unsigned long vdso;
10458 +
10459 +#ifdef CONFIG_X86_32
10460 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10461 + unsigned long user_cs_base;
10462 + unsigned long user_cs_limit;
10463 +
10464 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10465 + cpumask_t cpu_user_cs_mask;
10466 +#endif
10467 +
10468 +#endif
10469 +#endif
10470 } mm_context_t;
10471
10472 #ifdef CONFIG_SMP
10473 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10474 index 6902152..399f3a2 100644
10475 --- a/arch/x86/include/asm/mmu_context.h
10476 +++ b/arch/x86/include/asm/mmu_context.h
10477 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10478
10479 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10480 {
10481 +
10482 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10483 + unsigned int i;
10484 + pgd_t *pgd;
10485 +
10486 + pax_open_kernel();
10487 + pgd = get_cpu_pgd(smp_processor_id());
10488 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10489 + set_pgd_batched(pgd+i, native_make_pgd(0));
10490 + pax_close_kernel();
10491 +#endif
10492 +
10493 #ifdef CONFIG_SMP
10494 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10495 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10496 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10497 struct task_struct *tsk)
10498 {
10499 unsigned cpu = smp_processor_id();
10500 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10501 + int tlbstate = TLBSTATE_OK;
10502 +#endif
10503
10504 if (likely(prev != next)) {
10505 #ifdef CONFIG_SMP
10506 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10507 + tlbstate = percpu_read(cpu_tlbstate.state);
10508 +#endif
10509 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10510 percpu_write(cpu_tlbstate.active_mm, next);
10511 #endif
10512 cpumask_set_cpu(cpu, mm_cpumask(next));
10513
10514 /* Re-load page tables */
10515 +#ifdef CONFIG_PAX_PER_CPU_PGD
10516 + pax_open_kernel();
10517 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10518 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10519 + pax_close_kernel();
10520 + load_cr3(get_cpu_pgd(cpu));
10521 +#else
10522 load_cr3(next->pgd);
10523 +#endif
10524
10525 /* stop flush ipis for the previous mm */
10526 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10527 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10528 */
10529 if (unlikely(prev->context.ldt != next->context.ldt))
10530 load_LDT_nolock(&next->context);
10531 - }
10532 +
10533 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10534 + if (!(__supported_pte_mask & _PAGE_NX)) {
10535 + smp_mb__before_clear_bit();
10536 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10537 + smp_mb__after_clear_bit();
10538 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10539 + }
10540 +#endif
10541 +
10542 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10543 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10544 + prev->context.user_cs_limit != next->context.user_cs_limit))
10545 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10546 #ifdef CONFIG_SMP
10547 + else if (unlikely(tlbstate != TLBSTATE_OK))
10548 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10549 +#endif
10550 +#endif
10551 +
10552 + }
10553 else {
10554 +
10555 +#ifdef CONFIG_PAX_PER_CPU_PGD
10556 + pax_open_kernel();
10557 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10558 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10559 + pax_close_kernel();
10560 + load_cr3(get_cpu_pgd(cpu));
10561 +#endif
10562 +
10563 +#ifdef CONFIG_SMP
10564 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10565 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10566
10567 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10568 * tlb flush IPI delivery. We must reload CR3
10569 * to make sure to use no freed page tables.
10570 */
10571 +
10572 +#ifndef CONFIG_PAX_PER_CPU_PGD
10573 load_cr3(next->pgd);
10574 +#endif
10575 +
10576 load_LDT_nolock(&next->context);
10577 +
10578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10579 + if (!(__supported_pte_mask & _PAGE_NX))
10580 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10581 +#endif
10582 +
10583 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10584 +#ifdef CONFIG_PAX_PAGEEXEC
10585 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10586 +#endif
10587 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10588 +#endif
10589 +
10590 }
10591 +#endif
10592 }
10593 -#endif
10594 }
10595
10596 #define activate_mm(prev, next) \
10597 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10598 index 9eae775..c914fea 100644
10599 --- a/arch/x86/include/asm/module.h
10600 +++ b/arch/x86/include/asm/module.h
10601 @@ -5,6 +5,7 @@
10602
10603 #ifdef CONFIG_X86_64
10604 /* X86_64 does not define MODULE_PROC_FAMILY */
10605 +#define MODULE_PROC_FAMILY ""
10606 #elif defined CONFIG_M386
10607 #define MODULE_PROC_FAMILY "386 "
10608 #elif defined CONFIG_M486
10609 @@ -59,8 +60,20 @@
10610 #error unknown processor family
10611 #endif
10612
10613 -#ifdef CONFIG_X86_32
10614 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10615 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10616 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10617 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10618 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10619 +#else
10620 +#define MODULE_PAX_KERNEXEC ""
10621 #endif
10622
10623 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10624 +#define MODULE_PAX_UDEREF "UDEREF "
10625 +#else
10626 +#define MODULE_PAX_UDEREF ""
10627 +#endif
10628 +
10629 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10630 +
10631 #endif /* _ASM_X86_MODULE_H */
10632 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10633 index 7639dbf..e08a58c 100644
10634 --- a/arch/x86/include/asm/page_64_types.h
10635 +++ b/arch/x86/include/asm/page_64_types.h
10636 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10637
10638 /* duplicated to the one in bootmem.h */
10639 extern unsigned long max_pfn;
10640 -extern unsigned long phys_base;
10641 +extern const unsigned long phys_base;
10642
10643 extern unsigned long __phys_addr(unsigned long);
10644 #define __phys_reloc_hide(x) (x)
10645 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10646 index a7d2db9..edb023e 100644
10647 --- a/arch/x86/include/asm/paravirt.h
10648 +++ b/arch/x86/include/asm/paravirt.h
10649 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10650 val);
10651 }
10652
10653 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10654 +{
10655 + pgdval_t val = native_pgd_val(pgd);
10656 +
10657 + if (sizeof(pgdval_t) > sizeof(long))
10658 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10659 + val, (u64)val >> 32);
10660 + else
10661 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10662 + val);
10663 +}
10664 +
10665 static inline void pgd_clear(pgd_t *pgdp)
10666 {
10667 set_pgd(pgdp, __pgd(0));
10668 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10669 pv_mmu_ops.set_fixmap(idx, phys, flags);
10670 }
10671
10672 +#ifdef CONFIG_PAX_KERNEXEC
10673 +static inline unsigned long pax_open_kernel(void)
10674 +{
10675 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10676 +}
10677 +
10678 +static inline unsigned long pax_close_kernel(void)
10679 +{
10680 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10681 +}
10682 +#else
10683 +static inline unsigned long pax_open_kernel(void) { return 0; }
10684 +static inline unsigned long pax_close_kernel(void) { return 0; }
10685 +#endif
10686 +
10687 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10688
10689 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10690 @@ -964,7 +991,7 @@ extern void default_banner(void);
10691
10692 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10693 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10694 -#define PARA_INDIRECT(addr) *%cs:addr
10695 +#define PARA_INDIRECT(addr) *%ss:addr
10696 #endif
10697
10698 #define INTERRUPT_RETURN \
10699 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10700 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10701 CLBR_NONE, \
10702 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10703 +
10704 +#define GET_CR0_INTO_RDI \
10705 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10706 + mov %rax,%rdi
10707 +
10708 +#define SET_RDI_INTO_CR0 \
10709 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10710 +
10711 +#define GET_CR3_INTO_RDI \
10712 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10713 + mov %rax,%rdi
10714 +
10715 +#define SET_RDI_INTO_CR3 \
10716 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10717 +
10718 #endif /* CONFIG_X86_32 */
10719
10720 #endif /* __ASSEMBLY__ */
10721 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10722 index 8e8b9a4..f07d725 100644
10723 --- a/arch/x86/include/asm/paravirt_types.h
10724 +++ b/arch/x86/include/asm/paravirt_types.h
10725 @@ -84,20 +84,20 @@ struct pv_init_ops {
10726 */
10727 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10728 unsigned long addr, unsigned len);
10729 -};
10730 +} __no_const;
10731
10732
10733 struct pv_lazy_ops {
10734 /* Set deferred update mode, used for batching operations. */
10735 void (*enter)(void);
10736 void (*leave)(void);
10737 -};
10738 +} __no_const;
10739
10740 struct pv_time_ops {
10741 unsigned long long (*sched_clock)(void);
10742 unsigned long long (*steal_clock)(int cpu);
10743 unsigned long (*get_tsc_khz)(void);
10744 -};
10745 +} __no_const;
10746
10747 struct pv_cpu_ops {
10748 /* hooks for various privileged instructions */
10749 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10750
10751 void (*start_context_switch)(struct task_struct *prev);
10752 void (*end_context_switch)(struct task_struct *next);
10753 -};
10754 +} __no_const;
10755
10756 struct pv_irq_ops {
10757 /*
10758 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10759 unsigned long start_eip,
10760 unsigned long start_esp);
10761 #endif
10762 -};
10763 +} __no_const;
10764
10765 struct pv_mmu_ops {
10766 unsigned long (*read_cr2)(void);
10767 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10768 struct paravirt_callee_save make_pud;
10769
10770 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10771 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10772 #endif /* PAGETABLE_LEVELS == 4 */
10773 #endif /* PAGETABLE_LEVELS >= 3 */
10774
10775 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10776 an mfn. We can tell which is which from the index. */
10777 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10778 phys_addr_t phys, pgprot_t flags);
10779 +
10780 +#ifdef CONFIG_PAX_KERNEXEC
10781 + unsigned long (*pax_open_kernel)(void);
10782 + unsigned long (*pax_close_kernel)(void);
10783 +#endif
10784 +
10785 };
10786
10787 struct arch_spinlock;
10788 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10789 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10790 int (*spin_trylock)(struct arch_spinlock *lock);
10791 void (*spin_unlock)(struct arch_spinlock *lock);
10792 -};
10793 +} __no_const;
10794
10795 /* This contains all the paravirt structures: we get a convenient
10796 * number for each function using the offset which we use to indicate
10797 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10798 index b4389a4..b7ff22c 100644
10799 --- a/arch/x86/include/asm/pgalloc.h
10800 +++ b/arch/x86/include/asm/pgalloc.h
10801 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10802 pmd_t *pmd, pte_t *pte)
10803 {
10804 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10805 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10806 +}
10807 +
10808 +static inline void pmd_populate_user(struct mm_struct *mm,
10809 + pmd_t *pmd, pte_t *pte)
10810 +{
10811 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10812 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10813 }
10814
10815 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10816 index 98391db..8f6984e 100644
10817 --- a/arch/x86/include/asm/pgtable-2level.h
10818 +++ b/arch/x86/include/asm/pgtable-2level.h
10819 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10820
10821 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10822 {
10823 + pax_open_kernel();
10824 *pmdp = pmd;
10825 + pax_close_kernel();
10826 }
10827
10828 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10829 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10830 index effff47..f9e4035 100644
10831 --- a/arch/x86/include/asm/pgtable-3level.h
10832 +++ b/arch/x86/include/asm/pgtable-3level.h
10833 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10834
10835 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10836 {
10837 + pax_open_kernel();
10838 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10839 + pax_close_kernel();
10840 }
10841
10842 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10843 {
10844 + pax_open_kernel();
10845 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10846 + pax_close_kernel();
10847 }
10848
10849 /*
10850 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10851 index 49afb3f..ed14d07 100644
10852 --- a/arch/x86/include/asm/pgtable.h
10853 +++ b/arch/x86/include/asm/pgtable.h
10854 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10855
10856 #ifndef __PAGETABLE_PUD_FOLDED
10857 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10858 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10859 #define pgd_clear(pgd) native_pgd_clear(pgd)
10860 #endif
10861
10862 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10863
10864 #define arch_end_context_switch(prev) do {} while(0)
10865
10866 +#define pax_open_kernel() native_pax_open_kernel()
10867 +#define pax_close_kernel() native_pax_close_kernel()
10868 #endif /* CONFIG_PARAVIRT */
10869
10870 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10871 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10872 +
10873 +#ifdef CONFIG_PAX_KERNEXEC
10874 +static inline unsigned long native_pax_open_kernel(void)
10875 +{
10876 + unsigned long cr0;
10877 +
10878 + preempt_disable();
10879 + barrier();
10880 + cr0 = read_cr0() ^ X86_CR0_WP;
10881 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10882 + write_cr0(cr0);
10883 + return cr0 ^ X86_CR0_WP;
10884 +}
10885 +
10886 +static inline unsigned long native_pax_close_kernel(void)
10887 +{
10888 + unsigned long cr0;
10889 +
10890 + cr0 = read_cr0() ^ X86_CR0_WP;
10891 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10892 + write_cr0(cr0);
10893 + barrier();
10894 + preempt_enable_no_resched();
10895 + return cr0 ^ X86_CR0_WP;
10896 +}
10897 +#else
10898 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10899 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10900 +#endif
10901 +
10902 /*
10903 * The following only work if pte_present() is true.
10904 * Undefined behaviour if not..
10905 */
10906 +static inline int pte_user(pte_t pte)
10907 +{
10908 + return pte_val(pte) & _PAGE_USER;
10909 +}
10910 +
10911 static inline int pte_dirty(pte_t pte)
10912 {
10913 return pte_flags(pte) & _PAGE_DIRTY;
10914 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10915 return pte_clear_flags(pte, _PAGE_RW);
10916 }
10917
10918 +static inline pte_t pte_mkread(pte_t pte)
10919 +{
10920 + return __pte(pte_val(pte) | _PAGE_USER);
10921 +}
10922 +
10923 static inline pte_t pte_mkexec(pte_t pte)
10924 {
10925 - return pte_clear_flags(pte, _PAGE_NX);
10926 +#ifdef CONFIG_X86_PAE
10927 + if (__supported_pte_mask & _PAGE_NX)
10928 + return pte_clear_flags(pte, _PAGE_NX);
10929 + else
10930 +#endif
10931 + return pte_set_flags(pte, _PAGE_USER);
10932 +}
10933 +
10934 +static inline pte_t pte_exprotect(pte_t pte)
10935 +{
10936 +#ifdef CONFIG_X86_PAE
10937 + if (__supported_pte_mask & _PAGE_NX)
10938 + return pte_set_flags(pte, _PAGE_NX);
10939 + else
10940 +#endif
10941 + return pte_clear_flags(pte, _PAGE_USER);
10942 }
10943
10944 static inline pte_t pte_mkdirty(pte_t pte)
10945 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10946 #endif
10947
10948 #ifndef __ASSEMBLY__
10949 +
10950 +#ifdef CONFIG_PAX_PER_CPU_PGD
10951 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10952 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10953 +{
10954 + return cpu_pgd[cpu];
10955 +}
10956 +#endif
10957 +
10958 #include <linux/mm_types.h>
10959
10960 static inline int pte_none(pte_t pte)
10961 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10962
10963 static inline int pgd_bad(pgd_t pgd)
10964 {
10965 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10966 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10967 }
10968
10969 static inline int pgd_none(pgd_t pgd)
10970 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10971 * pgd_offset() returns a (pgd_t *)
10972 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10973 */
10974 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10975 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10976 +
10977 +#ifdef CONFIG_PAX_PER_CPU_PGD
10978 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10979 +#endif
10980 +
10981 /*
10982 * a shortcut which implies the use of the kernel's pgd, instead
10983 * of a process's
10984 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10985 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10986 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10987
10988 +#ifdef CONFIG_X86_32
10989 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10990 +#else
10991 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10992 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10993 +
10994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10995 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10996 +#else
10997 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10998 +#endif
10999 +
11000 +#endif
11001 +
11002 #ifndef __ASSEMBLY__
11003
11004 extern int direct_gbpages;
11005 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11006 * dst and src can be on the same page, but the range must not overlap,
11007 * and must not cross a page boundary.
11008 */
11009 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11010 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11011 {
11012 - memcpy(dst, src, count * sizeof(pgd_t));
11013 + pax_open_kernel();
11014 + while (count--)
11015 + *dst++ = *src++;
11016 + pax_close_kernel();
11017 }
11018
11019 +#ifdef CONFIG_PAX_PER_CPU_PGD
11020 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11021 +#endif
11022 +
11023 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11024 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11025 +#else
11026 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11027 +#endif
11028
11029 #include <asm-generic/pgtable.h>
11030 #endif /* __ASSEMBLY__ */
11031 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11032 index 0c92113..34a77c6 100644
11033 --- a/arch/x86/include/asm/pgtable_32.h
11034 +++ b/arch/x86/include/asm/pgtable_32.h
11035 @@ -25,9 +25,6 @@
11036 struct mm_struct;
11037 struct vm_area_struct;
11038
11039 -extern pgd_t swapper_pg_dir[1024];
11040 -extern pgd_t initial_page_table[1024];
11041 -
11042 static inline void pgtable_cache_init(void) { }
11043 static inline void check_pgt_cache(void) { }
11044 void paging_init(void);
11045 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11046 # include <asm/pgtable-2level.h>
11047 #endif
11048
11049 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11050 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11051 +#ifdef CONFIG_X86_PAE
11052 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11053 +#endif
11054 +
11055 #if defined(CONFIG_HIGHPTE)
11056 #define pte_offset_map(dir, address) \
11057 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11058 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11059 /* Clear a kernel PTE and flush it from the TLB */
11060 #define kpte_clear_flush(ptep, vaddr) \
11061 do { \
11062 + pax_open_kernel(); \
11063 pte_clear(&init_mm, (vaddr), (ptep)); \
11064 + pax_close_kernel(); \
11065 __flush_tlb_one((vaddr)); \
11066 } while (0)
11067
11068 @@ -74,6 +79,9 @@ do { \
11069
11070 #endif /* !__ASSEMBLY__ */
11071
11072 +#define HAVE_ARCH_UNMAPPED_AREA
11073 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11074 +
11075 /*
11076 * kern_addr_valid() is (1) for FLATMEM and (0) for
11077 * SPARSEMEM and DISCONTIGMEM
11078 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11079 index ed5903b..c7fe163 100644
11080 --- a/arch/x86/include/asm/pgtable_32_types.h
11081 +++ b/arch/x86/include/asm/pgtable_32_types.h
11082 @@ -8,7 +8,7 @@
11083 */
11084 #ifdef CONFIG_X86_PAE
11085 # include <asm/pgtable-3level_types.h>
11086 -# define PMD_SIZE (1UL << PMD_SHIFT)
11087 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11088 # define PMD_MASK (~(PMD_SIZE - 1))
11089 #else
11090 # include <asm/pgtable-2level_types.h>
11091 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11092 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11093 #endif
11094
11095 +#ifdef CONFIG_PAX_KERNEXEC
11096 +#ifndef __ASSEMBLY__
11097 +extern unsigned char MODULES_EXEC_VADDR[];
11098 +extern unsigned char MODULES_EXEC_END[];
11099 +#endif
11100 +#include <asm/boot.h>
11101 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11102 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11103 +#else
11104 +#define ktla_ktva(addr) (addr)
11105 +#define ktva_ktla(addr) (addr)
11106 +#endif
11107 +
11108 #define MODULES_VADDR VMALLOC_START
11109 #define MODULES_END VMALLOC_END
11110 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11111 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11112 index 975f709..107976d 100644
11113 --- a/arch/x86/include/asm/pgtable_64.h
11114 +++ b/arch/x86/include/asm/pgtable_64.h
11115 @@ -16,10 +16,14 @@
11116
11117 extern pud_t level3_kernel_pgt[512];
11118 extern pud_t level3_ident_pgt[512];
11119 +extern pud_t level3_vmalloc_start_pgt[512];
11120 +extern pud_t level3_vmalloc_end_pgt[512];
11121 +extern pud_t level3_vmemmap_pgt[512];
11122 +extern pud_t level2_vmemmap_pgt[512];
11123 extern pmd_t level2_kernel_pgt[512];
11124 extern pmd_t level2_fixmap_pgt[512];
11125 -extern pmd_t level2_ident_pgt[512];
11126 -extern pgd_t init_level4_pgt[];
11127 +extern pmd_t level2_ident_pgt[512*2];
11128 +extern pgd_t init_level4_pgt[512];
11129
11130 #define swapper_pg_dir init_level4_pgt
11131
11132 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11133
11134 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11135 {
11136 + pax_open_kernel();
11137 *pmdp = pmd;
11138 + pax_close_kernel();
11139 }
11140
11141 static inline void native_pmd_clear(pmd_t *pmd)
11142 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11143
11144 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11145 {
11146 + pax_open_kernel();
11147 + *pgdp = pgd;
11148 + pax_close_kernel();
11149 +}
11150 +
11151 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11152 +{
11153 *pgdp = pgd;
11154 }
11155
11156 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11157 index 766ea16..5b96cb3 100644
11158 --- a/arch/x86/include/asm/pgtable_64_types.h
11159 +++ b/arch/x86/include/asm/pgtable_64_types.h
11160 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11161 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11162 #define MODULES_END _AC(0xffffffffff000000, UL)
11163 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11164 +#define MODULES_EXEC_VADDR MODULES_VADDR
11165 +#define MODULES_EXEC_END MODULES_END
11166 +
11167 +#define ktla_ktva(addr) (addr)
11168 +#define ktva_ktla(addr) (addr)
11169
11170 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11171 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11172 index 013286a..8b42f4f 100644
11173 --- a/arch/x86/include/asm/pgtable_types.h
11174 +++ b/arch/x86/include/asm/pgtable_types.h
11175 @@ -16,13 +16,12 @@
11176 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11177 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11178 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11179 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11180 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11181 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11182 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11183 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11184 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11185 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11186 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11187 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11188 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11189 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11190
11191 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11192 @@ -40,7 +39,6 @@
11193 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11194 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11195 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11196 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11197 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11198 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11199 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11200 @@ -57,8 +55,10 @@
11201
11202 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11203 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11204 -#else
11205 +#elif defined(CONFIG_KMEMCHECK)
11206 #define _PAGE_NX (_AT(pteval_t, 0))
11207 +#else
11208 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11209 #endif
11210
11211 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11212 @@ -96,6 +96,9 @@
11213 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11214 _PAGE_ACCESSED)
11215
11216 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11217 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11218 +
11219 #define __PAGE_KERNEL_EXEC \
11220 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11221 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11222 @@ -106,7 +109,7 @@
11223 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11224 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11225 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11226 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11227 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11228 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11229 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11230 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11231 @@ -168,8 +171,8 @@
11232 * bits are combined, this will alow user to access the high address mapped
11233 * VDSO in the presence of CONFIG_COMPAT_VDSO
11234 */
11235 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11236 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11237 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11238 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11239 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11240 #endif
11241
11242 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11243 {
11244 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11245 }
11246 +#endif
11247
11248 +#if PAGETABLE_LEVELS == 3
11249 +#include <asm-generic/pgtable-nopud.h>
11250 +#endif
11251 +
11252 +#if PAGETABLE_LEVELS == 2
11253 +#include <asm-generic/pgtable-nopmd.h>
11254 +#endif
11255 +
11256 +#ifndef __ASSEMBLY__
11257 #if PAGETABLE_LEVELS > 3
11258 typedef struct { pudval_t pud; } pud_t;
11259
11260 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11261 return pud.pud;
11262 }
11263 #else
11264 -#include <asm-generic/pgtable-nopud.h>
11265 -
11266 static inline pudval_t native_pud_val(pud_t pud)
11267 {
11268 return native_pgd_val(pud.pgd);
11269 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11270 return pmd.pmd;
11271 }
11272 #else
11273 -#include <asm-generic/pgtable-nopmd.h>
11274 -
11275 static inline pmdval_t native_pmd_val(pmd_t pmd)
11276 {
11277 return native_pgd_val(pmd.pud.pgd);
11278 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11279
11280 extern pteval_t __supported_pte_mask;
11281 extern void set_nx(void);
11282 -extern int nx_enabled;
11283
11284 #define pgprot_writecombine pgprot_writecombine
11285 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11286 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11287 index 58545c9..fe6fc38e 100644
11288 --- a/arch/x86/include/asm/processor.h
11289 +++ b/arch/x86/include/asm/processor.h
11290 @@ -266,7 +266,7 @@ struct tss_struct {
11291
11292 } ____cacheline_aligned;
11293
11294 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11295 +extern struct tss_struct init_tss[NR_CPUS];
11296
11297 /*
11298 * Save the original ist values for checking stack pointers during debugging
11299 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11300 */
11301 #define TASK_SIZE PAGE_OFFSET
11302 #define TASK_SIZE_MAX TASK_SIZE
11303 +
11304 +#ifdef CONFIG_PAX_SEGMEXEC
11305 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11306 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11307 +#else
11308 #define STACK_TOP TASK_SIZE
11309 -#define STACK_TOP_MAX STACK_TOP
11310 +#endif
11311 +
11312 +#define STACK_TOP_MAX TASK_SIZE
11313
11314 #define INIT_THREAD { \
11315 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11316 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11317 .vm86_info = NULL, \
11318 .sysenter_cs = __KERNEL_CS, \
11319 .io_bitmap_ptr = NULL, \
11320 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11321 */
11322 #define INIT_TSS { \
11323 .x86_tss = { \
11324 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11325 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11326 .ss0 = __KERNEL_DS, \
11327 .ss1 = __KERNEL_CS, \
11328 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11329 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11330 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11331
11332 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11333 -#define KSTK_TOP(info) \
11334 -({ \
11335 - unsigned long *__ptr = (unsigned long *)(info); \
11336 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11337 -})
11338 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11339
11340 /*
11341 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11342 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11343 #define task_pt_regs(task) \
11344 ({ \
11345 struct pt_regs *__regs__; \
11346 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11347 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11348 __regs__ - 1; \
11349 })
11350
11351 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11352 /*
11353 * User space process size. 47bits minus one guard page.
11354 */
11355 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11356 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11357
11358 /* This decides where the kernel will search for a free chunk of vm
11359 * space during mmap's.
11360 */
11361 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11362 - 0xc0000000 : 0xFFFFe000)
11363 + 0xc0000000 : 0xFFFFf000)
11364
11365 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11366 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11367 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11368 #define STACK_TOP_MAX TASK_SIZE_MAX
11369
11370 #define INIT_THREAD { \
11371 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11372 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11373 }
11374
11375 #define INIT_TSS { \
11376 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11377 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11378 }
11379
11380 /*
11381 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11382 */
11383 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11384
11385 +#ifdef CONFIG_PAX_SEGMEXEC
11386 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11387 +#endif
11388 +
11389 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11390
11391 /* Get/set a process' ability to use the timestamp counter instruction */
11392 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11393 index 3566454..4bdfb8c 100644
11394 --- a/arch/x86/include/asm/ptrace.h
11395 +++ b/arch/x86/include/asm/ptrace.h
11396 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11397 }
11398
11399 /*
11400 - * user_mode_vm(regs) determines whether a register set came from user mode.
11401 + * user_mode(regs) determines whether a register set came from user mode.
11402 * This is true if V8086 mode was enabled OR if the register set was from
11403 * protected mode with RPL-3 CS value. This tricky test checks that with
11404 * one comparison. Many places in the kernel can bypass this full check
11405 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11406 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11407 + * be used.
11408 */
11409 -static inline int user_mode(struct pt_regs *regs)
11410 +static inline int user_mode_novm(struct pt_regs *regs)
11411 {
11412 #ifdef CONFIG_X86_32
11413 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11414 #else
11415 - return !!(regs->cs & 3);
11416 + return !!(regs->cs & SEGMENT_RPL_MASK);
11417 #endif
11418 }
11419
11420 -static inline int user_mode_vm(struct pt_regs *regs)
11421 +static inline int user_mode(struct pt_regs *regs)
11422 {
11423 #ifdef CONFIG_X86_32
11424 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11425 USER_RPL;
11426 #else
11427 - return user_mode(regs);
11428 + return user_mode_novm(regs);
11429 #endif
11430 }
11431
11432 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11433 #ifdef CONFIG_X86_64
11434 static inline bool user_64bit_mode(struct pt_regs *regs)
11435 {
11436 + unsigned long cs = regs->cs & 0xffff;
11437 #ifndef CONFIG_PARAVIRT
11438 /*
11439 * On non-paravirt systems, this is the only long mode CPL 3
11440 * selector. We do not allow long mode selectors in the LDT.
11441 */
11442 - return regs->cs == __USER_CS;
11443 + return cs == __USER_CS;
11444 #else
11445 /* Headers are too twisted for this to go in paravirt.h. */
11446 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11447 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11448 #endif
11449 }
11450 #endif
11451 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11452 index 92f29706..a79cbbb 100644
11453 --- a/arch/x86/include/asm/reboot.h
11454 +++ b/arch/x86/include/asm/reboot.h
11455 @@ -6,19 +6,19 @@
11456 struct pt_regs;
11457
11458 struct machine_ops {
11459 - void (*restart)(char *cmd);
11460 - void (*halt)(void);
11461 - void (*power_off)(void);
11462 + void (* __noreturn restart)(char *cmd);
11463 + void (* __noreturn halt)(void);
11464 + void (* __noreturn power_off)(void);
11465 void (*shutdown)(void);
11466 void (*crash_shutdown)(struct pt_regs *);
11467 - void (*emergency_restart)(void);
11468 -};
11469 + void (* __noreturn emergency_restart)(void);
11470 +} __no_const;
11471
11472 extern struct machine_ops machine_ops;
11473
11474 void native_machine_crash_shutdown(struct pt_regs *regs);
11475 void native_machine_shutdown(void);
11476 -void machine_real_restart(unsigned int type);
11477 +void machine_real_restart(unsigned int type) __noreturn;
11478 /* These must match dispatch_table in reboot_32.S */
11479 #define MRR_BIOS 0
11480 #define MRR_APM 1
11481 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11482 index 2dbe4a7..ce1db00 100644
11483 --- a/arch/x86/include/asm/rwsem.h
11484 +++ b/arch/x86/include/asm/rwsem.h
11485 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11486 {
11487 asm volatile("# beginning down_read\n\t"
11488 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11489 +
11490 +#ifdef CONFIG_PAX_REFCOUNT
11491 + "jno 0f\n"
11492 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11493 + "int $4\n0:\n"
11494 + _ASM_EXTABLE(0b, 0b)
11495 +#endif
11496 +
11497 /* adds 0x00000001 */
11498 " jns 1f\n"
11499 " call call_rwsem_down_read_failed\n"
11500 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11501 "1:\n\t"
11502 " mov %1,%2\n\t"
11503 " add %3,%2\n\t"
11504 +
11505 +#ifdef CONFIG_PAX_REFCOUNT
11506 + "jno 0f\n"
11507 + "sub %3,%2\n"
11508 + "int $4\n0:\n"
11509 + _ASM_EXTABLE(0b, 0b)
11510 +#endif
11511 +
11512 " jle 2f\n\t"
11513 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11514 " jnz 1b\n\t"
11515 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11516 long tmp;
11517 asm volatile("# beginning down_write\n\t"
11518 LOCK_PREFIX " xadd %1,(%2)\n\t"
11519 +
11520 +#ifdef CONFIG_PAX_REFCOUNT
11521 + "jno 0f\n"
11522 + "mov %1,(%2)\n"
11523 + "int $4\n0:\n"
11524 + _ASM_EXTABLE(0b, 0b)
11525 +#endif
11526 +
11527 /* adds 0xffff0001, returns the old value */
11528 " test %1,%1\n\t"
11529 /* was the count 0 before? */
11530 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11531 long tmp;
11532 asm volatile("# beginning __up_read\n\t"
11533 LOCK_PREFIX " xadd %1,(%2)\n\t"
11534 +
11535 +#ifdef CONFIG_PAX_REFCOUNT
11536 + "jno 0f\n"
11537 + "mov %1,(%2)\n"
11538 + "int $4\n0:\n"
11539 + _ASM_EXTABLE(0b, 0b)
11540 +#endif
11541 +
11542 /* subtracts 1, returns the old value */
11543 " jns 1f\n\t"
11544 " call call_rwsem_wake\n" /* expects old value in %edx */
11545 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11546 long tmp;
11547 asm volatile("# beginning __up_write\n\t"
11548 LOCK_PREFIX " xadd %1,(%2)\n\t"
11549 +
11550 +#ifdef CONFIG_PAX_REFCOUNT
11551 + "jno 0f\n"
11552 + "mov %1,(%2)\n"
11553 + "int $4\n0:\n"
11554 + _ASM_EXTABLE(0b, 0b)
11555 +#endif
11556 +
11557 /* subtracts 0xffff0001, returns the old value */
11558 " jns 1f\n\t"
11559 " call call_rwsem_wake\n" /* expects old value in %edx */
11560 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11561 {
11562 asm volatile("# beginning __downgrade_write\n\t"
11563 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11564 +
11565 +#ifdef CONFIG_PAX_REFCOUNT
11566 + "jno 0f\n"
11567 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11568 + "int $4\n0:\n"
11569 + _ASM_EXTABLE(0b, 0b)
11570 +#endif
11571 +
11572 /*
11573 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11574 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11575 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11576 */
11577 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11578 {
11579 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11580 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11581 +
11582 +#ifdef CONFIG_PAX_REFCOUNT
11583 + "jno 0f\n"
11584 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11585 + "int $4\n0:\n"
11586 + _ASM_EXTABLE(0b, 0b)
11587 +#endif
11588 +
11589 : "+m" (sem->count)
11590 : "er" (delta));
11591 }
11592 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11593 */
11594 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11595 {
11596 - return delta + xadd(&sem->count, delta);
11597 + return delta + xadd_check_overflow(&sem->count, delta);
11598 }
11599
11600 #endif /* __KERNEL__ */
11601 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11602 index 5e64171..f58957e 100644
11603 --- a/arch/x86/include/asm/segment.h
11604 +++ b/arch/x86/include/asm/segment.h
11605 @@ -64,10 +64,15 @@
11606 * 26 - ESPFIX small SS
11607 * 27 - per-cpu [ offset to per-cpu data area ]
11608 * 28 - stack_canary-20 [ for stack protector ]
11609 - * 29 - unused
11610 - * 30 - unused
11611 + * 29 - PCI BIOS CS
11612 + * 30 - PCI BIOS DS
11613 * 31 - TSS for double fault handler
11614 */
11615 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11616 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11617 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11618 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11619 +
11620 #define GDT_ENTRY_TLS_MIN 6
11621 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11622
11623 @@ -79,6 +84,8 @@
11624
11625 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11626
11627 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11628 +
11629 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11630
11631 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11632 @@ -104,6 +111,12 @@
11633 #define __KERNEL_STACK_CANARY 0
11634 #endif
11635
11636 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11637 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11638 +
11639 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11640 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11641 +
11642 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11643
11644 /*
11645 @@ -141,7 +154,7 @@
11646 */
11647
11648 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11649 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11650 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11651
11652
11653 #else
11654 @@ -165,6 +178,8 @@
11655 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11656 #define __USER32_DS __USER_DS
11657
11658 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11659 +
11660 #define GDT_ENTRY_TSS 8 /* needs two entries */
11661 #define GDT_ENTRY_LDT 10 /* needs two entries */
11662 #define GDT_ENTRY_TLS_MIN 12
11663 @@ -185,6 +200,7 @@
11664 #endif
11665
11666 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11667 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11668 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11669 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11670 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11671 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11672 index 0434c40..1714bf0 100644
11673 --- a/arch/x86/include/asm/smp.h
11674 +++ b/arch/x86/include/asm/smp.h
11675 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11676 /* cpus sharing the last level cache: */
11677 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11678 DECLARE_PER_CPU(u16, cpu_llc_id);
11679 -DECLARE_PER_CPU(int, cpu_number);
11680 +DECLARE_PER_CPU(unsigned int, cpu_number);
11681
11682 static inline struct cpumask *cpu_sibling_mask(int cpu)
11683 {
11684 @@ -77,7 +77,7 @@ struct smp_ops {
11685
11686 void (*send_call_func_ipi)(const struct cpumask *mask);
11687 void (*send_call_func_single_ipi)(int cpu);
11688 -};
11689 +} __no_const;
11690
11691 /* Globals due to paravirt */
11692 extern void set_cpu_sibling_map(int cpu);
11693 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11694 extern int safe_smp_processor_id(void);
11695
11696 #elif defined(CONFIG_X86_64_SMP)
11697 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11698 -
11699 -#define stack_smp_processor_id() \
11700 -({ \
11701 - struct thread_info *ti; \
11702 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11703 - ti->cpu; \
11704 -})
11705 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11706 +#define stack_smp_processor_id() raw_smp_processor_id()
11707 #define safe_smp_processor_id() smp_processor_id()
11708
11709 #endif
11710 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11711 index a82c2bf..2198f61 100644
11712 --- a/arch/x86/include/asm/spinlock.h
11713 +++ b/arch/x86/include/asm/spinlock.h
11714 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11715 static inline void arch_read_lock(arch_rwlock_t *rw)
11716 {
11717 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11718 +
11719 +#ifdef CONFIG_PAX_REFCOUNT
11720 + "jno 0f\n"
11721 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11722 + "int $4\n0:\n"
11723 + _ASM_EXTABLE(0b, 0b)
11724 +#endif
11725 +
11726 "jns 1f\n"
11727 "call __read_lock_failed\n\t"
11728 "1:\n"
11729 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11730 static inline void arch_write_lock(arch_rwlock_t *rw)
11731 {
11732 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11733 +
11734 +#ifdef CONFIG_PAX_REFCOUNT
11735 + "jno 0f\n"
11736 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11737 + "int $4\n0:\n"
11738 + _ASM_EXTABLE(0b, 0b)
11739 +#endif
11740 +
11741 "jz 1f\n"
11742 "call __write_lock_failed\n\t"
11743 "1:\n"
11744 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11745
11746 static inline void arch_read_unlock(arch_rwlock_t *rw)
11747 {
11748 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11749 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11750 +
11751 +#ifdef CONFIG_PAX_REFCOUNT
11752 + "jno 0f\n"
11753 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11754 + "int $4\n0:\n"
11755 + _ASM_EXTABLE(0b, 0b)
11756 +#endif
11757 +
11758 :"+m" (rw->lock) : : "memory");
11759 }
11760
11761 static inline void arch_write_unlock(arch_rwlock_t *rw)
11762 {
11763 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11764 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11765 +
11766 +#ifdef CONFIG_PAX_REFCOUNT
11767 + "jno 0f\n"
11768 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11769 + "int $4\n0:\n"
11770 + _ASM_EXTABLE(0b, 0b)
11771 +#endif
11772 +
11773 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11774 }
11775
11776 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11777 index 1575177..cb23f52 100644
11778 --- a/arch/x86/include/asm/stackprotector.h
11779 +++ b/arch/x86/include/asm/stackprotector.h
11780 @@ -48,7 +48,7 @@
11781 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11782 */
11783 #define GDT_STACK_CANARY_INIT \
11784 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11785 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11786
11787 /*
11788 * Initialize the stackprotector canary value.
11789 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11790
11791 static inline void load_stack_canary_segment(void)
11792 {
11793 -#ifdef CONFIG_X86_32
11794 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11795 asm volatile ("mov %0, %%gs" : : "r" (0));
11796 #endif
11797 }
11798 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11799 index 70bbe39..4ae2bd4 100644
11800 --- a/arch/x86/include/asm/stacktrace.h
11801 +++ b/arch/x86/include/asm/stacktrace.h
11802 @@ -11,28 +11,20 @@
11803
11804 extern int kstack_depth_to_print;
11805
11806 -struct thread_info;
11807 +struct task_struct;
11808 struct stacktrace_ops;
11809
11810 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11811 - unsigned long *stack,
11812 - unsigned long bp,
11813 - const struct stacktrace_ops *ops,
11814 - void *data,
11815 - unsigned long *end,
11816 - int *graph);
11817 +typedef unsigned long walk_stack_t(struct task_struct *task,
11818 + void *stack_start,
11819 + unsigned long *stack,
11820 + unsigned long bp,
11821 + const struct stacktrace_ops *ops,
11822 + void *data,
11823 + unsigned long *end,
11824 + int *graph);
11825
11826 -extern unsigned long
11827 -print_context_stack(struct thread_info *tinfo,
11828 - unsigned long *stack, unsigned long bp,
11829 - const struct stacktrace_ops *ops, void *data,
11830 - unsigned long *end, int *graph);
11831 -
11832 -extern unsigned long
11833 -print_context_stack_bp(struct thread_info *tinfo,
11834 - unsigned long *stack, unsigned long bp,
11835 - const struct stacktrace_ops *ops, void *data,
11836 - unsigned long *end, int *graph);
11837 +extern walk_stack_t print_context_stack;
11838 +extern walk_stack_t print_context_stack_bp;
11839
11840 /* Generic stack tracer with callbacks */
11841
11842 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11843 void (*address)(void *data, unsigned long address, int reliable);
11844 /* On negative return stop dumping */
11845 int (*stack)(void *data, char *name);
11846 - walk_stack_t walk_stack;
11847 + walk_stack_t *walk_stack;
11848 };
11849
11850 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11851 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11852 index cb23852..2dde194 100644
11853 --- a/arch/x86/include/asm/sys_ia32.h
11854 +++ b/arch/x86/include/asm/sys_ia32.h
11855 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11856 compat_sigset_t __user *, unsigned int);
11857 asmlinkage long sys32_alarm(unsigned int);
11858
11859 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11860 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11861 asmlinkage long sys32_sysfs(int, u32, u32);
11862
11863 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11864 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
11865 index f1d8b44..a4de8b7 100644
11866 --- a/arch/x86/include/asm/syscalls.h
11867 +++ b/arch/x86/include/asm/syscalls.h
11868 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
11869 void __user *, struct pt_regs *);
11870
11871 /* kernel/ldt.c */
11872 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
11873 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
11874
11875 /* kernel/signal.c */
11876 long sys_rt_sigreturn(struct pt_regs *);
11877 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11878 index 2d2f01c..f985723 100644
11879 --- a/arch/x86/include/asm/system.h
11880 +++ b/arch/x86/include/asm/system.h
11881 @@ -129,7 +129,7 @@ do { \
11882 "call __switch_to\n\t" \
11883 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11884 __switch_canary \
11885 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11886 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11887 "movq %%rax,%%rdi\n\t" \
11888 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11889 "jnz ret_from_fork\n\t" \
11890 @@ -140,7 +140,7 @@ do { \
11891 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11892 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11893 [_tif_fork] "i" (_TIF_FORK), \
11894 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11895 + [thread_info] "m" (current_tinfo), \
11896 [current_task] "m" (current_task) \
11897 __switch_canary_iparam \
11898 : "memory", "cc" __EXTRA_CLOBBER)
11899 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11900 {
11901 unsigned long __limit;
11902 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11903 - return __limit + 1;
11904 + return __limit;
11905 }
11906
11907 static inline void native_clts(void)
11908 @@ -397,13 +397,13 @@ void enable_hlt(void);
11909
11910 void cpu_idle_wait(void);
11911
11912 -extern unsigned long arch_align_stack(unsigned long sp);
11913 +#define arch_align_stack(x) ((x) & ~0xfUL)
11914 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11915
11916 void default_idle(void);
11917 bool set_pm_idle_to_default(void);
11918
11919 -void stop_this_cpu(void *dummy);
11920 +void stop_this_cpu(void *dummy) __noreturn;
11921
11922 /*
11923 * Force strict CPU ordering.
11924 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11925 index cfd8144..1b1127d 100644
11926 --- a/arch/x86/include/asm/thread_info.h
11927 +++ b/arch/x86/include/asm/thread_info.h
11928 @@ -10,6 +10,7 @@
11929 #include <linux/compiler.h>
11930 #include <asm/page.h>
11931 #include <asm/types.h>
11932 +#include <asm/percpu.h>
11933
11934 /*
11935 * low level task data that entry.S needs immediate access to
11936 @@ -24,7 +25,6 @@ struct exec_domain;
11937 #include <linux/atomic.h>
11938
11939 struct thread_info {
11940 - struct task_struct *task; /* main task structure */
11941 struct exec_domain *exec_domain; /* execution domain */
11942 __u32 flags; /* low level flags */
11943 __u32 status; /* thread synchronous flags */
11944 @@ -34,19 +34,13 @@ struct thread_info {
11945 mm_segment_t addr_limit;
11946 struct restart_block restart_block;
11947 void __user *sysenter_return;
11948 -#ifdef CONFIG_X86_32
11949 - unsigned long previous_esp; /* ESP of the previous stack in
11950 - case of nested (IRQ) stacks
11951 - */
11952 - __u8 supervisor_stack[0];
11953 -#endif
11954 + unsigned long lowest_stack;
11955 unsigned int sig_on_uaccess_error:1;
11956 unsigned int uaccess_err:1; /* uaccess failed */
11957 };
11958
11959 -#define INIT_THREAD_INFO(tsk) \
11960 +#define INIT_THREAD_INFO \
11961 { \
11962 - .task = &tsk, \
11963 .exec_domain = &default_exec_domain, \
11964 .flags = 0, \
11965 .cpu = 0, \
11966 @@ -57,7 +51,7 @@ struct thread_info {
11967 }, \
11968 }
11969
11970 -#define init_thread_info (init_thread_union.thread_info)
11971 +#define init_thread_info (init_thread_union.stack)
11972 #define init_stack (init_thread_union.stack)
11973
11974 #else /* !__ASSEMBLY__ */
11975 @@ -169,45 +163,40 @@ struct thread_info {
11976 ret; \
11977 })
11978
11979 -#ifdef CONFIG_X86_32
11980 -
11981 -#define STACK_WARN (THREAD_SIZE/8)
11982 -/*
11983 - * macros/functions for gaining access to the thread information structure
11984 - *
11985 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11986 - */
11987 -#ifndef __ASSEMBLY__
11988 -
11989 -
11990 -/* how to get the current stack pointer from C */
11991 -register unsigned long current_stack_pointer asm("esp") __used;
11992 -
11993 -/* how to get the thread information struct from C */
11994 -static inline struct thread_info *current_thread_info(void)
11995 -{
11996 - return (struct thread_info *)
11997 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11998 -}
11999 -
12000 -#else /* !__ASSEMBLY__ */
12001 -
12002 +#ifdef __ASSEMBLY__
12003 /* how to get the thread information struct from ASM */
12004 #define GET_THREAD_INFO(reg) \
12005 - movl $-THREAD_SIZE, reg; \
12006 - andl %esp, reg
12007 + mov PER_CPU_VAR(current_tinfo), reg
12008
12009 /* use this one if reg already contains %esp */
12010 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12011 - andl $-THREAD_SIZE, reg
12012 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12013 +#else
12014 +/* how to get the thread information struct from C */
12015 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12016 +
12017 +static __always_inline struct thread_info *current_thread_info(void)
12018 +{
12019 + return percpu_read_stable(current_tinfo);
12020 +}
12021 +#endif
12022 +
12023 +#ifdef CONFIG_X86_32
12024 +
12025 +#define STACK_WARN (THREAD_SIZE/8)
12026 +/*
12027 + * macros/functions for gaining access to the thread information structure
12028 + *
12029 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12030 + */
12031 +#ifndef __ASSEMBLY__
12032 +
12033 +/* how to get the current stack pointer from C */
12034 +register unsigned long current_stack_pointer asm("esp") __used;
12035
12036 #endif
12037
12038 #else /* X86_32 */
12039
12040 -#include <asm/percpu.h>
12041 -#define KERNEL_STACK_OFFSET (5*8)
12042 -
12043 /*
12044 * macros/functions for gaining access to the thread information structure
12045 * preempt_count needs to be 1 initially, until the scheduler is functional.
12046 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
12047 #ifndef __ASSEMBLY__
12048 DECLARE_PER_CPU(unsigned long, kernel_stack);
12049
12050 -static inline struct thread_info *current_thread_info(void)
12051 -{
12052 - struct thread_info *ti;
12053 - ti = (void *)(percpu_read_stable(kernel_stack) +
12054 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12055 - return ti;
12056 -}
12057 -
12058 -#else /* !__ASSEMBLY__ */
12059 -
12060 -/* how to get the thread information struct from ASM */
12061 -#define GET_THREAD_INFO(reg) \
12062 - movq PER_CPU_VAR(kernel_stack),reg ; \
12063 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12064 -
12065 -/*
12066 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12067 - * a certain register (to be used in assembler memory operands).
12068 - */
12069 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12070 -
12071 +/* how to get the current stack pointer from C */
12072 +register unsigned long current_stack_pointer asm("rsp") __used;
12073 #endif
12074
12075 #endif /* !X86_32 */
12076 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
12077 extern void free_thread_info(struct thread_info *ti);
12078 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12079 #define arch_task_cache_init arch_task_cache_init
12080 +
12081 +#define __HAVE_THREAD_FUNCTIONS
12082 +#define task_thread_info(task) (&(task)->tinfo)
12083 +#define task_stack_page(task) ((task)->stack)
12084 +#define setup_thread_stack(p, org) do {} while (0)
12085 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12086 +
12087 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12088 +extern struct task_struct *alloc_task_struct_node(int node);
12089 +extern void free_task_struct(struct task_struct *);
12090 +
12091 #endif
12092 #endif /* _ASM_X86_THREAD_INFO_H */
12093 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12094 index 8be5f54..7ae826d 100644
12095 --- a/arch/x86/include/asm/uaccess.h
12096 +++ b/arch/x86/include/asm/uaccess.h
12097 @@ -7,12 +7,15 @@
12098 #include <linux/compiler.h>
12099 #include <linux/thread_info.h>
12100 #include <linux/string.h>
12101 +#include <linux/sched.h>
12102 #include <asm/asm.h>
12103 #include <asm/page.h>
12104
12105 #define VERIFY_READ 0
12106 #define VERIFY_WRITE 1
12107
12108 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12109 +
12110 /*
12111 * The fs value determines whether argument validity checking should be
12112 * performed or not. If get_fs() == USER_DS, checking is performed, with
12113 @@ -28,7 +31,12 @@
12114
12115 #define get_ds() (KERNEL_DS)
12116 #define get_fs() (current_thread_info()->addr_limit)
12117 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12118 +void __set_fs(mm_segment_t x);
12119 +void set_fs(mm_segment_t x);
12120 +#else
12121 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12122 +#endif
12123
12124 #define segment_eq(a, b) ((a).seg == (b).seg)
12125
12126 @@ -76,7 +84,33 @@
12127 * checks that the pointer is in the user space range - after calling
12128 * this function, memory access functions may still return -EFAULT.
12129 */
12130 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12131 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12132 +#define access_ok(type, addr, size) \
12133 +({ \
12134 + long __size = size; \
12135 + unsigned long __addr = (unsigned long)addr; \
12136 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12137 + unsigned long __end_ao = __addr + __size - 1; \
12138 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12139 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12140 + while(__addr_ao <= __end_ao) { \
12141 + char __c_ao; \
12142 + __addr_ao += PAGE_SIZE; \
12143 + if (__size > PAGE_SIZE) \
12144 + cond_resched(); \
12145 + if (__get_user(__c_ao, (char __user *)__addr)) \
12146 + break; \
12147 + if (type != VERIFY_WRITE) { \
12148 + __addr = __addr_ao; \
12149 + continue; \
12150 + } \
12151 + if (__put_user(__c_ao, (char __user *)__addr)) \
12152 + break; \
12153 + __addr = __addr_ao; \
12154 + } \
12155 + } \
12156 + __ret_ao; \
12157 +})
12158
12159 /*
12160 * The exception table consists of pairs of addresses: the first is the
12161 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12162 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12163 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12164
12165 -
12166 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12167 +#define __copyuser_seg "gs;"
12168 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12169 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12170 +#else
12171 +#define __copyuser_seg
12172 +#define __COPYUSER_SET_ES
12173 +#define __COPYUSER_RESTORE_ES
12174 +#endif
12175
12176 #ifdef CONFIG_X86_32
12177 #define __put_user_asm_u64(x, addr, err, errret) \
12178 - asm volatile("1: movl %%eax,0(%2)\n" \
12179 - "2: movl %%edx,4(%2)\n" \
12180 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12181 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12182 "3:\n" \
12183 ".section .fixup,\"ax\"\n" \
12184 "4: movl %3,%0\n" \
12185 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12186 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12187
12188 #define __put_user_asm_ex_u64(x, addr) \
12189 - asm volatile("1: movl %%eax,0(%1)\n" \
12190 - "2: movl %%edx,4(%1)\n" \
12191 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12192 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12193 "3:\n" \
12194 _ASM_EXTABLE(1b, 2b - 1b) \
12195 _ASM_EXTABLE(2b, 3b - 2b) \
12196 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12197 __typeof__(*(ptr)) __pu_val; \
12198 __chk_user_ptr(ptr); \
12199 might_fault(); \
12200 - __pu_val = x; \
12201 + __pu_val = (x); \
12202 switch (sizeof(*(ptr))) { \
12203 case 1: \
12204 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12205 @@ -373,7 +415,7 @@ do { \
12206 } while (0)
12207
12208 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12209 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12210 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12211 "2:\n" \
12212 ".section .fixup,\"ax\"\n" \
12213 "3: mov %3,%0\n" \
12214 @@ -381,7 +423,7 @@ do { \
12215 " jmp 2b\n" \
12216 ".previous\n" \
12217 _ASM_EXTABLE(1b, 3b) \
12218 - : "=r" (err), ltype(x) \
12219 + : "=r" (err), ltype (x) \
12220 : "m" (__m(addr)), "i" (errret), "0" (err))
12221
12222 #define __get_user_size_ex(x, ptr, size) \
12223 @@ -406,7 +448,7 @@ do { \
12224 } while (0)
12225
12226 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12227 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12228 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12229 "2:\n" \
12230 _ASM_EXTABLE(1b, 2b - 1b) \
12231 : ltype(x) : "m" (__m(addr)))
12232 @@ -423,13 +465,24 @@ do { \
12233 int __gu_err; \
12234 unsigned long __gu_val; \
12235 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12236 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12237 + (x) = (__typeof__(*(ptr)))__gu_val; \
12238 __gu_err; \
12239 })
12240
12241 /* FIXME: this hack is definitely wrong -AK */
12242 struct __large_struct { unsigned long buf[100]; };
12243 -#define __m(x) (*(struct __large_struct __user *)(x))
12244 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12245 +#define ____m(x) \
12246 +({ \
12247 + unsigned long ____x = (unsigned long)(x); \
12248 + if (____x < PAX_USER_SHADOW_BASE) \
12249 + ____x += PAX_USER_SHADOW_BASE; \
12250 + (void __user *)____x; \
12251 +})
12252 +#else
12253 +#define ____m(x) (x)
12254 +#endif
12255 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12256
12257 /*
12258 * Tell gcc we read from memory instead of writing: this is because
12259 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12260 * aliasing issues.
12261 */
12262 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12263 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12264 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12265 "2:\n" \
12266 ".section .fixup,\"ax\"\n" \
12267 "3: mov %3,%0\n" \
12268 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12269 ".previous\n" \
12270 _ASM_EXTABLE(1b, 3b) \
12271 : "=r"(err) \
12272 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12273 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12274
12275 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12276 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12277 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12278 "2:\n" \
12279 _ASM_EXTABLE(1b, 2b - 1b) \
12280 : : ltype(x), "m" (__m(addr)))
12281 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12282 * On error, the variable @x is set to zero.
12283 */
12284
12285 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12286 +#define __get_user(x, ptr) get_user((x), (ptr))
12287 +#else
12288 #define __get_user(x, ptr) \
12289 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12290 +#endif
12291
12292 /**
12293 * __put_user: - Write a simple value into user space, with less checking.
12294 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12295 * Returns zero on success, or -EFAULT on error.
12296 */
12297
12298 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12299 +#define __put_user(x, ptr) put_user((x), (ptr))
12300 +#else
12301 #define __put_user(x, ptr) \
12302 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12303 +#endif
12304
12305 #define __get_user_unaligned __get_user
12306 #define __put_user_unaligned __put_user
12307 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12308 #define get_user_ex(x, ptr) do { \
12309 unsigned long __gue_val; \
12310 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12311 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12312 + (x) = (__typeof__(*(ptr)))__gue_val; \
12313 } while (0)
12314
12315 #ifdef CONFIG_X86_WP_WORKS_OK
12316 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12317 index 566e803..7183d0b 100644
12318 --- a/arch/x86/include/asm/uaccess_32.h
12319 +++ b/arch/x86/include/asm/uaccess_32.h
12320 @@ -11,15 +11,15 @@
12321 #include <asm/page.h>
12322
12323 unsigned long __must_check __copy_to_user_ll
12324 - (void __user *to, const void *from, unsigned long n);
12325 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12326 unsigned long __must_check __copy_from_user_ll
12327 - (void *to, const void __user *from, unsigned long n);
12328 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12329 unsigned long __must_check __copy_from_user_ll_nozero
12330 - (void *to, const void __user *from, unsigned long n);
12331 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12332 unsigned long __must_check __copy_from_user_ll_nocache
12333 - (void *to, const void __user *from, unsigned long n);
12334 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12335 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12336 - (void *to, const void __user *from, unsigned long n);
12337 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12338
12339 /**
12340 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12341 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12342 */
12343
12344 static __always_inline unsigned long __must_check
12345 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12346 +static __always_inline unsigned long __must_check
12347 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12348 {
12349 + if ((long)n < 0)
12350 + return n;
12351 +
12352 if (__builtin_constant_p(n)) {
12353 unsigned long ret;
12354
12355 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12356 return ret;
12357 }
12358 }
12359 + if (!__builtin_constant_p(n))
12360 + check_object_size(from, n, true);
12361 return __copy_to_user_ll(to, from, n);
12362 }
12363
12364 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12365 * On success, this will be zero.
12366 */
12367 static __always_inline unsigned long __must_check
12368 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12369 +static __always_inline unsigned long __must_check
12370 __copy_to_user(void __user *to, const void *from, unsigned long n)
12371 {
12372 might_fault();
12373 +
12374 return __copy_to_user_inatomic(to, from, n);
12375 }
12376
12377 static __always_inline unsigned long
12378 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12379 +static __always_inline unsigned long
12380 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12381 {
12382 + if ((long)n < 0)
12383 + return n;
12384 +
12385 /* Avoid zeroing the tail if the copy fails..
12386 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12387 * but as the zeroing behaviour is only significant when n is not
12388 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12389 * for explanation of why this is needed.
12390 */
12391 static __always_inline unsigned long
12392 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12393 +static __always_inline unsigned long
12394 __copy_from_user(void *to, const void __user *from, unsigned long n)
12395 {
12396 might_fault();
12397 +
12398 + if ((long)n < 0)
12399 + return n;
12400 +
12401 if (__builtin_constant_p(n)) {
12402 unsigned long ret;
12403
12404 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12405 return ret;
12406 }
12407 }
12408 + if (!__builtin_constant_p(n))
12409 + check_object_size(to, n, false);
12410 return __copy_from_user_ll(to, from, n);
12411 }
12412
12413 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12414 + const void __user *from, unsigned long n) __size_overflow(3);
12415 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12416 const void __user *from, unsigned long n)
12417 {
12418 might_fault();
12419 +
12420 + if ((long)n < 0)
12421 + return n;
12422 +
12423 if (__builtin_constant_p(n)) {
12424 unsigned long ret;
12425
12426 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12427
12428 static __always_inline unsigned long
12429 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12430 + unsigned long n) __size_overflow(3);
12431 +static __always_inline unsigned long
12432 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12433 unsigned long n)
12434 {
12435 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12436 + if ((long)n < 0)
12437 + return n;
12438 +
12439 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12440 }
12441
12442 -unsigned long __must_check copy_to_user(void __user *to,
12443 - const void *from, unsigned long n);
12444 -unsigned long __must_check _copy_from_user(void *to,
12445 - const void __user *from,
12446 - unsigned long n);
12447 -
12448 +extern void copy_to_user_overflow(void)
12449 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12450 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12451 +#else
12452 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12453 +#endif
12454 +;
12455
12456 extern void copy_from_user_overflow(void)
12457 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12458 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
12459 #endif
12460 ;
12461
12462 -static inline unsigned long __must_check copy_from_user(void *to,
12463 - const void __user *from,
12464 - unsigned long n)
12465 +/**
12466 + * copy_to_user: - Copy a block of data into user space.
12467 + * @to: Destination address, in user space.
12468 + * @from: Source address, in kernel space.
12469 + * @n: Number of bytes to copy.
12470 + *
12471 + * Context: User context only. This function may sleep.
12472 + *
12473 + * Copy data from kernel space to user space.
12474 + *
12475 + * Returns number of bytes that could not be copied.
12476 + * On success, this will be zero.
12477 + */
12478 +static inline unsigned long __must_check
12479 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12480 +static inline unsigned long __must_check
12481 +copy_to_user(void __user *to, const void *from, unsigned long n)
12482 +{
12483 + int sz = __compiletime_object_size(from);
12484 +
12485 + if (unlikely(sz != -1 && sz < n))
12486 + copy_to_user_overflow();
12487 + else if (access_ok(VERIFY_WRITE, to, n))
12488 + n = __copy_to_user(to, from, n);
12489 + return n;
12490 +}
12491 +
12492 +/**
12493 + * copy_from_user: - Copy a block of data from user space.
12494 + * @to: Destination address, in kernel space.
12495 + * @from: Source address, in user space.
12496 + * @n: Number of bytes to copy.
12497 + *
12498 + * Context: User context only. This function may sleep.
12499 + *
12500 + * Copy data from user space to kernel space.
12501 + *
12502 + * Returns number of bytes that could not be copied.
12503 + * On success, this will be zero.
12504 + *
12505 + * If some data could not be copied, this function will pad the copied
12506 + * data to the requested size using zero bytes.
12507 + */
12508 +static inline unsigned long __must_check
12509 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12510 +static inline unsigned long __must_check
12511 +copy_from_user(void *to, const void __user *from, unsigned long n)
12512 {
12513 int sz = __compiletime_object_size(to);
12514
12515 - if (likely(sz == -1 || sz >= n))
12516 - n = _copy_from_user(to, from, n);
12517 - else
12518 + if (unlikely(sz != -1 && sz < n))
12519 copy_from_user_overflow();
12520 -
12521 + else if (access_ok(VERIFY_READ, from, n))
12522 + n = __copy_from_user(to, from, n);
12523 + else if ((long)n > 0) {
12524 + if (!__builtin_constant_p(n))
12525 + check_object_size(to, n, false);
12526 + memset(to, 0, n);
12527 + }
12528 return n;
12529 }
12530
12531 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
12532 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12533
12534 long strnlen_user(const char __user *str, long n);
12535 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12536 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12537 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12538 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12539
12540 #endif /* _ASM_X86_UACCESS_32_H */
12541 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12542 index 1c66d30..e294b5f 100644
12543 --- a/arch/x86/include/asm/uaccess_64.h
12544 +++ b/arch/x86/include/asm/uaccess_64.h
12545 @@ -10,6 +10,9 @@
12546 #include <asm/alternative.h>
12547 #include <asm/cpufeature.h>
12548 #include <asm/page.h>
12549 +#include <asm/pgtable.h>
12550 +
12551 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12552
12553 /*
12554 * Copy To/From Userspace
12555 @@ -17,12 +20,14 @@
12556
12557 /* Handles exceptions in both to and from, but doesn't do access_ok */
12558 __must_check unsigned long
12559 -copy_user_generic_string(void *to, const void *from, unsigned len);
12560 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12561 __must_check unsigned long
12562 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12563 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12564
12565 static __always_inline __must_check unsigned long
12566 -copy_user_generic(void *to, const void *from, unsigned len)
12567 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12568 +static __always_inline __must_check unsigned long
12569 +copy_user_generic(void *to, const void *from, unsigned long len)
12570 {
12571 unsigned ret;
12572
12573 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12574 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12575 "=d" (len)),
12576 "1" (to), "2" (from), "3" (len)
12577 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12578 + : "memory", "rcx", "r8", "r9", "r11");
12579 return ret;
12580 }
12581
12582 +static __always_inline __must_check unsigned long
12583 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12584 +static __always_inline __must_check unsigned long
12585 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12586 __must_check unsigned long
12587 -_copy_to_user(void __user *to, const void *from, unsigned len);
12588 -__must_check unsigned long
12589 -_copy_from_user(void *to, const void __user *from, unsigned len);
12590 -__must_check unsigned long
12591 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12592 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12593
12594 static inline unsigned long __must_check copy_from_user(void *to,
12595 const void __user *from,
12596 + unsigned long n) __size_overflow(3);
12597 +static inline unsigned long __must_check copy_from_user(void *to,
12598 + const void __user *from,
12599 unsigned long n)
12600 {
12601 - int sz = __compiletime_object_size(to);
12602 -
12603 might_fault();
12604 - if (likely(sz == -1 || sz >= n))
12605 - n = _copy_from_user(to, from, n);
12606 -#ifdef CONFIG_DEBUG_VM
12607 - else
12608 - WARN(1, "Buffer overflow detected!\n");
12609 -#endif
12610 +
12611 + if (access_ok(VERIFY_READ, from, n))
12612 + n = __copy_from_user(to, from, n);
12613 + else if (n < INT_MAX) {
12614 + if (!__builtin_constant_p(n))
12615 + check_object_size(to, n, false);
12616 + memset(to, 0, n);
12617 + }
12618 return n;
12619 }
12620
12621 static __always_inline __must_check
12622 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12623 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12624 +static __always_inline __must_check
12625 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12626 {
12627 might_fault();
12628
12629 - return _copy_to_user(dst, src, size);
12630 + if (access_ok(VERIFY_WRITE, dst, size))
12631 + size = __copy_to_user(dst, src, size);
12632 + return size;
12633 }
12634
12635 static __always_inline __must_check
12636 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12637 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12638 +static __always_inline __must_check
12639 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12640 {
12641 - int ret = 0;
12642 + int sz = __compiletime_object_size(dst);
12643 + unsigned ret = 0;
12644
12645 might_fault();
12646 - if (!__builtin_constant_p(size))
12647 - return copy_user_generic(dst, (__force void *)src, size);
12648 +
12649 + if (size > INT_MAX)
12650 + return size;
12651 +
12652 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12653 + if (!__access_ok(VERIFY_READ, src, size))
12654 + return size;
12655 +#endif
12656 +
12657 + if (unlikely(sz != -1 && sz < size)) {
12658 +#ifdef CONFIG_DEBUG_VM
12659 + WARN(1, "Buffer overflow detected!\n");
12660 +#endif
12661 + return size;
12662 + }
12663 +
12664 + if (!__builtin_constant_p(size)) {
12665 + check_object_size(dst, size, false);
12666 +
12667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12668 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12669 + src += PAX_USER_SHADOW_BASE;
12670 +#endif
12671 +
12672 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12673 + }
12674 switch (size) {
12675 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12676 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12677 ret, "b", "b", "=q", 1);
12678 return ret;
12679 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12680 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12681 ret, "w", "w", "=r", 2);
12682 return ret;
12683 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12684 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12685 ret, "l", "k", "=r", 4);
12686 return ret;
12687 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12688 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12689 ret, "q", "", "=r", 8);
12690 return ret;
12691 case 10:
12692 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12693 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12694 ret, "q", "", "=r", 10);
12695 if (unlikely(ret))
12696 return ret;
12697 __get_user_asm(*(u16 *)(8 + (char *)dst),
12698 - (u16 __user *)(8 + (char __user *)src),
12699 + (const u16 __user *)(8 + (const char __user *)src),
12700 ret, "w", "w", "=r", 2);
12701 return ret;
12702 case 16:
12703 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12704 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12705 ret, "q", "", "=r", 16);
12706 if (unlikely(ret))
12707 return ret;
12708 __get_user_asm(*(u64 *)(8 + (char *)dst),
12709 - (u64 __user *)(8 + (char __user *)src),
12710 + (const u64 __user *)(8 + (const char __user *)src),
12711 ret, "q", "", "=r", 8);
12712 return ret;
12713 default:
12714 - return copy_user_generic(dst, (__force void *)src, size);
12715 +
12716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12717 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12718 + src += PAX_USER_SHADOW_BASE;
12719 +#endif
12720 +
12721 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12722 }
12723 }
12724
12725 static __always_inline __must_check
12726 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12727 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12728 +static __always_inline __must_check
12729 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12730 {
12731 - int ret = 0;
12732 + int sz = __compiletime_object_size(src);
12733 + unsigned ret = 0;
12734
12735 might_fault();
12736 - if (!__builtin_constant_p(size))
12737 - return copy_user_generic((__force void *)dst, src, size);
12738 +
12739 + if (size > INT_MAX)
12740 + return size;
12741 +
12742 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12743 + if (!__access_ok(VERIFY_WRITE, dst, size))
12744 + return size;
12745 +#endif
12746 +
12747 + if (unlikely(sz != -1 && sz < size)) {
12748 +#ifdef CONFIG_DEBUG_VM
12749 + WARN(1, "Buffer overflow detected!\n");
12750 +#endif
12751 + return size;
12752 + }
12753 +
12754 + if (!__builtin_constant_p(size)) {
12755 + check_object_size(src, size, true);
12756 +
12757 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12758 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12759 + dst += PAX_USER_SHADOW_BASE;
12760 +#endif
12761 +
12762 + return copy_user_generic((__force_kernel void *)dst, src, size);
12763 + }
12764 switch (size) {
12765 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12766 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12767 ret, "b", "b", "iq", 1);
12768 return ret;
12769 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12770 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12771 ret, "w", "w", "ir", 2);
12772 return ret;
12773 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12774 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12775 ret, "l", "k", "ir", 4);
12776 return ret;
12777 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12778 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12779 ret, "q", "", "er", 8);
12780 return ret;
12781 case 10:
12782 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12783 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12784 ret, "q", "", "er", 10);
12785 if (unlikely(ret))
12786 return ret;
12787 asm("":::"memory");
12788 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12789 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12790 ret, "w", "w", "ir", 2);
12791 return ret;
12792 case 16:
12793 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12794 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12795 ret, "q", "", "er", 16);
12796 if (unlikely(ret))
12797 return ret;
12798 asm("":::"memory");
12799 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12800 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12801 ret, "q", "", "er", 8);
12802 return ret;
12803 default:
12804 - return copy_user_generic((__force void *)dst, src, size);
12805 +
12806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12807 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12808 + dst += PAX_USER_SHADOW_BASE;
12809 +#endif
12810 +
12811 + return copy_user_generic((__force_kernel void *)dst, src, size);
12812 }
12813 }
12814
12815 static __always_inline __must_check
12816 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12817 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
12818 +static __always_inline __must_check
12819 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12820 {
12821 - int ret = 0;
12822 + unsigned ret = 0;
12823
12824 might_fault();
12825 - if (!__builtin_constant_p(size))
12826 - return copy_user_generic((__force void *)dst,
12827 - (__force void *)src, size);
12828 +
12829 + if (size > INT_MAX)
12830 + return size;
12831 +
12832 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12833 + if (!__access_ok(VERIFY_READ, src, size))
12834 + return size;
12835 + if (!__access_ok(VERIFY_WRITE, dst, size))
12836 + return size;
12837 +#endif
12838 +
12839 + if (!__builtin_constant_p(size)) {
12840 +
12841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12842 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12843 + src += PAX_USER_SHADOW_BASE;
12844 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12845 + dst += PAX_USER_SHADOW_BASE;
12846 +#endif
12847 +
12848 + return copy_user_generic((__force_kernel void *)dst,
12849 + (__force_kernel const void *)src, size);
12850 + }
12851 switch (size) {
12852 case 1: {
12853 u8 tmp;
12854 - __get_user_asm(tmp, (u8 __user *)src,
12855 + __get_user_asm(tmp, (const u8 __user *)src,
12856 ret, "b", "b", "=q", 1);
12857 if (likely(!ret))
12858 __put_user_asm(tmp, (u8 __user *)dst,
12859 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12860 }
12861 case 2: {
12862 u16 tmp;
12863 - __get_user_asm(tmp, (u16 __user *)src,
12864 + __get_user_asm(tmp, (const u16 __user *)src,
12865 ret, "w", "w", "=r", 2);
12866 if (likely(!ret))
12867 __put_user_asm(tmp, (u16 __user *)dst,
12868 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12869
12870 case 4: {
12871 u32 tmp;
12872 - __get_user_asm(tmp, (u32 __user *)src,
12873 + __get_user_asm(tmp, (const u32 __user *)src,
12874 ret, "l", "k", "=r", 4);
12875 if (likely(!ret))
12876 __put_user_asm(tmp, (u32 __user *)dst,
12877 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12878 }
12879 case 8: {
12880 u64 tmp;
12881 - __get_user_asm(tmp, (u64 __user *)src,
12882 + __get_user_asm(tmp, (const u64 __user *)src,
12883 ret, "q", "", "=r", 8);
12884 if (likely(!ret))
12885 __put_user_asm(tmp, (u64 __user *)dst,
12886 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12887 return ret;
12888 }
12889 default:
12890 - return copy_user_generic((__force void *)dst,
12891 - (__force void *)src, size);
12892 +
12893 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12894 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12895 + src += PAX_USER_SHADOW_BASE;
12896 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12897 + dst += PAX_USER_SHADOW_BASE;
12898 +#endif
12899 +
12900 + return copy_user_generic((__force_kernel void *)dst,
12901 + (__force_kernel const void *)src, size);
12902 }
12903 }
12904
12905 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
12906 __must_check long strnlen_user(const char __user *str, long n);
12907 __must_check long __strnlen_user(const char __user *str, long n);
12908 __must_check long strlen_user(const char __user *str);
12909 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
12910 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12911 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12912 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12913
12914 static __must_check __always_inline int
12915 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12916 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12917 +static __must_check __always_inline int
12918 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12919 {
12920 - return copy_user_generic(dst, (__force const void *)src, size);
12921 + if (size > INT_MAX)
12922 + return size;
12923 +
12924 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12925 + if (!__access_ok(VERIFY_READ, src, size))
12926 + return size;
12927 +
12928 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12929 + src += PAX_USER_SHADOW_BASE;
12930 +#endif
12931 +
12932 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12933 }
12934
12935 -static __must_check __always_inline int
12936 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12937 +static __must_check __always_inline unsigned long
12938 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12939 +static __must_check __always_inline unsigned long
12940 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12941 {
12942 - return copy_user_generic((__force void *)dst, src, size);
12943 + if (size > INT_MAX)
12944 + return size;
12945 +
12946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12947 + if (!__access_ok(VERIFY_WRITE, dst, size))
12948 + return size;
12949 +
12950 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12951 + dst += PAX_USER_SHADOW_BASE;
12952 +#endif
12953 +
12954 + return copy_user_generic((__force_kernel void *)dst, src, size);
12955 }
12956
12957 -extern long __copy_user_nocache(void *dst, const void __user *src,
12958 - unsigned size, int zerorest);
12959 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12960 + unsigned long size, int zerorest) __size_overflow(3);
12961
12962 -static inline int
12963 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12964 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12965 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12966 {
12967 might_sleep();
12968 +
12969 + if (size > INT_MAX)
12970 + return size;
12971 +
12972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12973 + if (!__access_ok(VERIFY_READ, src, size))
12974 + return size;
12975 +#endif
12976 +
12977 return __copy_user_nocache(dst, src, size, 1);
12978 }
12979
12980 -static inline int
12981 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12982 - unsigned size)
12983 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12984 + unsigned long size) __size_overflow(3);
12985 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12986 + unsigned long size)
12987 {
12988 + if (size > INT_MAX)
12989 + return size;
12990 +
12991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12992 + if (!__access_ok(VERIFY_READ, src, size))
12993 + return size;
12994 +#endif
12995 +
12996 return __copy_user_nocache(dst, src, size, 0);
12997 }
12998
12999 -unsigned long
13000 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13001 +extern unsigned long
13002 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13003
13004 #endif /* _ASM_X86_UACCESS_64_H */
13005 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13006 index bb05228..d763d5b 100644
13007 --- a/arch/x86/include/asm/vdso.h
13008 +++ b/arch/x86/include/asm/vdso.h
13009 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13010 #define VDSO32_SYMBOL(base, name) \
13011 ({ \
13012 extern const char VDSO32_##name[]; \
13013 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13014 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13015 })
13016 #endif
13017
13018 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13019 index 517d476..a1cb4d9 100644
13020 --- a/arch/x86/include/asm/x86_init.h
13021 +++ b/arch/x86/include/asm/x86_init.h
13022 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13023 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13024 void (*find_smp_config)(void);
13025 void (*get_smp_config)(unsigned int early);
13026 -};
13027 +} __no_const;
13028
13029 /**
13030 * struct x86_init_resources - platform specific resource related ops
13031 @@ -43,7 +43,7 @@ struct x86_init_resources {
13032 void (*probe_roms)(void);
13033 void (*reserve_resources)(void);
13034 char *(*memory_setup)(void);
13035 -};
13036 +} __no_const;
13037
13038 /**
13039 * struct x86_init_irqs - platform specific interrupt setup
13040 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13041 void (*pre_vector_init)(void);
13042 void (*intr_init)(void);
13043 void (*trap_init)(void);
13044 -};
13045 +} __no_const;
13046
13047 /**
13048 * struct x86_init_oem - oem platform specific customizing functions
13049 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13050 struct x86_init_oem {
13051 void (*arch_setup)(void);
13052 void (*banner)(void);
13053 -};
13054 +} __no_const;
13055
13056 /**
13057 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13058 @@ -77,7 +77,7 @@ struct x86_init_oem {
13059 */
13060 struct x86_init_mapping {
13061 void (*pagetable_reserve)(u64 start, u64 end);
13062 -};
13063 +} __no_const;
13064
13065 /**
13066 * struct x86_init_paging - platform specific paging functions
13067 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13068 struct x86_init_paging {
13069 void (*pagetable_setup_start)(pgd_t *base);
13070 void (*pagetable_setup_done)(pgd_t *base);
13071 -};
13072 +} __no_const;
13073
13074 /**
13075 * struct x86_init_timers - platform specific timer setup
13076 @@ -102,7 +102,7 @@ struct x86_init_timers {
13077 void (*tsc_pre_init)(void);
13078 void (*timer_init)(void);
13079 void (*wallclock_init)(void);
13080 -};
13081 +} __no_const;
13082
13083 /**
13084 * struct x86_init_iommu - platform specific iommu setup
13085 @@ -110,7 +110,7 @@ struct x86_init_timers {
13086 */
13087 struct x86_init_iommu {
13088 int (*iommu_init)(void);
13089 -};
13090 +} __no_const;
13091
13092 /**
13093 * struct x86_init_pci - platform specific pci init functions
13094 @@ -124,7 +124,7 @@ struct x86_init_pci {
13095 int (*init)(void);
13096 void (*init_irq)(void);
13097 void (*fixup_irqs)(void);
13098 -};
13099 +} __no_const;
13100
13101 /**
13102 * struct x86_init_ops - functions for platform specific setup
13103 @@ -140,7 +140,7 @@ struct x86_init_ops {
13104 struct x86_init_timers timers;
13105 struct x86_init_iommu iommu;
13106 struct x86_init_pci pci;
13107 -};
13108 +} __no_const;
13109
13110 /**
13111 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13112 @@ -149,7 +149,7 @@ struct x86_init_ops {
13113 struct x86_cpuinit_ops {
13114 void (*setup_percpu_clockev)(void);
13115 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13116 -};
13117 +} __no_const;
13118
13119 /**
13120 * struct x86_platform_ops - platform specific runtime functions
13121 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13122 void (*nmi_init)(void);
13123 unsigned char (*get_nmi_reason)(void);
13124 int (*i8042_detect)(void);
13125 -};
13126 +} __no_const;
13127
13128 struct pci_dev;
13129
13130 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13131 void (*teardown_msi_irq)(unsigned int irq);
13132 void (*teardown_msi_irqs)(struct pci_dev *dev);
13133 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13134 -};
13135 +} __no_const;
13136
13137 extern struct x86_init_ops x86_init;
13138 extern struct x86_cpuinit_ops x86_cpuinit;
13139 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13140 index c6ce245..ffbdab7 100644
13141 --- a/arch/x86/include/asm/xsave.h
13142 +++ b/arch/x86/include/asm/xsave.h
13143 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13144 {
13145 int err;
13146
13147 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13148 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13149 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13150 +#endif
13151 +
13152 /*
13153 * Clear the xsave header first, so that reserved fields are
13154 * initialized to zero.
13155 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13156 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13157 {
13158 int err;
13159 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13160 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13161 u32 lmask = mask;
13162 u32 hmask = mask >> 32;
13163
13164 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13165 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13166 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13167 +#endif
13168 +
13169 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13170 "2:\n"
13171 ".section .fixup,\"ax\"\n"
13172 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13173 index 6a564ac..9b1340c 100644
13174 --- a/arch/x86/kernel/acpi/realmode/Makefile
13175 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13176 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13177 $(call cc-option, -fno-stack-protector) \
13178 $(call cc-option, -mpreferred-stack-boundary=2)
13179 KBUILD_CFLAGS += $(call cc-option, -m32)
13180 +ifdef CONSTIFY_PLUGIN
13181 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13182 +endif
13183 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13184 GCOV_PROFILE := n
13185
13186 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13187 index b4fd836..4358fe3 100644
13188 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13189 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13190 @@ -108,6 +108,9 @@ wakeup_code:
13191 /* Do any other stuff... */
13192
13193 #ifndef CONFIG_64BIT
13194 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13195 + call verify_cpu
13196 +
13197 /* This could also be done in C code... */
13198 movl pmode_cr3, %eax
13199 movl %eax, %cr3
13200 @@ -131,6 +134,7 @@ wakeup_code:
13201 movl pmode_cr0, %eax
13202 movl %eax, %cr0
13203 jmp pmode_return
13204 +# include "../../verify_cpu.S"
13205 #else
13206 pushw $0
13207 pushw trampoline_segment
13208 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13209 index 103b6ab..2004d0a 100644
13210 --- a/arch/x86/kernel/acpi/sleep.c
13211 +++ b/arch/x86/kernel/acpi/sleep.c
13212 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13213 header->trampoline_segment = trampoline_address() >> 4;
13214 #ifdef CONFIG_SMP
13215 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13216 +
13217 + pax_open_kernel();
13218 early_gdt_descr.address =
13219 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13220 + pax_close_kernel();
13221 +
13222 initial_gs = per_cpu_offset(smp_processor_id());
13223 #endif
13224 initial_code = (unsigned long)wakeup_long64;
13225 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13226 index 13ab720..95d5442 100644
13227 --- a/arch/x86/kernel/acpi/wakeup_32.S
13228 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13229 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13230 # and restore the stack ... but you need gdt for this to work
13231 movl saved_context_esp, %esp
13232
13233 - movl %cs:saved_magic, %eax
13234 - cmpl $0x12345678, %eax
13235 + cmpl $0x12345678, saved_magic
13236 jne bogus_magic
13237
13238 # jump to place where we left off
13239 - movl saved_eip, %eax
13240 - jmp *%eax
13241 + jmp *(saved_eip)
13242
13243 bogus_magic:
13244 jmp bogus_magic
13245 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13246 index 1f84794..e23f862 100644
13247 --- a/arch/x86/kernel/alternative.c
13248 +++ b/arch/x86/kernel/alternative.c
13249 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13250 */
13251 for (a = start; a < end; a++) {
13252 instr = (u8 *)&a->instr_offset + a->instr_offset;
13253 +
13254 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13255 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13256 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13257 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13258 +#endif
13259 +
13260 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13261 BUG_ON(a->replacementlen > a->instrlen);
13262 BUG_ON(a->instrlen > sizeof(insnbuf));
13263 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13264 for (poff = start; poff < end; poff++) {
13265 u8 *ptr = (u8 *)poff + *poff;
13266
13267 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13268 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13269 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13270 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13271 +#endif
13272 +
13273 if (!*poff || ptr < text || ptr >= text_end)
13274 continue;
13275 /* turn DS segment override prefix into lock prefix */
13276 - if (*ptr == 0x3e)
13277 + if (*ktla_ktva(ptr) == 0x3e)
13278 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13279 };
13280 mutex_unlock(&text_mutex);
13281 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13282 for (poff = start; poff < end; poff++) {
13283 u8 *ptr = (u8 *)poff + *poff;
13284
13285 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13286 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13287 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13288 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13289 +#endif
13290 +
13291 if (!*poff || ptr < text || ptr >= text_end)
13292 continue;
13293 /* turn lock prefix into DS segment override prefix */
13294 - if (*ptr == 0xf0)
13295 + if (*ktla_ktva(ptr) == 0xf0)
13296 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13297 };
13298 mutex_unlock(&text_mutex);
13299 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13300
13301 BUG_ON(p->len > MAX_PATCH_LEN);
13302 /* prep the buffer with the original instructions */
13303 - memcpy(insnbuf, p->instr, p->len);
13304 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13305 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13306 (unsigned long)p->instr, p->len);
13307
13308 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13309 if (smp_alt_once)
13310 free_init_pages("SMP alternatives",
13311 (unsigned long)__smp_locks,
13312 - (unsigned long)__smp_locks_end);
13313 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13314
13315 restart_nmi();
13316 }
13317 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13318 * instructions. And on the local CPU you need to be protected again NMI or MCE
13319 * handlers seeing an inconsistent instruction while you patch.
13320 */
13321 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13322 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13323 size_t len)
13324 {
13325 unsigned long flags;
13326 local_irq_save(flags);
13327 - memcpy(addr, opcode, len);
13328 +
13329 + pax_open_kernel();
13330 + memcpy(ktla_ktva(addr), opcode, len);
13331 sync_core();
13332 + pax_close_kernel();
13333 +
13334 local_irq_restore(flags);
13335 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13336 that causes hangs on some VIA CPUs. */
13337 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13338 */
13339 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13340 {
13341 - unsigned long flags;
13342 - char *vaddr;
13343 + unsigned char *vaddr = ktla_ktva(addr);
13344 struct page *pages[2];
13345 - int i;
13346 + size_t i;
13347
13348 if (!core_kernel_text((unsigned long)addr)) {
13349 - pages[0] = vmalloc_to_page(addr);
13350 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13351 + pages[0] = vmalloc_to_page(vaddr);
13352 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13353 } else {
13354 - pages[0] = virt_to_page(addr);
13355 + pages[0] = virt_to_page(vaddr);
13356 WARN_ON(!PageReserved(pages[0]));
13357 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13358 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13359 }
13360 BUG_ON(!pages[0]);
13361 - local_irq_save(flags);
13362 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13363 - if (pages[1])
13364 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13365 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13366 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13367 - clear_fixmap(FIX_TEXT_POKE0);
13368 - if (pages[1])
13369 - clear_fixmap(FIX_TEXT_POKE1);
13370 - local_flush_tlb();
13371 - sync_core();
13372 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13373 - that causes hangs on some VIA CPUs. */
13374 + text_poke_early(addr, opcode, len);
13375 for (i = 0; i < len; i++)
13376 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13377 - local_irq_restore(flags);
13378 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13379 return addr;
13380 }
13381
13382 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13383 index 2eec05b..fef012b 100644
13384 --- a/arch/x86/kernel/apic/apic.c
13385 +++ b/arch/x86/kernel/apic/apic.c
13386 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13387 /*
13388 * Debug level, exported for io_apic.c
13389 */
13390 -unsigned int apic_verbosity;
13391 +int apic_verbosity;
13392
13393 int pic_mode;
13394
13395 @@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13396 apic_write(APIC_ESR, 0);
13397 v1 = apic_read(APIC_ESR);
13398 ack_APIC_irq();
13399 - atomic_inc(&irq_err_count);
13400 + atomic_inc_unchecked(&irq_err_count);
13401
13402 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13403 smp_processor_id(), v0 , v1);
13404 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13405 index fb07275..e06bb59 100644
13406 --- a/arch/x86/kernel/apic/io_apic.c
13407 +++ b/arch/x86/kernel/apic/io_apic.c
13408 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13409 }
13410 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13411
13412 -void lock_vector_lock(void)
13413 +void lock_vector_lock(void) __acquires(vector_lock)
13414 {
13415 /* Used to the online set of cpus does not change
13416 * during assign_irq_vector.
13417 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13418 raw_spin_lock(&vector_lock);
13419 }
13420
13421 -void unlock_vector_lock(void)
13422 +void unlock_vector_lock(void) __releases(vector_lock)
13423 {
13424 raw_spin_unlock(&vector_lock);
13425 }
13426 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13427 ack_APIC_irq();
13428 }
13429
13430 -atomic_t irq_mis_count;
13431 +atomic_unchecked_t irq_mis_count;
13432
13433 static void ack_apic_level(struct irq_data *data)
13434 {
13435 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13436 * at the cpu.
13437 */
13438 if (!(v & (1 << (i & 0x1f)))) {
13439 - atomic_inc(&irq_mis_count);
13440 + atomic_inc_unchecked(&irq_mis_count);
13441
13442 eoi_ioapic_irq(irq, cfg);
13443 }
13444 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13445 index f76623c..aab694f 100644
13446 --- a/arch/x86/kernel/apm_32.c
13447 +++ b/arch/x86/kernel/apm_32.c
13448 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13449 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13450 * even though they are called in protected mode.
13451 */
13452 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13453 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13454 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13455
13456 static const char driver_version[] = "1.16ac"; /* no spaces */
13457 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13458 BUG_ON(cpu != 0);
13459 gdt = get_cpu_gdt_table(cpu);
13460 save_desc_40 = gdt[0x40 / 8];
13461 +
13462 + pax_open_kernel();
13463 gdt[0x40 / 8] = bad_bios_desc;
13464 + pax_close_kernel();
13465
13466 apm_irq_save(flags);
13467 APM_DO_SAVE_SEGS;
13468 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13469 &call->esi);
13470 APM_DO_RESTORE_SEGS;
13471 apm_irq_restore(flags);
13472 +
13473 + pax_open_kernel();
13474 gdt[0x40 / 8] = save_desc_40;
13475 + pax_close_kernel();
13476 +
13477 put_cpu();
13478
13479 return call->eax & 0xff;
13480 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13481 BUG_ON(cpu != 0);
13482 gdt = get_cpu_gdt_table(cpu);
13483 save_desc_40 = gdt[0x40 / 8];
13484 +
13485 + pax_open_kernel();
13486 gdt[0x40 / 8] = bad_bios_desc;
13487 + pax_close_kernel();
13488
13489 apm_irq_save(flags);
13490 APM_DO_SAVE_SEGS;
13491 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13492 &call->eax);
13493 APM_DO_RESTORE_SEGS;
13494 apm_irq_restore(flags);
13495 +
13496 + pax_open_kernel();
13497 gdt[0x40 / 8] = save_desc_40;
13498 + pax_close_kernel();
13499 +
13500 put_cpu();
13501 return error;
13502 }
13503 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13504 * code to that CPU.
13505 */
13506 gdt = get_cpu_gdt_table(0);
13507 +
13508 + pax_open_kernel();
13509 set_desc_base(&gdt[APM_CS >> 3],
13510 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13511 set_desc_base(&gdt[APM_CS_16 >> 3],
13512 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13513 set_desc_base(&gdt[APM_DS >> 3],
13514 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13515 + pax_close_kernel();
13516
13517 proc_create("apm", 0, NULL, &apm_file_ops);
13518
13519 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13520 index 68de2dc..1f3c720 100644
13521 --- a/arch/x86/kernel/asm-offsets.c
13522 +++ b/arch/x86/kernel/asm-offsets.c
13523 @@ -33,6 +33,8 @@ void common(void) {
13524 OFFSET(TI_status, thread_info, status);
13525 OFFSET(TI_addr_limit, thread_info, addr_limit);
13526 OFFSET(TI_preempt_count, thread_info, preempt_count);
13527 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13528 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13529
13530 BLANK();
13531 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13532 @@ -53,8 +55,26 @@ void common(void) {
13533 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13534 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13535 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13536 +
13537 +#ifdef CONFIG_PAX_KERNEXEC
13538 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13539 #endif
13540
13541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13542 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13543 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13544 +#ifdef CONFIG_X86_64
13545 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13546 +#endif
13547 +#endif
13548 +
13549 +#endif
13550 +
13551 + BLANK();
13552 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13553 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13554 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13555 +
13556 #ifdef CONFIG_XEN
13557 BLANK();
13558 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13559 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13560 index 834e897..dacddc8 100644
13561 --- a/arch/x86/kernel/asm-offsets_64.c
13562 +++ b/arch/x86/kernel/asm-offsets_64.c
13563 @@ -70,6 +70,7 @@ int main(void)
13564 BLANK();
13565 #undef ENTRY
13566
13567 + DEFINE(TSS_size, sizeof(struct tss_struct));
13568 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13569 BLANK();
13570
13571 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13572 index 25f24dc..4094a7f 100644
13573 --- a/arch/x86/kernel/cpu/Makefile
13574 +++ b/arch/x86/kernel/cpu/Makefile
13575 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13576 CFLAGS_REMOVE_perf_event.o = -pg
13577 endif
13578
13579 -# Make sure load_percpu_segment has no stackprotector
13580 -nostackp := $(call cc-option, -fno-stack-protector)
13581 -CFLAGS_common.o := $(nostackp)
13582 -
13583 obj-y := intel_cacheinfo.o scattered.o topology.o
13584 obj-y += proc.o capflags.o powerflags.o common.o
13585 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13586 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13587 index f4773f4..b3fb13c 100644
13588 --- a/arch/x86/kernel/cpu/amd.c
13589 +++ b/arch/x86/kernel/cpu/amd.c
13590 @@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13591 unsigned int size)
13592 {
13593 /* AMD errata T13 (order #21922) */
13594 - if ((c->x86 == 6)) {
13595 + if (c->x86 == 6) {
13596 /* Duron Rev A0 */
13597 if (c->x86_model == 3 && c->x86_mask == 0)
13598 size = 64;
13599 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13600 index c0f7d68..aa418f9 100644
13601 --- a/arch/x86/kernel/cpu/common.c
13602 +++ b/arch/x86/kernel/cpu/common.c
13603 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13604
13605 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13606
13607 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13608 -#ifdef CONFIG_X86_64
13609 - /*
13610 - * We need valid kernel segments for data and code in long mode too
13611 - * IRET will check the segment types kkeil 2000/10/28
13612 - * Also sysret mandates a special GDT layout
13613 - *
13614 - * TLS descriptors are currently at a different place compared to i386.
13615 - * Hopefully nobody expects them at a fixed place (Wine?)
13616 - */
13617 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13618 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13619 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13620 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13621 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13622 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13623 -#else
13624 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13625 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13626 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13627 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13628 - /*
13629 - * Segments used for calling PnP BIOS have byte granularity.
13630 - * They code segments and data segments have fixed 64k limits,
13631 - * the transfer segment sizes are set at run time.
13632 - */
13633 - /* 32-bit code */
13634 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13635 - /* 16-bit code */
13636 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13637 - /* 16-bit data */
13638 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13639 - /* 16-bit data */
13640 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13641 - /* 16-bit data */
13642 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13643 - /*
13644 - * The APM segments have byte granularity and their bases
13645 - * are set at run time. All have 64k limits.
13646 - */
13647 - /* 32-bit code */
13648 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13649 - /* 16-bit code */
13650 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13651 - /* data */
13652 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13653 -
13654 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13655 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13656 - GDT_STACK_CANARY_INIT
13657 -#endif
13658 -} };
13659 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13660 -
13661 static int __init x86_xsave_setup(char *s)
13662 {
13663 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13664 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13665 {
13666 struct desc_ptr gdt_descr;
13667
13668 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13669 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13670 gdt_descr.size = GDT_SIZE - 1;
13671 load_gdt(&gdt_descr);
13672 /* Reload the per-cpu base */
13673 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13674 /* Filter out anything that depends on CPUID levels we don't have */
13675 filter_cpuid_features(c, true);
13676
13677 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13678 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13679 +#endif
13680 +
13681 /* If the model name is still unset, do table lookup. */
13682 if (!c->x86_model_id[0]) {
13683 const char *p;
13684 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13685 }
13686 __setup("clearcpuid=", setup_disablecpuid);
13687
13688 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13689 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13690 +
13691 #ifdef CONFIG_X86_64
13692 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13693 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13694 - (unsigned long) nmi_idt_table };
13695 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13696
13697 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13698 irq_stack_union) __aligned(PAGE_SIZE);
13699 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13700 EXPORT_PER_CPU_SYMBOL(current_task);
13701
13702 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13703 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13704 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13705 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13706
13707 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13708 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13709 {
13710 memset(regs, 0, sizeof(struct pt_regs));
13711 regs->fs = __KERNEL_PERCPU;
13712 - regs->gs = __KERNEL_STACK_CANARY;
13713 + savesegment(gs, regs->gs);
13714
13715 return regs;
13716 }
13717 @@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13718 int i;
13719
13720 cpu = stack_smp_processor_id();
13721 - t = &per_cpu(init_tss, cpu);
13722 + t = init_tss + cpu;
13723 oist = &per_cpu(orig_ist, cpu);
13724
13725 #ifdef CONFIG_NUMA
13726 @@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13727 switch_to_new_gdt(cpu);
13728 loadsegment(fs, 0);
13729
13730 - load_idt((const struct desc_ptr *)&idt_descr);
13731 + load_idt(&idt_descr);
13732
13733 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13734 syscall_init();
13735 @@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13736 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13737 barrier();
13738
13739 - x86_configure_nx();
13740 if (cpu != 0)
13741 enable_x2apic();
13742
13743 @@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13744 {
13745 int cpu = smp_processor_id();
13746 struct task_struct *curr = current;
13747 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13748 + struct tss_struct *t = init_tss + cpu;
13749 struct thread_struct *thread = &curr->thread;
13750
13751 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13752 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13753 index 3e6ff6c..54b4992 100644
13754 --- a/arch/x86/kernel/cpu/intel.c
13755 +++ b/arch/x86/kernel/cpu/intel.c
13756 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13757 * Update the IDT descriptor and reload the IDT so that
13758 * it uses the read-only mapped virtual address.
13759 */
13760 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13761 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13762 load_idt(&idt_descr);
13763 }
13764 #endif
13765 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13766 index fc4beb3..f20a5a7 100644
13767 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13768 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13769 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
13770
13771 /* Error injection interface */
13772 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13773 + size_t usize, loff_t *off) __size_overflow(3);
13774 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13775 size_t usize, loff_t *off)
13776 {
13777 struct mce m;
13778 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13779 index 5a11ae2..a1a1c8a 100644
13780 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13781 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13782 @@ -42,6 +42,7 @@
13783 #include <asm/processor.h>
13784 #include <asm/mce.h>
13785 #include <asm/msr.h>
13786 +#include <asm/local.h>
13787
13788 #include "mce-internal.h"
13789
13790 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13791 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13792 m->cs, m->ip);
13793
13794 - if (m->cs == __KERNEL_CS)
13795 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13796 print_symbol("{%s}", m->ip);
13797 pr_cont("\n");
13798 }
13799 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13800
13801 #define PANIC_TIMEOUT 5 /* 5 seconds */
13802
13803 -static atomic_t mce_paniced;
13804 +static atomic_unchecked_t mce_paniced;
13805
13806 static int fake_panic;
13807 -static atomic_t mce_fake_paniced;
13808 +static atomic_unchecked_t mce_fake_paniced;
13809
13810 /* Panic in progress. Enable interrupts and wait for final IPI */
13811 static void wait_for_panic(void)
13812 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13813 /*
13814 * Make sure only one CPU runs in machine check panic
13815 */
13816 - if (atomic_inc_return(&mce_paniced) > 1)
13817 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13818 wait_for_panic();
13819 barrier();
13820
13821 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13822 console_verbose();
13823 } else {
13824 /* Don't log too much for fake panic */
13825 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13826 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13827 return;
13828 }
13829 /* First print corrected ones that are still unlogged */
13830 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13831 * might have been modified by someone else.
13832 */
13833 rmb();
13834 - if (atomic_read(&mce_paniced))
13835 + if (atomic_read_unchecked(&mce_paniced))
13836 wait_for_panic();
13837 if (!monarch_timeout)
13838 goto out;
13839 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13840 }
13841
13842 /* Call the installed machine check handler for this CPU setup. */
13843 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13844 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13845 unexpected_machine_check;
13846
13847 /*
13848 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13849 return;
13850 }
13851
13852 + pax_open_kernel();
13853 machine_check_vector = do_machine_check;
13854 + pax_close_kernel();
13855
13856 __mcheck_cpu_init_generic();
13857 __mcheck_cpu_init_vendor(c);
13858 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13859 */
13860
13861 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13862 -static int mce_chrdev_open_count; /* #times opened */
13863 +static local_t mce_chrdev_open_count; /* #times opened */
13864 static int mce_chrdev_open_exclu; /* already open exclusive? */
13865
13866 static int mce_chrdev_open(struct inode *inode, struct file *file)
13867 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13868 spin_lock(&mce_chrdev_state_lock);
13869
13870 if (mce_chrdev_open_exclu ||
13871 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13872 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13873 spin_unlock(&mce_chrdev_state_lock);
13874
13875 return -EBUSY;
13876 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13877
13878 if (file->f_flags & O_EXCL)
13879 mce_chrdev_open_exclu = 1;
13880 - mce_chrdev_open_count++;
13881 + local_inc(&mce_chrdev_open_count);
13882
13883 spin_unlock(&mce_chrdev_state_lock);
13884
13885 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13886 {
13887 spin_lock(&mce_chrdev_state_lock);
13888
13889 - mce_chrdev_open_count--;
13890 + local_dec(&mce_chrdev_open_count);
13891 mce_chrdev_open_exclu = 0;
13892
13893 spin_unlock(&mce_chrdev_state_lock);
13894 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13895 static void mce_reset(void)
13896 {
13897 cpu_missing = 0;
13898 - atomic_set(&mce_fake_paniced, 0);
13899 + atomic_set_unchecked(&mce_fake_paniced, 0);
13900 atomic_set(&mce_executing, 0);
13901 atomic_set(&mce_callin, 0);
13902 atomic_set(&global_nwo, 0);
13903 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13904 index 5c0e653..0882b0a 100644
13905 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13906 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13907 @@ -12,6 +12,7 @@
13908 #include <asm/system.h>
13909 #include <asm/mce.h>
13910 #include <asm/msr.h>
13911 +#include <asm/pgtable.h>
13912
13913 /* By default disabled */
13914 int mce_p5_enabled __read_mostly;
13915 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13916 if (!cpu_has(c, X86_FEATURE_MCE))
13917 return;
13918
13919 + pax_open_kernel();
13920 machine_check_vector = pentium_machine_check;
13921 + pax_close_kernel();
13922 /* Make sure the vector pointer is visible before we enable MCEs: */
13923 wmb();
13924
13925 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13926 index 54060f5..c1a7577 100644
13927 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13928 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13929 @@ -11,6 +11,7 @@
13930 #include <asm/system.h>
13931 #include <asm/mce.h>
13932 #include <asm/msr.h>
13933 +#include <asm/pgtable.h>
13934
13935 /* Machine check handler for WinChip C6: */
13936 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13937 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13938 {
13939 u32 lo, hi;
13940
13941 + pax_open_kernel();
13942 machine_check_vector = winchip_machine_check;
13943 + pax_close_kernel();
13944 /* Make sure the vector pointer is visible before we enable MCEs: */
13945 wmb();
13946
13947 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
13948 index 7928963..1b16001 100644
13949 --- a/arch/x86/kernel/cpu/mtrr/if.c
13950 +++ b/arch/x86/kernel/cpu/mtrr/if.c
13951 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
13952 * "base=%Lx size=%Lx type=%s" or "disable=%d"
13953 */
13954 static ssize_t
13955 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
13956 +static ssize_t
13957 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
13958 {
13959 int i, err;
13960 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13961 index 6b96110..0da73eb 100644
13962 --- a/arch/x86/kernel/cpu/mtrr/main.c
13963 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13964 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13965 u64 size_or_mask, size_and_mask;
13966 static bool mtrr_aps_delayed_init;
13967
13968 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13969 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13970
13971 const struct mtrr_ops *mtrr_if;
13972
13973 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13974 index df5e41f..816c719 100644
13975 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13976 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13977 @@ -25,7 +25,7 @@ struct mtrr_ops {
13978 int (*validate_add_page)(unsigned long base, unsigned long size,
13979 unsigned int type);
13980 int (*have_wrcomb)(void);
13981 -};
13982 +} __do_const;
13983
13984 extern int generic_get_free_region(unsigned long base, unsigned long size,
13985 int replace_reg);
13986 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13987 index 5adce10..99284ec 100644
13988 --- a/arch/x86/kernel/cpu/perf_event.c
13989 +++ b/arch/x86/kernel/cpu/perf_event.c
13990 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13991 break;
13992
13993 perf_callchain_store(entry, frame.return_address);
13994 - fp = frame.next_frame;
13995 + fp = (const void __force_user *)frame.next_frame;
13996 }
13997 }
13998
13999 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14000 index 13ad899..f642b9a 100644
14001 --- a/arch/x86/kernel/crash.c
14002 +++ b/arch/x86/kernel/crash.c
14003 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14004 {
14005 #ifdef CONFIG_X86_32
14006 struct pt_regs fixed_regs;
14007 -#endif
14008
14009 -#ifdef CONFIG_X86_32
14010 - if (!user_mode_vm(regs)) {
14011 + if (!user_mode(regs)) {
14012 crash_fixup_ss_esp(&fixed_regs, regs);
14013 regs = &fixed_regs;
14014 }
14015 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14016 index 37250fe..bf2ec74 100644
14017 --- a/arch/x86/kernel/doublefault_32.c
14018 +++ b/arch/x86/kernel/doublefault_32.c
14019 @@ -11,7 +11,7 @@
14020
14021 #define DOUBLEFAULT_STACKSIZE (1024)
14022 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14023 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14024 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14025
14026 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14027
14028 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14029 unsigned long gdt, tss;
14030
14031 store_gdt(&gdt_desc);
14032 - gdt = gdt_desc.address;
14033 + gdt = (unsigned long)gdt_desc.address;
14034
14035 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14036
14037 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14038 /* 0x2 bit is always set */
14039 .flags = X86_EFLAGS_SF | 0x2,
14040 .sp = STACK_START,
14041 - .es = __USER_DS,
14042 + .es = __KERNEL_DS,
14043 .cs = __KERNEL_CS,
14044 .ss = __KERNEL_DS,
14045 - .ds = __USER_DS,
14046 + .ds = __KERNEL_DS,
14047 .fs = __KERNEL_PERCPU,
14048
14049 .__cr3 = __pa_nodebug(swapper_pg_dir),
14050 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14051 index 4025fe4..d8451c6 100644
14052 --- a/arch/x86/kernel/dumpstack.c
14053 +++ b/arch/x86/kernel/dumpstack.c
14054 @@ -2,6 +2,9 @@
14055 * Copyright (C) 1991, 1992 Linus Torvalds
14056 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14057 */
14058 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14059 +#define __INCLUDED_BY_HIDESYM 1
14060 +#endif
14061 #include <linux/kallsyms.h>
14062 #include <linux/kprobes.h>
14063 #include <linux/uaccess.h>
14064 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14065 static void
14066 print_ftrace_graph_addr(unsigned long addr, void *data,
14067 const struct stacktrace_ops *ops,
14068 - struct thread_info *tinfo, int *graph)
14069 + struct task_struct *task, int *graph)
14070 {
14071 - struct task_struct *task = tinfo->task;
14072 unsigned long ret_addr;
14073 int index = task->curr_ret_stack;
14074
14075 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14076 static inline void
14077 print_ftrace_graph_addr(unsigned long addr, void *data,
14078 const struct stacktrace_ops *ops,
14079 - struct thread_info *tinfo, int *graph)
14080 + struct task_struct *task, int *graph)
14081 { }
14082 #endif
14083
14084 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14085 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14086 */
14087
14088 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14089 - void *p, unsigned int size, void *end)
14090 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14091 {
14092 - void *t = tinfo;
14093 if (end) {
14094 if (p < end && p >= (end-THREAD_SIZE))
14095 return 1;
14096 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14097 }
14098
14099 unsigned long
14100 -print_context_stack(struct thread_info *tinfo,
14101 +print_context_stack(struct task_struct *task, void *stack_start,
14102 unsigned long *stack, unsigned long bp,
14103 const struct stacktrace_ops *ops, void *data,
14104 unsigned long *end, int *graph)
14105 {
14106 struct stack_frame *frame = (struct stack_frame *)bp;
14107
14108 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14109 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14110 unsigned long addr;
14111
14112 addr = *stack;
14113 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14114 } else {
14115 ops->address(data, addr, 0);
14116 }
14117 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14118 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14119 }
14120 stack++;
14121 }
14122 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14123 EXPORT_SYMBOL_GPL(print_context_stack);
14124
14125 unsigned long
14126 -print_context_stack_bp(struct thread_info *tinfo,
14127 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14128 unsigned long *stack, unsigned long bp,
14129 const struct stacktrace_ops *ops, void *data,
14130 unsigned long *end, int *graph)
14131 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14132 struct stack_frame *frame = (struct stack_frame *)bp;
14133 unsigned long *ret_addr = &frame->return_address;
14134
14135 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14136 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14137 unsigned long addr = *ret_addr;
14138
14139 if (!__kernel_text_address(addr))
14140 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14141 ops->address(data, addr, 1);
14142 frame = frame->next_frame;
14143 ret_addr = &frame->return_address;
14144 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14145 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14146 }
14147
14148 return (unsigned long)frame;
14149 @@ -186,7 +186,7 @@ void dump_stack(void)
14150
14151 bp = stack_frame(current, NULL);
14152 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14153 - current->pid, current->comm, print_tainted(),
14154 + task_pid_nr(current), current->comm, print_tainted(),
14155 init_utsname()->release,
14156 (int)strcspn(init_utsname()->version, " "),
14157 init_utsname()->version);
14158 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14159 }
14160 EXPORT_SYMBOL_GPL(oops_begin);
14161
14162 +extern void gr_handle_kernel_exploit(void);
14163 +
14164 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14165 {
14166 if (regs && kexec_should_crash(current))
14167 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14168 panic("Fatal exception in interrupt");
14169 if (panic_on_oops)
14170 panic("Fatal exception");
14171 - do_exit(signr);
14172 +
14173 + gr_handle_kernel_exploit();
14174 +
14175 + do_group_exit(signr);
14176 }
14177
14178 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14179 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14180
14181 show_registers(regs);
14182 #ifdef CONFIG_X86_32
14183 - if (user_mode_vm(regs)) {
14184 + if (user_mode(regs)) {
14185 sp = regs->sp;
14186 ss = regs->ss & 0xffff;
14187 } else {
14188 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14189 unsigned long flags = oops_begin();
14190 int sig = SIGSEGV;
14191
14192 - if (!user_mode_vm(regs))
14193 + if (!user_mode(regs))
14194 report_bug(regs->ip, regs);
14195
14196 if (__die(str, regs, err))
14197 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14198 index c99f9ed..2a15d80 100644
14199 --- a/arch/x86/kernel/dumpstack_32.c
14200 +++ b/arch/x86/kernel/dumpstack_32.c
14201 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14202 bp = stack_frame(task, regs);
14203
14204 for (;;) {
14205 - struct thread_info *context;
14206 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14207
14208 - context = (struct thread_info *)
14209 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14210 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14211 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14212
14213 - stack = (unsigned long *)context->previous_esp;
14214 - if (!stack)
14215 + if (stack_start == task_stack_page(task))
14216 break;
14217 + stack = *(unsigned long **)stack_start;
14218 if (ops->stack(data, "IRQ") < 0)
14219 break;
14220 touch_nmi_watchdog();
14221 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14222 * When in-kernel, we also print out the stack and code at the
14223 * time of the fault..
14224 */
14225 - if (!user_mode_vm(regs)) {
14226 + if (!user_mode(regs)) {
14227 unsigned int code_prologue = code_bytes * 43 / 64;
14228 unsigned int code_len = code_bytes;
14229 unsigned char c;
14230 u8 *ip;
14231 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14232
14233 printk(KERN_EMERG "Stack:\n");
14234 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14235
14236 printk(KERN_EMERG "Code: ");
14237
14238 - ip = (u8 *)regs->ip - code_prologue;
14239 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14240 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14241 /* try starting at IP */
14242 - ip = (u8 *)regs->ip;
14243 + ip = (u8 *)regs->ip + cs_base;
14244 code_len = code_len - code_prologue + 1;
14245 }
14246 for (i = 0; i < code_len; i++, ip++) {
14247 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14248 printk(KERN_CONT " Bad EIP value.");
14249 break;
14250 }
14251 - if (ip == (u8 *)regs->ip)
14252 + if (ip == (u8 *)regs->ip + cs_base)
14253 printk(KERN_CONT "<%02x> ", c);
14254 else
14255 printk(KERN_CONT "%02x ", c);
14256 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14257 {
14258 unsigned short ud2;
14259
14260 + ip = ktla_ktva(ip);
14261 if (ip < PAGE_OFFSET)
14262 return 0;
14263 if (probe_kernel_address((unsigned short *)ip, ud2))
14264 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14265
14266 return ud2 == 0x0b0f;
14267 }
14268 +
14269 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14270 +void pax_check_alloca(unsigned long size)
14271 +{
14272 + unsigned long sp = (unsigned long)&sp, stack_left;
14273 +
14274 + /* all kernel stacks are of the same size */
14275 + stack_left = sp & (THREAD_SIZE - 1);
14276 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14277 +}
14278 +EXPORT_SYMBOL(pax_check_alloca);
14279 +#endif
14280 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14281 index 17107bd..b2deecf 100644
14282 --- a/arch/x86/kernel/dumpstack_64.c
14283 +++ b/arch/x86/kernel/dumpstack_64.c
14284 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14285 unsigned long *irq_stack_end =
14286 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14287 unsigned used = 0;
14288 - struct thread_info *tinfo;
14289 int graph = 0;
14290 unsigned long dummy;
14291 + void *stack_start;
14292
14293 if (!task)
14294 task = current;
14295 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14296 * current stack address. If the stacks consist of nested
14297 * exceptions
14298 */
14299 - tinfo = task_thread_info(task);
14300 for (;;) {
14301 char *id;
14302 unsigned long *estack_end;
14303 +
14304 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14305 &used, &id);
14306
14307 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14308 if (ops->stack(data, id) < 0)
14309 break;
14310
14311 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14312 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14313 data, estack_end, &graph);
14314 ops->stack(data, "<EOE>");
14315 /*
14316 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14317 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14318 if (ops->stack(data, "IRQ") < 0)
14319 break;
14320 - bp = ops->walk_stack(tinfo, stack, bp,
14321 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14322 ops, data, irq_stack_end, &graph);
14323 /*
14324 * We link to the next stack (which would be
14325 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14326 /*
14327 * This handles the process stack:
14328 */
14329 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14330 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14331 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14332 put_cpu();
14333 }
14334 EXPORT_SYMBOL(dump_trace);
14335 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14336
14337 return ud2 == 0x0b0f;
14338 }
14339 +
14340 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14341 +void pax_check_alloca(unsigned long size)
14342 +{
14343 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14344 + unsigned cpu, used;
14345 + char *id;
14346 +
14347 + /* check the process stack first */
14348 + stack_start = (unsigned long)task_stack_page(current);
14349 + stack_end = stack_start + THREAD_SIZE;
14350 + if (likely(stack_start <= sp && sp < stack_end)) {
14351 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14352 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14353 + return;
14354 + }
14355 +
14356 + cpu = get_cpu();
14357 +
14358 + /* check the irq stacks */
14359 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14360 + stack_start = stack_end - IRQ_STACK_SIZE;
14361 + if (stack_start <= sp && sp < stack_end) {
14362 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14363 + put_cpu();
14364 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14365 + return;
14366 + }
14367 +
14368 + /* check the exception stacks */
14369 + used = 0;
14370 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14371 + stack_start = stack_end - EXCEPTION_STKSZ;
14372 + if (stack_end && stack_start <= sp && sp < stack_end) {
14373 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14374 + put_cpu();
14375 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14376 + return;
14377 + }
14378 +
14379 + put_cpu();
14380 +
14381 + /* unknown stack */
14382 + BUG();
14383 +}
14384 +EXPORT_SYMBOL(pax_check_alloca);
14385 +#endif
14386 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14387 index 9b9f18b..9fcaa04 100644
14388 --- a/arch/x86/kernel/early_printk.c
14389 +++ b/arch/x86/kernel/early_printk.c
14390 @@ -7,6 +7,7 @@
14391 #include <linux/pci_regs.h>
14392 #include <linux/pci_ids.h>
14393 #include <linux/errno.h>
14394 +#include <linux/sched.h>
14395 #include <asm/io.h>
14396 #include <asm/processor.h>
14397 #include <asm/fcntl.h>
14398 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14399 index 7b784f4..76aaad7 100644
14400 --- a/arch/x86/kernel/entry_32.S
14401 +++ b/arch/x86/kernel/entry_32.S
14402 @@ -179,13 +179,146 @@
14403 /*CFI_REL_OFFSET gs, PT_GS*/
14404 .endm
14405 .macro SET_KERNEL_GS reg
14406 +
14407 +#ifdef CONFIG_CC_STACKPROTECTOR
14408 movl $(__KERNEL_STACK_CANARY), \reg
14409 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14410 + movl $(__USER_DS), \reg
14411 +#else
14412 + xorl \reg, \reg
14413 +#endif
14414 +
14415 movl \reg, %gs
14416 .endm
14417
14418 #endif /* CONFIG_X86_32_LAZY_GS */
14419
14420 -.macro SAVE_ALL
14421 +.macro pax_enter_kernel
14422 +#ifdef CONFIG_PAX_KERNEXEC
14423 + call pax_enter_kernel
14424 +#endif
14425 +.endm
14426 +
14427 +.macro pax_exit_kernel
14428 +#ifdef CONFIG_PAX_KERNEXEC
14429 + call pax_exit_kernel
14430 +#endif
14431 +.endm
14432 +
14433 +#ifdef CONFIG_PAX_KERNEXEC
14434 +ENTRY(pax_enter_kernel)
14435 +#ifdef CONFIG_PARAVIRT
14436 + pushl %eax
14437 + pushl %ecx
14438 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14439 + mov %eax, %esi
14440 +#else
14441 + mov %cr0, %esi
14442 +#endif
14443 + bts $16, %esi
14444 + jnc 1f
14445 + mov %cs, %esi
14446 + cmp $__KERNEL_CS, %esi
14447 + jz 3f
14448 + ljmp $__KERNEL_CS, $3f
14449 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14450 +2:
14451 +#ifdef CONFIG_PARAVIRT
14452 + mov %esi, %eax
14453 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14454 +#else
14455 + mov %esi, %cr0
14456 +#endif
14457 +3:
14458 +#ifdef CONFIG_PARAVIRT
14459 + popl %ecx
14460 + popl %eax
14461 +#endif
14462 + ret
14463 +ENDPROC(pax_enter_kernel)
14464 +
14465 +ENTRY(pax_exit_kernel)
14466 +#ifdef CONFIG_PARAVIRT
14467 + pushl %eax
14468 + pushl %ecx
14469 +#endif
14470 + mov %cs, %esi
14471 + cmp $__KERNEXEC_KERNEL_CS, %esi
14472 + jnz 2f
14473 +#ifdef CONFIG_PARAVIRT
14474 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14475 + mov %eax, %esi
14476 +#else
14477 + mov %cr0, %esi
14478 +#endif
14479 + btr $16, %esi
14480 + ljmp $__KERNEL_CS, $1f
14481 +1:
14482 +#ifdef CONFIG_PARAVIRT
14483 + mov %esi, %eax
14484 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14485 +#else
14486 + mov %esi, %cr0
14487 +#endif
14488 +2:
14489 +#ifdef CONFIG_PARAVIRT
14490 + popl %ecx
14491 + popl %eax
14492 +#endif
14493 + ret
14494 +ENDPROC(pax_exit_kernel)
14495 +#endif
14496 +
14497 +.macro pax_erase_kstack
14498 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14499 + call pax_erase_kstack
14500 +#endif
14501 +.endm
14502 +
14503 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14504 +/*
14505 + * ebp: thread_info
14506 + * ecx, edx: can be clobbered
14507 + */
14508 +ENTRY(pax_erase_kstack)
14509 + pushl %edi
14510 + pushl %eax
14511 +
14512 + mov TI_lowest_stack(%ebp), %edi
14513 + mov $-0xBEEF, %eax
14514 + std
14515 +
14516 +1: mov %edi, %ecx
14517 + and $THREAD_SIZE_asm - 1, %ecx
14518 + shr $2, %ecx
14519 + repne scasl
14520 + jecxz 2f
14521 +
14522 + cmp $2*16, %ecx
14523 + jc 2f
14524 +
14525 + mov $2*16, %ecx
14526 + repe scasl
14527 + jecxz 2f
14528 + jne 1b
14529 +
14530 +2: cld
14531 + mov %esp, %ecx
14532 + sub %edi, %ecx
14533 + shr $2, %ecx
14534 + rep stosl
14535 +
14536 + mov TI_task_thread_sp0(%ebp), %edi
14537 + sub $128, %edi
14538 + mov %edi, TI_lowest_stack(%ebp)
14539 +
14540 + popl %eax
14541 + popl %edi
14542 + ret
14543 +ENDPROC(pax_erase_kstack)
14544 +#endif
14545 +
14546 +.macro __SAVE_ALL _DS
14547 cld
14548 PUSH_GS
14549 pushl_cfi %fs
14550 @@ -208,7 +341,7 @@
14551 CFI_REL_OFFSET ecx, 0
14552 pushl_cfi %ebx
14553 CFI_REL_OFFSET ebx, 0
14554 - movl $(__USER_DS), %edx
14555 + movl $\_DS, %edx
14556 movl %edx, %ds
14557 movl %edx, %es
14558 movl $(__KERNEL_PERCPU), %edx
14559 @@ -216,6 +349,15 @@
14560 SET_KERNEL_GS %edx
14561 .endm
14562
14563 +.macro SAVE_ALL
14564 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14565 + __SAVE_ALL __KERNEL_DS
14566 + pax_enter_kernel
14567 +#else
14568 + __SAVE_ALL __USER_DS
14569 +#endif
14570 +.endm
14571 +
14572 .macro RESTORE_INT_REGS
14573 popl_cfi %ebx
14574 CFI_RESTORE ebx
14575 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14576 popfl_cfi
14577 jmp syscall_exit
14578 CFI_ENDPROC
14579 -END(ret_from_fork)
14580 +ENDPROC(ret_from_fork)
14581
14582 /*
14583 * Interrupt exit functions should be protected against kprobes
14584 @@ -335,7 +477,15 @@ resume_userspace_sig:
14585 andl $SEGMENT_RPL_MASK, %eax
14586 #endif
14587 cmpl $USER_RPL, %eax
14588 +
14589 +#ifdef CONFIG_PAX_KERNEXEC
14590 + jae resume_userspace
14591 +
14592 + PAX_EXIT_KERNEL
14593 + jmp resume_kernel
14594 +#else
14595 jb resume_kernel # not returning to v8086 or userspace
14596 +#endif
14597
14598 ENTRY(resume_userspace)
14599 LOCKDEP_SYS_EXIT
14600 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14601 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14602 # int/exception return?
14603 jne work_pending
14604 - jmp restore_all
14605 -END(ret_from_exception)
14606 + jmp restore_all_pax
14607 +ENDPROC(ret_from_exception)
14608
14609 #ifdef CONFIG_PREEMPT
14610 ENTRY(resume_kernel)
14611 @@ -363,7 +513,7 @@ need_resched:
14612 jz restore_all
14613 call preempt_schedule_irq
14614 jmp need_resched
14615 -END(resume_kernel)
14616 +ENDPROC(resume_kernel)
14617 #endif
14618 CFI_ENDPROC
14619 /*
14620 @@ -397,23 +547,34 @@ sysenter_past_esp:
14621 /*CFI_REL_OFFSET cs, 0*/
14622 /*
14623 * Push current_thread_info()->sysenter_return to the stack.
14624 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14625 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14626 */
14627 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14628 + pushl_cfi $0
14629 CFI_REL_OFFSET eip, 0
14630
14631 pushl_cfi %eax
14632 SAVE_ALL
14633 + GET_THREAD_INFO(%ebp)
14634 + movl TI_sysenter_return(%ebp),%ebp
14635 + movl %ebp,PT_EIP(%esp)
14636 ENABLE_INTERRUPTS(CLBR_NONE)
14637
14638 /*
14639 * Load the potential sixth argument from user stack.
14640 * Careful about security.
14641 */
14642 + movl PT_OLDESP(%esp),%ebp
14643 +
14644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14645 + mov PT_OLDSS(%esp),%ds
14646 +1: movl %ds:(%ebp),%ebp
14647 + push %ss
14648 + pop %ds
14649 +#else
14650 cmpl $__PAGE_OFFSET-3,%ebp
14651 jae syscall_fault
14652 1: movl (%ebp),%ebp
14653 +#endif
14654 +
14655 movl %ebp,PT_EBP(%esp)
14656 .section __ex_table,"a"
14657 .align 4
14658 @@ -436,12 +597,24 @@ sysenter_do_call:
14659 testl $_TIF_ALLWORK_MASK, %ecx
14660 jne sysexit_audit
14661 sysenter_exit:
14662 +
14663 +#ifdef CONFIG_PAX_RANDKSTACK
14664 + pushl_cfi %eax
14665 + movl %esp, %eax
14666 + call pax_randomize_kstack
14667 + popl_cfi %eax
14668 +#endif
14669 +
14670 + pax_erase_kstack
14671 +
14672 /* if something modifies registers it must also disable sysexit */
14673 movl PT_EIP(%esp), %edx
14674 movl PT_OLDESP(%esp), %ecx
14675 xorl %ebp,%ebp
14676 TRACE_IRQS_ON
14677 1: mov PT_FS(%esp), %fs
14678 +2: mov PT_DS(%esp), %ds
14679 +3: mov PT_ES(%esp), %es
14680 PTGS_TO_GS
14681 ENABLE_INTERRUPTS_SYSEXIT
14682
14683 @@ -458,6 +631,9 @@ sysenter_audit:
14684 movl %eax,%edx /* 2nd arg: syscall number */
14685 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14686 call __audit_syscall_entry
14687 +
14688 + pax_erase_kstack
14689 +
14690 pushl_cfi %ebx
14691 movl PT_EAX(%esp),%eax /* reload syscall number */
14692 jmp sysenter_do_call
14693 @@ -483,11 +659,17 @@ sysexit_audit:
14694
14695 CFI_ENDPROC
14696 .pushsection .fixup,"ax"
14697 -2: movl $0,PT_FS(%esp)
14698 +4: movl $0,PT_FS(%esp)
14699 + jmp 1b
14700 +5: movl $0,PT_DS(%esp)
14701 + jmp 1b
14702 +6: movl $0,PT_ES(%esp)
14703 jmp 1b
14704 .section __ex_table,"a"
14705 .align 4
14706 - .long 1b,2b
14707 + .long 1b,4b
14708 + .long 2b,5b
14709 + .long 3b,6b
14710 .popsection
14711 PTGS_TO_GS_EX
14712 ENDPROC(ia32_sysenter_target)
14713 @@ -520,6 +702,15 @@ syscall_exit:
14714 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14715 jne syscall_exit_work
14716
14717 +restore_all_pax:
14718 +
14719 +#ifdef CONFIG_PAX_RANDKSTACK
14720 + movl %esp, %eax
14721 + call pax_randomize_kstack
14722 +#endif
14723 +
14724 + pax_erase_kstack
14725 +
14726 restore_all:
14727 TRACE_IRQS_IRET
14728 restore_all_notrace:
14729 @@ -579,14 +770,34 @@ ldt_ss:
14730 * compensating for the offset by changing to the ESPFIX segment with
14731 * a base address that matches for the difference.
14732 */
14733 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14734 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14735 mov %esp, %edx /* load kernel esp */
14736 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14737 mov %dx, %ax /* eax: new kernel esp */
14738 sub %eax, %edx /* offset (low word is 0) */
14739 +#ifdef CONFIG_SMP
14740 + movl PER_CPU_VAR(cpu_number), %ebx
14741 + shll $PAGE_SHIFT_asm, %ebx
14742 + addl $cpu_gdt_table, %ebx
14743 +#else
14744 + movl $cpu_gdt_table, %ebx
14745 +#endif
14746 shr $16, %edx
14747 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14748 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14749 +
14750 +#ifdef CONFIG_PAX_KERNEXEC
14751 + mov %cr0, %esi
14752 + btr $16, %esi
14753 + mov %esi, %cr0
14754 +#endif
14755 +
14756 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14757 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14758 +
14759 +#ifdef CONFIG_PAX_KERNEXEC
14760 + bts $16, %esi
14761 + mov %esi, %cr0
14762 +#endif
14763 +
14764 pushl_cfi $__ESPFIX_SS
14765 pushl_cfi %eax /* new kernel esp */
14766 /* Disable interrupts, but do not irqtrace this section: we
14767 @@ -615,38 +826,30 @@ work_resched:
14768 movl TI_flags(%ebp), %ecx
14769 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14770 # than syscall tracing?
14771 - jz restore_all
14772 + jz restore_all_pax
14773 testb $_TIF_NEED_RESCHED, %cl
14774 jnz work_resched
14775
14776 work_notifysig: # deal with pending signals and
14777 # notify-resume requests
14778 + movl %esp, %eax
14779 #ifdef CONFIG_VM86
14780 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14781 - movl %esp, %eax
14782 - jne work_notifysig_v86 # returning to kernel-space or
14783 + jz 1f # returning to kernel-space or
14784 # vm86-space
14785 - TRACE_IRQS_ON
14786 - ENABLE_INTERRUPTS(CLBR_NONE)
14787 - xorl %edx, %edx
14788 - call do_notify_resume
14789 - jmp resume_userspace_sig
14790
14791 - ALIGN
14792 -work_notifysig_v86:
14793 pushl_cfi %ecx # save ti_flags for do_notify_resume
14794 call save_v86_state # %eax contains pt_regs pointer
14795 popl_cfi %ecx
14796 movl %eax, %esp
14797 -#else
14798 - movl %esp, %eax
14799 +1:
14800 #endif
14801 TRACE_IRQS_ON
14802 ENABLE_INTERRUPTS(CLBR_NONE)
14803 xorl %edx, %edx
14804 call do_notify_resume
14805 jmp resume_userspace_sig
14806 -END(work_pending)
14807 +ENDPROC(work_pending)
14808
14809 # perform syscall exit tracing
14810 ALIGN
14811 @@ -654,11 +857,14 @@ syscall_trace_entry:
14812 movl $-ENOSYS,PT_EAX(%esp)
14813 movl %esp, %eax
14814 call syscall_trace_enter
14815 +
14816 + pax_erase_kstack
14817 +
14818 /* What it returned is what we'll actually use. */
14819 cmpl $(NR_syscalls), %eax
14820 jnae syscall_call
14821 jmp syscall_exit
14822 -END(syscall_trace_entry)
14823 +ENDPROC(syscall_trace_entry)
14824
14825 # perform syscall exit tracing
14826 ALIGN
14827 @@ -671,20 +877,24 @@ syscall_exit_work:
14828 movl %esp, %eax
14829 call syscall_trace_leave
14830 jmp resume_userspace
14831 -END(syscall_exit_work)
14832 +ENDPROC(syscall_exit_work)
14833 CFI_ENDPROC
14834
14835 RING0_INT_FRAME # can't unwind into user space anyway
14836 syscall_fault:
14837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14838 + push %ss
14839 + pop %ds
14840 +#endif
14841 GET_THREAD_INFO(%ebp)
14842 movl $-EFAULT,PT_EAX(%esp)
14843 jmp resume_userspace
14844 -END(syscall_fault)
14845 +ENDPROC(syscall_fault)
14846
14847 syscall_badsys:
14848 movl $-ENOSYS,PT_EAX(%esp)
14849 jmp resume_userspace
14850 -END(syscall_badsys)
14851 +ENDPROC(syscall_badsys)
14852 CFI_ENDPROC
14853 /*
14854 * End of kprobes section
14855 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14856 CFI_ENDPROC
14857 ENDPROC(ptregs_clone)
14858
14859 + ALIGN;
14860 +ENTRY(kernel_execve)
14861 + CFI_STARTPROC
14862 + pushl_cfi %ebp
14863 + sub $PT_OLDSS+4,%esp
14864 + pushl_cfi %edi
14865 + pushl_cfi %ecx
14866 + pushl_cfi %eax
14867 + lea 3*4(%esp),%edi
14868 + mov $PT_OLDSS/4+1,%ecx
14869 + xorl %eax,%eax
14870 + rep stosl
14871 + popl_cfi %eax
14872 + popl_cfi %ecx
14873 + popl_cfi %edi
14874 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14875 + pushl_cfi %esp
14876 + call sys_execve
14877 + add $4,%esp
14878 + CFI_ADJUST_CFA_OFFSET -4
14879 + GET_THREAD_INFO(%ebp)
14880 + test %eax,%eax
14881 + jz syscall_exit
14882 + add $PT_OLDSS+4,%esp
14883 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14884 + popl_cfi %ebp
14885 + ret
14886 + CFI_ENDPROC
14887 +ENDPROC(kernel_execve)
14888 +
14889 .macro FIXUP_ESPFIX_STACK
14890 /*
14891 * Switch back for ESPFIX stack to the normal zerobased stack
14892 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14893 * normal stack and adjusts ESP with the matching offset.
14894 */
14895 /* fixup the stack */
14896 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14897 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14898 +#ifdef CONFIG_SMP
14899 + movl PER_CPU_VAR(cpu_number), %ebx
14900 + shll $PAGE_SHIFT_asm, %ebx
14901 + addl $cpu_gdt_table, %ebx
14902 +#else
14903 + movl $cpu_gdt_table, %ebx
14904 +#endif
14905 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14906 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14907 shl $16, %eax
14908 addl %esp, %eax /* the adjusted stack pointer */
14909 pushl_cfi $__KERNEL_DS
14910 @@ -819,7 +1066,7 @@ vector=vector+1
14911 .endr
14912 2: jmp common_interrupt
14913 .endr
14914 -END(irq_entries_start)
14915 +ENDPROC(irq_entries_start)
14916
14917 .previous
14918 END(interrupt)
14919 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14920 pushl_cfi $do_coprocessor_error
14921 jmp error_code
14922 CFI_ENDPROC
14923 -END(coprocessor_error)
14924 +ENDPROC(coprocessor_error)
14925
14926 ENTRY(simd_coprocessor_error)
14927 RING0_INT_FRAME
14928 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14929 #endif
14930 jmp error_code
14931 CFI_ENDPROC
14932 -END(simd_coprocessor_error)
14933 +ENDPROC(simd_coprocessor_error)
14934
14935 ENTRY(device_not_available)
14936 RING0_INT_FRAME
14937 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14938 pushl_cfi $do_device_not_available
14939 jmp error_code
14940 CFI_ENDPROC
14941 -END(device_not_available)
14942 +ENDPROC(device_not_available)
14943
14944 #ifdef CONFIG_PARAVIRT
14945 ENTRY(native_iret)
14946 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
14947 .align 4
14948 .long native_iret, iret_exc
14949 .previous
14950 -END(native_iret)
14951 +ENDPROC(native_iret)
14952
14953 ENTRY(native_irq_enable_sysexit)
14954 sti
14955 sysexit
14956 -END(native_irq_enable_sysexit)
14957 +ENDPROC(native_irq_enable_sysexit)
14958 #endif
14959
14960 ENTRY(overflow)
14961 @@ -919,7 +1166,7 @@ ENTRY(overflow)
14962 pushl_cfi $do_overflow
14963 jmp error_code
14964 CFI_ENDPROC
14965 -END(overflow)
14966 +ENDPROC(overflow)
14967
14968 ENTRY(bounds)
14969 RING0_INT_FRAME
14970 @@ -927,7 +1174,7 @@ ENTRY(bounds)
14971 pushl_cfi $do_bounds
14972 jmp error_code
14973 CFI_ENDPROC
14974 -END(bounds)
14975 +ENDPROC(bounds)
14976
14977 ENTRY(invalid_op)
14978 RING0_INT_FRAME
14979 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
14980 pushl_cfi $do_invalid_op
14981 jmp error_code
14982 CFI_ENDPROC
14983 -END(invalid_op)
14984 +ENDPROC(invalid_op)
14985
14986 ENTRY(coprocessor_segment_overrun)
14987 RING0_INT_FRAME
14988 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
14989 pushl_cfi $do_coprocessor_segment_overrun
14990 jmp error_code
14991 CFI_ENDPROC
14992 -END(coprocessor_segment_overrun)
14993 +ENDPROC(coprocessor_segment_overrun)
14994
14995 ENTRY(invalid_TSS)
14996 RING0_EC_FRAME
14997 pushl_cfi $do_invalid_TSS
14998 jmp error_code
14999 CFI_ENDPROC
15000 -END(invalid_TSS)
15001 +ENDPROC(invalid_TSS)
15002
15003 ENTRY(segment_not_present)
15004 RING0_EC_FRAME
15005 pushl_cfi $do_segment_not_present
15006 jmp error_code
15007 CFI_ENDPROC
15008 -END(segment_not_present)
15009 +ENDPROC(segment_not_present)
15010
15011 ENTRY(stack_segment)
15012 RING0_EC_FRAME
15013 pushl_cfi $do_stack_segment
15014 jmp error_code
15015 CFI_ENDPROC
15016 -END(stack_segment)
15017 +ENDPROC(stack_segment)
15018
15019 ENTRY(alignment_check)
15020 RING0_EC_FRAME
15021 pushl_cfi $do_alignment_check
15022 jmp error_code
15023 CFI_ENDPROC
15024 -END(alignment_check)
15025 +ENDPROC(alignment_check)
15026
15027 ENTRY(divide_error)
15028 RING0_INT_FRAME
15029 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15030 pushl_cfi $do_divide_error
15031 jmp error_code
15032 CFI_ENDPROC
15033 -END(divide_error)
15034 +ENDPROC(divide_error)
15035
15036 #ifdef CONFIG_X86_MCE
15037 ENTRY(machine_check)
15038 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15039 pushl_cfi machine_check_vector
15040 jmp error_code
15041 CFI_ENDPROC
15042 -END(machine_check)
15043 +ENDPROC(machine_check)
15044 #endif
15045
15046 ENTRY(spurious_interrupt_bug)
15047 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15048 pushl_cfi $do_spurious_interrupt_bug
15049 jmp error_code
15050 CFI_ENDPROC
15051 -END(spurious_interrupt_bug)
15052 +ENDPROC(spurious_interrupt_bug)
15053 /*
15054 * End of kprobes section
15055 */
15056 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15057
15058 ENTRY(mcount)
15059 ret
15060 -END(mcount)
15061 +ENDPROC(mcount)
15062
15063 ENTRY(ftrace_caller)
15064 cmpl $0, function_trace_stop
15065 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15066 .globl ftrace_stub
15067 ftrace_stub:
15068 ret
15069 -END(ftrace_caller)
15070 +ENDPROC(ftrace_caller)
15071
15072 #else /* ! CONFIG_DYNAMIC_FTRACE */
15073
15074 @@ -1177,7 +1424,7 @@ trace:
15075 popl %ecx
15076 popl %eax
15077 jmp ftrace_stub
15078 -END(mcount)
15079 +ENDPROC(mcount)
15080 #endif /* CONFIG_DYNAMIC_FTRACE */
15081 #endif /* CONFIG_FUNCTION_TRACER */
15082
15083 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15084 popl %ecx
15085 popl %eax
15086 ret
15087 -END(ftrace_graph_caller)
15088 +ENDPROC(ftrace_graph_caller)
15089
15090 .globl return_to_handler
15091 return_to_handler:
15092 @@ -1253,15 +1500,18 @@ error_code:
15093 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15094 REG_TO_PTGS %ecx
15095 SET_KERNEL_GS %ecx
15096 - movl $(__USER_DS), %ecx
15097 + movl $(__KERNEL_DS), %ecx
15098 movl %ecx, %ds
15099 movl %ecx, %es
15100 +
15101 + pax_enter_kernel
15102 +
15103 TRACE_IRQS_OFF
15104 movl %esp,%eax # pt_regs pointer
15105 call *%edi
15106 jmp ret_from_exception
15107 CFI_ENDPROC
15108 -END(page_fault)
15109 +ENDPROC(page_fault)
15110
15111 /*
15112 * Debug traps and NMI can happen at the one SYSENTER instruction
15113 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15114 call do_debug
15115 jmp ret_from_exception
15116 CFI_ENDPROC
15117 -END(debug)
15118 +ENDPROC(debug)
15119
15120 /*
15121 * NMI is doubly nasty. It can happen _while_ we're handling
15122 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15123 xorl %edx,%edx # zero error code
15124 movl %esp,%eax # pt_regs pointer
15125 call do_nmi
15126 +
15127 + pax_exit_kernel
15128 +
15129 jmp restore_all_notrace
15130 CFI_ENDPROC
15131
15132 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15133 FIXUP_ESPFIX_STACK # %eax == %esp
15134 xorl %edx,%edx # zero error code
15135 call do_nmi
15136 +
15137 + pax_exit_kernel
15138 +
15139 RESTORE_REGS
15140 lss 12+4(%esp), %esp # back to espfix stack
15141 CFI_ADJUST_CFA_OFFSET -24
15142 jmp irq_return
15143 CFI_ENDPROC
15144 -END(nmi)
15145 +ENDPROC(nmi)
15146
15147 ENTRY(int3)
15148 RING0_INT_FRAME
15149 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15150 call do_int3
15151 jmp ret_from_exception
15152 CFI_ENDPROC
15153 -END(int3)
15154 +ENDPROC(int3)
15155
15156 ENTRY(general_protection)
15157 RING0_EC_FRAME
15158 pushl_cfi $do_general_protection
15159 jmp error_code
15160 CFI_ENDPROC
15161 -END(general_protection)
15162 +ENDPROC(general_protection)
15163
15164 #ifdef CONFIG_KVM_GUEST
15165 ENTRY(async_page_fault)
15166 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15167 pushl_cfi $do_async_page_fault
15168 jmp error_code
15169 CFI_ENDPROC
15170 -END(async_page_fault)
15171 +ENDPROC(async_page_fault)
15172 #endif
15173
15174 /*
15175 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15176 index 1333d98..b340ca2 100644
15177 --- a/arch/x86/kernel/entry_64.S
15178 +++ b/arch/x86/kernel/entry_64.S
15179 @@ -56,6 +56,8 @@
15180 #include <asm/ftrace.h>
15181 #include <asm/percpu.h>
15182 #include <linux/err.h>
15183 +#include <asm/pgtable.h>
15184 +#include <asm/alternative-asm.h>
15185
15186 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15187 #include <linux/elf-em.h>
15188 @@ -69,8 +71,9 @@
15189 #ifdef CONFIG_FUNCTION_TRACER
15190 #ifdef CONFIG_DYNAMIC_FTRACE
15191 ENTRY(mcount)
15192 + pax_force_retaddr
15193 retq
15194 -END(mcount)
15195 +ENDPROC(mcount)
15196
15197 ENTRY(ftrace_caller)
15198 cmpl $0, function_trace_stop
15199 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15200 #endif
15201
15202 GLOBAL(ftrace_stub)
15203 + pax_force_retaddr
15204 retq
15205 -END(ftrace_caller)
15206 +ENDPROC(ftrace_caller)
15207
15208 #else /* ! CONFIG_DYNAMIC_FTRACE */
15209 ENTRY(mcount)
15210 @@ -113,6 +117,7 @@ ENTRY(mcount)
15211 #endif
15212
15213 GLOBAL(ftrace_stub)
15214 + pax_force_retaddr
15215 retq
15216
15217 trace:
15218 @@ -122,12 +127,13 @@ trace:
15219 movq 8(%rbp), %rsi
15220 subq $MCOUNT_INSN_SIZE, %rdi
15221
15222 + pax_force_fptr ftrace_trace_function
15223 call *ftrace_trace_function
15224
15225 MCOUNT_RESTORE_FRAME
15226
15227 jmp ftrace_stub
15228 -END(mcount)
15229 +ENDPROC(mcount)
15230 #endif /* CONFIG_DYNAMIC_FTRACE */
15231 #endif /* CONFIG_FUNCTION_TRACER */
15232
15233 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15234
15235 MCOUNT_RESTORE_FRAME
15236
15237 + pax_force_retaddr
15238 retq
15239 -END(ftrace_graph_caller)
15240 +ENDPROC(ftrace_graph_caller)
15241
15242 GLOBAL(return_to_handler)
15243 subq $24, %rsp
15244 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15245 movq 8(%rsp), %rdx
15246 movq (%rsp), %rax
15247 addq $24, %rsp
15248 + pax_force_fptr %rdi
15249 jmp *%rdi
15250 #endif
15251
15252 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15253 ENDPROC(native_usergs_sysret64)
15254 #endif /* CONFIG_PARAVIRT */
15255
15256 + .macro ljmpq sel, off
15257 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15258 + .byte 0x48; ljmp *1234f(%rip)
15259 + .pushsection .rodata
15260 + .align 16
15261 + 1234: .quad \off; .word \sel
15262 + .popsection
15263 +#else
15264 + pushq $\sel
15265 + pushq $\off
15266 + lretq
15267 +#endif
15268 + .endm
15269 +
15270 + .macro pax_enter_kernel
15271 + pax_set_fptr_mask
15272 +#ifdef CONFIG_PAX_KERNEXEC
15273 + call pax_enter_kernel
15274 +#endif
15275 + .endm
15276 +
15277 + .macro pax_exit_kernel
15278 +#ifdef CONFIG_PAX_KERNEXEC
15279 + call pax_exit_kernel
15280 +#endif
15281 + .endm
15282 +
15283 +#ifdef CONFIG_PAX_KERNEXEC
15284 +ENTRY(pax_enter_kernel)
15285 + pushq %rdi
15286 +
15287 +#ifdef CONFIG_PARAVIRT
15288 + PV_SAVE_REGS(CLBR_RDI)
15289 +#endif
15290 +
15291 + GET_CR0_INTO_RDI
15292 + bts $16,%rdi
15293 + jnc 3f
15294 + mov %cs,%edi
15295 + cmp $__KERNEL_CS,%edi
15296 + jnz 2f
15297 +1:
15298 +
15299 +#ifdef CONFIG_PARAVIRT
15300 + PV_RESTORE_REGS(CLBR_RDI)
15301 +#endif
15302 +
15303 + popq %rdi
15304 + pax_force_retaddr
15305 + retq
15306 +
15307 +2: ljmpq __KERNEL_CS,1f
15308 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15309 +4: SET_RDI_INTO_CR0
15310 + jmp 1b
15311 +ENDPROC(pax_enter_kernel)
15312 +
15313 +ENTRY(pax_exit_kernel)
15314 + pushq %rdi
15315 +
15316 +#ifdef CONFIG_PARAVIRT
15317 + PV_SAVE_REGS(CLBR_RDI)
15318 +#endif
15319 +
15320 + mov %cs,%rdi
15321 + cmp $__KERNEXEC_KERNEL_CS,%edi
15322 + jz 2f
15323 +1:
15324 +
15325 +#ifdef CONFIG_PARAVIRT
15326 + PV_RESTORE_REGS(CLBR_RDI);
15327 +#endif
15328 +
15329 + popq %rdi
15330 + pax_force_retaddr
15331 + retq
15332 +
15333 +2: GET_CR0_INTO_RDI
15334 + btr $16,%rdi
15335 + ljmpq __KERNEL_CS,3f
15336 +3: SET_RDI_INTO_CR0
15337 + jmp 1b
15338 +#ifdef CONFIG_PARAVIRT
15339 + PV_RESTORE_REGS(CLBR_RDI);
15340 +#endif
15341 +
15342 + popq %rdi
15343 + pax_force_retaddr
15344 + retq
15345 +ENDPROC(pax_exit_kernel)
15346 +#endif
15347 +
15348 + .macro pax_enter_kernel_user
15349 + pax_set_fptr_mask
15350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15351 + call pax_enter_kernel_user
15352 +#endif
15353 + .endm
15354 +
15355 + .macro pax_exit_kernel_user
15356 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15357 + call pax_exit_kernel_user
15358 +#endif
15359 +#ifdef CONFIG_PAX_RANDKSTACK
15360 + pushq %rax
15361 + call pax_randomize_kstack
15362 + popq %rax
15363 +#endif
15364 + .endm
15365 +
15366 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15367 +ENTRY(pax_enter_kernel_user)
15368 + pushq %rdi
15369 + pushq %rbx
15370 +
15371 +#ifdef CONFIG_PARAVIRT
15372 + PV_SAVE_REGS(CLBR_RDI)
15373 +#endif
15374 +
15375 + GET_CR3_INTO_RDI
15376 + mov %rdi,%rbx
15377 + add $__START_KERNEL_map,%rbx
15378 + sub phys_base(%rip),%rbx
15379 +
15380 +#ifdef CONFIG_PARAVIRT
15381 + pushq %rdi
15382 + cmpl $0, pv_info+PARAVIRT_enabled
15383 + jz 1f
15384 + i = 0
15385 + .rept USER_PGD_PTRS
15386 + mov i*8(%rbx),%rsi
15387 + mov $0,%sil
15388 + lea i*8(%rbx),%rdi
15389 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15390 + i = i + 1
15391 + .endr
15392 + jmp 2f
15393 +1:
15394 +#endif
15395 +
15396 + i = 0
15397 + .rept USER_PGD_PTRS
15398 + movb $0,i*8(%rbx)
15399 + i = i + 1
15400 + .endr
15401 +
15402 +#ifdef CONFIG_PARAVIRT
15403 +2: popq %rdi
15404 +#endif
15405 + SET_RDI_INTO_CR3
15406 +
15407 +#ifdef CONFIG_PAX_KERNEXEC
15408 + GET_CR0_INTO_RDI
15409 + bts $16,%rdi
15410 + SET_RDI_INTO_CR0
15411 +#endif
15412 +
15413 +#ifdef CONFIG_PARAVIRT
15414 + PV_RESTORE_REGS(CLBR_RDI)
15415 +#endif
15416 +
15417 + popq %rbx
15418 + popq %rdi
15419 + pax_force_retaddr
15420 + retq
15421 +ENDPROC(pax_enter_kernel_user)
15422 +
15423 +ENTRY(pax_exit_kernel_user)
15424 + push %rdi
15425 +
15426 +#ifdef CONFIG_PARAVIRT
15427 + pushq %rbx
15428 + PV_SAVE_REGS(CLBR_RDI)
15429 +#endif
15430 +
15431 +#ifdef CONFIG_PAX_KERNEXEC
15432 + GET_CR0_INTO_RDI
15433 + btr $16,%rdi
15434 + SET_RDI_INTO_CR0
15435 +#endif
15436 +
15437 + GET_CR3_INTO_RDI
15438 + add $__START_KERNEL_map,%rdi
15439 + sub phys_base(%rip),%rdi
15440 +
15441 +#ifdef CONFIG_PARAVIRT
15442 + cmpl $0, pv_info+PARAVIRT_enabled
15443 + jz 1f
15444 + mov %rdi,%rbx
15445 + i = 0
15446 + .rept USER_PGD_PTRS
15447 + mov i*8(%rbx),%rsi
15448 + mov $0x67,%sil
15449 + lea i*8(%rbx),%rdi
15450 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15451 + i = i + 1
15452 + .endr
15453 + jmp 2f
15454 +1:
15455 +#endif
15456 +
15457 + i = 0
15458 + .rept USER_PGD_PTRS
15459 + movb $0x67,i*8(%rdi)
15460 + i = i + 1
15461 + .endr
15462 +
15463 +#ifdef CONFIG_PARAVIRT
15464 +2: PV_RESTORE_REGS(CLBR_RDI)
15465 + popq %rbx
15466 +#endif
15467 +
15468 + popq %rdi
15469 + pax_force_retaddr
15470 + retq
15471 +ENDPROC(pax_exit_kernel_user)
15472 +#endif
15473 +
15474 +.macro pax_erase_kstack
15475 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15476 + call pax_erase_kstack
15477 +#endif
15478 +.endm
15479 +
15480 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15481 +/*
15482 + * r11: thread_info
15483 + * rcx, rdx: can be clobbered
15484 + */
15485 +ENTRY(pax_erase_kstack)
15486 + pushq %rdi
15487 + pushq %rax
15488 + pushq %r11
15489 +
15490 + GET_THREAD_INFO(%r11)
15491 + mov TI_lowest_stack(%r11), %rdi
15492 + mov $-0xBEEF, %rax
15493 + std
15494 +
15495 +1: mov %edi, %ecx
15496 + and $THREAD_SIZE_asm - 1, %ecx
15497 + shr $3, %ecx
15498 + repne scasq
15499 + jecxz 2f
15500 +
15501 + cmp $2*8, %ecx
15502 + jc 2f
15503 +
15504 + mov $2*8, %ecx
15505 + repe scasq
15506 + jecxz 2f
15507 + jne 1b
15508 +
15509 +2: cld
15510 + mov %esp, %ecx
15511 + sub %edi, %ecx
15512 +
15513 + cmp $THREAD_SIZE_asm, %rcx
15514 + jb 3f
15515 + ud2
15516 +3:
15517 +
15518 + shr $3, %ecx
15519 + rep stosq
15520 +
15521 + mov TI_task_thread_sp0(%r11), %rdi
15522 + sub $256, %rdi
15523 + mov %rdi, TI_lowest_stack(%r11)
15524 +
15525 + popq %r11
15526 + popq %rax
15527 + popq %rdi
15528 + pax_force_retaddr
15529 + ret
15530 +ENDPROC(pax_erase_kstack)
15531 +#endif
15532
15533 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15534 #ifdef CONFIG_TRACE_IRQFLAGS
15535 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15536 .endm
15537
15538 .macro UNFAKE_STACK_FRAME
15539 - addq $8*6, %rsp
15540 - CFI_ADJUST_CFA_OFFSET -(6*8)
15541 + addq $8*6 + ARG_SKIP, %rsp
15542 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15543 .endm
15544
15545 /*
15546 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15547 movq %rsp, %rsi
15548
15549 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15550 - testl $3, CS(%rdi)
15551 + testb $3, CS(%rdi)
15552 je 1f
15553 SWAPGS
15554 /*
15555 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15556 movq_cfi r15, R15+16
15557 movq %r11, 8(%rsp) /* return address */
15558 FIXUP_TOP_OF_STACK %r11, 16
15559 + pax_force_retaddr
15560 ret
15561 CFI_ENDPROC
15562 -END(save_rest)
15563 +ENDPROC(save_rest)
15564
15565 /* save complete stack frame */
15566 .pushsection .kprobes.text, "ax"
15567 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15568 js 1f /* negative -> in kernel */
15569 SWAPGS
15570 xorl %ebx,%ebx
15571 -1: ret
15572 +1: pax_force_retaddr_bts
15573 + ret
15574 CFI_ENDPROC
15575 -END(save_paranoid)
15576 +ENDPROC(save_paranoid)
15577 .popsection
15578
15579 /*
15580 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15581
15582 RESTORE_REST
15583
15584 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15585 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15586 jz retint_restore_args
15587
15588 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15589 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15590 jmp ret_from_sys_call # go to the SYSRET fastpath
15591
15592 CFI_ENDPROC
15593 -END(ret_from_fork)
15594 +ENDPROC(ret_from_fork)
15595
15596 /*
15597 * System call entry. Up to 6 arguments in registers are supported.
15598 @@ -457,7 +743,7 @@ END(ret_from_fork)
15599 ENTRY(system_call)
15600 CFI_STARTPROC simple
15601 CFI_SIGNAL_FRAME
15602 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15603 + CFI_DEF_CFA rsp,0
15604 CFI_REGISTER rip,rcx
15605 /*CFI_REGISTER rflags,r11*/
15606 SWAPGS_UNSAFE_STACK
15607 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15608
15609 movq %rsp,PER_CPU_VAR(old_rsp)
15610 movq PER_CPU_VAR(kernel_stack),%rsp
15611 + SAVE_ARGS 8*6,0
15612 + pax_enter_kernel_user
15613 /*
15614 * No need to follow this irqs off/on section - it's straight
15615 * and short:
15616 */
15617 ENABLE_INTERRUPTS(CLBR_NONE)
15618 - SAVE_ARGS 8,0
15619 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15620 movq %rcx,RIP-ARGOFFSET(%rsp)
15621 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15622 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15623 + GET_THREAD_INFO(%rcx)
15624 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15625 jnz tracesys
15626 system_call_fastpath:
15627 cmpq $__NR_syscall_max,%rax
15628 ja badsys
15629 - movq %r10,%rcx
15630 + movq R10-ARGOFFSET(%rsp),%rcx
15631 call *sys_call_table(,%rax,8) # XXX: rip relative
15632 movq %rax,RAX-ARGOFFSET(%rsp)
15633 /*
15634 @@ -498,10 +786,13 @@ sysret_check:
15635 LOCKDEP_SYS_EXIT
15636 DISABLE_INTERRUPTS(CLBR_NONE)
15637 TRACE_IRQS_OFF
15638 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15639 + GET_THREAD_INFO(%rcx)
15640 + movl TI_flags(%rcx),%edx
15641 andl %edi,%edx
15642 jnz sysret_careful
15643 CFI_REMEMBER_STATE
15644 + pax_exit_kernel_user
15645 + pax_erase_kstack
15646 /*
15647 * sysretq will re-enable interrupts:
15648 */
15649 @@ -553,14 +844,18 @@ badsys:
15650 * jump back to the normal fast path.
15651 */
15652 auditsys:
15653 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15654 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15655 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15656 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15657 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15658 movq %rax,%rsi /* 2nd arg: syscall number */
15659 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15660 call __audit_syscall_entry
15661 +
15662 + pax_erase_kstack
15663 +
15664 LOAD_ARGS 0 /* reload call-clobbered registers */
15665 + pax_set_fptr_mask
15666 jmp system_call_fastpath
15667
15668 /*
15669 @@ -581,7 +876,7 @@ sysret_audit:
15670 /* Do syscall tracing */
15671 tracesys:
15672 #ifdef CONFIG_AUDITSYSCALL
15673 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15674 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15675 jz auditsys
15676 #endif
15677 SAVE_REST
15678 @@ -589,16 +884,20 @@ tracesys:
15679 FIXUP_TOP_OF_STACK %rdi
15680 movq %rsp,%rdi
15681 call syscall_trace_enter
15682 +
15683 + pax_erase_kstack
15684 +
15685 /*
15686 * Reload arg registers from stack in case ptrace changed them.
15687 * We don't reload %rax because syscall_trace_enter() returned
15688 * the value it wants us to use in the table lookup.
15689 */
15690 LOAD_ARGS ARGOFFSET, 1
15691 + pax_set_fptr_mask
15692 RESTORE_REST
15693 cmpq $__NR_syscall_max,%rax
15694 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15695 - movq %r10,%rcx /* fixup for C */
15696 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15697 call *sys_call_table(,%rax,8)
15698 movq %rax,RAX-ARGOFFSET(%rsp)
15699 /* Use IRET because user could have changed frame */
15700 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15701 andl %edi,%edx
15702 jnz int_careful
15703 andl $~TS_COMPAT,TI_status(%rcx)
15704 + pax_erase_kstack
15705 jmp retint_swapgs
15706
15707 /* Either reschedule or signal or syscall exit tracking needed. */
15708 @@ -665,7 +965,7 @@ int_restore_rest:
15709 TRACE_IRQS_OFF
15710 jmp int_with_check
15711 CFI_ENDPROC
15712 -END(system_call)
15713 +ENDPROC(system_call)
15714
15715 /*
15716 * Certain special system calls that need to save a complete full stack frame.
15717 @@ -681,7 +981,7 @@ ENTRY(\label)
15718 call \func
15719 jmp ptregscall_common
15720 CFI_ENDPROC
15721 -END(\label)
15722 +ENDPROC(\label)
15723 .endm
15724
15725 PTREGSCALL stub_clone, sys_clone, %r8
15726 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15727 movq_cfi_restore R12+8, r12
15728 movq_cfi_restore RBP+8, rbp
15729 movq_cfi_restore RBX+8, rbx
15730 + pax_force_retaddr
15731 ret $REST_SKIP /* pop extended registers */
15732 CFI_ENDPROC
15733 -END(ptregscall_common)
15734 +ENDPROC(ptregscall_common)
15735
15736 ENTRY(stub_execve)
15737 CFI_STARTPROC
15738 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15739 RESTORE_REST
15740 jmp int_ret_from_sys_call
15741 CFI_ENDPROC
15742 -END(stub_execve)
15743 +ENDPROC(stub_execve)
15744
15745 /*
15746 * sigreturn is special because it needs to restore all registers on return.
15747 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15748 RESTORE_REST
15749 jmp int_ret_from_sys_call
15750 CFI_ENDPROC
15751 -END(stub_rt_sigreturn)
15752 +ENDPROC(stub_rt_sigreturn)
15753
15754 /*
15755 * Build the entry stubs and pointer table with some assembler magic.
15756 @@ -769,7 +1070,7 @@ vector=vector+1
15757 2: jmp common_interrupt
15758 .endr
15759 CFI_ENDPROC
15760 -END(irq_entries_start)
15761 +ENDPROC(irq_entries_start)
15762
15763 .previous
15764 END(interrupt)
15765 @@ -789,6 +1090,16 @@ END(interrupt)
15766 subq $ORIG_RAX-RBP, %rsp
15767 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15768 SAVE_ARGS_IRQ
15769 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15770 + testb $3, CS(%rdi)
15771 + jnz 1f
15772 + pax_enter_kernel
15773 + jmp 2f
15774 +1: pax_enter_kernel_user
15775 +2:
15776 +#else
15777 + pax_enter_kernel
15778 +#endif
15779 call \func
15780 .endm
15781
15782 @@ -820,7 +1131,7 @@ ret_from_intr:
15783
15784 exit_intr:
15785 GET_THREAD_INFO(%rcx)
15786 - testl $3,CS-ARGOFFSET(%rsp)
15787 + testb $3,CS-ARGOFFSET(%rsp)
15788 je retint_kernel
15789
15790 /* Interrupt came from user space */
15791 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15792 * The iretq could re-enable interrupts:
15793 */
15794 DISABLE_INTERRUPTS(CLBR_ANY)
15795 + pax_exit_kernel_user
15796 TRACE_IRQS_IRETQ
15797 SWAPGS
15798 jmp restore_args
15799
15800 retint_restore_args: /* return to kernel space */
15801 DISABLE_INTERRUPTS(CLBR_ANY)
15802 + pax_exit_kernel
15803 + pax_force_retaddr RIP-ARGOFFSET
15804 /*
15805 * The iretq could re-enable interrupts:
15806 */
15807 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15808 #endif
15809
15810 CFI_ENDPROC
15811 -END(common_interrupt)
15812 +ENDPROC(common_interrupt)
15813 /*
15814 * End of kprobes section
15815 */
15816 @@ -953,7 +1267,7 @@ ENTRY(\sym)
15817 interrupt \do_sym
15818 jmp ret_from_intr
15819 CFI_ENDPROC
15820 -END(\sym)
15821 +ENDPROC(\sym)
15822 .endm
15823
15824 #ifdef CONFIG_SMP
15825 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
15826 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15827 call error_entry
15828 DEFAULT_FRAME 0
15829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15830 + testb $3, CS(%rsp)
15831 + jnz 1f
15832 + pax_enter_kernel
15833 + jmp 2f
15834 +1: pax_enter_kernel_user
15835 +2:
15836 +#else
15837 + pax_enter_kernel
15838 +#endif
15839 movq %rsp,%rdi /* pt_regs pointer */
15840 xorl %esi,%esi /* no error code */
15841 call \do_sym
15842 jmp error_exit /* %ebx: no swapgs flag */
15843 CFI_ENDPROC
15844 -END(\sym)
15845 +ENDPROC(\sym)
15846 .endm
15847
15848 .macro paranoidzeroentry sym do_sym
15849 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
15850 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15851 call save_paranoid
15852 TRACE_IRQS_OFF
15853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15854 + testb $3, CS(%rsp)
15855 + jnz 1f
15856 + pax_enter_kernel
15857 + jmp 2f
15858 +1: pax_enter_kernel_user
15859 +2:
15860 +#else
15861 + pax_enter_kernel
15862 +#endif
15863 movq %rsp,%rdi /* pt_regs pointer */
15864 xorl %esi,%esi /* no error code */
15865 call \do_sym
15866 jmp paranoid_exit /* %ebx: no swapgs flag */
15867 CFI_ENDPROC
15868 -END(\sym)
15869 +ENDPROC(\sym)
15870 .endm
15871
15872 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15873 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15874 .macro paranoidzeroentry_ist sym do_sym ist
15875 ENTRY(\sym)
15876 INTR_FRAME
15877 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
15878 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15879 call save_paranoid
15880 TRACE_IRQS_OFF
15881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15882 + testb $3, CS(%rsp)
15883 + jnz 1f
15884 + pax_enter_kernel
15885 + jmp 2f
15886 +1: pax_enter_kernel_user
15887 +2:
15888 +#else
15889 + pax_enter_kernel
15890 +#endif
15891 movq %rsp,%rdi /* pt_regs pointer */
15892 xorl %esi,%esi /* no error code */
15893 +#ifdef CONFIG_SMP
15894 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15895 + lea init_tss(%r12), %r12
15896 +#else
15897 + lea init_tss(%rip), %r12
15898 +#endif
15899 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15900 call \do_sym
15901 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15902 jmp paranoid_exit /* %ebx: no swapgs flag */
15903 CFI_ENDPROC
15904 -END(\sym)
15905 +ENDPROC(\sym)
15906 .endm
15907
15908 .macro errorentry sym do_sym
15909 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
15910 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15911 call error_entry
15912 DEFAULT_FRAME 0
15913 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15914 + testb $3, CS(%rsp)
15915 + jnz 1f
15916 + pax_enter_kernel
15917 + jmp 2f
15918 +1: pax_enter_kernel_user
15919 +2:
15920 +#else
15921 + pax_enter_kernel
15922 +#endif
15923 movq %rsp,%rdi /* pt_regs pointer */
15924 movq ORIG_RAX(%rsp),%rsi /* get error code */
15925 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15926 call \do_sym
15927 jmp error_exit /* %ebx: no swapgs flag */
15928 CFI_ENDPROC
15929 -END(\sym)
15930 +ENDPROC(\sym)
15931 .endm
15932
15933 /* error code is on the stack already */
15934 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
15935 call save_paranoid
15936 DEFAULT_FRAME 0
15937 TRACE_IRQS_OFF
15938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15939 + testb $3, CS(%rsp)
15940 + jnz 1f
15941 + pax_enter_kernel
15942 + jmp 2f
15943 +1: pax_enter_kernel_user
15944 +2:
15945 +#else
15946 + pax_enter_kernel
15947 +#endif
15948 movq %rsp,%rdi /* pt_regs pointer */
15949 movq ORIG_RAX(%rsp),%rsi /* get error code */
15950 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15951 call \do_sym
15952 jmp paranoid_exit /* %ebx: no swapgs flag */
15953 CFI_ENDPROC
15954 -END(\sym)
15955 +ENDPROC(\sym)
15956 .endm
15957
15958 zeroentry divide_error do_divide_error
15959 @@ -1134,9 +1504,10 @@ gs_change:
15960 2: mfence /* workaround */
15961 SWAPGS
15962 popfq_cfi
15963 + pax_force_retaddr
15964 ret
15965 CFI_ENDPROC
15966 -END(native_load_gs_index)
15967 +ENDPROC(native_load_gs_index)
15968
15969 .section __ex_table,"a"
15970 .align 8
15971 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
15972 * Here we are in the child and the registers are set as they were
15973 * at kernel_thread() invocation in the parent.
15974 */
15975 + pax_force_fptr %rsi
15976 call *%rsi
15977 # exit
15978 mov %eax, %edi
15979 call do_exit
15980 ud2 # padding for call trace
15981 CFI_ENDPROC
15982 -END(kernel_thread_helper)
15983 +ENDPROC(kernel_thread_helper)
15984
15985 /*
15986 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15987 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
15988 RESTORE_REST
15989 testq %rax,%rax
15990 je int_ret_from_sys_call
15991 - RESTORE_ARGS
15992 UNFAKE_STACK_FRAME
15993 + pax_force_retaddr
15994 ret
15995 CFI_ENDPROC
15996 -END(kernel_execve)
15997 +ENDPROC(kernel_execve)
15998
15999 /* Call softirq on interrupt stack. Interrupts are off. */
16000 ENTRY(call_softirq)
16001 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16002 CFI_DEF_CFA_REGISTER rsp
16003 CFI_ADJUST_CFA_OFFSET -8
16004 decl PER_CPU_VAR(irq_count)
16005 + pax_force_retaddr
16006 ret
16007 CFI_ENDPROC
16008 -END(call_softirq)
16009 +ENDPROC(call_softirq)
16010
16011 #ifdef CONFIG_XEN
16012 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16013 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16014 decl PER_CPU_VAR(irq_count)
16015 jmp error_exit
16016 CFI_ENDPROC
16017 -END(xen_do_hypervisor_callback)
16018 +ENDPROC(xen_do_hypervisor_callback)
16019
16020 /*
16021 * Hypervisor uses this for application faults while it executes.
16022 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16023 SAVE_ALL
16024 jmp error_exit
16025 CFI_ENDPROC
16026 -END(xen_failsafe_callback)
16027 +ENDPROC(xen_failsafe_callback)
16028
16029 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16030 xen_hvm_callback_vector xen_evtchn_do_upcall
16031 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16032 TRACE_IRQS_OFF
16033 testl %ebx,%ebx /* swapgs needed? */
16034 jnz paranoid_restore
16035 - testl $3,CS(%rsp)
16036 + testb $3,CS(%rsp)
16037 jnz paranoid_userspace
16038 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16039 + pax_exit_kernel
16040 + TRACE_IRQS_IRETQ 0
16041 + SWAPGS_UNSAFE_STACK
16042 + RESTORE_ALL 8
16043 + pax_force_retaddr_bts
16044 + jmp irq_return
16045 +#endif
16046 paranoid_swapgs:
16047 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16048 + pax_exit_kernel_user
16049 +#else
16050 + pax_exit_kernel
16051 +#endif
16052 TRACE_IRQS_IRETQ 0
16053 SWAPGS_UNSAFE_STACK
16054 RESTORE_ALL 8
16055 jmp irq_return
16056 paranoid_restore:
16057 + pax_exit_kernel
16058 TRACE_IRQS_IRETQ 0
16059 RESTORE_ALL 8
16060 + pax_force_retaddr_bts
16061 jmp irq_return
16062 paranoid_userspace:
16063 GET_THREAD_INFO(%rcx)
16064 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16065 TRACE_IRQS_OFF
16066 jmp paranoid_userspace
16067 CFI_ENDPROC
16068 -END(paranoid_exit)
16069 +ENDPROC(paranoid_exit)
16070
16071 /*
16072 * Exception entry point. This expects an error code/orig_rax on the stack.
16073 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16074 movq_cfi r14, R14+8
16075 movq_cfi r15, R15+8
16076 xorl %ebx,%ebx
16077 - testl $3,CS+8(%rsp)
16078 + testb $3,CS+8(%rsp)
16079 je error_kernelspace
16080 error_swapgs:
16081 SWAPGS
16082 error_sti:
16083 TRACE_IRQS_OFF
16084 + pax_force_retaddr_bts
16085 ret
16086
16087 /*
16088 @@ -1458,7 +1847,7 @@ bstep_iret:
16089 movq %rcx,RIP+8(%rsp)
16090 jmp error_swapgs
16091 CFI_ENDPROC
16092 -END(error_entry)
16093 +ENDPROC(error_entry)
16094
16095
16096 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16097 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16098 jnz retint_careful
16099 jmp retint_swapgs
16100 CFI_ENDPROC
16101 -END(error_exit)
16102 +ENDPROC(error_exit)
16103
16104 /*
16105 * Test if a given stack is an NMI stack or not.
16106 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16107 * If %cs was not the kernel segment, then the NMI triggered in user
16108 * space, which means it is definitely not nested.
16109 */
16110 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16111 + je 1f
16112 cmpl $__KERNEL_CS, 16(%rsp)
16113 jne first_nmi
16114 -
16115 +1:
16116 /*
16117 * Check the special variable on the stack to see if NMIs are
16118 * executing.
16119 @@ -1659,6 +2050,16 @@ restart_nmi:
16120 */
16121 call save_paranoid
16122 DEFAULT_FRAME 0
16123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16124 + testb $3, CS(%rsp)
16125 + jnz 1f
16126 + pax_enter_kernel
16127 + jmp 2f
16128 +1: pax_enter_kernel_user
16129 +2:
16130 +#else
16131 + pax_enter_kernel
16132 +#endif
16133 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16134 movq %rsp,%rdi
16135 movq $-1,%rsi
16136 @@ -1666,14 +2067,25 @@ restart_nmi:
16137 testl %ebx,%ebx /* swapgs needed? */
16138 jnz nmi_restore
16139 nmi_swapgs:
16140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16141 + pax_exit_kernel_user
16142 +#else
16143 + pax_exit_kernel
16144 +#endif
16145 SWAPGS_UNSAFE_STACK
16146 + RESTORE_ALL 8
16147 + /* Clear the NMI executing stack variable */
16148 + movq $0, 10*8(%rsp)
16149 + jmp irq_return
16150 nmi_restore:
16151 + pax_exit_kernel
16152 RESTORE_ALL 8
16153 + pax_force_retaddr_bts
16154 /* Clear the NMI executing stack variable */
16155 movq $0, 10*8(%rsp)
16156 jmp irq_return
16157 CFI_ENDPROC
16158 -END(nmi)
16159 +ENDPROC(nmi)
16160
16161 /*
16162 * If an NMI hit an iret because of an exception or breakpoint,
16163 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16164 mov $-ENOSYS,%eax
16165 sysret
16166 CFI_ENDPROC
16167 -END(ignore_sysret)
16168 +ENDPROC(ignore_sysret)
16169
16170 /*
16171 * End of kprobes section
16172 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16173 index c9a281f..ce2f317 100644
16174 --- a/arch/x86/kernel/ftrace.c
16175 +++ b/arch/x86/kernel/ftrace.c
16176 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16177 static const void *mod_code_newcode; /* holds the text to write to the IP */
16178
16179 static unsigned nmi_wait_count;
16180 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16181 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16182
16183 int ftrace_arch_read_dyn_info(char *buf, int size)
16184 {
16185 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16186
16187 r = snprintf(buf, size, "%u %u",
16188 nmi_wait_count,
16189 - atomic_read(&nmi_update_count));
16190 + atomic_read_unchecked(&nmi_update_count));
16191 return r;
16192 }
16193
16194 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16195
16196 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16197 smp_rmb();
16198 + pax_open_kernel();
16199 ftrace_mod_code();
16200 - atomic_inc(&nmi_update_count);
16201 + pax_close_kernel();
16202 + atomic_inc_unchecked(&nmi_update_count);
16203 }
16204 /* Must have previous changes seen before executions */
16205 smp_mb();
16206 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16207 {
16208 unsigned char replaced[MCOUNT_INSN_SIZE];
16209
16210 + ip = ktla_ktva(ip);
16211 +
16212 /*
16213 * Note: Due to modules and __init, code can
16214 * disappear and change, we need to protect against faulting
16215 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16216 unsigned char old[MCOUNT_INSN_SIZE], *new;
16217 int ret;
16218
16219 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16220 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16221 new = ftrace_call_replace(ip, (unsigned long)func);
16222 ret = ftrace_modify_code(ip, old, new);
16223
16224 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16225 {
16226 unsigned char code[MCOUNT_INSN_SIZE];
16227
16228 + ip = ktla_ktva(ip);
16229 +
16230 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16231 return -EFAULT;
16232
16233 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16234 index 51ff186..9e77418 100644
16235 --- a/arch/x86/kernel/head32.c
16236 +++ b/arch/x86/kernel/head32.c
16237 @@ -19,6 +19,7 @@
16238 #include <asm/io_apic.h>
16239 #include <asm/bios_ebda.h>
16240 #include <asm/tlbflush.h>
16241 +#include <asm/boot.h>
16242
16243 static void __init i386_default_early_setup(void)
16244 {
16245 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16246
16247 void __init i386_start_kernel(void)
16248 {
16249 - memblock_reserve(__pa_symbol(&_text),
16250 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16251 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16252
16253 #ifdef CONFIG_BLK_DEV_INITRD
16254 /* Reserve INITRD */
16255 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16256 index ce0be7c..c41476e 100644
16257 --- a/arch/x86/kernel/head_32.S
16258 +++ b/arch/x86/kernel/head_32.S
16259 @@ -25,6 +25,12 @@
16260 /* Physical address */
16261 #define pa(X) ((X) - __PAGE_OFFSET)
16262
16263 +#ifdef CONFIG_PAX_KERNEXEC
16264 +#define ta(X) (X)
16265 +#else
16266 +#define ta(X) ((X) - __PAGE_OFFSET)
16267 +#endif
16268 +
16269 /*
16270 * References to members of the new_cpu_data structure.
16271 */
16272 @@ -54,11 +60,7 @@
16273 * and small than max_low_pfn, otherwise will waste some page table entries
16274 */
16275
16276 -#if PTRS_PER_PMD > 1
16277 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16278 -#else
16279 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16280 -#endif
16281 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16282
16283 /* Number of possible pages in the lowmem region */
16284 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16285 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16286 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16287
16288 /*
16289 + * Real beginning of normal "text" segment
16290 + */
16291 +ENTRY(stext)
16292 +ENTRY(_stext)
16293 +
16294 +/*
16295 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16296 * %esi points to the real-mode code as a 32-bit pointer.
16297 * CS and DS must be 4 GB flat segments, but we don't depend on
16298 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16299 * can.
16300 */
16301 __HEAD
16302 +
16303 +#ifdef CONFIG_PAX_KERNEXEC
16304 + jmp startup_32
16305 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16306 +.fill PAGE_SIZE-5,1,0xcc
16307 +#endif
16308 +
16309 ENTRY(startup_32)
16310 movl pa(stack_start),%ecx
16311
16312 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16313 2:
16314 leal -__PAGE_OFFSET(%ecx),%esp
16315
16316 +#ifdef CONFIG_SMP
16317 + movl $pa(cpu_gdt_table),%edi
16318 + movl $__per_cpu_load,%eax
16319 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16320 + rorl $16,%eax
16321 + movb %al,__KERNEL_PERCPU + 4(%edi)
16322 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16323 + movl $__per_cpu_end - 1,%eax
16324 + subl $__per_cpu_start,%eax
16325 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16326 +#endif
16327 +
16328 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16329 + movl $NR_CPUS,%ecx
16330 + movl $pa(cpu_gdt_table),%edi
16331 +1:
16332 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16333 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16334 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16335 + addl $PAGE_SIZE_asm,%edi
16336 + loop 1b
16337 +#endif
16338 +
16339 +#ifdef CONFIG_PAX_KERNEXEC
16340 + movl $pa(boot_gdt),%edi
16341 + movl $__LOAD_PHYSICAL_ADDR,%eax
16342 + movw %ax,__BOOT_CS + 2(%edi)
16343 + rorl $16,%eax
16344 + movb %al,__BOOT_CS + 4(%edi)
16345 + movb %ah,__BOOT_CS + 7(%edi)
16346 + rorl $16,%eax
16347 +
16348 + ljmp $(__BOOT_CS),$1f
16349 +1:
16350 +
16351 + movl $NR_CPUS,%ecx
16352 + movl $pa(cpu_gdt_table),%edi
16353 + addl $__PAGE_OFFSET,%eax
16354 +1:
16355 + movw %ax,__KERNEL_CS + 2(%edi)
16356 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16357 + rorl $16,%eax
16358 + movb %al,__KERNEL_CS + 4(%edi)
16359 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16360 + movb %ah,__KERNEL_CS + 7(%edi)
16361 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16362 + rorl $16,%eax
16363 + addl $PAGE_SIZE_asm,%edi
16364 + loop 1b
16365 +#endif
16366 +
16367 /*
16368 * Clear BSS first so that there are no surprises...
16369 */
16370 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16371 movl %eax, pa(max_pfn_mapped)
16372
16373 /* Do early initialization of the fixmap area */
16374 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16375 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16376 +#ifdef CONFIG_COMPAT_VDSO
16377 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16378 +#else
16379 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16380 +#endif
16381 #else /* Not PAE */
16382
16383 page_pde_offset = (__PAGE_OFFSET >> 20);
16384 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16385 movl %eax, pa(max_pfn_mapped)
16386
16387 /* Do early initialization of the fixmap area */
16388 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16389 - movl %eax,pa(initial_page_table+0xffc)
16390 +#ifdef CONFIG_COMPAT_VDSO
16391 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16392 +#else
16393 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16394 +#endif
16395 #endif
16396
16397 #ifdef CONFIG_PARAVIRT
16398 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16399 cmpl $num_subarch_entries, %eax
16400 jae bad_subarch
16401
16402 - movl pa(subarch_entries)(,%eax,4), %eax
16403 - subl $__PAGE_OFFSET, %eax
16404 - jmp *%eax
16405 + jmp *pa(subarch_entries)(,%eax,4)
16406
16407 bad_subarch:
16408 WEAK(lguest_entry)
16409 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16410 __INITDATA
16411
16412 subarch_entries:
16413 - .long default_entry /* normal x86/PC */
16414 - .long lguest_entry /* lguest hypervisor */
16415 - .long xen_entry /* Xen hypervisor */
16416 - .long default_entry /* Moorestown MID */
16417 + .long ta(default_entry) /* normal x86/PC */
16418 + .long ta(lguest_entry) /* lguest hypervisor */
16419 + .long ta(xen_entry) /* Xen hypervisor */
16420 + .long ta(default_entry) /* Moorestown MID */
16421 num_subarch_entries = (. - subarch_entries) / 4
16422 .previous
16423 #else
16424 @@ -312,6 +382,7 @@ default_entry:
16425 orl %edx,%eax
16426 movl %eax,%cr4
16427
16428 +#ifdef CONFIG_X86_PAE
16429 testb $X86_CR4_PAE, %al # check if PAE is enabled
16430 jz 6f
16431
16432 @@ -340,6 +411,9 @@ default_entry:
16433 /* Make changes effective */
16434 wrmsr
16435
16436 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16437 +#endif
16438 +
16439 6:
16440
16441 /*
16442 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16443 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16444 movl %eax,%ss # after changing gdt.
16445
16446 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16447 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16448 movl %eax,%ds
16449 movl %eax,%es
16450
16451 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16452 */
16453 cmpb $0,ready
16454 jne 1f
16455 - movl $gdt_page,%eax
16456 + movl $cpu_gdt_table,%eax
16457 movl $stack_canary,%ecx
16458 +#ifdef CONFIG_SMP
16459 + addl $__per_cpu_load,%ecx
16460 +#endif
16461 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16462 shrl $16, %ecx
16463 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16464 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16465 1:
16466 -#endif
16467 movl $(__KERNEL_STACK_CANARY),%eax
16468 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16469 + movl $(__USER_DS),%eax
16470 +#else
16471 + xorl %eax,%eax
16472 +#endif
16473 movl %eax,%gs
16474
16475 xorl %eax,%eax # Clear LDT
16476 @@ -558,22 +639,22 @@ early_page_fault:
16477 jmp early_fault
16478
16479 early_fault:
16480 - cld
16481 #ifdef CONFIG_PRINTK
16482 + cmpl $1,%ss:early_recursion_flag
16483 + je hlt_loop
16484 + incl %ss:early_recursion_flag
16485 + cld
16486 pusha
16487 movl $(__KERNEL_DS),%eax
16488 movl %eax,%ds
16489 movl %eax,%es
16490 - cmpl $2,early_recursion_flag
16491 - je hlt_loop
16492 - incl early_recursion_flag
16493 movl %cr2,%eax
16494 pushl %eax
16495 pushl %edx /* trapno */
16496 pushl $fault_msg
16497 call printk
16498 +; call dump_stack
16499 #endif
16500 - call dump_stack
16501 hlt_loop:
16502 hlt
16503 jmp hlt_loop
16504 @@ -581,8 +662,11 @@ hlt_loop:
16505 /* This is the default interrupt "handler" :-) */
16506 ALIGN
16507 ignore_int:
16508 - cld
16509 #ifdef CONFIG_PRINTK
16510 + cmpl $2,%ss:early_recursion_flag
16511 + je hlt_loop
16512 + incl %ss:early_recursion_flag
16513 + cld
16514 pushl %eax
16515 pushl %ecx
16516 pushl %edx
16517 @@ -591,9 +675,6 @@ ignore_int:
16518 movl $(__KERNEL_DS),%eax
16519 movl %eax,%ds
16520 movl %eax,%es
16521 - cmpl $2,early_recursion_flag
16522 - je hlt_loop
16523 - incl early_recursion_flag
16524 pushl 16(%esp)
16525 pushl 24(%esp)
16526 pushl 32(%esp)
16527 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16528 /*
16529 * BSS section
16530 */
16531 -__PAGE_ALIGNED_BSS
16532 - .align PAGE_SIZE
16533 #ifdef CONFIG_X86_PAE
16534 +.section .initial_pg_pmd,"a",@progbits
16535 initial_pg_pmd:
16536 .fill 1024*KPMDS,4,0
16537 #else
16538 +.section .initial_page_table,"a",@progbits
16539 ENTRY(initial_page_table)
16540 .fill 1024,4,0
16541 #endif
16542 +.section .initial_pg_fixmap,"a",@progbits
16543 initial_pg_fixmap:
16544 .fill 1024,4,0
16545 +.section .empty_zero_page,"a",@progbits
16546 ENTRY(empty_zero_page)
16547 .fill 4096,1,0
16548 +.section .swapper_pg_dir,"a",@progbits
16549 ENTRY(swapper_pg_dir)
16550 +#ifdef CONFIG_X86_PAE
16551 + .fill 4,8,0
16552 +#else
16553 .fill 1024,4,0
16554 +#endif
16555 +
16556 +/*
16557 + * The IDT has to be page-aligned to simplify the Pentium
16558 + * F0 0F bug workaround.. We have a special link segment
16559 + * for this.
16560 + */
16561 +.section .idt,"a",@progbits
16562 +ENTRY(idt_table)
16563 + .fill 256,8,0
16564
16565 /*
16566 * This starts the data section.
16567 */
16568 #ifdef CONFIG_X86_PAE
16569 -__PAGE_ALIGNED_DATA
16570 - /* Page-aligned for the benefit of paravirt? */
16571 - .align PAGE_SIZE
16572 +.section .initial_page_table,"a",@progbits
16573 ENTRY(initial_page_table)
16574 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16575 # if KPMDS == 3
16576 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16577 # error "Kernel PMDs should be 1, 2 or 3"
16578 # endif
16579 .align PAGE_SIZE /* needs to be page-sized too */
16580 +
16581 +#ifdef CONFIG_PAX_PER_CPU_PGD
16582 +ENTRY(cpu_pgd)
16583 + .rept NR_CPUS
16584 + .fill 4,8,0
16585 + .endr
16586 +#endif
16587 +
16588 #endif
16589
16590 .data
16591 .balign 4
16592 ENTRY(stack_start)
16593 - .long init_thread_union+THREAD_SIZE
16594 + .long init_thread_union+THREAD_SIZE-8
16595
16596 +ready: .byte 0
16597 +
16598 +.section .rodata,"a",@progbits
16599 early_recursion_flag:
16600 .long 0
16601
16602 -ready: .byte 0
16603 -
16604 int_msg:
16605 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16606
16607 @@ -707,7 +811,7 @@ fault_msg:
16608 .word 0 # 32 bit align gdt_desc.address
16609 boot_gdt_descr:
16610 .word __BOOT_DS+7
16611 - .long boot_gdt - __PAGE_OFFSET
16612 + .long pa(boot_gdt)
16613
16614 .word 0 # 32-bit align idt_desc.address
16615 idt_descr:
16616 @@ -718,7 +822,7 @@ idt_descr:
16617 .word 0 # 32 bit align gdt_desc.address
16618 ENTRY(early_gdt_descr)
16619 .word GDT_ENTRIES*8-1
16620 - .long gdt_page /* Overwritten for secondary CPUs */
16621 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16622
16623 /*
16624 * The boot_gdt must mirror the equivalent in setup.S and is
16625 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16626 .align L1_CACHE_BYTES
16627 ENTRY(boot_gdt)
16628 .fill GDT_ENTRY_BOOT_CS,8,0
16629 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16630 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16631 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16632 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16633 +
16634 + .align PAGE_SIZE_asm
16635 +ENTRY(cpu_gdt_table)
16636 + .rept NR_CPUS
16637 + .quad 0x0000000000000000 /* NULL descriptor */
16638 + .quad 0x0000000000000000 /* 0x0b reserved */
16639 + .quad 0x0000000000000000 /* 0x13 reserved */
16640 + .quad 0x0000000000000000 /* 0x1b reserved */
16641 +
16642 +#ifdef CONFIG_PAX_KERNEXEC
16643 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16644 +#else
16645 + .quad 0x0000000000000000 /* 0x20 unused */
16646 +#endif
16647 +
16648 + .quad 0x0000000000000000 /* 0x28 unused */
16649 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16650 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16651 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16652 + .quad 0x0000000000000000 /* 0x4b reserved */
16653 + .quad 0x0000000000000000 /* 0x53 reserved */
16654 + .quad 0x0000000000000000 /* 0x5b reserved */
16655 +
16656 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16657 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16658 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16659 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16660 +
16661 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16662 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16663 +
16664 + /*
16665 + * Segments used for calling PnP BIOS have byte granularity.
16666 + * The code segments and data segments have fixed 64k limits,
16667 + * the transfer segment sizes are set at run time.
16668 + */
16669 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16670 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16671 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16672 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16673 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16674 +
16675 + /*
16676 + * The APM segments have byte granularity and their bases
16677 + * are set at run time. All have 64k limits.
16678 + */
16679 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16680 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16681 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16682 +
16683 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16684 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16685 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16686 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16687 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16688 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16689 +
16690 + /* Be sure this is zeroed to avoid false validations in Xen */
16691 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16692 + .endr
16693 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16694 index 40f4eb3..6d24d9d 100644
16695 --- a/arch/x86/kernel/head_64.S
16696 +++ b/arch/x86/kernel/head_64.S
16697 @@ -19,6 +19,8 @@
16698 #include <asm/cache.h>
16699 #include <asm/processor-flags.h>
16700 #include <asm/percpu.h>
16701 +#include <asm/cpufeature.h>
16702 +#include <asm/alternative-asm.h>
16703
16704 #ifdef CONFIG_PARAVIRT
16705 #include <asm/asm-offsets.h>
16706 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16707 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16708 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16709 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16710 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16711 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16712 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16713 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16714 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16715 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16716
16717 .text
16718 __HEAD
16719 @@ -85,35 +93,23 @@ startup_64:
16720 */
16721 addq %rbp, init_level4_pgt + 0(%rip)
16722 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16723 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16724 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16725 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16726 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16727
16728 addq %rbp, level3_ident_pgt + 0(%rip)
16729 +#ifndef CONFIG_XEN
16730 + addq %rbp, level3_ident_pgt + 8(%rip)
16731 +#endif
16732
16733 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16734 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16735 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16736 +
16737 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16738 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16739
16740 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16741 -
16742 - /* Add an Identity mapping if I am above 1G */
16743 - leaq _text(%rip), %rdi
16744 - andq $PMD_PAGE_MASK, %rdi
16745 -
16746 - movq %rdi, %rax
16747 - shrq $PUD_SHIFT, %rax
16748 - andq $(PTRS_PER_PUD - 1), %rax
16749 - jz ident_complete
16750 -
16751 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16752 - leaq level3_ident_pgt(%rip), %rbx
16753 - movq %rdx, 0(%rbx, %rax, 8)
16754 -
16755 - movq %rdi, %rax
16756 - shrq $PMD_SHIFT, %rax
16757 - andq $(PTRS_PER_PMD - 1), %rax
16758 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16759 - leaq level2_spare_pgt(%rip), %rbx
16760 - movq %rdx, 0(%rbx, %rax, 8)
16761 -ident_complete:
16762 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16763
16764 /*
16765 * Fixup the kernel text+data virtual addresses. Note that
16766 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16767 * after the boot processor executes this code.
16768 */
16769
16770 - /* Enable PAE mode and PGE */
16771 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16772 + /* Enable PAE mode and PSE/PGE */
16773 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16774 movq %rax, %cr4
16775
16776 /* Setup early boot stage 4 level pagetables. */
16777 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16778 movl $MSR_EFER, %ecx
16779 rdmsr
16780 btsl $_EFER_SCE, %eax /* Enable System Call */
16781 - btl $20,%edi /* No Execute supported? */
16782 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16783 jnc 1f
16784 btsl $_EFER_NX, %eax
16785 + leaq init_level4_pgt(%rip), %rdi
16786 +#ifndef CONFIG_EFI
16787 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16788 +#endif
16789 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16790 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16791 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16792 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16793 1: wrmsr /* Make changes effective */
16794
16795 /* Setup cr0 */
16796 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16797 * jump. In addition we need to ensure %cs is set so we make this
16798 * a far return.
16799 */
16800 + pax_set_fptr_mask
16801 movq initial_code(%rip),%rax
16802 pushq $0 # fake return address to stop unwinder
16803 pushq $__KERNEL_CS # set correct cs
16804 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16805 bad_address:
16806 jmp bad_address
16807
16808 - .section ".init.text","ax"
16809 + __INIT
16810 #ifdef CONFIG_EARLY_PRINTK
16811 .globl early_idt_handlers
16812 early_idt_handlers:
16813 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16814 #endif /* EARLY_PRINTK */
16815 1: hlt
16816 jmp 1b
16817 + .previous
16818
16819 #ifdef CONFIG_EARLY_PRINTK
16820 + __INITDATA
16821 early_recursion_flag:
16822 .long 0
16823 + .previous
16824
16825 + .section .rodata,"a",@progbits
16826 early_idt_msg:
16827 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16828 early_idt_ripmsg:
16829 .asciz "RIP %s\n"
16830 + .previous
16831 #endif /* CONFIG_EARLY_PRINTK */
16832 - .previous
16833
16834 + .section .rodata,"a",@progbits
16835 #define NEXT_PAGE(name) \
16836 .balign PAGE_SIZE; \
16837 ENTRY(name)
16838 @@ -338,7 +348,6 @@ ENTRY(name)
16839 i = i + 1 ; \
16840 .endr
16841
16842 - .data
16843 /*
16844 * This default setting generates an ident mapping at address 0x100000
16845 * and a mapping for the kernel that precisely maps virtual address
16846 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16847 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16848 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16849 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16850 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16851 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16852 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16853 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16854 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16855 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16856 .org init_level4_pgt + L4_START_KERNEL*8, 0
16857 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16858 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16859
16860 +#ifdef CONFIG_PAX_PER_CPU_PGD
16861 +NEXT_PAGE(cpu_pgd)
16862 + .rept NR_CPUS
16863 + .fill 512,8,0
16864 + .endr
16865 +#endif
16866 +
16867 NEXT_PAGE(level3_ident_pgt)
16868 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16869 +#ifdef CONFIG_XEN
16870 .fill 511,8,0
16871 +#else
16872 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16873 + .fill 510,8,0
16874 +#endif
16875 +
16876 +NEXT_PAGE(level3_vmalloc_start_pgt)
16877 + .fill 512,8,0
16878 +
16879 +NEXT_PAGE(level3_vmalloc_end_pgt)
16880 + .fill 512,8,0
16881 +
16882 +NEXT_PAGE(level3_vmemmap_pgt)
16883 + .fill L3_VMEMMAP_START,8,0
16884 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16885
16886 NEXT_PAGE(level3_kernel_pgt)
16887 .fill L3_START_KERNEL,8,0
16888 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16889 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16890 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16891
16892 +NEXT_PAGE(level2_vmemmap_pgt)
16893 + .fill 512,8,0
16894 +
16895 NEXT_PAGE(level2_fixmap_pgt)
16896 - .fill 506,8,0
16897 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16898 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16899 - .fill 5,8,0
16900 + .fill 507,8,0
16901 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16902 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16903 + .fill 4,8,0
16904
16905 -NEXT_PAGE(level1_fixmap_pgt)
16906 +NEXT_PAGE(level1_vsyscall_pgt)
16907 .fill 512,8,0
16908
16909 -NEXT_PAGE(level2_ident_pgt)
16910 - /* Since I easily can, map the first 1G.
16911 + /* Since I easily can, map the first 2G.
16912 * Don't set NX because code runs from these pages.
16913 */
16914 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16915 +NEXT_PAGE(level2_ident_pgt)
16916 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16917
16918 NEXT_PAGE(level2_kernel_pgt)
16919 /*
16920 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16921 * If you want to increase this then increase MODULES_VADDR
16922 * too.)
16923 */
16924 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16925 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16926 -
16927 -NEXT_PAGE(level2_spare_pgt)
16928 - .fill 512, 8, 0
16929 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16930
16931 #undef PMDS
16932 #undef NEXT_PAGE
16933
16934 - .data
16935 + .align PAGE_SIZE
16936 +ENTRY(cpu_gdt_table)
16937 + .rept NR_CPUS
16938 + .quad 0x0000000000000000 /* NULL descriptor */
16939 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16940 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16941 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16942 + .quad 0x00cffb000000ffff /* __USER32_CS */
16943 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16944 + .quad 0x00affb000000ffff /* __USER_CS */
16945 +
16946 +#ifdef CONFIG_PAX_KERNEXEC
16947 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16948 +#else
16949 + .quad 0x0 /* unused */
16950 +#endif
16951 +
16952 + .quad 0,0 /* TSS */
16953 + .quad 0,0 /* LDT */
16954 + .quad 0,0,0 /* three TLS descriptors */
16955 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16956 + /* asm/segment.h:GDT_ENTRIES must match this */
16957 +
16958 + /* zero the remaining page */
16959 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16960 + .endr
16961 +
16962 .align 16
16963 .globl early_gdt_descr
16964 early_gdt_descr:
16965 .word GDT_ENTRIES*8-1
16966 early_gdt_descr_base:
16967 - .quad INIT_PER_CPU_VAR(gdt_page)
16968 + .quad cpu_gdt_table
16969
16970 ENTRY(phys_base)
16971 /* This must match the first entry in level2_kernel_pgt */
16972 .quad 0x0000000000000000
16973
16974 #include "../../x86/xen/xen-head.S"
16975 -
16976 - .section .bss, "aw", @nobits
16977 +
16978 + .section .rodata,"a",@progbits
16979 .align L1_CACHE_BYTES
16980 ENTRY(idt_table)
16981 - .skip IDT_ENTRIES * 16
16982 + .fill 512,8,0
16983
16984 .align L1_CACHE_BYTES
16985 ENTRY(nmi_idt_table)
16986 - .skip IDT_ENTRIES * 16
16987 + .fill 512,8,0
16988
16989 __PAGE_ALIGNED_BSS
16990 .align PAGE_SIZE
16991 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16992 index 9c3bd4a..e1d9b35 100644
16993 --- a/arch/x86/kernel/i386_ksyms_32.c
16994 +++ b/arch/x86/kernel/i386_ksyms_32.c
16995 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16996 EXPORT_SYMBOL(cmpxchg8b_emu);
16997 #endif
16998
16999 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17000 +
17001 /* Networking helper routines. */
17002 EXPORT_SYMBOL(csum_partial_copy_generic);
17003 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17004 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17005
17006 EXPORT_SYMBOL(__get_user_1);
17007 EXPORT_SYMBOL(__get_user_2);
17008 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17009
17010 EXPORT_SYMBOL(csum_partial);
17011 EXPORT_SYMBOL(empty_zero_page);
17012 +
17013 +#ifdef CONFIG_PAX_KERNEXEC
17014 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17015 +#endif
17016 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17017 index 739d859..d1d6be7 100644
17018 --- a/arch/x86/kernel/i387.c
17019 +++ b/arch/x86/kernel/i387.c
17020 @@ -188,6 +188,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17021
17022 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17023 unsigned int pos, unsigned int count,
17024 + void *kbuf, void __user *ubuf) __size_overflow(4);
17025 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17026 + unsigned int pos, unsigned int count,
17027 void *kbuf, void __user *ubuf)
17028 {
17029 int ret;
17030 @@ -207,6 +210,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17031
17032 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17033 unsigned int pos, unsigned int count,
17034 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17035 +int xfpregs_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)
17038 {
17039 int ret;
17040 @@ -240,6 +246,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17041
17042 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17043 unsigned int pos, unsigned int count,
17044 + void *kbuf, void __user *ubuf) __size_overflow(4);
17045 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17046 + unsigned int pos, unsigned int count,
17047 void *kbuf, void __user *ubuf)
17048 {
17049 int ret;
17050 @@ -269,6 +278,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17051
17052 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17053 unsigned int pos, unsigned int count,
17054 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17055 +int xstateregs_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)
17058 {
17059 int ret;
17060 @@ -439,6 +451,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17061
17062 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17063 unsigned int pos, unsigned int count,
17064 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17065 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17066 + unsigned int pos, unsigned int count,
17067 void *kbuf, void __user *ubuf)
17068 {
17069 struct user_i387_ia32_struct env;
17070 @@ -471,6 +486,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17071
17072 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17073 unsigned int pos, unsigned int count,
17074 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17075 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17076 + unsigned int pos, unsigned int count,
17077 const void *kbuf, const void __user *ubuf)
17078 {
17079 struct user_i387_ia32_struct env;
17080 @@ -619,6 +637,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17081 }
17082
17083 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17084 + unsigned int size) __size_overflow(2);
17085 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17086 unsigned int size)
17087 {
17088 struct task_struct *tsk = current;
17089 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17090 index 6104852..6114160 100644
17091 --- a/arch/x86/kernel/i8259.c
17092 +++ b/arch/x86/kernel/i8259.c
17093 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17094 "spurious 8259A interrupt: IRQ%d.\n", irq);
17095 spurious_irq_mask |= irqmask;
17096 }
17097 - atomic_inc(&irq_err_count);
17098 + atomic_inc_unchecked(&irq_err_count);
17099 /*
17100 * Theoretically we do not have to handle this IRQ,
17101 * but in Linux this does not cause problems and is
17102 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17103 index 43e9ccf..44ccf6f 100644
17104 --- a/arch/x86/kernel/init_task.c
17105 +++ b/arch/x86/kernel/init_task.c
17106 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17107 * way process stacks are handled. This is done by having a special
17108 * "init_task" linker map entry..
17109 */
17110 -union thread_union init_thread_union __init_task_data =
17111 - { INIT_THREAD_INFO(init_task) };
17112 +union thread_union init_thread_union __init_task_data;
17113
17114 /*
17115 * Initial task structure.
17116 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17117 * section. Since TSS's are completely CPU-local, we want them
17118 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17119 */
17120 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17121 -
17122 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17123 +EXPORT_SYMBOL(init_tss);
17124 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17125 index 8c96897..be66bfa 100644
17126 --- a/arch/x86/kernel/ioport.c
17127 +++ b/arch/x86/kernel/ioport.c
17128 @@ -6,6 +6,7 @@
17129 #include <linux/sched.h>
17130 #include <linux/kernel.h>
17131 #include <linux/capability.h>
17132 +#include <linux/security.h>
17133 #include <linux/errno.h>
17134 #include <linux/types.h>
17135 #include <linux/ioport.h>
17136 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17137
17138 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17139 return -EINVAL;
17140 +#ifdef CONFIG_GRKERNSEC_IO
17141 + if (turn_on && grsec_disable_privio) {
17142 + gr_handle_ioperm();
17143 + return -EPERM;
17144 + }
17145 +#endif
17146 if (turn_on && !capable(CAP_SYS_RAWIO))
17147 return -EPERM;
17148
17149 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17150 * because the ->io_bitmap_max value must match the bitmap
17151 * contents:
17152 */
17153 - tss = &per_cpu(init_tss, get_cpu());
17154 + tss = init_tss + get_cpu();
17155
17156 if (turn_on)
17157 bitmap_clear(t->io_bitmap_ptr, from, num);
17158 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17159 return -EINVAL;
17160 /* Trying to gain more privileges? */
17161 if (level > old) {
17162 +#ifdef CONFIG_GRKERNSEC_IO
17163 + if (grsec_disable_privio) {
17164 + gr_handle_iopl();
17165 + return -EPERM;
17166 + }
17167 +#endif
17168 if (!capable(CAP_SYS_RAWIO))
17169 return -EPERM;
17170 }
17171 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17172 index 7943e0c..dd32c5c 100644
17173 --- a/arch/x86/kernel/irq.c
17174 +++ b/arch/x86/kernel/irq.c
17175 @@ -18,7 +18,7 @@
17176 #include <asm/mce.h>
17177 #include <asm/hw_irq.h>
17178
17179 -atomic_t irq_err_count;
17180 +atomic_unchecked_t irq_err_count;
17181
17182 /* Function pointer for generic interrupt vector handling */
17183 void (*x86_platform_ipi_callback)(void) = NULL;
17184 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17185 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17186 seq_printf(p, " Machine check polls\n");
17187 #endif
17188 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17189 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17190 #if defined(CONFIG_X86_IO_APIC)
17191 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17192 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17193 #endif
17194 return 0;
17195 }
17196 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17197
17198 u64 arch_irq_stat(void)
17199 {
17200 - u64 sum = atomic_read(&irq_err_count);
17201 + u64 sum = atomic_read_unchecked(&irq_err_count);
17202
17203 #ifdef CONFIG_X86_IO_APIC
17204 - sum += atomic_read(&irq_mis_count);
17205 + sum += atomic_read_unchecked(&irq_mis_count);
17206 #endif
17207 return sum;
17208 }
17209 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17210 index 40fc861..9b8739b 100644
17211 --- a/arch/x86/kernel/irq_32.c
17212 +++ b/arch/x86/kernel/irq_32.c
17213 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17214 __asm__ __volatile__("andl %%esp,%0" :
17215 "=r" (sp) : "0" (THREAD_SIZE - 1));
17216
17217 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17218 + return sp < STACK_WARN;
17219 }
17220
17221 static void print_stack_overflow(void)
17222 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17223 * per-CPU IRQ handling contexts (thread information and stack)
17224 */
17225 union irq_ctx {
17226 - struct thread_info tinfo;
17227 - u32 stack[THREAD_SIZE/sizeof(u32)];
17228 + unsigned long previous_esp;
17229 + u32 stack[THREAD_SIZE/sizeof(u32)];
17230 } __attribute__((aligned(THREAD_SIZE)));
17231
17232 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17233 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17234 static inline int
17235 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17236 {
17237 - union irq_ctx *curctx, *irqctx;
17238 + union irq_ctx *irqctx;
17239 u32 *isp, arg1, arg2;
17240
17241 - curctx = (union irq_ctx *) current_thread_info();
17242 irqctx = __this_cpu_read(hardirq_ctx);
17243
17244 /*
17245 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17246 * handler) we can't do that and just have to keep using the
17247 * current stack (which is the irq stack already after all)
17248 */
17249 - if (unlikely(curctx == irqctx))
17250 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17251 return 0;
17252
17253 /* build the stack frame on the IRQ stack */
17254 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17255 - irqctx->tinfo.task = curctx->tinfo.task;
17256 - irqctx->tinfo.previous_esp = current_stack_pointer;
17257 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17258 + irqctx->previous_esp = current_stack_pointer;
17259
17260 - /*
17261 - * Copy the softirq bits in preempt_count so that the
17262 - * softirq checks work in the hardirq context.
17263 - */
17264 - irqctx->tinfo.preempt_count =
17265 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17266 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17268 + __set_fs(MAKE_MM_SEG(0));
17269 +#endif
17270
17271 if (unlikely(overflow))
17272 call_on_stack(print_stack_overflow, isp);
17273 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17274 : "0" (irq), "1" (desc), "2" (isp),
17275 "D" (desc->handle_irq)
17276 : "memory", "cc", "ecx");
17277 +
17278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17279 + __set_fs(current_thread_info()->addr_limit);
17280 +#endif
17281 +
17282 return 1;
17283 }
17284
17285 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17286 */
17287 void __cpuinit irq_ctx_init(int cpu)
17288 {
17289 - union irq_ctx *irqctx;
17290 -
17291 if (per_cpu(hardirq_ctx, cpu))
17292 return;
17293
17294 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17295 - THREAD_FLAGS,
17296 - THREAD_ORDER));
17297 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17298 - irqctx->tinfo.cpu = cpu;
17299 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17300 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17301 -
17302 - per_cpu(hardirq_ctx, cpu) = irqctx;
17303 -
17304 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17305 - THREAD_FLAGS,
17306 - THREAD_ORDER));
17307 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17308 - irqctx->tinfo.cpu = cpu;
17309 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17310 -
17311 - per_cpu(softirq_ctx, cpu) = irqctx;
17312 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17313 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17314
17315 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17316 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17317 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17318 asmlinkage void do_softirq(void)
17319 {
17320 unsigned long flags;
17321 - struct thread_info *curctx;
17322 union irq_ctx *irqctx;
17323 u32 *isp;
17324
17325 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17326 local_irq_save(flags);
17327
17328 if (local_softirq_pending()) {
17329 - curctx = current_thread_info();
17330 irqctx = __this_cpu_read(softirq_ctx);
17331 - irqctx->tinfo.task = curctx->task;
17332 - irqctx->tinfo.previous_esp = current_stack_pointer;
17333 + irqctx->previous_esp = current_stack_pointer;
17334
17335 /* build the stack frame on the softirq stack */
17336 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17337 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17338 +
17339 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17340 + __set_fs(MAKE_MM_SEG(0));
17341 +#endif
17342
17343 call_on_stack(__do_softirq, isp);
17344 +
17345 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17346 + __set_fs(current_thread_info()->addr_limit);
17347 +#endif
17348 +
17349 /*
17350 * Shouldn't happen, we returned above if in_interrupt():
17351 */
17352 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17353 index d04d3ec..ea4b374 100644
17354 --- a/arch/x86/kernel/irq_64.c
17355 +++ b/arch/x86/kernel/irq_64.c
17356 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17357 u64 estack_top, estack_bottom;
17358 u64 curbase = (u64)task_stack_page(current);
17359
17360 - if (user_mode_vm(regs))
17361 + if (user_mode(regs))
17362 return;
17363
17364 if (regs->sp >= curbase + sizeof(struct thread_info) +
17365 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17366 index 90fcf62..e682cdd 100644
17367 --- a/arch/x86/kernel/kdebugfs.c
17368 +++ b/arch/x86/kernel/kdebugfs.c
17369 @@ -28,6 +28,8 @@ struct setup_data_node {
17370 };
17371
17372 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17373 + size_t count, loff_t *ppos) __size_overflow(3);
17374 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17375 size_t count, loff_t *ppos)
17376 {
17377 struct setup_data_node *node = file->private_data;
17378 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17379 index 2f45c4c..d95504f 100644
17380 --- a/arch/x86/kernel/kgdb.c
17381 +++ b/arch/x86/kernel/kgdb.c
17382 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17383 #ifdef CONFIG_X86_32
17384 switch (regno) {
17385 case GDB_SS:
17386 - if (!user_mode_vm(regs))
17387 + if (!user_mode(regs))
17388 *(unsigned long *)mem = __KERNEL_DS;
17389 break;
17390 case GDB_SP:
17391 - if (!user_mode_vm(regs))
17392 + if (!user_mode(regs))
17393 *(unsigned long *)mem = kernel_stack_pointer(regs);
17394 break;
17395 case GDB_GS:
17396 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17397 case 'k':
17398 /* clear the trace bit */
17399 linux_regs->flags &= ~X86_EFLAGS_TF;
17400 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17401 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17402
17403 /* set the trace bit if we're stepping */
17404 if (remcomInBuffer[0] == 's') {
17405 linux_regs->flags |= X86_EFLAGS_TF;
17406 - atomic_set(&kgdb_cpu_doing_single_step,
17407 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17408 raw_smp_processor_id());
17409 }
17410
17411 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17412
17413 switch (cmd) {
17414 case DIE_DEBUG:
17415 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17416 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17417 if (user_mode(regs))
17418 return single_step_cont(regs, args);
17419 break;
17420 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17421 index 7da647d..56fe348 100644
17422 --- a/arch/x86/kernel/kprobes.c
17423 +++ b/arch/x86/kernel/kprobes.c
17424 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17425 } __attribute__((packed)) *insn;
17426
17427 insn = (struct __arch_relative_insn *)from;
17428 +
17429 + pax_open_kernel();
17430 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17431 insn->op = op;
17432 + pax_close_kernel();
17433 }
17434
17435 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17436 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17437 kprobe_opcode_t opcode;
17438 kprobe_opcode_t *orig_opcodes = opcodes;
17439
17440 - if (search_exception_tables((unsigned long)opcodes))
17441 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17442 return 0; /* Page fault may occur on this address. */
17443
17444 retry:
17445 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17446 }
17447 }
17448 insn_get_length(&insn);
17449 + pax_open_kernel();
17450 memcpy(dest, insn.kaddr, insn.length);
17451 + pax_close_kernel();
17452
17453 #ifdef CONFIG_X86_64
17454 if (insn_rip_relative(&insn)) {
17455 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17456 (u8 *) dest;
17457 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17458 disp = (u8 *) dest + insn_offset_displacement(&insn);
17459 + pax_open_kernel();
17460 *(s32 *) disp = (s32) newdisp;
17461 + pax_close_kernel();
17462 }
17463 #endif
17464 return insn.length;
17465 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17466 */
17467 __copy_instruction(p->ainsn.insn, p->addr, 0);
17468
17469 - if (can_boost(p->addr))
17470 + if (can_boost(ktla_ktva(p->addr)))
17471 p->ainsn.boostable = 0;
17472 else
17473 p->ainsn.boostable = -1;
17474
17475 - p->opcode = *p->addr;
17476 + p->opcode = *(ktla_ktva(p->addr));
17477 }
17478
17479 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17480 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17481 * nor set current_kprobe, because it doesn't use single
17482 * stepping.
17483 */
17484 - regs->ip = (unsigned long)p->ainsn.insn;
17485 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17486 preempt_enable_no_resched();
17487 return;
17488 }
17489 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17490 if (p->opcode == BREAKPOINT_INSTRUCTION)
17491 regs->ip = (unsigned long)p->addr;
17492 else
17493 - regs->ip = (unsigned long)p->ainsn.insn;
17494 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17495 }
17496
17497 /*
17498 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17499 setup_singlestep(p, regs, kcb, 0);
17500 return 1;
17501 }
17502 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17503 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17504 /*
17505 * The breakpoint instruction was removed right
17506 * after we hit it. Another cpu has removed
17507 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17508 " movq %rax, 152(%rsp)\n"
17509 RESTORE_REGS_STRING
17510 " popfq\n"
17511 +#ifdef KERNEXEC_PLUGIN
17512 + " btsq $63,(%rsp)\n"
17513 +#endif
17514 #else
17515 " pushf\n"
17516 SAVE_REGS_STRING
17517 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17518 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17519 {
17520 unsigned long *tos = stack_addr(regs);
17521 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17522 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17523 unsigned long orig_ip = (unsigned long)p->addr;
17524 kprobe_opcode_t *insn = p->ainsn.insn;
17525
17526 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17527 struct die_args *args = data;
17528 int ret = NOTIFY_DONE;
17529
17530 - if (args->regs && user_mode_vm(args->regs))
17531 + if (args->regs && user_mode(args->regs))
17532 return ret;
17533
17534 switch (val) {
17535 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17536 * Verify if the address gap is in 2GB range, because this uses
17537 * a relative jump.
17538 */
17539 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17540 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17541 if (abs(rel) > 0x7fffffff)
17542 return -ERANGE;
17543
17544 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17545 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17546
17547 /* Set probe function call */
17548 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17549 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17550
17551 /* Set returning jmp instruction at the tail of out-of-line buffer */
17552 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17553 - (u8 *)op->kp.addr + op->optinsn.size);
17554 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17555
17556 flush_icache_range((unsigned long) buf,
17557 (unsigned long) buf + TMPL_END_IDX +
17558 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17559 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17560
17561 /* Backup instructions which will be replaced by jump address */
17562 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17563 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17564 RELATIVE_ADDR_SIZE);
17565
17566 insn_buf[0] = RELATIVEJUMP_OPCODE;
17567 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17568 index ea69726..a305f16 100644
17569 --- a/arch/x86/kernel/ldt.c
17570 +++ b/arch/x86/kernel/ldt.c
17571 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17572 if (reload) {
17573 #ifdef CONFIG_SMP
17574 preempt_disable();
17575 - load_LDT(pc);
17576 + load_LDT_nolock(pc);
17577 if (!cpumask_equal(mm_cpumask(current->mm),
17578 cpumask_of(smp_processor_id())))
17579 smp_call_function(flush_ldt, current->mm, 1);
17580 preempt_enable();
17581 #else
17582 - load_LDT(pc);
17583 + load_LDT_nolock(pc);
17584 #endif
17585 }
17586 if (oldsize) {
17587 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17588 return err;
17589
17590 for (i = 0; i < old->size; i++)
17591 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17592 + write_ldt_entry(new->ldt, i, old->ldt + i);
17593 return 0;
17594 }
17595
17596 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17597 retval = copy_ldt(&mm->context, &old_mm->context);
17598 mutex_unlock(&old_mm->context.lock);
17599 }
17600 +
17601 + if (tsk == current) {
17602 + mm->context.vdso = 0;
17603 +
17604 +#ifdef CONFIG_X86_32
17605 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17606 + mm->context.user_cs_base = 0UL;
17607 + mm->context.user_cs_limit = ~0UL;
17608 +
17609 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17610 + cpus_clear(mm->context.cpu_user_cs_mask);
17611 +#endif
17612 +
17613 +#endif
17614 +#endif
17615 +
17616 + }
17617 +
17618 return retval;
17619 }
17620
17621 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17622 }
17623 }
17624
17625 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17626 static int read_ldt(void __user *ptr, unsigned long bytecount)
17627 {
17628 int err;
17629 @@ -175,6 +194,7 @@ error_return:
17630 return err;
17631 }
17632
17633 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17634 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
17635 {
17636 /* CHECKME: Can we use _one_ random number ? */
17637 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17638 }
17639 }
17640
17641 +#ifdef CONFIG_PAX_SEGMEXEC
17642 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17643 + error = -EINVAL;
17644 + goto out_unlock;
17645 + }
17646 +#endif
17647 +
17648 fill_ldt(&ldt, &ldt_info);
17649 if (oldmode)
17650 ldt.avl = 0;
17651 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17652 index a3fa43b..8966f4c 100644
17653 --- a/arch/x86/kernel/machine_kexec_32.c
17654 +++ b/arch/x86/kernel/machine_kexec_32.c
17655 @@ -27,7 +27,7 @@
17656 #include <asm/cacheflush.h>
17657 #include <asm/debugreg.h>
17658
17659 -static void set_idt(void *newidt, __u16 limit)
17660 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17661 {
17662 struct desc_ptr curidt;
17663
17664 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17665 }
17666
17667
17668 -static void set_gdt(void *newgdt, __u16 limit)
17669 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17670 {
17671 struct desc_ptr curgdt;
17672
17673 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17674 }
17675
17676 control_page = page_address(image->control_code_page);
17677 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17678 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17679
17680 relocate_kernel_ptr = control_page;
17681 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17682 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17683 index 3ca42d0..79d24cd 100644
17684 --- a/arch/x86/kernel/microcode_intel.c
17685 +++ b/arch/x86/kernel/microcode_intel.c
17686 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17687 return ret;
17688 }
17689
17690 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17691 static int get_ucode_user(void *to, const void *from, size_t n)
17692 {
17693 - return copy_from_user(to, from, n);
17694 + return copy_from_user(to, (const void __force_user *)from, n);
17695 }
17696
17697 static enum ucode_state
17698 request_microcode_user(int cpu, const void __user *buf, size_t size)
17699 {
17700 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17701 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17702 }
17703
17704 static void microcode_fini_cpu(int cpu)
17705 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17706 index 925179f..1f0d561 100644
17707 --- a/arch/x86/kernel/module.c
17708 +++ b/arch/x86/kernel/module.c
17709 @@ -36,15 +36,61 @@
17710 #define DEBUGP(fmt...)
17711 #endif
17712
17713 -void *module_alloc(unsigned long size)
17714 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
17715 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17716 {
17717 - if (PAGE_ALIGN(size) > MODULES_LEN)
17718 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17719 return NULL;
17720 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17721 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17722 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17723 -1, __builtin_return_address(0));
17724 }
17725
17726 +void *module_alloc(unsigned long size)
17727 +{
17728 +
17729 +#ifdef CONFIG_PAX_KERNEXEC
17730 + return __module_alloc(size, PAGE_KERNEL);
17731 +#else
17732 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17733 +#endif
17734 +
17735 +}
17736 +
17737 +#ifdef CONFIG_PAX_KERNEXEC
17738 +#ifdef CONFIG_X86_32
17739 +void *module_alloc_exec(unsigned long size)
17740 +{
17741 + struct vm_struct *area;
17742 +
17743 + if (size == 0)
17744 + return NULL;
17745 +
17746 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17747 + return area ? area->addr : NULL;
17748 +}
17749 +EXPORT_SYMBOL(module_alloc_exec);
17750 +
17751 +void module_free_exec(struct module *mod, void *module_region)
17752 +{
17753 + vunmap(module_region);
17754 +}
17755 +EXPORT_SYMBOL(module_free_exec);
17756 +#else
17757 +void module_free_exec(struct module *mod, void *module_region)
17758 +{
17759 + module_free(mod, module_region);
17760 +}
17761 +EXPORT_SYMBOL(module_free_exec);
17762 +
17763 +void *module_alloc_exec(unsigned long size)
17764 +{
17765 + return __module_alloc(size, PAGE_KERNEL_RX);
17766 +}
17767 +EXPORT_SYMBOL(module_alloc_exec);
17768 +#endif
17769 +#endif
17770 +
17771 #ifdef CONFIG_X86_32
17772 int apply_relocate(Elf32_Shdr *sechdrs,
17773 const char *strtab,
17774 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17775 unsigned int i;
17776 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17777 Elf32_Sym *sym;
17778 - uint32_t *location;
17779 + uint32_t *plocation, location;
17780
17781 DEBUGP("Applying relocate section %u to %u\n", relsec,
17782 sechdrs[relsec].sh_info);
17783 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17784 /* This is where to make the change */
17785 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17786 - + rel[i].r_offset;
17787 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17788 + location = (uint32_t)plocation;
17789 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17790 + plocation = ktla_ktva((void *)plocation);
17791 /* This is the symbol it is referring to. Note that all
17792 undefined symbols have been resolved. */
17793 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17794 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17795 switch (ELF32_R_TYPE(rel[i].r_info)) {
17796 case R_386_32:
17797 /* We add the value into the location given */
17798 - *location += sym->st_value;
17799 + pax_open_kernel();
17800 + *plocation += sym->st_value;
17801 + pax_close_kernel();
17802 break;
17803 case R_386_PC32:
17804 /* Add the value, subtract its postition */
17805 - *location += sym->st_value - (uint32_t)location;
17806 + pax_open_kernel();
17807 + *plocation += sym->st_value - location;
17808 + pax_close_kernel();
17809 break;
17810 default:
17811 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17812 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17813 case R_X86_64_NONE:
17814 break;
17815 case R_X86_64_64:
17816 + pax_open_kernel();
17817 *(u64 *)loc = val;
17818 + pax_close_kernel();
17819 break;
17820 case R_X86_64_32:
17821 + pax_open_kernel();
17822 *(u32 *)loc = val;
17823 + pax_close_kernel();
17824 if (val != *(u32 *)loc)
17825 goto overflow;
17826 break;
17827 case R_X86_64_32S:
17828 + pax_open_kernel();
17829 *(s32 *)loc = val;
17830 + pax_close_kernel();
17831 if ((s64)val != *(s32 *)loc)
17832 goto overflow;
17833 break;
17834 case R_X86_64_PC32:
17835 val -= (u64)loc;
17836 + pax_open_kernel();
17837 *(u32 *)loc = val;
17838 + pax_close_kernel();
17839 +
17840 #if 0
17841 if ((s64)val != *(s32 *)loc)
17842 goto overflow;
17843 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17844 index 47acaf3..ec48ab6 100644
17845 --- a/arch/x86/kernel/nmi.c
17846 +++ b/arch/x86/kernel/nmi.c
17847 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17848 dotraplinkage notrace __kprobes void
17849 do_nmi(struct pt_regs *regs, long error_code)
17850 {
17851 +
17852 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17853 + if (!user_mode(regs)) {
17854 + unsigned long cs = regs->cs & 0xFFFF;
17855 + unsigned long ip = ktva_ktla(regs->ip);
17856 +
17857 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17858 + regs->ip = ip;
17859 + }
17860 +#endif
17861 +
17862 nmi_nesting_preprocess(regs);
17863
17864 nmi_enter();
17865 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17866 index 676b8c7..870ba04 100644
17867 --- a/arch/x86/kernel/paravirt-spinlocks.c
17868 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17869 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17870 arch_spin_lock(lock);
17871 }
17872
17873 -struct pv_lock_ops pv_lock_ops = {
17874 +struct pv_lock_ops pv_lock_ops __read_only = {
17875 #ifdef CONFIG_SMP
17876 .spin_is_locked = __ticket_spin_is_locked,
17877 .spin_is_contended = __ticket_spin_is_contended,
17878 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17879 index d90272e..6bb013b 100644
17880 --- a/arch/x86/kernel/paravirt.c
17881 +++ b/arch/x86/kernel/paravirt.c
17882 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17883 {
17884 return x;
17885 }
17886 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17887 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17888 +#endif
17889
17890 void __init default_banner(void)
17891 {
17892 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17893 if (opfunc == NULL)
17894 /* If there's no function, patch it with a ud2a (BUG) */
17895 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17896 - else if (opfunc == _paravirt_nop)
17897 + else if (opfunc == (void *)_paravirt_nop)
17898 /* If the operation is a nop, then nop the callsite */
17899 ret = paravirt_patch_nop();
17900
17901 /* identity functions just return their single argument */
17902 - else if (opfunc == _paravirt_ident_32)
17903 + else if (opfunc == (void *)_paravirt_ident_32)
17904 ret = paravirt_patch_ident_32(insnbuf, len);
17905 - else if (opfunc == _paravirt_ident_64)
17906 + else if (opfunc == (void *)_paravirt_ident_64)
17907 ret = paravirt_patch_ident_64(insnbuf, len);
17908 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17909 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17910 + ret = paravirt_patch_ident_64(insnbuf, len);
17911 +#endif
17912
17913 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17914 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17915 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17916 if (insn_len > len || start == NULL)
17917 insn_len = len;
17918 else
17919 - memcpy(insnbuf, start, insn_len);
17920 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17921
17922 return insn_len;
17923 }
17924 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17925 preempt_enable();
17926 }
17927
17928 -struct pv_info pv_info = {
17929 +struct pv_info pv_info __read_only = {
17930 .name = "bare hardware",
17931 .paravirt_enabled = 0,
17932 .kernel_rpl = 0,
17933 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17934 #endif
17935 };
17936
17937 -struct pv_init_ops pv_init_ops = {
17938 +struct pv_init_ops pv_init_ops __read_only = {
17939 .patch = native_patch,
17940 };
17941
17942 -struct pv_time_ops pv_time_ops = {
17943 +struct pv_time_ops pv_time_ops __read_only = {
17944 .sched_clock = native_sched_clock,
17945 .steal_clock = native_steal_clock,
17946 };
17947
17948 -struct pv_irq_ops pv_irq_ops = {
17949 +struct pv_irq_ops pv_irq_ops __read_only = {
17950 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17951 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17952 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17953 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17954 #endif
17955 };
17956
17957 -struct pv_cpu_ops pv_cpu_ops = {
17958 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17959 .cpuid = native_cpuid,
17960 .get_debugreg = native_get_debugreg,
17961 .set_debugreg = native_set_debugreg,
17962 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17963 .end_context_switch = paravirt_nop,
17964 };
17965
17966 -struct pv_apic_ops pv_apic_ops = {
17967 +struct pv_apic_ops pv_apic_ops __read_only = {
17968 #ifdef CONFIG_X86_LOCAL_APIC
17969 .startup_ipi_hook = paravirt_nop,
17970 #endif
17971 };
17972
17973 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17974 +#ifdef CONFIG_X86_32
17975 +#ifdef CONFIG_X86_PAE
17976 +/* 64-bit pagetable entries */
17977 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17978 +#else
17979 /* 32-bit pagetable entries */
17980 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17981 +#endif
17982 #else
17983 /* 64-bit pagetable entries */
17984 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17985 #endif
17986
17987 -struct pv_mmu_ops pv_mmu_ops = {
17988 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17989
17990 .read_cr2 = native_read_cr2,
17991 .write_cr2 = native_write_cr2,
17992 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17993 .make_pud = PTE_IDENT,
17994
17995 .set_pgd = native_set_pgd,
17996 + .set_pgd_batched = native_set_pgd_batched,
17997 #endif
17998 #endif /* PAGETABLE_LEVELS >= 3 */
17999
18000 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18001 },
18002
18003 .set_fixmap = native_set_fixmap,
18004 +
18005 +#ifdef CONFIG_PAX_KERNEXEC
18006 + .pax_open_kernel = native_pax_open_kernel,
18007 + .pax_close_kernel = native_pax_close_kernel,
18008 +#endif
18009 +
18010 };
18011
18012 EXPORT_SYMBOL_GPL(pv_time_ops);
18013 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18014 index 35ccf75..7a15747 100644
18015 --- a/arch/x86/kernel/pci-iommu_table.c
18016 +++ b/arch/x86/kernel/pci-iommu_table.c
18017 @@ -2,7 +2,7 @@
18018 #include <asm/iommu_table.h>
18019 #include <linux/string.h>
18020 #include <linux/kallsyms.h>
18021 -
18022 +#include <linux/sched.h>
18023
18024 #define DEBUG 1
18025
18026 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18027 index 15763af..da59ada 100644
18028 --- a/arch/x86/kernel/process.c
18029 +++ b/arch/x86/kernel/process.c
18030 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18031
18032 void free_thread_info(struct thread_info *ti)
18033 {
18034 - free_thread_xstate(ti->task);
18035 free_pages((unsigned long)ti, THREAD_ORDER);
18036 }
18037
18038 +static struct kmem_cache *task_struct_cachep;
18039 +
18040 void arch_task_cache_init(void)
18041 {
18042 - task_xstate_cachep =
18043 - kmem_cache_create("task_xstate", xstate_size,
18044 + /* create a slab on which task_structs can be allocated */
18045 + task_struct_cachep =
18046 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18047 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18048 +
18049 + task_xstate_cachep =
18050 + kmem_cache_create("task_xstate", xstate_size,
18051 __alignof__(union thread_xstate),
18052 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18053 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18054 +}
18055 +
18056 +struct task_struct *alloc_task_struct_node(int node)
18057 +{
18058 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18059 +}
18060 +
18061 +void free_task_struct(struct task_struct *task)
18062 +{
18063 + free_thread_xstate(task);
18064 + kmem_cache_free(task_struct_cachep, task);
18065 }
18066
18067 /*
18068 @@ -70,7 +87,7 @@ void exit_thread(void)
18069 unsigned long *bp = t->io_bitmap_ptr;
18070
18071 if (bp) {
18072 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18073 + struct tss_struct *tss = init_tss + get_cpu();
18074
18075 t->io_bitmap_ptr = NULL;
18076 clear_thread_flag(TIF_IO_BITMAP);
18077 @@ -106,7 +123,7 @@ void show_regs_common(void)
18078
18079 printk(KERN_CONT "\n");
18080 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18081 - current->pid, current->comm, print_tainted(),
18082 + task_pid_nr(current), current->comm, print_tainted(),
18083 init_utsname()->release,
18084 (int)strcspn(init_utsname()->version, " "),
18085 init_utsname()->version);
18086 @@ -120,6 +137,9 @@ void flush_thread(void)
18087 {
18088 struct task_struct *tsk = current;
18089
18090 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18091 + loadsegment(gs, 0);
18092 +#endif
18093 flush_ptrace_hw_breakpoint(tsk);
18094 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18095 /*
18096 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18097 regs.di = (unsigned long) arg;
18098
18099 #ifdef CONFIG_X86_32
18100 - regs.ds = __USER_DS;
18101 - regs.es = __USER_DS;
18102 + regs.ds = __KERNEL_DS;
18103 + regs.es = __KERNEL_DS;
18104 regs.fs = __KERNEL_PERCPU;
18105 - regs.gs = __KERNEL_STACK_CANARY;
18106 + savesegment(gs, regs.gs);
18107 #else
18108 regs.ss = __KERNEL_DS;
18109 #endif
18110 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18111
18112 return ret;
18113 }
18114 -void stop_this_cpu(void *dummy)
18115 +__noreturn void stop_this_cpu(void *dummy)
18116 {
18117 local_irq_disable();
18118 /*
18119 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18120 }
18121 early_param("idle", idle_setup);
18122
18123 -unsigned long arch_align_stack(unsigned long sp)
18124 +#ifdef CONFIG_PAX_RANDKSTACK
18125 +void pax_randomize_kstack(struct pt_regs *regs)
18126 {
18127 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18128 - sp -= get_random_int() % 8192;
18129 - return sp & ~0xf;
18130 -}
18131 + struct thread_struct *thread = &current->thread;
18132 + unsigned long time;
18133
18134 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18135 -{
18136 - unsigned long range_end = mm->brk + 0x02000000;
18137 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18138 -}
18139 + if (!randomize_va_space)
18140 + return;
18141 +
18142 + if (v8086_mode(regs))
18143 + return;
18144
18145 + rdtscl(time);
18146 +
18147 + /* P4 seems to return a 0 LSB, ignore it */
18148 +#ifdef CONFIG_MPENTIUM4
18149 + time &= 0x3EUL;
18150 + time <<= 2;
18151 +#elif defined(CONFIG_X86_64)
18152 + time &= 0xFUL;
18153 + time <<= 4;
18154 +#else
18155 + time &= 0x1FUL;
18156 + time <<= 3;
18157 +#endif
18158 +
18159 + thread->sp0 ^= time;
18160 + load_sp0(init_tss + smp_processor_id(), thread);
18161 +
18162 +#ifdef CONFIG_X86_64
18163 + percpu_write(kernel_stack, thread->sp0);
18164 +#endif
18165 +}
18166 +#endif
18167 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18168 index c08d1ff..6ae1c81 100644
18169 --- a/arch/x86/kernel/process_32.c
18170 +++ b/arch/x86/kernel/process_32.c
18171 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18172 unsigned long thread_saved_pc(struct task_struct *tsk)
18173 {
18174 return ((unsigned long *)tsk->thread.sp)[3];
18175 +//XXX return tsk->thread.eip;
18176 }
18177
18178 #ifndef CONFIG_SMP
18179 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18180 unsigned long sp;
18181 unsigned short ss, gs;
18182
18183 - if (user_mode_vm(regs)) {
18184 + if (user_mode(regs)) {
18185 sp = regs->sp;
18186 ss = regs->ss & 0xffff;
18187 - gs = get_user_gs(regs);
18188 } else {
18189 sp = kernel_stack_pointer(regs);
18190 savesegment(ss, ss);
18191 - savesegment(gs, gs);
18192 }
18193 + gs = get_user_gs(regs);
18194
18195 show_regs_common();
18196
18197 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18198 struct task_struct *tsk;
18199 int err;
18200
18201 - childregs = task_pt_regs(p);
18202 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18203 *childregs = *regs;
18204 childregs->ax = 0;
18205 childregs->sp = sp;
18206
18207 p->thread.sp = (unsigned long) childregs;
18208 p->thread.sp0 = (unsigned long) (childregs+1);
18209 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18210
18211 p->thread.ip = (unsigned long) ret_from_fork;
18212
18213 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18214 struct thread_struct *prev = &prev_p->thread,
18215 *next = &next_p->thread;
18216 int cpu = smp_processor_id();
18217 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18218 + struct tss_struct *tss = init_tss + cpu;
18219 fpu_switch_t fpu;
18220
18221 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18222 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18223 */
18224 lazy_save_gs(prev->gs);
18225
18226 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18227 + __set_fs(task_thread_info(next_p)->addr_limit);
18228 +#endif
18229 +
18230 /*
18231 * Load the per-thread Thread-Local Storage descriptor.
18232 */
18233 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18234 */
18235 arch_end_context_switch(next_p);
18236
18237 + percpu_write(current_task, next_p);
18238 + percpu_write(current_tinfo, &next_p->tinfo);
18239 +
18240 /*
18241 * Restore %gs if needed (which is common)
18242 */
18243 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18244
18245 switch_fpu_finish(next_p, fpu);
18246
18247 - percpu_write(current_task, next_p);
18248 -
18249 return prev_p;
18250 }
18251
18252 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18253 } while (count++ < 16);
18254 return 0;
18255 }
18256 -
18257 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18258 index cfa5c90..4facd28 100644
18259 --- a/arch/x86/kernel/process_64.c
18260 +++ b/arch/x86/kernel/process_64.c
18261 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18262 void exit_idle(void)
18263 {
18264 /* idle loop has pid 0 */
18265 - if (current->pid)
18266 + if (task_pid_nr(current))
18267 return;
18268 __exit_idle();
18269 }
18270 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18271 struct pt_regs *childregs;
18272 struct task_struct *me = current;
18273
18274 - childregs = ((struct pt_regs *)
18275 - (THREAD_SIZE + task_stack_page(p))) - 1;
18276 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18277 *childregs = *regs;
18278
18279 childregs->ax = 0;
18280 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18281 p->thread.sp = (unsigned long) childregs;
18282 p->thread.sp0 = (unsigned long) (childregs+1);
18283 p->thread.usersp = me->thread.usersp;
18284 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18285
18286 set_tsk_thread_flag(p, TIF_FORK);
18287
18288 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18289 struct thread_struct *prev = &prev_p->thread;
18290 struct thread_struct *next = &next_p->thread;
18291 int cpu = smp_processor_id();
18292 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18293 + struct tss_struct *tss = init_tss + cpu;
18294 unsigned fsindex, gsindex;
18295 fpu_switch_t fpu;
18296
18297 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18298 prev->usersp = percpu_read(old_rsp);
18299 percpu_write(old_rsp, next->usersp);
18300 percpu_write(current_task, next_p);
18301 + percpu_write(current_tinfo, &next_p->tinfo);
18302
18303 - percpu_write(kernel_stack,
18304 - (unsigned long)task_stack_page(next_p) +
18305 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18306 + percpu_write(kernel_stack, next->sp0);
18307
18308 /*
18309 * Now maybe reload the debug registers and handle I/O bitmaps
18310 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18311 if (!p || p == current || p->state == TASK_RUNNING)
18312 return 0;
18313 stack = (unsigned long)task_stack_page(p);
18314 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18315 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18316 return 0;
18317 fp = *(u64 *)(p->thread.sp);
18318 do {
18319 - if (fp < (unsigned long)stack ||
18320 - fp >= (unsigned long)stack+THREAD_SIZE)
18321 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18322 return 0;
18323 ip = *(u64 *)(fp+8);
18324 if (!in_sched_functions(ip))
18325 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18326 index 5026738..e1b5aa8 100644
18327 --- a/arch/x86/kernel/ptrace.c
18328 +++ b/arch/x86/kernel/ptrace.c
18329 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18330 static int ioperm_get(struct task_struct *target,
18331 const struct user_regset *regset,
18332 unsigned int pos, unsigned int count,
18333 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18334 +static int ioperm_get(struct task_struct *target,
18335 + const struct user_regset *regset,
18336 + unsigned int pos, unsigned int count,
18337 void *kbuf, void __user *ubuf)
18338 {
18339 if (!target->thread.io_bitmap_ptr)
18340 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
18341 unsigned long addr, unsigned long data)
18342 {
18343 int ret;
18344 - unsigned long __user *datap = (unsigned long __user *)data;
18345 + unsigned long __user *datap = (__force unsigned long __user *)data;
18346
18347 switch (request) {
18348 /* read the word at location addr in the USER area. */
18349 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
18350 if ((int) addr < 0)
18351 return -EIO;
18352 ret = do_get_thread_area(child, addr,
18353 - (struct user_desc __user *)data);
18354 + (__force struct user_desc __user *) data);
18355 break;
18356
18357 case PTRACE_SET_THREAD_AREA:
18358 if ((int) addr < 0)
18359 return -EIO;
18360 ret = do_set_thread_area(child, addr,
18361 - (struct user_desc __user *)data, 0);
18362 + (__force struct user_desc __user *) data, 0);
18363 break;
18364 #endif
18365
18366 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18367 memset(info, 0, sizeof(*info));
18368 info->si_signo = SIGTRAP;
18369 info->si_code = si_code;
18370 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18371 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18372 }
18373
18374 void user_single_step_siginfo(struct task_struct *tsk,
18375 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18376 index 42eb330..139955c 100644
18377 --- a/arch/x86/kernel/pvclock.c
18378 +++ b/arch/x86/kernel/pvclock.c
18379 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18380 return pv_tsc_khz;
18381 }
18382
18383 -static atomic64_t last_value = ATOMIC64_INIT(0);
18384 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18385
18386 void pvclock_resume(void)
18387 {
18388 - atomic64_set(&last_value, 0);
18389 + atomic64_set_unchecked(&last_value, 0);
18390 }
18391
18392 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18393 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18394 * updating at the same time, and one of them could be slightly behind,
18395 * making the assumption that last_value always go forward fail to hold.
18396 */
18397 - last = atomic64_read(&last_value);
18398 + last = atomic64_read_unchecked(&last_value);
18399 do {
18400 if (ret < last)
18401 return last;
18402 - last = atomic64_cmpxchg(&last_value, last, ret);
18403 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18404 } while (unlikely(last != ret));
18405
18406 return ret;
18407 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18408 index d840e69..98e9581 100644
18409 --- a/arch/x86/kernel/reboot.c
18410 +++ b/arch/x86/kernel/reboot.c
18411 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18412 EXPORT_SYMBOL(pm_power_off);
18413
18414 static const struct desc_ptr no_idt = {};
18415 -static int reboot_mode;
18416 +static unsigned short reboot_mode;
18417 enum reboot_type reboot_type = BOOT_ACPI;
18418 int reboot_force;
18419
18420 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18421 extern const unsigned char machine_real_restart_asm[];
18422 extern const u64 machine_real_restart_gdt[3];
18423
18424 -void machine_real_restart(unsigned int type)
18425 +__noreturn void machine_real_restart(unsigned int type)
18426 {
18427 void *restart_va;
18428 unsigned long restart_pa;
18429 - void (*restart_lowmem)(unsigned int);
18430 + void (* __noreturn restart_lowmem)(unsigned int);
18431 u64 *lowmem_gdt;
18432
18433 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18434 + struct desc_struct *gdt;
18435 +#endif
18436 +
18437 local_irq_disable();
18438
18439 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18440 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18441 boot)". This seems like a fairly standard thing that gets set by
18442 REBOOT.COM programs, and the previous reset routine did this
18443 too. */
18444 - *((unsigned short *)0x472) = reboot_mode;
18445 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18446
18447 /* Patch the GDT in the low memory trampoline */
18448 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18449
18450 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18451 restart_pa = virt_to_phys(restart_va);
18452 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18453 + restart_lowmem = (void *)restart_pa;
18454
18455 /* GDT[0]: GDT self-pointer */
18456 lowmem_gdt[0] =
18457 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18458 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18459
18460 /* Jump to the identity-mapped low memory code */
18461 +
18462 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18463 + gdt = get_cpu_gdt_table(smp_processor_id());
18464 + pax_open_kernel();
18465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18466 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18467 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18468 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18469 +#endif
18470 +#ifdef CONFIG_PAX_KERNEXEC
18471 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18472 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18473 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18474 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18475 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18476 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18477 +#endif
18478 + pax_close_kernel();
18479 +#endif
18480 +
18481 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18482 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18483 + unreachable();
18484 +#else
18485 restart_lowmem(type);
18486 +#endif
18487 +
18488 }
18489 #ifdef CONFIG_APM_MODULE
18490 EXPORT_SYMBOL(machine_real_restart);
18491 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18492 * try to force a triple fault and then cycle between hitting the keyboard
18493 * controller and doing that
18494 */
18495 -static void native_machine_emergency_restart(void)
18496 +__noreturn static void native_machine_emergency_restart(void)
18497 {
18498 int i;
18499 int attempt = 0;
18500 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18501 #endif
18502 }
18503
18504 -static void __machine_emergency_restart(int emergency)
18505 +static __noreturn void __machine_emergency_restart(int emergency)
18506 {
18507 reboot_emergency = emergency;
18508 machine_ops.emergency_restart();
18509 }
18510
18511 -static void native_machine_restart(char *__unused)
18512 +static __noreturn void native_machine_restart(char *__unused)
18513 {
18514 printk("machine restart\n");
18515
18516 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18517 __machine_emergency_restart(0);
18518 }
18519
18520 -static void native_machine_halt(void)
18521 +static __noreturn void native_machine_halt(void)
18522 {
18523 /* stop other cpus and apics */
18524 machine_shutdown();
18525 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18526 stop_this_cpu(NULL);
18527 }
18528
18529 -static void native_machine_power_off(void)
18530 +__noreturn static void native_machine_power_off(void)
18531 {
18532 if (pm_power_off) {
18533 if (!reboot_force)
18534 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18535 }
18536 /* a fallback in case there is no PM info available */
18537 tboot_shutdown(TB_SHUTDOWN_HALT);
18538 + unreachable();
18539 }
18540
18541 struct machine_ops machine_ops = {
18542 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18543 index 7a6f3b3..bed145d7 100644
18544 --- a/arch/x86/kernel/relocate_kernel_64.S
18545 +++ b/arch/x86/kernel/relocate_kernel_64.S
18546 @@ -11,6 +11,7 @@
18547 #include <asm/kexec.h>
18548 #include <asm/processor-flags.h>
18549 #include <asm/pgtable_types.h>
18550 +#include <asm/alternative-asm.h>
18551
18552 /*
18553 * Must be relocatable PIC code callable as a C function
18554 @@ -160,13 +161,14 @@ identity_mapped:
18555 xorq %rbp, %rbp
18556 xorq %r8, %r8
18557 xorq %r9, %r9
18558 - xorq %r10, %r9
18559 + xorq %r10, %r10
18560 xorq %r11, %r11
18561 xorq %r12, %r12
18562 xorq %r13, %r13
18563 xorq %r14, %r14
18564 xorq %r15, %r15
18565
18566 + pax_force_retaddr 0, 1
18567 ret
18568
18569 1:
18570 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18571 index d7d5099..28555d0 100644
18572 --- a/arch/x86/kernel/setup.c
18573 +++ b/arch/x86/kernel/setup.c
18574 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18575
18576 switch (data->type) {
18577 case SETUP_E820_EXT:
18578 - parse_e820_ext(data);
18579 + parse_e820_ext((struct setup_data __force_kernel *)data);
18580 break;
18581 case SETUP_DTB:
18582 add_dtb(pa_data);
18583 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18584 * area (640->1Mb) as ram even though it is not.
18585 * take them out.
18586 */
18587 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18588 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18589 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18590 }
18591
18592 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18593
18594 if (!boot_params.hdr.root_flags)
18595 root_mountflags &= ~MS_RDONLY;
18596 - init_mm.start_code = (unsigned long) _text;
18597 - init_mm.end_code = (unsigned long) _etext;
18598 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18599 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18600 init_mm.end_data = (unsigned long) _edata;
18601 init_mm.brk = _brk_end;
18602
18603 - code_resource.start = virt_to_phys(_text);
18604 - code_resource.end = virt_to_phys(_etext)-1;
18605 - data_resource.start = virt_to_phys(_etext);
18606 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18607 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18608 + data_resource.start = virt_to_phys(_sdata);
18609 data_resource.end = virt_to_phys(_edata)-1;
18610 bss_resource.start = virt_to_phys(&__bss_start);
18611 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18612 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18613 index 71f4727..217419b 100644
18614 --- a/arch/x86/kernel/setup_percpu.c
18615 +++ b/arch/x86/kernel/setup_percpu.c
18616 @@ -21,19 +21,17 @@
18617 #include <asm/cpu.h>
18618 #include <asm/stackprotector.h>
18619
18620 -DEFINE_PER_CPU(int, cpu_number);
18621 +#ifdef CONFIG_SMP
18622 +DEFINE_PER_CPU(unsigned int, cpu_number);
18623 EXPORT_PER_CPU_SYMBOL(cpu_number);
18624 +#endif
18625
18626 -#ifdef CONFIG_X86_64
18627 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18628 -#else
18629 -#define BOOT_PERCPU_OFFSET 0
18630 -#endif
18631
18632 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18633 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18634
18635 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18636 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18637 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18638 };
18639 EXPORT_SYMBOL(__per_cpu_offset);
18640 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18641 * Pointer to the allocated area on success, NULL on failure.
18642 */
18643 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18644 + unsigned long align) __size_overflow(2);
18645 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18646 unsigned long align)
18647 {
18648 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18649 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18650 /*
18651 * Helpers for first chunk memory allocation
18652 */
18653 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18654 +
18655 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18656 {
18657 return pcpu_alloc_bootmem(cpu, size, align);
18658 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18659 {
18660 #ifdef CONFIG_X86_32
18661 struct desc_struct gdt;
18662 + unsigned long base = per_cpu_offset(cpu);
18663
18664 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18665 - 0x2 | DESCTYPE_S, 0x8);
18666 - gdt.s = 1;
18667 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18668 + 0x83 | DESCTYPE_S, 0xC);
18669 write_gdt_entry(get_cpu_gdt_table(cpu),
18670 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18671 #endif
18672 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18673 /* alrighty, percpu areas up and running */
18674 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18675 for_each_possible_cpu(cpu) {
18676 +#ifdef CONFIG_CC_STACKPROTECTOR
18677 +#ifdef CONFIG_X86_32
18678 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18679 +#endif
18680 +#endif
18681 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18682 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18683 per_cpu(cpu_number, cpu) = cpu;
18684 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18685 */
18686 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18687 #endif
18688 +#ifdef CONFIG_CC_STACKPROTECTOR
18689 +#ifdef CONFIG_X86_32
18690 + if (!cpu)
18691 + per_cpu(stack_canary.canary, cpu) = canary;
18692 +#endif
18693 +#endif
18694 /*
18695 * Up to this point, the boot CPU has been using .init.data
18696 * area. Reload any changed state for the boot CPU.
18697 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18698 index 46a01bd..2e88e6d 100644
18699 --- a/arch/x86/kernel/signal.c
18700 +++ b/arch/x86/kernel/signal.c
18701 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18702 * Align the stack pointer according to the i386 ABI,
18703 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18704 */
18705 - sp = ((sp + 4) & -16ul) - 4;
18706 + sp = ((sp - 12) & -16ul) - 4;
18707 #else /* !CONFIG_X86_32 */
18708 sp = round_down(sp, 16) - 8;
18709 #endif
18710 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18711 * Return an always-bogus address instead so we will die with SIGSEGV.
18712 */
18713 if (onsigstack && !likely(on_sig_stack(sp)))
18714 - return (void __user *)-1L;
18715 + return (__force void __user *)-1L;
18716
18717 /* save i387 state */
18718 if (used_math() && save_i387_xstate(*fpstate) < 0)
18719 - return (void __user *)-1L;
18720 + return (__force void __user *)-1L;
18721
18722 return (void __user *)sp;
18723 }
18724 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18725 }
18726
18727 if (current->mm->context.vdso)
18728 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18729 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18730 else
18731 - restorer = &frame->retcode;
18732 + restorer = (void __user *)&frame->retcode;
18733 if (ka->sa.sa_flags & SA_RESTORER)
18734 restorer = ka->sa.sa_restorer;
18735
18736 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18737 * reasons and because gdb uses it as a signature to notice
18738 * signal handler stack frames.
18739 */
18740 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18741 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18742
18743 if (err)
18744 return -EFAULT;
18745 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18746 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18747
18748 /* Set up to return from userspace. */
18749 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18750 + if (current->mm->context.vdso)
18751 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18752 + else
18753 + restorer = (void __user *)&frame->retcode;
18754 if (ka->sa.sa_flags & SA_RESTORER)
18755 restorer = ka->sa.sa_restorer;
18756 put_user_ex(restorer, &frame->pretcode);
18757 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18758 * reasons and because gdb uses it as a signature to notice
18759 * signal handler stack frames.
18760 */
18761 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18762 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18763 } put_user_catch(err);
18764
18765 if (err)
18766 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18767 * X86_32: vm86 regs switched out by assembly code before reaching
18768 * here, so testing against kernel CS suffices.
18769 */
18770 - if (!user_mode(regs))
18771 + if (!user_mode_novm(regs))
18772 return;
18773
18774 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18775 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18776 index 66d250c..f1b10bd 100644
18777 --- a/arch/x86/kernel/smpboot.c
18778 +++ b/arch/x86/kernel/smpboot.c
18779 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18780 set_idle_for_cpu(cpu, c_idle.idle);
18781 do_rest:
18782 per_cpu(current_task, cpu) = c_idle.idle;
18783 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18784 #ifdef CONFIG_X86_32
18785 /* Stack for startup_32 can be just as for start_secondary onwards */
18786 irq_ctx_init(cpu);
18787 #else
18788 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18789 initial_gs = per_cpu_offset(cpu);
18790 - per_cpu(kernel_stack, cpu) =
18791 - (unsigned long)task_stack_page(c_idle.idle) -
18792 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18793 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18794 #endif
18795 +
18796 + pax_open_kernel();
18797 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18798 + pax_close_kernel();
18799 +
18800 initial_code = (unsigned long)start_secondary;
18801 stack_start = c_idle.idle->thread.sp;
18802
18803 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18804
18805 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18806
18807 +#ifdef CONFIG_PAX_PER_CPU_PGD
18808 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18809 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18810 + KERNEL_PGD_PTRS);
18811 +#endif
18812 +
18813 err = do_boot_cpu(apicid, cpu);
18814 if (err) {
18815 pr_debug("do_boot_cpu failed %d\n", err);
18816 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18817 index c346d11..d43b163 100644
18818 --- a/arch/x86/kernel/step.c
18819 +++ b/arch/x86/kernel/step.c
18820 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18821 struct desc_struct *desc;
18822 unsigned long base;
18823
18824 - seg &= ~7UL;
18825 + seg >>= 3;
18826
18827 mutex_lock(&child->mm->context.lock);
18828 - if (unlikely((seg >> 3) >= child->mm->context.size))
18829 + if (unlikely(seg >= child->mm->context.size))
18830 addr = -1L; /* bogus selector, access would fault */
18831 else {
18832 desc = child->mm->context.ldt + seg;
18833 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18834 addr += base;
18835 }
18836 mutex_unlock(&child->mm->context.lock);
18837 - }
18838 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18839 + addr = ktla_ktva(addr);
18840
18841 return addr;
18842 }
18843 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18844 unsigned char opcode[15];
18845 unsigned long addr = convert_ip_to_linear(child, regs);
18846
18847 + if (addr == -EINVAL)
18848 + return 0;
18849 +
18850 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18851 for (i = 0; i < copied; i++) {
18852 switch (opcode[i]) {
18853 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18854 index 0b0cb5f..db6b9ed 100644
18855 --- a/arch/x86/kernel/sys_i386_32.c
18856 +++ b/arch/x86/kernel/sys_i386_32.c
18857 @@ -24,17 +24,224 @@
18858
18859 #include <asm/syscalls.h>
18860
18861 -/*
18862 - * Do a system call from kernel instead of calling sys_execve so we
18863 - * end up with proper pt_regs.
18864 - */
18865 -int kernel_execve(const char *filename,
18866 - const char *const argv[],
18867 - const char *const envp[])
18868 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18869 {
18870 - long __res;
18871 - asm volatile ("int $0x80"
18872 - : "=a" (__res)
18873 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18874 - return __res;
18875 + unsigned long pax_task_size = TASK_SIZE;
18876 +
18877 +#ifdef CONFIG_PAX_SEGMEXEC
18878 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18879 + pax_task_size = SEGMEXEC_TASK_SIZE;
18880 +#endif
18881 +
18882 + if (len > pax_task_size || addr > pax_task_size - len)
18883 + return -EINVAL;
18884 +
18885 + return 0;
18886 +}
18887 +
18888 +unsigned long
18889 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18890 + unsigned long len, unsigned long pgoff, unsigned long flags)
18891 +{
18892 + struct mm_struct *mm = current->mm;
18893 + struct vm_area_struct *vma;
18894 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18895 +
18896 +#ifdef CONFIG_PAX_SEGMEXEC
18897 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18898 + pax_task_size = SEGMEXEC_TASK_SIZE;
18899 +#endif
18900 +
18901 + pax_task_size -= PAGE_SIZE;
18902 +
18903 + if (len > pax_task_size)
18904 + return -ENOMEM;
18905 +
18906 + if (flags & MAP_FIXED)
18907 + return addr;
18908 +
18909 +#ifdef CONFIG_PAX_RANDMMAP
18910 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18911 +#endif
18912 +
18913 + if (addr) {
18914 + addr = PAGE_ALIGN(addr);
18915 + if (pax_task_size - len >= addr) {
18916 + vma = find_vma(mm, addr);
18917 + if (check_heap_stack_gap(vma, addr, len))
18918 + return addr;
18919 + }
18920 + }
18921 + if (len > mm->cached_hole_size) {
18922 + start_addr = addr = mm->free_area_cache;
18923 + } else {
18924 + start_addr = addr = mm->mmap_base;
18925 + mm->cached_hole_size = 0;
18926 + }
18927 +
18928 +#ifdef CONFIG_PAX_PAGEEXEC
18929 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18930 + start_addr = 0x00110000UL;
18931 +
18932 +#ifdef CONFIG_PAX_RANDMMAP
18933 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18934 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18935 +#endif
18936 +
18937 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18938 + start_addr = addr = mm->mmap_base;
18939 + else
18940 + addr = start_addr;
18941 + }
18942 +#endif
18943 +
18944 +full_search:
18945 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18946 + /* At this point: (!vma || addr < vma->vm_end). */
18947 + if (pax_task_size - len < addr) {
18948 + /*
18949 + * Start a new search - just in case we missed
18950 + * some holes.
18951 + */
18952 + if (start_addr != mm->mmap_base) {
18953 + start_addr = addr = mm->mmap_base;
18954 + mm->cached_hole_size = 0;
18955 + goto full_search;
18956 + }
18957 + return -ENOMEM;
18958 + }
18959 + if (check_heap_stack_gap(vma, addr, len))
18960 + break;
18961 + if (addr + mm->cached_hole_size < vma->vm_start)
18962 + mm->cached_hole_size = vma->vm_start - addr;
18963 + addr = vma->vm_end;
18964 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18965 + start_addr = addr = mm->mmap_base;
18966 + mm->cached_hole_size = 0;
18967 + goto full_search;
18968 + }
18969 + }
18970 +
18971 + /*
18972 + * Remember the place where we stopped the search:
18973 + */
18974 + mm->free_area_cache = addr + len;
18975 + return addr;
18976 +}
18977 +
18978 +unsigned long
18979 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18980 + const unsigned long len, const unsigned long pgoff,
18981 + const unsigned long flags)
18982 +{
18983 + struct vm_area_struct *vma;
18984 + struct mm_struct *mm = current->mm;
18985 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18986 +
18987 +#ifdef CONFIG_PAX_SEGMEXEC
18988 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18989 + pax_task_size = SEGMEXEC_TASK_SIZE;
18990 +#endif
18991 +
18992 + pax_task_size -= PAGE_SIZE;
18993 +
18994 + /* requested length too big for entire address space */
18995 + if (len > pax_task_size)
18996 + return -ENOMEM;
18997 +
18998 + if (flags & MAP_FIXED)
18999 + return addr;
19000 +
19001 +#ifdef CONFIG_PAX_PAGEEXEC
19002 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19003 + goto bottomup;
19004 +#endif
19005 +
19006 +#ifdef CONFIG_PAX_RANDMMAP
19007 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19008 +#endif
19009 +
19010 + /* requesting a specific address */
19011 + if (addr) {
19012 + addr = PAGE_ALIGN(addr);
19013 + if (pax_task_size - len >= addr) {
19014 + vma = find_vma(mm, addr);
19015 + if (check_heap_stack_gap(vma, addr, len))
19016 + return addr;
19017 + }
19018 + }
19019 +
19020 + /* check if free_area_cache is useful for us */
19021 + if (len <= mm->cached_hole_size) {
19022 + mm->cached_hole_size = 0;
19023 + mm->free_area_cache = mm->mmap_base;
19024 + }
19025 +
19026 + /* either no address requested or can't fit in requested address hole */
19027 + addr = mm->free_area_cache;
19028 +
19029 + /* make sure it can fit in the remaining address space */
19030 + if (addr > len) {
19031 + vma = find_vma(mm, addr-len);
19032 + if (check_heap_stack_gap(vma, addr - len, len))
19033 + /* remember the address as a hint for next time */
19034 + return (mm->free_area_cache = addr-len);
19035 + }
19036 +
19037 + if (mm->mmap_base < len)
19038 + goto bottomup;
19039 +
19040 + addr = mm->mmap_base-len;
19041 +
19042 + do {
19043 + /*
19044 + * Lookup failure means no vma is above this address,
19045 + * else if new region fits below vma->vm_start,
19046 + * return with success:
19047 + */
19048 + vma = find_vma(mm, addr);
19049 + if (check_heap_stack_gap(vma, addr, len))
19050 + /* remember the address as a hint for next time */
19051 + return (mm->free_area_cache = addr);
19052 +
19053 + /* remember the largest hole we saw so far */
19054 + if (addr + mm->cached_hole_size < vma->vm_start)
19055 + mm->cached_hole_size = vma->vm_start - addr;
19056 +
19057 + /* try just below the current vma->vm_start */
19058 + addr = skip_heap_stack_gap(vma, len);
19059 + } while (!IS_ERR_VALUE(addr));
19060 +
19061 +bottomup:
19062 + /*
19063 + * A failed mmap() very likely causes application failure,
19064 + * so fall back to the bottom-up function here. This scenario
19065 + * can happen with large stack limits and large mmap()
19066 + * allocations.
19067 + */
19068 +
19069 +#ifdef CONFIG_PAX_SEGMEXEC
19070 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19071 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19072 + else
19073 +#endif
19074 +
19075 + mm->mmap_base = TASK_UNMAPPED_BASE;
19076 +
19077 +#ifdef CONFIG_PAX_RANDMMAP
19078 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19079 + mm->mmap_base += mm->delta_mmap;
19080 +#endif
19081 +
19082 + mm->free_area_cache = mm->mmap_base;
19083 + mm->cached_hole_size = ~0UL;
19084 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19085 + /*
19086 + * Restore the topdown base:
19087 + */
19088 + mm->mmap_base = base;
19089 + mm->free_area_cache = base;
19090 + mm->cached_hole_size = ~0UL;
19091 +
19092 + return addr;
19093 }
19094 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19095 index 0514890..3dbebce 100644
19096 --- a/arch/x86/kernel/sys_x86_64.c
19097 +++ b/arch/x86/kernel/sys_x86_64.c
19098 @@ -95,8 +95,8 @@ out:
19099 return error;
19100 }
19101
19102 -static void find_start_end(unsigned long flags, unsigned long *begin,
19103 - unsigned long *end)
19104 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19105 + unsigned long *begin, unsigned long *end)
19106 {
19107 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19108 unsigned long new_begin;
19109 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19110 *begin = new_begin;
19111 }
19112 } else {
19113 - *begin = TASK_UNMAPPED_BASE;
19114 + *begin = mm->mmap_base;
19115 *end = TASK_SIZE;
19116 }
19117 }
19118 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19119 if (flags & MAP_FIXED)
19120 return addr;
19121
19122 - find_start_end(flags, &begin, &end);
19123 + find_start_end(mm, flags, &begin, &end);
19124
19125 if (len > end)
19126 return -ENOMEM;
19127
19128 +#ifdef CONFIG_PAX_RANDMMAP
19129 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19130 +#endif
19131 +
19132 if (addr) {
19133 addr = PAGE_ALIGN(addr);
19134 vma = find_vma(mm, addr);
19135 - if (end - len >= addr &&
19136 - (!vma || addr + len <= vma->vm_start))
19137 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19138 return addr;
19139 }
19140 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19141 @@ -172,7 +175,7 @@ full_search:
19142 }
19143 return -ENOMEM;
19144 }
19145 - if (!vma || addr + len <= vma->vm_start) {
19146 + if (check_heap_stack_gap(vma, addr, len)) {
19147 /*
19148 * Remember the place where we stopped the search:
19149 */
19150 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19151 {
19152 struct vm_area_struct *vma;
19153 struct mm_struct *mm = current->mm;
19154 - unsigned long addr = addr0;
19155 + unsigned long base = mm->mmap_base, addr = addr0;
19156
19157 /* requested length too big for entire address space */
19158 if (len > TASK_SIZE)
19159 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19160 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19161 goto bottomup;
19162
19163 +#ifdef CONFIG_PAX_RANDMMAP
19164 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19165 +#endif
19166 +
19167 /* requesting a specific address */
19168 if (addr) {
19169 addr = PAGE_ALIGN(addr);
19170 - vma = find_vma(mm, addr);
19171 - if (TASK_SIZE - len >= addr &&
19172 - (!vma || addr + len <= vma->vm_start))
19173 - return addr;
19174 + if (TASK_SIZE - len >= addr) {
19175 + vma = find_vma(mm, addr);
19176 + if (check_heap_stack_gap(vma, addr, len))
19177 + return addr;
19178 + }
19179 }
19180
19181 /* check if free_area_cache is useful for us */
19182 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19183 ALIGN_TOPDOWN);
19184
19185 vma = find_vma(mm, tmp_addr);
19186 - if (!vma || tmp_addr + len <= vma->vm_start)
19187 + if (check_heap_stack_gap(vma, tmp_addr, len))
19188 /* remember the address as a hint for next time */
19189 return mm->free_area_cache = tmp_addr;
19190 }
19191 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19192 * return with success:
19193 */
19194 vma = find_vma(mm, addr);
19195 - if (!vma || addr+len <= vma->vm_start)
19196 + if (check_heap_stack_gap(vma, addr, len))
19197 /* remember the address as a hint for next time */
19198 return mm->free_area_cache = addr;
19199
19200 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19201 mm->cached_hole_size = vma->vm_start - addr;
19202
19203 /* try just below the current vma->vm_start */
19204 - addr = vma->vm_start-len;
19205 - } while (len < vma->vm_start);
19206 + addr = skip_heap_stack_gap(vma, len);
19207 + } while (!IS_ERR_VALUE(addr));
19208
19209 bottomup:
19210 /*
19211 @@ -270,13 +278,21 @@ bottomup:
19212 * can happen with large stack limits and large mmap()
19213 * allocations.
19214 */
19215 + mm->mmap_base = TASK_UNMAPPED_BASE;
19216 +
19217 +#ifdef CONFIG_PAX_RANDMMAP
19218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19219 + mm->mmap_base += mm->delta_mmap;
19220 +#endif
19221 +
19222 + mm->free_area_cache = mm->mmap_base;
19223 mm->cached_hole_size = ~0UL;
19224 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19225 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19226 /*
19227 * Restore the topdown base:
19228 */
19229 - mm->free_area_cache = mm->mmap_base;
19230 + mm->mmap_base = base;
19231 + mm->free_area_cache = base;
19232 mm->cached_hole_size = ~0UL;
19233
19234 return addr;
19235 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19236 index e2410e2..4fe3fbc 100644
19237 --- a/arch/x86/kernel/tboot.c
19238 +++ b/arch/x86/kernel/tboot.c
19239 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19240
19241 void tboot_shutdown(u32 shutdown_type)
19242 {
19243 - void (*shutdown)(void);
19244 + void (* __noreturn shutdown)(void);
19245
19246 if (!tboot_enabled())
19247 return;
19248 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19249
19250 switch_to_tboot_pt();
19251
19252 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19253 + shutdown = (void *)tboot->shutdown_entry;
19254 shutdown();
19255
19256 /* should not reach here */
19257 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19258 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19259 }
19260
19261 -static atomic_t ap_wfs_count;
19262 +static atomic_unchecked_t ap_wfs_count;
19263
19264 static int tboot_wait_for_aps(int num_aps)
19265 {
19266 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19267 {
19268 switch (action) {
19269 case CPU_DYING:
19270 - atomic_inc(&ap_wfs_count);
19271 + atomic_inc_unchecked(&ap_wfs_count);
19272 if (num_online_cpus() == 1)
19273 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19274 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19275 return NOTIFY_BAD;
19276 break;
19277 }
19278 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19279
19280 tboot_create_trampoline();
19281
19282 - atomic_set(&ap_wfs_count, 0);
19283 + atomic_set_unchecked(&ap_wfs_count, 0);
19284 register_hotcpu_notifier(&tboot_cpu_notifier);
19285 return 0;
19286 }
19287 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19288 index dd5fbf4..b7f2232 100644
19289 --- a/arch/x86/kernel/time.c
19290 +++ b/arch/x86/kernel/time.c
19291 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19292 {
19293 unsigned long pc = instruction_pointer(regs);
19294
19295 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19296 + if (!user_mode(regs) && in_lock_functions(pc)) {
19297 #ifdef CONFIG_FRAME_POINTER
19298 - return *(unsigned long *)(regs->bp + sizeof(long));
19299 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19300 #else
19301 unsigned long *sp =
19302 (unsigned long *)kernel_stack_pointer(regs);
19303 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19304 * or above a saved flags. Eflags has bits 22-31 zero,
19305 * kernel addresses don't.
19306 */
19307 +
19308 +#ifdef CONFIG_PAX_KERNEXEC
19309 + return ktla_ktva(sp[0]);
19310 +#else
19311 if (sp[0] >> 22)
19312 return sp[0];
19313 if (sp[1] >> 22)
19314 return sp[1];
19315 #endif
19316 +
19317 +#endif
19318 }
19319 return pc;
19320 }
19321 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19322 index bcfec2d..8f88b4a 100644
19323 --- a/arch/x86/kernel/tls.c
19324 +++ b/arch/x86/kernel/tls.c
19325 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19326 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19327 return -EINVAL;
19328
19329 +#ifdef CONFIG_PAX_SEGMEXEC
19330 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19331 + return -EINVAL;
19332 +#endif
19333 +
19334 set_tls_desc(p, idx, &info, 1);
19335
19336 return 0;
19337 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19338 index 2f083a2..7d3fecc 100644
19339 --- a/arch/x86/kernel/tls.h
19340 +++ b/arch/x86/kernel/tls.h
19341 @@ -16,6 +16,6 @@
19342
19343 extern user_regset_active_fn regset_tls_active;
19344 extern user_regset_get_fn regset_tls_get;
19345 -extern user_regset_set_fn regset_tls_set;
19346 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19347
19348 #endif /* _ARCH_X86_KERNEL_TLS_H */
19349 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19350 index 451c0a7..e57f551 100644
19351 --- a/arch/x86/kernel/trampoline_32.S
19352 +++ b/arch/x86/kernel/trampoline_32.S
19353 @@ -32,6 +32,12 @@
19354 #include <asm/segment.h>
19355 #include <asm/page_types.h>
19356
19357 +#ifdef CONFIG_PAX_KERNEXEC
19358 +#define ta(X) (X)
19359 +#else
19360 +#define ta(X) ((X) - __PAGE_OFFSET)
19361 +#endif
19362 +
19363 #ifdef CONFIG_SMP
19364
19365 .section ".x86_trampoline","a"
19366 @@ -62,7 +68,7 @@ r_base = .
19367 inc %ax # protected mode (PE) bit
19368 lmsw %ax # into protected mode
19369 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19370 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19371 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19372
19373 # These need to be in the same 64K segment as the above;
19374 # hence we don't use the boot_gdt_descr defined in head.S
19375 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19376 index 09ff517..df19fbff 100644
19377 --- a/arch/x86/kernel/trampoline_64.S
19378 +++ b/arch/x86/kernel/trampoline_64.S
19379 @@ -90,7 +90,7 @@ startup_32:
19380 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19381 movl %eax, %ds
19382
19383 - movl $X86_CR4_PAE, %eax
19384 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19385 movl %eax, %cr4 # Enable PAE mode
19386
19387 # Setup trampoline 4 level pagetables
19388 @@ -138,7 +138,7 @@ tidt:
19389 # so the kernel can live anywhere
19390 .balign 4
19391 tgdt:
19392 - .short tgdt_end - tgdt # gdt limit
19393 + .short tgdt_end - tgdt - 1 # gdt limit
19394 .long tgdt - r_base
19395 .short 0
19396 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19397 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19398 index 4bbe04d..41d0943 100644
19399 --- a/arch/x86/kernel/traps.c
19400 +++ b/arch/x86/kernel/traps.c
19401 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19402
19403 /* Do we ignore FPU interrupts ? */
19404 char ignore_fpu_irq;
19405 -
19406 -/*
19407 - * The IDT has to be page-aligned to simplify the Pentium
19408 - * F0 0F bug workaround.
19409 - */
19410 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19411 #endif
19412
19413 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19414 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19415 }
19416
19417 static void __kprobes
19418 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19419 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19420 long error_code, siginfo_t *info)
19421 {
19422 struct task_struct *tsk = current;
19423
19424 #ifdef CONFIG_X86_32
19425 - if (regs->flags & X86_VM_MASK) {
19426 + if (v8086_mode(regs)) {
19427 /*
19428 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19429 * On nmi (interrupt 2), do_trap should not be called.
19430 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19431 }
19432 #endif
19433
19434 - if (!user_mode(regs))
19435 + if (!user_mode_novm(regs))
19436 goto kernel_trap;
19437
19438 #ifdef CONFIG_X86_32
19439 @@ -148,7 +142,7 @@ trap_signal:
19440 printk_ratelimit()) {
19441 printk(KERN_INFO
19442 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19443 - tsk->comm, tsk->pid, str,
19444 + tsk->comm, task_pid_nr(tsk), str,
19445 regs->ip, regs->sp, error_code);
19446 print_vma_addr(" in ", regs->ip);
19447 printk("\n");
19448 @@ -165,8 +159,20 @@ kernel_trap:
19449 if (!fixup_exception(regs)) {
19450 tsk->thread.error_code = error_code;
19451 tsk->thread.trap_no = trapnr;
19452 +
19453 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19454 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19455 + str = "PAX: suspicious stack segment fault";
19456 +#endif
19457 +
19458 die(str, regs, error_code);
19459 }
19460 +
19461 +#ifdef CONFIG_PAX_REFCOUNT
19462 + if (trapnr == 4)
19463 + pax_report_refcount_overflow(regs);
19464 +#endif
19465 +
19466 return;
19467
19468 #ifdef CONFIG_X86_32
19469 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19470 conditional_sti(regs);
19471
19472 #ifdef CONFIG_X86_32
19473 - if (regs->flags & X86_VM_MASK)
19474 + if (v8086_mode(regs))
19475 goto gp_in_vm86;
19476 #endif
19477
19478 tsk = current;
19479 - if (!user_mode(regs))
19480 + if (!user_mode_novm(regs))
19481 goto gp_in_kernel;
19482
19483 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19484 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19485 + struct mm_struct *mm = tsk->mm;
19486 + unsigned long limit;
19487 +
19488 + down_write(&mm->mmap_sem);
19489 + limit = mm->context.user_cs_limit;
19490 + if (limit < TASK_SIZE) {
19491 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19492 + up_write(&mm->mmap_sem);
19493 + return;
19494 + }
19495 + up_write(&mm->mmap_sem);
19496 + }
19497 +#endif
19498 +
19499 tsk->thread.error_code = error_code;
19500 tsk->thread.trap_no = 13;
19501
19502 @@ -295,6 +317,13 @@ gp_in_kernel:
19503 if (notify_die(DIE_GPF, "general protection fault", regs,
19504 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19505 return;
19506 +
19507 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19508 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19509 + die("PAX: suspicious general protection fault", regs, error_code);
19510 + else
19511 +#endif
19512 +
19513 die("general protection fault", regs, error_code);
19514 }
19515
19516 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19517 /* It's safe to allow irq's after DR6 has been saved */
19518 preempt_conditional_sti(regs);
19519
19520 - if (regs->flags & X86_VM_MASK) {
19521 + if (v8086_mode(regs)) {
19522 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19523 error_code, 1);
19524 preempt_conditional_cli(regs);
19525 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19526 * We already checked v86 mode above, so we can check for kernel mode
19527 * by just checking the CPL of CS.
19528 */
19529 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19530 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19531 tsk->thread.debugreg6 &= ~DR_STEP;
19532 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19533 regs->flags &= ~X86_EFLAGS_TF;
19534 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19535 return;
19536 conditional_sti(regs);
19537
19538 - if (!user_mode_vm(regs))
19539 + if (!user_mode(regs))
19540 {
19541 if (!fixup_exception(regs)) {
19542 task->thread.error_code = error_code;
19543 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19544 index b9242ba..50c5edd 100644
19545 --- a/arch/x86/kernel/verify_cpu.S
19546 +++ b/arch/x86/kernel/verify_cpu.S
19547 @@ -20,6 +20,7 @@
19548 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19549 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19550 * arch/x86/kernel/head_32.S: processor startup
19551 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19552 *
19553 * verify_cpu, returns the status of longmode and SSE in register %eax.
19554 * 0: Success 1: Failure
19555 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19556 index 328cb37..f37fee1 100644
19557 --- a/arch/x86/kernel/vm86_32.c
19558 +++ b/arch/x86/kernel/vm86_32.c
19559 @@ -41,6 +41,7 @@
19560 #include <linux/ptrace.h>
19561 #include <linux/audit.h>
19562 #include <linux/stddef.h>
19563 +#include <linux/grsecurity.h>
19564
19565 #include <asm/uaccess.h>
19566 #include <asm/io.h>
19567 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
19568 /* convert vm86_regs to kernel_vm86_regs */
19569 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19570 const struct vm86_regs __user *user,
19571 + unsigned extra) __size_overflow(3);
19572 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19573 + const struct vm86_regs __user *user,
19574 unsigned extra)
19575 {
19576 int ret = 0;
19577 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19578 do_exit(SIGSEGV);
19579 }
19580
19581 - tss = &per_cpu(init_tss, get_cpu());
19582 + tss = init_tss + get_cpu();
19583 current->thread.sp0 = current->thread.saved_sp0;
19584 current->thread.sysenter_cs = __KERNEL_CS;
19585 load_sp0(tss, &current->thread);
19586 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19587 struct task_struct *tsk;
19588 int tmp, ret = -EPERM;
19589
19590 +#ifdef CONFIG_GRKERNSEC_VM86
19591 + if (!capable(CAP_SYS_RAWIO)) {
19592 + gr_handle_vm86();
19593 + goto out;
19594 + }
19595 +#endif
19596 +
19597 tsk = current;
19598 if (tsk->thread.saved_sp0)
19599 goto out;
19600 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19601 int tmp, ret;
19602 struct vm86plus_struct __user *v86;
19603
19604 +#ifdef CONFIG_GRKERNSEC_VM86
19605 + if (!capable(CAP_SYS_RAWIO)) {
19606 + gr_handle_vm86();
19607 + ret = -EPERM;
19608 + goto out;
19609 + }
19610 +#endif
19611 +
19612 tsk = current;
19613 switch (cmd) {
19614 case VM86_REQUEST_IRQ:
19615 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19616 tsk->thread.saved_fs = info->regs32->fs;
19617 tsk->thread.saved_gs = get_user_gs(info->regs32);
19618
19619 - tss = &per_cpu(init_tss, get_cpu());
19620 + tss = init_tss + get_cpu();
19621 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19622 if (cpu_has_sep)
19623 tsk->thread.sysenter_cs = 0;
19624 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19625 goto cannot_handle;
19626 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19627 goto cannot_handle;
19628 - intr_ptr = (unsigned long __user *) (i << 2);
19629 + intr_ptr = (__force unsigned long __user *) (i << 2);
19630 if (get_user(segoffs, intr_ptr))
19631 goto cannot_handle;
19632 if ((segoffs >> 16) == BIOSSEG)
19633 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19634 index 0f703f1..9e15f64 100644
19635 --- a/arch/x86/kernel/vmlinux.lds.S
19636 +++ b/arch/x86/kernel/vmlinux.lds.S
19637 @@ -26,6 +26,13 @@
19638 #include <asm/page_types.h>
19639 #include <asm/cache.h>
19640 #include <asm/boot.h>
19641 +#include <asm/segment.h>
19642 +
19643 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19644 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19645 +#else
19646 +#define __KERNEL_TEXT_OFFSET 0
19647 +#endif
19648
19649 #undef i386 /* in case the preprocessor is a 32bit one */
19650
19651 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19652
19653 PHDRS {
19654 text PT_LOAD FLAGS(5); /* R_E */
19655 +#ifdef CONFIG_X86_32
19656 + module PT_LOAD FLAGS(5); /* R_E */
19657 +#endif
19658 +#ifdef CONFIG_XEN
19659 + rodata PT_LOAD FLAGS(5); /* R_E */
19660 +#else
19661 + rodata PT_LOAD FLAGS(4); /* R__ */
19662 +#endif
19663 data PT_LOAD FLAGS(6); /* RW_ */
19664 -#ifdef CONFIG_X86_64
19665 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19666 #ifdef CONFIG_SMP
19667 percpu PT_LOAD FLAGS(6); /* RW_ */
19668 #endif
19669 + text.init PT_LOAD FLAGS(5); /* R_E */
19670 + text.exit PT_LOAD FLAGS(5); /* R_E */
19671 init PT_LOAD FLAGS(7); /* RWE */
19672 -#endif
19673 note PT_NOTE FLAGS(0); /* ___ */
19674 }
19675
19676 SECTIONS
19677 {
19678 #ifdef CONFIG_X86_32
19679 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19680 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19681 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19682 #else
19683 - . = __START_KERNEL;
19684 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19685 + . = __START_KERNEL;
19686 #endif
19687
19688 /* Text and read-only data */
19689 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19690 - _text = .;
19691 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19692 /* bootstrapping code */
19693 +#ifdef CONFIG_X86_32
19694 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19695 +#else
19696 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19697 +#endif
19698 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19699 + _text = .;
19700 HEAD_TEXT
19701 #ifdef CONFIG_X86_32
19702 . = ALIGN(PAGE_SIZE);
19703 @@ -108,13 +128,47 @@ SECTIONS
19704 IRQENTRY_TEXT
19705 *(.fixup)
19706 *(.gnu.warning)
19707 - /* End of text section */
19708 - _etext = .;
19709 } :text = 0x9090
19710
19711 - NOTES :text :note
19712 + . += __KERNEL_TEXT_OFFSET;
19713
19714 - EXCEPTION_TABLE(16) :text = 0x9090
19715 +#ifdef CONFIG_X86_32
19716 + . = ALIGN(PAGE_SIZE);
19717 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19718 +
19719 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19720 + MODULES_EXEC_VADDR = .;
19721 + BYTE(0)
19722 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19723 + . = ALIGN(HPAGE_SIZE);
19724 + MODULES_EXEC_END = . - 1;
19725 +#endif
19726 +
19727 + } :module
19728 +#endif
19729 +
19730 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19731 + /* End of text section */
19732 + _etext = . - __KERNEL_TEXT_OFFSET;
19733 + }
19734 +
19735 +#ifdef CONFIG_X86_32
19736 + . = ALIGN(PAGE_SIZE);
19737 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19738 + *(.idt)
19739 + . = ALIGN(PAGE_SIZE);
19740 + *(.empty_zero_page)
19741 + *(.initial_pg_fixmap)
19742 + *(.initial_pg_pmd)
19743 + *(.initial_page_table)
19744 + *(.swapper_pg_dir)
19745 + } :rodata
19746 +#endif
19747 +
19748 + . = ALIGN(PAGE_SIZE);
19749 + NOTES :rodata :note
19750 +
19751 + EXCEPTION_TABLE(16) :rodata
19752
19753 #if defined(CONFIG_DEBUG_RODATA)
19754 /* .text should occupy whole number of pages */
19755 @@ -126,16 +180,20 @@ SECTIONS
19756
19757 /* Data */
19758 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19759 +
19760 +#ifdef CONFIG_PAX_KERNEXEC
19761 + . = ALIGN(HPAGE_SIZE);
19762 +#else
19763 + . = ALIGN(PAGE_SIZE);
19764 +#endif
19765 +
19766 /* Start of data section */
19767 _sdata = .;
19768
19769 /* init_task */
19770 INIT_TASK_DATA(THREAD_SIZE)
19771
19772 -#ifdef CONFIG_X86_32
19773 - /* 32 bit has nosave before _edata */
19774 NOSAVE_DATA
19775 -#endif
19776
19777 PAGE_ALIGNED_DATA(PAGE_SIZE)
19778
19779 @@ -176,12 +234,19 @@ SECTIONS
19780 #endif /* CONFIG_X86_64 */
19781
19782 /* Init code and data - will be freed after init */
19783 - . = ALIGN(PAGE_SIZE);
19784 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19785 + BYTE(0)
19786 +
19787 +#ifdef CONFIG_PAX_KERNEXEC
19788 + . = ALIGN(HPAGE_SIZE);
19789 +#else
19790 + . = ALIGN(PAGE_SIZE);
19791 +#endif
19792 +
19793 __init_begin = .; /* paired with __init_end */
19794 - }
19795 + } :init.begin
19796
19797 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19798 +#ifdef CONFIG_SMP
19799 /*
19800 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19801 * output PHDR, so the next output section - .init.text - should
19802 @@ -190,12 +255,27 @@ SECTIONS
19803 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19804 #endif
19805
19806 - INIT_TEXT_SECTION(PAGE_SIZE)
19807 -#ifdef CONFIG_X86_64
19808 - :init
19809 -#endif
19810 + . = ALIGN(PAGE_SIZE);
19811 + init_begin = .;
19812 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19813 + VMLINUX_SYMBOL(_sinittext) = .;
19814 + INIT_TEXT
19815 + VMLINUX_SYMBOL(_einittext) = .;
19816 + . = ALIGN(PAGE_SIZE);
19817 + } :text.init
19818
19819 - INIT_DATA_SECTION(16)
19820 + /*
19821 + * .exit.text is discard at runtime, not link time, to deal with
19822 + * references from .altinstructions and .eh_frame
19823 + */
19824 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19825 + EXIT_TEXT
19826 + . = ALIGN(16);
19827 + } :text.exit
19828 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19829 +
19830 + . = ALIGN(PAGE_SIZE);
19831 + INIT_DATA_SECTION(16) :init
19832
19833 /*
19834 * Code and data for a variety of lowlevel trampolines, to be
19835 @@ -269,19 +349,12 @@ SECTIONS
19836 }
19837
19838 . = ALIGN(8);
19839 - /*
19840 - * .exit.text is discard at runtime, not link time, to deal with
19841 - * references from .altinstructions and .eh_frame
19842 - */
19843 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19844 - EXIT_TEXT
19845 - }
19846
19847 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19848 EXIT_DATA
19849 }
19850
19851 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19852 +#ifndef CONFIG_SMP
19853 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19854 #endif
19855
19856 @@ -300,16 +373,10 @@ SECTIONS
19857 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19858 __smp_locks = .;
19859 *(.smp_locks)
19860 - . = ALIGN(PAGE_SIZE);
19861 __smp_locks_end = .;
19862 + . = ALIGN(PAGE_SIZE);
19863 }
19864
19865 -#ifdef CONFIG_X86_64
19866 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19867 - NOSAVE_DATA
19868 - }
19869 -#endif
19870 -
19871 /* BSS */
19872 . = ALIGN(PAGE_SIZE);
19873 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19874 @@ -325,6 +392,7 @@ SECTIONS
19875 __brk_base = .;
19876 . += 64 * 1024; /* 64k alignment slop space */
19877 *(.brk_reservation) /* areas brk users have reserved */
19878 + . = ALIGN(HPAGE_SIZE);
19879 __brk_limit = .;
19880 }
19881
19882 @@ -351,13 +419,12 @@ SECTIONS
19883 * for the boot processor.
19884 */
19885 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19886 -INIT_PER_CPU(gdt_page);
19887 INIT_PER_CPU(irq_stack_union);
19888
19889 /*
19890 * Build-time check on the image size:
19891 */
19892 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19893 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19894 "kernel image bigger than KERNEL_IMAGE_SIZE");
19895
19896 #ifdef CONFIG_SMP
19897 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19898 index b07ba93..a212969 100644
19899 --- a/arch/x86/kernel/vsyscall_64.c
19900 +++ b/arch/x86/kernel/vsyscall_64.c
19901 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19902 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19903 };
19904
19905 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19906 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19907
19908 static int __init vsyscall_setup(char *str)
19909 {
19910 if (str) {
19911 if (!strcmp("emulate", str))
19912 vsyscall_mode = EMULATE;
19913 - else if (!strcmp("native", str))
19914 - vsyscall_mode = NATIVE;
19915 else if (!strcmp("none", str))
19916 vsyscall_mode = NONE;
19917 else
19918 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19919
19920 tsk = current;
19921 if (seccomp_mode(&tsk->seccomp))
19922 - do_exit(SIGKILL);
19923 + do_group_exit(SIGKILL);
19924
19925 /*
19926 * With a real vsyscall, page faults cause SIGSEGV. We want to
19927 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19928 return true;
19929
19930 sigsegv:
19931 - force_sig(SIGSEGV, current);
19932 - return true;
19933 + do_group_exit(SIGKILL);
19934 }
19935
19936 /*
19937 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19938 extern char __vvar_page;
19939 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19940
19941 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19942 - vsyscall_mode == NATIVE
19943 - ? PAGE_KERNEL_VSYSCALL
19944 - : PAGE_KERNEL_VVAR);
19945 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19946 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19947 (unsigned long)VSYSCALL_START);
19948
19949 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19950 index 9796c2f..f686fbf 100644
19951 --- a/arch/x86/kernel/x8664_ksyms_64.c
19952 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19953 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19954 EXPORT_SYMBOL(copy_user_generic_string);
19955 EXPORT_SYMBOL(copy_user_generic_unrolled);
19956 EXPORT_SYMBOL(__copy_user_nocache);
19957 -EXPORT_SYMBOL(_copy_from_user);
19958 -EXPORT_SYMBOL(_copy_to_user);
19959
19960 EXPORT_SYMBOL(copy_page);
19961 EXPORT_SYMBOL(clear_page);
19962 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19963 index 7110911..e8cdee5 100644
19964 --- a/arch/x86/kernel/xsave.c
19965 +++ b/arch/x86/kernel/xsave.c
19966 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19967 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19968 return -EINVAL;
19969
19970 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19971 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19972 fx_sw_user->extended_size -
19973 FP_XSTATE_MAGIC2_SIZE));
19974 if (err)
19975 @@ -266,7 +266,7 @@ fx_only:
19976 * the other extended state.
19977 */
19978 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19979 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19980 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19981 }
19982
19983 /*
19984 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19985 if (use_xsave())
19986 err = restore_user_xstate(buf);
19987 else
19988 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19989 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19990 buf);
19991 if (unlikely(err)) {
19992 /*
19993 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
19994 index 89b02bf..0f6511d 100644
19995 --- a/arch/x86/kvm/cpuid.c
19996 +++ b/arch/x86/kvm/cpuid.c
19997 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19998 struct kvm_cpuid2 *cpuid,
19999 struct kvm_cpuid_entry2 __user *entries)
20000 {
20001 - int r;
20002 + int r, i;
20003
20004 r = -E2BIG;
20005 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20006 goto out;
20007 r = -EFAULT;
20008 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20009 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20010 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20011 goto out;
20012 + for (i = 0; i < cpuid->nent; ++i) {
20013 + struct kvm_cpuid_entry2 cpuid_entry;
20014 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20015 + goto out;
20016 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20017 + }
20018 vcpu->arch.cpuid_nent = cpuid->nent;
20019 kvm_apic_set_version(vcpu);
20020 kvm_x86_ops->cpuid_update(vcpu);
20021 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20022 struct kvm_cpuid2 *cpuid,
20023 struct kvm_cpuid_entry2 __user *entries)
20024 {
20025 - int r;
20026 + int r, i;
20027
20028 r = -E2BIG;
20029 if (cpuid->nent < vcpu->arch.cpuid_nent)
20030 goto out;
20031 r = -EFAULT;
20032 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20033 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20034 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20035 goto out;
20036 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20037 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20038 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20039 + goto out;
20040 + }
20041 return 0;
20042
20043 out:
20044 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20045 index 0982507..7f6d72f 100644
20046 --- a/arch/x86/kvm/emulate.c
20047 +++ b/arch/x86/kvm/emulate.c
20048 @@ -250,6 +250,7 @@ struct gprefix {
20049
20050 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20051 do { \
20052 + unsigned long _tmp; \
20053 __asm__ __volatile__ ( \
20054 _PRE_EFLAGS("0", "4", "2") \
20055 _op _suffix " %"_x"3,%1; " \
20056 @@ -264,8 +265,6 @@ struct gprefix {
20057 /* Raw emulation: instruction has two explicit operands. */
20058 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20059 do { \
20060 - unsigned long _tmp; \
20061 - \
20062 switch ((ctxt)->dst.bytes) { \
20063 case 2: \
20064 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20065 @@ -281,7 +280,6 @@ struct gprefix {
20066
20067 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20068 do { \
20069 - unsigned long _tmp; \
20070 switch ((ctxt)->dst.bytes) { \
20071 case 1: \
20072 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20073 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20074 index cfdc6e0..ab92e84 100644
20075 --- a/arch/x86/kvm/lapic.c
20076 +++ b/arch/x86/kvm/lapic.c
20077 @@ -54,7 +54,7 @@
20078 #define APIC_BUS_CYCLE_NS 1
20079
20080 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20081 -#define apic_debug(fmt, arg...)
20082 +#define apic_debug(fmt, arg...) do {} while (0)
20083
20084 #define APIC_LVT_NUM 6
20085 /* 14 is the version for Xeon and Pentium 8.4.8*/
20086 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20087 index 1561028..0ed7f14 100644
20088 --- a/arch/x86/kvm/paging_tmpl.h
20089 +++ b/arch/x86/kvm/paging_tmpl.h
20090 @@ -197,7 +197,7 @@ retry_walk:
20091 if (unlikely(kvm_is_error_hva(host_addr)))
20092 goto error;
20093
20094 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20095 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20096 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20097 goto error;
20098
20099 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20100 index e385214..029e9dd 100644
20101 --- a/arch/x86/kvm/svm.c
20102 +++ b/arch/x86/kvm/svm.c
20103 @@ -3051,6 +3051,7 @@ static int svm_set_vm_cr(struct kvm_vcpu *vcpu, u64 data)
20104 return 0;
20105 }
20106
20107 +static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) __size_overflow(3);
20108 static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
20109 {
20110 struct vcpu_svm *svm = to_svm(vcpu);
20111 @@ -3420,7 +3421,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20112 int cpu = raw_smp_processor_id();
20113
20114 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20115 +
20116 + pax_open_kernel();
20117 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20118 + pax_close_kernel();
20119 +
20120 load_TR_desc();
20121 }
20122
20123 @@ -3798,6 +3803,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20124 #endif
20125 #endif
20126
20127 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20128 + __set_fs(current_thread_info()->addr_limit);
20129 +#endif
20130 +
20131 reload_tss(vcpu);
20132
20133 local_irq_disable();
20134 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20135 index 3b4c8d8..f457b63 100644
20136 --- a/arch/x86/kvm/vmx.c
20137 +++ b/arch/x86/kvm/vmx.c
20138 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20139 struct desc_struct *descs;
20140
20141 descs = (void *)gdt->address;
20142 +
20143 + pax_open_kernel();
20144 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20145 + pax_close_kernel();
20146 +
20147 load_TR_desc();
20148 }
20149
20150 @@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
20151 if (!cpu_has_vmx_flexpriority())
20152 flexpriority_enabled = 0;
20153
20154 - if (!cpu_has_vmx_tpr_shadow())
20155 - kvm_x86_ops->update_cr8_intercept = NULL;
20156 + if (!cpu_has_vmx_tpr_shadow()) {
20157 + pax_open_kernel();
20158 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20159 + pax_close_kernel();
20160 + }
20161
20162 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20163 kvm_disable_largepages();
20164 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
20165 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20166
20167 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20168 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20169 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20170
20171 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20172 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20173 @@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20174 "jmp .Lkvm_vmx_return \n\t"
20175 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20176 ".Lkvm_vmx_return: "
20177 +
20178 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20179 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20180 + ".Lkvm_vmx_return2: "
20181 +#endif
20182 +
20183 /* Save guest registers, load host registers, keep flags */
20184 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20185 "pop %0 \n\t"
20186 @@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20187 #endif
20188 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20189 [wordsize]"i"(sizeof(ulong))
20190 +
20191 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20192 + ,[cs]"i"(__KERNEL_CS)
20193 +#endif
20194 +
20195 : "cc", "memory"
20196 , R"ax", R"bx", R"di", R"si"
20197 #ifdef CONFIG_X86_64
20198 @@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20199 }
20200 }
20201
20202 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20203 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20204 +
20205 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20206 + loadsegment(fs, __KERNEL_PERCPU);
20207 +#endif
20208 +
20209 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20210 + __set_fs(current_thread_info()->addr_limit);
20211 +#endif
20212 +
20213 vmx->loaded_vmcs->launched = 1;
20214
20215 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20216 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20217 index 9cbfc06..943ffa6 100644
20218 --- a/arch/x86/kvm/x86.c
20219 +++ b/arch/x86/kvm/x86.c
20220 @@ -873,6 +873,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20221 return kvm_set_msr(vcpu, index, *data);
20222 }
20223
20224 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20225 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20226 {
20227 int version;
20228 @@ -1307,12 +1308,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
20229 return 0;
20230 }
20231
20232 +static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) __size_overflow(2);
20233 static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20234 {
20235 struct kvm *kvm = vcpu->kvm;
20236 int lm = is_long_mode(vcpu);
20237 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20238 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20239 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20240 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20241 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20242 : kvm->arch.xen_hvm_config.blob_size_32;
20243 u32 page_num = data & ~PAGE_MASK;
20244 @@ -2145,6 +2147,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20245 if (n < msr_list.nmsrs)
20246 goto out;
20247 r = -EFAULT;
20248 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20249 + goto out;
20250 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20251 num_msrs_to_save * sizeof(u32)))
20252 goto out;
20253 @@ -2266,7 +2270,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20254 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20255 struct kvm_interrupt *irq)
20256 {
20257 - if (irq->irq < 0 || irq->irq >= 256)
20258 + if (irq->irq >= 256)
20259 return -EINVAL;
20260 if (irqchip_in_kernel(vcpu->kvm))
20261 return -ENXIO;
20262 @@ -3497,6 +3501,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20263
20264 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20265 struct kvm_vcpu *vcpu, u32 access,
20266 + struct x86_exception *exception) __size_overflow(1,3);
20267 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20268 + struct kvm_vcpu *vcpu, u32 access,
20269 struct x86_exception *exception)
20270 {
20271 void *data = val;
20272 @@ -3528,6 +3535,9 @@ out:
20273 /* used for instruction fetching */
20274 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20275 gva_t addr, void *val, unsigned int bytes,
20276 + struct x86_exception *exception) __size_overflow(2,4);
20277 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20278 + gva_t addr, void *val, unsigned int bytes,
20279 struct x86_exception *exception)
20280 {
20281 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20282 @@ -3552,6 +3562,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20283
20284 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20285 gva_t addr, void *val, unsigned int bytes,
20286 + struct x86_exception *exception) __size_overflow(2,4);
20287 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20288 + gva_t addr, void *val, unsigned int bytes,
20289 struct x86_exception *exception)
20290 {
20291 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20292 @@ -3665,12 +3678,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20293 }
20294
20295 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20296 + void *val, int bytes) __size_overflow(2);
20297 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20298 void *val, int bytes)
20299 {
20300 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20301 }
20302
20303 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20304 + void *val, int bytes) __size_overflow(2);
20305 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20306 void *val, int bytes)
20307 {
20308 return emulator_write_phys(vcpu, gpa, val, bytes);
20309 @@ -3821,6 +3838,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20310 const void *old,
20311 const void *new,
20312 unsigned int bytes,
20313 + struct x86_exception *exception) __size_overflow(5);
20314 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20315 + unsigned long addr,
20316 + const void *old,
20317 + const void *new,
20318 + unsigned int bytes,
20319 struct x86_exception *exception)
20320 {
20321 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20322 @@ -4780,7 +4803,7 @@ static void kvm_set_mmio_spte_mask(void)
20323 kvm_mmu_set_mmio_spte_mask(mask);
20324 }
20325
20326 -int kvm_arch_init(void *opaque)
20327 +int kvm_arch_init(const void *opaque)
20328 {
20329 int r;
20330 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20331 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
20332 index cb80c29..aeee86c 100644
20333 --- a/arch/x86/kvm/x86.h
20334 +++ b/arch/x86/kvm/x86.h
20335 @@ -116,11 +116,11 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
20336
20337 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
20338 gva_t addr, void *val, unsigned int bytes,
20339 - struct x86_exception *exception);
20340 + struct x86_exception *exception) __size_overflow(2,4);
20341
20342 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20343 gva_t addr, void *val, unsigned int bytes,
20344 - struct x86_exception *exception);
20345 + struct x86_exception *exception) __size_overflow(2,4);
20346
20347 extern u64 host_xcr0;
20348
20349 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20350 index 642d880..44e0f3f 100644
20351 --- a/arch/x86/lguest/boot.c
20352 +++ b/arch/x86/lguest/boot.c
20353 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20354 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20355 * Launcher to reboot us.
20356 */
20357 -static void lguest_restart(char *reason)
20358 +static __noreturn void lguest_restart(char *reason)
20359 {
20360 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20361 + BUG();
20362 }
20363
20364 /*G:050
20365 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20366 index 042f682..c92afb6 100644
20367 --- a/arch/x86/lib/atomic64_32.c
20368 +++ b/arch/x86/lib/atomic64_32.c
20369 @@ -8,18 +8,30 @@
20370
20371 long long atomic64_read_cx8(long long, const atomic64_t *v);
20372 EXPORT_SYMBOL(atomic64_read_cx8);
20373 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20374 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20375 long long atomic64_set_cx8(long long, const atomic64_t *v);
20376 EXPORT_SYMBOL(atomic64_set_cx8);
20377 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20378 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20379 long long atomic64_xchg_cx8(long long, unsigned high);
20380 EXPORT_SYMBOL(atomic64_xchg_cx8);
20381 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20382 EXPORT_SYMBOL(atomic64_add_return_cx8);
20383 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20384 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20385 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20386 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20387 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20388 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20389 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20390 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20391 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20392 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20393 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20394 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20395 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20396 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20397 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20398 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20399 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20400 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20401 #ifndef CONFIG_X86_CMPXCHG64
20402 long long atomic64_read_386(long long, const atomic64_t *v);
20403 EXPORT_SYMBOL(atomic64_read_386);
20404 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20405 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20406 long long atomic64_set_386(long long, const atomic64_t *v);
20407 EXPORT_SYMBOL(atomic64_set_386);
20408 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20409 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20410 long long atomic64_xchg_386(long long, unsigned high);
20411 EXPORT_SYMBOL(atomic64_xchg_386);
20412 long long atomic64_add_return_386(long long a, atomic64_t *v);
20413 EXPORT_SYMBOL(atomic64_add_return_386);
20414 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20415 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20416 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20417 EXPORT_SYMBOL(atomic64_sub_return_386);
20418 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20419 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20420 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20421 EXPORT_SYMBOL(atomic64_inc_return_386);
20422 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20423 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20424 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20425 EXPORT_SYMBOL(atomic64_dec_return_386);
20426 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20427 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20428 long long atomic64_add_386(long long a, atomic64_t *v);
20429 EXPORT_SYMBOL(atomic64_add_386);
20430 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20431 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20432 long long atomic64_sub_386(long long a, atomic64_t *v);
20433 EXPORT_SYMBOL(atomic64_sub_386);
20434 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20435 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20436 long long atomic64_inc_386(long long a, atomic64_t *v);
20437 EXPORT_SYMBOL(atomic64_inc_386);
20438 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20439 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20440 long long atomic64_dec_386(long long a, atomic64_t *v);
20441 EXPORT_SYMBOL(atomic64_dec_386);
20442 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20443 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20444 long long atomic64_dec_if_positive_386(atomic64_t *v);
20445 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20446 int atomic64_inc_not_zero_386(atomic64_t *v);
20447 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20448 index e8e7e0d..56fd1b0 100644
20449 --- a/arch/x86/lib/atomic64_386_32.S
20450 +++ b/arch/x86/lib/atomic64_386_32.S
20451 @@ -48,6 +48,10 @@ BEGIN(read)
20452 movl (v), %eax
20453 movl 4(v), %edx
20454 RET_ENDP
20455 +BEGIN(read_unchecked)
20456 + movl (v), %eax
20457 + movl 4(v), %edx
20458 +RET_ENDP
20459 #undef v
20460
20461 #define v %esi
20462 @@ -55,6 +59,10 @@ BEGIN(set)
20463 movl %ebx, (v)
20464 movl %ecx, 4(v)
20465 RET_ENDP
20466 +BEGIN(set_unchecked)
20467 + movl %ebx, (v)
20468 + movl %ecx, 4(v)
20469 +RET_ENDP
20470 #undef v
20471
20472 #define v %esi
20473 @@ -70,6 +78,20 @@ RET_ENDP
20474 BEGIN(add)
20475 addl %eax, (v)
20476 adcl %edx, 4(v)
20477 +
20478 +#ifdef CONFIG_PAX_REFCOUNT
20479 + jno 0f
20480 + subl %eax, (v)
20481 + sbbl %edx, 4(v)
20482 + int $4
20483 +0:
20484 + _ASM_EXTABLE(0b, 0b)
20485 +#endif
20486 +
20487 +RET_ENDP
20488 +BEGIN(add_unchecked)
20489 + addl %eax, (v)
20490 + adcl %edx, 4(v)
20491 RET_ENDP
20492 #undef v
20493
20494 @@ -77,6 +99,24 @@ RET_ENDP
20495 BEGIN(add_return)
20496 addl (v), %eax
20497 adcl 4(v), %edx
20498 +
20499 +#ifdef CONFIG_PAX_REFCOUNT
20500 + into
20501 +1234:
20502 + _ASM_EXTABLE(1234b, 2f)
20503 +#endif
20504 +
20505 + movl %eax, (v)
20506 + movl %edx, 4(v)
20507 +
20508 +#ifdef CONFIG_PAX_REFCOUNT
20509 +2:
20510 +#endif
20511 +
20512 +RET_ENDP
20513 +BEGIN(add_return_unchecked)
20514 + addl (v), %eax
20515 + adcl 4(v), %edx
20516 movl %eax, (v)
20517 movl %edx, 4(v)
20518 RET_ENDP
20519 @@ -86,6 +126,20 @@ RET_ENDP
20520 BEGIN(sub)
20521 subl %eax, (v)
20522 sbbl %edx, 4(v)
20523 +
20524 +#ifdef CONFIG_PAX_REFCOUNT
20525 + jno 0f
20526 + addl %eax, (v)
20527 + adcl %edx, 4(v)
20528 + int $4
20529 +0:
20530 + _ASM_EXTABLE(0b, 0b)
20531 +#endif
20532 +
20533 +RET_ENDP
20534 +BEGIN(sub_unchecked)
20535 + subl %eax, (v)
20536 + sbbl %edx, 4(v)
20537 RET_ENDP
20538 #undef v
20539
20540 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20541 sbbl $0, %edx
20542 addl (v), %eax
20543 adcl 4(v), %edx
20544 +
20545 +#ifdef CONFIG_PAX_REFCOUNT
20546 + into
20547 +1234:
20548 + _ASM_EXTABLE(1234b, 2f)
20549 +#endif
20550 +
20551 + movl %eax, (v)
20552 + movl %edx, 4(v)
20553 +
20554 +#ifdef CONFIG_PAX_REFCOUNT
20555 +2:
20556 +#endif
20557 +
20558 +RET_ENDP
20559 +BEGIN(sub_return_unchecked)
20560 + negl %edx
20561 + negl %eax
20562 + sbbl $0, %edx
20563 + addl (v), %eax
20564 + adcl 4(v), %edx
20565 movl %eax, (v)
20566 movl %edx, 4(v)
20567 RET_ENDP
20568 @@ -105,6 +180,20 @@ RET_ENDP
20569 BEGIN(inc)
20570 addl $1, (v)
20571 adcl $0, 4(v)
20572 +
20573 +#ifdef CONFIG_PAX_REFCOUNT
20574 + jno 0f
20575 + subl $1, (v)
20576 + sbbl $0, 4(v)
20577 + int $4
20578 +0:
20579 + _ASM_EXTABLE(0b, 0b)
20580 +#endif
20581 +
20582 +RET_ENDP
20583 +BEGIN(inc_unchecked)
20584 + addl $1, (v)
20585 + adcl $0, 4(v)
20586 RET_ENDP
20587 #undef v
20588
20589 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20590 movl 4(v), %edx
20591 addl $1, %eax
20592 adcl $0, %edx
20593 +
20594 +#ifdef CONFIG_PAX_REFCOUNT
20595 + into
20596 +1234:
20597 + _ASM_EXTABLE(1234b, 2f)
20598 +#endif
20599 +
20600 + movl %eax, (v)
20601 + movl %edx, 4(v)
20602 +
20603 +#ifdef CONFIG_PAX_REFCOUNT
20604 +2:
20605 +#endif
20606 +
20607 +RET_ENDP
20608 +BEGIN(inc_return_unchecked)
20609 + movl (v), %eax
20610 + movl 4(v), %edx
20611 + addl $1, %eax
20612 + adcl $0, %edx
20613 movl %eax, (v)
20614 movl %edx, 4(v)
20615 RET_ENDP
20616 @@ -123,6 +232,20 @@ RET_ENDP
20617 BEGIN(dec)
20618 subl $1, (v)
20619 sbbl $0, 4(v)
20620 +
20621 +#ifdef CONFIG_PAX_REFCOUNT
20622 + jno 0f
20623 + addl $1, (v)
20624 + adcl $0, 4(v)
20625 + int $4
20626 +0:
20627 + _ASM_EXTABLE(0b, 0b)
20628 +#endif
20629 +
20630 +RET_ENDP
20631 +BEGIN(dec_unchecked)
20632 + subl $1, (v)
20633 + sbbl $0, 4(v)
20634 RET_ENDP
20635 #undef v
20636
20637 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20638 movl 4(v), %edx
20639 subl $1, %eax
20640 sbbl $0, %edx
20641 +
20642 +#ifdef CONFIG_PAX_REFCOUNT
20643 + into
20644 +1234:
20645 + _ASM_EXTABLE(1234b, 2f)
20646 +#endif
20647 +
20648 + movl %eax, (v)
20649 + movl %edx, 4(v)
20650 +
20651 +#ifdef CONFIG_PAX_REFCOUNT
20652 +2:
20653 +#endif
20654 +
20655 +RET_ENDP
20656 +BEGIN(dec_return_unchecked)
20657 + movl (v), %eax
20658 + movl 4(v), %edx
20659 + subl $1, %eax
20660 + sbbl $0, %edx
20661 movl %eax, (v)
20662 movl %edx, 4(v)
20663 RET_ENDP
20664 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20665 adcl %edx, %edi
20666 addl (v), %eax
20667 adcl 4(v), %edx
20668 +
20669 +#ifdef CONFIG_PAX_REFCOUNT
20670 + into
20671 +1234:
20672 + _ASM_EXTABLE(1234b, 2f)
20673 +#endif
20674 +
20675 cmpl %eax, %esi
20676 je 3f
20677 1:
20678 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20679 1:
20680 addl $1, %eax
20681 adcl $0, %edx
20682 +
20683 +#ifdef CONFIG_PAX_REFCOUNT
20684 + into
20685 +1234:
20686 + _ASM_EXTABLE(1234b, 2f)
20687 +#endif
20688 +
20689 movl %eax, (v)
20690 movl %edx, 4(v)
20691 movl $1, %eax
20692 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20693 movl 4(v), %edx
20694 subl $1, %eax
20695 sbbl $0, %edx
20696 +
20697 +#ifdef CONFIG_PAX_REFCOUNT
20698 + into
20699 +1234:
20700 + _ASM_EXTABLE(1234b, 1f)
20701 +#endif
20702 +
20703 js 1f
20704 movl %eax, (v)
20705 movl %edx, 4(v)
20706 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20707 index 391a083..d658e9f 100644
20708 --- a/arch/x86/lib/atomic64_cx8_32.S
20709 +++ b/arch/x86/lib/atomic64_cx8_32.S
20710 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20711 CFI_STARTPROC
20712
20713 read64 %ecx
20714 + pax_force_retaddr
20715 ret
20716 CFI_ENDPROC
20717 ENDPROC(atomic64_read_cx8)
20718
20719 +ENTRY(atomic64_read_unchecked_cx8)
20720 + CFI_STARTPROC
20721 +
20722 + read64 %ecx
20723 + pax_force_retaddr
20724 + ret
20725 + CFI_ENDPROC
20726 +ENDPROC(atomic64_read_unchecked_cx8)
20727 +
20728 ENTRY(atomic64_set_cx8)
20729 CFI_STARTPROC
20730
20731 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20732 cmpxchg8b (%esi)
20733 jne 1b
20734
20735 + pax_force_retaddr
20736 ret
20737 CFI_ENDPROC
20738 ENDPROC(atomic64_set_cx8)
20739
20740 +ENTRY(atomic64_set_unchecked_cx8)
20741 + CFI_STARTPROC
20742 +
20743 +1:
20744 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20745 + * are atomic on 586 and newer */
20746 + cmpxchg8b (%esi)
20747 + jne 1b
20748 +
20749 + pax_force_retaddr
20750 + ret
20751 + CFI_ENDPROC
20752 +ENDPROC(atomic64_set_unchecked_cx8)
20753 +
20754 ENTRY(atomic64_xchg_cx8)
20755 CFI_STARTPROC
20756
20757 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20758 cmpxchg8b (%esi)
20759 jne 1b
20760
20761 + pax_force_retaddr
20762 ret
20763 CFI_ENDPROC
20764 ENDPROC(atomic64_xchg_cx8)
20765
20766 -.macro addsub_return func ins insc
20767 -ENTRY(atomic64_\func\()_return_cx8)
20768 +.macro addsub_return func ins insc unchecked=""
20769 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20770 CFI_STARTPROC
20771 SAVE ebp
20772 SAVE ebx
20773 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20774 movl %edx, %ecx
20775 \ins\()l %esi, %ebx
20776 \insc\()l %edi, %ecx
20777 +
20778 +.ifb \unchecked
20779 +#ifdef CONFIG_PAX_REFCOUNT
20780 + into
20781 +2:
20782 + _ASM_EXTABLE(2b, 3f)
20783 +#endif
20784 +.endif
20785 +
20786 LOCK_PREFIX
20787 cmpxchg8b (%ebp)
20788 jne 1b
20789 -
20790 -10:
20791 movl %ebx, %eax
20792 movl %ecx, %edx
20793 +
20794 +.ifb \unchecked
20795 +#ifdef CONFIG_PAX_REFCOUNT
20796 +3:
20797 +#endif
20798 +.endif
20799 +
20800 RESTORE edi
20801 RESTORE esi
20802 RESTORE ebx
20803 RESTORE ebp
20804 + pax_force_retaddr
20805 ret
20806 CFI_ENDPROC
20807 -ENDPROC(atomic64_\func\()_return_cx8)
20808 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20809 .endm
20810
20811 addsub_return add add adc
20812 addsub_return sub sub sbb
20813 +addsub_return add add adc _unchecked
20814 +addsub_return sub sub sbb _unchecked
20815
20816 -.macro incdec_return func ins insc
20817 -ENTRY(atomic64_\func\()_return_cx8)
20818 +.macro incdec_return func ins insc unchecked
20819 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20820 CFI_STARTPROC
20821 SAVE ebx
20822
20823 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20824 movl %edx, %ecx
20825 \ins\()l $1, %ebx
20826 \insc\()l $0, %ecx
20827 +
20828 +.ifb \unchecked
20829 +#ifdef CONFIG_PAX_REFCOUNT
20830 + into
20831 +2:
20832 + _ASM_EXTABLE(2b, 3f)
20833 +#endif
20834 +.endif
20835 +
20836 LOCK_PREFIX
20837 cmpxchg8b (%esi)
20838 jne 1b
20839
20840 -10:
20841 movl %ebx, %eax
20842 movl %ecx, %edx
20843 +
20844 +.ifb \unchecked
20845 +#ifdef CONFIG_PAX_REFCOUNT
20846 +3:
20847 +#endif
20848 +.endif
20849 +
20850 RESTORE ebx
20851 + pax_force_retaddr
20852 ret
20853 CFI_ENDPROC
20854 -ENDPROC(atomic64_\func\()_return_cx8)
20855 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20856 .endm
20857
20858 incdec_return inc add adc
20859 incdec_return dec sub sbb
20860 +incdec_return inc add adc _unchecked
20861 +incdec_return dec sub sbb _unchecked
20862
20863 ENTRY(atomic64_dec_if_positive_cx8)
20864 CFI_STARTPROC
20865 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20866 movl %edx, %ecx
20867 subl $1, %ebx
20868 sbb $0, %ecx
20869 +
20870 +#ifdef CONFIG_PAX_REFCOUNT
20871 + into
20872 +1234:
20873 + _ASM_EXTABLE(1234b, 2f)
20874 +#endif
20875 +
20876 js 2f
20877 LOCK_PREFIX
20878 cmpxchg8b (%esi)
20879 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20880 movl %ebx, %eax
20881 movl %ecx, %edx
20882 RESTORE ebx
20883 + pax_force_retaddr
20884 ret
20885 CFI_ENDPROC
20886 ENDPROC(atomic64_dec_if_positive_cx8)
20887 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20888 movl %edx, %ecx
20889 addl %esi, %ebx
20890 adcl %edi, %ecx
20891 +
20892 +#ifdef CONFIG_PAX_REFCOUNT
20893 + into
20894 +1234:
20895 + _ASM_EXTABLE(1234b, 3f)
20896 +#endif
20897 +
20898 LOCK_PREFIX
20899 cmpxchg8b (%ebp)
20900 jne 1b
20901 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20902 CFI_ADJUST_CFA_OFFSET -8
20903 RESTORE ebx
20904 RESTORE ebp
20905 + pax_force_retaddr
20906 ret
20907 4:
20908 cmpl %edx, 4(%esp)
20909 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20910 movl %edx, %ecx
20911 addl $1, %ebx
20912 adcl $0, %ecx
20913 +
20914 +#ifdef CONFIG_PAX_REFCOUNT
20915 + into
20916 +1234:
20917 + _ASM_EXTABLE(1234b, 3f)
20918 +#endif
20919 +
20920 LOCK_PREFIX
20921 cmpxchg8b (%esi)
20922 jne 1b
20923 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20924 movl $1, %eax
20925 3:
20926 RESTORE ebx
20927 + pax_force_retaddr
20928 ret
20929 4:
20930 testl %edx, %edx
20931 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20932 index 78d16a5..fbcf666 100644
20933 --- a/arch/x86/lib/checksum_32.S
20934 +++ b/arch/x86/lib/checksum_32.S
20935 @@ -28,7 +28,8 @@
20936 #include <linux/linkage.h>
20937 #include <asm/dwarf2.h>
20938 #include <asm/errno.h>
20939 -
20940 +#include <asm/segment.h>
20941 +
20942 /*
20943 * computes a partial checksum, e.g. for TCP/UDP fragments
20944 */
20945 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20946
20947 #define ARGBASE 16
20948 #define FP 12
20949 -
20950 -ENTRY(csum_partial_copy_generic)
20951 +
20952 +ENTRY(csum_partial_copy_generic_to_user)
20953 CFI_STARTPROC
20954 +
20955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20956 + pushl_cfi %gs
20957 + popl_cfi %es
20958 + jmp csum_partial_copy_generic
20959 +#endif
20960 +
20961 +ENTRY(csum_partial_copy_generic_from_user)
20962 +
20963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20964 + pushl_cfi %gs
20965 + popl_cfi %ds
20966 +#endif
20967 +
20968 +ENTRY(csum_partial_copy_generic)
20969 subl $4,%esp
20970 CFI_ADJUST_CFA_OFFSET 4
20971 pushl_cfi %edi
20972 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20973 jmp 4f
20974 SRC(1: movw (%esi), %bx )
20975 addl $2, %esi
20976 -DST( movw %bx, (%edi) )
20977 +DST( movw %bx, %es:(%edi) )
20978 addl $2, %edi
20979 addw %bx, %ax
20980 adcl $0, %eax
20981 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20982 SRC(1: movl (%esi), %ebx )
20983 SRC( movl 4(%esi), %edx )
20984 adcl %ebx, %eax
20985 -DST( movl %ebx, (%edi) )
20986 +DST( movl %ebx, %es:(%edi) )
20987 adcl %edx, %eax
20988 -DST( movl %edx, 4(%edi) )
20989 +DST( movl %edx, %es:4(%edi) )
20990
20991 SRC( movl 8(%esi), %ebx )
20992 SRC( movl 12(%esi), %edx )
20993 adcl %ebx, %eax
20994 -DST( movl %ebx, 8(%edi) )
20995 +DST( movl %ebx, %es:8(%edi) )
20996 adcl %edx, %eax
20997 -DST( movl %edx, 12(%edi) )
20998 +DST( movl %edx, %es:12(%edi) )
20999
21000 SRC( movl 16(%esi), %ebx )
21001 SRC( movl 20(%esi), %edx )
21002 adcl %ebx, %eax
21003 -DST( movl %ebx, 16(%edi) )
21004 +DST( movl %ebx, %es:16(%edi) )
21005 adcl %edx, %eax
21006 -DST( movl %edx, 20(%edi) )
21007 +DST( movl %edx, %es:20(%edi) )
21008
21009 SRC( movl 24(%esi), %ebx )
21010 SRC( movl 28(%esi), %edx )
21011 adcl %ebx, %eax
21012 -DST( movl %ebx, 24(%edi) )
21013 +DST( movl %ebx, %es:24(%edi) )
21014 adcl %edx, %eax
21015 -DST( movl %edx, 28(%edi) )
21016 +DST( movl %edx, %es:28(%edi) )
21017
21018 lea 32(%esi), %esi
21019 lea 32(%edi), %edi
21020 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21021 shrl $2, %edx # This clears CF
21022 SRC(3: movl (%esi), %ebx )
21023 adcl %ebx, %eax
21024 -DST( movl %ebx, (%edi) )
21025 +DST( movl %ebx, %es:(%edi) )
21026 lea 4(%esi), %esi
21027 lea 4(%edi), %edi
21028 dec %edx
21029 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21030 jb 5f
21031 SRC( movw (%esi), %cx )
21032 leal 2(%esi), %esi
21033 -DST( movw %cx, (%edi) )
21034 +DST( movw %cx, %es:(%edi) )
21035 leal 2(%edi), %edi
21036 je 6f
21037 shll $16,%ecx
21038 SRC(5: movb (%esi), %cl )
21039 -DST( movb %cl, (%edi) )
21040 +DST( movb %cl, %es:(%edi) )
21041 6: addl %ecx, %eax
21042 adcl $0, %eax
21043 7:
21044 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21045
21046 6001:
21047 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21048 - movl $-EFAULT, (%ebx)
21049 + movl $-EFAULT, %ss:(%ebx)
21050
21051 # zero the complete destination - computing the rest
21052 # is too much work
21053 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21054
21055 6002:
21056 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21057 - movl $-EFAULT,(%ebx)
21058 + movl $-EFAULT,%ss:(%ebx)
21059 jmp 5000b
21060
21061 .previous
21062
21063 + pushl_cfi %ss
21064 + popl_cfi %ds
21065 + pushl_cfi %ss
21066 + popl_cfi %es
21067 popl_cfi %ebx
21068 CFI_RESTORE ebx
21069 popl_cfi %esi
21070 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21071 popl_cfi %ecx # equivalent to addl $4,%esp
21072 ret
21073 CFI_ENDPROC
21074 -ENDPROC(csum_partial_copy_generic)
21075 +ENDPROC(csum_partial_copy_generic_to_user)
21076
21077 #else
21078
21079 /* Version for PentiumII/PPro */
21080
21081 #define ROUND1(x) \
21082 + nop; nop; nop; \
21083 SRC(movl x(%esi), %ebx ) ; \
21084 addl %ebx, %eax ; \
21085 - DST(movl %ebx, x(%edi) ) ;
21086 + DST(movl %ebx, %es:x(%edi)) ;
21087
21088 #define ROUND(x) \
21089 + nop; nop; nop; \
21090 SRC(movl x(%esi), %ebx ) ; \
21091 adcl %ebx, %eax ; \
21092 - DST(movl %ebx, x(%edi) ) ;
21093 + DST(movl %ebx, %es:x(%edi)) ;
21094
21095 #define ARGBASE 12
21096 -
21097 -ENTRY(csum_partial_copy_generic)
21098 +
21099 +ENTRY(csum_partial_copy_generic_to_user)
21100 CFI_STARTPROC
21101 +
21102 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21103 + pushl_cfi %gs
21104 + popl_cfi %es
21105 + jmp csum_partial_copy_generic
21106 +#endif
21107 +
21108 +ENTRY(csum_partial_copy_generic_from_user)
21109 +
21110 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21111 + pushl_cfi %gs
21112 + popl_cfi %ds
21113 +#endif
21114 +
21115 +ENTRY(csum_partial_copy_generic)
21116 pushl_cfi %ebx
21117 CFI_REL_OFFSET ebx, 0
21118 pushl_cfi %edi
21119 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21120 subl %ebx, %edi
21121 lea -1(%esi),%edx
21122 andl $-32,%edx
21123 - lea 3f(%ebx,%ebx), %ebx
21124 + lea 3f(%ebx,%ebx,2), %ebx
21125 testl %esi, %esi
21126 jmp *%ebx
21127 1: addl $64,%esi
21128 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21129 jb 5f
21130 SRC( movw (%esi), %dx )
21131 leal 2(%esi), %esi
21132 -DST( movw %dx, (%edi) )
21133 +DST( movw %dx, %es:(%edi) )
21134 leal 2(%edi), %edi
21135 je 6f
21136 shll $16,%edx
21137 5:
21138 SRC( movb (%esi), %dl )
21139 -DST( movb %dl, (%edi) )
21140 +DST( movb %dl, %es:(%edi) )
21141 6: addl %edx, %eax
21142 adcl $0, %eax
21143 7:
21144 .section .fixup, "ax"
21145 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21146 - movl $-EFAULT, (%ebx)
21147 + movl $-EFAULT, %ss:(%ebx)
21148 # zero the complete destination (computing the rest is too much work)
21149 movl ARGBASE+8(%esp),%edi # dst
21150 movl ARGBASE+12(%esp),%ecx # len
21151 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21152 rep; stosb
21153 jmp 7b
21154 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21155 - movl $-EFAULT, (%ebx)
21156 + movl $-EFAULT, %ss:(%ebx)
21157 jmp 7b
21158 .previous
21159
21160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21161 + pushl_cfi %ss
21162 + popl_cfi %ds
21163 + pushl_cfi %ss
21164 + popl_cfi %es
21165 +#endif
21166 +
21167 popl_cfi %esi
21168 CFI_RESTORE esi
21169 popl_cfi %edi
21170 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21171 CFI_RESTORE ebx
21172 ret
21173 CFI_ENDPROC
21174 -ENDPROC(csum_partial_copy_generic)
21175 +ENDPROC(csum_partial_copy_generic_to_user)
21176
21177 #undef ROUND
21178 #undef ROUND1
21179 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21180 index f2145cf..cea889d 100644
21181 --- a/arch/x86/lib/clear_page_64.S
21182 +++ b/arch/x86/lib/clear_page_64.S
21183 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21184 movl $4096/8,%ecx
21185 xorl %eax,%eax
21186 rep stosq
21187 + pax_force_retaddr
21188 ret
21189 CFI_ENDPROC
21190 ENDPROC(clear_page_c)
21191 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21192 movl $4096,%ecx
21193 xorl %eax,%eax
21194 rep stosb
21195 + pax_force_retaddr
21196 ret
21197 CFI_ENDPROC
21198 ENDPROC(clear_page_c_e)
21199 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21200 leaq 64(%rdi),%rdi
21201 jnz .Lloop
21202 nop
21203 + pax_force_retaddr
21204 ret
21205 CFI_ENDPROC
21206 .Lclear_page_end:
21207 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21208
21209 #include <asm/cpufeature.h>
21210
21211 - .section .altinstr_replacement,"ax"
21212 + .section .altinstr_replacement,"a"
21213 1: .byte 0xeb /* jmp <disp8> */
21214 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21215 2: .byte 0xeb /* jmp <disp8> */
21216 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21217 index 1e572c5..2a162cd 100644
21218 --- a/arch/x86/lib/cmpxchg16b_emu.S
21219 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21220 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21221
21222 popf
21223 mov $1, %al
21224 + pax_force_retaddr
21225 ret
21226
21227 not_same:
21228 popf
21229 xor %al,%al
21230 + pax_force_retaddr
21231 ret
21232
21233 CFI_ENDPROC
21234 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21235 index 01c805b..dccb07f 100644
21236 --- a/arch/x86/lib/copy_page_64.S
21237 +++ b/arch/x86/lib/copy_page_64.S
21238 @@ -9,6 +9,7 @@ copy_page_c:
21239 CFI_STARTPROC
21240 movl $4096/8,%ecx
21241 rep movsq
21242 + pax_force_retaddr
21243 ret
21244 CFI_ENDPROC
21245 ENDPROC(copy_page_c)
21246 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21247 movq 16 (%rsi), %rdx
21248 movq 24 (%rsi), %r8
21249 movq 32 (%rsi), %r9
21250 - movq 40 (%rsi), %r10
21251 + movq 40 (%rsi), %r13
21252 movq 48 (%rsi), %r11
21253 movq 56 (%rsi), %r12
21254
21255 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21256 movq %rdx, 16 (%rdi)
21257 movq %r8, 24 (%rdi)
21258 movq %r9, 32 (%rdi)
21259 - movq %r10, 40 (%rdi)
21260 + movq %r13, 40 (%rdi)
21261 movq %r11, 48 (%rdi)
21262 movq %r12, 56 (%rdi)
21263
21264 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21265 movq 16 (%rsi), %rdx
21266 movq 24 (%rsi), %r8
21267 movq 32 (%rsi), %r9
21268 - movq 40 (%rsi), %r10
21269 + movq 40 (%rsi), %r13
21270 movq 48 (%rsi), %r11
21271 movq 56 (%rsi), %r12
21272
21273 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21274 movq %rdx, 16 (%rdi)
21275 movq %r8, 24 (%rdi)
21276 movq %r9, 32 (%rdi)
21277 - movq %r10, 40 (%rdi)
21278 + movq %r13, 40 (%rdi)
21279 movq %r11, 48 (%rdi)
21280 movq %r12, 56 (%rdi)
21281
21282 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21283 CFI_RESTORE r13
21284 addq $3*8,%rsp
21285 CFI_ADJUST_CFA_OFFSET -3*8
21286 + pax_force_retaddr
21287 ret
21288 .Lcopy_page_end:
21289 CFI_ENDPROC
21290 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21291
21292 #include <asm/cpufeature.h>
21293
21294 - .section .altinstr_replacement,"ax"
21295 + .section .altinstr_replacement,"a"
21296 1: .byte 0xeb /* jmp <disp8> */
21297 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21298 2:
21299 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21300 index 0248402..821c786 100644
21301 --- a/arch/x86/lib/copy_user_64.S
21302 +++ b/arch/x86/lib/copy_user_64.S
21303 @@ -16,6 +16,7 @@
21304 #include <asm/thread_info.h>
21305 #include <asm/cpufeature.h>
21306 #include <asm/alternative-asm.h>
21307 +#include <asm/pgtable.h>
21308
21309 /*
21310 * By placing feature2 after feature1 in altinstructions section, we logically
21311 @@ -29,7 +30,7 @@
21312 .byte 0xe9 /* 32bit jump */
21313 .long \orig-1f /* by default jump to orig */
21314 1:
21315 - .section .altinstr_replacement,"ax"
21316 + .section .altinstr_replacement,"a"
21317 2: .byte 0xe9 /* near jump with 32bit immediate */
21318 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21319 3: .byte 0xe9 /* near jump with 32bit immediate */
21320 @@ -71,47 +72,20 @@
21321 #endif
21322 .endm
21323
21324 -/* Standard copy_to_user with segment limit checking */
21325 -ENTRY(_copy_to_user)
21326 - CFI_STARTPROC
21327 - GET_THREAD_INFO(%rax)
21328 - movq %rdi,%rcx
21329 - addq %rdx,%rcx
21330 - jc bad_to_user
21331 - cmpq TI_addr_limit(%rax),%rcx
21332 - ja bad_to_user
21333 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21334 - copy_user_generic_unrolled,copy_user_generic_string, \
21335 - copy_user_enhanced_fast_string
21336 - CFI_ENDPROC
21337 -ENDPROC(_copy_to_user)
21338 -
21339 -/* Standard copy_from_user with segment limit checking */
21340 -ENTRY(_copy_from_user)
21341 - CFI_STARTPROC
21342 - GET_THREAD_INFO(%rax)
21343 - movq %rsi,%rcx
21344 - addq %rdx,%rcx
21345 - jc bad_from_user
21346 - cmpq TI_addr_limit(%rax),%rcx
21347 - ja bad_from_user
21348 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21349 - copy_user_generic_unrolled,copy_user_generic_string, \
21350 - copy_user_enhanced_fast_string
21351 - CFI_ENDPROC
21352 -ENDPROC(_copy_from_user)
21353 -
21354 .section .fixup,"ax"
21355 /* must zero dest */
21356 ENTRY(bad_from_user)
21357 bad_from_user:
21358 CFI_STARTPROC
21359 + testl %edx,%edx
21360 + js bad_to_user
21361 movl %edx,%ecx
21362 xorl %eax,%eax
21363 rep
21364 stosb
21365 bad_to_user:
21366 movl %edx,%eax
21367 + pax_force_retaddr
21368 ret
21369 CFI_ENDPROC
21370 ENDPROC(bad_from_user)
21371 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21372 jz 17f
21373 1: movq (%rsi),%r8
21374 2: movq 1*8(%rsi),%r9
21375 -3: movq 2*8(%rsi),%r10
21376 +3: movq 2*8(%rsi),%rax
21377 4: movq 3*8(%rsi),%r11
21378 5: movq %r8,(%rdi)
21379 6: movq %r9,1*8(%rdi)
21380 -7: movq %r10,2*8(%rdi)
21381 +7: movq %rax,2*8(%rdi)
21382 8: movq %r11,3*8(%rdi)
21383 9: movq 4*8(%rsi),%r8
21384 10: movq 5*8(%rsi),%r9
21385 -11: movq 6*8(%rsi),%r10
21386 +11: movq 6*8(%rsi),%rax
21387 12: movq 7*8(%rsi),%r11
21388 13: movq %r8,4*8(%rdi)
21389 14: movq %r9,5*8(%rdi)
21390 -15: movq %r10,6*8(%rdi)
21391 +15: movq %rax,6*8(%rdi)
21392 16: movq %r11,7*8(%rdi)
21393 leaq 64(%rsi),%rsi
21394 leaq 64(%rdi),%rdi
21395 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21396 decl %ecx
21397 jnz 21b
21398 23: xor %eax,%eax
21399 + pax_force_retaddr
21400 ret
21401
21402 .section .fixup,"ax"
21403 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21404 3: rep
21405 movsb
21406 4: xorl %eax,%eax
21407 + pax_force_retaddr
21408 ret
21409
21410 .section .fixup,"ax"
21411 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21412 1: rep
21413 movsb
21414 2: xorl %eax,%eax
21415 + pax_force_retaddr
21416 ret
21417
21418 .section .fixup,"ax"
21419 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21420 index cb0c112..e3a6895 100644
21421 --- a/arch/x86/lib/copy_user_nocache_64.S
21422 +++ b/arch/x86/lib/copy_user_nocache_64.S
21423 @@ -8,12 +8,14 @@
21424
21425 #include <linux/linkage.h>
21426 #include <asm/dwarf2.h>
21427 +#include <asm/alternative-asm.h>
21428
21429 #define FIX_ALIGNMENT 1
21430
21431 #include <asm/current.h>
21432 #include <asm/asm-offsets.h>
21433 #include <asm/thread_info.h>
21434 +#include <asm/pgtable.h>
21435
21436 .macro ALIGN_DESTINATION
21437 #ifdef FIX_ALIGNMENT
21438 @@ -50,6 +52,15 @@
21439 */
21440 ENTRY(__copy_user_nocache)
21441 CFI_STARTPROC
21442 +
21443 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21444 + mov $PAX_USER_SHADOW_BASE,%rcx
21445 + cmp %rcx,%rsi
21446 + jae 1f
21447 + add %rcx,%rsi
21448 +1:
21449 +#endif
21450 +
21451 cmpl $8,%edx
21452 jb 20f /* less then 8 bytes, go to byte copy loop */
21453 ALIGN_DESTINATION
21454 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21455 jz 17f
21456 1: movq (%rsi),%r8
21457 2: movq 1*8(%rsi),%r9
21458 -3: movq 2*8(%rsi),%r10
21459 +3: movq 2*8(%rsi),%rax
21460 4: movq 3*8(%rsi),%r11
21461 5: movnti %r8,(%rdi)
21462 6: movnti %r9,1*8(%rdi)
21463 -7: movnti %r10,2*8(%rdi)
21464 +7: movnti %rax,2*8(%rdi)
21465 8: movnti %r11,3*8(%rdi)
21466 9: movq 4*8(%rsi),%r8
21467 10: movq 5*8(%rsi),%r9
21468 -11: movq 6*8(%rsi),%r10
21469 +11: movq 6*8(%rsi),%rax
21470 12: movq 7*8(%rsi),%r11
21471 13: movnti %r8,4*8(%rdi)
21472 14: movnti %r9,5*8(%rdi)
21473 -15: movnti %r10,6*8(%rdi)
21474 +15: movnti %rax,6*8(%rdi)
21475 16: movnti %r11,7*8(%rdi)
21476 leaq 64(%rsi),%rsi
21477 leaq 64(%rdi),%rdi
21478 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21479 jnz 21b
21480 23: xorl %eax,%eax
21481 sfence
21482 + pax_force_retaddr
21483 ret
21484
21485 .section .fixup,"ax"
21486 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21487 index fb903b7..c92b7f7 100644
21488 --- a/arch/x86/lib/csum-copy_64.S
21489 +++ b/arch/x86/lib/csum-copy_64.S
21490 @@ -8,6 +8,7 @@
21491 #include <linux/linkage.h>
21492 #include <asm/dwarf2.h>
21493 #include <asm/errno.h>
21494 +#include <asm/alternative-asm.h>
21495
21496 /*
21497 * Checksum copy with exception handling.
21498 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21499 CFI_RESTORE rbp
21500 addq $7*8, %rsp
21501 CFI_ADJUST_CFA_OFFSET -7*8
21502 + pax_force_retaddr 0, 1
21503 ret
21504 CFI_RESTORE_STATE
21505
21506 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21507 index 459b58a..9570bc7 100644
21508 --- a/arch/x86/lib/csum-wrappers_64.c
21509 +++ b/arch/x86/lib/csum-wrappers_64.c
21510 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21511 len -= 2;
21512 }
21513 }
21514 - isum = csum_partial_copy_generic((__force const void *)src,
21515 +
21516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21517 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21518 + src += PAX_USER_SHADOW_BASE;
21519 +#endif
21520 +
21521 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21522 dst, len, isum, errp, NULL);
21523 if (unlikely(*errp))
21524 goto out_err;
21525 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21526 }
21527
21528 *errp = 0;
21529 - return csum_partial_copy_generic(src, (void __force *)dst,
21530 +
21531 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21532 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21533 + dst += PAX_USER_SHADOW_BASE;
21534 +#endif
21535 +
21536 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21537 len, isum, NULL, errp);
21538 }
21539 EXPORT_SYMBOL(csum_partial_copy_to_user);
21540 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21541 index 51f1504..ddac4c1 100644
21542 --- a/arch/x86/lib/getuser.S
21543 +++ b/arch/x86/lib/getuser.S
21544 @@ -33,15 +33,38 @@
21545 #include <asm/asm-offsets.h>
21546 #include <asm/thread_info.h>
21547 #include <asm/asm.h>
21548 +#include <asm/segment.h>
21549 +#include <asm/pgtable.h>
21550 +#include <asm/alternative-asm.h>
21551 +
21552 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21553 +#define __copyuser_seg gs;
21554 +#else
21555 +#define __copyuser_seg
21556 +#endif
21557
21558 .text
21559 ENTRY(__get_user_1)
21560 CFI_STARTPROC
21561 +
21562 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21563 GET_THREAD_INFO(%_ASM_DX)
21564 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21565 jae bad_get_user
21566 -1: movzb (%_ASM_AX),%edx
21567 +
21568 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21569 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21570 + cmp %_ASM_DX,%_ASM_AX
21571 + jae 1234f
21572 + add %_ASM_DX,%_ASM_AX
21573 +1234:
21574 +#endif
21575 +
21576 +#endif
21577 +
21578 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21579 xor %eax,%eax
21580 + pax_force_retaddr
21581 ret
21582 CFI_ENDPROC
21583 ENDPROC(__get_user_1)
21584 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21585 ENTRY(__get_user_2)
21586 CFI_STARTPROC
21587 add $1,%_ASM_AX
21588 +
21589 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21590 jc bad_get_user
21591 GET_THREAD_INFO(%_ASM_DX)
21592 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21593 jae bad_get_user
21594 -2: movzwl -1(%_ASM_AX),%edx
21595 +
21596 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21597 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21598 + cmp %_ASM_DX,%_ASM_AX
21599 + jae 1234f
21600 + add %_ASM_DX,%_ASM_AX
21601 +1234:
21602 +#endif
21603 +
21604 +#endif
21605 +
21606 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21607 xor %eax,%eax
21608 + pax_force_retaddr
21609 ret
21610 CFI_ENDPROC
21611 ENDPROC(__get_user_2)
21612 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21613 ENTRY(__get_user_4)
21614 CFI_STARTPROC
21615 add $3,%_ASM_AX
21616 +
21617 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21618 jc bad_get_user
21619 GET_THREAD_INFO(%_ASM_DX)
21620 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21621 jae bad_get_user
21622 -3: mov -3(%_ASM_AX),%edx
21623 +
21624 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21625 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21626 + cmp %_ASM_DX,%_ASM_AX
21627 + jae 1234f
21628 + add %_ASM_DX,%_ASM_AX
21629 +1234:
21630 +#endif
21631 +
21632 +#endif
21633 +
21634 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21635 xor %eax,%eax
21636 + pax_force_retaddr
21637 ret
21638 CFI_ENDPROC
21639 ENDPROC(__get_user_4)
21640 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21641 GET_THREAD_INFO(%_ASM_DX)
21642 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21643 jae bad_get_user
21644 +
21645 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21646 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21647 + cmp %_ASM_DX,%_ASM_AX
21648 + jae 1234f
21649 + add %_ASM_DX,%_ASM_AX
21650 +1234:
21651 +#endif
21652 +
21653 4: movq -7(%_ASM_AX),%_ASM_DX
21654 xor %eax,%eax
21655 + pax_force_retaddr
21656 ret
21657 CFI_ENDPROC
21658 ENDPROC(__get_user_8)
21659 @@ -91,6 +152,7 @@ bad_get_user:
21660 CFI_STARTPROC
21661 xor %edx,%edx
21662 mov $(-EFAULT),%_ASM_AX
21663 + pax_force_retaddr
21664 ret
21665 CFI_ENDPROC
21666 END(bad_get_user)
21667 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21668 index 5a1f9f3..ba9f577 100644
21669 --- a/arch/x86/lib/insn.c
21670 +++ b/arch/x86/lib/insn.c
21671 @@ -21,6 +21,11 @@
21672 #include <linux/string.h>
21673 #include <asm/inat.h>
21674 #include <asm/insn.h>
21675 +#ifdef __KERNEL__
21676 +#include <asm/pgtable_types.h>
21677 +#else
21678 +#define ktla_ktva(addr) addr
21679 +#endif
21680
21681 /* Verify next sizeof(t) bytes can be on the same instruction */
21682 #define validate_next(t, insn, n) \
21683 @@ -49,8 +54,8 @@
21684 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21685 {
21686 memset(insn, 0, sizeof(*insn));
21687 - insn->kaddr = kaddr;
21688 - insn->next_byte = kaddr;
21689 + insn->kaddr = ktla_ktva(kaddr);
21690 + insn->next_byte = ktla_ktva(kaddr);
21691 insn->x86_64 = x86_64 ? 1 : 0;
21692 insn->opnd_bytes = 4;
21693 if (x86_64)
21694 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21695 index 05a95e7..326f2fa 100644
21696 --- a/arch/x86/lib/iomap_copy_64.S
21697 +++ b/arch/x86/lib/iomap_copy_64.S
21698 @@ -17,6 +17,7 @@
21699
21700 #include <linux/linkage.h>
21701 #include <asm/dwarf2.h>
21702 +#include <asm/alternative-asm.h>
21703
21704 /*
21705 * override generic version in lib/iomap_copy.c
21706 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21707 CFI_STARTPROC
21708 movl %edx,%ecx
21709 rep movsd
21710 + pax_force_retaddr
21711 ret
21712 CFI_ENDPROC
21713 ENDPROC(__iowrite32_copy)
21714 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21715 index efbf2a0..8893637 100644
21716 --- a/arch/x86/lib/memcpy_64.S
21717 +++ b/arch/x86/lib/memcpy_64.S
21718 @@ -34,6 +34,7 @@
21719 rep movsq
21720 movl %edx, %ecx
21721 rep movsb
21722 + pax_force_retaddr
21723 ret
21724 .Lmemcpy_e:
21725 .previous
21726 @@ -51,6 +52,7 @@
21727
21728 movl %edx, %ecx
21729 rep movsb
21730 + pax_force_retaddr
21731 ret
21732 .Lmemcpy_e_e:
21733 .previous
21734 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21735 */
21736 movq 0*8(%rsi), %r8
21737 movq 1*8(%rsi), %r9
21738 - movq 2*8(%rsi), %r10
21739 + movq 2*8(%rsi), %rcx
21740 movq 3*8(%rsi), %r11
21741 leaq 4*8(%rsi), %rsi
21742
21743 movq %r8, 0*8(%rdi)
21744 movq %r9, 1*8(%rdi)
21745 - movq %r10, 2*8(%rdi)
21746 + movq %rcx, 2*8(%rdi)
21747 movq %r11, 3*8(%rdi)
21748 leaq 4*8(%rdi), %rdi
21749 jae .Lcopy_forward_loop
21750 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21751 subq $0x20, %rdx
21752 movq -1*8(%rsi), %r8
21753 movq -2*8(%rsi), %r9
21754 - movq -3*8(%rsi), %r10
21755 + movq -3*8(%rsi), %rcx
21756 movq -4*8(%rsi), %r11
21757 leaq -4*8(%rsi), %rsi
21758 movq %r8, -1*8(%rdi)
21759 movq %r9, -2*8(%rdi)
21760 - movq %r10, -3*8(%rdi)
21761 + movq %rcx, -3*8(%rdi)
21762 movq %r11, -4*8(%rdi)
21763 leaq -4*8(%rdi), %rdi
21764 jae .Lcopy_backward_loop
21765 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21766 */
21767 movq 0*8(%rsi), %r8
21768 movq 1*8(%rsi), %r9
21769 - movq -2*8(%rsi, %rdx), %r10
21770 + movq -2*8(%rsi, %rdx), %rcx
21771 movq -1*8(%rsi, %rdx), %r11
21772 movq %r8, 0*8(%rdi)
21773 movq %r9, 1*8(%rdi)
21774 - movq %r10, -2*8(%rdi, %rdx)
21775 + movq %rcx, -2*8(%rdi, %rdx)
21776 movq %r11, -1*8(%rdi, %rdx)
21777 + pax_force_retaddr
21778 retq
21779 .p2align 4
21780 .Lless_16bytes:
21781 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21782 movq -1*8(%rsi, %rdx), %r9
21783 movq %r8, 0*8(%rdi)
21784 movq %r9, -1*8(%rdi, %rdx)
21785 + pax_force_retaddr
21786 retq
21787 .p2align 4
21788 .Lless_8bytes:
21789 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21790 movl -4(%rsi, %rdx), %r8d
21791 movl %ecx, (%rdi)
21792 movl %r8d, -4(%rdi, %rdx)
21793 + pax_force_retaddr
21794 retq
21795 .p2align 4
21796 .Lless_3bytes:
21797 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21798 jnz .Lloop_1
21799
21800 .Lend:
21801 + pax_force_retaddr
21802 retq
21803 CFI_ENDPROC
21804 ENDPROC(memcpy)
21805 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21806 index ee16461..c39c199 100644
21807 --- a/arch/x86/lib/memmove_64.S
21808 +++ b/arch/x86/lib/memmove_64.S
21809 @@ -61,13 +61,13 @@ ENTRY(memmove)
21810 5:
21811 sub $0x20, %rdx
21812 movq 0*8(%rsi), %r11
21813 - movq 1*8(%rsi), %r10
21814 + movq 1*8(%rsi), %rcx
21815 movq 2*8(%rsi), %r9
21816 movq 3*8(%rsi), %r8
21817 leaq 4*8(%rsi), %rsi
21818
21819 movq %r11, 0*8(%rdi)
21820 - movq %r10, 1*8(%rdi)
21821 + movq %rcx, 1*8(%rdi)
21822 movq %r9, 2*8(%rdi)
21823 movq %r8, 3*8(%rdi)
21824 leaq 4*8(%rdi), %rdi
21825 @@ -81,10 +81,10 @@ ENTRY(memmove)
21826 4:
21827 movq %rdx, %rcx
21828 movq -8(%rsi, %rdx), %r11
21829 - lea -8(%rdi, %rdx), %r10
21830 + lea -8(%rdi, %rdx), %r9
21831 shrq $3, %rcx
21832 rep movsq
21833 - movq %r11, (%r10)
21834 + movq %r11, (%r9)
21835 jmp 13f
21836 .Lmemmove_end_forward:
21837
21838 @@ -95,14 +95,14 @@ ENTRY(memmove)
21839 7:
21840 movq %rdx, %rcx
21841 movq (%rsi), %r11
21842 - movq %rdi, %r10
21843 + movq %rdi, %r9
21844 leaq -8(%rsi, %rdx), %rsi
21845 leaq -8(%rdi, %rdx), %rdi
21846 shrq $3, %rcx
21847 std
21848 rep movsq
21849 cld
21850 - movq %r11, (%r10)
21851 + movq %r11, (%r9)
21852 jmp 13f
21853
21854 /*
21855 @@ -127,13 +127,13 @@ ENTRY(memmove)
21856 8:
21857 subq $0x20, %rdx
21858 movq -1*8(%rsi), %r11
21859 - movq -2*8(%rsi), %r10
21860 + movq -2*8(%rsi), %rcx
21861 movq -3*8(%rsi), %r9
21862 movq -4*8(%rsi), %r8
21863 leaq -4*8(%rsi), %rsi
21864
21865 movq %r11, -1*8(%rdi)
21866 - movq %r10, -2*8(%rdi)
21867 + movq %rcx, -2*8(%rdi)
21868 movq %r9, -3*8(%rdi)
21869 movq %r8, -4*8(%rdi)
21870 leaq -4*8(%rdi), %rdi
21871 @@ -151,11 +151,11 @@ ENTRY(memmove)
21872 * Move data from 16 bytes to 31 bytes.
21873 */
21874 movq 0*8(%rsi), %r11
21875 - movq 1*8(%rsi), %r10
21876 + movq 1*8(%rsi), %rcx
21877 movq -2*8(%rsi, %rdx), %r9
21878 movq -1*8(%rsi, %rdx), %r8
21879 movq %r11, 0*8(%rdi)
21880 - movq %r10, 1*8(%rdi)
21881 + movq %rcx, 1*8(%rdi)
21882 movq %r9, -2*8(%rdi, %rdx)
21883 movq %r8, -1*8(%rdi, %rdx)
21884 jmp 13f
21885 @@ -167,9 +167,9 @@ ENTRY(memmove)
21886 * Move data from 8 bytes to 15 bytes.
21887 */
21888 movq 0*8(%rsi), %r11
21889 - movq -1*8(%rsi, %rdx), %r10
21890 + movq -1*8(%rsi, %rdx), %r9
21891 movq %r11, 0*8(%rdi)
21892 - movq %r10, -1*8(%rdi, %rdx)
21893 + movq %r9, -1*8(%rdi, %rdx)
21894 jmp 13f
21895 10:
21896 cmpq $4, %rdx
21897 @@ -178,9 +178,9 @@ ENTRY(memmove)
21898 * Move data from 4 bytes to 7 bytes.
21899 */
21900 movl (%rsi), %r11d
21901 - movl -4(%rsi, %rdx), %r10d
21902 + movl -4(%rsi, %rdx), %r9d
21903 movl %r11d, (%rdi)
21904 - movl %r10d, -4(%rdi, %rdx)
21905 + movl %r9d, -4(%rdi, %rdx)
21906 jmp 13f
21907 11:
21908 cmp $2, %rdx
21909 @@ -189,9 +189,9 @@ ENTRY(memmove)
21910 * Move data from 2 bytes to 3 bytes.
21911 */
21912 movw (%rsi), %r11w
21913 - movw -2(%rsi, %rdx), %r10w
21914 + movw -2(%rsi, %rdx), %r9w
21915 movw %r11w, (%rdi)
21916 - movw %r10w, -2(%rdi, %rdx)
21917 + movw %r9w, -2(%rdi, %rdx)
21918 jmp 13f
21919 12:
21920 cmp $1, %rdx
21921 @@ -202,6 +202,7 @@ ENTRY(memmove)
21922 movb (%rsi), %r11b
21923 movb %r11b, (%rdi)
21924 13:
21925 + pax_force_retaddr
21926 retq
21927 CFI_ENDPROC
21928
21929 @@ -210,6 +211,7 @@ ENTRY(memmove)
21930 /* Forward moving data. */
21931 movq %rdx, %rcx
21932 rep movsb
21933 + pax_force_retaddr
21934 retq
21935 .Lmemmove_end_forward_efs:
21936 .previous
21937 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21938 index 79bd454..dff325a 100644
21939 --- a/arch/x86/lib/memset_64.S
21940 +++ b/arch/x86/lib/memset_64.S
21941 @@ -31,6 +31,7 @@
21942 movl %r8d,%ecx
21943 rep stosb
21944 movq %r9,%rax
21945 + pax_force_retaddr
21946 ret
21947 .Lmemset_e:
21948 .previous
21949 @@ -53,6 +54,7 @@
21950 movl %edx,%ecx
21951 rep stosb
21952 movq %r9,%rax
21953 + pax_force_retaddr
21954 ret
21955 .Lmemset_e_e:
21956 .previous
21957 @@ -60,13 +62,13 @@
21958 ENTRY(memset)
21959 ENTRY(__memset)
21960 CFI_STARTPROC
21961 - movq %rdi,%r10
21962 movq %rdx,%r11
21963
21964 /* expand byte value */
21965 movzbl %sil,%ecx
21966 movabs $0x0101010101010101,%rax
21967 mul %rcx /* with rax, clobbers rdx */
21968 + movq %rdi,%rdx
21969
21970 /* align dst */
21971 movl %edi,%r9d
21972 @@ -120,7 +122,8 @@ ENTRY(__memset)
21973 jnz .Lloop_1
21974
21975 .Lende:
21976 - movq %r10,%rax
21977 + movq %rdx,%rax
21978 + pax_force_retaddr
21979 ret
21980
21981 CFI_RESTORE_STATE
21982 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21983 index c9f2d9b..e7fd2c0 100644
21984 --- a/arch/x86/lib/mmx_32.c
21985 +++ b/arch/x86/lib/mmx_32.c
21986 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21987 {
21988 void *p;
21989 int i;
21990 + unsigned long cr0;
21991
21992 if (unlikely(in_interrupt()))
21993 return __memcpy(to, from, len);
21994 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21995 kernel_fpu_begin();
21996
21997 __asm__ __volatile__ (
21998 - "1: prefetch (%0)\n" /* This set is 28 bytes */
21999 - " prefetch 64(%0)\n"
22000 - " prefetch 128(%0)\n"
22001 - " prefetch 192(%0)\n"
22002 - " prefetch 256(%0)\n"
22003 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22004 + " prefetch 64(%1)\n"
22005 + " prefetch 128(%1)\n"
22006 + " prefetch 192(%1)\n"
22007 + " prefetch 256(%1)\n"
22008 "2: \n"
22009 ".section .fixup, \"ax\"\n"
22010 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22011 + "3: \n"
22012 +
22013 +#ifdef CONFIG_PAX_KERNEXEC
22014 + " movl %%cr0, %0\n"
22015 + " movl %0, %%eax\n"
22016 + " andl $0xFFFEFFFF, %%eax\n"
22017 + " movl %%eax, %%cr0\n"
22018 +#endif
22019 +
22020 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22021 +
22022 +#ifdef CONFIG_PAX_KERNEXEC
22023 + " movl %0, %%cr0\n"
22024 +#endif
22025 +
22026 " jmp 2b\n"
22027 ".previous\n"
22028 _ASM_EXTABLE(1b, 3b)
22029 - : : "r" (from));
22030 + : "=&r" (cr0) : "r" (from) : "ax");
22031
22032 for ( ; i > 5; i--) {
22033 __asm__ __volatile__ (
22034 - "1: prefetch 320(%0)\n"
22035 - "2: movq (%0), %%mm0\n"
22036 - " movq 8(%0), %%mm1\n"
22037 - " movq 16(%0), %%mm2\n"
22038 - " movq 24(%0), %%mm3\n"
22039 - " movq %%mm0, (%1)\n"
22040 - " movq %%mm1, 8(%1)\n"
22041 - " movq %%mm2, 16(%1)\n"
22042 - " movq %%mm3, 24(%1)\n"
22043 - " movq 32(%0), %%mm0\n"
22044 - " movq 40(%0), %%mm1\n"
22045 - " movq 48(%0), %%mm2\n"
22046 - " movq 56(%0), %%mm3\n"
22047 - " movq %%mm0, 32(%1)\n"
22048 - " movq %%mm1, 40(%1)\n"
22049 - " movq %%mm2, 48(%1)\n"
22050 - " movq %%mm3, 56(%1)\n"
22051 + "1: prefetch 320(%1)\n"
22052 + "2: movq (%1), %%mm0\n"
22053 + " movq 8(%1), %%mm1\n"
22054 + " movq 16(%1), %%mm2\n"
22055 + " movq 24(%1), %%mm3\n"
22056 + " movq %%mm0, (%2)\n"
22057 + " movq %%mm1, 8(%2)\n"
22058 + " movq %%mm2, 16(%2)\n"
22059 + " movq %%mm3, 24(%2)\n"
22060 + " movq 32(%1), %%mm0\n"
22061 + " movq 40(%1), %%mm1\n"
22062 + " movq 48(%1), %%mm2\n"
22063 + " movq 56(%1), %%mm3\n"
22064 + " movq %%mm0, 32(%2)\n"
22065 + " movq %%mm1, 40(%2)\n"
22066 + " movq %%mm2, 48(%2)\n"
22067 + " movq %%mm3, 56(%2)\n"
22068 ".section .fixup, \"ax\"\n"
22069 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22070 + "3:\n"
22071 +
22072 +#ifdef CONFIG_PAX_KERNEXEC
22073 + " movl %%cr0, %0\n"
22074 + " movl %0, %%eax\n"
22075 + " andl $0xFFFEFFFF, %%eax\n"
22076 + " movl %%eax, %%cr0\n"
22077 +#endif
22078 +
22079 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22080 +
22081 +#ifdef CONFIG_PAX_KERNEXEC
22082 + " movl %0, %%cr0\n"
22083 +#endif
22084 +
22085 " jmp 2b\n"
22086 ".previous\n"
22087 _ASM_EXTABLE(1b, 3b)
22088 - : : "r" (from), "r" (to) : "memory");
22089 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22090
22091 from += 64;
22092 to += 64;
22093 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22094 static void fast_copy_page(void *to, void *from)
22095 {
22096 int i;
22097 + unsigned long cr0;
22098
22099 kernel_fpu_begin();
22100
22101 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22102 * but that is for later. -AV
22103 */
22104 __asm__ __volatile__(
22105 - "1: prefetch (%0)\n"
22106 - " prefetch 64(%0)\n"
22107 - " prefetch 128(%0)\n"
22108 - " prefetch 192(%0)\n"
22109 - " prefetch 256(%0)\n"
22110 + "1: prefetch (%1)\n"
22111 + " prefetch 64(%1)\n"
22112 + " prefetch 128(%1)\n"
22113 + " prefetch 192(%1)\n"
22114 + " prefetch 256(%1)\n"
22115 "2: \n"
22116 ".section .fixup, \"ax\"\n"
22117 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22118 + "3: \n"
22119 +
22120 +#ifdef CONFIG_PAX_KERNEXEC
22121 + " movl %%cr0, %0\n"
22122 + " movl %0, %%eax\n"
22123 + " andl $0xFFFEFFFF, %%eax\n"
22124 + " movl %%eax, %%cr0\n"
22125 +#endif
22126 +
22127 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22128 +
22129 +#ifdef CONFIG_PAX_KERNEXEC
22130 + " movl %0, %%cr0\n"
22131 +#endif
22132 +
22133 " jmp 2b\n"
22134 ".previous\n"
22135 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22136 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22137
22138 for (i = 0; i < (4096-320)/64; i++) {
22139 __asm__ __volatile__ (
22140 - "1: prefetch 320(%0)\n"
22141 - "2: movq (%0), %%mm0\n"
22142 - " movntq %%mm0, (%1)\n"
22143 - " movq 8(%0), %%mm1\n"
22144 - " movntq %%mm1, 8(%1)\n"
22145 - " movq 16(%0), %%mm2\n"
22146 - " movntq %%mm2, 16(%1)\n"
22147 - " movq 24(%0), %%mm3\n"
22148 - " movntq %%mm3, 24(%1)\n"
22149 - " movq 32(%0), %%mm4\n"
22150 - " movntq %%mm4, 32(%1)\n"
22151 - " movq 40(%0), %%mm5\n"
22152 - " movntq %%mm5, 40(%1)\n"
22153 - " movq 48(%0), %%mm6\n"
22154 - " movntq %%mm6, 48(%1)\n"
22155 - " movq 56(%0), %%mm7\n"
22156 - " movntq %%mm7, 56(%1)\n"
22157 + "1: prefetch 320(%1)\n"
22158 + "2: movq (%1), %%mm0\n"
22159 + " movntq %%mm0, (%2)\n"
22160 + " movq 8(%1), %%mm1\n"
22161 + " movntq %%mm1, 8(%2)\n"
22162 + " movq 16(%1), %%mm2\n"
22163 + " movntq %%mm2, 16(%2)\n"
22164 + " movq 24(%1), %%mm3\n"
22165 + " movntq %%mm3, 24(%2)\n"
22166 + " movq 32(%1), %%mm4\n"
22167 + " movntq %%mm4, 32(%2)\n"
22168 + " movq 40(%1), %%mm5\n"
22169 + " movntq %%mm5, 40(%2)\n"
22170 + " movq 48(%1), %%mm6\n"
22171 + " movntq %%mm6, 48(%2)\n"
22172 + " movq 56(%1), %%mm7\n"
22173 + " movntq %%mm7, 56(%2)\n"
22174 ".section .fixup, \"ax\"\n"
22175 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22176 + "3:\n"
22177 +
22178 +#ifdef CONFIG_PAX_KERNEXEC
22179 + " movl %%cr0, %0\n"
22180 + " movl %0, %%eax\n"
22181 + " andl $0xFFFEFFFF, %%eax\n"
22182 + " movl %%eax, %%cr0\n"
22183 +#endif
22184 +
22185 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22186 +
22187 +#ifdef CONFIG_PAX_KERNEXEC
22188 + " movl %0, %%cr0\n"
22189 +#endif
22190 +
22191 " jmp 2b\n"
22192 ".previous\n"
22193 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22194 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22195
22196 from += 64;
22197 to += 64;
22198 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22199 static void fast_copy_page(void *to, void *from)
22200 {
22201 int i;
22202 + unsigned long cr0;
22203
22204 kernel_fpu_begin();
22205
22206 __asm__ __volatile__ (
22207 - "1: prefetch (%0)\n"
22208 - " prefetch 64(%0)\n"
22209 - " prefetch 128(%0)\n"
22210 - " prefetch 192(%0)\n"
22211 - " prefetch 256(%0)\n"
22212 + "1: prefetch (%1)\n"
22213 + " prefetch 64(%1)\n"
22214 + " prefetch 128(%1)\n"
22215 + " prefetch 192(%1)\n"
22216 + " prefetch 256(%1)\n"
22217 "2: \n"
22218 ".section .fixup, \"ax\"\n"
22219 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22220 + "3: \n"
22221 +
22222 +#ifdef CONFIG_PAX_KERNEXEC
22223 + " movl %%cr0, %0\n"
22224 + " movl %0, %%eax\n"
22225 + " andl $0xFFFEFFFF, %%eax\n"
22226 + " movl %%eax, %%cr0\n"
22227 +#endif
22228 +
22229 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22230 +
22231 +#ifdef CONFIG_PAX_KERNEXEC
22232 + " movl %0, %%cr0\n"
22233 +#endif
22234 +
22235 " jmp 2b\n"
22236 ".previous\n"
22237 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22238 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22239
22240 for (i = 0; i < 4096/64; i++) {
22241 __asm__ __volatile__ (
22242 - "1: prefetch 320(%0)\n"
22243 - "2: movq (%0), %%mm0\n"
22244 - " movq 8(%0), %%mm1\n"
22245 - " movq 16(%0), %%mm2\n"
22246 - " movq 24(%0), %%mm3\n"
22247 - " movq %%mm0, (%1)\n"
22248 - " movq %%mm1, 8(%1)\n"
22249 - " movq %%mm2, 16(%1)\n"
22250 - " movq %%mm3, 24(%1)\n"
22251 - " movq 32(%0), %%mm0\n"
22252 - " movq 40(%0), %%mm1\n"
22253 - " movq 48(%0), %%mm2\n"
22254 - " movq 56(%0), %%mm3\n"
22255 - " movq %%mm0, 32(%1)\n"
22256 - " movq %%mm1, 40(%1)\n"
22257 - " movq %%mm2, 48(%1)\n"
22258 - " movq %%mm3, 56(%1)\n"
22259 + "1: prefetch 320(%1)\n"
22260 + "2: movq (%1), %%mm0\n"
22261 + " movq 8(%1), %%mm1\n"
22262 + " movq 16(%1), %%mm2\n"
22263 + " movq 24(%1), %%mm3\n"
22264 + " movq %%mm0, (%2)\n"
22265 + " movq %%mm1, 8(%2)\n"
22266 + " movq %%mm2, 16(%2)\n"
22267 + " movq %%mm3, 24(%2)\n"
22268 + " movq 32(%1), %%mm0\n"
22269 + " movq 40(%1), %%mm1\n"
22270 + " movq 48(%1), %%mm2\n"
22271 + " movq 56(%1), %%mm3\n"
22272 + " movq %%mm0, 32(%2)\n"
22273 + " movq %%mm1, 40(%2)\n"
22274 + " movq %%mm2, 48(%2)\n"
22275 + " movq %%mm3, 56(%2)\n"
22276 ".section .fixup, \"ax\"\n"
22277 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22278 + "3:\n"
22279 +
22280 +#ifdef CONFIG_PAX_KERNEXEC
22281 + " movl %%cr0, %0\n"
22282 + " movl %0, %%eax\n"
22283 + " andl $0xFFFEFFFF, %%eax\n"
22284 + " movl %%eax, %%cr0\n"
22285 +#endif
22286 +
22287 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22288 +
22289 +#ifdef CONFIG_PAX_KERNEXEC
22290 + " movl %0, %%cr0\n"
22291 +#endif
22292 +
22293 " jmp 2b\n"
22294 ".previous\n"
22295 _ASM_EXTABLE(1b, 3b)
22296 - : : "r" (from), "r" (to) : "memory");
22297 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22298
22299 from += 64;
22300 to += 64;
22301 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22302 index 69fa106..adda88b 100644
22303 --- a/arch/x86/lib/msr-reg.S
22304 +++ b/arch/x86/lib/msr-reg.S
22305 @@ -3,6 +3,7 @@
22306 #include <asm/dwarf2.h>
22307 #include <asm/asm.h>
22308 #include <asm/msr.h>
22309 +#include <asm/alternative-asm.h>
22310
22311 #ifdef CONFIG_X86_64
22312 /*
22313 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22314 CFI_STARTPROC
22315 pushq_cfi %rbx
22316 pushq_cfi %rbp
22317 - movq %rdi, %r10 /* Save pointer */
22318 + movq %rdi, %r9 /* Save pointer */
22319 xorl %r11d, %r11d /* Return value */
22320 movl (%rdi), %eax
22321 movl 4(%rdi), %ecx
22322 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22323 movl 28(%rdi), %edi
22324 CFI_REMEMBER_STATE
22325 1: \op
22326 -2: movl %eax, (%r10)
22327 +2: movl %eax, (%r9)
22328 movl %r11d, %eax /* Return value */
22329 - movl %ecx, 4(%r10)
22330 - movl %edx, 8(%r10)
22331 - movl %ebx, 12(%r10)
22332 - movl %ebp, 20(%r10)
22333 - movl %esi, 24(%r10)
22334 - movl %edi, 28(%r10)
22335 + movl %ecx, 4(%r9)
22336 + movl %edx, 8(%r9)
22337 + movl %ebx, 12(%r9)
22338 + movl %ebp, 20(%r9)
22339 + movl %esi, 24(%r9)
22340 + movl %edi, 28(%r9)
22341 popq_cfi %rbp
22342 popq_cfi %rbx
22343 + pax_force_retaddr
22344 ret
22345 3:
22346 CFI_RESTORE_STATE
22347 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22348 index 36b0d15..d381858 100644
22349 --- a/arch/x86/lib/putuser.S
22350 +++ b/arch/x86/lib/putuser.S
22351 @@ -15,7 +15,9 @@
22352 #include <asm/thread_info.h>
22353 #include <asm/errno.h>
22354 #include <asm/asm.h>
22355 -
22356 +#include <asm/segment.h>
22357 +#include <asm/pgtable.h>
22358 +#include <asm/alternative-asm.h>
22359
22360 /*
22361 * __put_user_X
22362 @@ -29,52 +31,119 @@
22363 * as they get called from within inline assembly.
22364 */
22365
22366 -#define ENTER CFI_STARTPROC ; \
22367 - GET_THREAD_INFO(%_ASM_BX)
22368 -#define EXIT ret ; \
22369 +#define ENTER CFI_STARTPROC
22370 +#define EXIT pax_force_retaddr; ret ; \
22371 CFI_ENDPROC
22372
22373 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22374 +#define _DEST %_ASM_CX,%_ASM_BX
22375 +#else
22376 +#define _DEST %_ASM_CX
22377 +#endif
22378 +
22379 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22380 +#define __copyuser_seg gs;
22381 +#else
22382 +#define __copyuser_seg
22383 +#endif
22384 +
22385 .text
22386 ENTRY(__put_user_1)
22387 ENTER
22388 +
22389 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22390 + GET_THREAD_INFO(%_ASM_BX)
22391 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22392 jae bad_put_user
22393 -1: movb %al,(%_ASM_CX)
22394 +
22395 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22396 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22397 + cmp %_ASM_BX,%_ASM_CX
22398 + jb 1234f
22399 + xor %ebx,%ebx
22400 +1234:
22401 +#endif
22402 +
22403 +#endif
22404 +
22405 +1: __copyuser_seg movb %al,(_DEST)
22406 xor %eax,%eax
22407 EXIT
22408 ENDPROC(__put_user_1)
22409
22410 ENTRY(__put_user_2)
22411 ENTER
22412 +
22413 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22414 + GET_THREAD_INFO(%_ASM_BX)
22415 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22416 sub $1,%_ASM_BX
22417 cmp %_ASM_BX,%_ASM_CX
22418 jae bad_put_user
22419 -2: movw %ax,(%_ASM_CX)
22420 +
22421 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22422 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22423 + cmp %_ASM_BX,%_ASM_CX
22424 + jb 1234f
22425 + xor %ebx,%ebx
22426 +1234:
22427 +#endif
22428 +
22429 +#endif
22430 +
22431 +2: __copyuser_seg movw %ax,(_DEST)
22432 xor %eax,%eax
22433 EXIT
22434 ENDPROC(__put_user_2)
22435
22436 ENTRY(__put_user_4)
22437 ENTER
22438 +
22439 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22440 + GET_THREAD_INFO(%_ASM_BX)
22441 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22442 sub $3,%_ASM_BX
22443 cmp %_ASM_BX,%_ASM_CX
22444 jae bad_put_user
22445 -3: movl %eax,(%_ASM_CX)
22446 +
22447 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22448 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22449 + cmp %_ASM_BX,%_ASM_CX
22450 + jb 1234f
22451 + xor %ebx,%ebx
22452 +1234:
22453 +#endif
22454 +
22455 +#endif
22456 +
22457 +3: __copyuser_seg movl %eax,(_DEST)
22458 xor %eax,%eax
22459 EXIT
22460 ENDPROC(__put_user_4)
22461
22462 ENTRY(__put_user_8)
22463 ENTER
22464 +
22465 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22466 + GET_THREAD_INFO(%_ASM_BX)
22467 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22468 sub $7,%_ASM_BX
22469 cmp %_ASM_BX,%_ASM_CX
22470 jae bad_put_user
22471 -4: mov %_ASM_AX,(%_ASM_CX)
22472 +
22473 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22474 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22475 + cmp %_ASM_BX,%_ASM_CX
22476 + jb 1234f
22477 + xor %ebx,%ebx
22478 +1234:
22479 +#endif
22480 +
22481 +#endif
22482 +
22483 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22484 #ifdef CONFIG_X86_32
22485 -5: movl %edx,4(%_ASM_CX)
22486 +5: __copyuser_seg movl %edx,4(_DEST)
22487 #endif
22488 xor %eax,%eax
22489 EXIT
22490 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22491 index 1cad221..de671ee 100644
22492 --- a/arch/x86/lib/rwlock.S
22493 +++ b/arch/x86/lib/rwlock.S
22494 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22495 FRAME
22496 0: LOCK_PREFIX
22497 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22498 +
22499 +#ifdef CONFIG_PAX_REFCOUNT
22500 + jno 1234f
22501 + LOCK_PREFIX
22502 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22503 + int $4
22504 +1234:
22505 + _ASM_EXTABLE(1234b, 1234b)
22506 +#endif
22507 +
22508 1: rep; nop
22509 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22510 jne 1b
22511 LOCK_PREFIX
22512 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22513 +
22514 +#ifdef CONFIG_PAX_REFCOUNT
22515 + jno 1234f
22516 + LOCK_PREFIX
22517 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22518 + int $4
22519 +1234:
22520 + _ASM_EXTABLE(1234b, 1234b)
22521 +#endif
22522 +
22523 jnz 0b
22524 ENDFRAME
22525 + pax_force_retaddr
22526 ret
22527 CFI_ENDPROC
22528 END(__write_lock_failed)
22529 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22530 FRAME
22531 0: LOCK_PREFIX
22532 READ_LOCK_SIZE(inc) (%__lock_ptr)
22533 +
22534 +#ifdef CONFIG_PAX_REFCOUNT
22535 + jno 1234f
22536 + LOCK_PREFIX
22537 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22538 + int $4
22539 +1234:
22540 + _ASM_EXTABLE(1234b, 1234b)
22541 +#endif
22542 +
22543 1: rep; nop
22544 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22545 js 1b
22546 LOCK_PREFIX
22547 READ_LOCK_SIZE(dec) (%__lock_ptr)
22548 +
22549 +#ifdef CONFIG_PAX_REFCOUNT
22550 + jno 1234f
22551 + LOCK_PREFIX
22552 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22553 + int $4
22554 +1234:
22555 + _ASM_EXTABLE(1234b, 1234b)
22556 +#endif
22557 +
22558 js 0b
22559 ENDFRAME
22560 + pax_force_retaddr
22561 ret
22562 CFI_ENDPROC
22563 END(__read_lock_failed)
22564 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22565 index 5dff5f0..cadebf4 100644
22566 --- a/arch/x86/lib/rwsem.S
22567 +++ b/arch/x86/lib/rwsem.S
22568 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22569 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22570 CFI_RESTORE __ASM_REG(dx)
22571 restore_common_regs
22572 + pax_force_retaddr
22573 ret
22574 CFI_ENDPROC
22575 ENDPROC(call_rwsem_down_read_failed)
22576 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22577 movq %rax,%rdi
22578 call rwsem_down_write_failed
22579 restore_common_regs
22580 + pax_force_retaddr
22581 ret
22582 CFI_ENDPROC
22583 ENDPROC(call_rwsem_down_write_failed)
22584 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22585 movq %rax,%rdi
22586 call rwsem_wake
22587 restore_common_regs
22588 -1: ret
22589 +1: pax_force_retaddr
22590 + ret
22591 CFI_ENDPROC
22592 ENDPROC(call_rwsem_wake)
22593
22594 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22595 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22596 CFI_RESTORE __ASM_REG(dx)
22597 restore_common_regs
22598 + pax_force_retaddr
22599 ret
22600 CFI_ENDPROC
22601 ENDPROC(call_rwsem_downgrade_wake)
22602 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22603 index a63efd6..ccecad8 100644
22604 --- a/arch/x86/lib/thunk_64.S
22605 +++ b/arch/x86/lib/thunk_64.S
22606 @@ -8,6 +8,7 @@
22607 #include <linux/linkage.h>
22608 #include <asm/dwarf2.h>
22609 #include <asm/calling.h>
22610 +#include <asm/alternative-asm.h>
22611
22612 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22613 .macro THUNK name, func, put_ret_addr_in_rdi=0
22614 @@ -41,5 +42,6 @@
22615 SAVE_ARGS
22616 restore:
22617 RESTORE_ARGS
22618 + pax_force_retaddr
22619 ret
22620 CFI_ENDPROC
22621 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22622 index e218d5d..a99a1eb 100644
22623 --- a/arch/x86/lib/usercopy_32.c
22624 +++ b/arch/x86/lib/usercopy_32.c
22625 @@ -43,7 +43,7 @@ do { \
22626 __asm__ __volatile__( \
22627 " testl %1,%1\n" \
22628 " jz 2f\n" \
22629 - "0: lodsb\n" \
22630 + "0: "__copyuser_seg"lodsb\n" \
22631 " stosb\n" \
22632 " testb %%al,%%al\n" \
22633 " jz 1f\n" \
22634 @@ -128,10 +128,12 @@ do { \
22635 int __d0; \
22636 might_fault(); \
22637 __asm__ __volatile__( \
22638 + __COPYUSER_SET_ES \
22639 "0: rep; stosl\n" \
22640 " movl %2,%0\n" \
22641 "1: rep; stosb\n" \
22642 "2:\n" \
22643 + __COPYUSER_RESTORE_ES \
22644 ".section .fixup,\"ax\"\n" \
22645 "3: lea 0(%2,%0,4),%0\n" \
22646 " jmp 2b\n" \
22647 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22648 might_fault();
22649
22650 __asm__ __volatile__(
22651 + __COPYUSER_SET_ES
22652 " testl %0, %0\n"
22653 " jz 3f\n"
22654 " andl %0,%%ecx\n"
22655 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22656 " subl %%ecx,%0\n"
22657 " addl %0,%%eax\n"
22658 "1:\n"
22659 + __COPYUSER_RESTORE_ES
22660 ".section .fixup,\"ax\"\n"
22661 "2: xorl %%eax,%%eax\n"
22662 " jmp 1b\n"
22663 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22664
22665 #ifdef CONFIG_X86_INTEL_USERCOPY
22666 static unsigned long
22667 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22668 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22669 {
22670 int d0, d1;
22671 __asm__ __volatile__(
22672 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22673 " .align 2,0x90\n"
22674 "3: movl 0(%4), %%eax\n"
22675 "4: movl 4(%4), %%edx\n"
22676 - "5: movl %%eax, 0(%3)\n"
22677 - "6: movl %%edx, 4(%3)\n"
22678 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22679 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22680 "7: movl 8(%4), %%eax\n"
22681 "8: movl 12(%4),%%edx\n"
22682 - "9: movl %%eax, 8(%3)\n"
22683 - "10: movl %%edx, 12(%3)\n"
22684 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22685 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22686 "11: movl 16(%4), %%eax\n"
22687 "12: movl 20(%4), %%edx\n"
22688 - "13: movl %%eax, 16(%3)\n"
22689 - "14: movl %%edx, 20(%3)\n"
22690 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22691 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22692 "15: movl 24(%4), %%eax\n"
22693 "16: movl 28(%4), %%edx\n"
22694 - "17: movl %%eax, 24(%3)\n"
22695 - "18: movl %%edx, 28(%3)\n"
22696 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22697 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22698 "19: movl 32(%4), %%eax\n"
22699 "20: movl 36(%4), %%edx\n"
22700 - "21: movl %%eax, 32(%3)\n"
22701 - "22: movl %%edx, 36(%3)\n"
22702 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22703 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22704 "23: movl 40(%4), %%eax\n"
22705 "24: movl 44(%4), %%edx\n"
22706 - "25: movl %%eax, 40(%3)\n"
22707 - "26: movl %%edx, 44(%3)\n"
22708 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22709 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22710 "27: movl 48(%4), %%eax\n"
22711 "28: movl 52(%4), %%edx\n"
22712 - "29: movl %%eax, 48(%3)\n"
22713 - "30: movl %%edx, 52(%3)\n"
22714 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22715 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22716 "31: movl 56(%4), %%eax\n"
22717 "32: movl 60(%4), %%edx\n"
22718 - "33: movl %%eax, 56(%3)\n"
22719 - "34: movl %%edx, 60(%3)\n"
22720 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22721 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22722 " addl $-64, %0\n"
22723 " addl $64, %4\n"
22724 " addl $64, %3\n"
22725 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22726 " shrl $2, %0\n"
22727 " andl $3, %%eax\n"
22728 " cld\n"
22729 + __COPYUSER_SET_ES
22730 "99: rep; movsl\n"
22731 "36: movl %%eax, %0\n"
22732 "37: rep; movsb\n"
22733 "100:\n"
22734 + __COPYUSER_RESTORE_ES
22735 ".section .fixup,\"ax\"\n"
22736 "101: lea 0(%%eax,%0,4),%0\n"
22737 " jmp 100b\n"
22738 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22739 }
22740
22741 static unsigned long
22742 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22743 +{
22744 + int d0, d1;
22745 + __asm__ __volatile__(
22746 + " .align 2,0x90\n"
22747 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22748 + " cmpl $67, %0\n"
22749 + " jbe 3f\n"
22750 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22751 + " .align 2,0x90\n"
22752 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22753 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22754 + "5: movl %%eax, 0(%3)\n"
22755 + "6: movl %%edx, 4(%3)\n"
22756 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22757 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22758 + "9: movl %%eax, 8(%3)\n"
22759 + "10: movl %%edx, 12(%3)\n"
22760 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22761 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22762 + "13: movl %%eax, 16(%3)\n"
22763 + "14: movl %%edx, 20(%3)\n"
22764 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22765 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22766 + "17: movl %%eax, 24(%3)\n"
22767 + "18: movl %%edx, 28(%3)\n"
22768 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22769 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22770 + "21: movl %%eax, 32(%3)\n"
22771 + "22: movl %%edx, 36(%3)\n"
22772 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22773 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22774 + "25: movl %%eax, 40(%3)\n"
22775 + "26: movl %%edx, 44(%3)\n"
22776 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22777 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22778 + "29: movl %%eax, 48(%3)\n"
22779 + "30: movl %%edx, 52(%3)\n"
22780 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22781 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22782 + "33: movl %%eax, 56(%3)\n"
22783 + "34: movl %%edx, 60(%3)\n"
22784 + " addl $-64, %0\n"
22785 + " addl $64, %4\n"
22786 + " addl $64, %3\n"
22787 + " cmpl $63, %0\n"
22788 + " ja 1b\n"
22789 + "35: movl %0, %%eax\n"
22790 + " shrl $2, %0\n"
22791 + " andl $3, %%eax\n"
22792 + " cld\n"
22793 + "99: rep; "__copyuser_seg" movsl\n"
22794 + "36: movl %%eax, %0\n"
22795 + "37: rep; "__copyuser_seg" movsb\n"
22796 + "100:\n"
22797 + ".section .fixup,\"ax\"\n"
22798 + "101: lea 0(%%eax,%0,4),%0\n"
22799 + " jmp 100b\n"
22800 + ".previous\n"
22801 + ".section __ex_table,\"a\"\n"
22802 + " .align 4\n"
22803 + " .long 1b,100b\n"
22804 + " .long 2b,100b\n"
22805 + " .long 3b,100b\n"
22806 + " .long 4b,100b\n"
22807 + " .long 5b,100b\n"
22808 + " .long 6b,100b\n"
22809 + " .long 7b,100b\n"
22810 + " .long 8b,100b\n"
22811 + " .long 9b,100b\n"
22812 + " .long 10b,100b\n"
22813 + " .long 11b,100b\n"
22814 + " .long 12b,100b\n"
22815 + " .long 13b,100b\n"
22816 + " .long 14b,100b\n"
22817 + " .long 15b,100b\n"
22818 + " .long 16b,100b\n"
22819 + " .long 17b,100b\n"
22820 + " .long 18b,100b\n"
22821 + " .long 19b,100b\n"
22822 + " .long 20b,100b\n"
22823 + " .long 21b,100b\n"
22824 + " .long 22b,100b\n"
22825 + " .long 23b,100b\n"
22826 + " .long 24b,100b\n"
22827 + " .long 25b,100b\n"
22828 + " .long 26b,100b\n"
22829 + " .long 27b,100b\n"
22830 + " .long 28b,100b\n"
22831 + " .long 29b,100b\n"
22832 + " .long 30b,100b\n"
22833 + " .long 31b,100b\n"
22834 + " .long 32b,100b\n"
22835 + " .long 33b,100b\n"
22836 + " .long 34b,100b\n"
22837 + " .long 35b,100b\n"
22838 + " .long 36b,100b\n"
22839 + " .long 37b,100b\n"
22840 + " .long 99b,101b\n"
22841 + ".previous"
22842 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22843 + : "1"(to), "2"(from), "0"(size)
22844 + : "eax", "edx", "memory");
22845 + return size;
22846 +}
22847 +
22848 +static unsigned long
22849 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22850 +static unsigned long
22851 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22852 {
22853 int d0, d1;
22854 __asm__ __volatile__(
22855 " .align 2,0x90\n"
22856 - "0: movl 32(%4), %%eax\n"
22857 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22858 " cmpl $67, %0\n"
22859 " jbe 2f\n"
22860 - "1: movl 64(%4), %%eax\n"
22861 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22862 " .align 2,0x90\n"
22863 - "2: movl 0(%4), %%eax\n"
22864 - "21: movl 4(%4), %%edx\n"
22865 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22866 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22867 " movl %%eax, 0(%3)\n"
22868 " movl %%edx, 4(%3)\n"
22869 - "3: movl 8(%4), %%eax\n"
22870 - "31: movl 12(%4),%%edx\n"
22871 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22872 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22873 " movl %%eax, 8(%3)\n"
22874 " movl %%edx, 12(%3)\n"
22875 - "4: movl 16(%4), %%eax\n"
22876 - "41: movl 20(%4), %%edx\n"
22877 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22878 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22879 " movl %%eax, 16(%3)\n"
22880 " movl %%edx, 20(%3)\n"
22881 - "10: movl 24(%4), %%eax\n"
22882 - "51: movl 28(%4), %%edx\n"
22883 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22884 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22885 " movl %%eax, 24(%3)\n"
22886 " movl %%edx, 28(%3)\n"
22887 - "11: movl 32(%4), %%eax\n"
22888 - "61: movl 36(%4), %%edx\n"
22889 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22890 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22891 " movl %%eax, 32(%3)\n"
22892 " movl %%edx, 36(%3)\n"
22893 - "12: movl 40(%4), %%eax\n"
22894 - "71: movl 44(%4), %%edx\n"
22895 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22896 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22897 " movl %%eax, 40(%3)\n"
22898 " movl %%edx, 44(%3)\n"
22899 - "13: movl 48(%4), %%eax\n"
22900 - "81: movl 52(%4), %%edx\n"
22901 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22902 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22903 " movl %%eax, 48(%3)\n"
22904 " movl %%edx, 52(%3)\n"
22905 - "14: movl 56(%4), %%eax\n"
22906 - "91: movl 60(%4), %%edx\n"
22907 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22908 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22909 " movl %%eax, 56(%3)\n"
22910 " movl %%edx, 60(%3)\n"
22911 " addl $-64, %0\n"
22912 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22913 " shrl $2, %0\n"
22914 " andl $3, %%eax\n"
22915 " cld\n"
22916 - "6: rep; movsl\n"
22917 + "6: rep; "__copyuser_seg" movsl\n"
22918 " movl %%eax,%0\n"
22919 - "7: rep; movsb\n"
22920 + "7: rep; "__copyuser_seg" movsb\n"
22921 "8:\n"
22922 ".section .fixup,\"ax\"\n"
22923 "9: lea 0(%%eax,%0,4),%0\n"
22924 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22925 */
22926
22927 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22928 + const void __user *from, unsigned long size) __size_overflow(3);
22929 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22930 const void __user *from, unsigned long size)
22931 {
22932 int d0, d1;
22933
22934 __asm__ __volatile__(
22935 " .align 2,0x90\n"
22936 - "0: movl 32(%4), %%eax\n"
22937 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22938 " cmpl $67, %0\n"
22939 " jbe 2f\n"
22940 - "1: movl 64(%4), %%eax\n"
22941 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22942 " .align 2,0x90\n"
22943 - "2: movl 0(%4), %%eax\n"
22944 - "21: movl 4(%4), %%edx\n"
22945 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22946 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22947 " movnti %%eax, 0(%3)\n"
22948 " movnti %%edx, 4(%3)\n"
22949 - "3: movl 8(%4), %%eax\n"
22950 - "31: movl 12(%4),%%edx\n"
22951 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22952 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22953 " movnti %%eax, 8(%3)\n"
22954 " movnti %%edx, 12(%3)\n"
22955 - "4: movl 16(%4), %%eax\n"
22956 - "41: movl 20(%4), %%edx\n"
22957 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22958 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22959 " movnti %%eax, 16(%3)\n"
22960 " movnti %%edx, 20(%3)\n"
22961 - "10: movl 24(%4), %%eax\n"
22962 - "51: movl 28(%4), %%edx\n"
22963 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22964 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22965 " movnti %%eax, 24(%3)\n"
22966 " movnti %%edx, 28(%3)\n"
22967 - "11: movl 32(%4), %%eax\n"
22968 - "61: movl 36(%4), %%edx\n"
22969 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22970 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22971 " movnti %%eax, 32(%3)\n"
22972 " movnti %%edx, 36(%3)\n"
22973 - "12: movl 40(%4), %%eax\n"
22974 - "71: movl 44(%4), %%edx\n"
22975 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22976 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22977 " movnti %%eax, 40(%3)\n"
22978 " movnti %%edx, 44(%3)\n"
22979 - "13: movl 48(%4), %%eax\n"
22980 - "81: movl 52(%4), %%edx\n"
22981 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22982 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22983 " movnti %%eax, 48(%3)\n"
22984 " movnti %%edx, 52(%3)\n"
22985 - "14: movl 56(%4), %%eax\n"
22986 - "91: movl 60(%4), %%edx\n"
22987 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22988 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22989 " movnti %%eax, 56(%3)\n"
22990 " movnti %%edx, 60(%3)\n"
22991 " addl $-64, %0\n"
22992 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22993 " shrl $2, %0\n"
22994 " andl $3, %%eax\n"
22995 " cld\n"
22996 - "6: rep; movsl\n"
22997 + "6: rep; "__copyuser_seg" movsl\n"
22998 " movl %%eax,%0\n"
22999 - "7: rep; movsb\n"
23000 + "7: rep; "__copyuser_seg" movsb\n"
23001 "8:\n"
23002 ".section .fixup,\"ax\"\n"
23003 "9: lea 0(%%eax,%0,4),%0\n"
23004 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23005 }
23006
23007 static unsigned long __copy_user_intel_nocache(void *to,
23008 + const void __user *from, unsigned long size) __size_overflow(3);
23009 +static unsigned long __copy_user_intel_nocache(void *to,
23010 const void __user *from, unsigned long size)
23011 {
23012 int d0, d1;
23013
23014 __asm__ __volatile__(
23015 " .align 2,0x90\n"
23016 - "0: movl 32(%4), %%eax\n"
23017 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23018 " cmpl $67, %0\n"
23019 " jbe 2f\n"
23020 - "1: movl 64(%4), %%eax\n"
23021 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23022 " .align 2,0x90\n"
23023 - "2: movl 0(%4), %%eax\n"
23024 - "21: movl 4(%4), %%edx\n"
23025 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23026 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23027 " movnti %%eax, 0(%3)\n"
23028 " movnti %%edx, 4(%3)\n"
23029 - "3: movl 8(%4), %%eax\n"
23030 - "31: movl 12(%4),%%edx\n"
23031 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23032 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23033 " movnti %%eax, 8(%3)\n"
23034 " movnti %%edx, 12(%3)\n"
23035 - "4: movl 16(%4), %%eax\n"
23036 - "41: movl 20(%4), %%edx\n"
23037 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23038 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23039 " movnti %%eax, 16(%3)\n"
23040 " movnti %%edx, 20(%3)\n"
23041 - "10: movl 24(%4), %%eax\n"
23042 - "51: movl 28(%4), %%edx\n"
23043 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23044 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23045 " movnti %%eax, 24(%3)\n"
23046 " movnti %%edx, 28(%3)\n"
23047 - "11: movl 32(%4), %%eax\n"
23048 - "61: movl 36(%4), %%edx\n"
23049 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23050 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23051 " movnti %%eax, 32(%3)\n"
23052 " movnti %%edx, 36(%3)\n"
23053 - "12: movl 40(%4), %%eax\n"
23054 - "71: movl 44(%4), %%edx\n"
23055 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23056 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23057 " movnti %%eax, 40(%3)\n"
23058 " movnti %%edx, 44(%3)\n"
23059 - "13: movl 48(%4), %%eax\n"
23060 - "81: movl 52(%4), %%edx\n"
23061 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23062 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23063 " movnti %%eax, 48(%3)\n"
23064 " movnti %%edx, 52(%3)\n"
23065 - "14: movl 56(%4), %%eax\n"
23066 - "91: movl 60(%4), %%edx\n"
23067 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23068 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23069 " movnti %%eax, 56(%3)\n"
23070 " movnti %%edx, 60(%3)\n"
23071 " addl $-64, %0\n"
23072 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23073 " shrl $2, %0\n"
23074 " andl $3, %%eax\n"
23075 " cld\n"
23076 - "6: rep; movsl\n"
23077 + "6: rep; "__copyuser_seg" movsl\n"
23078 " movl %%eax,%0\n"
23079 - "7: rep; movsb\n"
23080 + "7: rep; "__copyuser_seg" movsb\n"
23081 "8:\n"
23082 ".section .fixup,\"ax\"\n"
23083 "9: lea 0(%%eax,%0,4),%0\n"
23084 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23085 */
23086 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23087 unsigned long size);
23088 -unsigned long __copy_user_intel(void __user *to, const void *from,
23089 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23090 + unsigned long size);
23091 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23092 unsigned long size);
23093 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23094 const void __user *from, unsigned long size);
23095 #endif /* CONFIG_X86_INTEL_USERCOPY */
23096
23097 /* Generic arbitrary sized copy. */
23098 -#define __copy_user(to, from, size) \
23099 +#define __copy_user(to, from, size, prefix, set, restore) \
23100 do { \
23101 int __d0, __d1, __d2; \
23102 __asm__ __volatile__( \
23103 + set \
23104 " cmp $7,%0\n" \
23105 " jbe 1f\n" \
23106 " movl %1,%0\n" \
23107 " negl %0\n" \
23108 " andl $7,%0\n" \
23109 " subl %0,%3\n" \
23110 - "4: rep; movsb\n" \
23111 + "4: rep; "prefix"movsb\n" \
23112 " movl %3,%0\n" \
23113 " shrl $2,%0\n" \
23114 " andl $3,%3\n" \
23115 " .align 2,0x90\n" \
23116 - "0: rep; movsl\n" \
23117 + "0: rep; "prefix"movsl\n" \
23118 " movl %3,%0\n" \
23119 - "1: rep; movsb\n" \
23120 + "1: rep; "prefix"movsb\n" \
23121 "2:\n" \
23122 + restore \
23123 ".section .fixup,\"ax\"\n" \
23124 "5: addl %3,%0\n" \
23125 " jmp 2b\n" \
23126 @@ -682,14 +805,14 @@ do { \
23127 " negl %0\n" \
23128 " andl $7,%0\n" \
23129 " subl %0,%3\n" \
23130 - "4: rep; movsb\n" \
23131 + "4: rep; "__copyuser_seg"movsb\n" \
23132 " movl %3,%0\n" \
23133 " shrl $2,%0\n" \
23134 " andl $3,%3\n" \
23135 " .align 2,0x90\n" \
23136 - "0: rep; movsl\n" \
23137 + "0: rep; "__copyuser_seg"movsl\n" \
23138 " movl %3,%0\n" \
23139 - "1: rep; movsb\n" \
23140 + "1: rep; "__copyuser_seg"movsb\n" \
23141 "2:\n" \
23142 ".section .fixup,\"ax\"\n" \
23143 "5: addl %3,%0\n" \
23144 @@ -775,9 +898,9 @@ survive:
23145 }
23146 #endif
23147 if (movsl_is_ok(to, from, n))
23148 - __copy_user(to, from, n);
23149 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23150 else
23151 - n = __copy_user_intel(to, from, n);
23152 + n = __generic_copy_to_user_intel(to, from, n);
23153 return n;
23154 }
23155 EXPORT_SYMBOL(__copy_to_user_ll);
23156 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23157 unsigned long n)
23158 {
23159 if (movsl_is_ok(to, from, n))
23160 - __copy_user(to, from, n);
23161 + __copy_user(to, from, n, __copyuser_seg, "", "");
23162 else
23163 - n = __copy_user_intel((void __user *)to,
23164 - (const void *)from, n);
23165 + n = __generic_copy_from_user_intel(to, from, n);
23166 return n;
23167 }
23168 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23169 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23170 if (n > 64 && cpu_has_xmm2)
23171 n = __copy_user_intel_nocache(to, from, n);
23172 else
23173 - __copy_user(to, from, n);
23174 + __copy_user(to, from, n, __copyuser_seg, "", "");
23175 #else
23176 - __copy_user(to, from, n);
23177 + __copy_user(to, from, n, __copyuser_seg, "", "");
23178 #endif
23179 return n;
23180 }
23181 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23182
23183 -/**
23184 - * copy_to_user: - Copy a block of data into user space.
23185 - * @to: Destination address, in user space.
23186 - * @from: Source address, in kernel space.
23187 - * @n: Number of bytes to copy.
23188 - *
23189 - * Context: User context only. This function may sleep.
23190 - *
23191 - * Copy data from kernel space to user space.
23192 - *
23193 - * Returns number of bytes that could not be copied.
23194 - * On success, this will be zero.
23195 - */
23196 -unsigned long
23197 -copy_to_user(void __user *to, const void *from, unsigned long n)
23198 -{
23199 - if (access_ok(VERIFY_WRITE, to, n))
23200 - n = __copy_to_user(to, from, n);
23201 - return n;
23202 -}
23203 -EXPORT_SYMBOL(copy_to_user);
23204 -
23205 -/**
23206 - * copy_from_user: - Copy a block of data from user space.
23207 - * @to: Destination address, in kernel space.
23208 - * @from: Source address, in user space.
23209 - * @n: Number of bytes to copy.
23210 - *
23211 - * Context: User context only. This function may sleep.
23212 - *
23213 - * Copy data from user space to kernel space.
23214 - *
23215 - * Returns number of bytes that could not be copied.
23216 - * On success, this will be zero.
23217 - *
23218 - * If some data could not be copied, this function will pad the copied
23219 - * data to the requested size using zero bytes.
23220 - */
23221 -unsigned long
23222 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23223 -{
23224 - if (access_ok(VERIFY_READ, from, n))
23225 - n = __copy_from_user(to, from, n);
23226 - else
23227 - memset(to, 0, n);
23228 - return n;
23229 -}
23230 -EXPORT_SYMBOL(_copy_from_user);
23231 -
23232 void copy_from_user_overflow(void)
23233 {
23234 WARN(1, "Buffer overflow detected!\n");
23235 }
23236 EXPORT_SYMBOL(copy_from_user_overflow);
23237 +
23238 +void copy_to_user_overflow(void)
23239 +{
23240 + WARN(1, "Buffer overflow detected!\n");
23241 +}
23242 +EXPORT_SYMBOL(copy_to_user_overflow);
23243 +
23244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23245 +void __set_fs(mm_segment_t x)
23246 +{
23247 + switch (x.seg) {
23248 + case 0:
23249 + loadsegment(gs, 0);
23250 + break;
23251 + case TASK_SIZE_MAX:
23252 + loadsegment(gs, __USER_DS);
23253 + break;
23254 + case -1UL:
23255 + loadsegment(gs, __KERNEL_DS);
23256 + break;
23257 + default:
23258 + BUG();
23259 + }
23260 + return;
23261 +}
23262 +EXPORT_SYMBOL(__set_fs);
23263 +
23264 +void set_fs(mm_segment_t x)
23265 +{
23266 + current_thread_info()->addr_limit = x;
23267 + __set_fs(x);
23268 +}
23269 +EXPORT_SYMBOL(set_fs);
23270 +#endif
23271 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23272 index b7c2849..8633ad8 100644
23273 --- a/arch/x86/lib/usercopy_64.c
23274 +++ b/arch/x86/lib/usercopy_64.c
23275 @@ -42,6 +42,12 @@ long
23276 __strncpy_from_user(char *dst, const char __user *src, long count)
23277 {
23278 long res;
23279 +
23280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23281 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23282 + src += PAX_USER_SHADOW_BASE;
23283 +#endif
23284 +
23285 __do_strncpy_from_user(dst, src, count, res);
23286 return res;
23287 }
23288 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23289 {
23290 long __d0;
23291 might_fault();
23292 +
23293 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23294 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23295 + addr += PAX_USER_SHADOW_BASE;
23296 +#endif
23297 +
23298 /* no memory constraint because it doesn't change any memory gcc knows
23299 about */
23300 asm volatile(
23301 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23302 }
23303 EXPORT_SYMBOL(strlen_user);
23304
23305 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23306 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23307 {
23308 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23309 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23310 - }
23311 - return len;
23312 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23313 +
23314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23315 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23316 + to += PAX_USER_SHADOW_BASE;
23317 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23318 + from += PAX_USER_SHADOW_BASE;
23319 +#endif
23320 +
23321 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23322 + }
23323 + return len;
23324 }
23325 EXPORT_SYMBOL(copy_in_user);
23326
23327 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23328 * it is not necessary to optimize tail handling.
23329 */
23330 unsigned long
23331 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23332 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23333 {
23334 char c;
23335 unsigned zero_len;
23336 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23337 index 1fb85db..8b3540b 100644
23338 --- a/arch/x86/mm/extable.c
23339 +++ b/arch/x86/mm/extable.c
23340 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23341 const struct exception_table_entry *fixup;
23342
23343 #ifdef CONFIG_PNPBIOS
23344 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23345 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23346 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23347 extern u32 pnp_bios_is_utter_crap;
23348 pnp_bios_is_utter_crap = 1;
23349 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23350 index f0b4caf..d92fd42 100644
23351 --- a/arch/x86/mm/fault.c
23352 +++ b/arch/x86/mm/fault.c
23353 @@ -13,11 +13,18 @@
23354 #include <linux/perf_event.h> /* perf_sw_event */
23355 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23356 #include <linux/prefetch.h> /* prefetchw */
23357 +#include <linux/unistd.h>
23358 +#include <linux/compiler.h>
23359
23360 #include <asm/traps.h> /* dotraplinkage, ... */
23361 #include <asm/pgalloc.h> /* pgd_*(), ... */
23362 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23363 #include <asm/fixmap.h> /* VSYSCALL_START */
23364 +#include <asm/tlbflush.h>
23365 +
23366 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23367 +#include <asm/stacktrace.h>
23368 +#endif
23369
23370 /*
23371 * Page fault error code bits:
23372 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23373 int ret = 0;
23374
23375 /* kprobe_running() needs smp_processor_id() */
23376 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23377 + if (kprobes_built_in() && !user_mode(regs)) {
23378 preempt_disable();
23379 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23380 ret = 1;
23381 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23382 return !instr_lo || (instr_lo>>1) == 1;
23383 case 0x00:
23384 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23385 - if (probe_kernel_address(instr, opcode))
23386 + if (user_mode(regs)) {
23387 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23388 + return 0;
23389 + } else if (probe_kernel_address(instr, opcode))
23390 return 0;
23391
23392 *prefetch = (instr_lo == 0xF) &&
23393 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23394 while (instr < max_instr) {
23395 unsigned char opcode;
23396
23397 - if (probe_kernel_address(instr, opcode))
23398 + if (user_mode(regs)) {
23399 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23400 + break;
23401 + } else if (probe_kernel_address(instr, opcode))
23402 break;
23403
23404 instr++;
23405 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23406 force_sig_info(si_signo, &info, tsk);
23407 }
23408
23409 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23410 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23411 +#endif
23412 +
23413 +#ifdef CONFIG_PAX_EMUTRAMP
23414 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23415 +#endif
23416 +
23417 +#ifdef CONFIG_PAX_PAGEEXEC
23418 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23419 +{
23420 + pgd_t *pgd;
23421 + pud_t *pud;
23422 + pmd_t *pmd;
23423 +
23424 + pgd = pgd_offset(mm, address);
23425 + if (!pgd_present(*pgd))
23426 + return NULL;
23427 + pud = pud_offset(pgd, address);
23428 + if (!pud_present(*pud))
23429 + return NULL;
23430 + pmd = pmd_offset(pud, address);
23431 + if (!pmd_present(*pmd))
23432 + return NULL;
23433 + return pmd;
23434 +}
23435 +#endif
23436 +
23437 DEFINE_SPINLOCK(pgd_lock);
23438 LIST_HEAD(pgd_list);
23439
23440 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23441 for (address = VMALLOC_START & PMD_MASK;
23442 address >= TASK_SIZE && address < FIXADDR_TOP;
23443 address += PMD_SIZE) {
23444 +
23445 +#ifdef CONFIG_PAX_PER_CPU_PGD
23446 + unsigned long cpu;
23447 +#else
23448 struct page *page;
23449 +#endif
23450
23451 spin_lock(&pgd_lock);
23452 +
23453 +#ifdef CONFIG_PAX_PER_CPU_PGD
23454 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23455 + pgd_t *pgd = get_cpu_pgd(cpu);
23456 + pmd_t *ret;
23457 +#else
23458 list_for_each_entry(page, &pgd_list, lru) {
23459 + pgd_t *pgd = page_address(page);
23460 spinlock_t *pgt_lock;
23461 pmd_t *ret;
23462
23463 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23464 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23465
23466 spin_lock(pgt_lock);
23467 - ret = vmalloc_sync_one(page_address(page), address);
23468 +#endif
23469 +
23470 + ret = vmalloc_sync_one(pgd, address);
23471 +
23472 +#ifndef CONFIG_PAX_PER_CPU_PGD
23473 spin_unlock(pgt_lock);
23474 +#endif
23475
23476 if (!ret)
23477 break;
23478 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23479 * an interrupt in the middle of a task switch..
23480 */
23481 pgd_paddr = read_cr3();
23482 +
23483 +#ifdef CONFIG_PAX_PER_CPU_PGD
23484 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23485 +#endif
23486 +
23487 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23488 if (!pmd_k)
23489 return -1;
23490 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23491 * happen within a race in page table update. In the later
23492 * case just flush:
23493 */
23494 +
23495 +#ifdef CONFIG_PAX_PER_CPU_PGD
23496 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23497 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23498 +#else
23499 pgd = pgd_offset(current->active_mm, address);
23500 +#endif
23501 +
23502 pgd_ref = pgd_offset_k(address);
23503 if (pgd_none(*pgd_ref))
23504 return -1;
23505 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23506 static int is_errata100(struct pt_regs *regs, unsigned long address)
23507 {
23508 #ifdef CONFIG_X86_64
23509 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23510 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23511 return 1;
23512 #endif
23513 return 0;
23514 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23515 }
23516
23517 static const char nx_warning[] = KERN_CRIT
23518 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23519 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23520
23521 static void
23522 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23523 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23524 if (!oops_may_print())
23525 return;
23526
23527 - if (error_code & PF_INSTR) {
23528 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23529 unsigned int level;
23530
23531 pte_t *pte = lookup_address(address, &level);
23532
23533 if (pte && pte_present(*pte) && !pte_exec(*pte))
23534 - printk(nx_warning, current_uid());
23535 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23536 }
23537
23538 +#ifdef CONFIG_PAX_KERNEXEC
23539 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23540 + if (current->signal->curr_ip)
23541 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23542 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23543 + else
23544 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23545 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23546 + }
23547 +#endif
23548 +
23549 printk(KERN_ALERT "BUG: unable to handle kernel ");
23550 if (address < PAGE_SIZE)
23551 printk(KERN_CONT "NULL pointer dereference");
23552 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23553 }
23554 #endif
23555
23556 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23557 + if (pax_is_fetch_fault(regs, error_code, address)) {
23558 +
23559 +#ifdef CONFIG_PAX_EMUTRAMP
23560 + switch (pax_handle_fetch_fault(regs)) {
23561 + case 2:
23562 + return;
23563 + }
23564 +#endif
23565 +
23566 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23567 + do_group_exit(SIGKILL);
23568 + }
23569 +#endif
23570 +
23571 if (unlikely(show_unhandled_signals))
23572 show_signal_msg(regs, error_code, address, tsk);
23573
23574 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23575 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23576 printk(KERN_ERR
23577 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23578 - tsk->comm, tsk->pid, address);
23579 + tsk->comm, task_pid_nr(tsk), address);
23580 code = BUS_MCEERR_AR;
23581 }
23582 #endif
23583 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23584 return 1;
23585 }
23586
23587 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23588 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23589 +{
23590 + pte_t *pte;
23591 + pmd_t *pmd;
23592 + spinlock_t *ptl;
23593 + unsigned char pte_mask;
23594 +
23595 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23596 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23597 + return 0;
23598 +
23599 + /* PaX: it's our fault, let's handle it if we can */
23600 +
23601 + /* PaX: take a look at read faults before acquiring any locks */
23602 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23603 + /* instruction fetch attempt from a protected page in user mode */
23604 + up_read(&mm->mmap_sem);
23605 +
23606 +#ifdef CONFIG_PAX_EMUTRAMP
23607 + switch (pax_handle_fetch_fault(regs)) {
23608 + case 2:
23609 + return 1;
23610 + }
23611 +#endif
23612 +
23613 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23614 + do_group_exit(SIGKILL);
23615 + }
23616 +
23617 + pmd = pax_get_pmd(mm, address);
23618 + if (unlikely(!pmd))
23619 + return 0;
23620 +
23621 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23622 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23623 + pte_unmap_unlock(pte, ptl);
23624 + return 0;
23625 + }
23626 +
23627 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23628 + /* write attempt to a protected page in user mode */
23629 + pte_unmap_unlock(pte, ptl);
23630 + return 0;
23631 + }
23632 +
23633 +#ifdef CONFIG_SMP
23634 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23635 +#else
23636 + if (likely(address > get_limit(regs->cs)))
23637 +#endif
23638 + {
23639 + set_pte(pte, pte_mkread(*pte));
23640 + __flush_tlb_one(address);
23641 + pte_unmap_unlock(pte, ptl);
23642 + up_read(&mm->mmap_sem);
23643 + return 1;
23644 + }
23645 +
23646 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23647 +
23648 + /*
23649 + * PaX: fill DTLB with user rights and retry
23650 + */
23651 + __asm__ __volatile__ (
23652 + "orb %2,(%1)\n"
23653 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23654 +/*
23655 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23656 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23657 + * page fault when examined during a TLB load attempt. this is true not only
23658 + * for PTEs holding a non-present entry but also present entries that will
23659 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23660 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23661 + * for our target pages since their PTEs are simply not in the TLBs at all.
23662 +
23663 + * the best thing in omitting it is that we gain around 15-20% speed in the
23664 + * fast path of the page fault handler and can get rid of tracing since we
23665 + * can no longer flush unintended entries.
23666 + */
23667 + "invlpg (%0)\n"
23668 +#endif
23669 + __copyuser_seg"testb $0,(%0)\n"
23670 + "xorb %3,(%1)\n"
23671 + :
23672 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23673 + : "memory", "cc");
23674 + pte_unmap_unlock(pte, ptl);
23675 + up_read(&mm->mmap_sem);
23676 + return 1;
23677 +}
23678 +#endif
23679 +
23680 /*
23681 * Handle a spurious fault caused by a stale TLB entry.
23682 *
23683 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23684 static inline int
23685 access_error(unsigned long error_code, struct vm_area_struct *vma)
23686 {
23687 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23688 + return 1;
23689 +
23690 if (error_code & PF_WRITE) {
23691 /* write, present and write, not present: */
23692 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23693 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23694 {
23695 struct vm_area_struct *vma;
23696 struct task_struct *tsk;
23697 - unsigned long address;
23698 struct mm_struct *mm;
23699 int fault;
23700 int write = error_code & PF_WRITE;
23701 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23702 (write ? FAULT_FLAG_WRITE : 0);
23703
23704 - tsk = current;
23705 - mm = tsk->mm;
23706 -
23707 /* Get the faulting address: */
23708 - address = read_cr2();
23709 + unsigned long address = read_cr2();
23710 +
23711 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23712 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23713 + if (!search_exception_tables(regs->ip)) {
23714 + bad_area_nosemaphore(regs, error_code, address);
23715 + return;
23716 + }
23717 + if (address < PAX_USER_SHADOW_BASE) {
23718 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23719 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23720 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23721 + } else
23722 + address -= PAX_USER_SHADOW_BASE;
23723 + }
23724 +#endif
23725 +
23726 + tsk = current;
23727 + mm = tsk->mm;
23728
23729 /*
23730 * Detect and handle instructions that would cause a page fault for
23731 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23732 * User-mode registers count as a user access even for any
23733 * potential system fault or CPU buglet:
23734 */
23735 - if (user_mode_vm(regs)) {
23736 + if (user_mode(regs)) {
23737 local_irq_enable();
23738 error_code |= PF_USER;
23739 } else {
23740 @@ -1132,6 +1338,11 @@ retry:
23741 might_sleep();
23742 }
23743
23744 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23745 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23746 + return;
23747 +#endif
23748 +
23749 vma = find_vma(mm, address);
23750 if (unlikely(!vma)) {
23751 bad_area(regs, error_code, address);
23752 @@ -1143,18 +1354,24 @@ retry:
23753 bad_area(regs, error_code, address);
23754 return;
23755 }
23756 - if (error_code & PF_USER) {
23757 - /*
23758 - * Accessing the stack below %sp is always a bug.
23759 - * The large cushion allows instructions like enter
23760 - * and pusha to work. ("enter $65535, $31" pushes
23761 - * 32 pointers and then decrements %sp by 65535.)
23762 - */
23763 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23764 - bad_area(regs, error_code, address);
23765 - return;
23766 - }
23767 + /*
23768 + * Accessing the stack below %sp is always a bug.
23769 + * The large cushion allows instructions like enter
23770 + * and pusha to work. ("enter $65535, $31" pushes
23771 + * 32 pointers and then decrements %sp by 65535.)
23772 + */
23773 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23774 + bad_area(regs, error_code, address);
23775 + return;
23776 }
23777 +
23778 +#ifdef CONFIG_PAX_SEGMEXEC
23779 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23780 + bad_area(regs, error_code, address);
23781 + return;
23782 + }
23783 +#endif
23784 +
23785 if (unlikely(expand_stack(vma, address))) {
23786 bad_area(regs, error_code, address);
23787 return;
23788 @@ -1209,3 +1426,292 @@ good_area:
23789
23790 up_read(&mm->mmap_sem);
23791 }
23792 +
23793 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23794 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23795 +{
23796 + struct mm_struct *mm = current->mm;
23797 + unsigned long ip = regs->ip;
23798 +
23799 + if (v8086_mode(regs))
23800 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23801 +
23802 +#ifdef CONFIG_PAX_PAGEEXEC
23803 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23804 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23805 + return true;
23806 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23807 + return true;
23808 + return false;
23809 + }
23810 +#endif
23811 +
23812 +#ifdef CONFIG_PAX_SEGMEXEC
23813 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23814 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23815 + return true;
23816 + return false;
23817 + }
23818 +#endif
23819 +
23820 + return false;
23821 +}
23822 +#endif
23823 +
23824 +#ifdef CONFIG_PAX_EMUTRAMP
23825 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23826 +{
23827 + int err;
23828 +
23829 + do { /* PaX: libffi trampoline emulation */
23830 + unsigned char mov, jmp;
23831 + unsigned int addr1, addr2;
23832 +
23833 +#ifdef CONFIG_X86_64
23834 + if ((regs->ip + 9) >> 32)
23835 + break;
23836 +#endif
23837 +
23838 + err = get_user(mov, (unsigned char __user *)regs->ip);
23839 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23840 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23841 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23842 +
23843 + if (err)
23844 + break;
23845 +
23846 + if (mov == 0xB8 && jmp == 0xE9) {
23847 + regs->ax = addr1;
23848 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23849 + return 2;
23850 + }
23851 + } while (0);
23852 +
23853 + do { /* PaX: gcc trampoline emulation #1 */
23854 + unsigned char mov1, mov2;
23855 + unsigned short jmp;
23856 + unsigned int addr1, addr2;
23857 +
23858 +#ifdef CONFIG_X86_64
23859 + if ((regs->ip + 11) >> 32)
23860 + break;
23861 +#endif
23862 +
23863 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23864 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23865 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23866 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23867 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23868 +
23869 + if (err)
23870 + break;
23871 +
23872 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23873 + regs->cx = addr1;
23874 + regs->ax = addr2;
23875 + regs->ip = addr2;
23876 + return 2;
23877 + }
23878 + } while (0);
23879 +
23880 + do { /* PaX: gcc trampoline emulation #2 */
23881 + unsigned char mov, jmp;
23882 + unsigned int addr1, addr2;
23883 +
23884 +#ifdef CONFIG_X86_64
23885 + if ((regs->ip + 9) >> 32)
23886 + break;
23887 +#endif
23888 +
23889 + err = get_user(mov, (unsigned char __user *)regs->ip);
23890 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23891 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23892 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23893 +
23894 + if (err)
23895 + break;
23896 +
23897 + if (mov == 0xB9 && jmp == 0xE9) {
23898 + regs->cx = addr1;
23899 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23900 + return 2;
23901 + }
23902 + } while (0);
23903 +
23904 + return 1; /* PaX in action */
23905 +}
23906 +
23907 +#ifdef CONFIG_X86_64
23908 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23909 +{
23910 + int err;
23911 +
23912 + do { /* PaX: libffi trampoline emulation */
23913 + unsigned short mov1, mov2, jmp1;
23914 + unsigned char stcclc, jmp2;
23915 + unsigned long addr1, addr2;
23916 +
23917 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23918 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23919 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23920 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23921 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23922 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23923 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23924 +
23925 + if (err)
23926 + break;
23927 +
23928 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23929 + regs->r11 = addr1;
23930 + regs->r10 = addr2;
23931 + if (stcclc == 0xF8)
23932 + regs->flags &= ~X86_EFLAGS_CF;
23933 + else
23934 + regs->flags |= X86_EFLAGS_CF;
23935 + regs->ip = addr1;
23936 + return 2;
23937 + }
23938 + } while (0);
23939 +
23940 + do { /* PaX: gcc trampoline emulation #1 */
23941 + unsigned short mov1, mov2, jmp1;
23942 + unsigned char jmp2;
23943 + unsigned int addr1;
23944 + unsigned long addr2;
23945 +
23946 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23947 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23948 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23949 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23950 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23951 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23952 +
23953 + if (err)
23954 + break;
23955 +
23956 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23957 + regs->r11 = addr1;
23958 + regs->r10 = addr2;
23959 + regs->ip = addr1;
23960 + return 2;
23961 + }
23962 + } while (0);
23963 +
23964 + do { /* PaX: gcc trampoline emulation #2 */
23965 + unsigned short mov1, mov2, jmp1;
23966 + unsigned char jmp2;
23967 + unsigned long addr1, addr2;
23968 +
23969 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23970 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23971 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23972 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23973 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23974 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23975 +
23976 + if (err)
23977 + break;
23978 +
23979 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23980 + regs->r11 = addr1;
23981 + regs->r10 = addr2;
23982 + regs->ip = addr1;
23983 + return 2;
23984 + }
23985 + } while (0);
23986 +
23987 + return 1; /* PaX in action */
23988 +}
23989 +#endif
23990 +
23991 +/*
23992 + * PaX: decide what to do with offenders (regs->ip = fault address)
23993 + *
23994 + * returns 1 when task should be killed
23995 + * 2 when gcc trampoline was detected
23996 + */
23997 +static int pax_handle_fetch_fault(struct pt_regs *regs)
23998 +{
23999 + if (v8086_mode(regs))
24000 + return 1;
24001 +
24002 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24003 + return 1;
24004 +
24005 +#ifdef CONFIG_X86_32
24006 + return pax_handle_fetch_fault_32(regs);
24007 +#else
24008 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24009 + return pax_handle_fetch_fault_32(regs);
24010 + else
24011 + return pax_handle_fetch_fault_64(regs);
24012 +#endif
24013 +}
24014 +#endif
24015 +
24016 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24017 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24018 +{
24019 + long i;
24020 +
24021 + printk(KERN_ERR "PAX: bytes at PC: ");
24022 + for (i = 0; i < 20; i++) {
24023 + unsigned char c;
24024 + if (get_user(c, (unsigned char __force_user *)pc+i))
24025 + printk(KERN_CONT "?? ");
24026 + else
24027 + printk(KERN_CONT "%02x ", c);
24028 + }
24029 + printk("\n");
24030 +
24031 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24032 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24033 + unsigned long c;
24034 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24035 +#ifdef CONFIG_X86_32
24036 + printk(KERN_CONT "???????? ");
24037 +#else
24038 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24039 + printk(KERN_CONT "???????? ???????? ");
24040 + else
24041 + printk(KERN_CONT "???????????????? ");
24042 +#endif
24043 + } else {
24044 +#ifdef CONFIG_X86_64
24045 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24046 + printk(KERN_CONT "%08x ", (unsigned int)c);
24047 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24048 + } else
24049 +#endif
24050 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24051 + }
24052 + }
24053 + printk("\n");
24054 +}
24055 +#endif
24056 +
24057 +/**
24058 + * probe_kernel_write(): safely attempt to write to a location
24059 + * @dst: address to write to
24060 + * @src: pointer to the data that shall be written
24061 + * @size: size of the data chunk
24062 + *
24063 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24064 + * happens, handle that and return -EFAULT.
24065 + */
24066 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24067 +{
24068 + long ret;
24069 + mm_segment_t old_fs = get_fs();
24070 +
24071 + set_fs(KERNEL_DS);
24072 + pagefault_disable();
24073 + pax_open_kernel();
24074 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24075 + pax_close_kernel();
24076 + pagefault_enable();
24077 + set_fs(old_fs);
24078 +
24079 + return ret ? -EFAULT : 0;
24080 +}
24081 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24082 index dd74e46..7d26398 100644
24083 --- a/arch/x86/mm/gup.c
24084 +++ b/arch/x86/mm/gup.c
24085 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24086 addr = start;
24087 len = (unsigned long) nr_pages << PAGE_SHIFT;
24088 end = start + len;
24089 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24090 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24091 (void __user *)start, len)))
24092 return 0;
24093
24094 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24095 index f4f29b1..5cac4fb 100644
24096 --- a/arch/x86/mm/highmem_32.c
24097 +++ b/arch/x86/mm/highmem_32.c
24098 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24099 idx = type + KM_TYPE_NR*smp_processor_id();
24100 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24101 BUG_ON(!pte_none(*(kmap_pte-idx)));
24102 +
24103 + pax_open_kernel();
24104 set_pte(kmap_pte-idx, mk_pte(page, prot));
24105 + pax_close_kernel();
24106 +
24107 arch_flush_lazy_mmu_mode();
24108
24109 return (void *)vaddr;
24110 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24111 index 8ecbb4b..29efd37 100644
24112 --- a/arch/x86/mm/hugetlbpage.c
24113 +++ b/arch/x86/mm/hugetlbpage.c
24114 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24115 struct hstate *h = hstate_file(file);
24116 struct mm_struct *mm = current->mm;
24117 struct vm_area_struct *vma;
24118 - unsigned long start_addr;
24119 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24120 +
24121 +#ifdef CONFIG_PAX_SEGMEXEC
24122 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24123 + pax_task_size = SEGMEXEC_TASK_SIZE;
24124 +#endif
24125 +
24126 + pax_task_size -= PAGE_SIZE;
24127
24128 if (len > mm->cached_hole_size) {
24129 - start_addr = mm->free_area_cache;
24130 + start_addr = mm->free_area_cache;
24131 } else {
24132 - start_addr = TASK_UNMAPPED_BASE;
24133 - mm->cached_hole_size = 0;
24134 + start_addr = mm->mmap_base;
24135 + mm->cached_hole_size = 0;
24136 }
24137
24138 full_search:
24139 @@ -280,26 +287,27 @@ full_search:
24140
24141 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24142 /* At this point: (!vma || addr < vma->vm_end). */
24143 - if (TASK_SIZE - len < addr) {
24144 + if (pax_task_size - len < addr) {
24145 /*
24146 * Start a new search - just in case we missed
24147 * some holes.
24148 */
24149 - if (start_addr != TASK_UNMAPPED_BASE) {
24150 - start_addr = TASK_UNMAPPED_BASE;
24151 + if (start_addr != mm->mmap_base) {
24152 + start_addr = mm->mmap_base;
24153 mm->cached_hole_size = 0;
24154 goto full_search;
24155 }
24156 return -ENOMEM;
24157 }
24158 - if (!vma || addr + len <= vma->vm_start) {
24159 - mm->free_area_cache = addr + len;
24160 - return addr;
24161 - }
24162 + if (check_heap_stack_gap(vma, addr, len))
24163 + break;
24164 if (addr + mm->cached_hole_size < vma->vm_start)
24165 mm->cached_hole_size = vma->vm_start - addr;
24166 addr = ALIGN(vma->vm_end, huge_page_size(h));
24167 }
24168 +
24169 + mm->free_area_cache = addr + len;
24170 + return addr;
24171 }
24172
24173 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24174 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24175 {
24176 struct hstate *h = hstate_file(file);
24177 struct mm_struct *mm = current->mm;
24178 - struct vm_area_struct *vma, *prev_vma;
24179 - unsigned long base = mm->mmap_base, addr = addr0;
24180 + struct vm_area_struct *vma;
24181 + unsigned long base = mm->mmap_base, addr;
24182 unsigned long largest_hole = mm->cached_hole_size;
24183 - int first_time = 1;
24184
24185 /* don't allow allocations above current base */
24186 if (mm->free_area_cache > base)
24187 @@ -321,66 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24188 largest_hole = 0;
24189 mm->free_area_cache = base;
24190 }
24191 -try_again:
24192 +
24193 /* make sure it can fit in the remaining address space */
24194 if (mm->free_area_cache < len)
24195 goto fail;
24196
24197 /* either no address requested or can't fit in requested address hole */
24198 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24199 + addr = (mm->free_area_cache - len);
24200 do {
24201 + addr &= huge_page_mask(h);
24202 + vma = find_vma(mm, addr);
24203 /*
24204 * Lookup failure means no vma is above this address,
24205 * i.e. return with success:
24206 - */
24207 - vma = find_vma(mm, addr);
24208 - if (!vma)
24209 - return addr;
24210 -
24211 - /*
24212 * new region fits between prev_vma->vm_end and
24213 * vma->vm_start, use it:
24214 */
24215 - prev_vma = vma->vm_prev;
24216 - if (addr + len <= vma->vm_start &&
24217 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24218 + if (check_heap_stack_gap(vma, addr, len)) {
24219 /* remember the address as a hint for next time */
24220 - mm->cached_hole_size = largest_hole;
24221 - return (mm->free_area_cache = addr);
24222 - } else {
24223 - /* pull free_area_cache down to the first hole */
24224 - if (mm->free_area_cache == vma->vm_end) {
24225 - mm->free_area_cache = vma->vm_start;
24226 - mm->cached_hole_size = largest_hole;
24227 - }
24228 + mm->cached_hole_size = largest_hole;
24229 + return (mm->free_area_cache = addr);
24230 + }
24231 + /* pull free_area_cache down to the first hole */
24232 + if (mm->free_area_cache == vma->vm_end) {
24233 + mm->free_area_cache = vma->vm_start;
24234 + mm->cached_hole_size = largest_hole;
24235 }
24236
24237 /* remember the largest hole we saw so far */
24238 if (addr + largest_hole < vma->vm_start)
24239 - largest_hole = vma->vm_start - addr;
24240 + largest_hole = vma->vm_start - addr;
24241
24242 /* try just below the current vma->vm_start */
24243 - addr = (vma->vm_start - len) & huge_page_mask(h);
24244 - } while (len <= vma->vm_start);
24245 + addr = skip_heap_stack_gap(vma, len);
24246 + } while (!IS_ERR_VALUE(addr));
24247
24248 fail:
24249 /*
24250 - * if hint left us with no space for the requested
24251 - * mapping then try again:
24252 - */
24253 - if (first_time) {
24254 - mm->free_area_cache = base;
24255 - largest_hole = 0;
24256 - first_time = 0;
24257 - goto try_again;
24258 - }
24259 - /*
24260 * A failed mmap() very likely causes application failure,
24261 * so fall back to the bottom-up function here. This scenario
24262 * can happen with large stack limits and large mmap()
24263 * allocations.
24264 */
24265 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24266 +
24267 +#ifdef CONFIG_PAX_SEGMEXEC
24268 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24269 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24270 + else
24271 +#endif
24272 +
24273 + mm->mmap_base = TASK_UNMAPPED_BASE;
24274 +
24275 +#ifdef CONFIG_PAX_RANDMMAP
24276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24277 + mm->mmap_base += mm->delta_mmap;
24278 +#endif
24279 +
24280 + mm->free_area_cache = mm->mmap_base;
24281 mm->cached_hole_size = ~0UL;
24282 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24283 len, pgoff, flags);
24284 @@ -388,6 +392,7 @@ fail:
24285 /*
24286 * Restore the topdown base:
24287 */
24288 + mm->mmap_base = base;
24289 mm->free_area_cache = base;
24290 mm->cached_hole_size = ~0UL;
24291
24292 @@ -401,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24293 struct hstate *h = hstate_file(file);
24294 struct mm_struct *mm = current->mm;
24295 struct vm_area_struct *vma;
24296 + unsigned long pax_task_size = TASK_SIZE;
24297
24298 if (len & ~huge_page_mask(h))
24299 return -EINVAL;
24300 - if (len > TASK_SIZE)
24301 +
24302 +#ifdef CONFIG_PAX_SEGMEXEC
24303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24304 + pax_task_size = SEGMEXEC_TASK_SIZE;
24305 +#endif
24306 +
24307 + pax_task_size -= PAGE_SIZE;
24308 +
24309 + if (len > pax_task_size)
24310 return -ENOMEM;
24311
24312 if (flags & MAP_FIXED) {
24313 @@ -416,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24314 if (addr) {
24315 addr = ALIGN(addr, huge_page_size(h));
24316 vma = find_vma(mm, addr);
24317 - if (TASK_SIZE - len >= addr &&
24318 - (!vma || addr + len <= vma->vm_start))
24319 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24320 return addr;
24321 }
24322 if (mm->get_unmapped_area == arch_get_unmapped_area)
24323 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24324 index 6cabf65..77e9c1c 100644
24325 --- a/arch/x86/mm/init.c
24326 +++ b/arch/x86/mm/init.c
24327 @@ -17,6 +17,7 @@
24328 #include <asm/tlb.h>
24329 #include <asm/proto.h>
24330 #include <asm/dma.h> /* for MAX_DMA_PFN */
24331 +#include <asm/desc.h>
24332
24333 unsigned long __initdata pgt_buf_start;
24334 unsigned long __meminitdata pgt_buf_end;
24335 @@ -33,7 +34,7 @@ int direct_gbpages
24336 static void __init find_early_table_space(unsigned long end, int use_pse,
24337 int use_gbpages)
24338 {
24339 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24340 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24341 phys_addr_t base;
24342
24343 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24344 @@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24345 */
24346 int devmem_is_allowed(unsigned long pagenr)
24347 {
24348 +#ifdef CONFIG_GRKERNSEC_KMEM
24349 + /* allow BDA */
24350 + if (!pagenr)
24351 + return 1;
24352 + /* allow EBDA */
24353 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24354 + return 1;
24355 +#else
24356 + if (!pagenr)
24357 + return 1;
24358 +#ifdef CONFIG_VM86
24359 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24360 + return 1;
24361 +#endif
24362 +#endif
24363 +
24364 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24365 + return 1;
24366 +#ifdef CONFIG_GRKERNSEC_KMEM
24367 + /* throw out everything else below 1MB */
24368 if (pagenr <= 256)
24369 - return 1;
24370 + return 0;
24371 +#endif
24372 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24373 return 0;
24374 if (!page_is_ram(pagenr))
24375 @@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24376
24377 void free_initmem(void)
24378 {
24379 +
24380 +#ifdef CONFIG_PAX_KERNEXEC
24381 +#ifdef CONFIG_X86_32
24382 + /* PaX: limit KERNEL_CS to actual size */
24383 + unsigned long addr, limit;
24384 + struct desc_struct d;
24385 + int cpu;
24386 +
24387 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24388 + limit = (limit - 1UL) >> PAGE_SHIFT;
24389 +
24390 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24391 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24392 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24393 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24394 + }
24395 +
24396 + /* PaX: make KERNEL_CS read-only */
24397 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24398 + if (!paravirt_enabled())
24399 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24400 +/*
24401 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24402 + pgd = pgd_offset_k(addr);
24403 + pud = pud_offset(pgd, addr);
24404 + pmd = pmd_offset(pud, addr);
24405 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24406 + }
24407 +*/
24408 +#ifdef CONFIG_X86_PAE
24409 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24410 +/*
24411 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24412 + pgd = pgd_offset_k(addr);
24413 + pud = pud_offset(pgd, addr);
24414 + pmd = pmd_offset(pud, addr);
24415 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24416 + }
24417 +*/
24418 +#endif
24419 +
24420 +#ifdef CONFIG_MODULES
24421 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24422 +#endif
24423 +
24424 +#else
24425 + pgd_t *pgd;
24426 + pud_t *pud;
24427 + pmd_t *pmd;
24428 + unsigned long addr, end;
24429 +
24430 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24431 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24432 + pgd = pgd_offset_k(addr);
24433 + pud = pud_offset(pgd, addr);
24434 + pmd = pmd_offset(pud, addr);
24435 + if (!pmd_present(*pmd))
24436 + continue;
24437 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24438 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24439 + else
24440 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24441 + }
24442 +
24443 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24444 + end = addr + KERNEL_IMAGE_SIZE;
24445 + for (; addr < end; addr += PMD_SIZE) {
24446 + pgd = pgd_offset_k(addr);
24447 + pud = pud_offset(pgd, addr);
24448 + pmd = pmd_offset(pud, addr);
24449 + if (!pmd_present(*pmd))
24450 + continue;
24451 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24452 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24453 + }
24454 +#endif
24455 +
24456 + flush_tlb_all();
24457 +#endif
24458 +
24459 free_init_pages("unused kernel memory",
24460 (unsigned long)(&__init_begin),
24461 (unsigned long)(&__init_end));
24462 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24463 index 8663f6c..829ae76 100644
24464 --- a/arch/x86/mm/init_32.c
24465 +++ b/arch/x86/mm/init_32.c
24466 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24467 }
24468
24469 /*
24470 - * Creates a middle page table and puts a pointer to it in the
24471 - * given global directory entry. This only returns the gd entry
24472 - * in non-PAE compilation mode, since the middle layer is folded.
24473 - */
24474 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24475 -{
24476 - pud_t *pud;
24477 - pmd_t *pmd_table;
24478 -
24479 -#ifdef CONFIG_X86_PAE
24480 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24481 - if (after_bootmem)
24482 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24483 - else
24484 - pmd_table = (pmd_t *)alloc_low_page();
24485 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24486 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24487 - pud = pud_offset(pgd, 0);
24488 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24489 -
24490 - return pmd_table;
24491 - }
24492 -#endif
24493 - pud = pud_offset(pgd, 0);
24494 - pmd_table = pmd_offset(pud, 0);
24495 -
24496 - return pmd_table;
24497 -}
24498 -
24499 -/*
24500 * Create a page table and place a pointer to it in a middle page
24501 * directory entry:
24502 */
24503 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24504 page_table = (pte_t *)alloc_low_page();
24505
24506 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24507 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24508 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24509 +#else
24510 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24511 +#endif
24512 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24513 }
24514
24515 return pte_offset_kernel(pmd, 0);
24516 }
24517
24518 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24519 +{
24520 + pud_t *pud;
24521 + pmd_t *pmd_table;
24522 +
24523 + pud = pud_offset(pgd, 0);
24524 + pmd_table = pmd_offset(pud, 0);
24525 +
24526 + return pmd_table;
24527 +}
24528 +
24529 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24530 {
24531 int pgd_idx = pgd_index(vaddr);
24532 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24533 int pgd_idx, pmd_idx;
24534 unsigned long vaddr;
24535 pgd_t *pgd;
24536 + pud_t *pud;
24537 pmd_t *pmd;
24538 pte_t *pte = NULL;
24539
24540 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24541 pgd = pgd_base + pgd_idx;
24542
24543 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24544 - pmd = one_md_table_init(pgd);
24545 - pmd = pmd + pmd_index(vaddr);
24546 + pud = pud_offset(pgd, vaddr);
24547 + pmd = pmd_offset(pud, vaddr);
24548 +
24549 +#ifdef CONFIG_X86_PAE
24550 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24551 +#endif
24552 +
24553 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24554 pmd++, pmd_idx++) {
24555 pte = page_table_kmap_check(one_page_table_init(pmd),
24556 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24557 }
24558 }
24559
24560 -static inline int is_kernel_text(unsigned long addr)
24561 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24562 {
24563 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24564 - return 1;
24565 - return 0;
24566 + if ((start > ktla_ktva((unsigned long)_etext) ||
24567 + end <= ktla_ktva((unsigned long)_stext)) &&
24568 + (start > ktla_ktva((unsigned long)_einittext) ||
24569 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24570 +
24571 +#ifdef CONFIG_ACPI_SLEEP
24572 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24573 +#endif
24574 +
24575 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24576 + return 0;
24577 + return 1;
24578 }
24579
24580 /*
24581 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24582 unsigned long last_map_addr = end;
24583 unsigned long start_pfn, end_pfn;
24584 pgd_t *pgd_base = swapper_pg_dir;
24585 - int pgd_idx, pmd_idx, pte_ofs;
24586 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24587 unsigned long pfn;
24588 pgd_t *pgd;
24589 + pud_t *pud;
24590 pmd_t *pmd;
24591 pte_t *pte;
24592 unsigned pages_2m, pages_4k;
24593 @@ -281,8 +282,13 @@ repeat:
24594 pfn = start_pfn;
24595 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24596 pgd = pgd_base + pgd_idx;
24597 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24598 - pmd = one_md_table_init(pgd);
24599 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24600 + pud = pud_offset(pgd, 0);
24601 + pmd = pmd_offset(pud, 0);
24602 +
24603 +#ifdef CONFIG_X86_PAE
24604 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24605 +#endif
24606
24607 if (pfn >= end_pfn)
24608 continue;
24609 @@ -294,14 +300,13 @@ repeat:
24610 #endif
24611 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24612 pmd++, pmd_idx++) {
24613 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24614 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24615
24616 /*
24617 * Map with big pages if possible, otherwise
24618 * create normal page tables:
24619 */
24620 if (use_pse) {
24621 - unsigned int addr2;
24622 pgprot_t prot = PAGE_KERNEL_LARGE;
24623 /*
24624 * first pass will use the same initial
24625 @@ -311,11 +316,7 @@ repeat:
24626 __pgprot(PTE_IDENT_ATTR |
24627 _PAGE_PSE);
24628
24629 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24630 - PAGE_OFFSET + PAGE_SIZE-1;
24631 -
24632 - if (is_kernel_text(addr) ||
24633 - is_kernel_text(addr2))
24634 + if (is_kernel_text(address, address + PMD_SIZE))
24635 prot = PAGE_KERNEL_LARGE_EXEC;
24636
24637 pages_2m++;
24638 @@ -332,7 +333,7 @@ repeat:
24639 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24640 pte += pte_ofs;
24641 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24642 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24643 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24644 pgprot_t prot = PAGE_KERNEL;
24645 /*
24646 * first pass will use the same initial
24647 @@ -340,7 +341,7 @@ repeat:
24648 */
24649 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24650
24651 - if (is_kernel_text(addr))
24652 + if (is_kernel_text(address, address + PAGE_SIZE))
24653 prot = PAGE_KERNEL_EXEC;
24654
24655 pages_4k++;
24656 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24657
24658 pud = pud_offset(pgd, va);
24659 pmd = pmd_offset(pud, va);
24660 - if (!pmd_present(*pmd))
24661 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24662 break;
24663
24664 pte = pte_offset_kernel(pmd, va);
24665 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24666
24667 static void __init pagetable_init(void)
24668 {
24669 - pgd_t *pgd_base = swapper_pg_dir;
24670 -
24671 - permanent_kmaps_init(pgd_base);
24672 + permanent_kmaps_init(swapper_pg_dir);
24673 }
24674
24675 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24676 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24677 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24678
24679 /* user-defined highmem size */
24680 @@ -735,6 +734,12 @@ void __init mem_init(void)
24681
24682 pci_iommu_alloc();
24683
24684 +#ifdef CONFIG_PAX_PER_CPU_PGD
24685 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24686 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24687 + KERNEL_PGD_PTRS);
24688 +#endif
24689 +
24690 #ifdef CONFIG_FLATMEM
24691 BUG_ON(!mem_map);
24692 #endif
24693 @@ -761,7 +766,7 @@ void __init mem_init(void)
24694 reservedpages++;
24695
24696 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24697 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24698 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24699 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24700
24701 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24702 @@ -802,10 +807,10 @@ void __init mem_init(void)
24703 ((unsigned long)&__init_end -
24704 (unsigned long)&__init_begin) >> 10,
24705
24706 - (unsigned long)&_etext, (unsigned long)&_edata,
24707 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24708 + (unsigned long)&_sdata, (unsigned long)&_edata,
24709 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24710
24711 - (unsigned long)&_text, (unsigned long)&_etext,
24712 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24713 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24714
24715 /*
24716 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24717 if (!kernel_set_to_readonly)
24718 return;
24719
24720 + start = ktla_ktva(start);
24721 pr_debug("Set kernel text: %lx - %lx for read write\n",
24722 start, start+size);
24723
24724 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24725 if (!kernel_set_to_readonly)
24726 return;
24727
24728 + start = ktla_ktva(start);
24729 pr_debug("Set kernel text: %lx - %lx for read only\n",
24730 start, start+size);
24731
24732 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24733 unsigned long start = PFN_ALIGN(_text);
24734 unsigned long size = PFN_ALIGN(_etext) - start;
24735
24736 + start = ktla_ktva(start);
24737 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24738 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24739 size >> 10);
24740 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24741 index 436a030..b8596b9 100644
24742 --- a/arch/x86/mm/init_64.c
24743 +++ b/arch/x86/mm/init_64.c
24744 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24745 * around without checking the pgd every time.
24746 */
24747
24748 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24749 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24750 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24751
24752 int force_personality32;
24753 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24754
24755 for (address = start; address <= end; address += PGDIR_SIZE) {
24756 const pgd_t *pgd_ref = pgd_offset_k(address);
24757 +
24758 +#ifdef CONFIG_PAX_PER_CPU_PGD
24759 + unsigned long cpu;
24760 +#else
24761 struct page *page;
24762 +#endif
24763
24764 if (pgd_none(*pgd_ref))
24765 continue;
24766
24767 spin_lock(&pgd_lock);
24768 +
24769 +#ifdef CONFIG_PAX_PER_CPU_PGD
24770 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24771 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24772 +#else
24773 list_for_each_entry(page, &pgd_list, lru) {
24774 pgd_t *pgd;
24775 spinlock_t *pgt_lock;
24776 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24777 /* the pgt_lock only for Xen */
24778 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24779 spin_lock(pgt_lock);
24780 +#endif
24781
24782 if (pgd_none(*pgd))
24783 set_pgd(pgd, *pgd_ref);
24784 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24785 BUG_ON(pgd_page_vaddr(*pgd)
24786 != pgd_page_vaddr(*pgd_ref));
24787
24788 +#ifndef CONFIG_PAX_PER_CPU_PGD
24789 spin_unlock(pgt_lock);
24790 +#endif
24791 +
24792 }
24793 spin_unlock(&pgd_lock);
24794 }
24795 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24796 pmd = fill_pmd(pud, vaddr);
24797 pte = fill_pte(pmd, vaddr);
24798
24799 + pax_open_kernel();
24800 set_pte(pte, new_pte);
24801 + pax_close_kernel();
24802
24803 /*
24804 * It's enough to flush this one mapping.
24805 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24806 pgd = pgd_offset_k((unsigned long)__va(phys));
24807 if (pgd_none(*pgd)) {
24808 pud = (pud_t *) spp_getpage();
24809 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24810 - _PAGE_USER));
24811 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24812 }
24813 pud = pud_offset(pgd, (unsigned long)__va(phys));
24814 if (pud_none(*pud)) {
24815 pmd = (pmd_t *) spp_getpage();
24816 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24817 - _PAGE_USER));
24818 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24819 }
24820 pmd = pmd_offset(pud, phys);
24821 BUG_ON(!pmd_none(*pmd));
24822 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24823 if (pfn >= pgt_buf_top)
24824 panic("alloc_low_page: ran out of memory");
24825
24826 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24827 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24828 clear_page(adr);
24829 *phys = pfn * PAGE_SIZE;
24830 return adr;
24831 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24832
24833 phys = __pa(virt);
24834 left = phys & (PAGE_SIZE - 1);
24835 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24836 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24837 adr = (void *)(((unsigned long)adr) | left);
24838
24839 return adr;
24840 @@ -684,6 +698,12 @@ void __init mem_init(void)
24841
24842 pci_iommu_alloc();
24843
24844 +#ifdef CONFIG_PAX_PER_CPU_PGD
24845 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24846 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24847 + KERNEL_PGD_PTRS);
24848 +#endif
24849 +
24850 /* clear_bss() already clear the empty_zero_page */
24851
24852 reservedpages = 0;
24853 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
24854 static struct vm_area_struct gate_vma = {
24855 .vm_start = VSYSCALL_START,
24856 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24857 - .vm_page_prot = PAGE_READONLY_EXEC,
24858 - .vm_flags = VM_READ | VM_EXEC
24859 + .vm_page_prot = PAGE_READONLY,
24860 + .vm_flags = VM_READ
24861 };
24862
24863 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24864 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
24865
24866 const char *arch_vma_name(struct vm_area_struct *vma)
24867 {
24868 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24869 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24870 return "[vdso]";
24871 if (vma == &gate_vma)
24872 return "[vsyscall]";
24873 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24874 index 7b179b4..6bd1777 100644
24875 --- a/arch/x86/mm/iomap_32.c
24876 +++ b/arch/x86/mm/iomap_32.c
24877 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24878 type = kmap_atomic_idx_push();
24879 idx = type + KM_TYPE_NR * smp_processor_id();
24880 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24881 +
24882 + pax_open_kernel();
24883 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24884 + pax_close_kernel();
24885 +
24886 arch_flush_lazy_mmu_mode();
24887
24888 return (void *)vaddr;
24889 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24890 index be1ef57..55f0160 100644
24891 --- a/arch/x86/mm/ioremap.c
24892 +++ b/arch/x86/mm/ioremap.c
24893 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24894 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24895 int is_ram = page_is_ram(pfn);
24896
24897 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24898 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24899 return NULL;
24900 WARN_ON_ONCE(is_ram);
24901 }
24902 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24903
24904 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24905 if (page_is_ram(start >> PAGE_SHIFT))
24906 +#ifdef CONFIG_HIGHMEM
24907 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24908 +#endif
24909 return __va(phys);
24910
24911 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24912 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24913 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24914
24915 static __initdata int after_paging_init;
24916 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24917 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24918
24919 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24920 {
24921 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24922 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24923
24924 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24925 - memset(bm_pte, 0, sizeof(bm_pte));
24926 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24927 + pmd_populate_user(&init_mm, pmd, bm_pte);
24928
24929 /*
24930 * The boot-ioremap range spans multiple pmds, for which
24931 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24932 index d87dd6d..bf3fa66 100644
24933 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24934 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24935 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24936 * memory (e.g. tracked pages)? For now, we need this to avoid
24937 * invoking kmemcheck for PnP BIOS calls.
24938 */
24939 - if (regs->flags & X86_VM_MASK)
24940 + if (v8086_mode(regs))
24941 return false;
24942 - if (regs->cs != __KERNEL_CS)
24943 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24944 return false;
24945
24946 pte = kmemcheck_pte_lookup(address);
24947 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24948 index 845df68..1d8d29f 100644
24949 --- a/arch/x86/mm/mmap.c
24950 +++ b/arch/x86/mm/mmap.c
24951 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24952 * Leave an at least ~128 MB hole with possible stack randomization.
24953 */
24954 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24955 -#define MAX_GAP (TASK_SIZE/6*5)
24956 +#define MAX_GAP (pax_task_size/6*5)
24957
24958 static int mmap_is_legacy(void)
24959 {
24960 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24961 return rnd << PAGE_SHIFT;
24962 }
24963
24964 -static unsigned long mmap_base(void)
24965 +static unsigned long mmap_base(struct mm_struct *mm)
24966 {
24967 unsigned long gap = rlimit(RLIMIT_STACK);
24968 + unsigned long pax_task_size = TASK_SIZE;
24969 +
24970 +#ifdef CONFIG_PAX_SEGMEXEC
24971 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24972 + pax_task_size = SEGMEXEC_TASK_SIZE;
24973 +#endif
24974
24975 if (gap < MIN_GAP)
24976 gap = MIN_GAP;
24977 else if (gap > MAX_GAP)
24978 gap = MAX_GAP;
24979
24980 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24981 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24982 }
24983
24984 /*
24985 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24986 * does, but not when emulating X86_32
24987 */
24988 -static unsigned long mmap_legacy_base(void)
24989 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
24990 {
24991 - if (mmap_is_ia32())
24992 + if (mmap_is_ia32()) {
24993 +
24994 +#ifdef CONFIG_PAX_SEGMEXEC
24995 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24996 + return SEGMEXEC_TASK_UNMAPPED_BASE;
24997 + else
24998 +#endif
24999 +
25000 return TASK_UNMAPPED_BASE;
25001 - else
25002 + } else
25003 return TASK_UNMAPPED_BASE + mmap_rnd();
25004 }
25005
25006 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25007 void arch_pick_mmap_layout(struct mm_struct *mm)
25008 {
25009 if (mmap_is_legacy()) {
25010 - mm->mmap_base = mmap_legacy_base();
25011 + mm->mmap_base = mmap_legacy_base(mm);
25012 +
25013 +#ifdef CONFIG_PAX_RANDMMAP
25014 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25015 + mm->mmap_base += mm->delta_mmap;
25016 +#endif
25017 +
25018 mm->get_unmapped_area = arch_get_unmapped_area;
25019 mm->unmap_area = arch_unmap_area;
25020 } else {
25021 - mm->mmap_base = mmap_base();
25022 + mm->mmap_base = mmap_base(mm);
25023 +
25024 +#ifdef CONFIG_PAX_RANDMMAP
25025 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25026 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25027 +#endif
25028 +
25029 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25030 mm->unmap_area = arch_unmap_area_topdown;
25031 }
25032 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25033 index dc0b727..dc9d71a 100644
25034 --- a/arch/x86/mm/mmio-mod.c
25035 +++ b/arch/x86/mm/mmio-mod.c
25036 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25037 break;
25038 default:
25039 {
25040 - unsigned char *ip = (unsigned char *)instptr;
25041 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25042 my_trace->opcode = MMIO_UNKNOWN_OP;
25043 my_trace->width = 0;
25044 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25045 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25046 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25047 void __iomem *addr)
25048 {
25049 - static atomic_t next_id;
25050 + static atomic_unchecked_t next_id;
25051 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25052 /* These are page-unaligned. */
25053 struct mmiotrace_map map = {
25054 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25055 .private = trace
25056 },
25057 .phys = offset,
25058 - .id = atomic_inc_return(&next_id)
25059 + .id = atomic_inc_return_unchecked(&next_id)
25060 };
25061 map.map_id = trace->id;
25062
25063 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25064 index b008656..773eac2 100644
25065 --- a/arch/x86/mm/pageattr-test.c
25066 +++ b/arch/x86/mm/pageattr-test.c
25067 @@ -36,7 +36,7 @@ enum {
25068
25069 static int pte_testbit(pte_t pte)
25070 {
25071 - return pte_flags(pte) & _PAGE_UNUSED1;
25072 + return pte_flags(pte) & _PAGE_CPA_TEST;
25073 }
25074
25075 struct split_state {
25076 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25077 index e1ebde3..b1e1db38 100644
25078 --- a/arch/x86/mm/pageattr.c
25079 +++ b/arch/x86/mm/pageattr.c
25080 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25081 */
25082 #ifdef CONFIG_PCI_BIOS
25083 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25084 - pgprot_val(forbidden) |= _PAGE_NX;
25085 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25086 #endif
25087
25088 /*
25089 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25090 * Does not cover __inittext since that is gone later on. On
25091 * 64bit we do not enforce !NX on the low mapping
25092 */
25093 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25094 - pgprot_val(forbidden) |= _PAGE_NX;
25095 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25096 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25097
25098 +#ifdef CONFIG_DEBUG_RODATA
25099 /*
25100 * The .rodata section needs to be read-only. Using the pfn
25101 * catches all aliases.
25102 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25103 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25104 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25105 pgprot_val(forbidden) |= _PAGE_RW;
25106 +#endif
25107
25108 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25109 /*
25110 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25111 }
25112 #endif
25113
25114 +#ifdef CONFIG_PAX_KERNEXEC
25115 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25116 + pgprot_val(forbidden) |= _PAGE_RW;
25117 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25118 + }
25119 +#endif
25120 +
25121 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25122
25123 return prot;
25124 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25125 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25126 {
25127 /* change init_mm */
25128 + pax_open_kernel();
25129 set_pte_atomic(kpte, pte);
25130 +
25131 #ifdef CONFIG_X86_32
25132 if (!SHARED_KERNEL_PMD) {
25133 +
25134 +#ifdef CONFIG_PAX_PER_CPU_PGD
25135 + unsigned long cpu;
25136 +#else
25137 struct page *page;
25138 +#endif
25139
25140 +#ifdef CONFIG_PAX_PER_CPU_PGD
25141 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25142 + pgd_t *pgd = get_cpu_pgd(cpu);
25143 +#else
25144 list_for_each_entry(page, &pgd_list, lru) {
25145 - pgd_t *pgd;
25146 + pgd_t *pgd = (pgd_t *)page_address(page);
25147 +#endif
25148 +
25149 pud_t *pud;
25150 pmd_t *pmd;
25151
25152 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25153 + pgd += pgd_index(address);
25154 pud = pud_offset(pgd, address);
25155 pmd = pmd_offset(pud, address);
25156 set_pte_atomic((pte_t *)pmd, pte);
25157 }
25158 }
25159 #endif
25160 + pax_close_kernel();
25161 }
25162
25163 static int
25164 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25165 index f6ff57b..481690f 100644
25166 --- a/arch/x86/mm/pat.c
25167 +++ b/arch/x86/mm/pat.c
25168 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25169
25170 if (!entry) {
25171 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25172 - current->comm, current->pid, start, end);
25173 + current->comm, task_pid_nr(current), start, end);
25174 return -EINVAL;
25175 }
25176
25177 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25178 while (cursor < to) {
25179 if (!devmem_is_allowed(pfn)) {
25180 printk(KERN_INFO
25181 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25182 - current->comm, from, to);
25183 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25184 + current->comm, from, to, cursor);
25185 return 0;
25186 }
25187 cursor += PAGE_SIZE;
25188 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25189 printk(KERN_INFO
25190 "%s:%d ioremap_change_attr failed %s "
25191 "for %Lx-%Lx\n",
25192 - current->comm, current->pid,
25193 + current->comm, task_pid_nr(current),
25194 cattr_name(flags),
25195 base, (unsigned long long)(base + size));
25196 return -EINVAL;
25197 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25198 if (want_flags != flags) {
25199 printk(KERN_WARNING
25200 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25201 - current->comm, current->pid,
25202 + current->comm, task_pid_nr(current),
25203 cattr_name(want_flags),
25204 (unsigned long long)paddr,
25205 (unsigned long long)(paddr + size),
25206 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25207 free_memtype(paddr, paddr + size);
25208 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25209 " for %Lx-%Lx, got %s\n",
25210 - current->comm, current->pid,
25211 + current->comm, task_pid_nr(current),
25212 cattr_name(want_flags),
25213 (unsigned long long)paddr,
25214 (unsigned long long)(paddr + size),
25215 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25216 index 9f0614d..92ae64a 100644
25217 --- a/arch/x86/mm/pf_in.c
25218 +++ b/arch/x86/mm/pf_in.c
25219 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25220 int i;
25221 enum reason_type rv = OTHERS;
25222
25223 - p = (unsigned char *)ins_addr;
25224 + p = (unsigned char *)ktla_ktva(ins_addr);
25225 p += skip_prefix(p, &prf);
25226 p += get_opcode(p, &opcode);
25227
25228 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25229 struct prefix_bits prf;
25230 int i;
25231
25232 - p = (unsigned char *)ins_addr;
25233 + p = (unsigned char *)ktla_ktva(ins_addr);
25234 p += skip_prefix(p, &prf);
25235 p += get_opcode(p, &opcode);
25236
25237 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25238 struct prefix_bits prf;
25239 int i;
25240
25241 - p = (unsigned char *)ins_addr;
25242 + p = (unsigned char *)ktla_ktva(ins_addr);
25243 p += skip_prefix(p, &prf);
25244 p += get_opcode(p, &opcode);
25245
25246 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25247 struct prefix_bits prf;
25248 int i;
25249
25250 - p = (unsigned char *)ins_addr;
25251 + p = (unsigned char *)ktla_ktva(ins_addr);
25252 p += skip_prefix(p, &prf);
25253 p += get_opcode(p, &opcode);
25254 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25255 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25256 struct prefix_bits prf;
25257 int i;
25258
25259 - p = (unsigned char *)ins_addr;
25260 + p = (unsigned char *)ktla_ktva(ins_addr);
25261 p += skip_prefix(p, &prf);
25262 p += get_opcode(p, &opcode);
25263 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25264 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25265 index 8573b83..7d9628f 100644
25266 --- a/arch/x86/mm/pgtable.c
25267 +++ b/arch/x86/mm/pgtable.c
25268 @@ -84,10 +84,60 @@ static inline void pgd_list_del(pgd_t *pgd)
25269 list_del(&page->lru);
25270 }
25271
25272 -#define UNSHARED_PTRS_PER_PGD \
25273 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25274 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25275 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25276
25277 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25278 +{
25279 + while (count--)
25280 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25281 +}
25282 +#endif
25283
25284 +#ifdef CONFIG_PAX_PER_CPU_PGD
25285 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25286 +{
25287 + while (count--) {
25288 + pgd_t pgd;
25289 +
25290 +#ifdef CONFIG_X86_64
25291 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25292 +#else
25293 + pgd = *src++;
25294 +#endif
25295 +
25296 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25297 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25298 +#endif
25299 +
25300 + *dst++ = pgd;
25301 + }
25302 +
25303 +}
25304 +#endif
25305 +
25306 +#ifdef CONFIG_X86_64
25307 +#define pxd_t pud_t
25308 +#define pyd_t pgd_t
25309 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25310 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25311 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25312 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25313 +#define PYD_SIZE PGDIR_SIZE
25314 +#else
25315 +#define pxd_t pmd_t
25316 +#define pyd_t pud_t
25317 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25318 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25319 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25320 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25321 +#define PYD_SIZE PUD_SIZE
25322 +#endif
25323 +
25324 +#ifdef CONFIG_PAX_PER_CPU_PGD
25325 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25326 +static inline void pgd_dtor(pgd_t *pgd) {}
25327 +#else
25328 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25329 {
25330 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25331 @@ -128,6 +178,7 @@ static void pgd_dtor(pgd_t *pgd)
25332 pgd_list_del(pgd);
25333 spin_unlock(&pgd_lock);
25334 }
25335 +#endif
25336
25337 /*
25338 * List of all pgd's needed for non-PAE so it can invalidate entries
25339 @@ -140,7 +191,7 @@ static void pgd_dtor(pgd_t *pgd)
25340 * -- wli
25341 */
25342
25343 -#ifdef CONFIG_X86_PAE
25344 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25345 /*
25346 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25347 * updating the top-level pagetable entries to guarantee the
25348 @@ -152,7 +203,7 @@ static void pgd_dtor(pgd_t *pgd)
25349 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25350 * and initialize the kernel pmds here.
25351 */
25352 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25353 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25354
25355 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25356 {
25357 @@ -170,36 +221,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25358 */
25359 flush_tlb_mm(mm);
25360 }
25361 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25362 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25363 #else /* !CONFIG_X86_PAE */
25364
25365 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25366 -#define PREALLOCATED_PMDS 0
25367 +#define PREALLOCATED_PXDS 0
25368
25369 #endif /* CONFIG_X86_PAE */
25370
25371 -static void free_pmds(pmd_t *pmds[])
25372 +static void free_pxds(pxd_t *pxds[])
25373 {
25374 int i;
25375
25376 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25377 - if (pmds[i])
25378 - free_page((unsigned long)pmds[i]);
25379 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25380 + if (pxds[i])
25381 + free_page((unsigned long)pxds[i]);
25382 }
25383
25384 -static int preallocate_pmds(pmd_t *pmds[])
25385 +static int preallocate_pxds(pxd_t *pxds[])
25386 {
25387 int i;
25388 bool failed = false;
25389
25390 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25391 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25392 - if (pmd == NULL)
25393 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25394 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25395 + if (pxd == NULL)
25396 failed = true;
25397 - pmds[i] = pmd;
25398 + pxds[i] = pxd;
25399 }
25400
25401 if (failed) {
25402 - free_pmds(pmds);
25403 + free_pxds(pxds);
25404 return -ENOMEM;
25405 }
25406
25407 @@ -212,51 +265,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25408 * preallocate which never got a corresponding vma will need to be
25409 * freed manually.
25410 */
25411 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25412 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25413 {
25414 int i;
25415
25416 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25417 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25418 pgd_t pgd = pgdp[i];
25419
25420 if (pgd_val(pgd) != 0) {
25421 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25422 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25423
25424 - pgdp[i] = native_make_pgd(0);
25425 + set_pgd(pgdp + i, native_make_pgd(0));
25426
25427 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25428 - pmd_free(mm, pmd);
25429 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25430 + pxd_free(mm, pxd);
25431 }
25432 }
25433 }
25434
25435 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25436 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25437 {
25438 - pud_t *pud;
25439 + pyd_t *pyd;
25440 unsigned long addr;
25441 int i;
25442
25443 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25444 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25445 return;
25446
25447 - pud = pud_offset(pgd, 0);
25448 +#ifdef CONFIG_X86_64
25449 + pyd = pyd_offset(mm, 0L);
25450 +#else
25451 + pyd = pyd_offset(pgd, 0L);
25452 +#endif
25453
25454 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25455 - i++, pud++, addr += PUD_SIZE) {
25456 - pmd_t *pmd = pmds[i];
25457 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25458 + i++, pyd++, addr += PYD_SIZE) {
25459 + pxd_t *pxd = pxds[i];
25460
25461 if (i >= KERNEL_PGD_BOUNDARY)
25462 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25463 - sizeof(pmd_t) * PTRS_PER_PMD);
25464 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25465 + sizeof(pxd_t) * PTRS_PER_PMD);
25466
25467 - pud_populate(mm, pud, pmd);
25468 + pyd_populate(mm, pyd, pxd);
25469 }
25470 }
25471
25472 pgd_t *pgd_alloc(struct mm_struct *mm)
25473 {
25474 pgd_t *pgd;
25475 - pmd_t *pmds[PREALLOCATED_PMDS];
25476 + pxd_t *pxds[PREALLOCATED_PXDS];
25477
25478 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25479
25480 @@ -265,11 +322,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25481
25482 mm->pgd = pgd;
25483
25484 - if (preallocate_pmds(pmds) != 0)
25485 + if (preallocate_pxds(pxds) != 0)
25486 goto out_free_pgd;
25487
25488 if (paravirt_pgd_alloc(mm) != 0)
25489 - goto out_free_pmds;
25490 + goto out_free_pxds;
25491
25492 /*
25493 * Make sure that pre-populating the pmds is atomic with
25494 @@ -279,14 +336,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25495 spin_lock(&pgd_lock);
25496
25497 pgd_ctor(mm, pgd);
25498 - pgd_prepopulate_pmd(mm, pgd, pmds);
25499 + pgd_prepopulate_pxd(mm, pgd, pxds);
25500
25501 spin_unlock(&pgd_lock);
25502
25503 return pgd;
25504
25505 -out_free_pmds:
25506 - free_pmds(pmds);
25507 +out_free_pxds:
25508 + free_pxds(pxds);
25509 out_free_pgd:
25510 free_page((unsigned long)pgd);
25511 out:
25512 @@ -295,7 +352,7 @@ out:
25513
25514 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25515 {
25516 - pgd_mop_up_pmds(mm, pgd);
25517 + pgd_mop_up_pxds(mm, pgd);
25518 pgd_dtor(pgd);
25519 paravirt_pgd_free(mm, pgd);
25520 free_page((unsigned long)pgd);
25521 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25522 index cac7184..09a39fa 100644
25523 --- a/arch/x86/mm/pgtable_32.c
25524 +++ b/arch/x86/mm/pgtable_32.c
25525 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25526 return;
25527 }
25528 pte = pte_offset_kernel(pmd, vaddr);
25529 +
25530 + pax_open_kernel();
25531 if (pte_val(pteval))
25532 set_pte_at(&init_mm, vaddr, pte, pteval);
25533 else
25534 pte_clear(&init_mm, vaddr, pte);
25535 + pax_close_kernel();
25536
25537 /*
25538 * It's enough to flush this one mapping.
25539 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25540 index 410531d..0f16030 100644
25541 --- a/arch/x86/mm/setup_nx.c
25542 +++ b/arch/x86/mm/setup_nx.c
25543 @@ -5,8 +5,10 @@
25544 #include <asm/pgtable.h>
25545 #include <asm/proto.h>
25546
25547 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25548 static int disable_nx __cpuinitdata;
25549
25550 +#ifndef CONFIG_PAX_PAGEEXEC
25551 /*
25552 * noexec = on|off
25553 *
25554 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25555 return 0;
25556 }
25557 early_param("noexec", noexec_setup);
25558 +#endif
25559 +
25560 +#endif
25561
25562 void __cpuinit x86_configure_nx(void)
25563 {
25564 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25565 if (cpu_has_nx && !disable_nx)
25566 __supported_pte_mask |= _PAGE_NX;
25567 else
25568 +#endif
25569 __supported_pte_mask &= ~_PAGE_NX;
25570 }
25571
25572 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25573 index d6c0418..06a0ad5 100644
25574 --- a/arch/x86/mm/tlb.c
25575 +++ b/arch/x86/mm/tlb.c
25576 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25577 BUG();
25578 cpumask_clear_cpu(cpu,
25579 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25580 +
25581 +#ifndef CONFIG_PAX_PER_CPU_PGD
25582 load_cr3(swapper_pg_dir);
25583 +#endif
25584 +
25585 }
25586 EXPORT_SYMBOL_GPL(leave_mm);
25587
25588 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25589 index 6687022..ceabcfa 100644
25590 --- a/arch/x86/net/bpf_jit.S
25591 +++ b/arch/x86/net/bpf_jit.S
25592 @@ -9,6 +9,7 @@
25593 */
25594 #include <linux/linkage.h>
25595 #include <asm/dwarf2.h>
25596 +#include <asm/alternative-asm.h>
25597
25598 /*
25599 * Calling convention :
25600 @@ -35,6 +36,7 @@ sk_load_word:
25601 jle bpf_slow_path_word
25602 mov (SKBDATA,%rsi),%eax
25603 bswap %eax /* ntohl() */
25604 + pax_force_retaddr
25605 ret
25606
25607
25608 @@ -53,6 +55,7 @@ sk_load_half:
25609 jle bpf_slow_path_half
25610 movzwl (SKBDATA,%rsi),%eax
25611 rol $8,%ax # ntohs()
25612 + pax_force_retaddr
25613 ret
25614
25615 sk_load_byte_ind:
25616 @@ -66,6 +69,7 @@ sk_load_byte:
25617 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25618 jle bpf_slow_path_byte
25619 movzbl (SKBDATA,%rsi),%eax
25620 + pax_force_retaddr
25621 ret
25622
25623 /**
25624 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25625 movzbl (SKBDATA,%rsi),%ebx
25626 and $15,%bl
25627 shl $2,%bl
25628 + pax_force_retaddr
25629 ret
25630 CFI_ENDPROC
25631 ENDPROC(sk_load_byte_msh)
25632 @@ -91,6 +96,7 @@ bpf_error:
25633 xor %eax,%eax
25634 mov -8(%rbp),%rbx
25635 leaveq
25636 + pax_force_retaddr
25637 ret
25638
25639 /* rsi contains offset and can be scratched */
25640 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25641 js bpf_error
25642 mov -12(%rbp),%eax
25643 bswap %eax
25644 + pax_force_retaddr
25645 ret
25646
25647 bpf_slow_path_half:
25648 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25649 mov -12(%rbp),%ax
25650 rol $8,%ax
25651 movzwl %ax,%eax
25652 + pax_force_retaddr
25653 ret
25654
25655 bpf_slow_path_byte:
25656 bpf_slow_path_common(1)
25657 js bpf_error
25658 movzbl -12(%rbp),%eax
25659 + pax_force_retaddr
25660 ret
25661
25662 bpf_slow_path_byte_msh:
25663 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25664 and $15,%al
25665 shl $2,%al
25666 xchg %eax,%ebx
25667 + pax_force_retaddr
25668 ret
25669 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25670 index 5a5b6e4..201d42e 100644
25671 --- a/arch/x86/net/bpf_jit_comp.c
25672 +++ b/arch/x86/net/bpf_jit_comp.c
25673 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25674 set_fs(old_fs);
25675 }
25676
25677 +struct bpf_jit_work {
25678 + struct work_struct work;
25679 + void *image;
25680 +};
25681
25682 void bpf_jit_compile(struct sk_filter *fp)
25683 {
25684 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25685 if (addrs == NULL)
25686 return;
25687
25688 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25689 + if (!fp->work)
25690 + goto out;
25691 +
25692 /* Before first pass, make a rough estimation of addrs[]
25693 * each bpf instruction is translated to less than 64 bytes
25694 */
25695 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25696 common_load: seen |= SEEN_DATAREF;
25697 if ((int)K < 0) {
25698 /* Abort the JIT because __load_pointer() is needed. */
25699 - goto out;
25700 + goto error;
25701 }
25702 t_offset = func - (image + addrs[i]);
25703 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25704 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25705 case BPF_S_LDX_B_MSH:
25706 if ((int)K < 0) {
25707 /* Abort the JIT because __load_pointer() is needed. */
25708 - goto out;
25709 + goto error;
25710 }
25711 seen |= SEEN_DATAREF | SEEN_XREG;
25712 t_offset = sk_load_byte_msh - (image + addrs[i]);
25713 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25714 break;
25715 default:
25716 /* hmm, too complex filter, give up with jit compiler */
25717 - goto out;
25718 + goto error;
25719 }
25720 ilen = prog - temp;
25721 if (image) {
25722 if (unlikely(proglen + ilen > oldproglen)) {
25723 pr_err("bpb_jit_compile fatal error\n");
25724 - kfree(addrs);
25725 - module_free(NULL, image);
25726 - return;
25727 + module_free_exec(NULL, image);
25728 + goto error;
25729 }
25730 + pax_open_kernel();
25731 memcpy(image + proglen, temp, ilen);
25732 + pax_close_kernel();
25733 }
25734 proglen += ilen;
25735 addrs[i] = proglen;
25736 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25737 break;
25738 }
25739 if (proglen == oldproglen) {
25740 - image = module_alloc(max_t(unsigned int,
25741 - proglen,
25742 - sizeof(struct work_struct)));
25743 + image = module_alloc_exec(proglen);
25744 if (!image)
25745 - goto out;
25746 + goto error;
25747 }
25748 oldproglen = proglen;
25749 }
25750 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25751 bpf_flush_icache(image, image + proglen);
25752
25753 fp->bpf_func = (void *)image;
25754 - }
25755 + } else
25756 +error:
25757 + kfree(fp->work);
25758 +
25759 out:
25760 kfree(addrs);
25761 return;
25762 @@ -641,18 +651,20 @@ out:
25763
25764 static void jit_free_defer(struct work_struct *arg)
25765 {
25766 - module_free(NULL, arg);
25767 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25768 + kfree(arg);
25769 }
25770
25771 /* run from softirq, we must use a work_struct to call
25772 - * module_free() from process context
25773 + * module_free_exec() from process context
25774 */
25775 void bpf_jit_free(struct sk_filter *fp)
25776 {
25777 if (fp->bpf_func != sk_run_filter) {
25778 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25779 + struct work_struct *work = &fp->work->work;
25780
25781 INIT_WORK(work, jit_free_defer);
25782 + fp->work->image = fp->bpf_func;
25783 schedule_work(work);
25784 }
25785 }
25786 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25787 index bff89df..377758a 100644
25788 --- a/arch/x86/oprofile/backtrace.c
25789 +++ b/arch/x86/oprofile/backtrace.c
25790 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25791 struct stack_frame_ia32 *fp;
25792 unsigned long bytes;
25793
25794 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25795 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25796 if (bytes != sizeof(bufhead))
25797 return NULL;
25798
25799 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25800 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25801
25802 oprofile_add_trace(bufhead[0].return_address);
25803
25804 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25805 struct stack_frame bufhead[2];
25806 unsigned long bytes;
25807
25808 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25809 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25810 if (bytes != sizeof(bufhead))
25811 return NULL;
25812
25813 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25814 {
25815 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25816
25817 - if (!user_mode_vm(regs)) {
25818 + if (!user_mode(regs)) {
25819 unsigned long stack = kernel_stack_pointer(regs);
25820 if (depth)
25821 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25822 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25823 index cb29191..036766d 100644
25824 --- a/arch/x86/pci/mrst.c
25825 +++ b/arch/x86/pci/mrst.c
25826 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25827 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25828 pci_mmcfg_late_init();
25829 pcibios_enable_irq = mrst_pci_irq_enable;
25830 - pci_root_ops = pci_mrst_ops;
25831 + pax_open_kernel();
25832 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25833 + pax_close_kernel();
25834 /* Continue with standard init */
25835 return 1;
25836 }
25837 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25838 index da8fe05..7ee6704 100644
25839 --- a/arch/x86/pci/pcbios.c
25840 +++ b/arch/x86/pci/pcbios.c
25841 @@ -79,50 +79,93 @@ union bios32 {
25842 static struct {
25843 unsigned long address;
25844 unsigned short segment;
25845 -} bios32_indirect = { 0, __KERNEL_CS };
25846 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25847
25848 /*
25849 * Returns the entry point for the given service, NULL on error
25850 */
25851
25852 -static unsigned long bios32_service(unsigned long service)
25853 +static unsigned long __devinit bios32_service(unsigned long service)
25854 {
25855 unsigned char return_code; /* %al */
25856 unsigned long address; /* %ebx */
25857 unsigned long length; /* %ecx */
25858 unsigned long entry; /* %edx */
25859 unsigned long flags;
25860 + struct desc_struct d, *gdt;
25861
25862 local_irq_save(flags);
25863 - __asm__("lcall *(%%edi); cld"
25864 +
25865 + gdt = get_cpu_gdt_table(smp_processor_id());
25866 +
25867 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25868 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25869 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25870 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25871 +
25872 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25873 : "=a" (return_code),
25874 "=b" (address),
25875 "=c" (length),
25876 "=d" (entry)
25877 : "0" (service),
25878 "1" (0),
25879 - "D" (&bios32_indirect));
25880 + "D" (&bios32_indirect),
25881 + "r"(__PCIBIOS_DS)
25882 + : "memory");
25883 +
25884 + pax_open_kernel();
25885 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25886 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25887 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25888 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25889 + pax_close_kernel();
25890 +
25891 local_irq_restore(flags);
25892
25893 switch (return_code) {
25894 - case 0:
25895 - return address + entry;
25896 - case 0x80: /* Not present */
25897 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25898 - return 0;
25899 - default: /* Shouldn't happen */
25900 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25901 - service, return_code);
25902 + case 0: {
25903 + int cpu;
25904 + unsigned char flags;
25905 +
25906 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25907 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25908 + printk(KERN_WARNING "bios32_service: not valid\n");
25909 return 0;
25910 + }
25911 + address = address + PAGE_OFFSET;
25912 + length += 16UL; /* some BIOSs underreport this... */
25913 + flags = 4;
25914 + if (length >= 64*1024*1024) {
25915 + length >>= PAGE_SHIFT;
25916 + flags |= 8;
25917 + }
25918 +
25919 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25920 + gdt = get_cpu_gdt_table(cpu);
25921 + pack_descriptor(&d, address, length, 0x9b, flags);
25922 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25923 + pack_descriptor(&d, address, length, 0x93, flags);
25924 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25925 + }
25926 + return entry;
25927 + }
25928 + case 0x80: /* Not present */
25929 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25930 + return 0;
25931 + default: /* Shouldn't happen */
25932 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25933 + service, return_code);
25934 + return 0;
25935 }
25936 }
25937
25938 static struct {
25939 unsigned long address;
25940 unsigned short segment;
25941 -} pci_indirect = { 0, __KERNEL_CS };
25942 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25943
25944 -static int pci_bios_present;
25945 +static int pci_bios_present __read_only;
25946
25947 static int __devinit check_pcibios(void)
25948 {
25949 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25950 unsigned long flags, pcibios_entry;
25951
25952 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25953 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25954 + pci_indirect.address = pcibios_entry;
25955
25956 local_irq_save(flags);
25957 - __asm__(
25958 - "lcall *(%%edi); cld\n\t"
25959 + __asm__("movw %w6, %%ds\n\t"
25960 + "lcall *%%ss:(%%edi); cld\n\t"
25961 + "push %%ss\n\t"
25962 + "pop %%ds\n\t"
25963 "jc 1f\n\t"
25964 "xor %%ah, %%ah\n"
25965 "1:"
25966 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25967 "=b" (ebx),
25968 "=c" (ecx)
25969 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25970 - "D" (&pci_indirect)
25971 + "D" (&pci_indirect),
25972 + "r" (__PCIBIOS_DS)
25973 : "memory");
25974 local_irq_restore(flags);
25975
25976 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25977
25978 switch (len) {
25979 case 1:
25980 - __asm__("lcall *(%%esi); cld\n\t"
25981 + __asm__("movw %w6, %%ds\n\t"
25982 + "lcall *%%ss:(%%esi); cld\n\t"
25983 + "push %%ss\n\t"
25984 + "pop %%ds\n\t"
25985 "jc 1f\n\t"
25986 "xor %%ah, %%ah\n"
25987 "1:"
25988 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25989 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25990 "b" (bx),
25991 "D" ((long)reg),
25992 - "S" (&pci_indirect));
25993 + "S" (&pci_indirect),
25994 + "r" (__PCIBIOS_DS));
25995 /*
25996 * Zero-extend the result beyond 8 bits, do not trust the
25997 * BIOS having done it:
25998 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25999 *value &= 0xff;
26000 break;
26001 case 2:
26002 - __asm__("lcall *(%%esi); cld\n\t"
26003 + __asm__("movw %w6, %%ds\n\t"
26004 + "lcall *%%ss:(%%esi); cld\n\t"
26005 + "push %%ss\n\t"
26006 + "pop %%ds\n\t"
26007 "jc 1f\n\t"
26008 "xor %%ah, %%ah\n"
26009 "1:"
26010 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26011 : "1" (PCIBIOS_READ_CONFIG_WORD),
26012 "b" (bx),
26013 "D" ((long)reg),
26014 - "S" (&pci_indirect));
26015 + "S" (&pci_indirect),
26016 + "r" (__PCIBIOS_DS));
26017 /*
26018 * Zero-extend the result beyond 16 bits, do not trust the
26019 * BIOS having done it:
26020 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26021 *value &= 0xffff;
26022 break;
26023 case 4:
26024 - __asm__("lcall *(%%esi); cld\n\t"
26025 + __asm__("movw %w6, %%ds\n\t"
26026 + "lcall *%%ss:(%%esi); cld\n\t"
26027 + "push %%ss\n\t"
26028 + "pop %%ds\n\t"
26029 "jc 1f\n\t"
26030 "xor %%ah, %%ah\n"
26031 "1:"
26032 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26033 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26034 "b" (bx),
26035 "D" ((long)reg),
26036 - "S" (&pci_indirect));
26037 + "S" (&pci_indirect),
26038 + "r" (__PCIBIOS_DS));
26039 break;
26040 }
26041
26042 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26043
26044 switch (len) {
26045 case 1:
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 @@ -265,10 +326,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 2:
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 @@ -277,10 +342,14 @@ 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 case 4:
26080 - __asm__("lcall *(%%esi); cld\n\t"
26081 + __asm__("movw %w6, %%ds\n\t"
26082 + "lcall *%%ss:(%%esi); cld\n\t"
26083 + "push %%ss\n\t"
26084 + "pop %%ds\n\t"
26085 "jc 1f\n\t"
26086 "xor %%ah, %%ah\n"
26087 "1:"
26088 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26089 "c" (value),
26090 "b" (bx),
26091 "D" ((long)reg),
26092 - "S" (&pci_indirect));
26093 + "S" (&pci_indirect),
26094 + "r" (__PCIBIOS_DS));
26095 break;
26096 }
26097
26098 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26099
26100 DBG("PCI: Fetching IRQ routing table... ");
26101 __asm__("push %%es\n\t"
26102 + "movw %w8, %%ds\n\t"
26103 "push %%ds\n\t"
26104 "pop %%es\n\t"
26105 - "lcall *(%%esi); cld\n\t"
26106 + "lcall *%%ss:(%%esi); cld\n\t"
26107 "pop %%es\n\t"
26108 + "push %%ss\n\t"
26109 + "pop %%ds\n"
26110 "jc 1f\n\t"
26111 "xor %%ah, %%ah\n"
26112 "1:"
26113 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26114 "1" (0),
26115 "D" ((long) &opt),
26116 "S" (&pci_indirect),
26117 - "m" (opt)
26118 + "m" (opt),
26119 + "r" (__PCIBIOS_DS)
26120 : "memory");
26121 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26122 if (ret & 0xff00)
26123 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26124 {
26125 int ret;
26126
26127 - __asm__("lcall *(%%esi); cld\n\t"
26128 + __asm__("movw %w5, %%ds\n\t"
26129 + "lcall *%%ss:(%%esi); cld\n\t"
26130 + "push %%ss\n\t"
26131 + "pop %%ds\n"
26132 "jc 1f\n\t"
26133 "xor %%ah, %%ah\n"
26134 "1:"
26135 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26136 : "0" (PCIBIOS_SET_PCI_HW_INT),
26137 "b" ((dev->bus->number << 8) | dev->devfn),
26138 "c" ((irq << 8) | (pin + 10)),
26139 - "S" (&pci_indirect));
26140 + "S" (&pci_indirect),
26141 + "r" (__PCIBIOS_DS));
26142 return !(ret & 0xff00);
26143 }
26144 EXPORT_SYMBOL(pcibios_set_irq_routing);
26145 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26146 index 40e4469..1ab536e 100644
26147 --- a/arch/x86/platform/efi/efi_32.c
26148 +++ b/arch/x86/platform/efi/efi_32.c
26149 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26150 {
26151 struct desc_ptr gdt_descr;
26152
26153 +#ifdef CONFIG_PAX_KERNEXEC
26154 + struct desc_struct d;
26155 +#endif
26156 +
26157 local_irq_save(efi_rt_eflags);
26158
26159 load_cr3(initial_page_table);
26160 __flush_tlb_all();
26161
26162 +#ifdef CONFIG_PAX_KERNEXEC
26163 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26164 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26165 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26166 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26167 +#endif
26168 +
26169 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26170 gdt_descr.size = GDT_SIZE - 1;
26171 load_gdt(&gdt_descr);
26172 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26173 {
26174 struct desc_ptr gdt_descr;
26175
26176 +#ifdef CONFIG_PAX_KERNEXEC
26177 + struct desc_struct d;
26178 +
26179 + memset(&d, 0, sizeof d);
26180 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26181 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26182 +#endif
26183 +
26184 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26185 gdt_descr.size = GDT_SIZE - 1;
26186 load_gdt(&gdt_descr);
26187 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26188 index fbe66e6..c5c0dd2 100644
26189 --- a/arch/x86/platform/efi/efi_stub_32.S
26190 +++ b/arch/x86/platform/efi/efi_stub_32.S
26191 @@ -6,7 +6,9 @@
26192 */
26193
26194 #include <linux/linkage.h>
26195 +#include <linux/init.h>
26196 #include <asm/page_types.h>
26197 +#include <asm/segment.h>
26198
26199 /*
26200 * efi_call_phys(void *, ...) is a function with variable parameters.
26201 @@ -20,7 +22,7 @@
26202 * service functions will comply with gcc calling convention, too.
26203 */
26204
26205 -.text
26206 +__INIT
26207 ENTRY(efi_call_phys)
26208 /*
26209 * 0. The function can only be called in Linux kernel. So CS has been
26210 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26211 * The mapping of lower virtual memory has been created in prelog and
26212 * epilog.
26213 */
26214 - movl $1f, %edx
26215 - subl $__PAGE_OFFSET, %edx
26216 - jmp *%edx
26217 + movl $(__KERNEXEC_EFI_DS), %edx
26218 + mov %edx, %ds
26219 + mov %edx, %es
26220 + mov %edx, %ss
26221 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26222 1:
26223
26224 /*
26225 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26226 * parameter 2, ..., param n. To make things easy, we save the return
26227 * address of efi_call_phys in a global variable.
26228 */
26229 - popl %edx
26230 - movl %edx, saved_return_addr
26231 - /* get the function pointer into ECX*/
26232 - popl %ecx
26233 - movl %ecx, efi_rt_function_ptr
26234 - movl $2f, %edx
26235 - subl $__PAGE_OFFSET, %edx
26236 - pushl %edx
26237 + popl (saved_return_addr)
26238 + popl (efi_rt_function_ptr)
26239
26240 /*
26241 * 3. Clear PG bit in %CR0.
26242 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26243 /*
26244 * 5. Call the physical function.
26245 */
26246 - jmp *%ecx
26247 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26248
26249 -2:
26250 /*
26251 * 6. After EFI runtime service returns, control will return to
26252 * following instruction. We'd better readjust stack pointer first.
26253 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26254 movl %cr0, %edx
26255 orl $0x80000000, %edx
26256 movl %edx, %cr0
26257 - jmp 1f
26258 -1:
26259 +
26260 /*
26261 * 8. Now restore the virtual mode from flat mode by
26262 * adding EIP with PAGE_OFFSET.
26263 */
26264 - movl $1f, %edx
26265 - jmp *%edx
26266 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26267 1:
26268 + movl $(__KERNEL_DS), %edx
26269 + mov %edx, %ds
26270 + mov %edx, %es
26271 + mov %edx, %ss
26272
26273 /*
26274 * 9. Balance the stack. And because EAX contain the return value,
26275 * we'd better not clobber it.
26276 */
26277 - leal efi_rt_function_ptr, %edx
26278 - movl (%edx), %ecx
26279 - pushl %ecx
26280 + pushl (efi_rt_function_ptr)
26281
26282 /*
26283 - * 10. Push the saved return address onto the stack and return.
26284 + * 10. Return to the saved return address.
26285 */
26286 - leal saved_return_addr, %edx
26287 - movl (%edx), %ecx
26288 - pushl %ecx
26289 - ret
26290 + jmpl *(saved_return_addr)
26291 ENDPROC(efi_call_phys)
26292 .previous
26293
26294 -.data
26295 +__INITDATA
26296 saved_return_addr:
26297 .long 0
26298 efi_rt_function_ptr:
26299 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26300 index 4c07cca..2c8427d 100644
26301 --- a/arch/x86/platform/efi/efi_stub_64.S
26302 +++ b/arch/x86/platform/efi/efi_stub_64.S
26303 @@ -7,6 +7,7 @@
26304 */
26305
26306 #include <linux/linkage.h>
26307 +#include <asm/alternative-asm.h>
26308
26309 #define SAVE_XMM \
26310 mov %rsp, %rax; \
26311 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26312 call *%rdi
26313 addq $32, %rsp
26314 RESTORE_XMM
26315 + pax_force_retaddr 0, 1
26316 ret
26317 ENDPROC(efi_call0)
26318
26319 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26320 call *%rdi
26321 addq $32, %rsp
26322 RESTORE_XMM
26323 + pax_force_retaddr 0, 1
26324 ret
26325 ENDPROC(efi_call1)
26326
26327 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26328 call *%rdi
26329 addq $32, %rsp
26330 RESTORE_XMM
26331 + pax_force_retaddr 0, 1
26332 ret
26333 ENDPROC(efi_call2)
26334
26335 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26336 call *%rdi
26337 addq $32, %rsp
26338 RESTORE_XMM
26339 + pax_force_retaddr 0, 1
26340 ret
26341 ENDPROC(efi_call3)
26342
26343 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26344 call *%rdi
26345 addq $32, %rsp
26346 RESTORE_XMM
26347 + pax_force_retaddr 0, 1
26348 ret
26349 ENDPROC(efi_call4)
26350
26351 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26352 call *%rdi
26353 addq $48, %rsp
26354 RESTORE_XMM
26355 + pax_force_retaddr 0, 1
26356 ret
26357 ENDPROC(efi_call5)
26358
26359 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26360 call *%rdi
26361 addq $48, %rsp
26362 RESTORE_XMM
26363 + pax_force_retaddr 0, 1
26364 ret
26365 ENDPROC(efi_call6)
26366 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26367 index 475e2cd..1b8e708 100644
26368 --- a/arch/x86/platform/mrst/mrst.c
26369 +++ b/arch/x86/platform/mrst/mrst.c
26370 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26371 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26372 int sfi_mrtc_num;
26373
26374 -static void mrst_power_off(void)
26375 +static __noreturn void mrst_power_off(void)
26376 {
26377 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26378 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26379 + BUG();
26380 }
26381
26382 -static void mrst_reboot(void)
26383 +static __noreturn void mrst_reboot(void)
26384 {
26385 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26386 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26387 else
26388 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26389 + BUG();
26390 }
26391
26392 /* parse all the mtimer info to a static mtimer array */
26393 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
26394 index 3ae0e61..4202d86 100644
26395 --- a/arch/x86/platform/uv/tlb_uv.c
26396 +++ b/arch/x86/platform/uv/tlb_uv.c
26397 @@ -1424,6 +1424,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
26398 * 0: display meaning of the statistics
26399 */
26400 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26401 + size_t count, loff_t *data) __size_overflow(3);
26402 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26403 size_t count, loff_t *data)
26404 {
26405 int cpu;
26406 @@ -1539,6 +1541,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
26407 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
26408 */
26409 static ssize_t tunables_write(struct file *file, const char __user *user,
26410 + size_t count, loff_t *data) __size_overflow(3);
26411 +static ssize_t tunables_write(struct file *file, const char __user *user,
26412 size_t count, loff_t *data)
26413 {
26414 int cpu;
26415 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26416 index f10c0af..3ec1f95 100644
26417 --- a/arch/x86/power/cpu.c
26418 +++ b/arch/x86/power/cpu.c
26419 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26420 static void fix_processor_context(void)
26421 {
26422 int cpu = smp_processor_id();
26423 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26424 + struct tss_struct *t = init_tss + cpu;
26425
26426 set_tss_desc(cpu, t); /*
26427 * This just modifies memory; should not be
26428 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26429 */
26430
26431 #ifdef CONFIG_X86_64
26432 + pax_open_kernel();
26433 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26434 + pax_close_kernel();
26435
26436 syscall_init(); /* This sets MSR_*STAR and related */
26437 #endif
26438 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26439 index 5d17950..2253fc9 100644
26440 --- a/arch/x86/vdso/Makefile
26441 +++ b/arch/x86/vdso/Makefile
26442 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26443 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26444 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26445
26446 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26447 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26448 GCOV_PROFILE := n
26449
26450 #
26451 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26452 index 468d591..8e80a0a 100644
26453 --- a/arch/x86/vdso/vdso32-setup.c
26454 +++ b/arch/x86/vdso/vdso32-setup.c
26455 @@ -25,6 +25,7 @@
26456 #include <asm/tlbflush.h>
26457 #include <asm/vdso.h>
26458 #include <asm/proto.h>
26459 +#include <asm/mman.h>
26460
26461 enum {
26462 VDSO_DISABLED = 0,
26463 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26464 void enable_sep_cpu(void)
26465 {
26466 int cpu = get_cpu();
26467 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26468 + struct tss_struct *tss = init_tss + cpu;
26469
26470 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26471 put_cpu();
26472 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26473 gate_vma.vm_start = FIXADDR_USER_START;
26474 gate_vma.vm_end = FIXADDR_USER_END;
26475 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26476 - gate_vma.vm_page_prot = __P101;
26477 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26478 /*
26479 * Make sure the vDSO gets into every core dump.
26480 * Dumping its contents makes post-mortem fully interpretable later
26481 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26482 if (compat)
26483 addr = VDSO_HIGH_BASE;
26484 else {
26485 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26486 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26487 if (IS_ERR_VALUE(addr)) {
26488 ret = addr;
26489 goto up_fail;
26490 }
26491 }
26492
26493 - current->mm->context.vdso = (void *)addr;
26494 + current->mm->context.vdso = addr;
26495
26496 if (compat_uses_vma || !compat) {
26497 /*
26498 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26499 }
26500
26501 current_thread_info()->sysenter_return =
26502 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26503 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26504
26505 up_fail:
26506 if (ret)
26507 - current->mm->context.vdso = NULL;
26508 + current->mm->context.vdso = 0;
26509
26510 up_write(&mm->mmap_sem);
26511
26512 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26513
26514 const char *arch_vma_name(struct vm_area_struct *vma)
26515 {
26516 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26517 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26518 return "[vdso]";
26519 +
26520 +#ifdef CONFIG_PAX_SEGMEXEC
26521 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26522 + return "[vdso]";
26523 +#endif
26524 +
26525 return NULL;
26526 }
26527
26528 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26529 * Check to see if the corresponding task was created in compat vdso
26530 * mode.
26531 */
26532 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26533 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26534 return &gate_vma;
26535 return NULL;
26536 }
26537 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26538 index 153407c..611cba9 100644
26539 --- a/arch/x86/vdso/vma.c
26540 +++ b/arch/x86/vdso/vma.c
26541 @@ -16,8 +16,6 @@
26542 #include <asm/vdso.h>
26543 #include <asm/page.h>
26544
26545 -unsigned int __read_mostly vdso_enabled = 1;
26546 -
26547 extern char vdso_start[], vdso_end[];
26548 extern unsigned short vdso_sync_cpuid;
26549
26550 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26551 * unaligned here as a result of stack start randomization.
26552 */
26553 addr = PAGE_ALIGN(addr);
26554 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26555
26556 return addr;
26557 }
26558 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26559 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26560 {
26561 struct mm_struct *mm = current->mm;
26562 - unsigned long addr;
26563 + unsigned long addr = 0;
26564 int ret;
26565
26566 - if (!vdso_enabled)
26567 - return 0;
26568 -
26569 down_write(&mm->mmap_sem);
26570 +
26571 +#ifdef CONFIG_PAX_RANDMMAP
26572 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26573 +#endif
26574 +
26575 addr = vdso_addr(mm->start_stack, vdso_size);
26576 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26577 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26578 if (IS_ERR_VALUE(addr)) {
26579 ret = addr;
26580 goto up_fail;
26581 }
26582
26583 - current->mm->context.vdso = (void *)addr;
26584 + mm->context.vdso = addr;
26585
26586 ret = install_special_mapping(mm, addr, vdso_size,
26587 VM_READ|VM_EXEC|
26588 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26589 VM_ALWAYSDUMP,
26590 vdso_pages);
26591 - if (ret) {
26592 - current->mm->context.vdso = NULL;
26593 - goto up_fail;
26594 - }
26595 +
26596 + if (ret)
26597 + mm->context.vdso = 0;
26598
26599 up_fail:
26600 up_write(&mm->mmap_sem);
26601 return ret;
26602 }
26603 -
26604 -static __init int vdso_setup(char *s)
26605 -{
26606 - vdso_enabled = simple_strtoul(s, NULL, 0);
26607 - return 0;
26608 -}
26609 -__setup("vdso=", vdso_setup);
26610 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26611 index 4172af8..2c8ed7f 100644
26612 --- a/arch/x86/xen/enlighten.c
26613 +++ b/arch/x86/xen/enlighten.c
26614 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26615
26616 struct shared_info xen_dummy_shared_info;
26617
26618 -void *xen_initial_gdt;
26619 -
26620 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26621 __read_mostly int xen_have_vector_callback;
26622 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26623 @@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26624 #endif
26625 };
26626
26627 -static void xen_reboot(int reason)
26628 +static __noreturn void xen_reboot(int reason)
26629 {
26630 struct sched_shutdown r = { .reason = reason };
26631
26632 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26633 - BUG();
26634 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26635 + BUG();
26636 }
26637
26638 -static void xen_restart(char *msg)
26639 +static __noreturn void xen_restart(char *msg)
26640 {
26641 xen_reboot(SHUTDOWN_reboot);
26642 }
26643
26644 -static void xen_emergency_restart(void)
26645 +static __noreturn void xen_emergency_restart(void)
26646 {
26647 xen_reboot(SHUTDOWN_reboot);
26648 }
26649
26650 -static void xen_machine_halt(void)
26651 +static __noreturn void xen_machine_halt(void)
26652 {
26653 xen_reboot(SHUTDOWN_poweroff);
26654 }
26655
26656 -static void xen_machine_power_off(void)
26657 +static __noreturn void xen_machine_power_off(void)
26658 {
26659 if (pm_power_off)
26660 pm_power_off();
26661 @@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26662 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26663
26664 /* Work out if we support NX */
26665 - x86_configure_nx();
26666 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26667 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26668 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26669 + unsigned l, h;
26670 +
26671 + __supported_pte_mask |= _PAGE_NX;
26672 + rdmsr(MSR_EFER, l, h);
26673 + l |= EFER_NX;
26674 + wrmsr(MSR_EFER, l, h);
26675 + }
26676 +#endif
26677
26678 xen_setup_features();
26679
26680 @@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26681
26682 machine_ops = xen_machine_ops;
26683
26684 - /*
26685 - * The only reliable way to retain the initial address of the
26686 - * percpu gdt_page is to remember it here, so we can go and
26687 - * mark it RW later, when the initial percpu area is freed.
26688 - */
26689 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26690 -
26691 xen_smp_init();
26692
26693 #ifdef CONFIG_ACPI_NUMA
26694 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26695 index 95c1cf6..4bfa5be 100644
26696 --- a/arch/x86/xen/mmu.c
26697 +++ b/arch/x86/xen/mmu.c
26698 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26699 convert_pfn_mfn(init_level4_pgt);
26700 convert_pfn_mfn(level3_ident_pgt);
26701 convert_pfn_mfn(level3_kernel_pgt);
26702 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26703 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26704 + convert_pfn_mfn(level3_vmemmap_pgt);
26705
26706 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26707 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26708 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26709 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26710 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26711 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26712 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26713 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26714 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26715 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26716 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26717 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26718 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26719
26720 @@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26721 pv_mmu_ops.set_pud = xen_set_pud;
26722 #if PAGETABLE_LEVELS == 4
26723 pv_mmu_ops.set_pgd = xen_set_pgd;
26724 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26725 #endif
26726
26727 /* This will work as long as patching hasn't happened yet
26728 @@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26729 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26730 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26731 .set_pgd = xen_set_pgd_hyper,
26732 + .set_pgd_batched = xen_set_pgd_hyper,
26733
26734 .alloc_pud = xen_alloc_pmd_init,
26735 .release_pud = xen_release_pmd_init,
26736 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26737 index 501d4e0..e877605 100644
26738 --- a/arch/x86/xen/smp.c
26739 +++ b/arch/x86/xen/smp.c
26740 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26741 {
26742 BUG_ON(smp_processor_id() != 0);
26743 native_smp_prepare_boot_cpu();
26744 -
26745 - /* We've switched to the "real" per-cpu gdt, so make sure the
26746 - old memory can be recycled */
26747 - make_lowmem_page_readwrite(xen_initial_gdt);
26748 -
26749 xen_filter_cpu_maps();
26750 xen_setup_vcpu_info_placement();
26751 }
26752 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26753 gdt = get_cpu_gdt_table(cpu);
26754
26755 ctxt->flags = VGCF_IN_KERNEL;
26756 - ctxt->user_regs.ds = __USER_DS;
26757 - ctxt->user_regs.es = __USER_DS;
26758 + ctxt->user_regs.ds = __KERNEL_DS;
26759 + ctxt->user_regs.es = __KERNEL_DS;
26760 ctxt->user_regs.ss = __KERNEL_DS;
26761 #ifdef CONFIG_X86_32
26762 ctxt->user_regs.fs = __KERNEL_PERCPU;
26763 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26764 + savesegment(gs, ctxt->user_regs.gs);
26765 #else
26766 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26767 #endif
26768 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26769 int rc;
26770
26771 per_cpu(current_task, cpu) = idle;
26772 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26773 #ifdef CONFIG_X86_32
26774 irq_ctx_init(cpu);
26775 #else
26776 clear_tsk_thread_flag(idle, TIF_FORK);
26777 - per_cpu(kernel_stack, cpu) =
26778 - (unsigned long)task_stack_page(idle) -
26779 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26780 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26781 #endif
26782 xen_setup_runstate_info(cpu);
26783 xen_setup_timer(cpu);
26784 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26785 index b040b0e..8cc4fe0 100644
26786 --- a/arch/x86/xen/xen-asm_32.S
26787 +++ b/arch/x86/xen/xen-asm_32.S
26788 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26789 ESP_OFFSET=4 # bytes pushed onto stack
26790
26791 /*
26792 - * Store vcpu_info pointer for easy access. Do it this way to
26793 - * avoid having to reload %fs
26794 + * Store vcpu_info pointer for easy access.
26795 */
26796 #ifdef CONFIG_SMP
26797 - GET_THREAD_INFO(%eax)
26798 - movl TI_cpu(%eax), %eax
26799 - movl __per_cpu_offset(,%eax,4), %eax
26800 - mov xen_vcpu(%eax), %eax
26801 + push %fs
26802 + mov $(__KERNEL_PERCPU), %eax
26803 + mov %eax, %fs
26804 + mov PER_CPU_VAR(xen_vcpu), %eax
26805 + pop %fs
26806 #else
26807 movl xen_vcpu, %eax
26808 #endif
26809 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26810 index aaa7291..3f77960 100644
26811 --- a/arch/x86/xen/xen-head.S
26812 +++ b/arch/x86/xen/xen-head.S
26813 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26814 #ifdef CONFIG_X86_32
26815 mov %esi,xen_start_info
26816 mov $init_thread_union+THREAD_SIZE,%esp
26817 +#ifdef CONFIG_SMP
26818 + movl $cpu_gdt_table,%edi
26819 + movl $__per_cpu_load,%eax
26820 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26821 + rorl $16,%eax
26822 + movb %al,__KERNEL_PERCPU + 4(%edi)
26823 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26824 + movl $__per_cpu_end - 1,%eax
26825 + subl $__per_cpu_start,%eax
26826 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26827 +#endif
26828 #else
26829 mov %rsi,xen_start_info
26830 mov $init_thread_union+THREAD_SIZE,%rsp
26831 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26832 index b095739..8c17bcd 100644
26833 --- a/arch/x86/xen/xen-ops.h
26834 +++ b/arch/x86/xen/xen-ops.h
26835 @@ -10,8 +10,6 @@
26836 extern const char xen_hypervisor_callback[];
26837 extern const char xen_failsafe_callback[];
26838
26839 -extern void *xen_initial_gdt;
26840 -
26841 struct trap_info;
26842 void xen_copy_trap_info(struct trap_info *traps);
26843
26844 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26845 index 525bd3d..ef888b1 100644
26846 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26847 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26848 @@ -119,9 +119,9 @@
26849 ----------------------------------------------------------------------*/
26850
26851 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26852 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26853 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26854 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26855 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26856
26857 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26858 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26859 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26860 index 2f33760..835e50a 100644
26861 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26862 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26863 @@ -11,6 +11,7 @@
26864 #ifndef _XTENSA_CORE_H
26865 #define _XTENSA_CORE_H
26866
26867 +#include <linux/const.h>
26868
26869 /****************************************************************************
26870 Parameters Useful for Any Code, USER or PRIVILEGED
26871 @@ -112,9 +113,9 @@
26872 ----------------------------------------------------------------------*/
26873
26874 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26875 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26876 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26877 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26878 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26879
26880 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26881 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26882 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26883 index af00795..2bb8105 100644
26884 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26885 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26886 @@ -11,6 +11,7 @@
26887 #ifndef _XTENSA_CORE_CONFIGURATION_H
26888 #define _XTENSA_CORE_CONFIGURATION_H
26889
26890 +#include <linux/const.h>
26891
26892 /****************************************************************************
26893 Parameters Useful for Any Code, USER or PRIVILEGED
26894 @@ -118,9 +119,9 @@
26895 ----------------------------------------------------------------------*/
26896
26897 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26898 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26899 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26900 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26901 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26902
26903 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26904 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26905 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26906 index 58916af..9cb880b 100644
26907 --- a/block/blk-iopoll.c
26908 +++ b/block/blk-iopoll.c
26909 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26910 }
26911 EXPORT_SYMBOL(blk_iopoll_complete);
26912
26913 -static void blk_iopoll_softirq(struct softirq_action *h)
26914 +static void blk_iopoll_softirq(void)
26915 {
26916 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26917 int rearm = 0, budget = blk_iopoll_budget;
26918 diff --git a/block/blk-map.c b/block/blk-map.c
26919 index 623e1cd..ca1e109 100644
26920 --- a/block/blk-map.c
26921 +++ b/block/blk-map.c
26922 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26923 if (!len || !kbuf)
26924 return -EINVAL;
26925
26926 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26927 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26928 if (do_copy)
26929 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26930 else
26931 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26932 index 1366a89..e17f54b 100644
26933 --- a/block/blk-softirq.c
26934 +++ b/block/blk-softirq.c
26935 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26936 * Softirq action handler - move entries to local list and loop over them
26937 * while passing them to the queue registered handler.
26938 */
26939 -static void blk_done_softirq(struct softirq_action *h)
26940 +static void blk_done_softirq(void)
26941 {
26942 struct list_head *cpu_list, local_list;
26943
26944 diff --git a/block/bsg.c b/block/bsg.c
26945 index ff64ae3..593560c 100644
26946 --- a/block/bsg.c
26947 +++ b/block/bsg.c
26948 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26949 struct sg_io_v4 *hdr, struct bsg_device *bd,
26950 fmode_t has_write_perm)
26951 {
26952 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26953 + unsigned char *cmdptr;
26954 +
26955 if (hdr->request_len > BLK_MAX_CDB) {
26956 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26957 if (!rq->cmd)
26958 return -ENOMEM;
26959 - }
26960 + cmdptr = rq->cmd;
26961 + } else
26962 + cmdptr = tmpcmd;
26963
26964 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26965 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26966 hdr->request_len))
26967 return -EFAULT;
26968
26969 + if (cmdptr != rq->cmd)
26970 + memcpy(rq->cmd, cmdptr, hdr->request_len);
26971 +
26972 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26973 if (blk_verify_command(rq->cmd, has_write_perm))
26974 return -EPERM;
26975 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26976 index 7c668c8..db3521c 100644
26977 --- a/block/compat_ioctl.c
26978 +++ b/block/compat_ioctl.c
26979 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26980 err |= __get_user(f->spec1, &uf->spec1);
26981 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26982 err |= __get_user(name, &uf->name);
26983 - f->name = compat_ptr(name);
26984 + f->name = (void __force_kernel *)compat_ptr(name);
26985 if (err) {
26986 err = -EFAULT;
26987 goto out;
26988 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
26989 index 6296b40..417c00f 100644
26990 --- a/block/partitions/efi.c
26991 +++ b/block/partitions/efi.c
26992 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
26993 if (!gpt)
26994 return NULL;
26995
26996 + if (!le32_to_cpu(gpt->num_partition_entries))
26997 + return NULL;
26998 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
26999 + if (!pte)
27000 + return NULL;
27001 +
27002 count = le32_to_cpu(gpt->num_partition_entries) *
27003 le32_to_cpu(gpt->sizeof_partition_entry);
27004 - if (!count)
27005 - return NULL;
27006 - pte = kzalloc(count, GFP_KERNEL);
27007 - if (!pte)
27008 - return NULL;
27009 -
27010 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27011 (u8 *) pte,
27012 count) < count) {
27013 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27014 index 260fa80..e8f3caf 100644
27015 --- a/block/scsi_ioctl.c
27016 +++ b/block/scsi_ioctl.c
27017 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27018 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27019 struct sg_io_hdr *hdr, fmode_t mode)
27020 {
27021 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27022 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27023 + unsigned char *cmdptr;
27024 +
27025 + if (rq->cmd != rq->__cmd)
27026 + cmdptr = rq->cmd;
27027 + else
27028 + cmdptr = tmpcmd;
27029 +
27030 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27031 return -EFAULT;
27032 +
27033 + if (cmdptr != rq->cmd)
27034 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27035 +
27036 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27037 return -EPERM;
27038
27039 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27040 int err;
27041 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27042 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27043 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27044 + unsigned char *cmdptr;
27045
27046 if (!sic)
27047 return -EINVAL;
27048 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27049 */
27050 err = -EFAULT;
27051 rq->cmd_len = cmdlen;
27052 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27053 +
27054 + if (rq->cmd != rq->__cmd)
27055 + cmdptr = rq->cmd;
27056 + else
27057 + cmdptr = tmpcmd;
27058 +
27059 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27060 goto error;
27061
27062 + if (rq->cmd != cmdptr)
27063 + memcpy(rq->cmd, cmdptr, cmdlen);
27064 +
27065 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27066 goto error;
27067
27068 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27069 index a0f768c..1da9c73 100644
27070 --- a/crypto/ablkcipher.c
27071 +++ b/crypto/ablkcipher.c
27072 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27073 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27074
27075 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27076 + unsigned int keylen) __size_overflow(3);
27077 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27078 unsigned int keylen)
27079 {
27080 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27081 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27082 }
27083
27084 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27085 + unsigned int keylen) __size_overflow(3);
27086 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27087 unsigned int keylen)
27088 {
27089 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27090 diff --git a/crypto/aead.c b/crypto/aead.c
27091 index 04add3dc..983032f 100644
27092 --- a/crypto/aead.c
27093 +++ b/crypto/aead.c
27094 @@ -27,6 +27,8 @@
27095 #include "internal.h"
27096
27097 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27098 + unsigned int keylen) __size_overflow(3);
27099 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27100 unsigned int keylen)
27101 {
27102 struct aead_alg *aead = crypto_aead_alg(tfm);
27103 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27104 return ret;
27105 }
27106
27107 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27108 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27109 {
27110 struct aead_alg *aead = crypto_aead_alg(tfm);
27111 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27112 index 1e61d1a..cf06b86 100644
27113 --- a/crypto/blkcipher.c
27114 +++ b/crypto/blkcipher.c
27115 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27116 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27117
27118 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27119 + unsigned int keylen) __size_overflow(3);
27120 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27121 unsigned int keylen)
27122 {
27123 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27124 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27125 return ret;
27126 }
27127
27128 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27129 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27130 {
27131 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27132 diff --git a/crypto/cipher.c b/crypto/cipher.c
27133 index 39541e0..802d956 100644
27134 --- a/crypto/cipher.c
27135 +++ b/crypto/cipher.c
27136 @@ -21,6 +21,8 @@
27137 #include "internal.h"
27138
27139 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27140 + unsigned int keylen) __size_overflow(3);
27141 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27142 unsigned int keylen)
27143 {
27144 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27145 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27146
27147 }
27148
27149 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27150 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27151 {
27152 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27153 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27154 index 671d4d6..5f24030 100644
27155 --- a/crypto/cryptd.c
27156 +++ b/crypto/cryptd.c
27157 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27158
27159 struct cryptd_blkcipher_request_ctx {
27160 crypto_completion_t complete;
27161 -};
27162 +} __no_const;
27163
27164 struct cryptd_hash_ctx {
27165 struct crypto_shash *child;
27166 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27167
27168 struct cryptd_aead_request_ctx {
27169 crypto_completion_t complete;
27170 -};
27171 +} __no_const;
27172
27173 static void cryptd_queue_worker(struct work_struct *work);
27174
27175 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27176 index 5d41894..22021e4 100644
27177 --- a/drivers/acpi/apei/cper.c
27178 +++ b/drivers/acpi/apei/cper.c
27179 @@ -38,12 +38,12 @@
27180 */
27181 u64 cper_next_record_id(void)
27182 {
27183 - static atomic64_t seq;
27184 + static atomic64_unchecked_t seq;
27185
27186 - if (!atomic64_read(&seq))
27187 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27188 + if (!atomic64_read_unchecked(&seq))
27189 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27190
27191 - return atomic64_inc_return(&seq);
27192 + return atomic64_inc_return_unchecked(&seq);
27193 }
27194 EXPORT_SYMBOL_GPL(cper_next_record_id);
27195
27196 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27197 index 86933ca..5cb1a69 100644
27198 --- a/drivers/acpi/battery.c
27199 +++ b/drivers/acpi/battery.c
27200 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27201
27202 static ssize_t acpi_battery_write_alarm(struct file *file,
27203 const char __user * buffer,
27204 + size_t count, loff_t * ppos) __size_overflow(3);
27205 +static ssize_t acpi_battery_write_alarm(struct file *file,
27206 + const char __user * buffer,
27207 size_t count, loff_t * ppos)
27208 {
27209 int result = 0;
27210 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27211 index b258cab..3fb7da7 100644
27212 --- a/drivers/acpi/ec_sys.c
27213 +++ b/drivers/acpi/ec_sys.c
27214 @@ -12,6 +12,7 @@
27215 #include <linux/acpi.h>
27216 #include <linux/debugfs.h>
27217 #include <linux/module.h>
27218 +#include <linux/uaccess.h>
27219 #include "internal.h"
27220
27221 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27222 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27223 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27224 */
27225 unsigned int size = EC_SPACE_SIZE;
27226 - u8 *data = (u8 *) buf;
27227 + u8 data;
27228 loff_t init_off = *off;
27229 int err = 0;
27230
27231 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27232 size = count;
27233
27234 while (size) {
27235 - err = ec_read(*off, &data[*off - init_off]);
27236 + err = ec_read(*off, &data);
27237 if (err)
27238 return err;
27239 + if (put_user(data, &buf[*off - init_off]))
27240 + return -EFAULT;
27241 *off += 1;
27242 size--;
27243 }
27244 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27245
27246 unsigned int size = count;
27247 loff_t init_off = *off;
27248 - u8 *data = (u8 *) buf;
27249 int err = 0;
27250
27251 if (*off >= EC_SPACE_SIZE)
27252 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27253 }
27254
27255 while (size) {
27256 - u8 byte_write = data[*off - init_off];
27257 + u8 byte_write;
27258 + if (get_user(byte_write, &buf[*off - init_off]))
27259 + return -EFAULT;
27260 err = ec_write(*off, byte_write);
27261 if (err)
27262 return err;
27263 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27264 index 251c7b62..000462d 100644
27265 --- a/drivers/acpi/proc.c
27266 +++ b/drivers/acpi/proc.c
27267 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27268 size_t count, loff_t * ppos)
27269 {
27270 struct list_head *node, *next;
27271 - char strbuf[5];
27272 - char str[5] = "";
27273 - unsigned int len = count;
27274 + char strbuf[5] = {0};
27275
27276 - if (len > 4)
27277 - len = 4;
27278 - if (len < 0)
27279 + if (count > 4)
27280 + count = 4;
27281 + if (copy_from_user(strbuf, buffer, count))
27282 return -EFAULT;
27283 -
27284 - if (copy_from_user(strbuf, buffer, len))
27285 - return -EFAULT;
27286 - strbuf[len] = '\0';
27287 - sscanf(strbuf, "%s", str);
27288 + strbuf[count] = '\0';
27289
27290 mutex_lock(&acpi_device_lock);
27291 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27292 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27293 if (!dev->wakeup.flags.valid)
27294 continue;
27295
27296 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27297 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27298 if (device_can_wakeup(&dev->dev)) {
27299 bool enable = !device_may_wakeup(&dev->dev);
27300 device_set_wakeup_enable(&dev->dev, enable);
27301 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27302 index 8ae05ce..7dbbed9 100644
27303 --- a/drivers/acpi/processor_driver.c
27304 +++ b/drivers/acpi/processor_driver.c
27305 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27306 return 0;
27307 #endif
27308
27309 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27310 + BUG_ON(pr->id >= nr_cpu_ids);
27311
27312 /*
27313 * Buggy BIOS check
27314 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
27315 index 6e36d0c..f319944 100644
27316 --- a/drivers/acpi/sbs.c
27317 +++ b/drivers/acpi/sbs.c
27318 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
27319
27320 static ssize_t
27321 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27322 + size_t count, loff_t * ppos) __size_overflow(3);
27323 +static ssize_t
27324 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27325 size_t count, loff_t * ppos)
27326 {
27327 struct seq_file *seq = file->private_data;
27328 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27329 index c06e0ec..a2c06ba 100644
27330 --- a/drivers/ata/libata-core.c
27331 +++ b/drivers/ata/libata-core.c
27332 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27333 struct ata_port *ap;
27334 unsigned int tag;
27335
27336 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27337 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27338 ap = qc->ap;
27339
27340 qc->flags = 0;
27341 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27342 struct ata_port *ap;
27343 struct ata_link *link;
27344
27345 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27346 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27347 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27348 ap = qc->ap;
27349 link = qc->dev->link;
27350 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27351 return;
27352
27353 spin_lock(&lock);
27354 + pax_open_kernel();
27355
27356 for (cur = ops->inherits; cur; cur = cur->inherits) {
27357 void **inherit = (void **)cur;
27358 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27359 if (IS_ERR(*pp))
27360 *pp = NULL;
27361
27362 - ops->inherits = NULL;
27363 + *(struct ata_port_operations **)&ops->inherits = NULL;
27364
27365 + pax_close_kernel();
27366 spin_unlock(&lock);
27367 }
27368
27369 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27370 index 048589f..4002b98 100644
27371 --- a/drivers/ata/pata_arasan_cf.c
27372 +++ b/drivers/ata/pata_arasan_cf.c
27373 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27374 /* Handle platform specific quirks */
27375 if (pdata->quirk) {
27376 if (pdata->quirk & CF_BROKEN_PIO) {
27377 - ap->ops->set_piomode = NULL;
27378 + pax_open_kernel();
27379 + *(void **)&ap->ops->set_piomode = NULL;
27380 + pax_close_kernel();
27381 ap->pio_mask = 0;
27382 }
27383 if (pdata->quirk & CF_BROKEN_MWDMA)
27384 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27385 index f9b983a..887b9d8 100644
27386 --- a/drivers/atm/adummy.c
27387 +++ b/drivers/atm/adummy.c
27388 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27389 vcc->pop(vcc, skb);
27390 else
27391 dev_kfree_skb_any(skb);
27392 - atomic_inc(&vcc->stats->tx);
27393 + atomic_inc_unchecked(&vcc->stats->tx);
27394
27395 return 0;
27396 }
27397 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27398 index f8f41e0..1f987dd 100644
27399 --- a/drivers/atm/ambassador.c
27400 +++ b/drivers/atm/ambassador.c
27401 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27402 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27403
27404 // VC layer stats
27405 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27406 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27407
27408 // free the descriptor
27409 kfree (tx_descr);
27410 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27411 dump_skb ("<<<", vc, skb);
27412
27413 // VC layer stats
27414 - atomic_inc(&atm_vcc->stats->rx);
27415 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27416 __net_timestamp(skb);
27417 // end of our responsibility
27418 atm_vcc->push (atm_vcc, skb);
27419 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27420 } else {
27421 PRINTK (KERN_INFO, "dropped over-size frame");
27422 // should we count this?
27423 - atomic_inc(&atm_vcc->stats->rx_drop);
27424 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27425 }
27426
27427 } else {
27428 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27429 }
27430
27431 if (check_area (skb->data, skb->len)) {
27432 - atomic_inc(&atm_vcc->stats->tx_err);
27433 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27434 return -ENOMEM; // ?
27435 }
27436
27437 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27438 index b22d71c..d6e1049 100644
27439 --- a/drivers/atm/atmtcp.c
27440 +++ b/drivers/atm/atmtcp.c
27441 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27442 if (vcc->pop) vcc->pop(vcc,skb);
27443 else dev_kfree_skb(skb);
27444 if (dev_data) return 0;
27445 - atomic_inc(&vcc->stats->tx_err);
27446 + atomic_inc_unchecked(&vcc->stats->tx_err);
27447 return -ENOLINK;
27448 }
27449 size = skb->len+sizeof(struct atmtcp_hdr);
27450 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27451 if (!new_skb) {
27452 if (vcc->pop) vcc->pop(vcc,skb);
27453 else dev_kfree_skb(skb);
27454 - atomic_inc(&vcc->stats->tx_err);
27455 + atomic_inc_unchecked(&vcc->stats->tx_err);
27456 return -ENOBUFS;
27457 }
27458 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27459 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27460 if (vcc->pop) vcc->pop(vcc,skb);
27461 else dev_kfree_skb(skb);
27462 out_vcc->push(out_vcc,new_skb);
27463 - atomic_inc(&vcc->stats->tx);
27464 - atomic_inc(&out_vcc->stats->rx);
27465 + atomic_inc_unchecked(&vcc->stats->tx);
27466 + atomic_inc_unchecked(&out_vcc->stats->rx);
27467 return 0;
27468 }
27469
27470 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27471 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27472 read_unlock(&vcc_sklist_lock);
27473 if (!out_vcc) {
27474 - atomic_inc(&vcc->stats->tx_err);
27475 + atomic_inc_unchecked(&vcc->stats->tx_err);
27476 goto done;
27477 }
27478 skb_pull(skb,sizeof(struct atmtcp_hdr));
27479 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27480 __net_timestamp(new_skb);
27481 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27482 out_vcc->push(out_vcc,new_skb);
27483 - atomic_inc(&vcc->stats->tx);
27484 - atomic_inc(&out_vcc->stats->rx);
27485 + atomic_inc_unchecked(&vcc->stats->tx);
27486 + atomic_inc_unchecked(&out_vcc->stats->rx);
27487 done:
27488 if (vcc->pop) vcc->pop(vcc,skb);
27489 else dev_kfree_skb(skb);
27490 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27491 index 956e9ac..133516d 100644
27492 --- a/drivers/atm/eni.c
27493 +++ b/drivers/atm/eni.c
27494 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27495 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27496 vcc->dev->number);
27497 length = 0;
27498 - atomic_inc(&vcc->stats->rx_err);
27499 + atomic_inc_unchecked(&vcc->stats->rx_err);
27500 }
27501 else {
27502 length = ATM_CELL_SIZE-1; /* no HEC */
27503 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27504 size);
27505 }
27506 eff = length = 0;
27507 - atomic_inc(&vcc->stats->rx_err);
27508 + atomic_inc_unchecked(&vcc->stats->rx_err);
27509 }
27510 else {
27511 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27512 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27513 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27514 vcc->dev->number,vcc->vci,length,size << 2,descr);
27515 length = eff = 0;
27516 - atomic_inc(&vcc->stats->rx_err);
27517 + atomic_inc_unchecked(&vcc->stats->rx_err);
27518 }
27519 }
27520 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27521 @@ -771,7 +771,7 @@ rx_dequeued++;
27522 vcc->push(vcc,skb);
27523 pushed++;
27524 }
27525 - atomic_inc(&vcc->stats->rx);
27526 + atomic_inc_unchecked(&vcc->stats->rx);
27527 }
27528 wake_up(&eni_dev->rx_wait);
27529 }
27530 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27531 PCI_DMA_TODEVICE);
27532 if (vcc->pop) vcc->pop(vcc,skb);
27533 else dev_kfree_skb_irq(skb);
27534 - atomic_inc(&vcc->stats->tx);
27535 + atomic_inc_unchecked(&vcc->stats->tx);
27536 wake_up(&eni_dev->tx_wait);
27537 dma_complete++;
27538 }
27539 @@ -1569,7 +1569,7 @@ tx_complete++;
27540 /*--------------------------------- entries ---------------------------------*/
27541
27542
27543 -static const char *media_name[] __devinitdata = {
27544 +static const char *media_name[] __devinitconst = {
27545 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27546 "UTP", "05?", "06?", "07?", /* 4- 7 */
27547 "TAXI","09?", "10?", "11?", /* 8-11 */
27548 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27549 index 5072f8a..fa52520d 100644
27550 --- a/drivers/atm/firestream.c
27551 +++ b/drivers/atm/firestream.c
27552 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27553 }
27554 }
27555
27556 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27557 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27558
27559 fs_dprintk (FS_DEBUG_TXMEM, "i");
27560 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27561 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27562 #endif
27563 skb_put (skb, qe->p1 & 0xffff);
27564 ATM_SKB(skb)->vcc = atm_vcc;
27565 - atomic_inc(&atm_vcc->stats->rx);
27566 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27567 __net_timestamp(skb);
27568 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27569 atm_vcc->push (atm_vcc, skb);
27570 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27571 kfree (pe);
27572 }
27573 if (atm_vcc)
27574 - atomic_inc(&atm_vcc->stats->rx_drop);
27575 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27576 break;
27577 case 0x1f: /* Reassembly abort: no buffers. */
27578 /* Silently increment error counter. */
27579 if (atm_vcc)
27580 - atomic_inc(&atm_vcc->stats->rx_drop);
27581 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27582 break;
27583 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27584 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27585 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27586 index 361f5ae..7fc552d 100644
27587 --- a/drivers/atm/fore200e.c
27588 +++ b/drivers/atm/fore200e.c
27589 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27590 #endif
27591 /* check error condition */
27592 if (*entry->status & STATUS_ERROR)
27593 - atomic_inc(&vcc->stats->tx_err);
27594 + atomic_inc_unchecked(&vcc->stats->tx_err);
27595 else
27596 - atomic_inc(&vcc->stats->tx);
27597 + atomic_inc_unchecked(&vcc->stats->tx);
27598 }
27599 }
27600
27601 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27602 if (skb == NULL) {
27603 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27604
27605 - atomic_inc(&vcc->stats->rx_drop);
27606 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27607 return -ENOMEM;
27608 }
27609
27610 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27611
27612 dev_kfree_skb_any(skb);
27613
27614 - atomic_inc(&vcc->stats->rx_drop);
27615 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27616 return -ENOMEM;
27617 }
27618
27619 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27620
27621 vcc->push(vcc, skb);
27622 - atomic_inc(&vcc->stats->rx);
27623 + atomic_inc_unchecked(&vcc->stats->rx);
27624
27625 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27626
27627 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27628 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27629 fore200e->atm_dev->number,
27630 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27631 - atomic_inc(&vcc->stats->rx_err);
27632 + atomic_inc_unchecked(&vcc->stats->rx_err);
27633 }
27634 }
27635
27636 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27637 goto retry_here;
27638 }
27639
27640 - atomic_inc(&vcc->stats->tx_err);
27641 + atomic_inc_unchecked(&vcc->stats->tx_err);
27642
27643 fore200e->tx_sat++;
27644 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27645 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27646 index b182c2f..1c6fa8a 100644
27647 --- a/drivers/atm/he.c
27648 +++ b/drivers/atm/he.c
27649 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27650
27651 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27652 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27653 - atomic_inc(&vcc->stats->rx_drop);
27654 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27655 goto return_host_buffers;
27656 }
27657
27658 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27659 RBRQ_LEN_ERR(he_dev->rbrq_head)
27660 ? "LEN_ERR" : "",
27661 vcc->vpi, vcc->vci);
27662 - atomic_inc(&vcc->stats->rx_err);
27663 + atomic_inc_unchecked(&vcc->stats->rx_err);
27664 goto return_host_buffers;
27665 }
27666
27667 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27668 vcc->push(vcc, skb);
27669 spin_lock(&he_dev->global_lock);
27670
27671 - atomic_inc(&vcc->stats->rx);
27672 + atomic_inc_unchecked(&vcc->stats->rx);
27673
27674 return_host_buffers:
27675 ++pdus_assembled;
27676 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27677 tpd->vcc->pop(tpd->vcc, tpd->skb);
27678 else
27679 dev_kfree_skb_any(tpd->skb);
27680 - atomic_inc(&tpd->vcc->stats->tx_err);
27681 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27682 }
27683 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27684 return;
27685 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27686 vcc->pop(vcc, skb);
27687 else
27688 dev_kfree_skb_any(skb);
27689 - atomic_inc(&vcc->stats->tx_err);
27690 + atomic_inc_unchecked(&vcc->stats->tx_err);
27691 return -EINVAL;
27692 }
27693
27694 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27695 vcc->pop(vcc, skb);
27696 else
27697 dev_kfree_skb_any(skb);
27698 - atomic_inc(&vcc->stats->tx_err);
27699 + atomic_inc_unchecked(&vcc->stats->tx_err);
27700 return -EINVAL;
27701 }
27702 #endif
27703 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27704 vcc->pop(vcc, skb);
27705 else
27706 dev_kfree_skb_any(skb);
27707 - atomic_inc(&vcc->stats->tx_err);
27708 + atomic_inc_unchecked(&vcc->stats->tx_err);
27709 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27710 return -ENOMEM;
27711 }
27712 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27713 vcc->pop(vcc, skb);
27714 else
27715 dev_kfree_skb_any(skb);
27716 - atomic_inc(&vcc->stats->tx_err);
27717 + atomic_inc_unchecked(&vcc->stats->tx_err);
27718 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27719 return -ENOMEM;
27720 }
27721 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27722 __enqueue_tpd(he_dev, tpd, cid);
27723 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27724
27725 - atomic_inc(&vcc->stats->tx);
27726 + atomic_inc_unchecked(&vcc->stats->tx);
27727
27728 return 0;
27729 }
27730 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27731 index b812103..e391a49 100644
27732 --- a/drivers/atm/horizon.c
27733 +++ b/drivers/atm/horizon.c
27734 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27735 {
27736 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27737 // VC layer stats
27738 - atomic_inc(&vcc->stats->rx);
27739 + atomic_inc_unchecked(&vcc->stats->rx);
27740 __net_timestamp(skb);
27741 // end of our responsibility
27742 vcc->push (vcc, skb);
27743 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27744 dev->tx_iovec = NULL;
27745
27746 // VC layer stats
27747 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27748 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27749
27750 // free the skb
27751 hrz_kfree_skb (skb);
27752 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27753 index 1c05212..c28e200 100644
27754 --- a/drivers/atm/idt77252.c
27755 +++ b/drivers/atm/idt77252.c
27756 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27757 else
27758 dev_kfree_skb(skb);
27759
27760 - atomic_inc(&vcc->stats->tx);
27761 + atomic_inc_unchecked(&vcc->stats->tx);
27762 }
27763
27764 atomic_dec(&scq->used);
27765 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27766 if ((sb = dev_alloc_skb(64)) == NULL) {
27767 printk("%s: Can't allocate buffers for aal0.\n",
27768 card->name);
27769 - atomic_add(i, &vcc->stats->rx_drop);
27770 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27771 break;
27772 }
27773 if (!atm_charge(vcc, sb->truesize)) {
27774 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27775 card->name);
27776 - atomic_add(i - 1, &vcc->stats->rx_drop);
27777 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27778 dev_kfree_skb(sb);
27779 break;
27780 }
27781 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27782 ATM_SKB(sb)->vcc = vcc;
27783 __net_timestamp(sb);
27784 vcc->push(vcc, sb);
27785 - atomic_inc(&vcc->stats->rx);
27786 + atomic_inc_unchecked(&vcc->stats->rx);
27787
27788 cell += ATM_CELL_PAYLOAD;
27789 }
27790 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27791 "(CDC: %08x)\n",
27792 card->name, len, rpp->len, readl(SAR_REG_CDC));
27793 recycle_rx_pool_skb(card, rpp);
27794 - atomic_inc(&vcc->stats->rx_err);
27795 + atomic_inc_unchecked(&vcc->stats->rx_err);
27796 return;
27797 }
27798 if (stat & SAR_RSQE_CRC) {
27799 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27800 recycle_rx_pool_skb(card, rpp);
27801 - atomic_inc(&vcc->stats->rx_err);
27802 + atomic_inc_unchecked(&vcc->stats->rx_err);
27803 return;
27804 }
27805 if (skb_queue_len(&rpp->queue) > 1) {
27806 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27807 RXPRINTK("%s: Can't alloc RX skb.\n",
27808 card->name);
27809 recycle_rx_pool_skb(card, rpp);
27810 - atomic_inc(&vcc->stats->rx_err);
27811 + atomic_inc_unchecked(&vcc->stats->rx_err);
27812 return;
27813 }
27814 if (!atm_charge(vcc, skb->truesize)) {
27815 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27816 __net_timestamp(skb);
27817
27818 vcc->push(vcc, skb);
27819 - atomic_inc(&vcc->stats->rx);
27820 + atomic_inc_unchecked(&vcc->stats->rx);
27821
27822 return;
27823 }
27824 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27825 __net_timestamp(skb);
27826
27827 vcc->push(vcc, skb);
27828 - atomic_inc(&vcc->stats->rx);
27829 + atomic_inc_unchecked(&vcc->stats->rx);
27830
27831 if (skb->truesize > SAR_FB_SIZE_3)
27832 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27833 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27834 if (vcc->qos.aal != ATM_AAL0) {
27835 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27836 card->name, vpi, vci);
27837 - atomic_inc(&vcc->stats->rx_drop);
27838 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27839 goto drop;
27840 }
27841
27842 if ((sb = dev_alloc_skb(64)) == NULL) {
27843 printk("%s: Can't allocate buffers for AAL0.\n",
27844 card->name);
27845 - atomic_inc(&vcc->stats->rx_err);
27846 + atomic_inc_unchecked(&vcc->stats->rx_err);
27847 goto drop;
27848 }
27849
27850 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27851 ATM_SKB(sb)->vcc = vcc;
27852 __net_timestamp(sb);
27853 vcc->push(vcc, sb);
27854 - atomic_inc(&vcc->stats->rx);
27855 + atomic_inc_unchecked(&vcc->stats->rx);
27856
27857 drop:
27858 skb_pull(queue, 64);
27859 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27860
27861 if (vc == NULL) {
27862 printk("%s: NULL connection in send().\n", card->name);
27863 - atomic_inc(&vcc->stats->tx_err);
27864 + atomic_inc_unchecked(&vcc->stats->tx_err);
27865 dev_kfree_skb(skb);
27866 return -EINVAL;
27867 }
27868 if (!test_bit(VCF_TX, &vc->flags)) {
27869 printk("%s: Trying to transmit on a non-tx VC.\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 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27876 break;
27877 default:
27878 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27879 - atomic_inc(&vcc->stats->tx_err);
27880 + atomic_inc_unchecked(&vcc->stats->tx_err);
27881 dev_kfree_skb(skb);
27882 return -EINVAL;
27883 }
27884
27885 if (skb_shinfo(skb)->nr_frags != 0) {
27886 printk("%s: No scatter-gather yet.\n", card->name);
27887 - atomic_inc(&vcc->stats->tx_err);
27888 + atomic_inc_unchecked(&vcc->stats->tx_err);
27889 dev_kfree_skb(skb);
27890 return -EINVAL;
27891 }
27892 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27893
27894 err = queue_skb(card, vc, skb, oam);
27895 if (err) {
27896 - atomic_inc(&vcc->stats->tx_err);
27897 + atomic_inc_unchecked(&vcc->stats->tx_err);
27898 dev_kfree_skb(skb);
27899 return err;
27900 }
27901 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27902 skb = dev_alloc_skb(64);
27903 if (!skb) {
27904 printk("%s: Out of memory in send_oam().\n", card->name);
27905 - atomic_inc(&vcc->stats->tx_err);
27906 + atomic_inc_unchecked(&vcc->stats->tx_err);
27907 return -ENOMEM;
27908 }
27909 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27910 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27911 index 9e373ba..cf93727 100644
27912 --- a/drivers/atm/iphase.c
27913 +++ b/drivers/atm/iphase.c
27914 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27915 status = (u_short) (buf_desc_ptr->desc_mode);
27916 if (status & (RX_CER | RX_PTE | RX_OFL))
27917 {
27918 - atomic_inc(&vcc->stats->rx_err);
27919 + atomic_inc_unchecked(&vcc->stats->rx_err);
27920 IF_ERR(printk("IA: bad packet, dropping it");)
27921 if (status & RX_CER) {
27922 IF_ERR(printk(" cause: packet CRC error\n");)
27923 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27924 len = dma_addr - buf_addr;
27925 if (len > iadev->rx_buf_sz) {
27926 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27927 - atomic_inc(&vcc->stats->rx_err);
27928 + atomic_inc_unchecked(&vcc->stats->rx_err);
27929 goto out_free_desc;
27930 }
27931
27932 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27933 ia_vcc = INPH_IA_VCC(vcc);
27934 if (ia_vcc == NULL)
27935 {
27936 - atomic_inc(&vcc->stats->rx_err);
27937 + atomic_inc_unchecked(&vcc->stats->rx_err);
27938 atm_return(vcc, skb->truesize);
27939 dev_kfree_skb_any(skb);
27940 goto INCR_DLE;
27941 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27942 if ((length > iadev->rx_buf_sz) || (length >
27943 (skb->len - sizeof(struct cpcs_trailer))))
27944 {
27945 - atomic_inc(&vcc->stats->rx_err);
27946 + atomic_inc_unchecked(&vcc->stats->rx_err);
27947 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27948 length, skb->len);)
27949 atm_return(vcc, skb->truesize);
27950 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27951
27952 IF_RX(printk("rx_dle_intr: skb push");)
27953 vcc->push(vcc,skb);
27954 - atomic_inc(&vcc->stats->rx);
27955 + atomic_inc_unchecked(&vcc->stats->rx);
27956 iadev->rx_pkt_cnt++;
27957 }
27958 INCR_DLE:
27959 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27960 {
27961 struct k_sonet_stats *stats;
27962 stats = &PRIV(_ia_dev[board])->sonet_stats;
27963 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27964 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27965 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27966 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27967 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27968 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27969 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27970 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27971 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27972 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27973 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27974 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27975 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27976 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27977 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27978 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27979 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27980 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27981 }
27982 ia_cmds.status = 0;
27983 break;
27984 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27985 if ((desc == 0) || (desc > iadev->num_tx_desc))
27986 {
27987 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27988 - atomic_inc(&vcc->stats->tx);
27989 + atomic_inc_unchecked(&vcc->stats->tx);
27990 if (vcc->pop)
27991 vcc->pop(vcc, skb);
27992 else
27993 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27994 ATM_DESC(skb) = vcc->vci;
27995 skb_queue_tail(&iadev->tx_dma_q, skb);
27996
27997 - atomic_inc(&vcc->stats->tx);
27998 + atomic_inc_unchecked(&vcc->stats->tx);
27999 iadev->tx_pkt_cnt++;
28000 /* Increment transaction counter */
28001 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28002
28003 #if 0
28004 /* add flow control logic */
28005 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28006 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28007 if (iavcc->vc_desc_cnt > 10) {
28008 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28009 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28010 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28011 index f556969..0da15eb 100644
28012 --- a/drivers/atm/lanai.c
28013 +++ b/drivers/atm/lanai.c
28014 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28015 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28016 lanai_endtx(lanai, lvcc);
28017 lanai_free_skb(lvcc->tx.atmvcc, skb);
28018 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28019 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28020 }
28021
28022 /* Try to fill the buffer - don't call unless there is backlog */
28023 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28024 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28025 __net_timestamp(skb);
28026 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28027 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28028 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28029 out:
28030 lvcc->rx.buf.ptr = end;
28031 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28032 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28033 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28034 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28035 lanai->stats.service_rxnotaal5++;
28036 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28037 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28038 return 0;
28039 }
28040 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28041 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28042 int bytes;
28043 read_unlock(&vcc_sklist_lock);
28044 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28045 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28046 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28047 lvcc->stats.x.aal5.service_trash++;
28048 bytes = (SERVICE_GET_END(s) * 16) -
28049 (((unsigned long) lvcc->rx.buf.ptr) -
28050 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28051 }
28052 if (s & SERVICE_STREAM) {
28053 read_unlock(&vcc_sklist_lock);
28054 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28055 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28056 lvcc->stats.x.aal5.service_stream++;
28057 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28058 "PDU on VCI %d!\n", lanai->number, vci);
28059 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28060 return 0;
28061 }
28062 DPRINTK("got rx crc error on vci %d\n", vci);
28063 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28064 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28065 lvcc->stats.x.aal5.service_rxcrc++;
28066 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28067 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28068 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28069 index 1c70c45..300718d 100644
28070 --- a/drivers/atm/nicstar.c
28071 +++ b/drivers/atm/nicstar.c
28072 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28073 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28074 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28075 card->index);
28076 - atomic_inc(&vcc->stats->tx_err);
28077 + atomic_inc_unchecked(&vcc->stats->tx_err);
28078 dev_kfree_skb_any(skb);
28079 return -EINVAL;
28080 }
28081 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28082 if (!vc->tx) {
28083 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28084 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 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28091 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28092 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28093 card->index);
28094 - atomic_inc(&vcc->stats->tx_err);
28095 + atomic_inc_unchecked(&vcc->stats->tx_err);
28096 dev_kfree_skb_any(skb);
28097 return -EINVAL;
28098 }
28099
28100 if (skb_shinfo(skb)->nr_frags != 0) {
28101 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28102 - atomic_inc(&vcc->stats->tx_err);
28103 + atomic_inc_unchecked(&vcc->stats->tx_err);
28104 dev_kfree_skb_any(skb);
28105 return -EINVAL;
28106 }
28107 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28108 }
28109
28110 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28111 - atomic_inc(&vcc->stats->tx_err);
28112 + atomic_inc_unchecked(&vcc->stats->tx_err);
28113 dev_kfree_skb_any(skb);
28114 return -EIO;
28115 }
28116 - atomic_inc(&vcc->stats->tx);
28117 + atomic_inc_unchecked(&vcc->stats->tx);
28118
28119 return 0;
28120 }
28121 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28122 printk
28123 ("nicstar%d: Can't allocate buffers for aal0.\n",
28124 card->index);
28125 - atomic_add(i, &vcc->stats->rx_drop);
28126 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28127 break;
28128 }
28129 if (!atm_charge(vcc, sb->truesize)) {
28130 RXPRINTK
28131 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28132 card->index);
28133 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28134 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28135 dev_kfree_skb_any(sb);
28136 break;
28137 }
28138 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28139 ATM_SKB(sb)->vcc = vcc;
28140 __net_timestamp(sb);
28141 vcc->push(vcc, sb);
28142 - atomic_inc(&vcc->stats->rx);
28143 + atomic_inc_unchecked(&vcc->stats->rx);
28144 cell += ATM_CELL_PAYLOAD;
28145 }
28146
28147 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28148 if (iovb == NULL) {
28149 printk("nicstar%d: Out of iovec buffers.\n",
28150 card->index);
28151 - atomic_inc(&vcc->stats->rx_drop);
28152 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28153 recycle_rx_buf(card, skb);
28154 return;
28155 }
28156 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28157 small or large buffer itself. */
28158 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28159 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28160 - atomic_inc(&vcc->stats->rx_err);
28161 + atomic_inc_unchecked(&vcc->stats->rx_err);
28162 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28163 NS_MAX_IOVECS);
28164 NS_PRV_IOVCNT(iovb) = 0;
28165 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28166 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28167 card->index);
28168 which_list(card, skb);
28169 - atomic_inc(&vcc->stats->rx_err);
28170 + atomic_inc_unchecked(&vcc->stats->rx_err);
28171 recycle_rx_buf(card, skb);
28172 vc->rx_iov = NULL;
28173 recycle_iov_buf(card, iovb);
28174 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28175 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28176 card->index);
28177 which_list(card, skb);
28178 - atomic_inc(&vcc->stats->rx_err);
28179 + atomic_inc_unchecked(&vcc->stats->rx_err);
28180 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28181 NS_PRV_IOVCNT(iovb));
28182 vc->rx_iov = NULL;
28183 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28184 printk(" - PDU size mismatch.\n");
28185 else
28186 printk(".\n");
28187 - atomic_inc(&vcc->stats->rx_err);
28188 + atomic_inc_unchecked(&vcc->stats->rx_err);
28189 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28190 NS_PRV_IOVCNT(iovb));
28191 vc->rx_iov = NULL;
28192 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28193 /* skb points to a small buffer */
28194 if (!atm_charge(vcc, skb->truesize)) {
28195 push_rxbufs(card, skb);
28196 - atomic_inc(&vcc->stats->rx_drop);
28197 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28198 } else {
28199 skb_put(skb, len);
28200 dequeue_sm_buf(card, skb);
28201 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28202 ATM_SKB(skb)->vcc = vcc;
28203 __net_timestamp(skb);
28204 vcc->push(vcc, skb);
28205 - atomic_inc(&vcc->stats->rx);
28206 + atomic_inc_unchecked(&vcc->stats->rx);
28207 }
28208 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28209 struct sk_buff *sb;
28210 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28211 if (len <= NS_SMBUFSIZE) {
28212 if (!atm_charge(vcc, sb->truesize)) {
28213 push_rxbufs(card, sb);
28214 - atomic_inc(&vcc->stats->rx_drop);
28215 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28216 } else {
28217 skb_put(sb, len);
28218 dequeue_sm_buf(card, sb);
28219 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28220 ATM_SKB(sb)->vcc = vcc;
28221 __net_timestamp(sb);
28222 vcc->push(vcc, sb);
28223 - atomic_inc(&vcc->stats->rx);
28224 + atomic_inc_unchecked(&vcc->stats->rx);
28225 }
28226
28227 push_rxbufs(card, skb);
28228 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28229
28230 if (!atm_charge(vcc, skb->truesize)) {
28231 push_rxbufs(card, skb);
28232 - atomic_inc(&vcc->stats->rx_drop);
28233 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28234 } else {
28235 dequeue_lg_buf(card, skb);
28236 #ifdef NS_USE_DESTRUCTORS
28237 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28238 ATM_SKB(skb)->vcc = vcc;
28239 __net_timestamp(skb);
28240 vcc->push(vcc, skb);
28241 - atomic_inc(&vcc->stats->rx);
28242 + atomic_inc_unchecked(&vcc->stats->rx);
28243 }
28244
28245 push_rxbufs(card, sb);
28246 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28247 printk
28248 ("nicstar%d: Out of huge buffers.\n",
28249 card->index);
28250 - atomic_inc(&vcc->stats->rx_drop);
28251 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28252 recycle_iovec_rx_bufs(card,
28253 (struct iovec *)
28254 iovb->data,
28255 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28256 card->hbpool.count++;
28257 } else
28258 dev_kfree_skb_any(hb);
28259 - atomic_inc(&vcc->stats->rx_drop);
28260 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28261 } else {
28262 /* Copy the small buffer to the huge buffer */
28263 sb = (struct sk_buff *)iov->iov_base;
28264 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28265 #endif /* NS_USE_DESTRUCTORS */
28266 __net_timestamp(hb);
28267 vcc->push(vcc, hb);
28268 - atomic_inc(&vcc->stats->rx);
28269 + atomic_inc_unchecked(&vcc->stats->rx);
28270 }
28271 }
28272
28273 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28274 index e8cd652..bbbd1fc 100644
28275 --- a/drivers/atm/solos-pci.c
28276 +++ b/drivers/atm/solos-pci.c
28277 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28278 }
28279 atm_charge(vcc, skb->truesize);
28280 vcc->push(vcc, skb);
28281 - atomic_inc(&vcc->stats->rx);
28282 + atomic_inc_unchecked(&vcc->stats->rx);
28283 break;
28284
28285 case PKT_STATUS:
28286 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28287 vcc = SKB_CB(oldskb)->vcc;
28288
28289 if (vcc) {
28290 - atomic_inc(&vcc->stats->tx);
28291 + atomic_inc_unchecked(&vcc->stats->tx);
28292 solos_pop(vcc, oldskb);
28293 } else
28294 dev_kfree_skb_irq(oldskb);
28295 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28296 index 90f1ccc..04c4a1e 100644
28297 --- a/drivers/atm/suni.c
28298 +++ b/drivers/atm/suni.c
28299 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28300
28301
28302 #define ADD_LIMITED(s,v) \
28303 - atomic_add((v),&stats->s); \
28304 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28305 + atomic_add_unchecked((v),&stats->s); \
28306 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28307
28308
28309 static void suni_hz(unsigned long from_timer)
28310 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28311 index 5120a96..e2572bd 100644
28312 --- a/drivers/atm/uPD98402.c
28313 +++ b/drivers/atm/uPD98402.c
28314 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28315 struct sonet_stats tmp;
28316 int error = 0;
28317
28318 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28319 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28320 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28321 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28322 if (zero && !error) {
28323 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28324
28325
28326 #define ADD_LIMITED(s,v) \
28327 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28328 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28329 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28330 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28331 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28332 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28333
28334
28335 static void stat_event(struct atm_dev *dev)
28336 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28337 if (reason & uPD98402_INT_PFM) stat_event(dev);
28338 if (reason & uPD98402_INT_PCO) {
28339 (void) GET(PCOCR); /* clear interrupt cause */
28340 - atomic_add(GET(HECCT),
28341 + atomic_add_unchecked(GET(HECCT),
28342 &PRIV(dev)->sonet_stats.uncorr_hcs);
28343 }
28344 if ((reason & uPD98402_INT_RFO) &&
28345 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28346 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28347 uPD98402_INT_LOS),PIMR); /* enable them */
28348 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28349 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28350 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28351 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28352 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28353 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28354 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28355 return 0;
28356 }
28357
28358 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28359 index d889f56..17eb71e 100644
28360 --- a/drivers/atm/zatm.c
28361 +++ b/drivers/atm/zatm.c
28362 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28363 }
28364 if (!size) {
28365 dev_kfree_skb_irq(skb);
28366 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28367 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28368 continue;
28369 }
28370 if (!atm_charge(vcc,skb->truesize)) {
28371 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28372 skb->len = size;
28373 ATM_SKB(skb)->vcc = vcc;
28374 vcc->push(vcc,skb);
28375 - atomic_inc(&vcc->stats->rx);
28376 + atomic_inc_unchecked(&vcc->stats->rx);
28377 }
28378 zout(pos & 0xffff,MTA(mbx));
28379 #if 0 /* probably a stupid idea */
28380 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28381 skb_queue_head(&zatm_vcc->backlog,skb);
28382 break;
28383 }
28384 - atomic_inc(&vcc->stats->tx);
28385 + atomic_inc_unchecked(&vcc->stats->tx);
28386 wake_up(&zatm_vcc->tx_wait);
28387 }
28388
28389 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28390 index 8493536..31adee0 100644
28391 --- a/drivers/base/devtmpfs.c
28392 +++ b/drivers/base/devtmpfs.c
28393 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28394 if (!thread)
28395 return 0;
28396
28397 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28398 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28399 if (err)
28400 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28401 else
28402 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28403 index caf995f..6f76697 100644
28404 --- a/drivers/base/power/wakeup.c
28405 +++ b/drivers/base/power/wakeup.c
28406 @@ -30,14 +30,14 @@ bool events_check_enabled;
28407 * They need to be modified together atomically, so it's better to use one
28408 * atomic variable to hold them both.
28409 */
28410 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28411 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28412
28413 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28414 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28415
28416 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28417 {
28418 - unsigned int comb = atomic_read(&combined_event_count);
28419 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28420
28421 *cnt = (comb >> IN_PROGRESS_BITS);
28422 *inpr = comb & MAX_IN_PROGRESS;
28423 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28424 ws->last_time = ktime_get();
28425
28426 /* Increment the counter of events in progress. */
28427 - atomic_inc(&combined_event_count);
28428 + atomic_inc_unchecked(&combined_event_count);
28429 }
28430
28431 /**
28432 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28433 * Increment the counter of registered wakeup events and decrement the
28434 * couter of wakeup events in progress simultaneously.
28435 */
28436 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28437 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28438 }
28439
28440 /**
28441 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28442 index b0f553b..77b928b 100644
28443 --- a/drivers/block/cciss.c
28444 +++ b/drivers/block/cciss.c
28445 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28446 int err;
28447 u32 cp;
28448
28449 + memset(&arg64, 0, sizeof(arg64));
28450 +
28451 err = 0;
28452 err |=
28453 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28454 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28455 while (!list_empty(&h->reqQ)) {
28456 c = list_entry(h->reqQ.next, CommandList_struct, list);
28457 /* can't do anything if fifo is full */
28458 - if ((h->access.fifo_full(h))) {
28459 + if ((h->access->fifo_full(h))) {
28460 dev_warn(&h->pdev->dev, "fifo full\n");
28461 break;
28462 }
28463 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28464 h->Qdepth--;
28465
28466 /* Tell the controller execute command */
28467 - h->access.submit_command(h, c);
28468 + h->access->submit_command(h, c);
28469
28470 /* Put job onto the completed Q */
28471 addQ(&h->cmpQ, c);
28472 @@ -3443,17 +3445,17 @@ startio:
28473
28474 static inline unsigned long get_next_completion(ctlr_info_t *h)
28475 {
28476 - return h->access.command_completed(h);
28477 + return h->access->command_completed(h);
28478 }
28479
28480 static inline int interrupt_pending(ctlr_info_t *h)
28481 {
28482 - return h->access.intr_pending(h);
28483 + return h->access->intr_pending(h);
28484 }
28485
28486 static inline long interrupt_not_for_us(ctlr_info_t *h)
28487 {
28488 - return ((h->access.intr_pending(h) == 0) ||
28489 + return ((h->access->intr_pending(h) == 0) ||
28490 (h->interrupts_enabled == 0));
28491 }
28492
28493 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28494 u32 a;
28495
28496 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28497 - return h->access.command_completed(h);
28498 + return h->access->command_completed(h);
28499
28500 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28501 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28502 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28503 trans_support & CFGTBL_Trans_use_short_tags);
28504
28505 /* Change the access methods to the performant access methods */
28506 - h->access = SA5_performant_access;
28507 + h->access = &SA5_performant_access;
28508 h->transMethod = CFGTBL_Trans_Performant;
28509
28510 return;
28511 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28512 if (prod_index < 0)
28513 return -ENODEV;
28514 h->product_name = products[prod_index].product_name;
28515 - h->access = *(products[prod_index].access);
28516 + h->access = products[prod_index].access;
28517
28518 if (cciss_board_disabled(h)) {
28519 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28520 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28521 }
28522
28523 /* make sure the board interrupts are off */
28524 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28525 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28526 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28527 if (rc)
28528 goto clean2;
28529 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28530 * fake ones to scoop up any residual completions.
28531 */
28532 spin_lock_irqsave(&h->lock, flags);
28533 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28534 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28535 spin_unlock_irqrestore(&h->lock, flags);
28536 free_irq(h->intr[h->intr_mode], h);
28537 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28538 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28539 dev_info(&h->pdev->dev, "Board READY.\n");
28540 dev_info(&h->pdev->dev,
28541 "Waiting for stale completions to drain.\n");
28542 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28543 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28544 msleep(10000);
28545 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28546 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28547
28548 rc = controller_reset_failed(h->cfgtable);
28549 if (rc)
28550 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28551 cciss_scsi_setup(h);
28552
28553 /* Turn the interrupts on so we can service requests */
28554 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28555 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28556
28557 /* Get the firmware version */
28558 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28559 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28560 kfree(flush_buf);
28561 if (return_code != IO_OK)
28562 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28563 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28564 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28565 free_irq(h->intr[h->intr_mode], h);
28566 }
28567
28568 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28569 index 7fda30e..eb5dfe0 100644
28570 --- a/drivers/block/cciss.h
28571 +++ b/drivers/block/cciss.h
28572 @@ -101,7 +101,7 @@ struct ctlr_info
28573 /* information about each logical volume */
28574 drive_info_struct *drv[CISS_MAX_LUN];
28575
28576 - struct access_method access;
28577 + struct access_method *access;
28578
28579 /* queue and queue Info */
28580 struct list_head reqQ;
28581 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28582 index 9125bbe..eede5c8 100644
28583 --- a/drivers/block/cpqarray.c
28584 +++ b/drivers/block/cpqarray.c
28585 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28586 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28587 goto Enomem4;
28588 }
28589 - hba[i]->access.set_intr_mask(hba[i], 0);
28590 + hba[i]->access->set_intr_mask(hba[i], 0);
28591 if (request_irq(hba[i]->intr, do_ida_intr,
28592 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28593 {
28594 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28595 add_timer(&hba[i]->timer);
28596
28597 /* Enable IRQ now that spinlock and rate limit timer are set up */
28598 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28599 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28600
28601 for(j=0; j<NWD; j++) {
28602 struct gendisk *disk = ida_gendisk[i][j];
28603 @@ -694,7 +694,7 @@ DBGINFO(
28604 for(i=0; i<NR_PRODUCTS; i++) {
28605 if (board_id == products[i].board_id) {
28606 c->product_name = products[i].product_name;
28607 - c->access = *(products[i].access);
28608 + c->access = products[i].access;
28609 break;
28610 }
28611 }
28612 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28613 hba[ctlr]->intr = intr;
28614 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28615 hba[ctlr]->product_name = products[j].product_name;
28616 - hba[ctlr]->access = *(products[j].access);
28617 + hba[ctlr]->access = products[j].access;
28618 hba[ctlr]->ctlr = ctlr;
28619 hba[ctlr]->board_id = board_id;
28620 hba[ctlr]->pci_dev = NULL; /* not PCI */
28621 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28622
28623 while((c = h->reqQ) != NULL) {
28624 /* Can't do anything if we're busy */
28625 - if (h->access.fifo_full(h) == 0)
28626 + if (h->access->fifo_full(h) == 0)
28627 return;
28628
28629 /* Get the first entry from the request Q */
28630 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28631 h->Qdepth--;
28632
28633 /* Tell the controller to do our bidding */
28634 - h->access.submit_command(h, c);
28635 + h->access->submit_command(h, c);
28636
28637 /* Get onto the completion Q */
28638 addQ(&h->cmpQ, c);
28639 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28640 unsigned long flags;
28641 __u32 a,a1;
28642
28643 - istat = h->access.intr_pending(h);
28644 + istat = h->access->intr_pending(h);
28645 /* Is this interrupt for us? */
28646 if (istat == 0)
28647 return IRQ_NONE;
28648 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28649 */
28650 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28651 if (istat & FIFO_NOT_EMPTY) {
28652 - while((a = h->access.command_completed(h))) {
28653 + while((a = h->access->command_completed(h))) {
28654 a1 = a; a &= ~3;
28655 if ((c = h->cmpQ) == NULL)
28656 {
28657 @@ -1449,11 +1449,11 @@ static int sendcmd(
28658 /*
28659 * Disable interrupt
28660 */
28661 - info_p->access.set_intr_mask(info_p, 0);
28662 + info_p->access->set_intr_mask(info_p, 0);
28663 /* Make sure there is room in the command FIFO */
28664 /* Actually it should be completely empty at this time. */
28665 for (i = 200000; i > 0; i--) {
28666 - temp = info_p->access.fifo_full(info_p);
28667 + temp = info_p->access->fifo_full(info_p);
28668 if (temp != 0) {
28669 break;
28670 }
28671 @@ -1466,7 +1466,7 @@ DBG(
28672 /*
28673 * Send the cmd
28674 */
28675 - info_p->access.submit_command(info_p, c);
28676 + info_p->access->submit_command(info_p, c);
28677 complete = pollcomplete(ctlr);
28678
28679 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28680 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28681 * we check the new geometry. Then turn interrupts back on when
28682 * we're done.
28683 */
28684 - host->access.set_intr_mask(host, 0);
28685 + host->access->set_intr_mask(host, 0);
28686 getgeometry(ctlr);
28687 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28688 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28689
28690 for(i=0; i<NWD; i++) {
28691 struct gendisk *disk = ida_gendisk[ctlr][i];
28692 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28693 /* Wait (up to 2 seconds) for a command to complete */
28694
28695 for (i = 200000; i > 0; i--) {
28696 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28697 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28698 if (done == 0) {
28699 udelay(10); /* a short fixed delay */
28700 } else
28701 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28702 index be73e9d..7fbf140 100644
28703 --- a/drivers/block/cpqarray.h
28704 +++ b/drivers/block/cpqarray.h
28705 @@ -99,7 +99,7 @@ struct ctlr_info {
28706 drv_info_t drv[NWD];
28707 struct proc_dir_entry *proc;
28708
28709 - struct access_method access;
28710 + struct access_method *access;
28711
28712 cmdlist_t *reqQ;
28713 cmdlist_t *cmpQ;
28714 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28715 index 8d68056..e67050f 100644
28716 --- a/drivers/block/drbd/drbd_int.h
28717 +++ b/drivers/block/drbd/drbd_int.h
28718 @@ -736,7 +736,7 @@ struct drbd_request;
28719 struct drbd_epoch {
28720 struct list_head list;
28721 unsigned int barrier_nr;
28722 - atomic_t epoch_size; /* increased on every request added. */
28723 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28724 atomic_t active; /* increased on every req. added, and dec on every finished. */
28725 unsigned long flags;
28726 };
28727 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28728 void *int_dig_in;
28729 void *int_dig_vv;
28730 wait_queue_head_t seq_wait;
28731 - atomic_t packet_seq;
28732 + atomic_unchecked_t packet_seq;
28733 unsigned int peer_seq;
28734 spinlock_t peer_seq_lock;
28735 unsigned int minor;
28736 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28737
28738 static inline void drbd_tcp_cork(struct socket *sock)
28739 {
28740 - int __user val = 1;
28741 + int val = 1;
28742 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28743 - (char __user *)&val, sizeof(val));
28744 + (char __force_user *)&val, sizeof(val));
28745 }
28746
28747 static inline void drbd_tcp_uncork(struct socket *sock)
28748 {
28749 - int __user val = 0;
28750 + int val = 0;
28751 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28752 - (char __user *)&val, sizeof(val));
28753 + (char __force_user *)&val, sizeof(val));
28754 }
28755
28756 static inline void drbd_tcp_nodelay(struct socket *sock)
28757 {
28758 - int __user val = 1;
28759 + int val = 1;
28760 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28761 - (char __user *)&val, sizeof(val));
28762 + (char __force_user *)&val, sizeof(val));
28763 }
28764
28765 static inline void drbd_tcp_quickack(struct socket *sock)
28766 {
28767 - int __user val = 2;
28768 + int val = 2;
28769 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28770 - (char __user *)&val, sizeof(val));
28771 + (char __force_user *)&val, sizeof(val));
28772 }
28773
28774 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28775 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28776 index 211fc44..c5116f1 100644
28777 --- a/drivers/block/drbd/drbd_main.c
28778 +++ b/drivers/block/drbd/drbd_main.c
28779 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28780 p.sector = sector;
28781 p.block_id = block_id;
28782 p.blksize = blksize;
28783 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28784 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28785
28786 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28787 return false;
28788 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28789 p.sector = cpu_to_be64(req->sector);
28790 p.block_id = (unsigned long)req;
28791 p.seq_num = cpu_to_be32(req->seq_num =
28792 - atomic_add_return(1, &mdev->packet_seq));
28793 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28794
28795 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28796
28797 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28798 atomic_set(&mdev->unacked_cnt, 0);
28799 atomic_set(&mdev->local_cnt, 0);
28800 atomic_set(&mdev->net_cnt, 0);
28801 - atomic_set(&mdev->packet_seq, 0);
28802 + atomic_set_unchecked(&mdev->packet_seq, 0);
28803 atomic_set(&mdev->pp_in_use, 0);
28804 atomic_set(&mdev->pp_in_use_by_net, 0);
28805 atomic_set(&mdev->rs_sect_in, 0);
28806 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28807 mdev->receiver.t_state);
28808
28809 /* no need to lock it, I'm the only thread alive */
28810 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28811 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28812 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28813 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28814 mdev->al_writ_cnt =
28815 mdev->bm_writ_cnt =
28816 mdev->read_cnt =
28817 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28818 index af2a250..219c74b 100644
28819 --- a/drivers/block/drbd/drbd_nl.c
28820 +++ b/drivers/block/drbd/drbd_nl.c
28821 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28822 module_put(THIS_MODULE);
28823 }
28824
28825 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28826 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28827
28828 static unsigned short *
28829 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28830 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28831 cn_reply->id.idx = CN_IDX_DRBD;
28832 cn_reply->id.val = CN_VAL_DRBD;
28833
28834 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28835 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28836 cn_reply->ack = 0; /* not used here. */
28837 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28838 (int)((char *)tl - (char *)reply->tag_list);
28839 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28840 cn_reply->id.idx = CN_IDX_DRBD;
28841 cn_reply->id.val = CN_VAL_DRBD;
28842
28843 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28844 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28845 cn_reply->ack = 0; /* not used here. */
28846 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28847 (int)((char *)tl - (char *)reply->tag_list);
28848 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28849 cn_reply->id.idx = CN_IDX_DRBD;
28850 cn_reply->id.val = CN_VAL_DRBD;
28851
28852 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28853 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28854 cn_reply->ack = 0; // not used here.
28855 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28856 (int)((char*)tl - (char*)reply->tag_list);
28857 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28858 cn_reply->id.idx = CN_IDX_DRBD;
28859 cn_reply->id.val = CN_VAL_DRBD;
28860
28861 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28862 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28863 cn_reply->ack = 0; /* not used here. */
28864 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28865 (int)((char *)tl - (char *)reply->tag_list);
28866 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28867 index 43beaca..4a5b1dd 100644
28868 --- a/drivers/block/drbd/drbd_receiver.c
28869 +++ b/drivers/block/drbd/drbd_receiver.c
28870 @@ -894,7 +894,7 @@ retry:
28871 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28872 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28873
28874 - atomic_set(&mdev->packet_seq, 0);
28875 + atomic_set_unchecked(&mdev->packet_seq, 0);
28876 mdev->peer_seq = 0;
28877
28878 drbd_thread_start(&mdev->asender);
28879 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28880 do {
28881 next_epoch = NULL;
28882
28883 - epoch_size = atomic_read(&epoch->epoch_size);
28884 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28885
28886 switch (ev & ~EV_CLEANUP) {
28887 case EV_PUT:
28888 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28889 rv = FE_DESTROYED;
28890 } else {
28891 epoch->flags = 0;
28892 - atomic_set(&epoch->epoch_size, 0);
28893 + atomic_set_unchecked(&epoch->epoch_size, 0);
28894 /* atomic_set(&epoch->active, 0); is already zero */
28895 if (rv == FE_STILL_LIVE)
28896 rv = FE_RECYCLED;
28897 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28898 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28899 drbd_flush(mdev);
28900
28901 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28902 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28903 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28904 if (epoch)
28905 break;
28906 }
28907
28908 epoch = mdev->current_epoch;
28909 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28910 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28911
28912 D_ASSERT(atomic_read(&epoch->active) == 0);
28913 D_ASSERT(epoch->flags == 0);
28914 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28915 }
28916
28917 epoch->flags = 0;
28918 - atomic_set(&epoch->epoch_size, 0);
28919 + atomic_set_unchecked(&epoch->epoch_size, 0);
28920 atomic_set(&epoch->active, 0);
28921
28922 spin_lock(&mdev->epoch_lock);
28923 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28924 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28925 list_add(&epoch->list, &mdev->current_epoch->list);
28926 mdev->current_epoch = epoch;
28927 mdev->epochs++;
28928 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28929 spin_unlock(&mdev->peer_seq_lock);
28930
28931 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28932 - atomic_inc(&mdev->current_epoch->epoch_size);
28933 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28934 return drbd_drain_block(mdev, data_size);
28935 }
28936
28937 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28938
28939 spin_lock(&mdev->epoch_lock);
28940 e->epoch = mdev->current_epoch;
28941 - atomic_inc(&e->epoch->epoch_size);
28942 + atomic_inc_unchecked(&e->epoch->epoch_size);
28943 atomic_inc(&e->epoch->active);
28944 spin_unlock(&mdev->epoch_lock);
28945
28946 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28947 D_ASSERT(list_empty(&mdev->done_ee));
28948
28949 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28950 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28951 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28952 D_ASSERT(list_empty(&mdev->current_epoch->list));
28953 }
28954
28955 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28956 index cd50435..ba1ffb5 100644
28957 --- a/drivers/block/loop.c
28958 +++ b/drivers/block/loop.c
28959 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
28960 mm_segment_t old_fs = get_fs();
28961
28962 set_fs(get_ds());
28963 - bw = file->f_op->write(file, buf, len, &pos);
28964 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28965 set_fs(old_fs);
28966 if (likely(bw == len))
28967 return 0;
28968 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28969 index 4364303..9adf4ee 100644
28970 --- a/drivers/char/Kconfig
28971 +++ b/drivers/char/Kconfig
28972 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28973
28974 config DEVKMEM
28975 bool "/dev/kmem virtual device support"
28976 - default y
28977 + default n
28978 + depends on !GRKERNSEC_KMEM
28979 help
28980 Say Y here if you want to support the /dev/kmem device. The
28981 /dev/kmem device is rarely used, but can be used for certain
28982 @@ -596,6 +597,7 @@ config DEVPORT
28983 bool
28984 depends on !M68K
28985 depends on ISA || PCI
28986 + depends on !GRKERNSEC_KMEM
28987 default y
28988
28989 source "drivers/s390/char/Kconfig"
28990 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28991 index 2e04433..22afc64 100644
28992 --- a/drivers/char/agp/frontend.c
28993 +++ b/drivers/char/agp/frontend.c
28994 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28995 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28996 return -EFAULT;
28997
28998 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28999 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29000 return -EFAULT;
29001
29002 client = agp_find_client_by_pid(reserve.pid);
29003 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29004 index 095ab90..afad0a4 100644
29005 --- a/drivers/char/briq_panel.c
29006 +++ b/drivers/char/briq_panel.c
29007 @@ -9,6 +9,7 @@
29008 #include <linux/types.h>
29009 #include <linux/errno.h>
29010 #include <linux/tty.h>
29011 +#include <linux/mutex.h>
29012 #include <linux/timer.h>
29013 #include <linux/kernel.h>
29014 #include <linux/wait.h>
29015 @@ -34,6 +35,7 @@ static int vfd_is_open;
29016 static unsigned char vfd[40];
29017 static int vfd_cursor;
29018 static unsigned char ledpb, led;
29019 +static DEFINE_MUTEX(vfd_mutex);
29020
29021 static void update_vfd(void)
29022 {
29023 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29024 if (!vfd_is_open)
29025 return -EBUSY;
29026
29027 + mutex_lock(&vfd_mutex);
29028 for (;;) {
29029 char c;
29030 if (!indx)
29031 break;
29032 - if (get_user(c, buf))
29033 + if (get_user(c, buf)) {
29034 + mutex_unlock(&vfd_mutex);
29035 return -EFAULT;
29036 + }
29037 if (esc) {
29038 set_led(c);
29039 esc = 0;
29040 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29041 buf++;
29042 }
29043 update_vfd();
29044 + mutex_unlock(&vfd_mutex);
29045
29046 return len;
29047 }
29048 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29049 index f773a9d..65cd683 100644
29050 --- a/drivers/char/genrtc.c
29051 +++ b/drivers/char/genrtc.c
29052 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29053 switch (cmd) {
29054
29055 case RTC_PLL_GET:
29056 + memset(&pll, 0, sizeof(pll));
29057 if (get_rtc_pll(&pll))
29058 return -EINVAL;
29059 else
29060 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29061 index 0833896..cccce52 100644
29062 --- a/drivers/char/hpet.c
29063 +++ b/drivers/char/hpet.c
29064 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29065 }
29066
29067 static int
29068 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29069 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29070 struct hpet_info *info)
29071 {
29072 struct hpet_timer __iomem *timer;
29073 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29074 index 58c0e63..46c16bf 100644
29075 --- a/drivers/char/ipmi/ipmi_msghandler.c
29076 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29077 @@ -415,7 +415,7 @@ struct ipmi_smi {
29078 struct proc_dir_entry *proc_dir;
29079 char proc_dir_name[10];
29080
29081 - atomic_t stats[IPMI_NUM_STATS];
29082 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29083
29084 /*
29085 * run_to_completion duplicate of smb_info, smi_info
29086 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29087
29088
29089 #define ipmi_inc_stat(intf, stat) \
29090 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29091 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29092 #define ipmi_get_stat(intf, stat) \
29093 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29094 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29095
29096 static int is_lan_addr(struct ipmi_addr *addr)
29097 {
29098 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29099 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29100 init_waitqueue_head(&intf->waitq);
29101 for (i = 0; i < IPMI_NUM_STATS; i++)
29102 - atomic_set(&intf->stats[i], 0);
29103 + atomic_set_unchecked(&intf->stats[i], 0);
29104
29105 intf->proc_dir = NULL;
29106
29107 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29108 index 50fcf9c..91b5528 100644
29109 --- a/drivers/char/ipmi/ipmi_si_intf.c
29110 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29111 @@ -277,7 +277,7 @@ struct smi_info {
29112 unsigned char slave_addr;
29113
29114 /* Counters and things for the proc filesystem. */
29115 - atomic_t stats[SI_NUM_STATS];
29116 + atomic_unchecked_t stats[SI_NUM_STATS];
29117
29118 struct task_struct *thread;
29119
29120 @@ -286,9 +286,9 @@ struct smi_info {
29121 };
29122
29123 #define smi_inc_stat(smi, stat) \
29124 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29125 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29126 #define smi_get_stat(smi, stat) \
29127 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29128 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29129
29130 #define SI_MAX_PARMS 4
29131
29132 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29133 atomic_set(&new_smi->req_events, 0);
29134 new_smi->run_to_completion = 0;
29135 for (i = 0; i < SI_NUM_STATS; i++)
29136 - atomic_set(&new_smi->stats[i], 0);
29137 + atomic_set_unchecked(&new_smi->stats[i], 0);
29138
29139 new_smi->interrupt_disabled = 1;
29140 atomic_set(&new_smi->stop_operation, 0);
29141 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29142 index 1aeaaba..e018570 100644
29143 --- a/drivers/char/mbcs.c
29144 +++ b/drivers/char/mbcs.c
29145 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29146 return 0;
29147 }
29148
29149 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29150 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29151 {
29152 .part_num = MBCS_PART_NUM,
29153 .mfg_num = MBCS_MFG_NUM,
29154 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29155 index d6e9d08..4493e89 100644
29156 --- a/drivers/char/mem.c
29157 +++ b/drivers/char/mem.c
29158 @@ -18,6 +18,7 @@
29159 #include <linux/raw.h>
29160 #include <linux/tty.h>
29161 #include <linux/capability.h>
29162 +#include <linux/security.h>
29163 #include <linux/ptrace.h>
29164 #include <linux/device.h>
29165 #include <linux/highmem.h>
29166 @@ -35,6 +36,10 @@
29167 # include <linux/efi.h>
29168 #endif
29169
29170 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29171 +extern const struct file_operations grsec_fops;
29172 +#endif
29173 +
29174 static inline unsigned long size_inside_page(unsigned long start,
29175 unsigned long size)
29176 {
29177 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29178
29179 while (cursor < to) {
29180 if (!devmem_is_allowed(pfn)) {
29181 +#ifdef CONFIG_GRKERNSEC_KMEM
29182 + gr_handle_mem_readwrite(from, to);
29183 +#else
29184 printk(KERN_INFO
29185 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29186 current->comm, from, to);
29187 +#endif
29188 return 0;
29189 }
29190 cursor += PAGE_SIZE;
29191 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29192 }
29193 return 1;
29194 }
29195 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29196 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29197 +{
29198 + return 0;
29199 +}
29200 #else
29201 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29202 {
29203 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29204
29205 while (count > 0) {
29206 unsigned long remaining;
29207 + char *temp;
29208
29209 sz = size_inside_page(p, count);
29210
29211 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29212 if (!ptr)
29213 return -EFAULT;
29214
29215 - remaining = copy_to_user(buf, ptr, sz);
29216 +#ifdef CONFIG_PAX_USERCOPY
29217 + temp = kmalloc(sz, GFP_KERNEL);
29218 + if (!temp) {
29219 + unxlate_dev_mem_ptr(p, ptr);
29220 + return -ENOMEM;
29221 + }
29222 + memcpy(temp, ptr, sz);
29223 +#else
29224 + temp = ptr;
29225 +#endif
29226 +
29227 + remaining = copy_to_user(buf, temp, sz);
29228 +
29229 +#ifdef CONFIG_PAX_USERCOPY
29230 + kfree(temp);
29231 +#endif
29232 +
29233 unxlate_dev_mem_ptr(p, ptr);
29234 if (remaining)
29235 return -EFAULT;
29236 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29237 size_t count, loff_t *ppos)
29238 {
29239 unsigned long p = *ppos;
29240 - ssize_t low_count, read, sz;
29241 + ssize_t low_count, read, sz, err = 0;
29242 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29243 - int err = 0;
29244
29245 read = 0;
29246 if (p < (unsigned long) high_memory) {
29247 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29248 }
29249 #endif
29250 while (low_count > 0) {
29251 + char *temp;
29252 +
29253 sz = size_inside_page(p, low_count);
29254
29255 /*
29256 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29257 */
29258 kbuf = xlate_dev_kmem_ptr((char *)p);
29259
29260 - if (copy_to_user(buf, kbuf, sz))
29261 +#ifdef CONFIG_PAX_USERCOPY
29262 + temp = kmalloc(sz, GFP_KERNEL);
29263 + if (!temp)
29264 + return -ENOMEM;
29265 + memcpy(temp, kbuf, sz);
29266 +#else
29267 + temp = kbuf;
29268 +#endif
29269 +
29270 + err = copy_to_user(buf, temp, sz);
29271 +
29272 +#ifdef CONFIG_PAX_USERCOPY
29273 + kfree(temp);
29274 +#endif
29275 +
29276 + if (err)
29277 return -EFAULT;
29278 buf += sz;
29279 p += sz;
29280 @@ -867,6 +914,9 @@ static const struct memdev {
29281 #ifdef CONFIG_CRASH_DUMP
29282 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29283 #endif
29284 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29285 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29286 +#endif
29287 };
29288
29289 static int memory_open(struct inode *inode, struct file *filp)
29290 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29291 index da3cfee..a5a6606 100644
29292 --- a/drivers/char/nvram.c
29293 +++ b/drivers/char/nvram.c
29294 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29295
29296 spin_unlock_irq(&rtc_lock);
29297
29298 - if (copy_to_user(buf, contents, tmp - contents))
29299 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29300 return -EFAULT;
29301
29302 *ppos = i;
29303 diff --git a/drivers/char/random.c b/drivers/char/random.c
29304 index 54ca8b2..4a092ed 100644
29305 --- a/drivers/char/random.c
29306 +++ b/drivers/char/random.c
29307 @@ -261,8 +261,13 @@
29308 /*
29309 * Configuration information
29310 */
29311 +#ifdef CONFIG_GRKERNSEC_RANDNET
29312 +#define INPUT_POOL_WORDS 512
29313 +#define OUTPUT_POOL_WORDS 128
29314 +#else
29315 #define INPUT_POOL_WORDS 128
29316 #define OUTPUT_POOL_WORDS 32
29317 +#endif
29318 #define SEC_XFER_SIZE 512
29319 #define EXTRACT_SIZE 10
29320
29321 @@ -300,10 +305,17 @@ static struct poolinfo {
29322 int poolwords;
29323 int tap1, tap2, tap3, tap4, tap5;
29324 } poolinfo_table[] = {
29325 +#ifdef CONFIG_GRKERNSEC_RANDNET
29326 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29327 + { 512, 411, 308, 208, 104, 1 },
29328 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29329 + { 128, 103, 76, 51, 25, 1 },
29330 +#else
29331 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29332 { 128, 103, 76, 51, 25, 1 },
29333 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29334 { 32, 26, 20, 14, 7, 1 },
29335 +#endif
29336 #if 0
29337 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29338 { 2048, 1638, 1231, 819, 411, 1 },
29339 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29340
29341 extract_buf(r, tmp);
29342 i = min_t(int, nbytes, EXTRACT_SIZE);
29343 - if (copy_to_user(buf, tmp, i)) {
29344 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29345 ret = -EFAULT;
29346 break;
29347 }
29348 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29349 #include <linux/sysctl.h>
29350
29351 static int min_read_thresh = 8, min_write_thresh;
29352 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29353 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29354 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29355 static char sysctl_bootid[16];
29356
29357 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29358 uuid = table->data;
29359 if (!uuid) {
29360 uuid = tmp_uuid;
29361 - uuid[8] = 0;
29362 - }
29363 - if (uuid[8] == 0)
29364 generate_random_uuid(uuid);
29365 + } else {
29366 + static DEFINE_SPINLOCK(bootid_spinlock);
29367 +
29368 + spin_lock(&bootid_spinlock);
29369 + if (!uuid[8])
29370 + generate_random_uuid(uuid);
29371 + spin_unlock(&bootid_spinlock);
29372 + }
29373
29374 sprintf(buf, "%pU", uuid);
29375
29376 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29377 index 1ee8ce7..b778bef 100644
29378 --- a/drivers/char/sonypi.c
29379 +++ b/drivers/char/sonypi.c
29380 @@ -55,6 +55,7 @@
29381 #include <asm/uaccess.h>
29382 #include <asm/io.h>
29383 #include <asm/system.h>
29384 +#include <asm/local.h>
29385
29386 #include <linux/sonypi.h>
29387
29388 @@ -491,7 +492,7 @@ static struct sonypi_device {
29389 spinlock_t fifo_lock;
29390 wait_queue_head_t fifo_proc_list;
29391 struct fasync_struct *fifo_async;
29392 - int open_count;
29393 + local_t open_count;
29394 int model;
29395 struct input_dev *input_jog_dev;
29396 struct input_dev *input_key_dev;
29397 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29398 static int sonypi_misc_release(struct inode *inode, struct file *file)
29399 {
29400 mutex_lock(&sonypi_device.lock);
29401 - sonypi_device.open_count--;
29402 + local_dec(&sonypi_device.open_count);
29403 mutex_unlock(&sonypi_device.lock);
29404 return 0;
29405 }
29406 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29407 {
29408 mutex_lock(&sonypi_device.lock);
29409 /* Flush input queue on first open */
29410 - if (!sonypi_device.open_count)
29411 + if (!local_read(&sonypi_device.open_count))
29412 kfifo_reset(&sonypi_device.fifo);
29413 - sonypi_device.open_count++;
29414 + local_inc(&sonypi_device.open_count);
29415 mutex_unlock(&sonypi_device.lock);
29416
29417 return 0;
29418 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29419 index ad7c732..5aa8054 100644
29420 --- a/drivers/char/tpm/tpm.c
29421 +++ b/drivers/char/tpm/tpm.c
29422 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29423 chip->vendor.req_complete_val)
29424 goto out_recv;
29425
29426 - if ((status == chip->vendor.req_canceled)) {
29427 + if (status == chip->vendor.req_canceled) {
29428 dev_err(chip->dev, "Operation Canceled\n");
29429 rc = -ECANCELED;
29430 goto out;
29431 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29432 index 0636520..169c1d0 100644
29433 --- a/drivers/char/tpm/tpm_bios.c
29434 +++ b/drivers/char/tpm/tpm_bios.c
29435 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29436 event = addr;
29437
29438 if ((event->event_type == 0 && event->event_size == 0) ||
29439 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29440 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29441 return NULL;
29442
29443 return addr;
29444 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29445 return NULL;
29446
29447 if ((event->event_type == 0 && event->event_size == 0) ||
29448 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29449 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29450 return NULL;
29451
29452 (*pos)++;
29453 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29454 int i;
29455
29456 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29457 - seq_putc(m, data[i]);
29458 + if (!seq_putc(m, data[i]))
29459 + return -EFAULT;
29460
29461 return 0;
29462 }
29463 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29464 log->bios_event_log_end = log->bios_event_log + len;
29465
29466 virt = acpi_os_map_memory(start, len);
29467 + if (!virt) {
29468 + kfree(log->bios_event_log);
29469 + log->bios_event_log = NULL;
29470 + return -EFAULT;
29471 + }
29472
29473 - memcpy(log->bios_event_log, virt, len);
29474 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29475
29476 acpi_os_unmap_memory(virt, len);
29477 return 0;
29478 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29479 index b58b561..c9088c8 100644
29480 --- a/drivers/char/virtio_console.c
29481 +++ b/drivers/char/virtio_console.c
29482 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29483 if (to_user) {
29484 ssize_t ret;
29485
29486 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29487 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29488 if (ret)
29489 return -EFAULT;
29490 } else {
29491 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29492 if (!port_has_data(port) && !port->host_connected)
29493 return 0;
29494
29495 - return fill_readbuf(port, ubuf, count, true);
29496 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29497 }
29498
29499 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29500 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29501 index c9eee6d..f9d5280 100644
29502 --- a/drivers/edac/amd64_edac.c
29503 +++ b/drivers/edac/amd64_edac.c
29504 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29505 * PCI core identifies what devices are on a system during boot, and then
29506 * inquiry this table to see if this driver is for a given device found.
29507 */
29508 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29509 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29510 {
29511 .vendor = PCI_VENDOR_ID_AMD,
29512 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29513 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29514 index e47e73b..348e0bd 100644
29515 --- a/drivers/edac/amd76x_edac.c
29516 +++ b/drivers/edac/amd76x_edac.c
29517 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29518 edac_mc_free(mci);
29519 }
29520
29521 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29522 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29523 {
29524 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29525 AMD762},
29526 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29527 index 1af531a..3a8ff27 100644
29528 --- a/drivers/edac/e752x_edac.c
29529 +++ b/drivers/edac/e752x_edac.c
29530 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29531 edac_mc_free(mci);
29532 }
29533
29534 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29535 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29536 {
29537 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29538 E7520},
29539 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29540 index 6ffb6d2..383d8d7 100644
29541 --- a/drivers/edac/e7xxx_edac.c
29542 +++ b/drivers/edac/e7xxx_edac.c
29543 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29544 edac_mc_free(mci);
29545 }
29546
29547 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29548 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29549 {
29550 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29551 E7205},
29552 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29553 index 97f5064..202b6e6 100644
29554 --- a/drivers/edac/edac_pci_sysfs.c
29555 +++ b/drivers/edac/edac_pci_sysfs.c
29556 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29557 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29558 static int edac_pci_poll_msec = 1000; /* one second workq period */
29559
29560 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29561 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29562 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29563 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29564
29565 static struct kobject *edac_pci_top_main_kobj;
29566 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29567 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29568 edac_printk(KERN_CRIT, EDAC_PCI,
29569 "Signaled System Error on %s\n",
29570 pci_name(dev));
29571 - atomic_inc(&pci_nonparity_count);
29572 + atomic_inc_unchecked(&pci_nonparity_count);
29573 }
29574
29575 if (status & (PCI_STATUS_PARITY)) {
29576 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29577 "Master Data Parity Error on %s\n",
29578 pci_name(dev));
29579
29580 - atomic_inc(&pci_parity_count);
29581 + atomic_inc_unchecked(&pci_parity_count);
29582 }
29583
29584 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29585 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29586 "Detected Parity Error on %s\n",
29587 pci_name(dev));
29588
29589 - atomic_inc(&pci_parity_count);
29590 + atomic_inc_unchecked(&pci_parity_count);
29591 }
29592 }
29593
29594 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29595 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29596 "Signaled System Error on %s\n",
29597 pci_name(dev));
29598 - atomic_inc(&pci_nonparity_count);
29599 + atomic_inc_unchecked(&pci_nonparity_count);
29600 }
29601
29602 if (status & (PCI_STATUS_PARITY)) {
29603 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29604 "Master Data Parity Error on "
29605 "%s\n", pci_name(dev));
29606
29607 - atomic_inc(&pci_parity_count);
29608 + atomic_inc_unchecked(&pci_parity_count);
29609 }
29610
29611 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29612 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29613 "Detected Parity Error on %s\n",
29614 pci_name(dev));
29615
29616 - atomic_inc(&pci_parity_count);
29617 + atomic_inc_unchecked(&pci_parity_count);
29618 }
29619 }
29620 }
29621 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29622 if (!check_pci_errors)
29623 return;
29624
29625 - before_count = atomic_read(&pci_parity_count);
29626 + before_count = atomic_read_unchecked(&pci_parity_count);
29627
29628 /* scan all PCI devices looking for a Parity Error on devices and
29629 * bridges.
29630 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29631 /* Only if operator has selected panic on PCI Error */
29632 if (edac_pci_get_panic_on_pe()) {
29633 /* If the count is different 'after' from 'before' */
29634 - if (before_count != atomic_read(&pci_parity_count))
29635 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29636 panic("EDAC: PCI Parity Error");
29637 }
29638 }
29639 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29640 index c0510b3..6e2a954 100644
29641 --- a/drivers/edac/i3000_edac.c
29642 +++ b/drivers/edac/i3000_edac.c
29643 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29644 edac_mc_free(mci);
29645 }
29646
29647 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29648 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29649 {
29650 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29651 I3000},
29652 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29653 index 73f55e200..5faaf59 100644
29654 --- a/drivers/edac/i3200_edac.c
29655 +++ b/drivers/edac/i3200_edac.c
29656 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29657 edac_mc_free(mci);
29658 }
29659
29660 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29661 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29662 {
29663 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29664 I3200},
29665 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29666 index 4dc3ac2..67d05a6 100644
29667 --- a/drivers/edac/i5000_edac.c
29668 +++ b/drivers/edac/i5000_edac.c
29669 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29670 *
29671 * The "E500P" device is the first device supported.
29672 */
29673 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29674 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29675 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29676 .driver_data = I5000P},
29677
29678 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29679 index bcbdeec..9886d16 100644
29680 --- a/drivers/edac/i5100_edac.c
29681 +++ b/drivers/edac/i5100_edac.c
29682 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29683 edac_mc_free(mci);
29684 }
29685
29686 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29687 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29688 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29689 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29690 { 0, }
29691 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29692 index 74d6ec34..baff517 100644
29693 --- a/drivers/edac/i5400_edac.c
29694 +++ b/drivers/edac/i5400_edac.c
29695 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29696 *
29697 * The "E500P" device is the first device supported.
29698 */
29699 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29700 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29701 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29702 {0,} /* 0 terminated list. */
29703 };
29704 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29705 index 6104dba..e7ea8e1 100644
29706 --- a/drivers/edac/i7300_edac.c
29707 +++ b/drivers/edac/i7300_edac.c
29708 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29709 *
29710 * Has only 8086:360c PCI ID
29711 */
29712 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29713 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29714 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29715 {0,} /* 0 terminated list. */
29716 };
29717 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29718 index 8568d9b..42b2fa8 100644
29719 --- a/drivers/edac/i7core_edac.c
29720 +++ b/drivers/edac/i7core_edac.c
29721 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29722 /*
29723 * pci_device_id table for which devices we are looking for
29724 */
29725 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29726 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29727 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29728 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29729 {0,} /* 0 terminated list. */
29730 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29731 index 4329d39..f3022ef 100644
29732 --- a/drivers/edac/i82443bxgx_edac.c
29733 +++ b/drivers/edac/i82443bxgx_edac.c
29734 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29735
29736 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29737
29738 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29739 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29740 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29741 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29742 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29743 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29744 index 931a057..fd28340 100644
29745 --- a/drivers/edac/i82860_edac.c
29746 +++ b/drivers/edac/i82860_edac.c
29747 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29748 edac_mc_free(mci);
29749 }
29750
29751 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29752 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29753 {
29754 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29755 I82860},
29756 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29757 index 33864c6..01edc61 100644
29758 --- a/drivers/edac/i82875p_edac.c
29759 +++ b/drivers/edac/i82875p_edac.c
29760 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29761 edac_mc_free(mci);
29762 }
29763
29764 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29765 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29766 {
29767 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29768 I82875P},
29769 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29770 index 4184e01..dcb2cd3 100644
29771 --- a/drivers/edac/i82975x_edac.c
29772 +++ b/drivers/edac/i82975x_edac.c
29773 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29774 edac_mc_free(mci);
29775 }
29776
29777 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29778 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29779 {
29780 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29781 I82975X
29782 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29783 index 0106747..0b40417 100644
29784 --- a/drivers/edac/mce_amd.h
29785 +++ b/drivers/edac/mce_amd.h
29786 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29787 bool (*dc_mce)(u16, u8);
29788 bool (*ic_mce)(u16, u8);
29789 bool (*nb_mce)(u16, u8);
29790 -};
29791 +} __no_const;
29792
29793 void amd_report_gart_errors(bool);
29794 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29795 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29796 index e294e1b..a41b05b 100644
29797 --- a/drivers/edac/r82600_edac.c
29798 +++ b/drivers/edac/r82600_edac.c
29799 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29800 edac_mc_free(mci);
29801 }
29802
29803 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29804 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29805 {
29806 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29807 },
29808 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29809 index 1dc118d..8c68af9 100644
29810 --- a/drivers/edac/sb_edac.c
29811 +++ b/drivers/edac/sb_edac.c
29812 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29813 /*
29814 * pci_device_id table for which devices we are looking for
29815 */
29816 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29817 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29818 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29819 {0,} /* 0 terminated list. */
29820 };
29821 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29822 index b6f47de..c5acf3a 100644
29823 --- a/drivers/edac/x38_edac.c
29824 +++ b/drivers/edac/x38_edac.c
29825 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29826 edac_mc_free(mci);
29827 }
29828
29829 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29830 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29831 {
29832 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29833 X38},
29834 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29835 index 85661b0..c784559a 100644
29836 --- a/drivers/firewire/core-card.c
29837 +++ b/drivers/firewire/core-card.c
29838 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29839
29840 void fw_core_remove_card(struct fw_card *card)
29841 {
29842 - struct fw_card_driver dummy_driver = dummy_driver_template;
29843 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29844
29845 card->driver->update_phy_reg(card, 4,
29846 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29847 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29848 index 4799393..37bd3ab 100644
29849 --- a/drivers/firewire/core-cdev.c
29850 +++ b/drivers/firewire/core-cdev.c
29851 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29852 int ret;
29853
29854 if ((request->channels == 0 && request->bandwidth == 0) ||
29855 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29856 - request->bandwidth < 0)
29857 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29858 return -EINVAL;
29859
29860 r = kmalloc(sizeof(*r), GFP_KERNEL);
29861 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29862 index 855ab3f..11f4bbd 100644
29863 --- a/drivers/firewire/core-transaction.c
29864 +++ b/drivers/firewire/core-transaction.c
29865 @@ -37,6 +37,7 @@
29866 #include <linux/timer.h>
29867 #include <linux/types.h>
29868 #include <linux/workqueue.h>
29869 +#include <linux/sched.h>
29870
29871 #include <asm/byteorder.h>
29872
29873 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29874 index b45be57..5fad18b 100644
29875 --- a/drivers/firewire/core.h
29876 +++ b/drivers/firewire/core.h
29877 @@ -101,6 +101,7 @@ struct fw_card_driver {
29878
29879 int (*stop_iso)(struct fw_iso_context *ctx);
29880 };
29881 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29882
29883 void fw_card_initialize(struct fw_card *card,
29884 const struct fw_card_driver *driver, struct device *device);
29885 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29886 index 153980b..4b4d046 100644
29887 --- a/drivers/firmware/dmi_scan.c
29888 +++ b/drivers/firmware/dmi_scan.c
29889 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29890 }
29891 }
29892 else {
29893 - /*
29894 - * no iounmap() for that ioremap(); it would be a no-op, but
29895 - * it's so early in setup that sucker gets confused into doing
29896 - * what it shouldn't if we actually call it.
29897 - */
29898 p = dmi_ioremap(0xF0000, 0x10000);
29899 if (p == NULL)
29900 goto error;
29901 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29902 if (buf == NULL)
29903 return -1;
29904
29905 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29906 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29907
29908 iounmap(buf);
29909 return 0;
29910 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29911 index 82d5c20..44a7177 100644
29912 --- a/drivers/gpio/gpio-vr41xx.c
29913 +++ b/drivers/gpio/gpio-vr41xx.c
29914 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29915 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29916 maskl, pendl, maskh, pendh);
29917
29918 - atomic_inc(&irq_err_count);
29919 + atomic_inc_unchecked(&irq_err_count);
29920
29921 return -EINVAL;
29922 }
29923 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29924 index 84a4a80..ce0306e 100644
29925 --- a/drivers/gpu/drm/drm_crtc_helper.c
29926 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29927 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29928 struct drm_crtc *tmp;
29929 int crtc_mask = 1;
29930
29931 - WARN(!crtc, "checking null crtc?\n");
29932 + BUG_ON(!crtc);
29933
29934 dev = crtc->dev;
29935
29936 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29937 index ebf7d3f..d64c436 100644
29938 --- a/drivers/gpu/drm/drm_drv.c
29939 +++ b/drivers/gpu/drm/drm_drv.c
29940 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29941 /**
29942 * Copy and IOCTL return string to user space
29943 */
29944 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29945 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29946 {
29947 int len;
29948
29949 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29950
29951 dev = file_priv->minor->dev;
29952 atomic_inc(&dev->ioctl_count);
29953 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29954 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29955 ++file_priv->ioctl_count;
29956
29957 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29958 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29959 index 6263b01..7987f55 100644
29960 --- a/drivers/gpu/drm/drm_fops.c
29961 +++ b/drivers/gpu/drm/drm_fops.c
29962 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29963 }
29964
29965 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29966 - atomic_set(&dev->counts[i], 0);
29967 + atomic_set_unchecked(&dev->counts[i], 0);
29968
29969 dev->sigdata.lock = NULL;
29970
29971 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29972
29973 retcode = drm_open_helper(inode, filp, dev);
29974 if (!retcode) {
29975 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29976 - if (!dev->open_count++)
29977 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29978 + if (local_inc_return(&dev->open_count) == 1)
29979 retcode = drm_setup(dev);
29980 }
29981 if (!retcode) {
29982 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29983
29984 mutex_lock(&drm_global_mutex);
29985
29986 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29987 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
29988
29989 if (dev->driver->preclose)
29990 dev->driver->preclose(dev, file_priv);
29991 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
29992 * Begin inline drm_release
29993 */
29994
29995 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29996 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
29997 task_pid_nr(current),
29998 (long)old_encode_dev(file_priv->minor->device),
29999 - dev->open_count);
30000 + local_read(&dev->open_count));
30001
30002 /* Release any auth tokens that might point to this file_priv,
30003 (do that under the drm_global_mutex) */
30004 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30005 * End inline drm_release
30006 */
30007
30008 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30009 - if (!--dev->open_count) {
30010 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30011 + if (local_dec_and_test(&dev->open_count)) {
30012 if (atomic_read(&dev->ioctl_count)) {
30013 DRM_ERROR("Device busy: %d\n",
30014 atomic_read(&dev->ioctl_count));
30015 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30016 index c87dc96..326055d 100644
30017 --- a/drivers/gpu/drm/drm_global.c
30018 +++ b/drivers/gpu/drm/drm_global.c
30019 @@ -36,7 +36,7 @@
30020 struct drm_global_item {
30021 struct mutex mutex;
30022 void *object;
30023 - int refcount;
30024 + atomic_t refcount;
30025 };
30026
30027 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30028 @@ -49,7 +49,7 @@ void drm_global_init(void)
30029 struct drm_global_item *item = &glob[i];
30030 mutex_init(&item->mutex);
30031 item->object = NULL;
30032 - item->refcount = 0;
30033 + atomic_set(&item->refcount, 0);
30034 }
30035 }
30036
30037 @@ -59,7 +59,7 @@ void drm_global_release(void)
30038 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30039 struct drm_global_item *item = &glob[i];
30040 BUG_ON(item->object != NULL);
30041 - BUG_ON(item->refcount != 0);
30042 + BUG_ON(atomic_read(&item->refcount) != 0);
30043 }
30044 }
30045
30046 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30047 void *object;
30048
30049 mutex_lock(&item->mutex);
30050 - if (item->refcount == 0) {
30051 + if (atomic_read(&item->refcount) == 0) {
30052 item->object = kzalloc(ref->size, GFP_KERNEL);
30053 if (unlikely(item->object == NULL)) {
30054 ret = -ENOMEM;
30055 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30056 goto out_err;
30057
30058 }
30059 - ++item->refcount;
30060 + atomic_inc(&item->refcount);
30061 ref->object = item->object;
30062 object = item->object;
30063 mutex_unlock(&item->mutex);
30064 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30065 struct drm_global_item *item = &glob[ref->global_type];
30066
30067 mutex_lock(&item->mutex);
30068 - BUG_ON(item->refcount == 0);
30069 + BUG_ON(atomic_read(&item->refcount) == 0);
30070 BUG_ON(ref->object != item->object);
30071 - if (--item->refcount == 0) {
30072 + if (atomic_dec_and_test(&item->refcount)) {
30073 ref->release(ref);
30074 item->object = NULL;
30075 }
30076 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30077 index ab1162d..42587b2 100644
30078 --- a/drivers/gpu/drm/drm_info.c
30079 +++ b/drivers/gpu/drm/drm_info.c
30080 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30081 struct drm_local_map *map;
30082 struct drm_map_list *r_list;
30083
30084 - /* Hardcoded from _DRM_FRAME_BUFFER,
30085 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30086 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30087 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30088 + static const char * const types[] = {
30089 + [_DRM_FRAME_BUFFER] = "FB",
30090 + [_DRM_REGISTERS] = "REG",
30091 + [_DRM_SHM] = "SHM",
30092 + [_DRM_AGP] = "AGP",
30093 + [_DRM_SCATTER_GATHER] = "SG",
30094 + [_DRM_CONSISTENT] = "PCI",
30095 + [_DRM_GEM] = "GEM" };
30096 const char *type;
30097 int i;
30098
30099 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30100 map = r_list->map;
30101 if (!map)
30102 continue;
30103 - if (map->type < 0 || map->type > 5)
30104 + if (map->type >= ARRAY_SIZE(types))
30105 type = "??";
30106 else
30107 type = types[map->type];
30108 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30109 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30110 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30111 vma->vm_flags & VM_IO ? 'i' : '-',
30112 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30113 + 0);
30114 +#else
30115 vma->vm_pgoff);
30116 +#endif
30117
30118 #if defined(__i386__)
30119 pgprot = pgprot_val(vma->vm_page_prot);
30120 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30121 index 637fcc3..e890b33 100644
30122 --- a/drivers/gpu/drm/drm_ioc32.c
30123 +++ b/drivers/gpu/drm/drm_ioc32.c
30124 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30125 request = compat_alloc_user_space(nbytes);
30126 if (!access_ok(VERIFY_WRITE, request, nbytes))
30127 return -EFAULT;
30128 - list = (struct drm_buf_desc *) (request + 1);
30129 + list = (struct drm_buf_desc __user *) (request + 1);
30130
30131 if (__put_user(count, &request->count)
30132 || __put_user(list, &request->list))
30133 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30134 request = compat_alloc_user_space(nbytes);
30135 if (!access_ok(VERIFY_WRITE, request, nbytes))
30136 return -EFAULT;
30137 - list = (struct drm_buf_pub *) (request + 1);
30138 + list = (struct drm_buf_pub __user *) (request + 1);
30139
30140 if (__put_user(count, &request->count)
30141 || __put_user(list, &request->list))
30142 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30143 index 956fd38..e52167a 100644
30144 --- a/drivers/gpu/drm/drm_ioctl.c
30145 +++ b/drivers/gpu/drm/drm_ioctl.c
30146 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30147 stats->data[i].value =
30148 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30149 else
30150 - stats->data[i].value = atomic_read(&dev->counts[i]);
30151 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30152 stats->data[i].type = dev->types[i];
30153 }
30154
30155 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30156 index c79c713..2048588 100644
30157 --- a/drivers/gpu/drm/drm_lock.c
30158 +++ b/drivers/gpu/drm/drm_lock.c
30159 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30160 if (drm_lock_take(&master->lock, lock->context)) {
30161 master->lock.file_priv = file_priv;
30162 master->lock.lock_time = jiffies;
30163 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30164 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30165 break; /* Got lock */
30166 }
30167
30168 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30169 return -EINVAL;
30170 }
30171
30172 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30173 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30174
30175 if (drm_lock_free(&master->lock, lock->context)) {
30176 /* FIXME: Should really bail out here. */
30177 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30178 index 7f4b4e1..bf4def2 100644
30179 --- a/drivers/gpu/drm/i810/i810_dma.c
30180 +++ b/drivers/gpu/drm/i810/i810_dma.c
30181 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30182 dma->buflist[vertex->idx],
30183 vertex->discard, vertex->used);
30184
30185 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30186 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30187 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30188 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30189 sarea_priv->last_enqueue = dev_priv->counter - 1;
30190 sarea_priv->last_dispatch = (int)hw_status[5];
30191
30192 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30193 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30194 mc->last_render);
30195
30196 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30197 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30198 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30199 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30200 sarea_priv->last_enqueue = dev_priv->counter - 1;
30201 sarea_priv->last_dispatch = (int)hw_status[5];
30202
30203 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30204 index c9339f4..f5e1b9d 100644
30205 --- a/drivers/gpu/drm/i810/i810_drv.h
30206 +++ b/drivers/gpu/drm/i810/i810_drv.h
30207 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30208 int page_flipping;
30209
30210 wait_queue_head_t irq_queue;
30211 - atomic_t irq_received;
30212 - atomic_t irq_emitted;
30213 + atomic_unchecked_t irq_received;
30214 + atomic_unchecked_t irq_emitted;
30215
30216 int front_offset;
30217 } drm_i810_private_t;
30218 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30219 index deaa657..e0fd296 100644
30220 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30221 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30222 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30223 I915_READ(GTIMR));
30224 }
30225 seq_printf(m, "Interrupts received: %d\n",
30226 - atomic_read(&dev_priv->irq_received));
30227 + atomic_read_unchecked(&dev_priv->irq_received));
30228 for (i = 0; i < I915_NUM_RINGS; i++) {
30229 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30230 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30231 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30232 return ret;
30233
30234 if (opregion->header)
30235 - seq_write(m, opregion->header, OPREGION_SIZE);
30236 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30237
30238 mutex_unlock(&dev->struct_mutex);
30239
30240 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30241 index ddfe3d9..f6e6b21 100644
30242 --- a/drivers/gpu/drm/i915/i915_dma.c
30243 +++ b/drivers/gpu/drm/i915/i915_dma.c
30244 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30245 bool can_switch;
30246
30247 spin_lock(&dev->count_lock);
30248 - can_switch = (dev->open_count == 0);
30249 + can_switch = (local_read(&dev->open_count) == 0);
30250 spin_unlock(&dev->count_lock);
30251 return can_switch;
30252 }
30253 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30254 index 9689ca3..294f9c1 100644
30255 --- a/drivers/gpu/drm/i915/i915_drv.h
30256 +++ b/drivers/gpu/drm/i915/i915_drv.h
30257 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30258 /* render clock increase/decrease */
30259 /* display clock increase/decrease */
30260 /* pll clock increase/decrease */
30261 -};
30262 +} __no_const;
30263
30264 struct intel_device_info {
30265 u8 gen;
30266 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30267 int current_page;
30268 int page_flipping;
30269
30270 - atomic_t irq_received;
30271 + atomic_unchecked_t irq_received;
30272
30273 /* protects the irq masks */
30274 spinlock_t irq_lock;
30275 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30276 * will be page flipped away on the next vblank. When it
30277 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30278 */
30279 - atomic_t pending_flip;
30280 + atomic_unchecked_t pending_flip;
30281 };
30282
30283 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30284 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30285 extern void intel_teardown_gmbus(struct drm_device *dev);
30286 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30287 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30288 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30289 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30290 {
30291 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30292 }
30293 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30294 index 65e1f00..a30ef00 100644
30295 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30296 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30297 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30298 i915_gem_clflush_object(obj);
30299
30300 if (obj->base.pending_write_domain)
30301 - cd->flips |= atomic_read(&obj->pending_flip);
30302 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30303
30304 /* The actual obj->write_domain will be updated with
30305 * pending_write_domain after we emit the accumulated flush for all
30306 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30307
30308 static int
30309 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30310 - int count)
30311 + unsigned int count)
30312 {
30313 - int i;
30314 + unsigned int i;
30315
30316 for (i = 0; i < count; i++) {
30317 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30318 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30319 index 5bd4361..0241a42 100644
30320 --- a/drivers/gpu/drm/i915/i915_irq.c
30321 +++ b/drivers/gpu/drm/i915/i915_irq.c
30322 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30323 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30324 struct drm_i915_master_private *master_priv;
30325
30326 - atomic_inc(&dev_priv->irq_received);
30327 + atomic_inc_unchecked(&dev_priv->irq_received);
30328
30329 /* disable master interrupt before clearing iir */
30330 de_ier = I915_READ(DEIER);
30331 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30332 struct drm_i915_master_private *master_priv;
30333 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30334
30335 - atomic_inc(&dev_priv->irq_received);
30336 + atomic_inc_unchecked(&dev_priv->irq_received);
30337
30338 if (IS_GEN6(dev))
30339 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30340 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30341 int ret = IRQ_NONE, pipe;
30342 bool blc_event = false;
30343
30344 - atomic_inc(&dev_priv->irq_received);
30345 + atomic_inc_unchecked(&dev_priv->irq_received);
30346
30347 iir = I915_READ(IIR);
30348
30349 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30350 {
30351 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30352
30353 - atomic_set(&dev_priv->irq_received, 0);
30354 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30355
30356 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30357 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30358 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30359 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30360 int pipe;
30361
30362 - atomic_set(&dev_priv->irq_received, 0);
30363 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30364
30365 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30366 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30367 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30368 index 2163818..e536c3d 100644
30369 --- a/drivers/gpu/drm/i915/intel_display.c
30370 +++ b/drivers/gpu/drm/i915/intel_display.c
30371 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30372
30373 wait_event(dev_priv->pending_flip_queue,
30374 atomic_read(&dev_priv->mm.wedged) ||
30375 - atomic_read(&obj->pending_flip) == 0);
30376 + atomic_read_unchecked(&obj->pending_flip) == 0);
30377
30378 /* Big Hammer, we also need to ensure that any pending
30379 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30380 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30381 obj = to_intel_framebuffer(crtc->fb)->obj;
30382 dev_priv = crtc->dev->dev_private;
30383 wait_event(dev_priv->pending_flip_queue,
30384 - atomic_read(&obj->pending_flip) == 0);
30385 + atomic_read_unchecked(&obj->pending_flip) == 0);
30386 }
30387
30388 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30389 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30390
30391 atomic_clear_mask(1 << intel_crtc->plane,
30392 &obj->pending_flip.counter);
30393 - if (atomic_read(&obj->pending_flip) == 0)
30394 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30395 wake_up(&dev_priv->pending_flip_queue);
30396
30397 schedule_work(&work->work);
30398 @@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30399 /* Block clients from rendering to the new back buffer until
30400 * the flip occurs and the object is no longer visible.
30401 */
30402 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30403 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30404
30405 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30406 if (ret)
30407 @@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30408 return 0;
30409
30410 cleanup_pending:
30411 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30412 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30413 drm_gem_object_unreference(&work->old_fb_obj->base);
30414 drm_gem_object_unreference(&obj->base);
30415 mutex_unlock(&dev->struct_mutex);
30416 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30417 index 54558a0..2d97005 100644
30418 --- a/drivers/gpu/drm/mga/mga_drv.h
30419 +++ b/drivers/gpu/drm/mga/mga_drv.h
30420 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30421 u32 clear_cmd;
30422 u32 maccess;
30423
30424 - atomic_t vbl_received; /**< Number of vblanks received. */
30425 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30426 wait_queue_head_t fence_queue;
30427 - atomic_t last_fence_retired;
30428 + atomic_unchecked_t last_fence_retired;
30429 u32 next_fence_to_post;
30430
30431 unsigned int fb_cpp;
30432 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30433 index 2581202..f230a8d9 100644
30434 --- a/drivers/gpu/drm/mga/mga_irq.c
30435 +++ b/drivers/gpu/drm/mga/mga_irq.c
30436 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30437 if (crtc != 0)
30438 return 0;
30439
30440 - return atomic_read(&dev_priv->vbl_received);
30441 + return atomic_read_unchecked(&dev_priv->vbl_received);
30442 }
30443
30444
30445 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30446 /* VBLANK interrupt */
30447 if (status & MGA_VLINEPEN) {
30448 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30449 - atomic_inc(&dev_priv->vbl_received);
30450 + atomic_inc_unchecked(&dev_priv->vbl_received);
30451 drm_handle_vblank(dev, 0);
30452 handled = 1;
30453 }
30454 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30455 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30456 MGA_WRITE(MGA_PRIMEND, prim_end);
30457
30458 - atomic_inc(&dev_priv->last_fence_retired);
30459 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30460 DRM_WAKEUP(&dev_priv->fence_queue);
30461 handled = 1;
30462 }
30463 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30464 * using fences.
30465 */
30466 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30467 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30468 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30469 - *sequence) <= (1 << 23)));
30470
30471 *sequence = cur_fence;
30472 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30473 index e5cbead..6c354a3 100644
30474 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30475 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30476 @@ -199,7 +199,7 @@ struct methods {
30477 const char desc[8];
30478 void (*loadbios)(struct drm_device *, uint8_t *);
30479 const bool rw;
30480 -};
30481 +} __do_const;
30482
30483 static struct methods shadow_methods[] = {
30484 { "PRAMIN", load_vbios_pramin, true },
30485 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30486 struct bit_table {
30487 const char id;
30488 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30489 -};
30490 +} __no_const;
30491
30492 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30493
30494 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30495 index b827098..c31a797 100644
30496 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30497 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30498 @@ -242,7 +242,7 @@ struct nouveau_channel {
30499 struct list_head pending;
30500 uint32_t sequence;
30501 uint32_t sequence_ack;
30502 - atomic_t last_sequence_irq;
30503 + atomic_unchecked_t last_sequence_irq;
30504 struct nouveau_vma vma;
30505 } fence;
30506
30507 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30508 u32 handle, u16 class);
30509 void (*set_tile_region)(struct drm_device *dev, int i);
30510 void (*tlb_flush)(struct drm_device *, int engine);
30511 -};
30512 +} __no_const;
30513
30514 struct nouveau_instmem_engine {
30515 void *priv;
30516 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30517 struct nouveau_mc_engine {
30518 int (*init)(struct drm_device *dev);
30519 void (*takedown)(struct drm_device *dev);
30520 -};
30521 +} __no_const;
30522
30523 struct nouveau_timer_engine {
30524 int (*init)(struct drm_device *dev);
30525 void (*takedown)(struct drm_device *dev);
30526 uint64_t (*read)(struct drm_device *dev);
30527 -};
30528 +} __no_const;
30529
30530 struct nouveau_fb_engine {
30531 int num_tiles;
30532 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30533 void (*put)(struct drm_device *, struct nouveau_mem **);
30534
30535 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30536 -};
30537 +} __no_const;
30538
30539 struct nouveau_engine {
30540 struct nouveau_instmem_engine instmem;
30541 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30542 struct drm_global_reference mem_global_ref;
30543 struct ttm_bo_global_ref bo_global_ref;
30544 struct ttm_bo_device bdev;
30545 - atomic_t validate_sequence;
30546 + atomic_unchecked_t validate_sequence;
30547 } ttm;
30548
30549 struct {
30550 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30551 index 2f6daae..c9d7b9e 100644
30552 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30553 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30554 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30555 if (USE_REFCNT(dev))
30556 sequence = nvchan_rd32(chan, 0x48);
30557 else
30558 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30559 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30560
30561 if (chan->fence.sequence_ack == sequence)
30562 goto out;
30563 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30564 return ret;
30565 }
30566
30567 - atomic_set(&chan->fence.last_sequence_irq, 0);
30568 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30569 return 0;
30570 }
30571
30572 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30573 index 7ce3fde..cb3ea04 100644
30574 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30575 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30576 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30577 int trycnt = 0;
30578 int ret, i;
30579
30580 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30581 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30582 retry:
30583 if (++trycnt > 100000) {
30584 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30585 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30586 index f80c5e0..936baa7 100644
30587 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30588 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30589 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30590 bool can_switch;
30591
30592 spin_lock(&dev->count_lock);
30593 - can_switch = (dev->open_count == 0);
30594 + can_switch = (local_read(&dev->open_count) == 0);
30595 spin_unlock(&dev->count_lock);
30596 return can_switch;
30597 }
30598 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30599 index dbdea8e..cd6eeeb 100644
30600 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30601 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30602 @@ -554,7 +554,7 @@ static int
30603 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30604 u32 class, u32 mthd, u32 data)
30605 {
30606 - atomic_set(&chan->fence.last_sequence_irq, data);
30607 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30608 return 0;
30609 }
30610
30611 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30612 index bcac90b..53bfc76 100644
30613 --- a/drivers/gpu/drm/r128/r128_cce.c
30614 +++ b/drivers/gpu/drm/r128/r128_cce.c
30615 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30616
30617 /* GH: Simple idle check.
30618 */
30619 - atomic_set(&dev_priv->idle_count, 0);
30620 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30621
30622 /* We don't support anything other than bus-mastering ring mode,
30623 * but the ring can be in either AGP or PCI space for the ring
30624 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30625 index 930c71b..499aded 100644
30626 --- a/drivers/gpu/drm/r128/r128_drv.h
30627 +++ b/drivers/gpu/drm/r128/r128_drv.h
30628 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30629 int is_pci;
30630 unsigned long cce_buffers_offset;
30631
30632 - atomic_t idle_count;
30633 + atomic_unchecked_t idle_count;
30634
30635 int page_flipping;
30636 int current_page;
30637 u32 crtc_offset;
30638 u32 crtc_offset_cntl;
30639
30640 - atomic_t vbl_received;
30641 + atomic_unchecked_t vbl_received;
30642
30643 u32 color_fmt;
30644 unsigned int front_offset;
30645 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30646 index 429d5a0..7e899ed 100644
30647 --- a/drivers/gpu/drm/r128/r128_irq.c
30648 +++ b/drivers/gpu/drm/r128/r128_irq.c
30649 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30650 if (crtc != 0)
30651 return 0;
30652
30653 - return atomic_read(&dev_priv->vbl_received);
30654 + return atomic_read_unchecked(&dev_priv->vbl_received);
30655 }
30656
30657 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30658 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30659 /* VBLANK interrupt */
30660 if (status & R128_CRTC_VBLANK_INT) {
30661 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30662 - atomic_inc(&dev_priv->vbl_received);
30663 + atomic_inc_unchecked(&dev_priv->vbl_received);
30664 drm_handle_vblank(dev, 0);
30665 return IRQ_HANDLED;
30666 }
30667 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30668 index a9e33ce..09edd4b 100644
30669 --- a/drivers/gpu/drm/r128/r128_state.c
30670 +++ b/drivers/gpu/drm/r128/r128_state.c
30671 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30672
30673 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30674 {
30675 - if (atomic_read(&dev_priv->idle_count) == 0)
30676 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30677 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30678 else
30679 - atomic_set(&dev_priv->idle_count, 0);
30680 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30681 }
30682
30683 #endif
30684 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30685 index 5a82b6b..9e69c73 100644
30686 --- a/drivers/gpu/drm/radeon/mkregtable.c
30687 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30688 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30689 regex_t mask_rex;
30690 regmatch_t match[4];
30691 char buf[1024];
30692 - size_t end;
30693 + long end;
30694 int len;
30695 int done = 0;
30696 int r;
30697 unsigned o;
30698 struct offset *offset;
30699 char last_reg_s[10];
30700 - int last_reg;
30701 + unsigned long last_reg;
30702
30703 if (regcomp
30704 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30705 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30706 index 1668ec1..30ebdab 100644
30707 --- a/drivers/gpu/drm/radeon/radeon.h
30708 +++ b/drivers/gpu/drm/radeon/radeon.h
30709 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30710 uint32_t scratch_reg;
30711 uint64_t gpu_addr;
30712 volatile uint32_t *cpu_addr;
30713 - atomic_t seq;
30714 + atomic_unchecked_t seq;
30715 uint32_t last_seq;
30716 unsigned long last_jiffies;
30717 unsigned long last_timeout;
30718 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30719 int x2, int y2);
30720 void (*draw_auto)(struct radeon_device *rdev);
30721 void (*set_default_state)(struct radeon_device *rdev);
30722 -};
30723 +} __no_const;
30724
30725 struct r600_blit {
30726 struct mutex mutex;
30727 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30728 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30729 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30730 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30731 -};
30732 +} __no_const;
30733
30734 /*
30735 * Asic structures
30736 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30737 index 49f7cb7..2fcb48f 100644
30738 --- a/drivers/gpu/drm/radeon/radeon_device.c
30739 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30740 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30741 bool can_switch;
30742
30743 spin_lock(&dev->count_lock);
30744 - can_switch = (dev->open_count == 0);
30745 + can_switch = (local_read(&dev->open_count) == 0);
30746 spin_unlock(&dev->count_lock);
30747 return can_switch;
30748 }
30749 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30750 index a1b59ca..86f2d44 100644
30751 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30752 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30753 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30754
30755 /* SW interrupt */
30756 wait_queue_head_t swi_queue;
30757 - atomic_t swi_emitted;
30758 + atomic_unchecked_t swi_emitted;
30759 int vblank_crtc;
30760 uint32_t irq_enable_reg;
30761 uint32_t r500_disp_irq_reg;
30762 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30763 index 4bd36a3..e66fe9c 100644
30764 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30765 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30766 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30767 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30768 return 0;
30769 }
30770 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30771 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30772 if (!rdev->ring[fence->ring].ready)
30773 /* FIXME: cp is not running assume everythings is done right
30774 * away
30775 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30776 }
30777 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30778 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30779 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30780 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30781 rdev->fence_drv[ring].initialized = true;
30782 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30783 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30784 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30785 rdev->fence_drv[ring].scratch_reg = -1;
30786 rdev->fence_drv[ring].cpu_addr = NULL;
30787 rdev->fence_drv[ring].gpu_addr = 0;
30788 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30789 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30790 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30791 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30792 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30793 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30794 index 48b7cea..342236f 100644
30795 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30796 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30797 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30798 request = compat_alloc_user_space(sizeof(*request));
30799 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30800 || __put_user(req32.param, &request->param)
30801 - || __put_user((void __user *)(unsigned long)req32.value,
30802 + || __put_user((unsigned long)req32.value,
30803 &request->value))
30804 return -EFAULT;
30805
30806 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30807 index 00da384..32f972d 100644
30808 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30809 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30810 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30811 unsigned int ret;
30812 RING_LOCALS;
30813
30814 - atomic_inc(&dev_priv->swi_emitted);
30815 - ret = atomic_read(&dev_priv->swi_emitted);
30816 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30817 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30818
30819 BEGIN_RING(4);
30820 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30821 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30822 drm_radeon_private_t *dev_priv =
30823 (drm_radeon_private_t *) dev->dev_private;
30824
30825 - atomic_set(&dev_priv->swi_emitted, 0);
30826 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30827 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30828
30829 dev->max_vblank_count = 0x001fffff;
30830 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30831 index e8422ae..d22d4a8 100644
30832 --- a/drivers/gpu/drm/radeon/radeon_state.c
30833 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30834 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30835 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30836 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30837
30838 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30839 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30840 sarea_priv->nbox * sizeof(depth_boxes[0])))
30841 return -EFAULT;
30842
30843 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30844 {
30845 drm_radeon_private_t *dev_priv = dev->dev_private;
30846 drm_radeon_getparam_t *param = data;
30847 - int value;
30848 + int value = 0;
30849
30850 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30851
30852 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30853 index c421e77..e6bf2e8 100644
30854 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30855 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30856 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30857 }
30858 if (unlikely(ttm_vm_ops == NULL)) {
30859 ttm_vm_ops = vma->vm_ops;
30860 - radeon_ttm_vm_ops = *ttm_vm_ops;
30861 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30862 + pax_open_kernel();
30863 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30864 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30865 + pax_close_kernel();
30866 }
30867 vma->vm_ops = &radeon_ttm_vm_ops;
30868 return 0;
30869 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30870 index f68dff2..8df955c 100644
30871 --- a/drivers/gpu/drm/radeon/rs690.c
30872 +++ b/drivers/gpu/drm/radeon/rs690.c
30873 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30874 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30875 rdev->pm.sideport_bandwidth.full)
30876 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30877 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30878 + read_delay_latency.full = dfixed_const(800 * 1000);
30879 read_delay_latency.full = dfixed_div(read_delay_latency,
30880 rdev->pm.igp_sideport_mclk);
30881 + a.full = dfixed_const(370);
30882 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30883 } else {
30884 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30885 rdev->pm.k8_bandwidth.full)
30886 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30887 index 499debd..66fce72 100644
30888 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30889 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30890 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30891 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30892 struct shrink_control *sc)
30893 {
30894 - static atomic_t start_pool = ATOMIC_INIT(0);
30895 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30896 unsigned i;
30897 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30898 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30899 struct ttm_page_pool *pool;
30900 int shrink_pages = sc->nr_to_scan;
30901
30902 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30903 index 88edacc..1e5412b 100644
30904 --- a/drivers/gpu/drm/via/via_drv.h
30905 +++ b/drivers/gpu/drm/via/via_drv.h
30906 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30907 typedef uint32_t maskarray_t[5];
30908
30909 typedef struct drm_via_irq {
30910 - atomic_t irq_received;
30911 + atomic_unchecked_t irq_received;
30912 uint32_t pending_mask;
30913 uint32_t enable_mask;
30914 wait_queue_head_t irq_queue;
30915 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30916 struct timeval last_vblank;
30917 int last_vblank_valid;
30918 unsigned usec_per_vblank;
30919 - atomic_t vbl_received;
30920 + atomic_unchecked_t vbl_received;
30921 drm_via_state_t hc_state;
30922 char pci_buf[VIA_PCI_BUF_SIZE];
30923 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30924 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30925 index d391f48..10c8ca3 100644
30926 --- a/drivers/gpu/drm/via/via_irq.c
30927 +++ b/drivers/gpu/drm/via/via_irq.c
30928 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30929 if (crtc != 0)
30930 return 0;
30931
30932 - return atomic_read(&dev_priv->vbl_received);
30933 + return atomic_read_unchecked(&dev_priv->vbl_received);
30934 }
30935
30936 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30937 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30938
30939 status = VIA_READ(VIA_REG_INTERRUPT);
30940 if (status & VIA_IRQ_VBLANK_PENDING) {
30941 - atomic_inc(&dev_priv->vbl_received);
30942 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30943 + atomic_inc_unchecked(&dev_priv->vbl_received);
30944 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30945 do_gettimeofday(&cur_vblank);
30946 if (dev_priv->last_vblank_valid) {
30947 dev_priv->usec_per_vblank =
30948 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30949 dev_priv->last_vblank = cur_vblank;
30950 dev_priv->last_vblank_valid = 1;
30951 }
30952 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30953 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30954 DRM_DEBUG("US per vblank is: %u\n",
30955 dev_priv->usec_per_vblank);
30956 }
30957 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30958
30959 for (i = 0; i < dev_priv->num_irqs; ++i) {
30960 if (status & cur_irq->pending_mask) {
30961 - atomic_inc(&cur_irq->irq_received);
30962 + atomic_inc_unchecked(&cur_irq->irq_received);
30963 DRM_WAKEUP(&cur_irq->irq_queue);
30964 handled = 1;
30965 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30966 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30967 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30968 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30969 masks[irq][4]));
30970 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30971 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30972 } else {
30973 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30974 (((cur_irq_sequence =
30975 - atomic_read(&cur_irq->irq_received)) -
30976 + atomic_read_unchecked(&cur_irq->irq_received)) -
30977 *sequence) <= (1 << 23)));
30978 }
30979 *sequence = cur_irq_sequence;
30980 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30981 }
30982
30983 for (i = 0; i < dev_priv->num_irqs; ++i) {
30984 - atomic_set(&cur_irq->irq_received, 0);
30985 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30986 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30987 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30988 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30989 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30990 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30991 case VIA_IRQ_RELATIVE:
30992 irqwait->request.sequence +=
30993 - atomic_read(&cur_irq->irq_received);
30994 + atomic_read_unchecked(&cur_irq->irq_received);
30995 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30996 case VIA_IRQ_ABSOLUTE:
30997 break;
30998 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30999 index dc27970..f18b008 100644
31000 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31001 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31002 @@ -260,7 +260,7 @@ struct vmw_private {
31003 * Fencing and IRQs.
31004 */
31005
31006 - atomic_t marker_seq;
31007 + atomic_unchecked_t marker_seq;
31008 wait_queue_head_t fence_queue;
31009 wait_queue_head_t fifo_queue;
31010 int fence_queue_waiters; /* Protected by hw_mutex */
31011 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31012 index a0c2f12..68ae6cb 100644
31013 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31014 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31015 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31016 (unsigned int) min,
31017 (unsigned int) fifo->capabilities);
31018
31019 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31020 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31021 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31022 vmw_marker_queue_init(&fifo->marker_queue);
31023 return vmw_fifo_send_fence(dev_priv, &dummy);
31024 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31025 if (reserveable)
31026 iowrite32(bytes, fifo_mem +
31027 SVGA_FIFO_RESERVED);
31028 - return fifo_mem + (next_cmd >> 2);
31029 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31030 } else {
31031 need_bounce = true;
31032 }
31033 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31034
31035 fm = vmw_fifo_reserve(dev_priv, bytes);
31036 if (unlikely(fm == NULL)) {
31037 - *seqno = atomic_read(&dev_priv->marker_seq);
31038 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31039 ret = -ENOMEM;
31040 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31041 false, 3*HZ);
31042 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31043 }
31044
31045 do {
31046 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31047 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31048 } while (*seqno == 0);
31049
31050 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31051 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31052 index cabc95f..14b3d77 100644
31053 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31054 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31055 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31056 * emitted. Then the fence is stale and signaled.
31057 */
31058
31059 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31060 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31061 > VMW_FENCE_WRAP);
31062
31063 return ret;
31064 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31065
31066 if (fifo_idle)
31067 down_read(&fifo_state->rwsem);
31068 - signal_seq = atomic_read(&dev_priv->marker_seq);
31069 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31070 ret = 0;
31071
31072 for (;;) {
31073 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31074 index 8a8725c..afed796 100644
31075 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31076 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31077 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31078 while (!vmw_lag_lt(queue, us)) {
31079 spin_lock(&queue->lock);
31080 if (list_empty(&queue->head))
31081 - seqno = atomic_read(&dev_priv->marker_seq);
31082 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31083 else {
31084 marker = list_first_entry(&queue->head,
31085 struct vmw_marker, head);
31086 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31087 index 75dbe34..f9204a8 100644
31088 --- a/drivers/hid/hid-core.c
31089 +++ b/drivers/hid/hid-core.c
31090 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31091
31092 int hid_add_device(struct hid_device *hdev)
31093 {
31094 - static atomic_t id = ATOMIC_INIT(0);
31095 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31096 int ret;
31097
31098 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31099 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31100 /* XXX hack, any other cleaner solution after the driver core
31101 * is converted to allow more than 20 bytes as the device name? */
31102 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31103 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31104 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31105
31106 hid_debug_register(hdev, dev_name(&hdev->dev));
31107 ret = device_add(&hdev->dev);
31108 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31109 index b1ec0e2..c295a61 100644
31110 --- a/drivers/hid/usbhid/hiddev.c
31111 +++ b/drivers/hid/usbhid/hiddev.c
31112 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31113 break;
31114
31115 case HIDIOCAPPLICATION:
31116 - if (arg < 0 || arg >= hid->maxapplication)
31117 + if (arg >= hid->maxapplication)
31118 break;
31119
31120 for (i = 0; i < hid->maxcollection; i++)
31121 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31122 index 4065374..10ed7dc 100644
31123 --- a/drivers/hv/channel.c
31124 +++ b/drivers/hv/channel.c
31125 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31126 int ret = 0;
31127 int t;
31128
31129 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31130 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31131 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31132 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31133
31134 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31135 if (ret)
31136 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31137 index 12aa97f..c0679f7 100644
31138 --- a/drivers/hv/hv.c
31139 +++ b/drivers/hv/hv.c
31140 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31141 u64 output_address = (output) ? virt_to_phys(output) : 0;
31142 u32 output_address_hi = output_address >> 32;
31143 u32 output_address_lo = output_address & 0xFFFFFFFF;
31144 - void *hypercall_page = hv_context.hypercall_page;
31145 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31146
31147 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31148 "=a"(hv_status_lo) : "d" (control_hi),
31149 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31150 index 6d7d286..92b0873 100644
31151 --- a/drivers/hv/hyperv_vmbus.h
31152 +++ b/drivers/hv/hyperv_vmbus.h
31153 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31154 struct vmbus_connection {
31155 enum vmbus_connect_state conn_state;
31156
31157 - atomic_t next_gpadl_handle;
31158 + atomic_unchecked_t next_gpadl_handle;
31159
31160 /*
31161 * Represents channel interrupts. Each bit position represents a
31162 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31163 index a220e57..428f54d 100644
31164 --- a/drivers/hv/vmbus_drv.c
31165 +++ b/drivers/hv/vmbus_drv.c
31166 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31167 {
31168 int ret = 0;
31169
31170 - static atomic_t device_num = ATOMIC_INIT(0);
31171 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31172
31173 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31174 - atomic_inc_return(&device_num));
31175 + atomic_inc_return_unchecked(&device_num));
31176
31177 child_device_obj->device.bus = &hv_bus;
31178 child_device_obj->device.parent = &hv_acpi_dev->dev;
31179 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31180 index 554f046..f8b4729 100644
31181 --- a/drivers/hwmon/acpi_power_meter.c
31182 +++ b/drivers/hwmon/acpi_power_meter.c
31183 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31184 return res;
31185
31186 temp /= 1000;
31187 - if (temp < 0)
31188 - return -EINVAL;
31189
31190 mutex_lock(&resource->lock);
31191 resource->trip[attr->index - 7] = temp;
31192 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31193 index 91fdd1f..b66a686 100644
31194 --- a/drivers/hwmon/sht15.c
31195 +++ b/drivers/hwmon/sht15.c
31196 @@ -166,7 +166,7 @@ struct sht15_data {
31197 int supply_uV;
31198 bool supply_uV_valid;
31199 struct work_struct update_supply_work;
31200 - atomic_t interrupt_handled;
31201 + atomic_unchecked_t interrupt_handled;
31202 };
31203
31204 /**
31205 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31206 return ret;
31207
31208 gpio_direction_input(data->pdata->gpio_data);
31209 - atomic_set(&data->interrupt_handled, 0);
31210 + atomic_set_unchecked(&data->interrupt_handled, 0);
31211
31212 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31213 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31214 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31215 /* Only relevant if the interrupt hasn't occurred. */
31216 - if (!atomic_read(&data->interrupt_handled))
31217 + if (!atomic_read_unchecked(&data->interrupt_handled))
31218 schedule_work(&data->read_work);
31219 }
31220 ret = wait_event_timeout(data->wait_queue,
31221 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31222
31223 /* First disable the interrupt */
31224 disable_irq_nosync(irq);
31225 - atomic_inc(&data->interrupt_handled);
31226 + atomic_inc_unchecked(&data->interrupt_handled);
31227 /* Then schedule a reading work struct */
31228 if (data->state != SHT15_READING_NOTHING)
31229 schedule_work(&data->read_work);
31230 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31231 * If not, then start the interrupt again - care here as could
31232 * have gone low in meantime so verify it hasn't!
31233 */
31234 - atomic_set(&data->interrupt_handled, 0);
31235 + atomic_set_unchecked(&data->interrupt_handled, 0);
31236 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31237 /* If still not occurred or another handler has been scheduled */
31238 if (gpio_get_value(data->pdata->gpio_data)
31239 - || atomic_read(&data->interrupt_handled))
31240 + || atomic_read_unchecked(&data->interrupt_handled))
31241 return;
31242 }
31243
31244 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31245 index 378fcb5..5e91fa8 100644
31246 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31247 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31248 @@ -43,7 +43,7 @@
31249 extern struct i2c_adapter amd756_smbus;
31250
31251 static struct i2c_adapter *s4882_adapter;
31252 -static struct i2c_algorithm *s4882_algo;
31253 +static i2c_algorithm_no_const *s4882_algo;
31254
31255 /* Wrapper access functions for multiplexed SMBus */
31256 static DEFINE_MUTEX(amd756_lock);
31257 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31258 index 29015eb..af2d8e9 100644
31259 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31260 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31261 @@ -41,7 +41,7 @@
31262 extern struct i2c_adapter *nforce2_smbus;
31263
31264 static struct i2c_adapter *s4985_adapter;
31265 -static struct i2c_algorithm *s4985_algo;
31266 +static i2c_algorithm_no_const *s4985_algo;
31267
31268 /* Wrapper access functions for multiplexed SMBus */
31269 static DEFINE_MUTEX(nforce2_lock);
31270 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31271 index d7a4833..7fae376 100644
31272 --- a/drivers/i2c/i2c-mux.c
31273 +++ b/drivers/i2c/i2c-mux.c
31274 @@ -28,7 +28,7 @@
31275 /* multiplexer per channel data */
31276 struct i2c_mux_priv {
31277 struct i2c_adapter adap;
31278 - struct i2c_algorithm algo;
31279 + i2c_algorithm_no_const algo;
31280
31281 struct i2c_adapter *parent;
31282 void *mux_dev; /* the mux chip/device */
31283 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31284 index 57d00ca..0145194 100644
31285 --- a/drivers/ide/aec62xx.c
31286 +++ b/drivers/ide/aec62xx.c
31287 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31288 .cable_detect = atp86x_cable_detect,
31289 };
31290
31291 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31292 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31293 { /* 0: AEC6210 */
31294 .name = DRV_NAME,
31295 .init_chipset = init_chipset_aec62xx,
31296 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31297 index 2c8016a..911a27c 100644
31298 --- a/drivers/ide/alim15x3.c
31299 +++ b/drivers/ide/alim15x3.c
31300 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31301 .dma_sff_read_status = ide_dma_sff_read_status,
31302 };
31303
31304 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31305 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31306 .name = DRV_NAME,
31307 .init_chipset = init_chipset_ali15x3,
31308 .init_hwif = init_hwif_ali15x3,
31309 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31310 index 3747b25..56fc995 100644
31311 --- a/drivers/ide/amd74xx.c
31312 +++ b/drivers/ide/amd74xx.c
31313 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31314 .udma_mask = udma, \
31315 }
31316
31317 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31318 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31319 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31320 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31321 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31322 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31323 index 15f0ead..cb43480 100644
31324 --- a/drivers/ide/atiixp.c
31325 +++ b/drivers/ide/atiixp.c
31326 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31327 .cable_detect = atiixp_cable_detect,
31328 };
31329
31330 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31331 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31332 { /* 0: IXP200/300/400/700 */
31333 .name = DRV_NAME,
31334 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31335 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31336 index 5f80312..d1fc438 100644
31337 --- a/drivers/ide/cmd64x.c
31338 +++ b/drivers/ide/cmd64x.c
31339 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31340 .dma_sff_read_status = ide_dma_sff_read_status,
31341 };
31342
31343 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31344 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31345 { /* 0: CMD643 */
31346 .name = DRV_NAME,
31347 .init_chipset = init_chipset_cmd64x,
31348 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31349 index 2c1e5f7..1444762 100644
31350 --- a/drivers/ide/cs5520.c
31351 +++ b/drivers/ide/cs5520.c
31352 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31353 .set_dma_mode = cs5520_set_dma_mode,
31354 };
31355
31356 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31357 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31358 .name = DRV_NAME,
31359 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31360 .port_ops = &cs5520_port_ops,
31361 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31362 index 4dc4eb9..49b40ad 100644
31363 --- a/drivers/ide/cs5530.c
31364 +++ b/drivers/ide/cs5530.c
31365 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31366 .udma_filter = cs5530_udma_filter,
31367 };
31368
31369 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31370 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31371 .name = DRV_NAME,
31372 .init_chipset = init_chipset_cs5530,
31373 .init_hwif = init_hwif_cs5530,
31374 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31375 index 5059faf..18d4c85 100644
31376 --- a/drivers/ide/cs5535.c
31377 +++ b/drivers/ide/cs5535.c
31378 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31379 .cable_detect = cs5535_cable_detect,
31380 };
31381
31382 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31383 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31384 .name = DRV_NAME,
31385 .port_ops = &cs5535_port_ops,
31386 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31387 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31388 index 847553f..3ffb49d 100644
31389 --- a/drivers/ide/cy82c693.c
31390 +++ b/drivers/ide/cy82c693.c
31391 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31392 .set_dma_mode = cy82c693_set_dma_mode,
31393 };
31394
31395 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31396 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31397 .name = DRV_NAME,
31398 .init_iops = init_iops_cy82c693,
31399 .port_ops = &cy82c693_port_ops,
31400 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31401 index 58c51cd..4aec3b8 100644
31402 --- a/drivers/ide/hpt366.c
31403 +++ b/drivers/ide/hpt366.c
31404 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31405 }
31406 };
31407
31408 -static const struct hpt_info hpt36x __devinitdata = {
31409 +static const struct hpt_info hpt36x __devinitconst = {
31410 .chip_name = "HPT36x",
31411 .chip_type = HPT36x,
31412 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31413 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31414 .timings = &hpt36x_timings
31415 };
31416
31417 -static const struct hpt_info hpt370 __devinitdata = {
31418 +static const struct hpt_info hpt370 __devinitconst = {
31419 .chip_name = "HPT370",
31420 .chip_type = HPT370,
31421 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31422 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31423 .timings = &hpt37x_timings
31424 };
31425
31426 -static const struct hpt_info hpt370a __devinitdata = {
31427 +static const struct hpt_info hpt370a __devinitconst = {
31428 .chip_name = "HPT370A",
31429 .chip_type = HPT370A,
31430 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31431 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31432 .timings = &hpt37x_timings
31433 };
31434
31435 -static const struct hpt_info hpt374 __devinitdata = {
31436 +static const struct hpt_info hpt374 __devinitconst = {
31437 .chip_name = "HPT374",
31438 .chip_type = HPT374,
31439 .udma_mask = ATA_UDMA5,
31440 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31441 .timings = &hpt37x_timings
31442 };
31443
31444 -static const struct hpt_info hpt372 __devinitdata = {
31445 +static const struct hpt_info hpt372 __devinitconst = {
31446 .chip_name = "HPT372",
31447 .chip_type = HPT372,
31448 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31449 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31450 .timings = &hpt37x_timings
31451 };
31452
31453 -static const struct hpt_info hpt372a __devinitdata = {
31454 +static const struct hpt_info hpt372a __devinitconst = {
31455 .chip_name = "HPT372A",
31456 .chip_type = HPT372A,
31457 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31458 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31459 .timings = &hpt37x_timings
31460 };
31461
31462 -static const struct hpt_info hpt302 __devinitdata = {
31463 +static const struct hpt_info hpt302 __devinitconst = {
31464 .chip_name = "HPT302",
31465 .chip_type = HPT302,
31466 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31467 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31468 .timings = &hpt37x_timings
31469 };
31470
31471 -static const struct hpt_info hpt371 __devinitdata = {
31472 +static const struct hpt_info hpt371 __devinitconst = {
31473 .chip_name = "HPT371",
31474 .chip_type = HPT371,
31475 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31476 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31477 .timings = &hpt37x_timings
31478 };
31479
31480 -static const struct hpt_info hpt372n __devinitdata = {
31481 +static const struct hpt_info hpt372n __devinitconst = {
31482 .chip_name = "HPT372N",
31483 .chip_type = HPT372N,
31484 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31485 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31486 .timings = &hpt37x_timings
31487 };
31488
31489 -static const struct hpt_info hpt302n __devinitdata = {
31490 +static const struct hpt_info hpt302n __devinitconst = {
31491 .chip_name = "HPT302N",
31492 .chip_type = HPT302N,
31493 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31494 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31495 .timings = &hpt37x_timings
31496 };
31497
31498 -static const struct hpt_info hpt371n __devinitdata = {
31499 +static const struct hpt_info hpt371n __devinitconst = {
31500 .chip_name = "HPT371N",
31501 .chip_type = HPT371N,
31502 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31503 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31504 .dma_sff_read_status = ide_dma_sff_read_status,
31505 };
31506
31507 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31508 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31509 { /* 0: HPT36x */
31510 .name = DRV_NAME,
31511 .init_chipset = init_chipset_hpt366,
31512 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31513 index 8126824..55a2798 100644
31514 --- a/drivers/ide/ide-cd.c
31515 +++ b/drivers/ide/ide-cd.c
31516 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31517 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31518 if ((unsigned long)buf & alignment
31519 || blk_rq_bytes(rq) & q->dma_pad_mask
31520 - || object_is_on_stack(buf))
31521 + || object_starts_on_stack(buf))
31522 drive->dma = 0;
31523 }
31524 }
31525 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31526 index 7f56b73..dab5b67 100644
31527 --- a/drivers/ide/ide-pci-generic.c
31528 +++ b/drivers/ide/ide-pci-generic.c
31529 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31530 .udma_mask = ATA_UDMA6, \
31531 }
31532
31533 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31534 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31535 /* 0: Unknown */
31536 DECLARE_GENERIC_PCI_DEV(0),
31537
31538 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31539 index 560e66d..d5dd180 100644
31540 --- a/drivers/ide/it8172.c
31541 +++ b/drivers/ide/it8172.c
31542 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31543 .set_dma_mode = it8172_set_dma_mode,
31544 };
31545
31546 -static const struct ide_port_info it8172_port_info __devinitdata = {
31547 +static const struct ide_port_info it8172_port_info __devinitconst = {
31548 .name = DRV_NAME,
31549 .port_ops = &it8172_port_ops,
31550 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31551 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31552 index 46816ba..1847aeb 100644
31553 --- a/drivers/ide/it8213.c
31554 +++ b/drivers/ide/it8213.c
31555 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31556 .cable_detect = it8213_cable_detect,
31557 };
31558
31559 -static const struct ide_port_info it8213_chipset __devinitdata = {
31560 +static const struct ide_port_info it8213_chipset __devinitconst = {
31561 .name = DRV_NAME,
31562 .enablebits = { {0x41, 0x80, 0x80} },
31563 .port_ops = &it8213_port_ops,
31564 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31565 index 2e3169f..c5611db 100644
31566 --- a/drivers/ide/it821x.c
31567 +++ b/drivers/ide/it821x.c
31568 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31569 .cable_detect = it821x_cable_detect,
31570 };
31571
31572 -static const struct ide_port_info it821x_chipset __devinitdata = {
31573 +static const struct ide_port_info it821x_chipset __devinitconst = {
31574 .name = DRV_NAME,
31575 .init_chipset = init_chipset_it821x,
31576 .init_hwif = init_hwif_it821x,
31577 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31578 index 74c2c4a..efddd7d 100644
31579 --- a/drivers/ide/jmicron.c
31580 +++ b/drivers/ide/jmicron.c
31581 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31582 .cable_detect = jmicron_cable_detect,
31583 };
31584
31585 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31586 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31587 .name = DRV_NAME,
31588 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31589 .port_ops = &jmicron_port_ops,
31590 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31591 index 95327a2..73f78d8 100644
31592 --- a/drivers/ide/ns87415.c
31593 +++ b/drivers/ide/ns87415.c
31594 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31595 .dma_sff_read_status = superio_dma_sff_read_status,
31596 };
31597
31598 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31599 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31600 .name = DRV_NAME,
31601 .init_hwif = init_hwif_ns87415,
31602 .tp_ops = &ns87415_tp_ops,
31603 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31604 index 1a53a4c..39edc66 100644
31605 --- a/drivers/ide/opti621.c
31606 +++ b/drivers/ide/opti621.c
31607 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31608 .set_pio_mode = opti621_set_pio_mode,
31609 };
31610
31611 -static const struct ide_port_info opti621_chipset __devinitdata = {
31612 +static const struct ide_port_info opti621_chipset __devinitconst = {
31613 .name = DRV_NAME,
31614 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31615 .port_ops = &opti621_port_ops,
31616 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31617 index 9546fe2..2e5ceb6 100644
31618 --- a/drivers/ide/pdc202xx_new.c
31619 +++ b/drivers/ide/pdc202xx_new.c
31620 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31621 .udma_mask = udma, \
31622 }
31623
31624 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31625 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31626 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31627 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31628 };
31629 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31630 index 3a35ec6..5634510 100644
31631 --- a/drivers/ide/pdc202xx_old.c
31632 +++ b/drivers/ide/pdc202xx_old.c
31633 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31634 .max_sectors = sectors, \
31635 }
31636
31637 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31638 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31639 { /* 0: PDC20246 */
31640 .name = DRV_NAME,
31641 .init_chipset = init_chipset_pdc202xx,
31642 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31643 index 1892e81..fe0fd60 100644
31644 --- a/drivers/ide/piix.c
31645 +++ b/drivers/ide/piix.c
31646 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31647 .udma_mask = udma, \
31648 }
31649
31650 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31651 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31652 /* 0: MPIIX */
31653 { /*
31654 * MPIIX actually has only a single IDE channel mapped to
31655 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31656 index a6414a8..c04173e 100644
31657 --- a/drivers/ide/rz1000.c
31658 +++ b/drivers/ide/rz1000.c
31659 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31660 }
31661 }
31662
31663 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31664 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31665 .name = DRV_NAME,
31666 .host_flags = IDE_HFLAG_NO_DMA,
31667 };
31668 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31669 index 356b9b5..d4758eb 100644
31670 --- a/drivers/ide/sc1200.c
31671 +++ b/drivers/ide/sc1200.c
31672 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31673 .dma_sff_read_status = ide_dma_sff_read_status,
31674 };
31675
31676 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31677 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31678 .name = DRV_NAME,
31679 .port_ops = &sc1200_port_ops,
31680 .dma_ops = &sc1200_dma_ops,
31681 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31682 index b7f5b0c..9701038 100644
31683 --- a/drivers/ide/scc_pata.c
31684 +++ b/drivers/ide/scc_pata.c
31685 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31686 .dma_sff_read_status = scc_dma_sff_read_status,
31687 };
31688
31689 -static const struct ide_port_info scc_chipset __devinitdata = {
31690 +static const struct ide_port_info scc_chipset __devinitconst = {
31691 .name = "sccIDE",
31692 .init_iops = init_iops_scc,
31693 .init_dma = scc_init_dma,
31694 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31695 index 35fb8da..24d72ef 100644
31696 --- a/drivers/ide/serverworks.c
31697 +++ b/drivers/ide/serverworks.c
31698 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31699 .cable_detect = svwks_cable_detect,
31700 };
31701
31702 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31703 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31704 { /* 0: OSB4 */
31705 .name = DRV_NAME,
31706 .init_chipset = init_chipset_svwks,
31707 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31708 index ddeda44..46f7e30 100644
31709 --- a/drivers/ide/siimage.c
31710 +++ b/drivers/ide/siimage.c
31711 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31712 .udma_mask = ATA_UDMA6, \
31713 }
31714
31715 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31716 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31717 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31718 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31719 };
31720 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31721 index 4a00225..09e61b4 100644
31722 --- a/drivers/ide/sis5513.c
31723 +++ b/drivers/ide/sis5513.c
31724 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31725 .cable_detect = sis_cable_detect,
31726 };
31727
31728 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31729 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31730 .name = DRV_NAME,
31731 .init_chipset = init_chipset_sis5513,
31732 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31733 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31734 index f21dc2a..d051cd2 100644
31735 --- a/drivers/ide/sl82c105.c
31736 +++ b/drivers/ide/sl82c105.c
31737 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31738 .dma_sff_read_status = ide_dma_sff_read_status,
31739 };
31740
31741 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31742 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31743 .name = DRV_NAME,
31744 .init_chipset = init_chipset_sl82c105,
31745 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31746 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31747 index 864ffe0..863a5e9 100644
31748 --- a/drivers/ide/slc90e66.c
31749 +++ b/drivers/ide/slc90e66.c
31750 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31751 .cable_detect = slc90e66_cable_detect,
31752 };
31753
31754 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31755 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31756 .name = DRV_NAME,
31757 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31758 .port_ops = &slc90e66_port_ops,
31759 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31760 index 4799d5c..1794678 100644
31761 --- a/drivers/ide/tc86c001.c
31762 +++ b/drivers/ide/tc86c001.c
31763 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31764 .dma_sff_read_status = ide_dma_sff_read_status,
31765 };
31766
31767 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31768 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31769 .name = DRV_NAME,
31770 .init_hwif = init_hwif_tc86c001,
31771 .port_ops = &tc86c001_port_ops,
31772 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31773 index 281c914..55ce1b8 100644
31774 --- a/drivers/ide/triflex.c
31775 +++ b/drivers/ide/triflex.c
31776 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31777 .set_dma_mode = triflex_set_mode,
31778 };
31779
31780 -static const struct ide_port_info triflex_device __devinitdata = {
31781 +static const struct ide_port_info triflex_device __devinitconst = {
31782 .name = DRV_NAME,
31783 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31784 .port_ops = &triflex_port_ops,
31785 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31786 index 4b42ca0..e494a98 100644
31787 --- a/drivers/ide/trm290.c
31788 +++ b/drivers/ide/trm290.c
31789 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31790 .dma_check = trm290_dma_check,
31791 };
31792
31793 -static const struct ide_port_info trm290_chipset __devinitdata = {
31794 +static const struct ide_port_info trm290_chipset __devinitconst = {
31795 .name = DRV_NAME,
31796 .init_hwif = init_hwif_trm290,
31797 .tp_ops = &trm290_tp_ops,
31798 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31799 index f46f49c..eb77678 100644
31800 --- a/drivers/ide/via82cxxx.c
31801 +++ b/drivers/ide/via82cxxx.c
31802 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31803 .cable_detect = via82cxxx_cable_detect,
31804 };
31805
31806 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31807 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31808 .name = DRV_NAME,
31809 .init_chipset = init_chipset_via82cxxx,
31810 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31811 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31812 index 73d4531..c90cd2d 100644
31813 --- a/drivers/ieee802154/fakehard.c
31814 +++ b/drivers/ieee802154/fakehard.c
31815 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31816 phy->transmit_power = 0xbf;
31817
31818 dev->netdev_ops = &fake_ops;
31819 - dev->ml_priv = &fake_mlme;
31820 + dev->ml_priv = (void *)&fake_mlme;
31821
31822 priv = netdev_priv(dev);
31823 priv->phy = phy;
31824 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31825 index c889aae..6cf5aa7 100644
31826 --- a/drivers/infiniband/core/cm.c
31827 +++ b/drivers/infiniband/core/cm.c
31828 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31829
31830 struct cm_counter_group {
31831 struct kobject obj;
31832 - atomic_long_t counter[CM_ATTR_COUNT];
31833 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31834 };
31835
31836 struct cm_counter_attribute {
31837 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31838 struct ib_mad_send_buf *msg = NULL;
31839 int ret;
31840
31841 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31842 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31843 counter[CM_REQ_COUNTER]);
31844
31845 /* Quick state check to discard duplicate REQs. */
31846 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31847 if (!cm_id_priv)
31848 return;
31849
31850 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31851 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31852 counter[CM_REP_COUNTER]);
31853 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31854 if (ret)
31855 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31856 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31857 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31858 spin_unlock_irq(&cm_id_priv->lock);
31859 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31860 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31861 counter[CM_RTU_COUNTER]);
31862 goto out;
31863 }
31864 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31865 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31866 dreq_msg->local_comm_id);
31867 if (!cm_id_priv) {
31868 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31869 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31870 counter[CM_DREQ_COUNTER]);
31871 cm_issue_drep(work->port, work->mad_recv_wc);
31872 return -EINVAL;
31873 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31874 case IB_CM_MRA_REP_RCVD:
31875 break;
31876 case IB_CM_TIMEWAIT:
31877 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31878 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31879 counter[CM_DREQ_COUNTER]);
31880 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31881 goto unlock;
31882 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31883 cm_free_msg(msg);
31884 goto deref;
31885 case IB_CM_DREQ_RCVD:
31886 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31887 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31888 counter[CM_DREQ_COUNTER]);
31889 goto unlock;
31890 default:
31891 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31892 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31893 cm_id_priv->msg, timeout)) {
31894 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31895 - atomic_long_inc(&work->port->
31896 + atomic_long_inc_unchecked(&work->port->
31897 counter_group[CM_RECV_DUPLICATES].
31898 counter[CM_MRA_COUNTER]);
31899 goto out;
31900 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31901 break;
31902 case IB_CM_MRA_REQ_RCVD:
31903 case IB_CM_MRA_REP_RCVD:
31904 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31905 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31906 counter[CM_MRA_COUNTER]);
31907 /* fall through */
31908 default:
31909 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31910 case IB_CM_LAP_IDLE:
31911 break;
31912 case IB_CM_MRA_LAP_SENT:
31913 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31914 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31915 counter[CM_LAP_COUNTER]);
31916 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31917 goto unlock;
31918 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31919 cm_free_msg(msg);
31920 goto deref;
31921 case IB_CM_LAP_RCVD:
31922 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31923 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31924 counter[CM_LAP_COUNTER]);
31925 goto unlock;
31926 default:
31927 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31928 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31929 if (cur_cm_id_priv) {
31930 spin_unlock_irq(&cm.lock);
31931 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31932 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31933 counter[CM_SIDR_REQ_COUNTER]);
31934 goto out; /* Duplicate message. */
31935 }
31936 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31937 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31938 msg->retries = 1;
31939
31940 - atomic_long_add(1 + msg->retries,
31941 + atomic_long_add_unchecked(1 + msg->retries,
31942 &port->counter_group[CM_XMIT].counter[attr_index]);
31943 if (msg->retries)
31944 - atomic_long_add(msg->retries,
31945 + atomic_long_add_unchecked(msg->retries,
31946 &port->counter_group[CM_XMIT_RETRIES].
31947 counter[attr_index]);
31948
31949 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31950 }
31951
31952 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31953 - atomic_long_inc(&port->counter_group[CM_RECV].
31954 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31955 counter[attr_id - CM_ATTR_ID_OFFSET]);
31956
31957 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31958 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31959 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31960
31961 return sprintf(buf, "%ld\n",
31962 - atomic_long_read(&group->counter[cm_attr->index]));
31963 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31964 }
31965
31966 static const struct sysfs_ops cm_counter_ops = {
31967 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31968 index 176c8f9..2627b62 100644
31969 --- a/drivers/infiniband/core/fmr_pool.c
31970 +++ b/drivers/infiniband/core/fmr_pool.c
31971 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31972
31973 struct task_struct *thread;
31974
31975 - atomic_t req_ser;
31976 - atomic_t flush_ser;
31977 + atomic_unchecked_t req_ser;
31978 + atomic_unchecked_t flush_ser;
31979
31980 wait_queue_head_t force_wait;
31981 };
31982 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31983 struct ib_fmr_pool *pool = pool_ptr;
31984
31985 do {
31986 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31987 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31988 ib_fmr_batch_release(pool);
31989
31990 - atomic_inc(&pool->flush_ser);
31991 + atomic_inc_unchecked(&pool->flush_ser);
31992 wake_up_interruptible(&pool->force_wait);
31993
31994 if (pool->flush_function)
31995 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31996 }
31997
31998 set_current_state(TASK_INTERRUPTIBLE);
31999 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32000 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32001 !kthread_should_stop())
32002 schedule();
32003 __set_current_state(TASK_RUNNING);
32004 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32005 pool->dirty_watermark = params->dirty_watermark;
32006 pool->dirty_len = 0;
32007 spin_lock_init(&pool->pool_lock);
32008 - atomic_set(&pool->req_ser, 0);
32009 - atomic_set(&pool->flush_ser, 0);
32010 + atomic_set_unchecked(&pool->req_ser, 0);
32011 + atomic_set_unchecked(&pool->flush_ser, 0);
32012 init_waitqueue_head(&pool->force_wait);
32013
32014 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32015 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32016 }
32017 spin_unlock_irq(&pool->pool_lock);
32018
32019 - serial = atomic_inc_return(&pool->req_ser);
32020 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32021 wake_up_process(pool->thread);
32022
32023 if (wait_event_interruptible(pool->force_wait,
32024 - atomic_read(&pool->flush_ser) - serial >= 0))
32025 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32026 return -EINTR;
32027
32028 return 0;
32029 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32030 } else {
32031 list_add_tail(&fmr->list, &pool->dirty_list);
32032 if (++pool->dirty_len >= pool->dirty_watermark) {
32033 - atomic_inc(&pool->req_ser);
32034 + atomic_inc_unchecked(&pool->req_ser);
32035 wake_up_process(pool->thread);
32036 }
32037 }
32038 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32039 index 40c8353..946b0e4 100644
32040 --- a/drivers/infiniband/hw/cxgb4/mem.c
32041 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32042 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32043 int err;
32044 struct fw_ri_tpte tpt;
32045 u32 stag_idx;
32046 - static atomic_t key;
32047 + static atomic_unchecked_t key;
32048
32049 if (c4iw_fatal_error(rdev))
32050 return -EIO;
32051 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32052 &rdev->resource.tpt_fifo_lock);
32053 if (!stag_idx)
32054 return -ENOMEM;
32055 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32056 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32057 }
32058 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32059 __func__, stag_state, type, pdid, stag_idx);
32060 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32061 index a4de9d5..5fa20c3 100644
32062 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32063 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32064 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32065 };
32066
32067 static ssize_t flash_read(struct file *file, char __user *buf,
32068 + size_t count, loff_t *ppos) __size_overflow(3);
32069 +static ssize_t flash_read(struct file *file, char __user *buf,
32070 size_t count, loff_t *ppos)
32071 {
32072 struct ipath_devdata *dd;
32073 @@ -177,6 +179,8 @@ bail:
32074 }
32075
32076 static ssize_t flash_write(struct file *file, const char __user *buf,
32077 + size_t count, loff_t *ppos) __size_overflow(3);
32078 +static ssize_t flash_write(struct file *file, const char __user *buf,
32079 size_t count, loff_t *ppos)
32080 {
32081 struct ipath_devdata *dd;
32082 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32083 index 79b3dbc..96e5fcc 100644
32084 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32085 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32086 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32087 struct ib_atomic_eth *ateth;
32088 struct ipath_ack_entry *e;
32089 u64 vaddr;
32090 - atomic64_t *maddr;
32091 + atomic64_unchecked_t *maddr;
32092 u64 sdata;
32093 u32 rkey;
32094 u8 next;
32095 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32096 IB_ACCESS_REMOTE_ATOMIC)))
32097 goto nack_acc_unlck;
32098 /* Perform atomic OP and save result. */
32099 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32100 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32101 sdata = be64_to_cpu(ateth->swap_data);
32102 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32103 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32104 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32105 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32106 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32107 be64_to_cpu(ateth->compare_data),
32108 sdata);
32109 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32110 index 1f95bba..9530f87 100644
32111 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32112 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32113 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32114 unsigned long flags;
32115 struct ib_wc wc;
32116 u64 sdata;
32117 - atomic64_t *maddr;
32118 + atomic64_unchecked_t *maddr;
32119 enum ib_wc_status send_status;
32120
32121 /*
32122 @@ -382,11 +382,11 @@ again:
32123 IB_ACCESS_REMOTE_ATOMIC)))
32124 goto acc_err;
32125 /* Perform atomic OP and save result. */
32126 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32127 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32128 sdata = wqe->wr.wr.atomic.compare_add;
32129 *(u64 *) sqp->s_sge.sge.vaddr =
32130 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32131 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32132 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32133 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32134 sdata, wqe->wr.wr.atomic.swap);
32135 goto send_comp;
32136 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32137 index 7140199..da60063 100644
32138 --- a/drivers/infiniband/hw/nes/nes.c
32139 +++ b/drivers/infiniband/hw/nes/nes.c
32140 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32141 LIST_HEAD(nes_adapter_list);
32142 static LIST_HEAD(nes_dev_list);
32143
32144 -atomic_t qps_destroyed;
32145 +atomic_unchecked_t qps_destroyed;
32146
32147 static unsigned int ee_flsh_adapter;
32148 static unsigned int sysfs_nonidx_addr;
32149 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32150 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32151 struct nes_adapter *nesadapter = nesdev->nesadapter;
32152
32153 - atomic_inc(&qps_destroyed);
32154 + atomic_inc_unchecked(&qps_destroyed);
32155
32156 /* Free the control structures */
32157
32158 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32159 index c438e46..ca30356 100644
32160 --- a/drivers/infiniband/hw/nes/nes.h
32161 +++ b/drivers/infiniband/hw/nes/nes.h
32162 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32163 extern unsigned int wqm_quanta;
32164 extern struct list_head nes_adapter_list;
32165
32166 -extern atomic_t cm_connects;
32167 -extern atomic_t cm_accepts;
32168 -extern atomic_t cm_disconnects;
32169 -extern atomic_t cm_closes;
32170 -extern atomic_t cm_connecteds;
32171 -extern atomic_t cm_connect_reqs;
32172 -extern atomic_t cm_rejects;
32173 -extern atomic_t mod_qp_timouts;
32174 -extern atomic_t qps_created;
32175 -extern atomic_t qps_destroyed;
32176 -extern atomic_t sw_qps_destroyed;
32177 +extern atomic_unchecked_t cm_connects;
32178 +extern atomic_unchecked_t cm_accepts;
32179 +extern atomic_unchecked_t cm_disconnects;
32180 +extern atomic_unchecked_t cm_closes;
32181 +extern atomic_unchecked_t cm_connecteds;
32182 +extern atomic_unchecked_t cm_connect_reqs;
32183 +extern atomic_unchecked_t cm_rejects;
32184 +extern atomic_unchecked_t mod_qp_timouts;
32185 +extern atomic_unchecked_t qps_created;
32186 +extern atomic_unchecked_t qps_destroyed;
32187 +extern atomic_unchecked_t sw_qps_destroyed;
32188 extern u32 mh_detected;
32189 extern u32 mh_pauses_sent;
32190 extern u32 cm_packets_sent;
32191 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32192 extern u32 cm_packets_received;
32193 extern u32 cm_packets_dropped;
32194 extern u32 cm_packets_retrans;
32195 -extern atomic_t cm_listens_created;
32196 -extern atomic_t cm_listens_destroyed;
32197 +extern atomic_unchecked_t cm_listens_created;
32198 +extern atomic_unchecked_t cm_listens_destroyed;
32199 extern u32 cm_backlog_drops;
32200 -extern atomic_t cm_loopbacks;
32201 -extern atomic_t cm_nodes_created;
32202 -extern atomic_t cm_nodes_destroyed;
32203 -extern atomic_t cm_accel_dropped_pkts;
32204 -extern atomic_t cm_resets_recvd;
32205 -extern atomic_t pau_qps_created;
32206 -extern atomic_t pau_qps_destroyed;
32207 +extern atomic_unchecked_t cm_loopbacks;
32208 +extern atomic_unchecked_t cm_nodes_created;
32209 +extern atomic_unchecked_t cm_nodes_destroyed;
32210 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32211 +extern atomic_unchecked_t cm_resets_recvd;
32212 +extern atomic_unchecked_t pau_qps_created;
32213 +extern atomic_unchecked_t pau_qps_destroyed;
32214
32215 extern u32 int_mod_timer_init;
32216 extern u32 int_mod_cq_depth_256;
32217 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32218 index a4972ab..1bcfc31 100644
32219 --- a/drivers/infiniband/hw/nes/nes_cm.c
32220 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32221 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32222 u32 cm_packets_retrans;
32223 u32 cm_packets_created;
32224 u32 cm_packets_received;
32225 -atomic_t cm_listens_created;
32226 -atomic_t cm_listens_destroyed;
32227 +atomic_unchecked_t cm_listens_created;
32228 +atomic_unchecked_t cm_listens_destroyed;
32229 u32 cm_backlog_drops;
32230 -atomic_t cm_loopbacks;
32231 -atomic_t cm_nodes_created;
32232 -atomic_t cm_nodes_destroyed;
32233 -atomic_t cm_accel_dropped_pkts;
32234 -atomic_t cm_resets_recvd;
32235 +atomic_unchecked_t cm_loopbacks;
32236 +atomic_unchecked_t cm_nodes_created;
32237 +atomic_unchecked_t cm_nodes_destroyed;
32238 +atomic_unchecked_t cm_accel_dropped_pkts;
32239 +atomic_unchecked_t cm_resets_recvd;
32240
32241 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32242 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32243 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32244
32245 static struct nes_cm_core *g_cm_core;
32246
32247 -atomic_t cm_connects;
32248 -atomic_t cm_accepts;
32249 -atomic_t cm_disconnects;
32250 -atomic_t cm_closes;
32251 -atomic_t cm_connecteds;
32252 -atomic_t cm_connect_reqs;
32253 -atomic_t cm_rejects;
32254 +atomic_unchecked_t cm_connects;
32255 +atomic_unchecked_t cm_accepts;
32256 +atomic_unchecked_t cm_disconnects;
32257 +atomic_unchecked_t cm_closes;
32258 +atomic_unchecked_t cm_connecteds;
32259 +atomic_unchecked_t cm_connect_reqs;
32260 +atomic_unchecked_t cm_rejects;
32261
32262 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32263 {
32264 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32265 kfree(listener);
32266 listener = NULL;
32267 ret = 0;
32268 - atomic_inc(&cm_listens_destroyed);
32269 + atomic_inc_unchecked(&cm_listens_destroyed);
32270 } else {
32271 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32272 }
32273 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32274 cm_node->rem_mac);
32275
32276 add_hte_node(cm_core, cm_node);
32277 - atomic_inc(&cm_nodes_created);
32278 + atomic_inc_unchecked(&cm_nodes_created);
32279
32280 return cm_node;
32281 }
32282 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32283 }
32284
32285 atomic_dec(&cm_core->node_cnt);
32286 - atomic_inc(&cm_nodes_destroyed);
32287 + atomic_inc_unchecked(&cm_nodes_destroyed);
32288 nesqp = cm_node->nesqp;
32289 if (nesqp) {
32290 nesqp->cm_node = NULL;
32291 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32292
32293 static void drop_packet(struct sk_buff *skb)
32294 {
32295 - atomic_inc(&cm_accel_dropped_pkts);
32296 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32297 dev_kfree_skb_any(skb);
32298 }
32299
32300 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32301 {
32302
32303 int reset = 0; /* whether to send reset in case of err.. */
32304 - atomic_inc(&cm_resets_recvd);
32305 + atomic_inc_unchecked(&cm_resets_recvd);
32306 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32307 " refcnt=%d\n", cm_node, cm_node->state,
32308 atomic_read(&cm_node->ref_count));
32309 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32310 rem_ref_cm_node(cm_node->cm_core, cm_node);
32311 return NULL;
32312 }
32313 - atomic_inc(&cm_loopbacks);
32314 + atomic_inc_unchecked(&cm_loopbacks);
32315 loopbackremotenode->loopbackpartner = cm_node;
32316 loopbackremotenode->tcp_cntxt.rcv_wscale =
32317 NES_CM_DEFAULT_RCV_WND_SCALE;
32318 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32319 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32320 else {
32321 rem_ref_cm_node(cm_core, cm_node);
32322 - atomic_inc(&cm_accel_dropped_pkts);
32323 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32324 dev_kfree_skb_any(skb);
32325 }
32326 break;
32327 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32328
32329 if ((cm_id) && (cm_id->event_handler)) {
32330 if (issue_disconn) {
32331 - atomic_inc(&cm_disconnects);
32332 + atomic_inc_unchecked(&cm_disconnects);
32333 cm_event.event = IW_CM_EVENT_DISCONNECT;
32334 cm_event.status = disconn_status;
32335 cm_event.local_addr = cm_id->local_addr;
32336 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32337 }
32338
32339 if (issue_close) {
32340 - atomic_inc(&cm_closes);
32341 + atomic_inc_unchecked(&cm_closes);
32342 nes_disconnect(nesqp, 1);
32343
32344 cm_id->provider_data = nesqp;
32345 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32346
32347 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32348 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32349 - atomic_inc(&cm_accepts);
32350 + atomic_inc_unchecked(&cm_accepts);
32351
32352 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32353 netdev_refcnt_read(nesvnic->netdev));
32354 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32355 struct nes_cm_core *cm_core;
32356 u8 *start_buff;
32357
32358 - atomic_inc(&cm_rejects);
32359 + atomic_inc_unchecked(&cm_rejects);
32360 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32361 loopback = cm_node->loopbackpartner;
32362 cm_core = cm_node->cm_core;
32363 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32364 ntohl(cm_id->local_addr.sin_addr.s_addr),
32365 ntohs(cm_id->local_addr.sin_port));
32366
32367 - atomic_inc(&cm_connects);
32368 + atomic_inc_unchecked(&cm_connects);
32369 nesqp->active_conn = 1;
32370
32371 /* cache the cm_id in the qp */
32372 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32373 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32374 return err;
32375 }
32376 - atomic_inc(&cm_listens_created);
32377 + atomic_inc_unchecked(&cm_listens_created);
32378 }
32379
32380 cm_id->add_ref(cm_id);
32381 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32382
32383 if (nesqp->destroyed)
32384 return;
32385 - atomic_inc(&cm_connecteds);
32386 + atomic_inc_unchecked(&cm_connecteds);
32387 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32388 " local port 0x%04X. jiffies = %lu.\n",
32389 nesqp->hwqp.qp_id,
32390 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32391
32392 cm_id->add_ref(cm_id);
32393 ret = cm_id->event_handler(cm_id, &cm_event);
32394 - atomic_inc(&cm_closes);
32395 + atomic_inc_unchecked(&cm_closes);
32396 cm_event.event = IW_CM_EVENT_CLOSE;
32397 cm_event.status = 0;
32398 cm_event.provider_data = cm_id->provider_data;
32399 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32400 return;
32401 cm_id = cm_node->cm_id;
32402
32403 - atomic_inc(&cm_connect_reqs);
32404 + atomic_inc_unchecked(&cm_connect_reqs);
32405 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32406 cm_node, cm_id, jiffies);
32407
32408 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32409 return;
32410 cm_id = cm_node->cm_id;
32411
32412 - atomic_inc(&cm_connect_reqs);
32413 + atomic_inc_unchecked(&cm_connect_reqs);
32414 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32415 cm_node, cm_id, jiffies);
32416
32417 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32418 index 3ba7be3..c81f6ff 100644
32419 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32420 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32421 @@ -40,8 +40,8 @@
32422 #include "nes.h"
32423 #include "nes_mgt.h"
32424
32425 -atomic_t pau_qps_created;
32426 -atomic_t pau_qps_destroyed;
32427 +atomic_unchecked_t pau_qps_created;
32428 +atomic_unchecked_t pau_qps_destroyed;
32429
32430 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32431 {
32432 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32433 {
32434 struct sk_buff *skb;
32435 unsigned long flags;
32436 - atomic_inc(&pau_qps_destroyed);
32437 + atomic_inc_unchecked(&pau_qps_destroyed);
32438
32439 /* Free packets that have not yet been forwarded */
32440 /* Lock is acquired by skb_dequeue when removing the skb */
32441 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32442 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32443 skb_queue_head_init(&nesqp->pau_list);
32444 spin_lock_init(&nesqp->pau_lock);
32445 - atomic_inc(&pau_qps_created);
32446 + atomic_inc_unchecked(&pau_qps_created);
32447 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32448 }
32449
32450 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32451 index f3a3ecf..57d311d 100644
32452 --- a/drivers/infiniband/hw/nes/nes_nic.c
32453 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32454 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32455 target_stat_values[++index] = mh_detected;
32456 target_stat_values[++index] = mh_pauses_sent;
32457 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32458 - target_stat_values[++index] = atomic_read(&cm_connects);
32459 - target_stat_values[++index] = atomic_read(&cm_accepts);
32460 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32461 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32462 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32463 - target_stat_values[++index] = atomic_read(&cm_rejects);
32464 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32465 - target_stat_values[++index] = atomic_read(&qps_created);
32466 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32467 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32468 - target_stat_values[++index] = atomic_read(&cm_closes);
32469 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32470 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32471 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32472 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32473 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32474 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32475 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32476 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32477 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32478 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32479 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32480 target_stat_values[++index] = cm_packets_sent;
32481 target_stat_values[++index] = cm_packets_bounced;
32482 target_stat_values[++index] = cm_packets_created;
32483 target_stat_values[++index] = cm_packets_received;
32484 target_stat_values[++index] = cm_packets_dropped;
32485 target_stat_values[++index] = cm_packets_retrans;
32486 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32487 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32488 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32489 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32490 target_stat_values[++index] = cm_backlog_drops;
32491 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32492 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32493 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32494 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32495 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32496 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32497 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32498 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32499 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32500 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32501 target_stat_values[++index] = nesadapter->free_4kpbl;
32502 target_stat_values[++index] = nesadapter->free_256pbl;
32503 target_stat_values[++index] = int_mod_timer_init;
32504 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32505 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32506 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32507 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32508 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32509 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32510 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32511 }
32512
32513 /**
32514 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32515 index 0927b5c..ed67986 100644
32516 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32517 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32518 @@ -46,9 +46,9 @@
32519
32520 #include <rdma/ib_umem.h>
32521
32522 -atomic_t mod_qp_timouts;
32523 -atomic_t qps_created;
32524 -atomic_t sw_qps_destroyed;
32525 +atomic_unchecked_t mod_qp_timouts;
32526 +atomic_unchecked_t qps_created;
32527 +atomic_unchecked_t sw_qps_destroyed;
32528
32529 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32530
32531 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32532 if (init_attr->create_flags)
32533 return ERR_PTR(-EINVAL);
32534
32535 - atomic_inc(&qps_created);
32536 + atomic_inc_unchecked(&qps_created);
32537 switch (init_attr->qp_type) {
32538 case IB_QPT_RC:
32539 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32540 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32541 struct iw_cm_event cm_event;
32542 int ret = 0;
32543
32544 - atomic_inc(&sw_qps_destroyed);
32545 + atomic_inc_unchecked(&sw_qps_destroyed);
32546 nesqp->destroyed = 1;
32547
32548 /* Blow away the connection if it exists. */
32549 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32550 index b881bdc..c2e360c 100644
32551 --- a/drivers/infiniband/hw/qib/qib.h
32552 +++ b/drivers/infiniband/hw/qib/qib.h
32553 @@ -51,6 +51,7 @@
32554 #include <linux/completion.h>
32555 #include <linux/kref.h>
32556 #include <linux/sched.h>
32557 +#include <linux/slab.h>
32558
32559 #include "qib_common.h"
32560 #include "qib_verbs.h"
32561 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32562 index 05e0f17..0275789 100644
32563 --- a/drivers/infiniband/hw/qib/qib_fs.c
32564 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32565 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32566 };
32567
32568 static ssize_t flash_read(struct file *file, char __user *buf,
32569 + size_t count, loff_t *ppos) __size_overflow(3);
32570 +static ssize_t flash_read(struct file *file, char __user *buf,
32571 size_t count, loff_t *ppos)
32572 {
32573 struct qib_devdata *dd;
32574 @@ -318,6 +320,8 @@ bail:
32575 }
32576
32577 static ssize_t flash_write(struct file *file, const char __user *buf,
32578 + size_t count, loff_t *ppos) __size_overflow(3);
32579 +static ssize_t flash_write(struct file *file, const char __user *buf,
32580 size_t count, loff_t *ppos)
32581 {
32582 struct qib_devdata *dd;
32583 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32584 index c351aa4..e6967c2 100644
32585 --- a/drivers/input/gameport/gameport.c
32586 +++ b/drivers/input/gameport/gameport.c
32587 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32588 */
32589 static void gameport_init_port(struct gameport *gameport)
32590 {
32591 - static atomic_t gameport_no = ATOMIC_INIT(0);
32592 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32593
32594 __module_get(THIS_MODULE);
32595
32596 mutex_init(&gameport->drv_mutex);
32597 device_initialize(&gameport->dev);
32598 dev_set_name(&gameport->dev, "gameport%lu",
32599 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32600 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32601 gameport->dev.bus = &gameport_bus;
32602 gameport->dev.release = gameport_release_port;
32603 if (gameport->parent)
32604 diff --git a/drivers/input/input.c b/drivers/input/input.c
32605 index 1f78c95..3cddc6c 100644
32606 --- a/drivers/input/input.c
32607 +++ b/drivers/input/input.c
32608 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32609 */
32610 int input_register_device(struct input_dev *dev)
32611 {
32612 - static atomic_t input_no = ATOMIC_INIT(0);
32613 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32614 struct input_handler *handler;
32615 const char *path;
32616 int error;
32617 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32618 dev->setkeycode = input_default_setkeycode;
32619
32620 dev_set_name(&dev->dev, "input%ld",
32621 - (unsigned long) atomic_inc_return(&input_no) - 1);
32622 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32623
32624 error = device_add(&dev->dev);
32625 if (error)
32626 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32627 index b8d8611..7a4a04b 100644
32628 --- a/drivers/input/joystick/sidewinder.c
32629 +++ b/drivers/input/joystick/sidewinder.c
32630 @@ -30,6 +30,7 @@
32631 #include <linux/kernel.h>
32632 #include <linux/module.h>
32633 #include <linux/slab.h>
32634 +#include <linux/sched.h>
32635 #include <linux/init.h>
32636 #include <linux/input.h>
32637 #include <linux/gameport.h>
32638 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32639 index fd7a0d5..a4af10c 100644
32640 --- a/drivers/input/joystick/xpad.c
32641 +++ b/drivers/input/joystick/xpad.c
32642 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32643
32644 static int xpad_led_probe(struct usb_xpad *xpad)
32645 {
32646 - static atomic_t led_seq = ATOMIC_INIT(0);
32647 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32648 long led_no;
32649 struct xpad_led *led;
32650 struct led_classdev *led_cdev;
32651 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32652 if (!led)
32653 return -ENOMEM;
32654
32655 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32656 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32657
32658 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32659 led->xpad = xpad;
32660 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32661 index 0110b5a..d3ad144 100644
32662 --- a/drivers/input/mousedev.c
32663 +++ b/drivers/input/mousedev.c
32664 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32665
32666 spin_unlock_irq(&client->packet_lock);
32667
32668 - if (copy_to_user(buffer, data, count))
32669 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32670 return -EFAULT;
32671
32672 return count;
32673 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32674 index ba70058..571d25d 100644
32675 --- a/drivers/input/serio/serio.c
32676 +++ b/drivers/input/serio/serio.c
32677 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32678 */
32679 static void serio_init_port(struct serio *serio)
32680 {
32681 - static atomic_t serio_no = ATOMIC_INIT(0);
32682 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32683
32684 __module_get(THIS_MODULE);
32685
32686 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32687 mutex_init(&serio->drv_mutex);
32688 device_initialize(&serio->dev);
32689 dev_set_name(&serio->dev, "serio%ld",
32690 - (long)atomic_inc_return(&serio_no) - 1);
32691 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32692 serio->dev.bus = &serio_bus;
32693 serio->dev.release = serio_release_port;
32694 serio->dev.groups = serio_device_attr_groups;
32695 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32696 index e44933d..9ba484a 100644
32697 --- a/drivers/isdn/capi/capi.c
32698 +++ b/drivers/isdn/capi/capi.c
32699 @@ -83,8 +83,8 @@ struct capiminor {
32700
32701 struct capi20_appl *ap;
32702 u32 ncci;
32703 - atomic_t datahandle;
32704 - atomic_t msgid;
32705 + atomic_unchecked_t datahandle;
32706 + atomic_unchecked_t msgid;
32707
32708 struct tty_port port;
32709 int ttyinstop;
32710 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32711 capimsg_setu16(s, 2, mp->ap->applid);
32712 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32713 capimsg_setu8 (s, 5, CAPI_RESP);
32714 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32715 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32716 capimsg_setu32(s, 8, mp->ncci);
32717 capimsg_setu16(s, 12, datahandle);
32718 }
32719 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32720 mp->outbytes -= len;
32721 spin_unlock_bh(&mp->outlock);
32722
32723 - datahandle = atomic_inc_return(&mp->datahandle);
32724 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32725 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32726 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32727 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32728 capimsg_setu16(skb->data, 2, mp->ap->applid);
32729 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32730 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32731 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32732 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32733 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32734 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32735 capimsg_setu16(skb->data, 16, len); /* Data length */
32736 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32737 index db621db..825ea1a 100644
32738 --- a/drivers/isdn/gigaset/common.c
32739 +++ b/drivers/isdn/gigaset/common.c
32740 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32741 cs->commands_pending = 0;
32742 cs->cur_at_seq = 0;
32743 cs->gotfwver = -1;
32744 - cs->open_count = 0;
32745 + local_set(&cs->open_count, 0);
32746 cs->dev = NULL;
32747 cs->tty = NULL;
32748 cs->tty_dev = NULL;
32749 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32750 index 212efaf..f187c6b 100644
32751 --- a/drivers/isdn/gigaset/gigaset.h
32752 +++ b/drivers/isdn/gigaset/gigaset.h
32753 @@ -35,6 +35,7 @@
32754 #include <linux/tty_driver.h>
32755 #include <linux/list.h>
32756 #include <linux/atomic.h>
32757 +#include <asm/local.h>
32758
32759 #define GIG_VERSION {0, 5, 0, 0}
32760 #define GIG_COMPAT {0, 4, 0, 0}
32761 @@ -433,7 +434,7 @@ struct cardstate {
32762 spinlock_t cmdlock;
32763 unsigned curlen, cmdbytes;
32764
32765 - unsigned open_count;
32766 + local_t open_count;
32767 struct tty_struct *tty;
32768 struct tasklet_struct if_wake_tasklet;
32769 unsigned control_state;
32770 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32771 index ee0a549..a7c9798 100644
32772 --- a/drivers/isdn/gigaset/interface.c
32773 +++ b/drivers/isdn/gigaset/interface.c
32774 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32775 }
32776 tty->driver_data = cs;
32777
32778 - ++cs->open_count;
32779 -
32780 - if (cs->open_count == 1) {
32781 + if (local_inc_return(&cs->open_count) == 1) {
32782 spin_lock_irqsave(&cs->lock, flags);
32783 cs->tty = tty;
32784 spin_unlock_irqrestore(&cs->lock, flags);
32785 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32786
32787 if (!cs->connected)
32788 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32789 - else if (!cs->open_count)
32790 + else if (!local_read(&cs->open_count))
32791 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32792 else {
32793 - if (!--cs->open_count) {
32794 + if (!local_dec_return(&cs->open_count)) {
32795 spin_lock_irqsave(&cs->lock, flags);
32796 cs->tty = NULL;
32797 spin_unlock_irqrestore(&cs->lock, flags);
32798 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32799 if (!cs->connected) {
32800 gig_dbg(DEBUG_IF, "not connected");
32801 retval = -ENODEV;
32802 - } else if (!cs->open_count)
32803 + } else if (!local_read(&cs->open_count))
32804 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32805 else {
32806 retval = 0;
32807 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32808 retval = -ENODEV;
32809 goto done;
32810 }
32811 - if (!cs->open_count) {
32812 + if (!local_read(&cs->open_count)) {
32813 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32814 retval = -ENODEV;
32815 goto done;
32816 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32817 if (!cs->connected) {
32818 gig_dbg(DEBUG_IF, "not connected");
32819 retval = -ENODEV;
32820 - } else if (!cs->open_count)
32821 + } else if (!local_read(&cs->open_count))
32822 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32823 else if (cs->mstate != MS_LOCKED) {
32824 dev_warn(cs->dev, "can't write to unlocked device\n");
32825 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32826
32827 if (!cs->connected)
32828 gig_dbg(DEBUG_IF, "not connected");
32829 - else if (!cs->open_count)
32830 + else if (!local_read(&cs->open_count))
32831 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32832 else if (cs->mstate != MS_LOCKED)
32833 dev_warn(cs->dev, "can't write to unlocked device\n");
32834 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32835
32836 if (!cs->connected)
32837 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32838 - else if (!cs->open_count)
32839 + else if (!local_read(&cs->open_count))
32840 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32841 else
32842 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32843 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32844
32845 if (!cs->connected)
32846 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32847 - else if (!cs->open_count)
32848 + else if (!local_read(&cs->open_count))
32849 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32850 else
32851 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32852 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32853 goto out;
32854 }
32855
32856 - if (!cs->open_count) {
32857 + if (!local_read(&cs->open_count)) {
32858 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32859 goto out;
32860 }
32861 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32862 index 2a57da59..e7a12ed 100644
32863 --- a/drivers/isdn/hardware/avm/b1.c
32864 +++ b/drivers/isdn/hardware/avm/b1.c
32865 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32866 }
32867 if (left) {
32868 if (t4file->user) {
32869 - if (copy_from_user(buf, dp, left))
32870 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32871 return -EFAULT;
32872 } else {
32873 memcpy(buf, dp, left);
32874 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32875 }
32876 if (left) {
32877 if (config->user) {
32878 - if (copy_from_user(buf, dp, left))
32879 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32880 return -EFAULT;
32881 } else {
32882 memcpy(buf, dp, left);
32883 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32884 index 85784a7..a19ca98 100644
32885 --- a/drivers/isdn/hardware/eicon/divasync.h
32886 +++ b/drivers/isdn/hardware/eicon/divasync.h
32887 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32888 } diva_didd_add_adapter_t;
32889 typedef struct _diva_didd_remove_adapter {
32890 IDI_CALL p_request;
32891 -} diva_didd_remove_adapter_t;
32892 +} __no_const diva_didd_remove_adapter_t;
32893 typedef struct _diva_didd_read_adapter_array {
32894 void * buffer;
32895 dword length;
32896 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32897 index a3bd163..8956575 100644
32898 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32899 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32900 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32901 typedef struct _diva_os_idi_adapter_interface {
32902 diva_init_card_proc_t cleanup_adapter_proc;
32903 diva_cmd_card_proc_t cmd_proc;
32904 -} diva_os_idi_adapter_interface_t;
32905 +} __no_const diva_os_idi_adapter_interface_t;
32906
32907 typedef struct _diva_os_xdi_adapter {
32908 struct list_head link;
32909 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32910 index 1f355bb..43f1fea 100644
32911 --- a/drivers/isdn/icn/icn.c
32912 +++ b/drivers/isdn/icn/icn.c
32913 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32914 if (count > len)
32915 count = len;
32916 if (user) {
32917 - if (copy_from_user(msg, buf, count))
32918 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32919 return -EFAULT;
32920 } else
32921 memcpy(msg, buf, count);
32922 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32923 index b5fdcb7..5b6c59f 100644
32924 --- a/drivers/lguest/core.c
32925 +++ b/drivers/lguest/core.c
32926 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32927 * it's worked so far. The end address needs +1 because __get_vm_area
32928 * allocates an extra guard page, so we need space for that.
32929 */
32930 +
32931 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32932 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32933 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32934 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32935 +#else
32936 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32937 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32938 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32939 +#endif
32940 +
32941 if (!switcher_vma) {
32942 err = -ENOMEM;
32943 printk("lguest: could not map switcher pages high\n");
32944 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32945 * Now the Switcher is mapped at the right address, we can't fail!
32946 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32947 */
32948 - memcpy(switcher_vma->addr, start_switcher_text,
32949 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32950 end_switcher_text - start_switcher_text);
32951
32952 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32953 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
32954 index ff4a0bc..f5fdd9c 100644
32955 --- a/drivers/lguest/lguest_user.c
32956 +++ b/drivers/lguest/lguest_user.c
32957 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
32958 * Once our Guest is initialized, the Launcher makes it run by reading
32959 * from /dev/lguest.
32960 */
32961 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
32962 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
32963 {
32964 struct lguest *lg = file->private_data;
32965 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32966 index 3980903..ce25c5e 100644
32967 --- a/drivers/lguest/x86/core.c
32968 +++ b/drivers/lguest/x86/core.c
32969 @@ -59,7 +59,7 @@ static struct {
32970 /* Offset from where switcher.S was compiled to where we've copied it */
32971 static unsigned long switcher_offset(void)
32972 {
32973 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32974 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32975 }
32976
32977 /* This cpu's struct lguest_pages. */
32978 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32979 * These copies are pretty cheap, so we do them unconditionally: */
32980 /* Save the current Host top-level page directory.
32981 */
32982 +
32983 +#ifdef CONFIG_PAX_PER_CPU_PGD
32984 + pages->state.host_cr3 = read_cr3();
32985 +#else
32986 pages->state.host_cr3 = __pa(current->mm->pgd);
32987 +#endif
32988 +
32989 /*
32990 * Set up the Guest's page tables to see this CPU's pages (and no
32991 * other CPU's pages).
32992 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32993 * compiled-in switcher code and the high-mapped copy we just made.
32994 */
32995 for (i = 0; i < IDT_ENTRIES; i++)
32996 - default_idt_entries[i] += switcher_offset();
32997 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32998
32999 /*
33000 * Set up the Switcher's per-cpu areas.
33001 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33002 * it will be undisturbed when we switch. To change %cs and jump we
33003 * need this structure to feed to Intel's "lcall" instruction.
33004 */
33005 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33006 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33007 lguest_entry.segment = LGUEST_CS;
33008
33009 /*
33010 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33011 index 40634b0..4f5855e 100644
33012 --- a/drivers/lguest/x86/switcher_32.S
33013 +++ b/drivers/lguest/x86/switcher_32.S
33014 @@ -87,6 +87,7 @@
33015 #include <asm/page.h>
33016 #include <asm/segment.h>
33017 #include <asm/lguest.h>
33018 +#include <asm/processor-flags.h>
33019
33020 // We mark the start of the code to copy
33021 // It's placed in .text tho it's never run here
33022 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33023 // Changes type when we load it: damn Intel!
33024 // For after we switch over our page tables
33025 // That entry will be read-only: we'd crash.
33026 +
33027 +#ifdef CONFIG_PAX_KERNEXEC
33028 + mov %cr0, %edx
33029 + xor $X86_CR0_WP, %edx
33030 + mov %edx, %cr0
33031 +#endif
33032 +
33033 movl $(GDT_ENTRY_TSS*8), %edx
33034 ltr %dx
33035
33036 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33037 // Let's clear it again for our return.
33038 // The GDT descriptor of the Host
33039 // Points to the table after two "size" bytes
33040 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33041 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33042 // Clear "used" from type field (byte 5, bit 2)
33043 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33044 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33045 +
33046 +#ifdef CONFIG_PAX_KERNEXEC
33047 + mov %cr0, %eax
33048 + xor $X86_CR0_WP, %eax
33049 + mov %eax, %cr0
33050 +#endif
33051
33052 // Once our page table's switched, the Guest is live!
33053 // The Host fades as we run this final step.
33054 @@ -295,13 +309,12 @@ deliver_to_host:
33055 // I consulted gcc, and it gave
33056 // These instructions, which I gladly credit:
33057 leal (%edx,%ebx,8), %eax
33058 - movzwl (%eax),%edx
33059 - movl 4(%eax), %eax
33060 - xorw %ax, %ax
33061 - orl %eax, %edx
33062 + movl 4(%eax), %edx
33063 + movw (%eax), %dx
33064 // Now the address of the handler's in %edx
33065 // We call it now: its "iret" drops us home.
33066 - jmp *%edx
33067 + ljmp $__KERNEL_CS, $1f
33068 +1: jmp *%edx
33069
33070 // Every interrupt can come to us here
33071 // But we must truly tell each apart.
33072 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33073 index 4daf9e5..b8d1d0f 100644
33074 --- a/drivers/macintosh/macio_asic.c
33075 +++ b/drivers/macintosh/macio_asic.c
33076 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33077 * MacIO is matched against any Apple ID, it's probe() function
33078 * will then decide wether it applies or not
33079 */
33080 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33081 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33082 .vendor = PCI_VENDOR_ID_APPLE,
33083 .device = PCI_ANY_ID,
33084 .subvendor = PCI_ANY_ID,
33085 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33086 index 1ce84ed..0fdd40a 100644
33087 --- a/drivers/md/dm-ioctl.c
33088 +++ b/drivers/md/dm-ioctl.c
33089 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33090 cmd == DM_LIST_VERSIONS_CMD)
33091 return 0;
33092
33093 - if ((cmd == DM_DEV_CREATE_CMD)) {
33094 + if (cmd == DM_DEV_CREATE_CMD) {
33095 if (!*param->name) {
33096 DMWARN("name not supplied when creating device");
33097 return -EINVAL;
33098 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33099 index 9bfd057..5373ff3 100644
33100 --- a/drivers/md/dm-raid1.c
33101 +++ b/drivers/md/dm-raid1.c
33102 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33103
33104 struct mirror {
33105 struct mirror_set *ms;
33106 - atomic_t error_count;
33107 + atomic_unchecked_t error_count;
33108 unsigned long error_type;
33109 struct dm_dev *dev;
33110 sector_t offset;
33111 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33112 struct mirror *m;
33113
33114 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33115 - if (!atomic_read(&m->error_count))
33116 + if (!atomic_read_unchecked(&m->error_count))
33117 return m;
33118
33119 return NULL;
33120 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33121 * simple way to tell if a device has encountered
33122 * errors.
33123 */
33124 - atomic_inc(&m->error_count);
33125 + atomic_inc_unchecked(&m->error_count);
33126
33127 if (test_and_set_bit(error_type, &m->error_type))
33128 return;
33129 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33130 struct mirror *m = get_default_mirror(ms);
33131
33132 do {
33133 - if (likely(!atomic_read(&m->error_count)))
33134 + if (likely(!atomic_read_unchecked(&m->error_count)))
33135 return m;
33136
33137 if (m-- == ms->mirror)
33138 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33139 {
33140 struct mirror *default_mirror = get_default_mirror(m->ms);
33141
33142 - return !atomic_read(&default_mirror->error_count);
33143 + return !atomic_read_unchecked(&default_mirror->error_count);
33144 }
33145
33146 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33147 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33148 */
33149 if (likely(region_in_sync(ms, region, 1)))
33150 m = choose_mirror(ms, bio->bi_sector);
33151 - else if (m && atomic_read(&m->error_count))
33152 + else if (m && atomic_read_unchecked(&m->error_count))
33153 m = NULL;
33154
33155 if (likely(m))
33156 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33157 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33158 uint32_t region_size,
33159 struct dm_target *ti,
33160 + struct dm_dirty_log *dl) __size_overflow(1);
33161 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33162 + uint32_t region_size,
33163 + struct dm_target *ti,
33164 struct dm_dirty_log *dl)
33165 {
33166 size_t len;
33167 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33168 }
33169
33170 ms->mirror[mirror].ms = ms;
33171 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33172 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33173 ms->mirror[mirror].error_type = 0;
33174 ms->mirror[mirror].offset = offset;
33175
33176 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33177 */
33178 static char device_status_char(struct mirror *m)
33179 {
33180 - if (!atomic_read(&(m->error_count)))
33181 + if (!atomic_read_unchecked(&(m->error_count)))
33182 return 'A';
33183
33184 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33185 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33186 index 3d80cf0..7d98e1a 100644
33187 --- a/drivers/md/dm-stripe.c
33188 +++ b/drivers/md/dm-stripe.c
33189 @@ -20,7 +20,7 @@ struct stripe {
33190 struct dm_dev *dev;
33191 sector_t physical_start;
33192
33193 - atomic_t error_count;
33194 + atomic_unchecked_t error_count;
33195 };
33196
33197 struct stripe_c {
33198 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33199 dm_table_event(sc->ti->table);
33200 }
33201
33202 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
33203 static inline struct stripe_c *alloc_context(unsigned int stripes)
33204 {
33205 size_t len;
33206 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33207 kfree(sc);
33208 return r;
33209 }
33210 - atomic_set(&(sc->stripe[i].error_count), 0);
33211 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33212 }
33213
33214 ti->private = sc;
33215 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33216 DMEMIT("%d ", sc->stripes);
33217 for (i = 0; i < sc->stripes; i++) {
33218 DMEMIT("%s ", sc->stripe[i].dev->name);
33219 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33220 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33221 'D' : 'A';
33222 }
33223 buffer[i] = '\0';
33224 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33225 */
33226 for (i = 0; i < sc->stripes; i++)
33227 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33228 - atomic_inc(&(sc->stripe[i].error_count));
33229 - if (atomic_read(&(sc->stripe[i].error_count)) <
33230 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33231 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33232 DM_IO_ERROR_THRESHOLD)
33233 schedule_work(&sc->trigger_event);
33234 }
33235 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33236 index 63cc542..8d45caf3 100644
33237 --- a/drivers/md/dm-table.c
33238 +++ b/drivers/md/dm-table.c
33239 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33240 if (!dev_size)
33241 return 0;
33242
33243 - if ((start >= dev_size) || (start + len > dev_size)) {
33244 + if ((start >= dev_size) || (len > dev_size - start)) {
33245 DMWARN("%s: %s too small for target: "
33246 "start=%llu, len=%llu, dev_size=%llu",
33247 dm_device_name(ti->table->md), bdevname(bdev, b),
33248 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33249 index 237571a..fb6d19b 100644
33250 --- a/drivers/md/dm-thin-metadata.c
33251 +++ b/drivers/md/dm-thin-metadata.c
33252 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33253
33254 pmd->info.tm = tm;
33255 pmd->info.levels = 2;
33256 - pmd->info.value_type.context = pmd->data_sm;
33257 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33258 pmd->info.value_type.size = sizeof(__le64);
33259 pmd->info.value_type.inc = data_block_inc;
33260 pmd->info.value_type.dec = data_block_dec;
33261 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33262
33263 pmd->bl_info.tm = tm;
33264 pmd->bl_info.levels = 1;
33265 - pmd->bl_info.value_type.context = pmd->data_sm;
33266 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33267 pmd->bl_info.value_type.size = sizeof(__le64);
33268 pmd->bl_info.value_type.inc = data_block_inc;
33269 pmd->bl_info.value_type.dec = data_block_dec;
33270 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33271 index b89c548..2af3ce4 100644
33272 --- a/drivers/md/dm.c
33273 +++ b/drivers/md/dm.c
33274 @@ -176,9 +176,9 @@ struct mapped_device {
33275 /*
33276 * Event handling.
33277 */
33278 - atomic_t event_nr;
33279 + atomic_unchecked_t event_nr;
33280 wait_queue_head_t eventq;
33281 - atomic_t uevent_seq;
33282 + atomic_unchecked_t uevent_seq;
33283 struct list_head uevent_list;
33284 spinlock_t uevent_lock; /* Protect access to uevent_list */
33285
33286 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33287 rwlock_init(&md->map_lock);
33288 atomic_set(&md->holders, 1);
33289 atomic_set(&md->open_count, 0);
33290 - atomic_set(&md->event_nr, 0);
33291 - atomic_set(&md->uevent_seq, 0);
33292 + atomic_set_unchecked(&md->event_nr, 0);
33293 + atomic_set_unchecked(&md->uevent_seq, 0);
33294 INIT_LIST_HEAD(&md->uevent_list);
33295 spin_lock_init(&md->uevent_lock);
33296
33297 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33298
33299 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33300
33301 - atomic_inc(&md->event_nr);
33302 + atomic_inc_unchecked(&md->event_nr);
33303 wake_up(&md->eventq);
33304 }
33305
33306 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33307
33308 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33309 {
33310 - return atomic_add_return(1, &md->uevent_seq);
33311 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33312 }
33313
33314 uint32_t dm_get_event_nr(struct mapped_device *md)
33315 {
33316 - return atomic_read(&md->event_nr);
33317 + return atomic_read_unchecked(&md->event_nr);
33318 }
33319
33320 int dm_wait_event(struct mapped_device *md, int event_nr)
33321 {
33322 return wait_event_interruptible(md->eventq,
33323 - (event_nr != atomic_read(&md->event_nr)));
33324 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33325 }
33326
33327 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33328 diff --git a/drivers/md/md.c b/drivers/md/md.c
33329 index 6acc846..80a6b96 100644
33330 --- a/drivers/md/md.c
33331 +++ b/drivers/md/md.c
33332 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33333 * start build, activate spare
33334 */
33335 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33336 -static atomic_t md_event_count;
33337 +static atomic_unchecked_t md_event_count;
33338 void md_new_event(struct mddev *mddev)
33339 {
33340 - atomic_inc(&md_event_count);
33341 + atomic_inc_unchecked(&md_event_count);
33342 wake_up(&md_event_waiters);
33343 }
33344 EXPORT_SYMBOL_GPL(md_new_event);
33345 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33346 */
33347 static void md_new_event_inintr(struct mddev *mddev)
33348 {
33349 - atomic_inc(&md_event_count);
33350 + atomic_inc_unchecked(&md_event_count);
33351 wake_up(&md_event_waiters);
33352 }
33353
33354 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33355
33356 rdev->preferred_minor = 0xffff;
33357 rdev->data_offset = le64_to_cpu(sb->data_offset);
33358 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33359 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33360
33361 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33362 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33363 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33364 else
33365 sb->resync_offset = cpu_to_le64(0);
33366
33367 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33368 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33369
33370 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33371 sb->size = cpu_to_le64(mddev->dev_sectors);
33372 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33373 static ssize_t
33374 errors_show(struct md_rdev *rdev, char *page)
33375 {
33376 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33377 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33378 }
33379
33380 static ssize_t
33381 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33382 char *e;
33383 unsigned long n = simple_strtoul(buf, &e, 10);
33384 if (*buf && (*e == 0 || *e == '\n')) {
33385 - atomic_set(&rdev->corrected_errors, n);
33386 + atomic_set_unchecked(&rdev->corrected_errors, n);
33387 return len;
33388 }
33389 return -EINVAL;
33390 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
33391 rdev->sb_loaded = 0;
33392 rdev->bb_page = NULL;
33393 atomic_set(&rdev->nr_pending, 0);
33394 - atomic_set(&rdev->read_errors, 0);
33395 - atomic_set(&rdev->corrected_errors, 0);
33396 + atomic_set_unchecked(&rdev->read_errors, 0);
33397 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33398
33399 INIT_LIST_HEAD(&rdev->same_set);
33400 init_waitqueue_head(&rdev->blocked_wait);
33401 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33402
33403 spin_unlock(&pers_lock);
33404 seq_printf(seq, "\n");
33405 - seq->poll_event = atomic_read(&md_event_count);
33406 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33407 return 0;
33408 }
33409 if (v == (void*)2) {
33410 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33411 chunk_kb ? "KB" : "B");
33412 if (bitmap->file) {
33413 seq_printf(seq, ", file: ");
33414 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33415 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33416 }
33417
33418 seq_printf(seq, "\n");
33419 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33420 return error;
33421
33422 seq = file->private_data;
33423 - seq->poll_event = atomic_read(&md_event_count);
33424 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33425 return error;
33426 }
33427
33428 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33429 /* always allow read */
33430 mask = POLLIN | POLLRDNORM;
33431
33432 - if (seq->poll_event != atomic_read(&md_event_count))
33433 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33434 mask |= POLLERR | POLLPRI;
33435 return mask;
33436 }
33437 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33438 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33439 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33440 (int)part_stat_read(&disk->part0, sectors[1]) -
33441 - atomic_read(&disk->sync_io);
33442 + atomic_read_unchecked(&disk->sync_io);
33443 /* sync IO will cause sync_io to increase before the disk_stats
33444 * as sync_io is counted when a request starts, and
33445 * disk_stats is counted when it completes.
33446 diff --git a/drivers/md/md.h b/drivers/md/md.h
33447 index 44c63df..b795d1a 100644
33448 --- a/drivers/md/md.h
33449 +++ b/drivers/md/md.h
33450 @@ -93,13 +93,13 @@ struct md_rdev {
33451 * only maintained for arrays that
33452 * support hot removal
33453 */
33454 - atomic_t read_errors; /* number of consecutive read errors that
33455 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33456 * we have tried to ignore.
33457 */
33458 struct timespec last_read_error; /* monotonic time since our
33459 * last read error
33460 */
33461 - atomic_t corrected_errors; /* number of corrected read errors,
33462 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33463 * for reporting to userspace and storing
33464 * in superblock.
33465 */
33466 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33467
33468 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33469 {
33470 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33471 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33472 }
33473
33474 struct md_personality
33475 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33476 index 50ed53b..4f29d7d 100644
33477 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33478 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33479 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33480 /*----------------------------------------------------------------*/
33481
33482 struct sm_checker {
33483 - struct dm_space_map sm;
33484 + dm_space_map_no_const sm;
33485
33486 struct count_array old_counts;
33487 struct count_array counts;
33488 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33489 index fc469ba..2d91555 100644
33490 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33491 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33492 @@ -23,7 +23,7 @@
33493 * Space map interface.
33494 */
33495 struct sm_disk {
33496 - struct dm_space_map sm;
33497 + dm_space_map_no_const sm;
33498
33499 struct ll_disk ll;
33500 struct ll_disk old_ll;
33501 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33502 index e89ae5e..062e4c2 100644
33503 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33504 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33505 @@ -43,7 +43,7 @@ struct block_op {
33506 };
33507
33508 struct sm_metadata {
33509 - struct dm_space_map sm;
33510 + dm_space_map_no_const sm;
33511
33512 struct ll_disk ll;
33513 struct ll_disk old_ll;
33514 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33515 index 1cbfc6b..56e1dbb 100644
33516 --- a/drivers/md/persistent-data/dm-space-map.h
33517 +++ b/drivers/md/persistent-data/dm-space-map.h
33518 @@ -60,6 +60,7 @@ struct dm_space_map {
33519 int (*root_size)(struct dm_space_map *sm, size_t *result);
33520 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33521 };
33522 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33523
33524 /*----------------------------------------------------------------*/
33525
33526 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33527 index 118e0f6..210c4d7 100644
33528 --- a/drivers/md/raid1.c
33529 +++ b/drivers/md/raid1.c
33530 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33531 if (r1_sync_page_io(rdev, sect, s,
33532 bio->bi_io_vec[idx].bv_page,
33533 READ) != 0)
33534 - atomic_add(s, &rdev->corrected_errors);
33535 + atomic_add_unchecked(s, &rdev->corrected_errors);
33536 }
33537 sectors -= s;
33538 sect += s;
33539 @@ -1858,7 +1858,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33540 test_bit(In_sync, &rdev->flags)) {
33541 if (r1_sync_page_io(rdev, sect, s,
33542 conf->tmppage, READ)) {
33543 - atomic_add(s, &rdev->corrected_errors);
33544 + atomic_add_unchecked(s, &rdev->corrected_errors);
33545 printk(KERN_INFO
33546 "md/raid1:%s: read error corrected "
33547 "(%d sectors at %llu on %s)\n",
33548 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33549 index be7101d..f23ba30 100644
33550 --- a/drivers/md/raid10.c
33551 +++ b/drivers/md/raid10.c
33552 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33553 /* The write handler will notice the lack of
33554 * R10BIO_Uptodate and record any errors etc
33555 */
33556 - atomic_add(r10_bio->sectors,
33557 + atomic_add_unchecked(r10_bio->sectors,
33558 &conf->mirrors[d].rdev->corrected_errors);
33559
33560 /* for reconstruct, we always reschedule after a read.
33561 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33562 {
33563 struct timespec cur_time_mon;
33564 unsigned long hours_since_last;
33565 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33566 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33567
33568 ktime_get_ts(&cur_time_mon);
33569
33570 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33571 * overflowing the shift of read_errors by hours_since_last.
33572 */
33573 if (hours_since_last >= 8 * sizeof(read_errors))
33574 - atomic_set(&rdev->read_errors, 0);
33575 + atomic_set_unchecked(&rdev->read_errors, 0);
33576 else
33577 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33578 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33579 }
33580
33581 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33582 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33583 return;
33584
33585 check_decay_read_errors(mddev, rdev);
33586 - atomic_inc(&rdev->read_errors);
33587 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33588 + atomic_inc_unchecked(&rdev->read_errors);
33589 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33590 char b[BDEVNAME_SIZE];
33591 bdevname(rdev->bdev, b);
33592
33593 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33594 "md/raid10:%s: %s: Raid device exceeded "
33595 "read_error threshold [cur %d:max %d]\n",
33596 mdname(mddev), b,
33597 - atomic_read(&rdev->read_errors), max_read_errors);
33598 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33599 printk(KERN_NOTICE
33600 "md/raid10:%s: %s: Failing raid device\n",
33601 mdname(mddev), b);
33602 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33603 (unsigned long long)(
33604 sect + rdev->data_offset),
33605 bdevname(rdev->bdev, b));
33606 - atomic_add(s, &rdev->corrected_errors);
33607 + atomic_add_unchecked(s, &rdev->corrected_errors);
33608 }
33609
33610 rdev_dec_pending(rdev, mddev);
33611 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33612 index 360f2b9..08b5382 100644
33613 --- a/drivers/md/raid5.c
33614 +++ b/drivers/md/raid5.c
33615 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33616 (unsigned long long)(sh->sector
33617 + rdev->data_offset),
33618 bdevname(rdev->bdev, b));
33619 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33620 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33621 clear_bit(R5_ReadError, &sh->dev[i].flags);
33622 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33623 }
33624 - if (atomic_read(&rdev->read_errors))
33625 - atomic_set(&rdev->read_errors, 0);
33626 + if (atomic_read_unchecked(&rdev->read_errors))
33627 + atomic_set_unchecked(&rdev->read_errors, 0);
33628 } else {
33629 const char *bdn = bdevname(rdev->bdev, b);
33630 int retry = 0;
33631
33632 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33633 - atomic_inc(&rdev->read_errors);
33634 + atomic_inc_unchecked(&rdev->read_errors);
33635 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33636 printk_ratelimited(
33637 KERN_WARNING
33638 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33639 (unsigned long long)(sh->sector
33640 + rdev->data_offset),
33641 bdn);
33642 - else if (atomic_read(&rdev->read_errors)
33643 + else if (atomic_read_unchecked(&rdev->read_errors)
33644 > conf->max_nr_stripes)
33645 printk(KERN_WARNING
33646 "md/raid:%s: Too many read errors, failing device %s.\n",
33647 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33648 index ce4f858..7bcfb46 100644
33649 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33650 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33651 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33652 .subvendor = _subvend, .subdevice = _subdev, \
33653 .driver_data = (unsigned long)&_driverdata }
33654
33655 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33656 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33657 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33658 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33659 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33660 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33661 index a7d876f..8c21b61 100644
33662 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33663 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33664 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33665 union {
33666 dmx_ts_cb ts;
33667 dmx_section_cb sec;
33668 - } cb;
33669 + } __no_const cb;
33670
33671 struct dvb_demux *demux;
33672 void *priv;
33673 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33674 index 00a6732..70a682e 100644
33675 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33676 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33677 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33678 const struct dvb_device *template, void *priv, int type)
33679 {
33680 struct dvb_device *dvbdev;
33681 - struct file_operations *dvbdevfops;
33682 + file_operations_no_const *dvbdevfops;
33683 struct device *clsdev;
33684 int minor;
33685 int id;
33686 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33687 index 3940bb0..fb3952a 100644
33688 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33689 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33690 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33691
33692 struct dib0700_adapter_state {
33693 int (*set_param_save) (struct dvb_frontend *);
33694 -};
33695 +} __no_const;
33696
33697 static int dib7070_set_param_override(struct dvb_frontend *fe)
33698 {
33699 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33700 index 451c5a7..649f711 100644
33701 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33702 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33703 @@ -95,7 +95,7 @@ struct su3000_state {
33704
33705 struct s6x0_state {
33706 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33707 -};
33708 +} __no_const;
33709
33710 /* debug */
33711 static int dvb_usb_dw2102_debug;
33712 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33713 index 404f63a..4796533 100644
33714 --- a/drivers/media/dvb/frontends/dib3000.h
33715 +++ b/drivers/media/dvb/frontends/dib3000.h
33716 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33717 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33718 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33719 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33720 -};
33721 +} __no_const;
33722
33723 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33724 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33725 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33726 index 8418c02..8555013 100644
33727 --- a/drivers/media/dvb/ngene/ngene-cards.c
33728 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33729 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33730
33731 /****************************************************************************/
33732
33733 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33734 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33735 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33736 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33737 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33738 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33739 index 16a089f..ab1667d 100644
33740 --- a/drivers/media/radio/radio-cadet.c
33741 +++ b/drivers/media/radio/radio-cadet.c
33742 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33743 unsigned char readbuf[RDS_BUFFER];
33744 int i = 0;
33745
33746 + if (count > RDS_BUFFER)
33747 + return -EFAULT;
33748 mutex_lock(&dev->lock);
33749 if (dev->rdsstat == 0) {
33750 dev->rdsstat = 1;
33751 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33752 index 9cde353..8c6a1c3 100644
33753 --- a/drivers/media/video/au0828/au0828.h
33754 +++ b/drivers/media/video/au0828/au0828.h
33755 @@ -191,7 +191,7 @@ struct au0828_dev {
33756
33757 /* I2C */
33758 struct i2c_adapter i2c_adap;
33759 - struct i2c_algorithm i2c_algo;
33760 + i2c_algorithm_no_const i2c_algo;
33761 struct i2c_client i2c_client;
33762 u32 i2c_rc;
33763
33764 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
33765 index ee91e295..04ad048 100644
33766 --- a/drivers/media/video/cpia2/cpia2_core.c
33767 +++ b/drivers/media/video/cpia2/cpia2_core.c
33768 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
33769 return ret;
33770 }
33771
33772 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33773 static void *rvmalloc(unsigned long size)
33774 {
33775 void *mem;
33776 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
33777 index 82d195b..181103c 100644
33778 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
33779 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
33780 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
33781
33782
33783 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33784 + size_t size) __size_overflow(2);
33785 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33786 size_t size)
33787 {
33788 struct snd_pcm_runtime *runtime = subs->runtime;
33789 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
33790 index a2c2b7d..8f1bec7 100644
33791 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
33792 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
33793 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
33794 }
33795
33796 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33797 + size_t size) __size_overflow(2);
33798 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33799 size_t size)
33800 {
33801 struct snd_pcm_runtime *runtime = subs->runtime;
33802 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33803 index 04bf662..e0ac026 100644
33804 --- a/drivers/media/video/cx88/cx88-alsa.c
33805 +++ b/drivers/media/video/cx88/cx88-alsa.c
33806 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33807 * Only boards with eeprom and byte 1 at eeprom=1 have it
33808 */
33809
33810 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33811 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33812 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33813 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33814 {0, }
33815 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
33816 index e2a7b77..753d0ee 100644
33817 --- a/drivers/media/video/em28xx/em28xx-audio.c
33818 +++ b/drivers/media/video/em28xx/em28xx-audio.c
33819 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
33820 }
33821
33822 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33823 + size_t size) __size_overflow(2);
33824 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33825 size_t size)
33826 {
33827 struct snd_pcm_runtime *runtime = subs->runtime;
33828 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
33829 index b09a3c8..6dcba0a 100644
33830 --- a/drivers/media/video/meye.c
33831 +++ b/drivers/media/video/meye.c
33832 @@ -72,6 +72,7 @@ static struct meye meye;
33833 /****************************************************************************/
33834 /* Memory allocation routines (stolen from bttv-driver.c) */
33835 /****************************************************************************/
33836 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33837 static void *rvmalloc(unsigned long size)
33838 {
33839 void *mem;
33840 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33841 index 1fb7d5b..3901e77 100644
33842 --- a/drivers/media/video/omap/omap_vout.c
33843 +++ b/drivers/media/video/omap/omap_vout.c
33844 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33845 OMAP_VIDEO2,
33846 };
33847
33848 -static struct videobuf_queue_ops video_vbq_ops;
33849 /* Variables configurable through module params*/
33850 static u32 video1_numbuffers = 3;
33851 static u32 video2_numbuffers = 3;
33852 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33853 {
33854 struct videobuf_queue *q;
33855 struct omap_vout_device *vout = NULL;
33856 + static struct videobuf_queue_ops video_vbq_ops = {
33857 + .buf_setup = omap_vout_buffer_setup,
33858 + .buf_prepare = omap_vout_buffer_prepare,
33859 + .buf_release = omap_vout_buffer_release,
33860 + .buf_queue = omap_vout_buffer_queue,
33861 + };
33862
33863 vout = video_drvdata(file);
33864 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33865 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33866 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33867
33868 q = &vout->vbq;
33869 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33870 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33871 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33872 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33873 spin_lock_init(&vout->vbq_lock);
33874
33875 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33876 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33877 index 305e6aa..0143317 100644
33878 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33879 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33880 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33881
33882 /* I2C stuff */
33883 struct i2c_adapter i2c_adap;
33884 - struct i2c_algorithm i2c_algo;
33885 + i2c_algorithm_no_const i2c_algo;
33886 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33887 int i2c_cx25840_hack_state;
33888 int i2c_linked;
33889 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
33890 index 2fd38a0..ddec3c4 100644
33891 --- a/drivers/media/video/saa7164/saa7164-encoder.c
33892 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
33893 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
33894 }
33895
33896 static ssize_t fops_read(struct file *file, char __user *buffer,
33897 + size_t count, loff_t *pos) __size_overflow(3);
33898 +static ssize_t fops_read(struct file *file, char __user *buffer,
33899 size_t count, loff_t *pos)
33900 {
33901 struct saa7164_encoder_fh *fh = file->private_data;
33902 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
33903 index e2e0341..b80056c 100644
33904 --- a/drivers/media/video/saa7164/saa7164-vbi.c
33905 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
33906 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
33907 }
33908
33909 static ssize_t fops_read(struct file *file, char __user *buffer,
33910 + size_t count, loff_t *pos) __size_overflow(3);
33911 +static ssize_t fops_read(struct file *file, char __user *buffer,
33912 size_t count, loff_t *pos)
33913 {
33914 struct saa7164_vbi_fh *fh = file->private_data;
33915 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33916 index 4ed1c7c2..8f15e13 100644
33917 --- a/drivers/media/video/timblogiw.c
33918 +++ b/drivers/media/video/timblogiw.c
33919 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33920
33921 /* Platform device functions */
33922
33923 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33924 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33925 .vidioc_querycap = timblogiw_querycap,
33926 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33927 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33928 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33929 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33930 };
33931
33932 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33933 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33934 .owner = THIS_MODULE,
33935 .open = timblogiw_open,
33936 .release = timblogiw_close,
33937 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
33938 index c969111..a7910f4 100644
33939 --- a/drivers/media/video/videobuf-dma-contig.c
33940 +++ b/drivers/media/video/videobuf-dma-contig.c
33941 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
33942 return ret;
33943 }
33944
33945 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33946 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33947 {
33948 struct videobuf_dma_contig_memory *mem;
33949 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
33950 index f300dea..5fc9c4a 100644
33951 --- a/drivers/media/video/videobuf-dma-sg.c
33952 +++ b/drivers/media/video/videobuf-dma-sg.c
33953 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33954 struct videobuf_dma_sg_memory
33955 */
33956
33957 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33958 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33959 {
33960 struct videobuf_dma_sg_memory *mem;
33961 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
33962 index df14258..12cc7a3 100644
33963 --- a/drivers/media/video/videobuf-vmalloc.c
33964 +++ b/drivers/media/video/videobuf-vmalloc.c
33965 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33966 struct videobuf_dma_sg_memory
33967 */
33968
33969 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33970 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33971 {
33972 struct videobuf_vmalloc_memory *mem;
33973 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33974 index a7dc467..a55c423 100644
33975 --- a/drivers/message/fusion/mptbase.c
33976 +++ b/drivers/message/fusion/mptbase.c
33977 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33978 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33979 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33980
33981 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33982 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33983 +#else
33984 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33985 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33986 +#endif
33987 +
33988 /*
33989 * Rounding UP to nearest 4-kB boundary here...
33990 */
33991 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33992 index 551262e..7551198 100644
33993 --- a/drivers/message/fusion/mptsas.c
33994 +++ b/drivers/message/fusion/mptsas.c
33995 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33996 return 0;
33997 }
33998
33999 +static inline void
34000 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34001 +{
34002 + if (phy_info->port_details) {
34003 + phy_info->port_details->rphy = rphy;
34004 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34005 + ioc->name, rphy));
34006 + }
34007 +
34008 + if (rphy) {
34009 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34010 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34011 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34012 + ioc->name, rphy, rphy->dev.release));
34013 + }
34014 +}
34015 +
34016 /* no mutex */
34017 static void
34018 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34019 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34020 return NULL;
34021 }
34022
34023 -static inline void
34024 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34025 -{
34026 - if (phy_info->port_details) {
34027 - phy_info->port_details->rphy = rphy;
34028 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34029 - ioc->name, rphy));
34030 - }
34031 -
34032 - if (rphy) {
34033 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34034 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34035 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34036 - ioc->name, rphy, rphy->dev.release));
34037 - }
34038 -}
34039 -
34040 static inline struct sas_port *
34041 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34042 {
34043 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34044 index 0c3ced7..1fe34ec 100644
34045 --- a/drivers/message/fusion/mptscsih.c
34046 +++ b/drivers/message/fusion/mptscsih.c
34047 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34048
34049 h = shost_priv(SChost);
34050
34051 - if (h) {
34052 - if (h->info_kbuf == NULL)
34053 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34054 - return h->info_kbuf;
34055 - h->info_kbuf[0] = '\0';
34056 + if (!h)
34057 + return NULL;
34058
34059 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34060 - h->info_kbuf[size-1] = '\0';
34061 - }
34062 + if (h->info_kbuf == NULL)
34063 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34064 + return h->info_kbuf;
34065 + h->info_kbuf[0] = '\0';
34066 +
34067 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34068 + h->info_kbuf[size-1] = '\0';
34069
34070 return h->info_kbuf;
34071 }
34072 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34073 index 6d115c7..58ff7fd 100644
34074 --- a/drivers/message/i2o/i2o_proc.c
34075 +++ b/drivers/message/i2o/i2o_proc.c
34076 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34077 "Array Controller Device"
34078 };
34079
34080 -static char *chtostr(u8 * chars, int n)
34081 -{
34082 - char tmp[256];
34083 - tmp[0] = 0;
34084 - return strncat(tmp, (char *)chars, n);
34085 -}
34086 -
34087 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34088 char *group)
34089 {
34090 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34091
34092 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34093 seq_printf(seq, "%-#8x", ddm_table.module_id);
34094 - seq_printf(seq, "%-29s",
34095 - chtostr(ddm_table.module_name_version, 28));
34096 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34097 seq_printf(seq, "%9d ", ddm_table.data_size);
34098 seq_printf(seq, "%8d", ddm_table.code_size);
34099
34100 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34101
34102 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34103 seq_printf(seq, "%-#8x", dst->module_id);
34104 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34105 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34106 + seq_printf(seq, "%-.28s", dst->module_name_version);
34107 + seq_printf(seq, "%-.8s", dst->date);
34108 seq_printf(seq, "%8d ", dst->module_size);
34109 seq_printf(seq, "%8d ", dst->mpb_size);
34110 seq_printf(seq, "0x%04x", dst->module_flags);
34111 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34112 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34113 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34114 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34115 - seq_printf(seq, "Vendor info : %s\n",
34116 - chtostr((u8 *) (work32 + 2), 16));
34117 - seq_printf(seq, "Product info : %s\n",
34118 - chtostr((u8 *) (work32 + 6), 16));
34119 - seq_printf(seq, "Description : %s\n",
34120 - chtostr((u8 *) (work32 + 10), 16));
34121 - seq_printf(seq, "Product rev. : %s\n",
34122 - chtostr((u8 *) (work32 + 14), 8));
34123 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34124 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34125 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34126 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34127
34128 seq_printf(seq, "Serial number : ");
34129 print_serial_number(seq, (u8 *) (work32 + 16),
34130 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34131 }
34132
34133 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34134 - seq_printf(seq, "Module name : %s\n",
34135 - chtostr(result.module_name, 24));
34136 - seq_printf(seq, "Module revision : %s\n",
34137 - chtostr(result.module_rev, 8));
34138 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34139 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34140
34141 seq_printf(seq, "Serial number : ");
34142 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34143 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34144 return 0;
34145 }
34146
34147 - seq_printf(seq, "Device name : %s\n",
34148 - chtostr(result.device_name, 64));
34149 - seq_printf(seq, "Service name : %s\n",
34150 - chtostr(result.service_name, 64));
34151 - seq_printf(seq, "Physical name : %s\n",
34152 - chtostr(result.physical_location, 64));
34153 - seq_printf(seq, "Instance number : %s\n",
34154 - chtostr(result.instance_number, 4));
34155 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34156 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34157 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34158 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34159
34160 return 0;
34161 }
34162 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34163 index a8c08f3..155fe3d 100644
34164 --- a/drivers/message/i2o/iop.c
34165 +++ b/drivers/message/i2o/iop.c
34166 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34167
34168 spin_lock_irqsave(&c->context_list_lock, flags);
34169
34170 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34171 - atomic_inc(&c->context_list_counter);
34172 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34173 + atomic_inc_unchecked(&c->context_list_counter);
34174
34175 - entry->context = atomic_read(&c->context_list_counter);
34176 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34177
34178 list_add(&entry->list, &c->context_list);
34179
34180 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34181
34182 #if BITS_PER_LONG == 64
34183 spin_lock_init(&c->context_list_lock);
34184 - atomic_set(&c->context_list_counter, 0);
34185 + atomic_set_unchecked(&c->context_list_counter, 0);
34186 INIT_LIST_HEAD(&c->context_list);
34187 #endif
34188
34189 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34190 index 7ce65f4..e66e9bc 100644
34191 --- a/drivers/mfd/abx500-core.c
34192 +++ b/drivers/mfd/abx500-core.c
34193 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34194
34195 struct abx500_device_entry {
34196 struct list_head list;
34197 - struct abx500_ops ops;
34198 + abx500_ops_no_const ops;
34199 struct device *dev;
34200 };
34201
34202 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34203 index a9223ed..4127b13 100644
34204 --- a/drivers/mfd/janz-cmodio.c
34205 +++ b/drivers/mfd/janz-cmodio.c
34206 @@ -13,6 +13,7 @@
34207
34208 #include <linux/kernel.h>
34209 #include <linux/module.h>
34210 +#include <linux/slab.h>
34211 #include <linux/init.h>
34212 #include <linux/pci.h>
34213 #include <linux/interrupt.h>
34214 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34215 index a981e2a..5ca0c8b 100644
34216 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34217 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34218 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34219 * the lid is closed. This leads to interrupts as soon as a little move
34220 * is done.
34221 */
34222 - atomic_inc(&lis3->count);
34223 + atomic_inc_unchecked(&lis3->count);
34224
34225 wake_up_interruptible(&lis3->misc_wait);
34226 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34227 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34228 if (lis3->pm_dev)
34229 pm_runtime_get_sync(lis3->pm_dev);
34230
34231 - atomic_set(&lis3->count, 0);
34232 + atomic_set_unchecked(&lis3->count, 0);
34233 return 0;
34234 }
34235
34236 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34237 add_wait_queue(&lis3->misc_wait, &wait);
34238 while (true) {
34239 set_current_state(TASK_INTERRUPTIBLE);
34240 - data = atomic_xchg(&lis3->count, 0);
34241 + data = atomic_xchg_unchecked(&lis3->count, 0);
34242 if (data)
34243 break;
34244
34245 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34246 struct lis3lv02d, miscdev);
34247
34248 poll_wait(file, &lis3->misc_wait, wait);
34249 - if (atomic_read(&lis3->count))
34250 + if (atomic_read_unchecked(&lis3->count))
34251 return POLLIN | POLLRDNORM;
34252 return 0;
34253 }
34254 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34255 index 2b1482a..5d33616 100644
34256 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34257 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34258 @@ -266,7 +266,7 @@ struct lis3lv02d {
34259 struct input_polled_dev *idev; /* input device */
34260 struct platform_device *pdev; /* platform device */
34261 struct regulator_bulk_data regulators[2];
34262 - atomic_t count; /* interrupt count after last read */
34263 + atomic_unchecked_t count; /* interrupt count after last read */
34264 union axis_conversion ac; /* hw -> logical axis */
34265 int mapped_btns[3];
34266
34267 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34268 index 2f30bad..c4c13d0 100644
34269 --- a/drivers/misc/sgi-gru/gruhandles.c
34270 +++ b/drivers/misc/sgi-gru/gruhandles.c
34271 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34272 unsigned long nsec;
34273
34274 nsec = CLKS2NSEC(clks);
34275 - atomic_long_inc(&mcs_op_statistics[op].count);
34276 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34277 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34278 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34279 if (mcs_op_statistics[op].max < nsec)
34280 mcs_op_statistics[op].max = nsec;
34281 }
34282 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34283 index 950dbe9..eeef0f8 100644
34284 --- a/drivers/misc/sgi-gru/gruprocfs.c
34285 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34286 @@ -32,9 +32,9 @@
34287
34288 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34289
34290 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34291 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34292 {
34293 - unsigned long val = atomic_long_read(v);
34294 + unsigned long val = atomic_long_read_unchecked(v);
34295
34296 seq_printf(s, "%16lu %s\n", val, id);
34297 }
34298 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34299
34300 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34301 for (op = 0; op < mcsop_last; op++) {
34302 - count = atomic_long_read(&mcs_op_statistics[op].count);
34303 - total = atomic_long_read(&mcs_op_statistics[op].total);
34304 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34305 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34306 max = mcs_op_statistics[op].max;
34307 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34308 count ? total / count : 0, max);
34309 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34310 index 5c3ce24..4915ccb 100644
34311 --- a/drivers/misc/sgi-gru/grutables.h
34312 +++ b/drivers/misc/sgi-gru/grutables.h
34313 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34314 * GRU statistics.
34315 */
34316 struct gru_stats_s {
34317 - atomic_long_t vdata_alloc;
34318 - atomic_long_t vdata_free;
34319 - atomic_long_t gts_alloc;
34320 - atomic_long_t gts_free;
34321 - atomic_long_t gms_alloc;
34322 - atomic_long_t gms_free;
34323 - atomic_long_t gts_double_allocate;
34324 - atomic_long_t assign_context;
34325 - atomic_long_t assign_context_failed;
34326 - atomic_long_t free_context;
34327 - atomic_long_t load_user_context;
34328 - atomic_long_t load_kernel_context;
34329 - atomic_long_t lock_kernel_context;
34330 - atomic_long_t unlock_kernel_context;
34331 - atomic_long_t steal_user_context;
34332 - atomic_long_t steal_kernel_context;
34333 - atomic_long_t steal_context_failed;
34334 - atomic_long_t nopfn;
34335 - atomic_long_t asid_new;
34336 - atomic_long_t asid_next;
34337 - atomic_long_t asid_wrap;
34338 - atomic_long_t asid_reuse;
34339 - atomic_long_t intr;
34340 - atomic_long_t intr_cbr;
34341 - atomic_long_t intr_tfh;
34342 - atomic_long_t intr_spurious;
34343 - atomic_long_t intr_mm_lock_failed;
34344 - atomic_long_t call_os;
34345 - atomic_long_t call_os_wait_queue;
34346 - atomic_long_t user_flush_tlb;
34347 - atomic_long_t user_unload_context;
34348 - atomic_long_t user_exception;
34349 - atomic_long_t set_context_option;
34350 - atomic_long_t check_context_retarget_intr;
34351 - atomic_long_t check_context_unload;
34352 - atomic_long_t tlb_dropin;
34353 - atomic_long_t tlb_preload_page;
34354 - atomic_long_t tlb_dropin_fail_no_asid;
34355 - atomic_long_t tlb_dropin_fail_upm;
34356 - atomic_long_t tlb_dropin_fail_invalid;
34357 - atomic_long_t tlb_dropin_fail_range_active;
34358 - atomic_long_t tlb_dropin_fail_idle;
34359 - atomic_long_t tlb_dropin_fail_fmm;
34360 - atomic_long_t tlb_dropin_fail_no_exception;
34361 - atomic_long_t tfh_stale_on_fault;
34362 - atomic_long_t mmu_invalidate_range;
34363 - atomic_long_t mmu_invalidate_page;
34364 - atomic_long_t flush_tlb;
34365 - atomic_long_t flush_tlb_gru;
34366 - atomic_long_t flush_tlb_gru_tgh;
34367 - atomic_long_t flush_tlb_gru_zero_asid;
34368 + atomic_long_unchecked_t vdata_alloc;
34369 + atomic_long_unchecked_t vdata_free;
34370 + atomic_long_unchecked_t gts_alloc;
34371 + atomic_long_unchecked_t gts_free;
34372 + atomic_long_unchecked_t gms_alloc;
34373 + atomic_long_unchecked_t gms_free;
34374 + atomic_long_unchecked_t gts_double_allocate;
34375 + atomic_long_unchecked_t assign_context;
34376 + atomic_long_unchecked_t assign_context_failed;
34377 + atomic_long_unchecked_t free_context;
34378 + atomic_long_unchecked_t load_user_context;
34379 + atomic_long_unchecked_t load_kernel_context;
34380 + atomic_long_unchecked_t lock_kernel_context;
34381 + atomic_long_unchecked_t unlock_kernel_context;
34382 + atomic_long_unchecked_t steal_user_context;
34383 + atomic_long_unchecked_t steal_kernel_context;
34384 + atomic_long_unchecked_t steal_context_failed;
34385 + atomic_long_unchecked_t nopfn;
34386 + atomic_long_unchecked_t asid_new;
34387 + atomic_long_unchecked_t asid_next;
34388 + atomic_long_unchecked_t asid_wrap;
34389 + atomic_long_unchecked_t asid_reuse;
34390 + atomic_long_unchecked_t intr;
34391 + atomic_long_unchecked_t intr_cbr;
34392 + atomic_long_unchecked_t intr_tfh;
34393 + atomic_long_unchecked_t intr_spurious;
34394 + atomic_long_unchecked_t intr_mm_lock_failed;
34395 + atomic_long_unchecked_t call_os;
34396 + atomic_long_unchecked_t call_os_wait_queue;
34397 + atomic_long_unchecked_t user_flush_tlb;
34398 + atomic_long_unchecked_t user_unload_context;
34399 + atomic_long_unchecked_t user_exception;
34400 + atomic_long_unchecked_t set_context_option;
34401 + atomic_long_unchecked_t check_context_retarget_intr;
34402 + atomic_long_unchecked_t check_context_unload;
34403 + atomic_long_unchecked_t tlb_dropin;
34404 + atomic_long_unchecked_t tlb_preload_page;
34405 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34406 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34407 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34408 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34409 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34410 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34411 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34412 + atomic_long_unchecked_t tfh_stale_on_fault;
34413 + atomic_long_unchecked_t mmu_invalidate_range;
34414 + atomic_long_unchecked_t mmu_invalidate_page;
34415 + atomic_long_unchecked_t flush_tlb;
34416 + atomic_long_unchecked_t flush_tlb_gru;
34417 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34418 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34419
34420 - atomic_long_t copy_gpa;
34421 - atomic_long_t read_gpa;
34422 + atomic_long_unchecked_t copy_gpa;
34423 + atomic_long_unchecked_t read_gpa;
34424
34425 - atomic_long_t mesq_receive;
34426 - atomic_long_t mesq_receive_none;
34427 - atomic_long_t mesq_send;
34428 - atomic_long_t mesq_send_failed;
34429 - atomic_long_t mesq_noop;
34430 - atomic_long_t mesq_send_unexpected_error;
34431 - atomic_long_t mesq_send_lb_overflow;
34432 - atomic_long_t mesq_send_qlimit_reached;
34433 - atomic_long_t mesq_send_amo_nacked;
34434 - atomic_long_t mesq_send_put_nacked;
34435 - atomic_long_t mesq_page_overflow;
34436 - atomic_long_t mesq_qf_locked;
34437 - atomic_long_t mesq_qf_noop_not_full;
34438 - atomic_long_t mesq_qf_switch_head_failed;
34439 - atomic_long_t mesq_qf_unexpected_error;
34440 - atomic_long_t mesq_noop_unexpected_error;
34441 - atomic_long_t mesq_noop_lb_overflow;
34442 - atomic_long_t mesq_noop_qlimit_reached;
34443 - atomic_long_t mesq_noop_amo_nacked;
34444 - atomic_long_t mesq_noop_put_nacked;
34445 - atomic_long_t mesq_noop_page_overflow;
34446 + atomic_long_unchecked_t mesq_receive;
34447 + atomic_long_unchecked_t mesq_receive_none;
34448 + atomic_long_unchecked_t mesq_send;
34449 + atomic_long_unchecked_t mesq_send_failed;
34450 + atomic_long_unchecked_t mesq_noop;
34451 + atomic_long_unchecked_t mesq_send_unexpected_error;
34452 + atomic_long_unchecked_t mesq_send_lb_overflow;
34453 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34454 + atomic_long_unchecked_t mesq_send_amo_nacked;
34455 + atomic_long_unchecked_t mesq_send_put_nacked;
34456 + atomic_long_unchecked_t mesq_page_overflow;
34457 + atomic_long_unchecked_t mesq_qf_locked;
34458 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34459 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34460 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34461 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34462 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34463 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34464 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34465 + atomic_long_unchecked_t mesq_noop_put_nacked;
34466 + atomic_long_unchecked_t mesq_noop_page_overflow;
34467
34468 };
34469
34470 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34471 tghop_invalidate, mcsop_last};
34472
34473 struct mcs_op_statistic {
34474 - atomic_long_t count;
34475 - atomic_long_t total;
34476 + atomic_long_unchecked_t count;
34477 + atomic_long_unchecked_t total;
34478 unsigned long max;
34479 };
34480
34481 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34482
34483 #define STAT(id) do { \
34484 if (gru_options & OPT_STATS) \
34485 - atomic_long_inc(&gru_stats.id); \
34486 + atomic_long_inc_unchecked(&gru_stats.id); \
34487 } while (0)
34488
34489 #ifdef CONFIG_SGI_GRU_DEBUG
34490 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34491 index 851b2f2..a4ec097 100644
34492 --- a/drivers/misc/sgi-xp/xp.h
34493 +++ b/drivers/misc/sgi-xp/xp.h
34494 @@ -289,7 +289,7 @@ struct xpc_interface {
34495 xpc_notify_func, void *);
34496 void (*received) (short, int, void *);
34497 enum xp_retval (*partid_to_nasids) (short, void *);
34498 -};
34499 +} __no_const;
34500
34501 extern struct xpc_interface xpc_interface;
34502
34503 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34504 index b94d5f7..7f494c5 100644
34505 --- a/drivers/misc/sgi-xp/xpc.h
34506 +++ b/drivers/misc/sgi-xp/xpc.h
34507 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34508 void (*received_payload) (struct xpc_channel *, void *);
34509 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34510 };
34511 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34512
34513 /* struct xpc_partition act_state values (for XPC HB) */
34514
34515 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34516 /* found in xpc_main.c */
34517 extern struct device *xpc_part;
34518 extern struct device *xpc_chan;
34519 -extern struct xpc_arch_operations xpc_arch_ops;
34520 +extern xpc_arch_operations_no_const xpc_arch_ops;
34521 extern int xpc_disengage_timelimit;
34522 extern int xpc_disengage_timedout;
34523 extern int xpc_activate_IRQ_rcvd;
34524 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34525 index 8d082b4..aa749ae 100644
34526 --- a/drivers/misc/sgi-xp/xpc_main.c
34527 +++ b/drivers/misc/sgi-xp/xpc_main.c
34528 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34529 .notifier_call = xpc_system_die,
34530 };
34531
34532 -struct xpc_arch_operations xpc_arch_ops;
34533 +xpc_arch_operations_no_const xpc_arch_ops;
34534
34535 /*
34536 * Timer function to enforce the timelimit on the partition disengage.
34537 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34538 index 6ebdc40..9edf5d8 100644
34539 --- a/drivers/mmc/host/sdhci-pci.c
34540 +++ b/drivers/mmc/host/sdhci-pci.c
34541 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34542 .probe = via_probe,
34543 };
34544
34545 -static const struct pci_device_id pci_ids[] __devinitdata = {
34546 +static const struct pci_device_id pci_ids[] __devinitconst = {
34547 {
34548 .vendor = PCI_VENDOR_ID_RICOH,
34549 .device = PCI_DEVICE_ID_RICOH_R5C822,
34550 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34551 index 87a431c..4959b43 100644
34552 --- a/drivers/mtd/devices/doc2000.c
34553 +++ b/drivers/mtd/devices/doc2000.c
34554 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34555
34556 /* The ECC will not be calculated correctly if less than 512 is written */
34557 /* DBB-
34558 - if (len != 0x200 && eccbuf)
34559 + if (len != 0x200)
34560 printk(KERN_WARNING
34561 "ECC needs a full sector write (adr: %lx size %lx)\n",
34562 (long) to, (long) len);
34563 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34564 index 9eacf67..4534b5b 100644
34565 --- a/drivers/mtd/devices/doc2001.c
34566 +++ b/drivers/mtd/devices/doc2001.c
34567 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34568 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34569
34570 /* Don't allow read past end of device */
34571 - if (from >= this->totlen)
34572 + if (from >= this->totlen || !len)
34573 return -EINVAL;
34574
34575 /* Don't allow a single read to cross a 512-byte block boundary */
34576 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34577 index 3984d48..28aa897 100644
34578 --- a/drivers/mtd/nand/denali.c
34579 +++ b/drivers/mtd/nand/denali.c
34580 @@ -26,6 +26,7 @@
34581 #include <linux/pci.h>
34582 #include <linux/mtd/mtd.h>
34583 #include <linux/module.h>
34584 +#include <linux/slab.h>
34585
34586 #include "denali.h"
34587
34588 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34589 index 51b9d6a..52af9a7 100644
34590 --- a/drivers/mtd/nftlmount.c
34591 +++ b/drivers/mtd/nftlmount.c
34592 @@ -24,6 +24,7 @@
34593 #include <asm/errno.h>
34594 #include <linux/delay.h>
34595 #include <linux/slab.h>
34596 +#include <linux/sched.h>
34597 #include <linux/mtd/mtd.h>
34598 #include <linux/mtd/nand.h>
34599 #include <linux/mtd/nftl.h>
34600 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34601 index e2cdebf..d48183a 100644
34602 --- a/drivers/mtd/ubi/debug.c
34603 +++ b/drivers/mtd/ubi/debug.c
34604 @@ -338,6 +338,8 @@ out:
34605
34606 /* Write an UBI debugfs file */
34607 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34608 + size_t count, loff_t *ppos) __size_overflow(3);
34609 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34610 size_t count, loff_t *ppos)
34611 {
34612 unsigned long ubi_num = (unsigned long)file->private_data;
34613 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34614 index 071f4c8..440862e 100644
34615 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34616 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34617 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34618 */
34619
34620 #define ATL2_PARAM(X, desc) \
34621 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34622 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34623 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34624 MODULE_PARM_DESC(X, desc);
34625 #else
34626 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34627 index 66da39f..5dc436d 100644
34628 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34629 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34630 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34631
34632 int (*wait_comp)(struct bnx2x *bp,
34633 struct bnx2x_rx_mode_ramrod_params *p);
34634 -};
34635 +} __no_const;
34636
34637 /********************** Set multicast group ***********************************/
34638
34639 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34640 index aea8f72..fcebf75 100644
34641 --- a/drivers/net/ethernet/broadcom/tg3.h
34642 +++ b/drivers/net/ethernet/broadcom/tg3.h
34643 @@ -140,6 +140,7 @@
34644 #define CHIPREV_ID_5750_A0 0x4000
34645 #define CHIPREV_ID_5750_A1 0x4001
34646 #define CHIPREV_ID_5750_A3 0x4003
34647 +#define CHIPREV_ID_5750_C1 0x4201
34648 #define CHIPREV_ID_5750_C2 0x4202
34649 #define CHIPREV_ID_5752_A0_HW 0x5000
34650 #define CHIPREV_ID_5752_A0 0x6000
34651 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
34652 index 47a8435..248e4b3 100644
34653 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
34654 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
34655 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
34656 * be copied but there is no memory for the copy.
34657 */
34658 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34659 + struct freelQ *fl, unsigned int len) __size_overflow(3);
34660 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34661 struct freelQ *fl, unsigned int len)
34662 {
34663 struct sk_buff *skb;
34664 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34665 index c4e8643..0979484 100644
34666 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34667 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34668 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34669 */
34670 struct l2t_skb_cb {
34671 arp_failure_handler_func arp_failure_handler;
34672 -};
34673 +} __no_const;
34674
34675 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34676
34677 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34678 index cfb60e1..94af340 100644
34679 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34680 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34681 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34682 * of the SW ring.
34683 */
34684 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34685 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34686 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34687 size_t sw_size, dma_addr_t * phys, void *metadata)
34688 {
34689 size_t len = nelem * elem_size;
34690 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
34691 * be copied but there is no memory for the copy.
34692 */
34693 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34694 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
34695 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34696 unsigned int len, unsigned int drop_thres)
34697 {
34698 struct sk_buff *skb = NULL;
34699 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34700 index 2dae795..73037d2 100644
34701 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34702 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34703 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34704 */
34705 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34706 size_t sw_size, dma_addr_t *phys, void *metadata,
34707 + size_t stat_size, int node) __size_overflow(2,4);
34708 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34709 + size_t sw_size, dma_addr_t *phys, void *metadata,
34710 size_t stat_size, int node)
34711 {
34712 size_t len = nelem * elem_size + stat_size;
34713 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34714 index 0bd585b..d954ca5 100644
34715 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34716 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34717 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34718 */
34719 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34720 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34721 + size_t stat_size) __size_overflow(2,4);
34722 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34723 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34724 size_t stat_size)
34725 {
34726 /*
34727 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34728 index 4d71f5a..8004440 100644
34729 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34730 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34731 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34732 for (i=0; i<ETH_ALEN; i++) {
34733 tmp.addr[i] = dev->dev_addr[i];
34734 }
34735 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34736 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34737 break;
34738
34739 case DE4X5_SET_HWADDR: /* Set the hardware address */
34740 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34741 spin_lock_irqsave(&lp->lock, flags);
34742 memcpy(&statbuf, &lp->pktStats, ioc->len);
34743 spin_unlock_irqrestore(&lp->lock, flags);
34744 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34745 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34746 return -EFAULT;
34747 break;
34748 }
34749 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34750 index 14d5b61..1398636 100644
34751 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34752 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34753 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34754 {NULL}};
34755
34756
34757 -static const char *block_name[] __devinitdata = {
34758 +static const char *block_name[] __devinitconst = {
34759 "21140 non-MII",
34760 "21140 MII PHY",
34761 "21142 Serial PHY",
34762 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34763 index 52da7b2..4ddfe1c 100644
34764 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34765 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34766 @@ -236,7 +236,7 @@ struct pci_id_info {
34767 int drv_flags; /* Driver use, intended as capability flags. */
34768 };
34769
34770 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34771 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34772 { /* Sometime a Level-One switch card. */
34773 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34774 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34775 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34776 index 28a3a9b..d96cb63 100644
34777 --- a/drivers/net/ethernet/dlink/sundance.c
34778 +++ b/drivers/net/ethernet/dlink/sundance.c
34779 @@ -218,7 +218,7 @@ enum {
34780 struct pci_id_info {
34781 const char *name;
34782 };
34783 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34784 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34785 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34786 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34787 {"D-Link DFE-580TX 4 port Server Adapter"},
34788 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34789 index e703d64..d62ecf9 100644
34790 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34791 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34792 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34793
34794 if (wrapped)
34795 newacc += 65536;
34796 - ACCESS_ONCE(*acc) = newacc;
34797 + ACCESS_ONCE_RW(*acc) = newacc;
34798 }
34799
34800 void be_parse_stats(struct be_adapter *adapter)
34801 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34802 index 47f85c3..82ab6c4 100644
34803 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34804 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34805 @@ -31,6 +31,8 @@
34806 #include <linux/netdevice.h>
34807 #include <linux/phy.h>
34808 #include <linux/platform_device.h>
34809 +#include <linux/interrupt.h>
34810 +#include <linux/irqreturn.h>
34811 #include <net/ip.h>
34812
34813 #include "ftgmac100.h"
34814 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34815 index bb336a0..4b472da 100644
34816 --- a/drivers/net/ethernet/faraday/ftmac100.c
34817 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34818 @@ -31,6 +31,8 @@
34819 #include <linux/module.h>
34820 #include <linux/netdevice.h>
34821 #include <linux/platform_device.h>
34822 +#include <linux/interrupt.h>
34823 +#include <linux/irqreturn.h>
34824
34825 #include "ftmac100.h"
34826
34827 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34828 index c82d444..0007fb4 100644
34829 --- a/drivers/net/ethernet/fealnx.c
34830 +++ b/drivers/net/ethernet/fealnx.c
34831 @@ -150,7 +150,7 @@ struct chip_info {
34832 int flags;
34833 };
34834
34835 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34836 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34837 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34838 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34839 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34840 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34841 index e1159e5..e18684d 100644
34842 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34843 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34844 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34845 {
34846 struct e1000_hw *hw = &adapter->hw;
34847 struct e1000_mac_info *mac = &hw->mac;
34848 - struct e1000_mac_operations *func = &mac->ops;
34849 + e1000_mac_operations_no_const *func = &mac->ops;
34850
34851 /* Set media type */
34852 switch (adapter->pdev->device) {
34853 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34854 index a3e65fd..f451444 100644
34855 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34856 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34857 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34858 {
34859 struct e1000_hw *hw = &adapter->hw;
34860 struct e1000_mac_info *mac = &hw->mac;
34861 - struct e1000_mac_operations *func = &mac->ops;
34862 + e1000_mac_operations_no_const *func = &mac->ops;
34863 u32 swsm = 0;
34864 u32 swsm2 = 0;
34865 bool force_clear_smbi = false;
34866 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34867 index 2967039..ca8c40c 100644
34868 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34869 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34870 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34871 void (*write_vfta)(struct e1000_hw *, u32, u32);
34872 s32 (*read_mac_addr)(struct e1000_hw *);
34873 };
34874 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34875
34876 /*
34877 * When to use various PHY register access functions:
34878 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34879 void (*power_up)(struct e1000_hw *);
34880 void (*power_down)(struct e1000_hw *);
34881 };
34882 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34883
34884 /* Function pointers for the NVM. */
34885 struct e1000_nvm_operations {
34886 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34887 s32 (*validate)(struct e1000_hw *);
34888 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34889 };
34890 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34891
34892 struct e1000_mac_info {
34893 - struct e1000_mac_operations ops;
34894 + e1000_mac_operations_no_const ops;
34895 u8 addr[ETH_ALEN];
34896 u8 perm_addr[ETH_ALEN];
34897
34898 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34899 };
34900
34901 struct e1000_phy_info {
34902 - struct e1000_phy_operations ops;
34903 + e1000_phy_operations_no_const ops;
34904
34905 enum e1000_phy_type type;
34906
34907 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34908 };
34909
34910 struct e1000_nvm_info {
34911 - struct e1000_nvm_operations ops;
34912 + e1000_nvm_operations_no_const ops;
34913
34914 enum e1000_nvm_type type;
34915 enum e1000_nvm_override override;
34916 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34917 index f67cbd3..cef9e3d 100644
34918 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34919 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34920 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34921 s32 (*read_mac_addr)(struct e1000_hw *);
34922 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34923 };
34924 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34925
34926 struct e1000_phy_operations {
34927 s32 (*acquire)(struct e1000_hw *);
34928 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34929 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34930 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34931 };
34932 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34933
34934 struct e1000_nvm_operations {
34935 s32 (*acquire)(struct e1000_hw *);
34936 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34937 s32 (*update)(struct e1000_hw *);
34938 s32 (*validate)(struct e1000_hw *);
34939 };
34940 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34941
34942 struct e1000_info {
34943 s32 (*get_invariants)(struct e1000_hw *);
34944 @@ -350,7 +353,7 @@ struct e1000_info {
34945 extern const struct e1000_info e1000_82575_info;
34946
34947 struct e1000_mac_info {
34948 - struct e1000_mac_operations ops;
34949 + e1000_mac_operations_no_const ops;
34950
34951 u8 addr[6];
34952 u8 perm_addr[6];
34953 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34954 };
34955
34956 struct e1000_phy_info {
34957 - struct e1000_phy_operations ops;
34958 + e1000_phy_operations_no_const ops;
34959
34960 enum e1000_phy_type type;
34961
34962 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34963 };
34964
34965 struct e1000_nvm_info {
34966 - struct e1000_nvm_operations ops;
34967 + e1000_nvm_operations_no_const ops;
34968 enum e1000_nvm_type type;
34969 enum e1000_nvm_override override;
34970
34971 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34972 s32 (*check_for_ack)(struct e1000_hw *, u16);
34973 s32 (*check_for_rst)(struct e1000_hw *, u16);
34974 };
34975 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34976
34977 struct e1000_mbx_stats {
34978 u32 msgs_tx;
34979 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34980 };
34981
34982 struct e1000_mbx_info {
34983 - struct e1000_mbx_operations ops;
34984 + e1000_mbx_operations_no_const ops;
34985 struct e1000_mbx_stats stats;
34986 u32 timeout;
34987 u32 usec_delay;
34988 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34989 index 57db3c6..aa825fc 100644
34990 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34991 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34992 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34993 s32 (*read_mac_addr)(struct e1000_hw *);
34994 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34995 };
34996 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34997
34998 struct e1000_mac_info {
34999 - struct e1000_mac_operations ops;
35000 + e1000_mac_operations_no_const ops;
35001 u8 addr[6];
35002 u8 perm_addr[6];
35003
35004 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35005 s32 (*check_for_ack)(struct e1000_hw *);
35006 s32 (*check_for_rst)(struct e1000_hw *);
35007 };
35008 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35009
35010 struct e1000_mbx_stats {
35011 u32 msgs_tx;
35012 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35013 };
35014
35015 struct e1000_mbx_info {
35016 - struct e1000_mbx_operations ops;
35017 + e1000_mbx_operations_no_const ops;
35018 struct e1000_mbx_stats stats;
35019 u32 timeout;
35020 u32 usec_delay;
35021 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35022 index 9b95bef..7e254ee 100644
35023 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35024 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35025 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35026 s32 (*update_checksum)(struct ixgbe_hw *);
35027 u16 (*calc_checksum)(struct ixgbe_hw *);
35028 };
35029 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35030
35031 struct ixgbe_mac_operations {
35032 s32 (*init_hw)(struct ixgbe_hw *);
35033 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35034 /* Manageability interface */
35035 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35036 };
35037 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35038
35039 struct ixgbe_phy_operations {
35040 s32 (*identify)(struct ixgbe_hw *);
35041 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35042 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35043 s32 (*check_overtemp)(struct ixgbe_hw *);
35044 };
35045 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35046
35047 struct ixgbe_eeprom_info {
35048 - struct ixgbe_eeprom_operations ops;
35049 + ixgbe_eeprom_operations_no_const ops;
35050 enum ixgbe_eeprom_type type;
35051 u32 semaphore_delay;
35052 u16 word_size;
35053 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35054
35055 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35056 struct ixgbe_mac_info {
35057 - struct ixgbe_mac_operations ops;
35058 + ixgbe_mac_operations_no_const ops;
35059 enum ixgbe_mac_type type;
35060 u8 addr[ETH_ALEN];
35061 u8 perm_addr[ETH_ALEN];
35062 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35063 };
35064
35065 struct ixgbe_phy_info {
35066 - struct ixgbe_phy_operations ops;
35067 + ixgbe_phy_operations_no_const ops;
35068 struct mdio_if_info mdio;
35069 enum ixgbe_phy_type type;
35070 u32 id;
35071 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35072 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35073 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35074 };
35075 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35076
35077 struct ixgbe_mbx_stats {
35078 u32 msgs_tx;
35079 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35080 };
35081
35082 struct ixgbe_mbx_info {
35083 - struct ixgbe_mbx_operations ops;
35084 + ixgbe_mbx_operations_no_const ops;
35085 struct ixgbe_mbx_stats stats;
35086 u32 timeout;
35087 u32 usec_delay;
35088 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35089 index 25c951d..cc7cf33 100644
35090 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35091 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35092 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35093 s32 (*clear_vfta)(struct ixgbe_hw *);
35094 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35095 };
35096 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35097
35098 enum ixgbe_mac_type {
35099 ixgbe_mac_unknown = 0,
35100 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35101 };
35102
35103 struct ixgbe_mac_info {
35104 - struct ixgbe_mac_operations ops;
35105 + ixgbe_mac_operations_no_const ops;
35106 u8 addr[6];
35107 u8 perm_addr[6];
35108
35109 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35110 s32 (*check_for_ack)(struct ixgbe_hw *);
35111 s32 (*check_for_rst)(struct ixgbe_hw *);
35112 };
35113 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35114
35115 struct ixgbe_mbx_stats {
35116 u32 msgs_tx;
35117 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35118 };
35119
35120 struct ixgbe_mbx_info {
35121 - struct ixgbe_mbx_operations ops;
35122 + ixgbe_mbx_operations_no_const ops;
35123 struct ixgbe_mbx_stats stats;
35124 u32 timeout;
35125 u32 udelay;
35126 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35127 index 8bf22b6..7f5baaa 100644
35128 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35129 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35130 @@ -41,6 +41,7 @@
35131 #include <linux/slab.h>
35132 #include <linux/io-mapping.h>
35133 #include <linux/delay.h>
35134 +#include <linux/sched.h>
35135
35136 #include <linux/mlx4/device.h>
35137 #include <linux/mlx4/doorbell.h>
35138 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35139 index 5046a64..71ca936 100644
35140 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35141 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35142 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35143 void (*link_down)(struct __vxge_hw_device *devh);
35144 void (*crit_err)(struct __vxge_hw_device *devh,
35145 enum vxge_hw_event type, u64 ext_data);
35146 -};
35147 +} __no_const;
35148
35149 /*
35150 * struct __vxge_hw_blockpool_entry - Block private data structure
35151 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35152 index 4a518a3..936b334 100644
35153 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35154 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35155 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35156 struct vxge_hw_mempool_dma *dma_object,
35157 u32 index,
35158 u32 is_last);
35159 -};
35160 +} __no_const;
35161
35162 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35163 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35164 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35165 index bbacb37..d60887d 100644
35166 --- a/drivers/net/ethernet/realtek/r8169.c
35167 +++ b/drivers/net/ethernet/realtek/r8169.c
35168 @@ -695,17 +695,17 @@ struct rtl8169_private {
35169 struct mdio_ops {
35170 void (*write)(void __iomem *, int, int);
35171 int (*read)(void __iomem *, int);
35172 - } mdio_ops;
35173 + } __no_const mdio_ops;
35174
35175 struct pll_power_ops {
35176 void (*down)(struct rtl8169_private *);
35177 void (*up)(struct rtl8169_private *);
35178 - } pll_power_ops;
35179 + } __no_const pll_power_ops;
35180
35181 struct jumbo_ops {
35182 void (*enable)(struct rtl8169_private *);
35183 void (*disable)(struct rtl8169_private *);
35184 - } jumbo_ops;
35185 + } __no_const jumbo_ops;
35186
35187 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35188 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35189 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35190 index 5b118cd..858b523 100644
35191 --- a/drivers/net/ethernet/sis/sis190.c
35192 +++ b/drivers/net/ethernet/sis/sis190.c
35193 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35194 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35195 struct net_device *dev)
35196 {
35197 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35198 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35199 struct sis190_private *tp = netdev_priv(dev);
35200 struct pci_dev *isa_bridge;
35201 u8 reg, tmp8;
35202 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35203 index c07cfe9..81cbf7e 100644
35204 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35205 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35206 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35207
35208 writel(value, ioaddr + MMC_CNTRL);
35209
35210 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35211 - MMC_CNTRL, value);
35212 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35213 +// MMC_CNTRL, value);
35214 }
35215
35216 /* To mask all all interrupts.*/
35217 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35218 index dec5836..6d4db7d 100644
35219 --- a/drivers/net/hyperv/hyperv_net.h
35220 +++ b/drivers/net/hyperv/hyperv_net.h
35221 @@ -97,7 +97,7 @@ struct rndis_device {
35222
35223 enum rndis_device_state state;
35224 bool link_state;
35225 - atomic_t new_req_id;
35226 + atomic_unchecked_t new_req_id;
35227
35228 spinlock_t request_lock;
35229 struct list_head req_list;
35230 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35231 index 133b7fb..d58c559 100644
35232 --- a/drivers/net/hyperv/rndis_filter.c
35233 +++ b/drivers/net/hyperv/rndis_filter.c
35234 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35235 * template
35236 */
35237 set = &rndis_msg->msg.set_req;
35238 - set->req_id = atomic_inc_return(&dev->new_req_id);
35239 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35240
35241 /* Add to the request list */
35242 spin_lock_irqsave(&dev->request_lock, flags);
35243 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35244
35245 /* Setup the rndis set */
35246 halt = &request->request_msg.msg.halt_req;
35247 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35248 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35249
35250 /* Ignore return since this msg is optional. */
35251 rndis_filter_send_request(dev, request);
35252 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35253 index 486b404..0d6677d 100644
35254 --- a/drivers/net/ppp/ppp_generic.c
35255 +++ b/drivers/net/ppp/ppp_generic.c
35256 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35257 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35258 struct ppp_stats stats;
35259 struct ppp_comp_stats cstats;
35260 - char *vers;
35261
35262 switch (cmd) {
35263 case SIOCGPPPSTATS:
35264 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35265 break;
35266
35267 case SIOCGPPPVER:
35268 - vers = PPP_VERSION;
35269 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35270 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35271 break;
35272 err = 0;
35273 break;
35274 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35275 index 515f122..41dd273 100644
35276 --- a/drivers/net/tokenring/abyss.c
35277 +++ b/drivers/net/tokenring/abyss.c
35278 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35279
35280 static int __init abyss_init (void)
35281 {
35282 - abyss_netdev_ops = tms380tr_netdev_ops;
35283 + pax_open_kernel();
35284 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35285
35286 - abyss_netdev_ops.ndo_open = abyss_open;
35287 - abyss_netdev_ops.ndo_stop = abyss_close;
35288 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35289 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35290 + pax_close_kernel();
35291
35292 return pci_register_driver(&abyss_driver);
35293 }
35294 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35295 index 6153cfd..cf69c1c 100644
35296 --- a/drivers/net/tokenring/madgemc.c
35297 +++ b/drivers/net/tokenring/madgemc.c
35298 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35299
35300 static int __init madgemc_init (void)
35301 {
35302 - madgemc_netdev_ops = tms380tr_netdev_ops;
35303 - madgemc_netdev_ops.ndo_open = madgemc_open;
35304 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35305 + pax_open_kernel();
35306 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35307 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35308 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35309 + pax_close_kernel();
35310
35311 return mca_register_driver (&madgemc_driver);
35312 }
35313 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35314 index 8d362e6..f91cc52 100644
35315 --- a/drivers/net/tokenring/proteon.c
35316 +++ b/drivers/net/tokenring/proteon.c
35317 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35318 struct platform_device *pdev;
35319 int i, num = 0, err = 0;
35320
35321 - proteon_netdev_ops = tms380tr_netdev_ops;
35322 - proteon_netdev_ops.ndo_open = proteon_open;
35323 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35324 + pax_open_kernel();
35325 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35326 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35327 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35328 + pax_close_kernel();
35329
35330 err = platform_driver_register(&proteon_driver);
35331 if (err)
35332 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35333 index 46db5c5..37c1536 100644
35334 --- a/drivers/net/tokenring/skisa.c
35335 +++ b/drivers/net/tokenring/skisa.c
35336 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35337 struct platform_device *pdev;
35338 int i, num = 0, err = 0;
35339
35340 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35341 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35342 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35343 + pax_open_kernel();
35344 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35345 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35346 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35347 + pax_close_kernel();
35348
35349 err = platform_driver_register(&sk_isa_driver);
35350 if (err)
35351 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35352 index e1324b4..e1b0041 100644
35353 --- a/drivers/net/usb/hso.c
35354 +++ b/drivers/net/usb/hso.c
35355 @@ -71,7 +71,7 @@
35356 #include <asm/byteorder.h>
35357 #include <linux/serial_core.h>
35358 #include <linux/serial.h>
35359 -
35360 +#include <asm/local.h>
35361
35362 #define MOD_AUTHOR "Option Wireless"
35363 #define MOD_DESCRIPTION "USB High Speed Option driver"
35364 @@ -257,7 +257,7 @@ struct hso_serial {
35365
35366 /* from usb_serial_port */
35367 struct tty_struct *tty;
35368 - int open_count;
35369 + local_t open_count;
35370 spinlock_t serial_lock;
35371
35372 int (*write_data) (struct hso_serial *serial);
35373 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35374 struct urb *urb;
35375
35376 urb = serial->rx_urb[0];
35377 - if (serial->open_count > 0) {
35378 + if (local_read(&serial->open_count) > 0) {
35379 count = put_rxbuf_data(urb, serial);
35380 if (count == -1)
35381 return;
35382 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35383 DUMP1(urb->transfer_buffer, urb->actual_length);
35384
35385 /* Anyone listening? */
35386 - if (serial->open_count == 0)
35387 + if (local_read(&serial->open_count) == 0)
35388 return;
35389
35390 if (status == 0) {
35391 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35392 spin_unlock_irq(&serial->serial_lock);
35393
35394 /* check for port already opened, if not set the termios */
35395 - serial->open_count++;
35396 - if (serial->open_count == 1) {
35397 + if (local_inc_return(&serial->open_count) == 1) {
35398 serial->rx_state = RX_IDLE;
35399 /* Force default termio settings */
35400 _hso_serial_set_termios(tty, NULL);
35401 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35402 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35403 if (result) {
35404 hso_stop_serial_device(serial->parent);
35405 - serial->open_count--;
35406 + local_dec(&serial->open_count);
35407 kref_put(&serial->parent->ref, hso_serial_ref_free);
35408 }
35409 } else {
35410 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35411
35412 /* reset the rts and dtr */
35413 /* do the actual close */
35414 - serial->open_count--;
35415 + local_dec(&serial->open_count);
35416
35417 - if (serial->open_count <= 0) {
35418 - serial->open_count = 0;
35419 + if (local_read(&serial->open_count) <= 0) {
35420 + local_set(&serial->open_count, 0);
35421 spin_lock_irq(&serial->serial_lock);
35422 if (serial->tty == tty) {
35423 serial->tty->driver_data = NULL;
35424 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35425
35426 /* the actual setup */
35427 spin_lock_irqsave(&serial->serial_lock, flags);
35428 - if (serial->open_count)
35429 + if (local_read(&serial->open_count))
35430 _hso_serial_set_termios(tty, old);
35431 else
35432 tty->termios = old;
35433 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35434 D1("Pending read interrupt on port %d\n", i);
35435 spin_lock(&serial->serial_lock);
35436 if (serial->rx_state == RX_IDLE &&
35437 - serial->open_count > 0) {
35438 + local_read(&serial->open_count) > 0) {
35439 /* Setup and send a ctrl req read on
35440 * port i */
35441 if (!serial->rx_urb_filled[0]) {
35442 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35443 /* Start all serial ports */
35444 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35445 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35446 - if (dev2ser(serial_table[i])->open_count) {
35447 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35448 result =
35449 hso_start_serial_device(serial_table[i], GFP_NOIO);
35450 hso_kick_transmit(dev2ser(serial_table[i]));
35451 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35452 index efc0111..79c8f5b 100644
35453 --- a/drivers/net/wireless/ath/ath.h
35454 +++ b/drivers/net/wireless/ath/ath.h
35455 @@ -119,6 +119,7 @@ struct ath_ops {
35456 void (*write_flush) (void *);
35457 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35458 };
35459 +typedef struct ath_ops __no_const ath_ops_no_const;
35460
35461 struct ath_common;
35462 struct ath_bus_ops;
35463 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35464 index 8c5ce8b..abf101b 100644
35465 --- a/drivers/net/wireless/ath/ath5k/debug.c
35466 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35467 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35468
35469 static ssize_t write_file_debug(struct file *file,
35470 const char __user *userbuf,
35471 + size_t count, loff_t *ppos) __size_overflow(3);
35472 +static ssize_t write_file_debug(struct file *file,
35473 + const char __user *userbuf,
35474 size_t count, loff_t *ppos)
35475 {
35476 struct ath5k_hw *ah = file->private_data;
35477 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35478 index 7b6417b..ab5db98 100644
35479 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35480 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35481 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35482 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35483 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35484
35485 - ACCESS_ONCE(ads->ds_link) = i->link;
35486 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35487 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35488 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35489
35490 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35491 ctl6 = SM(i->keytype, AR_EncrType);
35492 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35493
35494 if ((i->is_first || i->is_last) &&
35495 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35496 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35497 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35498 | set11nTries(i->rates, 1)
35499 | set11nTries(i->rates, 2)
35500 | set11nTries(i->rates, 3)
35501 | (i->dur_update ? AR_DurUpdateEna : 0)
35502 | SM(0, AR_BurstDur);
35503
35504 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35505 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35506 | set11nRate(i->rates, 1)
35507 | set11nRate(i->rates, 2)
35508 | set11nRate(i->rates, 3);
35509 } else {
35510 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35511 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35512 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35513 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35514 }
35515
35516 if (!i->is_first) {
35517 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35518 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35519 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35520 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35521 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35522 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35523 return;
35524 }
35525
35526 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35527 break;
35528 }
35529
35530 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35531 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35532 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35533 | SM(i->txpower, AR_XmitPower)
35534 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35535 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35536 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35537 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35538
35539 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35540 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35541 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35542 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35543
35544 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35545 return;
35546
35547 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35548 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35549 | set11nPktDurRTSCTS(i->rates, 1);
35550
35551 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35552 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35553 | set11nPktDurRTSCTS(i->rates, 3);
35554
35555 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35556 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35557 | set11nRateFlags(i->rates, 1)
35558 | set11nRateFlags(i->rates, 2)
35559 | set11nRateFlags(i->rates, 3)
35560 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35561 index 09b8c9d..905339e 100644
35562 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35563 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35564 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35565 (i->qcu << AR_TxQcuNum_S) | 0x17;
35566
35567 checksum += val;
35568 - ACCESS_ONCE(ads->info) = val;
35569 + ACCESS_ONCE_RW(ads->info) = val;
35570
35571 checksum += i->link;
35572 - ACCESS_ONCE(ads->link) = i->link;
35573 + ACCESS_ONCE_RW(ads->link) = i->link;
35574
35575 checksum += i->buf_addr[0];
35576 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35577 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35578 checksum += i->buf_addr[1];
35579 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35580 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35581 checksum += i->buf_addr[2];
35582 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35583 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35584 checksum += i->buf_addr[3];
35585 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35586 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35587
35588 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35589 - ACCESS_ONCE(ads->ctl3) = val;
35590 + ACCESS_ONCE_RW(ads->ctl3) = val;
35591 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35592 - ACCESS_ONCE(ads->ctl5) = val;
35593 + ACCESS_ONCE_RW(ads->ctl5) = val;
35594 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35595 - ACCESS_ONCE(ads->ctl7) = val;
35596 + ACCESS_ONCE_RW(ads->ctl7) = val;
35597 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35598 - ACCESS_ONCE(ads->ctl9) = val;
35599 + ACCESS_ONCE_RW(ads->ctl9) = val;
35600
35601 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35602 - ACCESS_ONCE(ads->ctl10) = checksum;
35603 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35604
35605 if (i->is_first || i->is_last) {
35606 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35607 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35608 | set11nTries(i->rates, 1)
35609 | set11nTries(i->rates, 2)
35610 | set11nTries(i->rates, 3)
35611 | (i->dur_update ? AR_DurUpdateEna : 0)
35612 | SM(0, AR_BurstDur);
35613
35614 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35615 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35616 | set11nRate(i->rates, 1)
35617 | set11nRate(i->rates, 2)
35618 | set11nRate(i->rates, 3);
35619 } else {
35620 - ACCESS_ONCE(ads->ctl13) = 0;
35621 - ACCESS_ONCE(ads->ctl14) = 0;
35622 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35623 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35624 }
35625
35626 ads->ctl20 = 0;
35627 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35628
35629 ctl17 = SM(i->keytype, AR_EncrType);
35630 if (!i->is_first) {
35631 - ACCESS_ONCE(ads->ctl11) = 0;
35632 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35633 - ACCESS_ONCE(ads->ctl15) = 0;
35634 - ACCESS_ONCE(ads->ctl16) = 0;
35635 - ACCESS_ONCE(ads->ctl17) = ctl17;
35636 - ACCESS_ONCE(ads->ctl18) = 0;
35637 - ACCESS_ONCE(ads->ctl19) = 0;
35638 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35639 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35640 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35641 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35642 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35643 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35644 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35645 return;
35646 }
35647
35648 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35649 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35650 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35651 | SM(i->txpower, AR_XmitPower)
35652 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35653 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35654 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35655 ctl12 |= SM(val, AR_PAPRDChainMask);
35656
35657 - ACCESS_ONCE(ads->ctl12) = ctl12;
35658 - ACCESS_ONCE(ads->ctl17) = ctl17;
35659 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35660 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35661
35662 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35663 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35664 | set11nPktDurRTSCTS(i->rates, 1);
35665
35666 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35667 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35668 | set11nPktDurRTSCTS(i->rates, 3);
35669
35670 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35671 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35672 | set11nRateFlags(i->rates, 1)
35673 | set11nRateFlags(i->rates, 2)
35674 | set11nRateFlags(i->rates, 3)
35675 | SM(i->rtscts_rate, AR_RTSCTSRate);
35676
35677 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35678 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35679 }
35680
35681 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35682 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
35683 index 68d972b..1d9205b 100644
35684 --- a/drivers/net/wireless/ath/ath9k/debug.c
35685 +++ b/drivers/net/wireless/ath/ath9k/debug.c
35686 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35687 }
35688
35689 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35690 + size_t count, loff_t *ppos) __size_overflow(3);
35691 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35692 size_t count, loff_t *ppos)
35693 {
35694 struct ath_softc *sc = file->private_data;
35695 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35696 index d3ff33c..c98bcda 100644
35697 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35698 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35699 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35700 }
35701
35702 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35703 + size_t count, loff_t *ppos) __size_overflow(3);
35704 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35705 size_t count, loff_t *ppos)
35706 {
35707 struct ath9k_htc_priv *priv = file->private_data;
35708 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35709 index c8261d4..8d88929 100644
35710 --- a/drivers/net/wireless/ath/ath9k/hw.h
35711 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35712 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35713
35714 /* ANI */
35715 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35716 -};
35717 +} __no_const;
35718
35719 /**
35720 * struct ath_hw_ops - callbacks used by hardware code and driver code
35721 @@ -803,7 +803,7 @@ struct ath_hw_ops {
35722 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35723 struct ath_hw_antcomb_conf *antconf);
35724
35725 -};
35726 +} __no_const;
35727
35728 struct ath_nf_limits {
35729 s16 max;
35730 @@ -823,7 +823,7 @@ enum ath_cal_list {
35731 #define AH_FASTCC 0x4
35732
35733 struct ath_hw {
35734 - struct ath_ops reg_ops;
35735 + ath_ops_no_const reg_ops;
35736
35737 struct ieee80211_hw *hw;
35738 struct ath_common common;
35739 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35740 index af00e2c..ab04d34 100644
35741 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35742 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35743 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35744 void (*carrsuppr)(struct brcms_phy *);
35745 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35746 void (*detach)(struct brcms_phy *);
35747 -};
35748 +} __no_const;
35749
35750 struct brcms_phy {
35751 struct brcms_phy_pub pubpi_ro;
35752 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35753 index a2ec369..36fdf14 100644
35754 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35755 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35756 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35757 */
35758 if (il3945_mod_params.disable_hw_scan) {
35759 D_INFO("Disabling hw_scan\n");
35760 - il3945_hw_ops.hw_scan = NULL;
35761 + pax_open_kernel();
35762 + *(void **)&il3945_hw_ops.hw_scan = NULL;
35763 + pax_close_kernel();
35764 }
35765
35766 D_INFO("*** LOAD DRIVER ***\n");
35767 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35768 index f8fc239..8cade22 100644
35769 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35770 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35771 @@ -86,8 +86,8 @@ do { \
35772 } while (0)
35773
35774 #else
35775 -#define IWL_DEBUG(m, level, fmt, args...)
35776 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35777 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35778 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35779 #define iwl_print_hex_dump(m, level, p, len)
35780 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35781 do { \
35782 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35783 index 4b9e730..7603659 100644
35784 --- a/drivers/net/wireless/mac80211_hwsim.c
35785 +++ b/drivers/net/wireless/mac80211_hwsim.c
35786 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35787 return -EINVAL;
35788
35789 if (fake_hw_scan) {
35790 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35791 - mac80211_hwsim_ops.sw_scan_start = NULL;
35792 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35793 + pax_open_kernel();
35794 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35795 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35796 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35797 + pax_close_kernel();
35798 }
35799
35800 spin_lock_init(&hwsim_radio_lock);
35801 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35802 index 3186aa4..b35b09f 100644
35803 --- a/drivers/net/wireless/mwifiex/main.h
35804 +++ b/drivers/net/wireless/mwifiex/main.h
35805 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35806 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35807 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35808 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35809 -};
35810 +} __no_const;
35811
35812 struct mwifiex_adapter {
35813 u8 iface_type;
35814 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35815 index a330c69..a81540f 100644
35816 --- a/drivers/net/wireless/rndis_wlan.c
35817 +++ b/drivers/net/wireless/rndis_wlan.c
35818 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35819
35820 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35821
35822 - if (rts_threshold < 0 || rts_threshold > 2347)
35823 + if (rts_threshold > 2347)
35824 rts_threshold = 2347;
35825
35826 tmp = cpu_to_le32(rts_threshold);
35827 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35828 index a77f1bb..c608b2b 100644
35829 --- a/drivers/net/wireless/wl1251/wl1251.h
35830 +++ b/drivers/net/wireless/wl1251/wl1251.h
35831 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35832 void (*reset)(struct wl1251 *wl);
35833 void (*enable_irq)(struct wl1251 *wl);
35834 void (*disable_irq)(struct wl1251 *wl);
35835 -};
35836 +} __no_const;
35837
35838 struct wl1251 {
35839 struct ieee80211_hw *hw;
35840 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35841 index f34b5b2..b5abb9f 100644
35842 --- a/drivers/oprofile/buffer_sync.c
35843 +++ b/drivers/oprofile/buffer_sync.c
35844 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35845 if (cookie == NO_COOKIE)
35846 offset = pc;
35847 if (cookie == INVALID_COOKIE) {
35848 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35849 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35850 offset = pc;
35851 }
35852 if (cookie != last_cookie) {
35853 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35854 /* add userspace sample */
35855
35856 if (!mm) {
35857 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35858 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35859 return 0;
35860 }
35861
35862 cookie = lookup_dcookie(mm, s->eip, &offset);
35863
35864 if (cookie == INVALID_COOKIE) {
35865 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35866 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35867 return 0;
35868 }
35869
35870 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35871 /* ignore backtraces if failed to add a sample */
35872 if (state == sb_bt_start) {
35873 state = sb_bt_ignore;
35874 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35875 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35876 }
35877 }
35878 release_mm(mm);
35879 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35880 index c0cc4e7..44d4e54 100644
35881 --- a/drivers/oprofile/event_buffer.c
35882 +++ b/drivers/oprofile/event_buffer.c
35883 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35884 }
35885
35886 if (buffer_pos == buffer_size) {
35887 - atomic_inc(&oprofile_stats.event_lost_overflow);
35888 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35889 return;
35890 }
35891
35892 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35893 index ed2c3ec..deda85a 100644
35894 --- a/drivers/oprofile/oprof.c
35895 +++ b/drivers/oprofile/oprof.c
35896 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35897 if (oprofile_ops.switch_events())
35898 return;
35899
35900 - atomic_inc(&oprofile_stats.multiplex_counter);
35901 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35902 start_switch_worker();
35903 }
35904
35905 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
35906 index 84a208d..f07d177 100644
35907 --- a/drivers/oprofile/oprofile_files.c
35908 +++ b/drivers/oprofile/oprofile_files.c
35909 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
35910
35911
35912 static ssize_t timeout_write(struct file *file, char const __user *buf,
35913 + size_t count, loff_t *offset) __size_overflow(3);
35914 +static ssize_t timeout_write(struct file *file, char const __user *buf,
35915 size_t count, loff_t *offset)
35916 {
35917 unsigned long val;
35918 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
35919 }
35920
35921
35922 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35923 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35924 {
35925 unsigned long val;
35926 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
35927 };
35928
35929
35930 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35931 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
35932 {
35933 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
35934 }
35935
35936
35937 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35938 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35939 {
35940 unsigned long val;
35941 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35942 index 917d28e..d62d981 100644
35943 --- a/drivers/oprofile/oprofile_stats.c
35944 +++ b/drivers/oprofile/oprofile_stats.c
35945 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35946 cpu_buf->sample_invalid_eip = 0;
35947 }
35948
35949 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35950 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35951 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35952 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35953 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35954 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35955 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35956 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35957 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35958 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35959 }
35960
35961
35962 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35963 index 38b6fc0..b5cbfce 100644
35964 --- a/drivers/oprofile/oprofile_stats.h
35965 +++ b/drivers/oprofile/oprofile_stats.h
35966 @@ -13,11 +13,11 @@
35967 #include <linux/atomic.h>
35968
35969 struct oprofile_stat_struct {
35970 - atomic_t sample_lost_no_mm;
35971 - atomic_t sample_lost_no_mapping;
35972 - atomic_t bt_lost_no_mapping;
35973 - atomic_t event_lost_overflow;
35974 - atomic_t multiplex_counter;
35975 + atomic_unchecked_t sample_lost_no_mm;
35976 + atomic_unchecked_t sample_lost_no_mapping;
35977 + atomic_unchecked_t bt_lost_no_mapping;
35978 + atomic_unchecked_t event_lost_overflow;
35979 + atomic_unchecked_t multiplex_counter;
35980 };
35981
35982 extern struct oprofile_stat_struct oprofile_stats;
35983 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35984 index 2f0aa0f..d5246c3 100644
35985 --- a/drivers/oprofile/oprofilefs.c
35986 +++ b/drivers/oprofile/oprofilefs.c
35987 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
35988 }
35989
35990
35991 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35992 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35993 {
35994 unsigned long value;
35995 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
35996
35997
35998 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35999 - char const *name, atomic_t *val)
36000 + char const *name, atomic_unchecked_t *val)
36001 {
36002 return __oprofilefs_create_file(sb, root, name,
36003 &atomic_ro_fops, 0444, val);
36004 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36005 index 3f56bc0..707d642 100644
36006 --- a/drivers/parport/procfs.c
36007 +++ b/drivers/parport/procfs.c
36008 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36009
36010 *ppos += len;
36011
36012 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36013 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36014 }
36015
36016 #ifdef CONFIG_PARPORT_1284
36017 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36018
36019 *ppos += len;
36020
36021 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36022 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36023 }
36024 #endif /* IEEE1284.3 support. */
36025
36026 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36027 index 9fff878..ad0ad53 100644
36028 --- a/drivers/pci/hotplug/cpci_hotplug.h
36029 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36030 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36031 int (*hardware_test) (struct slot* slot, u32 value);
36032 u8 (*get_power) (struct slot* slot);
36033 int (*set_power) (struct slot* slot, int value);
36034 -};
36035 +} __no_const;
36036
36037 struct cpci_hp_controller {
36038 unsigned int irq;
36039 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36040 index 76ba8a1..20ca857 100644
36041 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36042 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36043 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36044
36045 void compaq_nvram_init (void __iomem *rom_start)
36046 {
36047 +
36048 +#ifndef CONFIG_PAX_KERNEXEC
36049 if (rom_start) {
36050 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36051 }
36052 +#endif
36053 +
36054 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36055
36056 /* initialize our int15 lock */
36057 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36058 index 2275162..95f1a92 100644
36059 --- a/drivers/pci/pcie/aspm.c
36060 +++ b/drivers/pci/pcie/aspm.c
36061 @@ -27,9 +27,9 @@
36062 #define MODULE_PARAM_PREFIX "pcie_aspm."
36063
36064 /* Note: those are not register definitions */
36065 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36066 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36067 -#define ASPM_STATE_L1 (4) /* L1 state */
36068 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36069 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36070 +#define ASPM_STATE_L1 (4U) /* L1 state */
36071 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36072 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36073
36074 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36075 index 71eac9c..2de27ef 100644
36076 --- a/drivers/pci/probe.c
36077 +++ b/drivers/pci/probe.c
36078 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36079 u32 l, sz, mask;
36080 u16 orig_cmd;
36081
36082 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36083 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36084
36085 if (!dev->mmio_always_on) {
36086 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36087 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36088 index 27911b5..5b6db88 100644
36089 --- a/drivers/pci/proc.c
36090 +++ b/drivers/pci/proc.c
36091 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36092 static int __init pci_proc_init(void)
36093 {
36094 struct pci_dev *dev = NULL;
36095 +
36096 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36097 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36098 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36099 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36100 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36101 +#endif
36102 +#else
36103 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36104 +#endif
36105 proc_create("devices", 0, proc_bus_pci_dir,
36106 &proc_bus_pci_dev_operations);
36107 proc_initialized = 1;
36108 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36109 index 6f966d6..68e18ed 100644
36110 --- a/drivers/platform/x86/asus_acpi.c
36111 +++ b/drivers/platform/x86/asus_acpi.c
36112 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36113 }
36114
36115 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36116 + size_t count, loff_t *pos) __size_overflow(3);
36117 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36118 size_t count, loff_t *pos)
36119 {
36120 int rv, value;
36121 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36122 index ea0c607..58c4628 100644
36123 --- a/drivers/platform/x86/thinkpad_acpi.c
36124 +++ b/drivers/platform/x86/thinkpad_acpi.c
36125 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36126 return 0;
36127 }
36128
36129 -void static hotkey_mask_warn_incomplete_mask(void)
36130 +static void hotkey_mask_warn_incomplete_mask(void)
36131 {
36132 /* log only what the user can fix... */
36133 const u32 wantedmask = hotkey_driver_mask &
36134 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36135 }
36136 }
36137
36138 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36139 - struct tp_nvram_state *newn,
36140 - const u32 event_mask)
36141 -{
36142 -
36143 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36144 do { \
36145 if ((event_mask & (1 << __scancode)) && \
36146 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36147 tpacpi_hotkey_send_key(__scancode); \
36148 } while (0)
36149
36150 - void issue_volchange(const unsigned int oldvol,
36151 - const unsigned int newvol)
36152 - {
36153 - unsigned int i = oldvol;
36154 +static void issue_volchange(const unsigned int oldvol,
36155 + const unsigned int newvol,
36156 + const u32 event_mask)
36157 +{
36158 + unsigned int i = oldvol;
36159
36160 - while (i > newvol) {
36161 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36162 - i--;
36163 - }
36164 - while (i < newvol) {
36165 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36166 - i++;
36167 - }
36168 + while (i > newvol) {
36169 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36170 + i--;
36171 }
36172 + while (i < newvol) {
36173 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36174 + i++;
36175 + }
36176 +}
36177
36178 - void issue_brightnesschange(const unsigned int oldbrt,
36179 - const unsigned int newbrt)
36180 - {
36181 - unsigned int i = oldbrt;
36182 +static void issue_brightnesschange(const unsigned int oldbrt,
36183 + const unsigned int newbrt,
36184 + const u32 event_mask)
36185 +{
36186 + unsigned int i = oldbrt;
36187
36188 - while (i > newbrt) {
36189 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36190 - i--;
36191 - }
36192 - while (i < newbrt) {
36193 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36194 - i++;
36195 - }
36196 + while (i > newbrt) {
36197 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36198 + i--;
36199 + }
36200 + while (i < newbrt) {
36201 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36202 + i++;
36203 }
36204 +}
36205
36206 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36207 + struct tp_nvram_state *newn,
36208 + const u32 event_mask)
36209 +{
36210 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36211 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36212 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36213 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36214 oldn->volume_level != newn->volume_level) {
36215 /* recently muted, or repeated mute keypress, or
36216 * multiple presses ending in mute */
36217 - issue_volchange(oldn->volume_level, newn->volume_level);
36218 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36219 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36220 }
36221 } else {
36222 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36223 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36224 }
36225 if (oldn->volume_level != newn->volume_level) {
36226 - issue_volchange(oldn->volume_level, newn->volume_level);
36227 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36228 } else if (oldn->volume_toggle != newn->volume_toggle) {
36229 /* repeated vol up/down keypress at end of scale ? */
36230 if (newn->volume_level == 0)
36231 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36232 /* handle brightness */
36233 if (oldn->brightness_level != newn->brightness_level) {
36234 issue_brightnesschange(oldn->brightness_level,
36235 - newn->brightness_level);
36236 + newn->brightness_level,
36237 + event_mask);
36238 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36239 /* repeated key presses that didn't change state */
36240 if (newn->brightness_level == 0)
36241 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36242 && !tp_features.bright_unkfw)
36243 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36244 }
36245 +}
36246
36247 #undef TPACPI_COMPARE_KEY
36248 #undef TPACPI_MAY_SEND_KEY
36249 -}
36250
36251 /*
36252 * Polling driver
36253 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36254 index dcdc1f4..85cee16 100644
36255 --- a/drivers/platform/x86/toshiba_acpi.c
36256 +++ b/drivers/platform/x86/toshiba_acpi.c
36257 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36258 }
36259
36260 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36261 + size_t count, loff_t *pos) __size_overflow(3);
36262 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36263 size_t count, loff_t *pos)
36264 {
36265 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36266 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36267 index b859d16..5cc6b1a 100644
36268 --- a/drivers/pnp/pnpbios/bioscalls.c
36269 +++ b/drivers/pnp/pnpbios/bioscalls.c
36270 @@ -59,7 +59,7 @@ do { \
36271 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36272 } while(0)
36273
36274 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36275 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36276 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36277
36278 /*
36279 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36280
36281 cpu = get_cpu();
36282 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36283 +
36284 + pax_open_kernel();
36285 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36286 + pax_close_kernel();
36287
36288 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36289 spin_lock_irqsave(&pnp_bios_lock, flags);
36290 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36291 :"memory");
36292 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36293
36294 + pax_open_kernel();
36295 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36296 + pax_close_kernel();
36297 +
36298 put_cpu();
36299
36300 /* If we get here and this is set then the PnP BIOS faulted on us. */
36301 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36302 return status;
36303 }
36304
36305 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36306 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36307 {
36308 int i;
36309
36310 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36311 pnp_bios_callpoint.offset = header->fields.pm16offset;
36312 pnp_bios_callpoint.segment = PNP_CS16;
36313
36314 + pax_open_kernel();
36315 +
36316 for_each_possible_cpu(i) {
36317 struct desc_struct *gdt = get_cpu_gdt_table(i);
36318 if (!gdt)
36319 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36320 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36321 (unsigned long)__va(header->fields.pm16dseg));
36322 }
36323 +
36324 + pax_close_kernel();
36325 }
36326 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36327 index b0ecacb..7c9da2e 100644
36328 --- a/drivers/pnp/resource.c
36329 +++ b/drivers/pnp/resource.c
36330 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36331 return 1;
36332
36333 /* check if the resource is valid */
36334 - if (*irq < 0 || *irq > 15)
36335 + if (*irq > 15)
36336 return 0;
36337
36338 /* check if the resource is reserved */
36339 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36340 return 1;
36341
36342 /* check if the resource is valid */
36343 - if (*dma < 0 || *dma == 4 || *dma > 7)
36344 + if (*dma == 4 || *dma > 7)
36345 return 0;
36346
36347 /* check if the resource is reserved */
36348 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36349 index 1ed6ea0..77c0bd2 100644
36350 --- a/drivers/power/bq27x00_battery.c
36351 +++ b/drivers/power/bq27x00_battery.c
36352 @@ -72,7 +72,7 @@
36353 struct bq27x00_device_info;
36354 struct bq27x00_access_methods {
36355 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36356 -};
36357 +} __no_const;
36358
36359 enum bq27x00_chip { BQ27000, BQ27500 };
36360
36361 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36362 index a838e66..a9e1665 100644
36363 --- a/drivers/regulator/max8660.c
36364 +++ b/drivers/regulator/max8660.c
36365 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36366 max8660->shadow_regs[MAX8660_OVER1] = 5;
36367 } else {
36368 /* Otherwise devices can be toggled via software */
36369 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36370 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36371 + pax_open_kernel();
36372 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36373 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36374 + pax_close_kernel();
36375 }
36376
36377 /*
36378 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36379 index e8cfc99..072aee2 100644
36380 --- a/drivers/regulator/mc13892-regulator.c
36381 +++ b/drivers/regulator/mc13892-regulator.c
36382 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36383 }
36384 mc13xxx_unlock(mc13892);
36385
36386 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36387 + pax_open_kernel();
36388 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36389 = mc13892_vcam_set_mode;
36390 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36391 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36392 = mc13892_vcam_get_mode;
36393 + pax_close_kernel();
36394
36395 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36396 ARRAY_SIZE(mc13892_regulators));
36397 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36398 index cace6d3..f623fda 100644
36399 --- a/drivers/rtc/rtc-dev.c
36400 +++ b/drivers/rtc/rtc-dev.c
36401 @@ -14,6 +14,7 @@
36402 #include <linux/module.h>
36403 #include <linux/rtc.h>
36404 #include <linux/sched.h>
36405 +#include <linux/grsecurity.h>
36406 #include "rtc-core.h"
36407
36408 static dev_t rtc_devt;
36409 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36410 if (copy_from_user(&tm, uarg, sizeof(tm)))
36411 return -EFAULT;
36412
36413 + gr_log_timechange();
36414 +
36415 return rtc_set_time(rtc, &tm);
36416
36417 case RTC_PIE_ON:
36418 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36419 index ffb5878..e6d785c 100644
36420 --- a/drivers/scsi/aacraid/aacraid.h
36421 +++ b/drivers/scsi/aacraid/aacraid.h
36422 @@ -492,7 +492,7 @@ struct adapter_ops
36423 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36424 /* Administrative operations */
36425 int (*adapter_comm)(struct aac_dev * dev, int comm);
36426 -};
36427 +} __no_const;
36428
36429 /*
36430 * Define which interrupt handler needs to be installed
36431 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36432 index 705e13e..91c873c 100644
36433 --- a/drivers/scsi/aacraid/linit.c
36434 +++ b/drivers/scsi/aacraid/linit.c
36435 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36436 #elif defined(__devinitconst)
36437 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36438 #else
36439 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36440 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36441 #endif
36442 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36443 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36444 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36445 index d5ff142..49c0ebb 100644
36446 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36447 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36448 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36449 .lldd_control_phy = asd_control_phy,
36450 };
36451
36452 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36453 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36454 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36455 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36456 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36457 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36458 index a796de9..1ef20e1 100644
36459 --- a/drivers/scsi/bfa/bfa.h
36460 +++ b/drivers/scsi/bfa/bfa.h
36461 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36462 u32 *end);
36463 int cpe_vec_q0;
36464 int rme_vec_q0;
36465 -};
36466 +} __no_const;
36467 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36468
36469 struct bfa_faa_cbfn_s {
36470 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36471 index f0f80e2..8ec946b 100644
36472 --- a/drivers/scsi/bfa/bfa_fcpim.c
36473 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36474 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36475
36476 bfa_iotag_attach(fcp);
36477
36478 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36479 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36480 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36481 (fcp->num_itns * sizeof(struct bfa_itn_s));
36482 memset(fcp->itn_arr, 0,
36483 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36484 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36485 {
36486 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36487 - struct bfa_itn_s *itn;
36488 + bfa_itn_s_no_const *itn;
36489
36490 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36491 itn->isr = isr;
36492 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36493 index 36f26da..38a34a8 100644
36494 --- a/drivers/scsi/bfa/bfa_fcpim.h
36495 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36496 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36497 struct bfa_itn_s {
36498 bfa_isr_func_t isr;
36499 };
36500 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36501
36502 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36503 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36504 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36505 struct list_head iotag_tio_free_q; /* free IO resources */
36506 struct list_head iotag_unused_q; /* unused IO resources*/
36507 struct bfa_iotag_s *iotag_arr;
36508 - struct bfa_itn_s *itn_arr;
36509 + bfa_itn_s_no_const *itn_arr;
36510 int num_ioim_reqs;
36511 int num_fwtio_reqs;
36512 int num_itns;
36513 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36514 index 546d46b..642fa5b 100644
36515 --- a/drivers/scsi/bfa/bfa_ioc.h
36516 +++ b/drivers/scsi/bfa/bfa_ioc.h
36517 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36518 bfa_ioc_disable_cbfn_t disable_cbfn;
36519 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36520 bfa_ioc_reset_cbfn_t reset_cbfn;
36521 -};
36522 +} __no_const;
36523
36524 /*
36525 * IOC event notification mechanism.
36526 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36527 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36528 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36529 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36530 -};
36531 +} __no_const;
36532
36533 /*
36534 * Queue element to wait for room in request queue. FIFO order is
36535 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36536 index 351dc0b..951dc32 100644
36537 --- a/drivers/scsi/hosts.c
36538 +++ b/drivers/scsi/hosts.c
36539 @@ -42,7 +42,7 @@
36540 #include "scsi_logging.h"
36541
36542
36543 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36544 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36545
36546
36547 static void scsi_host_cls_release(struct device *dev)
36548 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36549 * subtract one because we increment first then return, but we need to
36550 * know what the next host number was before increment
36551 */
36552 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36553 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36554 shost->dma_channel = 0xff;
36555
36556 /* These three are default values which can be overridden */
36557 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36558 index b96962c..0c82ec2 100644
36559 --- a/drivers/scsi/hpsa.c
36560 +++ b/drivers/scsi/hpsa.c
36561 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36562 u32 a;
36563
36564 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36565 - return h->access.command_completed(h);
36566 + return h->access->command_completed(h);
36567
36568 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36569 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36570 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36571 while (!list_empty(&h->reqQ)) {
36572 c = list_entry(h->reqQ.next, struct CommandList, list);
36573 /* can't do anything if fifo is full */
36574 - if ((h->access.fifo_full(h))) {
36575 + if ((h->access->fifo_full(h))) {
36576 dev_warn(&h->pdev->dev, "fifo full\n");
36577 break;
36578 }
36579 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36580 h->Qdepth--;
36581
36582 /* Tell the controller execute command */
36583 - h->access.submit_command(h, c);
36584 + h->access->submit_command(h, c);
36585
36586 /* Put job onto the completed Q */
36587 addQ(&h->cmpQ, c);
36588 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36589
36590 static inline unsigned long get_next_completion(struct ctlr_info *h)
36591 {
36592 - return h->access.command_completed(h);
36593 + return h->access->command_completed(h);
36594 }
36595
36596 static inline bool interrupt_pending(struct ctlr_info *h)
36597 {
36598 - return h->access.intr_pending(h);
36599 + return h->access->intr_pending(h);
36600 }
36601
36602 static inline long interrupt_not_for_us(struct ctlr_info *h)
36603 {
36604 - return (h->access.intr_pending(h) == 0) ||
36605 + return (h->access->intr_pending(h) == 0) ||
36606 (h->interrupts_enabled == 0);
36607 }
36608
36609 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36610 if (prod_index < 0)
36611 return -ENODEV;
36612 h->product_name = products[prod_index].product_name;
36613 - h->access = *(products[prod_index].access);
36614 + h->access = products[prod_index].access;
36615
36616 if (hpsa_board_disabled(h->pdev)) {
36617 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36618 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36619
36620 assert_spin_locked(&lockup_detector_lock);
36621 remove_ctlr_from_lockup_detector_list(h);
36622 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36623 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36624 spin_lock_irqsave(&h->lock, flags);
36625 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36626 spin_unlock_irqrestore(&h->lock, flags);
36627 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36628 }
36629
36630 /* make sure the board interrupts are off */
36631 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36632 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36633
36634 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36635 goto clean2;
36636 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36637 * fake ones to scoop up any residual completions.
36638 */
36639 spin_lock_irqsave(&h->lock, flags);
36640 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36641 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36642 spin_unlock_irqrestore(&h->lock, flags);
36643 free_irq(h->intr[h->intr_mode], h);
36644 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36645 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36646 dev_info(&h->pdev->dev, "Board READY.\n");
36647 dev_info(&h->pdev->dev,
36648 "Waiting for stale completions to drain.\n");
36649 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36650 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36651 msleep(10000);
36652 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36653 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36654
36655 rc = controller_reset_failed(h->cfgtable);
36656 if (rc)
36657 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36658 }
36659
36660 /* Turn the interrupts on so we can service requests */
36661 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36662 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36663
36664 hpsa_hba_inquiry(h);
36665 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36666 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36667 * To write all data in the battery backed cache to disks
36668 */
36669 hpsa_flush_cache(h);
36670 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36671 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36672 free_irq(h->intr[h->intr_mode], h);
36673 #ifdef CONFIG_PCI_MSI
36674 if (h->msix_vector)
36675 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36676 return;
36677 }
36678 /* Change the access methods to the performant access methods */
36679 - h->access = SA5_performant_access;
36680 + h->access = &SA5_performant_access;
36681 h->transMethod = CFGTBL_Trans_Performant;
36682 }
36683
36684 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36685 index 91edafb..a9b88ec 100644
36686 --- a/drivers/scsi/hpsa.h
36687 +++ b/drivers/scsi/hpsa.h
36688 @@ -73,7 +73,7 @@ struct ctlr_info {
36689 unsigned int msix_vector;
36690 unsigned int msi_vector;
36691 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36692 - struct access_method access;
36693 + struct access_method *access;
36694
36695 /* queue and queue Info */
36696 struct list_head reqQ;
36697 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36698 index f2df059..a3a9930 100644
36699 --- a/drivers/scsi/ips.h
36700 +++ b/drivers/scsi/ips.h
36701 @@ -1027,7 +1027,7 @@ typedef struct {
36702 int (*intr)(struct ips_ha *);
36703 void (*enableint)(struct ips_ha *);
36704 uint32_t (*statupd)(struct ips_ha *);
36705 -} ips_hw_func_t;
36706 +} __no_const ips_hw_func_t;
36707
36708 typedef struct ips_ha {
36709 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36710 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36711 index 4d70d96..84d0573 100644
36712 --- a/drivers/scsi/libfc/fc_exch.c
36713 +++ b/drivers/scsi/libfc/fc_exch.c
36714 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36715 * all together if not used XXX
36716 */
36717 struct {
36718 - atomic_t no_free_exch;
36719 - atomic_t no_free_exch_xid;
36720 - atomic_t xid_not_found;
36721 - atomic_t xid_busy;
36722 - atomic_t seq_not_found;
36723 - atomic_t non_bls_resp;
36724 + atomic_unchecked_t no_free_exch;
36725 + atomic_unchecked_t no_free_exch_xid;
36726 + atomic_unchecked_t xid_not_found;
36727 + atomic_unchecked_t xid_busy;
36728 + atomic_unchecked_t seq_not_found;
36729 + atomic_unchecked_t non_bls_resp;
36730 } stats;
36731 };
36732
36733 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36734 /* allocate memory for exchange */
36735 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36736 if (!ep) {
36737 - atomic_inc(&mp->stats.no_free_exch);
36738 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36739 goto out;
36740 }
36741 memset(ep, 0, sizeof(*ep));
36742 @@ -780,7 +780,7 @@ out:
36743 return ep;
36744 err:
36745 spin_unlock_bh(&pool->lock);
36746 - atomic_inc(&mp->stats.no_free_exch_xid);
36747 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36748 mempool_free(ep, mp->ep_pool);
36749 return NULL;
36750 }
36751 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36752 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36753 ep = fc_exch_find(mp, xid);
36754 if (!ep) {
36755 - atomic_inc(&mp->stats.xid_not_found);
36756 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36757 reject = FC_RJT_OX_ID;
36758 goto out;
36759 }
36760 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36761 ep = fc_exch_find(mp, xid);
36762 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36763 if (ep) {
36764 - atomic_inc(&mp->stats.xid_busy);
36765 + atomic_inc_unchecked(&mp->stats.xid_busy);
36766 reject = FC_RJT_RX_ID;
36767 goto rel;
36768 }
36769 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36770 }
36771 xid = ep->xid; /* get our XID */
36772 } else if (!ep) {
36773 - atomic_inc(&mp->stats.xid_not_found);
36774 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36775 reject = FC_RJT_RX_ID; /* XID not found */
36776 goto out;
36777 }
36778 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36779 } else {
36780 sp = &ep->seq;
36781 if (sp->id != fh->fh_seq_id) {
36782 - atomic_inc(&mp->stats.seq_not_found);
36783 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36784 if (f_ctl & FC_FC_END_SEQ) {
36785 /*
36786 * Update sequence_id based on incoming last
36787 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36788
36789 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36790 if (!ep) {
36791 - atomic_inc(&mp->stats.xid_not_found);
36792 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36793 goto out;
36794 }
36795 if (ep->esb_stat & ESB_ST_COMPLETE) {
36796 - atomic_inc(&mp->stats.xid_not_found);
36797 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36798 goto rel;
36799 }
36800 if (ep->rxid == FC_XID_UNKNOWN)
36801 ep->rxid = ntohs(fh->fh_rx_id);
36802 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36803 - atomic_inc(&mp->stats.xid_not_found);
36804 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36805 goto rel;
36806 }
36807 if (ep->did != ntoh24(fh->fh_s_id) &&
36808 ep->did != FC_FID_FLOGI) {
36809 - atomic_inc(&mp->stats.xid_not_found);
36810 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36811 goto rel;
36812 }
36813 sof = fr_sof(fp);
36814 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36815 sp->ssb_stat |= SSB_ST_RESP;
36816 sp->id = fh->fh_seq_id;
36817 } else if (sp->id != fh->fh_seq_id) {
36818 - atomic_inc(&mp->stats.seq_not_found);
36819 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36820 goto rel;
36821 }
36822
36823 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36824 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36825
36826 if (!sp)
36827 - atomic_inc(&mp->stats.xid_not_found);
36828 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36829 else
36830 - atomic_inc(&mp->stats.non_bls_resp);
36831 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36832
36833 fc_frame_free(fp);
36834 }
36835 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36836 index db9238f..4378ed2 100644
36837 --- a/drivers/scsi/libsas/sas_ata.c
36838 +++ b/drivers/scsi/libsas/sas_ata.c
36839 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36840 .postreset = ata_std_postreset,
36841 .error_handler = ata_std_error_handler,
36842 .post_internal_cmd = sas_ata_post_internal,
36843 - .qc_defer = ata_std_qc_defer,
36844 + .qc_defer = ata_std_qc_defer,
36845 .qc_prep = ata_noop_qc_prep,
36846 .qc_issue = sas_ata_qc_issue,
36847 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36848 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36849 index 825f930..ce42672 100644
36850 --- a/drivers/scsi/lpfc/lpfc.h
36851 +++ b/drivers/scsi/lpfc/lpfc.h
36852 @@ -413,7 +413,7 @@ struct lpfc_vport {
36853 struct dentry *debug_nodelist;
36854 struct dentry *vport_debugfs_root;
36855 struct lpfc_debugfs_trc *disc_trc;
36856 - atomic_t disc_trc_cnt;
36857 + atomic_unchecked_t disc_trc_cnt;
36858 #endif
36859 uint8_t stat_data_enabled;
36860 uint8_t stat_data_blocked;
36861 @@ -821,8 +821,8 @@ struct lpfc_hba {
36862 struct timer_list fabric_block_timer;
36863 unsigned long bit_flags;
36864 #define FABRIC_COMANDS_BLOCKED 0
36865 - atomic_t num_rsrc_err;
36866 - atomic_t num_cmd_success;
36867 + atomic_unchecked_t num_rsrc_err;
36868 + atomic_unchecked_t num_cmd_success;
36869 unsigned long last_rsrc_error_time;
36870 unsigned long last_ramp_down_time;
36871 unsigned long last_ramp_up_time;
36872 @@ -852,7 +852,7 @@ struct lpfc_hba {
36873
36874 struct dentry *debug_slow_ring_trc;
36875 struct lpfc_debugfs_trc *slow_ring_trc;
36876 - atomic_t slow_ring_trc_cnt;
36877 + atomic_unchecked_t slow_ring_trc_cnt;
36878 /* iDiag debugfs sub-directory */
36879 struct dentry *idiag_root;
36880 struct dentry *idiag_pci_cfg;
36881 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36882 index 3587a3f..d45b81b 100644
36883 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36884 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36885 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36886
36887 #include <linux/debugfs.h>
36888
36889 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36890 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36891 static unsigned long lpfc_debugfs_start_time = 0L;
36892
36893 /* iDiag */
36894 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36895 lpfc_debugfs_enable = 0;
36896
36897 len = 0;
36898 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36899 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36900 (lpfc_debugfs_max_disc_trc - 1);
36901 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36902 dtp = vport->disc_trc + i;
36903 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36904 lpfc_debugfs_enable = 0;
36905
36906 len = 0;
36907 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36908 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36909 (lpfc_debugfs_max_slow_ring_trc - 1);
36910 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36911 dtp = phba->slow_ring_trc + i;
36912 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36913 !vport || !vport->disc_trc)
36914 return;
36915
36916 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36917 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36918 (lpfc_debugfs_max_disc_trc - 1);
36919 dtp = vport->disc_trc + index;
36920 dtp->fmt = fmt;
36921 dtp->data1 = data1;
36922 dtp->data2 = data2;
36923 dtp->data3 = data3;
36924 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36925 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36926 dtp->jif = jiffies;
36927 #endif
36928 return;
36929 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36930 !phba || !phba->slow_ring_trc)
36931 return;
36932
36933 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36934 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36935 (lpfc_debugfs_max_slow_ring_trc - 1);
36936 dtp = phba->slow_ring_trc + index;
36937 dtp->fmt = fmt;
36938 dtp->data1 = data1;
36939 dtp->data2 = data2;
36940 dtp->data3 = data3;
36941 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36942 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36943 dtp->jif = jiffies;
36944 #endif
36945 return;
36946 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36947 "slow_ring buffer\n");
36948 goto debug_failed;
36949 }
36950 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36951 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36952 memset(phba->slow_ring_trc, 0,
36953 (sizeof(struct lpfc_debugfs_trc) *
36954 lpfc_debugfs_max_slow_ring_trc));
36955 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36956 "buffer\n");
36957 goto debug_failed;
36958 }
36959 - atomic_set(&vport->disc_trc_cnt, 0);
36960 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36961
36962 snprintf(name, sizeof(name), "discovery_trace");
36963 vport->debug_disc_trc =
36964 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36965 index dfea2da..8e17227 100644
36966 --- a/drivers/scsi/lpfc/lpfc_init.c
36967 +++ b/drivers/scsi/lpfc/lpfc_init.c
36968 @@ -10145,8 +10145,10 @@ lpfc_init(void)
36969 printk(LPFC_COPYRIGHT "\n");
36970
36971 if (lpfc_enable_npiv) {
36972 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36973 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36974 + pax_open_kernel();
36975 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36976 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36977 + pax_close_kernel();
36978 }
36979 lpfc_transport_template =
36980 fc_attach_transport(&lpfc_transport_functions);
36981 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36982 index c60f5d0..751535c 100644
36983 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36984 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36985 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36986 uint32_t evt_posted;
36987
36988 spin_lock_irqsave(&phba->hbalock, flags);
36989 - atomic_inc(&phba->num_rsrc_err);
36990 + atomic_inc_unchecked(&phba->num_rsrc_err);
36991 phba->last_rsrc_error_time = jiffies;
36992
36993 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36994 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36995 unsigned long flags;
36996 struct lpfc_hba *phba = vport->phba;
36997 uint32_t evt_posted;
36998 - atomic_inc(&phba->num_cmd_success);
36999 + atomic_inc_unchecked(&phba->num_cmd_success);
37000
37001 if (vport->cfg_lun_queue_depth <= queue_depth)
37002 return;
37003 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37004 unsigned long num_rsrc_err, num_cmd_success;
37005 int i;
37006
37007 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37008 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37009 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37010 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37011
37012 vports = lpfc_create_vport_work_array(phba);
37013 if (vports != NULL)
37014 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37015 }
37016 }
37017 lpfc_destroy_vport_work_array(phba, vports);
37018 - atomic_set(&phba->num_rsrc_err, 0);
37019 - atomic_set(&phba->num_cmd_success, 0);
37020 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37021 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37022 }
37023
37024 /**
37025 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37026 }
37027 }
37028 lpfc_destroy_vport_work_array(phba, vports);
37029 - atomic_set(&phba->num_rsrc_err, 0);
37030 - atomic_set(&phba->num_cmd_success, 0);
37031 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37032 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37033 }
37034
37035 /**
37036 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37037 index ea8a0b4..812a124 100644
37038 --- a/drivers/scsi/pmcraid.c
37039 +++ b/drivers/scsi/pmcraid.c
37040 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37041 res->scsi_dev = scsi_dev;
37042 scsi_dev->hostdata = res;
37043 res->change_detected = 0;
37044 - atomic_set(&res->read_failures, 0);
37045 - atomic_set(&res->write_failures, 0);
37046 + atomic_set_unchecked(&res->read_failures, 0);
37047 + atomic_set_unchecked(&res->write_failures, 0);
37048 rc = 0;
37049 }
37050 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37051 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37052
37053 /* If this was a SCSI read/write command keep count of errors */
37054 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37055 - atomic_inc(&res->read_failures);
37056 + atomic_inc_unchecked(&res->read_failures);
37057 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37058 - atomic_inc(&res->write_failures);
37059 + atomic_inc_unchecked(&res->write_failures);
37060
37061 if (!RES_IS_GSCSI(res->cfg_entry) &&
37062 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37063 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37064 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37065 * hrrq_id assigned here in queuecommand
37066 */
37067 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37068 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37069 pinstance->num_hrrq;
37070 cmd->cmd_done = pmcraid_io_done;
37071
37072 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37073 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37074 * hrrq_id assigned here in queuecommand
37075 */
37076 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37077 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37078 pinstance->num_hrrq;
37079
37080 if (request_size) {
37081 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37082
37083 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37084 /* add resources only after host is added into system */
37085 - if (!atomic_read(&pinstance->expose_resources))
37086 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37087 return;
37088
37089 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37090 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37091 init_waitqueue_head(&pinstance->reset_wait_q);
37092
37093 atomic_set(&pinstance->outstanding_cmds, 0);
37094 - atomic_set(&pinstance->last_message_id, 0);
37095 - atomic_set(&pinstance->expose_resources, 0);
37096 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37097 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37098
37099 INIT_LIST_HEAD(&pinstance->free_res_q);
37100 INIT_LIST_HEAD(&pinstance->used_res_q);
37101 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37102 /* Schedule worker thread to handle CCN and take care of adding and
37103 * removing devices to OS
37104 */
37105 - atomic_set(&pinstance->expose_resources, 1);
37106 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37107 schedule_work(&pinstance->worker_q);
37108 return rc;
37109
37110 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37111 index ca496c7..9c791d5 100644
37112 --- a/drivers/scsi/pmcraid.h
37113 +++ b/drivers/scsi/pmcraid.h
37114 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37115 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37116
37117 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37118 - atomic_t last_message_id;
37119 + atomic_unchecked_t last_message_id;
37120
37121 /* configuration table */
37122 struct pmcraid_config_table *cfg_table;
37123 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37124 atomic_t outstanding_cmds;
37125
37126 /* should add/delete resources to mid-layer now ?*/
37127 - atomic_t expose_resources;
37128 + atomic_unchecked_t expose_resources;
37129
37130
37131
37132 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37133 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37134 };
37135 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37136 - atomic_t read_failures; /* count of failed READ commands */
37137 - atomic_t write_failures; /* count of failed WRITE commands */
37138 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37139 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37140
37141 /* To indicate add/delete/modify during CCN */
37142 u8 change_detected;
37143 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37144 index af1003f..be55a75 100644
37145 --- a/drivers/scsi/qla2xxx/qla_def.h
37146 +++ b/drivers/scsi/qla2xxx/qla_def.h
37147 @@ -2247,7 +2247,7 @@ struct isp_operations {
37148 int (*start_scsi) (srb_t *);
37149 int (*abort_isp) (struct scsi_qla_host *);
37150 int (*iospace_config)(struct qla_hw_data*);
37151 -};
37152 +} __no_const;
37153
37154 /* MSI-X Support *************************************************************/
37155
37156 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37157 index bfe6854..ceac088 100644
37158 --- a/drivers/scsi/qla4xxx/ql4_def.h
37159 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37160 @@ -261,7 +261,7 @@ struct ddb_entry {
37161 * (4000 only) */
37162 atomic_t relogin_timer; /* Max Time to wait for
37163 * relogin to complete */
37164 - atomic_t relogin_retry_count; /* Num of times relogin has been
37165 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37166 * retried */
37167 uint32_t default_time2wait; /* Default Min time between
37168 * relogins (+aens) */
37169 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37170 index ce6d3b7..73fac54 100644
37171 --- a/drivers/scsi/qla4xxx/ql4_os.c
37172 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37173 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37174 */
37175 if (!iscsi_is_session_online(cls_sess)) {
37176 /* Reset retry relogin timer */
37177 - atomic_inc(&ddb_entry->relogin_retry_count);
37178 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37179 DEBUG2(ql4_printk(KERN_INFO, ha,
37180 "%s: index[%d] relogin timed out-retrying"
37181 " relogin (%d), retry (%d)\n", __func__,
37182 ddb_entry->fw_ddb_index,
37183 - atomic_read(&ddb_entry->relogin_retry_count),
37184 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37185 ddb_entry->default_time2wait + 4));
37186 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37187 atomic_set(&ddb_entry->retry_relogin_timer,
37188 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37189
37190 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37191 atomic_set(&ddb_entry->relogin_timer, 0);
37192 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37193 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37194 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37195 ddb_entry->default_relogin_timeout =
37196 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37197 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37198 index 2aeb2e9..46e3925 100644
37199 --- a/drivers/scsi/scsi.c
37200 +++ b/drivers/scsi/scsi.c
37201 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37202 unsigned long timeout;
37203 int rtn = 0;
37204
37205 - atomic_inc(&cmd->device->iorequest_cnt);
37206 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37207
37208 /* check if the device is still usable */
37209 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37210 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37211 index b2c95db..227d74e 100644
37212 --- a/drivers/scsi/scsi_lib.c
37213 +++ b/drivers/scsi/scsi_lib.c
37214 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37215 shost = sdev->host;
37216 scsi_init_cmd_errh(cmd);
37217 cmd->result = DID_NO_CONNECT << 16;
37218 - atomic_inc(&cmd->device->iorequest_cnt);
37219 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37220
37221 /*
37222 * SCSI request completion path will do scsi_device_unbusy(),
37223 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37224
37225 INIT_LIST_HEAD(&cmd->eh_entry);
37226
37227 - atomic_inc(&cmd->device->iodone_cnt);
37228 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37229 if (cmd->result)
37230 - atomic_inc(&cmd->device->ioerr_cnt);
37231 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37232
37233 disposition = scsi_decide_disposition(cmd);
37234 if (disposition != SUCCESS &&
37235 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37236 index 04c2a27..9d8bd66 100644
37237 --- a/drivers/scsi/scsi_sysfs.c
37238 +++ b/drivers/scsi/scsi_sysfs.c
37239 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37240 char *buf) \
37241 { \
37242 struct scsi_device *sdev = to_scsi_device(dev); \
37243 - unsigned long long count = atomic_read(&sdev->field); \
37244 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37245 return snprintf(buf, 20, "0x%llx\n", count); \
37246 } \
37247 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37248 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37249 index 84a1fdf..693b0d6 100644
37250 --- a/drivers/scsi/scsi_tgt_lib.c
37251 +++ b/drivers/scsi/scsi_tgt_lib.c
37252 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37253 int err;
37254
37255 dprintk("%lx %u\n", uaddr, len);
37256 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37257 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37258 if (err) {
37259 /*
37260 * TODO: need to fixup sg_tablesize, max_segment_size,
37261 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37262 index f59d4a0..1d89407 100644
37263 --- a/drivers/scsi/scsi_transport_fc.c
37264 +++ b/drivers/scsi/scsi_transport_fc.c
37265 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37266 * Netlink Infrastructure
37267 */
37268
37269 -static atomic_t fc_event_seq;
37270 +static atomic_unchecked_t fc_event_seq;
37271
37272 /**
37273 * fc_get_event_number - Obtain the next sequential FC event number
37274 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37275 u32
37276 fc_get_event_number(void)
37277 {
37278 - return atomic_add_return(1, &fc_event_seq);
37279 + return atomic_add_return_unchecked(1, &fc_event_seq);
37280 }
37281 EXPORT_SYMBOL(fc_get_event_number);
37282
37283 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37284 {
37285 int error;
37286
37287 - atomic_set(&fc_event_seq, 0);
37288 + atomic_set_unchecked(&fc_event_seq, 0);
37289
37290 error = transport_class_register(&fc_host_class);
37291 if (error)
37292 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37293 char *cp;
37294
37295 *val = simple_strtoul(buf, &cp, 0);
37296 - if ((*cp && (*cp != '\n')) || (*val < 0))
37297 + if (*cp && (*cp != '\n'))
37298 return -EINVAL;
37299 /*
37300 * Check for overflow; dev_loss_tmo is u32
37301 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37302 index e3e3c7d..ebdab62 100644
37303 --- a/drivers/scsi/scsi_transport_iscsi.c
37304 +++ b/drivers/scsi/scsi_transport_iscsi.c
37305 @@ -79,7 +79,7 @@ struct iscsi_internal {
37306 struct transport_container session_cont;
37307 };
37308
37309 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37310 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37311 static struct workqueue_struct *iscsi_eh_timer_workq;
37312
37313 static DEFINE_IDA(iscsi_sess_ida);
37314 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37315 int err;
37316
37317 ihost = shost->shost_data;
37318 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37319 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37320
37321 if (target_id == ISCSI_MAX_TARGET) {
37322 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37323 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37324 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37325 ISCSI_TRANSPORT_VERSION);
37326
37327 - atomic_set(&iscsi_session_nr, 0);
37328 + atomic_set_unchecked(&iscsi_session_nr, 0);
37329
37330 err = class_register(&iscsi_transport_class);
37331 if (err)
37332 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37333 index 21a045e..ec89e03 100644
37334 --- a/drivers/scsi/scsi_transport_srp.c
37335 +++ b/drivers/scsi/scsi_transport_srp.c
37336 @@ -33,7 +33,7 @@
37337 #include "scsi_transport_srp_internal.h"
37338
37339 struct srp_host_attrs {
37340 - atomic_t next_port_id;
37341 + atomic_unchecked_t next_port_id;
37342 };
37343 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37344
37345 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37346 struct Scsi_Host *shost = dev_to_shost(dev);
37347 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37348
37349 - atomic_set(&srp_host->next_port_id, 0);
37350 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37351 return 0;
37352 }
37353
37354 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37355 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37356 rport->roles = ids->roles;
37357
37358 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37359 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37360 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37361
37362 transport_setup_device(&rport->dev);
37363 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37364 index eacd46b..e3f4d62 100644
37365 --- a/drivers/scsi/sg.c
37366 +++ b/drivers/scsi/sg.c
37367 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37368 sdp->disk->disk_name,
37369 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37370 NULL,
37371 - (char *)arg);
37372 + (char __user *)arg);
37373 case BLKTRACESTART:
37374 return blk_trace_startstop(sdp->device->request_queue, 1);
37375 case BLKTRACESTOP:
37376 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37377 const struct file_operations * fops;
37378 };
37379
37380 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37381 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37382 {"allow_dio", &adio_fops},
37383 {"debug", &debug_fops},
37384 {"def_reserved_size", &dressz_fops},
37385 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37386 if (!sg_proc_sgp)
37387 return 1;
37388 for (k = 0; k < num_leaves; ++k) {
37389 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37390 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37391 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37392 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37393 }
37394 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37395 index f64250e..1ee3049 100644
37396 --- a/drivers/spi/spi-dw-pci.c
37397 +++ b/drivers/spi/spi-dw-pci.c
37398 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37399 #define spi_resume NULL
37400 #endif
37401
37402 -static const struct pci_device_id pci_ids[] __devinitdata = {
37403 +static const struct pci_device_id pci_ids[] __devinitconst = {
37404 /* Intel MID platform SPI controller 0 */
37405 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37406 {},
37407 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37408 index b2ccdea..84cde75 100644
37409 --- a/drivers/spi/spi.c
37410 +++ b/drivers/spi/spi.c
37411 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37412 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37413
37414 /* portable code must never pass more than 32 bytes */
37415 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37416 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37417
37418 static u8 *buf;
37419
37420 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37421 index 400df8c..065d4f4 100644
37422 --- a/drivers/staging/octeon/ethernet-rx.c
37423 +++ b/drivers/staging/octeon/ethernet-rx.c
37424 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37425 /* Increment RX stats for virtual ports */
37426 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37427 #ifdef CONFIG_64BIT
37428 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37429 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37430 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37431 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37432 #else
37433 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37434 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37435 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37436 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37437 #endif
37438 }
37439 netif_receive_skb(skb);
37440 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37441 dev->name);
37442 */
37443 #ifdef CONFIG_64BIT
37444 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37445 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37446 #else
37447 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37448 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37449 #endif
37450 dev_kfree_skb_irq(skb);
37451 }
37452 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37453 index 9112cd8..92f8d51 100644
37454 --- a/drivers/staging/octeon/ethernet.c
37455 +++ b/drivers/staging/octeon/ethernet.c
37456 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37457 * since the RX tasklet also increments it.
37458 */
37459 #ifdef CONFIG_64BIT
37460 - atomic64_add(rx_status.dropped_packets,
37461 - (atomic64_t *)&priv->stats.rx_dropped);
37462 + atomic64_add_unchecked(rx_status.dropped_packets,
37463 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37464 #else
37465 - atomic_add(rx_status.dropped_packets,
37466 - (atomic_t *)&priv->stats.rx_dropped);
37467 + atomic_add_unchecked(rx_status.dropped_packets,
37468 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37469 #endif
37470 }
37471
37472 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37473 index f9dae95..ff48901 100644
37474 --- a/drivers/staging/rtl8192e/rtllib_module.c
37475 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37476 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37477 }
37478
37479 static int store_debug_level(struct file *file, const char __user *buffer,
37480 + unsigned long count, void *data) __size_overflow(3);
37481 +static int store_debug_level(struct file *file, const char __user *buffer,
37482 unsigned long count, void *data)
37483 {
37484 char buf[] = "0x00000000";
37485 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37486 index e3d47bc..85f4d0d 100644
37487 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37488 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37489 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37490 }
37491
37492 static int store_debug_level(struct file *file, const char *buffer,
37493 + unsigned long count, void *data) __size_overflow(3);
37494 +static int store_debug_level(struct file *file, const char *buffer,
37495 unsigned long count, void *data)
37496 {
37497 char buf[] = "0x00000000";
37498 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37499 index 86308a0..feaa925 100644
37500 --- a/drivers/staging/rtl8712/rtl871x_io.h
37501 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37502 @@ -108,7 +108,7 @@ struct _io_ops {
37503 u8 *pmem);
37504 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37505 u8 *pmem);
37506 -};
37507 +} __no_const;
37508
37509 struct io_req {
37510 struct list_head list;
37511 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37512 index c7b5e8b..783d6cb 100644
37513 --- a/drivers/staging/sbe-2t3e3/netdev.c
37514 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37515 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37516 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37517
37518 if (rlen)
37519 - if (copy_to_user(data, &resp, rlen))
37520 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37521 return -EFAULT;
37522
37523 return 0;
37524 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37525 index 42cdafe..2769103 100644
37526 --- a/drivers/staging/speakup/speakup_soft.c
37527 +++ b/drivers/staging/speakup/speakup_soft.c
37528 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37529 break;
37530 } else if (!initialized) {
37531 if (*init) {
37532 - ch = *init;
37533 init++;
37534 } else {
37535 initialized = 1;
37536 }
37537 + ch = *init;
37538 } else {
37539 ch = synth_buffer_getc();
37540 }
37541 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37542 index b8f8c48..1fc5025 100644
37543 --- a/drivers/staging/usbip/usbip_common.h
37544 +++ b/drivers/staging/usbip/usbip_common.h
37545 @@ -289,7 +289,7 @@ struct usbip_device {
37546 void (*shutdown)(struct usbip_device *);
37547 void (*reset)(struct usbip_device *);
37548 void (*unusable)(struct usbip_device *);
37549 - } eh_ops;
37550 + } __no_const eh_ops;
37551 };
37552
37553 /* usbip_common.c */
37554 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37555 index 88b3298..3783eee 100644
37556 --- a/drivers/staging/usbip/vhci.h
37557 +++ b/drivers/staging/usbip/vhci.h
37558 @@ -88,7 +88,7 @@ struct vhci_hcd {
37559 unsigned resuming:1;
37560 unsigned long re_timeout;
37561
37562 - atomic_t seqnum;
37563 + atomic_unchecked_t seqnum;
37564
37565 /*
37566 * NOTE:
37567 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37568 index 2ee97e2..0420b86 100644
37569 --- a/drivers/staging/usbip/vhci_hcd.c
37570 +++ b/drivers/staging/usbip/vhci_hcd.c
37571 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37572 return;
37573 }
37574
37575 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37576 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37577 if (priv->seqnum == 0xffff)
37578 dev_info(&urb->dev->dev, "seqnum max\n");
37579
37580 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37581 return -ENOMEM;
37582 }
37583
37584 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37585 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37586 if (unlink->seqnum == 0xffff)
37587 pr_info("seqnum max\n");
37588
37589 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37590 vdev->rhport = rhport;
37591 }
37592
37593 - atomic_set(&vhci->seqnum, 0);
37594 + atomic_set_unchecked(&vhci->seqnum, 0);
37595 spin_lock_init(&vhci->lock);
37596
37597 hcd->power_budget = 0; /* no limit */
37598 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37599 index 3f511b4..d3dbc1e 100644
37600 --- a/drivers/staging/usbip/vhci_rx.c
37601 +++ b/drivers/staging/usbip/vhci_rx.c
37602 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37603 if (!urb) {
37604 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37605 pr_info("max seqnum %d\n",
37606 - atomic_read(&the_controller->seqnum));
37607 + atomic_read_unchecked(&the_controller->seqnum));
37608 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37609 return;
37610 }
37611 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37612 index 7735027..30eed13 100644
37613 --- a/drivers/staging/vt6655/hostap.c
37614 +++ b/drivers/staging/vt6655/hostap.c
37615 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37616 *
37617 */
37618
37619 +static net_device_ops_no_const apdev_netdev_ops;
37620 +
37621 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37622 {
37623 PSDevice apdev_priv;
37624 struct net_device *dev = pDevice->dev;
37625 int ret;
37626 - const struct net_device_ops apdev_netdev_ops = {
37627 - .ndo_start_xmit = pDevice->tx_80211,
37628 - };
37629
37630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37631
37632 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37633 *apdev_priv = *pDevice;
37634 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37635
37636 + /* only half broken now */
37637 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37638 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37639
37640 pDevice->apdev->type = ARPHRD_IEEE80211;
37641 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37642 index 51b5adf..098e320 100644
37643 --- a/drivers/staging/vt6656/hostap.c
37644 +++ b/drivers/staging/vt6656/hostap.c
37645 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37646 *
37647 */
37648
37649 +static net_device_ops_no_const apdev_netdev_ops;
37650 +
37651 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37652 {
37653 PSDevice apdev_priv;
37654 struct net_device *dev = pDevice->dev;
37655 int ret;
37656 - const struct net_device_ops apdev_netdev_ops = {
37657 - .ndo_start_xmit = pDevice->tx_80211,
37658 - };
37659
37660 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37661
37662 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37663 *apdev_priv = *pDevice;
37664 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37665
37666 + /* only half broken now */
37667 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37668 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37669
37670 pDevice->apdev->type = ARPHRD_IEEE80211;
37671 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37672 index 7843dfd..3db105f 100644
37673 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37674 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37675 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37676
37677 struct usbctlx_completor {
37678 int (*complete) (struct usbctlx_completor *);
37679 -};
37680 +} __no_const;
37681
37682 static int
37683 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37684 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37685 index 1ca66ea..76f1343 100644
37686 --- a/drivers/staging/zcache/tmem.c
37687 +++ b/drivers/staging/zcache/tmem.c
37688 @@ -39,7 +39,7 @@
37689 * A tmem host implementation must use this function to register callbacks
37690 * for memory allocation.
37691 */
37692 -static struct tmem_hostops tmem_hostops;
37693 +static tmem_hostops_no_const tmem_hostops;
37694
37695 static void tmem_objnode_tree_init(void);
37696
37697 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37698 * A tmem host implementation must use this function to register
37699 * callbacks for a page-accessible memory (PAM) implementation
37700 */
37701 -static struct tmem_pamops tmem_pamops;
37702 +static tmem_pamops_no_const tmem_pamops;
37703
37704 void tmem_register_pamops(struct tmem_pamops *m)
37705 {
37706 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37707 index ed147c4..94fc3c6 100644
37708 --- a/drivers/staging/zcache/tmem.h
37709 +++ b/drivers/staging/zcache/tmem.h
37710 @@ -180,6 +180,7 @@ struct tmem_pamops {
37711 void (*new_obj)(struct tmem_obj *);
37712 int (*replace_in_obj)(void *, struct tmem_obj *);
37713 };
37714 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37715 extern void tmem_register_pamops(struct tmem_pamops *m);
37716
37717 /* memory allocation methods provided by the host implementation */
37718 @@ -189,6 +190,7 @@ struct tmem_hostops {
37719 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37720 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37721 };
37722 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37723 extern void tmem_register_hostops(struct tmem_hostops *m);
37724
37725 /* core tmem accessor functions */
37726 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37727 index 97c74ee..7f6d77d 100644
37728 --- a/drivers/target/iscsi/iscsi_target.c
37729 +++ b/drivers/target/iscsi/iscsi_target.c
37730 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37731 * outstanding_r2ts reaches zero, go ahead and send the delayed
37732 * TASK_ABORTED status.
37733 */
37734 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37735 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37736 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37737 if (--cmd->outstanding_r2ts < 1) {
37738 iscsit_stop_dataout_timer(cmd);
37739 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37740 index dcb0618..97e3d85 100644
37741 --- a/drivers/target/target_core_tmr.c
37742 +++ b/drivers/target/target_core_tmr.c
37743 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37744 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37745 cmd->t_task_list_num,
37746 atomic_read(&cmd->t_task_cdbs_left),
37747 - atomic_read(&cmd->t_task_cdbs_sent),
37748 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37749 atomic_read(&cmd->t_transport_active),
37750 atomic_read(&cmd->t_transport_stop),
37751 atomic_read(&cmd->t_transport_sent));
37752 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37753 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37754 " task: %p, t_fe_count: %d dev: %p\n", task,
37755 fe_count, dev);
37756 - atomic_set(&cmd->t_transport_aborted, 1);
37757 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37758 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37759
37760 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37761 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37762 }
37763 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37764 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37765 - atomic_set(&cmd->t_transport_aborted, 1);
37766 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37767 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37768
37769 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37770 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37771 index cd5cd95..5249d30 100644
37772 --- a/drivers/target/target_core_transport.c
37773 +++ b/drivers/target/target_core_transport.c
37774 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37775 spin_lock_init(&dev->se_port_lock);
37776 spin_lock_init(&dev->se_tmr_lock);
37777 spin_lock_init(&dev->qf_cmd_lock);
37778 - atomic_set(&dev->dev_ordered_id, 0);
37779 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37780
37781 se_dev_set_default_attribs(dev, dev_limits);
37782
37783 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37784 * Used to determine when ORDERED commands should go from
37785 * Dormant to Active status.
37786 */
37787 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37788 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37789 smp_mb__after_atomic_inc();
37790 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37791 cmd->se_ordered_id, cmd->sam_task_attr,
37792 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37793 " t_transport_active: %d t_transport_stop: %d"
37794 " t_transport_sent: %d\n", cmd->t_task_list_num,
37795 atomic_read(&cmd->t_task_cdbs_left),
37796 - atomic_read(&cmd->t_task_cdbs_sent),
37797 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37798 atomic_read(&cmd->t_task_cdbs_ex_left),
37799 atomic_read(&cmd->t_transport_active),
37800 atomic_read(&cmd->t_transport_stop),
37801 @@ -2121,9 +2121,9 @@ check_depth:
37802 cmd = task->task_se_cmd;
37803 spin_lock_irqsave(&cmd->t_state_lock, flags);
37804 task->task_flags |= (TF_ACTIVE | TF_SENT);
37805 - atomic_inc(&cmd->t_task_cdbs_sent);
37806 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37807
37808 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37809 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37810 cmd->t_task_list_num)
37811 atomic_set(&cmd->t_transport_sent, 1);
37812
37813 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37814 atomic_set(&cmd->transport_lun_stop, 0);
37815 }
37816 if (!atomic_read(&cmd->t_transport_active) ||
37817 - atomic_read(&cmd->t_transport_aborted)) {
37818 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37819 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37820 return false;
37821 }
37822 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37823 {
37824 int ret = 0;
37825
37826 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37827 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37828 if (!send_status ||
37829 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37830 return 1;
37831 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37832 */
37833 if (cmd->data_direction == DMA_TO_DEVICE) {
37834 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37835 - atomic_inc(&cmd->t_transport_aborted);
37836 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37837 smp_mb__after_atomic_inc();
37838 }
37839 }
37840 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37841 index b9040be..e3f5aab 100644
37842 --- a/drivers/tty/hvc/hvcs.c
37843 +++ b/drivers/tty/hvc/hvcs.c
37844 @@ -83,6 +83,7 @@
37845 #include <asm/hvcserver.h>
37846 #include <asm/uaccess.h>
37847 #include <asm/vio.h>
37848 +#include <asm/local.h>
37849
37850 /*
37851 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37852 @@ -270,7 +271,7 @@ struct hvcs_struct {
37853 unsigned int index;
37854
37855 struct tty_struct *tty;
37856 - int open_count;
37857 + local_t open_count;
37858
37859 /*
37860 * Used to tell the driver kernel_thread what operations need to take
37861 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37862
37863 spin_lock_irqsave(&hvcsd->lock, flags);
37864
37865 - if (hvcsd->open_count > 0) {
37866 + if (local_read(&hvcsd->open_count) > 0) {
37867 spin_unlock_irqrestore(&hvcsd->lock, flags);
37868 printk(KERN_INFO "HVCS: vterm state unchanged. "
37869 "The hvcs device node is still in use.\n");
37870 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37871 if ((retval = hvcs_partner_connect(hvcsd)))
37872 goto error_release;
37873
37874 - hvcsd->open_count = 1;
37875 + local_set(&hvcsd->open_count, 1);
37876 hvcsd->tty = tty;
37877 tty->driver_data = hvcsd;
37878
37879 @@ -1179,7 +1180,7 @@ fast_open:
37880
37881 spin_lock_irqsave(&hvcsd->lock, flags);
37882 kref_get(&hvcsd->kref);
37883 - hvcsd->open_count++;
37884 + local_inc(&hvcsd->open_count);
37885 hvcsd->todo_mask |= HVCS_SCHED_READ;
37886 spin_unlock_irqrestore(&hvcsd->lock, flags);
37887
37888 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37889 hvcsd = tty->driver_data;
37890
37891 spin_lock_irqsave(&hvcsd->lock, flags);
37892 - if (--hvcsd->open_count == 0) {
37893 + if (local_dec_and_test(&hvcsd->open_count)) {
37894
37895 vio_disable_interrupts(hvcsd->vdev);
37896
37897 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37898 free_irq(irq, hvcsd);
37899 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37900 return;
37901 - } else if (hvcsd->open_count < 0) {
37902 + } else if (local_read(&hvcsd->open_count) < 0) {
37903 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37904 " is missmanaged.\n",
37905 - hvcsd->vdev->unit_address, hvcsd->open_count);
37906 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37907 }
37908
37909 spin_unlock_irqrestore(&hvcsd->lock, flags);
37910 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37911
37912 spin_lock_irqsave(&hvcsd->lock, flags);
37913 /* Preserve this so that we know how many kref refs to put */
37914 - temp_open_count = hvcsd->open_count;
37915 + temp_open_count = local_read(&hvcsd->open_count);
37916
37917 /*
37918 * Don't kref put inside the spinlock because the destruction
37919 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37920 hvcsd->tty->driver_data = NULL;
37921 hvcsd->tty = NULL;
37922
37923 - hvcsd->open_count = 0;
37924 + local_set(&hvcsd->open_count, 0);
37925
37926 /* This will drop any buffered data on the floor which is OK in a hangup
37927 * scenario. */
37928 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37929 * the middle of a write operation? This is a crummy place to do this
37930 * but we want to keep it all in the spinlock.
37931 */
37932 - if (hvcsd->open_count <= 0) {
37933 + if (local_read(&hvcsd->open_count) <= 0) {
37934 spin_unlock_irqrestore(&hvcsd->lock, flags);
37935 return -ENODEV;
37936 }
37937 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37938 {
37939 struct hvcs_struct *hvcsd = tty->driver_data;
37940
37941 - if (!hvcsd || hvcsd->open_count <= 0)
37942 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37943 return 0;
37944
37945 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37946 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37947 index ef92869..f4ebd88 100644
37948 --- a/drivers/tty/ipwireless/tty.c
37949 +++ b/drivers/tty/ipwireless/tty.c
37950 @@ -29,6 +29,7 @@
37951 #include <linux/tty_driver.h>
37952 #include <linux/tty_flip.h>
37953 #include <linux/uaccess.h>
37954 +#include <asm/local.h>
37955
37956 #include "tty.h"
37957 #include "network.h"
37958 @@ -51,7 +52,7 @@ struct ipw_tty {
37959 int tty_type;
37960 struct ipw_network *network;
37961 struct tty_struct *linux_tty;
37962 - int open_count;
37963 + local_t open_count;
37964 unsigned int control_lines;
37965 struct mutex ipw_tty_mutex;
37966 int tx_bytes_queued;
37967 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37968 mutex_unlock(&tty->ipw_tty_mutex);
37969 return -ENODEV;
37970 }
37971 - if (tty->open_count == 0)
37972 + if (local_read(&tty->open_count) == 0)
37973 tty->tx_bytes_queued = 0;
37974
37975 - tty->open_count++;
37976 + local_inc(&tty->open_count);
37977
37978 tty->linux_tty = linux_tty;
37979 linux_tty->driver_data = tty;
37980 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37981
37982 static void do_ipw_close(struct ipw_tty *tty)
37983 {
37984 - tty->open_count--;
37985 -
37986 - if (tty->open_count == 0) {
37987 + if (local_dec_return(&tty->open_count) == 0) {
37988 struct tty_struct *linux_tty = tty->linux_tty;
37989
37990 if (linux_tty != NULL) {
37991 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37992 return;
37993
37994 mutex_lock(&tty->ipw_tty_mutex);
37995 - if (tty->open_count == 0) {
37996 + if (local_read(&tty->open_count) == 0) {
37997 mutex_unlock(&tty->ipw_tty_mutex);
37998 return;
37999 }
38000 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38001 return;
38002 }
38003
38004 - if (!tty->open_count) {
38005 + if (!local_read(&tty->open_count)) {
38006 mutex_unlock(&tty->ipw_tty_mutex);
38007 return;
38008 }
38009 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38010 return -ENODEV;
38011
38012 mutex_lock(&tty->ipw_tty_mutex);
38013 - if (!tty->open_count) {
38014 + if (!local_read(&tty->open_count)) {
38015 mutex_unlock(&tty->ipw_tty_mutex);
38016 return -EINVAL;
38017 }
38018 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38019 if (!tty)
38020 return -ENODEV;
38021
38022 - if (!tty->open_count)
38023 + if (!local_read(&tty->open_count))
38024 return -EINVAL;
38025
38026 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38027 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38028 if (!tty)
38029 return 0;
38030
38031 - if (!tty->open_count)
38032 + if (!local_read(&tty->open_count))
38033 return 0;
38034
38035 return tty->tx_bytes_queued;
38036 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38037 if (!tty)
38038 return -ENODEV;
38039
38040 - if (!tty->open_count)
38041 + if (!local_read(&tty->open_count))
38042 return -EINVAL;
38043
38044 return get_control_lines(tty);
38045 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38046 if (!tty)
38047 return -ENODEV;
38048
38049 - if (!tty->open_count)
38050 + if (!local_read(&tty->open_count))
38051 return -EINVAL;
38052
38053 return set_control_lines(tty, set, clear);
38054 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38055 if (!tty)
38056 return -ENODEV;
38057
38058 - if (!tty->open_count)
38059 + if (!local_read(&tty->open_count))
38060 return -EINVAL;
38061
38062 /* FIXME: Exactly how is the tty object locked here .. */
38063 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38064 against a parallel ioctl etc */
38065 mutex_lock(&ttyj->ipw_tty_mutex);
38066 }
38067 - while (ttyj->open_count)
38068 + while (local_read(&ttyj->open_count))
38069 do_ipw_close(ttyj);
38070 ipwireless_disassociate_network_ttys(network,
38071 ttyj->channel_idx);
38072 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38073 index fc7bbba..9527e93 100644
38074 --- a/drivers/tty/n_gsm.c
38075 +++ b/drivers/tty/n_gsm.c
38076 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38077 kref_init(&dlci->ref);
38078 mutex_init(&dlci->mutex);
38079 dlci->fifo = &dlci->_fifo;
38080 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38081 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38082 kfree(dlci);
38083 return NULL;
38084 }
38085 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38086 index d2256d0..97476fa 100644
38087 --- a/drivers/tty/n_tty.c
38088 +++ b/drivers/tty/n_tty.c
38089 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38090 {
38091 *ops = tty_ldisc_N_TTY;
38092 ops->owner = NULL;
38093 - ops->refcount = ops->flags = 0;
38094 + atomic_set(&ops->refcount, 0);
38095 + ops->flags = 0;
38096 }
38097 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38098 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38099 index d8653ab..f8afd9d 100644
38100 --- a/drivers/tty/pty.c
38101 +++ b/drivers/tty/pty.c
38102 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38103 register_sysctl_table(pty_root_table);
38104
38105 /* Now create the /dev/ptmx special device */
38106 + pax_open_kernel();
38107 tty_default_fops(&ptmx_fops);
38108 - ptmx_fops.open = ptmx_open;
38109 + *(void **)&ptmx_fops.open = ptmx_open;
38110 + pax_close_kernel();
38111
38112 cdev_init(&ptmx_cdev, &ptmx_fops);
38113 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38114 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38115 index 2b42a01..32a2ed3 100644
38116 --- a/drivers/tty/serial/kgdboc.c
38117 +++ b/drivers/tty/serial/kgdboc.c
38118 @@ -24,8 +24,9 @@
38119 #define MAX_CONFIG_LEN 40
38120
38121 static struct kgdb_io kgdboc_io_ops;
38122 +static struct kgdb_io kgdboc_io_ops_console;
38123
38124 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38125 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38126 static int configured = -1;
38127
38128 static char config[MAX_CONFIG_LEN];
38129 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38130 kgdboc_unregister_kbd();
38131 if (configured == 1)
38132 kgdb_unregister_io_module(&kgdboc_io_ops);
38133 + else if (configured == 2)
38134 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38135 }
38136
38137 static int configure_kgdboc(void)
38138 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38139 int err;
38140 char *cptr = config;
38141 struct console *cons;
38142 + int is_console = 0;
38143
38144 err = kgdboc_option_setup(config);
38145 if (err || !strlen(config) || isspace(config[0]))
38146 goto noconfig;
38147
38148 err = -ENODEV;
38149 - kgdboc_io_ops.is_console = 0;
38150 kgdb_tty_driver = NULL;
38151
38152 kgdboc_use_kms = 0;
38153 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38154 int idx;
38155 if (cons->device && cons->device(cons, &idx) == p &&
38156 idx == tty_line) {
38157 - kgdboc_io_ops.is_console = 1;
38158 + is_console = 1;
38159 break;
38160 }
38161 cons = cons->next;
38162 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38163 kgdb_tty_line = tty_line;
38164
38165 do_register:
38166 - err = kgdb_register_io_module(&kgdboc_io_ops);
38167 + if (is_console) {
38168 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38169 + configured = 2;
38170 + } else {
38171 + err = kgdb_register_io_module(&kgdboc_io_ops);
38172 + configured = 1;
38173 + }
38174 if (err)
38175 goto noconfig;
38176
38177 - configured = 1;
38178 -
38179 return 0;
38180
38181 noconfig:
38182 @@ -213,7 +220,7 @@ noconfig:
38183 static int __init init_kgdboc(void)
38184 {
38185 /* Already configured? */
38186 - if (configured == 1)
38187 + if (configured >= 1)
38188 return 0;
38189
38190 return configure_kgdboc();
38191 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38192 if (config[len - 1] == '\n')
38193 config[len - 1] = '\0';
38194
38195 - if (configured == 1)
38196 + if (configured >= 1)
38197 cleanup_kgdboc();
38198
38199 /* Go and configure with the new params. */
38200 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38201 .post_exception = kgdboc_post_exp_handler,
38202 };
38203
38204 +static struct kgdb_io kgdboc_io_ops_console = {
38205 + .name = "kgdboc",
38206 + .read_char = kgdboc_get_char,
38207 + .write_char = kgdboc_put_char,
38208 + .pre_exception = kgdboc_pre_exp_handler,
38209 + .post_exception = kgdboc_post_exp_handler,
38210 + .is_console = 1
38211 +};
38212 +
38213 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38214 /* This is only available if kgdboc is a built in for early debugging */
38215 static int __init kgdboc_early_init(char *opt)
38216 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38217 index 7867b7c..b3c119d 100644
38218 --- a/drivers/tty/sysrq.c
38219 +++ b/drivers/tty/sysrq.c
38220 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38221 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38222 size_t count, loff_t *ppos)
38223 {
38224 - if (count) {
38225 + if (count && capable(CAP_SYS_ADMIN)) {
38226 char c;
38227
38228 if (get_user(c, buf))
38229 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38230 index e41b9bb..84002fb 100644
38231 --- a/drivers/tty/tty_io.c
38232 +++ b/drivers/tty/tty_io.c
38233 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38234
38235 void tty_default_fops(struct file_operations *fops)
38236 {
38237 - *fops = tty_fops;
38238 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38239 }
38240
38241 /*
38242 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38243 index 24b95db..9c078d0 100644
38244 --- a/drivers/tty/tty_ldisc.c
38245 +++ b/drivers/tty/tty_ldisc.c
38246 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38247 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38248 struct tty_ldisc_ops *ldo = ld->ops;
38249
38250 - ldo->refcount--;
38251 + atomic_dec(&ldo->refcount);
38252 module_put(ldo->owner);
38253 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38254
38255 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38256 spin_lock_irqsave(&tty_ldisc_lock, flags);
38257 tty_ldiscs[disc] = new_ldisc;
38258 new_ldisc->num = disc;
38259 - new_ldisc->refcount = 0;
38260 + atomic_set(&new_ldisc->refcount, 0);
38261 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38262
38263 return ret;
38264 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38265 return -EINVAL;
38266
38267 spin_lock_irqsave(&tty_ldisc_lock, flags);
38268 - if (tty_ldiscs[disc]->refcount)
38269 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38270 ret = -EBUSY;
38271 else
38272 tty_ldiscs[disc] = NULL;
38273 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38274 if (ldops) {
38275 ret = ERR_PTR(-EAGAIN);
38276 if (try_module_get(ldops->owner)) {
38277 - ldops->refcount++;
38278 + atomic_inc(&ldops->refcount);
38279 ret = ldops;
38280 }
38281 }
38282 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38283 unsigned long flags;
38284
38285 spin_lock_irqsave(&tty_ldisc_lock, flags);
38286 - ldops->refcount--;
38287 + atomic_dec(&ldops->refcount);
38288 module_put(ldops->owner);
38289 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38290 }
38291 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38292 index a605549..6bd3c96 100644
38293 --- a/drivers/tty/vt/keyboard.c
38294 +++ b/drivers/tty/vt/keyboard.c
38295 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38296 kbd->kbdmode == VC_OFF) &&
38297 value != KVAL(K_SAK))
38298 return; /* SAK is allowed even in raw mode */
38299 +
38300 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38301 + {
38302 + void *func = fn_handler[value];
38303 + if (func == fn_show_state || func == fn_show_ptregs ||
38304 + func == fn_show_mem)
38305 + return;
38306 + }
38307 +#endif
38308 +
38309 fn_handler[value](vc);
38310 }
38311
38312 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38313 index 65447c5..0526f0a 100644
38314 --- a/drivers/tty/vt/vt_ioctl.c
38315 +++ b/drivers/tty/vt/vt_ioctl.c
38316 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38317 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38318 return -EFAULT;
38319
38320 - if (!capable(CAP_SYS_TTY_CONFIG))
38321 - perm = 0;
38322 -
38323 switch (cmd) {
38324 case KDGKBENT:
38325 key_map = key_maps[s];
38326 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38327 val = (i ? K_HOLE : K_NOSUCHMAP);
38328 return put_user(val, &user_kbe->kb_value);
38329 case KDSKBENT:
38330 + if (!capable(CAP_SYS_TTY_CONFIG))
38331 + perm = 0;
38332 +
38333 if (!perm)
38334 return -EPERM;
38335 if (!i && v == K_NOSUCHMAP) {
38336 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38337 int i, j, k;
38338 int ret;
38339
38340 - if (!capable(CAP_SYS_TTY_CONFIG))
38341 - perm = 0;
38342 -
38343 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38344 if (!kbs) {
38345 ret = -ENOMEM;
38346 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38347 kfree(kbs);
38348 return ((p && *p) ? -EOVERFLOW : 0);
38349 case KDSKBSENT:
38350 + if (!capable(CAP_SYS_TTY_CONFIG))
38351 + perm = 0;
38352 +
38353 if (!perm) {
38354 ret = -EPERM;
38355 goto reterr;
38356 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38357 index a783d53..cb30d94 100644
38358 --- a/drivers/uio/uio.c
38359 +++ b/drivers/uio/uio.c
38360 @@ -25,6 +25,7 @@
38361 #include <linux/kobject.h>
38362 #include <linux/cdev.h>
38363 #include <linux/uio_driver.h>
38364 +#include <asm/local.h>
38365
38366 #define UIO_MAX_DEVICES (1U << MINORBITS)
38367
38368 @@ -32,10 +33,10 @@ struct uio_device {
38369 struct module *owner;
38370 struct device *dev;
38371 int minor;
38372 - atomic_t event;
38373 + atomic_unchecked_t event;
38374 struct fasync_struct *async_queue;
38375 wait_queue_head_t wait;
38376 - int vma_count;
38377 + local_t vma_count;
38378 struct uio_info *info;
38379 struct kobject *map_dir;
38380 struct kobject *portio_dir;
38381 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38382 struct device_attribute *attr, char *buf)
38383 {
38384 struct uio_device *idev = dev_get_drvdata(dev);
38385 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38386 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38387 }
38388
38389 static struct device_attribute uio_class_attributes[] = {
38390 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38391 {
38392 struct uio_device *idev = info->uio_dev;
38393
38394 - atomic_inc(&idev->event);
38395 + atomic_inc_unchecked(&idev->event);
38396 wake_up_interruptible(&idev->wait);
38397 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38398 }
38399 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38400 }
38401
38402 listener->dev = idev;
38403 - listener->event_count = atomic_read(&idev->event);
38404 + listener->event_count = atomic_read_unchecked(&idev->event);
38405 filep->private_data = listener;
38406
38407 if (idev->info->open) {
38408 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38409 return -EIO;
38410
38411 poll_wait(filep, &idev->wait, wait);
38412 - if (listener->event_count != atomic_read(&idev->event))
38413 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38414 return POLLIN | POLLRDNORM;
38415 return 0;
38416 }
38417 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38418 do {
38419 set_current_state(TASK_INTERRUPTIBLE);
38420
38421 - event_count = atomic_read(&idev->event);
38422 + event_count = atomic_read_unchecked(&idev->event);
38423 if (event_count != listener->event_count) {
38424 if (copy_to_user(buf, &event_count, count))
38425 retval = -EFAULT;
38426 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38427 static void uio_vma_open(struct vm_area_struct *vma)
38428 {
38429 struct uio_device *idev = vma->vm_private_data;
38430 - idev->vma_count++;
38431 + local_inc(&idev->vma_count);
38432 }
38433
38434 static void uio_vma_close(struct vm_area_struct *vma)
38435 {
38436 struct uio_device *idev = vma->vm_private_data;
38437 - idev->vma_count--;
38438 + local_dec(&idev->vma_count);
38439 }
38440
38441 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38442 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38443 idev->owner = owner;
38444 idev->info = info;
38445 init_waitqueue_head(&idev->wait);
38446 - atomic_set(&idev->event, 0);
38447 + atomic_set_unchecked(&idev->event, 0);
38448
38449 ret = uio_get_minor(idev);
38450 if (ret)
38451 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38452 index 98b89fe..aff824e 100644
38453 --- a/drivers/usb/atm/cxacru.c
38454 +++ b/drivers/usb/atm/cxacru.c
38455 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38456 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38457 if (ret < 2)
38458 return -EINVAL;
38459 - if (index < 0 || index > 0x7f)
38460 + if (index > 0x7f)
38461 return -EINVAL;
38462 pos += tmp;
38463
38464 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38465 index d3448ca..d2864ca 100644
38466 --- a/drivers/usb/atm/usbatm.c
38467 +++ b/drivers/usb/atm/usbatm.c
38468 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38469 if (printk_ratelimit())
38470 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38471 __func__, vpi, vci);
38472 - atomic_inc(&vcc->stats->rx_err);
38473 + atomic_inc_unchecked(&vcc->stats->rx_err);
38474 return;
38475 }
38476
38477 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38478 if (length > ATM_MAX_AAL5_PDU) {
38479 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38480 __func__, length, vcc);
38481 - atomic_inc(&vcc->stats->rx_err);
38482 + atomic_inc_unchecked(&vcc->stats->rx_err);
38483 goto out;
38484 }
38485
38486 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38487 if (sarb->len < pdu_length) {
38488 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38489 __func__, pdu_length, sarb->len, vcc);
38490 - atomic_inc(&vcc->stats->rx_err);
38491 + atomic_inc_unchecked(&vcc->stats->rx_err);
38492 goto out;
38493 }
38494
38495 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38496 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38497 __func__, vcc);
38498 - atomic_inc(&vcc->stats->rx_err);
38499 + atomic_inc_unchecked(&vcc->stats->rx_err);
38500 goto out;
38501 }
38502
38503 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38504 if (printk_ratelimit())
38505 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38506 __func__, length);
38507 - atomic_inc(&vcc->stats->rx_drop);
38508 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38509 goto out;
38510 }
38511
38512 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38513
38514 vcc->push(vcc, skb);
38515
38516 - atomic_inc(&vcc->stats->rx);
38517 + atomic_inc_unchecked(&vcc->stats->rx);
38518 out:
38519 skb_trim(sarb, 0);
38520 }
38521 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38522 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38523
38524 usbatm_pop(vcc, skb);
38525 - atomic_inc(&vcc->stats->tx);
38526 + atomic_inc_unchecked(&vcc->stats->tx);
38527
38528 skb = skb_dequeue(&instance->sndqueue);
38529 }
38530 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38531 if (!left--)
38532 return sprintf(page,
38533 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38534 - atomic_read(&atm_dev->stats.aal5.tx),
38535 - atomic_read(&atm_dev->stats.aal5.tx_err),
38536 - atomic_read(&atm_dev->stats.aal5.rx),
38537 - atomic_read(&atm_dev->stats.aal5.rx_err),
38538 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38539 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38540 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38541 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38542 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38543 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38544
38545 if (!left--) {
38546 if (instance->disconnected)
38547 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38548 index d956965..4179a77 100644
38549 --- a/drivers/usb/core/devices.c
38550 +++ b/drivers/usb/core/devices.c
38551 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38552 * time it gets called.
38553 */
38554 static struct device_connect_event {
38555 - atomic_t count;
38556 + atomic_unchecked_t count;
38557 wait_queue_head_t wait;
38558 } device_event = {
38559 .count = ATOMIC_INIT(1),
38560 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38561
38562 void usbfs_conn_disc_event(void)
38563 {
38564 - atomic_add(2, &device_event.count);
38565 + atomic_add_unchecked(2, &device_event.count);
38566 wake_up(&device_event.wait);
38567 }
38568
38569 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38570
38571 poll_wait(file, &device_event.wait, wait);
38572
38573 - event_count = atomic_read(&device_event.count);
38574 + event_count = atomic_read_unchecked(&device_event.count);
38575 if (file->f_version != event_count) {
38576 file->f_version = event_count;
38577 return POLLIN | POLLRDNORM;
38578 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38579 index 1fc8f12..20647c1 100644
38580 --- a/drivers/usb/early/ehci-dbgp.c
38581 +++ b/drivers/usb/early/ehci-dbgp.c
38582 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38583
38584 #ifdef CONFIG_KGDB
38585 static struct kgdb_io kgdbdbgp_io_ops;
38586 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38587 +static struct kgdb_io kgdbdbgp_io_ops_console;
38588 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38589 #else
38590 #define dbgp_kgdb_mode (0)
38591 #endif
38592 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38593 .write_char = kgdbdbgp_write_char,
38594 };
38595
38596 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38597 + .name = "kgdbdbgp",
38598 + .read_char = kgdbdbgp_read_char,
38599 + .write_char = kgdbdbgp_write_char,
38600 + .is_console = 1
38601 +};
38602 +
38603 static int kgdbdbgp_wait_time;
38604
38605 static int __init kgdbdbgp_parse_config(char *str)
38606 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38607 ptr++;
38608 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38609 }
38610 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38611 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38612 + if (early_dbgp_console.index != -1)
38613 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38614 + else
38615 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38616
38617 return 0;
38618 }
38619 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38620 index d6bea3e..60b250e 100644
38621 --- a/drivers/usb/wusbcore/wa-hc.h
38622 +++ b/drivers/usb/wusbcore/wa-hc.h
38623 @@ -192,7 +192,7 @@ struct wahc {
38624 struct list_head xfer_delayed_list;
38625 spinlock_t xfer_list_lock;
38626 struct work_struct xfer_work;
38627 - atomic_t xfer_id_count;
38628 + atomic_unchecked_t xfer_id_count;
38629 };
38630
38631
38632 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38633 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38634 spin_lock_init(&wa->xfer_list_lock);
38635 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38636 - atomic_set(&wa->xfer_id_count, 1);
38637 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38638 }
38639
38640 /**
38641 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38642 index 57c01ab..8a05959 100644
38643 --- a/drivers/usb/wusbcore/wa-xfer.c
38644 +++ b/drivers/usb/wusbcore/wa-xfer.c
38645 @@ -296,7 +296,7 @@ out:
38646 */
38647 static void wa_xfer_id_init(struct wa_xfer *xfer)
38648 {
38649 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38650 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38651 }
38652
38653 /*
38654 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38655 index c14c42b..f955cc2 100644
38656 --- a/drivers/vhost/vhost.c
38657 +++ b/drivers/vhost/vhost.c
38658 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38659 return 0;
38660 }
38661
38662 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38663 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38664 {
38665 struct file *eventfp, *filep = NULL,
38666 *pollstart = NULL, *pollstop = NULL;
38667 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38668 index b0b2ac3..89a4399 100644
38669 --- a/drivers/video/aty/aty128fb.c
38670 +++ b/drivers/video/aty/aty128fb.c
38671 @@ -148,7 +148,7 @@ enum {
38672 };
38673
38674 /* Must match above enum */
38675 -static const char *r128_family[] __devinitdata = {
38676 +static const char *r128_family[] __devinitconst = {
38677 "AGP",
38678 "PCI",
38679 "PRO AGP",
38680 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38681 index 5c3960d..15cf8fc 100644
38682 --- a/drivers/video/fbcmap.c
38683 +++ b/drivers/video/fbcmap.c
38684 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38685 rc = -ENODEV;
38686 goto out;
38687 }
38688 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38689 - !info->fbops->fb_setcmap)) {
38690 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38691 rc = -EINVAL;
38692 goto out1;
38693 }
38694 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38695 index c6ce416..3b9b642 100644
38696 --- a/drivers/video/fbmem.c
38697 +++ b/drivers/video/fbmem.c
38698 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38699 image->dx += image->width + 8;
38700 }
38701 } else if (rotate == FB_ROTATE_UD) {
38702 - for (x = 0; x < num && image->dx >= 0; x++) {
38703 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38704 info->fbops->fb_imageblit(info, image);
38705 image->dx -= image->width + 8;
38706 }
38707 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38708 image->dy += image->height + 8;
38709 }
38710 } else if (rotate == FB_ROTATE_CCW) {
38711 - for (x = 0; x < num && image->dy >= 0; x++) {
38712 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38713 info->fbops->fb_imageblit(info, image);
38714 image->dy -= image->height + 8;
38715 }
38716 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38717 return -EFAULT;
38718 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38719 return -EINVAL;
38720 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38721 + if (con2fb.framebuffer >= FB_MAX)
38722 return -EINVAL;
38723 if (!registered_fb[con2fb.framebuffer])
38724 request_module("fb%d", con2fb.framebuffer);
38725 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38726 index 5a5d092..265c5ed 100644
38727 --- a/drivers/video/geode/gx1fb_core.c
38728 +++ b/drivers/video/geode/gx1fb_core.c
38729 @@ -29,7 +29,7 @@ static int crt_option = 1;
38730 static char panel_option[32] = "";
38731
38732 /* Modes relevant to the GX1 (taken from modedb.c) */
38733 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38734 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38735 /* 640x480-60 VESA */
38736 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38737 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38738 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38739 index 0fad23f..0e9afa4 100644
38740 --- a/drivers/video/gxt4500.c
38741 +++ b/drivers/video/gxt4500.c
38742 @@ -156,7 +156,7 @@ struct gxt4500_par {
38743 static char *mode_option;
38744
38745 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38746 -static const struct fb_videomode defaultmode __devinitdata = {
38747 +static const struct fb_videomode defaultmode __devinitconst = {
38748 .refresh = 60,
38749 .xres = 1280,
38750 .yres = 1024,
38751 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38752 return 0;
38753 }
38754
38755 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38756 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38757 .id = "IBM GXT4500P",
38758 .type = FB_TYPE_PACKED_PIXELS,
38759 .visual = FB_VISUAL_PSEUDOCOLOR,
38760 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38761 index 7672d2e..b56437f 100644
38762 --- a/drivers/video/i810/i810_accel.c
38763 +++ b/drivers/video/i810/i810_accel.c
38764 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38765 }
38766 }
38767 printk("ringbuffer lockup!!!\n");
38768 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38769 i810_report_error(mmio);
38770 par->dev_flags |= LOCKUP;
38771 info->pixmap.scan_align = 1;
38772 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38773 index b83f361..2b05a91 100644
38774 --- a/drivers/video/i810/i810_main.c
38775 +++ b/drivers/video/i810/i810_main.c
38776 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38777 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38778
38779 /* PCI */
38780 -static const char *i810_pci_list[] __devinitdata = {
38781 +static const char *i810_pci_list[] __devinitconst = {
38782 "Intel(R) 810 Framebuffer Device" ,
38783 "Intel(R) 810-DC100 Framebuffer Device" ,
38784 "Intel(R) 810E Framebuffer Device" ,
38785 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38786 index de36693..3c63fc2 100644
38787 --- a/drivers/video/jz4740_fb.c
38788 +++ b/drivers/video/jz4740_fb.c
38789 @@ -136,7 +136,7 @@ struct jzfb {
38790 uint32_t pseudo_palette[16];
38791 };
38792
38793 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38794 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38795 .id = "JZ4740 FB",
38796 .type = FB_TYPE_PACKED_PIXELS,
38797 .visual = FB_VISUAL_TRUECOLOR,
38798 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38799 index 3c14e43..eafa544 100644
38800 --- a/drivers/video/logo/logo_linux_clut224.ppm
38801 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38802 @@ -1,1604 +1,1123 @@
38803 P3
38804 -# Standard 224-color Linux logo
38805 80 80
38806 255
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 - 0 0 0 0 0 0 0 0 0 0 0 0
38813 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 10 10 10 10 10 10
38817 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
38832 - 0 0 0 0 0 0 0 0 0 0 0 0
38833 - 0 0 0 0 0 0 0 0 0 0 0 0
38834 - 0 0 0 0 0 0 0 0 0 0 0 0
38835 - 0 0 0 6 6 6 10 10 10 14 14 14
38836 - 22 22 22 26 26 26 30 30 30 34 34 34
38837 - 30 30 30 30 30 30 26 26 26 18 18 18
38838 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0
38845 - 0 0 0 0 0 0 0 0 0 0 0 0
38846 - 0 0 0 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 0 0 0
38854 - 0 0 0 0 0 0 0 0 0 0 0 0
38855 - 6 6 6 14 14 14 26 26 26 42 42 42
38856 - 54 54 54 66 66 66 78 78 78 78 78 78
38857 - 78 78 78 74 74 74 66 66 66 54 54 54
38858 - 42 42 42 26 26 26 18 18 18 10 10 10
38859 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38865 - 0 0 0 0 0 0 0 0 0 0 0 0
38866 - 0 0 0 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 1 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 0 0 0
38871 - 0 0 0 0 0 0 0 0 0 0 0 0
38872 - 0 0 0 0 0 0 0 0 0 0 0 0
38873 - 0 0 0 0 0 0 0 0 0 0 0 0
38874 - 0 0 0 0 0 0 0 0 0 10 10 10
38875 - 22 22 22 42 42 42 66 66 66 86 86 86
38876 - 66 66 66 38 38 38 38 38 38 22 22 22
38877 - 26 26 26 34 34 34 54 54 54 66 66 66
38878 - 86 86 86 70 70 70 46 46 46 26 26 26
38879 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38885 - 0 0 0 0 0 0 0 0 0 0 0 0
38886 - 0 0 0 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 1 0 0 1 0 0 1 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 0 0 0 0 0 0
38891 - 0 0 0 0 0 0 0 0 0 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 0 0 0
38894 - 0 0 0 0 0 0 10 10 10 26 26 26
38895 - 50 50 50 82 82 82 58 58 58 6 6 6
38896 - 2 2 6 2 2 6 2 2 6 2 2 6
38897 - 2 2 6 2 2 6 2 2 6 2 2 6
38898 - 6 6 6 54 54 54 86 86 86 66 66 66
38899 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
38911 - 0 0 0 0 0 0 0 0 0 0 0 0
38912 - 0 0 0 0 0 0 0 0 0 0 0 0
38913 - 0 0 0 0 0 0 0 0 0 0 0 0
38914 - 0 0 0 6 6 6 22 22 22 50 50 50
38915 - 78 78 78 34 34 34 2 2 6 2 2 6
38916 - 2 2 6 2 2 6 2 2 6 2 2 6
38917 - 2 2 6 2 2 6 2 2 6 2 2 6
38918 - 2 2 6 2 2 6 6 6 6 70 70 70
38919 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
38925 - 0 0 0 0 0 0 0 0 0 0 0 0
38926 - 0 0 0 0 0 0 0 0 0 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 1 0 0 1 0 0 1 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 0 0 0 0 0 0 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 6 6 6 18 18 18 42 42 42 82 82 82
38935 - 26 26 26 2 2 6 2 2 6 2 2 6
38936 - 2 2 6 2 2 6 2 2 6 2 2 6
38937 - 2 2 6 2 2 6 2 2 6 14 14 14
38938 - 46 46 46 34 34 34 6 6 6 2 2 6
38939 - 42 42 42 78 78 78 42 42 42 18 18 18
38940 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38945 - 0 0 0 0 0 0 0 0 0 0 0 0
38946 - 0 0 0 0 0 0 0 0 0 0 0 0
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 1 0 0 0 0 0 1 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 0 0 0 0 0 0 0 0 0 0 0 0
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 0 0 0
38954 - 10 10 10 30 30 30 66 66 66 58 58 58
38955 - 2 2 6 2 2 6 2 2 6 2 2 6
38956 - 2 2 6 2 2 6 2 2 6 2 2 6
38957 - 2 2 6 2 2 6 2 2 6 26 26 26
38958 - 86 86 86 101 101 101 46 46 46 10 10 10
38959 - 2 2 6 58 58 58 70 70 70 34 34 34
38960 - 10 10 10 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 0 0 0 0 0 0 0 0 0 0
38965 - 0 0 0 0 0 0 0 0 0 0 0 0
38966 - 0 0 0 0 0 0 0 0 0 0 0 0
38967 - 0 0 0 0 0 0 0 0 0 0 0 0
38968 - 0 0 1 0 0 1 0 0 1 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 0 0 0 0 0 0 0 0 0 0 0 0
38971 - 0 0 0 0 0 0 0 0 0 0 0 0
38972 - 0 0 0 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 0 0 0 0 0 0
38974 - 14 14 14 42 42 42 86 86 86 10 10 10
38975 - 2 2 6 2 2 6 2 2 6 2 2 6
38976 - 2 2 6 2 2 6 2 2 6 2 2 6
38977 - 2 2 6 2 2 6 2 2 6 30 30 30
38978 - 94 94 94 94 94 94 58 58 58 26 26 26
38979 - 2 2 6 6 6 6 78 78 78 54 54 54
38980 - 22 22 22 6 6 6 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 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 0 0 0 0 0 0 0 0 0 0 0 0
38992 - 0 0 0 0 0 0 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 0 0 0 6 6 6
38994 - 22 22 22 62 62 62 62 62 62 2 2 6
38995 - 2 2 6 2 2 6 2 2 6 2 2 6
38996 - 2 2 6 2 2 6 2 2 6 2 2 6
38997 - 2 2 6 2 2 6 2 2 6 26 26 26
38998 - 54 54 54 38 38 38 18 18 18 10 10 10
38999 - 2 2 6 2 2 6 34 34 34 82 82 82
39000 - 38 38 38 14 14 14 0 0 0 0 0 0
39001 - 0 0 0 0 0 0 0 0 0 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 1 0 0 1 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 0 0 0 0 0 0 0 0 0
39011 - 0 0 0 0 0 0 0 0 0 0 0 0
39012 - 0 0 0 0 0 0 0 0 0 0 0 0
39013 - 0 0 0 0 0 0 0 0 0 6 6 6
39014 - 30 30 30 78 78 78 30 30 30 2 2 6
39015 - 2 2 6 2 2 6 2 2 6 2 2 6
39016 - 2 2 6 2 2 6 2 2 6 2 2 6
39017 - 2 2 6 2 2 6 2 2 6 10 10 10
39018 - 10 10 10 2 2 6 2 2 6 2 2 6
39019 - 2 2 6 2 2 6 2 2 6 78 78 78
39020 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39025 - 0 0 0 0 0 0 0 0 0 0 0 0
39026 - 0 0 0 0 0 0 0 0 0 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 1 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 0 0 0
39031 - 0 0 0 0 0 0 0 0 0 0 0 0
39032 - 0 0 0 0 0 0 0 0 0 0 0 0
39033 - 0 0 0 0 0 0 0 0 0 10 10 10
39034 - 38 38 38 86 86 86 14 14 14 2 2 6
39035 - 2 2 6 2 2 6 2 2 6 2 2 6
39036 - 2 2 6 2 2 6 2 2 6 2 2 6
39037 - 2 2 6 2 2 6 2 2 6 2 2 6
39038 - 2 2 6 2 2 6 2 2 6 2 2 6
39039 - 2 2 6 2 2 6 2 2 6 54 54 54
39040 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0
39045 - 0 0 0 0 0 0 0 0 0 0 0 0
39046 - 0 0 0 0 0 0 0 0 0 0 0 0
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 1 0 0 1 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 0 0 0
39050 - 0 0 0 0 0 0 0 0 0 0 0 0
39051 - 0 0 0 0 0 0 0 0 0 0 0 0
39052 - 0 0 0 0 0 0 0 0 0 0 0 0
39053 - 0 0 0 0 0 0 0 0 0 14 14 14
39054 - 42 42 42 82 82 82 2 2 6 2 2 6
39055 - 2 2 6 6 6 6 10 10 10 2 2 6
39056 - 2 2 6 2 2 6 2 2 6 2 2 6
39057 - 2 2 6 2 2 6 2 2 6 6 6 6
39058 - 14 14 14 10 10 10 2 2 6 2 2 6
39059 - 2 2 6 2 2 6 2 2 6 18 18 18
39060 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 0 0 0
39065 - 0 0 0 0 0 0 0 0 0 0 0 0
39066 - 0 0 0 0 0 0 0 0 0 0 0 0
39067 - 0 0 0 0 0 0 0 0 0 0 0 0
39068 - 0 0 1 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 0 0 0 0
39071 - 0 0 0 0 0 0 0 0 0 0 0 0
39072 - 0 0 0 0 0 0 0 0 0 0 0 0
39073 - 0 0 0 0 0 0 0 0 0 14 14 14
39074 - 46 46 46 86 86 86 2 2 6 2 2 6
39075 - 6 6 6 6 6 6 22 22 22 34 34 34
39076 - 6 6 6 2 2 6 2 2 6 2 2 6
39077 - 2 2 6 2 2 6 18 18 18 34 34 34
39078 - 10 10 10 50 50 50 22 22 22 2 2 6
39079 - 2 2 6 2 2 6 2 2 6 10 10 10
39080 - 86 86 86 42 42 42 14 14 14 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 1 0 0 1 0 0 1 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 0 0 0
39091 - 0 0 0 0 0 0 0 0 0 0 0 0
39092 - 0 0 0 0 0 0 0 0 0 0 0 0
39093 - 0 0 0 0 0 0 0 0 0 14 14 14
39094 - 46 46 46 86 86 86 2 2 6 2 2 6
39095 - 38 38 38 116 116 116 94 94 94 22 22 22
39096 - 22 22 22 2 2 6 2 2 6 2 2 6
39097 - 14 14 14 86 86 86 138 138 138 162 162 162
39098 -154 154 154 38 38 38 26 26 26 6 6 6
39099 - 2 2 6 2 2 6 2 2 6 2 2 6
39100 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39110 - 0 0 0 0 0 0 0 0 0 0 0 0
39111 - 0 0 0 0 0 0 0 0 0 0 0 0
39112 - 0 0 0 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 14 14 14
39114 - 46 46 46 86 86 86 2 2 6 14 14 14
39115 -134 134 134 198 198 198 195 195 195 116 116 116
39116 - 10 10 10 2 2 6 2 2 6 6 6 6
39117 -101 98 89 187 187 187 210 210 210 218 218 218
39118 -214 214 214 134 134 134 14 14 14 6 6 6
39119 - 2 2 6 2 2 6 2 2 6 2 2 6
39120 - 86 86 86 50 50 50 18 18 18 6 6 6
39121 - 0 0 0 0 0 0 0 0 0 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 0 0 0
39123 - 0 0 0 0 0 0 0 0 0 0 0 0
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 1 0 0 0
39128 - 0 0 1 0 0 1 0 0 1 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 0 0 0 0
39131 - 0 0 0 0 0 0 0 0 0 0 0 0
39132 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 14 14 14
39134 - 46 46 46 86 86 86 2 2 6 54 54 54
39135 -218 218 218 195 195 195 226 226 226 246 246 246
39136 - 58 58 58 2 2 6 2 2 6 30 30 30
39137 -210 210 210 253 253 253 174 174 174 123 123 123
39138 -221 221 221 234 234 234 74 74 74 2 2 6
39139 - 2 2 6 2 2 6 2 2 6 2 2 6
39140 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39150 - 0 0 0 0 0 0 0 0 0 0 0 0
39151 - 0 0 0 0 0 0 0 0 0 0 0 0
39152 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 14 14 14
39154 - 46 46 46 82 82 82 2 2 6 106 106 106
39155 -170 170 170 26 26 26 86 86 86 226 226 226
39156 -123 123 123 10 10 10 14 14 14 46 46 46
39157 -231 231 231 190 190 190 6 6 6 70 70 70
39158 - 90 90 90 238 238 238 158 158 158 2 2 6
39159 - 2 2 6 2 2 6 2 2 6 2 2 6
39160 - 70 70 70 58 58 58 22 22 22 6 6 6
39161 - 0 0 0 0 0 0 0 0 0 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 1 0 0 0
39168 - 0 0 1 0 0 1 0 0 1 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 14 14 14
39174 - 42 42 42 86 86 86 6 6 6 116 116 116
39175 -106 106 106 6 6 6 70 70 70 149 149 149
39176 -128 128 128 18 18 18 38 38 38 54 54 54
39177 -221 221 221 106 106 106 2 2 6 14 14 14
39178 - 46 46 46 190 190 190 198 198 198 2 2 6
39179 - 2 2 6 2 2 6 2 2 6 2 2 6
39180 - 74 74 74 62 62 62 22 22 22 6 6 6
39181 - 0 0 0 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 0 0 0 0 0 0 0 0 0
39183 - 0 0 0 0 0 0 0 0 0 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 1 0 0 0
39188 - 0 0 1 0 0 0 0 0 1 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 14 14 14
39194 - 42 42 42 94 94 94 14 14 14 101 101 101
39195 -128 128 128 2 2 6 18 18 18 116 116 116
39196 -118 98 46 121 92 8 121 92 8 98 78 10
39197 -162 162 162 106 106 106 2 2 6 2 2 6
39198 - 2 2 6 195 195 195 195 195 195 6 6 6
39199 - 2 2 6 2 2 6 2 2 6 2 2 6
39200 - 74 74 74 62 62 62 22 22 22 6 6 6
39201 - 0 0 0 0 0 0 0 0 0 0 0 0
39202 - 0 0 0 0 0 0 0 0 0 0 0 0
39203 - 0 0 0 0 0 0 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 1 0 0 1
39208 - 0 0 1 0 0 0 0 0 1 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 0 0 0 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 10 10 10
39214 - 38 38 38 90 90 90 14 14 14 58 58 58
39215 -210 210 210 26 26 26 54 38 6 154 114 10
39216 -226 170 11 236 186 11 225 175 15 184 144 12
39217 -215 174 15 175 146 61 37 26 9 2 2 6
39218 - 70 70 70 246 246 246 138 138 138 2 2 6
39219 - 2 2 6 2 2 6 2 2 6 2 2 6
39220 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 10 10 10
39234 - 38 38 38 86 86 86 14 14 14 10 10 10
39235 -195 195 195 188 164 115 192 133 9 225 175 15
39236 -239 182 13 234 190 10 232 195 16 232 200 30
39237 -245 207 45 241 208 19 232 195 16 184 144 12
39238 -218 194 134 211 206 186 42 42 42 2 2 6
39239 - 2 2 6 2 2 6 2 2 6 2 2 6
39240 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 10 10 10
39254 - 34 34 34 86 86 86 14 14 14 2 2 6
39255 -121 87 25 192 133 9 219 162 10 239 182 13
39256 -236 186 11 232 195 16 241 208 19 244 214 54
39257 -246 218 60 246 218 38 246 215 20 241 208 19
39258 -241 208 19 226 184 13 121 87 25 2 2 6
39259 - 2 2 6 2 2 6 2 2 6 2 2 6
39260 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 10 10 10
39274 - 34 34 34 82 82 82 30 30 30 61 42 6
39275 -180 123 7 206 145 10 230 174 11 239 182 13
39276 -234 190 10 238 202 15 241 208 19 246 218 74
39277 -246 218 38 246 215 20 246 215 20 246 215 20
39278 -226 184 13 215 174 15 184 144 12 6 6 6
39279 - 2 2 6 2 2 6 2 2 6 2 2 6
39280 - 26 26 26 94 94 94 42 42 42 14 14 14
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 10 10 10
39294 - 30 30 30 78 78 78 50 50 50 104 69 6
39295 -192 133 9 216 158 10 236 178 12 236 186 11
39296 -232 195 16 241 208 19 244 214 54 245 215 43
39297 -246 215 20 246 215 20 241 208 19 198 155 10
39298 -200 144 11 216 158 10 156 118 10 2 2 6
39299 - 2 2 6 2 2 6 2 2 6 2 2 6
39300 - 6 6 6 90 90 90 54 54 54 18 18 18
39301 - 6 6 6 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 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 10 10 10
39314 - 30 30 30 78 78 78 46 46 46 22 22 22
39315 -137 92 6 210 162 10 239 182 13 238 190 10
39316 -238 202 15 241 208 19 246 215 20 246 215 20
39317 -241 208 19 203 166 17 185 133 11 210 150 10
39318 -216 158 10 210 150 10 102 78 10 2 2 6
39319 - 6 6 6 54 54 54 14 14 14 2 2 6
39320 - 2 2 6 62 62 62 74 74 74 30 30 30
39321 - 10 10 10 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 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 10 10 10
39334 - 34 34 34 78 78 78 50 50 50 6 6 6
39335 - 94 70 30 139 102 15 190 146 13 226 184 13
39336 -232 200 30 232 195 16 215 174 15 190 146 13
39337 -168 122 10 192 133 9 210 150 10 213 154 11
39338 -202 150 34 182 157 106 101 98 89 2 2 6
39339 - 2 2 6 78 78 78 116 116 116 58 58 58
39340 - 2 2 6 22 22 22 90 90 90 46 46 46
39341 - 18 18 18 6 6 6 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 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 10 10 10
39354 - 38 38 38 86 86 86 50 50 50 6 6 6
39355 -128 128 128 174 154 114 156 107 11 168 122 10
39356 -198 155 10 184 144 12 197 138 11 200 144 11
39357 -206 145 10 206 145 10 197 138 11 188 164 115
39358 -195 195 195 198 198 198 174 174 174 14 14 14
39359 - 2 2 6 22 22 22 116 116 116 116 116 116
39360 - 22 22 22 2 2 6 74 74 74 70 70 70
39361 - 30 30 30 10 10 10 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 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 6 6 6 18 18 18
39374 - 50 50 50 101 101 101 26 26 26 10 10 10
39375 -138 138 138 190 190 190 174 154 114 156 107 11
39376 -197 138 11 200 144 11 197 138 11 192 133 9
39377 -180 123 7 190 142 34 190 178 144 187 187 187
39378 -202 202 202 221 221 221 214 214 214 66 66 66
39379 - 2 2 6 2 2 6 50 50 50 62 62 62
39380 - 6 6 6 2 2 6 10 10 10 90 90 90
39381 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 10 10 10 34 34 34
39394 - 74 74 74 74 74 74 2 2 6 6 6 6
39395 -144 144 144 198 198 198 190 190 190 178 166 146
39396 -154 121 60 156 107 11 156 107 11 168 124 44
39397 -174 154 114 187 187 187 190 190 190 210 210 210
39398 -246 246 246 253 253 253 253 253 253 182 182 182
39399 - 6 6 6 2 2 6 2 2 6 2 2 6
39400 - 2 2 6 2 2 6 2 2 6 62 62 62
39401 - 74 74 74 34 34 34 14 14 14 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 10 10 10 22 22 22 54 54 54
39414 - 94 94 94 18 18 18 2 2 6 46 46 46
39415 -234 234 234 221 221 221 190 190 190 190 190 190
39416 -190 190 190 187 187 187 187 187 187 190 190 190
39417 -190 190 190 195 195 195 214 214 214 242 242 242
39418 -253 253 253 253 253 253 253 253 253 253 253 253
39419 - 82 82 82 2 2 6 2 2 6 2 2 6
39420 - 2 2 6 2 2 6 2 2 6 14 14 14
39421 - 86 86 86 54 54 54 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 6 6 6 18 18 18 46 46 46 90 90 90
39434 - 46 46 46 18 18 18 6 6 6 182 182 182
39435 -253 253 253 246 246 246 206 206 206 190 190 190
39436 -190 190 190 190 190 190 190 190 190 190 190 190
39437 -206 206 206 231 231 231 250 250 250 253 253 253
39438 -253 253 253 253 253 253 253 253 253 253 253 253
39439 -202 202 202 14 14 14 2 2 6 2 2 6
39440 - 2 2 6 2 2 6 2 2 6 2 2 6
39441 - 42 42 42 86 86 86 42 42 42 18 18 18
39442 - 6 6 6 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 6 6 6
39453 - 14 14 14 38 38 38 74 74 74 66 66 66
39454 - 2 2 6 6 6 6 90 90 90 250 250 250
39455 -253 253 253 253 253 253 238 238 238 198 198 198
39456 -190 190 190 190 190 190 195 195 195 221 221 221
39457 -246 246 246 253 253 253 253 253 253 253 253 253
39458 -253 253 253 253 253 253 253 253 253 253 253 253
39459 -253 253 253 82 82 82 2 2 6 2 2 6
39460 - 2 2 6 2 2 6 2 2 6 2 2 6
39461 - 2 2 6 78 78 78 70 70 70 34 34 34
39462 - 14 14 14 6 6 6 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 0 0 0
39469 - 0 0 0 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 14 14 14
39473 - 34 34 34 66 66 66 78 78 78 6 6 6
39474 - 2 2 6 18 18 18 218 218 218 253 253 253
39475 -253 253 253 253 253 253 253 253 253 246 246 246
39476 -226 226 226 231 231 231 246 246 246 253 253 253
39477 -253 253 253 253 253 253 253 253 253 253 253 253
39478 -253 253 253 253 253 253 253 253 253 253 253 253
39479 -253 253 253 178 178 178 2 2 6 2 2 6
39480 - 2 2 6 2 2 6 2 2 6 2 2 6
39481 - 2 2 6 18 18 18 90 90 90 62 62 62
39482 - 30 30 30 10 10 10 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 0 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 10 10 10 26 26 26
39493 - 58 58 58 90 90 90 18 18 18 2 2 6
39494 - 2 2 6 110 110 110 253 253 253 253 253 253
39495 -253 253 253 253 253 253 253 253 253 253 253 253
39496 -250 250 250 253 253 253 253 253 253 253 253 253
39497 -253 253 253 253 253 253 253 253 253 253 253 253
39498 -253 253 253 253 253 253 253 253 253 253 253 253
39499 -253 253 253 231 231 231 18 18 18 2 2 6
39500 - 2 2 6 2 2 6 2 2 6 2 2 6
39501 - 2 2 6 2 2 6 18 18 18 94 94 94
39502 - 54 54 54 26 26 26 10 10 10 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 0 0 0 0 0 0 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 6 6 6 22 22 22 50 50 50
39513 - 90 90 90 26 26 26 2 2 6 2 2 6
39514 - 14 14 14 195 195 195 250 250 250 253 253 253
39515 -253 253 253 253 253 253 253 253 253 253 253 253
39516 -253 253 253 253 253 253 253 253 253 253 253 253
39517 -253 253 253 253 253 253 253 253 253 253 253 253
39518 -253 253 253 253 253 253 253 253 253 253 253 253
39519 -250 250 250 242 242 242 54 54 54 2 2 6
39520 - 2 2 6 2 2 6 2 2 6 2 2 6
39521 - 2 2 6 2 2 6 2 2 6 38 38 38
39522 - 86 86 86 50 50 50 22 22 22 6 6 6
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 6 6 6 14 14 14 38 38 38 82 82 82
39533 - 34 34 34 2 2 6 2 2 6 2 2 6
39534 - 42 42 42 195 195 195 246 246 246 253 253 253
39535 -253 253 253 253 253 253 253 253 253 250 250 250
39536 -242 242 242 242 242 242 250 250 250 253 253 253
39537 -253 253 253 253 253 253 253 253 253 253 253 253
39538 -253 253 253 250 250 250 246 246 246 238 238 238
39539 -226 226 226 231 231 231 101 101 101 6 6 6
39540 - 2 2 6 2 2 6 2 2 6 2 2 6
39541 - 2 2 6 2 2 6 2 2 6 2 2 6
39542 - 38 38 38 82 82 82 42 42 42 14 14 14
39543 - 6 6 6 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 10 10 10 26 26 26 62 62 62 66 66 66
39553 - 2 2 6 2 2 6 2 2 6 6 6 6
39554 - 70 70 70 170 170 170 206 206 206 234 234 234
39555 -246 246 246 250 250 250 250 250 250 238 238 238
39556 -226 226 226 231 231 231 238 238 238 250 250 250
39557 -250 250 250 250 250 250 246 246 246 231 231 231
39558 -214 214 214 206 206 206 202 202 202 202 202 202
39559 -198 198 198 202 202 202 182 182 182 18 18 18
39560 - 2 2 6 2 2 6 2 2 6 2 2 6
39561 - 2 2 6 2 2 6 2 2 6 2 2 6
39562 - 2 2 6 62 62 62 66 66 66 30 30 30
39563 - 10 10 10 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 14 14 14 42 42 42 82 82 82 18 18 18
39573 - 2 2 6 2 2 6 2 2 6 10 10 10
39574 - 94 94 94 182 182 182 218 218 218 242 242 242
39575 -250 250 250 253 253 253 253 253 253 250 250 250
39576 -234 234 234 253 253 253 253 253 253 253 253 253
39577 -253 253 253 253 253 253 253 253 253 246 246 246
39578 -238 238 238 226 226 226 210 210 210 202 202 202
39579 -195 195 195 195 195 195 210 210 210 158 158 158
39580 - 6 6 6 14 14 14 50 50 50 14 14 14
39581 - 2 2 6 2 2 6 2 2 6 2 2 6
39582 - 2 2 6 6 6 6 86 86 86 46 46 46
39583 - 18 18 18 6 6 6 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 6 6 6
39592 - 22 22 22 54 54 54 70 70 70 2 2 6
39593 - 2 2 6 10 10 10 2 2 6 22 22 22
39594 -166 166 166 231 231 231 250 250 250 253 253 253
39595 -253 253 253 253 253 253 253 253 253 250 250 250
39596 -242 242 242 253 253 253 253 253 253 253 253 253
39597 -253 253 253 253 253 253 253 253 253 253 253 253
39598 -253 253 253 253 253 253 253 253 253 246 246 246
39599 -231 231 231 206 206 206 198 198 198 226 226 226
39600 - 94 94 94 2 2 6 6 6 6 38 38 38
39601 - 30 30 30 2 2 6 2 2 6 2 2 6
39602 - 2 2 6 2 2 6 62 62 62 66 66 66
39603 - 26 26 26 10 10 10 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 10 10 10
39612 - 30 30 30 74 74 74 50 50 50 2 2 6
39613 - 26 26 26 26 26 26 2 2 6 106 106 106
39614 -238 238 238 253 253 253 253 253 253 253 253 253
39615 -253 253 253 253 253 253 253 253 253 253 253 253
39616 -253 253 253 253 253 253 253 253 253 253 253 253
39617 -253 253 253 253 253 253 253 253 253 253 253 253
39618 -253 253 253 253 253 253 253 253 253 253 253 253
39619 -253 253 253 246 246 246 218 218 218 202 202 202
39620 -210 210 210 14 14 14 2 2 6 2 2 6
39621 - 30 30 30 22 22 22 2 2 6 2 2 6
39622 - 2 2 6 2 2 6 18 18 18 86 86 86
39623 - 42 42 42 14 14 14 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 14 14 14
39632 - 42 42 42 90 90 90 22 22 22 2 2 6
39633 - 42 42 42 2 2 6 18 18 18 218 218 218
39634 -253 253 253 253 253 253 253 253 253 253 253 253
39635 -253 253 253 253 253 253 253 253 253 253 253 253
39636 -253 253 253 253 253 253 253 253 253 253 253 253
39637 -253 253 253 253 253 253 253 253 253 253 253 253
39638 -253 253 253 253 253 253 253 253 253 253 253 253
39639 -253 253 253 253 253 253 250 250 250 221 221 221
39640 -218 218 218 101 101 101 2 2 6 14 14 14
39641 - 18 18 18 38 38 38 10 10 10 2 2 6
39642 - 2 2 6 2 2 6 2 2 6 78 78 78
39643 - 58 58 58 22 22 22 6 6 6 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 6 6 6 18 18 18
39652 - 54 54 54 82 82 82 2 2 6 26 26 26
39653 - 22 22 22 2 2 6 123 123 123 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 253 253 253
39656 -253 253 253 253 253 253 253 253 253 253 253 253
39657 -253 253 253 253 253 253 253 253 253 253 253 253
39658 -253 253 253 253 253 253 253 253 253 253 253 253
39659 -253 253 253 253 253 253 253 253 253 250 250 250
39660 -238 238 238 198 198 198 6 6 6 38 38 38
39661 - 58 58 58 26 26 26 38 38 38 2 2 6
39662 - 2 2 6 2 2 6 2 2 6 46 46 46
39663 - 78 78 78 30 30 30 10 10 10 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 10 10 10 30 30 30
39672 - 74 74 74 58 58 58 2 2 6 42 42 42
39673 - 2 2 6 22 22 22 231 231 231 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 250 250 250
39676 -253 253 253 253 253 253 253 253 253 253 253 253
39677 -253 253 253 253 253 253 253 253 253 253 253 253
39678 -253 253 253 253 253 253 253 253 253 253 253 253
39679 -253 253 253 253 253 253 253 253 253 253 253 253
39680 -253 253 253 246 246 246 46 46 46 38 38 38
39681 - 42 42 42 14 14 14 38 38 38 14 14 14
39682 - 2 2 6 2 2 6 2 2 6 6 6 6
39683 - 86 86 86 46 46 46 14 14 14 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 6 6 6 14 14 14 42 42 42
39692 - 90 90 90 18 18 18 18 18 18 26 26 26
39693 - 2 2 6 116 116 116 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 250 250 250 238 238 238
39696 -253 253 253 253 253 253 253 253 253 253 253 253
39697 -253 253 253 253 253 253 253 253 253 253 253 253
39698 -253 253 253 253 253 253 253 253 253 253 253 253
39699 -253 253 253 253 253 253 253 253 253 253 253 253
39700 -253 253 253 253 253 253 94 94 94 6 6 6
39701 - 2 2 6 2 2 6 10 10 10 34 34 34
39702 - 2 2 6 2 2 6 2 2 6 2 2 6
39703 - 74 74 74 58 58 58 22 22 22 6 6 6
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 10 10 10 26 26 26 66 66 66
39712 - 82 82 82 2 2 6 38 38 38 6 6 6
39713 - 14 14 14 210 210 210 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 246 246 246 242 242 242
39716 -253 253 253 253 253 253 253 253 253 253 253 253
39717 -253 253 253 253 253 253 253 253 253 253 253 253
39718 -253 253 253 253 253 253 253 253 253 253 253 253
39719 -253 253 253 253 253 253 253 253 253 253 253 253
39720 -253 253 253 253 253 253 144 144 144 2 2 6
39721 - 2 2 6 2 2 6 2 2 6 46 46 46
39722 - 2 2 6 2 2 6 2 2 6 2 2 6
39723 - 42 42 42 74 74 74 30 30 30 10 10 10
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 6 6 6 14 14 14 42 42 42 90 90 90
39732 - 26 26 26 6 6 6 42 42 42 2 2 6
39733 - 74 74 74 250 250 250 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 242 242 242 242 242 242
39736 -253 253 253 253 253 253 253 253 253 253 253 253
39737 -253 253 253 253 253 253 253 253 253 253 253 253
39738 -253 253 253 253 253 253 253 253 253 253 253 253
39739 -253 253 253 253 253 253 253 253 253 253 253 253
39740 -253 253 253 253 253 253 182 182 182 2 2 6
39741 - 2 2 6 2 2 6 2 2 6 46 46 46
39742 - 2 2 6 2 2 6 2 2 6 2 2 6
39743 - 10 10 10 86 86 86 38 38 38 10 10 10
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 10 10 10 26 26 26 66 66 66 82 82 82
39752 - 2 2 6 22 22 22 18 18 18 2 2 6
39753 -149 149 149 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 234 234 234 242 242 242
39756 -253 253 253 253 253 253 253 253 253 253 253 253
39757 -253 253 253 253 253 253 253 253 253 253 253 253
39758 -253 253 253 253 253 253 253 253 253 253 253 253
39759 -253 253 253 253 253 253 253 253 253 253 253 253
39760 -253 253 253 253 253 253 206 206 206 2 2 6
39761 - 2 2 6 2 2 6 2 2 6 38 38 38
39762 - 2 2 6 2 2 6 2 2 6 2 2 6
39763 - 6 6 6 86 86 86 46 46 46 14 14 14
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 6 6 6
39771 - 18 18 18 46 46 46 86 86 86 18 18 18
39772 - 2 2 6 34 34 34 10 10 10 6 6 6
39773 -210 210 210 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 234 234 234 242 242 242
39776 -253 253 253 253 253 253 253 253 253 253 253 253
39777 -253 253 253 253 253 253 253 253 253 253 253 253
39778 -253 253 253 253 253 253 253 253 253 253 253 253
39779 -253 253 253 253 253 253 253 253 253 253 253 253
39780 -253 253 253 253 253 253 221 221 221 6 6 6
39781 - 2 2 6 2 2 6 6 6 6 30 30 30
39782 - 2 2 6 2 2 6 2 2 6 2 2 6
39783 - 2 2 6 82 82 82 54 54 54 18 18 18
39784 - 6 6 6 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 10 10 10
39791 - 26 26 26 66 66 66 62 62 62 2 2 6
39792 - 2 2 6 38 38 38 10 10 10 26 26 26
39793 -238 238 238 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 231 231 231 238 238 238
39796 -253 253 253 253 253 253 253 253 253 253 253 253
39797 -253 253 253 253 253 253 253 253 253 253 253 253
39798 -253 253 253 253 253 253 253 253 253 253 253 253
39799 -253 253 253 253 253 253 253 253 253 253 253 253
39800 -253 253 253 253 253 253 231 231 231 6 6 6
39801 - 2 2 6 2 2 6 10 10 10 30 30 30
39802 - 2 2 6 2 2 6 2 2 6 2 2 6
39803 - 2 2 6 66 66 66 58 58 58 22 22 22
39804 - 6 6 6 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 10 10 10
39811 - 38 38 38 78 78 78 6 6 6 2 2 6
39812 - 2 2 6 46 46 46 14 14 14 42 42 42
39813 -246 246 246 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 231 231 231 242 242 242
39816 -253 253 253 253 253 253 253 253 253 253 253 253
39817 -253 253 253 253 253 253 253 253 253 253 253 253
39818 -253 253 253 253 253 253 253 253 253 253 253 253
39819 -253 253 253 253 253 253 253 253 253 253 253 253
39820 -253 253 253 253 253 253 234 234 234 10 10 10
39821 - 2 2 6 2 2 6 22 22 22 14 14 14
39822 - 2 2 6 2 2 6 2 2 6 2 2 6
39823 - 2 2 6 66 66 66 62 62 62 22 22 22
39824 - 6 6 6 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 6 6 6 18 18 18
39831 - 50 50 50 74 74 74 2 2 6 2 2 6
39832 - 14 14 14 70 70 70 34 34 34 62 62 62
39833 -250 250 250 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 231 231 231 246 246 246
39836 -253 253 253 253 253 253 253 253 253 253 253 253
39837 -253 253 253 253 253 253 253 253 253 253 253 253
39838 -253 253 253 253 253 253 253 253 253 253 253 253
39839 -253 253 253 253 253 253 253 253 253 253 253 253
39840 -253 253 253 253 253 253 234 234 234 14 14 14
39841 - 2 2 6 2 2 6 30 30 30 2 2 6
39842 - 2 2 6 2 2 6 2 2 6 2 2 6
39843 - 2 2 6 66 66 66 62 62 62 22 22 22
39844 - 6 6 6 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 6 6 6 18 18 18
39851 - 54 54 54 62 62 62 2 2 6 2 2 6
39852 - 2 2 6 30 30 30 46 46 46 70 70 70
39853 -250 250 250 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 231 231 231 246 246 246
39856 -253 253 253 253 253 253 253 253 253 253 253 253
39857 -253 253 253 253 253 253 253 253 253 253 253 253
39858 -253 253 253 253 253 253 253 253 253 253 253 253
39859 -253 253 253 253 253 253 253 253 253 253 253 253
39860 -253 253 253 253 253 253 226 226 226 10 10 10
39861 - 2 2 6 6 6 6 30 30 30 2 2 6
39862 - 2 2 6 2 2 6 2 2 6 2 2 6
39863 - 2 2 6 66 66 66 58 58 58 22 22 22
39864 - 6 6 6 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 6 6 6 22 22 22
39871 - 58 58 58 62 62 62 2 2 6 2 2 6
39872 - 2 2 6 2 2 6 30 30 30 78 78 78
39873 -250 250 250 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 231 231 231 246 246 246
39876 -253 253 253 253 253 253 253 253 253 253 253 253
39877 -253 253 253 253 253 253 253 253 253 253 253 253
39878 -253 253 253 253 253 253 253 253 253 253 253 253
39879 -253 253 253 253 253 253 253 253 253 253 253 253
39880 -253 253 253 253 253 253 206 206 206 2 2 6
39881 - 22 22 22 34 34 34 18 14 6 22 22 22
39882 - 26 26 26 18 18 18 6 6 6 2 2 6
39883 - 2 2 6 82 82 82 54 54 54 18 18 18
39884 - 6 6 6 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 6 6 6 26 26 26
39891 - 62 62 62 106 106 106 74 54 14 185 133 11
39892 -210 162 10 121 92 8 6 6 6 62 62 62
39893 -238 238 238 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 231 231 231 246 246 246
39896 -253 253 253 253 253 253 253 253 253 253 253 253
39897 -253 253 253 253 253 253 253 253 253 253 253 253
39898 -253 253 253 253 253 253 253 253 253 253 253 253
39899 -253 253 253 253 253 253 253 253 253 253 253 253
39900 -253 253 253 253 253 253 158 158 158 18 18 18
39901 - 14 14 14 2 2 6 2 2 6 2 2 6
39902 - 6 6 6 18 18 18 66 66 66 38 38 38
39903 - 6 6 6 94 94 94 50 50 50 18 18 18
39904 - 6 6 6 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 6 6 6
39910 - 10 10 10 10 10 10 18 18 18 38 38 38
39911 - 78 78 78 142 134 106 216 158 10 242 186 14
39912 -246 190 14 246 190 14 156 118 10 10 10 10
39913 - 90 90 90 238 238 238 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 231 231 231 250 250 250
39916 -253 253 253 253 253 253 253 253 253 253 253 253
39917 -253 253 253 253 253 253 253 253 253 253 253 253
39918 -253 253 253 253 253 253 253 253 253 253 253 253
39919 -253 253 253 253 253 253 253 253 253 246 230 190
39920 -238 204 91 238 204 91 181 142 44 37 26 9
39921 - 2 2 6 2 2 6 2 2 6 2 2 6
39922 - 2 2 6 2 2 6 38 38 38 46 46 46
39923 - 26 26 26 106 106 106 54 54 54 18 18 18
39924 - 6 6 6 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 6 6 6 14 14 14 22 22 22
39930 - 30 30 30 38 38 38 50 50 50 70 70 70
39931 -106 106 106 190 142 34 226 170 11 242 186 14
39932 -246 190 14 246 190 14 246 190 14 154 114 10
39933 - 6 6 6 74 74 74 226 226 226 253 253 253
39934 -253 253 253 253 253 253 253 253 253 253 253 253
39935 -253 253 253 253 253 253 231 231 231 250 250 250
39936 -253 253 253 253 253 253 253 253 253 253 253 253
39937 -253 253 253 253 253 253 253 253 253 253 253 253
39938 -253 253 253 253 253 253 253 253 253 253 253 253
39939 -253 253 253 253 253 253 253 253 253 228 184 62
39940 -241 196 14 241 208 19 232 195 16 38 30 10
39941 - 2 2 6 2 2 6 2 2 6 2 2 6
39942 - 2 2 6 6 6 6 30 30 30 26 26 26
39943 -203 166 17 154 142 90 66 66 66 26 26 26
39944 - 6 6 6 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 6 6 6 18 18 18 38 38 38 58 58 58
39950 - 78 78 78 86 86 86 101 101 101 123 123 123
39951 -175 146 61 210 150 10 234 174 13 246 186 14
39952 -246 190 14 246 190 14 246 190 14 238 190 10
39953 -102 78 10 2 2 6 46 46 46 198 198 198
39954 -253 253 253 253 253 253 253 253 253 253 253 253
39955 -253 253 253 253 253 253 234 234 234 242 242 242
39956 -253 253 253 253 253 253 253 253 253 253 253 253
39957 -253 253 253 253 253 253 253 253 253 253 253 253
39958 -253 253 253 253 253 253 253 253 253 253 253 253
39959 -253 253 253 253 253 253 253 253 253 224 178 62
39960 -242 186 14 241 196 14 210 166 10 22 18 6
39961 - 2 2 6 2 2 6 2 2 6 2 2 6
39962 - 2 2 6 2 2 6 6 6 6 121 92 8
39963 -238 202 15 232 195 16 82 82 82 34 34 34
39964 - 10 10 10 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 14 14 14 38 38 38 70 70 70 154 122 46
39970 -190 142 34 200 144 11 197 138 11 197 138 11
39971 -213 154 11 226 170 11 242 186 14 246 190 14
39972 -246 190 14 246 190 14 246 190 14 246 190 14
39973 -225 175 15 46 32 6 2 2 6 22 22 22
39974 -158 158 158 250 250 250 253 253 253 253 253 253
39975 -253 253 253 253 253 253 253 253 253 253 253 253
39976 -253 253 253 253 253 253 253 253 253 253 253 253
39977 -253 253 253 253 253 253 253 253 253 253 253 253
39978 -253 253 253 253 253 253 253 253 253 253 253 253
39979 -253 253 253 250 250 250 242 242 242 224 178 62
39980 -239 182 13 236 186 11 213 154 11 46 32 6
39981 - 2 2 6 2 2 6 2 2 6 2 2 6
39982 - 2 2 6 2 2 6 61 42 6 225 175 15
39983 -238 190 10 236 186 11 112 100 78 42 42 42
39984 - 14 14 14 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 6 6 6
39989 - 22 22 22 54 54 54 154 122 46 213 154 11
39990 -226 170 11 230 174 11 226 170 11 226 170 11
39991 -236 178 12 242 186 14 246 190 14 246 190 14
39992 -246 190 14 246 190 14 246 190 14 246 190 14
39993 -241 196 14 184 144 12 10 10 10 2 2 6
39994 - 6 6 6 116 116 116 242 242 242 253 253 253
39995 -253 253 253 253 253 253 253 253 253 253 253 253
39996 -253 253 253 253 253 253 253 253 253 253 253 253
39997 -253 253 253 253 253 253 253 253 253 253 253 253
39998 -253 253 253 253 253 253 253 253 253 253 253 253
39999 -253 253 253 231 231 231 198 198 198 214 170 54
40000 -236 178 12 236 178 12 210 150 10 137 92 6
40001 - 18 14 6 2 2 6 2 2 6 2 2 6
40002 - 6 6 6 70 47 6 200 144 11 236 178 12
40003 -239 182 13 239 182 13 124 112 88 58 58 58
40004 - 22 22 22 6 6 6 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 10 10 10
40009 - 30 30 30 70 70 70 180 133 36 226 170 11
40010 -239 182 13 242 186 14 242 186 14 246 186 14
40011 -246 190 14 246 190 14 246 190 14 246 190 14
40012 -246 190 14 246 190 14 246 190 14 246 190 14
40013 -246 190 14 232 195 16 98 70 6 2 2 6
40014 - 2 2 6 2 2 6 66 66 66 221 221 221
40015 -253 253 253 253 253 253 253 253 253 253 253 253
40016 -253 253 253 253 253 253 253 253 253 253 253 253
40017 -253 253 253 253 253 253 253 253 253 253 253 253
40018 -253 253 253 253 253 253 253 253 253 253 253 253
40019 -253 253 253 206 206 206 198 198 198 214 166 58
40020 -230 174 11 230 174 11 216 158 10 192 133 9
40021 -163 110 8 116 81 8 102 78 10 116 81 8
40022 -167 114 7 197 138 11 226 170 11 239 182 13
40023 -242 186 14 242 186 14 162 146 94 78 78 78
40024 - 34 34 34 14 14 14 6 6 6 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 6 6 6
40029 - 30 30 30 78 78 78 190 142 34 226 170 11
40030 -239 182 13 246 190 14 246 190 14 246 190 14
40031 -246 190 14 246 190 14 246 190 14 246 190 14
40032 -246 190 14 246 190 14 246 190 14 246 190 14
40033 -246 190 14 241 196 14 203 166 17 22 18 6
40034 - 2 2 6 2 2 6 2 2 6 38 38 38
40035 -218 218 218 253 253 253 253 253 253 253 253 253
40036 -253 253 253 253 253 253 253 253 253 253 253 253
40037 -253 253 253 253 253 253 253 253 253 253 253 253
40038 -253 253 253 253 253 253 253 253 253 253 253 253
40039 -250 250 250 206 206 206 198 198 198 202 162 69
40040 -226 170 11 236 178 12 224 166 10 210 150 10
40041 -200 144 11 197 138 11 192 133 9 197 138 11
40042 -210 150 10 226 170 11 242 186 14 246 190 14
40043 -246 190 14 246 186 14 225 175 15 124 112 88
40044 - 62 62 62 30 30 30 14 14 14 6 6 6
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 10 10 10
40049 - 30 30 30 78 78 78 174 135 50 224 166 10
40050 -239 182 13 246 190 14 246 190 14 246 190 14
40051 -246 190 14 246 190 14 246 190 14 246 190 14
40052 -246 190 14 246 190 14 246 190 14 246 190 14
40053 -246 190 14 246 190 14 241 196 14 139 102 15
40054 - 2 2 6 2 2 6 2 2 6 2 2 6
40055 - 78 78 78 250 250 250 253 253 253 253 253 253
40056 -253 253 253 253 253 253 253 253 253 253 253 253
40057 -253 253 253 253 253 253 253 253 253 253 253 253
40058 -253 253 253 253 253 253 253 253 253 253 253 253
40059 -250 250 250 214 214 214 198 198 198 190 150 46
40060 -219 162 10 236 178 12 234 174 13 224 166 10
40061 -216 158 10 213 154 11 213 154 11 216 158 10
40062 -226 170 11 239 182 13 246 190 14 246 190 14
40063 -246 190 14 246 190 14 242 186 14 206 162 42
40064 -101 101 101 58 58 58 30 30 30 14 14 14
40065 - 6 6 6 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 10 10 10
40069 - 30 30 30 74 74 74 174 135 50 216 158 10
40070 -236 178 12 246 190 14 246 190 14 246 190 14
40071 -246 190 14 246 190 14 246 190 14 246 190 14
40072 -246 190 14 246 190 14 246 190 14 246 190 14
40073 -246 190 14 246 190 14 241 196 14 226 184 13
40074 - 61 42 6 2 2 6 2 2 6 2 2 6
40075 - 22 22 22 238 238 238 253 253 253 253 253 253
40076 -253 253 253 253 253 253 253 253 253 253 253 253
40077 -253 253 253 253 253 253 253 253 253 253 253 253
40078 -253 253 253 253 253 253 253 253 253 253 253 253
40079 -253 253 253 226 226 226 187 187 187 180 133 36
40080 -216 158 10 236 178 12 239 182 13 236 178 12
40081 -230 174 11 226 170 11 226 170 11 230 174 11
40082 -236 178 12 242 186 14 246 190 14 246 190 14
40083 -246 190 14 246 190 14 246 186 14 239 182 13
40084 -206 162 42 106 106 106 66 66 66 34 34 34
40085 - 14 14 14 6 6 6 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 6 6 6
40089 - 26 26 26 70 70 70 163 133 67 213 154 11
40090 -236 178 12 246 190 14 246 190 14 246 190 14
40091 -246 190 14 246 190 14 246 190 14 246 190 14
40092 -246 190 14 246 190 14 246 190 14 246 190 14
40093 -246 190 14 246 190 14 246 190 14 241 196 14
40094 -190 146 13 18 14 6 2 2 6 2 2 6
40095 - 46 46 46 246 246 246 253 253 253 253 253 253
40096 -253 253 253 253 253 253 253 253 253 253 253 253
40097 -253 253 253 253 253 253 253 253 253 253 253 253
40098 -253 253 253 253 253 253 253 253 253 253 253 253
40099 -253 253 253 221 221 221 86 86 86 156 107 11
40100 -216 158 10 236 178 12 242 186 14 246 186 14
40101 -242 186 14 239 182 13 239 182 13 242 186 14
40102 -242 186 14 246 186 14 246 190 14 246 190 14
40103 -246 190 14 246 190 14 246 190 14 246 190 14
40104 -242 186 14 225 175 15 142 122 72 66 66 66
40105 - 30 30 30 10 10 10 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 6 6 6
40109 - 26 26 26 70 70 70 163 133 67 210 150 10
40110 -236 178 12 246 190 14 246 190 14 246 190 14
40111 -246 190 14 246 190 14 246 190 14 246 190 14
40112 -246 190 14 246 190 14 246 190 14 246 190 14
40113 -246 190 14 246 190 14 246 190 14 246 190 14
40114 -232 195 16 121 92 8 34 34 34 106 106 106
40115 -221 221 221 253 253 253 253 253 253 253 253 253
40116 -253 253 253 253 253 253 253 253 253 253 253 253
40117 -253 253 253 253 253 253 253 253 253 253 253 253
40118 -253 253 253 253 253 253 253 253 253 253 253 253
40119 -242 242 242 82 82 82 18 14 6 163 110 8
40120 -216 158 10 236 178 12 242 186 14 246 190 14
40121 -246 190 14 246 190 14 246 190 14 246 190 14
40122 -246 190 14 246 190 14 246 190 14 246 190 14
40123 -246 190 14 246 190 14 246 190 14 246 190 14
40124 -246 190 14 246 190 14 242 186 14 163 133 67
40125 - 46 46 46 18 18 18 6 6 6 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 10 10 10
40129 - 30 30 30 78 78 78 163 133 67 210 150 10
40130 -236 178 12 246 186 14 246 190 14 246 190 14
40131 -246 190 14 246 190 14 246 190 14 246 190 14
40132 -246 190 14 246 190 14 246 190 14 246 190 14
40133 -246 190 14 246 190 14 246 190 14 246 190 14
40134 -241 196 14 215 174 15 190 178 144 253 253 253
40135 -253 253 253 253 253 253 253 253 253 253 253 253
40136 -253 253 253 253 253 253 253 253 253 253 253 253
40137 -253 253 253 253 253 253 253 253 253 253 253 253
40138 -253 253 253 253 253 253 253 253 253 218 218 218
40139 - 58 58 58 2 2 6 22 18 6 167 114 7
40140 -216 158 10 236 178 12 246 186 14 246 190 14
40141 -246 190 14 246 190 14 246 190 14 246 190 14
40142 -246 190 14 246 190 14 246 190 14 246 190 14
40143 -246 190 14 246 190 14 246 190 14 246 190 14
40144 -246 190 14 246 186 14 242 186 14 190 150 46
40145 - 54 54 54 22 22 22 6 6 6 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 14 14 14
40149 - 38 38 38 86 86 86 180 133 36 213 154 11
40150 -236 178 12 246 186 14 246 190 14 246 190 14
40151 -246 190 14 246 190 14 246 190 14 246 190 14
40152 -246 190 14 246 190 14 246 190 14 246 190 14
40153 -246 190 14 246 190 14 246 190 14 246 190 14
40154 -246 190 14 232 195 16 190 146 13 214 214 214
40155 -253 253 253 253 253 253 253 253 253 253 253 253
40156 -253 253 253 253 253 253 253 253 253 253 253 253
40157 -253 253 253 253 253 253 253 253 253 253 253 253
40158 -253 253 253 250 250 250 170 170 170 26 26 26
40159 - 2 2 6 2 2 6 37 26 9 163 110 8
40160 -219 162 10 239 182 13 246 186 14 246 190 14
40161 -246 190 14 246 190 14 246 190 14 246 190 14
40162 -246 190 14 246 190 14 246 190 14 246 190 14
40163 -246 190 14 246 190 14 246 190 14 246 190 14
40164 -246 186 14 236 178 12 224 166 10 142 122 72
40165 - 46 46 46 18 18 18 6 6 6 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 6 6 6 18 18 18
40169 - 50 50 50 109 106 95 192 133 9 224 166 10
40170 -242 186 14 246 190 14 246 190 14 246 190 14
40171 -246 190 14 246 190 14 246 190 14 246 190 14
40172 -246 190 14 246 190 14 246 190 14 246 190 14
40173 -246 190 14 246 190 14 246 190 14 246 190 14
40174 -242 186 14 226 184 13 210 162 10 142 110 46
40175 -226 226 226 253 253 253 253 253 253 253 253 253
40176 -253 253 253 253 253 253 253 253 253 253 253 253
40177 -253 253 253 253 253 253 253 253 253 253 253 253
40178 -198 198 198 66 66 66 2 2 6 2 2 6
40179 - 2 2 6 2 2 6 50 34 6 156 107 11
40180 -219 162 10 239 182 13 246 186 14 246 190 14
40181 -246 190 14 246 190 14 246 190 14 246 190 14
40182 -246 190 14 246 190 14 246 190 14 246 190 14
40183 -246 190 14 246 190 14 246 190 14 242 186 14
40184 -234 174 13 213 154 11 154 122 46 66 66 66
40185 - 30 30 30 10 10 10 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 6 6 6 22 22 22
40189 - 58 58 58 154 121 60 206 145 10 234 174 13
40190 -242 186 14 246 186 14 246 190 14 246 190 14
40191 -246 190 14 246 190 14 246 190 14 246 190 14
40192 -246 190 14 246 190 14 246 190 14 246 190 14
40193 -246 190 14 246 190 14 246 190 14 246 190 14
40194 -246 186 14 236 178 12 210 162 10 163 110 8
40195 - 61 42 6 138 138 138 218 218 218 250 250 250
40196 -253 253 253 253 253 253 253 253 253 250 250 250
40197 -242 242 242 210 210 210 144 144 144 66 66 66
40198 - 6 6 6 2 2 6 2 2 6 2 2 6
40199 - 2 2 6 2 2 6 61 42 6 163 110 8
40200 -216 158 10 236 178 12 246 190 14 246 190 14
40201 -246 190 14 246 190 14 246 190 14 246 190 14
40202 -246 190 14 246 190 14 246 190 14 246 190 14
40203 -246 190 14 239 182 13 230 174 11 216 158 10
40204 -190 142 34 124 112 88 70 70 70 38 38 38
40205 - 18 18 18 6 6 6 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 6 6 6 22 22 22
40209 - 62 62 62 168 124 44 206 145 10 224 166 10
40210 -236 178 12 239 182 13 242 186 14 242 186 14
40211 -246 186 14 246 190 14 246 190 14 246 190 14
40212 -246 190 14 246 190 14 246 190 14 246 190 14
40213 -246 190 14 246 190 14 246 190 14 246 190 14
40214 -246 190 14 236 178 12 216 158 10 175 118 6
40215 - 80 54 7 2 2 6 6 6 6 30 30 30
40216 - 54 54 54 62 62 62 50 50 50 38 38 38
40217 - 14 14 14 2 2 6 2 2 6 2 2 6
40218 - 2 2 6 2 2 6 2 2 6 2 2 6
40219 - 2 2 6 6 6 6 80 54 7 167 114 7
40220 -213 154 11 236 178 12 246 190 14 246 190 14
40221 -246 190 14 246 190 14 246 190 14 246 190 14
40222 -246 190 14 242 186 14 239 182 13 239 182 13
40223 -230 174 11 210 150 10 174 135 50 124 112 88
40224 - 82 82 82 54 54 54 34 34 34 18 18 18
40225 - 6 6 6 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 6 6 6 18 18 18
40229 - 50 50 50 158 118 36 192 133 9 200 144 11
40230 -216 158 10 219 162 10 224 166 10 226 170 11
40231 -230 174 11 236 178 12 239 182 13 239 182 13
40232 -242 186 14 246 186 14 246 190 14 246 190 14
40233 -246 190 14 246 190 14 246 190 14 246 190 14
40234 -246 186 14 230 174 11 210 150 10 163 110 8
40235 -104 69 6 10 10 10 2 2 6 2 2 6
40236 - 2 2 6 2 2 6 2 2 6 2 2 6
40237 - 2 2 6 2 2 6 2 2 6 2 2 6
40238 - 2 2 6 2 2 6 2 2 6 2 2 6
40239 - 2 2 6 6 6 6 91 60 6 167 114 7
40240 -206 145 10 230 174 11 242 186 14 246 190 14
40241 -246 190 14 246 190 14 246 186 14 242 186 14
40242 -239 182 13 230 174 11 224 166 10 213 154 11
40243 -180 133 36 124 112 88 86 86 86 58 58 58
40244 - 38 38 38 22 22 22 10 10 10 6 6 6
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 14 14 14
40249 - 34 34 34 70 70 70 138 110 50 158 118 36
40250 -167 114 7 180 123 7 192 133 9 197 138 11
40251 -200 144 11 206 145 10 213 154 11 219 162 10
40252 -224 166 10 230 174 11 239 182 13 242 186 14
40253 -246 186 14 246 186 14 246 186 14 246 186 14
40254 -239 182 13 216 158 10 185 133 11 152 99 6
40255 -104 69 6 18 14 6 2 2 6 2 2 6
40256 - 2 2 6 2 2 6 2 2 6 2 2 6
40257 - 2 2 6 2 2 6 2 2 6 2 2 6
40258 - 2 2 6 2 2 6 2 2 6 2 2 6
40259 - 2 2 6 6 6 6 80 54 7 152 99 6
40260 -192 133 9 219 162 10 236 178 12 239 182 13
40261 -246 186 14 242 186 14 239 182 13 236 178 12
40262 -224 166 10 206 145 10 192 133 9 154 121 60
40263 - 94 94 94 62 62 62 42 42 42 22 22 22
40264 - 14 14 14 6 6 6 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 6 6 6
40269 - 18 18 18 34 34 34 58 58 58 78 78 78
40270 -101 98 89 124 112 88 142 110 46 156 107 11
40271 -163 110 8 167 114 7 175 118 6 180 123 7
40272 -185 133 11 197 138 11 210 150 10 219 162 10
40273 -226 170 11 236 178 12 236 178 12 234 174 13
40274 -219 162 10 197 138 11 163 110 8 130 83 6
40275 - 91 60 6 10 10 10 2 2 6 2 2 6
40276 - 18 18 18 38 38 38 38 38 38 38 38 38
40277 - 38 38 38 38 38 38 38 38 38 38 38 38
40278 - 38 38 38 38 38 38 26 26 26 2 2 6
40279 - 2 2 6 6 6 6 70 47 6 137 92 6
40280 -175 118 6 200 144 11 219 162 10 230 174 11
40281 -234 174 13 230 174 11 219 162 10 210 150 10
40282 -192 133 9 163 110 8 124 112 88 82 82 82
40283 - 50 50 50 30 30 30 14 14 14 6 6 6
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 6 6 6 14 14 14 22 22 22 34 34 34
40290 - 42 42 42 58 58 58 74 74 74 86 86 86
40291 -101 98 89 122 102 70 130 98 46 121 87 25
40292 -137 92 6 152 99 6 163 110 8 180 123 7
40293 -185 133 11 197 138 11 206 145 10 200 144 11
40294 -180 123 7 156 107 11 130 83 6 104 69 6
40295 - 50 34 6 54 54 54 110 110 110 101 98 89
40296 - 86 86 86 82 82 82 78 78 78 78 78 78
40297 - 78 78 78 78 78 78 78 78 78 78 78 78
40298 - 78 78 78 82 82 82 86 86 86 94 94 94
40299 -106 106 106 101 101 101 86 66 34 124 80 6
40300 -156 107 11 180 123 7 192 133 9 200 144 11
40301 -206 145 10 200 144 11 192 133 9 175 118 6
40302 -139 102 15 109 106 95 70 70 70 42 42 42
40303 - 22 22 22 10 10 10 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 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 6 6 6 10 10 10
40310 - 14 14 14 22 22 22 30 30 30 38 38 38
40311 - 50 50 50 62 62 62 74 74 74 90 90 90
40312 -101 98 89 112 100 78 121 87 25 124 80 6
40313 -137 92 6 152 99 6 152 99 6 152 99 6
40314 -138 86 6 124 80 6 98 70 6 86 66 30
40315 -101 98 89 82 82 82 58 58 58 46 46 46
40316 - 38 38 38 34 34 34 34 34 34 34 34 34
40317 - 34 34 34 34 34 34 34 34 34 34 34 34
40318 - 34 34 34 34 34 34 38 38 38 42 42 42
40319 - 54 54 54 82 82 82 94 86 76 91 60 6
40320 -134 86 6 156 107 11 167 114 7 175 118 6
40321 -175 118 6 167 114 7 152 99 6 121 87 25
40322 -101 98 89 62 62 62 34 34 34 18 18 18
40323 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 6 6 6 6 6 6 10 10 10
40331 - 18 18 18 22 22 22 30 30 30 42 42 42
40332 - 50 50 50 66 66 66 86 86 86 101 98 89
40333 -106 86 58 98 70 6 104 69 6 104 69 6
40334 -104 69 6 91 60 6 82 62 34 90 90 90
40335 - 62 62 62 38 38 38 22 22 22 14 14 14
40336 - 10 10 10 10 10 10 10 10 10 10 10 10
40337 - 10 10 10 10 10 10 6 6 6 10 10 10
40338 - 10 10 10 10 10 10 10 10 10 14 14 14
40339 - 22 22 22 42 42 42 70 70 70 89 81 66
40340 - 80 54 7 104 69 6 124 80 6 137 92 6
40341 -134 86 6 116 81 8 100 82 52 86 86 86
40342 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 6 6 6 10 10 10 14 14 14
40352 - 18 18 18 26 26 26 38 38 38 54 54 54
40353 - 70 70 70 86 86 86 94 86 76 89 81 66
40354 - 89 81 66 86 86 86 74 74 74 50 50 50
40355 - 30 30 30 14 14 14 6 6 6 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 6 6 6 18 18 18 34 34 34 58 58 58
40360 - 82 82 82 89 81 66 89 81 66 89 81 66
40361 - 94 86 66 94 86 76 74 74 74 50 50 50
40362 - 26 26 26 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 6 6 6 6 6 6 14 14 14 18 18 18
40373 - 30 30 30 38 38 38 46 46 46 54 54 54
40374 - 50 50 50 42 42 42 30 30 30 18 18 18
40375 - 10 10 10 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 6 6 6 14 14 14 26 26 26
40380 - 38 38 38 50 50 50 58 58 58 58 58 58
40381 - 54 54 54 42 42 42 30 30 30 18 18 18
40382 - 10 10 10 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 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 6 6 6
40393 - 6 6 6 10 10 10 14 14 14 18 18 18
40394 - 18 18 18 14 14 14 10 10 10 6 6 6
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 6 6 6
40400 - 14 14 14 18 18 18 22 22 22 22 22 22
40401 - 18 18 18 14 14 14 10 10 10 6 6 6
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
40417 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
40491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
40496 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40501 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
40505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40507 +4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
40510 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40511 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40515 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40516 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40517 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40518 +4 4 4 4 4 4
40519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40521 +4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40524 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40525 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40528 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40529 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40530 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40531 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40532 +4 4 4 4 4 4
40533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40536 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40537 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40538 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40539 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40541 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40542 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40543 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40544 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40545 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40546 +4 4 4 4 4 4
40547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40550 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40551 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40552 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40553 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40554 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40555 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40556 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40557 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40558 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40559 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40560 +4 4 4 4 4 4
40561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40564 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40565 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40566 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40567 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40568 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40569 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40570 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40571 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40572 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40573 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40574 +4 4 4 4 4 4
40575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40577 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40578 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40579 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40580 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40581 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40582 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40583 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40584 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40585 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40586 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40587 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40588 +4 4 4 4 4 4
40589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40591 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40592 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40593 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40594 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40595 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40596 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40597 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40598 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40599 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40600 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40601 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40602 +4 4 4 4 4 4
40603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40605 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40606 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40607 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40608 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40609 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40610 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40611 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40612 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40613 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40614 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40615 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40616 +4 4 4 4 4 4
40617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40619 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40620 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40621 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40622 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40623 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40624 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40625 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40626 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40627 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40628 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40629 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40630 +4 4 4 4 4 4
40631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40633 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40634 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40635 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40636 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40637 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40638 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40639 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40640 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40641 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40642 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40643 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40644 +4 4 4 4 4 4
40645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40647 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40648 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40649 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40650 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40651 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40652 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40653 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40654 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40655 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40656 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40657 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40658 +0 0 0 4 4 4
40659 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40660 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40661 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40662 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40663 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40664 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40665 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40666 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40667 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40668 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40669 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40670 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40671 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40672 +2 0 0 0 0 0
40673 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40674 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40675 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40676 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40677 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40678 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40679 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40680 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40681 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40682 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40683 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40684 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40685 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40686 +37 38 37 0 0 0
40687 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40688 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40689 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40690 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40691 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40692 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40693 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40694 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40695 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40696 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40697 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40698 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40699 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40700 +85 115 134 4 0 0
40701 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40702 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40703 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40704 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40705 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40706 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40707 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40708 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40709 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40710 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40711 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40712 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40713 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40714 +60 73 81 4 0 0
40715 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40716 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40717 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40718 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40719 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40720 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40721 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40722 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40723 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40724 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40725 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40726 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40727 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40728 +16 19 21 4 0 0
40729 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40730 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40731 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40732 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40733 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40734 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40735 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40736 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40737 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40738 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40739 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40740 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40741 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40742 +4 0 0 4 3 3
40743 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40744 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40745 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40747 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40748 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40749 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40750 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40751 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40752 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40753 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40754 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40755 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40756 +3 2 2 4 4 4
40757 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40758 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40759 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40760 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40761 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40762 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40763 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40764 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40765 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40766 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40767 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40768 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40769 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40770 +4 4 4 4 4 4
40771 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40772 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40773 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40774 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40775 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40776 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40777 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40778 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40779 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40780 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40781 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40782 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40783 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40784 +4 4 4 4 4 4
40785 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40786 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40787 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40788 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40789 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40790 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40791 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40792 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40793 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40794 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40795 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40796 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40797 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40798 +5 5 5 5 5 5
40799 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40800 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40801 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40802 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40803 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40804 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40805 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40806 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40807 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40808 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40809 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40810 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40811 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40812 +5 5 5 4 4 4
40813 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40814 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40815 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40816 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40817 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40818 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40819 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40820 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40821 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40822 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40823 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40824 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4
40827 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40828 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40829 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40830 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40831 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40832 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40833 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40834 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40835 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40836 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40837 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40838 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840 +4 4 4 4 4 4
40841 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40842 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40843 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40844 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40845 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40846 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40847 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40848 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40849 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40850 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40851 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854 +4 4 4 4 4 4
40855 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40856 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40857 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40858 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40859 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40860 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40861 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40862 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40863 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40864 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40865 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868 +4 4 4 4 4 4
40869 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40870 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40871 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40872 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40873 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40874 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40875 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40876 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40877 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40878 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40879 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882 +4 4 4 4 4 4
40883 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40884 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40885 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40886 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40887 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40888 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40889 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40890 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40891 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40892 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40893 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896 +4 4 4 4 4 4
40897 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40898 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40899 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40900 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40901 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40902 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40903 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40904 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40905 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40906 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40907 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910 +4 4 4 4 4 4
40911 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40912 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40913 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40914 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40915 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40916 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40917 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40918 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40919 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40920 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40921 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924 +4 4 4 4 4 4
40925 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40926 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40927 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40928 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40929 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40930 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40931 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40932 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40933 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40934 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40935 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938 +4 4 4 4 4 4
40939 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40940 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40941 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40942 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40943 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40944 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40945 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40946 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40947 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40948 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40949 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952 +4 4 4 4 4 4
40953 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40954 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40955 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40956 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40957 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40958 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40959 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40960 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40961 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40962 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40963 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40966 +4 4 4 4 4 4
40967 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40968 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40969 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40970 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40971 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40972 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40973 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40974 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40975 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40976 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40977 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40980 +4 4 4 4 4 4
40981 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40982 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40983 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40984 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40985 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40986 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40987 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40988 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40989 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40990 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40991 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40994 +4 4 4 4 4 4
40995 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40996 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40997 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40998 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40999 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41000 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41001 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41002 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41003 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41004 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41005 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41008 +4 4 4 4 4 4
41009 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41010 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41011 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41012 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41013 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41014 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41015 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41016 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41017 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41018 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41019 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41022 +4 4 4 4 4 4
41023 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41024 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41025 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41026 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41027 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41028 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41029 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41030 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41031 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41032 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41033 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41036 +4 4 4 4 4 4
41037 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41038 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41039 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41040 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41041 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41042 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41043 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41044 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41045 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41046 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41047 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41050 +4 4 4 4 4 4
41051 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41052 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41053 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41054 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41055 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41056 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41057 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41058 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41059 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41060 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41061 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41064 +4 4 4 4 4 4
41065 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41066 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41067 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41068 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41069 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41070 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41071 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41072 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41073 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41074 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41075 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41078 +4 4 4 4 4 4
41079 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41080 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41081 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41082 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41083 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41084 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41085 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41086 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41087 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41088 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41089 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41092 +4 4 4 4 4 4
41093 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41094 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41095 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41096 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41097 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41098 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41099 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41100 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41101 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41102 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41103 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41106 +4 4 4 4 4 4
41107 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41108 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41109 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41110 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41111 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41112 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41113 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41114 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41115 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41116 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41117 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41120 +4 4 4 4 4 4
41121 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41122 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41123 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41124 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41125 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41126 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41127 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41128 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41129 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41130 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41131 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41134 +4 4 4 4 4 4
41135 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41136 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41137 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41138 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41139 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41140 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41141 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41142 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41143 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41144 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41145 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4
41149 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41150 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41151 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41152 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41153 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41154 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41155 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41156 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41157 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41158 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41159 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4
41163 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41164 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41165 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41166 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41167 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41168 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41169 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41170 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41171 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41172 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41173 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4
41177 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41178 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41179 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41180 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41181 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41182 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41183 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41184 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41185 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41186 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41187 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4
41191 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41192 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41193 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41194 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41196 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41197 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41199 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41200 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41201 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4
41205 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41206 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41207 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41208 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41209 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41210 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41211 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41212 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41213 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41214 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41215 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4
41219 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41220 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41221 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41222 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41223 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41224 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41225 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41226 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41227 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41228 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4
41233 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41234 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41235 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41236 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41237 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41238 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41239 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41240 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41241 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41242 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4
41247 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41248 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41249 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41250 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41251 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41252 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41253 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41254 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41255 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41256 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4
41261 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41262 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41263 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41264 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41265 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41266 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41267 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41268 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41269 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41270 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4
41275 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41276 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41277 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41278 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41279 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41280 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41281 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41282 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41283 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4
41289 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41290 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41291 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41292 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41293 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41294 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41295 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41296 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41297 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4
41303 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41304 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41305 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41306 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41307 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41308 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41309 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41310 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41311 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4
41317 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41318 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41319 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41320 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41321 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41322 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41323 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41324 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41332 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41333 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41334 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41335 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41336 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41337 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41338 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41346 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41347 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41348 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41349 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41350 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41351 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41352 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41361 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41362 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41363 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41364 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41365 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41366 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41375 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41376 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41377 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41378 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41379 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41380 +5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41390 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41391 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41392 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41393 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41394 +4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4
41400 +4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41404 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41405 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41406 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41407 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41419 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41420 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41421 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41433 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41434 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41435 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41447 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41448 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41449 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41461 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41462 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41463 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41476 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41477 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41490 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41491 +5 5 5 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 4 4 4 4 4 4 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
41499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41504 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
41513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41518 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41526 +4 4 4 4 4 4
41527 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41528 index a40c05e..785c583 100644
41529 --- a/drivers/video/udlfb.c
41530 +++ b/drivers/video/udlfb.c
41531 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41532 dlfb_urb_completion(urb);
41533
41534 error:
41535 - atomic_add(bytes_sent, &dev->bytes_sent);
41536 - atomic_add(bytes_identical, &dev->bytes_identical);
41537 - atomic_add(width*height*2, &dev->bytes_rendered);
41538 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41539 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41540 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41541 end_cycles = get_cycles();
41542 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41543 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41544 >> 10)), /* Kcycles */
41545 &dev->cpu_kcycles_used);
41546
41547 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41548 dlfb_urb_completion(urb);
41549
41550 error:
41551 - atomic_add(bytes_sent, &dev->bytes_sent);
41552 - atomic_add(bytes_identical, &dev->bytes_identical);
41553 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41554 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41555 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41556 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41557 end_cycles = get_cycles();
41558 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41559 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41560 >> 10)), /* Kcycles */
41561 &dev->cpu_kcycles_used);
41562 }
41563 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41564 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41565 struct dlfb_data *dev = fb_info->par;
41566 return snprintf(buf, PAGE_SIZE, "%u\n",
41567 - atomic_read(&dev->bytes_rendered));
41568 + atomic_read_unchecked(&dev->bytes_rendered));
41569 }
41570
41571 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41572 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41573 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41574 struct dlfb_data *dev = fb_info->par;
41575 return snprintf(buf, PAGE_SIZE, "%u\n",
41576 - atomic_read(&dev->bytes_identical));
41577 + atomic_read_unchecked(&dev->bytes_identical));
41578 }
41579
41580 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41581 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41582 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41583 struct dlfb_data *dev = fb_info->par;
41584 return snprintf(buf, PAGE_SIZE, "%u\n",
41585 - atomic_read(&dev->bytes_sent));
41586 + atomic_read_unchecked(&dev->bytes_sent));
41587 }
41588
41589 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41590 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41591 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41592 struct dlfb_data *dev = fb_info->par;
41593 return snprintf(buf, PAGE_SIZE, "%u\n",
41594 - atomic_read(&dev->cpu_kcycles_used));
41595 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41596 }
41597
41598 static ssize_t edid_show(
41599 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41600 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41601 struct dlfb_data *dev = fb_info->par;
41602
41603 - atomic_set(&dev->bytes_rendered, 0);
41604 - atomic_set(&dev->bytes_identical, 0);
41605 - atomic_set(&dev->bytes_sent, 0);
41606 - atomic_set(&dev->cpu_kcycles_used, 0);
41607 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41608 + atomic_set_unchecked(&dev->bytes_identical, 0);
41609 + atomic_set_unchecked(&dev->bytes_sent, 0);
41610 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41611
41612 return count;
41613 }
41614 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41615 index e7f69ef..83af4fd 100644
41616 --- a/drivers/video/uvesafb.c
41617 +++ b/drivers/video/uvesafb.c
41618 @@ -19,6 +19,7 @@
41619 #include <linux/io.h>
41620 #include <linux/mutex.h>
41621 #include <linux/slab.h>
41622 +#include <linux/moduleloader.h>
41623 #include <video/edid.h>
41624 #include <video/uvesafb.h>
41625 #ifdef CONFIG_X86
41626 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41627 NULL,
41628 };
41629
41630 - return call_usermodehelper(v86d_path, argv, envp, 1);
41631 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41632 }
41633
41634 /*
41635 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41636 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41637 par->pmi_setpal = par->ypan = 0;
41638 } else {
41639 +
41640 +#ifdef CONFIG_PAX_KERNEXEC
41641 +#ifdef CONFIG_MODULES
41642 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41643 +#endif
41644 + if (!par->pmi_code) {
41645 + par->pmi_setpal = par->ypan = 0;
41646 + return 0;
41647 + }
41648 +#endif
41649 +
41650 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41651 + task->t.regs.edi);
41652 +
41653 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41654 + pax_open_kernel();
41655 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41656 + pax_close_kernel();
41657 +
41658 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41659 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41660 +#else
41661 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41662 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41663 +#endif
41664 +
41665 printk(KERN_INFO "uvesafb: protected mode interface info at "
41666 "%04x:%04x\n",
41667 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41668 @@ -1821,6 +1844,11 @@ out:
41669 if (par->vbe_modes)
41670 kfree(par->vbe_modes);
41671
41672 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41673 + if (par->pmi_code)
41674 + module_free_exec(NULL, par->pmi_code);
41675 +#endif
41676 +
41677 framebuffer_release(info);
41678 return err;
41679 }
41680 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41681 kfree(par->vbe_state_orig);
41682 if (par->vbe_state_saved)
41683 kfree(par->vbe_state_saved);
41684 +
41685 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41686 + if (par->pmi_code)
41687 + module_free_exec(NULL, par->pmi_code);
41688 +#endif
41689 +
41690 }
41691
41692 framebuffer_release(info);
41693 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41694 index 501b340..86bd4cf 100644
41695 --- a/drivers/video/vesafb.c
41696 +++ b/drivers/video/vesafb.c
41697 @@ -9,6 +9,7 @@
41698 */
41699
41700 #include <linux/module.h>
41701 +#include <linux/moduleloader.h>
41702 #include <linux/kernel.h>
41703 #include <linux/errno.h>
41704 #include <linux/string.h>
41705 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41706 static int vram_total __initdata; /* Set total amount of memory */
41707 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41708 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41709 -static void (*pmi_start)(void) __read_mostly;
41710 -static void (*pmi_pal) (void) __read_mostly;
41711 +static void (*pmi_start)(void) __read_only;
41712 +static void (*pmi_pal) (void) __read_only;
41713 static int depth __read_mostly;
41714 static int vga_compat __read_mostly;
41715 /* --------------------------------------------------------------------- */
41716 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41717 unsigned int size_vmode;
41718 unsigned int size_remap;
41719 unsigned int size_total;
41720 + void *pmi_code = NULL;
41721
41722 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41723 return -ENODEV;
41724 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41725 size_remap = size_total;
41726 vesafb_fix.smem_len = size_remap;
41727
41728 -#ifndef __i386__
41729 - screen_info.vesapm_seg = 0;
41730 -#endif
41731 -
41732 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41733 printk(KERN_WARNING
41734 "vesafb: cannot reserve video memory at 0x%lx\n",
41735 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41736 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41737 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41738
41739 +#ifdef __i386__
41740 +
41741 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41742 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41743 + if (!pmi_code)
41744 +#elif !defined(CONFIG_PAX_KERNEXEC)
41745 + if (0)
41746 +#endif
41747 +
41748 +#endif
41749 + screen_info.vesapm_seg = 0;
41750 +
41751 if (screen_info.vesapm_seg) {
41752 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41753 - screen_info.vesapm_seg,screen_info.vesapm_off);
41754 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41755 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41756 }
41757
41758 if (screen_info.vesapm_seg < 0xc000)
41759 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41760
41761 if (ypan || pmi_setpal) {
41762 unsigned short *pmi_base;
41763 +
41764 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41765 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41766 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41767 +
41768 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41769 + pax_open_kernel();
41770 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41771 +#else
41772 + pmi_code = pmi_base;
41773 +#endif
41774 +
41775 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41776 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41777 +
41778 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41779 + pmi_start = ktva_ktla(pmi_start);
41780 + pmi_pal = ktva_ktla(pmi_pal);
41781 + pax_close_kernel();
41782 +#endif
41783 +
41784 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41785 if (pmi_base[3]) {
41786 printk(KERN_INFO "vesafb: pmi: ports = ");
41787 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41788 info->node, info->fix.id);
41789 return 0;
41790 err:
41791 +
41792 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41793 + module_free_exec(NULL, pmi_code);
41794 +#endif
41795 +
41796 if (info->screen_base)
41797 iounmap(info->screen_base);
41798 framebuffer_release(info);
41799 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41800 index 88714ae..16c2e11 100644
41801 --- a/drivers/video/via/via_clock.h
41802 +++ b/drivers/video/via/via_clock.h
41803 @@ -56,7 +56,7 @@ struct via_clock {
41804
41805 void (*set_engine_pll_state)(u8 state);
41806 void (*set_engine_pll)(struct via_pll_config config);
41807 -};
41808 +} __no_const;
41809
41810
41811 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41812 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41813 index e56c934..fc22f4b 100644
41814 --- a/drivers/xen/xen-pciback/conf_space.h
41815 +++ b/drivers/xen/xen-pciback/conf_space.h
41816 @@ -44,15 +44,15 @@ struct config_field {
41817 struct {
41818 conf_dword_write write;
41819 conf_dword_read read;
41820 - } dw;
41821 + } __no_const dw;
41822 struct {
41823 conf_word_write write;
41824 conf_word_read read;
41825 - } w;
41826 + } __no_const w;
41827 struct {
41828 conf_byte_write write;
41829 conf_byte_read read;
41830 - } b;
41831 + } __no_const b;
41832 } u;
41833 struct list_head list;
41834 };
41835 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41836 index 014c8dd..6f3dfe6 100644
41837 --- a/fs/9p/vfs_inode.c
41838 +++ b/fs/9p/vfs_inode.c
41839 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41840 void
41841 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41842 {
41843 - char *s = nd_get_link(nd);
41844 + const char *s = nd_get_link(nd);
41845
41846 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41847 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41848 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41849 index e95d1b6..3454244 100644
41850 --- a/fs/Kconfig.binfmt
41851 +++ b/fs/Kconfig.binfmt
41852 @@ -89,7 +89,7 @@ config HAVE_AOUT
41853
41854 config BINFMT_AOUT
41855 tristate "Kernel support for a.out and ECOFF binaries"
41856 - depends on HAVE_AOUT
41857 + depends on HAVE_AOUT && BROKEN
41858 ---help---
41859 A.out (Assembler.OUTput) is a set of formats for libraries and
41860 executables used in the earliest versions of UNIX. Linux used
41861 diff --git a/fs/aio.c b/fs/aio.c
41862 index b9d64d8..86cb1d5 100644
41863 --- a/fs/aio.c
41864 +++ b/fs/aio.c
41865 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41866 size += sizeof(struct io_event) * nr_events;
41867 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41868
41869 - if (nr_pages < 0)
41870 + if (nr_pages <= 0)
41871 return -EINVAL;
41872
41873 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41874 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41875 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41876 {
41877 ssize_t ret;
41878 + struct iovec iovstack;
41879
41880 #ifdef CONFIG_COMPAT
41881 if (compat)
41882 ret = compat_rw_copy_check_uvector(type,
41883 (struct compat_iovec __user *)kiocb->ki_buf,
41884 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41885 + kiocb->ki_nbytes, 1, &iovstack,
41886 &kiocb->ki_iovec, 1);
41887 else
41888 #endif
41889 ret = rw_copy_check_uvector(type,
41890 (struct iovec __user *)kiocb->ki_buf,
41891 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41892 + kiocb->ki_nbytes, 1, &iovstack,
41893 &kiocb->ki_iovec, 1);
41894 if (ret < 0)
41895 goto out;
41896
41897 + if (kiocb->ki_iovec == &iovstack) {
41898 + kiocb->ki_inline_vec = iovstack;
41899 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41900 + }
41901 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41902 kiocb->ki_cur_seg = 0;
41903 /* ki_nbytes/left now reflect bytes instead of segs */
41904 diff --git a/fs/attr.c b/fs/attr.c
41905 index 95053ad..2cc93ca 100644
41906 --- a/fs/attr.c
41907 +++ b/fs/attr.c
41908 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41909 unsigned long limit;
41910
41911 limit = rlimit(RLIMIT_FSIZE);
41912 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41913 if (limit != RLIM_INFINITY && offset > limit)
41914 goto out_sig;
41915 if (offset > inode->i_sb->s_maxbytes)
41916 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41917 index 9c098db..c755da5 100644
41918 --- a/fs/autofs4/waitq.c
41919 +++ b/fs/autofs4/waitq.c
41920 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41921 {
41922 unsigned long sigpipe, flags;
41923 mm_segment_t fs;
41924 - const char *data = (const char *)addr;
41925 + const char __user *data = (const char __force_user *)addr;
41926 ssize_t wr = 0;
41927
41928 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41929 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41930 index 6e6d536..457113a 100644
41931 --- a/fs/befs/linuxvfs.c
41932 +++ b/fs/befs/linuxvfs.c
41933 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41934 {
41935 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41936 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41937 - char *link = nd_get_link(nd);
41938 + const char *link = nd_get_link(nd);
41939 if (!IS_ERR(link))
41940 kfree(link);
41941 }
41942 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41943 index 1ff9405..f1e376a 100644
41944 --- a/fs/binfmt_aout.c
41945 +++ b/fs/binfmt_aout.c
41946 @@ -16,6 +16,7 @@
41947 #include <linux/string.h>
41948 #include <linux/fs.h>
41949 #include <linux/file.h>
41950 +#include <linux/security.h>
41951 #include <linux/stat.h>
41952 #include <linux/fcntl.h>
41953 #include <linux/ptrace.h>
41954 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41955 #endif
41956 # define START_STACK(u) ((void __user *)u.start_stack)
41957
41958 + memset(&dump, 0, sizeof(dump));
41959 +
41960 fs = get_fs();
41961 set_fs(KERNEL_DS);
41962 has_dumped = 1;
41963 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41964
41965 /* If the size of the dump file exceeds the rlimit, then see what would happen
41966 if we wrote the stack, but not the data area. */
41967 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41968 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41969 dump.u_dsize = 0;
41970
41971 /* Make sure we have enough room to write the stack and data areas. */
41972 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41973 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41974 dump.u_ssize = 0;
41975
41976 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41977 rlim = rlimit(RLIMIT_DATA);
41978 if (rlim >= RLIM_INFINITY)
41979 rlim = ~0;
41980 +
41981 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41982 if (ex.a_data + ex.a_bss > rlim)
41983 return -ENOMEM;
41984
41985 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41986 install_exec_creds(bprm);
41987 current->flags &= ~PF_FORKNOEXEC;
41988
41989 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41990 + current->mm->pax_flags = 0UL;
41991 +#endif
41992 +
41993 +#ifdef CONFIG_PAX_PAGEEXEC
41994 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41995 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41996 +
41997 +#ifdef CONFIG_PAX_EMUTRAMP
41998 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41999 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42000 +#endif
42001 +
42002 +#ifdef CONFIG_PAX_MPROTECT
42003 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42004 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42005 +#endif
42006 +
42007 + }
42008 +#endif
42009 +
42010 if (N_MAGIC(ex) == OMAGIC) {
42011 unsigned long text_addr, map_size;
42012 loff_t pos;
42013 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42014
42015 down_write(&current->mm->mmap_sem);
42016 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42017 - PROT_READ | PROT_WRITE | PROT_EXEC,
42018 + PROT_READ | PROT_WRITE,
42019 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42020 fd_offset + ex.a_text);
42021 up_write(&current->mm->mmap_sem);
42022 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42023 index 07d096c..851a18b 100644
42024 --- a/fs/binfmt_elf.c
42025 +++ b/fs/binfmt_elf.c
42026 @@ -32,6 +32,7 @@
42027 #include <linux/elf.h>
42028 #include <linux/utsname.h>
42029 #include <linux/coredump.h>
42030 +#include <linux/xattr.h>
42031 #include <asm/uaccess.h>
42032 #include <asm/param.h>
42033 #include <asm/page.h>
42034 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42035 #define elf_core_dump NULL
42036 #endif
42037
42038 +#ifdef CONFIG_PAX_MPROTECT
42039 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42040 +#endif
42041 +
42042 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42043 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42044 #else
42045 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42046 .load_binary = load_elf_binary,
42047 .load_shlib = load_elf_library,
42048 .core_dump = elf_core_dump,
42049 +
42050 +#ifdef CONFIG_PAX_MPROTECT
42051 + .handle_mprotect= elf_handle_mprotect,
42052 +#endif
42053 +
42054 .min_coredump = ELF_EXEC_PAGESIZE,
42055 };
42056
42057 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42058
42059 static int set_brk(unsigned long start, unsigned long end)
42060 {
42061 + unsigned long e = end;
42062 +
42063 start = ELF_PAGEALIGN(start);
42064 end = ELF_PAGEALIGN(end);
42065 if (end > start) {
42066 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42067 if (BAD_ADDR(addr))
42068 return addr;
42069 }
42070 - current->mm->start_brk = current->mm->brk = end;
42071 + current->mm->start_brk = current->mm->brk = e;
42072 return 0;
42073 }
42074
42075 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42076 elf_addr_t __user *u_rand_bytes;
42077 const char *k_platform = ELF_PLATFORM;
42078 const char *k_base_platform = ELF_BASE_PLATFORM;
42079 - unsigned char k_rand_bytes[16];
42080 + u32 k_rand_bytes[4];
42081 int items;
42082 elf_addr_t *elf_info;
42083 int ei_index = 0;
42084 const struct cred *cred = current_cred();
42085 struct vm_area_struct *vma;
42086 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42087
42088 /*
42089 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42090 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42091 * Generate 16 random bytes for userspace PRNG seeding.
42092 */
42093 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42094 - u_rand_bytes = (elf_addr_t __user *)
42095 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42096 + srandom32(k_rand_bytes[0] ^ random32());
42097 + srandom32(k_rand_bytes[1] ^ random32());
42098 + srandom32(k_rand_bytes[2] ^ random32());
42099 + srandom32(k_rand_bytes[3] ^ random32());
42100 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42101 + u_rand_bytes = (elf_addr_t __user *) p;
42102 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42103 return -EFAULT;
42104
42105 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42106 return -EFAULT;
42107 current->mm->env_end = p;
42108
42109 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42110 +
42111 /* Put the elf_info on the stack in the right place. */
42112 sp = (elf_addr_t __user *)envp + 1;
42113 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42114 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42115 return -EFAULT;
42116 return 0;
42117 }
42118 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42119 {
42120 struct elf_phdr *elf_phdata;
42121 struct elf_phdr *eppnt;
42122 - unsigned long load_addr = 0;
42123 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42124 int load_addr_set = 0;
42125 unsigned long last_bss = 0, elf_bss = 0;
42126 - unsigned long error = ~0UL;
42127 + unsigned long error = -EINVAL;
42128 unsigned long total_size;
42129 int retval, i, size;
42130
42131 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42132 goto out_close;
42133 }
42134
42135 +#ifdef CONFIG_PAX_SEGMEXEC
42136 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42137 + pax_task_size = SEGMEXEC_TASK_SIZE;
42138 +#endif
42139 +
42140 eppnt = elf_phdata;
42141 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42142 if (eppnt->p_type == PT_LOAD) {
42143 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42144 k = load_addr + eppnt->p_vaddr;
42145 if (BAD_ADDR(k) ||
42146 eppnt->p_filesz > eppnt->p_memsz ||
42147 - eppnt->p_memsz > TASK_SIZE ||
42148 - TASK_SIZE - eppnt->p_memsz < k) {
42149 + eppnt->p_memsz > pax_task_size ||
42150 + pax_task_size - eppnt->p_memsz < k) {
42151 error = -ENOMEM;
42152 goto out_close;
42153 }
42154 @@ -528,6 +552,351 @@ out:
42155 return error;
42156 }
42157
42158 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42159 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42160 +{
42161 + unsigned long pax_flags = 0UL;
42162 +
42163 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42164 +
42165 +#ifdef CONFIG_PAX_PAGEEXEC
42166 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42167 + pax_flags |= MF_PAX_PAGEEXEC;
42168 +#endif
42169 +
42170 +#ifdef CONFIG_PAX_SEGMEXEC
42171 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42172 + pax_flags |= MF_PAX_SEGMEXEC;
42173 +#endif
42174 +
42175 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42176 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42177 + if ((__supported_pte_mask & _PAGE_NX))
42178 + pax_flags &= ~MF_PAX_SEGMEXEC;
42179 + else
42180 + pax_flags &= ~MF_PAX_PAGEEXEC;
42181 + }
42182 +#endif
42183 +
42184 +#ifdef CONFIG_PAX_EMUTRAMP
42185 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42186 + pax_flags |= MF_PAX_EMUTRAMP;
42187 +#endif
42188 +
42189 +#ifdef CONFIG_PAX_MPROTECT
42190 + if (elf_phdata->p_flags & PF_MPROTECT)
42191 + pax_flags |= MF_PAX_MPROTECT;
42192 +#endif
42193 +
42194 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42195 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42196 + pax_flags |= MF_PAX_RANDMMAP;
42197 +#endif
42198 +
42199 +#endif
42200 +
42201 + return pax_flags;
42202 +}
42203 +
42204 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42205 +{
42206 + unsigned long pax_flags = 0UL;
42207 +
42208 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42209 +
42210 +#ifdef CONFIG_PAX_PAGEEXEC
42211 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42212 + pax_flags |= MF_PAX_PAGEEXEC;
42213 +#endif
42214 +
42215 +#ifdef CONFIG_PAX_SEGMEXEC
42216 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42217 + pax_flags |= MF_PAX_SEGMEXEC;
42218 +#endif
42219 +
42220 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42221 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42222 + if ((__supported_pte_mask & _PAGE_NX))
42223 + pax_flags &= ~MF_PAX_SEGMEXEC;
42224 + else
42225 + pax_flags &= ~MF_PAX_PAGEEXEC;
42226 + }
42227 +#endif
42228 +
42229 +#ifdef CONFIG_PAX_EMUTRAMP
42230 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42231 + pax_flags |= MF_PAX_EMUTRAMP;
42232 +#endif
42233 +
42234 +#ifdef CONFIG_PAX_MPROTECT
42235 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42236 + pax_flags |= MF_PAX_MPROTECT;
42237 +#endif
42238 +
42239 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42240 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42241 + pax_flags |= MF_PAX_RANDMMAP;
42242 +#endif
42243 +
42244 +#endif
42245 +
42246 + return pax_flags;
42247 +}
42248 +
42249 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42250 +{
42251 + unsigned long pax_flags = 0UL;
42252 +
42253 +#ifdef CONFIG_PAX_EI_PAX
42254 +
42255 +#ifdef CONFIG_PAX_PAGEEXEC
42256 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42257 + pax_flags |= MF_PAX_PAGEEXEC;
42258 +#endif
42259 +
42260 +#ifdef CONFIG_PAX_SEGMEXEC
42261 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42262 + pax_flags |= MF_PAX_SEGMEXEC;
42263 +#endif
42264 +
42265 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42266 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42267 + if ((__supported_pte_mask & _PAGE_NX))
42268 + pax_flags &= ~MF_PAX_SEGMEXEC;
42269 + else
42270 + pax_flags &= ~MF_PAX_PAGEEXEC;
42271 + }
42272 +#endif
42273 +
42274 +#ifdef CONFIG_PAX_EMUTRAMP
42275 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42276 + pax_flags |= MF_PAX_EMUTRAMP;
42277 +#endif
42278 +
42279 +#ifdef CONFIG_PAX_MPROTECT
42280 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42281 + pax_flags |= MF_PAX_MPROTECT;
42282 +#endif
42283 +
42284 +#ifdef CONFIG_PAX_ASLR
42285 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42286 + pax_flags |= MF_PAX_RANDMMAP;
42287 +#endif
42288 +
42289 +#else
42290 +
42291 +#ifdef CONFIG_PAX_PAGEEXEC
42292 + pax_flags |= MF_PAX_PAGEEXEC;
42293 +#endif
42294 +
42295 +#ifdef CONFIG_PAX_MPROTECT
42296 + pax_flags |= MF_PAX_MPROTECT;
42297 +#endif
42298 +
42299 +#ifdef CONFIG_PAX_RANDMMAP
42300 + pax_flags |= MF_PAX_RANDMMAP;
42301 +#endif
42302 +
42303 +#ifdef CONFIG_PAX_SEGMEXEC
42304 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42305 + pax_flags &= ~MF_PAX_PAGEEXEC;
42306 + pax_flags |= MF_PAX_SEGMEXEC;
42307 + }
42308 +#endif
42309 +
42310 +#endif
42311 +
42312 + return pax_flags;
42313 +}
42314 +
42315 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42316 +{
42317 +
42318 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42319 + unsigned long i;
42320 +
42321 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42322 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42323 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42324 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42325 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42326 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42327 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42328 + return ~0UL;
42329 +
42330 +#ifdef CONFIG_PAX_SOFTMODE
42331 + if (pax_softmode)
42332 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42333 + else
42334 +#endif
42335 +
42336 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42337 + break;
42338 + }
42339 +#endif
42340 +
42341 + return ~0UL;
42342 +}
42343 +
42344 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42345 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42346 +{
42347 + unsigned long pax_flags = 0UL;
42348 +
42349 +#ifdef CONFIG_PAX_PAGEEXEC
42350 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42351 + pax_flags |= MF_PAX_PAGEEXEC;
42352 +#endif
42353 +
42354 +#ifdef CONFIG_PAX_SEGMEXEC
42355 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42356 + pax_flags |= MF_PAX_SEGMEXEC;
42357 +#endif
42358 +
42359 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42360 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42361 + if ((__supported_pte_mask & _PAGE_NX))
42362 + pax_flags &= ~MF_PAX_SEGMEXEC;
42363 + else
42364 + pax_flags &= ~MF_PAX_PAGEEXEC;
42365 + }
42366 +#endif
42367 +
42368 +#ifdef CONFIG_PAX_EMUTRAMP
42369 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42370 + pax_flags |= MF_PAX_EMUTRAMP;
42371 +#endif
42372 +
42373 +#ifdef CONFIG_PAX_MPROTECT
42374 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42375 + pax_flags |= MF_PAX_MPROTECT;
42376 +#endif
42377 +
42378 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42379 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42380 + pax_flags |= MF_PAX_RANDMMAP;
42381 +#endif
42382 +
42383 + return pax_flags;
42384 +}
42385 +
42386 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42387 +{
42388 + unsigned long pax_flags = 0UL;
42389 +
42390 +#ifdef CONFIG_PAX_PAGEEXEC
42391 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42392 + pax_flags |= MF_PAX_PAGEEXEC;
42393 +#endif
42394 +
42395 +#ifdef CONFIG_PAX_SEGMEXEC
42396 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42397 + pax_flags |= MF_PAX_SEGMEXEC;
42398 +#endif
42399 +
42400 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42401 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42402 + if ((__supported_pte_mask & _PAGE_NX))
42403 + pax_flags &= ~MF_PAX_SEGMEXEC;
42404 + else
42405 + pax_flags &= ~MF_PAX_PAGEEXEC;
42406 + }
42407 +#endif
42408 +
42409 +#ifdef CONFIG_PAX_EMUTRAMP
42410 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42411 + pax_flags |= MF_PAX_EMUTRAMP;
42412 +#endif
42413 +
42414 +#ifdef CONFIG_PAX_MPROTECT
42415 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42416 + pax_flags |= MF_PAX_MPROTECT;
42417 +#endif
42418 +
42419 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42420 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42421 + pax_flags |= MF_PAX_RANDMMAP;
42422 +#endif
42423 +
42424 + return pax_flags;
42425 +}
42426 +#endif
42427 +
42428 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42429 +{
42430 +
42431 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42432 + ssize_t xattr_size, i;
42433 + unsigned char xattr_value[5];
42434 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42435 +
42436 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42437 + if (xattr_size <= 0)
42438 + return ~0UL;
42439 +
42440 + for (i = 0; i < xattr_size; i++)
42441 + switch (xattr_value[i]) {
42442 + default:
42443 + return ~0UL;
42444 +
42445 +#define parse_flag(option1, option2, flag) \
42446 + case option1: \
42447 + pax_flags_hardmode |= MF_PAX_##flag; \
42448 + break; \
42449 + case option2: \
42450 + pax_flags_softmode |= MF_PAX_##flag; \
42451 + break;
42452 +
42453 + parse_flag('p', 'P', PAGEEXEC);
42454 + parse_flag('e', 'E', EMUTRAMP);
42455 + parse_flag('m', 'M', MPROTECT);
42456 + parse_flag('r', 'R', RANDMMAP);
42457 + parse_flag('s', 'S', SEGMEXEC);
42458 +
42459 +#undef parse_flag
42460 + }
42461 +
42462 + if (pax_flags_hardmode & pax_flags_softmode)
42463 + return ~0UL;
42464 +
42465 +#ifdef CONFIG_PAX_SOFTMODE
42466 + if (pax_softmode)
42467 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42468 + else
42469 +#endif
42470 +
42471 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42472 +#else
42473 + return ~0UL;
42474 +#endif
42475 +
42476 +}
42477 +
42478 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42479 +{
42480 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42481 +
42482 + pax_flags = pax_parse_ei_pax(elf_ex);
42483 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42484 + xattr_pax_flags = pax_parse_xattr_pax(file);
42485 +
42486 + if (pt_pax_flags == ~0UL)
42487 + pt_pax_flags = xattr_pax_flags;
42488 + else if (xattr_pax_flags == ~0UL)
42489 + xattr_pax_flags = pt_pax_flags;
42490 + if (pt_pax_flags != xattr_pax_flags)
42491 + return -EINVAL;
42492 + if (pt_pax_flags != ~0UL)
42493 + pax_flags = pt_pax_flags;
42494 +
42495 + if (0 > pax_check_flags(&pax_flags))
42496 + return -EINVAL;
42497 +
42498 + current->mm->pax_flags = pax_flags;
42499 + return 0;
42500 +}
42501 +#endif
42502 +
42503 /*
42504 * These are the functions used to load ELF style executables and shared
42505 * libraries. There is no binary dependent code anywhere else.
42506 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42507 {
42508 unsigned int random_variable = 0;
42509
42510 +#ifdef CONFIG_PAX_RANDUSTACK
42511 + if (randomize_va_space)
42512 + return stack_top - current->mm->delta_stack;
42513 +#endif
42514 +
42515 if ((current->flags & PF_RANDOMIZE) &&
42516 !(current->personality & ADDR_NO_RANDOMIZE)) {
42517 random_variable = get_random_int() & STACK_RND_MASK;
42518 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42519 unsigned long load_addr = 0, load_bias = 0;
42520 int load_addr_set = 0;
42521 char * elf_interpreter = NULL;
42522 - unsigned long error;
42523 + unsigned long error = 0;
42524 struct elf_phdr *elf_ppnt, *elf_phdata;
42525 unsigned long elf_bss, elf_brk;
42526 int retval, i;
42527 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42528 unsigned long start_code, end_code, start_data, end_data;
42529 unsigned long reloc_func_desc __maybe_unused = 0;
42530 int executable_stack = EXSTACK_DEFAULT;
42531 - unsigned long def_flags = 0;
42532 struct {
42533 struct elfhdr elf_ex;
42534 struct elfhdr interp_elf_ex;
42535 } *loc;
42536 + unsigned long pax_task_size = TASK_SIZE;
42537
42538 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42539 if (!loc) {
42540 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42541
42542 /* OK, This is the point of no return */
42543 current->flags &= ~PF_FORKNOEXEC;
42544 - current->mm->def_flags = def_flags;
42545 +
42546 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42547 + current->mm->pax_flags = 0UL;
42548 +#endif
42549 +
42550 +#ifdef CONFIG_PAX_DLRESOLVE
42551 + current->mm->call_dl_resolve = 0UL;
42552 +#endif
42553 +
42554 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42555 + current->mm->call_syscall = 0UL;
42556 +#endif
42557 +
42558 +#ifdef CONFIG_PAX_ASLR
42559 + current->mm->delta_mmap = 0UL;
42560 + current->mm->delta_stack = 0UL;
42561 +#endif
42562 +
42563 + current->mm->def_flags = 0;
42564 +
42565 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42566 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42567 + send_sig(SIGKILL, current, 0);
42568 + goto out_free_dentry;
42569 + }
42570 +#endif
42571 +
42572 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42573 + pax_set_initial_flags(bprm);
42574 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42575 + if (pax_set_initial_flags_func)
42576 + (pax_set_initial_flags_func)(bprm);
42577 +#endif
42578 +
42579 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42580 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42581 + current->mm->context.user_cs_limit = PAGE_SIZE;
42582 + current->mm->def_flags |= VM_PAGEEXEC;
42583 + }
42584 +#endif
42585 +
42586 +#ifdef CONFIG_PAX_SEGMEXEC
42587 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42588 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42589 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42590 + pax_task_size = SEGMEXEC_TASK_SIZE;
42591 + current->mm->def_flags |= VM_NOHUGEPAGE;
42592 + }
42593 +#endif
42594 +
42595 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42596 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42597 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42598 + put_cpu();
42599 + }
42600 +#endif
42601
42602 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42603 may depend on the personality. */
42604 SET_PERSONALITY(loc->elf_ex);
42605 +
42606 +#ifdef CONFIG_PAX_ASLR
42607 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42608 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42609 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42610 + }
42611 +#endif
42612 +
42613 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42614 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42615 + executable_stack = EXSTACK_DISABLE_X;
42616 + current->personality &= ~READ_IMPLIES_EXEC;
42617 + } else
42618 +#endif
42619 +
42620 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42621 current->personality |= READ_IMPLIES_EXEC;
42622
42623 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42624 #else
42625 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42626 #endif
42627 +
42628 +#ifdef CONFIG_PAX_RANDMMAP
42629 + /* PaX: randomize base address at the default exe base if requested */
42630 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42631 +#ifdef CONFIG_SPARC64
42632 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42633 +#else
42634 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42635 +#endif
42636 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42637 + elf_flags |= MAP_FIXED;
42638 + }
42639 +#endif
42640 +
42641 }
42642
42643 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42644 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42645 * allowed task size. Note that p_filesz must always be
42646 * <= p_memsz so it is only necessary to check p_memsz.
42647 */
42648 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42649 - elf_ppnt->p_memsz > TASK_SIZE ||
42650 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42651 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42652 + elf_ppnt->p_memsz > pax_task_size ||
42653 + pax_task_size - elf_ppnt->p_memsz < k) {
42654 /* set_brk can never work. Avoid overflows. */
42655 send_sig(SIGKILL, current, 0);
42656 retval = -EINVAL;
42657 @@ -881,11 +1339,36 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42658 goto out_free_dentry;
42659 }
42660 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42661 - send_sig(SIGSEGV, current, 0);
42662 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42663 - goto out_free_dentry;
42664 + /*
42665 + * This bss-zeroing can fail if the ELF
42666 + * file specifies odd protections. So
42667 + * we don't check the return value
42668 + */
42669 }
42670
42671 +#ifdef CONFIG_PAX_RANDMMAP
42672 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42673 + unsigned long start, size;
42674 +
42675 + start = ELF_PAGEALIGN(elf_brk);
42676 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42677 + down_write(&current->mm->mmap_sem);
42678 + retval = -ENOMEM;
42679 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42680 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42681 + start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42682 + retval = IS_ERR_VALUE(start) ? start : 0;
42683 + }
42684 + up_write(&current->mm->mmap_sem);
42685 + if (retval == 0)
42686 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42687 + if (retval < 0) {
42688 + send_sig(SIGKILL, current, 0);
42689 + goto out_free_dentry;
42690 + }
42691 + }
42692 +#endif
42693 +
42694 if (elf_interpreter) {
42695 unsigned long uninitialized_var(interp_map_addr);
42696
42697 @@ -1098,7 +1581,7 @@ out:
42698 * Decide what to dump of a segment, part, all or none.
42699 */
42700 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42701 - unsigned long mm_flags)
42702 + unsigned long mm_flags, long signr)
42703 {
42704 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42705
42706 @@ -1132,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42707 if (vma->vm_file == NULL)
42708 return 0;
42709
42710 - if (FILTER(MAPPED_PRIVATE))
42711 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42712 goto whole;
42713
42714 /*
42715 @@ -1354,9 +1837,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42716 {
42717 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42718 int i = 0;
42719 - do
42720 + do {
42721 i += 2;
42722 - while (auxv[i - 2] != AT_NULL);
42723 + } while (auxv[i - 2] != AT_NULL);
42724 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42725 }
42726
42727 @@ -1862,14 +2345,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42728 }
42729
42730 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42731 - unsigned long mm_flags)
42732 + struct coredump_params *cprm)
42733 {
42734 struct vm_area_struct *vma;
42735 size_t size = 0;
42736
42737 for (vma = first_vma(current, gate_vma); vma != NULL;
42738 vma = next_vma(vma, gate_vma))
42739 - size += vma_dump_size(vma, mm_flags);
42740 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42741 return size;
42742 }
42743
42744 @@ -1963,7 +2446,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42745
42746 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42747
42748 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42749 + offset += elf_core_vma_data_size(gate_vma, cprm);
42750 offset += elf_core_extra_data_size();
42751 e_shoff = offset;
42752
42753 @@ -1977,10 +2460,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42754 offset = dataoff;
42755
42756 size += sizeof(*elf);
42757 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42758 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42759 goto end_coredump;
42760
42761 size += sizeof(*phdr4note);
42762 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42763 if (size > cprm->limit
42764 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42765 goto end_coredump;
42766 @@ -1994,7 +2479,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42767 phdr.p_offset = offset;
42768 phdr.p_vaddr = vma->vm_start;
42769 phdr.p_paddr = 0;
42770 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42771 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42772 phdr.p_memsz = vma->vm_end - vma->vm_start;
42773 offset += phdr.p_filesz;
42774 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42775 @@ -2005,6 +2490,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42776 phdr.p_align = ELF_EXEC_PAGESIZE;
42777
42778 size += sizeof(phdr);
42779 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42780 if (size > cprm->limit
42781 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42782 goto end_coredump;
42783 @@ -2029,7 +2515,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42784 unsigned long addr;
42785 unsigned long end;
42786
42787 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42788 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42789
42790 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42791 struct page *page;
42792 @@ -2038,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42793 page = get_dump_page(addr);
42794 if (page) {
42795 void *kaddr = kmap(page);
42796 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42797 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42798 !dump_write(cprm->file, kaddr,
42799 PAGE_SIZE);
42800 @@ -2055,6 +2542,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42801
42802 if (e_phnum == PN_XNUM) {
42803 size += sizeof(*shdr4extnum);
42804 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42805 if (size > cprm->limit
42806 || !dump_write(cprm->file, shdr4extnum,
42807 sizeof(*shdr4extnum)))
42808 @@ -2075,6 +2563,97 @@ out:
42809
42810 #endif /* CONFIG_ELF_CORE */
42811
42812 +#ifdef CONFIG_PAX_MPROTECT
42813 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42814 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42815 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42816 + *
42817 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42818 + * basis because we want to allow the common case and not the special ones.
42819 + */
42820 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42821 +{
42822 + struct elfhdr elf_h;
42823 + struct elf_phdr elf_p;
42824 + unsigned long i;
42825 + unsigned long oldflags;
42826 + bool is_textrel_rw, is_textrel_rx, is_relro;
42827 +
42828 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42829 + return;
42830 +
42831 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42832 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42833 +
42834 +#ifdef CONFIG_PAX_ELFRELOCS
42835 + /* possible TEXTREL */
42836 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42837 + 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);
42838 +#else
42839 + is_textrel_rw = false;
42840 + is_textrel_rx = false;
42841 +#endif
42842 +
42843 + /* possible RELRO */
42844 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42845 +
42846 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42847 + return;
42848 +
42849 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42850 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42851 +
42852 +#ifdef CONFIG_PAX_ETEXECRELOCS
42853 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42854 +#else
42855 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42856 +#endif
42857 +
42858 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42859 + !elf_check_arch(&elf_h) ||
42860 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42861 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42862 + return;
42863 +
42864 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42865 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42866 + return;
42867 + switch (elf_p.p_type) {
42868 + case PT_DYNAMIC:
42869 + if (!is_textrel_rw && !is_textrel_rx)
42870 + continue;
42871 + i = 0UL;
42872 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42873 + elf_dyn dyn;
42874 +
42875 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42876 + return;
42877 + if (dyn.d_tag == DT_NULL)
42878 + return;
42879 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42880 + gr_log_textrel(vma);
42881 + if (is_textrel_rw)
42882 + vma->vm_flags |= VM_MAYWRITE;
42883 + else
42884 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42885 + vma->vm_flags &= ~VM_MAYWRITE;
42886 + return;
42887 + }
42888 + i++;
42889 + }
42890 + return;
42891 +
42892 + case PT_GNU_RELRO:
42893 + if (!is_relro)
42894 + continue;
42895 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42896 + vma->vm_flags &= ~VM_MAYWRITE;
42897 + return;
42898 + }
42899 + }
42900 +}
42901 +#endif
42902 +
42903 static int __init init_elf_binfmt(void)
42904 {
42905 return register_binfmt(&elf_format);
42906 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42907 index 1bffbe0..c8c283e 100644
42908 --- a/fs/binfmt_flat.c
42909 +++ b/fs/binfmt_flat.c
42910 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42911 realdatastart = (unsigned long) -ENOMEM;
42912 printk("Unable to allocate RAM for process data, errno %d\n",
42913 (int)-realdatastart);
42914 + down_write(&current->mm->mmap_sem);
42915 do_munmap(current->mm, textpos, text_len);
42916 + up_write(&current->mm->mmap_sem);
42917 ret = realdatastart;
42918 goto err;
42919 }
42920 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42921 }
42922 if (IS_ERR_VALUE(result)) {
42923 printk("Unable to read data+bss, errno %d\n", (int)-result);
42924 + down_write(&current->mm->mmap_sem);
42925 do_munmap(current->mm, textpos, text_len);
42926 do_munmap(current->mm, realdatastart, len);
42927 + up_write(&current->mm->mmap_sem);
42928 ret = result;
42929 goto err;
42930 }
42931 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42932 }
42933 if (IS_ERR_VALUE(result)) {
42934 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42935 + down_write(&current->mm->mmap_sem);
42936 do_munmap(current->mm, textpos, text_len + data_len + extra +
42937 MAX_SHARED_LIBS * sizeof(unsigned long));
42938 + up_write(&current->mm->mmap_sem);
42939 ret = result;
42940 goto err;
42941 }
42942 diff --git a/fs/bio.c b/fs/bio.c
42943 index b980ecd..74800bf 100644
42944 --- a/fs/bio.c
42945 +++ b/fs/bio.c
42946 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42947 /*
42948 * Overflow, abort
42949 */
42950 - if (end < start)
42951 + if (end < start || end - start > INT_MAX - nr_pages)
42952 return ERR_PTR(-EINVAL);
42953
42954 nr_pages += end - start;
42955 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42956 const int read = bio_data_dir(bio) == READ;
42957 struct bio_map_data *bmd = bio->bi_private;
42958 int i;
42959 - char *p = bmd->sgvecs[0].iov_base;
42960 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42961
42962 __bio_for_each_segment(bvec, bio, i, 0) {
42963 char *addr = page_address(bvec->bv_page);
42964 diff --git a/fs/block_dev.c b/fs/block_dev.c
42965 index 5e9f198..6bf9b1c 100644
42966 --- a/fs/block_dev.c
42967 +++ b/fs/block_dev.c
42968 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42969 else if (bdev->bd_contains == bdev)
42970 return true; /* is a whole device which isn't held */
42971
42972 - else if (whole->bd_holder == bd_may_claim)
42973 + else if (whole->bd_holder == (void *)bd_may_claim)
42974 return true; /* is a partition of a device that is being partitioned */
42975 else if (whole->bd_holder != NULL)
42976 return false; /* is a partition of a held device */
42977 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42978 index d986824..af1befd 100644
42979 --- a/fs/btrfs/check-integrity.c
42980 +++ b/fs/btrfs/check-integrity.c
42981 @@ -157,7 +157,7 @@ struct btrfsic_block {
42982 union {
42983 bio_end_io_t *bio;
42984 bh_end_io_t *bh;
42985 - } orig_bio_bh_end_io;
42986 + } __no_const orig_bio_bh_end_io;
42987 int submit_bio_bh_rw;
42988 u64 flush_gen; /* only valid if !never_written */
42989 };
42990 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42991 index 0639a55..7d9e07f 100644
42992 --- a/fs/btrfs/ctree.c
42993 +++ b/fs/btrfs/ctree.c
42994 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42995 free_extent_buffer(buf);
42996 add_root_to_dirty_list(root);
42997 } else {
42998 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42999 - parent_start = parent->start;
43000 - else
43001 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43002 + if (parent)
43003 + parent_start = parent->start;
43004 + else
43005 + parent_start = 0;
43006 + } else
43007 parent_start = 0;
43008
43009 WARN_ON(trans->transid != btrfs_header_generation(parent));
43010 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43011 index 892b347..b3db246 100644
43012 --- a/fs/btrfs/inode.c
43013 +++ b/fs/btrfs/inode.c
43014 @@ -6930,7 +6930,7 @@ fail:
43015 return -ENOMEM;
43016 }
43017
43018 -static int btrfs_getattr(struct vfsmount *mnt,
43019 +int btrfs_getattr(struct vfsmount *mnt,
43020 struct dentry *dentry, struct kstat *stat)
43021 {
43022 struct inode *inode = dentry->d_inode;
43023 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43024 return 0;
43025 }
43026
43027 +EXPORT_SYMBOL(btrfs_getattr);
43028 +
43029 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43030 +{
43031 + return BTRFS_I(inode)->root->anon_dev;
43032 +}
43033 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43034 +
43035 /*
43036 * If a file is moved, it will inherit the cow and compression flags of the new
43037 * directory.
43038 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43039 index d8b5471..e5463d7 100644
43040 --- a/fs/btrfs/ioctl.c
43041 +++ b/fs/btrfs/ioctl.c
43042 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43043 for (i = 0; i < num_types; i++) {
43044 struct btrfs_space_info *tmp;
43045
43046 + /* Don't copy in more than we allocated */
43047 if (!slot_count)
43048 break;
43049
43050 + slot_count--;
43051 +
43052 info = NULL;
43053 rcu_read_lock();
43054 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43055 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43056 memcpy(dest, &space, sizeof(space));
43057 dest++;
43058 space_args.total_spaces++;
43059 - slot_count--;
43060 }
43061 - if (!slot_count)
43062 - break;
43063 }
43064 up_read(&info->groups_sem);
43065 }
43066
43067 - user_dest = (struct btrfs_ioctl_space_info *)
43068 + user_dest = (struct btrfs_ioctl_space_info __user *)
43069 (arg + sizeof(struct btrfs_ioctl_space_args));
43070
43071 if (copy_to_user(user_dest, dest_orig, alloc_size))
43072 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43073 index 8c1aae2..1e46446 100644
43074 --- a/fs/btrfs/relocation.c
43075 +++ b/fs/btrfs/relocation.c
43076 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43077 }
43078 spin_unlock(&rc->reloc_root_tree.lock);
43079
43080 - BUG_ON((struct btrfs_root *)node->data != root);
43081 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43082
43083 if (!del) {
43084 spin_lock(&rc->reloc_root_tree.lock);
43085 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43086 index 622f469..e8d2d55 100644
43087 --- a/fs/cachefiles/bind.c
43088 +++ b/fs/cachefiles/bind.c
43089 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43090 args);
43091
43092 /* start by checking things over */
43093 - ASSERT(cache->fstop_percent >= 0 &&
43094 - cache->fstop_percent < cache->fcull_percent &&
43095 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43096 cache->fcull_percent < cache->frun_percent &&
43097 cache->frun_percent < 100);
43098
43099 - ASSERT(cache->bstop_percent >= 0 &&
43100 - cache->bstop_percent < cache->bcull_percent &&
43101 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43102 cache->bcull_percent < cache->brun_percent &&
43103 cache->brun_percent < 100);
43104
43105 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43106 index 0a1467b..6a53245 100644
43107 --- a/fs/cachefiles/daemon.c
43108 +++ b/fs/cachefiles/daemon.c
43109 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43110 if (n > buflen)
43111 return -EMSGSIZE;
43112
43113 - if (copy_to_user(_buffer, buffer, n) != 0)
43114 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43115 return -EFAULT;
43116
43117 return n;
43118 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43119 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43120 return -EIO;
43121
43122 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43123 + if (datalen > PAGE_SIZE - 1)
43124 return -EOPNOTSUPP;
43125
43126 /* drag the command string into the kernel so we can parse it */
43127 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43128 if (args[0] != '%' || args[1] != '\0')
43129 return -EINVAL;
43130
43131 - if (fstop < 0 || fstop >= cache->fcull_percent)
43132 + if (fstop >= cache->fcull_percent)
43133 return cachefiles_daemon_range_error(cache, args);
43134
43135 cache->fstop_percent = fstop;
43136 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43137 if (args[0] != '%' || args[1] != '\0')
43138 return -EINVAL;
43139
43140 - if (bstop < 0 || bstop >= cache->bcull_percent)
43141 + if (bstop >= cache->bcull_percent)
43142 return cachefiles_daemon_range_error(cache, args);
43143
43144 cache->bstop_percent = bstop;
43145 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43146 index bd6bc1b..b627b53 100644
43147 --- a/fs/cachefiles/internal.h
43148 +++ b/fs/cachefiles/internal.h
43149 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43150 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43151 struct rb_root active_nodes; /* active nodes (can't be culled) */
43152 rwlock_t active_lock; /* lock for active_nodes */
43153 - atomic_t gravecounter; /* graveyard uniquifier */
43154 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43155 unsigned frun_percent; /* when to stop culling (% files) */
43156 unsigned fcull_percent; /* when to start culling (% files) */
43157 unsigned fstop_percent; /* when to stop allocating (% files) */
43158 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43159 * proc.c
43160 */
43161 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43162 -extern atomic_t cachefiles_lookup_histogram[HZ];
43163 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43164 -extern atomic_t cachefiles_create_histogram[HZ];
43165 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43166 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43167 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43168
43169 extern int __init cachefiles_proc_init(void);
43170 extern void cachefiles_proc_cleanup(void);
43171 static inline
43172 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43173 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43174 {
43175 unsigned long jif = jiffies - start_jif;
43176 if (jif >= HZ)
43177 jif = HZ - 1;
43178 - atomic_inc(&histogram[jif]);
43179 + atomic_inc_unchecked(&histogram[jif]);
43180 }
43181
43182 #else
43183 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43184 index a0358c2..d6137f2 100644
43185 --- a/fs/cachefiles/namei.c
43186 +++ b/fs/cachefiles/namei.c
43187 @@ -318,7 +318,7 @@ try_again:
43188 /* first step is to make up a grave dentry in the graveyard */
43189 sprintf(nbuffer, "%08x%08x",
43190 (uint32_t) get_seconds(),
43191 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43192 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43193
43194 /* do the multiway lock magic */
43195 trap = lock_rename(cache->graveyard, dir);
43196 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43197 index eccd339..4c1d995 100644
43198 --- a/fs/cachefiles/proc.c
43199 +++ b/fs/cachefiles/proc.c
43200 @@ -14,9 +14,9 @@
43201 #include <linux/seq_file.h>
43202 #include "internal.h"
43203
43204 -atomic_t cachefiles_lookup_histogram[HZ];
43205 -atomic_t cachefiles_mkdir_histogram[HZ];
43206 -atomic_t cachefiles_create_histogram[HZ];
43207 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43208 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43209 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43210
43211 /*
43212 * display the latency histogram
43213 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43214 return 0;
43215 default:
43216 index = (unsigned long) v - 3;
43217 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43218 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43219 - z = atomic_read(&cachefiles_create_histogram[index]);
43220 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43221 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43222 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43223 if (x == 0 && y == 0 && z == 0)
43224 return 0;
43225
43226 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43227 index 0e3c092..818480e 100644
43228 --- a/fs/cachefiles/rdwr.c
43229 +++ b/fs/cachefiles/rdwr.c
43230 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43231 old_fs = get_fs();
43232 set_fs(KERNEL_DS);
43233 ret = file->f_op->write(
43234 - file, (const void __user *) data, len, &pos);
43235 + file, (const void __force_user *) data, len, &pos);
43236 set_fs(old_fs);
43237 kunmap(page);
43238 if (ret != len)
43239 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43240 index 3e8094b..cb3ff3d 100644
43241 --- a/fs/ceph/dir.c
43242 +++ b/fs/ceph/dir.c
43243 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43244 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43245 struct ceph_mds_client *mdsc = fsc->mdsc;
43246 unsigned frag = fpos_frag(filp->f_pos);
43247 - int off = fpos_off(filp->f_pos);
43248 + unsigned int off = fpos_off(filp->f_pos);
43249 int err;
43250 u32 ftype;
43251 struct ceph_mds_reply_info_parsed *rinfo;
43252 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43253 if (nd &&
43254 (nd->flags & LOOKUP_OPEN) &&
43255 !(nd->intent.open.flags & O_CREAT)) {
43256 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43257 + int mode = nd->intent.open.create_mode & ~current_umask();
43258 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43259 }
43260
43261 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43262 index cfd1ce3..6b13a74 100644
43263 --- a/fs/cifs/asn1.c
43264 +++ b/fs/cifs/asn1.c
43265 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43266
43267 static int
43268 asn1_oid_decode(struct asn1_ctx *ctx,
43269 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43270 +static int
43271 +asn1_oid_decode(struct asn1_ctx *ctx,
43272 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43273 {
43274 unsigned long subid;
43275 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43276 index 24b3dfc..3cd5454 100644
43277 --- a/fs/cifs/cifs_debug.c
43278 +++ b/fs/cifs/cifs_debug.c
43279 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43280
43281 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43282 #ifdef CONFIG_CIFS_STATS2
43283 - atomic_set(&totBufAllocCount, 0);
43284 - atomic_set(&totSmBufAllocCount, 0);
43285 + atomic_set_unchecked(&totBufAllocCount, 0);
43286 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43287 #endif /* CONFIG_CIFS_STATS2 */
43288 spin_lock(&cifs_tcp_ses_lock);
43289 list_for_each(tmp1, &cifs_tcp_ses_list) {
43290 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43291 tcon = list_entry(tmp3,
43292 struct cifs_tcon,
43293 tcon_list);
43294 - atomic_set(&tcon->num_smbs_sent, 0);
43295 - atomic_set(&tcon->num_writes, 0);
43296 - atomic_set(&tcon->num_reads, 0);
43297 - atomic_set(&tcon->num_oplock_brks, 0);
43298 - atomic_set(&tcon->num_opens, 0);
43299 - atomic_set(&tcon->num_posixopens, 0);
43300 - atomic_set(&tcon->num_posixmkdirs, 0);
43301 - atomic_set(&tcon->num_closes, 0);
43302 - atomic_set(&tcon->num_deletes, 0);
43303 - atomic_set(&tcon->num_mkdirs, 0);
43304 - atomic_set(&tcon->num_rmdirs, 0);
43305 - atomic_set(&tcon->num_renames, 0);
43306 - atomic_set(&tcon->num_t2renames, 0);
43307 - atomic_set(&tcon->num_ffirst, 0);
43308 - atomic_set(&tcon->num_fnext, 0);
43309 - atomic_set(&tcon->num_fclose, 0);
43310 - atomic_set(&tcon->num_hardlinks, 0);
43311 - atomic_set(&tcon->num_symlinks, 0);
43312 - atomic_set(&tcon->num_locks, 0);
43313 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43314 + atomic_set_unchecked(&tcon->num_writes, 0);
43315 + atomic_set_unchecked(&tcon->num_reads, 0);
43316 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43317 + atomic_set_unchecked(&tcon->num_opens, 0);
43318 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43319 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43320 + atomic_set_unchecked(&tcon->num_closes, 0);
43321 + atomic_set_unchecked(&tcon->num_deletes, 0);
43322 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43323 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43324 + atomic_set_unchecked(&tcon->num_renames, 0);
43325 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43326 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43327 + atomic_set_unchecked(&tcon->num_fnext, 0);
43328 + atomic_set_unchecked(&tcon->num_fclose, 0);
43329 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43330 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43331 + atomic_set_unchecked(&tcon->num_locks, 0);
43332 }
43333 }
43334 }
43335 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43336 smBufAllocCount.counter, cifs_min_small);
43337 #ifdef CONFIG_CIFS_STATS2
43338 seq_printf(m, "Total Large %d Small %d Allocations\n",
43339 - atomic_read(&totBufAllocCount),
43340 - atomic_read(&totSmBufAllocCount));
43341 + atomic_read_unchecked(&totBufAllocCount),
43342 + atomic_read_unchecked(&totSmBufAllocCount));
43343 #endif /* CONFIG_CIFS_STATS2 */
43344
43345 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43346 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43347 if (tcon->need_reconnect)
43348 seq_puts(m, "\tDISCONNECTED ");
43349 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43350 - atomic_read(&tcon->num_smbs_sent),
43351 - atomic_read(&tcon->num_oplock_brks));
43352 + atomic_read_unchecked(&tcon->num_smbs_sent),
43353 + atomic_read_unchecked(&tcon->num_oplock_brks));
43354 seq_printf(m, "\nReads: %d Bytes: %lld",
43355 - atomic_read(&tcon->num_reads),
43356 + atomic_read_unchecked(&tcon->num_reads),
43357 (long long)(tcon->bytes_read));
43358 seq_printf(m, "\nWrites: %d Bytes: %lld",
43359 - atomic_read(&tcon->num_writes),
43360 + atomic_read_unchecked(&tcon->num_writes),
43361 (long long)(tcon->bytes_written));
43362 seq_printf(m, "\nFlushes: %d",
43363 - atomic_read(&tcon->num_flushes));
43364 + atomic_read_unchecked(&tcon->num_flushes));
43365 seq_printf(m, "\nLocks: %d HardLinks: %d "
43366 "Symlinks: %d",
43367 - atomic_read(&tcon->num_locks),
43368 - atomic_read(&tcon->num_hardlinks),
43369 - atomic_read(&tcon->num_symlinks));
43370 + atomic_read_unchecked(&tcon->num_locks),
43371 + atomic_read_unchecked(&tcon->num_hardlinks),
43372 + atomic_read_unchecked(&tcon->num_symlinks));
43373 seq_printf(m, "\nOpens: %d Closes: %d "
43374 "Deletes: %d",
43375 - atomic_read(&tcon->num_opens),
43376 - atomic_read(&tcon->num_closes),
43377 - atomic_read(&tcon->num_deletes));
43378 + atomic_read_unchecked(&tcon->num_opens),
43379 + atomic_read_unchecked(&tcon->num_closes),
43380 + atomic_read_unchecked(&tcon->num_deletes));
43381 seq_printf(m, "\nPosix Opens: %d "
43382 "Posix Mkdirs: %d",
43383 - atomic_read(&tcon->num_posixopens),
43384 - atomic_read(&tcon->num_posixmkdirs));
43385 + atomic_read_unchecked(&tcon->num_posixopens),
43386 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43387 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43388 - atomic_read(&tcon->num_mkdirs),
43389 - atomic_read(&tcon->num_rmdirs));
43390 + atomic_read_unchecked(&tcon->num_mkdirs),
43391 + atomic_read_unchecked(&tcon->num_rmdirs));
43392 seq_printf(m, "\nRenames: %d T2 Renames %d",
43393 - atomic_read(&tcon->num_renames),
43394 - atomic_read(&tcon->num_t2renames));
43395 + atomic_read_unchecked(&tcon->num_renames),
43396 + atomic_read_unchecked(&tcon->num_t2renames));
43397 seq_printf(m, "\nFindFirst: %d FNext %d "
43398 "FClose %d",
43399 - atomic_read(&tcon->num_ffirst),
43400 - atomic_read(&tcon->num_fnext),
43401 - atomic_read(&tcon->num_fclose));
43402 + atomic_read_unchecked(&tcon->num_ffirst),
43403 + atomic_read_unchecked(&tcon->num_fnext),
43404 + atomic_read_unchecked(&tcon->num_fclose));
43405 }
43406 }
43407 }
43408 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43409 index 6ee1cb4..8443157 100644
43410 --- a/fs/cifs/cifsfs.c
43411 +++ b/fs/cifs/cifsfs.c
43412 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43413 cifs_req_cachep = kmem_cache_create("cifs_request",
43414 CIFSMaxBufSize +
43415 MAX_CIFS_HDR_SIZE, 0,
43416 - SLAB_HWCACHE_ALIGN, NULL);
43417 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43418 if (cifs_req_cachep == NULL)
43419 return -ENOMEM;
43420
43421 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43422 efficient to alloc 1 per page off the slab compared to 17K (5page)
43423 alloc of large cifs buffers even when page debugging is on */
43424 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43425 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43426 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43427 NULL);
43428 if (cifs_sm_req_cachep == NULL) {
43429 mempool_destroy(cifs_req_poolp);
43430 @@ -1101,8 +1101,8 @@ init_cifs(void)
43431 atomic_set(&bufAllocCount, 0);
43432 atomic_set(&smBufAllocCount, 0);
43433 #ifdef CONFIG_CIFS_STATS2
43434 - atomic_set(&totBufAllocCount, 0);
43435 - atomic_set(&totSmBufAllocCount, 0);
43436 + atomic_set_unchecked(&totBufAllocCount, 0);
43437 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43438 #endif /* CONFIG_CIFS_STATS2 */
43439
43440 atomic_set(&midCount, 0);
43441 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43442 index d47d20a..77e8b33 100644
43443 --- a/fs/cifs/cifsglob.h
43444 +++ b/fs/cifs/cifsglob.h
43445 @@ -388,28 +388,28 @@ struct cifs_tcon {
43446 __u16 Flags; /* optional support bits */
43447 enum statusEnum tidStatus;
43448 #ifdef CONFIG_CIFS_STATS
43449 - atomic_t num_smbs_sent;
43450 - atomic_t num_writes;
43451 - atomic_t num_reads;
43452 - atomic_t num_flushes;
43453 - atomic_t num_oplock_brks;
43454 - atomic_t num_opens;
43455 - atomic_t num_closes;
43456 - atomic_t num_deletes;
43457 - atomic_t num_mkdirs;
43458 - atomic_t num_posixopens;
43459 - atomic_t num_posixmkdirs;
43460 - atomic_t num_rmdirs;
43461 - atomic_t num_renames;
43462 - atomic_t num_t2renames;
43463 - atomic_t num_ffirst;
43464 - atomic_t num_fnext;
43465 - atomic_t num_fclose;
43466 - atomic_t num_hardlinks;
43467 - atomic_t num_symlinks;
43468 - atomic_t num_locks;
43469 - atomic_t num_acl_get;
43470 - atomic_t num_acl_set;
43471 + atomic_unchecked_t num_smbs_sent;
43472 + atomic_unchecked_t num_writes;
43473 + atomic_unchecked_t num_reads;
43474 + atomic_unchecked_t num_flushes;
43475 + atomic_unchecked_t num_oplock_brks;
43476 + atomic_unchecked_t num_opens;
43477 + atomic_unchecked_t num_closes;
43478 + atomic_unchecked_t num_deletes;
43479 + atomic_unchecked_t num_mkdirs;
43480 + atomic_unchecked_t num_posixopens;
43481 + atomic_unchecked_t num_posixmkdirs;
43482 + atomic_unchecked_t num_rmdirs;
43483 + atomic_unchecked_t num_renames;
43484 + atomic_unchecked_t num_t2renames;
43485 + atomic_unchecked_t num_ffirst;
43486 + atomic_unchecked_t num_fnext;
43487 + atomic_unchecked_t num_fclose;
43488 + atomic_unchecked_t num_hardlinks;
43489 + atomic_unchecked_t num_symlinks;
43490 + atomic_unchecked_t num_locks;
43491 + atomic_unchecked_t num_acl_get;
43492 + atomic_unchecked_t num_acl_set;
43493 #ifdef CONFIG_CIFS_STATS2
43494 unsigned long long time_writes;
43495 unsigned long long time_reads;
43496 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43497 }
43498
43499 #ifdef CONFIG_CIFS_STATS
43500 -#define cifs_stats_inc atomic_inc
43501 +#define cifs_stats_inc atomic_inc_unchecked
43502
43503 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43504 unsigned int bytes)
43505 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43506 /* Various Debug counters */
43507 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43508 #ifdef CONFIG_CIFS_STATS2
43509 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43510 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43511 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43512 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43513 #endif
43514 GLOBAL_EXTERN atomic_t smBufAllocCount;
43515 GLOBAL_EXTERN atomic_t midCount;
43516 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43517 index 6b0e064..94e6c3c 100644
43518 --- a/fs/cifs/link.c
43519 +++ b/fs/cifs/link.c
43520 @@ -600,7 +600,7 @@ symlink_exit:
43521
43522 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43523 {
43524 - char *p = nd_get_link(nd);
43525 + const char *p = nd_get_link(nd);
43526 if (!IS_ERR(p))
43527 kfree(p);
43528 }
43529 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43530 index 703ef5c..2a44ed5 100644
43531 --- a/fs/cifs/misc.c
43532 +++ b/fs/cifs/misc.c
43533 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43534 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43535 atomic_inc(&bufAllocCount);
43536 #ifdef CONFIG_CIFS_STATS2
43537 - atomic_inc(&totBufAllocCount);
43538 + atomic_inc_unchecked(&totBufAllocCount);
43539 #endif /* CONFIG_CIFS_STATS2 */
43540 }
43541
43542 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43543 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43544 atomic_inc(&smBufAllocCount);
43545 #ifdef CONFIG_CIFS_STATS2
43546 - atomic_inc(&totSmBufAllocCount);
43547 + atomic_inc_unchecked(&totSmBufAllocCount);
43548 #endif /* CONFIG_CIFS_STATS2 */
43549
43550 }
43551 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43552 index 6901578..d402eb5 100644
43553 --- a/fs/coda/cache.c
43554 +++ b/fs/coda/cache.c
43555 @@ -24,7 +24,7 @@
43556 #include "coda_linux.h"
43557 #include "coda_cache.h"
43558
43559 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43560 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43561
43562 /* replace or extend an acl cache hit */
43563 void coda_cache_enter(struct inode *inode, int mask)
43564 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43565 struct coda_inode_info *cii = ITOC(inode);
43566
43567 spin_lock(&cii->c_lock);
43568 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43569 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43570 if (cii->c_uid != current_fsuid()) {
43571 cii->c_uid = current_fsuid();
43572 cii->c_cached_perm = mask;
43573 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43574 {
43575 struct coda_inode_info *cii = ITOC(inode);
43576 spin_lock(&cii->c_lock);
43577 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43578 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43579 spin_unlock(&cii->c_lock);
43580 }
43581
43582 /* remove all acl caches */
43583 void coda_cache_clear_all(struct super_block *sb)
43584 {
43585 - atomic_inc(&permission_epoch);
43586 + atomic_inc_unchecked(&permission_epoch);
43587 }
43588
43589
43590 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43591 spin_lock(&cii->c_lock);
43592 hit = (mask & cii->c_cached_perm) == mask &&
43593 cii->c_uid == current_fsuid() &&
43594 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43595 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43596 spin_unlock(&cii->c_lock);
43597
43598 return hit;
43599 diff --git a/fs/compat.c b/fs/compat.c
43600 index 07880ba..3fb2862 100644
43601 --- a/fs/compat.c
43602 +++ b/fs/compat.c
43603 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43604
43605 set_fs(KERNEL_DS);
43606 /* The __user pointer cast is valid because of the set_fs() */
43607 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43608 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43609 set_fs(oldfs);
43610 /* truncating is ok because it's a user address */
43611 if (!ret)
43612 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43613 goto out;
43614
43615 ret = -EINVAL;
43616 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43617 + if (nr_segs > UIO_MAXIOV)
43618 goto out;
43619 if (nr_segs > fast_segs) {
43620 ret = -ENOMEM;
43621 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43622
43623 struct compat_readdir_callback {
43624 struct compat_old_linux_dirent __user *dirent;
43625 + struct file * file;
43626 int result;
43627 };
43628
43629 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43630 buf->result = -EOVERFLOW;
43631 return -EOVERFLOW;
43632 }
43633 +
43634 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43635 + return 0;
43636 +
43637 buf->result++;
43638 dirent = buf->dirent;
43639 if (!access_ok(VERIFY_WRITE, dirent,
43640 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43641
43642 buf.result = 0;
43643 buf.dirent = dirent;
43644 + buf.file = file;
43645
43646 error = vfs_readdir(file, compat_fillonedir, &buf);
43647 if (buf.result)
43648 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
43649 struct compat_getdents_callback {
43650 struct compat_linux_dirent __user *current_dir;
43651 struct compat_linux_dirent __user *previous;
43652 + struct file * file;
43653 int count;
43654 int error;
43655 };
43656 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43657 buf->error = -EOVERFLOW;
43658 return -EOVERFLOW;
43659 }
43660 +
43661 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43662 + return 0;
43663 +
43664 dirent = buf->previous;
43665 if (dirent) {
43666 if (__put_user(offset, &dirent->d_off))
43667 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43668 buf.previous = NULL;
43669 buf.count = count;
43670 buf.error = 0;
43671 + buf.file = file;
43672
43673 error = vfs_readdir(file, compat_filldir, &buf);
43674 if (error >= 0)
43675 @@ -990,6 +1002,7 @@ out:
43676 struct compat_getdents_callback64 {
43677 struct linux_dirent64 __user *current_dir;
43678 struct linux_dirent64 __user *previous;
43679 + struct file * file;
43680 int count;
43681 int error;
43682 };
43683 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43684 buf->error = -EINVAL; /* only used if we fail.. */
43685 if (reclen > buf->count)
43686 return -EINVAL;
43687 +
43688 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43689 + return 0;
43690 +
43691 dirent = buf->previous;
43692
43693 if (dirent) {
43694 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43695 buf.previous = NULL;
43696 buf.count = count;
43697 buf.error = 0;
43698 + buf.file = file;
43699
43700 error = vfs_readdir(file, compat_filldir64, &buf);
43701 if (error >= 0)
43702 error = buf.error;
43703 lastdirent = buf.previous;
43704 if (lastdirent) {
43705 - typeof(lastdirent->d_off) d_off = file->f_pos;
43706 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43707 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43708 error = -EFAULT;
43709 else
43710 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43711 index 112e45a..b59845b 100644
43712 --- a/fs/compat_binfmt_elf.c
43713 +++ b/fs/compat_binfmt_elf.c
43714 @@ -30,11 +30,13 @@
43715 #undef elf_phdr
43716 #undef elf_shdr
43717 #undef elf_note
43718 +#undef elf_dyn
43719 #undef elf_addr_t
43720 #define elfhdr elf32_hdr
43721 #define elf_phdr elf32_phdr
43722 #define elf_shdr elf32_shdr
43723 #define elf_note elf32_note
43724 +#define elf_dyn Elf32_Dyn
43725 #define elf_addr_t Elf32_Addr
43726
43727 /*
43728 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43729 index a26bea1..ae23e72 100644
43730 --- a/fs/compat_ioctl.c
43731 +++ b/fs/compat_ioctl.c
43732 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43733
43734 err = get_user(palp, &up->palette);
43735 err |= get_user(length, &up->length);
43736 + if (err)
43737 + return -EFAULT;
43738
43739 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43740 err = put_user(compat_ptr(palp), &up_native->palette);
43741 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43742 return -EFAULT;
43743 if (__get_user(udata, &ss32->iomem_base))
43744 return -EFAULT;
43745 - ss.iomem_base = compat_ptr(udata);
43746 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43747 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43748 __get_user(ss.port_high, &ss32->port_high))
43749 return -EFAULT;
43750 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43751 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43752 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43753 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43754 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43755 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43756 return -EFAULT;
43757
43758 return ioctl_preallocate(file, p);
43759 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43760 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43761 {
43762 unsigned int a, b;
43763 - a = *(unsigned int *)p;
43764 - b = *(unsigned int *)q;
43765 + a = *(const unsigned int *)p;
43766 + b = *(const unsigned int *)q;
43767 if (a > b)
43768 return 1;
43769 if (a < b)
43770 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43771 index 5ddd7eb..c18bf04 100644
43772 --- a/fs/configfs/dir.c
43773 +++ b/fs/configfs/dir.c
43774 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43775 }
43776 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43777 struct configfs_dirent *next;
43778 - const char * name;
43779 + const unsigned char * name;
43780 + char d_name[sizeof(next->s_dentry->d_iname)];
43781 int len;
43782 struct inode *inode = NULL;
43783
43784 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43785 continue;
43786
43787 name = configfs_get_name(next);
43788 - len = strlen(name);
43789 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43790 + len = next->s_dentry->d_name.len;
43791 + memcpy(d_name, name, len);
43792 + name = d_name;
43793 + } else
43794 + len = strlen(name);
43795
43796 /*
43797 * We'll have a dentry and an inode for
43798 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
43799 index 2b6cb23..d76e879 100644
43800 --- a/fs/configfs/file.c
43801 +++ b/fs/configfs/file.c
43802 @@ -135,6 +135,8 @@ out:
43803 */
43804
43805 static int
43806 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
43807 +static int
43808 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
43809 {
43810 int error;
43811 diff --git a/fs/dcache.c b/fs/dcache.c
43812 index 2576d14..0cec38d 100644
43813 --- a/fs/dcache.c
43814 +++ b/fs/dcache.c
43815 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43816 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43817
43818 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43819 - unsigned long hash)
43820 + unsigned int hash)
43821 {
43822 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43823 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43824 + hash += (unsigned long) parent / L1_CACHE_BYTES;
43825 + hash = hash + (hash >> D_HASHBITS);
43826 return dentry_hashtable + (hash & D_HASHMASK);
43827 }
43828
43829 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43830 mempages -= reserve;
43831
43832 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43833 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43834 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43835
43836 dcache_init();
43837 inode_init();
43838 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43839 index 956d5dd..e755e04 100644
43840 --- a/fs/debugfs/inode.c
43841 +++ b/fs/debugfs/inode.c
43842 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43843 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43844 {
43845 return debugfs_create_file(name,
43846 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43847 + S_IFDIR | S_IRWXU,
43848 +#else
43849 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43850 +#endif
43851 parent, NULL, NULL);
43852 }
43853 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43854 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43855 index ab35b11..b30af66 100644
43856 --- a/fs/ecryptfs/inode.c
43857 +++ b/fs/ecryptfs/inode.c
43858 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43859 old_fs = get_fs();
43860 set_fs(get_ds());
43861 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43862 - (char __user *)lower_buf,
43863 + (char __force_user *)lower_buf,
43864 lower_bufsiz);
43865 set_fs(old_fs);
43866 if (rc < 0)
43867 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43868 }
43869 old_fs = get_fs();
43870 set_fs(get_ds());
43871 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43872 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43873 set_fs(old_fs);
43874 if (rc < 0) {
43875 kfree(buf);
43876 @@ -733,7 +733,7 @@ out:
43877 static void
43878 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43879 {
43880 - char *buf = nd_get_link(nd);
43881 + const char *buf = nd_get_link(nd);
43882 if (!IS_ERR(buf)) {
43883 /* Free the char* */
43884 kfree(buf);
43885 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43886 index 3a06f40..f7af544 100644
43887 --- a/fs/ecryptfs/miscdev.c
43888 +++ b/fs/ecryptfs/miscdev.c
43889 @@ -345,7 +345,7 @@ check_list:
43890 goto out_unlock_msg_ctx;
43891 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43892 if (msg_ctx->msg) {
43893 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43894 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43895 goto out_unlock_msg_ctx;
43896 i += packet_length_size;
43897 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43898 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43899 index b2a34a1..162fa69 100644
43900 --- a/fs/ecryptfs/read_write.c
43901 +++ b/fs/ecryptfs/read_write.c
43902 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43903 return -EIO;
43904 fs_save = get_fs();
43905 set_fs(get_ds());
43906 - rc = vfs_write(lower_file, data, size, &offset);
43907 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43908 set_fs(fs_save);
43909 mark_inode_dirty_sync(ecryptfs_inode);
43910 return rc;
43911 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43912 return -EIO;
43913 fs_save = get_fs();
43914 set_fs(get_ds());
43915 - rc = vfs_read(lower_file, data, size, &offset);
43916 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43917 set_fs(fs_save);
43918 return rc;
43919 }
43920 diff --git a/fs/exec.c b/fs/exec.c
43921 index 153dee1..ab4ebe9 100644
43922 --- a/fs/exec.c
43923 +++ b/fs/exec.c
43924 @@ -55,6 +55,13 @@
43925 #include <linux/pipe_fs_i.h>
43926 #include <linux/oom.h>
43927 #include <linux/compat.h>
43928 +#include <linux/random.h>
43929 +#include <linux/seq_file.h>
43930 +
43931 +#ifdef CONFIG_PAX_REFCOUNT
43932 +#include <linux/kallsyms.h>
43933 +#include <linux/kdebug.h>
43934 +#endif
43935
43936 #include <asm/uaccess.h>
43937 #include <asm/mmu_context.h>
43938 @@ -63,6 +70,15 @@
43939 #include <trace/events/task.h>
43940 #include "internal.h"
43941
43942 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43943 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43944 +#endif
43945 +
43946 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43947 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43948 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43949 +#endif
43950 +
43951 int core_uses_pid;
43952 char core_pattern[CORENAME_MAX_SIZE] = "core";
43953 unsigned int core_pipe_limit;
43954 @@ -72,7 +88,7 @@ struct core_name {
43955 char *corename;
43956 int used, size;
43957 };
43958 -static atomic_t call_count = ATOMIC_INIT(1);
43959 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43960
43961 /* The maximal length of core_pattern is also specified in sysctl.c */
43962
43963 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43964 int write)
43965 {
43966 struct page *page;
43967 - int ret;
43968
43969 -#ifdef CONFIG_STACK_GROWSUP
43970 - if (write) {
43971 - ret = expand_downwards(bprm->vma, pos);
43972 - if (ret < 0)
43973 - return NULL;
43974 - }
43975 -#endif
43976 - ret = get_user_pages(current, bprm->mm, pos,
43977 - 1, write, 1, &page, NULL);
43978 - if (ret <= 0)
43979 + if (0 > expand_downwards(bprm->vma, pos))
43980 + return NULL;
43981 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43982 return NULL;
43983
43984 if (write) {
43985 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43986 if (size <= ARG_MAX)
43987 return page;
43988
43989 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43990 + // only allow 512KB for argv+env on suid/sgid binaries
43991 + // to prevent easy ASLR exhaustion
43992 + if (((bprm->cred->euid != current_euid()) ||
43993 + (bprm->cred->egid != current_egid())) &&
43994 + (size > (512 * 1024))) {
43995 + put_page(page);
43996 + return NULL;
43997 + }
43998 +#endif
43999 +
44000 /*
44001 * Limit to 1/4-th the stack size for the argv+env strings.
44002 * This ensures that:
44003 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44004 vma->vm_end = STACK_TOP_MAX;
44005 vma->vm_start = vma->vm_end - PAGE_SIZE;
44006 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44007 +
44008 +#ifdef CONFIG_PAX_SEGMEXEC
44009 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44010 +#endif
44011 +
44012 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44013 INIT_LIST_HEAD(&vma->anon_vma_chain);
44014
44015 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44016 mm->stack_vm = mm->total_vm = 1;
44017 up_write(&mm->mmap_sem);
44018 bprm->p = vma->vm_end - sizeof(void *);
44019 +
44020 +#ifdef CONFIG_PAX_RANDUSTACK
44021 + if (randomize_va_space)
44022 + bprm->p ^= random32() & ~PAGE_MASK;
44023 +#endif
44024 +
44025 return 0;
44026 err:
44027 up_write(&mm->mmap_sem);
44028 @@ -398,19 +428,7 @@ err:
44029 return err;
44030 }
44031
44032 -struct user_arg_ptr {
44033 -#ifdef CONFIG_COMPAT
44034 - bool is_compat;
44035 -#endif
44036 - union {
44037 - const char __user *const __user *native;
44038 -#ifdef CONFIG_COMPAT
44039 - compat_uptr_t __user *compat;
44040 -#endif
44041 - } ptr;
44042 -};
44043 -
44044 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44045 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44046 {
44047 const char __user *native;
44048
44049 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44050 compat_uptr_t compat;
44051
44052 if (get_user(compat, argv.ptr.compat + nr))
44053 - return ERR_PTR(-EFAULT);
44054 + return (const char __force_user *)ERR_PTR(-EFAULT);
44055
44056 return compat_ptr(compat);
44057 }
44058 #endif
44059
44060 if (get_user(native, argv.ptr.native + nr))
44061 - return ERR_PTR(-EFAULT);
44062 + return (const char __force_user *)ERR_PTR(-EFAULT);
44063
44064 return native;
44065 }
44066 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44067 if (!p)
44068 break;
44069
44070 - if (IS_ERR(p))
44071 + if (IS_ERR((const char __force_kernel *)p))
44072 return -EFAULT;
44073
44074 if (i++ >= max)
44075 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44076
44077 ret = -EFAULT;
44078 str = get_user_arg_ptr(argv, argc);
44079 - if (IS_ERR(str))
44080 + if (IS_ERR((const char __force_kernel *)str))
44081 goto out;
44082
44083 len = strnlen_user(str, MAX_ARG_STRLEN);
44084 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44085 int r;
44086 mm_segment_t oldfs = get_fs();
44087 struct user_arg_ptr argv = {
44088 - .ptr.native = (const char __user *const __user *)__argv,
44089 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44090 };
44091
44092 set_fs(KERNEL_DS);
44093 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44094 unsigned long new_end = old_end - shift;
44095 struct mmu_gather tlb;
44096
44097 - BUG_ON(new_start > new_end);
44098 + if (new_start >= new_end || new_start < mmap_min_addr)
44099 + return -ENOMEM;
44100
44101 /*
44102 * ensure there are no vmas between where we want to go
44103 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44104 if (vma != find_vma(mm, new_start))
44105 return -EFAULT;
44106
44107 +#ifdef CONFIG_PAX_SEGMEXEC
44108 + BUG_ON(pax_find_mirror_vma(vma));
44109 +#endif
44110 +
44111 /*
44112 * cover the whole range: [new_start, old_end)
44113 */
44114 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44115 stack_top = arch_align_stack(stack_top);
44116 stack_top = PAGE_ALIGN(stack_top);
44117
44118 - if (unlikely(stack_top < mmap_min_addr) ||
44119 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44120 - return -ENOMEM;
44121 -
44122 stack_shift = vma->vm_end - stack_top;
44123
44124 bprm->p -= stack_shift;
44125 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44126 bprm->exec -= stack_shift;
44127
44128 down_write(&mm->mmap_sem);
44129 +
44130 + /* Move stack pages down in memory. */
44131 + if (stack_shift) {
44132 + ret = shift_arg_pages(vma, stack_shift);
44133 + if (ret)
44134 + goto out_unlock;
44135 + }
44136 +
44137 vm_flags = VM_STACK_FLAGS;
44138
44139 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44140 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44141 + vm_flags &= ~VM_EXEC;
44142 +
44143 +#ifdef CONFIG_PAX_MPROTECT
44144 + if (mm->pax_flags & MF_PAX_MPROTECT)
44145 + vm_flags &= ~VM_MAYEXEC;
44146 +#endif
44147 +
44148 + }
44149 +#endif
44150 +
44151 /*
44152 * Adjust stack execute permissions; explicitly enable for
44153 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44154 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44155 goto out_unlock;
44156 BUG_ON(prev != vma);
44157
44158 - /* Move stack pages down in memory. */
44159 - if (stack_shift) {
44160 - ret = shift_arg_pages(vma, stack_shift);
44161 - if (ret)
44162 - goto out_unlock;
44163 - }
44164 -
44165 /* mprotect_fixup is overkill to remove the temporary stack flags */
44166 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44167
44168 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44169 old_fs = get_fs();
44170 set_fs(get_ds());
44171 /* The cast to a user pointer is valid due to the set_fs() */
44172 - result = vfs_read(file, (void __user *)addr, count, &pos);
44173 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44174 set_fs(old_fs);
44175 return result;
44176 }
44177 @@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44178 }
44179 rcu_read_unlock();
44180
44181 - if (p->fs->users > n_fs) {
44182 + if (atomic_read(&p->fs->users) > n_fs) {
44183 bprm->unsafe |= LSM_UNSAFE_SHARE;
44184 } else {
44185 res = -EAGAIN;
44186 @@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44187
44188 EXPORT_SYMBOL(search_binary_handler);
44189
44190 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44191 +static DEFINE_PER_CPU(u64, exec_counter);
44192 +static int __init init_exec_counters(void)
44193 +{
44194 + unsigned int cpu;
44195 +
44196 + for_each_possible_cpu(cpu) {
44197 + per_cpu(exec_counter, cpu) = (u64)cpu;
44198 + }
44199 +
44200 + return 0;
44201 +}
44202 +early_initcall(init_exec_counters);
44203 +static inline void increment_exec_counter(void)
44204 +{
44205 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44206 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44207 +}
44208 +#else
44209 +static inline void increment_exec_counter(void) {}
44210 +#endif
44211 +
44212 /*
44213 * sys_execve() executes a new program.
44214 */
44215 @@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
44216 struct user_arg_ptr envp,
44217 struct pt_regs *regs)
44218 {
44219 +#ifdef CONFIG_GRKERNSEC
44220 + struct file *old_exec_file;
44221 + struct acl_subject_label *old_acl;
44222 + struct rlimit old_rlim[RLIM_NLIMITS];
44223 +#endif
44224 struct linux_binprm *bprm;
44225 struct file *file;
44226 struct files_struct *displaced;
44227 @@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
44228 int retval;
44229 const struct cred *cred = current_cred();
44230
44231 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44232 +
44233 /*
44234 * We move the actual failure in case of RLIMIT_NPROC excess from
44235 * set*uid() to execve() because too many poorly written programs
44236 @@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
44237 if (IS_ERR(file))
44238 goto out_unmark;
44239
44240 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44241 + retval = -EPERM;
44242 + goto out_file;
44243 + }
44244 +
44245 sched_exec();
44246
44247 bprm->file = file;
44248 bprm->filename = filename;
44249 bprm->interp = filename;
44250
44251 + if (gr_process_user_ban()) {
44252 + retval = -EPERM;
44253 + goto out_file;
44254 + }
44255 +
44256 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44257 + retval = -EACCES;
44258 + goto out_file;
44259 + }
44260 +
44261 retval = bprm_mm_init(bprm);
44262 if (retval)
44263 goto out_file;
44264 @@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
44265 if (retval < 0)
44266 goto out;
44267
44268 +#ifdef CONFIG_GRKERNSEC
44269 + old_acl = current->acl;
44270 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44271 + old_exec_file = current->exec_file;
44272 + get_file(file);
44273 + current->exec_file = file;
44274 +#endif
44275 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44276 + /* limit suid stack to 8MB
44277 + we saved the old limits above and will restore them if this exec fails
44278 + */
44279 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44280 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44281 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44282 +#endif
44283 +
44284 + if (!gr_tpe_allow(file)) {
44285 + retval = -EACCES;
44286 + goto out_fail;
44287 + }
44288 +
44289 + if (gr_check_crash_exec(file)) {
44290 + retval = -EACCES;
44291 + goto out_fail;
44292 + }
44293 +
44294 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44295 + bprm->unsafe);
44296 + if (retval < 0)
44297 + goto out_fail;
44298 +
44299 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44300 if (retval < 0)
44301 - goto out;
44302 + goto out_fail;
44303
44304 bprm->exec = bprm->p;
44305 retval = copy_strings(bprm->envc, envp, bprm);
44306 if (retval < 0)
44307 - goto out;
44308 + goto out_fail;
44309
44310 retval = copy_strings(bprm->argc, argv, bprm);
44311 if (retval < 0)
44312 - goto out;
44313 + goto out_fail;
44314 +
44315 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44316 +
44317 + gr_handle_exec_args(bprm, argv);
44318
44319 retval = search_binary_handler(bprm,regs);
44320 if (retval < 0)
44321 - goto out;
44322 + goto out_fail;
44323 +#ifdef CONFIG_GRKERNSEC
44324 + if (old_exec_file)
44325 + fput(old_exec_file);
44326 +#endif
44327
44328 /* execve succeeded */
44329 +
44330 + increment_exec_counter();
44331 current->fs->in_exec = 0;
44332 current->in_execve = 0;
44333 acct_update_integrals(current);
44334 @@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
44335 put_files_struct(displaced);
44336 return retval;
44337
44338 +out_fail:
44339 +#ifdef CONFIG_GRKERNSEC
44340 + current->acl = old_acl;
44341 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44342 + fput(current->exec_file);
44343 + current->exec_file = old_exec_file;
44344 +#endif
44345 +
44346 out:
44347 if (bprm->mm) {
44348 acct_arg_size(bprm, 0);
44349 @@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
44350 {
44351 char *old_corename = cn->corename;
44352
44353 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44354 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44355 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44356
44357 if (!cn->corename) {
44358 @@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
44359 int pid_in_pattern = 0;
44360 int err = 0;
44361
44362 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44363 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44364 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44365 cn->used = 0;
44366
44367 @@ -1817,6 +1942,228 @@ out:
44368 return ispipe;
44369 }
44370
44371 +int pax_check_flags(unsigned long *flags)
44372 +{
44373 + int retval = 0;
44374 +
44375 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44376 + if (*flags & MF_PAX_SEGMEXEC)
44377 + {
44378 + *flags &= ~MF_PAX_SEGMEXEC;
44379 + retval = -EINVAL;
44380 + }
44381 +#endif
44382 +
44383 + if ((*flags & MF_PAX_PAGEEXEC)
44384 +
44385 +#ifdef CONFIG_PAX_PAGEEXEC
44386 + && (*flags & MF_PAX_SEGMEXEC)
44387 +#endif
44388 +
44389 + )
44390 + {
44391 + *flags &= ~MF_PAX_PAGEEXEC;
44392 + retval = -EINVAL;
44393 + }
44394 +
44395 + if ((*flags & MF_PAX_MPROTECT)
44396 +
44397 +#ifdef CONFIG_PAX_MPROTECT
44398 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44399 +#endif
44400 +
44401 + )
44402 + {
44403 + *flags &= ~MF_PAX_MPROTECT;
44404 + retval = -EINVAL;
44405 + }
44406 +
44407 + if ((*flags & MF_PAX_EMUTRAMP)
44408 +
44409 +#ifdef CONFIG_PAX_EMUTRAMP
44410 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44411 +#endif
44412 +
44413 + )
44414 + {
44415 + *flags &= ~MF_PAX_EMUTRAMP;
44416 + retval = -EINVAL;
44417 + }
44418 +
44419 + return retval;
44420 +}
44421 +
44422 +EXPORT_SYMBOL(pax_check_flags);
44423 +
44424 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44425 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44426 +{
44427 + struct task_struct *tsk = current;
44428 + struct mm_struct *mm = current->mm;
44429 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44430 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44431 + char *path_exec = NULL;
44432 + char *path_fault = NULL;
44433 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44434 +
44435 + if (buffer_exec && buffer_fault) {
44436 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44437 +
44438 + down_read(&mm->mmap_sem);
44439 + vma = mm->mmap;
44440 + while (vma && (!vma_exec || !vma_fault)) {
44441 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44442 + vma_exec = vma;
44443 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44444 + vma_fault = vma;
44445 + vma = vma->vm_next;
44446 + }
44447 + if (vma_exec) {
44448 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44449 + if (IS_ERR(path_exec))
44450 + path_exec = "<path too long>";
44451 + else {
44452 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44453 + if (path_exec) {
44454 + *path_exec = 0;
44455 + path_exec = buffer_exec;
44456 + } else
44457 + path_exec = "<path too long>";
44458 + }
44459 + }
44460 + if (vma_fault) {
44461 + start = vma_fault->vm_start;
44462 + end = vma_fault->vm_end;
44463 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44464 + if (vma_fault->vm_file) {
44465 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44466 + if (IS_ERR(path_fault))
44467 + path_fault = "<path too long>";
44468 + else {
44469 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44470 + if (path_fault) {
44471 + *path_fault = 0;
44472 + path_fault = buffer_fault;
44473 + } else
44474 + path_fault = "<path too long>";
44475 + }
44476 + } else
44477 + path_fault = "<anonymous mapping>";
44478 + }
44479 + up_read(&mm->mmap_sem);
44480 + }
44481 + if (tsk->signal->curr_ip)
44482 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44483 + else
44484 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44485 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44486 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44487 + task_uid(tsk), task_euid(tsk), pc, sp);
44488 + free_page((unsigned long)buffer_exec);
44489 + free_page((unsigned long)buffer_fault);
44490 + pax_report_insns(regs, pc, sp);
44491 + do_coredump(SIGKILL, SIGKILL, regs);
44492 +}
44493 +#endif
44494 +
44495 +#ifdef CONFIG_PAX_REFCOUNT
44496 +void pax_report_refcount_overflow(struct pt_regs *regs)
44497 +{
44498 + if (current->signal->curr_ip)
44499 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44500 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44501 + else
44502 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44503 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44504 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44505 + show_regs(regs);
44506 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44507 +}
44508 +#endif
44509 +
44510 +#ifdef CONFIG_PAX_USERCOPY
44511 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44512 +int object_is_on_stack(const void *obj, unsigned long len)
44513 +{
44514 + const void * const stack = task_stack_page(current);
44515 + const void * const stackend = stack + THREAD_SIZE;
44516 +
44517 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44518 + const void *frame = NULL;
44519 + const void *oldframe;
44520 +#endif
44521 +
44522 + if (obj + len < obj)
44523 + return -1;
44524 +
44525 + if (obj + len <= stack || stackend <= obj)
44526 + return 0;
44527 +
44528 + if (obj < stack || stackend < obj + len)
44529 + return -1;
44530 +
44531 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44532 + oldframe = __builtin_frame_address(1);
44533 + if (oldframe)
44534 + frame = __builtin_frame_address(2);
44535 + /*
44536 + low ----------------------------------------------> high
44537 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44538 + ^----------------^
44539 + allow copies only within here
44540 + */
44541 + while (stack <= frame && frame < stackend) {
44542 + /* if obj + len extends past the last frame, this
44543 + check won't pass and the next frame will be 0,
44544 + causing us to bail out and correctly report
44545 + the copy as invalid
44546 + */
44547 + if (obj + len <= frame)
44548 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44549 + oldframe = frame;
44550 + frame = *(const void * const *)frame;
44551 + }
44552 + return -1;
44553 +#else
44554 + return 1;
44555 +#endif
44556 +}
44557 +
44558 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44559 +{
44560 + if (current->signal->curr_ip)
44561 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44562 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44563 + else
44564 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44565 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44566 + dump_stack();
44567 + gr_handle_kernel_exploit();
44568 + do_group_exit(SIGKILL);
44569 +}
44570 +#endif
44571 +
44572 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44573 +void pax_track_stack(void)
44574 +{
44575 + unsigned long sp = (unsigned long)&sp;
44576 + if (sp < current_thread_info()->lowest_stack &&
44577 + sp > (unsigned long)task_stack_page(current))
44578 + current_thread_info()->lowest_stack = sp;
44579 +}
44580 +EXPORT_SYMBOL(pax_track_stack);
44581 +#endif
44582 +
44583 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44584 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44585 +{
44586 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44587 + dump_stack();
44588 + do_group_exit(SIGKILL);
44589 +}
44590 +EXPORT_SYMBOL(report_size_overflow);
44591 +#endif
44592 +
44593 static int zap_process(struct task_struct *start, int exit_code)
44594 {
44595 struct task_struct *t;
44596 @@ -2014,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
44597 pipe = file->f_path.dentry->d_inode->i_pipe;
44598
44599 pipe_lock(pipe);
44600 - pipe->readers++;
44601 - pipe->writers--;
44602 + atomic_inc(&pipe->readers);
44603 + atomic_dec(&pipe->writers);
44604
44605 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44606 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44607 wake_up_interruptible_sync(&pipe->wait);
44608 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44609 pipe_wait(pipe);
44610 }
44611
44612 - pipe->readers--;
44613 - pipe->writers++;
44614 + atomic_dec(&pipe->readers);
44615 + atomic_inc(&pipe->writers);
44616 pipe_unlock(pipe);
44617
44618 }
44619 @@ -2085,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44620 int retval = 0;
44621 int flag = 0;
44622 int ispipe;
44623 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44624 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44625 struct coredump_params cprm = {
44626 .signr = signr,
44627 .regs = regs,
44628 @@ -2100,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44629
44630 audit_core_dumps(signr);
44631
44632 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44633 + gr_handle_brute_attach(current, cprm.mm_flags);
44634 +
44635 binfmt = mm->binfmt;
44636 if (!binfmt || !binfmt->core_dump)
44637 goto fail;
44638 @@ -2167,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44639 }
44640 cprm.limit = RLIM_INFINITY;
44641
44642 - dump_count = atomic_inc_return(&core_dump_count);
44643 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44644 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44645 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44646 task_tgid_vnr(current), current->comm);
44647 @@ -2194,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44648 } else {
44649 struct inode *inode;
44650
44651 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44652 +
44653 if (cprm.limit < binfmt->min_coredump)
44654 goto fail_unlock;
44655
44656 @@ -2237,7 +2589,7 @@ close_fail:
44657 filp_close(cprm.file, NULL);
44658 fail_dropcount:
44659 if (ispipe)
44660 - atomic_dec(&core_dump_count);
44661 + atomic_dec_unchecked(&core_dump_count);
44662 fail_unlock:
44663 kfree(cn.corename);
44664 fail_corename:
44665 @@ -2256,7 +2608,7 @@ fail:
44666 */
44667 int dump_write(struct file *file, const void *addr, int nr)
44668 {
44669 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44670 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44671 }
44672 EXPORT_SYMBOL(dump_write);
44673
44674 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44675 index a8cbe1b..fed04cb 100644
44676 --- a/fs/ext2/balloc.c
44677 +++ b/fs/ext2/balloc.c
44678 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44679
44680 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44681 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44682 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44683 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44684 sbi->s_resuid != current_fsuid() &&
44685 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44686 return 0;
44687 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44688 index a203892..4e64db5 100644
44689 --- a/fs/ext3/balloc.c
44690 +++ b/fs/ext3/balloc.c
44691 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44692
44693 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44694 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44695 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44696 + if (free_blocks < root_blocks + 1 &&
44697 !use_reservation && sbi->s_resuid != current_fsuid() &&
44698 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44699 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44700 + !capable_nolog(CAP_SYS_RESOURCE)) {
44701 return 0;
44702 }
44703 return 1;
44704 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44705 index f9e2cd8..bfdc476 100644
44706 --- a/fs/ext4/balloc.c
44707 +++ b/fs/ext4/balloc.c
44708 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44709 /* Hm, nope. Are (enough) root reserved clusters available? */
44710 if (sbi->s_resuid == current_fsuid() ||
44711 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44712 - capable(CAP_SYS_RESOURCE) ||
44713 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44714 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44715 + capable_nolog(CAP_SYS_RESOURCE)) {
44716
44717 if (free_clusters >= (nclusters + dirty_clusters))
44718 return 1;
44719 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44720 index 3ce6a0c..0311fe5 100644
44721 --- a/fs/ext4/ext4.h
44722 +++ b/fs/ext4/ext4.h
44723 @@ -1220,19 +1220,19 @@ struct ext4_sb_info {
44724 unsigned long s_mb_last_start;
44725
44726 /* stats for buddy allocator */
44727 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44728 - atomic_t s_bal_success; /* we found long enough chunks */
44729 - atomic_t s_bal_allocated; /* in blocks */
44730 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44731 - atomic_t s_bal_goals; /* goal hits */
44732 - atomic_t s_bal_breaks; /* too long searches */
44733 - atomic_t s_bal_2orders; /* 2^order hits */
44734 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44735 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44736 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44737 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44738 + atomic_unchecked_t s_bal_goals; /* goal hits */
44739 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44740 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44741 spinlock_t s_bal_lock;
44742 unsigned long s_mb_buddies_generated;
44743 unsigned long long s_mb_generation_time;
44744 - atomic_t s_mb_lost_chunks;
44745 - atomic_t s_mb_preallocated;
44746 - atomic_t s_mb_discarded;
44747 + atomic_unchecked_t s_mb_lost_chunks;
44748 + atomic_unchecked_t s_mb_preallocated;
44749 + atomic_unchecked_t s_mb_discarded;
44750 atomic_t s_lock_busy;
44751
44752 /* locality groups */
44753 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44754 index cb990b2..4820141 100644
44755 --- a/fs/ext4/mballoc.c
44756 +++ b/fs/ext4/mballoc.c
44757 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44758 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44759
44760 if (EXT4_SB(sb)->s_mb_stats)
44761 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44762 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44763
44764 break;
44765 }
44766 @@ -2088,7 +2088,7 @@ repeat:
44767 ac->ac_status = AC_STATUS_CONTINUE;
44768 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44769 cr = 3;
44770 - atomic_inc(&sbi->s_mb_lost_chunks);
44771 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44772 goto repeat;
44773 }
44774 }
44775 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44776 if (sbi->s_mb_stats) {
44777 ext4_msg(sb, KERN_INFO,
44778 "mballoc: %u blocks %u reqs (%u success)",
44779 - atomic_read(&sbi->s_bal_allocated),
44780 - atomic_read(&sbi->s_bal_reqs),
44781 - atomic_read(&sbi->s_bal_success));
44782 + atomic_read_unchecked(&sbi->s_bal_allocated),
44783 + atomic_read_unchecked(&sbi->s_bal_reqs),
44784 + atomic_read_unchecked(&sbi->s_bal_success));
44785 ext4_msg(sb, KERN_INFO,
44786 "mballoc: %u extents scanned, %u goal hits, "
44787 "%u 2^N hits, %u breaks, %u lost",
44788 - atomic_read(&sbi->s_bal_ex_scanned),
44789 - atomic_read(&sbi->s_bal_goals),
44790 - atomic_read(&sbi->s_bal_2orders),
44791 - atomic_read(&sbi->s_bal_breaks),
44792 - atomic_read(&sbi->s_mb_lost_chunks));
44793 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44794 + atomic_read_unchecked(&sbi->s_bal_goals),
44795 + atomic_read_unchecked(&sbi->s_bal_2orders),
44796 + atomic_read_unchecked(&sbi->s_bal_breaks),
44797 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44798 ext4_msg(sb, KERN_INFO,
44799 "mballoc: %lu generated and it took %Lu",
44800 sbi->s_mb_buddies_generated,
44801 sbi->s_mb_generation_time);
44802 ext4_msg(sb, KERN_INFO,
44803 "mballoc: %u preallocated, %u discarded",
44804 - atomic_read(&sbi->s_mb_preallocated),
44805 - atomic_read(&sbi->s_mb_discarded));
44806 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44807 + atomic_read_unchecked(&sbi->s_mb_discarded));
44808 }
44809
44810 free_percpu(sbi->s_locality_groups);
44811 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44812 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44813
44814 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44815 - atomic_inc(&sbi->s_bal_reqs);
44816 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44817 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44818 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44819 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44820 - atomic_inc(&sbi->s_bal_success);
44821 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44822 + atomic_inc_unchecked(&sbi->s_bal_success);
44823 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44824 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44825 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44826 - atomic_inc(&sbi->s_bal_goals);
44827 + atomic_inc_unchecked(&sbi->s_bal_goals);
44828 if (ac->ac_found > sbi->s_mb_max_to_scan)
44829 - atomic_inc(&sbi->s_bal_breaks);
44830 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44831 }
44832
44833 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44834 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44835 trace_ext4_mb_new_inode_pa(ac, pa);
44836
44837 ext4_mb_use_inode_pa(ac, pa);
44838 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44839 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44840
44841 ei = EXT4_I(ac->ac_inode);
44842 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44843 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44844 trace_ext4_mb_new_group_pa(ac, pa);
44845
44846 ext4_mb_use_group_pa(ac, pa);
44847 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44848 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44849
44850 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44851 lg = ac->ac_lg;
44852 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44853 * from the bitmap and continue.
44854 */
44855 }
44856 - atomic_add(free, &sbi->s_mb_discarded);
44857 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44858
44859 return err;
44860 }
44861 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44862 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44863 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44864 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44865 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44866 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44867 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44868
44869 return 0;
44870 diff --git a/fs/fcntl.c b/fs/fcntl.c
44871 index 22764c7..86372c9 100644
44872 --- a/fs/fcntl.c
44873 +++ b/fs/fcntl.c
44874 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44875 if (err)
44876 return err;
44877
44878 + if (gr_handle_chroot_fowner(pid, type))
44879 + return -ENOENT;
44880 + if (gr_check_protected_task_fowner(pid, type))
44881 + return -EACCES;
44882 +
44883 f_modown(filp, pid, type, force);
44884 return 0;
44885 }
44886 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44887
44888 static int f_setown_ex(struct file *filp, unsigned long arg)
44889 {
44890 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44891 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44892 struct f_owner_ex owner;
44893 struct pid *pid;
44894 int type;
44895 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44896
44897 static int f_getown_ex(struct file *filp, unsigned long arg)
44898 {
44899 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44900 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44901 struct f_owner_ex owner;
44902 int ret = 0;
44903
44904 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44905 switch (cmd) {
44906 case F_DUPFD:
44907 case F_DUPFD_CLOEXEC:
44908 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44909 if (arg >= rlimit(RLIMIT_NOFILE))
44910 break;
44911 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44912 diff --git a/fs/fifo.c b/fs/fifo.c
44913 index b1a524d..4ee270e 100644
44914 --- a/fs/fifo.c
44915 +++ b/fs/fifo.c
44916 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44917 */
44918 filp->f_op = &read_pipefifo_fops;
44919 pipe->r_counter++;
44920 - if (pipe->readers++ == 0)
44921 + if (atomic_inc_return(&pipe->readers) == 1)
44922 wake_up_partner(inode);
44923
44924 - if (!pipe->writers) {
44925 + if (!atomic_read(&pipe->writers)) {
44926 if ((filp->f_flags & O_NONBLOCK)) {
44927 /* suppress POLLHUP until we have
44928 * seen a writer */
44929 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44930 * errno=ENXIO when there is no process reading the FIFO.
44931 */
44932 ret = -ENXIO;
44933 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44934 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44935 goto err;
44936
44937 filp->f_op = &write_pipefifo_fops;
44938 pipe->w_counter++;
44939 - if (!pipe->writers++)
44940 + if (atomic_inc_return(&pipe->writers) == 1)
44941 wake_up_partner(inode);
44942
44943 - if (!pipe->readers) {
44944 + if (!atomic_read(&pipe->readers)) {
44945 wait_for_partner(inode, &pipe->r_counter);
44946 if (signal_pending(current))
44947 goto err_wr;
44948 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44949 */
44950 filp->f_op = &rdwr_pipefifo_fops;
44951
44952 - pipe->readers++;
44953 - pipe->writers++;
44954 + atomic_inc(&pipe->readers);
44955 + atomic_inc(&pipe->writers);
44956 pipe->r_counter++;
44957 pipe->w_counter++;
44958 - if (pipe->readers == 1 || pipe->writers == 1)
44959 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44960 wake_up_partner(inode);
44961 break;
44962
44963 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44964 return 0;
44965
44966 err_rd:
44967 - if (!--pipe->readers)
44968 + if (atomic_dec_and_test(&pipe->readers))
44969 wake_up_interruptible(&pipe->wait);
44970 ret = -ERESTARTSYS;
44971 goto err;
44972
44973 err_wr:
44974 - if (!--pipe->writers)
44975 + if (atomic_dec_and_test(&pipe->writers))
44976 wake_up_interruptible(&pipe->wait);
44977 ret = -ERESTARTSYS;
44978 goto err;
44979
44980 err:
44981 - if (!pipe->readers && !pipe->writers)
44982 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44983 free_pipe_info(inode);
44984
44985 err_nocleanup:
44986 diff --git a/fs/file.c b/fs/file.c
44987 index 4c6992d..104cdea 100644
44988 --- a/fs/file.c
44989 +++ b/fs/file.c
44990 @@ -15,6 +15,7 @@
44991 #include <linux/slab.h>
44992 #include <linux/vmalloc.h>
44993 #include <linux/file.h>
44994 +#include <linux/security.h>
44995 #include <linux/fdtable.h>
44996 #include <linux/bitops.h>
44997 #include <linux/interrupt.h>
44998 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44999 * N.B. For clone tasks sharing a files structure, this test
45000 * will limit the total number of files that can be opened.
45001 */
45002 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45003 if (nr >= rlimit(RLIMIT_NOFILE))
45004 return -EMFILE;
45005
45006 diff --git a/fs/filesystems.c b/fs/filesystems.c
45007 index 96f2428..f5eeb8e 100644
45008 --- a/fs/filesystems.c
45009 +++ b/fs/filesystems.c
45010 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45011 int len = dot ? dot - name : strlen(name);
45012
45013 fs = __get_fs_type(name, len);
45014 +
45015 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45016 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45017 +#else
45018 if (!fs && (request_module("%.*s", len, name) == 0))
45019 +#endif
45020 fs = __get_fs_type(name, len);
45021
45022 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45023 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45024 index 78b519c..a8b4979 100644
45025 --- a/fs/fs_struct.c
45026 +++ b/fs/fs_struct.c
45027 @@ -4,6 +4,7 @@
45028 #include <linux/path.h>
45029 #include <linux/slab.h>
45030 #include <linux/fs_struct.h>
45031 +#include <linux/grsecurity.h>
45032 #include "internal.h"
45033
45034 static inline void path_get_longterm(struct path *path)
45035 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45036 old_root = fs->root;
45037 fs->root = *path;
45038 path_get_longterm(path);
45039 + gr_set_chroot_entries(current, path);
45040 write_seqcount_end(&fs->seq);
45041 spin_unlock(&fs->lock);
45042 if (old_root.dentry)
45043 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45044 && fs->root.mnt == old_root->mnt) {
45045 path_get_longterm(new_root);
45046 fs->root = *new_root;
45047 + gr_set_chroot_entries(p, new_root);
45048 count++;
45049 }
45050 if (fs->pwd.dentry == old_root->dentry
45051 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45052 spin_lock(&fs->lock);
45053 write_seqcount_begin(&fs->seq);
45054 tsk->fs = NULL;
45055 - kill = !--fs->users;
45056 + gr_clear_chroot_entries(tsk);
45057 + kill = !atomic_dec_return(&fs->users);
45058 write_seqcount_end(&fs->seq);
45059 spin_unlock(&fs->lock);
45060 task_unlock(tsk);
45061 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45062 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45063 /* We don't need to lock fs - think why ;-) */
45064 if (fs) {
45065 - fs->users = 1;
45066 + atomic_set(&fs->users, 1);
45067 fs->in_exec = 0;
45068 spin_lock_init(&fs->lock);
45069 seqcount_init(&fs->seq);
45070 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45071 spin_lock(&old->lock);
45072 fs->root = old->root;
45073 path_get_longterm(&fs->root);
45074 + /* instead of calling gr_set_chroot_entries here,
45075 + we call it from every caller of this function
45076 + */
45077 fs->pwd = old->pwd;
45078 path_get_longterm(&fs->pwd);
45079 spin_unlock(&old->lock);
45080 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45081
45082 task_lock(current);
45083 spin_lock(&fs->lock);
45084 - kill = !--fs->users;
45085 + kill = !atomic_dec_return(&fs->users);
45086 current->fs = new_fs;
45087 + gr_set_chroot_entries(current, &new_fs->root);
45088 spin_unlock(&fs->lock);
45089 task_unlock(current);
45090
45091 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45092
45093 int current_umask(void)
45094 {
45095 - return current->fs->umask;
45096 + return current->fs->umask | gr_acl_umask();
45097 }
45098 EXPORT_SYMBOL(current_umask);
45099
45100 /* to be mentioned only in INIT_TASK */
45101 struct fs_struct init_fs = {
45102 - .users = 1,
45103 + .users = ATOMIC_INIT(1),
45104 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45105 .seq = SEQCNT_ZERO,
45106 .umask = 0022,
45107 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45108 task_lock(current);
45109
45110 spin_lock(&init_fs.lock);
45111 - init_fs.users++;
45112 + atomic_inc(&init_fs.users);
45113 spin_unlock(&init_fs.lock);
45114
45115 spin_lock(&fs->lock);
45116 current->fs = &init_fs;
45117 - kill = !--fs->users;
45118 + gr_set_chroot_entries(current, &current->fs->root);
45119 + kill = !atomic_dec_return(&fs->users);
45120 spin_unlock(&fs->lock);
45121
45122 task_unlock(current);
45123 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45124 index 9905350..02eaec4 100644
45125 --- a/fs/fscache/cookie.c
45126 +++ b/fs/fscache/cookie.c
45127 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45128 parent ? (char *) parent->def->name : "<no-parent>",
45129 def->name, netfs_data);
45130
45131 - fscache_stat(&fscache_n_acquires);
45132 + fscache_stat_unchecked(&fscache_n_acquires);
45133
45134 /* if there's no parent cookie, then we don't create one here either */
45135 if (!parent) {
45136 - fscache_stat(&fscache_n_acquires_null);
45137 + fscache_stat_unchecked(&fscache_n_acquires_null);
45138 _leave(" [no parent]");
45139 return NULL;
45140 }
45141 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45142 /* allocate and initialise a cookie */
45143 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45144 if (!cookie) {
45145 - fscache_stat(&fscache_n_acquires_oom);
45146 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45147 _leave(" [ENOMEM]");
45148 return NULL;
45149 }
45150 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45151
45152 switch (cookie->def->type) {
45153 case FSCACHE_COOKIE_TYPE_INDEX:
45154 - fscache_stat(&fscache_n_cookie_index);
45155 + fscache_stat_unchecked(&fscache_n_cookie_index);
45156 break;
45157 case FSCACHE_COOKIE_TYPE_DATAFILE:
45158 - fscache_stat(&fscache_n_cookie_data);
45159 + fscache_stat_unchecked(&fscache_n_cookie_data);
45160 break;
45161 default:
45162 - fscache_stat(&fscache_n_cookie_special);
45163 + fscache_stat_unchecked(&fscache_n_cookie_special);
45164 break;
45165 }
45166
45167 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45168 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45169 atomic_dec(&parent->n_children);
45170 __fscache_cookie_put(cookie);
45171 - fscache_stat(&fscache_n_acquires_nobufs);
45172 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45173 _leave(" = NULL");
45174 return NULL;
45175 }
45176 }
45177
45178 - fscache_stat(&fscache_n_acquires_ok);
45179 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45180 _leave(" = %p", cookie);
45181 return cookie;
45182 }
45183 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45184 cache = fscache_select_cache_for_object(cookie->parent);
45185 if (!cache) {
45186 up_read(&fscache_addremove_sem);
45187 - fscache_stat(&fscache_n_acquires_no_cache);
45188 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45189 _leave(" = -ENOMEDIUM [no cache]");
45190 return -ENOMEDIUM;
45191 }
45192 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45193 object = cache->ops->alloc_object(cache, cookie);
45194 fscache_stat_d(&fscache_n_cop_alloc_object);
45195 if (IS_ERR(object)) {
45196 - fscache_stat(&fscache_n_object_no_alloc);
45197 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45198 ret = PTR_ERR(object);
45199 goto error;
45200 }
45201
45202 - fscache_stat(&fscache_n_object_alloc);
45203 + fscache_stat_unchecked(&fscache_n_object_alloc);
45204
45205 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45206
45207 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45208 struct fscache_object *object;
45209 struct hlist_node *_p;
45210
45211 - fscache_stat(&fscache_n_updates);
45212 + fscache_stat_unchecked(&fscache_n_updates);
45213
45214 if (!cookie) {
45215 - fscache_stat(&fscache_n_updates_null);
45216 + fscache_stat_unchecked(&fscache_n_updates_null);
45217 _leave(" [no cookie]");
45218 return;
45219 }
45220 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45221 struct fscache_object *object;
45222 unsigned long event;
45223
45224 - fscache_stat(&fscache_n_relinquishes);
45225 + fscache_stat_unchecked(&fscache_n_relinquishes);
45226 if (retire)
45227 - fscache_stat(&fscache_n_relinquishes_retire);
45228 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45229
45230 if (!cookie) {
45231 - fscache_stat(&fscache_n_relinquishes_null);
45232 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45233 _leave(" [no cookie]");
45234 return;
45235 }
45236 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45237
45238 /* wait for the cookie to finish being instantiated (or to fail) */
45239 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45240 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45241 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45242 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45243 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45244 }
45245 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45246 index f6aad48..88dcf26 100644
45247 --- a/fs/fscache/internal.h
45248 +++ b/fs/fscache/internal.h
45249 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45250 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45251 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45252
45253 -extern atomic_t fscache_n_op_pend;
45254 -extern atomic_t fscache_n_op_run;
45255 -extern atomic_t fscache_n_op_enqueue;
45256 -extern atomic_t fscache_n_op_deferred_release;
45257 -extern atomic_t fscache_n_op_release;
45258 -extern atomic_t fscache_n_op_gc;
45259 -extern atomic_t fscache_n_op_cancelled;
45260 -extern atomic_t fscache_n_op_rejected;
45261 +extern atomic_unchecked_t fscache_n_op_pend;
45262 +extern atomic_unchecked_t fscache_n_op_run;
45263 +extern atomic_unchecked_t fscache_n_op_enqueue;
45264 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45265 +extern atomic_unchecked_t fscache_n_op_release;
45266 +extern atomic_unchecked_t fscache_n_op_gc;
45267 +extern atomic_unchecked_t fscache_n_op_cancelled;
45268 +extern atomic_unchecked_t fscache_n_op_rejected;
45269
45270 -extern atomic_t fscache_n_attr_changed;
45271 -extern atomic_t fscache_n_attr_changed_ok;
45272 -extern atomic_t fscache_n_attr_changed_nobufs;
45273 -extern atomic_t fscache_n_attr_changed_nomem;
45274 -extern atomic_t fscache_n_attr_changed_calls;
45275 +extern atomic_unchecked_t fscache_n_attr_changed;
45276 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45277 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45278 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45279 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45280
45281 -extern atomic_t fscache_n_allocs;
45282 -extern atomic_t fscache_n_allocs_ok;
45283 -extern atomic_t fscache_n_allocs_wait;
45284 -extern atomic_t fscache_n_allocs_nobufs;
45285 -extern atomic_t fscache_n_allocs_intr;
45286 -extern atomic_t fscache_n_allocs_object_dead;
45287 -extern atomic_t fscache_n_alloc_ops;
45288 -extern atomic_t fscache_n_alloc_op_waits;
45289 +extern atomic_unchecked_t fscache_n_allocs;
45290 +extern atomic_unchecked_t fscache_n_allocs_ok;
45291 +extern atomic_unchecked_t fscache_n_allocs_wait;
45292 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45293 +extern atomic_unchecked_t fscache_n_allocs_intr;
45294 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45295 +extern atomic_unchecked_t fscache_n_alloc_ops;
45296 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45297
45298 -extern atomic_t fscache_n_retrievals;
45299 -extern atomic_t fscache_n_retrievals_ok;
45300 -extern atomic_t fscache_n_retrievals_wait;
45301 -extern atomic_t fscache_n_retrievals_nodata;
45302 -extern atomic_t fscache_n_retrievals_nobufs;
45303 -extern atomic_t fscache_n_retrievals_intr;
45304 -extern atomic_t fscache_n_retrievals_nomem;
45305 -extern atomic_t fscache_n_retrievals_object_dead;
45306 -extern atomic_t fscache_n_retrieval_ops;
45307 -extern atomic_t fscache_n_retrieval_op_waits;
45308 +extern atomic_unchecked_t fscache_n_retrievals;
45309 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45310 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45311 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45312 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45313 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45314 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45315 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45316 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45317 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45318
45319 -extern atomic_t fscache_n_stores;
45320 -extern atomic_t fscache_n_stores_ok;
45321 -extern atomic_t fscache_n_stores_again;
45322 -extern atomic_t fscache_n_stores_nobufs;
45323 -extern atomic_t fscache_n_stores_oom;
45324 -extern atomic_t fscache_n_store_ops;
45325 -extern atomic_t fscache_n_store_calls;
45326 -extern atomic_t fscache_n_store_pages;
45327 -extern atomic_t fscache_n_store_radix_deletes;
45328 -extern atomic_t fscache_n_store_pages_over_limit;
45329 +extern atomic_unchecked_t fscache_n_stores;
45330 +extern atomic_unchecked_t fscache_n_stores_ok;
45331 +extern atomic_unchecked_t fscache_n_stores_again;
45332 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45333 +extern atomic_unchecked_t fscache_n_stores_oom;
45334 +extern atomic_unchecked_t fscache_n_store_ops;
45335 +extern atomic_unchecked_t fscache_n_store_calls;
45336 +extern atomic_unchecked_t fscache_n_store_pages;
45337 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45338 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45339
45340 -extern atomic_t fscache_n_store_vmscan_not_storing;
45341 -extern atomic_t fscache_n_store_vmscan_gone;
45342 -extern atomic_t fscache_n_store_vmscan_busy;
45343 -extern atomic_t fscache_n_store_vmscan_cancelled;
45344 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45345 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45346 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45347 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45348
45349 -extern atomic_t fscache_n_marks;
45350 -extern atomic_t fscache_n_uncaches;
45351 +extern atomic_unchecked_t fscache_n_marks;
45352 +extern atomic_unchecked_t fscache_n_uncaches;
45353
45354 -extern atomic_t fscache_n_acquires;
45355 -extern atomic_t fscache_n_acquires_null;
45356 -extern atomic_t fscache_n_acquires_no_cache;
45357 -extern atomic_t fscache_n_acquires_ok;
45358 -extern atomic_t fscache_n_acquires_nobufs;
45359 -extern atomic_t fscache_n_acquires_oom;
45360 +extern atomic_unchecked_t fscache_n_acquires;
45361 +extern atomic_unchecked_t fscache_n_acquires_null;
45362 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45363 +extern atomic_unchecked_t fscache_n_acquires_ok;
45364 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45365 +extern atomic_unchecked_t fscache_n_acquires_oom;
45366
45367 -extern atomic_t fscache_n_updates;
45368 -extern atomic_t fscache_n_updates_null;
45369 -extern atomic_t fscache_n_updates_run;
45370 +extern atomic_unchecked_t fscache_n_updates;
45371 +extern atomic_unchecked_t fscache_n_updates_null;
45372 +extern atomic_unchecked_t fscache_n_updates_run;
45373
45374 -extern atomic_t fscache_n_relinquishes;
45375 -extern atomic_t fscache_n_relinquishes_null;
45376 -extern atomic_t fscache_n_relinquishes_waitcrt;
45377 -extern atomic_t fscache_n_relinquishes_retire;
45378 +extern atomic_unchecked_t fscache_n_relinquishes;
45379 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45380 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45381 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45382
45383 -extern atomic_t fscache_n_cookie_index;
45384 -extern atomic_t fscache_n_cookie_data;
45385 -extern atomic_t fscache_n_cookie_special;
45386 +extern atomic_unchecked_t fscache_n_cookie_index;
45387 +extern atomic_unchecked_t fscache_n_cookie_data;
45388 +extern atomic_unchecked_t fscache_n_cookie_special;
45389
45390 -extern atomic_t fscache_n_object_alloc;
45391 -extern atomic_t fscache_n_object_no_alloc;
45392 -extern atomic_t fscache_n_object_lookups;
45393 -extern atomic_t fscache_n_object_lookups_negative;
45394 -extern atomic_t fscache_n_object_lookups_positive;
45395 -extern atomic_t fscache_n_object_lookups_timed_out;
45396 -extern atomic_t fscache_n_object_created;
45397 -extern atomic_t fscache_n_object_avail;
45398 -extern atomic_t fscache_n_object_dead;
45399 +extern atomic_unchecked_t fscache_n_object_alloc;
45400 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45401 +extern atomic_unchecked_t fscache_n_object_lookups;
45402 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45403 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45404 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45405 +extern atomic_unchecked_t fscache_n_object_created;
45406 +extern atomic_unchecked_t fscache_n_object_avail;
45407 +extern atomic_unchecked_t fscache_n_object_dead;
45408
45409 -extern atomic_t fscache_n_checkaux_none;
45410 -extern atomic_t fscache_n_checkaux_okay;
45411 -extern atomic_t fscache_n_checkaux_update;
45412 -extern atomic_t fscache_n_checkaux_obsolete;
45413 +extern atomic_unchecked_t fscache_n_checkaux_none;
45414 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45415 +extern atomic_unchecked_t fscache_n_checkaux_update;
45416 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45417
45418 extern atomic_t fscache_n_cop_alloc_object;
45419 extern atomic_t fscache_n_cop_lookup_object;
45420 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45421 atomic_inc(stat);
45422 }
45423
45424 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45425 +{
45426 + atomic_inc_unchecked(stat);
45427 +}
45428 +
45429 static inline void fscache_stat_d(atomic_t *stat)
45430 {
45431 atomic_dec(stat);
45432 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45433
45434 #define __fscache_stat(stat) (NULL)
45435 #define fscache_stat(stat) do {} while (0)
45436 +#define fscache_stat_unchecked(stat) do {} while (0)
45437 #define fscache_stat_d(stat) do {} while (0)
45438 #endif
45439
45440 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45441 index b6b897c..0ffff9c 100644
45442 --- a/fs/fscache/object.c
45443 +++ b/fs/fscache/object.c
45444 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45445 /* update the object metadata on disk */
45446 case FSCACHE_OBJECT_UPDATING:
45447 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45448 - fscache_stat(&fscache_n_updates_run);
45449 + fscache_stat_unchecked(&fscache_n_updates_run);
45450 fscache_stat(&fscache_n_cop_update_object);
45451 object->cache->ops->update_object(object);
45452 fscache_stat_d(&fscache_n_cop_update_object);
45453 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45454 spin_lock(&object->lock);
45455 object->state = FSCACHE_OBJECT_DEAD;
45456 spin_unlock(&object->lock);
45457 - fscache_stat(&fscache_n_object_dead);
45458 + fscache_stat_unchecked(&fscache_n_object_dead);
45459 goto terminal_transit;
45460
45461 /* handle the parent cache of this object being withdrawn from
45462 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45463 spin_lock(&object->lock);
45464 object->state = FSCACHE_OBJECT_DEAD;
45465 spin_unlock(&object->lock);
45466 - fscache_stat(&fscache_n_object_dead);
45467 + fscache_stat_unchecked(&fscache_n_object_dead);
45468 goto terminal_transit;
45469
45470 /* complain about the object being woken up once it is
45471 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45472 parent->cookie->def->name, cookie->def->name,
45473 object->cache->tag->name);
45474
45475 - fscache_stat(&fscache_n_object_lookups);
45476 + fscache_stat_unchecked(&fscache_n_object_lookups);
45477 fscache_stat(&fscache_n_cop_lookup_object);
45478 ret = object->cache->ops->lookup_object(object);
45479 fscache_stat_d(&fscache_n_cop_lookup_object);
45480 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45481 if (ret == -ETIMEDOUT) {
45482 /* probably stuck behind another object, so move this one to
45483 * the back of the queue */
45484 - fscache_stat(&fscache_n_object_lookups_timed_out);
45485 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45486 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45487 }
45488
45489 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45490
45491 spin_lock(&object->lock);
45492 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45493 - fscache_stat(&fscache_n_object_lookups_negative);
45494 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45495
45496 /* transit here to allow write requests to begin stacking up
45497 * and read requests to begin returning ENODATA */
45498 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45499 * result, in which case there may be data available */
45500 spin_lock(&object->lock);
45501 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45502 - fscache_stat(&fscache_n_object_lookups_positive);
45503 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45504
45505 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45506
45507 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45508 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45509 } else {
45510 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45511 - fscache_stat(&fscache_n_object_created);
45512 + fscache_stat_unchecked(&fscache_n_object_created);
45513
45514 object->state = FSCACHE_OBJECT_AVAILABLE;
45515 spin_unlock(&object->lock);
45516 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45517 fscache_enqueue_dependents(object);
45518
45519 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45520 - fscache_stat(&fscache_n_object_avail);
45521 + fscache_stat_unchecked(&fscache_n_object_avail);
45522
45523 _leave("");
45524 }
45525 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45526 enum fscache_checkaux result;
45527
45528 if (!object->cookie->def->check_aux) {
45529 - fscache_stat(&fscache_n_checkaux_none);
45530 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45531 return FSCACHE_CHECKAUX_OKAY;
45532 }
45533
45534 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45535 switch (result) {
45536 /* entry okay as is */
45537 case FSCACHE_CHECKAUX_OKAY:
45538 - fscache_stat(&fscache_n_checkaux_okay);
45539 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45540 break;
45541
45542 /* entry requires update */
45543 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45544 - fscache_stat(&fscache_n_checkaux_update);
45545 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45546 break;
45547
45548 /* entry requires deletion */
45549 case FSCACHE_CHECKAUX_OBSOLETE:
45550 - fscache_stat(&fscache_n_checkaux_obsolete);
45551 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45552 break;
45553
45554 default:
45555 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45556 index 30afdfa..2256596 100644
45557 --- a/fs/fscache/operation.c
45558 +++ b/fs/fscache/operation.c
45559 @@ -17,7 +17,7 @@
45560 #include <linux/slab.h>
45561 #include "internal.h"
45562
45563 -atomic_t fscache_op_debug_id;
45564 +atomic_unchecked_t fscache_op_debug_id;
45565 EXPORT_SYMBOL(fscache_op_debug_id);
45566
45567 /**
45568 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45569 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45570 ASSERTCMP(atomic_read(&op->usage), >, 0);
45571
45572 - fscache_stat(&fscache_n_op_enqueue);
45573 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45574 switch (op->flags & FSCACHE_OP_TYPE) {
45575 case FSCACHE_OP_ASYNC:
45576 _debug("queue async");
45577 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45578 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45579 if (op->processor)
45580 fscache_enqueue_operation(op);
45581 - fscache_stat(&fscache_n_op_run);
45582 + fscache_stat_unchecked(&fscache_n_op_run);
45583 }
45584
45585 /*
45586 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45587 if (object->n_ops > 1) {
45588 atomic_inc(&op->usage);
45589 list_add_tail(&op->pend_link, &object->pending_ops);
45590 - fscache_stat(&fscache_n_op_pend);
45591 + fscache_stat_unchecked(&fscache_n_op_pend);
45592 } else if (!list_empty(&object->pending_ops)) {
45593 atomic_inc(&op->usage);
45594 list_add_tail(&op->pend_link, &object->pending_ops);
45595 - fscache_stat(&fscache_n_op_pend);
45596 + fscache_stat_unchecked(&fscache_n_op_pend);
45597 fscache_start_operations(object);
45598 } else {
45599 ASSERTCMP(object->n_in_progress, ==, 0);
45600 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45601 object->n_exclusive++; /* reads and writes must wait */
45602 atomic_inc(&op->usage);
45603 list_add_tail(&op->pend_link, &object->pending_ops);
45604 - fscache_stat(&fscache_n_op_pend);
45605 + fscache_stat_unchecked(&fscache_n_op_pend);
45606 ret = 0;
45607 } else {
45608 /* not allowed to submit ops in any other state */
45609 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45610 if (object->n_exclusive > 0) {
45611 atomic_inc(&op->usage);
45612 list_add_tail(&op->pend_link, &object->pending_ops);
45613 - fscache_stat(&fscache_n_op_pend);
45614 + fscache_stat_unchecked(&fscache_n_op_pend);
45615 } else if (!list_empty(&object->pending_ops)) {
45616 atomic_inc(&op->usage);
45617 list_add_tail(&op->pend_link, &object->pending_ops);
45618 - fscache_stat(&fscache_n_op_pend);
45619 + fscache_stat_unchecked(&fscache_n_op_pend);
45620 fscache_start_operations(object);
45621 } else {
45622 ASSERTCMP(object->n_exclusive, ==, 0);
45623 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45624 object->n_ops++;
45625 atomic_inc(&op->usage);
45626 list_add_tail(&op->pend_link, &object->pending_ops);
45627 - fscache_stat(&fscache_n_op_pend);
45628 + fscache_stat_unchecked(&fscache_n_op_pend);
45629 ret = 0;
45630 } else if (object->state == FSCACHE_OBJECT_DYING ||
45631 object->state == FSCACHE_OBJECT_LC_DYING ||
45632 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45633 - fscache_stat(&fscache_n_op_rejected);
45634 + fscache_stat_unchecked(&fscache_n_op_rejected);
45635 ret = -ENOBUFS;
45636 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45637 fscache_report_unexpected_submission(object, op, ostate);
45638 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45639
45640 ret = -EBUSY;
45641 if (!list_empty(&op->pend_link)) {
45642 - fscache_stat(&fscache_n_op_cancelled);
45643 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45644 list_del_init(&op->pend_link);
45645 object->n_ops--;
45646 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45647 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45648 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45649 BUG();
45650
45651 - fscache_stat(&fscache_n_op_release);
45652 + fscache_stat_unchecked(&fscache_n_op_release);
45653
45654 if (op->release) {
45655 op->release(op);
45656 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45657 * lock, and defer it otherwise */
45658 if (!spin_trylock(&object->lock)) {
45659 _debug("defer put");
45660 - fscache_stat(&fscache_n_op_deferred_release);
45661 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45662
45663 cache = object->cache;
45664 spin_lock(&cache->op_gc_list_lock);
45665 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45666
45667 _debug("GC DEFERRED REL OBJ%x OP%x",
45668 object->debug_id, op->debug_id);
45669 - fscache_stat(&fscache_n_op_gc);
45670 + fscache_stat_unchecked(&fscache_n_op_gc);
45671
45672 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45673
45674 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45675 index 3f7a59b..cf196cc 100644
45676 --- a/fs/fscache/page.c
45677 +++ b/fs/fscache/page.c
45678 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45679 val = radix_tree_lookup(&cookie->stores, page->index);
45680 if (!val) {
45681 rcu_read_unlock();
45682 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45683 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45684 __fscache_uncache_page(cookie, page);
45685 return true;
45686 }
45687 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45688 spin_unlock(&cookie->stores_lock);
45689
45690 if (xpage) {
45691 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45692 - fscache_stat(&fscache_n_store_radix_deletes);
45693 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45694 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45695 ASSERTCMP(xpage, ==, page);
45696 } else {
45697 - fscache_stat(&fscache_n_store_vmscan_gone);
45698 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45699 }
45700
45701 wake_up_bit(&cookie->flags, 0);
45702 @@ -107,7 +107,7 @@ page_busy:
45703 /* we might want to wait here, but that could deadlock the allocator as
45704 * the work threads writing to the cache may all end up sleeping
45705 * on memory allocation */
45706 - fscache_stat(&fscache_n_store_vmscan_busy);
45707 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45708 return false;
45709 }
45710 EXPORT_SYMBOL(__fscache_maybe_release_page);
45711 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45712 FSCACHE_COOKIE_STORING_TAG);
45713 if (!radix_tree_tag_get(&cookie->stores, page->index,
45714 FSCACHE_COOKIE_PENDING_TAG)) {
45715 - fscache_stat(&fscache_n_store_radix_deletes);
45716 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45717 xpage = radix_tree_delete(&cookie->stores, page->index);
45718 }
45719 spin_unlock(&cookie->stores_lock);
45720 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45721
45722 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45723
45724 - fscache_stat(&fscache_n_attr_changed_calls);
45725 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45726
45727 if (fscache_object_is_active(object)) {
45728 fscache_stat(&fscache_n_cop_attr_changed);
45729 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45730
45731 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45732
45733 - fscache_stat(&fscache_n_attr_changed);
45734 + fscache_stat_unchecked(&fscache_n_attr_changed);
45735
45736 op = kzalloc(sizeof(*op), GFP_KERNEL);
45737 if (!op) {
45738 - fscache_stat(&fscache_n_attr_changed_nomem);
45739 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45740 _leave(" = -ENOMEM");
45741 return -ENOMEM;
45742 }
45743 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45744 if (fscache_submit_exclusive_op(object, op) < 0)
45745 goto nobufs;
45746 spin_unlock(&cookie->lock);
45747 - fscache_stat(&fscache_n_attr_changed_ok);
45748 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45749 fscache_put_operation(op);
45750 _leave(" = 0");
45751 return 0;
45752 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45753 nobufs:
45754 spin_unlock(&cookie->lock);
45755 kfree(op);
45756 - fscache_stat(&fscache_n_attr_changed_nobufs);
45757 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45758 _leave(" = %d", -ENOBUFS);
45759 return -ENOBUFS;
45760 }
45761 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45762 /* allocate a retrieval operation and attempt to submit it */
45763 op = kzalloc(sizeof(*op), GFP_NOIO);
45764 if (!op) {
45765 - fscache_stat(&fscache_n_retrievals_nomem);
45766 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45767 return NULL;
45768 }
45769
45770 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45771 return 0;
45772 }
45773
45774 - fscache_stat(&fscache_n_retrievals_wait);
45775 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45776
45777 jif = jiffies;
45778 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45779 fscache_wait_bit_interruptible,
45780 TASK_INTERRUPTIBLE) != 0) {
45781 - fscache_stat(&fscache_n_retrievals_intr);
45782 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45783 _leave(" = -ERESTARTSYS");
45784 return -ERESTARTSYS;
45785 }
45786 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45787 */
45788 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45789 struct fscache_retrieval *op,
45790 - atomic_t *stat_op_waits,
45791 - atomic_t *stat_object_dead)
45792 + atomic_unchecked_t *stat_op_waits,
45793 + atomic_unchecked_t *stat_object_dead)
45794 {
45795 int ret;
45796
45797 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45798 goto check_if_dead;
45799
45800 _debug(">>> WT");
45801 - fscache_stat(stat_op_waits);
45802 + fscache_stat_unchecked(stat_op_waits);
45803 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45804 fscache_wait_bit_interruptible,
45805 TASK_INTERRUPTIBLE) < 0) {
45806 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45807
45808 check_if_dead:
45809 if (unlikely(fscache_object_is_dead(object))) {
45810 - fscache_stat(stat_object_dead);
45811 + fscache_stat_unchecked(stat_object_dead);
45812 return -ENOBUFS;
45813 }
45814 return 0;
45815 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45816
45817 _enter("%p,%p,,,", cookie, page);
45818
45819 - fscache_stat(&fscache_n_retrievals);
45820 + fscache_stat_unchecked(&fscache_n_retrievals);
45821
45822 if (hlist_empty(&cookie->backing_objects))
45823 goto nobufs;
45824 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45825 goto nobufs_unlock;
45826 spin_unlock(&cookie->lock);
45827
45828 - fscache_stat(&fscache_n_retrieval_ops);
45829 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45830
45831 /* pin the netfs read context in case we need to do the actual netfs
45832 * read because we've encountered a cache read failure */
45833 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45834
45835 error:
45836 if (ret == -ENOMEM)
45837 - fscache_stat(&fscache_n_retrievals_nomem);
45838 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45839 else if (ret == -ERESTARTSYS)
45840 - fscache_stat(&fscache_n_retrievals_intr);
45841 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45842 else if (ret == -ENODATA)
45843 - fscache_stat(&fscache_n_retrievals_nodata);
45844 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45845 else if (ret < 0)
45846 - fscache_stat(&fscache_n_retrievals_nobufs);
45847 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45848 else
45849 - fscache_stat(&fscache_n_retrievals_ok);
45850 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45851
45852 fscache_put_retrieval(op);
45853 _leave(" = %d", ret);
45854 @@ -429,7 +429,7 @@ nobufs_unlock:
45855 spin_unlock(&cookie->lock);
45856 kfree(op);
45857 nobufs:
45858 - fscache_stat(&fscache_n_retrievals_nobufs);
45859 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45860 _leave(" = -ENOBUFS");
45861 return -ENOBUFS;
45862 }
45863 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45864
45865 _enter("%p,,%d,,,", cookie, *nr_pages);
45866
45867 - fscache_stat(&fscache_n_retrievals);
45868 + fscache_stat_unchecked(&fscache_n_retrievals);
45869
45870 if (hlist_empty(&cookie->backing_objects))
45871 goto nobufs;
45872 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45873 goto nobufs_unlock;
45874 spin_unlock(&cookie->lock);
45875
45876 - fscache_stat(&fscache_n_retrieval_ops);
45877 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45878
45879 /* pin the netfs read context in case we need to do the actual netfs
45880 * read because we've encountered a cache read failure */
45881 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45882
45883 error:
45884 if (ret == -ENOMEM)
45885 - fscache_stat(&fscache_n_retrievals_nomem);
45886 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45887 else if (ret == -ERESTARTSYS)
45888 - fscache_stat(&fscache_n_retrievals_intr);
45889 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45890 else if (ret == -ENODATA)
45891 - fscache_stat(&fscache_n_retrievals_nodata);
45892 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45893 else if (ret < 0)
45894 - fscache_stat(&fscache_n_retrievals_nobufs);
45895 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45896 else
45897 - fscache_stat(&fscache_n_retrievals_ok);
45898 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45899
45900 fscache_put_retrieval(op);
45901 _leave(" = %d", ret);
45902 @@ -545,7 +545,7 @@ nobufs_unlock:
45903 spin_unlock(&cookie->lock);
45904 kfree(op);
45905 nobufs:
45906 - fscache_stat(&fscache_n_retrievals_nobufs);
45907 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45908 _leave(" = -ENOBUFS");
45909 return -ENOBUFS;
45910 }
45911 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45912
45913 _enter("%p,%p,,,", cookie, page);
45914
45915 - fscache_stat(&fscache_n_allocs);
45916 + fscache_stat_unchecked(&fscache_n_allocs);
45917
45918 if (hlist_empty(&cookie->backing_objects))
45919 goto nobufs;
45920 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45921 goto nobufs_unlock;
45922 spin_unlock(&cookie->lock);
45923
45924 - fscache_stat(&fscache_n_alloc_ops);
45925 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45926
45927 ret = fscache_wait_for_retrieval_activation(
45928 object, op,
45929 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45930
45931 error:
45932 if (ret == -ERESTARTSYS)
45933 - fscache_stat(&fscache_n_allocs_intr);
45934 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45935 else if (ret < 0)
45936 - fscache_stat(&fscache_n_allocs_nobufs);
45937 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45938 else
45939 - fscache_stat(&fscache_n_allocs_ok);
45940 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45941
45942 fscache_put_retrieval(op);
45943 _leave(" = %d", ret);
45944 @@ -625,7 +625,7 @@ nobufs_unlock:
45945 spin_unlock(&cookie->lock);
45946 kfree(op);
45947 nobufs:
45948 - fscache_stat(&fscache_n_allocs_nobufs);
45949 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45950 _leave(" = -ENOBUFS");
45951 return -ENOBUFS;
45952 }
45953 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45954
45955 spin_lock(&cookie->stores_lock);
45956
45957 - fscache_stat(&fscache_n_store_calls);
45958 + fscache_stat_unchecked(&fscache_n_store_calls);
45959
45960 /* find a page to store */
45961 page = NULL;
45962 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45963 page = results[0];
45964 _debug("gang %d [%lx]", n, page->index);
45965 if (page->index > op->store_limit) {
45966 - fscache_stat(&fscache_n_store_pages_over_limit);
45967 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45968 goto superseded;
45969 }
45970
45971 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45972 spin_unlock(&cookie->stores_lock);
45973 spin_unlock(&object->lock);
45974
45975 - fscache_stat(&fscache_n_store_pages);
45976 + fscache_stat_unchecked(&fscache_n_store_pages);
45977 fscache_stat(&fscache_n_cop_write_page);
45978 ret = object->cache->ops->write_page(op, page);
45979 fscache_stat_d(&fscache_n_cop_write_page);
45980 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45981 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45982 ASSERT(PageFsCache(page));
45983
45984 - fscache_stat(&fscache_n_stores);
45985 + fscache_stat_unchecked(&fscache_n_stores);
45986
45987 op = kzalloc(sizeof(*op), GFP_NOIO);
45988 if (!op)
45989 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45990 spin_unlock(&cookie->stores_lock);
45991 spin_unlock(&object->lock);
45992
45993 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45994 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45995 op->store_limit = object->store_limit;
45996
45997 if (fscache_submit_op(object, &op->op) < 0)
45998 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45999
46000 spin_unlock(&cookie->lock);
46001 radix_tree_preload_end();
46002 - fscache_stat(&fscache_n_store_ops);
46003 - fscache_stat(&fscache_n_stores_ok);
46004 + fscache_stat_unchecked(&fscache_n_store_ops);
46005 + fscache_stat_unchecked(&fscache_n_stores_ok);
46006
46007 /* the work queue now carries its own ref on the object */
46008 fscache_put_operation(&op->op);
46009 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46010 return 0;
46011
46012 already_queued:
46013 - fscache_stat(&fscache_n_stores_again);
46014 + fscache_stat_unchecked(&fscache_n_stores_again);
46015 already_pending:
46016 spin_unlock(&cookie->stores_lock);
46017 spin_unlock(&object->lock);
46018 spin_unlock(&cookie->lock);
46019 radix_tree_preload_end();
46020 kfree(op);
46021 - fscache_stat(&fscache_n_stores_ok);
46022 + fscache_stat_unchecked(&fscache_n_stores_ok);
46023 _leave(" = 0");
46024 return 0;
46025
46026 @@ -851,14 +851,14 @@ nobufs:
46027 spin_unlock(&cookie->lock);
46028 radix_tree_preload_end();
46029 kfree(op);
46030 - fscache_stat(&fscache_n_stores_nobufs);
46031 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46032 _leave(" = -ENOBUFS");
46033 return -ENOBUFS;
46034
46035 nomem_free:
46036 kfree(op);
46037 nomem:
46038 - fscache_stat(&fscache_n_stores_oom);
46039 + fscache_stat_unchecked(&fscache_n_stores_oom);
46040 _leave(" = -ENOMEM");
46041 return -ENOMEM;
46042 }
46043 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46044 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46045 ASSERTCMP(page, !=, NULL);
46046
46047 - fscache_stat(&fscache_n_uncaches);
46048 + fscache_stat_unchecked(&fscache_n_uncaches);
46049
46050 /* cache withdrawal may beat us to it */
46051 if (!PageFsCache(page))
46052 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46053 unsigned long loop;
46054
46055 #ifdef CONFIG_FSCACHE_STATS
46056 - atomic_add(pagevec->nr, &fscache_n_marks);
46057 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46058 #endif
46059
46060 for (loop = 0; loop < pagevec->nr; loop++) {
46061 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46062 index 4765190..2a067f2 100644
46063 --- a/fs/fscache/stats.c
46064 +++ b/fs/fscache/stats.c
46065 @@ -18,95 +18,95 @@
46066 /*
46067 * operation counters
46068 */
46069 -atomic_t fscache_n_op_pend;
46070 -atomic_t fscache_n_op_run;
46071 -atomic_t fscache_n_op_enqueue;
46072 -atomic_t fscache_n_op_requeue;
46073 -atomic_t fscache_n_op_deferred_release;
46074 -atomic_t fscache_n_op_release;
46075 -atomic_t fscache_n_op_gc;
46076 -atomic_t fscache_n_op_cancelled;
46077 -atomic_t fscache_n_op_rejected;
46078 +atomic_unchecked_t fscache_n_op_pend;
46079 +atomic_unchecked_t fscache_n_op_run;
46080 +atomic_unchecked_t fscache_n_op_enqueue;
46081 +atomic_unchecked_t fscache_n_op_requeue;
46082 +atomic_unchecked_t fscache_n_op_deferred_release;
46083 +atomic_unchecked_t fscache_n_op_release;
46084 +atomic_unchecked_t fscache_n_op_gc;
46085 +atomic_unchecked_t fscache_n_op_cancelled;
46086 +atomic_unchecked_t fscache_n_op_rejected;
46087
46088 -atomic_t fscache_n_attr_changed;
46089 -atomic_t fscache_n_attr_changed_ok;
46090 -atomic_t fscache_n_attr_changed_nobufs;
46091 -atomic_t fscache_n_attr_changed_nomem;
46092 -atomic_t fscache_n_attr_changed_calls;
46093 +atomic_unchecked_t fscache_n_attr_changed;
46094 +atomic_unchecked_t fscache_n_attr_changed_ok;
46095 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46096 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46097 +atomic_unchecked_t fscache_n_attr_changed_calls;
46098
46099 -atomic_t fscache_n_allocs;
46100 -atomic_t fscache_n_allocs_ok;
46101 -atomic_t fscache_n_allocs_wait;
46102 -atomic_t fscache_n_allocs_nobufs;
46103 -atomic_t fscache_n_allocs_intr;
46104 -atomic_t fscache_n_allocs_object_dead;
46105 -atomic_t fscache_n_alloc_ops;
46106 -atomic_t fscache_n_alloc_op_waits;
46107 +atomic_unchecked_t fscache_n_allocs;
46108 +atomic_unchecked_t fscache_n_allocs_ok;
46109 +atomic_unchecked_t fscache_n_allocs_wait;
46110 +atomic_unchecked_t fscache_n_allocs_nobufs;
46111 +atomic_unchecked_t fscache_n_allocs_intr;
46112 +atomic_unchecked_t fscache_n_allocs_object_dead;
46113 +atomic_unchecked_t fscache_n_alloc_ops;
46114 +atomic_unchecked_t fscache_n_alloc_op_waits;
46115
46116 -atomic_t fscache_n_retrievals;
46117 -atomic_t fscache_n_retrievals_ok;
46118 -atomic_t fscache_n_retrievals_wait;
46119 -atomic_t fscache_n_retrievals_nodata;
46120 -atomic_t fscache_n_retrievals_nobufs;
46121 -atomic_t fscache_n_retrievals_intr;
46122 -atomic_t fscache_n_retrievals_nomem;
46123 -atomic_t fscache_n_retrievals_object_dead;
46124 -atomic_t fscache_n_retrieval_ops;
46125 -atomic_t fscache_n_retrieval_op_waits;
46126 +atomic_unchecked_t fscache_n_retrievals;
46127 +atomic_unchecked_t fscache_n_retrievals_ok;
46128 +atomic_unchecked_t fscache_n_retrievals_wait;
46129 +atomic_unchecked_t fscache_n_retrievals_nodata;
46130 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46131 +atomic_unchecked_t fscache_n_retrievals_intr;
46132 +atomic_unchecked_t fscache_n_retrievals_nomem;
46133 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46134 +atomic_unchecked_t fscache_n_retrieval_ops;
46135 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46136
46137 -atomic_t fscache_n_stores;
46138 -atomic_t fscache_n_stores_ok;
46139 -atomic_t fscache_n_stores_again;
46140 -atomic_t fscache_n_stores_nobufs;
46141 -atomic_t fscache_n_stores_oom;
46142 -atomic_t fscache_n_store_ops;
46143 -atomic_t fscache_n_store_calls;
46144 -atomic_t fscache_n_store_pages;
46145 -atomic_t fscache_n_store_radix_deletes;
46146 -atomic_t fscache_n_store_pages_over_limit;
46147 +atomic_unchecked_t fscache_n_stores;
46148 +atomic_unchecked_t fscache_n_stores_ok;
46149 +atomic_unchecked_t fscache_n_stores_again;
46150 +atomic_unchecked_t fscache_n_stores_nobufs;
46151 +atomic_unchecked_t fscache_n_stores_oom;
46152 +atomic_unchecked_t fscache_n_store_ops;
46153 +atomic_unchecked_t fscache_n_store_calls;
46154 +atomic_unchecked_t fscache_n_store_pages;
46155 +atomic_unchecked_t fscache_n_store_radix_deletes;
46156 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46157
46158 -atomic_t fscache_n_store_vmscan_not_storing;
46159 -atomic_t fscache_n_store_vmscan_gone;
46160 -atomic_t fscache_n_store_vmscan_busy;
46161 -atomic_t fscache_n_store_vmscan_cancelled;
46162 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46163 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46164 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46165 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46166
46167 -atomic_t fscache_n_marks;
46168 -atomic_t fscache_n_uncaches;
46169 +atomic_unchecked_t fscache_n_marks;
46170 +atomic_unchecked_t fscache_n_uncaches;
46171
46172 -atomic_t fscache_n_acquires;
46173 -atomic_t fscache_n_acquires_null;
46174 -atomic_t fscache_n_acquires_no_cache;
46175 -atomic_t fscache_n_acquires_ok;
46176 -atomic_t fscache_n_acquires_nobufs;
46177 -atomic_t fscache_n_acquires_oom;
46178 +atomic_unchecked_t fscache_n_acquires;
46179 +atomic_unchecked_t fscache_n_acquires_null;
46180 +atomic_unchecked_t fscache_n_acquires_no_cache;
46181 +atomic_unchecked_t fscache_n_acquires_ok;
46182 +atomic_unchecked_t fscache_n_acquires_nobufs;
46183 +atomic_unchecked_t fscache_n_acquires_oom;
46184
46185 -atomic_t fscache_n_updates;
46186 -atomic_t fscache_n_updates_null;
46187 -atomic_t fscache_n_updates_run;
46188 +atomic_unchecked_t fscache_n_updates;
46189 +atomic_unchecked_t fscache_n_updates_null;
46190 +atomic_unchecked_t fscache_n_updates_run;
46191
46192 -atomic_t fscache_n_relinquishes;
46193 -atomic_t fscache_n_relinquishes_null;
46194 -atomic_t fscache_n_relinquishes_waitcrt;
46195 -atomic_t fscache_n_relinquishes_retire;
46196 +atomic_unchecked_t fscache_n_relinquishes;
46197 +atomic_unchecked_t fscache_n_relinquishes_null;
46198 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46199 +atomic_unchecked_t fscache_n_relinquishes_retire;
46200
46201 -atomic_t fscache_n_cookie_index;
46202 -atomic_t fscache_n_cookie_data;
46203 -atomic_t fscache_n_cookie_special;
46204 +atomic_unchecked_t fscache_n_cookie_index;
46205 +atomic_unchecked_t fscache_n_cookie_data;
46206 +atomic_unchecked_t fscache_n_cookie_special;
46207
46208 -atomic_t fscache_n_object_alloc;
46209 -atomic_t fscache_n_object_no_alloc;
46210 -atomic_t fscache_n_object_lookups;
46211 -atomic_t fscache_n_object_lookups_negative;
46212 -atomic_t fscache_n_object_lookups_positive;
46213 -atomic_t fscache_n_object_lookups_timed_out;
46214 -atomic_t fscache_n_object_created;
46215 -atomic_t fscache_n_object_avail;
46216 -atomic_t fscache_n_object_dead;
46217 +atomic_unchecked_t fscache_n_object_alloc;
46218 +atomic_unchecked_t fscache_n_object_no_alloc;
46219 +atomic_unchecked_t fscache_n_object_lookups;
46220 +atomic_unchecked_t fscache_n_object_lookups_negative;
46221 +atomic_unchecked_t fscache_n_object_lookups_positive;
46222 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46223 +atomic_unchecked_t fscache_n_object_created;
46224 +atomic_unchecked_t fscache_n_object_avail;
46225 +atomic_unchecked_t fscache_n_object_dead;
46226
46227 -atomic_t fscache_n_checkaux_none;
46228 -atomic_t fscache_n_checkaux_okay;
46229 -atomic_t fscache_n_checkaux_update;
46230 -atomic_t fscache_n_checkaux_obsolete;
46231 +atomic_unchecked_t fscache_n_checkaux_none;
46232 +atomic_unchecked_t fscache_n_checkaux_okay;
46233 +atomic_unchecked_t fscache_n_checkaux_update;
46234 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46235
46236 atomic_t fscache_n_cop_alloc_object;
46237 atomic_t fscache_n_cop_lookup_object;
46238 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46239 seq_puts(m, "FS-Cache statistics\n");
46240
46241 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46242 - atomic_read(&fscache_n_cookie_index),
46243 - atomic_read(&fscache_n_cookie_data),
46244 - atomic_read(&fscache_n_cookie_special));
46245 + atomic_read_unchecked(&fscache_n_cookie_index),
46246 + atomic_read_unchecked(&fscache_n_cookie_data),
46247 + atomic_read_unchecked(&fscache_n_cookie_special));
46248
46249 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46250 - atomic_read(&fscache_n_object_alloc),
46251 - atomic_read(&fscache_n_object_no_alloc),
46252 - atomic_read(&fscache_n_object_avail),
46253 - atomic_read(&fscache_n_object_dead));
46254 + atomic_read_unchecked(&fscache_n_object_alloc),
46255 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46256 + atomic_read_unchecked(&fscache_n_object_avail),
46257 + atomic_read_unchecked(&fscache_n_object_dead));
46258 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46259 - atomic_read(&fscache_n_checkaux_none),
46260 - atomic_read(&fscache_n_checkaux_okay),
46261 - atomic_read(&fscache_n_checkaux_update),
46262 - atomic_read(&fscache_n_checkaux_obsolete));
46263 + atomic_read_unchecked(&fscache_n_checkaux_none),
46264 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46265 + atomic_read_unchecked(&fscache_n_checkaux_update),
46266 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46267
46268 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46269 - atomic_read(&fscache_n_marks),
46270 - atomic_read(&fscache_n_uncaches));
46271 + atomic_read_unchecked(&fscache_n_marks),
46272 + atomic_read_unchecked(&fscache_n_uncaches));
46273
46274 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46275 " oom=%u\n",
46276 - atomic_read(&fscache_n_acquires),
46277 - atomic_read(&fscache_n_acquires_null),
46278 - atomic_read(&fscache_n_acquires_no_cache),
46279 - atomic_read(&fscache_n_acquires_ok),
46280 - atomic_read(&fscache_n_acquires_nobufs),
46281 - atomic_read(&fscache_n_acquires_oom));
46282 + atomic_read_unchecked(&fscache_n_acquires),
46283 + atomic_read_unchecked(&fscache_n_acquires_null),
46284 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46285 + atomic_read_unchecked(&fscache_n_acquires_ok),
46286 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46287 + atomic_read_unchecked(&fscache_n_acquires_oom));
46288
46289 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46290 - atomic_read(&fscache_n_object_lookups),
46291 - atomic_read(&fscache_n_object_lookups_negative),
46292 - atomic_read(&fscache_n_object_lookups_positive),
46293 - atomic_read(&fscache_n_object_created),
46294 - atomic_read(&fscache_n_object_lookups_timed_out));
46295 + atomic_read_unchecked(&fscache_n_object_lookups),
46296 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46297 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46298 + atomic_read_unchecked(&fscache_n_object_created),
46299 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46300
46301 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46302 - atomic_read(&fscache_n_updates),
46303 - atomic_read(&fscache_n_updates_null),
46304 - atomic_read(&fscache_n_updates_run));
46305 + atomic_read_unchecked(&fscache_n_updates),
46306 + atomic_read_unchecked(&fscache_n_updates_null),
46307 + atomic_read_unchecked(&fscache_n_updates_run));
46308
46309 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46310 - atomic_read(&fscache_n_relinquishes),
46311 - atomic_read(&fscache_n_relinquishes_null),
46312 - atomic_read(&fscache_n_relinquishes_waitcrt),
46313 - atomic_read(&fscache_n_relinquishes_retire));
46314 + atomic_read_unchecked(&fscache_n_relinquishes),
46315 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46316 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46317 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46318
46319 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46320 - atomic_read(&fscache_n_attr_changed),
46321 - atomic_read(&fscache_n_attr_changed_ok),
46322 - atomic_read(&fscache_n_attr_changed_nobufs),
46323 - atomic_read(&fscache_n_attr_changed_nomem),
46324 - atomic_read(&fscache_n_attr_changed_calls));
46325 + atomic_read_unchecked(&fscache_n_attr_changed),
46326 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46327 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46328 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46329 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46330
46331 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46332 - atomic_read(&fscache_n_allocs),
46333 - atomic_read(&fscache_n_allocs_ok),
46334 - atomic_read(&fscache_n_allocs_wait),
46335 - atomic_read(&fscache_n_allocs_nobufs),
46336 - atomic_read(&fscache_n_allocs_intr));
46337 + atomic_read_unchecked(&fscache_n_allocs),
46338 + atomic_read_unchecked(&fscache_n_allocs_ok),
46339 + atomic_read_unchecked(&fscache_n_allocs_wait),
46340 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46341 + atomic_read_unchecked(&fscache_n_allocs_intr));
46342 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46343 - atomic_read(&fscache_n_alloc_ops),
46344 - atomic_read(&fscache_n_alloc_op_waits),
46345 - atomic_read(&fscache_n_allocs_object_dead));
46346 + atomic_read_unchecked(&fscache_n_alloc_ops),
46347 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46348 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46349
46350 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46351 " int=%u oom=%u\n",
46352 - atomic_read(&fscache_n_retrievals),
46353 - atomic_read(&fscache_n_retrievals_ok),
46354 - atomic_read(&fscache_n_retrievals_wait),
46355 - atomic_read(&fscache_n_retrievals_nodata),
46356 - atomic_read(&fscache_n_retrievals_nobufs),
46357 - atomic_read(&fscache_n_retrievals_intr),
46358 - atomic_read(&fscache_n_retrievals_nomem));
46359 + atomic_read_unchecked(&fscache_n_retrievals),
46360 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46361 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46362 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46363 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46364 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46365 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46366 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46367 - atomic_read(&fscache_n_retrieval_ops),
46368 - atomic_read(&fscache_n_retrieval_op_waits),
46369 - atomic_read(&fscache_n_retrievals_object_dead));
46370 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46371 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46372 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46373
46374 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46375 - atomic_read(&fscache_n_stores),
46376 - atomic_read(&fscache_n_stores_ok),
46377 - atomic_read(&fscache_n_stores_again),
46378 - atomic_read(&fscache_n_stores_nobufs),
46379 - atomic_read(&fscache_n_stores_oom));
46380 + atomic_read_unchecked(&fscache_n_stores),
46381 + atomic_read_unchecked(&fscache_n_stores_ok),
46382 + atomic_read_unchecked(&fscache_n_stores_again),
46383 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46384 + atomic_read_unchecked(&fscache_n_stores_oom));
46385 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46386 - atomic_read(&fscache_n_store_ops),
46387 - atomic_read(&fscache_n_store_calls),
46388 - atomic_read(&fscache_n_store_pages),
46389 - atomic_read(&fscache_n_store_radix_deletes),
46390 - atomic_read(&fscache_n_store_pages_over_limit));
46391 + atomic_read_unchecked(&fscache_n_store_ops),
46392 + atomic_read_unchecked(&fscache_n_store_calls),
46393 + atomic_read_unchecked(&fscache_n_store_pages),
46394 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46395 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46396
46397 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46398 - atomic_read(&fscache_n_store_vmscan_not_storing),
46399 - atomic_read(&fscache_n_store_vmscan_gone),
46400 - atomic_read(&fscache_n_store_vmscan_busy),
46401 - atomic_read(&fscache_n_store_vmscan_cancelled));
46402 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46403 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46404 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46405 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46406
46407 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46408 - atomic_read(&fscache_n_op_pend),
46409 - atomic_read(&fscache_n_op_run),
46410 - atomic_read(&fscache_n_op_enqueue),
46411 - atomic_read(&fscache_n_op_cancelled),
46412 - atomic_read(&fscache_n_op_rejected));
46413 + atomic_read_unchecked(&fscache_n_op_pend),
46414 + atomic_read_unchecked(&fscache_n_op_run),
46415 + atomic_read_unchecked(&fscache_n_op_enqueue),
46416 + atomic_read_unchecked(&fscache_n_op_cancelled),
46417 + atomic_read_unchecked(&fscache_n_op_rejected));
46418 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46419 - atomic_read(&fscache_n_op_deferred_release),
46420 - atomic_read(&fscache_n_op_release),
46421 - atomic_read(&fscache_n_op_gc));
46422 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46423 + atomic_read_unchecked(&fscache_n_op_release),
46424 + atomic_read_unchecked(&fscache_n_op_gc));
46425
46426 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46427 atomic_read(&fscache_n_cop_alloc_object),
46428 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46429 index 3426521..3b75162 100644
46430 --- a/fs/fuse/cuse.c
46431 +++ b/fs/fuse/cuse.c
46432 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46433 INIT_LIST_HEAD(&cuse_conntbl[i]);
46434
46435 /* inherit and extend fuse_dev_operations */
46436 - cuse_channel_fops = fuse_dev_operations;
46437 - cuse_channel_fops.owner = THIS_MODULE;
46438 - cuse_channel_fops.open = cuse_channel_open;
46439 - cuse_channel_fops.release = cuse_channel_release;
46440 + pax_open_kernel();
46441 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46442 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46443 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46444 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46445 + pax_close_kernel();
46446
46447 cuse_class = class_create(THIS_MODULE, "cuse");
46448 if (IS_ERR(cuse_class))
46449 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46450 index 5f3368a..8306426 100644
46451 --- a/fs/fuse/dev.c
46452 +++ b/fs/fuse/dev.c
46453 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46454 ret = 0;
46455 pipe_lock(pipe);
46456
46457 - if (!pipe->readers) {
46458 + if (!atomic_read(&pipe->readers)) {
46459 send_sig(SIGPIPE, current, 0);
46460 if (!ret)
46461 ret = -EPIPE;
46462 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46463 index 2066328..f5add3b 100644
46464 --- a/fs/fuse/dir.c
46465 +++ b/fs/fuse/dir.c
46466 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46467 return link;
46468 }
46469
46470 -static void free_link(char *link)
46471 +static void free_link(const char *link)
46472 {
46473 if (!IS_ERR(link))
46474 free_page((unsigned long) link);
46475 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46476 index 5698746..6086012 100644
46477 --- a/fs/gfs2/inode.c
46478 +++ b/fs/gfs2/inode.c
46479 @@ -1487,7 +1487,7 @@ out:
46480
46481 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46482 {
46483 - char *s = nd_get_link(nd);
46484 + const char *s = nd_get_link(nd);
46485 if (!IS_ERR(s))
46486 kfree(s);
46487 }
46488 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46489 index 3645cd3..786809c 100644
46490 --- a/fs/hugetlbfs/inode.c
46491 +++ b/fs/hugetlbfs/inode.c
46492 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46493 .kill_sb = kill_litter_super,
46494 };
46495
46496 -static struct vfsmount *hugetlbfs_vfsmount;
46497 +struct vfsmount *hugetlbfs_vfsmount;
46498
46499 static int can_do_hugetlb_shm(void)
46500 {
46501 diff --git a/fs/inode.c b/fs/inode.c
46502 index 83ab215..8842101 100644
46503 --- a/fs/inode.c
46504 +++ b/fs/inode.c
46505 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46506
46507 #ifdef CONFIG_SMP
46508 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46509 - static atomic_t shared_last_ino;
46510 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46511 + static atomic_unchecked_t shared_last_ino;
46512 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46513
46514 res = next - LAST_INO_BATCH;
46515 }
46516 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46517 index eafb8d3..f423d37 100644
46518 --- a/fs/jffs2/erase.c
46519 +++ b/fs/jffs2/erase.c
46520 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46521 struct jffs2_unknown_node marker = {
46522 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46523 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46524 - .totlen = cpu_to_je32(c->cleanmarker_size)
46525 + .totlen = cpu_to_je32(c->cleanmarker_size),
46526 + .hdr_crc = cpu_to_je32(0)
46527 };
46528
46529 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46530 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46531 index 30e8f47..21f600c 100644
46532 --- a/fs/jffs2/wbuf.c
46533 +++ b/fs/jffs2/wbuf.c
46534 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46535 {
46536 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46537 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46538 - .totlen = constant_cpu_to_je32(8)
46539 + .totlen = constant_cpu_to_je32(8),
46540 + .hdr_crc = constant_cpu_to_je32(0)
46541 };
46542
46543 /*
46544 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46545 index 682bca6..86b8e6e 100644
46546 --- a/fs/jfs/super.c
46547 +++ b/fs/jfs/super.c
46548 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46549
46550 jfs_inode_cachep =
46551 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46552 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46553 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46554 init_once);
46555 if (jfs_inode_cachep == NULL)
46556 return -ENOMEM;
46557 diff --git a/fs/libfs.c b/fs/libfs.c
46558 index 5b2dbb3..7442d54 100644
46559 --- a/fs/libfs.c
46560 +++ b/fs/libfs.c
46561 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46562
46563 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46564 struct dentry *next;
46565 + char d_name[sizeof(next->d_iname)];
46566 + const unsigned char *name;
46567 +
46568 next = list_entry(p, struct dentry, d_u.d_child);
46569 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46570 if (!simple_positive(next)) {
46571 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46572
46573 spin_unlock(&next->d_lock);
46574 spin_unlock(&dentry->d_lock);
46575 - if (filldir(dirent, next->d_name.name,
46576 + name = next->d_name.name;
46577 + if (name == next->d_iname) {
46578 + memcpy(d_name, name, next->d_name.len);
46579 + name = d_name;
46580 + }
46581 + if (filldir(dirent, name,
46582 next->d_name.len, filp->f_pos,
46583 next->d_inode->i_ino,
46584 dt_type(next->d_inode)) < 0)
46585 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46586 index 8392cb8..80d6193 100644
46587 --- a/fs/lockd/clntproc.c
46588 +++ b/fs/lockd/clntproc.c
46589 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46590 /*
46591 * Cookie counter for NLM requests
46592 */
46593 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46594 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46595
46596 void nlmclnt_next_cookie(struct nlm_cookie *c)
46597 {
46598 - u32 cookie = atomic_inc_return(&nlm_cookie);
46599 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46600
46601 memcpy(c->data, &cookie, 4);
46602 c->len=4;
46603 diff --git a/fs/locks.c b/fs/locks.c
46604 index 0d68f1f..f216b79 100644
46605 --- a/fs/locks.c
46606 +++ b/fs/locks.c
46607 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46608 return;
46609
46610 if (filp->f_op && filp->f_op->flock) {
46611 - struct file_lock fl = {
46612 + struct file_lock flock = {
46613 .fl_pid = current->tgid,
46614 .fl_file = filp,
46615 .fl_flags = FL_FLOCK,
46616 .fl_type = F_UNLCK,
46617 .fl_end = OFFSET_MAX,
46618 };
46619 - filp->f_op->flock(filp, F_SETLKW, &fl);
46620 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46621 - fl.fl_ops->fl_release_private(&fl);
46622 + filp->f_op->flock(filp, F_SETLKW, &flock);
46623 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46624 + flock.fl_ops->fl_release_private(&flock);
46625 }
46626
46627 lock_flocks();
46628 diff --git a/fs/namei.c b/fs/namei.c
46629 index 46ea9cc..c7cf3a3 100644
46630 --- a/fs/namei.c
46631 +++ b/fs/namei.c
46632 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46633 if (ret != -EACCES)
46634 return ret;
46635
46636 +#ifdef CONFIG_GRKERNSEC
46637 + /* we'll block if we have to log due to a denied capability use */
46638 + if (mask & MAY_NOT_BLOCK)
46639 + return -ECHILD;
46640 +#endif
46641 +
46642 if (S_ISDIR(inode->i_mode)) {
46643 /* DACs are overridable for directories */
46644 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46645 - return 0;
46646 if (!(mask & MAY_WRITE))
46647 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46648 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46649 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46650 return 0;
46651 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46652 + return 0;
46653 return -EACCES;
46654 }
46655 /*
46656 + * Searching includes executable on directories, else just read.
46657 + */
46658 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46659 + if (mask == MAY_READ)
46660 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46661 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46662 + return 0;
46663 +
46664 + /*
46665 * Read/write DACs are always overridable.
46666 * Executable DACs are overridable when there is
46667 * at least one exec bit set.
46668 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46669 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46670 return 0;
46671
46672 - /*
46673 - * Searching includes executable on directories, else just read.
46674 - */
46675 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46676 - if (mask == MAY_READ)
46677 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46678 - return 0;
46679 -
46680 return -EACCES;
46681 }
46682
46683 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46684 return error;
46685 }
46686
46687 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46688 + dentry->d_inode, dentry, nd->path.mnt)) {
46689 + error = -EACCES;
46690 + *p = ERR_PTR(error); /* no ->put_link(), please */
46691 + path_put(&nd->path);
46692 + return error;
46693 + }
46694 +
46695 nd->last_type = LAST_BIND;
46696 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46697 error = PTR_ERR(*p);
46698 if (!IS_ERR(*p)) {
46699 - char *s = nd_get_link(nd);
46700 + const char *s = nd_get_link(nd);
46701 error = 0;
46702 if (s)
46703 error = __vfs_follow_link(nd, s);
46704 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46705 if (!err)
46706 err = complete_walk(nd);
46707
46708 + if (!(nd->flags & LOOKUP_PARENT)) {
46709 +#ifdef CONFIG_GRKERNSEC
46710 + if (flags & LOOKUP_RCU) {
46711 + if (!err)
46712 + path_put(&nd->path);
46713 + err = -ECHILD;
46714 + } else
46715 +#endif
46716 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46717 + if (!err)
46718 + path_put(&nd->path);
46719 + err = -ENOENT;
46720 + }
46721 + }
46722 +
46723 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46724 if (!nd->inode->i_op->lookup) {
46725 path_put(&nd->path);
46726 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46727 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46728
46729 if (likely(!retval)) {
46730 + if (*name != '/' && nd->path.dentry && nd->inode) {
46731 +#ifdef CONFIG_GRKERNSEC
46732 + if (flags & LOOKUP_RCU)
46733 + return -ECHILD;
46734 +#endif
46735 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46736 + return -ENOENT;
46737 + }
46738 +
46739 if (unlikely(!audit_dummy_context())) {
46740 if (nd->path.dentry && nd->inode)
46741 audit_inode(name, nd->path.dentry);
46742 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46743 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46744 return -EPERM;
46745
46746 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46747 + return -EPERM;
46748 + if (gr_handle_rawio(inode))
46749 + return -EPERM;
46750 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46751 + return -EACCES;
46752 +
46753 return 0;
46754 }
46755
46756 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46757 error = complete_walk(nd);
46758 if (error)
46759 return ERR_PTR(error);
46760 +#ifdef CONFIG_GRKERNSEC
46761 + if (nd->flags & LOOKUP_RCU) {
46762 + error = -ECHILD;
46763 + goto exit;
46764 + }
46765 +#endif
46766 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46767 + error = -ENOENT;
46768 + goto exit;
46769 + }
46770 audit_inode(pathname, nd->path.dentry);
46771 if (open_flag & O_CREAT) {
46772 error = -EISDIR;
46773 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46774 error = complete_walk(nd);
46775 if (error)
46776 return ERR_PTR(error);
46777 +#ifdef CONFIG_GRKERNSEC
46778 + if (nd->flags & LOOKUP_RCU) {
46779 + error = -ECHILD;
46780 + goto exit;
46781 + }
46782 +#endif
46783 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46784 + error = -ENOENT;
46785 + goto exit;
46786 + }
46787 audit_inode(pathname, dir);
46788 goto ok;
46789 }
46790 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46791 error = complete_walk(nd);
46792 if (error)
46793 return ERR_PTR(error);
46794 +#ifdef CONFIG_GRKERNSEC
46795 + if (nd->flags & LOOKUP_RCU) {
46796 + error = -ECHILD;
46797 + goto exit;
46798 + }
46799 +#endif
46800 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46801 + error = -ENOENT;
46802 + goto exit;
46803 + }
46804
46805 error = -ENOTDIR;
46806 if (nd->flags & LOOKUP_DIRECTORY) {
46807 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46808 /* Negative dentry, just create the file */
46809 if (!dentry->d_inode) {
46810 umode_t mode = op->mode;
46811 +
46812 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46813 + error = -EACCES;
46814 + goto exit_mutex_unlock;
46815 + }
46816 +
46817 if (!IS_POSIXACL(dir->d_inode))
46818 mode &= ~current_umask();
46819 /*
46820 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46821 error = vfs_create(dir->d_inode, dentry, mode, nd);
46822 if (error)
46823 goto exit_mutex_unlock;
46824 + else
46825 + gr_handle_create(path->dentry, path->mnt);
46826 mutex_unlock(&dir->d_inode->i_mutex);
46827 dput(nd->path.dentry);
46828 nd->path.dentry = dentry;
46829 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46830 /*
46831 * It already exists.
46832 */
46833 +
46834 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46835 + error = -ENOENT;
46836 + goto exit_mutex_unlock;
46837 + }
46838 +
46839 + /* only check if O_CREAT is specified, all other checks need to go
46840 + into may_open */
46841 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46842 + error = -EACCES;
46843 + goto exit_mutex_unlock;
46844 + }
46845 +
46846 mutex_unlock(&dir->d_inode->i_mutex);
46847 audit_inode(pathname, path->dentry);
46848
46849 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46850 *path = nd.path;
46851 return dentry;
46852 eexist:
46853 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46854 + dput(dentry);
46855 + dentry = ERR_PTR(-ENOENT);
46856 + goto fail;
46857 + }
46858 dput(dentry);
46859 dentry = ERR_PTR(-EEXIST);
46860 fail:
46861 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46862 }
46863 EXPORT_SYMBOL(user_path_create);
46864
46865 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46866 +{
46867 + char *tmp = getname(pathname);
46868 + struct dentry *res;
46869 + if (IS_ERR(tmp))
46870 + return ERR_CAST(tmp);
46871 + res = kern_path_create(dfd, tmp, path, is_dir);
46872 + if (IS_ERR(res))
46873 + putname(tmp);
46874 + else
46875 + *to = tmp;
46876 + return res;
46877 +}
46878 +
46879 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46880 {
46881 int error = may_create(dir, dentry);
46882 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46883 error = mnt_want_write(path.mnt);
46884 if (error)
46885 goto out_dput;
46886 +
46887 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46888 + error = -EPERM;
46889 + goto out_drop_write;
46890 + }
46891 +
46892 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46893 + error = -EACCES;
46894 + goto out_drop_write;
46895 + }
46896 +
46897 error = security_path_mknod(&path, dentry, mode, dev);
46898 if (error)
46899 goto out_drop_write;
46900 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46901 }
46902 out_drop_write:
46903 mnt_drop_write(path.mnt);
46904 +
46905 + if (!error)
46906 + gr_handle_create(dentry, path.mnt);
46907 out_dput:
46908 dput(dentry);
46909 mutex_unlock(&path.dentry->d_inode->i_mutex);
46910 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46911 error = mnt_want_write(path.mnt);
46912 if (error)
46913 goto out_dput;
46914 +
46915 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46916 + error = -EACCES;
46917 + goto out_drop_write;
46918 + }
46919 +
46920 error = security_path_mkdir(&path, dentry, mode);
46921 if (error)
46922 goto out_drop_write;
46923 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46924 out_drop_write:
46925 mnt_drop_write(path.mnt);
46926 +
46927 + if (!error)
46928 + gr_handle_create(dentry, path.mnt);
46929 out_dput:
46930 dput(dentry);
46931 mutex_unlock(&path.dentry->d_inode->i_mutex);
46932 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46933 char * name;
46934 struct dentry *dentry;
46935 struct nameidata nd;
46936 + ino_t saved_ino = 0;
46937 + dev_t saved_dev = 0;
46938
46939 error = user_path_parent(dfd, pathname, &nd, &name);
46940 if (error)
46941 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46942 error = -ENOENT;
46943 goto exit3;
46944 }
46945 +
46946 + saved_ino = dentry->d_inode->i_ino;
46947 + saved_dev = gr_get_dev_from_dentry(dentry);
46948 +
46949 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46950 + error = -EACCES;
46951 + goto exit3;
46952 + }
46953 +
46954 error = mnt_want_write(nd.path.mnt);
46955 if (error)
46956 goto exit3;
46957 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46958 if (error)
46959 goto exit4;
46960 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46961 + if (!error && (saved_dev || saved_ino))
46962 + gr_handle_delete(saved_ino, saved_dev);
46963 exit4:
46964 mnt_drop_write(nd.path.mnt);
46965 exit3:
46966 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46967 struct dentry *dentry;
46968 struct nameidata nd;
46969 struct inode *inode = NULL;
46970 + ino_t saved_ino = 0;
46971 + dev_t saved_dev = 0;
46972
46973 error = user_path_parent(dfd, pathname, &nd, &name);
46974 if (error)
46975 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46976 if (!inode)
46977 goto slashes;
46978 ihold(inode);
46979 +
46980 + if (inode->i_nlink <= 1) {
46981 + saved_ino = inode->i_ino;
46982 + saved_dev = gr_get_dev_from_dentry(dentry);
46983 + }
46984 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46985 + error = -EACCES;
46986 + goto exit2;
46987 + }
46988 +
46989 error = mnt_want_write(nd.path.mnt);
46990 if (error)
46991 goto exit2;
46992 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46993 if (error)
46994 goto exit3;
46995 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46996 + if (!error && (saved_ino || saved_dev))
46997 + gr_handle_delete(saved_ino, saved_dev);
46998 exit3:
46999 mnt_drop_write(nd.path.mnt);
47000 exit2:
47001 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47002 error = mnt_want_write(path.mnt);
47003 if (error)
47004 goto out_dput;
47005 +
47006 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47007 + error = -EACCES;
47008 + goto out_drop_write;
47009 + }
47010 +
47011 error = security_path_symlink(&path, dentry, from);
47012 if (error)
47013 goto out_drop_write;
47014 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47015 + if (!error)
47016 + gr_handle_create(dentry, path.mnt);
47017 out_drop_write:
47018 mnt_drop_write(path.mnt);
47019 out_dput:
47020 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47021 {
47022 struct dentry *new_dentry;
47023 struct path old_path, new_path;
47024 + char *to = NULL;
47025 int how = 0;
47026 int error;
47027
47028 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47029 if (error)
47030 return error;
47031
47032 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47033 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47034 error = PTR_ERR(new_dentry);
47035 if (IS_ERR(new_dentry))
47036 goto out;
47037 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47038 error = mnt_want_write(new_path.mnt);
47039 if (error)
47040 goto out_dput;
47041 +
47042 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47043 + old_path.dentry->d_inode,
47044 + old_path.dentry->d_inode->i_mode, to)) {
47045 + error = -EACCES;
47046 + goto out_drop_write;
47047 + }
47048 +
47049 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47050 + old_path.dentry, old_path.mnt, to)) {
47051 + error = -EACCES;
47052 + goto out_drop_write;
47053 + }
47054 +
47055 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47056 if (error)
47057 goto out_drop_write;
47058 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47059 + if (!error)
47060 + gr_handle_create(new_dentry, new_path.mnt);
47061 out_drop_write:
47062 mnt_drop_write(new_path.mnt);
47063 out_dput:
47064 + putname(to);
47065 dput(new_dentry);
47066 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47067 path_put(&new_path);
47068 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47069 if (new_dentry == trap)
47070 goto exit5;
47071
47072 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47073 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47074 + to);
47075 + if (error)
47076 + goto exit5;
47077 +
47078 error = mnt_want_write(oldnd.path.mnt);
47079 if (error)
47080 goto exit5;
47081 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47082 goto exit6;
47083 error = vfs_rename(old_dir->d_inode, old_dentry,
47084 new_dir->d_inode, new_dentry);
47085 + if (!error)
47086 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47087 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47088 exit6:
47089 mnt_drop_write(oldnd.path.mnt);
47090 exit5:
47091 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47092
47093 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47094 {
47095 + char tmpbuf[64];
47096 + const char *newlink;
47097 int len;
47098
47099 len = PTR_ERR(link);
47100 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47101 len = strlen(link);
47102 if (len > (unsigned) buflen)
47103 len = buflen;
47104 - if (copy_to_user(buffer, link, len))
47105 +
47106 + if (len < sizeof(tmpbuf)) {
47107 + memcpy(tmpbuf, link, len);
47108 + newlink = tmpbuf;
47109 + } else
47110 + newlink = link;
47111 +
47112 + if (copy_to_user(buffer, newlink, len))
47113 len = -EFAULT;
47114 out:
47115 return len;
47116 diff --git a/fs/namespace.c b/fs/namespace.c
47117 index e608199..9609cb9 100644
47118 --- a/fs/namespace.c
47119 +++ b/fs/namespace.c
47120 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47121 if (!(sb->s_flags & MS_RDONLY))
47122 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47123 up_write(&sb->s_umount);
47124 +
47125 + gr_log_remount(mnt->mnt_devname, retval);
47126 +
47127 return retval;
47128 }
47129
47130 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47131 br_write_unlock(vfsmount_lock);
47132 up_write(&namespace_sem);
47133 release_mounts(&umount_list);
47134 +
47135 + gr_log_unmount(mnt->mnt_devname, retval);
47136 +
47137 return retval;
47138 }
47139
47140 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47141 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47142 MS_STRICTATIME);
47143
47144 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47145 + retval = -EPERM;
47146 + goto dput_out;
47147 + }
47148 +
47149 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47150 + retval = -EPERM;
47151 + goto dput_out;
47152 + }
47153 +
47154 if (flags & MS_REMOUNT)
47155 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47156 data_page);
47157 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47158 dev_name, data_page);
47159 dput_out:
47160 path_put(&path);
47161 +
47162 + gr_log_mount(dev_name, dir_name, retval);
47163 +
47164 return retval;
47165 }
47166
47167 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47168 if (error)
47169 goto out2;
47170
47171 + if (gr_handle_chroot_pivot()) {
47172 + error = -EPERM;
47173 + goto out2;
47174 + }
47175 +
47176 get_fs_root(current->fs, &root);
47177 error = lock_mount(&old);
47178 if (error)
47179 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47180 index 32c0658..b1c2045e 100644
47181 --- a/fs/ncpfs/ncplib_kernel.h
47182 +++ b/fs/ncpfs/ncplib_kernel.h
47183 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47184 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47185 const unsigned char *, unsigned int, int);
47186 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47187 - const unsigned char *, unsigned int, int);
47188 + const unsigned char *, unsigned int, int) __size_overflow(5);
47189
47190 #define NCP_ESC ':'
47191 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47192 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47193 int ncp__io2vol(unsigned char *, unsigned int *,
47194 const unsigned char *, unsigned int, int);
47195 int ncp__vol2io(unsigned char *, unsigned int *,
47196 - const unsigned char *, unsigned int, int);
47197 + const unsigned char *, unsigned int, int) __size_overflow(5);
47198
47199 #define NCP_IO_TABLE(sb) NULL
47200 #define ncp_tolower(t, c) tolower(c)
47201 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47202 index f649fba..236bf92 100644
47203 --- a/fs/nfs/inode.c
47204 +++ b/fs/nfs/inode.c
47205 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47206 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47207 nfsi->attrtimeo_timestamp = jiffies;
47208
47209 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47210 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47211 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47212 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47213 else
47214 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47215 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47216 }
47217
47218 -static atomic_long_t nfs_attr_generation_counter;
47219 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47220
47221 static unsigned long nfs_read_attr_generation_counter(void)
47222 {
47223 - return atomic_long_read(&nfs_attr_generation_counter);
47224 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47225 }
47226
47227 unsigned long nfs_inc_attr_generation_counter(void)
47228 {
47229 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47230 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47231 }
47232
47233 void nfs_fattr_init(struct nfs_fattr *fattr)
47234 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47235 index edf6d3e..bdd1da7 100644
47236 --- a/fs/nfsd/vfs.c
47237 +++ b/fs/nfsd/vfs.c
47238 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47239 } else {
47240 oldfs = get_fs();
47241 set_fs(KERNEL_DS);
47242 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47243 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47244 set_fs(oldfs);
47245 }
47246
47247 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47248
47249 /* Write the data. */
47250 oldfs = get_fs(); set_fs(KERNEL_DS);
47251 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47252 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47253 set_fs(oldfs);
47254 if (host_err < 0)
47255 goto out_nfserr;
47256 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47257 */
47258
47259 oldfs = get_fs(); set_fs(KERNEL_DS);
47260 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47261 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47262 set_fs(oldfs);
47263
47264 if (host_err < 0)
47265 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47266 index 3568c8a..e0240d8 100644
47267 --- a/fs/notify/fanotify/fanotify_user.c
47268 +++ b/fs/notify/fanotify/fanotify_user.c
47269 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47270 goto out_close_fd;
47271
47272 ret = -EFAULT;
47273 - if (copy_to_user(buf, &fanotify_event_metadata,
47274 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47275 + copy_to_user(buf, &fanotify_event_metadata,
47276 fanotify_event_metadata.event_len))
47277 goto out_kill_access_response;
47278
47279 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47280 index ee18815..7aa5d01 100644
47281 --- a/fs/notify/notification.c
47282 +++ b/fs/notify/notification.c
47283 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47284 * get set to 0 so it will never get 'freed'
47285 */
47286 static struct fsnotify_event *q_overflow_event;
47287 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47288 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47289
47290 /**
47291 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47292 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47293 */
47294 u32 fsnotify_get_cookie(void)
47295 {
47296 - return atomic_inc_return(&fsnotify_sync_cookie);
47297 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47298 }
47299 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47300
47301 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47302 index 99e3610..02c1068 100644
47303 --- a/fs/ntfs/dir.c
47304 +++ b/fs/ntfs/dir.c
47305 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47306 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47307 ~(s64)(ndir->itype.index.block_size - 1)));
47308 /* Bounds checks. */
47309 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47310 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47311 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47312 "inode 0x%lx or driver bug.", vdir->i_ino);
47313 goto err_out;
47314 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47315 index c587e2d..3641eaa 100644
47316 --- a/fs/ntfs/file.c
47317 +++ b/fs/ntfs/file.c
47318 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47319 #endif /* NTFS_RW */
47320 };
47321
47322 -const struct file_operations ntfs_empty_file_ops = {};
47323 +const struct file_operations ntfs_empty_file_ops __read_only;
47324
47325 -const struct inode_operations ntfs_empty_inode_ops = {};
47326 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47327 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47328 index 210c352..a174f83 100644
47329 --- a/fs/ocfs2/localalloc.c
47330 +++ b/fs/ocfs2/localalloc.c
47331 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47332 goto bail;
47333 }
47334
47335 - atomic_inc(&osb->alloc_stats.moves);
47336 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47337
47338 bail:
47339 if (handle)
47340 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47341 index d355e6e..578d905 100644
47342 --- a/fs/ocfs2/ocfs2.h
47343 +++ b/fs/ocfs2/ocfs2.h
47344 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47345
47346 struct ocfs2_alloc_stats
47347 {
47348 - atomic_t moves;
47349 - atomic_t local_data;
47350 - atomic_t bitmap_data;
47351 - atomic_t bg_allocs;
47352 - atomic_t bg_extends;
47353 + atomic_unchecked_t moves;
47354 + atomic_unchecked_t local_data;
47355 + atomic_unchecked_t bitmap_data;
47356 + atomic_unchecked_t bg_allocs;
47357 + atomic_unchecked_t bg_extends;
47358 };
47359
47360 enum ocfs2_local_alloc_state
47361 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47362 index ba5d97e..c77db25 100644
47363 --- a/fs/ocfs2/suballoc.c
47364 +++ b/fs/ocfs2/suballoc.c
47365 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47366 mlog_errno(status);
47367 goto bail;
47368 }
47369 - atomic_inc(&osb->alloc_stats.bg_extends);
47370 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47371
47372 /* You should never ask for this much metadata */
47373 BUG_ON(bits_wanted >
47374 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47375 mlog_errno(status);
47376 goto bail;
47377 }
47378 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47379 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47380
47381 *suballoc_loc = res.sr_bg_blkno;
47382 *suballoc_bit_start = res.sr_bit_offset;
47383 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47384 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47385 res->sr_bits);
47386
47387 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47388 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47389
47390 BUG_ON(res->sr_bits != 1);
47391
47392 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47393 mlog_errno(status);
47394 goto bail;
47395 }
47396 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47397 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47398
47399 BUG_ON(res.sr_bits != 1);
47400
47401 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47402 cluster_start,
47403 num_clusters);
47404 if (!status)
47405 - atomic_inc(&osb->alloc_stats.local_data);
47406 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47407 } else {
47408 if (min_clusters > (osb->bitmap_cpg - 1)) {
47409 /* The only paths asking for contiguousness
47410 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47411 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47412 res.sr_bg_blkno,
47413 res.sr_bit_offset);
47414 - atomic_inc(&osb->alloc_stats.bitmap_data);
47415 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47416 *num_clusters = res.sr_bits;
47417 }
47418 }
47419 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47420 index 604e12c..8426483 100644
47421 --- a/fs/ocfs2/super.c
47422 +++ b/fs/ocfs2/super.c
47423 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47424 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47425 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47426 "Stats",
47427 - atomic_read(&osb->alloc_stats.bitmap_data),
47428 - atomic_read(&osb->alloc_stats.local_data),
47429 - atomic_read(&osb->alloc_stats.bg_allocs),
47430 - atomic_read(&osb->alloc_stats.moves),
47431 - atomic_read(&osb->alloc_stats.bg_extends));
47432 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47433 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47434 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47435 + atomic_read_unchecked(&osb->alloc_stats.moves),
47436 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47437
47438 out += snprintf(buf + out, len - out,
47439 "%10s => State: %u Descriptor: %llu Size: %u bits "
47440 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47441 spin_lock_init(&osb->osb_xattr_lock);
47442 ocfs2_init_steal_slots(osb);
47443
47444 - atomic_set(&osb->alloc_stats.moves, 0);
47445 - atomic_set(&osb->alloc_stats.local_data, 0);
47446 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47447 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47448 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47449 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47450 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47451 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47452 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47453 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47454
47455 /* Copy the blockcheck stats from the superblock probe */
47456 osb->osb_ecc_stats = *stats;
47457 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47458 index 5d22872..523db20 100644
47459 --- a/fs/ocfs2/symlink.c
47460 +++ b/fs/ocfs2/symlink.c
47461 @@ -142,7 +142,7 @@ bail:
47462
47463 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47464 {
47465 - char *link = nd_get_link(nd);
47466 + const char *link = nd_get_link(nd);
47467 if (!IS_ERR(link))
47468 kfree(link);
47469 }
47470 diff --git a/fs/open.c b/fs/open.c
47471 index 77becc0..aad7bd9 100644
47472 --- a/fs/open.c
47473 +++ b/fs/open.c
47474 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47475 error = locks_verify_truncate(inode, NULL, length);
47476 if (!error)
47477 error = security_path_truncate(&path);
47478 +
47479 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47480 + error = -EACCES;
47481 +
47482 if (!error)
47483 error = do_truncate(path.dentry, length, 0, NULL);
47484
47485 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47486 if (__mnt_is_readonly(path.mnt))
47487 res = -EROFS;
47488
47489 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47490 + res = -EACCES;
47491 +
47492 out_path_release:
47493 path_put(&path);
47494 out:
47495 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47496 if (error)
47497 goto dput_and_out;
47498
47499 + gr_log_chdir(path.dentry, path.mnt);
47500 +
47501 set_fs_pwd(current->fs, &path);
47502
47503 dput_and_out:
47504 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47505 goto out_putf;
47506
47507 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47508 +
47509 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47510 + error = -EPERM;
47511 +
47512 + if (!error)
47513 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47514 +
47515 if (!error)
47516 set_fs_pwd(current->fs, &file->f_path);
47517 out_putf:
47518 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47519 if (error)
47520 goto dput_and_out;
47521
47522 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47523 + goto dput_and_out;
47524 +
47525 set_fs_root(current->fs, &path);
47526 +
47527 + gr_handle_chroot_chdir(&path);
47528 +
47529 error = 0;
47530 dput_and_out:
47531 path_put(&path);
47532 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47533 if (error)
47534 return error;
47535 mutex_lock(&inode->i_mutex);
47536 +
47537 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47538 + error = -EACCES;
47539 + goto out_unlock;
47540 + }
47541 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47542 + error = -EACCES;
47543 + goto out_unlock;
47544 + }
47545 +
47546 error = security_path_chmod(path, mode);
47547 if (error)
47548 goto out_unlock;
47549 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47550 int error;
47551 struct iattr newattrs;
47552
47553 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47554 + return -EACCES;
47555 +
47556 newattrs.ia_valid = ATTR_CTIME;
47557 if (user != (uid_t) -1) {
47558 newattrs.ia_valid |= ATTR_UID;
47559 diff --git a/fs/pipe.c b/fs/pipe.c
47560 index a932ced..6495412 100644
47561 --- a/fs/pipe.c
47562 +++ b/fs/pipe.c
47563 @@ -420,9 +420,9 @@ redo:
47564 }
47565 if (bufs) /* More to do? */
47566 continue;
47567 - if (!pipe->writers)
47568 + if (!atomic_read(&pipe->writers))
47569 break;
47570 - if (!pipe->waiting_writers) {
47571 + if (!atomic_read(&pipe->waiting_writers)) {
47572 /* syscall merging: Usually we must not sleep
47573 * if O_NONBLOCK is set, or if we got some data.
47574 * But if a writer sleeps in kernel space, then
47575 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47576 mutex_lock(&inode->i_mutex);
47577 pipe = inode->i_pipe;
47578
47579 - if (!pipe->readers) {
47580 + if (!atomic_read(&pipe->readers)) {
47581 send_sig(SIGPIPE, current, 0);
47582 ret = -EPIPE;
47583 goto out;
47584 @@ -530,7 +530,7 @@ redo1:
47585 for (;;) {
47586 int bufs;
47587
47588 - if (!pipe->readers) {
47589 + if (!atomic_read(&pipe->readers)) {
47590 send_sig(SIGPIPE, current, 0);
47591 if (!ret)
47592 ret = -EPIPE;
47593 @@ -616,9 +616,9 @@ redo2:
47594 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47595 do_wakeup = 0;
47596 }
47597 - pipe->waiting_writers++;
47598 + atomic_inc(&pipe->waiting_writers);
47599 pipe_wait(pipe);
47600 - pipe->waiting_writers--;
47601 + atomic_dec(&pipe->waiting_writers);
47602 }
47603 out:
47604 mutex_unlock(&inode->i_mutex);
47605 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47606 mask = 0;
47607 if (filp->f_mode & FMODE_READ) {
47608 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47609 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47610 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47611 mask |= POLLHUP;
47612 }
47613
47614 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47615 * Most Unices do not set POLLERR for FIFOs but on Linux they
47616 * behave exactly like pipes for poll().
47617 */
47618 - if (!pipe->readers)
47619 + if (!atomic_read(&pipe->readers))
47620 mask |= POLLERR;
47621 }
47622
47623 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47624
47625 mutex_lock(&inode->i_mutex);
47626 pipe = inode->i_pipe;
47627 - pipe->readers -= decr;
47628 - pipe->writers -= decw;
47629 + atomic_sub(decr, &pipe->readers);
47630 + atomic_sub(decw, &pipe->writers);
47631
47632 - if (!pipe->readers && !pipe->writers) {
47633 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47634 free_pipe_info(inode);
47635 } else {
47636 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47637 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47638
47639 if (inode->i_pipe) {
47640 ret = 0;
47641 - inode->i_pipe->readers++;
47642 + atomic_inc(&inode->i_pipe->readers);
47643 }
47644
47645 mutex_unlock(&inode->i_mutex);
47646 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47647
47648 if (inode->i_pipe) {
47649 ret = 0;
47650 - inode->i_pipe->writers++;
47651 + atomic_inc(&inode->i_pipe->writers);
47652 }
47653
47654 mutex_unlock(&inode->i_mutex);
47655 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47656 if (inode->i_pipe) {
47657 ret = 0;
47658 if (filp->f_mode & FMODE_READ)
47659 - inode->i_pipe->readers++;
47660 + atomic_inc(&inode->i_pipe->readers);
47661 if (filp->f_mode & FMODE_WRITE)
47662 - inode->i_pipe->writers++;
47663 + atomic_inc(&inode->i_pipe->writers);
47664 }
47665
47666 mutex_unlock(&inode->i_mutex);
47667 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47668 inode->i_pipe = NULL;
47669 }
47670
47671 -static struct vfsmount *pipe_mnt __read_mostly;
47672 +struct vfsmount *pipe_mnt __read_mostly;
47673
47674 /*
47675 * pipefs_dname() is called from d_path().
47676 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47677 goto fail_iput;
47678 inode->i_pipe = pipe;
47679
47680 - pipe->readers = pipe->writers = 1;
47681 + atomic_set(&pipe->readers, 1);
47682 + atomic_set(&pipe->writers, 1);
47683 inode->i_fop = &rdwr_pipefifo_fops;
47684
47685 /*
47686 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47687 index 15af622..0e9f4467 100644
47688 --- a/fs/proc/Kconfig
47689 +++ b/fs/proc/Kconfig
47690 @@ -30,12 +30,12 @@ config PROC_FS
47691
47692 config PROC_KCORE
47693 bool "/proc/kcore support" if !ARM
47694 - depends on PROC_FS && MMU
47695 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47696
47697 config PROC_VMCORE
47698 bool "/proc/vmcore support"
47699 - depends on PROC_FS && CRASH_DUMP
47700 - default y
47701 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47702 + default n
47703 help
47704 Exports the dump image of crashed kernel in ELF format.
47705
47706 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47707 limited in memory.
47708
47709 config PROC_PAGE_MONITOR
47710 - default y
47711 - depends on PROC_FS && MMU
47712 + default n
47713 + depends on PROC_FS && MMU && !GRKERNSEC
47714 bool "Enable /proc page monitoring" if EXPERT
47715 help
47716 Various /proc files exist to monitor process memory utilization:
47717 diff --git a/fs/proc/array.c b/fs/proc/array.c
47718 index c602b8d..a7de642 100644
47719 --- a/fs/proc/array.c
47720 +++ b/fs/proc/array.c
47721 @@ -60,6 +60,7 @@
47722 #include <linux/tty.h>
47723 #include <linux/string.h>
47724 #include <linux/mman.h>
47725 +#include <linux/grsecurity.h>
47726 #include <linux/proc_fs.h>
47727 #include <linux/ioport.h>
47728 #include <linux/uaccess.h>
47729 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47730 seq_putc(m, '\n');
47731 }
47732
47733 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47734 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47735 +{
47736 + if (p->mm)
47737 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47738 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47739 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47740 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47741 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47742 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47743 + else
47744 + seq_printf(m, "PaX:\t-----\n");
47745 +}
47746 +#endif
47747 +
47748 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47749 struct pid *pid, struct task_struct *task)
47750 {
47751 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47752 task_cpus_allowed(m, task);
47753 cpuset_task_status_allowed(m, task);
47754 task_context_switch_counts(m, task);
47755 +
47756 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47757 + task_pax(m, task);
47758 +#endif
47759 +
47760 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47761 + task_grsec_rbac(m, task);
47762 +#endif
47763 +
47764 return 0;
47765 }
47766
47767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47768 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47769 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47770 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47771 +#endif
47772 +
47773 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47774 struct pid *pid, struct task_struct *task, int whole)
47775 {
47776 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47777 char tcomm[sizeof(task->comm)];
47778 unsigned long flags;
47779
47780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47781 + if (current->exec_id != m->exec_id) {
47782 + gr_log_badprocpid("stat");
47783 + return 0;
47784 + }
47785 +#endif
47786 +
47787 state = *get_task_state(task);
47788 vsize = eip = esp = 0;
47789 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47790 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47791 gtime = task->gtime;
47792 }
47793
47794 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47795 + if (PAX_RAND_FLAGS(mm)) {
47796 + eip = 0;
47797 + esp = 0;
47798 + wchan = 0;
47799 + }
47800 +#endif
47801 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47802 + wchan = 0;
47803 + eip =0;
47804 + esp =0;
47805 +#endif
47806 +
47807 /* scale priority and nice values from timeslices to -20..20 */
47808 /* to make it look like a "normal" Unix priority/nice value */
47809 priority = task_prio(task);
47810 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47811 vsize,
47812 mm ? get_mm_rss(mm) : 0,
47813 rsslim,
47814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47815 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47816 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47817 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47818 +#else
47819 mm ? (permitted ? mm->start_code : 1) : 0,
47820 mm ? (permitted ? mm->end_code : 1) : 0,
47821 (permitted && mm) ? mm->start_stack : 0,
47822 +#endif
47823 esp,
47824 eip,
47825 /* The signal information here is obsolete.
47826 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47827 struct pid *pid, struct task_struct *task)
47828 {
47829 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47830 - struct mm_struct *mm = get_task_mm(task);
47831 + struct mm_struct *mm;
47832
47833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47834 + if (current->exec_id != m->exec_id) {
47835 + gr_log_badprocpid("statm");
47836 + return 0;
47837 + }
47838 +#endif
47839 + mm = get_task_mm(task);
47840 if (mm) {
47841 size = task_statm(mm, &shared, &text, &data, &resident);
47842 mmput(mm);
47843 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47844
47845 return 0;
47846 }
47847 +
47848 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47849 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47850 +{
47851 + u32 curr_ip = 0;
47852 + unsigned long flags;
47853 +
47854 + if (lock_task_sighand(task, &flags)) {
47855 + curr_ip = task->signal->curr_ip;
47856 + unlock_task_sighand(task, &flags);
47857 + }
47858 +
47859 + return sprintf(buffer, "%pI4\n", &curr_ip);
47860 +}
47861 +#endif
47862 diff --git a/fs/proc/base.c b/fs/proc/base.c
47863 index d4548dd..d101f84 100644
47864 --- a/fs/proc/base.c
47865 +++ b/fs/proc/base.c
47866 @@ -109,6 +109,14 @@ struct pid_entry {
47867 union proc_op op;
47868 };
47869
47870 +struct getdents_callback {
47871 + struct linux_dirent __user * current_dir;
47872 + struct linux_dirent __user * previous;
47873 + struct file * file;
47874 + int count;
47875 + int error;
47876 +};
47877 +
47878 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47879 .name = (NAME), \
47880 .len = sizeof(NAME) - 1, \
47881 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47882 if (!mm->arg_end)
47883 goto out_mm; /* Shh! No looking before we're done */
47884
47885 + if (gr_acl_handle_procpidmem(task))
47886 + goto out_mm;
47887 +
47888 len = mm->arg_end - mm->arg_start;
47889
47890 if (len > PAGE_SIZE)
47891 @@ -240,12 +251,28 @@ out:
47892 return res;
47893 }
47894
47895 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47896 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47897 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47898 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47899 +#endif
47900 +
47901 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47902 {
47903 struct mm_struct *mm = mm_for_maps(task);
47904 int res = PTR_ERR(mm);
47905 if (mm && !IS_ERR(mm)) {
47906 unsigned int nwords = 0;
47907 +
47908 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47909 + /* allow if we're currently ptracing this task */
47910 + if (PAX_RAND_FLAGS(mm) &&
47911 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47912 + mmput(mm);
47913 + return 0;
47914 + }
47915 +#endif
47916 +
47917 do {
47918 nwords += 2;
47919 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47920 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47921 }
47922
47923
47924 -#ifdef CONFIG_KALLSYMS
47925 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47926 /*
47927 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47928 * Returns the resolved symbol. If that fails, simply return the address.
47929 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47930 mutex_unlock(&task->signal->cred_guard_mutex);
47931 }
47932
47933 -#ifdef CONFIG_STACKTRACE
47934 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47935
47936 #define MAX_STACK_TRACE_DEPTH 64
47937
47938 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47939 return count;
47940 }
47941
47942 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47943 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47944 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47945 {
47946 long nr;
47947 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47948 /************************************************************************/
47949
47950 /* permission checks */
47951 -static int proc_fd_access_allowed(struct inode *inode)
47952 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47953 {
47954 struct task_struct *task;
47955 int allowed = 0;
47956 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47957 */
47958 task = get_proc_task(inode);
47959 if (task) {
47960 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47961 + if (log)
47962 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47963 + else
47964 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47965 put_task_struct(task);
47966 }
47967 return allowed;
47968 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47969 struct task_struct *task,
47970 int hide_pid_min)
47971 {
47972 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47973 + return false;
47974 +
47975 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47976 + rcu_read_lock();
47977 + {
47978 + const struct cred *tmpcred = current_cred();
47979 + const struct cred *cred = __task_cred(task);
47980 +
47981 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47982 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47983 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47984 +#endif
47985 + ) {
47986 + rcu_read_unlock();
47987 + return true;
47988 + }
47989 + }
47990 + rcu_read_unlock();
47991 +
47992 + if (!pid->hide_pid)
47993 + return false;
47994 +#endif
47995 +
47996 if (pid->hide_pid < hide_pid_min)
47997 return true;
47998 if (in_group_p(pid->pid_gid))
47999 return true;
48000 +
48001 return ptrace_may_access(task, PTRACE_MODE_READ);
48002 }
48003
48004 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48005 put_task_struct(task);
48006
48007 if (!has_perms) {
48008 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48009 + {
48010 +#else
48011 if (pid->hide_pid == 2) {
48012 +#endif
48013 /*
48014 * Let's make getdents(), stat(), and open()
48015 * consistent with each other. If a process
48016 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48017 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48018 file->private_data = mm;
48019
48020 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48021 + file->f_version = current->exec_id;
48022 +#endif
48023 +
48024 return 0;
48025 }
48026
48027 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48028 ssize_t copied;
48029 char *page;
48030
48031 +#ifdef CONFIG_GRKERNSEC
48032 + if (write)
48033 + return -EPERM;
48034 +#endif
48035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48036 + if (file->f_version != current->exec_id) {
48037 + gr_log_badprocpid("mem");
48038 + return 0;
48039 + }
48040 +#endif
48041 +
48042 if (!mm)
48043 return 0;
48044
48045 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48046 if (!task)
48047 goto out_no_task;
48048
48049 + if (gr_acl_handle_procpidmem(task))
48050 + goto out;
48051 +
48052 ret = -ENOMEM;
48053 page = (char *)__get_free_page(GFP_TEMPORARY);
48054 if (!page)
48055 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48056 path_put(&nd->path);
48057
48058 /* Are we allowed to snoop on the tasks file descriptors? */
48059 - if (!proc_fd_access_allowed(inode))
48060 + if (!proc_fd_access_allowed(inode, 0))
48061 goto out;
48062
48063 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48064 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48065 struct path path;
48066
48067 /* Are we allowed to snoop on the tasks file descriptors? */
48068 - if (!proc_fd_access_allowed(inode))
48069 - goto out;
48070 + /* logging this is needed for learning on chromium to work properly,
48071 + but we don't want to flood the logs from 'ps' which does a readlink
48072 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48073 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48074 + */
48075 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48076 + if (!proc_fd_access_allowed(inode,0))
48077 + goto out;
48078 + } else {
48079 + if (!proc_fd_access_allowed(inode,1))
48080 + goto out;
48081 + }
48082
48083 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48084 if (error)
48085 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48086 rcu_read_lock();
48087 cred = __task_cred(task);
48088 inode->i_uid = cred->euid;
48089 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48090 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48091 +#else
48092 inode->i_gid = cred->egid;
48093 +#endif
48094 rcu_read_unlock();
48095 }
48096 security_task_to_inode(task, inode);
48097 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48098 return -ENOENT;
48099 }
48100 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48101 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48102 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48103 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48104 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48105 +#endif
48106 task_dumpable(task)) {
48107 cred = __task_cred(task);
48108 stat->uid = cred->euid;
48109 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48110 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48111 +#else
48112 stat->gid = cred->egid;
48113 +#endif
48114 }
48115 }
48116 rcu_read_unlock();
48117 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48118
48119 if (task) {
48120 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48121 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48122 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48123 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48124 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48125 +#endif
48126 task_dumpable(task)) {
48127 rcu_read_lock();
48128 cred = __task_cred(task);
48129 inode->i_uid = cred->euid;
48130 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48131 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48132 +#else
48133 inode->i_gid = cred->egid;
48134 +#endif
48135 rcu_read_unlock();
48136 } else {
48137 inode->i_uid = 0;
48138 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48139 int fd = proc_fd(inode);
48140
48141 if (task) {
48142 - files = get_files_struct(task);
48143 + if (!gr_acl_handle_procpidmem(task))
48144 + files = get_files_struct(task);
48145 put_task_struct(task);
48146 }
48147 if (files) {
48148 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48149 */
48150 static int proc_fd_permission(struct inode *inode, int mask)
48151 {
48152 + struct task_struct *task;
48153 int rv = generic_permission(inode, mask);
48154 - if (rv == 0)
48155 - return 0;
48156 +
48157 if (task_pid(current) == proc_pid(inode))
48158 rv = 0;
48159 +
48160 + task = get_proc_task(inode);
48161 + if (task == NULL)
48162 + return rv;
48163 +
48164 + if (gr_acl_handle_procpidmem(task))
48165 + rv = -EACCES;
48166 +
48167 + put_task_struct(task);
48168 +
48169 return rv;
48170 }
48171
48172 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48173 if (!task)
48174 goto out_no_task;
48175
48176 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48177 + goto out;
48178 +
48179 /*
48180 * Yes, it does not scale. And it should not. Don't add
48181 * new entries into /proc/<tgid>/ without very good reasons.
48182 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48183 if (!task)
48184 goto out_no_task;
48185
48186 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48187 + goto out;
48188 +
48189 ret = 0;
48190 i = filp->f_pos;
48191 switch (i) {
48192 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48193 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48194 void *cookie)
48195 {
48196 - char *s = nd_get_link(nd);
48197 + const char *s = nd_get_link(nd);
48198 if (!IS_ERR(s))
48199 __putname(s);
48200 }
48201 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48202 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48203 #endif
48204 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48205 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48206 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48207 INF("syscall", S_IRUGO, proc_pid_syscall),
48208 #endif
48209 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48210 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48211 #ifdef CONFIG_SECURITY
48212 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48213 #endif
48214 -#ifdef CONFIG_KALLSYMS
48215 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48216 INF("wchan", S_IRUGO, proc_pid_wchan),
48217 #endif
48218 -#ifdef CONFIG_STACKTRACE
48219 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48220 ONE("stack", S_IRUGO, proc_pid_stack),
48221 #endif
48222 #ifdef CONFIG_SCHEDSTATS
48223 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48224 #ifdef CONFIG_HARDWALL
48225 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48226 #endif
48227 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48228 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48229 +#endif
48230 };
48231
48232 static int proc_tgid_base_readdir(struct file * filp,
48233 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48234 if (!inode)
48235 goto out;
48236
48237 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48238 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48239 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48240 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48241 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48242 +#else
48243 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48244 +#endif
48245 inode->i_op = &proc_tgid_base_inode_operations;
48246 inode->i_fop = &proc_tgid_base_operations;
48247 inode->i_flags|=S_IMMUTABLE;
48248 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48249 if (!task)
48250 goto out;
48251
48252 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48253 + goto out_put_task;
48254 +
48255 result = proc_pid_instantiate(dir, dentry, task, NULL);
48256 +out_put_task:
48257 put_task_struct(task);
48258 out:
48259 return result;
48260 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48261 static int fake_filldir(void *buf, const char *name, int namelen,
48262 loff_t offset, u64 ino, unsigned d_type)
48263 {
48264 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48265 + __buf->error = -EINVAL;
48266 return 0;
48267 }
48268
48269 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48270 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48271 #endif
48272 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48273 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48274 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48275 INF("syscall", S_IRUGO, proc_pid_syscall),
48276 #endif
48277 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48278 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48279 #ifdef CONFIG_SECURITY
48280 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48281 #endif
48282 -#ifdef CONFIG_KALLSYMS
48283 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48284 INF("wchan", S_IRUGO, proc_pid_wchan),
48285 #endif
48286 -#ifdef CONFIG_STACKTRACE
48287 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48288 ONE("stack", S_IRUGO, proc_pid_stack),
48289 #endif
48290 #ifdef CONFIG_SCHEDSTATS
48291 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48292 index 82676e3..5f8518a 100644
48293 --- a/fs/proc/cmdline.c
48294 +++ b/fs/proc/cmdline.c
48295 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48296
48297 static int __init proc_cmdline_init(void)
48298 {
48299 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48300 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48301 +#else
48302 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48303 +#endif
48304 return 0;
48305 }
48306 module_init(proc_cmdline_init);
48307 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48308 index b143471..bb105e5 100644
48309 --- a/fs/proc/devices.c
48310 +++ b/fs/proc/devices.c
48311 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48312
48313 static int __init proc_devices_init(void)
48314 {
48315 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48316 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48317 +#else
48318 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48319 +#endif
48320 return 0;
48321 }
48322 module_init(proc_devices_init);
48323 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48324 index 84fd323..f698a32 100644
48325 --- a/fs/proc/inode.c
48326 +++ b/fs/proc/inode.c
48327 @@ -21,12 +21,18 @@
48328 #include <linux/seq_file.h>
48329 #include <linux/slab.h>
48330 #include <linux/mount.h>
48331 +#include <linux/grsecurity.h>
48332
48333 #include <asm/system.h>
48334 #include <asm/uaccess.h>
48335
48336 #include "internal.h"
48337
48338 +#ifdef CONFIG_PROC_SYSCTL
48339 +extern const struct inode_operations proc_sys_inode_operations;
48340 +extern const struct inode_operations proc_sys_dir_operations;
48341 +#endif
48342 +
48343 static void proc_evict_inode(struct inode *inode)
48344 {
48345 struct proc_dir_entry *de;
48346 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48347 ns_ops = PROC_I(inode)->ns_ops;
48348 if (ns_ops && ns_ops->put)
48349 ns_ops->put(PROC_I(inode)->ns);
48350 +
48351 +#ifdef CONFIG_PROC_SYSCTL
48352 + if (inode->i_op == &proc_sys_inode_operations ||
48353 + inode->i_op == &proc_sys_dir_operations)
48354 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48355 +#endif
48356 +
48357 }
48358
48359 static struct kmem_cache * proc_inode_cachep;
48360 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48361 if (de->mode) {
48362 inode->i_mode = de->mode;
48363 inode->i_uid = de->uid;
48364 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48365 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48366 +#else
48367 inode->i_gid = de->gid;
48368 +#endif
48369 }
48370 if (de->size)
48371 inode->i_size = de->size;
48372 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48373 index 2925775..4f08fae 100644
48374 --- a/fs/proc/internal.h
48375 +++ b/fs/proc/internal.h
48376 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48377 struct pid *pid, struct task_struct *task);
48378 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48379 struct pid *pid, struct task_struct *task);
48380 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48381 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48382 +#endif
48383 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48384
48385 extern const struct file_operations proc_maps_operations;
48386 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48387 index d245cb2..f4e8498 100644
48388 --- a/fs/proc/kcore.c
48389 +++ b/fs/proc/kcore.c
48390 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48391 * the addresses in the elf_phdr on our list.
48392 */
48393 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48394 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48395 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48396 + if (tsz > buflen)
48397 tsz = buflen;
48398 -
48399 +
48400 while (buflen) {
48401 struct kcore_list *m;
48402
48403 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48404 kfree(elf_buf);
48405 } else {
48406 if (kern_addr_valid(start)) {
48407 - unsigned long n;
48408 + char *elf_buf;
48409 + mm_segment_t oldfs;
48410
48411 - n = copy_to_user(buffer, (char *)start, tsz);
48412 - /*
48413 - * We cannot distingush between fault on source
48414 - * and fault on destination. When this happens
48415 - * we clear too and hope it will trigger the
48416 - * EFAULT again.
48417 - */
48418 - if (n) {
48419 - if (clear_user(buffer + tsz - n,
48420 - n))
48421 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48422 + if (!elf_buf)
48423 + return -ENOMEM;
48424 + oldfs = get_fs();
48425 + set_fs(KERNEL_DS);
48426 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48427 + set_fs(oldfs);
48428 + if (copy_to_user(buffer, elf_buf, tsz)) {
48429 + kfree(elf_buf);
48430 return -EFAULT;
48431 + }
48432 }
48433 + set_fs(oldfs);
48434 + kfree(elf_buf);
48435 } else {
48436 if (clear_user(buffer, tsz))
48437 return -EFAULT;
48438 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48439
48440 static int open_kcore(struct inode *inode, struct file *filp)
48441 {
48442 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48443 + return -EPERM;
48444 +#endif
48445 if (!capable(CAP_SYS_RAWIO))
48446 return -EPERM;
48447 if (kcore_need_update)
48448 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48449 index 80e4645..53e5fcf 100644
48450 --- a/fs/proc/meminfo.c
48451 +++ b/fs/proc/meminfo.c
48452 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48453 vmi.used >> 10,
48454 vmi.largest_chunk >> 10
48455 #ifdef CONFIG_MEMORY_FAILURE
48456 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48457 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48458 #endif
48459 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48460 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48461 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48462 index b1822dd..df622cb 100644
48463 --- a/fs/proc/nommu.c
48464 +++ b/fs/proc/nommu.c
48465 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48466 if (len < 1)
48467 len = 1;
48468 seq_printf(m, "%*c", len, ' ');
48469 - seq_path(m, &file->f_path, "");
48470 + seq_path(m, &file->f_path, "\n\\");
48471 }
48472
48473 seq_putc(m, '\n');
48474 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48475 index 06e1cc1..177cd98 100644
48476 --- a/fs/proc/proc_net.c
48477 +++ b/fs/proc/proc_net.c
48478 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48479 struct task_struct *task;
48480 struct nsproxy *ns;
48481 struct net *net = NULL;
48482 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48483 + const struct cred *cred = current_cred();
48484 +#endif
48485 +
48486 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48487 + if (cred->fsuid)
48488 + return net;
48489 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48490 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48491 + return net;
48492 +#endif
48493
48494 rcu_read_lock();
48495 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48496 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48497 index 53c3bce..10ad159 100644
48498 --- a/fs/proc/proc_sysctl.c
48499 +++ b/fs/proc/proc_sysctl.c
48500 @@ -9,11 +9,13 @@
48501 #include <linux/namei.h>
48502 #include "internal.h"
48503
48504 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48505 +
48506 static const struct dentry_operations proc_sys_dentry_operations;
48507 static const struct file_operations proc_sys_file_operations;
48508 -static const struct inode_operations proc_sys_inode_operations;
48509 +const struct inode_operations proc_sys_inode_operations;
48510 static const struct file_operations proc_sys_dir_file_operations;
48511 -static const struct inode_operations proc_sys_dir_operations;
48512 +const struct inode_operations proc_sys_dir_operations;
48513
48514 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48515 {
48516 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48517
48518 err = NULL;
48519 d_set_d_op(dentry, &proc_sys_dentry_operations);
48520 +
48521 + gr_handle_proc_create(dentry, inode);
48522 +
48523 d_add(dentry, inode);
48524
48525 + if (gr_handle_sysctl(p, MAY_EXEC))
48526 + err = ERR_PTR(-ENOENT);
48527 +
48528 out:
48529 sysctl_head_finish(head);
48530 return err;
48531 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48532 if (!table->proc_handler)
48533 goto out;
48534
48535 +#ifdef CONFIG_GRKERNSEC
48536 + error = -EPERM;
48537 + if (write && !capable(CAP_SYS_ADMIN))
48538 + goto out;
48539 +#endif
48540 +
48541 /* careful: calling conventions are nasty here */
48542 res = count;
48543 error = table->proc_handler(table, write, buf, &res, ppos);
48544 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48545 return -ENOMEM;
48546 } else {
48547 d_set_d_op(child, &proc_sys_dentry_operations);
48548 +
48549 + gr_handle_proc_create(child, inode);
48550 +
48551 d_add(child, inode);
48552 }
48553 } else {
48554 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48555 if (*pos < file->f_pos)
48556 continue;
48557
48558 + if (gr_handle_sysctl(table, 0))
48559 + continue;
48560 +
48561 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48562 if (res)
48563 return res;
48564 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48565 if (IS_ERR(head))
48566 return PTR_ERR(head);
48567
48568 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48569 + return -ENOENT;
48570 +
48571 generic_fillattr(inode, stat);
48572 if (table)
48573 stat->mode = (stat->mode & S_IFMT) | table->mode;
48574 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48575 .llseek = generic_file_llseek,
48576 };
48577
48578 -static const struct inode_operations proc_sys_inode_operations = {
48579 +const struct inode_operations proc_sys_inode_operations = {
48580 .permission = proc_sys_permission,
48581 .setattr = proc_sys_setattr,
48582 .getattr = proc_sys_getattr,
48583 };
48584
48585 -static const struct inode_operations proc_sys_dir_operations = {
48586 +const struct inode_operations proc_sys_dir_operations = {
48587 .lookup = proc_sys_lookup,
48588 .permission = proc_sys_permission,
48589 .setattr = proc_sys_setattr,
48590 diff --git a/fs/proc/root.c b/fs/proc/root.c
48591 index 46a15d8..335631a 100644
48592 --- a/fs/proc/root.c
48593 +++ b/fs/proc/root.c
48594 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48595 #ifdef CONFIG_PROC_DEVICETREE
48596 proc_device_tree_init();
48597 #endif
48598 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48599 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48600 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48601 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48602 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48603 +#endif
48604 +#else
48605 proc_mkdir("bus", NULL);
48606 +#endif
48607 proc_sys_init();
48608 }
48609
48610 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48611 index 3efa725..23c925b 100644
48612 --- a/fs/proc/task_mmu.c
48613 +++ b/fs/proc/task_mmu.c
48614 @@ -11,6 +11,7 @@
48615 #include <linux/rmap.h>
48616 #include <linux/swap.h>
48617 #include <linux/swapops.h>
48618 +#include <linux/grsecurity.h>
48619
48620 #include <asm/elf.h>
48621 #include <asm/uaccess.h>
48622 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48623 "VmExe:\t%8lu kB\n"
48624 "VmLib:\t%8lu kB\n"
48625 "VmPTE:\t%8lu kB\n"
48626 - "VmSwap:\t%8lu kB\n",
48627 - hiwater_vm << (PAGE_SHIFT-10),
48628 + "VmSwap:\t%8lu kB\n"
48629 +
48630 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48631 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48632 +#endif
48633 +
48634 + ,hiwater_vm << (PAGE_SHIFT-10),
48635 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48636 mm->locked_vm << (PAGE_SHIFT-10),
48637 mm->pinned_vm << (PAGE_SHIFT-10),
48638 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48639 data << (PAGE_SHIFT-10),
48640 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48641 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48642 - swap << (PAGE_SHIFT-10));
48643 + swap << (PAGE_SHIFT-10)
48644 +
48645 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48646 + , mm->context.user_cs_base, mm->context.user_cs_limit
48647 +#endif
48648 +
48649 + );
48650 }
48651
48652 unsigned long task_vsize(struct mm_struct *mm)
48653 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48654 return ret;
48655 }
48656
48657 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48658 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48659 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48660 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48661 +#endif
48662 +
48663 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48664 {
48665 struct mm_struct *mm = vma->vm_mm;
48666 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48667 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48668 }
48669
48670 - /* We don't show the stack guard page in /proc/maps */
48671 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48672 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48673 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48674 +#else
48675 start = vma->vm_start;
48676 - if (stack_guard_page_start(vma, start))
48677 - start += PAGE_SIZE;
48678 end = vma->vm_end;
48679 - if (stack_guard_page_end(vma, end))
48680 - end -= PAGE_SIZE;
48681 +#endif
48682
48683 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48684 start,
48685 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48686 flags & VM_WRITE ? 'w' : '-',
48687 flags & VM_EXEC ? 'x' : '-',
48688 flags & VM_MAYSHARE ? 's' : 'p',
48689 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48690 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48691 +#else
48692 pgoff,
48693 +#endif
48694 MAJOR(dev), MINOR(dev), ino, &len);
48695
48696 /*
48697 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48698 */
48699 if (file) {
48700 pad_len_spaces(m, len);
48701 - seq_path(m, &file->f_path, "\n");
48702 + seq_path(m, &file->f_path, "\n\\");
48703 } else {
48704 const char *name = arch_vma_name(vma);
48705 if (!name) {
48706 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48707 if (vma->vm_start <= mm->brk &&
48708 vma->vm_end >= mm->start_brk) {
48709 name = "[heap]";
48710 - } else if (vma->vm_start <= mm->start_stack &&
48711 - vma->vm_end >= mm->start_stack) {
48712 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48713 + (vma->vm_start <= mm->start_stack &&
48714 + vma->vm_end >= mm->start_stack)) {
48715 name = "[stack]";
48716 }
48717 } else {
48718 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48719 struct proc_maps_private *priv = m->private;
48720 struct task_struct *task = priv->task;
48721
48722 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48723 + if (current->exec_id != m->exec_id) {
48724 + gr_log_badprocpid("maps");
48725 + return 0;
48726 + }
48727 +#endif
48728 +
48729 show_map_vma(m, vma);
48730
48731 if (m->count < m->size) /* vma is copied successfully */
48732 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48733 .private = &mss,
48734 };
48735
48736 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48737 + if (current->exec_id != m->exec_id) {
48738 + gr_log_badprocpid("smaps");
48739 + return 0;
48740 + }
48741 +#endif
48742 memset(&mss, 0, sizeof mss);
48743 - mss.vma = vma;
48744 - /* mmap_sem is held in m_start */
48745 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48746 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48747 -
48748 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48749 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48750 +#endif
48751 + mss.vma = vma;
48752 + /* mmap_sem is held in m_start */
48753 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48754 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48756 + }
48757 +#endif
48758 show_map_vma(m, vma);
48759
48760 seq_printf(m,
48761 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48762 "KernelPageSize: %8lu kB\n"
48763 "MMUPageSize: %8lu kB\n"
48764 "Locked: %8lu kB\n",
48765 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48766 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48767 +#else
48768 (vma->vm_end - vma->vm_start) >> 10,
48769 +#endif
48770 mss.resident >> 10,
48771 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48772 mss.shared_clean >> 10,
48773 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48774 int n;
48775 char buffer[50];
48776
48777 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48778 + if (current->exec_id != m->exec_id) {
48779 + gr_log_badprocpid("numa_maps");
48780 + return 0;
48781 + }
48782 +#endif
48783 +
48784 if (!mm)
48785 return 0;
48786
48787 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48788 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48789 mpol_cond_put(pol);
48790
48791 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48792 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48793 +#else
48794 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48795 +#endif
48796
48797 if (file) {
48798 seq_printf(m, " file=");
48799 - seq_path(m, &file->f_path, "\n\t= ");
48800 + seq_path(m, &file->f_path, "\n\t\\= ");
48801 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48802 seq_printf(m, " heap");
48803 } else if (vma->vm_start <= mm->start_stack &&
48804 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48805 index 980de54..2a4db5f 100644
48806 --- a/fs/proc/task_nommu.c
48807 +++ b/fs/proc/task_nommu.c
48808 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48809 else
48810 bytes += kobjsize(mm);
48811
48812 - if (current->fs && current->fs->users > 1)
48813 + if (current->fs && atomic_read(&current->fs->users) > 1)
48814 sbytes += kobjsize(current->fs);
48815 else
48816 bytes += kobjsize(current->fs);
48817 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48818
48819 if (file) {
48820 pad_len_spaces(m, len);
48821 - seq_path(m, &file->f_path, "");
48822 + seq_path(m, &file->f_path, "\n\\");
48823 } else if (mm) {
48824 if (vma->vm_start <= mm->start_stack &&
48825 vma->vm_end >= mm->start_stack) {
48826 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48827 index d67908b..d13f6a6 100644
48828 --- a/fs/quota/netlink.c
48829 +++ b/fs/quota/netlink.c
48830 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48831 void quota_send_warning(short type, unsigned int id, dev_t dev,
48832 const char warntype)
48833 {
48834 - static atomic_t seq;
48835 + static atomic_unchecked_t seq;
48836 struct sk_buff *skb;
48837 void *msg_head;
48838 int ret;
48839 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48840 "VFS: Not enough memory to send quota warning.\n");
48841 return;
48842 }
48843 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48844 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48845 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48846 if (!msg_head) {
48847 printk(KERN_ERR
48848 diff --git a/fs/readdir.c b/fs/readdir.c
48849 index 356f715..c918d38 100644
48850 --- a/fs/readdir.c
48851 +++ b/fs/readdir.c
48852 @@ -17,6 +17,7 @@
48853 #include <linux/security.h>
48854 #include <linux/syscalls.h>
48855 #include <linux/unistd.h>
48856 +#include <linux/namei.h>
48857
48858 #include <asm/uaccess.h>
48859
48860 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48861
48862 struct readdir_callback {
48863 struct old_linux_dirent __user * dirent;
48864 + struct file * file;
48865 int result;
48866 };
48867
48868 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48869 buf->result = -EOVERFLOW;
48870 return -EOVERFLOW;
48871 }
48872 +
48873 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48874 + return 0;
48875 +
48876 buf->result++;
48877 dirent = buf->dirent;
48878 if (!access_ok(VERIFY_WRITE, dirent,
48879 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48880
48881 buf.result = 0;
48882 buf.dirent = dirent;
48883 + buf.file = file;
48884
48885 error = vfs_readdir(file, fillonedir, &buf);
48886 if (buf.result)
48887 @@ -142,6 +149,7 @@ struct linux_dirent {
48888 struct getdents_callback {
48889 struct linux_dirent __user * current_dir;
48890 struct linux_dirent __user * previous;
48891 + struct file * file;
48892 int count;
48893 int error;
48894 };
48895 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48896 buf->error = -EOVERFLOW;
48897 return -EOVERFLOW;
48898 }
48899 +
48900 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48901 + return 0;
48902 +
48903 dirent = buf->previous;
48904 if (dirent) {
48905 if (__put_user(offset, &dirent->d_off))
48906 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48907 buf.previous = NULL;
48908 buf.count = count;
48909 buf.error = 0;
48910 + buf.file = file;
48911
48912 error = vfs_readdir(file, filldir, &buf);
48913 if (error >= 0)
48914 @@ -229,6 +242,7 @@ out:
48915 struct getdents_callback64 {
48916 struct linux_dirent64 __user * current_dir;
48917 struct linux_dirent64 __user * previous;
48918 + struct file *file;
48919 int count;
48920 int error;
48921 };
48922 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48923 buf->error = -EINVAL; /* only used if we fail.. */
48924 if (reclen > buf->count)
48925 return -EINVAL;
48926 +
48927 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48928 + return 0;
48929 +
48930 dirent = buf->previous;
48931 if (dirent) {
48932 if (__put_user(offset, &dirent->d_off))
48933 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48934
48935 buf.current_dir = dirent;
48936 buf.previous = NULL;
48937 + buf.file = file;
48938 buf.count = count;
48939 buf.error = 0;
48940
48941 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48942 error = buf.error;
48943 lastdirent = buf.previous;
48944 if (lastdirent) {
48945 - typeof(lastdirent->d_off) d_off = file->f_pos;
48946 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48947 if (__put_user(d_off, &lastdirent->d_off))
48948 error = -EFAULT;
48949 else
48950 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48951 index 60c0804..d814f98 100644
48952 --- a/fs/reiserfs/do_balan.c
48953 +++ b/fs/reiserfs/do_balan.c
48954 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48955 return;
48956 }
48957
48958 - atomic_inc(&(fs_generation(tb->tb_sb)));
48959 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48960 do_balance_starts(tb);
48961
48962 /* balance leaf returns 0 except if combining L R and S into
48963 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48964 index 7a99811..a7c96c4 100644
48965 --- a/fs/reiserfs/procfs.c
48966 +++ b/fs/reiserfs/procfs.c
48967 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48968 "SMALL_TAILS " : "NO_TAILS ",
48969 replay_only(sb) ? "REPLAY_ONLY " : "",
48970 convert_reiserfs(sb) ? "CONV " : "",
48971 - atomic_read(&r->s_generation_counter),
48972 + atomic_read_unchecked(&r->s_generation_counter),
48973 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48974 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48975 SF(s_good_search_by_key_reada), SF(s_bmaps),
48976 diff --git a/fs/select.c b/fs/select.c
48977 index e782258..3b4b44c 100644
48978 --- a/fs/select.c
48979 +++ b/fs/select.c
48980 @@ -20,6 +20,7 @@
48981 #include <linux/module.h>
48982 #include <linux/slab.h>
48983 #include <linux/poll.h>
48984 +#include <linux/security.h>
48985 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48986 #include <linux/file.h>
48987 #include <linux/fdtable.h>
48988 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48989 struct poll_list *walk = head;
48990 unsigned long todo = nfds;
48991
48992 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48993 if (nfds > rlimit(RLIMIT_NOFILE))
48994 return -EINVAL;
48995
48996 diff --git a/fs/seq_file.c b/fs/seq_file.c
48997 index 4023d6b..ab46c6a 100644
48998 --- a/fs/seq_file.c
48999 +++ b/fs/seq_file.c
49000 @@ -9,6 +9,7 @@
49001 #include <linux/module.h>
49002 #include <linux/seq_file.h>
49003 #include <linux/slab.h>
49004 +#include <linux/sched.h>
49005
49006 #include <asm/uaccess.h>
49007 #include <asm/page.h>
49008 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49009 memset(p, 0, sizeof(*p));
49010 mutex_init(&p->lock);
49011 p->op = op;
49012 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49013 + p->exec_id = current->exec_id;
49014 +#endif
49015
49016 /*
49017 * Wrappers around seq_open(e.g. swaps_open) need to be
49018 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49019 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49020 void *data)
49021 {
49022 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49023 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49024 int res = -ENOMEM;
49025
49026 if (op) {
49027 diff --git a/fs/splice.c b/fs/splice.c
49028 index 1ec0493..d6ab5c2 100644
49029 --- a/fs/splice.c
49030 +++ b/fs/splice.c
49031 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49032 pipe_lock(pipe);
49033
49034 for (;;) {
49035 - if (!pipe->readers) {
49036 + if (!atomic_read(&pipe->readers)) {
49037 send_sig(SIGPIPE, current, 0);
49038 if (!ret)
49039 ret = -EPIPE;
49040 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49041 do_wakeup = 0;
49042 }
49043
49044 - pipe->waiting_writers++;
49045 + atomic_inc(&pipe->waiting_writers);
49046 pipe_wait(pipe);
49047 - pipe->waiting_writers--;
49048 + atomic_dec(&pipe->waiting_writers);
49049 }
49050
49051 pipe_unlock(pipe);
49052 @@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49053 old_fs = get_fs();
49054 set_fs(get_ds());
49055 /* The cast to a user pointer is valid due to the set_fs() */
49056 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49057 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49058 set_fs(old_fs);
49059
49060 return res;
49061 @@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49062 old_fs = get_fs();
49063 set_fs(get_ds());
49064 /* The cast to a user pointer is valid due to the set_fs() */
49065 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49066 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49067 set_fs(old_fs);
49068
49069 return res;
49070 @@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49071 goto err;
49072
49073 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49074 - vec[i].iov_base = (void __user *) page_address(page);
49075 + vec[i].iov_base = (void __force_user *) page_address(page);
49076 vec[i].iov_len = this_len;
49077 spd.pages[i] = page;
49078 spd.nr_pages++;
49079 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49080 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49081 {
49082 while (!pipe->nrbufs) {
49083 - if (!pipe->writers)
49084 + if (!atomic_read(&pipe->writers))
49085 return 0;
49086
49087 - if (!pipe->waiting_writers && sd->num_spliced)
49088 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49089 return 0;
49090
49091 if (sd->flags & SPLICE_F_NONBLOCK)
49092 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49093 * out of the pipe right after the splice_to_pipe(). So set
49094 * PIPE_READERS appropriately.
49095 */
49096 - pipe->readers = 1;
49097 + atomic_set(&pipe->readers, 1);
49098
49099 current->splice_pipe = pipe;
49100 }
49101 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49102 ret = -ERESTARTSYS;
49103 break;
49104 }
49105 - if (!pipe->writers)
49106 + if (!atomic_read(&pipe->writers))
49107 break;
49108 - if (!pipe->waiting_writers) {
49109 + if (!atomic_read(&pipe->waiting_writers)) {
49110 if (flags & SPLICE_F_NONBLOCK) {
49111 ret = -EAGAIN;
49112 break;
49113 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49114 pipe_lock(pipe);
49115
49116 while (pipe->nrbufs >= pipe->buffers) {
49117 - if (!pipe->readers) {
49118 + if (!atomic_read(&pipe->readers)) {
49119 send_sig(SIGPIPE, current, 0);
49120 ret = -EPIPE;
49121 break;
49122 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49123 ret = -ERESTARTSYS;
49124 break;
49125 }
49126 - pipe->waiting_writers++;
49127 + atomic_inc(&pipe->waiting_writers);
49128 pipe_wait(pipe);
49129 - pipe->waiting_writers--;
49130 + atomic_dec(&pipe->waiting_writers);
49131 }
49132
49133 pipe_unlock(pipe);
49134 @@ -1818,14 +1818,14 @@ retry:
49135 pipe_double_lock(ipipe, opipe);
49136
49137 do {
49138 - if (!opipe->readers) {
49139 + if (!atomic_read(&opipe->readers)) {
49140 send_sig(SIGPIPE, current, 0);
49141 if (!ret)
49142 ret = -EPIPE;
49143 break;
49144 }
49145
49146 - if (!ipipe->nrbufs && !ipipe->writers)
49147 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49148 break;
49149
49150 /*
49151 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49152 pipe_double_lock(ipipe, opipe);
49153
49154 do {
49155 - if (!opipe->readers) {
49156 + if (!atomic_read(&opipe->readers)) {
49157 send_sig(SIGPIPE, current, 0);
49158 if (!ret)
49159 ret = -EPIPE;
49160 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49161 * return EAGAIN if we have the potential of some data in the
49162 * future, otherwise just return 0
49163 */
49164 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49165 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49166 ret = -EAGAIN;
49167
49168 pipe_unlock(ipipe);
49169 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49170 index a475983..9c6a1f0 100644
49171 --- a/fs/sysfs/bin.c
49172 +++ b/fs/sysfs/bin.c
49173 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49174 }
49175
49176 static ssize_t
49177 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49178 +static ssize_t
49179 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49180 {
49181 struct bin_buffer *bb = file->private_data;
49182 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49183 index 7fdf6a7..e6cd8ad 100644
49184 --- a/fs/sysfs/dir.c
49185 +++ b/fs/sysfs/dir.c
49186 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49187 struct sysfs_dirent *sd;
49188 int rc;
49189
49190 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49191 + const char *parent_name = parent_sd->s_name;
49192 +
49193 + mode = S_IFDIR | S_IRWXU;
49194 +
49195 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49196 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49197 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49198 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49199 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49200 +#endif
49201 +
49202 /* allocate */
49203 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49204 if (!sd)
49205 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49206 index 00012e3..8392349 100644
49207 --- a/fs/sysfs/file.c
49208 +++ b/fs/sysfs/file.c
49209 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49210
49211 struct sysfs_open_dirent {
49212 atomic_t refcnt;
49213 - atomic_t event;
49214 + atomic_unchecked_t event;
49215 wait_queue_head_t poll;
49216 struct list_head buffers; /* goes through sysfs_buffer.list */
49217 };
49218 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49219 if (!sysfs_get_active(attr_sd))
49220 return -ENODEV;
49221
49222 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49223 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49224 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49225
49226 sysfs_put_active(attr_sd);
49227 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49228 return -ENOMEM;
49229
49230 atomic_set(&new_od->refcnt, 0);
49231 - atomic_set(&new_od->event, 1);
49232 + atomic_set_unchecked(&new_od->event, 1);
49233 init_waitqueue_head(&new_od->poll);
49234 INIT_LIST_HEAD(&new_od->buffers);
49235 goto retry;
49236 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49237
49238 sysfs_put_active(attr_sd);
49239
49240 - if (buffer->event != atomic_read(&od->event))
49241 + if (buffer->event != atomic_read_unchecked(&od->event))
49242 goto trigger;
49243
49244 return DEFAULT_POLLMASK;
49245 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49246
49247 od = sd->s_attr.open;
49248 if (od) {
49249 - atomic_inc(&od->event);
49250 + atomic_inc_unchecked(&od->event);
49251 wake_up_interruptible(&od->poll);
49252 }
49253
49254 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49255 index a7ac78f..02158e1 100644
49256 --- a/fs/sysfs/symlink.c
49257 +++ b/fs/sysfs/symlink.c
49258 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49259
49260 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49261 {
49262 - char *page = nd_get_link(nd);
49263 + const char *page = nd_get_link(nd);
49264 if (!IS_ERR(page))
49265 free_page((unsigned long)page);
49266 }
49267 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49268 index f922cba..062fb02 100644
49269 --- a/fs/ubifs/debug.c
49270 +++ b/fs/ubifs/debug.c
49271 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49272 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49273 * in case of failure.
49274 */
49275 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49276 static int interpret_user_input(const char __user *u, size_t count)
49277 {
49278 size_t buf_size;
49279 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49280 }
49281
49282 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49283 + size_t count, loff_t *ppos) __size_overflow(3);
49284 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49285 size_t count, loff_t *ppos)
49286 {
49287 struct ubifs_info *c = file->private_data;
49288 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49289 index c175b4d..8f36a16 100644
49290 --- a/fs/udf/misc.c
49291 +++ b/fs/udf/misc.c
49292 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49293
49294 u8 udf_tag_checksum(const struct tag *t)
49295 {
49296 - u8 *data = (u8 *)t;
49297 + const u8 *data = (const u8 *)t;
49298 u8 checksum = 0;
49299 int i;
49300 for (i = 0; i < sizeof(struct tag); ++i)
49301 diff --git a/fs/utimes.c b/fs/utimes.c
49302 index ba653f3..06ea4b1 100644
49303 --- a/fs/utimes.c
49304 +++ b/fs/utimes.c
49305 @@ -1,6 +1,7 @@
49306 #include <linux/compiler.h>
49307 #include <linux/file.h>
49308 #include <linux/fs.h>
49309 +#include <linux/security.h>
49310 #include <linux/linkage.h>
49311 #include <linux/mount.h>
49312 #include <linux/namei.h>
49313 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49314 goto mnt_drop_write_and_out;
49315 }
49316 }
49317 +
49318 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49319 + error = -EACCES;
49320 + goto mnt_drop_write_and_out;
49321 + }
49322 +
49323 mutex_lock(&inode->i_mutex);
49324 error = notify_change(path->dentry, &newattrs);
49325 mutex_unlock(&inode->i_mutex);
49326 diff --git a/fs/xattr.c b/fs/xattr.c
49327 index 82f4337..236473c 100644
49328 --- a/fs/xattr.c
49329 +++ b/fs/xattr.c
49330 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49331 * Extended attribute SET operations
49332 */
49333 static long
49334 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49335 +setxattr(struct path *path, const char __user *name, const void __user *value,
49336 size_t size, int flags)
49337 {
49338 int error;
49339 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49340 return PTR_ERR(kvalue);
49341 }
49342
49343 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49344 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49345 + error = -EACCES;
49346 + goto out;
49347 + }
49348 +
49349 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49350 +out:
49351 kfree(kvalue);
49352 return error;
49353 }
49354 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49355 return error;
49356 error = mnt_want_write(path.mnt);
49357 if (!error) {
49358 - error = setxattr(path.dentry, name, value, size, flags);
49359 + error = setxattr(&path, name, value, size, flags);
49360 mnt_drop_write(path.mnt);
49361 }
49362 path_put(&path);
49363 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49364 return error;
49365 error = mnt_want_write(path.mnt);
49366 if (!error) {
49367 - error = setxattr(path.dentry, name, value, size, flags);
49368 + error = setxattr(&path, name, value, size, flags);
49369 mnt_drop_write(path.mnt);
49370 }
49371 path_put(&path);
49372 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49373 const void __user *,value, size_t, size, int, flags)
49374 {
49375 struct file *f;
49376 - struct dentry *dentry;
49377 int error = -EBADF;
49378
49379 f = fget(fd);
49380 if (!f)
49381 return error;
49382 - dentry = f->f_path.dentry;
49383 - audit_inode(NULL, dentry);
49384 + audit_inode(NULL, f->f_path.dentry);
49385 error = mnt_want_write_file(f);
49386 if (!error) {
49387 - error = setxattr(dentry, name, value, size, flags);
49388 + error = setxattr(&f->f_path, name, value, size, flags);
49389 mnt_drop_write_file(f);
49390 }
49391 fput(f);
49392 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49393 index 8d5a506..7f62712 100644
49394 --- a/fs/xattr_acl.c
49395 +++ b/fs/xattr_acl.c
49396 @@ -17,8 +17,8 @@
49397 struct posix_acl *
49398 posix_acl_from_xattr(const void *value, size_t size)
49399 {
49400 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49401 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49402 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49403 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49404 int count;
49405 struct posix_acl *acl;
49406 struct posix_acl_entry *acl_e;
49407 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49408 index 188ef2f..adcf864 100644
49409 --- a/fs/xfs/xfs_bmap.c
49410 +++ b/fs/xfs/xfs_bmap.c
49411 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49412 int nmap,
49413 int ret_nmap);
49414 #else
49415 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49416 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49417 #endif /* DEBUG */
49418
49419 STATIC int
49420 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49421 index 79d05e8..e3e5861 100644
49422 --- a/fs/xfs/xfs_dir2_sf.c
49423 +++ b/fs/xfs/xfs_dir2_sf.c
49424 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49425 }
49426
49427 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49428 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49429 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49430 + char name[sfep->namelen];
49431 + memcpy(name, sfep->name, sfep->namelen);
49432 + if (filldir(dirent, name, sfep->namelen,
49433 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49434 + *offset = off & 0x7fffffff;
49435 + return 0;
49436 + }
49437 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49438 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49439 *offset = off & 0x7fffffff;
49440 return 0;
49441 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49442 index 76f3ca5..f57f712 100644
49443 --- a/fs/xfs/xfs_ioctl.c
49444 +++ b/fs/xfs/xfs_ioctl.c
49445 @@ -128,7 +128,7 @@ xfs_find_handle(
49446 }
49447
49448 error = -EFAULT;
49449 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49450 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49451 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49452 goto out_put;
49453
49454 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49455 index ab30253..4d86958 100644
49456 --- a/fs/xfs/xfs_iops.c
49457 +++ b/fs/xfs/xfs_iops.c
49458 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49459 struct nameidata *nd,
49460 void *p)
49461 {
49462 - char *s = nd_get_link(nd);
49463 + const char *s = nd_get_link(nd);
49464
49465 if (!IS_ERR(s))
49466 kfree(s);
49467 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49468 new file mode 100644
49469 index 0000000..4089e05
49470 --- /dev/null
49471 +++ b/grsecurity/Kconfig
49472 @@ -0,0 +1,1078 @@
49473 +#
49474 +# grecurity configuration
49475 +#
49476 +
49477 +menu "Grsecurity"
49478 +
49479 +config GRKERNSEC
49480 + bool "Grsecurity"
49481 + select CRYPTO
49482 + select CRYPTO_SHA256
49483 + help
49484 + If you say Y here, you will be able to configure many features
49485 + that will enhance the security of your system. It is highly
49486 + recommended that you say Y here and read through the help
49487 + for each option so that you fully understand the features and
49488 + can evaluate their usefulness for your machine.
49489 +
49490 +choice
49491 + prompt "Security Level"
49492 + depends on GRKERNSEC
49493 + default GRKERNSEC_CUSTOM
49494 +
49495 +config GRKERNSEC_LOW
49496 + bool "Low"
49497 + select GRKERNSEC_LINK
49498 + select GRKERNSEC_FIFO
49499 + select GRKERNSEC_RANDNET
49500 + select GRKERNSEC_DMESG
49501 + select GRKERNSEC_CHROOT
49502 + select GRKERNSEC_CHROOT_CHDIR
49503 +
49504 + help
49505 + If you choose this option, several of the grsecurity options will
49506 + be enabled that will give you greater protection against a number
49507 + of attacks, while assuring that none of your software will have any
49508 + conflicts with the additional security measures. If you run a lot
49509 + of unusual software, or you are having problems with the higher
49510 + security levels, you should say Y here. With this option, the
49511 + following features are enabled:
49512 +
49513 + - Linking restrictions
49514 + - FIFO restrictions
49515 + - Restricted dmesg
49516 + - Enforced chdir("/") on chroot
49517 + - Runtime module disabling
49518 +
49519 +config GRKERNSEC_MEDIUM
49520 + bool "Medium"
49521 + select PAX
49522 + select PAX_EI_PAX
49523 + select PAX_PT_PAX_FLAGS
49524 + select PAX_HAVE_ACL_FLAGS
49525 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49526 + select GRKERNSEC_CHROOT
49527 + select GRKERNSEC_CHROOT_SYSCTL
49528 + select GRKERNSEC_LINK
49529 + select GRKERNSEC_FIFO
49530 + select GRKERNSEC_DMESG
49531 + select GRKERNSEC_RANDNET
49532 + select GRKERNSEC_FORKFAIL
49533 + select GRKERNSEC_TIME
49534 + select GRKERNSEC_SIGNAL
49535 + select GRKERNSEC_CHROOT
49536 + select GRKERNSEC_CHROOT_UNIX
49537 + select GRKERNSEC_CHROOT_MOUNT
49538 + select GRKERNSEC_CHROOT_PIVOT
49539 + select GRKERNSEC_CHROOT_DOUBLE
49540 + select GRKERNSEC_CHROOT_CHDIR
49541 + select GRKERNSEC_CHROOT_MKNOD
49542 + select GRKERNSEC_PROC
49543 + select GRKERNSEC_PROC_USERGROUP
49544 + select PAX_RANDUSTACK
49545 + select PAX_ASLR
49546 + select PAX_RANDMMAP
49547 + select PAX_REFCOUNT if (X86 || SPARC64)
49548 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49549 +
49550 + help
49551 + If you say Y here, several features in addition to those included
49552 + in the low additional security level will be enabled. These
49553 + features provide even more security to your system, though in rare
49554 + cases they may be incompatible with very old or poorly written
49555 + software. If you enable this option, make sure that your auth
49556 + service (identd) is running as gid 1001. With this option,
49557 + the following features (in addition to those provided in the
49558 + low additional security level) will be enabled:
49559 +
49560 + - Failed fork logging
49561 + - Time change logging
49562 + - Signal logging
49563 + - Deny mounts in chroot
49564 + - Deny double chrooting
49565 + - Deny sysctl writes in chroot
49566 + - Deny mknod in chroot
49567 + - Deny access to abstract AF_UNIX sockets out of chroot
49568 + - Deny pivot_root in chroot
49569 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49570 + - /proc restrictions with special GID set to 10 (usually wheel)
49571 + - Address Space Layout Randomization (ASLR)
49572 + - Prevent exploitation of most refcount overflows
49573 + - Bounds checking of copying between the kernel and userland
49574 +
49575 +config GRKERNSEC_HIGH
49576 + bool "High"
49577 + select GRKERNSEC_LINK
49578 + select GRKERNSEC_FIFO
49579 + select GRKERNSEC_DMESG
49580 + select GRKERNSEC_FORKFAIL
49581 + select GRKERNSEC_TIME
49582 + select GRKERNSEC_SIGNAL
49583 + select GRKERNSEC_CHROOT
49584 + select GRKERNSEC_CHROOT_SHMAT
49585 + select GRKERNSEC_CHROOT_UNIX
49586 + select GRKERNSEC_CHROOT_MOUNT
49587 + select GRKERNSEC_CHROOT_FCHDIR
49588 + select GRKERNSEC_CHROOT_PIVOT
49589 + select GRKERNSEC_CHROOT_DOUBLE
49590 + select GRKERNSEC_CHROOT_CHDIR
49591 + select GRKERNSEC_CHROOT_MKNOD
49592 + select GRKERNSEC_CHROOT_CAPS
49593 + select GRKERNSEC_CHROOT_SYSCTL
49594 + select GRKERNSEC_CHROOT_FINDTASK
49595 + select GRKERNSEC_SYSFS_RESTRICT
49596 + select GRKERNSEC_PROC
49597 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49598 + select GRKERNSEC_HIDESYM
49599 + select GRKERNSEC_BRUTE
49600 + select GRKERNSEC_PROC_USERGROUP
49601 + select GRKERNSEC_KMEM
49602 + select GRKERNSEC_RESLOG
49603 + select GRKERNSEC_RANDNET
49604 + select GRKERNSEC_PROC_ADD
49605 + select GRKERNSEC_CHROOT_CHMOD
49606 + select GRKERNSEC_CHROOT_NICE
49607 + select GRKERNSEC_SETXID
49608 + select GRKERNSEC_AUDIT_MOUNT
49609 + select GRKERNSEC_MODHARDEN if (MODULES)
49610 + select GRKERNSEC_HARDEN_PTRACE
49611 + select GRKERNSEC_PTRACE_READEXEC
49612 + select GRKERNSEC_VM86 if (X86_32)
49613 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49614 + select PAX
49615 + select PAX_RANDUSTACK
49616 + select PAX_ASLR
49617 + select PAX_RANDMMAP
49618 + select PAX_NOEXEC
49619 + select PAX_MPROTECT
49620 + select PAX_EI_PAX
49621 + select PAX_PT_PAX_FLAGS
49622 + select PAX_HAVE_ACL_FLAGS
49623 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49624 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49625 + select PAX_RANDKSTACK if (X86_TSC && X86)
49626 + select PAX_SEGMEXEC if (X86_32)
49627 + select PAX_PAGEEXEC
49628 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49629 + select PAX_EMUTRAMP if (PARISC)
49630 + select PAX_EMUSIGRT if (PARISC)
49631 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49632 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49633 + select PAX_REFCOUNT if (X86 || SPARC64)
49634 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49635 + help
49636 + If you say Y here, many of the features of grsecurity will be
49637 + enabled, which will protect you against many kinds of attacks
49638 + against your system. The heightened security comes at a cost
49639 + of an increased chance of incompatibilities with rare software
49640 + on your machine. Since this security level enables PaX, you should
49641 + view <http://pax.grsecurity.net> and read about the PaX
49642 + project. While you are there, download chpax and run it on
49643 + binaries that cause problems with PaX. Also remember that
49644 + since the /proc restrictions are enabled, you must run your
49645 + identd as gid 1001. This security level enables the following
49646 + features in addition to those listed in the low and medium
49647 + security levels:
49648 +
49649 + - Additional /proc restrictions
49650 + - Chmod restrictions in chroot
49651 + - No signals, ptrace, or viewing of processes outside of chroot
49652 + - Capability restrictions in chroot
49653 + - Deny fchdir out of chroot
49654 + - Priority restrictions in chroot
49655 + - Segmentation-based implementation of PaX
49656 + - Mprotect restrictions
49657 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49658 + - Kernel stack randomization
49659 + - Mount/unmount/remount logging
49660 + - Kernel symbol hiding
49661 + - Hardening of module auto-loading
49662 + - Ptrace restrictions
49663 + - Restricted vm86 mode
49664 + - Restricted sysfs/debugfs
49665 + - Active kernel exploit response
49666 +
49667 +config GRKERNSEC_CUSTOM
49668 + bool "Custom"
49669 + help
49670 + If you say Y here, you will be able to configure every grsecurity
49671 + option, which allows you to enable many more features that aren't
49672 + covered in the basic security levels. These additional features
49673 + include TPE, socket restrictions, and the sysctl system for
49674 + grsecurity. It is advised that you read through the help for
49675 + each option to determine its usefulness in your situation.
49676 +
49677 +endchoice
49678 +
49679 +menu "Memory Protections"
49680 +depends on GRKERNSEC
49681 +
49682 +config GRKERNSEC_KMEM
49683 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49684 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49685 + help
49686 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49687 + be written to or read from to modify or leak the contents of the running
49688 + kernel. /dev/port will also not be allowed to be opened. If you have module
49689 + support disabled, enabling this will close up four ways that are
49690 + currently used to insert malicious code into the running kernel.
49691 + Even with all these features enabled, we still highly recommend that
49692 + you use the RBAC system, as it is still possible for an attacker to
49693 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49694 + If you are not using XFree86, you may be able to stop this additional
49695 + case by enabling the 'Disable privileged I/O' option. Though nothing
49696 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49697 + but only to video memory, which is the only writing we allow in this
49698 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49699 + not be allowed to mprotect it with PROT_WRITE later.
49700 + It is highly recommended that you say Y here if you meet all the
49701 + conditions above.
49702 +
49703 +config GRKERNSEC_VM86
49704 + bool "Restrict VM86 mode"
49705 + depends on X86_32
49706 +
49707 + help
49708 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49709 + make use of a special execution mode on 32bit x86 processors called
49710 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49711 + video cards and will still work with this option enabled. The purpose
49712 + of the option is to prevent exploitation of emulation errors in
49713 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49714 + Nearly all users should be able to enable this option.
49715 +
49716 +config GRKERNSEC_IO
49717 + bool "Disable privileged I/O"
49718 + depends on X86
49719 + select RTC_CLASS
49720 + select RTC_INTF_DEV
49721 + select RTC_DRV_CMOS
49722 +
49723 + help
49724 + If you say Y here, all ioperm and iopl calls will return an error.
49725 + Ioperm and iopl can be used to modify the running kernel.
49726 + Unfortunately, some programs need this access to operate properly,
49727 + the most notable of which are XFree86 and hwclock. hwclock can be
49728 + remedied by having RTC support in the kernel, so real-time
49729 + clock support is enabled if this option is enabled, to ensure
49730 + that hwclock operates correctly. XFree86 still will not
49731 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49732 + IF YOU USE XFree86. If you use XFree86 and you still want to
49733 + protect your kernel against modification, use the RBAC system.
49734 +
49735 +config GRKERNSEC_PROC_MEMMAP
49736 + bool "Harden ASLR against information leaks and entropy reduction"
49737 + default y if (PAX_NOEXEC || PAX_ASLR)
49738 + depends on PAX_NOEXEC || PAX_ASLR
49739 + help
49740 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49741 + give no information about the addresses of its mappings if
49742 + PaX features that rely on random addresses are enabled on the task.
49743 + In addition to sanitizing this information and disabling other
49744 + dangerous sources of information, this option causes reads of sensitive
49745 + /proc/<pid> entries where the file descriptor was opened in a different
49746 + task than the one performing the read. Such attempts are logged.
49747 + This option also limits argv/env strings for suid/sgid binaries
49748 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49749 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49750 + binaries to prevent alternative mmap layouts from being abused.
49751 +
49752 + If you use PaX it is essential that you say Y here as it closes up
49753 + several holes that make full ASLR useless locally.
49754 +
49755 +config GRKERNSEC_BRUTE
49756 + bool "Deter exploit bruteforcing"
49757 + help
49758 + If you say Y here, attempts to bruteforce exploits against forking
49759 + daemons such as apache or sshd, as well as against suid/sgid binaries
49760 + will be deterred. When a child of a forking daemon is killed by PaX
49761 + or crashes due to an illegal instruction or other suspicious signal,
49762 + the parent process will be delayed 30 seconds upon every subsequent
49763 + fork until the administrator is able to assess the situation and
49764 + restart the daemon.
49765 + In the suid/sgid case, the attempt is logged, the user has all their
49766 + processes terminated, and they are prevented from executing any further
49767 + processes for 15 minutes.
49768 + It is recommended that you also enable signal logging in the auditing
49769 + section so that logs are generated when a process triggers a suspicious
49770 + signal.
49771 + If the sysctl option is enabled, a sysctl option with name
49772 + "deter_bruteforce" is created.
49773 +
49774 +
49775 +config GRKERNSEC_MODHARDEN
49776 + bool "Harden module auto-loading"
49777 + depends on MODULES
49778 + help
49779 + If you say Y here, module auto-loading in response to use of some
49780 + feature implemented by an unloaded module will be restricted to
49781 + root users. Enabling this option helps defend against attacks
49782 + by unprivileged users who abuse the auto-loading behavior to
49783 + cause a vulnerable module to load that is then exploited.
49784 +
49785 + If this option prevents a legitimate use of auto-loading for a
49786 + non-root user, the administrator can execute modprobe manually
49787 + with the exact name of the module mentioned in the alert log.
49788 + Alternatively, the administrator can add the module to the list
49789 + of modules loaded at boot by modifying init scripts.
49790 +
49791 + Modification of init scripts will most likely be needed on
49792 + Ubuntu servers with encrypted home directory support enabled,
49793 + as the first non-root user logging in will cause the ecb(aes),
49794 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49795 +
49796 +config GRKERNSEC_HIDESYM
49797 + bool "Hide kernel symbols"
49798 + help
49799 + If you say Y here, getting information on loaded modules, and
49800 + displaying all kernel symbols through a syscall will be restricted
49801 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49802 + /proc/kallsyms will be restricted to the root user. The RBAC
49803 + system can hide that entry even from root.
49804 +
49805 + This option also prevents leaking of kernel addresses through
49806 + several /proc entries.
49807 +
49808 + Note that this option is only effective provided the following
49809 + conditions are met:
49810 + 1) The kernel using grsecurity is not precompiled by some distribution
49811 + 2) You have also enabled GRKERNSEC_DMESG
49812 + 3) You are using the RBAC system and hiding other files such as your
49813 + kernel image and System.map. Alternatively, enabling this option
49814 + causes the permissions on /boot, /lib/modules, and the kernel
49815 + source directory to change at compile time to prevent
49816 + reading by non-root users.
49817 + If the above conditions are met, this option will aid in providing a
49818 + useful protection against local kernel exploitation of overflows
49819 + and arbitrary read/write vulnerabilities.
49820 +
49821 +config GRKERNSEC_KERN_LOCKOUT
49822 + bool "Active kernel exploit response"
49823 + depends on X86 || ARM || PPC || SPARC
49824 + help
49825 + If you say Y here, when a PaX alert is triggered due to suspicious
49826 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49827 + or an OOPs occurs due to bad memory accesses, instead of just
49828 + terminating the offending process (and potentially allowing
49829 + a subsequent exploit from the same user), we will take one of two
49830 + actions:
49831 + If the user was root, we will panic the system
49832 + If the user was non-root, we will log the attempt, terminate
49833 + all processes owned by the user, then prevent them from creating
49834 + any new processes until the system is restarted
49835 + This deters repeated kernel exploitation/bruteforcing attempts
49836 + and is useful for later forensics.
49837 +
49838 +endmenu
49839 +menu "Role Based Access Control Options"
49840 +depends on GRKERNSEC
49841 +
49842 +config GRKERNSEC_RBAC_DEBUG
49843 + bool
49844 +
49845 +config GRKERNSEC_NO_RBAC
49846 + bool "Disable RBAC system"
49847 + help
49848 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49849 + preventing the RBAC system from being enabled. You should only say Y
49850 + here if you have no intention of using the RBAC system, so as to prevent
49851 + an attacker with root access from misusing the RBAC system to hide files
49852 + and processes when loadable module support and /dev/[k]mem have been
49853 + locked down.
49854 +
49855 +config GRKERNSEC_ACL_HIDEKERN
49856 + bool "Hide kernel processes"
49857 + help
49858 + If you say Y here, all kernel threads will be hidden to all
49859 + processes but those whose subject has the "view hidden processes"
49860 + flag.
49861 +
49862 +config GRKERNSEC_ACL_MAXTRIES
49863 + int "Maximum tries before password lockout"
49864 + default 3
49865 + help
49866 + This option enforces the maximum number of times a user can attempt
49867 + to authorize themselves with the grsecurity RBAC system before being
49868 + denied the ability to attempt authorization again for a specified time.
49869 + The lower the number, the harder it will be to brute-force a password.
49870 +
49871 +config GRKERNSEC_ACL_TIMEOUT
49872 + int "Time to wait after max password tries, in seconds"
49873 + default 30
49874 + help
49875 + This option specifies the time the user must wait after attempting to
49876 + authorize to the RBAC system with the maximum number of invalid
49877 + passwords. The higher the number, the harder it will be to brute-force
49878 + a password.
49879 +
49880 +endmenu
49881 +menu "Filesystem Protections"
49882 +depends on GRKERNSEC
49883 +
49884 +config GRKERNSEC_PROC
49885 + bool "Proc restrictions"
49886 + help
49887 + If you say Y here, the permissions of the /proc filesystem
49888 + will be altered to enhance system security and privacy. You MUST
49889 + choose either a user only restriction or a user and group restriction.
49890 + Depending upon the option you choose, you can either restrict users to
49891 + see only the processes they themselves run, or choose a group that can
49892 + view all processes and files normally restricted to root if you choose
49893 + the "restrict to user only" option. NOTE: If you're running identd or
49894 + ntpd as a non-root user, you will have to run it as the group you
49895 + specify here.
49896 +
49897 +config GRKERNSEC_PROC_USER
49898 + bool "Restrict /proc to user only"
49899 + depends on GRKERNSEC_PROC
49900 + help
49901 + If you say Y here, non-root users will only be able to view their own
49902 + processes, and restricts them from viewing network-related information,
49903 + and viewing kernel symbol and module information.
49904 +
49905 +config GRKERNSEC_PROC_USERGROUP
49906 + bool "Allow special group"
49907 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49908 + help
49909 + If you say Y here, you will be able to select a group that will be
49910 + able to view all processes and network-related information. If you've
49911 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49912 + remain hidden. This option is useful if you want to run identd as
49913 + a non-root user.
49914 +
49915 +config GRKERNSEC_PROC_GID
49916 + int "GID for special group"
49917 + depends on GRKERNSEC_PROC_USERGROUP
49918 + default 1001
49919 +
49920 +config GRKERNSEC_PROC_ADD
49921 + bool "Additional restrictions"
49922 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49923 + help
49924 + If you say Y here, additional restrictions will be placed on
49925 + /proc that keep normal users from viewing device information and
49926 + slabinfo information that could be useful for exploits.
49927 +
49928 +config GRKERNSEC_LINK
49929 + bool "Linking restrictions"
49930 + help
49931 + If you say Y here, /tmp race exploits will be prevented, since users
49932 + will no longer be able to follow symlinks owned by other users in
49933 + world-writable +t directories (e.g. /tmp), unless the owner of the
49934 + symlink is the owner of the directory. users will also not be
49935 + able to hardlink to files they do not own. If the sysctl option is
49936 + enabled, a sysctl option with name "linking_restrictions" is created.
49937 +
49938 +config GRKERNSEC_FIFO
49939 + bool "FIFO restrictions"
49940 + help
49941 + If you say Y here, users will not be able to write to FIFOs they don't
49942 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49943 + the FIFO is the same owner of the directory it's held in. If the sysctl
49944 + option is enabled, a sysctl option with name "fifo_restrictions" is
49945 + created.
49946 +
49947 +config GRKERNSEC_SYSFS_RESTRICT
49948 + bool "Sysfs/debugfs restriction"
49949 + depends on SYSFS
49950 + help
49951 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49952 + any filesystem normally mounted under it (e.g. debugfs) will be
49953 + mostly accessible only by root. These filesystems generally provide access
49954 + to hardware and debug information that isn't appropriate for unprivileged
49955 + users of the system. Sysfs and debugfs have also become a large source
49956 + of new vulnerabilities, ranging from infoleaks to local compromise.
49957 + There has been very little oversight with an eye toward security involved
49958 + in adding new exporters of information to these filesystems, so their
49959 + use is discouraged.
49960 + For reasons of compatibility, a few directories have been whitelisted
49961 + for access by non-root users:
49962 + /sys/fs/selinux
49963 + /sys/fs/fuse
49964 + /sys/devices/system/cpu
49965 +
49966 +config GRKERNSEC_ROFS
49967 + bool "Runtime read-only mount protection"
49968 + help
49969 + If you say Y here, a sysctl option with name "romount_protect" will
49970 + be created. By setting this option to 1 at runtime, filesystems
49971 + will be protected in the following ways:
49972 + * No new writable mounts will be allowed
49973 + * Existing read-only mounts won't be able to be remounted read/write
49974 + * Write operations will be denied on all block devices
49975 + This option acts independently of grsec_lock: once it is set to 1,
49976 + it cannot be turned off. Therefore, please be mindful of the resulting
49977 + behavior if this option is enabled in an init script on a read-only
49978 + filesystem. This feature is mainly intended for secure embedded systems.
49979 +
49980 +config GRKERNSEC_CHROOT
49981 + bool "Chroot jail restrictions"
49982 + help
49983 + If you say Y here, you will be able to choose several options that will
49984 + make breaking out of a chrooted jail much more difficult. If you
49985 + encounter no software incompatibilities with the following options, it
49986 + is recommended that you enable each one.
49987 +
49988 +config GRKERNSEC_CHROOT_MOUNT
49989 + bool "Deny mounts"
49990 + depends on GRKERNSEC_CHROOT
49991 + help
49992 + If you say Y here, processes inside a chroot will not be able to
49993 + mount or remount filesystems. If the sysctl option is enabled, a
49994 + sysctl option with name "chroot_deny_mount" is created.
49995 +
49996 +config GRKERNSEC_CHROOT_DOUBLE
49997 + bool "Deny double-chroots"
49998 + depends on GRKERNSEC_CHROOT
49999 + help
50000 + If you say Y here, processes inside a chroot will not be able to chroot
50001 + again outside the chroot. This is a widely used method of breaking
50002 + out of a chroot jail and should not be allowed. If the sysctl
50003 + option is enabled, a sysctl option with name
50004 + "chroot_deny_chroot" is created.
50005 +
50006 +config GRKERNSEC_CHROOT_PIVOT
50007 + bool "Deny pivot_root in chroot"
50008 + depends on GRKERNSEC_CHROOT
50009 + help
50010 + If you say Y here, processes inside a chroot will not be able to use
50011 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50012 + works similar to chroot in that it changes the root filesystem. This
50013 + function could be misused in a chrooted process to attempt to break out
50014 + of the chroot, and therefore should not be allowed. If the sysctl
50015 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50016 + created.
50017 +
50018 +config GRKERNSEC_CHROOT_CHDIR
50019 + bool "Enforce chdir(\"/\") on all chroots"
50020 + depends on GRKERNSEC_CHROOT
50021 + help
50022 + If you say Y here, the current working directory of all newly-chrooted
50023 + applications will be set to the the root directory of the chroot.
50024 + The man page on chroot(2) states:
50025 + Note that this call does not change the current working
50026 + directory, so that `.' can be outside the tree rooted at
50027 + `/'. In particular, the super-user can escape from a
50028 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50029 +
50030 + It is recommended that you say Y here, since it's not known to break
50031 + any software. If the sysctl option is enabled, a sysctl option with
50032 + name "chroot_enforce_chdir" is created.
50033 +
50034 +config GRKERNSEC_CHROOT_CHMOD
50035 + bool "Deny (f)chmod +s"
50036 + depends on GRKERNSEC_CHROOT
50037 + help
50038 + If you say Y here, processes inside a chroot will not be able to chmod
50039 + or fchmod files to make them have suid or sgid bits. This protects
50040 + against another published method of breaking a chroot. If the sysctl
50041 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50042 + created.
50043 +
50044 +config GRKERNSEC_CHROOT_FCHDIR
50045 + bool "Deny fchdir out of chroot"
50046 + depends on GRKERNSEC_CHROOT
50047 + help
50048 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50049 + to a file descriptor of the chrooting process that points to a directory
50050 + outside the filesystem will be stopped. If the sysctl option
50051 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50052 +
50053 +config GRKERNSEC_CHROOT_MKNOD
50054 + bool "Deny mknod"
50055 + depends on GRKERNSEC_CHROOT
50056 + help
50057 + If you say Y here, processes inside a chroot will not be allowed to
50058 + mknod. The problem with using mknod inside a chroot is that it
50059 + would allow an attacker to create a device entry that is the same
50060 + as one on the physical root of your system, which could range from
50061 + anything from the console device to a device for your harddrive (which
50062 + they could then use to wipe the drive or steal data). It is recommended
50063 + that you say Y here, unless you run into software incompatibilities.
50064 + If the sysctl option is enabled, a sysctl option with name
50065 + "chroot_deny_mknod" is created.
50066 +
50067 +config GRKERNSEC_CHROOT_SHMAT
50068 + bool "Deny shmat() out of chroot"
50069 + depends on GRKERNSEC_CHROOT
50070 + help
50071 + If you say Y here, processes inside a chroot will not be able to attach
50072 + to shared memory segments that were created outside of the chroot jail.
50073 + It is recommended that you say Y here. If the sysctl option is enabled,
50074 + a sysctl option with name "chroot_deny_shmat" is created.
50075 +
50076 +config GRKERNSEC_CHROOT_UNIX
50077 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50078 + depends on GRKERNSEC_CHROOT
50079 + help
50080 + If you say Y here, processes inside a chroot will not be able to
50081 + connect to abstract (meaning not belonging to a filesystem) Unix
50082 + domain sockets that were bound outside of a chroot. It is recommended
50083 + that you say Y here. If the sysctl option is enabled, a sysctl option
50084 + with name "chroot_deny_unix" is created.
50085 +
50086 +config GRKERNSEC_CHROOT_FINDTASK
50087 + bool "Protect outside processes"
50088 + depends on GRKERNSEC_CHROOT
50089 + help
50090 + If you say Y here, processes inside a chroot will not be able to
50091 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50092 + getsid, or view any process outside of the chroot. If the sysctl
50093 + option is enabled, a sysctl option with name "chroot_findtask" is
50094 + created.
50095 +
50096 +config GRKERNSEC_CHROOT_NICE
50097 + bool "Restrict priority changes"
50098 + depends on GRKERNSEC_CHROOT
50099 + help
50100 + If you say Y here, processes inside a chroot will not be able to raise
50101 + the priority of processes in the chroot, or alter the priority of
50102 + processes outside the chroot. This provides more security than simply
50103 + removing CAP_SYS_NICE from the process' capability set. If the
50104 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50105 + is created.
50106 +
50107 +config GRKERNSEC_CHROOT_SYSCTL
50108 + bool "Deny sysctl writes"
50109 + depends on GRKERNSEC_CHROOT
50110 + help
50111 + If you say Y here, an attacker in a chroot will not be able to
50112 + write to sysctl entries, either by sysctl(2) or through a /proc
50113 + interface. It is strongly recommended that you say Y here. If the
50114 + sysctl option is enabled, a sysctl option with name
50115 + "chroot_deny_sysctl" is created.
50116 +
50117 +config GRKERNSEC_CHROOT_CAPS
50118 + bool "Capability restrictions"
50119 + depends on GRKERNSEC_CHROOT
50120 + help
50121 + If you say Y here, the capabilities on all processes within a
50122 + chroot jail will be lowered to stop module insertion, raw i/o,
50123 + system and net admin tasks, rebooting the system, modifying immutable
50124 + files, modifying IPC owned by another, and changing the system time.
50125 + This is left an option because it can break some apps. Disable this
50126 + if your chrooted apps are having problems performing those kinds of
50127 + tasks. If the sysctl option is enabled, a sysctl option with
50128 + name "chroot_caps" is created.
50129 +
50130 +endmenu
50131 +menu "Kernel Auditing"
50132 +depends on GRKERNSEC
50133 +
50134 +config GRKERNSEC_AUDIT_GROUP
50135 + bool "Single group for auditing"
50136 + help
50137 + If you say Y here, the exec, chdir, and (un)mount logging features
50138 + will only operate on a group you specify. This option is recommended
50139 + if you only want to watch certain users instead of having a large
50140 + amount of logs from the entire system. If the sysctl option is enabled,
50141 + a sysctl option with name "audit_group" is created.
50142 +
50143 +config GRKERNSEC_AUDIT_GID
50144 + int "GID for auditing"
50145 + depends on GRKERNSEC_AUDIT_GROUP
50146 + default 1007
50147 +
50148 +config GRKERNSEC_EXECLOG
50149 + bool "Exec logging"
50150 + help
50151 + If you say Y here, all execve() calls will be logged (since the
50152 + other exec*() calls are frontends to execve(), all execution
50153 + will be logged). Useful for shell-servers that like to keep track
50154 + of their users. If the sysctl option is enabled, a sysctl option with
50155 + name "exec_logging" is created.
50156 + WARNING: This option when enabled will produce a LOT of logs, especially
50157 + on an active system.
50158 +
50159 +config GRKERNSEC_RESLOG
50160 + bool "Resource logging"
50161 + help
50162 + If you say Y here, all attempts to overstep resource limits will
50163 + be logged with the resource name, the requested size, and the current
50164 + limit. It is highly recommended that you say Y here. If the sysctl
50165 + option is enabled, a sysctl option with name "resource_logging" is
50166 + created. If the RBAC system is enabled, the sysctl value is ignored.
50167 +
50168 +config GRKERNSEC_CHROOT_EXECLOG
50169 + bool "Log execs within chroot"
50170 + help
50171 + If you say Y here, all executions inside a chroot jail will be logged
50172 + to syslog. This can cause a large amount of logs if certain
50173 + applications (eg. djb's daemontools) are installed on the system, and
50174 + is therefore left as an option. If the sysctl option is enabled, a
50175 + sysctl option with name "chroot_execlog" is created.
50176 +
50177 +config GRKERNSEC_AUDIT_PTRACE
50178 + bool "Ptrace logging"
50179 + help
50180 + If you say Y here, all attempts to attach to a process via ptrace
50181 + will be logged. If the sysctl option is enabled, a sysctl option
50182 + with name "audit_ptrace" is created.
50183 +
50184 +config GRKERNSEC_AUDIT_CHDIR
50185 + bool "Chdir logging"
50186 + help
50187 + If you say Y here, all chdir() calls will be logged. If the sysctl
50188 + option is enabled, a sysctl option with name "audit_chdir" is created.
50189 +
50190 +config GRKERNSEC_AUDIT_MOUNT
50191 + bool "(Un)Mount logging"
50192 + help
50193 + If you say Y here, all mounts and unmounts will be logged. If the
50194 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50195 + created.
50196 +
50197 +config GRKERNSEC_SIGNAL
50198 + bool "Signal logging"
50199 + help
50200 + If you say Y here, certain important signals will be logged, such as
50201 + SIGSEGV, which will as a result inform you of when a error in a program
50202 + occurred, which in some cases could mean a possible exploit attempt.
50203 + If the sysctl option is enabled, a sysctl option with name
50204 + "signal_logging" is created.
50205 +
50206 +config GRKERNSEC_FORKFAIL
50207 + bool "Fork failure logging"
50208 + help
50209 + If you say Y here, all failed fork() attempts will be logged.
50210 + This could suggest a fork bomb, or someone attempting to overstep
50211 + their process limit. If the sysctl option is enabled, a sysctl option
50212 + with name "forkfail_logging" is created.
50213 +
50214 +config GRKERNSEC_TIME
50215 + bool "Time change logging"
50216 + help
50217 + If you say Y here, any changes of the system clock will be logged.
50218 + If the sysctl option is enabled, a sysctl option with name
50219 + "timechange_logging" is created.
50220 +
50221 +config GRKERNSEC_PROC_IPADDR
50222 + bool "/proc/<pid>/ipaddr support"
50223 + help
50224 + If you say Y here, a new entry will be added to each /proc/<pid>
50225 + directory that contains the IP address of the person using the task.
50226 + The IP is carried across local TCP and AF_UNIX stream sockets.
50227 + This information can be useful for IDS/IPSes to perform remote response
50228 + to a local attack. The entry is readable by only the owner of the
50229 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50230 + the RBAC system), and thus does not create privacy concerns.
50231 +
50232 +config GRKERNSEC_RWXMAP_LOG
50233 + bool 'Denied RWX mmap/mprotect logging'
50234 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50235 + help
50236 + If you say Y here, calls to mmap() and mprotect() with explicit
50237 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50238 + denied by the PAX_MPROTECT feature. If the sysctl option is
50239 + enabled, a sysctl option with name "rwxmap_logging" is created.
50240 +
50241 +config GRKERNSEC_AUDIT_TEXTREL
50242 + bool 'ELF text relocations logging (READ HELP)'
50243 + depends on PAX_MPROTECT
50244 + help
50245 + If you say Y here, text relocations will be logged with the filename
50246 + of the offending library or binary. The purpose of the feature is
50247 + to help Linux distribution developers get rid of libraries and
50248 + binaries that need text relocations which hinder the future progress
50249 + of PaX. Only Linux distribution developers should say Y here, and
50250 + never on a production machine, as this option creates an information
50251 + leak that could aid an attacker in defeating the randomization of
50252 + a single memory region. If the sysctl option is enabled, a sysctl
50253 + option with name "audit_textrel" is created.
50254 +
50255 +endmenu
50256 +
50257 +menu "Executable Protections"
50258 +depends on GRKERNSEC
50259 +
50260 +config GRKERNSEC_DMESG
50261 + bool "Dmesg(8) restriction"
50262 + help
50263 + If you say Y here, non-root users will not be able to use dmesg(8)
50264 + to view up to the last 4kb of messages in the kernel's log buffer.
50265 + The kernel's log buffer often contains kernel addresses and other
50266 + identifying information useful to an attacker in fingerprinting a
50267 + system for a targeted exploit.
50268 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50269 + created.
50270 +
50271 +config GRKERNSEC_HARDEN_PTRACE
50272 + bool "Deter ptrace-based process snooping"
50273 + help
50274 + If you say Y here, TTY sniffers and other malicious monitoring
50275 + programs implemented through ptrace will be defeated. If you
50276 + have been using the RBAC system, this option has already been
50277 + enabled for several years for all users, with the ability to make
50278 + fine-grained exceptions.
50279 +
50280 + This option only affects the ability of non-root users to ptrace
50281 + processes that are not a descendent of the ptracing process.
50282 + This means that strace ./binary and gdb ./binary will still work,
50283 + but attaching to arbitrary processes will not. If the sysctl
50284 + option is enabled, a sysctl option with name "harden_ptrace" is
50285 + created.
50286 +
50287 +config GRKERNSEC_PTRACE_READEXEC
50288 + bool "Require read access to ptrace sensitive binaries"
50289 + help
50290 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50291 + binaries. This option is useful in environments that
50292 + remove the read bits (e.g. file mode 4711) from suid binaries to
50293 + prevent infoleaking of their contents. This option adds
50294 + consistency to the use of that file mode, as the binary could normally
50295 + be read out when run without privileges while ptracing.
50296 +
50297 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50298 + is created.
50299 +
50300 +config GRKERNSEC_SETXID
50301 + bool "Enforce consistent multithreaded privileges"
50302 + help
50303 + If you say Y here, a change from a root uid to a non-root uid
50304 + in a multithreaded application will cause the resulting uids,
50305 + gids, supplementary groups, and capabilities in that thread
50306 + to be propagated to the other threads of the process. In most
50307 + cases this is unnecessary, as glibc will emulate this behavior
50308 + on behalf of the application. Other libcs do not act in the
50309 + same way, allowing the other threads of the process to continue
50310 + running with root privileges. If the sysctl option is enabled,
50311 + a sysctl option with name "consistent_setxid" is created.
50312 +
50313 +config GRKERNSEC_TPE
50314 + bool "Trusted Path Execution (TPE)"
50315 + help
50316 + If you say Y here, you will be able to choose a gid to add to the
50317 + supplementary groups of users you want to mark as "untrusted."
50318 + These users will not be able to execute any files that are not in
50319 + root-owned directories writable only by root. If the sysctl option
50320 + is enabled, a sysctl option with name "tpe" is created.
50321 +
50322 +config GRKERNSEC_TPE_ALL
50323 + bool "Partially restrict all non-root users"
50324 + depends on GRKERNSEC_TPE
50325 + help
50326 + If you say Y here, all non-root users will be covered under
50327 + a weaker TPE restriction. This is separate from, and in addition to,
50328 + the main TPE options that you have selected elsewhere. Thus, if a
50329 + "trusted" GID is chosen, this restriction applies to even that GID.
50330 + Under this restriction, all non-root users will only be allowed to
50331 + execute files in directories they own that are not group or
50332 + world-writable, or in directories owned by root and writable only by
50333 + root. If the sysctl option is enabled, a sysctl option with name
50334 + "tpe_restrict_all" is created.
50335 +
50336 +config GRKERNSEC_TPE_INVERT
50337 + bool "Invert GID option"
50338 + depends on GRKERNSEC_TPE
50339 + help
50340 + If you say Y here, the group you specify in the TPE configuration will
50341 + decide what group TPE restrictions will be *disabled* for. This
50342 + option is useful if you want TPE restrictions to be applied to most
50343 + users on the system. If the sysctl option is enabled, a sysctl option
50344 + with name "tpe_invert" is created. Unlike other sysctl options, this
50345 + entry will default to on for backward-compatibility.
50346 +
50347 +config GRKERNSEC_TPE_GID
50348 + int "GID for untrusted users"
50349 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50350 + default 1005
50351 + help
50352 + Setting this GID determines what group TPE restrictions will be
50353 + *enabled* for. If the sysctl option is enabled, a sysctl option
50354 + with name "tpe_gid" is created.
50355 +
50356 +config GRKERNSEC_TPE_GID
50357 + int "GID for trusted users"
50358 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50359 + default 1005
50360 + help
50361 + Setting this GID determines what group TPE restrictions will be
50362 + *disabled* for. If the sysctl option is enabled, a sysctl option
50363 + with name "tpe_gid" is created.
50364 +
50365 +endmenu
50366 +menu "Network Protections"
50367 +depends on GRKERNSEC
50368 +
50369 +config GRKERNSEC_RANDNET
50370 + bool "Larger entropy pools"
50371 + help
50372 + If you say Y here, the entropy pools used for many features of Linux
50373 + and grsecurity will be doubled in size. Since several grsecurity
50374 + features use additional randomness, it is recommended that you say Y
50375 + here. Saying Y here has a similar effect as modifying
50376 + /proc/sys/kernel/random/poolsize.
50377 +
50378 +config GRKERNSEC_BLACKHOLE
50379 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50380 + depends on NET
50381 + help
50382 + If you say Y here, neither TCP resets nor ICMP
50383 + destination-unreachable packets will be sent in response to packets
50384 + sent to ports for which no associated listening process exists.
50385 + This feature supports both IPV4 and IPV6 and exempts the
50386 + loopback interface from blackholing. Enabling this feature
50387 + makes a host more resilient to DoS attacks and reduces network
50388 + visibility against scanners.
50389 +
50390 + The blackhole feature as-implemented is equivalent to the FreeBSD
50391 + blackhole feature, as it prevents RST responses to all packets, not
50392 + just SYNs. Under most application behavior this causes no
50393 + problems, but applications (like haproxy) may not close certain
50394 + connections in a way that cleanly terminates them on the remote
50395 + end, leaving the remote host in LAST_ACK state. Because of this
50396 + side-effect and to prevent intentional LAST_ACK DoSes, this
50397 + feature also adds automatic mitigation against such attacks.
50398 + The mitigation drastically reduces the amount of time a socket
50399 + can spend in LAST_ACK state. If you're using haproxy and not
50400 + all servers it connects to have this option enabled, consider
50401 + disabling this feature on the haproxy host.
50402 +
50403 + If the sysctl option is enabled, two sysctl options with names
50404 + "ip_blackhole" and "lastack_retries" will be created.
50405 + While "ip_blackhole" takes the standard zero/non-zero on/off
50406 + toggle, "lastack_retries" uses the same kinds of values as
50407 + "tcp_retries1" and "tcp_retries2". The default value of 4
50408 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50409 + state.
50410 +
50411 +config GRKERNSEC_SOCKET
50412 + bool "Socket restrictions"
50413 + depends on NET
50414 + help
50415 + If you say Y here, you will be able to choose from several options.
50416 + If you assign a GID on your system and add it to the supplementary
50417 + groups of users you want to restrict socket access to, this patch
50418 + will perform up to three things, based on the option(s) you choose.
50419 +
50420 +config GRKERNSEC_SOCKET_ALL
50421 + bool "Deny any sockets to group"
50422 + depends on GRKERNSEC_SOCKET
50423 + help
50424 + If you say Y here, you will be able to choose a GID of whose users will
50425 + be unable to connect to other hosts from your machine or run server
50426 + applications from your machine. If the sysctl option is enabled, a
50427 + sysctl option with name "socket_all" is created.
50428 +
50429 +config GRKERNSEC_SOCKET_ALL_GID
50430 + int "GID to deny all sockets for"
50431 + depends on GRKERNSEC_SOCKET_ALL
50432 + default 1004
50433 + help
50434 + Here you can choose the GID to disable socket access for. Remember to
50435 + add the users you want socket access disabled for to the GID
50436 + specified here. If the sysctl option is enabled, a sysctl option
50437 + with name "socket_all_gid" is created.
50438 +
50439 +config GRKERNSEC_SOCKET_CLIENT
50440 + bool "Deny client sockets to group"
50441 + depends on GRKERNSEC_SOCKET
50442 + help
50443 + If you say Y here, you will be able to choose a GID of whose users will
50444 + be unable to connect to other hosts from your machine, but will be
50445 + able to run servers. If this option is enabled, all users in the group
50446 + you specify will have to use passive mode when initiating ftp transfers
50447 + from the shell on your machine. If the sysctl option is enabled, a
50448 + sysctl option with name "socket_client" is created.
50449 +
50450 +config GRKERNSEC_SOCKET_CLIENT_GID
50451 + int "GID to deny client sockets for"
50452 + depends on GRKERNSEC_SOCKET_CLIENT
50453 + default 1003
50454 + help
50455 + Here you can choose the GID to disable client socket access for.
50456 + Remember to add the users you want client socket access disabled for to
50457 + the GID specified here. If the sysctl option is enabled, a sysctl
50458 + option with name "socket_client_gid" is created.
50459 +
50460 +config GRKERNSEC_SOCKET_SERVER
50461 + bool "Deny server sockets to group"
50462 + depends on GRKERNSEC_SOCKET
50463 + help
50464 + If you say Y here, you will be able to choose a GID of whose users will
50465 + be unable to run server applications from your machine. If the sysctl
50466 + option is enabled, a sysctl option with name "socket_server" is created.
50467 +
50468 +config GRKERNSEC_SOCKET_SERVER_GID
50469 + int "GID to deny server sockets for"
50470 + depends on GRKERNSEC_SOCKET_SERVER
50471 + default 1002
50472 + help
50473 + Here you can choose the GID to disable server socket access for.
50474 + Remember to add the users you want server socket access disabled for to
50475 + the GID specified here. If the sysctl option is enabled, a sysctl
50476 + option with name "socket_server_gid" is created.
50477 +
50478 +endmenu
50479 +menu "Sysctl support"
50480 +depends on GRKERNSEC && SYSCTL
50481 +
50482 +config GRKERNSEC_SYSCTL
50483 + bool "Sysctl support"
50484 + help
50485 + If you say Y here, you will be able to change the options that
50486 + grsecurity runs with at bootup, without having to recompile your
50487 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50488 + to enable (1) or disable (0) various features. All the sysctl entries
50489 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50490 + All features enabled in the kernel configuration are disabled at boot
50491 + if you do not say Y to the "Turn on features by default" option.
50492 + All options should be set at startup, and the grsec_lock entry should
50493 + be set to a non-zero value after all the options are set.
50494 + *THIS IS EXTREMELY IMPORTANT*
50495 +
50496 +config GRKERNSEC_SYSCTL_DISTRO
50497 + bool "Extra sysctl support for distro makers (READ HELP)"
50498 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50499 + help
50500 + If you say Y here, additional sysctl options will be created
50501 + for features that affect processes running as root. Therefore,
50502 + it is critical when using this option that the grsec_lock entry be
50503 + enabled after boot. Only distros with prebuilt kernel packages
50504 + with this option enabled that can ensure grsec_lock is enabled
50505 + after boot should use this option.
50506 + *Failure to set grsec_lock after boot makes all grsec features
50507 + this option covers useless*
50508 +
50509 + Currently this option creates the following sysctl entries:
50510 + "Disable Privileged I/O": "disable_priv_io"
50511 +
50512 +config GRKERNSEC_SYSCTL_ON
50513 + bool "Turn on features by default"
50514 + depends on GRKERNSEC_SYSCTL
50515 + help
50516 + If you say Y here, instead of having all features enabled in the
50517 + kernel configuration disabled at boot time, the features will be
50518 + enabled at boot time. It is recommended you say Y here unless
50519 + there is some reason you would want all sysctl-tunable features to
50520 + be disabled by default. As mentioned elsewhere, it is important
50521 + to enable the grsec_lock entry once you have finished modifying
50522 + the sysctl entries.
50523 +
50524 +endmenu
50525 +menu "Logging Options"
50526 +depends on GRKERNSEC
50527 +
50528 +config GRKERNSEC_FLOODTIME
50529 + int "Seconds in between log messages (minimum)"
50530 + default 10
50531 + help
50532 + This option allows you to enforce the number of seconds between
50533 + grsecurity log messages. The default should be suitable for most
50534 + people, however, if you choose to change it, choose a value small enough
50535 + to allow informative logs to be produced, but large enough to
50536 + prevent flooding.
50537 +
50538 +config GRKERNSEC_FLOODBURST
50539 + int "Number of messages in a burst (maximum)"
50540 + default 6
50541 + help
50542 + This option allows you to choose the maximum number of messages allowed
50543 + within the flood time interval you chose in a separate option. The
50544 + default should be suitable for most people, however if you find that
50545 + many of your logs are being interpreted as flooding, you may want to
50546 + raise this value.
50547 +
50548 +endmenu
50549 +
50550 +endmenu
50551 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50552 new file mode 100644
50553 index 0000000..1b9afa9
50554 --- /dev/null
50555 +++ b/grsecurity/Makefile
50556 @@ -0,0 +1,38 @@
50557 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50558 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50559 +# into an RBAC system
50560 +#
50561 +# All code in this directory and various hooks inserted throughout the kernel
50562 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50563 +# under the GPL v2 or higher
50564 +
50565 +KBUILD_CFLAGS += -Werror
50566 +
50567 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50568 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50569 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50570 +
50571 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50572 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50573 + gracl_learn.o grsec_log.o
50574 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50575 +
50576 +ifdef CONFIG_NET
50577 +obj-y += grsec_sock.o
50578 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50579 +endif
50580 +
50581 +ifndef CONFIG_GRKERNSEC
50582 +obj-y += grsec_disabled.o
50583 +endif
50584 +
50585 +ifdef CONFIG_GRKERNSEC_HIDESYM
50586 +extra-y := grsec_hidesym.o
50587 +$(obj)/grsec_hidesym.o:
50588 + @-chmod -f 500 /boot
50589 + @-chmod -f 500 /lib/modules
50590 + @-chmod -f 500 /lib64/modules
50591 + @-chmod -f 500 /lib32/modules
50592 + @-chmod -f 700 .
50593 + @echo ' grsec: protected kernel image paths'
50594 +endif
50595 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50596 new file mode 100644
50597 index 0000000..42813ac
50598 --- /dev/null
50599 +++ b/grsecurity/gracl.c
50600 @@ -0,0 +1,4192 @@
50601 +#include <linux/kernel.h>
50602 +#include <linux/module.h>
50603 +#include <linux/sched.h>
50604 +#include <linux/mm.h>
50605 +#include <linux/file.h>
50606 +#include <linux/fs.h>
50607 +#include <linux/namei.h>
50608 +#include <linux/mount.h>
50609 +#include <linux/tty.h>
50610 +#include <linux/proc_fs.h>
50611 +#include <linux/lglock.h>
50612 +#include <linux/slab.h>
50613 +#include <linux/vmalloc.h>
50614 +#include <linux/types.h>
50615 +#include <linux/sysctl.h>
50616 +#include <linux/netdevice.h>
50617 +#include <linux/ptrace.h>
50618 +#include <linux/gracl.h>
50619 +#include <linux/gralloc.h>
50620 +#include <linux/security.h>
50621 +#include <linux/grinternal.h>
50622 +#include <linux/pid_namespace.h>
50623 +#include <linux/fdtable.h>
50624 +#include <linux/percpu.h>
50625 +#include "../fs/mount.h"
50626 +
50627 +#include <asm/uaccess.h>
50628 +#include <asm/errno.h>
50629 +#include <asm/mman.h>
50630 +
50631 +static struct acl_role_db acl_role_set;
50632 +static struct name_db name_set;
50633 +static struct inodev_db inodev_set;
50634 +
50635 +/* for keeping track of userspace pointers used for subjects, so we
50636 + can share references in the kernel as well
50637 +*/
50638 +
50639 +static struct path real_root;
50640 +
50641 +static struct acl_subj_map_db subj_map_set;
50642 +
50643 +static struct acl_role_label *default_role;
50644 +
50645 +static struct acl_role_label *role_list;
50646 +
50647 +static u16 acl_sp_role_value;
50648 +
50649 +extern char *gr_shared_page[4];
50650 +static DEFINE_MUTEX(gr_dev_mutex);
50651 +DEFINE_RWLOCK(gr_inode_lock);
50652 +
50653 +struct gr_arg *gr_usermode;
50654 +
50655 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50656 +
50657 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50658 +extern void gr_clear_learn_entries(void);
50659 +
50660 +#ifdef CONFIG_GRKERNSEC_RESLOG
50661 +extern void gr_log_resource(const struct task_struct *task,
50662 + const int res, const unsigned long wanted, const int gt);
50663 +#endif
50664 +
50665 +unsigned char *gr_system_salt;
50666 +unsigned char *gr_system_sum;
50667 +
50668 +static struct sprole_pw **acl_special_roles = NULL;
50669 +static __u16 num_sprole_pws = 0;
50670 +
50671 +static struct acl_role_label *kernel_role = NULL;
50672 +
50673 +static unsigned int gr_auth_attempts = 0;
50674 +static unsigned long gr_auth_expires = 0UL;
50675 +
50676 +#ifdef CONFIG_NET
50677 +extern struct vfsmount *sock_mnt;
50678 +#endif
50679 +
50680 +extern struct vfsmount *pipe_mnt;
50681 +extern struct vfsmount *shm_mnt;
50682 +#ifdef CONFIG_HUGETLBFS
50683 +extern struct vfsmount *hugetlbfs_vfsmount;
50684 +#endif
50685 +
50686 +static struct acl_object_label *fakefs_obj_rw;
50687 +static struct acl_object_label *fakefs_obj_rwx;
50688 +
50689 +extern int gr_init_uidset(void);
50690 +extern void gr_free_uidset(void);
50691 +extern void gr_remove_uid(uid_t uid);
50692 +extern int gr_find_uid(uid_t uid);
50693 +
50694 +DECLARE_BRLOCK(vfsmount_lock);
50695 +
50696 +__inline__ int
50697 +gr_acl_is_enabled(void)
50698 +{
50699 + return (gr_status & GR_READY);
50700 +}
50701 +
50702 +#ifdef CONFIG_BTRFS_FS
50703 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50704 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50705 +#endif
50706 +
50707 +static inline dev_t __get_dev(const struct dentry *dentry)
50708 +{
50709 +#ifdef CONFIG_BTRFS_FS
50710 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50711 + return get_btrfs_dev_from_inode(dentry->d_inode);
50712 + else
50713 +#endif
50714 + return dentry->d_inode->i_sb->s_dev;
50715 +}
50716 +
50717 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50718 +{
50719 + return __get_dev(dentry);
50720 +}
50721 +
50722 +static char gr_task_roletype_to_char(struct task_struct *task)
50723 +{
50724 + switch (task->role->roletype &
50725 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50726 + GR_ROLE_SPECIAL)) {
50727 + case GR_ROLE_DEFAULT:
50728 + return 'D';
50729 + case GR_ROLE_USER:
50730 + return 'U';
50731 + case GR_ROLE_GROUP:
50732 + return 'G';
50733 + case GR_ROLE_SPECIAL:
50734 + return 'S';
50735 + }
50736 +
50737 + return 'X';
50738 +}
50739 +
50740 +char gr_roletype_to_char(void)
50741 +{
50742 + return gr_task_roletype_to_char(current);
50743 +}
50744 +
50745 +__inline__ int
50746 +gr_acl_tpe_check(void)
50747 +{
50748 + if (unlikely(!(gr_status & GR_READY)))
50749 + return 0;
50750 + if (current->role->roletype & GR_ROLE_TPE)
50751 + return 1;
50752 + else
50753 + return 0;
50754 +}
50755 +
50756 +int
50757 +gr_handle_rawio(const struct inode *inode)
50758 +{
50759 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50760 + if (inode && S_ISBLK(inode->i_mode) &&
50761 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50762 + !capable(CAP_SYS_RAWIO))
50763 + return 1;
50764 +#endif
50765 + return 0;
50766 +}
50767 +
50768 +static int
50769 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50770 +{
50771 + if (likely(lena != lenb))
50772 + return 0;
50773 +
50774 + return !memcmp(a, b, lena);
50775 +}
50776 +
50777 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50778 +{
50779 + *buflen -= namelen;
50780 + if (*buflen < 0)
50781 + return -ENAMETOOLONG;
50782 + *buffer -= namelen;
50783 + memcpy(*buffer, str, namelen);
50784 + return 0;
50785 +}
50786 +
50787 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50788 +{
50789 + return prepend(buffer, buflen, name->name, name->len);
50790 +}
50791 +
50792 +static int prepend_path(const struct path *path, struct path *root,
50793 + char **buffer, int *buflen)
50794 +{
50795 + struct dentry *dentry = path->dentry;
50796 + struct vfsmount *vfsmnt = path->mnt;
50797 + struct mount *mnt = real_mount(vfsmnt);
50798 + bool slash = false;
50799 + int error = 0;
50800 +
50801 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50802 + struct dentry * parent;
50803 +
50804 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50805 + /* Global root? */
50806 + if (!mnt_has_parent(mnt)) {
50807 + goto out;
50808 + }
50809 + dentry = mnt->mnt_mountpoint;
50810 + mnt = mnt->mnt_parent;
50811 + vfsmnt = &mnt->mnt;
50812 + continue;
50813 + }
50814 + parent = dentry->d_parent;
50815 + prefetch(parent);
50816 + spin_lock(&dentry->d_lock);
50817 + error = prepend_name(buffer, buflen, &dentry->d_name);
50818 + spin_unlock(&dentry->d_lock);
50819 + if (!error)
50820 + error = prepend(buffer, buflen, "/", 1);
50821 + if (error)
50822 + break;
50823 +
50824 + slash = true;
50825 + dentry = parent;
50826 + }
50827 +
50828 +out:
50829 + if (!error && !slash)
50830 + error = prepend(buffer, buflen, "/", 1);
50831 +
50832 + return error;
50833 +}
50834 +
50835 +/* this must be called with vfsmount_lock and rename_lock held */
50836 +
50837 +static char *__our_d_path(const struct path *path, struct path *root,
50838 + char *buf, int buflen)
50839 +{
50840 + char *res = buf + buflen;
50841 + int error;
50842 +
50843 + prepend(&res, &buflen, "\0", 1);
50844 + error = prepend_path(path, root, &res, &buflen);
50845 + if (error)
50846 + return ERR_PTR(error);
50847 +
50848 + return res;
50849 +}
50850 +
50851 +static char *
50852 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50853 +{
50854 + char *retval;
50855 +
50856 + retval = __our_d_path(path, root, buf, buflen);
50857 + if (unlikely(IS_ERR(retval)))
50858 + retval = strcpy(buf, "<path too long>");
50859 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50860 + retval[1] = '\0';
50861 +
50862 + return retval;
50863 +}
50864 +
50865 +static char *
50866 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50867 + char *buf, int buflen)
50868 +{
50869 + struct path path;
50870 + char *res;
50871 +
50872 + path.dentry = (struct dentry *)dentry;
50873 + path.mnt = (struct vfsmount *)vfsmnt;
50874 +
50875 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50876 + by the RBAC system */
50877 + res = gen_full_path(&path, &real_root, buf, buflen);
50878 +
50879 + return res;
50880 +}
50881 +
50882 +static char *
50883 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50884 + char *buf, int buflen)
50885 +{
50886 + char *res;
50887 + struct path path;
50888 + struct path root;
50889 + struct task_struct *reaper = &init_task;
50890 +
50891 + path.dentry = (struct dentry *)dentry;
50892 + path.mnt = (struct vfsmount *)vfsmnt;
50893 +
50894 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50895 + get_fs_root(reaper->fs, &root);
50896 +
50897 + write_seqlock(&rename_lock);
50898 + br_read_lock(vfsmount_lock);
50899 + res = gen_full_path(&path, &root, buf, buflen);
50900 + br_read_unlock(vfsmount_lock);
50901 + write_sequnlock(&rename_lock);
50902 +
50903 + path_put(&root);
50904 + return res;
50905 +}
50906 +
50907 +static char *
50908 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50909 +{
50910 + char *ret;
50911 + write_seqlock(&rename_lock);
50912 + br_read_lock(vfsmount_lock);
50913 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50914 + PAGE_SIZE);
50915 + br_read_unlock(vfsmount_lock);
50916 + write_sequnlock(&rename_lock);
50917 + return ret;
50918 +}
50919 +
50920 +static char *
50921 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50922 +{
50923 + char *ret;
50924 + char *buf;
50925 + int buflen;
50926 +
50927 + write_seqlock(&rename_lock);
50928 + br_read_lock(vfsmount_lock);
50929 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50930 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50931 + buflen = (int)(ret - buf);
50932 + if (buflen >= 5)
50933 + prepend(&ret, &buflen, "/proc", 5);
50934 + else
50935 + ret = strcpy(buf, "<path too long>");
50936 + br_read_unlock(vfsmount_lock);
50937 + write_sequnlock(&rename_lock);
50938 + return ret;
50939 +}
50940 +
50941 +char *
50942 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50943 +{
50944 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50945 + PAGE_SIZE);
50946 +}
50947 +
50948 +char *
50949 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50950 +{
50951 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50952 + PAGE_SIZE);
50953 +}
50954 +
50955 +char *
50956 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50957 +{
50958 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50959 + PAGE_SIZE);
50960 +}
50961 +
50962 +char *
50963 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50964 +{
50965 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50966 + PAGE_SIZE);
50967 +}
50968 +
50969 +char *
50970 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50971 +{
50972 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50973 + PAGE_SIZE);
50974 +}
50975 +
50976 +__inline__ __u32
50977 +to_gr_audit(const __u32 reqmode)
50978 +{
50979 + /* masks off auditable permission flags, then shifts them to create
50980 + auditing flags, and adds the special case of append auditing if
50981 + we're requesting write */
50982 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50983 +}
50984 +
50985 +struct acl_subject_label *
50986 +lookup_subject_map(const struct acl_subject_label *userp)
50987 +{
50988 + unsigned int index = shash(userp, subj_map_set.s_size);
50989 + struct subject_map *match;
50990 +
50991 + match = subj_map_set.s_hash[index];
50992 +
50993 + while (match && match->user != userp)
50994 + match = match->next;
50995 +
50996 + if (match != NULL)
50997 + return match->kernel;
50998 + else
50999 + return NULL;
51000 +}
51001 +
51002 +static void
51003 +insert_subj_map_entry(struct subject_map *subjmap)
51004 +{
51005 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51006 + struct subject_map **curr;
51007 +
51008 + subjmap->prev = NULL;
51009 +
51010 + curr = &subj_map_set.s_hash[index];
51011 + if (*curr != NULL)
51012 + (*curr)->prev = subjmap;
51013 +
51014 + subjmap->next = *curr;
51015 + *curr = subjmap;
51016 +
51017 + return;
51018 +}
51019 +
51020 +static struct acl_role_label *
51021 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51022 + const gid_t gid)
51023 +{
51024 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51025 + struct acl_role_label *match;
51026 + struct role_allowed_ip *ipp;
51027 + unsigned int x;
51028 + u32 curr_ip = task->signal->curr_ip;
51029 +
51030 + task->signal->saved_ip = curr_ip;
51031 +
51032 + match = acl_role_set.r_hash[index];
51033 +
51034 + while (match) {
51035 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51036 + for (x = 0; x < match->domain_child_num; x++) {
51037 + if (match->domain_children[x] == uid)
51038 + goto found;
51039 + }
51040 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51041 + break;
51042 + match = match->next;
51043 + }
51044 +found:
51045 + if (match == NULL) {
51046 + try_group:
51047 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51048 + match = acl_role_set.r_hash[index];
51049 +
51050 + while (match) {
51051 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51052 + for (x = 0; x < match->domain_child_num; x++) {
51053 + if (match->domain_children[x] == gid)
51054 + goto found2;
51055 + }
51056 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51057 + break;
51058 + match = match->next;
51059 + }
51060 +found2:
51061 + if (match == NULL)
51062 + match = default_role;
51063 + if (match->allowed_ips == NULL)
51064 + return match;
51065 + else {
51066 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51067 + if (likely
51068 + ((ntohl(curr_ip) & ipp->netmask) ==
51069 + (ntohl(ipp->addr) & ipp->netmask)))
51070 + return match;
51071 + }
51072 + match = default_role;
51073 + }
51074 + } else if (match->allowed_ips == NULL) {
51075 + return match;
51076 + } else {
51077 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51078 + if (likely
51079 + ((ntohl(curr_ip) & ipp->netmask) ==
51080 + (ntohl(ipp->addr) & ipp->netmask)))
51081 + return match;
51082 + }
51083 + goto try_group;
51084 + }
51085 +
51086 + return match;
51087 +}
51088 +
51089 +struct acl_subject_label *
51090 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51091 + const struct acl_role_label *role)
51092 +{
51093 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51094 + struct acl_subject_label *match;
51095 +
51096 + match = role->subj_hash[index];
51097 +
51098 + while (match && (match->inode != ino || match->device != dev ||
51099 + (match->mode & GR_DELETED))) {
51100 + match = match->next;
51101 + }
51102 +
51103 + if (match && !(match->mode & GR_DELETED))
51104 + return match;
51105 + else
51106 + return NULL;
51107 +}
51108 +
51109 +struct acl_subject_label *
51110 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51111 + const struct acl_role_label *role)
51112 +{
51113 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51114 + struct acl_subject_label *match;
51115 +
51116 + match = role->subj_hash[index];
51117 +
51118 + while (match && (match->inode != ino || match->device != dev ||
51119 + !(match->mode & GR_DELETED))) {
51120 + match = match->next;
51121 + }
51122 +
51123 + if (match && (match->mode & GR_DELETED))
51124 + return match;
51125 + else
51126 + return NULL;
51127 +}
51128 +
51129 +static struct acl_object_label *
51130 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51131 + const struct acl_subject_label *subj)
51132 +{
51133 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51134 + struct acl_object_label *match;
51135 +
51136 + match = subj->obj_hash[index];
51137 +
51138 + while (match && (match->inode != ino || match->device != dev ||
51139 + (match->mode & GR_DELETED))) {
51140 + match = match->next;
51141 + }
51142 +
51143 + if (match && !(match->mode & GR_DELETED))
51144 + return match;
51145 + else
51146 + return NULL;
51147 +}
51148 +
51149 +static struct acl_object_label *
51150 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51151 + const struct acl_subject_label *subj)
51152 +{
51153 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51154 + struct acl_object_label *match;
51155 +
51156 + match = subj->obj_hash[index];
51157 +
51158 + while (match && (match->inode != ino || match->device != dev ||
51159 + !(match->mode & GR_DELETED))) {
51160 + match = match->next;
51161 + }
51162 +
51163 + if (match && (match->mode & GR_DELETED))
51164 + return match;
51165 +
51166 + match = subj->obj_hash[index];
51167 +
51168 + while (match && (match->inode != ino || match->device != dev ||
51169 + (match->mode & GR_DELETED))) {
51170 + match = match->next;
51171 + }
51172 +
51173 + if (match && !(match->mode & GR_DELETED))
51174 + return match;
51175 + else
51176 + return NULL;
51177 +}
51178 +
51179 +static struct name_entry *
51180 +lookup_name_entry(const char *name)
51181 +{
51182 + unsigned int len = strlen(name);
51183 + unsigned int key = full_name_hash(name, len);
51184 + unsigned int index = key % name_set.n_size;
51185 + struct name_entry *match;
51186 +
51187 + match = name_set.n_hash[index];
51188 +
51189 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51190 + match = match->next;
51191 +
51192 + return match;
51193 +}
51194 +
51195 +static struct name_entry *
51196 +lookup_name_entry_create(const char *name)
51197 +{
51198 + unsigned int len = strlen(name);
51199 + unsigned int key = full_name_hash(name, len);
51200 + unsigned int index = key % name_set.n_size;
51201 + struct name_entry *match;
51202 +
51203 + match = name_set.n_hash[index];
51204 +
51205 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51206 + !match->deleted))
51207 + match = match->next;
51208 +
51209 + if (match && match->deleted)
51210 + return match;
51211 +
51212 + match = name_set.n_hash[index];
51213 +
51214 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51215 + match->deleted))
51216 + match = match->next;
51217 +
51218 + if (match && !match->deleted)
51219 + return match;
51220 + else
51221 + return NULL;
51222 +}
51223 +
51224 +static struct inodev_entry *
51225 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51226 +{
51227 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51228 + struct inodev_entry *match;
51229 +
51230 + match = inodev_set.i_hash[index];
51231 +
51232 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51233 + match = match->next;
51234 +
51235 + return match;
51236 +}
51237 +
51238 +static void
51239 +insert_inodev_entry(struct inodev_entry *entry)
51240 +{
51241 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51242 + inodev_set.i_size);
51243 + struct inodev_entry **curr;
51244 +
51245 + entry->prev = NULL;
51246 +
51247 + curr = &inodev_set.i_hash[index];
51248 + if (*curr != NULL)
51249 + (*curr)->prev = entry;
51250 +
51251 + entry->next = *curr;
51252 + *curr = entry;
51253 +
51254 + return;
51255 +}
51256 +
51257 +static void
51258 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51259 +{
51260 + unsigned int index =
51261 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51262 + struct acl_role_label **curr;
51263 + struct acl_role_label *tmp, *tmp2;
51264 +
51265 + curr = &acl_role_set.r_hash[index];
51266 +
51267 + /* simple case, slot is empty, just set it to our role */
51268 + if (*curr == NULL) {
51269 + *curr = role;
51270 + } else {
51271 + /* example:
51272 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51273 + 2 -> 3
51274 + */
51275 + /* first check to see if we can already be reached via this slot */
51276 + tmp = *curr;
51277 + while (tmp && tmp != role)
51278 + tmp = tmp->next;
51279 + if (tmp == role) {
51280 + /* we don't need to add ourselves to this slot's chain */
51281 + return;
51282 + }
51283 + /* we need to add ourselves to this chain, two cases */
51284 + if (role->next == NULL) {
51285 + /* simple case, append the current chain to our role */
51286 + role->next = *curr;
51287 + *curr = role;
51288 + } else {
51289 + /* 1 -> 2 -> 3 -> 4
51290 + 2 -> 3 -> 4
51291 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51292 + */
51293 + /* trickier case: walk our role's chain until we find
51294 + the role for the start of the current slot's chain */
51295 + tmp = role;
51296 + tmp2 = *curr;
51297 + while (tmp->next && tmp->next != tmp2)
51298 + tmp = tmp->next;
51299 + if (tmp->next == tmp2) {
51300 + /* from example above, we found 3, so just
51301 + replace this slot's chain with ours */
51302 + *curr = role;
51303 + } else {
51304 + /* we didn't find a subset of our role's chain
51305 + in the current slot's chain, so append their
51306 + chain to ours, and set us as the first role in
51307 + the slot's chain
51308 +
51309 + we could fold this case with the case above,
51310 + but making it explicit for clarity
51311 + */
51312 + tmp->next = tmp2;
51313 + *curr = role;
51314 + }
51315 + }
51316 + }
51317 +
51318 + return;
51319 +}
51320 +
51321 +static void
51322 +insert_acl_role_label(struct acl_role_label *role)
51323 +{
51324 + int i;
51325 +
51326 + if (role_list == NULL) {
51327 + role_list = role;
51328 + role->prev = NULL;
51329 + } else {
51330 + role->prev = role_list;
51331 + role_list = role;
51332 + }
51333 +
51334 + /* used for hash chains */
51335 + role->next = NULL;
51336 +
51337 + if (role->roletype & GR_ROLE_DOMAIN) {
51338 + for (i = 0; i < role->domain_child_num; i++)
51339 + __insert_acl_role_label(role, role->domain_children[i]);
51340 + } else
51341 + __insert_acl_role_label(role, role->uidgid);
51342 +}
51343 +
51344 +static int
51345 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51346 +{
51347 + struct name_entry **curr, *nentry;
51348 + struct inodev_entry *ientry;
51349 + unsigned int len = strlen(name);
51350 + unsigned int key = full_name_hash(name, len);
51351 + unsigned int index = key % name_set.n_size;
51352 +
51353 + curr = &name_set.n_hash[index];
51354 +
51355 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51356 + curr = &((*curr)->next);
51357 +
51358 + if (*curr != NULL)
51359 + return 1;
51360 +
51361 + nentry = acl_alloc(sizeof (struct name_entry));
51362 + if (nentry == NULL)
51363 + return 0;
51364 + ientry = acl_alloc(sizeof (struct inodev_entry));
51365 + if (ientry == NULL)
51366 + return 0;
51367 + ientry->nentry = nentry;
51368 +
51369 + nentry->key = key;
51370 + nentry->name = name;
51371 + nentry->inode = inode;
51372 + nentry->device = device;
51373 + nentry->len = len;
51374 + nentry->deleted = deleted;
51375 +
51376 + nentry->prev = NULL;
51377 + curr = &name_set.n_hash[index];
51378 + if (*curr != NULL)
51379 + (*curr)->prev = nentry;
51380 + nentry->next = *curr;
51381 + *curr = nentry;
51382 +
51383 + /* insert us into the table searchable by inode/dev */
51384 + insert_inodev_entry(ientry);
51385 +
51386 + return 1;
51387 +}
51388 +
51389 +static void
51390 +insert_acl_obj_label(struct acl_object_label *obj,
51391 + struct acl_subject_label *subj)
51392 +{
51393 + unsigned int index =
51394 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51395 + struct acl_object_label **curr;
51396 +
51397 +
51398 + obj->prev = NULL;
51399 +
51400 + curr = &subj->obj_hash[index];
51401 + if (*curr != NULL)
51402 + (*curr)->prev = obj;
51403 +
51404 + obj->next = *curr;
51405 + *curr = obj;
51406 +
51407 + return;
51408 +}
51409 +
51410 +static void
51411 +insert_acl_subj_label(struct acl_subject_label *obj,
51412 + struct acl_role_label *role)
51413 +{
51414 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51415 + struct acl_subject_label **curr;
51416 +
51417 + obj->prev = NULL;
51418 +
51419 + curr = &role->subj_hash[index];
51420 + if (*curr != NULL)
51421 + (*curr)->prev = obj;
51422 +
51423 + obj->next = *curr;
51424 + *curr = obj;
51425 +
51426 + return;
51427 +}
51428 +
51429 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51430 +
51431 +static void *
51432 +create_table(__u32 * len, int elementsize)
51433 +{
51434 + unsigned int table_sizes[] = {
51435 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51436 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51437 + 4194301, 8388593, 16777213, 33554393, 67108859
51438 + };
51439 + void *newtable = NULL;
51440 + unsigned int pwr = 0;
51441 +
51442 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51443 + table_sizes[pwr] <= *len)
51444 + pwr++;
51445 +
51446 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51447 + return newtable;
51448 +
51449 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51450 + newtable =
51451 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51452 + else
51453 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51454 +
51455 + *len = table_sizes[pwr];
51456 +
51457 + return newtable;
51458 +}
51459 +
51460 +static int
51461 +init_variables(const struct gr_arg *arg)
51462 +{
51463 + struct task_struct *reaper = &init_task;
51464 + unsigned int stacksize;
51465 +
51466 + subj_map_set.s_size = arg->role_db.num_subjects;
51467 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51468 + name_set.n_size = arg->role_db.num_objects;
51469 + inodev_set.i_size = arg->role_db.num_objects;
51470 +
51471 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51472 + !name_set.n_size || !inodev_set.i_size)
51473 + return 1;
51474 +
51475 + if (!gr_init_uidset())
51476 + return 1;
51477 +
51478 + /* set up the stack that holds allocation info */
51479 +
51480 + stacksize = arg->role_db.num_pointers + 5;
51481 +
51482 + if (!acl_alloc_stack_init(stacksize))
51483 + return 1;
51484 +
51485 + /* grab reference for the real root dentry and vfsmount */
51486 + get_fs_root(reaper->fs, &real_root);
51487 +
51488 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51489 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51490 +#endif
51491 +
51492 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51493 + if (fakefs_obj_rw == NULL)
51494 + return 1;
51495 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51496 +
51497 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51498 + if (fakefs_obj_rwx == NULL)
51499 + return 1;
51500 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51501 +
51502 + subj_map_set.s_hash =
51503 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51504 + acl_role_set.r_hash =
51505 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51506 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51507 + inodev_set.i_hash =
51508 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51509 +
51510 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51511 + !name_set.n_hash || !inodev_set.i_hash)
51512 + return 1;
51513 +
51514 + memset(subj_map_set.s_hash, 0,
51515 + sizeof(struct subject_map *) * subj_map_set.s_size);
51516 + memset(acl_role_set.r_hash, 0,
51517 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51518 + memset(name_set.n_hash, 0,
51519 + sizeof (struct name_entry *) * name_set.n_size);
51520 + memset(inodev_set.i_hash, 0,
51521 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51522 +
51523 + return 0;
51524 +}
51525 +
51526 +/* free information not needed after startup
51527 + currently contains user->kernel pointer mappings for subjects
51528 +*/
51529 +
51530 +static void
51531 +free_init_variables(void)
51532 +{
51533 + __u32 i;
51534 +
51535 + if (subj_map_set.s_hash) {
51536 + for (i = 0; i < subj_map_set.s_size; i++) {
51537 + if (subj_map_set.s_hash[i]) {
51538 + kfree(subj_map_set.s_hash[i]);
51539 + subj_map_set.s_hash[i] = NULL;
51540 + }
51541 + }
51542 +
51543 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51544 + PAGE_SIZE)
51545 + kfree(subj_map_set.s_hash);
51546 + else
51547 + vfree(subj_map_set.s_hash);
51548 + }
51549 +
51550 + return;
51551 +}
51552 +
51553 +static void
51554 +free_variables(void)
51555 +{
51556 + struct acl_subject_label *s;
51557 + struct acl_role_label *r;
51558 + struct task_struct *task, *task2;
51559 + unsigned int x;
51560 +
51561 + gr_clear_learn_entries();
51562 +
51563 + read_lock(&tasklist_lock);
51564 + do_each_thread(task2, task) {
51565 + task->acl_sp_role = 0;
51566 + task->acl_role_id = 0;
51567 + task->acl = NULL;
51568 + task->role = NULL;
51569 + } while_each_thread(task2, task);
51570 + read_unlock(&tasklist_lock);
51571 +
51572 + /* release the reference to the real root dentry and vfsmount */
51573 + path_put(&real_root);
51574 + memset(&real_root, 0, sizeof(real_root));
51575 +
51576 + /* free all object hash tables */
51577 +
51578 + FOR_EACH_ROLE_START(r)
51579 + if (r->subj_hash == NULL)
51580 + goto next_role;
51581 + FOR_EACH_SUBJECT_START(r, s, x)
51582 + if (s->obj_hash == NULL)
51583 + break;
51584 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51585 + kfree(s->obj_hash);
51586 + else
51587 + vfree(s->obj_hash);
51588 + FOR_EACH_SUBJECT_END(s, x)
51589 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51590 + if (s->obj_hash == NULL)
51591 + break;
51592 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51593 + kfree(s->obj_hash);
51594 + else
51595 + vfree(s->obj_hash);
51596 + FOR_EACH_NESTED_SUBJECT_END(s)
51597 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51598 + kfree(r->subj_hash);
51599 + else
51600 + vfree(r->subj_hash);
51601 + r->subj_hash = NULL;
51602 +next_role:
51603 + FOR_EACH_ROLE_END(r)
51604 +
51605 + acl_free_all();
51606 +
51607 + if (acl_role_set.r_hash) {
51608 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51609 + PAGE_SIZE)
51610 + kfree(acl_role_set.r_hash);
51611 + else
51612 + vfree(acl_role_set.r_hash);
51613 + }
51614 + if (name_set.n_hash) {
51615 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51616 + PAGE_SIZE)
51617 + kfree(name_set.n_hash);
51618 + else
51619 + vfree(name_set.n_hash);
51620 + }
51621 +
51622 + if (inodev_set.i_hash) {
51623 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51624 + PAGE_SIZE)
51625 + kfree(inodev_set.i_hash);
51626 + else
51627 + vfree(inodev_set.i_hash);
51628 + }
51629 +
51630 + gr_free_uidset();
51631 +
51632 + memset(&name_set, 0, sizeof (struct name_db));
51633 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51634 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51635 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51636 +
51637 + default_role = NULL;
51638 + kernel_role = NULL;
51639 + role_list = NULL;
51640 +
51641 + return;
51642 +}
51643 +
51644 +static __u32
51645 +count_user_objs(struct acl_object_label *userp)
51646 +{
51647 + struct acl_object_label o_tmp;
51648 + __u32 num = 0;
51649 +
51650 + while (userp) {
51651 + if (copy_from_user(&o_tmp, userp,
51652 + sizeof (struct acl_object_label)))
51653 + break;
51654 +
51655 + userp = o_tmp.prev;
51656 + num++;
51657 + }
51658 +
51659 + return num;
51660 +}
51661 +
51662 +static struct acl_subject_label *
51663 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51664 +
51665 +static int
51666 +copy_user_glob(struct acl_object_label *obj)
51667 +{
51668 + struct acl_object_label *g_tmp, **guser;
51669 + unsigned int len;
51670 + char *tmp;
51671 +
51672 + if (obj->globbed == NULL)
51673 + return 0;
51674 +
51675 + guser = &obj->globbed;
51676 + while (*guser) {
51677 + g_tmp = (struct acl_object_label *)
51678 + acl_alloc(sizeof (struct acl_object_label));
51679 + if (g_tmp == NULL)
51680 + return -ENOMEM;
51681 +
51682 + if (copy_from_user(g_tmp, *guser,
51683 + sizeof (struct acl_object_label)))
51684 + return -EFAULT;
51685 +
51686 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51687 +
51688 + if (!len || len >= PATH_MAX)
51689 + return -EINVAL;
51690 +
51691 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51692 + return -ENOMEM;
51693 +
51694 + if (copy_from_user(tmp, g_tmp->filename, len))
51695 + return -EFAULT;
51696 + tmp[len-1] = '\0';
51697 + g_tmp->filename = tmp;
51698 +
51699 + *guser = g_tmp;
51700 + guser = &(g_tmp->next);
51701 + }
51702 +
51703 + return 0;
51704 +}
51705 +
51706 +static int
51707 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51708 + struct acl_role_label *role)
51709 +{
51710 + struct acl_object_label *o_tmp;
51711 + unsigned int len;
51712 + int ret;
51713 + char *tmp;
51714 +
51715 + while (userp) {
51716 + if ((o_tmp = (struct acl_object_label *)
51717 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51718 + return -ENOMEM;
51719 +
51720 + if (copy_from_user(o_tmp, userp,
51721 + sizeof (struct acl_object_label)))
51722 + return -EFAULT;
51723 +
51724 + userp = o_tmp->prev;
51725 +
51726 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51727 +
51728 + if (!len || len >= PATH_MAX)
51729 + return -EINVAL;
51730 +
51731 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51732 + return -ENOMEM;
51733 +
51734 + if (copy_from_user(tmp, o_tmp->filename, len))
51735 + return -EFAULT;
51736 + tmp[len-1] = '\0';
51737 + o_tmp->filename = tmp;
51738 +
51739 + insert_acl_obj_label(o_tmp, subj);
51740 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51741 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51742 + return -ENOMEM;
51743 +
51744 + ret = copy_user_glob(o_tmp);
51745 + if (ret)
51746 + return ret;
51747 +
51748 + if (o_tmp->nested) {
51749 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51750 + if (IS_ERR(o_tmp->nested))
51751 + return PTR_ERR(o_tmp->nested);
51752 +
51753 + /* insert into nested subject list */
51754 + o_tmp->nested->next = role->hash->first;
51755 + role->hash->first = o_tmp->nested;
51756 + }
51757 + }
51758 +
51759 + return 0;
51760 +}
51761 +
51762 +static __u32
51763 +count_user_subjs(struct acl_subject_label *userp)
51764 +{
51765 + struct acl_subject_label s_tmp;
51766 + __u32 num = 0;
51767 +
51768 + while (userp) {
51769 + if (copy_from_user(&s_tmp, userp,
51770 + sizeof (struct acl_subject_label)))
51771 + break;
51772 +
51773 + userp = s_tmp.prev;
51774 + /* do not count nested subjects against this count, since
51775 + they are not included in the hash table, but are
51776 + attached to objects. We have already counted
51777 + the subjects in userspace for the allocation
51778 + stack
51779 + */
51780 + if (!(s_tmp.mode & GR_NESTED))
51781 + num++;
51782 + }
51783 +
51784 + return num;
51785 +}
51786 +
51787 +static int
51788 +copy_user_allowedips(struct acl_role_label *rolep)
51789 +{
51790 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51791 +
51792 + ruserip = rolep->allowed_ips;
51793 +
51794 + while (ruserip) {
51795 + rlast = rtmp;
51796 +
51797 + if ((rtmp = (struct role_allowed_ip *)
51798 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51799 + return -ENOMEM;
51800 +
51801 + if (copy_from_user(rtmp, ruserip,
51802 + sizeof (struct role_allowed_ip)))
51803 + return -EFAULT;
51804 +
51805 + ruserip = rtmp->prev;
51806 +
51807 + if (!rlast) {
51808 + rtmp->prev = NULL;
51809 + rolep->allowed_ips = rtmp;
51810 + } else {
51811 + rlast->next = rtmp;
51812 + rtmp->prev = rlast;
51813 + }
51814 +
51815 + if (!ruserip)
51816 + rtmp->next = NULL;
51817 + }
51818 +
51819 + return 0;
51820 +}
51821 +
51822 +static int
51823 +copy_user_transitions(struct acl_role_label *rolep)
51824 +{
51825 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51826 +
51827 + unsigned int len;
51828 + char *tmp;
51829 +
51830 + rusertp = rolep->transitions;
51831 +
51832 + while (rusertp) {
51833 + rlast = rtmp;
51834 +
51835 + if ((rtmp = (struct role_transition *)
51836 + acl_alloc(sizeof (struct role_transition))) == NULL)
51837 + return -ENOMEM;
51838 +
51839 + if (copy_from_user(rtmp, rusertp,
51840 + sizeof (struct role_transition)))
51841 + return -EFAULT;
51842 +
51843 + rusertp = rtmp->prev;
51844 +
51845 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51846 +
51847 + if (!len || len >= GR_SPROLE_LEN)
51848 + return -EINVAL;
51849 +
51850 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51851 + return -ENOMEM;
51852 +
51853 + if (copy_from_user(tmp, rtmp->rolename, len))
51854 + return -EFAULT;
51855 + tmp[len-1] = '\0';
51856 + rtmp->rolename = tmp;
51857 +
51858 + if (!rlast) {
51859 + rtmp->prev = NULL;
51860 + rolep->transitions = rtmp;
51861 + } else {
51862 + rlast->next = rtmp;
51863 + rtmp->prev = rlast;
51864 + }
51865 +
51866 + if (!rusertp)
51867 + rtmp->next = NULL;
51868 + }
51869 +
51870 + return 0;
51871 +}
51872 +
51873 +static struct acl_subject_label *
51874 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51875 +{
51876 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51877 + unsigned int len;
51878 + char *tmp;
51879 + __u32 num_objs;
51880 + struct acl_ip_label **i_tmp, *i_utmp2;
51881 + struct gr_hash_struct ghash;
51882 + struct subject_map *subjmap;
51883 + unsigned int i_num;
51884 + int err;
51885 +
51886 + s_tmp = lookup_subject_map(userp);
51887 +
51888 + /* we've already copied this subject into the kernel, just return
51889 + the reference to it, and don't copy it over again
51890 + */
51891 + if (s_tmp)
51892 + return(s_tmp);
51893 +
51894 + if ((s_tmp = (struct acl_subject_label *)
51895 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51896 + return ERR_PTR(-ENOMEM);
51897 +
51898 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51899 + if (subjmap == NULL)
51900 + return ERR_PTR(-ENOMEM);
51901 +
51902 + subjmap->user = userp;
51903 + subjmap->kernel = s_tmp;
51904 + insert_subj_map_entry(subjmap);
51905 +
51906 + if (copy_from_user(s_tmp, userp,
51907 + sizeof (struct acl_subject_label)))
51908 + return ERR_PTR(-EFAULT);
51909 +
51910 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51911 +
51912 + if (!len || len >= PATH_MAX)
51913 + return ERR_PTR(-EINVAL);
51914 +
51915 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51916 + return ERR_PTR(-ENOMEM);
51917 +
51918 + if (copy_from_user(tmp, s_tmp->filename, len))
51919 + return ERR_PTR(-EFAULT);
51920 + tmp[len-1] = '\0';
51921 + s_tmp->filename = tmp;
51922 +
51923 + if (!strcmp(s_tmp->filename, "/"))
51924 + role->root_label = s_tmp;
51925 +
51926 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51927 + return ERR_PTR(-EFAULT);
51928 +
51929 + /* copy user and group transition tables */
51930 +
51931 + if (s_tmp->user_trans_num) {
51932 + uid_t *uidlist;
51933 +
51934 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51935 + if (uidlist == NULL)
51936 + return ERR_PTR(-ENOMEM);
51937 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51938 + return ERR_PTR(-EFAULT);
51939 +
51940 + s_tmp->user_transitions = uidlist;
51941 + }
51942 +
51943 + if (s_tmp->group_trans_num) {
51944 + gid_t *gidlist;
51945 +
51946 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51947 + if (gidlist == NULL)
51948 + return ERR_PTR(-ENOMEM);
51949 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51950 + return ERR_PTR(-EFAULT);
51951 +
51952 + s_tmp->group_transitions = gidlist;
51953 + }
51954 +
51955 + /* set up object hash table */
51956 + num_objs = count_user_objs(ghash.first);
51957 +
51958 + s_tmp->obj_hash_size = num_objs;
51959 + s_tmp->obj_hash =
51960 + (struct acl_object_label **)
51961 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51962 +
51963 + if (!s_tmp->obj_hash)
51964 + return ERR_PTR(-ENOMEM);
51965 +
51966 + memset(s_tmp->obj_hash, 0,
51967 + s_tmp->obj_hash_size *
51968 + sizeof (struct acl_object_label *));
51969 +
51970 + /* add in objects */
51971 + err = copy_user_objs(ghash.first, s_tmp, role);
51972 +
51973 + if (err)
51974 + return ERR_PTR(err);
51975 +
51976 + /* set pointer for parent subject */
51977 + if (s_tmp->parent_subject) {
51978 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51979 +
51980 + if (IS_ERR(s_tmp2))
51981 + return s_tmp2;
51982 +
51983 + s_tmp->parent_subject = s_tmp2;
51984 + }
51985 +
51986 + /* add in ip acls */
51987 +
51988 + if (!s_tmp->ip_num) {
51989 + s_tmp->ips = NULL;
51990 + goto insert;
51991 + }
51992 +
51993 + i_tmp =
51994 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51995 + sizeof (struct acl_ip_label *));
51996 +
51997 + if (!i_tmp)
51998 + return ERR_PTR(-ENOMEM);
51999 +
52000 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52001 + *(i_tmp + i_num) =
52002 + (struct acl_ip_label *)
52003 + acl_alloc(sizeof (struct acl_ip_label));
52004 + if (!*(i_tmp + i_num))
52005 + return ERR_PTR(-ENOMEM);
52006 +
52007 + if (copy_from_user
52008 + (&i_utmp2, s_tmp->ips + i_num,
52009 + sizeof (struct acl_ip_label *)))
52010 + return ERR_PTR(-EFAULT);
52011 +
52012 + if (copy_from_user
52013 + (*(i_tmp + i_num), i_utmp2,
52014 + sizeof (struct acl_ip_label)))
52015 + return ERR_PTR(-EFAULT);
52016 +
52017 + if ((*(i_tmp + i_num))->iface == NULL)
52018 + continue;
52019 +
52020 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52021 + if (!len || len >= IFNAMSIZ)
52022 + return ERR_PTR(-EINVAL);
52023 + tmp = acl_alloc(len);
52024 + if (tmp == NULL)
52025 + return ERR_PTR(-ENOMEM);
52026 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52027 + return ERR_PTR(-EFAULT);
52028 + (*(i_tmp + i_num))->iface = tmp;
52029 + }
52030 +
52031 + s_tmp->ips = i_tmp;
52032 +
52033 +insert:
52034 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52035 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52036 + return ERR_PTR(-ENOMEM);
52037 +
52038 + return s_tmp;
52039 +}
52040 +
52041 +static int
52042 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52043 +{
52044 + struct acl_subject_label s_pre;
52045 + struct acl_subject_label * ret;
52046 + int err;
52047 +
52048 + while (userp) {
52049 + if (copy_from_user(&s_pre, userp,
52050 + sizeof (struct acl_subject_label)))
52051 + return -EFAULT;
52052 +
52053 + /* do not add nested subjects here, add
52054 + while parsing objects
52055 + */
52056 +
52057 + if (s_pre.mode & GR_NESTED) {
52058 + userp = s_pre.prev;
52059 + continue;
52060 + }
52061 +
52062 + ret = do_copy_user_subj(userp, role);
52063 +
52064 + err = PTR_ERR(ret);
52065 + if (IS_ERR(ret))
52066 + return err;
52067 +
52068 + insert_acl_subj_label(ret, role);
52069 +
52070 + userp = s_pre.prev;
52071 + }
52072 +
52073 + return 0;
52074 +}
52075 +
52076 +static int
52077 +copy_user_acl(struct gr_arg *arg)
52078 +{
52079 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52080 + struct sprole_pw *sptmp;
52081 + struct gr_hash_struct *ghash;
52082 + uid_t *domainlist;
52083 + unsigned int r_num;
52084 + unsigned int len;
52085 + char *tmp;
52086 + int err = 0;
52087 + __u16 i;
52088 + __u32 num_subjs;
52089 +
52090 + /* we need a default and kernel role */
52091 + if (arg->role_db.num_roles < 2)
52092 + return -EINVAL;
52093 +
52094 + /* copy special role authentication info from userspace */
52095 +
52096 + num_sprole_pws = arg->num_sprole_pws;
52097 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52098 +
52099 + if (!acl_special_roles && num_sprole_pws)
52100 + return -ENOMEM;
52101 +
52102 + for (i = 0; i < num_sprole_pws; i++) {
52103 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52104 + if (!sptmp)
52105 + return -ENOMEM;
52106 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52107 + sizeof (struct sprole_pw)))
52108 + return -EFAULT;
52109 +
52110 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52111 +
52112 + if (!len || len >= GR_SPROLE_LEN)
52113 + return -EINVAL;
52114 +
52115 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52116 + return -ENOMEM;
52117 +
52118 + if (copy_from_user(tmp, sptmp->rolename, len))
52119 + return -EFAULT;
52120 +
52121 + tmp[len-1] = '\0';
52122 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52123 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52124 +#endif
52125 + sptmp->rolename = tmp;
52126 + acl_special_roles[i] = sptmp;
52127 + }
52128 +
52129 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52130 +
52131 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52132 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52133 +
52134 + if (!r_tmp)
52135 + return -ENOMEM;
52136 +
52137 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52138 + sizeof (struct acl_role_label *)))
52139 + return -EFAULT;
52140 +
52141 + if (copy_from_user(r_tmp, r_utmp2,
52142 + sizeof (struct acl_role_label)))
52143 + return -EFAULT;
52144 +
52145 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52146 +
52147 + if (!len || len >= PATH_MAX)
52148 + return -EINVAL;
52149 +
52150 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52151 + return -ENOMEM;
52152 +
52153 + if (copy_from_user(tmp, r_tmp->rolename, len))
52154 + return -EFAULT;
52155 +
52156 + tmp[len-1] = '\0';
52157 + r_tmp->rolename = tmp;
52158 +
52159 + if (!strcmp(r_tmp->rolename, "default")
52160 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52161 + default_role = r_tmp;
52162 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52163 + kernel_role = r_tmp;
52164 + }
52165 +
52166 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52167 + return -ENOMEM;
52168 +
52169 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52170 + return -EFAULT;
52171 +
52172 + r_tmp->hash = ghash;
52173 +
52174 + num_subjs = count_user_subjs(r_tmp->hash->first);
52175 +
52176 + r_tmp->subj_hash_size = num_subjs;
52177 + r_tmp->subj_hash =
52178 + (struct acl_subject_label **)
52179 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52180 +
52181 + if (!r_tmp->subj_hash)
52182 + return -ENOMEM;
52183 +
52184 + err = copy_user_allowedips(r_tmp);
52185 + if (err)
52186 + return err;
52187 +
52188 + /* copy domain info */
52189 + if (r_tmp->domain_children != NULL) {
52190 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52191 + if (domainlist == NULL)
52192 + return -ENOMEM;
52193 +
52194 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52195 + return -EFAULT;
52196 +
52197 + r_tmp->domain_children = domainlist;
52198 + }
52199 +
52200 + err = copy_user_transitions(r_tmp);
52201 + if (err)
52202 + return err;
52203 +
52204 + memset(r_tmp->subj_hash, 0,
52205 + r_tmp->subj_hash_size *
52206 + sizeof (struct acl_subject_label *));
52207 +
52208 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52209 +
52210 + if (err)
52211 + return err;
52212 +
52213 + /* set nested subject list to null */
52214 + r_tmp->hash->first = NULL;
52215 +
52216 + insert_acl_role_label(r_tmp);
52217 + }
52218 +
52219 + if (default_role == NULL || kernel_role == NULL)
52220 + return -EINVAL;
52221 +
52222 + return err;
52223 +}
52224 +
52225 +static int
52226 +gracl_init(struct gr_arg *args)
52227 +{
52228 + int error = 0;
52229 +
52230 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52231 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52232 +
52233 + if (init_variables(args)) {
52234 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52235 + error = -ENOMEM;
52236 + free_variables();
52237 + goto out;
52238 + }
52239 +
52240 + error = copy_user_acl(args);
52241 + free_init_variables();
52242 + if (error) {
52243 + free_variables();
52244 + goto out;
52245 + }
52246 +
52247 + if ((error = gr_set_acls(0))) {
52248 + free_variables();
52249 + goto out;
52250 + }
52251 +
52252 + pax_open_kernel();
52253 + gr_status |= GR_READY;
52254 + pax_close_kernel();
52255 +
52256 + out:
52257 + return error;
52258 +}
52259 +
52260 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52261 +
52262 +static int
52263 +glob_match(const char *p, const char *n)
52264 +{
52265 + char c;
52266 +
52267 + while ((c = *p++) != '\0') {
52268 + switch (c) {
52269 + case '?':
52270 + if (*n == '\0')
52271 + return 1;
52272 + else if (*n == '/')
52273 + return 1;
52274 + break;
52275 + case '\\':
52276 + if (*n != c)
52277 + return 1;
52278 + break;
52279 + case '*':
52280 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52281 + if (*n == '/')
52282 + return 1;
52283 + else if (c == '?') {
52284 + if (*n == '\0')
52285 + return 1;
52286 + else
52287 + ++n;
52288 + }
52289 + }
52290 + if (c == '\0') {
52291 + return 0;
52292 + } else {
52293 + const char *endp;
52294 +
52295 + if ((endp = strchr(n, '/')) == NULL)
52296 + endp = n + strlen(n);
52297 +
52298 + if (c == '[') {
52299 + for (--p; n < endp; ++n)
52300 + if (!glob_match(p, n))
52301 + return 0;
52302 + } else if (c == '/') {
52303 + while (*n != '\0' && *n != '/')
52304 + ++n;
52305 + if (*n == '/' && !glob_match(p, n + 1))
52306 + return 0;
52307 + } else {
52308 + for (--p; n < endp; ++n)
52309 + if (*n == c && !glob_match(p, n))
52310 + return 0;
52311 + }
52312 +
52313 + return 1;
52314 + }
52315 + case '[':
52316 + {
52317 + int not;
52318 + char cold;
52319 +
52320 + if (*n == '\0' || *n == '/')
52321 + return 1;
52322 +
52323 + not = (*p == '!' || *p == '^');
52324 + if (not)
52325 + ++p;
52326 +
52327 + c = *p++;
52328 + for (;;) {
52329 + unsigned char fn = (unsigned char)*n;
52330 +
52331 + if (c == '\0')
52332 + return 1;
52333 + else {
52334 + if (c == fn)
52335 + goto matched;
52336 + cold = c;
52337 + c = *p++;
52338 +
52339 + if (c == '-' && *p != ']') {
52340 + unsigned char cend = *p++;
52341 +
52342 + if (cend == '\0')
52343 + return 1;
52344 +
52345 + if (cold <= fn && fn <= cend)
52346 + goto matched;
52347 +
52348 + c = *p++;
52349 + }
52350 + }
52351 +
52352 + if (c == ']')
52353 + break;
52354 + }
52355 + if (!not)
52356 + return 1;
52357 + break;
52358 + matched:
52359 + while (c != ']') {
52360 + if (c == '\0')
52361 + return 1;
52362 +
52363 + c = *p++;
52364 + }
52365 + if (not)
52366 + return 1;
52367 + }
52368 + break;
52369 + default:
52370 + if (c != *n)
52371 + return 1;
52372 + }
52373 +
52374 + ++n;
52375 + }
52376 +
52377 + if (*n == '\0')
52378 + return 0;
52379 +
52380 + if (*n == '/')
52381 + return 0;
52382 +
52383 + return 1;
52384 +}
52385 +
52386 +static struct acl_object_label *
52387 +chk_glob_label(struct acl_object_label *globbed,
52388 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52389 +{
52390 + struct acl_object_label *tmp;
52391 +
52392 + if (*path == NULL)
52393 + *path = gr_to_filename_nolock(dentry, mnt);
52394 +
52395 + tmp = globbed;
52396 +
52397 + while (tmp) {
52398 + if (!glob_match(tmp->filename, *path))
52399 + return tmp;
52400 + tmp = tmp->next;
52401 + }
52402 +
52403 + return NULL;
52404 +}
52405 +
52406 +static struct acl_object_label *
52407 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52408 + const ino_t curr_ino, const dev_t curr_dev,
52409 + const struct acl_subject_label *subj, char **path, const int checkglob)
52410 +{
52411 + struct acl_subject_label *tmpsubj;
52412 + struct acl_object_label *retval;
52413 + struct acl_object_label *retval2;
52414 +
52415 + tmpsubj = (struct acl_subject_label *) subj;
52416 + read_lock(&gr_inode_lock);
52417 + do {
52418 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52419 + if (retval) {
52420 + if (checkglob && retval->globbed) {
52421 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52422 + if (retval2)
52423 + retval = retval2;
52424 + }
52425 + break;
52426 + }
52427 + } while ((tmpsubj = tmpsubj->parent_subject));
52428 + read_unlock(&gr_inode_lock);
52429 +
52430 + return retval;
52431 +}
52432 +
52433 +static __inline__ struct acl_object_label *
52434 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52435 + struct dentry *curr_dentry,
52436 + const struct acl_subject_label *subj, char **path, const int checkglob)
52437 +{
52438 + int newglob = checkglob;
52439 + ino_t inode;
52440 + dev_t device;
52441 +
52442 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52443 + as we don't want a / * rule to match instead of the / object
52444 + don't do this for create lookups that call this function though, since they're looking up
52445 + on the parent and thus need globbing checks on all paths
52446 + */
52447 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52448 + newglob = GR_NO_GLOB;
52449 +
52450 + spin_lock(&curr_dentry->d_lock);
52451 + inode = curr_dentry->d_inode->i_ino;
52452 + device = __get_dev(curr_dentry);
52453 + spin_unlock(&curr_dentry->d_lock);
52454 +
52455 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52456 +}
52457 +
52458 +static struct acl_object_label *
52459 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52460 + const struct acl_subject_label *subj, char *path, const int checkglob)
52461 +{
52462 + struct dentry *dentry = (struct dentry *) l_dentry;
52463 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52464 + struct mount *real_mnt = real_mount(mnt);
52465 + struct acl_object_label *retval;
52466 + struct dentry *parent;
52467 +
52468 + write_seqlock(&rename_lock);
52469 + br_read_lock(vfsmount_lock);
52470 +
52471 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52472 +#ifdef CONFIG_NET
52473 + mnt == sock_mnt ||
52474 +#endif
52475 +#ifdef CONFIG_HUGETLBFS
52476 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52477 +#endif
52478 + /* ignore Eric Biederman */
52479 + IS_PRIVATE(l_dentry->d_inode))) {
52480 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52481 + goto out;
52482 + }
52483 +
52484 + for (;;) {
52485 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52486 + break;
52487 +
52488 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52489 + if (!mnt_has_parent(real_mnt))
52490 + break;
52491 +
52492 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52493 + if (retval != NULL)
52494 + goto out;
52495 +
52496 + dentry = real_mnt->mnt_mountpoint;
52497 + real_mnt = real_mnt->mnt_parent;
52498 + mnt = &real_mnt->mnt;
52499 + continue;
52500 + }
52501 +
52502 + parent = dentry->d_parent;
52503 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52504 + if (retval != NULL)
52505 + goto out;
52506 +
52507 + dentry = parent;
52508 + }
52509 +
52510 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52511 +
52512 + /* real_root is pinned so we don't have to hold a reference */
52513 + if (retval == NULL)
52514 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52515 +out:
52516 + br_read_unlock(vfsmount_lock);
52517 + write_sequnlock(&rename_lock);
52518 +
52519 + BUG_ON(retval == NULL);
52520 +
52521 + return retval;
52522 +}
52523 +
52524 +static __inline__ struct acl_object_label *
52525 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52526 + const struct acl_subject_label *subj)
52527 +{
52528 + char *path = NULL;
52529 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52530 +}
52531 +
52532 +static __inline__ struct acl_object_label *
52533 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52534 + const struct acl_subject_label *subj)
52535 +{
52536 + char *path = NULL;
52537 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52538 +}
52539 +
52540 +static __inline__ struct acl_object_label *
52541 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52542 + const struct acl_subject_label *subj, char *path)
52543 +{
52544 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52545 +}
52546 +
52547 +static struct acl_subject_label *
52548 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52549 + const struct acl_role_label *role)
52550 +{
52551 + struct dentry *dentry = (struct dentry *) l_dentry;
52552 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52553 + struct mount *real_mnt = real_mount(mnt);
52554 + struct acl_subject_label *retval;
52555 + struct dentry *parent;
52556 +
52557 + write_seqlock(&rename_lock);
52558 + br_read_lock(vfsmount_lock);
52559 +
52560 + for (;;) {
52561 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52562 + break;
52563 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52564 + if (!mnt_has_parent(real_mnt))
52565 + break;
52566 +
52567 + spin_lock(&dentry->d_lock);
52568 + read_lock(&gr_inode_lock);
52569 + retval =
52570 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52571 + __get_dev(dentry), role);
52572 + read_unlock(&gr_inode_lock);
52573 + spin_unlock(&dentry->d_lock);
52574 + if (retval != NULL)
52575 + goto out;
52576 +
52577 + dentry = real_mnt->mnt_mountpoint;
52578 + real_mnt = real_mnt->mnt_parent;
52579 + mnt = &real_mnt->mnt;
52580 + continue;
52581 + }
52582 +
52583 + spin_lock(&dentry->d_lock);
52584 + read_lock(&gr_inode_lock);
52585 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52586 + __get_dev(dentry), role);
52587 + read_unlock(&gr_inode_lock);
52588 + parent = dentry->d_parent;
52589 + spin_unlock(&dentry->d_lock);
52590 +
52591 + if (retval != NULL)
52592 + goto out;
52593 +
52594 + dentry = parent;
52595 + }
52596 +
52597 + spin_lock(&dentry->d_lock);
52598 + read_lock(&gr_inode_lock);
52599 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52600 + __get_dev(dentry), role);
52601 + read_unlock(&gr_inode_lock);
52602 + spin_unlock(&dentry->d_lock);
52603 +
52604 + if (unlikely(retval == NULL)) {
52605 + /* real_root is pinned, we don't need to hold a reference */
52606 + read_lock(&gr_inode_lock);
52607 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52608 + __get_dev(real_root.dentry), role);
52609 + read_unlock(&gr_inode_lock);
52610 + }
52611 +out:
52612 + br_read_unlock(vfsmount_lock);
52613 + write_sequnlock(&rename_lock);
52614 +
52615 + BUG_ON(retval == NULL);
52616 +
52617 + return retval;
52618 +}
52619 +
52620 +static void
52621 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52622 +{
52623 + struct task_struct *task = current;
52624 + const struct cred *cred = current_cred();
52625 +
52626 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52627 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52628 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52629 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52630 +
52631 + return;
52632 +}
52633 +
52634 +static void
52635 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52636 +{
52637 + struct task_struct *task = current;
52638 + const struct cred *cred = current_cred();
52639 +
52640 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52641 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52642 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52643 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52644 +
52645 + return;
52646 +}
52647 +
52648 +static void
52649 +gr_log_learn_id_change(const char type, const unsigned int real,
52650 + const unsigned int effective, const unsigned int fs)
52651 +{
52652 + struct task_struct *task = current;
52653 + const struct cred *cred = current_cred();
52654 +
52655 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52656 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52657 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52658 + type, real, effective, fs, &task->signal->saved_ip);
52659 +
52660 + return;
52661 +}
52662 +
52663 +__u32
52664 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52665 + const struct vfsmount * mnt)
52666 +{
52667 + __u32 retval = mode;
52668 + struct acl_subject_label *curracl;
52669 + struct acl_object_label *currobj;
52670 +
52671 + if (unlikely(!(gr_status & GR_READY)))
52672 + return (mode & ~GR_AUDITS);
52673 +
52674 + curracl = current->acl;
52675 +
52676 + currobj = chk_obj_label(dentry, mnt, curracl);
52677 + retval = currobj->mode & mode;
52678 +
52679 + /* if we're opening a specified transfer file for writing
52680 + (e.g. /dev/initctl), then transfer our role to init
52681 + */
52682 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52683 + current->role->roletype & GR_ROLE_PERSIST)) {
52684 + struct task_struct *task = init_pid_ns.child_reaper;
52685 +
52686 + if (task->role != current->role) {
52687 + task->acl_sp_role = 0;
52688 + task->acl_role_id = current->acl_role_id;
52689 + task->role = current->role;
52690 + rcu_read_lock();
52691 + read_lock(&grsec_exec_file_lock);
52692 + gr_apply_subject_to_task(task);
52693 + read_unlock(&grsec_exec_file_lock);
52694 + rcu_read_unlock();
52695 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52696 + }
52697 + }
52698 +
52699 + if (unlikely
52700 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52701 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52702 + __u32 new_mode = mode;
52703 +
52704 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52705 +
52706 + retval = new_mode;
52707 +
52708 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52709 + new_mode |= GR_INHERIT;
52710 +
52711 + if (!(mode & GR_NOLEARN))
52712 + gr_log_learn(dentry, mnt, new_mode);
52713 + }
52714 +
52715 + return retval;
52716 +}
52717 +
52718 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52719 + const struct dentry *parent,
52720 + const struct vfsmount *mnt)
52721 +{
52722 + struct name_entry *match;
52723 + struct acl_object_label *matchpo;
52724 + struct acl_subject_label *curracl;
52725 + char *path;
52726 +
52727 + if (unlikely(!(gr_status & GR_READY)))
52728 + return NULL;
52729 +
52730 + preempt_disable();
52731 + path = gr_to_filename_rbac(new_dentry, mnt);
52732 + match = lookup_name_entry_create(path);
52733 +
52734 + curracl = current->acl;
52735 +
52736 + if (match) {
52737 + read_lock(&gr_inode_lock);
52738 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52739 + read_unlock(&gr_inode_lock);
52740 +
52741 + if (matchpo) {
52742 + preempt_enable();
52743 + return matchpo;
52744 + }
52745 + }
52746 +
52747 + // lookup parent
52748 +
52749 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52750 +
52751 + preempt_enable();
52752 + return matchpo;
52753 +}
52754 +
52755 +__u32
52756 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52757 + const struct vfsmount * mnt, const __u32 mode)
52758 +{
52759 + struct acl_object_label *matchpo;
52760 + __u32 retval;
52761 +
52762 + if (unlikely(!(gr_status & GR_READY)))
52763 + return (mode & ~GR_AUDITS);
52764 +
52765 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52766 +
52767 + retval = matchpo->mode & mode;
52768 +
52769 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52770 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52771 + __u32 new_mode = mode;
52772 +
52773 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52774 +
52775 + gr_log_learn(new_dentry, mnt, new_mode);
52776 + return new_mode;
52777 + }
52778 +
52779 + return retval;
52780 +}
52781 +
52782 +__u32
52783 +gr_check_link(const struct dentry * new_dentry,
52784 + const struct dentry * parent_dentry,
52785 + const struct vfsmount * parent_mnt,
52786 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52787 +{
52788 + struct acl_object_label *obj;
52789 + __u32 oldmode, newmode;
52790 + __u32 needmode;
52791 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52792 + GR_DELETE | GR_INHERIT;
52793 +
52794 + if (unlikely(!(gr_status & GR_READY)))
52795 + return (GR_CREATE | GR_LINK);
52796 +
52797 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52798 + oldmode = obj->mode;
52799 +
52800 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52801 + newmode = obj->mode;
52802 +
52803 + needmode = newmode & checkmodes;
52804 +
52805 + // old name for hardlink must have at least the permissions of the new name
52806 + if ((oldmode & needmode) != needmode)
52807 + goto bad;
52808 +
52809 + // if old name had restrictions/auditing, make sure the new name does as well
52810 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52811 +
52812 + // don't allow hardlinking of suid/sgid files without permission
52813 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52814 + needmode |= GR_SETID;
52815 +
52816 + if ((newmode & needmode) != needmode)
52817 + goto bad;
52818 +
52819 + // enforce minimum permissions
52820 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52821 + return newmode;
52822 +bad:
52823 + needmode = oldmode;
52824 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52825 + needmode |= GR_SETID;
52826 +
52827 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52828 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52829 + return (GR_CREATE | GR_LINK);
52830 + } else if (newmode & GR_SUPPRESS)
52831 + return GR_SUPPRESS;
52832 + else
52833 + return 0;
52834 +}
52835 +
52836 +int
52837 +gr_check_hidden_task(const struct task_struct *task)
52838 +{
52839 + if (unlikely(!(gr_status & GR_READY)))
52840 + return 0;
52841 +
52842 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52843 + return 1;
52844 +
52845 + return 0;
52846 +}
52847 +
52848 +int
52849 +gr_check_protected_task(const struct task_struct *task)
52850 +{
52851 + if (unlikely(!(gr_status & GR_READY) || !task))
52852 + return 0;
52853 +
52854 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52855 + task->acl != current->acl)
52856 + return 1;
52857 +
52858 + return 0;
52859 +}
52860 +
52861 +int
52862 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52863 +{
52864 + struct task_struct *p;
52865 + int ret = 0;
52866 +
52867 + if (unlikely(!(gr_status & GR_READY) || !pid))
52868 + return ret;
52869 +
52870 + read_lock(&tasklist_lock);
52871 + do_each_pid_task(pid, type, p) {
52872 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52873 + p->acl != current->acl) {
52874 + ret = 1;
52875 + goto out;
52876 + }
52877 + } while_each_pid_task(pid, type, p);
52878 +out:
52879 + read_unlock(&tasklist_lock);
52880 +
52881 + return ret;
52882 +}
52883 +
52884 +void
52885 +gr_copy_label(struct task_struct *tsk)
52886 +{
52887 + /* plain copying of fields is already done by dup_task_struct */
52888 + tsk->signal->used_accept = 0;
52889 + tsk->acl_sp_role = 0;
52890 + //tsk->acl_role_id = current->acl_role_id;
52891 + //tsk->acl = current->acl;
52892 + //tsk->role = current->role;
52893 + tsk->signal->curr_ip = current->signal->curr_ip;
52894 + tsk->signal->saved_ip = current->signal->saved_ip;
52895 + if (current->exec_file)
52896 + get_file(current->exec_file);
52897 + //tsk->exec_file = current->exec_file;
52898 + //tsk->is_writable = current->is_writable;
52899 + if (unlikely(current->signal->used_accept)) {
52900 + current->signal->curr_ip = 0;
52901 + current->signal->saved_ip = 0;
52902 + }
52903 +
52904 + return;
52905 +}
52906 +
52907 +static void
52908 +gr_set_proc_res(struct task_struct *task)
52909 +{
52910 + struct acl_subject_label *proc;
52911 + unsigned short i;
52912 +
52913 + proc = task->acl;
52914 +
52915 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52916 + return;
52917 +
52918 + for (i = 0; i < RLIM_NLIMITS; i++) {
52919 + if (!(proc->resmask & (1 << i)))
52920 + continue;
52921 +
52922 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52923 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52924 + }
52925 +
52926 + return;
52927 +}
52928 +
52929 +extern int __gr_process_user_ban(struct user_struct *user);
52930 +
52931 +int
52932 +gr_check_user_change(int real, int effective, int fs)
52933 +{
52934 + unsigned int i;
52935 + __u16 num;
52936 + uid_t *uidlist;
52937 + int curuid;
52938 + int realok = 0;
52939 + int effectiveok = 0;
52940 + int fsok = 0;
52941 +
52942 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52943 + struct user_struct *user;
52944 +
52945 + if (real == -1)
52946 + goto skipit;
52947 +
52948 + user = find_user(real);
52949 + if (user == NULL)
52950 + goto skipit;
52951 +
52952 + if (__gr_process_user_ban(user)) {
52953 + /* for find_user */
52954 + free_uid(user);
52955 + return 1;
52956 + }
52957 +
52958 + /* for find_user */
52959 + free_uid(user);
52960 +
52961 +skipit:
52962 +#endif
52963 +
52964 + if (unlikely(!(gr_status & GR_READY)))
52965 + return 0;
52966 +
52967 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52968 + gr_log_learn_id_change('u', real, effective, fs);
52969 +
52970 + num = current->acl->user_trans_num;
52971 + uidlist = current->acl->user_transitions;
52972 +
52973 + if (uidlist == NULL)
52974 + return 0;
52975 +
52976 + if (real == -1)
52977 + realok = 1;
52978 + if (effective == -1)
52979 + effectiveok = 1;
52980 + if (fs == -1)
52981 + fsok = 1;
52982 +
52983 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52984 + for (i = 0; i < num; i++) {
52985 + curuid = (int)uidlist[i];
52986 + if (real == curuid)
52987 + realok = 1;
52988 + if (effective == curuid)
52989 + effectiveok = 1;
52990 + if (fs == curuid)
52991 + fsok = 1;
52992 + }
52993 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52994 + for (i = 0; i < num; i++) {
52995 + curuid = (int)uidlist[i];
52996 + if (real == curuid)
52997 + break;
52998 + if (effective == curuid)
52999 + break;
53000 + if (fs == curuid)
53001 + break;
53002 + }
53003 + /* not in deny list */
53004 + if (i == num) {
53005 + realok = 1;
53006 + effectiveok = 1;
53007 + fsok = 1;
53008 + }
53009 + }
53010 +
53011 + if (realok && effectiveok && fsok)
53012 + return 0;
53013 + else {
53014 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53015 + return 1;
53016 + }
53017 +}
53018 +
53019 +int
53020 +gr_check_group_change(int real, int effective, int fs)
53021 +{
53022 + unsigned int i;
53023 + __u16 num;
53024 + gid_t *gidlist;
53025 + int curgid;
53026 + int realok = 0;
53027 + int effectiveok = 0;
53028 + int fsok = 0;
53029 +
53030 + if (unlikely(!(gr_status & GR_READY)))
53031 + return 0;
53032 +
53033 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53034 + gr_log_learn_id_change('g', real, effective, fs);
53035 +
53036 + num = current->acl->group_trans_num;
53037 + gidlist = current->acl->group_transitions;
53038 +
53039 + if (gidlist == NULL)
53040 + return 0;
53041 +
53042 + if (real == -1)
53043 + realok = 1;
53044 + if (effective == -1)
53045 + effectiveok = 1;
53046 + if (fs == -1)
53047 + fsok = 1;
53048 +
53049 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53050 + for (i = 0; i < num; i++) {
53051 + curgid = (int)gidlist[i];
53052 + if (real == curgid)
53053 + realok = 1;
53054 + if (effective == curgid)
53055 + effectiveok = 1;
53056 + if (fs == curgid)
53057 + fsok = 1;
53058 + }
53059 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53060 + for (i = 0; i < num; i++) {
53061 + curgid = (int)gidlist[i];
53062 + if (real == curgid)
53063 + break;
53064 + if (effective == curgid)
53065 + break;
53066 + if (fs == curgid)
53067 + break;
53068 + }
53069 + /* not in deny list */
53070 + if (i == num) {
53071 + realok = 1;
53072 + effectiveok = 1;
53073 + fsok = 1;
53074 + }
53075 + }
53076 +
53077 + if (realok && effectiveok && fsok)
53078 + return 0;
53079 + else {
53080 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53081 + return 1;
53082 + }
53083 +}
53084 +
53085 +extern int gr_acl_is_capable(const int cap);
53086 +
53087 +void
53088 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53089 +{
53090 + struct acl_role_label *role = task->role;
53091 + struct acl_subject_label *subj = NULL;
53092 + struct acl_object_label *obj;
53093 + struct file *filp;
53094 +
53095 + if (unlikely(!(gr_status & GR_READY)))
53096 + return;
53097 +
53098 + filp = task->exec_file;
53099 +
53100 + /* kernel process, we'll give them the kernel role */
53101 + if (unlikely(!filp)) {
53102 + task->role = kernel_role;
53103 + task->acl = kernel_role->root_label;
53104 + return;
53105 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53106 + role = lookup_acl_role_label(task, uid, gid);
53107 +
53108 + /* don't change the role if we're not a privileged process */
53109 + if (role && task->role != role &&
53110 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53111 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53112 + return;
53113 +
53114 + /* perform subject lookup in possibly new role
53115 + we can use this result below in the case where role == task->role
53116 + */
53117 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53118 +
53119 + /* if we changed uid/gid, but result in the same role
53120 + and are using inheritance, don't lose the inherited subject
53121 + if current subject is other than what normal lookup
53122 + would result in, we arrived via inheritance, don't
53123 + lose subject
53124 + */
53125 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53126 + (subj == task->acl)))
53127 + task->acl = subj;
53128 +
53129 + task->role = role;
53130 +
53131 + task->is_writable = 0;
53132 +
53133 + /* ignore additional mmap checks for processes that are writable
53134 + by the default ACL */
53135 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53136 + if (unlikely(obj->mode & GR_WRITE))
53137 + task->is_writable = 1;
53138 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53139 + if (unlikely(obj->mode & GR_WRITE))
53140 + task->is_writable = 1;
53141 +
53142 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53143 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53144 +#endif
53145 +
53146 + gr_set_proc_res(task);
53147 +
53148 + return;
53149 +}
53150 +
53151 +int
53152 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53153 + const int unsafe_flags)
53154 +{
53155 + struct task_struct *task = current;
53156 + struct acl_subject_label *newacl;
53157 + struct acl_object_label *obj;
53158 + __u32 retmode;
53159 +
53160 + if (unlikely(!(gr_status & GR_READY)))
53161 + return 0;
53162 +
53163 + newacl = chk_subj_label(dentry, mnt, task->role);
53164 +
53165 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53166 + did an exec
53167 + */
53168 + rcu_read_lock();
53169 + read_lock(&tasklist_lock);
53170 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53171 + (task->parent->acl->mode & GR_POVERRIDE))) {
53172 + read_unlock(&tasklist_lock);
53173 + rcu_read_unlock();
53174 + goto skip_check;
53175 + }
53176 + read_unlock(&tasklist_lock);
53177 + rcu_read_unlock();
53178 +
53179 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53180 + !(task->role->roletype & GR_ROLE_GOD) &&
53181 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53182 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53183 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53184 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53185 + else
53186 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53187 + return -EACCES;
53188 + }
53189 +
53190 +skip_check:
53191 +
53192 + obj = chk_obj_label(dentry, mnt, task->acl);
53193 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53194 +
53195 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53196 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53197 + if (obj->nested)
53198 + task->acl = obj->nested;
53199 + else
53200 + task->acl = newacl;
53201 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53202 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53203 +
53204 + task->is_writable = 0;
53205 +
53206 + /* ignore additional mmap checks for processes that are writable
53207 + by the default ACL */
53208 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53209 + if (unlikely(obj->mode & GR_WRITE))
53210 + task->is_writable = 1;
53211 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53212 + if (unlikely(obj->mode & GR_WRITE))
53213 + task->is_writable = 1;
53214 +
53215 + gr_set_proc_res(task);
53216 +
53217 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53218 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53219 +#endif
53220 + return 0;
53221 +}
53222 +
53223 +/* always called with valid inodev ptr */
53224 +static void
53225 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53226 +{
53227 + struct acl_object_label *matchpo;
53228 + struct acl_subject_label *matchps;
53229 + struct acl_subject_label *subj;
53230 + struct acl_role_label *role;
53231 + unsigned int x;
53232 +
53233 + FOR_EACH_ROLE_START(role)
53234 + FOR_EACH_SUBJECT_START(role, subj, x)
53235 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53236 + matchpo->mode |= GR_DELETED;
53237 + FOR_EACH_SUBJECT_END(subj,x)
53238 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53239 + if (subj->inode == ino && subj->device == dev)
53240 + subj->mode |= GR_DELETED;
53241 + FOR_EACH_NESTED_SUBJECT_END(subj)
53242 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53243 + matchps->mode |= GR_DELETED;
53244 + FOR_EACH_ROLE_END(role)
53245 +
53246 + inodev->nentry->deleted = 1;
53247 +
53248 + return;
53249 +}
53250 +
53251 +void
53252 +gr_handle_delete(const ino_t ino, const dev_t dev)
53253 +{
53254 + struct inodev_entry *inodev;
53255 +
53256 + if (unlikely(!(gr_status & GR_READY)))
53257 + return;
53258 +
53259 + write_lock(&gr_inode_lock);
53260 + inodev = lookup_inodev_entry(ino, dev);
53261 + if (inodev != NULL)
53262 + do_handle_delete(inodev, ino, dev);
53263 + write_unlock(&gr_inode_lock);
53264 +
53265 + return;
53266 +}
53267 +
53268 +static void
53269 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53270 + const ino_t newinode, const dev_t newdevice,
53271 + struct acl_subject_label *subj)
53272 +{
53273 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53274 + struct acl_object_label *match;
53275 +
53276 + match = subj->obj_hash[index];
53277 +
53278 + while (match && (match->inode != oldinode ||
53279 + match->device != olddevice ||
53280 + !(match->mode & GR_DELETED)))
53281 + match = match->next;
53282 +
53283 + if (match && (match->inode == oldinode)
53284 + && (match->device == olddevice)
53285 + && (match->mode & GR_DELETED)) {
53286 + if (match->prev == NULL) {
53287 + subj->obj_hash[index] = match->next;
53288 + if (match->next != NULL)
53289 + match->next->prev = NULL;
53290 + } else {
53291 + match->prev->next = match->next;
53292 + if (match->next != NULL)
53293 + match->next->prev = match->prev;
53294 + }
53295 + match->prev = NULL;
53296 + match->next = NULL;
53297 + match->inode = newinode;
53298 + match->device = newdevice;
53299 + match->mode &= ~GR_DELETED;
53300 +
53301 + insert_acl_obj_label(match, subj);
53302 + }
53303 +
53304 + return;
53305 +}
53306 +
53307 +static void
53308 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53309 + const ino_t newinode, const dev_t newdevice,
53310 + struct acl_role_label *role)
53311 +{
53312 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53313 + struct acl_subject_label *match;
53314 +
53315 + match = role->subj_hash[index];
53316 +
53317 + while (match && (match->inode != oldinode ||
53318 + match->device != olddevice ||
53319 + !(match->mode & GR_DELETED)))
53320 + match = match->next;
53321 +
53322 + if (match && (match->inode == oldinode)
53323 + && (match->device == olddevice)
53324 + && (match->mode & GR_DELETED)) {
53325 + if (match->prev == NULL) {
53326 + role->subj_hash[index] = match->next;
53327 + if (match->next != NULL)
53328 + match->next->prev = NULL;
53329 + } else {
53330 + match->prev->next = match->next;
53331 + if (match->next != NULL)
53332 + match->next->prev = match->prev;
53333 + }
53334 + match->prev = NULL;
53335 + match->next = NULL;
53336 + match->inode = newinode;
53337 + match->device = newdevice;
53338 + match->mode &= ~GR_DELETED;
53339 +
53340 + insert_acl_subj_label(match, role);
53341 + }
53342 +
53343 + return;
53344 +}
53345 +
53346 +static void
53347 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53348 + const ino_t newinode, const dev_t newdevice)
53349 +{
53350 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53351 + struct inodev_entry *match;
53352 +
53353 + match = inodev_set.i_hash[index];
53354 +
53355 + while (match && (match->nentry->inode != oldinode ||
53356 + match->nentry->device != olddevice || !match->nentry->deleted))
53357 + match = match->next;
53358 +
53359 + if (match && (match->nentry->inode == oldinode)
53360 + && (match->nentry->device == olddevice) &&
53361 + match->nentry->deleted) {
53362 + if (match->prev == NULL) {
53363 + inodev_set.i_hash[index] = match->next;
53364 + if (match->next != NULL)
53365 + match->next->prev = NULL;
53366 + } else {
53367 + match->prev->next = match->next;
53368 + if (match->next != NULL)
53369 + match->next->prev = match->prev;
53370 + }
53371 + match->prev = NULL;
53372 + match->next = NULL;
53373 + match->nentry->inode = newinode;
53374 + match->nentry->device = newdevice;
53375 + match->nentry->deleted = 0;
53376 +
53377 + insert_inodev_entry(match);
53378 + }
53379 +
53380 + return;
53381 +}
53382 +
53383 +static void
53384 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53385 +{
53386 + struct acl_subject_label *subj;
53387 + struct acl_role_label *role;
53388 + unsigned int x;
53389 +
53390 + FOR_EACH_ROLE_START(role)
53391 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53392 +
53393 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53394 + if ((subj->inode == ino) && (subj->device == dev)) {
53395 + subj->inode = ino;
53396 + subj->device = dev;
53397 + }
53398 + FOR_EACH_NESTED_SUBJECT_END(subj)
53399 + FOR_EACH_SUBJECT_START(role, subj, x)
53400 + update_acl_obj_label(matchn->inode, matchn->device,
53401 + ino, dev, subj);
53402 + FOR_EACH_SUBJECT_END(subj,x)
53403 + FOR_EACH_ROLE_END(role)
53404 +
53405 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53406 +
53407 + return;
53408 +}
53409 +
53410 +static void
53411 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53412 + const struct vfsmount *mnt)
53413 +{
53414 + ino_t ino = dentry->d_inode->i_ino;
53415 + dev_t dev = __get_dev(dentry);
53416 +
53417 + __do_handle_create(matchn, ino, dev);
53418 +
53419 + return;
53420 +}
53421 +
53422 +void
53423 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53424 +{
53425 + struct name_entry *matchn;
53426 +
53427 + if (unlikely(!(gr_status & GR_READY)))
53428 + return;
53429 +
53430 + preempt_disable();
53431 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53432 +
53433 + if (unlikely((unsigned long)matchn)) {
53434 + write_lock(&gr_inode_lock);
53435 + do_handle_create(matchn, dentry, mnt);
53436 + write_unlock(&gr_inode_lock);
53437 + }
53438 + preempt_enable();
53439 +
53440 + return;
53441 +}
53442 +
53443 +void
53444 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53445 +{
53446 + struct name_entry *matchn;
53447 +
53448 + if (unlikely(!(gr_status & GR_READY)))
53449 + return;
53450 +
53451 + preempt_disable();
53452 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53453 +
53454 + if (unlikely((unsigned long)matchn)) {
53455 + write_lock(&gr_inode_lock);
53456 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53457 + write_unlock(&gr_inode_lock);
53458 + }
53459 + preempt_enable();
53460 +
53461 + return;
53462 +}
53463 +
53464 +void
53465 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53466 + struct dentry *old_dentry,
53467 + struct dentry *new_dentry,
53468 + struct vfsmount *mnt, const __u8 replace)
53469 +{
53470 + struct name_entry *matchn;
53471 + struct inodev_entry *inodev;
53472 + struct inode *inode = new_dentry->d_inode;
53473 + ino_t old_ino = old_dentry->d_inode->i_ino;
53474 + dev_t old_dev = __get_dev(old_dentry);
53475 +
53476 + /* vfs_rename swaps the name and parent link for old_dentry and
53477 + new_dentry
53478 + at this point, old_dentry has the new name, parent link, and inode
53479 + for the renamed file
53480 + if a file is being replaced by a rename, new_dentry has the inode
53481 + and name for the replaced file
53482 + */
53483 +
53484 + if (unlikely(!(gr_status & GR_READY)))
53485 + return;
53486 +
53487 + preempt_disable();
53488 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53489 +
53490 + /* we wouldn't have to check d_inode if it weren't for
53491 + NFS silly-renaming
53492 + */
53493 +
53494 + write_lock(&gr_inode_lock);
53495 + if (unlikely(replace && inode)) {
53496 + ino_t new_ino = inode->i_ino;
53497 + dev_t new_dev = __get_dev(new_dentry);
53498 +
53499 + inodev = lookup_inodev_entry(new_ino, new_dev);
53500 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53501 + do_handle_delete(inodev, new_ino, new_dev);
53502 + }
53503 +
53504 + inodev = lookup_inodev_entry(old_ino, old_dev);
53505 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53506 + do_handle_delete(inodev, old_ino, old_dev);
53507 +
53508 + if (unlikely((unsigned long)matchn))
53509 + do_handle_create(matchn, old_dentry, mnt);
53510 +
53511 + write_unlock(&gr_inode_lock);
53512 + preempt_enable();
53513 +
53514 + return;
53515 +}
53516 +
53517 +static int
53518 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53519 + unsigned char **sum)
53520 +{
53521 + struct acl_role_label *r;
53522 + struct role_allowed_ip *ipp;
53523 + struct role_transition *trans;
53524 + unsigned int i;
53525 + int found = 0;
53526 + u32 curr_ip = current->signal->curr_ip;
53527 +
53528 + current->signal->saved_ip = curr_ip;
53529 +
53530 + /* check transition table */
53531 +
53532 + for (trans = current->role->transitions; trans; trans = trans->next) {
53533 + if (!strcmp(rolename, trans->rolename)) {
53534 + found = 1;
53535 + break;
53536 + }
53537 + }
53538 +
53539 + if (!found)
53540 + return 0;
53541 +
53542 + /* handle special roles that do not require authentication
53543 + and check ip */
53544 +
53545 + FOR_EACH_ROLE_START(r)
53546 + if (!strcmp(rolename, r->rolename) &&
53547 + (r->roletype & GR_ROLE_SPECIAL)) {
53548 + found = 0;
53549 + if (r->allowed_ips != NULL) {
53550 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53551 + if ((ntohl(curr_ip) & ipp->netmask) ==
53552 + (ntohl(ipp->addr) & ipp->netmask))
53553 + found = 1;
53554 + }
53555 + } else
53556 + found = 2;
53557 + if (!found)
53558 + return 0;
53559 +
53560 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53561 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53562 + *salt = NULL;
53563 + *sum = NULL;
53564 + return 1;
53565 + }
53566 + }
53567 + FOR_EACH_ROLE_END(r)
53568 +
53569 + for (i = 0; i < num_sprole_pws; i++) {
53570 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53571 + *salt = acl_special_roles[i]->salt;
53572 + *sum = acl_special_roles[i]->sum;
53573 + return 1;
53574 + }
53575 + }
53576 +
53577 + return 0;
53578 +}
53579 +
53580 +static void
53581 +assign_special_role(char *rolename)
53582 +{
53583 + struct acl_object_label *obj;
53584 + struct acl_role_label *r;
53585 + struct acl_role_label *assigned = NULL;
53586 + struct task_struct *tsk;
53587 + struct file *filp;
53588 +
53589 + FOR_EACH_ROLE_START(r)
53590 + if (!strcmp(rolename, r->rolename) &&
53591 + (r->roletype & GR_ROLE_SPECIAL)) {
53592 + assigned = r;
53593 + break;
53594 + }
53595 + FOR_EACH_ROLE_END(r)
53596 +
53597 + if (!assigned)
53598 + return;
53599 +
53600 + read_lock(&tasklist_lock);
53601 + read_lock(&grsec_exec_file_lock);
53602 +
53603 + tsk = current->real_parent;
53604 + if (tsk == NULL)
53605 + goto out_unlock;
53606 +
53607 + filp = tsk->exec_file;
53608 + if (filp == NULL)
53609 + goto out_unlock;
53610 +
53611 + tsk->is_writable = 0;
53612 +
53613 + tsk->acl_sp_role = 1;
53614 + tsk->acl_role_id = ++acl_sp_role_value;
53615 + tsk->role = assigned;
53616 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53617 +
53618 + /* ignore additional mmap checks for processes that are writable
53619 + by the default ACL */
53620 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53621 + if (unlikely(obj->mode & GR_WRITE))
53622 + tsk->is_writable = 1;
53623 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53624 + if (unlikely(obj->mode & GR_WRITE))
53625 + tsk->is_writable = 1;
53626 +
53627 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53628 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53629 +#endif
53630 +
53631 +out_unlock:
53632 + read_unlock(&grsec_exec_file_lock);
53633 + read_unlock(&tasklist_lock);
53634 + return;
53635 +}
53636 +
53637 +int gr_check_secure_terminal(struct task_struct *task)
53638 +{
53639 + struct task_struct *p, *p2, *p3;
53640 + struct files_struct *files;
53641 + struct fdtable *fdt;
53642 + struct file *our_file = NULL, *file;
53643 + int i;
53644 +
53645 + if (task->signal->tty == NULL)
53646 + return 1;
53647 +
53648 + files = get_files_struct(task);
53649 + if (files != NULL) {
53650 + rcu_read_lock();
53651 + fdt = files_fdtable(files);
53652 + for (i=0; i < fdt->max_fds; i++) {
53653 + file = fcheck_files(files, i);
53654 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53655 + get_file(file);
53656 + our_file = file;
53657 + }
53658 + }
53659 + rcu_read_unlock();
53660 + put_files_struct(files);
53661 + }
53662 +
53663 + if (our_file == NULL)
53664 + return 1;
53665 +
53666 + read_lock(&tasklist_lock);
53667 + do_each_thread(p2, p) {
53668 + files = get_files_struct(p);
53669 + if (files == NULL ||
53670 + (p->signal && p->signal->tty == task->signal->tty)) {
53671 + if (files != NULL)
53672 + put_files_struct(files);
53673 + continue;
53674 + }
53675 + rcu_read_lock();
53676 + fdt = files_fdtable(files);
53677 + for (i=0; i < fdt->max_fds; i++) {
53678 + file = fcheck_files(files, i);
53679 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53680 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53681 + p3 = task;
53682 + while (p3->pid > 0) {
53683 + if (p3 == p)
53684 + break;
53685 + p3 = p3->real_parent;
53686 + }
53687 + if (p3 == p)
53688 + break;
53689 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53690 + gr_handle_alertkill(p);
53691 + rcu_read_unlock();
53692 + put_files_struct(files);
53693 + read_unlock(&tasklist_lock);
53694 + fput(our_file);
53695 + return 0;
53696 + }
53697 + }
53698 + rcu_read_unlock();
53699 + put_files_struct(files);
53700 + } while_each_thread(p2, p);
53701 + read_unlock(&tasklist_lock);
53702 +
53703 + fput(our_file);
53704 + return 1;
53705 +}
53706 +
53707 +ssize_t
53708 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53709 +{
53710 + struct gr_arg_wrapper uwrap;
53711 + unsigned char *sprole_salt = NULL;
53712 + unsigned char *sprole_sum = NULL;
53713 + int error = sizeof (struct gr_arg_wrapper);
53714 + int error2 = 0;
53715 +
53716 + mutex_lock(&gr_dev_mutex);
53717 +
53718 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53719 + error = -EPERM;
53720 + goto out;
53721 + }
53722 +
53723 + if (count != sizeof (struct gr_arg_wrapper)) {
53724 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53725 + error = -EINVAL;
53726 + goto out;
53727 + }
53728 +
53729 +
53730 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53731 + gr_auth_expires = 0;
53732 + gr_auth_attempts = 0;
53733 + }
53734 +
53735 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53736 + error = -EFAULT;
53737 + goto out;
53738 + }
53739 +
53740 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53741 + error = -EINVAL;
53742 + goto out;
53743 + }
53744 +
53745 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53746 + error = -EFAULT;
53747 + goto out;
53748 + }
53749 +
53750 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53751 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53752 + time_after(gr_auth_expires, get_seconds())) {
53753 + error = -EBUSY;
53754 + goto out;
53755 + }
53756 +
53757 + /* if non-root trying to do anything other than use a special role,
53758 + do not attempt authentication, do not count towards authentication
53759 + locking
53760 + */
53761 +
53762 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53763 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53764 + current_uid()) {
53765 + error = -EPERM;
53766 + goto out;
53767 + }
53768 +
53769 + /* ensure pw and special role name are null terminated */
53770 +
53771 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53772 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53773 +
53774 + /* Okay.
53775 + * We have our enough of the argument structure..(we have yet
53776 + * to copy_from_user the tables themselves) . Copy the tables
53777 + * only if we need them, i.e. for loading operations. */
53778 +
53779 + switch (gr_usermode->mode) {
53780 + case GR_STATUS:
53781 + if (gr_status & GR_READY) {
53782 + error = 1;
53783 + if (!gr_check_secure_terminal(current))
53784 + error = 3;
53785 + } else
53786 + error = 2;
53787 + goto out;
53788 + case GR_SHUTDOWN:
53789 + if ((gr_status & GR_READY)
53790 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53791 + pax_open_kernel();
53792 + gr_status &= ~GR_READY;
53793 + pax_close_kernel();
53794 +
53795 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53796 + free_variables();
53797 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53798 + memset(gr_system_salt, 0, GR_SALT_LEN);
53799 + memset(gr_system_sum, 0, GR_SHA_LEN);
53800 + } else if (gr_status & GR_READY) {
53801 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53802 + error = -EPERM;
53803 + } else {
53804 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53805 + error = -EAGAIN;
53806 + }
53807 + break;
53808 + case GR_ENABLE:
53809 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53810 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53811 + else {
53812 + if (gr_status & GR_READY)
53813 + error = -EAGAIN;
53814 + else
53815 + error = error2;
53816 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53817 + }
53818 + break;
53819 + case GR_RELOAD:
53820 + if (!(gr_status & GR_READY)) {
53821 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53822 + error = -EAGAIN;
53823 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53824 + preempt_disable();
53825 +
53826 + pax_open_kernel();
53827 + gr_status &= ~GR_READY;
53828 + pax_close_kernel();
53829 +
53830 + free_variables();
53831 + if (!(error2 = gracl_init(gr_usermode))) {
53832 + preempt_enable();
53833 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53834 + } else {
53835 + preempt_enable();
53836 + error = error2;
53837 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53838 + }
53839 + } else {
53840 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53841 + error = -EPERM;
53842 + }
53843 + break;
53844 + case GR_SEGVMOD:
53845 + if (unlikely(!(gr_status & GR_READY))) {
53846 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53847 + error = -EAGAIN;
53848 + break;
53849 + }
53850 +
53851 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53852 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53853 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53854 + struct acl_subject_label *segvacl;
53855 + segvacl =
53856 + lookup_acl_subj_label(gr_usermode->segv_inode,
53857 + gr_usermode->segv_device,
53858 + current->role);
53859 + if (segvacl) {
53860 + segvacl->crashes = 0;
53861 + segvacl->expires = 0;
53862 + }
53863 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53864 + gr_remove_uid(gr_usermode->segv_uid);
53865 + }
53866 + } else {
53867 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53868 + error = -EPERM;
53869 + }
53870 + break;
53871 + case GR_SPROLE:
53872 + case GR_SPROLEPAM:
53873 + if (unlikely(!(gr_status & GR_READY))) {
53874 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53875 + error = -EAGAIN;
53876 + break;
53877 + }
53878 +
53879 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53880 + current->role->expires = 0;
53881 + current->role->auth_attempts = 0;
53882 + }
53883 +
53884 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53885 + time_after(current->role->expires, get_seconds())) {
53886 + error = -EBUSY;
53887 + goto out;
53888 + }
53889 +
53890 + if (lookup_special_role_auth
53891 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53892 + && ((!sprole_salt && !sprole_sum)
53893 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53894 + char *p = "";
53895 + assign_special_role(gr_usermode->sp_role);
53896 + read_lock(&tasklist_lock);
53897 + if (current->real_parent)
53898 + p = current->real_parent->role->rolename;
53899 + read_unlock(&tasklist_lock);
53900 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53901 + p, acl_sp_role_value);
53902 + } else {
53903 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53904 + error = -EPERM;
53905 + if(!(current->role->auth_attempts++))
53906 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53907 +
53908 + goto out;
53909 + }
53910 + break;
53911 + case GR_UNSPROLE:
53912 + if (unlikely(!(gr_status & GR_READY))) {
53913 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53914 + error = -EAGAIN;
53915 + break;
53916 + }
53917 +
53918 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53919 + char *p = "";
53920 + int i = 0;
53921 +
53922 + read_lock(&tasklist_lock);
53923 + if (current->real_parent) {
53924 + p = current->real_parent->role->rolename;
53925 + i = current->real_parent->acl_role_id;
53926 + }
53927 + read_unlock(&tasklist_lock);
53928 +
53929 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53930 + gr_set_acls(1);
53931 + } else {
53932 + error = -EPERM;
53933 + goto out;
53934 + }
53935 + break;
53936 + default:
53937 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53938 + error = -EINVAL;
53939 + break;
53940 + }
53941 +
53942 + if (error != -EPERM)
53943 + goto out;
53944 +
53945 + if(!(gr_auth_attempts++))
53946 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53947 +
53948 + out:
53949 + mutex_unlock(&gr_dev_mutex);
53950 + return error;
53951 +}
53952 +
53953 +/* must be called with
53954 + rcu_read_lock();
53955 + read_lock(&tasklist_lock);
53956 + read_lock(&grsec_exec_file_lock);
53957 +*/
53958 +int gr_apply_subject_to_task(struct task_struct *task)
53959 +{
53960 + struct acl_object_label *obj;
53961 + char *tmpname;
53962 + struct acl_subject_label *tmpsubj;
53963 + struct file *filp;
53964 + struct name_entry *nmatch;
53965 +
53966 + filp = task->exec_file;
53967 + if (filp == NULL)
53968 + return 0;
53969 +
53970 + /* the following is to apply the correct subject
53971 + on binaries running when the RBAC system
53972 + is enabled, when the binaries have been
53973 + replaced or deleted since their execution
53974 + -----
53975 + when the RBAC system starts, the inode/dev
53976 + from exec_file will be one the RBAC system
53977 + is unaware of. It only knows the inode/dev
53978 + of the present file on disk, or the absence
53979 + of it.
53980 + */
53981 + preempt_disable();
53982 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53983 +
53984 + nmatch = lookup_name_entry(tmpname);
53985 + preempt_enable();
53986 + tmpsubj = NULL;
53987 + if (nmatch) {
53988 + if (nmatch->deleted)
53989 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53990 + else
53991 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53992 + if (tmpsubj != NULL)
53993 + task->acl = tmpsubj;
53994 + }
53995 + if (tmpsubj == NULL)
53996 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53997 + task->role);
53998 + if (task->acl) {
53999 + task->is_writable = 0;
54000 + /* ignore additional mmap checks for processes that are writable
54001 + by the default ACL */
54002 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54003 + if (unlikely(obj->mode & GR_WRITE))
54004 + task->is_writable = 1;
54005 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54006 + if (unlikely(obj->mode & GR_WRITE))
54007 + task->is_writable = 1;
54008 +
54009 + gr_set_proc_res(task);
54010 +
54011 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54012 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54013 +#endif
54014 + } else {
54015 + return 1;
54016 + }
54017 +
54018 + return 0;
54019 +}
54020 +
54021 +int
54022 +gr_set_acls(const int type)
54023 +{
54024 + struct task_struct *task, *task2;
54025 + struct acl_role_label *role = current->role;
54026 + __u16 acl_role_id = current->acl_role_id;
54027 + const struct cred *cred;
54028 + int ret;
54029 +
54030 + rcu_read_lock();
54031 + read_lock(&tasklist_lock);
54032 + read_lock(&grsec_exec_file_lock);
54033 + do_each_thread(task2, task) {
54034 + /* check to see if we're called from the exit handler,
54035 + if so, only replace ACLs that have inherited the admin
54036 + ACL */
54037 +
54038 + if (type && (task->role != role ||
54039 + task->acl_role_id != acl_role_id))
54040 + continue;
54041 +
54042 + task->acl_role_id = 0;
54043 + task->acl_sp_role = 0;
54044 +
54045 + if (task->exec_file) {
54046 + cred = __task_cred(task);
54047 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54048 + ret = gr_apply_subject_to_task(task);
54049 + if (ret) {
54050 + read_unlock(&grsec_exec_file_lock);
54051 + read_unlock(&tasklist_lock);
54052 + rcu_read_unlock();
54053 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54054 + return ret;
54055 + }
54056 + } else {
54057 + // it's a kernel process
54058 + task->role = kernel_role;
54059 + task->acl = kernel_role->root_label;
54060 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54061 + task->acl->mode &= ~GR_PROCFIND;
54062 +#endif
54063 + }
54064 + } while_each_thread(task2, task);
54065 + read_unlock(&grsec_exec_file_lock);
54066 + read_unlock(&tasklist_lock);
54067 + rcu_read_unlock();
54068 +
54069 + return 0;
54070 +}
54071 +
54072 +void
54073 +gr_learn_resource(const struct task_struct *task,
54074 + const int res, const unsigned long wanted, const int gt)
54075 +{
54076 + struct acl_subject_label *acl;
54077 + const struct cred *cred;
54078 +
54079 + if (unlikely((gr_status & GR_READY) &&
54080 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54081 + goto skip_reslog;
54082 +
54083 +#ifdef CONFIG_GRKERNSEC_RESLOG
54084 + gr_log_resource(task, res, wanted, gt);
54085 +#endif
54086 + skip_reslog:
54087 +
54088 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54089 + return;
54090 +
54091 + acl = task->acl;
54092 +
54093 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54094 + !(acl->resmask & (1 << (unsigned short) res))))
54095 + return;
54096 +
54097 + if (wanted >= acl->res[res].rlim_cur) {
54098 + unsigned long res_add;
54099 +
54100 + res_add = wanted;
54101 + switch (res) {
54102 + case RLIMIT_CPU:
54103 + res_add += GR_RLIM_CPU_BUMP;
54104 + break;
54105 + case RLIMIT_FSIZE:
54106 + res_add += GR_RLIM_FSIZE_BUMP;
54107 + break;
54108 + case RLIMIT_DATA:
54109 + res_add += GR_RLIM_DATA_BUMP;
54110 + break;
54111 + case RLIMIT_STACK:
54112 + res_add += GR_RLIM_STACK_BUMP;
54113 + break;
54114 + case RLIMIT_CORE:
54115 + res_add += GR_RLIM_CORE_BUMP;
54116 + break;
54117 + case RLIMIT_RSS:
54118 + res_add += GR_RLIM_RSS_BUMP;
54119 + break;
54120 + case RLIMIT_NPROC:
54121 + res_add += GR_RLIM_NPROC_BUMP;
54122 + break;
54123 + case RLIMIT_NOFILE:
54124 + res_add += GR_RLIM_NOFILE_BUMP;
54125 + break;
54126 + case RLIMIT_MEMLOCK:
54127 + res_add += GR_RLIM_MEMLOCK_BUMP;
54128 + break;
54129 + case RLIMIT_AS:
54130 + res_add += GR_RLIM_AS_BUMP;
54131 + break;
54132 + case RLIMIT_LOCKS:
54133 + res_add += GR_RLIM_LOCKS_BUMP;
54134 + break;
54135 + case RLIMIT_SIGPENDING:
54136 + res_add += GR_RLIM_SIGPENDING_BUMP;
54137 + break;
54138 + case RLIMIT_MSGQUEUE:
54139 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54140 + break;
54141 + case RLIMIT_NICE:
54142 + res_add += GR_RLIM_NICE_BUMP;
54143 + break;
54144 + case RLIMIT_RTPRIO:
54145 + res_add += GR_RLIM_RTPRIO_BUMP;
54146 + break;
54147 + case RLIMIT_RTTIME:
54148 + res_add += GR_RLIM_RTTIME_BUMP;
54149 + break;
54150 + }
54151 +
54152 + acl->res[res].rlim_cur = res_add;
54153 +
54154 + if (wanted > acl->res[res].rlim_max)
54155 + acl->res[res].rlim_max = res_add;
54156 +
54157 + /* only log the subject filename, since resource logging is supported for
54158 + single-subject learning only */
54159 + rcu_read_lock();
54160 + cred = __task_cred(task);
54161 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54162 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54163 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54164 + "", (unsigned long) res, &task->signal->saved_ip);
54165 + rcu_read_unlock();
54166 + }
54167 +
54168 + return;
54169 +}
54170 +
54171 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54172 +void
54173 +pax_set_initial_flags(struct linux_binprm *bprm)
54174 +{
54175 + struct task_struct *task = current;
54176 + struct acl_subject_label *proc;
54177 + unsigned long flags;
54178 +
54179 + if (unlikely(!(gr_status & GR_READY)))
54180 + return;
54181 +
54182 + flags = pax_get_flags(task);
54183 +
54184 + proc = task->acl;
54185 +
54186 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54187 + flags &= ~MF_PAX_PAGEEXEC;
54188 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54189 + flags &= ~MF_PAX_SEGMEXEC;
54190 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54191 + flags &= ~MF_PAX_RANDMMAP;
54192 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54193 + flags &= ~MF_PAX_EMUTRAMP;
54194 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54195 + flags &= ~MF_PAX_MPROTECT;
54196 +
54197 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54198 + flags |= MF_PAX_PAGEEXEC;
54199 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54200 + flags |= MF_PAX_SEGMEXEC;
54201 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54202 + flags |= MF_PAX_RANDMMAP;
54203 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54204 + flags |= MF_PAX_EMUTRAMP;
54205 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54206 + flags |= MF_PAX_MPROTECT;
54207 +
54208 + pax_set_flags(task, flags);
54209 +
54210 + return;
54211 +}
54212 +#endif
54213 +
54214 +#ifdef CONFIG_SYSCTL
54215 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54216 + system to save 35kb of memory */
54217 +
54218 +/* we modify the passed in filename, but adjust it back before returning */
54219 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54220 +{
54221 + struct name_entry *nmatch;
54222 + char *p, *lastp = NULL;
54223 + struct acl_object_label *obj = NULL, *tmp;
54224 + struct acl_subject_label *tmpsubj;
54225 + char c = '\0';
54226 +
54227 + read_lock(&gr_inode_lock);
54228 +
54229 + p = name + len - 1;
54230 + do {
54231 + nmatch = lookup_name_entry(name);
54232 + if (lastp != NULL)
54233 + *lastp = c;
54234 +
54235 + if (nmatch == NULL)
54236 + goto next_component;
54237 + tmpsubj = current->acl;
54238 + do {
54239 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54240 + if (obj != NULL) {
54241 + tmp = obj->globbed;
54242 + while (tmp) {
54243 + if (!glob_match(tmp->filename, name)) {
54244 + obj = tmp;
54245 + goto found_obj;
54246 + }
54247 + tmp = tmp->next;
54248 + }
54249 + goto found_obj;
54250 + }
54251 + } while ((tmpsubj = tmpsubj->parent_subject));
54252 +next_component:
54253 + /* end case */
54254 + if (p == name)
54255 + break;
54256 +
54257 + while (*p != '/')
54258 + p--;
54259 + if (p == name)
54260 + lastp = p + 1;
54261 + else {
54262 + lastp = p;
54263 + p--;
54264 + }
54265 + c = *lastp;
54266 + *lastp = '\0';
54267 + } while (1);
54268 +found_obj:
54269 + read_unlock(&gr_inode_lock);
54270 + /* obj returned will always be non-null */
54271 + return obj;
54272 +}
54273 +
54274 +/* returns 0 when allowing, non-zero on error
54275 + op of 0 is used for readdir, so we don't log the names of hidden files
54276 +*/
54277 +__u32
54278 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54279 +{
54280 + struct ctl_table *tmp;
54281 + const char *proc_sys = "/proc/sys";
54282 + char *path;
54283 + struct acl_object_label *obj;
54284 + unsigned short len = 0, pos = 0, depth = 0, i;
54285 + __u32 err = 0;
54286 + __u32 mode = 0;
54287 +
54288 + if (unlikely(!(gr_status & GR_READY)))
54289 + return 0;
54290 +
54291 + /* for now, ignore operations on non-sysctl entries if it's not a
54292 + readdir*/
54293 + if (table->child != NULL && op != 0)
54294 + return 0;
54295 +
54296 + mode |= GR_FIND;
54297 + /* it's only a read if it's an entry, read on dirs is for readdir */
54298 + if (op & MAY_READ)
54299 + mode |= GR_READ;
54300 + if (op & MAY_WRITE)
54301 + mode |= GR_WRITE;
54302 +
54303 + preempt_disable();
54304 +
54305 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54306 +
54307 + /* it's only a read/write if it's an actual entry, not a dir
54308 + (which are opened for readdir)
54309 + */
54310 +
54311 + /* convert the requested sysctl entry into a pathname */
54312 +
54313 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54314 + len += strlen(tmp->procname);
54315 + len++;
54316 + depth++;
54317 + }
54318 +
54319 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54320 + /* deny */
54321 + goto out;
54322 + }
54323 +
54324 + memset(path, 0, PAGE_SIZE);
54325 +
54326 + memcpy(path, proc_sys, strlen(proc_sys));
54327 +
54328 + pos += strlen(proc_sys);
54329 +
54330 + for (; depth > 0; depth--) {
54331 + path[pos] = '/';
54332 + pos++;
54333 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54334 + if (depth == i) {
54335 + memcpy(path + pos, tmp->procname,
54336 + strlen(tmp->procname));
54337 + pos += strlen(tmp->procname);
54338 + }
54339 + i++;
54340 + }
54341 + }
54342 +
54343 + obj = gr_lookup_by_name(path, pos);
54344 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54345 +
54346 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54347 + ((err & mode) != mode))) {
54348 + __u32 new_mode = mode;
54349 +
54350 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54351 +
54352 + err = 0;
54353 + gr_log_learn_sysctl(path, new_mode);
54354 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54355 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54356 + err = -ENOENT;
54357 + } else if (!(err & GR_FIND)) {
54358 + err = -ENOENT;
54359 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54360 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54361 + path, (mode & GR_READ) ? " reading" : "",
54362 + (mode & GR_WRITE) ? " writing" : "");
54363 + err = -EACCES;
54364 + } else if ((err & mode) != mode) {
54365 + err = -EACCES;
54366 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54367 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54368 + path, (mode & GR_READ) ? " reading" : "",
54369 + (mode & GR_WRITE) ? " writing" : "");
54370 + err = 0;
54371 + } else
54372 + err = 0;
54373 +
54374 + out:
54375 + preempt_enable();
54376 +
54377 + return err;
54378 +}
54379 +#endif
54380 +
54381 +int
54382 +gr_handle_proc_ptrace(struct task_struct *task)
54383 +{
54384 + struct file *filp;
54385 + struct task_struct *tmp = task;
54386 + struct task_struct *curtemp = current;
54387 + __u32 retmode;
54388 +
54389 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54390 + if (unlikely(!(gr_status & GR_READY)))
54391 + return 0;
54392 +#endif
54393 +
54394 + read_lock(&tasklist_lock);
54395 + read_lock(&grsec_exec_file_lock);
54396 + filp = task->exec_file;
54397 +
54398 + while (tmp->pid > 0) {
54399 + if (tmp == curtemp)
54400 + break;
54401 + tmp = tmp->real_parent;
54402 + }
54403 +
54404 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54405 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54406 + read_unlock(&grsec_exec_file_lock);
54407 + read_unlock(&tasklist_lock);
54408 + return 1;
54409 + }
54410 +
54411 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54412 + if (!(gr_status & GR_READY)) {
54413 + read_unlock(&grsec_exec_file_lock);
54414 + read_unlock(&tasklist_lock);
54415 + return 0;
54416 + }
54417 +#endif
54418 +
54419 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54420 + read_unlock(&grsec_exec_file_lock);
54421 + read_unlock(&tasklist_lock);
54422 +
54423 + if (retmode & GR_NOPTRACE)
54424 + return 1;
54425 +
54426 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54427 + && (current->acl != task->acl || (current->acl != current->role->root_label
54428 + && current->pid != task->pid)))
54429 + return 1;
54430 +
54431 + return 0;
54432 +}
54433 +
54434 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54435 +{
54436 + if (unlikely(!(gr_status & GR_READY)))
54437 + return;
54438 +
54439 + if (!(current->role->roletype & GR_ROLE_GOD))
54440 + return;
54441 +
54442 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54443 + p->role->rolename, gr_task_roletype_to_char(p),
54444 + p->acl->filename);
54445 +}
54446 +
54447 +int
54448 +gr_handle_ptrace(struct task_struct *task, const long request)
54449 +{
54450 + struct task_struct *tmp = task;
54451 + struct task_struct *curtemp = current;
54452 + __u32 retmode;
54453 +
54454 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54455 + if (unlikely(!(gr_status & GR_READY)))
54456 + return 0;
54457 +#endif
54458 +
54459 + read_lock(&tasklist_lock);
54460 + while (tmp->pid > 0) {
54461 + if (tmp == curtemp)
54462 + break;
54463 + tmp = tmp->real_parent;
54464 + }
54465 +
54466 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54467 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54468 + read_unlock(&tasklist_lock);
54469 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54470 + return 1;
54471 + }
54472 + read_unlock(&tasklist_lock);
54473 +
54474 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54475 + if (!(gr_status & GR_READY))
54476 + return 0;
54477 +#endif
54478 +
54479 + read_lock(&grsec_exec_file_lock);
54480 + if (unlikely(!task->exec_file)) {
54481 + read_unlock(&grsec_exec_file_lock);
54482 + return 0;
54483 + }
54484 +
54485 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54486 + read_unlock(&grsec_exec_file_lock);
54487 +
54488 + if (retmode & GR_NOPTRACE) {
54489 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54490 + return 1;
54491 + }
54492 +
54493 + if (retmode & GR_PTRACERD) {
54494 + switch (request) {
54495 + case PTRACE_SEIZE:
54496 + case PTRACE_POKETEXT:
54497 + case PTRACE_POKEDATA:
54498 + case PTRACE_POKEUSR:
54499 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54500 + case PTRACE_SETREGS:
54501 + case PTRACE_SETFPREGS:
54502 +#endif
54503 +#ifdef CONFIG_X86
54504 + case PTRACE_SETFPXREGS:
54505 +#endif
54506 +#ifdef CONFIG_ALTIVEC
54507 + case PTRACE_SETVRREGS:
54508 +#endif
54509 + return 1;
54510 + default:
54511 + return 0;
54512 + }
54513 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54514 + !(current->role->roletype & GR_ROLE_GOD) &&
54515 + (current->acl != task->acl)) {
54516 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54517 + return 1;
54518 + }
54519 +
54520 + return 0;
54521 +}
54522 +
54523 +static int is_writable_mmap(const struct file *filp)
54524 +{
54525 + struct task_struct *task = current;
54526 + struct acl_object_label *obj, *obj2;
54527 +
54528 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54529 + !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))) {
54530 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54531 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54532 + task->role->root_label);
54533 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54534 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54535 + return 1;
54536 + }
54537 + }
54538 + return 0;
54539 +}
54540 +
54541 +int
54542 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54543 +{
54544 + __u32 mode;
54545 +
54546 + if (unlikely(!file || !(prot & PROT_EXEC)))
54547 + return 1;
54548 +
54549 + if (is_writable_mmap(file))
54550 + return 0;
54551 +
54552 + mode =
54553 + gr_search_file(file->f_path.dentry,
54554 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54555 + file->f_path.mnt);
54556 +
54557 + if (!gr_tpe_allow(file))
54558 + return 0;
54559 +
54560 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54561 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54562 + return 0;
54563 + } else if (unlikely(!(mode & GR_EXEC))) {
54564 + return 0;
54565 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54566 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54567 + return 1;
54568 + }
54569 +
54570 + return 1;
54571 +}
54572 +
54573 +int
54574 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54575 +{
54576 + __u32 mode;
54577 +
54578 + if (unlikely(!file || !(prot & PROT_EXEC)))
54579 + return 1;
54580 +
54581 + if (is_writable_mmap(file))
54582 + return 0;
54583 +
54584 + mode =
54585 + gr_search_file(file->f_path.dentry,
54586 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54587 + file->f_path.mnt);
54588 +
54589 + if (!gr_tpe_allow(file))
54590 + return 0;
54591 +
54592 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54593 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54594 + return 0;
54595 + } else if (unlikely(!(mode & GR_EXEC))) {
54596 + return 0;
54597 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54598 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54599 + return 1;
54600 + }
54601 +
54602 + return 1;
54603 +}
54604 +
54605 +void
54606 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54607 +{
54608 + unsigned long runtime;
54609 + unsigned long cputime;
54610 + unsigned int wday, cday;
54611 + __u8 whr, chr;
54612 + __u8 wmin, cmin;
54613 + __u8 wsec, csec;
54614 + struct timespec timeval;
54615 +
54616 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54617 + !(task->acl->mode & GR_PROCACCT)))
54618 + return;
54619 +
54620 + do_posix_clock_monotonic_gettime(&timeval);
54621 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54622 + wday = runtime / (3600 * 24);
54623 + runtime -= wday * (3600 * 24);
54624 + whr = runtime / 3600;
54625 + runtime -= whr * 3600;
54626 + wmin = runtime / 60;
54627 + runtime -= wmin * 60;
54628 + wsec = runtime;
54629 +
54630 + cputime = (task->utime + task->stime) / HZ;
54631 + cday = cputime / (3600 * 24);
54632 + cputime -= cday * (3600 * 24);
54633 + chr = cputime / 3600;
54634 + cputime -= chr * 3600;
54635 + cmin = cputime / 60;
54636 + cputime -= cmin * 60;
54637 + csec = cputime;
54638 +
54639 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54640 +
54641 + return;
54642 +}
54643 +
54644 +void gr_set_kernel_label(struct task_struct *task)
54645 +{
54646 + if (gr_status & GR_READY) {
54647 + task->role = kernel_role;
54648 + task->acl = kernel_role->root_label;
54649 + }
54650 + return;
54651 +}
54652 +
54653 +#ifdef CONFIG_TASKSTATS
54654 +int gr_is_taskstats_denied(int pid)
54655 +{
54656 + struct task_struct *task;
54657 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54658 + const struct cred *cred;
54659 +#endif
54660 + int ret = 0;
54661 +
54662 + /* restrict taskstats viewing to un-chrooted root users
54663 + who have the 'view' subject flag if the RBAC system is enabled
54664 + */
54665 +
54666 + rcu_read_lock();
54667 + read_lock(&tasklist_lock);
54668 + task = find_task_by_vpid(pid);
54669 + if (task) {
54670 +#ifdef CONFIG_GRKERNSEC_CHROOT
54671 + if (proc_is_chrooted(task))
54672 + ret = -EACCES;
54673 +#endif
54674 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54675 + cred = __task_cred(task);
54676 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54677 + if (cred->uid != 0)
54678 + ret = -EACCES;
54679 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54680 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54681 + ret = -EACCES;
54682 +#endif
54683 +#endif
54684 + if (gr_status & GR_READY) {
54685 + if (!(task->acl->mode & GR_VIEW))
54686 + ret = -EACCES;
54687 + }
54688 + } else
54689 + ret = -ENOENT;
54690 +
54691 + read_unlock(&tasklist_lock);
54692 + rcu_read_unlock();
54693 +
54694 + return ret;
54695 +}
54696 +#endif
54697 +
54698 +/* AUXV entries are filled via a descendant of search_binary_handler
54699 + after we've already applied the subject for the target
54700 +*/
54701 +int gr_acl_enable_at_secure(void)
54702 +{
54703 + if (unlikely(!(gr_status & GR_READY)))
54704 + return 0;
54705 +
54706 + if (current->acl->mode & GR_ATSECURE)
54707 + return 1;
54708 +
54709 + return 0;
54710 +}
54711 +
54712 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54713 +{
54714 + struct task_struct *task = current;
54715 + struct dentry *dentry = file->f_path.dentry;
54716 + struct vfsmount *mnt = file->f_path.mnt;
54717 + struct acl_object_label *obj, *tmp;
54718 + struct acl_subject_label *subj;
54719 + unsigned int bufsize;
54720 + int is_not_root;
54721 + char *path;
54722 + dev_t dev = __get_dev(dentry);
54723 +
54724 + if (unlikely(!(gr_status & GR_READY)))
54725 + return 1;
54726 +
54727 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54728 + return 1;
54729 +
54730 + /* ignore Eric Biederman */
54731 + if (IS_PRIVATE(dentry->d_inode))
54732 + return 1;
54733 +
54734 + subj = task->acl;
54735 + do {
54736 + obj = lookup_acl_obj_label(ino, dev, subj);
54737 + if (obj != NULL)
54738 + return (obj->mode & GR_FIND) ? 1 : 0;
54739 + } while ((subj = subj->parent_subject));
54740 +
54741 + /* this is purely an optimization since we're looking for an object
54742 + for the directory we're doing a readdir on
54743 + if it's possible for any globbed object to match the entry we're
54744 + filling into the directory, then the object we find here will be
54745 + an anchor point with attached globbed objects
54746 + */
54747 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54748 + if (obj->globbed == NULL)
54749 + return (obj->mode & GR_FIND) ? 1 : 0;
54750 +
54751 + is_not_root = ((obj->filename[0] == '/') &&
54752 + (obj->filename[1] == '\0')) ? 0 : 1;
54753 + bufsize = PAGE_SIZE - namelen - is_not_root;
54754 +
54755 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54756 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54757 + return 1;
54758 +
54759 + preempt_disable();
54760 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54761 + bufsize);
54762 +
54763 + bufsize = strlen(path);
54764 +
54765 + /* if base is "/", don't append an additional slash */
54766 + if (is_not_root)
54767 + *(path + bufsize) = '/';
54768 + memcpy(path + bufsize + is_not_root, name, namelen);
54769 + *(path + bufsize + namelen + is_not_root) = '\0';
54770 +
54771 + tmp = obj->globbed;
54772 + while (tmp) {
54773 + if (!glob_match(tmp->filename, path)) {
54774 + preempt_enable();
54775 + return (tmp->mode & GR_FIND) ? 1 : 0;
54776 + }
54777 + tmp = tmp->next;
54778 + }
54779 + preempt_enable();
54780 + return (obj->mode & GR_FIND) ? 1 : 0;
54781 +}
54782 +
54783 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54784 +EXPORT_SYMBOL(gr_acl_is_enabled);
54785 +#endif
54786 +EXPORT_SYMBOL(gr_learn_resource);
54787 +EXPORT_SYMBOL(gr_set_kernel_label);
54788 +#ifdef CONFIG_SECURITY
54789 +EXPORT_SYMBOL(gr_check_user_change);
54790 +EXPORT_SYMBOL(gr_check_group_change);
54791 +#endif
54792 +
54793 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54794 new file mode 100644
54795 index 0000000..34fefda
54796 --- /dev/null
54797 +++ b/grsecurity/gracl_alloc.c
54798 @@ -0,0 +1,105 @@
54799 +#include <linux/kernel.h>
54800 +#include <linux/mm.h>
54801 +#include <linux/slab.h>
54802 +#include <linux/vmalloc.h>
54803 +#include <linux/gracl.h>
54804 +#include <linux/grsecurity.h>
54805 +
54806 +static unsigned long alloc_stack_next = 1;
54807 +static unsigned long alloc_stack_size = 1;
54808 +static void **alloc_stack;
54809 +
54810 +static __inline__ int
54811 +alloc_pop(void)
54812 +{
54813 + if (alloc_stack_next == 1)
54814 + return 0;
54815 +
54816 + kfree(alloc_stack[alloc_stack_next - 2]);
54817 +
54818 + alloc_stack_next--;
54819 +
54820 + return 1;
54821 +}
54822 +
54823 +static __inline__ int
54824 +alloc_push(void *buf)
54825 +{
54826 + if (alloc_stack_next >= alloc_stack_size)
54827 + return 1;
54828 +
54829 + alloc_stack[alloc_stack_next - 1] = buf;
54830 +
54831 + alloc_stack_next++;
54832 +
54833 + return 0;
54834 +}
54835 +
54836 +void *
54837 +acl_alloc(unsigned long len)
54838 +{
54839 + void *ret = NULL;
54840 +
54841 + if (!len || len > PAGE_SIZE)
54842 + goto out;
54843 +
54844 + ret = kmalloc(len, GFP_KERNEL);
54845 +
54846 + if (ret) {
54847 + if (alloc_push(ret)) {
54848 + kfree(ret);
54849 + ret = NULL;
54850 + }
54851 + }
54852 +
54853 +out:
54854 + return ret;
54855 +}
54856 +
54857 +void *
54858 +acl_alloc_num(unsigned long num, unsigned long len)
54859 +{
54860 + if (!len || (num > (PAGE_SIZE / len)))
54861 + return NULL;
54862 +
54863 + return acl_alloc(num * len);
54864 +}
54865 +
54866 +void
54867 +acl_free_all(void)
54868 +{
54869 + if (gr_acl_is_enabled() || !alloc_stack)
54870 + return;
54871 +
54872 + while (alloc_pop()) ;
54873 +
54874 + if (alloc_stack) {
54875 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54876 + kfree(alloc_stack);
54877 + else
54878 + vfree(alloc_stack);
54879 + }
54880 +
54881 + alloc_stack = NULL;
54882 + alloc_stack_size = 1;
54883 + alloc_stack_next = 1;
54884 +
54885 + return;
54886 +}
54887 +
54888 +int
54889 +acl_alloc_stack_init(unsigned long size)
54890 +{
54891 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54892 + alloc_stack =
54893 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54894 + else
54895 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54896 +
54897 + alloc_stack_size = size;
54898 +
54899 + if (!alloc_stack)
54900 + return 0;
54901 + else
54902 + return 1;
54903 +}
54904 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54905 new file mode 100644
54906 index 0000000..6d21049
54907 --- /dev/null
54908 +++ b/grsecurity/gracl_cap.c
54909 @@ -0,0 +1,110 @@
54910 +#include <linux/kernel.h>
54911 +#include <linux/module.h>
54912 +#include <linux/sched.h>
54913 +#include <linux/gracl.h>
54914 +#include <linux/grsecurity.h>
54915 +#include <linux/grinternal.h>
54916 +
54917 +extern const char *captab_log[];
54918 +extern int captab_log_entries;
54919 +
54920 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54921 +{
54922 + struct acl_subject_label *curracl;
54923 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54924 + kernel_cap_t cap_audit = __cap_empty_set;
54925 +
54926 + if (!gr_acl_is_enabled())
54927 + return 1;
54928 +
54929 + curracl = task->acl;
54930 +
54931 + cap_drop = curracl->cap_lower;
54932 + cap_mask = curracl->cap_mask;
54933 + cap_audit = curracl->cap_invert_audit;
54934 +
54935 + while ((curracl = curracl->parent_subject)) {
54936 + /* if the cap isn't specified in the current computed mask but is specified in the
54937 + current level subject, and is lowered in the current level subject, then add
54938 + it to the set of dropped capabilities
54939 + otherwise, add the current level subject's mask to the current computed mask
54940 + */
54941 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54942 + cap_raise(cap_mask, cap);
54943 + if (cap_raised(curracl->cap_lower, cap))
54944 + cap_raise(cap_drop, cap);
54945 + if (cap_raised(curracl->cap_invert_audit, cap))
54946 + cap_raise(cap_audit, cap);
54947 + }
54948 + }
54949 +
54950 + if (!cap_raised(cap_drop, cap)) {
54951 + if (cap_raised(cap_audit, cap))
54952 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54953 + return 1;
54954 + }
54955 +
54956 + curracl = task->acl;
54957 +
54958 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54959 + && cap_raised(cred->cap_effective, cap)) {
54960 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54961 + task->role->roletype, cred->uid,
54962 + cred->gid, task->exec_file ?
54963 + gr_to_filename(task->exec_file->f_path.dentry,
54964 + task->exec_file->f_path.mnt) : curracl->filename,
54965 + curracl->filename, 0UL,
54966 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54967 + return 1;
54968 + }
54969 +
54970 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54971 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54972 +
54973 + return 0;
54974 +}
54975 +
54976 +int
54977 +gr_acl_is_capable(const int cap)
54978 +{
54979 + return gr_task_acl_is_capable(current, current_cred(), cap);
54980 +}
54981 +
54982 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54983 +{
54984 + struct acl_subject_label *curracl;
54985 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54986 +
54987 + if (!gr_acl_is_enabled())
54988 + return 1;
54989 +
54990 + curracl = task->acl;
54991 +
54992 + cap_drop = curracl->cap_lower;
54993 + cap_mask = curracl->cap_mask;
54994 +
54995 + while ((curracl = curracl->parent_subject)) {
54996 + /* if the cap isn't specified in the current computed mask but is specified in the
54997 + current level subject, and is lowered in the current level subject, then add
54998 + it to the set of dropped capabilities
54999 + otherwise, add the current level subject's mask to the current computed mask
55000 + */
55001 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55002 + cap_raise(cap_mask, cap);
55003 + if (cap_raised(curracl->cap_lower, cap))
55004 + cap_raise(cap_drop, cap);
55005 + }
55006 + }
55007 +
55008 + if (!cap_raised(cap_drop, cap))
55009 + return 1;
55010 +
55011 + return 0;
55012 +}
55013 +
55014 +int
55015 +gr_acl_is_capable_nolog(const int cap)
55016 +{
55017 + return gr_task_acl_is_capable_nolog(current, cap);
55018 +}
55019 +
55020 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55021 new file mode 100644
55022 index 0000000..88d0e87
55023 --- /dev/null
55024 +++ b/grsecurity/gracl_fs.c
55025 @@ -0,0 +1,435 @@
55026 +#include <linux/kernel.h>
55027 +#include <linux/sched.h>
55028 +#include <linux/types.h>
55029 +#include <linux/fs.h>
55030 +#include <linux/file.h>
55031 +#include <linux/stat.h>
55032 +#include <linux/grsecurity.h>
55033 +#include <linux/grinternal.h>
55034 +#include <linux/gracl.h>
55035 +
55036 +umode_t
55037 +gr_acl_umask(void)
55038 +{
55039 + if (unlikely(!gr_acl_is_enabled()))
55040 + return 0;
55041 +
55042 + return current->role->umask;
55043 +}
55044 +
55045 +__u32
55046 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55047 + const struct vfsmount * mnt)
55048 +{
55049 + __u32 mode;
55050 +
55051 + if (unlikely(!dentry->d_inode))
55052 + return GR_FIND;
55053 +
55054 + mode =
55055 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55056 +
55057 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55058 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55059 + return mode;
55060 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55061 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55062 + return 0;
55063 + } else if (unlikely(!(mode & GR_FIND)))
55064 + return 0;
55065 +
55066 + return GR_FIND;
55067 +}
55068 +
55069 +__u32
55070 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55071 + int acc_mode)
55072 +{
55073 + __u32 reqmode = GR_FIND;
55074 + __u32 mode;
55075 +
55076 + if (unlikely(!dentry->d_inode))
55077 + return reqmode;
55078 +
55079 + if (acc_mode & MAY_APPEND)
55080 + reqmode |= GR_APPEND;
55081 + else if (acc_mode & MAY_WRITE)
55082 + reqmode |= GR_WRITE;
55083 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55084 + reqmode |= GR_READ;
55085 +
55086 + mode =
55087 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55088 + mnt);
55089 +
55090 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55091 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55092 + reqmode & GR_READ ? " reading" : "",
55093 + reqmode & GR_WRITE ? " writing" : reqmode &
55094 + GR_APPEND ? " appending" : "");
55095 + return reqmode;
55096 + } else
55097 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55098 + {
55099 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55100 + reqmode & GR_READ ? " reading" : "",
55101 + reqmode & GR_WRITE ? " writing" : reqmode &
55102 + GR_APPEND ? " appending" : "");
55103 + return 0;
55104 + } else if (unlikely((mode & reqmode) != reqmode))
55105 + return 0;
55106 +
55107 + return reqmode;
55108 +}
55109 +
55110 +__u32
55111 +gr_acl_handle_creat(const struct dentry * dentry,
55112 + const struct dentry * p_dentry,
55113 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55114 + const int imode)
55115 +{
55116 + __u32 reqmode = GR_WRITE | GR_CREATE;
55117 + __u32 mode;
55118 +
55119 + if (acc_mode & MAY_APPEND)
55120 + reqmode |= GR_APPEND;
55121 + // if a directory was required or the directory already exists, then
55122 + // don't count this open as a read
55123 + if ((acc_mode & MAY_READ) &&
55124 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55125 + reqmode |= GR_READ;
55126 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55127 + reqmode |= GR_SETID;
55128 +
55129 + mode =
55130 + gr_check_create(dentry, p_dentry, p_mnt,
55131 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55132 +
55133 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55134 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55135 + reqmode & GR_READ ? " reading" : "",
55136 + reqmode & GR_WRITE ? " writing" : reqmode &
55137 + GR_APPEND ? " appending" : "");
55138 + return reqmode;
55139 + } else
55140 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55141 + {
55142 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55143 + reqmode & GR_READ ? " reading" : "",
55144 + reqmode & GR_WRITE ? " writing" : reqmode &
55145 + GR_APPEND ? " appending" : "");
55146 + return 0;
55147 + } else if (unlikely((mode & reqmode) != reqmode))
55148 + return 0;
55149 +
55150 + return reqmode;
55151 +}
55152 +
55153 +__u32
55154 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55155 + const int fmode)
55156 +{
55157 + __u32 mode, reqmode = GR_FIND;
55158 +
55159 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55160 + reqmode |= GR_EXEC;
55161 + if (fmode & S_IWOTH)
55162 + reqmode |= GR_WRITE;
55163 + if (fmode & S_IROTH)
55164 + reqmode |= GR_READ;
55165 +
55166 + mode =
55167 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55168 + mnt);
55169 +
55170 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55171 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55172 + reqmode & GR_READ ? " reading" : "",
55173 + reqmode & GR_WRITE ? " writing" : "",
55174 + reqmode & GR_EXEC ? " executing" : "");
55175 + return reqmode;
55176 + } else
55177 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55178 + {
55179 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55180 + reqmode & GR_READ ? " reading" : "",
55181 + reqmode & GR_WRITE ? " writing" : "",
55182 + reqmode & GR_EXEC ? " executing" : "");
55183 + return 0;
55184 + } else if (unlikely((mode & reqmode) != reqmode))
55185 + return 0;
55186 +
55187 + return reqmode;
55188 +}
55189 +
55190 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55191 +{
55192 + __u32 mode;
55193 +
55194 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55195 +
55196 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55197 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55198 + return mode;
55199 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55200 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55201 + return 0;
55202 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55203 + return 0;
55204 +
55205 + return (reqmode);
55206 +}
55207 +
55208 +__u32
55209 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55210 +{
55211 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55212 +}
55213 +
55214 +__u32
55215 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55216 +{
55217 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55218 +}
55219 +
55220 +__u32
55221 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55222 +{
55223 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55224 +}
55225 +
55226 +__u32
55227 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55228 +{
55229 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55230 +}
55231 +
55232 +__u32
55233 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55234 + umode_t *modeptr)
55235 +{
55236 + umode_t mode;
55237 +
55238 + *modeptr &= ~gr_acl_umask();
55239 + mode = *modeptr;
55240 +
55241 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55242 + return 1;
55243 +
55244 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55245 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55246 + GR_CHMOD_ACL_MSG);
55247 + } else {
55248 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55249 + }
55250 +}
55251 +
55252 +__u32
55253 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55254 +{
55255 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55256 +}
55257 +
55258 +__u32
55259 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55260 +{
55261 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55262 +}
55263 +
55264 +__u32
55265 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55266 +{
55267 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55268 +}
55269 +
55270 +__u32
55271 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55272 +{
55273 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55274 + GR_UNIXCONNECT_ACL_MSG);
55275 +}
55276 +
55277 +/* hardlinks require at minimum create and link permission,
55278 + any additional privilege required is based on the
55279 + privilege of the file being linked to
55280 +*/
55281 +__u32
55282 +gr_acl_handle_link(const struct dentry * new_dentry,
55283 + const struct dentry * parent_dentry,
55284 + const struct vfsmount * parent_mnt,
55285 + const struct dentry * old_dentry,
55286 + const struct vfsmount * old_mnt, const char *to)
55287 +{
55288 + __u32 mode;
55289 + __u32 needmode = GR_CREATE | GR_LINK;
55290 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55291 +
55292 + mode =
55293 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55294 + old_mnt);
55295 +
55296 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55297 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55298 + return mode;
55299 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55300 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55301 + return 0;
55302 + } else if (unlikely((mode & needmode) != needmode))
55303 + return 0;
55304 +
55305 + return 1;
55306 +}
55307 +
55308 +__u32
55309 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55310 + const struct dentry * parent_dentry,
55311 + const struct vfsmount * parent_mnt, const char *from)
55312 +{
55313 + __u32 needmode = GR_WRITE | GR_CREATE;
55314 + __u32 mode;
55315 +
55316 + mode =
55317 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55318 + GR_CREATE | GR_AUDIT_CREATE |
55319 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55320 +
55321 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55322 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55323 + return mode;
55324 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55325 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55326 + return 0;
55327 + } else if (unlikely((mode & needmode) != needmode))
55328 + return 0;
55329 +
55330 + return (GR_WRITE | GR_CREATE);
55331 +}
55332 +
55333 +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)
55334 +{
55335 + __u32 mode;
55336 +
55337 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55338 +
55339 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55340 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55341 + return mode;
55342 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55343 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55344 + return 0;
55345 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55346 + return 0;
55347 +
55348 + return (reqmode);
55349 +}
55350 +
55351 +__u32
55352 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55353 + const struct dentry * parent_dentry,
55354 + const struct vfsmount * parent_mnt,
55355 + const int mode)
55356 +{
55357 + __u32 reqmode = GR_WRITE | GR_CREATE;
55358 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55359 + reqmode |= GR_SETID;
55360 +
55361 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55362 + reqmode, GR_MKNOD_ACL_MSG);
55363 +}
55364 +
55365 +__u32
55366 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55367 + const struct dentry *parent_dentry,
55368 + const struct vfsmount *parent_mnt)
55369 +{
55370 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55371 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55372 +}
55373 +
55374 +#define RENAME_CHECK_SUCCESS(old, new) \
55375 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55376 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55377 +
55378 +int
55379 +gr_acl_handle_rename(struct dentry *new_dentry,
55380 + struct dentry *parent_dentry,
55381 + const struct vfsmount *parent_mnt,
55382 + struct dentry *old_dentry,
55383 + struct inode *old_parent_inode,
55384 + struct vfsmount *old_mnt, const char *newname)
55385 +{
55386 + __u32 comp1, comp2;
55387 + int error = 0;
55388 +
55389 + if (unlikely(!gr_acl_is_enabled()))
55390 + return 0;
55391 +
55392 + if (!new_dentry->d_inode) {
55393 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55394 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55395 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55396 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55397 + GR_DELETE | GR_AUDIT_DELETE |
55398 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55399 + GR_SUPPRESS, old_mnt);
55400 + } else {
55401 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55402 + GR_CREATE | GR_DELETE |
55403 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55404 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55405 + GR_SUPPRESS, parent_mnt);
55406 + comp2 =
55407 + gr_search_file(old_dentry,
55408 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55409 + GR_DELETE | GR_AUDIT_DELETE |
55410 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55411 + }
55412 +
55413 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55414 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55415 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55416 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55417 + && !(comp2 & GR_SUPPRESS)) {
55418 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55419 + error = -EACCES;
55420 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55421 + error = -EACCES;
55422 +
55423 + return error;
55424 +}
55425 +
55426 +void
55427 +gr_acl_handle_exit(void)
55428 +{
55429 + u16 id;
55430 + char *rolename;
55431 + struct file *exec_file;
55432 +
55433 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55434 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55435 + id = current->acl_role_id;
55436 + rolename = current->role->rolename;
55437 + gr_set_acls(1);
55438 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55439 + }
55440 +
55441 + write_lock(&grsec_exec_file_lock);
55442 + exec_file = current->exec_file;
55443 + current->exec_file = NULL;
55444 + write_unlock(&grsec_exec_file_lock);
55445 +
55446 + if (exec_file)
55447 + fput(exec_file);
55448 +}
55449 +
55450 +int
55451 +gr_acl_handle_procpidmem(const struct task_struct *task)
55452 +{
55453 + if (unlikely(!gr_acl_is_enabled()))
55454 + return 0;
55455 +
55456 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55457 + return -EACCES;
55458 +
55459 + return 0;
55460 +}
55461 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55462 new file mode 100644
55463 index 0000000..58800a7
55464 --- /dev/null
55465 +++ b/grsecurity/gracl_ip.c
55466 @@ -0,0 +1,384 @@
55467 +#include <linux/kernel.h>
55468 +#include <asm/uaccess.h>
55469 +#include <asm/errno.h>
55470 +#include <net/sock.h>
55471 +#include <linux/file.h>
55472 +#include <linux/fs.h>
55473 +#include <linux/net.h>
55474 +#include <linux/in.h>
55475 +#include <linux/skbuff.h>
55476 +#include <linux/ip.h>
55477 +#include <linux/udp.h>
55478 +#include <linux/types.h>
55479 +#include <linux/sched.h>
55480 +#include <linux/netdevice.h>
55481 +#include <linux/inetdevice.h>
55482 +#include <linux/gracl.h>
55483 +#include <linux/grsecurity.h>
55484 +#include <linux/grinternal.h>
55485 +
55486 +#define GR_BIND 0x01
55487 +#define GR_CONNECT 0x02
55488 +#define GR_INVERT 0x04
55489 +#define GR_BINDOVERRIDE 0x08
55490 +#define GR_CONNECTOVERRIDE 0x10
55491 +#define GR_SOCK_FAMILY 0x20
55492 +
55493 +static const char * gr_protocols[IPPROTO_MAX] = {
55494 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55495 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55496 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55497 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55498 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55499 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55500 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55501 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55502 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55503 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55504 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55505 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55506 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55507 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55508 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55509 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55510 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55511 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55512 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55513 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55514 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55515 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55516 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55517 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55518 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55519 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55520 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55521 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55522 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55523 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55524 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55525 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55526 + };
55527 +
55528 +static const char * gr_socktypes[SOCK_MAX] = {
55529 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55530 + "unknown:7", "unknown:8", "unknown:9", "packet"
55531 + };
55532 +
55533 +static const char * gr_sockfamilies[AF_MAX+1] = {
55534 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55535 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55536 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55537 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55538 + };
55539 +
55540 +const char *
55541 +gr_proto_to_name(unsigned char proto)
55542 +{
55543 + return gr_protocols[proto];
55544 +}
55545 +
55546 +const char *
55547 +gr_socktype_to_name(unsigned char type)
55548 +{
55549 + return gr_socktypes[type];
55550 +}
55551 +
55552 +const char *
55553 +gr_sockfamily_to_name(unsigned char family)
55554 +{
55555 + return gr_sockfamilies[family];
55556 +}
55557 +
55558 +int
55559 +gr_search_socket(const int domain, const int type, const int protocol)
55560 +{
55561 + struct acl_subject_label *curr;
55562 + const struct cred *cred = current_cred();
55563 +
55564 + if (unlikely(!gr_acl_is_enabled()))
55565 + goto exit;
55566 +
55567 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55568 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55569 + goto exit; // let the kernel handle it
55570 +
55571 + curr = current->acl;
55572 +
55573 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55574 + /* the family is allowed, if this is PF_INET allow it only if
55575 + the extra sock type/protocol checks pass */
55576 + if (domain == PF_INET)
55577 + goto inet_check;
55578 + goto exit;
55579 + } else {
55580 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55581 + __u32 fakeip = 0;
55582 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55583 + current->role->roletype, cred->uid,
55584 + cred->gid, current->exec_file ?
55585 + gr_to_filename(current->exec_file->f_path.dentry,
55586 + current->exec_file->f_path.mnt) :
55587 + curr->filename, curr->filename,
55588 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55589 + &current->signal->saved_ip);
55590 + goto exit;
55591 + }
55592 + goto exit_fail;
55593 + }
55594 +
55595 +inet_check:
55596 + /* the rest of this checking is for IPv4 only */
55597 + if (!curr->ips)
55598 + goto exit;
55599 +
55600 + if ((curr->ip_type & (1 << type)) &&
55601 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55602 + goto exit;
55603 +
55604 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55605 + /* we don't place acls on raw sockets , and sometimes
55606 + dgram/ip sockets are opened for ioctl and not
55607 + bind/connect, so we'll fake a bind learn log */
55608 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55609 + __u32 fakeip = 0;
55610 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55611 + current->role->roletype, cred->uid,
55612 + cred->gid, current->exec_file ?
55613 + gr_to_filename(current->exec_file->f_path.dentry,
55614 + current->exec_file->f_path.mnt) :
55615 + curr->filename, curr->filename,
55616 + &fakeip, 0, type,
55617 + protocol, GR_CONNECT, &current->signal->saved_ip);
55618 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55619 + __u32 fakeip = 0;
55620 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55621 + current->role->roletype, cred->uid,
55622 + cred->gid, current->exec_file ?
55623 + gr_to_filename(current->exec_file->f_path.dentry,
55624 + current->exec_file->f_path.mnt) :
55625 + curr->filename, curr->filename,
55626 + &fakeip, 0, type,
55627 + protocol, GR_BIND, &current->signal->saved_ip);
55628 + }
55629 + /* we'll log when they use connect or bind */
55630 + goto exit;
55631 + }
55632 +
55633 +exit_fail:
55634 + if (domain == PF_INET)
55635 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55636 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55637 + else
55638 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55639 + gr_socktype_to_name(type), protocol);
55640 +
55641 + return 0;
55642 +exit:
55643 + return 1;
55644 +}
55645 +
55646 +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)
55647 +{
55648 + if ((ip->mode & mode) &&
55649 + (ip_port >= ip->low) &&
55650 + (ip_port <= ip->high) &&
55651 + ((ntohl(ip_addr) & our_netmask) ==
55652 + (ntohl(our_addr) & our_netmask))
55653 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55654 + && (ip->type & (1 << type))) {
55655 + if (ip->mode & GR_INVERT)
55656 + return 2; // specifically denied
55657 + else
55658 + return 1; // allowed
55659 + }
55660 +
55661 + return 0; // not specifically allowed, may continue parsing
55662 +}
55663 +
55664 +static int
55665 +gr_search_connectbind(const int full_mode, struct sock *sk,
55666 + struct sockaddr_in *addr, const int type)
55667 +{
55668 + char iface[IFNAMSIZ] = {0};
55669 + struct acl_subject_label *curr;
55670 + struct acl_ip_label *ip;
55671 + struct inet_sock *isk;
55672 + struct net_device *dev;
55673 + struct in_device *idev;
55674 + unsigned long i;
55675 + int ret;
55676 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55677 + __u32 ip_addr = 0;
55678 + __u32 our_addr;
55679 + __u32 our_netmask;
55680 + char *p;
55681 + __u16 ip_port = 0;
55682 + const struct cred *cred = current_cred();
55683 +
55684 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55685 + return 0;
55686 +
55687 + curr = current->acl;
55688 + isk = inet_sk(sk);
55689 +
55690 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55691 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55692 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55693 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55694 + struct sockaddr_in saddr;
55695 + int err;
55696 +
55697 + saddr.sin_family = AF_INET;
55698 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55699 + saddr.sin_port = isk->inet_sport;
55700 +
55701 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55702 + if (err)
55703 + return err;
55704 +
55705 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55706 + if (err)
55707 + return err;
55708 + }
55709 +
55710 + if (!curr->ips)
55711 + return 0;
55712 +
55713 + ip_addr = addr->sin_addr.s_addr;
55714 + ip_port = ntohs(addr->sin_port);
55715 +
55716 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55717 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55718 + current->role->roletype, cred->uid,
55719 + cred->gid, current->exec_file ?
55720 + gr_to_filename(current->exec_file->f_path.dentry,
55721 + current->exec_file->f_path.mnt) :
55722 + curr->filename, curr->filename,
55723 + &ip_addr, ip_port, type,
55724 + sk->sk_protocol, mode, &current->signal->saved_ip);
55725 + return 0;
55726 + }
55727 +
55728 + for (i = 0; i < curr->ip_num; i++) {
55729 + ip = *(curr->ips + i);
55730 + if (ip->iface != NULL) {
55731 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55732 + p = strchr(iface, ':');
55733 + if (p != NULL)
55734 + *p = '\0';
55735 + dev = dev_get_by_name(sock_net(sk), iface);
55736 + if (dev == NULL)
55737 + continue;
55738 + idev = in_dev_get(dev);
55739 + if (idev == NULL) {
55740 + dev_put(dev);
55741 + continue;
55742 + }
55743 + rcu_read_lock();
55744 + for_ifa(idev) {
55745 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55746 + our_addr = ifa->ifa_address;
55747 + our_netmask = 0xffffffff;
55748 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55749 + if (ret == 1) {
55750 + rcu_read_unlock();
55751 + in_dev_put(idev);
55752 + dev_put(dev);
55753 + return 0;
55754 + } else if (ret == 2) {
55755 + rcu_read_unlock();
55756 + in_dev_put(idev);
55757 + dev_put(dev);
55758 + goto denied;
55759 + }
55760 + }
55761 + } endfor_ifa(idev);
55762 + rcu_read_unlock();
55763 + in_dev_put(idev);
55764 + dev_put(dev);
55765 + } else {
55766 + our_addr = ip->addr;
55767 + our_netmask = ip->netmask;
55768 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55769 + if (ret == 1)
55770 + return 0;
55771 + else if (ret == 2)
55772 + goto denied;
55773 + }
55774 + }
55775 +
55776 +denied:
55777 + if (mode == GR_BIND)
55778 + 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));
55779 + else if (mode == GR_CONNECT)
55780 + 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));
55781 +
55782 + return -EACCES;
55783 +}
55784 +
55785 +int
55786 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55787 +{
55788 + /* always allow disconnection of dgram sockets with connect */
55789 + if (addr->sin_family == AF_UNSPEC)
55790 + return 0;
55791 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55792 +}
55793 +
55794 +int
55795 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55796 +{
55797 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55798 +}
55799 +
55800 +int gr_search_listen(struct socket *sock)
55801 +{
55802 + struct sock *sk = sock->sk;
55803 + struct sockaddr_in addr;
55804 +
55805 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55806 + addr.sin_port = inet_sk(sk)->inet_sport;
55807 +
55808 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55809 +}
55810 +
55811 +int gr_search_accept(struct socket *sock)
55812 +{
55813 + struct sock *sk = sock->sk;
55814 + struct sockaddr_in addr;
55815 +
55816 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55817 + addr.sin_port = inet_sk(sk)->inet_sport;
55818 +
55819 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55820 +}
55821 +
55822 +int
55823 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55824 +{
55825 + if (addr)
55826 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55827 + else {
55828 + struct sockaddr_in sin;
55829 + const struct inet_sock *inet = inet_sk(sk);
55830 +
55831 + sin.sin_addr.s_addr = inet->inet_daddr;
55832 + sin.sin_port = inet->inet_dport;
55833 +
55834 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55835 + }
55836 +}
55837 +
55838 +int
55839 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55840 +{
55841 + struct sockaddr_in sin;
55842 +
55843 + if (unlikely(skb->len < sizeof (struct udphdr)))
55844 + return 0; // skip this packet
55845 +
55846 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55847 + sin.sin_port = udp_hdr(skb)->source;
55848 +
55849 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55850 +}
55851 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55852 new file mode 100644
55853 index 0000000..25f54ef
55854 --- /dev/null
55855 +++ b/grsecurity/gracl_learn.c
55856 @@ -0,0 +1,207 @@
55857 +#include <linux/kernel.h>
55858 +#include <linux/mm.h>
55859 +#include <linux/sched.h>
55860 +#include <linux/poll.h>
55861 +#include <linux/string.h>
55862 +#include <linux/file.h>
55863 +#include <linux/types.h>
55864 +#include <linux/vmalloc.h>
55865 +#include <linux/grinternal.h>
55866 +
55867 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55868 + size_t count, loff_t *ppos);
55869 +extern int gr_acl_is_enabled(void);
55870 +
55871 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55872 +static int gr_learn_attached;
55873 +
55874 +/* use a 512k buffer */
55875 +#define LEARN_BUFFER_SIZE (512 * 1024)
55876 +
55877 +static DEFINE_SPINLOCK(gr_learn_lock);
55878 +static DEFINE_MUTEX(gr_learn_user_mutex);
55879 +
55880 +/* we need to maintain two buffers, so that the kernel context of grlearn
55881 + uses a semaphore around the userspace copying, and the other kernel contexts
55882 + use a spinlock when copying into the buffer, since they cannot sleep
55883 +*/
55884 +static char *learn_buffer;
55885 +static char *learn_buffer_user;
55886 +static int learn_buffer_len;
55887 +static int learn_buffer_user_len;
55888 +
55889 +static ssize_t
55890 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55891 +{
55892 + DECLARE_WAITQUEUE(wait, current);
55893 + ssize_t retval = 0;
55894 +
55895 + add_wait_queue(&learn_wait, &wait);
55896 + set_current_state(TASK_INTERRUPTIBLE);
55897 + do {
55898 + mutex_lock(&gr_learn_user_mutex);
55899 + spin_lock(&gr_learn_lock);
55900 + if (learn_buffer_len)
55901 + break;
55902 + spin_unlock(&gr_learn_lock);
55903 + mutex_unlock(&gr_learn_user_mutex);
55904 + if (file->f_flags & O_NONBLOCK) {
55905 + retval = -EAGAIN;
55906 + goto out;
55907 + }
55908 + if (signal_pending(current)) {
55909 + retval = -ERESTARTSYS;
55910 + goto out;
55911 + }
55912 +
55913 + schedule();
55914 + } while (1);
55915 +
55916 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55917 + learn_buffer_user_len = learn_buffer_len;
55918 + retval = learn_buffer_len;
55919 + learn_buffer_len = 0;
55920 +
55921 + spin_unlock(&gr_learn_lock);
55922 +
55923 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55924 + retval = -EFAULT;
55925 +
55926 + mutex_unlock(&gr_learn_user_mutex);
55927 +out:
55928 + set_current_state(TASK_RUNNING);
55929 + remove_wait_queue(&learn_wait, &wait);
55930 + return retval;
55931 +}
55932 +
55933 +static unsigned int
55934 +poll_learn(struct file * file, poll_table * wait)
55935 +{
55936 + poll_wait(file, &learn_wait, wait);
55937 +
55938 + if (learn_buffer_len)
55939 + return (POLLIN | POLLRDNORM);
55940 +
55941 + return 0;
55942 +}
55943 +
55944 +void
55945 +gr_clear_learn_entries(void)
55946 +{
55947 + char *tmp;
55948 +
55949 + mutex_lock(&gr_learn_user_mutex);
55950 + spin_lock(&gr_learn_lock);
55951 + tmp = learn_buffer;
55952 + learn_buffer = NULL;
55953 + spin_unlock(&gr_learn_lock);
55954 + if (tmp)
55955 + vfree(tmp);
55956 + if (learn_buffer_user != NULL) {
55957 + vfree(learn_buffer_user);
55958 + learn_buffer_user = NULL;
55959 + }
55960 + learn_buffer_len = 0;
55961 + mutex_unlock(&gr_learn_user_mutex);
55962 +
55963 + return;
55964 +}
55965 +
55966 +void
55967 +gr_add_learn_entry(const char *fmt, ...)
55968 +{
55969 + va_list args;
55970 + unsigned int len;
55971 +
55972 + if (!gr_learn_attached)
55973 + return;
55974 +
55975 + spin_lock(&gr_learn_lock);
55976 +
55977 + /* leave a gap at the end so we know when it's "full" but don't have to
55978 + compute the exact length of the string we're trying to append
55979 + */
55980 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55981 + spin_unlock(&gr_learn_lock);
55982 + wake_up_interruptible(&learn_wait);
55983 + return;
55984 + }
55985 + if (learn_buffer == NULL) {
55986 + spin_unlock(&gr_learn_lock);
55987 + return;
55988 + }
55989 +
55990 + va_start(args, fmt);
55991 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55992 + va_end(args);
55993 +
55994 + learn_buffer_len += len + 1;
55995 +
55996 + spin_unlock(&gr_learn_lock);
55997 + wake_up_interruptible(&learn_wait);
55998 +
55999 + return;
56000 +}
56001 +
56002 +static int
56003 +open_learn(struct inode *inode, struct file *file)
56004 +{
56005 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56006 + return -EBUSY;
56007 + if (file->f_mode & FMODE_READ) {
56008 + int retval = 0;
56009 + mutex_lock(&gr_learn_user_mutex);
56010 + if (learn_buffer == NULL)
56011 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56012 + if (learn_buffer_user == NULL)
56013 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56014 + if (learn_buffer == NULL) {
56015 + retval = -ENOMEM;
56016 + goto out_error;
56017 + }
56018 + if (learn_buffer_user == NULL) {
56019 + retval = -ENOMEM;
56020 + goto out_error;
56021 + }
56022 + learn_buffer_len = 0;
56023 + learn_buffer_user_len = 0;
56024 + gr_learn_attached = 1;
56025 +out_error:
56026 + mutex_unlock(&gr_learn_user_mutex);
56027 + return retval;
56028 + }
56029 + return 0;
56030 +}
56031 +
56032 +static int
56033 +close_learn(struct inode *inode, struct file *file)
56034 +{
56035 + if (file->f_mode & FMODE_READ) {
56036 + char *tmp = NULL;
56037 + mutex_lock(&gr_learn_user_mutex);
56038 + spin_lock(&gr_learn_lock);
56039 + tmp = learn_buffer;
56040 + learn_buffer = NULL;
56041 + spin_unlock(&gr_learn_lock);
56042 + if (tmp)
56043 + vfree(tmp);
56044 + if (learn_buffer_user != NULL) {
56045 + vfree(learn_buffer_user);
56046 + learn_buffer_user = NULL;
56047 + }
56048 + learn_buffer_len = 0;
56049 + learn_buffer_user_len = 0;
56050 + gr_learn_attached = 0;
56051 + mutex_unlock(&gr_learn_user_mutex);
56052 + }
56053 +
56054 + return 0;
56055 +}
56056 +
56057 +const struct file_operations grsec_fops = {
56058 + .read = read_learn,
56059 + .write = write_grsec_handler,
56060 + .open = open_learn,
56061 + .release = close_learn,
56062 + .poll = poll_learn,
56063 +};
56064 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56065 new file mode 100644
56066 index 0000000..39645c9
56067 --- /dev/null
56068 +++ b/grsecurity/gracl_res.c
56069 @@ -0,0 +1,68 @@
56070 +#include <linux/kernel.h>
56071 +#include <linux/sched.h>
56072 +#include <linux/gracl.h>
56073 +#include <linux/grinternal.h>
56074 +
56075 +static const char *restab_log[] = {
56076 + [RLIMIT_CPU] = "RLIMIT_CPU",
56077 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56078 + [RLIMIT_DATA] = "RLIMIT_DATA",
56079 + [RLIMIT_STACK] = "RLIMIT_STACK",
56080 + [RLIMIT_CORE] = "RLIMIT_CORE",
56081 + [RLIMIT_RSS] = "RLIMIT_RSS",
56082 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56083 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56084 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56085 + [RLIMIT_AS] = "RLIMIT_AS",
56086 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56087 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56088 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56089 + [RLIMIT_NICE] = "RLIMIT_NICE",
56090 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56091 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56092 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56093 +};
56094 +
56095 +void
56096 +gr_log_resource(const struct task_struct *task,
56097 + const int res, const unsigned long wanted, const int gt)
56098 +{
56099 + const struct cred *cred;
56100 + unsigned long rlim;
56101 +
56102 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56103 + return;
56104 +
56105 + // not yet supported resource
56106 + if (unlikely(!restab_log[res]))
56107 + return;
56108 +
56109 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56110 + rlim = task_rlimit_max(task, res);
56111 + else
56112 + rlim = task_rlimit(task, res);
56113 +
56114 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56115 + return;
56116 +
56117 + rcu_read_lock();
56118 + cred = __task_cred(task);
56119 +
56120 + if (res == RLIMIT_NPROC &&
56121 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56122 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56123 + goto out_rcu_unlock;
56124 + else if (res == RLIMIT_MEMLOCK &&
56125 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56126 + goto out_rcu_unlock;
56127 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56128 + goto out_rcu_unlock;
56129 + rcu_read_unlock();
56130 +
56131 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56132 +
56133 + return;
56134 +out_rcu_unlock:
56135 + rcu_read_unlock();
56136 + return;
56137 +}
56138 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56139 new file mode 100644
56140 index 0000000..5556be3
56141 --- /dev/null
56142 +++ b/grsecurity/gracl_segv.c
56143 @@ -0,0 +1,299 @@
56144 +#include <linux/kernel.h>
56145 +#include <linux/mm.h>
56146 +#include <asm/uaccess.h>
56147 +#include <asm/errno.h>
56148 +#include <asm/mman.h>
56149 +#include <net/sock.h>
56150 +#include <linux/file.h>
56151 +#include <linux/fs.h>
56152 +#include <linux/net.h>
56153 +#include <linux/in.h>
56154 +#include <linux/slab.h>
56155 +#include <linux/types.h>
56156 +#include <linux/sched.h>
56157 +#include <linux/timer.h>
56158 +#include <linux/gracl.h>
56159 +#include <linux/grsecurity.h>
56160 +#include <linux/grinternal.h>
56161 +
56162 +static struct crash_uid *uid_set;
56163 +static unsigned short uid_used;
56164 +static DEFINE_SPINLOCK(gr_uid_lock);
56165 +extern rwlock_t gr_inode_lock;
56166 +extern struct acl_subject_label *
56167 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56168 + struct acl_role_label *role);
56169 +
56170 +#ifdef CONFIG_BTRFS_FS
56171 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56172 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56173 +#endif
56174 +
56175 +static inline dev_t __get_dev(const struct dentry *dentry)
56176 +{
56177 +#ifdef CONFIG_BTRFS_FS
56178 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56179 + return get_btrfs_dev_from_inode(dentry->d_inode);
56180 + else
56181 +#endif
56182 + return dentry->d_inode->i_sb->s_dev;
56183 +}
56184 +
56185 +int
56186 +gr_init_uidset(void)
56187 +{
56188 + uid_set =
56189 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56190 + uid_used = 0;
56191 +
56192 + return uid_set ? 1 : 0;
56193 +}
56194 +
56195 +void
56196 +gr_free_uidset(void)
56197 +{
56198 + if (uid_set)
56199 + kfree(uid_set);
56200 +
56201 + return;
56202 +}
56203 +
56204 +int
56205 +gr_find_uid(const uid_t uid)
56206 +{
56207 + struct crash_uid *tmp = uid_set;
56208 + uid_t buid;
56209 + int low = 0, high = uid_used - 1, mid;
56210 +
56211 + while (high >= low) {
56212 + mid = (low + high) >> 1;
56213 + buid = tmp[mid].uid;
56214 + if (buid == uid)
56215 + return mid;
56216 + if (buid > uid)
56217 + high = mid - 1;
56218 + if (buid < uid)
56219 + low = mid + 1;
56220 + }
56221 +
56222 + return -1;
56223 +}
56224 +
56225 +static __inline__ void
56226 +gr_insertsort(void)
56227 +{
56228 + unsigned short i, j;
56229 + struct crash_uid index;
56230 +
56231 + for (i = 1; i < uid_used; i++) {
56232 + index = uid_set[i];
56233 + j = i;
56234 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56235 + uid_set[j] = uid_set[j - 1];
56236 + j--;
56237 + }
56238 + uid_set[j] = index;
56239 + }
56240 +
56241 + return;
56242 +}
56243 +
56244 +static __inline__ void
56245 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56246 +{
56247 + int loc;
56248 +
56249 + if (uid_used == GR_UIDTABLE_MAX)
56250 + return;
56251 +
56252 + loc = gr_find_uid(uid);
56253 +
56254 + if (loc >= 0) {
56255 + uid_set[loc].expires = expires;
56256 + return;
56257 + }
56258 +
56259 + uid_set[uid_used].uid = uid;
56260 + uid_set[uid_used].expires = expires;
56261 + uid_used++;
56262 +
56263 + gr_insertsort();
56264 +
56265 + return;
56266 +}
56267 +
56268 +void
56269 +gr_remove_uid(const unsigned short loc)
56270 +{
56271 + unsigned short i;
56272 +
56273 + for (i = loc + 1; i < uid_used; i++)
56274 + uid_set[i - 1] = uid_set[i];
56275 +
56276 + uid_used--;
56277 +
56278 + return;
56279 +}
56280 +
56281 +int
56282 +gr_check_crash_uid(const uid_t uid)
56283 +{
56284 + int loc;
56285 + int ret = 0;
56286 +
56287 + if (unlikely(!gr_acl_is_enabled()))
56288 + return 0;
56289 +
56290 + spin_lock(&gr_uid_lock);
56291 + loc = gr_find_uid(uid);
56292 +
56293 + if (loc < 0)
56294 + goto out_unlock;
56295 +
56296 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56297 + gr_remove_uid(loc);
56298 + else
56299 + ret = 1;
56300 +
56301 +out_unlock:
56302 + spin_unlock(&gr_uid_lock);
56303 + return ret;
56304 +}
56305 +
56306 +static __inline__ int
56307 +proc_is_setxid(const struct cred *cred)
56308 +{
56309 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56310 + cred->uid != cred->fsuid)
56311 + return 1;
56312 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56313 + cred->gid != cred->fsgid)
56314 + return 1;
56315 +
56316 + return 0;
56317 +}
56318 +
56319 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56320 +
56321 +void
56322 +gr_handle_crash(struct task_struct *task, const int sig)
56323 +{
56324 + struct acl_subject_label *curr;
56325 + struct task_struct *tsk, *tsk2;
56326 + const struct cred *cred;
56327 + const struct cred *cred2;
56328 +
56329 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56330 + return;
56331 +
56332 + if (unlikely(!gr_acl_is_enabled()))
56333 + return;
56334 +
56335 + curr = task->acl;
56336 +
56337 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56338 + return;
56339 +
56340 + if (time_before_eq(curr->expires, get_seconds())) {
56341 + curr->expires = 0;
56342 + curr->crashes = 0;
56343 + }
56344 +
56345 + curr->crashes++;
56346 +
56347 + if (!curr->expires)
56348 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56349 +
56350 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56351 + time_after(curr->expires, get_seconds())) {
56352 + rcu_read_lock();
56353 + cred = __task_cred(task);
56354 + if (cred->uid && proc_is_setxid(cred)) {
56355 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56356 + spin_lock(&gr_uid_lock);
56357 + gr_insert_uid(cred->uid, curr->expires);
56358 + spin_unlock(&gr_uid_lock);
56359 + curr->expires = 0;
56360 + curr->crashes = 0;
56361 + read_lock(&tasklist_lock);
56362 + do_each_thread(tsk2, tsk) {
56363 + cred2 = __task_cred(tsk);
56364 + if (tsk != task && cred2->uid == cred->uid)
56365 + gr_fake_force_sig(SIGKILL, tsk);
56366 + } while_each_thread(tsk2, tsk);
56367 + read_unlock(&tasklist_lock);
56368 + } else {
56369 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56370 + read_lock(&tasklist_lock);
56371 + read_lock(&grsec_exec_file_lock);
56372 + do_each_thread(tsk2, tsk) {
56373 + if (likely(tsk != task)) {
56374 + // if this thread has the same subject as the one that triggered
56375 + // RES_CRASH and it's the same binary, kill it
56376 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56377 + gr_fake_force_sig(SIGKILL, tsk);
56378 + }
56379 + } while_each_thread(tsk2, tsk);
56380 + read_unlock(&grsec_exec_file_lock);
56381 + read_unlock(&tasklist_lock);
56382 + }
56383 + rcu_read_unlock();
56384 + }
56385 +
56386 + return;
56387 +}
56388 +
56389 +int
56390 +gr_check_crash_exec(const struct file *filp)
56391 +{
56392 + struct acl_subject_label *curr;
56393 +
56394 + if (unlikely(!gr_acl_is_enabled()))
56395 + return 0;
56396 +
56397 + read_lock(&gr_inode_lock);
56398 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56399 + __get_dev(filp->f_path.dentry),
56400 + current->role);
56401 + read_unlock(&gr_inode_lock);
56402 +
56403 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56404 + (!curr->crashes && !curr->expires))
56405 + return 0;
56406 +
56407 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56408 + time_after(curr->expires, get_seconds()))
56409 + return 1;
56410 + else if (time_before_eq(curr->expires, get_seconds())) {
56411 + curr->crashes = 0;
56412 + curr->expires = 0;
56413 + }
56414 +
56415 + return 0;
56416 +}
56417 +
56418 +void
56419 +gr_handle_alertkill(struct task_struct *task)
56420 +{
56421 + struct acl_subject_label *curracl;
56422 + __u32 curr_ip;
56423 + struct task_struct *p, *p2;
56424 +
56425 + if (unlikely(!gr_acl_is_enabled()))
56426 + return;
56427 +
56428 + curracl = task->acl;
56429 + curr_ip = task->signal->curr_ip;
56430 +
56431 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56432 + read_lock(&tasklist_lock);
56433 + do_each_thread(p2, p) {
56434 + if (p->signal->curr_ip == curr_ip)
56435 + gr_fake_force_sig(SIGKILL, p);
56436 + } while_each_thread(p2, p);
56437 + read_unlock(&tasklist_lock);
56438 + } else if (curracl->mode & GR_KILLPROC)
56439 + gr_fake_force_sig(SIGKILL, task);
56440 +
56441 + return;
56442 +}
56443 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56444 new file mode 100644
56445 index 0000000..9d83a69
56446 --- /dev/null
56447 +++ b/grsecurity/gracl_shm.c
56448 @@ -0,0 +1,40 @@
56449 +#include <linux/kernel.h>
56450 +#include <linux/mm.h>
56451 +#include <linux/sched.h>
56452 +#include <linux/file.h>
56453 +#include <linux/ipc.h>
56454 +#include <linux/gracl.h>
56455 +#include <linux/grsecurity.h>
56456 +#include <linux/grinternal.h>
56457 +
56458 +int
56459 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56460 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56461 +{
56462 + struct task_struct *task;
56463 +
56464 + if (!gr_acl_is_enabled())
56465 + return 1;
56466 +
56467 + rcu_read_lock();
56468 + read_lock(&tasklist_lock);
56469 +
56470 + task = find_task_by_vpid(shm_cprid);
56471 +
56472 + if (unlikely(!task))
56473 + task = find_task_by_vpid(shm_lapid);
56474 +
56475 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56476 + (task->pid == shm_lapid)) &&
56477 + (task->acl->mode & GR_PROTSHM) &&
56478 + (task->acl != current->acl))) {
56479 + read_unlock(&tasklist_lock);
56480 + rcu_read_unlock();
56481 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56482 + return 0;
56483 + }
56484 + read_unlock(&tasklist_lock);
56485 + rcu_read_unlock();
56486 +
56487 + return 1;
56488 +}
56489 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56490 new file mode 100644
56491 index 0000000..bc0be01
56492 --- /dev/null
56493 +++ b/grsecurity/grsec_chdir.c
56494 @@ -0,0 +1,19 @@
56495 +#include <linux/kernel.h>
56496 +#include <linux/sched.h>
56497 +#include <linux/fs.h>
56498 +#include <linux/file.h>
56499 +#include <linux/grsecurity.h>
56500 +#include <linux/grinternal.h>
56501 +
56502 +void
56503 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56504 +{
56505 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56506 + if ((grsec_enable_chdir && grsec_enable_group &&
56507 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56508 + !grsec_enable_group)) {
56509 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56510 + }
56511 +#endif
56512 + return;
56513 +}
56514 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56515 new file mode 100644
56516 index 0000000..9807ee2
56517 --- /dev/null
56518 +++ b/grsecurity/grsec_chroot.c
56519 @@ -0,0 +1,368 @@
56520 +#include <linux/kernel.h>
56521 +#include <linux/module.h>
56522 +#include <linux/sched.h>
56523 +#include <linux/file.h>
56524 +#include <linux/fs.h>
56525 +#include <linux/mount.h>
56526 +#include <linux/types.h>
56527 +#include "../fs/mount.h"
56528 +#include <linux/grsecurity.h>
56529 +#include <linux/grinternal.h>
56530 +
56531 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56532 +{
56533 +#ifdef CONFIG_GRKERNSEC
56534 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56535 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56536 + task->gr_is_chrooted = 1;
56537 + else
56538 + task->gr_is_chrooted = 0;
56539 +
56540 + task->gr_chroot_dentry = path->dentry;
56541 +#endif
56542 + return;
56543 +}
56544 +
56545 +void gr_clear_chroot_entries(struct task_struct *task)
56546 +{
56547 +#ifdef CONFIG_GRKERNSEC
56548 + task->gr_is_chrooted = 0;
56549 + task->gr_chroot_dentry = NULL;
56550 +#endif
56551 + return;
56552 +}
56553 +
56554 +int
56555 +gr_handle_chroot_unix(const pid_t pid)
56556 +{
56557 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56558 + struct task_struct *p;
56559 +
56560 + if (unlikely(!grsec_enable_chroot_unix))
56561 + return 1;
56562 +
56563 + if (likely(!proc_is_chrooted(current)))
56564 + return 1;
56565 +
56566 + rcu_read_lock();
56567 + read_lock(&tasklist_lock);
56568 + p = find_task_by_vpid_unrestricted(pid);
56569 + if (unlikely(p && !have_same_root(current, p))) {
56570 + read_unlock(&tasklist_lock);
56571 + rcu_read_unlock();
56572 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56573 + return 0;
56574 + }
56575 + read_unlock(&tasklist_lock);
56576 + rcu_read_unlock();
56577 +#endif
56578 + return 1;
56579 +}
56580 +
56581 +int
56582 +gr_handle_chroot_nice(void)
56583 +{
56584 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56585 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56586 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56587 + return -EPERM;
56588 + }
56589 +#endif
56590 + return 0;
56591 +}
56592 +
56593 +int
56594 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56595 +{
56596 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56597 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56598 + && proc_is_chrooted(current)) {
56599 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56600 + return -EACCES;
56601 + }
56602 +#endif
56603 + return 0;
56604 +}
56605 +
56606 +int
56607 +gr_handle_chroot_rawio(const struct inode *inode)
56608 +{
56609 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56610 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56611 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56612 + return 1;
56613 +#endif
56614 + return 0;
56615 +}
56616 +
56617 +int
56618 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56619 +{
56620 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56621 + struct task_struct *p;
56622 + int ret = 0;
56623 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56624 + return ret;
56625 +
56626 + read_lock(&tasklist_lock);
56627 + do_each_pid_task(pid, type, p) {
56628 + if (!have_same_root(current, p)) {
56629 + ret = 1;
56630 + goto out;
56631 + }
56632 + } while_each_pid_task(pid, type, p);
56633 +out:
56634 + read_unlock(&tasklist_lock);
56635 + return ret;
56636 +#endif
56637 + return 0;
56638 +}
56639 +
56640 +int
56641 +gr_pid_is_chrooted(struct task_struct *p)
56642 +{
56643 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56644 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56645 + return 0;
56646 +
56647 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56648 + !have_same_root(current, p)) {
56649 + return 1;
56650 + }
56651 +#endif
56652 + return 0;
56653 +}
56654 +
56655 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56656 +
56657 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56658 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56659 +{
56660 + struct path path, currentroot;
56661 + int ret = 0;
56662 +
56663 + path.dentry = (struct dentry *)u_dentry;
56664 + path.mnt = (struct vfsmount *)u_mnt;
56665 + get_fs_root(current->fs, &currentroot);
56666 + if (path_is_under(&path, &currentroot))
56667 + ret = 1;
56668 + path_put(&currentroot);
56669 +
56670 + return ret;
56671 +}
56672 +#endif
56673 +
56674 +int
56675 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56676 +{
56677 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56678 + if (!grsec_enable_chroot_fchdir)
56679 + return 1;
56680 +
56681 + if (!proc_is_chrooted(current))
56682 + return 1;
56683 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56684 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56685 + return 0;
56686 + }
56687 +#endif
56688 + return 1;
56689 +}
56690 +
56691 +int
56692 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56693 + const time_t shm_createtime)
56694 +{
56695 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56696 + struct task_struct *p;
56697 + time_t starttime;
56698 +
56699 + if (unlikely(!grsec_enable_chroot_shmat))
56700 + return 1;
56701 +
56702 + if (likely(!proc_is_chrooted(current)))
56703 + return 1;
56704 +
56705 + rcu_read_lock();
56706 + read_lock(&tasklist_lock);
56707 +
56708 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56709 + starttime = p->start_time.tv_sec;
56710 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56711 + if (have_same_root(current, p)) {
56712 + goto allow;
56713 + } else {
56714 + read_unlock(&tasklist_lock);
56715 + rcu_read_unlock();
56716 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56717 + return 0;
56718 + }
56719 + }
56720 + /* creator exited, pid reuse, fall through to next check */
56721 + }
56722 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56723 + if (unlikely(!have_same_root(current, p))) {
56724 + read_unlock(&tasklist_lock);
56725 + rcu_read_unlock();
56726 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56727 + return 0;
56728 + }
56729 + }
56730 +
56731 +allow:
56732 + read_unlock(&tasklist_lock);
56733 + rcu_read_unlock();
56734 +#endif
56735 + return 1;
56736 +}
56737 +
56738 +void
56739 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56740 +{
56741 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56742 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56743 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56744 +#endif
56745 + return;
56746 +}
56747 +
56748 +int
56749 +gr_handle_chroot_mknod(const struct dentry *dentry,
56750 + const struct vfsmount *mnt, const int mode)
56751 +{
56752 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56753 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56754 + proc_is_chrooted(current)) {
56755 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56756 + return -EPERM;
56757 + }
56758 +#endif
56759 + return 0;
56760 +}
56761 +
56762 +int
56763 +gr_handle_chroot_mount(const struct dentry *dentry,
56764 + const struct vfsmount *mnt, const char *dev_name)
56765 +{
56766 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56767 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56768 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56769 + return -EPERM;
56770 + }
56771 +#endif
56772 + return 0;
56773 +}
56774 +
56775 +int
56776 +gr_handle_chroot_pivot(void)
56777 +{
56778 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56779 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56780 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56781 + return -EPERM;
56782 + }
56783 +#endif
56784 + return 0;
56785 +}
56786 +
56787 +int
56788 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56789 +{
56790 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56791 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56792 + !gr_is_outside_chroot(dentry, mnt)) {
56793 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56794 + return -EPERM;
56795 + }
56796 +#endif
56797 + return 0;
56798 +}
56799 +
56800 +extern const char *captab_log[];
56801 +extern int captab_log_entries;
56802 +
56803 +int
56804 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56805 +{
56806 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56807 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56808 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56809 + if (cap_raised(chroot_caps, cap)) {
56810 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56811 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56812 + }
56813 + return 0;
56814 + }
56815 + }
56816 +#endif
56817 + return 1;
56818 +}
56819 +
56820 +int
56821 +gr_chroot_is_capable(const int cap)
56822 +{
56823 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56824 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56825 +#endif
56826 + return 1;
56827 +}
56828 +
56829 +int
56830 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56831 +{
56832 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56833 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56834 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56835 + if (cap_raised(chroot_caps, cap)) {
56836 + return 0;
56837 + }
56838 + }
56839 +#endif
56840 + return 1;
56841 +}
56842 +
56843 +int
56844 +gr_chroot_is_capable_nolog(const int cap)
56845 +{
56846 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56847 + return gr_task_chroot_is_capable_nolog(current, cap);
56848 +#endif
56849 + return 1;
56850 +}
56851 +
56852 +int
56853 +gr_handle_chroot_sysctl(const int op)
56854 +{
56855 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56856 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56857 + proc_is_chrooted(current))
56858 + return -EACCES;
56859 +#endif
56860 + return 0;
56861 +}
56862 +
56863 +void
56864 +gr_handle_chroot_chdir(struct path *path)
56865 +{
56866 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56867 + if (grsec_enable_chroot_chdir)
56868 + set_fs_pwd(current->fs, path);
56869 +#endif
56870 + return;
56871 +}
56872 +
56873 +int
56874 +gr_handle_chroot_chmod(const struct dentry *dentry,
56875 + const struct vfsmount *mnt, const int mode)
56876 +{
56877 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56878 + /* allow chmod +s on directories, but not files */
56879 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56880 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56881 + proc_is_chrooted(current)) {
56882 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56883 + return -EPERM;
56884 + }
56885 +#endif
56886 + return 0;
56887 +}
56888 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56889 new file mode 100644
56890 index 0000000..213ad8b
56891 --- /dev/null
56892 +++ b/grsecurity/grsec_disabled.c
56893 @@ -0,0 +1,437 @@
56894 +#include <linux/kernel.h>
56895 +#include <linux/module.h>
56896 +#include <linux/sched.h>
56897 +#include <linux/file.h>
56898 +#include <linux/fs.h>
56899 +#include <linux/kdev_t.h>
56900 +#include <linux/net.h>
56901 +#include <linux/in.h>
56902 +#include <linux/ip.h>
56903 +#include <linux/skbuff.h>
56904 +#include <linux/sysctl.h>
56905 +
56906 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56907 +void
56908 +pax_set_initial_flags(struct linux_binprm *bprm)
56909 +{
56910 + return;
56911 +}
56912 +#endif
56913 +
56914 +#ifdef CONFIG_SYSCTL
56915 +__u32
56916 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56917 +{
56918 + return 0;
56919 +}
56920 +#endif
56921 +
56922 +#ifdef CONFIG_TASKSTATS
56923 +int gr_is_taskstats_denied(int pid)
56924 +{
56925 + return 0;
56926 +}
56927 +#endif
56928 +
56929 +int
56930 +gr_acl_is_enabled(void)
56931 +{
56932 + return 0;
56933 +}
56934 +
56935 +void
56936 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56937 +{
56938 + return;
56939 +}
56940 +
56941 +int
56942 +gr_handle_rawio(const struct inode *inode)
56943 +{
56944 + return 0;
56945 +}
56946 +
56947 +void
56948 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56949 +{
56950 + return;
56951 +}
56952 +
56953 +int
56954 +gr_handle_ptrace(struct task_struct *task, const long request)
56955 +{
56956 + return 0;
56957 +}
56958 +
56959 +int
56960 +gr_handle_proc_ptrace(struct task_struct *task)
56961 +{
56962 + return 0;
56963 +}
56964 +
56965 +void
56966 +gr_learn_resource(const struct task_struct *task,
56967 + const int res, const unsigned long wanted, const int gt)
56968 +{
56969 + return;
56970 +}
56971 +
56972 +int
56973 +gr_set_acls(const int type)
56974 +{
56975 + return 0;
56976 +}
56977 +
56978 +int
56979 +gr_check_hidden_task(const struct task_struct *tsk)
56980 +{
56981 + return 0;
56982 +}
56983 +
56984 +int
56985 +gr_check_protected_task(const struct task_struct *task)
56986 +{
56987 + return 0;
56988 +}
56989 +
56990 +int
56991 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56992 +{
56993 + return 0;
56994 +}
56995 +
56996 +void
56997 +gr_copy_label(struct task_struct *tsk)
56998 +{
56999 + return;
57000 +}
57001 +
57002 +void
57003 +gr_set_pax_flags(struct task_struct *task)
57004 +{
57005 + return;
57006 +}
57007 +
57008 +int
57009 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57010 + const int unsafe_share)
57011 +{
57012 + return 0;
57013 +}
57014 +
57015 +void
57016 +gr_handle_delete(const ino_t ino, const dev_t dev)
57017 +{
57018 + return;
57019 +}
57020 +
57021 +void
57022 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57023 +{
57024 + return;
57025 +}
57026 +
57027 +void
57028 +gr_handle_crash(struct task_struct *task, const int sig)
57029 +{
57030 + return;
57031 +}
57032 +
57033 +int
57034 +gr_check_crash_exec(const struct file *filp)
57035 +{
57036 + return 0;
57037 +}
57038 +
57039 +int
57040 +gr_check_crash_uid(const uid_t uid)
57041 +{
57042 + return 0;
57043 +}
57044 +
57045 +void
57046 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57047 + struct dentry *old_dentry,
57048 + struct dentry *new_dentry,
57049 + struct vfsmount *mnt, const __u8 replace)
57050 +{
57051 + return;
57052 +}
57053 +
57054 +int
57055 +gr_search_socket(const int family, const int type, const int protocol)
57056 +{
57057 + return 1;
57058 +}
57059 +
57060 +int
57061 +gr_search_connectbind(const int mode, const struct socket *sock,
57062 + const struct sockaddr_in *addr)
57063 +{
57064 + return 0;
57065 +}
57066 +
57067 +void
57068 +gr_handle_alertkill(struct task_struct *task)
57069 +{
57070 + return;
57071 +}
57072 +
57073 +__u32
57074 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57075 +{
57076 + return 1;
57077 +}
57078 +
57079 +__u32
57080 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57081 + const struct vfsmount * mnt)
57082 +{
57083 + return 1;
57084 +}
57085 +
57086 +__u32
57087 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57088 + int acc_mode)
57089 +{
57090 + return 1;
57091 +}
57092 +
57093 +__u32
57094 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57095 +{
57096 + return 1;
57097 +}
57098 +
57099 +__u32
57100 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57101 +{
57102 + return 1;
57103 +}
57104 +
57105 +int
57106 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57107 + unsigned int *vm_flags)
57108 +{
57109 + return 1;
57110 +}
57111 +
57112 +__u32
57113 +gr_acl_handle_truncate(const struct dentry * dentry,
57114 + const struct vfsmount * mnt)
57115 +{
57116 + return 1;
57117 +}
57118 +
57119 +__u32
57120 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57121 +{
57122 + return 1;
57123 +}
57124 +
57125 +__u32
57126 +gr_acl_handle_access(const struct dentry * dentry,
57127 + const struct vfsmount * mnt, const int fmode)
57128 +{
57129 + return 1;
57130 +}
57131 +
57132 +__u32
57133 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57134 + umode_t *mode)
57135 +{
57136 + return 1;
57137 +}
57138 +
57139 +__u32
57140 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57141 +{
57142 + return 1;
57143 +}
57144 +
57145 +__u32
57146 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57147 +{
57148 + return 1;
57149 +}
57150 +
57151 +void
57152 +grsecurity_init(void)
57153 +{
57154 + return;
57155 +}
57156 +
57157 +umode_t gr_acl_umask(void)
57158 +{
57159 + return 0;
57160 +}
57161 +
57162 +__u32
57163 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57164 + const struct dentry * parent_dentry,
57165 + const struct vfsmount * parent_mnt,
57166 + const int mode)
57167 +{
57168 + return 1;
57169 +}
57170 +
57171 +__u32
57172 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57173 + const struct dentry * parent_dentry,
57174 + const struct vfsmount * parent_mnt)
57175 +{
57176 + return 1;
57177 +}
57178 +
57179 +__u32
57180 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57181 + const struct dentry * parent_dentry,
57182 + const struct vfsmount * parent_mnt, const char *from)
57183 +{
57184 + return 1;
57185 +}
57186 +
57187 +__u32
57188 +gr_acl_handle_link(const struct dentry * new_dentry,
57189 + const struct dentry * parent_dentry,
57190 + const struct vfsmount * parent_mnt,
57191 + const struct dentry * old_dentry,
57192 + const struct vfsmount * old_mnt, const char *to)
57193 +{
57194 + return 1;
57195 +}
57196 +
57197 +int
57198 +gr_acl_handle_rename(const struct dentry *new_dentry,
57199 + const struct dentry *parent_dentry,
57200 + const struct vfsmount *parent_mnt,
57201 + const struct dentry *old_dentry,
57202 + const struct inode *old_parent_inode,
57203 + const struct vfsmount *old_mnt, const char *newname)
57204 +{
57205 + return 0;
57206 +}
57207 +
57208 +int
57209 +gr_acl_handle_filldir(const struct file *file, const char *name,
57210 + const int namelen, const ino_t ino)
57211 +{
57212 + return 1;
57213 +}
57214 +
57215 +int
57216 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57217 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57218 +{
57219 + return 1;
57220 +}
57221 +
57222 +int
57223 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57224 +{
57225 + return 0;
57226 +}
57227 +
57228 +int
57229 +gr_search_accept(const struct socket *sock)
57230 +{
57231 + return 0;
57232 +}
57233 +
57234 +int
57235 +gr_search_listen(const struct socket *sock)
57236 +{
57237 + return 0;
57238 +}
57239 +
57240 +int
57241 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57242 +{
57243 + return 0;
57244 +}
57245 +
57246 +__u32
57247 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57248 +{
57249 + return 1;
57250 +}
57251 +
57252 +__u32
57253 +gr_acl_handle_creat(const struct dentry * dentry,
57254 + const struct dentry * p_dentry,
57255 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57256 + const int imode)
57257 +{
57258 + return 1;
57259 +}
57260 +
57261 +void
57262 +gr_acl_handle_exit(void)
57263 +{
57264 + return;
57265 +}
57266 +
57267 +int
57268 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57269 +{
57270 + return 1;
57271 +}
57272 +
57273 +void
57274 +gr_set_role_label(const uid_t uid, const gid_t gid)
57275 +{
57276 + return;
57277 +}
57278 +
57279 +int
57280 +gr_acl_handle_procpidmem(const struct task_struct *task)
57281 +{
57282 + return 0;
57283 +}
57284 +
57285 +int
57286 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57287 +{
57288 + return 0;
57289 +}
57290 +
57291 +int
57292 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57293 +{
57294 + return 0;
57295 +}
57296 +
57297 +void
57298 +gr_set_kernel_label(struct task_struct *task)
57299 +{
57300 + return;
57301 +}
57302 +
57303 +int
57304 +gr_check_user_change(int real, int effective, int fs)
57305 +{
57306 + return 0;
57307 +}
57308 +
57309 +int
57310 +gr_check_group_change(int real, int effective, int fs)
57311 +{
57312 + return 0;
57313 +}
57314 +
57315 +int gr_acl_enable_at_secure(void)
57316 +{
57317 + return 0;
57318 +}
57319 +
57320 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57321 +{
57322 + return dentry->d_inode->i_sb->s_dev;
57323 +}
57324 +
57325 +EXPORT_SYMBOL(gr_learn_resource);
57326 +EXPORT_SYMBOL(gr_set_kernel_label);
57327 +#ifdef CONFIG_SECURITY
57328 +EXPORT_SYMBOL(gr_check_user_change);
57329 +EXPORT_SYMBOL(gr_check_group_change);
57330 +#endif
57331 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57332 new file mode 100644
57333 index 0000000..abfa971
57334 --- /dev/null
57335 +++ b/grsecurity/grsec_exec.c
57336 @@ -0,0 +1,174 @@
57337 +#include <linux/kernel.h>
57338 +#include <linux/sched.h>
57339 +#include <linux/file.h>
57340 +#include <linux/binfmts.h>
57341 +#include <linux/fs.h>
57342 +#include <linux/types.h>
57343 +#include <linux/grdefs.h>
57344 +#include <linux/grsecurity.h>
57345 +#include <linux/grinternal.h>
57346 +#include <linux/capability.h>
57347 +#include <linux/module.h>
57348 +
57349 +#include <asm/uaccess.h>
57350 +
57351 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57352 +static char gr_exec_arg_buf[132];
57353 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57354 +#endif
57355 +
57356 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57357 +
57358 +void
57359 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57360 +{
57361 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57362 + char *grarg = gr_exec_arg_buf;
57363 + unsigned int i, x, execlen = 0;
57364 + char c;
57365 +
57366 + if (!((grsec_enable_execlog && grsec_enable_group &&
57367 + in_group_p(grsec_audit_gid))
57368 + || (grsec_enable_execlog && !grsec_enable_group)))
57369 + return;
57370 +
57371 + mutex_lock(&gr_exec_arg_mutex);
57372 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57373 +
57374 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57375 + const char __user *p;
57376 + unsigned int len;
57377 +
57378 + p = get_user_arg_ptr(argv, i);
57379 + if (IS_ERR(p))
57380 + goto log;
57381 +
57382 + len = strnlen_user(p, 128 - execlen);
57383 + if (len > 128 - execlen)
57384 + len = 128 - execlen;
57385 + else if (len > 0)
57386 + len--;
57387 + if (copy_from_user(grarg + execlen, p, len))
57388 + goto log;
57389 +
57390 + /* rewrite unprintable characters */
57391 + for (x = 0; x < len; x++) {
57392 + c = *(grarg + execlen + x);
57393 + if (c < 32 || c > 126)
57394 + *(grarg + execlen + x) = ' ';
57395 + }
57396 +
57397 + execlen += len;
57398 + *(grarg + execlen) = ' ';
57399 + *(grarg + execlen + 1) = '\0';
57400 + execlen++;
57401 + }
57402 +
57403 + log:
57404 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57405 + bprm->file->f_path.mnt, grarg);
57406 + mutex_unlock(&gr_exec_arg_mutex);
57407 +#endif
57408 + return;
57409 +}
57410 +
57411 +#ifdef CONFIG_GRKERNSEC
57412 +extern int gr_acl_is_capable(const int cap);
57413 +extern int gr_acl_is_capable_nolog(const int cap);
57414 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57415 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57416 +extern int gr_chroot_is_capable(const int cap);
57417 +extern int gr_chroot_is_capable_nolog(const int cap);
57418 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57419 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57420 +#endif
57421 +
57422 +const char *captab_log[] = {
57423 + "CAP_CHOWN",
57424 + "CAP_DAC_OVERRIDE",
57425 + "CAP_DAC_READ_SEARCH",
57426 + "CAP_FOWNER",
57427 + "CAP_FSETID",
57428 + "CAP_KILL",
57429 + "CAP_SETGID",
57430 + "CAP_SETUID",
57431 + "CAP_SETPCAP",
57432 + "CAP_LINUX_IMMUTABLE",
57433 + "CAP_NET_BIND_SERVICE",
57434 + "CAP_NET_BROADCAST",
57435 + "CAP_NET_ADMIN",
57436 + "CAP_NET_RAW",
57437 + "CAP_IPC_LOCK",
57438 + "CAP_IPC_OWNER",
57439 + "CAP_SYS_MODULE",
57440 + "CAP_SYS_RAWIO",
57441 + "CAP_SYS_CHROOT",
57442 + "CAP_SYS_PTRACE",
57443 + "CAP_SYS_PACCT",
57444 + "CAP_SYS_ADMIN",
57445 + "CAP_SYS_BOOT",
57446 + "CAP_SYS_NICE",
57447 + "CAP_SYS_RESOURCE",
57448 + "CAP_SYS_TIME",
57449 + "CAP_SYS_TTY_CONFIG",
57450 + "CAP_MKNOD",
57451 + "CAP_LEASE",
57452 + "CAP_AUDIT_WRITE",
57453 + "CAP_AUDIT_CONTROL",
57454 + "CAP_SETFCAP",
57455 + "CAP_MAC_OVERRIDE",
57456 + "CAP_MAC_ADMIN",
57457 + "CAP_SYSLOG",
57458 + "CAP_WAKE_ALARM"
57459 +};
57460 +
57461 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57462 +
57463 +int gr_is_capable(const int cap)
57464 +{
57465 +#ifdef CONFIG_GRKERNSEC
57466 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57467 + return 1;
57468 + return 0;
57469 +#else
57470 + return 1;
57471 +#endif
57472 +}
57473 +
57474 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57475 +{
57476 +#ifdef CONFIG_GRKERNSEC
57477 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57478 + return 1;
57479 + return 0;
57480 +#else
57481 + return 1;
57482 +#endif
57483 +}
57484 +
57485 +int gr_is_capable_nolog(const int cap)
57486 +{
57487 +#ifdef CONFIG_GRKERNSEC
57488 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57489 + return 1;
57490 + return 0;
57491 +#else
57492 + return 1;
57493 +#endif
57494 +}
57495 +
57496 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57497 +{
57498 +#ifdef CONFIG_GRKERNSEC
57499 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57500 + return 1;
57501 + return 0;
57502 +#else
57503 + return 1;
57504 +#endif
57505 +}
57506 +
57507 +EXPORT_SYMBOL(gr_is_capable);
57508 +EXPORT_SYMBOL(gr_is_capable_nolog);
57509 +EXPORT_SYMBOL(gr_task_is_capable);
57510 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57511 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57512 new file mode 100644
57513 index 0000000..d3ee748
57514 --- /dev/null
57515 +++ b/grsecurity/grsec_fifo.c
57516 @@ -0,0 +1,24 @@
57517 +#include <linux/kernel.h>
57518 +#include <linux/sched.h>
57519 +#include <linux/fs.h>
57520 +#include <linux/file.h>
57521 +#include <linux/grinternal.h>
57522 +
57523 +int
57524 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57525 + const struct dentry *dir, const int flag, const int acc_mode)
57526 +{
57527 +#ifdef CONFIG_GRKERNSEC_FIFO
57528 + const struct cred *cred = current_cred();
57529 +
57530 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57531 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57532 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57533 + (cred->fsuid != dentry->d_inode->i_uid)) {
57534 + if (!inode_permission(dentry->d_inode, acc_mode))
57535 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57536 + return -EACCES;
57537 + }
57538 +#endif
57539 + return 0;
57540 +}
57541 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57542 new file mode 100644
57543 index 0000000..8ca18bf
57544 --- /dev/null
57545 +++ b/grsecurity/grsec_fork.c
57546 @@ -0,0 +1,23 @@
57547 +#include <linux/kernel.h>
57548 +#include <linux/sched.h>
57549 +#include <linux/grsecurity.h>
57550 +#include <linux/grinternal.h>
57551 +#include <linux/errno.h>
57552 +
57553 +void
57554 +gr_log_forkfail(const int retval)
57555 +{
57556 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57557 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57558 + switch (retval) {
57559 + case -EAGAIN:
57560 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57561 + break;
57562 + case -ENOMEM:
57563 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57564 + break;
57565 + }
57566 + }
57567 +#endif
57568 + return;
57569 +}
57570 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57571 new file mode 100644
57572 index 0000000..01ddde4
57573 --- /dev/null
57574 +++ b/grsecurity/grsec_init.c
57575 @@ -0,0 +1,277 @@
57576 +#include <linux/kernel.h>
57577 +#include <linux/sched.h>
57578 +#include <linux/mm.h>
57579 +#include <linux/gracl.h>
57580 +#include <linux/slab.h>
57581 +#include <linux/vmalloc.h>
57582 +#include <linux/percpu.h>
57583 +#include <linux/module.h>
57584 +
57585 +int grsec_enable_ptrace_readexec;
57586 +int grsec_enable_setxid;
57587 +int grsec_enable_brute;
57588 +int grsec_enable_link;
57589 +int grsec_enable_dmesg;
57590 +int grsec_enable_harden_ptrace;
57591 +int grsec_enable_fifo;
57592 +int grsec_enable_execlog;
57593 +int grsec_enable_signal;
57594 +int grsec_enable_forkfail;
57595 +int grsec_enable_audit_ptrace;
57596 +int grsec_enable_time;
57597 +int grsec_enable_audit_textrel;
57598 +int grsec_enable_group;
57599 +int grsec_audit_gid;
57600 +int grsec_enable_chdir;
57601 +int grsec_enable_mount;
57602 +int grsec_enable_rofs;
57603 +int grsec_enable_chroot_findtask;
57604 +int grsec_enable_chroot_mount;
57605 +int grsec_enable_chroot_shmat;
57606 +int grsec_enable_chroot_fchdir;
57607 +int grsec_enable_chroot_double;
57608 +int grsec_enable_chroot_pivot;
57609 +int grsec_enable_chroot_chdir;
57610 +int grsec_enable_chroot_chmod;
57611 +int grsec_enable_chroot_mknod;
57612 +int grsec_enable_chroot_nice;
57613 +int grsec_enable_chroot_execlog;
57614 +int grsec_enable_chroot_caps;
57615 +int grsec_enable_chroot_sysctl;
57616 +int grsec_enable_chroot_unix;
57617 +int grsec_enable_tpe;
57618 +int grsec_tpe_gid;
57619 +int grsec_enable_blackhole;
57620 +#ifdef CONFIG_IPV6_MODULE
57621 +EXPORT_SYMBOL(grsec_enable_blackhole);
57622 +#endif
57623 +int grsec_lastack_retries;
57624 +int grsec_enable_tpe_all;
57625 +int grsec_enable_tpe_invert;
57626 +int grsec_enable_socket_all;
57627 +int grsec_socket_all_gid;
57628 +int grsec_enable_socket_client;
57629 +int grsec_socket_client_gid;
57630 +int grsec_enable_socket_server;
57631 +int grsec_socket_server_gid;
57632 +int grsec_resource_logging;
57633 +int grsec_disable_privio;
57634 +int grsec_enable_log_rwxmaps;
57635 +int grsec_lock;
57636 +
57637 +DEFINE_SPINLOCK(grsec_alert_lock);
57638 +unsigned long grsec_alert_wtime = 0;
57639 +unsigned long grsec_alert_fyet = 0;
57640 +
57641 +DEFINE_SPINLOCK(grsec_audit_lock);
57642 +
57643 +DEFINE_RWLOCK(grsec_exec_file_lock);
57644 +
57645 +char *gr_shared_page[4];
57646 +
57647 +char *gr_alert_log_fmt;
57648 +char *gr_audit_log_fmt;
57649 +char *gr_alert_log_buf;
57650 +char *gr_audit_log_buf;
57651 +
57652 +extern struct gr_arg *gr_usermode;
57653 +extern unsigned char *gr_system_salt;
57654 +extern unsigned char *gr_system_sum;
57655 +
57656 +void __init
57657 +grsecurity_init(void)
57658 +{
57659 + int j;
57660 + /* create the per-cpu shared pages */
57661 +
57662 +#ifdef CONFIG_X86
57663 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57664 +#endif
57665 +
57666 + for (j = 0; j < 4; j++) {
57667 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57668 + if (gr_shared_page[j] == NULL) {
57669 + panic("Unable to allocate grsecurity shared page");
57670 + return;
57671 + }
57672 + }
57673 +
57674 + /* allocate log buffers */
57675 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57676 + if (!gr_alert_log_fmt) {
57677 + panic("Unable to allocate grsecurity alert log format buffer");
57678 + return;
57679 + }
57680 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57681 + if (!gr_audit_log_fmt) {
57682 + panic("Unable to allocate grsecurity audit log format buffer");
57683 + return;
57684 + }
57685 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57686 + if (!gr_alert_log_buf) {
57687 + panic("Unable to allocate grsecurity alert log buffer");
57688 + return;
57689 + }
57690 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57691 + if (!gr_audit_log_buf) {
57692 + panic("Unable to allocate grsecurity audit log buffer");
57693 + return;
57694 + }
57695 +
57696 + /* allocate memory for authentication structure */
57697 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57698 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57699 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57700 +
57701 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57702 + panic("Unable to allocate grsecurity authentication structure");
57703 + return;
57704 + }
57705 +
57706 +
57707 +#ifdef CONFIG_GRKERNSEC_IO
57708 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57709 + grsec_disable_privio = 1;
57710 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57711 + grsec_disable_privio = 1;
57712 +#else
57713 + grsec_disable_privio = 0;
57714 +#endif
57715 +#endif
57716 +
57717 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57718 + /* for backward compatibility, tpe_invert always defaults to on if
57719 + enabled in the kernel
57720 + */
57721 + grsec_enable_tpe_invert = 1;
57722 +#endif
57723 +
57724 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57725 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57726 + grsec_lock = 1;
57727 +#endif
57728 +
57729 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57730 + grsec_enable_audit_textrel = 1;
57731 +#endif
57732 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57733 + grsec_enable_log_rwxmaps = 1;
57734 +#endif
57735 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57736 + grsec_enable_group = 1;
57737 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57738 +#endif
57739 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57740 + grsec_enable_ptrace_readexec = 1;
57741 +#endif
57742 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57743 + grsec_enable_chdir = 1;
57744 +#endif
57745 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57746 + grsec_enable_harden_ptrace = 1;
57747 +#endif
57748 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57749 + grsec_enable_mount = 1;
57750 +#endif
57751 +#ifdef CONFIG_GRKERNSEC_LINK
57752 + grsec_enable_link = 1;
57753 +#endif
57754 +#ifdef CONFIG_GRKERNSEC_BRUTE
57755 + grsec_enable_brute = 1;
57756 +#endif
57757 +#ifdef CONFIG_GRKERNSEC_DMESG
57758 + grsec_enable_dmesg = 1;
57759 +#endif
57760 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57761 + grsec_enable_blackhole = 1;
57762 + grsec_lastack_retries = 4;
57763 +#endif
57764 +#ifdef CONFIG_GRKERNSEC_FIFO
57765 + grsec_enable_fifo = 1;
57766 +#endif
57767 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57768 + grsec_enable_execlog = 1;
57769 +#endif
57770 +#ifdef CONFIG_GRKERNSEC_SETXID
57771 + grsec_enable_setxid = 1;
57772 +#endif
57773 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57774 + grsec_enable_signal = 1;
57775 +#endif
57776 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57777 + grsec_enable_forkfail = 1;
57778 +#endif
57779 +#ifdef CONFIG_GRKERNSEC_TIME
57780 + grsec_enable_time = 1;
57781 +#endif
57782 +#ifdef CONFIG_GRKERNSEC_RESLOG
57783 + grsec_resource_logging = 1;
57784 +#endif
57785 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57786 + grsec_enable_chroot_findtask = 1;
57787 +#endif
57788 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57789 + grsec_enable_chroot_unix = 1;
57790 +#endif
57791 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57792 + grsec_enable_chroot_mount = 1;
57793 +#endif
57794 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57795 + grsec_enable_chroot_fchdir = 1;
57796 +#endif
57797 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57798 + grsec_enable_chroot_shmat = 1;
57799 +#endif
57800 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57801 + grsec_enable_audit_ptrace = 1;
57802 +#endif
57803 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57804 + grsec_enable_chroot_double = 1;
57805 +#endif
57806 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57807 + grsec_enable_chroot_pivot = 1;
57808 +#endif
57809 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57810 + grsec_enable_chroot_chdir = 1;
57811 +#endif
57812 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57813 + grsec_enable_chroot_chmod = 1;
57814 +#endif
57815 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57816 + grsec_enable_chroot_mknod = 1;
57817 +#endif
57818 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57819 + grsec_enable_chroot_nice = 1;
57820 +#endif
57821 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57822 + grsec_enable_chroot_execlog = 1;
57823 +#endif
57824 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57825 + grsec_enable_chroot_caps = 1;
57826 +#endif
57827 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57828 + grsec_enable_chroot_sysctl = 1;
57829 +#endif
57830 +#ifdef CONFIG_GRKERNSEC_TPE
57831 + grsec_enable_tpe = 1;
57832 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57833 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57834 + grsec_enable_tpe_all = 1;
57835 +#endif
57836 +#endif
57837 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57838 + grsec_enable_socket_all = 1;
57839 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57840 +#endif
57841 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57842 + grsec_enable_socket_client = 1;
57843 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57844 +#endif
57845 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57846 + grsec_enable_socket_server = 1;
57847 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57848 +#endif
57849 +#endif
57850 +
57851 + return;
57852 +}
57853 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57854 new file mode 100644
57855 index 0000000..3efe141
57856 --- /dev/null
57857 +++ b/grsecurity/grsec_link.c
57858 @@ -0,0 +1,43 @@
57859 +#include <linux/kernel.h>
57860 +#include <linux/sched.h>
57861 +#include <linux/fs.h>
57862 +#include <linux/file.h>
57863 +#include <linux/grinternal.h>
57864 +
57865 +int
57866 +gr_handle_follow_link(const struct inode *parent,
57867 + const struct inode *inode,
57868 + const struct dentry *dentry, const struct vfsmount *mnt)
57869 +{
57870 +#ifdef CONFIG_GRKERNSEC_LINK
57871 + const struct cred *cred = current_cred();
57872 +
57873 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57874 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57875 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57876 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57877 + return -EACCES;
57878 + }
57879 +#endif
57880 + return 0;
57881 +}
57882 +
57883 +int
57884 +gr_handle_hardlink(const struct dentry *dentry,
57885 + const struct vfsmount *mnt,
57886 + struct inode *inode, const int mode, const char *to)
57887 +{
57888 +#ifdef CONFIG_GRKERNSEC_LINK
57889 + const struct cred *cred = current_cred();
57890 +
57891 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57892 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57893 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57894 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57895 + !capable(CAP_FOWNER) && cred->uid) {
57896 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57897 + return -EPERM;
57898 + }
57899 +#endif
57900 + return 0;
57901 +}
57902 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57903 new file mode 100644
57904 index 0000000..a45d2e9
57905 --- /dev/null
57906 +++ b/grsecurity/grsec_log.c
57907 @@ -0,0 +1,322 @@
57908 +#include <linux/kernel.h>
57909 +#include <linux/sched.h>
57910 +#include <linux/file.h>
57911 +#include <linux/tty.h>
57912 +#include <linux/fs.h>
57913 +#include <linux/grinternal.h>
57914 +
57915 +#ifdef CONFIG_TREE_PREEMPT_RCU
57916 +#define DISABLE_PREEMPT() preempt_disable()
57917 +#define ENABLE_PREEMPT() preempt_enable()
57918 +#else
57919 +#define DISABLE_PREEMPT()
57920 +#define ENABLE_PREEMPT()
57921 +#endif
57922 +
57923 +#define BEGIN_LOCKS(x) \
57924 + DISABLE_PREEMPT(); \
57925 + rcu_read_lock(); \
57926 + read_lock(&tasklist_lock); \
57927 + read_lock(&grsec_exec_file_lock); \
57928 + if (x != GR_DO_AUDIT) \
57929 + spin_lock(&grsec_alert_lock); \
57930 + else \
57931 + spin_lock(&grsec_audit_lock)
57932 +
57933 +#define END_LOCKS(x) \
57934 + if (x != GR_DO_AUDIT) \
57935 + spin_unlock(&grsec_alert_lock); \
57936 + else \
57937 + spin_unlock(&grsec_audit_lock); \
57938 + read_unlock(&grsec_exec_file_lock); \
57939 + read_unlock(&tasklist_lock); \
57940 + rcu_read_unlock(); \
57941 + ENABLE_PREEMPT(); \
57942 + if (x == GR_DONT_AUDIT) \
57943 + gr_handle_alertkill(current)
57944 +
57945 +enum {
57946 + FLOODING,
57947 + NO_FLOODING
57948 +};
57949 +
57950 +extern char *gr_alert_log_fmt;
57951 +extern char *gr_audit_log_fmt;
57952 +extern char *gr_alert_log_buf;
57953 +extern char *gr_audit_log_buf;
57954 +
57955 +static int gr_log_start(int audit)
57956 +{
57957 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57958 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57959 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57960 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57961 + unsigned long curr_secs = get_seconds();
57962 +
57963 + if (audit == GR_DO_AUDIT)
57964 + goto set_fmt;
57965 +
57966 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57967 + grsec_alert_wtime = curr_secs;
57968 + grsec_alert_fyet = 0;
57969 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57970 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57971 + grsec_alert_fyet++;
57972 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57973 + grsec_alert_wtime = curr_secs;
57974 + grsec_alert_fyet++;
57975 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57976 + return FLOODING;
57977 + }
57978 + else return FLOODING;
57979 +
57980 +set_fmt:
57981 +#endif
57982 + memset(buf, 0, PAGE_SIZE);
57983 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57984 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57985 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57986 + } else if (current->signal->curr_ip) {
57987 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57988 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57989 + } else if (gr_acl_is_enabled()) {
57990 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57991 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57992 + } else {
57993 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57994 + strcpy(buf, fmt);
57995 + }
57996 +
57997 + return NO_FLOODING;
57998 +}
57999 +
58000 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58001 + __attribute__ ((format (printf, 2, 0)));
58002 +
58003 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58004 +{
58005 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58006 + unsigned int len = strlen(buf);
58007 +
58008 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58009 +
58010 + return;
58011 +}
58012 +
58013 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58014 + __attribute__ ((format (printf, 2, 3)));
58015 +
58016 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58017 +{
58018 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58019 + unsigned int len = strlen(buf);
58020 + va_list ap;
58021 +
58022 + va_start(ap, msg);
58023 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58024 + va_end(ap);
58025 +
58026 + return;
58027 +}
58028 +
58029 +static void gr_log_end(int audit, int append_default)
58030 +{
58031 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58032 +
58033 + if (append_default) {
58034 + unsigned int len = strlen(buf);
58035 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58036 + }
58037 +
58038 + printk("%s\n", buf);
58039 +
58040 + return;
58041 +}
58042 +
58043 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58044 +{
58045 + int logtype;
58046 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58047 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58048 + void *voidptr = NULL;
58049 + int num1 = 0, num2 = 0;
58050 + unsigned long ulong1 = 0, ulong2 = 0;
58051 + struct dentry *dentry = NULL;
58052 + struct vfsmount *mnt = NULL;
58053 + struct file *file = NULL;
58054 + struct task_struct *task = NULL;
58055 + const struct cred *cred, *pcred;
58056 + va_list ap;
58057 +
58058 + BEGIN_LOCKS(audit);
58059 + logtype = gr_log_start(audit);
58060 + if (logtype == FLOODING) {
58061 + END_LOCKS(audit);
58062 + return;
58063 + }
58064 + va_start(ap, argtypes);
58065 + switch (argtypes) {
58066 + case GR_TTYSNIFF:
58067 + task = va_arg(ap, struct task_struct *);
58068 + 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);
58069 + break;
58070 + case GR_SYSCTL_HIDDEN:
58071 + str1 = va_arg(ap, char *);
58072 + gr_log_middle_varargs(audit, msg, result, str1);
58073 + break;
58074 + case GR_RBAC:
58075 + dentry = va_arg(ap, struct dentry *);
58076 + mnt = va_arg(ap, struct vfsmount *);
58077 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58078 + break;
58079 + case GR_RBAC_STR:
58080 + dentry = va_arg(ap, struct dentry *);
58081 + mnt = va_arg(ap, struct vfsmount *);
58082 + str1 = va_arg(ap, char *);
58083 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58084 + break;
58085 + case GR_STR_RBAC:
58086 + str1 = va_arg(ap, char *);
58087 + dentry = va_arg(ap, struct dentry *);
58088 + mnt = va_arg(ap, struct vfsmount *);
58089 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58090 + break;
58091 + case GR_RBAC_MODE2:
58092 + dentry = va_arg(ap, struct dentry *);
58093 + mnt = va_arg(ap, struct vfsmount *);
58094 + str1 = va_arg(ap, char *);
58095 + str2 = va_arg(ap, char *);
58096 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58097 + break;
58098 + case GR_RBAC_MODE3:
58099 + dentry = va_arg(ap, struct dentry *);
58100 + mnt = va_arg(ap, struct vfsmount *);
58101 + str1 = va_arg(ap, char *);
58102 + str2 = va_arg(ap, char *);
58103 + str3 = va_arg(ap, char *);
58104 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58105 + break;
58106 + case GR_FILENAME:
58107 + dentry = va_arg(ap, struct dentry *);
58108 + mnt = va_arg(ap, struct vfsmount *);
58109 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58110 + break;
58111 + case GR_STR_FILENAME:
58112 + str1 = va_arg(ap, char *);
58113 + dentry = va_arg(ap, struct dentry *);
58114 + mnt = va_arg(ap, struct vfsmount *);
58115 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58116 + break;
58117 + case GR_FILENAME_STR:
58118 + dentry = va_arg(ap, struct dentry *);
58119 + mnt = va_arg(ap, struct vfsmount *);
58120 + str1 = va_arg(ap, char *);
58121 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58122 + break;
58123 + case GR_FILENAME_TWO_INT:
58124 + dentry = va_arg(ap, struct dentry *);
58125 + mnt = va_arg(ap, struct vfsmount *);
58126 + num1 = va_arg(ap, int);
58127 + num2 = va_arg(ap, int);
58128 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58129 + break;
58130 + case GR_FILENAME_TWO_INT_STR:
58131 + dentry = va_arg(ap, struct dentry *);
58132 + mnt = va_arg(ap, struct vfsmount *);
58133 + num1 = va_arg(ap, int);
58134 + num2 = va_arg(ap, int);
58135 + str1 = va_arg(ap, char *);
58136 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58137 + break;
58138 + case GR_TEXTREL:
58139 + file = va_arg(ap, struct file *);
58140 + ulong1 = va_arg(ap, unsigned long);
58141 + ulong2 = va_arg(ap, unsigned long);
58142 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58143 + break;
58144 + case GR_PTRACE:
58145 + task = va_arg(ap, struct task_struct *);
58146 + 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);
58147 + break;
58148 + case GR_RESOURCE:
58149 + task = va_arg(ap, struct task_struct *);
58150 + cred = __task_cred(task);
58151 + pcred = __task_cred(task->real_parent);
58152 + ulong1 = va_arg(ap, unsigned long);
58153 + str1 = va_arg(ap, char *);
58154 + ulong2 = va_arg(ap, unsigned long);
58155 + 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);
58156 + break;
58157 + case GR_CAP:
58158 + task = va_arg(ap, struct task_struct *);
58159 + cred = __task_cred(task);
58160 + pcred = __task_cred(task->real_parent);
58161 + str1 = va_arg(ap, char *);
58162 + 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);
58163 + break;
58164 + case GR_SIG:
58165 + str1 = va_arg(ap, char *);
58166 + voidptr = va_arg(ap, void *);
58167 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58168 + break;
58169 + case GR_SIG2:
58170 + task = va_arg(ap, struct task_struct *);
58171 + cred = __task_cred(task);
58172 + pcred = __task_cred(task->real_parent);
58173 + num1 = va_arg(ap, int);
58174 + 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);
58175 + break;
58176 + case GR_CRASH1:
58177 + task = va_arg(ap, struct task_struct *);
58178 + cred = __task_cred(task);
58179 + pcred = __task_cred(task->real_parent);
58180 + ulong1 = va_arg(ap, unsigned long);
58181 + 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);
58182 + break;
58183 + case GR_CRASH2:
58184 + task = va_arg(ap, struct task_struct *);
58185 + cred = __task_cred(task);
58186 + pcred = __task_cred(task->real_parent);
58187 + ulong1 = va_arg(ap, unsigned long);
58188 + 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);
58189 + break;
58190 + case GR_RWXMAP:
58191 + file = va_arg(ap, struct file *);
58192 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58193 + break;
58194 + case GR_PSACCT:
58195 + {
58196 + unsigned int wday, cday;
58197 + __u8 whr, chr;
58198 + __u8 wmin, cmin;
58199 + __u8 wsec, csec;
58200 + char cur_tty[64] = { 0 };
58201 + char parent_tty[64] = { 0 };
58202 +
58203 + task = va_arg(ap, struct task_struct *);
58204 + wday = va_arg(ap, unsigned int);
58205 + cday = va_arg(ap, unsigned int);
58206 + whr = va_arg(ap, int);
58207 + chr = va_arg(ap, int);
58208 + wmin = va_arg(ap, int);
58209 + cmin = va_arg(ap, int);
58210 + wsec = va_arg(ap, int);
58211 + csec = va_arg(ap, int);
58212 + ulong1 = va_arg(ap, unsigned long);
58213 + cred = __task_cred(task);
58214 + pcred = __task_cred(task->real_parent);
58215 +
58216 + 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);
58217 + }
58218 + break;
58219 + default:
58220 + gr_log_middle(audit, msg, ap);
58221 + }
58222 + va_end(ap);
58223 + // these don't need DEFAULTSECARGS printed on the end
58224 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58225 + gr_log_end(audit, 0);
58226 + else
58227 + gr_log_end(audit, 1);
58228 + END_LOCKS(audit);
58229 +}
58230 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58231 new file mode 100644
58232 index 0000000..f536303
58233 --- /dev/null
58234 +++ b/grsecurity/grsec_mem.c
58235 @@ -0,0 +1,40 @@
58236 +#include <linux/kernel.h>
58237 +#include <linux/sched.h>
58238 +#include <linux/mm.h>
58239 +#include <linux/mman.h>
58240 +#include <linux/grinternal.h>
58241 +
58242 +void
58243 +gr_handle_ioperm(void)
58244 +{
58245 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58246 + return;
58247 +}
58248 +
58249 +void
58250 +gr_handle_iopl(void)
58251 +{
58252 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58253 + return;
58254 +}
58255 +
58256 +void
58257 +gr_handle_mem_readwrite(u64 from, u64 to)
58258 +{
58259 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58260 + return;
58261 +}
58262 +
58263 +void
58264 +gr_handle_vm86(void)
58265 +{
58266 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58267 + return;
58268 +}
58269 +
58270 +void
58271 +gr_log_badprocpid(const char *entry)
58272 +{
58273 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58274 + return;
58275 +}
58276 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58277 new file mode 100644
58278 index 0000000..2131422
58279 --- /dev/null
58280 +++ b/grsecurity/grsec_mount.c
58281 @@ -0,0 +1,62 @@
58282 +#include <linux/kernel.h>
58283 +#include <linux/sched.h>
58284 +#include <linux/mount.h>
58285 +#include <linux/grsecurity.h>
58286 +#include <linux/grinternal.h>
58287 +
58288 +void
58289 +gr_log_remount(const char *devname, const int retval)
58290 +{
58291 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58292 + if (grsec_enable_mount && (retval >= 0))
58293 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58294 +#endif
58295 + return;
58296 +}
58297 +
58298 +void
58299 +gr_log_unmount(const char *devname, const int retval)
58300 +{
58301 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58302 + if (grsec_enable_mount && (retval >= 0))
58303 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58304 +#endif
58305 + return;
58306 +}
58307 +
58308 +void
58309 +gr_log_mount(const char *from, const char *to, const int retval)
58310 +{
58311 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58312 + if (grsec_enable_mount && (retval >= 0))
58313 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58314 +#endif
58315 + return;
58316 +}
58317 +
58318 +int
58319 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58320 +{
58321 +#ifdef CONFIG_GRKERNSEC_ROFS
58322 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58323 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58324 + return -EPERM;
58325 + } else
58326 + return 0;
58327 +#endif
58328 + return 0;
58329 +}
58330 +
58331 +int
58332 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58333 +{
58334 +#ifdef CONFIG_GRKERNSEC_ROFS
58335 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58336 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58337 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58338 + return -EPERM;
58339 + } else
58340 + return 0;
58341 +#endif
58342 + return 0;
58343 +}
58344 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58345 new file mode 100644
58346 index 0000000..a3b12a0
58347 --- /dev/null
58348 +++ b/grsecurity/grsec_pax.c
58349 @@ -0,0 +1,36 @@
58350 +#include <linux/kernel.h>
58351 +#include <linux/sched.h>
58352 +#include <linux/mm.h>
58353 +#include <linux/file.h>
58354 +#include <linux/grinternal.h>
58355 +#include <linux/grsecurity.h>
58356 +
58357 +void
58358 +gr_log_textrel(struct vm_area_struct * vma)
58359 +{
58360 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58361 + if (grsec_enable_audit_textrel)
58362 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58363 +#endif
58364 + return;
58365 +}
58366 +
58367 +void
58368 +gr_log_rwxmmap(struct file *file)
58369 +{
58370 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58371 + if (grsec_enable_log_rwxmaps)
58372 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58373 +#endif
58374 + return;
58375 +}
58376 +
58377 +void
58378 +gr_log_rwxmprotect(struct file *file)
58379 +{
58380 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58381 + if (grsec_enable_log_rwxmaps)
58382 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58383 +#endif
58384 + return;
58385 +}
58386 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58387 new file mode 100644
58388 index 0000000..f7f29aa
58389 --- /dev/null
58390 +++ b/grsecurity/grsec_ptrace.c
58391 @@ -0,0 +1,30 @@
58392 +#include <linux/kernel.h>
58393 +#include <linux/sched.h>
58394 +#include <linux/grinternal.h>
58395 +#include <linux/security.h>
58396 +
58397 +void
58398 +gr_audit_ptrace(struct task_struct *task)
58399 +{
58400 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58401 + if (grsec_enable_audit_ptrace)
58402 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58403 +#endif
58404 + return;
58405 +}
58406 +
58407 +int
58408 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58409 +{
58410 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58411 + const struct dentry *dentry = file->f_path.dentry;
58412 + const struct vfsmount *mnt = file->f_path.mnt;
58413 +
58414 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58415 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58416 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58417 + return -EACCES;
58418 + }
58419 +#endif
58420 + return 0;
58421 +}
58422 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58423 new file mode 100644
58424 index 0000000..7a5b2de
58425 --- /dev/null
58426 +++ b/grsecurity/grsec_sig.c
58427 @@ -0,0 +1,207 @@
58428 +#include <linux/kernel.h>
58429 +#include <linux/sched.h>
58430 +#include <linux/delay.h>
58431 +#include <linux/grsecurity.h>
58432 +#include <linux/grinternal.h>
58433 +#include <linux/hardirq.h>
58434 +
58435 +char *signames[] = {
58436 + [SIGSEGV] = "Segmentation fault",
58437 + [SIGILL] = "Illegal instruction",
58438 + [SIGABRT] = "Abort",
58439 + [SIGBUS] = "Invalid alignment/Bus error"
58440 +};
58441 +
58442 +void
58443 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58444 +{
58445 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58446 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58447 + (sig == SIGABRT) || (sig == SIGBUS))) {
58448 + if (t->pid == current->pid) {
58449 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58450 + } else {
58451 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58452 + }
58453 + }
58454 +#endif
58455 + return;
58456 +}
58457 +
58458 +int
58459 +gr_handle_signal(const struct task_struct *p, const int sig)
58460 +{
58461 +#ifdef CONFIG_GRKERNSEC
58462 + /* ignore the 0 signal for protected task checks */
58463 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58464 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58465 + return -EPERM;
58466 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58467 + return -EPERM;
58468 + }
58469 +#endif
58470 + return 0;
58471 +}
58472 +
58473 +#ifdef CONFIG_GRKERNSEC
58474 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58475 +
58476 +int gr_fake_force_sig(int sig, struct task_struct *t)
58477 +{
58478 + unsigned long int flags;
58479 + int ret, blocked, ignored;
58480 + struct k_sigaction *action;
58481 +
58482 + spin_lock_irqsave(&t->sighand->siglock, flags);
58483 + action = &t->sighand->action[sig-1];
58484 + ignored = action->sa.sa_handler == SIG_IGN;
58485 + blocked = sigismember(&t->blocked, sig);
58486 + if (blocked || ignored) {
58487 + action->sa.sa_handler = SIG_DFL;
58488 + if (blocked) {
58489 + sigdelset(&t->blocked, sig);
58490 + recalc_sigpending_and_wake(t);
58491 + }
58492 + }
58493 + if (action->sa.sa_handler == SIG_DFL)
58494 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58495 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58496 +
58497 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58498 +
58499 + return ret;
58500 +}
58501 +#endif
58502 +
58503 +#ifdef CONFIG_GRKERNSEC_BRUTE
58504 +#define GR_USER_BAN_TIME (15 * 60)
58505 +
58506 +static int __get_dumpable(unsigned long mm_flags)
58507 +{
58508 + int ret;
58509 +
58510 + ret = mm_flags & MMF_DUMPABLE_MASK;
58511 + return (ret >= 2) ? 2 : ret;
58512 +}
58513 +#endif
58514 +
58515 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58516 +{
58517 +#ifdef CONFIG_GRKERNSEC_BRUTE
58518 + uid_t uid = 0;
58519 +
58520 + if (!grsec_enable_brute)
58521 + return;
58522 +
58523 + rcu_read_lock();
58524 + read_lock(&tasklist_lock);
58525 + read_lock(&grsec_exec_file_lock);
58526 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58527 + p->real_parent->brute = 1;
58528 + else {
58529 + const struct cred *cred = __task_cred(p), *cred2;
58530 + struct task_struct *tsk, *tsk2;
58531 +
58532 + if (!__get_dumpable(mm_flags) && cred->uid) {
58533 + struct user_struct *user;
58534 +
58535 + uid = cred->uid;
58536 +
58537 + /* this is put upon execution past expiration */
58538 + user = find_user(uid);
58539 + if (user == NULL)
58540 + goto unlock;
58541 + user->banned = 1;
58542 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58543 + if (user->ban_expires == ~0UL)
58544 + user->ban_expires--;
58545 +
58546 + do_each_thread(tsk2, tsk) {
58547 + cred2 = __task_cred(tsk);
58548 + if (tsk != p && cred2->uid == uid)
58549 + gr_fake_force_sig(SIGKILL, tsk);
58550 + } while_each_thread(tsk2, tsk);
58551 + }
58552 + }
58553 +unlock:
58554 + read_unlock(&grsec_exec_file_lock);
58555 + read_unlock(&tasklist_lock);
58556 + rcu_read_unlock();
58557 +
58558 + if (uid)
58559 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58560 +
58561 +#endif
58562 + return;
58563 +}
58564 +
58565 +void gr_handle_brute_check(void)
58566 +{
58567 +#ifdef CONFIG_GRKERNSEC_BRUTE
58568 + if (current->brute)
58569 + msleep(30 * 1000);
58570 +#endif
58571 + return;
58572 +}
58573 +
58574 +void gr_handle_kernel_exploit(void)
58575 +{
58576 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58577 + const struct cred *cred;
58578 + struct task_struct *tsk, *tsk2;
58579 + struct user_struct *user;
58580 + uid_t uid;
58581 +
58582 + if (in_irq() || in_serving_softirq() || in_nmi())
58583 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58584 +
58585 + uid = current_uid();
58586 +
58587 + if (uid == 0)
58588 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58589 + else {
58590 + /* kill all the processes of this user, hold a reference
58591 + to their creds struct, and prevent them from creating
58592 + another process until system reset
58593 + */
58594 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58595 + /* we intentionally leak this ref */
58596 + user = get_uid(current->cred->user);
58597 + if (user) {
58598 + user->banned = 1;
58599 + user->ban_expires = ~0UL;
58600 + }
58601 +
58602 + read_lock(&tasklist_lock);
58603 + do_each_thread(tsk2, tsk) {
58604 + cred = __task_cred(tsk);
58605 + if (cred->uid == uid)
58606 + gr_fake_force_sig(SIGKILL, tsk);
58607 + } while_each_thread(tsk2, tsk);
58608 + read_unlock(&tasklist_lock);
58609 + }
58610 +#endif
58611 +}
58612 +
58613 +int __gr_process_user_ban(struct user_struct *user)
58614 +{
58615 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58616 + if (unlikely(user->banned)) {
58617 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58618 + user->banned = 0;
58619 + user->ban_expires = 0;
58620 + free_uid(user);
58621 + } else
58622 + return -EPERM;
58623 + }
58624 +#endif
58625 + return 0;
58626 +}
58627 +
58628 +int gr_process_user_ban(void)
58629 +{
58630 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58631 + return __gr_process_user_ban(current->cred->user);
58632 +#endif
58633 + return 0;
58634 +}
58635 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58636 new file mode 100644
58637 index 0000000..4030d57
58638 --- /dev/null
58639 +++ b/grsecurity/grsec_sock.c
58640 @@ -0,0 +1,244 @@
58641 +#include <linux/kernel.h>
58642 +#include <linux/module.h>
58643 +#include <linux/sched.h>
58644 +#include <linux/file.h>
58645 +#include <linux/net.h>
58646 +#include <linux/in.h>
58647 +#include <linux/ip.h>
58648 +#include <net/sock.h>
58649 +#include <net/inet_sock.h>
58650 +#include <linux/grsecurity.h>
58651 +#include <linux/grinternal.h>
58652 +#include <linux/gracl.h>
58653 +
58654 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58655 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58656 +
58657 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58658 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58659 +
58660 +#ifdef CONFIG_UNIX_MODULE
58661 +EXPORT_SYMBOL(gr_acl_handle_unix);
58662 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58663 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58664 +EXPORT_SYMBOL(gr_handle_create);
58665 +#endif
58666 +
58667 +#ifdef CONFIG_GRKERNSEC
58668 +#define gr_conn_table_size 32749
58669 +struct conn_table_entry {
58670 + struct conn_table_entry *next;
58671 + struct signal_struct *sig;
58672 +};
58673 +
58674 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58675 +DEFINE_SPINLOCK(gr_conn_table_lock);
58676 +
58677 +extern const char * gr_socktype_to_name(unsigned char type);
58678 +extern const char * gr_proto_to_name(unsigned char proto);
58679 +extern const char * gr_sockfamily_to_name(unsigned char family);
58680 +
58681 +static __inline__ int
58682 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58683 +{
58684 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58685 +}
58686 +
58687 +static __inline__ int
58688 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58689 + __u16 sport, __u16 dport)
58690 +{
58691 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58692 + sig->gr_sport == sport && sig->gr_dport == dport))
58693 + return 1;
58694 + else
58695 + return 0;
58696 +}
58697 +
58698 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58699 +{
58700 + struct conn_table_entry **match;
58701 + unsigned int index;
58702 +
58703 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58704 + sig->gr_sport, sig->gr_dport,
58705 + gr_conn_table_size);
58706 +
58707 + newent->sig = sig;
58708 +
58709 + match = &gr_conn_table[index];
58710 + newent->next = *match;
58711 + *match = newent;
58712 +
58713 + return;
58714 +}
58715 +
58716 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58717 +{
58718 + struct conn_table_entry *match, *last = NULL;
58719 + unsigned int index;
58720 +
58721 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58722 + sig->gr_sport, sig->gr_dport,
58723 + gr_conn_table_size);
58724 +
58725 + match = gr_conn_table[index];
58726 + while (match && !conn_match(match->sig,
58727 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58728 + sig->gr_dport)) {
58729 + last = match;
58730 + match = match->next;
58731 + }
58732 +
58733 + if (match) {
58734 + if (last)
58735 + last->next = match->next;
58736 + else
58737 + gr_conn_table[index] = NULL;
58738 + kfree(match);
58739 + }
58740 +
58741 + return;
58742 +}
58743 +
58744 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58745 + __u16 sport, __u16 dport)
58746 +{
58747 + struct conn_table_entry *match;
58748 + unsigned int index;
58749 +
58750 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58751 +
58752 + match = gr_conn_table[index];
58753 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58754 + match = match->next;
58755 +
58756 + if (match)
58757 + return match->sig;
58758 + else
58759 + return NULL;
58760 +}
58761 +
58762 +#endif
58763 +
58764 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58765 +{
58766 +#ifdef CONFIG_GRKERNSEC
58767 + struct signal_struct *sig = task->signal;
58768 + struct conn_table_entry *newent;
58769 +
58770 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58771 + if (newent == NULL)
58772 + return;
58773 + /* no bh lock needed since we are called with bh disabled */
58774 + spin_lock(&gr_conn_table_lock);
58775 + gr_del_task_from_ip_table_nolock(sig);
58776 + sig->gr_saddr = inet->inet_rcv_saddr;
58777 + sig->gr_daddr = inet->inet_daddr;
58778 + sig->gr_sport = inet->inet_sport;
58779 + sig->gr_dport = inet->inet_dport;
58780 + gr_add_to_task_ip_table_nolock(sig, newent);
58781 + spin_unlock(&gr_conn_table_lock);
58782 +#endif
58783 + return;
58784 +}
58785 +
58786 +void gr_del_task_from_ip_table(struct task_struct *task)
58787 +{
58788 +#ifdef CONFIG_GRKERNSEC
58789 + spin_lock_bh(&gr_conn_table_lock);
58790 + gr_del_task_from_ip_table_nolock(task->signal);
58791 + spin_unlock_bh(&gr_conn_table_lock);
58792 +#endif
58793 + return;
58794 +}
58795 +
58796 +void
58797 +gr_attach_curr_ip(const struct sock *sk)
58798 +{
58799 +#ifdef CONFIG_GRKERNSEC
58800 + struct signal_struct *p, *set;
58801 + const struct inet_sock *inet = inet_sk(sk);
58802 +
58803 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58804 + return;
58805 +
58806 + set = current->signal;
58807 +
58808 + spin_lock_bh(&gr_conn_table_lock);
58809 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58810 + inet->inet_dport, inet->inet_sport);
58811 + if (unlikely(p != NULL)) {
58812 + set->curr_ip = p->curr_ip;
58813 + set->used_accept = 1;
58814 + gr_del_task_from_ip_table_nolock(p);
58815 + spin_unlock_bh(&gr_conn_table_lock);
58816 + return;
58817 + }
58818 + spin_unlock_bh(&gr_conn_table_lock);
58819 +
58820 + set->curr_ip = inet->inet_daddr;
58821 + set->used_accept = 1;
58822 +#endif
58823 + return;
58824 +}
58825 +
58826 +int
58827 +gr_handle_sock_all(const int family, const int type, const int protocol)
58828 +{
58829 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58830 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58831 + (family != AF_UNIX)) {
58832 + if (family == AF_INET)
58833 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58834 + else
58835 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58836 + return -EACCES;
58837 + }
58838 +#endif
58839 + return 0;
58840 +}
58841 +
58842 +int
58843 +gr_handle_sock_server(const struct sockaddr *sck)
58844 +{
58845 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58846 + if (grsec_enable_socket_server &&
58847 + in_group_p(grsec_socket_server_gid) &&
58848 + sck && (sck->sa_family != AF_UNIX) &&
58849 + (sck->sa_family != AF_LOCAL)) {
58850 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58851 + return -EACCES;
58852 + }
58853 +#endif
58854 + return 0;
58855 +}
58856 +
58857 +int
58858 +gr_handle_sock_server_other(const struct sock *sck)
58859 +{
58860 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58861 + if (grsec_enable_socket_server &&
58862 + in_group_p(grsec_socket_server_gid) &&
58863 + sck && (sck->sk_family != AF_UNIX) &&
58864 + (sck->sk_family != AF_LOCAL)) {
58865 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58866 + return -EACCES;
58867 + }
58868 +#endif
58869 + return 0;
58870 +}
58871 +
58872 +int
58873 +gr_handle_sock_client(const struct sockaddr *sck)
58874 +{
58875 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58876 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58877 + sck && (sck->sa_family != AF_UNIX) &&
58878 + (sck->sa_family != AF_LOCAL)) {
58879 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58880 + return -EACCES;
58881 + }
58882 +#endif
58883 + return 0;
58884 +}
58885 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58886 new file mode 100644
58887 index 0000000..a1aedd7
58888 --- /dev/null
58889 +++ b/grsecurity/grsec_sysctl.c
58890 @@ -0,0 +1,451 @@
58891 +#include <linux/kernel.h>
58892 +#include <linux/sched.h>
58893 +#include <linux/sysctl.h>
58894 +#include <linux/grsecurity.h>
58895 +#include <linux/grinternal.h>
58896 +
58897 +int
58898 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58899 +{
58900 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58901 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58902 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58903 + return -EACCES;
58904 + }
58905 +#endif
58906 + return 0;
58907 +}
58908 +
58909 +#ifdef CONFIG_GRKERNSEC_ROFS
58910 +static int __maybe_unused one = 1;
58911 +#endif
58912 +
58913 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58914 +struct ctl_table grsecurity_table[] = {
58915 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58916 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58917 +#ifdef CONFIG_GRKERNSEC_IO
58918 + {
58919 + .procname = "disable_priv_io",
58920 + .data = &grsec_disable_privio,
58921 + .maxlen = sizeof(int),
58922 + .mode = 0600,
58923 + .proc_handler = &proc_dointvec,
58924 + },
58925 +#endif
58926 +#endif
58927 +#ifdef CONFIG_GRKERNSEC_LINK
58928 + {
58929 + .procname = "linking_restrictions",
58930 + .data = &grsec_enable_link,
58931 + .maxlen = sizeof(int),
58932 + .mode = 0600,
58933 + .proc_handler = &proc_dointvec,
58934 + },
58935 +#endif
58936 +#ifdef CONFIG_GRKERNSEC_BRUTE
58937 + {
58938 + .procname = "deter_bruteforce",
58939 + .data = &grsec_enable_brute,
58940 + .maxlen = sizeof(int),
58941 + .mode = 0600,
58942 + .proc_handler = &proc_dointvec,
58943 + },
58944 +#endif
58945 +#ifdef CONFIG_GRKERNSEC_FIFO
58946 + {
58947 + .procname = "fifo_restrictions",
58948 + .data = &grsec_enable_fifo,
58949 + .maxlen = sizeof(int),
58950 + .mode = 0600,
58951 + .proc_handler = &proc_dointvec,
58952 + },
58953 +#endif
58954 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58955 + {
58956 + .procname = "ptrace_readexec",
58957 + .data = &grsec_enable_ptrace_readexec,
58958 + .maxlen = sizeof(int),
58959 + .mode = 0600,
58960 + .proc_handler = &proc_dointvec,
58961 + },
58962 +#endif
58963 +#ifdef CONFIG_GRKERNSEC_SETXID
58964 + {
58965 + .procname = "consistent_setxid",
58966 + .data = &grsec_enable_setxid,
58967 + .maxlen = sizeof(int),
58968 + .mode = 0600,
58969 + .proc_handler = &proc_dointvec,
58970 + },
58971 +#endif
58972 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58973 + {
58974 + .procname = "ip_blackhole",
58975 + .data = &grsec_enable_blackhole,
58976 + .maxlen = sizeof(int),
58977 + .mode = 0600,
58978 + .proc_handler = &proc_dointvec,
58979 + },
58980 + {
58981 + .procname = "lastack_retries",
58982 + .data = &grsec_lastack_retries,
58983 + .maxlen = sizeof(int),
58984 + .mode = 0600,
58985 + .proc_handler = &proc_dointvec,
58986 + },
58987 +#endif
58988 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58989 + {
58990 + .procname = "exec_logging",
58991 + .data = &grsec_enable_execlog,
58992 + .maxlen = sizeof(int),
58993 + .mode = 0600,
58994 + .proc_handler = &proc_dointvec,
58995 + },
58996 +#endif
58997 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58998 + {
58999 + .procname = "rwxmap_logging",
59000 + .data = &grsec_enable_log_rwxmaps,
59001 + .maxlen = sizeof(int),
59002 + .mode = 0600,
59003 + .proc_handler = &proc_dointvec,
59004 + },
59005 +#endif
59006 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59007 + {
59008 + .procname = "signal_logging",
59009 + .data = &grsec_enable_signal,
59010 + .maxlen = sizeof(int),
59011 + .mode = 0600,
59012 + .proc_handler = &proc_dointvec,
59013 + },
59014 +#endif
59015 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59016 + {
59017 + .procname = "forkfail_logging",
59018 + .data = &grsec_enable_forkfail,
59019 + .maxlen = sizeof(int),
59020 + .mode = 0600,
59021 + .proc_handler = &proc_dointvec,
59022 + },
59023 +#endif
59024 +#ifdef CONFIG_GRKERNSEC_TIME
59025 + {
59026 + .procname = "timechange_logging",
59027 + .data = &grsec_enable_time,
59028 + .maxlen = sizeof(int),
59029 + .mode = 0600,
59030 + .proc_handler = &proc_dointvec,
59031 + },
59032 +#endif
59033 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59034 + {
59035 + .procname = "chroot_deny_shmat",
59036 + .data = &grsec_enable_chroot_shmat,
59037 + .maxlen = sizeof(int),
59038 + .mode = 0600,
59039 + .proc_handler = &proc_dointvec,
59040 + },
59041 +#endif
59042 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59043 + {
59044 + .procname = "chroot_deny_unix",
59045 + .data = &grsec_enable_chroot_unix,
59046 + .maxlen = sizeof(int),
59047 + .mode = 0600,
59048 + .proc_handler = &proc_dointvec,
59049 + },
59050 +#endif
59051 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59052 + {
59053 + .procname = "chroot_deny_mount",
59054 + .data = &grsec_enable_chroot_mount,
59055 + .maxlen = sizeof(int),
59056 + .mode = 0600,
59057 + .proc_handler = &proc_dointvec,
59058 + },
59059 +#endif
59060 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59061 + {
59062 + .procname = "chroot_deny_fchdir",
59063 + .data = &grsec_enable_chroot_fchdir,
59064 + .maxlen = sizeof(int),
59065 + .mode = 0600,
59066 + .proc_handler = &proc_dointvec,
59067 + },
59068 +#endif
59069 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59070 + {
59071 + .procname = "chroot_deny_chroot",
59072 + .data = &grsec_enable_chroot_double,
59073 + .maxlen = sizeof(int),
59074 + .mode = 0600,
59075 + .proc_handler = &proc_dointvec,
59076 + },
59077 +#endif
59078 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59079 + {
59080 + .procname = "chroot_deny_pivot",
59081 + .data = &grsec_enable_chroot_pivot,
59082 + .maxlen = sizeof(int),
59083 + .mode = 0600,
59084 + .proc_handler = &proc_dointvec,
59085 + },
59086 +#endif
59087 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59088 + {
59089 + .procname = "chroot_enforce_chdir",
59090 + .data = &grsec_enable_chroot_chdir,
59091 + .maxlen = sizeof(int),
59092 + .mode = 0600,
59093 + .proc_handler = &proc_dointvec,
59094 + },
59095 +#endif
59096 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59097 + {
59098 + .procname = "chroot_deny_chmod",
59099 + .data = &grsec_enable_chroot_chmod,
59100 + .maxlen = sizeof(int),
59101 + .mode = 0600,
59102 + .proc_handler = &proc_dointvec,
59103 + },
59104 +#endif
59105 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59106 + {
59107 + .procname = "chroot_deny_mknod",
59108 + .data = &grsec_enable_chroot_mknod,
59109 + .maxlen = sizeof(int),
59110 + .mode = 0600,
59111 + .proc_handler = &proc_dointvec,
59112 + },
59113 +#endif
59114 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59115 + {
59116 + .procname = "chroot_restrict_nice",
59117 + .data = &grsec_enable_chroot_nice,
59118 + .maxlen = sizeof(int),
59119 + .mode = 0600,
59120 + .proc_handler = &proc_dointvec,
59121 + },
59122 +#endif
59123 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59124 + {
59125 + .procname = "chroot_execlog",
59126 + .data = &grsec_enable_chroot_execlog,
59127 + .maxlen = sizeof(int),
59128 + .mode = 0600,
59129 + .proc_handler = &proc_dointvec,
59130 + },
59131 +#endif
59132 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59133 + {
59134 + .procname = "chroot_caps",
59135 + .data = &grsec_enable_chroot_caps,
59136 + .maxlen = sizeof(int),
59137 + .mode = 0600,
59138 + .proc_handler = &proc_dointvec,
59139 + },
59140 +#endif
59141 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59142 + {
59143 + .procname = "chroot_deny_sysctl",
59144 + .data = &grsec_enable_chroot_sysctl,
59145 + .maxlen = sizeof(int),
59146 + .mode = 0600,
59147 + .proc_handler = &proc_dointvec,
59148 + },
59149 +#endif
59150 +#ifdef CONFIG_GRKERNSEC_TPE
59151 + {
59152 + .procname = "tpe",
59153 + .data = &grsec_enable_tpe,
59154 + .maxlen = sizeof(int),
59155 + .mode = 0600,
59156 + .proc_handler = &proc_dointvec,
59157 + },
59158 + {
59159 + .procname = "tpe_gid",
59160 + .data = &grsec_tpe_gid,
59161 + .maxlen = sizeof(int),
59162 + .mode = 0600,
59163 + .proc_handler = &proc_dointvec,
59164 + },
59165 +#endif
59166 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59167 + {
59168 + .procname = "tpe_invert",
59169 + .data = &grsec_enable_tpe_invert,
59170 + .maxlen = sizeof(int),
59171 + .mode = 0600,
59172 + .proc_handler = &proc_dointvec,
59173 + },
59174 +#endif
59175 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59176 + {
59177 + .procname = "tpe_restrict_all",
59178 + .data = &grsec_enable_tpe_all,
59179 + .maxlen = sizeof(int),
59180 + .mode = 0600,
59181 + .proc_handler = &proc_dointvec,
59182 + },
59183 +#endif
59184 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59185 + {
59186 + .procname = "socket_all",
59187 + .data = &grsec_enable_socket_all,
59188 + .maxlen = sizeof(int),
59189 + .mode = 0600,
59190 + .proc_handler = &proc_dointvec,
59191 + },
59192 + {
59193 + .procname = "socket_all_gid",
59194 + .data = &grsec_socket_all_gid,
59195 + .maxlen = sizeof(int),
59196 + .mode = 0600,
59197 + .proc_handler = &proc_dointvec,
59198 + },
59199 +#endif
59200 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59201 + {
59202 + .procname = "socket_client",
59203 + .data = &grsec_enable_socket_client,
59204 + .maxlen = sizeof(int),
59205 + .mode = 0600,
59206 + .proc_handler = &proc_dointvec,
59207 + },
59208 + {
59209 + .procname = "socket_client_gid",
59210 + .data = &grsec_socket_client_gid,
59211 + .maxlen = sizeof(int),
59212 + .mode = 0600,
59213 + .proc_handler = &proc_dointvec,
59214 + },
59215 +#endif
59216 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59217 + {
59218 + .procname = "socket_server",
59219 + .data = &grsec_enable_socket_server,
59220 + .maxlen = sizeof(int),
59221 + .mode = 0600,
59222 + .proc_handler = &proc_dointvec,
59223 + },
59224 + {
59225 + .procname = "socket_server_gid",
59226 + .data = &grsec_socket_server_gid,
59227 + .maxlen = sizeof(int),
59228 + .mode = 0600,
59229 + .proc_handler = &proc_dointvec,
59230 + },
59231 +#endif
59232 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59233 + {
59234 + .procname = "audit_group",
59235 + .data = &grsec_enable_group,
59236 + .maxlen = sizeof(int),
59237 + .mode = 0600,
59238 + .proc_handler = &proc_dointvec,
59239 + },
59240 + {
59241 + .procname = "audit_gid",
59242 + .data = &grsec_audit_gid,
59243 + .maxlen = sizeof(int),
59244 + .mode = 0600,
59245 + .proc_handler = &proc_dointvec,
59246 + },
59247 +#endif
59248 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59249 + {
59250 + .procname = "audit_chdir",
59251 + .data = &grsec_enable_chdir,
59252 + .maxlen = sizeof(int),
59253 + .mode = 0600,
59254 + .proc_handler = &proc_dointvec,
59255 + },
59256 +#endif
59257 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59258 + {
59259 + .procname = "audit_mount",
59260 + .data = &grsec_enable_mount,
59261 + .maxlen = sizeof(int),
59262 + .mode = 0600,
59263 + .proc_handler = &proc_dointvec,
59264 + },
59265 +#endif
59266 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59267 + {
59268 + .procname = "audit_textrel",
59269 + .data = &grsec_enable_audit_textrel,
59270 + .maxlen = sizeof(int),
59271 + .mode = 0600,
59272 + .proc_handler = &proc_dointvec,
59273 + },
59274 +#endif
59275 +#ifdef CONFIG_GRKERNSEC_DMESG
59276 + {
59277 + .procname = "dmesg",
59278 + .data = &grsec_enable_dmesg,
59279 + .maxlen = sizeof(int),
59280 + .mode = 0600,
59281 + .proc_handler = &proc_dointvec,
59282 + },
59283 +#endif
59284 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59285 + {
59286 + .procname = "chroot_findtask",
59287 + .data = &grsec_enable_chroot_findtask,
59288 + .maxlen = sizeof(int),
59289 + .mode = 0600,
59290 + .proc_handler = &proc_dointvec,
59291 + },
59292 +#endif
59293 +#ifdef CONFIG_GRKERNSEC_RESLOG
59294 + {
59295 + .procname = "resource_logging",
59296 + .data = &grsec_resource_logging,
59297 + .maxlen = sizeof(int),
59298 + .mode = 0600,
59299 + .proc_handler = &proc_dointvec,
59300 + },
59301 +#endif
59302 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59303 + {
59304 + .procname = "audit_ptrace",
59305 + .data = &grsec_enable_audit_ptrace,
59306 + .maxlen = sizeof(int),
59307 + .mode = 0600,
59308 + .proc_handler = &proc_dointvec,
59309 + },
59310 +#endif
59311 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59312 + {
59313 + .procname = "harden_ptrace",
59314 + .data = &grsec_enable_harden_ptrace,
59315 + .maxlen = sizeof(int),
59316 + .mode = 0600,
59317 + .proc_handler = &proc_dointvec,
59318 + },
59319 +#endif
59320 + {
59321 + .procname = "grsec_lock",
59322 + .data = &grsec_lock,
59323 + .maxlen = sizeof(int),
59324 + .mode = 0600,
59325 + .proc_handler = &proc_dointvec,
59326 + },
59327 +#endif
59328 +#ifdef CONFIG_GRKERNSEC_ROFS
59329 + {
59330 + .procname = "romount_protect",
59331 + .data = &grsec_enable_rofs,
59332 + .maxlen = sizeof(int),
59333 + .mode = 0600,
59334 + .proc_handler = &proc_dointvec_minmax,
59335 + .extra1 = &one,
59336 + .extra2 = &one,
59337 + },
59338 +#endif
59339 + { }
59340 +};
59341 +#endif
59342 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59343 new file mode 100644
59344 index 0000000..0dc13c3
59345 --- /dev/null
59346 +++ b/grsecurity/grsec_time.c
59347 @@ -0,0 +1,16 @@
59348 +#include <linux/kernel.h>
59349 +#include <linux/sched.h>
59350 +#include <linux/grinternal.h>
59351 +#include <linux/module.h>
59352 +
59353 +void
59354 +gr_log_timechange(void)
59355 +{
59356 +#ifdef CONFIG_GRKERNSEC_TIME
59357 + if (grsec_enable_time)
59358 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59359 +#endif
59360 + return;
59361 +}
59362 +
59363 +EXPORT_SYMBOL(gr_log_timechange);
59364 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59365 new file mode 100644
59366 index 0000000..07e0dc0
59367 --- /dev/null
59368 +++ b/grsecurity/grsec_tpe.c
59369 @@ -0,0 +1,73 @@
59370 +#include <linux/kernel.h>
59371 +#include <linux/sched.h>
59372 +#include <linux/file.h>
59373 +#include <linux/fs.h>
59374 +#include <linux/grinternal.h>
59375 +
59376 +extern int gr_acl_tpe_check(void);
59377 +
59378 +int
59379 +gr_tpe_allow(const struct file *file)
59380 +{
59381 +#ifdef CONFIG_GRKERNSEC
59382 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59383 + const struct cred *cred = current_cred();
59384 + char *msg = NULL;
59385 + char *msg2 = NULL;
59386 +
59387 + // never restrict root
59388 + if (!cred->uid)
59389 + return 1;
59390 +
59391 + if (grsec_enable_tpe) {
59392 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59393 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59394 + msg = "not being in trusted group";
59395 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59396 + msg = "being in untrusted group";
59397 +#else
59398 + if (in_group_p(grsec_tpe_gid))
59399 + msg = "being in untrusted group";
59400 +#endif
59401 + }
59402 + if (!msg && gr_acl_tpe_check())
59403 + msg = "being in untrusted role";
59404 +
59405 + // not in any affected group/role
59406 + if (!msg)
59407 + goto next_check;
59408 +
59409 + if (inode->i_uid)
59410 + msg2 = "file in non-root-owned directory";
59411 + else if (inode->i_mode & S_IWOTH)
59412 + msg2 = "file in world-writable directory";
59413 + else if (inode->i_mode & S_IWGRP)
59414 + msg2 = "file in group-writable directory";
59415 +
59416 + if (msg && msg2) {
59417 + char fullmsg[70] = {0};
59418 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59419 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59420 + return 0;
59421 + }
59422 + msg = NULL;
59423 +next_check:
59424 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59425 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59426 + return 1;
59427 +
59428 + if (inode->i_uid && (inode->i_uid != cred->uid))
59429 + msg = "directory not owned by user";
59430 + else if (inode->i_mode & S_IWOTH)
59431 + msg = "file in world-writable directory";
59432 + else if (inode->i_mode & S_IWGRP)
59433 + msg = "file in group-writable directory";
59434 +
59435 + if (msg) {
59436 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59437 + return 0;
59438 + }
59439 +#endif
59440 +#endif
59441 + return 1;
59442 +}
59443 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59444 new file mode 100644
59445 index 0000000..9f7b1ac
59446 --- /dev/null
59447 +++ b/grsecurity/grsum.c
59448 @@ -0,0 +1,61 @@
59449 +#include <linux/err.h>
59450 +#include <linux/kernel.h>
59451 +#include <linux/sched.h>
59452 +#include <linux/mm.h>
59453 +#include <linux/scatterlist.h>
59454 +#include <linux/crypto.h>
59455 +#include <linux/gracl.h>
59456 +
59457 +
59458 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59459 +#error "crypto and sha256 must be built into the kernel"
59460 +#endif
59461 +
59462 +int
59463 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59464 +{
59465 + char *p;
59466 + struct crypto_hash *tfm;
59467 + struct hash_desc desc;
59468 + struct scatterlist sg;
59469 + unsigned char temp_sum[GR_SHA_LEN];
59470 + volatile int retval = 0;
59471 + volatile int dummy = 0;
59472 + unsigned int i;
59473 +
59474 + sg_init_table(&sg, 1);
59475 +
59476 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59477 + if (IS_ERR(tfm)) {
59478 + /* should never happen, since sha256 should be built in */
59479 + return 1;
59480 + }
59481 +
59482 + desc.tfm = tfm;
59483 + desc.flags = 0;
59484 +
59485 + crypto_hash_init(&desc);
59486 +
59487 + p = salt;
59488 + sg_set_buf(&sg, p, GR_SALT_LEN);
59489 + crypto_hash_update(&desc, &sg, sg.length);
59490 +
59491 + p = entry->pw;
59492 + sg_set_buf(&sg, p, strlen(p));
59493 +
59494 + crypto_hash_update(&desc, &sg, sg.length);
59495 +
59496 + crypto_hash_final(&desc, temp_sum);
59497 +
59498 + memset(entry->pw, 0, GR_PW_LEN);
59499 +
59500 + for (i = 0; i < GR_SHA_LEN; i++)
59501 + if (sum[i] != temp_sum[i])
59502 + retval = 1;
59503 + else
59504 + dummy = 1; // waste a cycle
59505 +
59506 + crypto_free_hash(tfm);
59507 +
59508 + return retval;
59509 +}
59510 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59511 index 6cd5b64..f620d2d 100644
59512 --- a/include/acpi/acpi_bus.h
59513 +++ b/include/acpi/acpi_bus.h
59514 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59515 acpi_op_bind bind;
59516 acpi_op_unbind unbind;
59517 acpi_op_notify notify;
59518 -};
59519 +} __no_const;
59520
59521 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59522
59523 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59524 index b7babf0..71e4e74 100644
59525 --- a/include/asm-generic/atomic-long.h
59526 +++ b/include/asm-generic/atomic-long.h
59527 @@ -22,6 +22,12 @@
59528
59529 typedef atomic64_t atomic_long_t;
59530
59531 +#ifdef CONFIG_PAX_REFCOUNT
59532 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59533 +#else
59534 +typedef atomic64_t atomic_long_unchecked_t;
59535 +#endif
59536 +
59537 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59538
59539 static inline long atomic_long_read(atomic_long_t *l)
59540 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59541 return (long)atomic64_read(v);
59542 }
59543
59544 +#ifdef CONFIG_PAX_REFCOUNT
59545 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59546 +{
59547 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59548 +
59549 + return (long)atomic64_read_unchecked(v);
59550 +}
59551 +#endif
59552 +
59553 static inline void atomic_long_set(atomic_long_t *l, long i)
59554 {
59555 atomic64_t *v = (atomic64_t *)l;
59556 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59557 atomic64_set(v, i);
59558 }
59559
59560 +#ifdef CONFIG_PAX_REFCOUNT
59561 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59562 +{
59563 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59564 +
59565 + atomic64_set_unchecked(v, i);
59566 +}
59567 +#endif
59568 +
59569 static inline void atomic_long_inc(atomic_long_t *l)
59570 {
59571 atomic64_t *v = (atomic64_t *)l;
59572 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59573 atomic64_inc(v);
59574 }
59575
59576 +#ifdef CONFIG_PAX_REFCOUNT
59577 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59578 +{
59579 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59580 +
59581 + atomic64_inc_unchecked(v);
59582 +}
59583 +#endif
59584 +
59585 static inline void atomic_long_dec(atomic_long_t *l)
59586 {
59587 atomic64_t *v = (atomic64_t *)l;
59588 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59589 atomic64_dec(v);
59590 }
59591
59592 +#ifdef CONFIG_PAX_REFCOUNT
59593 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59594 +{
59595 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59596 +
59597 + atomic64_dec_unchecked(v);
59598 +}
59599 +#endif
59600 +
59601 static inline void atomic_long_add(long i, atomic_long_t *l)
59602 {
59603 atomic64_t *v = (atomic64_t *)l;
59604 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59605 atomic64_add(i, v);
59606 }
59607
59608 +#ifdef CONFIG_PAX_REFCOUNT
59609 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59610 +{
59611 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59612 +
59613 + atomic64_add_unchecked(i, v);
59614 +}
59615 +#endif
59616 +
59617 static inline void atomic_long_sub(long i, atomic_long_t *l)
59618 {
59619 atomic64_t *v = (atomic64_t *)l;
59620 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59621 atomic64_sub(i, v);
59622 }
59623
59624 +#ifdef CONFIG_PAX_REFCOUNT
59625 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59626 +{
59627 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59628 +
59629 + atomic64_sub_unchecked(i, v);
59630 +}
59631 +#endif
59632 +
59633 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59634 {
59635 atomic64_t *v = (atomic64_t *)l;
59636 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59637 return (long)atomic64_inc_return(v);
59638 }
59639
59640 +#ifdef CONFIG_PAX_REFCOUNT
59641 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59642 +{
59643 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59644 +
59645 + return (long)atomic64_inc_return_unchecked(v);
59646 +}
59647 +#endif
59648 +
59649 static inline long atomic_long_dec_return(atomic_long_t *l)
59650 {
59651 atomic64_t *v = (atomic64_t *)l;
59652 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59653
59654 typedef atomic_t atomic_long_t;
59655
59656 +#ifdef CONFIG_PAX_REFCOUNT
59657 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59658 +#else
59659 +typedef atomic_t atomic_long_unchecked_t;
59660 +#endif
59661 +
59662 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59663 static inline long atomic_long_read(atomic_long_t *l)
59664 {
59665 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59666 return (long)atomic_read(v);
59667 }
59668
59669 +#ifdef CONFIG_PAX_REFCOUNT
59670 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59671 +{
59672 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59673 +
59674 + return (long)atomic_read_unchecked(v);
59675 +}
59676 +#endif
59677 +
59678 static inline void atomic_long_set(atomic_long_t *l, long i)
59679 {
59680 atomic_t *v = (atomic_t *)l;
59681 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59682 atomic_set(v, i);
59683 }
59684
59685 +#ifdef CONFIG_PAX_REFCOUNT
59686 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59687 +{
59688 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59689 +
59690 + atomic_set_unchecked(v, i);
59691 +}
59692 +#endif
59693 +
59694 static inline void atomic_long_inc(atomic_long_t *l)
59695 {
59696 atomic_t *v = (atomic_t *)l;
59697 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59698 atomic_inc(v);
59699 }
59700
59701 +#ifdef CONFIG_PAX_REFCOUNT
59702 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59703 +{
59704 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59705 +
59706 + atomic_inc_unchecked(v);
59707 +}
59708 +#endif
59709 +
59710 static inline void atomic_long_dec(atomic_long_t *l)
59711 {
59712 atomic_t *v = (atomic_t *)l;
59713 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59714 atomic_dec(v);
59715 }
59716
59717 +#ifdef CONFIG_PAX_REFCOUNT
59718 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59719 +{
59720 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59721 +
59722 + atomic_dec_unchecked(v);
59723 +}
59724 +#endif
59725 +
59726 static inline void atomic_long_add(long i, atomic_long_t *l)
59727 {
59728 atomic_t *v = (atomic_t *)l;
59729 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59730 atomic_add(i, v);
59731 }
59732
59733 +#ifdef CONFIG_PAX_REFCOUNT
59734 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59735 +{
59736 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59737 +
59738 + atomic_add_unchecked(i, v);
59739 +}
59740 +#endif
59741 +
59742 static inline void atomic_long_sub(long i, atomic_long_t *l)
59743 {
59744 atomic_t *v = (atomic_t *)l;
59745 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59746 atomic_sub(i, v);
59747 }
59748
59749 +#ifdef CONFIG_PAX_REFCOUNT
59750 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59751 +{
59752 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59753 +
59754 + atomic_sub_unchecked(i, v);
59755 +}
59756 +#endif
59757 +
59758 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59759 {
59760 atomic_t *v = (atomic_t *)l;
59761 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59762 return (long)atomic_inc_return(v);
59763 }
59764
59765 +#ifdef CONFIG_PAX_REFCOUNT
59766 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59767 +{
59768 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59769 +
59770 + return (long)atomic_inc_return_unchecked(v);
59771 +}
59772 +#endif
59773 +
59774 static inline long atomic_long_dec_return(atomic_long_t *l)
59775 {
59776 atomic_t *v = (atomic_t *)l;
59777 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59778
59779 #endif /* BITS_PER_LONG == 64 */
59780
59781 +#ifdef CONFIG_PAX_REFCOUNT
59782 +static inline void pax_refcount_needs_these_functions(void)
59783 +{
59784 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59785 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59786 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59787 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59788 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59789 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59790 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59791 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59792 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59793 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59794 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59795 +
59796 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59797 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59798 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59799 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59800 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59801 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59802 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59803 +}
59804 +#else
59805 +#define atomic_read_unchecked(v) atomic_read(v)
59806 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59807 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59808 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59809 +#define atomic_inc_unchecked(v) atomic_inc(v)
59810 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59811 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59812 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59813 +#define atomic_dec_unchecked(v) atomic_dec(v)
59814 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59815 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59816 +
59817 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59818 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59819 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59820 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59821 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59822 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59823 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59824 +#endif
59825 +
59826 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59827 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59828 index b18ce4f..2ee2843 100644
59829 --- a/include/asm-generic/atomic64.h
59830 +++ b/include/asm-generic/atomic64.h
59831 @@ -16,6 +16,8 @@ typedef struct {
59832 long long counter;
59833 } atomic64_t;
59834
59835 +typedef atomic64_t atomic64_unchecked_t;
59836 +
59837 #define ATOMIC64_INIT(i) { (i) }
59838
59839 extern long long atomic64_read(const atomic64_t *v);
59840 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59841 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59842 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59843
59844 +#define atomic64_read_unchecked(v) atomic64_read(v)
59845 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59846 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59847 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59848 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59849 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59850 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59851 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59852 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59853 +
59854 #endif /* _ASM_GENERIC_ATOMIC64_H */
59855 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59856 index 1bfcfe5..e04c5c9 100644
59857 --- a/include/asm-generic/cache.h
59858 +++ b/include/asm-generic/cache.h
59859 @@ -6,7 +6,7 @@
59860 * cache lines need to provide their own cache.h.
59861 */
59862
59863 -#define L1_CACHE_SHIFT 5
59864 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59865 +#define L1_CACHE_SHIFT 5UL
59866 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59867
59868 #endif /* __ASM_GENERIC_CACHE_H */
59869 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59870 index 0d68a1e..b74a761 100644
59871 --- a/include/asm-generic/emergency-restart.h
59872 +++ b/include/asm-generic/emergency-restart.h
59873 @@ -1,7 +1,7 @@
59874 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59875 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59876
59877 -static inline void machine_emergency_restart(void)
59878 +static inline __noreturn void machine_emergency_restart(void)
59879 {
59880 machine_restart(NULL);
59881 }
59882 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59883 index 0232ccb..13d9165 100644
59884 --- a/include/asm-generic/kmap_types.h
59885 +++ b/include/asm-generic/kmap_types.h
59886 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59887 KMAP_D(17) KM_NMI,
59888 KMAP_D(18) KM_NMI_PTE,
59889 KMAP_D(19) KM_KDB,
59890 +KMAP_D(20) KM_CLEARPAGE,
59891 /*
59892 * Remember to update debug_kmap_atomic() when adding new kmap types!
59893 */
59894 -KMAP_D(20) KM_TYPE_NR
59895 +KMAP_D(21) KM_TYPE_NR
59896 };
59897
59898 #undef KMAP_D
59899 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59900 index 9ceb03b..2efbcbd 100644
59901 --- a/include/asm-generic/local.h
59902 +++ b/include/asm-generic/local.h
59903 @@ -39,6 +39,7 @@ typedef struct
59904 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59905 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59906 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59907 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59908
59909 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59910 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59911 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59912 index 725612b..9cc513a 100644
59913 --- a/include/asm-generic/pgtable-nopmd.h
59914 +++ b/include/asm-generic/pgtable-nopmd.h
59915 @@ -1,14 +1,19 @@
59916 #ifndef _PGTABLE_NOPMD_H
59917 #define _PGTABLE_NOPMD_H
59918
59919 -#ifndef __ASSEMBLY__
59920 -
59921 #include <asm-generic/pgtable-nopud.h>
59922
59923 -struct mm_struct;
59924 -
59925 #define __PAGETABLE_PMD_FOLDED
59926
59927 +#define PMD_SHIFT PUD_SHIFT
59928 +#define PTRS_PER_PMD 1
59929 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59930 +#define PMD_MASK (~(PMD_SIZE-1))
59931 +
59932 +#ifndef __ASSEMBLY__
59933 +
59934 +struct mm_struct;
59935 +
59936 /*
59937 * Having the pmd type consist of a pud gets the size right, and allows
59938 * us to conceptually access the pud entry that this pmd is folded into
59939 @@ -16,11 +21,6 @@ struct mm_struct;
59940 */
59941 typedef struct { pud_t pud; } pmd_t;
59942
59943 -#define PMD_SHIFT PUD_SHIFT
59944 -#define PTRS_PER_PMD 1
59945 -#define PMD_SIZE (1UL << PMD_SHIFT)
59946 -#define PMD_MASK (~(PMD_SIZE-1))
59947 -
59948 /*
59949 * The "pud_xxx()" functions here are trivial for a folded two-level
59950 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59951 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59952 index 810431d..ccc3638 100644
59953 --- a/include/asm-generic/pgtable-nopud.h
59954 +++ b/include/asm-generic/pgtable-nopud.h
59955 @@ -1,10 +1,15 @@
59956 #ifndef _PGTABLE_NOPUD_H
59957 #define _PGTABLE_NOPUD_H
59958
59959 -#ifndef __ASSEMBLY__
59960 -
59961 #define __PAGETABLE_PUD_FOLDED
59962
59963 +#define PUD_SHIFT PGDIR_SHIFT
59964 +#define PTRS_PER_PUD 1
59965 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59966 +#define PUD_MASK (~(PUD_SIZE-1))
59967 +
59968 +#ifndef __ASSEMBLY__
59969 +
59970 /*
59971 * Having the pud type consist of a pgd gets the size right, and allows
59972 * us to conceptually access the pgd entry that this pud is folded into
59973 @@ -12,11 +17,6 @@
59974 */
59975 typedef struct { pgd_t pgd; } pud_t;
59976
59977 -#define PUD_SHIFT PGDIR_SHIFT
59978 -#define PTRS_PER_PUD 1
59979 -#define PUD_SIZE (1UL << PUD_SHIFT)
59980 -#define PUD_MASK (~(PUD_SIZE-1))
59981 -
59982 /*
59983 * The "pgd_xxx()" functions here are trivial for a folded two-level
59984 * setup: the pud is never bad, and a pud always exists (as it's folded
59985 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59986 index a03c098..7e5b223 100644
59987 --- a/include/asm-generic/pgtable.h
59988 +++ b/include/asm-generic/pgtable.h
59989 @@ -502,6 +502,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59990 #endif
59991 }
59992
59993 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59994 +static inline unsigned long pax_open_kernel(void) { return 0; }
59995 +#endif
59996 +
59997 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59998 +static inline unsigned long pax_close_kernel(void) { return 0; }
59999 +#endif
60000 +
60001 #endif /* CONFIG_MMU */
60002
60003 #endif /* !__ASSEMBLY__ */
60004 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
60005 index 9788568..510dece 100644
60006 --- a/include/asm-generic/uaccess.h
60007 +++ b/include/asm-generic/uaccess.h
60008 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
60009 */
60010 #ifndef __copy_from_user
60011 static inline __must_check long __copy_from_user(void *to,
60012 + const void __user * from, unsigned long n) __size_overflow(3);
60013 +static inline __must_check long __copy_from_user(void *to,
60014 const void __user * from, unsigned long n)
60015 {
60016 if (__builtin_constant_p(n)) {
60017 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
60018
60019 #ifndef __copy_to_user
60020 static inline __must_check long __copy_to_user(void __user *to,
60021 + const void *from, unsigned long n) __size_overflow(3);
60022 +static inline __must_check long __copy_to_user(void __user *to,
60023 const void *from, unsigned long n)
60024 {
60025 if (__builtin_constant_p(n)) {
60026 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60027 -EFAULT; \
60028 })
60029
60030 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60031 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60032 {
60033 size = __copy_from_user(x, ptr, size);
60034 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60035 #define __copy_to_user_inatomic __copy_to_user
60036 #endif
60037
60038 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60039 static inline long copy_from_user(void *to,
60040 const void __user * from, unsigned long n)
60041 {
60042 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60043 return n;
60044 }
60045
60046 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60047 static inline long copy_to_user(void __user *to,
60048 const void *from, unsigned long n)
60049 {
60050 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
60051 */
60052 #ifndef __clear_user
60053 static inline __must_check unsigned long
60054 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60055 +static inline __must_check unsigned long
60056 __clear_user(void __user *to, unsigned long n)
60057 {
60058 memset((void __force *)to, 0, n);
60059 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
60060 #endif
60061
60062 static inline __must_check unsigned long
60063 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60064 +static inline __must_check unsigned long
60065 clear_user(void __user *to, unsigned long n)
60066 {
60067 might_sleep();
60068 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60069 index b5e2e4c..6a5373e 100644
60070 --- a/include/asm-generic/vmlinux.lds.h
60071 +++ b/include/asm-generic/vmlinux.lds.h
60072 @@ -217,6 +217,7 @@
60073 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60074 VMLINUX_SYMBOL(__start_rodata) = .; \
60075 *(.rodata) *(.rodata.*) \
60076 + *(.data..read_only) \
60077 *(__vermagic) /* Kernel version magic */ \
60078 . = ALIGN(8); \
60079 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60080 @@ -722,17 +723,18 @@
60081 * section in the linker script will go there too. @phdr should have
60082 * a leading colon.
60083 *
60084 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60085 + * Note that this macros defines per_cpu_load as an absolute symbol.
60086 * If there is no need to put the percpu section at a predetermined
60087 * address, use PERCPU_SECTION.
60088 */
60089 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60090 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60091 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60092 + per_cpu_load = .; \
60093 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60094 - LOAD_OFFSET) { \
60095 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60096 PERCPU_INPUT(cacheline) \
60097 } phdr \
60098 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60099 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60100
60101 /**
60102 * PERCPU_SECTION - define output section for percpu area, simple version
60103 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60104 index 92f0981..d44a37c 100644
60105 --- a/include/drm/drmP.h
60106 +++ b/include/drm/drmP.h
60107 @@ -72,6 +72,7 @@
60108 #include <linux/workqueue.h>
60109 #include <linux/poll.h>
60110 #include <asm/pgalloc.h>
60111 +#include <asm/local.h>
60112 #include "drm.h"
60113
60114 #include <linux/idr.h>
60115 @@ -1038,7 +1039,7 @@ struct drm_device {
60116
60117 /** \name Usage Counters */
60118 /*@{ */
60119 - int open_count; /**< Outstanding files open */
60120 + local_t open_count; /**< Outstanding files open */
60121 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60122 atomic_t vma_count; /**< Outstanding vma areas open */
60123 int buf_use; /**< Buffers in use -- cannot alloc */
60124 @@ -1049,7 +1050,7 @@ struct drm_device {
60125 /*@{ */
60126 unsigned long counters;
60127 enum drm_stat_type types[15];
60128 - atomic_t counts[15];
60129 + atomic_unchecked_t counts[15];
60130 /*@} */
60131
60132 struct list_head filelist;
60133 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60134 index 37515d1..34fa8b0 100644
60135 --- a/include/drm/drm_crtc_helper.h
60136 +++ b/include/drm/drm_crtc_helper.h
60137 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60138
60139 /* disable crtc when not in use - more explicit than dpms off */
60140 void (*disable)(struct drm_crtc *crtc);
60141 -};
60142 +} __no_const;
60143
60144 struct drm_encoder_helper_funcs {
60145 void (*dpms)(struct drm_encoder *encoder, int mode);
60146 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60147 struct drm_connector *connector);
60148 /* disable encoder when not in use - more explicit than dpms off */
60149 void (*disable)(struct drm_encoder *encoder);
60150 -};
60151 +} __no_const;
60152
60153 struct drm_connector_helper_funcs {
60154 int (*get_modes)(struct drm_connector *connector);
60155 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60156 index 26c1f78..6722682 100644
60157 --- a/include/drm/ttm/ttm_memory.h
60158 +++ b/include/drm/ttm/ttm_memory.h
60159 @@ -47,7 +47,7 @@
60160
60161 struct ttm_mem_shrink {
60162 int (*do_shrink) (struct ttm_mem_shrink *);
60163 -};
60164 +} __no_const;
60165
60166 /**
60167 * struct ttm_mem_global - Global memory accounting structure.
60168 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60169 index e86dfca..40cc55f 100644
60170 --- a/include/linux/a.out.h
60171 +++ b/include/linux/a.out.h
60172 @@ -39,6 +39,14 @@ enum machine_type {
60173 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60174 };
60175
60176 +/* Constants for the N_FLAGS field */
60177 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60178 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60179 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60180 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60181 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60182 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60183 +
60184 #if !defined (N_MAGIC)
60185 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60186 #endif
60187 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60188 index f4ff882..84b53a6 100644
60189 --- a/include/linux/atmdev.h
60190 +++ b/include/linux/atmdev.h
60191 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60192 #endif
60193
60194 struct k_atm_aal_stats {
60195 -#define __HANDLE_ITEM(i) atomic_t i
60196 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60197 __AAL_STAT_ITEMS
60198 #undef __HANDLE_ITEM
60199 };
60200 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60201 index 0092102..8a801b4 100644
60202 --- a/include/linux/binfmts.h
60203 +++ b/include/linux/binfmts.h
60204 @@ -89,6 +89,7 @@ struct linux_binfmt {
60205 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60206 int (*load_shlib)(struct file *);
60207 int (*core_dump)(struct coredump_params *cprm);
60208 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60209 unsigned long min_coredump; /* minimal dump size */
60210 };
60211
60212 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60213 index 606cf33..b72c577 100644
60214 --- a/include/linux/blkdev.h
60215 +++ b/include/linux/blkdev.h
60216 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60217 /* this callback is with swap_lock and sometimes page table lock held */
60218 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60219 struct module *owner;
60220 -};
60221 +} __do_const;
60222
60223 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60224 unsigned long);
60225 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60226 index 4d1a074..88f929a 100644
60227 --- a/include/linux/blktrace_api.h
60228 +++ b/include/linux/blktrace_api.h
60229 @@ -162,7 +162,7 @@ struct blk_trace {
60230 struct dentry *dir;
60231 struct dentry *dropped_file;
60232 struct dentry *msg_file;
60233 - atomic_t dropped;
60234 + atomic_unchecked_t dropped;
60235 };
60236
60237 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60238 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60239 index 83195fb..0b0f77d 100644
60240 --- a/include/linux/byteorder/little_endian.h
60241 +++ b/include/linux/byteorder/little_endian.h
60242 @@ -42,51 +42,51 @@
60243
60244 static inline __le64 __cpu_to_le64p(const __u64 *p)
60245 {
60246 - return (__force __le64)*p;
60247 + return (__force const __le64)*p;
60248 }
60249 static inline __u64 __le64_to_cpup(const __le64 *p)
60250 {
60251 - return (__force __u64)*p;
60252 + return (__force const __u64)*p;
60253 }
60254 static inline __le32 __cpu_to_le32p(const __u32 *p)
60255 {
60256 - return (__force __le32)*p;
60257 + return (__force const __le32)*p;
60258 }
60259 static inline __u32 __le32_to_cpup(const __le32 *p)
60260 {
60261 - return (__force __u32)*p;
60262 + return (__force const __u32)*p;
60263 }
60264 static inline __le16 __cpu_to_le16p(const __u16 *p)
60265 {
60266 - return (__force __le16)*p;
60267 + return (__force const __le16)*p;
60268 }
60269 static inline __u16 __le16_to_cpup(const __le16 *p)
60270 {
60271 - return (__force __u16)*p;
60272 + return (__force const __u16)*p;
60273 }
60274 static inline __be64 __cpu_to_be64p(const __u64 *p)
60275 {
60276 - return (__force __be64)__swab64p(p);
60277 + return (__force const __be64)__swab64p(p);
60278 }
60279 static inline __u64 __be64_to_cpup(const __be64 *p)
60280 {
60281 - return __swab64p((__u64 *)p);
60282 + return __swab64p((const __u64 *)p);
60283 }
60284 static inline __be32 __cpu_to_be32p(const __u32 *p)
60285 {
60286 - return (__force __be32)__swab32p(p);
60287 + return (__force const __be32)__swab32p(p);
60288 }
60289 static inline __u32 __be32_to_cpup(const __be32 *p)
60290 {
60291 - return __swab32p((__u32 *)p);
60292 + return __swab32p((const __u32 *)p);
60293 }
60294 static inline __be16 __cpu_to_be16p(const __u16 *p)
60295 {
60296 - return (__force __be16)__swab16p(p);
60297 + return (__force const __be16)__swab16p(p);
60298 }
60299 static inline __u16 __be16_to_cpup(const __be16 *p)
60300 {
60301 - return __swab16p((__u16 *)p);
60302 + return __swab16p((const __u16 *)p);
60303 }
60304 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60305 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60306 diff --git a/include/linux/cache.h b/include/linux/cache.h
60307 index 4c57065..4307975 100644
60308 --- a/include/linux/cache.h
60309 +++ b/include/linux/cache.h
60310 @@ -16,6 +16,10 @@
60311 #define __read_mostly
60312 #endif
60313
60314 +#ifndef __read_only
60315 +#define __read_only __read_mostly
60316 +#endif
60317 +
60318 #ifndef ____cacheline_aligned
60319 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60320 #endif
60321 diff --git a/include/linux/capability.h b/include/linux/capability.h
60322 index 12d52de..b5f7fa7 100644
60323 --- a/include/linux/capability.h
60324 +++ b/include/linux/capability.h
60325 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60326 extern bool capable(int cap);
60327 extern bool ns_capable(struct user_namespace *ns, int cap);
60328 extern bool nsown_capable(int cap);
60329 +extern bool capable_nolog(int cap);
60330 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60331
60332 /* audit system wants to get cap info from files as well */
60333 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60334 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60335 index 04ffb2e..6799180 100644
60336 --- a/include/linux/cleancache.h
60337 +++ b/include/linux/cleancache.h
60338 @@ -31,7 +31,7 @@ struct cleancache_ops {
60339 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60340 void (*flush_inode)(int, struct cleancache_filekey);
60341 void (*flush_fs)(int);
60342 -};
60343 +} __no_const;
60344
60345 extern struct cleancache_ops
60346 cleancache_register_ops(struct cleancache_ops *ops);
60347 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60348 index 2f40791..567b215 100644
60349 --- a/include/linux/compiler-gcc4.h
60350 +++ b/include/linux/compiler-gcc4.h
60351 @@ -32,6 +32,15 @@
60352 #define __linktime_error(message) __attribute__((__error__(message)))
60353
60354 #if __GNUC_MINOR__ >= 5
60355 +
60356 +#ifdef CONSTIFY_PLUGIN
60357 +#define __no_const __attribute__((no_const))
60358 +#define __do_const __attribute__((do_const))
60359 +#endif
60360 +
60361 +#ifdef SIZE_OVERFLOW_PLUGIN
60362 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60363 +#endif
60364 /*
60365 * Mark a position in code as unreachable. This can be used to
60366 * suppress control flow warnings after asm blocks that transfer
60367 @@ -47,6 +56,11 @@
60368 #define __noclone __attribute__((__noclone__))
60369
60370 #endif
60371 +
60372 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60373 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60374 +#define __bos0(ptr) __bos((ptr), 0)
60375 +#define __bos1(ptr) __bos((ptr), 1)
60376 #endif
60377
60378 #if __GNUC_MINOR__ > 0
60379 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60380 index 4a24354..ecaff7a 100644
60381 --- a/include/linux/compiler.h
60382 +++ b/include/linux/compiler.h
60383 @@ -5,31 +5,62 @@
60384
60385 #ifdef __CHECKER__
60386 # define __user __attribute__((noderef, address_space(1)))
60387 +# define __force_user __force __user
60388 # define __kernel __attribute__((address_space(0)))
60389 +# define __force_kernel __force __kernel
60390 # define __safe __attribute__((safe))
60391 # define __force __attribute__((force))
60392 # define __nocast __attribute__((nocast))
60393 # define __iomem __attribute__((noderef, address_space(2)))
60394 +# define __force_iomem __force __iomem
60395 # define __acquires(x) __attribute__((context(x,0,1)))
60396 # define __releases(x) __attribute__((context(x,1,0)))
60397 # define __acquire(x) __context__(x,1)
60398 # define __release(x) __context__(x,-1)
60399 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60400 # define __percpu __attribute__((noderef, address_space(3)))
60401 +# define __force_percpu __force __percpu
60402 #ifdef CONFIG_SPARSE_RCU_POINTER
60403 # define __rcu __attribute__((noderef, address_space(4)))
60404 +# define __force_rcu __force __rcu
60405 #else
60406 # define __rcu
60407 +# define __force_rcu
60408 #endif
60409 extern void __chk_user_ptr(const volatile void __user *);
60410 extern void __chk_io_ptr(const volatile void __iomem *);
60411 +#elif defined(CHECKER_PLUGIN)
60412 +//# define __user
60413 +//# define __force_user
60414 +//# define __kernel
60415 +//# define __force_kernel
60416 +# define __safe
60417 +# define __force
60418 +# define __nocast
60419 +# define __iomem
60420 +# define __force_iomem
60421 +# define __chk_user_ptr(x) (void)0
60422 +# define __chk_io_ptr(x) (void)0
60423 +# define __builtin_warning(x, y...) (1)
60424 +# define __acquires(x)
60425 +# define __releases(x)
60426 +# define __acquire(x) (void)0
60427 +# define __release(x) (void)0
60428 +# define __cond_lock(x,c) (c)
60429 +# define __percpu
60430 +# define __force_percpu
60431 +# define __rcu
60432 +# define __force_rcu
60433 #else
60434 # define __user
60435 +# define __force_user
60436 # define __kernel
60437 +# define __force_kernel
60438 # define __safe
60439 # define __force
60440 # define __nocast
60441 # define __iomem
60442 +# define __force_iomem
60443 # define __chk_user_ptr(x) (void)0
60444 # define __chk_io_ptr(x) (void)0
60445 # define __builtin_warning(x, y...) (1)
60446 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60447 # define __release(x) (void)0
60448 # define __cond_lock(x,c) (c)
60449 # define __percpu
60450 +# define __force_percpu
60451 # define __rcu
60452 +# define __force_rcu
60453 #endif
60454
60455 #ifdef __KERNEL__
60456 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60457 # define __attribute_const__ /* unimplemented */
60458 #endif
60459
60460 +#ifndef __no_const
60461 +# define __no_const
60462 +#endif
60463 +
60464 +#ifndef __do_const
60465 +# define __do_const
60466 +#endif
60467 +
60468 +#ifndef __size_overflow
60469 +# define __size_overflow(...)
60470 +#endif
60471 /*
60472 * Tell gcc if a function is cold. The compiler will assume any path
60473 * directly leading to the call is unlikely.
60474 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60475 #define __cold
60476 #endif
60477
60478 +#ifndef __alloc_size
60479 +#define __alloc_size(...)
60480 +#endif
60481 +
60482 +#ifndef __bos
60483 +#define __bos(ptr, arg)
60484 +#endif
60485 +
60486 +#ifndef __bos0
60487 +#define __bos0(ptr)
60488 +#endif
60489 +
60490 +#ifndef __bos1
60491 +#define __bos1(ptr)
60492 +#endif
60493 +
60494 /* Simple shorthand for a section definition */
60495 #ifndef __section
60496 # define __section(S) __attribute__ ((__section__(#S)))
60497 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60498 * use is to mediate communication between process-level code and irq/NMI
60499 * handlers, all running on the same CPU.
60500 */
60501 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60502 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60503 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60504
60505 #endif /* __LINUX_COMPILER_H */
60506 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60507 index e9eaec5..bfeb9bb 100644
60508 --- a/include/linux/cpuset.h
60509 +++ b/include/linux/cpuset.h
60510 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60511 * nodemask.
60512 */
60513 smp_mb();
60514 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60515 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60516 }
60517
60518 static inline void set_mems_allowed(nodemask_t nodemask)
60519 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60520 index b936763..48685ee 100644
60521 --- a/include/linux/crash_dump.h
60522 +++ b/include/linux/crash_dump.h
60523 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60524 extern unsigned long long elfcorehdr_size;
60525
60526 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60527 - unsigned long, int);
60528 + unsigned long, int) __size_overflow(3);
60529
60530 /* Architecture code defines this if there are other possible ELF
60531 * machine types, e.g. on bi-arch capable hardware. */
60532 diff --git a/include/linux/cred.h b/include/linux/cred.h
60533 index adadf71..6af5560 100644
60534 --- a/include/linux/cred.h
60535 +++ b/include/linux/cred.h
60536 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60537 static inline void validate_process_creds(void)
60538 {
60539 }
60540 +static inline void validate_task_creds(struct task_struct *task)
60541 +{
60542 +}
60543 #endif
60544
60545 /**
60546 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60547 index 8a94217..15d49e3 100644
60548 --- a/include/linux/crypto.h
60549 +++ b/include/linux/crypto.h
60550 @@ -365,7 +365,7 @@ struct cipher_tfm {
60551 const u8 *key, unsigned int keylen);
60552 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60553 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60554 -};
60555 +} __no_const;
60556
60557 struct hash_tfm {
60558 int (*init)(struct hash_desc *desc);
60559 @@ -386,13 +386,13 @@ struct compress_tfm {
60560 int (*cot_decompress)(struct crypto_tfm *tfm,
60561 const u8 *src, unsigned int slen,
60562 u8 *dst, unsigned int *dlen);
60563 -};
60564 +} __no_const;
60565
60566 struct rng_tfm {
60567 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60568 unsigned int dlen);
60569 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60570 -};
60571 +} __no_const;
60572
60573 #define crt_ablkcipher crt_u.ablkcipher
60574 #define crt_aead crt_u.aead
60575 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60576 index 7925bf0..d5143d2 100644
60577 --- a/include/linux/decompress/mm.h
60578 +++ b/include/linux/decompress/mm.h
60579 @@ -77,7 +77,7 @@ static void free(void *where)
60580 * warnings when not needed (indeed large_malloc / large_free are not
60581 * needed by inflate */
60582
60583 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60584 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60585 #define free(a) kfree(a)
60586
60587 #define large_malloc(a) vmalloc(a)
60588 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60589 index e13117c..e9fc938 100644
60590 --- a/include/linux/dma-mapping.h
60591 +++ b/include/linux/dma-mapping.h
60592 @@ -46,7 +46,7 @@ struct dma_map_ops {
60593 u64 (*get_required_mask)(struct device *dev);
60594 #endif
60595 int is_phys;
60596 -};
60597 +} __do_const;
60598
60599 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60600
60601 diff --git a/include/linux/efi.h b/include/linux/efi.h
60602 index 37c3007..92ab679 100644
60603 --- a/include/linux/efi.h
60604 +++ b/include/linux/efi.h
60605 @@ -580,7 +580,7 @@ struct efivar_operations {
60606 efi_get_variable_t *get_variable;
60607 efi_get_next_variable_t *get_next_variable;
60608 efi_set_variable_t *set_variable;
60609 -};
60610 +} __no_const;
60611
60612 struct efivars {
60613 /*
60614 diff --git a/include/linux/elf.h b/include/linux/elf.h
60615 index 999b4f5..57753b4 100644
60616 --- a/include/linux/elf.h
60617 +++ b/include/linux/elf.h
60618 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60619 #define PT_GNU_EH_FRAME 0x6474e550
60620
60621 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60622 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60623 +
60624 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60625 +
60626 +/* Constants for the e_flags field */
60627 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60628 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60629 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60630 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60631 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60632 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60633
60634 /*
60635 * Extended Numbering
60636 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60637 #define DT_DEBUG 21
60638 #define DT_TEXTREL 22
60639 #define DT_JMPREL 23
60640 +#define DT_FLAGS 30
60641 + #define DF_TEXTREL 0x00000004
60642 #define DT_ENCODING 32
60643 #define OLD_DT_LOOS 0x60000000
60644 #define DT_LOOS 0x6000000d
60645 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60646 #define PF_W 0x2
60647 #define PF_X 0x1
60648
60649 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60650 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60651 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60652 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60653 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60654 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60655 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60656 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60657 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60658 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60659 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60660 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60661 +
60662 typedef struct elf32_phdr{
60663 Elf32_Word p_type;
60664 Elf32_Off p_offset;
60665 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60666 #define EI_OSABI 7
60667 #define EI_PAD 8
60668
60669 +#define EI_PAX 14
60670 +
60671 #define ELFMAG0 0x7f /* EI_MAG */
60672 #define ELFMAG1 'E'
60673 #define ELFMAG2 'L'
60674 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60675 #define elf_note elf32_note
60676 #define elf_addr_t Elf32_Off
60677 #define Elf_Half Elf32_Half
60678 +#define elf_dyn Elf32_Dyn
60679
60680 #else
60681
60682 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60683 #define elf_note elf64_note
60684 #define elf_addr_t Elf64_Off
60685 #define Elf_Half Elf64_Half
60686 +#define elf_dyn Elf64_Dyn
60687
60688 #endif
60689
60690 diff --git a/include/linux/filter.h b/include/linux/filter.h
60691 index 8eeb205..d59bfa2 100644
60692 --- a/include/linux/filter.h
60693 +++ b/include/linux/filter.h
60694 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60695
60696 struct sk_buff;
60697 struct sock;
60698 +struct bpf_jit_work;
60699
60700 struct sk_filter
60701 {
60702 @@ -141,6 +142,9 @@ struct sk_filter
60703 unsigned int len; /* Number of filter blocks */
60704 unsigned int (*bpf_func)(const struct sk_buff *skb,
60705 const struct sock_filter *filter);
60706 +#ifdef CONFIG_BPF_JIT
60707 + struct bpf_jit_work *work;
60708 +#endif
60709 struct rcu_head rcu;
60710 struct sock_filter insns[0];
60711 };
60712 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60713 index 84ccf8e..2e9b14c 100644
60714 --- a/include/linux/firewire.h
60715 +++ b/include/linux/firewire.h
60716 @@ -428,7 +428,7 @@ struct fw_iso_context {
60717 union {
60718 fw_iso_callback_t sc;
60719 fw_iso_mc_callback_t mc;
60720 - } callback;
60721 + } __no_const callback;
60722 void *callback_data;
60723 };
60724
60725 diff --git a/include/linux/fs.h b/include/linux/fs.h
60726 index f4b6e06..d6ba573 100644
60727 --- a/include/linux/fs.h
60728 +++ b/include/linux/fs.h
60729 @@ -1628,7 +1628,8 @@ struct file_operations {
60730 int (*setlease)(struct file *, long, struct file_lock **);
60731 long (*fallocate)(struct file *file, int mode, loff_t offset,
60732 loff_t len);
60733 -};
60734 +} __do_const;
60735 +typedef struct file_operations __no_const file_operations_no_const;
60736
60737 struct inode_operations {
60738 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60739 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60740 index 003dc0f..3c4ea97 100644
60741 --- a/include/linux/fs_struct.h
60742 +++ b/include/linux/fs_struct.h
60743 @@ -6,7 +6,7 @@
60744 #include <linux/seqlock.h>
60745
60746 struct fs_struct {
60747 - int users;
60748 + atomic_t users;
60749 spinlock_t lock;
60750 seqcount_t seq;
60751 int umask;
60752 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60753 index ce31408..b1ad003 100644
60754 --- a/include/linux/fscache-cache.h
60755 +++ b/include/linux/fscache-cache.h
60756 @@ -102,7 +102,7 @@ struct fscache_operation {
60757 fscache_operation_release_t release;
60758 };
60759
60760 -extern atomic_t fscache_op_debug_id;
60761 +extern atomic_unchecked_t fscache_op_debug_id;
60762 extern void fscache_op_work_func(struct work_struct *work);
60763
60764 extern void fscache_enqueue_operation(struct fscache_operation *);
60765 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60766 {
60767 INIT_WORK(&op->work, fscache_op_work_func);
60768 atomic_set(&op->usage, 1);
60769 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60770 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60771 op->processor = processor;
60772 op->release = release;
60773 INIT_LIST_HEAD(&op->pend_link);
60774 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60775 index 2a53f10..0187fdf 100644
60776 --- a/include/linux/fsnotify.h
60777 +++ b/include/linux/fsnotify.h
60778 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60779 */
60780 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60781 {
60782 - return kstrdup(name, GFP_KERNEL);
60783 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60784 }
60785
60786 /*
60787 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60788 index 91d0e0a3..035666b 100644
60789 --- a/include/linux/fsnotify_backend.h
60790 +++ b/include/linux/fsnotify_backend.h
60791 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60792 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60793 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60794 };
60795 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60796
60797 /*
60798 * A group is a "thing" that wants to receive notification about filesystem
60799 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60800 index c3da42d..c70e0df 100644
60801 --- a/include/linux/ftrace_event.h
60802 +++ b/include/linux/ftrace_event.h
60803 @@ -97,7 +97,7 @@ struct trace_event_functions {
60804 trace_print_func raw;
60805 trace_print_func hex;
60806 trace_print_func binary;
60807 -};
60808 +} __no_const;
60809
60810 struct trace_event {
60811 struct hlist_node node;
60812 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60813 extern int trace_add_event_call(struct ftrace_event_call *call);
60814 extern void trace_remove_event_call(struct ftrace_event_call *call);
60815
60816 -#define is_signed_type(type) (((type)(-1)) < 0)
60817 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60818
60819 int trace_set_clr_event(const char *system, const char *event, int set);
60820
60821 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60822 index e61d319..0da8505 100644
60823 --- a/include/linux/genhd.h
60824 +++ b/include/linux/genhd.h
60825 @@ -185,7 +185,7 @@ struct gendisk {
60826 struct kobject *slave_dir;
60827
60828 struct timer_rand_state *random;
60829 - atomic_t sync_io; /* RAID */
60830 + atomic_unchecked_t sync_io; /* RAID */
60831 struct disk_events *ev;
60832 #ifdef CONFIG_BLK_DEV_INTEGRITY
60833 struct blk_integrity *integrity;
60834 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60835 new file mode 100644
60836 index 0000000..8a130b6
60837 --- /dev/null
60838 +++ b/include/linux/gracl.h
60839 @@ -0,0 +1,319 @@
60840 +#ifndef GR_ACL_H
60841 +#define GR_ACL_H
60842 +
60843 +#include <linux/grdefs.h>
60844 +#include <linux/resource.h>
60845 +#include <linux/capability.h>
60846 +#include <linux/dcache.h>
60847 +#include <asm/resource.h>
60848 +
60849 +/* Major status information */
60850 +
60851 +#define GR_VERSION "grsecurity 2.9"
60852 +#define GRSECURITY_VERSION 0x2900
60853 +
60854 +enum {
60855 + GR_SHUTDOWN = 0,
60856 + GR_ENABLE = 1,
60857 + GR_SPROLE = 2,
60858 + GR_RELOAD = 3,
60859 + GR_SEGVMOD = 4,
60860 + GR_STATUS = 5,
60861 + GR_UNSPROLE = 6,
60862 + GR_PASSSET = 7,
60863 + GR_SPROLEPAM = 8,
60864 +};
60865 +
60866 +/* Password setup definitions
60867 + * kernel/grhash.c */
60868 +enum {
60869 + GR_PW_LEN = 128,
60870 + GR_SALT_LEN = 16,
60871 + GR_SHA_LEN = 32,
60872 +};
60873 +
60874 +enum {
60875 + GR_SPROLE_LEN = 64,
60876 +};
60877 +
60878 +enum {
60879 + GR_NO_GLOB = 0,
60880 + GR_REG_GLOB,
60881 + GR_CREATE_GLOB
60882 +};
60883 +
60884 +#define GR_NLIMITS 32
60885 +
60886 +/* Begin Data Structures */
60887 +
60888 +struct sprole_pw {
60889 + unsigned char *rolename;
60890 + unsigned char salt[GR_SALT_LEN];
60891 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60892 +};
60893 +
60894 +struct name_entry {
60895 + __u32 key;
60896 + ino_t inode;
60897 + dev_t device;
60898 + char *name;
60899 + __u16 len;
60900 + __u8 deleted;
60901 + struct name_entry *prev;
60902 + struct name_entry *next;
60903 +};
60904 +
60905 +struct inodev_entry {
60906 + struct name_entry *nentry;
60907 + struct inodev_entry *prev;
60908 + struct inodev_entry *next;
60909 +};
60910 +
60911 +struct acl_role_db {
60912 + struct acl_role_label **r_hash;
60913 + __u32 r_size;
60914 +};
60915 +
60916 +struct inodev_db {
60917 + struct inodev_entry **i_hash;
60918 + __u32 i_size;
60919 +};
60920 +
60921 +struct name_db {
60922 + struct name_entry **n_hash;
60923 + __u32 n_size;
60924 +};
60925 +
60926 +struct crash_uid {
60927 + uid_t uid;
60928 + unsigned long expires;
60929 +};
60930 +
60931 +struct gr_hash_struct {
60932 + void **table;
60933 + void **nametable;
60934 + void *first;
60935 + __u32 table_size;
60936 + __u32 used_size;
60937 + int type;
60938 +};
60939 +
60940 +/* Userspace Grsecurity ACL data structures */
60941 +
60942 +struct acl_subject_label {
60943 + char *filename;
60944 + ino_t inode;
60945 + dev_t device;
60946 + __u32 mode;
60947 + kernel_cap_t cap_mask;
60948 + kernel_cap_t cap_lower;
60949 + kernel_cap_t cap_invert_audit;
60950 +
60951 + struct rlimit res[GR_NLIMITS];
60952 + __u32 resmask;
60953 +
60954 + __u8 user_trans_type;
60955 + __u8 group_trans_type;
60956 + uid_t *user_transitions;
60957 + gid_t *group_transitions;
60958 + __u16 user_trans_num;
60959 + __u16 group_trans_num;
60960 +
60961 + __u32 sock_families[2];
60962 + __u32 ip_proto[8];
60963 + __u32 ip_type;
60964 + struct acl_ip_label **ips;
60965 + __u32 ip_num;
60966 + __u32 inaddr_any_override;
60967 +
60968 + __u32 crashes;
60969 + unsigned long expires;
60970 +
60971 + struct acl_subject_label *parent_subject;
60972 + struct gr_hash_struct *hash;
60973 + struct acl_subject_label *prev;
60974 + struct acl_subject_label *next;
60975 +
60976 + struct acl_object_label **obj_hash;
60977 + __u32 obj_hash_size;
60978 + __u16 pax_flags;
60979 +};
60980 +
60981 +struct role_allowed_ip {
60982 + __u32 addr;
60983 + __u32 netmask;
60984 +
60985 + struct role_allowed_ip *prev;
60986 + struct role_allowed_ip *next;
60987 +};
60988 +
60989 +struct role_transition {
60990 + char *rolename;
60991 +
60992 + struct role_transition *prev;
60993 + struct role_transition *next;
60994 +};
60995 +
60996 +struct acl_role_label {
60997 + char *rolename;
60998 + uid_t uidgid;
60999 + __u16 roletype;
61000 +
61001 + __u16 auth_attempts;
61002 + unsigned long expires;
61003 +
61004 + struct acl_subject_label *root_label;
61005 + struct gr_hash_struct *hash;
61006 +
61007 + struct acl_role_label *prev;
61008 + struct acl_role_label *next;
61009 +
61010 + struct role_transition *transitions;
61011 + struct role_allowed_ip *allowed_ips;
61012 + uid_t *domain_children;
61013 + __u16 domain_child_num;
61014 +
61015 + umode_t umask;
61016 +
61017 + struct acl_subject_label **subj_hash;
61018 + __u32 subj_hash_size;
61019 +};
61020 +
61021 +struct user_acl_role_db {
61022 + struct acl_role_label **r_table;
61023 + __u32 num_pointers; /* Number of allocations to track */
61024 + __u32 num_roles; /* Number of roles */
61025 + __u32 num_domain_children; /* Number of domain children */
61026 + __u32 num_subjects; /* Number of subjects */
61027 + __u32 num_objects; /* Number of objects */
61028 +};
61029 +
61030 +struct acl_object_label {
61031 + char *filename;
61032 + ino_t inode;
61033 + dev_t device;
61034 + __u32 mode;
61035 +
61036 + struct acl_subject_label *nested;
61037 + struct acl_object_label *globbed;
61038 +
61039 + /* next two structures not used */
61040 +
61041 + struct acl_object_label *prev;
61042 + struct acl_object_label *next;
61043 +};
61044 +
61045 +struct acl_ip_label {
61046 + char *iface;
61047 + __u32 addr;
61048 + __u32 netmask;
61049 + __u16 low, high;
61050 + __u8 mode;
61051 + __u32 type;
61052 + __u32 proto[8];
61053 +
61054 + /* next two structures not used */
61055 +
61056 + struct acl_ip_label *prev;
61057 + struct acl_ip_label *next;
61058 +};
61059 +
61060 +struct gr_arg {
61061 + struct user_acl_role_db role_db;
61062 + unsigned char pw[GR_PW_LEN];
61063 + unsigned char salt[GR_SALT_LEN];
61064 + unsigned char sum[GR_SHA_LEN];
61065 + unsigned char sp_role[GR_SPROLE_LEN];
61066 + struct sprole_pw *sprole_pws;
61067 + dev_t segv_device;
61068 + ino_t segv_inode;
61069 + uid_t segv_uid;
61070 + __u16 num_sprole_pws;
61071 + __u16 mode;
61072 +};
61073 +
61074 +struct gr_arg_wrapper {
61075 + struct gr_arg *arg;
61076 + __u32 version;
61077 + __u32 size;
61078 +};
61079 +
61080 +struct subject_map {
61081 + struct acl_subject_label *user;
61082 + struct acl_subject_label *kernel;
61083 + struct subject_map *prev;
61084 + struct subject_map *next;
61085 +};
61086 +
61087 +struct acl_subj_map_db {
61088 + struct subject_map **s_hash;
61089 + __u32 s_size;
61090 +};
61091 +
61092 +/* End Data Structures Section */
61093 +
61094 +/* Hash functions generated by empirical testing by Brad Spengler
61095 + Makes good use of the low bits of the inode. Generally 0-1 times
61096 + in loop for successful match. 0-3 for unsuccessful match.
61097 + Shift/add algorithm with modulus of table size and an XOR*/
61098 +
61099 +static __inline__ unsigned int
61100 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61101 +{
61102 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61103 +}
61104 +
61105 + static __inline__ unsigned int
61106 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61107 +{
61108 + return ((const unsigned long)userp % sz);
61109 +}
61110 +
61111 +static __inline__ unsigned int
61112 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61113 +{
61114 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61115 +}
61116 +
61117 +static __inline__ unsigned int
61118 +nhash(const char *name, const __u16 len, const unsigned int sz)
61119 +{
61120 + return full_name_hash((const unsigned char *)name, len) % sz;
61121 +}
61122 +
61123 +#define FOR_EACH_ROLE_START(role) \
61124 + role = role_list; \
61125 + while (role) {
61126 +
61127 +#define FOR_EACH_ROLE_END(role) \
61128 + role = role->prev; \
61129 + }
61130 +
61131 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61132 + subj = NULL; \
61133 + iter = 0; \
61134 + while (iter < role->subj_hash_size) { \
61135 + if (subj == NULL) \
61136 + subj = role->subj_hash[iter]; \
61137 + if (subj == NULL) { \
61138 + iter++; \
61139 + continue; \
61140 + }
61141 +
61142 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61143 + subj = subj->next; \
61144 + if (subj == NULL) \
61145 + iter++; \
61146 + }
61147 +
61148 +
61149 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61150 + subj = role->hash->first; \
61151 + while (subj != NULL) {
61152 +
61153 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61154 + subj = subj->next; \
61155 + }
61156 +
61157 +#endif
61158 +
61159 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61160 new file mode 100644
61161 index 0000000..323ecf2
61162 --- /dev/null
61163 +++ b/include/linux/gralloc.h
61164 @@ -0,0 +1,9 @@
61165 +#ifndef __GRALLOC_H
61166 +#define __GRALLOC_H
61167 +
61168 +void acl_free_all(void);
61169 +int acl_alloc_stack_init(unsigned long size);
61170 +void *acl_alloc(unsigned long len);
61171 +void *acl_alloc_num(unsigned long num, unsigned long len);
61172 +
61173 +#endif
61174 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61175 new file mode 100644
61176 index 0000000..b30e9bc
61177 --- /dev/null
61178 +++ b/include/linux/grdefs.h
61179 @@ -0,0 +1,140 @@
61180 +#ifndef GRDEFS_H
61181 +#define GRDEFS_H
61182 +
61183 +/* Begin grsecurity status declarations */
61184 +
61185 +enum {
61186 + GR_READY = 0x01,
61187 + GR_STATUS_INIT = 0x00 // disabled state
61188 +};
61189 +
61190 +/* Begin ACL declarations */
61191 +
61192 +/* Role flags */
61193 +
61194 +enum {
61195 + GR_ROLE_USER = 0x0001,
61196 + GR_ROLE_GROUP = 0x0002,
61197 + GR_ROLE_DEFAULT = 0x0004,
61198 + GR_ROLE_SPECIAL = 0x0008,
61199 + GR_ROLE_AUTH = 0x0010,
61200 + GR_ROLE_NOPW = 0x0020,
61201 + GR_ROLE_GOD = 0x0040,
61202 + GR_ROLE_LEARN = 0x0080,
61203 + GR_ROLE_TPE = 0x0100,
61204 + GR_ROLE_DOMAIN = 0x0200,
61205 + GR_ROLE_PAM = 0x0400,
61206 + GR_ROLE_PERSIST = 0x0800
61207 +};
61208 +
61209 +/* ACL Subject and Object mode flags */
61210 +enum {
61211 + GR_DELETED = 0x80000000
61212 +};
61213 +
61214 +/* ACL Object-only mode flags */
61215 +enum {
61216 + GR_READ = 0x00000001,
61217 + GR_APPEND = 0x00000002,
61218 + GR_WRITE = 0x00000004,
61219 + GR_EXEC = 0x00000008,
61220 + GR_FIND = 0x00000010,
61221 + GR_INHERIT = 0x00000020,
61222 + GR_SETID = 0x00000040,
61223 + GR_CREATE = 0x00000080,
61224 + GR_DELETE = 0x00000100,
61225 + GR_LINK = 0x00000200,
61226 + GR_AUDIT_READ = 0x00000400,
61227 + GR_AUDIT_APPEND = 0x00000800,
61228 + GR_AUDIT_WRITE = 0x00001000,
61229 + GR_AUDIT_EXEC = 0x00002000,
61230 + GR_AUDIT_FIND = 0x00004000,
61231 + GR_AUDIT_INHERIT= 0x00008000,
61232 + GR_AUDIT_SETID = 0x00010000,
61233 + GR_AUDIT_CREATE = 0x00020000,
61234 + GR_AUDIT_DELETE = 0x00040000,
61235 + GR_AUDIT_LINK = 0x00080000,
61236 + GR_PTRACERD = 0x00100000,
61237 + GR_NOPTRACE = 0x00200000,
61238 + GR_SUPPRESS = 0x00400000,
61239 + GR_NOLEARN = 0x00800000,
61240 + GR_INIT_TRANSFER= 0x01000000
61241 +};
61242 +
61243 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61244 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61245 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61246 +
61247 +/* ACL subject-only mode flags */
61248 +enum {
61249 + GR_KILL = 0x00000001,
61250 + GR_VIEW = 0x00000002,
61251 + GR_PROTECTED = 0x00000004,
61252 + GR_LEARN = 0x00000008,
61253 + GR_OVERRIDE = 0x00000010,
61254 + /* just a placeholder, this mode is only used in userspace */
61255 + GR_DUMMY = 0x00000020,
61256 + GR_PROTSHM = 0x00000040,
61257 + GR_KILLPROC = 0x00000080,
61258 + GR_KILLIPPROC = 0x00000100,
61259 + /* just a placeholder, this mode is only used in userspace */
61260 + GR_NOTROJAN = 0x00000200,
61261 + GR_PROTPROCFD = 0x00000400,
61262 + GR_PROCACCT = 0x00000800,
61263 + GR_RELAXPTRACE = 0x00001000,
61264 + GR_NESTED = 0x00002000,
61265 + GR_INHERITLEARN = 0x00004000,
61266 + GR_PROCFIND = 0x00008000,
61267 + GR_POVERRIDE = 0x00010000,
61268 + GR_KERNELAUTH = 0x00020000,
61269 + GR_ATSECURE = 0x00040000,
61270 + GR_SHMEXEC = 0x00080000
61271 +};
61272 +
61273 +enum {
61274 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61275 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61276 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61277 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61278 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61279 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61280 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61281 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61282 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61283 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61284 +};
61285 +
61286 +enum {
61287 + GR_ID_USER = 0x01,
61288 + GR_ID_GROUP = 0x02,
61289 +};
61290 +
61291 +enum {
61292 + GR_ID_ALLOW = 0x01,
61293 + GR_ID_DENY = 0x02,
61294 +};
61295 +
61296 +#define GR_CRASH_RES 31
61297 +#define GR_UIDTABLE_MAX 500
61298 +
61299 +/* begin resource learning section */
61300 +enum {
61301 + GR_RLIM_CPU_BUMP = 60,
61302 + GR_RLIM_FSIZE_BUMP = 50000,
61303 + GR_RLIM_DATA_BUMP = 10000,
61304 + GR_RLIM_STACK_BUMP = 1000,
61305 + GR_RLIM_CORE_BUMP = 10000,
61306 + GR_RLIM_RSS_BUMP = 500000,
61307 + GR_RLIM_NPROC_BUMP = 1,
61308 + GR_RLIM_NOFILE_BUMP = 5,
61309 + GR_RLIM_MEMLOCK_BUMP = 50000,
61310 + GR_RLIM_AS_BUMP = 500000,
61311 + GR_RLIM_LOCKS_BUMP = 2,
61312 + GR_RLIM_SIGPENDING_BUMP = 5,
61313 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61314 + GR_RLIM_NICE_BUMP = 1,
61315 + GR_RLIM_RTPRIO_BUMP = 1,
61316 + GR_RLIM_RTTIME_BUMP = 1000000
61317 +};
61318 +
61319 +#endif
61320 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61321 new file mode 100644
61322 index 0000000..da390f1
61323 --- /dev/null
61324 +++ b/include/linux/grinternal.h
61325 @@ -0,0 +1,221 @@
61326 +#ifndef __GRINTERNAL_H
61327 +#define __GRINTERNAL_H
61328 +
61329 +#ifdef CONFIG_GRKERNSEC
61330 +
61331 +#include <linux/fs.h>
61332 +#include <linux/mnt_namespace.h>
61333 +#include <linux/nsproxy.h>
61334 +#include <linux/gracl.h>
61335 +#include <linux/grdefs.h>
61336 +#include <linux/grmsg.h>
61337 +
61338 +void gr_add_learn_entry(const char *fmt, ...)
61339 + __attribute__ ((format (printf, 1, 2)));
61340 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61341 + const struct vfsmount *mnt);
61342 +__u32 gr_check_create(const struct dentry *new_dentry,
61343 + const struct dentry *parent,
61344 + const struct vfsmount *mnt, const __u32 mode);
61345 +int gr_check_protected_task(const struct task_struct *task);
61346 +__u32 to_gr_audit(const __u32 reqmode);
61347 +int gr_set_acls(const int type);
61348 +int gr_apply_subject_to_task(struct task_struct *task);
61349 +int gr_acl_is_enabled(void);
61350 +char gr_roletype_to_char(void);
61351 +
61352 +void gr_handle_alertkill(struct task_struct *task);
61353 +char *gr_to_filename(const struct dentry *dentry,
61354 + const struct vfsmount *mnt);
61355 +char *gr_to_filename1(const struct dentry *dentry,
61356 + const struct vfsmount *mnt);
61357 +char *gr_to_filename2(const struct dentry *dentry,
61358 + const struct vfsmount *mnt);
61359 +char *gr_to_filename3(const struct dentry *dentry,
61360 + const struct vfsmount *mnt);
61361 +
61362 +extern int grsec_enable_ptrace_readexec;
61363 +extern int grsec_enable_harden_ptrace;
61364 +extern int grsec_enable_link;
61365 +extern int grsec_enable_fifo;
61366 +extern int grsec_enable_execve;
61367 +extern int grsec_enable_shm;
61368 +extern int grsec_enable_execlog;
61369 +extern int grsec_enable_signal;
61370 +extern int grsec_enable_audit_ptrace;
61371 +extern int grsec_enable_forkfail;
61372 +extern int grsec_enable_time;
61373 +extern int grsec_enable_rofs;
61374 +extern int grsec_enable_chroot_shmat;
61375 +extern int grsec_enable_chroot_mount;
61376 +extern int grsec_enable_chroot_double;
61377 +extern int grsec_enable_chroot_pivot;
61378 +extern int grsec_enable_chroot_chdir;
61379 +extern int grsec_enable_chroot_chmod;
61380 +extern int grsec_enable_chroot_mknod;
61381 +extern int grsec_enable_chroot_fchdir;
61382 +extern int grsec_enable_chroot_nice;
61383 +extern int grsec_enable_chroot_execlog;
61384 +extern int grsec_enable_chroot_caps;
61385 +extern int grsec_enable_chroot_sysctl;
61386 +extern int grsec_enable_chroot_unix;
61387 +extern int grsec_enable_tpe;
61388 +extern int grsec_tpe_gid;
61389 +extern int grsec_enable_tpe_all;
61390 +extern int grsec_enable_tpe_invert;
61391 +extern int grsec_enable_socket_all;
61392 +extern int grsec_socket_all_gid;
61393 +extern int grsec_enable_socket_client;
61394 +extern int grsec_socket_client_gid;
61395 +extern int grsec_enable_socket_server;
61396 +extern int grsec_socket_server_gid;
61397 +extern int grsec_audit_gid;
61398 +extern int grsec_enable_group;
61399 +extern int grsec_enable_audit_textrel;
61400 +extern int grsec_enable_log_rwxmaps;
61401 +extern int grsec_enable_mount;
61402 +extern int grsec_enable_chdir;
61403 +extern int grsec_resource_logging;
61404 +extern int grsec_enable_blackhole;
61405 +extern int grsec_lastack_retries;
61406 +extern int grsec_enable_brute;
61407 +extern int grsec_lock;
61408 +
61409 +extern spinlock_t grsec_alert_lock;
61410 +extern unsigned long grsec_alert_wtime;
61411 +extern unsigned long grsec_alert_fyet;
61412 +
61413 +extern spinlock_t grsec_audit_lock;
61414 +
61415 +extern rwlock_t grsec_exec_file_lock;
61416 +
61417 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61418 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61419 + (tsk)->exec_file->f_vfsmnt) : "/")
61420 +
61421 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61422 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61423 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61424 +
61425 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61426 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61427 + (tsk)->exec_file->f_vfsmnt) : "/")
61428 +
61429 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61430 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61431 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61432 +
61433 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61434 +
61435 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61436 +
61437 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61438 + (task)->pid, (cred)->uid, \
61439 + (cred)->euid, (cred)->gid, (cred)->egid, \
61440 + gr_parent_task_fullpath(task), \
61441 + (task)->real_parent->comm, (task)->real_parent->pid, \
61442 + (pcred)->uid, (pcred)->euid, \
61443 + (pcred)->gid, (pcred)->egid
61444 +
61445 +#define GR_CHROOT_CAPS {{ \
61446 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61447 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61448 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61449 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61450 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61451 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61452 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61453 +
61454 +#define security_learn(normal_msg,args...) \
61455 +({ \
61456 + read_lock(&grsec_exec_file_lock); \
61457 + gr_add_learn_entry(normal_msg "\n", ## args); \
61458 + read_unlock(&grsec_exec_file_lock); \
61459 +})
61460 +
61461 +enum {
61462 + GR_DO_AUDIT,
61463 + GR_DONT_AUDIT,
61464 + /* used for non-audit messages that we shouldn't kill the task on */
61465 + GR_DONT_AUDIT_GOOD
61466 +};
61467 +
61468 +enum {
61469 + GR_TTYSNIFF,
61470 + GR_RBAC,
61471 + GR_RBAC_STR,
61472 + GR_STR_RBAC,
61473 + GR_RBAC_MODE2,
61474 + GR_RBAC_MODE3,
61475 + GR_FILENAME,
61476 + GR_SYSCTL_HIDDEN,
61477 + GR_NOARGS,
61478 + GR_ONE_INT,
61479 + GR_ONE_INT_TWO_STR,
61480 + GR_ONE_STR,
61481 + GR_STR_INT,
61482 + GR_TWO_STR_INT,
61483 + GR_TWO_INT,
61484 + GR_TWO_U64,
61485 + GR_THREE_INT,
61486 + GR_FIVE_INT_TWO_STR,
61487 + GR_TWO_STR,
61488 + GR_THREE_STR,
61489 + GR_FOUR_STR,
61490 + GR_STR_FILENAME,
61491 + GR_FILENAME_STR,
61492 + GR_FILENAME_TWO_INT,
61493 + GR_FILENAME_TWO_INT_STR,
61494 + GR_TEXTREL,
61495 + GR_PTRACE,
61496 + GR_RESOURCE,
61497 + GR_CAP,
61498 + GR_SIG,
61499 + GR_SIG2,
61500 + GR_CRASH1,
61501 + GR_CRASH2,
61502 + GR_PSACCT,
61503 + GR_RWXMAP
61504 +};
61505 +
61506 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61507 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61508 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61509 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61510 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61511 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61512 +#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)
61513 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61514 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61515 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61516 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61517 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61518 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61519 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61520 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61521 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61522 +#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)
61523 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61524 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61525 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61526 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61527 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61528 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61529 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61530 +#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)
61531 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61532 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61533 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61534 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61535 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61536 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61537 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61538 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61539 +#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)
61540 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61541 +
61542 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61543 +
61544 +#endif
61545 +
61546 +#endif
61547 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61548 new file mode 100644
61549 index 0000000..ae576a1
61550 --- /dev/null
61551 +++ b/include/linux/grmsg.h
61552 @@ -0,0 +1,109 @@
61553 +#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"
61554 +#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"
61555 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61556 +#define GR_STOPMOD_MSG "denied modification of module state by "
61557 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61558 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61559 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61560 +#define GR_IOPL_MSG "denied use of iopl() by "
61561 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61562 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61563 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61564 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61565 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61566 +#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"
61567 +#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"
61568 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61569 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61570 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61571 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61572 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61573 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61574 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61575 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61576 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61577 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61578 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61579 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61580 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61581 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61582 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61583 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61584 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61585 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61586 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61587 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61588 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61589 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61590 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61591 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61592 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61593 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61594 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61595 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61596 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61597 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61598 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61599 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61600 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61601 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61602 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61603 +#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"
61604 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61605 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61606 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61607 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61608 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61609 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61610 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61611 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61612 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61613 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61614 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61615 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61616 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61617 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61618 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61619 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61620 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61621 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61622 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61623 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61624 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61625 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61626 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61627 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61628 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61629 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61630 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61631 +#define GR_TIME_MSG "time set by "
61632 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61633 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61634 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61635 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61636 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61637 +#define GR_BIND_MSG "denied bind() by "
61638 +#define GR_CONNECT_MSG "denied connect() by "
61639 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61640 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61641 +#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"
61642 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61643 +#define GR_CAP_ACL_MSG "use of %s denied for "
61644 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61645 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61646 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61647 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61648 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61649 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61650 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61651 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61652 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61653 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61654 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61655 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61656 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61657 +#define GR_VM86_MSG "denied use of vm86 by "
61658 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61659 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61660 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61661 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61662 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61663 new file mode 100644
61664 index 0000000..acd05db
61665 --- /dev/null
61666 +++ b/include/linux/grsecurity.h
61667 @@ -0,0 +1,232 @@
61668 +#ifndef GR_SECURITY_H
61669 +#define GR_SECURITY_H
61670 +#include <linux/fs.h>
61671 +#include <linux/fs_struct.h>
61672 +#include <linux/binfmts.h>
61673 +#include <linux/gracl.h>
61674 +
61675 +/* notify of brain-dead configs */
61676 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61677 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61678 +#endif
61679 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61680 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61681 +#endif
61682 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61683 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61684 +#endif
61685 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61686 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61687 +#endif
61688 +
61689 +#include <linux/compat.h>
61690 +
61691 +struct user_arg_ptr {
61692 +#ifdef CONFIG_COMPAT
61693 + bool is_compat;
61694 +#endif
61695 + union {
61696 + const char __user *const __user *native;
61697 +#ifdef CONFIG_COMPAT
61698 + compat_uptr_t __user *compat;
61699 +#endif
61700 + } ptr;
61701 +};
61702 +
61703 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61704 +void gr_handle_brute_check(void);
61705 +void gr_handle_kernel_exploit(void);
61706 +int gr_process_user_ban(void);
61707 +
61708 +char gr_roletype_to_char(void);
61709 +
61710 +int gr_acl_enable_at_secure(void);
61711 +
61712 +int gr_check_user_change(int real, int effective, int fs);
61713 +int gr_check_group_change(int real, int effective, int fs);
61714 +
61715 +void gr_del_task_from_ip_table(struct task_struct *p);
61716 +
61717 +int gr_pid_is_chrooted(struct task_struct *p);
61718 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61719 +int gr_handle_chroot_nice(void);
61720 +int gr_handle_chroot_sysctl(const int op);
61721 +int gr_handle_chroot_setpriority(struct task_struct *p,
61722 + const int niceval);
61723 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61724 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61725 + const struct vfsmount *mnt);
61726 +void gr_handle_chroot_chdir(struct path *path);
61727 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61728 + const struct vfsmount *mnt, const int mode);
61729 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61730 + const struct vfsmount *mnt, const int mode);
61731 +int gr_handle_chroot_mount(const struct dentry *dentry,
61732 + const struct vfsmount *mnt,
61733 + const char *dev_name);
61734 +int gr_handle_chroot_pivot(void);
61735 +int gr_handle_chroot_unix(const pid_t pid);
61736 +
61737 +int gr_handle_rawio(const struct inode *inode);
61738 +
61739 +void gr_handle_ioperm(void);
61740 +void gr_handle_iopl(void);
61741 +
61742 +umode_t gr_acl_umask(void);
61743 +
61744 +int gr_tpe_allow(const struct file *file);
61745 +
61746 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61747 +void gr_clear_chroot_entries(struct task_struct *task);
61748 +
61749 +void gr_log_forkfail(const int retval);
61750 +void gr_log_timechange(void);
61751 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61752 +void gr_log_chdir(const struct dentry *dentry,
61753 + const struct vfsmount *mnt);
61754 +void gr_log_chroot_exec(const struct dentry *dentry,
61755 + const struct vfsmount *mnt);
61756 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61757 +void gr_log_remount(const char *devname, const int retval);
61758 +void gr_log_unmount(const char *devname, const int retval);
61759 +void gr_log_mount(const char *from, const char *to, const int retval);
61760 +void gr_log_textrel(struct vm_area_struct *vma);
61761 +void gr_log_rwxmmap(struct file *file);
61762 +void gr_log_rwxmprotect(struct file *file);
61763 +
61764 +int gr_handle_follow_link(const struct inode *parent,
61765 + const struct inode *inode,
61766 + const struct dentry *dentry,
61767 + const struct vfsmount *mnt);
61768 +int gr_handle_fifo(const struct dentry *dentry,
61769 + const struct vfsmount *mnt,
61770 + const struct dentry *dir, const int flag,
61771 + const int acc_mode);
61772 +int gr_handle_hardlink(const struct dentry *dentry,
61773 + const struct vfsmount *mnt,
61774 + struct inode *inode,
61775 + const int mode, const char *to);
61776 +
61777 +int gr_is_capable(const int cap);
61778 +int gr_is_capable_nolog(const int cap);
61779 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61780 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61781 +
61782 +void gr_learn_resource(const struct task_struct *task, const int limit,
61783 + const unsigned long wanted, const int gt);
61784 +void gr_copy_label(struct task_struct *tsk);
61785 +void gr_handle_crash(struct task_struct *task, const int sig);
61786 +int gr_handle_signal(const struct task_struct *p, const int sig);
61787 +int gr_check_crash_uid(const uid_t uid);
61788 +int gr_check_protected_task(const struct task_struct *task);
61789 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61790 +int gr_acl_handle_mmap(const struct file *file,
61791 + const unsigned long prot);
61792 +int gr_acl_handle_mprotect(const struct file *file,
61793 + const unsigned long prot);
61794 +int gr_check_hidden_task(const struct task_struct *tsk);
61795 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61796 + const struct vfsmount *mnt);
61797 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61798 + const struct vfsmount *mnt);
61799 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61800 + const struct vfsmount *mnt, const int fmode);
61801 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61802 + const struct vfsmount *mnt, umode_t *mode);
61803 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61804 + const struct vfsmount *mnt);
61805 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61806 + const struct vfsmount *mnt);
61807 +int gr_handle_ptrace(struct task_struct *task, const long request);
61808 +int gr_handle_proc_ptrace(struct task_struct *task);
61809 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61810 + const struct vfsmount *mnt);
61811 +int gr_check_crash_exec(const struct file *filp);
61812 +int gr_acl_is_enabled(void);
61813 +void gr_set_kernel_label(struct task_struct *task);
61814 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61815 + const gid_t gid);
61816 +int gr_set_proc_label(const struct dentry *dentry,
61817 + const struct vfsmount *mnt,
61818 + const int unsafe_flags);
61819 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61820 + const struct vfsmount *mnt);
61821 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61822 + const struct vfsmount *mnt, int acc_mode);
61823 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61824 + const struct dentry *p_dentry,
61825 + const struct vfsmount *p_mnt,
61826 + int open_flags, int acc_mode, const int imode);
61827 +void gr_handle_create(const struct dentry *dentry,
61828 + const struct vfsmount *mnt);
61829 +void gr_handle_proc_create(const struct dentry *dentry,
61830 + const struct inode *inode);
61831 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61832 + const struct dentry *parent_dentry,
61833 + const struct vfsmount *parent_mnt,
61834 + const int mode);
61835 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61836 + const struct dentry *parent_dentry,
61837 + const struct vfsmount *parent_mnt);
61838 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61839 + const struct vfsmount *mnt);
61840 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61841 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61842 + const struct vfsmount *mnt);
61843 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61844 + const struct dentry *parent_dentry,
61845 + const struct vfsmount *parent_mnt,
61846 + const char *from);
61847 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61848 + const struct dentry *parent_dentry,
61849 + const struct vfsmount *parent_mnt,
61850 + const struct dentry *old_dentry,
61851 + const struct vfsmount *old_mnt, const char *to);
61852 +int gr_acl_handle_rename(struct dentry *new_dentry,
61853 + struct dentry *parent_dentry,
61854 + const struct vfsmount *parent_mnt,
61855 + struct dentry *old_dentry,
61856 + struct inode *old_parent_inode,
61857 + struct vfsmount *old_mnt, const char *newname);
61858 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61859 + struct dentry *old_dentry,
61860 + struct dentry *new_dentry,
61861 + struct vfsmount *mnt, const __u8 replace);
61862 +__u32 gr_check_link(const struct dentry *new_dentry,
61863 + const struct dentry *parent_dentry,
61864 + const struct vfsmount *parent_mnt,
61865 + const struct dentry *old_dentry,
61866 + const struct vfsmount *old_mnt);
61867 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61868 + const unsigned int namelen, const ino_t ino);
61869 +
61870 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61871 + const struct vfsmount *mnt);
61872 +void gr_acl_handle_exit(void);
61873 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61874 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61875 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61876 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61877 +void gr_audit_ptrace(struct task_struct *task);
61878 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61879 +
61880 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61881 +
61882 +#ifdef CONFIG_GRKERNSEC
61883 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61884 +void gr_handle_vm86(void);
61885 +void gr_handle_mem_readwrite(u64 from, u64 to);
61886 +
61887 +void gr_log_badprocpid(const char *entry);
61888 +
61889 +extern int grsec_enable_dmesg;
61890 +extern int grsec_disable_privio;
61891 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61892 +extern int grsec_enable_chroot_findtask;
61893 +#endif
61894 +#ifdef CONFIG_GRKERNSEC_SETXID
61895 +extern int grsec_enable_setxid;
61896 +#endif
61897 +#endif
61898 +
61899 +#endif
61900 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61901 new file mode 100644
61902 index 0000000..e7ffaaf
61903 --- /dev/null
61904 +++ b/include/linux/grsock.h
61905 @@ -0,0 +1,19 @@
61906 +#ifndef __GRSOCK_H
61907 +#define __GRSOCK_H
61908 +
61909 +extern void gr_attach_curr_ip(const struct sock *sk);
61910 +extern int gr_handle_sock_all(const int family, const int type,
61911 + const int protocol);
61912 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61913 +extern int gr_handle_sock_server_other(const struct sock *sck);
61914 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61915 +extern int gr_search_connect(struct socket * sock,
61916 + struct sockaddr_in * addr);
61917 +extern int gr_search_bind(struct socket * sock,
61918 + struct sockaddr_in * addr);
61919 +extern int gr_search_listen(struct socket * sock);
61920 +extern int gr_search_accept(struct socket * sock);
61921 +extern int gr_search_socket(const int domain, const int type,
61922 + const int protocol);
61923 +
61924 +#endif
61925 diff --git a/include/linux/hid.h b/include/linux/hid.h
61926 index 3a95da6..51986f1 100644
61927 --- a/include/linux/hid.h
61928 +++ b/include/linux/hid.h
61929 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61930 unsigned int code, int value);
61931
61932 int (*parse)(struct hid_device *hdev);
61933 -};
61934 +} __no_const;
61935
61936 #define PM_HINT_FULLON 1<<5
61937 #define PM_HINT_NORMAL 1<<1
61938 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61939 index 3a93f73..b19d0b3 100644
61940 --- a/include/linux/highmem.h
61941 +++ b/include/linux/highmem.h
61942 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61943 kunmap_atomic(kaddr, KM_USER0);
61944 }
61945
61946 +static inline void sanitize_highpage(struct page *page)
61947 +{
61948 + void *kaddr;
61949 + unsigned long flags;
61950 +
61951 + local_irq_save(flags);
61952 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
61953 + clear_page(kaddr);
61954 + kunmap_atomic(kaddr, KM_CLEARPAGE);
61955 + local_irq_restore(flags);
61956 +}
61957 +
61958 static inline void zero_user_segments(struct page *page,
61959 unsigned start1, unsigned end1,
61960 unsigned start2, unsigned end2)
61961 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61962 index 8e25a91..551b161 100644
61963 --- a/include/linux/i2c.h
61964 +++ b/include/linux/i2c.h
61965 @@ -364,6 +364,7 @@ struct i2c_algorithm {
61966 /* To determine what the adapter supports */
61967 u32 (*functionality) (struct i2c_adapter *);
61968 };
61969 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61970
61971 /*
61972 * i2c_adapter is the structure used to identify a physical i2c bus along
61973 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61974 index a6deef4..c56a7f2 100644
61975 --- a/include/linux/i2o.h
61976 +++ b/include/linux/i2o.h
61977 @@ -564,7 +564,7 @@ struct i2o_controller {
61978 struct i2o_device *exec; /* Executive */
61979 #if BITS_PER_LONG == 64
61980 spinlock_t context_list_lock; /* lock for context_list */
61981 - atomic_t context_list_counter; /* needed for unique contexts */
61982 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61983 struct list_head context_list; /* list of context id's
61984 and pointers */
61985 #endif
61986 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61987 index 58404b0..439ed95 100644
61988 --- a/include/linux/if_team.h
61989 +++ b/include/linux/if_team.h
61990 @@ -64,6 +64,7 @@ struct team_mode_ops {
61991 void (*port_leave)(struct team *team, struct team_port *port);
61992 void (*port_change_mac)(struct team *team, struct team_port *port);
61993 };
61994 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61995
61996 enum team_option_type {
61997 TEAM_OPTION_TYPE_U32,
61998 @@ -112,7 +113,7 @@ struct team {
61999 struct list_head option_list;
62000
62001 const struct team_mode *mode;
62002 - struct team_mode_ops ops;
62003 + team_mode_ops_no_const ops;
62004 long mode_priv[TEAM_MODE_PRIV_LONGS];
62005 };
62006
62007 diff --git a/include/linux/init.h b/include/linux/init.h
62008 index 6b95109..4aca62c 100644
62009 --- a/include/linux/init.h
62010 +++ b/include/linux/init.h
62011 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
62012
62013 /* Each module must use one module_init(). */
62014 #define module_init(initfn) \
62015 - static inline initcall_t __inittest(void) \
62016 + static inline __used initcall_t __inittest(void) \
62017 { return initfn; } \
62018 int init_module(void) __attribute__((alias(#initfn)));
62019
62020 /* This is only required if you want to be unloadable. */
62021 #define module_exit(exitfn) \
62022 - static inline exitcall_t __exittest(void) \
62023 + static inline __used exitcall_t __exittest(void) \
62024 { return exitfn; } \
62025 void cleanup_module(void) __attribute__((alias(#exitfn)));
62026
62027 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62028 index 9c66b1a..a3fdded 100644
62029 --- a/include/linux/init_task.h
62030 +++ b/include/linux/init_task.h
62031 @@ -127,6 +127,12 @@ extern struct cred init_cred;
62032
62033 #define INIT_TASK_COMM "swapper"
62034
62035 +#ifdef CONFIG_X86
62036 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62037 +#else
62038 +#define INIT_TASK_THREAD_INFO
62039 +#endif
62040 +
62041 /*
62042 * INIT_TASK is used to set up the first task table, touch at
62043 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62044 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62045 RCU_INIT_POINTER(.cred, &init_cred), \
62046 .comm = INIT_TASK_COMM, \
62047 .thread = INIT_THREAD, \
62048 + INIT_TASK_THREAD_INFO \
62049 .fs = &init_fs, \
62050 .files = &init_files, \
62051 .signal = &init_signals, \
62052 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62053 index e6ca56d..8583707 100644
62054 --- a/include/linux/intel-iommu.h
62055 +++ b/include/linux/intel-iommu.h
62056 @@ -296,7 +296,7 @@ struct iommu_flush {
62057 u8 fm, u64 type);
62058 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62059 unsigned int size_order, u64 type);
62060 -};
62061 +} __no_const;
62062
62063 enum {
62064 SR_DMAR_FECTL_REG,
62065 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62066 index a64b00e..464d8bc 100644
62067 --- a/include/linux/interrupt.h
62068 +++ b/include/linux/interrupt.h
62069 @@ -441,7 +441,7 @@ enum
62070 /* map softirq index to softirq name. update 'softirq_to_name' in
62071 * kernel/softirq.c when adding a new softirq.
62072 */
62073 -extern char *softirq_to_name[NR_SOFTIRQS];
62074 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62075
62076 /* softirq mask and active fields moved to irq_cpustat_t in
62077 * asm/hardirq.h to get better cache usage. KAO
62078 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62079
62080 struct softirq_action
62081 {
62082 - void (*action)(struct softirq_action *);
62083 + void (*action)(void);
62084 };
62085
62086 asmlinkage void do_softirq(void);
62087 asmlinkage void __do_softirq(void);
62088 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62089 +extern void open_softirq(int nr, void (*action)(void));
62090 extern void softirq_init(void);
62091 static inline void __raise_softirq_irqoff(unsigned int nr)
62092 {
62093 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62094 index 3875719..4cd454c 100644
62095 --- a/include/linux/kallsyms.h
62096 +++ b/include/linux/kallsyms.h
62097 @@ -15,7 +15,8 @@
62098
62099 struct module;
62100
62101 -#ifdef CONFIG_KALLSYMS
62102 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62103 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62104 /* Lookup the address for a symbol. Returns 0 if not found. */
62105 unsigned long kallsyms_lookup_name(const char *name);
62106
62107 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62108 /* Stupid that this does nothing, but I didn't create this mess. */
62109 #define __print_symbol(fmt, addr)
62110 #endif /*CONFIG_KALLSYMS*/
62111 +#else /* when included by kallsyms.c, vsnprintf.c, or
62112 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62113 +extern void __print_symbol(const char *fmt, unsigned long address);
62114 +extern int sprint_backtrace(char *buffer, unsigned long address);
62115 +extern int sprint_symbol(char *buffer, unsigned long address);
62116 +const char *kallsyms_lookup(unsigned long addr,
62117 + unsigned long *symbolsize,
62118 + unsigned long *offset,
62119 + char **modname, char *namebuf);
62120 +#endif
62121
62122 /* This macro allows us to keep printk typechecking */
62123 static __printf(1, 2)
62124 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62125 index c4d2fc1..5df9c19 100644
62126 --- a/include/linux/kgdb.h
62127 +++ b/include/linux/kgdb.h
62128 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62129 extern int kgdb_io_module_registered;
62130
62131 extern atomic_t kgdb_setting_breakpoint;
62132 -extern atomic_t kgdb_cpu_doing_single_step;
62133 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62134
62135 extern struct task_struct *kgdb_usethread;
62136 extern struct task_struct *kgdb_contthread;
62137 @@ -252,7 +252,7 @@ struct kgdb_arch {
62138 void (*disable_hw_break)(struct pt_regs *regs);
62139 void (*remove_all_hw_break)(void);
62140 void (*correct_hw_break)(void);
62141 -};
62142 +} __do_const;
62143
62144 /**
62145 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62146 @@ -277,7 +277,7 @@ struct kgdb_io {
62147 void (*pre_exception) (void);
62148 void (*post_exception) (void);
62149 int is_console;
62150 -};
62151 +} __do_const;
62152
62153 extern struct kgdb_arch arch_kgdb_ops;
62154
62155 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62156 index 0fb48ef..1b680b2 100644
62157 --- a/include/linux/kmod.h
62158 +++ b/include/linux/kmod.h
62159 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62160 * usually useless though. */
62161 extern __printf(2, 3)
62162 int __request_module(bool wait, const char *name, ...);
62163 +extern __printf(3, 4)
62164 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62165 #define request_module(mod...) __request_module(true, mod)
62166 #define request_module_nowait(mod...) __request_module(false, mod)
62167 #define try_then_request_module(x, mod...) \
62168 diff --git a/include/linux/kref.h b/include/linux/kref.h
62169 index 9c07dce..a92fa71 100644
62170 --- a/include/linux/kref.h
62171 +++ b/include/linux/kref.h
62172 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62173 static inline int kref_sub(struct kref *kref, unsigned int count,
62174 void (*release)(struct kref *kref))
62175 {
62176 - WARN_ON(release == NULL);
62177 + BUG_ON(release == NULL);
62178
62179 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62180 release(kref);
62181 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62182 index 900c763..3287a0b 100644
62183 --- a/include/linux/kvm_host.h
62184 +++ b/include/linux/kvm_host.h
62185 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62186 void vcpu_load(struct kvm_vcpu *vcpu);
62187 void vcpu_put(struct kvm_vcpu *vcpu);
62188
62189 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62190 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62191 struct module *module);
62192 void kvm_exit(void);
62193
62194 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
62195 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62196 int len);
62197 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62198 - unsigned long len);
62199 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62200 + unsigned long len) __size_overflow(4);
62201 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62202 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62203 - void *data, unsigned long len);
62204 + void *data, unsigned long len) __size_overflow(4);
62205 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62206 int offset, int len);
62207 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62208 - unsigned long len);
62209 + unsigned long len) __size_overflow(2,4);
62210 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62211 - void *data, unsigned long len);
62212 + void *data, unsigned long len) __size_overflow(4);
62213 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62214 gpa_t gpa);
62215 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62216 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62217 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62218 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62219 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62220 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62221 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62222 struct kvm_guest_debug *dbg);
62223 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62224
62225 -int kvm_arch_init(void *opaque);
62226 +int kvm_arch_init(const void *opaque);
62227 void kvm_arch_exit(void);
62228
62229 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62230 @@ -721,7 +721,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62231 int kvm_set_irq_routing(struct kvm *kvm,
62232 const struct kvm_irq_routing_entry *entries,
62233 unsigned nr,
62234 - unsigned flags);
62235 + unsigned flags) __size_overflow(3);
62236 void kvm_free_irq_routing(struct kvm *kvm);
62237
62238 #else
62239 diff --git a/include/linux/libata.h b/include/linux/libata.h
62240 index cafc09a..d7e7829 100644
62241 --- a/include/linux/libata.h
62242 +++ b/include/linux/libata.h
62243 @@ -909,7 +909,7 @@ struct ata_port_operations {
62244 * fields must be pointers.
62245 */
62246 const struct ata_port_operations *inherits;
62247 -};
62248 +} __do_const;
62249
62250 struct ata_port_info {
62251 unsigned long flags;
62252 diff --git a/include/linux/mca.h b/include/linux/mca.h
62253 index 3797270..7765ede 100644
62254 --- a/include/linux/mca.h
62255 +++ b/include/linux/mca.h
62256 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62257 int region);
62258 void * (*mca_transform_memory)(struct mca_device *,
62259 void *memory);
62260 -};
62261 +} __no_const;
62262
62263 struct mca_bus {
62264 u64 default_dma_mask;
62265 diff --git a/include/linux/memory.h b/include/linux/memory.h
62266 index 1ac7f6e..a5794d0 100644
62267 --- a/include/linux/memory.h
62268 +++ b/include/linux/memory.h
62269 @@ -143,7 +143,7 @@ struct memory_accessor {
62270 size_t count);
62271 ssize_t (*write)(struct memory_accessor *, const char *buf,
62272 off_t offset, size_t count);
62273 -};
62274 +} __no_const;
62275
62276 /*
62277 * Kernel text modification mutex, used for code patching. Users of this lock
62278 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62279 index 9970337..9444122 100644
62280 --- a/include/linux/mfd/abx500.h
62281 +++ b/include/linux/mfd/abx500.h
62282 @@ -188,6 +188,7 @@ struct abx500_ops {
62283 int (*event_registers_startup_state_get) (struct device *, u8 *);
62284 int (*startup_irq_enabled) (struct device *, unsigned int);
62285 };
62286 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62287
62288 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62289 void abx500_remove_ops(struct device *dev);
62290 diff --git a/include/linux/mm.h b/include/linux/mm.h
62291 index 17b27cd..467ba2f 100644
62292 --- a/include/linux/mm.h
62293 +++ b/include/linux/mm.h
62294 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62295
62296 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62297 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62298 +
62299 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62300 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62301 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62302 +#else
62303 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62304 +#endif
62305 +
62306 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62307 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62308
62309 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62310 int set_page_dirty_lock(struct page *page);
62311 int clear_page_dirty_for_io(struct page *page);
62312
62313 -/* Is the vma a continuation of the stack vma above it? */
62314 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62315 -{
62316 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62317 -}
62318 -
62319 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62320 - unsigned long addr)
62321 -{
62322 - return (vma->vm_flags & VM_GROWSDOWN) &&
62323 - (vma->vm_start == addr) &&
62324 - !vma_growsdown(vma->vm_prev, addr);
62325 -}
62326 -
62327 -/* Is the vma a continuation of the stack vma below it? */
62328 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62329 -{
62330 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62331 -}
62332 -
62333 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62334 - unsigned long addr)
62335 -{
62336 - return (vma->vm_flags & VM_GROWSUP) &&
62337 - (vma->vm_end == addr) &&
62338 - !vma_growsup(vma->vm_next, addr);
62339 -}
62340 -
62341 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62342 unsigned long old_addr, struct vm_area_struct *new_vma,
62343 unsigned long new_addr, unsigned long len);
62344 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62345 }
62346 #endif
62347
62348 +#ifdef CONFIG_MMU
62349 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62350 +#else
62351 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62352 +{
62353 + return __pgprot(0);
62354 +}
62355 +#endif
62356 +
62357 int vma_wants_writenotify(struct vm_area_struct *vma);
62358
62359 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62360 @@ -1409,6 +1397,7 @@ out:
62361 }
62362
62363 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62364 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62365
62366 extern unsigned long do_brk(unsigned long, unsigned long);
62367
62368 @@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62369 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62370 struct vm_area_struct **pprev);
62371
62372 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62373 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62374 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62375 +
62376 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62377 NULL if none. Assume start_addr < end_addr. */
62378 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62379 @@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62380 return vma;
62381 }
62382
62383 -#ifdef CONFIG_MMU
62384 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62385 -#else
62386 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62387 -{
62388 - return __pgprot(0);
62389 -}
62390 -#endif
62391 -
62392 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62393 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62394 unsigned long pfn, unsigned long size, pgprot_t);
62395 @@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
62396 extern int sysctl_memory_failure_early_kill;
62397 extern int sysctl_memory_failure_recovery;
62398 extern void shake_page(struct page *p, int access);
62399 -extern atomic_long_t mce_bad_pages;
62400 +extern atomic_long_unchecked_t mce_bad_pages;
62401 extern int soft_offline_page(struct page *page, int flags);
62402
62403 extern void dump_page(struct page *page);
62404 @@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62405 static inline bool page_is_guard(struct page *page) { return false; }
62406 #endif /* CONFIG_DEBUG_PAGEALLOC */
62407
62408 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62409 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62410 +#else
62411 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62412 +#endif
62413 +
62414 #endif /* __KERNEL__ */
62415 #endif /* _LINUX_MM_H */
62416 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62417 index 3cc3062..efeaeb7 100644
62418 --- a/include/linux/mm_types.h
62419 +++ b/include/linux/mm_types.h
62420 @@ -252,6 +252,8 @@ struct vm_area_struct {
62421 #ifdef CONFIG_NUMA
62422 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62423 #endif
62424 +
62425 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62426 };
62427
62428 struct core_thread {
62429 @@ -326,7 +328,7 @@ struct mm_struct {
62430 unsigned long def_flags;
62431 unsigned long nr_ptes; /* Page table pages */
62432 unsigned long start_code, end_code, start_data, end_data;
62433 - unsigned long start_brk, brk, start_stack;
62434 + unsigned long brk_gap, start_brk, brk, start_stack;
62435 unsigned long arg_start, arg_end, env_start, env_end;
62436
62437 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62438 @@ -388,6 +390,24 @@ struct mm_struct {
62439 #ifdef CONFIG_CPUMASK_OFFSTACK
62440 struct cpumask cpumask_allocation;
62441 #endif
62442 +
62443 +#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)
62444 + unsigned long pax_flags;
62445 +#endif
62446 +
62447 +#ifdef CONFIG_PAX_DLRESOLVE
62448 + unsigned long call_dl_resolve;
62449 +#endif
62450 +
62451 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62452 + unsigned long call_syscall;
62453 +#endif
62454 +
62455 +#ifdef CONFIG_PAX_ASLR
62456 + unsigned long delta_mmap; /* randomized offset */
62457 + unsigned long delta_stack; /* randomized offset */
62458 +#endif
62459 +
62460 };
62461
62462 static inline void mm_init_cpumask(struct mm_struct *mm)
62463 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62464 index 1d1b1e1..2a13c78 100644
62465 --- a/include/linux/mmu_notifier.h
62466 +++ b/include/linux/mmu_notifier.h
62467 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62468 */
62469 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62470 ({ \
62471 - pte_t __pte; \
62472 + pte_t ___pte; \
62473 struct vm_area_struct *___vma = __vma; \
62474 unsigned long ___address = __address; \
62475 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62476 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62477 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62478 - __pte; \
62479 + ___pte; \
62480 })
62481
62482 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62483 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62484 index 650ba2f..af0a58c 100644
62485 --- a/include/linux/mmzone.h
62486 +++ b/include/linux/mmzone.h
62487 @@ -379,7 +379,7 @@ struct zone {
62488 unsigned long flags; /* zone flags, see below */
62489
62490 /* Zone statistics */
62491 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62492 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62493
62494 /*
62495 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62496 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62497 index 83ac071..2656e0e 100644
62498 --- a/include/linux/mod_devicetable.h
62499 +++ b/include/linux/mod_devicetable.h
62500 @@ -12,7 +12,7 @@
62501 typedef unsigned long kernel_ulong_t;
62502 #endif
62503
62504 -#define PCI_ANY_ID (~0)
62505 +#define PCI_ANY_ID ((__u16)~0)
62506
62507 struct pci_device_id {
62508 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62509 @@ -131,7 +131,7 @@ struct usb_device_id {
62510 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62511 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62512
62513 -#define HID_ANY_ID (~0)
62514 +#define HID_ANY_ID (~0U)
62515
62516 struct hid_device_id {
62517 __u16 bus;
62518 diff --git a/include/linux/module.h b/include/linux/module.h
62519 index 4598bf0..e069d7f 100644
62520 --- a/include/linux/module.h
62521 +++ b/include/linux/module.h
62522 @@ -17,6 +17,7 @@
62523 #include <linux/moduleparam.h>
62524 #include <linux/tracepoint.h>
62525 #include <linux/export.h>
62526 +#include <linux/fs.h>
62527
62528 #include <linux/percpu.h>
62529 #include <asm/module.h>
62530 @@ -275,19 +276,16 @@ struct module
62531 int (*init)(void);
62532
62533 /* If this is non-NULL, vfree after init() returns */
62534 - void *module_init;
62535 + void *module_init_rx, *module_init_rw;
62536
62537 /* Here is the actual code + data, vfree'd on unload. */
62538 - void *module_core;
62539 + void *module_core_rx, *module_core_rw;
62540
62541 /* Here are the sizes of the init and core sections */
62542 - unsigned int init_size, core_size;
62543 + unsigned int init_size_rw, core_size_rw;
62544
62545 /* The size of the executable code in each section. */
62546 - unsigned int init_text_size, core_text_size;
62547 -
62548 - /* Size of RO sections of the module (text+rodata) */
62549 - unsigned int init_ro_size, core_ro_size;
62550 + unsigned int init_size_rx, core_size_rx;
62551
62552 /* Arch-specific module values */
62553 struct mod_arch_specific arch;
62554 @@ -343,6 +341,10 @@ struct module
62555 #ifdef CONFIG_EVENT_TRACING
62556 struct ftrace_event_call **trace_events;
62557 unsigned int num_trace_events;
62558 + struct file_operations trace_id;
62559 + struct file_operations trace_enable;
62560 + struct file_operations trace_format;
62561 + struct file_operations trace_filter;
62562 #endif
62563 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62564 unsigned int num_ftrace_callsites;
62565 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62566 bool is_module_percpu_address(unsigned long addr);
62567 bool is_module_text_address(unsigned long addr);
62568
62569 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62570 +{
62571 +
62572 +#ifdef CONFIG_PAX_KERNEXEC
62573 + if (ktla_ktva(addr) >= (unsigned long)start &&
62574 + ktla_ktva(addr) < (unsigned long)start + size)
62575 + return 1;
62576 +#endif
62577 +
62578 + return ((void *)addr >= start && (void *)addr < start + size);
62579 +}
62580 +
62581 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62582 +{
62583 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62584 +}
62585 +
62586 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62587 +{
62588 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62589 +}
62590 +
62591 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62592 +{
62593 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62594 +}
62595 +
62596 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62597 +{
62598 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62599 +}
62600 +
62601 static inline int within_module_core(unsigned long addr, struct module *mod)
62602 {
62603 - return (unsigned long)mod->module_core <= addr &&
62604 - addr < (unsigned long)mod->module_core + mod->core_size;
62605 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62606 }
62607
62608 static inline int within_module_init(unsigned long addr, struct module *mod)
62609 {
62610 - return (unsigned long)mod->module_init <= addr &&
62611 - addr < (unsigned long)mod->module_init + mod->init_size;
62612 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62613 }
62614
62615 /* Search for module by name: must hold module_mutex. */
62616 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62617 index b2be02e..72d2f78 100644
62618 --- a/include/linux/moduleloader.h
62619 +++ b/include/linux/moduleloader.h
62620 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62621
62622 /* Allocator used for allocating struct module, core sections and init
62623 sections. Returns NULL on failure. */
62624 -void *module_alloc(unsigned long size);
62625 +void *module_alloc(unsigned long size) __size_overflow(1);
62626 +
62627 +#ifdef CONFIG_PAX_KERNEXEC
62628 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62629 +#else
62630 +#define module_alloc_exec(x) module_alloc(x)
62631 +#endif
62632
62633 /* Free memory returned from module_alloc. */
62634 void module_free(struct module *mod, void *module_region);
62635
62636 +#ifdef CONFIG_PAX_KERNEXEC
62637 +void module_free_exec(struct module *mod, void *module_region);
62638 +#else
62639 +#define module_free_exec(x, y) module_free((x), (y))
62640 +#endif
62641 +
62642 /* Apply the given relocation to the (simplified) ELF. Return -error
62643 or 0. */
62644 int apply_relocate(Elf_Shdr *sechdrs,
62645 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62646 index c47f4d6..23f9bdb 100644
62647 --- a/include/linux/moduleparam.h
62648 +++ b/include/linux/moduleparam.h
62649 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62650 * @len is usually just sizeof(string).
62651 */
62652 #define module_param_string(name, string, len, perm) \
62653 - static const struct kparam_string __param_string_##name \
62654 + static const struct kparam_string __param_string_##name __used \
62655 = { len, string }; \
62656 __module_param_call(MODULE_PARAM_PREFIX, name, \
62657 &param_ops_string, \
62658 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62659 */
62660 #define module_param_array_named(name, array, type, nump, perm) \
62661 param_check_##type(name, &(array)[0]); \
62662 - static const struct kparam_array __param_arr_##name \
62663 + static const struct kparam_array __param_arr_##name __used \
62664 = { .max = ARRAY_SIZE(array), .num = nump, \
62665 .ops = &param_ops_##type, \
62666 .elemsize = sizeof(array[0]), .elem = array }; \
62667 diff --git a/include/linux/namei.h b/include/linux/namei.h
62668 index ffc0213..2c1f2cb 100644
62669 --- a/include/linux/namei.h
62670 +++ b/include/linux/namei.h
62671 @@ -24,7 +24,7 @@ struct nameidata {
62672 unsigned seq;
62673 int last_type;
62674 unsigned depth;
62675 - char *saved_names[MAX_NESTED_LINKS + 1];
62676 + const char *saved_names[MAX_NESTED_LINKS + 1];
62677
62678 /* Intent data */
62679 union {
62680 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62681 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62682 extern void unlock_rename(struct dentry *, struct dentry *);
62683
62684 -static inline void nd_set_link(struct nameidata *nd, char *path)
62685 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62686 {
62687 nd->saved_names[nd->depth] = path;
62688 }
62689
62690 -static inline char *nd_get_link(struct nameidata *nd)
62691 +static inline const char *nd_get_link(const struct nameidata *nd)
62692 {
62693 return nd->saved_names[nd->depth];
62694 }
62695 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62696 index 0eac07c..a59f6a8 100644
62697 --- a/include/linux/netdevice.h
62698 +++ b/include/linux/netdevice.h
62699 @@ -1002,6 +1002,7 @@ struct net_device_ops {
62700 int (*ndo_neigh_construct)(struct neighbour *n);
62701 void (*ndo_neigh_destroy)(struct neighbour *n);
62702 };
62703 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62704
62705 /*
62706 * The DEVICE structure.
62707 @@ -1063,7 +1064,7 @@ struct net_device {
62708 int iflink;
62709
62710 struct net_device_stats stats;
62711 - atomic_long_t rx_dropped; /* dropped packets by core network
62712 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62713 * Do not use this in drivers.
62714 */
62715
62716 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62717 new file mode 100644
62718 index 0000000..33f4af8
62719 --- /dev/null
62720 +++ b/include/linux/netfilter/xt_gradm.h
62721 @@ -0,0 +1,9 @@
62722 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62723 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62724 +
62725 +struct xt_gradm_mtinfo {
62726 + __u16 flags;
62727 + __u16 invflags;
62728 +};
62729 +
62730 +#endif
62731 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62732 index c65a18a..0c05f3a 100644
62733 --- a/include/linux/of_pdt.h
62734 +++ b/include/linux/of_pdt.h
62735 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62736
62737 /* return 0 on success; fill in 'len' with number of bytes in path */
62738 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62739 -};
62740 +} __no_const;
62741
62742 extern void *prom_early_alloc(unsigned long size);
62743
62744 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62745 index a4c5624..2dabfb7 100644
62746 --- a/include/linux/oprofile.h
62747 +++ b/include/linux/oprofile.h
62748 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62749 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62750 char const * name, ulong * val);
62751
62752 -/** Create a file for read-only access to an atomic_t. */
62753 +/** Create a file for read-only access to an atomic_unchecked_t. */
62754 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62755 - char const * name, atomic_t * val);
62756 + char const * name, atomic_unchecked_t * val);
62757
62758 /** create a directory */
62759 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62760 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
62761 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
62762 * Returns 0 on success, < 0 on error.
62763 */
62764 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
62765 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
62766
62767 /** lock for read/write safety */
62768 extern raw_spinlock_t oprofilefs_lock;
62769 diff --git a/include/linux/padata.h b/include/linux/padata.h
62770 index 4633b2f..988bc08 100644
62771 --- a/include/linux/padata.h
62772 +++ b/include/linux/padata.h
62773 @@ -129,7 +129,7 @@ struct parallel_data {
62774 struct padata_instance *pinst;
62775 struct padata_parallel_queue __percpu *pqueue;
62776 struct padata_serial_queue __percpu *squeue;
62777 - atomic_t seq_nr;
62778 + atomic_unchecked_t seq_nr;
62779 atomic_t reorder_objects;
62780 atomic_t refcnt;
62781 unsigned int max_seq_nr;
62782 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62783 index abb2776..d8b8e15 100644
62784 --- a/include/linux/perf_event.h
62785 +++ b/include/linux/perf_event.h
62786 @@ -750,8 +750,8 @@ struct perf_event {
62787
62788 enum perf_event_active_state state;
62789 unsigned int attach_state;
62790 - local64_t count;
62791 - atomic64_t child_count;
62792 + local64_t count; /* PaX: fix it one day */
62793 + atomic64_unchecked_t child_count;
62794
62795 /*
62796 * These are the total time in nanoseconds that the event
62797 @@ -802,8 +802,8 @@ struct perf_event {
62798 * These accumulate total time (in nanoseconds) that children
62799 * events have been enabled and running, respectively.
62800 */
62801 - atomic64_t child_total_time_enabled;
62802 - atomic64_t child_total_time_running;
62803 + atomic64_unchecked_t child_total_time_enabled;
62804 + atomic64_unchecked_t child_total_time_running;
62805
62806 /*
62807 * Protect attach/detach and child_list:
62808 diff --git a/include/linux/personality.h b/include/linux/personality.h
62809 index 8fc7dd1a..c19d89e 100644
62810 --- a/include/linux/personality.h
62811 +++ b/include/linux/personality.h
62812 @@ -44,6 +44,7 @@ enum {
62813 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62814 ADDR_NO_RANDOMIZE | \
62815 ADDR_COMPAT_LAYOUT | \
62816 + ADDR_LIMIT_3GB | \
62817 MMAP_PAGE_ZERO)
62818
62819 /*
62820 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62821 index 77257c9..51d473a 100644
62822 --- a/include/linux/pipe_fs_i.h
62823 +++ b/include/linux/pipe_fs_i.h
62824 @@ -46,9 +46,9 @@ struct pipe_buffer {
62825 struct pipe_inode_info {
62826 wait_queue_head_t wait;
62827 unsigned int nrbufs, curbuf, buffers;
62828 - unsigned int readers;
62829 - unsigned int writers;
62830 - unsigned int waiting_writers;
62831 + atomic_t readers;
62832 + atomic_t writers;
62833 + atomic_t waiting_writers;
62834 unsigned int r_counter;
62835 unsigned int w_counter;
62836 struct page *tmp_page;
62837 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62838 index 609daae..5392427 100644
62839 --- a/include/linux/pm_runtime.h
62840 +++ b/include/linux/pm_runtime.h
62841 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62842
62843 static inline void pm_runtime_mark_last_busy(struct device *dev)
62844 {
62845 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62846 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62847 }
62848
62849 #else /* !CONFIG_PM_RUNTIME */
62850 diff --git a/include/linux/poison.h b/include/linux/poison.h
62851 index 2110a81..13a11bb 100644
62852 --- a/include/linux/poison.h
62853 +++ b/include/linux/poison.h
62854 @@ -19,8 +19,8 @@
62855 * under normal circumstances, used to verify that nobody uses
62856 * non-initialized list entries.
62857 */
62858 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62859 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62860 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62861 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62862
62863 /********** include/linux/timer.h **********/
62864 /*
62865 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62866 index 58969b2..ead129b 100644
62867 --- a/include/linux/preempt.h
62868 +++ b/include/linux/preempt.h
62869 @@ -123,7 +123,7 @@ struct preempt_ops {
62870 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62871 void (*sched_out)(struct preempt_notifier *notifier,
62872 struct task_struct *next);
62873 -};
62874 +} __no_const;
62875
62876 /**
62877 * preempt_notifier - key for installing preemption notifiers
62878 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62879 index 85c5073..51fac8b 100644
62880 --- a/include/linux/proc_fs.h
62881 +++ b/include/linux/proc_fs.h
62882 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62883 return proc_create_data(name, mode, parent, proc_fops, NULL);
62884 }
62885
62886 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62887 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62888 +{
62889 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62890 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62891 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62892 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62893 +#else
62894 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62895 +#endif
62896 +}
62897 +
62898 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62899 umode_t mode, struct proc_dir_entry *base,
62900 read_proc_t *read_proc, void * data)
62901 @@ -258,7 +270,7 @@ union proc_op {
62902 int (*proc_show)(struct seq_file *m,
62903 struct pid_namespace *ns, struct pid *pid,
62904 struct task_struct *task);
62905 -};
62906 +} __no_const;
62907
62908 struct ctl_table_header;
62909 struct ctl_table;
62910 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62911 index c2f1f6a..6fdb196 100644
62912 --- a/include/linux/ptrace.h
62913 +++ b/include/linux/ptrace.h
62914 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62915 if (unlikely(ptrace_event_enabled(current, event))) {
62916 current->ptrace_message = message;
62917 ptrace_notify((event << 8) | SIGTRAP);
62918 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62919 + } else if (event == PTRACE_EVENT_EXEC) {
62920 /* legacy EXEC report via SIGTRAP */
62921 - send_sig(SIGTRAP, current, 0);
62922 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62923 + send_sig(SIGTRAP, current, 0);
62924 }
62925 }
62926
62927 diff --git a/include/linux/random.h b/include/linux/random.h
62928 index 8f74538..02a1012 100644
62929 --- a/include/linux/random.h
62930 +++ b/include/linux/random.h
62931 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62932
62933 u32 prandom32(struct rnd_state *);
62934
62935 +static inline unsigned long pax_get_random_long(void)
62936 +{
62937 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62938 +}
62939 +
62940 /*
62941 * Handle minimum values for seeds
62942 */
62943 static inline u32 __seed(u32 x, u32 m)
62944 {
62945 - return (x < m) ? x + m : x;
62946 + return (x <= m) ? x + m + 1 : x;
62947 }
62948
62949 /**
62950 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62951 index e0879a7..a12f962 100644
62952 --- a/include/linux/reboot.h
62953 +++ b/include/linux/reboot.h
62954 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62955 * Architecture-specific implementations of sys_reboot commands.
62956 */
62957
62958 -extern void machine_restart(char *cmd);
62959 -extern void machine_halt(void);
62960 -extern void machine_power_off(void);
62961 +extern void machine_restart(char *cmd) __noreturn;
62962 +extern void machine_halt(void) __noreturn;
62963 +extern void machine_power_off(void) __noreturn;
62964
62965 extern void machine_shutdown(void);
62966 struct pt_regs;
62967 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62968 */
62969
62970 extern void kernel_restart_prepare(char *cmd);
62971 -extern void kernel_restart(char *cmd);
62972 -extern void kernel_halt(void);
62973 -extern void kernel_power_off(void);
62974 +extern void kernel_restart(char *cmd) __noreturn;
62975 +extern void kernel_halt(void) __noreturn;
62976 +extern void kernel_power_off(void) __noreturn;
62977
62978 extern int C_A_D; /* for sysctl */
62979 void ctrl_alt_del(void);
62980 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62981 * Emergency restart, callable from an interrupt handler.
62982 */
62983
62984 -extern void emergency_restart(void);
62985 +extern void emergency_restart(void) __noreturn;
62986 #include <asm/emergency-restart.h>
62987
62988 #endif
62989 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62990 index 2213ddc..650212a 100644
62991 --- a/include/linux/reiserfs_fs.h
62992 +++ b/include/linux/reiserfs_fs.h
62993 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
62994 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
62995
62996 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
62997 -#define get_generation(s) atomic_read (&fs_generation(s))
62998 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
62999 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63000 #define __fs_changed(gen,s) (gen != get_generation (s))
63001 #define fs_changed(gen,s) \
63002 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63003 index 8c9e85c..1698e9a 100644
63004 --- a/include/linux/reiserfs_fs_sb.h
63005 +++ b/include/linux/reiserfs_fs_sb.h
63006 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63007 /* Comment? -Hans */
63008 wait_queue_head_t s_wait;
63009 /* To be obsoleted soon by per buffer seals.. -Hans */
63010 - atomic_t s_generation_counter; // increased by one every time the
63011 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63012 // tree gets re-balanced
63013 unsigned long s_properties; /* File system properties. Currently holds
63014 on-disk FS format */
63015 diff --git a/include/linux/relay.h b/include/linux/relay.h
63016 index a822fd7..62b70f6 100644
63017 --- a/include/linux/relay.h
63018 +++ b/include/linux/relay.h
63019 @@ -159,7 +159,7 @@ struct rchan_callbacks
63020 * The callback should return 0 if successful, negative if not.
63021 */
63022 int (*remove_buf_file)(struct dentry *dentry);
63023 -};
63024 +} __no_const;
63025
63026 /*
63027 * CONFIG_RELAY kernel API, kernel/relay.c
63028 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63029 index c6c6084..5bf1212 100644
63030 --- a/include/linux/rfkill.h
63031 +++ b/include/linux/rfkill.h
63032 @@ -147,6 +147,7 @@ struct rfkill_ops {
63033 void (*query)(struct rfkill *rfkill, void *data);
63034 int (*set_block)(void *data, bool blocked);
63035 };
63036 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63037
63038 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63039 /**
63040 diff --git a/include/linux/rio.h b/include/linux/rio.h
63041 index 4d50611..c6858a2 100644
63042 --- a/include/linux/rio.h
63043 +++ b/include/linux/rio.h
63044 @@ -315,7 +315,7 @@ struct rio_ops {
63045 int mbox, void *buffer, size_t len);
63046 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63047 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63048 -};
63049 +} __no_const;
63050
63051 #define RIO_RESOURCE_MEM 0x00000100
63052 #define RIO_RESOURCE_DOORBELL 0x00000200
63053 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63054 index 1cdd62a..e399f0d 100644
63055 --- a/include/linux/rmap.h
63056 +++ b/include/linux/rmap.h
63057 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63058 void anon_vma_init(void); /* create anon_vma_cachep */
63059 int anon_vma_prepare(struct vm_area_struct *);
63060 void unlink_anon_vmas(struct vm_area_struct *);
63061 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63062 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63063 void anon_vma_moveto_tail(struct vm_area_struct *);
63064 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63065 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63066 void __anon_vma_link(struct vm_area_struct *);
63067
63068 static inline void anon_vma_merge(struct vm_area_struct *vma,
63069 diff --git a/include/linux/sched.h b/include/linux/sched.h
63070 index 0657368..765f70f 100644
63071 --- a/include/linux/sched.h
63072 +++ b/include/linux/sched.h
63073 @@ -101,6 +101,7 @@ struct bio_list;
63074 struct fs_struct;
63075 struct perf_event_context;
63076 struct blk_plug;
63077 +struct linux_binprm;
63078
63079 /*
63080 * List of flags we want to share for kernel threads,
63081 @@ -382,10 +383,13 @@ struct user_namespace;
63082 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63083
63084 extern int sysctl_max_map_count;
63085 +extern unsigned long sysctl_heap_stack_gap;
63086
63087 #include <linux/aio.h>
63088
63089 #ifdef CONFIG_MMU
63090 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63091 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63092 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63093 extern unsigned long
63094 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63095 @@ -631,6 +635,17 @@ struct signal_struct {
63096 #ifdef CONFIG_TASKSTATS
63097 struct taskstats *stats;
63098 #endif
63099 +
63100 +#ifdef CONFIG_GRKERNSEC
63101 + u32 curr_ip;
63102 + u32 saved_ip;
63103 + u32 gr_saddr;
63104 + u32 gr_daddr;
63105 + u16 gr_sport;
63106 + u16 gr_dport;
63107 + u8 used_accept:1;
63108 +#endif
63109 +
63110 #ifdef CONFIG_AUDIT
63111 unsigned audit_tty;
63112 struct tty_audit_buf *tty_audit_buf;
63113 @@ -714,6 +729,11 @@ struct user_struct {
63114 struct key *session_keyring; /* UID's default session keyring */
63115 #endif
63116
63117 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63118 + unsigned int banned;
63119 + unsigned long ban_expires;
63120 +#endif
63121 +
63122 /* Hash table maintenance information */
63123 struct hlist_node uidhash_node;
63124 uid_t uid;
63125 @@ -1354,8 +1374,8 @@ struct task_struct {
63126 struct list_head thread_group;
63127
63128 struct completion *vfork_done; /* for vfork() */
63129 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63130 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63131 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63132 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63133
63134 cputime_t utime, stime, utimescaled, stimescaled;
63135 cputime_t gtime;
63136 @@ -1371,13 +1391,6 @@ struct task_struct {
63137 struct task_cputime cputime_expires;
63138 struct list_head cpu_timers[3];
63139
63140 -/* process credentials */
63141 - const struct cred __rcu *real_cred; /* objective and real subjective task
63142 - * credentials (COW) */
63143 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63144 - * credentials (COW) */
63145 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63146 -
63147 char comm[TASK_COMM_LEN]; /* executable name excluding path
63148 - access with [gs]et_task_comm (which lock
63149 it with task_lock())
63150 @@ -1394,8 +1407,16 @@ struct task_struct {
63151 #endif
63152 /* CPU-specific state of this task */
63153 struct thread_struct thread;
63154 +/* thread_info moved to task_struct */
63155 +#ifdef CONFIG_X86
63156 + struct thread_info tinfo;
63157 +#endif
63158 /* filesystem information */
63159 struct fs_struct *fs;
63160 +
63161 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63162 + * credentials (COW) */
63163 +
63164 /* open file information */
63165 struct files_struct *files;
63166 /* namespaces */
63167 @@ -1442,6 +1463,11 @@ struct task_struct {
63168 struct rt_mutex_waiter *pi_blocked_on;
63169 #endif
63170
63171 +/* process credentials */
63172 + const struct cred __rcu *real_cred; /* objective and real subjective task
63173 + * credentials (COW) */
63174 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63175 +
63176 #ifdef CONFIG_DEBUG_MUTEXES
63177 /* mutex deadlock detection */
63178 struct mutex_waiter *blocked_on;
63179 @@ -1558,6 +1584,27 @@ struct task_struct {
63180 unsigned long default_timer_slack_ns;
63181
63182 struct list_head *scm_work_list;
63183 +
63184 +#ifdef CONFIG_GRKERNSEC
63185 + /* grsecurity */
63186 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63187 + u64 exec_id;
63188 +#endif
63189 +#ifdef CONFIG_GRKERNSEC_SETXID
63190 + const struct cred *delayed_cred;
63191 +#endif
63192 + struct dentry *gr_chroot_dentry;
63193 + struct acl_subject_label *acl;
63194 + struct acl_role_label *role;
63195 + struct file *exec_file;
63196 + u16 acl_role_id;
63197 + /* is this the task that authenticated to the special role */
63198 + u8 acl_sp_role;
63199 + u8 is_writable;
63200 + u8 brute;
63201 + u8 gr_is_chrooted;
63202 +#endif
63203 +
63204 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63205 /* Index of current stored address in ret_stack */
63206 int curr_ret_stack;
63207 @@ -1592,6 +1639,51 @@ struct task_struct {
63208 #endif
63209 };
63210
63211 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63212 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63213 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63214 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63215 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63216 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63217 +
63218 +#ifdef CONFIG_PAX_SOFTMODE
63219 +extern int pax_softmode;
63220 +#endif
63221 +
63222 +extern int pax_check_flags(unsigned long *);
63223 +
63224 +/* if tsk != current then task_lock must be held on it */
63225 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63226 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63227 +{
63228 + if (likely(tsk->mm))
63229 + return tsk->mm->pax_flags;
63230 + else
63231 + return 0UL;
63232 +}
63233 +
63234 +/* if tsk != current then task_lock must be held on it */
63235 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63236 +{
63237 + if (likely(tsk->mm)) {
63238 + tsk->mm->pax_flags = flags;
63239 + return 0;
63240 + }
63241 + return -EINVAL;
63242 +}
63243 +#endif
63244 +
63245 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63246 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63247 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63248 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63249 +#endif
63250 +
63251 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63252 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63253 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63254 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63255 +
63256 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63257 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63258
63259 @@ -2104,7 +2196,9 @@ void yield(void);
63260 extern struct exec_domain default_exec_domain;
63261
63262 union thread_union {
63263 +#ifndef CONFIG_X86
63264 struct thread_info thread_info;
63265 +#endif
63266 unsigned long stack[THREAD_SIZE/sizeof(long)];
63267 };
63268
63269 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63270 */
63271
63272 extern struct task_struct *find_task_by_vpid(pid_t nr);
63273 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63274 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63275 struct pid_namespace *ns);
63276
63277 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63278 extern void exit_itimers(struct signal_struct *);
63279 extern void flush_itimer_signals(void);
63280
63281 -extern void do_group_exit(int);
63282 +extern __noreturn void do_group_exit(int);
63283
63284 extern void daemonize(const char *, ...);
63285 extern int allow_signal(int);
63286 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63287
63288 #endif
63289
63290 -static inline int object_is_on_stack(void *obj)
63291 +static inline int object_starts_on_stack(void *obj)
63292 {
63293 - void *stack = task_stack_page(current);
63294 + const void *stack = task_stack_page(current);
63295
63296 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63297 }
63298
63299 +#ifdef CONFIG_PAX_USERCOPY
63300 +extern int object_is_on_stack(const void *obj, unsigned long len);
63301 +#endif
63302 +
63303 extern void thread_info_cache_init(void);
63304
63305 #ifdef CONFIG_DEBUG_STACK_USAGE
63306 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63307 index 899fbb4..1cb4138 100644
63308 --- a/include/linux/screen_info.h
63309 +++ b/include/linux/screen_info.h
63310 @@ -43,7 +43,8 @@ struct screen_info {
63311 __u16 pages; /* 0x32 */
63312 __u16 vesa_attributes; /* 0x34 */
63313 __u32 capabilities; /* 0x36 */
63314 - __u8 _reserved[6]; /* 0x3a */
63315 + __u16 vesapm_size; /* 0x3a */
63316 + __u8 _reserved[4]; /* 0x3c */
63317 } __attribute__((packed));
63318
63319 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63320 diff --git a/include/linux/security.h b/include/linux/security.h
63321 index 83c18e8..2d98860 100644
63322 --- a/include/linux/security.h
63323 +++ b/include/linux/security.h
63324 @@ -37,6 +37,7 @@
63325 #include <linux/xfrm.h>
63326 #include <linux/slab.h>
63327 #include <linux/xattr.h>
63328 +#include <linux/grsecurity.h>
63329 #include <net/flow.h>
63330
63331 /* Maximum number of letters for an LSM name string */
63332 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63333 index 44f1514..2bbf6c1 100644
63334 --- a/include/linux/seq_file.h
63335 +++ b/include/linux/seq_file.h
63336 @@ -24,6 +24,9 @@ struct seq_file {
63337 struct mutex lock;
63338 const struct seq_operations *op;
63339 int poll_event;
63340 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63341 + u64 exec_id;
63342 +#endif
63343 void *private;
63344 };
63345
63346 @@ -33,6 +36,7 @@ struct seq_operations {
63347 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63348 int (*show) (struct seq_file *m, void *v);
63349 };
63350 +typedef struct seq_operations __no_const seq_operations_no_const;
63351
63352 #define SEQ_SKIP 1
63353
63354 diff --git a/include/linux/shm.h b/include/linux/shm.h
63355 index 92808b8..c28cac4 100644
63356 --- a/include/linux/shm.h
63357 +++ b/include/linux/shm.h
63358 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63359
63360 /* The task created the shm object. NULL if the task is dead. */
63361 struct task_struct *shm_creator;
63362 +#ifdef CONFIG_GRKERNSEC
63363 + time_t shm_createtime;
63364 + pid_t shm_lapid;
63365 +#endif
63366 };
63367
63368 /* shm_mode upper byte flags */
63369 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63370 index ae86ade..2b51468 100644
63371 --- a/include/linux/skbuff.h
63372 +++ b/include/linux/skbuff.h
63373 @@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63374 */
63375 static inline int skb_queue_empty(const struct sk_buff_head *list)
63376 {
63377 - return list->next == (struct sk_buff *)list;
63378 + return list->next == (const struct sk_buff *)list;
63379 }
63380
63381 /**
63382 @@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63383 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63384 const struct sk_buff *skb)
63385 {
63386 - return skb->next == (struct sk_buff *)list;
63387 + return skb->next == (const struct sk_buff *)list;
63388 }
63389
63390 /**
63391 @@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63392 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63393 const struct sk_buff *skb)
63394 {
63395 - return skb->prev == (struct sk_buff *)list;
63396 + return skb->prev == (const struct sk_buff *)list;
63397 }
63398
63399 /**
63400 @@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63401 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63402 */
63403 #ifndef NET_SKB_PAD
63404 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63405 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63406 #endif
63407
63408 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63409 diff --git a/include/linux/slab.h b/include/linux/slab.h
63410 index 573c809..07e1f43 100644
63411 --- a/include/linux/slab.h
63412 +++ b/include/linux/slab.h
63413 @@ -11,12 +11,20 @@
63414
63415 #include <linux/gfp.h>
63416 #include <linux/types.h>
63417 +#include <linux/err.h>
63418
63419 /*
63420 * Flags to pass to kmem_cache_create().
63421 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63422 */
63423 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63424 +
63425 +#ifdef CONFIG_PAX_USERCOPY
63426 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63427 +#else
63428 +#define SLAB_USERCOPY 0x00000000UL
63429 +#endif
63430 +
63431 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63432 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63433 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63434 @@ -87,10 +95,13 @@
63435 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63436 * Both make kfree a no-op.
63437 */
63438 -#define ZERO_SIZE_PTR ((void *)16)
63439 +#define ZERO_SIZE_PTR \
63440 +({ \
63441 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63442 + (void *)(-MAX_ERRNO-1L); \
63443 +})
63444
63445 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63446 - (unsigned long)ZERO_SIZE_PTR)
63447 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63448
63449 /*
63450 * struct kmem_cache related prototypes
63451 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63452 /*
63453 * Common kmalloc functions provided by all allocators
63454 */
63455 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63456 -void * __must_check krealloc(const void *, size_t, gfp_t);
63457 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63458 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63459 void kfree(const void *);
63460 void kzfree(const void *);
63461 size_t ksize(const void *);
63462 +void check_object_size(const void *ptr, unsigned long n, bool to);
63463
63464 /*
63465 * Allocator specific definitions. These are mainly used to establish optimized
63466 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63467 */
63468 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63469 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63470 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63471 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63472 #define kmalloc_track_caller(size, flags) \
63473 __kmalloc_track_caller(size, flags, _RET_IP_)
63474 #else
63475 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63476 */
63477 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63478 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63479 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63480 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63481 #define kmalloc_node_track_caller(size, flags, node) \
63482 __kmalloc_node_track_caller(size, flags, node, \
63483 _RET_IP_)
63484 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63485 index fbd1117..c0bd874 100644
63486 --- a/include/linux/slab_def.h
63487 +++ b/include/linux/slab_def.h
63488 @@ -66,10 +66,10 @@ struct kmem_cache {
63489 unsigned long node_allocs;
63490 unsigned long node_frees;
63491 unsigned long node_overflow;
63492 - atomic_t allochit;
63493 - atomic_t allocmiss;
63494 - atomic_t freehit;
63495 - atomic_t freemiss;
63496 + atomic_unchecked_t allochit;
63497 + atomic_unchecked_t allocmiss;
63498 + atomic_unchecked_t freehit;
63499 + atomic_unchecked_t freemiss;
63500
63501 /*
63502 * If debugging is enabled, then the allocator can add additional
63503 @@ -107,7 +107,7 @@ struct cache_sizes {
63504 extern struct cache_sizes malloc_sizes[];
63505
63506 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63507 -void *__kmalloc(size_t size, gfp_t flags);
63508 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63509
63510 #ifdef CONFIG_TRACING
63511 extern void *kmem_cache_alloc_trace(size_t size,
63512 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63513 }
63514 #endif
63515
63516 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63517 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63518 {
63519 struct kmem_cache *cachep;
63520 @@ -160,7 +161,7 @@ found:
63521 }
63522
63523 #ifdef CONFIG_NUMA
63524 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63525 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63526 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63527
63528 #ifdef CONFIG_TRACING
63529 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
63530 }
63531 #endif
63532
63533 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63534 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63535 {
63536 struct kmem_cache *cachep;
63537 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63538 index 0ec00b3..65e7e0e 100644
63539 --- a/include/linux/slob_def.h
63540 +++ b/include/linux/slob_def.h
63541 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63542 return kmem_cache_alloc_node(cachep, flags, -1);
63543 }
63544
63545 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63546 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63547
63548 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63549 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63550 {
63551 return __kmalloc_node(size, flags, node);
63552 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63553 * kmalloc is the normal method of allocating memory
63554 * in the kernel.
63555 */
63556 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63557 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63558 {
63559 return __kmalloc_node(size, flags, -1);
63560 }
63561
63562 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63563 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63564 {
63565 return kmalloc(size, flags);
63566 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63567 index a32bcfd..d26bd6e 100644
63568 --- a/include/linux/slub_def.h
63569 +++ b/include/linux/slub_def.h
63570 @@ -89,7 +89,7 @@ struct kmem_cache {
63571 struct kmem_cache_order_objects max;
63572 struct kmem_cache_order_objects min;
63573 gfp_t allocflags; /* gfp flags to use on each alloc */
63574 - int refcount; /* Refcount for slab cache destroy */
63575 + atomic_t refcount; /* Refcount for slab cache destroy */
63576 void (*ctor)(void *);
63577 int inuse; /* Offset to metadata */
63578 int align; /* Alignment */
63579 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
63580 * This ought to end up with a global pointer to the right cache
63581 * in kmalloc_caches.
63582 */
63583 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
63584 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63585 {
63586 int index = kmalloc_index(size);
63587 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63588 }
63589
63590 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63591 -void *__kmalloc(size_t size, gfp_t flags);
63592 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63593
63594 static __always_inline void *
63595 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
63596 +static __always_inline void *
63597 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63598 {
63599 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
63600 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63601 }
63602 #endif
63603
63604 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63605 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63606 {
63607 unsigned int order = get_order(size);
63608 return kmalloc_order_trace(size, flags, order);
63609 }
63610
63611 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63612 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63613 {
63614 if (__builtin_constant_p(size)) {
63615 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63616 }
63617
63618 #ifdef CONFIG_NUMA
63619 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63620 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63621 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63622
63623 #ifdef CONFIG_TRACING
63624 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
63625 }
63626 #endif
63627
63628 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63629 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63630 {
63631 if (__builtin_constant_p(size) &&
63632 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63633 index de8832d..0147b46 100644
63634 --- a/include/linux/sonet.h
63635 +++ b/include/linux/sonet.h
63636 @@ -61,7 +61,7 @@ struct sonet_stats {
63637 #include <linux/atomic.h>
63638
63639 struct k_sonet_stats {
63640 -#define __HANDLE_ITEM(i) atomic_t i
63641 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63642 __SONET_ITEMS
63643 #undef __HANDLE_ITEM
63644 };
63645 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63646 index 2c5993a..b0e79f0 100644
63647 --- a/include/linux/sunrpc/clnt.h
63648 +++ b/include/linux/sunrpc/clnt.h
63649 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63650 {
63651 switch (sap->sa_family) {
63652 case AF_INET:
63653 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63654 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63655 case AF_INET6:
63656 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63657 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63658 }
63659 return 0;
63660 }
63661 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63662 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63663 const struct sockaddr *src)
63664 {
63665 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63666 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63667 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63668
63669 dsin->sin_family = ssin->sin_family;
63670 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63671 if (sa->sa_family != AF_INET6)
63672 return 0;
63673
63674 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63675 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63676 }
63677
63678 #endif /* __KERNEL__ */
63679 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63680 index e775689..9e206d9 100644
63681 --- a/include/linux/sunrpc/sched.h
63682 +++ b/include/linux/sunrpc/sched.h
63683 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63684 void (*rpc_call_done)(struct rpc_task *, void *);
63685 void (*rpc_release)(void *);
63686 };
63687 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63688
63689 struct rpc_task_setup {
63690 struct rpc_task *task;
63691 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63692 index c14fe86..393245e 100644
63693 --- a/include/linux/sunrpc/svc_rdma.h
63694 +++ b/include/linux/sunrpc/svc_rdma.h
63695 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63696 extern unsigned int svcrdma_max_requests;
63697 extern unsigned int svcrdma_max_req_size;
63698
63699 -extern atomic_t rdma_stat_recv;
63700 -extern atomic_t rdma_stat_read;
63701 -extern atomic_t rdma_stat_write;
63702 -extern atomic_t rdma_stat_sq_starve;
63703 -extern atomic_t rdma_stat_rq_starve;
63704 -extern atomic_t rdma_stat_rq_poll;
63705 -extern atomic_t rdma_stat_rq_prod;
63706 -extern atomic_t rdma_stat_sq_poll;
63707 -extern atomic_t rdma_stat_sq_prod;
63708 +extern atomic_unchecked_t rdma_stat_recv;
63709 +extern atomic_unchecked_t rdma_stat_read;
63710 +extern atomic_unchecked_t rdma_stat_write;
63711 +extern atomic_unchecked_t rdma_stat_sq_starve;
63712 +extern atomic_unchecked_t rdma_stat_rq_starve;
63713 +extern atomic_unchecked_t rdma_stat_rq_poll;
63714 +extern atomic_unchecked_t rdma_stat_rq_prod;
63715 +extern atomic_unchecked_t rdma_stat_sq_poll;
63716 +extern atomic_unchecked_t rdma_stat_sq_prod;
63717
63718 #define RPCRDMA_VERSION 1
63719
63720 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63721 index bb9127d..34ab358 100644
63722 --- a/include/linux/sysctl.h
63723 +++ b/include/linux/sysctl.h
63724 @@ -155,7 +155,11 @@ enum
63725 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63726 };
63727
63728 -
63729 +#ifdef CONFIG_PAX_SOFTMODE
63730 +enum {
63731 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63732 +};
63733 +#endif
63734
63735 /* CTL_VM names: */
63736 enum
63737 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63738
63739 extern int proc_dostring(struct ctl_table *, int,
63740 void __user *, size_t *, loff_t *);
63741 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63742 + void __user *, size_t *, loff_t *);
63743 extern int proc_dointvec(struct ctl_table *, int,
63744 void __user *, size_t *, loff_t *);
63745 extern int proc_dointvec_minmax(struct ctl_table *, int,
63746 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63747 index a71a292..51bd91d 100644
63748 --- a/include/linux/tracehook.h
63749 +++ b/include/linux/tracehook.h
63750 @@ -54,12 +54,12 @@ struct linux_binprm;
63751 /*
63752 * ptrace report for syscall entry and exit looks identical.
63753 */
63754 -static inline void ptrace_report_syscall(struct pt_regs *regs)
63755 +static inline int ptrace_report_syscall(struct pt_regs *regs)
63756 {
63757 int ptrace = current->ptrace;
63758
63759 if (!(ptrace & PT_PTRACED))
63760 - return;
63761 + return 0;
63762
63763 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63764
63765 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63766 send_sig(current->exit_code, current, 1);
63767 current->exit_code = 0;
63768 }
63769 +
63770 + return fatal_signal_pending(current);
63771 }
63772
63773 /**
63774 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63775 static inline __must_check int tracehook_report_syscall_entry(
63776 struct pt_regs *regs)
63777 {
63778 - ptrace_report_syscall(regs);
63779 - return 0;
63780 + return ptrace_report_syscall(regs);
63781 }
63782
63783 /**
63784 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63785 index ff7dc08..893e1bd 100644
63786 --- a/include/linux/tty_ldisc.h
63787 +++ b/include/linux/tty_ldisc.h
63788 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63789
63790 struct module *owner;
63791
63792 - int refcount;
63793 + atomic_t refcount;
63794 };
63795
63796 struct tty_ldisc {
63797 diff --git a/include/linux/types.h b/include/linux/types.h
63798 index e5fa503..df6e8a4 100644
63799 --- a/include/linux/types.h
63800 +++ b/include/linux/types.h
63801 @@ -214,10 +214,26 @@ typedef struct {
63802 int counter;
63803 } atomic_t;
63804
63805 +#ifdef CONFIG_PAX_REFCOUNT
63806 +typedef struct {
63807 + int counter;
63808 +} atomic_unchecked_t;
63809 +#else
63810 +typedef atomic_t atomic_unchecked_t;
63811 +#endif
63812 +
63813 #ifdef CONFIG_64BIT
63814 typedef struct {
63815 long counter;
63816 } atomic64_t;
63817 +
63818 +#ifdef CONFIG_PAX_REFCOUNT
63819 +typedef struct {
63820 + long counter;
63821 +} atomic64_unchecked_t;
63822 +#else
63823 +typedef atomic64_t atomic64_unchecked_t;
63824 +#endif
63825 #endif
63826
63827 struct list_head {
63828 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63829 index 5ca0951..53a2fff 100644
63830 --- a/include/linux/uaccess.h
63831 +++ b/include/linux/uaccess.h
63832 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63833 long ret; \
63834 mm_segment_t old_fs = get_fs(); \
63835 \
63836 - set_fs(KERNEL_DS); \
63837 pagefault_disable(); \
63838 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63839 - pagefault_enable(); \
63840 + set_fs(KERNEL_DS); \
63841 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63842 set_fs(old_fs); \
63843 + pagefault_enable(); \
63844 ret; \
63845 })
63846
63847 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
63848 * Safely write to address @dst from the buffer at @src. If a kernel fault
63849 * happens, handle that and return -EFAULT.
63850 */
63851 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
63852 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
63853 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
63854
63855 #endif /* __LINUX_UACCESS_H__ */
63856 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63857 index 99c1b4d..bb94261 100644
63858 --- a/include/linux/unaligned/access_ok.h
63859 +++ b/include/linux/unaligned/access_ok.h
63860 @@ -6,32 +6,32 @@
63861
63862 static inline u16 get_unaligned_le16(const void *p)
63863 {
63864 - return le16_to_cpup((__le16 *)p);
63865 + return le16_to_cpup((const __le16 *)p);
63866 }
63867
63868 static inline u32 get_unaligned_le32(const void *p)
63869 {
63870 - return le32_to_cpup((__le32 *)p);
63871 + return le32_to_cpup((const __le32 *)p);
63872 }
63873
63874 static inline u64 get_unaligned_le64(const void *p)
63875 {
63876 - return le64_to_cpup((__le64 *)p);
63877 + return le64_to_cpup((const __le64 *)p);
63878 }
63879
63880 static inline u16 get_unaligned_be16(const void *p)
63881 {
63882 - return be16_to_cpup((__be16 *)p);
63883 + return be16_to_cpup((const __be16 *)p);
63884 }
63885
63886 static inline u32 get_unaligned_be32(const void *p)
63887 {
63888 - return be32_to_cpup((__be32 *)p);
63889 + return be32_to_cpup((const __be32 *)p);
63890 }
63891
63892 static inline u64 get_unaligned_be64(const void *p)
63893 {
63894 - return be64_to_cpup((__be64 *)p);
63895 + return be64_to_cpup((const __be64 *)p);
63896 }
63897
63898 static inline void put_unaligned_le16(u16 val, void *p)
63899 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63900 index 0d3f988..000f101 100644
63901 --- a/include/linux/usb/renesas_usbhs.h
63902 +++ b/include/linux/usb/renesas_usbhs.h
63903 @@ -39,7 +39,7 @@ enum {
63904 */
63905 struct renesas_usbhs_driver_callback {
63906 int (*notify_hotplug)(struct platform_device *pdev);
63907 -};
63908 +} __no_const;
63909
63910 /*
63911 * callback functions for platform
63912 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63913 * VBUS control is needed for Host
63914 */
63915 int (*set_vbus)(struct platform_device *pdev, int enable);
63916 -};
63917 +} __no_const;
63918
63919 /*
63920 * parameters for renesas usbhs
63921 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63922 index 6f8fbcf..8259001 100644
63923 --- a/include/linux/vermagic.h
63924 +++ b/include/linux/vermagic.h
63925 @@ -25,9 +25,35 @@
63926 #define MODULE_ARCH_VERMAGIC ""
63927 #endif
63928
63929 +#ifdef CONFIG_PAX_REFCOUNT
63930 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63931 +#else
63932 +#define MODULE_PAX_REFCOUNT ""
63933 +#endif
63934 +
63935 +#ifdef CONSTIFY_PLUGIN
63936 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63937 +#else
63938 +#define MODULE_CONSTIFY_PLUGIN ""
63939 +#endif
63940 +
63941 +#ifdef STACKLEAK_PLUGIN
63942 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63943 +#else
63944 +#define MODULE_STACKLEAK_PLUGIN ""
63945 +#endif
63946 +
63947 +#ifdef CONFIG_GRKERNSEC
63948 +#define MODULE_GRSEC "GRSEC "
63949 +#else
63950 +#define MODULE_GRSEC ""
63951 +#endif
63952 +
63953 #define VERMAGIC_STRING \
63954 UTS_RELEASE " " \
63955 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63956 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63957 - MODULE_ARCH_VERMAGIC
63958 + MODULE_ARCH_VERMAGIC \
63959 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63960 + MODULE_GRSEC
63961
63962 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63963 index dcdfc2b..cce598d 100644
63964 --- a/include/linux/vmalloc.h
63965 +++ b/include/linux/vmalloc.h
63966 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63967 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63968 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63969 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63970 +
63971 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63972 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63973 +#endif
63974 +
63975 /* bits [20..32] reserved for arch specific ioremap internals */
63976
63977 /*
63978 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
63979 }
63980 #endif
63981
63982 -extern void *vmalloc(unsigned long size);
63983 -extern void *vzalloc(unsigned long size);
63984 -extern void *vmalloc_user(unsigned long size);
63985 -extern void *vmalloc_node(unsigned long size, int node);
63986 -extern void *vzalloc_node(unsigned long size, int node);
63987 -extern void *vmalloc_exec(unsigned long size);
63988 -extern void *vmalloc_32(unsigned long size);
63989 -extern void *vmalloc_32_user(unsigned long size);
63990 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63991 +extern void *vmalloc(unsigned long size) __size_overflow(1);
63992 +extern void *vzalloc(unsigned long size) __size_overflow(1);
63993 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
63994 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
63995 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
63996 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
63997 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
63998 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
63999 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
64000 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64001 unsigned long start, unsigned long end, gfp_t gfp_mask,
64002 - pgprot_t prot, int node, void *caller);
64003 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64004 extern void vfree(const void *addr);
64005
64006 extern void *vmap(struct page **pages, unsigned int count,
64007 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64008 extern void free_vm_area(struct vm_struct *area);
64009
64010 /* for /dev/kmem */
64011 -extern long vread(char *buf, char *addr, unsigned long count);
64012 -extern long vwrite(char *buf, char *addr, unsigned long count);
64013 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64014 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64015
64016 /*
64017 * Internals. Dont't use..
64018 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64019 index 65efb92..137adbb 100644
64020 --- a/include/linux/vmstat.h
64021 +++ b/include/linux/vmstat.h
64022 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64023 /*
64024 * Zone based page accounting with per cpu differentials.
64025 */
64026 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64027 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64028
64029 static inline void zone_page_state_add(long x, struct zone *zone,
64030 enum zone_stat_item item)
64031 {
64032 - atomic_long_add(x, &zone->vm_stat[item]);
64033 - atomic_long_add(x, &vm_stat[item]);
64034 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64035 + atomic_long_add_unchecked(x, &vm_stat[item]);
64036 }
64037
64038 static inline unsigned long global_page_state(enum zone_stat_item item)
64039 {
64040 - long x = atomic_long_read(&vm_stat[item]);
64041 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64042 #ifdef CONFIG_SMP
64043 if (x < 0)
64044 x = 0;
64045 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64046 static inline unsigned long zone_page_state(struct zone *zone,
64047 enum zone_stat_item item)
64048 {
64049 - long x = atomic_long_read(&zone->vm_stat[item]);
64050 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64051 #ifdef CONFIG_SMP
64052 if (x < 0)
64053 x = 0;
64054 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64055 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64056 enum zone_stat_item item)
64057 {
64058 - long x = atomic_long_read(&zone->vm_stat[item]);
64059 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64060
64061 #ifdef CONFIG_SMP
64062 int cpu;
64063 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64064
64065 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64066 {
64067 - atomic_long_inc(&zone->vm_stat[item]);
64068 - atomic_long_inc(&vm_stat[item]);
64069 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64070 + atomic_long_inc_unchecked(&vm_stat[item]);
64071 }
64072
64073 static inline void __inc_zone_page_state(struct page *page,
64074 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64075
64076 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64077 {
64078 - atomic_long_dec(&zone->vm_stat[item]);
64079 - atomic_long_dec(&vm_stat[item]);
64080 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64081 + atomic_long_dec_unchecked(&vm_stat[item]);
64082 }
64083
64084 static inline void __dec_zone_page_state(struct page *page,
64085 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64086 index e5d1220..ef6e406 100644
64087 --- a/include/linux/xattr.h
64088 +++ b/include/linux/xattr.h
64089 @@ -57,6 +57,11 @@
64090 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64091 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64092
64093 +/* User namespace */
64094 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64095 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64096 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64097 +
64098 #ifdef __KERNEL__
64099
64100 #include <linux/types.h>
64101 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64102 index 4aeff96..b378cdc 100644
64103 --- a/include/media/saa7146_vv.h
64104 +++ b/include/media/saa7146_vv.h
64105 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64106 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64107
64108 /* the extension can override this */
64109 - struct v4l2_ioctl_ops ops;
64110 + v4l2_ioctl_ops_no_const ops;
64111 /* pointer to the saa7146 core ops */
64112 const struct v4l2_ioctl_ops *core_ops;
64113
64114 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64115 index c7c40f1..4f01585 100644
64116 --- a/include/media/v4l2-dev.h
64117 +++ b/include/media/v4l2-dev.h
64118 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64119
64120
64121 struct v4l2_file_operations {
64122 - struct module *owner;
64123 + struct module * const owner;
64124 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64125 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64126 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64127 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64128 int (*open) (struct file *);
64129 int (*release) (struct file *);
64130 };
64131 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64132
64133 /*
64134 * Newer version of video_device, handled by videodev2.c
64135 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64136 index 3f5d60f..44210ed 100644
64137 --- a/include/media/v4l2-ioctl.h
64138 +++ b/include/media/v4l2-ioctl.h
64139 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64140 long (*vidioc_default) (struct file *file, void *fh,
64141 bool valid_prio, int cmd, void *arg);
64142 };
64143 -
64144 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64145
64146 /* v4l debugging and diagnostics */
64147
64148 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64149 index 8d55251..dfe5b0a 100644
64150 --- a/include/net/caif/caif_hsi.h
64151 +++ b/include/net/caif/caif_hsi.h
64152 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64153 void (*rx_done_cb) (struct cfhsi_drv *drv);
64154 void (*wake_up_cb) (struct cfhsi_drv *drv);
64155 void (*wake_down_cb) (struct cfhsi_drv *drv);
64156 -};
64157 +} __no_const;
64158
64159 /* Structure implemented by HSI device. */
64160 struct cfhsi_dev {
64161 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64162 index 9e5425b..8136ffc 100644
64163 --- a/include/net/caif/cfctrl.h
64164 +++ b/include/net/caif/cfctrl.h
64165 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64166 void (*radioset_rsp)(void);
64167 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64168 struct cflayer *client_layer);
64169 -};
64170 +} __no_const;
64171
64172 /* Link Setup Parameters for CAIF-Links. */
64173 struct cfctrl_link_param {
64174 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64175 struct cfctrl {
64176 struct cfsrvl serv;
64177 struct cfctrl_rsp res;
64178 - atomic_t req_seq_no;
64179 - atomic_t rsp_seq_no;
64180 + atomic_unchecked_t req_seq_no;
64181 + atomic_unchecked_t rsp_seq_no;
64182 struct list_head list;
64183 /* Protects from simultaneous access to first_req list */
64184 spinlock_t info_list_lock;
64185 diff --git a/include/net/flow.h b/include/net/flow.h
64186 index 6c469db..7743b8e 100644
64187 --- a/include/net/flow.h
64188 +++ b/include/net/flow.h
64189 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64190
64191 extern void flow_cache_flush(void);
64192 extern void flow_cache_flush_deferred(void);
64193 -extern atomic_t flow_cache_genid;
64194 +extern atomic_unchecked_t flow_cache_genid;
64195
64196 #endif
64197 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64198 index b94765e..053f68b 100644
64199 --- a/include/net/inetpeer.h
64200 +++ b/include/net/inetpeer.h
64201 @@ -48,8 +48,8 @@ struct inet_peer {
64202 */
64203 union {
64204 struct {
64205 - atomic_t rid; /* Frag reception counter */
64206 - atomic_t ip_id_count; /* IP ID for the next packet */
64207 + atomic_unchecked_t rid; /* Frag reception counter */
64208 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64209 __u32 tcp_ts;
64210 __u32 tcp_ts_stamp;
64211 };
64212 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64213 more++;
64214 inet_peer_refcheck(p);
64215 do {
64216 - old = atomic_read(&p->ip_id_count);
64217 + old = atomic_read_unchecked(&p->ip_id_count);
64218 new = old + more;
64219 if (!new)
64220 new = 1;
64221 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64222 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64223 return new;
64224 }
64225
64226 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64227 index 10422ef..662570f 100644
64228 --- a/include/net/ip_fib.h
64229 +++ b/include/net/ip_fib.h
64230 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64231
64232 #define FIB_RES_SADDR(net, res) \
64233 ((FIB_RES_NH(res).nh_saddr_genid == \
64234 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64235 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64236 FIB_RES_NH(res).nh_saddr : \
64237 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64238 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64239 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64240 index ebe517f..1bd286b 100644
64241 --- a/include/net/ip_vs.h
64242 +++ b/include/net/ip_vs.h
64243 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64244 struct ip_vs_conn *control; /* Master control connection */
64245 atomic_t n_control; /* Number of controlled ones */
64246 struct ip_vs_dest *dest; /* real server */
64247 - atomic_t in_pkts; /* incoming packet counter */
64248 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64249
64250 /* packet transmitter for different forwarding methods. If it
64251 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64252 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64253 __be16 port; /* port number of the server */
64254 union nf_inet_addr addr; /* IP address of the server */
64255 volatile unsigned flags; /* dest status flags */
64256 - atomic_t conn_flags; /* flags to copy to conn */
64257 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64258 atomic_t weight; /* server weight */
64259
64260 atomic_t refcnt; /* reference counter */
64261 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64262 index 69b610a..fe3962c 100644
64263 --- a/include/net/irda/ircomm_core.h
64264 +++ b/include/net/irda/ircomm_core.h
64265 @@ -51,7 +51,7 @@ typedef struct {
64266 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64267 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64268 struct ircomm_info *);
64269 -} call_t;
64270 +} __no_const call_t;
64271
64272 struct ircomm_cb {
64273 irda_queue_t queue;
64274 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64275 index 59ba38bc..d515662 100644
64276 --- a/include/net/irda/ircomm_tty.h
64277 +++ b/include/net/irda/ircomm_tty.h
64278 @@ -35,6 +35,7 @@
64279 #include <linux/termios.h>
64280 #include <linux/timer.h>
64281 #include <linux/tty.h> /* struct tty_struct */
64282 +#include <asm/local.h>
64283
64284 #include <net/irda/irias_object.h>
64285 #include <net/irda/ircomm_core.h>
64286 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64287 unsigned short close_delay;
64288 unsigned short closing_wait; /* time to wait before closing */
64289
64290 - int open_count;
64291 - int blocked_open; /* # of blocked opens */
64292 + local_t open_count;
64293 + local_t blocked_open; /* # of blocked opens */
64294
64295 /* Protect concurent access to :
64296 * o self->open_count
64297 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64298 index 0954ec9..7413562 100644
64299 --- a/include/net/iucv/af_iucv.h
64300 +++ b/include/net/iucv/af_iucv.h
64301 @@ -138,7 +138,7 @@ struct iucv_sock {
64302 struct iucv_sock_list {
64303 struct hlist_head head;
64304 rwlock_t lock;
64305 - atomic_t autobind_name;
64306 + atomic_unchecked_t autobind_name;
64307 };
64308
64309 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64310 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64311 index 34c996f..bb3b4d4 100644
64312 --- a/include/net/neighbour.h
64313 +++ b/include/net/neighbour.h
64314 @@ -123,7 +123,7 @@ struct neigh_ops {
64315 void (*error_report)(struct neighbour *, struct sk_buff *);
64316 int (*output)(struct neighbour *, struct sk_buff *);
64317 int (*connected_output)(struct neighbour *, struct sk_buff *);
64318 -};
64319 +} __do_const;
64320
64321 struct pneigh_entry {
64322 struct pneigh_entry *next;
64323 diff --git a/include/net/netlink.h b/include/net/netlink.h
64324 index cb1f350..3279d2c 100644
64325 --- a/include/net/netlink.h
64326 +++ b/include/net/netlink.h
64327 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64328 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64329 {
64330 if (mark)
64331 - skb_trim(skb, (unsigned char *) mark - skb->data);
64332 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64333 }
64334
64335 /**
64336 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64337 index bbd023a..97c6d0d 100644
64338 --- a/include/net/netns/ipv4.h
64339 +++ b/include/net/netns/ipv4.h
64340 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64341 unsigned int sysctl_ping_group_range[2];
64342 long sysctl_tcp_mem[3];
64343
64344 - atomic_t rt_genid;
64345 - atomic_t dev_addr_genid;
64346 + atomic_unchecked_t rt_genid;
64347 + atomic_unchecked_t dev_addr_genid;
64348
64349 #ifdef CONFIG_IP_MROUTE
64350 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64351 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64352 index d368561..96aaa17 100644
64353 --- a/include/net/sctp/sctp.h
64354 +++ b/include/net/sctp/sctp.h
64355 @@ -318,9 +318,9 @@ do { \
64356
64357 #else /* SCTP_DEBUG */
64358
64359 -#define SCTP_DEBUG_PRINTK(whatever...)
64360 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64361 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64362 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64363 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64364 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64365 #define SCTP_ENABLE_DEBUG
64366 #define SCTP_DISABLE_DEBUG
64367 #define SCTP_ASSERT(expr, str, func)
64368 diff --git a/include/net/sock.h b/include/net/sock.h
64369 index 91c1c8b..15ae923 100644
64370 --- a/include/net/sock.h
64371 +++ b/include/net/sock.h
64372 @@ -299,7 +299,7 @@ struct sock {
64373 #ifdef CONFIG_RPS
64374 __u32 sk_rxhash;
64375 #endif
64376 - atomic_t sk_drops;
64377 + atomic_unchecked_t sk_drops;
64378 int sk_rcvbuf;
64379
64380 struct sk_filter __rcu *sk_filter;
64381 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64382 }
64383
64384 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64385 - char __user *from, char *to,
64386 + char __user *from, unsigned char *to,
64387 int copy, int offset)
64388 {
64389 if (skb->ip_summed == CHECKSUM_NONE) {
64390 diff --git a/include/net/tcp.h b/include/net/tcp.h
64391 index 2d80c29..aa07caf 100644
64392 --- a/include/net/tcp.h
64393 +++ b/include/net/tcp.h
64394 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64395 char *name;
64396 sa_family_t family;
64397 const struct file_operations *seq_fops;
64398 - struct seq_operations seq_ops;
64399 + seq_operations_no_const seq_ops;
64400 };
64401
64402 struct tcp_iter_state {
64403 diff --git a/include/net/udp.h b/include/net/udp.h
64404 index e39592f..fef9680 100644
64405 --- a/include/net/udp.h
64406 +++ b/include/net/udp.h
64407 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64408 sa_family_t family;
64409 struct udp_table *udp_table;
64410 const struct file_operations *seq_fops;
64411 - struct seq_operations seq_ops;
64412 + seq_operations_no_const seq_ops;
64413 };
64414
64415 struct udp_iter_state {
64416 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64417 index 89174e2..1f82598 100644
64418 --- a/include/net/xfrm.h
64419 +++ b/include/net/xfrm.h
64420 @@ -505,7 +505,7 @@ struct xfrm_policy {
64421 struct timer_list timer;
64422
64423 struct flow_cache_object flo;
64424 - atomic_t genid;
64425 + atomic_unchecked_t genid;
64426 u32 priority;
64427 u32 index;
64428 struct xfrm_mark mark;
64429 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64430 index 1a046b1..ee0bef0 100644
64431 --- a/include/rdma/iw_cm.h
64432 +++ b/include/rdma/iw_cm.h
64433 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64434 int backlog);
64435
64436 int (*destroy_listen)(struct iw_cm_id *cm_id);
64437 -};
64438 +} __no_const;
64439
64440 /**
64441 * iw_create_cm_id - Create an IW CM identifier.
64442 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64443 index 6a3922f..0b73022 100644
64444 --- a/include/scsi/libfc.h
64445 +++ b/include/scsi/libfc.h
64446 @@ -748,6 +748,7 @@ struct libfc_function_template {
64447 */
64448 void (*disc_stop_final) (struct fc_lport *);
64449 };
64450 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64451
64452 /**
64453 * struct fc_disc - Discovery context
64454 @@ -851,7 +852,7 @@ struct fc_lport {
64455 struct fc_vport *vport;
64456
64457 /* Operational Information */
64458 - struct libfc_function_template tt;
64459 + libfc_function_template_no_const tt;
64460 u8 link_up;
64461 u8 qfull;
64462 enum fc_lport_state state;
64463 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64464 index 77273f2..dd4031f 100644
64465 --- a/include/scsi/scsi_device.h
64466 +++ b/include/scsi/scsi_device.h
64467 @@ -161,9 +161,9 @@ struct scsi_device {
64468 unsigned int max_device_blocked; /* what device_blocked counts down from */
64469 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64470
64471 - atomic_t iorequest_cnt;
64472 - atomic_t iodone_cnt;
64473 - atomic_t ioerr_cnt;
64474 + atomic_unchecked_t iorequest_cnt;
64475 + atomic_unchecked_t iodone_cnt;
64476 + atomic_unchecked_t ioerr_cnt;
64477
64478 struct device sdev_gendev,
64479 sdev_dev;
64480 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64481 index 2a65167..91e01f8 100644
64482 --- a/include/scsi/scsi_transport_fc.h
64483 +++ b/include/scsi/scsi_transport_fc.h
64484 @@ -711,7 +711,7 @@ struct fc_function_template {
64485 unsigned long show_host_system_hostname:1;
64486
64487 unsigned long disable_target_scan:1;
64488 -};
64489 +} __do_const;
64490
64491
64492 /**
64493 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64494 index 030b87c..98a6954 100644
64495 --- a/include/sound/ak4xxx-adda.h
64496 +++ b/include/sound/ak4xxx-adda.h
64497 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64498 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64499 unsigned char val);
64500 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64501 -};
64502 +} __no_const;
64503
64504 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64505
64506 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64507 index 8c05e47..2b5df97 100644
64508 --- a/include/sound/hwdep.h
64509 +++ b/include/sound/hwdep.h
64510 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64511 struct snd_hwdep_dsp_status *status);
64512 int (*dsp_load)(struct snd_hwdep *hw,
64513 struct snd_hwdep_dsp_image *image);
64514 -};
64515 +} __no_const;
64516
64517 struct snd_hwdep {
64518 struct snd_card *card;
64519 diff --git a/include/sound/info.h b/include/sound/info.h
64520 index 9ca1a49..aba1728 100644
64521 --- a/include/sound/info.h
64522 +++ b/include/sound/info.h
64523 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64524 struct snd_info_buffer *buffer);
64525 void (*write)(struct snd_info_entry *entry,
64526 struct snd_info_buffer *buffer);
64527 -};
64528 +} __no_const;
64529
64530 struct snd_info_entry_ops {
64531 int (*open)(struct snd_info_entry *entry,
64532 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64533 index 0cf91b2..b70cae4 100644
64534 --- a/include/sound/pcm.h
64535 +++ b/include/sound/pcm.h
64536 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64537 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64538 int (*ack)(struct snd_pcm_substream *substream);
64539 };
64540 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64541
64542 /*
64543 *
64544 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64545 index af1b49e..a5d55a5 100644
64546 --- a/include/sound/sb16_csp.h
64547 +++ b/include/sound/sb16_csp.h
64548 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64549 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64550 int (*csp_stop) (struct snd_sb_csp * p);
64551 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64552 -};
64553 +} __no_const;
64554
64555 /*
64556 * CSP private data
64557 diff --git a/include/sound/soc.h b/include/sound/soc.h
64558 index 0992dff..bb366fe 100644
64559 --- a/include/sound/soc.h
64560 +++ b/include/sound/soc.h
64561 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64562 /* platform IO - used for platform DAPM */
64563 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64564 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64565 -};
64566 +} __do_const;
64567
64568 struct snd_soc_platform {
64569 const char *name;
64570 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64571 struct snd_soc_dai_link *dai_link;
64572 struct mutex pcm_mutex;
64573 enum snd_soc_pcm_subclass pcm_subclass;
64574 - struct snd_pcm_ops ops;
64575 + snd_pcm_ops_no_const ops;
64576
64577 unsigned int complete:1;
64578 unsigned int dev_registered:1;
64579 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64580 index 444cd6b..3327cc5 100644
64581 --- a/include/sound/ymfpci.h
64582 +++ b/include/sound/ymfpci.h
64583 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64584 spinlock_t reg_lock;
64585 spinlock_t voice_lock;
64586 wait_queue_head_t interrupt_sleep;
64587 - atomic_t interrupt_sleep_count;
64588 + atomic_unchecked_t interrupt_sleep_count;
64589 struct snd_info_entry *proc_entry;
64590 const struct firmware *dsp_microcode;
64591 const struct firmware *controller_microcode;
64592 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64593 index fe73eb8..56388b1 100644
64594 --- a/include/target/target_core_base.h
64595 +++ b/include/target/target_core_base.h
64596 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
64597 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64598 int (*t10_pr_register)(struct se_cmd *);
64599 int (*t10_pr_clear)(struct se_cmd *);
64600 -};
64601 +} __no_const;
64602
64603 struct t10_reservation {
64604 /* Reservation effects all target ports */
64605 @@ -561,8 +561,8 @@ struct se_cmd {
64606 atomic_t t_se_count;
64607 atomic_t t_task_cdbs_left;
64608 atomic_t t_task_cdbs_ex_left;
64609 - atomic_t t_task_cdbs_sent;
64610 - atomic_t t_transport_aborted;
64611 + atomic_unchecked_t t_task_cdbs_sent;
64612 + atomic_unchecked_t t_transport_aborted;
64613 atomic_t t_transport_active;
64614 atomic_t t_transport_complete;
64615 atomic_t t_transport_queue_active;
64616 @@ -799,7 +799,7 @@ struct se_device {
64617 spinlock_t stats_lock;
64618 /* Active commands on this virtual SE device */
64619 atomic_t simple_cmds;
64620 - atomic_t dev_ordered_id;
64621 + atomic_unchecked_t dev_ordered_id;
64622 atomic_t execute_tasks;
64623 atomic_t dev_ordered_sync;
64624 atomic_t dev_qf_count;
64625 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64626 index 1c09820..7f5ec79 100644
64627 --- a/include/trace/events/irq.h
64628 +++ b/include/trace/events/irq.h
64629 @@ -36,7 +36,7 @@ struct softirq_action;
64630 */
64631 TRACE_EVENT(irq_handler_entry,
64632
64633 - TP_PROTO(int irq, struct irqaction *action),
64634 + TP_PROTO(int irq, const struct irqaction *action),
64635
64636 TP_ARGS(irq, action),
64637
64638 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64639 */
64640 TRACE_EVENT(irq_handler_exit,
64641
64642 - TP_PROTO(int irq, struct irqaction *action, int ret),
64643 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64644
64645 TP_ARGS(irq, action, ret),
64646
64647 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64648 index c41f308..6918de3 100644
64649 --- a/include/video/udlfb.h
64650 +++ b/include/video/udlfb.h
64651 @@ -52,10 +52,10 @@ struct dlfb_data {
64652 u32 pseudo_palette[256];
64653 int blank_mode; /*one of FB_BLANK_ */
64654 /* blit-only rendering path metrics, exposed through sysfs */
64655 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64656 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64657 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64658 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64659 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64660 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64661 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64662 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64663 };
64664
64665 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64666 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64667 index 0993a22..32ba2fe 100644
64668 --- a/include/video/uvesafb.h
64669 +++ b/include/video/uvesafb.h
64670 @@ -177,6 +177,7 @@ struct uvesafb_par {
64671 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64672 u8 pmi_setpal; /* PMI for palette changes */
64673 u16 *pmi_base; /* protected mode interface location */
64674 + u8 *pmi_code; /* protected mode code location */
64675 void *pmi_start;
64676 void *pmi_pal;
64677 u8 *vbe_state_orig; /*
64678 diff --git a/init/Kconfig b/init/Kconfig
64679 index 3f42cd6..613f41d 100644
64680 --- a/init/Kconfig
64681 +++ b/init/Kconfig
64682 @@ -799,6 +799,7 @@ endif # CGROUPS
64683
64684 config CHECKPOINT_RESTORE
64685 bool "Checkpoint/restore support" if EXPERT
64686 + depends on !GRKERNSEC
64687 default n
64688 help
64689 Enables additional kernel features in a sake of checkpoint/restore.
64690 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64691
64692 config COMPAT_BRK
64693 bool "Disable heap randomization"
64694 - default y
64695 + default n
64696 help
64697 Randomizing heap placement makes heap exploits harder, but it
64698 also breaks ancient binaries (including anything libc5 based).
64699 diff --git a/init/do_mounts.c b/init/do_mounts.c
64700 index 2974c8b..0b863ae 100644
64701 --- a/init/do_mounts.c
64702 +++ b/init/do_mounts.c
64703 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64704 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64705 {
64706 struct super_block *s;
64707 - int err = sys_mount(name, "/root", fs, flags, data);
64708 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64709 if (err)
64710 return err;
64711
64712 - sys_chdir((const char __user __force *)"/root");
64713 + sys_chdir((const char __force_user *)"/root");
64714 s = current->fs->pwd.dentry->d_sb;
64715 ROOT_DEV = s->s_dev;
64716 printk(KERN_INFO
64717 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64718 va_start(args, fmt);
64719 vsprintf(buf, fmt, args);
64720 va_end(args);
64721 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64722 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64723 if (fd >= 0) {
64724 sys_ioctl(fd, FDEJECT, 0);
64725 sys_close(fd);
64726 }
64727 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64728 - fd = sys_open("/dev/console", O_RDWR, 0);
64729 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64730 if (fd >= 0) {
64731 sys_ioctl(fd, TCGETS, (long)&termios);
64732 termios.c_lflag &= ~ICANON;
64733 sys_ioctl(fd, TCSETSF, (long)&termios);
64734 - sys_read(fd, &c, 1);
64735 + sys_read(fd, (char __user *)&c, 1);
64736 termios.c_lflag |= ICANON;
64737 sys_ioctl(fd, TCSETSF, (long)&termios);
64738 sys_close(fd);
64739 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64740 mount_root();
64741 out:
64742 devtmpfs_mount("dev");
64743 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64744 - sys_chroot((const char __user __force *)".");
64745 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64746 + sys_chroot((const char __force_user *)".");
64747 }
64748 diff --git a/init/do_mounts.h b/init/do_mounts.h
64749 index f5b978a..69dbfe8 100644
64750 --- a/init/do_mounts.h
64751 +++ b/init/do_mounts.h
64752 @@ -15,15 +15,15 @@ extern int root_mountflags;
64753
64754 static inline int create_dev(char *name, dev_t dev)
64755 {
64756 - sys_unlink(name);
64757 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64758 + sys_unlink((char __force_user *)name);
64759 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64760 }
64761
64762 #if BITS_PER_LONG == 32
64763 static inline u32 bstat(char *name)
64764 {
64765 struct stat64 stat;
64766 - if (sys_stat64(name, &stat) != 0)
64767 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64768 return 0;
64769 if (!S_ISBLK(stat.st_mode))
64770 return 0;
64771 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64772 static inline u32 bstat(char *name)
64773 {
64774 struct stat stat;
64775 - if (sys_newstat(name, &stat) != 0)
64776 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64777 return 0;
64778 if (!S_ISBLK(stat.st_mode))
64779 return 0;
64780 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64781 index 3098a38..253064e 100644
64782 --- a/init/do_mounts_initrd.c
64783 +++ b/init/do_mounts_initrd.c
64784 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64785 create_dev("/dev/root.old", Root_RAM0);
64786 /* mount initrd on rootfs' /root */
64787 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64788 - sys_mkdir("/old", 0700);
64789 - root_fd = sys_open("/", 0, 0);
64790 - old_fd = sys_open("/old", 0, 0);
64791 + sys_mkdir((const char __force_user *)"/old", 0700);
64792 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64793 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64794 /* move initrd over / and chdir/chroot in initrd root */
64795 - sys_chdir("/root");
64796 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64797 - sys_chroot(".");
64798 + sys_chdir((const char __force_user *)"/root");
64799 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64800 + sys_chroot((const char __force_user *)".");
64801
64802 /*
64803 * In case that a resume from disk is carried out by linuxrc or one of
64804 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64805
64806 /* move initrd to rootfs' /old */
64807 sys_fchdir(old_fd);
64808 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64809 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64810 /* switch root and cwd back to / of rootfs */
64811 sys_fchdir(root_fd);
64812 - sys_chroot(".");
64813 + sys_chroot((const char __force_user *)".");
64814 sys_close(old_fd);
64815 sys_close(root_fd);
64816
64817 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64818 - sys_chdir("/old");
64819 + sys_chdir((const char __force_user *)"/old");
64820 return;
64821 }
64822
64823 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64824 mount_root();
64825
64826 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64827 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64828 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64829 if (!error)
64830 printk("okay\n");
64831 else {
64832 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64833 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64834 if (error == -ENOENT)
64835 printk("/initrd does not exist. Ignored.\n");
64836 else
64837 printk("failed\n");
64838 printk(KERN_NOTICE "Unmounting old root\n");
64839 - sys_umount("/old", MNT_DETACH);
64840 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64841 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64842 if (fd < 0) {
64843 error = fd;
64844 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64845 * mounted in the normal path.
64846 */
64847 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64848 - sys_unlink("/initrd.image");
64849 + sys_unlink((const char __force_user *)"/initrd.image");
64850 handle_initrd();
64851 return 1;
64852 }
64853 }
64854 - sys_unlink("/initrd.image");
64855 + sys_unlink((const char __force_user *)"/initrd.image");
64856 return 0;
64857 }
64858 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64859 index 32c4799..c27ee74 100644
64860 --- a/init/do_mounts_md.c
64861 +++ b/init/do_mounts_md.c
64862 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64863 partitioned ? "_d" : "", minor,
64864 md_setup_args[ent].device_names);
64865
64866 - fd = sys_open(name, 0, 0);
64867 + fd = sys_open((char __force_user *)name, 0, 0);
64868 if (fd < 0) {
64869 printk(KERN_ERR "md: open failed - cannot start "
64870 "array %s\n", name);
64871 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64872 * array without it
64873 */
64874 sys_close(fd);
64875 - fd = sys_open(name, 0, 0);
64876 + fd = sys_open((char __force_user *)name, 0, 0);
64877 sys_ioctl(fd, BLKRRPART, 0);
64878 }
64879 sys_close(fd);
64880 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64881
64882 wait_for_device_probe();
64883
64884 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64885 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64886 if (fd >= 0) {
64887 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64888 sys_close(fd);
64889 diff --git a/init/initramfs.c b/init/initramfs.c
64890 index 8216c30..25e8e32 100644
64891 --- a/init/initramfs.c
64892 +++ b/init/initramfs.c
64893 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64894 }
64895 }
64896
64897 -static long __init do_utime(char __user *filename, time_t mtime)
64898 +static long __init do_utime(__force char __user *filename, time_t mtime)
64899 {
64900 struct timespec t[2];
64901
64902 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64903 struct dir_entry *de, *tmp;
64904 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64905 list_del(&de->list);
64906 - do_utime(de->name, de->mtime);
64907 + do_utime((char __force_user *)de->name, de->mtime);
64908 kfree(de->name);
64909 kfree(de);
64910 }
64911 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64912 if (nlink >= 2) {
64913 char *old = find_link(major, minor, ino, mode, collected);
64914 if (old)
64915 - return (sys_link(old, collected) < 0) ? -1 : 1;
64916 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64917 }
64918 return 0;
64919 }
64920 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64921 {
64922 struct stat st;
64923
64924 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64925 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64926 if (S_ISDIR(st.st_mode))
64927 - sys_rmdir(path);
64928 + sys_rmdir((char __force_user *)path);
64929 else
64930 - sys_unlink(path);
64931 + sys_unlink((char __force_user *)path);
64932 }
64933 }
64934
64935 @@ -305,7 +305,7 @@ static int __init do_name(void)
64936 int openflags = O_WRONLY|O_CREAT;
64937 if (ml != 1)
64938 openflags |= O_TRUNC;
64939 - wfd = sys_open(collected, openflags, mode);
64940 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64941
64942 if (wfd >= 0) {
64943 sys_fchown(wfd, uid, gid);
64944 @@ -317,17 +317,17 @@ static int __init do_name(void)
64945 }
64946 }
64947 } else if (S_ISDIR(mode)) {
64948 - sys_mkdir(collected, mode);
64949 - sys_chown(collected, uid, gid);
64950 - sys_chmod(collected, mode);
64951 + sys_mkdir((char __force_user *)collected, mode);
64952 + sys_chown((char __force_user *)collected, uid, gid);
64953 + sys_chmod((char __force_user *)collected, mode);
64954 dir_add(collected, mtime);
64955 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64956 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64957 if (maybe_link() == 0) {
64958 - sys_mknod(collected, mode, rdev);
64959 - sys_chown(collected, uid, gid);
64960 - sys_chmod(collected, mode);
64961 - do_utime(collected, mtime);
64962 + sys_mknod((char __force_user *)collected, mode, rdev);
64963 + sys_chown((char __force_user *)collected, uid, gid);
64964 + sys_chmod((char __force_user *)collected, mode);
64965 + do_utime((char __force_user *)collected, mtime);
64966 }
64967 }
64968 return 0;
64969 @@ -336,15 +336,15 @@ static int __init do_name(void)
64970 static int __init do_copy(void)
64971 {
64972 if (count >= body_len) {
64973 - sys_write(wfd, victim, body_len);
64974 + sys_write(wfd, (char __force_user *)victim, body_len);
64975 sys_close(wfd);
64976 - do_utime(vcollected, mtime);
64977 + do_utime((char __force_user *)vcollected, mtime);
64978 kfree(vcollected);
64979 eat(body_len);
64980 state = SkipIt;
64981 return 0;
64982 } else {
64983 - sys_write(wfd, victim, count);
64984 + sys_write(wfd, (char __force_user *)victim, count);
64985 body_len -= count;
64986 eat(count);
64987 return 1;
64988 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64989 {
64990 collected[N_ALIGN(name_len) + body_len] = '\0';
64991 clean_path(collected, 0);
64992 - sys_symlink(collected + N_ALIGN(name_len), collected);
64993 - sys_lchown(collected, uid, gid);
64994 - do_utime(collected, mtime);
64995 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64996 + sys_lchown((char __force_user *)collected, uid, gid);
64997 + do_utime((char __force_user *)collected, mtime);
64998 state = SkipIt;
64999 next_state = Reset;
65000 return 0;
65001 diff --git a/init/main.c b/init/main.c
65002 index ff49a6d..5fa0429 100644
65003 --- a/init/main.c
65004 +++ b/init/main.c
65005 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65006 extern void tc_init(void);
65007 #endif
65008
65009 +extern void grsecurity_init(void);
65010 +
65011 /*
65012 * Debug helper: via this flag we know that we are in 'early bootup code'
65013 * where only the boot processor is running with IRQ disabled. This means
65014 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65015
65016 __setup("reset_devices", set_reset_devices);
65017
65018 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65019 +extern char pax_enter_kernel_user[];
65020 +extern char pax_exit_kernel_user[];
65021 +extern pgdval_t clone_pgd_mask;
65022 +#endif
65023 +
65024 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65025 +static int __init setup_pax_nouderef(char *str)
65026 +{
65027 +#ifdef CONFIG_X86_32
65028 + unsigned int cpu;
65029 + struct desc_struct *gdt;
65030 +
65031 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65032 + gdt = get_cpu_gdt_table(cpu);
65033 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65034 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65035 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65036 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65037 + }
65038 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65039 +#else
65040 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65041 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65042 + clone_pgd_mask = ~(pgdval_t)0UL;
65043 +#endif
65044 +
65045 + return 0;
65046 +}
65047 +early_param("pax_nouderef", setup_pax_nouderef);
65048 +#endif
65049 +
65050 +#ifdef CONFIG_PAX_SOFTMODE
65051 +int pax_softmode;
65052 +
65053 +static int __init setup_pax_softmode(char *str)
65054 +{
65055 + get_option(&str, &pax_softmode);
65056 + return 1;
65057 +}
65058 +__setup("pax_softmode=", setup_pax_softmode);
65059 +#endif
65060 +
65061 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65062 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65063 static const char *panic_later, *panic_param;
65064 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65065 {
65066 int count = preempt_count();
65067 int ret;
65068 + const char *msg1 = "", *msg2 = "";
65069
65070 if (initcall_debug)
65071 ret = do_one_initcall_debug(fn);
65072 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65073 sprintf(msgbuf, "error code %d ", ret);
65074
65075 if (preempt_count() != count) {
65076 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65077 + msg1 = " preemption imbalance";
65078 preempt_count() = count;
65079 }
65080 if (irqs_disabled()) {
65081 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65082 + msg2 = " disabled interrupts";
65083 local_irq_enable();
65084 }
65085 - if (msgbuf[0]) {
65086 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65087 + if (msgbuf[0] || *msg1 || *msg2) {
65088 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65089 }
65090
65091 return ret;
65092 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65093 do_basic_setup();
65094
65095 /* Open the /dev/console on the rootfs, this should never fail */
65096 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65097 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65098 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65099
65100 (void) sys_dup(0);
65101 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65102 if (!ramdisk_execute_command)
65103 ramdisk_execute_command = "/init";
65104
65105 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65106 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65107 ramdisk_execute_command = NULL;
65108 prepare_namespace();
65109 }
65110
65111 + grsecurity_init();
65112 +
65113 /*
65114 * Ok, we have completed the initial bootup, and
65115 * we're essentially up and running. Get rid of the
65116 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65117 index 86ee272..773d937 100644
65118 --- a/ipc/mqueue.c
65119 +++ b/ipc/mqueue.c
65120 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65121 mq_bytes = (mq_msg_tblsz +
65122 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65123
65124 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65125 spin_lock(&mq_lock);
65126 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65127 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65128 diff --git a/ipc/msg.c b/ipc/msg.c
65129 index 7385de2..a8180e08 100644
65130 --- a/ipc/msg.c
65131 +++ b/ipc/msg.c
65132 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65133 return security_msg_queue_associate(msq, msgflg);
65134 }
65135
65136 +static struct ipc_ops msg_ops = {
65137 + .getnew = newque,
65138 + .associate = msg_security,
65139 + .more_checks = NULL
65140 +};
65141 +
65142 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65143 {
65144 struct ipc_namespace *ns;
65145 - struct ipc_ops msg_ops;
65146 struct ipc_params msg_params;
65147
65148 ns = current->nsproxy->ipc_ns;
65149
65150 - msg_ops.getnew = newque;
65151 - msg_ops.associate = msg_security;
65152 - msg_ops.more_checks = NULL;
65153 -
65154 msg_params.key = key;
65155 msg_params.flg = msgflg;
65156
65157 diff --git a/ipc/sem.c b/ipc/sem.c
65158 index 5215a81..cfc0cac 100644
65159 --- a/ipc/sem.c
65160 +++ b/ipc/sem.c
65161 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65162 return 0;
65163 }
65164
65165 +static struct ipc_ops sem_ops = {
65166 + .getnew = newary,
65167 + .associate = sem_security,
65168 + .more_checks = sem_more_checks
65169 +};
65170 +
65171 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65172 {
65173 struct ipc_namespace *ns;
65174 - struct ipc_ops sem_ops;
65175 struct ipc_params sem_params;
65176
65177 ns = current->nsproxy->ipc_ns;
65178 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65179 if (nsems < 0 || nsems > ns->sc_semmsl)
65180 return -EINVAL;
65181
65182 - sem_ops.getnew = newary;
65183 - sem_ops.associate = sem_security;
65184 - sem_ops.more_checks = sem_more_checks;
65185 -
65186 sem_params.key = key;
65187 sem_params.flg = semflg;
65188 sem_params.u.nsems = nsems;
65189 diff --git a/ipc/shm.c b/ipc/shm.c
65190 index b76be5b..859e750 100644
65191 --- a/ipc/shm.c
65192 +++ b/ipc/shm.c
65193 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65194 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65195 #endif
65196
65197 +#ifdef CONFIG_GRKERNSEC
65198 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65199 + const time_t shm_createtime, const uid_t cuid,
65200 + const int shmid);
65201 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65202 + const time_t shm_createtime);
65203 +#endif
65204 +
65205 void shm_init_ns(struct ipc_namespace *ns)
65206 {
65207 ns->shm_ctlmax = SHMMAX;
65208 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65209 shp->shm_lprid = 0;
65210 shp->shm_atim = shp->shm_dtim = 0;
65211 shp->shm_ctim = get_seconds();
65212 +#ifdef CONFIG_GRKERNSEC
65213 + {
65214 + struct timespec timeval;
65215 + do_posix_clock_monotonic_gettime(&timeval);
65216 +
65217 + shp->shm_createtime = timeval.tv_sec;
65218 + }
65219 +#endif
65220 shp->shm_segsz = size;
65221 shp->shm_nattch = 0;
65222 shp->shm_file = file;
65223 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65224 return 0;
65225 }
65226
65227 +static struct ipc_ops shm_ops = {
65228 + .getnew = newseg,
65229 + .associate = shm_security,
65230 + .more_checks = shm_more_checks
65231 +};
65232 +
65233 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65234 {
65235 struct ipc_namespace *ns;
65236 - struct ipc_ops shm_ops;
65237 struct ipc_params shm_params;
65238
65239 ns = current->nsproxy->ipc_ns;
65240
65241 - shm_ops.getnew = newseg;
65242 - shm_ops.associate = shm_security;
65243 - shm_ops.more_checks = shm_more_checks;
65244 -
65245 shm_params.key = key;
65246 shm_params.flg = shmflg;
65247 shm_params.u.size = size;
65248 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65249 f_mode = FMODE_READ | FMODE_WRITE;
65250 }
65251 if (shmflg & SHM_EXEC) {
65252 +
65253 +#ifdef CONFIG_PAX_MPROTECT
65254 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65255 + goto out;
65256 +#endif
65257 +
65258 prot |= PROT_EXEC;
65259 acc_mode |= S_IXUGO;
65260 }
65261 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65262 if (err)
65263 goto out_unlock;
65264
65265 +#ifdef CONFIG_GRKERNSEC
65266 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65267 + shp->shm_perm.cuid, shmid) ||
65268 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65269 + err = -EACCES;
65270 + goto out_unlock;
65271 + }
65272 +#endif
65273 +
65274 path = shp->shm_file->f_path;
65275 path_get(&path);
65276 shp->shm_nattch++;
65277 +#ifdef CONFIG_GRKERNSEC
65278 + shp->shm_lapid = current->pid;
65279 +#endif
65280 size = i_size_read(path.dentry->d_inode);
65281 shm_unlock(shp);
65282
65283 diff --git a/kernel/acct.c b/kernel/acct.c
65284 index 02e6167..54824f7 100644
65285 --- a/kernel/acct.c
65286 +++ b/kernel/acct.c
65287 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65288 */
65289 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65290 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65291 - file->f_op->write(file, (char *)&ac,
65292 + file->f_op->write(file, (char __force_user *)&ac,
65293 sizeof(acct_t), &file->f_pos);
65294 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65295 set_fs(fs);
65296 diff --git a/kernel/audit.c b/kernel/audit.c
65297 index bb0eb5b..cf2a03a 100644
65298 --- a/kernel/audit.c
65299 +++ b/kernel/audit.c
65300 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65301 3) suppressed due to audit_rate_limit
65302 4) suppressed due to audit_backlog_limit
65303 */
65304 -static atomic_t audit_lost = ATOMIC_INIT(0);
65305 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65306
65307 /* The netlink socket. */
65308 static struct sock *audit_sock;
65309 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65310 unsigned long now;
65311 int print;
65312
65313 - atomic_inc(&audit_lost);
65314 + atomic_inc_unchecked(&audit_lost);
65315
65316 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65317
65318 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65319 printk(KERN_WARNING
65320 "audit: audit_lost=%d audit_rate_limit=%d "
65321 "audit_backlog_limit=%d\n",
65322 - atomic_read(&audit_lost),
65323 + atomic_read_unchecked(&audit_lost),
65324 audit_rate_limit,
65325 audit_backlog_limit);
65326 audit_panic(message);
65327 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65328 status_set.pid = audit_pid;
65329 status_set.rate_limit = audit_rate_limit;
65330 status_set.backlog_limit = audit_backlog_limit;
65331 - status_set.lost = atomic_read(&audit_lost);
65332 + status_set.lost = atomic_read_unchecked(&audit_lost);
65333 status_set.backlog = skb_queue_len(&audit_skb_queue);
65334 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65335 &status_set, sizeof(status_set));
65336 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65337 index af1de0f..06dfe57 100644
65338 --- a/kernel/auditsc.c
65339 +++ b/kernel/auditsc.c
65340 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65341 }
65342
65343 /* global counter which is incremented every time something logs in */
65344 -static atomic_t session_id = ATOMIC_INIT(0);
65345 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65346
65347 /**
65348 * audit_set_loginuid - set current task's audit_context loginuid
65349 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65350 return -EPERM;
65351 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65352
65353 - sessionid = atomic_inc_return(&session_id);
65354 + sessionid = atomic_inc_return_unchecked(&session_id);
65355 if (context && context->in_syscall) {
65356 struct audit_buffer *ab;
65357
65358 diff --git a/kernel/capability.c b/kernel/capability.c
65359 index 3f1adb6..c564db0 100644
65360 --- a/kernel/capability.c
65361 +++ b/kernel/capability.c
65362 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65363 * before modification is attempted and the application
65364 * fails.
65365 */
65366 + if (tocopy > ARRAY_SIZE(kdata))
65367 + return -EFAULT;
65368 +
65369 if (copy_to_user(dataptr, kdata, tocopy
65370 * sizeof(struct __user_cap_data_struct))) {
65371 return -EFAULT;
65372 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65373 int ret;
65374
65375 rcu_read_lock();
65376 - ret = security_capable(__task_cred(t), ns, cap);
65377 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65378 + gr_task_is_capable(t, __task_cred(t), cap);
65379 rcu_read_unlock();
65380
65381 - return (ret == 0);
65382 + return ret;
65383 }
65384
65385 /**
65386 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65387 int ret;
65388
65389 rcu_read_lock();
65390 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65391 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65392 rcu_read_unlock();
65393
65394 - return (ret == 0);
65395 + return ret;
65396 }
65397
65398 /**
65399 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65400 BUG();
65401 }
65402
65403 - if (security_capable(current_cred(), ns, cap) == 0) {
65404 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65405 current->flags |= PF_SUPERPRIV;
65406 return true;
65407 }
65408 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65409 }
65410 EXPORT_SYMBOL(ns_capable);
65411
65412 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65413 +{
65414 + if (unlikely(!cap_valid(cap))) {
65415 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65416 + BUG();
65417 + }
65418 +
65419 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65420 + current->flags |= PF_SUPERPRIV;
65421 + return true;
65422 + }
65423 + return false;
65424 +}
65425 +EXPORT_SYMBOL(ns_capable_nolog);
65426 +
65427 /**
65428 * capable - Determine if the current task has a superior capability in effect
65429 * @cap: The capability to be tested for
65430 @@ -408,6 +427,12 @@ bool capable(int cap)
65431 }
65432 EXPORT_SYMBOL(capable);
65433
65434 +bool capable_nolog(int cap)
65435 +{
65436 + return ns_capable_nolog(&init_user_ns, cap);
65437 +}
65438 +EXPORT_SYMBOL(capable_nolog);
65439 +
65440 /**
65441 * nsown_capable - Check superior capability to one's own user_ns
65442 * @cap: The capability in question
65443 diff --git a/kernel/compat.c b/kernel/compat.c
65444 index f346ced..aa2b1f4 100644
65445 --- a/kernel/compat.c
65446 +++ b/kernel/compat.c
65447 @@ -13,6 +13,7 @@
65448
65449 #include <linux/linkage.h>
65450 #include <linux/compat.h>
65451 +#include <linux/module.h>
65452 #include <linux/errno.h>
65453 #include <linux/time.h>
65454 #include <linux/signal.h>
65455 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65456 mm_segment_t oldfs;
65457 long ret;
65458
65459 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65460 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65461 oldfs = get_fs();
65462 set_fs(KERNEL_DS);
65463 ret = hrtimer_nanosleep_restart(restart);
65464 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65465 oldfs = get_fs();
65466 set_fs(KERNEL_DS);
65467 ret = hrtimer_nanosleep(&tu,
65468 - rmtp ? (struct timespec __user *)&rmt : NULL,
65469 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65470 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65471 set_fs(oldfs);
65472
65473 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65474 mm_segment_t old_fs = get_fs();
65475
65476 set_fs(KERNEL_DS);
65477 - ret = sys_sigpending((old_sigset_t __user *) &s);
65478 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65479 set_fs(old_fs);
65480 if (ret == 0)
65481 ret = put_user(s, set);
65482 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65483 old_fs = get_fs();
65484 set_fs(KERNEL_DS);
65485 ret = sys_sigprocmask(how,
65486 - set ? (old_sigset_t __user *) &s : NULL,
65487 - oset ? (old_sigset_t __user *) &s : NULL);
65488 + set ? (old_sigset_t __force_user *) &s : NULL,
65489 + oset ? (old_sigset_t __force_user *) &s : NULL);
65490 set_fs(old_fs);
65491 if (ret == 0)
65492 if (oset)
65493 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65494 mm_segment_t old_fs = get_fs();
65495
65496 set_fs(KERNEL_DS);
65497 - ret = sys_old_getrlimit(resource, &r);
65498 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65499 set_fs(old_fs);
65500
65501 if (!ret) {
65502 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65503 mm_segment_t old_fs = get_fs();
65504
65505 set_fs(KERNEL_DS);
65506 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65507 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65508 set_fs(old_fs);
65509
65510 if (ret)
65511 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65512 set_fs (KERNEL_DS);
65513 ret = sys_wait4(pid,
65514 (stat_addr ?
65515 - (unsigned int __user *) &status : NULL),
65516 - options, (struct rusage __user *) &r);
65517 + (unsigned int __force_user *) &status : NULL),
65518 + options, (struct rusage __force_user *) &r);
65519 set_fs (old_fs);
65520
65521 if (ret > 0) {
65522 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65523 memset(&info, 0, sizeof(info));
65524
65525 set_fs(KERNEL_DS);
65526 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65527 - uru ? (struct rusage __user *)&ru : NULL);
65528 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65529 + uru ? (struct rusage __force_user *)&ru : NULL);
65530 set_fs(old_fs);
65531
65532 if ((ret < 0) || (info.si_signo == 0))
65533 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65534 oldfs = get_fs();
65535 set_fs(KERNEL_DS);
65536 err = sys_timer_settime(timer_id, flags,
65537 - (struct itimerspec __user *) &newts,
65538 - (struct itimerspec __user *) &oldts);
65539 + (struct itimerspec __force_user *) &newts,
65540 + (struct itimerspec __force_user *) &oldts);
65541 set_fs(oldfs);
65542 if (!err && old && put_compat_itimerspec(old, &oldts))
65543 return -EFAULT;
65544 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65545 oldfs = get_fs();
65546 set_fs(KERNEL_DS);
65547 err = sys_timer_gettime(timer_id,
65548 - (struct itimerspec __user *) &ts);
65549 + (struct itimerspec __force_user *) &ts);
65550 set_fs(oldfs);
65551 if (!err && put_compat_itimerspec(setting, &ts))
65552 return -EFAULT;
65553 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65554 oldfs = get_fs();
65555 set_fs(KERNEL_DS);
65556 err = sys_clock_settime(which_clock,
65557 - (struct timespec __user *) &ts);
65558 + (struct timespec __force_user *) &ts);
65559 set_fs(oldfs);
65560 return err;
65561 }
65562 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65563 oldfs = get_fs();
65564 set_fs(KERNEL_DS);
65565 err = sys_clock_gettime(which_clock,
65566 - (struct timespec __user *) &ts);
65567 + (struct timespec __force_user *) &ts);
65568 set_fs(oldfs);
65569 if (!err && put_compat_timespec(&ts, tp))
65570 return -EFAULT;
65571 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65572
65573 oldfs = get_fs();
65574 set_fs(KERNEL_DS);
65575 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65576 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65577 set_fs(oldfs);
65578
65579 err = compat_put_timex(utp, &txc);
65580 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65581 oldfs = get_fs();
65582 set_fs(KERNEL_DS);
65583 err = sys_clock_getres(which_clock,
65584 - (struct timespec __user *) &ts);
65585 + (struct timespec __force_user *) &ts);
65586 set_fs(oldfs);
65587 if (!err && tp && put_compat_timespec(&ts, tp))
65588 return -EFAULT;
65589 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65590 long err;
65591 mm_segment_t oldfs;
65592 struct timespec tu;
65593 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65594 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65595
65596 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65597 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65598 oldfs = get_fs();
65599 set_fs(KERNEL_DS);
65600 err = clock_nanosleep_restart(restart);
65601 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65602 oldfs = get_fs();
65603 set_fs(KERNEL_DS);
65604 err = sys_clock_nanosleep(which_clock, flags,
65605 - (struct timespec __user *) &in,
65606 - (struct timespec __user *) &out);
65607 + (struct timespec __force_user *) &in,
65608 + (struct timespec __force_user *) &out);
65609 set_fs(oldfs);
65610
65611 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65612 diff --git a/kernel/configs.c b/kernel/configs.c
65613 index 42e8fa0..9e7406b 100644
65614 --- a/kernel/configs.c
65615 +++ b/kernel/configs.c
65616 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65617 struct proc_dir_entry *entry;
65618
65619 /* create the current config file */
65620 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65621 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65622 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65623 + &ikconfig_file_ops);
65624 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65625 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65626 + &ikconfig_file_ops);
65627 +#endif
65628 +#else
65629 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65630 &ikconfig_file_ops);
65631 +#endif
65632 +
65633 if (!entry)
65634 return -ENOMEM;
65635
65636 diff --git a/kernel/cred.c b/kernel/cred.c
65637 index 48c6fd3..3342f00 100644
65638 --- a/kernel/cred.c
65639 +++ b/kernel/cred.c
65640 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65641 validate_creds(cred);
65642 put_cred(cred);
65643 }
65644 +
65645 +#ifdef CONFIG_GRKERNSEC_SETXID
65646 + cred = (struct cred *) tsk->delayed_cred;
65647 + if (cred) {
65648 + tsk->delayed_cred = NULL;
65649 + validate_creds(cred);
65650 + put_cred(cred);
65651 + }
65652 +#endif
65653 }
65654
65655 /**
65656 @@ -472,7 +481,7 @@ error_put:
65657 * Always returns 0 thus allowing this function to be tail-called at the end
65658 * of, say, sys_setgid().
65659 */
65660 -int commit_creds(struct cred *new)
65661 +static int __commit_creds(struct cred *new)
65662 {
65663 struct task_struct *task = current;
65664 const struct cred *old = task->real_cred;
65665 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65666
65667 get_cred(new); /* we will require a ref for the subj creds too */
65668
65669 + gr_set_role_label(task, new->uid, new->gid);
65670 +
65671 /* dumpability changes */
65672 if (old->euid != new->euid ||
65673 old->egid != new->egid ||
65674 @@ -540,6 +551,92 @@ int commit_creds(struct cred *new)
65675 put_cred(old);
65676 return 0;
65677 }
65678 +#ifdef CONFIG_GRKERNSEC_SETXID
65679 +extern int set_user(struct cred *new);
65680 +
65681 +void gr_delayed_cred_worker(void)
65682 +{
65683 + const struct cred *new = current->delayed_cred;
65684 + struct cred *ncred;
65685 +
65686 + current->delayed_cred = NULL;
65687 +
65688 + if (current_uid() && new != NULL) {
65689 + // from doing get_cred on it when queueing this
65690 + put_cred(new);
65691 + return;
65692 + } else if (new == NULL)
65693 + return;
65694 +
65695 + ncred = prepare_creds();
65696 + if (!ncred)
65697 + goto die;
65698 + // uids
65699 + ncred->uid = new->uid;
65700 + ncred->euid = new->euid;
65701 + ncred->suid = new->suid;
65702 + ncred->fsuid = new->fsuid;
65703 + // gids
65704 + ncred->gid = new->gid;
65705 + ncred->egid = new->egid;
65706 + ncred->sgid = new->sgid;
65707 + ncred->fsgid = new->fsgid;
65708 + // groups
65709 + if (set_groups(ncred, new->group_info) < 0) {
65710 + abort_creds(ncred);
65711 + goto die;
65712 + }
65713 + // caps
65714 + ncred->securebits = new->securebits;
65715 + ncred->cap_inheritable = new->cap_inheritable;
65716 + ncred->cap_permitted = new->cap_permitted;
65717 + ncred->cap_effective = new->cap_effective;
65718 + ncred->cap_bset = new->cap_bset;
65719 +
65720 + if (set_user(ncred)) {
65721 + abort_creds(ncred);
65722 + goto die;
65723 + }
65724 +
65725 + // from doing get_cred on it when queueing this
65726 + put_cred(new);
65727 +
65728 + __commit_creds(ncred);
65729 + return;
65730 +die:
65731 + // from doing get_cred on it when queueing this
65732 + put_cred(new);
65733 + do_group_exit(SIGKILL);
65734 +}
65735 +#endif
65736 +
65737 +int commit_creds(struct cred *new)
65738 +{
65739 +#ifdef CONFIG_GRKERNSEC_SETXID
65740 + struct task_struct *t;
65741 +
65742 + /* we won't get called with tasklist_lock held for writing
65743 + and interrupts disabled as the cred struct in that case is
65744 + init_cred
65745 + */
65746 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65747 + !current_uid() && new->uid) {
65748 + rcu_read_lock();
65749 + read_lock(&tasklist_lock);
65750 + for (t = next_thread(current); t != current;
65751 + t = next_thread(t)) {
65752 + if (t->delayed_cred == NULL) {
65753 + t->delayed_cred = get_cred(new);
65754 + set_tsk_need_resched(t);
65755 + }
65756 + }
65757 + read_unlock(&tasklist_lock);
65758 + rcu_read_unlock();
65759 + }
65760 +#endif
65761 + return __commit_creds(new);
65762 +}
65763 +
65764 EXPORT_SYMBOL(commit_creds);
65765
65766 /**
65767 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65768 index 7fda904..59f620c 100644
65769 --- a/kernel/debug/debug_core.c
65770 +++ b/kernel/debug/debug_core.c
65771 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65772 */
65773 static atomic_t masters_in_kgdb;
65774 static atomic_t slaves_in_kgdb;
65775 -static atomic_t kgdb_break_tasklet_var;
65776 +static atomic_unchecked_t kgdb_break_tasklet_var;
65777 atomic_t kgdb_setting_breakpoint;
65778
65779 struct task_struct *kgdb_usethread;
65780 @@ -129,7 +129,7 @@ int kgdb_single_step;
65781 static pid_t kgdb_sstep_pid;
65782
65783 /* to keep track of the CPU which is doing the single stepping*/
65784 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65785 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65786
65787 /*
65788 * If you are debugging a problem where roundup (the collection of
65789 @@ -537,7 +537,7 @@ return_normal:
65790 * kernel will only try for the value of sstep_tries before
65791 * giving up and continuing on.
65792 */
65793 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65794 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65795 (kgdb_info[cpu].task &&
65796 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65797 atomic_set(&kgdb_active, -1);
65798 @@ -631,8 +631,8 @@ cpu_master_loop:
65799 }
65800
65801 kgdb_restore:
65802 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65803 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65804 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65805 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65806 if (kgdb_info[sstep_cpu].task)
65807 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65808 else
65809 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65810 static void kgdb_tasklet_bpt(unsigned long ing)
65811 {
65812 kgdb_breakpoint();
65813 - atomic_set(&kgdb_break_tasklet_var, 0);
65814 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65815 }
65816
65817 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65818
65819 void kgdb_schedule_breakpoint(void)
65820 {
65821 - if (atomic_read(&kgdb_break_tasklet_var) ||
65822 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65823 atomic_read(&kgdb_active) != -1 ||
65824 atomic_read(&kgdb_setting_breakpoint))
65825 return;
65826 - atomic_inc(&kgdb_break_tasklet_var);
65827 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65828 tasklet_schedule(&kgdb_tasklet_breakpoint);
65829 }
65830 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65831 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65832 index e2ae734..08a4c5c 100644
65833 --- a/kernel/debug/kdb/kdb_main.c
65834 +++ b/kernel/debug/kdb/kdb_main.c
65835 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65836 list_for_each_entry(mod, kdb_modules, list) {
65837
65838 kdb_printf("%-20s%8u 0x%p ", mod->name,
65839 - mod->core_size, (void *)mod);
65840 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65841 #ifdef CONFIG_MODULE_UNLOAD
65842 kdb_printf("%4ld ", module_refcount(mod));
65843 #endif
65844 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65845 kdb_printf(" (Loading)");
65846 else
65847 kdb_printf(" (Live)");
65848 - kdb_printf(" 0x%p", mod->module_core);
65849 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65850
65851 #ifdef CONFIG_MODULE_UNLOAD
65852 {
65853 diff --git a/kernel/events/core.c b/kernel/events/core.c
65854 index 1b5c081..c375f83 100644
65855 --- a/kernel/events/core.c
65856 +++ b/kernel/events/core.c
65857 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65858 return 0;
65859 }
65860
65861 -static atomic64_t perf_event_id;
65862 +static atomic64_unchecked_t perf_event_id;
65863
65864 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65865 enum event_type_t event_type);
65866 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65867
65868 static inline u64 perf_event_count(struct perf_event *event)
65869 {
65870 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65871 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65872 }
65873
65874 static u64 perf_event_read(struct perf_event *event)
65875 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65876 mutex_lock(&event->child_mutex);
65877 total += perf_event_read(event);
65878 *enabled += event->total_time_enabled +
65879 - atomic64_read(&event->child_total_time_enabled);
65880 + atomic64_read_unchecked(&event->child_total_time_enabled);
65881 *running += event->total_time_running +
65882 - atomic64_read(&event->child_total_time_running);
65883 + atomic64_read_unchecked(&event->child_total_time_running);
65884
65885 list_for_each_entry(child, &event->child_list, child_list) {
65886 total += perf_event_read(child);
65887 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65888 userpg->offset -= local64_read(&event->hw.prev_count);
65889
65890 userpg->time_enabled = enabled +
65891 - atomic64_read(&event->child_total_time_enabled);
65892 + atomic64_read_unchecked(&event->child_total_time_enabled);
65893
65894 userpg->time_running = running +
65895 - atomic64_read(&event->child_total_time_running);
65896 + atomic64_read_unchecked(&event->child_total_time_running);
65897
65898 barrier();
65899 ++userpg->lock;
65900 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65901 values[n++] = perf_event_count(event);
65902 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65903 values[n++] = enabled +
65904 - atomic64_read(&event->child_total_time_enabled);
65905 + atomic64_read_unchecked(&event->child_total_time_enabled);
65906 }
65907 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65908 values[n++] = running +
65909 - atomic64_read(&event->child_total_time_running);
65910 + atomic64_read_unchecked(&event->child_total_time_running);
65911 }
65912 if (read_format & PERF_FORMAT_ID)
65913 values[n++] = primary_event_id(event);
65914 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65915 * need to add enough zero bytes after the string to handle
65916 * the 64bit alignment we do later.
65917 */
65918 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65919 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65920 if (!buf) {
65921 name = strncpy(tmp, "//enomem", sizeof(tmp));
65922 goto got_name;
65923 }
65924 - name = d_path(&file->f_path, buf, PATH_MAX);
65925 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65926 if (IS_ERR(name)) {
65927 name = strncpy(tmp, "//toolong", sizeof(tmp));
65928 goto got_name;
65929 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65930 event->parent = parent_event;
65931
65932 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65933 - event->id = atomic64_inc_return(&perf_event_id);
65934 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65935
65936 event->state = PERF_EVENT_STATE_INACTIVE;
65937
65938 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65939 /*
65940 * Add back the child's count to the parent's count:
65941 */
65942 - atomic64_add(child_val, &parent_event->child_count);
65943 - atomic64_add(child_event->total_time_enabled,
65944 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65945 + atomic64_add_unchecked(child_event->total_time_enabled,
65946 &parent_event->child_total_time_enabled);
65947 - atomic64_add(child_event->total_time_running,
65948 + atomic64_add_unchecked(child_event->total_time_running,
65949 &parent_event->child_total_time_running);
65950
65951 /*
65952 diff --git a/kernel/exit.c b/kernel/exit.c
65953 index 4b4042f..5bdd8d5 100644
65954 --- a/kernel/exit.c
65955 +++ b/kernel/exit.c
65956 @@ -58,6 +58,10 @@
65957 #include <asm/pgtable.h>
65958 #include <asm/mmu_context.h>
65959
65960 +#ifdef CONFIG_GRKERNSEC
65961 +extern rwlock_t grsec_exec_file_lock;
65962 +#endif
65963 +
65964 static void exit_mm(struct task_struct * tsk);
65965
65966 static void __unhash_process(struct task_struct *p, bool group_dead)
65967 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
65968 struct task_struct *leader;
65969 int zap_leader;
65970 repeat:
65971 +#ifdef CONFIG_NET
65972 + gr_del_task_from_ip_table(p);
65973 +#endif
65974 +
65975 /* don't need to get the RCU readlock here - the process is dead and
65976 * can't be modifying its own credentials. But shut RCU-lockdep up */
65977 rcu_read_lock();
65978 @@ -381,7 +389,7 @@ int allow_signal(int sig)
65979 * know it'll be handled, so that they don't get converted to
65980 * SIGKILL or just silently dropped.
65981 */
65982 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65983 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65984 recalc_sigpending();
65985 spin_unlock_irq(&current->sighand->siglock);
65986 return 0;
65987 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
65988 vsnprintf(current->comm, sizeof(current->comm), name, args);
65989 va_end(args);
65990
65991 +#ifdef CONFIG_GRKERNSEC
65992 + write_lock(&grsec_exec_file_lock);
65993 + if (current->exec_file) {
65994 + fput(current->exec_file);
65995 + current->exec_file = NULL;
65996 + }
65997 + write_unlock(&grsec_exec_file_lock);
65998 +#endif
65999 +
66000 + gr_set_kernel_label(current);
66001 +
66002 /*
66003 * If we were started as result of loading a module, close all of the
66004 * user space pages. We don't need them, and if we didn't close them
66005 @@ -892,6 +911,8 @@ void do_exit(long code)
66006 struct task_struct *tsk = current;
66007 int group_dead;
66008
66009 + set_fs(USER_DS);
66010 +
66011 profile_task_exit(tsk);
66012
66013 WARN_ON(blk_needs_flush_plug(tsk));
66014 @@ -908,7 +929,6 @@ void do_exit(long code)
66015 * mm_release()->clear_child_tid() from writing to a user-controlled
66016 * kernel address.
66017 */
66018 - set_fs(USER_DS);
66019
66020 ptrace_event(PTRACE_EVENT_EXIT, code);
66021
66022 @@ -969,6 +989,9 @@ void do_exit(long code)
66023 tsk->exit_code = code;
66024 taskstats_exit(tsk, group_dead);
66025
66026 + gr_acl_handle_psacct(tsk, code);
66027 + gr_acl_handle_exit();
66028 +
66029 exit_mm(tsk);
66030
66031 if (group_dead)
66032 @@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66033 * Take down every thread in the group. This is called by fatal signals
66034 * as well as by sys_exit_group (below).
66035 */
66036 -void
66037 +__noreturn void
66038 do_group_exit(int exit_code)
66039 {
66040 struct signal_struct *sig = current->signal;
66041 diff --git a/kernel/fork.c b/kernel/fork.c
66042 index 26a7a67..a1053f9 100644
66043 --- a/kernel/fork.c
66044 +++ b/kernel/fork.c
66045 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66046 *stackend = STACK_END_MAGIC; /* for overflow detection */
66047
66048 #ifdef CONFIG_CC_STACKPROTECTOR
66049 - tsk->stack_canary = get_random_int();
66050 + tsk->stack_canary = pax_get_random_long();
66051 #endif
66052
66053 /*
66054 @@ -308,13 +308,77 @@ out:
66055 }
66056
66057 #ifdef CONFIG_MMU
66058 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66059 +{
66060 + struct vm_area_struct *tmp;
66061 + unsigned long charge;
66062 + struct mempolicy *pol;
66063 + struct file *file;
66064 +
66065 + charge = 0;
66066 + if (mpnt->vm_flags & VM_ACCOUNT) {
66067 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66068 + if (security_vm_enough_memory(len))
66069 + goto fail_nomem;
66070 + charge = len;
66071 + }
66072 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66073 + if (!tmp)
66074 + goto fail_nomem;
66075 + *tmp = *mpnt;
66076 + tmp->vm_mm = mm;
66077 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66078 + pol = mpol_dup(vma_policy(mpnt));
66079 + if (IS_ERR(pol))
66080 + goto fail_nomem_policy;
66081 + vma_set_policy(tmp, pol);
66082 + if (anon_vma_fork(tmp, mpnt))
66083 + goto fail_nomem_anon_vma_fork;
66084 + tmp->vm_flags &= ~VM_LOCKED;
66085 + tmp->vm_next = tmp->vm_prev = NULL;
66086 + tmp->vm_mirror = NULL;
66087 + file = tmp->vm_file;
66088 + if (file) {
66089 + struct inode *inode = file->f_path.dentry->d_inode;
66090 + struct address_space *mapping = file->f_mapping;
66091 +
66092 + get_file(file);
66093 + if (tmp->vm_flags & VM_DENYWRITE)
66094 + atomic_dec(&inode->i_writecount);
66095 + mutex_lock(&mapping->i_mmap_mutex);
66096 + if (tmp->vm_flags & VM_SHARED)
66097 + mapping->i_mmap_writable++;
66098 + flush_dcache_mmap_lock(mapping);
66099 + /* insert tmp into the share list, just after mpnt */
66100 + vma_prio_tree_add(tmp, mpnt);
66101 + flush_dcache_mmap_unlock(mapping);
66102 + mutex_unlock(&mapping->i_mmap_mutex);
66103 + }
66104 +
66105 + /*
66106 + * Clear hugetlb-related page reserves for children. This only
66107 + * affects MAP_PRIVATE mappings. Faults generated by the child
66108 + * are not guaranteed to succeed, even if read-only
66109 + */
66110 + if (is_vm_hugetlb_page(tmp))
66111 + reset_vma_resv_huge_pages(tmp);
66112 +
66113 + return tmp;
66114 +
66115 +fail_nomem_anon_vma_fork:
66116 + mpol_put(pol);
66117 +fail_nomem_policy:
66118 + kmem_cache_free(vm_area_cachep, tmp);
66119 +fail_nomem:
66120 + vm_unacct_memory(charge);
66121 + return NULL;
66122 +}
66123 +
66124 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66125 {
66126 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66127 struct rb_node **rb_link, *rb_parent;
66128 int retval;
66129 - unsigned long charge;
66130 - struct mempolicy *pol;
66131
66132 down_write(&oldmm->mmap_sem);
66133 flush_cache_dup_mm(oldmm);
66134 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66135 mm->locked_vm = 0;
66136 mm->mmap = NULL;
66137 mm->mmap_cache = NULL;
66138 - mm->free_area_cache = oldmm->mmap_base;
66139 - mm->cached_hole_size = ~0UL;
66140 + mm->free_area_cache = oldmm->free_area_cache;
66141 + mm->cached_hole_size = oldmm->cached_hole_size;
66142 mm->map_count = 0;
66143 cpumask_clear(mm_cpumask(mm));
66144 mm->mm_rb = RB_ROOT;
66145 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66146
66147 prev = NULL;
66148 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66149 - struct file *file;
66150 -
66151 if (mpnt->vm_flags & VM_DONTCOPY) {
66152 long pages = vma_pages(mpnt);
66153 mm->total_vm -= pages;
66154 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66155 -pages);
66156 continue;
66157 }
66158 - charge = 0;
66159 - if (mpnt->vm_flags & VM_ACCOUNT) {
66160 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66161 - if (security_vm_enough_memory(len))
66162 - goto fail_nomem;
66163 - charge = len;
66164 + tmp = dup_vma(mm, mpnt);
66165 + if (!tmp) {
66166 + retval = -ENOMEM;
66167 + goto out;
66168 }
66169 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66170 - if (!tmp)
66171 - goto fail_nomem;
66172 - *tmp = *mpnt;
66173 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66174 - pol = mpol_dup(vma_policy(mpnt));
66175 - retval = PTR_ERR(pol);
66176 - if (IS_ERR(pol))
66177 - goto fail_nomem_policy;
66178 - vma_set_policy(tmp, pol);
66179 - tmp->vm_mm = mm;
66180 - if (anon_vma_fork(tmp, mpnt))
66181 - goto fail_nomem_anon_vma_fork;
66182 - tmp->vm_flags &= ~VM_LOCKED;
66183 - tmp->vm_next = tmp->vm_prev = NULL;
66184 - file = tmp->vm_file;
66185 - if (file) {
66186 - struct inode *inode = file->f_path.dentry->d_inode;
66187 - struct address_space *mapping = file->f_mapping;
66188 -
66189 - get_file(file);
66190 - if (tmp->vm_flags & VM_DENYWRITE)
66191 - atomic_dec(&inode->i_writecount);
66192 - mutex_lock(&mapping->i_mmap_mutex);
66193 - if (tmp->vm_flags & VM_SHARED)
66194 - mapping->i_mmap_writable++;
66195 - flush_dcache_mmap_lock(mapping);
66196 - /* insert tmp into the share list, just after mpnt */
66197 - vma_prio_tree_add(tmp, mpnt);
66198 - flush_dcache_mmap_unlock(mapping);
66199 - mutex_unlock(&mapping->i_mmap_mutex);
66200 - }
66201 -
66202 - /*
66203 - * Clear hugetlb-related page reserves for children. This only
66204 - * affects MAP_PRIVATE mappings. Faults generated by the child
66205 - * are not guaranteed to succeed, even if read-only
66206 - */
66207 - if (is_vm_hugetlb_page(tmp))
66208 - reset_vma_resv_huge_pages(tmp);
66209
66210 /*
66211 * Link in the new vma and copy the page table entries.
66212 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66213 if (retval)
66214 goto out;
66215 }
66216 +
66217 +#ifdef CONFIG_PAX_SEGMEXEC
66218 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66219 + struct vm_area_struct *mpnt_m;
66220 +
66221 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66222 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66223 +
66224 + if (!mpnt->vm_mirror)
66225 + continue;
66226 +
66227 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66228 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66229 + mpnt->vm_mirror = mpnt_m;
66230 + } else {
66231 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66232 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66233 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66234 + mpnt->vm_mirror->vm_mirror = mpnt;
66235 + }
66236 + }
66237 + BUG_ON(mpnt_m);
66238 + }
66239 +#endif
66240 +
66241 /* a new mm has just been created */
66242 arch_dup_mmap(oldmm, mm);
66243 retval = 0;
66244 @@ -429,14 +474,6 @@ out:
66245 flush_tlb_mm(oldmm);
66246 up_write(&oldmm->mmap_sem);
66247 return retval;
66248 -fail_nomem_anon_vma_fork:
66249 - mpol_put(pol);
66250 -fail_nomem_policy:
66251 - kmem_cache_free(vm_area_cachep, tmp);
66252 -fail_nomem:
66253 - retval = -ENOMEM;
66254 - vm_unacct_memory(charge);
66255 - goto out;
66256 }
66257
66258 static inline int mm_alloc_pgd(struct mm_struct *mm)
66259 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66260 return ERR_PTR(err);
66261
66262 mm = get_task_mm(task);
66263 - if (mm && mm != current->mm &&
66264 - !ptrace_may_access(task, mode)) {
66265 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66266 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66267 mmput(mm);
66268 mm = ERR_PTR(-EACCES);
66269 }
66270 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66271 spin_unlock(&fs->lock);
66272 return -EAGAIN;
66273 }
66274 - fs->users++;
66275 + atomic_inc(&fs->users);
66276 spin_unlock(&fs->lock);
66277 return 0;
66278 }
66279 tsk->fs = copy_fs_struct(fs);
66280 if (!tsk->fs)
66281 return -ENOMEM;
66282 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66283 return 0;
66284 }
66285
66286 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66287 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66288 #endif
66289 retval = -EAGAIN;
66290 +
66291 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66292 +
66293 if (atomic_read(&p->real_cred->user->processes) >=
66294 task_rlimit(p, RLIMIT_NPROC)) {
66295 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66296 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66297 if (clone_flags & CLONE_THREAD)
66298 p->tgid = current->tgid;
66299
66300 + gr_copy_label(p);
66301 +
66302 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66303 /*
66304 * Clear TID on mm_release()?
66305 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
66306 bad_fork_free:
66307 free_task(p);
66308 fork_out:
66309 + gr_log_forkfail(retval);
66310 +
66311 return ERR_PTR(retval);
66312 }
66313
66314 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
66315 if (clone_flags & CLONE_PARENT_SETTID)
66316 put_user(nr, parent_tidptr);
66317
66318 + gr_handle_brute_check();
66319 +
66320 if (clone_flags & CLONE_VFORK) {
66321 p->vfork_done = &vfork;
66322 init_completion(&vfork);
66323 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66324 return 0;
66325
66326 /* don't need lock here; in the worst case we'll do useless copy */
66327 - if (fs->users == 1)
66328 + if (atomic_read(&fs->users) == 1)
66329 return 0;
66330
66331 *new_fsp = copy_fs_struct(fs);
66332 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66333 fs = current->fs;
66334 spin_lock(&fs->lock);
66335 current->fs = new_fs;
66336 - if (--fs->users)
66337 + gr_set_chroot_entries(current, &current->fs->root);
66338 + if (atomic_dec_return(&fs->users))
66339 new_fs = NULL;
66340 else
66341 new_fs = fs;
66342 diff --git a/kernel/futex.c b/kernel/futex.c
66343 index 0677023..f3c3b79 100644
66344 --- a/kernel/futex.c
66345 +++ b/kernel/futex.c
66346 @@ -54,6 +54,7 @@
66347 #include <linux/mount.h>
66348 #include <linux/pagemap.h>
66349 #include <linux/syscalls.h>
66350 +#include <linux/ptrace.h>
66351 #include <linux/signal.h>
66352 #include <linux/export.h>
66353 #include <linux/magic.h>
66354 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66355 struct page *page, *page_head;
66356 int err, ro = 0;
66357
66358 +#ifdef CONFIG_PAX_SEGMEXEC
66359 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66360 + return -EFAULT;
66361 +#endif
66362 +
66363 /*
66364 * The futex address must be "naturally" aligned.
66365 */
66366 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66367 if (!p)
66368 goto err_unlock;
66369 ret = -EPERM;
66370 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66371 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66372 + goto err_unlock;
66373 +#endif
66374 pcred = __task_cred(p);
66375 /* If victim is in different user_ns, then uids are not
66376 comparable, so we must have CAP_SYS_PTRACE */
66377 @@ -2731,6 +2741,7 @@ static int __init futex_init(void)
66378 {
66379 u32 curval;
66380 int i;
66381 + mm_segment_t oldfs;
66382
66383 /*
66384 * This will fail and we want it. Some arch implementations do
66385 @@ -2742,8 +2753,11 @@ static int __init futex_init(void)
66386 * implementation, the non-functional ones will return
66387 * -ENOSYS.
66388 */
66389 + oldfs = get_fs();
66390 + set_fs(USER_DS);
66391 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66392 futex_cmpxchg_enabled = 1;
66393 + set_fs(oldfs);
66394
66395 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66396 plist_head_init(&futex_queues[i].chain);
66397 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66398 index 5f9e689..582d46d 100644
66399 --- a/kernel/futex_compat.c
66400 +++ b/kernel/futex_compat.c
66401 @@ -10,6 +10,7 @@
66402 #include <linux/compat.h>
66403 #include <linux/nsproxy.h>
66404 #include <linux/futex.h>
66405 +#include <linux/ptrace.h>
66406
66407 #include <asm/uaccess.h>
66408
66409 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66410 {
66411 struct compat_robust_list_head __user *head;
66412 unsigned long ret;
66413 - const struct cred *cred = current_cred(), *pcred;
66414 + const struct cred *cred = current_cred();
66415 + const struct cred *pcred;
66416
66417 if (!futex_cmpxchg_enabled)
66418 return -ENOSYS;
66419 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66420 if (!p)
66421 goto err_unlock;
66422 ret = -EPERM;
66423 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66424 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66425 + goto err_unlock;
66426 +#endif
66427 pcred = __task_cred(p);
66428 /* If victim is in different user_ns, then uids are not
66429 comparable, so we must have CAP_SYS_PTRACE */
66430 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66431 index 9b22d03..6295b62 100644
66432 --- a/kernel/gcov/base.c
66433 +++ b/kernel/gcov/base.c
66434 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66435 }
66436
66437 #ifdef CONFIG_MODULES
66438 -static inline int within(void *addr, void *start, unsigned long size)
66439 -{
66440 - return ((addr >= start) && (addr < start + size));
66441 -}
66442 -
66443 /* Update list and generate events when modules are unloaded. */
66444 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66445 void *data)
66446 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66447 prev = NULL;
66448 /* Remove entries located in module from linked list. */
66449 for (info = gcov_info_head; info; info = info->next) {
66450 - if (within(info, mod->module_core, mod->core_size)) {
66451 + if (within_module_core_rw((unsigned long)info, mod)) {
66452 if (prev)
66453 prev->next = info->next;
66454 else
66455 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66456 index ae34bf5..4e2f3d0 100644
66457 --- a/kernel/hrtimer.c
66458 +++ b/kernel/hrtimer.c
66459 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66460 local_irq_restore(flags);
66461 }
66462
66463 -static void run_hrtimer_softirq(struct softirq_action *h)
66464 +static void run_hrtimer_softirq(void)
66465 {
66466 hrtimer_peek_ahead_timers();
66467 }
66468 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66469 index 01d3b70..9e4d098 100644
66470 --- a/kernel/jump_label.c
66471 +++ b/kernel/jump_label.c
66472 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66473
66474 size = (((unsigned long)stop - (unsigned long)start)
66475 / sizeof(struct jump_entry));
66476 + pax_open_kernel();
66477 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66478 + pax_close_kernel();
66479 }
66480
66481 static void jump_label_update(struct jump_label_key *key, int enable);
66482 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66483 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66484 struct jump_entry *iter;
66485
66486 + pax_open_kernel();
66487 for (iter = iter_start; iter < iter_stop; iter++) {
66488 if (within_module_init(iter->code, mod))
66489 iter->code = 0;
66490 }
66491 + pax_close_kernel();
66492 }
66493
66494 static int
66495 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66496 index 079f1d3..a407562 100644
66497 --- a/kernel/kallsyms.c
66498 +++ b/kernel/kallsyms.c
66499 @@ -11,6 +11,9 @@
66500 * Changed the compression method from stem compression to "table lookup"
66501 * compression (see scripts/kallsyms.c for a more complete description)
66502 */
66503 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66504 +#define __INCLUDED_BY_HIDESYM 1
66505 +#endif
66506 #include <linux/kallsyms.h>
66507 #include <linux/module.h>
66508 #include <linux/init.h>
66509 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66510
66511 static inline int is_kernel_inittext(unsigned long addr)
66512 {
66513 + if (system_state != SYSTEM_BOOTING)
66514 + return 0;
66515 +
66516 if (addr >= (unsigned long)_sinittext
66517 && addr <= (unsigned long)_einittext)
66518 return 1;
66519 return 0;
66520 }
66521
66522 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66523 +#ifdef CONFIG_MODULES
66524 +static inline int is_module_text(unsigned long addr)
66525 +{
66526 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66527 + return 1;
66528 +
66529 + addr = ktla_ktva(addr);
66530 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66531 +}
66532 +#else
66533 +static inline int is_module_text(unsigned long addr)
66534 +{
66535 + return 0;
66536 +}
66537 +#endif
66538 +#endif
66539 +
66540 static inline int is_kernel_text(unsigned long addr)
66541 {
66542 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66543 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66544
66545 static inline int is_kernel(unsigned long addr)
66546 {
66547 +
66548 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66549 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66550 + return 1;
66551 +
66552 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66553 +#else
66554 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66555 +#endif
66556 +
66557 return 1;
66558 return in_gate_area_no_mm(addr);
66559 }
66560
66561 static int is_ksym_addr(unsigned long addr)
66562 {
66563 +
66564 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66565 + if (is_module_text(addr))
66566 + return 0;
66567 +#endif
66568 +
66569 if (all_var)
66570 return is_kernel(addr);
66571
66572 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66573
66574 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66575 {
66576 - iter->name[0] = '\0';
66577 iter->nameoff = get_symbol_offset(new_pos);
66578 iter->pos = new_pos;
66579 }
66580 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66581 {
66582 struct kallsym_iter *iter = m->private;
66583
66584 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66585 + if (current_uid())
66586 + return 0;
66587 +#endif
66588 +
66589 /* Some debugging symbols have no name. Ignore them. */
66590 if (!iter->name[0])
66591 return 0;
66592 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66593 struct kallsym_iter *iter;
66594 int ret;
66595
66596 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66597 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66598 if (!iter)
66599 return -ENOMEM;
66600 reset_iter(iter, 0);
66601 diff --git a/kernel/kexec.c b/kernel/kexec.c
66602 index 7b08867..3bac516 100644
66603 --- a/kernel/kexec.c
66604 +++ b/kernel/kexec.c
66605 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66606 unsigned long flags)
66607 {
66608 struct compat_kexec_segment in;
66609 - struct kexec_segment out, __user *ksegments;
66610 + struct kexec_segment out;
66611 + struct kexec_segment __user *ksegments;
66612 unsigned long i, result;
66613
66614 /* Don't allow clients that don't understand the native
66615 diff --git a/kernel/kmod.c b/kernel/kmod.c
66616 index a3a46cb..f2e42f8 100644
66617 --- a/kernel/kmod.c
66618 +++ b/kernel/kmod.c
66619 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66620 * If module auto-loading support is disabled then this function
66621 * becomes a no-operation.
66622 */
66623 -int __request_module(bool wait, const char *fmt, ...)
66624 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66625 {
66626 - va_list args;
66627 char module_name[MODULE_NAME_LEN];
66628 unsigned int max_modprobes;
66629 int ret;
66630 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66631 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66632 static char *envp[] = { "HOME=/",
66633 "TERM=linux",
66634 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66635 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66636 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66637 static int kmod_loop_msg;
66638
66639 - va_start(args, fmt);
66640 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66641 - va_end(args);
66642 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66643 if (ret >= MODULE_NAME_LEN)
66644 return -ENAMETOOLONG;
66645
66646 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66647 if (ret)
66648 return ret;
66649
66650 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66651 + if (!current_uid()) {
66652 + /* hack to workaround consolekit/udisks stupidity */
66653 + read_lock(&tasklist_lock);
66654 + if (!strcmp(current->comm, "mount") &&
66655 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66656 + read_unlock(&tasklist_lock);
66657 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66658 + return -EPERM;
66659 + }
66660 + read_unlock(&tasklist_lock);
66661 + }
66662 +#endif
66663 +
66664 /* If modprobe needs a service that is in a module, we get a recursive
66665 * loop. Limit the number of running kmod threads to max_threads/2 or
66666 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66667 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66668 atomic_dec(&kmod_concurrent);
66669 return ret;
66670 }
66671 +
66672 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66673 +{
66674 + va_list args;
66675 + int ret;
66676 +
66677 + va_start(args, fmt);
66678 + ret = ____request_module(wait, module_param, fmt, args);
66679 + va_end(args);
66680 +
66681 + return ret;
66682 +}
66683 +
66684 +int __request_module(bool wait, const char *fmt, ...)
66685 +{
66686 + va_list args;
66687 + int ret;
66688 +
66689 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66690 + if (current_uid()) {
66691 + char module_param[MODULE_NAME_LEN];
66692 +
66693 + memset(module_param, 0, sizeof(module_param));
66694 +
66695 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66696 +
66697 + va_start(args, fmt);
66698 + ret = ____request_module(wait, module_param, fmt, args);
66699 + va_end(args);
66700 +
66701 + return ret;
66702 + }
66703 +#endif
66704 +
66705 + va_start(args, fmt);
66706 + ret = ____request_module(wait, NULL, fmt, args);
66707 + va_end(args);
66708 +
66709 + return ret;
66710 +}
66711 +
66712 EXPORT_SYMBOL(__request_module);
66713 #endif /* CONFIG_MODULES */
66714
66715 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66716 *
66717 * Thus the __user pointer cast is valid here.
66718 */
66719 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66720 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66721
66722 /*
66723 * If ret is 0, either ____call_usermodehelper failed and the
66724 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66725 index c62b854..cb67968 100644
66726 --- a/kernel/kprobes.c
66727 +++ b/kernel/kprobes.c
66728 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66729 * kernel image and loaded module images reside. This is required
66730 * so x86_64 can correctly handle the %rip-relative fixups.
66731 */
66732 - kip->insns = module_alloc(PAGE_SIZE);
66733 + kip->insns = module_alloc_exec(PAGE_SIZE);
66734 if (!kip->insns) {
66735 kfree(kip);
66736 return NULL;
66737 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66738 */
66739 if (!list_is_singular(&kip->list)) {
66740 list_del(&kip->list);
66741 - module_free(NULL, kip->insns);
66742 + module_free_exec(NULL, kip->insns);
66743 kfree(kip);
66744 }
66745 return 1;
66746 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66747 {
66748 int i, err = 0;
66749 unsigned long offset = 0, size = 0;
66750 - char *modname, namebuf[128];
66751 + char *modname, namebuf[KSYM_NAME_LEN];
66752 const char *symbol_name;
66753 void *addr;
66754 struct kprobe_blackpoint *kb;
66755 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66756 const char *sym = NULL;
66757 unsigned int i = *(loff_t *) v;
66758 unsigned long offset = 0;
66759 - char *modname, namebuf[128];
66760 + char *modname, namebuf[KSYM_NAME_LEN];
66761
66762 head = &kprobe_table[i];
66763 preempt_disable();
66764 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66765 index 4e316e1..5501eef 100644
66766 --- a/kernel/ksysfs.c
66767 +++ b/kernel/ksysfs.c
66768 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66769 {
66770 if (count+1 > UEVENT_HELPER_PATH_LEN)
66771 return -ENOENT;
66772 + if (!capable(CAP_SYS_ADMIN))
66773 + return -EPERM;
66774 memcpy(uevent_helper, buf, count);
66775 uevent_helper[count] = '\0';
66776 if (count && uevent_helper[count-1] == '\n')
66777 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66778 index 8889f7d..95319b7 100644
66779 --- a/kernel/lockdep.c
66780 +++ b/kernel/lockdep.c
66781 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66782 end = (unsigned long) &_end,
66783 addr = (unsigned long) obj;
66784
66785 +#ifdef CONFIG_PAX_KERNEXEC
66786 + start = ktla_ktva(start);
66787 +#endif
66788 +
66789 /*
66790 * static variable?
66791 */
66792 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66793 if (!static_obj(lock->key)) {
66794 debug_locks_off();
66795 printk("INFO: trying to register non-static key.\n");
66796 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66797 printk("the code is fine but needs lockdep annotation.\n");
66798 printk("turning off the locking correctness validator.\n");
66799 dump_stack();
66800 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66801 if (!class)
66802 return 0;
66803 }
66804 - atomic_inc((atomic_t *)&class->ops);
66805 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66806 if (very_verbose(class)) {
66807 printk("\nacquire class [%p] %s", class->key, class->name);
66808 if (class->name_version > 1)
66809 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66810 index 91c32a0..b2c71c5 100644
66811 --- a/kernel/lockdep_proc.c
66812 +++ b/kernel/lockdep_proc.c
66813 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66814
66815 static void print_name(struct seq_file *m, struct lock_class *class)
66816 {
66817 - char str[128];
66818 + char str[KSYM_NAME_LEN];
66819 const char *name = class->name;
66820
66821 if (!name) {
66822 diff --git a/kernel/module.c b/kernel/module.c
66823 index 3d56b6f..2a22bd0 100644
66824 --- a/kernel/module.c
66825 +++ b/kernel/module.c
66826 @@ -58,6 +58,7 @@
66827 #include <linux/jump_label.h>
66828 #include <linux/pfn.h>
66829 #include <linux/bsearch.h>
66830 +#include <linux/grsecurity.h>
66831
66832 #define CREATE_TRACE_POINTS
66833 #include <trace/events/module.h>
66834 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66835
66836 /* Bounds of module allocation, for speeding __module_address.
66837 * Protected by module_mutex. */
66838 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66839 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66840 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66841
66842 int register_module_notifier(struct notifier_block * nb)
66843 {
66844 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66845 return true;
66846
66847 list_for_each_entry_rcu(mod, &modules, list) {
66848 - struct symsearch arr[] = {
66849 + struct symsearch modarr[] = {
66850 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66851 NOT_GPL_ONLY, false },
66852 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66853 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66854 #endif
66855 };
66856
66857 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66858 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66859 return true;
66860 }
66861 return false;
66862 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66863 static int percpu_modalloc(struct module *mod,
66864 unsigned long size, unsigned long align)
66865 {
66866 - if (align > PAGE_SIZE) {
66867 + if (align-1 >= PAGE_SIZE) {
66868 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66869 mod->name, align, PAGE_SIZE);
66870 align = PAGE_SIZE;
66871 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66872 static ssize_t show_coresize(struct module_attribute *mattr,
66873 struct module_kobject *mk, char *buffer)
66874 {
66875 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66876 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66877 }
66878
66879 static struct module_attribute modinfo_coresize =
66880 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66881 static ssize_t show_initsize(struct module_attribute *mattr,
66882 struct module_kobject *mk, char *buffer)
66883 {
66884 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66885 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66886 }
66887
66888 static struct module_attribute modinfo_initsize =
66889 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66890 */
66891 #ifdef CONFIG_SYSFS
66892
66893 -#ifdef CONFIG_KALLSYMS
66894 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66895 static inline bool sect_empty(const Elf_Shdr *sect)
66896 {
66897 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66898 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66899
66900 static void unset_module_core_ro_nx(struct module *mod)
66901 {
66902 - set_page_attributes(mod->module_core + mod->core_text_size,
66903 - mod->module_core + mod->core_size,
66904 + set_page_attributes(mod->module_core_rw,
66905 + mod->module_core_rw + mod->core_size_rw,
66906 set_memory_x);
66907 - set_page_attributes(mod->module_core,
66908 - mod->module_core + mod->core_ro_size,
66909 + set_page_attributes(mod->module_core_rx,
66910 + mod->module_core_rx + mod->core_size_rx,
66911 set_memory_rw);
66912 }
66913
66914 static void unset_module_init_ro_nx(struct module *mod)
66915 {
66916 - set_page_attributes(mod->module_init + mod->init_text_size,
66917 - mod->module_init + mod->init_size,
66918 + set_page_attributes(mod->module_init_rw,
66919 + mod->module_init_rw + mod->init_size_rw,
66920 set_memory_x);
66921 - set_page_attributes(mod->module_init,
66922 - mod->module_init + mod->init_ro_size,
66923 + set_page_attributes(mod->module_init_rx,
66924 + mod->module_init_rx + mod->init_size_rx,
66925 set_memory_rw);
66926 }
66927
66928 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66929
66930 mutex_lock(&module_mutex);
66931 list_for_each_entry_rcu(mod, &modules, list) {
66932 - if ((mod->module_core) && (mod->core_text_size)) {
66933 - set_page_attributes(mod->module_core,
66934 - mod->module_core + mod->core_text_size,
66935 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66936 + set_page_attributes(mod->module_core_rx,
66937 + mod->module_core_rx + mod->core_size_rx,
66938 set_memory_rw);
66939 }
66940 - if ((mod->module_init) && (mod->init_text_size)) {
66941 - set_page_attributes(mod->module_init,
66942 - mod->module_init + mod->init_text_size,
66943 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66944 + set_page_attributes(mod->module_init_rx,
66945 + mod->module_init_rx + mod->init_size_rx,
66946 set_memory_rw);
66947 }
66948 }
66949 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66950
66951 mutex_lock(&module_mutex);
66952 list_for_each_entry_rcu(mod, &modules, list) {
66953 - if ((mod->module_core) && (mod->core_text_size)) {
66954 - set_page_attributes(mod->module_core,
66955 - mod->module_core + mod->core_text_size,
66956 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66957 + set_page_attributes(mod->module_core_rx,
66958 + mod->module_core_rx + mod->core_size_rx,
66959 set_memory_ro);
66960 }
66961 - if ((mod->module_init) && (mod->init_text_size)) {
66962 - set_page_attributes(mod->module_init,
66963 - mod->module_init + mod->init_text_size,
66964 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66965 + set_page_attributes(mod->module_init_rx,
66966 + mod->module_init_rx + mod->init_size_rx,
66967 set_memory_ro);
66968 }
66969 }
66970 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66971
66972 /* This may be NULL, but that's OK */
66973 unset_module_init_ro_nx(mod);
66974 - module_free(mod, mod->module_init);
66975 + module_free(mod, mod->module_init_rw);
66976 + module_free_exec(mod, mod->module_init_rx);
66977 kfree(mod->args);
66978 percpu_modfree(mod);
66979
66980 /* Free lock-classes: */
66981 - lockdep_free_key_range(mod->module_core, mod->core_size);
66982 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66983 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66984
66985 /* Finally, free the core (containing the module structure) */
66986 unset_module_core_ro_nx(mod);
66987 - module_free(mod, mod->module_core);
66988 + module_free_exec(mod, mod->module_core_rx);
66989 + module_free(mod, mod->module_core_rw);
66990
66991 #ifdef CONFIG_MPU
66992 update_protections(current->mm);
66993 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66994 unsigned int i;
66995 int ret = 0;
66996 const struct kernel_symbol *ksym;
66997 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66998 + int is_fs_load = 0;
66999 + int register_filesystem_found = 0;
67000 + char *p;
67001 +
67002 + p = strstr(mod->args, "grsec_modharden_fs");
67003 + if (p) {
67004 + char *endptr = p + strlen("grsec_modharden_fs");
67005 + /* copy \0 as well */
67006 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67007 + is_fs_load = 1;
67008 + }
67009 +#endif
67010
67011 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67012 const char *name = info->strtab + sym[i].st_name;
67013
67014 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67015 + /* it's a real shame this will never get ripped and copied
67016 + upstream! ;(
67017 + */
67018 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67019 + register_filesystem_found = 1;
67020 +#endif
67021 +
67022 switch (sym[i].st_shndx) {
67023 case SHN_COMMON:
67024 /* We compiled with -fno-common. These are not
67025 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67026 ksym = resolve_symbol_wait(mod, info, name);
67027 /* Ok if resolved. */
67028 if (ksym && !IS_ERR(ksym)) {
67029 + pax_open_kernel();
67030 sym[i].st_value = ksym->value;
67031 + pax_close_kernel();
67032 break;
67033 }
67034
67035 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67036 secbase = (unsigned long)mod_percpu(mod);
67037 else
67038 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67039 + pax_open_kernel();
67040 sym[i].st_value += secbase;
67041 + pax_close_kernel();
67042 break;
67043 }
67044 }
67045
67046 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67047 + if (is_fs_load && !register_filesystem_found) {
67048 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67049 + ret = -EPERM;
67050 + }
67051 +#endif
67052 +
67053 return ret;
67054 }
67055
67056 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67057 || s->sh_entsize != ~0UL
67058 || strstarts(sname, ".init"))
67059 continue;
67060 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67061 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67062 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67063 + else
67064 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67065 pr_debug("\t%s\n", sname);
67066 }
67067 - switch (m) {
67068 - case 0: /* executable */
67069 - mod->core_size = debug_align(mod->core_size);
67070 - mod->core_text_size = mod->core_size;
67071 - break;
67072 - case 1: /* RO: text and ro-data */
67073 - mod->core_size = debug_align(mod->core_size);
67074 - mod->core_ro_size = mod->core_size;
67075 - break;
67076 - case 3: /* whole core */
67077 - mod->core_size = debug_align(mod->core_size);
67078 - break;
67079 - }
67080 }
67081
67082 pr_debug("Init section allocation order:\n");
67083 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67084 || s->sh_entsize != ~0UL
67085 || !strstarts(sname, ".init"))
67086 continue;
67087 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67088 - | INIT_OFFSET_MASK);
67089 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67090 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67091 + else
67092 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67093 + s->sh_entsize |= INIT_OFFSET_MASK;
67094 pr_debug("\t%s\n", sname);
67095 }
67096 - switch (m) {
67097 - case 0: /* executable */
67098 - mod->init_size = debug_align(mod->init_size);
67099 - mod->init_text_size = mod->init_size;
67100 - break;
67101 - case 1: /* RO: text and ro-data */
67102 - mod->init_size = debug_align(mod->init_size);
67103 - mod->init_ro_size = mod->init_size;
67104 - break;
67105 - case 3: /* whole init */
67106 - mod->init_size = debug_align(mod->init_size);
67107 - break;
67108 - }
67109 }
67110 }
67111
67112 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67113
67114 /* Put symbol section at end of init part of module. */
67115 symsect->sh_flags |= SHF_ALLOC;
67116 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67117 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67118 info->index.sym) | INIT_OFFSET_MASK;
67119 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67120
67121 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67122 }
67123
67124 /* Append room for core symbols at end of core part. */
67125 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67126 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67127 - mod->core_size += strtab_size;
67128 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67129 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67130 + mod->core_size_rx += strtab_size;
67131
67132 /* Put string table section at end of init part of module. */
67133 strsect->sh_flags |= SHF_ALLOC;
67134 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67135 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67136 info->index.str) | INIT_OFFSET_MASK;
67137 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67138 }
67139 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67140 /* Make sure we get permanent strtab: don't use info->strtab. */
67141 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67142
67143 + pax_open_kernel();
67144 +
67145 /* Set types up while we still have access to sections. */
67146 for (i = 0; i < mod->num_symtab; i++)
67147 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67148
67149 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67150 - mod->core_strtab = s = mod->module_core + info->stroffs;
67151 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67152 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67153 src = mod->symtab;
67154 *dst = *src;
67155 *s++ = 0;
67156 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67157 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67158 }
67159 mod->core_num_syms = ndst;
67160 +
67161 + pax_close_kernel();
67162 }
67163 #else
67164 static inline void layout_symtab(struct module *mod, struct load_info *info)
67165 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67166 return size == 0 ? NULL : vmalloc_exec(size);
67167 }
67168
67169 -static void *module_alloc_update_bounds(unsigned long size)
67170 +static void *module_alloc_update_bounds_rw(unsigned long size)
67171 {
67172 void *ret = module_alloc(size);
67173
67174 if (ret) {
67175 mutex_lock(&module_mutex);
67176 /* Update module bounds. */
67177 - if ((unsigned long)ret < module_addr_min)
67178 - module_addr_min = (unsigned long)ret;
67179 - if ((unsigned long)ret + size > module_addr_max)
67180 - module_addr_max = (unsigned long)ret + size;
67181 + if ((unsigned long)ret < module_addr_min_rw)
67182 + module_addr_min_rw = (unsigned long)ret;
67183 + if ((unsigned long)ret + size > module_addr_max_rw)
67184 + module_addr_max_rw = (unsigned long)ret + size;
67185 + mutex_unlock(&module_mutex);
67186 + }
67187 + return ret;
67188 +}
67189 +
67190 +static void *module_alloc_update_bounds_rx(unsigned long size)
67191 +{
67192 + void *ret = module_alloc_exec(size);
67193 +
67194 + if (ret) {
67195 + mutex_lock(&module_mutex);
67196 + /* Update module bounds. */
67197 + if ((unsigned long)ret < module_addr_min_rx)
67198 + module_addr_min_rx = (unsigned long)ret;
67199 + if ((unsigned long)ret + size > module_addr_max_rx)
67200 + module_addr_max_rx = (unsigned long)ret + size;
67201 mutex_unlock(&module_mutex);
67202 }
67203 return ret;
67204 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67205 static int check_modinfo(struct module *mod, struct load_info *info)
67206 {
67207 const char *modmagic = get_modinfo(info, "vermagic");
67208 + const char *license = get_modinfo(info, "license");
67209 int err;
67210
67211 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67212 + if (!license || !license_is_gpl_compatible(license))
67213 + return -ENOEXEC;
67214 +#endif
67215 +
67216 /* This is allowed: modprobe --force will invalidate it. */
67217 if (!modmagic) {
67218 err = try_to_force_load(mod, "bad vermagic");
67219 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67220 }
67221
67222 /* Set up license info based on the info section */
67223 - set_license(mod, get_modinfo(info, "license"));
67224 + set_license(mod, license);
67225
67226 return 0;
67227 }
67228 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67229 void *ptr;
67230
67231 /* Do the allocs. */
67232 - ptr = module_alloc_update_bounds(mod->core_size);
67233 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67234 /*
67235 * The pointer to this block is stored in the module structure
67236 * which is inside the block. Just mark it as not being a
67237 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67238 if (!ptr)
67239 return -ENOMEM;
67240
67241 - memset(ptr, 0, mod->core_size);
67242 - mod->module_core = ptr;
67243 + memset(ptr, 0, mod->core_size_rw);
67244 + mod->module_core_rw = ptr;
67245
67246 - ptr = module_alloc_update_bounds(mod->init_size);
67247 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67248 /*
67249 * The pointer to this block is stored in the module structure
67250 * which is inside the block. This block doesn't need to be
67251 * scanned as it contains data and code that will be freed
67252 * after the module is initialized.
67253 */
67254 - kmemleak_ignore(ptr);
67255 - if (!ptr && mod->init_size) {
67256 - module_free(mod, mod->module_core);
67257 + kmemleak_not_leak(ptr);
67258 + if (!ptr && mod->init_size_rw) {
67259 + module_free(mod, mod->module_core_rw);
67260 return -ENOMEM;
67261 }
67262 - memset(ptr, 0, mod->init_size);
67263 - mod->module_init = ptr;
67264 + memset(ptr, 0, mod->init_size_rw);
67265 + mod->module_init_rw = ptr;
67266 +
67267 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67268 + kmemleak_not_leak(ptr);
67269 + if (!ptr) {
67270 + module_free(mod, mod->module_init_rw);
67271 + module_free(mod, mod->module_core_rw);
67272 + return -ENOMEM;
67273 + }
67274 +
67275 + pax_open_kernel();
67276 + memset(ptr, 0, mod->core_size_rx);
67277 + pax_close_kernel();
67278 + mod->module_core_rx = ptr;
67279 +
67280 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67281 + kmemleak_not_leak(ptr);
67282 + if (!ptr && mod->init_size_rx) {
67283 + module_free_exec(mod, mod->module_core_rx);
67284 + module_free(mod, mod->module_init_rw);
67285 + module_free(mod, mod->module_core_rw);
67286 + return -ENOMEM;
67287 + }
67288 +
67289 + pax_open_kernel();
67290 + memset(ptr, 0, mod->init_size_rx);
67291 + pax_close_kernel();
67292 + mod->module_init_rx = ptr;
67293
67294 /* Transfer each section which specifies SHF_ALLOC */
67295 pr_debug("final section addresses:\n");
67296 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67297 if (!(shdr->sh_flags & SHF_ALLOC))
67298 continue;
67299
67300 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67301 - dest = mod->module_init
67302 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67303 - else
67304 - dest = mod->module_core + shdr->sh_entsize;
67305 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67306 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67307 + dest = mod->module_init_rw
67308 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67309 + else
67310 + dest = mod->module_init_rx
67311 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67312 + } else {
67313 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67314 + dest = mod->module_core_rw + shdr->sh_entsize;
67315 + else
67316 + dest = mod->module_core_rx + shdr->sh_entsize;
67317 + }
67318 +
67319 + if (shdr->sh_type != SHT_NOBITS) {
67320 +
67321 +#ifdef CONFIG_PAX_KERNEXEC
67322 +#ifdef CONFIG_X86_64
67323 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67324 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67325 +#endif
67326 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67327 + pax_open_kernel();
67328 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67329 + pax_close_kernel();
67330 + } else
67331 +#endif
67332
67333 - if (shdr->sh_type != SHT_NOBITS)
67334 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67335 + }
67336 /* Update sh_addr to point to copy in image. */
67337 - shdr->sh_addr = (unsigned long)dest;
67338 +
67339 +#ifdef CONFIG_PAX_KERNEXEC
67340 + if (shdr->sh_flags & SHF_EXECINSTR)
67341 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67342 + else
67343 +#endif
67344 +
67345 + shdr->sh_addr = (unsigned long)dest;
67346 pr_debug("\t0x%lx %s\n",
67347 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67348 }
67349 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67350 * Do it before processing of module parameters, so the module
67351 * can provide parameter accessor functions of its own.
67352 */
67353 - if (mod->module_init)
67354 - flush_icache_range((unsigned long)mod->module_init,
67355 - (unsigned long)mod->module_init
67356 - + mod->init_size);
67357 - flush_icache_range((unsigned long)mod->module_core,
67358 - (unsigned long)mod->module_core + mod->core_size);
67359 + if (mod->module_init_rx)
67360 + flush_icache_range((unsigned long)mod->module_init_rx,
67361 + (unsigned long)mod->module_init_rx
67362 + + mod->init_size_rx);
67363 + flush_icache_range((unsigned long)mod->module_core_rx,
67364 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67365
67366 set_fs(old_fs);
67367 }
67368 @@ -2802,8 +2901,10 @@ out:
67369 static void module_deallocate(struct module *mod, struct load_info *info)
67370 {
67371 percpu_modfree(mod);
67372 - module_free(mod, mod->module_init);
67373 - module_free(mod, mod->module_core);
67374 + module_free_exec(mod, mod->module_init_rx);
67375 + module_free_exec(mod, mod->module_core_rx);
67376 + module_free(mod, mod->module_init_rw);
67377 + module_free(mod, mod->module_core_rw);
67378 }
67379
67380 int __weak module_finalize(const Elf_Ehdr *hdr,
67381 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67382 if (err)
67383 goto free_unload;
67384
67385 + /* Now copy in args */
67386 + mod->args = strndup_user(uargs, ~0UL >> 1);
67387 + if (IS_ERR(mod->args)) {
67388 + err = PTR_ERR(mod->args);
67389 + goto free_unload;
67390 + }
67391 +
67392 /* Set up MODINFO_ATTR fields */
67393 setup_modinfo(mod, &info);
67394
67395 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67396 + {
67397 + char *p, *p2;
67398 +
67399 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67400 + 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);
67401 + err = -EPERM;
67402 + goto free_modinfo;
67403 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67404 + p += strlen("grsec_modharden_normal");
67405 + p2 = strstr(p, "_");
67406 + if (p2) {
67407 + *p2 = '\0';
67408 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67409 + *p2 = '_';
67410 + }
67411 + err = -EPERM;
67412 + goto free_modinfo;
67413 + }
67414 + }
67415 +#endif
67416 +
67417 /* Fix up syms, so that st_value is a pointer to location. */
67418 err = simplify_symbols(mod, &info);
67419 if (err < 0)
67420 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67421
67422 flush_module_icache(mod);
67423
67424 - /* Now copy in args */
67425 - mod->args = strndup_user(uargs, ~0UL >> 1);
67426 - if (IS_ERR(mod->args)) {
67427 - err = PTR_ERR(mod->args);
67428 - goto free_arch_cleanup;
67429 - }
67430 -
67431 /* Mark state as coming so strong_try_module_get() ignores us. */
67432 mod->state = MODULE_STATE_COMING;
67433
67434 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67435 unlock:
67436 mutex_unlock(&module_mutex);
67437 synchronize_sched();
67438 - kfree(mod->args);
67439 - free_arch_cleanup:
67440 module_arch_cleanup(mod);
67441 free_modinfo:
67442 free_modinfo(mod);
67443 + kfree(mod->args);
67444 free_unload:
67445 module_unload_free(mod);
67446 free_module:
67447 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67448 MODULE_STATE_COMING, mod);
67449
67450 /* Set RO and NX regions for core */
67451 - set_section_ro_nx(mod->module_core,
67452 - mod->core_text_size,
67453 - mod->core_ro_size,
67454 - mod->core_size);
67455 + set_section_ro_nx(mod->module_core_rx,
67456 + mod->core_size_rx,
67457 + mod->core_size_rx,
67458 + mod->core_size_rx);
67459
67460 /* Set RO and NX regions for init */
67461 - set_section_ro_nx(mod->module_init,
67462 - mod->init_text_size,
67463 - mod->init_ro_size,
67464 - mod->init_size);
67465 + set_section_ro_nx(mod->module_init_rx,
67466 + mod->init_size_rx,
67467 + mod->init_size_rx,
67468 + mod->init_size_rx);
67469
67470 do_mod_ctors(mod);
67471 /* Start the module */
67472 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67473 mod->strtab = mod->core_strtab;
67474 #endif
67475 unset_module_init_ro_nx(mod);
67476 - module_free(mod, mod->module_init);
67477 - mod->module_init = NULL;
67478 - mod->init_size = 0;
67479 - mod->init_ro_size = 0;
67480 - mod->init_text_size = 0;
67481 + module_free(mod, mod->module_init_rw);
67482 + module_free_exec(mod, mod->module_init_rx);
67483 + mod->module_init_rw = NULL;
67484 + mod->module_init_rx = NULL;
67485 + mod->init_size_rw = 0;
67486 + mod->init_size_rx = 0;
67487 mutex_unlock(&module_mutex);
67488
67489 return 0;
67490 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67491 unsigned long nextval;
67492
67493 /* At worse, next value is at end of module */
67494 - if (within_module_init(addr, mod))
67495 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67496 + if (within_module_init_rx(addr, mod))
67497 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67498 + else if (within_module_init_rw(addr, mod))
67499 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67500 + else if (within_module_core_rx(addr, mod))
67501 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67502 + else if (within_module_core_rw(addr, mod))
67503 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67504 else
67505 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67506 + return NULL;
67507
67508 /* Scan for closest preceding symbol, and next symbol. (ELF
67509 starts real symbols at 1). */
67510 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67511 char buf[8];
67512
67513 seq_printf(m, "%s %u",
67514 - mod->name, mod->init_size + mod->core_size);
67515 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67516 print_unload_info(m, mod);
67517
67518 /* Informative for users. */
67519 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67520 mod->state == MODULE_STATE_COMING ? "Loading":
67521 "Live");
67522 /* Used by oprofile and other similar tools. */
67523 - seq_printf(m, " 0x%pK", mod->module_core);
67524 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67525
67526 /* Taints info */
67527 if (mod->taints)
67528 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67529
67530 static int __init proc_modules_init(void)
67531 {
67532 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67533 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67534 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67535 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67536 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67537 +#else
67538 proc_create("modules", 0, NULL, &proc_modules_operations);
67539 +#endif
67540 +#else
67541 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67542 +#endif
67543 return 0;
67544 }
67545 module_init(proc_modules_init);
67546 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67547 {
67548 struct module *mod;
67549
67550 - if (addr < module_addr_min || addr > module_addr_max)
67551 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67552 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67553 return NULL;
67554
67555 list_for_each_entry_rcu(mod, &modules, list)
67556 - if (within_module_core(addr, mod)
67557 - || within_module_init(addr, mod))
67558 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67559 return mod;
67560 return NULL;
67561 }
67562 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67563 */
67564 struct module *__module_text_address(unsigned long addr)
67565 {
67566 - struct module *mod = __module_address(addr);
67567 + struct module *mod;
67568 +
67569 +#ifdef CONFIG_X86_32
67570 + addr = ktla_ktva(addr);
67571 +#endif
67572 +
67573 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67574 + return NULL;
67575 +
67576 + mod = __module_address(addr);
67577 +
67578 if (mod) {
67579 /* Make sure it's within the text section. */
67580 - if (!within(addr, mod->module_init, mod->init_text_size)
67581 - && !within(addr, mod->module_core, mod->core_text_size))
67582 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67583 mod = NULL;
67584 }
67585 return mod;
67586 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67587 index 7e3443f..b2a1e6b 100644
67588 --- a/kernel/mutex-debug.c
67589 +++ b/kernel/mutex-debug.c
67590 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67591 }
67592
67593 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67594 - struct thread_info *ti)
67595 + struct task_struct *task)
67596 {
67597 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67598
67599 /* Mark the current thread as blocked on the lock: */
67600 - ti->task->blocked_on = waiter;
67601 + task->blocked_on = waiter;
67602 }
67603
67604 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67605 - struct thread_info *ti)
67606 + struct task_struct *task)
67607 {
67608 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67609 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67610 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67611 - ti->task->blocked_on = NULL;
67612 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67613 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67614 + task->blocked_on = NULL;
67615
67616 list_del_init(&waiter->list);
67617 waiter->task = NULL;
67618 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67619 index 0799fd3..d06ae3b 100644
67620 --- a/kernel/mutex-debug.h
67621 +++ b/kernel/mutex-debug.h
67622 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67623 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67624 extern void debug_mutex_add_waiter(struct mutex *lock,
67625 struct mutex_waiter *waiter,
67626 - struct thread_info *ti);
67627 + struct task_struct *task);
67628 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67629 - struct thread_info *ti);
67630 + struct task_struct *task);
67631 extern void debug_mutex_unlock(struct mutex *lock);
67632 extern void debug_mutex_init(struct mutex *lock, const char *name,
67633 struct lock_class_key *key);
67634 diff --git a/kernel/mutex.c b/kernel/mutex.c
67635 index 89096dd..f91ebc5 100644
67636 --- a/kernel/mutex.c
67637 +++ b/kernel/mutex.c
67638 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67639 spin_lock_mutex(&lock->wait_lock, flags);
67640
67641 debug_mutex_lock_common(lock, &waiter);
67642 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67643 + debug_mutex_add_waiter(lock, &waiter, task);
67644
67645 /* add waiting tasks to the end of the waitqueue (FIFO): */
67646 list_add_tail(&waiter.list, &lock->wait_list);
67647 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67648 * TASK_UNINTERRUPTIBLE case.)
67649 */
67650 if (unlikely(signal_pending_state(state, task))) {
67651 - mutex_remove_waiter(lock, &waiter,
67652 - task_thread_info(task));
67653 + mutex_remove_waiter(lock, &waiter, task);
67654 mutex_release(&lock->dep_map, 1, ip);
67655 spin_unlock_mutex(&lock->wait_lock, flags);
67656
67657 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67658 done:
67659 lock_acquired(&lock->dep_map, ip);
67660 /* got the lock - rejoice! */
67661 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67662 + mutex_remove_waiter(lock, &waiter, task);
67663 mutex_set_owner(lock);
67664
67665 /* set it to 0 if there are no waiters left: */
67666 diff --git a/kernel/padata.c b/kernel/padata.c
67667 index b452599..5d68f4e 100644
67668 --- a/kernel/padata.c
67669 +++ b/kernel/padata.c
67670 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67671 padata->pd = pd;
67672 padata->cb_cpu = cb_cpu;
67673
67674 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67675 - atomic_set(&pd->seq_nr, -1);
67676 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67677 + atomic_set_unchecked(&pd->seq_nr, -1);
67678
67679 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67680 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67681
67682 target_cpu = padata_cpu_hash(padata);
67683 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67684 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67685 padata_init_pqueues(pd);
67686 padata_init_squeues(pd);
67687 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67688 - atomic_set(&pd->seq_nr, -1);
67689 + atomic_set_unchecked(&pd->seq_nr, -1);
67690 atomic_set(&pd->reorder_objects, 0);
67691 atomic_set(&pd->refcnt, 0);
67692 pd->pinst = pinst;
67693 diff --git a/kernel/panic.c b/kernel/panic.c
67694 index 80aed44..e83856a 100644
67695 --- a/kernel/panic.c
67696 +++ b/kernel/panic.c
67697 @@ -97,7 +97,7 @@ void panic(const char *fmt, ...)
67698 /*
67699 * Avoid nested stack-dumping if a panic occurs during oops processing
67700 */
67701 - if (!oops_in_progress)
67702 + if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
67703 dump_stack();
67704 #endif
67705
67706 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67707 const char *board;
67708
67709 printk(KERN_WARNING "------------[ cut here ]------------\n");
67710 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67711 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67712 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67713 if (board)
67714 printk(KERN_WARNING "Hardware name: %s\n", board);
67715 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67716 */
67717 void __stack_chk_fail(void)
67718 {
67719 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67720 + dump_stack();
67721 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67722 __builtin_return_address(0));
67723 }
67724 EXPORT_SYMBOL(__stack_chk_fail);
67725 diff --git a/kernel/pid.c b/kernel/pid.c
67726 index 9f08dfa..6765c40 100644
67727 --- a/kernel/pid.c
67728 +++ b/kernel/pid.c
67729 @@ -33,6 +33,7 @@
67730 #include <linux/rculist.h>
67731 #include <linux/bootmem.h>
67732 #include <linux/hash.h>
67733 +#include <linux/security.h>
67734 #include <linux/pid_namespace.h>
67735 #include <linux/init_task.h>
67736 #include <linux/syscalls.h>
67737 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67738
67739 int pid_max = PID_MAX_DEFAULT;
67740
67741 -#define RESERVED_PIDS 300
67742 +#define RESERVED_PIDS 500
67743
67744 int pid_max_min = RESERVED_PIDS + 1;
67745 int pid_max_max = PID_MAX_LIMIT;
67746 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67747 */
67748 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67749 {
67750 + struct task_struct *task;
67751 +
67752 rcu_lockdep_assert(rcu_read_lock_held(),
67753 "find_task_by_pid_ns() needs rcu_read_lock()"
67754 " protection");
67755 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67756 +
67757 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67758 +
67759 + if (gr_pid_is_chrooted(task))
67760 + return NULL;
67761 +
67762 + return task;
67763 }
67764
67765 struct task_struct *find_task_by_vpid(pid_t vnr)
67766 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67767 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67768 }
67769
67770 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67771 +{
67772 + rcu_lockdep_assert(rcu_read_lock_held(),
67773 + "find_task_by_pid_ns() needs rcu_read_lock()"
67774 + " protection");
67775 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67776 +}
67777 +
67778 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67779 {
67780 struct pid *pid;
67781 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67782 index 125cb67..a4d1c30 100644
67783 --- a/kernel/posix-cpu-timers.c
67784 +++ b/kernel/posix-cpu-timers.c
67785 @@ -6,6 +6,7 @@
67786 #include <linux/posix-timers.h>
67787 #include <linux/errno.h>
67788 #include <linux/math64.h>
67789 +#include <linux/security.h>
67790 #include <asm/uaccess.h>
67791 #include <linux/kernel_stat.h>
67792 #include <trace/events/timer.h>
67793 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67794
67795 static __init int init_posix_cpu_timers(void)
67796 {
67797 - struct k_clock process = {
67798 + static struct k_clock process = {
67799 .clock_getres = process_cpu_clock_getres,
67800 .clock_get = process_cpu_clock_get,
67801 .timer_create = process_cpu_timer_create,
67802 .nsleep = process_cpu_nsleep,
67803 .nsleep_restart = process_cpu_nsleep_restart,
67804 };
67805 - struct k_clock thread = {
67806 + static struct k_clock thread = {
67807 .clock_getres = thread_cpu_clock_getres,
67808 .clock_get = thread_cpu_clock_get,
67809 .timer_create = thread_cpu_timer_create,
67810 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67811 index 69185ae..cc2847a 100644
67812 --- a/kernel/posix-timers.c
67813 +++ b/kernel/posix-timers.c
67814 @@ -43,6 +43,7 @@
67815 #include <linux/idr.h>
67816 #include <linux/posix-clock.h>
67817 #include <linux/posix-timers.h>
67818 +#include <linux/grsecurity.h>
67819 #include <linux/syscalls.h>
67820 #include <linux/wait.h>
67821 #include <linux/workqueue.h>
67822 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67823 * which we beg off on and pass to do_sys_settimeofday().
67824 */
67825
67826 -static struct k_clock posix_clocks[MAX_CLOCKS];
67827 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67828
67829 /*
67830 * These ones are defined below.
67831 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67832 */
67833 static __init int init_posix_timers(void)
67834 {
67835 - struct k_clock clock_realtime = {
67836 + static struct k_clock clock_realtime = {
67837 .clock_getres = hrtimer_get_res,
67838 .clock_get = posix_clock_realtime_get,
67839 .clock_set = posix_clock_realtime_set,
67840 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67841 .timer_get = common_timer_get,
67842 .timer_del = common_timer_del,
67843 };
67844 - struct k_clock clock_monotonic = {
67845 + static struct k_clock clock_monotonic = {
67846 .clock_getres = hrtimer_get_res,
67847 .clock_get = posix_ktime_get_ts,
67848 .nsleep = common_nsleep,
67849 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67850 .timer_get = common_timer_get,
67851 .timer_del = common_timer_del,
67852 };
67853 - struct k_clock clock_monotonic_raw = {
67854 + static struct k_clock clock_monotonic_raw = {
67855 .clock_getres = hrtimer_get_res,
67856 .clock_get = posix_get_monotonic_raw,
67857 };
67858 - struct k_clock clock_realtime_coarse = {
67859 + static struct k_clock clock_realtime_coarse = {
67860 .clock_getres = posix_get_coarse_res,
67861 .clock_get = posix_get_realtime_coarse,
67862 };
67863 - struct k_clock clock_monotonic_coarse = {
67864 + static struct k_clock clock_monotonic_coarse = {
67865 .clock_getres = posix_get_coarse_res,
67866 .clock_get = posix_get_monotonic_coarse,
67867 };
67868 - struct k_clock clock_boottime = {
67869 + static struct k_clock clock_boottime = {
67870 .clock_getres = hrtimer_get_res,
67871 .clock_get = posix_get_boottime,
67872 .nsleep = common_nsleep,
67873 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67874 return;
67875 }
67876
67877 - posix_clocks[clock_id] = *new_clock;
67878 + posix_clocks[clock_id] = new_clock;
67879 }
67880 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67881
67882 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67883 return (id & CLOCKFD_MASK) == CLOCKFD ?
67884 &clock_posix_dynamic : &clock_posix_cpu;
67885
67886 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67887 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67888 return NULL;
67889 - return &posix_clocks[id];
67890 + return posix_clocks[id];
67891 }
67892
67893 static int common_timer_create(struct k_itimer *new_timer)
67894 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67895 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67896 return -EFAULT;
67897
67898 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67899 + have their clock_set fptr set to a nosettime dummy function
67900 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67901 + call common_clock_set, which calls do_sys_settimeofday, which
67902 + we hook
67903 + */
67904 +
67905 return kc->clock_set(which_clock, &new_tp);
67906 }
67907
67908 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67909 index d523593..68197a4 100644
67910 --- a/kernel/power/poweroff.c
67911 +++ b/kernel/power/poweroff.c
67912 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67913 .enable_mask = SYSRQ_ENABLE_BOOT,
67914 };
67915
67916 -static int pm_sysrq_init(void)
67917 +static int __init pm_sysrq_init(void)
67918 {
67919 register_sysrq_key('o', &sysrq_poweroff_op);
67920 return 0;
67921 diff --git a/kernel/power/process.c b/kernel/power/process.c
67922 index 7aac07a..2d3c6dc 100644
67923 --- a/kernel/power/process.c
67924 +++ b/kernel/power/process.c
67925 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67926 u64 elapsed_csecs64;
67927 unsigned int elapsed_csecs;
67928 bool wakeup = false;
67929 + bool timedout = false;
67930
67931 do_gettimeofday(&start);
67932
67933 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67934
67935 while (true) {
67936 todo = 0;
67937 + if (time_after(jiffies, end_time))
67938 + timedout = true;
67939 read_lock(&tasklist_lock);
67940 do_each_thread(g, p) {
67941 if (p == current || !freeze_task(p))
67942 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
67943 * try_to_stop() after schedule() in ptrace/signal
67944 * stop sees TIF_FREEZE.
67945 */
67946 - if (!task_is_stopped_or_traced(p) &&
67947 - !freezer_should_skip(p))
67948 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67949 todo++;
67950 + if (timedout) {
67951 + printk(KERN_ERR "Task refusing to freeze:\n");
67952 + sched_show_task(p);
67953 + }
67954 + }
67955 } while_each_thread(g, p);
67956 read_unlock(&tasklist_lock);
67957
67958 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
67959 todo += wq_busy;
67960 }
67961
67962 - if (!todo || time_after(jiffies, end_time))
67963 + if (!todo || timedout)
67964 break;
67965
67966 if (pm_wakeup_pending()) {
67967 diff --git a/kernel/printk.c b/kernel/printk.c
67968 index 32690a0..cd7c798 100644
67969 --- a/kernel/printk.c
67970 +++ b/kernel/printk.c
67971 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67972 if (from_file && type != SYSLOG_ACTION_OPEN)
67973 return 0;
67974
67975 +#ifdef CONFIG_GRKERNSEC_DMESG
67976 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67977 + return -EPERM;
67978 +#endif
67979 +
67980 if (syslog_action_restricted(type)) {
67981 if (capable(CAP_SYSLOG))
67982 return 0;
67983 diff --git a/kernel/profile.c b/kernel/profile.c
67984 index 76b8e77..a2930e8 100644
67985 --- a/kernel/profile.c
67986 +++ b/kernel/profile.c
67987 @@ -39,7 +39,7 @@ struct profile_hit {
67988 /* Oprofile timer tick hook */
67989 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67990
67991 -static atomic_t *prof_buffer;
67992 +static atomic_unchecked_t *prof_buffer;
67993 static unsigned long prof_len, prof_shift;
67994
67995 int prof_on __read_mostly;
67996 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67997 hits[i].pc = 0;
67998 continue;
67999 }
68000 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68001 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68002 hits[i].hits = hits[i].pc = 0;
68003 }
68004 }
68005 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68006 * Add the current hit(s) and flush the write-queue out
68007 * to the global buffer:
68008 */
68009 - atomic_add(nr_hits, &prof_buffer[pc]);
68010 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68011 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68012 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68013 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68014 hits[i].pc = hits[i].hits = 0;
68015 }
68016 out:
68017 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68018 {
68019 unsigned long pc;
68020 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68021 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68022 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68023 }
68024 #endif /* !CONFIG_SMP */
68025
68026 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68027 return -EFAULT;
68028 buf++; p++; count--; read++;
68029 }
68030 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68031 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68032 if (copy_to_user(buf, (void *)pnt, count))
68033 return -EFAULT;
68034 read += count;
68035 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68036 }
68037 #endif
68038 profile_discard_flip_buffers();
68039 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68040 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68041 return count;
68042 }
68043
68044 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68045 index 00ab2ca..d237f61 100644
68046 --- a/kernel/ptrace.c
68047 +++ b/kernel/ptrace.c
68048 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68049 task->ptrace = PT_PTRACED;
68050 if (seize)
68051 task->ptrace |= PT_SEIZED;
68052 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68053 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68054 task->ptrace |= PT_PTRACE_CAP;
68055
68056 __ptrace_link(task, current);
68057 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68058 break;
68059 return -EIO;
68060 }
68061 - if (copy_to_user(dst, buf, retval))
68062 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68063 return -EFAULT;
68064 copied += retval;
68065 src += retval;
68066 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
68067 bool seized = child->ptrace & PT_SEIZED;
68068 int ret = -EIO;
68069 siginfo_t siginfo, *si;
68070 - void __user *datavp = (void __user *) data;
68071 + void __user *datavp = (__force void __user *) data;
68072 unsigned long __user *datalp = datavp;
68073 unsigned long flags;
68074
68075 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68076 goto out;
68077 }
68078
68079 + if (gr_handle_ptrace(child, request)) {
68080 + ret = -EPERM;
68081 + goto out_put_task_struct;
68082 + }
68083 +
68084 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68085 ret = ptrace_attach(child, request, data);
68086 /*
68087 * Some architectures need to do book-keeping after
68088 * a ptrace attach.
68089 */
68090 - if (!ret)
68091 + if (!ret) {
68092 arch_ptrace_attach(child);
68093 + gr_audit_ptrace(child);
68094 + }
68095 goto out_put_task_struct;
68096 }
68097
68098 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68099 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68100 if (copied != sizeof(tmp))
68101 return -EIO;
68102 - return put_user(tmp, (unsigned long __user *)data);
68103 + return put_user(tmp, (__force unsigned long __user *)data);
68104 }
68105
68106 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68107 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68108 goto out;
68109 }
68110
68111 + if (gr_handle_ptrace(child, request)) {
68112 + ret = -EPERM;
68113 + goto out_put_task_struct;
68114 + }
68115 +
68116 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68117 ret = ptrace_attach(child, request, data);
68118 /*
68119 * Some architectures need to do book-keeping after
68120 * a ptrace attach.
68121 */
68122 - if (!ret)
68123 + if (!ret) {
68124 arch_ptrace_attach(child);
68125 + gr_audit_ptrace(child);
68126 + }
68127 goto out_put_task_struct;
68128 }
68129
68130 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68131 index 977296d..c4744dc 100644
68132 --- a/kernel/rcutiny.c
68133 +++ b/kernel/rcutiny.c
68134 @@ -46,7 +46,7 @@
68135 struct rcu_ctrlblk;
68136 static void invoke_rcu_callbacks(void);
68137 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68138 -static void rcu_process_callbacks(struct softirq_action *unused);
68139 +static void rcu_process_callbacks(void);
68140 static void __call_rcu(struct rcu_head *head,
68141 void (*func)(struct rcu_head *rcu),
68142 struct rcu_ctrlblk *rcp);
68143 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68144 rcu_is_callbacks_kthread()));
68145 }
68146
68147 -static void rcu_process_callbacks(struct softirq_action *unused)
68148 +static void rcu_process_callbacks(void)
68149 {
68150 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68151 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68152 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68153 index 9cb1ae4..aac7d3e 100644
68154 --- a/kernel/rcutiny_plugin.h
68155 +++ b/kernel/rcutiny_plugin.h
68156 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68157 have_rcu_kthread_work = morework;
68158 local_irq_restore(flags);
68159 if (work)
68160 - rcu_process_callbacks(NULL);
68161 + rcu_process_callbacks();
68162 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68163 }
68164
68165 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68166 index a58ac28..196a3d8 100644
68167 --- a/kernel/rcutorture.c
68168 +++ b/kernel/rcutorture.c
68169 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68170 { 0 };
68171 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68172 { 0 };
68173 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68174 -static atomic_t n_rcu_torture_alloc;
68175 -static atomic_t n_rcu_torture_alloc_fail;
68176 -static atomic_t n_rcu_torture_free;
68177 -static atomic_t n_rcu_torture_mberror;
68178 -static atomic_t n_rcu_torture_error;
68179 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68180 +static atomic_unchecked_t n_rcu_torture_alloc;
68181 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68182 +static atomic_unchecked_t n_rcu_torture_free;
68183 +static atomic_unchecked_t n_rcu_torture_mberror;
68184 +static atomic_unchecked_t n_rcu_torture_error;
68185 static long n_rcu_torture_boost_ktrerror;
68186 static long n_rcu_torture_boost_rterror;
68187 static long n_rcu_torture_boost_failure;
68188 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68189
68190 spin_lock_bh(&rcu_torture_lock);
68191 if (list_empty(&rcu_torture_freelist)) {
68192 - atomic_inc(&n_rcu_torture_alloc_fail);
68193 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68194 spin_unlock_bh(&rcu_torture_lock);
68195 return NULL;
68196 }
68197 - atomic_inc(&n_rcu_torture_alloc);
68198 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68199 p = rcu_torture_freelist.next;
68200 list_del_init(p);
68201 spin_unlock_bh(&rcu_torture_lock);
68202 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68203 static void
68204 rcu_torture_free(struct rcu_torture *p)
68205 {
68206 - atomic_inc(&n_rcu_torture_free);
68207 + atomic_inc_unchecked(&n_rcu_torture_free);
68208 spin_lock_bh(&rcu_torture_lock);
68209 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68210 spin_unlock_bh(&rcu_torture_lock);
68211 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68212 i = rp->rtort_pipe_count;
68213 if (i > RCU_TORTURE_PIPE_LEN)
68214 i = RCU_TORTURE_PIPE_LEN;
68215 - atomic_inc(&rcu_torture_wcount[i]);
68216 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68217 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68218 rp->rtort_mbtest = 0;
68219 rcu_torture_free(rp);
68220 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68221 i = rp->rtort_pipe_count;
68222 if (i > RCU_TORTURE_PIPE_LEN)
68223 i = RCU_TORTURE_PIPE_LEN;
68224 - atomic_inc(&rcu_torture_wcount[i]);
68225 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68226 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68227 rp->rtort_mbtest = 0;
68228 list_del(&rp->rtort_free);
68229 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68230 i = old_rp->rtort_pipe_count;
68231 if (i > RCU_TORTURE_PIPE_LEN)
68232 i = RCU_TORTURE_PIPE_LEN;
68233 - atomic_inc(&rcu_torture_wcount[i]);
68234 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68235 old_rp->rtort_pipe_count++;
68236 cur_ops->deferred_free(old_rp);
68237 }
68238 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68239 return;
68240 }
68241 if (p->rtort_mbtest == 0)
68242 - atomic_inc(&n_rcu_torture_mberror);
68243 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68244 spin_lock(&rand_lock);
68245 cur_ops->read_delay(&rand);
68246 n_rcu_torture_timers++;
68247 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68248 continue;
68249 }
68250 if (p->rtort_mbtest == 0)
68251 - atomic_inc(&n_rcu_torture_mberror);
68252 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68253 cur_ops->read_delay(&rand);
68254 preempt_disable();
68255 pipe_count = p->rtort_pipe_count;
68256 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68257 rcu_torture_current,
68258 rcu_torture_current_version,
68259 list_empty(&rcu_torture_freelist),
68260 - atomic_read(&n_rcu_torture_alloc),
68261 - atomic_read(&n_rcu_torture_alloc_fail),
68262 - atomic_read(&n_rcu_torture_free),
68263 - atomic_read(&n_rcu_torture_mberror),
68264 + atomic_read_unchecked(&n_rcu_torture_alloc),
68265 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68266 + atomic_read_unchecked(&n_rcu_torture_free),
68267 + atomic_read_unchecked(&n_rcu_torture_mberror),
68268 n_rcu_torture_boost_ktrerror,
68269 n_rcu_torture_boost_rterror,
68270 n_rcu_torture_boost_failure,
68271 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68272 n_online_attempts,
68273 n_offline_successes,
68274 n_offline_attempts);
68275 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68276 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68277 n_rcu_torture_boost_ktrerror != 0 ||
68278 n_rcu_torture_boost_rterror != 0 ||
68279 n_rcu_torture_boost_failure != 0)
68280 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68281 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68282 if (i > 1) {
68283 cnt += sprintf(&page[cnt], "!!! ");
68284 - atomic_inc(&n_rcu_torture_error);
68285 + atomic_inc_unchecked(&n_rcu_torture_error);
68286 WARN_ON_ONCE(1);
68287 }
68288 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68289 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68290 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68291 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68292 cnt += sprintf(&page[cnt], " %d",
68293 - atomic_read(&rcu_torture_wcount[i]));
68294 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68295 }
68296 cnt += sprintf(&page[cnt], "\n");
68297 if (cur_ops->stats)
68298 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68299
68300 if (cur_ops->cleanup)
68301 cur_ops->cleanup();
68302 - if (atomic_read(&n_rcu_torture_error))
68303 + if (atomic_read_unchecked(&n_rcu_torture_error))
68304 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68305 else
68306 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68307 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68308
68309 rcu_torture_current = NULL;
68310 rcu_torture_current_version = 0;
68311 - atomic_set(&n_rcu_torture_alloc, 0);
68312 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68313 - atomic_set(&n_rcu_torture_free, 0);
68314 - atomic_set(&n_rcu_torture_mberror, 0);
68315 - atomic_set(&n_rcu_torture_error, 0);
68316 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68317 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68318 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68319 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68320 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68321 n_rcu_torture_boost_ktrerror = 0;
68322 n_rcu_torture_boost_rterror = 0;
68323 n_rcu_torture_boost_failure = 0;
68324 n_rcu_torture_boosts = 0;
68325 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68326 - atomic_set(&rcu_torture_wcount[i], 0);
68327 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68328 for_each_possible_cpu(cpu) {
68329 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68330 per_cpu(rcu_torture_count, cpu)[i] = 0;
68331 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68332 index 6c4a672..70f3202 100644
68333 --- a/kernel/rcutree.c
68334 +++ b/kernel/rcutree.c
68335 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68336 rcu_prepare_for_idle(smp_processor_id());
68337 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68338 smp_mb__before_atomic_inc(); /* See above. */
68339 - atomic_inc(&rdtp->dynticks);
68340 + atomic_inc_unchecked(&rdtp->dynticks);
68341 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68342 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68343 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68344 }
68345
68346 /**
68347 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68348 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68349 {
68350 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68351 - atomic_inc(&rdtp->dynticks);
68352 + atomic_inc_unchecked(&rdtp->dynticks);
68353 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68354 smp_mb__after_atomic_inc(); /* See above. */
68355 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68356 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68357 rcu_cleanup_after_idle(smp_processor_id());
68358 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68359 if (!is_idle_task(current)) {
68360 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68361 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68362
68363 if (rdtp->dynticks_nmi_nesting == 0 &&
68364 - (atomic_read(&rdtp->dynticks) & 0x1))
68365 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68366 return;
68367 rdtp->dynticks_nmi_nesting++;
68368 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68369 - atomic_inc(&rdtp->dynticks);
68370 + atomic_inc_unchecked(&rdtp->dynticks);
68371 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68372 smp_mb__after_atomic_inc(); /* See above. */
68373 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68374 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68375 }
68376
68377 /**
68378 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68379 return;
68380 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68381 smp_mb__before_atomic_inc(); /* See above. */
68382 - atomic_inc(&rdtp->dynticks);
68383 + atomic_inc_unchecked(&rdtp->dynticks);
68384 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68385 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68386 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68387 }
68388
68389 #ifdef CONFIG_PROVE_RCU
68390 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68391 int ret;
68392
68393 preempt_disable();
68394 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68395 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68396 preempt_enable();
68397 return ret;
68398 }
68399 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68400 */
68401 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68402 {
68403 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68404 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68405 return (rdp->dynticks_snap & 0x1) == 0;
68406 }
68407
68408 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68409 unsigned int curr;
68410 unsigned int snap;
68411
68412 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68413 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68414 snap = (unsigned int)rdp->dynticks_snap;
68415
68416 /*
68417 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68418 /*
68419 * Do RCU core processing for the current CPU.
68420 */
68421 -static void rcu_process_callbacks(struct softirq_action *unused)
68422 +static void rcu_process_callbacks(void)
68423 {
68424 trace_rcu_utilization("Start RCU core");
68425 __rcu_process_callbacks(&rcu_sched_state,
68426 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68427 rdp->qlen = 0;
68428 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68429 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68430 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68431 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68432 rdp->cpu = cpu;
68433 rdp->rsp = rsp;
68434 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68435 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68436 rdp->n_force_qs_snap = rsp->n_force_qs;
68437 rdp->blimit = blimit;
68438 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68439 - atomic_set(&rdp->dynticks->dynticks,
68440 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68441 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68442 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68443 rcu_prepare_for_idle_init(cpu);
68444 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68445
68446 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68447 index fddff92..2c08359 100644
68448 --- a/kernel/rcutree.h
68449 +++ b/kernel/rcutree.h
68450 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68451 long long dynticks_nesting; /* Track irq/process nesting level. */
68452 /* Process level is worth LLONG_MAX/2. */
68453 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68454 - atomic_t dynticks; /* Even value for idle, else odd. */
68455 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68456 };
68457
68458 /* RCU's kthread states for tracing. */
68459 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68460 index 8bb35d7..6ea0a463 100644
68461 --- a/kernel/rcutree_plugin.h
68462 +++ b/kernel/rcutree_plugin.h
68463 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68464
68465 /* Clean up and exit. */
68466 smp_mb(); /* ensure expedited GP seen before counter increment. */
68467 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68468 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68469 unlock_mb_ret:
68470 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68471 mb_ret:
68472 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68473
68474 #else /* #ifndef CONFIG_SMP */
68475
68476 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68477 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68478 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68479 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68480
68481 static int synchronize_sched_expedited_cpu_stop(void *data)
68482 {
68483 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68484 int firstsnap, s, snap, trycount = 0;
68485
68486 /* Note that atomic_inc_return() implies full memory barrier. */
68487 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68488 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68489 get_online_cpus();
68490
68491 /*
68492 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68493 }
68494
68495 /* Check to see if someone else did our work for us. */
68496 - s = atomic_read(&sync_sched_expedited_done);
68497 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68498 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68499 smp_mb(); /* ensure test happens before caller kfree */
68500 return;
68501 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68502 * grace period works for us.
68503 */
68504 get_online_cpus();
68505 - snap = atomic_read(&sync_sched_expedited_started);
68506 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68507 smp_mb(); /* ensure read is before try_stop_cpus(). */
68508 }
68509
68510 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68511 * than we did beat us to the punch.
68512 */
68513 do {
68514 - s = atomic_read(&sync_sched_expedited_done);
68515 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68516 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68517 smp_mb(); /* ensure test happens before caller kfree */
68518 break;
68519 }
68520 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68521 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68522
68523 put_online_cpus();
68524 }
68525 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68526 index 654cfe6..c0b28e2 100644
68527 --- a/kernel/rcutree_trace.c
68528 +++ b/kernel/rcutree_trace.c
68529 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68530 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68531 rdp->qs_pending);
68532 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68533 - atomic_read(&rdp->dynticks->dynticks),
68534 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68535 rdp->dynticks->dynticks_nesting,
68536 rdp->dynticks->dynticks_nmi_nesting,
68537 rdp->dynticks_fqs);
68538 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68539 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68540 rdp->qs_pending);
68541 seq_printf(m, ",%d,%llx,%d,%lu",
68542 - atomic_read(&rdp->dynticks->dynticks),
68543 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68544 rdp->dynticks->dynticks_nesting,
68545 rdp->dynticks->dynticks_nmi_nesting,
68546 rdp->dynticks_fqs);
68547 diff --git a/kernel/resource.c b/kernel/resource.c
68548 index 7640b3a..5879283 100644
68549 --- a/kernel/resource.c
68550 +++ b/kernel/resource.c
68551 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68552
68553 static int __init ioresources_init(void)
68554 {
68555 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68556 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68557 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68558 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68559 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68560 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68561 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68562 +#endif
68563 +#else
68564 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68565 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68566 +#endif
68567 return 0;
68568 }
68569 __initcall(ioresources_init);
68570 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68571 index 98ec494..4241d6d 100644
68572 --- a/kernel/rtmutex-tester.c
68573 +++ b/kernel/rtmutex-tester.c
68574 @@ -20,7 +20,7 @@
68575 #define MAX_RT_TEST_MUTEXES 8
68576
68577 static spinlock_t rttest_lock;
68578 -static atomic_t rttest_event;
68579 +static atomic_unchecked_t rttest_event;
68580
68581 struct test_thread_data {
68582 int opcode;
68583 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68584
68585 case RTTEST_LOCKCONT:
68586 td->mutexes[td->opdata] = 1;
68587 - td->event = atomic_add_return(1, &rttest_event);
68588 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68589 return 0;
68590
68591 case RTTEST_RESET:
68592 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68593 return 0;
68594
68595 case RTTEST_RESETEVENT:
68596 - atomic_set(&rttest_event, 0);
68597 + atomic_set_unchecked(&rttest_event, 0);
68598 return 0;
68599
68600 default:
68601 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68602 return ret;
68603
68604 td->mutexes[id] = 1;
68605 - td->event = atomic_add_return(1, &rttest_event);
68606 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68607 rt_mutex_lock(&mutexes[id]);
68608 - td->event = atomic_add_return(1, &rttest_event);
68609 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68610 td->mutexes[id] = 4;
68611 return 0;
68612
68613 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68614 return ret;
68615
68616 td->mutexes[id] = 1;
68617 - td->event = atomic_add_return(1, &rttest_event);
68618 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68619 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68620 - td->event = atomic_add_return(1, &rttest_event);
68621 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68622 td->mutexes[id] = ret ? 0 : 4;
68623 return ret ? -EINTR : 0;
68624
68625 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68626 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68627 return ret;
68628
68629 - td->event = atomic_add_return(1, &rttest_event);
68630 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68631 rt_mutex_unlock(&mutexes[id]);
68632 - td->event = atomic_add_return(1, &rttest_event);
68633 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68634 td->mutexes[id] = 0;
68635 return 0;
68636
68637 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68638 break;
68639
68640 td->mutexes[dat] = 2;
68641 - td->event = atomic_add_return(1, &rttest_event);
68642 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68643 break;
68644
68645 default:
68646 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68647 return;
68648
68649 td->mutexes[dat] = 3;
68650 - td->event = atomic_add_return(1, &rttest_event);
68651 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68652 break;
68653
68654 case RTTEST_LOCKNOWAIT:
68655 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68656 return;
68657
68658 td->mutexes[dat] = 1;
68659 - td->event = atomic_add_return(1, &rttest_event);
68660 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68661 return;
68662
68663 default:
68664 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68665 index e8a1f83..363d17d 100644
68666 --- a/kernel/sched/auto_group.c
68667 +++ b/kernel/sched/auto_group.c
68668 @@ -11,7 +11,7 @@
68669
68670 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68671 static struct autogroup autogroup_default;
68672 -static atomic_t autogroup_seq_nr;
68673 +static atomic_unchecked_t autogroup_seq_nr;
68674
68675 void __init autogroup_init(struct task_struct *init_task)
68676 {
68677 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68678
68679 kref_init(&ag->kref);
68680 init_rwsem(&ag->lock);
68681 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68682 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68683 ag->tg = tg;
68684 #ifdef CONFIG_RT_GROUP_SCHED
68685 /*
68686 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68687 index b342f57..00324a0 100644
68688 --- a/kernel/sched/core.c
68689 +++ b/kernel/sched/core.c
68690 @@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
68691 BUG(); /* the idle class will always have a runnable task */
68692 }
68693
68694 +#ifdef CONFIG_GRKERNSEC_SETXID
68695 +extern void gr_delayed_cred_worker(void);
68696 +static inline void gr_cred_schedule(void)
68697 +{
68698 + if (unlikely(current->delayed_cred))
68699 + gr_delayed_cred_worker();
68700 +}
68701 +#else
68702 +static inline void gr_cred_schedule(void)
68703 +{
68704 +}
68705 +#endif
68706 +
68707 /*
68708 * __schedule() is the main scheduler function.
68709 */
68710 @@ -3162,6 +3175,8 @@ need_resched:
68711
68712 schedule_debug(prev);
68713
68714 + gr_cred_schedule();
68715 +
68716 if (sched_feat(HRTICK))
68717 hrtick_clear(rq);
68718
68719 @@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
68720 /* convert nice value [19,-20] to rlimit style value [1,40] */
68721 int nice_rlim = 20 - nice;
68722
68723 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68724 +
68725 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68726 capable(CAP_SYS_NICE));
68727 }
68728 @@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68729 if (nice > 19)
68730 nice = 19;
68731
68732 - if (increment < 0 && !can_nice(current, nice))
68733 + if (increment < 0 && (!can_nice(current, nice) ||
68734 + gr_handle_chroot_nice()))
68735 return -EPERM;
68736
68737 retval = security_task_setnice(current, nice);
68738 @@ -4042,6 +4060,7 @@ recheck:
68739 unsigned long rlim_rtprio =
68740 task_rlimit(p, RLIMIT_RTPRIO);
68741
68742 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68743 /* can't set/change the rt policy */
68744 if (policy != p->policy && !rlim_rtprio)
68745 return -EPERM;
68746 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68747 index aca16b8..8e3acc4 100644
68748 --- a/kernel/sched/fair.c
68749 +++ b/kernel/sched/fair.c
68750 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68751 * run_rebalance_domains is triggered when needed from the scheduler tick.
68752 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68753 */
68754 -static void run_rebalance_domains(struct softirq_action *h)
68755 +static void run_rebalance_domains(void)
68756 {
68757 int this_cpu = smp_processor_id();
68758 struct rq *this_rq = cpu_rq(this_cpu);
68759 diff --git a/kernel/signal.c b/kernel/signal.c
68760 index c73c428..7040057 100644
68761 --- a/kernel/signal.c
68762 +++ b/kernel/signal.c
68763 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68764
68765 int print_fatal_signals __read_mostly;
68766
68767 -static void __user *sig_handler(struct task_struct *t, int sig)
68768 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68769 {
68770 return t->sighand->action[sig - 1].sa.sa_handler;
68771 }
68772
68773 -static int sig_handler_ignored(void __user *handler, int sig)
68774 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68775 {
68776 /* Is it explicitly or implicitly ignored? */
68777 return handler == SIG_IGN ||
68778 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68779 static int sig_task_ignored(struct task_struct *t, int sig,
68780 int from_ancestor_ns)
68781 {
68782 - void __user *handler;
68783 + __sighandler_t handler;
68784
68785 handler = sig_handler(t, sig);
68786
68787 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68788 atomic_inc(&user->sigpending);
68789 rcu_read_unlock();
68790
68791 + if (!override_rlimit)
68792 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68793 +
68794 if (override_rlimit ||
68795 atomic_read(&user->sigpending) <=
68796 task_rlimit(t, RLIMIT_SIGPENDING)) {
68797 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68798
68799 int unhandled_signal(struct task_struct *tsk, int sig)
68800 {
68801 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68802 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68803 if (is_global_init(tsk))
68804 return 1;
68805 if (handler != SIG_IGN && handler != SIG_DFL)
68806 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68807 }
68808 }
68809
68810 + /* allow glibc communication via tgkill to other threads in our
68811 + thread group */
68812 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68813 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68814 + && gr_handle_signal(t, sig))
68815 + return -EPERM;
68816 +
68817 return security_task_kill(t, info, sig, 0);
68818 }
68819
68820 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68821 return send_signal(sig, info, p, 1);
68822 }
68823
68824 -static int
68825 +int
68826 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68827 {
68828 return send_signal(sig, info, t, 0);
68829 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68830 unsigned long int flags;
68831 int ret, blocked, ignored;
68832 struct k_sigaction *action;
68833 + int is_unhandled = 0;
68834
68835 spin_lock_irqsave(&t->sighand->siglock, flags);
68836 action = &t->sighand->action[sig-1];
68837 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68838 }
68839 if (action->sa.sa_handler == SIG_DFL)
68840 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68841 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68842 + is_unhandled = 1;
68843 ret = specific_send_sig_info(sig, info, t);
68844 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68845
68846 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68847 + normal operation */
68848 + if (is_unhandled) {
68849 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68850 + gr_handle_crash(t, sig);
68851 + }
68852 +
68853 return ret;
68854 }
68855
68856 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68857 ret = check_kill_permission(sig, info, p);
68858 rcu_read_unlock();
68859
68860 - if (!ret && sig)
68861 + if (!ret && sig) {
68862 ret = do_send_sig_info(sig, info, p, true);
68863 + if (!ret)
68864 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68865 + }
68866
68867 return ret;
68868 }
68869 @@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68870 int error = -ESRCH;
68871
68872 rcu_read_lock();
68873 - p = find_task_by_vpid(pid);
68874 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68875 + /* allow glibc communication via tgkill to other threads in our
68876 + thread group */
68877 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68878 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68879 + p = find_task_by_vpid_unrestricted(pid);
68880 + else
68881 +#endif
68882 + p = find_task_by_vpid(pid);
68883 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68884 error = check_kill_permission(sig, info, p);
68885 /*
68886 diff --git a/kernel/smp.c b/kernel/smp.c
68887 index db197d6..17aef0b 100644
68888 --- a/kernel/smp.c
68889 +++ b/kernel/smp.c
68890 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68891 }
68892 EXPORT_SYMBOL(smp_call_function);
68893
68894 -void ipi_call_lock(void)
68895 +void ipi_call_lock(void) __acquires(call_function.lock)
68896 {
68897 raw_spin_lock(&call_function.lock);
68898 }
68899
68900 -void ipi_call_unlock(void)
68901 +void ipi_call_unlock(void) __releases(call_function.lock)
68902 {
68903 raw_spin_unlock(&call_function.lock);
68904 }
68905
68906 -void ipi_call_lock_irq(void)
68907 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68908 {
68909 raw_spin_lock_irq(&call_function.lock);
68910 }
68911
68912 -void ipi_call_unlock_irq(void)
68913 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68914 {
68915 raw_spin_unlock_irq(&call_function.lock);
68916 }
68917 diff --git a/kernel/softirq.c b/kernel/softirq.c
68918 index 4eb3a0f..6f1fa81 100644
68919 --- a/kernel/softirq.c
68920 +++ b/kernel/softirq.c
68921 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68922
68923 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68924
68925 -char *softirq_to_name[NR_SOFTIRQS] = {
68926 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68927 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68928 "TASKLET", "SCHED", "HRTIMER", "RCU"
68929 };
68930 @@ -235,7 +235,7 @@ restart:
68931 kstat_incr_softirqs_this_cpu(vec_nr);
68932
68933 trace_softirq_entry(vec_nr);
68934 - h->action(h);
68935 + h->action();
68936 trace_softirq_exit(vec_nr);
68937 if (unlikely(prev_count != preempt_count())) {
68938 printk(KERN_ERR "huh, entered softirq %u %s %p"
68939 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68940 local_irq_restore(flags);
68941 }
68942
68943 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68944 +void open_softirq(int nr, void (*action)(void))
68945 {
68946 - softirq_vec[nr].action = action;
68947 + pax_open_kernel();
68948 + *(void **)&softirq_vec[nr].action = action;
68949 + pax_close_kernel();
68950 }
68951
68952 /*
68953 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68954
68955 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68956
68957 -static void tasklet_action(struct softirq_action *a)
68958 +static void tasklet_action(void)
68959 {
68960 struct tasklet_struct *list;
68961
68962 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68963 }
68964 }
68965
68966 -static void tasklet_hi_action(struct softirq_action *a)
68967 +static void tasklet_hi_action(void)
68968 {
68969 struct tasklet_struct *list;
68970
68971 diff --git a/kernel/sys.c b/kernel/sys.c
68972 index 888d227..f04b318 100644
68973 --- a/kernel/sys.c
68974 +++ b/kernel/sys.c
68975 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68976 error = -EACCES;
68977 goto out;
68978 }
68979 +
68980 + if (gr_handle_chroot_setpriority(p, niceval)) {
68981 + error = -EACCES;
68982 + goto out;
68983 + }
68984 +
68985 no_nice = security_task_setnice(p, niceval);
68986 if (no_nice) {
68987 error = no_nice;
68988 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68989 goto error;
68990 }
68991
68992 + if (gr_check_group_change(new->gid, new->egid, -1))
68993 + goto error;
68994 +
68995 if (rgid != (gid_t) -1 ||
68996 (egid != (gid_t) -1 && egid != old->gid))
68997 new->sgid = new->egid;
68998 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68999 old = current_cred();
69000
69001 retval = -EPERM;
69002 +
69003 + if (gr_check_group_change(gid, gid, gid))
69004 + goto error;
69005 +
69006 if (nsown_capable(CAP_SETGID))
69007 new->gid = new->egid = new->sgid = new->fsgid = gid;
69008 else if (gid == old->gid || gid == old->sgid)
69009 @@ -618,7 +631,7 @@ error:
69010 /*
69011 * change the user struct in a credentials set to match the new UID
69012 */
69013 -static int set_user(struct cred *new)
69014 +int set_user(struct cred *new)
69015 {
69016 struct user_struct *new_user;
69017
69018 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69019 goto error;
69020 }
69021
69022 + if (gr_check_user_change(new->uid, new->euid, -1))
69023 + goto error;
69024 +
69025 if (new->uid != old->uid) {
69026 retval = set_user(new);
69027 if (retval < 0)
69028 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69029 old = current_cred();
69030
69031 retval = -EPERM;
69032 +
69033 + if (gr_check_crash_uid(uid))
69034 + goto error;
69035 + if (gr_check_user_change(uid, uid, uid))
69036 + goto error;
69037 +
69038 if (nsown_capable(CAP_SETUID)) {
69039 new->suid = new->uid = uid;
69040 if (uid != old->uid) {
69041 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69042 goto error;
69043 }
69044
69045 + if (gr_check_user_change(ruid, euid, -1))
69046 + goto error;
69047 +
69048 if (ruid != (uid_t) -1) {
69049 new->uid = ruid;
69050 if (ruid != old->uid) {
69051 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69052 goto error;
69053 }
69054
69055 + if (gr_check_group_change(rgid, egid, -1))
69056 + goto error;
69057 +
69058 if (rgid != (gid_t) -1)
69059 new->gid = rgid;
69060 if (egid != (gid_t) -1)
69061 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69062 old = current_cred();
69063 old_fsuid = old->fsuid;
69064
69065 + if (gr_check_user_change(-1, -1, uid))
69066 + goto error;
69067 +
69068 if (uid == old->uid || uid == old->euid ||
69069 uid == old->suid || uid == old->fsuid ||
69070 nsown_capable(CAP_SETUID)) {
69071 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69072 }
69073 }
69074
69075 +error:
69076 abort_creds(new);
69077 return old_fsuid;
69078
69079 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69080 if (gid == old->gid || gid == old->egid ||
69081 gid == old->sgid || gid == old->fsgid ||
69082 nsown_capable(CAP_SETGID)) {
69083 + if (gr_check_group_change(-1, -1, gid))
69084 + goto error;
69085 +
69086 if (gid != old_fsgid) {
69087 new->fsgid = gid;
69088 goto change_okay;
69089 }
69090 }
69091
69092 +error:
69093 abort_creds(new);
69094 return old_fsgid;
69095
69096 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69097 }
69098 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69099 snprintf(buf, len, "2.6.%u%s", v, rest);
69100 - ret = copy_to_user(release, buf, len);
69101 + if (len > sizeof(buf))
69102 + ret = -EFAULT;
69103 + else
69104 + ret = copy_to_user(release, buf, len);
69105 }
69106 return ret;
69107 }
69108 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69109 return -EFAULT;
69110
69111 down_read(&uts_sem);
69112 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69113 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69114 __OLD_UTS_LEN);
69115 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69116 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69117 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69118 __OLD_UTS_LEN);
69119 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69120 - error |= __copy_to_user(&name->release, &utsname()->release,
69121 + error |= __copy_to_user(name->release, &utsname()->release,
69122 __OLD_UTS_LEN);
69123 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69124 - error |= __copy_to_user(&name->version, &utsname()->version,
69125 + error |= __copy_to_user(name->version, &utsname()->version,
69126 __OLD_UTS_LEN);
69127 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69128 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69129 + error |= __copy_to_user(name->machine, &utsname()->machine,
69130 __OLD_UTS_LEN);
69131 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69132 up_read(&uts_sem);
69133 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69134 error = get_dumpable(me->mm);
69135 break;
69136 case PR_SET_DUMPABLE:
69137 - if (arg2 < 0 || arg2 > 1) {
69138 + if (arg2 > 1) {
69139 error = -EINVAL;
69140 break;
69141 }
69142 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69143 index f03a6ef..5fcc8af 100644
69144 --- a/kernel/sysctl.c
69145 +++ b/kernel/sysctl.c
69146 @@ -86,6 +86,13 @@
69147
69148
69149 #if defined(CONFIG_SYSCTL)
69150 +#include <linux/grsecurity.h>
69151 +#include <linux/grinternal.h>
69152 +
69153 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69154 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69155 + const int op);
69156 +extern int gr_handle_chroot_sysctl(const int op);
69157
69158 /* External variables not in a header file. */
69159 extern int sysctl_overcommit_memory;
69160 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69161 }
69162
69163 #endif
69164 +extern struct ctl_table grsecurity_table[];
69165
69166 static struct ctl_table root_table[];
69167 static struct ctl_table_root sysctl_table_root;
69168 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69169 int sysctl_legacy_va_layout;
69170 #endif
69171
69172 +#ifdef CONFIG_PAX_SOFTMODE
69173 +static ctl_table pax_table[] = {
69174 + {
69175 + .procname = "softmode",
69176 + .data = &pax_softmode,
69177 + .maxlen = sizeof(unsigned int),
69178 + .mode = 0600,
69179 + .proc_handler = &proc_dointvec,
69180 + },
69181 +
69182 + { }
69183 +};
69184 +#endif
69185 +
69186 /* The default sysctl tables: */
69187
69188 static struct ctl_table root_table[] = {
69189 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69190 #endif
69191
69192 static struct ctl_table kern_table[] = {
69193 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69194 + {
69195 + .procname = "grsecurity",
69196 + .mode = 0500,
69197 + .child = grsecurity_table,
69198 + },
69199 +#endif
69200 +
69201 +#ifdef CONFIG_PAX_SOFTMODE
69202 + {
69203 + .procname = "pax",
69204 + .mode = 0500,
69205 + .child = pax_table,
69206 + },
69207 +#endif
69208 +
69209 {
69210 .procname = "sched_child_runs_first",
69211 .data = &sysctl_sched_child_runs_first,
69212 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69213 .data = &modprobe_path,
69214 .maxlen = KMOD_PATH_LEN,
69215 .mode = 0644,
69216 - .proc_handler = proc_dostring,
69217 + .proc_handler = proc_dostring_modpriv,
69218 },
69219 {
69220 .procname = "modules_disabled",
69221 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69222 .extra1 = &zero,
69223 .extra2 = &one,
69224 },
69225 +#endif
69226 {
69227 .procname = "kptr_restrict",
69228 .data = &kptr_restrict,
69229 .maxlen = sizeof(int),
69230 .mode = 0644,
69231 .proc_handler = proc_dointvec_minmax_sysadmin,
69232 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69233 + .extra1 = &two,
69234 +#else
69235 .extra1 = &zero,
69236 +#endif
69237 .extra2 = &two,
69238 },
69239 -#endif
69240 {
69241 .procname = "ngroups_max",
69242 .data = &ngroups_max,
69243 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
69244 .proc_handler = proc_dointvec_minmax,
69245 .extra1 = &zero,
69246 },
69247 + {
69248 + .procname = "heap_stack_gap",
69249 + .data = &sysctl_heap_stack_gap,
69250 + .maxlen = sizeof(sysctl_heap_stack_gap),
69251 + .mode = 0644,
69252 + .proc_handler = proc_doulongvec_minmax,
69253 + },
69254 #else
69255 {
69256 .procname = "nr_trim_pages",
69257 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
69258 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69259 {
69260 int mode;
69261 + int error;
69262 +
69263 + if (table->parent != NULL && table->parent->procname != NULL &&
69264 + table->procname != NULL &&
69265 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69266 + return -EACCES;
69267 + if (gr_handle_chroot_sysctl(op))
69268 + return -EACCES;
69269 + error = gr_handle_sysctl(table, op);
69270 + if (error)
69271 + return error;
69272
69273 if (root->permissions)
69274 mode = root->permissions(root, current->nsproxy, table);
69275 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
69276 buffer, lenp, ppos);
69277 }
69278
69279 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69280 + void __user *buffer, size_t *lenp, loff_t *ppos)
69281 +{
69282 + if (write && !capable(CAP_SYS_MODULE))
69283 + return -EPERM;
69284 +
69285 + return _proc_do_string(table->data, table->maxlen, write,
69286 + buffer, lenp, ppos);
69287 +}
69288 +
69289 static size_t proc_skip_spaces(char **buf)
69290 {
69291 size_t ret;
69292 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69293 len = strlen(tmp);
69294 if (len > *size)
69295 len = *size;
69296 + if (len > sizeof(tmp))
69297 + len = sizeof(tmp);
69298 if (copy_to_user(*buf, tmp, len))
69299 return -EFAULT;
69300 *size -= len;
69301 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69302 *i = val;
69303 } else {
69304 val = convdiv * (*i) / convmul;
69305 - if (!first)
69306 + if (!first) {
69307 err = proc_put_char(&buffer, &left, '\t');
69308 + if (err)
69309 + break;
69310 + }
69311 err = proc_put_long(&buffer, &left, val, false);
69312 if (err)
69313 break;
69314 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
69315 return -ENOSYS;
69316 }
69317
69318 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69319 + void __user *buffer, size_t *lenp, loff_t *ppos)
69320 +{
69321 + return -ENOSYS;
69322 +}
69323 +
69324 int proc_dointvec(struct ctl_table *table, int write,
69325 void __user *buffer, size_t *lenp, loff_t *ppos)
69326 {
69327 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69328 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69329 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69330 EXPORT_SYMBOL(proc_dostring);
69331 +EXPORT_SYMBOL(proc_dostring_modpriv);
69332 EXPORT_SYMBOL(proc_doulongvec_minmax);
69333 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69334 EXPORT_SYMBOL(register_sysctl_table);
69335 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69336 index a650694..aaeeb20 100644
69337 --- a/kernel/sysctl_binary.c
69338 +++ b/kernel/sysctl_binary.c
69339 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69340 int i;
69341
69342 set_fs(KERNEL_DS);
69343 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69344 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69345 set_fs(old_fs);
69346 if (result < 0)
69347 goto out_kfree;
69348 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69349 }
69350
69351 set_fs(KERNEL_DS);
69352 - result = vfs_write(file, buffer, str - buffer, &pos);
69353 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69354 set_fs(old_fs);
69355 if (result < 0)
69356 goto out_kfree;
69357 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69358 int i;
69359
69360 set_fs(KERNEL_DS);
69361 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69362 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69363 set_fs(old_fs);
69364 if (result < 0)
69365 goto out_kfree;
69366 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69367 }
69368
69369 set_fs(KERNEL_DS);
69370 - result = vfs_write(file, buffer, str - buffer, &pos);
69371 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69372 set_fs(old_fs);
69373 if (result < 0)
69374 goto out_kfree;
69375 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69376 int i;
69377
69378 set_fs(KERNEL_DS);
69379 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69380 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69381 set_fs(old_fs);
69382 if (result < 0)
69383 goto out;
69384 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69385 __le16 dnaddr;
69386
69387 set_fs(KERNEL_DS);
69388 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69389 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69390 set_fs(old_fs);
69391 if (result < 0)
69392 goto out;
69393 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69394 le16_to_cpu(dnaddr) & 0x3ff);
69395
69396 set_fs(KERNEL_DS);
69397 - result = vfs_write(file, buf, len, &pos);
69398 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69399 set_fs(old_fs);
69400 if (result < 0)
69401 goto out;
69402 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69403 index 362da65..ab8ef8c 100644
69404 --- a/kernel/sysctl_check.c
69405 +++ b/kernel/sysctl_check.c
69406 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69407 set_fail(&fail, table, "Directory with extra2");
69408 } else {
69409 if ((table->proc_handler == proc_dostring) ||
69410 + (table->proc_handler == proc_dostring_modpriv) ||
69411 (table->proc_handler == proc_dointvec) ||
69412 (table->proc_handler == proc_dointvec_minmax) ||
69413 (table->proc_handler == proc_dointvec_jiffies) ||
69414 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69415 index e660464..c8b9e67 100644
69416 --- a/kernel/taskstats.c
69417 +++ b/kernel/taskstats.c
69418 @@ -27,9 +27,12 @@
69419 #include <linux/cgroup.h>
69420 #include <linux/fs.h>
69421 #include <linux/file.h>
69422 +#include <linux/grsecurity.h>
69423 #include <net/genetlink.h>
69424 #include <linux/atomic.h>
69425
69426 +extern int gr_is_taskstats_denied(int pid);
69427 +
69428 /*
69429 * Maximum length of a cpumask that can be specified in
69430 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69431 @@ -556,6 +559,9 @@ err:
69432
69433 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69434 {
69435 + if (gr_is_taskstats_denied(current->pid))
69436 + return -EACCES;
69437 +
69438 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69439 return cmd_attr_register_cpumask(info);
69440 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69441 diff --git a/kernel/time.c b/kernel/time.c
69442 index 73e416d..cfc6f69 100644
69443 --- a/kernel/time.c
69444 +++ b/kernel/time.c
69445 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69446 return error;
69447
69448 if (tz) {
69449 + /* we log in do_settimeofday called below, so don't log twice
69450 + */
69451 + if (!tv)
69452 + gr_log_timechange();
69453 +
69454 /* SMP safe, global irq locking makes it work. */
69455 sys_tz = *tz;
69456 update_vsyscall_tz();
69457 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69458 index 8a46f5d..bbe6f9c 100644
69459 --- a/kernel/time/alarmtimer.c
69460 +++ b/kernel/time/alarmtimer.c
69461 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69462 struct platform_device *pdev;
69463 int error = 0;
69464 int i;
69465 - struct k_clock alarm_clock = {
69466 + static struct k_clock alarm_clock = {
69467 .clock_getres = alarm_clock_getres,
69468 .clock_get = alarm_clock_get,
69469 .timer_create = alarm_timer_create,
69470 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69471 index fd4a7b1..fae5c2a 100644
69472 --- a/kernel/time/tick-broadcast.c
69473 +++ b/kernel/time/tick-broadcast.c
69474 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69475 * then clear the broadcast bit.
69476 */
69477 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69478 - int cpu = smp_processor_id();
69479 + cpu = smp_processor_id();
69480
69481 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69482 tick_broadcast_clear_oneshot(cpu);
69483 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69484 index 0c63581..e25dcb6 100644
69485 --- a/kernel/time/timekeeping.c
69486 +++ b/kernel/time/timekeeping.c
69487 @@ -14,6 +14,7 @@
69488 #include <linux/init.h>
69489 #include <linux/mm.h>
69490 #include <linux/sched.h>
69491 +#include <linux/grsecurity.h>
69492 #include <linux/syscore_ops.h>
69493 #include <linux/clocksource.h>
69494 #include <linux/jiffies.h>
69495 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69496 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69497 return -EINVAL;
69498
69499 + gr_log_timechange();
69500 +
69501 write_seqlock_irqsave(&xtime_lock, flags);
69502
69503 timekeeping_forward_now();
69504 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69505 index 3258455..f35227d 100644
69506 --- a/kernel/time/timer_list.c
69507 +++ b/kernel/time/timer_list.c
69508 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69509
69510 static void print_name_offset(struct seq_file *m, void *sym)
69511 {
69512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69513 + SEQ_printf(m, "<%p>", NULL);
69514 +#else
69515 char symname[KSYM_NAME_LEN];
69516
69517 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69518 SEQ_printf(m, "<%pK>", sym);
69519 else
69520 SEQ_printf(m, "%s", symname);
69521 +#endif
69522 }
69523
69524 static void
69525 @@ -112,7 +116,11 @@ next_one:
69526 static void
69527 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69528 {
69529 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69530 + SEQ_printf(m, " .base: %p\n", NULL);
69531 +#else
69532 SEQ_printf(m, " .base: %pK\n", base);
69533 +#endif
69534 SEQ_printf(m, " .index: %d\n",
69535 base->index);
69536 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69537 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69538 {
69539 struct proc_dir_entry *pe;
69540
69541 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69542 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69543 +#else
69544 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69545 +#endif
69546 if (!pe)
69547 return -ENOMEM;
69548 return 0;
69549 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69550 index 0b537f2..9e71eca 100644
69551 --- a/kernel/time/timer_stats.c
69552 +++ b/kernel/time/timer_stats.c
69553 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69554 static unsigned long nr_entries;
69555 static struct entry entries[MAX_ENTRIES];
69556
69557 -static atomic_t overflow_count;
69558 +static atomic_unchecked_t overflow_count;
69559
69560 /*
69561 * The entries are in a hash-table, for fast lookup:
69562 @@ -140,7 +140,7 @@ static void reset_entries(void)
69563 nr_entries = 0;
69564 memset(entries, 0, sizeof(entries));
69565 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69566 - atomic_set(&overflow_count, 0);
69567 + atomic_set_unchecked(&overflow_count, 0);
69568 }
69569
69570 static struct entry *alloc_entry(void)
69571 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69572 if (likely(entry))
69573 entry->count++;
69574 else
69575 - atomic_inc(&overflow_count);
69576 + atomic_inc_unchecked(&overflow_count);
69577
69578 out_unlock:
69579 raw_spin_unlock_irqrestore(lock, flags);
69580 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69581
69582 static void print_name_offset(struct seq_file *m, unsigned long addr)
69583 {
69584 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69585 + seq_printf(m, "<%p>", NULL);
69586 +#else
69587 char symname[KSYM_NAME_LEN];
69588
69589 if (lookup_symbol_name(addr, symname) < 0)
69590 seq_printf(m, "<%p>", (void *)addr);
69591 else
69592 seq_printf(m, "%s", symname);
69593 +#endif
69594 }
69595
69596 static int tstats_show(struct seq_file *m, void *v)
69597 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69598
69599 seq_puts(m, "Timer Stats Version: v0.2\n");
69600 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69601 - if (atomic_read(&overflow_count))
69602 + if (atomic_read_unchecked(&overflow_count))
69603 seq_printf(m, "Overflow: %d entries\n",
69604 - atomic_read(&overflow_count));
69605 + atomic_read_unchecked(&overflow_count));
69606
69607 for (i = 0; i < nr_entries; i++) {
69608 entry = entries + i;
69609 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69610 {
69611 struct proc_dir_entry *pe;
69612
69613 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69614 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69615 +#else
69616 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69617 +#endif
69618 if (!pe)
69619 return -ENOMEM;
69620 return 0;
69621 diff --git a/kernel/timer.c b/kernel/timer.c
69622 index a297ffc..5e16b0b 100644
69623 --- a/kernel/timer.c
69624 +++ b/kernel/timer.c
69625 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69626 /*
69627 * This function runs timers and the timer-tq in bottom half context.
69628 */
69629 -static void run_timer_softirq(struct softirq_action *h)
69630 +static void run_timer_softirq(void)
69631 {
69632 struct tvec_base *base = __this_cpu_read(tvec_bases);
69633
69634 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69635 index cdea7b5..9b820d4 100644
69636 --- a/kernel/trace/blktrace.c
69637 +++ b/kernel/trace/blktrace.c
69638 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69639 struct blk_trace *bt = filp->private_data;
69640 char buf[16];
69641
69642 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69643 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69644
69645 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69646 }
69647 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69648 return 1;
69649
69650 bt = buf->chan->private_data;
69651 - atomic_inc(&bt->dropped);
69652 + atomic_inc_unchecked(&bt->dropped);
69653 return 0;
69654 }
69655
69656 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69657
69658 bt->dir = dir;
69659 bt->dev = dev;
69660 - atomic_set(&bt->dropped, 0);
69661 + atomic_set_unchecked(&bt->dropped, 0);
69662
69663 ret = -EIO;
69664 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69665 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69666 index 683d559..d70d914 100644
69667 --- a/kernel/trace/ftrace.c
69668 +++ b/kernel/trace/ftrace.c
69669 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69670 if (unlikely(ftrace_disabled))
69671 return 0;
69672
69673 + ret = ftrace_arch_code_modify_prepare();
69674 + FTRACE_WARN_ON(ret);
69675 + if (ret)
69676 + return 0;
69677 +
69678 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69679 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69680 if (ret) {
69681 ftrace_bug(ret, ip);
69682 - return 0;
69683 }
69684 - return 1;
69685 + return ret ? 0 : 1;
69686 }
69687
69688 /*
69689 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69690
69691 int
69692 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69693 - void *data)
69694 + void *data)
69695 {
69696 struct ftrace_func_probe *entry;
69697 struct ftrace_page *pg;
69698 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69699 index c4579f1..6a439da 100644
69700 --- a/kernel/trace/trace.c
69701 +++ b/kernel/trace/trace.c
69702 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69703 };
69704 #endif
69705
69706 -static struct dentry *d_tracer;
69707 -
69708 struct dentry *tracing_init_dentry(void)
69709 {
69710 + static struct dentry *d_tracer;
69711 static int once;
69712
69713 if (d_tracer)
69714 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69715 return d_tracer;
69716 }
69717
69718 -static struct dentry *d_percpu;
69719 -
69720 struct dentry *tracing_dentry_percpu(void)
69721 {
69722 + static struct dentry *d_percpu;
69723 static int once;
69724 struct dentry *d_tracer;
69725
69726 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69727 index c212a7f..7b02394 100644
69728 --- a/kernel/trace/trace_events.c
69729 +++ b/kernel/trace/trace_events.c
69730 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69731 struct ftrace_module_file_ops {
69732 struct list_head list;
69733 struct module *mod;
69734 - struct file_operations id;
69735 - struct file_operations enable;
69736 - struct file_operations format;
69737 - struct file_operations filter;
69738 };
69739
69740 static struct ftrace_module_file_ops *
69741 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69742
69743 file_ops->mod = mod;
69744
69745 - file_ops->id = ftrace_event_id_fops;
69746 - file_ops->id.owner = mod;
69747 -
69748 - file_ops->enable = ftrace_enable_fops;
69749 - file_ops->enable.owner = mod;
69750 -
69751 - file_ops->filter = ftrace_event_filter_fops;
69752 - file_ops->filter.owner = mod;
69753 -
69754 - file_ops->format = ftrace_event_format_fops;
69755 - file_ops->format.owner = mod;
69756 + pax_open_kernel();
69757 + *(void **)&mod->trace_id.owner = mod;
69758 + *(void **)&mod->trace_enable.owner = mod;
69759 + *(void **)&mod->trace_filter.owner = mod;
69760 + *(void **)&mod->trace_format.owner = mod;
69761 + pax_close_kernel();
69762
69763 list_add(&file_ops->list, &ftrace_module_file_list);
69764
69765 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69766
69767 for_each_event(call, start, end) {
69768 __trace_add_event_call(*call, mod,
69769 - &file_ops->id, &file_ops->enable,
69770 - &file_ops->filter, &file_ops->format);
69771 + &mod->trace_id, &mod->trace_enable,
69772 + &mod->trace_filter, &mod->trace_format);
69773 }
69774 }
69775
69776 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69777 index 00d527c..7c5b1a3 100644
69778 --- a/kernel/trace/trace_kprobe.c
69779 +++ b/kernel/trace/trace_kprobe.c
69780 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69781 long ret;
69782 int maxlen = get_rloc_len(*(u32 *)dest);
69783 u8 *dst = get_rloc_data(dest);
69784 - u8 *src = addr;
69785 + const u8 __user *src = (const u8 __force_user *)addr;
69786 mm_segment_t old_fs = get_fs();
69787 if (!maxlen)
69788 return;
69789 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69790 pagefault_disable();
69791 do
69792 ret = __copy_from_user_inatomic(dst++, src++, 1);
69793 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69794 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69795 dst[-1] = '\0';
69796 pagefault_enable();
69797 set_fs(old_fs);
69798 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69799 ((u8 *)get_rloc_data(dest))[0] = '\0';
69800 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69801 } else
69802 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69803 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69804 get_rloc_offs(*(u32 *)dest));
69805 }
69806 /* Return the length of string -- including null terminal byte */
69807 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69808 set_fs(KERNEL_DS);
69809 pagefault_disable();
69810 do {
69811 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69812 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69813 len++;
69814 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69815 pagefault_enable();
69816 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69817 index fd3c8aa..5f324a6 100644
69818 --- a/kernel/trace/trace_mmiotrace.c
69819 +++ b/kernel/trace/trace_mmiotrace.c
69820 @@ -24,7 +24,7 @@ struct header_iter {
69821 static struct trace_array *mmio_trace_array;
69822 static bool overrun_detected;
69823 static unsigned long prev_overruns;
69824 -static atomic_t dropped_count;
69825 +static atomic_unchecked_t dropped_count;
69826
69827 static void mmio_reset_data(struct trace_array *tr)
69828 {
69829 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69830
69831 static unsigned long count_overruns(struct trace_iterator *iter)
69832 {
69833 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69834 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69835 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69836
69837 if (over > prev_overruns)
69838 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69839 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69840 sizeof(*entry), 0, pc);
69841 if (!event) {
69842 - atomic_inc(&dropped_count);
69843 + atomic_inc_unchecked(&dropped_count);
69844 return;
69845 }
69846 entry = ring_buffer_event_data(event);
69847 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69848 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69849 sizeof(*entry), 0, pc);
69850 if (!event) {
69851 - atomic_inc(&dropped_count);
69852 + atomic_inc_unchecked(&dropped_count);
69853 return;
69854 }
69855 entry = ring_buffer_event_data(event);
69856 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69857 index 0d6ff35..67e0ed7 100644
69858 --- a/kernel/trace/trace_output.c
69859 +++ b/kernel/trace/trace_output.c
69860 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69861
69862 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69863 if (!IS_ERR(p)) {
69864 - p = mangle_path(s->buffer + s->len, p, "\n");
69865 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69866 if (p) {
69867 s->len = p - s->buffer;
69868 return 1;
69869 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69870 index d4545f4..a9010a1 100644
69871 --- a/kernel/trace/trace_stack.c
69872 +++ b/kernel/trace/trace_stack.c
69873 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69874 return;
69875
69876 /* we do not handle interrupt stacks yet */
69877 - if (!object_is_on_stack(&this_size))
69878 + if (!object_starts_on_stack(&this_size))
69879 return;
69880
69881 local_irq_save(flags);
69882 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69883 index 209b379..7f76423 100644
69884 --- a/kernel/trace/trace_workqueue.c
69885 +++ b/kernel/trace/trace_workqueue.c
69886 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69887 int cpu;
69888 pid_t pid;
69889 /* Can be inserted from interrupt or user context, need to be atomic */
69890 - atomic_t inserted;
69891 + atomic_unchecked_t inserted;
69892 /*
69893 * Don't need to be atomic, works are serialized in a single workqueue thread
69894 * on a single CPU.
69895 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69896 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69897 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69898 if (node->pid == wq_thread->pid) {
69899 - atomic_inc(&node->inserted);
69900 + atomic_inc_unchecked(&node->inserted);
69901 goto found;
69902 }
69903 }
69904 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69905 tsk = get_pid_task(pid, PIDTYPE_PID);
69906 if (tsk) {
69907 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69908 - atomic_read(&cws->inserted), cws->executed,
69909 + atomic_read_unchecked(&cws->inserted), cws->executed,
69910 tsk->comm);
69911 put_task_struct(tsk);
69912 }
69913 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69914 index 8745ac7..d144e37 100644
69915 --- a/lib/Kconfig.debug
69916 +++ b/lib/Kconfig.debug
69917 @@ -1103,6 +1103,7 @@ config LATENCYTOP
69918 depends on DEBUG_KERNEL
69919 depends on STACKTRACE_SUPPORT
69920 depends on PROC_FS
69921 + depends on !GRKERNSEC_HIDESYM
69922 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69923 select KALLSYMS
69924 select KALLSYMS_ALL
69925 diff --git a/lib/bitmap.c b/lib/bitmap.c
69926 index 0d4a127..33a06c7 100644
69927 --- a/lib/bitmap.c
69928 +++ b/lib/bitmap.c
69929 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69930 {
69931 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69932 u32 chunk;
69933 - const char __user __force *ubuf = (const char __user __force *)buf;
69934 + const char __user *ubuf = (const char __force_user *)buf;
69935
69936 bitmap_zero(maskp, nmaskbits);
69937
69938 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69939 {
69940 if (!access_ok(VERIFY_READ, ubuf, ulen))
69941 return -EFAULT;
69942 - return __bitmap_parse((const char __force *)ubuf,
69943 + return __bitmap_parse((const char __force_kernel *)ubuf,
69944 ulen, 1, maskp, nmaskbits);
69945
69946 }
69947 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69948 {
69949 unsigned a, b;
69950 int c, old_c, totaldigits;
69951 - const char __user __force *ubuf = (const char __user __force *)buf;
69952 + const char __user *ubuf = (const char __force_user *)buf;
69953 int exp_digit, in_range;
69954
69955 totaldigits = c = 0;
69956 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69957 {
69958 if (!access_ok(VERIFY_READ, ubuf, ulen))
69959 return -EFAULT;
69960 - return __bitmap_parselist((const char __force *)ubuf,
69961 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69962 ulen, 1, maskp, nmaskbits);
69963 }
69964 EXPORT_SYMBOL(bitmap_parselist_user);
69965 diff --git a/lib/bug.c b/lib/bug.c
69966 index a28c141..2bd3d95 100644
69967 --- a/lib/bug.c
69968 +++ b/lib/bug.c
69969 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69970 return BUG_TRAP_TYPE_NONE;
69971
69972 bug = find_bug(bugaddr);
69973 + if (!bug)
69974 + return BUG_TRAP_TYPE_NONE;
69975
69976 file = NULL;
69977 line = 0;
69978 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69979 index 0ab9ae8..f01ceca 100644
69980 --- a/lib/debugobjects.c
69981 +++ b/lib/debugobjects.c
69982 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69983 if (limit > 4)
69984 return;
69985
69986 - is_on_stack = object_is_on_stack(addr);
69987 + is_on_stack = object_starts_on_stack(addr);
69988 if (is_on_stack == onstack)
69989 return;
69990
69991 diff --git a/lib/devres.c b/lib/devres.c
69992 index 9676617..5149e15 100644
69993 --- a/lib/devres.c
69994 +++ b/lib/devres.c
69995 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69996 void devm_iounmap(struct device *dev, void __iomem *addr)
69997 {
69998 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69999 - (void *)addr));
70000 + (void __force *)addr));
70001 iounmap(addr);
70002 }
70003 EXPORT_SYMBOL(devm_iounmap);
70004 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70005 {
70006 ioport_unmap(addr);
70007 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70008 - devm_ioport_map_match, (void *)addr));
70009 + devm_ioport_map_match, (void __force *)addr));
70010 }
70011 EXPORT_SYMBOL(devm_ioport_unmap);
70012
70013 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70014 index fea790a..ebb0e82 100644
70015 --- a/lib/dma-debug.c
70016 +++ b/lib/dma-debug.c
70017 @@ -925,7 +925,7 @@ out:
70018
70019 static void check_for_stack(struct device *dev, void *addr)
70020 {
70021 - if (object_is_on_stack(addr))
70022 + if (object_starts_on_stack(addr))
70023 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70024 "stack [addr=%p]\n", addr);
70025 }
70026 diff --git a/lib/extable.c b/lib/extable.c
70027 index 4cac81e..63e9b8f 100644
70028 --- a/lib/extable.c
70029 +++ b/lib/extable.c
70030 @@ -13,6 +13,7 @@
70031 #include <linux/init.h>
70032 #include <linux/sort.h>
70033 #include <asm/uaccess.h>
70034 +#include <asm/pgtable.h>
70035
70036 #ifndef ARCH_HAS_SORT_EXTABLE
70037 /*
70038 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70039 void sort_extable(struct exception_table_entry *start,
70040 struct exception_table_entry *finish)
70041 {
70042 + pax_open_kernel();
70043 sort(start, finish - start, sizeof(struct exception_table_entry),
70044 cmp_ex, NULL);
70045 + pax_close_kernel();
70046 }
70047
70048 #ifdef CONFIG_MODULES
70049 diff --git a/lib/inflate.c b/lib/inflate.c
70050 index 013a761..c28f3fc 100644
70051 --- a/lib/inflate.c
70052 +++ b/lib/inflate.c
70053 @@ -269,7 +269,7 @@ static void free(void *where)
70054 malloc_ptr = free_mem_ptr;
70055 }
70056 #else
70057 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70058 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70059 #define free(a) kfree(a)
70060 #endif
70061
70062 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70063 index bd2bea9..6b3c95e 100644
70064 --- a/lib/is_single_threaded.c
70065 +++ b/lib/is_single_threaded.c
70066 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70067 struct task_struct *p, *t;
70068 bool ret;
70069
70070 + if (!mm)
70071 + return true;
70072 +
70073 if (atomic_read(&task->signal->live) != 1)
70074 return false;
70075
70076 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70077 index dc63d08..95ae14a 100644
70078 --- a/lib/radix-tree.c
70079 +++ b/lib/radix-tree.c
70080 @@ -78,7 +78,7 @@ struct radix_tree_preload {
70081 int nr;
70082 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70083 };
70084 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70085 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70086
70087 static inline void *ptr_to_indirect(void *ptr)
70088 {
70089 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70090 index 38e612e..4fb99a8 100644
70091 --- a/lib/vsprintf.c
70092 +++ b/lib/vsprintf.c
70093 @@ -16,6 +16,9 @@
70094 * - scnprintf and vscnprintf
70095 */
70096
70097 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70098 +#define __INCLUDED_BY_HIDESYM 1
70099 +#endif
70100 #include <stdarg.h>
70101 #include <linux/module.h>
70102 #include <linux/types.h>
70103 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70104 char sym[KSYM_SYMBOL_LEN];
70105 if (ext == 'B')
70106 sprint_backtrace(sym, value);
70107 - else if (ext != 'f' && ext != 's')
70108 + else if (ext != 'f' && ext != 's' && ext != 'a')
70109 sprint_symbol(sym, value);
70110 else
70111 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70112 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70113 return number(buf, end, *(const netdev_features_t *)addr, spec);
70114 }
70115
70116 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70117 +int kptr_restrict __read_mostly = 2;
70118 +#else
70119 int kptr_restrict __read_mostly;
70120 +#endif
70121
70122 /*
70123 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70124 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70125 * - 'S' For symbolic direct pointers with offset
70126 * - 's' For symbolic direct pointers without offset
70127 * - 'B' For backtraced symbolic direct pointers with offset
70128 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70129 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70130 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70131 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70132 * - 'M' For a 6-byte MAC address, it prints the address in the
70133 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70134 {
70135 if (!ptr && *fmt != 'K') {
70136 /*
70137 - * Print (null) with the same width as a pointer so it makes
70138 + * Print (nil) with the same width as a pointer so it makes
70139 * tabular output look nice.
70140 */
70141 if (spec.field_width == -1)
70142 spec.field_width = 2 * sizeof(void *);
70143 - return string(buf, end, "(null)", spec);
70144 + return string(buf, end, "(nil)", spec);
70145 }
70146
70147 switch (*fmt) {
70148 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70149 /* Fallthrough */
70150 case 'S':
70151 case 's':
70152 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70153 + break;
70154 +#else
70155 + return symbol_string(buf, end, ptr, spec, *fmt);
70156 +#endif
70157 + case 'A':
70158 + case 'a':
70159 case 'B':
70160 return symbol_string(buf, end, ptr, spec, *fmt);
70161 case 'R':
70162 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70163 typeof(type) value; \
70164 if (sizeof(type) == 8) { \
70165 args = PTR_ALIGN(args, sizeof(u32)); \
70166 - *(u32 *)&value = *(u32 *)args; \
70167 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70168 + *(u32 *)&value = *(const u32 *)args; \
70169 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70170 } else { \
70171 args = PTR_ALIGN(args, sizeof(type)); \
70172 - value = *(typeof(type) *)args; \
70173 + value = *(const typeof(type) *)args; \
70174 } \
70175 args += sizeof(type); \
70176 value; \
70177 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70178 case FORMAT_TYPE_STR: {
70179 const char *str_arg = args;
70180 args += strlen(str_arg) + 1;
70181 - str = string(str, end, (char *)str_arg, spec);
70182 + str = string(str, end, str_arg, spec);
70183 break;
70184 }
70185
70186 diff --git a/localversion-grsec b/localversion-grsec
70187 new file mode 100644
70188 index 0000000..7cd6065
70189 --- /dev/null
70190 +++ b/localversion-grsec
70191 @@ -0,0 +1 @@
70192 +-grsec
70193 diff --git a/mm/Kconfig b/mm/Kconfig
70194 index e338407..49b5b7a 100644
70195 --- a/mm/Kconfig
70196 +++ b/mm/Kconfig
70197 @@ -247,10 +247,10 @@ config KSM
70198 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70199
70200 config DEFAULT_MMAP_MIN_ADDR
70201 - int "Low address space to protect from user allocation"
70202 + int "Low address space to protect from user allocation"
70203 depends on MMU
70204 - default 4096
70205 - help
70206 + default 65536
70207 + help
70208 This is the portion of low virtual memory which should be protected
70209 from userspace allocation. Keeping a user from writing to low pages
70210 can help reduce the impact of kernel NULL pointer bugs.
70211 diff --git a/mm/filemap.c b/mm/filemap.c
70212 index b662757..3081ddd 100644
70213 --- a/mm/filemap.c
70214 +++ b/mm/filemap.c
70215 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70216 struct address_space *mapping = file->f_mapping;
70217
70218 if (!mapping->a_ops->readpage)
70219 - return -ENOEXEC;
70220 + return -ENODEV;
70221 file_accessed(file);
70222 vma->vm_ops = &generic_file_vm_ops;
70223 vma->vm_flags |= VM_CAN_NONLINEAR;
70224 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70225 *pos = i_size_read(inode);
70226
70227 if (limit != RLIM_INFINITY) {
70228 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70229 if (*pos >= limit) {
70230 send_sig(SIGXFSZ, current, 0);
70231 return -EFBIG;
70232 diff --git a/mm/fremap.c b/mm/fremap.c
70233 index 9ed4fd4..c42648d 100644
70234 --- a/mm/fremap.c
70235 +++ b/mm/fremap.c
70236 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70237 retry:
70238 vma = find_vma(mm, start);
70239
70240 +#ifdef CONFIG_PAX_SEGMEXEC
70241 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70242 + goto out;
70243 +#endif
70244 +
70245 /*
70246 * Make sure the vma is shared, that it supports prefaulting,
70247 * and that the remapped range is valid and fully within
70248 diff --git a/mm/highmem.c b/mm/highmem.c
70249 index 57d82c6..e9e0552 100644
70250 --- a/mm/highmem.c
70251 +++ b/mm/highmem.c
70252 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70253 * So no dangers, even with speculative execution.
70254 */
70255 page = pte_page(pkmap_page_table[i]);
70256 + pax_open_kernel();
70257 pte_clear(&init_mm, (unsigned long)page_address(page),
70258 &pkmap_page_table[i]);
70259 -
70260 + pax_close_kernel();
70261 set_page_address(page, NULL);
70262 need_flush = 1;
70263 }
70264 @@ -186,9 +187,11 @@ start:
70265 }
70266 }
70267 vaddr = PKMAP_ADDR(last_pkmap_nr);
70268 +
70269 + pax_open_kernel();
70270 set_pte_at(&init_mm, vaddr,
70271 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70272 -
70273 + pax_close_kernel();
70274 pkmap_count[last_pkmap_nr] = 1;
70275 set_page_address(page, (void *)vaddr);
70276
70277 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70278 index 8f7fc39..69bf1e9 100644
70279 --- a/mm/huge_memory.c
70280 +++ b/mm/huge_memory.c
70281 @@ -733,7 +733,7 @@ out:
70282 * run pte_offset_map on the pmd, if an huge pmd could
70283 * materialize from under us from a different thread.
70284 */
70285 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70286 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70287 return VM_FAULT_OOM;
70288 /* if an huge pmd materialized from under us just retry later */
70289 if (unlikely(pmd_trans_huge(*pmd)))
70290 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70291 index a876871..132cde0 100644
70292 --- a/mm/hugetlb.c
70293 +++ b/mm/hugetlb.c
70294 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70295 return 1;
70296 }
70297
70298 +#ifdef CONFIG_PAX_SEGMEXEC
70299 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70300 +{
70301 + struct mm_struct *mm = vma->vm_mm;
70302 + struct vm_area_struct *vma_m;
70303 + unsigned long address_m;
70304 + pte_t *ptep_m;
70305 +
70306 + vma_m = pax_find_mirror_vma(vma);
70307 + if (!vma_m)
70308 + return;
70309 +
70310 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70311 + address_m = address + SEGMEXEC_TASK_SIZE;
70312 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70313 + get_page(page_m);
70314 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70315 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70316 +}
70317 +#endif
70318 +
70319 /*
70320 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70321 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70322 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
70323 make_huge_pte(vma, new_page, 1));
70324 page_remove_rmap(old_page);
70325 hugepage_add_new_anon_rmap(new_page, vma, address);
70326 +
70327 +#ifdef CONFIG_PAX_SEGMEXEC
70328 + pax_mirror_huge_pte(vma, address, new_page);
70329 +#endif
70330 +
70331 /* Make the old page be freed below */
70332 new_page = old_page;
70333 mmu_notifier_invalidate_range_end(mm,
70334 @@ -2613,6 +2639,10 @@ retry:
70335 && (vma->vm_flags & VM_SHARED)));
70336 set_huge_pte_at(mm, address, ptep, new_pte);
70337
70338 +#ifdef CONFIG_PAX_SEGMEXEC
70339 + pax_mirror_huge_pte(vma, address, page);
70340 +#endif
70341 +
70342 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70343 /* Optimization, do the COW without a second fault */
70344 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70345 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70346 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70347 struct hstate *h = hstate_vma(vma);
70348
70349 +#ifdef CONFIG_PAX_SEGMEXEC
70350 + struct vm_area_struct *vma_m;
70351 +#endif
70352 +
70353 address &= huge_page_mask(h);
70354
70355 ptep = huge_pte_offset(mm, address);
70356 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70357 VM_FAULT_SET_HINDEX(h - hstates);
70358 }
70359
70360 +#ifdef CONFIG_PAX_SEGMEXEC
70361 + vma_m = pax_find_mirror_vma(vma);
70362 + if (vma_m) {
70363 + unsigned long address_m;
70364 +
70365 + if (vma->vm_start > vma_m->vm_start) {
70366 + address_m = address;
70367 + address -= SEGMEXEC_TASK_SIZE;
70368 + vma = vma_m;
70369 + h = hstate_vma(vma);
70370 + } else
70371 + address_m = address + SEGMEXEC_TASK_SIZE;
70372 +
70373 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70374 + return VM_FAULT_OOM;
70375 + address_m &= HPAGE_MASK;
70376 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70377 + }
70378 +#endif
70379 +
70380 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70381 if (!ptep)
70382 return VM_FAULT_OOM;
70383 diff --git a/mm/internal.h b/mm/internal.h
70384 index 2189af4..f2ca332 100644
70385 --- a/mm/internal.h
70386 +++ b/mm/internal.h
70387 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70388 * in mm/page_alloc.c
70389 */
70390 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70391 +extern void free_compound_page(struct page *page);
70392 extern void prep_compound_page(struct page *page, unsigned long order);
70393 #ifdef CONFIG_MEMORY_FAILURE
70394 extern bool is_free_buddy_page(struct page *page);
70395 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70396 index 45eb621..6ccd8ea 100644
70397 --- a/mm/kmemleak.c
70398 +++ b/mm/kmemleak.c
70399 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70400
70401 for (i = 0; i < object->trace_len; i++) {
70402 void *ptr = (void *)object->trace[i];
70403 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70404 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70405 }
70406 }
70407
70408 diff --git a/mm/maccess.c b/mm/maccess.c
70409 index d53adf9..03a24bf 100644
70410 --- a/mm/maccess.c
70411 +++ b/mm/maccess.c
70412 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70413 set_fs(KERNEL_DS);
70414 pagefault_disable();
70415 ret = __copy_from_user_inatomic(dst,
70416 - (__force const void __user *)src, size);
70417 + (const void __force_user *)src, size);
70418 pagefault_enable();
70419 set_fs(old_fs);
70420
70421 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70422
70423 set_fs(KERNEL_DS);
70424 pagefault_disable();
70425 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70426 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70427 pagefault_enable();
70428 set_fs(old_fs);
70429
70430 diff --git a/mm/madvise.c b/mm/madvise.c
70431 index 74bf193..feb6fd3 100644
70432 --- a/mm/madvise.c
70433 +++ b/mm/madvise.c
70434 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70435 pgoff_t pgoff;
70436 unsigned long new_flags = vma->vm_flags;
70437
70438 +#ifdef CONFIG_PAX_SEGMEXEC
70439 + struct vm_area_struct *vma_m;
70440 +#endif
70441 +
70442 switch (behavior) {
70443 case MADV_NORMAL:
70444 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70445 @@ -110,6 +114,13 @@ success:
70446 /*
70447 * vm_flags is protected by the mmap_sem held in write mode.
70448 */
70449 +
70450 +#ifdef CONFIG_PAX_SEGMEXEC
70451 + vma_m = pax_find_mirror_vma(vma);
70452 + if (vma_m)
70453 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70454 +#endif
70455 +
70456 vma->vm_flags = new_flags;
70457
70458 out:
70459 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70460 struct vm_area_struct ** prev,
70461 unsigned long start, unsigned long end)
70462 {
70463 +
70464 +#ifdef CONFIG_PAX_SEGMEXEC
70465 + struct vm_area_struct *vma_m;
70466 +#endif
70467 +
70468 *prev = vma;
70469 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70470 return -EINVAL;
70471 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70472 zap_page_range(vma, start, end - start, &details);
70473 } else
70474 zap_page_range(vma, start, end - start, NULL);
70475 +
70476 +#ifdef CONFIG_PAX_SEGMEXEC
70477 + vma_m = pax_find_mirror_vma(vma);
70478 + if (vma_m) {
70479 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70480 + struct zap_details details = {
70481 + .nonlinear_vma = vma_m,
70482 + .last_index = ULONG_MAX,
70483 + };
70484 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70485 + } else
70486 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70487 + }
70488 +#endif
70489 +
70490 return 0;
70491 }
70492
70493 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70494 if (end < start)
70495 goto out;
70496
70497 +#ifdef CONFIG_PAX_SEGMEXEC
70498 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70499 + if (end > SEGMEXEC_TASK_SIZE)
70500 + goto out;
70501 + } else
70502 +#endif
70503 +
70504 + if (end > TASK_SIZE)
70505 + goto out;
70506 +
70507 error = 0;
70508 if (end == start)
70509 goto out;
70510 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70511 index 56080ea..115071e 100644
70512 --- a/mm/memory-failure.c
70513 +++ b/mm/memory-failure.c
70514 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70515
70516 int sysctl_memory_failure_recovery __read_mostly = 1;
70517
70518 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70519 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70520
70521 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70522
70523 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70524 si.si_signo = SIGBUS;
70525 si.si_errno = 0;
70526 si.si_code = BUS_MCEERR_AO;
70527 - si.si_addr = (void *)addr;
70528 + si.si_addr = (void __user *)addr;
70529 #ifdef __ARCH_SI_TRAPNO
70530 si.si_trapno = trapno;
70531 #endif
70532 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70533 }
70534
70535 nr_pages = 1 << compound_trans_order(hpage);
70536 - atomic_long_add(nr_pages, &mce_bad_pages);
70537 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70538
70539 /*
70540 * We need/can do nothing about count=0 pages.
70541 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70542 if (!PageHWPoison(hpage)
70543 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70544 || (p != hpage && TestSetPageHWPoison(hpage))) {
70545 - atomic_long_sub(nr_pages, &mce_bad_pages);
70546 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70547 return 0;
70548 }
70549 set_page_hwpoison_huge_page(hpage);
70550 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70551 }
70552 if (hwpoison_filter(p)) {
70553 if (TestClearPageHWPoison(p))
70554 - atomic_long_sub(nr_pages, &mce_bad_pages);
70555 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70556 unlock_page(hpage);
70557 put_page(hpage);
70558 return 0;
70559 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70560 return 0;
70561 }
70562 if (TestClearPageHWPoison(p))
70563 - atomic_long_sub(nr_pages, &mce_bad_pages);
70564 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70565 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70566 return 0;
70567 }
70568 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70569 */
70570 if (TestClearPageHWPoison(page)) {
70571 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70572 - atomic_long_sub(nr_pages, &mce_bad_pages);
70573 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70574 freeit = 1;
70575 if (PageHuge(page))
70576 clear_page_hwpoison_huge_page(page);
70577 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70578 }
70579 done:
70580 if (!PageHWPoison(hpage))
70581 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70582 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70583 set_page_hwpoison_huge_page(hpage);
70584 dequeue_hwpoisoned_huge_page(hpage);
70585 /* keep elevated page count for bad page */
70586 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70587 return ret;
70588
70589 done:
70590 - atomic_long_add(1, &mce_bad_pages);
70591 + atomic_long_add_unchecked(1, &mce_bad_pages);
70592 SetPageHWPoison(page);
70593 /* keep elevated page count for bad page */
70594 return ret;
70595 diff --git a/mm/memory.c b/mm/memory.c
70596 index 10b4dda..764ee07 100644
70597 --- a/mm/memory.c
70598 +++ b/mm/memory.c
70599 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70600 return;
70601
70602 pmd = pmd_offset(pud, start);
70603 +
70604 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70605 pud_clear(pud);
70606 pmd_free_tlb(tlb, pmd, start);
70607 +#endif
70608 +
70609 }
70610
70611 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70612 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70613 if (end - 1 > ceiling - 1)
70614 return;
70615
70616 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70617 pud = pud_offset(pgd, start);
70618 pgd_clear(pgd);
70619 pud_free_tlb(tlb, pud, start);
70620 +#endif
70621 +
70622 }
70623
70624 /*
70625 @@ -1593,12 +1600,6 @@ no_page_table:
70626 return page;
70627 }
70628
70629 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70630 -{
70631 - return stack_guard_page_start(vma, addr) ||
70632 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70633 -}
70634 -
70635 /**
70636 * __get_user_pages() - pin user pages in memory
70637 * @tsk: task_struct of target task
70638 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70639 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70640 i = 0;
70641
70642 - do {
70643 + while (nr_pages) {
70644 struct vm_area_struct *vma;
70645
70646 - vma = find_extend_vma(mm, start);
70647 + vma = find_vma(mm, start);
70648 if (!vma && in_gate_area(mm, start)) {
70649 unsigned long pg = start & PAGE_MASK;
70650 pgd_t *pgd;
70651 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70652 goto next_page;
70653 }
70654
70655 - if (!vma ||
70656 + if (!vma || start < vma->vm_start ||
70657 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70658 !(vm_flags & vma->vm_flags))
70659 return i ? : -EFAULT;
70660 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70661 int ret;
70662 unsigned int fault_flags = 0;
70663
70664 - /* For mlock, just skip the stack guard page. */
70665 - if (foll_flags & FOLL_MLOCK) {
70666 - if (stack_guard_page(vma, start))
70667 - goto next_page;
70668 - }
70669 if (foll_flags & FOLL_WRITE)
70670 fault_flags |= FAULT_FLAG_WRITE;
70671 if (nonblocking)
70672 @@ -1827,7 +1823,7 @@ next_page:
70673 start += PAGE_SIZE;
70674 nr_pages--;
70675 } while (nr_pages && start < vma->vm_end);
70676 - } while (nr_pages);
70677 + }
70678 return i;
70679 }
70680 EXPORT_SYMBOL(__get_user_pages);
70681 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70682 page_add_file_rmap(page);
70683 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70684
70685 +#ifdef CONFIG_PAX_SEGMEXEC
70686 + pax_mirror_file_pte(vma, addr, page, ptl);
70687 +#endif
70688 +
70689 retval = 0;
70690 pte_unmap_unlock(pte, ptl);
70691 return retval;
70692 @@ -2068,10 +2068,22 @@ out:
70693 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70694 struct page *page)
70695 {
70696 +
70697 +#ifdef CONFIG_PAX_SEGMEXEC
70698 + struct vm_area_struct *vma_m;
70699 +#endif
70700 +
70701 if (addr < vma->vm_start || addr >= vma->vm_end)
70702 return -EFAULT;
70703 if (!page_count(page))
70704 return -EINVAL;
70705 +
70706 +#ifdef CONFIG_PAX_SEGMEXEC
70707 + vma_m = pax_find_mirror_vma(vma);
70708 + if (vma_m)
70709 + vma_m->vm_flags |= VM_INSERTPAGE;
70710 +#endif
70711 +
70712 vma->vm_flags |= VM_INSERTPAGE;
70713 return insert_page(vma, addr, page, vma->vm_page_prot);
70714 }
70715 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70716 unsigned long pfn)
70717 {
70718 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70719 + BUG_ON(vma->vm_mirror);
70720
70721 if (addr < vma->vm_start || addr >= vma->vm_end)
70722 return -EFAULT;
70723 @@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70724 copy_user_highpage(dst, src, va, vma);
70725 }
70726
70727 +#ifdef CONFIG_PAX_SEGMEXEC
70728 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70729 +{
70730 + struct mm_struct *mm = vma->vm_mm;
70731 + spinlock_t *ptl;
70732 + pte_t *pte, entry;
70733 +
70734 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70735 + entry = *pte;
70736 + if (!pte_present(entry)) {
70737 + if (!pte_none(entry)) {
70738 + BUG_ON(pte_file(entry));
70739 + free_swap_and_cache(pte_to_swp_entry(entry));
70740 + pte_clear_not_present_full(mm, address, pte, 0);
70741 + }
70742 + } else {
70743 + struct page *page;
70744 +
70745 + flush_cache_page(vma, address, pte_pfn(entry));
70746 + entry = ptep_clear_flush(vma, address, pte);
70747 + BUG_ON(pte_dirty(entry));
70748 + page = vm_normal_page(vma, address, entry);
70749 + if (page) {
70750 + update_hiwater_rss(mm);
70751 + if (PageAnon(page))
70752 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70753 + else
70754 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70755 + page_remove_rmap(page);
70756 + page_cache_release(page);
70757 + }
70758 + }
70759 + pte_unmap_unlock(pte, ptl);
70760 +}
70761 +
70762 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70763 + *
70764 + * the ptl of the lower mapped page is held on entry and is not released on exit
70765 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70766 + */
70767 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70768 +{
70769 + struct mm_struct *mm = vma->vm_mm;
70770 + unsigned long address_m;
70771 + spinlock_t *ptl_m;
70772 + struct vm_area_struct *vma_m;
70773 + pmd_t *pmd_m;
70774 + pte_t *pte_m, entry_m;
70775 +
70776 + BUG_ON(!page_m || !PageAnon(page_m));
70777 +
70778 + vma_m = pax_find_mirror_vma(vma);
70779 + if (!vma_m)
70780 + return;
70781 +
70782 + BUG_ON(!PageLocked(page_m));
70783 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70784 + address_m = address + SEGMEXEC_TASK_SIZE;
70785 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70786 + pte_m = pte_offset_map(pmd_m, address_m);
70787 + ptl_m = pte_lockptr(mm, pmd_m);
70788 + if (ptl != ptl_m) {
70789 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70790 + if (!pte_none(*pte_m))
70791 + goto out;
70792 + }
70793 +
70794 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70795 + page_cache_get(page_m);
70796 + page_add_anon_rmap(page_m, vma_m, address_m);
70797 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70798 + set_pte_at(mm, address_m, pte_m, entry_m);
70799 + update_mmu_cache(vma_m, address_m, entry_m);
70800 +out:
70801 + if (ptl != ptl_m)
70802 + spin_unlock(ptl_m);
70803 + pte_unmap(pte_m);
70804 + unlock_page(page_m);
70805 +}
70806 +
70807 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70808 +{
70809 + struct mm_struct *mm = vma->vm_mm;
70810 + unsigned long address_m;
70811 + spinlock_t *ptl_m;
70812 + struct vm_area_struct *vma_m;
70813 + pmd_t *pmd_m;
70814 + pte_t *pte_m, entry_m;
70815 +
70816 + BUG_ON(!page_m || PageAnon(page_m));
70817 +
70818 + vma_m = pax_find_mirror_vma(vma);
70819 + if (!vma_m)
70820 + return;
70821 +
70822 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70823 + address_m = address + SEGMEXEC_TASK_SIZE;
70824 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70825 + pte_m = pte_offset_map(pmd_m, address_m);
70826 + ptl_m = pte_lockptr(mm, pmd_m);
70827 + if (ptl != ptl_m) {
70828 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70829 + if (!pte_none(*pte_m))
70830 + goto out;
70831 + }
70832 +
70833 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70834 + page_cache_get(page_m);
70835 + page_add_file_rmap(page_m);
70836 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70837 + set_pte_at(mm, address_m, pte_m, entry_m);
70838 + update_mmu_cache(vma_m, address_m, entry_m);
70839 +out:
70840 + if (ptl != ptl_m)
70841 + spin_unlock(ptl_m);
70842 + pte_unmap(pte_m);
70843 +}
70844 +
70845 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70846 +{
70847 + struct mm_struct *mm = vma->vm_mm;
70848 + unsigned long address_m;
70849 + spinlock_t *ptl_m;
70850 + struct vm_area_struct *vma_m;
70851 + pmd_t *pmd_m;
70852 + pte_t *pte_m, entry_m;
70853 +
70854 + vma_m = pax_find_mirror_vma(vma);
70855 + if (!vma_m)
70856 + return;
70857 +
70858 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70859 + address_m = address + SEGMEXEC_TASK_SIZE;
70860 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70861 + pte_m = pte_offset_map(pmd_m, address_m);
70862 + ptl_m = pte_lockptr(mm, pmd_m);
70863 + if (ptl != ptl_m) {
70864 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70865 + if (!pte_none(*pte_m))
70866 + goto out;
70867 + }
70868 +
70869 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70870 + set_pte_at(mm, address_m, pte_m, entry_m);
70871 +out:
70872 + if (ptl != ptl_m)
70873 + spin_unlock(ptl_m);
70874 + pte_unmap(pte_m);
70875 +}
70876 +
70877 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70878 +{
70879 + struct page *page_m;
70880 + pte_t entry;
70881 +
70882 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70883 + goto out;
70884 +
70885 + entry = *pte;
70886 + page_m = vm_normal_page(vma, address, entry);
70887 + if (!page_m)
70888 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70889 + else if (PageAnon(page_m)) {
70890 + if (pax_find_mirror_vma(vma)) {
70891 + pte_unmap_unlock(pte, ptl);
70892 + lock_page(page_m);
70893 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70894 + if (pte_same(entry, *pte))
70895 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70896 + else
70897 + unlock_page(page_m);
70898 + }
70899 + } else
70900 + pax_mirror_file_pte(vma, address, page_m, ptl);
70901 +
70902 +out:
70903 + pte_unmap_unlock(pte, ptl);
70904 +}
70905 +#endif
70906 +
70907 /*
70908 * This routine handles present pages, when users try to write
70909 * to a shared page. It is done by copying the page to a new address
70910 @@ -2683,6 +2876,12 @@ gotten:
70911 */
70912 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70913 if (likely(pte_same(*page_table, orig_pte))) {
70914 +
70915 +#ifdef CONFIG_PAX_SEGMEXEC
70916 + if (pax_find_mirror_vma(vma))
70917 + BUG_ON(!trylock_page(new_page));
70918 +#endif
70919 +
70920 if (old_page) {
70921 if (!PageAnon(old_page)) {
70922 dec_mm_counter_fast(mm, MM_FILEPAGES);
70923 @@ -2734,6 +2933,10 @@ gotten:
70924 page_remove_rmap(old_page);
70925 }
70926
70927 +#ifdef CONFIG_PAX_SEGMEXEC
70928 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70929 +#endif
70930 +
70931 /* Free the old page.. */
70932 new_page = old_page;
70933 ret |= VM_FAULT_WRITE;
70934 @@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70935 swap_free(entry);
70936 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70937 try_to_free_swap(page);
70938 +
70939 +#ifdef CONFIG_PAX_SEGMEXEC
70940 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70941 +#endif
70942 +
70943 unlock_page(page);
70944 if (swapcache) {
70945 /*
70946 @@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70947
70948 /* No need to invalidate - it was non-present before */
70949 update_mmu_cache(vma, address, page_table);
70950 +
70951 +#ifdef CONFIG_PAX_SEGMEXEC
70952 + pax_mirror_anon_pte(vma, address, page, ptl);
70953 +#endif
70954 +
70955 unlock:
70956 pte_unmap_unlock(page_table, ptl);
70957 out:
70958 @@ -3055,40 +3268,6 @@ out_release:
70959 }
70960
70961 /*
70962 - * This is like a special single-page "expand_{down|up}wards()",
70963 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70964 - * doesn't hit another vma.
70965 - */
70966 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70967 -{
70968 - address &= PAGE_MASK;
70969 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70970 - struct vm_area_struct *prev = vma->vm_prev;
70971 -
70972 - /*
70973 - * Is there a mapping abutting this one below?
70974 - *
70975 - * That's only ok if it's the same stack mapping
70976 - * that has gotten split..
70977 - */
70978 - if (prev && prev->vm_end == address)
70979 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70980 -
70981 - expand_downwards(vma, address - PAGE_SIZE);
70982 - }
70983 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70984 - struct vm_area_struct *next = vma->vm_next;
70985 -
70986 - /* As VM_GROWSDOWN but s/below/above/ */
70987 - if (next && next->vm_start == address + PAGE_SIZE)
70988 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70989 -
70990 - expand_upwards(vma, address + PAGE_SIZE);
70991 - }
70992 - return 0;
70993 -}
70994 -
70995 -/*
70996 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70997 * but allow concurrent faults), and pte mapped but not yet locked.
70998 * We return with mmap_sem still held, but pte unmapped and unlocked.
70999 @@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71000 unsigned long address, pte_t *page_table, pmd_t *pmd,
71001 unsigned int flags)
71002 {
71003 - struct page *page;
71004 + struct page *page = NULL;
71005 spinlock_t *ptl;
71006 pte_t entry;
71007
71008 - pte_unmap(page_table);
71009 -
71010 - /* Check if we need to add a guard page to the stack */
71011 - if (check_stack_guard_page(vma, address) < 0)
71012 - return VM_FAULT_SIGBUS;
71013 -
71014 - /* Use the zero-page for reads */
71015 if (!(flags & FAULT_FLAG_WRITE)) {
71016 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71017 vma->vm_page_prot));
71018 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71019 + ptl = pte_lockptr(mm, pmd);
71020 + spin_lock(ptl);
71021 if (!pte_none(*page_table))
71022 goto unlock;
71023 goto setpte;
71024 }
71025
71026 /* Allocate our own private page. */
71027 + pte_unmap(page_table);
71028 +
71029 if (unlikely(anon_vma_prepare(vma)))
71030 goto oom;
71031 page = alloc_zeroed_user_highpage_movable(vma, address);
71032 @@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71033 if (!pte_none(*page_table))
71034 goto release;
71035
71036 +#ifdef CONFIG_PAX_SEGMEXEC
71037 + if (pax_find_mirror_vma(vma))
71038 + BUG_ON(!trylock_page(page));
71039 +#endif
71040 +
71041 inc_mm_counter_fast(mm, MM_ANONPAGES);
71042 page_add_new_anon_rmap(page, vma, address);
71043 setpte:
71044 @@ -3143,6 +3323,12 @@ setpte:
71045
71046 /* No need to invalidate - it was non-present before */
71047 update_mmu_cache(vma, address, page_table);
71048 +
71049 +#ifdef CONFIG_PAX_SEGMEXEC
71050 + if (page)
71051 + pax_mirror_anon_pte(vma, address, page, ptl);
71052 +#endif
71053 +
71054 unlock:
71055 pte_unmap_unlock(page_table, ptl);
71056 return 0;
71057 @@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71058 */
71059 /* Only go through if we didn't race with anybody else... */
71060 if (likely(pte_same(*page_table, orig_pte))) {
71061 +
71062 +#ifdef CONFIG_PAX_SEGMEXEC
71063 + if (anon && pax_find_mirror_vma(vma))
71064 + BUG_ON(!trylock_page(page));
71065 +#endif
71066 +
71067 flush_icache_page(vma, page);
71068 entry = mk_pte(page, vma->vm_page_prot);
71069 if (flags & FAULT_FLAG_WRITE)
71070 @@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71071
71072 /* no need to invalidate: a not-present page won't be cached */
71073 update_mmu_cache(vma, address, page_table);
71074 +
71075 +#ifdef CONFIG_PAX_SEGMEXEC
71076 + if (anon)
71077 + pax_mirror_anon_pte(vma, address, page, ptl);
71078 + else
71079 + pax_mirror_file_pte(vma, address, page, ptl);
71080 +#endif
71081 +
71082 } else {
71083 if (cow_page)
71084 mem_cgroup_uncharge_page(cow_page);
71085 @@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
71086 if (flags & FAULT_FLAG_WRITE)
71087 flush_tlb_fix_spurious_fault(vma, address);
71088 }
71089 +
71090 +#ifdef CONFIG_PAX_SEGMEXEC
71091 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71092 + return 0;
71093 +#endif
71094 +
71095 unlock:
71096 pte_unmap_unlock(pte, ptl);
71097 return 0;
71098 @@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71099 pmd_t *pmd;
71100 pte_t *pte;
71101
71102 +#ifdef CONFIG_PAX_SEGMEXEC
71103 + struct vm_area_struct *vma_m;
71104 +#endif
71105 +
71106 __set_current_state(TASK_RUNNING);
71107
71108 count_vm_event(PGFAULT);
71109 @@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71110 if (unlikely(is_vm_hugetlb_page(vma)))
71111 return hugetlb_fault(mm, vma, address, flags);
71112
71113 +#ifdef CONFIG_PAX_SEGMEXEC
71114 + vma_m = pax_find_mirror_vma(vma);
71115 + if (vma_m) {
71116 + unsigned long address_m;
71117 + pgd_t *pgd_m;
71118 + pud_t *pud_m;
71119 + pmd_t *pmd_m;
71120 +
71121 + if (vma->vm_start > vma_m->vm_start) {
71122 + address_m = address;
71123 + address -= SEGMEXEC_TASK_SIZE;
71124 + vma = vma_m;
71125 + } else
71126 + address_m = address + SEGMEXEC_TASK_SIZE;
71127 +
71128 + pgd_m = pgd_offset(mm, address_m);
71129 + pud_m = pud_alloc(mm, pgd_m, address_m);
71130 + if (!pud_m)
71131 + return VM_FAULT_OOM;
71132 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71133 + if (!pmd_m)
71134 + return VM_FAULT_OOM;
71135 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71136 + return VM_FAULT_OOM;
71137 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71138 + }
71139 +#endif
71140 +
71141 pgd = pgd_offset(mm, address);
71142 pud = pud_alloc(mm, pgd, address);
71143 if (!pud)
71144 @@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71145 * run pte_offset_map on the pmd, if an huge pmd could
71146 * materialize from under us from a different thread.
71147 */
71148 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71149 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71150 return VM_FAULT_OOM;
71151 /* if an huge pmd materialized from under us just retry later */
71152 if (unlikely(pmd_trans_huge(*pmd)))
71153 @@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
71154 gate_vma.vm_start = FIXADDR_USER_START;
71155 gate_vma.vm_end = FIXADDR_USER_END;
71156 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71157 - gate_vma.vm_page_prot = __P101;
71158 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71159 /*
71160 * Make sure the vDSO gets into every core dump.
71161 * Dumping its contents makes post-mortem fully interpretable later
71162 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71163 index 0a37570..2048346 100644
71164 --- a/mm/mempolicy.c
71165 +++ b/mm/mempolicy.c
71166 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71167 unsigned long vmstart;
71168 unsigned long vmend;
71169
71170 +#ifdef CONFIG_PAX_SEGMEXEC
71171 + struct vm_area_struct *vma_m;
71172 +#endif
71173 +
71174 vma = find_vma(mm, start);
71175 if (!vma || vma->vm_start > start)
71176 return -EFAULT;
71177 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71178 err = policy_vma(vma, new_pol);
71179 if (err)
71180 goto out;
71181 +
71182 +#ifdef CONFIG_PAX_SEGMEXEC
71183 + vma_m = pax_find_mirror_vma(vma);
71184 + if (vma_m) {
71185 + err = policy_vma(vma_m, new_pol);
71186 + if (err)
71187 + goto out;
71188 + }
71189 +#endif
71190 +
71191 }
71192
71193 out:
71194 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71195
71196 if (end < start)
71197 return -EINVAL;
71198 +
71199 +#ifdef CONFIG_PAX_SEGMEXEC
71200 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71201 + if (end > SEGMEXEC_TASK_SIZE)
71202 + return -EINVAL;
71203 + } else
71204 +#endif
71205 +
71206 + if (end > TASK_SIZE)
71207 + return -EINVAL;
71208 +
71209 if (end == start)
71210 return 0;
71211
71212 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71213 if (!mm)
71214 goto out;
71215
71216 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71217 + if (mm != current->mm &&
71218 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71219 + err = -EPERM;
71220 + goto out;
71221 + }
71222 +#endif
71223 +
71224 /*
71225 * Check if this process has the right to modify the specified
71226 * process. The right exists if the process has administrative
71227 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71228 rcu_read_lock();
71229 tcred = __task_cred(task);
71230 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71231 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71232 - !capable(CAP_SYS_NICE)) {
71233 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71234 rcu_read_unlock();
71235 err = -EPERM;
71236 goto out;
71237 diff --git a/mm/migrate.c b/mm/migrate.c
71238 index 1503b6b..156c672 100644
71239 --- a/mm/migrate.c
71240 +++ b/mm/migrate.c
71241 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71242 if (!mm)
71243 return -EINVAL;
71244
71245 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71246 + if (mm != current->mm &&
71247 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71248 + err = -EPERM;
71249 + goto out;
71250 + }
71251 +#endif
71252 +
71253 /*
71254 * Check if this process has the right to modify the specified
71255 * process. The right exists if the process has administrative
71256 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71257 rcu_read_lock();
71258 tcred = __task_cred(task);
71259 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71260 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71261 - !capable(CAP_SYS_NICE)) {
71262 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71263 rcu_read_unlock();
71264 err = -EPERM;
71265 goto out;
71266 diff --git a/mm/mlock.c b/mm/mlock.c
71267 index ef726e8..13e0901 100644
71268 --- a/mm/mlock.c
71269 +++ b/mm/mlock.c
71270 @@ -13,6 +13,7 @@
71271 #include <linux/pagemap.h>
71272 #include <linux/mempolicy.h>
71273 #include <linux/syscalls.h>
71274 +#include <linux/security.h>
71275 #include <linux/sched.h>
71276 #include <linux/export.h>
71277 #include <linux/rmap.h>
71278 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71279 return -EINVAL;
71280 if (end == start)
71281 return 0;
71282 + if (end > TASK_SIZE)
71283 + return -EINVAL;
71284 +
71285 vma = find_vma(current->mm, start);
71286 if (!vma || vma->vm_start > start)
71287 return -ENOMEM;
71288 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71289 for (nstart = start ; ; ) {
71290 vm_flags_t newflags;
71291
71292 +#ifdef CONFIG_PAX_SEGMEXEC
71293 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71294 + break;
71295 +#endif
71296 +
71297 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71298
71299 newflags = vma->vm_flags | VM_LOCKED;
71300 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71301 lock_limit >>= PAGE_SHIFT;
71302
71303 /* check against resource limits */
71304 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71305 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71306 error = do_mlock(start, len, 1);
71307 up_write(&current->mm->mmap_sem);
71308 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71309 static int do_mlockall(int flags)
71310 {
71311 struct vm_area_struct * vma, * prev = NULL;
71312 - unsigned int def_flags = 0;
71313
71314 if (flags & MCL_FUTURE)
71315 - def_flags = VM_LOCKED;
71316 - current->mm->def_flags = def_flags;
71317 + current->mm->def_flags |= VM_LOCKED;
71318 + else
71319 + current->mm->def_flags &= ~VM_LOCKED;
71320 if (flags == MCL_FUTURE)
71321 goto out;
71322
71323 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71324 vm_flags_t newflags;
71325
71326 +#ifdef CONFIG_PAX_SEGMEXEC
71327 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71328 + break;
71329 +#endif
71330 +
71331 + BUG_ON(vma->vm_end > TASK_SIZE);
71332 newflags = vma->vm_flags | VM_LOCKED;
71333 if (!(flags & MCL_CURRENT))
71334 newflags &= ~VM_LOCKED;
71335 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71336 lock_limit >>= PAGE_SHIFT;
71337
71338 ret = -ENOMEM;
71339 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71340 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71341 capable(CAP_IPC_LOCK))
71342 ret = do_mlockall(flags);
71343 diff --git a/mm/mmap.c b/mm/mmap.c
71344 index da15a79..314aef3 100644
71345 --- a/mm/mmap.c
71346 +++ b/mm/mmap.c
71347 @@ -46,6 +46,16 @@
71348 #define arch_rebalance_pgtables(addr, len) (addr)
71349 #endif
71350
71351 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71352 +{
71353 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71354 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71355 + up_read(&mm->mmap_sem);
71356 + BUG();
71357 + }
71358 +#endif
71359 +}
71360 +
71361 static void unmap_region(struct mm_struct *mm,
71362 struct vm_area_struct *vma, struct vm_area_struct *prev,
71363 unsigned long start, unsigned long end);
71364 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71365 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71366 *
71367 */
71368 -pgprot_t protection_map[16] = {
71369 +pgprot_t protection_map[16] __read_only = {
71370 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71371 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71372 };
71373
71374 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71375 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71376 {
71377 - return __pgprot(pgprot_val(protection_map[vm_flags &
71378 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71379 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71380 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71381 +
71382 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71383 + if (!(__supported_pte_mask & _PAGE_NX) &&
71384 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71385 + (vm_flags & (VM_READ | VM_WRITE)))
71386 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71387 +#endif
71388 +
71389 + return prot;
71390 }
71391 EXPORT_SYMBOL(vm_get_page_prot);
71392
71393 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71394 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71395 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71396 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71397 /*
71398 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71399 * other variables. It can be updated by several CPUs frequently.
71400 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71401 struct vm_area_struct *next = vma->vm_next;
71402
71403 might_sleep();
71404 + BUG_ON(vma->vm_mirror);
71405 if (vma->vm_ops && vma->vm_ops->close)
71406 vma->vm_ops->close(vma);
71407 if (vma->vm_file) {
71408 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71409 * not page aligned -Ram Gupta
71410 */
71411 rlim = rlimit(RLIMIT_DATA);
71412 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71413 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71414 (mm->end_data - mm->start_data) > rlim)
71415 goto out;
71416 @@ -689,6 +711,12 @@ static int
71417 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71418 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71419 {
71420 +
71421 +#ifdef CONFIG_PAX_SEGMEXEC
71422 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71423 + return 0;
71424 +#endif
71425 +
71426 if (is_mergeable_vma(vma, file, vm_flags) &&
71427 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71428 if (vma->vm_pgoff == vm_pgoff)
71429 @@ -708,6 +736,12 @@ static int
71430 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71431 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71432 {
71433 +
71434 +#ifdef CONFIG_PAX_SEGMEXEC
71435 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71436 + return 0;
71437 +#endif
71438 +
71439 if (is_mergeable_vma(vma, file, vm_flags) &&
71440 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71441 pgoff_t vm_pglen;
71442 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71443 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71444 struct vm_area_struct *prev, unsigned long addr,
71445 unsigned long end, unsigned long vm_flags,
71446 - struct anon_vma *anon_vma, struct file *file,
71447 + struct anon_vma *anon_vma, struct file *file,
71448 pgoff_t pgoff, struct mempolicy *policy)
71449 {
71450 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71451 struct vm_area_struct *area, *next;
71452 int err;
71453
71454 +#ifdef CONFIG_PAX_SEGMEXEC
71455 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71456 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71457 +
71458 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71459 +#endif
71460 +
71461 /*
71462 * We later require that vma->vm_flags == vm_flags,
71463 * so this tests vma->vm_flags & VM_SPECIAL, too.
71464 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71465 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71466 next = next->vm_next;
71467
71468 +#ifdef CONFIG_PAX_SEGMEXEC
71469 + if (prev)
71470 + prev_m = pax_find_mirror_vma(prev);
71471 + if (area)
71472 + area_m = pax_find_mirror_vma(area);
71473 + if (next)
71474 + next_m = pax_find_mirror_vma(next);
71475 +#endif
71476 +
71477 /*
71478 * Can it merge with the predecessor?
71479 */
71480 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71481 /* cases 1, 6 */
71482 err = vma_adjust(prev, prev->vm_start,
71483 next->vm_end, prev->vm_pgoff, NULL);
71484 - } else /* cases 2, 5, 7 */
71485 +
71486 +#ifdef CONFIG_PAX_SEGMEXEC
71487 + if (!err && prev_m)
71488 + err = vma_adjust(prev_m, prev_m->vm_start,
71489 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71490 +#endif
71491 +
71492 + } else { /* cases 2, 5, 7 */
71493 err = vma_adjust(prev, prev->vm_start,
71494 end, prev->vm_pgoff, NULL);
71495 +
71496 +#ifdef CONFIG_PAX_SEGMEXEC
71497 + if (!err && prev_m)
71498 + err = vma_adjust(prev_m, prev_m->vm_start,
71499 + end_m, prev_m->vm_pgoff, NULL);
71500 +#endif
71501 +
71502 + }
71503 if (err)
71504 return NULL;
71505 khugepaged_enter_vma_merge(prev);
71506 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71507 mpol_equal(policy, vma_policy(next)) &&
71508 can_vma_merge_before(next, vm_flags,
71509 anon_vma, file, pgoff+pglen)) {
71510 - if (prev && addr < prev->vm_end) /* case 4 */
71511 + if (prev && addr < prev->vm_end) { /* case 4 */
71512 err = vma_adjust(prev, prev->vm_start,
71513 addr, prev->vm_pgoff, NULL);
71514 - else /* cases 3, 8 */
71515 +
71516 +#ifdef CONFIG_PAX_SEGMEXEC
71517 + if (!err && prev_m)
71518 + err = vma_adjust(prev_m, prev_m->vm_start,
71519 + addr_m, prev_m->vm_pgoff, NULL);
71520 +#endif
71521 +
71522 + } else { /* cases 3, 8 */
71523 err = vma_adjust(area, addr, next->vm_end,
71524 next->vm_pgoff - pglen, NULL);
71525 +
71526 +#ifdef CONFIG_PAX_SEGMEXEC
71527 + if (!err && area_m)
71528 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71529 + next_m->vm_pgoff - pglen, NULL);
71530 +#endif
71531 +
71532 + }
71533 if (err)
71534 return NULL;
71535 khugepaged_enter_vma_merge(area);
71536 @@ -921,14 +1001,11 @@ none:
71537 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71538 struct file *file, long pages)
71539 {
71540 - const unsigned long stack_flags
71541 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71542 -
71543 if (file) {
71544 mm->shared_vm += pages;
71545 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71546 mm->exec_vm += pages;
71547 - } else if (flags & stack_flags)
71548 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71549 mm->stack_vm += pages;
71550 if (flags & (VM_RESERVED|VM_IO))
71551 mm->reserved_vm += pages;
71552 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71553 * (the exception is when the underlying filesystem is noexec
71554 * mounted, in which case we dont add PROT_EXEC.)
71555 */
71556 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71557 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71558 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71559 prot |= PROT_EXEC;
71560
71561 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71562 /* Obtain the address to map to. we verify (or select) it and ensure
71563 * that it represents a valid section of the address space.
71564 */
71565 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71566 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71567 if (addr & ~PAGE_MASK)
71568 return addr;
71569
71570 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71571 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71572 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71573
71574 +#ifdef CONFIG_PAX_MPROTECT
71575 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71576 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71577 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71578 + gr_log_rwxmmap(file);
71579 +
71580 +#ifdef CONFIG_PAX_EMUPLT
71581 + vm_flags &= ~VM_EXEC;
71582 +#else
71583 + return -EPERM;
71584 +#endif
71585 +
71586 + }
71587 +
71588 + if (!(vm_flags & VM_EXEC))
71589 + vm_flags &= ~VM_MAYEXEC;
71590 +#else
71591 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71592 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71593 +#endif
71594 + else
71595 + vm_flags &= ~VM_MAYWRITE;
71596 + }
71597 +#endif
71598 +
71599 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71600 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71601 + vm_flags &= ~VM_PAGEEXEC;
71602 +#endif
71603 +
71604 if (flags & MAP_LOCKED)
71605 if (!can_do_mlock())
71606 return -EPERM;
71607 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71608 locked += mm->locked_vm;
71609 lock_limit = rlimit(RLIMIT_MEMLOCK);
71610 lock_limit >>= PAGE_SHIFT;
71611 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71612 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71613 return -EAGAIN;
71614 }
71615 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71616 if (error)
71617 return error;
71618
71619 + if (!gr_acl_handle_mmap(file, prot))
71620 + return -EACCES;
71621 +
71622 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71623 }
71624 EXPORT_SYMBOL(do_mmap_pgoff);
71625 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71626 vm_flags_t vm_flags = vma->vm_flags;
71627
71628 /* If it was private or non-writable, the write bit is already clear */
71629 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71630 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71631 return 0;
71632
71633 /* The backer wishes to know when pages are first written to? */
71634 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71635 unsigned long charged = 0;
71636 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71637
71638 +#ifdef CONFIG_PAX_SEGMEXEC
71639 + struct vm_area_struct *vma_m = NULL;
71640 +#endif
71641 +
71642 + /*
71643 + * mm->mmap_sem is required to protect against another thread
71644 + * changing the mappings in case we sleep.
71645 + */
71646 + verify_mm_writelocked(mm);
71647 +
71648 /* Clear old maps */
71649 error = -ENOMEM;
71650 -munmap_back:
71651 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71652 if (vma && vma->vm_start < addr + len) {
71653 if (do_munmap(mm, addr, len))
71654 return -ENOMEM;
71655 - goto munmap_back;
71656 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71657 + BUG_ON(vma && vma->vm_start < addr + len);
71658 }
71659
71660 /* Check against address space limit. */
71661 @@ -1258,6 +1379,16 @@ munmap_back:
71662 goto unacct_error;
71663 }
71664
71665 +#ifdef CONFIG_PAX_SEGMEXEC
71666 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71667 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71668 + if (!vma_m) {
71669 + error = -ENOMEM;
71670 + goto free_vma;
71671 + }
71672 + }
71673 +#endif
71674 +
71675 vma->vm_mm = mm;
71676 vma->vm_start = addr;
71677 vma->vm_end = addr + len;
71678 @@ -1282,6 +1413,19 @@ munmap_back:
71679 error = file->f_op->mmap(file, vma);
71680 if (error)
71681 goto unmap_and_free_vma;
71682 +
71683 +#ifdef CONFIG_PAX_SEGMEXEC
71684 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71685 + added_exe_file_vma(mm);
71686 +#endif
71687 +
71688 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71689 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71690 + vma->vm_flags |= VM_PAGEEXEC;
71691 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71692 + }
71693 +#endif
71694 +
71695 if (vm_flags & VM_EXECUTABLE)
71696 added_exe_file_vma(mm);
71697
71698 @@ -1319,6 +1463,11 @@ munmap_back:
71699 vma_link(mm, vma, prev, rb_link, rb_parent);
71700 file = vma->vm_file;
71701
71702 +#ifdef CONFIG_PAX_SEGMEXEC
71703 + if (vma_m)
71704 + BUG_ON(pax_mirror_vma(vma_m, vma));
71705 +#endif
71706 +
71707 /* Once vma denies write, undo our temporary denial count */
71708 if (correct_wcount)
71709 atomic_inc(&inode->i_writecount);
71710 @@ -1327,6 +1476,7 @@ out:
71711
71712 mm->total_vm += len >> PAGE_SHIFT;
71713 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71714 + track_exec_limit(mm, addr, addr + len, vm_flags);
71715 if (vm_flags & VM_LOCKED) {
71716 if (!mlock_vma_pages_range(vma, addr, addr + len))
71717 mm->locked_vm += (len >> PAGE_SHIFT);
71718 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71719 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71720 charged = 0;
71721 free_vma:
71722 +
71723 +#ifdef CONFIG_PAX_SEGMEXEC
71724 + if (vma_m)
71725 + kmem_cache_free(vm_area_cachep, vma_m);
71726 +#endif
71727 +
71728 kmem_cache_free(vm_area_cachep, vma);
71729 unacct_error:
71730 if (charged)
71731 @@ -1351,6 +1507,44 @@ unacct_error:
71732 return error;
71733 }
71734
71735 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71736 +{
71737 + if (!vma) {
71738 +#ifdef CONFIG_STACK_GROWSUP
71739 + if (addr > sysctl_heap_stack_gap)
71740 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71741 + else
71742 + vma = find_vma(current->mm, 0);
71743 + if (vma && (vma->vm_flags & VM_GROWSUP))
71744 + return false;
71745 +#endif
71746 + return true;
71747 + }
71748 +
71749 + if (addr + len > vma->vm_start)
71750 + return false;
71751 +
71752 + if (vma->vm_flags & VM_GROWSDOWN)
71753 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71754 +#ifdef CONFIG_STACK_GROWSUP
71755 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71756 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71757 +#endif
71758 +
71759 + return true;
71760 +}
71761 +
71762 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71763 +{
71764 + if (vma->vm_start < len)
71765 + return -ENOMEM;
71766 + if (!(vma->vm_flags & VM_GROWSDOWN))
71767 + return vma->vm_start - len;
71768 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71769 + return vma->vm_start - len - sysctl_heap_stack_gap;
71770 + return -ENOMEM;
71771 +}
71772 +
71773 /* Get an address range which is currently unmapped.
71774 * For shmat() with addr=0.
71775 *
71776 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71777 if (flags & MAP_FIXED)
71778 return addr;
71779
71780 +#ifdef CONFIG_PAX_RANDMMAP
71781 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71782 +#endif
71783 +
71784 if (addr) {
71785 addr = PAGE_ALIGN(addr);
71786 - vma = find_vma(mm, addr);
71787 - if (TASK_SIZE - len >= addr &&
71788 - (!vma || addr + len <= vma->vm_start))
71789 - return addr;
71790 + if (TASK_SIZE - len >= addr) {
71791 + vma = find_vma(mm, addr);
71792 + if (check_heap_stack_gap(vma, addr, len))
71793 + return addr;
71794 + }
71795 }
71796 if (len > mm->cached_hole_size) {
71797 - start_addr = addr = mm->free_area_cache;
71798 + start_addr = addr = mm->free_area_cache;
71799 } else {
71800 - start_addr = addr = TASK_UNMAPPED_BASE;
71801 - mm->cached_hole_size = 0;
71802 + start_addr = addr = mm->mmap_base;
71803 + mm->cached_hole_size = 0;
71804 }
71805
71806 full_search:
71807 @@ -1399,34 +1598,40 @@ full_search:
71808 * Start a new search - just in case we missed
71809 * some holes.
71810 */
71811 - if (start_addr != TASK_UNMAPPED_BASE) {
71812 - addr = TASK_UNMAPPED_BASE;
71813 - start_addr = addr;
71814 + if (start_addr != mm->mmap_base) {
71815 + start_addr = addr = mm->mmap_base;
71816 mm->cached_hole_size = 0;
71817 goto full_search;
71818 }
71819 return -ENOMEM;
71820 }
71821 - if (!vma || addr + len <= vma->vm_start) {
71822 - /*
71823 - * Remember the place where we stopped the search:
71824 - */
71825 - mm->free_area_cache = addr + len;
71826 - return addr;
71827 - }
71828 + if (check_heap_stack_gap(vma, addr, len))
71829 + break;
71830 if (addr + mm->cached_hole_size < vma->vm_start)
71831 mm->cached_hole_size = vma->vm_start - addr;
71832 addr = vma->vm_end;
71833 }
71834 +
71835 + /*
71836 + * Remember the place where we stopped the search:
71837 + */
71838 + mm->free_area_cache = addr + len;
71839 + return addr;
71840 }
71841 #endif
71842
71843 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71844 {
71845 +
71846 +#ifdef CONFIG_PAX_SEGMEXEC
71847 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71848 + return;
71849 +#endif
71850 +
71851 /*
71852 * Is this a new hole at the lowest possible address?
71853 */
71854 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71855 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71856 mm->free_area_cache = addr;
71857 mm->cached_hole_size = ~0UL;
71858 }
71859 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71860 {
71861 struct vm_area_struct *vma;
71862 struct mm_struct *mm = current->mm;
71863 - unsigned long addr = addr0;
71864 + unsigned long base = mm->mmap_base, addr = addr0;
71865
71866 /* requested length too big for entire address space */
71867 if (len > TASK_SIZE)
71868 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71869 if (flags & MAP_FIXED)
71870 return addr;
71871
71872 +#ifdef CONFIG_PAX_RANDMMAP
71873 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71874 +#endif
71875 +
71876 /* requesting a specific address */
71877 if (addr) {
71878 addr = PAGE_ALIGN(addr);
71879 - vma = find_vma(mm, addr);
71880 - if (TASK_SIZE - len >= addr &&
71881 - (!vma || addr + len <= vma->vm_start))
71882 - return addr;
71883 + if (TASK_SIZE - len >= addr) {
71884 + vma = find_vma(mm, addr);
71885 + if (check_heap_stack_gap(vma, addr, len))
71886 + return addr;
71887 + }
71888 }
71889
71890 /* check if free_area_cache is useful for us */
71891 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71892 /* make sure it can fit in the remaining address space */
71893 if (addr > len) {
71894 vma = find_vma(mm, addr-len);
71895 - if (!vma || addr <= vma->vm_start)
71896 + if (check_heap_stack_gap(vma, addr - len, len))
71897 /* remember the address as a hint for next time */
71898 return (mm->free_area_cache = addr-len);
71899 }
71900 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71901 * return with success:
71902 */
71903 vma = find_vma(mm, addr);
71904 - if (!vma || addr+len <= vma->vm_start)
71905 + if (check_heap_stack_gap(vma, addr, len))
71906 /* remember the address as a hint for next time */
71907 return (mm->free_area_cache = addr);
71908
71909 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71910 mm->cached_hole_size = vma->vm_start - addr;
71911
71912 /* try just below the current vma->vm_start */
71913 - addr = vma->vm_start-len;
71914 - } while (len < vma->vm_start);
71915 + addr = skip_heap_stack_gap(vma, len);
71916 + } while (!IS_ERR_VALUE(addr));
71917
71918 bottomup:
71919 /*
71920 @@ -1510,13 +1720,21 @@ bottomup:
71921 * can happen with large stack limits and large mmap()
71922 * allocations.
71923 */
71924 + mm->mmap_base = TASK_UNMAPPED_BASE;
71925 +
71926 +#ifdef CONFIG_PAX_RANDMMAP
71927 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71928 + mm->mmap_base += mm->delta_mmap;
71929 +#endif
71930 +
71931 + mm->free_area_cache = mm->mmap_base;
71932 mm->cached_hole_size = ~0UL;
71933 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71934 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71935 /*
71936 * Restore the topdown base:
71937 */
71938 - mm->free_area_cache = mm->mmap_base;
71939 + mm->mmap_base = base;
71940 + mm->free_area_cache = base;
71941 mm->cached_hole_size = ~0UL;
71942
71943 return addr;
71944 @@ -1525,6 +1743,12 @@ bottomup:
71945
71946 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71947 {
71948 +
71949 +#ifdef CONFIG_PAX_SEGMEXEC
71950 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71951 + return;
71952 +#endif
71953 +
71954 /*
71955 * Is this a new hole at the highest possible address?
71956 */
71957 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71958 mm->free_area_cache = addr;
71959
71960 /* dont allow allocations above current base */
71961 - if (mm->free_area_cache > mm->mmap_base)
71962 + if (mm->free_area_cache > mm->mmap_base) {
71963 mm->free_area_cache = mm->mmap_base;
71964 + mm->cached_hole_size = ~0UL;
71965 + }
71966 }
71967
71968 unsigned long
71969 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71970 return vma;
71971 }
71972
71973 +#ifdef CONFIG_PAX_SEGMEXEC
71974 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71975 +{
71976 + struct vm_area_struct *vma_m;
71977 +
71978 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71979 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71980 + BUG_ON(vma->vm_mirror);
71981 + return NULL;
71982 + }
71983 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71984 + vma_m = vma->vm_mirror;
71985 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71986 + BUG_ON(vma->vm_file != vma_m->vm_file);
71987 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71988 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71989 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71990 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71991 + return vma_m;
71992 +}
71993 +#endif
71994 +
71995 /*
71996 * Verify that the stack growth is acceptable and
71997 * update accounting. This is shared with both the
71998 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71999 return -ENOMEM;
72000
72001 /* Stack limit test */
72002 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72003 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72004 return -ENOMEM;
72005
72006 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72007 locked = mm->locked_vm + grow;
72008 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72009 limit >>= PAGE_SHIFT;
72010 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72011 if (locked > limit && !capable(CAP_IPC_LOCK))
72012 return -ENOMEM;
72013 }
72014 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72015 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72016 * vma is the last one with address > vma->vm_end. Have to extend vma.
72017 */
72018 +#ifndef CONFIG_IA64
72019 +static
72020 +#endif
72021 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72022 {
72023 int error;
72024 + bool locknext;
72025
72026 if (!(vma->vm_flags & VM_GROWSUP))
72027 return -EFAULT;
72028
72029 + /* Also guard against wrapping around to address 0. */
72030 + if (address < PAGE_ALIGN(address+1))
72031 + address = PAGE_ALIGN(address+1);
72032 + else
72033 + return -ENOMEM;
72034 +
72035 /*
72036 * We must make sure the anon_vma is allocated
72037 * so that the anon_vma locking is not a noop.
72038 */
72039 if (unlikely(anon_vma_prepare(vma)))
72040 return -ENOMEM;
72041 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72042 + if (locknext && anon_vma_prepare(vma->vm_next))
72043 + return -ENOMEM;
72044 vma_lock_anon_vma(vma);
72045 + if (locknext)
72046 + vma_lock_anon_vma(vma->vm_next);
72047
72048 /*
72049 * vma->vm_start/vm_end cannot change under us because the caller
72050 * is required to hold the mmap_sem in read mode. We need the
72051 - * anon_vma lock to serialize against concurrent expand_stacks.
72052 - * Also guard against wrapping around to address 0.
72053 + * anon_vma locks to serialize against concurrent expand_stacks
72054 + * and expand_upwards.
72055 */
72056 - if (address < PAGE_ALIGN(address+4))
72057 - address = PAGE_ALIGN(address+4);
72058 - else {
72059 - vma_unlock_anon_vma(vma);
72060 - return -ENOMEM;
72061 - }
72062 error = 0;
72063
72064 /* Somebody else might have raced and expanded it already */
72065 - if (address > vma->vm_end) {
72066 + 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)
72067 + error = -ENOMEM;
72068 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72069 unsigned long size, grow;
72070
72071 size = address - vma->vm_start;
72072 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72073 }
72074 }
72075 }
72076 + if (locknext)
72077 + vma_unlock_anon_vma(vma->vm_next);
72078 vma_unlock_anon_vma(vma);
72079 khugepaged_enter_vma_merge(vma);
72080 return error;
72081 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72082 unsigned long address)
72083 {
72084 int error;
72085 + bool lockprev = false;
72086 + struct vm_area_struct *prev;
72087
72088 /*
72089 * We must make sure the anon_vma is allocated
72090 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72091 if (error)
72092 return error;
72093
72094 + prev = vma->vm_prev;
72095 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72096 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72097 +#endif
72098 + if (lockprev && anon_vma_prepare(prev))
72099 + return -ENOMEM;
72100 + if (lockprev)
72101 + vma_lock_anon_vma(prev);
72102 +
72103 vma_lock_anon_vma(vma);
72104
72105 /*
72106 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72107 */
72108
72109 /* Somebody else might have raced and expanded it already */
72110 - if (address < vma->vm_start) {
72111 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72112 + error = -ENOMEM;
72113 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72114 unsigned long size, grow;
72115
72116 +#ifdef CONFIG_PAX_SEGMEXEC
72117 + struct vm_area_struct *vma_m;
72118 +
72119 + vma_m = pax_find_mirror_vma(vma);
72120 +#endif
72121 +
72122 size = vma->vm_end - address;
72123 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72124
72125 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72126 if (!error) {
72127 vma->vm_start = address;
72128 vma->vm_pgoff -= grow;
72129 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72130 +
72131 +#ifdef CONFIG_PAX_SEGMEXEC
72132 + if (vma_m) {
72133 + vma_m->vm_start -= grow << PAGE_SHIFT;
72134 + vma_m->vm_pgoff -= grow;
72135 + }
72136 +#endif
72137 +
72138 perf_event_mmap(vma);
72139 }
72140 }
72141 }
72142 vma_unlock_anon_vma(vma);
72143 + if (lockprev)
72144 + vma_unlock_anon_vma(prev);
72145 khugepaged_enter_vma_merge(vma);
72146 return error;
72147 }
72148 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72149 do {
72150 long nrpages = vma_pages(vma);
72151
72152 +#ifdef CONFIG_PAX_SEGMEXEC
72153 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72154 + vma = remove_vma(vma);
72155 + continue;
72156 + }
72157 +#endif
72158 +
72159 mm->total_vm -= nrpages;
72160 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72161 vma = remove_vma(vma);
72162 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72163 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72164 vma->vm_prev = NULL;
72165 do {
72166 +
72167 +#ifdef CONFIG_PAX_SEGMEXEC
72168 + if (vma->vm_mirror) {
72169 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72170 + vma->vm_mirror->vm_mirror = NULL;
72171 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72172 + vma->vm_mirror = NULL;
72173 + }
72174 +#endif
72175 +
72176 rb_erase(&vma->vm_rb, &mm->mm_rb);
72177 mm->map_count--;
72178 tail_vma = vma;
72179 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72180 struct vm_area_struct *new;
72181 int err = -ENOMEM;
72182
72183 +#ifdef CONFIG_PAX_SEGMEXEC
72184 + struct vm_area_struct *vma_m, *new_m = NULL;
72185 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72186 +#endif
72187 +
72188 if (is_vm_hugetlb_page(vma) && (addr &
72189 ~(huge_page_mask(hstate_vma(vma)))))
72190 return -EINVAL;
72191
72192 +#ifdef CONFIG_PAX_SEGMEXEC
72193 + vma_m = pax_find_mirror_vma(vma);
72194 +#endif
72195 +
72196 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72197 if (!new)
72198 goto out_err;
72199
72200 +#ifdef CONFIG_PAX_SEGMEXEC
72201 + if (vma_m) {
72202 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72203 + if (!new_m) {
72204 + kmem_cache_free(vm_area_cachep, new);
72205 + goto out_err;
72206 + }
72207 + }
72208 +#endif
72209 +
72210 /* most fields are the same, copy all, and then fixup */
72211 *new = *vma;
72212
72213 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72214 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72215 }
72216
72217 +#ifdef CONFIG_PAX_SEGMEXEC
72218 + if (vma_m) {
72219 + *new_m = *vma_m;
72220 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72221 + new_m->vm_mirror = new;
72222 + new->vm_mirror = new_m;
72223 +
72224 + if (new_below)
72225 + new_m->vm_end = addr_m;
72226 + else {
72227 + new_m->vm_start = addr_m;
72228 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72229 + }
72230 + }
72231 +#endif
72232 +
72233 pol = mpol_dup(vma_policy(vma));
72234 if (IS_ERR(pol)) {
72235 err = PTR_ERR(pol);
72236 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72237 else
72238 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72239
72240 +#ifdef CONFIG_PAX_SEGMEXEC
72241 + if (!err && vma_m) {
72242 + if (anon_vma_clone(new_m, vma_m))
72243 + goto out_free_mpol;
72244 +
72245 + mpol_get(pol);
72246 + vma_set_policy(new_m, pol);
72247 +
72248 + if (new_m->vm_file) {
72249 + get_file(new_m->vm_file);
72250 + if (vma_m->vm_flags & VM_EXECUTABLE)
72251 + added_exe_file_vma(mm);
72252 + }
72253 +
72254 + if (new_m->vm_ops && new_m->vm_ops->open)
72255 + new_m->vm_ops->open(new_m);
72256 +
72257 + if (new_below)
72258 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72259 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72260 + else
72261 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72262 +
72263 + if (err) {
72264 + if (new_m->vm_ops && new_m->vm_ops->close)
72265 + new_m->vm_ops->close(new_m);
72266 + if (new_m->vm_file) {
72267 + if (vma_m->vm_flags & VM_EXECUTABLE)
72268 + removed_exe_file_vma(mm);
72269 + fput(new_m->vm_file);
72270 + }
72271 + mpol_put(pol);
72272 + }
72273 + }
72274 +#endif
72275 +
72276 /* Success. */
72277 if (!err)
72278 return 0;
72279 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72280 removed_exe_file_vma(mm);
72281 fput(new->vm_file);
72282 }
72283 - unlink_anon_vmas(new);
72284 out_free_mpol:
72285 mpol_put(pol);
72286 out_free_vma:
72287 +
72288 +#ifdef CONFIG_PAX_SEGMEXEC
72289 + if (new_m) {
72290 + unlink_anon_vmas(new_m);
72291 + kmem_cache_free(vm_area_cachep, new_m);
72292 + }
72293 +#endif
72294 +
72295 + unlink_anon_vmas(new);
72296 kmem_cache_free(vm_area_cachep, new);
72297 out_err:
72298 return err;
72299 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72300 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72301 unsigned long addr, int new_below)
72302 {
72303 +
72304 +#ifdef CONFIG_PAX_SEGMEXEC
72305 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72306 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72307 + if (mm->map_count >= sysctl_max_map_count-1)
72308 + return -ENOMEM;
72309 + } else
72310 +#endif
72311 +
72312 if (mm->map_count >= sysctl_max_map_count)
72313 return -ENOMEM;
72314
72315 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72316 * work. This now handles partial unmappings.
72317 * Jeremy Fitzhardinge <jeremy@goop.org>
72318 */
72319 +#ifdef CONFIG_PAX_SEGMEXEC
72320 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72321 {
72322 + int ret = __do_munmap(mm, start, len);
72323 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72324 + return ret;
72325 +
72326 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72327 +}
72328 +
72329 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72330 +#else
72331 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72332 +#endif
72333 +{
72334 unsigned long end;
72335 struct vm_area_struct *vma, *prev, *last;
72336
72337 + /*
72338 + * mm->mmap_sem is required to protect against another thread
72339 + * changing the mappings in case we sleep.
72340 + */
72341 + verify_mm_writelocked(mm);
72342 +
72343 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72344 return -EINVAL;
72345
72346 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72347 /* Fix up all other VM information */
72348 remove_vma_list(mm, vma);
72349
72350 + track_exec_limit(mm, start, end, 0UL);
72351 +
72352 return 0;
72353 }
72354
72355 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72356
72357 profile_munmap(addr);
72358
72359 +#ifdef CONFIG_PAX_SEGMEXEC
72360 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72361 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72362 + return -EINVAL;
72363 +#endif
72364 +
72365 down_write(&mm->mmap_sem);
72366 ret = do_munmap(mm, addr, len);
72367 up_write(&mm->mmap_sem);
72368 return ret;
72369 }
72370
72371 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72372 -{
72373 -#ifdef CONFIG_DEBUG_VM
72374 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72375 - WARN_ON(1);
72376 - up_read(&mm->mmap_sem);
72377 - }
72378 -#endif
72379 -}
72380 -
72381 /*
72382 * this is really a simplified "do_mmap". it only handles
72383 * anonymous maps. eventually we may be able to do some
72384 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72385 struct rb_node ** rb_link, * rb_parent;
72386 pgoff_t pgoff = addr >> PAGE_SHIFT;
72387 int error;
72388 + unsigned long charged;
72389
72390 len = PAGE_ALIGN(len);
72391 if (!len)
72392 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72393
72394 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72395
72396 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72397 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72398 + flags &= ~VM_EXEC;
72399 +
72400 +#ifdef CONFIG_PAX_MPROTECT
72401 + if (mm->pax_flags & MF_PAX_MPROTECT)
72402 + flags &= ~VM_MAYEXEC;
72403 +#endif
72404 +
72405 + }
72406 +#endif
72407 +
72408 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72409 if (error & ~PAGE_MASK)
72410 return error;
72411
72412 + charged = len >> PAGE_SHIFT;
72413 +
72414 /*
72415 * mlock MCL_FUTURE?
72416 */
72417 if (mm->def_flags & VM_LOCKED) {
72418 unsigned long locked, lock_limit;
72419 - locked = len >> PAGE_SHIFT;
72420 + locked = charged;
72421 locked += mm->locked_vm;
72422 lock_limit = rlimit(RLIMIT_MEMLOCK);
72423 lock_limit >>= PAGE_SHIFT;
72424 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72425 /*
72426 * Clear old maps. this also does some error checking for us
72427 */
72428 - munmap_back:
72429 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72430 if (vma && vma->vm_start < addr + len) {
72431 if (do_munmap(mm, addr, len))
72432 return -ENOMEM;
72433 - goto munmap_back;
72434 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72435 + BUG_ON(vma && vma->vm_start < addr + len);
72436 }
72437
72438 /* Check against address space limits *after* clearing old maps... */
72439 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72440 + if (!may_expand_vm(mm, charged))
72441 return -ENOMEM;
72442
72443 if (mm->map_count > sysctl_max_map_count)
72444 return -ENOMEM;
72445
72446 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72447 + if (security_vm_enough_memory(charged))
72448 return -ENOMEM;
72449
72450 /* Can we just expand an old private anonymous mapping? */
72451 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72452 */
72453 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72454 if (!vma) {
72455 - vm_unacct_memory(len >> PAGE_SHIFT);
72456 + vm_unacct_memory(charged);
72457 return -ENOMEM;
72458 }
72459
72460 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72461 vma_link(mm, vma, prev, rb_link, rb_parent);
72462 out:
72463 perf_event_mmap(vma);
72464 - mm->total_vm += len >> PAGE_SHIFT;
72465 + mm->total_vm += charged;
72466 if (flags & VM_LOCKED) {
72467 if (!mlock_vma_pages_range(vma, addr, addr + len))
72468 - mm->locked_vm += (len >> PAGE_SHIFT);
72469 + mm->locked_vm += charged;
72470 }
72471 + track_exec_limit(mm, addr, addr + len, flags);
72472 return addr;
72473 }
72474
72475 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72476 * Walk the list again, actually closing and freeing it,
72477 * with preemption enabled, without holding any MM locks.
72478 */
72479 - while (vma)
72480 + while (vma) {
72481 + vma->vm_mirror = NULL;
72482 vma = remove_vma(vma);
72483 + }
72484
72485 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72486 }
72487 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72488 struct vm_area_struct * __vma, * prev;
72489 struct rb_node ** rb_link, * rb_parent;
72490
72491 +#ifdef CONFIG_PAX_SEGMEXEC
72492 + struct vm_area_struct *vma_m = NULL;
72493 +#endif
72494 +
72495 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72496 + return -EPERM;
72497 +
72498 /*
72499 * The vm_pgoff of a purely anonymous vma should be irrelevant
72500 * until its first write fault, when page's anon_vma and index
72501 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72502 if ((vma->vm_flags & VM_ACCOUNT) &&
72503 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72504 return -ENOMEM;
72505 +
72506 +#ifdef CONFIG_PAX_SEGMEXEC
72507 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72508 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72509 + if (!vma_m)
72510 + return -ENOMEM;
72511 + }
72512 +#endif
72513 +
72514 vma_link(mm, vma, prev, rb_link, rb_parent);
72515 +
72516 +#ifdef CONFIG_PAX_SEGMEXEC
72517 + if (vma_m)
72518 + BUG_ON(pax_mirror_vma(vma_m, vma));
72519 +#endif
72520 +
72521 return 0;
72522 }
72523
72524 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72525 struct mempolicy *pol;
72526 bool faulted_in_anon_vma = true;
72527
72528 + BUG_ON(vma->vm_mirror);
72529 +
72530 /*
72531 * If anonymous vma has not yet been faulted, update new pgoff
72532 * to match new location, to increase its chance of merging.
72533 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72534 return NULL;
72535 }
72536
72537 +#ifdef CONFIG_PAX_SEGMEXEC
72538 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72539 +{
72540 + struct vm_area_struct *prev_m;
72541 + struct rb_node **rb_link_m, *rb_parent_m;
72542 + struct mempolicy *pol_m;
72543 +
72544 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72545 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72546 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72547 + *vma_m = *vma;
72548 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72549 + if (anon_vma_clone(vma_m, vma))
72550 + return -ENOMEM;
72551 + pol_m = vma_policy(vma_m);
72552 + mpol_get(pol_m);
72553 + vma_set_policy(vma_m, pol_m);
72554 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72555 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72556 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72557 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72558 + if (vma_m->vm_file)
72559 + get_file(vma_m->vm_file);
72560 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72561 + vma_m->vm_ops->open(vma_m);
72562 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72563 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72564 + vma_m->vm_mirror = vma;
72565 + vma->vm_mirror = vma_m;
72566 + return 0;
72567 +}
72568 +#endif
72569 +
72570 /*
72571 * Return true if the calling process may expand its vm space by the passed
72572 * number of pages
72573 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72574
72575 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72576
72577 +#ifdef CONFIG_PAX_RANDMMAP
72578 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72579 + cur -= mm->brk_gap;
72580 +#endif
72581 +
72582 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72583 if (cur + npages > lim)
72584 return 0;
72585 return 1;
72586 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72587 vma->vm_start = addr;
72588 vma->vm_end = addr + len;
72589
72590 +#ifdef CONFIG_PAX_MPROTECT
72591 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72592 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72593 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72594 + return -EPERM;
72595 + if (!(vm_flags & VM_EXEC))
72596 + vm_flags &= ~VM_MAYEXEC;
72597 +#else
72598 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72599 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72600 +#endif
72601 + else
72602 + vm_flags &= ~VM_MAYWRITE;
72603 + }
72604 +#endif
72605 +
72606 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72607 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72608
72609 diff --git a/mm/mprotect.c b/mm/mprotect.c
72610 index f437d05..e3763f6 100644
72611 --- a/mm/mprotect.c
72612 +++ b/mm/mprotect.c
72613 @@ -23,10 +23,16 @@
72614 #include <linux/mmu_notifier.h>
72615 #include <linux/migrate.h>
72616 #include <linux/perf_event.h>
72617 +
72618 +#ifdef CONFIG_PAX_MPROTECT
72619 +#include <linux/elf.h>
72620 +#endif
72621 +
72622 #include <asm/uaccess.h>
72623 #include <asm/pgtable.h>
72624 #include <asm/cacheflush.h>
72625 #include <asm/tlbflush.h>
72626 +#include <asm/mmu_context.h>
72627
72628 #ifndef pgprot_modify
72629 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72630 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72631 flush_tlb_range(vma, start, end);
72632 }
72633
72634 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72635 +/* called while holding the mmap semaphor for writing except stack expansion */
72636 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72637 +{
72638 + unsigned long oldlimit, newlimit = 0UL;
72639 +
72640 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72641 + return;
72642 +
72643 + spin_lock(&mm->page_table_lock);
72644 + oldlimit = mm->context.user_cs_limit;
72645 + if ((prot & VM_EXEC) && oldlimit < end)
72646 + /* USER_CS limit moved up */
72647 + newlimit = end;
72648 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72649 + /* USER_CS limit moved down */
72650 + newlimit = start;
72651 +
72652 + if (newlimit) {
72653 + mm->context.user_cs_limit = newlimit;
72654 +
72655 +#ifdef CONFIG_SMP
72656 + wmb();
72657 + cpus_clear(mm->context.cpu_user_cs_mask);
72658 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72659 +#endif
72660 +
72661 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72662 + }
72663 + spin_unlock(&mm->page_table_lock);
72664 + if (newlimit == end) {
72665 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72666 +
72667 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72668 + if (is_vm_hugetlb_page(vma))
72669 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72670 + else
72671 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72672 + }
72673 +}
72674 +#endif
72675 +
72676 int
72677 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72678 unsigned long start, unsigned long end, unsigned long newflags)
72679 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72680 int error;
72681 int dirty_accountable = 0;
72682
72683 +#ifdef CONFIG_PAX_SEGMEXEC
72684 + struct vm_area_struct *vma_m = NULL;
72685 + unsigned long start_m, end_m;
72686 +
72687 + start_m = start + SEGMEXEC_TASK_SIZE;
72688 + end_m = end + SEGMEXEC_TASK_SIZE;
72689 +#endif
72690 +
72691 if (newflags == oldflags) {
72692 *pprev = vma;
72693 return 0;
72694 }
72695
72696 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72697 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72698 +
72699 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72700 + return -ENOMEM;
72701 +
72702 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72703 + return -ENOMEM;
72704 + }
72705 +
72706 /*
72707 * If we make a private mapping writable we increase our commit;
72708 * but (without finer accounting) cannot reduce our commit if we
72709 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72710 }
72711 }
72712
72713 +#ifdef CONFIG_PAX_SEGMEXEC
72714 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72715 + if (start != vma->vm_start) {
72716 + error = split_vma(mm, vma, start, 1);
72717 + if (error)
72718 + goto fail;
72719 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72720 + *pprev = (*pprev)->vm_next;
72721 + }
72722 +
72723 + if (end != vma->vm_end) {
72724 + error = split_vma(mm, vma, end, 0);
72725 + if (error)
72726 + goto fail;
72727 + }
72728 +
72729 + if (pax_find_mirror_vma(vma)) {
72730 + error = __do_munmap(mm, start_m, end_m - start_m);
72731 + if (error)
72732 + goto fail;
72733 + } else {
72734 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72735 + if (!vma_m) {
72736 + error = -ENOMEM;
72737 + goto fail;
72738 + }
72739 + vma->vm_flags = newflags;
72740 + error = pax_mirror_vma(vma_m, vma);
72741 + if (error) {
72742 + vma->vm_flags = oldflags;
72743 + goto fail;
72744 + }
72745 + }
72746 + }
72747 +#endif
72748 +
72749 /*
72750 * First try to merge with previous and/or next vma.
72751 */
72752 @@ -204,9 +306,21 @@ success:
72753 * vm_flags and vm_page_prot are protected by the mmap_sem
72754 * held in write mode.
72755 */
72756 +
72757 +#ifdef CONFIG_PAX_SEGMEXEC
72758 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72759 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72760 +#endif
72761 +
72762 vma->vm_flags = newflags;
72763 +
72764 +#ifdef CONFIG_PAX_MPROTECT
72765 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72766 + mm->binfmt->handle_mprotect(vma, newflags);
72767 +#endif
72768 +
72769 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72770 - vm_get_page_prot(newflags));
72771 + vm_get_page_prot(vma->vm_flags));
72772
72773 if (vma_wants_writenotify(vma)) {
72774 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72775 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72776 end = start + len;
72777 if (end <= start)
72778 return -ENOMEM;
72779 +
72780 +#ifdef CONFIG_PAX_SEGMEXEC
72781 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72782 + if (end > SEGMEXEC_TASK_SIZE)
72783 + return -EINVAL;
72784 + } else
72785 +#endif
72786 +
72787 + if (end > TASK_SIZE)
72788 + return -EINVAL;
72789 +
72790 if (!arch_validate_prot(prot))
72791 return -EINVAL;
72792
72793 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72794 /*
72795 * Does the application expect PROT_READ to imply PROT_EXEC:
72796 */
72797 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72798 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72799 prot |= PROT_EXEC;
72800
72801 vm_flags = calc_vm_prot_bits(prot);
72802 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72803 if (start > vma->vm_start)
72804 prev = vma;
72805
72806 +#ifdef CONFIG_PAX_MPROTECT
72807 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72808 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72809 +#endif
72810 +
72811 for (nstart = start ; ; ) {
72812 unsigned long newflags;
72813
72814 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72815
72816 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72817 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72818 + if (prot & (PROT_WRITE | PROT_EXEC))
72819 + gr_log_rwxmprotect(vma->vm_file);
72820 +
72821 + error = -EACCES;
72822 + goto out;
72823 + }
72824 +
72825 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72826 error = -EACCES;
72827 goto out;
72828 }
72829 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72830 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72831 if (error)
72832 goto out;
72833 +
72834 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72835 +
72836 nstart = tmp;
72837
72838 if (nstart < prev->vm_end)
72839 diff --git a/mm/mremap.c b/mm/mremap.c
72840 index 87bb839..c3bfadb 100644
72841 --- a/mm/mremap.c
72842 +++ b/mm/mremap.c
72843 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72844 continue;
72845 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72846 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72847 +
72848 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72849 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72850 + pte = pte_exprotect(pte);
72851 +#endif
72852 +
72853 set_pte_at(mm, new_addr, new_pte, pte);
72854 }
72855
72856 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72857 if (is_vm_hugetlb_page(vma))
72858 goto Einval;
72859
72860 +#ifdef CONFIG_PAX_SEGMEXEC
72861 + if (pax_find_mirror_vma(vma))
72862 + goto Einval;
72863 +#endif
72864 +
72865 /* We can't remap across vm area boundaries */
72866 if (old_len > vma->vm_end - addr)
72867 goto Efault;
72868 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72869 unsigned long ret = -EINVAL;
72870 unsigned long charged = 0;
72871 unsigned long map_flags;
72872 + unsigned long pax_task_size = TASK_SIZE;
72873
72874 if (new_addr & ~PAGE_MASK)
72875 goto out;
72876
72877 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72878 +#ifdef CONFIG_PAX_SEGMEXEC
72879 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72880 + pax_task_size = SEGMEXEC_TASK_SIZE;
72881 +#endif
72882 +
72883 + pax_task_size -= PAGE_SIZE;
72884 +
72885 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72886 goto out;
72887
72888 /* Check if the location we're moving into overlaps the
72889 * old location at all, and fail if it does.
72890 */
72891 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72892 - goto out;
72893 -
72894 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72895 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72896 goto out;
72897
72898 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72899 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72900 struct vm_area_struct *vma;
72901 unsigned long ret = -EINVAL;
72902 unsigned long charged = 0;
72903 + unsigned long pax_task_size = TASK_SIZE;
72904
72905 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72906 goto out;
72907 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72908 if (!new_len)
72909 goto out;
72910
72911 +#ifdef CONFIG_PAX_SEGMEXEC
72912 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72913 + pax_task_size = SEGMEXEC_TASK_SIZE;
72914 +#endif
72915 +
72916 + pax_task_size -= PAGE_SIZE;
72917 +
72918 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72919 + old_len > pax_task_size || addr > pax_task_size-old_len)
72920 + goto out;
72921 +
72922 if (flags & MREMAP_FIXED) {
72923 if (flags & MREMAP_MAYMOVE)
72924 ret = mremap_to(addr, old_len, new_addr, new_len);
72925 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72926 addr + new_len);
72927 }
72928 ret = addr;
72929 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72930 goto out;
72931 }
72932 }
72933 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72934 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72935 if (ret)
72936 goto out;
72937 +
72938 + map_flags = vma->vm_flags;
72939 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72940 + if (!(ret & ~PAGE_MASK)) {
72941 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72942 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72943 + }
72944 }
72945 out:
72946 if (ret & ~PAGE_MASK)
72947 diff --git a/mm/nommu.c b/mm/nommu.c
72948 index f59e170..34e2a2b 100644
72949 --- a/mm/nommu.c
72950 +++ b/mm/nommu.c
72951 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72952 int sysctl_overcommit_ratio = 50; /* default is 50% */
72953 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72954 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72955 -int heap_stack_gap = 0;
72956
72957 atomic_long_t mmap_pages_allocated;
72958
72959 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72960 EXPORT_SYMBOL(find_vma);
72961
72962 /*
72963 - * find a VMA
72964 - * - we don't extend stack VMAs under NOMMU conditions
72965 - */
72966 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72967 -{
72968 - return find_vma(mm, addr);
72969 -}
72970 -
72971 -/*
72972 * expand a stack to a given address
72973 * - not supported under NOMMU conditions
72974 */
72975 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72976
72977 /* most fields are the same, copy all, and then fixup */
72978 *new = *vma;
72979 + INIT_LIST_HEAD(&new->anon_vma_chain);
72980 *region = *vma->vm_region;
72981 new->vm_region = region;
72982
72983 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72984 index a13ded1..b949d15 100644
72985 --- a/mm/page_alloc.c
72986 +++ b/mm/page_alloc.c
72987 @@ -335,7 +335,7 @@ out:
72988 * This usage means that zero-order pages may not be compound.
72989 */
72990
72991 -static void free_compound_page(struct page *page)
72992 +void free_compound_page(struct page *page)
72993 {
72994 __free_pages_ok(page, compound_order(page));
72995 }
72996 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72997 int i;
72998 int bad = 0;
72999
73000 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73001 + unsigned long index = 1UL << order;
73002 +#endif
73003 +
73004 trace_mm_page_free(page, order);
73005 kmemcheck_free_shadow(page, order);
73006
73007 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73008 debug_check_no_obj_freed(page_address(page),
73009 PAGE_SIZE << order);
73010 }
73011 +
73012 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73013 + for (; index; --index)
73014 + sanitize_highpage(page + index - 1);
73015 +#endif
73016 +
73017 arch_free_page(page, order);
73018 kernel_map_pages(page, 1 << order, 0);
73019
73020 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73021 arch_alloc_page(page, order);
73022 kernel_map_pages(page, 1 << order, 1);
73023
73024 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73025 if (gfp_flags & __GFP_ZERO)
73026 prep_zero_page(page, order, gfp_flags);
73027 +#endif
73028
73029 if (order && (gfp_flags & __GFP_COMP))
73030 prep_compound_page(page, order);
73031 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73032 unsigned long pfn;
73033
73034 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73035 +#ifdef CONFIG_X86_32
73036 + /* boot failures in VMware 8 on 32bit vanilla since
73037 + this change */
73038 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73039 +#else
73040 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73041 +#endif
73042 return 1;
73043 }
73044 return 0;
73045 diff --git a/mm/percpu.c b/mm/percpu.c
73046 index f47af91..7eeef99 100644
73047 --- a/mm/percpu.c
73048 +++ b/mm/percpu.c
73049 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73050 static unsigned int pcpu_high_unit_cpu __read_mostly;
73051
73052 /* the address of the first chunk which starts with the kernel static area */
73053 -void *pcpu_base_addr __read_mostly;
73054 +void *pcpu_base_addr __read_only;
73055 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73056
73057 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73058 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73059 index c20ff48..137702a 100644
73060 --- a/mm/process_vm_access.c
73061 +++ b/mm/process_vm_access.c
73062 @@ -13,6 +13,7 @@
73063 #include <linux/uio.h>
73064 #include <linux/sched.h>
73065 #include <linux/highmem.h>
73066 +#include <linux/security.h>
73067 #include <linux/ptrace.h>
73068 #include <linux/slab.h>
73069 #include <linux/syscalls.h>
73070 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73071 size_t iov_l_curr_offset = 0;
73072 ssize_t iov_len;
73073
73074 + return -ENOSYS; // PaX: until properly audited
73075 +
73076 /*
73077 * Work out how many pages of struct pages we're going to need
73078 * when eventually calling get_user_pages
73079 */
73080 for (i = 0; i < riovcnt; i++) {
73081 iov_len = rvec[i].iov_len;
73082 - if (iov_len > 0) {
73083 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73084 - + iov_len)
73085 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73086 - / PAGE_SIZE + 1;
73087 - nr_pages = max(nr_pages, nr_pages_iov);
73088 - }
73089 + if (iov_len <= 0)
73090 + continue;
73091 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73092 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73093 + nr_pages = max(nr_pages, nr_pages_iov);
73094 }
73095
73096 if (nr_pages == 0)
73097 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73098 goto free_proc_pages;
73099 }
73100
73101 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73102 + rc = -EPERM;
73103 + goto put_task_struct;
73104 + }
73105 +
73106 mm = mm_access(task, PTRACE_MODE_ATTACH);
73107 if (!mm || IS_ERR(mm)) {
73108 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73109 diff --git a/mm/rmap.c b/mm/rmap.c
73110 index c8454e0..b04f3a2 100644
73111 --- a/mm/rmap.c
73112 +++ b/mm/rmap.c
73113 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73114 struct anon_vma *anon_vma = vma->anon_vma;
73115 struct anon_vma_chain *avc;
73116
73117 +#ifdef CONFIG_PAX_SEGMEXEC
73118 + struct anon_vma_chain *avc_m = NULL;
73119 +#endif
73120 +
73121 might_sleep();
73122 if (unlikely(!anon_vma)) {
73123 struct mm_struct *mm = vma->vm_mm;
73124 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73125 if (!avc)
73126 goto out_enomem;
73127
73128 +#ifdef CONFIG_PAX_SEGMEXEC
73129 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73130 + if (!avc_m)
73131 + goto out_enomem_free_avc;
73132 +#endif
73133 +
73134 anon_vma = find_mergeable_anon_vma(vma);
73135 allocated = NULL;
73136 if (!anon_vma) {
73137 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73138 /* page_table_lock to protect against threads */
73139 spin_lock(&mm->page_table_lock);
73140 if (likely(!vma->anon_vma)) {
73141 +
73142 +#ifdef CONFIG_PAX_SEGMEXEC
73143 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73144 +
73145 + if (vma_m) {
73146 + BUG_ON(vma_m->anon_vma);
73147 + vma_m->anon_vma = anon_vma;
73148 + avc_m->anon_vma = anon_vma;
73149 + avc_m->vma = vma;
73150 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73151 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73152 + avc_m = NULL;
73153 + }
73154 +#endif
73155 +
73156 vma->anon_vma = anon_vma;
73157 avc->anon_vma = anon_vma;
73158 avc->vma = vma;
73159 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73160
73161 if (unlikely(allocated))
73162 put_anon_vma(allocated);
73163 +
73164 +#ifdef CONFIG_PAX_SEGMEXEC
73165 + if (unlikely(avc_m))
73166 + anon_vma_chain_free(avc_m);
73167 +#endif
73168 +
73169 if (unlikely(avc))
73170 anon_vma_chain_free(avc);
73171 }
73172 return 0;
73173
73174 out_enomem_free_avc:
73175 +
73176 +#ifdef CONFIG_PAX_SEGMEXEC
73177 + if (avc_m)
73178 + anon_vma_chain_free(avc_m);
73179 +#endif
73180 +
73181 anon_vma_chain_free(avc);
73182 out_enomem:
73183 return -ENOMEM;
73184 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73185 * Attach the anon_vmas from src to dst.
73186 * Returns 0 on success, -ENOMEM on failure.
73187 */
73188 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73189 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73190 {
73191 struct anon_vma_chain *avc, *pavc;
73192 struct anon_vma *root = NULL;
73193 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73194 * the corresponding VMA in the parent process is attached to.
73195 * Returns 0 on success, non-zero on failure.
73196 */
73197 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73198 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73199 {
73200 struct anon_vma_chain *avc;
73201 struct anon_vma *anon_vma;
73202 diff --git a/mm/shmem.c b/mm/shmem.c
73203 index 269d049..a9d2b50 100644
73204 --- a/mm/shmem.c
73205 +++ b/mm/shmem.c
73206 @@ -31,7 +31,7 @@
73207 #include <linux/export.h>
73208 #include <linux/swap.h>
73209
73210 -static struct vfsmount *shm_mnt;
73211 +struct vfsmount *shm_mnt;
73212
73213 #ifdef CONFIG_SHMEM
73214 /*
73215 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73216 #define BOGO_DIRENT_SIZE 20
73217
73218 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73219 -#define SHORT_SYMLINK_LEN 128
73220 +#define SHORT_SYMLINK_LEN 64
73221
73222 struct shmem_xattr {
73223 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73224 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73225 int err = -ENOMEM;
73226
73227 /* Round up to L1_CACHE_BYTES to resist false sharing */
73228 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73229 - L1_CACHE_BYTES), GFP_KERNEL);
73230 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73231 if (!sbinfo)
73232 return -ENOMEM;
73233
73234 diff --git a/mm/slab.c b/mm/slab.c
73235 index f0bd785..348b96a 100644
73236 --- a/mm/slab.c
73237 +++ b/mm/slab.c
73238 @@ -153,7 +153,7 @@
73239
73240 /* Legal flag mask for kmem_cache_create(). */
73241 #if DEBUG
73242 -# define CREATE_MASK (SLAB_RED_ZONE | \
73243 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73244 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73245 SLAB_CACHE_DMA | \
73246 SLAB_STORE_USER | \
73247 @@ -161,7 +161,7 @@
73248 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73249 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73250 #else
73251 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73252 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73253 SLAB_CACHE_DMA | \
73254 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73255 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73256 @@ -290,7 +290,7 @@ struct kmem_list3 {
73257 * Need this for bootstrapping a per node allocator.
73258 */
73259 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73260 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73261 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73262 #define CACHE_CACHE 0
73263 #define SIZE_AC MAX_NUMNODES
73264 #define SIZE_L3 (2 * MAX_NUMNODES)
73265 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73266 if ((x)->max_freeable < i) \
73267 (x)->max_freeable = i; \
73268 } while (0)
73269 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73270 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73271 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73272 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73273 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73274 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73275 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73276 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73277 #else
73278 #define STATS_INC_ACTIVE(x) do { } while (0)
73279 #define STATS_DEC_ACTIVE(x) do { } while (0)
73280 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73281 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73282 */
73283 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73284 - const struct slab *slab, void *obj)
73285 + const struct slab *slab, const void *obj)
73286 {
73287 u32 offset = (obj - slab->s_mem);
73288 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73289 @@ -568,7 +568,7 @@ struct cache_names {
73290 static struct cache_names __initdata cache_names[] = {
73291 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73292 #include <linux/kmalloc_sizes.h>
73293 - {NULL,}
73294 + {NULL}
73295 #undef CACHE
73296 };
73297
73298 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73299 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73300 sizes[INDEX_AC].cs_size,
73301 ARCH_KMALLOC_MINALIGN,
73302 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73303 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73304 NULL);
73305
73306 if (INDEX_AC != INDEX_L3) {
73307 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73308 kmem_cache_create(names[INDEX_L3].name,
73309 sizes[INDEX_L3].cs_size,
73310 ARCH_KMALLOC_MINALIGN,
73311 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73312 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73313 NULL);
73314 }
73315
73316 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73317 sizes->cs_cachep = kmem_cache_create(names->name,
73318 sizes->cs_size,
73319 ARCH_KMALLOC_MINALIGN,
73320 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73321 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73322 NULL);
73323 }
73324 #ifdef CONFIG_ZONE_DMA
73325 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73326 }
73327 /* cpu stats */
73328 {
73329 - unsigned long allochit = atomic_read(&cachep->allochit);
73330 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73331 - unsigned long freehit = atomic_read(&cachep->freehit);
73332 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73333 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73334 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73335 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73336 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73337
73338 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73339 allochit, allocmiss, freehit, freemiss);
73340 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73341 {
73342 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73343 #ifdef CONFIG_DEBUG_SLAB_LEAK
73344 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73345 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73346 #endif
73347 return 0;
73348 }
73349 module_init(slab_proc_init);
73350 #endif
73351
73352 +void check_object_size(const void *ptr, unsigned long n, bool to)
73353 +{
73354 +
73355 +#ifdef CONFIG_PAX_USERCOPY
73356 + struct page *page;
73357 + struct kmem_cache *cachep = NULL;
73358 + struct slab *slabp;
73359 + unsigned int objnr;
73360 + unsigned long offset;
73361 + const char *type;
73362 +
73363 + if (!n)
73364 + return;
73365 +
73366 + type = "<null>";
73367 + if (ZERO_OR_NULL_PTR(ptr))
73368 + goto report;
73369 +
73370 + if (!virt_addr_valid(ptr))
73371 + return;
73372 +
73373 + page = virt_to_head_page(ptr);
73374 +
73375 + type = "<process stack>";
73376 + if (!PageSlab(page)) {
73377 + if (object_is_on_stack(ptr, n) == -1)
73378 + goto report;
73379 + return;
73380 + }
73381 +
73382 + cachep = page_get_cache(page);
73383 + type = cachep->name;
73384 + if (!(cachep->flags & SLAB_USERCOPY))
73385 + goto report;
73386 +
73387 + slabp = page_get_slab(page);
73388 + objnr = obj_to_index(cachep, slabp, ptr);
73389 + BUG_ON(objnr >= cachep->num);
73390 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73391 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73392 + return;
73393 +
73394 +report:
73395 + pax_report_usercopy(ptr, n, to, type);
73396 +#endif
73397 +
73398 +}
73399 +EXPORT_SYMBOL(check_object_size);
73400 +
73401 /**
73402 * ksize - get the actual amount of memory allocated for a given object
73403 * @objp: Pointer to the object
73404 diff --git a/mm/slob.c b/mm/slob.c
73405 index 8105be4..e045f96 100644
73406 --- a/mm/slob.c
73407 +++ b/mm/slob.c
73408 @@ -29,7 +29,7 @@
73409 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73410 * alloc_pages() directly, allocating compound pages so the page order
73411 * does not have to be separately tracked, and also stores the exact
73412 - * allocation size in page->private so that it can be used to accurately
73413 + * allocation size in slob_page->size so that it can be used to accurately
73414 * provide ksize(). These objects are detected in kfree() because slob_page()
73415 * is false for them.
73416 *
73417 @@ -58,6 +58,7 @@
73418 */
73419
73420 #include <linux/kernel.h>
73421 +#include <linux/sched.h>
73422 #include <linux/slab.h>
73423 #include <linux/mm.h>
73424 #include <linux/swap.h> /* struct reclaim_state */
73425 @@ -102,7 +103,8 @@ struct slob_page {
73426 unsigned long flags; /* mandatory */
73427 atomic_t _count; /* mandatory */
73428 slobidx_t units; /* free units left in page */
73429 - unsigned long pad[2];
73430 + unsigned long pad[1];
73431 + unsigned long size; /* size when >=PAGE_SIZE */
73432 slob_t *free; /* first free slob_t in page */
73433 struct list_head list; /* linked list of free pages */
73434 };
73435 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73436 */
73437 static inline int is_slob_page(struct slob_page *sp)
73438 {
73439 - return PageSlab((struct page *)sp);
73440 + return PageSlab((struct page *)sp) && !sp->size;
73441 }
73442
73443 static inline void set_slob_page(struct slob_page *sp)
73444 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73445
73446 static inline struct slob_page *slob_page(const void *addr)
73447 {
73448 - return (struct slob_page *)virt_to_page(addr);
73449 + return (struct slob_page *)virt_to_head_page(addr);
73450 }
73451
73452 /*
73453 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73454 /*
73455 * Return the size of a slob block.
73456 */
73457 -static slobidx_t slob_units(slob_t *s)
73458 +static slobidx_t slob_units(const slob_t *s)
73459 {
73460 if (s->units > 0)
73461 return s->units;
73462 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73463 /*
73464 * Return the next free slob block pointer after this one.
73465 */
73466 -static slob_t *slob_next(slob_t *s)
73467 +static slob_t *slob_next(const slob_t *s)
73468 {
73469 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73470 slobidx_t next;
73471 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73472 /*
73473 * Returns true if s is the last free block in its page.
73474 */
73475 -static int slob_last(slob_t *s)
73476 +static int slob_last(const slob_t *s)
73477 {
73478 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73479 }
73480 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73481 if (!page)
73482 return NULL;
73483
73484 + set_slob_page(page);
73485 return page_address(page);
73486 }
73487
73488 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73489 if (!b)
73490 return NULL;
73491 sp = slob_page(b);
73492 - set_slob_page(sp);
73493
73494 spin_lock_irqsave(&slob_lock, flags);
73495 sp->units = SLOB_UNITS(PAGE_SIZE);
73496 sp->free = b;
73497 + sp->size = 0;
73498 INIT_LIST_HEAD(&sp->list);
73499 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73500 set_slob_page_free(sp, slob_list);
73501 @@ -476,10 +479,9 @@ out:
73502 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73503 */
73504
73505 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73506 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73507 {
73508 - unsigned int *m;
73509 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73510 + slob_t *m;
73511 void *ret;
73512
73513 gfp &= gfp_allowed_mask;
73514 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73515
73516 if (!m)
73517 return NULL;
73518 - *m = size;
73519 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73520 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73521 + m[0].units = size;
73522 + m[1].units = align;
73523 ret = (void *)m + align;
73524
73525 trace_kmalloc_node(_RET_IP_, ret,
73526 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73527 gfp |= __GFP_COMP;
73528 ret = slob_new_pages(gfp, order, node);
73529 if (ret) {
73530 - struct page *page;
73531 - page = virt_to_page(ret);
73532 - page->private = size;
73533 + struct slob_page *sp;
73534 + sp = slob_page(ret);
73535 + sp->size = size;
73536 }
73537
73538 trace_kmalloc_node(_RET_IP_, ret,
73539 size, PAGE_SIZE << order, gfp, node);
73540 }
73541
73542 - kmemleak_alloc(ret, size, 1, gfp);
73543 + return ret;
73544 +}
73545 +
73546 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73547 +{
73548 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73549 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73550 +
73551 + if (!ZERO_OR_NULL_PTR(ret))
73552 + kmemleak_alloc(ret, size, 1, gfp);
73553 return ret;
73554 }
73555 EXPORT_SYMBOL(__kmalloc_node);
73556 @@ -533,13 +547,92 @@ void kfree(const void *block)
73557 sp = slob_page(block);
73558 if (is_slob_page(sp)) {
73559 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73560 - unsigned int *m = (unsigned int *)(block - align);
73561 - slob_free(m, *m + align);
73562 - } else
73563 + slob_t *m = (slob_t *)(block - align);
73564 + slob_free(m, m[0].units + align);
73565 + } else {
73566 + clear_slob_page(sp);
73567 + free_slob_page(sp);
73568 + sp->size = 0;
73569 put_page(&sp->page);
73570 + }
73571 }
73572 EXPORT_SYMBOL(kfree);
73573
73574 +void check_object_size(const void *ptr, unsigned long n, bool to)
73575 +{
73576 +
73577 +#ifdef CONFIG_PAX_USERCOPY
73578 + struct slob_page *sp;
73579 + const slob_t *free;
73580 + const void *base;
73581 + unsigned long flags;
73582 + const char *type;
73583 +
73584 + if (!n)
73585 + return;
73586 +
73587 + type = "<null>";
73588 + if (ZERO_OR_NULL_PTR(ptr))
73589 + goto report;
73590 +
73591 + if (!virt_addr_valid(ptr))
73592 + return;
73593 +
73594 + type = "<process stack>";
73595 + sp = slob_page(ptr);
73596 + if (!PageSlab((struct page *)sp)) {
73597 + if (object_is_on_stack(ptr, n) == -1)
73598 + goto report;
73599 + return;
73600 + }
73601 +
73602 + type = "<slob>";
73603 + if (sp->size) {
73604 + base = page_address(&sp->page);
73605 + if (base <= ptr && n <= sp->size - (ptr - base))
73606 + return;
73607 + goto report;
73608 + }
73609 +
73610 + /* some tricky double walking to find the chunk */
73611 + spin_lock_irqsave(&slob_lock, flags);
73612 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73613 + free = sp->free;
73614 +
73615 + while (!slob_last(free) && (void *)free <= ptr) {
73616 + base = free + slob_units(free);
73617 + free = slob_next(free);
73618 + }
73619 +
73620 + while (base < (void *)free) {
73621 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73622 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73623 + int offset;
73624 +
73625 + if (ptr < base + align)
73626 + break;
73627 +
73628 + offset = ptr - base - align;
73629 + if (offset >= m) {
73630 + base += size;
73631 + continue;
73632 + }
73633 +
73634 + if (n > m - offset)
73635 + break;
73636 +
73637 + spin_unlock_irqrestore(&slob_lock, flags);
73638 + return;
73639 + }
73640 +
73641 + spin_unlock_irqrestore(&slob_lock, flags);
73642 +report:
73643 + pax_report_usercopy(ptr, n, to, type);
73644 +#endif
73645 +
73646 +}
73647 +EXPORT_SYMBOL(check_object_size);
73648 +
73649 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73650 size_t ksize(const void *block)
73651 {
73652 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73653 sp = slob_page(block);
73654 if (is_slob_page(sp)) {
73655 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73656 - unsigned int *m = (unsigned int *)(block - align);
73657 - return SLOB_UNITS(*m) * SLOB_UNIT;
73658 + slob_t *m = (slob_t *)(block - align);
73659 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73660 } else
73661 - return sp->page.private;
73662 + return sp->size;
73663 }
73664 EXPORT_SYMBOL(ksize);
73665
73666 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73667 {
73668 struct kmem_cache *c;
73669
73670 +#ifdef CONFIG_PAX_USERCOPY
73671 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73672 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73673 +#else
73674 c = slob_alloc(sizeof(struct kmem_cache),
73675 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73676 +#endif
73677
73678 if (c) {
73679 c->name = name;
73680 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73681
73682 lockdep_trace_alloc(flags);
73683
73684 +#ifdef CONFIG_PAX_USERCOPY
73685 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73686 +#else
73687 if (c->size < PAGE_SIZE) {
73688 b = slob_alloc(c->size, flags, c->align, node);
73689 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73690 SLOB_UNITS(c->size) * SLOB_UNIT,
73691 flags, node);
73692 } else {
73693 + struct slob_page *sp;
73694 +
73695 b = slob_new_pages(flags, get_order(c->size), node);
73696 + sp = slob_page(b);
73697 + sp->size = c->size;
73698 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73699 PAGE_SIZE << get_order(c->size),
73700 flags, node);
73701 }
73702 +#endif
73703
73704 if (c->ctor)
73705 c->ctor(b);
73706 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73707
73708 static void __kmem_cache_free(void *b, int size)
73709 {
73710 - if (size < PAGE_SIZE)
73711 + struct slob_page *sp = slob_page(b);
73712 +
73713 + if (is_slob_page(sp))
73714 slob_free(b, size);
73715 - else
73716 + else {
73717 + clear_slob_page(sp);
73718 + free_slob_page(sp);
73719 + sp->size = 0;
73720 slob_free_pages(b, get_order(size));
73721 + }
73722 }
73723
73724 static void kmem_rcu_free(struct rcu_head *head)
73725 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73726
73727 void kmem_cache_free(struct kmem_cache *c, void *b)
73728 {
73729 + int size = c->size;
73730 +
73731 +#ifdef CONFIG_PAX_USERCOPY
73732 + if (size + c->align < PAGE_SIZE) {
73733 + size += c->align;
73734 + b -= c->align;
73735 + }
73736 +#endif
73737 +
73738 kmemleak_free_recursive(b, c->flags);
73739 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73740 struct slob_rcu *slob_rcu;
73741 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73742 - slob_rcu->size = c->size;
73743 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73744 + slob_rcu->size = size;
73745 call_rcu(&slob_rcu->head, kmem_rcu_free);
73746 } else {
73747 - __kmem_cache_free(b, c->size);
73748 + __kmem_cache_free(b, size);
73749 }
73750
73751 +#ifdef CONFIG_PAX_USERCOPY
73752 + trace_kfree(_RET_IP_, b);
73753 +#else
73754 trace_kmem_cache_free(_RET_IP_, b);
73755 +#endif
73756 +
73757 }
73758 EXPORT_SYMBOL(kmem_cache_free);
73759
73760 diff --git a/mm/slub.c b/mm/slub.c
73761 index 0342a5d..8180ae9 100644
73762 --- a/mm/slub.c
73763 +++ b/mm/slub.c
73764 @@ -208,7 +208,7 @@ struct track {
73765
73766 enum track_item { TRACK_ALLOC, TRACK_FREE };
73767
73768 -#ifdef CONFIG_SYSFS
73769 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73770 static int sysfs_slab_add(struct kmem_cache *);
73771 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73772 static void sysfs_slab_remove(struct kmem_cache *);
73773 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73774 if (!t->addr)
73775 return;
73776
73777 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73778 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73779 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73780 #ifdef CONFIG_STACKTRACE
73781 {
73782 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73783
73784 page = virt_to_head_page(x);
73785
73786 + BUG_ON(!PageSlab(page));
73787 +
73788 slab_free(s, page, x, _RET_IP_);
73789
73790 trace_kmem_cache_free(_RET_IP_, x);
73791 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
73792 * Merge control. If this is set then no merging of slab caches will occur.
73793 * (Could be removed. This was introduced to pacify the merge skeptics.)
73794 */
73795 -static int slub_nomerge;
73796 +static int slub_nomerge = 1;
73797
73798 /*
73799 * Calculate the order of allocation given an slab object size.
73800 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73801 else
73802 s->cpu_partial = 30;
73803
73804 - s->refcount = 1;
73805 + atomic_set(&s->refcount, 1);
73806 #ifdef CONFIG_NUMA
73807 s->remote_node_defrag_ratio = 1000;
73808 #endif
73809 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73810 void kmem_cache_destroy(struct kmem_cache *s)
73811 {
73812 down_write(&slub_lock);
73813 - s->refcount--;
73814 - if (!s->refcount) {
73815 + if (atomic_dec_and_test(&s->refcount)) {
73816 list_del(&s->list);
73817 up_write(&slub_lock);
73818 if (kmem_cache_close(s)) {
73819 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73820 EXPORT_SYMBOL(__kmalloc_node);
73821 #endif
73822
73823 +void check_object_size(const void *ptr, unsigned long n, bool to)
73824 +{
73825 +
73826 +#ifdef CONFIG_PAX_USERCOPY
73827 + struct page *page;
73828 + struct kmem_cache *s = NULL;
73829 + unsigned long offset;
73830 + const char *type;
73831 +
73832 + if (!n)
73833 + return;
73834 +
73835 + type = "<null>";
73836 + if (ZERO_OR_NULL_PTR(ptr))
73837 + goto report;
73838 +
73839 + if (!virt_addr_valid(ptr))
73840 + return;
73841 +
73842 + page = virt_to_head_page(ptr);
73843 +
73844 + type = "<process stack>";
73845 + if (!PageSlab(page)) {
73846 + if (object_is_on_stack(ptr, n) == -1)
73847 + goto report;
73848 + return;
73849 + }
73850 +
73851 + s = page->slab;
73852 + type = s->name;
73853 + if (!(s->flags & SLAB_USERCOPY))
73854 + goto report;
73855 +
73856 + offset = (ptr - page_address(page)) % s->size;
73857 + if (offset <= s->objsize && n <= s->objsize - offset)
73858 + return;
73859 +
73860 +report:
73861 + pax_report_usercopy(ptr, n, to, type);
73862 +#endif
73863 +
73864 +}
73865 +EXPORT_SYMBOL(check_object_size);
73866 +
73867 size_t ksize(const void *object)
73868 {
73869 struct page *page;
73870 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73871 int node;
73872
73873 list_add(&s->list, &slab_caches);
73874 - s->refcount = -1;
73875 + atomic_set(&s->refcount, -1);
73876
73877 for_each_node_state(node, N_NORMAL_MEMORY) {
73878 struct kmem_cache_node *n = get_node(s, node);
73879 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73880
73881 /* Caches that are not of the two-to-the-power-of size */
73882 if (KMALLOC_MIN_SIZE <= 32) {
73883 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73884 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73885 caches++;
73886 }
73887
73888 if (KMALLOC_MIN_SIZE <= 64) {
73889 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73890 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73891 caches++;
73892 }
73893
73894 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73895 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73896 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73897 caches++;
73898 }
73899
73900 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73901 /*
73902 * We may have set a slab to be unmergeable during bootstrap.
73903 */
73904 - if (s->refcount < 0)
73905 + if (atomic_read(&s->refcount) < 0)
73906 return 1;
73907
73908 return 0;
73909 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73910 down_write(&slub_lock);
73911 s = find_mergeable(size, align, flags, name, ctor);
73912 if (s) {
73913 - s->refcount++;
73914 + atomic_inc(&s->refcount);
73915 /*
73916 * Adjust the object sizes so that we clear
73917 * the complete object on kzalloc.
73918 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73919 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73920
73921 if (sysfs_slab_alias(s, name)) {
73922 - s->refcount--;
73923 + atomic_dec(&s->refcount);
73924 goto err;
73925 }
73926 up_write(&slub_lock);
73927 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73928 }
73929 #endif
73930
73931 -#ifdef CONFIG_SYSFS
73932 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73933 static int count_inuse(struct page *page)
73934 {
73935 return page->inuse;
73936 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
73937 validate_slab_cache(kmalloc_caches[9]);
73938 }
73939 #else
73940 -#ifdef CONFIG_SYSFS
73941 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73942 static void resiliency_test(void) {};
73943 #endif
73944 #endif
73945
73946 -#ifdef CONFIG_SYSFS
73947 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73948 enum slab_stat_type {
73949 SL_ALL, /* All slabs */
73950 SL_PARTIAL, /* Only partially allocated slabs */
73951 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
73952
73953 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73954 {
73955 - return sprintf(buf, "%d\n", s->refcount - 1);
73956 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73957 }
73958 SLAB_ATTR_RO(aliases);
73959
73960 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
73961 return name;
73962 }
73963
73964 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73965 static int sysfs_slab_add(struct kmem_cache *s)
73966 {
73967 int err;
73968 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73969 kobject_del(&s->kobj);
73970 kobject_put(&s->kobj);
73971 }
73972 +#endif
73973
73974 /*
73975 * Need to buffer aliases during bootup until sysfs becomes
73976 @@ -5319,6 +5366,7 @@ struct saved_alias {
73977
73978 static struct saved_alias *alias_list;
73979
73980 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73981 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73982 {
73983 struct saved_alias *al;
73984 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73985 alias_list = al;
73986 return 0;
73987 }
73988 +#endif
73989
73990 static int __init slab_sysfs_init(void)
73991 {
73992 diff --git a/mm/swap.c b/mm/swap.c
73993 index 14380e9..e244704 100644
73994 --- a/mm/swap.c
73995 +++ b/mm/swap.c
73996 @@ -30,6 +30,7 @@
73997 #include <linux/backing-dev.h>
73998 #include <linux/memcontrol.h>
73999 #include <linux/gfp.h>
74000 +#include <linux/hugetlb.h>
74001
74002 #include "internal.h"
74003
74004 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74005
74006 __page_cache_release(page);
74007 dtor = get_compound_page_dtor(page);
74008 + if (!PageHuge(page))
74009 + BUG_ON(dtor != free_compound_page);
74010 (*dtor)(page);
74011 }
74012
74013 diff --git a/mm/swapfile.c b/mm/swapfile.c
74014 index f31b29d..8bdcae2 100644
74015 --- a/mm/swapfile.c
74016 +++ b/mm/swapfile.c
74017 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74018
74019 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74020 /* Activity counter to indicate that a swapon or swapoff has occurred */
74021 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74022 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74023
74024 static inline unsigned char swap_count(unsigned char ent)
74025 {
74026 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74027 }
74028 filp_close(swap_file, NULL);
74029 err = 0;
74030 - atomic_inc(&proc_poll_event);
74031 + atomic_inc_unchecked(&proc_poll_event);
74032 wake_up_interruptible(&proc_poll_wait);
74033
74034 out_dput:
74035 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74036
74037 poll_wait(file, &proc_poll_wait, wait);
74038
74039 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74040 - seq->poll_event = atomic_read(&proc_poll_event);
74041 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74042 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74043 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74044 }
74045
74046 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74047 return ret;
74048
74049 seq = file->private_data;
74050 - seq->poll_event = atomic_read(&proc_poll_event);
74051 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74052 return 0;
74053 }
74054
74055 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74056 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74057
74058 mutex_unlock(&swapon_mutex);
74059 - atomic_inc(&proc_poll_event);
74060 + atomic_inc_unchecked(&proc_poll_event);
74061 wake_up_interruptible(&proc_poll_wait);
74062
74063 if (S_ISREG(inode->i_mode))
74064 diff --git a/mm/util.c b/mm/util.c
74065 index 136ac4f..f917fa9 100644
74066 --- a/mm/util.c
74067 +++ b/mm/util.c
74068 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74069 void arch_pick_mmap_layout(struct mm_struct *mm)
74070 {
74071 mm->mmap_base = TASK_UNMAPPED_BASE;
74072 +
74073 +#ifdef CONFIG_PAX_RANDMMAP
74074 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74075 + mm->mmap_base += mm->delta_mmap;
74076 +#endif
74077 +
74078 mm->get_unmapped_area = arch_get_unmapped_area;
74079 mm->unmap_area = arch_unmap_area;
74080 }
74081 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74082 index 86ce9a5..bc498f3 100644
74083 --- a/mm/vmalloc.c
74084 +++ b/mm/vmalloc.c
74085 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74086
74087 pte = pte_offset_kernel(pmd, addr);
74088 do {
74089 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74090 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74091 +
74092 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74093 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74094 + BUG_ON(!pte_exec(*pte));
74095 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74096 + continue;
74097 + }
74098 +#endif
74099 +
74100 + {
74101 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74102 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74103 + }
74104 } while (pte++, addr += PAGE_SIZE, addr != end);
74105 }
74106
74107 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74108 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74109 {
74110 pte_t *pte;
74111 + int ret = -ENOMEM;
74112
74113 /*
74114 * nr is a running index into the array which helps higher level
74115 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74116 pte = pte_alloc_kernel(pmd, addr);
74117 if (!pte)
74118 return -ENOMEM;
74119 +
74120 + pax_open_kernel();
74121 do {
74122 struct page *page = pages[*nr];
74123
74124 - if (WARN_ON(!pte_none(*pte)))
74125 - return -EBUSY;
74126 - if (WARN_ON(!page))
74127 - return -ENOMEM;
74128 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74129 + if (pgprot_val(prot) & _PAGE_NX)
74130 +#endif
74131 +
74132 + if (WARN_ON(!pte_none(*pte))) {
74133 + ret = -EBUSY;
74134 + goto out;
74135 + }
74136 + if (WARN_ON(!page)) {
74137 + ret = -ENOMEM;
74138 + goto out;
74139 + }
74140 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74141 (*nr)++;
74142 } while (pte++, addr += PAGE_SIZE, addr != end);
74143 - return 0;
74144 + ret = 0;
74145 +out:
74146 + pax_close_kernel();
74147 + return ret;
74148 }
74149
74150 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74151 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74152 * and fall back on vmalloc() if that fails. Others
74153 * just put it in the vmalloc space.
74154 */
74155 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74156 +#ifdef CONFIG_MODULES
74157 +#ifdef MODULES_VADDR
74158 unsigned long addr = (unsigned long)x;
74159 if (addr >= MODULES_VADDR && addr < MODULES_END)
74160 return 1;
74161 #endif
74162 +
74163 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74164 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74165 + return 1;
74166 +#endif
74167 +
74168 +#endif
74169 +
74170 return is_vmalloc_addr(x);
74171 }
74172
74173 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74174
74175 if (!pgd_none(*pgd)) {
74176 pud_t *pud = pud_offset(pgd, addr);
74177 +#ifdef CONFIG_X86
74178 + if (!pud_large(*pud))
74179 +#endif
74180 if (!pud_none(*pud)) {
74181 pmd_t *pmd = pmd_offset(pud, addr);
74182 +#ifdef CONFIG_X86
74183 + if (!pmd_large(*pmd))
74184 +#endif
74185 if (!pmd_none(*pmd)) {
74186 pte_t *ptep, pte;
74187
74188 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74189 struct vm_struct *area;
74190
74191 BUG_ON(in_interrupt());
74192 +
74193 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74194 + if (flags & VM_KERNEXEC) {
74195 + if (start != VMALLOC_START || end != VMALLOC_END)
74196 + return NULL;
74197 + start = (unsigned long)MODULES_EXEC_VADDR;
74198 + end = (unsigned long)MODULES_EXEC_END;
74199 + }
74200 +#endif
74201 +
74202 if (flags & VM_IOREMAP) {
74203 int bit = fls(size);
74204
74205 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
74206 if (count > totalram_pages)
74207 return NULL;
74208
74209 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74210 + if (!(pgprot_val(prot) & _PAGE_NX))
74211 + flags |= VM_KERNEXEC;
74212 +#endif
74213 +
74214 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74215 __builtin_return_address(0));
74216 if (!area)
74217 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74218 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74219 goto fail;
74220
74221 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74222 + if (!(pgprot_val(prot) & _PAGE_NX))
74223 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74224 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74225 + else
74226 +#endif
74227 +
74228 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74229 start, end, node, gfp_mask, caller);
74230 if (!area)
74231 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
74232 * For tight control over page level allocator and protection flags
74233 * use __vmalloc() instead.
74234 */
74235 -
74236 void *vmalloc_exec(unsigned long size)
74237 {
74238 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74239 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74240 -1, __builtin_return_address(0));
74241 }
74242
74243 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74244 unsigned long uaddr = vma->vm_start;
74245 unsigned long usize = vma->vm_end - vma->vm_start;
74246
74247 + BUG_ON(vma->vm_mirror);
74248 +
74249 if ((PAGE_SIZE-1) & (unsigned long)addr)
74250 return -EINVAL;
74251
74252 diff --git a/mm/vmstat.c b/mm/vmstat.c
74253 index f600557..1459fc8 100644
74254 --- a/mm/vmstat.c
74255 +++ b/mm/vmstat.c
74256 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74257 *
74258 * vm_stat contains the global counters
74259 */
74260 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74261 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74262 EXPORT_SYMBOL(vm_stat);
74263
74264 #ifdef CONFIG_SMP
74265 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74266 v = p->vm_stat_diff[i];
74267 p->vm_stat_diff[i] = 0;
74268 local_irq_restore(flags);
74269 - atomic_long_add(v, &zone->vm_stat[i]);
74270 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74271 global_diff[i] += v;
74272 #ifdef CONFIG_NUMA
74273 /* 3 seconds idle till flush */
74274 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74275
74276 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74277 if (global_diff[i])
74278 - atomic_long_add(global_diff[i], &vm_stat[i]);
74279 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74280 }
74281
74282 #endif
74283 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74284 start_cpu_timer(cpu);
74285 #endif
74286 #ifdef CONFIG_PROC_FS
74287 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74288 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74289 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74290 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74291 + {
74292 + mode_t gr_mode = S_IRUGO;
74293 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74294 + gr_mode = S_IRUSR;
74295 +#endif
74296 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74297 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74298 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74299 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74300 +#else
74301 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74302 +#endif
74303 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74304 + }
74305 #endif
74306 return 0;
74307 }
74308 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74309 index efea35b..9c8dd0b 100644
74310 --- a/net/8021q/vlan.c
74311 +++ b/net/8021q/vlan.c
74312 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74313 err = -EPERM;
74314 if (!capable(CAP_NET_ADMIN))
74315 break;
74316 - if ((args.u.name_type >= 0) &&
74317 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74318 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74319 struct vlan_net *vn;
74320
74321 vn = net_generic(net, vlan_net_id);
74322 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74323 index fccae26..e7ece2f 100644
74324 --- a/net/9p/trans_fd.c
74325 +++ b/net/9p/trans_fd.c
74326 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74327 oldfs = get_fs();
74328 set_fs(get_ds());
74329 /* The cast to a user pointer is valid due to the set_fs() */
74330 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74331 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74332 set_fs(oldfs);
74333
74334 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74335 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74336 index 876fbe8..8bbea9f 100644
74337 --- a/net/atm/atm_misc.c
74338 +++ b/net/atm/atm_misc.c
74339 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74340 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74341 return 1;
74342 atm_return(vcc, truesize);
74343 - atomic_inc(&vcc->stats->rx_drop);
74344 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74345 return 0;
74346 }
74347 EXPORT_SYMBOL(atm_charge);
74348 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74349 }
74350 }
74351 atm_return(vcc, guess);
74352 - atomic_inc(&vcc->stats->rx_drop);
74353 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74354 return NULL;
74355 }
74356 EXPORT_SYMBOL(atm_alloc_charge);
74357 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74358
74359 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74360 {
74361 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74362 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74363 __SONET_ITEMS
74364 #undef __HANDLE_ITEM
74365 }
74366 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74367
74368 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74369 {
74370 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74371 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74372 __SONET_ITEMS
74373 #undef __HANDLE_ITEM
74374 }
74375 diff --git a/net/atm/lec.h b/net/atm/lec.h
74376 index dfc0719..47c5322 100644
74377 --- a/net/atm/lec.h
74378 +++ b/net/atm/lec.h
74379 @@ -48,7 +48,7 @@ struct lane2_ops {
74380 const u8 *tlvs, u32 sizeoftlvs);
74381 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74382 const u8 *tlvs, u32 sizeoftlvs);
74383 -};
74384 +} __no_const;
74385
74386 /*
74387 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74388 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74389 index 0919a88..a23d54e 100644
74390 --- a/net/atm/mpc.h
74391 +++ b/net/atm/mpc.h
74392 @@ -33,7 +33,7 @@ struct mpoa_client {
74393 struct mpc_parameters parameters; /* parameters for this client */
74394
74395 const struct net_device_ops *old_ops;
74396 - struct net_device_ops new_ops;
74397 + net_device_ops_no_const new_ops;
74398 };
74399
74400
74401 diff --git a/net/atm/proc.c b/net/atm/proc.c
74402 index 0d020de..011c7bb 100644
74403 --- a/net/atm/proc.c
74404 +++ b/net/atm/proc.c
74405 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74406 const struct k_atm_aal_stats *stats)
74407 {
74408 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74409 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74410 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74411 - atomic_read(&stats->rx_drop));
74412 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74413 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74414 + atomic_read_unchecked(&stats->rx_drop));
74415 }
74416
74417 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74418 diff --git a/net/atm/resources.c b/net/atm/resources.c
74419 index 23f45ce..c748f1a 100644
74420 --- a/net/atm/resources.c
74421 +++ b/net/atm/resources.c
74422 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74423 static void copy_aal_stats(struct k_atm_aal_stats *from,
74424 struct atm_aal_stats *to)
74425 {
74426 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74427 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74428 __AAL_STAT_ITEMS
74429 #undef __HANDLE_ITEM
74430 }
74431 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74432 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74433 struct atm_aal_stats *to)
74434 {
74435 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74436 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74437 __AAL_STAT_ITEMS
74438 #undef __HANDLE_ITEM
74439 }
74440 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74441 index 3512e25..2b33401 100644
74442 --- a/net/batman-adv/bat_iv_ogm.c
74443 +++ b/net/batman-adv/bat_iv_ogm.c
74444 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74445
74446 /* change sequence number to network order */
74447 batman_ogm_packet->seqno =
74448 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74449 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74450
74451 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74452 batman_ogm_packet->tt_crc = htons((uint16_t)
74453 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74454 else
74455 batman_ogm_packet->gw_flags = NO_FLAGS;
74456
74457 - atomic_inc(&hard_iface->seqno);
74458 + atomic_inc_unchecked(&hard_iface->seqno);
74459
74460 slide_own_bcast_window(hard_iface);
74461 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74462 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74463 return;
74464
74465 /* could be changed by schedule_own_packet() */
74466 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74467 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74468
74469 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74470
74471 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74472 index 7704df4..beb4e16 100644
74473 --- a/net/batman-adv/hard-interface.c
74474 +++ b/net/batman-adv/hard-interface.c
74475 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74476 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74477 dev_add_pack(&hard_iface->batman_adv_ptype);
74478
74479 - atomic_set(&hard_iface->seqno, 1);
74480 - atomic_set(&hard_iface->frag_seqno, 1);
74481 + atomic_set_unchecked(&hard_iface->seqno, 1);
74482 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74483 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74484 hard_iface->net_dev->name);
74485
74486 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74487 index 987c75a..20d6f36 100644
74488 --- a/net/batman-adv/soft-interface.c
74489 +++ b/net/batman-adv/soft-interface.c
74490 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74491
74492 /* set broadcast sequence number */
74493 bcast_packet->seqno =
74494 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74495 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74496
74497 add_bcast_packet_to_list(bat_priv, skb, 1);
74498
74499 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74500 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74501
74502 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74503 - atomic_set(&bat_priv->bcast_seqno, 1);
74504 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74505 atomic_set(&bat_priv->ttvn, 0);
74506 atomic_set(&bat_priv->tt_local_changes, 0);
74507 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74508 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74509 index e9eb043..d174eeb 100644
74510 --- a/net/batman-adv/types.h
74511 +++ b/net/batman-adv/types.h
74512 @@ -38,8 +38,8 @@ struct hard_iface {
74513 int16_t if_num;
74514 char if_status;
74515 struct net_device *net_dev;
74516 - atomic_t seqno;
74517 - atomic_t frag_seqno;
74518 + atomic_unchecked_t seqno;
74519 + atomic_unchecked_t frag_seqno;
74520 unsigned char *packet_buff;
74521 int packet_len;
74522 struct kobject *hardif_obj;
74523 @@ -154,7 +154,7 @@ struct bat_priv {
74524 atomic_t orig_interval; /* uint */
74525 atomic_t hop_penalty; /* uint */
74526 atomic_t log_level; /* uint */
74527 - atomic_t bcast_seqno;
74528 + atomic_unchecked_t bcast_seqno;
74529 atomic_t bcast_queue_left;
74530 atomic_t batman_queue_left;
74531 atomic_t ttvn; /* translation table version number */
74532 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74533 index 07d1c1d..7e9bea9 100644
74534 --- a/net/batman-adv/unicast.c
74535 +++ b/net/batman-adv/unicast.c
74536 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74537 frag1->flags = UNI_FRAG_HEAD | large_tail;
74538 frag2->flags = large_tail;
74539
74540 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74541 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74542 frag1->seqno = htons(seqno - 1);
74543 frag2->seqno = htons(seqno);
74544
74545 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74546 index 07bc69e..21e76b1 100644
74547 --- a/net/bluetooth/hci_conn.c
74548 +++ b/net/bluetooth/hci_conn.c
74549 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74550 memset(&cp, 0, sizeof(cp));
74551
74552 cp.handle = cpu_to_le16(conn->handle);
74553 - memcpy(cp.ltk, ltk, sizeof(ltk));
74554 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74555
74556 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74557 }
74558 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74559 index 32d338c..d24bcdb 100644
74560 --- a/net/bluetooth/l2cap_core.c
74561 +++ b/net/bluetooth/l2cap_core.c
74562 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74563 break;
74564
74565 case L2CAP_CONF_RFC:
74566 - if (olen == sizeof(rfc))
74567 - memcpy(&rfc, (void *)val, olen);
74568 + if (olen != sizeof(rfc))
74569 + break;
74570 +
74571 + memcpy(&rfc, (void *)val, olen);
74572
74573 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74574 rfc.mode != chan->mode)
74575 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74576
74577 switch (type) {
74578 case L2CAP_CONF_RFC:
74579 - if (olen == sizeof(rfc))
74580 - memcpy(&rfc, (void *)val, olen);
74581 + if (olen != sizeof(rfc))
74582 + break;
74583 +
74584 + memcpy(&rfc, (void *)val, olen);
74585 goto done;
74586 }
74587 }
74588 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
74589 index 5449294..7da9a5f 100644
74590 --- a/net/bridge/netfilter/ebt_ulog.c
74591 +++ b/net/bridge/netfilter/ebt_ulog.c
74592 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
74593 spin_unlock_bh(&ulog_buffers[data].lock);
74594 }
74595
74596 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
74597 static struct sk_buff *ulog_alloc_skb(unsigned int size)
74598 {
74599 struct sk_buff *skb;
74600 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74601 index 5fe2ff3..10968b5 100644
74602 --- a/net/bridge/netfilter/ebtables.c
74603 +++ b/net/bridge/netfilter/ebtables.c
74604 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74605 tmp.valid_hooks = t->table->valid_hooks;
74606 }
74607 mutex_unlock(&ebt_mutex);
74608 - if (copy_to_user(user, &tmp, *len) != 0){
74609 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74610 BUGPRINT("c2u Didn't work\n");
74611 ret = -EFAULT;
74612 break;
74613 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74614 index a97d97a..6f679ed 100644
74615 --- a/net/caif/caif_socket.c
74616 +++ b/net/caif/caif_socket.c
74617 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74618 #ifdef CONFIG_DEBUG_FS
74619 struct debug_fs_counter {
74620 atomic_t caif_nr_socks;
74621 - atomic_t caif_sock_create;
74622 - atomic_t num_connect_req;
74623 - atomic_t num_connect_resp;
74624 - atomic_t num_connect_fail_resp;
74625 - atomic_t num_disconnect;
74626 - atomic_t num_remote_shutdown_ind;
74627 - atomic_t num_tx_flow_off_ind;
74628 - atomic_t num_tx_flow_on_ind;
74629 - atomic_t num_rx_flow_off;
74630 - atomic_t num_rx_flow_on;
74631 + atomic_unchecked_t caif_sock_create;
74632 + atomic_unchecked_t num_connect_req;
74633 + atomic_unchecked_t num_connect_resp;
74634 + atomic_unchecked_t num_connect_fail_resp;
74635 + atomic_unchecked_t num_disconnect;
74636 + atomic_unchecked_t num_remote_shutdown_ind;
74637 + atomic_unchecked_t num_tx_flow_off_ind;
74638 + atomic_unchecked_t num_tx_flow_on_ind;
74639 + atomic_unchecked_t num_rx_flow_off;
74640 + atomic_unchecked_t num_rx_flow_on;
74641 };
74642 static struct debug_fs_counter cnt;
74643 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74644 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74645 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74646 #else
74647 #define dbfs_atomic_inc(v) 0
74648 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74649 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74650 sk_rcvbuf_lowwater(cf_sk));
74651 set_rx_flow_off(cf_sk);
74652 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74653 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74654 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74655 }
74656
74657 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74658 set_rx_flow_off(cf_sk);
74659 if (net_ratelimit())
74660 pr_debug("sending flow OFF due to rmem_schedule\n");
74661 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74662 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74663 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74664 }
74665 skb->dev = NULL;
74666 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74667 switch (flow) {
74668 case CAIF_CTRLCMD_FLOW_ON_IND:
74669 /* OK from modem to start sending again */
74670 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74671 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74672 set_tx_flow_on(cf_sk);
74673 cf_sk->sk.sk_state_change(&cf_sk->sk);
74674 break;
74675
74676 case CAIF_CTRLCMD_FLOW_OFF_IND:
74677 /* Modem asks us to shut up */
74678 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74679 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74680 set_tx_flow_off(cf_sk);
74681 cf_sk->sk.sk_state_change(&cf_sk->sk);
74682 break;
74683 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74684 /* We're now connected */
74685 caif_client_register_refcnt(&cf_sk->layer,
74686 cfsk_hold, cfsk_put);
74687 - dbfs_atomic_inc(&cnt.num_connect_resp);
74688 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74689 cf_sk->sk.sk_state = CAIF_CONNECTED;
74690 set_tx_flow_on(cf_sk);
74691 cf_sk->sk.sk_state_change(&cf_sk->sk);
74692 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74693
74694 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74695 /* Connect request failed */
74696 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74697 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74698 cf_sk->sk.sk_err = ECONNREFUSED;
74699 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74700 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74701 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74702
74703 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74704 /* Modem has closed this connection, or device is down. */
74705 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74706 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74707 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74708 cf_sk->sk.sk_err = ECONNRESET;
74709 set_rx_flow_on(cf_sk);
74710 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74711 return;
74712
74713 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74714 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74715 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74716 set_rx_flow_on(cf_sk);
74717 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74718 }
74719 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74720 /*ifindex = id of the interface.*/
74721 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74722
74723 - dbfs_atomic_inc(&cnt.num_connect_req);
74724 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74725 cf_sk->layer.receive = caif_sktrecv_cb;
74726
74727 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74728 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74729 spin_unlock_bh(&sk->sk_receive_queue.lock);
74730 sock->sk = NULL;
74731
74732 - dbfs_atomic_inc(&cnt.num_disconnect);
74733 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74734
74735 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74736 if (cf_sk->debugfs_socket_dir != NULL)
74737 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74738 cf_sk->conn_req.protocol = protocol;
74739 /* Increase the number of sockets created. */
74740 dbfs_atomic_inc(&cnt.caif_nr_socks);
74741 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74742 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74743 #ifdef CONFIG_DEBUG_FS
74744 if (!IS_ERR(debugfsdir)) {
74745
74746 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74747 index 5cf5222..6f704ad 100644
74748 --- a/net/caif/cfctrl.c
74749 +++ b/net/caif/cfctrl.c
74750 @@ -9,6 +9,7 @@
74751 #include <linux/stddef.h>
74752 #include <linux/spinlock.h>
74753 #include <linux/slab.h>
74754 +#include <linux/sched.h>
74755 #include <net/caif/caif_layer.h>
74756 #include <net/caif/cfpkt.h>
74757 #include <net/caif/cfctrl.h>
74758 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74759 memset(&dev_info, 0, sizeof(dev_info));
74760 dev_info.id = 0xff;
74761 cfsrvl_init(&this->serv, 0, &dev_info, false);
74762 - atomic_set(&this->req_seq_no, 1);
74763 - atomic_set(&this->rsp_seq_no, 1);
74764 + atomic_set_unchecked(&this->req_seq_no, 1);
74765 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74766 this->serv.layer.receive = cfctrl_recv;
74767 sprintf(this->serv.layer.name, "ctrl");
74768 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74769 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74770 struct cfctrl_request_info *req)
74771 {
74772 spin_lock_bh(&ctrl->info_list_lock);
74773 - atomic_inc(&ctrl->req_seq_no);
74774 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74775 + atomic_inc_unchecked(&ctrl->req_seq_no);
74776 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74777 list_add_tail(&req->list, &ctrl->list);
74778 spin_unlock_bh(&ctrl->info_list_lock);
74779 }
74780 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74781 if (p != first)
74782 pr_warn("Requests are not received in order\n");
74783
74784 - atomic_set(&ctrl->rsp_seq_no,
74785 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74786 p->sequence_no);
74787 list_del(&p->list);
74788 goto out;
74789 diff --git a/net/can/gw.c b/net/can/gw.c
74790 index 3d79b12..8de85fa 100644
74791 --- a/net/can/gw.c
74792 +++ b/net/can/gw.c
74793 @@ -96,7 +96,7 @@ struct cf_mod {
74794 struct {
74795 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74796 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74797 - } csumfunc;
74798 + } __no_const csumfunc;
74799 };
74800
74801
74802 diff --git a/net/compat.c b/net/compat.c
74803 index 6def90e..c6992fa 100644
74804 --- a/net/compat.c
74805 +++ b/net/compat.c
74806 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74807 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74808 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74809 return -EFAULT;
74810 - kmsg->msg_name = compat_ptr(tmp1);
74811 - kmsg->msg_iov = compat_ptr(tmp2);
74812 - kmsg->msg_control = compat_ptr(tmp3);
74813 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74814 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74815 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74816 return 0;
74817 }
74818
74819 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74820
74821 if (kern_msg->msg_namelen) {
74822 if (mode == VERIFY_READ) {
74823 - int err = move_addr_to_kernel(kern_msg->msg_name,
74824 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74825 kern_msg->msg_namelen,
74826 kern_address);
74827 if (err < 0)
74828 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74829 kern_msg->msg_name = NULL;
74830
74831 tot_len = iov_from_user_compat_to_kern(kern_iov,
74832 - (struct compat_iovec __user *)kern_msg->msg_iov,
74833 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74834 kern_msg->msg_iovlen);
74835 if (tot_len >= 0)
74836 kern_msg->msg_iov = kern_iov;
74837 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74838
74839 #define CMSG_COMPAT_FIRSTHDR(msg) \
74840 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74841 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74842 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74843 (struct compat_cmsghdr __user *)NULL)
74844
74845 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74846 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74847 (ucmlen) <= (unsigned long) \
74848 ((mhdr)->msg_controllen - \
74849 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74850 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74851
74852 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74853 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74854 {
74855 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74856 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74857 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74858 msg->msg_controllen)
74859 return NULL;
74860 return (struct compat_cmsghdr __user *)ptr;
74861 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74862 {
74863 struct compat_timeval ctv;
74864 struct compat_timespec cts[3];
74865 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74866 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74867 struct compat_cmsghdr cmhdr;
74868 int cmlen;
74869
74870 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74871
74872 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74873 {
74874 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74875 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74876 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74877 int fdnum = scm->fp->count;
74878 struct file **fp = scm->fp->fp;
74879 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74880 return -EFAULT;
74881 old_fs = get_fs();
74882 set_fs(KERNEL_DS);
74883 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74884 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74885 set_fs(old_fs);
74886
74887 return err;
74888 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74889 len = sizeof(ktime);
74890 old_fs = get_fs();
74891 set_fs(KERNEL_DS);
74892 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74893 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74894 set_fs(old_fs);
74895
74896 if (!err) {
74897 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74898 case MCAST_JOIN_GROUP:
74899 case MCAST_LEAVE_GROUP:
74900 {
74901 - struct compat_group_req __user *gr32 = (void *)optval;
74902 + struct compat_group_req __user *gr32 = (void __user *)optval;
74903 struct group_req __user *kgr =
74904 compat_alloc_user_space(sizeof(struct group_req));
74905 u32 interface;
74906 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74907 case MCAST_BLOCK_SOURCE:
74908 case MCAST_UNBLOCK_SOURCE:
74909 {
74910 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74911 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74912 struct group_source_req __user *kgsr = compat_alloc_user_space(
74913 sizeof(struct group_source_req));
74914 u32 interface;
74915 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74916 }
74917 case MCAST_MSFILTER:
74918 {
74919 - struct compat_group_filter __user *gf32 = (void *)optval;
74920 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74921 struct group_filter __user *kgf;
74922 u32 interface, fmode, numsrc;
74923
74924 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74925 char __user *optval, int __user *optlen,
74926 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74927 {
74928 - struct compat_group_filter __user *gf32 = (void *)optval;
74929 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74930 struct group_filter __user *kgf;
74931 int __user *koptlen;
74932 u32 interface, fmode, numsrc;
74933 diff --git a/net/core/datagram.c b/net/core/datagram.c
74934 index 68bbf9f..5ef0d12 100644
74935 --- a/net/core/datagram.c
74936 +++ b/net/core/datagram.c
74937 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74938 }
74939
74940 kfree_skb(skb);
74941 - atomic_inc(&sk->sk_drops);
74942 + atomic_inc_unchecked(&sk->sk_drops);
74943 sk_mem_reclaim_partial(sk);
74944
74945 return err;
74946 diff --git a/net/core/dev.c b/net/core/dev.c
74947 index a4bf943..9c83051 100644
74948 --- a/net/core/dev.c
74949 +++ b/net/core/dev.c
74950 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
74951 if (no_module && capable(CAP_NET_ADMIN))
74952 no_module = request_module("netdev-%s", name);
74953 if (no_module && capable(CAP_SYS_MODULE)) {
74954 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74955 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74956 +#else
74957 if (!request_module("%s", name))
74958 pr_err("Loading kernel module for a network device "
74959 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
74960 "instead\n", name);
74961 +#endif
74962 }
74963 }
74964 EXPORT_SYMBOL(dev_load);
74965 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74966 {
74967 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74968 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74969 - atomic_long_inc(&dev->rx_dropped);
74970 + atomic_long_inc_unchecked(&dev->rx_dropped);
74971 kfree_skb(skb);
74972 return NET_RX_DROP;
74973 }
74974 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74975 nf_reset(skb);
74976
74977 if (unlikely(!is_skb_forwardable(dev, skb))) {
74978 - atomic_long_inc(&dev->rx_dropped);
74979 + atomic_long_inc_unchecked(&dev->rx_dropped);
74980 kfree_skb(skb);
74981 return NET_RX_DROP;
74982 }
74983 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74984
74985 struct dev_gso_cb {
74986 void (*destructor)(struct sk_buff *skb);
74987 -};
74988 +} __no_const;
74989
74990 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74991
74992 @@ -2913,7 +2917,7 @@ enqueue:
74993
74994 local_irq_restore(flags);
74995
74996 - atomic_long_inc(&skb->dev->rx_dropped);
74997 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74998 kfree_skb(skb);
74999 return NET_RX_DROP;
75000 }
75001 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
75002 }
75003 EXPORT_SYMBOL(netif_rx_ni);
75004
75005 -static void net_tx_action(struct softirq_action *h)
75006 +static void net_tx_action(void)
75007 {
75008 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75009
75010 @@ -3273,7 +3277,7 @@ ncls:
75011 if (pt_prev) {
75012 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75013 } else {
75014 - atomic_long_inc(&skb->dev->rx_dropped);
75015 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75016 kfree_skb(skb);
75017 /* Jamal, now you will not able to escape explaining
75018 * me how you were going to use this. :-)
75019 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
75020 }
75021 EXPORT_SYMBOL(netif_napi_del);
75022
75023 -static void net_rx_action(struct softirq_action *h)
75024 +static void net_rx_action(void)
75025 {
75026 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75027 unsigned long time_limit = jiffies + 2;
75028 @@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75029 } else {
75030 netdev_stats_to_stats64(storage, &dev->stats);
75031 }
75032 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75033 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75034 return storage;
75035 }
75036 EXPORT_SYMBOL(dev_get_stats);
75037 diff --git a/net/core/flow.c b/net/core/flow.c
75038 index e318c7e..168b1d0 100644
75039 --- a/net/core/flow.c
75040 +++ b/net/core/flow.c
75041 @@ -61,7 +61,7 @@ struct flow_cache {
75042 struct timer_list rnd_timer;
75043 };
75044
75045 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75046 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75047 EXPORT_SYMBOL(flow_cache_genid);
75048 static struct flow_cache flow_cache_global;
75049 static struct kmem_cache *flow_cachep __read_mostly;
75050 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75051
75052 static int flow_entry_valid(struct flow_cache_entry *fle)
75053 {
75054 - if (atomic_read(&flow_cache_genid) != fle->genid)
75055 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75056 return 0;
75057 if (fle->object && !fle->object->ops->check(fle->object))
75058 return 0;
75059 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75060 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75061 fcp->hash_count++;
75062 }
75063 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75064 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75065 flo = fle->object;
75066 if (!flo)
75067 goto ret_object;
75068 @@ -280,7 +280,7 @@ nocache:
75069 }
75070 flo = resolver(net, key, family, dir, flo, ctx);
75071 if (fle) {
75072 - fle->genid = atomic_read(&flow_cache_genid);
75073 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75074 if (!IS_ERR(flo))
75075 fle->object = flo;
75076 else
75077 diff --git a/net/core/iovec.c b/net/core/iovec.c
75078 index c40f27e..7f49254 100644
75079 --- a/net/core/iovec.c
75080 +++ b/net/core/iovec.c
75081 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75082 if (m->msg_namelen) {
75083 if (mode == VERIFY_READ) {
75084 void __user *namep;
75085 - namep = (void __user __force *) m->msg_name;
75086 + namep = (void __force_user *) m->msg_name;
75087 err = move_addr_to_kernel(namep, m->msg_namelen,
75088 address);
75089 if (err < 0)
75090 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75091 }
75092
75093 size = m->msg_iovlen * sizeof(struct iovec);
75094 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75095 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75096 return -EFAULT;
75097
75098 m->msg_iov = iov;
75099 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75100 index 5c30296..ebe7b61 100644
75101 --- a/net/core/rtnetlink.c
75102 +++ b/net/core/rtnetlink.c
75103 @@ -57,7 +57,7 @@ struct rtnl_link {
75104 rtnl_doit_func doit;
75105 rtnl_dumpit_func dumpit;
75106 rtnl_calcit_func calcit;
75107 -};
75108 +} __no_const;
75109
75110 static DEFINE_MUTEX(rtnl_mutex);
75111
75112 diff --git a/net/core/scm.c b/net/core/scm.c
75113 index ff52ad0..aff1c0f 100644
75114 --- a/net/core/scm.c
75115 +++ b/net/core/scm.c
75116 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75117 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75118 {
75119 struct cmsghdr __user *cm
75120 - = (__force struct cmsghdr __user *)msg->msg_control;
75121 + = (struct cmsghdr __force_user *)msg->msg_control;
75122 struct cmsghdr cmhdr;
75123 int cmlen = CMSG_LEN(len);
75124 int err;
75125 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75126 err = -EFAULT;
75127 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75128 goto out;
75129 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75130 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75131 goto out;
75132 cmlen = CMSG_SPACE(len);
75133 if (msg->msg_controllen < cmlen)
75134 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75135 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75136 {
75137 struct cmsghdr __user *cm
75138 - = (__force struct cmsghdr __user*)msg->msg_control;
75139 + = (struct cmsghdr __force_user *)msg->msg_control;
75140
75141 int fdmax = 0;
75142 int fdnum = scm->fp->count;
75143 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75144 if (fdnum < fdmax)
75145 fdmax = fdnum;
75146
75147 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75148 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75149 i++, cmfptr++)
75150 {
75151 int new_fd;
75152 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75153 index da0c97f..8253632 100644
75154 --- a/net/core/skbuff.c
75155 +++ b/net/core/skbuff.c
75156 @@ -3160,6 +3160,8 @@ static void sock_rmem_free(struct sk_buff *skb)
75157 */
75158 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75159 {
75160 + int len = skb->len;
75161 +
75162 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75163 (unsigned)sk->sk_rcvbuf)
75164 return -ENOMEM;
75165 @@ -3174,7 +3176,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75166
75167 skb_queue_tail(&sk->sk_error_queue, skb);
75168 if (!sock_flag(sk, SOCK_DEAD))
75169 - sk->sk_data_ready(sk, skb->len);
75170 + sk->sk_data_ready(sk, len);
75171 return 0;
75172 }
75173 EXPORT_SYMBOL(sock_queue_err_skb);
75174 diff --git a/net/core/sock.c b/net/core/sock.c
75175 index 02f8dfe..86dfd4a 100644
75176 --- a/net/core/sock.c
75177 +++ b/net/core/sock.c
75178 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75179 struct sk_buff_head *list = &sk->sk_receive_queue;
75180
75181 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75182 - atomic_inc(&sk->sk_drops);
75183 + atomic_inc_unchecked(&sk->sk_drops);
75184 trace_sock_rcvqueue_full(sk, skb);
75185 return -ENOMEM;
75186 }
75187 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75188 return err;
75189
75190 if (!sk_rmem_schedule(sk, skb->truesize)) {
75191 - atomic_inc(&sk->sk_drops);
75192 + atomic_inc_unchecked(&sk->sk_drops);
75193 return -ENOBUFS;
75194 }
75195
75196 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75197 skb_dst_force(skb);
75198
75199 spin_lock_irqsave(&list->lock, flags);
75200 - skb->dropcount = atomic_read(&sk->sk_drops);
75201 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75202 __skb_queue_tail(list, skb);
75203 spin_unlock_irqrestore(&list->lock, flags);
75204
75205 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75206 skb->dev = NULL;
75207
75208 if (sk_rcvqueues_full(sk, skb)) {
75209 - atomic_inc(&sk->sk_drops);
75210 + atomic_inc_unchecked(&sk->sk_drops);
75211 goto discard_and_relse;
75212 }
75213 if (nested)
75214 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75215 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75216 } else if (sk_add_backlog(sk, skb)) {
75217 bh_unlock_sock(sk);
75218 - atomic_inc(&sk->sk_drops);
75219 + atomic_inc_unchecked(&sk->sk_drops);
75220 goto discard_and_relse;
75221 }
75222
75223 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75224 if (len > sizeof(peercred))
75225 len = sizeof(peercred);
75226 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75227 - if (copy_to_user(optval, &peercred, len))
75228 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75229 return -EFAULT;
75230 goto lenout;
75231 }
75232 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75233 return -ENOTCONN;
75234 if (lv < len)
75235 return -EINVAL;
75236 - if (copy_to_user(optval, address, len))
75237 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75238 return -EFAULT;
75239 goto lenout;
75240 }
75241 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75242
75243 if (len > lv)
75244 len = lv;
75245 - if (copy_to_user(optval, &v, len))
75246 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75247 return -EFAULT;
75248 lenout:
75249 if (put_user(len, optlen))
75250 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75251 */
75252 smp_wmb();
75253 atomic_set(&sk->sk_refcnt, 1);
75254 - atomic_set(&sk->sk_drops, 0);
75255 + atomic_set_unchecked(&sk->sk_drops, 0);
75256 }
75257 EXPORT_SYMBOL(sock_init_data);
75258
75259 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75260 index b9868e1..849f809 100644
75261 --- a/net/core/sock_diag.c
75262 +++ b/net/core/sock_diag.c
75263 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75264
75265 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75266 {
75267 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75268 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75269 cookie[1] != INET_DIAG_NOCOOKIE) &&
75270 ((u32)(unsigned long)sk != cookie[0] ||
75271 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75272 return -ESTALE;
75273 else
75274 +#endif
75275 return 0;
75276 }
75277 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75278
75279 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75280 {
75281 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75282 + cookie[0] = 0;
75283 + cookie[1] = 0;
75284 +#else
75285 cookie[0] = (u32)(unsigned long)sk;
75286 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75287 +#endif
75288 }
75289 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75290
75291 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75292 index 02e75d1..9a57a7c 100644
75293 --- a/net/decnet/sysctl_net_decnet.c
75294 +++ b/net/decnet/sysctl_net_decnet.c
75295 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75296
75297 if (len > *lenp) len = *lenp;
75298
75299 - if (copy_to_user(buffer, addr, len))
75300 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75301 return -EFAULT;
75302
75303 *lenp = len;
75304 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75305
75306 if (len > *lenp) len = *lenp;
75307
75308 - if (copy_to_user(buffer, devname, len))
75309 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75310 return -EFAULT;
75311
75312 *lenp = len;
75313 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75314 index 39a2d29..f39c0fe 100644
75315 --- a/net/econet/Kconfig
75316 +++ b/net/econet/Kconfig
75317 @@ -4,7 +4,7 @@
75318
75319 config ECONET
75320 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75321 - depends on EXPERIMENTAL && INET
75322 + depends on EXPERIMENTAL && INET && BROKEN
75323 ---help---
75324 Econet is a fairly old and slow networking protocol mainly used by
75325 Acorn computers to access file and print servers. It uses native
75326 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75327 index 36d1440..44ff28b 100644
75328 --- a/net/ipv4/ah4.c
75329 +++ b/net/ipv4/ah4.c
75330 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75331 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75332
75333 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75334 + unsigned int size) __size_overflow(3);
75335 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75336 unsigned int size)
75337 {
75338 unsigned int len;
75339 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75340 index 92fc5f6..b790d91 100644
75341 --- a/net/ipv4/fib_frontend.c
75342 +++ b/net/ipv4/fib_frontend.c
75343 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75344 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75345 fib_sync_up(dev);
75346 #endif
75347 - atomic_inc(&net->ipv4.dev_addr_genid);
75348 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75349 rt_cache_flush(dev_net(dev), -1);
75350 break;
75351 case NETDEV_DOWN:
75352 fib_del_ifaddr(ifa, NULL);
75353 - atomic_inc(&net->ipv4.dev_addr_genid);
75354 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75355 if (ifa->ifa_dev->ifa_list == NULL) {
75356 /* Last address was deleted from this interface.
75357 * Disable IP.
75358 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75359 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75360 fib_sync_up(dev);
75361 #endif
75362 - atomic_inc(&net->ipv4.dev_addr_genid);
75363 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75364 rt_cache_flush(dev_net(dev), -1);
75365 break;
75366 case NETDEV_DOWN:
75367 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75368 index 80106d8..232e898 100644
75369 --- a/net/ipv4/fib_semantics.c
75370 +++ b/net/ipv4/fib_semantics.c
75371 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75372 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75373 nh->nh_gw,
75374 nh->nh_parent->fib_scope);
75375 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75376 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75377
75378 return nh->nh_saddr;
75379 }
75380 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75381 index 984ec65..97ac518 100644
75382 --- a/net/ipv4/inet_hashtables.c
75383 +++ b/net/ipv4/inet_hashtables.c
75384 @@ -18,12 +18,15 @@
75385 #include <linux/sched.h>
75386 #include <linux/slab.h>
75387 #include <linux/wait.h>
75388 +#include <linux/security.h>
75389
75390 #include <net/inet_connection_sock.h>
75391 #include <net/inet_hashtables.h>
75392 #include <net/secure_seq.h>
75393 #include <net/ip.h>
75394
75395 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75396 +
75397 /*
75398 * Allocate and initialize a new local port bind bucket.
75399 * The bindhash mutex for snum's hash chain must be held here.
75400 @@ -530,6 +533,8 @@ ok:
75401 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75402 spin_unlock(&head->lock);
75403
75404 + gr_update_task_in_ip_table(current, inet_sk(sk));
75405 +
75406 if (tw) {
75407 inet_twsk_deschedule(tw, death_row);
75408 while (twrefcnt) {
75409 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75410 index d4d61b6..b81aec8 100644
75411 --- a/net/ipv4/inetpeer.c
75412 +++ b/net/ipv4/inetpeer.c
75413 @@ -487,8 +487,8 @@ relookup:
75414 if (p) {
75415 p->daddr = *daddr;
75416 atomic_set(&p->refcnt, 1);
75417 - atomic_set(&p->rid, 0);
75418 - atomic_set(&p->ip_id_count,
75419 + atomic_set_unchecked(&p->rid, 0);
75420 + atomic_set_unchecked(&p->ip_id_count,
75421 (daddr->family == AF_INET) ?
75422 secure_ip_id(daddr->addr.a4) :
75423 secure_ipv6_id(daddr->addr.a6));
75424 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75425 index 1f23a57..7180dfe 100644
75426 --- a/net/ipv4/ip_fragment.c
75427 +++ b/net/ipv4/ip_fragment.c
75428 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75429 return 0;
75430
75431 start = qp->rid;
75432 - end = atomic_inc_return(&peer->rid);
75433 + end = atomic_inc_return_unchecked(&peer->rid);
75434 qp->rid = end;
75435
75436 rc = qp->q.fragments && (end - start) > max;
75437 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75438 index 8aa87c1..35c3248 100644
75439 --- a/net/ipv4/ip_sockglue.c
75440 +++ b/net/ipv4/ip_sockglue.c
75441 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75442 len = min_t(unsigned int, len, opt->optlen);
75443 if (put_user(len, optlen))
75444 return -EFAULT;
75445 - if (copy_to_user(optval, opt->__data, len))
75446 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75447 + copy_to_user(optval, opt->__data, len))
75448 return -EFAULT;
75449 return 0;
75450 }
75451 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75452 if (sk->sk_type != SOCK_STREAM)
75453 return -ENOPROTOOPT;
75454
75455 - msg.msg_control = optval;
75456 + msg.msg_control = (void __force_kernel *)optval;
75457 msg.msg_controllen = len;
75458 msg.msg_flags = flags;
75459
75460 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75461 index 6e412a6..6640538 100644
75462 --- a/net/ipv4/ipconfig.c
75463 +++ b/net/ipv4/ipconfig.c
75464 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75465
75466 mm_segment_t oldfs = get_fs();
75467 set_fs(get_ds());
75468 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75469 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75470 set_fs(oldfs);
75471 return res;
75472 }
75473 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75474
75475 mm_segment_t oldfs = get_fs();
75476 set_fs(get_ds());
75477 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75478 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75479 set_fs(oldfs);
75480 return res;
75481 }
75482 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75483
75484 mm_segment_t oldfs = get_fs();
75485 set_fs(get_ds());
75486 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75487 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75488 set_fs(oldfs);
75489 return res;
75490 }
75491 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
75492 index fd7a3f6..a1b1013 100644
75493 --- a/net/ipv4/netfilter/arp_tables.c
75494 +++ b/net/ipv4/netfilter/arp_tables.c
75495 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75496
75497 static int copy_entries_to_user(unsigned int total_size,
75498 const struct xt_table *table,
75499 + void __user *userptr) __size_overflow(1);
75500 +static int copy_entries_to_user(unsigned int total_size,
75501 + const struct xt_table *table,
75502 void __user *userptr)
75503 {
75504 unsigned int off, num;
75505 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
75506 unsigned int valid_hooks,
75507 struct xt_table_info *newinfo,
75508 unsigned int num_counters,
75509 + void __user *counters_ptr) __size_overflow(5);
75510 +static int __do_replace(struct net *net, const char *name,
75511 + unsigned int valid_hooks,
75512 + struct xt_table_info *newinfo,
75513 + unsigned int num_counters,
75514 void __user *counters_ptr)
75515 {
75516 int ret;
75517 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
75518 }
75519
75520 static int do_add_counters(struct net *net, const void __user *user,
75521 + unsigned int len, int compat) __size_overflow(3);
75522 +static int do_add_counters(struct net *net, const void __user *user,
75523 unsigned int len, int compat)
75524 {
75525 unsigned int i, curcpu;
75526 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
75527 index 24e556e..b073356 100644
75528 --- a/net/ipv4/netfilter/ip_tables.c
75529 +++ b/net/ipv4/netfilter/ip_tables.c
75530 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75531 static int
75532 copy_entries_to_user(unsigned int total_size,
75533 const struct xt_table *table,
75534 + void __user *userptr) __size_overflow(1);
75535 +static int
75536 +copy_entries_to_user(unsigned int total_size,
75537 + const struct xt_table *table,
75538 void __user *userptr)
75539 {
75540 unsigned int off, num;
75541 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
75542 static int
75543 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75544 struct xt_table_info *newinfo, unsigned int num_counters,
75545 + void __user *counters_ptr) __size_overflow(5);
75546 +static int
75547 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75548 + struct xt_table_info *newinfo, unsigned int num_counters,
75549 void __user *counters_ptr)
75550 {
75551 int ret;
75552 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
75553
75554 static int
75555 do_add_counters(struct net *net, const void __user *user,
75556 + unsigned int len, int compat) __size_overflow(3);
75557 +static int
75558 +do_add_counters(struct net *net, const void __user *user,
75559 unsigned int len, int compat)
75560 {
75561 unsigned int i, curcpu;
75562 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
75563 index ba5756d..8d34d74 100644
75564 --- a/net/ipv4/netfilter/ipt_ULOG.c
75565 +++ b/net/ipv4/netfilter/ipt_ULOG.c
75566 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
75567 spin_unlock_bh(&ulog_lock);
75568 }
75569
75570 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75571 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75572 {
75573 struct sk_buff *skb;
75574 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75575 index 2133c30..0e8047e 100644
75576 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75577 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75578 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
75579 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75580 unsigned char *eoc,
75581 unsigned long **oid,
75582 + unsigned int *len) __size_overflow(2);
75583 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75584 + unsigned char *eoc,
75585 + unsigned long **oid,
75586 unsigned int *len)
75587 {
75588 unsigned long subid;
75589 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75590 index b072386..abdebcf 100644
75591 --- a/net/ipv4/ping.c
75592 +++ b/net/ipv4/ping.c
75593 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75594 sk_rmem_alloc_get(sp),
75595 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75596 atomic_read(&sp->sk_refcnt), sp,
75597 - atomic_read(&sp->sk_drops), len);
75598 + atomic_read_unchecked(&sp->sk_drops), len);
75599 }
75600
75601 static int ping_seq_show(struct seq_file *seq, void *v)
75602 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75603 index 3ccda5a..3c1e61d 100644
75604 --- a/net/ipv4/raw.c
75605 +++ b/net/ipv4/raw.c
75606 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75607 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75608 {
75609 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75610 - atomic_inc(&sk->sk_drops);
75611 + atomic_inc_unchecked(&sk->sk_drops);
75612 kfree_skb(skb);
75613 return NET_RX_DROP;
75614 }
75615 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75616
75617 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75618 {
75619 + struct icmp_filter filter;
75620 +
75621 if (optlen > sizeof(struct icmp_filter))
75622 optlen = sizeof(struct icmp_filter);
75623 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75624 + if (copy_from_user(&filter, optval, optlen))
75625 return -EFAULT;
75626 + raw_sk(sk)->filter = filter;
75627 return 0;
75628 }
75629
75630 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75631 {
75632 int len, ret = -EFAULT;
75633 + struct icmp_filter filter;
75634
75635 if (get_user(len, optlen))
75636 goto out;
75637 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75638 if (len > sizeof(struct icmp_filter))
75639 len = sizeof(struct icmp_filter);
75640 ret = -EFAULT;
75641 - if (put_user(len, optlen) ||
75642 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75643 + filter = raw_sk(sk)->filter;
75644 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75645 goto out;
75646 ret = 0;
75647 out: return ret;
75648 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75649 sk_wmem_alloc_get(sp),
75650 sk_rmem_alloc_get(sp),
75651 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75652 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75653 + atomic_read(&sp->sk_refcnt),
75654 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75655 + NULL,
75656 +#else
75657 + sp,
75658 +#endif
75659 + atomic_read_unchecked(&sp->sk_drops));
75660 }
75661
75662 static int raw_seq_show(struct seq_file *seq, void *v)
75663 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75664 index 0197747..7adb0dc 100644
75665 --- a/net/ipv4/route.c
75666 +++ b/net/ipv4/route.c
75667 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75668
75669 static inline int rt_genid(struct net *net)
75670 {
75671 - return atomic_read(&net->ipv4.rt_genid);
75672 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75673 }
75674
75675 #ifdef CONFIG_PROC_FS
75676 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75677 unsigned char shuffle;
75678
75679 get_random_bytes(&shuffle, sizeof(shuffle));
75680 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75681 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75682 inetpeer_invalidate_tree(AF_INET);
75683 }
75684
75685 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75686 error = rt->dst.error;
75687 if (peer) {
75688 inet_peer_refcheck(rt->peer);
75689 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75690 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75691 if (peer->tcp_ts_stamp) {
75692 ts = peer->tcp_ts;
75693 tsage = get_seconds() - peer->tcp_ts_stamp;
75694 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75695 index fd54c5f..96d6407 100644
75696 --- a/net/ipv4/tcp_ipv4.c
75697 +++ b/net/ipv4/tcp_ipv4.c
75698 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75699 int sysctl_tcp_low_latency __read_mostly;
75700 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75701
75702 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75703 +extern int grsec_enable_blackhole;
75704 +#endif
75705
75706 #ifdef CONFIG_TCP_MD5SIG
75707 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75708 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75709 return 0;
75710
75711 reset:
75712 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75713 + if (!grsec_enable_blackhole)
75714 +#endif
75715 tcp_v4_send_reset(rsk, skb);
75716 discard:
75717 kfree_skb(skb);
75718 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75719 TCP_SKB_CB(skb)->sacked = 0;
75720
75721 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75722 - if (!sk)
75723 + if (!sk) {
75724 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75725 + ret = 1;
75726 +#endif
75727 goto no_tcp_socket;
75728 -
75729 + }
75730 process:
75731 - if (sk->sk_state == TCP_TIME_WAIT)
75732 + if (sk->sk_state == TCP_TIME_WAIT) {
75733 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75734 + ret = 2;
75735 +#endif
75736 goto do_time_wait;
75737 + }
75738
75739 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75740 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75741 @@ -1755,6 +1768,10 @@ no_tcp_socket:
75742 bad_packet:
75743 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75744 } else {
75745 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75746 + if (!grsec_enable_blackhole || (ret == 1 &&
75747 + (skb->dev->flags & IFF_LOOPBACK)))
75748 +#endif
75749 tcp_v4_send_reset(NULL, skb);
75750 }
75751
75752 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75753 0, /* non standard timer */
75754 0, /* open_requests have no inode */
75755 atomic_read(&sk->sk_refcnt),
75756 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75757 + NULL,
75758 +#else
75759 req,
75760 +#endif
75761 len);
75762 }
75763
75764 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75765 sock_i_uid(sk),
75766 icsk->icsk_probes_out,
75767 sock_i_ino(sk),
75768 - atomic_read(&sk->sk_refcnt), sk,
75769 + atomic_read(&sk->sk_refcnt),
75770 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75771 + NULL,
75772 +#else
75773 + sk,
75774 +#endif
75775 jiffies_to_clock_t(icsk->icsk_rto),
75776 jiffies_to_clock_t(icsk->icsk_ack.ato),
75777 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75778 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75779 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75780 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75781 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75782 - atomic_read(&tw->tw_refcnt), tw, len);
75783 + atomic_read(&tw->tw_refcnt),
75784 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75785 + NULL,
75786 +#else
75787 + tw,
75788 +#endif
75789 + len);
75790 }
75791
75792 #define TMPSZ 150
75793 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75794 index 550e755..25721b3 100644
75795 --- a/net/ipv4/tcp_minisocks.c
75796 +++ b/net/ipv4/tcp_minisocks.c
75797 @@ -27,6 +27,10 @@
75798 #include <net/inet_common.h>
75799 #include <net/xfrm.h>
75800
75801 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75802 +extern int grsec_enable_blackhole;
75803 +#endif
75804 +
75805 int sysctl_tcp_syncookies __read_mostly = 1;
75806 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75807
75808 @@ -753,6 +757,10 @@ listen_overflow:
75809
75810 embryonic_reset:
75811 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75812 +
75813 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75814 + if (!grsec_enable_blackhole)
75815 +#endif
75816 if (!(flg & TCP_FLAG_RST))
75817 req->rsk_ops->send_reset(sk, skb);
75818
75819 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75820 index 85ee7eb..53277ab 100644
75821 --- a/net/ipv4/tcp_probe.c
75822 +++ b/net/ipv4/tcp_probe.c
75823 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75824 if (cnt + width >= len)
75825 break;
75826
75827 - if (copy_to_user(buf + cnt, tbuf, width))
75828 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75829 return -EFAULT;
75830 cnt += width;
75831 }
75832 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75833 index cd2e072..1fffee2 100644
75834 --- a/net/ipv4/tcp_timer.c
75835 +++ b/net/ipv4/tcp_timer.c
75836 @@ -22,6 +22,10 @@
75837 #include <linux/gfp.h>
75838 #include <net/tcp.h>
75839
75840 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75841 +extern int grsec_lastack_retries;
75842 +#endif
75843 +
75844 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75845 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75846 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75847 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75848 }
75849 }
75850
75851 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75852 + if ((sk->sk_state == TCP_LAST_ACK) &&
75853 + (grsec_lastack_retries > 0) &&
75854 + (grsec_lastack_retries < retry_until))
75855 + retry_until = grsec_lastack_retries;
75856 +#endif
75857 +
75858 if (retransmits_timed_out(sk, retry_until,
75859 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75860 /* Has it gone just too far? */
75861 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75862 index 5d075b5..d907d5f 100644
75863 --- a/net/ipv4/udp.c
75864 +++ b/net/ipv4/udp.c
75865 @@ -86,6 +86,7 @@
75866 #include <linux/types.h>
75867 #include <linux/fcntl.h>
75868 #include <linux/module.h>
75869 +#include <linux/security.h>
75870 #include <linux/socket.h>
75871 #include <linux/sockios.h>
75872 #include <linux/igmp.h>
75873 @@ -108,6 +109,10 @@
75874 #include <trace/events/udp.h>
75875 #include "udp_impl.h"
75876
75877 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75878 +extern int grsec_enable_blackhole;
75879 +#endif
75880 +
75881 struct udp_table udp_table __read_mostly;
75882 EXPORT_SYMBOL(udp_table);
75883
75884 @@ -566,6 +571,9 @@ found:
75885 return s;
75886 }
75887
75888 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75889 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75890 +
75891 /*
75892 * This routine is called by the ICMP module when it gets some
75893 * sort of error condition. If err < 0 then the socket should
75894 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75895 dport = usin->sin_port;
75896 if (dport == 0)
75897 return -EINVAL;
75898 +
75899 + err = gr_search_udp_sendmsg(sk, usin);
75900 + if (err)
75901 + return err;
75902 } else {
75903 if (sk->sk_state != TCP_ESTABLISHED)
75904 return -EDESTADDRREQ;
75905 +
75906 + err = gr_search_udp_sendmsg(sk, NULL);
75907 + if (err)
75908 + return err;
75909 +
75910 daddr = inet->inet_daddr;
75911 dport = inet->inet_dport;
75912 /* Open fast path for connected socket.
75913 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75914 udp_lib_checksum_complete(skb)) {
75915 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75916 IS_UDPLITE(sk));
75917 - atomic_inc(&sk->sk_drops);
75918 + atomic_inc_unchecked(&sk->sk_drops);
75919 __skb_unlink(skb, rcvq);
75920 __skb_queue_tail(&list_kill, skb);
75921 }
75922 @@ -1186,6 +1203,10 @@ try_again:
75923 if (!skb)
75924 goto out;
75925
75926 + err = gr_search_udp_recvmsg(sk, skb);
75927 + if (err)
75928 + goto out_free;
75929 +
75930 ulen = skb->len - sizeof(struct udphdr);
75931 copied = len;
75932 if (copied > ulen)
75933 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75934
75935 drop:
75936 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75937 - atomic_inc(&sk->sk_drops);
75938 + atomic_inc_unchecked(&sk->sk_drops);
75939 kfree_skb(skb);
75940 return -1;
75941 }
75942 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75943 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75944
75945 if (!skb1) {
75946 - atomic_inc(&sk->sk_drops);
75947 + atomic_inc_unchecked(&sk->sk_drops);
75948 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75949 IS_UDPLITE(sk));
75950 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75951 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75952 goto csum_error;
75953
75954 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75955 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75956 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75957 +#endif
75958 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75959
75960 /*
75961 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75962 sk_wmem_alloc_get(sp),
75963 sk_rmem_alloc_get(sp),
75964 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75965 - atomic_read(&sp->sk_refcnt), sp,
75966 - atomic_read(&sp->sk_drops), len);
75967 + atomic_read(&sp->sk_refcnt),
75968 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75969 + NULL,
75970 +#else
75971 + sp,
75972 +#endif
75973 + atomic_read_unchecked(&sp->sk_drops), len);
75974 }
75975
75976 int udp4_seq_show(struct seq_file *seq, void *v)
75977 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75978 index 6b8ebc5..1d624f4 100644
75979 --- a/net/ipv6/addrconf.c
75980 +++ b/net/ipv6/addrconf.c
75981 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75982 p.iph.ihl = 5;
75983 p.iph.protocol = IPPROTO_IPV6;
75984 p.iph.ttl = 64;
75985 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75986 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75987
75988 if (ops->ndo_do_ioctl) {
75989 mm_segment_t oldfs = get_fs();
75990 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
75991 index 2ae79db..8f101bf 100644
75992 --- a/net/ipv6/ah6.c
75993 +++ b/net/ipv6/ah6.c
75994 @@ -56,6 +56,8 @@ struct ah_skb_cb {
75995 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75996
75997 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75998 + unsigned int size) __size_overflow(3);
75999 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76000 unsigned int size)
76001 {
76002 unsigned int len;
76003 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76004 index 02dd203..e03fcc9 100644
76005 --- a/net/ipv6/inet6_connection_sock.c
76006 +++ b/net/ipv6/inet6_connection_sock.c
76007 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76008 #ifdef CONFIG_XFRM
76009 {
76010 struct rt6_info *rt = (struct rt6_info *)dst;
76011 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76012 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76013 }
76014 #endif
76015 }
76016 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76017 #ifdef CONFIG_XFRM
76018 if (dst) {
76019 struct rt6_info *rt = (struct rt6_info *)dst;
76020 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76021 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76022 __sk_dst_reset(sk);
76023 dst = NULL;
76024 }
76025 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76026 index 18a2719..779f36a 100644
76027 --- a/net/ipv6/ipv6_sockglue.c
76028 +++ b/net/ipv6/ipv6_sockglue.c
76029 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76030 if (sk->sk_type != SOCK_STREAM)
76031 return -ENOPROTOOPT;
76032
76033 - msg.msg_control = optval;
76034 + msg.msg_control = (void __force_kernel *)optval;
76035 msg.msg_controllen = len;
76036 msg.msg_flags = flags;
76037
76038 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76039 index 94874b0..108a94d 100644
76040 --- a/net/ipv6/netfilter/ip6_tables.c
76041 +++ b/net/ipv6/netfilter/ip6_tables.c
76042 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76043 static int
76044 copy_entries_to_user(unsigned int total_size,
76045 const struct xt_table *table,
76046 + void __user *userptr) __size_overflow(1);
76047 +static int
76048 +copy_entries_to_user(unsigned int total_size,
76049 + const struct xt_table *table,
76050 void __user *userptr)
76051 {
76052 unsigned int off, num;
76053 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76054 static int
76055 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76056 struct xt_table_info *newinfo, unsigned int num_counters,
76057 + void __user *counters_ptr) __size_overflow(5);
76058 +static int
76059 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76060 + struct xt_table_info *newinfo, unsigned int num_counters,
76061 void __user *counters_ptr)
76062 {
76063 int ret;
76064 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76065
76066 static int
76067 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76068 + int compat) __size_overflow(3);
76069 +static int
76070 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76071 int compat)
76072 {
76073 unsigned int i, curcpu;
76074 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76075 index d02f7e4..2d2a0f1 100644
76076 --- a/net/ipv6/raw.c
76077 +++ b/net/ipv6/raw.c
76078 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76079 {
76080 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76081 skb_checksum_complete(skb)) {
76082 - atomic_inc(&sk->sk_drops);
76083 + atomic_inc_unchecked(&sk->sk_drops);
76084 kfree_skb(skb);
76085 return NET_RX_DROP;
76086 }
76087 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76088 struct raw6_sock *rp = raw6_sk(sk);
76089
76090 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76091 - atomic_inc(&sk->sk_drops);
76092 + atomic_inc_unchecked(&sk->sk_drops);
76093 kfree_skb(skb);
76094 return NET_RX_DROP;
76095 }
76096 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76097
76098 if (inet->hdrincl) {
76099 if (skb_checksum_complete(skb)) {
76100 - atomic_inc(&sk->sk_drops);
76101 + atomic_inc_unchecked(&sk->sk_drops);
76102 kfree_skb(skb);
76103 return NET_RX_DROP;
76104 }
76105 @@ -602,7 +602,7 @@ out:
76106 return err;
76107 }
76108
76109 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76110 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76111 struct flowi6 *fl6, struct dst_entry **dstp,
76112 unsigned int flags)
76113 {
76114 @@ -912,12 +912,15 @@ do_confirm:
76115 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76116 char __user *optval, int optlen)
76117 {
76118 + struct icmp6_filter filter;
76119 +
76120 switch (optname) {
76121 case ICMPV6_FILTER:
76122 if (optlen > sizeof(struct icmp6_filter))
76123 optlen = sizeof(struct icmp6_filter);
76124 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76125 + if (copy_from_user(&filter, optval, optlen))
76126 return -EFAULT;
76127 + raw6_sk(sk)->filter = filter;
76128 return 0;
76129 default:
76130 return -ENOPROTOOPT;
76131 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76132 char __user *optval, int __user *optlen)
76133 {
76134 int len;
76135 + struct icmp6_filter filter;
76136
76137 switch (optname) {
76138 case ICMPV6_FILTER:
76139 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76140 len = sizeof(struct icmp6_filter);
76141 if (put_user(len, optlen))
76142 return -EFAULT;
76143 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76144 + filter = raw6_sk(sk)->filter;
76145 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76146 return -EFAULT;
76147 return 0;
76148 default:
76149 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76150 0, 0L, 0,
76151 sock_i_uid(sp), 0,
76152 sock_i_ino(sp),
76153 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76154 + atomic_read(&sp->sk_refcnt),
76155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76156 + NULL,
76157 +#else
76158 + sp,
76159 +#endif
76160 + atomic_read_unchecked(&sp->sk_drops));
76161 }
76162
76163 static int raw6_seq_show(struct seq_file *seq, void *v)
76164 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76165 index 3edd05a..63aad01 100644
76166 --- a/net/ipv6/tcp_ipv6.c
76167 +++ b/net/ipv6/tcp_ipv6.c
76168 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76169 }
76170 #endif
76171
76172 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76173 +extern int grsec_enable_blackhole;
76174 +#endif
76175 +
76176 static void tcp_v6_hash(struct sock *sk)
76177 {
76178 if (sk->sk_state != TCP_CLOSE) {
76179 @@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76180 return 0;
76181
76182 reset:
76183 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76184 + if (!grsec_enable_blackhole)
76185 +#endif
76186 tcp_v6_send_reset(sk, skb);
76187 discard:
76188 if (opt_skb)
76189 @@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76190 TCP_SKB_CB(skb)->sacked = 0;
76191
76192 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76193 - if (!sk)
76194 + if (!sk) {
76195 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76196 + ret = 1;
76197 +#endif
76198 goto no_tcp_socket;
76199 + }
76200
76201 process:
76202 - if (sk->sk_state == TCP_TIME_WAIT)
76203 + if (sk->sk_state == TCP_TIME_WAIT) {
76204 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76205 + ret = 2;
76206 +#endif
76207 goto do_time_wait;
76208 + }
76209
76210 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76211 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76212 @@ -1782,6 +1797,10 @@ no_tcp_socket:
76213 bad_packet:
76214 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76215 } else {
76216 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76217 + if (!grsec_enable_blackhole || (ret == 1 &&
76218 + (skb->dev->flags & IFF_LOOPBACK)))
76219 +#endif
76220 tcp_v6_send_reset(NULL, skb);
76221 }
76222
76223 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
76224 uid,
76225 0, /* non standard timer */
76226 0, /* open_requests have no inode */
76227 - 0, req);
76228 + 0,
76229 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76230 + NULL
76231 +#else
76232 + req
76233 +#endif
76234 + );
76235 }
76236
76237 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76238 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76239 sock_i_uid(sp),
76240 icsk->icsk_probes_out,
76241 sock_i_ino(sp),
76242 - atomic_read(&sp->sk_refcnt), sp,
76243 + atomic_read(&sp->sk_refcnt),
76244 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76245 + NULL,
76246 +#else
76247 + sp,
76248 +#endif
76249 jiffies_to_clock_t(icsk->icsk_rto),
76250 jiffies_to_clock_t(icsk->icsk_ack.ato),
76251 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76252 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76253 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76254 tw->tw_substate, 0, 0,
76255 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76256 - atomic_read(&tw->tw_refcnt), tw);
76257 + atomic_read(&tw->tw_refcnt),
76258 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76259 + NULL
76260 +#else
76261 + tw
76262 +#endif
76263 + );
76264 }
76265
76266 static int tcp6_seq_show(struct seq_file *seq, void *v)
76267 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76268 index 4f96b5c..75543d7 100644
76269 --- a/net/ipv6/udp.c
76270 +++ b/net/ipv6/udp.c
76271 @@ -50,6 +50,10 @@
76272 #include <linux/seq_file.h>
76273 #include "udp_impl.h"
76274
76275 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76276 +extern int grsec_enable_blackhole;
76277 +#endif
76278 +
76279 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76280 {
76281 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76282 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76283
76284 return 0;
76285 drop:
76286 - atomic_inc(&sk->sk_drops);
76287 + atomic_inc_unchecked(&sk->sk_drops);
76288 drop_no_sk_drops_inc:
76289 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76290 kfree_skb(skb);
76291 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76292 continue;
76293 }
76294 drop:
76295 - atomic_inc(&sk->sk_drops);
76296 + atomic_inc_unchecked(&sk->sk_drops);
76297 UDP6_INC_STATS_BH(sock_net(sk),
76298 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76299 UDP6_INC_STATS_BH(sock_net(sk),
76300 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76301 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76302 proto == IPPROTO_UDPLITE);
76303
76304 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76305 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76306 +#endif
76307 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76308
76309 kfree_skb(skb);
76310 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76311 if (!sock_owned_by_user(sk))
76312 udpv6_queue_rcv_skb(sk, skb);
76313 else if (sk_add_backlog(sk, skb)) {
76314 - atomic_inc(&sk->sk_drops);
76315 + atomic_inc_unchecked(&sk->sk_drops);
76316 bh_unlock_sock(sk);
76317 sock_put(sk);
76318 goto discard;
76319 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76320 0, 0L, 0,
76321 sock_i_uid(sp), 0,
76322 sock_i_ino(sp),
76323 - atomic_read(&sp->sk_refcnt), sp,
76324 - atomic_read(&sp->sk_drops));
76325 + atomic_read(&sp->sk_refcnt),
76326 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76327 + NULL,
76328 +#else
76329 + sp,
76330 +#endif
76331 + atomic_read_unchecked(&sp->sk_drops));
76332 }
76333
76334 int udp6_seq_show(struct seq_file *seq, void *v)
76335 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76336 index 253695d..9481ce8 100644
76337 --- a/net/irda/ircomm/ircomm_tty.c
76338 +++ b/net/irda/ircomm/ircomm_tty.c
76339 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76340 add_wait_queue(&self->open_wait, &wait);
76341
76342 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76343 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76344 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76345
76346 /* As far as I can see, we protect open_count - Jean II */
76347 spin_lock_irqsave(&self->spinlock, flags);
76348 if (!tty_hung_up_p(filp)) {
76349 extra_count = 1;
76350 - self->open_count--;
76351 + local_dec(&self->open_count);
76352 }
76353 spin_unlock_irqrestore(&self->spinlock, flags);
76354 - self->blocked_open++;
76355 + local_inc(&self->blocked_open);
76356
76357 while (1) {
76358 if (tty->termios->c_cflag & CBAUD) {
76359 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76360 }
76361
76362 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76363 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76364 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76365
76366 schedule();
76367 }
76368 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76369 if (extra_count) {
76370 /* ++ is not atomic, so this should be protected - Jean II */
76371 spin_lock_irqsave(&self->spinlock, flags);
76372 - self->open_count++;
76373 + local_inc(&self->open_count);
76374 spin_unlock_irqrestore(&self->spinlock, flags);
76375 }
76376 - self->blocked_open--;
76377 + local_dec(&self->blocked_open);
76378
76379 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76380 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76381 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76382
76383 if (!retval)
76384 self->flags |= ASYNC_NORMAL_ACTIVE;
76385 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76386 }
76387 /* ++ is not atomic, so this should be protected - Jean II */
76388 spin_lock_irqsave(&self->spinlock, flags);
76389 - self->open_count++;
76390 + local_inc(&self->open_count);
76391
76392 tty->driver_data = self;
76393 self->tty = tty;
76394 spin_unlock_irqrestore(&self->spinlock, flags);
76395
76396 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76397 - self->line, self->open_count);
76398 + self->line, local_read(&self->open_count));
76399
76400 /* Not really used by us, but lets do it anyway */
76401 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76402 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76403 return;
76404 }
76405
76406 - if ((tty->count == 1) && (self->open_count != 1)) {
76407 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76408 /*
76409 * Uh, oh. tty->count is 1, which means that the tty
76410 * structure will be freed. state->count should always
76411 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76412 */
76413 IRDA_DEBUG(0, "%s(), bad serial port count; "
76414 "tty->count is 1, state->count is %d\n", __func__ ,
76415 - self->open_count);
76416 - self->open_count = 1;
76417 + local_read(&self->open_count));
76418 + local_set(&self->open_count, 1);
76419 }
76420
76421 - if (--self->open_count < 0) {
76422 + if (local_dec_return(&self->open_count) < 0) {
76423 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76424 - __func__, self->line, self->open_count);
76425 - self->open_count = 0;
76426 + __func__, self->line, local_read(&self->open_count));
76427 + local_set(&self->open_count, 0);
76428 }
76429 - if (self->open_count) {
76430 + if (local_read(&self->open_count)) {
76431 spin_unlock_irqrestore(&self->spinlock, flags);
76432
76433 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76434 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76435 tty->closing = 0;
76436 self->tty = NULL;
76437
76438 - if (self->blocked_open) {
76439 + if (local_read(&self->blocked_open)) {
76440 if (self->close_delay)
76441 schedule_timeout_interruptible(self->close_delay);
76442 wake_up_interruptible(&self->open_wait);
76443 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76444 spin_lock_irqsave(&self->spinlock, flags);
76445 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76446 self->tty = NULL;
76447 - self->open_count = 0;
76448 + local_set(&self->open_count, 0);
76449 spin_unlock_irqrestore(&self->spinlock, flags);
76450
76451 wake_up_interruptible(&self->open_wait);
76452 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76453 seq_putc(m, '\n');
76454
76455 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76456 - seq_printf(m, "Open count: %d\n", self->open_count);
76457 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76458 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76459 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76460
76461 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76462 index d5c5b8f..33beff0 100644
76463 --- a/net/iucv/af_iucv.c
76464 +++ b/net/iucv/af_iucv.c
76465 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76466
76467 write_lock_bh(&iucv_sk_list.lock);
76468
76469 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76470 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76471 while (__iucv_get_sock_by_name(name)) {
76472 sprintf(name, "%08x",
76473 - atomic_inc_return(&iucv_sk_list.autobind_name));
76474 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76475 }
76476
76477 write_unlock_bh(&iucv_sk_list.lock);
76478 diff --git a/net/key/af_key.c b/net/key/af_key.c
76479 index 11dbb22..c20f667 100644
76480 --- a/net/key/af_key.c
76481 +++ b/net/key/af_key.c
76482 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76483 static u32 get_acqseq(void)
76484 {
76485 u32 res;
76486 - static atomic_t acqseq;
76487 + static atomic_unchecked_t acqseq;
76488
76489 do {
76490 - res = atomic_inc_return(&acqseq);
76491 + res = atomic_inc_return_unchecked(&acqseq);
76492 } while (!res);
76493 return res;
76494 }
76495 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76496 index 2f0642d..e5c6fba 100644
76497 --- a/net/mac80211/ieee80211_i.h
76498 +++ b/net/mac80211/ieee80211_i.h
76499 @@ -28,6 +28,7 @@
76500 #include <net/ieee80211_radiotap.h>
76501 #include <net/cfg80211.h>
76502 #include <net/mac80211.h>
76503 +#include <asm/local.h>
76504 #include "key.h"
76505 #include "sta_info.h"
76506
76507 @@ -781,7 +782,7 @@ struct ieee80211_local {
76508 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76509 spinlock_t queue_stop_reason_lock;
76510
76511 - int open_count;
76512 + local_t open_count;
76513 int monitors, cooked_mntrs;
76514 /* number of interfaces with corresponding FIF_ flags */
76515 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76516 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76517 index 8e2137b..2974283 100644
76518 --- a/net/mac80211/iface.c
76519 +++ b/net/mac80211/iface.c
76520 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76521 break;
76522 }
76523
76524 - if (local->open_count == 0) {
76525 + if (local_read(&local->open_count) == 0) {
76526 res = drv_start(local);
76527 if (res)
76528 goto err_del_bss;
76529 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76530 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76531
76532 if (!is_valid_ether_addr(dev->dev_addr)) {
76533 - if (!local->open_count)
76534 + if (!local_read(&local->open_count))
76535 drv_stop(local);
76536 return -EADDRNOTAVAIL;
76537 }
76538 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76539 mutex_unlock(&local->mtx);
76540
76541 if (coming_up)
76542 - local->open_count++;
76543 + local_inc(&local->open_count);
76544
76545 if (hw_reconf_flags)
76546 ieee80211_hw_config(local, hw_reconf_flags);
76547 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76548 err_del_interface:
76549 drv_remove_interface(local, sdata);
76550 err_stop:
76551 - if (!local->open_count)
76552 + if (!local_read(&local->open_count))
76553 drv_stop(local);
76554 err_del_bss:
76555 sdata->bss = NULL;
76556 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76557 }
76558
76559 if (going_down)
76560 - local->open_count--;
76561 + local_dec(&local->open_count);
76562
76563 switch (sdata->vif.type) {
76564 case NL80211_IFTYPE_AP_VLAN:
76565 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76566
76567 ieee80211_recalc_ps(local, -1);
76568
76569 - if (local->open_count == 0) {
76570 + if (local_read(&local->open_count) == 0) {
76571 if (local->ops->napi_poll)
76572 napi_disable(&local->napi);
76573 ieee80211_clear_tx_pending(local);
76574 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76575 index b142bd4..a651749 100644
76576 --- a/net/mac80211/main.c
76577 +++ b/net/mac80211/main.c
76578 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76579 local->hw.conf.power_level = power;
76580 }
76581
76582 - if (changed && local->open_count) {
76583 + if (changed && local_read(&local->open_count)) {
76584 ret = drv_config(local, changed);
76585 /*
76586 * Goal:
76587 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76588 index 596efaf..8f1911f 100644
76589 --- a/net/mac80211/pm.c
76590 +++ b/net/mac80211/pm.c
76591 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76592 struct ieee80211_sub_if_data *sdata;
76593 struct sta_info *sta;
76594
76595 - if (!local->open_count)
76596 + if (!local_read(&local->open_count))
76597 goto suspend;
76598
76599 ieee80211_scan_cancel(local);
76600 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76601 cancel_work_sync(&local->dynamic_ps_enable_work);
76602 del_timer_sync(&local->dynamic_ps_timer);
76603
76604 - local->wowlan = wowlan && local->open_count;
76605 + local->wowlan = wowlan && local_read(&local->open_count);
76606 if (local->wowlan) {
76607 int err = drv_suspend(local, wowlan);
76608 if (err < 0) {
76609 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76610 }
76611
76612 /* stop hardware - this must stop RX */
76613 - if (local->open_count)
76614 + if (local_read(&local->open_count))
76615 ieee80211_stop_device(local);
76616
76617 suspend:
76618 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76619 index f9b8e81..bb89b46 100644
76620 --- a/net/mac80211/rate.c
76621 +++ b/net/mac80211/rate.c
76622 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76623
76624 ASSERT_RTNL();
76625
76626 - if (local->open_count)
76627 + if (local_read(&local->open_count))
76628 return -EBUSY;
76629
76630 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76631 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76632 index c97a065..ff61928 100644
76633 --- a/net/mac80211/rc80211_pid_debugfs.c
76634 +++ b/net/mac80211/rc80211_pid_debugfs.c
76635 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76636
76637 spin_unlock_irqrestore(&events->lock, status);
76638
76639 - if (copy_to_user(buf, pb, p))
76640 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76641 return -EFAULT;
76642
76643 return p;
76644 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76645 index 9919892..8c49803 100644
76646 --- a/net/mac80211/util.c
76647 +++ b/net/mac80211/util.c
76648 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76649 }
76650 #endif
76651 /* everything else happens only if HW was up & running */
76652 - if (!local->open_count)
76653 + if (!local_read(&local->open_count))
76654 goto wake_up;
76655
76656 /*
76657 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76658 index f8ac4ef..b02560b 100644
76659 --- a/net/netfilter/Kconfig
76660 +++ b/net/netfilter/Kconfig
76661 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76662
76663 To compile it as a module, choose M here. If unsure, say N.
76664
76665 +config NETFILTER_XT_MATCH_GRADM
76666 + tristate '"gradm" match support'
76667 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76668 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76669 + ---help---
76670 + The gradm match allows to match on grsecurity RBAC being enabled.
76671 + It is useful when iptables rules are applied early on bootup to
76672 + prevent connections to the machine (except from a trusted host)
76673 + while the RBAC system is disabled.
76674 +
76675 config NETFILTER_XT_MATCH_HASHLIMIT
76676 tristate '"hashlimit" match support'
76677 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76678 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76679 index 40f4c3d..0d5dd6b 100644
76680 --- a/net/netfilter/Makefile
76681 +++ b/net/netfilter/Makefile
76682 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76683 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76684 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76685 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76686 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76687 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76688 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76689 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76690 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76691 index 29fa5ba..8debc79 100644
76692 --- a/net/netfilter/ipvs/ip_vs_conn.c
76693 +++ b/net/netfilter/ipvs/ip_vs_conn.c
76694 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76695 /* Increase the refcnt counter of the dest */
76696 atomic_inc(&dest->refcnt);
76697
76698 - conn_flags = atomic_read(&dest->conn_flags);
76699 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
76700 if (cp->protocol != IPPROTO_UDP)
76701 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76702 /* Bind with the destination and its corresponding transmitter */
76703 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76704 atomic_set(&cp->refcnt, 1);
76705
76706 atomic_set(&cp->n_control, 0);
76707 - atomic_set(&cp->in_pkts, 0);
76708 + atomic_set_unchecked(&cp->in_pkts, 0);
76709
76710 atomic_inc(&ipvs->conn_count);
76711 if (flags & IP_VS_CONN_F_NO_CPORT)
76712 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76713
76714 /* Don't drop the entry if its number of incoming packets is not
76715 located in [0, 8] */
76716 - i = atomic_read(&cp->in_pkts);
76717 + i = atomic_read_unchecked(&cp->in_pkts);
76718 if (i > 8 || i < 0) return 0;
76719
76720 if (!todrop_rate[i]) return 0;
76721 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76722 index 2555816..31492d9 100644
76723 --- a/net/netfilter/ipvs/ip_vs_core.c
76724 +++ b/net/netfilter/ipvs/ip_vs_core.c
76725 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76726 ret = cp->packet_xmit(skb, cp, pd->pp);
76727 /* do not touch skb anymore */
76728
76729 - atomic_inc(&cp->in_pkts);
76730 + atomic_inc_unchecked(&cp->in_pkts);
76731 ip_vs_conn_put(cp);
76732 return ret;
76733 }
76734 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76735 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76736 pkts = sysctl_sync_threshold(ipvs);
76737 else
76738 - pkts = atomic_add_return(1, &cp->in_pkts);
76739 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76740
76741 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76742 cp->protocol == IPPROTO_SCTP) {
76743 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76744 index b3afe18..08ec940 100644
76745 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76746 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76747 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76748 ip_vs_rs_hash(ipvs, dest);
76749 write_unlock_bh(&ipvs->rs_lock);
76750 }
76751 - atomic_set(&dest->conn_flags, conn_flags);
76752 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76753
76754 /* bind the service */
76755 if (!dest->svc) {
76756 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76757 " %-7s %-6d %-10d %-10d\n",
76758 &dest->addr.in6,
76759 ntohs(dest->port),
76760 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76761 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76762 atomic_read(&dest->weight),
76763 atomic_read(&dest->activeconns),
76764 atomic_read(&dest->inactconns));
76765 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76766 "%-7s %-6d %-10d %-10d\n",
76767 ntohl(dest->addr.ip),
76768 ntohs(dest->port),
76769 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76770 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76771 atomic_read(&dest->weight),
76772 atomic_read(&dest->activeconns),
76773 atomic_read(&dest->inactconns));
76774 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76775
76776 entry.addr = dest->addr.ip;
76777 entry.port = dest->port;
76778 - entry.conn_flags = atomic_read(&dest->conn_flags);
76779 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76780 entry.weight = atomic_read(&dest->weight);
76781 entry.u_threshold = dest->u_threshold;
76782 entry.l_threshold = dest->l_threshold;
76783 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76784 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76785
76786 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76787 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76788 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76789 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76790 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76791 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76792 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76793 index 8a0d6d6..90ec197 100644
76794 --- a/net/netfilter/ipvs/ip_vs_sync.c
76795 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76796 @@ -649,7 +649,7 @@ control:
76797 * i.e only increment in_pkts for Templates.
76798 */
76799 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76800 - int pkts = atomic_add_return(1, &cp->in_pkts);
76801 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76802
76803 if (pkts % sysctl_sync_period(ipvs) != 1)
76804 return;
76805 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76806
76807 if (opt)
76808 memcpy(&cp->in_seq, opt, sizeof(*opt));
76809 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76810 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76811 cp->state = state;
76812 cp->old_state = cp->state;
76813 /*
76814 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76815 index 7fd66de..e6fb361 100644
76816 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76817 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76818 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76819 else
76820 rc = NF_ACCEPT;
76821 /* do not touch skb anymore */
76822 - atomic_inc(&cp->in_pkts);
76823 + atomic_inc_unchecked(&cp->in_pkts);
76824 goto out;
76825 }
76826
76827 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76828 else
76829 rc = NF_ACCEPT;
76830 /* do not touch skb anymore */
76831 - atomic_inc(&cp->in_pkts);
76832 + atomic_inc_unchecked(&cp->in_pkts);
76833 goto out;
76834 }
76835
76836 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76837 index 66b2c54..c7884e3 100644
76838 --- a/net/netfilter/nfnetlink_log.c
76839 +++ b/net/netfilter/nfnetlink_log.c
76840 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76841 };
76842
76843 static DEFINE_SPINLOCK(instances_lock);
76844 -static atomic_t global_seq;
76845 +static atomic_unchecked_t global_seq;
76846
76847 #define INSTANCE_BUCKETS 16
76848 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76849 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76850 /* global sequence number */
76851 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76852 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76853 - htonl(atomic_inc_return(&global_seq)));
76854 + htonl(atomic_inc_return_unchecked(&global_seq)));
76855
76856 if (data_len) {
76857 struct nlattr *nla;
76858 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76859 new file mode 100644
76860 index 0000000..6905327
76861 --- /dev/null
76862 +++ b/net/netfilter/xt_gradm.c
76863 @@ -0,0 +1,51 @@
76864 +/*
76865 + * gradm match for netfilter
76866 + * Copyright © Zbigniew Krzystolik, 2010
76867 + *
76868 + * This program is free software; you can redistribute it and/or modify
76869 + * it under the terms of the GNU General Public License; either version
76870 + * 2 or 3 as published by the Free Software Foundation.
76871 + */
76872 +#include <linux/module.h>
76873 +#include <linux/moduleparam.h>
76874 +#include <linux/skbuff.h>
76875 +#include <linux/netfilter/x_tables.h>
76876 +#include <linux/grsecurity.h>
76877 +#include <linux/netfilter/xt_gradm.h>
76878 +
76879 +static bool
76880 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76881 +{
76882 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76883 + bool retval = false;
76884 + if (gr_acl_is_enabled())
76885 + retval = true;
76886 + return retval ^ info->invflags;
76887 +}
76888 +
76889 +static struct xt_match gradm_mt_reg __read_mostly = {
76890 + .name = "gradm",
76891 + .revision = 0,
76892 + .family = NFPROTO_UNSPEC,
76893 + .match = gradm_mt,
76894 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76895 + .me = THIS_MODULE,
76896 +};
76897 +
76898 +static int __init gradm_mt_init(void)
76899 +{
76900 + return xt_register_match(&gradm_mt_reg);
76901 +}
76902 +
76903 +static void __exit gradm_mt_exit(void)
76904 +{
76905 + xt_unregister_match(&gradm_mt_reg);
76906 +}
76907 +
76908 +module_init(gradm_mt_init);
76909 +module_exit(gradm_mt_exit);
76910 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76911 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76912 +MODULE_LICENSE("GPL");
76913 +MODULE_ALIAS("ipt_gradm");
76914 +MODULE_ALIAS("ip6t_gradm");
76915 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76916 index 4fe4fb4..87a89e5 100644
76917 --- a/net/netfilter/xt_statistic.c
76918 +++ b/net/netfilter/xt_statistic.c
76919 @@ -19,7 +19,7 @@
76920 #include <linux/module.h>
76921
76922 struct xt_statistic_priv {
76923 - atomic_t count;
76924 + atomic_unchecked_t count;
76925 } ____cacheline_aligned_in_smp;
76926
76927 MODULE_LICENSE("GPL");
76928 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76929 break;
76930 case XT_STATISTIC_MODE_NTH:
76931 do {
76932 - oval = atomic_read(&info->master->count);
76933 + oval = atomic_read_unchecked(&info->master->count);
76934 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76935 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76936 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76937 if (nval == 0)
76938 ret = !ret;
76939 break;
76940 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76941 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76942 if (info->master == NULL)
76943 return -ENOMEM;
76944 - atomic_set(&info->master->count, info->u.nth.count);
76945 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76946
76947 return 0;
76948 }
76949 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76950 index 629b061..8f415cc 100644
76951 --- a/net/netlink/af_netlink.c
76952 +++ b/net/netlink/af_netlink.c
76953 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76954 sk->sk_error_report(sk);
76955 }
76956 }
76957 - atomic_inc(&sk->sk_drops);
76958 + atomic_inc_unchecked(&sk->sk_drops);
76959 }
76960
76961 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76962 @@ -829,12 +829,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
76963 return 0;
76964 }
76965
76966 -int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76967 +static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76968 {
76969 int len = skb->len;
76970
76971 skb_queue_tail(&sk->sk_receive_queue, skb);
76972 sk->sk_data_ready(sk, len);
76973 + return len;
76974 +}
76975 +
76976 +int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76977 +{
76978 + int len = __netlink_sendskb(sk, skb);
76979 +
76980 sock_put(sk);
76981 return len;
76982 }
76983 @@ -957,8 +964,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
76984 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
76985 !test_bit(0, &nlk->state)) {
76986 skb_set_owner_r(skb, sk);
76987 - skb_queue_tail(&sk->sk_receive_queue, skb);
76988 - sk->sk_data_ready(sk, skb->len);
76989 + __netlink_sendskb(sk, skb);
76990 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
76991 }
76992 return -1;
76993 @@ -1680,10 +1686,8 @@ static int netlink_dump(struct sock *sk)
76994
76995 if (sk_filter(sk, skb))
76996 kfree_skb(skb);
76997 - else {
76998 - skb_queue_tail(&sk->sk_receive_queue, skb);
76999 - sk->sk_data_ready(sk, skb->len);
77000 - }
77001 + else
77002 + __netlink_sendskb(sk, skb);
77003 return 0;
77004 }
77005
77006 @@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk)
77007
77008 if (sk_filter(sk, skb))
77009 kfree_skb(skb);
77010 - else {
77011 - skb_queue_tail(&sk->sk_receive_queue, skb);
77012 - sk->sk_data_ready(sk, skb->len);
77013 - }
77014 + else
77015 + __netlink_sendskb(sk, skb);
77016
77017 if (cb->done)
77018 cb->done(cb);
77019 @@ -1995,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77020 sk_wmem_alloc_get(s),
77021 nlk->cb,
77022 atomic_read(&s->sk_refcnt),
77023 - atomic_read(&s->sk_drops),
77024 + atomic_read_unchecked(&s->sk_drops),
77025 sock_i_ino(s)
77026 );
77027
77028 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77029 index 7dab229..212156f 100644
77030 --- a/net/netrom/af_netrom.c
77031 +++ b/net/netrom/af_netrom.c
77032 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77033 struct sock *sk = sock->sk;
77034 struct nr_sock *nr = nr_sk(sk);
77035
77036 + memset(sax, 0, sizeof(*sax));
77037 lock_sock(sk);
77038 if (peer != 0) {
77039 if (sk->sk_state != TCP_ESTABLISHED) {
77040 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77041 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77042 } else {
77043 sax->fsa_ax25.sax25_family = AF_NETROM;
77044 - sax->fsa_ax25.sax25_ndigis = 0;
77045 sax->fsa_ax25.sax25_call = nr->source_addr;
77046 *uaddr_len = sizeof(struct sockaddr_ax25);
77047 }
77048 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77049 index 2dbb32b..a1b4722 100644
77050 --- a/net/packet/af_packet.c
77051 +++ b/net/packet/af_packet.c
77052 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77053
77054 spin_lock(&sk->sk_receive_queue.lock);
77055 po->stats.tp_packets++;
77056 - skb->dropcount = atomic_read(&sk->sk_drops);
77057 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77058 __skb_queue_tail(&sk->sk_receive_queue, skb);
77059 spin_unlock(&sk->sk_receive_queue.lock);
77060 sk->sk_data_ready(sk, skb->len);
77061 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77062 drop_n_acct:
77063 spin_lock(&sk->sk_receive_queue.lock);
77064 po->stats.tp_drops++;
77065 - atomic_inc(&sk->sk_drops);
77066 + atomic_inc_unchecked(&sk->sk_drops);
77067 spin_unlock(&sk->sk_receive_queue.lock);
77068
77069 drop_n_restore:
77070 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77071 case PACKET_HDRLEN:
77072 if (len > sizeof(int))
77073 len = sizeof(int);
77074 - if (copy_from_user(&val, optval, len))
77075 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77076 return -EFAULT;
77077 switch (val) {
77078 case TPACKET_V1:
77079 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77080
77081 if (put_user(len, optlen))
77082 return -EFAULT;
77083 - if (copy_to_user(optval, data, len))
77084 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77085 return -EFAULT;
77086 return 0;
77087 }
77088 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77089 index d65f699..05aa6ce 100644
77090 --- a/net/phonet/af_phonet.c
77091 +++ b/net/phonet/af_phonet.c
77092 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77093 {
77094 struct phonet_protocol *pp;
77095
77096 - if (protocol >= PHONET_NPROTO)
77097 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77098 return NULL;
77099
77100 rcu_read_lock();
77101 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77102 {
77103 int err = 0;
77104
77105 - if (protocol >= PHONET_NPROTO)
77106 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77107 return -EINVAL;
77108
77109 err = proto_register(pp->prot, 1);
77110 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77111 index 9f60008..ae96f04 100644
77112 --- a/net/phonet/pep.c
77113 +++ b/net/phonet/pep.c
77114 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77115
77116 case PNS_PEP_CTRL_REQ:
77117 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77118 - atomic_inc(&sk->sk_drops);
77119 + atomic_inc_unchecked(&sk->sk_drops);
77120 break;
77121 }
77122 __skb_pull(skb, 4);
77123 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77124 }
77125
77126 if (pn->rx_credits == 0) {
77127 - atomic_inc(&sk->sk_drops);
77128 + atomic_inc_unchecked(&sk->sk_drops);
77129 err = -ENOBUFS;
77130 break;
77131 }
77132 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77133 }
77134
77135 if (pn->rx_credits == 0) {
77136 - atomic_inc(&sk->sk_drops);
77137 + atomic_inc_unchecked(&sk->sk_drops);
77138 err = NET_RX_DROP;
77139 break;
77140 }
77141 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77142 index 4c7eff3..59c727f 100644
77143 --- a/net/phonet/socket.c
77144 +++ b/net/phonet/socket.c
77145 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77146 pn->resource, sk->sk_state,
77147 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77148 sock_i_uid(sk), sock_i_ino(sk),
77149 - atomic_read(&sk->sk_refcnt), sk,
77150 - atomic_read(&sk->sk_drops), &len);
77151 + atomic_read(&sk->sk_refcnt),
77152 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77153 + NULL,
77154 +#else
77155 + sk,
77156 +#endif
77157 + atomic_read_unchecked(&sk->sk_drops), &len);
77158 }
77159 seq_printf(seq, "%*s\n", 127 - len, "");
77160 return 0;
77161 diff --git a/net/rds/cong.c b/net/rds/cong.c
77162 index e5b65ac..f3b6fb7 100644
77163 --- a/net/rds/cong.c
77164 +++ b/net/rds/cong.c
77165 @@ -78,7 +78,7 @@
77166 * finds that the saved generation number is smaller than the global generation
77167 * number, it wakes up the process.
77168 */
77169 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77170 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77171
77172 /*
77173 * Congestion monitoring
77174 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77175 rdsdebug("waking map %p for %pI4\n",
77176 map, &map->m_addr);
77177 rds_stats_inc(s_cong_update_received);
77178 - atomic_inc(&rds_cong_generation);
77179 + atomic_inc_unchecked(&rds_cong_generation);
77180 if (waitqueue_active(&map->m_waitq))
77181 wake_up(&map->m_waitq);
77182 if (waitqueue_active(&rds_poll_waitq))
77183 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77184
77185 int rds_cong_updated_since(unsigned long *recent)
77186 {
77187 - unsigned long gen = atomic_read(&rds_cong_generation);
77188 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77189
77190 if (likely(*recent == gen))
77191 return 0;
77192 diff --git a/net/rds/ib.h b/net/rds/ib.h
77193 index edfaaaf..8c89879 100644
77194 --- a/net/rds/ib.h
77195 +++ b/net/rds/ib.h
77196 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77197 /* sending acks */
77198 unsigned long i_ack_flags;
77199 #ifdef KERNEL_HAS_ATOMIC64
77200 - atomic64_t i_ack_next; /* next ACK to send */
77201 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77202 #else
77203 spinlock_t i_ack_lock; /* protect i_ack_next */
77204 u64 i_ack_next; /* next ACK to send */
77205 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77206 index 51c8689..36c555f 100644
77207 --- a/net/rds/ib_cm.c
77208 +++ b/net/rds/ib_cm.c
77209 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77210 /* Clear the ACK state */
77211 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77212 #ifdef KERNEL_HAS_ATOMIC64
77213 - atomic64_set(&ic->i_ack_next, 0);
77214 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77215 #else
77216 ic->i_ack_next = 0;
77217 #endif
77218 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77219 index e29e0ca..fa3a6a3 100644
77220 --- a/net/rds/ib_recv.c
77221 +++ b/net/rds/ib_recv.c
77222 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77223 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77224 int ack_required)
77225 {
77226 - atomic64_set(&ic->i_ack_next, seq);
77227 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77228 if (ack_required) {
77229 smp_mb__before_clear_bit();
77230 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77231 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77232 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77233 smp_mb__after_clear_bit();
77234
77235 - return atomic64_read(&ic->i_ack_next);
77236 + return atomic64_read_unchecked(&ic->i_ack_next);
77237 }
77238 #endif
77239
77240 diff --git a/net/rds/iw.h b/net/rds/iw.h
77241 index 04ce3b1..48119a6 100644
77242 --- a/net/rds/iw.h
77243 +++ b/net/rds/iw.h
77244 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77245 /* sending acks */
77246 unsigned long i_ack_flags;
77247 #ifdef KERNEL_HAS_ATOMIC64
77248 - atomic64_t i_ack_next; /* next ACK to send */
77249 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77250 #else
77251 spinlock_t i_ack_lock; /* protect i_ack_next */
77252 u64 i_ack_next; /* next ACK to send */
77253 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77254 index 9556d28..f046d0e 100644
77255 --- a/net/rds/iw_cm.c
77256 +++ b/net/rds/iw_cm.c
77257 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77258 /* Clear the ACK state */
77259 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77260 #ifdef KERNEL_HAS_ATOMIC64
77261 - atomic64_set(&ic->i_ack_next, 0);
77262 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77263 #else
77264 ic->i_ack_next = 0;
77265 #endif
77266 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77267 index 5e57347..3916042 100644
77268 --- a/net/rds/iw_recv.c
77269 +++ b/net/rds/iw_recv.c
77270 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77271 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77272 int ack_required)
77273 {
77274 - atomic64_set(&ic->i_ack_next, seq);
77275 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77276 if (ack_required) {
77277 smp_mb__before_clear_bit();
77278 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77279 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77280 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77281 smp_mb__after_clear_bit();
77282
77283 - return atomic64_read(&ic->i_ack_next);
77284 + return atomic64_read_unchecked(&ic->i_ack_next);
77285 }
77286 #endif
77287
77288 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77289 index edac9ef..16bcb98 100644
77290 --- a/net/rds/tcp.c
77291 +++ b/net/rds/tcp.c
77292 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77293 int val = 1;
77294
77295 set_fs(KERNEL_DS);
77296 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77297 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77298 sizeof(val));
77299 set_fs(oldfs);
77300 }
77301 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77302 index 1b4fd68..2234175 100644
77303 --- a/net/rds/tcp_send.c
77304 +++ b/net/rds/tcp_send.c
77305 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77306
77307 oldfs = get_fs();
77308 set_fs(KERNEL_DS);
77309 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77310 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77311 sizeof(val));
77312 set_fs(oldfs);
77313 }
77314 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77315 index 74c064c..fdec26f 100644
77316 --- a/net/rxrpc/af_rxrpc.c
77317 +++ b/net/rxrpc/af_rxrpc.c
77318 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77319 __be32 rxrpc_epoch;
77320
77321 /* current debugging ID */
77322 -atomic_t rxrpc_debug_id;
77323 +atomic_unchecked_t rxrpc_debug_id;
77324
77325 /* count of skbs currently in use */
77326 atomic_t rxrpc_n_skbs;
77327 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77328 index c3126e8..21facc7 100644
77329 --- a/net/rxrpc/ar-ack.c
77330 +++ b/net/rxrpc/ar-ack.c
77331 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77332
77333 _enter("{%d,%d,%d,%d},",
77334 call->acks_hard, call->acks_unacked,
77335 - atomic_read(&call->sequence),
77336 + atomic_read_unchecked(&call->sequence),
77337 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77338
77339 stop = 0;
77340 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77341
77342 /* each Tx packet has a new serial number */
77343 sp->hdr.serial =
77344 - htonl(atomic_inc_return(&call->conn->serial));
77345 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77346
77347 hdr = (struct rxrpc_header *) txb->head;
77348 hdr->serial = sp->hdr.serial;
77349 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77350 */
77351 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77352 {
77353 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77354 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77355 }
77356
77357 /*
77358 @@ -629,7 +629,7 @@ process_further:
77359
77360 latest = ntohl(sp->hdr.serial);
77361 hard = ntohl(ack.firstPacket);
77362 - tx = atomic_read(&call->sequence);
77363 + tx = atomic_read_unchecked(&call->sequence);
77364
77365 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77366 latest,
77367 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77368 goto maybe_reschedule;
77369
77370 send_ACK_with_skew:
77371 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77372 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77373 ntohl(ack.serial));
77374 send_ACK:
77375 mtu = call->conn->trans->peer->if_mtu;
77376 @@ -1173,7 +1173,7 @@ send_ACK:
77377 ackinfo.rxMTU = htonl(5692);
77378 ackinfo.jumbo_max = htonl(4);
77379
77380 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77381 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77382 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77383 ntohl(hdr.serial),
77384 ntohs(ack.maxSkew),
77385 @@ -1191,7 +1191,7 @@ send_ACK:
77386 send_message:
77387 _debug("send message");
77388
77389 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77390 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77391 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77392 send_message_2:
77393
77394 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77395 index bf656c2..48f9d27 100644
77396 --- a/net/rxrpc/ar-call.c
77397 +++ b/net/rxrpc/ar-call.c
77398 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77399 spin_lock_init(&call->lock);
77400 rwlock_init(&call->state_lock);
77401 atomic_set(&call->usage, 1);
77402 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77403 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77404 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77405
77406 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77407 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77408 index 4106ca9..a338d7a 100644
77409 --- a/net/rxrpc/ar-connection.c
77410 +++ b/net/rxrpc/ar-connection.c
77411 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77412 rwlock_init(&conn->lock);
77413 spin_lock_init(&conn->state_lock);
77414 atomic_set(&conn->usage, 1);
77415 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77416 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77417 conn->avail_calls = RXRPC_MAXCALLS;
77418 conn->size_align = 4;
77419 conn->header_size = sizeof(struct rxrpc_header);
77420 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77421 index e7ed43a..6afa140 100644
77422 --- a/net/rxrpc/ar-connevent.c
77423 +++ b/net/rxrpc/ar-connevent.c
77424 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77425
77426 len = iov[0].iov_len + iov[1].iov_len;
77427
77428 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77429 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77430 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77431
77432 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77433 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77434 index 1a2b0633..e8d1382 100644
77435 --- a/net/rxrpc/ar-input.c
77436 +++ b/net/rxrpc/ar-input.c
77437 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77438 /* track the latest serial number on this connection for ACK packet
77439 * information */
77440 serial = ntohl(sp->hdr.serial);
77441 - hi_serial = atomic_read(&call->conn->hi_serial);
77442 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77443 while (serial > hi_serial)
77444 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77445 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77446 serial);
77447
77448 /* request ACK generation for any ACK or DATA packet that requests
77449 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77450 index 8e22bd3..f66d1c0 100644
77451 --- a/net/rxrpc/ar-internal.h
77452 +++ b/net/rxrpc/ar-internal.h
77453 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77454 int error; /* error code for local abort */
77455 int debug_id; /* debug ID for printks */
77456 unsigned call_counter; /* call ID counter */
77457 - atomic_t serial; /* packet serial number counter */
77458 - atomic_t hi_serial; /* highest serial number received */
77459 + atomic_unchecked_t serial; /* packet serial number counter */
77460 + atomic_unchecked_t hi_serial; /* highest serial number received */
77461 u8 avail_calls; /* number of calls available */
77462 u8 size_align; /* data size alignment (for security) */
77463 u8 header_size; /* rxrpc + security header size */
77464 @@ -346,7 +346,7 @@ struct rxrpc_call {
77465 spinlock_t lock;
77466 rwlock_t state_lock; /* lock for state transition */
77467 atomic_t usage;
77468 - atomic_t sequence; /* Tx data packet sequence counter */
77469 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77470 u32 abort_code; /* local/remote abort code */
77471 enum { /* current state of call */
77472 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77473 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77474 */
77475 extern atomic_t rxrpc_n_skbs;
77476 extern __be32 rxrpc_epoch;
77477 -extern atomic_t rxrpc_debug_id;
77478 +extern atomic_unchecked_t rxrpc_debug_id;
77479 extern struct workqueue_struct *rxrpc_workqueue;
77480
77481 /*
77482 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77483 index 87f7135..74d3703 100644
77484 --- a/net/rxrpc/ar-local.c
77485 +++ b/net/rxrpc/ar-local.c
77486 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77487 spin_lock_init(&local->lock);
77488 rwlock_init(&local->services_lock);
77489 atomic_set(&local->usage, 1);
77490 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77491 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77492 memcpy(&local->srx, srx, sizeof(*srx));
77493 }
77494
77495 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77496 index 16ae887..d24f12b 100644
77497 --- a/net/rxrpc/ar-output.c
77498 +++ b/net/rxrpc/ar-output.c
77499 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77500 sp->hdr.cid = call->cid;
77501 sp->hdr.callNumber = call->call_id;
77502 sp->hdr.seq =
77503 - htonl(atomic_inc_return(&call->sequence));
77504 + htonl(atomic_inc_return_unchecked(&call->sequence));
77505 sp->hdr.serial =
77506 - htonl(atomic_inc_return(&conn->serial));
77507 + htonl(atomic_inc_return_unchecked(&conn->serial));
77508 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77509 sp->hdr.userStatus = 0;
77510 sp->hdr.securityIndex = conn->security_ix;
77511 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77512 index 2754f09..b20e38f 100644
77513 --- a/net/rxrpc/ar-peer.c
77514 +++ b/net/rxrpc/ar-peer.c
77515 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77516 INIT_LIST_HEAD(&peer->error_targets);
77517 spin_lock_init(&peer->lock);
77518 atomic_set(&peer->usage, 1);
77519 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77520 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77521 memcpy(&peer->srx, srx, sizeof(*srx));
77522
77523 rxrpc_assess_MTU_size(peer);
77524 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77525 index 38047f7..9f48511 100644
77526 --- a/net/rxrpc/ar-proc.c
77527 +++ b/net/rxrpc/ar-proc.c
77528 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77529 atomic_read(&conn->usage),
77530 rxrpc_conn_states[conn->state],
77531 key_serial(conn->key),
77532 - atomic_read(&conn->serial),
77533 - atomic_read(&conn->hi_serial));
77534 + atomic_read_unchecked(&conn->serial),
77535 + atomic_read_unchecked(&conn->hi_serial));
77536
77537 return 0;
77538 }
77539 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77540 index 92df566..87ec1bf 100644
77541 --- a/net/rxrpc/ar-transport.c
77542 +++ b/net/rxrpc/ar-transport.c
77543 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77544 spin_lock_init(&trans->client_lock);
77545 rwlock_init(&trans->conn_lock);
77546 atomic_set(&trans->usage, 1);
77547 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77548 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77549
77550 if (peer->srx.transport.family == AF_INET) {
77551 switch (peer->srx.transport_type) {
77552 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77553 index 7635107..4670276 100644
77554 --- a/net/rxrpc/rxkad.c
77555 +++ b/net/rxrpc/rxkad.c
77556 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77557
77558 len = iov[0].iov_len + iov[1].iov_len;
77559
77560 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77561 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77562 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77563
77564 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77565 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77566
77567 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77568
77569 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77570 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77571 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77572
77573 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77574 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77575 index 1e2eee8..ce3967e 100644
77576 --- a/net/sctp/proc.c
77577 +++ b/net/sctp/proc.c
77578 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77579 seq_printf(seq,
77580 "%8pK %8pK %-3d %-3d %-2d %-4d "
77581 "%4d %8d %8d %7d %5lu %-5d %5d ",
77582 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77583 + assoc, sk,
77584 + sctp_sk(sk)->type, sk->sk_state,
77585 assoc->state, hash,
77586 assoc->assoc_id,
77587 assoc->sndbuf_used,
77588 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77589 index 408ebd0..202aa85 100644
77590 --- a/net/sctp/socket.c
77591 +++ b/net/sctp/socket.c
77592 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77593 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77594 if (space_left < addrlen)
77595 return -ENOMEM;
77596 - if (copy_to_user(to, &temp, addrlen))
77597 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77598 return -EFAULT;
77599 to += addrlen;
77600 cnt++;
77601 diff --git a/net/socket.c b/net/socket.c
77602 index 28a96af..61a7a06 100644
77603 --- a/net/socket.c
77604 +++ b/net/socket.c
77605 @@ -88,6 +88,7 @@
77606 #include <linux/nsproxy.h>
77607 #include <linux/magic.h>
77608 #include <linux/slab.h>
77609 +#include <linux/in.h>
77610
77611 #include <asm/uaccess.h>
77612 #include <asm/unistd.h>
77613 @@ -105,6 +106,8 @@
77614 #include <linux/sockios.h>
77615 #include <linux/atalk.h>
77616
77617 +#include <linux/grsock.h>
77618 +
77619 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77620 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77621 unsigned long nr_segs, loff_t pos);
77622 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77623 &sockfs_dentry_operations, SOCKFS_MAGIC);
77624 }
77625
77626 -static struct vfsmount *sock_mnt __read_mostly;
77627 +struct vfsmount *sock_mnt __read_mostly;
77628
77629 static struct file_system_type sock_fs_type = {
77630 .name = "sockfs",
77631 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77632 return -EAFNOSUPPORT;
77633 if (type < 0 || type >= SOCK_MAX)
77634 return -EINVAL;
77635 + if (protocol < 0)
77636 + return -EINVAL;
77637
77638 /* Compatibility.
77639
77640 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77641 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77642 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77643
77644 + if(!gr_search_socket(family, type, protocol)) {
77645 + retval = -EACCES;
77646 + goto out;
77647 + }
77648 +
77649 + if (gr_handle_sock_all(family, type, protocol)) {
77650 + retval = -EACCES;
77651 + goto out;
77652 + }
77653 +
77654 retval = sock_create(family, type, protocol, &sock);
77655 if (retval < 0)
77656 goto out;
77657 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77658 if (sock) {
77659 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
77660 if (err >= 0) {
77661 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77662 + err = -EACCES;
77663 + goto error;
77664 + }
77665 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77666 + if (err)
77667 + goto error;
77668 +
77669 err = security_socket_bind(sock,
77670 (struct sockaddr *)&address,
77671 addrlen);
77672 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77673 (struct sockaddr *)
77674 &address, addrlen);
77675 }
77676 +error:
77677 fput_light(sock->file, fput_needed);
77678 }
77679 return err;
77680 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77681 if ((unsigned)backlog > somaxconn)
77682 backlog = somaxconn;
77683
77684 + if (gr_handle_sock_server_other(sock->sk)) {
77685 + err = -EPERM;
77686 + goto error;
77687 + }
77688 +
77689 + err = gr_search_listen(sock);
77690 + if (err)
77691 + goto error;
77692 +
77693 err = security_socket_listen(sock, backlog);
77694 if (!err)
77695 err = sock->ops->listen(sock, backlog);
77696
77697 +error:
77698 fput_light(sock->file, fput_needed);
77699 }
77700 return err;
77701 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77702 newsock->type = sock->type;
77703 newsock->ops = sock->ops;
77704
77705 + if (gr_handle_sock_server_other(sock->sk)) {
77706 + err = -EPERM;
77707 + sock_release(newsock);
77708 + goto out_put;
77709 + }
77710 +
77711 + err = gr_search_accept(sock);
77712 + if (err) {
77713 + sock_release(newsock);
77714 + goto out_put;
77715 + }
77716 +
77717 /*
77718 * We don't need try_module_get here, as the listening socket (sock)
77719 * has the protocol module (sock->ops->owner) held.
77720 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77721 fd_install(newfd, newfile);
77722 err = newfd;
77723
77724 + gr_attach_curr_ip(newsock->sk);
77725 +
77726 out_put:
77727 fput_light(sock->file, fput_needed);
77728 out:
77729 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77730 int, addrlen)
77731 {
77732 struct socket *sock;
77733 + struct sockaddr *sck;
77734 struct sockaddr_storage address;
77735 int err, fput_needed;
77736
77737 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77738 if (err < 0)
77739 goto out_put;
77740
77741 + sck = (struct sockaddr *)&address;
77742 +
77743 + if (gr_handle_sock_client(sck)) {
77744 + err = -EACCES;
77745 + goto out_put;
77746 + }
77747 +
77748 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77749 + if (err)
77750 + goto out_put;
77751 +
77752 err =
77753 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77754 if (err)
77755 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77756 * checking falls down on this.
77757 */
77758 if (copy_from_user(ctl_buf,
77759 - (void __user __force *)msg_sys->msg_control,
77760 + (void __force_user *)msg_sys->msg_control,
77761 ctl_len))
77762 goto out_freectl;
77763 msg_sys->msg_control = ctl_buf;
77764 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77765 * kernel msghdr to use the kernel address space)
77766 */
77767
77768 - uaddr = (__force void __user *)msg_sys->msg_name;
77769 + uaddr = (void __force_user *)msg_sys->msg_name;
77770 uaddr_len = COMPAT_NAMELEN(msg);
77771 if (MSG_CMSG_COMPAT & flags) {
77772 err = verify_compat_iovec(msg_sys, iov,
77773 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77774 }
77775
77776 ifr = compat_alloc_user_space(buf_size);
77777 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77778 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77779
77780 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77781 return -EFAULT;
77782 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77783 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77784
77785 if (copy_in_user(rxnfc, compat_rxnfc,
77786 - (void *)(&rxnfc->fs.m_ext + 1) -
77787 - (void *)rxnfc) ||
77788 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77789 + (void __user *)rxnfc) ||
77790 copy_in_user(&rxnfc->fs.ring_cookie,
77791 &compat_rxnfc->fs.ring_cookie,
77792 - (void *)(&rxnfc->fs.location + 1) -
77793 - (void *)&rxnfc->fs.ring_cookie) ||
77794 + (void __user *)(&rxnfc->fs.location + 1) -
77795 + (void __user *)&rxnfc->fs.ring_cookie) ||
77796 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77797 sizeof(rxnfc->rule_cnt)))
77798 return -EFAULT;
77799 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77800
77801 if (convert_out) {
77802 if (copy_in_user(compat_rxnfc, rxnfc,
77803 - (const void *)(&rxnfc->fs.m_ext + 1) -
77804 - (const void *)rxnfc) ||
77805 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77806 + (const void __user *)rxnfc) ||
77807 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77808 &rxnfc->fs.ring_cookie,
77809 - (const void *)(&rxnfc->fs.location + 1) -
77810 - (const void *)&rxnfc->fs.ring_cookie) ||
77811 + (const void __user *)(&rxnfc->fs.location + 1) -
77812 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77813 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77814 sizeof(rxnfc->rule_cnt)))
77815 return -EFAULT;
77816 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77817 old_fs = get_fs();
77818 set_fs(KERNEL_DS);
77819 err = dev_ioctl(net, cmd,
77820 - (struct ifreq __user __force *) &kifr);
77821 + (struct ifreq __force_user *) &kifr);
77822 set_fs(old_fs);
77823
77824 return err;
77825 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77826
77827 old_fs = get_fs();
77828 set_fs(KERNEL_DS);
77829 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77830 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77831 set_fs(old_fs);
77832
77833 if (cmd == SIOCGIFMAP && !err) {
77834 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77835 ret |= __get_user(rtdev, &(ur4->rt_dev));
77836 if (rtdev) {
77837 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77838 - r4.rt_dev = (char __user __force *)devname;
77839 + r4.rt_dev = (char __force_user *)devname;
77840 devname[15] = 0;
77841 } else
77842 r4.rt_dev = NULL;
77843 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77844 int __user *uoptlen;
77845 int err;
77846
77847 - uoptval = (char __user __force *) optval;
77848 - uoptlen = (int __user __force *) optlen;
77849 + uoptval = (char __force_user *) optval;
77850 + uoptlen = (int __force_user *) optlen;
77851
77852 set_fs(KERNEL_DS);
77853 if (level == SOL_SOCKET)
77854 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77855 char __user *uoptval;
77856 int err;
77857
77858 - uoptval = (char __user __force *) optval;
77859 + uoptval = (char __force_user *) optval;
77860
77861 set_fs(KERNEL_DS);
77862 if (level == SOL_SOCKET)
77863 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77864 index 8efd96c..b492ab2 100644
77865 --- a/net/sunrpc/sched.c
77866 +++ b/net/sunrpc/sched.c
77867 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
77868 #ifdef RPC_DEBUG
77869 static void rpc_task_set_debuginfo(struct rpc_task *task)
77870 {
77871 - static atomic_t rpc_pid;
77872 + static atomic_unchecked_t rpc_pid;
77873
77874 - task->tk_pid = atomic_inc_return(&rpc_pid);
77875 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77876 }
77877 #else
77878 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77879 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77880 index 4645709..d41d668 100644
77881 --- a/net/sunrpc/svcsock.c
77882 +++ b/net/sunrpc/svcsock.c
77883 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77884 int buflen, unsigned int base)
77885 {
77886 size_t save_iovlen;
77887 - void __user *save_iovbase;
77888 + void *save_iovbase;
77889 unsigned int i;
77890 int ret;
77891
77892 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77893 index 09af4fa..77110a9 100644
77894 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77895 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77896 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77897 static unsigned int min_max_inline = 4096;
77898 static unsigned int max_max_inline = 65536;
77899
77900 -atomic_t rdma_stat_recv;
77901 -atomic_t rdma_stat_read;
77902 -atomic_t rdma_stat_write;
77903 -atomic_t rdma_stat_sq_starve;
77904 -atomic_t rdma_stat_rq_starve;
77905 -atomic_t rdma_stat_rq_poll;
77906 -atomic_t rdma_stat_rq_prod;
77907 -atomic_t rdma_stat_sq_poll;
77908 -atomic_t rdma_stat_sq_prod;
77909 +atomic_unchecked_t rdma_stat_recv;
77910 +atomic_unchecked_t rdma_stat_read;
77911 +atomic_unchecked_t rdma_stat_write;
77912 +atomic_unchecked_t rdma_stat_sq_starve;
77913 +atomic_unchecked_t rdma_stat_rq_starve;
77914 +atomic_unchecked_t rdma_stat_rq_poll;
77915 +atomic_unchecked_t rdma_stat_rq_prod;
77916 +atomic_unchecked_t rdma_stat_sq_poll;
77917 +atomic_unchecked_t rdma_stat_sq_prod;
77918
77919 /* Temporary NFS request map and context caches */
77920 struct kmem_cache *svc_rdma_map_cachep;
77921 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
77922 len -= *ppos;
77923 if (len > *lenp)
77924 len = *lenp;
77925 - if (len && copy_to_user(buffer, str_buf, len))
77926 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77927 return -EFAULT;
77928 *lenp = len;
77929 *ppos += len;
77930 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
77931 {
77932 .procname = "rdma_stat_read",
77933 .data = &rdma_stat_read,
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_recv",
77941 .data = &rdma_stat_recv,
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_write",
77949 .data = &rdma_stat_write,
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_sq_starve",
77957 .data = &rdma_stat_sq_starve,
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_starve",
77965 .data = &rdma_stat_rq_starve,
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_rq_poll",
77973 .data = &rdma_stat_rq_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_rq_prod",
77981 .data = &rdma_stat_rq_prod,
77982 - .maxlen = sizeof(atomic_t),
77983 + .maxlen = sizeof(atomic_unchecked_t),
77984 .mode = 0644,
77985 .proc_handler = read_reset_stat,
77986 },
77987 {
77988 .procname = "rdma_stat_sq_poll",
77989 .data = &rdma_stat_sq_poll,
77990 - .maxlen = sizeof(atomic_t),
77991 + .maxlen = sizeof(atomic_unchecked_t),
77992 .mode = 0644,
77993 .proc_handler = read_reset_stat,
77994 },
77995 {
77996 .procname = "rdma_stat_sq_prod",
77997 .data = &rdma_stat_sq_prod,
77998 - .maxlen = sizeof(atomic_t),
77999 + .maxlen = sizeof(atomic_unchecked_t),
78000 .mode = 0644,
78001 .proc_handler = read_reset_stat,
78002 },
78003 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78004 index df67211..c354b13 100644
78005 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78006 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78007 @@ -499,7 +499,7 @@ next_sge:
78008 svc_rdma_put_context(ctxt, 0);
78009 goto out;
78010 }
78011 - atomic_inc(&rdma_stat_read);
78012 + atomic_inc_unchecked(&rdma_stat_read);
78013
78014 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78015 chl_map->ch[ch_no].count -= read_wr.num_sge;
78016 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78017 dto_q);
78018 list_del_init(&ctxt->dto_q);
78019 } else {
78020 - atomic_inc(&rdma_stat_rq_starve);
78021 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78022 clear_bit(XPT_DATA, &xprt->xpt_flags);
78023 ctxt = NULL;
78024 }
78025 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78026 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78027 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78028 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78029 - atomic_inc(&rdma_stat_recv);
78030 + atomic_inc_unchecked(&rdma_stat_recv);
78031
78032 /* Build up the XDR from the receive buffers. */
78033 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78034 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78035 index 249a835..fb2794b 100644
78036 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78037 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78038 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78039 write_wr.wr.rdma.remote_addr = to;
78040
78041 /* Post It */
78042 - atomic_inc(&rdma_stat_write);
78043 + atomic_inc_unchecked(&rdma_stat_write);
78044 if (svc_rdma_send(xprt, &write_wr))
78045 goto err;
78046 return 0;
78047 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78048 index 894cb42..cf5bafb 100644
78049 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78050 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78051 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78052 return;
78053
78054 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78055 - atomic_inc(&rdma_stat_rq_poll);
78056 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78057
78058 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78059 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78060 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78061 }
78062
78063 if (ctxt)
78064 - atomic_inc(&rdma_stat_rq_prod);
78065 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78066
78067 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78068 /*
78069 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78070 return;
78071
78072 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78073 - atomic_inc(&rdma_stat_sq_poll);
78074 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78075 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78076 if (wc.status != IB_WC_SUCCESS)
78077 /* Close the transport */
78078 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78079 }
78080
78081 if (ctxt)
78082 - atomic_inc(&rdma_stat_sq_prod);
78083 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78084 }
78085
78086 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78087 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78088 spin_lock_bh(&xprt->sc_lock);
78089 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78090 spin_unlock_bh(&xprt->sc_lock);
78091 - atomic_inc(&rdma_stat_sq_starve);
78092 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78093
78094 /* See if we can opportunistically reap SQ WR to make room */
78095 sq_cq_reap(xprt);
78096 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78097 index e758139..d29ea47 100644
78098 --- a/net/sysctl_net.c
78099 +++ b/net/sysctl_net.c
78100 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78101 struct ctl_table *table)
78102 {
78103 /* Allow network administrator to have same access as root. */
78104 - if (capable(CAP_NET_ADMIN)) {
78105 + if (capable_nolog(CAP_NET_ADMIN)) {
78106 int mode = (table->mode >> 6) & 7;
78107 return (mode << 6) | (mode << 3) | mode;
78108 }
78109 diff --git a/net/tipc/link.c b/net/tipc/link.c
78110 index ac1832a..533ed97 100644
78111 --- a/net/tipc/link.c
78112 +++ b/net/tipc/link.c
78113 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78114 struct tipc_msg fragm_hdr;
78115 struct sk_buff *buf, *buf_chain, *prev;
78116 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78117 - const unchar *sect_crs;
78118 + const unchar __user *sect_crs;
78119 int curr_sect;
78120 u32 fragm_no;
78121
78122 @@ -1249,7 +1249,7 @@ again:
78123
78124 if (!sect_rest) {
78125 sect_rest = msg_sect[++curr_sect].iov_len;
78126 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78127 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78128 }
78129
78130 if (sect_rest < fragm_rest)
78131 @@ -1268,7 +1268,7 @@ error:
78132 }
78133 } else
78134 skb_copy_to_linear_data_offset(buf, fragm_crs,
78135 - sect_crs, sz);
78136 + (const void __force_kernel *)sect_crs, sz);
78137 sect_crs += sz;
78138 sect_rest -= sz;
78139 fragm_crs += sz;
78140 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78141 index 3e4d3e2..27b55dc 100644
78142 --- a/net/tipc/msg.c
78143 +++ b/net/tipc/msg.c
78144 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78145 msg_sect[cnt].iov_len);
78146 else
78147 skb_copy_to_linear_data_offset(*buf, pos,
78148 - msg_sect[cnt].iov_base,
78149 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78150 msg_sect[cnt].iov_len);
78151 pos += msg_sect[cnt].iov_len;
78152 }
78153 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78154 index 8c49566..14510cb 100644
78155 --- a/net/tipc/subscr.c
78156 +++ b/net/tipc/subscr.c
78157 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78158 {
78159 struct iovec msg_sect;
78160
78161 - msg_sect.iov_base = (void *)&sub->evt;
78162 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78163 msg_sect.iov_len = sizeof(struct tipc_event);
78164
78165 sub->evt.event = htohl(event, sub->swap);
78166 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78167 index 85d3bb7..79f4487 100644
78168 --- a/net/unix/af_unix.c
78169 +++ b/net/unix/af_unix.c
78170 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78171 err = -ECONNREFUSED;
78172 if (!S_ISSOCK(inode->i_mode))
78173 goto put_fail;
78174 +
78175 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78176 + err = -EACCES;
78177 + goto put_fail;
78178 + }
78179 +
78180 u = unix_find_socket_byinode(inode);
78181 if (!u)
78182 goto put_fail;
78183 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78184 if (u) {
78185 struct dentry *dentry;
78186 dentry = unix_sk(u)->dentry;
78187 +
78188 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78189 + err = -EPERM;
78190 + sock_put(u);
78191 + goto fail;
78192 + }
78193 +
78194 if (dentry)
78195 touch_atime(unix_sk(u)->mnt, dentry);
78196 } else
78197 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78198 err = security_path_mknod(&path, dentry, mode, 0);
78199 if (err)
78200 goto out_mknod_drop_write;
78201 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78202 + err = -EACCES;
78203 + goto out_mknod_drop_write;
78204 + }
78205 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78206 out_mknod_drop_write:
78207 mnt_drop_write(path.mnt);
78208 if (err)
78209 goto out_mknod_dput;
78210 +
78211 + gr_handle_create(dentry, path.mnt);
78212 +
78213 mutex_unlock(&path.dentry->d_inode->i_mutex);
78214 dput(path.dentry);
78215 path.dentry = dentry;
78216 diff --git a/net/wireless/core.h b/net/wireless/core.h
78217 index 43ad9c8..ab5127c 100644
78218 --- a/net/wireless/core.h
78219 +++ b/net/wireless/core.h
78220 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78221 struct mutex mtx;
78222
78223 /* rfkill support */
78224 - struct rfkill_ops rfkill_ops;
78225 + rfkill_ops_no_const rfkill_ops;
78226 struct rfkill *rfkill;
78227 struct work_struct rfkill_sync;
78228
78229 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78230 index 0af7f54..c916d2f 100644
78231 --- a/net/wireless/wext-core.c
78232 +++ b/net/wireless/wext-core.c
78233 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78234 */
78235
78236 /* Support for very large requests */
78237 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78238 - (user_length > descr->max_tokens)) {
78239 + if (user_length > descr->max_tokens) {
78240 /* Allow userspace to GET more than max so
78241 * we can support any size GET requests.
78242 * There is still a limit : -ENOMEM.
78243 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78244 }
78245 }
78246
78247 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78248 - /*
78249 - * If this is a GET, but not NOMAX, it means that the extra
78250 - * data is not bounded by userspace, but by max_tokens. Thus
78251 - * set the length to max_tokens. This matches the extra data
78252 - * allocation.
78253 - * The driver should fill it with the number of tokens it
78254 - * provided, and it may check iwp->length rather than having
78255 - * knowledge of max_tokens. If the driver doesn't change the
78256 - * iwp->length, this ioctl just copies back max_token tokens
78257 - * filled with zeroes. Hopefully the driver isn't claiming
78258 - * them to be valid data.
78259 - */
78260 - iwp->length = descr->max_tokens;
78261 - }
78262 -
78263 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78264
78265 iwp->length += essid_compat;
78266 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78267 index 7661576..80f7627 100644
78268 --- a/net/xfrm/xfrm_policy.c
78269 +++ b/net/xfrm/xfrm_policy.c
78270 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78271 {
78272 policy->walk.dead = 1;
78273
78274 - atomic_inc(&policy->genid);
78275 + atomic_inc_unchecked(&policy->genid);
78276
78277 if (del_timer(&policy->timer))
78278 xfrm_pol_put(policy);
78279 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78280 hlist_add_head(&policy->bydst, chain);
78281 xfrm_pol_hold(policy);
78282 net->xfrm.policy_count[dir]++;
78283 - atomic_inc(&flow_cache_genid);
78284 + atomic_inc_unchecked(&flow_cache_genid);
78285 if (delpol)
78286 __xfrm_policy_unlink(delpol, dir);
78287 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78288 @@ -1530,7 +1530,7 @@ free_dst:
78289 goto out;
78290 }
78291
78292 -static int inline
78293 +static inline int
78294 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78295 {
78296 if (!*target) {
78297 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78298 return 0;
78299 }
78300
78301 -static int inline
78302 +static inline int
78303 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78304 {
78305 #ifdef CONFIG_XFRM_SUB_POLICY
78306 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78307 #endif
78308 }
78309
78310 -static int inline
78311 +static inline int
78312 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78313 {
78314 #ifdef CONFIG_XFRM_SUB_POLICY
78315 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78316
78317 xdst->num_pols = num_pols;
78318 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78319 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78320 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78321
78322 return xdst;
78323 }
78324 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78325 if (xdst->xfrm_genid != dst->xfrm->genid)
78326 return 0;
78327 if (xdst->num_pols > 0 &&
78328 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78329 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78330 return 0;
78331
78332 mtu = dst_mtu(dst->child);
78333 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78334 sizeof(pol->xfrm_vec[i].saddr));
78335 pol->xfrm_vec[i].encap_family = mp->new_family;
78336 /* flush bundles */
78337 - atomic_inc(&pol->genid);
78338 + atomic_inc_unchecked(&pol->genid);
78339 }
78340 }
78341
78342 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78343 index d2b366c..51ff91ebc 100644
78344 --- a/scripts/Makefile.build
78345 +++ b/scripts/Makefile.build
78346 @@ -109,7 +109,7 @@ endif
78347 endif
78348
78349 # Do not include host rules unless needed
78350 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78351 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78352 include scripts/Makefile.host
78353 endif
78354
78355 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78356 index 686cb0d..9d653bf 100644
78357 --- a/scripts/Makefile.clean
78358 +++ b/scripts/Makefile.clean
78359 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78360 __clean-files := $(extra-y) $(always) \
78361 $(targets) $(clean-files) \
78362 $(host-progs) \
78363 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78364 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78365 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78366
78367 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78368
78369 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78370 index 1ac414f..a1c1451 100644
78371 --- a/scripts/Makefile.host
78372 +++ b/scripts/Makefile.host
78373 @@ -31,6 +31,7 @@
78374 # Note: Shared libraries consisting of C++ files are not supported
78375
78376 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78377 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78378
78379 # C code
78380 # Executables compiled from a single .c file
78381 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78382 # Shared libaries (only .c supported)
78383 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78384 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78385 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78386 # Remove .so files from "xxx-objs"
78387 host-cobjs := $(filter-out %.so,$(host-cobjs))
78388
78389 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78390 index cb1f50c..cef2a7c 100644
78391 --- a/scripts/basic/fixdep.c
78392 +++ b/scripts/basic/fixdep.c
78393 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78394 /*
78395 * Lookup a value in the configuration string.
78396 */
78397 -static int is_defined_config(const char *name, int len, unsigned int hash)
78398 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78399 {
78400 struct item *aux;
78401
78402 @@ -211,10 +211,10 @@ static void clear_config(void)
78403 /*
78404 * Record the use of a CONFIG_* word.
78405 */
78406 -static void use_config(const char *m, int slen)
78407 +static void use_config(const char *m, unsigned int slen)
78408 {
78409 unsigned int hash = strhash(m, slen);
78410 - int c, i;
78411 + unsigned int c, i;
78412
78413 if (is_defined_config(m, slen, hash))
78414 return;
78415 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78416
78417 static void parse_config_file(const char *map, size_t len)
78418 {
78419 - const int *end = (const int *) (map + len);
78420 + const unsigned int *end = (const unsigned int *) (map + len);
78421 /* start at +1, so that p can never be < map */
78422 - const int *m = (const int *) map + 1;
78423 + const unsigned int *m = (const unsigned int *) map + 1;
78424 const char *p, *q;
78425
78426 for (; m < end; m++) {
78427 @@ -406,7 +406,7 @@ static void print_deps(void)
78428 static void traps(void)
78429 {
78430 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78431 - int *p = (int *)test;
78432 + unsigned int *p = (unsigned int *)test;
78433
78434 if (*p != INT_CONF) {
78435 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78436 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78437 new file mode 100644
78438 index 0000000..8729101
78439 --- /dev/null
78440 +++ b/scripts/gcc-plugin.sh
78441 @@ -0,0 +1,2 @@
78442 +#!/bin/sh
78443 +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"
78444 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78445 index b89efe6..2c30808 100644
78446 --- a/scripts/mod/file2alias.c
78447 +++ b/scripts/mod/file2alias.c
78448 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78449 unsigned long size, unsigned long id_size,
78450 void *symval)
78451 {
78452 - int i;
78453 + unsigned int i;
78454
78455 if (size % id_size || size < id_size) {
78456 if (cross_build != 0)
78457 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78458 /* USB is special because the bcdDevice can be matched against a numeric range */
78459 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78460 static void do_usb_entry(struct usb_device_id *id,
78461 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78462 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78463 unsigned char range_lo, unsigned char range_hi,
78464 unsigned char max, struct module *mod)
78465 {
78466 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78467 {
78468 unsigned int devlo, devhi;
78469 unsigned char chi, clo, max;
78470 - int ndigits;
78471 + unsigned int ndigits;
78472
78473 id->match_flags = TO_NATIVE(id->match_flags);
78474 id->idVendor = TO_NATIVE(id->idVendor);
78475 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78476 for (i = 0; i < count; i++) {
78477 const char *id = (char *)devs[i].id;
78478 char acpi_id[sizeof(devs[0].id)];
78479 - int j;
78480 + unsigned int j;
78481
78482 buf_printf(&mod->dev_table_buf,
78483 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78484 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78485
78486 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78487 const char *id = (char *)card->devs[j].id;
78488 - int i2, j2;
78489 + unsigned int i2, j2;
78490 int dup = 0;
78491
78492 if (!id[0])
78493 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78494 /* add an individual alias for every device entry */
78495 if (!dup) {
78496 char acpi_id[sizeof(card->devs[0].id)];
78497 - int k;
78498 + unsigned int k;
78499
78500 buf_printf(&mod->dev_table_buf,
78501 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78502 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78503 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78504 char *alias)
78505 {
78506 - int i, j;
78507 + unsigned int i, j;
78508
78509 sprintf(alias, "dmi*");
78510
78511 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78512 index c4e7d15..4241aef 100644
78513 --- a/scripts/mod/modpost.c
78514 +++ b/scripts/mod/modpost.c
78515 @@ -922,6 +922,7 @@ enum mismatch {
78516 ANY_INIT_TO_ANY_EXIT,
78517 ANY_EXIT_TO_ANY_INIT,
78518 EXPORT_TO_INIT_EXIT,
78519 + DATA_TO_TEXT
78520 };
78521
78522 struct sectioncheck {
78523 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
78524 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78525 .mismatch = EXPORT_TO_INIT_EXIT,
78526 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78527 +},
78528 +/* Do not reference code from writable data */
78529 +{
78530 + .fromsec = { DATA_SECTIONS, NULL },
78531 + .tosec = { TEXT_SECTIONS, NULL },
78532 + .mismatch = DATA_TO_TEXT
78533 }
78534 };
78535
78536 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78537 continue;
78538 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78539 continue;
78540 - if (sym->st_value == addr)
78541 - return sym;
78542 /* Find a symbol nearby - addr are maybe negative */
78543 d = sym->st_value - addr;
78544 + if (d == 0)
78545 + return sym;
78546 if (d < 0)
78547 d = addr - sym->st_value;
78548 if (d < distance) {
78549 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
78550 tosym, prl_to, prl_to, tosym);
78551 free(prl_to);
78552 break;
78553 + case DATA_TO_TEXT:
78554 +/*
78555 + fprintf(stderr,
78556 + "The variable %s references\n"
78557 + "the %s %s%s%s\n",
78558 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78559 +*/
78560 + break;
78561 }
78562 fprintf(stderr, "\n");
78563 }
78564 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78565 static void check_sec_ref(struct module *mod, const char *modname,
78566 struct elf_info *elf)
78567 {
78568 - int i;
78569 + unsigned int i;
78570 Elf_Shdr *sechdrs = elf->sechdrs;
78571
78572 /* Walk through all sections */
78573 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78574 va_end(ap);
78575 }
78576
78577 -void buf_write(struct buffer *buf, const char *s, int len)
78578 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78579 {
78580 if (buf->size - buf->pos < len) {
78581 buf->size += len + SZ;
78582 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78583 if (fstat(fileno(file), &st) < 0)
78584 goto close_write;
78585
78586 - if (st.st_size != b->pos)
78587 + if (st.st_size != (off_t)b->pos)
78588 goto close_write;
78589
78590 tmp = NOFAIL(malloc(b->pos));
78591 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78592 index 51207e4..f7d603d 100644
78593 --- a/scripts/mod/modpost.h
78594 +++ b/scripts/mod/modpost.h
78595 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78596
78597 struct buffer {
78598 char *p;
78599 - int pos;
78600 - int size;
78601 + unsigned int pos;
78602 + unsigned int size;
78603 };
78604
78605 void __attribute__((format(printf, 2, 3)))
78606 buf_printf(struct buffer *buf, const char *fmt, ...);
78607
78608 void
78609 -buf_write(struct buffer *buf, const char *s, int len);
78610 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78611
78612 struct module {
78613 struct module *next;
78614 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78615 index 9dfcd6d..099068e 100644
78616 --- a/scripts/mod/sumversion.c
78617 +++ b/scripts/mod/sumversion.c
78618 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78619 goto out;
78620 }
78621
78622 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78623 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78624 warn("writing sum in %s failed: %s\n",
78625 filename, strerror(errno));
78626 goto out;
78627 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78628 index 5c11312..72742b5 100644
78629 --- a/scripts/pnmtologo.c
78630 +++ b/scripts/pnmtologo.c
78631 @@ -237,14 +237,14 @@ static void write_header(void)
78632 fprintf(out, " * Linux logo %s\n", logoname);
78633 fputs(" */\n\n", out);
78634 fputs("#include <linux/linux_logo.h>\n\n", out);
78635 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78636 + fprintf(out, "static unsigned char %s_data[] = {\n",
78637 logoname);
78638 }
78639
78640 static void write_footer(void)
78641 {
78642 fputs("\n};\n\n", out);
78643 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78644 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78645 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78646 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78647 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78648 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78649 fputs("\n};\n\n", out);
78650
78651 /* write logo clut */
78652 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78653 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78654 logoname);
78655 write_hex_cnt = 0;
78656 for (i = 0; i < logo_clutsize; i++) {
78657 diff --git a/scripts/tags.sh b/scripts/tags.sh
78658 index 833813a..0bc8588 100755
78659 --- a/scripts/tags.sh
78660 +++ b/scripts/tags.sh
78661 @@ -116,7 +116,7 @@ docscope()
78662
78663 dogtags()
78664 {
78665 - all_sources | gtags -f -
78666 + all_sources | gtags -i -f -
78667 }
78668
78669 exuberant()
78670 diff --git a/security/Kconfig b/security/Kconfig
78671 index 51bd5a0..c37f5e6 100644
78672 --- a/security/Kconfig
78673 +++ b/security/Kconfig
78674 @@ -4,6 +4,640 @@
78675
78676 menu "Security options"
78677
78678 +source grsecurity/Kconfig
78679 +
78680 +menu "PaX"
78681 +
78682 + config ARCH_TRACK_EXEC_LIMIT
78683 + bool
78684 +
78685 + config PAX_KERNEXEC_PLUGIN
78686 + bool
78687 +
78688 + config PAX_PER_CPU_PGD
78689 + bool
78690 +
78691 + config TASK_SIZE_MAX_SHIFT
78692 + int
78693 + depends on X86_64
78694 + default 47 if !PAX_PER_CPU_PGD
78695 + default 42 if PAX_PER_CPU_PGD
78696 +
78697 + config PAX_ENABLE_PAE
78698 + bool
78699 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78700 +
78701 +config PAX
78702 + bool "Enable various PaX features"
78703 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78704 + help
78705 + This allows you to enable various PaX features. PaX adds
78706 + intrusion prevention mechanisms to the kernel that reduce
78707 + the risks posed by exploitable memory corruption bugs.
78708 +
78709 +menu "PaX Control"
78710 + depends on PAX
78711 +
78712 +config PAX_SOFTMODE
78713 + bool 'Support soft mode'
78714 + help
78715 + Enabling this option will allow you to run PaX in soft mode, that
78716 + is, PaX features will not be enforced by default, only on executables
78717 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78718 + support as they are the only way to mark executables for soft mode use.
78719 +
78720 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78721 + line option on boot. Furthermore you can control various PaX features
78722 + at runtime via the entries in /proc/sys/kernel/pax.
78723 +
78724 +config PAX_EI_PAX
78725 + bool 'Use legacy ELF header marking'
78726 + help
78727 + Enabling this option will allow you to control PaX features on
78728 + a per executable basis via the 'chpax' utility available at
78729 + http://pax.grsecurity.net/. The control flags will be read from
78730 + an otherwise reserved part of the ELF header. This marking has
78731 + numerous drawbacks (no support for soft-mode, toolchain does not
78732 + know about the non-standard use of the ELF header) therefore it
78733 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78734 + support.
78735 +
78736 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78737 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78738 + option otherwise they will not get any protection.
78739 +
78740 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78741 + support as well, they will override the legacy EI_PAX marks.
78742 +
78743 +config PAX_PT_PAX_FLAGS
78744 + bool 'Use ELF program header marking'
78745 + help
78746 + Enabling this option will allow you to control PaX features on
78747 + a per executable basis via the 'paxctl' utility available at
78748 + http://pax.grsecurity.net/. The control flags will be read from
78749 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78750 + has the benefits of supporting both soft mode and being fully
78751 + integrated into the toolchain (the binutils patch is available
78752 + from http://pax.grsecurity.net).
78753 +
78754 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78755 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78756 + support otherwise they will not get any protection.
78757 +
78758 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78759 + must make sure that the marks are the same if a binary has both marks.
78760 +
78761 + Note that if you enable the legacy EI_PAX marking support as well,
78762 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78763 +
78764 +config PAX_XATTR_PAX_FLAGS
78765 + bool 'Use filesystem extended attributes marking'
78766 + select CIFS_XATTR if CIFS
78767 + select EXT2_FS_XATTR if EXT2_FS
78768 + select EXT3_FS_XATTR if EXT3_FS
78769 + select EXT4_FS_XATTR if EXT4_FS
78770 + select JFFS2_FS_XATTR if JFFS2_FS
78771 + select REISERFS_FS_XATTR if REISERFS_FS
78772 + select SQUASHFS_XATTR if SQUASHFS
78773 + select TMPFS_XATTR if TMPFS
78774 + select UBIFS_FS_XATTR if UBIFS_FS
78775 + help
78776 + Enabling this option will allow you to control PaX features on
78777 + a per executable basis via the 'setfattr' utility. The control
78778 + flags will be read from the user.pax.flags extended attribute of
78779 + the file. This marking has the benefit of supporting binary-only
78780 + applications that self-check themselves (e.g., skype) and would
78781 + not tolerate chpax/paxctl changes. The main drawback is that
78782 + extended attributes are not supported by some filesystems (e.g.,
78783 + isofs, udf, vfat) so copying files through such filesystems will
78784 + lose the extended attributes and these PaX markings.
78785 +
78786 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78787 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78788 + support otherwise they will not get any protection.
78789 +
78790 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78791 + must make sure that the marks are the same if a binary has both marks.
78792 +
78793 + Note that if you enable the legacy EI_PAX marking support as well,
78794 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78795 +
78796 +choice
78797 + prompt 'MAC system integration'
78798 + default PAX_HAVE_ACL_FLAGS
78799 + help
78800 + Mandatory Access Control systems have the option of controlling
78801 + PaX flags on a per executable basis, choose the method supported
78802 + by your particular system.
78803 +
78804 + - "none": if your MAC system does not interact with PaX,
78805 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78806 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78807 +
78808 + NOTE: this option is for developers/integrators only.
78809 +
78810 + config PAX_NO_ACL_FLAGS
78811 + bool 'none'
78812 +
78813 + config PAX_HAVE_ACL_FLAGS
78814 + bool 'direct'
78815 +
78816 + config PAX_HOOK_ACL_FLAGS
78817 + bool 'hook'
78818 +endchoice
78819 +
78820 +endmenu
78821 +
78822 +menu "Non-executable pages"
78823 + depends on PAX
78824 +
78825 +config PAX_NOEXEC
78826 + bool "Enforce non-executable pages"
78827 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78828 + help
78829 + By design some architectures do not allow for protecting memory
78830 + pages against execution or even if they do, Linux does not make
78831 + use of this feature. In practice this means that if a page is
78832 + readable (such as the stack or heap) it is also executable.
78833 +
78834 + There is a well known exploit technique that makes use of this
78835 + fact and a common programming mistake where an attacker can
78836 + introduce code of his choice somewhere in the attacked program's
78837 + memory (typically the stack or the heap) and then execute it.
78838 +
78839 + If the attacked program was running with different (typically
78840 + higher) privileges than that of the attacker, then he can elevate
78841 + his own privilege level (e.g. get a root shell, write to files for
78842 + which he does not have write access to, etc).
78843 +
78844 + Enabling this option will let you choose from various features
78845 + that prevent the injection and execution of 'foreign' code in
78846 + a program.
78847 +
78848 + This will also break programs that rely on the old behaviour and
78849 + expect that dynamically allocated memory via the malloc() family
78850 + of functions is executable (which it is not). Notable examples
78851 + are the XFree86 4.x server, the java runtime and wine.
78852 +
78853 +config PAX_PAGEEXEC
78854 + bool "Paging based non-executable pages"
78855 + 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)
78856 + select S390_SWITCH_AMODE if S390
78857 + select S390_EXEC_PROTECT if S390
78858 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78859 + help
78860 + This implementation is based on the paging feature of the CPU.
78861 + On i386 without hardware non-executable bit support there is a
78862 + variable but usually low performance impact, however on Intel's
78863 + P4 core based CPUs it is very high so you should not enable this
78864 + for kernels meant to be used on such CPUs.
78865 +
78866 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78867 + with hardware non-executable bit support there is no performance
78868 + impact, on ppc the impact is negligible.
78869 +
78870 + Note that several architectures require various emulations due to
78871 + badly designed userland ABIs, this will cause a performance impact
78872 + but will disappear as soon as userland is fixed. For example, ppc
78873 + userland MUST have been built with secure-plt by a recent toolchain.
78874 +
78875 +config PAX_SEGMEXEC
78876 + bool "Segmentation based non-executable pages"
78877 + depends on PAX_NOEXEC && X86_32
78878 + help
78879 + This implementation is based on the segmentation feature of the
78880 + CPU and has a very small performance impact, however applications
78881 + will be limited to a 1.5 GB address space instead of the normal
78882 + 3 GB.
78883 +
78884 +config PAX_EMUTRAMP
78885 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78886 + default y if PARISC
78887 + help
78888 + There are some programs and libraries that for one reason or
78889 + another attempt to execute special small code snippets from
78890 + non-executable memory pages. Most notable examples are the
78891 + signal handler return code generated by the kernel itself and
78892 + the GCC trampolines.
78893 +
78894 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78895 + such programs will no longer work under your kernel.
78896 +
78897 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78898 + utilities to enable trampoline emulation for the affected programs
78899 + yet still have the protection provided by the non-executable pages.
78900 +
78901 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78902 + your system will not even boot.
78903 +
78904 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78905 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78906 + for the affected files.
78907 +
78908 + NOTE: enabling this feature *may* open up a loophole in the
78909 + protection provided by non-executable pages that an attacker
78910 + could abuse. Therefore the best solution is to not have any
78911 + files on your system that would require this option. This can
78912 + be achieved by not using libc5 (which relies on the kernel
78913 + signal handler return code) and not using or rewriting programs
78914 + that make use of the nested function implementation of GCC.
78915 + Skilled users can just fix GCC itself so that it implements
78916 + nested function calls in a way that does not interfere with PaX.
78917 +
78918 +config PAX_EMUSIGRT
78919 + bool "Automatically emulate sigreturn trampolines"
78920 + depends on PAX_EMUTRAMP && PARISC
78921 + default y
78922 + help
78923 + Enabling this option will have the kernel automatically detect
78924 + and emulate signal return trampolines executing on the stack
78925 + that would otherwise lead to task termination.
78926 +
78927 + This solution is intended as a temporary one for users with
78928 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78929 + Modula-3 runtime, etc) or executables linked to such, basically
78930 + everything that does not specify its own SA_RESTORER function in
78931 + normal executable memory like glibc 2.1+ does.
78932 +
78933 + On parisc you MUST enable this option, otherwise your system will
78934 + not even boot.
78935 +
78936 + NOTE: this feature cannot be disabled on a per executable basis
78937 + and since it *does* open up a loophole in the protection provided
78938 + by non-executable pages, the best solution is to not have any
78939 + files on your system that would require this option.
78940 +
78941 +config PAX_MPROTECT
78942 + bool "Restrict mprotect()"
78943 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78944 + help
78945 + Enabling this option will prevent programs from
78946 + - changing the executable status of memory pages that were
78947 + not originally created as executable,
78948 + - making read-only executable pages writable again,
78949 + - creating executable pages from anonymous memory,
78950 + - making read-only-after-relocations (RELRO) data pages writable again.
78951 +
78952 + You should say Y here to complete the protection provided by
78953 + the enforcement of non-executable pages.
78954 +
78955 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78956 + this feature on a per file basis.
78957 +
78958 +config PAX_MPROTECT_COMPAT
78959 + bool "Use legacy/compat protection demoting (read help)"
78960 + depends on PAX_MPROTECT
78961 + default n
78962 + help
78963 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78964 + by sending the proper error code to the application. For some broken
78965 + userland, this can cause problems with Python or other applications. The
78966 + current implementation however allows for applications like clamav to
78967 + detect if JIT compilation/execution is allowed and to fall back gracefully
78968 + to an interpreter-based mode if it does not. While we encourage everyone
78969 + to use the current implementation as-is and push upstream to fix broken
78970 + userland (note that the RWX logging option can assist with this), in some
78971 + environments this may not be possible. Having to disable MPROTECT
78972 + completely on certain binaries reduces the security benefit of PaX,
78973 + so this option is provided for those environments to revert to the old
78974 + behavior.
78975 +
78976 +config PAX_ELFRELOCS
78977 + bool "Allow ELF text relocations (read help)"
78978 + depends on PAX_MPROTECT
78979 + default n
78980 + help
78981 + Non-executable pages and mprotect() restrictions are effective
78982 + in preventing the introduction of new executable code into an
78983 + attacked task's address space. There remain only two venues
78984 + for this kind of attack: if the attacker can execute already
78985 + existing code in the attacked task then he can either have it
78986 + create and mmap() a file containing his code or have it mmap()
78987 + an already existing ELF library that does not have position
78988 + independent code in it and use mprotect() on it to make it
78989 + writable and copy his code there. While protecting against
78990 + the former approach is beyond PaX, the latter can be prevented
78991 + by having only PIC ELF libraries on one's system (which do not
78992 + need to relocate their code). If you are sure this is your case,
78993 + as is the case with all modern Linux distributions, then leave
78994 + this option disabled. You should say 'n' here.
78995 +
78996 +config PAX_ETEXECRELOCS
78997 + bool "Allow ELF ET_EXEC text relocations"
78998 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78999 + select PAX_ELFRELOCS
79000 + default y
79001 + help
79002 + On some architectures there are incorrectly created applications
79003 + that require text relocations and would not work without enabling
79004 + this option. If you are an alpha, ia64 or parisc user, you should
79005 + enable this option and disable it once you have made sure that
79006 + none of your applications need it.
79007 +
79008 +config PAX_EMUPLT
79009 + bool "Automatically emulate ELF PLT"
79010 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79011 + default y
79012 + help
79013 + Enabling this option will have the kernel automatically detect
79014 + and emulate the Procedure Linkage Table entries in ELF files.
79015 + On some architectures such entries are in writable memory, and
79016 + become non-executable leading to task termination. Therefore
79017 + it is mandatory that you enable this option on alpha, parisc,
79018 + sparc and sparc64, otherwise your system would not even boot.
79019 +
79020 + NOTE: this feature *does* open up a loophole in the protection
79021 + provided by the non-executable pages, therefore the proper
79022 + solution is to modify the toolchain to produce a PLT that does
79023 + not need to be writable.
79024 +
79025 +config PAX_DLRESOLVE
79026 + bool 'Emulate old glibc resolver stub'
79027 + depends on PAX_EMUPLT && SPARC
79028 + default n
79029 + help
79030 + This option is needed if userland has an old glibc (before 2.4)
79031 + that puts a 'save' instruction into the runtime generated resolver
79032 + stub that needs special emulation.
79033 +
79034 +config PAX_KERNEXEC
79035 + bool "Enforce non-executable kernel pages"
79036 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79037 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79038 + select PAX_KERNEXEC_PLUGIN if X86_64
79039 + help
79040 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79041 + that is, enabling this option will make it harder to inject
79042 + and execute 'foreign' code in kernel memory itself.
79043 +
79044 + Note that on x86_64 kernels there is a known regression when
79045 + this feature and KVM/VMX are both enabled in the host kernel.
79046 +
79047 +choice
79048 + prompt "Return Address Instrumentation Method"
79049 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79050 + depends on PAX_KERNEXEC_PLUGIN
79051 + help
79052 + Select the method used to instrument function pointer dereferences.
79053 + Note that binary modules cannot be instrumented by this approach.
79054 +
79055 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79056 + bool "bts"
79057 + help
79058 + This method is compatible with binary only modules but has
79059 + a higher runtime overhead.
79060 +
79061 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79062 + bool "or"
79063 + depends on !PARAVIRT
79064 + help
79065 + This method is incompatible with binary only modules but has
79066 + a lower runtime overhead.
79067 +endchoice
79068 +
79069 +config PAX_KERNEXEC_PLUGIN_METHOD
79070 + string
79071 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79072 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79073 + default ""
79074 +
79075 +config PAX_KERNEXEC_MODULE_TEXT
79076 + int "Minimum amount of memory reserved for module code"
79077 + default "4"
79078 + depends on PAX_KERNEXEC && X86_32 && MODULES
79079 + help
79080 + Due to implementation details the kernel must reserve a fixed
79081 + amount of memory for module code at compile time that cannot be
79082 + changed at runtime. Here you can specify the minimum amount
79083 + in MB that will be reserved. Due to the same implementation
79084 + details this size will always be rounded up to the next 2/4 MB
79085 + boundary (depends on PAE) so the actually available memory for
79086 + module code will usually be more than this minimum.
79087 +
79088 + The default 4 MB should be enough for most users but if you have
79089 + an excessive number of modules (e.g., most distribution configs
79090 + compile many drivers as modules) or use huge modules such as
79091 + nvidia's kernel driver, you will need to adjust this amount.
79092 + A good rule of thumb is to look at your currently loaded kernel
79093 + modules and add up their sizes.
79094 +
79095 +endmenu
79096 +
79097 +menu "Address Space Layout Randomization"
79098 + depends on PAX
79099 +
79100 +config PAX_ASLR
79101 + bool "Address Space Layout Randomization"
79102 + help
79103 + Many if not most exploit techniques rely on the knowledge of
79104 + certain addresses in the attacked program. The following options
79105 + will allow the kernel to apply a certain amount of randomization
79106 + to specific parts of the program thereby forcing an attacker to
79107 + guess them in most cases. Any failed guess will most likely crash
79108 + the attacked program which allows the kernel to detect such attempts
79109 + and react on them. PaX itself provides no reaction mechanisms,
79110 + instead it is strongly encouraged that you make use of Nergal's
79111 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79112 + (http://www.grsecurity.net/) built-in crash detection features or
79113 + develop one yourself.
79114 +
79115 + By saying Y here you can choose to randomize the following areas:
79116 + - top of the task's kernel stack
79117 + - top of the task's userland stack
79118 + - base address for mmap() requests that do not specify one
79119 + (this includes all libraries)
79120 + - base address of the main executable
79121 +
79122 + It is strongly recommended to say Y here as address space layout
79123 + randomization has negligible impact on performance yet it provides
79124 + a very effective protection.
79125 +
79126 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79127 + this feature on a per file basis.
79128 +
79129 +config PAX_RANDKSTACK
79130 + bool "Randomize kernel stack base"
79131 + depends on X86_TSC && X86
79132 + help
79133 + By saying Y here the kernel will randomize every task's kernel
79134 + stack on every system call. This will not only force an attacker
79135 + to guess it but also prevent him from making use of possible
79136 + leaked information about it.
79137 +
79138 + Since the kernel stack is a rather scarce resource, randomization
79139 + may cause unexpected stack overflows, therefore you should very
79140 + carefully test your system. Note that once enabled in the kernel
79141 + configuration, this feature cannot be disabled on a per file basis.
79142 +
79143 +config PAX_RANDUSTACK
79144 + bool "Randomize user stack base"
79145 + depends on PAX_ASLR
79146 + help
79147 + By saying Y here the kernel will randomize every task's userland
79148 + stack. The randomization is done in two steps where the second
79149 + one may apply a big amount of shift to the top of the stack and
79150 + cause problems for programs that want to use lots of memory (more
79151 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79152 + For this reason the second step can be controlled by 'chpax' or
79153 + 'paxctl' on a per file basis.
79154 +
79155 +config PAX_RANDMMAP
79156 + bool "Randomize mmap() base"
79157 + depends on PAX_ASLR
79158 + help
79159 + By saying Y here the kernel will use a randomized base address for
79160 + mmap() requests that do not specify one themselves. As a result
79161 + all dynamically loaded libraries will appear at random addresses
79162 + and therefore be harder to exploit by a technique where an attacker
79163 + attempts to execute library code for his purposes (e.g. spawn a
79164 + shell from an exploited program that is running at an elevated
79165 + privilege level).
79166 +
79167 + Furthermore, if a program is relinked as a dynamic ELF file, its
79168 + base address will be randomized as well, completing the full
79169 + randomization of the address space layout. Attacking such programs
79170 + becomes a guess game. You can find an example of doing this at
79171 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79172 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79173 +
79174 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79175 + feature on a per file basis.
79176 +
79177 +endmenu
79178 +
79179 +menu "Miscellaneous hardening features"
79180 +
79181 +config PAX_MEMORY_SANITIZE
79182 + bool "Sanitize all freed memory"
79183 + depends on !HIBERNATION
79184 + help
79185 + By saying Y here the kernel will erase memory pages as soon as they
79186 + are freed. This in turn reduces the lifetime of data stored in the
79187 + pages, making it less likely that sensitive information such as
79188 + passwords, cryptographic secrets, etc stay in memory for too long.
79189 +
79190 + This is especially useful for programs whose runtime is short, long
79191 + lived processes and the kernel itself benefit from this as long as
79192 + they operate on whole memory pages and ensure timely freeing of pages
79193 + that may hold sensitive information.
79194 +
79195 + The tradeoff is performance impact, on a single CPU system kernel
79196 + compilation sees a 3% slowdown, other systems and workloads may vary
79197 + and you are advised to test this feature on your expected workload
79198 + before deploying it.
79199 +
79200 + Note that this feature does not protect data stored in live pages,
79201 + e.g., process memory swapped to disk may stay there for a long time.
79202 +
79203 +config PAX_MEMORY_STACKLEAK
79204 + bool "Sanitize kernel stack"
79205 + depends on X86
79206 + help
79207 + By saying Y here the kernel will erase the kernel stack before it
79208 + returns from a system call. This in turn reduces the information
79209 + that a kernel stack leak bug can reveal.
79210 +
79211 + Note that such a bug can still leak information that was put on
79212 + the stack by the current system call (the one eventually triggering
79213 + the bug) but traces of earlier system calls on the kernel stack
79214 + cannot leak anymore.
79215 +
79216 + The tradeoff is performance impact: on a single CPU system kernel
79217 + compilation sees a 1% slowdown, other systems and workloads may vary
79218 + and you are advised to test this feature on your expected workload
79219 + before deploying it.
79220 +
79221 + Note: full support for this feature requires gcc with plugin support
79222 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79223 + versions means that functions with large enough stack frames may
79224 + leave uninitialized memory behind that may be exposed to a later
79225 + syscall leaking the stack.
79226 +
79227 +config PAX_MEMORY_UDEREF
79228 + bool "Prevent invalid userland pointer dereference"
79229 + depends on X86 && !UML_X86 && !XEN
79230 + select PAX_PER_CPU_PGD if X86_64
79231 + help
79232 + By saying Y here the kernel will be prevented from dereferencing
79233 + userland pointers in contexts where the kernel expects only kernel
79234 + pointers. This is both a useful runtime debugging feature and a
79235 + security measure that prevents exploiting a class of kernel bugs.
79236 +
79237 + The tradeoff is that some virtualization solutions may experience
79238 + a huge slowdown and therefore you should not enable this feature
79239 + for kernels meant to run in such environments. Whether a given VM
79240 + solution is affected or not is best determined by simply trying it
79241 + out, the performance impact will be obvious right on boot as this
79242 + mechanism engages from very early on. A good rule of thumb is that
79243 + VMs running on CPUs without hardware virtualization support (i.e.,
79244 + the majority of IA-32 CPUs) will likely experience the slowdown.
79245 +
79246 +config PAX_REFCOUNT
79247 + bool "Prevent various kernel object reference counter overflows"
79248 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79249 + help
79250 + By saying Y here the kernel will detect and prevent overflowing
79251 + various (but not all) kinds of object reference counters. Such
79252 + overflows can normally occur due to bugs only and are often, if
79253 + not always, exploitable.
79254 +
79255 + The tradeoff is that data structures protected by an overflowed
79256 + refcount will never be freed and therefore will leak memory. Note
79257 + that this leak also happens even without this protection but in
79258 + that case the overflow can eventually trigger the freeing of the
79259 + data structure while it is still being used elsewhere, resulting
79260 + in the exploitable situation that this feature prevents.
79261 +
79262 + Since this has a negligible performance impact, you should enable
79263 + this feature.
79264 +
79265 +config PAX_USERCOPY
79266 + bool "Harden heap object copies between kernel and userland"
79267 + depends on X86 || PPC || SPARC || ARM
79268 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79269 + help
79270 + By saying Y here the kernel will enforce the size of heap objects
79271 + when they are copied in either direction between the kernel and
79272 + userland, even if only a part of the heap object is copied.
79273 +
79274 + Specifically, this checking prevents information leaking from the
79275 + kernel heap during kernel to userland copies (if the kernel heap
79276 + object is otherwise fully initialized) and prevents kernel heap
79277 + overflows during userland to kernel copies.
79278 +
79279 + Note that the current implementation provides the strictest bounds
79280 + checks for the SLUB allocator.
79281 +
79282 + Enabling this option also enables per-slab cache protection against
79283 + data in a given cache being copied into/out of via userland
79284 + accessors. Though the whitelist of regions will be reduced over
79285 + time, it notably protects important data structures like task structs.
79286 +
79287 + If frame pointers are enabled on x86, this option will also restrict
79288 + copies into and out of the kernel stack to local variables within a
79289 + single frame.
79290 +
79291 + Since this has a negligible performance impact, you should enable
79292 + this feature.
79293 +
79294 +config PAX_SIZE_OVERFLOW
79295 + bool "Prevent various integer overflows in function size parameters"
79296 + depends on X86
79297 + help
79298 + By saying Y here the kernel recomputes expressions of function
79299 + arguments marked by a size_overflow attribute with double integer
79300 + precision (DImode/TImode for 32/64 bit integer types).
79301 +
79302 + The recomputed argument is checked against INT_MAX and an event
79303 + is logged on overflow and the triggering process is killed.
79304 +
79305 + Homepage:
79306 + http://www.grsecurity.net/~ephox/overflow_plugin/
79307 +
79308 +endmenu
79309 +
79310 +endmenu
79311 +
79312 config KEYS
79313 bool "Enable access key retention support"
79314 help
79315 @@ -169,7 +803,7 @@ config INTEL_TXT
79316 config LSM_MMAP_MIN_ADDR
79317 int "Low address space for LSM to protect from user allocation"
79318 depends on SECURITY && SECURITY_SELINUX
79319 - default 32768 if ARM
79320 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79321 default 65536
79322 help
79323 This is the portion of low virtual memory which should be protected
79324 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79325 index 97ce8fa..23dad96 100644
79326 --- a/security/apparmor/lsm.c
79327 +++ b/security/apparmor/lsm.c
79328 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79329 return error;
79330 }
79331
79332 -static struct security_operations apparmor_ops = {
79333 +static struct security_operations apparmor_ops __read_only = {
79334 .name = "apparmor",
79335
79336 .ptrace_access_check = apparmor_ptrace_access_check,
79337 diff --git a/security/commoncap.c b/security/commoncap.c
79338 index 7ce191e..6c29c34 100644
79339 --- a/security/commoncap.c
79340 +++ b/security/commoncap.c
79341 @@ -28,6 +28,7 @@
79342 #include <linux/prctl.h>
79343 #include <linux/securebits.h>
79344 #include <linux/user_namespace.h>
79345 +#include <net/sock.h>
79346
79347 /*
79348 * If a non-root user executes a setuid-root binary in
79349 @@ -569,6 +570,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79350 {
79351 const struct cred *cred = current_cred();
79352
79353 + if (gr_acl_enable_at_secure())
79354 + return 1;
79355 +
79356 if (cred->uid != 0) {
79357 if (bprm->cap_effective)
79358 return 1;
79359 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79360 index 3ccf7ac..d73ad64 100644
79361 --- a/security/integrity/ima/ima.h
79362 +++ b/security/integrity/ima/ima.h
79363 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79364 extern spinlock_t ima_queue_lock;
79365
79366 struct ima_h_table {
79367 - atomic_long_t len; /* number of stored measurements in the list */
79368 - atomic_long_t violations;
79369 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79370 + atomic_long_unchecked_t violations;
79371 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79372 };
79373 extern struct ima_h_table ima_htable;
79374 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79375 index 88a2788..581ab92 100644
79376 --- a/security/integrity/ima/ima_api.c
79377 +++ b/security/integrity/ima/ima_api.c
79378 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79379 int result;
79380
79381 /* can overflow, only indicator */
79382 - atomic_long_inc(&ima_htable.violations);
79383 + atomic_long_inc_unchecked(&ima_htable.violations);
79384
79385 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79386 if (!entry) {
79387 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79388 index e1aa2b4..52027bf 100644
79389 --- a/security/integrity/ima/ima_fs.c
79390 +++ b/security/integrity/ima/ima_fs.c
79391 @@ -28,12 +28,12 @@
79392 static int valid_policy = 1;
79393 #define TMPBUFLEN 12
79394 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79395 - loff_t *ppos, atomic_long_t *val)
79396 + loff_t *ppos, atomic_long_unchecked_t *val)
79397 {
79398 char tmpbuf[TMPBUFLEN];
79399 ssize_t len;
79400
79401 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79402 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79403 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79404 }
79405
79406 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79407 index 55a6271..ad829c3 100644
79408 --- a/security/integrity/ima/ima_queue.c
79409 +++ b/security/integrity/ima/ima_queue.c
79410 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79411 INIT_LIST_HEAD(&qe->later);
79412 list_add_tail_rcu(&qe->later, &ima_measurements);
79413
79414 - atomic_long_inc(&ima_htable.len);
79415 + atomic_long_inc_unchecked(&ima_htable.len);
79416 key = ima_hash_key(entry->digest);
79417 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79418 return 0;
79419 diff --git a/security/keys/compat.c b/security/keys/compat.c
79420 index 4c48e13..7abdac9 100644
79421 --- a/security/keys/compat.c
79422 +++ b/security/keys/compat.c
79423 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79424 if (ret == 0)
79425 goto no_payload_free;
79426
79427 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79428 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79429
79430 if (iov != iovstack)
79431 kfree(iov);
79432 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79433 index 0b3f5d7..892c8a6 100644
79434 --- a/security/keys/keyctl.c
79435 +++ b/security/keys/keyctl.c
79436 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79437 /*
79438 * Copy the iovec data from userspace
79439 */
79440 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79441 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79442 unsigned ioc)
79443 {
79444 for (; ioc > 0; ioc--) {
79445 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79446 * If successful, 0 will be returned.
79447 */
79448 long keyctl_instantiate_key_common(key_serial_t id,
79449 - const struct iovec *payload_iov,
79450 + const struct iovec __user *payload_iov,
79451 unsigned ioc,
79452 size_t plen,
79453 key_serial_t ringid)
79454 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79455 [0].iov_len = plen
79456 };
79457
79458 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79459 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79460 }
79461
79462 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79463 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79464 if (ret == 0)
79465 goto no_payload_free;
79466
79467 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79468 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79469
79470 if (iov != iovstack)
79471 kfree(iov);
79472 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79473 index d605f75..2bc6be9 100644
79474 --- a/security/keys/keyring.c
79475 +++ b/security/keys/keyring.c
79476 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79477 ret = -EFAULT;
79478
79479 for (loop = 0; loop < klist->nkeys; loop++) {
79480 + key_serial_t serial;
79481 key = klist->keys[loop];
79482 + serial = key->serial;
79483
79484 tmp = sizeof(key_serial_t);
79485 if (tmp > buflen)
79486 tmp = buflen;
79487
79488 - if (copy_to_user(buffer,
79489 - &key->serial,
79490 - tmp) != 0)
79491 + if (copy_to_user(buffer, &serial, tmp))
79492 goto error;
79493
79494 buflen -= tmp;
79495 diff --git a/security/min_addr.c b/security/min_addr.c
79496 index f728728..6457a0c 100644
79497 --- a/security/min_addr.c
79498 +++ b/security/min_addr.c
79499 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79500 */
79501 static void update_mmap_min_addr(void)
79502 {
79503 +#ifndef SPARC
79504 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79505 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79506 mmap_min_addr = dac_mmap_min_addr;
79507 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79508 #else
79509 mmap_min_addr = dac_mmap_min_addr;
79510 #endif
79511 +#endif
79512 }
79513
79514 /*
79515 diff --git a/security/security.c b/security/security.c
79516 index d754249..8bf426e 100644
79517 --- a/security/security.c
79518 +++ b/security/security.c
79519 @@ -26,8 +26,8 @@
79520 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79521 CONFIG_DEFAULT_SECURITY;
79522
79523 -static struct security_operations *security_ops;
79524 -static struct security_operations default_security_ops = {
79525 +static struct security_operations *security_ops __read_only;
79526 +static struct security_operations default_security_ops __read_only = {
79527 .name = "default",
79528 };
79529
79530 @@ -68,7 +68,9 @@ int __init security_init(void)
79531
79532 void reset_security_ops(void)
79533 {
79534 + pax_open_kernel();
79535 security_ops = &default_security_ops;
79536 + pax_close_kernel();
79537 }
79538
79539 /* Save user chosen LSM */
79540 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79541 index 6a3683e..f52f4c0 100644
79542 --- a/security/selinux/hooks.c
79543 +++ b/security/selinux/hooks.c
79544 @@ -94,8 +94,6 @@
79545
79546 #define NUM_SEL_MNT_OPTS 5
79547
79548 -extern struct security_operations *security_ops;
79549 -
79550 /* SECMARK reference count */
79551 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79552
79553 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79554
79555 #endif
79556
79557 -static struct security_operations selinux_ops = {
79558 +static struct security_operations selinux_ops __read_only = {
79559 .name = "selinux",
79560
79561 .ptrace_access_check = selinux_ptrace_access_check,
79562 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79563 index b43813c..74be837 100644
79564 --- a/security/selinux/include/xfrm.h
79565 +++ b/security/selinux/include/xfrm.h
79566 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79567
79568 static inline void selinux_xfrm_notify_policyload(void)
79569 {
79570 - atomic_inc(&flow_cache_genid);
79571 + atomic_inc_unchecked(&flow_cache_genid);
79572 }
79573 #else
79574 static inline int selinux_xfrm_enabled(void)
79575 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79576 index e8af5b0b..78527ef 100644
79577 --- a/security/smack/smack_lsm.c
79578 +++ b/security/smack/smack_lsm.c
79579 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79580 return 0;
79581 }
79582
79583 -struct security_operations smack_ops = {
79584 +struct security_operations smack_ops __read_only = {
79585 .name = "smack",
79586
79587 .ptrace_access_check = smack_ptrace_access_check,
79588 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79589 index 620d37c..e2ad89b 100644
79590 --- a/security/tomoyo/tomoyo.c
79591 +++ b/security/tomoyo/tomoyo.c
79592 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79593 * tomoyo_security_ops is a "struct security_operations" which is used for
79594 * registering TOMOYO.
79595 */
79596 -static struct security_operations tomoyo_security_ops = {
79597 +static struct security_operations tomoyo_security_ops __read_only = {
79598 .name = "tomoyo",
79599 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79600 .cred_prepare = tomoyo_cred_prepare,
79601 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79602 index 762af68..7103453 100644
79603 --- a/sound/aoa/codecs/onyx.c
79604 +++ b/sound/aoa/codecs/onyx.c
79605 @@ -54,7 +54,7 @@ struct onyx {
79606 spdif_locked:1,
79607 analog_locked:1,
79608 original_mute:2;
79609 - int open_count;
79610 + local_t open_count;
79611 struct codec_info *codec_info;
79612
79613 /* mutex serializes concurrent access to the device
79614 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79615 struct onyx *onyx = cii->codec_data;
79616
79617 mutex_lock(&onyx->mutex);
79618 - onyx->open_count++;
79619 + local_inc(&onyx->open_count);
79620 mutex_unlock(&onyx->mutex);
79621
79622 return 0;
79623 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79624 struct onyx *onyx = cii->codec_data;
79625
79626 mutex_lock(&onyx->mutex);
79627 - onyx->open_count--;
79628 - if (!onyx->open_count)
79629 + if (local_dec_and_test(&onyx->open_count))
79630 onyx->spdif_locked = onyx->analog_locked = 0;
79631 mutex_unlock(&onyx->mutex);
79632
79633 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79634 index ffd2025..df062c9 100644
79635 --- a/sound/aoa/codecs/onyx.h
79636 +++ b/sound/aoa/codecs/onyx.h
79637 @@ -11,6 +11,7 @@
79638 #include <linux/i2c.h>
79639 #include <asm/pmac_low_i2c.h>
79640 #include <asm/prom.h>
79641 +#include <asm/local.h>
79642
79643 /* PCM3052 register definitions */
79644
79645 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79646 index 08fde00..0bf641a 100644
79647 --- a/sound/core/oss/pcm_oss.c
79648 +++ b/sound/core/oss/pcm_oss.c
79649 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79650 if (in_kernel) {
79651 mm_segment_t fs;
79652 fs = snd_enter_user();
79653 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79654 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79655 snd_leave_user(fs);
79656 } else {
79657 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79658 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79659 }
79660 if (ret != -EPIPE && ret != -ESTRPIPE)
79661 break;
79662 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79663 if (in_kernel) {
79664 mm_segment_t fs;
79665 fs = snd_enter_user();
79666 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79667 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79668 snd_leave_user(fs);
79669 } else {
79670 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79671 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79672 }
79673 if (ret == -EPIPE) {
79674 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79675 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79676 struct snd_pcm_plugin_channel *channels;
79677 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79678 if (!in_kernel) {
79679 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79680 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79681 return -EFAULT;
79682 buf = runtime->oss.buffer;
79683 }
79684 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79685 }
79686 } else {
79687 tmp = snd_pcm_oss_write2(substream,
79688 - (const char __force *)buf,
79689 + (const char __force_kernel *)buf,
79690 runtime->oss.period_bytes, 0);
79691 if (tmp <= 0)
79692 goto err;
79693 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79694 struct snd_pcm_runtime *runtime = substream->runtime;
79695 snd_pcm_sframes_t frames, frames1;
79696 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79697 - char __user *final_dst = (char __force __user *)buf;
79698 + char __user *final_dst = (char __force_user *)buf;
79699 if (runtime->oss.plugin_first) {
79700 struct snd_pcm_plugin_channel *channels;
79701 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79702 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79703 xfer += tmp;
79704 runtime->oss.buffer_used -= tmp;
79705 } else {
79706 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79707 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79708 runtime->oss.period_bytes, 0);
79709 if (tmp <= 0)
79710 goto err;
79711 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79712 size1);
79713 size1 /= runtime->channels; /* frames */
79714 fs = snd_enter_user();
79715 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79716 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79717 snd_leave_user(fs);
79718 }
79719 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79720 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79721 index 91cdf94..4085161 100644
79722 --- a/sound/core/pcm_compat.c
79723 +++ b/sound/core/pcm_compat.c
79724 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79725 int err;
79726
79727 fs = snd_enter_user();
79728 - err = snd_pcm_delay(substream, &delay);
79729 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79730 snd_leave_user(fs);
79731 if (err < 0)
79732 return err;
79733 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79734 index 25ed9fe..24c46e9 100644
79735 --- a/sound/core/pcm_native.c
79736 +++ b/sound/core/pcm_native.c
79737 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79738 switch (substream->stream) {
79739 case SNDRV_PCM_STREAM_PLAYBACK:
79740 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79741 - (void __user *)arg);
79742 + (void __force_user *)arg);
79743 break;
79744 case SNDRV_PCM_STREAM_CAPTURE:
79745 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79746 - (void __user *)arg);
79747 + (void __force_user *)arg);
79748 break;
79749 default:
79750 result = -EINVAL;
79751 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79752 index 5cf8d65..912a79c 100644
79753 --- a/sound/core/seq/seq_device.c
79754 +++ b/sound/core/seq/seq_device.c
79755 @@ -64,7 +64,7 @@ struct ops_list {
79756 int argsize; /* argument size */
79757
79758 /* operators */
79759 - struct snd_seq_dev_ops ops;
79760 + struct snd_seq_dev_ops *ops;
79761
79762 /* registred devices */
79763 struct list_head dev_list; /* list of devices */
79764 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79765
79766 mutex_lock(&ops->reg_mutex);
79767 /* copy driver operators */
79768 - ops->ops = *entry;
79769 + ops->ops = entry;
79770 ops->driver |= DRIVER_LOADED;
79771 ops->argsize = argsize;
79772
79773 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79774 dev->name, ops->id, ops->argsize, dev->argsize);
79775 return -EINVAL;
79776 }
79777 - if (ops->ops.init_device(dev) >= 0) {
79778 + if (ops->ops->init_device(dev) >= 0) {
79779 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79780 ops->num_init_devices++;
79781 } else {
79782 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79783 dev->name, ops->id, ops->argsize, dev->argsize);
79784 return -EINVAL;
79785 }
79786 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79787 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79788 dev->status = SNDRV_SEQ_DEVICE_FREE;
79789 dev->driver_data = NULL;
79790 ops->num_init_devices--;
79791 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79792 index 621e60e..f4543f5 100644
79793 --- a/sound/drivers/mts64.c
79794 +++ b/sound/drivers/mts64.c
79795 @@ -29,6 +29,7 @@
79796 #include <sound/initval.h>
79797 #include <sound/rawmidi.h>
79798 #include <sound/control.h>
79799 +#include <asm/local.h>
79800
79801 #define CARD_NAME "Miditerminal 4140"
79802 #define DRIVER_NAME "MTS64"
79803 @@ -67,7 +68,7 @@ struct mts64 {
79804 struct pardevice *pardev;
79805 int pardev_claimed;
79806
79807 - int open_count;
79808 + local_t open_count;
79809 int current_midi_output_port;
79810 int current_midi_input_port;
79811 u8 mode[MTS64_NUM_INPUT_PORTS];
79812 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79813 {
79814 struct mts64 *mts = substream->rmidi->private_data;
79815
79816 - if (mts->open_count == 0) {
79817 + if (local_read(&mts->open_count) == 0) {
79818 /* We don't need a spinlock here, because this is just called
79819 if the device has not been opened before.
79820 So there aren't any IRQs from the device */
79821 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79822
79823 msleep(50);
79824 }
79825 - ++(mts->open_count);
79826 + local_inc(&mts->open_count);
79827
79828 return 0;
79829 }
79830 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79831 struct mts64 *mts = substream->rmidi->private_data;
79832 unsigned long flags;
79833
79834 - --(mts->open_count);
79835 - if (mts->open_count == 0) {
79836 + if (local_dec_return(&mts->open_count) == 0) {
79837 /* We need the spinlock_irqsave here because we can still
79838 have IRQs at this point */
79839 spin_lock_irqsave(&mts->lock, flags);
79840 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79841
79842 msleep(500);
79843
79844 - } else if (mts->open_count < 0)
79845 - mts->open_count = 0;
79846 + } else if (local_read(&mts->open_count) < 0)
79847 + local_set(&mts->open_count, 0);
79848
79849 return 0;
79850 }
79851 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79852 index b953fb4..1999c01 100644
79853 --- a/sound/drivers/opl4/opl4_lib.c
79854 +++ b/sound/drivers/opl4/opl4_lib.c
79855 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79856 MODULE_DESCRIPTION("OPL4 driver");
79857 MODULE_LICENSE("GPL");
79858
79859 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79860 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79861 {
79862 int timeout = 10;
79863 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79864 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79865 index 3e32bd3..46fc152 100644
79866 --- a/sound/drivers/portman2x4.c
79867 +++ b/sound/drivers/portman2x4.c
79868 @@ -48,6 +48,7 @@
79869 #include <sound/initval.h>
79870 #include <sound/rawmidi.h>
79871 #include <sound/control.h>
79872 +#include <asm/local.h>
79873
79874 #define CARD_NAME "Portman 2x4"
79875 #define DRIVER_NAME "portman"
79876 @@ -85,7 +86,7 @@ struct portman {
79877 struct pardevice *pardev;
79878 int pardev_claimed;
79879
79880 - int open_count;
79881 + local_t open_count;
79882 int mode[PORTMAN_NUM_INPUT_PORTS];
79883 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79884 };
79885 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79886 index 87657dd..a8268d4 100644
79887 --- a/sound/firewire/amdtp.c
79888 +++ b/sound/firewire/amdtp.c
79889 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79890 ptr = s->pcm_buffer_pointer + data_blocks;
79891 if (ptr >= pcm->runtime->buffer_size)
79892 ptr -= pcm->runtime->buffer_size;
79893 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79894 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79895
79896 s->pcm_period_pointer += data_blocks;
79897 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79898 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79899 */
79900 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79901 {
79902 - ACCESS_ONCE(s->source_node_id_field) =
79903 + ACCESS_ONCE_RW(s->source_node_id_field) =
79904 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79905 }
79906 EXPORT_SYMBOL(amdtp_out_stream_update);
79907 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79908 index 537a9cb..8e8c8e9 100644
79909 --- a/sound/firewire/amdtp.h
79910 +++ b/sound/firewire/amdtp.h
79911 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79912 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79913 struct snd_pcm_substream *pcm)
79914 {
79915 - ACCESS_ONCE(s->pcm) = pcm;
79916 + ACCESS_ONCE_RW(s->pcm) = pcm;
79917 }
79918
79919 /**
79920 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79921 index cd094ec..eca1277 100644
79922 --- a/sound/firewire/isight.c
79923 +++ b/sound/firewire/isight.c
79924 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79925 ptr += count;
79926 if (ptr >= runtime->buffer_size)
79927 ptr -= runtime->buffer_size;
79928 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79929 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79930
79931 isight->period_counter += count;
79932 if (isight->period_counter >= runtime->period_size) {
79933 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79934 if (err < 0)
79935 return err;
79936
79937 - ACCESS_ONCE(isight->pcm_active) = true;
79938 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79939
79940 return 0;
79941 }
79942 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79943 {
79944 struct isight *isight = substream->private_data;
79945
79946 - ACCESS_ONCE(isight->pcm_active) = false;
79947 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79948
79949 mutex_lock(&isight->mutex);
79950 isight_stop_streaming(isight);
79951 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79952
79953 switch (cmd) {
79954 case SNDRV_PCM_TRIGGER_START:
79955 - ACCESS_ONCE(isight->pcm_running) = true;
79956 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79957 break;
79958 case SNDRV_PCM_TRIGGER_STOP:
79959 - ACCESS_ONCE(isight->pcm_running) = false;
79960 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79961 break;
79962 default:
79963 return -EINVAL;
79964 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79965 index 7bd5e33..1fcab12 100644
79966 --- a/sound/isa/cmi8330.c
79967 +++ b/sound/isa/cmi8330.c
79968 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79969
79970 struct snd_pcm *pcm;
79971 struct snd_cmi8330_stream {
79972 - struct snd_pcm_ops ops;
79973 + snd_pcm_ops_no_const ops;
79974 snd_pcm_open_callback_t open;
79975 void *private_data; /* sb or wss */
79976 } streams[2];
79977 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79978 index 733b014..56ce96f 100644
79979 --- a/sound/oss/sb_audio.c
79980 +++ b/sound/oss/sb_audio.c
79981 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79982 buf16 = (signed short *)(localbuf + localoffs);
79983 while (c)
79984 {
79985 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79986 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79987 if (copy_from_user(lbuf8,
79988 userbuf+useroffs + p,
79989 locallen))
79990 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79991 index 09d4648..cf234c7 100644
79992 --- a/sound/oss/swarm_cs4297a.c
79993 +++ b/sound/oss/swarm_cs4297a.c
79994 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79995 {
79996 struct cs4297a_state *s;
79997 u32 pwr, id;
79998 - mm_segment_t fs;
79999 int rval;
80000 #ifndef CONFIG_BCM_CS4297A_CSWARM
80001 u64 cfg;
80002 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80003 if (!rval) {
80004 char *sb1250_duart_present;
80005
80006 +#if 0
80007 + mm_segment_t fs;
80008 fs = get_fs();
80009 set_fs(KERNEL_DS);
80010 -#if 0
80011 val = SOUND_MASK_LINE;
80012 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80013 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80014 val = initvol[i].vol;
80015 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80016 }
80017 + set_fs(fs);
80018 // cs4297a_write_ac97(s, 0x18, 0x0808);
80019 #else
80020 // cs4297a_write_ac97(s, 0x5e, 0x180);
80021 cs4297a_write_ac97(s, 0x02, 0x0808);
80022 cs4297a_write_ac97(s, 0x18, 0x0808);
80023 #endif
80024 - set_fs(fs);
80025
80026 list_add(&s->list, &cs4297a_devs);
80027
80028 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80029 index f0f1943..8e1f96c 100644
80030 --- a/sound/pci/hda/hda_codec.h
80031 +++ b/sound/pci/hda/hda_codec.h
80032 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80033 /* notify power-up/down from codec to controller */
80034 void (*pm_notify)(struct hda_bus *bus);
80035 #endif
80036 -};
80037 +} __no_const;
80038
80039 /* template to pass to the bus constructor */
80040 struct hda_bus_template {
80041 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80042 #endif
80043 void (*reboot_notify)(struct hda_codec *codec);
80044 };
80045 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80046
80047 /* record for amp information cache */
80048 struct hda_cache_head {
80049 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80050 struct snd_pcm_substream *substream);
80051 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80052 struct snd_pcm_substream *substream);
80053 -};
80054 +} __no_const;
80055
80056 /* PCM information for each substream */
80057 struct hda_pcm_stream {
80058 @@ -801,7 +802,7 @@ struct hda_codec {
80059 const char *modelname; /* model name for preset */
80060
80061 /* set by patch */
80062 - struct hda_codec_ops patch_ops;
80063 + hda_codec_ops_no_const patch_ops;
80064
80065 /* PCM to create, set by patch_ops.build_pcms callback */
80066 unsigned int num_pcms;
80067 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80068 index 0da778a..bc38b84 100644
80069 --- a/sound/pci/ice1712/ice1712.h
80070 +++ b/sound/pci/ice1712/ice1712.h
80071 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80072 unsigned int mask_flags; /* total mask bits */
80073 struct snd_akm4xxx_ops {
80074 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80075 - } ops;
80076 + } __no_const ops;
80077 };
80078
80079 struct snd_ice1712_spdif {
80080 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80081 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80082 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80083 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80084 - } ops;
80085 + } __no_const ops;
80086 };
80087
80088
80089 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80090 index 12a9a2b..2b6138f 100644
80091 --- a/sound/pci/ymfpci/ymfpci_main.c
80092 +++ b/sound/pci/ymfpci/ymfpci_main.c
80093 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80094 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80095 break;
80096 }
80097 - if (atomic_read(&chip->interrupt_sleep_count)) {
80098 - atomic_set(&chip->interrupt_sleep_count, 0);
80099 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80100 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80101 wake_up(&chip->interrupt_sleep);
80102 }
80103 __end:
80104 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80105 continue;
80106 init_waitqueue_entry(&wait, current);
80107 add_wait_queue(&chip->interrupt_sleep, &wait);
80108 - atomic_inc(&chip->interrupt_sleep_count);
80109 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80110 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80111 remove_wait_queue(&chip->interrupt_sleep, &wait);
80112 }
80113 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80114 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80115 spin_unlock(&chip->reg_lock);
80116
80117 - if (atomic_read(&chip->interrupt_sleep_count)) {
80118 - atomic_set(&chip->interrupt_sleep_count, 0);
80119 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80120 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80121 wake_up(&chip->interrupt_sleep);
80122 }
80123 }
80124 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80125 spin_lock_init(&chip->reg_lock);
80126 spin_lock_init(&chip->voice_lock);
80127 init_waitqueue_head(&chip->interrupt_sleep);
80128 - atomic_set(&chip->interrupt_sleep_count, 0);
80129 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80130 chip->card = card;
80131 chip->pci = pci;
80132 chip->irq = -1;
80133 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80134 index cdc860a..db34a93 100644
80135 --- a/sound/soc/soc-pcm.c
80136 +++ b/sound/soc/soc-pcm.c
80137 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80138 struct snd_soc_platform *platform = rtd->platform;
80139 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80140 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80141 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80142 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80143 struct snd_pcm *pcm;
80144 char new_name[64];
80145 int ret = 0, playback = 0, capture = 0;
80146 diff --git a/sound/usb/card.h b/sound/usb/card.h
80147 index da5fa1a..113cd02 100644
80148 --- a/sound/usb/card.h
80149 +++ b/sound/usb/card.h
80150 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80151 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80152 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80153 };
80154 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80155
80156 struct snd_usb_substream {
80157 struct snd_usb_stream *stream;
80158 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80159 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80160 spinlock_t lock;
80161
80162 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80163 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80164 int last_frame_number; /* stored frame number */
80165 int last_delay; /* stored delay */
80166 };
80167 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80168 new file mode 100644
80169 index 0000000..ca64170
80170 --- /dev/null
80171 +++ b/tools/gcc/Makefile
80172 @@ -0,0 +1,26 @@
80173 +#CC := gcc
80174 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80175 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80176 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80177 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80178 +
80179 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80180 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80181 +
80182 +hostlibs-y := constify_plugin.so
80183 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80184 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80185 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80186 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80187 +hostlibs-y += colorize_plugin.so
80188 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80189 +
80190 +always := $(hostlibs-y)
80191 +
80192 +constify_plugin-objs := constify_plugin.o
80193 +stackleak_plugin-objs := stackleak_plugin.o
80194 +kallocstat_plugin-objs := kallocstat_plugin.o
80195 +kernexec_plugin-objs := kernexec_plugin.o
80196 +checker_plugin-objs := checker_plugin.o
80197 +colorize_plugin-objs := colorize_plugin.o
80198 +size_overflow_plugin-objs := size_overflow_plugin.o
80199 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80200 new file mode 100644
80201 index 0000000..d41b5af
80202 --- /dev/null
80203 +++ b/tools/gcc/checker_plugin.c
80204 @@ -0,0 +1,171 @@
80205 +/*
80206 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80207 + * Licensed under the GPL v2
80208 + *
80209 + * Note: the choice of the license means that the compilation process is
80210 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80211 + * but for the kernel it doesn't matter since it doesn't link against
80212 + * any of the gcc libraries
80213 + *
80214 + * gcc plugin to implement various sparse (source code checker) features
80215 + *
80216 + * TODO:
80217 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80218 + *
80219 + * BUGS:
80220 + * - none known
80221 + */
80222 +#include "gcc-plugin.h"
80223 +#include "config.h"
80224 +#include "system.h"
80225 +#include "coretypes.h"
80226 +#include "tree.h"
80227 +#include "tree-pass.h"
80228 +#include "flags.h"
80229 +#include "intl.h"
80230 +#include "toplev.h"
80231 +#include "plugin.h"
80232 +//#include "expr.h" where are you...
80233 +#include "diagnostic.h"
80234 +#include "plugin-version.h"
80235 +#include "tm.h"
80236 +#include "function.h"
80237 +#include "basic-block.h"
80238 +#include "gimple.h"
80239 +#include "rtl.h"
80240 +#include "emit-rtl.h"
80241 +#include "tree-flow.h"
80242 +#include "target.h"
80243 +
80244 +extern void c_register_addr_space (const char *str, addr_space_t as);
80245 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80246 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80247 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80248 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80249 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80250 +
80251 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80252 +extern rtx emit_move_insn(rtx x, rtx y);
80253 +
80254 +int plugin_is_GPL_compatible;
80255 +
80256 +static struct plugin_info checker_plugin_info = {
80257 + .version = "201111150100",
80258 +};
80259 +
80260 +#define ADDR_SPACE_KERNEL 0
80261 +#define ADDR_SPACE_FORCE_KERNEL 1
80262 +#define ADDR_SPACE_USER 2
80263 +#define ADDR_SPACE_FORCE_USER 3
80264 +#define ADDR_SPACE_IOMEM 0
80265 +#define ADDR_SPACE_FORCE_IOMEM 0
80266 +#define ADDR_SPACE_PERCPU 0
80267 +#define ADDR_SPACE_FORCE_PERCPU 0
80268 +#define ADDR_SPACE_RCU 0
80269 +#define ADDR_SPACE_FORCE_RCU 0
80270 +
80271 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80272 +{
80273 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80274 +}
80275 +
80276 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80277 +{
80278 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80279 +}
80280 +
80281 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80282 +{
80283 + return default_addr_space_valid_pointer_mode(mode, as);
80284 +}
80285 +
80286 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80287 +{
80288 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80289 +}
80290 +
80291 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80292 +{
80293 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80294 +}
80295 +
80296 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80297 +{
80298 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80299 + return true;
80300 +
80301 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80302 + return true;
80303 +
80304 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80305 + return true;
80306 +
80307 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80308 + return true;
80309 +
80310 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80311 + return true;
80312 +
80313 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80314 + return true;
80315 +
80316 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80317 + return true;
80318 +
80319 + return subset == superset;
80320 +}
80321 +
80322 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80323 +{
80324 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80325 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80326 +
80327 + return op;
80328 +}
80329 +
80330 +static void register_checker_address_spaces(void *event_data, void *data)
80331 +{
80332 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80333 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80334 + c_register_addr_space("__user", ADDR_SPACE_USER);
80335 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80336 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80337 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80338 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80339 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80340 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80341 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80342 +
80343 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80344 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80345 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80346 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80347 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80348 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80349 + targetm.addr_space.convert = checker_addr_space_convert;
80350 +}
80351 +
80352 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80353 +{
80354 + const char * const plugin_name = plugin_info->base_name;
80355 + const int argc = plugin_info->argc;
80356 + const struct plugin_argument * const argv = plugin_info->argv;
80357 + int i;
80358 +
80359 + if (!plugin_default_version_check(version, &gcc_version)) {
80360 + error(G_("incompatible gcc/plugin versions"));
80361 + return 1;
80362 + }
80363 +
80364 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80365 +
80366 + for (i = 0; i < argc; ++i)
80367 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80368 +
80369 + if (TARGET_64BIT == 0)
80370 + return 0;
80371 +
80372 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80373 +
80374 + return 0;
80375 +}
80376 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80377 new file mode 100644
80378 index 0000000..ee950d0
80379 --- /dev/null
80380 +++ b/tools/gcc/colorize_plugin.c
80381 @@ -0,0 +1,147 @@
80382 +/*
80383 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80384 + * Licensed under the GPL v2
80385 + *
80386 + * Note: the choice of the license means that the compilation process is
80387 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80388 + * but for the kernel it doesn't matter since it doesn't link against
80389 + * any of the gcc libraries
80390 + *
80391 + * gcc plugin to colorize diagnostic output
80392 + *
80393 + */
80394 +
80395 +#include "gcc-plugin.h"
80396 +#include "config.h"
80397 +#include "system.h"
80398 +#include "coretypes.h"
80399 +#include "tree.h"
80400 +#include "tree-pass.h"
80401 +#include "flags.h"
80402 +#include "intl.h"
80403 +#include "toplev.h"
80404 +#include "plugin.h"
80405 +#include "diagnostic.h"
80406 +#include "plugin-version.h"
80407 +#include "tm.h"
80408 +
80409 +int plugin_is_GPL_compatible;
80410 +
80411 +static struct plugin_info colorize_plugin_info = {
80412 + .version = "201203092200",
80413 +};
80414 +
80415 +#define GREEN "\033[32m\033[2m"
80416 +#define LIGHTGREEN "\033[32m\033[1m"
80417 +#define YELLOW "\033[33m\033[2m"
80418 +#define LIGHTYELLOW "\033[33m\033[1m"
80419 +#define RED "\033[31m\033[2m"
80420 +#define LIGHTRED "\033[31m\033[1m"
80421 +#define BLUE "\033[34m\033[2m"
80422 +#define LIGHTBLUE "\033[34m\033[1m"
80423 +#define BRIGHT "\033[m\033[1m"
80424 +#define NORMAL "\033[m"
80425 +
80426 +static diagnostic_starter_fn old_starter;
80427 +static diagnostic_finalizer_fn old_finalizer;
80428 +
80429 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80430 +{
80431 + const char *color;
80432 + char *newprefix;
80433 +
80434 + switch (diagnostic->kind) {
80435 + case DK_NOTE:
80436 + color = LIGHTBLUE;
80437 + break;
80438 +
80439 + case DK_PEDWARN:
80440 + case DK_WARNING:
80441 + color = LIGHTYELLOW;
80442 + break;
80443 +
80444 + case DK_ERROR:
80445 + case DK_FATAL:
80446 + case DK_ICE:
80447 + case DK_PERMERROR:
80448 + case DK_SORRY:
80449 + color = LIGHTRED;
80450 + break;
80451 +
80452 + default:
80453 + color = NORMAL;
80454 + }
80455 +
80456 + old_starter(context, diagnostic);
80457 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80458 + return;
80459 + pp_destroy_prefix(context->printer);
80460 + pp_set_prefix(context->printer, newprefix);
80461 +}
80462 +
80463 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80464 +{
80465 + old_finalizer(context, diagnostic);
80466 +}
80467 +
80468 +static void colorize_arm(void)
80469 +{
80470 + old_starter = diagnostic_starter(global_dc);
80471 + old_finalizer = diagnostic_finalizer(global_dc);
80472 +
80473 + diagnostic_starter(global_dc) = start_colorize;
80474 + diagnostic_finalizer(global_dc) = finalize_colorize;
80475 +}
80476 +
80477 +static unsigned int execute_colorize_rearm(void)
80478 +{
80479 + if (diagnostic_starter(global_dc) == start_colorize)
80480 + return 0;
80481 +
80482 + colorize_arm();
80483 + return 0;
80484 +}
80485 +
80486 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80487 + .pass = {
80488 + .type = SIMPLE_IPA_PASS,
80489 + .name = "colorize_rearm",
80490 + .gate = NULL,
80491 + .execute = execute_colorize_rearm,
80492 + .sub = NULL,
80493 + .next = NULL,
80494 + .static_pass_number = 0,
80495 + .tv_id = TV_NONE,
80496 + .properties_required = 0,
80497 + .properties_provided = 0,
80498 + .properties_destroyed = 0,
80499 + .todo_flags_start = 0,
80500 + .todo_flags_finish = 0
80501 + }
80502 +};
80503 +
80504 +static void colorize_start_unit(void *gcc_data, void *user_data)
80505 +{
80506 + colorize_arm();
80507 +}
80508 +
80509 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80510 +{
80511 + const char * const plugin_name = plugin_info->base_name;
80512 + struct register_pass_info colorize_rearm_pass_info = {
80513 + .pass = &pass_ipa_colorize_rearm.pass,
80514 + .reference_pass_name = "*free_lang_data",
80515 + .ref_pass_instance_number = 0,
80516 + .pos_op = PASS_POS_INSERT_AFTER
80517 + };
80518 +
80519 + if (!plugin_default_version_check(version, &gcc_version)) {
80520 + error(G_("incompatible gcc/plugin versions"));
80521 + return 1;
80522 + }
80523 +
80524 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80525 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80526 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80527 + return 0;
80528 +}
80529 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80530 new file mode 100644
80531 index 0000000..704a564
80532 --- /dev/null
80533 +++ b/tools/gcc/constify_plugin.c
80534 @@ -0,0 +1,303 @@
80535 +/*
80536 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80537 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80538 + * Licensed under the GPL v2, or (at your option) v3
80539 + *
80540 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80541 + *
80542 + * Homepage:
80543 + * http://www.grsecurity.net/~ephox/const_plugin/
80544 + *
80545 + * Usage:
80546 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80547 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80548 + */
80549 +
80550 +#include "gcc-plugin.h"
80551 +#include "config.h"
80552 +#include "system.h"
80553 +#include "coretypes.h"
80554 +#include "tree.h"
80555 +#include "tree-pass.h"
80556 +#include "flags.h"
80557 +#include "intl.h"
80558 +#include "toplev.h"
80559 +#include "plugin.h"
80560 +#include "diagnostic.h"
80561 +#include "plugin-version.h"
80562 +#include "tm.h"
80563 +#include "function.h"
80564 +#include "basic-block.h"
80565 +#include "gimple.h"
80566 +#include "rtl.h"
80567 +#include "emit-rtl.h"
80568 +#include "tree-flow.h"
80569 +
80570 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80571 +
80572 +int plugin_is_GPL_compatible;
80573 +
80574 +static struct plugin_info const_plugin_info = {
80575 + .version = "201111150100",
80576 + .help = "no-constify\tturn off constification\n",
80577 +};
80578 +
80579 +static void constify_type(tree type);
80580 +static bool walk_struct(tree node);
80581 +
80582 +static tree deconstify_type(tree old_type)
80583 +{
80584 + tree new_type, field;
80585 +
80586 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80587 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80588 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80589 + DECL_FIELD_CONTEXT(field) = new_type;
80590 + TYPE_READONLY(new_type) = 0;
80591 + C_TYPE_FIELDS_READONLY(new_type) = 0;
80592 + return new_type;
80593 +}
80594 +
80595 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80596 +{
80597 + tree type;
80598 +
80599 + *no_add_attrs = true;
80600 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80601 + error("%qE attribute does not apply to functions", name);
80602 + return NULL_TREE;
80603 + }
80604 +
80605 + if (TREE_CODE(*node) == VAR_DECL) {
80606 + error("%qE attribute does not apply to variables", name);
80607 + return NULL_TREE;
80608 + }
80609 +
80610 + if (TYPE_P(*node)) {
80611 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80612 + *no_add_attrs = false;
80613 + else
80614 + error("%qE attribute applies to struct and union types only", name);
80615 + return NULL_TREE;
80616 + }
80617 +
80618 + type = TREE_TYPE(*node);
80619 +
80620 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80621 + error("%qE attribute applies to struct and union types only", name);
80622 + return NULL_TREE;
80623 + }
80624 +
80625 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80626 + error("%qE attribute is already applied to the type", name);
80627 + return NULL_TREE;
80628 + }
80629 +
80630 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80631 + error("%qE attribute used on type that is not constified", name);
80632 + return NULL_TREE;
80633 + }
80634 +
80635 + if (TREE_CODE(*node) == TYPE_DECL) {
80636 + TREE_TYPE(*node) = deconstify_type(type);
80637 + TREE_READONLY(*node) = 0;
80638 + return NULL_TREE;
80639 + }
80640 +
80641 + return NULL_TREE;
80642 +}
80643 +
80644 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80645 +{
80646 + *no_add_attrs = true;
80647 + if (!TYPE_P(*node)) {
80648 + error("%qE attribute applies to types only", name);
80649 + return NULL_TREE;
80650 + }
80651 +
80652 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80653 + error("%qE attribute applies to struct and union types only", name);
80654 + return NULL_TREE;
80655 + }
80656 +
80657 + *no_add_attrs = false;
80658 + constify_type(*node);
80659 + return NULL_TREE;
80660 +}
80661 +
80662 +static struct attribute_spec no_const_attr = {
80663 + .name = "no_const",
80664 + .min_length = 0,
80665 + .max_length = 0,
80666 + .decl_required = false,
80667 + .type_required = false,
80668 + .function_type_required = false,
80669 + .handler = handle_no_const_attribute,
80670 +#if BUILDING_GCC_VERSION >= 4007
80671 + .affects_type_identity = true
80672 +#endif
80673 +};
80674 +
80675 +static struct attribute_spec do_const_attr = {
80676 + .name = "do_const",
80677 + .min_length = 0,
80678 + .max_length = 0,
80679 + .decl_required = false,
80680 + .type_required = false,
80681 + .function_type_required = false,
80682 + .handler = handle_do_const_attribute,
80683 +#if BUILDING_GCC_VERSION >= 4007
80684 + .affects_type_identity = true
80685 +#endif
80686 +};
80687 +
80688 +static void register_attributes(void *event_data, void *data)
80689 +{
80690 + register_attribute(&no_const_attr);
80691 + register_attribute(&do_const_attr);
80692 +}
80693 +
80694 +static void constify_type(tree type)
80695 +{
80696 + TYPE_READONLY(type) = 1;
80697 + C_TYPE_FIELDS_READONLY(type) = 1;
80698 +}
80699 +
80700 +static bool is_fptr(tree field)
80701 +{
80702 + tree ptr = TREE_TYPE(field);
80703 +
80704 + if (TREE_CODE(ptr) != POINTER_TYPE)
80705 + return false;
80706 +
80707 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80708 +}
80709 +
80710 +static bool walk_struct(tree node)
80711 +{
80712 + tree field;
80713 +
80714 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
80715 + return false;
80716 +
80717 + if (TYPE_FIELDS(node) == NULL_TREE)
80718 + return false;
80719 +
80720 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80721 + tree type = TREE_TYPE(field);
80722 + enum tree_code code = TREE_CODE(type);
80723 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80724 + if (!(walk_struct(type)))
80725 + return false;
80726 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80727 + return false;
80728 + }
80729 + return true;
80730 +}
80731 +
80732 +static void finish_type(void *event_data, void *data)
80733 +{
80734 + tree type = (tree)event_data;
80735 +
80736 + if (type == NULL_TREE)
80737 + return;
80738 +
80739 + if (TYPE_READONLY(type))
80740 + return;
80741 +
80742 + if (walk_struct(type))
80743 + constify_type(type);
80744 +}
80745 +
80746 +static unsigned int check_local_variables(void);
80747 +
80748 +struct gimple_opt_pass pass_local_variable = {
80749 + {
80750 + .type = GIMPLE_PASS,
80751 + .name = "check_local_variables",
80752 + .gate = NULL,
80753 + .execute = check_local_variables,
80754 + .sub = NULL,
80755 + .next = NULL,
80756 + .static_pass_number = 0,
80757 + .tv_id = TV_NONE,
80758 + .properties_required = 0,
80759 + .properties_provided = 0,
80760 + .properties_destroyed = 0,
80761 + .todo_flags_start = 0,
80762 + .todo_flags_finish = 0
80763 + }
80764 +};
80765 +
80766 +static unsigned int check_local_variables(void)
80767 +{
80768 + tree var;
80769 + referenced_var_iterator rvi;
80770 +
80771 +#if BUILDING_GCC_VERSION == 4005
80772 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80773 +#else
80774 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80775 +#endif
80776 + tree type = TREE_TYPE(var);
80777 +
80778 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80779 + continue;
80780 +
80781 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80782 + continue;
80783 +
80784 + if (!TYPE_READONLY(type))
80785 + continue;
80786 +
80787 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80788 +// continue;
80789 +
80790 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80791 +// continue;
80792 +
80793 + if (walk_struct(type)) {
80794 + error("constified variable %qE cannot be local", var);
80795 + return 1;
80796 + }
80797 + }
80798 + return 0;
80799 +}
80800 +
80801 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80802 +{
80803 + const char * const plugin_name = plugin_info->base_name;
80804 + const int argc = plugin_info->argc;
80805 + const struct plugin_argument * const argv = plugin_info->argv;
80806 + int i;
80807 + bool constify = true;
80808 +
80809 + struct register_pass_info local_variable_pass_info = {
80810 + .pass = &pass_local_variable.pass,
80811 + .reference_pass_name = "*referenced_vars",
80812 + .ref_pass_instance_number = 0,
80813 + .pos_op = PASS_POS_INSERT_AFTER
80814 + };
80815 +
80816 + if (!plugin_default_version_check(version, &gcc_version)) {
80817 + error(G_("incompatible gcc/plugin versions"));
80818 + return 1;
80819 + }
80820 +
80821 + for (i = 0; i < argc; ++i) {
80822 + if (!(strcmp(argv[i].key, "no-constify"))) {
80823 + constify = false;
80824 + continue;
80825 + }
80826 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80827 + }
80828 +
80829 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80830 + if (constify) {
80831 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80832 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80833 + }
80834 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80835 +
80836 + return 0;
80837 +}
80838 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80839 new file mode 100644
80840 index 0000000..a5eabce
80841 --- /dev/null
80842 +++ b/tools/gcc/kallocstat_plugin.c
80843 @@ -0,0 +1,167 @@
80844 +/*
80845 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80846 + * Licensed under the GPL v2
80847 + *
80848 + * Note: the choice of the license means that the compilation process is
80849 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80850 + * but for the kernel it doesn't matter since it doesn't link against
80851 + * any of the gcc libraries
80852 + *
80853 + * gcc plugin to find the distribution of k*alloc sizes
80854 + *
80855 + * TODO:
80856 + *
80857 + * BUGS:
80858 + * - none known
80859 + */
80860 +#include "gcc-plugin.h"
80861 +#include "config.h"
80862 +#include "system.h"
80863 +#include "coretypes.h"
80864 +#include "tree.h"
80865 +#include "tree-pass.h"
80866 +#include "flags.h"
80867 +#include "intl.h"
80868 +#include "toplev.h"
80869 +#include "plugin.h"
80870 +//#include "expr.h" where are you...
80871 +#include "diagnostic.h"
80872 +#include "plugin-version.h"
80873 +#include "tm.h"
80874 +#include "function.h"
80875 +#include "basic-block.h"
80876 +#include "gimple.h"
80877 +#include "rtl.h"
80878 +#include "emit-rtl.h"
80879 +
80880 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80881 +
80882 +int plugin_is_GPL_compatible;
80883 +
80884 +static const char * const kalloc_functions[] = {
80885 + "__kmalloc",
80886 + "kmalloc",
80887 + "kmalloc_large",
80888 + "kmalloc_node",
80889 + "kmalloc_order",
80890 + "kmalloc_order_trace",
80891 + "kmalloc_slab",
80892 + "kzalloc",
80893 + "kzalloc_node",
80894 +};
80895 +
80896 +static struct plugin_info kallocstat_plugin_info = {
80897 + .version = "201111150100",
80898 +};
80899 +
80900 +static unsigned int execute_kallocstat(void);
80901 +
80902 +static struct gimple_opt_pass kallocstat_pass = {
80903 + .pass = {
80904 + .type = GIMPLE_PASS,
80905 + .name = "kallocstat",
80906 + .gate = NULL,
80907 + .execute = execute_kallocstat,
80908 + .sub = NULL,
80909 + .next = NULL,
80910 + .static_pass_number = 0,
80911 + .tv_id = TV_NONE,
80912 + .properties_required = 0,
80913 + .properties_provided = 0,
80914 + .properties_destroyed = 0,
80915 + .todo_flags_start = 0,
80916 + .todo_flags_finish = 0
80917 + }
80918 +};
80919 +
80920 +static bool is_kalloc(const char *fnname)
80921 +{
80922 + size_t i;
80923 +
80924 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80925 + if (!strcmp(fnname, kalloc_functions[i]))
80926 + return true;
80927 + return false;
80928 +}
80929 +
80930 +static unsigned int execute_kallocstat(void)
80931 +{
80932 + basic_block bb;
80933 +
80934 + // 1. loop through BBs and GIMPLE statements
80935 + FOR_EACH_BB(bb) {
80936 + gimple_stmt_iterator gsi;
80937 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80938 + // gimple match:
80939 + tree fndecl, size;
80940 + gimple call_stmt;
80941 + const char *fnname;
80942 +
80943 + // is it a call
80944 + call_stmt = gsi_stmt(gsi);
80945 + if (!is_gimple_call(call_stmt))
80946 + continue;
80947 + fndecl = gimple_call_fndecl(call_stmt);
80948 + if (fndecl == NULL_TREE)
80949 + continue;
80950 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80951 + continue;
80952 +
80953 + // is it a call to k*alloc
80954 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80955 + if (!is_kalloc(fnname))
80956 + continue;
80957 +
80958 + // is the size arg the result of a simple const assignment
80959 + size = gimple_call_arg(call_stmt, 0);
80960 + while (true) {
80961 + gimple def_stmt;
80962 + expanded_location xloc;
80963 + size_t size_val;
80964 +
80965 + if (TREE_CODE(size) != SSA_NAME)
80966 + break;
80967 + def_stmt = SSA_NAME_DEF_STMT(size);
80968 + if (!def_stmt || !is_gimple_assign(def_stmt))
80969 + break;
80970 + if (gimple_num_ops(def_stmt) != 2)
80971 + break;
80972 + size = gimple_assign_rhs1(def_stmt);
80973 + if (!TREE_CONSTANT(size))
80974 + continue;
80975 + xloc = expand_location(gimple_location(def_stmt));
80976 + if (!xloc.file)
80977 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80978 + size_val = TREE_INT_CST_LOW(size);
80979 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80980 + break;
80981 + }
80982 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80983 +//debug_tree(gimple_call_fn(call_stmt));
80984 +//print_node(stderr, "pax", fndecl, 4);
80985 + }
80986 + }
80987 +
80988 + return 0;
80989 +}
80990 +
80991 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80992 +{
80993 + const char * const plugin_name = plugin_info->base_name;
80994 + struct register_pass_info kallocstat_pass_info = {
80995 + .pass = &kallocstat_pass.pass,
80996 + .reference_pass_name = "ssa",
80997 + .ref_pass_instance_number = 0,
80998 + .pos_op = PASS_POS_INSERT_AFTER
80999 + };
81000 +
81001 + if (!plugin_default_version_check(version, &gcc_version)) {
81002 + error(G_("incompatible gcc/plugin versions"));
81003 + return 1;
81004 + }
81005 +
81006 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81007 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81008 +
81009 + return 0;
81010 +}
81011 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81012 new file mode 100644
81013 index 0000000..d8a8da2
81014 --- /dev/null
81015 +++ b/tools/gcc/kernexec_plugin.c
81016 @@ -0,0 +1,427 @@
81017 +/*
81018 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81019 + * Licensed under the GPL v2
81020 + *
81021 + * Note: the choice of the license means that the compilation process is
81022 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81023 + * but for the kernel it doesn't matter since it doesn't link against
81024 + * any of the gcc libraries
81025 + *
81026 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81027 + *
81028 + * TODO:
81029 + *
81030 + * BUGS:
81031 + * - none known
81032 + */
81033 +#include "gcc-plugin.h"
81034 +#include "config.h"
81035 +#include "system.h"
81036 +#include "coretypes.h"
81037 +#include "tree.h"
81038 +#include "tree-pass.h"
81039 +#include "flags.h"
81040 +#include "intl.h"
81041 +#include "toplev.h"
81042 +#include "plugin.h"
81043 +//#include "expr.h" where are you...
81044 +#include "diagnostic.h"
81045 +#include "plugin-version.h"
81046 +#include "tm.h"
81047 +#include "function.h"
81048 +#include "basic-block.h"
81049 +#include "gimple.h"
81050 +#include "rtl.h"
81051 +#include "emit-rtl.h"
81052 +#include "tree-flow.h"
81053 +
81054 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81055 +extern rtx emit_move_insn(rtx x, rtx y);
81056 +
81057 +int plugin_is_GPL_compatible;
81058 +
81059 +static struct plugin_info kernexec_plugin_info = {
81060 + .version = "201111291120",
81061 + .help = "method=[bts|or]\tinstrumentation method\n"
81062 +};
81063 +
81064 +static unsigned int execute_kernexec_reload(void);
81065 +static unsigned int execute_kernexec_fptr(void);
81066 +static unsigned int execute_kernexec_retaddr(void);
81067 +static bool kernexec_cmodel_check(void);
81068 +
81069 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81070 +static void (*kernexec_instrument_retaddr)(rtx);
81071 +
81072 +static struct gimple_opt_pass kernexec_reload_pass = {
81073 + .pass = {
81074 + .type = GIMPLE_PASS,
81075 + .name = "kernexec_reload",
81076 + .gate = kernexec_cmodel_check,
81077 + .execute = execute_kernexec_reload,
81078 + .sub = NULL,
81079 + .next = NULL,
81080 + .static_pass_number = 0,
81081 + .tv_id = TV_NONE,
81082 + .properties_required = 0,
81083 + .properties_provided = 0,
81084 + .properties_destroyed = 0,
81085 + .todo_flags_start = 0,
81086 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81087 + }
81088 +};
81089 +
81090 +static struct gimple_opt_pass kernexec_fptr_pass = {
81091 + .pass = {
81092 + .type = GIMPLE_PASS,
81093 + .name = "kernexec_fptr",
81094 + .gate = kernexec_cmodel_check,
81095 + .execute = execute_kernexec_fptr,
81096 + .sub = NULL,
81097 + .next = NULL,
81098 + .static_pass_number = 0,
81099 + .tv_id = TV_NONE,
81100 + .properties_required = 0,
81101 + .properties_provided = 0,
81102 + .properties_destroyed = 0,
81103 + .todo_flags_start = 0,
81104 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81105 + }
81106 +};
81107 +
81108 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81109 + .pass = {
81110 + .type = RTL_PASS,
81111 + .name = "kernexec_retaddr",
81112 + .gate = kernexec_cmodel_check,
81113 + .execute = execute_kernexec_retaddr,
81114 + .sub = NULL,
81115 + .next = NULL,
81116 + .static_pass_number = 0,
81117 + .tv_id = TV_NONE,
81118 + .properties_required = 0,
81119 + .properties_provided = 0,
81120 + .properties_destroyed = 0,
81121 + .todo_flags_start = 0,
81122 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81123 + }
81124 +};
81125 +
81126 +static bool kernexec_cmodel_check(void)
81127 +{
81128 + tree section;
81129 +
81130 + if (ix86_cmodel != CM_KERNEL)
81131 + return false;
81132 +
81133 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81134 + if (!section || !TREE_VALUE(section))
81135 + return true;
81136 +
81137 + section = TREE_VALUE(TREE_VALUE(section));
81138 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81139 + return true;
81140 +
81141 + return false;
81142 +}
81143 +
81144 +/*
81145 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81146 + */
81147 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81148 +{
81149 + gimple asm_movabs_stmt;
81150 +
81151 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81152 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81153 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81154 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81155 + update_stmt(asm_movabs_stmt);
81156 +}
81157 +
81158 +/*
81159 + * find all asm() stmts that clobber r10 and add a reload of r10
81160 + */
81161 +static unsigned int execute_kernexec_reload(void)
81162 +{
81163 + basic_block bb;
81164 +
81165 + // 1. loop through BBs and GIMPLE statements
81166 + FOR_EACH_BB(bb) {
81167 + gimple_stmt_iterator gsi;
81168 +
81169 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81170 + // gimple match: __asm__ ("" : : : "r10");
81171 + gimple asm_stmt;
81172 + size_t nclobbers;
81173 +
81174 + // is it an asm ...
81175 + asm_stmt = gsi_stmt(gsi);
81176 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81177 + continue;
81178 +
81179 + // ... clobbering r10
81180 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81181 + while (nclobbers--) {
81182 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81183 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81184 + continue;
81185 + kernexec_reload_fptr_mask(&gsi);
81186 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81187 + break;
81188 + }
81189 + }
81190 + }
81191 +
81192 + return 0;
81193 +}
81194 +
81195 +/*
81196 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81197 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81198 + */
81199 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81200 +{
81201 + gimple assign_intptr, assign_new_fptr, call_stmt;
81202 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81203 +
81204 + call_stmt = gsi_stmt(*gsi);
81205 + old_fptr = gimple_call_fn(call_stmt);
81206 +
81207 + // create temporary unsigned long variable used for bitops and cast fptr to it
81208 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81209 + add_referenced_var(intptr);
81210 + mark_sym_for_renaming(intptr);
81211 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81212 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81213 + update_stmt(assign_intptr);
81214 +
81215 + // apply logical or to temporary unsigned long and bitmask
81216 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81217 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81218 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81219 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81220 + update_stmt(assign_intptr);
81221 +
81222 + // cast temporary unsigned long back to a temporary fptr variable
81223 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81224 + add_referenced_var(new_fptr);
81225 + mark_sym_for_renaming(new_fptr);
81226 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81227 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81228 + update_stmt(assign_new_fptr);
81229 +
81230 + // replace call stmt fn with the new fptr
81231 + gimple_call_set_fn(call_stmt, new_fptr);
81232 + update_stmt(call_stmt);
81233 +}
81234 +
81235 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81236 +{
81237 + gimple asm_or_stmt, call_stmt;
81238 + tree old_fptr, new_fptr, input, output;
81239 + VEC(tree, gc) *inputs = NULL;
81240 + VEC(tree, gc) *outputs = NULL;
81241 +
81242 + call_stmt = gsi_stmt(*gsi);
81243 + old_fptr = gimple_call_fn(call_stmt);
81244 +
81245 + // create temporary fptr variable
81246 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81247 + add_referenced_var(new_fptr);
81248 + mark_sym_for_renaming(new_fptr);
81249 +
81250 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81251 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81252 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81253 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81254 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81255 + VEC_safe_push(tree, gc, inputs, input);
81256 + VEC_safe_push(tree, gc, outputs, output);
81257 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81258 + gimple_asm_set_volatile(asm_or_stmt, true);
81259 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81260 + update_stmt(asm_or_stmt);
81261 +
81262 + // replace call stmt fn with the new fptr
81263 + gimple_call_set_fn(call_stmt, new_fptr);
81264 + update_stmt(call_stmt);
81265 +}
81266 +
81267 +/*
81268 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81269 + */
81270 +static unsigned int execute_kernexec_fptr(void)
81271 +{
81272 + basic_block bb;
81273 +
81274 + // 1. loop through BBs and GIMPLE statements
81275 + FOR_EACH_BB(bb) {
81276 + gimple_stmt_iterator gsi;
81277 +
81278 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81279 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81280 + tree fn;
81281 + gimple call_stmt;
81282 +
81283 + // is it a call ...
81284 + call_stmt = gsi_stmt(gsi);
81285 + if (!is_gimple_call(call_stmt))
81286 + continue;
81287 + fn = gimple_call_fn(call_stmt);
81288 + if (TREE_CODE(fn) == ADDR_EXPR)
81289 + continue;
81290 + if (TREE_CODE(fn) != SSA_NAME)
81291 + gcc_unreachable();
81292 +
81293 + // ... through a function pointer
81294 + fn = SSA_NAME_VAR(fn);
81295 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81296 + continue;
81297 + fn = TREE_TYPE(fn);
81298 + if (TREE_CODE(fn) != POINTER_TYPE)
81299 + continue;
81300 + fn = TREE_TYPE(fn);
81301 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81302 + continue;
81303 +
81304 + kernexec_instrument_fptr(&gsi);
81305 +
81306 +//debug_tree(gimple_call_fn(call_stmt));
81307 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81308 + }
81309 + }
81310 +
81311 + return 0;
81312 +}
81313 +
81314 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81315 +static void kernexec_instrument_retaddr_bts(rtx insn)
81316 +{
81317 + rtx btsq;
81318 + rtvec argvec, constraintvec, labelvec;
81319 + int line;
81320 +
81321 + // create asm volatile("btsq $63,(%%rsp)":::)
81322 + argvec = rtvec_alloc(0);
81323 + constraintvec = rtvec_alloc(0);
81324 + labelvec = rtvec_alloc(0);
81325 + line = expand_location(RTL_LOCATION(insn)).line;
81326 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81327 + MEM_VOLATILE_P(btsq) = 1;
81328 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81329 + emit_insn_before(btsq, insn);
81330 +}
81331 +
81332 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81333 +static void kernexec_instrument_retaddr_or(rtx insn)
81334 +{
81335 + rtx orq;
81336 + rtvec argvec, constraintvec, labelvec;
81337 + int line;
81338 +
81339 + // create asm volatile("orq %%r10,(%%rsp)":::)
81340 + argvec = rtvec_alloc(0);
81341 + constraintvec = rtvec_alloc(0);
81342 + labelvec = rtvec_alloc(0);
81343 + line = expand_location(RTL_LOCATION(insn)).line;
81344 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81345 + MEM_VOLATILE_P(orq) = 1;
81346 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81347 + emit_insn_before(orq, insn);
81348 +}
81349 +
81350 +/*
81351 + * find all asm level function returns and forcibly set the highest bit of the return address
81352 + */
81353 +static unsigned int execute_kernexec_retaddr(void)
81354 +{
81355 + rtx insn;
81356 +
81357 + // 1. find function returns
81358 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81359 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81360 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81361 + rtx body;
81362 +
81363 + // is it a retn
81364 + if (!JUMP_P(insn))
81365 + continue;
81366 + body = PATTERN(insn);
81367 + if (GET_CODE(body) == PARALLEL)
81368 + body = XVECEXP(body, 0, 0);
81369 + if (GET_CODE(body) != RETURN)
81370 + continue;
81371 + kernexec_instrument_retaddr(insn);
81372 + }
81373 +
81374 +// print_simple_rtl(stderr, get_insns());
81375 +// print_rtl(stderr, get_insns());
81376 +
81377 + return 0;
81378 +}
81379 +
81380 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81381 +{
81382 + const char * const plugin_name = plugin_info->base_name;
81383 + const int argc = plugin_info->argc;
81384 + const struct plugin_argument * const argv = plugin_info->argv;
81385 + int i;
81386 + struct register_pass_info kernexec_reload_pass_info = {
81387 + .pass = &kernexec_reload_pass.pass,
81388 + .reference_pass_name = "ssa",
81389 + .ref_pass_instance_number = 0,
81390 + .pos_op = PASS_POS_INSERT_AFTER
81391 + };
81392 + struct register_pass_info kernexec_fptr_pass_info = {
81393 + .pass = &kernexec_fptr_pass.pass,
81394 + .reference_pass_name = "ssa",
81395 + .ref_pass_instance_number = 0,
81396 + .pos_op = PASS_POS_INSERT_AFTER
81397 + };
81398 + struct register_pass_info kernexec_retaddr_pass_info = {
81399 + .pass = &kernexec_retaddr_pass.pass,
81400 + .reference_pass_name = "pro_and_epilogue",
81401 + .ref_pass_instance_number = 0,
81402 + .pos_op = PASS_POS_INSERT_AFTER
81403 + };
81404 +
81405 + if (!plugin_default_version_check(version, &gcc_version)) {
81406 + error(G_("incompatible gcc/plugin versions"));
81407 + return 1;
81408 + }
81409 +
81410 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81411 +
81412 + if (TARGET_64BIT == 0)
81413 + return 0;
81414 +
81415 + for (i = 0; i < argc; ++i) {
81416 + if (!strcmp(argv[i].key, "method")) {
81417 + if (!argv[i].value) {
81418 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81419 + continue;
81420 + }
81421 + if (!strcmp(argv[i].value, "bts")) {
81422 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81423 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81424 + } else if (!strcmp(argv[i].value, "or")) {
81425 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81426 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81427 + fix_register("r10", 1, 1);
81428 + } else
81429 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81430 + continue;
81431 + }
81432 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81433 + }
81434 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81435 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81436 +
81437 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81438 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81439 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81440 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81441 +
81442 + return 0;
81443 +}
81444 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81445 new file mode 100644
81446 index 0000000..16ccac1
81447 --- /dev/null
81448 +++ b/tools/gcc/size_overflow_hash1.h
81449 @@ -0,0 +1,3047 @@
81450 +struct size_overflow_hash size_overflow_hash1[65536] = {
81451 + [10013].file = "security/smack/smackfs.c",
81452 + [10013].name = "smk_write_direct",
81453 + [10013].param3 = 1,
81454 + [10167].file = "sound/core/oss/pcm_plugin.c",
81455 + [10167].name = "snd_pcm_plugin_build",
81456 + [10167].param5 = 1,
81457 + [1020].file = "drivers/usb/misc/usbtest.c",
81458 + [1020].name = "test_unaligned_bulk",
81459 + [1020].param3 = 1,
81460 + [1022].file = "sound/pci/rme9652/rme9652.c",
81461 + [1022].name = "snd_rme9652_playback_copy",
81462 + [1022].param5 = 1,
81463 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
81464 + [10321].name = "create_attr_set",
81465 + [10321].param1 = 1,
81466 + [10341].file = "fs/nfsd/nfs4xdr.c",
81467 + [10341].name = "read_buf",
81468 + [10341].param2 = 1,
81469 + [10357].file = "net/sunrpc/cache.c",
81470 + [10357].name = "cache_read",
81471 + [10357].param3 = 1,
81472 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81473 + [10397].name = "i915_wedged_write",
81474 + [10397].param3 = 1,
81475 + [10399].file = "kernel/trace/trace.c",
81476 + [10399].name = "trace_seq_to_user",
81477 + [10399].param3 = 1,
81478 + [10414].file = "drivers/tty/vt/vt.c",
81479 + [10414].name = "vc_do_resize",
81480 + [10414].param3 = 1,
81481 + [10414].param4 = 1,
81482 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81483 + [10565].name = "ad7879_spi_multi_read",
81484 + [10565].param3 = 1,
81485 + [10623].file = "drivers/infiniband/core/user_mad.c",
81486 + [10623].name = "ib_umad_write",
81487 + [10623].param3 = 1,
81488 + [10707].file = "fs/nfs/idmap.c",
81489 + [10707].name = "nfs_idmap_request_key",
81490 + [10707].param2 = 1,
81491 + [1073].file = "drivers/block/aoe/aoecmd.c",
81492 + [1073].name = "addtgt",
81493 + [1073].param3 = 1,
81494 + [10745].file = "fs/cifs/connect.c",
81495 + [10745].name = "get_server_iovec",
81496 + [10745].param2 = 1,
81497 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
81498 + [10750].name = "iwm_ntf_calib_res",
81499 + [10750].param3 = 1,
81500 + [10773].file = "drivers/input/mousedev.c",
81501 + [10773].name = "mousedev_read",
81502 + [10773].param3 = 1,
81503 + [10777].file = "fs/ntfs/file.c",
81504 + [10777].name = "ntfs_file_buffered_write",
81505 + [10777].param6 = 1,
81506 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
81507 + [10893].name = "options_write",
81508 + [10893].param3 = 1,
81509 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81510 + [10919].name = "do_arpt_set_ctl",
81511 + [10919].param4 = 1,
81512 + [1107].file = "mm/process_vm_access.c",
81513 + [1107].name = "process_vm_rw_single_vec",
81514 + [1107].param1 = 1,
81515 + [1107].param2 = 1,
81516 + [11230].file = "net/core/neighbour.c",
81517 + [11230].name = "neigh_hash_grow",
81518 + [11230].param2 = 1,
81519 + [11364].file = "fs/ext4/super.c",
81520 + [11364].name = "ext4_kvzalloc",
81521 + [11364].param1 = 1,
81522 + [114].file = "security/selinux/selinuxfs.c",
81523 + [114].name = "sel_write_relabel",
81524 + [114].param3 = 1,
81525 + [11549].file = "drivers/media/rc/redrat3.c",
81526 + [11549].name = "redrat3_transmit_ir",
81527 + [11549].param3 = 1,
81528 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
81529 + [11568].name = "drm_vmalloc_dma",
81530 + [11568].param1 = 1,
81531 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
81532 + [11582].name = "lpfc_sli4_queue_alloc",
81533 + [11582].param3 = 1,
81534 + [11616].file = "security/selinux/selinuxfs.c",
81535 + [11616].name = "sel_write_enforce",
81536 + [11616].param3 = 1,
81537 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81538 + [11699].name = "vxge_os_dma_malloc",
81539 + [11699].param2 = 1,
81540 + [11766].file = "drivers/block/paride/pt.c",
81541 + [11766].name = "pt_read",
81542 + [11766].param3 = 1,
81543 + [11784].file = "fs/bio.c",
81544 + [11784].name = "bio_kmalloc",
81545 + [11784].param2 = 1,
81546 + [11919].file = "drivers/lguest/core.c",
81547 + [11919].name = "__lgread",
81548 + [11919].param4 = 1,
81549 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
81550 + [11925].name = "cx18_copy_mdl_to_user",
81551 + [11925].param4 = 1,
81552 + [11985].file = "drivers/block/floppy.c",
81553 + [11985].name = "fd_copyin",
81554 + [11985].param3 = 1,
81555 + [11986].file = "drivers/net/usb/asix.c",
81556 + [11986].name = "asix_read_cmd",
81557 + [11986].param5 = 1,
81558 + [12018].file = "sound/core/oss/pcm_oss.c",
81559 + [12018].name = "snd_pcm_oss_read1",
81560 + [12018].param3 = 1,
81561 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
81562 + [12059].name = "lbs_debugfs_write",
81563 + [12059].param3 = 1,
81564 + [12151].file = "fs/compat.c",
81565 + [12151].name = "compat_rw_copy_check_uvector",
81566 + [12151].param3 = 1,
81567 + [12205].file = "fs/reiserfs/journal.c",
81568 + [12205].name = "reiserfs_allocate_list_bitmaps",
81569 + [12205].param3 = 1,
81570 + [12234].file = "include/acpi/platform/aclinux.h",
81571 + [12234].name = "acpi_os_allocate",
81572 + [12234].param1 = 1,
81573 + [1227].file = "lib/cpu_rmap.c",
81574 + [1227].name = "alloc_cpu_rmap",
81575 + [1227].param1 = 1,
81576 + [12395].file = "drivers/char/hw_random/core.c",
81577 + [12395].name = "rng_dev_read",
81578 + [12395].param3 = 1,
81579 + [12602].file = "net/sunrpc/cache.c",
81580 + [12602].name = "cache_downcall",
81581 + [12602].param3 = 1,
81582 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
81583 + [12712].name = "i2400m_zrealloc_2x",
81584 + [12712].param3 = 1,
81585 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
81586 + [12755].name = "snd_opl4_mem_proc_read",
81587 + [12755].param5 = 1,
81588 + [12833].file = "net/sctp/auth.c",
81589 + [12833].name = "sctp_auth_create_key",
81590 + [12833].param1 = 1,
81591 + [12840].file = "net/sctp/tsnmap.c",
81592 + [12840].name = "sctp_tsnmap_mark",
81593 + [12840].param2 = 1,
81594 + [12931].file = "drivers/hid/hid-roccat.c",
81595 + [12931].name = "roccat_read",
81596 + [12931].param3 = 1,
81597 + [12954].file = "fs/proc/base.c",
81598 + [12954].name = "oom_adjust_write",
81599 + [12954].param3 = 1,
81600 + [13103].file = "drivers/acpi/acpica/utobject.c",
81601 + [13103].name = "acpi_ut_create_string_object",
81602 + [13103].param1 = 1,
81603 + [13121].file = "net/ipv4/ip_sockglue.c",
81604 + [13121].name = "do_ip_setsockopt",
81605 + [13121].param5 = 1,
81606 + [1327].file = "net/netfilter/nfnetlink_log.c",
81607 + [1327].name = "nfulnl_alloc_skb",
81608 + [1327].param2 = 1,
81609 + [13337].file = "net/core/iovec.c",
81610 + [13337].name = "csum_partial_copy_fromiovecend",
81611 + [13337].param4 = 1,
81612 + [13339].file = "security/smack/smackfs.c",
81613 + [13339].name = "smk_write_netlbladdr",
81614 + [13339].param3 = 1,
81615 + [13342].file = "fs/jbd2/journal.c",
81616 + [13342].name = "jbd2_alloc",
81617 + [13342].param1 = 1,
81618 + [13384].file = "drivers/char/virtio_console.c",
81619 + [13384].name = "alloc_buf",
81620 + [13384].param1 = 1,
81621 + [13412].file = "fs/proc/base.c",
81622 + [13412].name = "oom_score_adj_write",
81623 + [13412].param3 = 1,
81624 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
81625 + [13559].name = "ivtv_read",
81626 + [13559].param3 = 1,
81627 + [13618].file = "drivers/net/team/team.c",
81628 + [13618].name = "team_options_register",
81629 + [13618].param3 = 1,
81630 + [13659].file = "drivers/net/wan/hdlc.c",
81631 + [13659].name = "attach_hdlc_protocol",
81632 + [13659].param3 = 1,
81633 + [13708].file = "drivers/usb/misc/usbtest.c",
81634 + [13708].name = "simple_alloc_urb",
81635 + [13708].param3 = 1,
81636 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
81637 + [13805].name = "altera_swap_dr",
81638 + [13805].param2 = 1,
81639 + [13868].file = "fs/lockd/mon.c",
81640 + [13868].name = "nsm_create_handle",
81641 + [13868].param4 = 1,
81642 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
81643 + [13924].name = "do_ipt_set_ctl",
81644 + [13924].param4 = 1,
81645 + [14019].file = "net/dns_resolver/dns_key.c",
81646 + [14019].name = "dns_resolver_instantiate",
81647 + [14019].param2 = 1,
81648 + [14019].param3 = 1,
81649 + [14025].file = "net/ax25/af_ax25.c",
81650 + [14025].name = "ax25_setsockopt",
81651 + [14025].param5 = 1,
81652 + [14029].file = "drivers/spi/spidev.c",
81653 + [14029].name = "spidev_compat_ioctl",
81654 + [14029].param2 = 1,
81655 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
81656 + [14090].name = "btmrvl_hsmode_write",
81657 + [14090].param3 = 1,
81658 + [14149].file = "drivers/hid/hidraw.c",
81659 + [14149].name = "hidraw_ioctl",
81660 + [14149].param2 = 1,
81661 + [14153].file = "drivers/staging/bcm/led_control.c",
81662 + [14153].name = "ValidateDSDParamsChecksum",
81663 + [14153].param3 = 1,
81664 + [14174].file = "sound/pci/es1938.c",
81665 + [14174].name = "snd_es1938_capture_copy",
81666 + [14174].param5 = 1,
81667 + [14207].file = "drivers/media/video/v4l2-event.c",
81668 + [14207].name = "v4l2_event_subscribe",
81669 + [14207].param3 = 1,
81670 + [14241].file = "drivers/platform/x86/asus_acpi.c",
81671 + [14241].name = "brn_proc_write",
81672 + [14241].param3 = 1,
81673 + [14345].file = "fs/cachefiles/daemon.c",
81674 + [14345].name = "cachefiles_daemon_write",
81675 + [14345].param3 = 1,
81676 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
81677 + [14347].name = "dvb_ca_en50221_io_write",
81678 + [14347].param3 = 1,
81679 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
81680 + [14566].name = "alloc_ebda_hpc",
81681 + [14566].param1 = 1,
81682 + [14566].param2 = 1,
81683 + [1458].file = "drivers/misc/lkdtm.c",
81684 + [1458].name = "direct_entry",
81685 + [1458].param3 = 1,
81686 + [14646].file = "fs/compat.c",
81687 + [14646].name = "compat_writev",
81688 + [14646].param3 = 1,
81689 + [14684].file = "drivers/media/video/stk-webcam.c",
81690 + [14684].name = "stk_allocate_buffers",
81691 + [14684].param2 = 1,
81692 + [14736].file = "drivers/usb/misc/usbtest.c",
81693 + [14736].name = "unlink_queued",
81694 + [14736].param3 = 1,
81695 + [1482].file = "drivers/scsi/scsi_netlink.c",
81696 + [1482].name = "scsi_nl_send_vendor_msg",
81697 + [1482].param5 = 1,
81698 + [15017].file = "drivers/edac/edac_device.c",
81699 + [15017].name = "edac_device_alloc_ctl_info",
81700 + [15017].param1 = 1,
81701 + [15044].file = "drivers/uio/uio.c",
81702 + [15044].name = "uio_write",
81703 + [15044].param3 = 1,
81704 + [15087].file = "fs/bio.c",
81705 + [15087].name = "bio_map_kern",
81706 + [15087].param2 = 1,
81707 + [15087].param3 = 1,
81708 + [15112].file = "drivers/xen/evtchn.c",
81709 + [15112].name = "evtchn_write",
81710 + [15112].param3 = 1,
81711 + [15130].file = "net/bluetooth/hci_core.c",
81712 + [15130].name = "hci_send_cmd",
81713 + [15130].param3 = 1,
81714 + [15202].file = "net/bluetooth/rfcomm/tty.c",
81715 + [15202].name = "rfcomm_wmalloc",
81716 + [15202].param2 = 1,
81717 + [15274].file = "crypto/shash.c",
81718 + [15274].name = "crypto_shash_setkey",
81719 + [15274].param3 = 1,
81720 + [15354].file = "drivers/isdn/mISDN/socket.c",
81721 + [15354].name = "mISDN_sock_sendmsg",
81722 + [15354].param4 = 1,
81723 + [15361].file = "drivers/char/agp/generic.c",
81724 + [15361].name = "agp_allocate_memory",
81725 + [15361].param2 = 1,
81726 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
81727 + [15497].name = "ts_read",
81728 + [15497].param3 = 1,
81729 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
81730 + [15551].name = "clusterip_proc_write",
81731 + [15551].param3 = 1,
81732 + [15701].file = "drivers/hid/hid-roccat-common.c",
81733 + [15701].name = "roccat_common_receive",
81734 + [15701].param4 = 1,
81735 + [1572].file = "net/ceph/pagevec.c",
81736 + [1572].name = "ceph_copy_page_vector_to_user",
81737 + [1572].param4 = 1,
81738 + [15814].file = "net/mac80211/debugfs_netdev.c",
81739 + [15814].name = "ieee80211_if_write",
81740 + [15814].param3 = 1,
81741 + [15883].file = "security/keys/keyctl.c",
81742 + [15883].name = "sys_add_key",
81743 + [15883].param4 = 1,
81744 + [15884].file = "fs/exofs/super.c",
81745 + [15884].name = "exofs_read_lookup_dev_table",
81746 + [15884].param3 = 1,
81747 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
81748 + [16037].name = "easycap_alsa_vmalloc",
81749 + [16037].param2 = 1,
81750 + [16073].file = "net/sctp/socket.c",
81751 + [16073].name = "sctp_setsockopt",
81752 + [16073].param5 = 1,
81753 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
81754 + [16132].name = "buffer_from_user",
81755 + [16132].param3 = 1,
81756 + [16138].file = "security/selinux/ss/services.c",
81757 + [16138].name = "security_context_to_sid_force",
81758 + [16138].param2 = 1,
81759 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
81760 + [16166].name = "dispatch_proc_write",
81761 + [16166].param3 = 1,
81762 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
81763 + [16229].name = "iscsi_offload_mesg",
81764 + [16229].param5 = 1,
81765 + [16353].file = "drivers/base/regmap/regmap.c",
81766 + [16353].name = "regmap_raw_write",
81767 + [16353].param4 = 1,
81768 + [16383].file = "fs/proc/base.c",
81769 + [16383].name = "comm_write",
81770 + [16383].param3 = 1,
81771 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
81772 + [16396].name = "altera_irscan",
81773 + [16396].param2 = 1,
81774 + [16447].file = "drivers/hid/usbhid/hiddev.c",
81775 + [16447].name = "hiddev_ioctl",
81776 + [16447].param2 = 1,
81777 + [16453].file = "include/linux/slab.h",
81778 + [16453].name = "kzalloc",
81779 + [16453].param1 = 1,
81780 + [16605].file = "fs/ecryptfs/miscdev.c",
81781 + [16605].name = "ecryptfs_send_miscdev",
81782 + [16605].param2 = 1,
81783 + [16606].file = "drivers/ide/ide-tape.c",
81784 + [16606].name = "idetape_chrdev_write",
81785 + [16606].param3 = 1,
81786 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
81787 + [16637].name = "datablob_hmac_verify",
81788 + [16637].param4 = 1,
81789 + [16828].file = "net/batman-adv/hash.c",
81790 + [16828].name = "hash_new",
81791 + [16828].param1 = 1,
81792 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
81793 + [16853].name = "t4vf_pktgl_to_skb",
81794 + [16853].param2 = 1,
81795 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
81796 + [16911].name = "LoadBitmap",
81797 + [16911].param2 = 1,
81798 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
81799 + [169].name = "pcnet32_realloc_rx_ring",
81800 + [169].param3 = 1,
81801 + [17075].file = "sound/isa/gus/gus_dram.c",
81802 + [17075].name = "snd_gus_dram_write",
81803 + [17075].param4 = 1,
81804 + [17133].file = "drivers/usb/misc/iowarrior.c",
81805 + [17133].name = "iowarrior_read",
81806 + [17133].param3 = 1,
81807 + [17185].file = "net/wireless/scan.c",
81808 + [17185].name = "cfg80211_inform_bss",
81809 + [17185].param8 = 1,
81810 + [17349].file = "net/tipc/link.c",
81811 + [17349].name = "tipc_link_send_sections_fast",
81812 + [17349].param4 = 1,
81813 + [17377].file = "drivers/usb/class/cdc-wdm.c",
81814 + [17377].name = "wdm_write",
81815 + [17377].param3 = 1,
81816 + [17459].file = "drivers/usb/misc/rio500.c",
81817 + [17459].name = "write_rio",
81818 + [17459].param3 = 1,
81819 + [17460].file = "fs/nfsd/nfscache.c",
81820 + [17460].name = "nfsd_cache_update",
81821 + [17460].param3 = 1,
81822 + [17492].file = "net/dccp/proto.c",
81823 + [17492].name = "do_dccp_setsockopt",
81824 + [17492].param5 = 1,
81825 + [1754].file = "sound/core/oss/pcm_oss.c",
81826 + [1754].name = "snd_pcm_oss_write",
81827 + [1754].param3 = 1,
81828 + [17604].file = "fs/proc/generic.c",
81829 + [17604].name = "__proc_file_read",
81830 + [17604].param3 = 1,
81831 + [17718].file = "net/caif/caif_socket.c",
81832 + [17718].name = "setsockopt",
81833 + [17718].param5 = 1,
81834 + [17828].file = "kernel/sched/core.c",
81835 + [17828].name = "sched_feat_write",
81836 + [17828].param3 = 1,
81837 + [17841].file = "drivers/misc/tifm_core.c",
81838 + [17841].name = "tifm_alloc_adapter",
81839 + [17841].param1 = 1,
81840 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
81841 + [17946].name = "if_spi_host_to_card",
81842 + [17946].param4 = 1,
81843 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
81844 + [1800].name = "dvb_dvr_do_ioctl",
81845 + [1800].param3 = 1,
81846 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
81847 + [18119].name = "iwmct_fw_parser_init",
81848 + [18119].param4 = 1,
81849 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
81850 + [18140].name = "pm8001_store_update_fw",
81851 + [18140].param4 = 1,
81852 + [18191].file = "sound/pci/hda/patch_realtek.c",
81853 + [18191].name = "new_bind_ctl",
81854 + [18191].param2 = 1,
81855 + [18224].file = "drivers/xen/grant-table.c",
81856 + [18224].name = "gnttab_map",
81857 + [18224].param2 = 1,
81858 + [18232].file = "fs/nfs/write.c",
81859 + [18232].name = "nfs_writedata_alloc",
81860 + [18232].param1 = 1,
81861 + [18247].file = "drivers/char/agp/generic.c",
81862 + [18247].name = "agp_create_user_memory",
81863 + [18247].param1 = 1,
81864 + [18303].file = "fs/xattr.c",
81865 + [18303].name = "getxattr",
81866 + [18303].param4 = 1,
81867 + [18353].file = "net/rfkill/core.c",
81868 + [18353].name = "rfkill_fop_read",
81869 + [18353].param3 = 1,
81870 + [18386].file = "fs/read_write.c",
81871 + [18386].name = "vfs_readv",
81872 + [18386].param3 = 1,
81873 + [18391].file = "fs/ocfs2/stack_user.c",
81874 + [18391].name = "ocfs2_control_write",
81875 + [18391].param3 = 1,
81876 + [183].file = "crypto/ahash.c",
81877 + [183].name = "crypto_ahash_setkey",
81878 + [183].param3 = 1,
81879 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
81880 + [18406].name = "tm6000_read_write_usb",
81881 + [18406].param7 = 1,
81882 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
81883 + [1845].name = "rt2x00debug_write_rf",
81884 + [1845].param3 = 1,
81885 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
81886 + [18465].name = "cxgb_alloc_mem",
81887 + [18465].param1 = 1,
81888 + [184].file = "drivers/firewire/nosy.c",
81889 + [184].name = "packet_buffer_init",
81890 + [184].param2 = 1,
81891 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
81892 + [1858].name = "do_ip6t_set_ctl",
81893 + [1858].param4 = 1,
81894 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
81895 + [18659].name = "dvb_usercopy",
81896 + [18659].param2 = 1,
81897 + [18722].file = "security/tomoyo/condition.c",
81898 + [18722].name = "tomoyo_scan_bprm",
81899 + [18722].param2 = 1,
81900 + [18722].param4 = 1,
81901 + [18775].file = "include/linux/textsearch.h",
81902 + [18775].name = "alloc_ts_config",
81903 + [18775].param1 = 1,
81904 + [18940].file = "drivers/usb/host/hwa-hc.c",
81905 + [18940].name = "__hwahc_op_set_gtk",
81906 + [18940].param4 = 1,
81907 + [19012].file = "drivers/acpi/event.c",
81908 + [19012].name = "acpi_system_read_event",
81909 + [19012].param3 = 1,
81910 + [19028].file = "mm/filemap.c",
81911 + [19028].name = "iov_iter_copy_from_user_atomic",
81912 + [19028].param4 = 1,
81913 + [19107].file = "security/smack/smackfs.c",
81914 + [19107].name = "smk_write_load_list",
81915 + [19107].param3 = 1,
81916 + [19240].file = "net/sctp/socket.c",
81917 + [19240].name = "sctp_setsockopt_delayed_ack",
81918 + [19240].param3 = 1,
81919 + [19274].file = "net/core/pktgen.c",
81920 + [19274].name = "pktgen_if_write",
81921 + [19274].param3 = 1,
81922 + [19286].file = "drivers/base/regmap/regmap.c",
81923 + [19286].name = "_regmap_raw_write",
81924 + [19286].param4 = 1,
81925 + [19308].file = "drivers/char/mem.c",
81926 + [19308].name = "read_oldmem",
81927 + [19308].param3 = 1,
81928 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
81929 + [19343].name = "datablob_hmac_append",
81930 + [19343].param3 = 1,
81931 + [19349].file = "drivers/acpi/acpica/utobject.c",
81932 + [19349].name = "acpi_ut_create_package_object",
81933 + [19349].param1 = 1,
81934 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
81935 + [19453].name = "sge_rx",
81936 + [19453].param3 = 1,
81937 + [19504].file = "drivers/usb/serial/garmin_gps.c",
81938 + [19504].name = "pkt_add",
81939 + [19504].param3 = 1,
81940 + [19522].file = "mm/percpu.c",
81941 + [19522].name = "pcpu_mem_zalloc",
81942 + [19522].param1 = 1,
81943 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
81944 + [19548].name = "qla2x00_get_ctx_sp",
81945 + [19548].param3 = 1,
81946 + [19592].file = "net/dccp/proto.c",
81947 + [19592].name = "dccp_setsockopt_service",
81948 + [19592].param4 = 1,
81949 + [19726].file = "kernel/trace/trace.c",
81950 + [19726].name = "tracing_set_trace_write",
81951 + [19726].param3 = 1,
81952 + [19738].file = "fs/sysfs/file.c",
81953 + [19738].name = "sysfs_write_file",
81954 + [19738].param3 = 1,
81955 + [19833].file = "drivers/xen/privcmd.c",
81956 + [19833].name = "gather_array",
81957 + [19833].param3 = 1,
81958 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
81959 + [19910].name = "saa7164_buffer_alloc_user",
81960 + [19910].param2 = 1,
81961 + [19920].file = "drivers/input/joydev.c",
81962 + [19920].name = "joydev_ioctl",
81963 + [19920].param2 = 1,
81964 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
81965 + [19931].name = "ftdi_elan_write",
81966 + [19931].param3 = 1,
81967 + [19960].file = "drivers/usb/class/usblp.c",
81968 + [19960].name = "usblp_read",
81969 + [19960].param3 = 1,
81970 + [1996].file = "drivers/scsi/libsrp.c",
81971 + [1996].name = "srp_target_alloc",
81972 + [1996].param3 = 1,
81973 + [20023].file = "drivers/media/video/gspca/gspca.c",
81974 + [20023].name = "dev_read",
81975 + [20023].param3 = 1,
81976 + [20207].file = "net/core/sock.c",
81977 + [20207].name = "sock_alloc_send_pskb",
81978 + [20207].param2 = 1,
81979 + [20263].file = "kernel/trace/trace_events.c",
81980 + [20263].name = "event_filter_write",
81981 + [20263].param3 = 1,
81982 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
81983 + [20314].name = "drm_ht_create",
81984 + [20314].param2 = 1,
81985 + [20320].file = "drivers/mfd/sm501.c",
81986 + [20320].name = "sm501_create_subdev",
81987 + [20320].param3 = 1,
81988 + [20320].param4 = 1,
81989 + [20376].file = "mm/nobootmem.c",
81990 + [20376].name = "__alloc_bootmem_nopanic",
81991 + [20376].param1 = 1,
81992 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
81993 + [20409].name = "opera1_usb_i2c_msgxfer",
81994 + [20409].param4 = 1,
81995 + [20473].file = "drivers/mtd/mtdchar.c",
81996 + [20473].name = "mtdchar_write",
81997 + [20473].param3 = 1,
81998 + [20611].file = "net/netfilter/x_tables.c",
81999 + [20611].name = "xt_alloc_table_info",
82000 + [20611].param1 = 1,
82001 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
82002 + [20618].name = "chd_dec_fetch_cdata",
82003 + [20618].param3 = 1,
82004 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
82005 + [20713].name = "ttm_bo_io",
82006 + [20713].param5 = 1,
82007 + [20801].file = "drivers/vhost/vhost.c",
82008 + [20801].name = "vhost_add_used_n",
82009 + [20801].param3 = 1,
82010 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
82011 + [20835].name = "isdn_read",
82012 + [20835].param3 = 1,
82013 + [20951].file = "crypto/rng.c",
82014 + [20951].name = "rngapi_reset",
82015 + [20951].param3 = 1,
82016 + [21125].file = "fs/gfs2/dir.c",
82017 + [21125].name = "gfs2_alloc_sort_buffer",
82018 + [21125].param1 = 1,
82019 + [21132].file = "kernel/cgroup.c",
82020 + [21132].name = "cgroup_write_X64",
82021 + [21132].param5 = 1,
82022 + [21138].file = "drivers/uio/uio.c",
82023 + [21138].name = "uio_read",
82024 + [21138].param3 = 1,
82025 + [21193].file = "net/wireless/sme.c",
82026 + [21193].name = "cfg80211_disconnected",
82027 + [21193].param4 = 1,
82028 + [21312].file = "lib/ts_kmp.c",
82029 + [21312].name = "kmp_init",
82030 + [21312].param2 = 1,
82031 + [21335].file = "net/econet/af_econet.c",
82032 + [21335].name = "econet_sendmsg",
82033 + [21335].param4 = 1,
82034 + [21406].file = "fs/libfs.c",
82035 + [21406].name = "simple_write_to_buffer",
82036 + [21406].param2 = 1,
82037 + [21406].param5 = 1,
82038 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82039 + [21451].name = "do_ip_vs_set_ctl",
82040 + [21451].param4 = 1,
82041 + [21459].file = "security/smack/smackfs.c",
82042 + [21459].name = "smk_write_doi",
82043 + [21459].param3 = 1,
82044 + [21508].file = "include/linux/usb/wusb.h",
82045 + [21508].name = "wusb_prf_64",
82046 + [21508].param7 = 1,
82047 + [21511].file = "drivers/input/ff-core.c",
82048 + [21511].name = "input_ff_create",
82049 + [21511].param2 = 1,
82050 + [21538].file = "net/bluetooth/l2cap_sock.c",
82051 + [21538].name = "l2cap_sock_setsockopt",
82052 + [21538].param5 = 1,
82053 + [21543].file = "drivers/media/video/gspca/gspca.c",
82054 + [21543].name = "frame_alloc",
82055 + [21543].param4 = 1,
82056 + [21608].file = "drivers/char/tpm/tpm.c",
82057 + [21608].name = "tpm_write",
82058 + [21608].param3 = 1,
82059 + [2160].file = "drivers/net/wireless/ray_cs.c",
82060 + [2160].name = "int_proc_write",
82061 + [2160].param3 = 1,
82062 + [21632].file = "fs/afs/cell.c",
82063 + [21632].name = "afs_cell_create",
82064 + [21632].param2 = 1,
82065 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82066 + [21679].name = "carl9170_debugfs_write",
82067 + [21679].param3 = 1,
82068 + [21784].file = "crypto/ahash.c",
82069 + [21784].name = "ahash_setkey_unaligned",
82070 + [21784].param3 = 1,
82071 + [2180].file = "drivers/char/ppdev.c",
82072 + [2180].name = "pp_write",
82073 + [2180].param3 = 1,
82074 + [21810].file = "net/core/netprio_cgroup.c",
82075 + [21810].name = "extend_netdev_table",
82076 + [21810].param2 = 1,
82077 + [21906].file = "net/atm/mpc.c",
82078 + [21906].name = "copy_macs",
82079 + [21906].param4 = 1,
82080 + [21946].file = "fs/nfs/idmap.c",
82081 + [21946].name = "nfs_map_name_to_uid",
82082 + [21946].param3 = 1,
82083 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
82084 + [22052].name = "get_packet_pg",
82085 + [22052].param4 = 1,
82086 + [22085].file = "drivers/staging/sep/sep_driver.c",
82087 + [22085].name = "sep_lock_user_pages",
82088 + [22085].param2 = 1,
82089 + [22085].param3 = 1,
82090 + [22190].file = "drivers/char/tpm/tpm.c",
82091 + [22190].name = "tpm_read",
82092 + [22190].param3 = 1,
82093 + [22291].file = "net/core/pktgen.c",
82094 + [22291].name = "pgctrl_write",
82095 + [22291].param3 = 1,
82096 + [22439].file = "fs/afs/rxrpc.c",
82097 + [22439].name = "afs_alloc_flat_call",
82098 + [22439].param2 = 1,
82099 + [22439].param3 = 1,
82100 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82101 + [2243].name = "scsi_tgt_kspace_exec",
82102 + [2243].param8 = 1,
82103 + [22440].file = "drivers/uwb/neh.c",
82104 + [22440].name = "uwb_rc_neh_grok_event",
82105 + [22440].param3 = 1,
82106 + [22611].file = "drivers/staging/android/logger.c",
82107 + [22611].name = "do_write_log_from_user",
82108 + [22611].param3 = 1,
82109 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
82110 + [22614].name = "cx18_copy_buf_to_user",
82111 + [22614].param4 = 1,
82112 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
82113 + [22667].name = "altera_set_ir_post",
82114 + [22667].param2 = 1,
82115 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82116 + [22772].name = "iscsit_dump_data_payload",
82117 + [22772].param2 = 1,
82118 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
82119 + [22777].name = "srp_alloc_iu",
82120 + [22777].param2 = 1,
82121 + [22811].file = "drivers/usb/dwc3/debugfs.c",
82122 + [22811].name = "dwc3_mode_write",
82123 + [22811].param3 = 1,
82124 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
82125 + [22817].name = "usbvision_rvmalloc",
82126 + [22817].param1 = 1,
82127 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82128 + [22864].name = "ath6kl_add_bss_if_needed",
82129 + [22864].param6 = 1,
82130 + [2286].file = "drivers/scsi/mvumi.c",
82131 + [2286].name = "mvumi_alloc_mem_resource",
82132 + [2286].param3 = 1,
82133 + [22904].file = "security/selinux/ss/services.c",
82134 + [22904].name = "security_context_to_sid_default",
82135 + [22904].param2 = 1,
82136 + [22932].file = "fs/compat.c",
82137 + [22932].name = "compat_sys_writev",
82138 + [22932].param3 = 1,
82139 + [2302].file = "drivers/media/video/stk-webcam.c",
82140 + [2302].name = "v4l_stk_read",
82141 + [2302].param3 = 1,
82142 + [2307].file = "drivers/pcmcia/cistpl.c",
82143 + [2307].name = "pcmcia_replace_cis",
82144 + [2307].param3 = 1,
82145 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82146 + [23117].name = "dvb_audio_write",
82147 + [23117].param3 = 1,
82148 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82149 + [23220].name = "do_dmabuf_dirty_sou",
82150 + [23220].param7 = 1,
82151 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
82152 + [23232].name = "sm_checker_extend",
82153 + [23232].param2 = 1,
82154 + [2324].file = "net/ieee802154/wpan-class.c",
82155 + [2324].name = "wpan_phy_alloc",
82156 + [2324].param1 = 1,
82157 + [2328].file = "kernel/trace/ftrace.c",
82158 + [2328].name = "ftrace_pid_write",
82159 + [2328].param3 = 1,
82160 + [23290].file = "fs/proc/base.c",
82161 + [23290].name = "mem_rw",
82162 + [23290].param3 = 1,
82163 + [23449].file = "crypto/blkcipher.c",
82164 + [23449].name = "blkcipher_next_slow",
82165 + [23449].param3 = 1,
82166 + [23449].param4 = 1,
82167 + [23535].file = "ipc/sem.c",
82168 + [23535].name = "sys_semtimedop",
82169 + [23535].param3 = 1,
82170 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82171 + [2357].name = "garmin_read_process",
82172 + [2357].param3 = 1,
82173 + [23589].file = "kernel/relay.c",
82174 + [23589].name = "subbuf_read_actor",
82175 + [23589].param3 = 1,
82176 + [23848].file = "crypto/blkcipher.c",
82177 + [23848].name = "async_setkey",
82178 + [23848].param3 = 1,
82179 + [2386].file = "drivers/acpi/acpica/exnames.c",
82180 + [2386].name = "acpi_ex_allocate_name_string",
82181 + [2386].param2 = 1,
82182 + [2389].file = "net/core/sock.c",
82183 + [2389].name = "sock_rmalloc",
82184 + [2389].param2 = 1,
82185 + [23994].file = "net/bluetooth/mgmt.c",
82186 + [23994].name = "set_powered",
82187 + [23994].param4 = 1,
82188 + [23999].file = "sound/pci/rme9652/hdsp.c",
82189 + [23999].name = "snd_hdsp_capture_copy",
82190 + [23999].param5 = 1,
82191 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82192 + [24233].name = "aer_inject_write",
82193 + [24233].param3 = 1,
82194 + [24359].file = "kernel/power/qos.c",
82195 + [24359].name = "pm_qos_power_write",
82196 + [24359].param3 = 1,
82197 + [24457].file = "fs/btrfs/backref.c",
82198 + [24457].name = "init_data_container",
82199 + [24457].param1 = 1,
82200 + [24719].file = "drivers/input/evdev.c",
82201 + [24719].name = "bits_to_user",
82202 + [24719].param3 = 1,
82203 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82204 + [2472].name = "compat_do_ipt_set_ctl",
82205 + [2472].param4 = 1,
82206 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82207 + [24755].name = "qib_diag_write",
82208 + [24755].param3 = 1,
82209 + [24805].file = "security/keys/user_defined.c",
82210 + [24805].name = "user_update",
82211 + [24805].param3 = 1,
82212 + [25036].file = "fs/pipe.c",
82213 + [25036].name = "pipe_iov_copy_from_user",
82214 + [25036].param3 = 1,
82215 + [25078].file = "drivers/net/wireless/p54/fwio.c",
82216 + [25078].name = "p54_download_eeprom",
82217 + [25078].param4 = 1,
82218 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82219 + [25127].name = "realloc_buffer",
82220 + [25127].param2 = 1,
82221 + [25145].file = "net/tipc/link.c",
82222 + [25145].name = "link_send_sections_long",
82223 + [25145].param4 = 1,
82224 + [25157].file = "security/keys/request_key_auth.c",
82225 + [25157].name = "request_key_auth_new",
82226 + [25157].param3 = 1,
82227 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82228 + [25158].name = "mlx4_en_create_rx_ring",
82229 + [25158].param3 = 1,
82230 + [25267].file = "fs/configfs/file.c",
82231 + [25267].name = "configfs_write_file",
82232 + [25267].param3 = 1,
82233 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82234 + [25495].name = "bfad_debugfs_write_regwr",
82235 + [25495].param3 = 1,
82236 + [25558].file = "fs/proc/task_mmu.c",
82237 + [25558].name = "clear_refs_write",
82238 + [25558].param3 = 1,
82239 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82240 + [25692].name = "ath6kl_wmi_send_action_cmd",
82241 + [25692].param7 = 1,
82242 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
82243 + [25765].name = "flexcop_device_kmalloc",
82244 + [25765].param1 = 1,
82245 + [26100].file = "sound/core/info.c",
82246 + [26100].name = "snd_info_entry_write",
82247 + [26100].param3 = 1,
82248 + [26256].file = "fs/hpfs/name.c",
82249 + [26256].name = "hpfs_translate_name",
82250 + [26256].param3 = 1,
82251 + [26394].file = "drivers/hid/hidraw.c",
82252 + [26394].name = "hidraw_get_report",
82253 + [26394].param3 = 1,
82254 + [26494].file = "kernel/signal.c",
82255 + [26494].name = "sys_rt_sigpending",
82256 + [26494].param2 = 1,
82257 + [26497].file = "security/keys/keyctl.c",
82258 + [26497].name = "sys_keyctl",
82259 + [26497].param4 = 1,
82260 + [26533].file = "drivers/block/aoe/aoechr.c",
82261 + [26533].name = "aoechr_write",
82262 + [26533].param3 = 1,
82263 + [26560].file = "crypto/algapi.c",
82264 + [26560].name = "crypto_alloc_instance2",
82265 + [26560].param3 = 1,
82266 + [26605].file = "security/selinux/selinuxfs.c",
82267 + [26605].name = "sel_write_user",
82268 + [26605].param3 = 1,
82269 + [26620].file = "net/bluetooth/mgmt.c",
82270 + [26620].name = "mgmt_control",
82271 + [26620].param3 = 1,
82272 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82273 + [26701].name = "cfi_read_pri",
82274 + [26701].param3 = 1,
82275 + [26757].file = "fs/xattr.c",
82276 + [26757].name = "sys_fgetxattr",
82277 + [26757].param4 = 1,
82278 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82279 + [2678].name = "disp_proc_write",
82280 + [2678].param3 = 1,
82281 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82282 + [26834].name = "drm_ioctl",
82283 + [26834].param2 = 1,
82284 + [26843].file = "drivers/firewire/core-cdev.c",
82285 + [26843].name = "fw_device_op_compat_ioctl",
82286 + [26843].param2 = 1,
82287 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82288 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82289 + [26845].param3 = 1,
82290 + [26888].file = "net/bridge/br_ioctl.c",
82291 + [26888].name = "get_fdb_entries",
82292 + [26888].param3 = 1,
82293 + [26962].file = "drivers/usb/class/usbtmc.c",
82294 + [26962].name = "usbtmc_write",
82295 + [26962].param3 = 1,
82296 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82297 + [26966].name = "ts_write",
82298 + [26966].param3 = 1,
82299 + [27004].file = "drivers/misc/hpilo.c",
82300 + [27004].name = "ilo_write",
82301 + [27004].param3 = 1,
82302 + [27025].file = "fs/ntfs/file.c",
82303 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82304 + [27025].param3 = 1,
82305 + [27025].param4 = 1,
82306 + [27061].file = "drivers/firewire/core-cdev.c",
82307 + [27061].name = "iso_callback",
82308 + [27061].param3 = 1,
82309 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82310 + [2711].name = "dvb_ringbuffer_read_user",
82311 + [2711].param3 = 1,
82312 + [27129].file = "fs/lockd/mon.c",
82313 + [27129].name = "nsm_get_handle",
82314 + [27129].param4 = 1,
82315 + [27142].file = "fs/proc/kcore.c",
82316 + [27142].name = "read_kcore",
82317 + [27142].param3 = 1,
82318 + [27164].file = "include/drm/drm_mem_util.h",
82319 + [27164].name = "drm_calloc_large",
82320 + [27164].param1 = 1,
82321 + [27164].param2 = 1,
82322 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
82323 + [27176].name = "otp_read",
82324 + [27176].param2 = 1,
82325 + [27176].param5 = 1,
82326 + [27232].file = "security/apparmor/lib.c",
82327 + [27232].name = "kvmalloc",
82328 + [27232].param1 = 1,
82329 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82330 + [27275].name = "cxgbi_ddp_reserve",
82331 + [27275].param4 = 1,
82332 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82333 + [27280].name = "mlx4_en_create_tx_ring",
82334 + [27280].param4 = 1,
82335 + [27290].file = "security/selinux/ss/services.c",
82336 + [27290].name = "security_context_to_sid_core",
82337 + [27290].param2 = 1,
82338 + [27302].file = "fs/proc/base.c",
82339 + [27302].name = "proc_loginuid_write",
82340 + [27302].param3 = 1,
82341 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
82342 + [2730].name = "iscsi_decode_text_input",
82343 + [2730].param4 = 1,
82344 + [27314].file = "net/bluetooth/mgmt.c",
82345 + [27314].name = "cmd_complete",
82346 + [27314].param5 = 1,
82347 + [27472].file = "security/selinux/selinuxfs.c",
82348 + [27472].name = "sel_write_load",
82349 + [27472].param3 = 1,
82350 + [27491].file = "fs/proc/base.c",
82351 + [27491].name = "proc_pid_attr_write",
82352 + [27491].param3 = 1,
82353 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82354 + [27568].name = "t4_alloc_mem",
82355 + [27568].param1 = 1,
82356 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82357 + [27582].name = "ledd_proc_write",
82358 + [27582].param3 = 1,
82359 + [27595].file = "net/core/sock.c",
82360 + [27595].name = "sock_alloc_send_skb",
82361 + [27595].param2 = 1,
82362 + [27648].file = "net/bluetooth/l2cap_core.c",
82363 + [27648].name = "l2cap_bredr_sig_cmd",
82364 + [27648].param3 = 1,
82365 + [27697].file = "drivers/staging/mei/iorw.c",
82366 + [27697].name = "amthi_read",
82367 + [27697].param4 = 1,
82368 + [27911].file = "fs/ext4/resize.c",
82369 + [27911].name = "alloc_flex_gd",
82370 + [27911].param1 = 1,
82371 + [27927].file = "drivers/tty/tty_io.c",
82372 + [27927].name = "redirected_tty_write",
82373 + [27927].param3 = 1,
82374 + [28040].file = "kernel/kfifo.c",
82375 + [28040].name = "__kfifo_alloc",
82376 + [28040].param2 = 1,
82377 + [28040].param3 = 1,
82378 + [28151].file = "mm/filemap_xip.c",
82379 + [28151].name = "do_xip_mapping_read",
82380 + [28151].param5 = 1,
82381 + [28247].file = "net/sctp/tsnmap.c",
82382 + [28247].name = "sctp_tsnmap_init",
82383 + [28247].param2 = 1,
82384 + [28253].file = "include/linux/fb.h",
82385 + [28253].name = "alloc_apertures",
82386 + [28253].param1 = 1,
82387 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82388 + [28265].name = "fanotify_write",
82389 + [28265].param3 = 1,
82390 + [28316].file = "drivers/input/joydev.c",
82391 + [28316].name = "joydev_ioctl_common",
82392 + [28316].param2 = 1,
82393 + [28359].file = "drivers/spi/spidev.c",
82394 + [28359].name = "spidev_message",
82395 + [28359].param3 = 1,
82396 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82397 + [28360].name = "hiddev_compat_ioctl",
82398 + [28360].param2 = 1,
82399 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82400 + [28407].name = "rt2x00debug_write_csr",
82401 + [28407].param3 = 1,
82402 + [2847].file = "fs/ntfs/file.c",
82403 + [2847].name = "ntfs_copy_from_user",
82404 + [2847].param3 = 1,
82405 + [2847].param5 = 1,
82406 + [28584].file = "drivers/memstick/core/memstick.c",
82407 + [28584].name = "memstick_alloc_host",
82408 + [28584].param1 = 1,
82409 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82410 + [28783].name = "i915_cache_sharing_write",
82411 + [28783].param3 = 1,
82412 + [28787].file = "drivers/media/video/videobuf2-core.c",
82413 + [28787].name = "vb2_write",
82414 + [28787].param3 = 1,
82415 + [28879].file = "drivers/base/map.c",
82416 + [28879].name = "kobj_map",
82417 + [28879].param2 = 1,
82418 + [28879].param3 = 1,
82419 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82420 + [28889].name = "cm4040_write",
82421 + [28889].param3 = 1,
82422 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82423 + [29073].name = "vmw_kms_readback",
82424 + [29073].param6 = 1,
82425 + [29085].file = "security/apparmor/apparmorfs.c",
82426 + [29085].name = "profile_load",
82427 + [29085].param3 = 1,
82428 + [29092].file = "lib/lru_cache.c",
82429 + [29092].name = "lc_create",
82430 + [29092].param3 = 1,
82431 + [29257].file = "drivers/vhost/vhost.c",
82432 + [29257].name = "vhost_add_used_and_signal_n",
82433 + [29257].param4 = 1,
82434 + [29267].file = "net/ipv4/fib_trie.c",
82435 + [29267].name = "tnode_alloc",
82436 + [29267].param1 = 1,
82437 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82438 + [29338].name = "bnad_debugfs_write_regwr",
82439 + [29338].param3 = 1,
82440 + [29353].file = "net/sctp/socket.c",
82441 + [29353].name = "sctp_setsockopt_del_key",
82442 + [29353].param3 = 1,
82443 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82444 + [29405].name = "dw210x_op_rw",
82445 + [29405].param6 = 1,
82446 + [29542].file = "net/nfc/nci/core.c",
82447 + [29542].name = "nci_send_cmd",
82448 + [29542].param3 = 1,
82449 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82450 + [29714].name = "cxgbi_device_register",
82451 + [29714].param1 = 1,
82452 + [29714].param2 = 1,
82453 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
82454 + [2972].name = "crystalhd_create_dio_pool",
82455 + [2972].param2 = 1,
82456 + [29769].file = "drivers/misc/iwmc3200top/log.c",
82457 + [29769].name = "store_iwmct_log_level",
82458 + [29769].param4 = 1,
82459 + [29792].file = "drivers/staging/bcm/nvm.c",
82460 + [29792].name = "BcmCopySection",
82461 + [29792].param5 = 1,
82462 + [29859].file = "net/rds/page.c",
82463 + [29859].name = "rds_page_copy_user",
82464 + [29859].param4 = 1,
82465 + [29905].file = "mm/nobootmem.c",
82466 + [29905].name = "___alloc_bootmem",
82467 + [29905].param1 = 1,
82468 + [2995].file = "mm/page_alloc.c",
82469 + [2995].name = "alloc_large_system_hash",
82470 + [2995].param2 = 1,
82471 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
82472 + [30000].name = "wlc_phy_loadsampletable_nphy",
82473 + [30000].param3 = 1,
82474 + [30242].file = "fs/cifs/cifssmb.c",
82475 + [30242].name = "cifs_readdata_alloc",
82476 + [30242].param1 = 1,
82477 + [30494].file = "net/ceph/buffer.c",
82478 + [30494].name = "ceph_buffer_new",
82479 + [30494].param1 = 1,
82480 + [30590].file = "security/tomoyo/memory.c",
82481 + [30590].name = "tomoyo_commit_ok",
82482 + [30590].param2 = 1,
82483 + [3060].file = "lib/mpi/mpiutil.c",
82484 + [3060].name = "mpi_alloc_limb_space",
82485 + [3060].param1 = 1,
82486 + [30687].file = "drivers/uwb/uwb-debug.c",
82487 + [30687].name = "command_write",
82488 + [30687].param3 = 1,
82489 + [30726].file = "drivers/bluetooth/hci_vhci.c",
82490 + [30726].name = "vhci_get_user",
82491 + [30726].param3 = 1,
82492 + [30873].file = "net/packet/af_packet.c",
82493 + [30873].name = "alloc_one_pg_vec_page",
82494 + [30873].param1 = 1,
82495 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
82496 + [30970].name = "create_bounce_buffer",
82497 + [30970].param3 = 1,
82498 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
82499 + [310].name = "bm_realloc_pages",
82500 + [310].param2 = 1,
82501 + [3119].file = "drivers/misc/ibmasm/command.c",
82502 + [3119].name = "ibmasm_new_command",
82503 + [3119].param2 = 1,
82504 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82505 + [31207].name = "parse_arg",
82506 + [31207].param2 = 1,
82507 + [31287].file = "drivers/scsi/libsrp.c",
82508 + [31287].name = "srp_iu_pool_alloc",
82509 + [31287].param2 = 1,
82510 + [31291].file = "sound/pci/rme9652/rme9652.c",
82511 + [31291].name = "snd_rme9652_capture_copy",
82512 + [31291].param5 = 1,
82513 + [31348].file = "kernel/sched/core.c",
82514 + [31348].name = "sys_sched_getaffinity",
82515 + [31348].param2 = 1,
82516 + [31492].file = "drivers/hid/hidraw.c",
82517 + [31492].name = "hidraw_read",
82518 + [31492].param3 = 1,
82519 + [3170].file = "security/integrity/ima/ima_fs.c",
82520 + [3170].name = "ima_write_policy",
82521 + [3170].param3 = 1,
82522 + [31782].file = "drivers/misc/pti.c",
82523 + [31782].name = "pti_char_write",
82524 + [31782].param3 = 1,
82525 + [31789].file = "fs/file.c",
82526 + [31789].name = "alloc_fdmem",
82527 + [31789].param1 = 1,
82528 + [31957].file = "fs/afs/proc.c",
82529 + [31957].name = "afs_proc_cells_write",
82530 + [31957].param3 = 1,
82531 + [32002].file = "net/sctp/socket.c",
82532 + [32002].name = "sctp_setsockopt_active_key",
82533 + [32002].param3 = 1,
82534 + [32182].file = "net/sunrpc/cache.c",
82535 + [32182].name = "cache_write",
82536 + [32182].param3 = 1,
82537 + [32278].file = "kernel/time/timer_stats.c",
82538 + [32278].name = "tstats_write",
82539 + [32278].param3 = 1,
82540 + [32326].file = "drivers/tty/n_r3964.c",
82541 + [32326].name = "r3964_write",
82542 + [32326].param4 = 1,
82543 + [32399].file = "drivers/net/phy/mdio_bus.c",
82544 + [32399].name = "mdiobus_alloc_size",
82545 + [32399].param1 = 1,
82546 + [32402].file = "net/ceph/pagevec.c",
82547 + [32402].name = "ceph_copy_user_to_page_vector",
82548 + [32402].param4 = 1,
82549 + [3241].file = "drivers/usb/wusbcore/crypto.c",
82550 + [3241].name = "wusb_prf",
82551 + [3241].param7 = 1,
82552 + [32459].file = "drivers/media/radio/radio-wl1273.c",
82553 + [32459].name = "wl1273_fm_fops_write",
82554 + [32459].param3 = 1,
82555 + [32531].file = "fs/bio.c",
82556 + [32531].name = "__bio_map_kern",
82557 + [32531].param2 = 1,
82558 + [32531].param3 = 1,
82559 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
82560 + [32537].name = "buffer_to_user",
82561 + [32537].param3 = 1,
82562 + [32560].file = "drivers/input/input-mt.c",
82563 + [32560].name = "input_mt_init_slots",
82564 + [32560].param2 = 1,
82565 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82566 + [32600].name = "ath6kl_set_assoc_req_ies",
82567 + [32600].param3 = 1,
82568 + [32608].file = "security/selinux/selinuxfs.c",
82569 + [32608].name = "sel_write_checkreqprot",
82570 + [32608].param3 = 1,
82571 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82572 + [32812].name = "__vxge_hw_channel_allocate",
82573 + [32812].param3 = 1,
82574 + [32950].file = "fs/reiserfs/resize.c",
82575 + [32950].name = "reiserfs_resize",
82576 + [32950].param2 = 1,
82577 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82578 + [33010].name = "dvb_ringbuffer_pkt_read_user",
82579 + [33010].param5 = 1,
82580 + [33130].file = "net/llc/llc_sap.c",
82581 + [33130].name = "llc_alloc_frame",
82582 + [33130].param4 = 1,
82583 + [33221].file = "crypto/ablkcipher.c",
82584 + [33221].name = "ablkcipher_copy_iv",
82585 + [33221].param3 = 1,
82586 + [33268].file = "mm/maccess.c",
82587 + [33268].name = "__probe_kernel_write",
82588 + [33268].param3 = 1,
82589 + [33280].file = "fs/xfs/kmem.c",
82590 + [33280].name = "kmem_realloc",
82591 + [33280].param2 = 1,
82592 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
82593 + [33375].name = "_malloc",
82594 + [33375].param1 = 1,
82595 + [33420].file = "drivers/net/team/team.c",
82596 + [33420].name = "__team_options_register",
82597 + [33420].param3 = 1,
82598 + [33489].file = "fs/binfmt_misc.c",
82599 + [33489].name = "create_entry",
82600 + [33489].param2 = 1,
82601 + [33637].file = "net/9p/client.c",
82602 + [33637].name = "p9_client_read",
82603 + [33637].param5 = 1,
82604 + [33669].file = "fs/gfs2/glock.c",
82605 + [33669].name = "gfs2_glock_nq_m",
82606 + [33669].param1 = 1,
82607 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
82608 + [33704].name = "ttm_dma_page_pool_free",
82609 + [33704].param2 = 1,
82610 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
82611 + [33779].name = "resource_from_user",
82612 + [33779].param3 = 1,
82613 + [33810].file = "net/mac80211/util.c",
82614 + [33810].name = "ieee80211_send_probe_req",
82615 + [33810].param6 = 1,
82616 + [3384].file = "drivers/block/paride/pg.c",
82617 + [3384].name = "pg_write",
82618 + [3384].param3 = 1,
82619 + [34105].file = "fs/libfs.c",
82620 + [34105].name = "simple_read_from_buffer",
82621 + [34105].param2 = 1,
82622 + [34105].param5 = 1,
82623 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
82624 + [34120].name = "pvr2_stream_buffer_count",
82625 + [34120].param2 = 1,
82626 + [34226].file = "mm/shmem.c",
82627 + [34226].name = "shmem_xattr_set",
82628 + [34226].param4 = 1,
82629 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
82630 + [34251].name = "OS_kmalloc",
82631 + [34251].param1 = 1,
82632 + [34276].file = "drivers/media/video/videobuf2-core.c",
82633 + [34276].name = "__vb2_perform_fileio",
82634 + [34276].param3 = 1,
82635 + [34278].file = "fs/ubifs/debug.c",
82636 + [34278].name = "dfs_global_file_write",
82637 + [34278].param3 = 1,
82638 + [34432].file = "drivers/edac/edac_pci.c",
82639 + [34432].name = "edac_pci_alloc_ctl_info",
82640 + [34432].param1 = 1,
82641 + [34532].file = "drivers/virtio/virtio_ring.c",
82642 + [34532].name = "vring_add_indirect",
82643 + [34532].param3 = 1,
82644 + [34532].param4 = 1,
82645 + [34543].file = "net/sctp/tsnmap.c",
82646 + [34543].name = "sctp_tsnmap_grow",
82647 + [34543].param2 = 1,
82648 + [34551].file = "fs/ocfs2/stack_user.c",
82649 + [34551].name = "ocfs2_control_cfu",
82650 + [34551].param2 = 1,
82651 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82652 + [34634].name = "ath6kl_send_go_probe_resp",
82653 + [34634].param3 = 1,
82654 + [34666].file = "fs/cifs/cifs_debug.c",
82655 + [34666].name = "cifs_security_flags_proc_write",
82656 + [34666].param3 = 1,
82657 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
82658 + [3466].name = "altera_drscan",
82659 + [3466].param2 = 1,
82660 + [34672].file = "drivers/tty/tty_io.c",
82661 + [34672].name = "tty_write",
82662 + [34672].param3 = 1,
82663 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82664 + [34679].name = "ivtv_copy_buf_to_user",
82665 + [34679].param4 = 1,
82666 + [34721].file = "drivers/usb/host/hwa-hc.c",
82667 + [34721].name = "__hwahc_dev_set_key",
82668 + [34721].param5 = 1,
82669 + [34749].file = "mm/nobootmem.c",
82670 + [34749].name = "__alloc_bootmem_low_node",
82671 + [34749].param2 = 1,
82672 + [34760].file = "include/acpi/platform/aclinux.h",
82673 + [34760].name = "acpi_os_allocate_zeroed",
82674 + [34760].param1 = 1,
82675 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
82676 + [34802].name = "cxgbi_alloc_big_mem",
82677 + [34802].param1 = 1,
82678 + [34863].file = "drivers/video/fbsysfs.c",
82679 + [34863].name = "framebuffer_alloc",
82680 + [34863].param1 = 1,
82681 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82682 + [34868].name = "bnad_debugfs_write_regrd",
82683 + [34868].param3 = 1,
82684 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
82685 + [34882].name = "video_proc_write",
82686 + [34882].param3 = 1,
82687 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
82688 + [35050].name = "dlmfs_file_write",
82689 + [35050].param3 = 1,
82690 + [35119].file = "fs/xattr.c",
82691 + [35119].name = "sys_llistxattr",
82692 + [35119].param3 = 1,
82693 + [35129].file = "mm/nobootmem.c",
82694 + [35129].name = "___alloc_bootmem_nopanic",
82695 + [35129].param1 = 1,
82696 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
82697 + [35159].name = "__i2400mu_send_barker",
82698 + [35159].param3 = 1,
82699 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
82700 + [35232].name = "cx18_read",
82701 + [35232].param3 = 1,
82702 + [35234].file = "net/irda/irnet/irnet_ppp.c",
82703 + [35234].name = "irnet_ctrl_write",
82704 + [35234].param3 = 1,
82705 + [35256].file = "sound/core/memory.c",
82706 + [35256].name = "copy_from_user_toio",
82707 + [35256].param3 = 1,
82708 + [35268].file = "security/keys/request_key_auth.c",
82709 + [35268].name = "request_key_auth_read",
82710 + [35268].param3 = 1,
82711 + [3538].file = "net/bluetooth/mgmt.c",
82712 + [3538].name = "disconnect",
82713 + [3538].param4 = 1,
82714 + [35443].file = "sound/core/pcm_memory.c",
82715 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
82716 + [35443].param2 = 1,
82717 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82718 + [35468].name = "xenbus_file_write",
82719 + [35468].param3 = 1,
82720 + [35536].file = "kernel/sysctl_binary.c",
82721 + [35536].name = "bin_uuid",
82722 + [35536].param3 = 1,
82723 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82724 + [35551].name = "ivtv_read_pos",
82725 + [35551].param3 = 1,
82726 + [35556].file = "fs/read_write.c",
82727 + [35556].name = "sys_readv",
82728 + [35556].param3 = 1,
82729 + [35693].file = "drivers/staging/mei/main.c",
82730 + [35693].name = "mei_read",
82731 + [35693].param3 = 1,
82732 + [35703].file = "crypto/ablkcipher.c",
82733 + [35703].name = "ablkcipher_next_slow",
82734 + [35703].param3 = 1,
82735 + [35703].param4 = 1,
82736 + [35729].file = "include/linux/skbuff.h",
82737 + [35729].name = "__dev_alloc_skb",
82738 + [35729].param1 = 1,
82739 + [35731].file = "drivers/usb/class/cdc-wdm.c",
82740 + [35731].name = "wdm_read",
82741 + [35731].param3 = 1,
82742 + [35796].file = "drivers/mtd/nand/nand_bch.c",
82743 + [35796].name = "nand_bch_init",
82744 + [35796].param2 = 1,
82745 + [35796].param3 = 1,
82746 + [35880].file = "fs/ecryptfs/crypto.c",
82747 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
82748 + [35880].param6 = 1,
82749 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
82750 + [36076].name = "efx_tsoh_heap_alloc",
82751 + [36076].param2 = 1,
82752 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
82753 + [36080].name = "video_usercopy",
82754 + [36080].param2 = 1,
82755 + [36149].file = "fs/udf/inode.c",
82756 + [36149].name = "udf_alloc_i_data",
82757 + [36149].param2 = 1,
82758 + [36183].file = "drivers/tty/vt/vc_screen.c",
82759 + [36183].name = "vcs_read",
82760 + [36183].param3 = 1,
82761 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
82762 + [36199].name = "gss_pipe_downcall",
82763 + [36199].param3 = 1,
82764 + [36206].file = "net/ipv4/tcp_input.c",
82765 + [36206].name = "tcp_collapse",
82766 + [36206].param5 = 1,
82767 + [36206].param6 = 1,
82768 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
82769 + [36230].name = "ppp_cp_parse_cr",
82770 + [36230].param4 = 1,
82771 + [36284].file = "drivers/spi/spi.c",
82772 + [36284].name = "spi_register_board_info",
82773 + [36284].param2 = 1,
82774 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82775 + [36490].name = "ath6kl_cfg80211_connect_event",
82776 + [36490].param7 = 1,
82777 + [36522].file = "drivers/hid/hidraw.c",
82778 + [36522].name = "hidraw_send_report",
82779 + [36522].param3 = 1,
82780 + [36560].file = "net/sunrpc/cache.c",
82781 + [36560].name = "write_flush",
82782 + [36560].param3 = 1,
82783 + [36807].file = "drivers/usb/mon/mon_bin.c",
82784 + [36807].name = "mon_bin_get_event",
82785 + [36807].param4 = 1,
82786 + [37034].file = "fs/cifs/cifssmb.c",
82787 + [37034].name = "cifs_writedata_alloc",
82788 + [37034].param1 = 1,
82789 + [37044].file = "sound/firewire/packets-buffer.c",
82790 + [37044].name = "iso_packets_buffer_init",
82791 + [37044].param3 = 1,
82792 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
82793 + [37108].name = "dvb_video_write",
82794 + [37108].param3 = 1,
82795 + [37154].file = "net/nfc/llcp/commands.c",
82796 + [37154].name = "nfc_llcp_build_tlv",
82797 + [37154].param3 = 1,
82798 + [37163].file = "net/core/skbuff.c",
82799 + [37163].name = "__netdev_alloc_skb",
82800 + [37163].param2 = 1,
82801 + [37233].file = "fs/ocfs2/cluster/tcp.c",
82802 + [37233].name = "o2net_send_message_vec",
82803 + [37233].param4 = 1,
82804 + [37241].file = "net/atm/lec.c",
82805 + [37241].name = "lane2_associate_req",
82806 + [37241].param4 = 1,
82807 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
82808 + [37384].name = "vmw_fifo_reserve",
82809 + [37384].param2 = 1,
82810 + [37497].file = "net/mac80211/util.c",
82811 + [37497].name = "ieee80211_build_probe_req",
82812 + [37497].param7 = 1,
82813 + [37535].file = "kernel/trace/trace.c",
82814 + [37535].name = "tracing_trace_options_write",
82815 + [37535].param3 = 1,
82816 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
82817 + [37611].name = "split",
82818 + [37611].param2 = 1,
82819 + [37661].file = "mm/filemap.c",
82820 + [37661].name = "file_read_actor",
82821 + [37661].param4 = 1,
82822 + [37852].file = "drivers/staging/android/logger.c",
82823 + [37852].name = "do_read_log_to_user",
82824 + [37852].param4 = 1,
82825 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
82826 + [37921].name = "wl1271_rx_handle_data",
82827 + [37921].param3 = 1,
82828 + [37976].file = "drivers/platform/x86/asus_acpi.c",
82829 + [37976].name = "bluetooth_proc_write",
82830 + [37976].param3 = 1,
82831 + [3797].file = "sound/pci/asihpi/hpicmn.c",
82832 + [3797].name = "hpi_alloc_control_cache",
82833 + [3797].param1 = 1,
82834 + [3801].file = "drivers/block/paride/pt.c",
82835 + [3801].name = "pt_write",
82836 + [3801].param3 = 1,
82837 + [38052].file = "kernel/kexec.c",
82838 + [38052].name = "kimage_normal_alloc",
82839 + [38052].param3 = 1,
82840 + [38057].file = "fs/coda/psdev.c",
82841 + [38057].name = "coda_psdev_write",
82842 + [38057].param3 = 1,
82843 + [38186].file = "kernel/signal.c",
82844 + [38186].name = "do_sigpending",
82845 + [38186].param2 = 1,
82846 + [38314].file = "fs/nfs/read.c",
82847 + [38314].name = "nfs_readdata_alloc",
82848 + [38314].param1 = 1,
82849 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82850 + [38401].name = "queue_reply",
82851 + [38401].param3 = 1,
82852 + [3841].file = "drivers/platform/x86/asus_acpi.c",
82853 + [3841].name = "write_led",
82854 + [3841].param2 = 1,
82855 + [38532].file = "fs/afs/cell.c",
82856 + [38532].name = "afs_cell_lookup",
82857 + [38532].param2 = 1,
82858 + [38564].file = "fs/nfs/nfs4proc.c",
82859 + [38564].name = "nfs4_realloc_slot_table",
82860 + [38564].param2 = 1,
82861 + [38576].file = "drivers/i2c/i2c-dev.c",
82862 + [38576].name = "i2cdev_read",
82863 + [38576].param3 = 1,
82864 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
82865 + [38704].name = "uvc_alloc_entity",
82866 + [38704].param3 = 1,
82867 + [38704].param4 = 1,
82868 + [38747].file = "fs/xattr.c",
82869 + [38747].name = "sys_lgetxattr",
82870 + [38747].param4 = 1,
82871 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
82872 + [38867].name = "fc_host_post_vendor_event",
82873 + [38867].param3 = 1,
82874 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
82875 + [38931].name = "diva_os_alloc_message_buffer",
82876 + [38931].param1 = 1,
82877 + [38972].file = "security/smack/smackfs.c",
82878 + [38972].name = "smk_write_logging",
82879 + [38972].param3 = 1,
82880 + [39001].file = "net/xfrm/xfrm_hash.c",
82881 + [39001].name = "xfrm_hash_alloc",
82882 + [39001].param1 = 1,
82883 + [39052].file = "drivers/input/evdev.c",
82884 + [39052].name = "evdev_ioctl",
82885 + [39052].param2 = 1,
82886 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
82887 + [39066].name = "tda10048_writeregbulk",
82888 + [39066].param4 = 1,
82889 + [39118].file = "drivers/misc/iwmc3200top/log.c",
82890 + [39118].name = "store_iwmct_log_level_fw",
82891 + [39118].param4 = 1,
82892 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
82893 + [39254].name = "cmm_write",
82894 + [39254].param3 = 1,
82895 + [39392].file = "drivers/atm/solos-pci.c",
82896 + [39392].name = "send_command",
82897 + [39392].param4 = 1,
82898 + [39415].file = "fs/pstore/inode.c",
82899 + [39415].name = "pstore_mkfile",
82900 + [39415].param5 = 1,
82901 + [39417].file = "drivers/block/DAC960.c",
82902 + [39417].name = "dac960_user_command_proc_write",
82903 + [39417].param3 = 1,
82904 + [39460].file = "fs/btrfs/volumes.c",
82905 + [39460].name = "btrfs_map_block",
82906 + [39460].param3 = 1,
82907 + [39479].file = "drivers/ide/ide-tape.c",
82908 + [39479].name = "idetape_chrdev_read",
82909 + [39479].param3 = 1,
82910 + [39586].file = "drivers/hv/channel.c",
82911 + [39586].name = "create_gpadl_header",
82912 + [39586].param2 = 1,
82913 + [39638].file = "security/selinux/selinuxfs.c",
82914 + [39638].name = "sel_write_avc_cache_threshold",
82915 + [39638].param3 = 1,
82916 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
82917 + [39645].name = "dvb_generic_ioctl",
82918 + [39645].param2 = 1,
82919 + [39770].file = "include/linux/mISDNif.h",
82920 + [39770].name = "mI_alloc_skb",
82921 + [39770].param1 = 1,
82922 + [39813].file = "fs/ocfs2/stack_user.c",
82923 + [39813].name = "ocfs2_control_message",
82924 + [39813].param3 = 1,
82925 + [39888].file = "net/core/skbuff.c",
82926 + [39888].name = "__alloc_skb",
82927 + [39888].param1 = 1,
82928 + [39980].file = "net/bluetooth/mgmt.c",
82929 + [39980].name = "pair_device",
82930 + [39980].param4 = 1,
82931 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
82932 + [40043].name = "video_ioctl2",
82933 + [40043].param2 = 1,
82934 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
82935 + [40049].name = "btmrvl_psmode_write",
82936 + [40049].param3 = 1,
82937 + [40075].file = "drivers/media/video/c-qcam.c",
82938 + [40075].name = "qc_capture",
82939 + [40075].param3 = 1,
82940 + [40163].file = "fs/ncpfs/file.c",
82941 + [40163].name = "ncp_file_write",
82942 + [40163].param3 = 1,
82943 + [40240].file = "drivers/char/nvram.c",
82944 + [40240].name = "nvram_write",
82945 + [40240].param3 = 1,
82946 + [40256].file = "drivers/tty/vt/vc_screen.c",
82947 + [40256].name = "vcs_write",
82948 + [40256].param3 = 1,
82949 + [40302].file = "sound/isa/gus/gus_dram.c",
82950 + [40302].name = "snd_gus_dram_poke",
82951 + [40302].param4 = 1,
82952 + [40339].file = "drivers/acpi/apei/hest.c",
82953 + [40339].name = "hest_ghes_dev_register",
82954 + [40339].param1 = 1,
82955 + [40355].file = "drivers/staging/mei/main.c",
82956 + [40355].name = "mei_write",
82957 + [40355].param3 = 1,
82958 + [40373].file = "fs/cifs/cifs_spnego.c",
82959 + [40373].name = "cifs_spnego_key_instantiate",
82960 + [40373].param3 = 1,
82961 + [40519].file = "net/sctp/socket.c",
82962 + [40519].name = "sctp_setsockopt_events",
82963 + [40519].param3 = 1,
82964 + [40694].file = "mm/page_cgroup.c",
82965 + [40694].name = "alloc_page_cgroup",
82966 + [40694].param1 = 1,
82967 + [40731].file = "drivers/tty/tty_io.c",
82968 + [40731].name = "do_tty_write",
82969 + [40731].param5 = 1,
82970 + [40754].file = "fs/btrfs/delayed-inode.c",
82971 + [40754].name = "btrfs_alloc_delayed_item",
82972 + [40754].param1 = 1,
82973 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
82974 + [40786].name = "asn1_octets_decode",
82975 + [40786].param2 = 1,
82976 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
82977 + [40901].name = "drbd_bm_resize",
82978 + [40901].param2 = 1,
82979 + [40951].file = "drivers/xen/evtchn.c",
82980 + [40951].name = "evtchn_read",
82981 + [40951].param3 = 1,
82982 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
82983 + [40952].name = "xpc_kmalloc_cacheline_aligned",
82984 + [40952].param1 = 1,
82985 + [41000].file = "sound/core/pcm_native.c",
82986 + [41000].name = "snd_pcm_aio_read",
82987 + [41000].param3 = 1,
82988 + [41005].file = "net/bridge/netfilter/ebtables.c",
82989 + [41005].name = "copy_counters_to_user",
82990 + [41005].param5 = 1,
82991 + [41041].file = "net/core/sock.c",
82992 + [41041].name = "sock_wmalloc",
82993 + [41041].param2 = 1,
82994 + [41122].file = "fs/binfmt_misc.c",
82995 + [41122].name = "bm_status_write",
82996 + [41122].param3 = 1,
82997 + [41176].file = "kernel/trace/trace_events.c",
82998 + [41176].name = "subsystem_filter_write",
82999 + [41176].param3 = 1,
83000 + [41249].file = "drivers/media/video/zr364xx.c",
83001 + [41249].name = "send_control_msg",
83002 + [41249].param6 = 1,
83003 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
83004 + [41287].name = "vxge_os_dma_malloc_async",
83005 + [41287].param3 = 1,
83006 + [41302].file = "net/dns_resolver/dns_query.c",
83007 + [41302].name = "dns_query",
83008 + [41302].param3 = 1,
83009 + [41408].file = "mm/filemap_xip.c",
83010 + [41408].name = "__xip_file_write",
83011 + [41408].param3 = 1,
83012 + [41547].file = "net/bluetooth/smp.c",
83013 + [41547].name = "smp_build_cmd",
83014 + [41547].param3 = 1,
83015 + [4155].file = "kernel/kexec.c",
83016 + [4155].name = "do_kimage_alloc",
83017 + [4155].param3 = 1,
83018 + [41676].file = "fs/compat.c",
83019 + [41676].name = "compat_sys_preadv",
83020 + [41676].param3 = 1,
83021 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
83022 + [4167].name = "cx24116_writeregN",
83023 + [4167].param4 = 1,
83024 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83025 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
83026 + [41793].param7 = 1,
83027 + [41924].file = "security/keys/keyctl.c",
83028 + [41924].name = "keyctl_get_security",
83029 + [41924].param3 = 1,
83030 + [41968].file = "fs/btrfs/volumes.c",
83031 + [41968].name = "__btrfs_map_block",
83032 + [41968].param3 = 1,
83033 + [4202].file = "drivers/edac/edac_mc.c",
83034 + [4202].name = "edac_mc_alloc",
83035 + [4202].param1 = 1,
83036 + [42081].file = "net/econet/af_econet.c",
83037 + [42081].name = "aun_incoming",
83038 + [42081].param3 = 1,
83039 + [42143].file = "drivers/media/video/c-qcam.c",
83040 + [42143].name = "qcam_read",
83041 + [42143].param3 = 1,
83042 + [42206].file = "fs/quota/quota_tree.c",
83043 + [42206].name = "getdqbuf",
83044 + [42206].param1 = 1,
83045 + [42270].file = "net/wireless/scan.c",
83046 + [42270].name = "cfg80211_inform_bss_frame",
83047 + [42270].param4 = 1,
83048 + [42281].file = "include/linux/mISDNif.h",
83049 + [42281].name = "_queue_data",
83050 + [42281].param4 = 1,
83051 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83052 + [42420].name = "prism2_set_genericelement",
83053 + [42420].param3 = 1,
83054 + [42472].file = "fs/compat.c",
83055 + [42472].name = "compat_readv",
83056 + [42472].param3 = 1,
83057 + [42473].file = "net/tipc/name_table.c",
83058 + [42473].name = "tipc_subseq_alloc",
83059 + [42473].param1 = 1,
83060 + [42562].file = "kernel/kfifo.c",
83061 + [42562].name = "__kfifo_to_user_r",
83062 + [42562].param3 = 1,
83063 + [42666].file = "drivers/pcmcia/cistpl.c",
83064 + [42666].name = "read_cis_cache",
83065 + [42666].param4 = 1,
83066 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
83067 + [42714].name = "scsi_tgt_copy_sense",
83068 + [42714].param3 = 1,
83069 + [42833].file = "kernel/trace/blktrace.c",
83070 + [42833].name = "blk_msg_write",
83071 + [42833].param3 = 1,
83072 + [42857].file = "security/selinux/selinuxfs.c",
83073 + [42857].name = "sel_write_member",
83074 + [42857].param3 = 1,
83075 + [42882].file = "security/keys/user_defined.c",
83076 + [42882].name = "user_instantiate",
83077 + [42882].param3 = 1,
83078 + [42930].file = "net/caif/cfpkt_skbuff.c",
83079 + [42930].name = "cfpkt_create_pfx",
83080 + [42930].param1 = 1,
83081 + [42930].param2 = 1,
83082 + [43023].file = "drivers/usb/misc/usblcd.c",
83083 + [43023].name = "lcd_write",
83084 + [43023].param3 = 1,
83085 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
83086 + [43104].name = "dataflash_read_user_otp",
83087 + [43104].param3 = 1,
83088 + [43133].file = "lib/mpi/mpiutil.c",
83089 + [43133].name = "mpi_resize",
83090 + [43133].param2 = 1,
83091 + [4324].file = "drivers/video/fbmem.c",
83092 + [4324].name = "fb_read",
83093 + [4324].param3 = 1,
83094 + [43266].file = "fs/afs/cell.c",
83095 + [43266].name = "afs_cell_alloc",
83096 + [43266].param2 = 1,
83097 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
83098 + [4328].name = "musb_test_mode_write",
83099 + [4328].param3 = 1,
83100 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83101 + [43380].name = "bfad_debugfs_write_regrd",
83102 + [43380].param3 = 1,
83103 + [43510].file = "kernel/kexec.c",
83104 + [43510].name = "compat_sys_kexec_load",
83105 + [43510].param2 = 1,
83106 + [43540].file = "include/rdma/ib_verbs.h",
83107 + [43540].name = "ib_copy_to_udata",
83108 + [43540].param3 = 1,
83109 + [4357].file = "security/tomoyo/securityfs_if.c",
83110 + [4357].name = "tomoyo_read_self",
83111 + [4357].param3 = 1,
83112 + [43590].file = "security/smack/smackfs.c",
83113 + [43590].name = "smk_write_onlycap",
83114 + [43590].param3 = 1,
83115 + [43596].file = "drivers/usb/core/buffer.c",
83116 + [43596].name = "hcd_buffer_alloc",
83117 + [43596].param2 = 1,
83118 + [43632].file = "drivers/media/video/videobuf2-core.c",
83119 + [43632].name = "vb2_read",
83120 + [43632].param3 = 1,
83121 + [43659].file = "drivers/firmware/efivars.c",
83122 + [43659].name = "efivar_create_sysfs_entry",
83123 + [43659].param2 = 1,
83124 + [43731].file = "drivers/hid/hid-picolcd.c",
83125 + [43731].name = "picolcd_debug_eeprom_read",
83126 + [43731].param3 = 1,
83127 + [43777].file = "drivers/acpi/acpica/utobject.c",
83128 + [43777].name = "acpi_ut_create_buffer_object",
83129 + [43777].param1 = 1,
83130 + [43798].file = "net/bluetooth/mgmt.c",
83131 + [43798].name = "set_local_name",
83132 + [43798].param4 = 1,
83133 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
83134 + [4380].name = "dataflash_read_fact_otp",
83135 + [4380].param3 = 1,
83136 + [43834].file = "security/apparmor/apparmorfs.c",
83137 + [43834].name = "profile_replace",
83138 + [43834].param3 = 1,
83139 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83140 + [43895].name = "ddb_output_write",
83141 + [43895].param3 = 1,
83142 + [43899].file = "drivers/media/rc/imon.c",
83143 + [43899].name = "vfd_write",
83144 + [43899].param3 = 1,
83145 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
83146 + [43900].name = "cxgbi_device_portmap_create",
83147 + [43900].param3 = 1,
83148 + [43922].file = "drivers/mmc/card/mmc_test.c",
83149 + [43922].name = "mmc_test_alloc_mem",
83150 + [43922].param3 = 1,
83151 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
83152 + [43946].name = "aggr_recv_addba_req_evt",
83153 + [43946].param4 = 1,
83154 + [44006].file = "mm/process_vm_access.c",
83155 + [44006].name = "process_vm_rw_pages",
83156 + [44006].param5 = 1,
83157 + [44006].param6 = 1,
83158 + [44050].file = "fs/nfs/idmap.c",
83159 + [44050].name = "nfs_map_group_to_gid",
83160 + [44050].param3 = 1,
83161 + [44125].file = "fs/ext4/super.c",
83162 + [44125].name = "ext4_kvmalloc",
83163 + [44125].param1 = 1,
83164 + [44266].file = "kernel/cgroup.c",
83165 + [44266].name = "cgroup_write_string",
83166 + [44266].param5 = 1,
83167 + [44290].file = "drivers/net/usb/dm9601.c",
83168 + [44290].name = "dm_read",
83169 + [44290].param3 = 1,
83170 + [44308].file = "crypto/af_alg.c",
83171 + [44308].name = "alg_setkey",
83172 + [44308].param3 = 1,
83173 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
83174 + [44510].name = "bnx2_nvram_write",
83175 + [44510].param2 = 1,
83176 + [44625].file = "net/bluetooth/mgmt.c",
83177 + [44625].name = "set_connectable",
83178 + [44625].param4 = 1,
83179 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
83180 + [44642].name = "iwm_umac_set_config_var",
83181 + [44642].param4 = 1,
83182 + [44698].file = "net/sctp/socket.c",
83183 + [44698].name = "sctp_setsockopt_context",
83184 + [44698].param3 = 1,
83185 + [4471].file = "fs/ntfs/malloc.h",
83186 + [4471].name = "__ntfs_malloc",
83187 + [4471].param1 = 1,
83188 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83189 + [44773].name = "vme_user_write",
83190 + [44773].param3 = 1,
83191 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83192 + [44825].name = "_osd_realloc_seg",
83193 + [44825].param3 = 1,
83194 + [44852].file = "net/sctp/socket.c",
83195 + [44852].name = "sctp_setsockopt_rtoinfo",
83196 + [44852].param3 = 1,
83197 + [44936].file = "drivers/md/dm-raid.c",
83198 + [44936].name = "context_alloc",
83199 + [44936].param3 = 1,
83200 + [44943].file = "mm/util.c",
83201 + [44943].name = "kmemdup",
83202 + [44943].param2 = 1,
83203 + [44946].file = "net/sctp/socket.c",
83204 + [44946].name = "sctp_setsockopt_auth_chunk",
83205 + [44946].param3 = 1,
83206 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83207 + [44990].name = "pvr2_ioread_set_sync_key",
83208 + [44990].param3 = 1,
83209 + [45000].file = "fs/afs/proc.c",
83210 + [45000].name = "afs_proc_rootcell_write",
83211 + [45000].param3 = 1,
83212 + [45117].file = "drivers/staging/winbond/wb35reg.c",
83213 + [45117].name = "Wb35Reg_BurstWrite",
83214 + [45117].param4 = 1,
83215 + [45200].file = "drivers/scsi/scsi_proc.c",
83216 + [45200].name = "proc_scsi_write_proc",
83217 + [45200].param3 = 1,
83218 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83219 + [45217].name = "iwl_dbgfs_debug_level_write",
83220 + [45217].param3 = 1,
83221 + [45233].file = "net/rds/info.c",
83222 + [45233].name = "rds_info_getsockopt",
83223 + [45233].param3 = 1,
83224 + [45326].file = "drivers/mtd/ubi/cdev.c",
83225 + [45326].name = "vol_cdev_read",
83226 + [45326].param3 = 1,
83227 + [45335].file = "fs/read_write.c",
83228 + [45335].name = "vfs_writev",
83229 + [45335].param3 = 1,
83230 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83231 + [45366].name = "init_tid_tabs",
83232 + [45366].param2 = 1,
83233 + [45366].param3 = 1,
83234 + [45366].param4 = 1,
83235 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83236 + [45534].name = "carl9170_cmd_buf",
83237 + [45534].param3 = 1,
83238 + [45576].file = "net/netfilter/xt_recent.c",
83239 + [45576].name = "recent_mt_proc_write",
83240 + [45576].param3 = 1,
83241 + [45583].file = "fs/gfs2/dir.c",
83242 + [45583].name = "leaf_dealloc",
83243 + [45583].param3 = 1,
83244 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83245 + [45586].name = "rt2x00debug_write_bbp",
83246 + [45586].param3 = 1,
83247 + [45629].file = "lib/bch.c",
83248 + [45629].name = "bch_alloc",
83249 + [45629].param1 = 1,
83250 + [45633].file = "drivers/input/evdev.c",
83251 + [45633].name = "evdev_do_ioctl",
83252 + [45633].param2 = 1,
83253 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
83254 + [45743].name = "qlcnic_alloc_msix_entries",
83255 + [45743].param2 = 1,
83256 + [45864].file = "drivers/atm/ambassador.c",
83257 + [45864].name = "create_queues",
83258 + [45864].param2 = 1,
83259 + [45864].param3 = 1,
83260 + [45930].file = "security/apparmor/apparmorfs.c",
83261 + [45930].name = "profile_remove",
83262 + [45930].param3 = 1,
83263 + [45954].file = "drivers/usb/misc/legousbtower.c",
83264 + [45954].name = "tower_write",
83265 + [45954].param3 = 1,
83266 + [46140].file = "sound/core/memalloc.c",
83267 + [46140].name = "snd_mem_proc_write",
83268 + [46140].param3 = 1,
83269 + [4616].file = "net/sunrpc/cache.c",
83270 + [4616].name = "cache_do_downcall",
83271 + [4616].param3 = 1,
83272 + [46243].file = "fs/binfmt_misc.c",
83273 + [46243].name = "bm_register_write",
83274 + [46243].param3 = 1,
83275 + [46250].file = "fs/xattr.c",
83276 + [46250].name = "sys_getxattr",
83277 + [46250].param4 = 1,
83278 + [46343].file = "fs/compat.c",
83279 + [46343].name = "compat_do_readv_writev",
83280 + [46343].param4 = 1,
83281 + [46400].file = "drivers/staging/sep/sep_driver.c",
83282 + [46400].name = "sep_prepare_input_output_dma_table",
83283 + [46400].param2 = 1,
83284 + [46400].param3 = 1,
83285 + [46400].param4 = 1,
83286 + [4644].file = "drivers/net/usb/mcs7830.c",
83287 + [4644].name = "mcs7830_get_reg",
83288 + [4644].param3 = 1,
83289 + [46605].file = "sound/core/oss/pcm_oss.c",
83290 + [46605].name = "snd_pcm_oss_sync1",
83291 + [46605].param2 = 1,
83292 + [46630].file = "net/decnet/af_decnet.c",
83293 + [46630].name = "__dn_setsockopt",
83294 + [46630].param5 = 1,
83295 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83296 + [46655].name = "hdpvr_read",
83297 + [46655].param3 = 1,
83298 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83299 + [46685].name = "ttm_bo_fbdev_io",
83300 + [46685].param4 = 1,
83301 + [46742].file = "drivers/scsi/st.c",
83302 + [46742].name = "sgl_map_user_pages",
83303 + [46742].param2 = 1,
83304 + [46881].file = "drivers/char/lp.c",
83305 + [46881].name = "lp_write",
83306 + [46881].param3 = 1,
83307 + [47130].file = "kernel/kfifo.c",
83308 + [47130].name = "kfifo_copy_to_user",
83309 + [47130].param3 = 1,
83310 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83311 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83312 + [47265].param2 = 1,
83313 + [47265].param3 = 1,
83314 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
83315 + [47309].name = "asd_store_update_bios",
83316 + [47309].param4 = 1,
83317 + [47342].file = "fs/proc/base.c",
83318 + [47342].name = "sched_autogroup_write",
83319 + [47342].param3 = 1,
83320 + [47363].file = "drivers/input/evdev.c",
83321 + [47363].name = "evdev_ioctl_handler",
83322 + [47363].param2 = 1,
83323 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83324 + [47385].name = "zd_usb_iowrite16v",
83325 + [47385].param3 = 1,
83326 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83327 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
83328 + [4738].param3 = 1,
83329 + [47393].file = "drivers/net/wireless/ath/main.c",
83330 + [47393].name = "ath_rxbuf_alloc",
83331 + [47393].param2 = 1,
83332 + [47463].file = "fs/xfs/kmem.c",
83333 + [47463].name = "kmem_zalloc",
83334 + [47463].param1 = 1,
83335 + [47474].file = "kernel/trace/trace.c",
83336 + [47474].name = "tracing_buffers_read",
83337 + [47474].param3 = 1,
83338 + [47636].file = "drivers/usb/class/usblp.c",
83339 + [47636].name = "usblp_ioctl",
83340 + [47636].param2 = 1,
83341 + [47637].file = "drivers/block/cciss.c",
83342 + [47637].name = "cciss_proc_write",
83343 + [47637].param3 = 1,
83344 + [47712].file = "net/sctp/socket.c",
83345 + [47712].name = "sctp_setsockopt_maxburst",
83346 + [47712].param3 = 1,
83347 + [47728].file = "drivers/char/agp/isoch.c",
83348 + [47728].name = "agp_3_5_isochronous_node_enable",
83349 + [47728].param3 = 1,
83350 + [4779].file = "fs/pipe.c",
83351 + [4779].name = "pipe_set_size",
83352 + [4779].param2 = 1,
83353 + [47881].file = "security/selinux/selinuxfs.c",
83354 + [47881].name = "sel_write_disable",
83355 + [47881].param3 = 1,
83356 + [48111].file = "net/wireless/sme.c",
83357 + [48111].name = "cfg80211_roamed_bss",
83358 + [48111].param4 = 1,
83359 + [48111].param6 = 1,
83360 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
83361 + [48124].name = "iwm_notif_send",
83362 + [48124].param6 = 1,
83363 + [48155].file = "net/sctp/sm_make_chunk.c",
83364 + [48155].name = "sctp_make_abort_user",
83365 + [48155].param3 = 1,
83366 + [48182].file = "crypto/cryptd.c",
83367 + [48182].name = "cryptd_alloc_instance",
83368 + [48182].param2 = 1,
83369 + [48182].param3 = 1,
83370 + [48248].file = "security/keys/keyctl.c",
83371 + [48248].name = "keyctl_instantiate_key",
83372 + [48248].param3 = 1,
83373 + [4829].file = "drivers/block/floppy.c",
83374 + [4829].name = "fd_copyout",
83375 + [4829].param3 = 1,
83376 + [48632].file = "net/bluetooth/l2cap_core.c",
83377 + [48632].name = "l2cap_build_cmd",
83378 + [48632].param4 = 1,
83379 + [48642].file = "fs/hugetlbfs/inode.c",
83380 + [48642].name = "hugetlbfs_read",
83381 + [48642].param3 = 1,
83382 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83383 + [48720].name = "i915_max_freq_write",
83384 + [48720].param3 = 1,
83385 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83386 + [48768].name = "dev_irnet_write",
83387 + [48768].param3 = 1,
83388 + [48818].file = "net/sunrpc/svc.c",
83389 + [48818].name = "svc_pool_map_alloc_arrays",
83390 + [48818].param2 = 1,
83391 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83392 + [48856].name = "acpi_ut_initialize_buffer",
83393 + [48856].param2 = 1,
83394 + [48862].file = "net/sctp/socket.c",
83395 + [48862].name = "sctp_setsockopt_adaptation_layer",
83396 + [48862].param3 = 1,
83397 + [49126].file = "lib/prio_heap.c",
83398 + [49126].name = "heap_init",
83399 + [49126].param2 = 1,
83400 + [49143].file = "sound/core/oss/pcm_oss.c",
83401 + [49143].name = "snd_pcm_oss_write2",
83402 + [49143].param3 = 1,
83403 + [49216].file = "fs/read_write.c",
83404 + [49216].name = "do_readv_writev",
83405 + [49216].param4 = 1,
83406 + [49426].file = "net/bluetooth/l2cap_sock.c",
83407 + [49426].name = "l2cap_sock_setsockopt_old",
83408 + [49426].param4 = 1,
83409 + [49448].file = "drivers/isdn/gigaset/common.c",
83410 + [49448].name = "gigaset_initdriver",
83411 + [49448].param2 = 1,
83412 + [49494].file = "drivers/virtio/virtio_ring.c",
83413 + [49494].name = "vring_new_virtqueue",
83414 + [49494].param1 = 1,
83415 + [49499].file = "drivers/block/nvme.c",
83416 + [49499].name = "nvme_alloc_iod",
83417 + [49499].param1 = 1,
83418 + [49510].file = "net/sctp/socket.c",
83419 + [49510].name = "sctp_setsockopt_autoclose",
83420 + [49510].param3 = 1,
83421 + [4958].file = "drivers/net/wireless/p54/fwio.c",
83422 + [4958].name = "p54_alloc_skb",
83423 + [4958].param3 = 1,
83424 + [49604].file = "crypto/af_alg.c",
83425 + [49604].name = "alg_setsockopt",
83426 + [49604].param5 = 1,
83427 + [49646].file = "drivers/tty/vt/vt.c",
83428 + [49646].name = "vc_resize",
83429 + [49646].param2 = 1,
83430 + [49646].param3 = 1,
83431 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
83432 + [49658].name = "dma_attach",
83433 + [49658].param6 = 1,
83434 + [49658].param7 = 1,
83435 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83436 + [49663].name = "uvc_simplify_fraction",
83437 + [49663].param3 = 1,
83438 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83439 + [49746].name = "compat_do_arpt_set_ctl",
83440 + [49746].param4 = 1,
83441 + [49780].file = "net/mac80211/key.c",
83442 + [49780].name = "ieee80211_key_alloc",
83443 + [49780].param3 = 1,
83444 + [49805].file = "drivers/pci/pci.c",
83445 + [49805].name = "pci_add_cap_save_buffer",
83446 + [49805].param3 = 1,
83447 + [49845].file = "mm/vmalloc.c",
83448 + [49845].name = "__vmalloc_node",
83449 + [49845].param1 = 1,
83450 + [49929].file = "drivers/mtd/ubi/cdev.c",
83451 + [49929].name = "vol_cdev_direct_write",
83452 + [49929].param3 = 1,
83453 + [49935].file = "fs/xfs/kmem.c",
83454 + [49935].name = "kmem_zalloc_greedy",
83455 + [49935].param2 = 1,
83456 + [49935].param3 = 1,
83457 + [49].file = "net/atm/svc.c",
83458 + [49].name = "svc_setsockopt",
83459 + [49].param5 = 1,
83460 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83461 + [50518].name = "u_memcpya",
83462 + [50518].param2 = 1,
83463 + [50518].param3 = 1,
83464 + [5052].file = "drivers/char/ppdev.c",
83465 + [5052].name = "pp_read",
83466 + [5052].param3 = 1,
83467 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83468 + [50562].name = "zoran_write",
83469 + [50562].param3 = 1,
83470 + [50617].file = "fs/hugetlbfs/inode.c",
83471 + [50617].name = "hugetlbfs_read_actor",
83472 + [50617].param2 = 1,
83473 + [50617].param4 = 1,
83474 + [50617].param5 = 1,
83475 + [50692].file = "lib/ts_bm.c",
83476 + [50692].name = "bm_init",
83477 + [50692].param2 = 1,
83478 + [50813].file = "mm/vmalloc.c",
83479 + [50813].name = "__vmalloc_node_flags",
83480 + [50813].param1 = 1,
83481 + [5087].file = "drivers/atm/solos-pci.c",
83482 + [5087].name = "console_store",
83483 + [5087].param4 = 1,
83484 + [5102].file = "drivers/usb/misc/usbtest.c",
83485 + [5102].name = "usbtest_alloc_urb",
83486 + [5102].param3 = 1,
83487 + [5102].param5 = 1,
83488 + [51061].file = "net/bluetooth/mgmt.c",
83489 + [51061].name = "pin_code_reply",
83490 + [51061].param4 = 1,
83491 + [51139].file = "fs/pipe.c",
83492 + [51139].name = "pipe_iov_copy_to_user",
83493 + [51139].param3 = 1,
83494 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83495 + [51177].name = "xprt_rdma_allocate",
83496 + [51177].param2 = 1,
83497 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83498 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83499 + [51182].param1 = 1,
83500 + [51250].file = "fs/read_write.c",
83501 + [51250].name = "rw_copy_check_uvector",
83502 + [51250].param3 = 1,
83503 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83504 + [51253].name = "rt2x00debug_write_eeprom",
83505 + [51253].param3 = 1,
83506 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83507 + [51323].name = "snd_ac97_pcm_assign",
83508 + [51323].param2 = 1,
83509 + [51340].file = "drivers/usb/class/usblp.c",
83510 + [51340].name = "usblp_write",
83511 + [51340].param3 = 1,
83512 + [51499].file = "net/802/garp.c",
83513 + [51499].name = "garp_attr_create",
83514 + [51499].param3 = 1,
83515 + [51842].file = "drivers/hid/hid-core.c",
83516 + [51842].name = "hid_register_field",
83517 + [51842].param2 = 1,
83518 + [51842].param3 = 1,
83519 + [5197].file = "net/core/dev.c",
83520 + [5197].name = "dev_set_alias",
83521 + [5197].param3 = 1,
83522 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83523 + [5204].name = "usbvision_v4l2_read",
83524 + [5204].param3 = 1,
83525 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
83526 + [5206].name = "av7110_vbi_write",
83527 + [5206].param3 = 1,
83528 + [52086].file = "drivers/usb/image/mdc800.c",
83529 + [52086].name = "mdc800_device_read",
83530 + [52086].param3 = 1,
83531 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83532 + [52099].name = "do_surface_dirty_sou",
83533 + [52099].param7 = 1,
83534 + [52172].file = "drivers/pcmcia/cistpl.c",
83535 + [52172].name = "pccard_store_cis",
83536 + [52172].param6 = 1,
83537 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83538 + [52173].name = "remote_settings_file_write",
83539 + [52173].param3 = 1,
83540 + [52199].file = "mm/nobootmem.c",
83541 + [52199].name = "__alloc_bootmem",
83542 + [52199].param1 = 1,
83543 + [52343].file = "drivers/usb/misc/adutux.c",
83544 + [52343].name = "adu_read",
83545 + [52343].param3 = 1,
83546 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
83547 + [52401].name = "r871x_set_wpa_ie",
83548 + [52401].param3 = 1,
83549 + [52699].file = "lib/ts_fsm.c",
83550 + [52699].name = "fsm_init",
83551 + [52699].param2 = 1,
83552 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
83553 + [52721].name = "encrypted_instantiate",
83554 + [52721].param3 = 1,
83555 + [52902].file = "fs/xfs/kmem.h",
83556 + [52902].name = "kmem_zalloc_large",
83557 + [52902].param1 = 1,
83558 + [52950].file = "net/bluetooth/mgmt.c",
83559 + [52950].name = "set_discoverable",
83560 + [52950].param4 = 1,
83561 + [53041].file = "fs/libfs.c",
83562 + [53041].name = "simple_transaction_get",
83563 + [53041].param3 = 1,
83564 + [5313].file = "fs/gfs2/quota.c",
83565 + [5313].name = "do_sync",
83566 + [5313].param1 = 1,
83567 + [53209].file = "drivers/usb/host/ehci-sched.c",
83568 + [53209].name = "iso_sched_alloc",
83569 + [53209].param1 = 1,
83570 + [53302].file = "drivers/firewire/core-cdev.c",
83571 + [53302].name = "dispatch_ioctl",
83572 + [53302].param2 = 1,
83573 + [53355].file = "fs/ceph/dir.c",
83574 + [53355].name = "ceph_read_dir",
83575 + [53355].param3 = 1,
83576 + [53405].file = "drivers/media/video/videobuf-core.c",
83577 + [53405].name = "__videobuf_copy_to_user",
83578 + [53405].param4 = 1,
83579 + [53407].file = "net/wireless/sme.c",
83580 + [53407].name = "cfg80211_connect_result",
83581 + [53407].param4 = 1,
83582 + [53407].param6 = 1,
83583 + [53426].file = "fs/libfs.c",
83584 + [53426].name = "simple_transaction_read",
83585 + [53426].param3 = 1,
83586 + [5344].file = "security/selinux/ss/hashtab.c",
83587 + [5344].name = "hashtab_create",
83588 + [5344].param3 = 1,
83589 + [53513].file = "drivers/mmc/core/mmc_ops.c",
83590 + [53513].name = "mmc_send_bus_test",
83591 + [53513].param4 = 1,
83592 + [53626].file = "drivers/block/paride/pg.c",
83593 + [53626].name = "pg_read",
83594 + [53626].param3 = 1,
83595 + [53631].file = "mm/util.c",
83596 + [53631].name = "memdup_user",
83597 + [53631].param2 = 1,
83598 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
83599 + [53674].name = "ci_ll_write",
83600 + [53674].param4 = 1,
83601 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
83602 + [5389].name = "ib_uverbs_unmarshall_recv",
83603 + [5389].param5 = 1,
83604 + [53901].file = "net/rds/message.c",
83605 + [53901].name = "rds_message_alloc",
83606 + [53901].param1 = 1,
83607 + [53902].file = "net/sctp/socket.c",
83608 + [53902].name = "sctp_setsockopt_initmsg",
83609 + [53902].param3 = 1,
83610 + [5410].file = "kernel/kexec.c",
83611 + [5410].name = "sys_kexec_load",
83612 + [5410].param2 = 1,
83613 + [54172].file = "net/nfc/core.c",
83614 + [54172].name = "nfc_alloc_recv_skb",
83615 + [54172].param1 = 1,
83616 + [54182].file = "drivers/block/rbd.c",
83617 + [54182].name = "rbd_snap_add",
83618 + [54182].param4 = 1,
83619 + [54201].file = "drivers/platform/x86/asus_acpi.c",
83620 + [54201].name = "mled_proc_write",
83621 + [54201].param3 = 1,
83622 + [54263].file = "security/keys/trusted.c",
83623 + [54263].name = "trusted_instantiate",
83624 + [54263].param3 = 1,
83625 + [54296].file = "include/linux/mISDNif.h",
83626 + [54296].name = "_alloc_mISDN_skb",
83627 + [54296].param3 = 1,
83628 + [54298].file = "drivers/usb/wusbcore/crypto.c",
83629 + [54298].name = "wusb_ccm_mac",
83630 + [54298].param7 = 1,
83631 + [54318].file = "include/drm/drm_mem_util.h",
83632 + [54318].name = "drm_malloc_ab",
83633 + [54318].param1 = 1,
83634 + [54318].param2 = 1,
83635 + [54335].file = "drivers/md/dm-table.c",
83636 + [54335].name = "dm_vcalloc",
83637 + [54335].param1 = 1,
83638 + [54335].param2 = 1,
83639 + [54338].file = "fs/ntfs/malloc.h",
83640 + [54338].name = "ntfs_malloc_nofs",
83641 + [54338].param1 = 1,
83642 + [54339].file = "security/smack/smackfs.c",
83643 + [54339].name = "smk_write_cipso",
83644 + [54339].param3 = 1,
83645 + [54369].file = "drivers/usb/storage/realtek_cr.c",
83646 + [54369].name = "rts51x_read_mem",
83647 + [54369].param4 = 1,
83648 + [5438].file = "sound/core/memory.c",
83649 + [5438].name = "copy_to_user_fromio",
83650 + [5438].param3 = 1,
83651 + [54401].file = "lib/dynamic_debug.c",
83652 + [54401].name = "ddebug_proc_write",
83653 + [54401].param3 = 1,
83654 + [54467].file = "net/packet/af_packet.c",
83655 + [54467].name = "packet_setsockopt",
83656 + [54467].param5 = 1,
83657 + [54573].file = "ipc/sem.c",
83658 + [54573].name = "sys_semop",
83659 + [54573].param3 = 1,
83660 + [54583].file = "net/sctp/socket.c",
83661 + [54583].name = "sctp_setsockopt_peer_addr_params",
83662 + [54583].param3 = 1,
83663 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
83664 + [54643].name = "um_idi_write",
83665 + [54643].param3 = 1,
83666 + [54657].file = "mm/migrate.c",
83667 + [54657].name = "do_pages_stat",
83668 + [54657].param2 = 1,
83669 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
83670 + [54663].name = "diva_os_malloc",
83671 + [54663].param2 = 1,
83672 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
83673 + [54701].name = "altera_swap_ir",
83674 + [54701].param2 = 1,
83675 + [54751].file = "drivers/infiniband/core/device.c",
83676 + [54751].name = "ib_alloc_device",
83677 + [54751].param1 = 1,
83678 + [54771].file = "drivers/isdn/mISDN/socket.c",
83679 + [54771].name = "_l2_alloc_skb",
83680 + [54771].param1 = 1,
83681 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83682 + [54777].name = "ath6kl_debug_roam_tbl_event",
83683 + [54777].param3 = 1,
83684 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83685 + [54806].name = "lpfc_debugfs_dif_err_write",
83686 + [54806].param3 = 1,
83687 + [5494].file = "fs/cifs/cifsacl.c",
83688 + [5494].name = "cifs_idmap_key_instantiate",
83689 + [5494].param3 = 1,
83690 + [55066].file = "net/ipv6/ipv6_sockglue.c",
83691 + [55066].name = "do_ipv6_setsockopt",
83692 + [55066].param5 = 1,
83693 + [55105].file = "drivers/base/devres.c",
83694 + [55105].name = "devres_alloc",
83695 + [55105].param2 = 1,
83696 + [55115].file = "net/sctp/probe.c",
83697 + [55115].name = "sctpprobe_read",
83698 + [55115].param3 = 1,
83699 + [55155].file = "net/bluetooth/rfcomm/sock.c",
83700 + [55155].name = "rfcomm_sock_setsockopt",
83701 + [55155].param5 = 1,
83702 + [55187].file = "security/keys/keyctl.c",
83703 + [55187].name = "keyctl_describe_key",
83704 + [55187].param3 = 1,
83705 + [55253].file = "drivers/net/wireless/ray_cs.c",
83706 + [55253].name = "ray_cs_essid_proc_write",
83707 + [55253].param3 = 1,
83708 + [55341].file = "drivers/staging/sep/sep_driver.c",
83709 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
83710 + [55341].param4 = 1,
83711 + [55341].param5 = 1,
83712 + [55417].file = "drivers/hv/channel.c",
83713 + [55417].name = "vmbus_open",
83714 + [55417].param2 = 1,
83715 + [55417].param3 = 1,
83716 + [5548].file = "drivers/media/media-entity.c",
83717 + [5548].name = "media_entity_init",
83718 + [5548].param2 = 1,
83719 + [5548].param4 = 1,
83720 + [55546].file = "drivers/spi/spi.c",
83721 + [55546].name = "spi_alloc_master",
83722 + [55546].param2 = 1,
83723 + [55580].file = "drivers/usb/mon/mon_bin.c",
83724 + [55580].name = "copy_from_buf",
83725 + [55580].param2 = 1,
83726 + [55584].file = "drivers/tty/tty_buffer.c",
83727 + [55584].name = "tty_buffer_alloc",
83728 + [55584].param2 = 1,
83729 + [55712].file = "drivers/char/mem.c",
83730 + [55712].name = "read_zero",
83731 + [55712].param3 = 1,
83732 + [55727].file = "drivers/media/video/stk-webcam.c",
83733 + [55727].name = "stk_prepare_sio_buffers",
83734 + [55727].param2 = 1,
83735 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
83736 + [55816].name = "altera_set_ir_pre",
83737 + [55816].param2 = 1,
83738 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
83739 + [55826].name = "ipath_get_base_info",
83740 + [55826].param3 = 1,
83741 + [5586].file = "net/atm/common.c",
83742 + [5586].name = "alloc_tx",
83743 + [5586].param2 = 1,
83744 + [55978].file = "drivers/usb/misc/iowarrior.c",
83745 + [55978].name = "iowarrior_write",
83746 + [55978].param3 = 1,
83747 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
83748 + [56170].name = "__wa_xfer_setup_segs",
83749 + [56170].param2 = 1,
83750 + [56199].file = "fs/binfmt_misc.c",
83751 + [56199].name = "parse_command",
83752 + [56199].param2 = 1,
83753 + [56218].file = "drivers/mmc/card/mmc_test.c",
83754 + [56218].name = "mtf_test_write",
83755 + [56218].param3 = 1,
83756 + [56239].file = "fs/sysfs/file.c",
83757 + [56239].name = "fill_write_buffer",
83758 + [56239].param3 = 1,
83759 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
83760 + [5624].name = "ath9k_wmi_cmd",
83761 + [5624].param4 = 1,
83762 + [56416].file = "drivers/misc/lkdtm.c",
83763 + [56416].name = "do_register_entry",
83764 + [56416].param4 = 1,
83765 + [56458].file = "drivers/usb/host/hwa-hc.c",
83766 + [56458].name = "__hwahc_op_set_ptk",
83767 + [56458].param5 = 1,
83768 + [56471].file = "include/linux/slab.h",
83769 + [56471].name = "kcalloc",
83770 + [56471].param1 = 1,
83771 + [56471].param2 = 1,
83772 + [56513].file = "fs/cifs/connect.c",
83773 + [56513].name = "cifs_readv_from_socket",
83774 + [56513].param3 = 1,
83775 + [56531].file = "net/bluetooth/l2cap_core.c",
83776 + [56531].name = "l2cap_send_cmd",
83777 + [56531].param4 = 1,
83778 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
83779 + [56544].name = "receive_DataRequest",
83780 + [56544].param3 = 1,
83781 + [56609].file = "lib/mpi/mpi-internal.h",
83782 + [56609].name = "RESIZE_IF_NEEDED",
83783 + [56609].param2 = 1,
83784 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
83785 + [56652].name = "altera_set_dr_post",
83786 + [56652].param2 = 1,
83787 + [56653].file = "net/irda/af_irda.c",
83788 + [56653].name = "irda_setsockopt",
83789 + [56653].param5 = 1,
83790 + [56672].file = "drivers/char/agp/generic.c",
83791 + [56672].name = "agp_alloc_page_array",
83792 + [56672].param1 = 1,
83793 + [56798].file = "fs/bio.c",
83794 + [56798].name = "bio_alloc_map_data",
83795 + [56798].param2 = 1,
83796 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
83797 + [56843].name = "iscsi_recv_pdu",
83798 + [56843].param4 = 1,
83799 + [56903].file = "drivers/mtd/mtdchar.c",
83800 + [56903].name = "mtdchar_readoob",
83801 + [56903].param4 = 1,
83802 + [5699].file = "net/sctp/socket.c",
83803 + [5699].name = "sctp_setsockopt_default_send_param",
83804 + [5699].param3 = 1,
83805 + [5704].file = "drivers/mtd/mtdswap.c",
83806 + [5704].name = "mtdswap_init",
83807 + [5704].param2 = 1,
83808 + [57128].file = "drivers/pnp/pnpbios/proc.c",
83809 + [57128].name = "pnpbios_proc_write",
83810 + [57128].param3 = 1,
83811 + [57190].file = "drivers/char/agp/generic.c",
83812 + [57190].name = "agp_generic_alloc_user",
83813 + [57190].param1 = 1,
83814 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
83815 + [57252].name = "dvb_dmxdev_set_buffer_size",
83816 + [57252].param2 = 1,
83817 + [57392].file = "drivers/block/aoe/aoecmd.c",
83818 + [57392].name = "new_skb",
83819 + [57392].param1 = 1,
83820 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
83821 + [57471].name = "sn9c102_read",
83822 + [57471].param3 = 1,
83823 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
83824 + [57547].name = "get_derived_key",
83825 + [57547].param4 = 1,
83826 + [57552].file = "net/sunrpc/cache.c",
83827 + [57552].name = "cache_slow_downcall",
83828 + [57552].param2 = 1,
83829 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
83830 + [57670].name = "btmrvl_pscmd_write",
83831 + [57670].param3 = 1,
83832 + [57710].file = "include/linux/usb/wusb.h",
83833 + [57710].name = "wusb_prf_256",
83834 + [57710].param7 = 1,
83835 + [57724].file = "net/bluetooth/hci_sock.c",
83836 + [57724].name = "hci_sock_setsockopt",
83837 + [57724].param5 = 1,
83838 + [57761].file = "kernel/kexec.c",
83839 + [57761].name = "kimage_crash_alloc",
83840 + [57761].param3 = 1,
83841 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
83842 + [57786].name = "compat_do_ip6t_set_ctl",
83843 + [57786].param4 = 1,
83844 + [57872].file = "fs/ceph/xattr.c",
83845 + [57872].name = "ceph_setxattr",
83846 + [57872].param4 = 1,
83847 + [57927].file = "fs/read_write.c",
83848 + [57927].name = "sys_preadv",
83849 + [57927].param3 = 1,
83850 + [58012].file = "include/net/bluetooth/bluetooth.h",
83851 + [58012].name = "bt_skb_alloc",
83852 + [58012].param1 = 1,
83853 + [58020].file = "drivers/firewire/core-cdev.c",
83854 + [58020].name = "fw_device_op_ioctl",
83855 + [58020].param2 = 1,
83856 + [58043].file = "kernel/auditfilter.c",
83857 + [58043].name = "audit_unpack_string",
83858 + [58043].param3 = 1,
83859 + [58087].file = "kernel/module.c",
83860 + [58087].name = "module_alloc_update_bounds_rw",
83861 + [58087].param1 = 1,
83862 + [58124].file = "drivers/usb/misc/usbtest.c",
83863 + [58124].name = "ctrl_out",
83864 + [58124].param3 = 1,
83865 + [58124].param5 = 1,
83866 + [58217].file = "net/sctp/socket.c",
83867 + [58217].name = "sctp_setsockopt_peer_primary_addr",
83868 + [58217].param3 = 1,
83869 + [58263].file = "security/keys/keyring.c",
83870 + [58263].name = "keyring_read",
83871 + [58263].param3 = 1,
83872 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
83873 + [5830].name = "vga_switcheroo_debugfs_write",
83874 + [5830].param3 = 1,
83875 + [58320].file = "drivers/scsi/scsi_proc.c",
83876 + [58320].name = "proc_scsi_write",
83877 + [58320].param3 = 1,
83878 + [58344].file = "net/sunrpc/cache.c",
83879 + [58344].name = "read_flush",
83880 + [58344].param3 = 1,
83881 + [58379].file = "mm/nobootmem.c",
83882 + [58379].name = "__alloc_bootmem_node",
83883 + [58379].param2 = 1,
83884 + [58597].file = "kernel/kfifo.c",
83885 + [58597].name = "__kfifo_to_user",
83886 + [58597].param3 = 1,
83887 + [58641].file = "drivers/usb/misc/adutux.c",
83888 + [58641].name = "adu_write",
83889 + [58641].param3 = 1,
83890 + [58709].file = "fs/compat.c",
83891 + [58709].name = "compat_sys_pwritev",
83892 + [58709].param3 = 1,
83893 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83894 + [58769].name = "zd_usb_read_fw",
83895 + [58769].param4 = 1,
83896 + [5876].file = "drivers/net/ppp/ppp_generic.c",
83897 + [5876].name = "ppp_write",
83898 + [5876].param3 = 1,
83899 + [58826].file = "net/sunrpc/xprt.c",
83900 + [58826].name = "xprt_alloc",
83901 + [58826].param2 = 1,
83902 + [58865].file = "include/linux/slub_def.h",
83903 + [58865].name = "kmalloc_order_trace",
83904 + [58865].param1 = 1,
83905 + [58867].file = "drivers/platform/x86/asus_acpi.c",
83906 + [58867].name = "wled_proc_write",
83907 + [58867].param3 = 1,
83908 + [58888].file = "fs/xattr.c",
83909 + [58888].name = "listxattr",
83910 + [58888].param3 = 1,
83911 + [58889].file = "kernel/trace/trace_kprobe.c",
83912 + [58889].name = "probes_write",
83913 + [58889].param3 = 1,
83914 + [58912].file = "drivers/lguest/core.c",
83915 + [58912].name = "__lgwrite",
83916 + [58912].param4 = 1,
83917 + [58918].file = "sound/core/pcm_native.c",
83918 + [58918].name = "snd_pcm_aio_write",
83919 + [58918].param3 = 1,
83920 + [58942].file = "drivers/block/aoe/aoedev.c",
83921 + [58942].name = "aoedev_flush",
83922 + [58942].param2 = 1,
83923 + [58958].file = "fs/fuse/control.c",
83924 + [58958].name = "fuse_conn_limit_write",
83925 + [58958].param3 = 1,
83926 + [59005].file = "drivers/staging/sep/sep_driver.c",
83927 + [59005].name = "sep_prepare_input_dma_table",
83928 + [59005].param2 = 1,
83929 + [59005].param3 = 1,
83930 + [59013].file = "fs/xfs/xfs_ioctl.c",
83931 + [59013].name = "xfs_handle_to_dentry",
83932 + [59013].param3 = 1,
83933 + [59034].file = "drivers/acpi/acpica/dsobject.c",
83934 + [59034].name = "acpi_ds_build_internal_package_obj",
83935 + [59034].param3 = 1,
83936 + [59073].file = "drivers/staging/speakup/i18n.c",
83937 + [59073].name = "msg_set",
83938 + [59073].param3 = 1,
83939 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
83940 + [59074].name = "ddp_make_gl",
83941 + [59074].param1 = 1,
83942 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
83943 + [59297].name = "dvb_play",
83944 + [59297].param3 = 1,
83945 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
83946 + [59472].name = "command_file_write",
83947 + [59472].param3 = 1,
83948 + [59504].file = "fs/exofs/super.c",
83949 + [59504].name = "__alloc_dev_table",
83950 + [59504].param2 = 1,
83951 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83952 + [59505].name = "pvr2_ioread_read",
83953 + [59505].param3 = 1,
83954 + [59681].file = "fs/xfs/kmem.c",
83955 + [59681].name = "kmem_alloc",
83956 + [59681].param1 = 1,
83957 + [5968].file = "net/sunrpc/sched.c",
83958 + [5968].name = "rpc_malloc",
83959 + [5968].param2 = 1,
83960 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
83961 + [59695].name = "ulog_alloc_skb",
83962 + [59695].param1 = 1,
83963 + [59838].file = "net/netlink/af_netlink.c",
83964 + [59838].name = "nl_pid_hash_zalloc",
83965 + [59838].param1 = 1,
83966 + [59856].file = "drivers/base/devres.c",
83967 + [59856].name = "devm_kzalloc",
83968 + [59856].param2 = 1,
83969 + [60066].file = "mm/filemap.c",
83970 + [60066].name = "iov_iter_copy_from_user",
83971 + [60066].param4 = 1,
83972 + [60185].file = "kernel/params.c",
83973 + [60185].name = "kmalloc_parameter",
83974 + [60185].param1 = 1,
83975 + [60198].file = "fs/nfs/nfs4proc.c",
83976 + [60198].name = "nfs4_write_cached_acl",
83977 + [60198].param3 = 1,
83978 + [60330].file = "drivers/media/video/w9966.c",
83979 + [60330].name = "w9966_v4l_read",
83980 + [60330].param3 = 1,
83981 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
83982 + [604].name = "r8712_usbctrl_vendorreq",
83983 + [604].param6 = 1,
83984 + [60543].file = "drivers/usb/class/usbtmc.c",
83985 + [60543].name = "usbtmc_read",
83986 + [60543].param3 = 1,
83987 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
83988 + [60683].name = "snd_opl4_mem_proc_write",
83989 + [60683].param5 = 1,
83990 + [60693].file = "drivers/misc/hpilo.c",
83991 + [60693].name = "ilo_read",
83992 + [60693].param3 = 1,
83993 + [60744].file = "sound/pci/emu10k1/emuproc.c",
83994 + [60744].name = "snd_emu10k1_fx8010_read",
83995 + [60744].param5 = 1,
83996 + [60777].file = "fs/ntfs/malloc.h",
83997 + [60777].name = "ntfs_malloc_nofs_nofail",
83998 + [60777].param1 = 1,
83999 + [60833].file = "drivers/block/aoe/aoenet.c",
84000 + [60833].name = "set_aoe_iflist",
84001 + [60833].param2 = 1,
84002 + [60882].file = "drivers/input/joydev.c",
84003 + [60882].name = "joydev_compat_ioctl",
84004 + [60882].param2 = 1,
84005 + [60891].file = "kernel/sched/core.c",
84006 + [60891].name = "sys_sched_setaffinity",
84007 + [60891].param2 = 1,
84008 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
84009 + [60920].name = "qib_get_base_info",
84010 + [60920].param3 = 1,
84011 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
84012 + [60928].name = "bcm_char_read",
84013 + [60928].param3 = 1,
84014 + [61122].file = "drivers/base/devres.c",
84015 + [61122].name = "alloc_dr",
84016 + [61122].param2 = 1,
84017 + [61254].file = "drivers/scsi/scsi_devinfo.c",
84018 + [61254].name = "proc_scsi_devinfo_write",
84019 + [61254].param3 = 1,
84020 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84021 + [61283].name = "ath6kl_fwlog_read",
84022 + [61283].param3 = 1,
84023 + [61289].file = "security/apparmor/apparmorfs.c",
84024 + [61289].name = "aa_simple_write_to_buffer",
84025 + [61289].param4 = 1,
84026 + [61389].file = "include/linux/slab.h",
84027 + [61389].name = "kzalloc_node",
84028 + [61389].param1 = 1,
84029 + [61441].file = "fs/ntfs/file.c",
84030 + [61441].name = "ntfs_copy_from_user_iovec",
84031 + [61441].param3 = 1,
84032 + [61441].param6 = 1,
84033 + [61552].file = "drivers/input/evdev.c",
84034 + [61552].name = "str_to_user",
84035 + [61552].param2 = 1,
84036 + [61673].file = "security/keys/trusted.c",
84037 + [61673].name = "trusted_update",
84038 + [61673].param3 = 1,
84039 + [61676].file = "kernel/module.c",
84040 + [61676].name = "module_alloc_update_bounds_rx",
84041 + [61676].param1 = 1,
84042 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84043 + [61684].name = "cxgb3_get_cpl_reply_skb",
84044 + [61684].param2 = 1,
84045 + [6173].file = "net/netlink/af_netlink.c",
84046 + [6173].name = "netlink_sendmsg",
84047 + [6173].param4 = 1,
84048 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84049 + [61770].name = "et61x251_read",
84050 + [61770].param3 = 1,
84051 + [61772].file = "fs/exofs/ore_raid.c",
84052 + [61772].name = "_sp2d_alloc",
84053 + [61772].param1 = 1,
84054 + [61772].param2 = 1,
84055 + [61772].param3 = 1,
84056 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84057 + [61926].name = "ddb_input_read",
84058 + [61926].param3 = 1,
84059 + [61932].file = "drivers/message/fusion/mptctl.c",
84060 + [61932].name = "__mptctl_ioctl",
84061 + [61932].param2 = 1,
84062 + [61966].file = "fs/nfs/nfs4proc.c",
84063 + [61966].name = "nfs4_alloc_slots",
84064 + [61966].param1 = 1,
84065 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84066 + [62081].name = "vlsi_alloc_ring",
84067 + [62081].param3 = 1,
84068 + [62081].param4 = 1,
84069 + [62116].file = "fs/libfs.c",
84070 + [62116].name = "simple_attr_read",
84071 + [62116].param3 = 1,
84072 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
84073 + [6211].name = "pcnet32_realloc_tx_ring",
84074 + [6211].param3 = 1,
84075 + [62294].file = "sound/core/info.c",
84076 + [62294].name = "resize_info_buffer",
84077 + [62294].param2 = 1,
84078 + [62387].file = "fs/nfs/idmap.c",
84079 + [62387].name = "nfs_idmap_lookup_id",
84080 + [62387].param2 = 1,
84081 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
84082 + [62465].name = "altera_set_dr_pre",
84083 + [62465].param2 = 1,
84084 + [62466].file = "lib/mpi/mpiutil.c",
84085 + [62466].name = "mpi_alloc",
84086 + [62466].param1 = 1,
84087 + [62495].file = "drivers/block/floppy.c",
84088 + [62495].name = "fallback_on_nodma_alloc",
84089 + [62495].param2 = 1,
84090 + [62498].file = "fs/xattr.c",
84091 + [62498].name = "sys_listxattr",
84092 + [62498].param3 = 1,
84093 + [625].file = "fs/read_write.c",
84094 + [625].name = "sys_pwritev",
84095 + [625].param3 = 1,
84096 + [62662].file = "drivers/message/fusion/mptctl.c",
84097 + [62662].name = "mptctl_getiocinfo",
84098 + [62662].param2 = 1,
84099 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84100 + [62669].name = "tled_proc_write",
84101 + [62669].param3 = 1,
84102 + [62714].file = "security/keys/keyctl.c",
84103 + [62714].name = "keyctl_update_key",
84104 + [62714].param3 = 1,
84105 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
84106 + [62760].name = "play_iframe",
84107 + [62760].param3 = 1,
84108 + [62851].file = "fs/proc/vmcore.c",
84109 + [62851].name = "read_vmcore",
84110 + [62851].param3 = 1,
84111 + [62870].file = "fs/nfs/idmap.c",
84112 + [62870].name = "nfs_idmap_get_desc",
84113 + [62870].param2 = 1,
84114 + [62870].param4 = 1,
84115 + [62905].file = "net/caif/cfpkt_skbuff.c",
84116 + [62905].name = "cfpkt_create",
84117 + [62905].param1 = 1,
84118 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
84119 + [62920].name = "b43_nphy_load_samples",
84120 + [62920].param3 = 1,
84121 + [62925].file = "include/rdma/ib_verbs.h",
84122 + [62925].name = "ib_copy_from_udata",
84123 + [62925].param3 = 1,
84124 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
84125 + [62934].name = "wl1251_cmd_template_set",
84126 + [62934].param4 = 1,
84127 + [62940].file = "drivers/scsi/libsrp.c",
84128 + [62940].name = "srp_ring_alloc",
84129 + [62940].param2 = 1,
84130 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84131 + [62967].name = "encrypted_update",
84132 + [62967].param3 = 1,
84133 + [62970].file = "net/sched/sch_api.c",
84134 + [62970].name = "qdisc_class_hash_alloc",
84135 + [62970].param1 = 1,
84136 + [62999].file = "net/core/neighbour.c",
84137 + [62999].name = "neigh_hash_alloc",
84138 + [62999].param1 = 1,
84139 + [63007].file = "fs/proc/base.c",
84140 + [63007].name = "proc_coredump_filter_write",
84141 + [63007].param3 = 1,
84142 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84143 + [63010].name = "ttm_page_pool_free",
84144 + [63010].param2 = 1,
84145 + [63045].file = "crypto/shash.c",
84146 + [63045].name = "shash_setkey_unaligned",
84147 + [63045].param3 = 1,
84148 + [63075].file = "kernel/relay.c",
84149 + [63075].name = "relay_alloc_page_array",
84150 + [63075].param1 = 1,
84151 + [63076].file = "fs/cifs/xattr.c",
84152 + [63076].name = "cifs_setxattr",
84153 + [63076].param4 = 1,
84154 + [63091].file = "drivers/net/usb/pegasus.c",
84155 + [63091].name = "get_registers",
84156 + [63091].param3 = 1,
84157 + [6331].file = "drivers/atm/solos-pci.c",
84158 + [6331].name = "solos_param_store",
84159 + [6331].param4 = 1,
84160 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84161 + [63367].name = "ip_set_alloc",
84162 + [63367].param1 = 1,
84163 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84164 + [63489].name = "btmrvl_hscfgcmd_write",
84165 + [63489].param3 = 1,
84166 + [63490].file = "crypto/shash.c",
84167 + [63490].name = "shash_compat_setkey",
84168 + [63490].param3 = 1,
84169 + [63605].file = "mm/mempool.c",
84170 + [63605].name = "mempool_kmalloc",
84171 + [63605].param2 = 1,
84172 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
84173 + [63633].name = "btmrvl_sdio_host_to_card",
84174 + [63633].param3 = 1,
84175 + [63961].file = "fs/xattr.c",
84176 + [63961].name = "sys_flistxattr",
84177 + [63961].param3 = 1,
84178 + [63964].file = "net/sctp/socket.c",
84179 + [63964].name = "sctp_setsockopt_maxseg",
84180 + [63964].param3 = 1,
84181 + [63988].file = "drivers/input/evdev.c",
84182 + [63988].name = "evdev_ioctl_compat",
84183 + [63988].param2 = 1,
84184 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
84185 + [64055].name = "dvb_aplay",
84186 + [64055].param3 = 1,
84187 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84188 + [64156].name = "ath6kl_mgmt_tx",
84189 + [64156].param9 = 1,
84190 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
84191 + [64226].name = "ca_extend",
84192 + [64226].param2 = 1,
84193 + [64227].file = "mm/nobootmem.c",
84194 + [64227].name = "__alloc_bootmem_node_nopanic",
84195 + [64227].param2 = 1,
84196 + [64351].file = "kernel/kfifo.c",
84197 + [64351].name = "kfifo_copy_from_user",
84198 + [64351].param3 = 1,
84199 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84200 + [64392].name = "mmc_send_cxd_data",
84201 + [64392].param5 = 1,
84202 + [64423].file = "kernel/sched/core.c",
84203 + [64423].name = "get_user_cpu_mask",
84204 + [64423].param2 = 1,
84205 + [64432].file = "security/selinux/selinuxfs.c",
84206 + [64432].name = "sel_write_create",
84207 + [64432].param3 = 1,
84208 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84209 + [64471].name = "btmrvl_hscmd_write",
84210 + [64471].param3 = 1,
84211 + [64667].file = "sound/core/oss/pcm_oss.c",
84212 + [64667].name = "snd_pcm_oss_read",
84213 + [64667].param3 = 1,
84214 + [64689].file = "sound/isa/gus/gus_dram.c",
84215 + [64689].name = "snd_gus_dram_read",
84216 + [64689].param4 = 1,
84217 + [64692].file = "fs/binfmt_misc.c",
84218 + [64692].name = "bm_entry_write",
84219 + [64692].param3 = 1,
84220 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84221 + [64705].name = "sca3000_read_first_n_hw_rb",
84222 + [64705].param2 = 1,
84223 + [64713].file = "fs/cifs/connect.c",
84224 + [64713].name = "extract_hostname",
84225 + [64713].param1 = 1,
84226 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84227 + [64743].name = "dlmfs_file_read",
84228 + [64743].param3 = 1,
84229 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
84230 + [64771].name = "datablob_format",
84231 + [64771].param2 = 1,
84232 + [6477].file = "net/bluetooth/mgmt.c",
84233 + [6477].name = "mgmt_pending_add",
84234 + [6477].param5 = 1,
84235 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84236 + [64906].name = "b43legacy_debugfs_write",
84237 + [64906].param3 = 1,
84238 + [64913].file = "sound/core/oss/pcm_oss.c",
84239 + [64913].name = "snd_pcm_oss_write1",
84240 + [64913].param3 = 1,
84241 + [64961].file = "drivers/spi/spidev.c",
84242 + [64961].name = "spidev_ioctl",
84243 + [64961].param2 = 1,
84244 + [65033].file = "crypto/shash.c",
84245 + [65033].name = "shash_async_setkey",
84246 + [65033].param3 = 1,
84247 + [65093].file = "security/integrity/evm/evm_secfs.c",
84248 + [65093].name = "evm_write_key",
84249 + [65093].param3 = 1,
84250 + [6514].file = "mm/nobootmem.c",
84251 + [6514].name = "__alloc_bootmem_low",
84252 + [6514].param1 = 1,
84253 + [65169].file = "net/core/skbuff.c",
84254 + [65169].name = "dev_alloc_skb",
84255 + [65169].param1 = 1,
84256 + [6517].file = "drivers/md/dm-table.c",
84257 + [6517].name = "alloc_targets",
84258 + [6517].param2 = 1,
84259 + [65205].file = "drivers/input/evdev.c",
84260 + [65205].name = "handle_eviocgbit",
84261 + [65205].param3 = 1,
84262 + [65237].file = "kernel/profile.c",
84263 + [65237].name = "read_profile",
84264 + [65237].param3 = 1,
84265 + [65343].file = "kernel/trace/trace.c",
84266 + [65343].name = "tracing_clock_write",
84267 + [65343].param3 = 1,
84268 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84269 + [65345].name = "xz_dec_lzma2_create",
84270 + [65345].param2 = 1,
84271 + [65409].file = "net/802/garp.c",
84272 + [65409].name = "garp_request_join",
84273 + [65409].param4 = 1,
84274 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84275 + [65432].name = "kone_receive",
84276 + [65432].param4 = 1,
84277 + [65514].file = "drivers/media/video/gspca/t613.c",
84278 + [65514].name = "reg_w_ixbuf",
84279 + [65514].param4 = 1,
84280 + [6551].file = "drivers/usb/host/xhci-mem.c",
84281 + [6551].name = "xhci_alloc_stream_info",
84282 + [6551].param3 = 1,
84283 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84284 + [65535].name = "opera1_xilinx_rw",
84285 + [65535].param5 = 1,
84286 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84287 + [6672].name = "b43_debugfs_write",
84288 + [6672].param3 = 1,
84289 + [6691].file = "drivers/acpi/proc.c",
84290 + [6691].name = "acpi_system_write_wakeup_device",
84291 + [6691].param3 = 1,
84292 + [6865].file = "drivers/staging/iio/ring_sw.c",
84293 + [6865].name = "iio_read_first_n_sw_rb",
84294 + [6865].param2 = 1,
84295 + [6867].file = "fs/coda/psdev.c",
84296 + [6867].name = "coda_psdev_read",
84297 + [6867].param3 = 1,
84298 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84299 + [6891].name = "btmrvl_gpiogap_write",
84300 + [6891].param3 = 1,
84301 + [6944].file = "drivers/ide/ide-proc.c",
84302 + [6944].name = "ide_settings_proc_write",
84303 + [6944].param3 = 1,
84304 + [6950].file = "drivers/isdn/capi/capi.c",
84305 + [6950].name = "capi_write",
84306 + [6950].param3 = 1,
84307 + [697].file = "sound/isa/gus/gus_dram.c",
84308 + [697].name = "snd_gus_dram_peek",
84309 + [697].param4 = 1,
84310 + [7066].file = "security/keys/keyctl.c",
84311 + [7066].name = "keyctl_instantiate_key_common",
84312 + [7066].param4 = 1,
84313 + [7125].file = "include/net/nfc/nci_core.h",
84314 + [7125].name = "nci_skb_alloc",
84315 + [7125].param2 = 1,
84316 + [7129].file = "mm/maccess.c",
84317 + [7129].name = "__probe_kernel_read",
84318 + [7129].param3 = 1,
84319 + [7158].file = "kernel/trace/trace.c",
84320 + [7158].name = "tracing_read_pipe",
84321 + [7158].param3 = 1,
84322 + [720].file = "sound/pci/rme9652/hdsp.c",
84323 + [720].name = "snd_hdsp_playback_copy",
84324 + [720].param5 = 1,
84325 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
84326 + [7236].name = "drm_plane_init",
84327 + [7236].param6 = 1,
84328 + [7411].file = "drivers/vhost/vhost.c",
84329 + [7411].name = "__vhost_add_used_n",
84330 + [7411].param3 = 1,
84331 + [7432].file = "net/bluetooth/mgmt.c",
84332 + [7432].name = "mgmt_event",
84333 + [7432].param4 = 1,
84334 + [7488].file = "security/keys/user_defined.c",
84335 + [7488].name = "user_read",
84336 + [7488].param3 = 1,
84337 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84338 + [7551].name = "ad7879_spi_xfer",
84339 + [7551].param3 = 1,
84340 + [7671].file = "mm/nobootmem.c",
84341 + [7671].name = "__alloc_bootmem_node_high",
84342 + [7671].param2 = 1,
84343 + [7676].file = "drivers/acpi/custom_method.c",
84344 + [7676].name = "cm_write",
84345 + [7676].param3 = 1,
84346 + [7693].file = "net/sctp/socket.c",
84347 + [7693].name = "sctp_setsockopt_associnfo",
84348 + [7693].param3 = 1,
84349 + [7697].file = "security/selinux/selinuxfs.c",
84350 + [7697].name = "sel_write_access",
84351 + [7697].param3 = 1,
84352 + [7843].file = "fs/compat.c",
84353 + [7843].name = "compat_sys_readv",
84354 + [7843].param3 = 1,
84355 + [7883].file = "net/sched/sch_sfq.c",
84356 + [7883].name = "sfq_alloc",
84357 + [7883].param1 = 1,
84358 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
84359 + [7924].name = "cx18_read_pos",
84360 + [7924].param3 = 1,
84361 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84362 + [7958].name = "vga_arb_write",
84363 + [7958].param3 = 1,
84364 + [7976].file = "drivers/usb/gadget/rndis.c",
84365 + [7976].name = "rndis_add_response",
84366 + [7976].param2 = 1,
84367 + [7985].file = "net/mac80211/cfg.c",
84368 + [7985].name = "ieee80211_mgmt_tx",
84369 + [7985].param9 = 1,
84370 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84371 + [8014].name = "init_list_set",
84372 + [8014].param2 = 1,
84373 + [8014].param3 = 1,
84374 + [8126].file = "sound/soc/soc-core.c",
84375 + [8126].name = "codec_reg_read_file",
84376 + [8126].param3 = 1,
84377 + [8317].file = "security/smack/smackfs.c",
84378 + [8317].name = "smk_write_ambient",
84379 + [8317].param3 = 1,
84380 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84381 + [8335].name = "dvb_dvr_set_buffer_size",
84382 + [8335].param2 = 1,
84383 + [8383].file = "kernel/module.c",
84384 + [8383].name = "copy_and_check",
84385 + [8383].param3 = 1,
84386 + [8411].file = "net/caif/cfpkt_skbuff.c",
84387 + [8411].name = "cfpkt_append",
84388 + [8411].param3 = 1,
84389 + [8536].file = "fs/cifs/dns_resolve.c",
84390 + [8536].name = "dns_resolve_server_name_to_ip",
84391 + [8536].param1 = 1,
84392 + [857].file = "drivers/virtio/virtio_ring.c",
84393 + [857].name = "virtqueue_add_buf",
84394 + [857].param3 = 1,
84395 + [857].param4 = 1,
84396 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84397 + [8650].name = "vmw_kms_present",
84398 + [8650].param9 = 1,
84399 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
84400 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
84401 + [8654].param2 = 1,
84402 + [8654].param3 = 1,
84403 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84404 + [865].name = "regmap_access_read_file",
84405 + [865].param3 = 1,
84406 + [8663].file = "net/bridge/netfilter/ebtables.c",
84407 + [8663].name = "do_update_counters",
84408 + [8663].param4 = 1,
84409 + [8684].file = "fs/read_write.c",
84410 + [8684].name = "sys_writev",
84411 + [8684].param3 = 1,
84412 + [8699].file = "security/selinux/selinuxfs.c",
84413 + [8699].name = "sel_commit_bools_write",
84414 + [8699].param3 = 1,
84415 + [8764].file = "drivers/usb/core/devio.c",
84416 + [8764].name = "usbdev_read",
84417 + [8764].param3 = 1,
84418 + [8802].file = "fs/dlm/user.c",
84419 + [8802].name = "device_write",
84420 + [8802].param3 = 1,
84421 + [8810].file = "net/mac80211/debugfs_sta.c",
84422 + [8810].name = "sta_agg_status_write",
84423 + [8810].param3 = 1,
84424 + [8815].file = "security/tomoyo/securityfs_if.c",
84425 + [8815].name = "tomoyo_write_self",
84426 + [8815].param3 = 1,
84427 + [8821].file = "net/wireless/sme.c",
84428 + [8821].name = "cfg80211_roamed",
84429 + [8821].param5 = 1,
84430 + [8821].param7 = 1,
84431 + [8833].file = "security/selinux/ss/services.c",
84432 + [8833].name = "security_context_to_sid",
84433 + [8833].param2 = 1,
84434 + [8838].file = "lib/mpi/mpi-bit.c",
84435 + [8838].name = "mpi_lshift_limbs",
84436 + [8838].param2 = 1,
84437 + [8851].file = "net/key/af_key.c",
84438 + [8851].name = "pfkey_sendmsg",
84439 + [8851].param4 = 1,
84440 + [8917].file = "net/can/raw.c",
84441 + [8917].name = "raw_setsockopt",
84442 + [8917].param5 = 1,
84443 + [8983].file = "include/linux/skbuff.h",
84444 + [8983].name = "alloc_skb",
84445 + [8983].param1 = 1,
84446 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
84447 + [9117].name = "regcache_rbtree_insert_to_block",
84448 + [9117].param5 = 1,
84449 + [9226].file = "mm/migrate.c",
84450 + [9226].name = "sys_move_pages",
84451 + [9226].param2 = 1,
84452 + [9304].file = "kernel/auditfilter.c",
84453 + [9304].name = "audit_init_entry",
84454 + [9304].param1 = 1,
84455 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
84456 + [9317].name = "wa_nep_queue",
84457 + [9317].param2 = 1,
84458 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84459 + [9341].name = "erst_dbg_write",
84460 + [9341].param3 = 1,
84461 + [9386].file = "fs/exofs/ore.c",
84462 + [9386].name = "_ore_get_io_state",
84463 + [9386].param3 = 1,
84464 + [9386].param4 = 1,
84465 + [9386].param5 = 1,
84466 + [9538].file = "crypto/blkcipher.c",
84467 + [9538].name = "blkcipher_copy_iv",
84468 + [9538].param3 = 1,
84469 + [9546].file = "drivers/video/fbmem.c",
84470 + [9546].name = "fb_write",
84471 + [9546].param3 = 1,
84472 + [9601].file = "kernel/kfifo.c",
84473 + [9601].name = "__kfifo_from_user",
84474 + [9601].param3 = 1,
84475 + [9618].file = "security/selinux/selinuxfs.c",
84476 + [9618].name = "sel_write_bool",
84477 + [9618].param3 = 1,
84478 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84479 + [9768].name = "vmw_execbuf_process",
84480 + [9768].param5 = 1,
84481 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84482 + [9828].name = "dvb_demux_do_ioctl",
84483 + [9828].param3 = 1,
84484 + [9870].file = "net/atm/addr.c",
84485 + [9870].name = "atm_get_addr",
84486 + [9870].param3 = 1,
84487 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84488 + [9977].name = "zd_usb_iowrite16v_async",
84489 + [9977].param3 = 1,
84490 + [16344].collision = 1,
84491 + [307].collision = 1,
84492 + [31649].collision = 1,
84493 + [33040].collision = 1,
84494 + [45231].collision = 1,
84495 + [60651].collision = 1,
84496 +};
84497 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84498 new file mode 100644
84499 index 0000000..9ec45ae
84500 --- /dev/null
84501 +++ b/tools/gcc/size_overflow_hash2.h
84502 @@ -0,0 +1,35 @@
84503 +struct size_overflow_hash size_overflow_hash2[65536] = {
84504 + [22224].file = "fs/proc/vmcore.c",
84505 + [22224].name = "read_from_oldmem",
84506 + [22224].param2 = 1,
84507 + [2344].file = "fs/ecryptfs/crypto.c",
84508 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
84509 + [2344].param5 = 1,
84510 + [2515].file = "fs/ecryptfs/crypto.c",
84511 + [2515].name = "ecryptfs_copy_filename",
84512 + [2515].param4 = 1,
84513 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84514 + [26518].name = "vga_arb_read",
84515 + [26518].param3 = 1,
84516 + [30632].file = "drivers/ide/ide-proc.c",
84517 + [30632].name = "ide_driver_proc_write",
84518 + [30632].param3 = 1,
84519 + [39024].file = "lib/scatterlist.c",
84520 + [39024].name = "sg_kmalloc",
84521 + [39024].param1 = 1,
84522 + [50359].file = "kernel/sched/core.c",
84523 + [50359].name = "alloc_sched_domains",
84524 + [50359].param1 = 1,
84525 + [53262].file = "drivers/block/aoe/aoechr.c",
84526 + [53262].name = "revalidate",
84527 + [53262].param2 = 1,
84528 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
84529 + [56432].name = "regmap_map_read_file",
84530 + [56432].param3 = 1,
84531 + [57500].file = "drivers/spi/spidev.c",
84532 + [57500].name = "spidev_write",
84533 + [57500].param3 = 1,
84534 + [8155].file = "drivers/hv/channel.c",
84535 + [8155].name = "vmbus_establish_gpadl",
84536 + [8155].param3 = 1,
84537 +};
84538 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84539 new file mode 100644
84540 index 0000000..255439f
84541 --- /dev/null
84542 +++ b/tools/gcc/size_overflow_plugin.c
84543 @@ -0,0 +1,1110 @@
84544 +/*
84545 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84546 + * Licensed under the GPL v2, or (at your option) v3
84547 + *
84548 + * Homepage:
84549 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84550 + *
84551 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84552 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84553 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
84554 + *
84555 + * Usage:
84556 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
84557 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84558 + */
84559 +
84560 +#include "gcc-plugin.h"
84561 +#include "config.h"
84562 +#include "system.h"
84563 +#include "coretypes.h"
84564 +#include "tree.h"
84565 +#include "tree-pass.h"
84566 +#include "intl.h"
84567 +#include "plugin-version.h"
84568 +#include "tm.h"
84569 +#include "toplev.h"
84570 +#include "function.h"
84571 +#include "tree-flow.h"
84572 +#include "plugin.h"
84573 +#include "gimple.h"
84574 +#include "c-common.h"
84575 +#include "diagnostic.h"
84576 +#include "cfgloop.h"
84577 +
84578 +struct size_overflow_hash {
84579 + const char *name;
84580 + const char *file;
84581 + unsigned short collision:1;
84582 + unsigned short param1:1;
84583 + unsigned short param2:1;
84584 + unsigned short param3:1;
84585 + unsigned short param4:1;
84586 + unsigned short param5:1;
84587 + unsigned short param6:1;
84588 + unsigned short param7:1;
84589 + unsigned short param8:1;
84590 + unsigned short param9:1;
84591 +};
84592 +
84593 +#include "size_overflow_hash1.h"
84594 +#include "size_overflow_hash2.h"
84595 +
84596 +#define __unused __attribute__((__unused__))
84597 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
84598 +#define BEFORE_STMT true
84599 +#define AFTER_STMT false
84600 +#define CREATE_NEW_VAR NULL_TREE
84601 +
84602 +int plugin_is_GPL_compatible;
84603 +void debug_gimple_stmt (gimple gs);
84604 +
84605 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
84606 +static tree signed_size_overflow_type;
84607 +static tree unsigned_size_overflow_type;
84608 +static tree report_size_overflow_decl;
84609 +static tree const_char_ptr_type_node;
84610 +static unsigned int handle_function(void);
84611 +
84612 +static struct plugin_info size_overflow_plugin_info = {
84613 + .version = "20120409beta",
84614 + .help = "no-size_overflow\tturn off size overflow checking\n",
84615 +};
84616 +
84617 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
84618 +{
84619 + unsigned int arg_count = type_num_arguments(*node);
84620 +
84621 + for (; args; args = TREE_CHAIN(args)) {
84622 + tree position = TREE_VALUE(args);
84623 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
84624 + error("handle_size_overflow_attribute: overflow parameter outside range.");
84625 + *no_add_attrs = true;
84626 + }
84627 + }
84628 + return NULL_TREE;
84629 +}
84630 +
84631 +static struct attribute_spec no_size_overflow_attr = {
84632 + .name = "size_overflow",
84633 + .min_length = 1,
84634 + .max_length = -1,
84635 + .decl_required = false,
84636 + .type_required = true,
84637 + .function_type_required = true,
84638 + .handler = handle_size_overflow_attribute
84639 +};
84640 +
84641 +static void register_attributes(void __unused *event_data, void __unused *data)
84642 +{
84643 + register_attribute(&no_size_overflow_attr);
84644 +}
84645 +
84646 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
84647 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
84648 +{
84649 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
84650 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
84651 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
84652 +
84653 + const unsigned int m = 0x57559429;
84654 + const unsigned int n = 0x5052acdb;
84655 + const unsigned int *key4 = (const unsigned int *)key;
84656 + unsigned int h = len;
84657 + unsigned int k = len + seed + n;
84658 + unsigned long long p;
84659 +
84660 + while (len >= 8) {
84661 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
84662 + len -= 8;
84663 + }
84664 + if (len >= 4) {
84665 + cwmixb(key4[0]) key4 += 1;
84666 + len -= 4;
84667 + }
84668 + if (len)
84669 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
84670 + cwmixb(h ^ (k + n));
84671 + return k ^ h;
84672 +
84673 +#undef cwfold
84674 +#undef cwmixa
84675 +#undef cwmixb
84676 +}
84677 +
84678 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
84679 +{
84680 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
84681 +}
84682 +
84683 +static inline tree get_original_function_decl(tree fndecl)
84684 +{
84685 + if (DECL_ABSTRACT_ORIGIN(fndecl))
84686 + return DECL_ABSTRACT_ORIGIN(fndecl);
84687 + return fndecl;
84688 +}
84689 +
84690 +static inline gimple get_def_stmt(tree node)
84691 +{
84692 + gcc_assert(TREE_CODE(node) == SSA_NAME);
84693 + return SSA_NAME_DEF_STMT(node);
84694 +}
84695 +
84696 +static struct size_overflow_hash *get_function_hash(tree fndecl)
84697 +{
84698 + unsigned int hash;
84699 + const char *func = NAME(fndecl);
84700 +
84701 + hash = size_overflow_hash(func, 0);
84702 +
84703 + if (size_overflow_hash1[hash].collision) {
84704 + hash = size_overflow_hash(func, 23432);
84705 + return &size_overflow_hash2[hash];
84706 + }
84707 + return &size_overflow_hash1[hash];
84708 +}
84709 +
84710 +static void check_arg_type(tree var)
84711 +{
84712 + tree type = TREE_TYPE(var);
84713 + enum tree_code code = TREE_CODE(type);
84714 +
84715 + gcc_assert(code == INTEGER_TYPE ||
84716 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
84717 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
84718 +}
84719 +
84720 +static void check_missing_attribute(tree arg)
84721 +{
84722 + tree var, type, func = get_original_function_decl(current_function_decl);
84723 + const char *curfunc = NAME(func);
84724 + unsigned int new_hash, argnum = 1;
84725 + struct size_overflow_hash *hash;
84726 + location_t loc;
84727 + expanded_location xloc;
84728 + bool match = false;
84729 +
84730 + type = TREE_TYPE(arg);
84731 + // skip function pointers
84732 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
84733 + return;
84734 +
84735 + loc = DECL_SOURCE_LOCATION(func);
84736 + xloc = expand_location(loc);
84737 +
84738 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
84739 + return;
84740 +
84741 + hash = get_function_hash(func);
84742 + if (hash->name && !strcmp(hash->name, NAME(func)) && !strcmp(hash->file, xloc.file))
84743 + return;
84744 +
84745 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
84746 +
84747 + if (TREE_CODE(arg) == SSA_NAME)
84748 + arg = SSA_NAME_VAR(arg);
84749 +
84750 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
84751 + if (strcmp(NAME(arg), NAME(var))) {
84752 + argnum++;
84753 + continue;
84754 + }
84755 + check_arg_type(var);
84756 +
84757 + match = true;
84758 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
84759 + return;
84760 + break;
84761 + }
84762 + if (!match) {
84763 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
84764 + return;
84765 + }
84766 +
84767 +#define check_param(num) \
84768 + if (num == argnum && hash->param##num) \
84769 + return;
84770 + check_param(1);
84771 + check_param(2);
84772 + check_param(3);
84773 + check_param(4);
84774 + check_param(5);
84775 + check_param(6);
84776 + check_param(7);
84777 + check_param(8);
84778 + check_param(9);
84779 +#undef check_param
84780 +
84781 + new_hash = size_overflow_hash(curfunc, 0);
84782 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
84783 +}
84784 +
84785 +static tree create_new_var(tree type)
84786 +{
84787 + tree new_var = create_tmp_var(type, "cicus");
84788 +
84789 + add_referenced_var(new_var);
84790 + mark_sym_for_renaming(new_var);
84791 + return new_var;
84792 +}
84793 +
84794 +static bool is_bool(tree node)
84795 +{
84796 + tree type;
84797 +
84798 + if (node == NULL_TREE)
84799 + return false;
84800 +
84801 + type = TREE_TYPE(node);
84802 + if (!INTEGRAL_TYPE_P(type))
84803 + return false;
84804 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84805 + return true;
84806 + if (TYPE_PRECISION(type) == 1)
84807 + return true;
84808 + return false;
84809 +}
84810 +
84811 +static tree cast_a_tree(tree type, tree var)
84812 +{
84813 + gcc_assert(fold_convertible_p(type, var));
84814 +
84815 + return fold_convert(type, var);
84816 +}
84817 +
84818 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84819 +{
84820 + gimple assign;
84821 +
84822 + if (new_var == CREATE_NEW_VAR)
84823 + new_var = create_new_var(type);
84824 +
84825 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
84826 + gimple_set_location(assign, loc);
84827 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84828 +
84829 + return assign;
84830 +}
84831 +
84832 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
84833 +{
84834 + tree oldstmt_rhs1;
84835 + enum tree_code code;
84836 + gimple stmt;
84837 + gimple_stmt_iterator gsi;
84838 +
84839 + if (!*potentionally_overflowed)
84840 + return NULL_TREE;
84841 +
84842 + if (rhs1 == NULL_TREE) {
84843 + debug_gimple_stmt(oldstmt);
84844 + error("create_assign: rhs1 is NULL_TREE");
84845 + gcc_unreachable();
84846 + }
84847 +
84848 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
84849 + code = TREE_CODE(oldstmt_rhs1);
84850 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
84851 + check_missing_attribute(oldstmt_rhs1);
84852 +
84853 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
84854 + gsi = gsi_for_stmt(oldstmt);
84855 + if (before)
84856 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
84857 + else
84858 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
84859 + update_stmt(stmt);
84860 + pointer_set_insert(visited, oldstmt);
84861 + return gimple_get_lhs(stmt);
84862 +}
84863 +
84864 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
84865 +{
84866 + tree new_var, lhs = gimple_get_lhs(oldstmt);
84867 + gimple stmt;
84868 + gimple_stmt_iterator gsi;
84869 +
84870 + if (!*potentionally_overflowed)
84871 + return NULL_TREE;
84872 +
84873 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
84874 + rhs1 = gimple_assign_rhs1(oldstmt);
84875 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
84876 + }
84877 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
84878 + rhs2 = gimple_assign_rhs2(oldstmt);
84879 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
84880 + }
84881 +
84882 + stmt = gimple_copy(oldstmt);
84883 + gimple_set_location(stmt, gimple_location(oldstmt));
84884 +
84885 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
84886 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
84887 +
84888 + if (is_bool(lhs))
84889 + new_var = SSA_NAME_VAR(lhs);
84890 + else
84891 + new_var = create_new_var(signed_size_overflow_type);
84892 + new_var = make_ssa_name(new_var, stmt);
84893 + gimple_set_lhs(stmt, new_var);
84894 +
84895 + if (rhs1 != NULL_TREE) {
84896 + if (!gimple_assign_cast_p(oldstmt))
84897 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
84898 + gimple_assign_set_rhs1(stmt, rhs1);
84899 + }
84900 +
84901 + if (rhs2 != NULL_TREE)
84902 + gimple_assign_set_rhs2(stmt, rhs2);
84903 +#if BUILDING_GCC_VERSION >= 4007
84904 + if (rhs3 != NULL_TREE)
84905 + gimple_assign_set_rhs3(stmt, rhs3);
84906 +#endif
84907 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
84908 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
84909 +
84910 + gsi = gsi_for_stmt(oldstmt);
84911 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
84912 + update_stmt(stmt);
84913 + pointer_set_insert(visited, oldstmt);
84914 + return gimple_get_lhs(stmt);
84915 +}
84916 +
84917 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
84918 +{
84919 + basic_block bb;
84920 + gimple phi;
84921 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
84922 +
84923 + bb = gsi_bb(gsi);
84924 +
84925 + phi = create_phi_node(var, bb);
84926 + gsi = gsi_last(phi_nodes(bb));
84927 + gsi_remove(&gsi, false);
84928 +
84929 + gsi = gsi_for_stmt(oldstmt);
84930 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
84931 + gimple_set_bb(phi, bb);
84932 + return phi;
84933 +}
84934 +
84935 +static tree signed_cast_constant(tree node)
84936 +{
84937 + gcc_assert(is_gimple_constant(node));
84938 +
84939 + return cast_a_tree(signed_size_overflow_type, node);
84940 +}
84941 +
84942 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
84943 +{
84944 + basic_block bb;
84945 + gimple newstmt, def_stmt;
84946 + gimple_stmt_iterator gsi;
84947 +
84948 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
84949 + if (TREE_CODE(arg) == SSA_NAME) {
84950 + def_stmt = get_def_stmt(arg);
84951 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
84952 + gsi = gsi_for_stmt(def_stmt);
84953 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
84954 + return newstmt;
84955 + }
84956 + }
84957 +
84958 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
84959 + gsi = gsi_after_labels(bb);
84960 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
84961 + return newstmt;
84962 +}
84963 +
84964 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
84965 +{
84966 + gimple newstmt;
84967 + gimple_stmt_iterator gsi;
84968 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
84969 + gimple def_newstmt = get_def_stmt(new_rhs);
84970 +
84971 + gsi_insert = gsi_insert_after;
84972 + gsi = gsi_for_stmt(def_newstmt);
84973 +
84974 + switch (gimple_code(get_def_stmt(arg))) {
84975 + case GIMPLE_PHI:
84976 + newstmt = gimple_build_assign(new_var, new_rhs);
84977 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
84978 + gsi_insert = gsi_insert_before;
84979 + break;
84980 + case GIMPLE_ASM:
84981 + case GIMPLE_CALL:
84982 + newstmt = gimple_build_assign(new_var, new_rhs);
84983 + break;
84984 + case GIMPLE_ASSIGN:
84985 + newstmt = gimple_copy(def_newstmt);
84986 + break;
84987 + default:
84988 + /* unknown gimple_code (handle_build_new_phi_arg) */
84989 + gcc_unreachable();
84990 + }
84991 +
84992 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
84993 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
84994 + return newstmt;
84995 +}
84996 +
84997 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
84998 +{
84999 + gimple newstmt;
85000 + tree new_rhs;
85001 +
85002 + new_rhs = expand(visited, potentionally_overflowed, arg);
85003 +
85004 + if (new_rhs == NULL_TREE)
85005 + return NULL_TREE;
85006 +
85007 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85008 + update_stmt(newstmt);
85009 + return gimple_get_lhs(newstmt);
85010 +}
85011 +
85012 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
85013 +{
85014 + gimple phi;
85015 + tree new_var = create_new_var(signed_size_overflow_type);
85016 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85017 +
85018 + pointer_set_insert(visited, oldstmt);
85019 + phi = overflow_create_phi_node(oldstmt, new_var);
85020 + for (i = 0; i < n; i++) {
85021 + tree arg, lhs;
85022 +
85023 + arg = gimple_phi_arg_def(oldstmt, i);
85024 + if (is_gimple_constant(arg))
85025 + arg = signed_cast_constant(arg);
85026 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85027 + if (lhs == NULL_TREE)
85028 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85029 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85030 + }
85031 +
85032 + update_stmt(phi);
85033 + return gimple_phi_result(phi);
85034 +}
85035 +
85036 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85037 +{
85038 + gimple def_stmt = get_def_stmt(var);
85039 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85040 +
85041 + *potentionally_overflowed = true;
85042 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85043 + if (new_rhs1 == NULL_TREE) {
85044 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85045 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85046 + else
85047 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85048 + }
85049 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85050 +}
85051 +
85052 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85053 +{
85054 + gimple def_stmt = get_def_stmt(var);
85055 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85056 +
85057 + if (is_gimple_constant(rhs1))
85058 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85059 +
85060 + switch (TREE_CODE(rhs1)) {
85061 + case SSA_NAME:
85062 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85063 +
85064 + case ARRAY_REF:
85065 + case ADDR_EXPR:
85066 + case COMPONENT_REF:
85067 + case COND_EXPR:
85068 + case INDIRECT_REF:
85069 +#if BUILDING_GCC_VERSION >= 4006
85070 + case MEM_REF:
85071 +#endif
85072 + case PARM_DECL:
85073 + case TARGET_MEM_REF:
85074 + case VAR_DECL:
85075 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85076 +
85077 + default:
85078 + debug_gimple_stmt(def_stmt);
85079 + debug_tree(rhs1);
85080 + gcc_unreachable();
85081 + }
85082 +}
85083 +
85084 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85085 +{
85086 + gimple cond_stmt;
85087 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85088 +
85089 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85090 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85091 + update_stmt(cond_stmt);
85092 +}
85093 +
85094 +static tree create_string_param(tree string)
85095 +{
85096 + tree array_ref = build4(ARRAY_REF, TREE_TYPE(string), string, integer_zero_node, NULL, NULL);
85097 +
85098 + return build1(ADDR_EXPR, ptr_type_node, array_ref);
85099 +}
85100 +
85101 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85102 +{
85103 + gimple func_stmt, def_stmt;
85104 + tree current_func, loc_file, loc_line;
85105 + expanded_location xloc;
85106 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85107 +
85108 + def_stmt = get_def_stmt(arg);
85109 + xloc = expand_location(gimple_location(def_stmt));
85110 +
85111 + if (!gimple_has_location(def_stmt)) {
85112 + xloc = expand_location(gimple_location(stmt));
85113 + if (!gimple_has_location(stmt))
85114 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85115 + }
85116 +
85117 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85118 +
85119 + loc_file = build_string(strlen(xloc.file), xloc.file);
85120 + TREE_TYPE(loc_file) = char_array_type_node;
85121 + loc_file = create_string_param(loc_file);
85122 +
85123 + current_func = build_string(IDENTIFIER_LENGTH(DECL_NAME(current_function_decl)), NAME(current_function_decl));
85124 + TREE_TYPE(current_func) = char_array_type_node;
85125 + current_func = create_string_param(current_func);
85126 +
85127 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85128 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85129 +
85130 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85131 +}
85132 +
85133 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85134 +{
85135 + basic_block cond_bb, join_bb, bb_true;
85136 + edge e;
85137 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85138 +// location_t loc = gimple_location(stmt);
85139 +
85140 + cond_bb = gimple_bb(stmt);
85141 + gsi_prev(&gsi);
85142 + if (gsi_end_p(gsi))
85143 + e = split_block_after_labels(cond_bb);
85144 + else
85145 + e = split_block(cond_bb, gsi_stmt(gsi));
85146 + cond_bb = e->src;
85147 + join_bb = e->dest;
85148 + e->flags = EDGE_FALSE_VALUE;
85149 + e->probability = REG_BR_PROB_BASE;
85150 +
85151 + bb_true = create_empty_bb(cond_bb);
85152 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85153 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85154 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85155 +
85156 + if (dom_info_available_p(CDI_DOMINATORS)) {
85157 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85158 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85159 + }
85160 +
85161 + if (current_loops != NULL) {
85162 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85163 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85164 + }
85165 +
85166 + insert_cond(cond_bb, arg, cond_code, type_value);
85167 + insert_cond_result(bb_true, stmt, arg);
85168 +
85169 +// inform(loc, "Integer size_overflow check applied here.");
85170 +}
85171 +
85172 +static tree get_type_for_check(tree rhs)
85173 +{
85174 + tree def_rhs;
85175 + gimple def_stmt = get_def_stmt(rhs);
85176 +
85177 + if (!gimple_assign_cast_p(def_stmt))
85178 + return TREE_TYPE(rhs);
85179 + def_rhs = gimple_assign_rhs1(def_stmt);
85180 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
85181 + return TREE_TYPE(def_rhs);
85182 + return TREE_TYPE(rhs);
85183 +}
85184 +
85185 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85186 +{
85187 + gimple ucast_stmt;
85188 + gimple_stmt_iterator gsi;
85189 + location_t loc = gimple_location(stmt);
85190 +
85191 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85192 + gsi = gsi_for_stmt(stmt);
85193 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85194 + return ucast_stmt;
85195 +}
85196 +
85197 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85198 +{
85199 + tree type_max, type_min, rhs_type;
85200 + gimple ucast_stmt;
85201 +
85202 + if (!*potentionally_overflowed)
85203 + return;
85204 +
85205 + rhs_type = get_type_for_check(rhs);
85206 +
85207 + if (TYPE_UNSIGNED(rhs_type)) {
85208 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85209 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85210 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85211 + } else {
85212 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85213 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85214 +
85215 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
85216 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85217 + }
85218 +}
85219 +
85220 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
85221 +{
85222 + gimple assign;
85223 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85224 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
85225 +
85226 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85227 +
85228 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
85229 + if (new_rhs == NULL_TREE)
85230 + return NULL_TREE;
85231 +
85232 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85233 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85234 + update_stmt(assign);
85235 + return gimple_get_lhs(assign);
85236 +}
85237 +
85238 +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))
85239 +{
85240 + tree new_rhs, cast_rhs;
85241 +
85242 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85243 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85244 +
85245 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
85246 + if (new_rhs != NULL_TREE) {
85247 + gimple_assign_set_rhs(def_stmt, new_rhs);
85248 + update_stmt(def_stmt);
85249 +
85250 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
85251 +
85252 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
85253 + }
85254 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85255 +}
85256 +
85257 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85258 +{
85259 + tree rhs1, rhs2;
85260 + gimple def_stmt = get_def_stmt(var);
85261 + tree new_rhs1 = NULL_TREE;
85262 + tree new_rhs2 = NULL_TREE;
85263 +
85264 + rhs1 = gimple_assign_rhs1(def_stmt);
85265 + rhs2 = gimple_assign_rhs2(def_stmt);
85266 +
85267 + /* no DImode/TImode division in the 32/64 bit kernel */
85268 + switch (gimple_assign_rhs_code(def_stmt)) {
85269 + case RDIV_EXPR:
85270 + case TRUNC_DIV_EXPR:
85271 + case CEIL_DIV_EXPR:
85272 + case FLOOR_DIV_EXPR:
85273 + case ROUND_DIV_EXPR:
85274 + case TRUNC_MOD_EXPR:
85275 + case CEIL_MOD_EXPR:
85276 + case FLOOR_MOD_EXPR:
85277 + case ROUND_MOD_EXPR:
85278 + case EXACT_DIV_EXPR:
85279 + case POINTER_PLUS_EXPR:
85280 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85281 + default:
85282 + break;
85283 + }
85284 +
85285 + *potentionally_overflowed = true;
85286 +
85287 + if (TREE_CODE(rhs1) == SSA_NAME)
85288 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85289 + if (TREE_CODE(rhs2) == SSA_NAME)
85290 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85291 +
85292 + if (is_gimple_constant(rhs2))
85293 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
85294 +
85295 + if (is_gimple_constant(rhs1))
85296 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85297 +
85298 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85299 +}
85300 +
85301 +#if BUILDING_GCC_VERSION >= 4007
85302 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85303 +{
85304 + if (is_gimple_constant(rhs))
85305 + return signed_cast_constant(rhs);
85306 + if (TREE_CODE(rhs) != SSA_NAME)
85307 + return NULL_TREE;
85308 + return expand(visited, potentionally_overflowed, rhs);
85309 +}
85310 +
85311 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85312 +{
85313 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85314 + gimple def_stmt = get_def_stmt(var);
85315 +
85316 + *potentionally_overflowed = true;
85317 +
85318 + rhs1 = gimple_assign_rhs1(def_stmt);
85319 + rhs2 = gimple_assign_rhs2(def_stmt);
85320 + rhs3 = gimple_assign_rhs3(def_stmt);
85321 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85322 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85323 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85324 +
85325 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85326 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85327 + error("handle_ternary_ops: unknown rhs");
85328 + gcc_unreachable();
85329 +}
85330 +#endif
85331 +
85332 +static void set_size_overflow_type(tree node)
85333 +{
85334 + switch (TYPE_MODE(TREE_TYPE(node))) {
85335 + case SImode:
85336 + signed_size_overflow_type = intDI_type_node;
85337 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85338 + break;
85339 + case DImode:
85340 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85341 + signed_size_overflow_type = intDI_type_node;
85342 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85343 + } else {
85344 + signed_size_overflow_type = intTI_type_node;
85345 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85346 + }
85347 + break;
85348 + default:
85349 + error("set_size_overflow_type: unsupported gcc configuration.");
85350 + gcc_unreachable();
85351 + }
85352 +}
85353 +
85354 +static tree expand_visited(gimple def_stmt)
85355 +{
85356 + gimple tmp;
85357 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85358 +
85359 + gsi_next(&gsi);
85360 + tmp = gsi_stmt(gsi);
85361 + switch (gimple_code(tmp)) {
85362 + case GIMPLE_ASSIGN:
85363 + return gimple_get_lhs(tmp);
85364 + case GIMPLE_PHI:
85365 + return gimple_phi_result(tmp);
85366 + case GIMPLE_CALL:
85367 + return gimple_call_lhs(tmp);
85368 + default:
85369 + return NULL_TREE;
85370 + }
85371 +}
85372 +
85373 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85374 +{
85375 + gimple def_stmt;
85376 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85377 +
85378 + if (is_gimple_constant(var))
85379 + return NULL_TREE;
85380 +
85381 + if (TREE_CODE(var) == ADDR_EXPR)
85382 + return NULL_TREE;
85383 +
85384 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
85385 + if (code != INTEGER_TYPE)
85386 + return NULL_TREE;
85387 +
85388 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85389 + check_missing_attribute(var);
85390 + return NULL_TREE;
85391 + }
85392 +
85393 + def_stmt = get_def_stmt(var);
85394 +
85395 + if (!def_stmt)
85396 + return NULL_TREE;
85397 +
85398 + if (pointer_set_contains(visited, def_stmt))
85399 + return expand_visited(def_stmt);
85400 +
85401 + switch (gimple_code(def_stmt)) {
85402 + case GIMPLE_NOP:
85403 + check_missing_attribute(var);
85404 + return NULL_TREE;
85405 + case GIMPLE_PHI:
85406 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85407 + case GIMPLE_CALL:
85408 + case GIMPLE_ASM:
85409 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85410 + case GIMPLE_ASSIGN:
85411 + switch (gimple_num_ops(def_stmt)) {
85412 + case 2:
85413 + return handle_unary_ops(visited, potentionally_overflowed, var);
85414 + case 3:
85415 + return handle_binary_ops(visited, potentionally_overflowed, var);
85416 +#if BUILDING_GCC_VERSION >= 4007
85417 + case 4:
85418 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85419 +#endif
85420 + }
85421 + default:
85422 + debug_gimple_stmt(def_stmt);
85423 + error("expand: unknown gimple code");
85424 + gcc_unreachable();
85425 + }
85426 +}
85427 +
85428 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85429 +{
85430 + gimple assign;
85431 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85432 + tree origtype = TREE_TYPE(origarg);
85433 +
85434 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85435 +
85436 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85437 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85438 + update_stmt(assign);
85439 +
85440 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85441 + update_stmt(stmt);
85442 +}
85443 +
85444 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85445 +{
85446 + const char *origid;
85447 + tree arg, origarg;
85448 +
85449 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85450 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85451 + return gimple_call_arg(stmt, argnum);
85452 + }
85453 +
85454 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85455 + while (origarg && argnum) {
85456 + argnum--;
85457 + origarg = TREE_CHAIN(origarg);
85458 + }
85459 +
85460 + gcc_assert(argnum == 0);
85461 +
85462 + gcc_assert(origarg != NULL_TREE);
85463 + origid = NAME(origarg);
85464 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85465 + if (!strcmp(origid, NAME(arg)))
85466 + return arg;
85467 + }
85468 + return NULL_TREE;
85469 +}
85470 +
85471 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85472 +{
85473 + struct pointer_set_t *visited;
85474 + tree arg, newarg, type_max;
85475 + gimple ucast_stmt;
85476 + bool potentionally_overflowed;
85477 +
85478 + arg = get_function_arg(argnum, stmt, fndecl);
85479 + if (arg == NULL_TREE)
85480 + return;
85481 +
85482 + if (is_gimple_constant(arg))
85483 + return;
85484 + if (TREE_CODE(arg) != SSA_NAME)
85485 + return;
85486 +
85487 + check_arg_type(arg);
85488 +
85489 + set_size_overflow_type(arg);
85490 +
85491 + visited = pointer_set_create();
85492 + potentionally_overflowed = false;
85493 + newarg = expand(visited, &potentionally_overflowed, arg);
85494 + pointer_set_destroy(visited);
85495 +
85496 + if (newarg == NULL_TREE || !potentionally_overflowed)
85497 + return;
85498 +
85499 + change_function_arg(stmt, arg, argnum, newarg);
85500 +
85501 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
85502 +
85503 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
85504 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85505 +}
85506 +
85507 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85508 +{
85509 + tree p = TREE_VALUE(attr);
85510 + do {
85511 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85512 + p = TREE_CHAIN(p);
85513 + } while (p);
85514 +}
85515 +
85516 +static void handle_function_by_hash(gimple stmt, tree fndecl)
85517 +{
85518 + struct size_overflow_hash *hash;
85519 + expanded_location xloc;
85520 +
85521 + hash = get_function_hash(fndecl);
85522 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
85523 +
85524 + fndecl = get_original_function_decl(fndecl);
85525 + if (!hash->name || !hash->file)
85526 + return;
85527 + if (strcmp(hash->name, NAME(fndecl)) || strcmp(hash->file, xloc.file))
85528 + return;
85529 +
85530 +#define search_param(argnum) \
85531 + if (hash->param##argnum) \
85532 + handle_function_arg(stmt, fndecl, argnum - 1);
85533 +
85534 + search_param(1);
85535 + search_param(2);
85536 + search_param(3);
85537 + search_param(4);
85538 + search_param(5);
85539 + search_param(6);
85540 + search_param(7);
85541 + search_param(8);
85542 + search_param(9);
85543 +#undef search_param
85544 +}
85545 +
85546 +static unsigned int handle_function(void)
85547 +{
85548 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
85549 + int saved_last_basic_block = last_basic_block;
85550 +
85551 + do {
85552 + gimple_stmt_iterator gsi;
85553 + basic_block next = bb->next_bb;
85554 +
85555 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85556 + tree fndecl, attr;
85557 + gimple stmt = gsi_stmt(gsi);
85558 +
85559 + if (!(is_gimple_call(stmt)))
85560 + continue;
85561 + fndecl = gimple_call_fndecl(stmt);
85562 + if (fndecl == NULL_TREE)
85563 + continue;
85564 + if (gimple_call_num_args(stmt) == 0)
85565 + continue;
85566 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
85567 + if (!attr || !TREE_VALUE(attr))
85568 + handle_function_by_hash(stmt, fndecl);
85569 + else
85570 + handle_function_by_attribute(stmt, attr, fndecl);
85571 + gsi = gsi_for_stmt(stmt);
85572 + }
85573 + bb = next;
85574 + } while (bb && bb->index <= saved_last_basic_block);
85575 + return 0;
85576 +}
85577 +
85578 +static struct gimple_opt_pass size_overflow_pass = {
85579 + .pass = {
85580 + .type = GIMPLE_PASS,
85581 + .name = "size_overflow",
85582 + .gate = NULL,
85583 + .execute = handle_function,
85584 + .sub = NULL,
85585 + .next = NULL,
85586 + .static_pass_number = 0,
85587 + .tv_id = TV_NONE,
85588 + .properties_required = PROP_cfg | PROP_referenced_vars,
85589 + .properties_provided = 0,
85590 + .properties_destroyed = 0,
85591 + .todo_flags_start = 0,
85592 + .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
85593 + }
85594 +};
85595 +
85596 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
85597 +{
85598 + tree fntype;
85599 +
85600 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
85601 +
85602 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
85603 + fntype = build_function_type_list(void_type_node,
85604 + const_char_ptr_type_node,
85605 + unsigned_type_node,
85606 + const_char_ptr_type_node,
85607 + NULL_TREE);
85608 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
85609 +
85610 + TREE_PUBLIC(report_size_overflow_decl) = 1;
85611 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
85612 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
85613 +}
85614 +
85615 +extern struct gimple_opt_pass pass_dce;
85616 +
85617 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85618 +{
85619 + int i;
85620 + const char * const plugin_name = plugin_info->base_name;
85621 + const int argc = plugin_info->argc;
85622 + const struct plugin_argument * const argv = plugin_info->argv;
85623 + bool enable = true;
85624 +
85625 + struct register_pass_info size_overflow_pass_info = {
85626 + .pass = &size_overflow_pass.pass,
85627 + .reference_pass_name = "ssa",
85628 + .ref_pass_instance_number = 1,
85629 + .pos_op = PASS_POS_INSERT_AFTER
85630 + };
85631 +
85632 + if (!plugin_default_version_check(version, &gcc_version)) {
85633 + error(G_("incompatible gcc/plugin versions"));
85634 + return 1;
85635 + }
85636 +
85637 + for (i = 0; i < argc; ++i) {
85638 + if (!(strcmp(argv[i].key, "no-size_overflow"))) {
85639 + enable = false;
85640 + continue;
85641 + }
85642 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85643 + }
85644 +
85645 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
85646 + if (enable) {
85647 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85648 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
85649 + }
85650 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85651 +
85652 + return 0;
85653 +}
85654 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
85655 new file mode 100644
85656 index 0000000..b87ec9d
85657 --- /dev/null
85658 +++ b/tools/gcc/stackleak_plugin.c
85659 @@ -0,0 +1,313 @@
85660 +/*
85661 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85662 + * Licensed under the GPL v2
85663 + *
85664 + * Note: the choice of the license means that the compilation process is
85665 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85666 + * but for the kernel it doesn't matter since it doesn't link against
85667 + * any of the gcc libraries
85668 + *
85669 + * gcc plugin to help implement various PaX features
85670 + *
85671 + * - track lowest stack pointer
85672 + *
85673 + * TODO:
85674 + * - initialize all local variables
85675 + *
85676 + * BUGS:
85677 + * - none known
85678 + */
85679 +#include "gcc-plugin.h"
85680 +#include "config.h"
85681 +#include "system.h"
85682 +#include "coretypes.h"
85683 +#include "tree.h"
85684 +#include "tree-pass.h"
85685 +#include "flags.h"
85686 +#include "intl.h"
85687 +#include "toplev.h"
85688 +#include "plugin.h"
85689 +//#include "expr.h" where are you...
85690 +#include "diagnostic.h"
85691 +#include "plugin-version.h"
85692 +#include "tm.h"
85693 +#include "function.h"
85694 +#include "basic-block.h"
85695 +#include "gimple.h"
85696 +#include "rtl.h"
85697 +#include "emit-rtl.h"
85698 +
85699 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85700 +
85701 +int plugin_is_GPL_compatible;
85702 +
85703 +static int track_frame_size = -1;
85704 +static const char track_function[] = "pax_track_stack";
85705 +static const char check_function[] = "pax_check_alloca";
85706 +static bool init_locals;
85707 +
85708 +static struct plugin_info stackleak_plugin_info = {
85709 + .version = "201203140940",
85710 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
85711 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
85712 +};
85713 +
85714 +static bool gate_stackleak_track_stack(void);
85715 +static unsigned int execute_stackleak_tree_instrument(void);
85716 +static unsigned int execute_stackleak_final(void);
85717 +
85718 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
85719 + .pass = {
85720 + .type = GIMPLE_PASS,
85721 + .name = "stackleak_tree_instrument",
85722 + .gate = gate_stackleak_track_stack,
85723 + .execute = execute_stackleak_tree_instrument,
85724 + .sub = NULL,
85725 + .next = NULL,
85726 + .static_pass_number = 0,
85727 + .tv_id = TV_NONE,
85728 + .properties_required = PROP_gimple_leh | PROP_cfg,
85729 + .properties_provided = 0,
85730 + .properties_destroyed = 0,
85731 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85732 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85733 + }
85734 +};
85735 +
85736 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
85737 + .pass = {
85738 + .type = RTL_PASS,
85739 + .name = "stackleak_final",
85740 + .gate = gate_stackleak_track_stack,
85741 + .execute = execute_stackleak_final,
85742 + .sub = NULL,
85743 + .next = NULL,
85744 + .static_pass_number = 0,
85745 + .tv_id = TV_NONE,
85746 + .properties_required = 0,
85747 + .properties_provided = 0,
85748 + .properties_destroyed = 0,
85749 + .todo_flags_start = 0,
85750 + .todo_flags_finish = TODO_dump_func
85751 + }
85752 +};
85753 +
85754 +static bool gate_stackleak_track_stack(void)
85755 +{
85756 + return track_frame_size >= 0;
85757 +}
85758 +
85759 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
85760 +{
85761 + gimple check_alloca;
85762 + tree fntype, fndecl, alloca_size;
85763 +
85764 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
85765 + fndecl = build_fn_decl(check_function, fntype);
85766 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85767 +
85768 + // insert call to void pax_check_alloca(unsigned long size)
85769 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
85770 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
85771 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
85772 +}
85773 +
85774 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
85775 +{
85776 + gimple track_stack;
85777 + tree fntype, fndecl;
85778 +
85779 + fntype = build_function_type_list(void_type_node, NULL_TREE);
85780 + fndecl = build_fn_decl(track_function, fntype);
85781 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85782 +
85783 + // insert call to void pax_track_stack(void)
85784 + track_stack = gimple_build_call(fndecl, 0);
85785 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
85786 +}
85787 +
85788 +#if BUILDING_GCC_VERSION == 4005
85789 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
85790 +{
85791 + tree fndecl;
85792 +
85793 + if (!is_gimple_call(stmt))
85794 + return false;
85795 + fndecl = gimple_call_fndecl(stmt);
85796 + if (!fndecl)
85797 + return false;
85798 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85799 + return false;
85800 +// print_node(stderr, "pax", fndecl, 4);
85801 + return DECL_FUNCTION_CODE(fndecl) == code;
85802 +}
85803 +#endif
85804 +
85805 +static bool is_alloca(gimple stmt)
85806 +{
85807 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85808 + return true;
85809 +
85810 +#if BUILDING_GCC_VERSION >= 4007
85811 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85812 + return true;
85813 +#endif
85814 +
85815 + return false;
85816 +}
85817 +
85818 +static unsigned int execute_stackleak_tree_instrument(void)
85819 +{
85820 + basic_block bb, entry_bb;
85821 + bool prologue_instrumented = false, is_leaf = true;
85822 +
85823 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85824 +
85825 + // 1. loop through BBs and GIMPLE statements
85826 + FOR_EACH_BB(bb) {
85827 + gimple_stmt_iterator gsi;
85828 +
85829 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85830 + gimple stmt;
85831 +
85832 + stmt = gsi_stmt(gsi);
85833 +
85834 + if (is_gimple_call(stmt))
85835 + is_leaf = false;
85836 +
85837 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85838 + if (!is_alloca(stmt))
85839 + continue;
85840 +
85841 + // 2. insert stack overflow check before each __builtin_alloca call
85842 + stackleak_check_alloca(&gsi);
85843 +
85844 + // 3. insert track call after each __builtin_alloca call
85845 + stackleak_add_instrumentation(&gsi);
85846 + if (bb == entry_bb)
85847 + prologue_instrumented = true;
85848 + }
85849 + }
85850 +
85851 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85852 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85853 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85854 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85855 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85856 + return 0;
85857 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85858 + return 0;
85859 +
85860 + // 4. insert track call at the beginning
85861 + if (!prologue_instrumented) {
85862 + gimple_stmt_iterator gsi;
85863 +
85864 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85865 + if (dom_info_available_p(CDI_DOMINATORS))
85866 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85867 + gsi = gsi_start_bb(bb);
85868 + stackleak_add_instrumentation(&gsi);
85869 + }
85870 +
85871 + return 0;
85872 +}
85873 +
85874 +static unsigned int execute_stackleak_final(void)
85875 +{
85876 + rtx insn;
85877 +
85878 + if (cfun->calls_alloca)
85879 + return 0;
85880 +
85881 + // keep calls only if function frame is big enough
85882 + if (get_frame_size() >= track_frame_size)
85883 + return 0;
85884 +
85885 + // 1. find pax_track_stack calls
85886 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85887 + // 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))
85888 + rtx body;
85889 +
85890 + if (!CALL_P(insn))
85891 + continue;
85892 + body = PATTERN(insn);
85893 + if (GET_CODE(body) != CALL)
85894 + continue;
85895 + body = XEXP(body, 0);
85896 + if (GET_CODE(body) != MEM)
85897 + continue;
85898 + body = XEXP(body, 0);
85899 + if (GET_CODE(body) != SYMBOL_REF)
85900 + continue;
85901 + if (strcmp(XSTR(body, 0), track_function))
85902 + continue;
85903 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85904 + // 2. delete call
85905 + insn = delete_insn_and_edges(insn);
85906 +#if BUILDING_GCC_VERSION >= 4007
85907 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
85908 + insn = delete_insn_and_edges(insn);
85909 +#endif
85910 + }
85911 +
85912 +// print_simple_rtl(stderr, get_insns());
85913 +// print_rtl(stderr, get_insns());
85914 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85915 +
85916 + return 0;
85917 +}
85918 +
85919 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85920 +{
85921 + const char * const plugin_name = plugin_info->base_name;
85922 + const int argc = plugin_info->argc;
85923 + const struct plugin_argument * const argv = plugin_info->argv;
85924 + int i;
85925 + struct register_pass_info stackleak_tree_instrument_pass_info = {
85926 + .pass = &stackleak_tree_instrument_pass.pass,
85927 +// .reference_pass_name = "tree_profile",
85928 + .reference_pass_name = "optimized",
85929 + .ref_pass_instance_number = 0,
85930 + .pos_op = PASS_POS_INSERT_BEFORE
85931 + };
85932 + struct register_pass_info stackleak_final_pass_info = {
85933 + .pass = &stackleak_final_rtl_opt_pass.pass,
85934 + .reference_pass_name = "final",
85935 + .ref_pass_instance_number = 0,
85936 + .pos_op = PASS_POS_INSERT_BEFORE
85937 + };
85938 +
85939 + if (!plugin_default_version_check(version, &gcc_version)) {
85940 + error(G_("incompatible gcc/plugin versions"));
85941 + return 1;
85942 + }
85943 +
85944 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
85945 +
85946 + for (i = 0; i < argc; ++i) {
85947 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85948 + if (!argv[i].value) {
85949 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85950 + continue;
85951 + }
85952 + track_frame_size = atoi(argv[i].value);
85953 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85954 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85955 + continue;
85956 + }
85957 + if (!strcmp(argv[i].key, "initialize-locals")) {
85958 + if (argv[i].value) {
85959 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85960 + continue;
85961 + }
85962 + init_locals = true;
85963 + continue;
85964 + }
85965 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85966 + }
85967 +
85968 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
85969 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
85970 +
85971 + return 0;
85972 +}
85973 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
85974 index 6789d78..4afd019 100644
85975 --- a/tools/perf/util/include/asm/alternative-asm.h
85976 +++ b/tools/perf/util/include/asm/alternative-asm.h
85977 @@ -5,4 +5,7 @@
85978
85979 #define altinstruction_entry #
85980
85981 + .macro pax_force_retaddr rip=0, reload=0
85982 + .endm
85983 +
85984 #endif
85985 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
85986 index af0f22f..9a7d479 100644
85987 --- a/usr/gen_init_cpio.c
85988 +++ b/usr/gen_init_cpio.c
85989 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
85990 int retval;
85991 int rc = -1;
85992 int namesize;
85993 - int i;
85994 + unsigned int i;
85995
85996 mode |= S_IFREG;
85997
85998 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
85999 *env_var = *expanded = '\0';
86000 strncat(env_var, start + 2, end - start - 2);
86001 strncat(expanded, new_location, start - new_location);
86002 - strncat(expanded, getenv(env_var), PATH_MAX);
86003 - strncat(expanded, end + 1, PATH_MAX);
86004 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86005 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86006 strncpy(new_location, expanded, PATH_MAX);
86007 + new_location[PATH_MAX] = 0;
86008 } else
86009 break;
86010 }
86011 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86012 index a91f980..a58d32c 100644
86013 --- a/virt/kvm/kvm_main.c
86014 +++ b/virt/kvm/kvm_main.c
86015 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86016
86017 static cpumask_var_t cpus_hardware_enabled;
86018 static int kvm_usage_count = 0;
86019 -static atomic_t hardware_enable_failed;
86020 +static atomic_unchecked_t hardware_enable_failed;
86021
86022 struct kmem_cache *kvm_vcpu_cache;
86023 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86024 @@ -2312,7 +2312,7 @@ static void hardware_enable_nolock(void *junk)
86025
86026 if (r) {
86027 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86028 - atomic_inc(&hardware_enable_failed);
86029 + atomic_inc_unchecked(&hardware_enable_failed);
86030 printk(KERN_INFO "kvm: enabling virtualization on "
86031 "CPU%d failed\n", cpu);
86032 }
86033 @@ -2366,10 +2366,10 @@ static int hardware_enable_all(void)
86034
86035 kvm_usage_count++;
86036 if (kvm_usage_count == 1) {
86037 - atomic_set(&hardware_enable_failed, 0);
86038 + atomic_set_unchecked(&hardware_enable_failed, 0);
86039 on_each_cpu(hardware_enable_nolock, NULL, 1);
86040
86041 - if (atomic_read(&hardware_enable_failed)) {
86042 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86043 hardware_disable_all_nolock();
86044 r = -EBUSY;
86045 }
86046 @@ -2732,7 +2732,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86047 kvm_arch_vcpu_put(vcpu);
86048 }
86049
86050 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86051 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86052 struct module *module)
86053 {
86054 int r;
86055 @@ -2795,7 +2795,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86056 if (!vcpu_align)
86057 vcpu_align = __alignof__(struct kvm_vcpu);
86058 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86059 - 0, NULL);
86060 + SLAB_USERCOPY, NULL);
86061 if (!kvm_vcpu_cache) {
86062 r = -ENOMEM;
86063 goto out_free_3;
86064 @@ -2805,9 +2805,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86065 if (r)
86066 goto out_free;
86067
86068 - kvm_chardev_ops.owner = module;
86069 - kvm_vm_fops.owner = module;
86070 - kvm_vcpu_fops.owner = module;
86071 + pax_open_kernel();
86072 + *(void **)&kvm_chardev_ops.owner = module;
86073 + *(void **)&kvm_vm_fops.owner = module;
86074 + *(void **)&kvm_vcpu_fops.owner = module;
86075 + pax_close_kernel();
86076
86077 r = misc_register(&kvm_dev);
86078 if (r) {