]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.1-201204091729.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.1-201204091729.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 026a227..990f035 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..3935f40 100644
9654 --- a/arch/x86/include/asm/cmpxchg.h
9655 +++ b/arch/x86/include/asm/cmpxchg.h
9656 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9657 __compiletime_error("Bad argument size for cmpxchg");
9658 extern void __xadd_wrong_size(void)
9659 __compiletime_error("Bad argument size for xadd");
9660 +extern void __xadd_check_overflow_wrong_size(void)
9661 + __compiletime_error("Bad argument size for xadd_check_overflow");
9662 extern void __add_wrong_size(void)
9663 __compiletime_error("Bad argument size for add");
9664 +extern void __add_check_overflow_wrong_size(void)
9665 + __compiletime_error("Bad argument size for add_check_overflow");
9666
9667 /*
9668 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9669 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9670 __ret; \
9671 })
9672
9673 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9674 + ({ \
9675 + __typeof__ (*(ptr)) __ret = (arg); \
9676 + switch (sizeof(*(ptr))) { \
9677 + case __X86_CASE_L: \
9678 + asm volatile (lock #op "l %0, %1\n" \
9679 + "jno 0f\n" \
9680 + "mov %0,%1\n" \
9681 + "int $4\n0:\n" \
9682 + _ASM_EXTABLE(0b, 0b) \
9683 + : "+r" (__ret), "+m" (*(ptr)) \
9684 + : : "memory", "cc"); \
9685 + break; \
9686 + case __X86_CASE_Q: \
9687 + asm volatile (lock #op "q %q0, %1\n" \
9688 + "jno 0f\n" \
9689 + "mov %0,%1\n" \
9690 + "int $4\n0:\n" \
9691 + _ASM_EXTABLE(0b, 0b) \
9692 + : "+r" (__ret), "+m" (*(ptr)) \
9693 + : : "memory", "cc"); \
9694 + break; \
9695 + default: \
9696 + __ ## op ## _check_overflow_wrong_size(); \
9697 + } \
9698 + __ret; \
9699 + })
9700 +
9701 /*
9702 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9703 * Since this is generally used to protect other memory information, we
9704 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
9705 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9706 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9707
9708 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9709 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9710 +
9711 #define __add(ptr, inc, lock) \
9712 ({ \
9713 __typeof__ (*(ptr)) __ret = (inc); \
9714 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9715 index 8d67d42..183d0eb 100644
9716 --- a/arch/x86/include/asm/cpufeature.h
9717 +++ b/arch/x86/include/asm/cpufeature.h
9718 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9719 ".section .discard,\"aw\",@progbits\n"
9720 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9721 ".previous\n"
9722 - ".section .altinstr_replacement,\"ax\"\n"
9723 + ".section .altinstr_replacement,\"a\"\n"
9724 "3: movb $1,%0\n"
9725 "4:\n"
9726 ".previous\n"
9727 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9728 index e95822d..a90010e 100644
9729 --- a/arch/x86/include/asm/desc.h
9730 +++ b/arch/x86/include/asm/desc.h
9731 @@ -4,6 +4,7 @@
9732 #include <asm/desc_defs.h>
9733 #include <asm/ldt.h>
9734 #include <asm/mmu.h>
9735 +#include <asm/pgtable.h>
9736
9737 #include <linux/smp.h>
9738
9739 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9740
9741 desc->type = (info->read_exec_only ^ 1) << 1;
9742 desc->type |= info->contents << 2;
9743 + desc->type |= info->seg_not_present ^ 1;
9744
9745 desc->s = 1;
9746 desc->dpl = 0x3;
9747 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9748 }
9749
9750 extern struct desc_ptr idt_descr;
9751 -extern gate_desc idt_table[];
9752 extern struct desc_ptr nmi_idt_descr;
9753 -extern gate_desc nmi_idt_table[];
9754 -
9755 -struct gdt_page {
9756 - struct desc_struct gdt[GDT_ENTRIES];
9757 -} __attribute__((aligned(PAGE_SIZE)));
9758 -
9759 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9760 +extern gate_desc idt_table[256];
9761 +extern gate_desc nmi_idt_table[256];
9762
9763 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9764 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9765 {
9766 - return per_cpu(gdt_page, cpu).gdt;
9767 + return cpu_gdt_table[cpu];
9768 }
9769
9770 #ifdef CONFIG_X86_64
9771 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9772 unsigned long base, unsigned dpl, unsigned flags,
9773 unsigned short seg)
9774 {
9775 - gate->a = (seg << 16) | (base & 0xffff);
9776 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9777 + gate->gate.offset_low = base;
9778 + gate->gate.seg = seg;
9779 + gate->gate.reserved = 0;
9780 + gate->gate.type = type;
9781 + gate->gate.s = 0;
9782 + gate->gate.dpl = dpl;
9783 + gate->gate.p = 1;
9784 + gate->gate.offset_high = base >> 16;
9785 }
9786
9787 #endif
9788 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9789
9790 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9791 {
9792 + pax_open_kernel();
9793 memcpy(&idt[entry], gate, sizeof(*gate));
9794 + pax_close_kernel();
9795 }
9796
9797 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9798 {
9799 + pax_open_kernel();
9800 memcpy(&ldt[entry], desc, 8);
9801 + pax_close_kernel();
9802 }
9803
9804 static inline void
9805 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9806 default: size = sizeof(*gdt); break;
9807 }
9808
9809 + pax_open_kernel();
9810 memcpy(&gdt[entry], desc, size);
9811 + pax_close_kernel();
9812 }
9813
9814 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9815 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9816
9817 static inline void native_load_tr_desc(void)
9818 {
9819 + pax_open_kernel();
9820 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9821 + pax_close_kernel();
9822 }
9823
9824 static inline void native_load_gdt(const struct desc_ptr *dtr)
9825 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9826 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9827 unsigned int i;
9828
9829 + pax_open_kernel();
9830 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9831 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9832 + pax_close_kernel();
9833 }
9834
9835 #define _LDT_empty(info) \
9836 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9837 }
9838
9839 #ifdef CONFIG_X86_64
9840 -static inline void set_nmi_gate(int gate, void *addr)
9841 +static inline void set_nmi_gate(int gate, const void *addr)
9842 {
9843 gate_desc s;
9844
9845 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9846 }
9847 #endif
9848
9849 -static inline void _set_gate(int gate, unsigned type, void *addr,
9850 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9851 unsigned dpl, unsigned ist, unsigned seg)
9852 {
9853 gate_desc s;
9854 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9855 * Pentium F0 0F bugfix can have resulted in the mapped
9856 * IDT being write-protected.
9857 */
9858 -static inline void set_intr_gate(unsigned int n, void *addr)
9859 +static inline void set_intr_gate(unsigned int n, const void *addr)
9860 {
9861 BUG_ON((unsigned)n > 0xFF);
9862 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9863 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9864 /*
9865 * This routine sets up an interrupt gate at directory privilege level 3.
9866 */
9867 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9868 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9869 {
9870 BUG_ON((unsigned)n > 0xFF);
9871 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9872 }
9873
9874 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9875 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9876 {
9877 BUG_ON((unsigned)n > 0xFF);
9878 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9879 }
9880
9881 -static inline void set_trap_gate(unsigned int n, void *addr)
9882 +static inline void set_trap_gate(unsigned int n, const void *addr)
9883 {
9884 BUG_ON((unsigned)n > 0xFF);
9885 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9886 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9887 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9888 {
9889 BUG_ON((unsigned)n > 0xFF);
9890 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9891 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9892 }
9893
9894 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9895 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9896 {
9897 BUG_ON((unsigned)n > 0xFF);
9898 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9899 }
9900
9901 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9902 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9903 {
9904 BUG_ON((unsigned)n > 0xFF);
9905 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9906 }
9907
9908 +#ifdef CONFIG_X86_32
9909 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9910 +{
9911 + struct desc_struct d;
9912 +
9913 + if (likely(limit))
9914 + limit = (limit - 1UL) >> PAGE_SHIFT;
9915 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9916 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9917 +}
9918 +#endif
9919 +
9920 #endif /* _ASM_X86_DESC_H */
9921 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9922 index 278441f..b95a174 100644
9923 --- a/arch/x86/include/asm/desc_defs.h
9924 +++ b/arch/x86/include/asm/desc_defs.h
9925 @@ -31,6 +31,12 @@ struct desc_struct {
9926 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9927 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9928 };
9929 + struct {
9930 + u16 offset_low;
9931 + u16 seg;
9932 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9933 + unsigned offset_high: 16;
9934 + } gate;
9935 };
9936 } __attribute__((packed));
9937
9938 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9939 index 3778256..c5d4fce 100644
9940 --- a/arch/x86/include/asm/e820.h
9941 +++ b/arch/x86/include/asm/e820.h
9942 @@ -69,7 +69,7 @@ struct e820map {
9943 #define ISA_START_ADDRESS 0xa0000
9944 #define ISA_END_ADDRESS 0x100000
9945
9946 -#define BIOS_BEGIN 0x000a0000
9947 +#define BIOS_BEGIN 0x000c0000
9948 #define BIOS_END 0x00100000
9949
9950 #define BIOS_ROM_BASE 0xffe00000
9951 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9952 index 5f962df..7289f09 100644
9953 --- a/arch/x86/include/asm/elf.h
9954 +++ b/arch/x86/include/asm/elf.h
9955 @@ -238,7 +238,25 @@ extern int force_personality32;
9956 the loader. We need to make sure that it is out of the way of the program
9957 that it will "exec", and that there is sufficient room for the brk. */
9958
9959 +#ifdef CONFIG_PAX_SEGMEXEC
9960 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9961 +#else
9962 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9963 +#endif
9964 +
9965 +#ifdef CONFIG_PAX_ASLR
9966 +#ifdef CONFIG_X86_32
9967 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9968 +
9969 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9970 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9971 +#else
9972 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9973 +
9974 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9975 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9976 +#endif
9977 +#endif
9978
9979 /* This yields a mask that user programs can use to figure out what
9980 instruction set this CPU supports. This could be done in user space,
9981 @@ -291,9 +309,7 @@ do { \
9982
9983 #define ARCH_DLINFO \
9984 do { \
9985 - if (vdso_enabled) \
9986 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9987 - (unsigned long)current->mm->context.vdso); \
9988 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9989 } while (0)
9990
9991 #define AT_SYSINFO 32
9992 @@ -304,7 +320,7 @@ do { \
9993
9994 #endif /* !CONFIG_X86_32 */
9995
9996 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9997 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9998
9999 #define VDSO_ENTRY \
10000 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10001 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10002 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10003 #define compat_arch_setup_additional_pages syscall32_setup_pages
10004
10005 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10006 -#define arch_randomize_brk arch_randomize_brk
10007 -
10008 /*
10009 * True on X86_32 or when emulating IA32 on X86_64
10010 */
10011 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10012 index cc70c1c..d96d011 100644
10013 --- a/arch/x86/include/asm/emergency-restart.h
10014 +++ b/arch/x86/include/asm/emergency-restart.h
10015 @@ -15,6 +15,6 @@ enum reboot_type {
10016
10017 extern enum reboot_type reboot_type;
10018
10019 -extern void machine_emergency_restart(void);
10020 +extern void machine_emergency_restart(void) __noreturn;
10021
10022 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10023 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10024 index dbe82a5..c6d8a00 100644
10025 --- a/arch/x86/include/asm/floppy.h
10026 +++ b/arch/x86/include/asm/floppy.h
10027 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10028 }
10029
10030
10031 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10032 static unsigned long vdma_mem_alloc(unsigned long size)
10033 {
10034 return (unsigned long)vmalloc(size);
10035 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10036 index d09bb03..4ea4194 100644
10037 --- a/arch/x86/include/asm/futex.h
10038 +++ b/arch/x86/include/asm/futex.h
10039 @@ -12,16 +12,18 @@
10040 #include <asm/system.h>
10041
10042 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10043 + typecheck(u32 __user *, uaddr); \
10044 asm volatile("1:\t" insn "\n" \
10045 "2:\t.section .fixup,\"ax\"\n" \
10046 "3:\tmov\t%3, %1\n" \
10047 "\tjmp\t2b\n" \
10048 "\t.previous\n" \
10049 _ASM_EXTABLE(1b, 3b) \
10050 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10051 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10052 : "i" (-EFAULT), "0" (oparg), "1" (0))
10053
10054 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10055 + typecheck(u32 __user *, uaddr); \
10056 asm volatile("1:\tmovl %2, %0\n" \
10057 "\tmovl\t%0, %3\n" \
10058 "\t" insn "\n" \
10059 @@ -34,7 +36,7 @@
10060 _ASM_EXTABLE(1b, 4b) \
10061 _ASM_EXTABLE(2b, 4b) \
10062 : "=&a" (oldval), "=&r" (ret), \
10063 - "+m" (*uaddr), "=&r" (tem) \
10064 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10065 : "r" (oparg), "i" (-EFAULT), "1" (0))
10066
10067 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10068 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10069
10070 switch (op) {
10071 case FUTEX_OP_SET:
10072 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10073 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10074 break;
10075 case FUTEX_OP_ADD:
10076 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10077 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10078 uaddr, oparg);
10079 break;
10080 case FUTEX_OP_OR:
10081 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10082 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10083 return -EFAULT;
10084
10085 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10086 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10087 "2:\t.section .fixup, \"ax\"\n"
10088 "3:\tmov %3, %0\n"
10089 "\tjmp 2b\n"
10090 "\t.previous\n"
10091 _ASM_EXTABLE(1b, 3b)
10092 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10093 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10094 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10095 : "memory"
10096 );
10097 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10098 index eb92a6e..b98b2f4 100644
10099 --- a/arch/x86/include/asm/hw_irq.h
10100 +++ b/arch/x86/include/asm/hw_irq.h
10101 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10102 extern void enable_IO_APIC(void);
10103
10104 /* Statistics */
10105 -extern atomic_t irq_err_count;
10106 -extern atomic_t irq_mis_count;
10107 +extern atomic_unchecked_t irq_err_count;
10108 +extern atomic_unchecked_t irq_mis_count;
10109
10110 /* EISA */
10111 extern void eisa_set_level_irq(unsigned int irq);
10112 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10113 index 2479049..3fb9795 100644
10114 --- a/arch/x86/include/asm/i387.h
10115 +++ b/arch/x86/include/asm/i387.h
10116 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10117 {
10118 int err;
10119
10120 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10121 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10122 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10123 +#endif
10124 +
10125 /* See comment in fxsave() below. */
10126 #ifdef CONFIG_AS_FXSAVEQ
10127 asm volatile("1: fxrstorq %[fx]\n\t"
10128 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10129 {
10130 int err;
10131
10132 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10133 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10134 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10135 +#endif
10136 +
10137 /*
10138 * Clear the bytes not touched by the fxsave and reserved
10139 * for the SW usage.
10140 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10141 "emms\n\t" /* clear stack tags */
10142 "fildl %P[addr]", /* set F?P to defined value */
10143 X86_FEATURE_FXSAVE_LEAK,
10144 - [addr] "m" (tsk->thread.fpu.has_fpu));
10145 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10146
10147 return fpu_restore_checking(&tsk->thread.fpu);
10148 }
10149 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10150 static inline bool interrupted_user_mode(void)
10151 {
10152 struct pt_regs *regs = get_irq_regs();
10153 - return regs && user_mode_vm(regs);
10154 + return regs && user_mode(regs);
10155 }
10156
10157 /*
10158 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10159 index d8e8eef..99f81ae 100644
10160 --- a/arch/x86/include/asm/io.h
10161 +++ b/arch/x86/include/asm/io.h
10162 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10163
10164 #include <linux/vmalloc.h>
10165
10166 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10167 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10168 +{
10169 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10170 +}
10171 +
10172 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10173 +{
10174 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10175 +}
10176 +
10177 /*
10178 * Convert a virtual cached pointer to an uncached pointer
10179 */
10180 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10181 index bba3cf8..06bc8da 100644
10182 --- a/arch/x86/include/asm/irqflags.h
10183 +++ b/arch/x86/include/asm/irqflags.h
10184 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10185 sti; \
10186 sysexit
10187
10188 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10189 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10190 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10191 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10192 +
10193 #else
10194 #define INTERRUPT_RETURN iret
10195 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10196 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10197 index 5478825..839e88c 100644
10198 --- a/arch/x86/include/asm/kprobes.h
10199 +++ b/arch/x86/include/asm/kprobes.h
10200 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10201 #define RELATIVEJUMP_SIZE 5
10202 #define RELATIVECALL_OPCODE 0xe8
10203 #define RELATIVE_ADDR_SIZE 4
10204 -#define MAX_STACK_SIZE 64
10205 -#define MIN_STACK_SIZE(ADDR) \
10206 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10207 - THREAD_SIZE - (unsigned long)(ADDR))) \
10208 - ? (MAX_STACK_SIZE) \
10209 - : (((unsigned long)current_thread_info()) + \
10210 - THREAD_SIZE - (unsigned long)(ADDR)))
10211 +#define MAX_STACK_SIZE 64UL
10212 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10213
10214 #define flush_insn_slot(p) do { } while (0)
10215
10216 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10217 index 52d6640..3d2c938 100644
10218 --- a/arch/x86/include/asm/kvm_host.h
10219 +++ b/arch/x86/include/asm/kvm_host.h
10220 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10221 int (*check_intercept)(struct kvm_vcpu *vcpu,
10222 struct x86_instruction_info *info,
10223 enum x86_intercept_stage stage);
10224 -};
10225 +} __do_const;
10226
10227 struct kvm_arch_async_pf {
10228 u32 token;
10229 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10230 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10231
10232 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10233 - const void *val, int bytes);
10234 + const void *val, int bytes) __size_overflow(2);
10235 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10236
10237 extern bool tdp_enabled;
10238 @@ -756,7 +756,7 @@ void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
10239 int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
10240
10241 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
10242 -int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
10243 +int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) __size_overflow(3);
10244
10245 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
10246 void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
10247 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10248
10249 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10250 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10251 - const u8 *new, int bytes);
10252 + const u8 *new, int bytes) __size_overflow(2);
10253 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10254 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10255 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10256 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10257 index 9cdae5d..300d20f 100644
10258 --- a/arch/x86/include/asm/local.h
10259 +++ b/arch/x86/include/asm/local.h
10260 @@ -18,26 +18,58 @@ typedef struct {
10261
10262 static inline void local_inc(local_t *l)
10263 {
10264 - asm volatile(_ASM_INC "%0"
10265 + asm volatile(_ASM_INC "%0\n"
10266 +
10267 +#ifdef CONFIG_PAX_REFCOUNT
10268 + "jno 0f\n"
10269 + _ASM_DEC "%0\n"
10270 + "int $4\n0:\n"
10271 + _ASM_EXTABLE(0b, 0b)
10272 +#endif
10273 +
10274 : "+m" (l->a.counter));
10275 }
10276
10277 static inline void local_dec(local_t *l)
10278 {
10279 - asm volatile(_ASM_DEC "%0"
10280 + asm volatile(_ASM_DEC "%0\n"
10281 +
10282 +#ifdef CONFIG_PAX_REFCOUNT
10283 + "jno 0f\n"
10284 + _ASM_INC "%0\n"
10285 + "int $4\n0:\n"
10286 + _ASM_EXTABLE(0b, 0b)
10287 +#endif
10288 +
10289 : "+m" (l->a.counter));
10290 }
10291
10292 static inline void local_add(long i, local_t *l)
10293 {
10294 - asm volatile(_ASM_ADD "%1,%0"
10295 + asm volatile(_ASM_ADD "%1,%0\n"
10296 +
10297 +#ifdef CONFIG_PAX_REFCOUNT
10298 + "jno 0f\n"
10299 + _ASM_SUB "%1,%0\n"
10300 + "int $4\n0:\n"
10301 + _ASM_EXTABLE(0b, 0b)
10302 +#endif
10303 +
10304 : "+m" (l->a.counter)
10305 : "ir" (i));
10306 }
10307
10308 static inline void local_sub(long i, local_t *l)
10309 {
10310 - asm volatile(_ASM_SUB "%1,%0"
10311 + asm volatile(_ASM_SUB "%1,%0\n"
10312 +
10313 +#ifdef CONFIG_PAX_REFCOUNT
10314 + "jno 0f\n"
10315 + _ASM_ADD "%1,%0\n"
10316 + "int $4\n0:\n"
10317 + _ASM_EXTABLE(0b, 0b)
10318 +#endif
10319 +
10320 : "+m" (l->a.counter)
10321 : "ir" (i));
10322 }
10323 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10324 {
10325 unsigned char c;
10326
10327 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10328 + asm volatile(_ASM_SUB "%2,%0\n"
10329 +
10330 +#ifdef CONFIG_PAX_REFCOUNT
10331 + "jno 0f\n"
10332 + _ASM_ADD "%2,%0\n"
10333 + "int $4\n0:\n"
10334 + _ASM_EXTABLE(0b, 0b)
10335 +#endif
10336 +
10337 + "sete %1\n"
10338 : "+m" (l->a.counter), "=qm" (c)
10339 : "ir" (i) : "memory");
10340 return c;
10341 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10342 {
10343 unsigned char c;
10344
10345 - asm volatile(_ASM_DEC "%0; sete %1"
10346 + asm volatile(_ASM_DEC "%0\n"
10347 +
10348 +#ifdef CONFIG_PAX_REFCOUNT
10349 + "jno 0f\n"
10350 + _ASM_INC "%0\n"
10351 + "int $4\n0:\n"
10352 + _ASM_EXTABLE(0b, 0b)
10353 +#endif
10354 +
10355 + "sete %1\n"
10356 : "+m" (l->a.counter), "=qm" (c)
10357 : : "memory");
10358 return c != 0;
10359 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10360 {
10361 unsigned char c;
10362
10363 - asm volatile(_ASM_INC "%0; sete %1"
10364 + asm volatile(_ASM_INC "%0\n"
10365 +
10366 +#ifdef CONFIG_PAX_REFCOUNT
10367 + "jno 0f\n"
10368 + _ASM_DEC "%0\n"
10369 + "int $4\n0:\n"
10370 + _ASM_EXTABLE(0b, 0b)
10371 +#endif
10372 +
10373 + "sete %1\n"
10374 : "+m" (l->a.counter), "=qm" (c)
10375 : : "memory");
10376 return c != 0;
10377 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10378 {
10379 unsigned char c;
10380
10381 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10382 + asm volatile(_ASM_ADD "%2,%0\n"
10383 +
10384 +#ifdef CONFIG_PAX_REFCOUNT
10385 + "jno 0f\n"
10386 + _ASM_SUB "%2,%0\n"
10387 + "int $4\n0:\n"
10388 + _ASM_EXTABLE(0b, 0b)
10389 +#endif
10390 +
10391 + "sets %1\n"
10392 : "+m" (l->a.counter), "=qm" (c)
10393 : "ir" (i) : "memory");
10394 return c;
10395 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10396 #endif
10397 /* Modern 486+ processor */
10398 __i = i;
10399 - asm volatile(_ASM_XADD "%0, %1;"
10400 + asm volatile(_ASM_XADD "%0, %1\n"
10401 +
10402 +#ifdef CONFIG_PAX_REFCOUNT
10403 + "jno 0f\n"
10404 + _ASM_MOV "%0,%1\n"
10405 + "int $4\n0:\n"
10406 + _ASM_EXTABLE(0b, 0b)
10407 +#endif
10408 +
10409 : "+r" (i), "+m" (l->a.counter)
10410 : : "memory");
10411 return i + __i;
10412 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10413 index 593e51d..fa69c9a 100644
10414 --- a/arch/x86/include/asm/mman.h
10415 +++ b/arch/x86/include/asm/mman.h
10416 @@ -5,4 +5,14 @@
10417
10418 #include <asm-generic/mman.h>
10419
10420 +#ifdef __KERNEL__
10421 +#ifndef __ASSEMBLY__
10422 +#ifdef CONFIG_X86_32
10423 +#define arch_mmap_check i386_mmap_check
10424 +int i386_mmap_check(unsigned long addr, unsigned long len,
10425 + unsigned long flags);
10426 +#endif
10427 +#endif
10428 +#endif
10429 +
10430 #endif /* _ASM_X86_MMAN_H */
10431 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10432 index 5f55e69..e20bfb1 100644
10433 --- a/arch/x86/include/asm/mmu.h
10434 +++ b/arch/x86/include/asm/mmu.h
10435 @@ -9,7 +9,7 @@
10436 * we put the segment information here.
10437 */
10438 typedef struct {
10439 - void *ldt;
10440 + struct desc_struct *ldt;
10441 int size;
10442
10443 #ifdef CONFIG_X86_64
10444 @@ -18,7 +18,19 @@ typedef struct {
10445 #endif
10446
10447 struct mutex lock;
10448 - void *vdso;
10449 + unsigned long vdso;
10450 +
10451 +#ifdef CONFIG_X86_32
10452 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10453 + unsigned long user_cs_base;
10454 + unsigned long user_cs_limit;
10455 +
10456 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10457 + cpumask_t cpu_user_cs_mask;
10458 +#endif
10459 +
10460 +#endif
10461 +#endif
10462 } mm_context_t;
10463
10464 #ifdef CONFIG_SMP
10465 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10466 index 6902152..399f3a2 100644
10467 --- a/arch/x86/include/asm/mmu_context.h
10468 +++ b/arch/x86/include/asm/mmu_context.h
10469 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10470
10471 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10472 {
10473 +
10474 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10475 + unsigned int i;
10476 + pgd_t *pgd;
10477 +
10478 + pax_open_kernel();
10479 + pgd = get_cpu_pgd(smp_processor_id());
10480 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10481 + set_pgd_batched(pgd+i, native_make_pgd(0));
10482 + pax_close_kernel();
10483 +#endif
10484 +
10485 #ifdef CONFIG_SMP
10486 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10487 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10488 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10489 struct task_struct *tsk)
10490 {
10491 unsigned cpu = smp_processor_id();
10492 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10493 + int tlbstate = TLBSTATE_OK;
10494 +#endif
10495
10496 if (likely(prev != next)) {
10497 #ifdef CONFIG_SMP
10498 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10499 + tlbstate = percpu_read(cpu_tlbstate.state);
10500 +#endif
10501 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10502 percpu_write(cpu_tlbstate.active_mm, next);
10503 #endif
10504 cpumask_set_cpu(cpu, mm_cpumask(next));
10505
10506 /* Re-load page tables */
10507 +#ifdef CONFIG_PAX_PER_CPU_PGD
10508 + pax_open_kernel();
10509 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10510 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10511 + pax_close_kernel();
10512 + load_cr3(get_cpu_pgd(cpu));
10513 +#else
10514 load_cr3(next->pgd);
10515 +#endif
10516
10517 /* stop flush ipis for the previous mm */
10518 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10519 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10520 */
10521 if (unlikely(prev->context.ldt != next->context.ldt))
10522 load_LDT_nolock(&next->context);
10523 - }
10524 +
10525 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10526 + if (!(__supported_pte_mask & _PAGE_NX)) {
10527 + smp_mb__before_clear_bit();
10528 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10529 + smp_mb__after_clear_bit();
10530 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10531 + }
10532 +#endif
10533 +
10534 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10535 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10536 + prev->context.user_cs_limit != next->context.user_cs_limit))
10537 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10538 #ifdef CONFIG_SMP
10539 + else if (unlikely(tlbstate != TLBSTATE_OK))
10540 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10541 +#endif
10542 +#endif
10543 +
10544 + }
10545 else {
10546 +
10547 +#ifdef CONFIG_PAX_PER_CPU_PGD
10548 + pax_open_kernel();
10549 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10550 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10551 + pax_close_kernel();
10552 + load_cr3(get_cpu_pgd(cpu));
10553 +#endif
10554 +
10555 +#ifdef CONFIG_SMP
10556 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10557 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10558
10559 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10560 * tlb flush IPI delivery. We must reload CR3
10561 * to make sure to use no freed page tables.
10562 */
10563 +
10564 +#ifndef CONFIG_PAX_PER_CPU_PGD
10565 load_cr3(next->pgd);
10566 +#endif
10567 +
10568 load_LDT_nolock(&next->context);
10569 +
10570 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10571 + if (!(__supported_pte_mask & _PAGE_NX))
10572 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10573 +#endif
10574 +
10575 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10576 +#ifdef CONFIG_PAX_PAGEEXEC
10577 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10578 +#endif
10579 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10580 +#endif
10581 +
10582 }
10583 +#endif
10584 }
10585 -#endif
10586 }
10587
10588 #define activate_mm(prev, next) \
10589 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10590 index 9eae775..c914fea 100644
10591 --- a/arch/x86/include/asm/module.h
10592 +++ b/arch/x86/include/asm/module.h
10593 @@ -5,6 +5,7 @@
10594
10595 #ifdef CONFIG_X86_64
10596 /* X86_64 does not define MODULE_PROC_FAMILY */
10597 +#define MODULE_PROC_FAMILY ""
10598 #elif defined CONFIG_M386
10599 #define MODULE_PROC_FAMILY "386 "
10600 #elif defined CONFIG_M486
10601 @@ -59,8 +60,20 @@
10602 #error unknown processor family
10603 #endif
10604
10605 -#ifdef CONFIG_X86_32
10606 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10607 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10608 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10609 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10610 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10611 +#else
10612 +#define MODULE_PAX_KERNEXEC ""
10613 #endif
10614
10615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10616 +#define MODULE_PAX_UDEREF "UDEREF "
10617 +#else
10618 +#define MODULE_PAX_UDEREF ""
10619 +#endif
10620 +
10621 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10622 +
10623 #endif /* _ASM_X86_MODULE_H */
10624 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10625 index 7639dbf..e08a58c 100644
10626 --- a/arch/x86/include/asm/page_64_types.h
10627 +++ b/arch/x86/include/asm/page_64_types.h
10628 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10629
10630 /* duplicated to the one in bootmem.h */
10631 extern unsigned long max_pfn;
10632 -extern unsigned long phys_base;
10633 +extern const unsigned long phys_base;
10634
10635 extern unsigned long __phys_addr(unsigned long);
10636 #define __phys_reloc_hide(x) (x)
10637 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10638 index a7d2db9..edb023e 100644
10639 --- a/arch/x86/include/asm/paravirt.h
10640 +++ b/arch/x86/include/asm/paravirt.h
10641 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10642 val);
10643 }
10644
10645 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10646 +{
10647 + pgdval_t val = native_pgd_val(pgd);
10648 +
10649 + if (sizeof(pgdval_t) > sizeof(long))
10650 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10651 + val, (u64)val >> 32);
10652 + else
10653 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10654 + val);
10655 +}
10656 +
10657 static inline void pgd_clear(pgd_t *pgdp)
10658 {
10659 set_pgd(pgdp, __pgd(0));
10660 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10661 pv_mmu_ops.set_fixmap(idx, phys, flags);
10662 }
10663
10664 +#ifdef CONFIG_PAX_KERNEXEC
10665 +static inline unsigned long pax_open_kernel(void)
10666 +{
10667 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10668 +}
10669 +
10670 +static inline unsigned long pax_close_kernel(void)
10671 +{
10672 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10673 +}
10674 +#else
10675 +static inline unsigned long pax_open_kernel(void) { return 0; }
10676 +static inline unsigned long pax_close_kernel(void) { return 0; }
10677 +#endif
10678 +
10679 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10680
10681 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10682 @@ -964,7 +991,7 @@ extern void default_banner(void);
10683
10684 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10685 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10686 -#define PARA_INDIRECT(addr) *%cs:addr
10687 +#define PARA_INDIRECT(addr) *%ss:addr
10688 #endif
10689
10690 #define INTERRUPT_RETURN \
10691 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10692 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10693 CLBR_NONE, \
10694 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10695 +
10696 +#define GET_CR0_INTO_RDI \
10697 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10698 + mov %rax,%rdi
10699 +
10700 +#define SET_RDI_INTO_CR0 \
10701 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10702 +
10703 +#define GET_CR3_INTO_RDI \
10704 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10705 + mov %rax,%rdi
10706 +
10707 +#define SET_RDI_INTO_CR3 \
10708 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10709 +
10710 #endif /* CONFIG_X86_32 */
10711
10712 #endif /* __ASSEMBLY__ */
10713 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10714 index 8e8b9a4..f07d725 100644
10715 --- a/arch/x86/include/asm/paravirt_types.h
10716 +++ b/arch/x86/include/asm/paravirt_types.h
10717 @@ -84,20 +84,20 @@ struct pv_init_ops {
10718 */
10719 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10720 unsigned long addr, unsigned len);
10721 -};
10722 +} __no_const;
10723
10724
10725 struct pv_lazy_ops {
10726 /* Set deferred update mode, used for batching operations. */
10727 void (*enter)(void);
10728 void (*leave)(void);
10729 -};
10730 +} __no_const;
10731
10732 struct pv_time_ops {
10733 unsigned long long (*sched_clock)(void);
10734 unsigned long long (*steal_clock)(int cpu);
10735 unsigned long (*get_tsc_khz)(void);
10736 -};
10737 +} __no_const;
10738
10739 struct pv_cpu_ops {
10740 /* hooks for various privileged instructions */
10741 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10742
10743 void (*start_context_switch)(struct task_struct *prev);
10744 void (*end_context_switch)(struct task_struct *next);
10745 -};
10746 +} __no_const;
10747
10748 struct pv_irq_ops {
10749 /*
10750 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10751 unsigned long start_eip,
10752 unsigned long start_esp);
10753 #endif
10754 -};
10755 +} __no_const;
10756
10757 struct pv_mmu_ops {
10758 unsigned long (*read_cr2)(void);
10759 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10760 struct paravirt_callee_save make_pud;
10761
10762 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10763 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10764 #endif /* PAGETABLE_LEVELS == 4 */
10765 #endif /* PAGETABLE_LEVELS >= 3 */
10766
10767 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10768 an mfn. We can tell which is which from the index. */
10769 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10770 phys_addr_t phys, pgprot_t flags);
10771 +
10772 +#ifdef CONFIG_PAX_KERNEXEC
10773 + unsigned long (*pax_open_kernel)(void);
10774 + unsigned long (*pax_close_kernel)(void);
10775 +#endif
10776 +
10777 };
10778
10779 struct arch_spinlock;
10780 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10781 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10782 int (*spin_trylock)(struct arch_spinlock *lock);
10783 void (*spin_unlock)(struct arch_spinlock *lock);
10784 -};
10785 +} __no_const;
10786
10787 /* This contains all the paravirt structures: we get a convenient
10788 * number for each function using the offset which we use to indicate
10789 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10790 index b4389a4..b7ff22c 100644
10791 --- a/arch/x86/include/asm/pgalloc.h
10792 +++ b/arch/x86/include/asm/pgalloc.h
10793 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10794 pmd_t *pmd, pte_t *pte)
10795 {
10796 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10797 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10798 +}
10799 +
10800 +static inline void pmd_populate_user(struct mm_struct *mm,
10801 + pmd_t *pmd, pte_t *pte)
10802 +{
10803 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10804 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10805 }
10806
10807 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10808 index 98391db..8f6984e 100644
10809 --- a/arch/x86/include/asm/pgtable-2level.h
10810 +++ b/arch/x86/include/asm/pgtable-2level.h
10811 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10812
10813 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10814 {
10815 + pax_open_kernel();
10816 *pmdp = pmd;
10817 + pax_close_kernel();
10818 }
10819
10820 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10821 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10822 index effff47..f9e4035 100644
10823 --- a/arch/x86/include/asm/pgtable-3level.h
10824 +++ b/arch/x86/include/asm/pgtable-3level.h
10825 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10826
10827 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10828 {
10829 + pax_open_kernel();
10830 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10831 + pax_close_kernel();
10832 }
10833
10834 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10835 {
10836 + pax_open_kernel();
10837 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10838 + pax_close_kernel();
10839 }
10840
10841 /*
10842 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10843 index 49afb3f..ed14d07 100644
10844 --- a/arch/x86/include/asm/pgtable.h
10845 +++ b/arch/x86/include/asm/pgtable.h
10846 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10847
10848 #ifndef __PAGETABLE_PUD_FOLDED
10849 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10850 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10851 #define pgd_clear(pgd) native_pgd_clear(pgd)
10852 #endif
10853
10854 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10855
10856 #define arch_end_context_switch(prev) do {} while(0)
10857
10858 +#define pax_open_kernel() native_pax_open_kernel()
10859 +#define pax_close_kernel() native_pax_close_kernel()
10860 #endif /* CONFIG_PARAVIRT */
10861
10862 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10863 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10864 +
10865 +#ifdef CONFIG_PAX_KERNEXEC
10866 +static inline unsigned long native_pax_open_kernel(void)
10867 +{
10868 + unsigned long cr0;
10869 +
10870 + preempt_disable();
10871 + barrier();
10872 + cr0 = read_cr0() ^ X86_CR0_WP;
10873 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10874 + write_cr0(cr0);
10875 + return cr0 ^ X86_CR0_WP;
10876 +}
10877 +
10878 +static inline unsigned long native_pax_close_kernel(void)
10879 +{
10880 + unsigned long cr0;
10881 +
10882 + cr0 = read_cr0() ^ X86_CR0_WP;
10883 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10884 + write_cr0(cr0);
10885 + barrier();
10886 + preempt_enable_no_resched();
10887 + return cr0 ^ X86_CR0_WP;
10888 +}
10889 +#else
10890 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10891 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10892 +#endif
10893 +
10894 /*
10895 * The following only work if pte_present() is true.
10896 * Undefined behaviour if not..
10897 */
10898 +static inline int pte_user(pte_t pte)
10899 +{
10900 + return pte_val(pte) & _PAGE_USER;
10901 +}
10902 +
10903 static inline int pte_dirty(pte_t pte)
10904 {
10905 return pte_flags(pte) & _PAGE_DIRTY;
10906 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10907 return pte_clear_flags(pte, _PAGE_RW);
10908 }
10909
10910 +static inline pte_t pte_mkread(pte_t pte)
10911 +{
10912 + return __pte(pte_val(pte) | _PAGE_USER);
10913 +}
10914 +
10915 static inline pte_t pte_mkexec(pte_t pte)
10916 {
10917 - return pte_clear_flags(pte, _PAGE_NX);
10918 +#ifdef CONFIG_X86_PAE
10919 + if (__supported_pte_mask & _PAGE_NX)
10920 + return pte_clear_flags(pte, _PAGE_NX);
10921 + else
10922 +#endif
10923 + return pte_set_flags(pte, _PAGE_USER);
10924 +}
10925 +
10926 +static inline pte_t pte_exprotect(pte_t pte)
10927 +{
10928 +#ifdef CONFIG_X86_PAE
10929 + if (__supported_pte_mask & _PAGE_NX)
10930 + return pte_set_flags(pte, _PAGE_NX);
10931 + else
10932 +#endif
10933 + return pte_clear_flags(pte, _PAGE_USER);
10934 }
10935
10936 static inline pte_t pte_mkdirty(pte_t pte)
10937 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10938 #endif
10939
10940 #ifndef __ASSEMBLY__
10941 +
10942 +#ifdef CONFIG_PAX_PER_CPU_PGD
10943 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10944 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10945 +{
10946 + return cpu_pgd[cpu];
10947 +}
10948 +#endif
10949 +
10950 #include <linux/mm_types.h>
10951
10952 static inline int pte_none(pte_t pte)
10953 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10954
10955 static inline int pgd_bad(pgd_t pgd)
10956 {
10957 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10958 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10959 }
10960
10961 static inline int pgd_none(pgd_t pgd)
10962 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10963 * pgd_offset() returns a (pgd_t *)
10964 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10965 */
10966 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10967 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10968 +
10969 +#ifdef CONFIG_PAX_PER_CPU_PGD
10970 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10971 +#endif
10972 +
10973 /*
10974 * a shortcut which implies the use of the kernel's pgd, instead
10975 * of a process's
10976 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10977 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10978 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10979
10980 +#ifdef CONFIG_X86_32
10981 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10982 +#else
10983 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10984 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10985 +
10986 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10987 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10988 +#else
10989 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10990 +#endif
10991 +
10992 +#endif
10993 +
10994 #ifndef __ASSEMBLY__
10995
10996 extern int direct_gbpages;
10997 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10998 * dst and src can be on the same page, but the range must not overlap,
10999 * and must not cross a page boundary.
11000 */
11001 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11002 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11003 {
11004 - memcpy(dst, src, count * sizeof(pgd_t));
11005 + pax_open_kernel();
11006 + while (count--)
11007 + *dst++ = *src++;
11008 + pax_close_kernel();
11009 }
11010
11011 +#ifdef CONFIG_PAX_PER_CPU_PGD
11012 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11013 +#endif
11014 +
11015 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11016 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11017 +#else
11018 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11019 +#endif
11020
11021 #include <asm-generic/pgtable.h>
11022 #endif /* __ASSEMBLY__ */
11023 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11024 index 0c92113..34a77c6 100644
11025 --- a/arch/x86/include/asm/pgtable_32.h
11026 +++ b/arch/x86/include/asm/pgtable_32.h
11027 @@ -25,9 +25,6 @@
11028 struct mm_struct;
11029 struct vm_area_struct;
11030
11031 -extern pgd_t swapper_pg_dir[1024];
11032 -extern pgd_t initial_page_table[1024];
11033 -
11034 static inline void pgtable_cache_init(void) { }
11035 static inline void check_pgt_cache(void) { }
11036 void paging_init(void);
11037 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11038 # include <asm/pgtable-2level.h>
11039 #endif
11040
11041 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11042 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11043 +#ifdef CONFIG_X86_PAE
11044 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11045 +#endif
11046 +
11047 #if defined(CONFIG_HIGHPTE)
11048 #define pte_offset_map(dir, address) \
11049 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11050 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11051 /* Clear a kernel PTE and flush it from the TLB */
11052 #define kpte_clear_flush(ptep, vaddr) \
11053 do { \
11054 + pax_open_kernel(); \
11055 pte_clear(&init_mm, (vaddr), (ptep)); \
11056 + pax_close_kernel(); \
11057 __flush_tlb_one((vaddr)); \
11058 } while (0)
11059
11060 @@ -74,6 +79,9 @@ do { \
11061
11062 #endif /* !__ASSEMBLY__ */
11063
11064 +#define HAVE_ARCH_UNMAPPED_AREA
11065 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11066 +
11067 /*
11068 * kern_addr_valid() is (1) for FLATMEM and (0) for
11069 * SPARSEMEM and DISCONTIGMEM
11070 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11071 index ed5903b..c7fe163 100644
11072 --- a/arch/x86/include/asm/pgtable_32_types.h
11073 +++ b/arch/x86/include/asm/pgtable_32_types.h
11074 @@ -8,7 +8,7 @@
11075 */
11076 #ifdef CONFIG_X86_PAE
11077 # include <asm/pgtable-3level_types.h>
11078 -# define PMD_SIZE (1UL << PMD_SHIFT)
11079 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11080 # define PMD_MASK (~(PMD_SIZE - 1))
11081 #else
11082 # include <asm/pgtable-2level_types.h>
11083 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11084 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11085 #endif
11086
11087 +#ifdef CONFIG_PAX_KERNEXEC
11088 +#ifndef __ASSEMBLY__
11089 +extern unsigned char MODULES_EXEC_VADDR[];
11090 +extern unsigned char MODULES_EXEC_END[];
11091 +#endif
11092 +#include <asm/boot.h>
11093 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11094 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11095 +#else
11096 +#define ktla_ktva(addr) (addr)
11097 +#define ktva_ktla(addr) (addr)
11098 +#endif
11099 +
11100 #define MODULES_VADDR VMALLOC_START
11101 #define MODULES_END VMALLOC_END
11102 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11103 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11104 index 975f709..107976d 100644
11105 --- a/arch/x86/include/asm/pgtable_64.h
11106 +++ b/arch/x86/include/asm/pgtable_64.h
11107 @@ -16,10 +16,14 @@
11108
11109 extern pud_t level3_kernel_pgt[512];
11110 extern pud_t level3_ident_pgt[512];
11111 +extern pud_t level3_vmalloc_start_pgt[512];
11112 +extern pud_t level3_vmalloc_end_pgt[512];
11113 +extern pud_t level3_vmemmap_pgt[512];
11114 +extern pud_t level2_vmemmap_pgt[512];
11115 extern pmd_t level2_kernel_pgt[512];
11116 extern pmd_t level2_fixmap_pgt[512];
11117 -extern pmd_t level2_ident_pgt[512];
11118 -extern pgd_t init_level4_pgt[];
11119 +extern pmd_t level2_ident_pgt[512*2];
11120 +extern pgd_t init_level4_pgt[512];
11121
11122 #define swapper_pg_dir init_level4_pgt
11123
11124 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11125
11126 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11127 {
11128 + pax_open_kernel();
11129 *pmdp = pmd;
11130 + pax_close_kernel();
11131 }
11132
11133 static inline void native_pmd_clear(pmd_t *pmd)
11134 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11135
11136 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11137 {
11138 + pax_open_kernel();
11139 + *pgdp = pgd;
11140 + pax_close_kernel();
11141 +}
11142 +
11143 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11144 +{
11145 *pgdp = pgd;
11146 }
11147
11148 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11149 index 766ea16..5b96cb3 100644
11150 --- a/arch/x86/include/asm/pgtable_64_types.h
11151 +++ b/arch/x86/include/asm/pgtable_64_types.h
11152 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11153 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11154 #define MODULES_END _AC(0xffffffffff000000, UL)
11155 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11156 +#define MODULES_EXEC_VADDR MODULES_VADDR
11157 +#define MODULES_EXEC_END MODULES_END
11158 +
11159 +#define ktla_ktva(addr) (addr)
11160 +#define ktva_ktla(addr) (addr)
11161
11162 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11163 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11164 index 013286a..8b42f4f 100644
11165 --- a/arch/x86/include/asm/pgtable_types.h
11166 +++ b/arch/x86/include/asm/pgtable_types.h
11167 @@ -16,13 +16,12 @@
11168 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11169 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11170 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11171 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11172 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11173 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11174 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11175 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11176 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11177 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11178 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11179 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11180 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11181 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11182
11183 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11184 @@ -40,7 +39,6 @@
11185 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11186 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11187 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11188 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11189 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11190 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11191 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11192 @@ -57,8 +55,10 @@
11193
11194 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11195 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11196 -#else
11197 +#elif defined(CONFIG_KMEMCHECK)
11198 #define _PAGE_NX (_AT(pteval_t, 0))
11199 +#else
11200 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11201 #endif
11202
11203 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11204 @@ -96,6 +96,9 @@
11205 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11206 _PAGE_ACCESSED)
11207
11208 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11209 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11210 +
11211 #define __PAGE_KERNEL_EXEC \
11212 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11213 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11214 @@ -106,7 +109,7 @@
11215 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11216 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11217 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11218 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11219 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11220 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11221 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11222 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11223 @@ -168,8 +171,8 @@
11224 * bits are combined, this will alow user to access the high address mapped
11225 * VDSO in the presence of CONFIG_COMPAT_VDSO
11226 */
11227 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11228 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11229 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11230 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11231 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11232 #endif
11233
11234 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11235 {
11236 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11237 }
11238 +#endif
11239
11240 +#if PAGETABLE_LEVELS == 3
11241 +#include <asm-generic/pgtable-nopud.h>
11242 +#endif
11243 +
11244 +#if PAGETABLE_LEVELS == 2
11245 +#include <asm-generic/pgtable-nopmd.h>
11246 +#endif
11247 +
11248 +#ifndef __ASSEMBLY__
11249 #if PAGETABLE_LEVELS > 3
11250 typedef struct { pudval_t pud; } pud_t;
11251
11252 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11253 return pud.pud;
11254 }
11255 #else
11256 -#include <asm-generic/pgtable-nopud.h>
11257 -
11258 static inline pudval_t native_pud_val(pud_t pud)
11259 {
11260 return native_pgd_val(pud.pgd);
11261 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11262 return pmd.pmd;
11263 }
11264 #else
11265 -#include <asm-generic/pgtable-nopmd.h>
11266 -
11267 static inline pmdval_t native_pmd_val(pmd_t pmd)
11268 {
11269 return native_pgd_val(pmd.pud.pgd);
11270 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11271
11272 extern pteval_t __supported_pte_mask;
11273 extern void set_nx(void);
11274 -extern int nx_enabled;
11275
11276 #define pgprot_writecombine pgprot_writecombine
11277 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11278 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11279 index 58545c9..fe6fc38e 100644
11280 --- a/arch/x86/include/asm/processor.h
11281 +++ b/arch/x86/include/asm/processor.h
11282 @@ -266,7 +266,7 @@ struct tss_struct {
11283
11284 } ____cacheline_aligned;
11285
11286 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11287 +extern struct tss_struct init_tss[NR_CPUS];
11288
11289 /*
11290 * Save the original ist values for checking stack pointers during debugging
11291 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11292 */
11293 #define TASK_SIZE PAGE_OFFSET
11294 #define TASK_SIZE_MAX TASK_SIZE
11295 +
11296 +#ifdef CONFIG_PAX_SEGMEXEC
11297 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11298 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11299 +#else
11300 #define STACK_TOP TASK_SIZE
11301 -#define STACK_TOP_MAX STACK_TOP
11302 +#endif
11303 +
11304 +#define STACK_TOP_MAX TASK_SIZE
11305
11306 #define INIT_THREAD { \
11307 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11308 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11309 .vm86_info = NULL, \
11310 .sysenter_cs = __KERNEL_CS, \
11311 .io_bitmap_ptr = NULL, \
11312 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11313 */
11314 #define INIT_TSS { \
11315 .x86_tss = { \
11316 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11317 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11318 .ss0 = __KERNEL_DS, \
11319 .ss1 = __KERNEL_CS, \
11320 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11321 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11322 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11323
11324 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11325 -#define KSTK_TOP(info) \
11326 -({ \
11327 - unsigned long *__ptr = (unsigned long *)(info); \
11328 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11329 -})
11330 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11331
11332 /*
11333 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11334 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11335 #define task_pt_regs(task) \
11336 ({ \
11337 struct pt_regs *__regs__; \
11338 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11339 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11340 __regs__ - 1; \
11341 })
11342
11343 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11344 /*
11345 * User space process size. 47bits minus one guard page.
11346 */
11347 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11348 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11349
11350 /* This decides where the kernel will search for a free chunk of vm
11351 * space during mmap's.
11352 */
11353 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11354 - 0xc0000000 : 0xFFFFe000)
11355 + 0xc0000000 : 0xFFFFf000)
11356
11357 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11358 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11359 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11360 #define STACK_TOP_MAX TASK_SIZE_MAX
11361
11362 #define INIT_THREAD { \
11363 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11364 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11365 }
11366
11367 #define INIT_TSS { \
11368 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11369 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11370 }
11371
11372 /*
11373 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11374 */
11375 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11376
11377 +#ifdef CONFIG_PAX_SEGMEXEC
11378 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11379 +#endif
11380 +
11381 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11382
11383 /* Get/set a process' ability to use the timestamp counter instruction */
11384 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11385 index 3566454..4bdfb8c 100644
11386 --- a/arch/x86/include/asm/ptrace.h
11387 +++ b/arch/x86/include/asm/ptrace.h
11388 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11389 }
11390
11391 /*
11392 - * user_mode_vm(regs) determines whether a register set came from user mode.
11393 + * user_mode(regs) determines whether a register set came from user mode.
11394 * This is true if V8086 mode was enabled OR if the register set was from
11395 * protected mode with RPL-3 CS value. This tricky test checks that with
11396 * one comparison. Many places in the kernel can bypass this full check
11397 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11398 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11399 + * be used.
11400 */
11401 -static inline int user_mode(struct pt_regs *regs)
11402 +static inline int user_mode_novm(struct pt_regs *regs)
11403 {
11404 #ifdef CONFIG_X86_32
11405 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11406 #else
11407 - return !!(regs->cs & 3);
11408 + return !!(regs->cs & SEGMENT_RPL_MASK);
11409 #endif
11410 }
11411
11412 -static inline int user_mode_vm(struct pt_regs *regs)
11413 +static inline int user_mode(struct pt_regs *regs)
11414 {
11415 #ifdef CONFIG_X86_32
11416 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11417 USER_RPL;
11418 #else
11419 - return user_mode(regs);
11420 + return user_mode_novm(regs);
11421 #endif
11422 }
11423
11424 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11425 #ifdef CONFIG_X86_64
11426 static inline bool user_64bit_mode(struct pt_regs *regs)
11427 {
11428 + unsigned long cs = regs->cs & 0xffff;
11429 #ifndef CONFIG_PARAVIRT
11430 /*
11431 * On non-paravirt systems, this is the only long mode CPL 3
11432 * selector. We do not allow long mode selectors in the LDT.
11433 */
11434 - return regs->cs == __USER_CS;
11435 + return cs == __USER_CS;
11436 #else
11437 /* Headers are too twisted for this to go in paravirt.h. */
11438 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11439 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11440 #endif
11441 }
11442 #endif
11443 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11444 index 92f29706..a79cbbb 100644
11445 --- a/arch/x86/include/asm/reboot.h
11446 +++ b/arch/x86/include/asm/reboot.h
11447 @@ -6,19 +6,19 @@
11448 struct pt_regs;
11449
11450 struct machine_ops {
11451 - void (*restart)(char *cmd);
11452 - void (*halt)(void);
11453 - void (*power_off)(void);
11454 + void (* __noreturn restart)(char *cmd);
11455 + void (* __noreturn halt)(void);
11456 + void (* __noreturn power_off)(void);
11457 void (*shutdown)(void);
11458 void (*crash_shutdown)(struct pt_regs *);
11459 - void (*emergency_restart)(void);
11460 -};
11461 + void (* __noreturn emergency_restart)(void);
11462 +} __no_const;
11463
11464 extern struct machine_ops machine_ops;
11465
11466 void native_machine_crash_shutdown(struct pt_regs *regs);
11467 void native_machine_shutdown(void);
11468 -void machine_real_restart(unsigned int type);
11469 +void machine_real_restart(unsigned int type) __noreturn;
11470 /* These must match dispatch_table in reboot_32.S */
11471 #define MRR_BIOS 0
11472 #define MRR_APM 1
11473 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11474 index 2dbe4a7..ce1db00 100644
11475 --- a/arch/x86/include/asm/rwsem.h
11476 +++ b/arch/x86/include/asm/rwsem.h
11477 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11478 {
11479 asm volatile("# beginning down_read\n\t"
11480 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11481 +
11482 +#ifdef CONFIG_PAX_REFCOUNT
11483 + "jno 0f\n"
11484 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11485 + "int $4\n0:\n"
11486 + _ASM_EXTABLE(0b, 0b)
11487 +#endif
11488 +
11489 /* adds 0x00000001 */
11490 " jns 1f\n"
11491 " call call_rwsem_down_read_failed\n"
11492 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11493 "1:\n\t"
11494 " mov %1,%2\n\t"
11495 " add %3,%2\n\t"
11496 +
11497 +#ifdef CONFIG_PAX_REFCOUNT
11498 + "jno 0f\n"
11499 + "sub %3,%2\n"
11500 + "int $4\n0:\n"
11501 + _ASM_EXTABLE(0b, 0b)
11502 +#endif
11503 +
11504 " jle 2f\n\t"
11505 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11506 " jnz 1b\n\t"
11507 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11508 long tmp;
11509 asm volatile("# beginning down_write\n\t"
11510 LOCK_PREFIX " xadd %1,(%2)\n\t"
11511 +
11512 +#ifdef CONFIG_PAX_REFCOUNT
11513 + "jno 0f\n"
11514 + "mov %1,(%2)\n"
11515 + "int $4\n0:\n"
11516 + _ASM_EXTABLE(0b, 0b)
11517 +#endif
11518 +
11519 /* adds 0xffff0001, returns the old value */
11520 " test %1,%1\n\t"
11521 /* was the count 0 before? */
11522 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11523 long tmp;
11524 asm volatile("# beginning __up_read\n\t"
11525 LOCK_PREFIX " xadd %1,(%2)\n\t"
11526 +
11527 +#ifdef CONFIG_PAX_REFCOUNT
11528 + "jno 0f\n"
11529 + "mov %1,(%2)\n"
11530 + "int $4\n0:\n"
11531 + _ASM_EXTABLE(0b, 0b)
11532 +#endif
11533 +
11534 /* subtracts 1, returns the old value */
11535 " jns 1f\n\t"
11536 " call call_rwsem_wake\n" /* expects old value in %edx */
11537 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11538 long tmp;
11539 asm volatile("# beginning __up_write\n\t"
11540 LOCK_PREFIX " xadd %1,(%2)\n\t"
11541 +
11542 +#ifdef CONFIG_PAX_REFCOUNT
11543 + "jno 0f\n"
11544 + "mov %1,(%2)\n"
11545 + "int $4\n0:\n"
11546 + _ASM_EXTABLE(0b, 0b)
11547 +#endif
11548 +
11549 /* subtracts 0xffff0001, returns the old value */
11550 " jns 1f\n\t"
11551 " call call_rwsem_wake\n" /* expects old value in %edx */
11552 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11553 {
11554 asm volatile("# beginning __downgrade_write\n\t"
11555 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11556 +
11557 +#ifdef CONFIG_PAX_REFCOUNT
11558 + "jno 0f\n"
11559 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11560 + "int $4\n0:\n"
11561 + _ASM_EXTABLE(0b, 0b)
11562 +#endif
11563 +
11564 /*
11565 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11566 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11567 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11568 */
11569 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11570 {
11571 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11572 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11573 +
11574 +#ifdef CONFIG_PAX_REFCOUNT
11575 + "jno 0f\n"
11576 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11577 + "int $4\n0:\n"
11578 + _ASM_EXTABLE(0b, 0b)
11579 +#endif
11580 +
11581 : "+m" (sem->count)
11582 : "er" (delta));
11583 }
11584 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11585 */
11586 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11587 {
11588 - return delta + xadd(&sem->count, delta);
11589 + return delta + xadd_check_overflow(&sem->count, delta);
11590 }
11591
11592 #endif /* __KERNEL__ */
11593 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11594 index 5e64171..f58957e 100644
11595 --- a/arch/x86/include/asm/segment.h
11596 +++ b/arch/x86/include/asm/segment.h
11597 @@ -64,10 +64,15 @@
11598 * 26 - ESPFIX small SS
11599 * 27 - per-cpu [ offset to per-cpu data area ]
11600 * 28 - stack_canary-20 [ for stack protector ]
11601 - * 29 - unused
11602 - * 30 - unused
11603 + * 29 - PCI BIOS CS
11604 + * 30 - PCI BIOS DS
11605 * 31 - TSS for double fault handler
11606 */
11607 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11608 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11609 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11610 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11611 +
11612 #define GDT_ENTRY_TLS_MIN 6
11613 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11614
11615 @@ -79,6 +84,8 @@
11616
11617 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11618
11619 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11620 +
11621 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11622
11623 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11624 @@ -104,6 +111,12 @@
11625 #define __KERNEL_STACK_CANARY 0
11626 #endif
11627
11628 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11629 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11630 +
11631 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11632 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11633 +
11634 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11635
11636 /*
11637 @@ -141,7 +154,7 @@
11638 */
11639
11640 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11641 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11642 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11643
11644
11645 #else
11646 @@ -165,6 +178,8 @@
11647 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11648 #define __USER32_DS __USER_DS
11649
11650 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11651 +
11652 #define GDT_ENTRY_TSS 8 /* needs two entries */
11653 #define GDT_ENTRY_LDT 10 /* needs two entries */
11654 #define GDT_ENTRY_TLS_MIN 12
11655 @@ -185,6 +200,7 @@
11656 #endif
11657
11658 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11659 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11660 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11661 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11662 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11663 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11664 index 0434c40..1714bf0 100644
11665 --- a/arch/x86/include/asm/smp.h
11666 +++ b/arch/x86/include/asm/smp.h
11667 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11668 /* cpus sharing the last level cache: */
11669 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11670 DECLARE_PER_CPU(u16, cpu_llc_id);
11671 -DECLARE_PER_CPU(int, cpu_number);
11672 +DECLARE_PER_CPU(unsigned int, cpu_number);
11673
11674 static inline struct cpumask *cpu_sibling_mask(int cpu)
11675 {
11676 @@ -77,7 +77,7 @@ struct smp_ops {
11677
11678 void (*send_call_func_ipi)(const struct cpumask *mask);
11679 void (*send_call_func_single_ipi)(int cpu);
11680 -};
11681 +} __no_const;
11682
11683 /* Globals due to paravirt */
11684 extern void set_cpu_sibling_map(int cpu);
11685 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11686 extern int safe_smp_processor_id(void);
11687
11688 #elif defined(CONFIG_X86_64_SMP)
11689 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11690 -
11691 -#define stack_smp_processor_id() \
11692 -({ \
11693 - struct thread_info *ti; \
11694 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11695 - ti->cpu; \
11696 -})
11697 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11698 +#define stack_smp_processor_id() raw_smp_processor_id()
11699 #define safe_smp_processor_id() smp_processor_id()
11700
11701 #endif
11702 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11703 index a82c2bf..2198f61 100644
11704 --- a/arch/x86/include/asm/spinlock.h
11705 +++ b/arch/x86/include/asm/spinlock.h
11706 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11707 static inline void arch_read_lock(arch_rwlock_t *rw)
11708 {
11709 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11710 +
11711 +#ifdef CONFIG_PAX_REFCOUNT
11712 + "jno 0f\n"
11713 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11714 + "int $4\n0:\n"
11715 + _ASM_EXTABLE(0b, 0b)
11716 +#endif
11717 +
11718 "jns 1f\n"
11719 "call __read_lock_failed\n\t"
11720 "1:\n"
11721 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11722 static inline void arch_write_lock(arch_rwlock_t *rw)
11723 {
11724 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11725 +
11726 +#ifdef CONFIG_PAX_REFCOUNT
11727 + "jno 0f\n"
11728 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11729 + "int $4\n0:\n"
11730 + _ASM_EXTABLE(0b, 0b)
11731 +#endif
11732 +
11733 "jz 1f\n"
11734 "call __write_lock_failed\n\t"
11735 "1:\n"
11736 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11737
11738 static inline void arch_read_unlock(arch_rwlock_t *rw)
11739 {
11740 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11741 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11742 +
11743 +#ifdef CONFIG_PAX_REFCOUNT
11744 + "jno 0f\n"
11745 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11746 + "int $4\n0:\n"
11747 + _ASM_EXTABLE(0b, 0b)
11748 +#endif
11749 +
11750 :"+m" (rw->lock) : : "memory");
11751 }
11752
11753 static inline void arch_write_unlock(arch_rwlock_t *rw)
11754 {
11755 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11756 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11757 +
11758 +#ifdef CONFIG_PAX_REFCOUNT
11759 + "jno 0f\n"
11760 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11761 + "int $4\n0:\n"
11762 + _ASM_EXTABLE(0b, 0b)
11763 +#endif
11764 +
11765 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11766 }
11767
11768 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11769 index 1575177..cb23f52 100644
11770 --- a/arch/x86/include/asm/stackprotector.h
11771 +++ b/arch/x86/include/asm/stackprotector.h
11772 @@ -48,7 +48,7 @@
11773 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11774 */
11775 #define GDT_STACK_CANARY_INIT \
11776 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11777 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11778
11779 /*
11780 * Initialize the stackprotector canary value.
11781 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11782
11783 static inline void load_stack_canary_segment(void)
11784 {
11785 -#ifdef CONFIG_X86_32
11786 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11787 asm volatile ("mov %0, %%gs" : : "r" (0));
11788 #endif
11789 }
11790 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11791 index 70bbe39..4ae2bd4 100644
11792 --- a/arch/x86/include/asm/stacktrace.h
11793 +++ b/arch/x86/include/asm/stacktrace.h
11794 @@ -11,28 +11,20 @@
11795
11796 extern int kstack_depth_to_print;
11797
11798 -struct thread_info;
11799 +struct task_struct;
11800 struct stacktrace_ops;
11801
11802 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11803 - unsigned long *stack,
11804 - unsigned long bp,
11805 - const struct stacktrace_ops *ops,
11806 - void *data,
11807 - unsigned long *end,
11808 - int *graph);
11809 +typedef unsigned long walk_stack_t(struct task_struct *task,
11810 + void *stack_start,
11811 + unsigned long *stack,
11812 + unsigned long bp,
11813 + const struct stacktrace_ops *ops,
11814 + void *data,
11815 + unsigned long *end,
11816 + int *graph);
11817
11818 -extern unsigned long
11819 -print_context_stack(struct thread_info *tinfo,
11820 - unsigned long *stack, unsigned long bp,
11821 - const struct stacktrace_ops *ops, void *data,
11822 - unsigned long *end, int *graph);
11823 -
11824 -extern unsigned long
11825 -print_context_stack_bp(struct thread_info *tinfo,
11826 - unsigned long *stack, unsigned long bp,
11827 - const struct stacktrace_ops *ops, void *data,
11828 - unsigned long *end, int *graph);
11829 +extern walk_stack_t print_context_stack;
11830 +extern walk_stack_t print_context_stack_bp;
11831
11832 /* Generic stack tracer with callbacks */
11833
11834 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11835 void (*address)(void *data, unsigned long address, int reliable);
11836 /* On negative return stop dumping */
11837 int (*stack)(void *data, char *name);
11838 - walk_stack_t walk_stack;
11839 + walk_stack_t *walk_stack;
11840 };
11841
11842 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11843 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11844 index cb23852..2dde194 100644
11845 --- a/arch/x86/include/asm/sys_ia32.h
11846 +++ b/arch/x86/include/asm/sys_ia32.h
11847 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11848 compat_sigset_t __user *, unsigned int);
11849 asmlinkage long sys32_alarm(unsigned int);
11850
11851 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11852 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11853 asmlinkage long sys32_sysfs(int, u32, u32);
11854
11855 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11856 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
11857 index f1d8b44..a4de8b7 100644
11858 --- a/arch/x86/include/asm/syscalls.h
11859 +++ b/arch/x86/include/asm/syscalls.h
11860 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
11861 void __user *, struct pt_regs *);
11862
11863 /* kernel/ldt.c */
11864 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
11865 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
11866
11867 /* kernel/signal.c */
11868 long sys_rt_sigreturn(struct pt_regs *);
11869 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11870 index 2d2f01c..f985723 100644
11871 --- a/arch/x86/include/asm/system.h
11872 +++ b/arch/x86/include/asm/system.h
11873 @@ -129,7 +129,7 @@ do { \
11874 "call __switch_to\n\t" \
11875 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11876 __switch_canary \
11877 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11878 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11879 "movq %%rax,%%rdi\n\t" \
11880 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11881 "jnz ret_from_fork\n\t" \
11882 @@ -140,7 +140,7 @@ do { \
11883 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11884 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11885 [_tif_fork] "i" (_TIF_FORK), \
11886 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11887 + [thread_info] "m" (current_tinfo), \
11888 [current_task] "m" (current_task) \
11889 __switch_canary_iparam \
11890 : "memory", "cc" __EXTRA_CLOBBER)
11891 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11892 {
11893 unsigned long __limit;
11894 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11895 - return __limit + 1;
11896 + return __limit;
11897 }
11898
11899 static inline void native_clts(void)
11900 @@ -397,13 +397,13 @@ void enable_hlt(void);
11901
11902 void cpu_idle_wait(void);
11903
11904 -extern unsigned long arch_align_stack(unsigned long sp);
11905 +#define arch_align_stack(x) ((x) & ~0xfUL)
11906 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11907
11908 void default_idle(void);
11909 bool set_pm_idle_to_default(void);
11910
11911 -void stop_this_cpu(void *dummy);
11912 +void stop_this_cpu(void *dummy) __noreturn;
11913
11914 /*
11915 * Force strict CPU ordering.
11916 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11917 index cfd8144..1b1127d 100644
11918 --- a/arch/x86/include/asm/thread_info.h
11919 +++ b/arch/x86/include/asm/thread_info.h
11920 @@ -10,6 +10,7 @@
11921 #include <linux/compiler.h>
11922 #include <asm/page.h>
11923 #include <asm/types.h>
11924 +#include <asm/percpu.h>
11925
11926 /*
11927 * low level task data that entry.S needs immediate access to
11928 @@ -24,7 +25,6 @@ struct exec_domain;
11929 #include <linux/atomic.h>
11930
11931 struct thread_info {
11932 - struct task_struct *task; /* main task structure */
11933 struct exec_domain *exec_domain; /* execution domain */
11934 __u32 flags; /* low level flags */
11935 __u32 status; /* thread synchronous flags */
11936 @@ -34,19 +34,13 @@ struct thread_info {
11937 mm_segment_t addr_limit;
11938 struct restart_block restart_block;
11939 void __user *sysenter_return;
11940 -#ifdef CONFIG_X86_32
11941 - unsigned long previous_esp; /* ESP of the previous stack in
11942 - case of nested (IRQ) stacks
11943 - */
11944 - __u8 supervisor_stack[0];
11945 -#endif
11946 + unsigned long lowest_stack;
11947 unsigned int sig_on_uaccess_error:1;
11948 unsigned int uaccess_err:1; /* uaccess failed */
11949 };
11950
11951 -#define INIT_THREAD_INFO(tsk) \
11952 +#define INIT_THREAD_INFO \
11953 { \
11954 - .task = &tsk, \
11955 .exec_domain = &default_exec_domain, \
11956 .flags = 0, \
11957 .cpu = 0, \
11958 @@ -57,7 +51,7 @@ struct thread_info {
11959 }, \
11960 }
11961
11962 -#define init_thread_info (init_thread_union.thread_info)
11963 +#define init_thread_info (init_thread_union.stack)
11964 #define init_stack (init_thread_union.stack)
11965
11966 #else /* !__ASSEMBLY__ */
11967 @@ -169,45 +163,40 @@ struct thread_info {
11968 ret; \
11969 })
11970
11971 -#ifdef CONFIG_X86_32
11972 -
11973 -#define STACK_WARN (THREAD_SIZE/8)
11974 -/*
11975 - * macros/functions for gaining access to the thread information structure
11976 - *
11977 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11978 - */
11979 -#ifndef __ASSEMBLY__
11980 -
11981 -
11982 -/* how to get the current stack pointer from C */
11983 -register unsigned long current_stack_pointer asm("esp") __used;
11984 -
11985 -/* how to get the thread information struct from C */
11986 -static inline struct thread_info *current_thread_info(void)
11987 -{
11988 - return (struct thread_info *)
11989 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11990 -}
11991 -
11992 -#else /* !__ASSEMBLY__ */
11993 -
11994 +#ifdef __ASSEMBLY__
11995 /* how to get the thread information struct from ASM */
11996 #define GET_THREAD_INFO(reg) \
11997 - movl $-THREAD_SIZE, reg; \
11998 - andl %esp, reg
11999 + mov PER_CPU_VAR(current_tinfo), reg
12000
12001 /* use this one if reg already contains %esp */
12002 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12003 - andl $-THREAD_SIZE, reg
12004 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12005 +#else
12006 +/* how to get the thread information struct from C */
12007 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12008 +
12009 +static __always_inline struct thread_info *current_thread_info(void)
12010 +{
12011 + return percpu_read_stable(current_tinfo);
12012 +}
12013 +#endif
12014 +
12015 +#ifdef CONFIG_X86_32
12016 +
12017 +#define STACK_WARN (THREAD_SIZE/8)
12018 +/*
12019 + * macros/functions for gaining access to the thread information structure
12020 + *
12021 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12022 + */
12023 +#ifndef __ASSEMBLY__
12024 +
12025 +/* how to get the current stack pointer from C */
12026 +register unsigned long current_stack_pointer asm("esp") __used;
12027
12028 #endif
12029
12030 #else /* X86_32 */
12031
12032 -#include <asm/percpu.h>
12033 -#define KERNEL_STACK_OFFSET (5*8)
12034 -
12035 /*
12036 * macros/functions for gaining access to the thread information structure
12037 * preempt_count needs to be 1 initially, until the scheduler is functional.
12038 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
12039 #ifndef __ASSEMBLY__
12040 DECLARE_PER_CPU(unsigned long, kernel_stack);
12041
12042 -static inline struct thread_info *current_thread_info(void)
12043 -{
12044 - struct thread_info *ti;
12045 - ti = (void *)(percpu_read_stable(kernel_stack) +
12046 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12047 - return ti;
12048 -}
12049 -
12050 -#else /* !__ASSEMBLY__ */
12051 -
12052 -/* how to get the thread information struct from ASM */
12053 -#define GET_THREAD_INFO(reg) \
12054 - movq PER_CPU_VAR(kernel_stack),reg ; \
12055 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12056 -
12057 -/*
12058 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12059 - * a certain register (to be used in assembler memory operands).
12060 - */
12061 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12062 -
12063 +/* how to get the current stack pointer from C */
12064 +register unsigned long current_stack_pointer asm("rsp") __used;
12065 #endif
12066
12067 #endif /* !X86_32 */
12068 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
12069 extern void free_thread_info(struct thread_info *ti);
12070 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12071 #define arch_task_cache_init arch_task_cache_init
12072 +
12073 +#define __HAVE_THREAD_FUNCTIONS
12074 +#define task_thread_info(task) (&(task)->tinfo)
12075 +#define task_stack_page(task) ((task)->stack)
12076 +#define setup_thread_stack(p, org) do {} while (0)
12077 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12078 +
12079 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12080 +extern struct task_struct *alloc_task_struct_node(int node);
12081 +extern void free_task_struct(struct task_struct *);
12082 +
12083 #endif
12084 #endif /* _ASM_X86_THREAD_INFO_H */
12085 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12086 index 8be5f54..7ae826d 100644
12087 --- a/arch/x86/include/asm/uaccess.h
12088 +++ b/arch/x86/include/asm/uaccess.h
12089 @@ -7,12 +7,15 @@
12090 #include <linux/compiler.h>
12091 #include <linux/thread_info.h>
12092 #include <linux/string.h>
12093 +#include <linux/sched.h>
12094 #include <asm/asm.h>
12095 #include <asm/page.h>
12096
12097 #define VERIFY_READ 0
12098 #define VERIFY_WRITE 1
12099
12100 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12101 +
12102 /*
12103 * The fs value determines whether argument validity checking should be
12104 * performed or not. If get_fs() == USER_DS, checking is performed, with
12105 @@ -28,7 +31,12 @@
12106
12107 #define get_ds() (KERNEL_DS)
12108 #define get_fs() (current_thread_info()->addr_limit)
12109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12110 +void __set_fs(mm_segment_t x);
12111 +void set_fs(mm_segment_t x);
12112 +#else
12113 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12114 +#endif
12115
12116 #define segment_eq(a, b) ((a).seg == (b).seg)
12117
12118 @@ -76,7 +84,33 @@
12119 * checks that the pointer is in the user space range - after calling
12120 * this function, memory access functions may still return -EFAULT.
12121 */
12122 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12123 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12124 +#define access_ok(type, addr, size) \
12125 +({ \
12126 + long __size = size; \
12127 + unsigned long __addr = (unsigned long)addr; \
12128 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12129 + unsigned long __end_ao = __addr + __size - 1; \
12130 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12131 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12132 + while(__addr_ao <= __end_ao) { \
12133 + char __c_ao; \
12134 + __addr_ao += PAGE_SIZE; \
12135 + if (__size > PAGE_SIZE) \
12136 + cond_resched(); \
12137 + if (__get_user(__c_ao, (char __user *)__addr)) \
12138 + break; \
12139 + if (type != VERIFY_WRITE) { \
12140 + __addr = __addr_ao; \
12141 + continue; \
12142 + } \
12143 + if (__put_user(__c_ao, (char __user *)__addr)) \
12144 + break; \
12145 + __addr = __addr_ao; \
12146 + } \
12147 + } \
12148 + __ret_ao; \
12149 +})
12150
12151 /*
12152 * The exception table consists of pairs of addresses: the first is the
12153 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12154 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12155 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12156
12157 -
12158 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12159 +#define __copyuser_seg "gs;"
12160 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12161 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12162 +#else
12163 +#define __copyuser_seg
12164 +#define __COPYUSER_SET_ES
12165 +#define __COPYUSER_RESTORE_ES
12166 +#endif
12167
12168 #ifdef CONFIG_X86_32
12169 #define __put_user_asm_u64(x, addr, err, errret) \
12170 - asm volatile("1: movl %%eax,0(%2)\n" \
12171 - "2: movl %%edx,4(%2)\n" \
12172 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12173 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12174 "3:\n" \
12175 ".section .fixup,\"ax\"\n" \
12176 "4: movl %3,%0\n" \
12177 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12178 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12179
12180 #define __put_user_asm_ex_u64(x, addr) \
12181 - asm volatile("1: movl %%eax,0(%1)\n" \
12182 - "2: movl %%edx,4(%1)\n" \
12183 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12184 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12185 "3:\n" \
12186 _ASM_EXTABLE(1b, 2b - 1b) \
12187 _ASM_EXTABLE(2b, 3b - 2b) \
12188 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12189 __typeof__(*(ptr)) __pu_val; \
12190 __chk_user_ptr(ptr); \
12191 might_fault(); \
12192 - __pu_val = x; \
12193 + __pu_val = (x); \
12194 switch (sizeof(*(ptr))) { \
12195 case 1: \
12196 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12197 @@ -373,7 +415,7 @@ do { \
12198 } while (0)
12199
12200 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12201 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12202 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12203 "2:\n" \
12204 ".section .fixup,\"ax\"\n" \
12205 "3: mov %3,%0\n" \
12206 @@ -381,7 +423,7 @@ do { \
12207 " jmp 2b\n" \
12208 ".previous\n" \
12209 _ASM_EXTABLE(1b, 3b) \
12210 - : "=r" (err), ltype(x) \
12211 + : "=r" (err), ltype (x) \
12212 : "m" (__m(addr)), "i" (errret), "0" (err))
12213
12214 #define __get_user_size_ex(x, ptr, size) \
12215 @@ -406,7 +448,7 @@ do { \
12216 } while (0)
12217
12218 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12219 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12220 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12221 "2:\n" \
12222 _ASM_EXTABLE(1b, 2b - 1b) \
12223 : ltype(x) : "m" (__m(addr)))
12224 @@ -423,13 +465,24 @@ do { \
12225 int __gu_err; \
12226 unsigned long __gu_val; \
12227 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12228 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12229 + (x) = (__typeof__(*(ptr)))__gu_val; \
12230 __gu_err; \
12231 })
12232
12233 /* FIXME: this hack is definitely wrong -AK */
12234 struct __large_struct { unsigned long buf[100]; };
12235 -#define __m(x) (*(struct __large_struct __user *)(x))
12236 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12237 +#define ____m(x) \
12238 +({ \
12239 + unsigned long ____x = (unsigned long)(x); \
12240 + if (____x < PAX_USER_SHADOW_BASE) \
12241 + ____x += PAX_USER_SHADOW_BASE; \
12242 + (void __user *)____x; \
12243 +})
12244 +#else
12245 +#define ____m(x) (x)
12246 +#endif
12247 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12248
12249 /*
12250 * Tell gcc we read from memory instead of writing: this is because
12251 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12252 * aliasing issues.
12253 */
12254 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12255 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12256 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12257 "2:\n" \
12258 ".section .fixup,\"ax\"\n" \
12259 "3: mov %3,%0\n" \
12260 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12261 ".previous\n" \
12262 _ASM_EXTABLE(1b, 3b) \
12263 : "=r"(err) \
12264 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12265 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12266
12267 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12268 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12269 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12270 "2:\n" \
12271 _ASM_EXTABLE(1b, 2b - 1b) \
12272 : : ltype(x), "m" (__m(addr)))
12273 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12274 * On error, the variable @x is set to zero.
12275 */
12276
12277 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12278 +#define __get_user(x, ptr) get_user((x), (ptr))
12279 +#else
12280 #define __get_user(x, ptr) \
12281 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12282 +#endif
12283
12284 /**
12285 * __put_user: - Write a simple value into user space, with less checking.
12286 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12287 * Returns zero on success, or -EFAULT on error.
12288 */
12289
12290 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12291 +#define __put_user(x, ptr) put_user((x), (ptr))
12292 +#else
12293 #define __put_user(x, ptr) \
12294 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12295 +#endif
12296
12297 #define __get_user_unaligned __get_user
12298 #define __put_user_unaligned __put_user
12299 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12300 #define get_user_ex(x, ptr) do { \
12301 unsigned long __gue_val; \
12302 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12303 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12304 + (x) = (__typeof__(*(ptr)))__gue_val; \
12305 } while (0)
12306
12307 #ifdef CONFIG_X86_WP_WORKS_OK
12308 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12309 index 566e803..7183d0b 100644
12310 --- a/arch/x86/include/asm/uaccess_32.h
12311 +++ b/arch/x86/include/asm/uaccess_32.h
12312 @@ -11,15 +11,15 @@
12313 #include <asm/page.h>
12314
12315 unsigned long __must_check __copy_to_user_ll
12316 - (void __user *to, const void *from, unsigned long n);
12317 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12318 unsigned long __must_check __copy_from_user_ll
12319 - (void *to, const void __user *from, unsigned long n);
12320 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12321 unsigned long __must_check __copy_from_user_ll_nozero
12322 - (void *to, const void __user *from, unsigned long n);
12323 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12324 unsigned long __must_check __copy_from_user_ll_nocache
12325 - (void *to, const void __user *from, unsigned long n);
12326 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12327 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12328 - (void *to, const void __user *from, unsigned long n);
12329 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12330
12331 /**
12332 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12333 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12334 */
12335
12336 static __always_inline unsigned long __must_check
12337 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12338 +static __always_inline unsigned long __must_check
12339 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12340 {
12341 + if ((long)n < 0)
12342 + return n;
12343 +
12344 if (__builtin_constant_p(n)) {
12345 unsigned long ret;
12346
12347 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12348 return ret;
12349 }
12350 }
12351 + if (!__builtin_constant_p(n))
12352 + check_object_size(from, n, true);
12353 return __copy_to_user_ll(to, from, n);
12354 }
12355
12356 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12357 * On success, this will be zero.
12358 */
12359 static __always_inline unsigned long __must_check
12360 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12361 +static __always_inline unsigned long __must_check
12362 __copy_to_user(void __user *to, const void *from, unsigned long n)
12363 {
12364 might_fault();
12365 +
12366 return __copy_to_user_inatomic(to, from, n);
12367 }
12368
12369 static __always_inline unsigned long
12370 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12371 +static __always_inline unsigned long
12372 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12373 {
12374 + if ((long)n < 0)
12375 + return n;
12376 +
12377 /* Avoid zeroing the tail if the copy fails..
12378 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12379 * but as the zeroing behaviour is only significant when n is not
12380 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12381 * for explanation of why this is needed.
12382 */
12383 static __always_inline unsigned long
12384 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12385 +static __always_inline unsigned long
12386 __copy_from_user(void *to, const void __user *from, unsigned long n)
12387 {
12388 might_fault();
12389 +
12390 + if ((long)n < 0)
12391 + return n;
12392 +
12393 if (__builtin_constant_p(n)) {
12394 unsigned long ret;
12395
12396 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12397 return ret;
12398 }
12399 }
12400 + if (!__builtin_constant_p(n))
12401 + check_object_size(to, n, false);
12402 return __copy_from_user_ll(to, from, n);
12403 }
12404
12405 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12406 + const void __user *from, unsigned long n) __size_overflow(3);
12407 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12408 const void __user *from, unsigned long n)
12409 {
12410 might_fault();
12411 +
12412 + if ((long)n < 0)
12413 + return n;
12414 +
12415 if (__builtin_constant_p(n)) {
12416 unsigned long ret;
12417
12418 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12419
12420 static __always_inline unsigned long
12421 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12422 + unsigned long n) __size_overflow(3);
12423 +static __always_inline unsigned long
12424 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12425 unsigned long n)
12426 {
12427 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12428 + if ((long)n < 0)
12429 + return n;
12430 +
12431 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12432 }
12433
12434 -unsigned long __must_check copy_to_user(void __user *to,
12435 - const void *from, unsigned long n);
12436 -unsigned long __must_check _copy_from_user(void *to,
12437 - const void __user *from,
12438 - unsigned long n);
12439 -
12440 +extern void copy_to_user_overflow(void)
12441 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12442 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12443 +#else
12444 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12445 +#endif
12446 +;
12447
12448 extern void copy_from_user_overflow(void)
12449 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12450 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
12451 #endif
12452 ;
12453
12454 -static inline unsigned long __must_check copy_from_user(void *to,
12455 - const void __user *from,
12456 - unsigned long n)
12457 +/**
12458 + * copy_to_user: - Copy a block of data into user space.
12459 + * @to: Destination address, in user space.
12460 + * @from: Source address, in kernel space.
12461 + * @n: Number of bytes to copy.
12462 + *
12463 + * Context: User context only. This function may sleep.
12464 + *
12465 + * Copy data from kernel space to user space.
12466 + *
12467 + * Returns number of bytes that could not be copied.
12468 + * On success, this will be zero.
12469 + */
12470 +static inline unsigned long __must_check
12471 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12472 +static inline unsigned long __must_check
12473 +copy_to_user(void __user *to, const void *from, unsigned long n)
12474 +{
12475 + int sz = __compiletime_object_size(from);
12476 +
12477 + if (unlikely(sz != -1 && sz < n))
12478 + copy_to_user_overflow();
12479 + else if (access_ok(VERIFY_WRITE, to, n))
12480 + n = __copy_to_user(to, from, n);
12481 + return n;
12482 +}
12483 +
12484 +/**
12485 + * copy_from_user: - Copy a block of data from user space.
12486 + * @to: Destination address, in kernel space.
12487 + * @from: Source address, in user space.
12488 + * @n: Number of bytes to copy.
12489 + *
12490 + * Context: User context only. This function may sleep.
12491 + *
12492 + * Copy data from user space to kernel space.
12493 + *
12494 + * Returns number of bytes that could not be copied.
12495 + * On success, this will be zero.
12496 + *
12497 + * If some data could not be copied, this function will pad the copied
12498 + * data to the requested size using zero bytes.
12499 + */
12500 +static inline unsigned long __must_check
12501 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12502 +static inline unsigned long __must_check
12503 +copy_from_user(void *to, const void __user *from, unsigned long n)
12504 {
12505 int sz = __compiletime_object_size(to);
12506
12507 - if (likely(sz == -1 || sz >= n))
12508 - n = _copy_from_user(to, from, n);
12509 - else
12510 + if (unlikely(sz != -1 && sz < n))
12511 copy_from_user_overflow();
12512 -
12513 + else if (access_ok(VERIFY_READ, from, n))
12514 + n = __copy_from_user(to, from, n);
12515 + else if ((long)n > 0) {
12516 + if (!__builtin_constant_p(n))
12517 + check_object_size(to, n, false);
12518 + memset(to, 0, n);
12519 + }
12520 return n;
12521 }
12522
12523 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
12524 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12525
12526 long strnlen_user(const char __user *str, long n);
12527 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12528 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12529 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12530 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12531
12532 #endif /* _ASM_X86_UACCESS_32_H */
12533 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12534 index 1c66d30..e294b5f 100644
12535 --- a/arch/x86/include/asm/uaccess_64.h
12536 +++ b/arch/x86/include/asm/uaccess_64.h
12537 @@ -10,6 +10,9 @@
12538 #include <asm/alternative.h>
12539 #include <asm/cpufeature.h>
12540 #include <asm/page.h>
12541 +#include <asm/pgtable.h>
12542 +
12543 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12544
12545 /*
12546 * Copy To/From Userspace
12547 @@ -17,12 +20,14 @@
12548
12549 /* Handles exceptions in both to and from, but doesn't do access_ok */
12550 __must_check unsigned long
12551 -copy_user_generic_string(void *to, const void *from, unsigned len);
12552 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12553 __must_check unsigned long
12554 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12555 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12556
12557 static __always_inline __must_check unsigned long
12558 -copy_user_generic(void *to, const void *from, unsigned len)
12559 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12560 +static __always_inline __must_check unsigned long
12561 +copy_user_generic(void *to, const void *from, unsigned long len)
12562 {
12563 unsigned ret;
12564
12565 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12566 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12567 "=d" (len)),
12568 "1" (to), "2" (from), "3" (len)
12569 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12570 + : "memory", "rcx", "r8", "r9", "r11");
12571 return ret;
12572 }
12573
12574 +static __always_inline __must_check unsigned long
12575 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12576 +static __always_inline __must_check unsigned long
12577 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12578 __must_check unsigned long
12579 -_copy_to_user(void __user *to, const void *from, unsigned len);
12580 -__must_check unsigned long
12581 -_copy_from_user(void *to, const void __user *from, unsigned len);
12582 -__must_check unsigned long
12583 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12584 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12585
12586 static inline unsigned long __must_check copy_from_user(void *to,
12587 const void __user *from,
12588 + unsigned long n) __size_overflow(3);
12589 +static inline unsigned long __must_check copy_from_user(void *to,
12590 + const void __user *from,
12591 unsigned long n)
12592 {
12593 - int sz = __compiletime_object_size(to);
12594 -
12595 might_fault();
12596 - if (likely(sz == -1 || sz >= n))
12597 - n = _copy_from_user(to, from, n);
12598 -#ifdef CONFIG_DEBUG_VM
12599 - else
12600 - WARN(1, "Buffer overflow detected!\n");
12601 -#endif
12602 +
12603 + if (access_ok(VERIFY_READ, from, n))
12604 + n = __copy_from_user(to, from, n);
12605 + else if (n < INT_MAX) {
12606 + if (!__builtin_constant_p(n))
12607 + check_object_size(to, n, false);
12608 + memset(to, 0, n);
12609 + }
12610 return n;
12611 }
12612
12613 static __always_inline __must_check
12614 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12615 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12616 +static __always_inline __must_check
12617 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12618 {
12619 might_fault();
12620
12621 - return _copy_to_user(dst, src, size);
12622 + if (access_ok(VERIFY_WRITE, dst, size))
12623 + size = __copy_to_user(dst, src, size);
12624 + return size;
12625 }
12626
12627 static __always_inline __must_check
12628 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12629 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12630 +static __always_inline __must_check
12631 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12632 {
12633 - int ret = 0;
12634 + int sz = __compiletime_object_size(dst);
12635 + unsigned ret = 0;
12636
12637 might_fault();
12638 - if (!__builtin_constant_p(size))
12639 - return copy_user_generic(dst, (__force void *)src, size);
12640 +
12641 + if (size > INT_MAX)
12642 + return size;
12643 +
12644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12645 + if (!__access_ok(VERIFY_READ, src, size))
12646 + return size;
12647 +#endif
12648 +
12649 + if (unlikely(sz != -1 && sz < size)) {
12650 +#ifdef CONFIG_DEBUG_VM
12651 + WARN(1, "Buffer overflow detected!\n");
12652 +#endif
12653 + return size;
12654 + }
12655 +
12656 + if (!__builtin_constant_p(size)) {
12657 + check_object_size(dst, size, false);
12658 +
12659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12660 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12661 + src += PAX_USER_SHADOW_BASE;
12662 +#endif
12663 +
12664 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12665 + }
12666 switch (size) {
12667 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12668 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12669 ret, "b", "b", "=q", 1);
12670 return ret;
12671 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12672 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12673 ret, "w", "w", "=r", 2);
12674 return ret;
12675 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12676 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12677 ret, "l", "k", "=r", 4);
12678 return ret;
12679 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12680 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12681 ret, "q", "", "=r", 8);
12682 return ret;
12683 case 10:
12684 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12685 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12686 ret, "q", "", "=r", 10);
12687 if (unlikely(ret))
12688 return ret;
12689 __get_user_asm(*(u16 *)(8 + (char *)dst),
12690 - (u16 __user *)(8 + (char __user *)src),
12691 + (const u16 __user *)(8 + (const char __user *)src),
12692 ret, "w", "w", "=r", 2);
12693 return ret;
12694 case 16:
12695 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12696 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12697 ret, "q", "", "=r", 16);
12698 if (unlikely(ret))
12699 return ret;
12700 __get_user_asm(*(u64 *)(8 + (char *)dst),
12701 - (u64 __user *)(8 + (char __user *)src),
12702 + (const u64 __user *)(8 + (const char __user *)src),
12703 ret, "q", "", "=r", 8);
12704 return ret;
12705 default:
12706 - return copy_user_generic(dst, (__force void *)src, size);
12707 +
12708 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12709 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12710 + src += PAX_USER_SHADOW_BASE;
12711 +#endif
12712 +
12713 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12714 }
12715 }
12716
12717 static __always_inline __must_check
12718 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12719 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12720 +static __always_inline __must_check
12721 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12722 {
12723 - int ret = 0;
12724 + int sz = __compiletime_object_size(src);
12725 + unsigned ret = 0;
12726
12727 might_fault();
12728 - if (!__builtin_constant_p(size))
12729 - return copy_user_generic((__force void *)dst, src, size);
12730 +
12731 + if (size > INT_MAX)
12732 + return size;
12733 +
12734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12735 + if (!__access_ok(VERIFY_WRITE, dst, size))
12736 + return size;
12737 +#endif
12738 +
12739 + if (unlikely(sz != -1 && sz < size)) {
12740 +#ifdef CONFIG_DEBUG_VM
12741 + WARN(1, "Buffer overflow detected!\n");
12742 +#endif
12743 + return size;
12744 + }
12745 +
12746 + if (!__builtin_constant_p(size)) {
12747 + check_object_size(src, size, true);
12748 +
12749 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12750 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12751 + dst += PAX_USER_SHADOW_BASE;
12752 +#endif
12753 +
12754 + return copy_user_generic((__force_kernel void *)dst, src, size);
12755 + }
12756 switch (size) {
12757 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12758 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12759 ret, "b", "b", "iq", 1);
12760 return ret;
12761 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12762 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12763 ret, "w", "w", "ir", 2);
12764 return ret;
12765 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12766 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12767 ret, "l", "k", "ir", 4);
12768 return ret;
12769 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12770 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12771 ret, "q", "", "er", 8);
12772 return ret;
12773 case 10:
12774 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12775 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12776 ret, "q", "", "er", 10);
12777 if (unlikely(ret))
12778 return ret;
12779 asm("":::"memory");
12780 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12781 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12782 ret, "w", "w", "ir", 2);
12783 return ret;
12784 case 16:
12785 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12786 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12787 ret, "q", "", "er", 16);
12788 if (unlikely(ret))
12789 return ret;
12790 asm("":::"memory");
12791 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12792 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12793 ret, "q", "", "er", 8);
12794 return ret;
12795 default:
12796 - return copy_user_generic((__force void *)dst, src, size);
12797 +
12798 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12799 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12800 + dst += PAX_USER_SHADOW_BASE;
12801 +#endif
12802 +
12803 + return copy_user_generic((__force_kernel void *)dst, src, size);
12804 }
12805 }
12806
12807 static __always_inline __must_check
12808 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12809 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
12810 +static __always_inline __must_check
12811 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12812 {
12813 - int ret = 0;
12814 + unsigned ret = 0;
12815
12816 might_fault();
12817 - if (!__builtin_constant_p(size))
12818 - return copy_user_generic((__force void *)dst,
12819 - (__force void *)src, size);
12820 +
12821 + if (size > INT_MAX)
12822 + return size;
12823 +
12824 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12825 + if (!__access_ok(VERIFY_READ, src, size))
12826 + return size;
12827 + if (!__access_ok(VERIFY_WRITE, dst, size))
12828 + return size;
12829 +#endif
12830 +
12831 + if (!__builtin_constant_p(size)) {
12832 +
12833 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12834 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12835 + src += PAX_USER_SHADOW_BASE;
12836 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12837 + dst += PAX_USER_SHADOW_BASE;
12838 +#endif
12839 +
12840 + return copy_user_generic((__force_kernel void *)dst,
12841 + (__force_kernel const void *)src, size);
12842 + }
12843 switch (size) {
12844 case 1: {
12845 u8 tmp;
12846 - __get_user_asm(tmp, (u8 __user *)src,
12847 + __get_user_asm(tmp, (const u8 __user *)src,
12848 ret, "b", "b", "=q", 1);
12849 if (likely(!ret))
12850 __put_user_asm(tmp, (u8 __user *)dst,
12851 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12852 }
12853 case 2: {
12854 u16 tmp;
12855 - __get_user_asm(tmp, (u16 __user *)src,
12856 + __get_user_asm(tmp, (const u16 __user *)src,
12857 ret, "w", "w", "=r", 2);
12858 if (likely(!ret))
12859 __put_user_asm(tmp, (u16 __user *)dst,
12860 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12861
12862 case 4: {
12863 u32 tmp;
12864 - __get_user_asm(tmp, (u32 __user *)src,
12865 + __get_user_asm(tmp, (const u32 __user *)src,
12866 ret, "l", "k", "=r", 4);
12867 if (likely(!ret))
12868 __put_user_asm(tmp, (u32 __user *)dst,
12869 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12870 }
12871 case 8: {
12872 u64 tmp;
12873 - __get_user_asm(tmp, (u64 __user *)src,
12874 + __get_user_asm(tmp, (const u64 __user *)src,
12875 ret, "q", "", "=r", 8);
12876 if (likely(!ret))
12877 __put_user_asm(tmp, (u64 __user *)dst,
12878 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12879 return ret;
12880 }
12881 default:
12882 - return copy_user_generic((__force void *)dst,
12883 - (__force void *)src, size);
12884 +
12885 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12886 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12887 + src += PAX_USER_SHADOW_BASE;
12888 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12889 + dst += PAX_USER_SHADOW_BASE;
12890 +#endif
12891 +
12892 + return copy_user_generic((__force_kernel void *)dst,
12893 + (__force_kernel const void *)src, size);
12894 }
12895 }
12896
12897 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
12898 __must_check long strnlen_user(const char __user *str, long n);
12899 __must_check long __strnlen_user(const char __user *str, long n);
12900 __must_check long strlen_user(const char __user *str);
12901 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
12902 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12903 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12904 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12905
12906 static __must_check __always_inline int
12907 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12908 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12909 +static __must_check __always_inline int
12910 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12911 {
12912 - return copy_user_generic(dst, (__force const void *)src, size);
12913 + if (size > INT_MAX)
12914 + return size;
12915 +
12916 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12917 + if (!__access_ok(VERIFY_READ, src, size))
12918 + return size;
12919 +
12920 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12921 + src += PAX_USER_SHADOW_BASE;
12922 +#endif
12923 +
12924 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12925 }
12926
12927 -static __must_check __always_inline int
12928 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12929 +static __must_check __always_inline unsigned long
12930 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12931 +static __must_check __always_inline unsigned long
12932 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12933 {
12934 - return copy_user_generic((__force void *)dst, src, size);
12935 + if (size > INT_MAX)
12936 + return size;
12937 +
12938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12939 + if (!__access_ok(VERIFY_WRITE, dst, size))
12940 + return size;
12941 +
12942 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12943 + dst += PAX_USER_SHADOW_BASE;
12944 +#endif
12945 +
12946 + return copy_user_generic((__force_kernel void *)dst, src, size);
12947 }
12948
12949 -extern long __copy_user_nocache(void *dst, const void __user *src,
12950 - unsigned size, int zerorest);
12951 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12952 + unsigned long size, int zerorest) __size_overflow(3);
12953
12954 -static inline int
12955 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12956 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12957 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12958 {
12959 might_sleep();
12960 +
12961 + if (size > INT_MAX)
12962 + return size;
12963 +
12964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12965 + if (!__access_ok(VERIFY_READ, src, size))
12966 + return size;
12967 +#endif
12968 +
12969 return __copy_user_nocache(dst, src, size, 1);
12970 }
12971
12972 -static inline int
12973 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12974 - unsigned size)
12975 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12976 + unsigned long size) __size_overflow(3);
12977 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12978 + unsigned long size)
12979 {
12980 + if (size > INT_MAX)
12981 + return size;
12982 +
12983 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12984 + if (!__access_ok(VERIFY_READ, src, size))
12985 + return size;
12986 +#endif
12987 +
12988 return __copy_user_nocache(dst, src, size, 0);
12989 }
12990
12991 -unsigned long
12992 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12993 +extern unsigned long
12994 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
12995
12996 #endif /* _ASM_X86_UACCESS_64_H */
12997 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12998 index bb05228..d763d5b 100644
12999 --- a/arch/x86/include/asm/vdso.h
13000 +++ b/arch/x86/include/asm/vdso.h
13001 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13002 #define VDSO32_SYMBOL(base, name) \
13003 ({ \
13004 extern const char VDSO32_##name[]; \
13005 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13006 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13007 })
13008 #endif
13009
13010 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13011 index 517d476..a1cb4d9 100644
13012 --- a/arch/x86/include/asm/x86_init.h
13013 +++ b/arch/x86/include/asm/x86_init.h
13014 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13015 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13016 void (*find_smp_config)(void);
13017 void (*get_smp_config)(unsigned int early);
13018 -};
13019 +} __no_const;
13020
13021 /**
13022 * struct x86_init_resources - platform specific resource related ops
13023 @@ -43,7 +43,7 @@ struct x86_init_resources {
13024 void (*probe_roms)(void);
13025 void (*reserve_resources)(void);
13026 char *(*memory_setup)(void);
13027 -};
13028 +} __no_const;
13029
13030 /**
13031 * struct x86_init_irqs - platform specific interrupt setup
13032 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13033 void (*pre_vector_init)(void);
13034 void (*intr_init)(void);
13035 void (*trap_init)(void);
13036 -};
13037 +} __no_const;
13038
13039 /**
13040 * struct x86_init_oem - oem platform specific customizing functions
13041 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13042 struct x86_init_oem {
13043 void (*arch_setup)(void);
13044 void (*banner)(void);
13045 -};
13046 +} __no_const;
13047
13048 /**
13049 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13050 @@ -77,7 +77,7 @@ struct x86_init_oem {
13051 */
13052 struct x86_init_mapping {
13053 void (*pagetable_reserve)(u64 start, u64 end);
13054 -};
13055 +} __no_const;
13056
13057 /**
13058 * struct x86_init_paging - platform specific paging functions
13059 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13060 struct x86_init_paging {
13061 void (*pagetable_setup_start)(pgd_t *base);
13062 void (*pagetable_setup_done)(pgd_t *base);
13063 -};
13064 +} __no_const;
13065
13066 /**
13067 * struct x86_init_timers - platform specific timer setup
13068 @@ -102,7 +102,7 @@ struct x86_init_timers {
13069 void (*tsc_pre_init)(void);
13070 void (*timer_init)(void);
13071 void (*wallclock_init)(void);
13072 -};
13073 +} __no_const;
13074
13075 /**
13076 * struct x86_init_iommu - platform specific iommu setup
13077 @@ -110,7 +110,7 @@ struct x86_init_timers {
13078 */
13079 struct x86_init_iommu {
13080 int (*iommu_init)(void);
13081 -};
13082 +} __no_const;
13083
13084 /**
13085 * struct x86_init_pci - platform specific pci init functions
13086 @@ -124,7 +124,7 @@ struct x86_init_pci {
13087 int (*init)(void);
13088 void (*init_irq)(void);
13089 void (*fixup_irqs)(void);
13090 -};
13091 +} __no_const;
13092
13093 /**
13094 * struct x86_init_ops - functions for platform specific setup
13095 @@ -140,7 +140,7 @@ struct x86_init_ops {
13096 struct x86_init_timers timers;
13097 struct x86_init_iommu iommu;
13098 struct x86_init_pci pci;
13099 -};
13100 +} __no_const;
13101
13102 /**
13103 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13104 @@ -149,7 +149,7 @@ struct x86_init_ops {
13105 struct x86_cpuinit_ops {
13106 void (*setup_percpu_clockev)(void);
13107 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13108 -};
13109 +} __no_const;
13110
13111 /**
13112 * struct x86_platform_ops - platform specific runtime functions
13113 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13114 void (*nmi_init)(void);
13115 unsigned char (*get_nmi_reason)(void);
13116 int (*i8042_detect)(void);
13117 -};
13118 +} __no_const;
13119
13120 struct pci_dev;
13121
13122 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13123 void (*teardown_msi_irq)(unsigned int irq);
13124 void (*teardown_msi_irqs)(struct pci_dev *dev);
13125 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13126 -};
13127 +} __no_const;
13128
13129 extern struct x86_init_ops x86_init;
13130 extern struct x86_cpuinit_ops x86_cpuinit;
13131 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13132 index c6ce245..ffbdab7 100644
13133 --- a/arch/x86/include/asm/xsave.h
13134 +++ b/arch/x86/include/asm/xsave.h
13135 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13136 {
13137 int err;
13138
13139 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13140 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13141 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13142 +#endif
13143 +
13144 /*
13145 * Clear the xsave header first, so that reserved fields are
13146 * initialized to zero.
13147 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13148 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13149 {
13150 int err;
13151 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13152 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13153 u32 lmask = mask;
13154 u32 hmask = mask >> 32;
13155
13156 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13157 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13158 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13159 +#endif
13160 +
13161 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13162 "2:\n"
13163 ".section .fixup,\"ax\"\n"
13164 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13165 index 6a564ac..9b1340c 100644
13166 --- a/arch/x86/kernel/acpi/realmode/Makefile
13167 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13168 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13169 $(call cc-option, -fno-stack-protector) \
13170 $(call cc-option, -mpreferred-stack-boundary=2)
13171 KBUILD_CFLAGS += $(call cc-option, -m32)
13172 +ifdef CONSTIFY_PLUGIN
13173 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13174 +endif
13175 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13176 GCOV_PROFILE := n
13177
13178 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13179 index b4fd836..4358fe3 100644
13180 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13181 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13182 @@ -108,6 +108,9 @@ wakeup_code:
13183 /* Do any other stuff... */
13184
13185 #ifndef CONFIG_64BIT
13186 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13187 + call verify_cpu
13188 +
13189 /* This could also be done in C code... */
13190 movl pmode_cr3, %eax
13191 movl %eax, %cr3
13192 @@ -131,6 +134,7 @@ wakeup_code:
13193 movl pmode_cr0, %eax
13194 movl %eax, %cr0
13195 jmp pmode_return
13196 +# include "../../verify_cpu.S"
13197 #else
13198 pushw $0
13199 pushw trampoline_segment
13200 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13201 index 103b6ab..2004d0a 100644
13202 --- a/arch/x86/kernel/acpi/sleep.c
13203 +++ b/arch/x86/kernel/acpi/sleep.c
13204 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13205 header->trampoline_segment = trampoline_address() >> 4;
13206 #ifdef CONFIG_SMP
13207 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13208 +
13209 + pax_open_kernel();
13210 early_gdt_descr.address =
13211 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13212 + pax_close_kernel();
13213 +
13214 initial_gs = per_cpu_offset(smp_processor_id());
13215 #endif
13216 initial_code = (unsigned long)wakeup_long64;
13217 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13218 index 13ab720..95d5442 100644
13219 --- a/arch/x86/kernel/acpi/wakeup_32.S
13220 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13221 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13222 # and restore the stack ... but you need gdt for this to work
13223 movl saved_context_esp, %esp
13224
13225 - movl %cs:saved_magic, %eax
13226 - cmpl $0x12345678, %eax
13227 + cmpl $0x12345678, saved_magic
13228 jne bogus_magic
13229
13230 # jump to place where we left off
13231 - movl saved_eip, %eax
13232 - jmp *%eax
13233 + jmp *(saved_eip)
13234
13235 bogus_magic:
13236 jmp bogus_magic
13237 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13238 index 1f84794..e23f862 100644
13239 --- a/arch/x86/kernel/alternative.c
13240 +++ b/arch/x86/kernel/alternative.c
13241 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13242 */
13243 for (a = start; a < end; a++) {
13244 instr = (u8 *)&a->instr_offset + a->instr_offset;
13245 +
13246 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13247 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13248 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13249 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13250 +#endif
13251 +
13252 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13253 BUG_ON(a->replacementlen > a->instrlen);
13254 BUG_ON(a->instrlen > sizeof(insnbuf));
13255 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13256 for (poff = start; poff < end; poff++) {
13257 u8 *ptr = (u8 *)poff + *poff;
13258
13259 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13260 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13261 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13262 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13263 +#endif
13264 +
13265 if (!*poff || ptr < text || ptr >= text_end)
13266 continue;
13267 /* turn DS segment override prefix into lock prefix */
13268 - if (*ptr == 0x3e)
13269 + if (*ktla_ktva(ptr) == 0x3e)
13270 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13271 };
13272 mutex_unlock(&text_mutex);
13273 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13274 for (poff = start; poff < end; poff++) {
13275 u8 *ptr = (u8 *)poff + *poff;
13276
13277 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13278 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13279 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13280 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13281 +#endif
13282 +
13283 if (!*poff || ptr < text || ptr >= text_end)
13284 continue;
13285 /* turn lock prefix into DS segment override prefix */
13286 - if (*ptr == 0xf0)
13287 + if (*ktla_ktva(ptr) == 0xf0)
13288 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13289 };
13290 mutex_unlock(&text_mutex);
13291 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13292
13293 BUG_ON(p->len > MAX_PATCH_LEN);
13294 /* prep the buffer with the original instructions */
13295 - memcpy(insnbuf, p->instr, p->len);
13296 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13297 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13298 (unsigned long)p->instr, p->len);
13299
13300 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13301 if (smp_alt_once)
13302 free_init_pages("SMP alternatives",
13303 (unsigned long)__smp_locks,
13304 - (unsigned long)__smp_locks_end);
13305 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13306
13307 restart_nmi();
13308 }
13309 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13310 * instructions. And on the local CPU you need to be protected again NMI or MCE
13311 * handlers seeing an inconsistent instruction while you patch.
13312 */
13313 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13314 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13315 size_t len)
13316 {
13317 unsigned long flags;
13318 local_irq_save(flags);
13319 - memcpy(addr, opcode, len);
13320 +
13321 + pax_open_kernel();
13322 + memcpy(ktla_ktva(addr), opcode, len);
13323 sync_core();
13324 + pax_close_kernel();
13325 +
13326 local_irq_restore(flags);
13327 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13328 that causes hangs on some VIA CPUs. */
13329 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13330 */
13331 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13332 {
13333 - unsigned long flags;
13334 - char *vaddr;
13335 + unsigned char *vaddr = ktla_ktva(addr);
13336 struct page *pages[2];
13337 - int i;
13338 + size_t i;
13339
13340 if (!core_kernel_text((unsigned long)addr)) {
13341 - pages[0] = vmalloc_to_page(addr);
13342 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13343 + pages[0] = vmalloc_to_page(vaddr);
13344 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13345 } else {
13346 - pages[0] = virt_to_page(addr);
13347 + pages[0] = virt_to_page(vaddr);
13348 WARN_ON(!PageReserved(pages[0]));
13349 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13350 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13351 }
13352 BUG_ON(!pages[0]);
13353 - local_irq_save(flags);
13354 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13355 - if (pages[1])
13356 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13357 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13358 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13359 - clear_fixmap(FIX_TEXT_POKE0);
13360 - if (pages[1])
13361 - clear_fixmap(FIX_TEXT_POKE1);
13362 - local_flush_tlb();
13363 - sync_core();
13364 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13365 - that causes hangs on some VIA CPUs. */
13366 + text_poke_early(addr, opcode, len);
13367 for (i = 0; i < len; i++)
13368 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13369 - local_irq_restore(flags);
13370 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13371 return addr;
13372 }
13373
13374 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13375 index 2eec05b..fef012b 100644
13376 --- a/arch/x86/kernel/apic/apic.c
13377 +++ b/arch/x86/kernel/apic/apic.c
13378 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13379 /*
13380 * Debug level, exported for io_apic.c
13381 */
13382 -unsigned int apic_verbosity;
13383 +int apic_verbosity;
13384
13385 int pic_mode;
13386
13387 @@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13388 apic_write(APIC_ESR, 0);
13389 v1 = apic_read(APIC_ESR);
13390 ack_APIC_irq();
13391 - atomic_inc(&irq_err_count);
13392 + atomic_inc_unchecked(&irq_err_count);
13393
13394 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13395 smp_processor_id(), v0 , v1);
13396 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13397 index 6d10a66..f4687b8 100644
13398 --- a/arch/x86/kernel/apic/io_apic.c
13399 +++ b/arch/x86/kernel/apic/io_apic.c
13400 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13401 }
13402 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13403
13404 -void lock_vector_lock(void)
13405 +void lock_vector_lock(void) __acquires(vector_lock)
13406 {
13407 /* Used to the online set of cpus does not change
13408 * during assign_irq_vector.
13409 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13410 raw_spin_lock(&vector_lock);
13411 }
13412
13413 -void unlock_vector_lock(void)
13414 +void unlock_vector_lock(void) __releases(vector_lock)
13415 {
13416 raw_spin_unlock(&vector_lock);
13417 }
13418 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13419 ack_APIC_irq();
13420 }
13421
13422 -atomic_t irq_mis_count;
13423 +atomic_unchecked_t irq_mis_count;
13424
13425 static void ack_apic_level(struct irq_data *data)
13426 {
13427 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13428 * at the cpu.
13429 */
13430 if (!(v & (1 << (i & 0x1f)))) {
13431 - atomic_inc(&irq_mis_count);
13432 + atomic_inc_unchecked(&irq_mis_count);
13433
13434 eoi_ioapic_irq(irq, cfg);
13435 }
13436 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13437 index f76623c..aab694f 100644
13438 --- a/arch/x86/kernel/apm_32.c
13439 +++ b/arch/x86/kernel/apm_32.c
13440 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13441 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13442 * even though they are called in protected mode.
13443 */
13444 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13445 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13446 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13447
13448 static const char driver_version[] = "1.16ac"; /* no spaces */
13449 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13450 BUG_ON(cpu != 0);
13451 gdt = get_cpu_gdt_table(cpu);
13452 save_desc_40 = gdt[0x40 / 8];
13453 +
13454 + pax_open_kernel();
13455 gdt[0x40 / 8] = bad_bios_desc;
13456 + pax_close_kernel();
13457
13458 apm_irq_save(flags);
13459 APM_DO_SAVE_SEGS;
13460 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13461 &call->esi);
13462 APM_DO_RESTORE_SEGS;
13463 apm_irq_restore(flags);
13464 +
13465 + pax_open_kernel();
13466 gdt[0x40 / 8] = save_desc_40;
13467 + pax_close_kernel();
13468 +
13469 put_cpu();
13470
13471 return call->eax & 0xff;
13472 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13473 BUG_ON(cpu != 0);
13474 gdt = get_cpu_gdt_table(cpu);
13475 save_desc_40 = gdt[0x40 / 8];
13476 +
13477 + pax_open_kernel();
13478 gdt[0x40 / 8] = bad_bios_desc;
13479 + pax_close_kernel();
13480
13481 apm_irq_save(flags);
13482 APM_DO_SAVE_SEGS;
13483 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13484 &call->eax);
13485 APM_DO_RESTORE_SEGS;
13486 apm_irq_restore(flags);
13487 +
13488 + pax_open_kernel();
13489 gdt[0x40 / 8] = save_desc_40;
13490 + pax_close_kernel();
13491 +
13492 put_cpu();
13493 return error;
13494 }
13495 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13496 * code to that CPU.
13497 */
13498 gdt = get_cpu_gdt_table(0);
13499 +
13500 + pax_open_kernel();
13501 set_desc_base(&gdt[APM_CS >> 3],
13502 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13503 set_desc_base(&gdt[APM_CS_16 >> 3],
13504 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13505 set_desc_base(&gdt[APM_DS >> 3],
13506 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13507 + pax_close_kernel();
13508
13509 proc_create("apm", 0, NULL, &apm_file_ops);
13510
13511 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13512 index 68de2dc..1f3c720 100644
13513 --- a/arch/x86/kernel/asm-offsets.c
13514 +++ b/arch/x86/kernel/asm-offsets.c
13515 @@ -33,6 +33,8 @@ void common(void) {
13516 OFFSET(TI_status, thread_info, status);
13517 OFFSET(TI_addr_limit, thread_info, addr_limit);
13518 OFFSET(TI_preempt_count, thread_info, preempt_count);
13519 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13520 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13521
13522 BLANK();
13523 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13524 @@ -53,8 +55,26 @@ void common(void) {
13525 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13526 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13527 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13528 +
13529 +#ifdef CONFIG_PAX_KERNEXEC
13530 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13531 #endif
13532
13533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13534 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13535 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13536 +#ifdef CONFIG_X86_64
13537 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13538 +#endif
13539 +#endif
13540 +
13541 +#endif
13542 +
13543 + BLANK();
13544 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13545 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13546 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13547 +
13548 #ifdef CONFIG_XEN
13549 BLANK();
13550 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13551 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13552 index 834e897..dacddc8 100644
13553 --- a/arch/x86/kernel/asm-offsets_64.c
13554 +++ b/arch/x86/kernel/asm-offsets_64.c
13555 @@ -70,6 +70,7 @@ int main(void)
13556 BLANK();
13557 #undef ENTRY
13558
13559 + DEFINE(TSS_size, sizeof(struct tss_struct));
13560 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13561 BLANK();
13562
13563 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13564 index 25f24dc..4094a7f 100644
13565 --- a/arch/x86/kernel/cpu/Makefile
13566 +++ b/arch/x86/kernel/cpu/Makefile
13567 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13568 CFLAGS_REMOVE_perf_event.o = -pg
13569 endif
13570
13571 -# Make sure load_percpu_segment has no stackprotector
13572 -nostackp := $(call cc-option, -fno-stack-protector)
13573 -CFLAGS_common.o := $(nostackp)
13574 -
13575 obj-y := intel_cacheinfo.o scattered.o topology.o
13576 obj-y += proc.o capflags.o powerflags.o common.o
13577 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13578 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13579 index f4773f4..b3fb13c 100644
13580 --- a/arch/x86/kernel/cpu/amd.c
13581 +++ b/arch/x86/kernel/cpu/amd.c
13582 @@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13583 unsigned int size)
13584 {
13585 /* AMD errata T13 (order #21922) */
13586 - if ((c->x86 == 6)) {
13587 + if (c->x86 == 6) {
13588 /* Duron Rev A0 */
13589 if (c->x86_model == 3 && c->x86_mask == 0)
13590 size = 64;
13591 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13592 index c0f7d68..aa418f9 100644
13593 --- a/arch/x86/kernel/cpu/common.c
13594 +++ b/arch/x86/kernel/cpu/common.c
13595 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13596
13597 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13598
13599 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13600 -#ifdef CONFIG_X86_64
13601 - /*
13602 - * We need valid kernel segments for data and code in long mode too
13603 - * IRET will check the segment types kkeil 2000/10/28
13604 - * Also sysret mandates a special GDT layout
13605 - *
13606 - * TLS descriptors are currently at a different place compared to i386.
13607 - * Hopefully nobody expects them at a fixed place (Wine?)
13608 - */
13609 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13610 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13611 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13612 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13613 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13614 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13615 -#else
13616 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13617 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13618 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13619 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13620 - /*
13621 - * Segments used for calling PnP BIOS have byte granularity.
13622 - * They code segments and data segments have fixed 64k limits,
13623 - * the transfer segment sizes are set at run time.
13624 - */
13625 - /* 32-bit code */
13626 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13627 - /* 16-bit code */
13628 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13629 - /* 16-bit data */
13630 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13631 - /* 16-bit data */
13632 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13633 - /* 16-bit data */
13634 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13635 - /*
13636 - * The APM segments have byte granularity and their bases
13637 - * are set at run time. All have 64k limits.
13638 - */
13639 - /* 32-bit code */
13640 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13641 - /* 16-bit code */
13642 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13643 - /* data */
13644 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13645 -
13646 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13647 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13648 - GDT_STACK_CANARY_INIT
13649 -#endif
13650 -} };
13651 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13652 -
13653 static int __init x86_xsave_setup(char *s)
13654 {
13655 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13656 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13657 {
13658 struct desc_ptr gdt_descr;
13659
13660 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13661 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13662 gdt_descr.size = GDT_SIZE - 1;
13663 load_gdt(&gdt_descr);
13664 /* Reload the per-cpu base */
13665 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13666 /* Filter out anything that depends on CPUID levels we don't have */
13667 filter_cpuid_features(c, true);
13668
13669 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13670 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13671 +#endif
13672 +
13673 /* If the model name is still unset, do table lookup. */
13674 if (!c->x86_model_id[0]) {
13675 const char *p;
13676 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13677 }
13678 __setup("clearcpuid=", setup_disablecpuid);
13679
13680 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13681 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13682 +
13683 #ifdef CONFIG_X86_64
13684 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13685 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13686 - (unsigned long) nmi_idt_table };
13687 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13688
13689 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13690 irq_stack_union) __aligned(PAGE_SIZE);
13691 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13692 EXPORT_PER_CPU_SYMBOL(current_task);
13693
13694 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13695 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13696 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13697 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13698
13699 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13700 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13701 {
13702 memset(regs, 0, sizeof(struct pt_regs));
13703 regs->fs = __KERNEL_PERCPU;
13704 - regs->gs = __KERNEL_STACK_CANARY;
13705 + savesegment(gs, regs->gs);
13706
13707 return regs;
13708 }
13709 @@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13710 int i;
13711
13712 cpu = stack_smp_processor_id();
13713 - t = &per_cpu(init_tss, cpu);
13714 + t = init_tss + cpu;
13715 oist = &per_cpu(orig_ist, cpu);
13716
13717 #ifdef CONFIG_NUMA
13718 @@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13719 switch_to_new_gdt(cpu);
13720 loadsegment(fs, 0);
13721
13722 - load_idt((const struct desc_ptr *)&idt_descr);
13723 + load_idt(&idt_descr);
13724
13725 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13726 syscall_init();
13727 @@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13728 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13729 barrier();
13730
13731 - x86_configure_nx();
13732 if (cpu != 0)
13733 enable_x2apic();
13734
13735 @@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13736 {
13737 int cpu = smp_processor_id();
13738 struct task_struct *curr = current;
13739 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13740 + struct tss_struct *t = init_tss + cpu;
13741 struct thread_struct *thread = &curr->thread;
13742
13743 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13744 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13745 index 3e6ff6c..54b4992 100644
13746 --- a/arch/x86/kernel/cpu/intel.c
13747 +++ b/arch/x86/kernel/cpu/intel.c
13748 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13749 * Update the IDT descriptor and reload the IDT so that
13750 * it uses the read-only mapped virtual address.
13751 */
13752 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13753 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13754 load_idt(&idt_descr);
13755 }
13756 #endif
13757 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13758 index fc4beb3..f20a5a7 100644
13759 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13760 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13761 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
13762
13763 /* Error injection interface */
13764 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13765 + size_t usize, loff_t *off) __size_overflow(3);
13766 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13767 size_t usize, loff_t *off)
13768 {
13769 struct mce m;
13770 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13771 index 5a11ae2..a1a1c8a 100644
13772 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13773 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13774 @@ -42,6 +42,7 @@
13775 #include <asm/processor.h>
13776 #include <asm/mce.h>
13777 #include <asm/msr.h>
13778 +#include <asm/local.h>
13779
13780 #include "mce-internal.h"
13781
13782 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13783 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13784 m->cs, m->ip);
13785
13786 - if (m->cs == __KERNEL_CS)
13787 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13788 print_symbol("{%s}", m->ip);
13789 pr_cont("\n");
13790 }
13791 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13792
13793 #define PANIC_TIMEOUT 5 /* 5 seconds */
13794
13795 -static atomic_t mce_paniced;
13796 +static atomic_unchecked_t mce_paniced;
13797
13798 static int fake_panic;
13799 -static atomic_t mce_fake_paniced;
13800 +static atomic_unchecked_t mce_fake_paniced;
13801
13802 /* Panic in progress. Enable interrupts and wait for final IPI */
13803 static void wait_for_panic(void)
13804 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13805 /*
13806 * Make sure only one CPU runs in machine check panic
13807 */
13808 - if (atomic_inc_return(&mce_paniced) > 1)
13809 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13810 wait_for_panic();
13811 barrier();
13812
13813 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13814 console_verbose();
13815 } else {
13816 /* Don't log too much for fake panic */
13817 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13818 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13819 return;
13820 }
13821 /* First print corrected ones that are still unlogged */
13822 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13823 * might have been modified by someone else.
13824 */
13825 rmb();
13826 - if (atomic_read(&mce_paniced))
13827 + if (atomic_read_unchecked(&mce_paniced))
13828 wait_for_panic();
13829 if (!monarch_timeout)
13830 goto out;
13831 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13832 }
13833
13834 /* Call the installed machine check handler for this CPU setup. */
13835 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13836 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13837 unexpected_machine_check;
13838
13839 /*
13840 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13841 return;
13842 }
13843
13844 + pax_open_kernel();
13845 machine_check_vector = do_machine_check;
13846 + pax_close_kernel();
13847
13848 __mcheck_cpu_init_generic();
13849 __mcheck_cpu_init_vendor(c);
13850 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13851 */
13852
13853 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13854 -static int mce_chrdev_open_count; /* #times opened */
13855 +static local_t mce_chrdev_open_count; /* #times opened */
13856 static int mce_chrdev_open_exclu; /* already open exclusive? */
13857
13858 static int mce_chrdev_open(struct inode *inode, struct file *file)
13859 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13860 spin_lock(&mce_chrdev_state_lock);
13861
13862 if (mce_chrdev_open_exclu ||
13863 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13864 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13865 spin_unlock(&mce_chrdev_state_lock);
13866
13867 return -EBUSY;
13868 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13869
13870 if (file->f_flags & O_EXCL)
13871 mce_chrdev_open_exclu = 1;
13872 - mce_chrdev_open_count++;
13873 + local_inc(&mce_chrdev_open_count);
13874
13875 spin_unlock(&mce_chrdev_state_lock);
13876
13877 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13878 {
13879 spin_lock(&mce_chrdev_state_lock);
13880
13881 - mce_chrdev_open_count--;
13882 + local_dec(&mce_chrdev_open_count);
13883 mce_chrdev_open_exclu = 0;
13884
13885 spin_unlock(&mce_chrdev_state_lock);
13886 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13887 static void mce_reset(void)
13888 {
13889 cpu_missing = 0;
13890 - atomic_set(&mce_fake_paniced, 0);
13891 + atomic_set_unchecked(&mce_fake_paniced, 0);
13892 atomic_set(&mce_executing, 0);
13893 atomic_set(&mce_callin, 0);
13894 atomic_set(&global_nwo, 0);
13895 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13896 index 5c0e653..0882b0a 100644
13897 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13898 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13899 @@ -12,6 +12,7 @@
13900 #include <asm/system.h>
13901 #include <asm/mce.h>
13902 #include <asm/msr.h>
13903 +#include <asm/pgtable.h>
13904
13905 /* By default disabled */
13906 int mce_p5_enabled __read_mostly;
13907 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13908 if (!cpu_has(c, X86_FEATURE_MCE))
13909 return;
13910
13911 + pax_open_kernel();
13912 machine_check_vector = pentium_machine_check;
13913 + pax_close_kernel();
13914 /* Make sure the vector pointer is visible before we enable MCEs: */
13915 wmb();
13916
13917 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13918 index 54060f5..c1a7577 100644
13919 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13920 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13921 @@ -11,6 +11,7 @@
13922 #include <asm/system.h>
13923 #include <asm/mce.h>
13924 #include <asm/msr.h>
13925 +#include <asm/pgtable.h>
13926
13927 /* Machine check handler for WinChip C6: */
13928 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13929 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13930 {
13931 u32 lo, hi;
13932
13933 + pax_open_kernel();
13934 machine_check_vector = winchip_machine_check;
13935 + pax_close_kernel();
13936 /* Make sure the vector pointer is visible before we enable MCEs: */
13937 wmb();
13938
13939 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
13940 index 7928963..1b16001 100644
13941 --- a/arch/x86/kernel/cpu/mtrr/if.c
13942 +++ b/arch/x86/kernel/cpu/mtrr/if.c
13943 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
13944 * "base=%Lx size=%Lx type=%s" or "disable=%d"
13945 */
13946 static ssize_t
13947 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
13948 +static ssize_t
13949 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
13950 {
13951 int i, err;
13952 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13953 index 6b96110..0da73eb 100644
13954 --- a/arch/x86/kernel/cpu/mtrr/main.c
13955 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13956 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13957 u64 size_or_mask, size_and_mask;
13958 static bool mtrr_aps_delayed_init;
13959
13960 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13961 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13962
13963 const struct mtrr_ops *mtrr_if;
13964
13965 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13966 index df5e41f..816c719 100644
13967 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13968 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13969 @@ -25,7 +25,7 @@ struct mtrr_ops {
13970 int (*validate_add_page)(unsigned long base, unsigned long size,
13971 unsigned int type);
13972 int (*have_wrcomb)(void);
13973 -};
13974 +} __do_const;
13975
13976 extern int generic_get_free_region(unsigned long base, unsigned long size,
13977 int replace_reg);
13978 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13979 index 5adce10..99284ec 100644
13980 --- a/arch/x86/kernel/cpu/perf_event.c
13981 +++ b/arch/x86/kernel/cpu/perf_event.c
13982 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13983 break;
13984
13985 perf_callchain_store(entry, frame.return_address);
13986 - fp = frame.next_frame;
13987 + fp = (const void __force_user *)frame.next_frame;
13988 }
13989 }
13990
13991 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13992 index 13ad899..f642b9a 100644
13993 --- a/arch/x86/kernel/crash.c
13994 +++ b/arch/x86/kernel/crash.c
13995 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13996 {
13997 #ifdef CONFIG_X86_32
13998 struct pt_regs fixed_regs;
13999 -#endif
14000
14001 -#ifdef CONFIG_X86_32
14002 - if (!user_mode_vm(regs)) {
14003 + if (!user_mode(regs)) {
14004 crash_fixup_ss_esp(&fixed_regs, regs);
14005 regs = &fixed_regs;
14006 }
14007 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14008 index 37250fe..bf2ec74 100644
14009 --- a/arch/x86/kernel/doublefault_32.c
14010 +++ b/arch/x86/kernel/doublefault_32.c
14011 @@ -11,7 +11,7 @@
14012
14013 #define DOUBLEFAULT_STACKSIZE (1024)
14014 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14015 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14016 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14017
14018 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14019
14020 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14021 unsigned long gdt, tss;
14022
14023 store_gdt(&gdt_desc);
14024 - gdt = gdt_desc.address;
14025 + gdt = (unsigned long)gdt_desc.address;
14026
14027 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14028
14029 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14030 /* 0x2 bit is always set */
14031 .flags = X86_EFLAGS_SF | 0x2,
14032 .sp = STACK_START,
14033 - .es = __USER_DS,
14034 + .es = __KERNEL_DS,
14035 .cs = __KERNEL_CS,
14036 .ss = __KERNEL_DS,
14037 - .ds = __USER_DS,
14038 + .ds = __KERNEL_DS,
14039 .fs = __KERNEL_PERCPU,
14040
14041 .__cr3 = __pa_nodebug(swapper_pg_dir),
14042 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14043 index 4025fe4..d8451c6 100644
14044 --- a/arch/x86/kernel/dumpstack.c
14045 +++ b/arch/x86/kernel/dumpstack.c
14046 @@ -2,6 +2,9 @@
14047 * Copyright (C) 1991, 1992 Linus Torvalds
14048 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14049 */
14050 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14051 +#define __INCLUDED_BY_HIDESYM 1
14052 +#endif
14053 #include <linux/kallsyms.h>
14054 #include <linux/kprobes.h>
14055 #include <linux/uaccess.h>
14056 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14057 static void
14058 print_ftrace_graph_addr(unsigned long addr, void *data,
14059 const struct stacktrace_ops *ops,
14060 - struct thread_info *tinfo, int *graph)
14061 + struct task_struct *task, int *graph)
14062 {
14063 - struct task_struct *task = tinfo->task;
14064 unsigned long ret_addr;
14065 int index = task->curr_ret_stack;
14066
14067 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14068 static inline void
14069 print_ftrace_graph_addr(unsigned long addr, void *data,
14070 const struct stacktrace_ops *ops,
14071 - struct thread_info *tinfo, int *graph)
14072 + struct task_struct *task, int *graph)
14073 { }
14074 #endif
14075
14076 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14077 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14078 */
14079
14080 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14081 - void *p, unsigned int size, void *end)
14082 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14083 {
14084 - void *t = tinfo;
14085 if (end) {
14086 if (p < end && p >= (end-THREAD_SIZE))
14087 return 1;
14088 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14089 }
14090
14091 unsigned long
14092 -print_context_stack(struct thread_info *tinfo,
14093 +print_context_stack(struct task_struct *task, void *stack_start,
14094 unsigned long *stack, unsigned long bp,
14095 const struct stacktrace_ops *ops, void *data,
14096 unsigned long *end, int *graph)
14097 {
14098 struct stack_frame *frame = (struct stack_frame *)bp;
14099
14100 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14101 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14102 unsigned long addr;
14103
14104 addr = *stack;
14105 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14106 } else {
14107 ops->address(data, addr, 0);
14108 }
14109 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14110 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14111 }
14112 stack++;
14113 }
14114 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14115 EXPORT_SYMBOL_GPL(print_context_stack);
14116
14117 unsigned long
14118 -print_context_stack_bp(struct thread_info *tinfo,
14119 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14120 unsigned long *stack, unsigned long bp,
14121 const struct stacktrace_ops *ops, void *data,
14122 unsigned long *end, int *graph)
14123 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14124 struct stack_frame *frame = (struct stack_frame *)bp;
14125 unsigned long *ret_addr = &frame->return_address;
14126
14127 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14128 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14129 unsigned long addr = *ret_addr;
14130
14131 if (!__kernel_text_address(addr))
14132 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14133 ops->address(data, addr, 1);
14134 frame = frame->next_frame;
14135 ret_addr = &frame->return_address;
14136 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14137 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14138 }
14139
14140 return (unsigned long)frame;
14141 @@ -186,7 +186,7 @@ void dump_stack(void)
14142
14143 bp = stack_frame(current, NULL);
14144 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14145 - current->pid, current->comm, print_tainted(),
14146 + task_pid_nr(current), current->comm, print_tainted(),
14147 init_utsname()->release,
14148 (int)strcspn(init_utsname()->version, " "),
14149 init_utsname()->version);
14150 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14151 }
14152 EXPORT_SYMBOL_GPL(oops_begin);
14153
14154 +extern void gr_handle_kernel_exploit(void);
14155 +
14156 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14157 {
14158 if (regs && kexec_should_crash(current))
14159 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14160 panic("Fatal exception in interrupt");
14161 if (panic_on_oops)
14162 panic("Fatal exception");
14163 - do_exit(signr);
14164 +
14165 + gr_handle_kernel_exploit();
14166 +
14167 + do_group_exit(signr);
14168 }
14169
14170 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14171 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14172
14173 show_registers(regs);
14174 #ifdef CONFIG_X86_32
14175 - if (user_mode_vm(regs)) {
14176 + if (user_mode(regs)) {
14177 sp = regs->sp;
14178 ss = regs->ss & 0xffff;
14179 } else {
14180 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14181 unsigned long flags = oops_begin();
14182 int sig = SIGSEGV;
14183
14184 - if (!user_mode_vm(regs))
14185 + if (!user_mode(regs))
14186 report_bug(regs->ip, regs);
14187
14188 if (__die(str, regs, err))
14189 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14190 index c99f9ed..2a15d80 100644
14191 --- a/arch/x86/kernel/dumpstack_32.c
14192 +++ b/arch/x86/kernel/dumpstack_32.c
14193 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14194 bp = stack_frame(task, regs);
14195
14196 for (;;) {
14197 - struct thread_info *context;
14198 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14199
14200 - context = (struct thread_info *)
14201 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14202 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14203 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14204
14205 - stack = (unsigned long *)context->previous_esp;
14206 - if (!stack)
14207 + if (stack_start == task_stack_page(task))
14208 break;
14209 + stack = *(unsigned long **)stack_start;
14210 if (ops->stack(data, "IRQ") < 0)
14211 break;
14212 touch_nmi_watchdog();
14213 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14214 * When in-kernel, we also print out the stack and code at the
14215 * time of the fault..
14216 */
14217 - if (!user_mode_vm(regs)) {
14218 + if (!user_mode(regs)) {
14219 unsigned int code_prologue = code_bytes * 43 / 64;
14220 unsigned int code_len = code_bytes;
14221 unsigned char c;
14222 u8 *ip;
14223 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14224
14225 printk(KERN_EMERG "Stack:\n");
14226 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14227
14228 printk(KERN_EMERG "Code: ");
14229
14230 - ip = (u8 *)regs->ip - code_prologue;
14231 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14232 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14233 /* try starting at IP */
14234 - ip = (u8 *)regs->ip;
14235 + ip = (u8 *)regs->ip + cs_base;
14236 code_len = code_len - code_prologue + 1;
14237 }
14238 for (i = 0; i < code_len; i++, ip++) {
14239 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14240 printk(KERN_CONT " Bad EIP value.");
14241 break;
14242 }
14243 - if (ip == (u8 *)regs->ip)
14244 + if (ip == (u8 *)regs->ip + cs_base)
14245 printk(KERN_CONT "<%02x> ", c);
14246 else
14247 printk(KERN_CONT "%02x ", c);
14248 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14249 {
14250 unsigned short ud2;
14251
14252 + ip = ktla_ktva(ip);
14253 if (ip < PAGE_OFFSET)
14254 return 0;
14255 if (probe_kernel_address((unsigned short *)ip, ud2))
14256 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14257
14258 return ud2 == 0x0b0f;
14259 }
14260 +
14261 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14262 +void pax_check_alloca(unsigned long size)
14263 +{
14264 + unsigned long sp = (unsigned long)&sp, stack_left;
14265 +
14266 + /* all kernel stacks are of the same size */
14267 + stack_left = sp & (THREAD_SIZE - 1);
14268 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14269 +}
14270 +EXPORT_SYMBOL(pax_check_alloca);
14271 +#endif
14272 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14273 index 17107bd..b2deecf 100644
14274 --- a/arch/x86/kernel/dumpstack_64.c
14275 +++ b/arch/x86/kernel/dumpstack_64.c
14276 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14277 unsigned long *irq_stack_end =
14278 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14279 unsigned used = 0;
14280 - struct thread_info *tinfo;
14281 int graph = 0;
14282 unsigned long dummy;
14283 + void *stack_start;
14284
14285 if (!task)
14286 task = current;
14287 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14288 * current stack address. If the stacks consist of nested
14289 * exceptions
14290 */
14291 - tinfo = task_thread_info(task);
14292 for (;;) {
14293 char *id;
14294 unsigned long *estack_end;
14295 +
14296 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14297 &used, &id);
14298
14299 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14300 if (ops->stack(data, id) < 0)
14301 break;
14302
14303 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14304 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14305 data, estack_end, &graph);
14306 ops->stack(data, "<EOE>");
14307 /*
14308 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14309 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14310 if (ops->stack(data, "IRQ") < 0)
14311 break;
14312 - bp = ops->walk_stack(tinfo, stack, bp,
14313 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14314 ops, data, irq_stack_end, &graph);
14315 /*
14316 * We link to the next stack (which would be
14317 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14318 /*
14319 * This handles the process stack:
14320 */
14321 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14322 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14323 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14324 put_cpu();
14325 }
14326 EXPORT_SYMBOL(dump_trace);
14327 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14328
14329 return ud2 == 0x0b0f;
14330 }
14331 +
14332 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14333 +void pax_check_alloca(unsigned long size)
14334 +{
14335 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14336 + unsigned cpu, used;
14337 + char *id;
14338 +
14339 + /* check the process stack first */
14340 + stack_start = (unsigned long)task_stack_page(current);
14341 + stack_end = stack_start + THREAD_SIZE;
14342 + if (likely(stack_start <= sp && sp < stack_end)) {
14343 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14344 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14345 + return;
14346 + }
14347 +
14348 + cpu = get_cpu();
14349 +
14350 + /* check the irq stacks */
14351 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14352 + stack_start = stack_end - IRQ_STACK_SIZE;
14353 + if (stack_start <= sp && sp < stack_end) {
14354 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14355 + put_cpu();
14356 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14357 + return;
14358 + }
14359 +
14360 + /* check the exception stacks */
14361 + used = 0;
14362 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14363 + stack_start = stack_end - EXCEPTION_STKSZ;
14364 + if (stack_end && stack_start <= sp && sp < stack_end) {
14365 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14366 + put_cpu();
14367 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14368 + return;
14369 + }
14370 +
14371 + put_cpu();
14372 +
14373 + /* unknown stack */
14374 + BUG();
14375 +}
14376 +EXPORT_SYMBOL(pax_check_alloca);
14377 +#endif
14378 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14379 index 9b9f18b..9fcaa04 100644
14380 --- a/arch/x86/kernel/early_printk.c
14381 +++ b/arch/x86/kernel/early_printk.c
14382 @@ -7,6 +7,7 @@
14383 #include <linux/pci_regs.h>
14384 #include <linux/pci_ids.h>
14385 #include <linux/errno.h>
14386 +#include <linux/sched.h>
14387 #include <asm/io.h>
14388 #include <asm/processor.h>
14389 #include <asm/fcntl.h>
14390 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14391 index 7b784f4..76aaad7 100644
14392 --- a/arch/x86/kernel/entry_32.S
14393 +++ b/arch/x86/kernel/entry_32.S
14394 @@ -179,13 +179,146 @@
14395 /*CFI_REL_OFFSET gs, PT_GS*/
14396 .endm
14397 .macro SET_KERNEL_GS reg
14398 +
14399 +#ifdef CONFIG_CC_STACKPROTECTOR
14400 movl $(__KERNEL_STACK_CANARY), \reg
14401 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14402 + movl $(__USER_DS), \reg
14403 +#else
14404 + xorl \reg, \reg
14405 +#endif
14406 +
14407 movl \reg, %gs
14408 .endm
14409
14410 #endif /* CONFIG_X86_32_LAZY_GS */
14411
14412 -.macro SAVE_ALL
14413 +.macro pax_enter_kernel
14414 +#ifdef CONFIG_PAX_KERNEXEC
14415 + call pax_enter_kernel
14416 +#endif
14417 +.endm
14418 +
14419 +.macro pax_exit_kernel
14420 +#ifdef CONFIG_PAX_KERNEXEC
14421 + call pax_exit_kernel
14422 +#endif
14423 +.endm
14424 +
14425 +#ifdef CONFIG_PAX_KERNEXEC
14426 +ENTRY(pax_enter_kernel)
14427 +#ifdef CONFIG_PARAVIRT
14428 + pushl %eax
14429 + pushl %ecx
14430 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14431 + mov %eax, %esi
14432 +#else
14433 + mov %cr0, %esi
14434 +#endif
14435 + bts $16, %esi
14436 + jnc 1f
14437 + mov %cs, %esi
14438 + cmp $__KERNEL_CS, %esi
14439 + jz 3f
14440 + ljmp $__KERNEL_CS, $3f
14441 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14442 +2:
14443 +#ifdef CONFIG_PARAVIRT
14444 + mov %esi, %eax
14445 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14446 +#else
14447 + mov %esi, %cr0
14448 +#endif
14449 +3:
14450 +#ifdef CONFIG_PARAVIRT
14451 + popl %ecx
14452 + popl %eax
14453 +#endif
14454 + ret
14455 +ENDPROC(pax_enter_kernel)
14456 +
14457 +ENTRY(pax_exit_kernel)
14458 +#ifdef CONFIG_PARAVIRT
14459 + pushl %eax
14460 + pushl %ecx
14461 +#endif
14462 + mov %cs, %esi
14463 + cmp $__KERNEXEC_KERNEL_CS, %esi
14464 + jnz 2f
14465 +#ifdef CONFIG_PARAVIRT
14466 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14467 + mov %eax, %esi
14468 +#else
14469 + mov %cr0, %esi
14470 +#endif
14471 + btr $16, %esi
14472 + ljmp $__KERNEL_CS, $1f
14473 +1:
14474 +#ifdef CONFIG_PARAVIRT
14475 + mov %esi, %eax
14476 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14477 +#else
14478 + mov %esi, %cr0
14479 +#endif
14480 +2:
14481 +#ifdef CONFIG_PARAVIRT
14482 + popl %ecx
14483 + popl %eax
14484 +#endif
14485 + ret
14486 +ENDPROC(pax_exit_kernel)
14487 +#endif
14488 +
14489 +.macro pax_erase_kstack
14490 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14491 + call pax_erase_kstack
14492 +#endif
14493 +.endm
14494 +
14495 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14496 +/*
14497 + * ebp: thread_info
14498 + * ecx, edx: can be clobbered
14499 + */
14500 +ENTRY(pax_erase_kstack)
14501 + pushl %edi
14502 + pushl %eax
14503 +
14504 + mov TI_lowest_stack(%ebp), %edi
14505 + mov $-0xBEEF, %eax
14506 + std
14507 +
14508 +1: mov %edi, %ecx
14509 + and $THREAD_SIZE_asm - 1, %ecx
14510 + shr $2, %ecx
14511 + repne scasl
14512 + jecxz 2f
14513 +
14514 + cmp $2*16, %ecx
14515 + jc 2f
14516 +
14517 + mov $2*16, %ecx
14518 + repe scasl
14519 + jecxz 2f
14520 + jne 1b
14521 +
14522 +2: cld
14523 + mov %esp, %ecx
14524 + sub %edi, %ecx
14525 + shr $2, %ecx
14526 + rep stosl
14527 +
14528 + mov TI_task_thread_sp0(%ebp), %edi
14529 + sub $128, %edi
14530 + mov %edi, TI_lowest_stack(%ebp)
14531 +
14532 + popl %eax
14533 + popl %edi
14534 + ret
14535 +ENDPROC(pax_erase_kstack)
14536 +#endif
14537 +
14538 +.macro __SAVE_ALL _DS
14539 cld
14540 PUSH_GS
14541 pushl_cfi %fs
14542 @@ -208,7 +341,7 @@
14543 CFI_REL_OFFSET ecx, 0
14544 pushl_cfi %ebx
14545 CFI_REL_OFFSET ebx, 0
14546 - movl $(__USER_DS), %edx
14547 + movl $\_DS, %edx
14548 movl %edx, %ds
14549 movl %edx, %es
14550 movl $(__KERNEL_PERCPU), %edx
14551 @@ -216,6 +349,15 @@
14552 SET_KERNEL_GS %edx
14553 .endm
14554
14555 +.macro SAVE_ALL
14556 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14557 + __SAVE_ALL __KERNEL_DS
14558 + pax_enter_kernel
14559 +#else
14560 + __SAVE_ALL __USER_DS
14561 +#endif
14562 +.endm
14563 +
14564 .macro RESTORE_INT_REGS
14565 popl_cfi %ebx
14566 CFI_RESTORE ebx
14567 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14568 popfl_cfi
14569 jmp syscall_exit
14570 CFI_ENDPROC
14571 -END(ret_from_fork)
14572 +ENDPROC(ret_from_fork)
14573
14574 /*
14575 * Interrupt exit functions should be protected against kprobes
14576 @@ -335,7 +477,15 @@ resume_userspace_sig:
14577 andl $SEGMENT_RPL_MASK, %eax
14578 #endif
14579 cmpl $USER_RPL, %eax
14580 +
14581 +#ifdef CONFIG_PAX_KERNEXEC
14582 + jae resume_userspace
14583 +
14584 + PAX_EXIT_KERNEL
14585 + jmp resume_kernel
14586 +#else
14587 jb resume_kernel # not returning to v8086 or userspace
14588 +#endif
14589
14590 ENTRY(resume_userspace)
14591 LOCKDEP_SYS_EXIT
14592 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14593 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14594 # int/exception return?
14595 jne work_pending
14596 - jmp restore_all
14597 -END(ret_from_exception)
14598 + jmp restore_all_pax
14599 +ENDPROC(ret_from_exception)
14600
14601 #ifdef CONFIG_PREEMPT
14602 ENTRY(resume_kernel)
14603 @@ -363,7 +513,7 @@ need_resched:
14604 jz restore_all
14605 call preempt_schedule_irq
14606 jmp need_resched
14607 -END(resume_kernel)
14608 +ENDPROC(resume_kernel)
14609 #endif
14610 CFI_ENDPROC
14611 /*
14612 @@ -397,23 +547,34 @@ sysenter_past_esp:
14613 /*CFI_REL_OFFSET cs, 0*/
14614 /*
14615 * Push current_thread_info()->sysenter_return to the stack.
14616 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14617 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14618 */
14619 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14620 + pushl_cfi $0
14621 CFI_REL_OFFSET eip, 0
14622
14623 pushl_cfi %eax
14624 SAVE_ALL
14625 + GET_THREAD_INFO(%ebp)
14626 + movl TI_sysenter_return(%ebp),%ebp
14627 + movl %ebp,PT_EIP(%esp)
14628 ENABLE_INTERRUPTS(CLBR_NONE)
14629
14630 /*
14631 * Load the potential sixth argument from user stack.
14632 * Careful about security.
14633 */
14634 + movl PT_OLDESP(%esp),%ebp
14635 +
14636 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14637 + mov PT_OLDSS(%esp),%ds
14638 +1: movl %ds:(%ebp),%ebp
14639 + push %ss
14640 + pop %ds
14641 +#else
14642 cmpl $__PAGE_OFFSET-3,%ebp
14643 jae syscall_fault
14644 1: movl (%ebp),%ebp
14645 +#endif
14646 +
14647 movl %ebp,PT_EBP(%esp)
14648 .section __ex_table,"a"
14649 .align 4
14650 @@ -436,12 +597,24 @@ sysenter_do_call:
14651 testl $_TIF_ALLWORK_MASK, %ecx
14652 jne sysexit_audit
14653 sysenter_exit:
14654 +
14655 +#ifdef CONFIG_PAX_RANDKSTACK
14656 + pushl_cfi %eax
14657 + movl %esp, %eax
14658 + call pax_randomize_kstack
14659 + popl_cfi %eax
14660 +#endif
14661 +
14662 + pax_erase_kstack
14663 +
14664 /* if something modifies registers it must also disable sysexit */
14665 movl PT_EIP(%esp), %edx
14666 movl PT_OLDESP(%esp), %ecx
14667 xorl %ebp,%ebp
14668 TRACE_IRQS_ON
14669 1: mov PT_FS(%esp), %fs
14670 +2: mov PT_DS(%esp), %ds
14671 +3: mov PT_ES(%esp), %es
14672 PTGS_TO_GS
14673 ENABLE_INTERRUPTS_SYSEXIT
14674
14675 @@ -458,6 +631,9 @@ sysenter_audit:
14676 movl %eax,%edx /* 2nd arg: syscall number */
14677 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14678 call __audit_syscall_entry
14679 +
14680 + pax_erase_kstack
14681 +
14682 pushl_cfi %ebx
14683 movl PT_EAX(%esp),%eax /* reload syscall number */
14684 jmp sysenter_do_call
14685 @@ -483,11 +659,17 @@ sysexit_audit:
14686
14687 CFI_ENDPROC
14688 .pushsection .fixup,"ax"
14689 -2: movl $0,PT_FS(%esp)
14690 +4: movl $0,PT_FS(%esp)
14691 + jmp 1b
14692 +5: movl $0,PT_DS(%esp)
14693 + jmp 1b
14694 +6: movl $0,PT_ES(%esp)
14695 jmp 1b
14696 .section __ex_table,"a"
14697 .align 4
14698 - .long 1b,2b
14699 + .long 1b,4b
14700 + .long 2b,5b
14701 + .long 3b,6b
14702 .popsection
14703 PTGS_TO_GS_EX
14704 ENDPROC(ia32_sysenter_target)
14705 @@ -520,6 +702,15 @@ syscall_exit:
14706 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14707 jne syscall_exit_work
14708
14709 +restore_all_pax:
14710 +
14711 +#ifdef CONFIG_PAX_RANDKSTACK
14712 + movl %esp, %eax
14713 + call pax_randomize_kstack
14714 +#endif
14715 +
14716 + pax_erase_kstack
14717 +
14718 restore_all:
14719 TRACE_IRQS_IRET
14720 restore_all_notrace:
14721 @@ -579,14 +770,34 @@ ldt_ss:
14722 * compensating for the offset by changing to the ESPFIX segment with
14723 * a base address that matches for the difference.
14724 */
14725 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14726 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14727 mov %esp, %edx /* load kernel esp */
14728 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14729 mov %dx, %ax /* eax: new kernel esp */
14730 sub %eax, %edx /* offset (low word is 0) */
14731 +#ifdef CONFIG_SMP
14732 + movl PER_CPU_VAR(cpu_number), %ebx
14733 + shll $PAGE_SHIFT_asm, %ebx
14734 + addl $cpu_gdt_table, %ebx
14735 +#else
14736 + movl $cpu_gdt_table, %ebx
14737 +#endif
14738 shr $16, %edx
14739 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14740 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14741 +
14742 +#ifdef CONFIG_PAX_KERNEXEC
14743 + mov %cr0, %esi
14744 + btr $16, %esi
14745 + mov %esi, %cr0
14746 +#endif
14747 +
14748 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14749 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14750 +
14751 +#ifdef CONFIG_PAX_KERNEXEC
14752 + bts $16, %esi
14753 + mov %esi, %cr0
14754 +#endif
14755 +
14756 pushl_cfi $__ESPFIX_SS
14757 pushl_cfi %eax /* new kernel esp */
14758 /* Disable interrupts, but do not irqtrace this section: we
14759 @@ -615,38 +826,30 @@ work_resched:
14760 movl TI_flags(%ebp), %ecx
14761 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14762 # than syscall tracing?
14763 - jz restore_all
14764 + jz restore_all_pax
14765 testb $_TIF_NEED_RESCHED, %cl
14766 jnz work_resched
14767
14768 work_notifysig: # deal with pending signals and
14769 # notify-resume requests
14770 + movl %esp, %eax
14771 #ifdef CONFIG_VM86
14772 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14773 - movl %esp, %eax
14774 - jne work_notifysig_v86 # returning to kernel-space or
14775 + jz 1f # returning to kernel-space or
14776 # vm86-space
14777 - TRACE_IRQS_ON
14778 - ENABLE_INTERRUPTS(CLBR_NONE)
14779 - xorl %edx, %edx
14780 - call do_notify_resume
14781 - jmp resume_userspace_sig
14782
14783 - ALIGN
14784 -work_notifysig_v86:
14785 pushl_cfi %ecx # save ti_flags for do_notify_resume
14786 call save_v86_state # %eax contains pt_regs pointer
14787 popl_cfi %ecx
14788 movl %eax, %esp
14789 -#else
14790 - movl %esp, %eax
14791 +1:
14792 #endif
14793 TRACE_IRQS_ON
14794 ENABLE_INTERRUPTS(CLBR_NONE)
14795 xorl %edx, %edx
14796 call do_notify_resume
14797 jmp resume_userspace_sig
14798 -END(work_pending)
14799 +ENDPROC(work_pending)
14800
14801 # perform syscall exit tracing
14802 ALIGN
14803 @@ -654,11 +857,14 @@ syscall_trace_entry:
14804 movl $-ENOSYS,PT_EAX(%esp)
14805 movl %esp, %eax
14806 call syscall_trace_enter
14807 +
14808 + pax_erase_kstack
14809 +
14810 /* What it returned is what we'll actually use. */
14811 cmpl $(NR_syscalls), %eax
14812 jnae syscall_call
14813 jmp syscall_exit
14814 -END(syscall_trace_entry)
14815 +ENDPROC(syscall_trace_entry)
14816
14817 # perform syscall exit tracing
14818 ALIGN
14819 @@ -671,20 +877,24 @@ syscall_exit_work:
14820 movl %esp, %eax
14821 call syscall_trace_leave
14822 jmp resume_userspace
14823 -END(syscall_exit_work)
14824 +ENDPROC(syscall_exit_work)
14825 CFI_ENDPROC
14826
14827 RING0_INT_FRAME # can't unwind into user space anyway
14828 syscall_fault:
14829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14830 + push %ss
14831 + pop %ds
14832 +#endif
14833 GET_THREAD_INFO(%ebp)
14834 movl $-EFAULT,PT_EAX(%esp)
14835 jmp resume_userspace
14836 -END(syscall_fault)
14837 +ENDPROC(syscall_fault)
14838
14839 syscall_badsys:
14840 movl $-ENOSYS,PT_EAX(%esp)
14841 jmp resume_userspace
14842 -END(syscall_badsys)
14843 +ENDPROC(syscall_badsys)
14844 CFI_ENDPROC
14845 /*
14846 * End of kprobes section
14847 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14848 CFI_ENDPROC
14849 ENDPROC(ptregs_clone)
14850
14851 + ALIGN;
14852 +ENTRY(kernel_execve)
14853 + CFI_STARTPROC
14854 + pushl_cfi %ebp
14855 + sub $PT_OLDSS+4,%esp
14856 + pushl_cfi %edi
14857 + pushl_cfi %ecx
14858 + pushl_cfi %eax
14859 + lea 3*4(%esp),%edi
14860 + mov $PT_OLDSS/4+1,%ecx
14861 + xorl %eax,%eax
14862 + rep stosl
14863 + popl_cfi %eax
14864 + popl_cfi %ecx
14865 + popl_cfi %edi
14866 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14867 + pushl_cfi %esp
14868 + call sys_execve
14869 + add $4,%esp
14870 + CFI_ADJUST_CFA_OFFSET -4
14871 + GET_THREAD_INFO(%ebp)
14872 + test %eax,%eax
14873 + jz syscall_exit
14874 + add $PT_OLDSS+4,%esp
14875 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14876 + popl_cfi %ebp
14877 + ret
14878 + CFI_ENDPROC
14879 +ENDPROC(kernel_execve)
14880 +
14881 .macro FIXUP_ESPFIX_STACK
14882 /*
14883 * Switch back for ESPFIX stack to the normal zerobased stack
14884 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14885 * normal stack and adjusts ESP with the matching offset.
14886 */
14887 /* fixup the stack */
14888 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14889 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14890 +#ifdef CONFIG_SMP
14891 + movl PER_CPU_VAR(cpu_number), %ebx
14892 + shll $PAGE_SHIFT_asm, %ebx
14893 + addl $cpu_gdt_table, %ebx
14894 +#else
14895 + movl $cpu_gdt_table, %ebx
14896 +#endif
14897 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14898 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14899 shl $16, %eax
14900 addl %esp, %eax /* the adjusted stack pointer */
14901 pushl_cfi $__KERNEL_DS
14902 @@ -819,7 +1066,7 @@ vector=vector+1
14903 .endr
14904 2: jmp common_interrupt
14905 .endr
14906 -END(irq_entries_start)
14907 +ENDPROC(irq_entries_start)
14908
14909 .previous
14910 END(interrupt)
14911 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14912 pushl_cfi $do_coprocessor_error
14913 jmp error_code
14914 CFI_ENDPROC
14915 -END(coprocessor_error)
14916 +ENDPROC(coprocessor_error)
14917
14918 ENTRY(simd_coprocessor_error)
14919 RING0_INT_FRAME
14920 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14921 #endif
14922 jmp error_code
14923 CFI_ENDPROC
14924 -END(simd_coprocessor_error)
14925 +ENDPROC(simd_coprocessor_error)
14926
14927 ENTRY(device_not_available)
14928 RING0_INT_FRAME
14929 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14930 pushl_cfi $do_device_not_available
14931 jmp error_code
14932 CFI_ENDPROC
14933 -END(device_not_available)
14934 +ENDPROC(device_not_available)
14935
14936 #ifdef CONFIG_PARAVIRT
14937 ENTRY(native_iret)
14938 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
14939 .align 4
14940 .long native_iret, iret_exc
14941 .previous
14942 -END(native_iret)
14943 +ENDPROC(native_iret)
14944
14945 ENTRY(native_irq_enable_sysexit)
14946 sti
14947 sysexit
14948 -END(native_irq_enable_sysexit)
14949 +ENDPROC(native_irq_enable_sysexit)
14950 #endif
14951
14952 ENTRY(overflow)
14953 @@ -919,7 +1166,7 @@ ENTRY(overflow)
14954 pushl_cfi $do_overflow
14955 jmp error_code
14956 CFI_ENDPROC
14957 -END(overflow)
14958 +ENDPROC(overflow)
14959
14960 ENTRY(bounds)
14961 RING0_INT_FRAME
14962 @@ -927,7 +1174,7 @@ ENTRY(bounds)
14963 pushl_cfi $do_bounds
14964 jmp error_code
14965 CFI_ENDPROC
14966 -END(bounds)
14967 +ENDPROC(bounds)
14968
14969 ENTRY(invalid_op)
14970 RING0_INT_FRAME
14971 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
14972 pushl_cfi $do_invalid_op
14973 jmp error_code
14974 CFI_ENDPROC
14975 -END(invalid_op)
14976 +ENDPROC(invalid_op)
14977
14978 ENTRY(coprocessor_segment_overrun)
14979 RING0_INT_FRAME
14980 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
14981 pushl_cfi $do_coprocessor_segment_overrun
14982 jmp error_code
14983 CFI_ENDPROC
14984 -END(coprocessor_segment_overrun)
14985 +ENDPROC(coprocessor_segment_overrun)
14986
14987 ENTRY(invalid_TSS)
14988 RING0_EC_FRAME
14989 pushl_cfi $do_invalid_TSS
14990 jmp error_code
14991 CFI_ENDPROC
14992 -END(invalid_TSS)
14993 +ENDPROC(invalid_TSS)
14994
14995 ENTRY(segment_not_present)
14996 RING0_EC_FRAME
14997 pushl_cfi $do_segment_not_present
14998 jmp error_code
14999 CFI_ENDPROC
15000 -END(segment_not_present)
15001 +ENDPROC(segment_not_present)
15002
15003 ENTRY(stack_segment)
15004 RING0_EC_FRAME
15005 pushl_cfi $do_stack_segment
15006 jmp error_code
15007 CFI_ENDPROC
15008 -END(stack_segment)
15009 +ENDPROC(stack_segment)
15010
15011 ENTRY(alignment_check)
15012 RING0_EC_FRAME
15013 pushl_cfi $do_alignment_check
15014 jmp error_code
15015 CFI_ENDPROC
15016 -END(alignment_check)
15017 +ENDPROC(alignment_check)
15018
15019 ENTRY(divide_error)
15020 RING0_INT_FRAME
15021 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15022 pushl_cfi $do_divide_error
15023 jmp error_code
15024 CFI_ENDPROC
15025 -END(divide_error)
15026 +ENDPROC(divide_error)
15027
15028 #ifdef CONFIG_X86_MCE
15029 ENTRY(machine_check)
15030 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15031 pushl_cfi machine_check_vector
15032 jmp error_code
15033 CFI_ENDPROC
15034 -END(machine_check)
15035 +ENDPROC(machine_check)
15036 #endif
15037
15038 ENTRY(spurious_interrupt_bug)
15039 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15040 pushl_cfi $do_spurious_interrupt_bug
15041 jmp error_code
15042 CFI_ENDPROC
15043 -END(spurious_interrupt_bug)
15044 +ENDPROC(spurious_interrupt_bug)
15045 /*
15046 * End of kprobes section
15047 */
15048 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15049
15050 ENTRY(mcount)
15051 ret
15052 -END(mcount)
15053 +ENDPROC(mcount)
15054
15055 ENTRY(ftrace_caller)
15056 cmpl $0, function_trace_stop
15057 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15058 .globl ftrace_stub
15059 ftrace_stub:
15060 ret
15061 -END(ftrace_caller)
15062 +ENDPROC(ftrace_caller)
15063
15064 #else /* ! CONFIG_DYNAMIC_FTRACE */
15065
15066 @@ -1177,7 +1424,7 @@ trace:
15067 popl %ecx
15068 popl %eax
15069 jmp ftrace_stub
15070 -END(mcount)
15071 +ENDPROC(mcount)
15072 #endif /* CONFIG_DYNAMIC_FTRACE */
15073 #endif /* CONFIG_FUNCTION_TRACER */
15074
15075 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15076 popl %ecx
15077 popl %eax
15078 ret
15079 -END(ftrace_graph_caller)
15080 +ENDPROC(ftrace_graph_caller)
15081
15082 .globl return_to_handler
15083 return_to_handler:
15084 @@ -1253,15 +1500,18 @@ error_code:
15085 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15086 REG_TO_PTGS %ecx
15087 SET_KERNEL_GS %ecx
15088 - movl $(__USER_DS), %ecx
15089 + movl $(__KERNEL_DS), %ecx
15090 movl %ecx, %ds
15091 movl %ecx, %es
15092 +
15093 + pax_enter_kernel
15094 +
15095 TRACE_IRQS_OFF
15096 movl %esp,%eax # pt_regs pointer
15097 call *%edi
15098 jmp ret_from_exception
15099 CFI_ENDPROC
15100 -END(page_fault)
15101 +ENDPROC(page_fault)
15102
15103 /*
15104 * Debug traps and NMI can happen at the one SYSENTER instruction
15105 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15106 call do_debug
15107 jmp ret_from_exception
15108 CFI_ENDPROC
15109 -END(debug)
15110 +ENDPROC(debug)
15111
15112 /*
15113 * NMI is doubly nasty. It can happen _while_ we're handling
15114 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15115 xorl %edx,%edx # zero error code
15116 movl %esp,%eax # pt_regs pointer
15117 call do_nmi
15118 +
15119 + pax_exit_kernel
15120 +
15121 jmp restore_all_notrace
15122 CFI_ENDPROC
15123
15124 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15125 FIXUP_ESPFIX_STACK # %eax == %esp
15126 xorl %edx,%edx # zero error code
15127 call do_nmi
15128 +
15129 + pax_exit_kernel
15130 +
15131 RESTORE_REGS
15132 lss 12+4(%esp), %esp # back to espfix stack
15133 CFI_ADJUST_CFA_OFFSET -24
15134 jmp irq_return
15135 CFI_ENDPROC
15136 -END(nmi)
15137 +ENDPROC(nmi)
15138
15139 ENTRY(int3)
15140 RING0_INT_FRAME
15141 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15142 call do_int3
15143 jmp ret_from_exception
15144 CFI_ENDPROC
15145 -END(int3)
15146 +ENDPROC(int3)
15147
15148 ENTRY(general_protection)
15149 RING0_EC_FRAME
15150 pushl_cfi $do_general_protection
15151 jmp error_code
15152 CFI_ENDPROC
15153 -END(general_protection)
15154 +ENDPROC(general_protection)
15155
15156 #ifdef CONFIG_KVM_GUEST
15157 ENTRY(async_page_fault)
15158 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15159 pushl_cfi $do_async_page_fault
15160 jmp error_code
15161 CFI_ENDPROC
15162 -END(async_page_fault)
15163 +ENDPROC(async_page_fault)
15164 #endif
15165
15166 /*
15167 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15168 index 1333d98..b340ca2 100644
15169 --- a/arch/x86/kernel/entry_64.S
15170 +++ b/arch/x86/kernel/entry_64.S
15171 @@ -56,6 +56,8 @@
15172 #include <asm/ftrace.h>
15173 #include <asm/percpu.h>
15174 #include <linux/err.h>
15175 +#include <asm/pgtable.h>
15176 +#include <asm/alternative-asm.h>
15177
15178 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15179 #include <linux/elf-em.h>
15180 @@ -69,8 +71,9 @@
15181 #ifdef CONFIG_FUNCTION_TRACER
15182 #ifdef CONFIG_DYNAMIC_FTRACE
15183 ENTRY(mcount)
15184 + pax_force_retaddr
15185 retq
15186 -END(mcount)
15187 +ENDPROC(mcount)
15188
15189 ENTRY(ftrace_caller)
15190 cmpl $0, function_trace_stop
15191 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15192 #endif
15193
15194 GLOBAL(ftrace_stub)
15195 + pax_force_retaddr
15196 retq
15197 -END(ftrace_caller)
15198 +ENDPROC(ftrace_caller)
15199
15200 #else /* ! CONFIG_DYNAMIC_FTRACE */
15201 ENTRY(mcount)
15202 @@ -113,6 +117,7 @@ ENTRY(mcount)
15203 #endif
15204
15205 GLOBAL(ftrace_stub)
15206 + pax_force_retaddr
15207 retq
15208
15209 trace:
15210 @@ -122,12 +127,13 @@ trace:
15211 movq 8(%rbp), %rsi
15212 subq $MCOUNT_INSN_SIZE, %rdi
15213
15214 + pax_force_fptr ftrace_trace_function
15215 call *ftrace_trace_function
15216
15217 MCOUNT_RESTORE_FRAME
15218
15219 jmp ftrace_stub
15220 -END(mcount)
15221 +ENDPROC(mcount)
15222 #endif /* CONFIG_DYNAMIC_FTRACE */
15223 #endif /* CONFIG_FUNCTION_TRACER */
15224
15225 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15226
15227 MCOUNT_RESTORE_FRAME
15228
15229 + pax_force_retaddr
15230 retq
15231 -END(ftrace_graph_caller)
15232 +ENDPROC(ftrace_graph_caller)
15233
15234 GLOBAL(return_to_handler)
15235 subq $24, %rsp
15236 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15237 movq 8(%rsp), %rdx
15238 movq (%rsp), %rax
15239 addq $24, %rsp
15240 + pax_force_fptr %rdi
15241 jmp *%rdi
15242 #endif
15243
15244 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15245 ENDPROC(native_usergs_sysret64)
15246 #endif /* CONFIG_PARAVIRT */
15247
15248 + .macro ljmpq sel, off
15249 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15250 + .byte 0x48; ljmp *1234f(%rip)
15251 + .pushsection .rodata
15252 + .align 16
15253 + 1234: .quad \off; .word \sel
15254 + .popsection
15255 +#else
15256 + pushq $\sel
15257 + pushq $\off
15258 + lretq
15259 +#endif
15260 + .endm
15261 +
15262 + .macro pax_enter_kernel
15263 + pax_set_fptr_mask
15264 +#ifdef CONFIG_PAX_KERNEXEC
15265 + call pax_enter_kernel
15266 +#endif
15267 + .endm
15268 +
15269 + .macro pax_exit_kernel
15270 +#ifdef CONFIG_PAX_KERNEXEC
15271 + call pax_exit_kernel
15272 +#endif
15273 + .endm
15274 +
15275 +#ifdef CONFIG_PAX_KERNEXEC
15276 +ENTRY(pax_enter_kernel)
15277 + pushq %rdi
15278 +
15279 +#ifdef CONFIG_PARAVIRT
15280 + PV_SAVE_REGS(CLBR_RDI)
15281 +#endif
15282 +
15283 + GET_CR0_INTO_RDI
15284 + bts $16,%rdi
15285 + jnc 3f
15286 + mov %cs,%edi
15287 + cmp $__KERNEL_CS,%edi
15288 + jnz 2f
15289 +1:
15290 +
15291 +#ifdef CONFIG_PARAVIRT
15292 + PV_RESTORE_REGS(CLBR_RDI)
15293 +#endif
15294 +
15295 + popq %rdi
15296 + pax_force_retaddr
15297 + retq
15298 +
15299 +2: ljmpq __KERNEL_CS,1f
15300 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15301 +4: SET_RDI_INTO_CR0
15302 + jmp 1b
15303 +ENDPROC(pax_enter_kernel)
15304 +
15305 +ENTRY(pax_exit_kernel)
15306 + pushq %rdi
15307 +
15308 +#ifdef CONFIG_PARAVIRT
15309 + PV_SAVE_REGS(CLBR_RDI)
15310 +#endif
15311 +
15312 + mov %cs,%rdi
15313 + cmp $__KERNEXEC_KERNEL_CS,%edi
15314 + jz 2f
15315 +1:
15316 +
15317 +#ifdef CONFIG_PARAVIRT
15318 + PV_RESTORE_REGS(CLBR_RDI);
15319 +#endif
15320 +
15321 + popq %rdi
15322 + pax_force_retaddr
15323 + retq
15324 +
15325 +2: GET_CR0_INTO_RDI
15326 + btr $16,%rdi
15327 + ljmpq __KERNEL_CS,3f
15328 +3: SET_RDI_INTO_CR0
15329 + jmp 1b
15330 +#ifdef CONFIG_PARAVIRT
15331 + PV_RESTORE_REGS(CLBR_RDI);
15332 +#endif
15333 +
15334 + popq %rdi
15335 + pax_force_retaddr
15336 + retq
15337 +ENDPROC(pax_exit_kernel)
15338 +#endif
15339 +
15340 + .macro pax_enter_kernel_user
15341 + pax_set_fptr_mask
15342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15343 + call pax_enter_kernel_user
15344 +#endif
15345 + .endm
15346 +
15347 + .macro pax_exit_kernel_user
15348 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15349 + call pax_exit_kernel_user
15350 +#endif
15351 +#ifdef CONFIG_PAX_RANDKSTACK
15352 + pushq %rax
15353 + call pax_randomize_kstack
15354 + popq %rax
15355 +#endif
15356 + .endm
15357 +
15358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15359 +ENTRY(pax_enter_kernel_user)
15360 + pushq %rdi
15361 + pushq %rbx
15362 +
15363 +#ifdef CONFIG_PARAVIRT
15364 + PV_SAVE_REGS(CLBR_RDI)
15365 +#endif
15366 +
15367 + GET_CR3_INTO_RDI
15368 + mov %rdi,%rbx
15369 + add $__START_KERNEL_map,%rbx
15370 + sub phys_base(%rip),%rbx
15371 +
15372 +#ifdef CONFIG_PARAVIRT
15373 + pushq %rdi
15374 + cmpl $0, pv_info+PARAVIRT_enabled
15375 + jz 1f
15376 + i = 0
15377 + .rept USER_PGD_PTRS
15378 + mov i*8(%rbx),%rsi
15379 + mov $0,%sil
15380 + lea i*8(%rbx),%rdi
15381 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15382 + i = i + 1
15383 + .endr
15384 + jmp 2f
15385 +1:
15386 +#endif
15387 +
15388 + i = 0
15389 + .rept USER_PGD_PTRS
15390 + movb $0,i*8(%rbx)
15391 + i = i + 1
15392 + .endr
15393 +
15394 +#ifdef CONFIG_PARAVIRT
15395 +2: popq %rdi
15396 +#endif
15397 + SET_RDI_INTO_CR3
15398 +
15399 +#ifdef CONFIG_PAX_KERNEXEC
15400 + GET_CR0_INTO_RDI
15401 + bts $16,%rdi
15402 + SET_RDI_INTO_CR0
15403 +#endif
15404 +
15405 +#ifdef CONFIG_PARAVIRT
15406 + PV_RESTORE_REGS(CLBR_RDI)
15407 +#endif
15408 +
15409 + popq %rbx
15410 + popq %rdi
15411 + pax_force_retaddr
15412 + retq
15413 +ENDPROC(pax_enter_kernel_user)
15414 +
15415 +ENTRY(pax_exit_kernel_user)
15416 + push %rdi
15417 +
15418 +#ifdef CONFIG_PARAVIRT
15419 + pushq %rbx
15420 + PV_SAVE_REGS(CLBR_RDI)
15421 +#endif
15422 +
15423 +#ifdef CONFIG_PAX_KERNEXEC
15424 + GET_CR0_INTO_RDI
15425 + btr $16,%rdi
15426 + SET_RDI_INTO_CR0
15427 +#endif
15428 +
15429 + GET_CR3_INTO_RDI
15430 + add $__START_KERNEL_map,%rdi
15431 + sub phys_base(%rip),%rdi
15432 +
15433 +#ifdef CONFIG_PARAVIRT
15434 + cmpl $0, pv_info+PARAVIRT_enabled
15435 + jz 1f
15436 + mov %rdi,%rbx
15437 + i = 0
15438 + .rept USER_PGD_PTRS
15439 + mov i*8(%rbx),%rsi
15440 + mov $0x67,%sil
15441 + lea i*8(%rbx),%rdi
15442 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15443 + i = i + 1
15444 + .endr
15445 + jmp 2f
15446 +1:
15447 +#endif
15448 +
15449 + i = 0
15450 + .rept USER_PGD_PTRS
15451 + movb $0x67,i*8(%rdi)
15452 + i = i + 1
15453 + .endr
15454 +
15455 +#ifdef CONFIG_PARAVIRT
15456 +2: PV_RESTORE_REGS(CLBR_RDI)
15457 + popq %rbx
15458 +#endif
15459 +
15460 + popq %rdi
15461 + pax_force_retaddr
15462 + retq
15463 +ENDPROC(pax_exit_kernel_user)
15464 +#endif
15465 +
15466 +.macro pax_erase_kstack
15467 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15468 + call pax_erase_kstack
15469 +#endif
15470 +.endm
15471 +
15472 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15473 +/*
15474 + * r11: thread_info
15475 + * rcx, rdx: can be clobbered
15476 + */
15477 +ENTRY(pax_erase_kstack)
15478 + pushq %rdi
15479 + pushq %rax
15480 + pushq %r11
15481 +
15482 + GET_THREAD_INFO(%r11)
15483 + mov TI_lowest_stack(%r11), %rdi
15484 + mov $-0xBEEF, %rax
15485 + std
15486 +
15487 +1: mov %edi, %ecx
15488 + and $THREAD_SIZE_asm - 1, %ecx
15489 + shr $3, %ecx
15490 + repne scasq
15491 + jecxz 2f
15492 +
15493 + cmp $2*8, %ecx
15494 + jc 2f
15495 +
15496 + mov $2*8, %ecx
15497 + repe scasq
15498 + jecxz 2f
15499 + jne 1b
15500 +
15501 +2: cld
15502 + mov %esp, %ecx
15503 + sub %edi, %ecx
15504 +
15505 + cmp $THREAD_SIZE_asm, %rcx
15506 + jb 3f
15507 + ud2
15508 +3:
15509 +
15510 + shr $3, %ecx
15511 + rep stosq
15512 +
15513 + mov TI_task_thread_sp0(%r11), %rdi
15514 + sub $256, %rdi
15515 + mov %rdi, TI_lowest_stack(%r11)
15516 +
15517 + popq %r11
15518 + popq %rax
15519 + popq %rdi
15520 + pax_force_retaddr
15521 + ret
15522 +ENDPROC(pax_erase_kstack)
15523 +#endif
15524
15525 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15526 #ifdef CONFIG_TRACE_IRQFLAGS
15527 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15528 .endm
15529
15530 .macro UNFAKE_STACK_FRAME
15531 - addq $8*6, %rsp
15532 - CFI_ADJUST_CFA_OFFSET -(6*8)
15533 + addq $8*6 + ARG_SKIP, %rsp
15534 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15535 .endm
15536
15537 /*
15538 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15539 movq %rsp, %rsi
15540
15541 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15542 - testl $3, CS(%rdi)
15543 + testb $3, CS(%rdi)
15544 je 1f
15545 SWAPGS
15546 /*
15547 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15548 movq_cfi r15, R15+16
15549 movq %r11, 8(%rsp) /* return address */
15550 FIXUP_TOP_OF_STACK %r11, 16
15551 + pax_force_retaddr
15552 ret
15553 CFI_ENDPROC
15554 -END(save_rest)
15555 +ENDPROC(save_rest)
15556
15557 /* save complete stack frame */
15558 .pushsection .kprobes.text, "ax"
15559 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15560 js 1f /* negative -> in kernel */
15561 SWAPGS
15562 xorl %ebx,%ebx
15563 -1: ret
15564 +1: pax_force_retaddr_bts
15565 + ret
15566 CFI_ENDPROC
15567 -END(save_paranoid)
15568 +ENDPROC(save_paranoid)
15569 .popsection
15570
15571 /*
15572 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15573
15574 RESTORE_REST
15575
15576 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15577 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15578 jz retint_restore_args
15579
15580 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15581 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15582 jmp ret_from_sys_call # go to the SYSRET fastpath
15583
15584 CFI_ENDPROC
15585 -END(ret_from_fork)
15586 +ENDPROC(ret_from_fork)
15587
15588 /*
15589 * System call entry. Up to 6 arguments in registers are supported.
15590 @@ -457,7 +743,7 @@ END(ret_from_fork)
15591 ENTRY(system_call)
15592 CFI_STARTPROC simple
15593 CFI_SIGNAL_FRAME
15594 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15595 + CFI_DEF_CFA rsp,0
15596 CFI_REGISTER rip,rcx
15597 /*CFI_REGISTER rflags,r11*/
15598 SWAPGS_UNSAFE_STACK
15599 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15600
15601 movq %rsp,PER_CPU_VAR(old_rsp)
15602 movq PER_CPU_VAR(kernel_stack),%rsp
15603 + SAVE_ARGS 8*6,0
15604 + pax_enter_kernel_user
15605 /*
15606 * No need to follow this irqs off/on section - it's straight
15607 * and short:
15608 */
15609 ENABLE_INTERRUPTS(CLBR_NONE)
15610 - SAVE_ARGS 8,0
15611 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15612 movq %rcx,RIP-ARGOFFSET(%rsp)
15613 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15614 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15615 + GET_THREAD_INFO(%rcx)
15616 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15617 jnz tracesys
15618 system_call_fastpath:
15619 cmpq $__NR_syscall_max,%rax
15620 ja badsys
15621 - movq %r10,%rcx
15622 + movq R10-ARGOFFSET(%rsp),%rcx
15623 call *sys_call_table(,%rax,8) # XXX: rip relative
15624 movq %rax,RAX-ARGOFFSET(%rsp)
15625 /*
15626 @@ -498,10 +786,13 @@ sysret_check:
15627 LOCKDEP_SYS_EXIT
15628 DISABLE_INTERRUPTS(CLBR_NONE)
15629 TRACE_IRQS_OFF
15630 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15631 + GET_THREAD_INFO(%rcx)
15632 + movl TI_flags(%rcx),%edx
15633 andl %edi,%edx
15634 jnz sysret_careful
15635 CFI_REMEMBER_STATE
15636 + pax_exit_kernel_user
15637 + pax_erase_kstack
15638 /*
15639 * sysretq will re-enable interrupts:
15640 */
15641 @@ -553,14 +844,18 @@ badsys:
15642 * jump back to the normal fast path.
15643 */
15644 auditsys:
15645 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15646 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15647 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15648 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15649 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15650 movq %rax,%rsi /* 2nd arg: syscall number */
15651 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15652 call __audit_syscall_entry
15653 +
15654 + pax_erase_kstack
15655 +
15656 LOAD_ARGS 0 /* reload call-clobbered registers */
15657 + pax_set_fptr_mask
15658 jmp system_call_fastpath
15659
15660 /*
15661 @@ -581,7 +876,7 @@ sysret_audit:
15662 /* Do syscall tracing */
15663 tracesys:
15664 #ifdef CONFIG_AUDITSYSCALL
15665 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15666 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15667 jz auditsys
15668 #endif
15669 SAVE_REST
15670 @@ -589,16 +884,20 @@ tracesys:
15671 FIXUP_TOP_OF_STACK %rdi
15672 movq %rsp,%rdi
15673 call syscall_trace_enter
15674 +
15675 + pax_erase_kstack
15676 +
15677 /*
15678 * Reload arg registers from stack in case ptrace changed them.
15679 * We don't reload %rax because syscall_trace_enter() returned
15680 * the value it wants us to use in the table lookup.
15681 */
15682 LOAD_ARGS ARGOFFSET, 1
15683 + pax_set_fptr_mask
15684 RESTORE_REST
15685 cmpq $__NR_syscall_max,%rax
15686 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15687 - movq %r10,%rcx /* fixup for C */
15688 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15689 call *sys_call_table(,%rax,8)
15690 movq %rax,RAX-ARGOFFSET(%rsp)
15691 /* Use IRET because user could have changed frame */
15692 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15693 andl %edi,%edx
15694 jnz int_careful
15695 andl $~TS_COMPAT,TI_status(%rcx)
15696 + pax_erase_kstack
15697 jmp retint_swapgs
15698
15699 /* Either reschedule or signal or syscall exit tracking needed. */
15700 @@ -665,7 +965,7 @@ int_restore_rest:
15701 TRACE_IRQS_OFF
15702 jmp int_with_check
15703 CFI_ENDPROC
15704 -END(system_call)
15705 +ENDPROC(system_call)
15706
15707 /*
15708 * Certain special system calls that need to save a complete full stack frame.
15709 @@ -681,7 +981,7 @@ ENTRY(\label)
15710 call \func
15711 jmp ptregscall_common
15712 CFI_ENDPROC
15713 -END(\label)
15714 +ENDPROC(\label)
15715 .endm
15716
15717 PTREGSCALL stub_clone, sys_clone, %r8
15718 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15719 movq_cfi_restore R12+8, r12
15720 movq_cfi_restore RBP+8, rbp
15721 movq_cfi_restore RBX+8, rbx
15722 + pax_force_retaddr
15723 ret $REST_SKIP /* pop extended registers */
15724 CFI_ENDPROC
15725 -END(ptregscall_common)
15726 +ENDPROC(ptregscall_common)
15727
15728 ENTRY(stub_execve)
15729 CFI_STARTPROC
15730 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15731 RESTORE_REST
15732 jmp int_ret_from_sys_call
15733 CFI_ENDPROC
15734 -END(stub_execve)
15735 +ENDPROC(stub_execve)
15736
15737 /*
15738 * sigreturn is special because it needs to restore all registers on return.
15739 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15740 RESTORE_REST
15741 jmp int_ret_from_sys_call
15742 CFI_ENDPROC
15743 -END(stub_rt_sigreturn)
15744 +ENDPROC(stub_rt_sigreturn)
15745
15746 /*
15747 * Build the entry stubs and pointer table with some assembler magic.
15748 @@ -769,7 +1070,7 @@ vector=vector+1
15749 2: jmp common_interrupt
15750 .endr
15751 CFI_ENDPROC
15752 -END(irq_entries_start)
15753 +ENDPROC(irq_entries_start)
15754
15755 .previous
15756 END(interrupt)
15757 @@ -789,6 +1090,16 @@ END(interrupt)
15758 subq $ORIG_RAX-RBP, %rsp
15759 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15760 SAVE_ARGS_IRQ
15761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15762 + testb $3, CS(%rdi)
15763 + jnz 1f
15764 + pax_enter_kernel
15765 + jmp 2f
15766 +1: pax_enter_kernel_user
15767 +2:
15768 +#else
15769 + pax_enter_kernel
15770 +#endif
15771 call \func
15772 .endm
15773
15774 @@ -820,7 +1131,7 @@ ret_from_intr:
15775
15776 exit_intr:
15777 GET_THREAD_INFO(%rcx)
15778 - testl $3,CS-ARGOFFSET(%rsp)
15779 + testb $3,CS-ARGOFFSET(%rsp)
15780 je retint_kernel
15781
15782 /* Interrupt came from user space */
15783 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15784 * The iretq could re-enable interrupts:
15785 */
15786 DISABLE_INTERRUPTS(CLBR_ANY)
15787 + pax_exit_kernel_user
15788 TRACE_IRQS_IRETQ
15789 SWAPGS
15790 jmp restore_args
15791
15792 retint_restore_args: /* return to kernel space */
15793 DISABLE_INTERRUPTS(CLBR_ANY)
15794 + pax_exit_kernel
15795 + pax_force_retaddr RIP-ARGOFFSET
15796 /*
15797 * The iretq could re-enable interrupts:
15798 */
15799 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15800 #endif
15801
15802 CFI_ENDPROC
15803 -END(common_interrupt)
15804 +ENDPROC(common_interrupt)
15805 /*
15806 * End of kprobes section
15807 */
15808 @@ -953,7 +1267,7 @@ ENTRY(\sym)
15809 interrupt \do_sym
15810 jmp ret_from_intr
15811 CFI_ENDPROC
15812 -END(\sym)
15813 +ENDPROC(\sym)
15814 .endm
15815
15816 #ifdef CONFIG_SMP
15817 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
15818 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15819 call error_entry
15820 DEFAULT_FRAME 0
15821 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15822 + testb $3, CS(%rsp)
15823 + jnz 1f
15824 + pax_enter_kernel
15825 + jmp 2f
15826 +1: pax_enter_kernel_user
15827 +2:
15828 +#else
15829 + pax_enter_kernel
15830 +#endif
15831 movq %rsp,%rdi /* pt_regs pointer */
15832 xorl %esi,%esi /* no error code */
15833 call \do_sym
15834 jmp error_exit /* %ebx: no swapgs flag */
15835 CFI_ENDPROC
15836 -END(\sym)
15837 +ENDPROC(\sym)
15838 .endm
15839
15840 .macro paranoidzeroentry sym do_sym
15841 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
15842 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15843 call save_paranoid
15844 TRACE_IRQS_OFF
15845 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15846 + testb $3, CS(%rsp)
15847 + jnz 1f
15848 + pax_enter_kernel
15849 + jmp 2f
15850 +1: pax_enter_kernel_user
15851 +2:
15852 +#else
15853 + pax_enter_kernel
15854 +#endif
15855 movq %rsp,%rdi /* pt_regs pointer */
15856 xorl %esi,%esi /* no error code */
15857 call \do_sym
15858 jmp paranoid_exit /* %ebx: no swapgs flag */
15859 CFI_ENDPROC
15860 -END(\sym)
15861 +ENDPROC(\sym)
15862 .endm
15863
15864 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15865 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15866 .macro paranoidzeroentry_ist sym do_sym ist
15867 ENTRY(\sym)
15868 INTR_FRAME
15869 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
15870 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15871 call save_paranoid
15872 TRACE_IRQS_OFF
15873 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15874 + testb $3, CS(%rsp)
15875 + jnz 1f
15876 + pax_enter_kernel
15877 + jmp 2f
15878 +1: pax_enter_kernel_user
15879 +2:
15880 +#else
15881 + pax_enter_kernel
15882 +#endif
15883 movq %rsp,%rdi /* pt_regs pointer */
15884 xorl %esi,%esi /* no error code */
15885 +#ifdef CONFIG_SMP
15886 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15887 + lea init_tss(%r12), %r12
15888 +#else
15889 + lea init_tss(%rip), %r12
15890 +#endif
15891 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15892 call \do_sym
15893 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15894 jmp paranoid_exit /* %ebx: no swapgs flag */
15895 CFI_ENDPROC
15896 -END(\sym)
15897 +ENDPROC(\sym)
15898 .endm
15899
15900 .macro errorentry sym do_sym
15901 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
15902 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15903 call error_entry
15904 DEFAULT_FRAME 0
15905 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15906 + testb $3, CS(%rsp)
15907 + jnz 1f
15908 + pax_enter_kernel
15909 + jmp 2f
15910 +1: pax_enter_kernel_user
15911 +2:
15912 +#else
15913 + pax_enter_kernel
15914 +#endif
15915 movq %rsp,%rdi /* pt_regs pointer */
15916 movq ORIG_RAX(%rsp),%rsi /* get error code */
15917 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15918 call \do_sym
15919 jmp error_exit /* %ebx: no swapgs flag */
15920 CFI_ENDPROC
15921 -END(\sym)
15922 +ENDPROC(\sym)
15923 .endm
15924
15925 /* error code is on the stack already */
15926 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
15927 call save_paranoid
15928 DEFAULT_FRAME 0
15929 TRACE_IRQS_OFF
15930 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15931 + testb $3, CS(%rsp)
15932 + jnz 1f
15933 + pax_enter_kernel
15934 + jmp 2f
15935 +1: pax_enter_kernel_user
15936 +2:
15937 +#else
15938 + pax_enter_kernel
15939 +#endif
15940 movq %rsp,%rdi /* pt_regs pointer */
15941 movq ORIG_RAX(%rsp),%rsi /* get error code */
15942 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15943 call \do_sym
15944 jmp paranoid_exit /* %ebx: no swapgs flag */
15945 CFI_ENDPROC
15946 -END(\sym)
15947 +ENDPROC(\sym)
15948 .endm
15949
15950 zeroentry divide_error do_divide_error
15951 @@ -1134,9 +1504,10 @@ gs_change:
15952 2: mfence /* workaround */
15953 SWAPGS
15954 popfq_cfi
15955 + pax_force_retaddr
15956 ret
15957 CFI_ENDPROC
15958 -END(native_load_gs_index)
15959 +ENDPROC(native_load_gs_index)
15960
15961 .section __ex_table,"a"
15962 .align 8
15963 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
15964 * Here we are in the child and the registers are set as they were
15965 * at kernel_thread() invocation in the parent.
15966 */
15967 + pax_force_fptr %rsi
15968 call *%rsi
15969 # exit
15970 mov %eax, %edi
15971 call do_exit
15972 ud2 # padding for call trace
15973 CFI_ENDPROC
15974 -END(kernel_thread_helper)
15975 +ENDPROC(kernel_thread_helper)
15976
15977 /*
15978 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15979 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
15980 RESTORE_REST
15981 testq %rax,%rax
15982 je int_ret_from_sys_call
15983 - RESTORE_ARGS
15984 UNFAKE_STACK_FRAME
15985 + pax_force_retaddr
15986 ret
15987 CFI_ENDPROC
15988 -END(kernel_execve)
15989 +ENDPROC(kernel_execve)
15990
15991 /* Call softirq on interrupt stack. Interrupts are off. */
15992 ENTRY(call_softirq)
15993 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
15994 CFI_DEF_CFA_REGISTER rsp
15995 CFI_ADJUST_CFA_OFFSET -8
15996 decl PER_CPU_VAR(irq_count)
15997 + pax_force_retaddr
15998 ret
15999 CFI_ENDPROC
16000 -END(call_softirq)
16001 +ENDPROC(call_softirq)
16002
16003 #ifdef CONFIG_XEN
16004 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16005 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16006 decl PER_CPU_VAR(irq_count)
16007 jmp error_exit
16008 CFI_ENDPROC
16009 -END(xen_do_hypervisor_callback)
16010 +ENDPROC(xen_do_hypervisor_callback)
16011
16012 /*
16013 * Hypervisor uses this for application faults while it executes.
16014 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16015 SAVE_ALL
16016 jmp error_exit
16017 CFI_ENDPROC
16018 -END(xen_failsafe_callback)
16019 +ENDPROC(xen_failsafe_callback)
16020
16021 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16022 xen_hvm_callback_vector xen_evtchn_do_upcall
16023 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16024 TRACE_IRQS_OFF
16025 testl %ebx,%ebx /* swapgs needed? */
16026 jnz paranoid_restore
16027 - testl $3,CS(%rsp)
16028 + testb $3,CS(%rsp)
16029 jnz paranoid_userspace
16030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16031 + pax_exit_kernel
16032 + TRACE_IRQS_IRETQ 0
16033 + SWAPGS_UNSAFE_STACK
16034 + RESTORE_ALL 8
16035 + pax_force_retaddr_bts
16036 + jmp irq_return
16037 +#endif
16038 paranoid_swapgs:
16039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16040 + pax_exit_kernel_user
16041 +#else
16042 + pax_exit_kernel
16043 +#endif
16044 TRACE_IRQS_IRETQ 0
16045 SWAPGS_UNSAFE_STACK
16046 RESTORE_ALL 8
16047 jmp irq_return
16048 paranoid_restore:
16049 + pax_exit_kernel
16050 TRACE_IRQS_IRETQ 0
16051 RESTORE_ALL 8
16052 + pax_force_retaddr_bts
16053 jmp irq_return
16054 paranoid_userspace:
16055 GET_THREAD_INFO(%rcx)
16056 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16057 TRACE_IRQS_OFF
16058 jmp paranoid_userspace
16059 CFI_ENDPROC
16060 -END(paranoid_exit)
16061 +ENDPROC(paranoid_exit)
16062
16063 /*
16064 * Exception entry point. This expects an error code/orig_rax on the stack.
16065 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16066 movq_cfi r14, R14+8
16067 movq_cfi r15, R15+8
16068 xorl %ebx,%ebx
16069 - testl $3,CS+8(%rsp)
16070 + testb $3,CS+8(%rsp)
16071 je error_kernelspace
16072 error_swapgs:
16073 SWAPGS
16074 error_sti:
16075 TRACE_IRQS_OFF
16076 + pax_force_retaddr_bts
16077 ret
16078
16079 /*
16080 @@ -1458,7 +1847,7 @@ bstep_iret:
16081 movq %rcx,RIP+8(%rsp)
16082 jmp error_swapgs
16083 CFI_ENDPROC
16084 -END(error_entry)
16085 +ENDPROC(error_entry)
16086
16087
16088 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16089 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16090 jnz retint_careful
16091 jmp retint_swapgs
16092 CFI_ENDPROC
16093 -END(error_exit)
16094 +ENDPROC(error_exit)
16095
16096 /*
16097 * Test if a given stack is an NMI stack or not.
16098 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16099 * If %cs was not the kernel segment, then the NMI triggered in user
16100 * space, which means it is definitely not nested.
16101 */
16102 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16103 + je 1f
16104 cmpl $__KERNEL_CS, 16(%rsp)
16105 jne first_nmi
16106 -
16107 +1:
16108 /*
16109 * Check the special variable on the stack to see if NMIs are
16110 * executing.
16111 @@ -1659,6 +2050,16 @@ restart_nmi:
16112 */
16113 call save_paranoid
16114 DEFAULT_FRAME 0
16115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16116 + testb $3, CS(%rsp)
16117 + jnz 1f
16118 + pax_enter_kernel
16119 + jmp 2f
16120 +1: pax_enter_kernel_user
16121 +2:
16122 +#else
16123 + pax_enter_kernel
16124 +#endif
16125 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16126 movq %rsp,%rdi
16127 movq $-1,%rsi
16128 @@ -1666,14 +2067,25 @@ restart_nmi:
16129 testl %ebx,%ebx /* swapgs needed? */
16130 jnz nmi_restore
16131 nmi_swapgs:
16132 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16133 + pax_exit_kernel_user
16134 +#else
16135 + pax_exit_kernel
16136 +#endif
16137 SWAPGS_UNSAFE_STACK
16138 + RESTORE_ALL 8
16139 + /* Clear the NMI executing stack variable */
16140 + movq $0, 10*8(%rsp)
16141 + jmp irq_return
16142 nmi_restore:
16143 + pax_exit_kernel
16144 RESTORE_ALL 8
16145 + pax_force_retaddr_bts
16146 /* Clear the NMI executing stack variable */
16147 movq $0, 10*8(%rsp)
16148 jmp irq_return
16149 CFI_ENDPROC
16150 -END(nmi)
16151 +ENDPROC(nmi)
16152
16153 /*
16154 * If an NMI hit an iret because of an exception or breakpoint,
16155 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16156 mov $-ENOSYS,%eax
16157 sysret
16158 CFI_ENDPROC
16159 -END(ignore_sysret)
16160 +ENDPROC(ignore_sysret)
16161
16162 /*
16163 * End of kprobes section
16164 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16165 index c9a281f..ce2f317 100644
16166 --- a/arch/x86/kernel/ftrace.c
16167 +++ b/arch/x86/kernel/ftrace.c
16168 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16169 static const void *mod_code_newcode; /* holds the text to write to the IP */
16170
16171 static unsigned nmi_wait_count;
16172 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16173 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16174
16175 int ftrace_arch_read_dyn_info(char *buf, int size)
16176 {
16177 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16178
16179 r = snprintf(buf, size, "%u %u",
16180 nmi_wait_count,
16181 - atomic_read(&nmi_update_count));
16182 + atomic_read_unchecked(&nmi_update_count));
16183 return r;
16184 }
16185
16186 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16187
16188 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16189 smp_rmb();
16190 + pax_open_kernel();
16191 ftrace_mod_code();
16192 - atomic_inc(&nmi_update_count);
16193 + pax_close_kernel();
16194 + atomic_inc_unchecked(&nmi_update_count);
16195 }
16196 /* Must have previous changes seen before executions */
16197 smp_mb();
16198 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16199 {
16200 unsigned char replaced[MCOUNT_INSN_SIZE];
16201
16202 + ip = ktla_ktva(ip);
16203 +
16204 /*
16205 * Note: Due to modules and __init, code can
16206 * disappear and change, we need to protect against faulting
16207 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16208 unsigned char old[MCOUNT_INSN_SIZE], *new;
16209 int ret;
16210
16211 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16212 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16213 new = ftrace_call_replace(ip, (unsigned long)func);
16214 ret = ftrace_modify_code(ip, old, new);
16215
16216 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16217 {
16218 unsigned char code[MCOUNT_INSN_SIZE];
16219
16220 + ip = ktla_ktva(ip);
16221 +
16222 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16223 return -EFAULT;
16224
16225 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16226 index 51ff186..9e77418 100644
16227 --- a/arch/x86/kernel/head32.c
16228 +++ b/arch/x86/kernel/head32.c
16229 @@ -19,6 +19,7 @@
16230 #include <asm/io_apic.h>
16231 #include <asm/bios_ebda.h>
16232 #include <asm/tlbflush.h>
16233 +#include <asm/boot.h>
16234
16235 static void __init i386_default_early_setup(void)
16236 {
16237 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16238
16239 void __init i386_start_kernel(void)
16240 {
16241 - memblock_reserve(__pa_symbol(&_text),
16242 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16243 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16244
16245 #ifdef CONFIG_BLK_DEV_INITRD
16246 /* Reserve INITRD */
16247 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16248 index ce0be7c..c41476e 100644
16249 --- a/arch/x86/kernel/head_32.S
16250 +++ b/arch/x86/kernel/head_32.S
16251 @@ -25,6 +25,12 @@
16252 /* Physical address */
16253 #define pa(X) ((X) - __PAGE_OFFSET)
16254
16255 +#ifdef CONFIG_PAX_KERNEXEC
16256 +#define ta(X) (X)
16257 +#else
16258 +#define ta(X) ((X) - __PAGE_OFFSET)
16259 +#endif
16260 +
16261 /*
16262 * References to members of the new_cpu_data structure.
16263 */
16264 @@ -54,11 +60,7 @@
16265 * and small than max_low_pfn, otherwise will waste some page table entries
16266 */
16267
16268 -#if PTRS_PER_PMD > 1
16269 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16270 -#else
16271 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16272 -#endif
16273 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16274
16275 /* Number of possible pages in the lowmem region */
16276 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16277 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16278 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16279
16280 /*
16281 + * Real beginning of normal "text" segment
16282 + */
16283 +ENTRY(stext)
16284 +ENTRY(_stext)
16285 +
16286 +/*
16287 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16288 * %esi points to the real-mode code as a 32-bit pointer.
16289 * CS and DS must be 4 GB flat segments, but we don't depend on
16290 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16291 * can.
16292 */
16293 __HEAD
16294 +
16295 +#ifdef CONFIG_PAX_KERNEXEC
16296 + jmp startup_32
16297 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16298 +.fill PAGE_SIZE-5,1,0xcc
16299 +#endif
16300 +
16301 ENTRY(startup_32)
16302 movl pa(stack_start),%ecx
16303
16304 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16305 2:
16306 leal -__PAGE_OFFSET(%ecx),%esp
16307
16308 +#ifdef CONFIG_SMP
16309 + movl $pa(cpu_gdt_table),%edi
16310 + movl $__per_cpu_load,%eax
16311 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16312 + rorl $16,%eax
16313 + movb %al,__KERNEL_PERCPU + 4(%edi)
16314 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16315 + movl $__per_cpu_end - 1,%eax
16316 + subl $__per_cpu_start,%eax
16317 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16318 +#endif
16319 +
16320 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16321 + movl $NR_CPUS,%ecx
16322 + movl $pa(cpu_gdt_table),%edi
16323 +1:
16324 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16325 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16326 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16327 + addl $PAGE_SIZE_asm,%edi
16328 + loop 1b
16329 +#endif
16330 +
16331 +#ifdef CONFIG_PAX_KERNEXEC
16332 + movl $pa(boot_gdt),%edi
16333 + movl $__LOAD_PHYSICAL_ADDR,%eax
16334 + movw %ax,__BOOT_CS + 2(%edi)
16335 + rorl $16,%eax
16336 + movb %al,__BOOT_CS + 4(%edi)
16337 + movb %ah,__BOOT_CS + 7(%edi)
16338 + rorl $16,%eax
16339 +
16340 + ljmp $(__BOOT_CS),$1f
16341 +1:
16342 +
16343 + movl $NR_CPUS,%ecx
16344 + movl $pa(cpu_gdt_table),%edi
16345 + addl $__PAGE_OFFSET,%eax
16346 +1:
16347 + movw %ax,__KERNEL_CS + 2(%edi)
16348 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16349 + rorl $16,%eax
16350 + movb %al,__KERNEL_CS + 4(%edi)
16351 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16352 + movb %ah,__KERNEL_CS + 7(%edi)
16353 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16354 + rorl $16,%eax
16355 + addl $PAGE_SIZE_asm,%edi
16356 + loop 1b
16357 +#endif
16358 +
16359 /*
16360 * Clear BSS first so that there are no surprises...
16361 */
16362 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16363 movl %eax, pa(max_pfn_mapped)
16364
16365 /* Do early initialization of the fixmap area */
16366 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16367 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16368 +#ifdef CONFIG_COMPAT_VDSO
16369 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16370 +#else
16371 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16372 +#endif
16373 #else /* Not PAE */
16374
16375 page_pde_offset = (__PAGE_OFFSET >> 20);
16376 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16377 movl %eax, pa(max_pfn_mapped)
16378
16379 /* Do early initialization of the fixmap area */
16380 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16381 - movl %eax,pa(initial_page_table+0xffc)
16382 +#ifdef CONFIG_COMPAT_VDSO
16383 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16384 +#else
16385 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16386 +#endif
16387 #endif
16388
16389 #ifdef CONFIG_PARAVIRT
16390 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16391 cmpl $num_subarch_entries, %eax
16392 jae bad_subarch
16393
16394 - movl pa(subarch_entries)(,%eax,4), %eax
16395 - subl $__PAGE_OFFSET, %eax
16396 - jmp *%eax
16397 + jmp *pa(subarch_entries)(,%eax,4)
16398
16399 bad_subarch:
16400 WEAK(lguest_entry)
16401 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16402 __INITDATA
16403
16404 subarch_entries:
16405 - .long default_entry /* normal x86/PC */
16406 - .long lguest_entry /* lguest hypervisor */
16407 - .long xen_entry /* Xen hypervisor */
16408 - .long default_entry /* Moorestown MID */
16409 + .long ta(default_entry) /* normal x86/PC */
16410 + .long ta(lguest_entry) /* lguest hypervisor */
16411 + .long ta(xen_entry) /* Xen hypervisor */
16412 + .long ta(default_entry) /* Moorestown MID */
16413 num_subarch_entries = (. - subarch_entries) / 4
16414 .previous
16415 #else
16416 @@ -312,6 +382,7 @@ default_entry:
16417 orl %edx,%eax
16418 movl %eax,%cr4
16419
16420 +#ifdef CONFIG_X86_PAE
16421 testb $X86_CR4_PAE, %al # check if PAE is enabled
16422 jz 6f
16423
16424 @@ -340,6 +411,9 @@ default_entry:
16425 /* Make changes effective */
16426 wrmsr
16427
16428 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16429 +#endif
16430 +
16431 6:
16432
16433 /*
16434 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16435 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16436 movl %eax,%ss # after changing gdt.
16437
16438 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16439 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16440 movl %eax,%ds
16441 movl %eax,%es
16442
16443 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16444 */
16445 cmpb $0,ready
16446 jne 1f
16447 - movl $gdt_page,%eax
16448 + movl $cpu_gdt_table,%eax
16449 movl $stack_canary,%ecx
16450 +#ifdef CONFIG_SMP
16451 + addl $__per_cpu_load,%ecx
16452 +#endif
16453 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16454 shrl $16, %ecx
16455 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16456 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16457 1:
16458 -#endif
16459 movl $(__KERNEL_STACK_CANARY),%eax
16460 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16461 + movl $(__USER_DS),%eax
16462 +#else
16463 + xorl %eax,%eax
16464 +#endif
16465 movl %eax,%gs
16466
16467 xorl %eax,%eax # Clear LDT
16468 @@ -558,22 +639,22 @@ early_page_fault:
16469 jmp early_fault
16470
16471 early_fault:
16472 - cld
16473 #ifdef CONFIG_PRINTK
16474 + cmpl $1,%ss:early_recursion_flag
16475 + je hlt_loop
16476 + incl %ss:early_recursion_flag
16477 + cld
16478 pusha
16479 movl $(__KERNEL_DS),%eax
16480 movl %eax,%ds
16481 movl %eax,%es
16482 - cmpl $2,early_recursion_flag
16483 - je hlt_loop
16484 - incl early_recursion_flag
16485 movl %cr2,%eax
16486 pushl %eax
16487 pushl %edx /* trapno */
16488 pushl $fault_msg
16489 call printk
16490 +; call dump_stack
16491 #endif
16492 - call dump_stack
16493 hlt_loop:
16494 hlt
16495 jmp hlt_loop
16496 @@ -581,8 +662,11 @@ hlt_loop:
16497 /* This is the default interrupt "handler" :-) */
16498 ALIGN
16499 ignore_int:
16500 - cld
16501 #ifdef CONFIG_PRINTK
16502 + cmpl $2,%ss:early_recursion_flag
16503 + je hlt_loop
16504 + incl %ss:early_recursion_flag
16505 + cld
16506 pushl %eax
16507 pushl %ecx
16508 pushl %edx
16509 @@ -591,9 +675,6 @@ ignore_int:
16510 movl $(__KERNEL_DS),%eax
16511 movl %eax,%ds
16512 movl %eax,%es
16513 - cmpl $2,early_recursion_flag
16514 - je hlt_loop
16515 - incl early_recursion_flag
16516 pushl 16(%esp)
16517 pushl 24(%esp)
16518 pushl 32(%esp)
16519 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16520 /*
16521 * BSS section
16522 */
16523 -__PAGE_ALIGNED_BSS
16524 - .align PAGE_SIZE
16525 #ifdef CONFIG_X86_PAE
16526 +.section .initial_pg_pmd,"a",@progbits
16527 initial_pg_pmd:
16528 .fill 1024*KPMDS,4,0
16529 #else
16530 +.section .initial_page_table,"a",@progbits
16531 ENTRY(initial_page_table)
16532 .fill 1024,4,0
16533 #endif
16534 +.section .initial_pg_fixmap,"a",@progbits
16535 initial_pg_fixmap:
16536 .fill 1024,4,0
16537 +.section .empty_zero_page,"a",@progbits
16538 ENTRY(empty_zero_page)
16539 .fill 4096,1,0
16540 +.section .swapper_pg_dir,"a",@progbits
16541 ENTRY(swapper_pg_dir)
16542 +#ifdef CONFIG_X86_PAE
16543 + .fill 4,8,0
16544 +#else
16545 .fill 1024,4,0
16546 +#endif
16547 +
16548 +/*
16549 + * The IDT has to be page-aligned to simplify the Pentium
16550 + * F0 0F bug workaround.. We have a special link segment
16551 + * for this.
16552 + */
16553 +.section .idt,"a",@progbits
16554 +ENTRY(idt_table)
16555 + .fill 256,8,0
16556
16557 /*
16558 * This starts the data section.
16559 */
16560 #ifdef CONFIG_X86_PAE
16561 -__PAGE_ALIGNED_DATA
16562 - /* Page-aligned for the benefit of paravirt? */
16563 - .align PAGE_SIZE
16564 +.section .initial_page_table,"a",@progbits
16565 ENTRY(initial_page_table)
16566 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16567 # if KPMDS == 3
16568 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16569 # error "Kernel PMDs should be 1, 2 or 3"
16570 # endif
16571 .align PAGE_SIZE /* needs to be page-sized too */
16572 +
16573 +#ifdef CONFIG_PAX_PER_CPU_PGD
16574 +ENTRY(cpu_pgd)
16575 + .rept NR_CPUS
16576 + .fill 4,8,0
16577 + .endr
16578 +#endif
16579 +
16580 #endif
16581
16582 .data
16583 .balign 4
16584 ENTRY(stack_start)
16585 - .long init_thread_union+THREAD_SIZE
16586 + .long init_thread_union+THREAD_SIZE-8
16587
16588 +ready: .byte 0
16589 +
16590 +.section .rodata,"a",@progbits
16591 early_recursion_flag:
16592 .long 0
16593
16594 -ready: .byte 0
16595 -
16596 int_msg:
16597 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16598
16599 @@ -707,7 +811,7 @@ fault_msg:
16600 .word 0 # 32 bit align gdt_desc.address
16601 boot_gdt_descr:
16602 .word __BOOT_DS+7
16603 - .long boot_gdt - __PAGE_OFFSET
16604 + .long pa(boot_gdt)
16605
16606 .word 0 # 32-bit align idt_desc.address
16607 idt_descr:
16608 @@ -718,7 +822,7 @@ idt_descr:
16609 .word 0 # 32 bit align gdt_desc.address
16610 ENTRY(early_gdt_descr)
16611 .word GDT_ENTRIES*8-1
16612 - .long gdt_page /* Overwritten for secondary CPUs */
16613 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16614
16615 /*
16616 * The boot_gdt must mirror the equivalent in setup.S and is
16617 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16618 .align L1_CACHE_BYTES
16619 ENTRY(boot_gdt)
16620 .fill GDT_ENTRY_BOOT_CS,8,0
16621 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16622 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16623 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16624 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16625 +
16626 + .align PAGE_SIZE_asm
16627 +ENTRY(cpu_gdt_table)
16628 + .rept NR_CPUS
16629 + .quad 0x0000000000000000 /* NULL descriptor */
16630 + .quad 0x0000000000000000 /* 0x0b reserved */
16631 + .quad 0x0000000000000000 /* 0x13 reserved */
16632 + .quad 0x0000000000000000 /* 0x1b reserved */
16633 +
16634 +#ifdef CONFIG_PAX_KERNEXEC
16635 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16636 +#else
16637 + .quad 0x0000000000000000 /* 0x20 unused */
16638 +#endif
16639 +
16640 + .quad 0x0000000000000000 /* 0x28 unused */
16641 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16642 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16643 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16644 + .quad 0x0000000000000000 /* 0x4b reserved */
16645 + .quad 0x0000000000000000 /* 0x53 reserved */
16646 + .quad 0x0000000000000000 /* 0x5b reserved */
16647 +
16648 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16649 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16650 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16651 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16652 +
16653 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16654 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16655 +
16656 + /*
16657 + * Segments used for calling PnP BIOS have byte granularity.
16658 + * The code segments and data segments have fixed 64k limits,
16659 + * the transfer segment sizes are set at run time.
16660 + */
16661 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16662 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16663 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16664 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16665 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16666 +
16667 + /*
16668 + * The APM segments have byte granularity and their bases
16669 + * are set at run time. All have 64k limits.
16670 + */
16671 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16672 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16673 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16674 +
16675 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16676 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16677 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16678 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16679 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16680 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16681 +
16682 + /* Be sure this is zeroed to avoid false validations in Xen */
16683 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16684 + .endr
16685 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16686 index 40f4eb3..6d24d9d 100644
16687 --- a/arch/x86/kernel/head_64.S
16688 +++ b/arch/x86/kernel/head_64.S
16689 @@ -19,6 +19,8 @@
16690 #include <asm/cache.h>
16691 #include <asm/processor-flags.h>
16692 #include <asm/percpu.h>
16693 +#include <asm/cpufeature.h>
16694 +#include <asm/alternative-asm.h>
16695
16696 #ifdef CONFIG_PARAVIRT
16697 #include <asm/asm-offsets.h>
16698 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16699 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16700 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16701 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16702 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16703 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16704 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16705 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16706 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16707 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16708
16709 .text
16710 __HEAD
16711 @@ -85,35 +93,23 @@ startup_64:
16712 */
16713 addq %rbp, init_level4_pgt + 0(%rip)
16714 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16715 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16716 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16717 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16718 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16719
16720 addq %rbp, level3_ident_pgt + 0(%rip)
16721 +#ifndef CONFIG_XEN
16722 + addq %rbp, level3_ident_pgt + 8(%rip)
16723 +#endif
16724
16725 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16726 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16727 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16728 +
16729 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16730 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16731
16732 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16733 -
16734 - /* Add an Identity mapping if I am above 1G */
16735 - leaq _text(%rip), %rdi
16736 - andq $PMD_PAGE_MASK, %rdi
16737 -
16738 - movq %rdi, %rax
16739 - shrq $PUD_SHIFT, %rax
16740 - andq $(PTRS_PER_PUD - 1), %rax
16741 - jz ident_complete
16742 -
16743 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16744 - leaq level3_ident_pgt(%rip), %rbx
16745 - movq %rdx, 0(%rbx, %rax, 8)
16746 -
16747 - movq %rdi, %rax
16748 - shrq $PMD_SHIFT, %rax
16749 - andq $(PTRS_PER_PMD - 1), %rax
16750 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16751 - leaq level2_spare_pgt(%rip), %rbx
16752 - movq %rdx, 0(%rbx, %rax, 8)
16753 -ident_complete:
16754 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16755
16756 /*
16757 * Fixup the kernel text+data virtual addresses. Note that
16758 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16759 * after the boot processor executes this code.
16760 */
16761
16762 - /* Enable PAE mode and PGE */
16763 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16764 + /* Enable PAE mode and PSE/PGE */
16765 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16766 movq %rax, %cr4
16767
16768 /* Setup early boot stage 4 level pagetables. */
16769 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16770 movl $MSR_EFER, %ecx
16771 rdmsr
16772 btsl $_EFER_SCE, %eax /* Enable System Call */
16773 - btl $20,%edi /* No Execute supported? */
16774 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16775 jnc 1f
16776 btsl $_EFER_NX, %eax
16777 + leaq init_level4_pgt(%rip), %rdi
16778 +#ifndef CONFIG_EFI
16779 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16780 +#endif
16781 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16782 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16783 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16784 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16785 1: wrmsr /* Make changes effective */
16786
16787 /* Setup cr0 */
16788 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16789 * jump. In addition we need to ensure %cs is set so we make this
16790 * a far return.
16791 */
16792 + pax_set_fptr_mask
16793 movq initial_code(%rip),%rax
16794 pushq $0 # fake return address to stop unwinder
16795 pushq $__KERNEL_CS # set correct cs
16796 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16797 bad_address:
16798 jmp bad_address
16799
16800 - .section ".init.text","ax"
16801 + __INIT
16802 #ifdef CONFIG_EARLY_PRINTK
16803 .globl early_idt_handlers
16804 early_idt_handlers:
16805 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16806 #endif /* EARLY_PRINTK */
16807 1: hlt
16808 jmp 1b
16809 + .previous
16810
16811 #ifdef CONFIG_EARLY_PRINTK
16812 + __INITDATA
16813 early_recursion_flag:
16814 .long 0
16815 + .previous
16816
16817 + .section .rodata,"a",@progbits
16818 early_idt_msg:
16819 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16820 early_idt_ripmsg:
16821 .asciz "RIP %s\n"
16822 + .previous
16823 #endif /* CONFIG_EARLY_PRINTK */
16824 - .previous
16825
16826 + .section .rodata,"a",@progbits
16827 #define NEXT_PAGE(name) \
16828 .balign PAGE_SIZE; \
16829 ENTRY(name)
16830 @@ -338,7 +348,6 @@ ENTRY(name)
16831 i = i + 1 ; \
16832 .endr
16833
16834 - .data
16835 /*
16836 * This default setting generates an ident mapping at address 0x100000
16837 * and a mapping for the kernel that precisely maps virtual address
16838 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16839 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16840 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16841 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16842 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16843 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16844 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16845 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16846 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16847 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16848 .org init_level4_pgt + L4_START_KERNEL*8, 0
16849 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16850 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16851
16852 +#ifdef CONFIG_PAX_PER_CPU_PGD
16853 +NEXT_PAGE(cpu_pgd)
16854 + .rept NR_CPUS
16855 + .fill 512,8,0
16856 + .endr
16857 +#endif
16858 +
16859 NEXT_PAGE(level3_ident_pgt)
16860 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16861 +#ifdef CONFIG_XEN
16862 .fill 511,8,0
16863 +#else
16864 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16865 + .fill 510,8,0
16866 +#endif
16867 +
16868 +NEXT_PAGE(level3_vmalloc_start_pgt)
16869 + .fill 512,8,0
16870 +
16871 +NEXT_PAGE(level3_vmalloc_end_pgt)
16872 + .fill 512,8,0
16873 +
16874 +NEXT_PAGE(level3_vmemmap_pgt)
16875 + .fill L3_VMEMMAP_START,8,0
16876 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16877
16878 NEXT_PAGE(level3_kernel_pgt)
16879 .fill L3_START_KERNEL,8,0
16880 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16881 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16882 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16883
16884 +NEXT_PAGE(level2_vmemmap_pgt)
16885 + .fill 512,8,0
16886 +
16887 NEXT_PAGE(level2_fixmap_pgt)
16888 - .fill 506,8,0
16889 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16890 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16891 - .fill 5,8,0
16892 + .fill 507,8,0
16893 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16894 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16895 + .fill 4,8,0
16896
16897 -NEXT_PAGE(level1_fixmap_pgt)
16898 +NEXT_PAGE(level1_vsyscall_pgt)
16899 .fill 512,8,0
16900
16901 -NEXT_PAGE(level2_ident_pgt)
16902 - /* Since I easily can, map the first 1G.
16903 + /* Since I easily can, map the first 2G.
16904 * Don't set NX because code runs from these pages.
16905 */
16906 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16907 +NEXT_PAGE(level2_ident_pgt)
16908 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16909
16910 NEXT_PAGE(level2_kernel_pgt)
16911 /*
16912 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16913 * If you want to increase this then increase MODULES_VADDR
16914 * too.)
16915 */
16916 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16917 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16918 -
16919 -NEXT_PAGE(level2_spare_pgt)
16920 - .fill 512, 8, 0
16921 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16922
16923 #undef PMDS
16924 #undef NEXT_PAGE
16925
16926 - .data
16927 + .align PAGE_SIZE
16928 +ENTRY(cpu_gdt_table)
16929 + .rept NR_CPUS
16930 + .quad 0x0000000000000000 /* NULL descriptor */
16931 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16932 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16933 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16934 + .quad 0x00cffb000000ffff /* __USER32_CS */
16935 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16936 + .quad 0x00affb000000ffff /* __USER_CS */
16937 +
16938 +#ifdef CONFIG_PAX_KERNEXEC
16939 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16940 +#else
16941 + .quad 0x0 /* unused */
16942 +#endif
16943 +
16944 + .quad 0,0 /* TSS */
16945 + .quad 0,0 /* LDT */
16946 + .quad 0,0,0 /* three TLS descriptors */
16947 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16948 + /* asm/segment.h:GDT_ENTRIES must match this */
16949 +
16950 + /* zero the remaining page */
16951 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16952 + .endr
16953 +
16954 .align 16
16955 .globl early_gdt_descr
16956 early_gdt_descr:
16957 .word GDT_ENTRIES*8-1
16958 early_gdt_descr_base:
16959 - .quad INIT_PER_CPU_VAR(gdt_page)
16960 + .quad cpu_gdt_table
16961
16962 ENTRY(phys_base)
16963 /* This must match the first entry in level2_kernel_pgt */
16964 .quad 0x0000000000000000
16965
16966 #include "../../x86/xen/xen-head.S"
16967 -
16968 - .section .bss, "aw", @nobits
16969 +
16970 + .section .rodata,"a",@progbits
16971 .align L1_CACHE_BYTES
16972 ENTRY(idt_table)
16973 - .skip IDT_ENTRIES * 16
16974 + .fill 512,8,0
16975
16976 .align L1_CACHE_BYTES
16977 ENTRY(nmi_idt_table)
16978 - .skip IDT_ENTRIES * 16
16979 + .fill 512,8,0
16980
16981 __PAGE_ALIGNED_BSS
16982 .align PAGE_SIZE
16983 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16984 index 9c3bd4a..e1d9b35 100644
16985 --- a/arch/x86/kernel/i386_ksyms_32.c
16986 +++ b/arch/x86/kernel/i386_ksyms_32.c
16987 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16988 EXPORT_SYMBOL(cmpxchg8b_emu);
16989 #endif
16990
16991 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16992 +
16993 /* Networking helper routines. */
16994 EXPORT_SYMBOL(csum_partial_copy_generic);
16995 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16996 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16997
16998 EXPORT_SYMBOL(__get_user_1);
16999 EXPORT_SYMBOL(__get_user_2);
17000 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17001
17002 EXPORT_SYMBOL(csum_partial);
17003 EXPORT_SYMBOL(empty_zero_page);
17004 +
17005 +#ifdef CONFIG_PAX_KERNEXEC
17006 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17007 +#endif
17008 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17009 index 739d859..d1d6be7 100644
17010 --- a/arch/x86/kernel/i387.c
17011 +++ b/arch/x86/kernel/i387.c
17012 @@ -188,6 +188,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17013
17014 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17015 unsigned int pos, unsigned int count,
17016 + void *kbuf, void __user *ubuf) __size_overflow(4);
17017 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17018 + unsigned int pos, unsigned int count,
17019 void *kbuf, void __user *ubuf)
17020 {
17021 int ret;
17022 @@ -207,6 +210,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17023
17024 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17025 unsigned int pos, unsigned int count,
17026 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17027 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17028 + unsigned int pos, unsigned int count,
17029 const void *kbuf, const void __user *ubuf)
17030 {
17031 int ret;
17032 @@ -240,6 +246,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17033
17034 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17035 unsigned int pos, unsigned int count,
17036 + void *kbuf, void __user *ubuf) __size_overflow(4);
17037 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17038 + unsigned int pos, unsigned int count,
17039 void *kbuf, void __user *ubuf)
17040 {
17041 int ret;
17042 @@ -269,6 +278,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17043
17044 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17045 unsigned int pos, unsigned int count,
17046 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17047 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17048 + unsigned int pos, unsigned int count,
17049 const void *kbuf, const void __user *ubuf)
17050 {
17051 int ret;
17052 @@ -439,6 +451,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17053
17054 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17055 unsigned int pos, unsigned int count,
17056 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17057 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17058 + unsigned int pos, unsigned int count,
17059 void *kbuf, void __user *ubuf)
17060 {
17061 struct user_i387_ia32_struct env;
17062 @@ -471,6 +486,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17063
17064 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17065 unsigned int pos, unsigned int count,
17066 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17067 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17068 + unsigned int pos, unsigned int count,
17069 const void *kbuf, const void __user *ubuf)
17070 {
17071 struct user_i387_ia32_struct env;
17072 @@ -619,6 +637,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17073 }
17074
17075 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17076 + unsigned int size) __size_overflow(2);
17077 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17078 unsigned int size)
17079 {
17080 struct task_struct *tsk = current;
17081 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17082 index 6104852..6114160 100644
17083 --- a/arch/x86/kernel/i8259.c
17084 +++ b/arch/x86/kernel/i8259.c
17085 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17086 "spurious 8259A interrupt: IRQ%d.\n", irq);
17087 spurious_irq_mask |= irqmask;
17088 }
17089 - atomic_inc(&irq_err_count);
17090 + atomic_inc_unchecked(&irq_err_count);
17091 /*
17092 * Theoretically we do not have to handle this IRQ,
17093 * but in Linux this does not cause problems and is
17094 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17095 index 43e9ccf..44ccf6f 100644
17096 --- a/arch/x86/kernel/init_task.c
17097 +++ b/arch/x86/kernel/init_task.c
17098 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17099 * way process stacks are handled. This is done by having a special
17100 * "init_task" linker map entry..
17101 */
17102 -union thread_union init_thread_union __init_task_data =
17103 - { INIT_THREAD_INFO(init_task) };
17104 +union thread_union init_thread_union __init_task_data;
17105
17106 /*
17107 * Initial task structure.
17108 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17109 * section. Since TSS's are completely CPU-local, we want them
17110 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17111 */
17112 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17113 -
17114 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17115 +EXPORT_SYMBOL(init_tss);
17116 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17117 index 8c96897..be66bfa 100644
17118 --- a/arch/x86/kernel/ioport.c
17119 +++ b/arch/x86/kernel/ioport.c
17120 @@ -6,6 +6,7 @@
17121 #include <linux/sched.h>
17122 #include <linux/kernel.h>
17123 #include <linux/capability.h>
17124 +#include <linux/security.h>
17125 #include <linux/errno.h>
17126 #include <linux/types.h>
17127 #include <linux/ioport.h>
17128 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17129
17130 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17131 return -EINVAL;
17132 +#ifdef CONFIG_GRKERNSEC_IO
17133 + if (turn_on && grsec_disable_privio) {
17134 + gr_handle_ioperm();
17135 + return -EPERM;
17136 + }
17137 +#endif
17138 if (turn_on && !capable(CAP_SYS_RAWIO))
17139 return -EPERM;
17140
17141 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17142 * because the ->io_bitmap_max value must match the bitmap
17143 * contents:
17144 */
17145 - tss = &per_cpu(init_tss, get_cpu());
17146 + tss = init_tss + get_cpu();
17147
17148 if (turn_on)
17149 bitmap_clear(t->io_bitmap_ptr, from, num);
17150 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17151 return -EINVAL;
17152 /* Trying to gain more privileges? */
17153 if (level > old) {
17154 +#ifdef CONFIG_GRKERNSEC_IO
17155 + if (grsec_disable_privio) {
17156 + gr_handle_iopl();
17157 + return -EPERM;
17158 + }
17159 +#endif
17160 if (!capable(CAP_SYS_RAWIO))
17161 return -EPERM;
17162 }
17163 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17164 index 7943e0c..dd32c5c 100644
17165 --- a/arch/x86/kernel/irq.c
17166 +++ b/arch/x86/kernel/irq.c
17167 @@ -18,7 +18,7 @@
17168 #include <asm/mce.h>
17169 #include <asm/hw_irq.h>
17170
17171 -atomic_t irq_err_count;
17172 +atomic_unchecked_t irq_err_count;
17173
17174 /* Function pointer for generic interrupt vector handling */
17175 void (*x86_platform_ipi_callback)(void) = NULL;
17176 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17177 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17178 seq_printf(p, " Machine check polls\n");
17179 #endif
17180 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17181 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17182 #if defined(CONFIG_X86_IO_APIC)
17183 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17184 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17185 #endif
17186 return 0;
17187 }
17188 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17189
17190 u64 arch_irq_stat(void)
17191 {
17192 - u64 sum = atomic_read(&irq_err_count);
17193 + u64 sum = atomic_read_unchecked(&irq_err_count);
17194
17195 #ifdef CONFIG_X86_IO_APIC
17196 - sum += atomic_read(&irq_mis_count);
17197 + sum += atomic_read_unchecked(&irq_mis_count);
17198 #endif
17199 return sum;
17200 }
17201 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17202 index 40fc861..9b8739b 100644
17203 --- a/arch/x86/kernel/irq_32.c
17204 +++ b/arch/x86/kernel/irq_32.c
17205 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17206 __asm__ __volatile__("andl %%esp,%0" :
17207 "=r" (sp) : "0" (THREAD_SIZE - 1));
17208
17209 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17210 + return sp < STACK_WARN;
17211 }
17212
17213 static void print_stack_overflow(void)
17214 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17215 * per-CPU IRQ handling contexts (thread information and stack)
17216 */
17217 union irq_ctx {
17218 - struct thread_info tinfo;
17219 - u32 stack[THREAD_SIZE/sizeof(u32)];
17220 + unsigned long previous_esp;
17221 + u32 stack[THREAD_SIZE/sizeof(u32)];
17222 } __attribute__((aligned(THREAD_SIZE)));
17223
17224 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17225 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17226 static inline int
17227 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17228 {
17229 - union irq_ctx *curctx, *irqctx;
17230 + union irq_ctx *irqctx;
17231 u32 *isp, arg1, arg2;
17232
17233 - curctx = (union irq_ctx *) current_thread_info();
17234 irqctx = __this_cpu_read(hardirq_ctx);
17235
17236 /*
17237 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17238 * handler) we can't do that and just have to keep using the
17239 * current stack (which is the irq stack already after all)
17240 */
17241 - if (unlikely(curctx == irqctx))
17242 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17243 return 0;
17244
17245 /* build the stack frame on the IRQ stack */
17246 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17247 - irqctx->tinfo.task = curctx->tinfo.task;
17248 - irqctx->tinfo.previous_esp = current_stack_pointer;
17249 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17250 + irqctx->previous_esp = current_stack_pointer;
17251
17252 - /*
17253 - * Copy the softirq bits in preempt_count so that the
17254 - * softirq checks work in the hardirq context.
17255 - */
17256 - irqctx->tinfo.preempt_count =
17257 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17258 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17259 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17260 + __set_fs(MAKE_MM_SEG(0));
17261 +#endif
17262
17263 if (unlikely(overflow))
17264 call_on_stack(print_stack_overflow, isp);
17265 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17266 : "0" (irq), "1" (desc), "2" (isp),
17267 "D" (desc->handle_irq)
17268 : "memory", "cc", "ecx");
17269 +
17270 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17271 + __set_fs(current_thread_info()->addr_limit);
17272 +#endif
17273 +
17274 return 1;
17275 }
17276
17277 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17278 */
17279 void __cpuinit irq_ctx_init(int cpu)
17280 {
17281 - union irq_ctx *irqctx;
17282 -
17283 if (per_cpu(hardirq_ctx, cpu))
17284 return;
17285
17286 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17287 - THREAD_FLAGS,
17288 - THREAD_ORDER));
17289 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17290 - irqctx->tinfo.cpu = cpu;
17291 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17292 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17293 -
17294 - per_cpu(hardirq_ctx, cpu) = irqctx;
17295 -
17296 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17297 - THREAD_FLAGS,
17298 - THREAD_ORDER));
17299 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17300 - irqctx->tinfo.cpu = cpu;
17301 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17302 -
17303 - per_cpu(softirq_ctx, cpu) = irqctx;
17304 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17305 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17306
17307 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17308 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17309 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17310 asmlinkage void do_softirq(void)
17311 {
17312 unsigned long flags;
17313 - struct thread_info *curctx;
17314 union irq_ctx *irqctx;
17315 u32 *isp;
17316
17317 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17318 local_irq_save(flags);
17319
17320 if (local_softirq_pending()) {
17321 - curctx = current_thread_info();
17322 irqctx = __this_cpu_read(softirq_ctx);
17323 - irqctx->tinfo.task = curctx->task;
17324 - irqctx->tinfo.previous_esp = current_stack_pointer;
17325 + irqctx->previous_esp = current_stack_pointer;
17326
17327 /* build the stack frame on the softirq stack */
17328 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17329 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17330 +
17331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17332 + __set_fs(MAKE_MM_SEG(0));
17333 +#endif
17334
17335 call_on_stack(__do_softirq, isp);
17336 +
17337 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17338 + __set_fs(current_thread_info()->addr_limit);
17339 +#endif
17340 +
17341 /*
17342 * Shouldn't happen, we returned above if in_interrupt():
17343 */
17344 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17345 index d04d3ec..ea4b374 100644
17346 --- a/arch/x86/kernel/irq_64.c
17347 +++ b/arch/x86/kernel/irq_64.c
17348 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17349 u64 estack_top, estack_bottom;
17350 u64 curbase = (u64)task_stack_page(current);
17351
17352 - if (user_mode_vm(regs))
17353 + if (user_mode(regs))
17354 return;
17355
17356 if (regs->sp >= curbase + sizeof(struct thread_info) +
17357 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17358 index 90fcf62..e682cdd 100644
17359 --- a/arch/x86/kernel/kdebugfs.c
17360 +++ b/arch/x86/kernel/kdebugfs.c
17361 @@ -28,6 +28,8 @@ struct setup_data_node {
17362 };
17363
17364 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17365 + size_t count, loff_t *ppos) __size_overflow(3);
17366 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17367 size_t count, loff_t *ppos)
17368 {
17369 struct setup_data_node *node = file->private_data;
17370 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17371 index faba577..93b9e71 100644
17372 --- a/arch/x86/kernel/kgdb.c
17373 +++ b/arch/x86/kernel/kgdb.c
17374 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17375 #ifdef CONFIG_X86_32
17376 switch (regno) {
17377 case GDB_SS:
17378 - if (!user_mode_vm(regs))
17379 + if (!user_mode(regs))
17380 *(unsigned long *)mem = __KERNEL_DS;
17381 break;
17382 case GDB_SP:
17383 - if (!user_mode_vm(regs))
17384 + if (!user_mode(regs))
17385 *(unsigned long *)mem = kernel_stack_pointer(regs);
17386 break;
17387 case GDB_GS:
17388 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17389 case 'k':
17390 /* clear the trace bit */
17391 linux_regs->flags &= ~X86_EFLAGS_TF;
17392 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17393 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17394
17395 /* set the trace bit if we're stepping */
17396 if (remcomInBuffer[0] == 's') {
17397 linux_regs->flags |= X86_EFLAGS_TF;
17398 - atomic_set(&kgdb_cpu_doing_single_step,
17399 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17400 raw_smp_processor_id());
17401 }
17402
17403 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17404
17405 switch (cmd) {
17406 case DIE_DEBUG:
17407 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17408 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17409 if (user_mode(regs))
17410 return single_step_cont(regs, args);
17411 break;
17412 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17413 index 7da647d..56fe348 100644
17414 --- a/arch/x86/kernel/kprobes.c
17415 +++ b/arch/x86/kernel/kprobes.c
17416 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17417 } __attribute__((packed)) *insn;
17418
17419 insn = (struct __arch_relative_insn *)from;
17420 +
17421 + pax_open_kernel();
17422 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17423 insn->op = op;
17424 + pax_close_kernel();
17425 }
17426
17427 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17428 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17429 kprobe_opcode_t opcode;
17430 kprobe_opcode_t *orig_opcodes = opcodes;
17431
17432 - if (search_exception_tables((unsigned long)opcodes))
17433 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17434 return 0; /* Page fault may occur on this address. */
17435
17436 retry:
17437 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17438 }
17439 }
17440 insn_get_length(&insn);
17441 + pax_open_kernel();
17442 memcpy(dest, insn.kaddr, insn.length);
17443 + pax_close_kernel();
17444
17445 #ifdef CONFIG_X86_64
17446 if (insn_rip_relative(&insn)) {
17447 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17448 (u8 *) dest;
17449 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17450 disp = (u8 *) dest + insn_offset_displacement(&insn);
17451 + pax_open_kernel();
17452 *(s32 *) disp = (s32) newdisp;
17453 + pax_close_kernel();
17454 }
17455 #endif
17456 return insn.length;
17457 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17458 */
17459 __copy_instruction(p->ainsn.insn, p->addr, 0);
17460
17461 - if (can_boost(p->addr))
17462 + if (can_boost(ktla_ktva(p->addr)))
17463 p->ainsn.boostable = 0;
17464 else
17465 p->ainsn.boostable = -1;
17466
17467 - p->opcode = *p->addr;
17468 + p->opcode = *(ktla_ktva(p->addr));
17469 }
17470
17471 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17472 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17473 * nor set current_kprobe, because it doesn't use single
17474 * stepping.
17475 */
17476 - regs->ip = (unsigned long)p->ainsn.insn;
17477 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17478 preempt_enable_no_resched();
17479 return;
17480 }
17481 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17482 if (p->opcode == BREAKPOINT_INSTRUCTION)
17483 regs->ip = (unsigned long)p->addr;
17484 else
17485 - regs->ip = (unsigned long)p->ainsn.insn;
17486 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17487 }
17488
17489 /*
17490 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17491 setup_singlestep(p, regs, kcb, 0);
17492 return 1;
17493 }
17494 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17495 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17496 /*
17497 * The breakpoint instruction was removed right
17498 * after we hit it. Another cpu has removed
17499 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17500 " movq %rax, 152(%rsp)\n"
17501 RESTORE_REGS_STRING
17502 " popfq\n"
17503 +#ifdef KERNEXEC_PLUGIN
17504 + " btsq $63,(%rsp)\n"
17505 +#endif
17506 #else
17507 " pushf\n"
17508 SAVE_REGS_STRING
17509 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17510 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17511 {
17512 unsigned long *tos = stack_addr(regs);
17513 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17514 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17515 unsigned long orig_ip = (unsigned long)p->addr;
17516 kprobe_opcode_t *insn = p->ainsn.insn;
17517
17518 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17519 struct die_args *args = data;
17520 int ret = NOTIFY_DONE;
17521
17522 - if (args->regs && user_mode_vm(args->regs))
17523 + if (args->regs && user_mode(args->regs))
17524 return ret;
17525
17526 switch (val) {
17527 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17528 * Verify if the address gap is in 2GB range, because this uses
17529 * a relative jump.
17530 */
17531 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17532 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17533 if (abs(rel) > 0x7fffffff)
17534 return -ERANGE;
17535
17536 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17537 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17538
17539 /* Set probe function call */
17540 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17541 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17542
17543 /* Set returning jmp instruction at the tail of out-of-line buffer */
17544 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17545 - (u8 *)op->kp.addr + op->optinsn.size);
17546 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17547
17548 flush_icache_range((unsigned long) buf,
17549 (unsigned long) buf + TMPL_END_IDX +
17550 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17551 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17552
17553 /* Backup instructions which will be replaced by jump address */
17554 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17555 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17556 RELATIVE_ADDR_SIZE);
17557
17558 insn_buf[0] = RELATIVEJUMP_OPCODE;
17559 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17560 index ea69726..a305f16 100644
17561 --- a/arch/x86/kernel/ldt.c
17562 +++ b/arch/x86/kernel/ldt.c
17563 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17564 if (reload) {
17565 #ifdef CONFIG_SMP
17566 preempt_disable();
17567 - load_LDT(pc);
17568 + load_LDT_nolock(pc);
17569 if (!cpumask_equal(mm_cpumask(current->mm),
17570 cpumask_of(smp_processor_id())))
17571 smp_call_function(flush_ldt, current->mm, 1);
17572 preempt_enable();
17573 #else
17574 - load_LDT(pc);
17575 + load_LDT_nolock(pc);
17576 #endif
17577 }
17578 if (oldsize) {
17579 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17580 return err;
17581
17582 for (i = 0; i < old->size; i++)
17583 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17584 + write_ldt_entry(new->ldt, i, old->ldt + i);
17585 return 0;
17586 }
17587
17588 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17589 retval = copy_ldt(&mm->context, &old_mm->context);
17590 mutex_unlock(&old_mm->context.lock);
17591 }
17592 +
17593 + if (tsk == current) {
17594 + mm->context.vdso = 0;
17595 +
17596 +#ifdef CONFIG_X86_32
17597 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17598 + mm->context.user_cs_base = 0UL;
17599 + mm->context.user_cs_limit = ~0UL;
17600 +
17601 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17602 + cpus_clear(mm->context.cpu_user_cs_mask);
17603 +#endif
17604 +
17605 +#endif
17606 +#endif
17607 +
17608 + }
17609 +
17610 return retval;
17611 }
17612
17613 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17614 }
17615 }
17616
17617 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17618 static int read_ldt(void __user *ptr, unsigned long bytecount)
17619 {
17620 int err;
17621 @@ -175,6 +194,7 @@ error_return:
17622 return err;
17623 }
17624
17625 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17626 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
17627 {
17628 /* CHECKME: Can we use _one_ random number ? */
17629 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17630 }
17631 }
17632
17633 +#ifdef CONFIG_PAX_SEGMEXEC
17634 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17635 + error = -EINVAL;
17636 + goto out_unlock;
17637 + }
17638 +#endif
17639 +
17640 fill_ldt(&ldt, &ldt_info);
17641 if (oldmode)
17642 ldt.avl = 0;
17643 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17644 index a3fa43b..8966f4c 100644
17645 --- a/arch/x86/kernel/machine_kexec_32.c
17646 +++ b/arch/x86/kernel/machine_kexec_32.c
17647 @@ -27,7 +27,7 @@
17648 #include <asm/cacheflush.h>
17649 #include <asm/debugreg.h>
17650
17651 -static void set_idt(void *newidt, __u16 limit)
17652 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17653 {
17654 struct desc_ptr curidt;
17655
17656 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17657 }
17658
17659
17660 -static void set_gdt(void *newgdt, __u16 limit)
17661 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17662 {
17663 struct desc_ptr curgdt;
17664
17665 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17666 }
17667
17668 control_page = page_address(image->control_code_page);
17669 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17670 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17671
17672 relocate_kernel_ptr = control_page;
17673 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17674 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17675 index 3ca42d0..79d24cd 100644
17676 --- a/arch/x86/kernel/microcode_intel.c
17677 +++ b/arch/x86/kernel/microcode_intel.c
17678 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17679 return ret;
17680 }
17681
17682 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17683 static int get_ucode_user(void *to, const void *from, size_t n)
17684 {
17685 - return copy_from_user(to, from, n);
17686 + return copy_from_user(to, (const void __force_user *)from, n);
17687 }
17688
17689 static enum ucode_state
17690 request_microcode_user(int cpu, const void __user *buf, size_t size)
17691 {
17692 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17693 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17694 }
17695
17696 static void microcode_fini_cpu(int cpu)
17697 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17698 index 925179f..1f0d561 100644
17699 --- a/arch/x86/kernel/module.c
17700 +++ b/arch/x86/kernel/module.c
17701 @@ -36,15 +36,61 @@
17702 #define DEBUGP(fmt...)
17703 #endif
17704
17705 -void *module_alloc(unsigned long size)
17706 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
17707 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17708 {
17709 - if (PAGE_ALIGN(size) > MODULES_LEN)
17710 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17711 return NULL;
17712 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17713 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17714 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17715 -1, __builtin_return_address(0));
17716 }
17717
17718 +void *module_alloc(unsigned long size)
17719 +{
17720 +
17721 +#ifdef CONFIG_PAX_KERNEXEC
17722 + return __module_alloc(size, PAGE_KERNEL);
17723 +#else
17724 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17725 +#endif
17726 +
17727 +}
17728 +
17729 +#ifdef CONFIG_PAX_KERNEXEC
17730 +#ifdef CONFIG_X86_32
17731 +void *module_alloc_exec(unsigned long size)
17732 +{
17733 + struct vm_struct *area;
17734 +
17735 + if (size == 0)
17736 + return NULL;
17737 +
17738 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17739 + return area ? area->addr : NULL;
17740 +}
17741 +EXPORT_SYMBOL(module_alloc_exec);
17742 +
17743 +void module_free_exec(struct module *mod, void *module_region)
17744 +{
17745 + vunmap(module_region);
17746 +}
17747 +EXPORT_SYMBOL(module_free_exec);
17748 +#else
17749 +void module_free_exec(struct module *mod, void *module_region)
17750 +{
17751 + module_free(mod, module_region);
17752 +}
17753 +EXPORT_SYMBOL(module_free_exec);
17754 +
17755 +void *module_alloc_exec(unsigned long size)
17756 +{
17757 + return __module_alloc(size, PAGE_KERNEL_RX);
17758 +}
17759 +EXPORT_SYMBOL(module_alloc_exec);
17760 +#endif
17761 +#endif
17762 +
17763 #ifdef CONFIG_X86_32
17764 int apply_relocate(Elf32_Shdr *sechdrs,
17765 const char *strtab,
17766 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17767 unsigned int i;
17768 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17769 Elf32_Sym *sym;
17770 - uint32_t *location;
17771 + uint32_t *plocation, location;
17772
17773 DEBUGP("Applying relocate section %u to %u\n", relsec,
17774 sechdrs[relsec].sh_info);
17775 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17776 /* This is where to make the change */
17777 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17778 - + rel[i].r_offset;
17779 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17780 + location = (uint32_t)plocation;
17781 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17782 + plocation = ktla_ktva((void *)plocation);
17783 /* This is the symbol it is referring to. Note that all
17784 undefined symbols have been resolved. */
17785 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17786 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17787 switch (ELF32_R_TYPE(rel[i].r_info)) {
17788 case R_386_32:
17789 /* We add the value into the location given */
17790 - *location += sym->st_value;
17791 + pax_open_kernel();
17792 + *plocation += sym->st_value;
17793 + pax_close_kernel();
17794 break;
17795 case R_386_PC32:
17796 /* Add the value, subtract its postition */
17797 - *location += sym->st_value - (uint32_t)location;
17798 + pax_open_kernel();
17799 + *plocation += sym->st_value - location;
17800 + pax_close_kernel();
17801 break;
17802 default:
17803 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17804 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17805 case R_X86_64_NONE:
17806 break;
17807 case R_X86_64_64:
17808 + pax_open_kernel();
17809 *(u64 *)loc = val;
17810 + pax_close_kernel();
17811 break;
17812 case R_X86_64_32:
17813 + pax_open_kernel();
17814 *(u32 *)loc = val;
17815 + pax_close_kernel();
17816 if (val != *(u32 *)loc)
17817 goto overflow;
17818 break;
17819 case R_X86_64_32S:
17820 + pax_open_kernel();
17821 *(s32 *)loc = val;
17822 + pax_close_kernel();
17823 if ((s64)val != *(s32 *)loc)
17824 goto overflow;
17825 break;
17826 case R_X86_64_PC32:
17827 val -= (u64)loc;
17828 + pax_open_kernel();
17829 *(u32 *)loc = val;
17830 + pax_close_kernel();
17831 +
17832 #if 0
17833 if ((s64)val != *(s32 *)loc)
17834 goto overflow;
17835 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17836 index 47acaf3..ec48ab6 100644
17837 --- a/arch/x86/kernel/nmi.c
17838 +++ b/arch/x86/kernel/nmi.c
17839 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17840 dotraplinkage notrace __kprobes void
17841 do_nmi(struct pt_regs *regs, long error_code)
17842 {
17843 +
17844 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17845 + if (!user_mode(regs)) {
17846 + unsigned long cs = regs->cs & 0xFFFF;
17847 + unsigned long ip = ktva_ktla(regs->ip);
17848 +
17849 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17850 + regs->ip = ip;
17851 + }
17852 +#endif
17853 +
17854 nmi_nesting_preprocess(regs);
17855
17856 nmi_enter();
17857 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17858 index 676b8c7..870ba04 100644
17859 --- a/arch/x86/kernel/paravirt-spinlocks.c
17860 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17861 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17862 arch_spin_lock(lock);
17863 }
17864
17865 -struct pv_lock_ops pv_lock_ops = {
17866 +struct pv_lock_ops pv_lock_ops __read_only = {
17867 #ifdef CONFIG_SMP
17868 .spin_is_locked = __ticket_spin_is_locked,
17869 .spin_is_contended = __ticket_spin_is_contended,
17870 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17871 index d90272e..6bb013b 100644
17872 --- a/arch/x86/kernel/paravirt.c
17873 +++ b/arch/x86/kernel/paravirt.c
17874 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17875 {
17876 return x;
17877 }
17878 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17879 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17880 +#endif
17881
17882 void __init default_banner(void)
17883 {
17884 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17885 if (opfunc == NULL)
17886 /* If there's no function, patch it with a ud2a (BUG) */
17887 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17888 - else if (opfunc == _paravirt_nop)
17889 + else if (opfunc == (void *)_paravirt_nop)
17890 /* If the operation is a nop, then nop the callsite */
17891 ret = paravirt_patch_nop();
17892
17893 /* identity functions just return their single argument */
17894 - else if (opfunc == _paravirt_ident_32)
17895 + else if (opfunc == (void *)_paravirt_ident_32)
17896 ret = paravirt_patch_ident_32(insnbuf, len);
17897 - else if (opfunc == _paravirt_ident_64)
17898 + else if (opfunc == (void *)_paravirt_ident_64)
17899 ret = paravirt_patch_ident_64(insnbuf, len);
17900 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17901 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17902 + ret = paravirt_patch_ident_64(insnbuf, len);
17903 +#endif
17904
17905 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17906 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17907 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17908 if (insn_len > len || start == NULL)
17909 insn_len = len;
17910 else
17911 - memcpy(insnbuf, start, insn_len);
17912 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17913
17914 return insn_len;
17915 }
17916 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17917 preempt_enable();
17918 }
17919
17920 -struct pv_info pv_info = {
17921 +struct pv_info pv_info __read_only = {
17922 .name = "bare hardware",
17923 .paravirt_enabled = 0,
17924 .kernel_rpl = 0,
17925 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17926 #endif
17927 };
17928
17929 -struct pv_init_ops pv_init_ops = {
17930 +struct pv_init_ops pv_init_ops __read_only = {
17931 .patch = native_patch,
17932 };
17933
17934 -struct pv_time_ops pv_time_ops = {
17935 +struct pv_time_ops pv_time_ops __read_only = {
17936 .sched_clock = native_sched_clock,
17937 .steal_clock = native_steal_clock,
17938 };
17939
17940 -struct pv_irq_ops pv_irq_ops = {
17941 +struct pv_irq_ops pv_irq_ops __read_only = {
17942 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17943 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17944 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17945 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17946 #endif
17947 };
17948
17949 -struct pv_cpu_ops pv_cpu_ops = {
17950 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17951 .cpuid = native_cpuid,
17952 .get_debugreg = native_get_debugreg,
17953 .set_debugreg = native_set_debugreg,
17954 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17955 .end_context_switch = paravirt_nop,
17956 };
17957
17958 -struct pv_apic_ops pv_apic_ops = {
17959 +struct pv_apic_ops pv_apic_ops __read_only = {
17960 #ifdef CONFIG_X86_LOCAL_APIC
17961 .startup_ipi_hook = paravirt_nop,
17962 #endif
17963 };
17964
17965 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17966 +#ifdef CONFIG_X86_32
17967 +#ifdef CONFIG_X86_PAE
17968 +/* 64-bit pagetable entries */
17969 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17970 +#else
17971 /* 32-bit pagetable entries */
17972 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17973 +#endif
17974 #else
17975 /* 64-bit pagetable entries */
17976 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17977 #endif
17978
17979 -struct pv_mmu_ops pv_mmu_ops = {
17980 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17981
17982 .read_cr2 = native_read_cr2,
17983 .write_cr2 = native_write_cr2,
17984 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17985 .make_pud = PTE_IDENT,
17986
17987 .set_pgd = native_set_pgd,
17988 + .set_pgd_batched = native_set_pgd_batched,
17989 #endif
17990 #endif /* PAGETABLE_LEVELS >= 3 */
17991
17992 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17993 },
17994
17995 .set_fixmap = native_set_fixmap,
17996 +
17997 +#ifdef CONFIG_PAX_KERNEXEC
17998 + .pax_open_kernel = native_pax_open_kernel,
17999 + .pax_close_kernel = native_pax_close_kernel,
18000 +#endif
18001 +
18002 };
18003
18004 EXPORT_SYMBOL_GPL(pv_time_ops);
18005 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18006 index 35ccf75..7a15747 100644
18007 --- a/arch/x86/kernel/pci-iommu_table.c
18008 +++ b/arch/x86/kernel/pci-iommu_table.c
18009 @@ -2,7 +2,7 @@
18010 #include <asm/iommu_table.h>
18011 #include <linux/string.h>
18012 #include <linux/kallsyms.h>
18013 -
18014 +#include <linux/sched.h>
18015
18016 #define DEBUG 1
18017
18018 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18019 index 15763af..da59ada 100644
18020 --- a/arch/x86/kernel/process.c
18021 +++ b/arch/x86/kernel/process.c
18022 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18023
18024 void free_thread_info(struct thread_info *ti)
18025 {
18026 - free_thread_xstate(ti->task);
18027 free_pages((unsigned long)ti, THREAD_ORDER);
18028 }
18029
18030 +static struct kmem_cache *task_struct_cachep;
18031 +
18032 void arch_task_cache_init(void)
18033 {
18034 - task_xstate_cachep =
18035 - kmem_cache_create("task_xstate", xstate_size,
18036 + /* create a slab on which task_structs can be allocated */
18037 + task_struct_cachep =
18038 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18039 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18040 +
18041 + task_xstate_cachep =
18042 + kmem_cache_create("task_xstate", xstate_size,
18043 __alignof__(union thread_xstate),
18044 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18045 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18046 +}
18047 +
18048 +struct task_struct *alloc_task_struct_node(int node)
18049 +{
18050 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18051 +}
18052 +
18053 +void free_task_struct(struct task_struct *task)
18054 +{
18055 + free_thread_xstate(task);
18056 + kmem_cache_free(task_struct_cachep, task);
18057 }
18058
18059 /*
18060 @@ -70,7 +87,7 @@ void exit_thread(void)
18061 unsigned long *bp = t->io_bitmap_ptr;
18062
18063 if (bp) {
18064 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18065 + struct tss_struct *tss = init_tss + get_cpu();
18066
18067 t->io_bitmap_ptr = NULL;
18068 clear_thread_flag(TIF_IO_BITMAP);
18069 @@ -106,7 +123,7 @@ void show_regs_common(void)
18070
18071 printk(KERN_CONT "\n");
18072 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18073 - current->pid, current->comm, print_tainted(),
18074 + task_pid_nr(current), current->comm, print_tainted(),
18075 init_utsname()->release,
18076 (int)strcspn(init_utsname()->version, " "),
18077 init_utsname()->version);
18078 @@ -120,6 +137,9 @@ void flush_thread(void)
18079 {
18080 struct task_struct *tsk = current;
18081
18082 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18083 + loadsegment(gs, 0);
18084 +#endif
18085 flush_ptrace_hw_breakpoint(tsk);
18086 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18087 /*
18088 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18089 regs.di = (unsigned long) arg;
18090
18091 #ifdef CONFIG_X86_32
18092 - regs.ds = __USER_DS;
18093 - regs.es = __USER_DS;
18094 + regs.ds = __KERNEL_DS;
18095 + regs.es = __KERNEL_DS;
18096 regs.fs = __KERNEL_PERCPU;
18097 - regs.gs = __KERNEL_STACK_CANARY;
18098 + savesegment(gs, regs.gs);
18099 #else
18100 regs.ss = __KERNEL_DS;
18101 #endif
18102 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18103
18104 return ret;
18105 }
18106 -void stop_this_cpu(void *dummy)
18107 +__noreturn void stop_this_cpu(void *dummy)
18108 {
18109 local_irq_disable();
18110 /*
18111 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18112 }
18113 early_param("idle", idle_setup);
18114
18115 -unsigned long arch_align_stack(unsigned long sp)
18116 +#ifdef CONFIG_PAX_RANDKSTACK
18117 +void pax_randomize_kstack(struct pt_regs *regs)
18118 {
18119 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18120 - sp -= get_random_int() % 8192;
18121 - return sp & ~0xf;
18122 -}
18123 + struct thread_struct *thread = &current->thread;
18124 + unsigned long time;
18125
18126 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18127 -{
18128 - unsigned long range_end = mm->brk + 0x02000000;
18129 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18130 -}
18131 + if (!randomize_va_space)
18132 + return;
18133 +
18134 + if (v8086_mode(regs))
18135 + return;
18136
18137 + rdtscl(time);
18138 +
18139 + /* P4 seems to return a 0 LSB, ignore it */
18140 +#ifdef CONFIG_MPENTIUM4
18141 + time &= 0x3EUL;
18142 + time <<= 2;
18143 +#elif defined(CONFIG_X86_64)
18144 + time &= 0xFUL;
18145 + time <<= 4;
18146 +#else
18147 + time &= 0x1FUL;
18148 + time <<= 3;
18149 +#endif
18150 +
18151 + thread->sp0 ^= time;
18152 + load_sp0(init_tss + smp_processor_id(), thread);
18153 +
18154 +#ifdef CONFIG_X86_64
18155 + percpu_write(kernel_stack, thread->sp0);
18156 +#endif
18157 +}
18158 +#endif
18159 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18160 index c08d1ff..6ae1c81 100644
18161 --- a/arch/x86/kernel/process_32.c
18162 +++ b/arch/x86/kernel/process_32.c
18163 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18164 unsigned long thread_saved_pc(struct task_struct *tsk)
18165 {
18166 return ((unsigned long *)tsk->thread.sp)[3];
18167 +//XXX return tsk->thread.eip;
18168 }
18169
18170 #ifndef CONFIG_SMP
18171 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18172 unsigned long sp;
18173 unsigned short ss, gs;
18174
18175 - if (user_mode_vm(regs)) {
18176 + if (user_mode(regs)) {
18177 sp = regs->sp;
18178 ss = regs->ss & 0xffff;
18179 - gs = get_user_gs(regs);
18180 } else {
18181 sp = kernel_stack_pointer(regs);
18182 savesegment(ss, ss);
18183 - savesegment(gs, gs);
18184 }
18185 + gs = get_user_gs(regs);
18186
18187 show_regs_common();
18188
18189 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18190 struct task_struct *tsk;
18191 int err;
18192
18193 - childregs = task_pt_regs(p);
18194 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18195 *childregs = *regs;
18196 childregs->ax = 0;
18197 childregs->sp = sp;
18198
18199 p->thread.sp = (unsigned long) childregs;
18200 p->thread.sp0 = (unsigned long) (childregs+1);
18201 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18202
18203 p->thread.ip = (unsigned long) ret_from_fork;
18204
18205 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18206 struct thread_struct *prev = &prev_p->thread,
18207 *next = &next_p->thread;
18208 int cpu = smp_processor_id();
18209 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18210 + struct tss_struct *tss = init_tss + cpu;
18211 fpu_switch_t fpu;
18212
18213 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18214 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18215 */
18216 lazy_save_gs(prev->gs);
18217
18218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18219 + __set_fs(task_thread_info(next_p)->addr_limit);
18220 +#endif
18221 +
18222 /*
18223 * Load the per-thread Thread-Local Storage descriptor.
18224 */
18225 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18226 */
18227 arch_end_context_switch(next_p);
18228
18229 + percpu_write(current_task, next_p);
18230 + percpu_write(current_tinfo, &next_p->tinfo);
18231 +
18232 /*
18233 * Restore %gs if needed (which is common)
18234 */
18235 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18236
18237 switch_fpu_finish(next_p, fpu);
18238
18239 - percpu_write(current_task, next_p);
18240 -
18241 return prev_p;
18242 }
18243
18244 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18245 } while (count++ < 16);
18246 return 0;
18247 }
18248 -
18249 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18250 index cfa5c90..4facd28 100644
18251 --- a/arch/x86/kernel/process_64.c
18252 +++ b/arch/x86/kernel/process_64.c
18253 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18254 void exit_idle(void)
18255 {
18256 /* idle loop has pid 0 */
18257 - if (current->pid)
18258 + if (task_pid_nr(current))
18259 return;
18260 __exit_idle();
18261 }
18262 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18263 struct pt_regs *childregs;
18264 struct task_struct *me = current;
18265
18266 - childregs = ((struct pt_regs *)
18267 - (THREAD_SIZE + task_stack_page(p))) - 1;
18268 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18269 *childregs = *regs;
18270
18271 childregs->ax = 0;
18272 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18273 p->thread.sp = (unsigned long) childregs;
18274 p->thread.sp0 = (unsigned long) (childregs+1);
18275 p->thread.usersp = me->thread.usersp;
18276 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18277
18278 set_tsk_thread_flag(p, TIF_FORK);
18279
18280 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18281 struct thread_struct *prev = &prev_p->thread;
18282 struct thread_struct *next = &next_p->thread;
18283 int cpu = smp_processor_id();
18284 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18285 + struct tss_struct *tss = init_tss + cpu;
18286 unsigned fsindex, gsindex;
18287 fpu_switch_t fpu;
18288
18289 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18290 prev->usersp = percpu_read(old_rsp);
18291 percpu_write(old_rsp, next->usersp);
18292 percpu_write(current_task, next_p);
18293 + percpu_write(current_tinfo, &next_p->tinfo);
18294
18295 - percpu_write(kernel_stack,
18296 - (unsigned long)task_stack_page(next_p) +
18297 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18298 + percpu_write(kernel_stack, next->sp0);
18299
18300 /*
18301 * Now maybe reload the debug registers and handle I/O bitmaps
18302 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18303 if (!p || p == current || p->state == TASK_RUNNING)
18304 return 0;
18305 stack = (unsigned long)task_stack_page(p);
18306 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18307 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18308 return 0;
18309 fp = *(u64 *)(p->thread.sp);
18310 do {
18311 - if (fp < (unsigned long)stack ||
18312 - fp >= (unsigned long)stack+THREAD_SIZE)
18313 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18314 return 0;
18315 ip = *(u64 *)(fp+8);
18316 if (!in_sched_functions(ip))
18317 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18318 index 5026738..e1b5aa8 100644
18319 --- a/arch/x86/kernel/ptrace.c
18320 +++ b/arch/x86/kernel/ptrace.c
18321 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18322 static int ioperm_get(struct task_struct *target,
18323 const struct user_regset *regset,
18324 unsigned int pos, unsigned int count,
18325 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18326 +static int ioperm_get(struct task_struct *target,
18327 + const struct user_regset *regset,
18328 + unsigned int pos, unsigned int count,
18329 void *kbuf, void __user *ubuf)
18330 {
18331 if (!target->thread.io_bitmap_ptr)
18332 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
18333 unsigned long addr, unsigned long data)
18334 {
18335 int ret;
18336 - unsigned long __user *datap = (unsigned long __user *)data;
18337 + unsigned long __user *datap = (__force unsigned long __user *)data;
18338
18339 switch (request) {
18340 /* read the word at location addr in the USER area. */
18341 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
18342 if ((int) addr < 0)
18343 return -EIO;
18344 ret = do_get_thread_area(child, addr,
18345 - (struct user_desc __user *)data);
18346 + (__force struct user_desc __user *) data);
18347 break;
18348
18349 case PTRACE_SET_THREAD_AREA:
18350 if ((int) addr < 0)
18351 return -EIO;
18352 ret = do_set_thread_area(child, addr,
18353 - (struct user_desc __user *)data, 0);
18354 + (__force struct user_desc __user *) data, 0);
18355 break;
18356 #endif
18357
18358 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18359 memset(info, 0, sizeof(*info));
18360 info->si_signo = SIGTRAP;
18361 info->si_code = si_code;
18362 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18363 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18364 }
18365
18366 void user_single_step_siginfo(struct task_struct *tsk,
18367 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18368 index 42eb330..139955c 100644
18369 --- a/arch/x86/kernel/pvclock.c
18370 +++ b/arch/x86/kernel/pvclock.c
18371 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18372 return pv_tsc_khz;
18373 }
18374
18375 -static atomic64_t last_value = ATOMIC64_INIT(0);
18376 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18377
18378 void pvclock_resume(void)
18379 {
18380 - atomic64_set(&last_value, 0);
18381 + atomic64_set_unchecked(&last_value, 0);
18382 }
18383
18384 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18385 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18386 * updating at the same time, and one of them could be slightly behind,
18387 * making the assumption that last_value always go forward fail to hold.
18388 */
18389 - last = atomic64_read(&last_value);
18390 + last = atomic64_read_unchecked(&last_value);
18391 do {
18392 if (ret < last)
18393 return last;
18394 - last = atomic64_cmpxchg(&last_value, last, ret);
18395 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18396 } while (unlikely(last != ret));
18397
18398 return ret;
18399 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18400 index d840e69..98e9581 100644
18401 --- a/arch/x86/kernel/reboot.c
18402 +++ b/arch/x86/kernel/reboot.c
18403 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18404 EXPORT_SYMBOL(pm_power_off);
18405
18406 static const struct desc_ptr no_idt = {};
18407 -static int reboot_mode;
18408 +static unsigned short reboot_mode;
18409 enum reboot_type reboot_type = BOOT_ACPI;
18410 int reboot_force;
18411
18412 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18413 extern const unsigned char machine_real_restart_asm[];
18414 extern const u64 machine_real_restart_gdt[3];
18415
18416 -void machine_real_restart(unsigned int type)
18417 +__noreturn void machine_real_restart(unsigned int type)
18418 {
18419 void *restart_va;
18420 unsigned long restart_pa;
18421 - void (*restart_lowmem)(unsigned int);
18422 + void (* __noreturn restart_lowmem)(unsigned int);
18423 u64 *lowmem_gdt;
18424
18425 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18426 + struct desc_struct *gdt;
18427 +#endif
18428 +
18429 local_irq_disable();
18430
18431 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18432 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18433 boot)". This seems like a fairly standard thing that gets set by
18434 REBOOT.COM programs, and the previous reset routine did this
18435 too. */
18436 - *((unsigned short *)0x472) = reboot_mode;
18437 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18438
18439 /* Patch the GDT in the low memory trampoline */
18440 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18441
18442 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18443 restart_pa = virt_to_phys(restart_va);
18444 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18445 + restart_lowmem = (void *)restart_pa;
18446
18447 /* GDT[0]: GDT self-pointer */
18448 lowmem_gdt[0] =
18449 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18450 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18451
18452 /* Jump to the identity-mapped low memory code */
18453 +
18454 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18455 + gdt = get_cpu_gdt_table(smp_processor_id());
18456 + pax_open_kernel();
18457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18458 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18459 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18460 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18461 +#endif
18462 +#ifdef CONFIG_PAX_KERNEXEC
18463 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18464 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18465 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18466 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18467 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18468 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18469 +#endif
18470 + pax_close_kernel();
18471 +#endif
18472 +
18473 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18474 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18475 + unreachable();
18476 +#else
18477 restart_lowmem(type);
18478 +#endif
18479 +
18480 }
18481 #ifdef CONFIG_APM_MODULE
18482 EXPORT_SYMBOL(machine_real_restart);
18483 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18484 * try to force a triple fault and then cycle between hitting the keyboard
18485 * controller and doing that
18486 */
18487 -static void native_machine_emergency_restart(void)
18488 +__noreturn static void native_machine_emergency_restart(void)
18489 {
18490 int i;
18491 int attempt = 0;
18492 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18493 #endif
18494 }
18495
18496 -static void __machine_emergency_restart(int emergency)
18497 +static __noreturn void __machine_emergency_restart(int emergency)
18498 {
18499 reboot_emergency = emergency;
18500 machine_ops.emergency_restart();
18501 }
18502
18503 -static void native_machine_restart(char *__unused)
18504 +static __noreturn void native_machine_restart(char *__unused)
18505 {
18506 printk("machine restart\n");
18507
18508 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18509 __machine_emergency_restart(0);
18510 }
18511
18512 -static void native_machine_halt(void)
18513 +static __noreturn void native_machine_halt(void)
18514 {
18515 /* stop other cpus and apics */
18516 machine_shutdown();
18517 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18518 stop_this_cpu(NULL);
18519 }
18520
18521 -static void native_machine_power_off(void)
18522 +__noreturn static void native_machine_power_off(void)
18523 {
18524 if (pm_power_off) {
18525 if (!reboot_force)
18526 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18527 }
18528 /* a fallback in case there is no PM info available */
18529 tboot_shutdown(TB_SHUTDOWN_HALT);
18530 + unreachable();
18531 }
18532
18533 struct machine_ops machine_ops = {
18534 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18535 index 7a6f3b3..bed145d7 100644
18536 --- a/arch/x86/kernel/relocate_kernel_64.S
18537 +++ b/arch/x86/kernel/relocate_kernel_64.S
18538 @@ -11,6 +11,7 @@
18539 #include <asm/kexec.h>
18540 #include <asm/processor-flags.h>
18541 #include <asm/pgtable_types.h>
18542 +#include <asm/alternative-asm.h>
18543
18544 /*
18545 * Must be relocatable PIC code callable as a C function
18546 @@ -160,13 +161,14 @@ identity_mapped:
18547 xorq %rbp, %rbp
18548 xorq %r8, %r8
18549 xorq %r9, %r9
18550 - xorq %r10, %r9
18551 + xorq %r10, %r10
18552 xorq %r11, %r11
18553 xorq %r12, %r12
18554 xorq %r13, %r13
18555 xorq %r14, %r14
18556 xorq %r15, %r15
18557
18558 + pax_force_retaddr 0, 1
18559 ret
18560
18561 1:
18562 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18563 index d7d5099..28555d0 100644
18564 --- a/arch/x86/kernel/setup.c
18565 +++ b/arch/x86/kernel/setup.c
18566 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18567
18568 switch (data->type) {
18569 case SETUP_E820_EXT:
18570 - parse_e820_ext(data);
18571 + parse_e820_ext((struct setup_data __force_kernel *)data);
18572 break;
18573 case SETUP_DTB:
18574 add_dtb(pa_data);
18575 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18576 * area (640->1Mb) as ram even though it is not.
18577 * take them out.
18578 */
18579 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18580 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18581 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18582 }
18583
18584 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18585
18586 if (!boot_params.hdr.root_flags)
18587 root_mountflags &= ~MS_RDONLY;
18588 - init_mm.start_code = (unsigned long) _text;
18589 - init_mm.end_code = (unsigned long) _etext;
18590 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18591 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18592 init_mm.end_data = (unsigned long) _edata;
18593 init_mm.brk = _brk_end;
18594
18595 - code_resource.start = virt_to_phys(_text);
18596 - code_resource.end = virt_to_phys(_etext)-1;
18597 - data_resource.start = virt_to_phys(_etext);
18598 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18599 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18600 + data_resource.start = virt_to_phys(_sdata);
18601 data_resource.end = virt_to_phys(_edata)-1;
18602 bss_resource.start = virt_to_phys(&__bss_start);
18603 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18604 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18605 index 71f4727..217419b 100644
18606 --- a/arch/x86/kernel/setup_percpu.c
18607 +++ b/arch/x86/kernel/setup_percpu.c
18608 @@ -21,19 +21,17 @@
18609 #include <asm/cpu.h>
18610 #include <asm/stackprotector.h>
18611
18612 -DEFINE_PER_CPU(int, cpu_number);
18613 +#ifdef CONFIG_SMP
18614 +DEFINE_PER_CPU(unsigned int, cpu_number);
18615 EXPORT_PER_CPU_SYMBOL(cpu_number);
18616 +#endif
18617
18618 -#ifdef CONFIG_X86_64
18619 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18620 -#else
18621 -#define BOOT_PERCPU_OFFSET 0
18622 -#endif
18623
18624 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18625 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18626
18627 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18628 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18629 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18630 };
18631 EXPORT_SYMBOL(__per_cpu_offset);
18632 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18633 * Pointer to the allocated area on success, NULL on failure.
18634 */
18635 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18636 + unsigned long align) __size_overflow(2);
18637 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18638 unsigned long align)
18639 {
18640 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18641 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18642 /*
18643 * Helpers for first chunk memory allocation
18644 */
18645 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18646 +
18647 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18648 {
18649 return pcpu_alloc_bootmem(cpu, size, align);
18650 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18651 {
18652 #ifdef CONFIG_X86_32
18653 struct desc_struct gdt;
18654 + unsigned long base = per_cpu_offset(cpu);
18655
18656 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18657 - 0x2 | DESCTYPE_S, 0x8);
18658 - gdt.s = 1;
18659 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18660 + 0x83 | DESCTYPE_S, 0xC);
18661 write_gdt_entry(get_cpu_gdt_table(cpu),
18662 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18663 #endif
18664 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18665 /* alrighty, percpu areas up and running */
18666 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18667 for_each_possible_cpu(cpu) {
18668 +#ifdef CONFIG_CC_STACKPROTECTOR
18669 +#ifdef CONFIG_X86_32
18670 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18671 +#endif
18672 +#endif
18673 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18674 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18675 per_cpu(cpu_number, cpu) = cpu;
18676 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18677 */
18678 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18679 #endif
18680 +#ifdef CONFIG_CC_STACKPROTECTOR
18681 +#ifdef CONFIG_X86_32
18682 + if (!cpu)
18683 + per_cpu(stack_canary.canary, cpu) = canary;
18684 +#endif
18685 +#endif
18686 /*
18687 * Up to this point, the boot CPU has been using .init.data
18688 * area. Reload any changed state for the boot CPU.
18689 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18690 index 46a01bd..2e88e6d 100644
18691 --- a/arch/x86/kernel/signal.c
18692 +++ b/arch/x86/kernel/signal.c
18693 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18694 * Align the stack pointer according to the i386 ABI,
18695 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18696 */
18697 - sp = ((sp + 4) & -16ul) - 4;
18698 + sp = ((sp - 12) & -16ul) - 4;
18699 #else /* !CONFIG_X86_32 */
18700 sp = round_down(sp, 16) - 8;
18701 #endif
18702 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18703 * Return an always-bogus address instead so we will die with SIGSEGV.
18704 */
18705 if (onsigstack && !likely(on_sig_stack(sp)))
18706 - return (void __user *)-1L;
18707 + return (__force void __user *)-1L;
18708
18709 /* save i387 state */
18710 if (used_math() && save_i387_xstate(*fpstate) < 0)
18711 - return (void __user *)-1L;
18712 + return (__force void __user *)-1L;
18713
18714 return (void __user *)sp;
18715 }
18716 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18717 }
18718
18719 if (current->mm->context.vdso)
18720 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18721 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18722 else
18723 - restorer = &frame->retcode;
18724 + restorer = (void __user *)&frame->retcode;
18725 if (ka->sa.sa_flags & SA_RESTORER)
18726 restorer = ka->sa.sa_restorer;
18727
18728 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18729 * reasons and because gdb uses it as a signature to notice
18730 * signal handler stack frames.
18731 */
18732 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18733 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18734
18735 if (err)
18736 return -EFAULT;
18737 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18738 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18739
18740 /* Set up to return from userspace. */
18741 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18742 + if (current->mm->context.vdso)
18743 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18744 + else
18745 + restorer = (void __user *)&frame->retcode;
18746 if (ka->sa.sa_flags & SA_RESTORER)
18747 restorer = ka->sa.sa_restorer;
18748 put_user_ex(restorer, &frame->pretcode);
18749 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18750 * reasons and because gdb uses it as a signature to notice
18751 * signal handler stack frames.
18752 */
18753 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18754 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18755 } put_user_catch(err);
18756
18757 if (err)
18758 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18759 * X86_32: vm86 regs switched out by assembly code before reaching
18760 * here, so testing against kernel CS suffices.
18761 */
18762 - if (!user_mode(regs))
18763 + if (!user_mode_novm(regs))
18764 return;
18765
18766 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18767 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18768 index 66d250c..f1b10bd 100644
18769 --- a/arch/x86/kernel/smpboot.c
18770 +++ b/arch/x86/kernel/smpboot.c
18771 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18772 set_idle_for_cpu(cpu, c_idle.idle);
18773 do_rest:
18774 per_cpu(current_task, cpu) = c_idle.idle;
18775 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18776 #ifdef CONFIG_X86_32
18777 /* Stack for startup_32 can be just as for start_secondary onwards */
18778 irq_ctx_init(cpu);
18779 #else
18780 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18781 initial_gs = per_cpu_offset(cpu);
18782 - per_cpu(kernel_stack, cpu) =
18783 - (unsigned long)task_stack_page(c_idle.idle) -
18784 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18785 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18786 #endif
18787 +
18788 + pax_open_kernel();
18789 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18790 + pax_close_kernel();
18791 +
18792 initial_code = (unsigned long)start_secondary;
18793 stack_start = c_idle.idle->thread.sp;
18794
18795 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18796
18797 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18798
18799 +#ifdef CONFIG_PAX_PER_CPU_PGD
18800 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18801 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18802 + KERNEL_PGD_PTRS);
18803 +#endif
18804 +
18805 err = do_boot_cpu(apicid, cpu);
18806 if (err) {
18807 pr_debug("do_boot_cpu failed %d\n", err);
18808 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18809 index c346d11..d43b163 100644
18810 --- a/arch/x86/kernel/step.c
18811 +++ b/arch/x86/kernel/step.c
18812 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18813 struct desc_struct *desc;
18814 unsigned long base;
18815
18816 - seg &= ~7UL;
18817 + seg >>= 3;
18818
18819 mutex_lock(&child->mm->context.lock);
18820 - if (unlikely((seg >> 3) >= child->mm->context.size))
18821 + if (unlikely(seg >= child->mm->context.size))
18822 addr = -1L; /* bogus selector, access would fault */
18823 else {
18824 desc = child->mm->context.ldt + seg;
18825 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18826 addr += base;
18827 }
18828 mutex_unlock(&child->mm->context.lock);
18829 - }
18830 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18831 + addr = ktla_ktva(addr);
18832
18833 return addr;
18834 }
18835 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18836 unsigned char opcode[15];
18837 unsigned long addr = convert_ip_to_linear(child, regs);
18838
18839 + if (addr == -EINVAL)
18840 + return 0;
18841 +
18842 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18843 for (i = 0; i < copied; i++) {
18844 switch (opcode[i]) {
18845 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18846 index 0b0cb5f..db6b9ed 100644
18847 --- a/arch/x86/kernel/sys_i386_32.c
18848 +++ b/arch/x86/kernel/sys_i386_32.c
18849 @@ -24,17 +24,224 @@
18850
18851 #include <asm/syscalls.h>
18852
18853 -/*
18854 - * Do a system call from kernel instead of calling sys_execve so we
18855 - * end up with proper pt_regs.
18856 - */
18857 -int kernel_execve(const char *filename,
18858 - const char *const argv[],
18859 - const char *const envp[])
18860 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18861 {
18862 - long __res;
18863 - asm volatile ("int $0x80"
18864 - : "=a" (__res)
18865 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18866 - return __res;
18867 + unsigned long pax_task_size = TASK_SIZE;
18868 +
18869 +#ifdef CONFIG_PAX_SEGMEXEC
18870 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18871 + pax_task_size = SEGMEXEC_TASK_SIZE;
18872 +#endif
18873 +
18874 + if (len > pax_task_size || addr > pax_task_size - len)
18875 + return -EINVAL;
18876 +
18877 + return 0;
18878 +}
18879 +
18880 +unsigned long
18881 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18882 + unsigned long len, unsigned long pgoff, unsigned long flags)
18883 +{
18884 + struct mm_struct *mm = current->mm;
18885 + struct vm_area_struct *vma;
18886 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18887 +
18888 +#ifdef CONFIG_PAX_SEGMEXEC
18889 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18890 + pax_task_size = SEGMEXEC_TASK_SIZE;
18891 +#endif
18892 +
18893 + pax_task_size -= PAGE_SIZE;
18894 +
18895 + if (len > pax_task_size)
18896 + return -ENOMEM;
18897 +
18898 + if (flags & MAP_FIXED)
18899 + return addr;
18900 +
18901 +#ifdef CONFIG_PAX_RANDMMAP
18902 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18903 +#endif
18904 +
18905 + if (addr) {
18906 + addr = PAGE_ALIGN(addr);
18907 + if (pax_task_size - len >= addr) {
18908 + vma = find_vma(mm, addr);
18909 + if (check_heap_stack_gap(vma, addr, len))
18910 + return addr;
18911 + }
18912 + }
18913 + if (len > mm->cached_hole_size) {
18914 + start_addr = addr = mm->free_area_cache;
18915 + } else {
18916 + start_addr = addr = mm->mmap_base;
18917 + mm->cached_hole_size = 0;
18918 + }
18919 +
18920 +#ifdef CONFIG_PAX_PAGEEXEC
18921 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18922 + start_addr = 0x00110000UL;
18923 +
18924 +#ifdef CONFIG_PAX_RANDMMAP
18925 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18926 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18927 +#endif
18928 +
18929 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18930 + start_addr = addr = mm->mmap_base;
18931 + else
18932 + addr = start_addr;
18933 + }
18934 +#endif
18935 +
18936 +full_search:
18937 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18938 + /* At this point: (!vma || addr < vma->vm_end). */
18939 + if (pax_task_size - len < addr) {
18940 + /*
18941 + * Start a new search - just in case we missed
18942 + * some holes.
18943 + */
18944 + if (start_addr != mm->mmap_base) {
18945 + start_addr = addr = mm->mmap_base;
18946 + mm->cached_hole_size = 0;
18947 + goto full_search;
18948 + }
18949 + return -ENOMEM;
18950 + }
18951 + if (check_heap_stack_gap(vma, addr, len))
18952 + break;
18953 + if (addr + mm->cached_hole_size < vma->vm_start)
18954 + mm->cached_hole_size = vma->vm_start - addr;
18955 + addr = vma->vm_end;
18956 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18957 + start_addr = addr = mm->mmap_base;
18958 + mm->cached_hole_size = 0;
18959 + goto full_search;
18960 + }
18961 + }
18962 +
18963 + /*
18964 + * Remember the place where we stopped the search:
18965 + */
18966 + mm->free_area_cache = addr + len;
18967 + return addr;
18968 +}
18969 +
18970 +unsigned long
18971 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18972 + const unsigned long len, const unsigned long pgoff,
18973 + const unsigned long flags)
18974 +{
18975 + struct vm_area_struct *vma;
18976 + struct mm_struct *mm = current->mm;
18977 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18978 +
18979 +#ifdef CONFIG_PAX_SEGMEXEC
18980 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18981 + pax_task_size = SEGMEXEC_TASK_SIZE;
18982 +#endif
18983 +
18984 + pax_task_size -= PAGE_SIZE;
18985 +
18986 + /* requested length too big for entire address space */
18987 + if (len > pax_task_size)
18988 + return -ENOMEM;
18989 +
18990 + if (flags & MAP_FIXED)
18991 + return addr;
18992 +
18993 +#ifdef CONFIG_PAX_PAGEEXEC
18994 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18995 + goto bottomup;
18996 +#endif
18997 +
18998 +#ifdef CONFIG_PAX_RANDMMAP
18999 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19000 +#endif
19001 +
19002 + /* requesting a specific address */
19003 + if (addr) {
19004 + addr = PAGE_ALIGN(addr);
19005 + if (pax_task_size - len >= addr) {
19006 + vma = find_vma(mm, addr);
19007 + if (check_heap_stack_gap(vma, addr, len))
19008 + return addr;
19009 + }
19010 + }
19011 +
19012 + /* check if free_area_cache is useful for us */
19013 + if (len <= mm->cached_hole_size) {
19014 + mm->cached_hole_size = 0;
19015 + mm->free_area_cache = mm->mmap_base;
19016 + }
19017 +
19018 + /* either no address requested or can't fit in requested address hole */
19019 + addr = mm->free_area_cache;
19020 +
19021 + /* make sure it can fit in the remaining address space */
19022 + if (addr > len) {
19023 + vma = find_vma(mm, addr-len);
19024 + if (check_heap_stack_gap(vma, addr - len, len))
19025 + /* remember the address as a hint for next time */
19026 + return (mm->free_area_cache = addr-len);
19027 + }
19028 +
19029 + if (mm->mmap_base < len)
19030 + goto bottomup;
19031 +
19032 + addr = mm->mmap_base-len;
19033 +
19034 + do {
19035 + /*
19036 + * Lookup failure means no vma is above this address,
19037 + * else if new region fits below vma->vm_start,
19038 + * return with success:
19039 + */
19040 + vma = find_vma(mm, addr);
19041 + if (check_heap_stack_gap(vma, addr, len))
19042 + /* remember the address as a hint for next time */
19043 + return (mm->free_area_cache = addr);
19044 +
19045 + /* remember the largest hole we saw so far */
19046 + if (addr + mm->cached_hole_size < vma->vm_start)
19047 + mm->cached_hole_size = vma->vm_start - addr;
19048 +
19049 + /* try just below the current vma->vm_start */
19050 + addr = skip_heap_stack_gap(vma, len);
19051 + } while (!IS_ERR_VALUE(addr));
19052 +
19053 +bottomup:
19054 + /*
19055 + * A failed mmap() very likely causes application failure,
19056 + * so fall back to the bottom-up function here. This scenario
19057 + * can happen with large stack limits and large mmap()
19058 + * allocations.
19059 + */
19060 +
19061 +#ifdef CONFIG_PAX_SEGMEXEC
19062 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19063 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19064 + else
19065 +#endif
19066 +
19067 + mm->mmap_base = TASK_UNMAPPED_BASE;
19068 +
19069 +#ifdef CONFIG_PAX_RANDMMAP
19070 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19071 + mm->mmap_base += mm->delta_mmap;
19072 +#endif
19073 +
19074 + mm->free_area_cache = mm->mmap_base;
19075 + mm->cached_hole_size = ~0UL;
19076 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19077 + /*
19078 + * Restore the topdown base:
19079 + */
19080 + mm->mmap_base = base;
19081 + mm->free_area_cache = base;
19082 + mm->cached_hole_size = ~0UL;
19083 +
19084 + return addr;
19085 }
19086 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19087 index 0514890..3dbebce 100644
19088 --- a/arch/x86/kernel/sys_x86_64.c
19089 +++ b/arch/x86/kernel/sys_x86_64.c
19090 @@ -95,8 +95,8 @@ out:
19091 return error;
19092 }
19093
19094 -static void find_start_end(unsigned long flags, unsigned long *begin,
19095 - unsigned long *end)
19096 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19097 + unsigned long *begin, unsigned long *end)
19098 {
19099 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19100 unsigned long new_begin;
19101 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19102 *begin = new_begin;
19103 }
19104 } else {
19105 - *begin = TASK_UNMAPPED_BASE;
19106 + *begin = mm->mmap_base;
19107 *end = TASK_SIZE;
19108 }
19109 }
19110 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19111 if (flags & MAP_FIXED)
19112 return addr;
19113
19114 - find_start_end(flags, &begin, &end);
19115 + find_start_end(mm, flags, &begin, &end);
19116
19117 if (len > end)
19118 return -ENOMEM;
19119
19120 +#ifdef CONFIG_PAX_RANDMMAP
19121 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19122 +#endif
19123 +
19124 if (addr) {
19125 addr = PAGE_ALIGN(addr);
19126 vma = find_vma(mm, addr);
19127 - if (end - len >= addr &&
19128 - (!vma || addr + len <= vma->vm_start))
19129 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19130 return addr;
19131 }
19132 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19133 @@ -172,7 +175,7 @@ full_search:
19134 }
19135 return -ENOMEM;
19136 }
19137 - if (!vma || addr + len <= vma->vm_start) {
19138 + if (check_heap_stack_gap(vma, addr, len)) {
19139 /*
19140 * Remember the place where we stopped the search:
19141 */
19142 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19143 {
19144 struct vm_area_struct *vma;
19145 struct mm_struct *mm = current->mm;
19146 - unsigned long addr = addr0;
19147 + unsigned long base = mm->mmap_base, addr = addr0;
19148
19149 /* requested length too big for entire address space */
19150 if (len > TASK_SIZE)
19151 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19152 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19153 goto bottomup;
19154
19155 +#ifdef CONFIG_PAX_RANDMMAP
19156 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19157 +#endif
19158 +
19159 /* requesting a specific address */
19160 if (addr) {
19161 addr = PAGE_ALIGN(addr);
19162 - vma = find_vma(mm, addr);
19163 - if (TASK_SIZE - len >= addr &&
19164 - (!vma || addr + len <= vma->vm_start))
19165 - return addr;
19166 + if (TASK_SIZE - len >= addr) {
19167 + vma = find_vma(mm, addr);
19168 + if (check_heap_stack_gap(vma, addr, len))
19169 + return addr;
19170 + }
19171 }
19172
19173 /* check if free_area_cache is useful for us */
19174 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19175 ALIGN_TOPDOWN);
19176
19177 vma = find_vma(mm, tmp_addr);
19178 - if (!vma || tmp_addr + len <= vma->vm_start)
19179 + if (check_heap_stack_gap(vma, tmp_addr, len))
19180 /* remember the address as a hint for next time */
19181 return mm->free_area_cache = tmp_addr;
19182 }
19183 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19184 * return with success:
19185 */
19186 vma = find_vma(mm, addr);
19187 - if (!vma || addr+len <= vma->vm_start)
19188 + if (check_heap_stack_gap(vma, addr, len))
19189 /* remember the address as a hint for next time */
19190 return mm->free_area_cache = addr;
19191
19192 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19193 mm->cached_hole_size = vma->vm_start - addr;
19194
19195 /* try just below the current vma->vm_start */
19196 - addr = vma->vm_start-len;
19197 - } while (len < vma->vm_start);
19198 + addr = skip_heap_stack_gap(vma, len);
19199 + } while (!IS_ERR_VALUE(addr));
19200
19201 bottomup:
19202 /*
19203 @@ -270,13 +278,21 @@ bottomup:
19204 * can happen with large stack limits and large mmap()
19205 * allocations.
19206 */
19207 + mm->mmap_base = TASK_UNMAPPED_BASE;
19208 +
19209 +#ifdef CONFIG_PAX_RANDMMAP
19210 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19211 + mm->mmap_base += mm->delta_mmap;
19212 +#endif
19213 +
19214 + mm->free_area_cache = mm->mmap_base;
19215 mm->cached_hole_size = ~0UL;
19216 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19217 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19218 /*
19219 * Restore the topdown base:
19220 */
19221 - mm->free_area_cache = mm->mmap_base;
19222 + mm->mmap_base = base;
19223 + mm->free_area_cache = base;
19224 mm->cached_hole_size = ~0UL;
19225
19226 return addr;
19227 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19228 index e2410e2..4fe3fbc 100644
19229 --- a/arch/x86/kernel/tboot.c
19230 +++ b/arch/x86/kernel/tboot.c
19231 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19232
19233 void tboot_shutdown(u32 shutdown_type)
19234 {
19235 - void (*shutdown)(void);
19236 + void (* __noreturn shutdown)(void);
19237
19238 if (!tboot_enabled())
19239 return;
19240 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19241
19242 switch_to_tboot_pt();
19243
19244 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19245 + shutdown = (void *)tboot->shutdown_entry;
19246 shutdown();
19247
19248 /* should not reach here */
19249 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19250 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19251 }
19252
19253 -static atomic_t ap_wfs_count;
19254 +static atomic_unchecked_t ap_wfs_count;
19255
19256 static int tboot_wait_for_aps(int num_aps)
19257 {
19258 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19259 {
19260 switch (action) {
19261 case CPU_DYING:
19262 - atomic_inc(&ap_wfs_count);
19263 + atomic_inc_unchecked(&ap_wfs_count);
19264 if (num_online_cpus() == 1)
19265 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19266 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19267 return NOTIFY_BAD;
19268 break;
19269 }
19270 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19271
19272 tboot_create_trampoline();
19273
19274 - atomic_set(&ap_wfs_count, 0);
19275 + atomic_set_unchecked(&ap_wfs_count, 0);
19276 register_hotcpu_notifier(&tboot_cpu_notifier);
19277 return 0;
19278 }
19279 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19280 index dd5fbf4..b7f2232 100644
19281 --- a/arch/x86/kernel/time.c
19282 +++ b/arch/x86/kernel/time.c
19283 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19284 {
19285 unsigned long pc = instruction_pointer(regs);
19286
19287 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19288 + if (!user_mode(regs) && in_lock_functions(pc)) {
19289 #ifdef CONFIG_FRAME_POINTER
19290 - return *(unsigned long *)(regs->bp + sizeof(long));
19291 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19292 #else
19293 unsigned long *sp =
19294 (unsigned long *)kernel_stack_pointer(regs);
19295 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19296 * or above a saved flags. Eflags has bits 22-31 zero,
19297 * kernel addresses don't.
19298 */
19299 +
19300 +#ifdef CONFIG_PAX_KERNEXEC
19301 + return ktla_ktva(sp[0]);
19302 +#else
19303 if (sp[0] >> 22)
19304 return sp[0];
19305 if (sp[1] >> 22)
19306 return sp[1];
19307 #endif
19308 +
19309 +#endif
19310 }
19311 return pc;
19312 }
19313 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19314 index bcfec2d..8f88b4a 100644
19315 --- a/arch/x86/kernel/tls.c
19316 +++ b/arch/x86/kernel/tls.c
19317 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19318 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19319 return -EINVAL;
19320
19321 +#ifdef CONFIG_PAX_SEGMEXEC
19322 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19323 + return -EINVAL;
19324 +#endif
19325 +
19326 set_tls_desc(p, idx, &info, 1);
19327
19328 return 0;
19329 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19330 index 2f083a2..7d3fecc 100644
19331 --- a/arch/x86/kernel/tls.h
19332 +++ b/arch/x86/kernel/tls.h
19333 @@ -16,6 +16,6 @@
19334
19335 extern user_regset_active_fn regset_tls_active;
19336 extern user_regset_get_fn regset_tls_get;
19337 -extern user_regset_set_fn regset_tls_set;
19338 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19339
19340 #endif /* _ARCH_X86_KERNEL_TLS_H */
19341 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19342 index 451c0a7..e57f551 100644
19343 --- a/arch/x86/kernel/trampoline_32.S
19344 +++ b/arch/x86/kernel/trampoline_32.S
19345 @@ -32,6 +32,12 @@
19346 #include <asm/segment.h>
19347 #include <asm/page_types.h>
19348
19349 +#ifdef CONFIG_PAX_KERNEXEC
19350 +#define ta(X) (X)
19351 +#else
19352 +#define ta(X) ((X) - __PAGE_OFFSET)
19353 +#endif
19354 +
19355 #ifdef CONFIG_SMP
19356
19357 .section ".x86_trampoline","a"
19358 @@ -62,7 +68,7 @@ r_base = .
19359 inc %ax # protected mode (PE) bit
19360 lmsw %ax # into protected mode
19361 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19362 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19363 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19364
19365 # These need to be in the same 64K segment as the above;
19366 # hence we don't use the boot_gdt_descr defined in head.S
19367 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19368 index 09ff517..df19fbff 100644
19369 --- a/arch/x86/kernel/trampoline_64.S
19370 +++ b/arch/x86/kernel/trampoline_64.S
19371 @@ -90,7 +90,7 @@ startup_32:
19372 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19373 movl %eax, %ds
19374
19375 - movl $X86_CR4_PAE, %eax
19376 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19377 movl %eax, %cr4 # Enable PAE mode
19378
19379 # Setup trampoline 4 level pagetables
19380 @@ -138,7 +138,7 @@ tidt:
19381 # so the kernel can live anywhere
19382 .balign 4
19383 tgdt:
19384 - .short tgdt_end - tgdt # gdt limit
19385 + .short tgdt_end - tgdt - 1 # gdt limit
19386 .long tgdt - r_base
19387 .short 0
19388 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19389 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19390 index 4bbe04d..41d0943 100644
19391 --- a/arch/x86/kernel/traps.c
19392 +++ b/arch/x86/kernel/traps.c
19393 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19394
19395 /* Do we ignore FPU interrupts ? */
19396 char ignore_fpu_irq;
19397 -
19398 -/*
19399 - * The IDT has to be page-aligned to simplify the Pentium
19400 - * F0 0F bug workaround.
19401 - */
19402 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19403 #endif
19404
19405 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19406 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19407 }
19408
19409 static void __kprobes
19410 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19411 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19412 long error_code, siginfo_t *info)
19413 {
19414 struct task_struct *tsk = current;
19415
19416 #ifdef CONFIG_X86_32
19417 - if (regs->flags & X86_VM_MASK) {
19418 + if (v8086_mode(regs)) {
19419 /*
19420 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19421 * On nmi (interrupt 2), do_trap should not be called.
19422 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19423 }
19424 #endif
19425
19426 - if (!user_mode(regs))
19427 + if (!user_mode_novm(regs))
19428 goto kernel_trap;
19429
19430 #ifdef CONFIG_X86_32
19431 @@ -148,7 +142,7 @@ trap_signal:
19432 printk_ratelimit()) {
19433 printk(KERN_INFO
19434 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19435 - tsk->comm, tsk->pid, str,
19436 + tsk->comm, task_pid_nr(tsk), str,
19437 regs->ip, regs->sp, error_code);
19438 print_vma_addr(" in ", regs->ip);
19439 printk("\n");
19440 @@ -165,8 +159,20 @@ kernel_trap:
19441 if (!fixup_exception(regs)) {
19442 tsk->thread.error_code = error_code;
19443 tsk->thread.trap_no = trapnr;
19444 +
19445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19446 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19447 + str = "PAX: suspicious stack segment fault";
19448 +#endif
19449 +
19450 die(str, regs, error_code);
19451 }
19452 +
19453 +#ifdef CONFIG_PAX_REFCOUNT
19454 + if (trapnr == 4)
19455 + pax_report_refcount_overflow(regs);
19456 +#endif
19457 +
19458 return;
19459
19460 #ifdef CONFIG_X86_32
19461 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19462 conditional_sti(regs);
19463
19464 #ifdef CONFIG_X86_32
19465 - if (regs->flags & X86_VM_MASK)
19466 + if (v8086_mode(regs))
19467 goto gp_in_vm86;
19468 #endif
19469
19470 tsk = current;
19471 - if (!user_mode(regs))
19472 + if (!user_mode_novm(regs))
19473 goto gp_in_kernel;
19474
19475 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19476 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19477 + struct mm_struct *mm = tsk->mm;
19478 + unsigned long limit;
19479 +
19480 + down_write(&mm->mmap_sem);
19481 + limit = mm->context.user_cs_limit;
19482 + if (limit < TASK_SIZE) {
19483 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19484 + up_write(&mm->mmap_sem);
19485 + return;
19486 + }
19487 + up_write(&mm->mmap_sem);
19488 + }
19489 +#endif
19490 +
19491 tsk->thread.error_code = error_code;
19492 tsk->thread.trap_no = 13;
19493
19494 @@ -295,6 +317,13 @@ gp_in_kernel:
19495 if (notify_die(DIE_GPF, "general protection fault", regs,
19496 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19497 return;
19498 +
19499 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19500 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19501 + die("PAX: suspicious general protection fault", regs, error_code);
19502 + else
19503 +#endif
19504 +
19505 die("general protection fault", regs, error_code);
19506 }
19507
19508 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19509 /* It's safe to allow irq's after DR6 has been saved */
19510 preempt_conditional_sti(regs);
19511
19512 - if (regs->flags & X86_VM_MASK) {
19513 + if (v8086_mode(regs)) {
19514 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19515 error_code, 1);
19516 preempt_conditional_cli(regs);
19517 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19518 * We already checked v86 mode above, so we can check for kernel mode
19519 * by just checking the CPL of CS.
19520 */
19521 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19522 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19523 tsk->thread.debugreg6 &= ~DR_STEP;
19524 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19525 regs->flags &= ~X86_EFLAGS_TF;
19526 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19527 return;
19528 conditional_sti(regs);
19529
19530 - if (!user_mode_vm(regs))
19531 + if (!user_mode(regs))
19532 {
19533 if (!fixup_exception(regs)) {
19534 task->thread.error_code = error_code;
19535 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19536 index b9242ba..50c5edd 100644
19537 --- a/arch/x86/kernel/verify_cpu.S
19538 +++ b/arch/x86/kernel/verify_cpu.S
19539 @@ -20,6 +20,7 @@
19540 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19541 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19542 * arch/x86/kernel/head_32.S: processor startup
19543 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19544 *
19545 * verify_cpu, returns the status of longmode and SSE in register %eax.
19546 * 0: Success 1: Failure
19547 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19548 index 328cb37..f37fee1 100644
19549 --- a/arch/x86/kernel/vm86_32.c
19550 +++ b/arch/x86/kernel/vm86_32.c
19551 @@ -41,6 +41,7 @@
19552 #include <linux/ptrace.h>
19553 #include <linux/audit.h>
19554 #include <linux/stddef.h>
19555 +#include <linux/grsecurity.h>
19556
19557 #include <asm/uaccess.h>
19558 #include <asm/io.h>
19559 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
19560 /* convert vm86_regs to kernel_vm86_regs */
19561 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19562 const struct vm86_regs __user *user,
19563 + unsigned extra) __size_overflow(3);
19564 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19565 + const struct vm86_regs __user *user,
19566 unsigned extra)
19567 {
19568 int ret = 0;
19569 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19570 do_exit(SIGSEGV);
19571 }
19572
19573 - tss = &per_cpu(init_tss, get_cpu());
19574 + tss = init_tss + get_cpu();
19575 current->thread.sp0 = current->thread.saved_sp0;
19576 current->thread.sysenter_cs = __KERNEL_CS;
19577 load_sp0(tss, &current->thread);
19578 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19579 struct task_struct *tsk;
19580 int tmp, ret = -EPERM;
19581
19582 +#ifdef CONFIG_GRKERNSEC_VM86
19583 + if (!capable(CAP_SYS_RAWIO)) {
19584 + gr_handle_vm86();
19585 + goto out;
19586 + }
19587 +#endif
19588 +
19589 tsk = current;
19590 if (tsk->thread.saved_sp0)
19591 goto out;
19592 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19593 int tmp, ret;
19594 struct vm86plus_struct __user *v86;
19595
19596 +#ifdef CONFIG_GRKERNSEC_VM86
19597 + if (!capable(CAP_SYS_RAWIO)) {
19598 + gr_handle_vm86();
19599 + ret = -EPERM;
19600 + goto out;
19601 + }
19602 +#endif
19603 +
19604 tsk = current;
19605 switch (cmd) {
19606 case VM86_REQUEST_IRQ:
19607 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19608 tsk->thread.saved_fs = info->regs32->fs;
19609 tsk->thread.saved_gs = get_user_gs(info->regs32);
19610
19611 - tss = &per_cpu(init_tss, get_cpu());
19612 + tss = init_tss + get_cpu();
19613 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19614 if (cpu_has_sep)
19615 tsk->thread.sysenter_cs = 0;
19616 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19617 goto cannot_handle;
19618 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19619 goto cannot_handle;
19620 - intr_ptr = (unsigned long __user *) (i << 2);
19621 + intr_ptr = (__force unsigned long __user *) (i << 2);
19622 if (get_user(segoffs, intr_ptr))
19623 goto cannot_handle;
19624 if ((segoffs >> 16) == BIOSSEG)
19625 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19626 index 0f703f1..9e15f64 100644
19627 --- a/arch/x86/kernel/vmlinux.lds.S
19628 +++ b/arch/x86/kernel/vmlinux.lds.S
19629 @@ -26,6 +26,13 @@
19630 #include <asm/page_types.h>
19631 #include <asm/cache.h>
19632 #include <asm/boot.h>
19633 +#include <asm/segment.h>
19634 +
19635 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19636 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19637 +#else
19638 +#define __KERNEL_TEXT_OFFSET 0
19639 +#endif
19640
19641 #undef i386 /* in case the preprocessor is a 32bit one */
19642
19643 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19644
19645 PHDRS {
19646 text PT_LOAD FLAGS(5); /* R_E */
19647 +#ifdef CONFIG_X86_32
19648 + module PT_LOAD FLAGS(5); /* R_E */
19649 +#endif
19650 +#ifdef CONFIG_XEN
19651 + rodata PT_LOAD FLAGS(5); /* R_E */
19652 +#else
19653 + rodata PT_LOAD FLAGS(4); /* R__ */
19654 +#endif
19655 data PT_LOAD FLAGS(6); /* RW_ */
19656 -#ifdef CONFIG_X86_64
19657 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19658 #ifdef CONFIG_SMP
19659 percpu PT_LOAD FLAGS(6); /* RW_ */
19660 #endif
19661 + text.init PT_LOAD FLAGS(5); /* R_E */
19662 + text.exit PT_LOAD FLAGS(5); /* R_E */
19663 init PT_LOAD FLAGS(7); /* RWE */
19664 -#endif
19665 note PT_NOTE FLAGS(0); /* ___ */
19666 }
19667
19668 SECTIONS
19669 {
19670 #ifdef CONFIG_X86_32
19671 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19672 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19673 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19674 #else
19675 - . = __START_KERNEL;
19676 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19677 + . = __START_KERNEL;
19678 #endif
19679
19680 /* Text and read-only data */
19681 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19682 - _text = .;
19683 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19684 /* bootstrapping code */
19685 +#ifdef CONFIG_X86_32
19686 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19687 +#else
19688 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19689 +#endif
19690 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19691 + _text = .;
19692 HEAD_TEXT
19693 #ifdef CONFIG_X86_32
19694 . = ALIGN(PAGE_SIZE);
19695 @@ -108,13 +128,47 @@ SECTIONS
19696 IRQENTRY_TEXT
19697 *(.fixup)
19698 *(.gnu.warning)
19699 - /* End of text section */
19700 - _etext = .;
19701 } :text = 0x9090
19702
19703 - NOTES :text :note
19704 + . += __KERNEL_TEXT_OFFSET;
19705
19706 - EXCEPTION_TABLE(16) :text = 0x9090
19707 +#ifdef CONFIG_X86_32
19708 + . = ALIGN(PAGE_SIZE);
19709 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19710 +
19711 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19712 + MODULES_EXEC_VADDR = .;
19713 + BYTE(0)
19714 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19715 + . = ALIGN(HPAGE_SIZE);
19716 + MODULES_EXEC_END = . - 1;
19717 +#endif
19718 +
19719 + } :module
19720 +#endif
19721 +
19722 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19723 + /* End of text section */
19724 + _etext = . - __KERNEL_TEXT_OFFSET;
19725 + }
19726 +
19727 +#ifdef CONFIG_X86_32
19728 + . = ALIGN(PAGE_SIZE);
19729 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19730 + *(.idt)
19731 + . = ALIGN(PAGE_SIZE);
19732 + *(.empty_zero_page)
19733 + *(.initial_pg_fixmap)
19734 + *(.initial_pg_pmd)
19735 + *(.initial_page_table)
19736 + *(.swapper_pg_dir)
19737 + } :rodata
19738 +#endif
19739 +
19740 + . = ALIGN(PAGE_SIZE);
19741 + NOTES :rodata :note
19742 +
19743 + EXCEPTION_TABLE(16) :rodata
19744
19745 #if defined(CONFIG_DEBUG_RODATA)
19746 /* .text should occupy whole number of pages */
19747 @@ -126,16 +180,20 @@ SECTIONS
19748
19749 /* Data */
19750 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19751 +
19752 +#ifdef CONFIG_PAX_KERNEXEC
19753 + . = ALIGN(HPAGE_SIZE);
19754 +#else
19755 + . = ALIGN(PAGE_SIZE);
19756 +#endif
19757 +
19758 /* Start of data section */
19759 _sdata = .;
19760
19761 /* init_task */
19762 INIT_TASK_DATA(THREAD_SIZE)
19763
19764 -#ifdef CONFIG_X86_32
19765 - /* 32 bit has nosave before _edata */
19766 NOSAVE_DATA
19767 -#endif
19768
19769 PAGE_ALIGNED_DATA(PAGE_SIZE)
19770
19771 @@ -176,12 +234,19 @@ SECTIONS
19772 #endif /* CONFIG_X86_64 */
19773
19774 /* Init code and data - will be freed after init */
19775 - . = ALIGN(PAGE_SIZE);
19776 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19777 + BYTE(0)
19778 +
19779 +#ifdef CONFIG_PAX_KERNEXEC
19780 + . = ALIGN(HPAGE_SIZE);
19781 +#else
19782 + . = ALIGN(PAGE_SIZE);
19783 +#endif
19784 +
19785 __init_begin = .; /* paired with __init_end */
19786 - }
19787 + } :init.begin
19788
19789 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19790 +#ifdef CONFIG_SMP
19791 /*
19792 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19793 * output PHDR, so the next output section - .init.text - should
19794 @@ -190,12 +255,27 @@ SECTIONS
19795 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19796 #endif
19797
19798 - INIT_TEXT_SECTION(PAGE_SIZE)
19799 -#ifdef CONFIG_X86_64
19800 - :init
19801 -#endif
19802 + . = ALIGN(PAGE_SIZE);
19803 + init_begin = .;
19804 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19805 + VMLINUX_SYMBOL(_sinittext) = .;
19806 + INIT_TEXT
19807 + VMLINUX_SYMBOL(_einittext) = .;
19808 + . = ALIGN(PAGE_SIZE);
19809 + } :text.init
19810
19811 - INIT_DATA_SECTION(16)
19812 + /*
19813 + * .exit.text is discard at runtime, not link time, to deal with
19814 + * references from .altinstructions and .eh_frame
19815 + */
19816 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19817 + EXIT_TEXT
19818 + . = ALIGN(16);
19819 + } :text.exit
19820 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19821 +
19822 + . = ALIGN(PAGE_SIZE);
19823 + INIT_DATA_SECTION(16) :init
19824
19825 /*
19826 * Code and data for a variety of lowlevel trampolines, to be
19827 @@ -269,19 +349,12 @@ SECTIONS
19828 }
19829
19830 . = ALIGN(8);
19831 - /*
19832 - * .exit.text is discard at runtime, not link time, to deal with
19833 - * references from .altinstructions and .eh_frame
19834 - */
19835 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19836 - EXIT_TEXT
19837 - }
19838
19839 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19840 EXIT_DATA
19841 }
19842
19843 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19844 +#ifndef CONFIG_SMP
19845 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19846 #endif
19847
19848 @@ -300,16 +373,10 @@ SECTIONS
19849 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19850 __smp_locks = .;
19851 *(.smp_locks)
19852 - . = ALIGN(PAGE_SIZE);
19853 __smp_locks_end = .;
19854 + . = ALIGN(PAGE_SIZE);
19855 }
19856
19857 -#ifdef CONFIG_X86_64
19858 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19859 - NOSAVE_DATA
19860 - }
19861 -#endif
19862 -
19863 /* BSS */
19864 . = ALIGN(PAGE_SIZE);
19865 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19866 @@ -325,6 +392,7 @@ SECTIONS
19867 __brk_base = .;
19868 . += 64 * 1024; /* 64k alignment slop space */
19869 *(.brk_reservation) /* areas brk users have reserved */
19870 + . = ALIGN(HPAGE_SIZE);
19871 __brk_limit = .;
19872 }
19873
19874 @@ -351,13 +419,12 @@ SECTIONS
19875 * for the boot processor.
19876 */
19877 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19878 -INIT_PER_CPU(gdt_page);
19879 INIT_PER_CPU(irq_stack_union);
19880
19881 /*
19882 * Build-time check on the image size:
19883 */
19884 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19885 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19886 "kernel image bigger than KERNEL_IMAGE_SIZE");
19887
19888 #ifdef CONFIG_SMP
19889 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19890 index b07ba93..a212969 100644
19891 --- a/arch/x86/kernel/vsyscall_64.c
19892 +++ b/arch/x86/kernel/vsyscall_64.c
19893 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19894 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19895 };
19896
19897 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19898 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19899
19900 static int __init vsyscall_setup(char *str)
19901 {
19902 if (str) {
19903 if (!strcmp("emulate", str))
19904 vsyscall_mode = EMULATE;
19905 - else if (!strcmp("native", str))
19906 - vsyscall_mode = NATIVE;
19907 else if (!strcmp("none", str))
19908 vsyscall_mode = NONE;
19909 else
19910 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19911
19912 tsk = current;
19913 if (seccomp_mode(&tsk->seccomp))
19914 - do_exit(SIGKILL);
19915 + do_group_exit(SIGKILL);
19916
19917 /*
19918 * With a real vsyscall, page faults cause SIGSEGV. We want to
19919 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19920 return true;
19921
19922 sigsegv:
19923 - force_sig(SIGSEGV, current);
19924 - return true;
19925 + do_group_exit(SIGKILL);
19926 }
19927
19928 /*
19929 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19930 extern char __vvar_page;
19931 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19932
19933 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19934 - vsyscall_mode == NATIVE
19935 - ? PAGE_KERNEL_VSYSCALL
19936 - : PAGE_KERNEL_VVAR);
19937 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19938 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19939 (unsigned long)VSYSCALL_START);
19940
19941 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19942 index 9796c2f..f686fbf 100644
19943 --- a/arch/x86/kernel/x8664_ksyms_64.c
19944 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19945 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19946 EXPORT_SYMBOL(copy_user_generic_string);
19947 EXPORT_SYMBOL(copy_user_generic_unrolled);
19948 EXPORT_SYMBOL(__copy_user_nocache);
19949 -EXPORT_SYMBOL(_copy_from_user);
19950 -EXPORT_SYMBOL(_copy_to_user);
19951
19952 EXPORT_SYMBOL(copy_page);
19953 EXPORT_SYMBOL(clear_page);
19954 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19955 index 7110911..e8cdee5 100644
19956 --- a/arch/x86/kernel/xsave.c
19957 +++ b/arch/x86/kernel/xsave.c
19958 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19959 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19960 return -EINVAL;
19961
19962 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19963 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19964 fx_sw_user->extended_size -
19965 FP_XSTATE_MAGIC2_SIZE));
19966 if (err)
19967 @@ -266,7 +266,7 @@ fx_only:
19968 * the other extended state.
19969 */
19970 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19971 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19972 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19973 }
19974
19975 /*
19976 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19977 if (use_xsave())
19978 err = restore_user_xstate(buf);
19979 else
19980 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19981 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19982 buf);
19983 if (unlikely(err)) {
19984 /*
19985 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
19986 index 89b02bf..0f6511d 100644
19987 --- a/arch/x86/kvm/cpuid.c
19988 +++ b/arch/x86/kvm/cpuid.c
19989 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19990 struct kvm_cpuid2 *cpuid,
19991 struct kvm_cpuid_entry2 __user *entries)
19992 {
19993 - int r;
19994 + int r, i;
19995
19996 r = -E2BIG;
19997 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19998 goto out;
19999 r = -EFAULT;
20000 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20001 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20002 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20003 goto out;
20004 + for (i = 0; i < cpuid->nent; ++i) {
20005 + struct kvm_cpuid_entry2 cpuid_entry;
20006 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20007 + goto out;
20008 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20009 + }
20010 vcpu->arch.cpuid_nent = cpuid->nent;
20011 kvm_apic_set_version(vcpu);
20012 kvm_x86_ops->cpuid_update(vcpu);
20013 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20014 struct kvm_cpuid2 *cpuid,
20015 struct kvm_cpuid_entry2 __user *entries)
20016 {
20017 - int r;
20018 + int r, i;
20019
20020 r = -E2BIG;
20021 if (cpuid->nent < vcpu->arch.cpuid_nent)
20022 goto out;
20023 r = -EFAULT;
20024 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20025 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20026 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20027 goto out;
20028 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20029 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20030 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20031 + goto out;
20032 + }
20033 return 0;
20034
20035 out:
20036 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20037 index 0982507..7f6d72f 100644
20038 --- a/arch/x86/kvm/emulate.c
20039 +++ b/arch/x86/kvm/emulate.c
20040 @@ -250,6 +250,7 @@ struct gprefix {
20041
20042 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20043 do { \
20044 + unsigned long _tmp; \
20045 __asm__ __volatile__ ( \
20046 _PRE_EFLAGS("0", "4", "2") \
20047 _op _suffix " %"_x"3,%1; " \
20048 @@ -264,8 +265,6 @@ struct gprefix {
20049 /* Raw emulation: instruction has two explicit operands. */
20050 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20051 do { \
20052 - unsigned long _tmp; \
20053 - \
20054 switch ((ctxt)->dst.bytes) { \
20055 case 2: \
20056 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20057 @@ -281,7 +280,6 @@ struct gprefix {
20058
20059 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20060 do { \
20061 - unsigned long _tmp; \
20062 switch ((ctxt)->dst.bytes) { \
20063 case 1: \
20064 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20065 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20066 index cfdc6e0..ab92e84 100644
20067 --- a/arch/x86/kvm/lapic.c
20068 +++ b/arch/x86/kvm/lapic.c
20069 @@ -54,7 +54,7 @@
20070 #define APIC_BUS_CYCLE_NS 1
20071
20072 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20073 -#define apic_debug(fmt, arg...)
20074 +#define apic_debug(fmt, arg...) do {} while (0)
20075
20076 #define APIC_LVT_NUM 6
20077 /* 14 is the version for Xeon and Pentium 8.4.8*/
20078 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20079 index 1561028..0ed7f14 100644
20080 --- a/arch/x86/kvm/paging_tmpl.h
20081 +++ b/arch/x86/kvm/paging_tmpl.h
20082 @@ -197,7 +197,7 @@ retry_walk:
20083 if (unlikely(kvm_is_error_hva(host_addr)))
20084 goto error;
20085
20086 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20087 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20088 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20089 goto error;
20090
20091 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20092 index e385214..029e9dd 100644
20093 --- a/arch/x86/kvm/svm.c
20094 +++ b/arch/x86/kvm/svm.c
20095 @@ -3051,6 +3051,7 @@ static int svm_set_vm_cr(struct kvm_vcpu *vcpu, u64 data)
20096 return 0;
20097 }
20098
20099 +static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) __size_overflow(3);
20100 static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
20101 {
20102 struct vcpu_svm *svm = to_svm(vcpu);
20103 @@ -3420,7 +3421,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20104 int cpu = raw_smp_processor_id();
20105
20106 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20107 +
20108 + pax_open_kernel();
20109 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20110 + pax_close_kernel();
20111 +
20112 load_TR_desc();
20113 }
20114
20115 @@ -3798,6 +3803,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20116 #endif
20117 #endif
20118
20119 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20120 + __set_fs(current_thread_info()->addr_limit);
20121 +#endif
20122 +
20123 reload_tss(vcpu);
20124
20125 local_irq_disable();
20126 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20127 index 3b4c8d8..4ae0af6 100644
20128 --- a/arch/x86/kvm/vmx.c
20129 +++ b/arch/x86/kvm/vmx.c
20130 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20131 struct desc_struct *descs;
20132
20133 descs = (void *)gdt->address;
20134 +
20135 + pax_open_kernel();
20136 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20137 + pax_close_kernel();
20138 +
20139 load_TR_desc();
20140 }
20141
20142 @@ -2162,6 +2166,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
20143 * Returns 0 on success, non-0 otherwise.
20144 * Assumes vcpu_load() was already called.
20145 */
20146 +static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) __size_overflow(3);
20147 static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
20148 {
20149 struct vcpu_vmx *vmx = to_vmx(vcpu);
20150 @@ -2631,8 +2636,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 +3656,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 +6192,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 +6246,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 +6279,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 5671752..6838cd1 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..d58cb51 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 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29358 index 1ee8ce7..b778bef 100644
29359 --- a/drivers/char/sonypi.c
29360 +++ b/drivers/char/sonypi.c
29361 @@ -55,6 +55,7 @@
29362 #include <asm/uaccess.h>
29363 #include <asm/io.h>
29364 #include <asm/system.h>
29365 +#include <asm/local.h>
29366
29367 #include <linux/sonypi.h>
29368
29369 @@ -491,7 +492,7 @@ static struct sonypi_device {
29370 spinlock_t fifo_lock;
29371 wait_queue_head_t fifo_proc_list;
29372 struct fasync_struct *fifo_async;
29373 - int open_count;
29374 + local_t open_count;
29375 int model;
29376 struct input_dev *input_jog_dev;
29377 struct input_dev *input_key_dev;
29378 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29379 static int sonypi_misc_release(struct inode *inode, struct file *file)
29380 {
29381 mutex_lock(&sonypi_device.lock);
29382 - sonypi_device.open_count--;
29383 + local_dec(&sonypi_device.open_count);
29384 mutex_unlock(&sonypi_device.lock);
29385 return 0;
29386 }
29387 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29388 {
29389 mutex_lock(&sonypi_device.lock);
29390 /* Flush input queue on first open */
29391 - if (!sonypi_device.open_count)
29392 + if (!local_read(&sonypi_device.open_count))
29393 kfifo_reset(&sonypi_device.fifo);
29394 - sonypi_device.open_count++;
29395 + local_inc(&sonypi_device.open_count);
29396 mutex_unlock(&sonypi_device.lock);
29397
29398 return 0;
29399 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29400 index ad7c732..5aa8054 100644
29401 --- a/drivers/char/tpm/tpm.c
29402 +++ b/drivers/char/tpm/tpm.c
29403 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29404 chip->vendor.req_complete_val)
29405 goto out_recv;
29406
29407 - if ((status == chip->vendor.req_canceled)) {
29408 + if (status == chip->vendor.req_canceled) {
29409 dev_err(chip->dev, "Operation Canceled\n");
29410 rc = -ECANCELED;
29411 goto out;
29412 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29413 index 0636520..169c1d0 100644
29414 --- a/drivers/char/tpm/tpm_bios.c
29415 +++ b/drivers/char/tpm/tpm_bios.c
29416 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29417 event = addr;
29418
29419 if ((event->event_type == 0 && event->event_size == 0) ||
29420 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29421 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29422 return NULL;
29423
29424 return addr;
29425 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29426 return NULL;
29427
29428 if ((event->event_type == 0 && event->event_size == 0) ||
29429 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29430 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29431 return NULL;
29432
29433 (*pos)++;
29434 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29435 int i;
29436
29437 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29438 - seq_putc(m, data[i]);
29439 + if (!seq_putc(m, data[i]))
29440 + return -EFAULT;
29441
29442 return 0;
29443 }
29444 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29445 log->bios_event_log_end = log->bios_event_log + len;
29446
29447 virt = acpi_os_map_memory(start, len);
29448 + if (!virt) {
29449 + kfree(log->bios_event_log);
29450 + log->bios_event_log = NULL;
29451 + return -EFAULT;
29452 + }
29453
29454 - memcpy(log->bios_event_log, virt, len);
29455 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29456
29457 acpi_os_unmap_memory(virt, len);
29458 return 0;
29459 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29460 index b58b561..c9088c8 100644
29461 --- a/drivers/char/virtio_console.c
29462 +++ b/drivers/char/virtio_console.c
29463 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29464 if (to_user) {
29465 ssize_t ret;
29466
29467 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29468 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29469 if (ret)
29470 return -EFAULT;
29471 } else {
29472 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29473 if (!port_has_data(port) && !port->host_connected)
29474 return 0;
29475
29476 - return fill_readbuf(port, ubuf, count, true);
29477 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29478 }
29479
29480 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29481 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29482 index c9eee6d..f9d5280 100644
29483 --- a/drivers/edac/amd64_edac.c
29484 +++ b/drivers/edac/amd64_edac.c
29485 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29486 * PCI core identifies what devices are on a system during boot, and then
29487 * inquiry this table to see if this driver is for a given device found.
29488 */
29489 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29490 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29491 {
29492 .vendor = PCI_VENDOR_ID_AMD,
29493 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29494 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29495 index e47e73b..348e0bd 100644
29496 --- a/drivers/edac/amd76x_edac.c
29497 +++ b/drivers/edac/amd76x_edac.c
29498 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29499 edac_mc_free(mci);
29500 }
29501
29502 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29503 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29504 {
29505 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29506 AMD762},
29507 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29508 index 1af531a..3a8ff27 100644
29509 --- a/drivers/edac/e752x_edac.c
29510 +++ b/drivers/edac/e752x_edac.c
29511 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29512 edac_mc_free(mci);
29513 }
29514
29515 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29516 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29517 {
29518 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29519 E7520},
29520 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29521 index 6ffb6d2..383d8d7 100644
29522 --- a/drivers/edac/e7xxx_edac.c
29523 +++ b/drivers/edac/e7xxx_edac.c
29524 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29525 edac_mc_free(mci);
29526 }
29527
29528 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29529 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29530 {
29531 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29532 E7205},
29533 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29534 index 97f5064..202b6e6 100644
29535 --- a/drivers/edac/edac_pci_sysfs.c
29536 +++ b/drivers/edac/edac_pci_sysfs.c
29537 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29538 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29539 static int edac_pci_poll_msec = 1000; /* one second workq period */
29540
29541 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29542 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29543 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29544 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29545
29546 static struct kobject *edac_pci_top_main_kobj;
29547 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29548 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29549 edac_printk(KERN_CRIT, EDAC_PCI,
29550 "Signaled System Error on %s\n",
29551 pci_name(dev));
29552 - atomic_inc(&pci_nonparity_count);
29553 + atomic_inc_unchecked(&pci_nonparity_count);
29554 }
29555
29556 if (status & (PCI_STATUS_PARITY)) {
29557 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29558 "Master Data Parity Error on %s\n",
29559 pci_name(dev));
29560
29561 - atomic_inc(&pci_parity_count);
29562 + atomic_inc_unchecked(&pci_parity_count);
29563 }
29564
29565 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29566 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29567 "Detected Parity Error on %s\n",
29568 pci_name(dev));
29569
29570 - atomic_inc(&pci_parity_count);
29571 + atomic_inc_unchecked(&pci_parity_count);
29572 }
29573 }
29574
29575 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29576 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29577 "Signaled System Error on %s\n",
29578 pci_name(dev));
29579 - atomic_inc(&pci_nonparity_count);
29580 + atomic_inc_unchecked(&pci_nonparity_count);
29581 }
29582
29583 if (status & (PCI_STATUS_PARITY)) {
29584 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29585 "Master Data Parity Error on "
29586 "%s\n", pci_name(dev));
29587
29588 - atomic_inc(&pci_parity_count);
29589 + atomic_inc_unchecked(&pci_parity_count);
29590 }
29591
29592 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29593 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29594 "Detected Parity Error on %s\n",
29595 pci_name(dev));
29596
29597 - atomic_inc(&pci_parity_count);
29598 + atomic_inc_unchecked(&pci_parity_count);
29599 }
29600 }
29601 }
29602 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29603 if (!check_pci_errors)
29604 return;
29605
29606 - before_count = atomic_read(&pci_parity_count);
29607 + before_count = atomic_read_unchecked(&pci_parity_count);
29608
29609 /* scan all PCI devices looking for a Parity Error on devices and
29610 * bridges.
29611 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29612 /* Only if operator has selected panic on PCI Error */
29613 if (edac_pci_get_panic_on_pe()) {
29614 /* If the count is different 'after' from 'before' */
29615 - if (before_count != atomic_read(&pci_parity_count))
29616 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29617 panic("EDAC: PCI Parity Error");
29618 }
29619 }
29620 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29621 index c0510b3..6e2a954 100644
29622 --- a/drivers/edac/i3000_edac.c
29623 +++ b/drivers/edac/i3000_edac.c
29624 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29625 edac_mc_free(mci);
29626 }
29627
29628 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29629 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29630 {
29631 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29632 I3000},
29633 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29634 index 73f55e200..5faaf59 100644
29635 --- a/drivers/edac/i3200_edac.c
29636 +++ b/drivers/edac/i3200_edac.c
29637 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29638 edac_mc_free(mci);
29639 }
29640
29641 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29642 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29643 {
29644 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29645 I3200},
29646 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29647 index 4dc3ac2..67d05a6 100644
29648 --- a/drivers/edac/i5000_edac.c
29649 +++ b/drivers/edac/i5000_edac.c
29650 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29651 *
29652 * The "E500P" device is the first device supported.
29653 */
29654 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29655 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29656 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29657 .driver_data = I5000P},
29658
29659 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29660 index bcbdeec..9886d16 100644
29661 --- a/drivers/edac/i5100_edac.c
29662 +++ b/drivers/edac/i5100_edac.c
29663 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29664 edac_mc_free(mci);
29665 }
29666
29667 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29668 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29669 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29670 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29671 { 0, }
29672 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29673 index 74d6ec34..baff517 100644
29674 --- a/drivers/edac/i5400_edac.c
29675 +++ b/drivers/edac/i5400_edac.c
29676 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29677 *
29678 * The "E500P" device is the first device supported.
29679 */
29680 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29681 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29682 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29683 {0,} /* 0 terminated list. */
29684 };
29685 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29686 index 6104dba..e7ea8e1 100644
29687 --- a/drivers/edac/i7300_edac.c
29688 +++ b/drivers/edac/i7300_edac.c
29689 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29690 *
29691 * Has only 8086:360c PCI ID
29692 */
29693 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29694 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29695 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29696 {0,} /* 0 terminated list. */
29697 };
29698 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29699 index 8568d9b..42b2fa8 100644
29700 --- a/drivers/edac/i7core_edac.c
29701 +++ b/drivers/edac/i7core_edac.c
29702 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29703 /*
29704 * pci_device_id table for which devices we are looking for
29705 */
29706 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29707 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29708 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29709 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29710 {0,} /* 0 terminated list. */
29711 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29712 index 4329d39..f3022ef 100644
29713 --- a/drivers/edac/i82443bxgx_edac.c
29714 +++ b/drivers/edac/i82443bxgx_edac.c
29715 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29716
29717 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29718
29719 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29720 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29721 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29722 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29723 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29724 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29725 index 931a057..fd28340 100644
29726 --- a/drivers/edac/i82860_edac.c
29727 +++ b/drivers/edac/i82860_edac.c
29728 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29729 edac_mc_free(mci);
29730 }
29731
29732 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29733 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29734 {
29735 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29736 I82860},
29737 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29738 index 33864c6..01edc61 100644
29739 --- a/drivers/edac/i82875p_edac.c
29740 +++ b/drivers/edac/i82875p_edac.c
29741 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29742 edac_mc_free(mci);
29743 }
29744
29745 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29746 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29747 {
29748 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29749 I82875P},
29750 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29751 index 4184e01..dcb2cd3 100644
29752 --- a/drivers/edac/i82975x_edac.c
29753 +++ b/drivers/edac/i82975x_edac.c
29754 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29755 edac_mc_free(mci);
29756 }
29757
29758 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29759 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29760 {
29761 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29762 I82975X
29763 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29764 index 0106747..0b40417 100644
29765 --- a/drivers/edac/mce_amd.h
29766 +++ b/drivers/edac/mce_amd.h
29767 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29768 bool (*dc_mce)(u16, u8);
29769 bool (*ic_mce)(u16, u8);
29770 bool (*nb_mce)(u16, u8);
29771 -};
29772 +} __no_const;
29773
29774 void amd_report_gart_errors(bool);
29775 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29776 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29777 index e294e1b..a41b05b 100644
29778 --- a/drivers/edac/r82600_edac.c
29779 +++ b/drivers/edac/r82600_edac.c
29780 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29781 edac_mc_free(mci);
29782 }
29783
29784 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29785 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29786 {
29787 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29788 },
29789 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29790 index 1dc118d..8c68af9 100644
29791 --- a/drivers/edac/sb_edac.c
29792 +++ b/drivers/edac/sb_edac.c
29793 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29794 /*
29795 * pci_device_id table for which devices we are looking for
29796 */
29797 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29798 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29799 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29800 {0,} /* 0 terminated list. */
29801 };
29802 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29803 index b6f47de..c5acf3a 100644
29804 --- a/drivers/edac/x38_edac.c
29805 +++ b/drivers/edac/x38_edac.c
29806 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29807 edac_mc_free(mci);
29808 }
29809
29810 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29811 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29812 {
29813 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29814 X38},
29815 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29816 index 85661b0..c784559a 100644
29817 --- a/drivers/firewire/core-card.c
29818 +++ b/drivers/firewire/core-card.c
29819 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29820
29821 void fw_core_remove_card(struct fw_card *card)
29822 {
29823 - struct fw_card_driver dummy_driver = dummy_driver_template;
29824 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29825
29826 card->driver->update_phy_reg(card, 4,
29827 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29828 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29829 index 4799393..37bd3ab 100644
29830 --- a/drivers/firewire/core-cdev.c
29831 +++ b/drivers/firewire/core-cdev.c
29832 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29833 int ret;
29834
29835 if ((request->channels == 0 && request->bandwidth == 0) ||
29836 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29837 - request->bandwidth < 0)
29838 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29839 return -EINVAL;
29840
29841 r = kmalloc(sizeof(*r), GFP_KERNEL);
29842 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29843 index 855ab3f..11f4bbd 100644
29844 --- a/drivers/firewire/core-transaction.c
29845 +++ b/drivers/firewire/core-transaction.c
29846 @@ -37,6 +37,7 @@
29847 #include <linux/timer.h>
29848 #include <linux/types.h>
29849 #include <linux/workqueue.h>
29850 +#include <linux/sched.h>
29851
29852 #include <asm/byteorder.h>
29853
29854 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29855 index b45be57..5fad18b 100644
29856 --- a/drivers/firewire/core.h
29857 +++ b/drivers/firewire/core.h
29858 @@ -101,6 +101,7 @@ struct fw_card_driver {
29859
29860 int (*stop_iso)(struct fw_iso_context *ctx);
29861 };
29862 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29863
29864 void fw_card_initialize(struct fw_card *card,
29865 const struct fw_card_driver *driver, struct device *device);
29866 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29867 index 153980b..4b4d046 100644
29868 --- a/drivers/firmware/dmi_scan.c
29869 +++ b/drivers/firmware/dmi_scan.c
29870 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29871 }
29872 }
29873 else {
29874 - /*
29875 - * no iounmap() for that ioremap(); it would be a no-op, but
29876 - * it's so early in setup that sucker gets confused into doing
29877 - * what it shouldn't if we actually call it.
29878 - */
29879 p = dmi_ioremap(0xF0000, 0x10000);
29880 if (p == NULL)
29881 goto error;
29882 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29883 if (buf == NULL)
29884 return -1;
29885
29886 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29887 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29888
29889 iounmap(buf);
29890 return 0;
29891 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29892 index 82d5c20..44a7177 100644
29893 --- a/drivers/gpio/gpio-vr41xx.c
29894 +++ b/drivers/gpio/gpio-vr41xx.c
29895 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29896 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29897 maskl, pendl, maskh, pendh);
29898
29899 - atomic_inc(&irq_err_count);
29900 + atomic_inc_unchecked(&irq_err_count);
29901
29902 return -EINVAL;
29903 }
29904 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29905 index 84a4a80..ce0306e 100644
29906 --- a/drivers/gpu/drm/drm_crtc_helper.c
29907 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29908 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29909 struct drm_crtc *tmp;
29910 int crtc_mask = 1;
29911
29912 - WARN(!crtc, "checking null crtc?\n");
29913 + BUG_ON(!crtc);
29914
29915 dev = crtc->dev;
29916
29917 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29918 index ebf7d3f..d64c436 100644
29919 --- a/drivers/gpu/drm/drm_drv.c
29920 +++ b/drivers/gpu/drm/drm_drv.c
29921 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29922 /**
29923 * Copy and IOCTL return string to user space
29924 */
29925 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29926 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29927 {
29928 int len;
29929
29930 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29931
29932 dev = file_priv->minor->dev;
29933 atomic_inc(&dev->ioctl_count);
29934 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29935 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29936 ++file_priv->ioctl_count;
29937
29938 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29939 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29940 index 6263b01..7987f55 100644
29941 --- a/drivers/gpu/drm/drm_fops.c
29942 +++ b/drivers/gpu/drm/drm_fops.c
29943 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29944 }
29945
29946 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29947 - atomic_set(&dev->counts[i], 0);
29948 + atomic_set_unchecked(&dev->counts[i], 0);
29949
29950 dev->sigdata.lock = NULL;
29951
29952 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29953
29954 retcode = drm_open_helper(inode, filp, dev);
29955 if (!retcode) {
29956 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29957 - if (!dev->open_count++)
29958 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29959 + if (local_inc_return(&dev->open_count) == 1)
29960 retcode = drm_setup(dev);
29961 }
29962 if (!retcode) {
29963 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29964
29965 mutex_lock(&drm_global_mutex);
29966
29967 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29968 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
29969
29970 if (dev->driver->preclose)
29971 dev->driver->preclose(dev, file_priv);
29972 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
29973 * Begin inline drm_release
29974 */
29975
29976 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29977 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
29978 task_pid_nr(current),
29979 (long)old_encode_dev(file_priv->minor->device),
29980 - dev->open_count);
29981 + local_read(&dev->open_count));
29982
29983 /* Release any auth tokens that might point to this file_priv,
29984 (do that under the drm_global_mutex) */
29985 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29986 * End inline drm_release
29987 */
29988
29989 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29990 - if (!--dev->open_count) {
29991 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29992 + if (local_dec_and_test(&dev->open_count)) {
29993 if (atomic_read(&dev->ioctl_count)) {
29994 DRM_ERROR("Device busy: %d\n",
29995 atomic_read(&dev->ioctl_count));
29996 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29997 index c87dc96..326055d 100644
29998 --- a/drivers/gpu/drm/drm_global.c
29999 +++ b/drivers/gpu/drm/drm_global.c
30000 @@ -36,7 +36,7 @@
30001 struct drm_global_item {
30002 struct mutex mutex;
30003 void *object;
30004 - int refcount;
30005 + atomic_t refcount;
30006 };
30007
30008 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30009 @@ -49,7 +49,7 @@ void drm_global_init(void)
30010 struct drm_global_item *item = &glob[i];
30011 mutex_init(&item->mutex);
30012 item->object = NULL;
30013 - item->refcount = 0;
30014 + atomic_set(&item->refcount, 0);
30015 }
30016 }
30017
30018 @@ -59,7 +59,7 @@ void drm_global_release(void)
30019 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30020 struct drm_global_item *item = &glob[i];
30021 BUG_ON(item->object != NULL);
30022 - BUG_ON(item->refcount != 0);
30023 + BUG_ON(atomic_read(&item->refcount) != 0);
30024 }
30025 }
30026
30027 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30028 void *object;
30029
30030 mutex_lock(&item->mutex);
30031 - if (item->refcount == 0) {
30032 + if (atomic_read(&item->refcount) == 0) {
30033 item->object = kzalloc(ref->size, GFP_KERNEL);
30034 if (unlikely(item->object == NULL)) {
30035 ret = -ENOMEM;
30036 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30037 goto out_err;
30038
30039 }
30040 - ++item->refcount;
30041 + atomic_inc(&item->refcount);
30042 ref->object = item->object;
30043 object = item->object;
30044 mutex_unlock(&item->mutex);
30045 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30046 struct drm_global_item *item = &glob[ref->global_type];
30047
30048 mutex_lock(&item->mutex);
30049 - BUG_ON(item->refcount == 0);
30050 + BUG_ON(atomic_read(&item->refcount) == 0);
30051 BUG_ON(ref->object != item->object);
30052 - if (--item->refcount == 0) {
30053 + if (atomic_dec_and_test(&item->refcount)) {
30054 ref->release(ref);
30055 item->object = NULL;
30056 }
30057 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30058 index ab1162d..42587b2 100644
30059 --- a/drivers/gpu/drm/drm_info.c
30060 +++ b/drivers/gpu/drm/drm_info.c
30061 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30062 struct drm_local_map *map;
30063 struct drm_map_list *r_list;
30064
30065 - /* Hardcoded from _DRM_FRAME_BUFFER,
30066 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30067 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30068 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30069 + static const char * const types[] = {
30070 + [_DRM_FRAME_BUFFER] = "FB",
30071 + [_DRM_REGISTERS] = "REG",
30072 + [_DRM_SHM] = "SHM",
30073 + [_DRM_AGP] = "AGP",
30074 + [_DRM_SCATTER_GATHER] = "SG",
30075 + [_DRM_CONSISTENT] = "PCI",
30076 + [_DRM_GEM] = "GEM" };
30077 const char *type;
30078 int i;
30079
30080 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30081 map = r_list->map;
30082 if (!map)
30083 continue;
30084 - if (map->type < 0 || map->type > 5)
30085 + if (map->type >= ARRAY_SIZE(types))
30086 type = "??";
30087 else
30088 type = types[map->type];
30089 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30090 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30091 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30092 vma->vm_flags & VM_IO ? 'i' : '-',
30093 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30094 + 0);
30095 +#else
30096 vma->vm_pgoff);
30097 +#endif
30098
30099 #if defined(__i386__)
30100 pgprot = pgprot_val(vma->vm_page_prot);
30101 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30102 index 637fcc3..e890b33 100644
30103 --- a/drivers/gpu/drm/drm_ioc32.c
30104 +++ b/drivers/gpu/drm/drm_ioc32.c
30105 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30106 request = compat_alloc_user_space(nbytes);
30107 if (!access_ok(VERIFY_WRITE, request, nbytes))
30108 return -EFAULT;
30109 - list = (struct drm_buf_desc *) (request + 1);
30110 + list = (struct drm_buf_desc __user *) (request + 1);
30111
30112 if (__put_user(count, &request->count)
30113 || __put_user(list, &request->list))
30114 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30115 request = compat_alloc_user_space(nbytes);
30116 if (!access_ok(VERIFY_WRITE, request, nbytes))
30117 return -EFAULT;
30118 - list = (struct drm_buf_pub *) (request + 1);
30119 + list = (struct drm_buf_pub __user *) (request + 1);
30120
30121 if (__put_user(count, &request->count)
30122 || __put_user(list, &request->list))
30123 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30124 index 956fd38..e52167a 100644
30125 --- a/drivers/gpu/drm/drm_ioctl.c
30126 +++ b/drivers/gpu/drm/drm_ioctl.c
30127 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30128 stats->data[i].value =
30129 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30130 else
30131 - stats->data[i].value = atomic_read(&dev->counts[i]);
30132 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30133 stats->data[i].type = dev->types[i];
30134 }
30135
30136 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30137 index c79c713..2048588 100644
30138 --- a/drivers/gpu/drm/drm_lock.c
30139 +++ b/drivers/gpu/drm/drm_lock.c
30140 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30141 if (drm_lock_take(&master->lock, lock->context)) {
30142 master->lock.file_priv = file_priv;
30143 master->lock.lock_time = jiffies;
30144 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30145 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30146 break; /* Got lock */
30147 }
30148
30149 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30150 return -EINVAL;
30151 }
30152
30153 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30154 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30155
30156 if (drm_lock_free(&master->lock, lock->context)) {
30157 /* FIXME: Should really bail out here. */
30158 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30159 index 7f4b4e1..bf4def2 100644
30160 --- a/drivers/gpu/drm/i810/i810_dma.c
30161 +++ b/drivers/gpu/drm/i810/i810_dma.c
30162 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30163 dma->buflist[vertex->idx],
30164 vertex->discard, vertex->used);
30165
30166 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30167 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30168 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30169 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30170 sarea_priv->last_enqueue = dev_priv->counter - 1;
30171 sarea_priv->last_dispatch = (int)hw_status[5];
30172
30173 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30174 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30175 mc->last_render);
30176
30177 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30178 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30179 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30180 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30181 sarea_priv->last_enqueue = dev_priv->counter - 1;
30182 sarea_priv->last_dispatch = (int)hw_status[5];
30183
30184 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30185 index c9339f4..f5e1b9d 100644
30186 --- a/drivers/gpu/drm/i810/i810_drv.h
30187 +++ b/drivers/gpu/drm/i810/i810_drv.h
30188 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30189 int page_flipping;
30190
30191 wait_queue_head_t irq_queue;
30192 - atomic_t irq_received;
30193 - atomic_t irq_emitted;
30194 + atomic_unchecked_t irq_received;
30195 + atomic_unchecked_t irq_emitted;
30196
30197 int front_offset;
30198 } drm_i810_private_t;
30199 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30200 index deaa657..e0fd296 100644
30201 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30202 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30203 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30204 I915_READ(GTIMR));
30205 }
30206 seq_printf(m, "Interrupts received: %d\n",
30207 - atomic_read(&dev_priv->irq_received));
30208 + atomic_read_unchecked(&dev_priv->irq_received));
30209 for (i = 0; i < I915_NUM_RINGS; i++) {
30210 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30211 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30212 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30213 return ret;
30214
30215 if (opregion->header)
30216 - seq_write(m, opregion->header, OPREGION_SIZE);
30217 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30218
30219 mutex_unlock(&dev->struct_mutex);
30220
30221 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30222 index ddfe3d9..f6e6b21 100644
30223 --- a/drivers/gpu/drm/i915/i915_dma.c
30224 +++ b/drivers/gpu/drm/i915/i915_dma.c
30225 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30226 bool can_switch;
30227
30228 spin_lock(&dev->count_lock);
30229 - can_switch = (dev->open_count == 0);
30230 + can_switch = (local_read(&dev->open_count) == 0);
30231 spin_unlock(&dev->count_lock);
30232 return can_switch;
30233 }
30234 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30235 index 9689ca3..294f9c1 100644
30236 --- a/drivers/gpu/drm/i915/i915_drv.h
30237 +++ b/drivers/gpu/drm/i915/i915_drv.h
30238 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30239 /* render clock increase/decrease */
30240 /* display clock increase/decrease */
30241 /* pll clock increase/decrease */
30242 -};
30243 +} __no_const;
30244
30245 struct intel_device_info {
30246 u8 gen;
30247 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30248 int current_page;
30249 int page_flipping;
30250
30251 - atomic_t irq_received;
30252 + atomic_unchecked_t irq_received;
30253
30254 /* protects the irq masks */
30255 spinlock_t irq_lock;
30256 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30257 * will be page flipped away on the next vblank. When it
30258 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30259 */
30260 - atomic_t pending_flip;
30261 + atomic_unchecked_t pending_flip;
30262 };
30263
30264 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30265 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30266 extern void intel_teardown_gmbus(struct drm_device *dev);
30267 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30268 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30269 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30270 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30271 {
30272 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30273 }
30274 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30275 index 65e1f00..a30ef00 100644
30276 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30277 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30278 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30279 i915_gem_clflush_object(obj);
30280
30281 if (obj->base.pending_write_domain)
30282 - cd->flips |= atomic_read(&obj->pending_flip);
30283 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30284
30285 /* The actual obj->write_domain will be updated with
30286 * pending_write_domain after we emit the accumulated flush for all
30287 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30288
30289 static int
30290 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30291 - int count)
30292 + unsigned int count)
30293 {
30294 - int i;
30295 + unsigned int i;
30296
30297 for (i = 0; i < count; i++) {
30298 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30299 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30300 index 5bd4361..0241a42 100644
30301 --- a/drivers/gpu/drm/i915/i915_irq.c
30302 +++ b/drivers/gpu/drm/i915/i915_irq.c
30303 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30304 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30305 struct drm_i915_master_private *master_priv;
30306
30307 - atomic_inc(&dev_priv->irq_received);
30308 + atomic_inc_unchecked(&dev_priv->irq_received);
30309
30310 /* disable master interrupt before clearing iir */
30311 de_ier = I915_READ(DEIER);
30312 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30313 struct drm_i915_master_private *master_priv;
30314 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30315
30316 - atomic_inc(&dev_priv->irq_received);
30317 + atomic_inc_unchecked(&dev_priv->irq_received);
30318
30319 if (IS_GEN6(dev))
30320 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30321 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30322 int ret = IRQ_NONE, pipe;
30323 bool blc_event = false;
30324
30325 - atomic_inc(&dev_priv->irq_received);
30326 + atomic_inc_unchecked(&dev_priv->irq_received);
30327
30328 iir = I915_READ(IIR);
30329
30330 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30331 {
30332 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30333
30334 - atomic_set(&dev_priv->irq_received, 0);
30335 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30336
30337 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30338 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30339 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30340 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30341 int pipe;
30342
30343 - atomic_set(&dev_priv->irq_received, 0);
30344 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30345
30346 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30347 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30348 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30349 index 397087c..9178d0d 100644
30350 --- a/drivers/gpu/drm/i915/intel_display.c
30351 +++ b/drivers/gpu/drm/i915/intel_display.c
30352 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30353
30354 wait_event(dev_priv->pending_flip_queue,
30355 atomic_read(&dev_priv->mm.wedged) ||
30356 - atomic_read(&obj->pending_flip) == 0);
30357 + atomic_read_unchecked(&obj->pending_flip) == 0);
30358
30359 /* Big Hammer, we also need to ensure that any pending
30360 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30361 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30362 obj = to_intel_framebuffer(crtc->fb)->obj;
30363 dev_priv = crtc->dev->dev_private;
30364 wait_event(dev_priv->pending_flip_queue,
30365 - atomic_read(&obj->pending_flip) == 0);
30366 + atomic_read_unchecked(&obj->pending_flip) == 0);
30367 }
30368
30369 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30370 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30371
30372 atomic_clear_mask(1 << intel_crtc->plane,
30373 &obj->pending_flip.counter);
30374 - if (atomic_read(&obj->pending_flip) == 0)
30375 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30376 wake_up(&dev_priv->pending_flip_queue);
30377
30378 schedule_work(&work->work);
30379 @@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30380 /* Block clients from rendering to the new back buffer until
30381 * the flip occurs and the object is no longer visible.
30382 */
30383 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30384 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30385
30386 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30387 if (ret)
30388 @@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30389 return 0;
30390
30391 cleanup_pending:
30392 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30393 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30394 drm_gem_object_unreference(&work->old_fb_obj->base);
30395 drm_gem_object_unreference(&obj->base);
30396 mutex_unlock(&dev->struct_mutex);
30397 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30398 index 54558a0..2d97005 100644
30399 --- a/drivers/gpu/drm/mga/mga_drv.h
30400 +++ b/drivers/gpu/drm/mga/mga_drv.h
30401 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30402 u32 clear_cmd;
30403 u32 maccess;
30404
30405 - atomic_t vbl_received; /**< Number of vblanks received. */
30406 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30407 wait_queue_head_t fence_queue;
30408 - atomic_t last_fence_retired;
30409 + atomic_unchecked_t last_fence_retired;
30410 u32 next_fence_to_post;
30411
30412 unsigned int fb_cpp;
30413 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30414 index 2581202..f230a8d9 100644
30415 --- a/drivers/gpu/drm/mga/mga_irq.c
30416 +++ b/drivers/gpu/drm/mga/mga_irq.c
30417 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30418 if (crtc != 0)
30419 return 0;
30420
30421 - return atomic_read(&dev_priv->vbl_received);
30422 + return atomic_read_unchecked(&dev_priv->vbl_received);
30423 }
30424
30425
30426 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30427 /* VBLANK interrupt */
30428 if (status & MGA_VLINEPEN) {
30429 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30430 - atomic_inc(&dev_priv->vbl_received);
30431 + atomic_inc_unchecked(&dev_priv->vbl_received);
30432 drm_handle_vblank(dev, 0);
30433 handled = 1;
30434 }
30435 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30436 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30437 MGA_WRITE(MGA_PRIMEND, prim_end);
30438
30439 - atomic_inc(&dev_priv->last_fence_retired);
30440 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30441 DRM_WAKEUP(&dev_priv->fence_queue);
30442 handled = 1;
30443 }
30444 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30445 * using fences.
30446 */
30447 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30448 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30449 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30450 - *sequence) <= (1 << 23)));
30451
30452 *sequence = cur_fence;
30453 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30454 index e5cbead..6c354a3 100644
30455 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30456 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30457 @@ -199,7 +199,7 @@ struct methods {
30458 const char desc[8];
30459 void (*loadbios)(struct drm_device *, uint8_t *);
30460 const bool rw;
30461 -};
30462 +} __do_const;
30463
30464 static struct methods shadow_methods[] = {
30465 { "PRAMIN", load_vbios_pramin, true },
30466 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30467 struct bit_table {
30468 const char id;
30469 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30470 -};
30471 +} __no_const;
30472
30473 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30474
30475 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30476 index b827098..c31a797 100644
30477 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30478 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30479 @@ -242,7 +242,7 @@ struct nouveau_channel {
30480 struct list_head pending;
30481 uint32_t sequence;
30482 uint32_t sequence_ack;
30483 - atomic_t last_sequence_irq;
30484 + atomic_unchecked_t last_sequence_irq;
30485 struct nouveau_vma vma;
30486 } fence;
30487
30488 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30489 u32 handle, u16 class);
30490 void (*set_tile_region)(struct drm_device *dev, int i);
30491 void (*tlb_flush)(struct drm_device *, int engine);
30492 -};
30493 +} __no_const;
30494
30495 struct nouveau_instmem_engine {
30496 void *priv;
30497 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30498 struct nouveau_mc_engine {
30499 int (*init)(struct drm_device *dev);
30500 void (*takedown)(struct drm_device *dev);
30501 -};
30502 +} __no_const;
30503
30504 struct nouveau_timer_engine {
30505 int (*init)(struct drm_device *dev);
30506 void (*takedown)(struct drm_device *dev);
30507 uint64_t (*read)(struct drm_device *dev);
30508 -};
30509 +} __no_const;
30510
30511 struct nouveau_fb_engine {
30512 int num_tiles;
30513 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30514 void (*put)(struct drm_device *, struct nouveau_mem **);
30515
30516 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30517 -};
30518 +} __no_const;
30519
30520 struct nouveau_engine {
30521 struct nouveau_instmem_engine instmem;
30522 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30523 struct drm_global_reference mem_global_ref;
30524 struct ttm_bo_global_ref bo_global_ref;
30525 struct ttm_bo_device bdev;
30526 - atomic_t validate_sequence;
30527 + atomic_unchecked_t validate_sequence;
30528 } ttm;
30529
30530 struct {
30531 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30532 index 2f6daae..c9d7b9e 100644
30533 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30534 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30535 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30536 if (USE_REFCNT(dev))
30537 sequence = nvchan_rd32(chan, 0x48);
30538 else
30539 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30540 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30541
30542 if (chan->fence.sequence_ack == sequence)
30543 goto out;
30544 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30545 return ret;
30546 }
30547
30548 - atomic_set(&chan->fence.last_sequence_irq, 0);
30549 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30550 return 0;
30551 }
30552
30553 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30554 index 7ce3fde..cb3ea04 100644
30555 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30556 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30557 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30558 int trycnt = 0;
30559 int ret, i;
30560
30561 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30562 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30563 retry:
30564 if (++trycnt > 100000) {
30565 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30566 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30567 index f80c5e0..936baa7 100644
30568 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30569 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30570 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30571 bool can_switch;
30572
30573 spin_lock(&dev->count_lock);
30574 - can_switch = (dev->open_count == 0);
30575 + can_switch = (local_read(&dev->open_count) == 0);
30576 spin_unlock(&dev->count_lock);
30577 return can_switch;
30578 }
30579 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30580 index dbdea8e..cd6eeeb 100644
30581 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30582 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30583 @@ -554,7 +554,7 @@ static int
30584 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30585 u32 class, u32 mthd, u32 data)
30586 {
30587 - atomic_set(&chan->fence.last_sequence_irq, data);
30588 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30589 return 0;
30590 }
30591
30592 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30593 index bcac90b..53bfc76 100644
30594 --- a/drivers/gpu/drm/r128/r128_cce.c
30595 +++ b/drivers/gpu/drm/r128/r128_cce.c
30596 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30597
30598 /* GH: Simple idle check.
30599 */
30600 - atomic_set(&dev_priv->idle_count, 0);
30601 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30602
30603 /* We don't support anything other than bus-mastering ring mode,
30604 * but the ring can be in either AGP or PCI space for the ring
30605 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30606 index 930c71b..499aded 100644
30607 --- a/drivers/gpu/drm/r128/r128_drv.h
30608 +++ b/drivers/gpu/drm/r128/r128_drv.h
30609 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30610 int is_pci;
30611 unsigned long cce_buffers_offset;
30612
30613 - atomic_t idle_count;
30614 + atomic_unchecked_t idle_count;
30615
30616 int page_flipping;
30617 int current_page;
30618 u32 crtc_offset;
30619 u32 crtc_offset_cntl;
30620
30621 - atomic_t vbl_received;
30622 + atomic_unchecked_t vbl_received;
30623
30624 u32 color_fmt;
30625 unsigned int front_offset;
30626 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30627 index 429d5a0..7e899ed 100644
30628 --- a/drivers/gpu/drm/r128/r128_irq.c
30629 +++ b/drivers/gpu/drm/r128/r128_irq.c
30630 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30631 if (crtc != 0)
30632 return 0;
30633
30634 - return atomic_read(&dev_priv->vbl_received);
30635 + return atomic_read_unchecked(&dev_priv->vbl_received);
30636 }
30637
30638 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30639 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30640 /* VBLANK interrupt */
30641 if (status & R128_CRTC_VBLANK_INT) {
30642 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30643 - atomic_inc(&dev_priv->vbl_received);
30644 + atomic_inc_unchecked(&dev_priv->vbl_received);
30645 drm_handle_vblank(dev, 0);
30646 return IRQ_HANDLED;
30647 }
30648 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30649 index a9e33ce..09edd4b 100644
30650 --- a/drivers/gpu/drm/r128/r128_state.c
30651 +++ b/drivers/gpu/drm/r128/r128_state.c
30652 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30653
30654 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30655 {
30656 - if (atomic_read(&dev_priv->idle_count) == 0)
30657 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30658 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30659 else
30660 - atomic_set(&dev_priv->idle_count, 0);
30661 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30662 }
30663
30664 #endif
30665 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30666 index 5a82b6b..9e69c73 100644
30667 --- a/drivers/gpu/drm/radeon/mkregtable.c
30668 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30669 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30670 regex_t mask_rex;
30671 regmatch_t match[4];
30672 char buf[1024];
30673 - size_t end;
30674 + long end;
30675 int len;
30676 int done = 0;
30677 int r;
30678 unsigned o;
30679 struct offset *offset;
30680 char last_reg_s[10];
30681 - int last_reg;
30682 + unsigned long last_reg;
30683
30684 if (regcomp
30685 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30686 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30687 index 1668ec1..30ebdab 100644
30688 --- a/drivers/gpu/drm/radeon/radeon.h
30689 +++ b/drivers/gpu/drm/radeon/radeon.h
30690 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30691 uint32_t scratch_reg;
30692 uint64_t gpu_addr;
30693 volatile uint32_t *cpu_addr;
30694 - atomic_t seq;
30695 + atomic_unchecked_t seq;
30696 uint32_t last_seq;
30697 unsigned long last_jiffies;
30698 unsigned long last_timeout;
30699 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30700 int x2, int y2);
30701 void (*draw_auto)(struct radeon_device *rdev);
30702 void (*set_default_state)(struct radeon_device *rdev);
30703 -};
30704 +} __no_const;
30705
30706 struct r600_blit {
30707 struct mutex mutex;
30708 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30709 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30710 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30711 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30712 -};
30713 +} __no_const;
30714
30715 /*
30716 * Asic structures
30717 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30718 index 49f7cb7..2fcb48f 100644
30719 --- a/drivers/gpu/drm/radeon/radeon_device.c
30720 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30721 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30722 bool can_switch;
30723
30724 spin_lock(&dev->count_lock);
30725 - can_switch = (dev->open_count == 0);
30726 + can_switch = (local_read(&dev->open_count) == 0);
30727 spin_unlock(&dev->count_lock);
30728 return can_switch;
30729 }
30730 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30731 index a1b59ca..86f2d44 100644
30732 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30733 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30734 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30735
30736 /* SW interrupt */
30737 wait_queue_head_t swi_queue;
30738 - atomic_t swi_emitted;
30739 + atomic_unchecked_t swi_emitted;
30740 int vblank_crtc;
30741 uint32_t irq_enable_reg;
30742 uint32_t r500_disp_irq_reg;
30743 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30744 index 4bd36a3..e66fe9c 100644
30745 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30746 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30747 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30748 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30749 return 0;
30750 }
30751 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30752 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30753 if (!rdev->ring[fence->ring].ready)
30754 /* FIXME: cp is not running assume everythings is done right
30755 * away
30756 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30757 }
30758 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30759 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30760 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30761 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30762 rdev->fence_drv[ring].initialized = true;
30763 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30764 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30765 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30766 rdev->fence_drv[ring].scratch_reg = -1;
30767 rdev->fence_drv[ring].cpu_addr = NULL;
30768 rdev->fence_drv[ring].gpu_addr = 0;
30769 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30770 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30771 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30772 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30773 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30774 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30775 index 48b7cea..342236f 100644
30776 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30777 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30778 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30779 request = compat_alloc_user_space(sizeof(*request));
30780 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30781 || __put_user(req32.param, &request->param)
30782 - || __put_user((void __user *)(unsigned long)req32.value,
30783 + || __put_user((unsigned long)req32.value,
30784 &request->value))
30785 return -EFAULT;
30786
30787 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30788 index 00da384..32f972d 100644
30789 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30790 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30791 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30792 unsigned int ret;
30793 RING_LOCALS;
30794
30795 - atomic_inc(&dev_priv->swi_emitted);
30796 - ret = atomic_read(&dev_priv->swi_emitted);
30797 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30798 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30799
30800 BEGIN_RING(4);
30801 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30802 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30803 drm_radeon_private_t *dev_priv =
30804 (drm_radeon_private_t *) dev->dev_private;
30805
30806 - atomic_set(&dev_priv->swi_emitted, 0);
30807 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30808 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30809
30810 dev->max_vblank_count = 0x001fffff;
30811 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30812 index e8422ae..d22d4a8 100644
30813 --- a/drivers/gpu/drm/radeon/radeon_state.c
30814 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30815 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30816 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30817 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30818
30819 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30820 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30821 sarea_priv->nbox * sizeof(depth_boxes[0])))
30822 return -EFAULT;
30823
30824 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30825 {
30826 drm_radeon_private_t *dev_priv = dev->dev_private;
30827 drm_radeon_getparam_t *param = data;
30828 - int value;
30829 + int value = 0;
30830
30831 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30832
30833 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30834 index c421e77..e6bf2e8 100644
30835 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30836 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30837 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30838 }
30839 if (unlikely(ttm_vm_ops == NULL)) {
30840 ttm_vm_ops = vma->vm_ops;
30841 - radeon_ttm_vm_ops = *ttm_vm_ops;
30842 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30843 + pax_open_kernel();
30844 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30845 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30846 + pax_close_kernel();
30847 }
30848 vma->vm_ops = &radeon_ttm_vm_ops;
30849 return 0;
30850 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30851 index f68dff2..8df955c 100644
30852 --- a/drivers/gpu/drm/radeon/rs690.c
30853 +++ b/drivers/gpu/drm/radeon/rs690.c
30854 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30855 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30856 rdev->pm.sideport_bandwidth.full)
30857 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30858 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30859 + read_delay_latency.full = dfixed_const(800 * 1000);
30860 read_delay_latency.full = dfixed_div(read_delay_latency,
30861 rdev->pm.igp_sideport_mclk);
30862 + a.full = dfixed_const(370);
30863 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30864 } else {
30865 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30866 rdev->pm.k8_bandwidth.full)
30867 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30868 index 499debd..66fce72 100644
30869 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30870 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30871 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30872 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30873 struct shrink_control *sc)
30874 {
30875 - static atomic_t start_pool = ATOMIC_INIT(0);
30876 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30877 unsigned i;
30878 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30879 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30880 struct ttm_page_pool *pool;
30881 int shrink_pages = sc->nr_to_scan;
30882
30883 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30884 index 88edacc..1e5412b 100644
30885 --- a/drivers/gpu/drm/via/via_drv.h
30886 +++ b/drivers/gpu/drm/via/via_drv.h
30887 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30888 typedef uint32_t maskarray_t[5];
30889
30890 typedef struct drm_via_irq {
30891 - atomic_t irq_received;
30892 + atomic_unchecked_t irq_received;
30893 uint32_t pending_mask;
30894 uint32_t enable_mask;
30895 wait_queue_head_t irq_queue;
30896 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30897 struct timeval last_vblank;
30898 int last_vblank_valid;
30899 unsigned usec_per_vblank;
30900 - atomic_t vbl_received;
30901 + atomic_unchecked_t vbl_received;
30902 drm_via_state_t hc_state;
30903 char pci_buf[VIA_PCI_BUF_SIZE];
30904 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30905 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30906 index d391f48..10c8ca3 100644
30907 --- a/drivers/gpu/drm/via/via_irq.c
30908 +++ b/drivers/gpu/drm/via/via_irq.c
30909 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30910 if (crtc != 0)
30911 return 0;
30912
30913 - return atomic_read(&dev_priv->vbl_received);
30914 + return atomic_read_unchecked(&dev_priv->vbl_received);
30915 }
30916
30917 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30918 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30919
30920 status = VIA_READ(VIA_REG_INTERRUPT);
30921 if (status & VIA_IRQ_VBLANK_PENDING) {
30922 - atomic_inc(&dev_priv->vbl_received);
30923 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30924 + atomic_inc_unchecked(&dev_priv->vbl_received);
30925 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30926 do_gettimeofday(&cur_vblank);
30927 if (dev_priv->last_vblank_valid) {
30928 dev_priv->usec_per_vblank =
30929 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30930 dev_priv->last_vblank = cur_vblank;
30931 dev_priv->last_vblank_valid = 1;
30932 }
30933 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30934 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30935 DRM_DEBUG("US per vblank is: %u\n",
30936 dev_priv->usec_per_vblank);
30937 }
30938 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30939
30940 for (i = 0; i < dev_priv->num_irqs; ++i) {
30941 if (status & cur_irq->pending_mask) {
30942 - atomic_inc(&cur_irq->irq_received);
30943 + atomic_inc_unchecked(&cur_irq->irq_received);
30944 DRM_WAKEUP(&cur_irq->irq_queue);
30945 handled = 1;
30946 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30947 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30948 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30949 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30950 masks[irq][4]));
30951 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30952 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30953 } else {
30954 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30955 (((cur_irq_sequence =
30956 - atomic_read(&cur_irq->irq_received)) -
30957 + atomic_read_unchecked(&cur_irq->irq_received)) -
30958 *sequence) <= (1 << 23)));
30959 }
30960 *sequence = cur_irq_sequence;
30961 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30962 }
30963
30964 for (i = 0; i < dev_priv->num_irqs; ++i) {
30965 - atomic_set(&cur_irq->irq_received, 0);
30966 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30967 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30968 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30969 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30970 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30971 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30972 case VIA_IRQ_RELATIVE:
30973 irqwait->request.sequence +=
30974 - atomic_read(&cur_irq->irq_received);
30975 + atomic_read_unchecked(&cur_irq->irq_received);
30976 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30977 case VIA_IRQ_ABSOLUTE:
30978 break;
30979 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30980 index dc27970..f18b008 100644
30981 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30982 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30983 @@ -260,7 +260,7 @@ struct vmw_private {
30984 * Fencing and IRQs.
30985 */
30986
30987 - atomic_t marker_seq;
30988 + atomic_unchecked_t marker_seq;
30989 wait_queue_head_t fence_queue;
30990 wait_queue_head_t fifo_queue;
30991 int fence_queue_waiters; /* Protected by hw_mutex */
30992 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30993 index a0c2f12..68ae6cb 100644
30994 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30995 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30996 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30997 (unsigned int) min,
30998 (unsigned int) fifo->capabilities);
30999
31000 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31001 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31002 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31003 vmw_marker_queue_init(&fifo->marker_queue);
31004 return vmw_fifo_send_fence(dev_priv, &dummy);
31005 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31006 if (reserveable)
31007 iowrite32(bytes, fifo_mem +
31008 SVGA_FIFO_RESERVED);
31009 - return fifo_mem + (next_cmd >> 2);
31010 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31011 } else {
31012 need_bounce = true;
31013 }
31014 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31015
31016 fm = vmw_fifo_reserve(dev_priv, bytes);
31017 if (unlikely(fm == NULL)) {
31018 - *seqno = atomic_read(&dev_priv->marker_seq);
31019 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31020 ret = -ENOMEM;
31021 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31022 false, 3*HZ);
31023 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31024 }
31025
31026 do {
31027 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31028 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31029 } while (*seqno == 0);
31030
31031 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31032 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31033 index cabc95f..14b3d77 100644
31034 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31035 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31036 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31037 * emitted. Then the fence is stale and signaled.
31038 */
31039
31040 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31041 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31042 > VMW_FENCE_WRAP);
31043
31044 return ret;
31045 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31046
31047 if (fifo_idle)
31048 down_read(&fifo_state->rwsem);
31049 - signal_seq = atomic_read(&dev_priv->marker_seq);
31050 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31051 ret = 0;
31052
31053 for (;;) {
31054 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31055 index 8a8725c..afed796 100644
31056 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31057 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31058 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31059 while (!vmw_lag_lt(queue, us)) {
31060 spin_lock(&queue->lock);
31061 if (list_empty(&queue->head))
31062 - seqno = atomic_read(&dev_priv->marker_seq);
31063 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31064 else {
31065 marker = list_first_entry(&queue->head,
31066 struct vmw_marker, head);
31067 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31068 index 75dbe34..f9204a8 100644
31069 --- a/drivers/hid/hid-core.c
31070 +++ b/drivers/hid/hid-core.c
31071 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31072
31073 int hid_add_device(struct hid_device *hdev)
31074 {
31075 - static atomic_t id = ATOMIC_INIT(0);
31076 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31077 int ret;
31078
31079 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31080 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31081 /* XXX hack, any other cleaner solution after the driver core
31082 * is converted to allow more than 20 bytes as the device name? */
31083 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31084 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31085 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31086
31087 hid_debug_register(hdev, dev_name(&hdev->dev));
31088 ret = device_add(&hdev->dev);
31089 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31090 index b1ec0e2..c295a61 100644
31091 --- a/drivers/hid/usbhid/hiddev.c
31092 +++ b/drivers/hid/usbhid/hiddev.c
31093 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31094 break;
31095
31096 case HIDIOCAPPLICATION:
31097 - if (arg < 0 || arg >= hid->maxapplication)
31098 + if (arg >= hid->maxapplication)
31099 break;
31100
31101 for (i = 0; i < hid->maxcollection; i++)
31102 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31103 index 4065374..10ed7dc 100644
31104 --- a/drivers/hv/channel.c
31105 +++ b/drivers/hv/channel.c
31106 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31107 int ret = 0;
31108 int t;
31109
31110 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31111 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31112 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31113 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31114
31115 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31116 if (ret)
31117 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31118 index 12aa97f..c0679f7 100644
31119 --- a/drivers/hv/hv.c
31120 +++ b/drivers/hv/hv.c
31121 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31122 u64 output_address = (output) ? virt_to_phys(output) : 0;
31123 u32 output_address_hi = output_address >> 32;
31124 u32 output_address_lo = output_address & 0xFFFFFFFF;
31125 - void *hypercall_page = hv_context.hypercall_page;
31126 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31127
31128 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31129 "=a"(hv_status_lo) : "d" (control_hi),
31130 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31131 index 6d7d286..92b0873 100644
31132 --- a/drivers/hv/hyperv_vmbus.h
31133 +++ b/drivers/hv/hyperv_vmbus.h
31134 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31135 struct vmbus_connection {
31136 enum vmbus_connect_state conn_state;
31137
31138 - atomic_t next_gpadl_handle;
31139 + atomic_unchecked_t next_gpadl_handle;
31140
31141 /*
31142 * Represents channel interrupts. Each bit position represents a
31143 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31144 index a220e57..428f54d 100644
31145 --- a/drivers/hv/vmbus_drv.c
31146 +++ b/drivers/hv/vmbus_drv.c
31147 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31148 {
31149 int ret = 0;
31150
31151 - static atomic_t device_num = ATOMIC_INIT(0);
31152 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31153
31154 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31155 - atomic_inc_return(&device_num));
31156 + atomic_inc_return_unchecked(&device_num));
31157
31158 child_device_obj->device.bus = &hv_bus;
31159 child_device_obj->device.parent = &hv_acpi_dev->dev;
31160 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31161 index 554f046..f8b4729 100644
31162 --- a/drivers/hwmon/acpi_power_meter.c
31163 +++ b/drivers/hwmon/acpi_power_meter.c
31164 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31165 return res;
31166
31167 temp /= 1000;
31168 - if (temp < 0)
31169 - return -EINVAL;
31170
31171 mutex_lock(&resource->lock);
31172 resource->trip[attr->index - 7] = temp;
31173 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31174 index 91fdd1f..b66a686 100644
31175 --- a/drivers/hwmon/sht15.c
31176 +++ b/drivers/hwmon/sht15.c
31177 @@ -166,7 +166,7 @@ struct sht15_data {
31178 int supply_uV;
31179 bool supply_uV_valid;
31180 struct work_struct update_supply_work;
31181 - atomic_t interrupt_handled;
31182 + atomic_unchecked_t interrupt_handled;
31183 };
31184
31185 /**
31186 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31187 return ret;
31188
31189 gpio_direction_input(data->pdata->gpio_data);
31190 - atomic_set(&data->interrupt_handled, 0);
31191 + atomic_set_unchecked(&data->interrupt_handled, 0);
31192
31193 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31194 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31195 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31196 /* Only relevant if the interrupt hasn't occurred. */
31197 - if (!atomic_read(&data->interrupt_handled))
31198 + if (!atomic_read_unchecked(&data->interrupt_handled))
31199 schedule_work(&data->read_work);
31200 }
31201 ret = wait_event_timeout(data->wait_queue,
31202 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31203
31204 /* First disable the interrupt */
31205 disable_irq_nosync(irq);
31206 - atomic_inc(&data->interrupt_handled);
31207 + atomic_inc_unchecked(&data->interrupt_handled);
31208 /* Then schedule a reading work struct */
31209 if (data->state != SHT15_READING_NOTHING)
31210 schedule_work(&data->read_work);
31211 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31212 * If not, then start the interrupt again - care here as could
31213 * have gone low in meantime so verify it hasn't!
31214 */
31215 - atomic_set(&data->interrupt_handled, 0);
31216 + atomic_set_unchecked(&data->interrupt_handled, 0);
31217 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31218 /* If still not occurred or another handler has been scheduled */
31219 if (gpio_get_value(data->pdata->gpio_data)
31220 - || atomic_read(&data->interrupt_handled))
31221 + || atomic_read_unchecked(&data->interrupt_handled))
31222 return;
31223 }
31224
31225 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31226 index 378fcb5..5e91fa8 100644
31227 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31228 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31229 @@ -43,7 +43,7 @@
31230 extern struct i2c_adapter amd756_smbus;
31231
31232 static struct i2c_adapter *s4882_adapter;
31233 -static struct i2c_algorithm *s4882_algo;
31234 +static i2c_algorithm_no_const *s4882_algo;
31235
31236 /* Wrapper access functions for multiplexed SMBus */
31237 static DEFINE_MUTEX(amd756_lock);
31238 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31239 index 29015eb..af2d8e9 100644
31240 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31241 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31242 @@ -41,7 +41,7 @@
31243 extern struct i2c_adapter *nforce2_smbus;
31244
31245 static struct i2c_adapter *s4985_adapter;
31246 -static struct i2c_algorithm *s4985_algo;
31247 +static i2c_algorithm_no_const *s4985_algo;
31248
31249 /* Wrapper access functions for multiplexed SMBus */
31250 static DEFINE_MUTEX(nforce2_lock);
31251 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31252 index d7a4833..7fae376 100644
31253 --- a/drivers/i2c/i2c-mux.c
31254 +++ b/drivers/i2c/i2c-mux.c
31255 @@ -28,7 +28,7 @@
31256 /* multiplexer per channel data */
31257 struct i2c_mux_priv {
31258 struct i2c_adapter adap;
31259 - struct i2c_algorithm algo;
31260 + i2c_algorithm_no_const algo;
31261
31262 struct i2c_adapter *parent;
31263 void *mux_dev; /* the mux chip/device */
31264 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31265 index 57d00ca..0145194 100644
31266 --- a/drivers/ide/aec62xx.c
31267 +++ b/drivers/ide/aec62xx.c
31268 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31269 .cable_detect = atp86x_cable_detect,
31270 };
31271
31272 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31273 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31274 { /* 0: AEC6210 */
31275 .name = DRV_NAME,
31276 .init_chipset = init_chipset_aec62xx,
31277 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31278 index 2c8016a..911a27c 100644
31279 --- a/drivers/ide/alim15x3.c
31280 +++ b/drivers/ide/alim15x3.c
31281 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31282 .dma_sff_read_status = ide_dma_sff_read_status,
31283 };
31284
31285 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31286 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31287 .name = DRV_NAME,
31288 .init_chipset = init_chipset_ali15x3,
31289 .init_hwif = init_hwif_ali15x3,
31290 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31291 index 3747b25..56fc995 100644
31292 --- a/drivers/ide/amd74xx.c
31293 +++ b/drivers/ide/amd74xx.c
31294 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31295 .udma_mask = udma, \
31296 }
31297
31298 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31299 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31300 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31301 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31302 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31303 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31304 index 15f0ead..cb43480 100644
31305 --- a/drivers/ide/atiixp.c
31306 +++ b/drivers/ide/atiixp.c
31307 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31308 .cable_detect = atiixp_cable_detect,
31309 };
31310
31311 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31312 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31313 { /* 0: IXP200/300/400/700 */
31314 .name = DRV_NAME,
31315 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31316 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31317 index 5f80312..d1fc438 100644
31318 --- a/drivers/ide/cmd64x.c
31319 +++ b/drivers/ide/cmd64x.c
31320 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31321 .dma_sff_read_status = ide_dma_sff_read_status,
31322 };
31323
31324 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31325 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31326 { /* 0: CMD643 */
31327 .name = DRV_NAME,
31328 .init_chipset = init_chipset_cmd64x,
31329 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31330 index 2c1e5f7..1444762 100644
31331 --- a/drivers/ide/cs5520.c
31332 +++ b/drivers/ide/cs5520.c
31333 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31334 .set_dma_mode = cs5520_set_dma_mode,
31335 };
31336
31337 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31338 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31339 .name = DRV_NAME,
31340 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31341 .port_ops = &cs5520_port_ops,
31342 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31343 index 4dc4eb9..49b40ad 100644
31344 --- a/drivers/ide/cs5530.c
31345 +++ b/drivers/ide/cs5530.c
31346 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31347 .udma_filter = cs5530_udma_filter,
31348 };
31349
31350 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31351 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31352 .name = DRV_NAME,
31353 .init_chipset = init_chipset_cs5530,
31354 .init_hwif = init_hwif_cs5530,
31355 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31356 index 5059faf..18d4c85 100644
31357 --- a/drivers/ide/cs5535.c
31358 +++ b/drivers/ide/cs5535.c
31359 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31360 .cable_detect = cs5535_cable_detect,
31361 };
31362
31363 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31364 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31365 .name = DRV_NAME,
31366 .port_ops = &cs5535_port_ops,
31367 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31368 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31369 index 847553f..3ffb49d 100644
31370 --- a/drivers/ide/cy82c693.c
31371 +++ b/drivers/ide/cy82c693.c
31372 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31373 .set_dma_mode = cy82c693_set_dma_mode,
31374 };
31375
31376 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31377 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31378 .name = DRV_NAME,
31379 .init_iops = init_iops_cy82c693,
31380 .port_ops = &cy82c693_port_ops,
31381 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31382 index 58c51cd..4aec3b8 100644
31383 --- a/drivers/ide/hpt366.c
31384 +++ b/drivers/ide/hpt366.c
31385 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31386 }
31387 };
31388
31389 -static const struct hpt_info hpt36x __devinitdata = {
31390 +static const struct hpt_info hpt36x __devinitconst = {
31391 .chip_name = "HPT36x",
31392 .chip_type = HPT36x,
31393 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31394 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31395 .timings = &hpt36x_timings
31396 };
31397
31398 -static const struct hpt_info hpt370 __devinitdata = {
31399 +static const struct hpt_info hpt370 __devinitconst = {
31400 .chip_name = "HPT370",
31401 .chip_type = HPT370,
31402 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31403 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31404 .timings = &hpt37x_timings
31405 };
31406
31407 -static const struct hpt_info hpt370a __devinitdata = {
31408 +static const struct hpt_info hpt370a __devinitconst = {
31409 .chip_name = "HPT370A",
31410 .chip_type = HPT370A,
31411 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31412 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31413 .timings = &hpt37x_timings
31414 };
31415
31416 -static const struct hpt_info hpt374 __devinitdata = {
31417 +static const struct hpt_info hpt374 __devinitconst = {
31418 .chip_name = "HPT374",
31419 .chip_type = HPT374,
31420 .udma_mask = ATA_UDMA5,
31421 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31422 .timings = &hpt37x_timings
31423 };
31424
31425 -static const struct hpt_info hpt372 __devinitdata = {
31426 +static const struct hpt_info hpt372 __devinitconst = {
31427 .chip_name = "HPT372",
31428 .chip_type = HPT372,
31429 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31430 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31431 .timings = &hpt37x_timings
31432 };
31433
31434 -static const struct hpt_info hpt372a __devinitdata = {
31435 +static const struct hpt_info hpt372a __devinitconst = {
31436 .chip_name = "HPT372A",
31437 .chip_type = HPT372A,
31438 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31439 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31440 .timings = &hpt37x_timings
31441 };
31442
31443 -static const struct hpt_info hpt302 __devinitdata = {
31444 +static const struct hpt_info hpt302 __devinitconst = {
31445 .chip_name = "HPT302",
31446 .chip_type = HPT302,
31447 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31448 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31449 .timings = &hpt37x_timings
31450 };
31451
31452 -static const struct hpt_info hpt371 __devinitdata = {
31453 +static const struct hpt_info hpt371 __devinitconst = {
31454 .chip_name = "HPT371",
31455 .chip_type = HPT371,
31456 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31457 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31458 .timings = &hpt37x_timings
31459 };
31460
31461 -static const struct hpt_info hpt372n __devinitdata = {
31462 +static const struct hpt_info hpt372n __devinitconst = {
31463 .chip_name = "HPT372N",
31464 .chip_type = HPT372N,
31465 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31466 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31467 .timings = &hpt37x_timings
31468 };
31469
31470 -static const struct hpt_info hpt302n __devinitdata = {
31471 +static const struct hpt_info hpt302n __devinitconst = {
31472 .chip_name = "HPT302N",
31473 .chip_type = HPT302N,
31474 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31475 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31476 .timings = &hpt37x_timings
31477 };
31478
31479 -static const struct hpt_info hpt371n __devinitdata = {
31480 +static const struct hpt_info hpt371n __devinitconst = {
31481 .chip_name = "HPT371N",
31482 .chip_type = HPT371N,
31483 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31484 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31485 .dma_sff_read_status = ide_dma_sff_read_status,
31486 };
31487
31488 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31489 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31490 { /* 0: HPT36x */
31491 .name = DRV_NAME,
31492 .init_chipset = init_chipset_hpt366,
31493 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31494 index 8126824..55a2798 100644
31495 --- a/drivers/ide/ide-cd.c
31496 +++ b/drivers/ide/ide-cd.c
31497 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31498 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31499 if ((unsigned long)buf & alignment
31500 || blk_rq_bytes(rq) & q->dma_pad_mask
31501 - || object_is_on_stack(buf))
31502 + || object_starts_on_stack(buf))
31503 drive->dma = 0;
31504 }
31505 }
31506 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31507 index 7f56b73..dab5b67 100644
31508 --- a/drivers/ide/ide-pci-generic.c
31509 +++ b/drivers/ide/ide-pci-generic.c
31510 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31511 .udma_mask = ATA_UDMA6, \
31512 }
31513
31514 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31515 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31516 /* 0: Unknown */
31517 DECLARE_GENERIC_PCI_DEV(0),
31518
31519 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31520 index 560e66d..d5dd180 100644
31521 --- a/drivers/ide/it8172.c
31522 +++ b/drivers/ide/it8172.c
31523 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31524 .set_dma_mode = it8172_set_dma_mode,
31525 };
31526
31527 -static const struct ide_port_info it8172_port_info __devinitdata = {
31528 +static const struct ide_port_info it8172_port_info __devinitconst = {
31529 .name = DRV_NAME,
31530 .port_ops = &it8172_port_ops,
31531 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31532 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31533 index 46816ba..1847aeb 100644
31534 --- a/drivers/ide/it8213.c
31535 +++ b/drivers/ide/it8213.c
31536 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31537 .cable_detect = it8213_cable_detect,
31538 };
31539
31540 -static const struct ide_port_info it8213_chipset __devinitdata = {
31541 +static const struct ide_port_info it8213_chipset __devinitconst = {
31542 .name = DRV_NAME,
31543 .enablebits = { {0x41, 0x80, 0x80} },
31544 .port_ops = &it8213_port_ops,
31545 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31546 index 2e3169f..c5611db 100644
31547 --- a/drivers/ide/it821x.c
31548 +++ b/drivers/ide/it821x.c
31549 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31550 .cable_detect = it821x_cable_detect,
31551 };
31552
31553 -static const struct ide_port_info it821x_chipset __devinitdata = {
31554 +static const struct ide_port_info it821x_chipset __devinitconst = {
31555 .name = DRV_NAME,
31556 .init_chipset = init_chipset_it821x,
31557 .init_hwif = init_hwif_it821x,
31558 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31559 index 74c2c4a..efddd7d 100644
31560 --- a/drivers/ide/jmicron.c
31561 +++ b/drivers/ide/jmicron.c
31562 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31563 .cable_detect = jmicron_cable_detect,
31564 };
31565
31566 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31567 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31568 .name = DRV_NAME,
31569 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31570 .port_ops = &jmicron_port_ops,
31571 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31572 index 95327a2..73f78d8 100644
31573 --- a/drivers/ide/ns87415.c
31574 +++ b/drivers/ide/ns87415.c
31575 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31576 .dma_sff_read_status = superio_dma_sff_read_status,
31577 };
31578
31579 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31580 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31581 .name = DRV_NAME,
31582 .init_hwif = init_hwif_ns87415,
31583 .tp_ops = &ns87415_tp_ops,
31584 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31585 index 1a53a4c..39edc66 100644
31586 --- a/drivers/ide/opti621.c
31587 +++ b/drivers/ide/opti621.c
31588 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31589 .set_pio_mode = opti621_set_pio_mode,
31590 };
31591
31592 -static const struct ide_port_info opti621_chipset __devinitdata = {
31593 +static const struct ide_port_info opti621_chipset __devinitconst = {
31594 .name = DRV_NAME,
31595 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31596 .port_ops = &opti621_port_ops,
31597 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31598 index 9546fe2..2e5ceb6 100644
31599 --- a/drivers/ide/pdc202xx_new.c
31600 +++ b/drivers/ide/pdc202xx_new.c
31601 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31602 .udma_mask = udma, \
31603 }
31604
31605 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31606 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31607 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31608 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31609 };
31610 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31611 index 3a35ec6..5634510 100644
31612 --- a/drivers/ide/pdc202xx_old.c
31613 +++ b/drivers/ide/pdc202xx_old.c
31614 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31615 .max_sectors = sectors, \
31616 }
31617
31618 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31619 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31620 { /* 0: PDC20246 */
31621 .name = DRV_NAME,
31622 .init_chipset = init_chipset_pdc202xx,
31623 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31624 index 1892e81..fe0fd60 100644
31625 --- a/drivers/ide/piix.c
31626 +++ b/drivers/ide/piix.c
31627 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31628 .udma_mask = udma, \
31629 }
31630
31631 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31632 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31633 /* 0: MPIIX */
31634 { /*
31635 * MPIIX actually has only a single IDE channel mapped to
31636 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31637 index a6414a8..c04173e 100644
31638 --- a/drivers/ide/rz1000.c
31639 +++ b/drivers/ide/rz1000.c
31640 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31641 }
31642 }
31643
31644 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31645 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31646 .name = DRV_NAME,
31647 .host_flags = IDE_HFLAG_NO_DMA,
31648 };
31649 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31650 index 356b9b5..d4758eb 100644
31651 --- a/drivers/ide/sc1200.c
31652 +++ b/drivers/ide/sc1200.c
31653 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31654 .dma_sff_read_status = ide_dma_sff_read_status,
31655 };
31656
31657 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31658 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31659 .name = DRV_NAME,
31660 .port_ops = &sc1200_port_ops,
31661 .dma_ops = &sc1200_dma_ops,
31662 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31663 index b7f5b0c..9701038 100644
31664 --- a/drivers/ide/scc_pata.c
31665 +++ b/drivers/ide/scc_pata.c
31666 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31667 .dma_sff_read_status = scc_dma_sff_read_status,
31668 };
31669
31670 -static const struct ide_port_info scc_chipset __devinitdata = {
31671 +static const struct ide_port_info scc_chipset __devinitconst = {
31672 .name = "sccIDE",
31673 .init_iops = init_iops_scc,
31674 .init_dma = scc_init_dma,
31675 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31676 index 35fb8da..24d72ef 100644
31677 --- a/drivers/ide/serverworks.c
31678 +++ b/drivers/ide/serverworks.c
31679 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31680 .cable_detect = svwks_cable_detect,
31681 };
31682
31683 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31684 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31685 { /* 0: OSB4 */
31686 .name = DRV_NAME,
31687 .init_chipset = init_chipset_svwks,
31688 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31689 index ddeda44..46f7e30 100644
31690 --- a/drivers/ide/siimage.c
31691 +++ b/drivers/ide/siimage.c
31692 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31693 .udma_mask = ATA_UDMA6, \
31694 }
31695
31696 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31697 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31698 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31699 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31700 };
31701 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31702 index 4a00225..09e61b4 100644
31703 --- a/drivers/ide/sis5513.c
31704 +++ b/drivers/ide/sis5513.c
31705 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31706 .cable_detect = sis_cable_detect,
31707 };
31708
31709 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31710 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31711 .name = DRV_NAME,
31712 .init_chipset = init_chipset_sis5513,
31713 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31714 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31715 index f21dc2a..d051cd2 100644
31716 --- a/drivers/ide/sl82c105.c
31717 +++ b/drivers/ide/sl82c105.c
31718 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31719 .dma_sff_read_status = ide_dma_sff_read_status,
31720 };
31721
31722 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31723 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31724 .name = DRV_NAME,
31725 .init_chipset = init_chipset_sl82c105,
31726 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31727 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31728 index 864ffe0..863a5e9 100644
31729 --- a/drivers/ide/slc90e66.c
31730 +++ b/drivers/ide/slc90e66.c
31731 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31732 .cable_detect = slc90e66_cable_detect,
31733 };
31734
31735 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31736 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31737 .name = DRV_NAME,
31738 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31739 .port_ops = &slc90e66_port_ops,
31740 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31741 index 4799d5c..1794678 100644
31742 --- a/drivers/ide/tc86c001.c
31743 +++ b/drivers/ide/tc86c001.c
31744 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31745 .dma_sff_read_status = ide_dma_sff_read_status,
31746 };
31747
31748 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31749 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31750 .name = DRV_NAME,
31751 .init_hwif = init_hwif_tc86c001,
31752 .port_ops = &tc86c001_port_ops,
31753 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31754 index 281c914..55ce1b8 100644
31755 --- a/drivers/ide/triflex.c
31756 +++ b/drivers/ide/triflex.c
31757 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31758 .set_dma_mode = triflex_set_mode,
31759 };
31760
31761 -static const struct ide_port_info triflex_device __devinitdata = {
31762 +static const struct ide_port_info triflex_device __devinitconst = {
31763 .name = DRV_NAME,
31764 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31765 .port_ops = &triflex_port_ops,
31766 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31767 index 4b42ca0..e494a98 100644
31768 --- a/drivers/ide/trm290.c
31769 +++ b/drivers/ide/trm290.c
31770 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31771 .dma_check = trm290_dma_check,
31772 };
31773
31774 -static const struct ide_port_info trm290_chipset __devinitdata = {
31775 +static const struct ide_port_info trm290_chipset __devinitconst = {
31776 .name = DRV_NAME,
31777 .init_hwif = init_hwif_trm290,
31778 .tp_ops = &trm290_tp_ops,
31779 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31780 index f46f49c..eb77678 100644
31781 --- a/drivers/ide/via82cxxx.c
31782 +++ b/drivers/ide/via82cxxx.c
31783 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31784 .cable_detect = via82cxxx_cable_detect,
31785 };
31786
31787 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31788 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31789 .name = DRV_NAME,
31790 .init_chipset = init_chipset_via82cxxx,
31791 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31792 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31793 index 73d4531..c90cd2d 100644
31794 --- a/drivers/ieee802154/fakehard.c
31795 +++ b/drivers/ieee802154/fakehard.c
31796 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31797 phy->transmit_power = 0xbf;
31798
31799 dev->netdev_ops = &fake_ops;
31800 - dev->ml_priv = &fake_mlme;
31801 + dev->ml_priv = (void *)&fake_mlme;
31802
31803 priv = netdev_priv(dev);
31804 priv->phy = phy;
31805 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31806 index c889aae..6cf5aa7 100644
31807 --- a/drivers/infiniband/core/cm.c
31808 +++ b/drivers/infiniband/core/cm.c
31809 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31810
31811 struct cm_counter_group {
31812 struct kobject obj;
31813 - atomic_long_t counter[CM_ATTR_COUNT];
31814 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31815 };
31816
31817 struct cm_counter_attribute {
31818 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31819 struct ib_mad_send_buf *msg = NULL;
31820 int ret;
31821
31822 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31823 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31824 counter[CM_REQ_COUNTER]);
31825
31826 /* Quick state check to discard duplicate REQs. */
31827 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31828 if (!cm_id_priv)
31829 return;
31830
31831 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31832 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31833 counter[CM_REP_COUNTER]);
31834 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31835 if (ret)
31836 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31837 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31838 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31839 spin_unlock_irq(&cm_id_priv->lock);
31840 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31841 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31842 counter[CM_RTU_COUNTER]);
31843 goto out;
31844 }
31845 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31846 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31847 dreq_msg->local_comm_id);
31848 if (!cm_id_priv) {
31849 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31850 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31851 counter[CM_DREQ_COUNTER]);
31852 cm_issue_drep(work->port, work->mad_recv_wc);
31853 return -EINVAL;
31854 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31855 case IB_CM_MRA_REP_RCVD:
31856 break;
31857 case IB_CM_TIMEWAIT:
31858 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31859 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31860 counter[CM_DREQ_COUNTER]);
31861 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31862 goto unlock;
31863 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31864 cm_free_msg(msg);
31865 goto deref;
31866 case IB_CM_DREQ_RCVD:
31867 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31868 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31869 counter[CM_DREQ_COUNTER]);
31870 goto unlock;
31871 default:
31872 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31873 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31874 cm_id_priv->msg, timeout)) {
31875 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31876 - atomic_long_inc(&work->port->
31877 + atomic_long_inc_unchecked(&work->port->
31878 counter_group[CM_RECV_DUPLICATES].
31879 counter[CM_MRA_COUNTER]);
31880 goto out;
31881 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31882 break;
31883 case IB_CM_MRA_REQ_RCVD:
31884 case IB_CM_MRA_REP_RCVD:
31885 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31886 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31887 counter[CM_MRA_COUNTER]);
31888 /* fall through */
31889 default:
31890 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31891 case IB_CM_LAP_IDLE:
31892 break;
31893 case IB_CM_MRA_LAP_SENT:
31894 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31895 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31896 counter[CM_LAP_COUNTER]);
31897 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31898 goto unlock;
31899 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31900 cm_free_msg(msg);
31901 goto deref;
31902 case IB_CM_LAP_RCVD:
31903 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31904 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31905 counter[CM_LAP_COUNTER]);
31906 goto unlock;
31907 default:
31908 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31909 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31910 if (cur_cm_id_priv) {
31911 spin_unlock_irq(&cm.lock);
31912 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31913 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31914 counter[CM_SIDR_REQ_COUNTER]);
31915 goto out; /* Duplicate message. */
31916 }
31917 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31918 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31919 msg->retries = 1;
31920
31921 - atomic_long_add(1 + msg->retries,
31922 + atomic_long_add_unchecked(1 + msg->retries,
31923 &port->counter_group[CM_XMIT].counter[attr_index]);
31924 if (msg->retries)
31925 - atomic_long_add(msg->retries,
31926 + atomic_long_add_unchecked(msg->retries,
31927 &port->counter_group[CM_XMIT_RETRIES].
31928 counter[attr_index]);
31929
31930 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31931 }
31932
31933 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31934 - atomic_long_inc(&port->counter_group[CM_RECV].
31935 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31936 counter[attr_id - CM_ATTR_ID_OFFSET]);
31937
31938 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31939 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31940 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31941
31942 return sprintf(buf, "%ld\n",
31943 - atomic_long_read(&group->counter[cm_attr->index]));
31944 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31945 }
31946
31947 static const struct sysfs_ops cm_counter_ops = {
31948 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31949 index 176c8f9..2627b62 100644
31950 --- a/drivers/infiniband/core/fmr_pool.c
31951 +++ b/drivers/infiniband/core/fmr_pool.c
31952 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31953
31954 struct task_struct *thread;
31955
31956 - atomic_t req_ser;
31957 - atomic_t flush_ser;
31958 + atomic_unchecked_t req_ser;
31959 + atomic_unchecked_t flush_ser;
31960
31961 wait_queue_head_t force_wait;
31962 };
31963 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31964 struct ib_fmr_pool *pool = pool_ptr;
31965
31966 do {
31967 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31968 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31969 ib_fmr_batch_release(pool);
31970
31971 - atomic_inc(&pool->flush_ser);
31972 + atomic_inc_unchecked(&pool->flush_ser);
31973 wake_up_interruptible(&pool->force_wait);
31974
31975 if (pool->flush_function)
31976 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31977 }
31978
31979 set_current_state(TASK_INTERRUPTIBLE);
31980 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31981 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31982 !kthread_should_stop())
31983 schedule();
31984 __set_current_state(TASK_RUNNING);
31985 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31986 pool->dirty_watermark = params->dirty_watermark;
31987 pool->dirty_len = 0;
31988 spin_lock_init(&pool->pool_lock);
31989 - atomic_set(&pool->req_ser, 0);
31990 - atomic_set(&pool->flush_ser, 0);
31991 + atomic_set_unchecked(&pool->req_ser, 0);
31992 + atomic_set_unchecked(&pool->flush_ser, 0);
31993 init_waitqueue_head(&pool->force_wait);
31994
31995 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31996 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31997 }
31998 spin_unlock_irq(&pool->pool_lock);
31999
32000 - serial = atomic_inc_return(&pool->req_ser);
32001 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32002 wake_up_process(pool->thread);
32003
32004 if (wait_event_interruptible(pool->force_wait,
32005 - atomic_read(&pool->flush_ser) - serial >= 0))
32006 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32007 return -EINTR;
32008
32009 return 0;
32010 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32011 } else {
32012 list_add_tail(&fmr->list, &pool->dirty_list);
32013 if (++pool->dirty_len >= pool->dirty_watermark) {
32014 - atomic_inc(&pool->req_ser);
32015 + atomic_inc_unchecked(&pool->req_ser);
32016 wake_up_process(pool->thread);
32017 }
32018 }
32019 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32020 index 40c8353..946b0e4 100644
32021 --- a/drivers/infiniband/hw/cxgb4/mem.c
32022 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32023 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32024 int err;
32025 struct fw_ri_tpte tpt;
32026 u32 stag_idx;
32027 - static atomic_t key;
32028 + static atomic_unchecked_t key;
32029
32030 if (c4iw_fatal_error(rdev))
32031 return -EIO;
32032 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32033 &rdev->resource.tpt_fifo_lock);
32034 if (!stag_idx)
32035 return -ENOMEM;
32036 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32037 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32038 }
32039 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32040 __func__, stag_state, type, pdid, stag_idx);
32041 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32042 index a4de9d5..5fa20c3 100644
32043 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32044 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32045 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32046 };
32047
32048 static ssize_t flash_read(struct file *file, char __user *buf,
32049 + size_t count, loff_t *ppos) __size_overflow(3);
32050 +static ssize_t flash_read(struct file *file, char __user *buf,
32051 size_t count, loff_t *ppos)
32052 {
32053 struct ipath_devdata *dd;
32054 @@ -177,6 +179,8 @@ bail:
32055 }
32056
32057 static ssize_t flash_write(struct file *file, const char __user *buf,
32058 + size_t count, loff_t *ppos) __size_overflow(3);
32059 +static ssize_t flash_write(struct file *file, const char __user *buf,
32060 size_t count, loff_t *ppos)
32061 {
32062 struct ipath_devdata *dd;
32063 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32064 index 79b3dbc..96e5fcc 100644
32065 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32066 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32067 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32068 struct ib_atomic_eth *ateth;
32069 struct ipath_ack_entry *e;
32070 u64 vaddr;
32071 - atomic64_t *maddr;
32072 + atomic64_unchecked_t *maddr;
32073 u64 sdata;
32074 u32 rkey;
32075 u8 next;
32076 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32077 IB_ACCESS_REMOTE_ATOMIC)))
32078 goto nack_acc_unlck;
32079 /* Perform atomic OP and save result. */
32080 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32081 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32082 sdata = be64_to_cpu(ateth->swap_data);
32083 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32084 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32085 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32086 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32087 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32088 be64_to_cpu(ateth->compare_data),
32089 sdata);
32090 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32091 index 1f95bba..9530f87 100644
32092 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32093 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32094 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32095 unsigned long flags;
32096 struct ib_wc wc;
32097 u64 sdata;
32098 - atomic64_t *maddr;
32099 + atomic64_unchecked_t *maddr;
32100 enum ib_wc_status send_status;
32101
32102 /*
32103 @@ -382,11 +382,11 @@ again:
32104 IB_ACCESS_REMOTE_ATOMIC)))
32105 goto acc_err;
32106 /* Perform atomic OP and save result. */
32107 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32108 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32109 sdata = wqe->wr.wr.atomic.compare_add;
32110 *(u64 *) sqp->s_sge.sge.vaddr =
32111 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32112 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32113 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32114 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32115 sdata, wqe->wr.wr.atomic.swap);
32116 goto send_comp;
32117 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32118 index 7140199..da60063 100644
32119 --- a/drivers/infiniband/hw/nes/nes.c
32120 +++ b/drivers/infiniband/hw/nes/nes.c
32121 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32122 LIST_HEAD(nes_adapter_list);
32123 static LIST_HEAD(nes_dev_list);
32124
32125 -atomic_t qps_destroyed;
32126 +atomic_unchecked_t qps_destroyed;
32127
32128 static unsigned int ee_flsh_adapter;
32129 static unsigned int sysfs_nonidx_addr;
32130 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32131 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32132 struct nes_adapter *nesadapter = nesdev->nesadapter;
32133
32134 - atomic_inc(&qps_destroyed);
32135 + atomic_inc_unchecked(&qps_destroyed);
32136
32137 /* Free the control structures */
32138
32139 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32140 index c438e46..ca30356 100644
32141 --- a/drivers/infiniband/hw/nes/nes.h
32142 +++ b/drivers/infiniband/hw/nes/nes.h
32143 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32144 extern unsigned int wqm_quanta;
32145 extern struct list_head nes_adapter_list;
32146
32147 -extern atomic_t cm_connects;
32148 -extern atomic_t cm_accepts;
32149 -extern atomic_t cm_disconnects;
32150 -extern atomic_t cm_closes;
32151 -extern atomic_t cm_connecteds;
32152 -extern atomic_t cm_connect_reqs;
32153 -extern atomic_t cm_rejects;
32154 -extern atomic_t mod_qp_timouts;
32155 -extern atomic_t qps_created;
32156 -extern atomic_t qps_destroyed;
32157 -extern atomic_t sw_qps_destroyed;
32158 +extern atomic_unchecked_t cm_connects;
32159 +extern atomic_unchecked_t cm_accepts;
32160 +extern atomic_unchecked_t cm_disconnects;
32161 +extern atomic_unchecked_t cm_closes;
32162 +extern atomic_unchecked_t cm_connecteds;
32163 +extern atomic_unchecked_t cm_connect_reqs;
32164 +extern atomic_unchecked_t cm_rejects;
32165 +extern atomic_unchecked_t mod_qp_timouts;
32166 +extern atomic_unchecked_t qps_created;
32167 +extern atomic_unchecked_t qps_destroyed;
32168 +extern atomic_unchecked_t sw_qps_destroyed;
32169 extern u32 mh_detected;
32170 extern u32 mh_pauses_sent;
32171 extern u32 cm_packets_sent;
32172 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32173 extern u32 cm_packets_received;
32174 extern u32 cm_packets_dropped;
32175 extern u32 cm_packets_retrans;
32176 -extern atomic_t cm_listens_created;
32177 -extern atomic_t cm_listens_destroyed;
32178 +extern atomic_unchecked_t cm_listens_created;
32179 +extern atomic_unchecked_t cm_listens_destroyed;
32180 extern u32 cm_backlog_drops;
32181 -extern atomic_t cm_loopbacks;
32182 -extern atomic_t cm_nodes_created;
32183 -extern atomic_t cm_nodes_destroyed;
32184 -extern atomic_t cm_accel_dropped_pkts;
32185 -extern atomic_t cm_resets_recvd;
32186 -extern atomic_t pau_qps_created;
32187 -extern atomic_t pau_qps_destroyed;
32188 +extern atomic_unchecked_t cm_loopbacks;
32189 +extern atomic_unchecked_t cm_nodes_created;
32190 +extern atomic_unchecked_t cm_nodes_destroyed;
32191 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32192 +extern atomic_unchecked_t cm_resets_recvd;
32193 +extern atomic_unchecked_t pau_qps_created;
32194 +extern atomic_unchecked_t pau_qps_destroyed;
32195
32196 extern u32 int_mod_timer_init;
32197 extern u32 int_mod_cq_depth_256;
32198 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32199 index a4972ab..1bcfc31 100644
32200 --- a/drivers/infiniband/hw/nes/nes_cm.c
32201 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32202 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32203 u32 cm_packets_retrans;
32204 u32 cm_packets_created;
32205 u32 cm_packets_received;
32206 -atomic_t cm_listens_created;
32207 -atomic_t cm_listens_destroyed;
32208 +atomic_unchecked_t cm_listens_created;
32209 +atomic_unchecked_t cm_listens_destroyed;
32210 u32 cm_backlog_drops;
32211 -atomic_t cm_loopbacks;
32212 -atomic_t cm_nodes_created;
32213 -atomic_t cm_nodes_destroyed;
32214 -atomic_t cm_accel_dropped_pkts;
32215 -atomic_t cm_resets_recvd;
32216 +atomic_unchecked_t cm_loopbacks;
32217 +atomic_unchecked_t cm_nodes_created;
32218 +atomic_unchecked_t cm_nodes_destroyed;
32219 +atomic_unchecked_t cm_accel_dropped_pkts;
32220 +atomic_unchecked_t cm_resets_recvd;
32221
32222 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32223 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32224 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32225
32226 static struct nes_cm_core *g_cm_core;
32227
32228 -atomic_t cm_connects;
32229 -atomic_t cm_accepts;
32230 -atomic_t cm_disconnects;
32231 -atomic_t cm_closes;
32232 -atomic_t cm_connecteds;
32233 -atomic_t cm_connect_reqs;
32234 -atomic_t cm_rejects;
32235 +atomic_unchecked_t cm_connects;
32236 +atomic_unchecked_t cm_accepts;
32237 +atomic_unchecked_t cm_disconnects;
32238 +atomic_unchecked_t cm_closes;
32239 +atomic_unchecked_t cm_connecteds;
32240 +atomic_unchecked_t cm_connect_reqs;
32241 +atomic_unchecked_t cm_rejects;
32242
32243 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32244 {
32245 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32246 kfree(listener);
32247 listener = NULL;
32248 ret = 0;
32249 - atomic_inc(&cm_listens_destroyed);
32250 + atomic_inc_unchecked(&cm_listens_destroyed);
32251 } else {
32252 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32253 }
32254 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32255 cm_node->rem_mac);
32256
32257 add_hte_node(cm_core, cm_node);
32258 - atomic_inc(&cm_nodes_created);
32259 + atomic_inc_unchecked(&cm_nodes_created);
32260
32261 return cm_node;
32262 }
32263 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32264 }
32265
32266 atomic_dec(&cm_core->node_cnt);
32267 - atomic_inc(&cm_nodes_destroyed);
32268 + atomic_inc_unchecked(&cm_nodes_destroyed);
32269 nesqp = cm_node->nesqp;
32270 if (nesqp) {
32271 nesqp->cm_node = NULL;
32272 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32273
32274 static void drop_packet(struct sk_buff *skb)
32275 {
32276 - atomic_inc(&cm_accel_dropped_pkts);
32277 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32278 dev_kfree_skb_any(skb);
32279 }
32280
32281 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32282 {
32283
32284 int reset = 0; /* whether to send reset in case of err.. */
32285 - atomic_inc(&cm_resets_recvd);
32286 + atomic_inc_unchecked(&cm_resets_recvd);
32287 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32288 " refcnt=%d\n", cm_node, cm_node->state,
32289 atomic_read(&cm_node->ref_count));
32290 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32291 rem_ref_cm_node(cm_node->cm_core, cm_node);
32292 return NULL;
32293 }
32294 - atomic_inc(&cm_loopbacks);
32295 + atomic_inc_unchecked(&cm_loopbacks);
32296 loopbackremotenode->loopbackpartner = cm_node;
32297 loopbackremotenode->tcp_cntxt.rcv_wscale =
32298 NES_CM_DEFAULT_RCV_WND_SCALE;
32299 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32300 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32301 else {
32302 rem_ref_cm_node(cm_core, cm_node);
32303 - atomic_inc(&cm_accel_dropped_pkts);
32304 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32305 dev_kfree_skb_any(skb);
32306 }
32307 break;
32308 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32309
32310 if ((cm_id) && (cm_id->event_handler)) {
32311 if (issue_disconn) {
32312 - atomic_inc(&cm_disconnects);
32313 + atomic_inc_unchecked(&cm_disconnects);
32314 cm_event.event = IW_CM_EVENT_DISCONNECT;
32315 cm_event.status = disconn_status;
32316 cm_event.local_addr = cm_id->local_addr;
32317 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32318 }
32319
32320 if (issue_close) {
32321 - atomic_inc(&cm_closes);
32322 + atomic_inc_unchecked(&cm_closes);
32323 nes_disconnect(nesqp, 1);
32324
32325 cm_id->provider_data = nesqp;
32326 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32327
32328 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32329 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32330 - atomic_inc(&cm_accepts);
32331 + atomic_inc_unchecked(&cm_accepts);
32332
32333 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32334 netdev_refcnt_read(nesvnic->netdev));
32335 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32336 struct nes_cm_core *cm_core;
32337 u8 *start_buff;
32338
32339 - atomic_inc(&cm_rejects);
32340 + atomic_inc_unchecked(&cm_rejects);
32341 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32342 loopback = cm_node->loopbackpartner;
32343 cm_core = cm_node->cm_core;
32344 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32345 ntohl(cm_id->local_addr.sin_addr.s_addr),
32346 ntohs(cm_id->local_addr.sin_port));
32347
32348 - atomic_inc(&cm_connects);
32349 + atomic_inc_unchecked(&cm_connects);
32350 nesqp->active_conn = 1;
32351
32352 /* cache the cm_id in the qp */
32353 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32354 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32355 return err;
32356 }
32357 - atomic_inc(&cm_listens_created);
32358 + atomic_inc_unchecked(&cm_listens_created);
32359 }
32360
32361 cm_id->add_ref(cm_id);
32362 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32363
32364 if (nesqp->destroyed)
32365 return;
32366 - atomic_inc(&cm_connecteds);
32367 + atomic_inc_unchecked(&cm_connecteds);
32368 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32369 " local port 0x%04X. jiffies = %lu.\n",
32370 nesqp->hwqp.qp_id,
32371 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32372
32373 cm_id->add_ref(cm_id);
32374 ret = cm_id->event_handler(cm_id, &cm_event);
32375 - atomic_inc(&cm_closes);
32376 + atomic_inc_unchecked(&cm_closes);
32377 cm_event.event = IW_CM_EVENT_CLOSE;
32378 cm_event.status = 0;
32379 cm_event.provider_data = cm_id->provider_data;
32380 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32381 return;
32382 cm_id = cm_node->cm_id;
32383
32384 - atomic_inc(&cm_connect_reqs);
32385 + atomic_inc_unchecked(&cm_connect_reqs);
32386 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32387 cm_node, cm_id, jiffies);
32388
32389 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32390 return;
32391 cm_id = cm_node->cm_id;
32392
32393 - atomic_inc(&cm_connect_reqs);
32394 + atomic_inc_unchecked(&cm_connect_reqs);
32395 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32396 cm_node, cm_id, jiffies);
32397
32398 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32399 index 3ba7be3..c81f6ff 100644
32400 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32401 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32402 @@ -40,8 +40,8 @@
32403 #include "nes.h"
32404 #include "nes_mgt.h"
32405
32406 -atomic_t pau_qps_created;
32407 -atomic_t pau_qps_destroyed;
32408 +atomic_unchecked_t pau_qps_created;
32409 +atomic_unchecked_t pau_qps_destroyed;
32410
32411 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32412 {
32413 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32414 {
32415 struct sk_buff *skb;
32416 unsigned long flags;
32417 - atomic_inc(&pau_qps_destroyed);
32418 + atomic_inc_unchecked(&pau_qps_destroyed);
32419
32420 /* Free packets that have not yet been forwarded */
32421 /* Lock is acquired by skb_dequeue when removing the skb */
32422 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32423 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32424 skb_queue_head_init(&nesqp->pau_list);
32425 spin_lock_init(&nesqp->pau_lock);
32426 - atomic_inc(&pau_qps_created);
32427 + atomic_inc_unchecked(&pau_qps_created);
32428 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32429 }
32430
32431 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32432 index f3a3ecf..57d311d 100644
32433 --- a/drivers/infiniband/hw/nes/nes_nic.c
32434 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32435 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32436 target_stat_values[++index] = mh_detected;
32437 target_stat_values[++index] = mh_pauses_sent;
32438 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32439 - target_stat_values[++index] = atomic_read(&cm_connects);
32440 - target_stat_values[++index] = atomic_read(&cm_accepts);
32441 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32442 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32443 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32444 - target_stat_values[++index] = atomic_read(&cm_rejects);
32445 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32446 - target_stat_values[++index] = atomic_read(&qps_created);
32447 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32448 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32449 - target_stat_values[++index] = atomic_read(&cm_closes);
32450 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32451 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32452 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32453 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32454 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32455 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32456 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32457 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32458 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32459 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32460 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32461 target_stat_values[++index] = cm_packets_sent;
32462 target_stat_values[++index] = cm_packets_bounced;
32463 target_stat_values[++index] = cm_packets_created;
32464 target_stat_values[++index] = cm_packets_received;
32465 target_stat_values[++index] = cm_packets_dropped;
32466 target_stat_values[++index] = cm_packets_retrans;
32467 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32468 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32469 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32470 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32471 target_stat_values[++index] = cm_backlog_drops;
32472 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32473 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32474 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32475 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32476 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32477 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32478 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32479 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32480 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32481 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32482 target_stat_values[++index] = nesadapter->free_4kpbl;
32483 target_stat_values[++index] = nesadapter->free_256pbl;
32484 target_stat_values[++index] = int_mod_timer_init;
32485 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32486 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32487 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32488 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32489 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32490 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32491 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32492 }
32493
32494 /**
32495 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32496 index 0927b5c..ed67986 100644
32497 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32498 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32499 @@ -46,9 +46,9 @@
32500
32501 #include <rdma/ib_umem.h>
32502
32503 -atomic_t mod_qp_timouts;
32504 -atomic_t qps_created;
32505 -atomic_t sw_qps_destroyed;
32506 +atomic_unchecked_t mod_qp_timouts;
32507 +atomic_unchecked_t qps_created;
32508 +atomic_unchecked_t sw_qps_destroyed;
32509
32510 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32511
32512 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32513 if (init_attr->create_flags)
32514 return ERR_PTR(-EINVAL);
32515
32516 - atomic_inc(&qps_created);
32517 + atomic_inc_unchecked(&qps_created);
32518 switch (init_attr->qp_type) {
32519 case IB_QPT_RC:
32520 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32521 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32522 struct iw_cm_event cm_event;
32523 int ret = 0;
32524
32525 - atomic_inc(&sw_qps_destroyed);
32526 + atomic_inc_unchecked(&sw_qps_destroyed);
32527 nesqp->destroyed = 1;
32528
32529 /* Blow away the connection if it exists. */
32530 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32531 index b881bdc..c2e360c 100644
32532 --- a/drivers/infiniband/hw/qib/qib.h
32533 +++ b/drivers/infiniband/hw/qib/qib.h
32534 @@ -51,6 +51,7 @@
32535 #include <linux/completion.h>
32536 #include <linux/kref.h>
32537 #include <linux/sched.h>
32538 +#include <linux/slab.h>
32539
32540 #include "qib_common.h"
32541 #include "qib_verbs.h"
32542 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32543 index 05e0f17..0275789 100644
32544 --- a/drivers/infiniband/hw/qib/qib_fs.c
32545 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32546 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32547 };
32548
32549 static ssize_t flash_read(struct file *file, char __user *buf,
32550 + size_t count, loff_t *ppos) __size_overflow(3);
32551 +static ssize_t flash_read(struct file *file, char __user *buf,
32552 size_t count, loff_t *ppos)
32553 {
32554 struct qib_devdata *dd;
32555 @@ -318,6 +320,8 @@ bail:
32556 }
32557
32558 static ssize_t flash_write(struct file *file, const char __user *buf,
32559 + size_t count, loff_t *ppos) __size_overflow(3);
32560 +static ssize_t flash_write(struct file *file, const char __user *buf,
32561 size_t count, loff_t *ppos)
32562 {
32563 struct qib_devdata *dd;
32564 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32565 index c351aa4..e6967c2 100644
32566 --- a/drivers/input/gameport/gameport.c
32567 +++ b/drivers/input/gameport/gameport.c
32568 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32569 */
32570 static void gameport_init_port(struct gameport *gameport)
32571 {
32572 - static atomic_t gameport_no = ATOMIC_INIT(0);
32573 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32574
32575 __module_get(THIS_MODULE);
32576
32577 mutex_init(&gameport->drv_mutex);
32578 device_initialize(&gameport->dev);
32579 dev_set_name(&gameport->dev, "gameport%lu",
32580 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32581 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32582 gameport->dev.bus = &gameport_bus;
32583 gameport->dev.release = gameport_release_port;
32584 if (gameport->parent)
32585 diff --git a/drivers/input/input.c b/drivers/input/input.c
32586 index 1f78c95..3cddc6c 100644
32587 --- a/drivers/input/input.c
32588 +++ b/drivers/input/input.c
32589 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32590 */
32591 int input_register_device(struct input_dev *dev)
32592 {
32593 - static atomic_t input_no = ATOMIC_INIT(0);
32594 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32595 struct input_handler *handler;
32596 const char *path;
32597 int error;
32598 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32599 dev->setkeycode = input_default_setkeycode;
32600
32601 dev_set_name(&dev->dev, "input%ld",
32602 - (unsigned long) atomic_inc_return(&input_no) - 1);
32603 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32604
32605 error = device_add(&dev->dev);
32606 if (error)
32607 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32608 index b8d8611..7a4a04b 100644
32609 --- a/drivers/input/joystick/sidewinder.c
32610 +++ b/drivers/input/joystick/sidewinder.c
32611 @@ -30,6 +30,7 @@
32612 #include <linux/kernel.h>
32613 #include <linux/module.h>
32614 #include <linux/slab.h>
32615 +#include <linux/sched.h>
32616 #include <linux/init.h>
32617 #include <linux/input.h>
32618 #include <linux/gameport.h>
32619 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32620 index fd7a0d5..a4af10c 100644
32621 --- a/drivers/input/joystick/xpad.c
32622 +++ b/drivers/input/joystick/xpad.c
32623 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32624
32625 static int xpad_led_probe(struct usb_xpad *xpad)
32626 {
32627 - static atomic_t led_seq = ATOMIC_INIT(0);
32628 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32629 long led_no;
32630 struct xpad_led *led;
32631 struct led_classdev *led_cdev;
32632 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32633 if (!led)
32634 return -ENOMEM;
32635
32636 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32637 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32638
32639 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32640 led->xpad = xpad;
32641 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32642 index 0110b5a..d3ad144 100644
32643 --- a/drivers/input/mousedev.c
32644 +++ b/drivers/input/mousedev.c
32645 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32646
32647 spin_unlock_irq(&client->packet_lock);
32648
32649 - if (copy_to_user(buffer, data, count))
32650 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32651 return -EFAULT;
32652
32653 return count;
32654 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32655 index ba70058..571d25d 100644
32656 --- a/drivers/input/serio/serio.c
32657 +++ b/drivers/input/serio/serio.c
32658 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32659 */
32660 static void serio_init_port(struct serio *serio)
32661 {
32662 - static atomic_t serio_no = ATOMIC_INIT(0);
32663 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32664
32665 __module_get(THIS_MODULE);
32666
32667 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32668 mutex_init(&serio->drv_mutex);
32669 device_initialize(&serio->dev);
32670 dev_set_name(&serio->dev, "serio%ld",
32671 - (long)atomic_inc_return(&serio_no) - 1);
32672 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32673 serio->dev.bus = &serio_bus;
32674 serio->dev.release = serio_release_port;
32675 serio->dev.groups = serio_device_attr_groups;
32676 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32677 index e44933d..9ba484a 100644
32678 --- a/drivers/isdn/capi/capi.c
32679 +++ b/drivers/isdn/capi/capi.c
32680 @@ -83,8 +83,8 @@ struct capiminor {
32681
32682 struct capi20_appl *ap;
32683 u32 ncci;
32684 - atomic_t datahandle;
32685 - atomic_t msgid;
32686 + atomic_unchecked_t datahandle;
32687 + atomic_unchecked_t msgid;
32688
32689 struct tty_port port;
32690 int ttyinstop;
32691 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32692 capimsg_setu16(s, 2, mp->ap->applid);
32693 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32694 capimsg_setu8 (s, 5, CAPI_RESP);
32695 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32696 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32697 capimsg_setu32(s, 8, mp->ncci);
32698 capimsg_setu16(s, 12, datahandle);
32699 }
32700 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32701 mp->outbytes -= len;
32702 spin_unlock_bh(&mp->outlock);
32703
32704 - datahandle = atomic_inc_return(&mp->datahandle);
32705 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32706 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32707 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32708 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32709 capimsg_setu16(skb->data, 2, mp->ap->applid);
32710 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32711 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32712 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32713 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32714 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32715 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32716 capimsg_setu16(skb->data, 16, len); /* Data length */
32717 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32718 index db621db..825ea1a 100644
32719 --- a/drivers/isdn/gigaset/common.c
32720 +++ b/drivers/isdn/gigaset/common.c
32721 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32722 cs->commands_pending = 0;
32723 cs->cur_at_seq = 0;
32724 cs->gotfwver = -1;
32725 - cs->open_count = 0;
32726 + local_set(&cs->open_count, 0);
32727 cs->dev = NULL;
32728 cs->tty = NULL;
32729 cs->tty_dev = NULL;
32730 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32731 index 212efaf..f187c6b 100644
32732 --- a/drivers/isdn/gigaset/gigaset.h
32733 +++ b/drivers/isdn/gigaset/gigaset.h
32734 @@ -35,6 +35,7 @@
32735 #include <linux/tty_driver.h>
32736 #include <linux/list.h>
32737 #include <linux/atomic.h>
32738 +#include <asm/local.h>
32739
32740 #define GIG_VERSION {0, 5, 0, 0}
32741 #define GIG_COMPAT {0, 4, 0, 0}
32742 @@ -433,7 +434,7 @@ struct cardstate {
32743 spinlock_t cmdlock;
32744 unsigned curlen, cmdbytes;
32745
32746 - unsigned open_count;
32747 + local_t open_count;
32748 struct tty_struct *tty;
32749 struct tasklet_struct if_wake_tasklet;
32750 unsigned control_state;
32751 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32752 index ee0a549..a7c9798 100644
32753 --- a/drivers/isdn/gigaset/interface.c
32754 +++ b/drivers/isdn/gigaset/interface.c
32755 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32756 }
32757 tty->driver_data = cs;
32758
32759 - ++cs->open_count;
32760 -
32761 - if (cs->open_count == 1) {
32762 + if (local_inc_return(&cs->open_count) == 1) {
32763 spin_lock_irqsave(&cs->lock, flags);
32764 cs->tty = tty;
32765 spin_unlock_irqrestore(&cs->lock, flags);
32766 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32767
32768 if (!cs->connected)
32769 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32770 - else if (!cs->open_count)
32771 + else if (!local_read(&cs->open_count))
32772 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32773 else {
32774 - if (!--cs->open_count) {
32775 + if (!local_dec_return(&cs->open_count)) {
32776 spin_lock_irqsave(&cs->lock, flags);
32777 cs->tty = NULL;
32778 spin_unlock_irqrestore(&cs->lock, flags);
32779 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32780 if (!cs->connected) {
32781 gig_dbg(DEBUG_IF, "not connected");
32782 retval = -ENODEV;
32783 - } else if (!cs->open_count)
32784 + } else if (!local_read(&cs->open_count))
32785 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32786 else {
32787 retval = 0;
32788 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32789 retval = -ENODEV;
32790 goto done;
32791 }
32792 - if (!cs->open_count) {
32793 + if (!local_read(&cs->open_count)) {
32794 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32795 retval = -ENODEV;
32796 goto done;
32797 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32798 if (!cs->connected) {
32799 gig_dbg(DEBUG_IF, "not connected");
32800 retval = -ENODEV;
32801 - } else if (!cs->open_count)
32802 + } else if (!local_read(&cs->open_count))
32803 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32804 else if (cs->mstate != MS_LOCKED) {
32805 dev_warn(cs->dev, "can't write to unlocked device\n");
32806 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32807
32808 if (!cs->connected)
32809 gig_dbg(DEBUG_IF, "not connected");
32810 - else if (!cs->open_count)
32811 + else if (!local_read(&cs->open_count))
32812 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32813 else if (cs->mstate != MS_LOCKED)
32814 dev_warn(cs->dev, "can't write to unlocked device\n");
32815 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32816
32817 if (!cs->connected)
32818 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32819 - else if (!cs->open_count)
32820 + else if (!local_read(&cs->open_count))
32821 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32822 else
32823 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32824 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32825
32826 if (!cs->connected)
32827 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32828 - else if (!cs->open_count)
32829 + else if (!local_read(&cs->open_count))
32830 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32831 else
32832 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32833 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32834 goto out;
32835 }
32836
32837 - if (!cs->open_count) {
32838 + if (!local_read(&cs->open_count)) {
32839 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32840 goto out;
32841 }
32842 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32843 index 2a57da59..e7a12ed 100644
32844 --- a/drivers/isdn/hardware/avm/b1.c
32845 +++ b/drivers/isdn/hardware/avm/b1.c
32846 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32847 }
32848 if (left) {
32849 if (t4file->user) {
32850 - if (copy_from_user(buf, dp, left))
32851 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32852 return -EFAULT;
32853 } else {
32854 memcpy(buf, dp, left);
32855 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32856 }
32857 if (left) {
32858 if (config->user) {
32859 - if (copy_from_user(buf, dp, left))
32860 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32861 return -EFAULT;
32862 } else {
32863 memcpy(buf, dp, left);
32864 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32865 index 85784a7..a19ca98 100644
32866 --- a/drivers/isdn/hardware/eicon/divasync.h
32867 +++ b/drivers/isdn/hardware/eicon/divasync.h
32868 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32869 } diva_didd_add_adapter_t;
32870 typedef struct _diva_didd_remove_adapter {
32871 IDI_CALL p_request;
32872 -} diva_didd_remove_adapter_t;
32873 +} __no_const diva_didd_remove_adapter_t;
32874 typedef struct _diva_didd_read_adapter_array {
32875 void * buffer;
32876 dword length;
32877 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32878 index a3bd163..8956575 100644
32879 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32880 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32881 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32882 typedef struct _diva_os_idi_adapter_interface {
32883 diva_init_card_proc_t cleanup_adapter_proc;
32884 diva_cmd_card_proc_t cmd_proc;
32885 -} diva_os_idi_adapter_interface_t;
32886 +} __no_const diva_os_idi_adapter_interface_t;
32887
32888 typedef struct _diva_os_xdi_adapter {
32889 struct list_head link;
32890 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32891 index 1f355bb..43f1fea 100644
32892 --- a/drivers/isdn/icn/icn.c
32893 +++ b/drivers/isdn/icn/icn.c
32894 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32895 if (count > len)
32896 count = len;
32897 if (user) {
32898 - if (copy_from_user(msg, buf, count))
32899 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32900 return -EFAULT;
32901 } else
32902 memcpy(msg, buf, count);
32903 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32904 index b5fdcb7..5b6c59f 100644
32905 --- a/drivers/lguest/core.c
32906 +++ b/drivers/lguest/core.c
32907 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32908 * it's worked so far. The end address needs +1 because __get_vm_area
32909 * allocates an extra guard page, so we need space for that.
32910 */
32911 +
32912 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32913 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32914 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32915 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32916 +#else
32917 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32918 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32919 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32920 +#endif
32921 +
32922 if (!switcher_vma) {
32923 err = -ENOMEM;
32924 printk("lguest: could not map switcher pages high\n");
32925 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32926 * Now the Switcher is mapped at the right address, we can't fail!
32927 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32928 */
32929 - memcpy(switcher_vma->addr, start_switcher_text,
32930 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32931 end_switcher_text - start_switcher_text);
32932
32933 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32934 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
32935 index ff4a0bc..f5fdd9c 100644
32936 --- a/drivers/lguest/lguest_user.c
32937 +++ b/drivers/lguest/lguest_user.c
32938 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
32939 * Once our Guest is initialized, the Launcher makes it run by reading
32940 * from /dev/lguest.
32941 */
32942 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
32943 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
32944 {
32945 struct lguest *lg = file->private_data;
32946 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32947 index 3980903..ce25c5e 100644
32948 --- a/drivers/lguest/x86/core.c
32949 +++ b/drivers/lguest/x86/core.c
32950 @@ -59,7 +59,7 @@ static struct {
32951 /* Offset from where switcher.S was compiled to where we've copied it */
32952 static unsigned long switcher_offset(void)
32953 {
32954 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32955 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32956 }
32957
32958 /* This cpu's struct lguest_pages. */
32959 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32960 * These copies are pretty cheap, so we do them unconditionally: */
32961 /* Save the current Host top-level page directory.
32962 */
32963 +
32964 +#ifdef CONFIG_PAX_PER_CPU_PGD
32965 + pages->state.host_cr3 = read_cr3();
32966 +#else
32967 pages->state.host_cr3 = __pa(current->mm->pgd);
32968 +#endif
32969 +
32970 /*
32971 * Set up the Guest's page tables to see this CPU's pages (and no
32972 * other CPU's pages).
32973 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32974 * compiled-in switcher code and the high-mapped copy we just made.
32975 */
32976 for (i = 0; i < IDT_ENTRIES; i++)
32977 - default_idt_entries[i] += switcher_offset();
32978 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32979
32980 /*
32981 * Set up the Switcher's per-cpu areas.
32982 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32983 * it will be undisturbed when we switch. To change %cs and jump we
32984 * need this structure to feed to Intel's "lcall" instruction.
32985 */
32986 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32987 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32988 lguest_entry.segment = LGUEST_CS;
32989
32990 /*
32991 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32992 index 40634b0..4f5855e 100644
32993 --- a/drivers/lguest/x86/switcher_32.S
32994 +++ b/drivers/lguest/x86/switcher_32.S
32995 @@ -87,6 +87,7 @@
32996 #include <asm/page.h>
32997 #include <asm/segment.h>
32998 #include <asm/lguest.h>
32999 +#include <asm/processor-flags.h>
33000
33001 // We mark the start of the code to copy
33002 // It's placed in .text tho it's never run here
33003 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33004 // Changes type when we load it: damn Intel!
33005 // For after we switch over our page tables
33006 // That entry will be read-only: we'd crash.
33007 +
33008 +#ifdef CONFIG_PAX_KERNEXEC
33009 + mov %cr0, %edx
33010 + xor $X86_CR0_WP, %edx
33011 + mov %edx, %cr0
33012 +#endif
33013 +
33014 movl $(GDT_ENTRY_TSS*8), %edx
33015 ltr %dx
33016
33017 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33018 // Let's clear it again for our return.
33019 // The GDT descriptor of the Host
33020 // Points to the table after two "size" bytes
33021 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33022 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33023 // Clear "used" from type field (byte 5, bit 2)
33024 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33025 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33026 +
33027 +#ifdef CONFIG_PAX_KERNEXEC
33028 + mov %cr0, %eax
33029 + xor $X86_CR0_WP, %eax
33030 + mov %eax, %cr0
33031 +#endif
33032
33033 // Once our page table's switched, the Guest is live!
33034 // The Host fades as we run this final step.
33035 @@ -295,13 +309,12 @@ deliver_to_host:
33036 // I consulted gcc, and it gave
33037 // These instructions, which I gladly credit:
33038 leal (%edx,%ebx,8), %eax
33039 - movzwl (%eax),%edx
33040 - movl 4(%eax), %eax
33041 - xorw %ax, %ax
33042 - orl %eax, %edx
33043 + movl 4(%eax), %edx
33044 + movw (%eax), %dx
33045 // Now the address of the handler's in %edx
33046 // We call it now: its "iret" drops us home.
33047 - jmp *%edx
33048 + ljmp $__KERNEL_CS, $1f
33049 +1: jmp *%edx
33050
33051 // Every interrupt can come to us here
33052 // But we must truly tell each apart.
33053 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33054 index 4daf9e5..b8d1d0f 100644
33055 --- a/drivers/macintosh/macio_asic.c
33056 +++ b/drivers/macintosh/macio_asic.c
33057 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33058 * MacIO is matched against any Apple ID, it's probe() function
33059 * will then decide wether it applies or not
33060 */
33061 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33062 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33063 .vendor = PCI_VENDOR_ID_APPLE,
33064 .device = PCI_ANY_ID,
33065 .subvendor = PCI_ANY_ID,
33066 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33067 index 1ce84ed..0fdd40a 100644
33068 --- a/drivers/md/dm-ioctl.c
33069 +++ b/drivers/md/dm-ioctl.c
33070 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33071 cmd == DM_LIST_VERSIONS_CMD)
33072 return 0;
33073
33074 - if ((cmd == DM_DEV_CREATE_CMD)) {
33075 + if (cmd == DM_DEV_CREATE_CMD) {
33076 if (!*param->name) {
33077 DMWARN("name not supplied when creating device");
33078 return -EINVAL;
33079 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33080 index 9bfd057..5373ff3 100644
33081 --- a/drivers/md/dm-raid1.c
33082 +++ b/drivers/md/dm-raid1.c
33083 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33084
33085 struct mirror {
33086 struct mirror_set *ms;
33087 - atomic_t error_count;
33088 + atomic_unchecked_t error_count;
33089 unsigned long error_type;
33090 struct dm_dev *dev;
33091 sector_t offset;
33092 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33093 struct mirror *m;
33094
33095 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33096 - if (!atomic_read(&m->error_count))
33097 + if (!atomic_read_unchecked(&m->error_count))
33098 return m;
33099
33100 return NULL;
33101 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33102 * simple way to tell if a device has encountered
33103 * errors.
33104 */
33105 - atomic_inc(&m->error_count);
33106 + atomic_inc_unchecked(&m->error_count);
33107
33108 if (test_and_set_bit(error_type, &m->error_type))
33109 return;
33110 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33111 struct mirror *m = get_default_mirror(ms);
33112
33113 do {
33114 - if (likely(!atomic_read(&m->error_count)))
33115 + if (likely(!atomic_read_unchecked(&m->error_count)))
33116 return m;
33117
33118 if (m-- == ms->mirror)
33119 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33120 {
33121 struct mirror *default_mirror = get_default_mirror(m->ms);
33122
33123 - return !atomic_read(&default_mirror->error_count);
33124 + return !atomic_read_unchecked(&default_mirror->error_count);
33125 }
33126
33127 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33128 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33129 */
33130 if (likely(region_in_sync(ms, region, 1)))
33131 m = choose_mirror(ms, bio->bi_sector);
33132 - else if (m && atomic_read(&m->error_count))
33133 + else if (m && atomic_read_unchecked(&m->error_count))
33134 m = NULL;
33135
33136 if (likely(m))
33137 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33138 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33139 uint32_t region_size,
33140 struct dm_target *ti,
33141 + struct dm_dirty_log *dl) __size_overflow(1);
33142 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33143 + uint32_t region_size,
33144 + struct dm_target *ti,
33145 struct dm_dirty_log *dl)
33146 {
33147 size_t len;
33148 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33149 }
33150
33151 ms->mirror[mirror].ms = ms;
33152 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33153 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33154 ms->mirror[mirror].error_type = 0;
33155 ms->mirror[mirror].offset = offset;
33156
33157 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33158 */
33159 static char device_status_char(struct mirror *m)
33160 {
33161 - if (!atomic_read(&(m->error_count)))
33162 + if (!atomic_read_unchecked(&(m->error_count)))
33163 return 'A';
33164
33165 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33166 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33167 index 3d80cf0..7d98e1a 100644
33168 --- a/drivers/md/dm-stripe.c
33169 +++ b/drivers/md/dm-stripe.c
33170 @@ -20,7 +20,7 @@ struct stripe {
33171 struct dm_dev *dev;
33172 sector_t physical_start;
33173
33174 - atomic_t error_count;
33175 + atomic_unchecked_t error_count;
33176 };
33177
33178 struct stripe_c {
33179 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33180 dm_table_event(sc->ti->table);
33181 }
33182
33183 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
33184 static inline struct stripe_c *alloc_context(unsigned int stripes)
33185 {
33186 size_t len;
33187 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33188 kfree(sc);
33189 return r;
33190 }
33191 - atomic_set(&(sc->stripe[i].error_count), 0);
33192 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33193 }
33194
33195 ti->private = sc;
33196 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33197 DMEMIT("%d ", sc->stripes);
33198 for (i = 0; i < sc->stripes; i++) {
33199 DMEMIT("%s ", sc->stripe[i].dev->name);
33200 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33201 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33202 'D' : 'A';
33203 }
33204 buffer[i] = '\0';
33205 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33206 */
33207 for (i = 0; i < sc->stripes; i++)
33208 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33209 - atomic_inc(&(sc->stripe[i].error_count));
33210 - if (atomic_read(&(sc->stripe[i].error_count)) <
33211 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33212 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33213 DM_IO_ERROR_THRESHOLD)
33214 schedule_work(&sc->trigger_event);
33215 }
33216 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33217 index 63cc542..8d45caf3 100644
33218 --- a/drivers/md/dm-table.c
33219 +++ b/drivers/md/dm-table.c
33220 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33221 if (!dev_size)
33222 return 0;
33223
33224 - if ((start >= dev_size) || (start + len > dev_size)) {
33225 + if ((start >= dev_size) || (len > dev_size - start)) {
33226 DMWARN("%s: %s too small for target: "
33227 "start=%llu, len=%llu, dev_size=%llu",
33228 dm_device_name(ti->table->md), bdevname(bdev, b),
33229 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33230 index 237571a..fb6d19b 100644
33231 --- a/drivers/md/dm-thin-metadata.c
33232 +++ b/drivers/md/dm-thin-metadata.c
33233 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33234
33235 pmd->info.tm = tm;
33236 pmd->info.levels = 2;
33237 - pmd->info.value_type.context = pmd->data_sm;
33238 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33239 pmd->info.value_type.size = sizeof(__le64);
33240 pmd->info.value_type.inc = data_block_inc;
33241 pmd->info.value_type.dec = data_block_dec;
33242 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33243
33244 pmd->bl_info.tm = tm;
33245 pmd->bl_info.levels = 1;
33246 - pmd->bl_info.value_type.context = pmd->data_sm;
33247 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33248 pmd->bl_info.value_type.size = sizeof(__le64);
33249 pmd->bl_info.value_type.inc = data_block_inc;
33250 pmd->bl_info.value_type.dec = data_block_dec;
33251 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33252 index b89c548..2af3ce4 100644
33253 --- a/drivers/md/dm.c
33254 +++ b/drivers/md/dm.c
33255 @@ -176,9 +176,9 @@ struct mapped_device {
33256 /*
33257 * Event handling.
33258 */
33259 - atomic_t event_nr;
33260 + atomic_unchecked_t event_nr;
33261 wait_queue_head_t eventq;
33262 - atomic_t uevent_seq;
33263 + atomic_unchecked_t uevent_seq;
33264 struct list_head uevent_list;
33265 spinlock_t uevent_lock; /* Protect access to uevent_list */
33266
33267 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33268 rwlock_init(&md->map_lock);
33269 atomic_set(&md->holders, 1);
33270 atomic_set(&md->open_count, 0);
33271 - atomic_set(&md->event_nr, 0);
33272 - atomic_set(&md->uevent_seq, 0);
33273 + atomic_set_unchecked(&md->event_nr, 0);
33274 + atomic_set_unchecked(&md->uevent_seq, 0);
33275 INIT_LIST_HEAD(&md->uevent_list);
33276 spin_lock_init(&md->uevent_lock);
33277
33278 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33279
33280 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33281
33282 - atomic_inc(&md->event_nr);
33283 + atomic_inc_unchecked(&md->event_nr);
33284 wake_up(&md->eventq);
33285 }
33286
33287 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33288
33289 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33290 {
33291 - return atomic_add_return(1, &md->uevent_seq);
33292 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33293 }
33294
33295 uint32_t dm_get_event_nr(struct mapped_device *md)
33296 {
33297 - return atomic_read(&md->event_nr);
33298 + return atomic_read_unchecked(&md->event_nr);
33299 }
33300
33301 int dm_wait_event(struct mapped_device *md, int event_nr)
33302 {
33303 return wait_event_interruptible(md->eventq,
33304 - (event_nr != atomic_read(&md->event_nr)));
33305 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33306 }
33307
33308 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33309 diff --git a/drivers/md/md.c b/drivers/md/md.c
33310 index 6acc846..80a6b96 100644
33311 --- a/drivers/md/md.c
33312 +++ b/drivers/md/md.c
33313 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33314 * start build, activate spare
33315 */
33316 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33317 -static atomic_t md_event_count;
33318 +static atomic_unchecked_t md_event_count;
33319 void md_new_event(struct mddev *mddev)
33320 {
33321 - atomic_inc(&md_event_count);
33322 + atomic_inc_unchecked(&md_event_count);
33323 wake_up(&md_event_waiters);
33324 }
33325 EXPORT_SYMBOL_GPL(md_new_event);
33326 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33327 */
33328 static void md_new_event_inintr(struct mddev *mddev)
33329 {
33330 - atomic_inc(&md_event_count);
33331 + atomic_inc_unchecked(&md_event_count);
33332 wake_up(&md_event_waiters);
33333 }
33334
33335 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33336
33337 rdev->preferred_minor = 0xffff;
33338 rdev->data_offset = le64_to_cpu(sb->data_offset);
33339 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33340 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33341
33342 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33343 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33344 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33345 else
33346 sb->resync_offset = cpu_to_le64(0);
33347
33348 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33349 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33350
33351 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33352 sb->size = cpu_to_le64(mddev->dev_sectors);
33353 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33354 static ssize_t
33355 errors_show(struct md_rdev *rdev, char *page)
33356 {
33357 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33358 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33359 }
33360
33361 static ssize_t
33362 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33363 char *e;
33364 unsigned long n = simple_strtoul(buf, &e, 10);
33365 if (*buf && (*e == 0 || *e == '\n')) {
33366 - atomic_set(&rdev->corrected_errors, n);
33367 + atomic_set_unchecked(&rdev->corrected_errors, n);
33368 return len;
33369 }
33370 return -EINVAL;
33371 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
33372 rdev->sb_loaded = 0;
33373 rdev->bb_page = NULL;
33374 atomic_set(&rdev->nr_pending, 0);
33375 - atomic_set(&rdev->read_errors, 0);
33376 - atomic_set(&rdev->corrected_errors, 0);
33377 + atomic_set_unchecked(&rdev->read_errors, 0);
33378 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33379
33380 INIT_LIST_HEAD(&rdev->same_set);
33381 init_waitqueue_head(&rdev->blocked_wait);
33382 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33383
33384 spin_unlock(&pers_lock);
33385 seq_printf(seq, "\n");
33386 - seq->poll_event = atomic_read(&md_event_count);
33387 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33388 return 0;
33389 }
33390 if (v == (void*)2) {
33391 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33392 chunk_kb ? "KB" : "B");
33393 if (bitmap->file) {
33394 seq_printf(seq, ", file: ");
33395 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33396 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33397 }
33398
33399 seq_printf(seq, "\n");
33400 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33401 return error;
33402
33403 seq = file->private_data;
33404 - seq->poll_event = atomic_read(&md_event_count);
33405 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33406 return error;
33407 }
33408
33409 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33410 /* always allow read */
33411 mask = POLLIN | POLLRDNORM;
33412
33413 - if (seq->poll_event != atomic_read(&md_event_count))
33414 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33415 mask |= POLLERR | POLLPRI;
33416 return mask;
33417 }
33418 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33419 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33420 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33421 (int)part_stat_read(&disk->part0, sectors[1]) -
33422 - atomic_read(&disk->sync_io);
33423 + atomic_read_unchecked(&disk->sync_io);
33424 /* sync IO will cause sync_io to increase before the disk_stats
33425 * as sync_io is counted when a request starts, and
33426 * disk_stats is counted when it completes.
33427 diff --git a/drivers/md/md.h b/drivers/md/md.h
33428 index 44c63df..b795d1a 100644
33429 --- a/drivers/md/md.h
33430 +++ b/drivers/md/md.h
33431 @@ -93,13 +93,13 @@ struct md_rdev {
33432 * only maintained for arrays that
33433 * support hot removal
33434 */
33435 - atomic_t read_errors; /* number of consecutive read errors that
33436 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33437 * we have tried to ignore.
33438 */
33439 struct timespec last_read_error; /* monotonic time since our
33440 * last read error
33441 */
33442 - atomic_t corrected_errors; /* number of corrected read errors,
33443 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33444 * for reporting to userspace and storing
33445 * in superblock.
33446 */
33447 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33448
33449 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33450 {
33451 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33452 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33453 }
33454
33455 struct md_personality
33456 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33457 index 50ed53b..4f29d7d 100644
33458 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33459 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33460 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33461 /*----------------------------------------------------------------*/
33462
33463 struct sm_checker {
33464 - struct dm_space_map sm;
33465 + dm_space_map_no_const sm;
33466
33467 struct count_array old_counts;
33468 struct count_array counts;
33469 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33470 index fc469ba..2d91555 100644
33471 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33472 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33473 @@ -23,7 +23,7 @@
33474 * Space map interface.
33475 */
33476 struct sm_disk {
33477 - struct dm_space_map sm;
33478 + dm_space_map_no_const sm;
33479
33480 struct ll_disk ll;
33481 struct ll_disk old_ll;
33482 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33483 index e89ae5e..062e4c2 100644
33484 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33485 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33486 @@ -43,7 +43,7 @@ struct block_op {
33487 };
33488
33489 struct sm_metadata {
33490 - struct dm_space_map sm;
33491 + dm_space_map_no_const sm;
33492
33493 struct ll_disk ll;
33494 struct ll_disk old_ll;
33495 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33496 index 1cbfc6b..56e1dbb 100644
33497 --- a/drivers/md/persistent-data/dm-space-map.h
33498 +++ b/drivers/md/persistent-data/dm-space-map.h
33499 @@ -60,6 +60,7 @@ struct dm_space_map {
33500 int (*root_size)(struct dm_space_map *sm, size_t *result);
33501 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33502 };
33503 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33504
33505 /*----------------------------------------------------------------*/
33506
33507 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33508 index 118e0f6..210c4d7 100644
33509 --- a/drivers/md/raid1.c
33510 +++ b/drivers/md/raid1.c
33511 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33512 if (r1_sync_page_io(rdev, sect, s,
33513 bio->bi_io_vec[idx].bv_page,
33514 READ) != 0)
33515 - atomic_add(s, &rdev->corrected_errors);
33516 + atomic_add_unchecked(s, &rdev->corrected_errors);
33517 }
33518 sectors -= s;
33519 sect += s;
33520 @@ -1858,7 +1858,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33521 test_bit(In_sync, &rdev->flags)) {
33522 if (r1_sync_page_io(rdev, sect, s,
33523 conf->tmppage, READ)) {
33524 - atomic_add(s, &rdev->corrected_errors);
33525 + atomic_add_unchecked(s, &rdev->corrected_errors);
33526 printk(KERN_INFO
33527 "md/raid1:%s: read error corrected "
33528 "(%d sectors at %llu on %s)\n",
33529 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33530 index be7101d..f23ba30 100644
33531 --- a/drivers/md/raid10.c
33532 +++ b/drivers/md/raid10.c
33533 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33534 /* The write handler will notice the lack of
33535 * R10BIO_Uptodate and record any errors etc
33536 */
33537 - atomic_add(r10_bio->sectors,
33538 + atomic_add_unchecked(r10_bio->sectors,
33539 &conf->mirrors[d].rdev->corrected_errors);
33540
33541 /* for reconstruct, we always reschedule after a read.
33542 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33543 {
33544 struct timespec cur_time_mon;
33545 unsigned long hours_since_last;
33546 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33547 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33548
33549 ktime_get_ts(&cur_time_mon);
33550
33551 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33552 * overflowing the shift of read_errors by hours_since_last.
33553 */
33554 if (hours_since_last >= 8 * sizeof(read_errors))
33555 - atomic_set(&rdev->read_errors, 0);
33556 + atomic_set_unchecked(&rdev->read_errors, 0);
33557 else
33558 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33559 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33560 }
33561
33562 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33563 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33564 return;
33565
33566 check_decay_read_errors(mddev, rdev);
33567 - atomic_inc(&rdev->read_errors);
33568 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33569 + atomic_inc_unchecked(&rdev->read_errors);
33570 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33571 char b[BDEVNAME_SIZE];
33572 bdevname(rdev->bdev, b);
33573
33574 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33575 "md/raid10:%s: %s: Raid device exceeded "
33576 "read_error threshold [cur %d:max %d]\n",
33577 mdname(mddev), b,
33578 - atomic_read(&rdev->read_errors), max_read_errors);
33579 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33580 printk(KERN_NOTICE
33581 "md/raid10:%s: %s: Failing raid device\n",
33582 mdname(mddev), b);
33583 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33584 (unsigned long long)(
33585 sect + rdev->data_offset),
33586 bdevname(rdev->bdev, b));
33587 - atomic_add(s, &rdev->corrected_errors);
33588 + atomic_add_unchecked(s, &rdev->corrected_errors);
33589 }
33590
33591 rdev_dec_pending(rdev, mddev);
33592 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33593 index 360f2b9..08b5382 100644
33594 --- a/drivers/md/raid5.c
33595 +++ b/drivers/md/raid5.c
33596 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33597 (unsigned long long)(sh->sector
33598 + rdev->data_offset),
33599 bdevname(rdev->bdev, b));
33600 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33601 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33602 clear_bit(R5_ReadError, &sh->dev[i].flags);
33603 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33604 }
33605 - if (atomic_read(&rdev->read_errors))
33606 - atomic_set(&rdev->read_errors, 0);
33607 + if (atomic_read_unchecked(&rdev->read_errors))
33608 + atomic_set_unchecked(&rdev->read_errors, 0);
33609 } else {
33610 const char *bdn = bdevname(rdev->bdev, b);
33611 int retry = 0;
33612
33613 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33614 - atomic_inc(&rdev->read_errors);
33615 + atomic_inc_unchecked(&rdev->read_errors);
33616 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33617 printk_ratelimited(
33618 KERN_WARNING
33619 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33620 (unsigned long long)(sh->sector
33621 + rdev->data_offset),
33622 bdn);
33623 - else if (atomic_read(&rdev->read_errors)
33624 + else if (atomic_read_unchecked(&rdev->read_errors)
33625 > conf->max_nr_stripes)
33626 printk(KERN_WARNING
33627 "md/raid:%s: Too many read errors, failing device %s.\n",
33628 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33629 index ce4f858..7bcfb46 100644
33630 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33631 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33632 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33633 .subvendor = _subvend, .subdevice = _subdev, \
33634 .driver_data = (unsigned long)&_driverdata }
33635
33636 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33637 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33638 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33639 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33640 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33641 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33642 index a7d876f..8c21b61 100644
33643 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33644 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33645 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33646 union {
33647 dmx_ts_cb ts;
33648 dmx_section_cb sec;
33649 - } cb;
33650 + } __no_const cb;
33651
33652 struct dvb_demux *demux;
33653 void *priv;
33654 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33655 index 00a6732..70a682e 100644
33656 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33657 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33658 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33659 const struct dvb_device *template, void *priv, int type)
33660 {
33661 struct dvb_device *dvbdev;
33662 - struct file_operations *dvbdevfops;
33663 + file_operations_no_const *dvbdevfops;
33664 struct device *clsdev;
33665 int minor;
33666 int id;
33667 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33668 index 3940bb0..fb3952a 100644
33669 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33670 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33671 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33672
33673 struct dib0700_adapter_state {
33674 int (*set_param_save) (struct dvb_frontend *);
33675 -};
33676 +} __no_const;
33677
33678 static int dib7070_set_param_override(struct dvb_frontend *fe)
33679 {
33680 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33681 index 451c5a7..649f711 100644
33682 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33683 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33684 @@ -95,7 +95,7 @@ struct su3000_state {
33685
33686 struct s6x0_state {
33687 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33688 -};
33689 +} __no_const;
33690
33691 /* debug */
33692 static int dvb_usb_dw2102_debug;
33693 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33694 index 404f63a..4796533 100644
33695 --- a/drivers/media/dvb/frontends/dib3000.h
33696 +++ b/drivers/media/dvb/frontends/dib3000.h
33697 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33698 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33699 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33700 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33701 -};
33702 +} __no_const;
33703
33704 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33705 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33706 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33707 index 8418c02..8555013 100644
33708 --- a/drivers/media/dvb/ngene/ngene-cards.c
33709 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33710 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33711
33712 /****************************************************************************/
33713
33714 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33715 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33716 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33717 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33718 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33719 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33720 index 16a089f..ab1667d 100644
33721 --- a/drivers/media/radio/radio-cadet.c
33722 +++ b/drivers/media/radio/radio-cadet.c
33723 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33724 unsigned char readbuf[RDS_BUFFER];
33725 int i = 0;
33726
33727 + if (count > RDS_BUFFER)
33728 + return -EFAULT;
33729 mutex_lock(&dev->lock);
33730 if (dev->rdsstat == 0) {
33731 dev->rdsstat = 1;
33732 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33733 index 9cde353..8c6a1c3 100644
33734 --- a/drivers/media/video/au0828/au0828.h
33735 +++ b/drivers/media/video/au0828/au0828.h
33736 @@ -191,7 +191,7 @@ struct au0828_dev {
33737
33738 /* I2C */
33739 struct i2c_adapter i2c_adap;
33740 - struct i2c_algorithm i2c_algo;
33741 + i2c_algorithm_no_const i2c_algo;
33742 struct i2c_client i2c_client;
33743 u32 i2c_rc;
33744
33745 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
33746 index ee91e295..04ad048 100644
33747 --- a/drivers/media/video/cpia2/cpia2_core.c
33748 +++ b/drivers/media/video/cpia2/cpia2_core.c
33749 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
33750 return ret;
33751 }
33752
33753 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33754 static void *rvmalloc(unsigned long size)
33755 {
33756 void *mem;
33757 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
33758 index 82d195b..181103c 100644
33759 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
33760 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
33761 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
33762
33763
33764 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33765 + size_t size) __size_overflow(2);
33766 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33767 size_t size)
33768 {
33769 struct snd_pcm_runtime *runtime = subs->runtime;
33770 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
33771 index a2c2b7d..8f1bec7 100644
33772 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
33773 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
33774 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
33775 }
33776
33777 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33778 + size_t size) __size_overflow(2);
33779 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33780 size_t size)
33781 {
33782 struct snd_pcm_runtime *runtime = subs->runtime;
33783 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33784 index 04bf662..e0ac026 100644
33785 --- a/drivers/media/video/cx88/cx88-alsa.c
33786 +++ b/drivers/media/video/cx88/cx88-alsa.c
33787 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33788 * Only boards with eeprom and byte 1 at eeprom=1 have it
33789 */
33790
33791 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33792 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33793 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33794 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33795 {0, }
33796 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
33797 index e2a7b77..753d0ee 100644
33798 --- a/drivers/media/video/em28xx/em28xx-audio.c
33799 +++ b/drivers/media/video/em28xx/em28xx-audio.c
33800 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
33801 }
33802
33803 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33804 + size_t size) __size_overflow(2);
33805 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33806 size_t size)
33807 {
33808 struct snd_pcm_runtime *runtime = subs->runtime;
33809 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
33810 index b09a3c8..6dcba0a 100644
33811 --- a/drivers/media/video/meye.c
33812 +++ b/drivers/media/video/meye.c
33813 @@ -72,6 +72,7 @@ static struct meye meye;
33814 /****************************************************************************/
33815 /* Memory allocation routines (stolen from bttv-driver.c) */
33816 /****************************************************************************/
33817 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33818 static void *rvmalloc(unsigned long size)
33819 {
33820 void *mem;
33821 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33822 index 1fb7d5b..3901e77 100644
33823 --- a/drivers/media/video/omap/omap_vout.c
33824 +++ b/drivers/media/video/omap/omap_vout.c
33825 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33826 OMAP_VIDEO2,
33827 };
33828
33829 -static struct videobuf_queue_ops video_vbq_ops;
33830 /* Variables configurable through module params*/
33831 static u32 video1_numbuffers = 3;
33832 static u32 video2_numbuffers = 3;
33833 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33834 {
33835 struct videobuf_queue *q;
33836 struct omap_vout_device *vout = NULL;
33837 + static struct videobuf_queue_ops video_vbq_ops = {
33838 + .buf_setup = omap_vout_buffer_setup,
33839 + .buf_prepare = omap_vout_buffer_prepare,
33840 + .buf_release = omap_vout_buffer_release,
33841 + .buf_queue = omap_vout_buffer_queue,
33842 + };
33843
33844 vout = video_drvdata(file);
33845 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33846 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33847 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33848
33849 q = &vout->vbq;
33850 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33851 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33852 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33853 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33854 spin_lock_init(&vout->vbq_lock);
33855
33856 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33857 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33858 index 305e6aa..0143317 100644
33859 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33860 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33861 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33862
33863 /* I2C stuff */
33864 struct i2c_adapter i2c_adap;
33865 - struct i2c_algorithm i2c_algo;
33866 + i2c_algorithm_no_const i2c_algo;
33867 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33868 int i2c_cx25840_hack_state;
33869 int i2c_linked;
33870 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
33871 index 2fd38a0..ddec3c4 100644
33872 --- a/drivers/media/video/saa7164/saa7164-encoder.c
33873 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
33874 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
33875 }
33876
33877 static ssize_t fops_read(struct file *file, char __user *buffer,
33878 + size_t count, loff_t *pos) __size_overflow(3);
33879 +static ssize_t fops_read(struct file *file, char __user *buffer,
33880 size_t count, loff_t *pos)
33881 {
33882 struct saa7164_encoder_fh *fh = file->private_data;
33883 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
33884 index e2e0341..b80056c 100644
33885 --- a/drivers/media/video/saa7164/saa7164-vbi.c
33886 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
33887 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
33888 }
33889
33890 static ssize_t fops_read(struct file *file, char __user *buffer,
33891 + size_t count, loff_t *pos) __size_overflow(3);
33892 +static ssize_t fops_read(struct file *file, char __user *buffer,
33893 size_t count, loff_t *pos)
33894 {
33895 struct saa7164_vbi_fh *fh = file->private_data;
33896 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33897 index 4ed1c7c2..8f15e13 100644
33898 --- a/drivers/media/video/timblogiw.c
33899 +++ b/drivers/media/video/timblogiw.c
33900 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33901
33902 /* Platform device functions */
33903
33904 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33905 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33906 .vidioc_querycap = timblogiw_querycap,
33907 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33908 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33909 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33910 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33911 };
33912
33913 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33914 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33915 .owner = THIS_MODULE,
33916 .open = timblogiw_open,
33917 .release = timblogiw_close,
33918 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
33919 index c969111..a7910f4 100644
33920 --- a/drivers/media/video/videobuf-dma-contig.c
33921 +++ b/drivers/media/video/videobuf-dma-contig.c
33922 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
33923 return ret;
33924 }
33925
33926 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33927 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33928 {
33929 struct videobuf_dma_contig_memory *mem;
33930 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
33931 index f300dea..5fc9c4a 100644
33932 --- a/drivers/media/video/videobuf-dma-sg.c
33933 +++ b/drivers/media/video/videobuf-dma-sg.c
33934 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33935 struct videobuf_dma_sg_memory
33936 */
33937
33938 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33939 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33940 {
33941 struct videobuf_dma_sg_memory *mem;
33942 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
33943 index df14258..12cc7a3 100644
33944 --- a/drivers/media/video/videobuf-vmalloc.c
33945 +++ b/drivers/media/video/videobuf-vmalloc.c
33946 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33947 struct videobuf_dma_sg_memory
33948 */
33949
33950 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33951 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33952 {
33953 struct videobuf_vmalloc_memory *mem;
33954 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33955 index a7dc467..a55c423 100644
33956 --- a/drivers/message/fusion/mptbase.c
33957 +++ b/drivers/message/fusion/mptbase.c
33958 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33959 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33960 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33961
33962 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33963 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33964 +#else
33965 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33966 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33967 +#endif
33968 +
33969 /*
33970 * Rounding UP to nearest 4-kB boundary here...
33971 */
33972 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33973 index 551262e..7551198 100644
33974 --- a/drivers/message/fusion/mptsas.c
33975 +++ b/drivers/message/fusion/mptsas.c
33976 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33977 return 0;
33978 }
33979
33980 +static inline void
33981 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33982 +{
33983 + if (phy_info->port_details) {
33984 + phy_info->port_details->rphy = rphy;
33985 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33986 + ioc->name, rphy));
33987 + }
33988 +
33989 + if (rphy) {
33990 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33991 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33992 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33993 + ioc->name, rphy, rphy->dev.release));
33994 + }
33995 +}
33996 +
33997 /* no mutex */
33998 static void
33999 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34000 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34001 return NULL;
34002 }
34003
34004 -static inline void
34005 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34006 -{
34007 - if (phy_info->port_details) {
34008 - phy_info->port_details->rphy = rphy;
34009 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34010 - ioc->name, rphy));
34011 - }
34012 -
34013 - if (rphy) {
34014 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34015 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34016 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34017 - ioc->name, rphy, rphy->dev.release));
34018 - }
34019 -}
34020 -
34021 static inline struct sas_port *
34022 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34023 {
34024 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34025 index 0c3ced7..1fe34ec 100644
34026 --- a/drivers/message/fusion/mptscsih.c
34027 +++ b/drivers/message/fusion/mptscsih.c
34028 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34029
34030 h = shost_priv(SChost);
34031
34032 - if (h) {
34033 - if (h->info_kbuf == NULL)
34034 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34035 - return h->info_kbuf;
34036 - h->info_kbuf[0] = '\0';
34037 + if (!h)
34038 + return NULL;
34039
34040 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34041 - h->info_kbuf[size-1] = '\0';
34042 - }
34043 + if (h->info_kbuf == NULL)
34044 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34045 + return h->info_kbuf;
34046 + h->info_kbuf[0] = '\0';
34047 +
34048 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34049 + h->info_kbuf[size-1] = '\0';
34050
34051 return h->info_kbuf;
34052 }
34053 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34054 index 6d115c7..58ff7fd 100644
34055 --- a/drivers/message/i2o/i2o_proc.c
34056 +++ b/drivers/message/i2o/i2o_proc.c
34057 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34058 "Array Controller Device"
34059 };
34060
34061 -static char *chtostr(u8 * chars, int n)
34062 -{
34063 - char tmp[256];
34064 - tmp[0] = 0;
34065 - return strncat(tmp, (char *)chars, n);
34066 -}
34067 -
34068 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34069 char *group)
34070 {
34071 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34072
34073 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34074 seq_printf(seq, "%-#8x", ddm_table.module_id);
34075 - seq_printf(seq, "%-29s",
34076 - chtostr(ddm_table.module_name_version, 28));
34077 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34078 seq_printf(seq, "%9d ", ddm_table.data_size);
34079 seq_printf(seq, "%8d", ddm_table.code_size);
34080
34081 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34082
34083 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34084 seq_printf(seq, "%-#8x", dst->module_id);
34085 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34086 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34087 + seq_printf(seq, "%-.28s", dst->module_name_version);
34088 + seq_printf(seq, "%-.8s", dst->date);
34089 seq_printf(seq, "%8d ", dst->module_size);
34090 seq_printf(seq, "%8d ", dst->mpb_size);
34091 seq_printf(seq, "0x%04x", dst->module_flags);
34092 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34093 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34094 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34095 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34096 - seq_printf(seq, "Vendor info : %s\n",
34097 - chtostr((u8 *) (work32 + 2), 16));
34098 - seq_printf(seq, "Product info : %s\n",
34099 - chtostr((u8 *) (work32 + 6), 16));
34100 - seq_printf(seq, "Description : %s\n",
34101 - chtostr((u8 *) (work32 + 10), 16));
34102 - seq_printf(seq, "Product rev. : %s\n",
34103 - chtostr((u8 *) (work32 + 14), 8));
34104 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34105 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34106 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34107 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34108
34109 seq_printf(seq, "Serial number : ");
34110 print_serial_number(seq, (u8 *) (work32 + 16),
34111 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34112 }
34113
34114 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34115 - seq_printf(seq, "Module name : %s\n",
34116 - chtostr(result.module_name, 24));
34117 - seq_printf(seq, "Module revision : %s\n",
34118 - chtostr(result.module_rev, 8));
34119 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34120 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34121
34122 seq_printf(seq, "Serial number : ");
34123 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34124 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34125 return 0;
34126 }
34127
34128 - seq_printf(seq, "Device name : %s\n",
34129 - chtostr(result.device_name, 64));
34130 - seq_printf(seq, "Service name : %s\n",
34131 - chtostr(result.service_name, 64));
34132 - seq_printf(seq, "Physical name : %s\n",
34133 - chtostr(result.physical_location, 64));
34134 - seq_printf(seq, "Instance number : %s\n",
34135 - chtostr(result.instance_number, 4));
34136 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34137 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34138 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34139 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34140
34141 return 0;
34142 }
34143 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34144 index a8c08f3..155fe3d 100644
34145 --- a/drivers/message/i2o/iop.c
34146 +++ b/drivers/message/i2o/iop.c
34147 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34148
34149 spin_lock_irqsave(&c->context_list_lock, flags);
34150
34151 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34152 - atomic_inc(&c->context_list_counter);
34153 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34154 + atomic_inc_unchecked(&c->context_list_counter);
34155
34156 - entry->context = atomic_read(&c->context_list_counter);
34157 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34158
34159 list_add(&entry->list, &c->context_list);
34160
34161 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34162
34163 #if BITS_PER_LONG == 64
34164 spin_lock_init(&c->context_list_lock);
34165 - atomic_set(&c->context_list_counter, 0);
34166 + atomic_set_unchecked(&c->context_list_counter, 0);
34167 INIT_LIST_HEAD(&c->context_list);
34168 #endif
34169
34170 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34171 index 7ce65f4..e66e9bc 100644
34172 --- a/drivers/mfd/abx500-core.c
34173 +++ b/drivers/mfd/abx500-core.c
34174 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34175
34176 struct abx500_device_entry {
34177 struct list_head list;
34178 - struct abx500_ops ops;
34179 + abx500_ops_no_const ops;
34180 struct device *dev;
34181 };
34182
34183 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34184 index a9223ed..4127b13 100644
34185 --- a/drivers/mfd/janz-cmodio.c
34186 +++ b/drivers/mfd/janz-cmodio.c
34187 @@ -13,6 +13,7 @@
34188
34189 #include <linux/kernel.h>
34190 #include <linux/module.h>
34191 +#include <linux/slab.h>
34192 #include <linux/init.h>
34193 #include <linux/pci.h>
34194 #include <linux/interrupt.h>
34195 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34196 index a981e2a..5ca0c8b 100644
34197 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34198 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34199 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34200 * the lid is closed. This leads to interrupts as soon as a little move
34201 * is done.
34202 */
34203 - atomic_inc(&lis3->count);
34204 + atomic_inc_unchecked(&lis3->count);
34205
34206 wake_up_interruptible(&lis3->misc_wait);
34207 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34208 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34209 if (lis3->pm_dev)
34210 pm_runtime_get_sync(lis3->pm_dev);
34211
34212 - atomic_set(&lis3->count, 0);
34213 + atomic_set_unchecked(&lis3->count, 0);
34214 return 0;
34215 }
34216
34217 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34218 add_wait_queue(&lis3->misc_wait, &wait);
34219 while (true) {
34220 set_current_state(TASK_INTERRUPTIBLE);
34221 - data = atomic_xchg(&lis3->count, 0);
34222 + data = atomic_xchg_unchecked(&lis3->count, 0);
34223 if (data)
34224 break;
34225
34226 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34227 struct lis3lv02d, miscdev);
34228
34229 poll_wait(file, &lis3->misc_wait, wait);
34230 - if (atomic_read(&lis3->count))
34231 + if (atomic_read_unchecked(&lis3->count))
34232 return POLLIN | POLLRDNORM;
34233 return 0;
34234 }
34235 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34236 index 2b1482a..5d33616 100644
34237 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34238 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34239 @@ -266,7 +266,7 @@ struct lis3lv02d {
34240 struct input_polled_dev *idev; /* input device */
34241 struct platform_device *pdev; /* platform device */
34242 struct regulator_bulk_data regulators[2];
34243 - atomic_t count; /* interrupt count after last read */
34244 + atomic_unchecked_t count; /* interrupt count after last read */
34245 union axis_conversion ac; /* hw -> logical axis */
34246 int mapped_btns[3];
34247
34248 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34249 index 2f30bad..c4c13d0 100644
34250 --- a/drivers/misc/sgi-gru/gruhandles.c
34251 +++ b/drivers/misc/sgi-gru/gruhandles.c
34252 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34253 unsigned long nsec;
34254
34255 nsec = CLKS2NSEC(clks);
34256 - atomic_long_inc(&mcs_op_statistics[op].count);
34257 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34258 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34259 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34260 if (mcs_op_statistics[op].max < nsec)
34261 mcs_op_statistics[op].max = nsec;
34262 }
34263 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34264 index 950dbe9..eeef0f8 100644
34265 --- a/drivers/misc/sgi-gru/gruprocfs.c
34266 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34267 @@ -32,9 +32,9 @@
34268
34269 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34270
34271 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34272 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34273 {
34274 - unsigned long val = atomic_long_read(v);
34275 + unsigned long val = atomic_long_read_unchecked(v);
34276
34277 seq_printf(s, "%16lu %s\n", val, id);
34278 }
34279 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34280
34281 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34282 for (op = 0; op < mcsop_last; op++) {
34283 - count = atomic_long_read(&mcs_op_statistics[op].count);
34284 - total = atomic_long_read(&mcs_op_statistics[op].total);
34285 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34286 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34287 max = mcs_op_statistics[op].max;
34288 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34289 count ? total / count : 0, max);
34290 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34291 index 5c3ce24..4915ccb 100644
34292 --- a/drivers/misc/sgi-gru/grutables.h
34293 +++ b/drivers/misc/sgi-gru/grutables.h
34294 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34295 * GRU statistics.
34296 */
34297 struct gru_stats_s {
34298 - atomic_long_t vdata_alloc;
34299 - atomic_long_t vdata_free;
34300 - atomic_long_t gts_alloc;
34301 - atomic_long_t gts_free;
34302 - atomic_long_t gms_alloc;
34303 - atomic_long_t gms_free;
34304 - atomic_long_t gts_double_allocate;
34305 - atomic_long_t assign_context;
34306 - atomic_long_t assign_context_failed;
34307 - atomic_long_t free_context;
34308 - atomic_long_t load_user_context;
34309 - atomic_long_t load_kernel_context;
34310 - atomic_long_t lock_kernel_context;
34311 - atomic_long_t unlock_kernel_context;
34312 - atomic_long_t steal_user_context;
34313 - atomic_long_t steal_kernel_context;
34314 - atomic_long_t steal_context_failed;
34315 - atomic_long_t nopfn;
34316 - atomic_long_t asid_new;
34317 - atomic_long_t asid_next;
34318 - atomic_long_t asid_wrap;
34319 - atomic_long_t asid_reuse;
34320 - atomic_long_t intr;
34321 - atomic_long_t intr_cbr;
34322 - atomic_long_t intr_tfh;
34323 - atomic_long_t intr_spurious;
34324 - atomic_long_t intr_mm_lock_failed;
34325 - atomic_long_t call_os;
34326 - atomic_long_t call_os_wait_queue;
34327 - atomic_long_t user_flush_tlb;
34328 - atomic_long_t user_unload_context;
34329 - atomic_long_t user_exception;
34330 - atomic_long_t set_context_option;
34331 - atomic_long_t check_context_retarget_intr;
34332 - atomic_long_t check_context_unload;
34333 - atomic_long_t tlb_dropin;
34334 - atomic_long_t tlb_preload_page;
34335 - atomic_long_t tlb_dropin_fail_no_asid;
34336 - atomic_long_t tlb_dropin_fail_upm;
34337 - atomic_long_t tlb_dropin_fail_invalid;
34338 - atomic_long_t tlb_dropin_fail_range_active;
34339 - atomic_long_t tlb_dropin_fail_idle;
34340 - atomic_long_t tlb_dropin_fail_fmm;
34341 - atomic_long_t tlb_dropin_fail_no_exception;
34342 - atomic_long_t tfh_stale_on_fault;
34343 - atomic_long_t mmu_invalidate_range;
34344 - atomic_long_t mmu_invalidate_page;
34345 - atomic_long_t flush_tlb;
34346 - atomic_long_t flush_tlb_gru;
34347 - atomic_long_t flush_tlb_gru_tgh;
34348 - atomic_long_t flush_tlb_gru_zero_asid;
34349 + atomic_long_unchecked_t vdata_alloc;
34350 + atomic_long_unchecked_t vdata_free;
34351 + atomic_long_unchecked_t gts_alloc;
34352 + atomic_long_unchecked_t gts_free;
34353 + atomic_long_unchecked_t gms_alloc;
34354 + atomic_long_unchecked_t gms_free;
34355 + atomic_long_unchecked_t gts_double_allocate;
34356 + atomic_long_unchecked_t assign_context;
34357 + atomic_long_unchecked_t assign_context_failed;
34358 + atomic_long_unchecked_t free_context;
34359 + atomic_long_unchecked_t load_user_context;
34360 + atomic_long_unchecked_t load_kernel_context;
34361 + atomic_long_unchecked_t lock_kernel_context;
34362 + atomic_long_unchecked_t unlock_kernel_context;
34363 + atomic_long_unchecked_t steal_user_context;
34364 + atomic_long_unchecked_t steal_kernel_context;
34365 + atomic_long_unchecked_t steal_context_failed;
34366 + atomic_long_unchecked_t nopfn;
34367 + atomic_long_unchecked_t asid_new;
34368 + atomic_long_unchecked_t asid_next;
34369 + atomic_long_unchecked_t asid_wrap;
34370 + atomic_long_unchecked_t asid_reuse;
34371 + atomic_long_unchecked_t intr;
34372 + atomic_long_unchecked_t intr_cbr;
34373 + atomic_long_unchecked_t intr_tfh;
34374 + atomic_long_unchecked_t intr_spurious;
34375 + atomic_long_unchecked_t intr_mm_lock_failed;
34376 + atomic_long_unchecked_t call_os;
34377 + atomic_long_unchecked_t call_os_wait_queue;
34378 + atomic_long_unchecked_t user_flush_tlb;
34379 + atomic_long_unchecked_t user_unload_context;
34380 + atomic_long_unchecked_t user_exception;
34381 + atomic_long_unchecked_t set_context_option;
34382 + atomic_long_unchecked_t check_context_retarget_intr;
34383 + atomic_long_unchecked_t check_context_unload;
34384 + atomic_long_unchecked_t tlb_dropin;
34385 + atomic_long_unchecked_t tlb_preload_page;
34386 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34387 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34388 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34389 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34390 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34391 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34392 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34393 + atomic_long_unchecked_t tfh_stale_on_fault;
34394 + atomic_long_unchecked_t mmu_invalidate_range;
34395 + atomic_long_unchecked_t mmu_invalidate_page;
34396 + atomic_long_unchecked_t flush_tlb;
34397 + atomic_long_unchecked_t flush_tlb_gru;
34398 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34399 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34400
34401 - atomic_long_t copy_gpa;
34402 - atomic_long_t read_gpa;
34403 + atomic_long_unchecked_t copy_gpa;
34404 + atomic_long_unchecked_t read_gpa;
34405
34406 - atomic_long_t mesq_receive;
34407 - atomic_long_t mesq_receive_none;
34408 - atomic_long_t mesq_send;
34409 - atomic_long_t mesq_send_failed;
34410 - atomic_long_t mesq_noop;
34411 - atomic_long_t mesq_send_unexpected_error;
34412 - atomic_long_t mesq_send_lb_overflow;
34413 - atomic_long_t mesq_send_qlimit_reached;
34414 - atomic_long_t mesq_send_amo_nacked;
34415 - atomic_long_t mesq_send_put_nacked;
34416 - atomic_long_t mesq_page_overflow;
34417 - atomic_long_t mesq_qf_locked;
34418 - atomic_long_t mesq_qf_noop_not_full;
34419 - atomic_long_t mesq_qf_switch_head_failed;
34420 - atomic_long_t mesq_qf_unexpected_error;
34421 - atomic_long_t mesq_noop_unexpected_error;
34422 - atomic_long_t mesq_noop_lb_overflow;
34423 - atomic_long_t mesq_noop_qlimit_reached;
34424 - atomic_long_t mesq_noop_amo_nacked;
34425 - atomic_long_t mesq_noop_put_nacked;
34426 - atomic_long_t mesq_noop_page_overflow;
34427 + atomic_long_unchecked_t mesq_receive;
34428 + atomic_long_unchecked_t mesq_receive_none;
34429 + atomic_long_unchecked_t mesq_send;
34430 + atomic_long_unchecked_t mesq_send_failed;
34431 + atomic_long_unchecked_t mesq_noop;
34432 + atomic_long_unchecked_t mesq_send_unexpected_error;
34433 + atomic_long_unchecked_t mesq_send_lb_overflow;
34434 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34435 + atomic_long_unchecked_t mesq_send_amo_nacked;
34436 + atomic_long_unchecked_t mesq_send_put_nacked;
34437 + atomic_long_unchecked_t mesq_page_overflow;
34438 + atomic_long_unchecked_t mesq_qf_locked;
34439 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34440 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34441 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34442 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34443 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34444 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34445 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34446 + atomic_long_unchecked_t mesq_noop_put_nacked;
34447 + atomic_long_unchecked_t mesq_noop_page_overflow;
34448
34449 };
34450
34451 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34452 tghop_invalidate, mcsop_last};
34453
34454 struct mcs_op_statistic {
34455 - atomic_long_t count;
34456 - atomic_long_t total;
34457 + atomic_long_unchecked_t count;
34458 + atomic_long_unchecked_t total;
34459 unsigned long max;
34460 };
34461
34462 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34463
34464 #define STAT(id) do { \
34465 if (gru_options & OPT_STATS) \
34466 - atomic_long_inc(&gru_stats.id); \
34467 + atomic_long_inc_unchecked(&gru_stats.id); \
34468 } while (0)
34469
34470 #ifdef CONFIG_SGI_GRU_DEBUG
34471 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34472 index 851b2f2..a4ec097 100644
34473 --- a/drivers/misc/sgi-xp/xp.h
34474 +++ b/drivers/misc/sgi-xp/xp.h
34475 @@ -289,7 +289,7 @@ struct xpc_interface {
34476 xpc_notify_func, void *);
34477 void (*received) (short, int, void *);
34478 enum xp_retval (*partid_to_nasids) (short, void *);
34479 -};
34480 +} __no_const;
34481
34482 extern struct xpc_interface xpc_interface;
34483
34484 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34485 index b94d5f7..7f494c5 100644
34486 --- a/drivers/misc/sgi-xp/xpc.h
34487 +++ b/drivers/misc/sgi-xp/xpc.h
34488 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34489 void (*received_payload) (struct xpc_channel *, void *);
34490 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34491 };
34492 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34493
34494 /* struct xpc_partition act_state values (for XPC HB) */
34495
34496 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34497 /* found in xpc_main.c */
34498 extern struct device *xpc_part;
34499 extern struct device *xpc_chan;
34500 -extern struct xpc_arch_operations xpc_arch_ops;
34501 +extern xpc_arch_operations_no_const xpc_arch_ops;
34502 extern int xpc_disengage_timelimit;
34503 extern int xpc_disengage_timedout;
34504 extern int xpc_activate_IRQ_rcvd;
34505 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34506 index 8d082b4..aa749ae 100644
34507 --- a/drivers/misc/sgi-xp/xpc_main.c
34508 +++ b/drivers/misc/sgi-xp/xpc_main.c
34509 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34510 .notifier_call = xpc_system_die,
34511 };
34512
34513 -struct xpc_arch_operations xpc_arch_ops;
34514 +xpc_arch_operations_no_const xpc_arch_ops;
34515
34516 /*
34517 * Timer function to enforce the timelimit on the partition disengage.
34518 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34519 index 6ebdc40..9edf5d8 100644
34520 --- a/drivers/mmc/host/sdhci-pci.c
34521 +++ b/drivers/mmc/host/sdhci-pci.c
34522 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34523 .probe = via_probe,
34524 };
34525
34526 -static const struct pci_device_id pci_ids[] __devinitdata = {
34527 +static const struct pci_device_id pci_ids[] __devinitconst = {
34528 {
34529 .vendor = PCI_VENDOR_ID_RICOH,
34530 .device = PCI_DEVICE_ID_RICOH_R5C822,
34531 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34532 index b1cdf64..ce6e438 100644
34533 --- a/drivers/mtd/devices/doc2000.c
34534 +++ b/drivers/mtd/devices/doc2000.c
34535 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34536
34537 /* The ECC will not be calculated correctly if less than 512 is written */
34538 /* DBB-
34539 - if (len != 0x200 && eccbuf)
34540 + if (len != 0x200)
34541 printk(KERN_WARNING
34542 "ECC needs a full sector write (adr: %lx size %lx)\n",
34543 (long) to, (long) len);
34544 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34545 index 7543b98..7069947 100644
34546 --- a/drivers/mtd/devices/doc2001.c
34547 +++ b/drivers/mtd/devices/doc2001.c
34548 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34549 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34550
34551 /* Don't allow read past end of device */
34552 - if (from >= this->totlen)
34553 + if (from >= this->totlen || !len)
34554 return -EINVAL;
34555
34556 /* Don't allow a single read to cross a 512-byte block boundary */
34557 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34558 index 3984d48..28aa897 100644
34559 --- a/drivers/mtd/nand/denali.c
34560 +++ b/drivers/mtd/nand/denali.c
34561 @@ -26,6 +26,7 @@
34562 #include <linux/pci.h>
34563 #include <linux/mtd/mtd.h>
34564 #include <linux/module.h>
34565 +#include <linux/slab.h>
34566
34567 #include "denali.h"
34568
34569 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34570 index 51b9d6a..52af9a7 100644
34571 --- a/drivers/mtd/nftlmount.c
34572 +++ b/drivers/mtd/nftlmount.c
34573 @@ -24,6 +24,7 @@
34574 #include <asm/errno.h>
34575 #include <linux/delay.h>
34576 #include <linux/slab.h>
34577 +#include <linux/sched.h>
34578 #include <linux/mtd/mtd.h>
34579 #include <linux/mtd/nand.h>
34580 #include <linux/mtd/nftl.h>
34581 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34582 index e2cdebf..d48183a 100644
34583 --- a/drivers/mtd/ubi/debug.c
34584 +++ b/drivers/mtd/ubi/debug.c
34585 @@ -338,6 +338,8 @@ out:
34586
34587 /* Write an UBI debugfs file */
34588 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34589 + size_t count, loff_t *ppos) __size_overflow(3);
34590 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34591 size_t count, loff_t *ppos)
34592 {
34593 unsigned long ubi_num = (unsigned long)file->private_data;
34594 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34595 index 071f4c8..440862e 100644
34596 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34597 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34598 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34599 */
34600
34601 #define ATL2_PARAM(X, desc) \
34602 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34603 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34604 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34605 MODULE_PARM_DESC(X, desc);
34606 #else
34607 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34608 index 66da39f..5dc436d 100644
34609 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34610 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34611 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34612
34613 int (*wait_comp)(struct bnx2x *bp,
34614 struct bnx2x_rx_mode_ramrod_params *p);
34615 -};
34616 +} __no_const;
34617
34618 /********************** Set multicast group ***********************************/
34619
34620 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34621 index aea8f72..fcebf75 100644
34622 --- a/drivers/net/ethernet/broadcom/tg3.h
34623 +++ b/drivers/net/ethernet/broadcom/tg3.h
34624 @@ -140,6 +140,7 @@
34625 #define CHIPREV_ID_5750_A0 0x4000
34626 #define CHIPREV_ID_5750_A1 0x4001
34627 #define CHIPREV_ID_5750_A3 0x4003
34628 +#define CHIPREV_ID_5750_C1 0x4201
34629 #define CHIPREV_ID_5750_C2 0x4202
34630 #define CHIPREV_ID_5752_A0_HW 0x5000
34631 #define CHIPREV_ID_5752_A0 0x6000
34632 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
34633 index 47a8435..248e4b3 100644
34634 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
34635 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
34636 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
34637 * be copied but there is no memory for the copy.
34638 */
34639 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34640 + struct freelQ *fl, unsigned int len) __size_overflow(3);
34641 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34642 struct freelQ *fl, unsigned int len)
34643 {
34644 struct sk_buff *skb;
34645 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34646 index c4e8643..0979484 100644
34647 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34648 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34649 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34650 */
34651 struct l2t_skb_cb {
34652 arp_failure_handler_func arp_failure_handler;
34653 -};
34654 +} __no_const;
34655
34656 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34657
34658 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34659 index cfb60e1..94af340 100644
34660 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34661 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34662 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34663 * of the SW ring.
34664 */
34665 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34666 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34667 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34668 size_t sw_size, dma_addr_t * phys, void *metadata)
34669 {
34670 size_t len = nelem * elem_size;
34671 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
34672 * be copied but there is no memory for the copy.
34673 */
34674 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34675 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
34676 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34677 unsigned int len, unsigned int drop_thres)
34678 {
34679 struct sk_buff *skb = NULL;
34680 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34681 index 2dae795..73037d2 100644
34682 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34683 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34684 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34685 */
34686 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34687 size_t sw_size, dma_addr_t *phys, void *metadata,
34688 + size_t stat_size, int node) __size_overflow(2,4);
34689 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34690 + size_t sw_size, dma_addr_t *phys, void *metadata,
34691 size_t stat_size, int node)
34692 {
34693 size_t len = nelem * elem_size + stat_size;
34694 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34695 index 0bd585b..d954ca5 100644
34696 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34697 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34698 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34699 */
34700 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34701 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34702 + size_t stat_size) __size_overflow(2,4);
34703 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34704 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34705 size_t stat_size)
34706 {
34707 /*
34708 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34709 index 4d71f5a..8004440 100644
34710 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34711 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34712 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34713 for (i=0; i<ETH_ALEN; i++) {
34714 tmp.addr[i] = dev->dev_addr[i];
34715 }
34716 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34717 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34718 break;
34719
34720 case DE4X5_SET_HWADDR: /* Set the hardware address */
34721 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34722 spin_lock_irqsave(&lp->lock, flags);
34723 memcpy(&statbuf, &lp->pktStats, ioc->len);
34724 spin_unlock_irqrestore(&lp->lock, flags);
34725 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34726 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34727 return -EFAULT;
34728 break;
34729 }
34730 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34731 index 14d5b61..1398636 100644
34732 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34733 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34734 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34735 {NULL}};
34736
34737
34738 -static const char *block_name[] __devinitdata = {
34739 +static const char *block_name[] __devinitconst = {
34740 "21140 non-MII",
34741 "21140 MII PHY",
34742 "21142 Serial PHY",
34743 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34744 index 52da7b2..4ddfe1c 100644
34745 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34746 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34747 @@ -236,7 +236,7 @@ struct pci_id_info {
34748 int drv_flags; /* Driver use, intended as capability flags. */
34749 };
34750
34751 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34752 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34753 { /* Sometime a Level-One switch card. */
34754 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34755 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34756 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34757 index 28a3a9b..d96cb63 100644
34758 --- a/drivers/net/ethernet/dlink/sundance.c
34759 +++ b/drivers/net/ethernet/dlink/sundance.c
34760 @@ -218,7 +218,7 @@ enum {
34761 struct pci_id_info {
34762 const char *name;
34763 };
34764 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34765 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34766 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34767 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34768 {"D-Link DFE-580TX 4 port Server Adapter"},
34769 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34770 index e703d64..d62ecf9 100644
34771 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34772 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34773 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34774
34775 if (wrapped)
34776 newacc += 65536;
34777 - ACCESS_ONCE(*acc) = newacc;
34778 + ACCESS_ONCE_RW(*acc) = newacc;
34779 }
34780
34781 void be_parse_stats(struct be_adapter *adapter)
34782 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34783 index 47f85c3..82ab6c4 100644
34784 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34785 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34786 @@ -31,6 +31,8 @@
34787 #include <linux/netdevice.h>
34788 #include <linux/phy.h>
34789 #include <linux/platform_device.h>
34790 +#include <linux/interrupt.h>
34791 +#include <linux/irqreturn.h>
34792 #include <net/ip.h>
34793
34794 #include "ftgmac100.h"
34795 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34796 index bb336a0..4b472da 100644
34797 --- a/drivers/net/ethernet/faraday/ftmac100.c
34798 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34799 @@ -31,6 +31,8 @@
34800 #include <linux/module.h>
34801 #include <linux/netdevice.h>
34802 #include <linux/platform_device.h>
34803 +#include <linux/interrupt.h>
34804 +#include <linux/irqreturn.h>
34805
34806 #include "ftmac100.h"
34807
34808 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34809 index c82d444..0007fb4 100644
34810 --- a/drivers/net/ethernet/fealnx.c
34811 +++ b/drivers/net/ethernet/fealnx.c
34812 @@ -150,7 +150,7 @@ struct chip_info {
34813 int flags;
34814 };
34815
34816 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34817 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34818 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34819 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34820 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34821 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34822 index e1159e5..e18684d 100644
34823 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34824 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34825 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34826 {
34827 struct e1000_hw *hw = &adapter->hw;
34828 struct e1000_mac_info *mac = &hw->mac;
34829 - struct e1000_mac_operations *func = &mac->ops;
34830 + e1000_mac_operations_no_const *func = &mac->ops;
34831
34832 /* Set media type */
34833 switch (adapter->pdev->device) {
34834 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34835 index a3e65fd..f451444 100644
34836 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34837 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34838 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34839 {
34840 struct e1000_hw *hw = &adapter->hw;
34841 struct e1000_mac_info *mac = &hw->mac;
34842 - struct e1000_mac_operations *func = &mac->ops;
34843 + e1000_mac_operations_no_const *func = &mac->ops;
34844 u32 swsm = 0;
34845 u32 swsm2 = 0;
34846 bool force_clear_smbi = false;
34847 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34848 index 2967039..ca8c40c 100644
34849 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34850 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34851 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34852 void (*write_vfta)(struct e1000_hw *, u32, u32);
34853 s32 (*read_mac_addr)(struct e1000_hw *);
34854 };
34855 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34856
34857 /*
34858 * When to use various PHY register access functions:
34859 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34860 void (*power_up)(struct e1000_hw *);
34861 void (*power_down)(struct e1000_hw *);
34862 };
34863 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34864
34865 /* Function pointers for the NVM. */
34866 struct e1000_nvm_operations {
34867 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34868 s32 (*validate)(struct e1000_hw *);
34869 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34870 };
34871 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34872
34873 struct e1000_mac_info {
34874 - struct e1000_mac_operations ops;
34875 + e1000_mac_operations_no_const ops;
34876 u8 addr[ETH_ALEN];
34877 u8 perm_addr[ETH_ALEN];
34878
34879 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34880 };
34881
34882 struct e1000_phy_info {
34883 - struct e1000_phy_operations ops;
34884 + e1000_phy_operations_no_const ops;
34885
34886 enum e1000_phy_type type;
34887
34888 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34889 };
34890
34891 struct e1000_nvm_info {
34892 - struct e1000_nvm_operations ops;
34893 + e1000_nvm_operations_no_const ops;
34894
34895 enum e1000_nvm_type type;
34896 enum e1000_nvm_override override;
34897 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34898 index f67cbd3..cef9e3d 100644
34899 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34900 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34901 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34902 s32 (*read_mac_addr)(struct e1000_hw *);
34903 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34904 };
34905 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34906
34907 struct e1000_phy_operations {
34908 s32 (*acquire)(struct e1000_hw *);
34909 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34910 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34911 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34912 };
34913 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34914
34915 struct e1000_nvm_operations {
34916 s32 (*acquire)(struct e1000_hw *);
34917 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34918 s32 (*update)(struct e1000_hw *);
34919 s32 (*validate)(struct e1000_hw *);
34920 };
34921 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34922
34923 struct e1000_info {
34924 s32 (*get_invariants)(struct e1000_hw *);
34925 @@ -350,7 +353,7 @@ struct e1000_info {
34926 extern const struct e1000_info e1000_82575_info;
34927
34928 struct e1000_mac_info {
34929 - struct e1000_mac_operations ops;
34930 + e1000_mac_operations_no_const ops;
34931
34932 u8 addr[6];
34933 u8 perm_addr[6];
34934 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34935 };
34936
34937 struct e1000_phy_info {
34938 - struct e1000_phy_operations ops;
34939 + e1000_phy_operations_no_const ops;
34940
34941 enum e1000_phy_type type;
34942
34943 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34944 };
34945
34946 struct e1000_nvm_info {
34947 - struct e1000_nvm_operations ops;
34948 + e1000_nvm_operations_no_const ops;
34949 enum e1000_nvm_type type;
34950 enum e1000_nvm_override override;
34951
34952 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34953 s32 (*check_for_ack)(struct e1000_hw *, u16);
34954 s32 (*check_for_rst)(struct e1000_hw *, u16);
34955 };
34956 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34957
34958 struct e1000_mbx_stats {
34959 u32 msgs_tx;
34960 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34961 };
34962
34963 struct e1000_mbx_info {
34964 - struct e1000_mbx_operations ops;
34965 + e1000_mbx_operations_no_const ops;
34966 struct e1000_mbx_stats stats;
34967 u32 timeout;
34968 u32 usec_delay;
34969 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34970 index 57db3c6..aa825fc 100644
34971 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34972 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34973 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34974 s32 (*read_mac_addr)(struct e1000_hw *);
34975 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34976 };
34977 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34978
34979 struct e1000_mac_info {
34980 - struct e1000_mac_operations ops;
34981 + e1000_mac_operations_no_const ops;
34982 u8 addr[6];
34983 u8 perm_addr[6];
34984
34985 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34986 s32 (*check_for_ack)(struct e1000_hw *);
34987 s32 (*check_for_rst)(struct e1000_hw *);
34988 };
34989 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34990
34991 struct e1000_mbx_stats {
34992 u32 msgs_tx;
34993 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34994 };
34995
34996 struct e1000_mbx_info {
34997 - struct e1000_mbx_operations ops;
34998 + e1000_mbx_operations_no_const ops;
34999 struct e1000_mbx_stats stats;
35000 u32 timeout;
35001 u32 usec_delay;
35002 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35003 index 9b95bef..7e254ee 100644
35004 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35005 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35006 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35007 s32 (*update_checksum)(struct ixgbe_hw *);
35008 u16 (*calc_checksum)(struct ixgbe_hw *);
35009 };
35010 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35011
35012 struct ixgbe_mac_operations {
35013 s32 (*init_hw)(struct ixgbe_hw *);
35014 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35015 /* Manageability interface */
35016 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35017 };
35018 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35019
35020 struct ixgbe_phy_operations {
35021 s32 (*identify)(struct ixgbe_hw *);
35022 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35023 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35024 s32 (*check_overtemp)(struct ixgbe_hw *);
35025 };
35026 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35027
35028 struct ixgbe_eeprom_info {
35029 - struct ixgbe_eeprom_operations ops;
35030 + ixgbe_eeprom_operations_no_const ops;
35031 enum ixgbe_eeprom_type type;
35032 u32 semaphore_delay;
35033 u16 word_size;
35034 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35035
35036 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35037 struct ixgbe_mac_info {
35038 - struct ixgbe_mac_operations ops;
35039 + ixgbe_mac_operations_no_const ops;
35040 enum ixgbe_mac_type type;
35041 u8 addr[ETH_ALEN];
35042 u8 perm_addr[ETH_ALEN];
35043 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35044 };
35045
35046 struct ixgbe_phy_info {
35047 - struct ixgbe_phy_operations ops;
35048 + ixgbe_phy_operations_no_const ops;
35049 struct mdio_if_info mdio;
35050 enum ixgbe_phy_type type;
35051 u32 id;
35052 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35053 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35054 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35055 };
35056 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35057
35058 struct ixgbe_mbx_stats {
35059 u32 msgs_tx;
35060 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35061 };
35062
35063 struct ixgbe_mbx_info {
35064 - struct ixgbe_mbx_operations ops;
35065 + ixgbe_mbx_operations_no_const ops;
35066 struct ixgbe_mbx_stats stats;
35067 u32 timeout;
35068 u32 usec_delay;
35069 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35070 index 25c951d..cc7cf33 100644
35071 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35072 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35073 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35074 s32 (*clear_vfta)(struct ixgbe_hw *);
35075 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35076 };
35077 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35078
35079 enum ixgbe_mac_type {
35080 ixgbe_mac_unknown = 0,
35081 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35082 };
35083
35084 struct ixgbe_mac_info {
35085 - struct ixgbe_mac_operations ops;
35086 + ixgbe_mac_operations_no_const ops;
35087 u8 addr[6];
35088 u8 perm_addr[6];
35089
35090 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35091 s32 (*check_for_ack)(struct ixgbe_hw *);
35092 s32 (*check_for_rst)(struct ixgbe_hw *);
35093 };
35094 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35095
35096 struct ixgbe_mbx_stats {
35097 u32 msgs_tx;
35098 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35099 };
35100
35101 struct ixgbe_mbx_info {
35102 - struct ixgbe_mbx_operations ops;
35103 + ixgbe_mbx_operations_no_const ops;
35104 struct ixgbe_mbx_stats stats;
35105 u32 timeout;
35106 u32 udelay;
35107 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35108 index 8bf22b6..7f5baaa 100644
35109 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35110 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35111 @@ -41,6 +41,7 @@
35112 #include <linux/slab.h>
35113 #include <linux/io-mapping.h>
35114 #include <linux/delay.h>
35115 +#include <linux/sched.h>
35116
35117 #include <linux/mlx4/device.h>
35118 #include <linux/mlx4/doorbell.h>
35119 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35120 index 5046a64..71ca936 100644
35121 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35122 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35123 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35124 void (*link_down)(struct __vxge_hw_device *devh);
35125 void (*crit_err)(struct __vxge_hw_device *devh,
35126 enum vxge_hw_event type, u64 ext_data);
35127 -};
35128 +} __no_const;
35129
35130 /*
35131 * struct __vxge_hw_blockpool_entry - Block private data structure
35132 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35133 index 4a518a3..936b334 100644
35134 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35135 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35136 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35137 struct vxge_hw_mempool_dma *dma_object,
35138 u32 index,
35139 u32 is_last);
35140 -};
35141 +} __no_const;
35142
35143 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35144 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35145 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35146 index bbacb37..d60887d 100644
35147 --- a/drivers/net/ethernet/realtek/r8169.c
35148 +++ b/drivers/net/ethernet/realtek/r8169.c
35149 @@ -695,17 +695,17 @@ struct rtl8169_private {
35150 struct mdio_ops {
35151 void (*write)(void __iomem *, int, int);
35152 int (*read)(void __iomem *, int);
35153 - } mdio_ops;
35154 + } __no_const mdio_ops;
35155
35156 struct pll_power_ops {
35157 void (*down)(struct rtl8169_private *);
35158 void (*up)(struct rtl8169_private *);
35159 - } pll_power_ops;
35160 + } __no_const pll_power_ops;
35161
35162 struct jumbo_ops {
35163 void (*enable)(struct rtl8169_private *);
35164 void (*disable)(struct rtl8169_private *);
35165 - } jumbo_ops;
35166 + } __no_const jumbo_ops;
35167
35168 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35169 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35170 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35171 index 5b118cd..858b523 100644
35172 --- a/drivers/net/ethernet/sis/sis190.c
35173 +++ b/drivers/net/ethernet/sis/sis190.c
35174 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35175 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35176 struct net_device *dev)
35177 {
35178 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35179 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35180 struct sis190_private *tp = netdev_priv(dev);
35181 struct pci_dev *isa_bridge;
35182 u8 reg, tmp8;
35183 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35184 index c07cfe9..81cbf7e 100644
35185 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35186 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35187 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35188
35189 writel(value, ioaddr + MMC_CNTRL);
35190
35191 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35192 - MMC_CNTRL, value);
35193 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35194 +// MMC_CNTRL, value);
35195 }
35196
35197 /* To mask all all interrupts.*/
35198 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35199 index dec5836..6d4db7d 100644
35200 --- a/drivers/net/hyperv/hyperv_net.h
35201 +++ b/drivers/net/hyperv/hyperv_net.h
35202 @@ -97,7 +97,7 @@ struct rndis_device {
35203
35204 enum rndis_device_state state;
35205 bool link_state;
35206 - atomic_t new_req_id;
35207 + atomic_unchecked_t new_req_id;
35208
35209 spinlock_t request_lock;
35210 struct list_head req_list;
35211 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35212 index 133b7fb..d58c559 100644
35213 --- a/drivers/net/hyperv/rndis_filter.c
35214 +++ b/drivers/net/hyperv/rndis_filter.c
35215 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35216 * template
35217 */
35218 set = &rndis_msg->msg.set_req;
35219 - set->req_id = atomic_inc_return(&dev->new_req_id);
35220 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35221
35222 /* Add to the request list */
35223 spin_lock_irqsave(&dev->request_lock, flags);
35224 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35225
35226 /* Setup the rndis set */
35227 halt = &request->request_msg.msg.halt_req;
35228 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35229 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35230
35231 /* Ignore return since this msg is optional. */
35232 rndis_filter_send_request(dev, request);
35233 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35234 index 486b404..0d6677d 100644
35235 --- a/drivers/net/ppp/ppp_generic.c
35236 +++ b/drivers/net/ppp/ppp_generic.c
35237 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35238 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35239 struct ppp_stats stats;
35240 struct ppp_comp_stats cstats;
35241 - char *vers;
35242
35243 switch (cmd) {
35244 case SIOCGPPPSTATS:
35245 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35246 break;
35247
35248 case SIOCGPPPVER:
35249 - vers = PPP_VERSION;
35250 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35251 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35252 break;
35253 err = 0;
35254 break;
35255 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35256 index 515f122..41dd273 100644
35257 --- a/drivers/net/tokenring/abyss.c
35258 +++ b/drivers/net/tokenring/abyss.c
35259 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35260
35261 static int __init abyss_init (void)
35262 {
35263 - abyss_netdev_ops = tms380tr_netdev_ops;
35264 + pax_open_kernel();
35265 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35266
35267 - abyss_netdev_ops.ndo_open = abyss_open;
35268 - abyss_netdev_ops.ndo_stop = abyss_close;
35269 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35270 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35271 + pax_close_kernel();
35272
35273 return pci_register_driver(&abyss_driver);
35274 }
35275 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35276 index 6153cfd..cf69c1c 100644
35277 --- a/drivers/net/tokenring/madgemc.c
35278 +++ b/drivers/net/tokenring/madgemc.c
35279 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35280
35281 static int __init madgemc_init (void)
35282 {
35283 - madgemc_netdev_ops = tms380tr_netdev_ops;
35284 - madgemc_netdev_ops.ndo_open = madgemc_open;
35285 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35286 + pax_open_kernel();
35287 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35288 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35289 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35290 + pax_close_kernel();
35291
35292 return mca_register_driver (&madgemc_driver);
35293 }
35294 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35295 index 8d362e6..f91cc52 100644
35296 --- a/drivers/net/tokenring/proteon.c
35297 +++ b/drivers/net/tokenring/proteon.c
35298 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35299 struct platform_device *pdev;
35300 int i, num = 0, err = 0;
35301
35302 - proteon_netdev_ops = tms380tr_netdev_ops;
35303 - proteon_netdev_ops.ndo_open = proteon_open;
35304 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35305 + pax_open_kernel();
35306 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35307 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35308 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35309 + pax_close_kernel();
35310
35311 err = platform_driver_register(&proteon_driver);
35312 if (err)
35313 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35314 index 46db5c5..37c1536 100644
35315 --- a/drivers/net/tokenring/skisa.c
35316 +++ b/drivers/net/tokenring/skisa.c
35317 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35318 struct platform_device *pdev;
35319 int i, num = 0, err = 0;
35320
35321 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35322 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35323 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35324 + pax_open_kernel();
35325 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35326 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35327 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35328 + pax_close_kernel();
35329
35330 err = platform_driver_register(&sk_isa_driver);
35331 if (err)
35332 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35333 index e1324b4..e1b0041 100644
35334 --- a/drivers/net/usb/hso.c
35335 +++ b/drivers/net/usb/hso.c
35336 @@ -71,7 +71,7 @@
35337 #include <asm/byteorder.h>
35338 #include <linux/serial_core.h>
35339 #include <linux/serial.h>
35340 -
35341 +#include <asm/local.h>
35342
35343 #define MOD_AUTHOR "Option Wireless"
35344 #define MOD_DESCRIPTION "USB High Speed Option driver"
35345 @@ -257,7 +257,7 @@ struct hso_serial {
35346
35347 /* from usb_serial_port */
35348 struct tty_struct *tty;
35349 - int open_count;
35350 + local_t open_count;
35351 spinlock_t serial_lock;
35352
35353 int (*write_data) (struct hso_serial *serial);
35354 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35355 struct urb *urb;
35356
35357 urb = serial->rx_urb[0];
35358 - if (serial->open_count > 0) {
35359 + if (local_read(&serial->open_count) > 0) {
35360 count = put_rxbuf_data(urb, serial);
35361 if (count == -1)
35362 return;
35363 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35364 DUMP1(urb->transfer_buffer, urb->actual_length);
35365
35366 /* Anyone listening? */
35367 - if (serial->open_count == 0)
35368 + if (local_read(&serial->open_count) == 0)
35369 return;
35370
35371 if (status == 0) {
35372 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35373 spin_unlock_irq(&serial->serial_lock);
35374
35375 /* check for port already opened, if not set the termios */
35376 - serial->open_count++;
35377 - if (serial->open_count == 1) {
35378 + if (local_inc_return(&serial->open_count) == 1) {
35379 serial->rx_state = RX_IDLE;
35380 /* Force default termio settings */
35381 _hso_serial_set_termios(tty, NULL);
35382 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35383 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35384 if (result) {
35385 hso_stop_serial_device(serial->parent);
35386 - serial->open_count--;
35387 + local_dec(&serial->open_count);
35388 kref_put(&serial->parent->ref, hso_serial_ref_free);
35389 }
35390 } else {
35391 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35392
35393 /* reset the rts and dtr */
35394 /* do the actual close */
35395 - serial->open_count--;
35396 + local_dec(&serial->open_count);
35397
35398 - if (serial->open_count <= 0) {
35399 - serial->open_count = 0;
35400 + if (local_read(&serial->open_count) <= 0) {
35401 + local_set(&serial->open_count, 0);
35402 spin_lock_irq(&serial->serial_lock);
35403 if (serial->tty == tty) {
35404 serial->tty->driver_data = NULL;
35405 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35406
35407 /* the actual setup */
35408 spin_lock_irqsave(&serial->serial_lock, flags);
35409 - if (serial->open_count)
35410 + if (local_read(&serial->open_count))
35411 _hso_serial_set_termios(tty, old);
35412 else
35413 tty->termios = old;
35414 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35415 D1("Pending read interrupt on port %d\n", i);
35416 spin_lock(&serial->serial_lock);
35417 if (serial->rx_state == RX_IDLE &&
35418 - serial->open_count > 0) {
35419 + local_read(&serial->open_count) > 0) {
35420 /* Setup and send a ctrl req read on
35421 * port i */
35422 if (!serial->rx_urb_filled[0]) {
35423 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35424 /* Start all serial ports */
35425 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35426 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35427 - if (dev2ser(serial_table[i])->open_count) {
35428 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35429 result =
35430 hso_start_serial_device(serial_table[i], GFP_NOIO);
35431 hso_kick_transmit(dev2ser(serial_table[i]));
35432 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35433 index efc0111..79c8f5b 100644
35434 --- a/drivers/net/wireless/ath/ath.h
35435 +++ b/drivers/net/wireless/ath/ath.h
35436 @@ -119,6 +119,7 @@ struct ath_ops {
35437 void (*write_flush) (void *);
35438 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35439 };
35440 +typedef struct ath_ops __no_const ath_ops_no_const;
35441
35442 struct ath_common;
35443 struct ath_bus_ops;
35444 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35445 index 8c5ce8b..abf101b 100644
35446 --- a/drivers/net/wireless/ath/ath5k/debug.c
35447 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35448 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35449
35450 static ssize_t write_file_debug(struct file *file,
35451 const char __user *userbuf,
35452 + size_t count, loff_t *ppos) __size_overflow(3);
35453 +static ssize_t write_file_debug(struct file *file,
35454 + const char __user *userbuf,
35455 size_t count, loff_t *ppos)
35456 {
35457 struct ath5k_hw *ah = file->private_data;
35458 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35459 index 7b6417b..ab5db98 100644
35460 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35461 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35462 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35463 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35464 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35465
35466 - ACCESS_ONCE(ads->ds_link) = i->link;
35467 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35468 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35469 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35470
35471 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35472 ctl6 = SM(i->keytype, AR_EncrType);
35473 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35474
35475 if ((i->is_first || i->is_last) &&
35476 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35477 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35478 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35479 | set11nTries(i->rates, 1)
35480 | set11nTries(i->rates, 2)
35481 | set11nTries(i->rates, 3)
35482 | (i->dur_update ? AR_DurUpdateEna : 0)
35483 | SM(0, AR_BurstDur);
35484
35485 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35486 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35487 | set11nRate(i->rates, 1)
35488 | set11nRate(i->rates, 2)
35489 | set11nRate(i->rates, 3);
35490 } else {
35491 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35492 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35493 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35494 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35495 }
35496
35497 if (!i->is_first) {
35498 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35499 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35500 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35501 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35502 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35503 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35504 return;
35505 }
35506
35507 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35508 break;
35509 }
35510
35511 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35512 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35513 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35514 | SM(i->txpower, AR_XmitPower)
35515 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35516 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35517 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35518 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35519
35520 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35521 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35522 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35523 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35524
35525 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35526 return;
35527
35528 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35529 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35530 | set11nPktDurRTSCTS(i->rates, 1);
35531
35532 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35533 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35534 | set11nPktDurRTSCTS(i->rates, 3);
35535
35536 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35537 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35538 | set11nRateFlags(i->rates, 1)
35539 | set11nRateFlags(i->rates, 2)
35540 | set11nRateFlags(i->rates, 3)
35541 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35542 index 09b8c9d..905339e 100644
35543 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35544 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35545 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35546 (i->qcu << AR_TxQcuNum_S) | 0x17;
35547
35548 checksum += val;
35549 - ACCESS_ONCE(ads->info) = val;
35550 + ACCESS_ONCE_RW(ads->info) = val;
35551
35552 checksum += i->link;
35553 - ACCESS_ONCE(ads->link) = i->link;
35554 + ACCESS_ONCE_RW(ads->link) = i->link;
35555
35556 checksum += i->buf_addr[0];
35557 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35558 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35559 checksum += i->buf_addr[1];
35560 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35561 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35562 checksum += i->buf_addr[2];
35563 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35564 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35565 checksum += i->buf_addr[3];
35566 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35567 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35568
35569 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35570 - ACCESS_ONCE(ads->ctl3) = val;
35571 + ACCESS_ONCE_RW(ads->ctl3) = val;
35572 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35573 - ACCESS_ONCE(ads->ctl5) = val;
35574 + ACCESS_ONCE_RW(ads->ctl5) = val;
35575 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35576 - ACCESS_ONCE(ads->ctl7) = val;
35577 + ACCESS_ONCE_RW(ads->ctl7) = val;
35578 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35579 - ACCESS_ONCE(ads->ctl9) = val;
35580 + ACCESS_ONCE_RW(ads->ctl9) = val;
35581
35582 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35583 - ACCESS_ONCE(ads->ctl10) = checksum;
35584 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35585
35586 if (i->is_first || i->is_last) {
35587 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35588 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35589 | set11nTries(i->rates, 1)
35590 | set11nTries(i->rates, 2)
35591 | set11nTries(i->rates, 3)
35592 | (i->dur_update ? AR_DurUpdateEna : 0)
35593 | SM(0, AR_BurstDur);
35594
35595 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35596 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35597 | set11nRate(i->rates, 1)
35598 | set11nRate(i->rates, 2)
35599 | set11nRate(i->rates, 3);
35600 } else {
35601 - ACCESS_ONCE(ads->ctl13) = 0;
35602 - ACCESS_ONCE(ads->ctl14) = 0;
35603 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35604 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35605 }
35606
35607 ads->ctl20 = 0;
35608 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35609
35610 ctl17 = SM(i->keytype, AR_EncrType);
35611 if (!i->is_first) {
35612 - ACCESS_ONCE(ads->ctl11) = 0;
35613 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35614 - ACCESS_ONCE(ads->ctl15) = 0;
35615 - ACCESS_ONCE(ads->ctl16) = 0;
35616 - ACCESS_ONCE(ads->ctl17) = ctl17;
35617 - ACCESS_ONCE(ads->ctl18) = 0;
35618 - ACCESS_ONCE(ads->ctl19) = 0;
35619 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35620 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35621 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35622 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35623 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35624 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35625 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35626 return;
35627 }
35628
35629 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35630 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35631 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35632 | SM(i->txpower, AR_XmitPower)
35633 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35634 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35635 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35636 ctl12 |= SM(val, AR_PAPRDChainMask);
35637
35638 - ACCESS_ONCE(ads->ctl12) = ctl12;
35639 - ACCESS_ONCE(ads->ctl17) = ctl17;
35640 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35641 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35642
35643 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35644 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35645 | set11nPktDurRTSCTS(i->rates, 1);
35646
35647 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35648 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35649 | set11nPktDurRTSCTS(i->rates, 3);
35650
35651 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35652 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35653 | set11nRateFlags(i->rates, 1)
35654 | set11nRateFlags(i->rates, 2)
35655 | set11nRateFlags(i->rates, 3)
35656 | SM(i->rtscts_rate, AR_RTSCTSRate);
35657
35658 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35659 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35660 }
35661
35662 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35663 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
35664 index 68d972b..1d9205b 100644
35665 --- a/drivers/net/wireless/ath/ath9k/debug.c
35666 +++ b/drivers/net/wireless/ath/ath9k/debug.c
35667 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35668 }
35669
35670 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35671 + size_t count, loff_t *ppos) __size_overflow(3);
35672 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35673 size_t count, loff_t *ppos)
35674 {
35675 struct ath_softc *sc = file->private_data;
35676 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35677 index d3ff33c..c98bcda 100644
35678 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35679 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35680 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35681 }
35682
35683 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35684 + size_t count, loff_t *ppos) __size_overflow(3);
35685 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35686 size_t count, loff_t *ppos)
35687 {
35688 struct ath9k_htc_priv *priv = file->private_data;
35689 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35690 index c8261d4..8d88929 100644
35691 --- a/drivers/net/wireless/ath/ath9k/hw.h
35692 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35693 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35694
35695 /* ANI */
35696 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35697 -};
35698 +} __no_const;
35699
35700 /**
35701 * struct ath_hw_ops - callbacks used by hardware code and driver code
35702 @@ -803,7 +803,7 @@ struct ath_hw_ops {
35703 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35704 struct ath_hw_antcomb_conf *antconf);
35705
35706 -};
35707 +} __no_const;
35708
35709 struct ath_nf_limits {
35710 s16 max;
35711 @@ -823,7 +823,7 @@ enum ath_cal_list {
35712 #define AH_FASTCC 0x4
35713
35714 struct ath_hw {
35715 - struct ath_ops reg_ops;
35716 + ath_ops_no_const reg_ops;
35717
35718 struct ieee80211_hw *hw;
35719 struct ath_common common;
35720 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35721 index af00e2c..ab04d34 100644
35722 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35723 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35724 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35725 void (*carrsuppr)(struct brcms_phy *);
35726 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35727 void (*detach)(struct brcms_phy *);
35728 -};
35729 +} __no_const;
35730
35731 struct brcms_phy {
35732 struct brcms_phy_pub pubpi_ro;
35733 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35734 index a7dfba8..e28eacd 100644
35735 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35736 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35737 @@ -3647,7 +3647,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35738 */
35739 if (il3945_mod_params.disable_hw_scan) {
35740 D_INFO("Disabling hw_scan\n");
35741 - il3945_hw_ops.hw_scan = NULL;
35742 + pax_open_kernel();
35743 + *(void **)&il3945_hw_ops.hw_scan = NULL;
35744 + pax_close_kernel();
35745 }
35746
35747 D_INFO("*** LOAD DRIVER ***\n");
35748 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35749 index f8fc239..8cade22 100644
35750 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35751 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35752 @@ -86,8 +86,8 @@ do { \
35753 } while (0)
35754
35755 #else
35756 -#define IWL_DEBUG(m, level, fmt, args...)
35757 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35758 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35759 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35760 #define iwl_print_hex_dump(m, level, p, len)
35761 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35762 do { \
35763 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35764 index 4b9e730..7603659 100644
35765 --- a/drivers/net/wireless/mac80211_hwsim.c
35766 +++ b/drivers/net/wireless/mac80211_hwsim.c
35767 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35768 return -EINVAL;
35769
35770 if (fake_hw_scan) {
35771 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35772 - mac80211_hwsim_ops.sw_scan_start = NULL;
35773 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35774 + pax_open_kernel();
35775 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35776 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35777 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35778 + pax_close_kernel();
35779 }
35780
35781 spin_lock_init(&hwsim_radio_lock);
35782 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35783 index 3186aa4..b35b09f 100644
35784 --- a/drivers/net/wireless/mwifiex/main.h
35785 +++ b/drivers/net/wireless/mwifiex/main.h
35786 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35787 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35788 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35789 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35790 -};
35791 +} __no_const;
35792
35793 struct mwifiex_adapter {
35794 u8 iface_type;
35795 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35796 index a330c69..a81540f 100644
35797 --- a/drivers/net/wireless/rndis_wlan.c
35798 +++ b/drivers/net/wireless/rndis_wlan.c
35799 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35800
35801 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35802
35803 - if (rts_threshold < 0 || rts_threshold > 2347)
35804 + if (rts_threshold > 2347)
35805 rts_threshold = 2347;
35806
35807 tmp = cpu_to_le32(rts_threshold);
35808 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35809 index a77f1bb..c608b2b 100644
35810 --- a/drivers/net/wireless/wl1251/wl1251.h
35811 +++ b/drivers/net/wireless/wl1251/wl1251.h
35812 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35813 void (*reset)(struct wl1251 *wl);
35814 void (*enable_irq)(struct wl1251 *wl);
35815 void (*disable_irq)(struct wl1251 *wl);
35816 -};
35817 +} __no_const;
35818
35819 struct wl1251 {
35820 struct ieee80211_hw *hw;
35821 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35822 index f34b5b2..b5abb9f 100644
35823 --- a/drivers/oprofile/buffer_sync.c
35824 +++ b/drivers/oprofile/buffer_sync.c
35825 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35826 if (cookie == NO_COOKIE)
35827 offset = pc;
35828 if (cookie == INVALID_COOKIE) {
35829 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35830 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35831 offset = pc;
35832 }
35833 if (cookie != last_cookie) {
35834 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35835 /* add userspace sample */
35836
35837 if (!mm) {
35838 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35839 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35840 return 0;
35841 }
35842
35843 cookie = lookup_dcookie(mm, s->eip, &offset);
35844
35845 if (cookie == INVALID_COOKIE) {
35846 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35847 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35848 return 0;
35849 }
35850
35851 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35852 /* ignore backtraces if failed to add a sample */
35853 if (state == sb_bt_start) {
35854 state = sb_bt_ignore;
35855 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35856 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35857 }
35858 }
35859 release_mm(mm);
35860 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35861 index c0cc4e7..44d4e54 100644
35862 --- a/drivers/oprofile/event_buffer.c
35863 +++ b/drivers/oprofile/event_buffer.c
35864 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35865 }
35866
35867 if (buffer_pos == buffer_size) {
35868 - atomic_inc(&oprofile_stats.event_lost_overflow);
35869 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35870 return;
35871 }
35872
35873 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35874 index ed2c3ec..deda85a 100644
35875 --- a/drivers/oprofile/oprof.c
35876 +++ b/drivers/oprofile/oprof.c
35877 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35878 if (oprofile_ops.switch_events())
35879 return;
35880
35881 - atomic_inc(&oprofile_stats.multiplex_counter);
35882 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35883 start_switch_worker();
35884 }
35885
35886 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
35887 index 84a208d..f07d177 100644
35888 --- a/drivers/oprofile/oprofile_files.c
35889 +++ b/drivers/oprofile/oprofile_files.c
35890 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
35891
35892
35893 static ssize_t timeout_write(struct file *file, char const __user *buf,
35894 + size_t count, loff_t *offset) __size_overflow(3);
35895 +static ssize_t timeout_write(struct file *file, char const __user *buf,
35896 size_t count, loff_t *offset)
35897 {
35898 unsigned long val;
35899 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
35900 }
35901
35902
35903 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35904 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35905 {
35906 unsigned long val;
35907 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
35908 };
35909
35910
35911 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35912 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
35913 {
35914 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
35915 }
35916
35917
35918 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35919 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35920 {
35921 unsigned long val;
35922 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35923 index 917d28e..d62d981 100644
35924 --- a/drivers/oprofile/oprofile_stats.c
35925 +++ b/drivers/oprofile/oprofile_stats.c
35926 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35927 cpu_buf->sample_invalid_eip = 0;
35928 }
35929
35930 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35931 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35932 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35933 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35934 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35935 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35936 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35937 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35938 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35939 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35940 }
35941
35942
35943 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35944 index 38b6fc0..b5cbfce 100644
35945 --- a/drivers/oprofile/oprofile_stats.h
35946 +++ b/drivers/oprofile/oprofile_stats.h
35947 @@ -13,11 +13,11 @@
35948 #include <linux/atomic.h>
35949
35950 struct oprofile_stat_struct {
35951 - atomic_t sample_lost_no_mm;
35952 - atomic_t sample_lost_no_mapping;
35953 - atomic_t bt_lost_no_mapping;
35954 - atomic_t event_lost_overflow;
35955 - atomic_t multiplex_counter;
35956 + atomic_unchecked_t sample_lost_no_mm;
35957 + atomic_unchecked_t sample_lost_no_mapping;
35958 + atomic_unchecked_t bt_lost_no_mapping;
35959 + atomic_unchecked_t event_lost_overflow;
35960 + atomic_unchecked_t multiplex_counter;
35961 };
35962
35963 extern struct oprofile_stat_struct oprofile_stats;
35964 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35965 index 2f0aa0f..d5246c3 100644
35966 --- a/drivers/oprofile/oprofilefs.c
35967 +++ b/drivers/oprofile/oprofilefs.c
35968 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
35969 }
35970
35971
35972 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35973 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35974 {
35975 unsigned long value;
35976 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
35977
35978
35979 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35980 - char const *name, atomic_t *val)
35981 + char const *name, atomic_unchecked_t *val)
35982 {
35983 return __oprofilefs_create_file(sb, root, name,
35984 &atomic_ro_fops, 0444, val);
35985 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35986 index 3f56bc0..707d642 100644
35987 --- a/drivers/parport/procfs.c
35988 +++ b/drivers/parport/procfs.c
35989 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35990
35991 *ppos += len;
35992
35993 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35994 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35995 }
35996
35997 #ifdef CONFIG_PARPORT_1284
35998 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35999
36000 *ppos += len;
36001
36002 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36003 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36004 }
36005 #endif /* IEEE1284.3 support. */
36006
36007 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36008 index 9fff878..ad0ad53 100644
36009 --- a/drivers/pci/hotplug/cpci_hotplug.h
36010 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36011 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36012 int (*hardware_test) (struct slot* slot, u32 value);
36013 u8 (*get_power) (struct slot* slot);
36014 int (*set_power) (struct slot* slot, int value);
36015 -};
36016 +} __no_const;
36017
36018 struct cpci_hp_controller {
36019 unsigned int irq;
36020 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36021 index 76ba8a1..20ca857 100644
36022 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36023 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36024 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36025
36026 void compaq_nvram_init (void __iomem *rom_start)
36027 {
36028 +
36029 +#ifndef CONFIG_PAX_KERNEXEC
36030 if (rom_start) {
36031 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36032 }
36033 +#endif
36034 +
36035 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36036
36037 /* initialize our int15 lock */
36038 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36039 index 2275162..95f1a92 100644
36040 --- a/drivers/pci/pcie/aspm.c
36041 +++ b/drivers/pci/pcie/aspm.c
36042 @@ -27,9 +27,9 @@
36043 #define MODULE_PARAM_PREFIX "pcie_aspm."
36044
36045 /* Note: those are not register definitions */
36046 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36047 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36048 -#define ASPM_STATE_L1 (4) /* L1 state */
36049 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36050 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36051 +#define ASPM_STATE_L1 (4U) /* L1 state */
36052 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36053 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36054
36055 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36056 index 71eac9c..2de27ef 100644
36057 --- a/drivers/pci/probe.c
36058 +++ b/drivers/pci/probe.c
36059 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36060 u32 l, sz, mask;
36061 u16 orig_cmd;
36062
36063 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36064 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36065
36066 if (!dev->mmio_always_on) {
36067 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36068 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36069 index 27911b5..5b6db88 100644
36070 --- a/drivers/pci/proc.c
36071 +++ b/drivers/pci/proc.c
36072 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36073 static int __init pci_proc_init(void)
36074 {
36075 struct pci_dev *dev = NULL;
36076 +
36077 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36078 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36079 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36080 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36081 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36082 +#endif
36083 +#else
36084 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36085 +#endif
36086 proc_create("devices", 0, proc_bus_pci_dir,
36087 &proc_bus_pci_dev_operations);
36088 proc_initialized = 1;
36089 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36090 index 6f966d6..68e18ed 100644
36091 --- a/drivers/platform/x86/asus_acpi.c
36092 +++ b/drivers/platform/x86/asus_acpi.c
36093 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36094 }
36095
36096 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36097 + size_t count, loff_t *pos) __size_overflow(3);
36098 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36099 size_t count, loff_t *pos)
36100 {
36101 int rv, value;
36102 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36103 index ea0c607..58c4628 100644
36104 --- a/drivers/platform/x86/thinkpad_acpi.c
36105 +++ b/drivers/platform/x86/thinkpad_acpi.c
36106 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36107 return 0;
36108 }
36109
36110 -void static hotkey_mask_warn_incomplete_mask(void)
36111 +static void hotkey_mask_warn_incomplete_mask(void)
36112 {
36113 /* log only what the user can fix... */
36114 const u32 wantedmask = hotkey_driver_mask &
36115 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36116 }
36117 }
36118
36119 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36120 - struct tp_nvram_state *newn,
36121 - const u32 event_mask)
36122 -{
36123 -
36124 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36125 do { \
36126 if ((event_mask & (1 << __scancode)) && \
36127 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36128 tpacpi_hotkey_send_key(__scancode); \
36129 } while (0)
36130
36131 - void issue_volchange(const unsigned int oldvol,
36132 - const unsigned int newvol)
36133 - {
36134 - unsigned int i = oldvol;
36135 +static void issue_volchange(const unsigned int oldvol,
36136 + const unsigned int newvol,
36137 + const u32 event_mask)
36138 +{
36139 + unsigned int i = oldvol;
36140
36141 - while (i > newvol) {
36142 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36143 - i--;
36144 - }
36145 - while (i < newvol) {
36146 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36147 - i++;
36148 - }
36149 + while (i > newvol) {
36150 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36151 + i--;
36152 }
36153 + while (i < newvol) {
36154 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36155 + i++;
36156 + }
36157 +}
36158
36159 - void issue_brightnesschange(const unsigned int oldbrt,
36160 - const unsigned int newbrt)
36161 - {
36162 - unsigned int i = oldbrt;
36163 +static void issue_brightnesschange(const unsigned int oldbrt,
36164 + const unsigned int newbrt,
36165 + const u32 event_mask)
36166 +{
36167 + unsigned int i = oldbrt;
36168
36169 - while (i > newbrt) {
36170 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36171 - i--;
36172 - }
36173 - while (i < newbrt) {
36174 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36175 - i++;
36176 - }
36177 + while (i > newbrt) {
36178 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36179 + i--;
36180 + }
36181 + while (i < newbrt) {
36182 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36183 + i++;
36184 }
36185 +}
36186
36187 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36188 + struct tp_nvram_state *newn,
36189 + const u32 event_mask)
36190 +{
36191 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36192 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36193 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36194 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36195 oldn->volume_level != newn->volume_level) {
36196 /* recently muted, or repeated mute keypress, or
36197 * multiple presses ending in mute */
36198 - issue_volchange(oldn->volume_level, newn->volume_level);
36199 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36200 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36201 }
36202 } else {
36203 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36204 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36205 }
36206 if (oldn->volume_level != newn->volume_level) {
36207 - issue_volchange(oldn->volume_level, newn->volume_level);
36208 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36209 } else if (oldn->volume_toggle != newn->volume_toggle) {
36210 /* repeated vol up/down keypress at end of scale ? */
36211 if (newn->volume_level == 0)
36212 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36213 /* handle brightness */
36214 if (oldn->brightness_level != newn->brightness_level) {
36215 issue_brightnesschange(oldn->brightness_level,
36216 - newn->brightness_level);
36217 + newn->brightness_level,
36218 + event_mask);
36219 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36220 /* repeated key presses that didn't change state */
36221 if (newn->brightness_level == 0)
36222 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36223 && !tp_features.bright_unkfw)
36224 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36225 }
36226 +}
36227
36228 #undef TPACPI_COMPARE_KEY
36229 #undef TPACPI_MAY_SEND_KEY
36230 -}
36231
36232 /*
36233 * Polling driver
36234 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36235 index dcdc1f4..85cee16 100644
36236 --- a/drivers/platform/x86/toshiba_acpi.c
36237 +++ b/drivers/platform/x86/toshiba_acpi.c
36238 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36239 }
36240
36241 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36242 + size_t count, loff_t *pos) __size_overflow(3);
36243 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36244 size_t count, loff_t *pos)
36245 {
36246 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36247 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36248 index b859d16..5cc6b1a 100644
36249 --- a/drivers/pnp/pnpbios/bioscalls.c
36250 +++ b/drivers/pnp/pnpbios/bioscalls.c
36251 @@ -59,7 +59,7 @@ do { \
36252 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36253 } while(0)
36254
36255 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36256 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36257 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36258
36259 /*
36260 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36261
36262 cpu = get_cpu();
36263 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36264 +
36265 + pax_open_kernel();
36266 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36267 + pax_close_kernel();
36268
36269 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36270 spin_lock_irqsave(&pnp_bios_lock, flags);
36271 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36272 :"memory");
36273 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36274
36275 + pax_open_kernel();
36276 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36277 + pax_close_kernel();
36278 +
36279 put_cpu();
36280
36281 /* If we get here and this is set then the PnP BIOS faulted on us. */
36282 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36283 return status;
36284 }
36285
36286 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36287 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36288 {
36289 int i;
36290
36291 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36292 pnp_bios_callpoint.offset = header->fields.pm16offset;
36293 pnp_bios_callpoint.segment = PNP_CS16;
36294
36295 + pax_open_kernel();
36296 +
36297 for_each_possible_cpu(i) {
36298 struct desc_struct *gdt = get_cpu_gdt_table(i);
36299 if (!gdt)
36300 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36301 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36302 (unsigned long)__va(header->fields.pm16dseg));
36303 }
36304 +
36305 + pax_close_kernel();
36306 }
36307 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36308 index b0ecacb..7c9da2e 100644
36309 --- a/drivers/pnp/resource.c
36310 +++ b/drivers/pnp/resource.c
36311 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36312 return 1;
36313
36314 /* check if the resource is valid */
36315 - if (*irq < 0 || *irq > 15)
36316 + if (*irq > 15)
36317 return 0;
36318
36319 /* check if the resource is reserved */
36320 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36321 return 1;
36322
36323 /* check if the resource is valid */
36324 - if (*dma < 0 || *dma == 4 || *dma > 7)
36325 + if (*dma == 4 || *dma > 7)
36326 return 0;
36327
36328 /* check if the resource is reserved */
36329 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36330 index 1ed6ea0..77c0bd2 100644
36331 --- a/drivers/power/bq27x00_battery.c
36332 +++ b/drivers/power/bq27x00_battery.c
36333 @@ -72,7 +72,7 @@
36334 struct bq27x00_device_info;
36335 struct bq27x00_access_methods {
36336 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36337 -};
36338 +} __no_const;
36339
36340 enum bq27x00_chip { BQ27000, BQ27500 };
36341
36342 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36343 index a838e66..a9e1665 100644
36344 --- a/drivers/regulator/max8660.c
36345 +++ b/drivers/regulator/max8660.c
36346 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36347 max8660->shadow_regs[MAX8660_OVER1] = 5;
36348 } else {
36349 /* Otherwise devices can be toggled via software */
36350 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36351 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36352 + pax_open_kernel();
36353 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36354 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36355 + pax_close_kernel();
36356 }
36357
36358 /*
36359 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36360 index e8cfc99..072aee2 100644
36361 --- a/drivers/regulator/mc13892-regulator.c
36362 +++ b/drivers/regulator/mc13892-regulator.c
36363 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36364 }
36365 mc13xxx_unlock(mc13892);
36366
36367 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36368 + pax_open_kernel();
36369 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36370 = mc13892_vcam_set_mode;
36371 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36372 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36373 = mc13892_vcam_get_mode;
36374 + pax_close_kernel();
36375
36376 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36377 ARRAY_SIZE(mc13892_regulators));
36378 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36379 index cace6d3..f623fda 100644
36380 --- a/drivers/rtc/rtc-dev.c
36381 +++ b/drivers/rtc/rtc-dev.c
36382 @@ -14,6 +14,7 @@
36383 #include <linux/module.h>
36384 #include <linux/rtc.h>
36385 #include <linux/sched.h>
36386 +#include <linux/grsecurity.h>
36387 #include "rtc-core.h"
36388
36389 static dev_t rtc_devt;
36390 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36391 if (copy_from_user(&tm, uarg, sizeof(tm)))
36392 return -EFAULT;
36393
36394 + gr_log_timechange();
36395 +
36396 return rtc_set_time(rtc, &tm);
36397
36398 case RTC_PIE_ON:
36399 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36400 index ffb5878..e6d785c 100644
36401 --- a/drivers/scsi/aacraid/aacraid.h
36402 +++ b/drivers/scsi/aacraid/aacraid.h
36403 @@ -492,7 +492,7 @@ struct adapter_ops
36404 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36405 /* Administrative operations */
36406 int (*adapter_comm)(struct aac_dev * dev, int comm);
36407 -};
36408 +} __no_const;
36409
36410 /*
36411 * Define which interrupt handler needs to be installed
36412 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36413 index 705e13e..91c873c 100644
36414 --- a/drivers/scsi/aacraid/linit.c
36415 +++ b/drivers/scsi/aacraid/linit.c
36416 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36417 #elif defined(__devinitconst)
36418 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36419 #else
36420 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36421 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36422 #endif
36423 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36424 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36425 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36426 index d5ff142..49c0ebb 100644
36427 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36428 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36429 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36430 .lldd_control_phy = asd_control_phy,
36431 };
36432
36433 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36434 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36435 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36436 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36437 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36438 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36439 index a796de9..1ef20e1 100644
36440 --- a/drivers/scsi/bfa/bfa.h
36441 +++ b/drivers/scsi/bfa/bfa.h
36442 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36443 u32 *end);
36444 int cpe_vec_q0;
36445 int rme_vec_q0;
36446 -};
36447 +} __no_const;
36448 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36449
36450 struct bfa_faa_cbfn_s {
36451 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36452 index f0f80e2..8ec946b 100644
36453 --- a/drivers/scsi/bfa/bfa_fcpim.c
36454 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36455 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36456
36457 bfa_iotag_attach(fcp);
36458
36459 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36460 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36461 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36462 (fcp->num_itns * sizeof(struct bfa_itn_s));
36463 memset(fcp->itn_arr, 0,
36464 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36465 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36466 {
36467 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36468 - struct bfa_itn_s *itn;
36469 + bfa_itn_s_no_const *itn;
36470
36471 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36472 itn->isr = isr;
36473 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36474 index 36f26da..38a34a8 100644
36475 --- a/drivers/scsi/bfa/bfa_fcpim.h
36476 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36477 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36478 struct bfa_itn_s {
36479 bfa_isr_func_t isr;
36480 };
36481 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36482
36483 void 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 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36486 struct list_head iotag_tio_free_q; /* free IO resources */
36487 struct list_head iotag_unused_q; /* unused IO resources*/
36488 struct bfa_iotag_s *iotag_arr;
36489 - struct bfa_itn_s *itn_arr;
36490 + bfa_itn_s_no_const *itn_arr;
36491 int num_ioim_reqs;
36492 int num_fwtio_reqs;
36493 int num_itns;
36494 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36495 index 546d46b..642fa5b 100644
36496 --- a/drivers/scsi/bfa/bfa_ioc.h
36497 +++ b/drivers/scsi/bfa/bfa_ioc.h
36498 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36499 bfa_ioc_disable_cbfn_t disable_cbfn;
36500 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36501 bfa_ioc_reset_cbfn_t reset_cbfn;
36502 -};
36503 +} __no_const;
36504
36505 /*
36506 * IOC event notification mechanism.
36507 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36508 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36509 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36510 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36511 -};
36512 +} __no_const;
36513
36514 /*
36515 * Queue element to wait for room in request queue. FIFO order is
36516 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36517 index 351dc0b..951dc32 100644
36518 --- a/drivers/scsi/hosts.c
36519 +++ b/drivers/scsi/hosts.c
36520 @@ -42,7 +42,7 @@
36521 #include "scsi_logging.h"
36522
36523
36524 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36525 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36526
36527
36528 static void scsi_host_cls_release(struct device *dev)
36529 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36530 * subtract one because we increment first then return, but we need to
36531 * know what the next host number was before increment
36532 */
36533 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36534 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36535 shost->dma_channel = 0xff;
36536
36537 /* These three are default values which can be overridden */
36538 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36539 index b96962c..0c82ec2 100644
36540 --- a/drivers/scsi/hpsa.c
36541 +++ b/drivers/scsi/hpsa.c
36542 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36543 u32 a;
36544
36545 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36546 - return h->access.command_completed(h);
36547 + return h->access->command_completed(h);
36548
36549 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36550 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36551 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36552 while (!list_empty(&h->reqQ)) {
36553 c = list_entry(h->reqQ.next, struct CommandList, list);
36554 /* can't do anything if fifo is full */
36555 - if ((h->access.fifo_full(h))) {
36556 + if ((h->access->fifo_full(h))) {
36557 dev_warn(&h->pdev->dev, "fifo full\n");
36558 break;
36559 }
36560 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36561 h->Qdepth--;
36562
36563 /* Tell the controller execute command */
36564 - h->access.submit_command(h, c);
36565 + h->access->submit_command(h, c);
36566
36567 /* Put job onto the completed Q */
36568 addQ(&h->cmpQ, c);
36569 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36570
36571 static inline unsigned long get_next_completion(struct ctlr_info *h)
36572 {
36573 - return h->access.command_completed(h);
36574 + return h->access->command_completed(h);
36575 }
36576
36577 static inline bool interrupt_pending(struct ctlr_info *h)
36578 {
36579 - return h->access.intr_pending(h);
36580 + return h->access->intr_pending(h);
36581 }
36582
36583 static inline long interrupt_not_for_us(struct ctlr_info *h)
36584 {
36585 - return (h->access.intr_pending(h) == 0) ||
36586 + return (h->access->intr_pending(h) == 0) ||
36587 (h->interrupts_enabled == 0);
36588 }
36589
36590 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36591 if (prod_index < 0)
36592 return -ENODEV;
36593 h->product_name = products[prod_index].product_name;
36594 - h->access = *(products[prod_index].access);
36595 + h->access = products[prod_index].access;
36596
36597 if (hpsa_board_disabled(h->pdev)) {
36598 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36599 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36600
36601 assert_spin_locked(&lockup_detector_lock);
36602 remove_ctlr_from_lockup_detector_list(h);
36603 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36604 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36605 spin_lock_irqsave(&h->lock, flags);
36606 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36607 spin_unlock_irqrestore(&h->lock, flags);
36608 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36609 }
36610
36611 /* make sure the board interrupts are off */
36612 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36613 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36614
36615 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36616 goto clean2;
36617 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36618 * fake ones to scoop up any residual completions.
36619 */
36620 spin_lock_irqsave(&h->lock, flags);
36621 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36622 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36623 spin_unlock_irqrestore(&h->lock, flags);
36624 free_irq(h->intr[h->intr_mode], h);
36625 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36626 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36627 dev_info(&h->pdev->dev, "Board READY.\n");
36628 dev_info(&h->pdev->dev,
36629 "Waiting for stale completions to drain.\n");
36630 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36631 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36632 msleep(10000);
36633 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36634 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36635
36636 rc = controller_reset_failed(h->cfgtable);
36637 if (rc)
36638 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36639 }
36640
36641 /* Turn the interrupts on so we can service requests */
36642 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36643 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36644
36645 hpsa_hba_inquiry(h);
36646 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36647 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36648 * To write all data in the battery backed cache to disks
36649 */
36650 hpsa_flush_cache(h);
36651 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36652 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36653 free_irq(h->intr[h->intr_mode], h);
36654 #ifdef CONFIG_PCI_MSI
36655 if (h->msix_vector)
36656 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36657 return;
36658 }
36659 /* Change the access methods to the performant access methods */
36660 - h->access = SA5_performant_access;
36661 + h->access = &SA5_performant_access;
36662 h->transMethod = CFGTBL_Trans_Performant;
36663 }
36664
36665 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36666 index 91edafb..a9b88ec 100644
36667 --- a/drivers/scsi/hpsa.h
36668 +++ b/drivers/scsi/hpsa.h
36669 @@ -73,7 +73,7 @@ struct ctlr_info {
36670 unsigned int msix_vector;
36671 unsigned int msi_vector;
36672 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36673 - struct access_method access;
36674 + struct access_method *access;
36675
36676 /* queue and queue Info */
36677 struct list_head reqQ;
36678 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36679 index f2df059..a3a9930 100644
36680 --- a/drivers/scsi/ips.h
36681 +++ b/drivers/scsi/ips.h
36682 @@ -1027,7 +1027,7 @@ typedef struct {
36683 int (*intr)(struct ips_ha *);
36684 void (*enableint)(struct ips_ha *);
36685 uint32_t (*statupd)(struct ips_ha *);
36686 -} ips_hw_func_t;
36687 +} __no_const ips_hw_func_t;
36688
36689 typedef struct ips_ha {
36690 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36691 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36692 index 4d70d96..84d0573 100644
36693 --- a/drivers/scsi/libfc/fc_exch.c
36694 +++ b/drivers/scsi/libfc/fc_exch.c
36695 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36696 * all together if not used XXX
36697 */
36698 struct {
36699 - atomic_t no_free_exch;
36700 - atomic_t no_free_exch_xid;
36701 - atomic_t xid_not_found;
36702 - atomic_t xid_busy;
36703 - atomic_t seq_not_found;
36704 - atomic_t non_bls_resp;
36705 + atomic_unchecked_t no_free_exch;
36706 + atomic_unchecked_t no_free_exch_xid;
36707 + atomic_unchecked_t xid_not_found;
36708 + atomic_unchecked_t xid_busy;
36709 + atomic_unchecked_t seq_not_found;
36710 + atomic_unchecked_t non_bls_resp;
36711 } stats;
36712 };
36713
36714 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36715 /* allocate memory for exchange */
36716 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36717 if (!ep) {
36718 - atomic_inc(&mp->stats.no_free_exch);
36719 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36720 goto out;
36721 }
36722 memset(ep, 0, sizeof(*ep));
36723 @@ -780,7 +780,7 @@ out:
36724 return ep;
36725 err:
36726 spin_unlock_bh(&pool->lock);
36727 - atomic_inc(&mp->stats.no_free_exch_xid);
36728 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36729 mempool_free(ep, mp->ep_pool);
36730 return NULL;
36731 }
36732 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36733 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36734 ep = fc_exch_find(mp, xid);
36735 if (!ep) {
36736 - atomic_inc(&mp->stats.xid_not_found);
36737 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36738 reject = FC_RJT_OX_ID;
36739 goto out;
36740 }
36741 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36742 ep = fc_exch_find(mp, xid);
36743 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36744 if (ep) {
36745 - atomic_inc(&mp->stats.xid_busy);
36746 + atomic_inc_unchecked(&mp->stats.xid_busy);
36747 reject = FC_RJT_RX_ID;
36748 goto rel;
36749 }
36750 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36751 }
36752 xid = ep->xid; /* get our XID */
36753 } else if (!ep) {
36754 - atomic_inc(&mp->stats.xid_not_found);
36755 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36756 reject = FC_RJT_RX_ID; /* XID not found */
36757 goto out;
36758 }
36759 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36760 } else {
36761 sp = &ep->seq;
36762 if (sp->id != fh->fh_seq_id) {
36763 - atomic_inc(&mp->stats.seq_not_found);
36764 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36765 if (f_ctl & FC_FC_END_SEQ) {
36766 /*
36767 * Update sequence_id based on incoming last
36768 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36769
36770 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36771 if (!ep) {
36772 - atomic_inc(&mp->stats.xid_not_found);
36773 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36774 goto out;
36775 }
36776 if (ep->esb_stat & ESB_ST_COMPLETE) {
36777 - atomic_inc(&mp->stats.xid_not_found);
36778 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36779 goto rel;
36780 }
36781 if (ep->rxid == FC_XID_UNKNOWN)
36782 ep->rxid = ntohs(fh->fh_rx_id);
36783 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36784 - atomic_inc(&mp->stats.xid_not_found);
36785 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36786 goto rel;
36787 }
36788 if (ep->did != ntoh24(fh->fh_s_id) &&
36789 ep->did != FC_FID_FLOGI) {
36790 - atomic_inc(&mp->stats.xid_not_found);
36791 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36792 goto rel;
36793 }
36794 sof = fr_sof(fp);
36795 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36796 sp->ssb_stat |= SSB_ST_RESP;
36797 sp->id = fh->fh_seq_id;
36798 } else if (sp->id != fh->fh_seq_id) {
36799 - atomic_inc(&mp->stats.seq_not_found);
36800 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36801 goto rel;
36802 }
36803
36804 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36805 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36806
36807 if (!sp)
36808 - atomic_inc(&mp->stats.xid_not_found);
36809 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36810 else
36811 - atomic_inc(&mp->stats.non_bls_resp);
36812 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36813
36814 fc_frame_free(fp);
36815 }
36816 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36817 index db9238f..4378ed2 100644
36818 --- a/drivers/scsi/libsas/sas_ata.c
36819 +++ b/drivers/scsi/libsas/sas_ata.c
36820 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36821 .postreset = ata_std_postreset,
36822 .error_handler = ata_std_error_handler,
36823 .post_internal_cmd = sas_ata_post_internal,
36824 - .qc_defer = ata_std_qc_defer,
36825 + .qc_defer = ata_std_qc_defer,
36826 .qc_prep = ata_noop_qc_prep,
36827 .qc_issue = sas_ata_qc_issue,
36828 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36829 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36830 index 825f930..ce42672 100644
36831 --- a/drivers/scsi/lpfc/lpfc.h
36832 +++ b/drivers/scsi/lpfc/lpfc.h
36833 @@ -413,7 +413,7 @@ struct lpfc_vport {
36834 struct dentry *debug_nodelist;
36835 struct dentry *vport_debugfs_root;
36836 struct lpfc_debugfs_trc *disc_trc;
36837 - atomic_t disc_trc_cnt;
36838 + atomic_unchecked_t disc_trc_cnt;
36839 #endif
36840 uint8_t stat_data_enabled;
36841 uint8_t stat_data_blocked;
36842 @@ -821,8 +821,8 @@ struct lpfc_hba {
36843 struct timer_list fabric_block_timer;
36844 unsigned long bit_flags;
36845 #define FABRIC_COMANDS_BLOCKED 0
36846 - atomic_t num_rsrc_err;
36847 - atomic_t num_cmd_success;
36848 + atomic_unchecked_t num_rsrc_err;
36849 + atomic_unchecked_t num_cmd_success;
36850 unsigned long last_rsrc_error_time;
36851 unsigned long last_ramp_down_time;
36852 unsigned long last_ramp_up_time;
36853 @@ -852,7 +852,7 @@ struct lpfc_hba {
36854
36855 struct dentry *debug_slow_ring_trc;
36856 struct lpfc_debugfs_trc *slow_ring_trc;
36857 - atomic_t slow_ring_trc_cnt;
36858 + atomic_unchecked_t slow_ring_trc_cnt;
36859 /* iDiag debugfs sub-directory */
36860 struct dentry *idiag_root;
36861 struct dentry *idiag_pci_cfg;
36862 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36863 index 3587a3f..d45b81b 100644
36864 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36865 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36866 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36867
36868 #include <linux/debugfs.h>
36869
36870 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36871 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36872 static unsigned long lpfc_debugfs_start_time = 0L;
36873
36874 /* iDiag */
36875 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36876 lpfc_debugfs_enable = 0;
36877
36878 len = 0;
36879 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36880 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36881 (lpfc_debugfs_max_disc_trc - 1);
36882 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36883 dtp = vport->disc_trc + i;
36884 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36885 lpfc_debugfs_enable = 0;
36886
36887 len = 0;
36888 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36889 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36890 (lpfc_debugfs_max_slow_ring_trc - 1);
36891 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36892 dtp = phba->slow_ring_trc + i;
36893 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36894 !vport || !vport->disc_trc)
36895 return;
36896
36897 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36898 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36899 (lpfc_debugfs_max_disc_trc - 1);
36900 dtp = vport->disc_trc + index;
36901 dtp->fmt = fmt;
36902 dtp->data1 = data1;
36903 dtp->data2 = data2;
36904 dtp->data3 = data3;
36905 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36906 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36907 dtp->jif = jiffies;
36908 #endif
36909 return;
36910 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36911 !phba || !phba->slow_ring_trc)
36912 return;
36913
36914 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36915 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36916 (lpfc_debugfs_max_slow_ring_trc - 1);
36917 dtp = phba->slow_ring_trc + index;
36918 dtp->fmt = fmt;
36919 dtp->data1 = data1;
36920 dtp->data2 = data2;
36921 dtp->data3 = data3;
36922 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36923 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36924 dtp->jif = jiffies;
36925 #endif
36926 return;
36927 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36928 "slow_ring buffer\n");
36929 goto debug_failed;
36930 }
36931 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36932 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36933 memset(phba->slow_ring_trc, 0,
36934 (sizeof(struct lpfc_debugfs_trc) *
36935 lpfc_debugfs_max_slow_ring_trc));
36936 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36937 "buffer\n");
36938 goto debug_failed;
36939 }
36940 - atomic_set(&vport->disc_trc_cnt, 0);
36941 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36942
36943 snprintf(name, sizeof(name), "discovery_trace");
36944 vport->debug_disc_trc =
36945 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36946 index dfea2da..8e17227 100644
36947 --- a/drivers/scsi/lpfc/lpfc_init.c
36948 +++ b/drivers/scsi/lpfc/lpfc_init.c
36949 @@ -10145,8 +10145,10 @@ lpfc_init(void)
36950 printk(LPFC_COPYRIGHT "\n");
36951
36952 if (lpfc_enable_npiv) {
36953 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36954 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36955 + pax_open_kernel();
36956 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36957 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36958 + pax_close_kernel();
36959 }
36960 lpfc_transport_template =
36961 fc_attach_transport(&lpfc_transport_functions);
36962 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36963 index c60f5d0..751535c 100644
36964 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36965 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36966 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36967 uint32_t evt_posted;
36968
36969 spin_lock_irqsave(&phba->hbalock, flags);
36970 - atomic_inc(&phba->num_rsrc_err);
36971 + atomic_inc_unchecked(&phba->num_rsrc_err);
36972 phba->last_rsrc_error_time = jiffies;
36973
36974 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36975 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36976 unsigned long flags;
36977 struct lpfc_hba *phba = vport->phba;
36978 uint32_t evt_posted;
36979 - atomic_inc(&phba->num_cmd_success);
36980 + atomic_inc_unchecked(&phba->num_cmd_success);
36981
36982 if (vport->cfg_lun_queue_depth <= queue_depth)
36983 return;
36984 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36985 unsigned long num_rsrc_err, num_cmd_success;
36986 int i;
36987
36988 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36989 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36990 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36991 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36992
36993 vports = lpfc_create_vport_work_array(phba);
36994 if (vports != NULL)
36995 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36996 }
36997 }
36998 lpfc_destroy_vport_work_array(phba, vports);
36999 - atomic_set(&phba->num_rsrc_err, 0);
37000 - atomic_set(&phba->num_cmd_success, 0);
37001 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37002 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37003 }
37004
37005 /**
37006 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37007 }
37008 }
37009 lpfc_destroy_vport_work_array(phba, vports);
37010 - atomic_set(&phba->num_rsrc_err, 0);
37011 - atomic_set(&phba->num_cmd_success, 0);
37012 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37013 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37014 }
37015
37016 /**
37017 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37018 index ea8a0b4..812a124 100644
37019 --- a/drivers/scsi/pmcraid.c
37020 +++ b/drivers/scsi/pmcraid.c
37021 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37022 res->scsi_dev = scsi_dev;
37023 scsi_dev->hostdata = res;
37024 res->change_detected = 0;
37025 - atomic_set(&res->read_failures, 0);
37026 - atomic_set(&res->write_failures, 0);
37027 + atomic_set_unchecked(&res->read_failures, 0);
37028 + atomic_set_unchecked(&res->write_failures, 0);
37029 rc = 0;
37030 }
37031 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37032 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37033
37034 /* If this was a SCSI read/write command keep count of errors */
37035 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37036 - atomic_inc(&res->read_failures);
37037 + atomic_inc_unchecked(&res->read_failures);
37038 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37039 - atomic_inc(&res->write_failures);
37040 + atomic_inc_unchecked(&res->write_failures);
37041
37042 if (!RES_IS_GSCSI(res->cfg_entry) &&
37043 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37044 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37045 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37046 * hrrq_id assigned here in queuecommand
37047 */
37048 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37049 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37050 pinstance->num_hrrq;
37051 cmd->cmd_done = pmcraid_io_done;
37052
37053 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37054 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37055 * hrrq_id assigned here in queuecommand
37056 */
37057 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37058 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37059 pinstance->num_hrrq;
37060
37061 if (request_size) {
37062 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37063
37064 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37065 /* add resources only after host is added into system */
37066 - if (!atomic_read(&pinstance->expose_resources))
37067 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37068 return;
37069
37070 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37071 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37072 init_waitqueue_head(&pinstance->reset_wait_q);
37073
37074 atomic_set(&pinstance->outstanding_cmds, 0);
37075 - atomic_set(&pinstance->last_message_id, 0);
37076 - atomic_set(&pinstance->expose_resources, 0);
37077 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37078 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37079
37080 INIT_LIST_HEAD(&pinstance->free_res_q);
37081 INIT_LIST_HEAD(&pinstance->used_res_q);
37082 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37083 /* Schedule worker thread to handle CCN and take care of adding and
37084 * removing devices to OS
37085 */
37086 - atomic_set(&pinstance->expose_resources, 1);
37087 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37088 schedule_work(&pinstance->worker_q);
37089 return rc;
37090
37091 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37092 index ca496c7..9c791d5 100644
37093 --- a/drivers/scsi/pmcraid.h
37094 +++ b/drivers/scsi/pmcraid.h
37095 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37096 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37097
37098 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37099 - atomic_t last_message_id;
37100 + atomic_unchecked_t last_message_id;
37101
37102 /* configuration table */
37103 struct pmcraid_config_table *cfg_table;
37104 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37105 atomic_t outstanding_cmds;
37106
37107 /* should add/delete resources to mid-layer now ?*/
37108 - atomic_t expose_resources;
37109 + atomic_unchecked_t expose_resources;
37110
37111
37112
37113 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37114 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37115 };
37116 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37117 - atomic_t read_failures; /* count of failed READ commands */
37118 - atomic_t write_failures; /* count of failed WRITE commands */
37119 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37120 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37121
37122 /* To indicate add/delete/modify during CCN */
37123 u8 change_detected;
37124 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37125 index af1003f..be55a75 100644
37126 --- a/drivers/scsi/qla2xxx/qla_def.h
37127 +++ b/drivers/scsi/qla2xxx/qla_def.h
37128 @@ -2247,7 +2247,7 @@ struct isp_operations {
37129 int (*start_scsi) (srb_t *);
37130 int (*abort_isp) (struct scsi_qla_host *);
37131 int (*iospace_config)(struct qla_hw_data*);
37132 -};
37133 +} __no_const;
37134
37135 /* MSI-X Support *************************************************************/
37136
37137 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37138 index bfe6854..ceac088 100644
37139 --- a/drivers/scsi/qla4xxx/ql4_def.h
37140 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37141 @@ -261,7 +261,7 @@ struct ddb_entry {
37142 * (4000 only) */
37143 atomic_t relogin_timer; /* Max Time to wait for
37144 * relogin to complete */
37145 - atomic_t relogin_retry_count; /* Num of times relogin has been
37146 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37147 * retried */
37148 uint32_t default_time2wait; /* Default Min time between
37149 * relogins (+aens) */
37150 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37151 index ce6d3b7..73fac54 100644
37152 --- a/drivers/scsi/qla4xxx/ql4_os.c
37153 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37154 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37155 */
37156 if (!iscsi_is_session_online(cls_sess)) {
37157 /* Reset retry relogin timer */
37158 - atomic_inc(&ddb_entry->relogin_retry_count);
37159 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37160 DEBUG2(ql4_printk(KERN_INFO, ha,
37161 "%s: index[%d] relogin timed out-retrying"
37162 " relogin (%d), retry (%d)\n", __func__,
37163 ddb_entry->fw_ddb_index,
37164 - atomic_read(&ddb_entry->relogin_retry_count),
37165 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37166 ddb_entry->default_time2wait + 4));
37167 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37168 atomic_set(&ddb_entry->retry_relogin_timer,
37169 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37170
37171 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37172 atomic_set(&ddb_entry->relogin_timer, 0);
37173 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37174 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37175 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37176 ddb_entry->default_relogin_timeout =
37177 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37178 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37179 index 2aeb2e9..46e3925 100644
37180 --- a/drivers/scsi/scsi.c
37181 +++ b/drivers/scsi/scsi.c
37182 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37183 unsigned long timeout;
37184 int rtn = 0;
37185
37186 - atomic_inc(&cmd->device->iorequest_cnt);
37187 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37188
37189 /* check if the device is still usable */
37190 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37191 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37192 index b2c95db..227d74e 100644
37193 --- a/drivers/scsi/scsi_lib.c
37194 +++ b/drivers/scsi/scsi_lib.c
37195 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37196 shost = sdev->host;
37197 scsi_init_cmd_errh(cmd);
37198 cmd->result = DID_NO_CONNECT << 16;
37199 - atomic_inc(&cmd->device->iorequest_cnt);
37200 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37201
37202 /*
37203 * SCSI request completion path will do scsi_device_unbusy(),
37204 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37205
37206 INIT_LIST_HEAD(&cmd->eh_entry);
37207
37208 - atomic_inc(&cmd->device->iodone_cnt);
37209 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37210 if (cmd->result)
37211 - atomic_inc(&cmd->device->ioerr_cnt);
37212 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37213
37214 disposition = scsi_decide_disposition(cmd);
37215 if (disposition != SUCCESS &&
37216 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37217 index 04c2a27..9d8bd66 100644
37218 --- a/drivers/scsi/scsi_sysfs.c
37219 +++ b/drivers/scsi/scsi_sysfs.c
37220 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37221 char *buf) \
37222 { \
37223 struct scsi_device *sdev = to_scsi_device(dev); \
37224 - unsigned long long count = atomic_read(&sdev->field); \
37225 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37226 return snprintf(buf, 20, "0x%llx\n", count); \
37227 } \
37228 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37229 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37230 index 84a1fdf..693b0d6 100644
37231 --- a/drivers/scsi/scsi_tgt_lib.c
37232 +++ b/drivers/scsi/scsi_tgt_lib.c
37233 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37234 int err;
37235
37236 dprintk("%lx %u\n", uaddr, len);
37237 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37238 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37239 if (err) {
37240 /*
37241 * TODO: need to fixup sg_tablesize, max_segment_size,
37242 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37243 index f59d4a0..1d89407 100644
37244 --- a/drivers/scsi/scsi_transport_fc.c
37245 +++ b/drivers/scsi/scsi_transport_fc.c
37246 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37247 * Netlink Infrastructure
37248 */
37249
37250 -static atomic_t fc_event_seq;
37251 +static atomic_unchecked_t fc_event_seq;
37252
37253 /**
37254 * fc_get_event_number - Obtain the next sequential FC event number
37255 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37256 u32
37257 fc_get_event_number(void)
37258 {
37259 - return atomic_add_return(1, &fc_event_seq);
37260 + return atomic_add_return_unchecked(1, &fc_event_seq);
37261 }
37262 EXPORT_SYMBOL(fc_get_event_number);
37263
37264 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37265 {
37266 int error;
37267
37268 - atomic_set(&fc_event_seq, 0);
37269 + atomic_set_unchecked(&fc_event_seq, 0);
37270
37271 error = transport_class_register(&fc_host_class);
37272 if (error)
37273 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37274 char *cp;
37275
37276 *val = simple_strtoul(buf, &cp, 0);
37277 - if ((*cp && (*cp != '\n')) || (*val < 0))
37278 + if (*cp && (*cp != '\n'))
37279 return -EINVAL;
37280 /*
37281 * Check for overflow; dev_loss_tmo is u32
37282 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37283 index e3e3c7d..ebdab62 100644
37284 --- a/drivers/scsi/scsi_transport_iscsi.c
37285 +++ b/drivers/scsi/scsi_transport_iscsi.c
37286 @@ -79,7 +79,7 @@ struct iscsi_internal {
37287 struct transport_container session_cont;
37288 };
37289
37290 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37291 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37292 static struct workqueue_struct *iscsi_eh_timer_workq;
37293
37294 static DEFINE_IDA(iscsi_sess_ida);
37295 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37296 int err;
37297
37298 ihost = shost->shost_data;
37299 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37300 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37301
37302 if (target_id == ISCSI_MAX_TARGET) {
37303 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37304 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37305 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37306 ISCSI_TRANSPORT_VERSION);
37307
37308 - atomic_set(&iscsi_session_nr, 0);
37309 + atomic_set_unchecked(&iscsi_session_nr, 0);
37310
37311 err = class_register(&iscsi_transport_class);
37312 if (err)
37313 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37314 index 21a045e..ec89e03 100644
37315 --- a/drivers/scsi/scsi_transport_srp.c
37316 +++ b/drivers/scsi/scsi_transport_srp.c
37317 @@ -33,7 +33,7 @@
37318 #include "scsi_transport_srp_internal.h"
37319
37320 struct srp_host_attrs {
37321 - atomic_t next_port_id;
37322 + atomic_unchecked_t next_port_id;
37323 };
37324 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37325
37326 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37327 struct Scsi_Host *shost = dev_to_shost(dev);
37328 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37329
37330 - atomic_set(&srp_host->next_port_id, 0);
37331 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37332 return 0;
37333 }
37334
37335 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37336 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37337 rport->roles = ids->roles;
37338
37339 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37340 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37341 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37342
37343 transport_setup_device(&rport->dev);
37344 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37345 index eacd46b..e3f4d62 100644
37346 --- a/drivers/scsi/sg.c
37347 +++ b/drivers/scsi/sg.c
37348 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37349 sdp->disk->disk_name,
37350 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37351 NULL,
37352 - (char *)arg);
37353 + (char __user *)arg);
37354 case BLKTRACESTART:
37355 return blk_trace_startstop(sdp->device->request_queue, 1);
37356 case BLKTRACESTOP:
37357 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37358 const struct file_operations * fops;
37359 };
37360
37361 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37362 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37363 {"allow_dio", &adio_fops},
37364 {"debug", &debug_fops},
37365 {"def_reserved_size", &dressz_fops},
37366 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37367 if (!sg_proc_sgp)
37368 return 1;
37369 for (k = 0; k < num_leaves; ++k) {
37370 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37371 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37372 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37373 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37374 }
37375 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37376 index f64250e..1ee3049 100644
37377 --- a/drivers/spi/spi-dw-pci.c
37378 +++ b/drivers/spi/spi-dw-pci.c
37379 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37380 #define spi_resume NULL
37381 #endif
37382
37383 -static const struct pci_device_id pci_ids[] __devinitdata = {
37384 +static const struct pci_device_id pci_ids[] __devinitconst = {
37385 /* Intel MID platform SPI controller 0 */
37386 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37387 {},
37388 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37389 index b2ccdea..84cde75 100644
37390 --- a/drivers/spi/spi.c
37391 +++ b/drivers/spi/spi.c
37392 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37393 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37394
37395 /* portable code must never pass more than 32 bytes */
37396 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37397 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37398
37399 static u8 *buf;
37400
37401 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37402 index 400df8c..065d4f4 100644
37403 --- a/drivers/staging/octeon/ethernet-rx.c
37404 +++ b/drivers/staging/octeon/ethernet-rx.c
37405 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37406 /* Increment RX stats for virtual ports */
37407 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37408 #ifdef CONFIG_64BIT
37409 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37410 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37411 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37412 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37413 #else
37414 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37415 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37416 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37417 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37418 #endif
37419 }
37420 netif_receive_skb(skb);
37421 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37422 dev->name);
37423 */
37424 #ifdef CONFIG_64BIT
37425 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37426 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37427 #else
37428 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37429 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37430 #endif
37431 dev_kfree_skb_irq(skb);
37432 }
37433 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37434 index 9112cd8..92f8d51 100644
37435 --- a/drivers/staging/octeon/ethernet.c
37436 +++ b/drivers/staging/octeon/ethernet.c
37437 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37438 * since the RX tasklet also increments it.
37439 */
37440 #ifdef CONFIG_64BIT
37441 - atomic64_add(rx_status.dropped_packets,
37442 - (atomic64_t *)&priv->stats.rx_dropped);
37443 + atomic64_add_unchecked(rx_status.dropped_packets,
37444 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37445 #else
37446 - atomic_add(rx_status.dropped_packets,
37447 - (atomic_t *)&priv->stats.rx_dropped);
37448 + atomic_add_unchecked(rx_status.dropped_packets,
37449 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37450 #endif
37451 }
37452
37453 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37454 index f9dae95..ff48901 100644
37455 --- a/drivers/staging/rtl8192e/rtllib_module.c
37456 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37457 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37458 }
37459
37460 static int store_debug_level(struct file *file, const char __user *buffer,
37461 + unsigned long count, void *data) __size_overflow(3);
37462 +static int store_debug_level(struct file *file, const char __user *buffer,
37463 unsigned long count, void *data)
37464 {
37465 char buf[] = "0x00000000";
37466 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37467 index e3d47bc..85f4d0d 100644
37468 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37469 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37470 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37471 }
37472
37473 static int store_debug_level(struct file *file, const char *buffer,
37474 + unsigned long count, void *data) __size_overflow(3);
37475 +static int store_debug_level(struct file *file, const char *buffer,
37476 unsigned long count, void *data)
37477 {
37478 char buf[] = "0x00000000";
37479 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37480 index 86308a0..feaa925 100644
37481 --- a/drivers/staging/rtl8712/rtl871x_io.h
37482 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37483 @@ -108,7 +108,7 @@ struct _io_ops {
37484 u8 *pmem);
37485 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37486 u8 *pmem);
37487 -};
37488 +} __no_const;
37489
37490 struct io_req {
37491 struct list_head list;
37492 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37493 index c7b5e8b..783d6cb 100644
37494 --- a/drivers/staging/sbe-2t3e3/netdev.c
37495 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37496 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37497 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37498
37499 if (rlen)
37500 - if (copy_to_user(data, &resp, rlen))
37501 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37502 return -EFAULT;
37503
37504 return 0;
37505 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37506 index 42cdafe..2769103 100644
37507 --- a/drivers/staging/speakup/speakup_soft.c
37508 +++ b/drivers/staging/speakup/speakup_soft.c
37509 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37510 break;
37511 } else if (!initialized) {
37512 if (*init) {
37513 - ch = *init;
37514 init++;
37515 } else {
37516 initialized = 1;
37517 }
37518 + ch = *init;
37519 } else {
37520 ch = synth_buffer_getc();
37521 }
37522 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37523 index b8f8c48..1fc5025 100644
37524 --- a/drivers/staging/usbip/usbip_common.h
37525 +++ b/drivers/staging/usbip/usbip_common.h
37526 @@ -289,7 +289,7 @@ struct usbip_device {
37527 void (*shutdown)(struct usbip_device *);
37528 void (*reset)(struct usbip_device *);
37529 void (*unusable)(struct usbip_device *);
37530 - } eh_ops;
37531 + } __no_const eh_ops;
37532 };
37533
37534 /* usbip_common.c */
37535 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37536 index 88b3298..3783eee 100644
37537 --- a/drivers/staging/usbip/vhci.h
37538 +++ b/drivers/staging/usbip/vhci.h
37539 @@ -88,7 +88,7 @@ struct vhci_hcd {
37540 unsigned resuming:1;
37541 unsigned long re_timeout;
37542
37543 - atomic_t seqnum;
37544 + atomic_unchecked_t seqnum;
37545
37546 /*
37547 * NOTE:
37548 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37549 index 2ee97e2..0420b86 100644
37550 --- a/drivers/staging/usbip/vhci_hcd.c
37551 +++ b/drivers/staging/usbip/vhci_hcd.c
37552 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37553 return;
37554 }
37555
37556 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37557 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37558 if (priv->seqnum == 0xffff)
37559 dev_info(&urb->dev->dev, "seqnum max\n");
37560
37561 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37562 return -ENOMEM;
37563 }
37564
37565 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37566 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37567 if (unlink->seqnum == 0xffff)
37568 pr_info("seqnum max\n");
37569
37570 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37571 vdev->rhport = rhport;
37572 }
37573
37574 - atomic_set(&vhci->seqnum, 0);
37575 + atomic_set_unchecked(&vhci->seqnum, 0);
37576 spin_lock_init(&vhci->lock);
37577
37578 hcd->power_budget = 0; /* no limit */
37579 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37580 index 3f511b4..d3dbc1e 100644
37581 --- a/drivers/staging/usbip/vhci_rx.c
37582 +++ b/drivers/staging/usbip/vhci_rx.c
37583 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37584 if (!urb) {
37585 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37586 pr_info("max seqnum %d\n",
37587 - atomic_read(&the_controller->seqnum));
37588 + atomic_read_unchecked(&the_controller->seqnum));
37589 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37590 return;
37591 }
37592 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37593 index 7735027..30eed13 100644
37594 --- a/drivers/staging/vt6655/hostap.c
37595 +++ b/drivers/staging/vt6655/hostap.c
37596 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37597 *
37598 */
37599
37600 +static net_device_ops_no_const apdev_netdev_ops;
37601 +
37602 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37603 {
37604 PSDevice apdev_priv;
37605 struct net_device *dev = pDevice->dev;
37606 int ret;
37607 - const struct net_device_ops apdev_netdev_ops = {
37608 - .ndo_start_xmit = pDevice->tx_80211,
37609 - };
37610
37611 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37612
37613 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37614 *apdev_priv = *pDevice;
37615 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37616
37617 + /* only half broken now */
37618 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37619 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37620
37621 pDevice->apdev->type = ARPHRD_IEEE80211;
37622 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37623 index 51b5adf..098e320 100644
37624 --- a/drivers/staging/vt6656/hostap.c
37625 +++ b/drivers/staging/vt6656/hostap.c
37626 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37627 *
37628 */
37629
37630 +static net_device_ops_no_const apdev_netdev_ops;
37631 +
37632 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37633 {
37634 PSDevice apdev_priv;
37635 struct net_device *dev = pDevice->dev;
37636 int ret;
37637 - const struct net_device_ops apdev_netdev_ops = {
37638 - .ndo_start_xmit = pDevice->tx_80211,
37639 - };
37640
37641 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37642
37643 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37644 *apdev_priv = *pDevice;
37645 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37646
37647 + /* only half broken now */
37648 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37649 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37650
37651 pDevice->apdev->type = ARPHRD_IEEE80211;
37652 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37653 index 7843dfd..3db105f 100644
37654 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37655 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37656 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37657
37658 struct usbctlx_completor {
37659 int (*complete) (struct usbctlx_completor *);
37660 -};
37661 +} __no_const;
37662
37663 static int
37664 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37665 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37666 index 1ca66ea..76f1343 100644
37667 --- a/drivers/staging/zcache/tmem.c
37668 +++ b/drivers/staging/zcache/tmem.c
37669 @@ -39,7 +39,7 @@
37670 * A tmem host implementation must use this function to register callbacks
37671 * for memory allocation.
37672 */
37673 -static struct tmem_hostops tmem_hostops;
37674 +static tmem_hostops_no_const tmem_hostops;
37675
37676 static void tmem_objnode_tree_init(void);
37677
37678 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37679 * A tmem host implementation must use this function to register
37680 * callbacks for a page-accessible memory (PAM) implementation
37681 */
37682 -static struct tmem_pamops tmem_pamops;
37683 +static tmem_pamops_no_const tmem_pamops;
37684
37685 void tmem_register_pamops(struct tmem_pamops *m)
37686 {
37687 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37688 index ed147c4..94fc3c6 100644
37689 --- a/drivers/staging/zcache/tmem.h
37690 +++ b/drivers/staging/zcache/tmem.h
37691 @@ -180,6 +180,7 @@ struct tmem_pamops {
37692 void (*new_obj)(struct tmem_obj *);
37693 int (*replace_in_obj)(void *, struct tmem_obj *);
37694 };
37695 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37696 extern void tmem_register_pamops(struct tmem_pamops *m);
37697
37698 /* memory allocation methods provided by the host implementation */
37699 @@ -189,6 +190,7 @@ struct tmem_hostops {
37700 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37701 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37702 };
37703 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37704 extern void tmem_register_hostops(struct tmem_hostops *m);
37705
37706 /* core tmem accessor functions */
37707 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37708 index 97c74ee..7f6d77d 100644
37709 --- a/drivers/target/iscsi/iscsi_target.c
37710 +++ b/drivers/target/iscsi/iscsi_target.c
37711 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37712 * outstanding_r2ts reaches zero, go ahead and send the delayed
37713 * TASK_ABORTED status.
37714 */
37715 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37716 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37717 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37718 if (--cmd->outstanding_r2ts < 1) {
37719 iscsit_stop_dataout_timer(cmd);
37720 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37721 index dcb0618..97e3d85 100644
37722 --- a/drivers/target/target_core_tmr.c
37723 +++ b/drivers/target/target_core_tmr.c
37724 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37725 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37726 cmd->t_task_list_num,
37727 atomic_read(&cmd->t_task_cdbs_left),
37728 - atomic_read(&cmd->t_task_cdbs_sent),
37729 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37730 atomic_read(&cmd->t_transport_active),
37731 atomic_read(&cmd->t_transport_stop),
37732 atomic_read(&cmd->t_transport_sent));
37733 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37734 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37735 " task: %p, t_fe_count: %d dev: %p\n", task,
37736 fe_count, dev);
37737 - atomic_set(&cmd->t_transport_aborted, 1);
37738 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37739 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37740
37741 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37742 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37743 }
37744 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37745 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37746 - atomic_set(&cmd->t_transport_aborted, 1);
37747 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37748 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37749
37750 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37751 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37752 index cd5cd95..5249d30 100644
37753 --- a/drivers/target/target_core_transport.c
37754 +++ b/drivers/target/target_core_transport.c
37755 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37756 spin_lock_init(&dev->se_port_lock);
37757 spin_lock_init(&dev->se_tmr_lock);
37758 spin_lock_init(&dev->qf_cmd_lock);
37759 - atomic_set(&dev->dev_ordered_id, 0);
37760 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37761
37762 se_dev_set_default_attribs(dev, dev_limits);
37763
37764 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37765 * Used to determine when ORDERED commands should go from
37766 * Dormant to Active status.
37767 */
37768 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37769 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37770 smp_mb__after_atomic_inc();
37771 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37772 cmd->se_ordered_id, cmd->sam_task_attr,
37773 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37774 " t_transport_active: %d t_transport_stop: %d"
37775 " t_transport_sent: %d\n", cmd->t_task_list_num,
37776 atomic_read(&cmd->t_task_cdbs_left),
37777 - atomic_read(&cmd->t_task_cdbs_sent),
37778 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37779 atomic_read(&cmd->t_task_cdbs_ex_left),
37780 atomic_read(&cmd->t_transport_active),
37781 atomic_read(&cmd->t_transport_stop),
37782 @@ -2121,9 +2121,9 @@ check_depth:
37783 cmd = task->task_se_cmd;
37784 spin_lock_irqsave(&cmd->t_state_lock, flags);
37785 task->task_flags |= (TF_ACTIVE | TF_SENT);
37786 - atomic_inc(&cmd->t_task_cdbs_sent);
37787 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37788
37789 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37790 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37791 cmd->t_task_list_num)
37792 atomic_set(&cmd->t_transport_sent, 1);
37793
37794 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37795 atomic_set(&cmd->transport_lun_stop, 0);
37796 }
37797 if (!atomic_read(&cmd->t_transport_active) ||
37798 - atomic_read(&cmd->t_transport_aborted)) {
37799 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37800 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37801 return false;
37802 }
37803 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37804 {
37805 int ret = 0;
37806
37807 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37808 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37809 if (!send_status ||
37810 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37811 return 1;
37812 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37813 */
37814 if (cmd->data_direction == DMA_TO_DEVICE) {
37815 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37816 - atomic_inc(&cmd->t_transport_aborted);
37817 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37818 smp_mb__after_atomic_inc();
37819 }
37820 }
37821 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37822 index b9040be..e3f5aab 100644
37823 --- a/drivers/tty/hvc/hvcs.c
37824 +++ b/drivers/tty/hvc/hvcs.c
37825 @@ -83,6 +83,7 @@
37826 #include <asm/hvcserver.h>
37827 #include <asm/uaccess.h>
37828 #include <asm/vio.h>
37829 +#include <asm/local.h>
37830
37831 /*
37832 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37833 @@ -270,7 +271,7 @@ struct hvcs_struct {
37834 unsigned int index;
37835
37836 struct tty_struct *tty;
37837 - int open_count;
37838 + local_t open_count;
37839
37840 /*
37841 * Used to tell the driver kernel_thread what operations need to take
37842 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37843
37844 spin_lock_irqsave(&hvcsd->lock, flags);
37845
37846 - if (hvcsd->open_count > 0) {
37847 + if (local_read(&hvcsd->open_count) > 0) {
37848 spin_unlock_irqrestore(&hvcsd->lock, flags);
37849 printk(KERN_INFO "HVCS: vterm state unchanged. "
37850 "The hvcs device node is still in use.\n");
37851 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37852 if ((retval = hvcs_partner_connect(hvcsd)))
37853 goto error_release;
37854
37855 - hvcsd->open_count = 1;
37856 + local_set(&hvcsd->open_count, 1);
37857 hvcsd->tty = tty;
37858 tty->driver_data = hvcsd;
37859
37860 @@ -1179,7 +1180,7 @@ fast_open:
37861
37862 spin_lock_irqsave(&hvcsd->lock, flags);
37863 kref_get(&hvcsd->kref);
37864 - hvcsd->open_count++;
37865 + local_inc(&hvcsd->open_count);
37866 hvcsd->todo_mask |= HVCS_SCHED_READ;
37867 spin_unlock_irqrestore(&hvcsd->lock, flags);
37868
37869 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37870 hvcsd = tty->driver_data;
37871
37872 spin_lock_irqsave(&hvcsd->lock, flags);
37873 - if (--hvcsd->open_count == 0) {
37874 + if (local_dec_and_test(&hvcsd->open_count)) {
37875
37876 vio_disable_interrupts(hvcsd->vdev);
37877
37878 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37879 free_irq(irq, hvcsd);
37880 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37881 return;
37882 - } else if (hvcsd->open_count < 0) {
37883 + } else if (local_read(&hvcsd->open_count) < 0) {
37884 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37885 " is missmanaged.\n",
37886 - hvcsd->vdev->unit_address, hvcsd->open_count);
37887 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37888 }
37889
37890 spin_unlock_irqrestore(&hvcsd->lock, flags);
37891 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37892
37893 spin_lock_irqsave(&hvcsd->lock, flags);
37894 /* Preserve this so that we know how many kref refs to put */
37895 - temp_open_count = hvcsd->open_count;
37896 + temp_open_count = local_read(&hvcsd->open_count);
37897
37898 /*
37899 * Don't kref put inside the spinlock because the destruction
37900 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37901 hvcsd->tty->driver_data = NULL;
37902 hvcsd->tty = NULL;
37903
37904 - hvcsd->open_count = 0;
37905 + local_set(&hvcsd->open_count, 0);
37906
37907 /* This will drop any buffered data on the floor which is OK in a hangup
37908 * scenario. */
37909 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37910 * the middle of a write operation? This is a crummy place to do this
37911 * but we want to keep it all in the spinlock.
37912 */
37913 - if (hvcsd->open_count <= 0) {
37914 + if (local_read(&hvcsd->open_count) <= 0) {
37915 spin_unlock_irqrestore(&hvcsd->lock, flags);
37916 return -ENODEV;
37917 }
37918 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37919 {
37920 struct hvcs_struct *hvcsd = tty->driver_data;
37921
37922 - if (!hvcsd || hvcsd->open_count <= 0)
37923 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37924 return 0;
37925
37926 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37927 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37928 index ef92869..f4ebd88 100644
37929 --- a/drivers/tty/ipwireless/tty.c
37930 +++ b/drivers/tty/ipwireless/tty.c
37931 @@ -29,6 +29,7 @@
37932 #include <linux/tty_driver.h>
37933 #include <linux/tty_flip.h>
37934 #include <linux/uaccess.h>
37935 +#include <asm/local.h>
37936
37937 #include "tty.h"
37938 #include "network.h"
37939 @@ -51,7 +52,7 @@ struct ipw_tty {
37940 int tty_type;
37941 struct ipw_network *network;
37942 struct tty_struct *linux_tty;
37943 - int open_count;
37944 + local_t open_count;
37945 unsigned int control_lines;
37946 struct mutex ipw_tty_mutex;
37947 int tx_bytes_queued;
37948 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37949 mutex_unlock(&tty->ipw_tty_mutex);
37950 return -ENODEV;
37951 }
37952 - if (tty->open_count == 0)
37953 + if (local_read(&tty->open_count) == 0)
37954 tty->tx_bytes_queued = 0;
37955
37956 - tty->open_count++;
37957 + local_inc(&tty->open_count);
37958
37959 tty->linux_tty = linux_tty;
37960 linux_tty->driver_data = tty;
37961 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37962
37963 static void do_ipw_close(struct ipw_tty *tty)
37964 {
37965 - tty->open_count--;
37966 -
37967 - if (tty->open_count == 0) {
37968 + if (local_dec_return(&tty->open_count) == 0) {
37969 struct tty_struct *linux_tty = tty->linux_tty;
37970
37971 if (linux_tty != NULL) {
37972 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37973 return;
37974
37975 mutex_lock(&tty->ipw_tty_mutex);
37976 - if (tty->open_count == 0) {
37977 + if (local_read(&tty->open_count) == 0) {
37978 mutex_unlock(&tty->ipw_tty_mutex);
37979 return;
37980 }
37981 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37982 return;
37983 }
37984
37985 - if (!tty->open_count) {
37986 + if (!local_read(&tty->open_count)) {
37987 mutex_unlock(&tty->ipw_tty_mutex);
37988 return;
37989 }
37990 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37991 return -ENODEV;
37992
37993 mutex_lock(&tty->ipw_tty_mutex);
37994 - if (!tty->open_count) {
37995 + if (!local_read(&tty->open_count)) {
37996 mutex_unlock(&tty->ipw_tty_mutex);
37997 return -EINVAL;
37998 }
37999 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38000 if (!tty)
38001 return -ENODEV;
38002
38003 - if (!tty->open_count)
38004 + if (!local_read(&tty->open_count))
38005 return -EINVAL;
38006
38007 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38008 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38009 if (!tty)
38010 return 0;
38011
38012 - if (!tty->open_count)
38013 + if (!local_read(&tty->open_count))
38014 return 0;
38015
38016 return tty->tx_bytes_queued;
38017 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38018 if (!tty)
38019 return -ENODEV;
38020
38021 - if (!tty->open_count)
38022 + if (!local_read(&tty->open_count))
38023 return -EINVAL;
38024
38025 return get_control_lines(tty);
38026 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38027 if (!tty)
38028 return -ENODEV;
38029
38030 - if (!tty->open_count)
38031 + if (!local_read(&tty->open_count))
38032 return -EINVAL;
38033
38034 return set_control_lines(tty, set, clear);
38035 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38036 if (!tty)
38037 return -ENODEV;
38038
38039 - if (!tty->open_count)
38040 + if (!local_read(&tty->open_count))
38041 return -EINVAL;
38042
38043 /* FIXME: Exactly how is the tty object locked here .. */
38044 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38045 against a parallel ioctl etc */
38046 mutex_lock(&ttyj->ipw_tty_mutex);
38047 }
38048 - while (ttyj->open_count)
38049 + while (local_read(&ttyj->open_count))
38050 do_ipw_close(ttyj);
38051 ipwireless_disassociate_network_ttys(network,
38052 ttyj->channel_idx);
38053 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38054 index fc7bbba..9527e93 100644
38055 --- a/drivers/tty/n_gsm.c
38056 +++ b/drivers/tty/n_gsm.c
38057 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38058 kref_init(&dlci->ref);
38059 mutex_init(&dlci->mutex);
38060 dlci->fifo = &dlci->_fifo;
38061 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38062 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38063 kfree(dlci);
38064 return NULL;
38065 }
38066 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38067 index d2256d0..97476fa 100644
38068 --- a/drivers/tty/n_tty.c
38069 +++ b/drivers/tty/n_tty.c
38070 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38071 {
38072 *ops = tty_ldisc_N_TTY;
38073 ops->owner = NULL;
38074 - ops->refcount = ops->flags = 0;
38075 + atomic_set(&ops->refcount, 0);
38076 + ops->flags = 0;
38077 }
38078 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38079 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38080 index d8653ab..f8afd9d 100644
38081 --- a/drivers/tty/pty.c
38082 +++ b/drivers/tty/pty.c
38083 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38084 register_sysctl_table(pty_root_table);
38085
38086 /* Now create the /dev/ptmx special device */
38087 + pax_open_kernel();
38088 tty_default_fops(&ptmx_fops);
38089 - ptmx_fops.open = ptmx_open;
38090 + *(void **)&ptmx_fops.open = ptmx_open;
38091 + pax_close_kernel();
38092
38093 cdev_init(&ptmx_cdev, &ptmx_fops);
38094 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38095 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38096 index 2b42a01..32a2ed3 100644
38097 --- a/drivers/tty/serial/kgdboc.c
38098 +++ b/drivers/tty/serial/kgdboc.c
38099 @@ -24,8 +24,9 @@
38100 #define MAX_CONFIG_LEN 40
38101
38102 static struct kgdb_io kgdboc_io_ops;
38103 +static struct kgdb_io kgdboc_io_ops_console;
38104
38105 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38106 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38107 static int configured = -1;
38108
38109 static char config[MAX_CONFIG_LEN];
38110 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38111 kgdboc_unregister_kbd();
38112 if (configured == 1)
38113 kgdb_unregister_io_module(&kgdboc_io_ops);
38114 + else if (configured == 2)
38115 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38116 }
38117
38118 static int configure_kgdboc(void)
38119 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38120 int err;
38121 char *cptr = config;
38122 struct console *cons;
38123 + int is_console = 0;
38124
38125 err = kgdboc_option_setup(config);
38126 if (err || !strlen(config) || isspace(config[0]))
38127 goto noconfig;
38128
38129 err = -ENODEV;
38130 - kgdboc_io_ops.is_console = 0;
38131 kgdb_tty_driver = NULL;
38132
38133 kgdboc_use_kms = 0;
38134 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38135 int idx;
38136 if (cons->device && cons->device(cons, &idx) == p &&
38137 idx == tty_line) {
38138 - kgdboc_io_ops.is_console = 1;
38139 + is_console = 1;
38140 break;
38141 }
38142 cons = cons->next;
38143 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38144 kgdb_tty_line = tty_line;
38145
38146 do_register:
38147 - err = kgdb_register_io_module(&kgdboc_io_ops);
38148 + if (is_console) {
38149 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38150 + configured = 2;
38151 + } else {
38152 + err = kgdb_register_io_module(&kgdboc_io_ops);
38153 + configured = 1;
38154 + }
38155 if (err)
38156 goto noconfig;
38157
38158 - configured = 1;
38159 -
38160 return 0;
38161
38162 noconfig:
38163 @@ -213,7 +220,7 @@ noconfig:
38164 static int __init init_kgdboc(void)
38165 {
38166 /* Already configured? */
38167 - if (configured == 1)
38168 + if (configured >= 1)
38169 return 0;
38170
38171 return configure_kgdboc();
38172 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38173 if (config[len - 1] == '\n')
38174 config[len - 1] = '\0';
38175
38176 - if (configured == 1)
38177 + if (configured >= 1)
38178 cleanup_kgdboc();
38179
38180 /* Go and configure with the new params. */
38181 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38182 .post_exception = kgdboc_post_exp_handler,
38183 };
38184
38185 +static struct kgdb_io kgdboc_io_ops_console = {
38186 + .name = "kgdboc",
38187 + .read_char = kgdboc_get_char,
38188 + .write_char = kgdboc_put_char,
38189 + .pre_exception = kgdboc_pre_exp_handler,
38190 + .post_exception = kgdboc_post_exp_handler,
38191 + .is_console = 1
38192 +};
38193 +
38194 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38195 /* This is only available if kgdboc is a built in for early debugging */
38196 static int __init kgdboc_early_init(char *opt)
38197 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38198 index 7867b7c..b3c119d 100644
38199 --- a/drivers/tty/sysrq.c
38200 +++ b/drivers/tty/sysrq.c
38201 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38202 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38203 size_t count, loff_t *ppos)
38204 {
38205 - if (count) {
38206 + if (count && capable(CAP_SYS_ADMIN)) {
38207 char c;
38208
38209 if (get_user(c, buf))
38210 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38211 index e41b9bb..84002fb 100644
38212 --- a/drivers/tty/tty_io.c
38213 +++ b/drivers/tty/tty_io.c
38214 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38215
38216 void tty_default_fops(struct file_operations *fops)
38217 {
38218 - *fops = tty_fops;
38219 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38220 }
38221
38222 /*
38223 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38224 index 24b95db..9c078d0 100644
38225 --- a/drivers/tty/tty_ldisc.c
38226 +++ b/drivers/tty/tty_ldisc.c
38227 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38228 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38229 struct tty_ldisc_ops *ldo = ld->ops;
38230
38231 - ldo->refcount--;
38232 + atomic_dec(&ldo->refcount);
38233 module_put(ldo->owner);
38234 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38235
38236 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38237 spin_lock_irqsave(&tty_ldisc_lock, flags);
38238 tty_ldiscs[disc] = new_ldisc;
38239 new_ldisc->num = disc;
38240 - new_ldisc->refcount = 0;
38241 + atomic_set(&new_ldisc->refcount, 0);
38242 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38243
38244 return ret;
38245 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38246 return -EINVAL;
38247
38248 spin_lock_irqsave(&tty_ldisc_lock, flags);
38249 - if (tty_ldiscs[disc]->refcount)
38250 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38251 ret = -EBUSY;
38252 else
38253 tty_ldiscs[disc] = NULL;
38254 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38255 if (ldops) {
38256 ret = ERR_PTR(-EAGAIN);
38257 if (try_module_get(ldops->owner)) {
38258 - ldops->refcount++;
38259 + atomic_inc(&ldops->refcount);
38260 ret = ldops;
38261 }
38262 }
38263 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38264 unsigned long flags;
38265
38266 spin_lock_irqsave(&tty_ldisc_lock, flags);
38267 - ldops->refcount--;
38268 + atomic_dec(&ldops->refcount);
38269 module_put(ldops->owner);
38270 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38271 }
38272 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38273 index a605549..6bd3c96 100644
38274 --- a/drivers/tty/vt/keyboard.c
38275 +++ b/drivers/tty/vt/keyboard.c
38276 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38277 kbd->kbdmode == VC_OFF) &&
38278 value != KVAL(K_SAK))
38279 return; /* SAK is allowed even in raw mode */
38280 +
38281 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38282 + {
38283 + void *func = fn_handler[value];
38284 + if (func == fn_show_state || func == fn_show_ptregs ||
38285 + func == fn_show_mem)
38286 + return;
38287 + }
38288 +#endif
38289 +
38290 fn_handler[value](vc);
38291 }
38292
38293 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38294 index 65447c5..0526f0a 100644
38295 --- a/drivers/tty/vt/vt_ioctl.c
38296 +++ b/drivers/tty/vt/vt_ioctl.c
38297 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38298 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38299 return -EFAULT;
38300
38301 - if (!capable(CAP_SYS_TTY_CONFIG))
38302 - perm = 0;
38303 -
38304 switch (cmd) {
38305 case KDGKBENT:
38306 key_map = key_maps[s];
38307 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38308 val = (i ? K_HOLE : K_NOSUCHMAP);
38309 return put_user(val, &user_kbe->kb_value);
38310 case KDSKBENT:
38311 + if (!capable(CAP_SYS_TTY_CONFIG))
38312 + perm = 0;
38313 +
38314 if (!perm)
38315 return -EPERM;
38316 if (!i && v == K_NOSUCHMAP) {
38317 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38318 int i, j, k;
38319 int ret;
38320
38321 - if (!capable(CAP_SYS_TTY_CONFIG))
38322 - perm = 0;
38323 -
38324 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38325 if (!kbs) {
38326 ret = -ENOMEM;
38327 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38328 kfree(kbs);
38329 return ((p && *p) ? -EOVERFLOW : 0);
38330 case KDSKBSENT:
38331 + if (!capable(CAP_SYS_TTY_CONFIG))
38332 + perm = 0;
38333 +
38334 if (!perm) {
38335 ret = -EPERM;
38336 goto reterr;
38337 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38338 index a783d53..cb30d94 100644
38339 --- a/drivers/uio/uio.c
38340 +++ b/drivers/uio/uio.c
38341 @@ -25,6 +25,7 @@
38342 #include <linux/kobject.h>
38343 #include <linux/cdev.h>
38344 #include <linux/uio_driver.h>
38345 +#include <asm/local.h>
38346
38347 #define UIO_MAX_DEVICES (1U << MINORBITS)
38348
38349 @@ -32,10 +33,10 @@ struct uio_device {
38350 struct module *owner;
38351 struct device *dev;
38352 int minor;
38353 - atomic_t event;
38354 + atomic_unchecked_t event;
38355 struct fasync_struct *async_queue;
38356 wait_queue_head_t wait;
38357 - int vma_count;
38358 + local_t vma_count;
38359 struct uio_info *info;
38360 struct kobject *map_dir;
38361 struct kobject *portio_dir;
38362 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38363 struct device_attribute *attr, char *buf)
38364 {
38365 struct uio_device *idev = dev_get_drvdata(dev);
38366 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38367 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38368 }
38369
38370 static struct device_attribute uio_class_attributes[] = {
38371 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38372 {
38373 struct uio_device *idev = info->uio_dev;
38374
38375 - atomic_inc(&idev->event);
38376 + atomic_inc_unchecked(&idev->event);
38377 wake_up_interruptible(&idev->wait);
38378 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38379 }
38380 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38381 }
38382
38383 listener->dev = idev;
38384 - listener->event_count = atomic_read(&idev->event);
38385 + listener->event_count = atomic_read_unchecked(&idev->event);
38386 filep->private_data = listener;
38387
38388 if (idev->info->open) {
38389 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38390 return -EIO;
38391
38392 poll_wait(filep, &idev->wait, wait);
38393 - if (listener->event_count != atomic_read(&idev->event))
38394 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38395 return POLLIN | POLLRDNORM;
38396 return 0;
38397 }
38398 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38399 do {
38400 set_current_state(TASK_INTERRUPTIBLE);
38401
38402 - event_count = atomic_read(&idev->event);
38403 + event_count = atomic_read_unchecked(&idev->event);
38404 if (event_count != listener->event_count) {
38405 if (copy_to_user(buf, &event_count, count))
38406 retval = -EFAULT;
38407 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38408 static void uio_vma_open(struct vm_area_struct *vma)
38409 {
38410 struct uio_device *idev = vma->vm_private_data;
38411 - idev->vma_count++;
38412 + local_inc(&idev->vma_count);
38413 }
38414
38415 static void uio_vma_close(struct vm_area_struct *vma)
38416 {
38417 struct uio_device *idev = vma->vm_private_data;
38418 - idev->vma_count--;
38419 + local_dec(&idev->vma_count);
38420 }
38421
38422 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38423 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38424 idev->owner = owner;
38425 idev->info = info;
38426 init_waitqueue_head(&idev->wait);
38427 - atomic_set(&idev->event, 0);
38428 + atomic_set_unchecked(&idev->event, 0);
38429
38430 ret = uio_get_minor(idev);
38431 if (ret)
38432 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38433 index 98b89fe..aff824e 100644
38434 --- a/drivers/usb/atm/cxacru.c
38435 +++ b/drivers/usb/atm/cxacru.c
38436 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38437 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38438 if (ret < 2)
38439 return -EINVAL;
38440 - if (index < 0 || index > 0x7f)
38441 + if (index > 0x7f)
38442 return -EINVAL;
38443 pos += tmp;
38444
38445 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38446 index d3448ca..d2864ca 100644
38447 --- a/drivers/usb/atm/usbatm.c
38448 +++ b/drivers/usb/atm/usbatm.c
38449 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38450 if (printk_ratelimit())
38451 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38452 __func__, vpi, vci);
38453 - atomic_inc(&vcc->stats->rx_err);
38454 + atomic_inc_unchecked(&vcc->stats->rx_err);
38455 return;
38456 }
38457
38458 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38459 if (length > ATM_MAX_AAL5_PDU) {
38460 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38461 __func__, length, vcc);
38462 - atomic_inc(&vcc->stats->rx_err);
38463 + atomic_inc_unchecked(&vcc->stats->rx_err);
38464 goto out;
38465 }
38466
38467 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38468 if (sarb->len < pdu_length) {
38469 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38470 __func__, pdu_length, sarb->len, vcc);
38471 - atomic_inc(&vcc->stats->rx_err);
38472 + atomic_inc_unchecked(&vcc->stats->rx_err);
38473 goto out;
38474 }
38475
38476 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38477 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38478 __func__, vcc);
38479 - atomic_inc(&vcc->stats->rx_err);
38480 + atomic_inc_unchecked(&vcc->stats->rx_err);
38481 goto out;
38482 }
38483
38484 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38485 if (printk_ratelimit())
38486 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38487 __func__, length);
38488 - atomic_inc(&vcc->stats->rx_drop);
38489 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38490 goto out;
38491 }
38492
38493 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38494
38495 vcc->push(vcc, skb);
38496
38497 - atomic_inc(&vcc->stats->rx);
38498 + atomic_inc_unchecked(&vcc->stats->rx);
38499 out:
38500 skb_trim(sarb, 0);
38501 }
38502 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38503 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38504
38505 usbatm_pop(vcc, skb);
38506 - atomic_inc(&vcc->stats->tx);
38507 + atomic_inc_unchecked(&vcc->stats->tx);
38508
38509 skb = skb_dequeue(&instance->sndqueue);
38510 }
38511 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38512 if (!left--)
38513 return sprintf(page,
38514 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38515 - atomic_read(&atm_dev->stats.aal5.tx),
38516 - atomic_read(&atm_dev->stats.aal5.tx_err),
38517 - atomic_read(&atm_dev->stats.aal5.rx),
38518 - atomic_read(&atm_dev->stats.aal5.rx_err),
38519 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38520 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38521 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38522 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38523 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38524 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38525
38526 if (!left--) {
38527 if (instance->disconnected)
38528 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38529 index d956965..4179a77 100644
38530 --- a/drivers/usb/core/devices.c
38531 +++ b/drivers/usb/core/devices.c
38532 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38533 * time it gets called.
38534 */
38535 static struct device_connect_event {
38536 - atomic_t count;
38537 + atomic_unchecked_t count;
38538 wait_queue_head_t wait;
38539 } device_event = {
38540 .count = ATOMIC_INIT(1),
38541 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38542
38543 void usbfs_conn_disc_event(void)
38544 {
38545 - atomic_add(2, &device_event.count);
38546 + atomic_add_unchecked(2, &device_event.count);
38547 wake_up(&device_event.wait);
38548 }
38549
38550 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38551
38552 poll_wait(file, &device_event.wait, wait);
38553
38554 - event_count = atomic_read(&device_event.count);
38555 + event_count = atomic_read_unchecked(&device_event.count);
38556 if (file->f_version != event_count) {
38557 file->f_version = event_count;
38558 return POLLIN | POLLRDNORM;
38559 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38560 index 1fc8f12..20647c1 100644
38561 --- a/drivers/usb/early/ehci-dbgp.c
38562 +++ b/drivers/usb/early/ehci-dbgp.c
38563 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38564
38565 #ifdef CONFIG_KGDB
38566 static struct kgdb_io kgdbdbgp_io_ops;
38567 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38568 +static struct kgdb_io kgdbdbgp_io_ops_console;
38569 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38570 #else
38571 #define dbgp_kgdb_mode (0)
38572 #endif
38573 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38574 .write_char = kgdbdbgp_write_char,
38575 };
38576
38577 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38578 + .name = "kgdbdbgp",
38579 + .read_char = kgdbdbgp_read_char,
38580 + .write_char = kgdbdbgp_write_char,
38581 + .is_console = 1
38582 +};
38583 +
38584 static int kgdbdbgp_wait_time;
38585
38586 static int __init kgdbdbgp_parse_config(char *str)
38587 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38588 ptr++;
38589 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38590 }
38591 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38592 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38593 + if (early_dbgp_console.index != -1)
38594 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38595 + else
38596 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38597
38598 return 0;
38599 }
38600 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38601 index d6bea3e..60b250e 100644
38602 --- a/drivers/usb/wusbcore/wa-hc.h
38603 +++ b/drivers/usb/wusbcore/wa-hc.h
38604 @@ -192,7 +192,7 @@ struct wahc {
38605 struct list_head xfer_delayed_list;
38606 spinlock_t xfer_list_lock;
38607 struct work_struct xfer_work;
38608 - atomic_t xfer_id_count;
38609 + atomic_unchecked_t xfer_id_count;
38610 };
38611
38612
38613 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38614 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38615 spin_lock_init(&wa->xfer_list_lock);
38616 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38617 - atomic_set(&wa->xfer_id_count, 1);
38618 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38619 }
38620
38621 /**
38622 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38623 index 57c01ab..8a05959 100644
38624 --- a/drivers/usb/wusbcore/wa-xfer.c
38625 +++ b/drivers/usb/wusbcore/wa-xfer.c
38626 @@ -296,7 +296,7 @@ out:
38627 */
38628 static void wa_xfer_id_init(struct wa_xfer *xfer)
38629 {
38630 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38631 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38632 }
38633
38634 /*
38635 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38636 index c14c42b..f955cc2 100644
38637 --- a/drivers/vhost/vhost.c
38638 +++ b/drivers/vhost/vhost.c
38639 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38640 return 0;
38641 }
38642
38643 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38644 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38645 {
38646 struct file *eventfp, *filep = NULL,
38647 *pollstart = NULL, *pollstop = NULL;
38648 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38649 index b0b2ac3..89a4399 100644
38650 --- a/drivers/video/aty/aty128fb.c
38651 +++ b/drivers/video/aty/aty128fb.c
38652 @@ -148,7 +148,7 @@ enum {
38653 };
38654
38655 /* Must match above enum */
38656 -static const char *r128_family[] __devinitdata = {
38657 +static const char *r128_family[] __devinitconst = {
38658 "AGP",
38659 "PCI",
38660 "PRO AGP",
38661 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38662 index 5c3960d..15cf8fc 100644
38663 --- a/drivers/video/fbcmap.c
38664 +++ b/drivers/video/fbcmap.c
38665 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38666 rc = -ENODEV;
38667 goto out;
38668 }
38669 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38670 - !info->fbops->fb_setcmap)) {
38671 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38672 rc = -EINVAL;
38673 goto out1;
38674 }
38675 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38676 index c6ce416..3b9b642 100644
38677 --- a/drivers/video/fbmem.c
38678 +++ b/drivers/video/fbmem.c
38679 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38680 image->dx += image->width + 8;
38681 }
38682 } else if (rotate == FB_ROTATE_UD) {
38683 - for (x = 0; x < num && image->dx >= 0; x++) {
38684 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38685 info->fbops->fb_imageblit(info, image);
38686 image->dx -= image->width + 8;
38687 }
38688 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38689 image->dy += image->height + 8;
38690 }
38691 } else if (rotate == FB_ROTATE_CCW) {
38692 - for (x = 0; x < num && image->dy >= 0; x++) {
38693 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38694 info->fbops->fb_imageblit(info, image);
38695 image->dy -= image->height + 8;
38696 }
38697 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38698 return -EFAULT;
38699 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38700 return -EINVAL;
38701 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38702 + if (con2fb.framebuffer >= FB_MAX)
38703 return -EINVAL;
38704 if (!registered_fb[con2fb.framebuffer])
38705 request_module("fb%d", con2fb.framebuffer);
38706 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38707 index 5a5d092..265c5ed 100644
38708 --- a/drivers/video/geode/gx1fb_core.c
38709 +++ b/drivers/video/geode/gx1fb_core.c
38710 @@ -29,7 +29,7 @@ static int crt_option = 1;
38711 static char panel_option[32] = "";
38712
38713 /* Modes relevant to the GX1 (taken from modedb.c) */
38714 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38715 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38716 /* 640x480-60 VESA */
38717 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38718 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38719 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38720 index 0fad23f..0e9afa4 100644
38721 --- a/drivers/video/gxt4500.c
38722 +++ b/drivers/video/gxt4500.c
38723 @@ -156,7 +156,7 @@ struct gxt4500_par {
38724 static char *mode_option;
38725
38726 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38727 -static const struct fb_videomode defaultmode __devinitdata = {
38728 +static const struct fb_videomode defaultmode __devinitconst = {
38729 .refresh = 60,
38730 .xres = 1280,
38731 .yres = 1024,
38732 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38733 return 0;
38734 }
38735
38736 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38737 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38738 .id = "IBM GXT4500P",
38739 .type = FB_TYPE_PACKED_PIXELS,
38740 .visual = FB_VISUAL_PSEUDOCOLOR,
38741 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38742 index 7672d2e..b56437f 100644
38743 --- a/drivers/video/i810/i810_accel.c
38744 +++ b/drivers/video/i810/i810_accel.c
38745 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38746 }
38747 }
38748 printk("ringbuffer lockup!!!\n");
38749 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38750 i810_report_error(mmio);
38751 par->dev_flags |= LOCKUP;
38752 info->pixmap.scan_align = 1;
38753 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38754 index b83f361..2b05a91 100644
38755 --- a/drivers/video/i810/i810_main.c
38756 +++ b/drivers/video/i810/i810_main.c
38757 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38758 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38759
38760 /* PCI */
38761 -static const char *i810_pci_list[] __devinitdata = {
38762 +static const char *i810_pci_list[] __devinitconst = {
38763 "Intel(R) 810 Framebuffer Device" ,
38764 "Intel(R) 810-DC100 Framebuffer Device" ,
38765 "Intel(R) 810E Framebuffer Device" ,
38766 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38767 index de36693..3c63fc2 100644
38768 --- a/drivers/video/jz4740_fb.c
38769 +++ b/drivers/video/jz4740_fb.c
38770 @@ -136,7 +136,7 @@ struct jzfb {
38771 uint32_t pseudo_palette[16];
38772 };
38773
38774 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38775 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38776 .id = "JZ4740 FB",
38777 .type = FB_TYPE_PACKED_PIXELS,
38778 .visual = FB_VISUAL_TRUECOLOR,
38779 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38780 index 3c14e43..eafa544 100644
38781 --- a/drivers/video/logo/logo_linux_clut224.ppm
38782 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38783 @@ -1,1604 +1,1123 @@
38784 P3
38785 -# Standard 224-color Linux logo
38786 80 80
38787 255
38788 - 0 0 0 0 0 0 0 0 0 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 0 0 0 0 0 0
38791 - 0 0 0 0 0 0 0 0 0 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 0 0 0
38793 - 0 0 0 0 0 0 0 0 0 0 0 0
38794 - 0 0 0 0 0 0 0 0 0 0 0 0
38795 - 0 0 0 0 0 0 0 0 0 0 0 0
38796 - 0 0 0 0 0 0 0 0 0 0 0 0
38797 - 6 6 6 6 6 6 10 10 10 10 10 10
38798 - 10 10 10 6 6 6 6 6 6 6 6 6
38799 - 0 0 0 0 0 0 0 0 0 0 0 0
38800 - 0 0 0 0 0 0 0 0 0 0 0 0
38801 - 0 0 0 0 0 0 0 0 0 0 0 0
38802 - 0 0 0 0 0 0 0 0 0 0 0 0
38803 - 0 0 0 0 0 0 0 0 0 0 0 0
38804 - 0 0 0 0 0 0 0 0 0 0 0 0
38805 - 0 0 0 0 0 0 0 0 0 0 0 0
38806 - 0 0 0 0 0 0 0 0 0 0 0 0
38807 - 0 0 0 0 0 0 0 0 0 0 0 0
38808 - 0 0 0 0 0 0 0 0 0 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 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 - 0 0 0 6 6 6 10 10 10 14 14 14
38817 - 22 22 22 26 26 26 30 30 30 34 34 34
38818 - 30 30 30 30 30 30 26 26 26 18 18 18
38819 - 14 14 14 10 10 10 6 6 6 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0
38836 - 6 6 6 14 14 14 26 26 26 42 42 42
38837 - 54 54 54 66 66 66 78 78 78 78 78 78
38838 - 78 78 78 74 74 74 66 66 66 54 54 54
38839 - 42 42 42 26 26 26 18 18 18 10 10 10
38840 - 6 6 6 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 0 0 0 0 0 0 0
38849 - 0 0 1 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 - 0 0 0 0 0 0 0 0 0 10 10 10
38856 - 22 22 22 42 42 42 66 66 66 86 86 86
38857 - 66 66 66 38 38 38 38 38 38 22 22 22
38858 - 26 26 26 34 34 34 54 54 54 66 66 66
38859 - 86 86 86 70 70 70 46 46 46 26 26 26
38860 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 1 0 0 1 0 0 1 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 0 0 0
38875 - 0 0 0 0 0 0 10 10 10 26 26 26
38876 - 50 50 50 82 82 82 58 58 58 6 6 6
38877 - 2 2 6 2 2 6 2 2 6 2 2 6
38878 - 2 2 6 2 2 6 2 2 6 2 2 6
38879 - 6 6 6 54 54 54 86 86 86 66 66 66
38880 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 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 0 0 0 0 0 0
38895 - 0 0 0 6 6 6 22 22 22 50 50 50
38896 - 78 78 78 34 34 34 2 2 6 2 2 6
38897 - 2 2 6 2 2 6 2 2 6 2 2 6
38898 - 2 2 6 2 2 6 2 2 6 2 2 6
38899 - 2 2 6 2 2 6 6 6 6 70 70 70
38900 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0
38915 - 6 6 6 18 18 18 42 42 42 82 82 82
38916 - 26 26 26 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 2 2 6 14 14 14
38919 - 46 46 46 34 34 34 6 6 6 2 2 6
38920 - 42 42 42 78 78 78 42 42 42 18 18 18
38921 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38929 - 0 0 1 0 0 0 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 10 10 10 30 30 30 66 66 66 58 58 58
38936 - 2 2 6 2 2 6 2 2 6 2 2 6
38937 - 2 2 6 2 2 6 2 2 6 2 2 6
38938 - 2 2 6 2 2 6 2 2 6 26 26 26
38939 - 86 86 86 101 101 101 46 46 46 10 10 10
38940 - 2 2 6 58 58 58 70 70 70 34 34 34
38941 - 10 10 10 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 0 0 0 0 0 0 0 0 0 0
38949 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 14 14 14 42 42 42 86 86 86 10 10 10
38956 - 2 2 6 2 2 6 2 2 6 2 2 6
38957 - 2 2 6 2 2 6 2 2 6 2 2 6
38958 - 2 2 6 2 2 6 2 2 6 30 30 30
38959 - 94 94 94 94 94 94 58 58 58 26 26 26
38960 - 2 2 6 6 6 6 78 78 78 54 54 54
38961 - 22 22 22 6 6 6 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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 6 6 6
38975 - 22 22 22 62 62 62 62 62 62 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 2 2 6
38978 - 2 2 6 2 2 6 2 2 6 26 26 26
38979 - 54 54 54 38 38 38 18 18 18 10 10 10
38980 - 2 2 6 2 2 6 34 34 34 82 82 82
38981 - 38 38 38 14 14 14 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 1 0 0 1 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 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 6 6 6
38995 - 30 30 30 78 78 78 30 30 30 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 2 2 6
38998 - 2 2 6 2 2 6 2 2 6 10 10 10
38999 - 10 10 10 2 2 6 2 2 6 2 2 6
39000 - 2 2 6 2 2 6 2 2 6 78 78 78
39001 - 50 50 50 18 18 18 6 6 6 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 1 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 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 10 10 10
39015 - 38 38 38 86 86 86 14 14 14 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 2 2 6
39018 - 2 2 6 2 2 6 2 2 6 2 2 6
39019 - 2 2 6 2 2 6 2 2 6 2 2 6
39020 - 2 2 6 2 2 6 2 2 6 54 54 54
39021 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 1 0 0 1 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 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 14 14 14
39035 - 42 42 42 82 82 82 2 2 6 2 2 6
39036 - 2 2 6 6 6 6 10 10 10 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 6 6 6
39039 - 14 14 14 10 10 10 2 2 6 2 2 6
39040 - 2 2 6 2 2 6 2 2 6 18 18 18
39041 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0
39049 - 0 0 1 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 0 0 0
39054 - 0 0 0 0 0 0 0 0 0 14 14 14
39055 - 46 46 46 86 86 86 2 2 6 2 2 6
39056 - 6 6 6 6 6 6 22 22 22 34 34 34
39057 - 6 6 6 2 2 6 2 2 6 2 2 6
39058 - 2 2 6 2 2 6 18 18 18 34 34 34
39059 - 10 10 10 50 50 50 22 22 22 2 2 6
39060 - 2 2 6 2 2 6 2 2 6 10 10 10
39061 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 14 14 14
39075 - 46 46 46 86 86 86 2 2 6 2 2 6
39076 - 38 38 38 116 116 116 94 94 94 22 22 22
39077 - 22 22 22 2 2 6 2 2 6 2 2 6
39078 - 14 14 14 86 86 86 138 138 138 162 162 162
39079 -154 154 154 38 38 38 26 26 26 6 6 6
39080 - 2 2 6 2 2 6 2 2 6 2 2 6
39081 - 86 86 86 46 46 46 14 14 14 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 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 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 14 14 14
39095 - 46 46 46 86 86 86 2 2 6 14 14 14
39096 -134 134 134 198 198 198 195 195 195 116 116 116
39097 - 10 10 10 2 2 6 2 2 6 6 6 6
39098 -101 98 89 187 187 187 210 210 210 218 218 218
39099 -214 214 214 134 134 134 14 14 14 6 6 6
39100 - 2 2 6 2 2 6 2 2 6 2 2 6
39101 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
39109 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 14 14 14
39115 - 46 46 46 86 86 86 2 2 6 54 54 54
39116 -218 218 218 195 195 195 226 226 226 246 246 246
39117 - 58 58 58 2 2 6 2 2 6 30 30 30
39118 -210 210 210 253 253 253 174 174 174 123 123 123
39119 -221 221 221 234 234 234 74 74 74 2 2 6
39120 - 2 2 6 2 2 6 2 2 6 2 2 6
39121 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 14 14 14
39135 - 46 46 46 82 82 82 2 2 6 106 106 106
39136 -170 170 170 26 26 26 86 86 86 226 226 226
39137 -123 123 123 10 10 10 14 14 14 46 46 46
39138 -231 231 231 190 190 190 6 6 6 70 70 70
39139 - 90 90 90 238 238 238 158 158 158 2 2 6
39140 - 2 2 6 2 2 6 2 2 6 2 2 6
39141 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
39149 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 14 14 14
39155 - 42 42 42 86 86 86 6 6 6 116 116 116
39156 -106 106 106 6 6 6 70 70 70 149 149 149
39157 -128 128 128 18 18 18 38 38 38 54 54 54
39158 -221 221 221 106 106 106 2 2 6 14 14 14
39159 - 46 46 46 190 190 190 198 198 198 2 2 6
39160 - 2 2 6 2 2 6 2 2 6 2 2 6
39161 - 74 74 74 62 62 62 22 22 22 6 6 6
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 1 0 0 0
39169 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 14 14 14
39175 - 42 42 42 94 94 94 14 14 14 101 101 101
39176 -128 128 128 2 2 6 18 18 18 116 116 116
39177 -118 98 46 121 92 8 121 92 8 98 78 10
39178 -162 162 162 106 106 106 2 2 6 2 2 6
39179 - 2 2 6 195 195 195 195 195 195 6 6 6
39180 - 2 2 6 2 2 6 2 2 6 2 2 6
39181 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 1 0 0 1
39189 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 10 10 10
39195 - 38 38 38 90 90 90 14 14 14 58 58 58
39196 -210 210 210 26 26 26 54 38 6 154 114 10
39197 -226 170 11 236 186 11 225 175 15 184 144 12
39198 -215 174 15 175 146 61 37 26 9 2 2 6
39199 - 70 70 70 246 246 246 138 138 138 2 2 6
39200 - 2 2 6 2 2 6 2 2 6 2 2 6
39201 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 10 10 10
39215 - 38 38 38 86 86 86 14 14 14 10 10 10
39216 -195 195 195 188 164 115 192 133 9 225 175 15
39217 -239 182 13 234 190 10 232 195 16 232 200 30
39218 -245 207 45 241 208 19 232 195 16 184 144 12
39219 -218 194 134 211 206 186 42 42 42 2 2 6
39220 - 2 2 6 2 2 6 2 2 6 2 2 6
39221 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 10 10 10
39235 - 34 34 34 86 86 86 14 14 14 2 2 6
39236 -121 87 25 192 133 9 219 162 10 239 182 13
39237 -236 186 11 232 195 16 241 208 19 244 214 54
39238 -246 218 60 246 218 38 246 215 20 241 208 19
39239 -241 208 19 226 184 13 121 87 25 2 2 6
39240 - 2 2 6 2 2 6 2 2 6 2 2 6
39241 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 10 10 10
39255 - 34 34 34 82 82 82 30 30 30 61 42 6
39256 -180 123 7 206 145 10 230 174 11 239 182 13
39257 -234 190 10 238 202 15 241 208 19 246 218 74
39258 -246 218 38 246 215 20 246 215 20 246 215 20
39259 -226 184 13 215 174 15 184 144 12 6 6 6
39260 - 2 2 6 2 2 6 2 2 6 2 2 6
39261 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 10 10 10
39275 - 30 30 30 78 78 78 50 50 50 104 69 6
39276 -192 133 9 216 158 10 236 178 12 236 186 11
39277 -232 195 16 241 208 19 244 214 54 245 215 43
39278 -246 215 20 246 215 20 241 208 19 198 155 10
39279 -200 144 11 216 158 10 156 118 10 2 2 6
39280 - 2 2 6 2 2 6 2 2 6 2 2 6
39281 - 6 6 6 90 90 90 54 54 54 18 18 18
39282 - 6 6 6 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 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 10 10 10
39295 - 30 30 30 78 78 78 46 46 46 22 22 22
39296 -137 92 6 210 162 10 239 182 13 238 190 10
39297 -238 202 15 241 208 19 246 215 20 246 215 20
39298 -241 208 19 203 166 17 185 133 11 210 150 10
39299 -216 158 10 210 150 10 102 78 10 2 2 6
39300 - 6 6 6 54 54 54 14 14 14 2 2 6
39301 - 2 2 6 62 62 62 74 74 74 30 30 30
39302 - 10 10 10 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 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 10 10 10
39315 - 34 34 34 78 78 78 50 50 50 6 6 6
39316 - 94 70 30 139 102 15 190 146 13 226 184 13
39317 -232 200 30 232 195 16 215 174 15 190 146 13
39318 -168 122 10 192 133 9 210 150 10 213 154 11
39319 -202 150 34 182 157 106 101 98 89 2 2 6
39320 - 2 2 6 78 78 78 116 116 116 58 58 58
39321 - 2 2 6 22 22 22 90 90 90 46 46 46
39322 - 18 18 18 6 6 6 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 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 10 10 10
39335 - 38 38 38 86 86 86 50 50 50 6 6 6
39336 -128 128 128 174 154 114 156 107 11 168 122 10
39337 -198 155 10 184 144 12 197 138 11 200 144 11
39338 -206 145 10 206 145 10 197 138 11 188 164 115
39339 -195 195 195 198 198 198 174 174 174 14 14 14
39340 - 2 2 6 22 22 22 116 116 116 116 116 116
39341 - 22 22 22 2 2 6 74 74 74 70 70 70
39342 - 30 30 30 10 10 10 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 0 0 0
39354 - 0 0 0 0 0 0 6 6 6 18 18 18
39355 - 50 50 50 101 101 101 26 26 26 10 10 10
39356 -138 138 138 190 190 190 174 154 114 156 107 11
39357 -197 138 11 200 144 11 197 138 11 192 133 9
39358 -180 123 7 190 142 34 190 178 144 187 187 187
39359 -202 202 202 221 221 221 214 214 214 66 66 66
39360 - 2 2 6 2 2 6 50 50 50 62 62 62
39361 - 6 6 6 2 2 6 10 10 10 90 90 90
39362 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 10 10 10 34 34 34
39375 - 74 74 74 74 74 74 2 2 6 6 6 6
39376 -144 144 144 198 198 198 190 190 190 178 166 146
39377 -154 121 60 156 107 11 156 107 11 168 124 44
39378 -174 154 114 187 187 187 190 190 190 210 210 210
39379 -246 246 246 253 253 253 253 253 253 182 182 182
39380 - 6 6 6 2 2 6 2 2 6 2 2 6
39381 - 2 2 6 2 2 6 2 2 6 62 62 62
39382 - 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0
39394 - 0 0 0 10 10 10 22 22 22 54 54 54
39395 - 94 94 94 18 18 18 2 2 6 46 46 46
39396 -234 234 234 221 221 221 190 190 190 190 190 190
39397 -190 190 190 187 187 187 187 187 187 190 190 190
39398 -190 190 190 195 195 195 214 214 214 242 242 242
39399 -253 253 253 253 253 253 253 253 253 253 253 253
39400 - 82 82 82 2 2 6 2 2 6 2 2 6
39401 - 2 2 6 2 2 6 2 2 6 14 14 14
39402 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
39414 - 6 6 6 18 18 18 46 46 46 90 90 90
39415 - 46 46 46 18 18 18 6 6 6 182 182 182
39416 -253 253 253 246 246 246 206 206 206 190 190 190
39417 -190 190 190 190 190 190 190 190 190 190 190 190
39418 -206 206 206 231 231 231 250 250 250 253 253 253
39419 -253 253 253 253 253 253 253 253 253 253 253 253
39420 -202 202 202 14 14 14 2 2 6 2 2 6
39421 - 2 2 6 2 2 6 2 2 6 2 2 6
39422 - 42 42 42 86 86 86 42 42 42 18 18 18
39423 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 6 6 6
39434 - 14 14 14 38 38 38 74 74 74 66 66 66
39435 - 2 2 6 6 6 6 90 90 90 250 250 250
39436 -253 253 253 253 253 253 238 238 238 198 198 198
39437 -190 190 190 190 190 190 195 195 195 221 221 221
39438 -246 246 246 253 253 253 253 253 253 253 253 253
39439 -253 253 253 253 253 253 253 253 253 253 253 253
39440 -253 253 253 82 82 82 2 2 6 2 2 6
39441 - 2 2 6 2 2 6 2 2 6 2 2 6
39442 - 2 2 6 78 78 78 70 70 70 34 34 34
39443 - 14 14 14 6 6 6 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 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 14 14 14
39454 - 34 34 34 66 66 66 78 78 78 6 6 6
39455 - 2 2 6 18 18 18 218 218 218 253 253 253
39456 -253 253 253 253 253 253 253 253 253 246 246 246
39457 -226 226 226 231 231 231 246 246 246 253 253 253
39458 -253 253 253 253 253 253 253 253 253 253 253 253
39459 -253 253 253 253 253 253 253 253 253 253 253 253
39460 -253 253 253 178 178 178 2 2 6 2 2 6
39461 - 2 2 6 2 2 6 2 2 6 2 2 6
39462 - 2 2 6 18 18 18 90 90 90 62 62 62
39463 - 30 30 30 10 10 10 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 0 0 0
39473 - 0 0 0 0 0 0 10 10 10 26 26 26
39474 - 58 58 58 90 90 90 18 18 18 2 2 6
39475 - 2 2 6 110 110 110 253 253 253 253 253 253
39476 -253 253 253 253 253 253 253 253 253 253 253 253
39477 -250 250 250 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 253 253 253 253 253 253 253 253 253
39480 -253 253 253 231 231 231 18 18 18 2 2 6
39481 - 2 2 6 2 2 6 2 2 6 2 2 6
39482 - 2 2 6 2 2 6 18 18 18 94 94 94
39483 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
39493 - 0 0 0 6 6 6 22 22 22 50 50 50
39494 - 90 90 90 26 26 26 2 2 6 2 2 6
39495 - 14 14 14 195 195 195 250 250 250 253 253 253
39496 -253 253 253 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 253 253 253 253 253 253 253 253 253
39500 -250 250 250 242 242 242 54 54 54 2 2 6
39501 - 2 2 6 2 2 6 2 2 6 2 2 6
39502 - 2 2 6 2 2 6 2 2 6 38 38 38
39503 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
39513 - 6 6 6 14 14 14 38 38 38 82 82 82
39514 - 34 34 34 2 2 6 2 2 6 2 2 6
39515 - 42 42 42 195 195 195 246 246 246 253 253 253
39516 -253 253 253 253 253 253 253 253 253 250 250 250
39517 -242 242 242 242 242 242 250 250 250 253 253 253
39518 -253 253 253 253 253 253 253 253 253 253 253 253
39519 -253 253 253 250 250 250 246 246 246 238 238 238
39520 -226 226 226 231 231 231 101 101 101 6 6 6
39521 - 2 2 6 2 2 6 2 2 6 2 2 6
39522 - 2 2 6 2 2 6 2 2 6 2 2 6
39523 - 38 38 38 82 82 82 42 42 42 14 14 14
39524 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 10 10 10 26 26 26 62 62 62 66 66 66
39534 - 2 2 6 2 2 6 2 2 6 6 6 6
39535 - 70 70 70 170 170 170 206 206 206 234 234 234
39536 -246 246 246 250 250 250 250 250 250 238 238 238
39537 -226 226 226 231 231 231 238 238 238 250 250 250
39538 -250 250 250 250 250 250 246 246 246 231 231 231
39539 -214 214 214 206 206 206 202 202 202 202 202 202
39540 -198 198 198 202 202 202 182 182 182 18 18 18
39541 - 2 2 6 2 2 6 2 2 6 2 2 6
39542 - 2 2 6 2 2 6 2 2 6 2 2 6
39543 - 2 2 6 62 62 62 66 66 66 30 30 30
39544 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 14 14 14 42 42 42 82 82 82 18 18 18
39554 - 2 2 6 2 2 6 2 2 6 10 10 10
39555 - 94 94 94 182 182 182 218 218 218 242 242 242
39556 -250 250 250 253 253 253 253 253 253 250 250 250
39557 -234 234 234 253 253 253 253 253 253 253 253 253
39558 -253 253 253 253 253 253 253 253 253 246 246 246
39559 -238 238 238 226 226 226 210 210 210 202 202 202
39560 -195 195 195 195 195 195 210 210 210 158 158 158
39561 - 6 6 6 14 14 14 50 50 50 14 14 14
39562 - 2 2 6 2 2 6 2 2 6 2 2 6
39563 - 2 2 6 6 6 6 86 86 86 46 46 46
39564 - 18 18 18 6 6 6 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 - 0 0 0 0 0 0 0 0 0 6 6 6
39573 - 22 22 22 54 54 54 70 70 70 2 2 6
39574 - 2 2 6 10 10 10 2 2 6 22 22 22
39575 -166 166 166 231 231 231 250 250 250 253 253 253
39576 -253 253 253 253 253 253 253 253 253 250 250 250
39577 -242 242 242 253 253 253 253 253 253 253 253 253
39578 -253 253 253 253 253 253 253 253 253 253 253 253
39579 -253 253 253 253 253 253 253 253 253 246 246 246
39580 -231 231 231 206 206 206 198 198 198 226 226 226
39581 - 94 94 94 2 2 6 6 6 6 38 38 38
39582 - 30 30 30 2 2 6 2 2 6 2 2 6
39583 - 2 2 6 2 2 6 62 62 62 66 66 66
39584 - 26 26 26 10 10 10 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 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 10 10 10
39593 - 30 30 30 74 74 74 50 50 50 2 2 6
39594 - 26 26 26 26 26 26 2 2 6 106 106 106
39595 -238 238 238 253 253 253 253 253 253 253 253 253
39596 -253 253 253 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 253 253 253
39599 -253 253 253 253 253 253 253 253 253 253 253 253
39600 -253 253 253 246 246 246 218 218 218 202 202 202
39601 -210 210 210 14 14 14 2 2 6 2 2 6
39602 - 30 30 30 22 22 22 2 2 6 2 2 6
39603 - 2 2 6 2 2 6 18 18 18 86 86 86
39604 - 42 42 42 14 14 14 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 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 14 14 14
39613 - 42 42 42 90 90 90 22 22 22 2 2 6
39614 - 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253 253 253 253 253 253 253
39620 -253 253 253 253 253 253 250 250 250 221 221 221
39621 -218 218 218 101 101 101 2 2 6 14 14 14
39622 - 18 18 18 38 38 38 10 10 10 2 2 6
39623 - 2 2 6 2 2 6 2 2 6 78 78 78
39624 - 58 58 58 22 22 22 6 6 6 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 0 0 0
39632 - 0 0 0 0 0 0 6 6 6 18 18 18
39633 - 54 54 54 82 82 82 2 2 6 26 26 26
39634 - 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253
39640 -253 253 253 253 253 253 253 253 253 250 250 250
39641 -238 238 238 198 198 198 6 6 6 38 38 38
39642 - 58 58 58 26 26 26 38 38 38 2 2 6
39643 - 2 2 6 2 2 6 2 2 6 46 46 46
39644 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 10 10 10 30 30 30
39653 - 74 74 74 58 58 58 2 2 6 42 42 42
39654 - 2 2 6 22 22 22 231 231 231 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 250 250 250
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 253 253 253
39660 -253 253 253 253 253 253 253 253 253 253 253 253
39661 -253 253 253 246 246 246 46 46 46 38 38 38
39662 - 42 42 42 14 14 14 38 38 38 14 14 14
39663 - 2 2 6 2 2 6 2 2 6 6 6 6
39664 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
39672 - 0 0 0 6 6 6 14 14 14 42 42 42
39673 - 90 90 90 18 18 18 18 18 18 26 26 26
39674 - 2 2 6 116 116 116 253 253 253 253 253 253
39675 -253 253 253 253 253 253 253 253 253 253 253 253
39676 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 253 253 253 253 253 253
39681 -253 253 253 253 253 253 94 94 94 6 6 6
39682 - 2 2 6 2 2 6 10 10 10 34 34 34
39683 - 2 2 6 2 2 6 2 2 6 2 2 6
39684 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 10 10 10 26 26 26 66 66 66
39693 - 82 82 82 2 2 6 38 38 38 6 6 6
39694 - 14 14 14 210 210 210 253 253 253 253 253 253
39695 -253 253 253 253 253 253 253 253 253 253 253 253
39696 -253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253
39701 -253 253 253 253 253 253 144 144 144 2 2 6
39702 - 2 2 6 2 2 6 2 2 6 46 46 46
39703 - 2 2 6 2 2 6 2 2 6 2 2 6
39704 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0 0 0
39712 - 6 6 6 14 14 14 42 42 42 90 90 90
39713 - 26 26 26 6 6 6 42 42 42 2 2 6
39714 - 74 74 74 250 250 250 253 253 253 253 253 253
39715 -253 253 253 253 253 253 253 253 253 253 253 253
39716 -253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253 253 253 253
39721 -253 253 253 253 253 253 182 182 182 2 2 6
39722 - 2 2 6 2 2 6 2 2 6 46 46 46
39723 - 2 2 6 2 2 6 2 2 6 2 2 6
39724 - 10 10 10 86 86 86 38 38 38 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 10 10 10 26 26 26 66 66 66 82 82 82
39733 - 2 2 6 22 22 22 18 18 18 2 2 6
39734 -149 149 149 253 253 253 253 253 253 253 253 253
39735 -253 253 253 253 253 253 253 253 253 253 253 253
39736 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
39741 -253 253 253 253 253 253 206 206 206 2 2 6
39742 - 2 2 6 2 2 6 2 2 6 38 38 38
39743 - 2 2 6 2 2 6 2 2 6 2 2 6
39744 - 6 6 6 86 86 86 46 46 46 14 14 14
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 - 0 0 0 0 0 0 0 0 0 6 6 6
39752 - 18 18 18 46 46 46 86 86 86 18 18 18
39753 - 2 2 6 34 34 34 10 10 10 6 6 6
39754 -210 210 210 253 253 253 253 253 253 253 253 253
39755 -253 253 253 253 253 253 253 253 253 253 253 253
39756 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
39761 -253 253 253 253 253 253 221 221 221 6 6 6
39762 - 2 2 6 2 2 6 6 6 6 30 30 30
39763 - 2 2 6 2 2 6 2 2 6 2 2 6
39764 - 2 2 6 82 82 82 54 54 54 18 18 18
39765 - 6 6 6 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 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 10 10 10
39772 - 26 26 26 66 66 66 62 62 62 2 2 6
39773 - 2 2 6 38 38 38 10 10 10 26 26 26
39774 -238 238 238 253 253 253 253 253 253 253 253 253
39775 -253 253 253 253 253 253 253 253 253 253 253 253
39776 -253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253 253 253 253
39781 -253 253 253 253 253 253 231 231 231 6 6 6
39782 - 2 2 6 2 2 6 10 10 10 30 30 30
39783 - 2 2 6 2 2 6 2 2 6 2 2 6
39784 - 2 2 6 66 66 66 58 58 58 22 22 22
39785 - 6 6 6 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 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 10 10 10
39792 - 38 38 38 78 78 78 6 6 6 2 2 6
39793 - 2 2 6 46 46 46 14 14 14 42 42 42
39794 -246 246 246 253 253 253 253 253 253 253 253 253
39795 -253 253 253 253 253 253 253 253 253 253 253 253
39796 -253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253
39801 -253 253 253 253 253 253 234 234 234 10 10 10
39802 - 2 2 6 2 2 6 22 22 22 14 14 14
39803 - 2 2 6 2 2 6 2 2 6 2 2 6
39804 - 2 2 6 66 66 66 62 62 62 22 22 22
39805 - 6 6 6 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 0 0 0
39811 - 0 0 0 0 0 0 6 6 6 18 18 18
39812 - 50 50 50 74 74 74 2 2 6 2 2 6
39813 - 14 14 14 70 70 70 34 34 34 62 62 62
39814 -250 250 250 253 253 253 253 253 253 253 253 253
39815 -253 253 253 253 253 253 253 253 253 253 253 253
39816 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
39821 -253 253 253 253 253 253 234 234 234 14 14 14
39822 - 2 2 6 2 2 6 30 30 30 2 2 6
39823 - 2 2 6 2 2 6 2 2 6 2 2 6
39824 - 2 2 6 66 66 66 62 62 62 22 22 22
39825 - 6 6 6 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 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 6 6 6 18 18 18
39832 - 54 54 54 62 62 62 2 2 6 2 2 6
39833 - 2 2 6 30 30 30 46 46 46 70 70 70
39834 -250 250 250 253 253 253 253 253 253 253 253 253
39835 -253 253 253 253 253 253 253 253 253 253 253 253
39836 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
39841 -253 253 253 253 253 253 226 226 226 10 10 10
39842 - 2 2 6 6 6 6 30 30 30 2 2 6
39843 - 2 2 6 2 2 6 2 2 6 2 2 6
39844 - 2 2 6 66 66 66 58 58 58 22 22 22
39845 - 6 6 6 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 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 6 6 6 22 22 22
39852 - 58 58 58 62 62 62 2 2 6 2 2 6
39853 - 2 2 6 2 2 6 30 30 30 78 78 78
39854 -250 250 250 253 253 253 253 253 253 253 253 253
39855 -253 253 253 253 253 253 253 253 253 253 253 253
39856 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
39861 -253 253 253 253 253 253 206 206 206 2 2 6
39862 - 22 22 22 34 34 34 18 14 6 22 22 22
39863 - 26 26 26 18 18 18 6 6 6 2 2 6
39864 - 2 2 6 82 82 82 54 54 54 18 18 18
39865 - 6 6 6 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 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 6 6 6 26 26 26
39872 - 62 62 62 106 106 106 74 54 14 185 133 11
39873 -210 162 10 121 92 8 6 6 6 62 62 62
39874 -238 238 238 253 253 253 253 253 253 253 253 253
39875 -253 253 253 253 253 253 253 253 253 253 253 253
39876 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
39881 -253 253 253 253 253 253 158 158 158 18 18 18
39882 - 14 14 14 2 2 6 2 2 6 2 2 6
39883 - 6 6 6 18 18 18 66 66 66 38 38 38
39884 - 6 6 6 94 94 94 50 50 50 18 18 18
39885 - 6 6 6 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 0 0 0 6 6 6
39891 - 10 10 10 10 10 10 18 18 18 38 38 38
39892 - 78 78 78 142 134 106 216 158 10 242 186 14
39893 -246 190 14 246 190 14 156 118 10 10 10 10
39894 - 90 90 90 238 238 238 253 253 253 253 253 253
39895 -253 253 253 253 253 253 253 253 253 253 253 253
39896 -253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 246 230 190
39901 -238 204 91 238 204 91 181 142 44 37 26 9
39902 - 2 2 6 2 2 6 2 2 6 2 2 6
39903 - 2 2 6 2 2 6 38 38 38 46 46 46
39904 - 26 26 26 106 106 106 54 54 54 18 18 18
39905 - 6 6 6 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 0 0 0
39910 - 0 0 0 6 6 6 14 14 14 22 22 22
39911 - 30 30 30 38 38 38 50 50 50 70 70 70
39912 -106 106 106 190 142 34 226 170 11 242 186 14
39913 -246 190 14 246 190 14 246 190 14 154 114 10
39914 - 6 6 6 74 74 74 226 226 226 253 253 253
39915 -253 253 253 253 253 253 253 253 253 253 253 253
39916 -253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253
39920 -253 253 253 253 253 253 253 253 253 228 184 62
39921 -241 196 14 241 208 19 232 195 16 38 30 10
39922 - 2 2 6 2 2 6 2 2 6 2 2 6
39923 - 2 2 6 6 6 6 30 30 30 26 26 26
39924 -203 166 17 154 142 90 66 66 66 26 26 26
39925 - 6 6 6 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 0 0 0 0 0 0 0 0 0
39930 - 6 6 6 18 18 18 38 38 38 58 58 58
39931 - 78 78 78 86 86 86 101 101 101 123 123 123
39932 -175 146 61 210 150 10 234 174 13 246 186 14
39933 -246 190 14 246 190 14 246 190 14 238 190 10
39934 -102 78 10 2 2 6 46 46 46 198 198 198
39935 -253 253 253 253 253 253 253 253 253 253 253 253
39936 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253
39940 -253 253 253 253 253 253 253 253 253 224 178 62
39941 -242 186 14 241 196 14 210 166 10 22 18 6
39942 - 2 2 6 2 2 6 2 2 6 2 2 6
39943 - 2 2 6 2 2 6 6 6 6 121 92 8
39944 -238 202 15 232 195 16 82 82 82 34 34 34
39945 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 14 14 14 38 38 38 70 70 70 154 122 46
39951 -190 142 34 200 144 11 197 138 11 197 138 11
39952 -213 154 11 226 170 11 242 186 14 246 190 14
39953 -246 190 14 246 190 14 246 190 14 246 190 14
39954 -225 175 15 46 32 6 2 2 6 22 22 22
39955 -158 158 158 250 250 250 253 253 253 253 253 253
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 253 253 253
39960 -253 253 253 250 250 250 242 242 242 224 178 62
39961 -239 182 13 236 186 11 213 154 11 46 32 6
39962 - 2 2 6 2 2 6 2 2 6 2 2 6
39963 - 2 2 6 2 2 6 61 42 6 225 175 15
39964 -238 190 10 236 186 11 112 100 78 42 42 42
39965 - 14 14 14 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 - 0 0 0 0 0 0 0 0 0 6 6 6
39970 - 22 22 22 54 54 54 154 122 46 213 154 11
39971 -226 170 11 230 174 11 226 170 11 226 170 11
39972 -236 178 12 242 186 14 246 190 14 246 190 14
39973 -246 190 14 246 190 14 246 190 14 246 190 14
39974 -241 196 14 184 144 12 10 10 10 2 2 6
39975 - 6 6 6 116 116 116 242 242 242 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 253 253 253 253 253 253 253 253 253
39980 -253 253 253 231 231 231 198 198 198 214 170 54
39981 -236 178 12 236 178 12 210 150 10 137 92 6
39982 - 18 14 6 2 2 6 2 2 6 2 2 6
39983 - 6 6 6 70 47 6 200 144 11 236 178 12
39984 -239 182 13 239 182 13 124 112 88 58 58 58
39985 - 22 22 22 6 6 6 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 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 10 10 10
39990 - 30 30 30 70 70 70 180 133 36 226 170 11
39991 -239 182 13 242 186 14 242 186 14 246 186 14
39992 -246 190 14 246 190 14 246 190 14 246 190 14
39993 -246 190 14 246 190 14 246 190 14 246 190 14
39994 -246 190 14 232 195 16 98 70 6 2 2 6
39995 - 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253 253 253 253
40000 -253 253 253 206 206 206 198 198 198 214 166 58
40001 -230 174 11 230 174 11 216 158 10 192 133 9
40002 -163 110 8 116 81 8 102 78 10 116 81 8
40003 -167 114 7 197 138 11 226 170 11 239 182 13
40004 -242 186 14 242 186 14 162 146 94 78 78 78
40005 - 34 34 34 14 14 14 6 6 6 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 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 6 6 6
40010 - 30 30 30 78 78 78 190 142 34 226 170 11
40011 -239 182 13 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 246 190 14 246 190 14 246 190 14
40014 -246 190 14 241 196 14 203 166 17 22 18 6
40015 - 2 2 6 2 2 6 2 2 6 38 38 38
40016 -218 218 218 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 253 253 253 253 253 253 253 253 253
40020 -250 250 250 206 206 206 198 198 198 202 162 69
40021 -226 170 11 236 178 12 224 166 10 210 150 10
40022 -200 144 11 197 138 11 192 133 9 197 138 11
40023 -210 150 10 226 170 11 242 186 14 246 190 14
40024 -246 190 14 246 186 14 225 175 15 124 112 88
40025 - 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 10 10 10
40030 - 30 30 30 78 78 78 174 135 50 224 166 10
40031 -239 182 13 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 246 190 14 246 190 14 246 190 14
40034 -246 190 14 246 190 14 241 196 14 139 102 15
40035 - 2 2 6 2 2 6 2 2 6 2 2 6
40036 - 78 78 78 250 250 250 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 -253 253 253 253 253 253 253 253 253 253 253 253
40040 -250 250 250 214 214 214 198 198 198 190 150 46
40041 -219 162 10 236 178 12 234 174 13 224 166 10
40042 -216 158 10 213 154 11 213 154 11 216 158 10
40043 -226 170 11 239 182 13 246 190 14 246 190 14
40044 -246 190 14 246 190 14 242 186 14 206 162 42
40045 -101 101 101 58 58 58 30 30 30 14 14 14
40046 - 6 6 6 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 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 10 10 10
40050 - 30 30 30 74 74 74 174 135 50 216 158 10
40051 -236 178 12 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 246 190 14 246 190 14
40054 -246 190 14 246 190 14 241 196 14 226 184 13
40055 - 61 42 6 2 2 6 2 2 6 2 2 6
40056 - 22 22 22 238 238 238 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 -253 253 253 253 253 253 253 253 253 253 253 253
40060 -253 253 253 226 226 226 187 187 187 180 133 36
40061 -216 158 10 236 178 12 239 182 13 236 178 12
40062 -230 174 11 226 170 11 226 170 11 230 174 11
40063 -236 178 12 242 186 14 246 190 14 246 190 14
40064 -246 190 14 246 190 14 246 186 14 239 182 13
40065 -206 162 42 106 106 106 66 66 66 34 34 34
40066 - 14 14 14 6 6 6 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 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 6 6 6
40070 - 26 26 26 70 70 70 163 133 67 213 154 11
40071 -236 178 12 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 246 190 14 246 190 14
40074 -246 190 14 246 190 14 246 190 14 241 196 14
40075 -190 146 13 18 14 6 2 2 6 2 2 6
40076 - 46 46 46 246 246 246 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 253 253 253 253 253 253 253 253 253
40080 -253 253 253 221 221 221 86 86 86 156 107 11
40081 -216 158 10 236 178 12 242 186 14 246 186 14
40082 -242 186 14 239 182 13 239 182 13 242 186 14
40083 -242 186 14 246 186 14 246 190 14 246 190 14
40084 -246 190 14 246 190 14 246 190 14 246 190 14
40085 -242 186 14 225 175 15 142 122 72 66 66 66
40086 - 30 30 30 10 10 10 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 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 6 6 6
40090 - 26 26 26 70 70 70 163 133 67 210 150 10
40091 -236 178 12 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 246 190 14
40094 -246 190 14 246 190 14 246 190 14 246 190 14
40095 -232 195 16 121 92 8 34 34 34 106 106 106
40096 -221 221 221 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 253 253 253 253 253 253 253 253 253
40100 -242 242 242 82 82 82 18 14 6 163 110 8
40101 -216 158 10 236 178 12 242 186 14 246 190 14
40102 -246 190 14 246 190 14 246 190 14 246 190 14
40103 -246 190 14 246 190 14 246 190 14 246 190 14
40104 -246 190 14 246 190 14 246 190 14 246 190 14
40105 -246 190 14 246 190 14 242 186 14 163 133 67
40106 - 46 46 46 18 18 18 6 6 6 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 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 10 10 10
40110 - 30 30 30 78 78 78 163 133 67 210 150 10
40111 -236 178 12 246 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
40115 -241 196 14 215 174 15 190 178 144 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 -253 253 253 253 253 253 253 253 253 218 218 218
40120 - 58 58 58 2 2 6 22 18 6 167 114 7
40121 -216 158 10 236 178 12 246 186 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 246 190 14 246 190 14
40125 -246 190 14 246 186 14 242 186 14 190 150 46
40126 - 54 54 54 22 22 22 6 6 6 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 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 14 14 14
40130 - 38 38 38 86 86 86 180 133 36 213 154 11
40131 -236 178 12 246 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
40135 -246 190 14 232 195 16 190 146 13 214 214 214
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 253 253 253
40139 -253 253 253 250 250 250 170 170 170 26 26 26
40140 - 2 2 6 2 2 6 37 26 9 163 110 8
40141 -219 162 10 239 182 13 246 186 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 190 14 246 190 14 246 190 14
40145 -246 186 14 236 178 12 224 166 10 142 122 72
40146 - 46 46 46 18 18 18 6 6 6 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 0 0 0
40149 - 0 0 0 0 0 0 6 6 6 18 18 18
40150 - 50 50 50 109 106 95 192 133 9 224 166 10
40151 -242 186 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 246 190 14 246 190 14 246 190 14
40155 -242 186 14 226 184 13 210 162 10 142 110 46
40156 -226 226 226 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 253 253 253 253 253 253 253 253 253
40159 -198 198 198 66 66 66 2 2 6 2 2 6
40160 - 2 2 6 2 2 6 50 34 6 156 107 11
40161 -219 162 10 239 182 13 246 186 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 190 14 246 190 14 246 190 14 242 186 14
40165 -234 174 13 213 154 11 154 122 46 66 66 66
40166 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 6 6 6 22 22 22
40170 - 58 58 58 154 121 60 206 145 10 234 174 13
40171 -242 186 14 246 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
40175 -246 186 14 236 178 12 210 162 10 163 110 8
40176 - 61 42 6 138 138 138 218 218 218 250 250 250
40177 -253 253 253 253 253 253 253 253 253 250 250 250
40178 -242 242 242 210 210 210 144 144 144 66 66 66
40179 - 6 6 6 2 2 6 2 2 6 2 2 6
40180 - 2 2 6 2 2 6 61 42 6 163 110 8
40181 -216 158 10 236 178 12 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 246 190 14
40184 -246 190 14 239 182 13 230 174 11 216 158 10
40185 -190 142 34 124 112 88 70 70 70 38 38 38
40186 - 18 18 18 6 6 6 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 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 6 6 6 22 22 22
40190 - 62 62 62 168 124 44 206 145 10 224 166 10
40191 -236 178 12 239 182 13 242 186 14 242 186 14
40192 -246 186 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 190 14 246 190 14 246 190 14 246 190 14
40195 -246 190 14 236 178 12 216 158 10 175 118 6
40196 - 80 54 7 2 2 6 6 6 6 30 30 30
40197 - 54 54 54 62 62 62 50 50 50 38 38 38
40198 - 14 14 14 2 2 6 2 2 6 2 2 6
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 2 2 6 6 6 6 80 54 7 167 114 7
40201 -213 154 11 236 178 12 246 190 14 246 190 14
40202 -246 190 14 246 190 14 246 190 14 246 190 14
40203 -246 190 14 242 186 14 239 182 13 239 182 13
40204 -230 174 11 210 150 10 174 135 50 124 112 88
40205 - 82 82 82 54 54 54 34 34 34 18 18 18
40206 - 6 6 6 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 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 6 6 6 18 18 18
40210 - 50 50 50 158 118 36 192 133 9 200 144 11
40211 -216 158 10 219 162 10 224 166 10 226 170 11
40212 -230 174 11 236 178 12 239 182 13 239 182 13
40213 -242 186 14 246 186 14 246 190 14 246 190 14
40214 -246 190 14 246 190 14 246 190 14 246 190 14
40215 -246 186 14 230 174 11 210 150 10 163 110 8
40216 -104 69 6 10 10 10 2 2 6 2 2 6
40217 - 2 2 6 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 2 2 6 2 2 6 2 2 6
40220 - 2 2 6 6 6 6 91 60 6 167 114 7
40221 -206 145 10 230 174 11 242 186 14 246 190 14
40222 -246 190 14 246 190 14 246 186 14 242 186 14
40223 -239 182 13 230 174 11 224 166 10 213 154 11
40224 -180 133 36 124 112 88 86 86 86 58 58 58
40225 - 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 14 14 14
40230 - 34 34 34 70 70 70 138 110 50 158 118 36
40231 -167 114 7 180 123 7 192 133 9 197 138 11
40232 -200 144 11 206 145 10 213 154 11 219 162 10
40233 -224 166 10 230 174 11 239 182 13 242 186 14
40234 -246 186 14 246 186 14 246 186 14 246 186 14
40235 -239 182 13 216 158 10 185 133 11 152 99 6
40236 -104 69 6 18 14 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 2 2 6 2 2 6 2 2 6
40240 - 2 2 6 6 6 6 80 54 7 152 99 6
40241 -192 133 9 219 162 10 236 178 12 239 182 13
40242 -246 186 14 242 186 14 239 182 13 236 178 12
40243 -224 166 10 206 145 10 192 133 9 154 121 60
40244 - 94 94 94 62 62 62 42 42 42 22 22 22
40245 - 14 14 14 6 6 6 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 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 6 6 6
40250 - 18 18 18 34 34 34 58 58 58 78 78 78
40251 -101 98 89 124 112 88 142 110 46 156 107 11
40252 -163 110 8 167 114 7 175 118 6 180 123 7
40253 -185 133 11 197 138 11 210 150 10 219 162 10
40254 -226 170 11 236 178 12 236 178 12 234 174 13
40255 -219 162 10 197 138 11 163 110 8 130 83 6
40256 - 91 60 6 10 10 10 2 2 6 2 2 6
40257 - 18 18 18 38 38 38 38 38 38 38 38 38
40258 - 38 38 38 38 38 38 38 38 38 38 38 38
40259 - 38 38 38 38 38 38 26 26 26 2 2 6
40260 - 2 2 6 6 6 6 70 47 6 137 92 6
40261 -175 118 6 200 144 11 219 162 10 230 174 11
40262 -234 174 13 230 174 11 219 162 10 210 150 10
40263 -192 133 9 163 110 8 124 112 88 82 82 82
40264 - 50 50 50 30 30 30 14 14 14 6 6 6
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 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 6 6 6 14 14 14 22 22 22 34 34 34
40271 - 42 42 42 58 58 58 74 74 74 86 86 86
40272 -101 98 89 122 102 70 130 98 46 121 87 25
40273 -137 92 6 152 99 6 163 110 8 180 123 7
40274 -185 133 11 197 138 11 206 145 10 200 144 11
40275 -180 123 7 156 107 11 130 83 6 104 69 6
40276 - 50 34 6 54 54 54 110 110 110 101 98 89
40277 - 86 86 86 82 82 82 78 78 78 78 78 78
40278 - 78 78 78 78 78 78 78 78 78 78 78 78
40279 - 78 78 78 82 82 82 86 86 86 94 94 94
40280 -106 106 106 101 101 101 86 66 34 124 80 6
40281 -156 107 11 180 123 7 192 133 9 200 144 11
40282 -206 145 10 200 144 11 192 133 9 175 118 6
40283 -139 102 15 109 106 95 70 70 70 42 42 42
40284 - 22 22 22 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 6 6 6 10 10 10
40291 - 14 14 14 22 22 22 30 30 30 38 38 38
40292 - 50 50 50 62 62 62 74 74 74 90 90 90
40293 -101 98 89 112 100 78 121 87 25 124 80 6
40294 -137 92 6 152 99 6 152 99 6 152 99 6
40295 -138 86 6 124 80 6 98 70 6 86 66 30
40296 -101 98 89 82 82 82 58 58 58 46 46 46
40297 - 38 38 38 34 34 34 34 34 34 34 34 34
40298 - 34 34 34 34 34 34 34 34 34 34 34 34
40299 - 34 34 34 34 34 34 38 38 38 42 42 42
40300 - 54 54 54 82 82 82 94 86 76 91 60 6
40301 -134 86 6 156 107 11 167 114 7 175 118 6
40302 -175 118 6 167 114 7 152 99 6 121 87 25
40303 -101 98 89 62 62 62 34 34 34 18 18 18
40304 - 6 6 6 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 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 6 6 6 6 6 6 10 10 10
40312 - 18 18 18 22 22 22 30 30 30 42 42 42
40313 - 50 50 50 66 66 66 86 86 86 101 98 89
40314 -106 86 58 98 70 6 104 69 6 104 69 6
40315 -104 69 6 91 60 6 82 62 34 90 90 90
40316 - 62 62 62 38 38 38 22 22 22 14 14 14
40317 - 10 10 10 10 10 10 10 10 10 10 10 10
40318 - 10 10 10 10 10 10 6 6 6 10 10 10
40319 - 10 10 10 10 10 10 10 10 10 14 14 14
40320 - 22 22 22 42 42 42 70 70 70 89 81 66
40321 - 80 54 7 104 69 6 124 80 6 137 92 6
40322 -134 86 6 116 81 8 100 82 52 86 86 86
40323 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 6 6 6 10 10 10 14 14 14
40333 - 18 18 18 26 26 26 38 38 38 54 54 54
40334 - 70 70 70 86 86 86 94 86 76 89 81 66
40335 - 89 81 66 86 86 86 74 74 74 50 50 50
40336 - 30 30 30 14 14 14 6 6 6 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 6 6 6 18 18 18 34 34 34 58 58 58
40341 - 82 82 82 89 81 66 89 81 66 89 81 66
40342 - 94 86 66 94 86 76 74 74 74 50 50 50
40343 - 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 6 6 6 6 6 6 14 14 14 18 18 18
40354 - 30 30 30 38 38 38 46 46 46 54 54 54
40355 - 50 50 50 42 42 42 30 30 30 18 18 18
40356 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 6 6 6 14 14 14 26 26 26
40361 - 38 38 38 50 50 50 58 58 58 58 58 58
40362 - 54 54 54 42 42 42 30 30 30 18 18 18
40363 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 6 6 6
40374 - 6 6 6 10 10 10 14 14 14 18 18 18
40375 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 6 6 6
40381 - 14 14 14 18 18 18 22 22 22 22 22 22
40382 - 18 18 18 14 14 14 10 10 10 6 6 6
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40401 +4 4 4 4 4 4
40402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40415 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40429 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4
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 4 4 4 3 3 3 0 0 0 0 0 0
40477 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
40482 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40483 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485 +4 4 4 4 4 4
40486 +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 2 2 2 0 0 0 3 4 3 26 28 28
40491 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40492 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
40496 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40497 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40498 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4
40500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40504 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40505 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40506 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
40510 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40511 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40512 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4
40514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40518 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40519 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40520 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
40523 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40524 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40525 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40526 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40527 +4 4 4 4 4 4
40528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40531 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40532 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40533 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40534 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40535 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40536 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40537 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40538 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40539 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40540 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40541 +4 4 4 4 4 4
40542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40545 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40546 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40547 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40548 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40549 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40550 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40551 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40552 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40553 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40554 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40555 +4 4 4 4 4 4
40556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40558 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40559 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40560 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40561 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40562 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40563 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40564 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40565 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40566 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40567 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40568 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40569 +4 4 4 4 4 4
40570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40572 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40573 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40574 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40575 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40576 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40577 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40578 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40579 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40580 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40581 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40582 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40583 +4 4 4 4 4 4
40584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40586 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40587 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40588 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40589 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40590 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40591 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40592 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40593 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40594 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40595 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40596 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40597 +4 4 4 4 4 4
40598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40600 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40601 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40602 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40603 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40604 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40605 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40606 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40607 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40608 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40609 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40610 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40611 +4 4 4 4 4 4
40612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40614 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40615 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40616 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40617 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40618 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40619 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40620 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40621 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40622 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40623 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40624 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40625 +4 4 4 4 4 4
40626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40628 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40629 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40630 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40631 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40632 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40633 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40634 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40635 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40636 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40637 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40638 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40639 +0 0 0 4 4 4
40640 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40641 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40642 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40643 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40644 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40645 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40646 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40647 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40648 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40649 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40650 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40651 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40652 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40653 +2 0 0 0 0 0
40654 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40655 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40656 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40657 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40658 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40659 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40660 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40661 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40662 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40663 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40664 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40665 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40666 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40667 +37 38 37 0 0 0
40668 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40669 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40670 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40671 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40672 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40673 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40674 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40675 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40676 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40677 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40678 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40679 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40680 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40681 +85 115 134 4 0 0
40682 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40683 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40684 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40685 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40686 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40687 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40688 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40689 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40690 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40691 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40692 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40693 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40694 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40695 +60 73 81 4 0 0
40696 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40697 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40698 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40699 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40700 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40701 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40702 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40703 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40704 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40705 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40706 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40707 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40708 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40709 +16 19 21 4 0 0
40710 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40711 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40712 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40713 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40714 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40715 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40716 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40717 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40718 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40719 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40720 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40721 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40722 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40723 +4 0 0 4 3 3
40724 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40725 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40726 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40728 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40729 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40730 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40731 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40732 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40733 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40734 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40735 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40736 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40737 +3 2 2 4 4 4
40738 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40739 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40740 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40741 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40742 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40743 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40744 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40745 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40746 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40747 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40748 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40749 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40750 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40751 +4 4 4 4 4 4
40752 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40753 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40754 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40755 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40756 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40757 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40758 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40759 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40760 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40761 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40762 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40763 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40764 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40765 +4 4 4 4 4 4
40766 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40767 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40768 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40769 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40770 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40771 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40772 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40773 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40774 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40775 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40776 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40777 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40778 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40779 +5 5 5 5 5 5
40780 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40781 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40782 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40783 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40784 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40785 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40786 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40787 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40788 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40789 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40790 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40791 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40792 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40793 +5 5 5 4 4 4
40794 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40795 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40796 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40797 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40798 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40799 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40800 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40801 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40802 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40803 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40804 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40805 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807 +4 4 4 4 4 4
40808 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40809 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40810 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40811 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40812 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40813 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40814 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40815 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40816 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40817 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40818 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40819 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 4 4 4
40822 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40823 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40824 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40825 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40826 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40827 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40828 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40829 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40830 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40831 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40832 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4
40836 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40837 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40838 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40839 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40840 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40841 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40842 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40843 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40844 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40845 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40846 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4
40850 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40851 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40852 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40853 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40854 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40855 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40856 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40857 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40858 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40859 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40860 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863 +4 4 4 4 4 4
40864 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40865 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40866 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40867 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40868 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40869 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40870 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40871 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40872 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40873 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40874 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877 +4 4 4 4 4 4
40878 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40879 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40880 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40881 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40882 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40883 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40884 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40885 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40886 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40887 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40888 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891 +4 4 4 4 4 4
40892 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40893 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40894 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40895 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40896 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40897 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40898 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40899 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40900 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40901 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40902 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905 +4 4 4 4 4 4
40906 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40907 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40908 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40909 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40910 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40911 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40912 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40913 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40914 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40915 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40916 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +4 4 4 4 4 4
40920 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40921 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40922 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40923 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40924 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40925 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40926 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40927 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40928 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40929 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40930 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4
40934 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40935 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40936 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40937 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40938 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40939 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40940 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40941 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40942 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40943 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40944 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947 +4 4 4 4 4 4
40948 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40949 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40950 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40951 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40952 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40953 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40954 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40955 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40956 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40957 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40958 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961 +4 4 4 4 4 4
40962 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40963 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40964 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40965 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40966 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40967 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40968 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40969 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40970 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40971 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40972 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40975 +4 4 4 4 4 4
40976 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40977 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40978 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40979 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40980 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40981 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40982 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40983 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40984 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40985 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40986 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40989 +4 4 4 4 4 4
40990 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40991 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40992 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40993 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40994 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40995 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40996 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40997 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40998 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40999 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41000 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41003 +4 4 4 4 4 4
41004 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41005 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41006 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41007 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41008 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41009 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41010 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41011 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41012 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41013 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41014 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41017 +4 4 4 4 4 4
41018 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41019 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41020 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41021 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41022 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41023 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41024 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41025 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41026 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41027 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41028 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41031 +4 4 4 4 4 4
41032 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41033 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41034 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41035 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41036 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41037 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41038 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41039 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41040 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41041 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41042 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41045 +4 4 4 4 4 4
41046 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41047 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41048 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41049 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41050 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41051 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41052 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41053 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41054 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41055 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41056 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41059 +4 4 4 4 4 4
41060 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41061 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41062 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41063 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41064 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41065 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41066 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41067 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41068 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41069 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41070 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41073 +4 4 4 4 4 4
41074 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41075 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41076 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41077 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41078 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41079 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41080 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41081 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41082 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41083 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41084 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41087 +4 4 4 4 4 4
41088 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41089 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41090 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41091 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41092 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41093 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41094 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41095 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41096 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41097 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41098 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41101 +4 4 4 4 4 4
41102 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41103 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41104 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41105 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41106 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41107 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41108 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41109 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41110 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41111 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41112 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115 +4 4 4 4 4 4
41116 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41117 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41118 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41119 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41120 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41121 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41122 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41123 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41124 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41125 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41126 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41129 +4 4 4 4 4 4
41130 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41131 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41132 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41134 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41135 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41136 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41137 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41138 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41139 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41140 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4
41144 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41145 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41146 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41147 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41148 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41149 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41150 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41151 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41152 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41153 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41154 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4
41158 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41159 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41160 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41161 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41162 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41163 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41164 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41165 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41166 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41167 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41168 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4
41172 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41173 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41174 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41175 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41177 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41178 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41180 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41181 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41182 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4
41186 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41187 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41188 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41189 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41190 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41191 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41192 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41193 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41194 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41195 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41196 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4
41200 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41201 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41202 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41203 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41204 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41205 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41206 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41207 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41208 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41209 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4
41214 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41215 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41216 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41217 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41218 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41219 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41220 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41221 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41222 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41223 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4
41228 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41229 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41230 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41231 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41232 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41233 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41234 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41235 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41236 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41237 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4
41242 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41243 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41244 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41245 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41246 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41247 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41248 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41249 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41250 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41251 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4
41256 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41257 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41258 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41259 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41260 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41261 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41262 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41263 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41264 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4
41270 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41271 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41272 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41273 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41274 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41275 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41276 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41277 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41278 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4
41284 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41285 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41286 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41287 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41288 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41289 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41290 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41291 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41292 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4
41298 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41299 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41300 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41301 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41302 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41303 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41304 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41305 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41313 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41314 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41315 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41316 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41317 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41318 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41319 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41327 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41328 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41329 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41330 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41331 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41332 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41333 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41342 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41343 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41344 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41345 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41346 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41347 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
41356 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41357 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41358 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41359 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41360 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41361 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41371 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41372 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41373 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41374 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41375 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4
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 5 5 5
41385 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41386 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41387 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41388 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41400 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41401 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41402 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
41414 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41415 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41416 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
41428 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41429 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41430 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4
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 5 5 5
41442 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41443 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41444 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41457 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41458 +4 3 3 5 5 5 5 5 5 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 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41471 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41472 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4
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 4 4 4 5 5 5 4 3 3 6 6 6
41485 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4
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 4 4 4 4 4 4 5 5 5 4 3 3
41499 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4
41508 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41509 index a40c05e..785c583 100644
41510 --- a/drivers/video/udlfb.c
41511 +++ b/drivers/video/udlfb.c
41512 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41513 dlfb_urb_completion(urb);
41514
41515 error:
41516 - atomic_add(bytes_sent, &dev->bytes_sent);
41517 - atomic_add(bytes_identical, &dev->bytes_identical);
41518 - atomic_add(width*height*2, &dev->bytes_rendered);
41519 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41520 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41521 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41522 end_cycles = get_cycles();
41523 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41524 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41525 >> 10)), /* Kcycles */
41526 &dev->cpu_kcycles_used);
41527
41528 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41529 dlfb_urb_completion(urb);
41530
41531 error:
41532 - atomic_add(bytes_sent, &dev->bytes_sent);
41533 - atomic_add(bytes_identical, &dev->bytes_identical);
41534 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41535 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41536 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41537 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41538 end_cycles = get_cycles();
41539 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41540 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41541 >> 10)), /* Kcycles */
41542 &dev->cpu_kcycles_used);
41543 }
41544 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41545 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41546 struct dlfb_data *dev = fb_info->par;
41547 return snprintf(buf, PAGE_SIZE, "%u\n",
41548 - atomic_read(&dev->bytes_rendered));
41549 + atomic_read_unchecked(&dev->bytes_rendered));
41550 }
41551
41552 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41553 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41554 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41555 struct dlfb_data *dev = fb_info->par;
41556 return snprintf(buf, PAGE_SIZE, "%u\n",
41557 - atomic_read(&dev->bytes_identical));
41558 + atomic_read_unchecked(&dev->bytes_identical));
41559 }
41560
41561 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41562 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41563 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41564 struct dlfb_data *dev = fb_info->par;
41565 return snprintf(buf, PAGE_SIZE, "%u\n",
41566 - atomic_read(&dev->bytes_sent));
41567 + atomic_read_unchecked(&dev->bytes_sent));
41568 }
41569
41570 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41571 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41572 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41573 struct dlfb_data *dev = fb_info->par;
41574 return snprintf(buf, PAGE_SIZE, "%u\n",
41575 - atomic_read(&dev->cpu_kcycles_used));
41576 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41577 }
41578
41579 static ssize_t edid_show(
41580 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41581 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41582 struct dlfb_data *dev = fb_info->par;
41583
41584 - atomic_set(&dev->bytes_rendered, 0);
41585 - atomic_set(&dev->bytes_identical, 0);
41586 - atomic_set(&dev->bytes_sent, 0);
41587 - atomic_set(&dev->cpu_kcycles_used, 0);
41588 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41589 + atomic_set_unchecked(&dev->bytes_identical, 0);
41590 + atomic_set_unchecked(&dev->bytes_sent, 0);
41591 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41592
41593 return count;
41594 }
41595 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41596 index e7f69ef..83af4fd 100644
41597 --- a/drivers/video/uvesafb.c
41598 +++ b/drivers/video/uvesafb.c
41599 @@ -19,6 +19,7 @@
41600 #include <linux/io.h>
41601 #include <linux/mutex.h>
41602 #include <linux/slab.h>
41603 +#include <linux/moduleloader.h>
41604 #include <video/edid.h>
41605 #include <video/uvesafb.h>
41606 #ifdef CONFIG_X86
41607 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41608 NULL,
41609 };
41610
41611 - return call_usermodehelper(v86d_path, argv, envp, 1);
41612 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41613 }
41614
41615 /*
41616 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41617 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41618 par->pmi_setpal = par->ypan = 0;
41619 } else {
41620 +
41621 +#ifdef CONFIG_PAX_KERNEXEC
41622 +#ifdef CONFIG_MODULES
41623 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41624 +#endif
41625 + if (!par->pmi_code) {
41626 + par->pmi_setpal = par->ypan = 0;
41627 + return 0;
41628 + }
41629 +#endif
41630 +
41631 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41632 + task->t.regs.edi);
41633 +
41634 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41635 + pax_open_kernel();
41636 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41637 + pax_close_kernel();
41638 +
41639 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41640 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41641 +#else
41642 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41643 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41644 +#endif
41645 +
41646 printk(KERN_INFO "uvesafb: protected mode interface info at "
41647 "%04x:%04x\n",
41648 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41649 @@ -1821,6 +1844,11 @@ out:
41650 if (par->vbe_modes)
41651 kfree(par->vbe_modes);
41652
41653 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41654 + if (par->pmi_code)
41655 + module_free_exec(NULL, par->pmi_code);
41656 +#endif
41657 +
41658 framebuffer_release(info);
41659 return err;
41660 }
41661 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41662 kfree(par->vbe_state_orig);
41663 if (par->vbe_state_saved)
41664 kfree(par->vbe_state_saved);
41665 +
41666 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41667 + if (par->pmi_code)
41668 + module_free_exec(NULL, par->pmi_code);
41669 +#endif
41670 +
41671 }
41672
41673 framebuffer_release(info);
41674 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41675 index 501b340..86bd4cf 100644
41676 --- a/drivers/video/vesafb.c
41677 +++ b/drivers/video/vesafb.c
41678 @@ -9,6 +9,7 @@
41679 */
41680
41681 #include <linux/module.h>
41682 +#include <linux/moduleloader.h>
41683 #include <linux/kernel.h>
41684 #include <linux/errno.h>
41685 #include <linux/string.h>
41686 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41687 static int vram_total __initdata; /* Set total amount of memory */
41688 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41689 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41690 -static void (*pmi_start)(void) __read_mostly;
41691 -static void (*pmi_pal) (void) __read_mostly;
41692 +static void (*pmi_start)(void) __read_only;
41693 +static void (*pmi_pal) (void) __read_only;
41694 static int depth __read_mostly;
41695 static int vga_compat __read_mostly;
41696 /* --------------------------------------------------------------------- */
41697 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41698 unsigned int size_vmode;
41699 unsigned int size_remap;
41700 unsigned int size_total;
41701 + void *pmi_code = NULL;
41702
41703 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41704 return -ENODEV;
41705 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41706 size_remap = size_total;
41707 vesafb_fix.smem_len = size_remap;
41708
41709 -#ifndef __i386__
41710 - screen_info.vesapm_seg = 0;
41711 -#endif
41712 -
41713 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41714 printk(KERN_WARNING
41715 "vesafb: cannot reserve video memory at 0x%lx\n",
41716 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41717 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41718 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41719
41720 +#ifdef __i386__
41721 +
41722 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41723 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41724 + if (!pmi_code)
41725 +#elif !defined(CONFIG_PAX_KERNEXEC)
41726 + if (0)
41727 +#endif
41728 +
41729 +#endif
41730 + screen_info.vesapm_seg = 0;
41731 +
41732 if (screen_info.vesapm_seg) {
41733 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41734 - screen_info.vesapm_seg,screen_info.vesapm_off);
41735 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41736 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41737 }
41738
41739 if (screen_info.vesapm_seg < 0xc000)
41740 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41741
41742 if (ypan || pmi_setpal) {
41743 unsigned short *pmi_base;
41744 +
41745 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41746 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41747 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41748 +
41749 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41750 + pax_open_kernel();
41751 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41752 +#else
41753 + pmi_code = pmi_base;
41754 +#endif
41755 +
41756 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41757 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41758 +
41759 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41760 + pmi_start = ktva_ktla(pmi_start);
41761 + pmi_pal = ktva_ktla(pmi_pal);
41762 + pax_close_kernel();
41763 +#endif
41764 +
41765 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41766 if (pmi_base[3]) {
41767 printk(KERN_INFO "vesafb: pmi: ports = ");
41768 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41769 info->node, info->fix.id);
41770 return 0;
41771 err:
41772 +
41773 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41774 + module_free_exec(NULL, pmi_code);
41775 +#endif
41776 +
41777 if (info->screen_base)
41778 iounmap(info->screen_base);
41779 framebuffer_release(info);
41780 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41781 index 88714ae..16c2e11 100644
41782 --- a/drivers/video/via/via_clock.h
41783 +++ b/drivers/video/via/via_clock.h
41784 @@ -56,7 +56,7 @@ struct via_clock {
41785
41786 void (*set_engine_pll_state)(u8 state);
41787 void (*set_engine_pll)(struct via_pll_config config);
41788 -};
41789 +} __no_const;
41790
41791
41792 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41793 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41794 index e56c934..fc22f4b 100644
41795 --- a/drivers/xen/xen-pciback/conf_space.h
41796 +++ b/drivers/xen/xen-pciback/conf_space.h
41797 @@ -44,15 +44,15 @@ struct config_field {
41798 struct {
41799 conf_dword_write write;
41800 conf_dword_read read;
41801 - } dw;
41802 + } __no_const dw;
41803 struct {
41804 conf_word_write write;
41805 conf_word_read read;
41806 - } w;
41807 + } __no_const w;
41808 struct {
41809 conf_byte_write write;
41810 conf_byte_read read;
41811 - } b;
41812 + } __no_const b;
41813 } u;
41814 struct list_head list;
41815 };
41816 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41817 index 014c8dd..6f3dfe6 100644
41818 --- a/fs/9p/vfs_inode.c
41819 +++ b/fs/9p/vfs_inode.c
41820 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41821 void
41822 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41823 {
41824 - char *s = nd_get_link(nd);
41825 + const char *s = nd_get_link(nd);
41826
41827 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41828 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41829 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41830 index e95d1b6..3454244 100644
41831 --- a/fs/Kconfig.binfmt
41832 +++ b/fs/Kconfig.binfmt
41833 @@ -89,7 +89,7 @@ config HAVE_AOUT
41834
41835 config BINFMT_AOUT
41836 tristate "Kernel support for a.out and ECOFF binaries"
41837 - depends on HAVE_AOUT
41838 + depends on HAVE_AOUT && BROKEN
41839 ---help---
41840 A.out (Assembler.OUTput) is a set of formats for libraries and
41841 executables used in the earliest versions of UNIX. Linux used
41842 diff --git a/fs/aio.c b/fs/aio.c
41843 index b9d64d8..86cb1d5 100644
41844 --- a/fs/aio.c
41845 +++ b/fs/aio.c
41846 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41847 size += sizeof(struct io_event) * nr_events;
41848 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41849
41850 - if (nr_pages < 0)
41851 + if (nr_pages <= 0)
41852 return -EINVAL;
41853
41854 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41855 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41856 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41857 {
41858 ssize_t ret;
41859 + struct iovec iovstack;
41860
41861 #ifdef CONFIG_COMPAT
41862 if (compat)
41863 ret = compat_rw_copy_check_uvector(type,
41864 (struct compat_iovec __user *)kiocb->ki_buf,
41865 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41866 + kiocb->ki_nbytes, 1, &iovstack,
41867 &kiocb->ki_iovec, 1);
41868 else
41869 #endif
41870 ret = rw_copy_check_uvector(type,
41871 (struct iovec __user *)kiocb->ki_buf,
41872 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41873 + kiocb->ki_nbytes, 1, &iovstack,
41874 &kiocb->ki_iovec, 1);
41875 if (ret < 0)
41876 goto out;
41877
41878 + if (kiocb->ki_iovec == &iovstack) {
41879 + kiocb->ki_inline_vec = iovstack;
41880 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41881 + }
41882 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41883 kiocb->ki_cur_seg = 0;
41884 /* ki_nbytes/left now reflect bytes instead of segs */
41885 diff --git a/fs/attr.c b/fs/attr.c
41886 index 95053ad..2cc93ca 100644
41887 --- a/fs/attr.c
41888 +++ b/fs/attr.c
41889 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41890 unsigned long limit;
41891
41892 limit = rlimit(RLIMIT_FSIZE);
41893 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41894 if (limit != RLIM_INFINITY && offset > limit)
41895 goto out_sig;
41896 if (offset > inode->i_sb->s_maxbytes)
41897 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41898 index 9c098db..c755da5 100644
41899 --- a/fs/autofs4/waitq.c
41900 +++ b/fs/autofs4/waitq.c
41901 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41902 {
41903 unsigned long sigpipe, flags;
41904 mm_segment_t fs;
41905 - const char *data = (const char *)addr;
41906 + const char __user *data = (const char __force_user *)addr;
41907 ssize_t wr = 0;
41908
41909 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41910 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41911 index 6e6d536..457113a 100644
41912 --- a/fs/befs/linuxvfs.c
41913 +++ b/fs/befs/linuxvfs.c
41914 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41915 {
41916 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41917 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41918 - char *link = nd_get_link(nd);
41919 + const char *link = nd_get_link(nd);
41920 if (!IS_ERR(link))
41921 kfree(link);
41922 }
41923 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41924 index 1ff9405..f1e376a 100644
41925 --- a/fs/binfmt_aout.c
41926 +++ b/fs/binfmt_aout.c
41927 @@ -16,6 +16,7 @@
41928 #include <linux/string.h>
41929 #include <linux/fs.h>
41930 #include <linux/file.h>
41931 +#include <linux/security.h>
41932 #include <linux/stat.h>
41933 #include <linux/fcntl.h>
41934 #include <linux/ptrace.h>
41935 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41936 #endif
41937 # define START_STACK(u) ((void __user *)u.start_stack)
41938
41939 + memset(&dump, 0, sizeof(dump));
41940 +
41941 fs = get_fs();
41942 set_fs(KERNEL_DS);
41943 has_dumped = 1;
41944 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41945
41946 /* If the size of the dump file exceeds the rlimit, then see what would happen
41947 if we wrote the stack, but not the data area. */
41948 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41949 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41950 dump.u_dsize = 0;
41951
41952 /* Make sure we have enough room to write the stack and data areas. */
41953 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41954 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41955 dump.u_ssize = 0;
41956
41957 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41958 rlim = rlimit(RLIMIT_DATA);
41959 if (rlim >= RLIM_INFINITY)
41960 rlim = ~0;
41961 +
41962 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41963 if (ex.a_data + ex.a_bss > rlim)
41964 return -ENOMEM;
41965
41966 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41967 install_exec_creds(bprm);
41968 current->flags &= ~PF_FORKNOEXEC;
41969
41970 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41971 + current->mm->pax_flags = 0UL;
41972 +#endif
41973 +
41974 +#ifdef CONFIG_PAX_PAGEEXEC
41975 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41976 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41977 +
41978 +#ifdef CONFIG_PAX_EMUTRAMP
41979 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41980 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41981 +#endif
41982 +
41983 +#ifdef CONFIG_PAX_MPROTECT
41984 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41985 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41986 +#endif
41987 +
41988 + }
41989 +#endif
41990 +
41991 if (N_MAGIC(ex) == OMAGIC) {
41992 unsigned long text_addr, map_size;
41993 loff_t pos;
41994 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41995
41996 down_write(&current->mm->mmap_sem);
41997 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41998 - PROT_READ | PROT_WRITE | PROT_EXEC,
41999 + PROT_READ | PROT_WRITE,
42000 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42001 fd_offset + ex.a_text);
42002 up_write(&current->mm->mmap_sem);
42003 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42004 index 07d096c..851a18b 100644
42005 --- a/fs/binfmt_elf.c
42006 +++ b/fs/binfmt_elf.c
42007 @@ -32,6 +32,7 @@
42008 #include <linux/elf.h>
42009 #include <linux/utsname.h>
42010 #include <linux/coredump.h>
42011 +#include <linux/xattr.h>
42012 #include <asm/uaccess.h>
42013 #include <asm/param.h>
42014 #include <asm/page.h>
42015 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42016 #define elf_core_dump NULL
42017 #endif
42018
42019 +#ifdef CONFIG_PAX_MPROTECT
42020 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42021 +#endif
42022 +
42023 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42024 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42025 #else
42026 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42027 .load_binary = load_elf_binary,
42028 .load_shlib = load_elf_library,
42029 .core_dump = elf_core_dump,
42030 +
42031 +#ifdef CONFIG_PAX_MPROTECT
42032 + .handle_mprotect= elf_handle_mprotect,
42033 +#endif
42034 +
42035 .min_coredump = ELF_EXEC_PAGESIZE,
42036 };
42037
42038 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42039
42040 static int set_brk(unsigned long start, unsigned long end)
42041 {
42042 + unsigned long e = end;
42043 +
42044 start = ELF_PAGEALIGN(start);
42045 end = ELF_PAGEALIGN(end);
42046 if (end > start) {
42047 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42048 if (BAD_ADDR(addr))
42049 return addr;
42050 }
42051 - current->mm->start_brk = current->mm->brk = end;
42052 + current->mm->start_brk = current->mm->brk = e;
42053 return 0;
42054 }
42055
42056 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42057 elf_addr_t __user *u_rand_bytes;
42058 const char *k_platform = ELF_PLATFORM;
42059 const char *k_base_platform = ELF_BASE_PLATFORM;
42060 - unsigned char k_rand_bytes[16];
42061 + u32 k_rand_bytes[4];
42062 int items;
42063 elf_addr_t *elf_info;
42064 int ei_index = 0;
42065 const struct cred *cred = current_cred();
42066 struct vm_area_struct *vma;
42067 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42068
42069 /*
42070 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42071 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42072 * Generate 16 random bytes for userspace PRNG seeding.
42073 */
42074 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42075 - u_rand_bytes = (elf_addr_t __user *)
42076 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42077 + srandom32(k_rand_bytes[0] ^ random32());
42078 + srandom32(k_rand_bytes[1] ^ random32());
42079 + srandom32(k_rand_bytes[2] ^ random32());
42080 + srandom32(k_rand_bytes[3] ^ random32());
42081 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42082 + u_rand_bytes = (elf_addr_t __user *) p;
42083 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42084 return -EFAULT;
42085
42086 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42087 return -EFAULT;
42088 current->mm->env_end = p;
42089
42090 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42091 +
42092 /* Put the elf_info on the stack in the right place. */
42093 sp = (elf_addr_t __user *)envp + 1;
42094 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42095 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42096 return -EFAULT;
42097 return 0;
42098 }
42099 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42100 {
42101 struct elf_phdr *elf_phdata;
42102 struct elf_phdr *eppnt;
42103 - unsigned long load_addr = 0;
42104 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42105 int load_addr_set = 0;
42106 unsigned long last_bss = 0, elf_bss = 0;
42107 - unsigned long error = ~0UL;
42108 + unsigned long error = -EINVAL;
42109 unsigned long total_size;
42110 int retval, i, size;
42111
42112 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42113 goto out_close;
42114 }
42115
42116 +#ifdef CONFIG_PAX_SEGMEXEC
42117 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42118 + pax_task_size = SEGMEXEC_TASK_SIZE;
42119 +#endif
42120 +
42121 eppnt = elf_phdata;
42122 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42123 if (eppnt->p_type == PT_LOAD) {
42124 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42125 k = load_addr + eppnt->p_vaddr;
42126 if (BAD_ADDR(k) ||
42127 eppnt->p_filesz > eppnt->p_memsz ||
42128 - eppnt->p_memsz > TASK_SIZE ||
42129 - TASK_SIZE - eppnt->p_memsz < k) {
42130 + eppnt->p_memsz > pax_task_size ||
42131 + pax_task_size - eppnt->p_memsz < k) {
42132 error = -ENOMEM;
42133 goto out_close;
42134 }
42135 @@ -528,6 +552,351 @@ out:
42136 return error;
42137 }
42138
42139 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42140 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42141 +{
42142 + unsigned long pax_flags = 0UL;
42143 +
42144 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42145 +
42146 +#ifdef CONFIG_PAX_PAGEEXEC
42147 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42148 + pax_flags |= MF_PAX_PAGEEXEC;
42149 +#endif
42150 +
42151 +#ifdef CONFIG_PAX_SEGMEXEC
42152 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42153 + pax_flags |= MF_PAX_SEGMEXEC;
42154 +#endif
42155 +
42156 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42157 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42158 + if ((__supported_pte_mask & _PAGE_NX))
42159 + pax_flags &= ~MF_PAX_SEGMEXEC;
42160 + else
42161 + pax_flags &= ~MF_PAX_PAGEEXEC;
42162 + }
42163 +#endif
42164 +
42165 +#ifdef CONFIG_PAX_EMUTRAMP
42166 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42167 + pax_flags |= MF_PAX_EMUTRAMP;
42168 +#endif
42169 +
42170 +#ifdef CONFIG_PAX_MPROTECT
42171 + if (elf_phdata->p_flags & PF_MPROTECT)
42172 + pax_flags |= MF_PAX_MPROTECT;
42173 +#endif
42174 +
42175 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42176 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42177 + pax_flags |= MF_PAX_RANDMMAP;
42178 +#endif
42179 +
42180 +#endif
42181 +
42182 + return pax_flags;
42183 +}
42184 +
42185 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42186 +{
42187 + unsigned long pax_flags = 0UL;
42188 +
42189 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42190 +
42191 +#ifdef CONFIG_PAX_PAGEEXEC
42192 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42193 + pax_flags |= MF_PAX_PAGEEXEC;
42194 +#endif
42195 +
42196 +#ifdef CONFIG_PAX_SEGMEXEC
42197 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42198 + pax_flags |= MF_PAX_SEGMEXEC;
42199 +#endif
42200 +
42201 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42202 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42203 + if ((__supported_pte_mask & _PAGE_NX))
42204 + pax_flags &= ~MF_PAX_SEGMEXEC;
42205 + else
42206 + pax_flags &= ~MF_PAX_PAGEEXEC;
42207 + }
42208 +#endif
42209 +
42210 +#ifdef CONFIG_PAX_EMUTRAMP
42211 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42212 + pax_flags |= MF_PAX_EMUTRAMP;
42213 +#endif
42214 +
42215 +#ifdef CONFIG_PAX_MPROTECT
42216 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42217 + pax_flags |= MF_PAX_MPROTECT;
42218 +#endif
42219 +
42220 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42221 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42222 + pax_flags |= MF_PAX_RANDMMAP;
42223 +#endif
42224 +
42225 +#endif
42226 +
42227 + return pax_flags;
42228 +}
42229 +
42230 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42231 +{
42232 + unsigned long pax_flags = 0UL;
42233 +
42234 +#ifdef CONFIG_PAX_EI_PAX
42235 +
42236 +#ifdef CONFIG_PAX_PAGEEXEC
42237 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42238 + pax_flags |= MF_PAX_PAGEEXEC;
42239 +#endif
42240 +
42241 +#ifdef CONFIG_PAX_SEGMEXEC
42242 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42243 + pax_flags |= MF_PAX_SEGMEXEC;
42244 +#endif
42245 +
42246 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42247 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42248 + if ((__supported_pte_mask & _PAGE_NX))
42249 + pax_flags &= ~MF_PAX_SEGMEXEC;
42250 + else
42251 + pax_flags &= ~MF_PAX_PAGEEXEC;
42252 + }
42253 +#endif
42254 +
42255 +#ifdef CONFIG_PAX_EMUTRAMP
42256 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42257 + pax_flags |= MF_PAX_EMUTRAMP;
42258 +#endif
42259 +
42260 +#ifdef CONFIG_PAX_MPROTECT
42261 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42262 + pax_flags |= MF_PAX_MPROTECT;
42263 +#endif
42264 +
42265 +#ifdef CONFIG_PAX_ASLR
42266 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42267 + pax_flags |= MF_PAX_RANDMMAP;
42268 +#endif
42269 +
42270 +#else
42271 +
42272 +#ifdef CONFIG_PAX_PAGEEXEC
42273 + pax_flags |= MF_PAX_PAGEEXEC;
42274 +#endif
42275 +
42276 +#ifdef CONFIG_PAX_MPROTECT
42277 + pax_flags |= MF_PAX_MPROTECT;
42278 +#endif
42279 +
42280 +#ifdef CONFIG_PAX_RANDMMAP
42281 + pax_flags |= MF_PAX_RANDMMAP;
42282 +#endif
42283 +
42284 +#ifdef CONFIG_PAX_SEGMEXEC
42285 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42286 + pax_flags &= ~MF_PAX_PAGEEXEC;
42287 + pax_flags |= MF_PAX_SEGMEXEC;
42288 + }
42289 +#endif
42290 +
42291 +#endif
42292 +
42293 + return pax_flags;
42294 +}
42295 +
42296 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42297 +{
42298 +
42299 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42300 + unsigned long i;
42301 +
42302 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42303 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42304 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42305 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42306 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42307 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42308 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42309 + return ~0UL;
42310 +
42311 +#ifdef CONFIG_PAX_SOFTMODE
42312 + if (pax_softmode)
42313 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42314 + else
42315 +#endif
42316 +
42317 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42318 + break;
42319 + }
42320 +#endif
42321 +
42322 + return ~0UL;
42323 +}
42324 +
42325 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42326 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42327 +{
42328 + unsigned long pax_flags = 0UL;
42329 +
42330 +#ifdef CONFIG_PAX_PAGEEXEC
42331 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42332 + pax_flags |= MF_PAX_PAGEEXEC;
42333 +#endif
42334 +
42335 +#ifdef CONFIG_PAX_SEGMEXEC
42336 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42337 + pax_flags |= MF_PAX_SEGMEXEC;
42338 +#endif
42339 +
42340 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42341 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42342 + if ((__supported_pte_mask & _PAGE_NX))
42343 + pax_flags &= ~MF_PAX_SEGMEXEC;
42344 + else
42345 + pax_flags &= ~MF_PAX_PAGEEXEC;
42346 + }
42347 +#endif
42348 +
42349 +#ifdef CONFIG_PAX_EMUTRAMP
42350 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42351 + pax_flags |= MF_PAX_EMUTRAMP;
42352 +#endif
42353 +
42354 +#ifdef CONFIG_PAX_MPROTECT
42355 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42356 + pax_flags |= MF_PAX_MPROTECT;
42357 +#endif
42358 +
42359 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42360 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42361 + pax_flags |= MF_PAX_RANDMMAP;
42362 +#endif
42363 +
42364 + return pax_flags;
42365 +}
42366 +
42367 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42368 +{
42369 + unsigned long pax_flags = 0UL;
42370 +
42371 +#ifdef CONFIG_PAX_PAGEEXEC
42372 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42373 + pax_flags |= MF_PAX_PAGEEXEC;
42374 +#endif
42375 +
42376 +#ifdef CONFIG_PAX_SEGMEXEC
42377 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42378 + pax_flags |= MF_PAX_SEGMEXEC;
42379 +#endif
42380 +
42381 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42382 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42383 + if ((__supported_pte_mask & _PAGE_NX))
42384 + pax_flags &= ~MF_PAX_SEGMEXEC;
42385 + else
42386 + pax_flags &= ~MF_PAX_PAGEEXEC;
42387 + }
42388 +#endif
42389 +
42390 +#ifdef CONFIG_PAX_EMUTRAMP
42391 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42392 + pax_flags |= MF_PAX_EMUTRAMP;
42393 +#endif
42394 +
42395 +#ifdef CONFIG_PAX_MPROTECT
42396 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42397 + pax_flags |= MF_PAX_MPROTECT;
42398 +#endif
42399 +
42400 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42401 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42402 + pax_flags |= MF_PAX_RANDMMAP;
42403 +#endif
42404 +
42405 + return pax_flags;
42406 +}
42407 +#endif
42408 +
42409 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42410 +{
42411 +
42412 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42413 + ssize_t xattr_size, i;
42414 + unsigned char xattr_value[5];
42415 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42416 +
42417 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42418 + if (xattr_size <= 0)
42419 + return ~0UL;
42420 +
42421 + for (i = 0; i < xattr_size; i++)
42422 + switch (xattr_value[i]) {
42423 + default:
42424 + return ~0UL;
42425 +
42426 +#define parse_flag(option1, option2, flag) \
42427 + case option1: \
42428 + pax_flags_hardmode |= MF_PAX_##flag; \
42429 + break; \
42430 + case option2: \
42431 + pax_flags_softmode |= MF_PAX_##flag; \
42432 + break;
42433 +
42434 + parse_flag('p', 'P', PAGEEXEC);
42435 + parse_flag('e', 'E', EMUTRAMP);
42436 + parse_flag('m', 'M', MPROTECT);
42437 + parse_flag('r', 'R', RANDMMAP);
42438 + parse_flag('s', 'S', SEGMEXEC);
42439 +
42440 +#undef parse_flag
42441 + }
42442 +
42443 + if (pax_flags_hardmode & pax_flags_softmode)
42444 + return ~0UL;
42445 +
42446 +#ifdef CONFIG_PAX_SOFTMODE
42447 + if (pax_softmode)
42448 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42449 + else
42450 +#endif
42451 +
42452 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42453 +#else
42454 + return ~0UL;
42455 +#endif
42456 +
42457 +}
42458 +
42459 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42460 +{
42461 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42462 +
42463 + pax_flags = pax_parse_ei_pax(elf_ex);
42464 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42465 + xattr_pax_flags = pax_parse_xattr_pax(file);
42466 +
42467 + if (pt_pax_flags == ~0UL)
42468 + pt_pax_flags = xattr_pax_flags;
42469 + else if (xattr_pax_flags == ~0UL)
42470 + xattr_pax_flags = pt_pax_flags;
42471 + if (pt_pax_flags != xattr_pax_flags)
42472 + return -EINVAL;
42473 + if (pt_pax_flags != ~0UL)
42474 + pax_flags = pt_pax_flags;
42475 +
42476 + if (0 > pax_check_flags(&pax_flags))
42477 + return -EINVAL;
42478 +
42479 + current->mm->pax_flags = pax_flags;
42480 + return 0;
42481 +}
42482 +#endif
42483 +
42484 /*
42485 * These are the functions used to load ELF style executables and shared
42486 * libraries. There is no binary dependent code anywhere else.
42487 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42488 {
42489 unsigned int random_variable = 0;
42490
42491 +#ifdef CONFIG_PAX_RANDUSTACK
42492 + if (randomize_va_space)
42493 + return stack_top - current->mm->delta_stack;
42494 +#endif
42495 +
42496 if ((current->flags & PF_RANDOMIZE) &&
42497 !(current->personality & ADDR_NO_RANDOMIZE)) {
42498 random_variable = get_random_int() & STACK_RND_MASK;
42499 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42500 unsigned long load_addr = 0, load_bias = 0;
42501 int load_addr_set = 0;
42502 char * elf_interpreter = NULL;
42503 - unsigned long error;
42504 + unsigned long error = 0;
42505 struct elf_phdr *elf_ppnt, *elf_phdata;
42506 unsigned long elf_bss, elf_brk;
42507 int retval, i;
42508 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42509 unsigned long start_code, end_code, start_data, end_data;
42510 unsigned long reloc_func_desc __maybe_unused = 0;
42511 int executable_stack = EXSTACK_DEFAULT;
42512 - unsigned long def_flags = 0;
42513 struct {
42514 struct elfhdr elf_ex;
42515 struct elfhdr interp_elf_ex;
42516 } *loc;
42517 + unsigned long pax_task_size = TASK_SIZE;
42518
42519 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42520 if (!loc) {
42521 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42522
42523 /* OK, This is the point of no return */
42524 current->flags &= ~PF_FORKNOEXEC;
42525 - current->mm->def_flags = def_flags;
42526 +
42527 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42528 + current->mm->pax_flags = 0UL;
42529 +#endif
42530 +
42531 +#ifdef CONFIG_PAX_DLRESOLVE
42532 + current->mm->call_dl_resolve = 0UL;
42533 +#endif
42534 +
42535 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42536 + current->mm->call_syscall = 0UL;
42537 +#endif
42538 +
42539 +#ifdef CONFIG_PAX_ASLR
42540 + current->mm->delta_mmap = 0UL;
42541 + current->mm->delta_stack = 0UL;
42542 +#endif
42543 +
42544 + current->mm->def_flags = 0;
42545 +
42546 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42547 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42548 + send_sig(SIGKILL, current, 0);
42549 + goto out_free_dentry;
42550 + }
42551 +#endif
42552 +
42553 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42554 + pax_set_initial_flags(bprm);
42555 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42556 + if (pax_set_initial_flags_func)
42557 + (pax_set_initial_flags_func)(bprm);
42558 +#endif
42559 +
42560 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42561 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42562 + current->mm->context.user_cs_limit = PAGE_SIZE;
42563 + current->mm->def_flags |= VM_PAGEEXEC;
42564 + }
42565 +#endif
42566 +
42567 +#ifdef CONFIG_PAX_SEGMEXEC
42568 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42569 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42570 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42571 + pax_task_size = SEGMEXEC_TASK_SIZE;
42572 + current->mm->def_flags |= VM_NOHUGEPAGE;
42573 + }
42574 +#endif
42575 +
42576 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42577 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42578 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42579 + put_cpu();
42580 + }
42581 +#endif
42582
42583 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42584 may depend on the personality. */
42585 SET_PERSONALITY(loc->elf_ex);
42586 +
42587 +#ifdef CONFIG_PAX_ASLR
42588 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42589 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42590 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42591 + }
42592 +#endif
42593 +
42594 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42595 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42596 + executable_stack = EXSTACK_DISABLE_X;
42597 + current->personality &= ~READ_IMPLIES_EXEC;
42598 + } else
42599 +#endif
42600 +
42601 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42602 current->personality |= READ_IMPLIES_EXEC;
42603
42604 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42605 #else
42606 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42607 #endif
42608 +
42609 +#ifdef CONFIG_PAX_RANDMMAP
42610 + /* PaX: randomize base address at the default exe base if requested */
42611 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42612 +#ifdef CONFIG_SPARC64
42613 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42614 +#else
42615 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42616 +#endif
42617 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42618 + elf_flags |= MAP_FIXED;
42619 + }
42620 +#endif
42621 +
42622 }
42623
42624 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42625 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42626 * allowed task size. Note that p_filesz must always be
42627 * <= p_memsz so it is only necessary to check p_memsz.
42628 */
42629 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42630 - elf_ppnt->p_memsz > TASK_SIZE ||
42631 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42632 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42633 + elf_ppnt->p_memsz > pax_task_size ||
42634 + pax_task_size - elf_ppnt->p_memsz < k) {
42635 /* set_brk can never work. Avoid overflows. */
42636 send_sig(SIGKILL, current, 0);
42637 retval = -EINVAL;
42638 @@ -881,11 +1339,36 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42639 goto out_free_dentry;
42640 }
42641 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42642 - send_sig(SIGSEGV, current, 0);
42643 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42644 - goto out_free_dentry;
42645 + /*
42646 + * This bss-zeroing can fail if the ELF
42647 + * file specifies odd protections. So
42648 + * we don't check the return value
42649 + */
42650 }
42651
42652 +#ifdef CONFIG_PAX_RANDMMAP
42653 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42654 + unsigned long start, size;
42655 +
42656 + start = ELF_PAGEALIGN(elf_brk);
42657 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42658 + down_write(&current->mm->mmap_sem);
42659 + retval = -ENOMEM;
42660 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42661 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42662 + start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42663 + retval = IS_ERR_VALUE(start) ? start : 0;
42664 + }
42665 + up_write(&current->mm->mmap_sem);
42666 + if (retval == 0)
42667 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42668 + if (retval < 0) {
42669 + send_sig(SIGKILL, current, 0);
42670 + goto out_free_dentry;
42671 + }
42672 + }
42673 +#endif
42674 +
42675 if (elf_interpreter) {
42676 unsigned long uninitialized_var(interp_map_addr);
42677
42678 @@ -1098,7 +1581,7 @@ out:
42679 * Decide what to dump of a segment, part, all or none.
42680 */
42681 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42682 - unsigned long mm_flags)
42683 + unsigned long mm_flags, long signr)
42684 {
42685 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42686
42687 @@ -1132,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42688 if (vma->vm_file == NULL)
42689 return 0;
42690
42691 - if (FILTER(MAPPED_PRIVATE))
42692 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42693 goto whole;
42694
42695 /*
42696 @@ -1354,9 +1837,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42697 {
42698 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42699 int i = 0;
42700 - do
42701 + do {
42702 i += 2;
42703 - while (auxv[i - 2] != AT_NULL);
42704 + } while (auxv[i - 2] != AT_NULL);
42705 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42706 }
42707
42708 @@ -1862,14 +2345,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42709 }
42710
42711 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42712 - unsigned long mm_flags)
42713 + struct coredump_params *cprm)
42714 {
42715 struct vm_area_struct *vma;
42716 size_t size = 0;
42717
42718 for (vma = first_vma(current, gate_vma); vma != NULL;
42719 vma = next_vma(vma, gate_vma))
42720 - size += vma_dump_size(vma, mm_flags);
42721 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42722 return size;
42723 }
42724
42725 @@ -1963,7 +2446,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42726
42727 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42728
42729 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42730 + offset += elf_core_vma_data_size(gate_vma, cprm);
42731 offset += elf_core_extra_data_size();
42732 e_shoff = offset;
42733
42734 @@ -1977,10 +2460,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42735 offset = dataoff;
42736
42737 size += sizeof(*elf);
42738 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42739 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42740 goto end_coredump;
42741
42742 size += sizeof(*phdr4note);
42743 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42744 if (size > cprm->limit
42745 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42746 goto end_coredump;
42747 @@ -1994,7 +2479,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42748 phdr.p_offset = offset;
42749 phdr.p_vaddr = vma->vm_start;
42750 phdr.p_paddr = 0;
42751 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42752 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42753 phdr.p_memsz = vma->vm_end - vma->vm_start;
42754 offset += phdr.p_filesz;
42755 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42756 @@ -2005,6 +2490,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42757 phdr.p_align = ELF_EXEC_PAGESIZE;
42758
42759 size += sizeof(phdr);
42760 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42761 if (size > cprm->limit
42762 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42763 goto end_coredump;
42764 @@ -2029,7 +2515,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42765 unsigned long addr;
42766 unsigned long end;
42767
42768 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42769 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42770
42771 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42772 struct page *page;
42773 @@ -2038,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42774 page = get_dump_page(addr);
42775 if (page) {
42776 void *kaddr = kmap(page);
42777 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42778 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42779 !dump_write(cprm->file, kaddr,
42780 PAGE_SIZE);
42781 @@ -2055,6 +2542,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42782
42783 if (e_phnum == PN_XNUM) {
42784 size += sizeof(*shdr4extnum);
42785 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42786 if (size > cprm->limit
42787 || !dump_write(cprm->file, shdr4extnum,
42788 sizeof(*shdr4extnum)))
42789 @@ -2075,6 +2563,97 @@ out:
42790
42791 #endif /* CONFIG_ELF_CORE */
42792
42793 +#ifdef CONFIG_PAX_MPROTECT
42794 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42795 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42796 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42797 + *
42798 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42799 + * basis because we want to allow the common case and not the special ones.
42800 + */
42801 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42802 +{
42803 + struct elfhdr elf_h;
42804 + struct elf_phdr elf_p;
42805 + unsigned long i;
42806 + unsigned long oldflags;
42807 + bool is_textrel_rw, is_textrel_rx, is_relro;
42808 +
42809 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42810 + return;
42811 +
42812 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42813 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42814 +
42815 +#ifdef CONFIG_PAX_ELFRELOCS
42816 + /* possible TEXTREL */
42817 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42818 + 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);
42819 +#else
42820 + is_textrel_rw = false;
42821 + is_textrel_rx = false;
42822 +#endif
42823 +
42824 + /* possible RELRO */
42825 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42826 +
42827 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42828 + return;
42829 +
42830 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42831 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42832 +
42833 +#ifdef CONFIG_PAX_ETEXECRELOCS
42834 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42835 +#else
42836 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42837 +#endif
42838 +
42839 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42840 + !elf_check_arch(&elf_h) ||
42841 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42842 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42843 + return;
42844 +
42845 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42846 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42847 + return;
42848 + switch (elf_p.p_type) {
42849 + case PT_DYNAMIC:
42850 + if (!is_textrel_rw && !is_textrel_rx)
42851 + continue;
42852 + i = 0UL;
42853 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42854 + elf_dyn dyn;
42855 +
42856 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42857 + return;
42858 + if (dyn.d_tag == DT_NULL)
42859 + return;
42860 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42861 + gr_log_textrel(vma);
42862 + if (is_textrel_rw)
42863 + vma->vm_flags |= VM_MAYWRITE;
42864 + else
42865 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42866 + vma->vm_flags &= ~VM_MAYWRITE;
42867 + return;
42868 + }
42869 + i++;
42870 + }
42871 + return;
42872 +
42873 + case PT_GNU_RELRO:
42874 + if (!is_relro)
42875 + continue;
42876 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42877 + vma->vm_flags &= ~VM_MAYWRITE;
42878 + return;
42879 + }
42880 + }
42881 +}
42882 +#endif
42883 +
42884 static int __init init_elf_binfmt(void)
42885 {
42886 return register_binfmt(&elf_format);
42887 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42888 index 1bffbe0..c8c283e 100644
42889 --- a/fs/binfmt_flat.c
42890 +++ b/fs/binfmt_flat.c
42891 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42892 realdatastart = (unsigned long) -ENOMEM;
42893 printk("Unable to allocate RAM for process data, errno %d\n",
42894 (int)-realdatastart);
42895 + down_write(&current->mm->mmap_sem);
42896 do_munmap(current->mm, textpos, text_len);
42897 + up_write(&current->mm->mmap_sem);
42898 ret = realdatastart;
42899 goto err;
42900 }
42901 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42902 }
42903 if (IS_ERR_VALUE(result)) {
42904 printk("Unable to read data+bss, errno %d\n", (int)-result);
42905 + down_write(&current->mm->mmap_sem);
42906 do_munmap(current->mm, textpos, text_len);
42907 do_munmap(current->mm, realdatastart, len);
42908 + up_write(&current->mm->mmap_sem);
42909 ret = result;
42910 goto err;
42911 }
42912 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42913 }
42914 if (IS_ERR_VALUE(result)) {
42915 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42916 + down_write(&current->mm->mmap_sem);
42917 do_munmap(current->mm, textpos, text_len + data_len + extra +
42918 MAX_SHARED_LIBS * sizeof(unsigned long));
42919 + up_write(&current->mm->mmap_sem);
42920 ret = result;
42921 goto err;
42922 }
42923 diff --git a/fs/bio.c b/fs/bio.c
42924 index b980ecd..74800bf 100644
42925 --- a/fs/bio.c
42926 +++ b/fs/bio.c
42927 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42928 /*
42929 * Overflow, abort
42930 */
42931 - if (end < start)
42932 + if (end < start || end - start > INT_MAX - nr_pages)
42933 return ERR_PTR(-EINVAL);
42934
42935 nr_pages += end - start;
42936 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42937 const int read = bio_data_dir(bio) == READ;
42938 struct bio_map_data *bmd = bio->bi_private;
42939 int i;
42940 - char *p = bmd->sgvecs[0].iov_base;
42941 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42942
42943 __bio_for_each_segment(bvec, bio, i, 0) {
42944 char *addr = page_address(bvec->bv_page);
42945 diff --git a/fs/block_dev.c b/fs/block_dev.c
42946 index 5e9f198..6bf9b1c 100644
42947 --- a/fs/block_dev.c
42948 +++ b/fs/block_dev.c
42949 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42950 else if (bdev->bd_contains == bdev)
42951 return true; /* is a whole device which isn't held */
42952
42953 - else if (whole->bd_holder == bd_may_claim)
42954 + else if (whole->bd_holder == (void *)bd_may_claim)
42955 return true; /* is a partition of a device that is being partitioned */
42956 else if (whole->bd_holder != NULL)
42957 return false; /* is a partition of a held device */
42958 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42959 index d986824..af1befd 100644
42960 --- a/fs/btrfs/check-integrity.c
42961 +++ b/fs/btrfs/check-integrity.c
42962 @@ -157,7 +157,7 @@ struct btrfsic_block {
42963 union {
42964 bio_end_io_t *bio;
42965 bh_end_io_t *bh;
42966 - } orig_bio_bh_end_io;
42967 + } __no_const orig_bio_bh_end_io;
42968 int submit_bio_bh_rw;
42969 u64 flush_gen; /* only valid if !never_written */
42970 };
42971 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42972 index 0639a55..7d9e07f 100644
42973 --- a/fs/btrfs/ctree.c
42974 +++ b/fs/btrfs/ctree.c
42975 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42976 free_extent_buffer(buf);
42977 add_root_to_dirty_list(root);
42978 } else {
42979 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42980 - parent_start = parent->start;
42981 - else
42982 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42983 + if (parent)
42984 + parent_start = parent->start;
42985 + else
42986 + parent_start = 0;
42987 + } else
42988 parent_start = 0;
42989
42990 WARN_ON(trans->transid != btrfs_header_generation(parent));
42991 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42992 index 892b347..b3db246 100644
42993 --- a/fs/btrfs/inode.c
42994 +++ b/fs/btrfs/inode.c
42995 @@ -6930,7 +6930,7 @@ fail:
42996 return -ENOMEM;
42997 }
42998
42999 -static int btrfs_getattr(struct vfsmount *mnt,
43000 +int btrfs_getattr(struct vfsmount *mnt,
43001 struct dentry *dentry, struct kstat *stat)
43002 {
43003 struct inode *inode = dentry->d_inode;
43004 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43005 return 0;
43006 }
43007
43008 +EXPORT_SYMBOL(btrfs_getattr);
43009 +
43010 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43011 +{
43012 + return BTRFS_I(inode)->root->anon_dev;
43013 +}
43014 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43015 +
43016 /*
43017 * If a file is moved, it will inherit the cow and compression flags of the new
43018 * directory.
43019 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43020 index d8b5471..e5463d7 100644
43021 --- a/fs/btrfs/ioctl.c
43022 +++ b/fs/btrfs/ioctl.c
43023 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43024 for (i = 0; i < num_types; i++) {
43025 struct btrfs_space_info *tmp;
43026
43027 + /* Don't copy in more than we allocated */
43028 if (!slot_count)
43029 break;
43030
43031 + slot_count--;
43032 +
43033 info = NULL;
43034 rcu_read_lock();
43035 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43036 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43037 memcpy(dest, &space, sizeof(space));
43038 dest++;
43039 space_args.total_spaces++;
43040 - slot_count--;
43041 }
43042 - if (!slot_count)
43043 - break;
43044 }
43045 up_read(&info->groups_sem);
43046 }
43047
43048 - user_dest = (struct btrfs_ioctl_space_info *)
43049 + user_dest = (struct btrfs_ioctl_space_info __user *)
43050 (arg + sizeof(struct btrfs_ioctl_space_args));
43051
43052 if (copy_to_user(user_dest, dest_orig, alloc_size))
43053 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43054 index 8c1aae2..1e46446 100644
43055 --- a/fs/btrfs/relocation.c
43056 +++ b/fs/btrfs/relocation.c
43057 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43058 }
43059 spin_unlock(&rc->reloc_root_tree.lock);
43060
43061 - BUG_ON((struct btrfs_root *)node->data != root);
43062 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43063
43064 if (!del) {
43065 spin_lock(&rc->reloc_root_tree.lock);
43066 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43067 index 622f469..e8d2d55 100644
43068 --- a/fs/cachefiles/bind.c
43069 +++ b/fs/cachefiles/bind.c
43070 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43071 args);
43072
43073 /* start by checking things over */
43074 - ASSERT(cache->fstop_percent >= 0 &&
43075 - cache->fstop_percent < cache->fcull_percent &&
43076 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43077 cache->fcull_percent < cache->frun_percent &&
43078 cache->frun_percent < 100);
43079
43080 - ASSERT(cache->bstop_percent >= 0 &&
43081 - cache->bstop_percent < cache->bcull_percent &&
43082 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43083 cache->bcull_percent < cache->brun_percent &&
43084 cache->brun_percent < 100);
43085
43086 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43087 index 0a1467b..6a53245 100644
43088 --- a/fs/cachefiles/daemon.c
43089 +++ b/fs/cachefiles/daemon.c
43090 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43091 if (n > buflen)
43092 return -EMSGSIZE;
43093
43094 - if (copy_to_user(_buffer, buffer, n) != 0)
43095 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43096 return -EFAULT;
43097
43098 return n;
43099 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43100 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43101 return -EIO;
43102
43103 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43104 + if (datalen > PAGE_SIZE - 1)
43105 return -EOPNOTSUPP;
43106
43107 /* drag the command string into the kernel so we can parse it */
43108 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43109 if (args[0] != '%' || args[1] != '\0')
43110 return -EINVAL;
43111
43112 - if (fstop < 0 || fstop >= cache->fcull_percent)
43113 + if (fstop >= cache->fcull_percent)
43114 return cachefiles_daemon_range_error(cache, args);
43115
43116 cache->fstop_percent = fstop;
43117 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43118 if (args[0] != '%' || args[1] != '\0')
43119 return -EINVAL;
43120
43121 - if (bstop < 0 || bstop >= cache->bcull_percent)
43122 + if (bstop >= cache->bcull_percent)
43123 return cachefiles_daemon_range_error(cache, args);
43124
43125 cache->bstop_percent = bstop;
43126 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43127 index bd6bc1b..b627b53 100644
43128 --- a/fs/cachefiles/internal.h
43129 +++ b/fs/cachefiles/internal.h
43130 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43131 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43132 struct rb_root active_nodes; /* active nodes (can't be culled) */
43133 rwlock_t active_lock; /* lock for active_nodes */
43134 - atomic_t gravecounter; /* graveyard uniquifier */
43135 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43136 unsigned frun_percent; /* when to stop culling (% files) */
43137 unsigned fcull_percent; /* when to start culling (% files) */
43138 unsigned fstop_percent; /* when to stop allocating (% files) */
43139 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43140 * proc.c
43141 */
43142 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43143 -extern atomic_t cachefiles_lookup_histogram[HZ];
43144 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43145 -extern atomic_t cachefiles_create_histogram[HZ];
43146 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43147 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43148 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43149
43150 extern int __init cachefiles_proc_init(void);
43151 extern void cachefiles_proc_cleanup(void);
43152 static inline
43153 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43154 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43155 {
43156 unsigned long jif = jiffies - start_jif;
43157 if (jif >= HZ)
43158 jif = HZ - 1;
43159 - atomic_inc(&histogram[jif]);
43160 + atomic_inc_unchecked(&histogram[jif]);
43161 }
43162
43163 #else
43164 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43165 index a0358c2..d6137f2 100644
43166 --- a/fs/cachefiles/namei.c
43167 +++ b/fs/cachefiles/namei.c
43168 @@ -318,7 +318,7 @@ try_again:
43169 /* first step is to make up a grave dentry in the graveyard */
43170 sprintf(nbuffer, "%08x%08x",
43171 (uint32_t) get_seconds(),
43172 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43173 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43174
43175 /* do the multiway lock magic */
43176 trap = lock_rename(cache->graveyard, dir);
43177 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43178 index eccd339..4c1d995 100644
43179 --- a/fs/cachefiles/proc.c
43180 +++ b/fs/cachefiles/proc.c
43181 @@ -14,9 +14,9 @@
43182 #include <linux/seq_file.h>
43183 #include "internal.h"
43184
43185 -atomic_t cachefiles_lookup_histogram[HZ];
43186 -atomic_t cachefiles_mkdir_histogram[HZ];
43187 -atomic_t cachefiles_create_histogram[HZ];
43188 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43189 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43190 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43191
43192 /*
43193 * display the latency histogram
43194 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43195 return 0;
43196 default:
43197 index = (unsigned long) v - 3;
43198 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43199 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43200 - z = atomic_read(&cachefiles_create_histogram[index]);
43201 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43202 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43203 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43204 if (x == 0 && y == 0 && z == 0)
43205 return 0;
43206
43207 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43208 index 0e3c092..818480e 100644
43209 --- a/fs/cachefiles/rdwr.c
43210 +++ b/fs/cachefiles/rdwr.c
43211 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43212 old_fs = get_fs();
43213 set_fs(KERNEL_DS);
43214 ret = file->f_op->write(
43215 - file, (const void __user *) data, len, &pos);
43216 + file, (const void __force_user *) data, len, &pos);
43217 set_fs(old_fs);
43218 kunmap(page);
43219 if (ret != len)
43220 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43221 index 3e8094b..cb3ff3d 100644
43222 --- a/fs/ceph/dir.c
43223 +++ b/fs/ceph/dir.c
43224 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43225 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43226 struct ceph_mds_client *mdsc = fsc->mdsc;
43227 unsigned frag = fpos_frag(filp->f_pos);
43228 - int off = fpos_off(filp->f_pos);
43229 + unsigned int off = fpos_off(filp->f_pos);
43230 int err;
43231 u32 ftype;
43232 struct ceph_mds_reply_info_parsed *rinfo;
43233 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43234 if (nd &&
43235 (nd->flags & LOOKUP_OPEN) &&
43236 !(nd->intent.open.flags & O_CREAT)) {
43237 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43238 + int mode = nd->intent.open.create_mode & ~current_umask();
43239 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43240 }
43241
43242 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43243 index cfd1ce3..6b13a74 100644
43244 --- a/fs/cifs/asn1.c
43245 +++ b/fs/cifs/asn1.c
43246 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43247
43248 static int
43249 asn1_oid_decode(struct asn1_ctx *ctx,
43250 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43251 +static int
43252 +asn1_oid_decode(struct asn1_ctx *ctx,
43253 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43254 {
43255 unsigned long subid;
43256 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43257 index 24b3dfc..3cd5454 100644
43258 --- a/fs/cifs/cifs_debug.c
43259 +++ b/fs/cifs/cifs_debug.c
43260 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43261
43262 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43263 #ifdef CONFIG_CIFS_STATS2
43264 - atomic_set(&totBufAllocCount, 0);
43265 - atomic_set(&totSmBufAllocCount, 0);
43266 + atomic_set_unchecked(&totBufAllocCount, 0);
43267 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43268 #endif /* CONFIG_CIFS_STATS2 */
43269 spin_lock(&cifs_tcp_ses_lock);
43270 list_for_each(tmp1, &cifs_tcp_ses_list) {
43271 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43272 tcon = list_entry(tmp3,
43273 struct cifs_tcon,
43274 tcon_list);
43275 - atomic_set(&tcon->num_smbs_sent, 0);
43276 - atomic_set(&tcon->num_writes, 0);
43277 - atomic_set(&tcon->num_reads, 0);
43278 - atomic_set(&tcon->num_oplock_brks, 0);
43279 - atomic_set(&tcon->num_opens, 0);
43280 - atomic_set(&tcon->num_posixopens, 0);
43281 - atomic_set(&tcon->num_posixmkdirs, 0);
43282 - atomic_set(&tcon->num_closes, 0);
43283 - atomic_set(&tcon->num_deletes, 0);
43284 - atomic_set(&tcon->num_mkdirs, 0);
43285 - atomic_set(&tcon->num_rmdirs, 0);
43286 - atomic_set(&tcon->num_renames, 0);
43287 - atomic_set(&tcon->num_t2renames, 0);
43288 - atomic_set(&tcon->num_ffirst, 0);
43289 - atomic_set(&tcon->num_fnext, 0);
43290 - atomic_set(&tcon->num_fclose, 0);
43291 - atomic_set(&tcon->num_hardlinks, 0);
43292 - atomic_set(&tcon->num_symlinks, 0);
43293 - atomic_set(&tcon->num_locks, 0);
43294 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43295 + atomic_set_unchecked(&tcon->num_writes, 0);
43296 + atomic_set_unchecked(&tcon->num_reads, 0);
43297 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43298 + atomic_set_unchecked(&tcon->num_opens, 0);
43299 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43300 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43301 + atomic_set_unchecked(&tcon->num_closes, 0);
43302 + atomic_set_unchecked(&tcon->num_deletes, 0);
43303 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43304 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43305 + atomic_set_unchecked(&tcon->num_renames, 0);
43306 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43307 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43308 + atomic_set_unchecked(&tcon->num_fnext, 0);
43309 + atomic_set_unchecked(&tcon->num_fclose, 0);
43310 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43311 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43312 + atomic_set_unchecked(&tcon->num_locks, 0);
43313 }
43314 }
43315 }
43316 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43317 smBufAllocCount.counter, cifs_min_small);
43318 #ifdef CONFIG_CIFS_STATS2
43319 seq_printf(m, "Total Large %d Small %d Allocations\n",
43320 - atomic_read(&totBufAllocCount),
43321 - atomic_read(&totSmBufAllocCount));
43322 + atomic_read_unchecked(&totBufAllocCount),
43323 + atomic_read_unchecked(&totSmBufAllocCount));
43324 #endif /* CONFIG_CIFS_STATS2 */
43325
43326 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43327 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43328 if (tcon->need_reconnect)
43329 seq_puts(m, "\tDISCONNECTED ");
43330 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43331 - atomic_read(&tcon->num_smbs_sent),
43332 - atomic_read(&tcon->num_oplock_brks));
43333 + atomic_read_unchecked(&tcon->num_smbs_sent),
43334 + atomic_read_unchecked(&tcon->num_oplock_brks));
43335 seq_printf(m, "\nReads: %d Bytes: %lld",
43336 - atomic_read(&tcon->num_reads),
43337 + atomic_read_unchecked(&tcon->num_reads),
43338 (long long)(tcon->bytes_read));
43339 seq_printf(m, "\nWrites: %d Bytes: %lld",
43340 - atomic_read(&tcon->num_writes),
43341 + atomic_read_unchecked(&tcon->num_writes),
43342 (long long)(tcon->bytes_written));
43343 seq_printf(m, "\nFlushes: %d",
43344 - atomic_read(&tcon->num_flushes));
43345 + atomic_read_unchecked(&tcon->num_flushes));
43346 seq_printf(m, "\nLocks: %d HardLinks: %d "
43347 "Symlinks: %d",
43348 - atomic_read(&tcon->num_locks),
43349 - atomic_read(&tcon->num_hardlinks),
43350 - atomic_read(&tcon->num_symlinks));
43351 + atomic_read_unchecked(&tcon->num_locks),
43352 + atomic_read_unchecked(&tcon->num_hardlinks),
43353 + atomic_read_unchecked(&tcon->num_symlinks));
43354 seq_printf(m, "\nOpens: %d Closes: %d "
43355 "Deletes: %d",
43356 - atomic_read(&tcon->num_opens),
43357 - atomic_read(&tcon->num_closes),
43358 - atomic_read(&tcon->num_deletes));
43359 + atomic_read_unchecked(&tcon->num_opens),
43360 + atomic_read_unchecked(&tcon->num_closes),
43361 + atomic_read_unchecked(&tcon->num_deletes));
43362 seq_printf(m, "\nPosix Opens: %d "
43363 "Posix Mkdirs: %d",
43364 - atomic_read(&tcon->num_posixopens),
43365 - atomic_read(&tcon->num_posixmkdirs));
43366 + atomic_read_unchecked(&tcon->num_posixopens),
43367 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43368 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43369 - atomic_read(&tcon->num_mkdirs),
43370 - atomic_read(&tcon->num_rmdirs));
43371 + atomic_read_unchecked(&tcon->num_mkdirs),
43372 + atomic_read_unchecked(&tcon->num_rmdirs));
43373 seq_printf(m, "\nRenames: %d T2 Renames %d",
43374 - atomic_read(&tcon->num_renames),
43375 - atomic_read(&tcon->num_t2renames));
43376 + atomic_read_unchecked(&tcon->num_renames),
43377 + atomic_read_unchecked(&tcon->num_t2renames));
43378 seq_printf(m, "\nFindFirst: %d FNext %d "
43379 "FClose %d",
43380 - atomic_read(&tcon->num_ffirst),
43381 - atomic_read(&tcon->num_fnext),
43382 - atomic_read(&tcon->num_fclose));
43383 + atomic_read_unchecked(&tcon->num_ffirst),
43384 + atomic_read_unchecked(&tcon->num_fnext),
43385 + atomic_read_unchecked(&tcon->num_fclose));
43386 }
43387 }
43388 }
43389 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43390 index 6ee1cb4..8443157 100644
43391 --- a/fs/cifs/cifsfs.c
43392 +++ b/fs/cifs/cifsfs.c
43393 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43394 cifs_req_cachep = kmem_cache_create("cifs_request",
43395 CIFSMaxBufSize +
43396 MAX_CIFS_HDR_SIZE, 0,
43397 - SLAB_HWCACHE_ALIGN, NULL);
43398 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43399 if (cifs_req_cachep == NULL)
43400 return -ENOMEM;
43401
43402 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43403 efficient to alloc 1 per page off the slab compared to 17K (5page)
43404 alloc of large cifs buffers even when page debugging is on */
43405 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43406 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43407 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43408 NULL);
43409 if (cifs_sm_req_cachep == NULL) {
43410 mempool_destroy(cifs_req_poolp);
43411 @@ -1101,8 +1101,8 @@ init_cifs(void)
43412 atomic_set(&bufAllocCount, 0);
43413 atomic_set(&smBufAllocCount, 0);
43414 #ifdef CONFIG_CIFS_STATS2
43415 - atomic_set(&totBufAllocCount, 0);
43416 - atomic_set(&totSmBufAllocCount, 0);
43417 + atomic_set_unchecked(&totBufAllocCount, 0);
43418 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43419 #endif /* CONFIG_CIFS_STATS2 */
43420
43421 atomic_set(&midCount, 0);
43422 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43423 index d47d20a..77e8b33 100644
43424 --- a/fs/cifs/cifsglob.h
43425 +++ b/fs/cifs/cifsglob.h
43426 @@ -388,28 +388,28 @@ struct cifs_tcon {
43427 __u16 Flags; /* optional support bits */
43428 enum statusEnum tidStatus;
43429 #ifdef CONFIG_CIFS_STATS
43430 - atomic_t num_smbs_sent;
43431 - atomic_t num_writes;
43432 - atomic_t num_reads;
43433 - atomic_t num_flushes;
43434 - atomic_t num_oplock_brks;
43435 - atomic_t num_opens;
43436 - atomic_t num_closes;
43437 - atomic_t num_deletes;
43438 - atomic_t num_mkdirs;
43439 - atomic_t num_posixopens;
43440 - atomic_t num_posixmkdirs;
43441 - atomic_t num_rmdirs;
43442 - atomic_t num_renames;
43443 - atomic_t num_t2renames;
43444 - atomic_t num_ffirst;
43445 - atomic_t num_fnext;
43446 - atomic_t num_fclose;
43447 - atomic_t num_hardlinks;
43448 - atomic_t num_symlinks;
43449 - atomic_t num_locks;
43450 - atomic_t num_acl_get;
43451 - atomic_t num_acl_set;
43452 + atomic_unchecked_t num_smbs_sent;
43453 + atomic_unchecked_t num_writes;
43454 + atomic_unchecked_t num_reads;
43455 + atomic_unchecked_t num_flushes;
43456 + atomic_unchecked_t num_oplock_brks;
43457 + atomic_unchecked_t num_opens;
43458 + atomic_unchecked_t num_closes;
43459 + atomic_unchecked_t num_deletes;
43460 + atomic_unchecked_t num_mkdirs;
43461 + atomic_unchecked_t num_posixopens;
43462 + atomic_unchecked_t num_posixmkdirs;
43463 + atomic_unchecked_t num_rmdirs;
43464 + atomic_unchecked_t num_renames;
43465 + atomic_unchecked_t num_t2renames;
43466 + atomic_unchecked_t num_ffirst;
43467 + atomic_unchecked_t num_fnext;
43468 + atomic_unchecked_t num_fclose;
43469 + atomic_unchecked_t num_hardlinks;
43470 + atomic_unchecked_t num_symlinks;
43471 + atomic_unchecked_t num_locks;
43472 + atomic_unchecked_t num_acl_get;
43473 + atomic_unchecked_t num_acl_set;
43474 #ifdef CONFIG_CIFS_STATS2
43475 unsigned long long time_writes;
43476 unsigned long long time_reads;
43477 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43478 }
43479
43480 #ifdef CONFIG_CIFS_STATS
43481 -#define cifs_stats_inc atomic_inc
43482 +#define cifs_stats_inc atomic_inc_unchecked
43483
43484 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43485 unsigned int bytes)
43486 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43487 /* Various Debug counters */
43488 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43489 #ifdef CONFIG_CIFS_STATS2
43490 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43491 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43492 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43493 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43494 #endif
43495 GLOBAL_EXTERN atomic_t smBufAllocCount;
43496 GLOBAL_EXTERN atomic_t midCount;
43497 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43498 index 6b0e064..94e6c3c 100644
43499 --- a/fs/cifs/link.c
43500 +++ b/fs/cifs/link.c
43501 @@ -600,7 +600,7 @@ symlink_exit:
43502
43503 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43504 {
43505 - char *p = nd_get_link(nd);
43506 + const char *p = nd_get_link(nd);
43507 if (!IS_ERR(p))
43508 kfree(p);
43509 }
43510 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43511 index 703ef5c..2a44ed5 100644
43512 --- a/fs/cifs/misc.c
43513 +++ b/fs/cifs/misc.c
43514 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43515 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43516 atomic_inc(&bufAllocCount);
43517 #ifdef CONFIG_CIFS_STATS2
43518 - atomic_inc(&totBufAllocCount);
43519 + atomic_inc_unchecked(&totBufAllocCount);
43520 #endif /* CONFIG_CIFS_STATS2 */
43521 }
43522
43523 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43524 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43525 atomic_inc(&smBufAllocCount);
43526 #ifdef CONFIG_CIFS_STATS2
43527 - atomic_inc(&totSmBufAllocCount);
43528 + atomic_inc_unchecked(&totSmBufAllocCount);
43529 #endif /* CONFIG_CIFS_STATS2 */
43530
43531 }
43532 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43533 index 6901578..d402eb5 100644
43534 --- a/fs/coda/cache.c
43535 +++ b/fs/coda/cache.c
43536 @@ -24,7 +24,7 @@
43537 #include "coda_linux.h"
43538 #include "coda_cache.h"
43539
43540 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43541 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43542
43543 /* replace or extend an acl cache hit */
43544 void coda_cache_enter(struct inode *inode, int mask)
43545 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43546 struct coda_inode_info *cii = ITOC(inode);
43547
43548 spin_lock(&cii->c_lock);
43549 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43550 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43551 if (cii->c_uid != current_fsuid()) {
43552 cii->c_uid = current_fsuid();
43553 cii->c_cached_perm = mask;
43554 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43555 {
43556 struct coda_inode_info *cii = ITOC(inode);
43557 spin_lock(&cii->c_lock);
43558 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43559 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43560 spin_unlock(&cii->c_lock);
43561 }
43562
43563 /* remove all acl caches */
43564 void coda_cache_clear_all(struct super_block *sb)
43565 {
43566 - atomic_inc(&permission_epoch);
43567 + atomic_inc_unchecked(&permission_epoch);
43568 }
43569
43570
43571 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43572 spin_lock(&cii->c_lock);
43573 hit = (mask & cii->c_cached_perm) == mask &&
43574 cii->c_uid == current_fsuid() &&
43575 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43576 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43577 spin_unlock(&cii->c_lock);
43578
43579 return hit;
43580 diff --git a/fs/compat.c b/fs/compat.c
43581 index 07880ba..3fb2862 100644
43582 --- a/fs/compat.c
43583 +++ b/fs/compat.c
43584 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43585
43586 set_fs(KERNEL_DS);
43587 /* The __user pointer cast is valid because of the set_fs() */
43588 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43589 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43590 set_fs(oldfs);
43591 /* truncating is ok because it's a user address */
43592 if (!ret)
43593 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43594 goto out;
43595
43596 ret = -EINVAL;
43597 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43598 + if (nr_segs > UIO_MAXIOV)
43599 goto out;
43600 if (nr_segs > fast_segs) {
43601 ret = -ENOMEM;
43602 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43603
43604 struct compat_readdir_callback {
43605 struct compat_old_linux_dirent __user *dirent;
43606 + struct file * file;
43607 int result;
43608 };
43609
43610 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43611 buf->result = -EOVERFLOW;
43612 return -EOVERFLOW;
43613 }
43614 +
43615 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43616 + return 0;
43617 +
43618 buf->result++;
43619 dirent = buf->dirent;
43620 if (!access_ok(VERIFY_WRITE, dirent,
43621 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43622
43623 buf.result = 0;
43624 buf.dirent = dirent;
43625 + buf.file = file;
43626
43627 error = vfs_readdir(file, compat_fillonedir, &buf);
43628 if (buf.result)
43629 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
43630 struct compat_getdents_callback {
43631 struct compat_linux_dirent __user *current_dir;
43632 struct compat_linux_dirent __user *previous;
43633 + struct file * file;
43634 int count;
43635 int error;
43636 };
43637 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43638 buf->error = -EOVERFLOW;
43639 return -EOVERFLOW;
43640 }
43641 +
43642 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43643 + return 0;
43644 +
43645 dirent = buf->previous;
43646 if (dirent) {
43647 if (__put_user(offset, &dirent->d_off))
43648 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43649 buf.previous = NULL;
43650 buf.count = count;
43651 buf.error = 0;
43652 + buf.file = file;
43653
43654 error = vfs_readdir(file, compat_filldir, &buf);
43655 if (error >= 0)
43656 @@ -990,6 +1002,7 @@ out:
43657 struct compat_getdents_callback64 {
43658 struct linux_dirent64 __user *current_dir;
43659 struct linux_dirent64 __user *previous;
43660 + struct file * file;
43661 int count;
43662 int error;
43663 };
43664 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43665 buf->error = -EINVAL; /* only used if we fail.. */
43666 if (reclen > buf->count)
43667 return -EINVAL;
43668 +
43669 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43670 + return 0;
43671 +
43672 dirent = buf->previous;
43673
43674 if (dirent) {
43675 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43676 buf.previous = NULL;
43677 buf.count = count;
43678 buf.error = 0;
43679 + buf.file = file;
43680
43681 error = vfs_readdir(file, compat_filldir64, &buf);
43682 if (error >= 0)
43683 error = buf.error;
43684 lastdirent = buf.previous;
43685 if (lastdirent) {
43686 - typeof(lastdirent->d_off) d_off = file->f_pos;
43687 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43688 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43689 error = -EFAULT;
43690 else
43691 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43692 index 112e45a..b59845b 100644
43693 --- a/fs/compat_binfmt_elf.c
43694 +++ b/fs/compat_binfmt_elf.c
43695 @@ -30,11 +30,13 @@
43696 #undef elf_phdr
43697 #undef elf_shdr
43698 #undef elf_note
43699 +#undef elf_dyn
43700 #undef elf_addr_t
43701 #define elfhdr elf32_hdr
43702 #define elf_phdr elf32_phdr
43703 #define elf_shdr elf32_shdr
43704 #define elf_note elf32_note
43705 +#define elf_dyn Elf32_Dyn
43706 #define elf_addr_t Elf32_Addr
43707
43708 /*
43709 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43710 index a26bea1..ae23e72 100644
43711 --- a/fs/compat_ioctl.c
43712 +++ b/fs/compat_ioctl.c
43713 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43714
43715 err = get_user(palp, &up->palette);
43716 err |= get_user(length, &up->length);
43717 + if (err)
43718 + return -EFAULT;
43719
43720 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43721 err = put_user(compat_ptr(palp), &up_native->palette);
43722 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43723 return -EFAULT;
43724 if (__get_user(udata, &ss32->iomem_base))
43725 return -EFAULT;
43726 - ss.iomem_base = compat_ptr(udata);
43727 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43728 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43729 __get_user(ss.port_high, &ss32->port_high))
43730 return -EFAULT;
43731 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43732 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43733 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43734 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43735 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43736 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43737 return -EFAULT;
43738
43739 return ioctl_preallocate(file, p);
43740 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43741 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43742 {
43743 unsigned int a, b;
43744 - a = *(unsigned int *)p;
43745 - b = *(unsigned int *)q;
43746 + a = *(const unsigned int *)p;
43747 + b = *(const unsigned int *)q;
43748 if (a > b)
43749 return 1;
43750 if (a < b)
43751 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43752 index 5ddd7eb..c18bf04 100644
43753 --- a/fs/configfs/dir.c
43754 +++ b/fs/configfs/dir.c
43755 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43756 }
43757 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43758 struct configfs_dirent *next;
43759 - const char * name;
43760 + const unsigned char * name;
43761 + char d_name[sizeof(next->s_dentry->d_iname)];
43762 int len;
43763 struct inode *inode = NULL;
43764
43765 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43766 continue;
43767
43768 name = configfs_get_name(next);
43769 - len = strlen(name);
43770 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43771 + len = next->s_dentry->d_name.len;
43772 + memcpy(d_name, name, len);
43773 + name = d_name;
43774 + } else
43775 + len = strlen(name);
43776
43777 /*
43778 * We'll have a dentry and an inode for
43779 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
43780 index 2b6cb23..d76e879 100644
43781 --- a/fs/configfs/file.c
43782 +++ b/fs/configfs/file.c
43783 @@ -135,6 +135,8 @@ out:
43784 */
43785
43786 static int
43787 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
43788 +static int
43789 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
43790 {
43791 int error;
43792 diff --git a/fs/dcache.c b/fs/dcache.c
43793 index 2576d14..0cec38d 100644
43794 --- a/fs/dcache.c
43795 +++ b/fs/dcache.c
43796 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43797 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43798
43799 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43800 - unsigned long hash)
43801 + unsigned int hash)
43802 {
43803 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43804 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43805 + hash += (unsigned long) parent / L1_CACHE_BYTES;
43806 + hash = hash + (hash >> D_HASHBITS);
43807 return dentry_hashtable + (hash & D_HASHMASK);
43808 }
43809
43810 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43811 mempages -= reserve;
43812
43813 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43814 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43815 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43816
43817 dcache_init();
43818 inode_init();
43819 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43820 index 956d5dd..e755e04 100644
43821 --- a/fs/debugfs/inode.c
43822 +++ b/fs/debugfs/inode.c
43823 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43824 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43825 {
43826 return debugfs_create_file(name,
43827 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43828 + S_IFDIR | S_IRWXU,
43829 +#else
43830 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43831 +#endif
43832 parent, NULL, NULL);
43833 }
43834 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43835 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43836 index ab35b11..b30af66 100644
43837 --- a/fs/ecryptfs/inode.c
43838 +++ b/fs/ecryptfs/inode.c
43839 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43840 old_fs = get_fs();
43841 set_fs(get_ds());
43842 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43843 - (char __user *)lower_buf,
43844 + (char __force_user *)lower_buf,
43845 lower_bufsiz);
43846 set_fs(old_fs);
43847 if (rc < 0)
43848 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43849 }
43850 old_fs = get_fs();
43851 set_fs(get_ds());
43852 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43853 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43854 set_fs(old_fs);
43855 if (rc < 0) {
43856 kfree(buf);
43857 @@ -733,7 +733,7 @@ out:
43858 static void
43859 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43860 {
43861 - char *buf = nd_get_link(nd);
43862 + const char *buf = nd_get_link(nd);
43863 if (!IS_ERR(buf)) {
43864 /* Free the char* */
43865 kfree(buf);
43866 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43867 index 3a06f40..f7af544 100644
43868 --- a/fs/ecryptfs/miscdev.c
43869 +++ b/fs/ecryptfs/miscdev.c
43870 @@ -345,7 +345,7 @@ check_list:
43871 goto out_unlock_msg_ctx;
43872 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43873 if (msg_ctx->msg) {
43874 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43875 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43876 goto out_unlock_msg_ctx;
43877 i += packet_length_size;
43878 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43879 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43880 index b2a34a1..162fa69 100644
43881 --- a/fs/ecryptfs/read_write.c
43882 +++ b/fs/ecryptfs/read_write.c
43883 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43884 return -EIO;
43885 fs_save = get_fs();
43886 set_fs(get_ds());
43887 - rc = vfs_write(lower_file, data, size, &offset);
43888 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43889 set_fs(fs_save);
43890 mark_inode_dirty_sync(ecryptfs_inode);
43891 return rc;
43892 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43893 return -EIO;
43894 fs_save = get_fs();
43895 set_fs(get_ds());
43896 - rc = vfs_read(lower_file, data, size, &offset);
43897 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43898 set_fs(fs_save);
43899 return rc;
43900 }
43901 diff --git a/fs/exec.c b/fs/exec.c
43902 index 153dee1..ab4ebe9 100644
43903 --- a/fs/exec.c
43904 +++ b/fs/exec.c
43905 @@ -55,6 +55,13 @@
43906 #include <linux/pipe_fs_i.h>
43907 #include <linux/oom.h>
43908 #include <linux/compat.h>
43909 +#include <linux/random.h>
43910 +#include <linux/seq_file.h>
43911 +
43912 +#ifdef CONFIG_PAX_REFCOUNT
43913 +#include <linux/kallsyms.h>
43914 +#include <linux/kdebug.h>
43915 +#endif
43916
43917 #include <asm/uaccess.h>
43918 #include <asm/mmu_context.h>
43919 @@ -63,6 +70,15 @@
43920 #include <trace/events/task.h>
43921 #include "internal.h"
43922
43923 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43924 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43925 +#endif
43926 +
43927 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43928 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43929 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43930 +#endif
43931 +
43932 int core_uses_pid;
43933 char core_pattern[CORENAME_MAX_SIZE] = "core";
43934 unsigned int core_pipe_limit;
43935 @@ -72,7 +88,7 @@ struct core_name {
43936 char *corename;
43937 int used, size;
43938 };
43939 -static atomic_t call_count = ATOMIC_INIT(1);
43940 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43941
43942 /* The maximal length of core_pattern is also specified in sysctl.c */
43943
43944 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43945 int write)
43946 {
43947 struct page *page;
43948 - int ret;
43949
43950 -#ifdef CONFIG_STACK_GROWSUP
43951 - if (write) {
43952 - ret = expand_downwards(bprm->vma, pos);
43953 - if (ret < 0)
43954 - return NULL;
43955 - }
43956 -#endif
43957 - ret = get_user_pages(current, bprm->mm, pos,
43958 - 1, write, 1, &page, NULL);
43959 - if (ret <= 0)
43960 + if (0 > expand_downwards(bprm->vma, pos))
43961 + return NULL;
43962 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43963 return NULL;
43964
43965 if (write) {
43966 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43967 if (size <= ARG_MAX)
43968 return page;
43969
43970 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43971 + // only allow 512KB for argv+env on suid/sgid binaries
43972 + // to prevent easy ASLR exhaustion
43973 + if (((bprm->cred->euid != current_euid()) ||
43974 + (bprm->cred->egid != current_egid())) &&
43975 + (size > (512 * 1024))) {
43976 + put_page(page);
43977 + return NULL;
43978 + }
43979 +#endif
43980 +
43981 /*
43982 * Limit to 1/4-th the stack size for the argv+env strings.
43983 * This ensures that:
43984 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43985 vma->vm_end = STACK_TOP_MAX;
43986 vma->vm_start = vma->vm_end - PAGE_SIZE;
43987 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43988 +
43989 +#ifdef CONFIG_PAX_SEGMEXEC
43990 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43991 +#endif
43992 +
43993 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43994 INIT_LIST_HEAD(&vma->anon_vma_chain);
43995
43996 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43997 mm->stack_vm = mm->total_vm = 1;
43998 up_write(&mm->mmap_sem);
43999 bprm->p = vma->vm_end - sizeof(void *);
44000 +
44001 +#ifdef CONFIG_PAX_RANDUSTACK
44002 + if (randomize_va_space)
44003 + bprm->p ^= random32() & ~PAGE_MASK;
44004 +#endif
44005 +
44006 return 0;
44007 err:
44008 up_write(&mm->mmap_sem);
44009 @@ -398,19 +428,7 @@ err:
44010 return err;
44011 }
44012
44013 -struct user_arg_ptr {
44014 -#ifdef CONFIG_COMPAT
44015 - bool is_compat;
44016 -#endif
44017 - union {
44018 - const char __user *const __user *native;
44019 -#ifdef CONFIG_COMPAT
44020 - compat_uptr_t __user *compat;
44021 -#endif
44022 - } ptr;
44023 -};
44024 -
44025 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44026 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44027 {
44028 const char __user *native;
44029
44030 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44031 compat_uptr_t compat;
44032
44033 if (get_user(compat, argv.ptr.compat + nr))
44034 - return ERR_PTR(-EFAULT);
44035 + return (const char __force_user *)ERR_PTR(-EFAULT);
44036
44037 return compat_ptr(compat);
44038 }
44039 #endif
44040
44041 if (get_user(native, argv.ptr.native + nr))
44042 - return ERR_PTR(-EFAULT);
44043 + return (const char __force_user *)ERR_PTR(-EFAULT);
44044
44045 return native;
44046 }
44047 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44048 if (!p)
44049 break;
44050
44051 - if (IS_ERR(p))
44052 + if (IS_ERR((const char __force_kernel *)p))
44053 return -EFAULT;
44054
44055 if (i++ >= max)
44056 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44057
44058 ret = -EFAULT;
44059 str = get_user_arg_ptr(argv, argc);
44060 - if (IS_ERR(str))
44061 + if (IS_ERR((const char __force_kernel *)str))
44062 goto out;
44063
44064 len = strnlen_user(str, MAX_ARG_STRLEN);
44065 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44066 int r;
44067 mm_segment_t oldfs = get_fs();
44068 struct user_arg_ptr argv = {
44069 - .ptr.native = (const char __user *const __user *)__argv,
44070 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44071 };
44072
44073 set_fs(KERNEL_DS);
44074 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44075 unsigned long new_end = old_end - shift;
44076 struct mmu_gather tlb;
44077
44078 - BUG_ON(new_start > new_end);
44079 + if (new_start >= new_end || new_start < mmap_min_addr)
44080 + return -ENOMEM;
44081
44082 /*
44083 * ensure there are no vmas between where we want to go
44084 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44085 if (vma != find_vma(mm, new_start))
44086 return -EFAULT;
44087
44088 +#ifdef CONFIG_PAX_SEGMEXEC
44089 + BUG_ON(pax_find_mirror_vma(vma));
44090 +#endif
44091 +
44092 /*
44093 * cover the whole range: [new_start, old_end)
44094 */
44095 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44096 stack_top = arch_align_stack(stack_top);
44097 stack_top = PAGE_ALIGN(stack_top);
44098
44099 - if (unlikely(stack_top < mmap_min_addr) ||
44100 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44101 - return -ENOMEM;
44102 -
44103 stack_shift = vma->vm_end - stack_top;
44104
44105 bprm->p -= stack_shift;
44106 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44107 bprm->exec -= stack_shift;
44108
44109 down_write(&mm->mmap_sem);
44110 +
44111 + /* Move stack pages down in memory. */
44112 + if (stack_shift) {
44113 + ret = shift_arg_pages(vma, stack_shift);
44114 + if (ret)
44115 + goto out_unlock;
44116 + }
44117 +
44118 vm_flags = VM_STACK_FLAGS;
44119
44120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44121 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44122 + vm_flags &= ~VM_EXEC;
44123 +
44124 +#ifdef CONFIG_PAX_MPROTECT
44125 + if (mm->pax_flags & MF_PAX_MPROTECT)
44126 + vm_flags &= ~VM_MAYEXEC;
44127 +#endif
44128 +
44129 + }
44130 +#endif
44131 +
44132 /*
44133 * Adjust stack execute permissions; explicitly enable for
44134 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44135 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44136 goto out_unlock;
44137 BUG_ON(prev != vma);
44138
44139 - /* Move stack pages down in memory. */
44140 - if (stack_shift) {
44141 - ret = shift_arg_pages(vma, stack_shift);
44142 - if (ret)
44143 - goto out_unlock;
44144 - }
44145 -
44146 /* mprotect_fixup is overkill to remove the temporary stack flags */
44147 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44148
44149 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44150 old_fs = get_fs();
44151 set_fs(get_ds());
44152 /* The cast to a user pointer is valid due to the set_fs() */
44153 - result = vfs_read(file, (void __user *)addr, count, &pos);
44154 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44155 set_fs(old_fs);
44156 return result;
44157 }
44158 @@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44159 }
44160 rcu_read_unlock();
44161
44162 - if (p->fs->users > n_fs) {
44163 + if (atomic_read(&p->fs->users) > n_fs) {
44164 bprm->unsafe |= LSM_UNSAFE_SHARE;
44165 } else {
44166 res = -EAGAIN;
44167 @@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44168
44169 EXPORT_SYMBOL(search_binary_handler);
44170
44171 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44172 +static DEFINE_PER_CPU(u64, exec_counter);
44173 +static int __init init_exec_counters(void)
44174 +{
44175 + unsigned int cpu;
44176 +
44177 + for_each_possible_cpu(cpu) {
44178 + per_cpu(exec_counter, cpu) = (u64)cpu;
44179 + }
44180 +
44181 + return 0;
44182 +}
44183 +early_initcall(init_exec_counters);
44184 +static inline void increment_exec_counter(void)
44185 +{
44186 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44187 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44188 +}
44189 +#else
44190 +static inline void increment_exec_counter(void) {}
44191 +#endif
44192 +
44193 /*
44194 * sys_execve() executes a new program.
44195 */
44196 @@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
44197 struct user_arg_ptr envp,
44198 struct pt_regs *regs)
44199 {
44200 +#ifdef CONFIG_GRKERNSEC
44201 + struct file *old_exec_file;
44202 + struct acl_subject_label *old_acl;
44203 + struct rlimit old_rlim[RLIM_NLIMITS];
44204 +#endif
44205 struct linux_binprm *bprm;
44206 struct file *file;
44207 struct files_struct *displaced;
44208 @@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
44209 int retval;
44210 const struct cred *cred = current_cred();
44211
44212 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44213 +
44214 /*
44215 * We move the actual failure in case of RLIMIT_NPROC excess from
44216 * set*uid() to execve() because too many poorly written programs
44217 @@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
44218 if (IS_ERR(file))
44219 goto out_unmark;
44220
44221 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44222 + retval = -EPERM;
44223 + goto out_file;
44224 + }
44225 +
44226 sched_exec();
44227
44228 bprm->file = file;
44229 bprm->filename = filename;
44230 bprm->interp = filename;
44231
44232 + if (gr_process_user_ban()) {
44233 + retval = -EPERM;
44234 + goto out_file;
44235 + }
44236 +
44237 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44238 + retval = -EACCES;
44239 + goto out_file;
44240 + }
44241 +
44242 retval = bprm_mm_init(bprm);
44243 if (retval)
44244 goto out_file;
44245 @@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
44246 if (retval < 0)
44247 goto out;
44248
44249 +#ifdef CONFIG_GRKERNSEC
44250 + old_acl = current->acl;
44251 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44252 + old_exec_file = current->exec_file;
44253 + get_file(file);
44254 + current->exec_file = file;
44255 +#endif
44256 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44257 + /* limit suid stack to 8MB
44258 + we saved the old limits above and will restore them if this exec fails
44259 + */
44260 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44261 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44262 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44263 +#endif
44264 +
44265 + if (!gr_tpe_allow(file)) {
44266 + retval = -EACCES;
44267 + goto out_fail;
44268 + }
44269 +
44270 + if (gr_check_crash_exec(file)) {
44271 + retval = -EACCES;
44272 + goto out_fail;
44273 + }
44274 +
44275 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44276 + bprm->unsafe);
44277 + if (retval < 0)
44278 + goto out_fail;
44279 +
44280 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44281 if (retval < 0)
44282 - goto out;
44283 + goto out_fail;
44284
44285 bprm->exec = bprm->p;
44286 retval = copy_strings(bprm->envc, envp, bprm);
44287 if (retval < 0)
44288 - goto out;
44289 + goto out_fail;
44290
44291 retval = copy_strings(bprm->argc, argv, bprm);
44292 if (retval < 0)
44293 - goto out;
44294 + goto out_fail;
44295 +
44296 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44297 +
44298 + gr_handle_exec_args(bprm, argv);
44299
44300 retval = search_binary_handler(bprm,regs);
44301 if (retval < 0)
44302 - goto out;
44303 + goto out_fail;
44304 +#ifdef CONFIG_GRKERNSEC
44305 + if (old_exec_file)
44306 + fput(old_exec_file);
44307 +#endif
44308
44309 /* execve succeeded */
44310 +
44311 + increment_exec_counter();
44312 current->fs->in_exec = 0;
44313 current->in_execve = 0;
44314 acct_update_integrals(current);
44315 @@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
44316 put_files_struct(displaced);
44317 return retval;
44318
44319 +out_fail:
44320 +#ifdef CONFIG_GRKERNSEC
44321 + current->acl = old_acl;
44322 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44323 + fput(current->exec_file);
44324 + current->exec_file = old_exec_file;
44325 +#endif
44326 +
44327 out:
44328 if (bprm->mm) {
44329 acct_arg_size(bprm, 0);
44330 @@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
44331 {
44332 char *old_corename = cn->corename;
44333
44334 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44335 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44336 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44337
44338 if (!cn->corename) {
44339 @@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
44340 int pid_in_pattern = 0;
44341 int err = 0;
44342
44343 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44344 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44345 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44346 cn->used = 0;
44347
44348 @@ -1817,6 +1942,228 @@ out:
44349 return ispipe;
44350 }
44351
44352 +int pax_check_flags(unsigned long *flags)
44353 +{
44354 + int retval = 0;
44355 +
44356 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44357 + if (*flags & MF_PAX_SEGMEXEC)
44358 + {
44359 + *flags &= ~MF_PAX_SEGMEXEC;
44360 + retval = -EINVAL;
44361 + }
44362 +#endif
44363 +
44364 + if ((*flags & MF_PAX_PAGEEXEC)
44365 +
44366 +#ifdef CONFIG_PAX_PAGEEXEC
44367 + && (*flags & MF_PAX_SEGMEXEC)
44368 +#endif
44369 +
44370 + )
44371 + {
44372 + *flags &= ~MF_PAX_PAGEEXEC;
44373 + retval = -EINVAL;
44374 + }
44375 +
44376 + if ((*flags & MF_PAX_MPROTECT)
44377 +
44378 +#ifdef CONFIG_PAX_MPROTECT
44379 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44380 +#endif
44381 +
44382 + )
44383 + {
44384 + *flags &= ~MF_PAX_MPROTECT;
44385 + retval = -EINVAL;
44386 + }
44387 +
44388 + if ((*flags & MF_PAX_EMUTRAMP)
44389 +
44390 +#ifdef CONFIG_PAX_EMUTRAMP
44391 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44392 +#endif
44393 +
44394 + )
44395 + {
44396 + *flags &= ~MF_PAX_EMUTRAMP;
44397 + retval = -EINVAL;
44398 + }
44399 +
44400 + return retval;
44401 +}
44402 +
44403 +EXPORT_SYMBOL(pax_check_flags);
44404 +
44405 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44406 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44407 +{
44408 + struct task_struct *tsk = current;
44409 + struct mm_struct *mm = current->mm;
44410 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44411 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44412 + char *path_exec = NULL;
44413 + char *path_fault = NULL;
44414 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44415 +
44416 + if (buffer_exec && buffer_fault) {
44417 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44418 +
44419 + down_read(&mm->mmap_sem);
44420 + vma = mm->mmap;
44421 + while (vma && (!vma_exec || !vma_fault)) {
44422 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44423 + vma_exec = vma;
44424 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44425 + vma_fault = vma;
44426 + vma = vma->vm_next;
44427 + }
44428 + if (vma_exec) {
44429 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44430 + if (IS_ERR(path_exec))
44431 + path_exec = "<path too long>";
44432 + else {
44433 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44434 + if (path_exec) {
44435 + *path_exec = 0;
44436 + path_exec = buffer_exec;
44437 + } else
44438 + path_exec = "<path too long>";
44439 + }
44440 + }
44441 + if (vma_fault) {
44442 + start = vma_fault->vm_start;
44443 + end = vma_fault->vm_end;
44444 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44445 + if (vma_fault->vm_file) {
44446 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44447 + if (IS_ERR(path_fault))
44448 + path_fault = "<path too long>";
44449 + else {
44450 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44451 + if (path_fault) {
44452 + *path_fault = 0;
44453 + path_fault = buffer_fault;
44454 + } else
44455 + path_fault = "<path too long>";
44456 + }
44457 + } else
44458 + path_fault = "<anonymous mapping>";
44459 + }
44460 + up_read(&mm->mmap_sem);
44461 + }
44462 + if (tsk->signal->curr_ip)
44463 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44464 + else
44465 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44466 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44467 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44468 + task_uid(tsk), task_euid(tsk), pc, sp);
44469 + free_page((unsigned long)buffer_exec);
44470 + free_page((unsigned long)buffer_fault);
44471 + pax_report_insns(regs, pc, sp);
44472 + do_coredump(SIGKILL, SIGKILL, regs);
44473 +}
44474 +#endif
44475 +
44476 +#ifdef CONFIG_PAX_REFCOUNT
44477 +void pax_report_refcount_overflow(struct pt_regs *regs)
44478 +{
44479 + if (current->signal->curr_ip)
44480 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44481 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44482 + else
44483 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44484 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44485 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44486 + show_regs(regs);
44487 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44488 +}
44489 +#endif
44490 +
44491 +#ifdef CONFIG_PAX_USERCOPY
44492 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44493 +int object_is_on_stack(const void *obj, unsigned long len)
44494 +{
44495 + const void * const stack = task_stack_page(current);
44496 + const void * const stackend = stack + THREAD_SIZE;
44497 +
44498 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44499 + const void *frame = NULL;
44500 + const void *oldframe;
44501 +#endif
44502 +
44503 + if (obj + len < obj)
44504 + return -1;
44505 +
44506 + if (obj + len <= stack || stackend <= obj)
44507 + return 0;
44508 +
44509 + if (obj < stack || stackend < obj + len)
44510 + return -1;
44511 +
44512 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44513 + oldframe = __builtin_frame_address(1);
44514 + if (oldframe)
44515 + frame = __builtin_frame_address(2);
44516 + /*
44517 + low ----------------------------------------------> high
44518 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44519 + ^----------------^
44520 + allow copies only within here
44521 + */
44522 + while (stack <= frame && frame < stackend) {
44523 + /* if obj + len extends past the last frame, this
44524 + check won't pass and the next frame will be 0,
44525 + causing us to bail out and correctly report
44526 + the copy as invalid
44527 + */
44528 + if (obj + len <= frame)
44529 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44530 + oldframe = frame;
44531 + frame = *(const void * const *)frame;
44532 + }
44533 + return -1;
44534 +#else
44535 + return 1;
44536 +#endif
44537 +}
44538 +
44539 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44540 +{
44541 + if (current->signal->curr_ip)
44542 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44543 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44544 + else
44545 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44546 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44547 + dump_stack();
44548 + gr_handle_kernel_exploit();
44549 + do_group_exit(SIGKILL);
44550 +}
44551 +#endif
44552 +
44553 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44554 +void pax_track_stack(void)
44555 +{
44556 + unsigned long sp = (unsigned long)&sp;
44557 + if (sp < current_thread_info()->lowest_stack &&
44558 + sp > (unsigned long)task_stack_page(current))
44559 + current_thread_info()->lowest_stack = sp;
44560 +}
44561 +EXPORT_SYMBOL(pax_track_stack);
44562 +#endif
44563 +
44564 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44565 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44566 +{
44567 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44568 + dump_stack();
44569 + do_group_exit(SIGKILL);
44570 +}
44571 +EXPORT_SYMBOL(report_size_overflow);
44572 +#endif
44573 +
44574 static int zap_process(struct task_struct *start, int exit_code)
44575 {
44576 struct task_struct *t;
44577 @@ -2014,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
44578 pipe = file->f_path.dentry->d_inode->i_pipe;
44579
44580 pipe_lock(pipe);
44581 - pipe->readers++;
44582 - pipe->writers--;
44583 + atomic_inc(&pipe->readers);
44584 + atomic_dec(&pipe->writers);
44585
44586 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44587 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44588 wake_up_interruptible_sync(&pipe->wait);
44589 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44590 pipe_wait(pipe);
44591 }
44592
44593 - pipe->readers--;
44594 - pipe->writers++;
44595 + atomic_dec(&pipe->readers);
44596 + atomic_inc(&pipe->writers);
44597 pipe_unlock(pipe);
44598
44599 }
44600 @@ -2085,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44601 int retval = 0;
44602 int flag = 0;
44603 int ispipe;
44604 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44605 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44606 struct coredump_params cprm = {
44607 .signr = signr,
44608 .regs = regs,
44609 @@ -2100,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44610
44611 audit_core_dumps(signr);
44612
44613 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44614 + gr_handle_brute_attach(current, cprm.mm_flags);
44615 +
44616 binfmt = mm->binfmt;
44617 if (!binfmt || !binfmt->core_dump)
44618 goto fail;
44619 @@ -2167,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44620 }
44621 cprm.limit = RLIM_INFINITY;
44622
44623 - dump_count = atomic_inc_return(&core_dump_count);
44624 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44625 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44626 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44627 task_tgid_vnr(current), current->comm);
44628 @@ -2194,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44629 } else {
44630 struct inode *inode;
44631
44632 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44633 +
44634 if (cprm.limit < binfmt->min_coredump)
44635 goto fail_unlock;
44636
44637 @@ -2237,7 +2589,7 @@ close_fail:
44638 filp_close(cprm.file, NULL);
44639 fail_dropcount:
44640 if (ispipe)
44641 - atomic_dec(&core_dump_count);
44642 + atomic_dec_unchecked(&core_dump_count);
44643 fail_unlock:
44644 kfree(cn.corename);
44645 fail_corename:
44646 @@ -2256,7 +2608,7 @@ fail:
44647 */
44648 int dump_write(struct file *file, const void *addr, int nr)
44649 {
44650 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44651 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44652 }
44653 EXPORT_SYMBOL(dump_write);
44654
44655 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44656 index a8cbe1b..fed04cb 100644
44657 --- a/fs/ext2/balloc.c
44658 +++ b/fs/ext2/balloc.c
44659 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44660
44661 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44662 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44663 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44664 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44665 sbi->s_resuid != current_fsuid() &&
44666 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44667 return 0;
44668 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44669 index a203892..4e64db5 100644
44670 --- a/fs/ext3/balloc.c
44671 +++ b/fs/ext3/balloc.c
44672 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44673
44674 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44675 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44676 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44677 + if (free_blocks < root_blocks + 1 &&
44678 !use_reservation && sbi->s_resuid != current_fsuid() &&
44679 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44680 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44681 + !capable_nolog(CAP_SYS_RESOURCE)) {
44682 return 0;
44683 }
44684 return 1;
44685 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44686 index f9e2cd8..bfdc476 100644
44687 --- a/fs/ext4/balloc.c
44688 +++ b/fs/ext4/balloc.c
44689 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44690 /* Hm, nope. Are (enough) root reserved clusters available? */
44691 if (sbi->s_resuid == current_fsuid() ||
44692 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44693 - capable(CAP_SYS_RESOURCE) ||
44694 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44695 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44696 + capable_nolog(CAP_SYS_RESOURCE)) {
44697
44698 if (free_clusters >= (nclusters + dirty_clusters))
44699 return 1;
44700 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44701 index 3ce6a0c..0311fe5 100644
44702 --- a/fs/ext4/ext4.h
44703 +++ b/fs/ext4/ext4.h
44704 @@ -1220,19 +1220,19 @@ struct ext4_sb_info {
44705 unsigned long s_mb_last_start;
44706
44707 /* stats for buddy allocator */
44708 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44709 - atomic_t s_bal_success; /* we found long enough chunks */
44710 - atomic_t s_bal_allocated; /* in blocks */
44711 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44712 - atomic_t s_bal_goals; /* goal hits */
44713 - atomic_t s_bal_breaks; /* too long searches */
44714 - atomic_t s_bal_2orders; /* 2^order hits */
44715 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44716 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44717 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44718 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44719 + atomic_unchecked_t s_bal_goals; /* goal hits */
44720 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44721 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44722 spinlock_t s_bal_lock;
44723 unsigned long s_mb_buddies_generated;
44724 unsigned long long s_mb_generation_time;
44725 - atomic_t s_mb_lost_chunks;
44726 - atomic_t s_mb_preallocated;
44727 - atomic_t s_mb_discarded;
44728 + atomic_unchecked_t s_mb_lost_chunks;
44729 + atomic_unchecked_t s_mb_preallocated;
44730 + atomic_unchecked_t s_mb_discarded;
44731 atomic_t s_lock_busy;
44732
44733 /* locality groups */
44734 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44735 index cb990b2..4820141 100644
44736 --- a/fs/ext4/mballoc.c
44737 +++ b/fs/ext4/mballoc.c
44738 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44739 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44740
44741 if (EXT4_SB(sb)->s_mb_stats)
44742 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44743 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44744
44745 break;
44746 }
44747 @@ -2088,7 +2088,7 @@ repeat:
44748 ac->ac_status = AC_STATUS_CONTINUE;
44749 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44750 cr = 3;
44751 - atomic_inc(&sbi->s_mb_lost_chunks);
44752 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44753 goto repeat;
44754 }
44755 }
44756 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44757 if (sbi->s_mb_stats) {
44758 ext4_msg(sb, KERN_INFO,
44759 "mballoc: %u blocks %u reqs (%u success)",
44760 - atomic_read(&sbi->s_bal_allocated),
44761 - atomic_read(&sbi->s_bal_reqs),
44762 - atomic_read(&sbi->s_bal_success));
44763 + atomic_read_unchecked(&sbi->s_bal_allocated),
44764 + atomic_read_unchecked(&sbi->s_bal_reqs),
44765 + atomic_read_unchecked(&sbi->s_bal_success));
44766 ext4_msg(sb, KERN_INFO,
44767 "mballoc: %u extents scanned, %u goal hits, "
44768 "%u 2^N hits, %u breaks, %u lost",
44769 - atomic_read(&sbi->s_bal_ex_scanned),
44770 - atomic_read(&sbi->s_bal_goals),
44771 - atomic_read(&sbi->s_bal_2orders),
44772 - atomic_read(&sbi->s_bal_breaks),
44773 - atomic_read(&sbi->s_mb_lost_chunks));
44774 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44775 + atomic_read_unchecked(&sbi->s_bal_goals),
44776 + atomic_read_unchecked(&sbi->s_bal_2orders),
44777 + atomic_read_unchecked(&sbi->s_bal_breaks),
44778 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44779 ext4_msg(sb, KERN_INFO,
44780 "mballoc: %lu generated and it took %Lu",
44781 sbi->s_mb_buddies_generated,
44782 sbi->s_mb_generation_time);
44783 ext4_msg(sb, KERN_INFO,
44784 "mballoc: %u preallocated, %u discarded",
44785 - atomic_read(&sbi->s_mb_preallocated),
44786 - atomic_read(&sbi->s_mb_discarded));
44787 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44788 + atomic_read_unchecked(&sbi->s_mb_discarded));
44789 }
44790
44791 free_percpu(sbi->s_locality_groups);
44792 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44793 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44794
44795 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44796 - atomic_inc(&sbi->s_bal_reqs);
44797 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44798 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44799 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44800 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44801 - atomic_inc(&sbi->s_bal_success);
44802 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44803 + atomic_inc_unchecked(&sbi->s_bal_success);
44804 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44805 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44806 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44807 - atomic_inc(&sbi->s_bal_goals);
44808 + atomic_inc_unchecked(&sbi->s_bal_goals);
44809 if (ac->ac_found > sbi->s_mb_max_to_scan)
44810 - atomic_inc(&sbi->s_bal_breaks);
44811 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44812 }
44813
44814 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44815 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44816 trace_ext4_mb_new_inode_pa(ac, pa);
44817
44818 ext4_mb_use_inode_pa(ac, pa);
44819 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44820 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44821
44822 ei = EXT4_I(ac->ac_inode);
44823 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44824 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44825 trace_ext4_mb_new_group_pa(ac, pa);
44826
44827 ext4_mb_use_group_pa(ac, pa);
44828 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44829 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44830
44831 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44832 lg = ac->ac_lg;
44833 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44834 * from the bitmap and continue.
44835 */
44836 }
44837 - atomic_add(free, &sbi->s_mb_discarded);
44838 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44839
44840 return err;
44841 }
44842 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44843 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44844 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44845 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44846 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44847 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44848 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44849
44850 return 0;
44851 diff --git a/fs/fcntl.c b/fs/fcntl.c
44852 index 22764c7..86372c9 100644
44853 --- a/fs/fcntl.c
44854 +++ b/fs/fcntl.c
44855 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44856 if (err)
44857 return err;
44858
44859 + if (gr_handle_chroot_fowner(pid, type))
44860 + return -ENOENT;
44861 + if (gr_check_protected_task_fowner(pid, type))
44862 + return -EACCES;
44863 +
44864 f_modown(filp, pid, type, force);
44865 return 0;
44866 }
44867 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44868
44869 static int f_setown_ex(struct file *filp, unsigned long arg)
44870 {
44871 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44872 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44873 struct f_owner_ex owner;
44874 struct pid *pid;
44875 int type;
44876 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44877
44878 static int f_getown_ex(struct file *filp, unsigned long arg)
44879 {
44880 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44881 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44882 struct f_owner_ex owner;
44883 int ret = 0;
44884
44885 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44886 switch (cmd) {
44887 case F_DUPFD:
44888 case F_DUPFD_CLOEXEC:
44889 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44890 if (arg >= rlimit(RLIMIT_NOFILE))
44891 break;
44892 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44893 diff --git a/fs/fifo.c b/fs/fifo.c
44894 index b1a524d..4ee270e 100644
44895 --- a/fs/fifo.c
44896 +++ b/fs/fifo.c
44897 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44898 */
44899 filp->f_op = &read_pipefifo_fops;
44900 pipe->r_counter++;
44901 - if (pipe->readers++ == 0)
44902 + if (atomic_inc_return(&pipe->readers) == 1)
44903 wake_up_partner(inode);
44904
44905 - if (!pipe->writers) {
44906 + if (!atomic_read(&pipe->writers)) {
44907 if ((filp->f_flags & O_NONBLOCK)) {
44908 /* suppress POLLHUP until we have
44909 * seen a writer */
44910 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44911 * errno=ENXIO when there is no process reading the FIFO.
44912 */
44913 ret = -ENXIO;
44914 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44915 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44916 goto err;
44917
44918 filp->f_op = &write_pipefifo_fops;
44919 pipe->w_counter++;
44920 - if (!pipe->writers++)
44921 + if (atomic_inc_return(&pipe->writers) == 1)
44922 wake_up_partner(inode);
44923
44924 - if (!pipe->readers) {
44925 + if (!atomic_read(&pipe->readers)) {
44926 wait_for_partner(inode, &pipe->r_counter);
44927 if (signal_pending(current))
44928 goto err_wr;
44929 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44930 */
44931 filp->f_op = &rdwr_pipefifo_fops;
44932
44933 - pipe->readers++;
44934 - pipe->writers++;
44935 + atomic_inc(&pipe->readers);
44936 + atomic_inc(&pipe->writers);
44937 pipe->r_counter++;
44938 pipe->w_counter++;
44939 - if (pipe->readers == 1 || pipe->writers == 1)
44940 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44941 wake_up_partner(inode);
44942 break;
44943
44944 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44945 return 0;
44946
44947 err_rd:
44948 - if (!--pipe->readers)
44949 + if (atomic_dec_and_test(&pipe->readers))
44950 wake_up_interruptible(&pipe->wait);
44951 ret = -ERESTARTSYS;
44952 goto err;
44953
44954 err_wr:
44955 - if (!--pipe->writers)
44956 + if (atomic_dec_and_test(&pipe->writers))
44957 wake_up_interruptible(&pipe->wait);
44958 ret = -ERESTARTSYS;
44959 goto err;
44960
44961 err:
44962 - if (!pipe->readers && !pipe->writers)
44963 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44964 free_pipe_info(inode);
44965
44966 err_nocleanup:
44967 diff --git a/fs/file.c b/fs/file.c
44968 index 4c6992d..104cdea 100644
44969 --- a/fs/file.c
44970 +++ b/fs/file.c
44971 @@ -15,6 +15,7 @@
44972 #include <linux/slab.h>
44973 #include <linux/vmalloc.h>
44974 #include <linux/file.h>
44975 +#include <linux/security.h>
44976 #include <linux/fdtable.h>
44977 #include <linux/bitops.h>
44978 #include <linux/interrupt.h>
44979 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44980 * N.B. For clone tasks sharing a files structure, this test
44981 * will limit the total number of files that can be opened.
44982 */
44983 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44984 if (nr >= rlimit(RLIMIT_NOFILE))
44985 return -EMFILE;
44986
44987 diff --git a/fs/filesystems.c b/fs/filesystems.c
44988 index 96f2428..f5eeb8e 100644
44989 --- a/fs/filesystems.c
44990 +++ b/fs/filesystems.c
44991 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44992 int len = dot ? dot - name : strlen(name);
44993
44994 fs = __get_fs_type(name, len);
44995 +
44996 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44997 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44998 +#else
44999 if (!fs && (request_module("%.*s", len, name) == 0))
45000 +#endif
45001 fs = __get_fs_type(name, len);
45002
45003 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45004 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45005 index 78b519c..a8b4979 100644
45006 --- a/fs/fs_struct.c
45007 +++ b/fs/fs_struct.c
45008 @@ -4,6 +4,7 @@
45009 #include <linux/path.h>
45010 #include <linux/slab.h>
45011 #include <linux/fs_struct.h>
45012 +#include <linux/grsecurity.h>
45013 #include "internal.h"
45014
45015 static inline void path_get_longterm(struct path *path)
45016 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45017 old_root = fs->root;
45018 fs->root = *path;
45019 path_get_longterm(path);
45020 + gr_set_chroot_entries(current, path);
45021 write_seqcount_end(&fs->seq);
45022 spin_unlock(&fs->lock);
45023 if (old_root.dentry)
45024 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45025 && fs->root.mnt == old_root->mnt) {
45026 path_get_longterm(new_root);
45027 fs->root = *new_root;
45028 + gr_set_chroot_entries(p, new_root);
45029 count++;
45030 }
45031 if (fs->pwd.dentry == old_root->dentry
45032 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45033 spin_lock(&fs->lock);
45034 write_seqcount_begin(&fs->seq);
45035 tsk->fs = NULL;
45036 - kill = !--fs->users;
45037 + gr_clear_chroot_entries(tsk);
45038 + kill = !atomic_dec_return(&fs->users);
45039 write_seqcount_end(&fs->seq);
45040 spin_unlock(&fs->lock);
45041 task_unlock(tsk);
45042 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45043 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45044 /* We don't need to lock fs - think why ;-) */
45045 if (fs) {
45046 - fs->users = 1;
45047 + atomic_set(&fs->users, 1);
45048 fs->in_exec = 0;
45049 spin_lock_init(&fs->lock);
45050 seqcount_init(&fs->seq);
45051 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45052 spin_lock(&old->lock);
45053 fs->root = old->root;
45054 path_get_longterm(&fs->root);
45055 + /* instead of calling gr_set_chroot_entries here,
45056 + we call it from every caller of this function
45057 + */
45058 fs->pwd = old->pwd;
45059 path_get_longterm(&fs->pwd);
45060 spin_unlock(&old->lock);
45061 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45062
45063 task_lock(current);
45064 spin_lock(&fs->lock);
45065 - kill = !--fs->users;
45066 + kill = !atomic_dec_return(&fs->users);
45067 current->fs = new_fs;
45068 + gr_set_chroot_entries(current, &new_fs->root);
45069 spin_unlock(&fs->lock);
45070 task_unlock(current);
45071
45072 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45073
45074 int current_umask(void)
45075 {
45076 - return current->fs->umask;
45077 + return current->fs->umask | gr_acl_umask();
45078 }
45079 EXPORT_SYMBOL(current_umask);
45080
45081 /* to be mentioned only in INIT_TASK */
45082 struct fs_struct init_fs = {
45083 - .users = 1,
45084 + .users = ATOMIC_INIT(1),
45085 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45086 .seq = SEQCNT_ZERO,
45087 .umask = 0022,
45088 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45089 task_lock(current);
45090
45091 spin_lock(&init_fs.lock);
45092 - init_fs.users++;
45093 + atomic_inc(&init_fs.users);
45094 spin_unlock(&init_fs.lock);
45095
45096 spin_lock(&fs->lock);
45097 current->fs = &init_fs;
45098 - kill = !--fs->users;
45099 + gr_set_chroot_entries(current, &current->fs->root);
45100 + kill = !atomic_dec_return(&fs->users);
45101 spin_unlock(&fs->lock);
45102
45103 task_unlock(current);
45104 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45105 index 9905350..02eaec4 100644
45106 --- a/fs/fscache/cookie.c
45107 +++ b/fs/fscache/cookie.c
45108 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45109 parent ? (char *) parent->def->name : "<no-parent>",
45110 def->name, netfs_data);
45111
45112 - fscache_stat(&fscache_n_acquires);
45113 + fscache_stat_unchecked(&fscache_n_acquires);
45114
45115 /* if there's no parent cookie, then we don't create one here either */
45116 if (!parent) {
45117 - fscache_stat(&fscache_n_acquires_null);
45118 + fscache_stat_unchecked(&fscache_n_acquires_null);
45119 _leave(" [no parent]");
45120 return NULL;
45121 }
45122 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45123 /* allocate and initialise a cookie */
45124 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45125 if (!cookie) {
45126 - fscache_stat(&fscache_n_acquires_oom);
45127 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45128 _leave(" [ENOMEM]");
45129 return NULL;
45130 }
45131 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45132
45133 switch (cookie->def->type) {
45134 case FSCACHE_COOKIE_TYPE_INDEX:
45135 - fscache_stat(&fscache_n_cookie_index);
45136 + fscache_stat_unchecked(&fscache_n_cookie_index);
45137 break;
45138 case FSCACHE_COOKIE_TYPE_DATAFILE:
45139 - fscache_stat(&fscache_n_cookie_data);
45140 + fscache_stat_unchecked(&fscache_n_cookie_data);
45141 break;
45142 default:
45143 - fscache_stat(&fscache_n_cookie_special);
45144 + fscache_stat_unchecked(&fscache_n_cookie_special);
45145 break;
45146 }
45147
45148 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45149 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45150 atomic_dec(&parent->n_children);
45151 __fscache_cookie_put(cookie);
45152 - fscache_stat(&fscache_n_acquires_nobufs);
45153 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45154 _leave(" = NULL");
45155 return NULL;
45156 }
45157 }
45158
45159 - fscache_stat(&fscache_n_acquires_ok);
45160 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45161 _leave(" = %p", cookie);
45162 return cookie;
45163 }
45164 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45165 cache = fscache_select_cache_for_object(cookie->parent);
45166 if (!cache) {
45167 up_read(&fscache_addremove_sem);
45168 - fscache_stat(&fscache_n_acquires_no_cache);
45169 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45170 _leave(" = -ENOMEDIUM [no cache]");
45171 return -ENOMEDIUM;
45172 }
45173 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45174 object = cache->ops->alloc_object(cache, cookie);
45175 fscache_stat_d(&fscache_n_cop_alloc_object);
45176 if (IS_ERR(object)) {
45177 - fscache_stat(&fscache_n_object_no_alloc);
45178 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45179 ret = PTR_ERR(object);
45180 goto error;
45181 }
45182
45183 - fscache_stat(&fscache_n_object_alloc);
45184 + fscache_stat_unchecked(&fscache_n_object_alloc);
45185
45186 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45187
45188 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45189 struct fscache_object *object;
45190 struct hlist_node *_p;
45191
45192 - fscache_stat(&fscache_n_updates);
45193 + fscache_stat_unchecked(&fscache_n_updates);
45194
45195 if (!cookie) {
45196 - fscache_stat(&fscache_n_updates_null);
45197 + fscache_stat_unchecked(&fscache_n_updates_null);
45198 _leave(" [no cookie]");
45199 return;
45200 }
45201 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45202 struct fscache_object *object;
45203 unsigned long event;
45204
45205 - fscache_stat(&fscache_n_relinquishes);
45206 + fscache_stat_unchecked(&fscache_n_relinquishes);
45207 if (retire)
45208 - fscache_stat(&fscache_n_relinquishes_retire);
45209 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45210
45211 if (!cookie) {
45212 - fscache_stat(&fscache_n_relinquishes_null);
45213 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45214 _leave(" [no cookie]");
45215 return;
45216 }
45217 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45218
45219 /* wait for the cookie to finish being instantiated (or to fail) */
45220 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45221 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45222 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45223 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45224 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45225 }
45226 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45227 index f6aad48..88dcf26 100644
45228 --- a/fs/fscache/internal.h
45229 +++ b/fs/fscache/internal.h
45230 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45231 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45232 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45233
45234 -extern atomic_t fscache_n_op_pend;
45235 -extern atomic_t fscache_n_op_run;
45236 -extern atomic_t fscache_n_op_enqueue;
45237 -extern atomic_t fscache_n_op_deferred_release;
45238 -extern atomic_t fscache_n_op_release;
45239 -extern atomic_t fscache_n_op_gc;
45240 -extern atomic_t fscache_n_op_cancelled;
45241 -extern atomic_t fscache_n_op_rejected;
45242 +extern atomic_unchecked_t fscache_n_op_pend;
45243 +extern atomic_unchecked_t fscache_n_op_run;
45244 +extern atomic_unchecked_t fscache_n_op_enqueue;
45245 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45246 +extern atomic_unchecked_t fscache_n_op_release;
45247 +extern atomic_unchecked_t fscache_n_op_gc;
45248 +extern atomic_unchecked_t fscache_n_op_cancelled;
45249 +extern atomic_unchecked_t fscache_n_op_rejected;
45250
45251 -extern atomic_t fscache_n_attr_changed;
45252 -extern atomic_t fscache_n_attr_changed_ok;
45253 -extern atomic_t fscache_n_attr_changed_nobufs;
45254 -extern atomic_t fscache_n_attr_changed_nomem;
45255 -extern atomic_t fscache_n_attr_changed_calls;
45256 +extern atomic_unchecked_t fscache_n_attr_changed;
45257 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45258 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45259 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45260 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45261
45262 -extern atomic_t fscache_n_allocs;
45263 -extern atomic_t fscache_n_allocs_ok;
45264 -extern atomic_t fscache_n_allocs_wait;
45265 -extern atomic_t fscache_n_allocs_nobufs;
45266 -extern atomic_t fscache_n_allocs_intr;
45267 -extern atomic_t fscache_n_allocs_object_dead;
45268 -extern atomic_t fscache_n_alloc_ops;
45269 -extern atomic_t fscache_n_alloc_op_waits;
45270 +extern atomic_unchecked_t fscache_n_allocs;
45271 +extern atomic_unchecked_t fscache_n_allocs_ok;
45272 +extern atomic_unchecked_t fscache_n_allocs_wait;
45273 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45274 +extern atomic_unchecked_t fscache_n_allocs_intr;
45275 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45276 +extern atomic_unchecked_t fscache_n_alloc_ops;
45277 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45278
45279 -extern atomic_t fscache_n_retrievals;
45280 -extern atomic_t fscache_n_retrievals_ok;
45281 -extern atomic_t fscache_n_retrievals_wait;
45282 -extern atomic_t fscache_n_retrievals_nodata;
45283 -extern atomic_t fscache_n_retrievals_nobufs;
45284 -extern atomic_t fscache_n_retrievals_intr;
45285 -extern atomic_t fscache_n_retrievals_nomem;
45286 -extern atomic_t fscache_n_retrievals_object_dead;
45287 -extern atomic_t fscache_n_retrieval_ops;
45288 -extern atomic_t fscache_n_retrieval_op_waits;
45289 +extern atomic_unchecked_t fscache_n_retrievals;
45290 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45291 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45292 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45293 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45294 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45295 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45296 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45297 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45298 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45299
45300 -extern atomic_t fscache_n_stores;
45301 -extern atomic_t fscache_n_stores_ok;
45302 -extern atomic_t fscache_n_stores_again;
45303 -extern atomic_t fscache_n_stores_nobufs;
45304 -extern atomic_t fscache_n_stores_oom;
45305 -extern atomic_t fscache_n_store_ops;
45306 -extern atomic_t fscache_n_store_calls;
45307 -extern atomic_t fscache_n_store_pages;
45308 -extern atomic_t fscache_n_store_radix_deletes;
45309 -extern atomic_t fscache_n_store_pages_over_limit;
45310 +extern atomic_unchecked_t fscache_n_stores;
45311 +extern atomic_unchecked_t fscache_n_stores_ok;
45312 +extern atomic_unchecked_t fscache_n_stores_again;
45313 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45314 +extern atomic_unchecked_t fscache_n_stores_oom;
45315 +extern atomic_unchecked_t fscache_n_store_ops;
45316 +extern atomic_unchecked_t fscache_n_store_calls;
45317 +extern atomic_unchecked_t fscache_n_store_pages;
45318 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45319 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45320
45321 -extern atomic_t fscache_n_store_vmscan_not_storing;
45322 -extern atomic_t fscache_n_store_vmscan_gone;
45323 -extern atomic_t fscache_n_store_vmscan_busy;
45324 -extern atomic_t fscache_n_store_vmscan_cancelled;
45325 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45326 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45327 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45328 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45329
45330 -extern atomic_t fscache_n_marks;
45331 -extern atomic_t fscache_n_uncaches;
45332 +extern atomic_unchecked_t fscache_n_marks;
45333 +extern atomic_unchecked_t fscache_n_uncaches;
45334
45335 -extern atomic_t fscache_n_acquires;
45336 -extern atomic_t fscache_n_acquires_null;
45337 -extern atomic_t fscache_n_acquires_no_cache;
45338 -extern atomic_t fscache_n_acquires_ok;
45339 -extern atomic_t fscache_n_acquires_nobufs;
45340 -extern atomic_t fscache_n_acquires_oom;
45341 +extern atomic_unchecked_t fscache_n_acquires;
45342 +extern atomic_unchecked_t fscache_n_acquires_null;
45343 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45344 +extern atomic_unchecked_t fscache_n_acquires_ok;
45345 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45346 +extern atomic_unchecked_t fscache_n_acquires_oom;
45347
45348 -extern atomic_t fscache_n_updates;
45349 -extern atomic_t fscache_n_updates_null;
45350 -extern atomic_t fscache_n_updates_run;
45351 +extern atomic_unchecked_t fscache_n_updates;
45352 +extern atomic_unchecked_t fscache_n_updates_null;
45353 +extern atomic_unchecked_t fscache_n_updates_run;
45354
45355 -extern atomic_t fscache_n_relinquishes;
45356 -extern atomic_t fscache_n_relinquishes_null;
45357 -extern atomic_t fscache_n_relinquishes_waitcrt;
45358 -extern atomic_t fscache_n_relinquishes_retire;
45359 +extern atomic_unchecked_t fscache_n_relinquishes;
45360 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45361 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45362 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45363
45364 -extern atomic_t fscache_n_cookie_index;
45365 -extern atomic_t fscache_n_cookie_data;
45366 -extern atomic_t fscache_n_cookie_special;
45367 +extern atomic_unchecked_t fscache_n_cookie_index;
45368 +extern atomic_unchecked_t fscache_n_cookie_data;
45369 +extern atomic_unchecked_t fscache_n_cookie_special;
45370
45371 -extern atomic_t fscache_n_object_alloc;
45372 -extern atomic_t fscache_n_object_no_alloc;
45373 -extern atomic_t fscache_n_object_lookups;
45374 -extern atomic_t fscache_n_object_lookups_negative;
45375 -extern atomic_t fscache_n_object_lookups_positive;
45376 -extern atomic_t fscache_n_object_lookups_timed_out;
45377 -extern atomic_t fscache_n_object_created;
45378 -extern atomic_t fscache_n_object_avail;
45379 -extern atomic_t fscache_n_object_dead;
45380 +extern atomic_unchecked_t fscache_n_object_alloc;
45381 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45382 +extern atomic_unchecked_t fscache_n_object_lookups;
45383 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45384 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45385 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45386 +extern atomic_unchecked_t fscache_n_object_created;
45387 +extern atomic_unchecked_t fscache_n_object_avail;
45388 +extern atomic_unchecked_t fscache_n_object_dead;
45389
45390 -extern atomic_t fscache_n_checkaux_none;
45391 -extern atomic_t fscache_n_checkaux_okay;
45392 -extern atomic_t fscache_n_checkaux_update;
45393 -extern atomic_t fscache_n_checkaux_obsolete;
45394 +extern atomic_unchecked_t fscache_n_checkaux_none;
45395 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45396 +extern atomic_unchecked_t fscache_n_checkaux_update;
45397 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45398
45399 extern atomic_t fscache_n_cop_alloc_object;
45400 extern atomic_t fscache_n_cop_lookup_object;
45401 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45402 atomic_inc(stat);
45403 }
45404
45405 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45406 +{
45407 + atomic_inc_unchecked(stat);
45408 +}
45409 +
45410 static inline void fscache_stat_d(atomic_t *stat)
45411 {
45412 atomic_dec(stat);
45413 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45414
45415 #define __fscache_stat(stat) (NULL)
45416 #define fscache_stat(stat) do {} while (0)
45417 +#define fscache_stat_unchecked(stat) do {} while (0)
45418 #define fscache_stat_d(stat) do {} while (0)
45419 #endif
45420
45421 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45422 index b6b897c..0ffff9c 100644
45423 --- a/fs/fscache/object.c
45424 +++ b/fs/fscache/object.c
45425 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45426 /* update the object metadata on disk */
45427 case FSCACHE_OBJECT_UPDATING:
45428 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45429 - fscache_stat(&fscache_n_updates_run);
45430 + fscache_stat_unchecked(&fscache_n_updates_run);
45431 fscache_stat(&fscache_n_cop_update_object);
45432 object->cache->ops->update_object(object);
45433 fscache_stat_d(&fscache_n_cop_update_object);
45434 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45435 spin_lock(&object->lock);
45436 object->state = FSCACHE_OBJECT_DEAD;
45437 spin_unlock(&object->lock);
45438 - fscache_stat(&fscache_n_object_dead);
45439 + fscache_stat_unchecked(&fscache_n_object_dead);
45440 goto terminal_transit;
45441
45442 /* handle the parent cache of this object being withdrawn from
45443 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45444 spin_lock(&object->lock);
45445 object->state = FSCACHE_OBJECT_DEAD;
45446 spin_unlock(&object->lock);
45447 - fscache_stat(&fscache_n_object_dead);
45448 + fscache_stat_unchecked(&fscache_n_object_dead);
45449 goto terminal_transit;
45450
45451 /* complain about the object being woken up once it is
45452 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45453 parent->cookie->def->name, cookie->def->name,
45454 object->cache->tag->name);
45455
45456 - fscache_stat(&fscache_n_object_lookups);
45457 + fscache_stat_unchecked(&fscache_n_object_lookups);
45458 fscache_stat(&fscache_n_cop_lookup_object);
45459 ret = object->cache->ops->lookup_object(object);
45460 fscache_stat_d(&fscache_n_cop_lookup_object);
45461 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45462 if (ret == -ETIMEDOUT) {
45463 /* probably stuck behind another object, so move this one to
45464 * the back of the queue */
45465 - fscache_stat(&fscache_n_object_lookups_timed_out);
45466 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45467 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45468 }
45469
45470 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45471
45472 spin_lock(&object->lock);
45473 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45474 - fscache_stat(&fscache_n_object_lookups_negative);
45475 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45476
45477 /* transit here to allow write requests to begin stacking up
45478 * and read requests to begin returning ENODATA */
45479 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45480 * result, in which case there may be data available */
45481 spin_lock(&object->lock);
45482 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45483 - fscache_stat(&fscache_n_object_lookups_positive);
45484 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45485
45486 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45487
45488 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45489 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45490 } else {
45491 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45492 - fscache_stat(&fscache_n_object_created);
45493 + fscache_stat_unchecked(&fscache_n_object_created);
45494
45495 object->state = FSCACHE_OBJECT_AVAILABLE;
45496 spin_unlock(&object->lock);
45497 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45498 fscache_enqueue_dependents(object);
45499
45500 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45501 - fscache_stat(&fscache_n_object_avail);
45502 + fscache_stat_unchecked(&fscache_n_object_avail);
45503
45504 _leave("");
45505 }
45506 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45507 enum fscache_checkaux result;
45508
45509 if (!object->cookie->def->check_aux) {
45510 - fscache_stat(&fscache_n_checkaux_none);
45511 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45512 return FSCACHE_CHECKAUX_OKAY;
45513 }
45514
45515 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45516 switch (result) {
45517 /* entry okay as is */
45518 case FSCACHE_CHECKAUX_OKAY:
45519 - fscache_stat(&fscache_n_checkaux_okay);
45520 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45521 break;
45522
45523 /* entry requires update */
45524 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45525 - fscache_stat(&fscache_n_checkaux_update);
45526 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45527 break;
45528
45529 /* entry requires deletion */
45530 case FSCACHE_CHECKAUX_OBSOLETE:
45531 - fscache_stat(&fscache_n_checkaux_obsolete);
45532 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45533 break;
45534
45535 default:
45536 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45537 index 30afdfa..2256596 100644
45538 --- a/fs/fscache/operation.c
45539 +++ b/fs/fscache/operation.c
45540 @@ -17,7 +17,7 @@
45541 #include <linux/slab.h>
45542 #include "internal.h"
45543
45544 -atomic_t fscache_op_debug_id;
45545 +atomic_unchecked_t fscache_op_debug_id;
45546 EXPORT_SYMBOL(fscache_op_debug_id);
45547
45548 /**
45549 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45550 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45551 ASSERTCMP(atomic_read(&op->usage), >, 0);
45552
45553 - fscache_stat(&fscache_n_op_enqueue);
45554 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45555 switch (op->flags & FSCACHE_OP_TYPE) {
45556 case FSCACHE_OP_ASYNC:
45557 _debug("queue async");
45558 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45559 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45560 if (op->processor)
45561 fscache_enqueue_operation(op);
45562 - fscache_stat(&fscache_n_op_run);
45563 + fscache_stat_unchecked(&fscache_n_op_run);
45564 }
45565
45566 /*
45567 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45568 if (object->n_ops > 1) {
45569 atomic_inc(&op->usage);
45570 list_add_tail(&op->pend_link, &object->pending_ops);
45571 - fscache_stat(&fscache_n_op_pend);
45572 + fscache_stat_unchecked(&fscache_n_op_pend);
45573 } else if (!list_empty(&object->pending_ops)) {
45574 atomic_inc(&op->usage);
45575 list_add_tail(&op->pend_link, &object->pending_ops);
45576 - fscache_stat(&fscache_n_op_pend);
45577 + fscache_stat_unchecked(&fscache_n_op_pend);
45578 fscache_start_operations(object);
45579 } else {
45580 ASSERTCMP(object->n_in_progress, ==, 0);
45581 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45582 object->n_exclusive++; /* reads and writes must wait */
45583 atomic_inc(&op->usage);
45584 list_add_tail(&op->pend_link, &object->pending_ops);
45585 - fscache_stat(&fscache_n_op_pend);
45586 + fscache_stat_unchecked(&fscache_n_op_pend);
45587 ret = 0;
45588 } else {
45589 /* not allowed to submit ops in any other state */
45590 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45591 if (object->n_exclusive > 0) {
45592 atomic_inc(&op->usage);
45593 list_add_tail(&op->pend_link, &object->pending_ops);
45594 - fscache_stat(&fscache_n_op_pend);
45595 + fscache_stat_unchecked(&fscache_n_op_pend);
45596 } else if (!list_empty(&object->pending_ops)) {
45597 atomic_inc(&op->usage);
45598 list_add_tail(&op->pend_link, &object->pending_ops);
45599 - fscache_stat(&fscache_n_op_pend);
45600 + fscache_stat_unchecked(&fscache_n_op_pend);
45601 fscache_start_operations(object);
45602 } else {
45603 ASSERTCMP(object->n_exclusive, ==, 0);
45604 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45605 object->n_ops++;
45606 atomic_inc(&op->usage);
45607 list_add_tail(&op->pend_link, &object->pending_ops);
45608 - fscache_stat(&fscache_n_op_pend);
45609 + fscache_stat_unchecked(&fscache_n_op_pend);
45610 ret = 0;
45611 } else if (object->state == FSCACHE_OBJECT_DYING ||
45612 object->state == FSCACHE_OBJECT_LC_DYING ||
45613 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45614 - fscache_stat(&fscache_n_op_rejected);
45615 + fscache_stat_unchecked(&fscache_n_op_rejected);
45616 ret = -ENOBUFS;
45617 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45618 fscache_report_unexpected_submission(object, op, ostate);
45619 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45620
45621 ret = -EBUSY;
45622 if (!list_empty(&op->pend_link)) {
45623 - fscache_stat(&fscache_n_op_cancelled);
45624 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45625 list_del_init(&op->pend_link);
45626 object->n_ops--;
45627 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45628 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45629 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45630 BUG();
45631
45632 - fscache_stat(&fscache_n_op_release);
45633 + fscache_stat_unchecked(&fscache_n_op_release);
45634
45635 if (op->release) {
45636 op->release(op);
45637 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45638 * lock, and defer it otherwise */
45639 if (!spin_trylock(&object->lock)) {
45640 _debug("defer put");
45641 - fscache_stat(&fscache_n_op_deferred_release);
45642 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45643
45644 cache = object->cache;
45645 spin_lock(&cache->op_gc_list_lock);
45646 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45647
45648 _debug("GC DEFERRED REL OBJ%x OP%x",
45649 object->debug_id, op->debug_id);
45650 - fscache_stat(&fscache_n_op_gc);
45651 + fscache_stat_unchecked(&fscache_n_op_gc);
45652
45653 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45654
45655 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45656 index 3f7a59b..cf196cc 100644
45657 --- a/fs/fscache/page.c
45658 +++ b/fs/fscache/page.c
45659 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45660 val = radix_tree_lookup(&cookie->stores, page->index);
45661 if (!val) {
45662 rcu_read_unlock();
45663 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45664 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45665 __fscache_uncache_page(cookie, page);
45666 return true;
45667 }
45668 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45669 spin_unlock(&cookie->stores_lock);
45670
45671 if (xpage) {
45672 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45673 - fscache_stat(&fscache_n_store_radix_deletes);
45674 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45675 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45676 ASSERTCMP(xpage, ==, page);
45677 } else {
45678 - fscache_stat(&fscache_n_store_vmscan_gone);
45679 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45680 }
45681
45682 wake_up_bit(&cookie->flags, 0);
45683 @@ -107,7 +107,7 @@ page_busy:
45684 /* we might want to wait here, but that could deadlock the allocator as
45685 * the work threads writing to the cache may all end up sleeping
45686 * on memory allocation */
45687 - fscache_stat(&fscache_n_store_vmscan_busy);
45688 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45689 return false;
45690 }
45691 EXPORT_SYMBOL(__fscache_maybe_release_page);
45692 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45693 FSCACHE_COOKIE_STORING_TAG);
45694 if (!radix_tree_tag_get(&cookie->stores, page->index,
45695 FSCACHE_COOKIE_PENDING_TAG)) {
45696 - fscache_stat(&fscache_n_store_radix_deletes);
45697 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45698 xpage = radix_tree_delete(&cookie->stores, page->index);
45699 }
45700 spin_unlock(&cookie->stores_lock);
45701 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45702
45703 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45704
45705 - fscache_stat(&fscache_n_attr_changed_calls);
45706 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45707
45708 if (fscache_object_is_active(object)) {
45709 fscache_stat(&fscache_n_cop_attr_changed);
45710 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45711
45712 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45713
45714 - fscache_stat(&fscache_n_attr_changed);
45715 + fscache_stat_unchecked(&fscache_n_attr_changed);
45716
45717 op = kzalloc(sizeof(*op), GFP_KERNEL);
45718 if (!op) {
45719 - fscache_stat(&fscache_n_attr_changed_nomem);
45720 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45721 _leave(" = -ENOMEM");
45722 return -ENOMEM;
45723 }
45724 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45725 if (fscache_submit_exclusive_op(object, op) < 0)
45726 goto nobufs;
45727 spin_unlock(&cookie->lock);
45728 - fscache_stat(&fscache_n_attr_changed_ok);
45729 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45730 fscache_put_operation(op);
45731 _leave(" = 0");
45732 return 0;
45733 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45734 nobufs:
45735 spin_unlock(&cookie->lock);
45736 kfree(op);
45737 - fscache_stat(&fscache_n_attr_changed_nobufs);
45738 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45739 _leave(" = %d", -ENOBUFS);
45740 return -ENOBUFS;
45741 }
45742 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45743 /* allocate a retrieval operation and attempt to submit it */
45744 op = kzalloc(sizeof(*op), GFP_NOIO);
45745 if (!op) {
45746 - fscache_stat(&fscache_n_retrievals_nomem);
45747 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45748 return NULL;
45749 }
45750
45751 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45752 return 0;
45753 }
45754
45755 - fscache_stat(&fscache_n_retrievals_wait);
45756 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45757
45758 jif = jiffies;
45759 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45760 fscache_wait_bit_interruptible,
45761 TASK_INTERRUPTIBLE) != 0) {
45762 - fscache_stat(&fscache_n_retrievals_intr);
45763 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45764 _leave(" = -ERESTARTSYS");
45765 return -ERESTARTSYS;
45766 }
45767 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45768 */
45769 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45770 struct fscache_retrieval *op,
45771 - atomic_t *stat_op_waits,
45772 - atomic_t *stat_object_dead)
45773 + atomic_unchecked_t *stat_op_waits,
45774 + atomic_unchecked_t *stat_object_dead)
45775 {
45776 int ret;
45777
45778 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45779 goto check_if_dead;
45780
45781 _debug(">>> WT");
45782 - fscache_stat(stat_op_waits);
45783 + fscache_stat_unchecked(stat_op_waits);
45784 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45785 fscache_wait_bit_interruptible,
45786 TASK_INTERRUPTIBLE) < 0) {
45787 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45788
45789 check_if_dead:
45790 if (unlikely(fscache_object_is_dead(object))) {
45791 - fscache_stat(stat_object_dead);
45792 + fscache_stat_unchecked(stat_object_dead);
45793 return -ENOBUFS;
45794 }
45795 return 0;
45796 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45797
45798 _enter("%p,%p,,,", cookie, page);
45799
45800 - fscache_stat(&fscache_n_retrievals);
45801 + fscache_stat_unchecked(&fscache_n_retrievals);
45802
45803 if (hlist_empty(&cookie->backing_objects))
45804 goto nobufs;
45805 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45806 goto nobufs_unlock;
45807 spin_unlock(&cookie->lock);
45808
45809 - fscache_stat(&fscache_n_retrieval_ops);
45810 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45811
45812 /* pin the netfs read context in case we need to do the actual netfs
45813 * read because we've encountered a cache read failure */
45814 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45815
45816 error:
45817 if (ret == -ENOMEM)
45818 - fscache_stat(&fscache_n_retrievals_nomem);
45819 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45820 else if (ret == -ERESTARTSYS)
45821 - fscache_stat(&fscache_n_retrievals_intr);
45822 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45823 else if (ret == -ENODATA)
45824 - fscache_stat(&fscache_n_retrievals_nodata);
45825 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45826 else if (ret < 0)
45827 - fscache_stat(&fscache_n_retrievals_nobufs);
45828 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45829 else
45830 - fscache_stat(&fscache_n_retrievals_ok);
45831 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45832
45833 fscache_put_retrieval(op);
45834 _leave(" = %d", ret);
45835 @@ -429,7 +429,7 @@ nobufs_unlock:
45836 spin_unlock(&cookie->lock);
45837 kfree(op);
45838 nobufs:
45839 - fscache_stat(&fscache_n_retrievals_nobufs);
45840 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45841 _leave(" = -ENOBUFS");
45842 return -ENOBUFS;
45843 }
45844 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45845
45846 _enter("%p,,%d,,,", cookie, *nr_pages);
45847
45848 - fscache_stat(&fscache_n_retrievals);
45849 + fscache_stat_unchecked(&fscache_n_retrievals);
45850
45851 if (hlist_empty(&cookie->backing_objects))
45852 goto nobufs;
45853 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45854 goto nobufs_unlock;
45855 spin_unlock(&cookie->lock);
45856
45857 - fscache_stat(&fscache_n_retrieval_ops);
45858 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45859
45860 /* pin the netfs read context in case we need to do the actual netfs
45861 * read because we've encountered a cache read failure */
45862 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45863
45864 error:
45865 if (ret == -ENOMEM)
45866 - fscache_stat(&fscache_n_retrievals_nomem);
45867 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45868 else if (ret == -ERESTARTSYS)
45869 - fscache_stat(&fscache_n_retrievals_intr);
45870 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45871 else if (ret == -ENODATA)
45872 - fscache_stat(&fscache_n_retrievals_nodata);
45873 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45874 else if (ret < 0)
45875 - fscache_stat(&fscache_n_retrievals_nobufs);
45876 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45877 else
45878 - fscache_stat(&fscache_n_retrievals_ok);
45879 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45880
45881 fscache_put_retrieval(op);
45882 _leave(" = %d", ret);
45883 @@ -545,7 +545,7 @@ nobufs_unlock:
45884 spin_unlock(&cookie->lock);
45885 kfree(op);
45886 nobufs:
45887 - fscache_stat(&fscache_n_retrievals_nobufs);
45888 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45889 _leave(" = -ENOBUFS");
45890 return -ENOBUFS;
45891 }
45892 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45893
45894 _enter("%p,%p,,,", cookie, page);
45895
45896 - fscache_stat(&fscache_n_allocs);
45897 + fscache_stat_unchecked(&fscache_n_allocs);
45898
45899 if (hlist_empty(&cookie->backing_objects))
45900 goto nobufs;
45901 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45902 goto nobufs_unlock;
45903 spin_unlock(&cookie->lock);
45904
45905 - fscache_stat(&fscache_n_alloc_ops);
45906 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45907
45908 ret = fscache_wait_for_retrieval_activation(
45909 object, op,
45910 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45911
45912 error:
45913 if (ret == -ERESTARTSYS)
45914 - fscache_stat(&fscache_n_allocs_intr);
45915 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45916 else if (ret < 0)
45917 - fscache_stat(&fscache_n_allocs_nobufs);
45918 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45919 else
45920 - fscache_stat(&fscache_n_allocs_ok);
45921 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45922
45923 fscache_put_retrieval(op);
45924 _leave(" = %d", ret);
45925 @@ -625,7 +625,7 @@ nobufs_unlock:
45926 spin_unlock(&cookie->lock);
45927 kfree(op);
45928 nobufs:
45929 - fscache_stat(&fscache_n_allocs_nobufs);
45930 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45931 _leave(" = -ENOBUFS");
45932 return -ENOBUFS;
45933 }
45934 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45935
45936 spin_lock(&cookie->stores_lock);
45937
45938 - fscache_stat(&fscache_n_store_calls);
45939 + fscache_stat_unchecked(&fscache_n_store_calls);
45940
45941 /* find a page to store */
45942 page = NULL;
45943 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45944 page = results[0];
45945 _debug("gang %d [%lx]", n, page->index);
45946 if (page->index > op->store_limit) {
45947 - fscache_stat(&fscache_n_store_pages_over_limit);
45948 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45949 goto superseded;
45950 }
45951
45952 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45953 spin_unlock(&cookie->stores_lock);
45954 spin_unlock(&object->lock);
45955
45956 - fscache_stat(&fscache_n_store_pages);
45957 + fscache_stat_unchecked(&fscache_n_store_pages);
45958 fscache_stat(&fscache_n_cop_write_page);
45959 ret = object->cache->ops->write_page(op, page);
45960 fscache_stat_d(&fscache_n_cop_write_page);
45961 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45962 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45963 ASSERT(PageFsCache(page));
45964
45965 - fscache_stat(&fscache_n_stores);
45966 + fscache_stat_unchecked(&fscache_n_stores);
45967
45968 op = kzalloc(sizeof(*op), GFP_NOIO);
45969 if (!op)
45970 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45971 spin_unlock(&cookie->stores_lock);
45972 spin_unlock(&object->lock);
45973
45974 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45975 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45976 op->store_limit = object->store_limit;
45977
45978 if (fscache_submit_op(object, &op->op) < 0)
45979 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45980
45981 spin_unlock(&cookie->lock);
45982 radix_tree_preload_end();
45983 - fscache_stat(&fscache_n_store_ops);
45984 - fscache_stat(&fscache_n_stores_ok);
45985 + fscache_stat_unchecked(&fscache_n_store_ops);
45986 + fscache_stat_unchecked(&fscache_n_stores_ok);
45987
45988 /* the work queue now carries its own ref on the object */
45989 fscache_put_operation(&op->op);
45990 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45991 return 0;
45992
45993 already_queued:
45994 - fscache_stat(&fscache_n_stores_again);
45995 + fscache_stat_unchecked(&fscache_n_stores_again);
45996 already_pending:
45997 spin_unlock(&cookie->stores_lock);
45998 spin_unlock(&object->lock);
45999 spin_unlock(&cookie->lock);
46000 radix_tree_preload_end();
46001 kfree(op);
46002 - fscache_stat(&fscache_n_stores_ok);
46003 + fscache_stat_unchecked(&fscache_n_stores_ok);
46004 _leave(" = 0");
46005 return 0;
46006
46007 @@ -851,14 +851,14 @@ nobufs:
46008 spin_unlock(&cookie->lock);
46009 radix_tree_preload_end();
46010 kfree(op);
46011 - fscache_stat(&fscache_n_stores_nobufs);
46012 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46013 _leave(" = -ENOBUFS");
46014 return -ENOBUFS;
46015
46016 nomem_free:
46017 kfree(op);
46018 nomem:
46019 - fscache_stat(&fscache_n_stores_oom);
46020 + fscache_stat_unchecked(&fscache_n_stores_oom);
46021 _leave(" = -ENOMEM");
46022 return -ENOMEM;
46023 }
46024 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46025 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46026 ASSERTCMP(page, !=, NULL);
46027
46028 - fscache_stat(&fscache_n_uncaches);
46029 + fscache_stat_unchecked(&fscache_n_uncaches);
46030
46031 /* cache withdrawal may beat us to it */
46032 if (!PageFsCache(page))
46033 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46034 unsigned long loop;
46035
46036 #ifdef CONFIG_FSCACHE_STATS
46037 - atomic_add(pagevec->nr, &fscache_n_marks);
46038 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46039 #endif
46040
46041 for (loop = 0; loop < pagevec->nr; loop++) {
46042 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46043 index 4765190..2a067f2 100644
46044 --- a/fs/fscache/stats.c
46045 +++ b/fs/fscache/stats.c
46046 @@ -18,95 +18,95 @@
46047 /*
46048 * operation counters
46049 */
46050 -atomic_t fscache_n_op_pend;
46051 -atomic_t fscache_n_op_run;
46052 -atomic_t fscache_n_op_enqueue;
46053 -atomic_t fscache_n_op_requeue;
46054 -atomic_t fscache_n_op_deferred_release;
46055 -atomic_t fscache_n_op_release;
46056 -atomic_t fscache_n_op_gc;
46057 -atomic_t fscache_n_op_cancelled;
46058 -atomic_t fscache_n_op_rejected;
46059 +atomic_unchecked_t fscache_n_op_pend;
46060 +atomic_unchecked_t fscache_n_op_run;
46061 +atomic_unchecked_t fscache_n_op_enqueue;
46062 +atomic_unchecked_t fscache_n_op_requeue;
46063 +atomic_unchecked_t fscache_n_op_deferred_release;
46064 +atomic_unchecked_t fscache_n_op_release;
46065 +atomic_unchecked_t fscache_n_op_gc;
46066 +atomic_unchecked_t fscache_n_op_cancelled;
46067 +atomic_unchecked_t fscache_n_op_rejected;
46068
46069 -atomic_t fscache_n_attr_changed;
46070 -atomic_t fscache_n_attr_changed_ok;
46071 -atomic_t fscache_n_attr_changed_nobufs;
46072 -atomic_t fscache_n_attr_changed_nomem;
46073 -atomic_t fscache_n_attr_changed_calls;
46074 +atomic_unchecked_t fscache_n_attr_changed;
46075 +atomic_unchecked_t fscache_n_attr_changed_ok;
46076 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46077 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46078 +atomic_unchecked_t fscache_n_attr_changed_calls;
46079
46080 -atomic_t fscache_n_allocs;
46081 -atomic_t fscache_n_allocs_ok;
46082 -atomic_t fscache_n_allocs_wait;
46083 -atomic_t fscache_n_allocs_nobufs;
46084 -atomic_t fscache_n_allocs_intr;
46085 -atomic_t fscache_n_allocs_object_dead;
46086 -atomic_t fscache_n_alloc_ops;
46087 -atomic_t fscache_n_alloc_op_waits;
46088 +atomic_unchecked_t fscache_n_allocs;
46089 +atomic_unchecked_t fscache_n_allocs_ok;
46090 +atomic_unchecked_t fscache_n_allocs_wait;
46091 +atomic_unchecked_t fscache_n_allocs_nobufs;
46092 +atomic_unchecked_t fscache_n_allocs_intr;
46093 +atomic_unchecked_t fscache_n_allocs_object_dead;
46094 +atomic_unchecked_t fscache_n_alloc_ops;
46095 +atomic_unchecked_t fscache_n_alloc_op_waits;
46096
46097 -atomic_t fscache_n_retrievals;
46098 -atomic_t fscache_n_retrievals_ok;
46099 -atomic_t fscache_n_retrievals_wait;
46100 -atomic_t fscache_n_retrievals_nodata;
46101 -atomic_t fscache_n_retrievals_nobufs;
46102 -atomic_t fscache_n_retrievals_intr;
46103 -atomic_t fscache_n_retrievals_nomem;
46104 -atomic_t fscache_n_retrievals_object_dead;
46105 -atomic_t fscache_n_retrieval_ops;
46106 -atomic_t fscache_n_retrieval_op_waits;
46107 +atomic_unchecked_t fscache_n_retrievals;
46108 +atomic_unchecked_t fscache_n_retrievals_ok;
46109 +atomic_unchecked_t fscache_n_retrievals_wait;
46110 +atomic_unchecked_t fscache_n_retrievals_nodata;
46111 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46112 +atomic_unchecked_t fscache_n_retrievals_intr;
46113 +atomic_unchecked_t fscache_n_retrievals_nomem;
46114 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46115 +atomic_unchecked_t fscache_n_retrieval_ops;
46116 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46117
46118 -atomic_t fscache_n_stores;
46119 -atomic_t fscache_n_stores_ok;
46120 -atomic_t fscache_n_stores_again;
46121 -atomic_t fscache_n_stores_nobufs;
46122 -atomic_t fscache_n_stores_oom;
46123 -atomic_t fscache_n_store_ops;
46124 -atomic_t fscache_n_store_calls;
46125 -atomic_t fscache_n_store_pages;
46126 -atomic_t fscache_n_store_radix_deletes;
46127 -atomic_t fscache_n_store_pages_over_limit;
46128 +atomic_unchecked_t fscache_n_stores;
46129 +atomic_unchecked_t fscache_n_stores_ok;
46130 +atomic_unchecked_t fscache_n_stores_again;
46131 +atomic_unchecked_t fscache_n_stores_nobufs;
46132 +atomic_unchecked_t fscache_n_stores_oom;
46133 +atomic_unchecked_t fscache_n_store_ops;
46134 +atomic_unchecked_t fscache_n_store_calls;
46135 +atomic_unchecked_t fscache_n_store_pages;
46136 +atomic_unchecked_t fscache_n_store_radix_deletes;
46137 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46138
46139 -atomic_t fscache_n_store_vmscan_not_storing;
46140 -atomic_t fscache_n_store_vmscan_gone;
46141 -atomic_t fscache_n_store_vmscan_busy;
46142 -atomic_t fscache_n_store_vmscan_cancelled;
46143 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46144 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46145 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46146 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46147
46148 -atomic_t fscache_n_marks;
46149 -atomic_t fscache_n_uncaches;
46150 +atomic_unchecked_t fscache_n_marks;
46151 +atomic_unchecked_t fscache_n_uncaches;
46152
46153 -atomic_t fscache_n_acquires;
46154 -atomic_t fscache_n_acquires_null;
46155 -atomic_t fscache_n_acquires_no_cache;
46156 -atomic_t fscache_n_acquires_ok;
46157 -atomic_t fscache_n_acquires_nobufs;
46158 -atomic_t fscache_n_acquires_oom;
46159 +atomic_unchecked_t fscache_n_acquires;
46160 +atomic_unchecked_t fscache_n_acquires_null;
46161 +atomic_unchecked_t fscache_n_acquires_no_cache;
46162 +atomic_unchecked_t fscache_n_acquires_ok;
46163 +atomic_unchecked_t fscache_n_acquires_nobufs;
46164 +atomic_unchecked_t fscache_n_acquires_oom;
46165
46166 -atomic_t fscache_n_updates;
46167 -atomic_t fscache_n_updates_null;
46168 -atomic_t fscache_n_updates_run;
46169 +atomic_unchecked_t fscache_n_updates;
46170 +atomic_unchecked_t fscache_n_updates_null;
46171 +atomic_unchecked_t fscache_n_updates_run;
46172
46173 -atomic_t fscache_n_relinquishes;
46174 -atomic_t fscache_n_relinquishes_null;
46175 -atomic_t fscache_n_relinquishes_waitcrt;
46176 -atomic_t fscache_n_relinquishes_retire;
46177 +atomic_unchecked_t fscache_n_relinquishes;
46178 +atomic_unchecked_t fscache_n_relinquishes_null;
46179 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46180 +atomic_unchecked_t fscache_n_relinquishes_retire;
46181
46182 -atomic_t fscache_n_cookie_index;
46183 -atomic_t fscache_n_cookie_data;
46184 -atomic_t fscache_n_cookie_special;
46185 +atomic_unchecked_t fscache_n_cookie_index;
46186 +atomic_unchecked_t fscache_n_cookie_data;
46187 +atomic_unchecked_t fscache_n_cookie_special;
46188
46189 -atomic_t fscache_n_object_alloc;
46190 -atomic_t fscache_n_object_no_alloc;
46191 -atomic_t fscache_n_object_lookups;
46192 -atomic_t fscache_n_object_lookups_negative;
46193 -atomic_t fscache_n_object_lookups_positive;
46194 -atomic_t fscache_n_object_lookups_timed_out;
46195 -atomic_t fscache_n_object_created;
46196 -atomic_t fscache_n_object_avail;
46197 -atomic_t fscache_n_object_dead;
46198 +atomic_unchecked_t fscache_n_object_alloc;
46199 +atomic_unchecked_t fscache_n_object_no_alloc;
46200 +atomic_unchecked_t fscache_n_object_lookups;
46201 +atomic_unchecked_t fscache_n_object_lookups_negative;
46202 +atomic_unchecked_t fscache_n_object_lookups_positive;
46203 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46204 +atomic_unchecked_t fscache_n_object_created;
46205 +atomic_unchecked_t fscache_n_object_avail;
46206 +atomic_unchecked_t fscache_n_object_dead;
46207
46208 -atomic_t fscache_n_checkaux_none;
46209 -atomic_t fscache_n_checkaux_okay;
46210 -atomic_t fscache_n_checkaux_update;
46211 -atomic_t fscache_n_checkaux_obsolete;
46212 +atomic_unchecked_t fscache_n_checkaux_none;
46213 +atomic_unchecked_t fscache_n_checkaux_okay;
46214 +atomic_unchecked_t fscache_n_checkaux_update;
46215 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46216
46217 atomic_t fscache_n_cop_alloc_object;
46218 atomic_t fscache_n_cop_lookup_object;
46219 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46220 seq_puts(m, "FS-Cache statistics\n");
46221
46222 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46223 - atomic_read(&fscache_n_cookie_index),
46224 - atomic_read(&fscache_n_cookie_data),
46225 - atomic_read(&fscache_n_cookie_special));
46226 + atomic_read_unchecked(&fscache_n_cookie_index),
46227 + atomic_read_unchecked(&fscache_n_cookie_data),
46228 + atomic_read_unchecked(&fscache_n_cookie_special));
46229
46230 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46231 - atomic_read(&fscache_n_object_alloc),
46232 - atomic_read(&fscache_n_object_no_alloc),
46233 - atomic_read(&fscache_n_object_avail),
46234 - atomic_read(&fscache_n_object_dead));
46235 + atomic_read_unchecked(&fscache_n_object_alloc),
46236 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46237 + atomic_read_unchecked(&fscache_n_object_avail),
46238 + atomic_read_unchecked(&fscache_n_object_dead));
46239 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46240 - atomic_read(&fscache_n_checkaux_none),
46241 - atomic_read(&fscache_n_checkaux_okay),
46242 - atomic_read(&fscache_n_checkaux_update),
46243 - atomic_read(&fscache_n_checkaux_obsolete));
46244 + atomic_read_unchecked(&fscache_n_checkaux_none),
46245 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46246 + atomic_read_unchecked(&fscache_n_checkaux_update),
46247 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46248
46249 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46250 - atomic_read(&fscache_n_marks),
46251 - atomic_read(&fscache_n_uncaches));
46252 + atomic_read_unchecked(&fscache_n_marks),
46253 + atomic_read_unchecked(&fscache_n_uncaches));
46254
46255 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46256 " oom=%u\n",
46257 - atomic_read(&fscache_n_acquires),
46258 - atomic_read(&fscache_n_acquires_null),
46259 - atomic_read(&fscache_n_acquires_no_cache),
46260 - atomic_read(&fscache_n_acquires_ok),
46261 - atomic_read(&fscache_n_acquires_nobufs),
46262 - atomic_read(&fscache_n_acquires_oom));
46263 + atomic_read_unchecked(&fscache_n_acquires),
46264 + atomic_read_unchecked(&fscache_n_acquires_null),
46265 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46266 + atomic_read_unchecked(&fscache_n_acquires_ok),
46267 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46268 + atomic_read_unchecked(&fscache_n_acquires_oom));
46269
46270 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46271 - atomic_read(&fscache_n_object_lookups),
46272 - atomic_read(&fscache_n_object_lookups_negative),
46273 - atomic_read(&fscache_n_object_lookups_positive),
46274 - atomic_read(&fscache_n_object_created),
46275 - atomic_read(&fscache_n_object_lookups_timed_out));
46276 + atomic_read_unchecked(&fscache_n_object_lookups),
46277 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46278 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46279 + atomic_read_unchecked(&fscache_n_object_created),
46280 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46281
46282 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46283 - atomic_read(&fscache_n_updates),
46284 - atomic_read(&fscache_n_updates_null),
46285 - atomic_read(&fscache_n_updates_run));
46286 + atomic_read_unchecked(&fscache_n_updates),
46287 + atomic_read_unchecked(&fscache_n_updates_null),
46288 + atomic_read_unchecked(&fscache_n_updates_run));
46289
46290 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46291 - atomic_read(&fscache_n_relinquishes),
46292 - atomic_read(&fscache_n_relinquishes_null),
46293 - atomic_read(&fscache_n_relinquishes_waitcrt),
46294 - atomic_read(&fscache_n_relinquishes_retire));
46295 + atomic_read_unchecked(&fscache_n_relinquishes),
46296 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46297 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46298 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46299
46300 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46301 - atomic_read(&fscache_n_attr_changed),
46302 - atomic_read(&fscache_n_attr_changed_ok),
46303 - atomic_read(&fscache_n_attr_changed_nobufs),
46304 - atomic_read(&fscache_n_attr_changed_nomem),
46305 - atomic_read(&fscache_n_attr_changed_calls));
46306 + atomic_read_unchecked(&fscache_n_attr_changed),
46307 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46308 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46309 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46310 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46311
46312 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46313 - atomic_read(&fscache_n_allocs),
46314 - atomic_read(&fscache_n_allocs_ok),
46315 - atomic_read(&fscache_n_allocs_wait),
46316 - atomic_read(&fscache_n_allocs_nobufs),
46317 - atomic_read(&fscache_n_allocs_intr));
46318 + atomic_read_unchecked(&fscache_n_allocs),
46319 + atomic_read_unchecked(&fscache_n_allocs_ok),
46320 + atomic_read_unchecked(&fscache_n_allocs_wait),
46321 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46322 + atomic_read_unchecked(&fscache_n_allocs_intr));
46323 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46324 - atomic_read(&fscache_n_alloc_ops),
46325 - atomic_read(&fscache_n_alloc_op_waits),
46326 - atomic_read(&fscache_n_allocs_object_dead));
46327 + atomic_read_unchecked(&fscache_n_alloc_ops),
46328 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46329 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46330
46331 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46332 " int=%u oom=%u\n",
46333 - atomic_read(&fscache_n_retrievals),
46334 - atomic_read(&fscache_n_retrievals_ok),
46335 - atomic_read(&fscache_n_retrievals_wait),
46336 - atomic_read(&fscache_n_retrievals_nodata),
46337 - atomic_read(&fscache_n_retrievals_nobufs),
46338 - atomic_read(&fscache_n_retrievals_intr),
46339 - atomic_read(&fscache_n_retrievals_nomem));
46340 + atomic_read_unchecked(&fscache_n_retrievals),
46341 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46342 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46343 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46344 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46345 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46346 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46347 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46348 - atomic_read(&fscache_n_retrieval_ops),
46349 - atomic_read(&fscache_n_retrieval_op_waits),
46350 - atomic_read(&fscache_n_retrievals_object_dead));
46351 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46352 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46353 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46354
46355 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46356 - atomic_read(&fscache_n_stores),
46357 - atomic_read(&fscache_n_stores_ok),
46358 - atomic_read(&fscache_n_stores_again),
46359 - atomic_read(&fscache_n_stores_nobufs),
46360 - atomic_read(&fscache_n_stores_oom));
46361 + atomic_read_unchecked(&fscache_n_stores),
46362 + atomic_read_unchecked(&fscache_n_stores_ok),
46363 + atomic_read_unchecked(&fscache_n_stores_again),
46364 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46365 + atomic_read_unchecked(&fscache_n_stores_oom));
46366 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46367 - atomic_read(&fscache_n_store_ops),
46368 - atomic_read(&fscache_n_store_calls),
46369 - atomic_read(&fscache_n_store_pages),
46370 - atomic_read(&fscache_n_store_radix_deletes),
46371 - atomic_read(&fscache_n_store_pages_over_limit));
46372 + atomic_read_unchecked(&fscache_n_store_ops),
46373 + atomic_read_unchecked(&fscache_n_store_calls),
46374 + atomic_read_unchecked(&fscache_n_store_pages),
46375 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46376 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46377
46378 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46379 - atomic_read(&fscache_n_store_vmscan_not_storing),
46380 - atomic_read(&fscache_n_store_vmscan_gone),
46381 - atomic_read(&fscache_n_store_vmscan_busy),
46382 - atomic_read(&fscache_n_store_vmscan_cancelled));
46383 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46384 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46385 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46386 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46387
46388 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46389 - atomic_read(&fscache_n_op_pend),
46390 - atomic_read(&fscache_n_op_run),
46391 - atomic_read(&fscache_n_op_enqueue),
46392 - atomic_read(&fscache_n_op_cancelled),
46393 - atomic_read(&fscache_n_op_rejected));
46394 + atomic_read_unchecked(&fscache_n_op_pend),
46395 + atomic_read_unchecked(&fscache_n_op_run),
46396 + atomic_read_unchecked(&fscache_n_op_enqueue),
46397 + atomic_read_unchecked(&fscache_n_op_cancelled),
46398 + atomic_read_unchecked(&fscache_n_op_rejected));
46399 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46400 - atomic_read(&fscache_n_op_deferred_release),
46401 - atomic_read(&fscache_n_op_release),
46402 - atomic_read(&fscache_n_op_gc));
46403 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46404 + atomic_read_unchecked(&fscache_n_op_release),
46405 + atomic_read_unchecked(&fscache_n_op_gc));
46406
46407 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46408 atomic_read(&fscache_n_cop_alloc_object),
46409 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46410 index 3426521..3b75162 100644
46411 --- a/fs/fuse/cuse.c
46412 +++ b/fs/fuse/cuse.c
46413 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46414 INIT_LIST_HEAD(&cuse_conntbl[i]);
46415
46416 /* inherit and extend fuse_dev_operations */
46417 - cuse_channel_fops = fuse_dev_operations;
46418 - cuse_channel_fops.owner = THIS_MODULE;
46419 - cuse_channel_fops.open = cuse_channel_open;
46420 - cuse_channel_fops.release = cuse_channel_release;
46421 + pax_open_kernel();
46422 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46423 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46424 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46425 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46426 + pax_close_kernel();
46427
46428 cuse_class = class_create(THIS_MODULE, "cuse");
46429 if (IS_ERR(cuse_class))
46430 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46431 index 5f3368a..8306426 100644
46432 --- a/fs/fuse/dev.c
46433 +++ b/fs/fuse/dev.c
46434 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46435 ret = 0;
46436 pipe_lock(pipe);
46437
46438 - if (!pipe->readers) {
46439 + if (!atomic_read(&pipe->readers)) {
46440 send_sig(SIGPIPE, current, 0);
46441 if (!ret)
46442 ret = -EPIPE;
46443 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46444 index 2066328..f5add3b 100644
46445 --- a/fs/fuse/dir.c
46446 +++ b/fs/fuse/dir.c
46447 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46448 return link;
46449 }
46450
46451 -static void free_link(char *link)
46452 +static void free_link(const char *link)
46453 {
46454 if (!IS_ERR(link))
46455 free_page((unsigned long) link);
46456 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46457 index 5698746..6086012 100644
46458 --- a/fs/gfs2/inode.c
46459 +++ b/fs/gfs2/inode.c
46460 @@ -1487,7 +1487,7 @@ out:
46461
46462 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46463 {
46464 - char *s = nd_get_link(nd);
46465 + const char *s = nd_get_link(nd);
46466 if (!IS_ERR(s))
46467 kfree(s);
46468 }
46469 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46470 index 3645cd3..786809c 100644
46471 --- a/fs/hugetlbfs/inode.c
46472 +++ b/fs/hugetlbfs/inode.c
46473 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46474 .kill_sb = kill_litter_super,
46475 };
46476
46477 -static struct vfsmount *hugetlbfs_vfsmount;
46478 +struct vfsmount *hugetlbfs_vfsmount;
46479
46480 static int can_do_hugetlb_shm(void)
46481 {
46482 diff --git a/fs/inode.c b/fs/inode.c
46483 index 83ab215..8842101 100644
46484 --- a/fs/inode.c
46485 +++ b/fs/inode.c
46486 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46487
46488 #ifdef CONFIG_SMP
46489 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46490 - static atomic_t shared_last_ino;
46491 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46492 + static atomic_unchecked_t shared_last_ino;
46493 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46494
46495 res = next - LAST_INO_BATCH;
46496 }
46497 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46498 index eafb8d3..f423d37 100644
46499 --- a/fs/jffs2/erase.c
46500 +++ b/fs/jffs2/erase.c
46501 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46502 struct jffs2_unknown_node marker = {
46503 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46504 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46505 - .totlen = cpu_to_je32(c->cleanmarker_size)
46506 + .totlen = cpu_to_je32(c->cleanmarker_size),
46507 + .hdr_crc = cpu_to_je32(0)
46508 };
46509
46510 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46511 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46512 index 30e8f47..21f600c 100644
46513 --- a/fs/jffs2/wbuf.c
46514 +++ b/fs/jffs2/wbuf.c
46515 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46516 {
46517 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46518 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46519 - .totlen = constant_cpu_to_je32(8)
46520 + .totlen = constant_cpu_to_je32(8),
46521 + .hdr_crc = constant_cpu_to_je32(0)
46522 };
46523
46524 /*
46525 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46526 index 682bca6..86b8e6e 100644
46527 --- a/fs/jfs/super.c
46528 +++ b/fs/jfs/super.c
46529 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46530
46531 jfs_inode_cachep =
46532 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46533 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46534 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46535 init_once);
46536 if (jfs_inode_cachep == NULL)
46537 return -ENOMEM;
46538 diff --git a/fs/libfs.c b/fs/libfs.c
46539 index 5b2dbb3..7442d54 100644
46540 --- a/fs/libfs.c
46541 +++ b/fs/libfs.c
46542 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46543
46544 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46545 struct dentry *next;
46546 + char d_name[sizeof(next->d_iname)];
46547 + const unsigned char *name;
46548 +
46549 next = list_entry(p, struct dentry, d_u.d_child);
46550 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46551 if (!simple_positive(next)) {
46552 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46553
46554 spin_unlock(&next->d_lock);
46555 spin_unlock(&dentry->d_lock);
46556 - if (filldir(dirent, next->d_name.name,
46557 + name = next->d_name.name;
46558 + if (name == next->d_iname) {
46559 + memcpy(d_name, name, next->d_name.len);
46560 + name = d_name;
46561 + }
46562 + if (filldir(dirent, name,
46563 next->d_name.len, filp->f_pos,
46564 next->d_inode->i_ino,
46565 dt_type(next->d_inode)) < 0)
46566 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46567 index 8392cb8..80d6193 100644
46568 --- a/fs/lockd/clntproc.c
46569 +++ b/fs/lockd/clntproc.c
46570 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46571 /*
46572 * Cookie counter for NLM requests
46573 */
46574 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46575 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46576
46577 void nlmclnt_next_cookie(struct nlm_cookie *c)
46578 {
46579 - u32 cookie = atomic_inc_return(&nlm_cookie);
46580 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46581
46582 memcpy(c->data, &cookie, 4);
46583 c->len=4;
46584 diff --git a/fs/locks.c b/fs/locks.c
46585 index 637694b..f84a121 100644
46586 --- a/fs/locks.c
46587 +++ b/fs/locks.c
46588 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
46589 return;
46590
46591 if (filp->f_op && filp->f_op->flock) {
46592 - struct file_lock fl = {
46593 + struct file_lock flock = {
46594 .fl_pid = current->tgid,
46595 .fl_file = filp,
46596 .fl_flags = FL_FLOCK,
46597 .fl_type = F_UNLCK,
46598 .fl_end = OFFSET_MAX,
46599 };
46600 - filp->f_op->flock(filp, F_SETLKW, &fl);
46601 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46602 - fl.fl_ops->fl_release_private(&fl);
46603 + filp->f_op->flock(filp, F_SETLKW, &flock);
46604 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46605 + flock.fl_ops->fl_release_private(&flock);
46606 }
46607
46608 lock_flocks();
46609 diff --git a/fs/namei.c b/fs/namei.c
46610 index 46ea9cc..c7cf3a3 100644
46611 --- a/fs/namei.c
46612 +++ b/fs/namei.c
46613 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46614 if (ret != -EACCES)
46615 return ret;
46616
46617 +#ifdef CONFIG_GRKERNSEC
46618 + /* we'll block if we have to log due to a denied capability use */
46619 + if (mask & MAY_NOT_BLOCK)
46620 + return -ECHILD;
46621 +#endif
46622 +
46623 if (S_ISDIR(inode->i_mode)) {
46624 /* DACs are overridable for directories */
46625 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46626 - return 0;
46627 if (!(mask & MAY_WRITE))
46628 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46629 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46630 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46631 return 0;
46632 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46633 + return 0;
46634 return -EACCES;
46635 }
46636 /*
46637 + * Searching includes executable on directories, else just read.
46638 + */
46639 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46640 + if (mask == MAY_READ)
46641 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46642 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46643 + return 0;
46644 +
46645 + /*
46646 * Read/write DACs are always overridable.
46647 * Executable DACs are overridable when there is
46648 * at least one exec bit set.
46649 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46650 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46651 return 0;
46652
46653 - /*
46654 - * Searching includes executable on directories, else just read.
46655 - */
46656 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46657 - if (mask == MAY_READ)
46658 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46659 - return 0;
46660 -
46661 return -EACCES;
46662 }
46663
46664 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46665 return error;
46666 }
46667
46668 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46669 + dentry->d_inode, dentry, nd->path.mnt)) {
46670 + error = -EACCES;
46671 + *p = ERR_PTR(error); /* no ->put_link(), please */
46672 + path_put(&nd->path);
46673 + return error;
46674 + }
46675 +
46676 nd->last_type = LAST_BIND;
46677 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46678 error = PTR_ERR(*p);
46679 if (!IS_ERR(*p)) {
46680 - char *s = nd_get_link(nd);
46681 + const char *s = nd_get_link(nd);
46682 error = 0;
46683 if (s)
46684 error = __vfs_follow_link(nd, s);
46685 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46686 if (!err)
46687 err = complete_walk(nd);
46688
46689 + if (!(nd->flags & LOOKUP_PARENT)) {
46690 +#ifdef CONFIG_GRKERNSEC
46691 + if (flags & LOOKUP_RCU) {
46692 + if (!err)
46693 + path_put(&nd->path);
46694 + err = -ECHILD;
46695 + } else
46696 +#endif
46697 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46698 + if (!err)
46699 + path_put(&nd->path);
46700 + err = -ENOENT;
46701 + }
46702 + }
46703 +
46704 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46705 if (!nd->inode->i_op->lookup) {
46706 path_put(&nd->path);
46707 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46708 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46709
46710 if (likely(!retval)) {
46711 + if (*name != '/' && nd->path.dentry && nd->inode) {
46712 +#ifdef CONFIG_GRKERNSEC
46713 + if (flags & LOOKUP_RCU)
46714 + return -ECHILD;
46715 +#endif
46716 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46717 + return -ENOENT;
46718 + }
46719 +
46720 if (unlikely(!audit_dummy_context())) {
46721 if (nd->path.dentry && nd->inode)
46722 audit_inode(name, nd->path.dentry);
46723 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46724 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46725 return -EPERM;
46726
46727 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46728 + return -EPERM;
46729 + if (gr_handle_rawio(inode))
46730 + return -EPERM;
46731 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46732 + return -EACCES;
46733 +
46734 return 0;
46735 }
46736
46737 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46738 error = complete_walk(nd);
46739 if (error)
46740 return ERR_PTR(error);
46741 +#ifdef CONFIG_GRKERNSEC
46742 + if (nd->flags & LOOKUP_RCU) {
46743 + error = -ECHILD;
46744 + goto exit;
46745 + }
46746 +#endif
46747 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46748 + error = -ENOENT;
46749 + goto exit;
46750 + }
46751 audit_inode(pathname, nd->path.dentry);
46752 if (open_flag & O_CREAT) {
46753 error = -EISDIR;
46754 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46755 error = complete_walk(nd);
46756 if (error)
46757 return ERR_PTR(error);
46758 +#ifdef CONFIG_GRKERNSEC
46759 + if (nd->flags & LOOKUP_RCU) {
46760 + error = -ECHILD;
46761 + goto exit;
46762 + }
46763 +#endif
46764 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46765 + error = -ENOENT;
46766 + goto exit;
46767 + }
46768 audit_inode(pathname, dir);
46769 goto ok;
46770 }
46771 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46772 error = complete_walk(nd);
46773 if (error)
46774 return ERR_PTR(error);
46775 +#ifdef CONFIG_GRKERNSEC
46776 + if (nd->flags & LOOKUP_RCU) {
46777 + error = -ECHILD;
46778 + goto exit;
46779 + }
46780 +#endif
46781 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46782 + error = -ENOENT;
46783 + goto exit;
46784 + }
46785
46786 error = -ENOTDIR;
46787 if (nd->flags & LOOKUP_DIRECTORY) {
46788 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46789 /* Negative dentry, just create the file */
46790 if (!dentry->d_inode) {
46791 umode_t mode = op->mode;
46792 +
46793 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46794 + error = -EACCES;
46795 + goto exit_mutex_unlock;
46796 + }
46797 +
46798 if (!IS_POSIXACL(dir->d_inode))
46799 mode &= ~current_umask();
46800 /*
46801 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46802 error = vfs_create(dir->d_inode, dentry, mode, nd);
46803 if (error)
46804 goto exit_mutex_unlock;
46805 + else
46806 + gr_handle_create(path->dentry, path->mnt);
46807 mutex_unlock(&dir->d_inode->i_mutex);
46808 dput(nd->path.dentry);
46809 nd->path.dentry = dentry;
46810 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46811 /*
46812 * It already exists.
46813 */
46814 +
46815 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46816 + error = -ENOENT;
46817 + goto exit_mutex_unlock;
46818 + }
46819 +
46820 + /* only check if O_CREAT is specified, all other checks need to go
46821 + into may_open */
46822 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46823 + error = -EACCES;
46824 + goto exit_mutex_unlock;
46825 + }
46826 +
46827 mutex_unlock(&dir->d_inode->i_mutex);
46828 audit_inode(pathname, path->dentry);
46829
46830 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46831 *path = nd.path;
46832 return dentry;
46833 eexist:
46834 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46835 + dput(dentry);
46836 + dentry = ERR_PTR(-ENOENT);
46837 + goto fail;
46838 + }
46839 dput(dentry);
46840 dentry = ERR_PTR(-EEXIST);
46841 fail:
46842 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46843 }
46844 EXPORT_SYMBOL(user_path_create);
46845
46846 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46847 +{
46848 + char *tmp = getname(pathname);
46849 + struct dentry *res;
46850 + if (IS_ERR(tmp))
46851 + return ERR_CAST(tmp);
46852 + res = kern_path_create(dfd, tmp, path, is_dir);
46853 + if (IS_ERR(res))
46854 + putname(tmp);
46855 + else
46856 + *to = tmp;
46857 + return res;
46858 +}
46859 +
46860 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46861 {
46862 int error = may_create(dir, dentry);
46863 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46864 error = mnt_want_write(path.mnt);
46865 if (error)
46866 goto out_dput;
46867 +
46868 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46869 + error = -EPERM;
46870 + goto out_drop_write;
46871 + }
46872 +
46873 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46874 + error = -EACCES;
46875 + goto out_drop_write;
46876 + }
46877 +
46878 error = security_path_mknod(&path, dentry, mode, dev);
46879 if (error)
46880 goto out_drop_write;
46881 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46882 }
46883 out_drop_write:
46884 mnt_drop_write(path.mnt);
46885 +
46886 + if (!error)
46887 + gr_handle_create(dentry, path.mnt);
46888 out_dput:
46889 dput(dentry);
46890 mutex_unlock(&path.dentry->d_inode->i_mutex);
46891 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46892 error = mnt_want_write(path.mnt);
46893 if (error)
46894 goto out_dput;
46895 +
46896 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46897 + error = -EACCES;
46898 + goto out_drop_write;
46899 + }
46900 +
46901 error = security_path_mkdir(&path, dentry, mode);
46902 if (error)
46903 goto out_drop_write;
46904 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46905 out_drop_write:
46906 mnt_drop_write(path.mnt);
46907 +
46908 + if (!error)
46909 + gr_handle_create(dentry, path.mnt);
46910 out_dput:
46911 dput(dentry);
46912 mutex_unlock(&path.dentry->d_inode->i_mutex);
46913 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46914 char * name;
46915 struct dentry *dentry;
46916 struct nameidata nd;
46917 + ino_t saved_ino = 0;
46918 + dev_t saved_dev = 0;
46919
46920 error = user_path_parent(dfd, pathname, &nd, &name);
46921 if (error)
46922 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46923 error = -ENOENT;
46924 goto exit3;
46925 }
46926 +
46927 + saved_ino = dentry->d_inode->i_ino;
46928 + saved_dev = gr_get_dev_from_dentry(dentry);
46929 +
46930 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46931 + error = -EACCES;
46932 + goto exit3;
46933 + }
46934 +
46935 error = mnt_want_write(nd.path.mnt);
46936 if (error)
46937 goto exit3;
46938 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46939 if (error)
46940 goto exit4;
46941 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46942 + if (!error && (saved_dev || saved_ino))
46943 + gr_handle_delete(saved_ino, saved_dev);
46944 exit4:
46945 mnt_drop_write(nd.path.mnt);
46946 exit3:
46947 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46948 struct dentry *dentry;
46949 struct nameidata nd;
46950 struct inode *inode = NULL;
46951 + ino_t saved_ino = 0;
46952 + dev_t saved_dev = 0;
46953
46954 error = user_path_parent(dfd, pathname, &nd, &name);
46955 if (error)
46956 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46957 if (!inode)
46958 goto slashes;
46959 ihold(inode);
46960 +
46961 + if (inode->i_nlink <= 1) {
46962 + saved_ino = inode->i_ino;
46963 + saved_dev = gr_get_dev_from_dentry(dentry);
46964 + }
46965 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46966 + error = -EACCES;
46967 + goto exit2;
46968 + }
46969 +
46970 error = mnt_want_write(nd.path.mnt);
46971 if (error)
46972 goto exit2;
46973 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46974 if (error)
46975 goto exit3;
46976 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46977 + if (!error && (saved_ino || saved_dev))
46978 + gr_handle_delete(saved_ino, saved_dev);
46979 exit3:
46980 mnt_drop_write(nd.path.mnt);
46981 exit2:
46982 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46983 error = mnt_want_write(path.mnt);
46984 if (error)
46985 goto out_dput;
46986 +
46987 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46988 + error = -EACCES;
46989 + goto out_drop_write;
46990 + }
46991 +
46992 error = security_path_symlink(&path, dentry, from);
46993 if (error)
46994 goto out_drop_write;
46995 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46996 + if (!error)
46997 + gr_handle_create(dentry, path.mnt);
46998 out_drop_write:
46999 mnt_drop_write(path.mnt);
47000 out_dput:
47001 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47002 {
47003 struct dentry *new_dentry;
47004 struct path old_path, new_path;
47005 + char *to = NULL;
47006 int how = 0;
47007 int error;
47008
47009 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47010 if (error)
47011 return error;
47012
47013 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47014 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47015 error = PTR_ERR(new_dentry);
47016 if (IS_ERR(new_dentry))
47017 goto out;
47018 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47019 error = mnt_want_write(new_path.mnt);
47020 if (error)
47021 goto out_dput;
47022 +
47023 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47024 + old_path.dentry->d_inode,
47025 + old_path.dentry->d_inode->i_mode, to)) {
47026 + error = -EACCES;
47027 + goto out_drop_write;
47028 + }
47029 +
47030 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47031 + old_path.dentry, old_path.mnt, to)) {
47032 + error = -EACCES;
47033 + goto out_drop_write;
47034 + }
47035 +
47036 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47037 if (error)
47038 goto out_drop_write;
47039 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47040 + if (!error)
47041 + gr_handle_create(new_dentry, new_path.mnt);
47042 out_drop_write:
47043 mnt_drop_write(new_path.mnt);
47044 out_dput:
47045 + putname(to);
47046 dput(new_dentry);
47047 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47048 path_put(&new_path);
47049 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47050 if (new_dentry == trap)
47051 goto exit5;
47052
47053 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47054 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47055 + to);
47056 + if (error)
47057 + goto exit5;
47058 +
47059 error = mnt_want_write(oldnd.path.mnt);
47060 if (error)
47061 goto exit5;
47062 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47063 goto exit6;
47064 error = vfs_rename(old_dir->d_inode, old_dentry,
47065 new_dir->d_inode, new_dentry);
47066 + if (!error)
47067 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47068 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47069 exit6:
47070 mnt_drop_write(oldnd.path.mnt);
47071 exit5:
47072 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47073
47074 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47075 {
47076 + char tmpbuf[64];
47077 + const char *newlink;
47078 int len;
47079
47080 len = PTR_ERR(link);
47081 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47082 len = strlen(link);
47083 if (len > (unsigned) buflen)
47084 len = buflen;
47085 - if (copy_to_user(buffer, link, len))
47086 +
47087 + if (len < sizeof(tmpbuf)) {
47088 + memcpy(tmpbuf, link, len);
47089 + newlink = tmpbuf;
47090 + } else
47091 + newlink = link;
47092 +
47093 + if (copy_to_user(buffer, newlink, len))
47094 len = -EFAULT;
47095 out:
47096 return len;
47097 diff --git a/fs/namespace.c b/fs/namespace.c
47098 index e608199..9609cb9 100644
47099 --- a/fs/namespace.c
47100 +++ b/fs/namespace.c
47101 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47102 if (!(sb->s_flags & MS_RDONLY))
47103 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47104 up_write(&sb->s_umount);
47105 +
47106 + gr_log_remount(mnt->mnt_devname, retval);
47107 +
47108 return retval;
47109 }
47110
47111 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47112 br_write_unlock(vfsmount_lock);
47113 up_write(&namespace_sem);
47114 release_mounts(&umount_list);
47115 +
47116 + gr_log_unmount(mnt->mnt_devname, retval);
47117 +
47118 return retval;
47119 }
47120
47121 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47122 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47123 MS_STRICTATIME);
47124
47125 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47126 + retval = -EPERM;
47127 + goto dput_out;
47128 + }
47129 +
47130 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47131 + retval = -EPERM;
47132 + goto dput_out;
47133 + }
47134 +
47135 if (flags & MS_REMOUNT)
47136 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47137 data_page);
47138 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47139 dev_name, data_page);
47140 dput_out:
47141 path_put(&path);
47142 +
47143 + gr_log_mount(dev_name, dir_name, retval);
47144 +
47145 return retval;
47146 }
47147
47148 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47149 if (error)
47150 goto out2;
47151
47152 + if (gr_handle_chroot_pivot()) {
47153 + error = -EPERM;
47154 + goto out2;
47155 + }
47156 +
47157 get_fs_root(current->fs, &root);
47158 error = lock_mount(&old);
47159 if (error)
47160 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47161 index 32c0658..b1c2045e 100644
47162 --- a/fs/ncpfs/ncplib_kernel.h
47163 +++ b/fs/ncpfs/ncplib_kernel.h
47164 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47165 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47166 const unsigned char *, unsigned int, int);
47167 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47168 - const unsigned char *, unsigned int, int);
47169 + const unsigned char *, unsigned int, int) __size_overflow(5);
47170
47171 #define NCP_ESC ':'
47172 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47173 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47174 int ncp__io2vol(unsigned char *, unsigned int *,
47175 const unsigned char *, unsigned int, int);
47176 int ncp__vol2io(unsigned char *, unsigned int *,
47177 - const unsigned char *, unsigned int, int);
47178 + const unsigned char *, unsigned int, int) __size_overflow(5);
47179
47180 #define NCP_IO_TABLE(sb) NULL
47181 #define ncp_tolower(t, c) tolower(c)
47182 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47183 index f649fba..236bf92 100644
47184 --- a/fs/nfs/inode.c
47185 +++ b/fs/nfs/inode.c
47186 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47187 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47188 nfsi->attrtimeo_timestamp = jiffies;
47189
47190 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47191 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47192 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47193 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47194 else
47195 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47196 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47197 }
47198
47199 -static atomic_long_t nfs_attr_generation_counter;
47200 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47201
47202 static unsigned long nfs_read_attr_generation_counter(void)
47203 {
47204 - return atomic_long_read(&nfs_attr_generation_counter);
47205 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47206 }
47207
47208 unsigned long nfs_inc_attr_generation_counter(void)
47209 {
47210 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47211 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47212 }
47213
47214 void nfs_fattr_init(struct nfs_fattr *fattr)
47215 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47216 index edf6d3e..bdd1da7 100644
47217 --- a/fs/nfsd/vfs.c
47218 +++ b/fs/nfsd/vfs.c
47219 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47220 } else {
47221 oldfs = get_fs();
47222 set_fs(KERNEL_DS);
47223 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47224 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47225 set_fs(oldfs);
47226 }
47227
47228 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47229
47230 /* Write the data. */
47231 oldfs = get_fs(); set_fs(KERNEL_DS);
47232 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47233 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47234 set_fs(oldfs);
47235 if (host_err < 0)
47236 goto out_nfserr;
47237 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47238 */
47239
47240 oldfs = get_fs(); set_fs(KERNEL_DS);
47241 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47242 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47243 set_fs(oldfs);
47244
47245 if (host_err < 0)
47246 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47247 index 3568c8a..e0240d8 100644
47248 --- a/fs/notify/fanotify/fanotify_user.c
47249 +++ b/fs/notify/fanotify/fanotify_user.c
47250 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47251 goto out_close_fd;
47252
47253 ret = -EFAULT;
47254 - if (copy_to_user(buf, &fanotify_event_metadata,
47255 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47256 + copy_to_user(buf, &fanotify_event_metadata,
47257 fanotify_event_metadata.event_len))
47258 goto out_kill_access_response;
47259
47260 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47261 index ee18815..7aa5d01 100644
47262 --- a/fs/notify/notification.c
47263 +++ b/fs/notify/notification.c
47264 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47265 * get set to 0 so it will never get 'freed'
47266 */
47267 static struct fsnotify_event *q_overflow_event;
47268 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47269 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47270
47271 /**
47272 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47273 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47274 */
47275 u32 fsnotify_get_cookie(void)
47276 {
47277 - return atomic_inc_return(&fsnotify_sync_cookie);
47278 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47279 }
47280 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47281
47282 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47283 index 99e3610..02c1068 100644
47284 --- a/fs/ntfs/dir.c
47285 +++ b/fs/ntfs/dir.c
47286 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47287 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47288 ~(s64)(ndir->itype.index.block_size - 1)));
47289 /* Bounds checks. */
47290 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47291 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47292 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47293 "inode 0x%lx or driver bug.", vdir->i_ino);
47294 goto err_out;
47295 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47296 index c587e2d..3641eaa 100644
47297 --- a/fs/ntfs/file.c
47298 +++ b/fs/ntfs/file.c
47299 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47300 #endif /* NTFS_RW */
47301 };
47302
47303 -const struct file_operations ntfs_empty_file_ops = {};
47304 +const struct file_operations ntfs_empty_file_ops __read_only;
47305
47306 -const struct inode_operations ntfs_empty_inode_ops = {};
47307 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47308 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47309 index 210c352..a174f83 100644
47310 --- a/fs/ocfs2/localalloc.c
47311 +++ b/fs/ocfs2/localalloc.c
47312 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47313 goto bail;
47314 }
47315
47316 - atomic_inc(&osb->alloc_stats.moves);
47317 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47318
47319 bail:
47320 if (handle)
47321 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47322 index d355e6e..578d905 100644
47323 --- a/fs/ocfs2/ocfs2.h
47324 +++ b/fs/ocfs2/ocfs2.h
47325 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47326
47327 struct ocfs2_alloc_stats
47328 {
47329 - atomic_t moves;
47330 - atomic_t local_data;
47331 - atomic_t bitmap_data;
47332 - atomic_t bg_allocs;
47333 - atomic_t bg_extends;
47334 + atomic_unchecked_t moves;
47335 + atomic_unchecked_t local_data;
47336 + atomic_unchecked_t bitmap_data;
47337 + atomic_unchecked_t bg_allocs;
47338 + atomic_unchecked_t bg_extends;
47339 };
47340
47341 enum ocfs2_local_alloc_state
47342 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47343 index ba5d97e..c77db25 100644
47344 --- a/fs/ocfs2/suballoc.c
47345 +++ b/fs/ocfs2/suballoc.c
47346 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47347 mlog_errno(status);
47348 goto bail;
47349 }
47350 - atomic_inc(&osb->alloc_stats.bg_extends);
47351 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47352
47353 /* You should never ask for this much metadata */
47354 BUG_ON(bits_wanted >
47355 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47356 mlog_errno(status);
47357 goto bail;
47358 }
47359 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47360 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47361
47362 *suballoc_loc = res.sr_bg_blkno;
47363 *suballoc_bit_start = res.sr_bit_offset;
47364 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47365 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47366 res->sr_bits);
47367
47368 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47369 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47370
47371 BUG_ON(res->sr_bits != 1);
47372
47373 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47374 mlog_errno(status);
47375 goto bail;
47376 }
47377 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47378 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47379
47380 BUG_ON(res.sr_bits != 1);
47381
47382 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47383 cluster_start,
47384 num_clusters);
47385 if (!status)
47386 - atomic_inc(&osb->alloc_stats.local_data);
47387 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47388 } else {
47389 if (min_clusters > (osb->bitmap_cpg - 1)) {
47390 /* The only paths asking for contiguousness
47391 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47392 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47393 res.sr_bg_blkno,
47394 res.sr_bit_offset);
47395 - atomic_inc(&osb->alloc_stats.bitmap_data);
47396 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47397 *num_clusters = res.sr_bits;
47398 }
47399 }
47400 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47401 index 604e12c..8426483 100644
47402 --- a/fs/ocfs2/super.c
47403 +++ b/fs/ocfs2/super.c
47404 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47405 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47406 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47407 "Stats",
47408 - atomic_read(&osb->alloc_stats.bitmap_data),
47409 - atomic_read(&osb->alloc_stats.local_data),
47410 - atomic_read(&osb->alloc_stats.bg_allocs),
47411 - atomic_read(&osb->alloc_stats.moves),
47412 - atomic_read(&osb->alloc_stats.bg_extends));
47413 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47414 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47415 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47416 + atomic_read_unchecked(&osb->alloc_stats.moves),
47417 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47418
47419 out += snprintf(buf + out, len - out,
47420 "%10s => State: %u Descriptor: %llu Size: %u bits "
47421 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47422 spin_lock_init(&osb->osb_xattr_lock);
47423 ocfs2_init_steal_slots(osb);
47424
47425 - atomic_set(&osb->alloc_stats.moves, 0);
47426 - atomic_set(&osb->alloc_stats.local_data, 0);
47427 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47428 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47429 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47430 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47431 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47432 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47433 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47434 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47435
47436 /* Copy the blockcheck stats from the superblock probe */
47437 osb->osb_ecc_stats = *stats;
47438 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47439 index 5d22872..523db20 100644
47440 --- a/fs/ocfs2/symlink.c
47441 +++ b/fs/ocfs2/symlink.c
47442 @@ -142,7 +142,7 @@ bail:
47443
47444 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47445 {
47446 - char *link = nd_get_link(nd);
47447 + const char *link = nd_get_link(nd);
47448 if (!IS_ERR(link))
47449 kfree(link);
47450 }
47451 diff --git a/fs/open.c b/fs/open.c
47452 index 77becc0..aad7bd9 100644
47453 --- a/fs/open.c
47454 +++ b/fs/open.c
47455 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47456 error = locks_verify_truncate(inode, NULL, length);
47457 if (!error)
47458 error = security_path_truncate(&path);
47459 +
47460 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47461 + error = -EACCES;
47462 +
47463 if (!error)
47464 error = do_truncate(path.dentry, length, 0, NULL);
47465
47466 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47467 if (__mnt_is_readonly(path.mnt))
47468 res = -EROFS;
47469
47470 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47471 + res = -EACCES;
47472 +
47473 out_path_release:
47474 path_put(&path);
47475 out:
47476 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47477 if (error)
47478 goto dput_and_out;
47479
47480 + gr_log_chdir(path.dentry, path.mnt);
47481 +
47482 set_fs_pwd(current->fs, &path);
47483
47484 dput_and_out:
47485 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47486 goto out_putf;
47487
47488 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47489 +
47490 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47491 + error = -EPERM;
47492 +
47493 + if (!error)
47494 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47495 +
47496 if (!error)
47497 set_fs_pwd(current->fs, &file->f_path);
47498 out_putf:
47499 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47500 if (error)
47501 goto dput_and_out;
47502
47503 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47504 + goto dput_and_out;
47505 +
47506 set_fs_root(current->fs, &path);
47507 +
47508 + gr_handle_chroot_chdir(&path);
47509 +
47510 error = 0;
47511 dput_and_out:
47512 path_put(&path);
47513 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47514 if (error)
47515 return error;
47516 mutex_lock(&inode->i_mutex);
47517 +
47518 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47519 + error = -EACCES;
47520 + goto out_unlock;
47521 + }
47522 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47523 + error = -EACCES;
47524 + goto out_unlock;
47525 + }
47526 +
47527 error = security_path_chmod(path, mode);
47528 if (error)
47529 goto out_unlock;
47530 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47531 int error;
47532 struct iattr newattrs;
47533
47534 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47535 + return -EACCES;
47536 +
47537 newattrs.ia_valid = ATTR_CTIME;
47538 if (user != (uid_t) -1) {
47539 newattrs.ia_valid |= ATTR_UID;
47540 diff --git a/fs/pipe.c b/fs/pipe.c
47541 index a932ced..6495412 100644
47542 --- a/fs/pipe.c
47543 +++ b/fs/pipe.c
47544 @@ -420,9 +420,9 @@ redo:
47545 }
47546 if (bufs) /* More to do? */
47547 continue;
47548 - if (!pipe->writers)
47549 + if (!atomic_read(&pipe->writers))
47550 break;
47551 - if (!pipe->waiting_writers) {
47552 + if (!atomic_read(&pipe->waiting_writers)) {
47553 /* syscall merging: Usually we must not sleep
47554 * if O_NONBLOCK is set, or if we got some data.
47555 * But if a writer sleeps in kernel space, then
47556 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47557 mutex_lock(&inode->i_mutex);
47558 pipe = inode->i_pipe;
47559
47560 - if (!pipe->readers) {
47561 + if (!atomic_read(&pipe->readers)) {
47562 send_sig(SIGPIPE, current, 0);
47563 ret = -EPIPE;
47564 goto out;
47565 @@ -530,7 +530,7 @@ redo1:
47566 for (;;) {
47567 int bufs;
47568
47569 - if (!pipe->readers) {
47570 + if (!atomic_read(&pipe->readers)) {
47571 send_sig(SIGPIPE, current, 0);
47572 if (!ret)
47573 ret = -EPIPE;
47574 @@ -616,9 +616,9 @@ redo2:
47575 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47576 do_wakeup = 0;
47577 }
47578 - pipe->waiting_writers++;
47579 + atomic_inc(&pipe->waiting_writers);
47580 pipe_wait(pipe);
47581 - pipe->waiting_writers--;
47582 + atomic_dec(&pipe->waiting_writers);
47583 }
47584 out:
47585 mutex_unlock(&inode->i_mutex);
47586 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47587 mask = 0;
47588 if (filp->f_mode & FMODE_READ) {
47589 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47590 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47591 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47592 mask |= POLLHUP;
47593 }
47594
47595 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47596 * Most Unices do not set POLLERR for FIFOs but on Linux they
47597 * behave exactly like pipes for poll().
47598 */
47599 - if (!pipe->readers)
47600 + if (!atomic_read(&pipe->readers))
47601 mask |= POLLERR;
47602 }
47603
47604 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47605
47606 mutex_lock(&inode->i_mutex);
47607 pipe = inode->i_pipe;
47608 - pipe->readers -= decr;
47609 - pipe->writers -= decw;
47610 + atomic_sub(decr, &pipe->readers);
47611 + atomic_sub(decw, &pipe->writers);
47612
47613 - if (!pipe->readers && !pipe->writers) {
47614 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47615 free_pipe_info(inode);
47616 } else {
47617 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47618 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47619
47620 if (inode->i_pipe) {
47621 ret = 0;
47622 - inode->i_pipe->readers++;
47623 + atomic_inc(&inode->i_pipe->readers);
47624 }
47625
47626 mutex_unlock(&inode->i_mutex);
47627 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47628
47629 if (inode->i_pipe) {
47630 ret = 0;
47631 - inode->i_pipe->writers++;
47632 + atomic_inc(&inode->i_pipe->writers);
47633 }
47634
47635 mutex_unlock(&inode->i_mutex);
47636 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47637 if (inode->i_pipe) {
47638 ret = 0;
47639 if (filp->f_mode & FMODE_READ)
47640 - inode->i_pipe->readers++;
47641 + atomic_inc(&inode->i_pipe->readers);
47642 if (filp->f_mode & FMODE_WRITE)
47643 - inode->i_pipe->writers++;
47644 + atomic_inc(&inode->i_pipe->writers);
47645 }
47646
47647 mutex_unlock(&inode->i_mutex);
47648 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47649 inode->i_pipe = NULL;
47650 }
47651
47652 -static struct vfsmount *pipe_mnt __read_mostly;
47653 +struct vfsmount *pipe_mnt __read_mostly;
47654
47655 /*
47656 * pipefs_dname() is called from d_path().
47657 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47658 goto fail_iput;
47659 inode->i_pipe = pipe;
47660
47661 - pipe->readers = pipe->writers = 1;
47662 + atomic_set(&pipe->readers, 1);
47663 + atomic_set(&pipe->writers, 1);
47664 inode->i_fop = &rdwr_pipefifo_fops;
47665
47666 /*
47667 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47668 index 15af622..0e9f4467 100644
47669 --- a/fs/proc/Kconfig
47670 +++ b/fs/proc/Kconfig
47671 @@ -30,12 +30,12 @@ config PROC_FS
47672
47673 config PROC_KCORE
47674 bool "/proc/kcore support" if !ARM
47675 - depends on PROC_FS && MMU
47676 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47677
47678 config PROC_VMCORE
47679 bool "/proc/vmcore support"
47680 - depends on PROC_FS && CRASH_DUMP
47681 - default y
47682 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47683 + default n
47684 help
47685 Exports the dump image of crashed kernel in ELF format.
47686
47687 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47688 limited in memory.
47689
47690 config PROC_PAGE_MONITOR
47691 - default y
47692 - depends on PROC_FS && MMU
47693 + default n
47694 + depends on PROC_FS && MMU && !GRKERNSEC
47695 bool "Enable /proc page monitoring" if EXPERT
47696 help
47697 Various /proc files exist to monitor process memory utilization:
47698 diff --git a/fs/proc/array.c b/fs/proc/array.c
47699 index c602b8d..a7de642 100644
47700 --- a/fs/proc/array.c
47701 +++ b/fs/proc/array.c
47702 @@ -60,6 +60,7 @@
47703 #include <linux/tty.h>
47704 #include <linux/string.h>
47705 #include <linux/mman.h>
47706 +#include <linux/grsecurity.h>
47707 #include <linux/proc_fs.h>
47708 #include <linux/ioport.h>
47709 #include <linux/uaccess.h>
47710 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47711 seq_putc(m, '\n');
47712 }
47713
47714 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47715 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47716 +{
47717 + if (p->mm)
47718 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47719 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47720 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47721 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47722 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47723 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47724 + else
47725 + seq_printf(m, "PaX:\t-----\n");
47726 +}
47727 +#endif
47728 +
47729 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47730 struct pid *pid, struct task_struct *task)
47731 {
47732 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47733 task_cpus_allowed(m, task);
47734 cpuset_task_status_allowed(m, task);
47735 task_context_switch_counts(m, task);
47736 +
47737 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47738 + task_pax(m, task);
47739 +#endif
47740 +
47741 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47742 + task_grsec_rbac(m, task);
47743 +#endif
47744 +
47745 return 0;
47746 }
47747
47748 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47749 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47750 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47751 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47752 +#endif
47753 +
47754 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47755 struct pid *pid, struct task_struct *task, int whole)
47756 {
47757 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47758 char tcomm[sizeof(task->comm)];
47759 unsigned long flags;
47760
47761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47762 + if (current->exec_id != m->exec_id) {
47763 + gr_log_badprocpid("stat");
47764 + return 0;
47765 + }
47766 +#endif
47767 +
47768 state = *get_task_state(task);
47769 vsize = eip = esp = 0;
47770 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47771 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47772 gtime = task->gtime;
47773 }
47774
47775 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47776 + if (PAX_RAND_FLAGS(mm)) {
47777 + eip = 0;
47778 + esp = 0;
47779 + wchan = 0;
47780 + }
47781 +#endif
47782 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47783 + wchan = 0;
47784 + eip =0;
47785 + esp =0;
47786 +#endif
47787 +
47788 /* scale priority and nice values from timeslices to -20..20 */
47789 /* to make it look like a "normal" Unix priority/nice value */
47790 priority = task_prio(task);
47791 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47792 vsize,
47793 mm ? get_mm_rss(mm) : 0,
47794 rsslim,
47795 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47796 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47797 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47798 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47799 +#else
47800 mm ? (permitted ? mm->start_code : 1) : 0,
47801 mm ? (permitted ? mm->end_code : 1) : 0,
47802 (permitted && mm) ? mm->start_stack : 0,
47803 +#endif
47804 esp,
47805 eip,
47806 /* The signal information here is obsolete.
47807 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47808 struct pid *pid, struct task_struct *task)
47809 {
47810 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47811 - struct mm_struct *mm = get_task_mm(task);
47812 + struct mm_struct *mm;
47813
47814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47815 + if (current->exec_id != m->exec_id) {
47816 + gr_log_badprocpid("statm");
47817 + return 0;
47818 + }
47819 +#endif
47820 + mm = get_task_mm(task);
47821 if (mm) {
47822 size = task_statm(mm, &shared, &text, &data, &resident);
47823 mmput(mm);
47824 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47825
47826 return 0;
47827 }
47828 +
47829 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47830 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47831 +{
47832 + u32 curr_ip = 0;
47833 + unsigned long flags;
47834 +
47835 + if (lock_task_sighand(task, &flags)) {
47836 + curr_ip = task->signal->curr_ip;
47837 + unlock_task_sighand(task, &flags);
47838 + }
47839 +
47840 + return sprintf(buffer, "%pI4\n", &curr_ip);
47841 +}
47842 +#endif
47843 diff --git a/fs/proc/base.c b/fs/proc/base.c
47844 index d4548dd..d101f84 100644
47845 --- a/fs/proc/base.c
47846 +++ b/fs/proc/base.c
47847 @@ -109,6 +109,14 @@ struct pid_entry {
47848 union proc_op op;
47849 };
47850
47851 +struct getdents_callback {
47852 + struct linux_dirent __user * current_dir;
47853 + struct linux_dirent __user * previous;
47854 + struct file * file;
47855 + int count;
47856 + int error;
47857 +};
47858 +
47859 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47860 .name = (NAME), \
47861 .len = sizeof(NAME) - 1, \
47862 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47863 if (!mm->arg_end)
47864 goto out_mm; /* Shh! No looking before we're done */
47865
47866 + if (gr_acl_handle_procpidmem(task))
47867 + goto out_mm;
47868 +
47869 len = mm->arg_end - mm->arg_start;
47870
47871 if (len > PAGE_SIZE)
47872 @@ -240,12 +251,28 @@ out:
47873 return res;
47874 }
47875
47876 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47877 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47878 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47879 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47880 +#endif
47881 +
47882 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47883 {
47884 struct mm_struct *mm = mm_for_maps(task);
47885 int res = PTR_ERR(mm);
47886 if (mm && !IS_ERR(mm)) {
47887 unsigned int nwords = 0;
47888 +
47889 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47890 + /* allow if we're currently ptracing this task */
47891 + if (PAX_RAND_FLAGS(mm) &&
47892 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47893 + mmput(mm);
47894 + return 0;
47895 + }
47896 +#endif
47897 +
47898 do {
47899 nwords += 2;
47900 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47901 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47902 }
47903
47904
47905 -#ifdef CONFIG_KALLSYMS
47906 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47907 /*
47908 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47909 * Returns the resolved symbol. If that fails, simply return the address.
47910 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47911 mutex_unlock(&task->signal->cred_guard_mutex);
47912 }
47913
47914 -#ifdef CONFIG_STACKTRACE
47915 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47916
47917 #define MAX_STACK_TRACE_DEPTH 64
47918
47919 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47920 return count;
47921 }
47922
47923 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47924 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47925 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47926 {
47927 long nr;
47928 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47929 /************************************************************************/
47930
47931 /* permission checks */
47932 -static int proc_fd_access_allowed(struct inode *inode)
47933 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47934 {
47935 struct task_struct *task;
47936 int allowed = 0;
47937 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47938 */
47939 task = get_proc_task(inode);
47940 if (task) {
47941 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47942 + if (log)
47943 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47944 + else
47945 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47946 put_task_struct(task);
47947 }
47948 return allowed;
47949 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47950 struct task_struct *task,
47951 int hide_pid_min)
47952 {
47953 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47954 + return false;
47955 +
47956 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47957 + rcu_read_lock();
47958 + {
47959 + const struct cred *tmpcred = current_cred();
47960 + const struct cred *cred = __task_cred(task);
47961 +
47962 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47963 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47964 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47965 +#endif
47966 + ) {
47967 + rcu_read_unlock();
47968 + return true;
47969 + }
47970 + }
47971 + rcu_read_unlock();
47972 +
47973 + if (!pid->hide_pid)
47974 + return false;
47975 +#endif
47976 +
47977 if (pid->hide_pid < hide_pid_min)
47978 return true;
47979 if (in_group_p(pid->pid_gid))
47980 return true;
47981 +
47982 return ptrace_may_access(task, PTRACE_MODE_READ);
47983 }
47984
47985 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47986 put_task_struct(task);
47987
47988 if (!has_perms) {
47989 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47990 + {
47991 +#else
47992 if (pid->hide_pid == 2) {
47993 +#endif
47994 /*
47995 * Let's make getdents(), stat(), and open()
47996 * consistent with each other. If a process
47997 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47998 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47999 file->private_data = mm;
48000
48001 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48002 + file->f_version = current->exec_id;
48003 +#endif
48004 +
48005 return 0;
48006 }
48007
48008 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48009 ssize_t copied;
48010 char *page;
48011
48012 +#ifdef CONFIG_GRKERNSEC
48013 + if (write)
48014 + return -EPERM;
48015 +#endif
48016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48017 + if (file->f_version != current->exec_id) {
48018 + gr_log_badprocpid("mem");
48019 + return 0;
48020 + }
48021 +#endif
48022 +
48023 if (!mm)
48024 return 0;
48025
48026 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48027 if (!task)
48028 goto out_no_task;
48029
48030 + if (gr_acl_handle_procpidmem(task))
48031 + goto out;
48032 +
48033 ret = -ENOMEM;
48034 page = (char *)__get_free_page(GFP_TEMPORARY);
48035 if (!page)
48036 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48037 path_put(&nd->path);
48038
48039 /* Are we allowed to snoop on the tasks file descriptors? */
48040 - if (!proc_fd_access_allowed(inode))
48041 + if (!proc_fd_access_allowed(inode, 0))
48042 goto out;
48043
48044 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48045 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48046 struct path path;
48047
48048 /* Are we allowed to snoop on the tasks file descriptors? */
48049 - if (!proc_fd_access_allowed(inode))
48050 - goto out;
48051 + /* logging this is needed for learning on chromium to work properly,
48052 + but we don't want to flood the logs from 'ps' which does a readlink
48053 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48054 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48055 + */
48056 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48057 + if (!proc_fd_access_allowed(inode,0))
48058 + goto out;
48059 + } else {
48060 + if (!proc_fd_access_allowed(inode,1))
48061 + goto out;
48062 + }
48063
48064 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48065 if (error)
48066 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48067 rcu_read_lock();
48068 cred = __task_cred(task);
48069 inode->i_uid = cred->euid;
48070 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48071 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48072 +#else
48073 inode->i_gid = cred->egid;
48074 +#endif
48075 rcu_read_unlock();
48076 }
48077 security_task_to_inode(task, inode);
48078 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48079 return -ENOENT;
48080 }
48081 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48082 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48083 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48084 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48085 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48086 +#endif
48087 task_dumpable(task)) {
48088 cred = __task_cred(task);
48089 stat->uid = cred->euid;
48090 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48091 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48092 +#else
48093 stat->gid = cred->egid;
48094 +#endif
48095 }
48096 }
48097 rcu_read_unlock();
48098 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48099
48100 if (task) {
48101 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48102 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48103 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48104 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48105 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48106 +#endif
48107 task_dumpable(task)) {
48108 rcu_read_lock();
48109 cred = __task_cred(task);
48110 inode->i_uid = cred->euid;
48111 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48112 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48113 +#else
48114 inode->i_gid = cred->egid;
48115 +#endif
48116 rcu_read_unlock();
48117 } else {
48118 inode->i_uid = 0;
48119 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48120 int fd = proc_fd(inode);
48121
48122 if (task) {
48123 - files = get_files_struct(task);
48124 + if (!gr_acl_handle_procpidmem(task))
48125 + files = get_files_struct(task);
48126 put_task_struct(task);
48127 }
48128 if (files) {
48129 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48130 */
48131 static int proc_fd_permission(struct inode *inode, int mask)
48132 {
48133 + struct task_struct *task;
48134 int rv = generic_permission(inode, mask);
48135 - if (rv == 0)
48136 - return 0;
48137 +
48138 if (task_pid(current) == proc_pid(inode))
48139 rv = 0;
48140 +
48141 + task = get_proc_task(inode);
48142 + if (task == NULL)
48143 + return rv;
48144 +
48145 + if (gr_acl_handle_procpidmem(task))
48146 + rv = -EACCES;
48147 +
48148 + put_task_struct(task);
48149 +
48150 return rv;
48151 }
48152
48153 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48154 if (!task)
48155 goto out_no_task;
48156
48157 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48158 + goto out;
48159 +
48160 /*
48161 * Yes, it does not scale. And it should not. Don't add
48162 * new entries into /proc/<tgid>/ without very good reasons.
48163 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48164 if (!task)
48165 goto out_no_task;
48166
48167 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48168 + goto out;
48169 +
48170 ret = 0;
48171 i = filp->f_pos;
48172 switch (i) {
48173 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48174 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48175 void *cookie)
48176 {
48177 - char *s = nd_get_link(nd);
48178 + const char *s = nd_get_link(nd);
48179 if (!IS_ERR(s))
48180 __putname(s);
48181 }
48182 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48183 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48184 #endif
48185 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48186 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48187 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48188 INF("syscall", S_IRUGO, proc_pid_syscall),
48189 #endif
48190 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48191 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48192 #ifdef CONFIG_SECURITY
48193 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48194 #endif
48195 -#ifdef CONFIG_KALLSYMS
48196 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48197 INF("wchan", S_IRUGO, proc_pid_wchan),
48198 #endif
48199 -#ifdef CONFIG_STACKTRACE
48200 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48201 ONE("stack", S_IRUGO, proc_pid_stack),
48202 #endif
48203 #ifdef CONFIG_SCHEDSTATS
48204 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48205 #ifdef CONFIG_HARDWALL
48206 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48207 #endif
48208 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48209 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48210 +#endif
48211 };
48212
48213 static int proc_tgid_base_readdir(struct file * filp,
48214 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48215 if (!inode)
48216 goto out;
48217
48218 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48219 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48220 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48221 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48222 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48223 +#else
48224 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48225 +#endif
48226 inode->i_op = &proc_tgid_base_inode_operations;
48227 inode->i_fop = &proc_tgid_base_operations;
48228 inode->i_flags|=S_IMMUTABLE;
48229 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48230 if (!task)
48231 goto out;
48232
48233 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48234 + goto out_put_task;
48235 +
48236 result = proc_pid_instantiate(dir, dentry, task, NULL);
48237 +out_put_task:
48238 put_task_struct(task);
48239 out:
48240 return result;
48241 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48242 static int fake_filldir(void *buf, const char *name, int namelen,
48243 loff_t offset, u64 ino, unsigned d_type)
48244 {
48245 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48246 + __buf->error = -EINVAL;
48247 return 0;
48248 }
48249
48250 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48251 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48252 #endif
48253 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48254 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48255 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48256 INF("syscall", S_IRUGO, proc_pid_syscall),
48257 #endif
48258 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48259 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48260 #ifdef CONFIG_SECURITY
48261 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48262 #endif
48263 -#ifdef CONFIG_KALLSYMS
48264 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48265 INF("wchan", S_IRUGO, proc_pid_wchan),
48266 #endif
48267 -#ifdef CONFIG_STACKTRACE
48268 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48269 ONE("stack", S_IRUGO, proc_pid_stack),
48270 #endif
48271 #ifdef CONFIG_SCHEDSTATS
48272 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48273 index 82676e3..5f8518a 100644
48274 --- a/fs/proc/cmdline.c
48275 +++ b/fs/proc/cmdline.c
48276 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48277
48278 static int __init proc_cmdline_init(void)
48279 {
48280 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48281 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48282 +#else
48283 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48284 +#endif
48285 return 0;
48286 }
48287 module_init(proc_cmdline_init);
48288 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48289 index b143471..bb105e5 100644
48290 --- a/fs/proc/devices.c
48291 +++ b/fs/proc/devices.c
48292 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48293
48294 static int __init proc_devices_init(void)
48295 {
48296 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48297 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48298 +#else
48299 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48300 +#endif
48301 return 0;
48302 }
48303 module_init(proc_devices_init);
48304 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48305 index 84fd323..f698a32 100644
48306 --- a/fs/proc/inode.c
48307 +++ b/fs/proc/inode.c
48308 @@ -21,12 +21,18 @@
48309 #include <linux/seq_file.h>
48310 #include <linux/slab.h>
48311 #include <linux/mount.h>
48312 +#include <linux/grsecurity.h>
48313
48314 #include <asm/system.h>
48315 #include <asm/uaccess.h>
48316
48317 #include "internal.h"
48318
48319 +#ifdef CONFIG_PROC_SYSCTL
48320 +extern const struct inode_operations proc_sys_inode_operations;
48321 +extern const struct inode_operations proc_sys_dir_operations;
48322 +#endif
48323 +
48324 static void proc_evict_inode(struct inode *inode)
48325 {
48326 struct proc_dir_entry *de;
48327 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48328 ns_ops = PROC_I(inode)->ns_ops;
48329 if (ns_ops && ns_ops->put)
48330 ns_ops->put(PROC_I(inode)->ns);
48331 +
48332 +#ifdef CONFIG_PROC_SYSCTL
48333 + if (inode->i_op == &proc_sys_inode_operations ||
48334 + inode->i_op == &proc_sys_dir_operations)
48335 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48336 +#endif
48337 +
48338 }
48339
48340 static struct kmem_cache * proc_inode_cachep;
48341 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48342 if (de->mode) {
48343 inode->i_mode = de->mode;
48344 inode->i_uid = de->uid;
48345 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48346 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48347 +#else
48348 inode->i_gid = de->gid;
48349 +#endif
48350 }
48351 if (de->size)
48352 inode->i_size = de->size;
48353 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48354 index 2925775..4f08fae 100644
48355 --- a/fs/proc/internal.h
48356 +++ b/fs/proc/internal.h
48357 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48358 struct pid *pid, struct task_struct *task);
48359 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48360 struct pid *pid, struct task_struct *task);
48361 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48362 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48363 +#endif
48364 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48365
48366 extern const struct file_operations proc_maps_operations;
48367 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48368 index d245cb2..f4e8498 100644
48369 --- a/fs/proc/kcore.c
48370 +++ b/fs/proc/kcore.c
48371 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48372 * the addresses in the elf_phdr on our list.
48373 */
48374 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48375 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48376 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48377 + if (tsz > buflen)
48378 tsz = buflen;
48379 -
48380 +
48381 while (buflen) {
48382 struct kcore_list *m;
48383
48384 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48385 kfree(elf_buf);
48386 } else {
48387 if (kern_addr_valid(start)) {
48388 - unsigned long n;
48389 + char *elf_buf;
48390 + mm_segment_t oldfs;
48391
48392 - n = copy_to_user(buffer, (char *)start, tsz);
48393 - /*
48394 - * We cannot distingush between fault on source
48395 - * and fault on destination. When this happens
48396 - * we clear too and hope it will trigger the
48397 - * EFAULT again.
48398 - */
48399 - if (n) {
48400 - if (clear_user(buffer + tsz - n,
48401 - n))
48402 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48403 + if (!elf_buf)
48404 + return -ENOMEM;
48405 + oldfs = get_fs();
48406 + set_fs(KERNEL_DS);
48407 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48408 + set_fs(oldfs);
48409 + if (copy_to_user(buffer, elf_buf, tsz)) {
48410 + kfree(elf_buf);
48411 return -EFAULT;
48412 + }
48413 }
48414 + set_fs(oldfs);
48415 + kfree(elf_buf);
48416 } else {
48417 if (clear_user(buffer, tsz))
48418 return -EFAULT;
48419 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48420
48421 static int open_kcore(struct inode *inode, struct file *filp)
48422 {
48423 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48424 + return -EPERM;
48425 +#endif
48426 if (!capable(CAP_SYS_RAWIO))
48427 return -EPERM;
48428 if (kcore_need_update)
48429 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48430 index 80e4645..53e5fcf 100644
48431 --- a/fs/proc/meminfo.c
48432 +++ b/fs/proc/meminfo.c
48433 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48434 vmi.used >> 10,
48435 vmi.largest_chunk >> 10
48436 #ifdef CONFIG_MEMORY_FAILURE
48437 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48438 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48439 #endif
48440 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48441 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48442 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48443 index b1822dd..df622cb 100644
48444 --- a/fs/proc/nommu.c
48445 +++ b/fs/proc/nommu.c
48446 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48447 if (len < 1)
48448 len = 1;
48449 seq_printf(m, "%*c", len, ' ');
48450 - seq_path(m, &file->f_path, "");
48451 + seq_path(m, &file->f_path, "\n\\");
48452 }
48453
48454 seq_putc(m, '\n');
48455 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48456 index 06e1cc1..177cd98 100644
48457 --- a/fs/proc/proc_net.c
48458 +++ b/fs/proc/proc_net.c
48459 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48460 struct task_struct *task;
48461 struct nsproxy *ns;
48462 struct net *net = NULL;
48463 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48464 + const struct cred *cred = current_cred();
48465 +#endif
48466 +
48467 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48468 + if (cred->fsuid)
48469 + return net;
48470 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48471 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48472 + return net;
48473 +#endif
48474
48475 rcu_read_lock();
48476 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48477 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48478 index 53c3bce..10ad159 100644
48479 --- a/fs/proc/proc_sysctl.c
48480 +++ b/fs/proc/proc_sysctl.c
48481 @@ -9,11 +9,13 @@
48482 #include <linux/namei.h>
48483 #include "internal.h"
48484
48485 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48486 +
48487 static const struct dentry_operations proc_sys_dentry_operations;
48488 static const struct file_operations proc_sys_file_operations;
48489 -static const struct inode_operations proc_sys_inode_operations;
48490 +const struct inode_operations proc_sys_inode_operations;
48491 static const struct file_operations proc_sys_dir_file_operations;
48492 -static const struct inode_operations proc_sys_dir_operations;
48493 +const struct inode_operations proc_sys_dir_operations;
48494
48495 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48496 {
48497 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48498
48499 err = NULL;
48500 d_set_d_op(dentry, &proc_sys_dentry_operations);
48501 +
48502 + gr_handle_proc_create(dentry, inode);
48503 +
48504 d_add(dentry, inode);
48505
48506 + if (gr_handle_sysctl(p, MAY_EXEC))
48507 + err = ERR_PTR(-ENOENT);
48508 +
48509 out:
48510 sysctl_head_finish(head);
48511 return err;
48512 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48513 if (!table->proc_handler)
48514 goto out;
48515
48516 +#ifdef CONFIG_GRKERNSEC
48517 + error = -EPERM;
48518 + if (write && !capable(CAP_SYS_ADMIN))
48519 + goto out;
48520 +#endif
48521 +
48522 /* careful: calling conventions are nasty here */
48523 res = count;
48524 error = table->proc_handler(table, write, buf, &res, ppos);
48525 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48526 return -ENOMEM;
48527 } else {
48528 d_set_d_op(child, &proc_sys_dentry_operations);
48529 +
48530 + gr_handle_proc_create(child, inode);
48531 +
48532 d_add(child, inode);
48533 }
48534 } else {
48535 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48536 if (*pos < file->f_pos)
48537 continue;
48538
48539 + if (gr_handle_sysctl(table, 0))
48540 + continue;
48541 +
48542 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48543 if (res)
48544 return res;
48545 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48546 if (IS_ERR(head))
48547 return PTR_ERR(head);
48548
48549 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48550 + return -ENOENT;
48551 +
48552 generic_fillattr(inode, stat);
48553 if (table)
48554 stat->mode = (stat->mode & S_IFMT) | table->mode;
48555 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48556 .llseek = generic_file_llseek,
48557 };
48558
48559 -static const struct inode_operations proc_sys_inode_operations = {
48560 +const struct inode_operations proc_sys_inode_operations = {
48561 .permission = proc_sys_permission,
48562 .setattr = proc_sys_setattr,
48563 .getattr = proc_sys_getattr,
48564 };
48565
48566 -static const struct inode_operations proc_sys_dir_operations = {
48567 +const struct inode_operations proc_sys_dir_operations = {
48568 .lookup = proc_sys_lookup,
48569 .permission = proc_sys_permission,
48570 .setattr = proc_sys_setattr,
48571 diff --git a/fs/proc/root.c b/fs/proc/root.c
48572 index 46a15d8..335631a 100644
48573 --- a/fs/proc/root.c
48574 +++ b/fs/proc/root.c
48575 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48576 #ifdef CONFIG_PROC_DEVICETREE
48577 proc_device_tree_init();
48578 #endif
48579 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48580 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48581 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48582 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48583 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48584 +#endif
48585 +#else
48586 proc_mkdir("bus", NULL);
48587 +#endif
48588 proc_sys_init();
48589 }
48590
48591 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48592 index 3efa725..23c925b 100644
48593 --- a/fs/proc/task_mmu.c
48594 +++ b/fs/proc/task_mmu.c
48595 @@ -11,6 +11,7 @@
48596 #include <linux/rmap.h>
48597 #include <linux/swap.h>
48598 #include <linux/swapops.h>
48599 +#include <linux/grsecurity.h>
48600
48601 #include <asm/elf.h>
48602 #include <asm/uaccess.h>
48603 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48604 "VmExe:\t%8lu kB\n"
48605 "VmLib:\t%8lu kB\n"
48606 "VmPTE:\t%8lu kB\n"
48607 - "VmSwap:\t%8lu kB\n",
48608 - hiwater_vm << (PAGE_SHIFT-10),
48609 + "VmSwap:\t%8lu kB\n"
48610 +
48611 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48612 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48613 +#endif
48614 +
48615 + ,hiwater_vm << (PAGE_SHIFT-10),
48616 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48617 mm->locked_vm << (PAGE_SHIFT-10),
48618 mm->pinned_vm << (PAGE_SHIFT-10),
48619 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48620 data << (PAGE_SHIFT-10),
48621 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48622 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48623 - swap << (PAGE_SHIFT-10));
48624 + swap << (PAGE_SHIFT-10)
48625 +
48626 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48627 + , mm->context.user_cs_base, mm->context.user_cs_limit
48628 +#endif
48629 +
48630 + );
48631 }
48632
48633 unsigned long task_vsize(struct mm_struct *mm)
48634 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48635 return ret;
48636 }
48637
48638 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48639 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48640 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48641 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48642 +#endif
48643 +
48644 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48645 {
48646 struct mm_struct *mm = vma->vm_mm;
48647 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48648 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48649 }
48650
48651 - /* We don't show the stack guard page in /proc/maps */
48652 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48653 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48654 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48655 +#else
48656 start = vma->vm_start;
48657 - if (stack_guard_page_start(vma, start))
48658 - start += PAGE_SIZE;
48659 end = vma->vm_end;
48660 - if (stack_guard_page_end(vma, end))
48661 - end -= PAGE_SIZE;
48662 +#endif
48663
48664 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48665 start,
48666 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48667 flags & VM_WRITE ? 'w' : '-',
48668 flags & VM_EXEC ? 'x' : '-',
48669 flags & VM_MAYSHARE ? 's' : 'p',
48670 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48671 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48672 +#else
48673 pgoff,
48674 +#endif
48675 MAJOR(dev), MINOR(dev), ino, &len);
48676
48677 /*
48678 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48679 */
48680 if (file) {
48681 pad_len_spaces(m, len);
48682 - seq_path(m, &file->f_path, "\n");
48683 + seq_path(m, &file->f_path, "\n\\");
48684 } else {
48685 const char *name = arch_vma_name(vma);
48686 if (!name) {
48687 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48688 if (vma->vm_start <= mm->brk &&
48689 vma->vm_end >= mm->start_brk) {
48690 name = "[heap]";
48691 - } else if (vma->vm_start <= mm->start_stack &&
48692 - vma->vm_end >= mm->start_stack) {
48693 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48694 + (vma->vm_start <= mm->start_stack &&
48695 + vma->vm_end >= mm->start_stack)) {
48696 name = "[stack]";
48697 }
48698 } else {
48699 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48700 struct proc_maps_private *priv = m->private;
48701 struct task_struct *task = priv->task;
48702
48703 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48704 + if (current->exec_id != m->exec_id) {
48705 + gr_log_badprocpid("maps");
48706 + return 0;
48707 + }
48708 +#endif
48709 +
48710 show_map_vma(m, vma);
48711
48712 if (m->count < m->size) /* vma is copied successfully */
48713 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48714 .private = &mss,
48715 };
48716
48717 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48718 + if (current->exec_id != m->exec_id) {
48719 + gr_log_badprocpid("smaps");
48720 + return 0;
48721 + }
48722 +#endif
48723 memset(&mss, 0, sizeof mss);
48724 - mss.vma = vma;
48725 - /* mmap_sem is held in m_start */
48726 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48727 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48728 -
48729 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48730 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48731 +#endif
48732 + mss.vma = vma;
48733 + /* mmap_sem is held in m_start */
48734 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48735 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48736 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48737 + }
48738 +#endif
48739 show_map_vma(m, vma);
48740
48741 seq_printf(m,
48742 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48743 "KernelPageSize: %8lu kB\n"
48744 "MMUPageSize: %8lu kB\n"
48745 "Locked: %8lu kB\n",
48746 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48747 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48748 +#else
48749 (vma->vm_end - vma->vm_start) >> 10,
48750 +#endif
48751 mss.resident >> 10,
48752 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48753 mss.shared_clean >> 10,
48754 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48755 int n;
48756 char buffer[50];
48757
48758 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48759 + if (current->exec_id != m->exec_id) {
48760 + gr_log_badprocpid("numa_maps");
48761 + return 0;
48762 + }
48763 +#endif
48764 +
48765 if (!mm)
48766 return 0;
48767
48768 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48769 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48770 mpol_cond_put(pol);
48771
48772 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48773 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48774 +#else
48775 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48776 +#endif
48777
48778 if (file) {
48779 seq_printf(m, " file=");
48780 - seq_path(m, &file->f_path, "\n\t= ");
48781 + seq_path(m, &file->f_path, "\n\t\\= ");
48782 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48783 seq_printf(m, " heap");
48784 } else if (vma->vm_start <= mm->start_stack &&
48785 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48786 index 980de54..2a4db5f 100644
48787 --- a/fs/proc/task_nommu.c
48788 +++ b/fs/proc/task_nommu.c
48789 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48790 else
48791 bytes += kobjsize(mm);
48792
48793 - if (current->fs && current->fs->users > 1)
48794 + if (current->fs && atomic_read(&current->fs->users) > 1)
48795 sbytes += kobjsize(current->fs);
48796 else
48797 bytes += kobjsize(current->fs);
48798 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48799
48800 if (file) {
48801 pad_len_spaces(m, len);
48802 - seq_path(m, &file->f_path, "");
48803 + seq_path(m, &file->f_path, "\n\\");
48804 } else if (mm) {
48805 if (vma->vm_start <= mm->start_stack &&
48806 vma->vm_end >= mm->start_stack) {
48807 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48808 index d67908b..d13f6a6 100644
48809 --- a/fs/quota/netlink.c
48810 +++ b/fs/quota/netlink.c
48811 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48812 void quota_send_warning(short type, unsigned int id, dev_t dev,
48813 const char warntype)
48814 {
48815 - static atomic_t seq;
48816 + static atomic_unchecked_t seq;
48817 struct sk_buff *skb;
48818 void *msg_head;
48819 int ret;
48820 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48821 "VFS: Not enough memory to send quota warning.\n");
48822 return;
48823 }
48824 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48825 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48826 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48827 if (!msg_head) {
48828 printk(KERN_ERR
48829 diff --git a/fs/readdir.c b/fs/readdir.c
48830 index 356f715..c918d38 100644
48831 --- a/fs/readdir.c
48832 +++ b/fs/readdir.c
48833 @@ -17,6 +17,7 @@
48834 #include <linux/security.h>
48835 #include <linux/syscalls.h>
48836 #include <linux/unistd.h>
48837 +#include <linux/namei.h>
48838
48839 #include <asm/uaccess.h>
48840
48841 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48842
48843 struct readdir_callback {
48844 struct old_linux_dirent __user * dirent;
48845 + struct file * file;
48846 int result;
48847 };
48848
48849 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48850 buf->result = -EOVERFLOW;
48851 return -EOVERFLOW;
48852 }
48853 +
48854 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48855 + return 0;
48856 +
48857 buf->result++;
48858 dirent = buf->dirent;
48859 if (!access_ok(VERIFY_WRITE, dirent,
48860 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48861
48862 buf.result = 0;
48863 buf.dirent = dirent;
48864 + buf.file = file;
48865
48866 error = vfs_readdir(file, fillonedir, &buf);
48867 if (buf.result)
48868 @@ -142,6 +149,7 @@ struct linux_dirent {
48869 struct getdents_callback {
48870 struct linux_dirent __user * current_dir;
48871 struct linux_dirent __user * previous;
48872 + struct file * file;
48873 int count;
48874 int error;
48875 };
48876 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48877 buf->error = -EOVERFLOW;
48878 return -EOVERFLOW;
48879 }
48880 +
48881 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48882 + return 0;
48883 +
48884 dirent = buf->previous;
48885 if (dirent) {
48886 if (__put_user(offset, &dirent->d_off))
48887 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48888 buf.previous = NULL;
48889 buf.count = count;
48890 buf.error = 0;
48891 + buf.file = file;
48892
48893 error = vfs_readdir(file, filldir, &buf);
48894 if (error >= 0)
48895 @@ -229,6 +242,7 @@ out:
48896 struct getdents_callback64 {
48897 struct linux_dirent64 __user * current_dir;
48898 struct linux_dirent64 __user * previous;
48899 + struct file *file;
48900 int count;
48901 int error;
48902 };
48903 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48904 buf->error = -EINVAL; /* only used if we fail.. */
48905 if (reclen > buf->count)
48906 return -EINVAL;
48907 +
48908 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48909 + return 0;
48910 +
48911 dirent = buf->previous;
48912 if (dirent) {
48913 if (__put_user(offset, &dirent->d_off))
48914 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48915
48916 buf.current_dir = dirent;
48917 buf.previous = NULL;
48918 + buf.file = file;
48919 buf.count = count;
48920 buf.error = 0;
48921
48922 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48923 error = buf.error;
48924 lastdirent = buf.previous;
48925 if (lastdirent) {
48926 - typeof(lastdirent->d_off) d_off = file->f_pos;
48927 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48928 if (__put_user(d_off, &lastdirent->d_off))
48929 error = -EFAULT;
48930 else
48931 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48932 index 60c0804..d814f98 100644
48933 --- a/fs/reiserfs/do_balan.c
48934 +++ b/fs/reiserfs/do_balan.c
48935 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48936 return;
48937 }
48938
48939 - atomic_inc(&(fs_generation(tb->tb_sb)));
48940 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48941 do_balance_starts(tb);
48942
48943 /* balance leaf returns 0 except if combining L R and S into
48944 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48945 index 7a99811..a7c96c4 100644
48946 --- a/fs/reiserfs/procfs.c
48947 +++ b/fs/reiserfs/procfs.c
48948 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48949 "SMALL_TAILS " : "NO_TAILS ",
48950 replay_only(sb) ? "REPLAY_ONLY " : "",
48951 convert_reiserfs(sb) ? "CONV " : "",
48952 - atomic_read(&r->s_generation_counter),
48953 + atomic_read_unchecked(&r->s_generation_counter),
48954 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48955 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48956 SF(s_good_search_by_key_reada), SF(s_bmaps),
48957 diff --git a/fs/select.c b/fs/select.c
48958 index e782258..3b4b44c 100644
48959 --- a/fs/select.c
48960 +++ b/fs/select.c
48961 @@ -20,6 +20,7 @@
48962 #include <linux/module.h>
48963 #include <linux/slab.h>
48964 #include <linux/poll.h>
48965 +#include <linux/security.h>
48966 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48967 #include <linux/file.h>
48968 #include <linux/fdtable.h>
48969 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48970 struct poll_list *walk = head;
48971 unsigned long todo = nfds;
48972
48973 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48974 if (nfds > rlimit(RLIMIT_NOFILE))
48975 return -EINVAL;
48976
48977 diff --git a/fs/seq_file.c b/fs/seq_file.c
48978 index 4023d6b..ab46c6a 100644
48979 --- a/fs/seq_file.c
48980 +++ b/fs/seq_file.c
48981 @@ -9,6 +9,7 @@
48982 #include <linux/module.h>
48983 #include <linux/seq_file.h>
48984 #include <linux/slab.h>
48985 +#include <linux/sched.h>
48986
48987 #include <asm/uaccess.h>
48988 #include <asm/page.h>
48989 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48990 memset(p, 0, sizeof(*p));
48991 mutex_init(&p->lock);
48992 p->op = op;
48993 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48994 + p->exec_id = current->exec_id;
48995 +#endif
48996
48997 /*
48998 * Wrappers around seq_open(e.g. swaps_open) need to be
48999 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49000 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49001 void *data)
49002 {
49003 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49004 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49005 int res = -ENOMEM;
49006
49007 if (op) {
49008 diff --git a/fs/splice.c b/fs/splice.c
49009 index 1ec0493..d6ab5c2 100644
49010 --- a/fs/splice.c
49011 +++ b/fs/splice.c
49012 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49013 pipe_lock(pipe);
49014
49015 for (;;) {
49016 - if (!pipe->readers) {
49017 + if (!atomic_read(&pipe->readers)) {
49018 send_sig(SIGPIPE, current, 0);
49019 if (!ret)
49020 ret = -EPIPE;
49021 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49022 do_wakeup = 0;
49023 }
49024
49025 - pipe->waiting_writers++;
49026 + atomic_inc(&pipe->waiting_writers);
49027 pipe_wait(pipe);
49028 - pipe->waiting_writers--;
49029 + atomic_dec(&pipe->waiting_writers);
49030 }
49031
49032 pipe_unlock(pipe);
49033 @@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49034 old_fs = get_fs();
49035 set_fs(get_ds());
49036 /* The cast to a user pointer is valid due to the set_fs() */
49037 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49038 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49039 set_fs(old_fs);
49040
49041 return res;
49042 @@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49043 old_fs = get_fs();
49044 set_fs(get_ds());
49045 /* The cast to a user pointer is valid due to the set_fs() */
49046 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49047 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49048 set_fs(old_fs);
49049
49050 return res;
49051 @@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49052 goto err;
49053
49054 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49055 - vec[i].iov_base = (void __user *) page_address(page);
49056 + vec[i].iov_base = (void __force_user *) page_address(page);
49057 vec[i].iov_len = this_len;
49058 spd.pages[i] = page;
49059 spd.nr_pages++;
49060 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49061 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49062 {
49063 while (!pipe->nrbufs) {
49064 - if (!pipe->writers)
49065 + if (!atomic_read(&pipe->writers))
49066 return 0;
49067
49068 - if (!pipe->waiting_writers && sd->num_spliced)
49069 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49070 return 0;
49071
49072 if (sd->flags & SPLICE_F_NONBLOCK)
49073 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49074 * out of the pipe right after the splice_to_pipe(). So set
49075 * PIPE_READERS appropriately.
49076 */
49077 - pipe->readers = 1;
49078 + atomic_set(&pipe->readers, 1);
49079
49080 current->splice_pipe = pipe;
49081 }
49082 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49083 ret = -ERESTARTSYS;
49084 break;
49085 }
49086 - if (!pipe->writers)
49087 + if (!atomic_read(&pipe->writers))
49088 break;
49089 - if (!pipe->waiting_writers) {
49090 + if (!atomic_read(&pipe->waiting_writers)) {
49091 if (flags & SPLICE_F_NONBLOCK) {
49092 ret = -EAGAIN;
49093 break;
49094 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49095 pipe_lock(pipe);
49096
49097 while (pipe->nrbufs >= pipe->buffers) {
49098 - if (!pipe->readers) {
49099 + if (!atomic_read(&pipe->readers)) {
49100 send_sig(SIGPIPE, current, 0);
49101 ret = -EPIPE;
49102 break;
49103 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49104 ret = -ERESTARTSYS;
49105 break;
49106 }
49107 - pipe->waiting_writers++;
49108 + atomic_inc(&pipe->waiting_writers);
49109 pipe_wait(pipe);
49110 - pipe->waiting_writers--;
49111 + atomic_dec(&pipe->waiting_writers);
49112 }
49113
49114 pipe_unlock(pipe);
49115 @@ -1818,14 +1818,14 @@ retry:
49116 pipe_double_lock(ipipe, opipe);
49117
49118 do {
49119 - if (!opipe->readers) {
49120 + if (!atomic_read(&opipe->readers)) {
49121 send_sig(SIGPIPE, current, 0);
49122 if (!ret)
49123 ret = -EPIPE;
49124 break;
49125 }
49126
49127 - if (!ipipe->nrbufs && !ipipe->writers)
49128 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49129 break;
49130
49131 /*
49132 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49133 pipe_double_lock(ipipe, opipe);
49134
49135 do {
49136 - if (!opipe->readers) {
49137 + if (!atomic_read(&opipe->readers)) {
49138 send_sig(SIGPIPE, current, 0);
49139 if (!ret)
49140 ret = -EPIPE;
49141 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49142 * return EAGAIN if we have the potential of some data in the
49143 * future, otherwise just return 0
49144 */
49145 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49146 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49147 ret = -EAGAIN;
49148
49149 pipe_unlock(ipipe);
49150 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49151 index a475983..9c6a1f0 100644
49152 --- a/fs/sysfs/bin.c
49153 +++ b/fs/sysfs/bin.c
49154 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49155 }
49156
49157 static ssize_t
49158 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49159 +static ssize_t
49160 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49161 {
49162 struct bin_buffer *bb = file->private_data;
49163 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49164 index 7fdf6a7..e6cd8ad 100644
49165 --- a/fs/sysfs/dir.c
49166 +++ b/fs/sysfs/dir.c
49167 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49168 struct sysfs_dirent *sd;
49169 int rc;
49170
49171 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49172 + const char *parent_name = parent_sd->s_name;
49173 +
49174 + mode = S_IFDIR | S_IRWXU;
49175 +
49176 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49177 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49178 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49179 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49180 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49181 +#endif
49182 +
49183 /* allocate */
49184 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49185 if (!sd)
49186 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49187 index 00012e3..8392349 100644
49188 --- a/fs/sysfs/file.c
49189 +++ b/fs/sysfs/file.c
49190 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49191
49192 struct sysfs_open_dirent {
49193 atomic_t refcnt;
49194 - atomic_t event;
49195 + atomic_unchecked_t event;
49196 wait_queue_head_t poll;
49197 struct list_head buffers; /* goes through sysfs_buffer.list */
49198 };
49199 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49200 if (!sysfs_get_active(attr_sd))
49201 return -ENODEV;
49202
49203 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49204 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49205 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49206
49207 sysfs_put_active(attr_sd);
49208 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49209 return -ENOMEM;
49210
49211 atomic_set(&new_od->refcnt, 0);
49212 - atomic_set(&new_od->event, 1);
49213 + atomic_set_unchecked(&new_od->event, 1);
49214 init_waitqueue_head(&new_od->poll);
49215 INIT_LIST_HEAD(&new_od->buffers);
49216 goto retry;
49217 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49218
49219 sysfs_put_active(attr_sd);
49220
49221 - if (buffer->event != atomic_read(&od->event))
49222 + if (buffer->event != atomic_read_unchecked(&od->event))
49223 goto trigger;
49224
49225 return DEFAULT_POLLMASK;
49226 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49227
49228 od = sd->s_attr.open;
49229 if (od) {
49230 - atomic_inc(&od->event);
49231 + atomic_inc_unchecked(&od->event);
49232 wake_up_interruptible(&od->poll);
49233 }
49234
49235 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49236 index a7ac78f..02158e1 100644
49237 --- a/fs/sysfs/symlink.c
49238 +++ b/fs/sysfs/symlink.c
49239 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49240
49241 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49242 {
49243 - char *page = nd_get_link(nd);
49244 + const char *page = nd_get_link(nd);
49245 if (!IS_ERR(page))
49246 free_page((unsigned long)page);
49247 }
49248 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49249 index f922cba..062fb02 100644
49250 --- a/fs/ubifs/debug.c
49251 +++ b/fs/ubifs/debug.c
49252 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49253 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49254 * in case of failure.
49255 */
49256 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49257 static int interpret_user_input(const char __user *u, size_t count)
49258 {
49259 size_t buf_size;
49260 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49261 }
49262
49263 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49264 + size_t count, loff_t *ppos) __size_overflow(3);
49265 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49266 size_t count, loff_t *ppos)
49267 {
49268 struct ubifs_info *c = file->private_data;
49269 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49270 index c175b4d..8f36a16 100644
49271 --- a/fs/udf/misc.c
49272 +++ b/fs/udf/misc.c
49273 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49274
49275 u8 udf_tag_checksum(const struct tag *t)
49276 {
49277 - u8 *data = (u8 *)t;
49278 + const u8 *data = (const u8 *)t;
49279 u8 checksum = 0;
49280 int i;
49281 for (i = 0; i < sizeof(struct tag); ++i)
49282 diff --git a/fs/utimes.c b/fs/utimes.c
49283 index ba653f3..06ea4b1 100644
49284 --- a/fs/utimes.c
49285 +++ b/fs/utimes.c
49286 @@ -1,6 +1,7 @@
49287 #include <linux/compiler.h>
49288 #include <linux/file.h>
49289 #include <linux/fs.h>
49290 +#include <linux/security.h>
49291 #include <linux/linkage.h>
49292 #include <linux/mount.h>
49293 #include <linux/namei.h>
49294 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49295 goto mnt_drop_write_and_out;
49296 }
49297 }
49298 +
49299 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49300 + error = -EACCES;
49301 + goto mnt_drop_write_and_out;
49302 + }
49303 +
49304 mutex_lock(&inode->i_mutex);
49305 error = notify_change(path->dentry, &newattrs);
49306 mutex_unlock(&inode->i_mutex);
49307 diff --git a/fs/xattr.c b/fs/xattr.c
49308 index 82f4337..236473c 100644
49309 --- a/fs/xattr.c
49310 +++ b/fs/xattr.c
49311 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49312 * Extended attribute SET operations
49313 */
49314 static long
49315 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49316 +setxattr(struct path *path, const char __user *name, const void __user *value,
49317 size_t size, int flags)
49318 {
49319 int error;
49320 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49321 return PTR_ERR(kvalue);
49322 }
49323
49324 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49325 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49326 + error = -EACCES;
49327 + goto out;
49328 + }
49329 +
49330 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49331 +out:
49332 kfree(kvalue);
49333 return error;
49334 }
49335 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49336 return error;
49337 error = mnt_want_write(path.mnt);
49338 if (!error) {
49339 - error = setxattr(path.dentry, name, value, size, flags);
49340 + error = setxattr(&path, name, value, size, flags);
49341 mnt_drop_write(path.mnt);
49342 }
49343 path_put(&path);
49344 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49345 return error;
49346 error = mnt_want_write(path.mnt);
49347 if (!error) {
49348 - error = setxattr(path.dentry, name, value, size, flags);
49349 + error = setxattr(&path, name, value, size, flags);
49350 mnt_drop_write(path.mnt);
49351 }
49352 path_put(&path);
49353 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49354 const void __user *,value, size_t, size, int, flags)
49355 {
49356 struct file *f;
49357 - struct dentry *dentry;
49358 int error = -EBADF;
49359
49360 f = fget(fd);
49361 if (!f)
49362 return error;
49363 - dentry = f->f_path.dentry;
49364 - audit_inode(NULL, dentry);
49365 + audit_inode(NULL, f->f_path.dentry);
49366 error = mnt_want_write_file(f);
49367 if (!error) {
49368 - error = setxattr(dentry, name, value, size, flags);
49369 + error = setxattr(&f->f_path, name, value, size, flags);
49370 mnt_drop_write_file(f);
49371 }
49372 fput(f);
49373 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49374 index 8d5a506..7f62712 100644
49375 --- a/fs/xattr_acl.c
49376 +++ b/fs/xattr_acl.c
49377 @@ -17,8 +17,8 @@
49378 struct posix_acl *
49379 posix_acl_from_xattr(const void *value, size_t size)
49380 {
49381 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49382 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49383 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49384 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49385 int count;
49386 struct posix_acl *acl;
49387 struct posix_acl_entry *acl_e;
49388 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49389 index 188ef2f..adcf864 100644
49390 --- a/fs/xfs/xfs_bmap.c
49391 +++ b/fs/xfs/xfs_bmap.c
49392 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49393 int nmap,
49394 int ret_nmap);
49395 #else
49396 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49397 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49398 #endif /* DEBUG */
49399
49400 STATIC int
49401 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49402 index 79d05e8..e3e5861 100644
49403 --- a/fs/xfs/xfs_dir2_sf.c
49404 +++ b/fs/xfs/xfs_dir2_sf.c
49405 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49406 }
49407
49408 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49409 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49410 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49411 + char name[sfep->namelen];
49412 + memcpy(name, sfep->name, sfep->namelen);
49413 + if (filldir(dirent, name, sfep->namelen,
49414 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49415 + *offset = off & 0x7fffffff;
49416 + return 0;
49417 + }
49418 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49419 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49420 *offset = off & 0x7fffffff;
49421 return 0;
49422 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49423 index 76f3ca5..f57f712 100644
49424 --- a/fs/xfs/xfs_ioctl.c
49425 +++ b/fs/xfs/xfs_ioctl.c
49426 @@ -128,7 +128,7 @@ xfs_find_handle(
49427 }
49428
49429 error = -EFAULT;
49430 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49431 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49432 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49433 goto out_put;
49434
49435 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49436 index ab30253..4d86958 100644
49437 --- a/fs/xfs/xfs_iops.c
49438 +++ b/fs/xfs/xfs_iops.c
49439 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49440 struct nameidata *nd,
49441 void *p)
49442 {
49443 - char *s = nd_get_link(nd);
49444 + const char *s = nd_get_link(nd);
49445
49446 if (!IS_ERR(s))
49447 kfree(s);
49448 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49449 new file mode 100644
49450 index 0000000..4089e05
49451 --- /dev/null
49452 +++ b/grsecurity/Kconfig
49453 @@ -0,0 +1,1078 @@
49454 +#
49455 +# grecurity configuration
49456 +#
49457 +
49458 +menu "Grsecurity"
49459 +
49460 +config GRKERNSEC
49461 + bool "Grsecurity"
49462 + select CRYPTO
49463 + select CRYPTO_SHA256
49464 + help
49465 + If you say Y here, you will be able to configure many features
49466 + that will enhance the security of your system. It is highly
49467 + recommended that you say Y here and read through the help
49468 + for each option so that you fully understand the features and
49469 + can evaluate their usefulness for your machine.
49470 +
49471 +choice
49472 + prompt "Security Level"
49473 + depends on GRKERNSEC
49474 + default GRKERNSEC_CUSTOM
49475 +
49476 +config GRKERNSEC_LOW
49477 + bool "Low"
49478 + select GRKERNSEC_LINK
49479 + select GRKERNSEC_FIFO
49480 + select GRKERNSEC_RANDNET
49481 + select GRKERNSEC_DMESG
49482 + select GRKERNSEC_CHROOT
49483 + select GRKERNSEC_CHROOT_CHDIR
49484 +
49485 + help
49486 + If you choose this option, several of the grsecurity options will
49487 + be enabled that will give you greater protection against a number
49488 + of attacks, while assuring that none of your software will have any
49489 + conflicts with the additional security measures. If you run a lot
49490 + of unusual software, or you are having problems with the higher
49491 + security levels, you should say Y here. With this option, the
49492 + following features are enabled:
49493 +
49494 + - Linking restrictions
49495 + - FIFO restrictions
49496 + - Restricted dmesg
49497 + - Enforced chdir("/") on chroot
49498 + - Runtime module disabling
49499 +
49500 +config GRKERNSEC_MEDIUM
49501 + bool "Medium"
49502 + select PAX
49503 + select PAX_EI_PAX
49504 + select PAX_PT_PAX_FLAGS
49505 + select PAX_HAVE_ACL_FLAGS
49506 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49507 + select GRKERNSEC_CHROOT
49508 + select GRKERNSEC_CHROOT_SYSCTL
49509 + select GRKERNSEC_LINK
49510 + select GRKERNSEC_FIFO
49511 + select GRKERNSEC_DMESG
49512 + select GRKERNSEC_RANDNET
49513 + select GRKERNSEC_FORKFAIL
49514 + select GRKERNSEC_TIME
49515 + select GRKERNSEC_SIGNAL
49516 + select GRKERNSEC_CHROOT
49517 + select GRKERNSEC_CHROOT_UNIX
49518 + select GRKERNSEC_CHROOT_MOUNT
49519 + select GRKERNSEC_CHROOT_PIVOT
49520 + select GRKERNSEC_CHROOT_DOUBLE
49521 + select GRKERNSEC_CHROOT_CHDIR
49522 + select GRKERNSEC_CHROOT_MKNOD
49523 + select GRKERNSEC_PROC
49524 + select GRKERNSEC_PROC_USERGROUP
49525 + select PAX_RANDUSTACK
49526 + select PAX_ASLR
49527 + select PAX_RANDMMAP
49528 + select PAX_REFCOUNT if (X86 || SPARC64)
49529 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49530 +
49531 + help
49532 + If you say Y here, several features in addition to those included
49533 + in the low additional security level will be enabled. These
49534 + features provide even more security to your system, though in rare
49535 + cases they may be incompatible with very old or poorly written
49536 + software. If you enable this option, make sure that your auth
49537 + service (identd) is running as gid 1001. With this option,
49538 + the following features (in addition to those provided in the
49539 + low additional security level) will be enabled:
49540 +
49541 + - Failed fork logging
49542 + - Time change logging
49543 + - Signal logging
49544 + - Deny mounts in chroot
49545 + - Deny double chrooting
49546 + - Deny sysctl writes in chroot
49547 + - Deny mknod in chroot
49548 + - Deny access to abstract AF_UNIX sockets out of chroot
49549 + - Deny pivot_root in chroot
49550 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49551 + - /proc restrictions with special GID set to 10 (usually wheel)
49552 + - Address Space Layout Randomization (ASLR)
49553 + - Prevent exploitation of most refcount overflows
49554 + - Bounds checking of copying between the kernel and userland
49555 +
49556 +config GRKERNSEC_HIGH
49557 + bool "High"
49558 + select GRKERNSEC_LINK
49559 + select GRKERNSEC_FIFO
49560 + select GRKERNSEC_DMESG
49561 + select GRKERNSEC_FORKFAIL
49562 + select GRKERNSEC_TIME
49563 + select GRKERNSEC_SIGNAL
49564 + select GRKERNSEC_CHROOT
49565 + select GRKERNSEC_CHROOT_SHMAT
49566 + select GRKERNSEC_CHROOT_UNIX
49567 + select GRKERNSEC_CHROOT_MOUNT
49568 + select GRKERNSEC_CHROOT_FCHDIR
49569 + select GRKERNSEC_CHROOT_PIVOT
49570 + select GRKERNSEC_CHROOT_DOUBLE
49571 + select GRKERNSEC_CHROOT_CHDIR
49572 + select GRKERNSEC_CHROOT_MKNOD
49573 + select GRKERNSEC_CHROOT_CAPS
49574 + select GRKERNSEC_CHROOT_SYSCTL
49575 + select GRKERNSEC_CHROOT_FINDTASK
49576 + select GRKERNSEC_SYSFS_RESTRICT
49577 + select GRKERNSEC_PROC
49578 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49579 + select GRKERNSEC_HIDESYM
49580 + select GRKERNSEC_BRUTE
49581 + select GRKERNSEC_PROC_USERGROUP
49582 + select GRKERNSEC_KMEM
49583 + select GRKERNSEC_RESLOG
49584 + select GRKERNSEC_RANDNET
49585 + select GRKERNSEC_PROC_ADD
49586 + select GRKERNSEC_CHROOT_CHMOD
49587 + select GRKERNSEC_CHROOT_NICE
49588 + select GRKERNSEC_SETXID
49589 + select GRKERNSEC_AUDIT_MOUNT
49590 + select GRKERNSEC_MODHARDEN if (MODULES)
49591 + select GRKERNSEC_HARDEN_PTRACE
49592 + select GRKERNSEC_PTRACE_READEXEC
49593 + select GRKERNSEC_VM86 if (X86_32)
49594 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49595 + select PAX
49596 + select PAX_RANDUSTACK
49597 + select PAX_ASLR
49598 + select PAX_RANDMMAP
49599 + select PAX_NOEXEC
49600 + select PAX_MPROTECT
49601 + select PAX_EI_PAX
49602 + select PAX_PT_PAX_FLAGS
49603 + select PAX_HAVE_ACL_FLAGS
49604 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49605 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49606 + select PAX_RANDKSTACK if (X86_TSC && X86)
49607 + select PAX_SEGMEXEC if (X86_32)
49608 + select PAX_PAGEEXEC
49609 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49610 + select PAX_EMUTRAMP if (PARISC)
49611 + select PAX_EMUSIGRT if (PARISC)
49612 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49613 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49614 + select PAX_REFCOUNT if (X86 || SPARC64)
49615 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49616 + help
49617 + If you say Y here, many of the features of grsecurity will be
49618 + enabled, which will protect you against many kinds of attacks
49619 + against your system. The heightened security comes at a cost
49620 + of an increased chance of incompatibilities with rare software
49621 + on your machine. Since this security level enables PaX, you should
49622 + view <http://pax.grsecurity.net> and read about the PaX
49623 + project. While you are there, download chpax and run it on
49624 + binaries that cause problems with PaX. Also remember that
49625 + since the /proc restrictions are enabled, you must run your
49626 + identd as gid 1001. This security level enables the following
49627 + features in addition to those listed in the low and medium
49628 + security levels:
49629 +
49630 + - Additional /proc restrictions
49631 + - Chmod restrictions in chroot
49632 + - No signals, ptrace, or viewing of processes outside of chroot
49633 + - Capability restrictions in chroot
49634 + - Deny fchdir out of chroot
49635 + - Priority restrictions in chroot
49636 + - Segmentation-based implementation of PaX
49637 + - Mprotect restrictions
49638 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49639 + - Kernel stack randomization
49640 + - Mount/unmount/remount logging
49641 + - Kernel symbol hiding
49642 + - Hardening of module auto-loading
49643 + - Ptrace restrictions
49644 + - Restricted vm86 mode
49645 + - Restricted sysfs/debugfs
49646 + - Active kernel exploit response
49647 +
49648 +config GRKERNSEC_CUSTOM
49649 + bool "Custom"
49650 + help
49651 + If you say Y here, you will be able to configure every grsecurity
49652 + option, which allows you to enable many more features that aren't
49653 + covered in the basic security levels. These additional features
49654 + include TPE, socket restrictions, and the sysctl system for
49655 + grsecurity. It is advised that you read through the help for
49656 + each option to determine its usefulness in your situation.
49657 +
49658 +endchoice
49659 +
49660 +menu "Memory Protections"
49661 +depends on GRKERNSEC
49662 +
49663 +config GRKERNSEC_KMEM
49664 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49665 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49666 + help
49667 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49668 + be written to or read from to modify or leak the contents of the running
49669 + kernel. /dev/port will also not be allowed to be opened. If you have module
49670 + support disabled, enabling this will close up four ways that are
49671 + currently used to insert malicious code into the running kernel.
49672 + Even with all these features enabled, we still highly recommend that
49673 + you use the RBAC system, as it is still possible for an attacker to
49674 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49675 + If you are not using XFree86, you may be able to stop this additional
49676 + case by enabling the 'Disable privileged I/O' option. Though nothing
49677 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49678 + but only to video memory, which is the only writing we allow in this
49679 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49680 + not be allowed to mprotect it with PROT_WRITE later.
49681 + It is highly recommended that you say Y here if you meet all the
49682 + conditions above.
49683 +
49684 +config GRKERNSEC_VM86
49685 + bool "Restrict VM86 mode"
49686 + depends on X86_32
49687 +
49688 + help
49689 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49690 + make use of a special execution mode on 32bit x86 processors called
49691 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49692 + video cards and will still work with this option enabled. The purpose
49693 + of the option is to prevent exploitation of emulation errors in
49694 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49695 + Nearly all users should be able to enable this option.
49696 +
49697 +config GRKERNSEC_IO
49698 + bool "Disable privileged I/O"
49699 + depends on X86
49700 + select RTC_CLASS
49701 + select RTC_INTF_DEV
49702 + select RTC_DRV_CMOS
49703 +
49704 + help
49705 + If you say Y here, all ioperm and iopl calls will return an error.
49706 + Ioperm and iopl can be used to modify the running kernel.
49707 + Unfortunately, some programs need this access to operate properly,
49708 + the most notable of which are XFree86 and hwclock. hwclock can be
49709 + remedied by having RTC support in the kernel, so real-time
49710 + clock support is enabled if this option is enabled, to ensure
49711 + that hwclock operates correctly. XFree86 still will not
49712 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49713 + IF YOU USE XFree86. If you use XFree86 and you still want to
49714 + protect your kernel against modification, use the RBAC system.
49715 +
49716 +config GRKERNSEC_PROC_MEMMAP
49717 + bool "Harden ASLR against information leaks and entropy reduction"
49718 + default y if (PAX_NOEXEC || PAX_ASLR)
49719 + depends on PAX_NOEXEC || PAX_ASLR
49720 + help
49721 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49722 + give no information about the addresses of its mappings if
49723 + PaX features that rely on random addresses are enabled on the task.
49724 + In addition to sanitizing this information and disabling other
49725 + dangerous sources of information, this option causes reads of sensitive
49726 + /proc/<pid> entries where the file descriptor was opened in a different
49727 + task than the one performing the read. Such attempts are logged.
49728 + This option also limits argv/env strings for suid/sgid binaries
49729 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49730 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49731 + binaries to prevent alternative mmap layouts from being abused.
49732 +
49733 + If you use PaX it is essential that you say Y here as it closes up
49734 + several holes that make full ASLR useless locally.
49735 +
49736 +config GRKERNSEC_BRUTE
49737 + bool "Deter exploit bruteforcing"
49738 + help
49739 + If you say Y here, attempts to bruteforce exploits against forking
49740 + daemons such as apache or sshd, as well as against suid/sgid binaries
49741 + will be deterred. When a child of a forking daemon is killed by PaX
49742 + or crashes due to an illegal instruction or other suspicious signal,
49743 + the parent process will be delayed 30 seconds upon every subsequent
49744 + fork until the administrator is able to assess the situation and
49745 + restart the daemon.
49746 + In the suid/sgid case, the attempt is logged, the user has all their
49747 + processes terminated, and they are prevented from executing any further
49748 + processes for 15 minutes.
49749 + It is recommended that you also enable signal logging in the auditing
49750 + section so that logs are generated when a process triggers a suspicious
49751 + signal.
49752 + If the sysctl option is enabled, a sysctl option with name
49753 + "deter_bruteforce" is created.
49754 +
49755 +
49756 +config GRKERNSEC_MODHARDEN
49757 + bool "Harden module auto-loading"
49758 + depends on MODULES
49759 + help
49760 + If you say Y here, module auto-loading in response to use of some
49761 + feature implemented by an unloaded module will be restricted to
49762 + root users. Enabling this option helps defend against attacks
49763 + by unprivileged users who abuse the auto-loading behavior to
49764 + cause a vulnerable module to load that is then exploited.
49765 +
49766 + If this option prevents a legitimate use of auto-loading for a
49767 + non-root user, the administrator can execute modprobe manually
49768 + with the exact name of the module mentioned in the alert log.
49769 + Alternatively, the administrator can add the module to the list
49770 + of modules loaded at boot by modifying init scripts.
49771 +
49772 + Modification of init scripts will most likely be needed on
49773 + Ubuntu servers with encrypted home directory support enabled,
49774 + as the first non-root user logging in will cause the ecb(aes),
49775 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49776 +
49777 +config GRKERNSEC_HIDESYM
49778 + bool "Hide kernel symbols"
49779 + help
49780 + If you say Y here, getting information on loaded modules, and
49781 + displaying all kernel symbols through a syscall will be restricted
49782 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49783 + /proc/kallsyms will be restricted to the root user. The RBAC
49784 + system can hide that entry even from root.
49785 +
49786 + This option also prevents leaking of kernel addresses through
49787 + several /proc entries.
49788 +
49789 + Note that this option is only effective provided the following
49790 + conditions are met:
49791 + 1) The kernel using grsecurity is not precompiled by some distribution
49792 + 2) You have also enabled GRKERNSEC_DMESG
49793 + 3) You are using the RBAC system and hiding other files such as your
49794 + kernel image and System.map. Alternatively, enabling this option
49795 + causes the permissions on /boot, /lib/modules, and the kernel
49796 + source directory to change at compile time to prevent
49797 + reading by non-root users.
49798 + If the above conditions are met, this option will aid in providing a
49799 + useful protection against local kernel exploitation of overflows
49800 + and arbitrary read/write vulnerabilities.
49801 +
49802 +config GRKERNSEC_KERN_LOCKOUT
49803 + bool "Active kernel exploit response"
49804 + depends on X86 || ARM || PPC || SPARC
49805 + help
49806 + If you say Y here, when a PaX alert is triggered due to suspicious
49807 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49808 + or an OOPs occurs due to bad memory accesses, instead of just
49809 + terminating the offending process (and potentially allowing
49810 + a subsequent exploit from the same user), we will take one of two
49811 + actions:
49812 + If the user was root, we will panic the system
49813 + If the user was non-root, we will log the attempt, terminate
49814 + all processes owned by the user, then prevent them from creating
49815 + any new processes until the system is restarted
49816 + This deters repeated kernel exploitation/bruteforcing attempts
49817 + and is useful for later forensics.
49818 +
49819 +endmenu
49820 +menu "Role Based Access Control Options"
49821 +depends on GRKERNSEC
49822 +
49823 +config GRKERNSEC_RBAC_DEBUG
49824 + bool
49825 +
49826 +config GRKERNSEC_NO_RBAC
49827 + bool "Disable RBAC system"
49828 + help
49829 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49830 + preventing the RBAC system from being enabled. You should only say Y
49831 + here if you have no intention of using the RBAC system, so as to prevent
49832 + an attacker with root access from misusing the RBAC system to hide files
49833 + and processes when loadable module support and /dev/[k]mem have been
49834 + locked down.
49835 +
49836 +config GRKERNSEC_ACL_HIDEKERN
49837 + bool "Hide kernel processes"
49838 + help
49839 + If you say Y here, all kernel threads will be hidden to all
49840 + processes but those whose subject has the "view hidden processes"
49841 + flag.
49842 +
49843 +config GRKERNSEC_ACL_MAXTRIES
49844 + int "Maximum tries before password lockout"
49845 + default 3
49846 + help
49847 + This option enforces the maximum number of times a user can attempt
49848 + to authorize themselves with the grsecurity RBAC system before being
49849 + denied the ability to attempt authorization again for a specified time.
49850 + The lower the number, the harder it will be to brute-force a password.
49851 +
49852 +config GRKERNSEC_ACL_TIMEOUT
49853 + int "Time to wait after max password tries, in seconds"
49854 + default 30
49855 + help
49856 + This option specifies the time the user must wait after attempting to
49857 + authorize to the RBAC system with the maximum number of invalid
49858 + passwords. The higher the number, the harder it will be to brute-force
49859 + a password.
49860 +
49861 +endmenu
49862 +menu "Filesystem Protections"
49863 +depends on GRKERNSEC
49864 +
49865 +config GRKERNSEC_PROC
49866 + bool "Proc restrictions"
49867 + help
49868 + If you say Y here, the permissions of the /proc filesystem
49869 + will be altered to enhance system security and privacy. You MUST
49870 + choose either a user only restriction or a user and group restriction.
49871 + Depending upon the option you choose, you can either restrict users to
49872 + see only the processes they themselves run, or choose a group that can
49873 + view all processes and files normally restricted to root if you choose
49874 + the "restrict to user only" option. NOTE: If you're running identd or
49875 + ntpd as a non-root user, you will have to run it as the group you
49876 + specify here.
49877 +
49878 +config GRKERNSEC_PROC_USER
49879 + bool "Restrict /proc to user only"
49880 + depends on GRKERNSEC_PROC
49881 + help
49882 + If you say Y here, non-root users will only be able to view their own
49883 + processes, and restricts them from viewing network-related information,
49884 + and viewing kernel symbol and module information.
49885 +
49886 +config GRKERNSEC_PROC_USERGROUP
49887 + bool "Allow special group"
49888 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49889 + help
49890 + If you say Y here, you will be able to select a group that will be
49891 + able to view all processes and network-related information. If you've
49892 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49893 + remain hidden. This option is useful if you want to run identd as
49894 + a non-root user.
49895 +
49896 +config GRKERNSEC_PROC_GID
49897 + int "GID for special group"
49898 + depends on GRKERNSEC_PROC_USERGROUP
49899 + default 1001
49900 +
49901 +config GRKERNSEC_PROC_ADD
49902 + bool "Additional restrictions"
49903 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49904 + help
49905 + If you say Y here, additional restrictions will be placed on
49906 + /proc that keep normal users from viewing device information and
49907 + slabinfo information that could be useful for exploits.
49908 +
49909 +config GRKERNSEC_LINK
49910 + bool "Linking restrictions"
49911 + help
49912 + If you say Y here, /tmp race exploits will be prevented, since users
49913 + will no longer be able to follow symlinks owned by other users in
49914 + world-writable +t directories (e.g. /tmp), unless the owner of the
49915 + symlink is the owner of the directory. users will also not be
49916 + able to hardlink to files they do not own. If the sysctl option is
49917 + enabled, a sysctl option with name "linking_restrictions" is created.
49918 +
49919 +config GRKERNSEC_FIFO
49920 + bool "FIFO restrictions"
49921 + help
49922 + If you say Y here, users will not be able to write to FIFOs they don't
49923 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49924 + the FIFO is the same owner of the directory it's held in. If the sysctl
49925 + option is enabled, a sysctl option with name "fifo_restrictions" is
49926 + created.
49927 +
49928 +config GRKERNSEC_SYSFS_RESTRICT
49929 + bool "Sysfs/debugfs restriction"
49930 + depends on SYSFS
49931 + help
49932 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49933 + any filesystem normally mounted under it (e.g. debugfs) will be
49934 + mostly accessible only by root. These filesystems generally provide access
49935 + to hardware and debug information that isn't appropriate for unprivileged
49936 + users of the system. Sysfs and debugfs have also become a large source
49937 + of new vulnerabilities, ranging from infoleaks to local compromise.
49938 + There has been very little oversight with an eye toward security involved
49939 + in adding new exporters of information to these filesystems, so their
49940 + use is discouraged.
49941 + For reasons of compatibility, a few directories have been whitelisted
49942 + for access by non-root users:
49943 + /sys/fs/selinux
49944 + /sys/fs/fuse
49945 + /sys/devices/system/cpu
49946 +
49947 +config GRKERNSEC_ROFS
49948 + bool "Runtime read-only mount protection"
49949 + help
49950 + If you say Y here, a sysctl option with name "romount_protect" will
49951 + be created. By setting this option to 1 at runtime, filesystems
49952 + will be protected in the following ways:
49953 + * No new writable mounts will be allowed
49954 + * Existing read-only mounts won't be able to be remounted read/write
49955 + * Write operations will be denied on all block devices
49956 + This option acts independently of grsec_lock: once it is set to 1,
49957 + it cannot be turned off. Therefore, please be mindful of the resulting
49958 + behavior if this option is enabled in an init script on a read-only
49959 + filesystem. This feature is mainly intended for secure embedded systems.
49960 +
49961 +config GRKERNSEC_CHROOT
49962 + bool "Chroot jail restrictions"
49963 + help
49964 + If you say Y here, you will be able to choose several options that will
49965 + make breaking out of a chrooted jail much more difficult. If you
49966 + encounter no software incompatibilities with the following options, it
49967 + is recommended that you enable each one.
49968 +
49969 +config GRKERNSEC_CHROOT_MOUNT
49970 + bool "Deny mounts"
49971 + depends on GRKERNSEC_CHROOT
49972 + help
49973 + If you say Y here, processes inside a chroot will not be able to
49974 + mount or remount filesystems. If the sysctl option is enabled, a
49975 + sysctl option with name "chroot_deny_mount" is created.
49976 +
49977 +config GRKERNSEC_CHROOT_DOUBLE
49978 + bool "Deny double-chroots"
49979 + depends on GRKERNSEC_CHROOT
49980 + help
49981 + If you say Y here, processes inside a chroot will not be able to chroot
49982 + again outside the chroot. This is a widely used method of breaking
49983 + out of a chroot jail and should not be allowed. If the sysctl
49984 + option is enabled, a sysctl option with name
49985 + "chroot_deny_chroot" is created.
49986 +
49987 +config GRKERNSEC_CHROOT_PIVOT
49988 + bool "Deny pivot_root in chroot"
49989 + depends on GRKERNSEC_CHROOT
49990 + help
49991 + If you say Y here, processes inside a chroot will not be able to use
49992 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49993 + works similar to chroot in that it changes the root filesystem. This
49994 + function could be misused in a chrooted process to attempt to break out
49995 + of the chroot, and therefore should not be allowed. If the sysctl
49996 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49997 + created.
49998 +
49999 +config GRKERNSEC_CHROOT_CHDIR
50000 + bool "Enforce chdir(\"/\") on all chroots"
50001 + depends on GRKERNSEC_CHROOT
50002 + help
50003 + If you say Y here, the current working directory of all newly-chrooted
50004 + applications will be set to the the root directory of the chroot.
50005 + The man page on chroot(2) states:
50006 + Note that this call does not change the current working
50007 + directory, so that `.' can be outside the tree rooted at
50008 + `/'. In particular, the super-user can escape from a
50009 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50010 +
50011 + It is recommended that you say Y here, since it's not known to break
50012 + any software. If the sysctl option is enabled, a sysctl option with
50013 + name "chroot_enforce_chdir" is created.
50014 +
50015 +config GRKERNSEC_CHROOT_CHMOD
50016 + bool "Deny (f)chmod +s"
50017 + depends on GRKERNSEC_CHROOT
50018 + help
50019 + If you say Y here, processes inside a chroot will not be able to chmod
50020 + or fchmod files to make them have suid or sgid bits. This protects
50021 + against another published method of breaking a chroot. If the sysctl
50022 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50023 + created.
50024 +
50025 +config GRKERNSEC_CHROOT_FCHDIR
50026 + bool "Deny fchdir out of chroot"
50027 + depends on GRKERNSEC_CHROOT
50028 + help
50029 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50030 + to a file descriptor of the chrooting process that points to a directory
50031 + outside the filesystem will be stopped. If the sysctl option
50032 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50033 +
50034 +config GRKERNSEC_CHROOT_MKNOD
50035 + bool "Deny mknod"
50036 + depends on GRKERNSEC_CHROOT
50037 + help
50038 + If you say Y here, processes inside a chroot will not be allowed to
50039 + mknod. The problem with using mknod inside a chroot is that it
50040 + would allow an attacker to create a device entry that is the same
50041 + as one on the physical root of your system, which could range from
50042 + anything from the console device to a device for your harddrive (which
50043 + they could then use to wipe the drive or steal data). It is recommended
50044 + that you say Y here, unless you run into software incompatibilities.
50045 + If the sysctl option is enabled, a sysctl option with name
50046 + "chroot_deny_mknod" is created.
50047 +
50048 +config GRKERNSEC_CHROOT_SHMAT
50049 + bool "Deny shmat() out of chroot"
50050 + depends on GRKERNSEC_CHROOT
50051 + help
50052 + If you say Y here, processes inside a chroot will not be able to attach
50053 + to shared memory segments that were created outside of the chroot jail.
50054 + It is recommended that you say Y here. If the sysctl option is enabled,
50055 + a sysctl option with name "chroot_deny_shmat" is created.
50056 +
50057 +config GRKERNSEC_CHROOT_UNIX
50058 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50059 + depends on GRKERNSEC_CHROOT
50060 + help
50061 + If you say Y here, processes inside a chroot will not be able to
50062 + connect to abstract (meaning not belonging to a filesystem) Unix
50063 + domain sockets that were bound outside of a chroot. It is recommended
50064 + that you say Y here. If the sysctl option is enabled, a sysctl option
50065 + with name "chroot_deny_unix" is created.
50066 +
50067 +config GRKERNSEC_CHROOT_FINDTASK
50068 + bool "Protect outside processes"
50069 + depends on GRKERNSEC_CHROOT
50070 + help
50071 + If you say Y here, processes inside a chroot will not be able to
50072 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50073 + getsid, or view any process outside of the chroot. If the sysctl
50074 + option is enabled, a sysctl option with name "chroot_findtask" is
50075 + created.
50076 +
50077 +config GRKERNSEC_CHROOT_NICE
50078 + bool "Restrict priority changes"
50079 + depends on GRKERNSEC_CHROOT
50080 + help
50081 + If you say Y here, processes inside a chroot will not be able to raise
50082 + the priority of processes in the chroot, or alter the priority of
50083 + processes outside the chroot. This provides more security than simply
50084 + removing CAP_SYS_NICE from the process' capability set. If the
50085 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50086 + is created.
50087 +
50088 +config GRKERNSEC_CHROOT_SYSCTL
50089 + bool "Deny sysctl writes"
50090 + depends on GRKERNSEC_CHROOT
50091 + help
50092 + If you say Y here, an attacker in a chroot will not be able to
50093 + write to sysctl entries, either by sysctl(2) or through a /proc
50094 + interface. It is strongly recommended that you say Y here. If the
50095 + sysctl option is enabled, a sysctl option with name
50096 + "chroot_deny_sysctl" is created.
50097 +
50098 +config GRKERNSEC_CHROOT_CAPS
50099 + bool "Capability restrictions"
50100 + depends on GRKERNSEC_CHROOT
50101 + help
50102 + If you say Y here, the capabilities on all processes within a
50103 + chroot jail will be lowered to stop module insertion, raw i/o,
50104 + system and net admin tasks, rebooting the system, modifying immutable
50105 + files, modifying IPC owned by another, and changing the system time.
50106 + This is left an option because it can break some apps. Disable this
50107 + if your chrooted apps are having problems performing those kinds of
50108 + tasks. If the sysctl option is enabled, a sysctl option with
50109 + name "chroot_caps" is created.
50110 +
50111 +endmenu
50112 +menu "Kernel Auditing"
50113 +depends on GRKERNSEC
50114 +
50115 +config GRKERNSEC_AUDIT_GROUP
50116 + bool "Single group for auditing"
50117 + help
50118 + If you say Y here, the exec, chdir, and (un)mount logging features
50119 + will only operate on a group you specify. This option is recommended
50120 + if you only want to watch certain users instead of having a large
50121 + amount of logs from the entire system. If the sysctl option is enabled,
50122 + a sysctl option with name "audit_group" is created.
50123 +
50124 +config GRKERNSEC_AUDIT_GID
50125 + int "GID for auditing"
50126 + depends on GRKERNSEC_AUDIT_GROUP
50127 + default 1007
50128 +
50129 +config GRKERNSEC_EXECLOG
50130 + bool "Exec logging"
50131 + help
50132 + If you say Y here, all execve() calls will be logged (since the
50133 + other exec*() calls are frontends to execve(), all execution
50134 + will be logged). Useful for shell-servers that like to keep track
50135 + of their users. If the sysctl option is enabled, a sysctl option with
50136 + name "exec_logging" is created.
50137 + WARNING: This option when enabled will produce a LOT of logs, especially
50138 + on an active system.
50139 +
50140 +config GRKERNSEC_RESLOG
50141 + bool "Resource logging"
50142 + help
50143 + If you say Y here, all attempts to overstep resource limits will
50144 + be logged with the resource name, the requested size, and the current
50145 + limit. It is highly recommended that you say Y here. If the sysctl
50146 + option is enabled, a sysctl option with name "resource_logging" is
50147 + created. If the RBAC system is enabled, the sysctl value is ignored.
50148 +
50149 +config GRKERNSEC_CHROOT_EXECLOG
50150 + bool "Log execs within chroot"
50151 + help
50152 + If you say Y here, all executions inside a chroot jail will be logged
50153 + to syslog. This can cause a large amount of logs if certain
50154 + applications (eg. djb's daemontools) are installed on the system, and
50155 + is therefore left as an option. If the sysctl option is enabled, a
50156 + sysctl option with name "chroot_execlog" is created.
50157 +
50158 +config GRKERNSEC_AUDIT_PTRACE
50159 + bool "Ptrace logging"
50160 + help
50161 + If you say Y here, all attempts to attach to a process via ptrace
50162 + will be logged. If the sysctl option is enabled, a sysctl option
50163 + with name "audit_ptrace" is created.
50164 +
50165 +config GRKERNSEC_AUDIT_CHDIR
50166 + bool "Chdir logging"
50167 + help
50168 + If you say Y here, all chdir() calls will be logged. If the sysctl
50169 + option is enabled, a sysctl option with name "audit_chdir" is created.
50170 +
50171 +config GRKERNSEC_AUDIT_MOUNT
50172 + bool "(Un)Mount logging"
50173 + help
50174 + If you say Y here, all mounts and unmounts will be logged. If the
50175 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50176 + created.
50177 +
50178 +config GRKERNSEC_SIGNAL
50179 + bool "Signal logging"
50180 + help
50181 + If you say Y here, certain important signals will be logged, such as
50182 + SIGSEGV, which will as a result inform you of when a error in a program
50183 + occurred, which in some cases could mean a possible exploit attempt.
50184 + If the sysctl option is enabled, a sysctl option with name
50185 + "signal_logging" is created.
50186 +
50187 +config GRKERNSEC_FORKFAIL
50188 + bool "Fork failure logging"
50189 + help
50190 + If you say Y here, all failed fork() attempts will be logged.
50191 + This could suggest a fork bomb, or someone attempting to overstep
50192 + their process limit. If the sysctl option is enabled, a sysctl option
50193 + with name "forkfail_logging" is created.
50194 +
50195 +config GRKERNSEC_TIME
50196 + bool "Time change logging"
50197 + help
50198 + If you say Y here, any changes of the system clock will be logged.
50199 + If the sysctl option is enabled, a sysctl option with name
50200 + "timechange_logging" is created.
50201 +
50202 +config GRKERNSEC_PROC_IPADDR
50203 + bool "/proc/<pid>/ipaddr support"
50204 + help
50205 + If you say Y here, a new entry will be added to each /proc/<pid>
50206 + directory that contains the IP address of the person using the task.
50207 + The IP is carried across local TCP and AF_UNIX stream sockets.
50208 + This information can be useful for IDS/IPSes to perform remote response
50209 + to a local attack. The entry is readable by only the owner of the
50210 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50211 + the RBAC system), and thus does not create privacy concerns.
50212 +
50213 +config GRKERNSEC_RWXMAP_LOG
50214 + bool 'Denied RWX mmap/mprotect logging'
50215 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50216 + help
50217 + If you say Y here, calls to mmap() and mprotect() with explicit
50218 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50219 + denied by the PAX_MPROTECT feature. If the sysctl option is
50220 + enabled, a sysctl option with name "rwxmap_logging" is created.
50221 +
50222 +config GRKERNSEC_AUDIT_TEXTREL
50223 + bool 'ELF text relocations logging (READ HELP)'
50224 + depends on PAX_MPROTECT
50225 + help
50226 + If you say Y here, text relocations will be logged with the filename
50227 + of the offending library or binary. The purpose of the feature is
50228 + to help Linux distribution developers get rid of libraries and
50229 + binaries that need text relocations which hinder the future progress
50230 + of PaX. Only Linux distribution developers should say Y here, and
50231 + never on a production machine, as this option creates an information
50232 + leak that could aid an attacker in defeating the randomization of
50233 + a single memory region. If the sysctl option is enabled, a sysctl
50234 + option with name "audit_textrel" is created.
50235 +
50236 +endmenu
50237 +
50238 +menu "Executable Protections"
50239 +depends on GRKERNSEC
50240 +
50241 +config GRKERNSEC_DMESG
50242 + bool "Dmesg(8) restriction"
50243 + help
50244 + If you say Y here, non-root users will not be able to use dmesg(8)
50245 + to view up to the last 4kb of messages in the kernel's log buffer.
50246 + The kernel's log buffer often contains kernel addresses and other
50247 + identifying information useful to an attacker in fingerprinting a
50248 + system for a targeted exploit.
50249 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50250 + created.
50251 +
50252 +config GRKERNSEC_HARDEN_PTRACE
50253 + bool "Deter ptrace-based process snooping"
50254 + help
50255 + If you say Y here, TTY sniffers and other malicious monitoring
50256 + programs implemented through ptrace will be defeated. If you
50257 + have been using the RBAC system, this option has already been
50258 + enabled for several years for all users, with the ability to make
50259 + fine-grained exceptions.
50260 +
50261 + This option only affects the ability of non-root users to ptrace
50262 + processes that are not a descendent of the ptracing process.
50263 + This means that strace ./binary and gdb ./binary will still work,
50264 + but attaching to arbitrary processes will not. If the sysctl
50265 + option is enabled, a sysctl option with name "harden_ptrace" is
50266 + created.
50267 +
50268 +config GRKERNSEC_PTRACE_READEXEC
50269 + bool "Require read access to ptrace sensitive binaries"
50270 + help
50271 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50272 + binaries. This option is useful in environments that
50273 + remove the read bits (e.g. file mode 4711) from suid binaries to
50274 + prevent infoleaking of their contents. This option adds
50275 + consistency to the use of that file mode, as the binary could normally
50276 + be read out when run without privileges while ptracing.
50277 +
50278 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50279 + is created.
50280 +
50281 +config GRKERNSEC_SETXID
50282 + bool "Enforce consistent multithreaded privileges"
50283 + help
50284 + If you say Y here, a change from a root uid to a non-root uid
50285 + in a multithreaded application will cause the resulting uids,
50286 + gids, supplementary groups, and capabilities in that thread
50287 + to be propagated to the other threads of the process. In most
50288 + cases this is unnecessary, as glibc will emulate this behavior
50289 + on behalf of the application. Other libcs do not act in the
50290 + same way, allowing the other threads of the process to continue
50291 + running with root privileges. If the sysctl option is enabled,
50292 + a sysctl option with name "consistent_setxid" is created.
50293 +
50294 +config GRKERNSEC_TPE
50295 + bool "Trusted Path Execution (TPE)"
50296 + help
50297 + If you say Y here, you will be able to choose a gid to add to the
50298 + supplementary groups of users you want to mark as "untrusted."
50299 + These users will not be able to execute any files that are not in
50300 + root-owned directories writable only by root. If the sysctl option
50301 + is enabled, a sysctl option with name "tpe" is created.
50302 +
50303 +config GRKERNSEC_TPE_ALL
50304 + bool "Partially restrict all non-root users"
50305 + depends on GRKERNSEC_TPE
50306 + help
50307 + If you say Y here, all non-root users will be covered under
50308 + a weaker TPE restriction. This is separate from, and in addition to,
50309 + the main TPE options that you have selected elsewhere. Thus, if a
50310 + "trusted" GID is chosen, this restriction applies to even that GID.
50311 + Under this restriction, all non-root users will only be allowed to
50312 + execute files in directories they own that are not group or
50313 + world-writable, or in directories owned by root and writable only by
50314 + root. If the sysctl option is enabled, a sysctl option with name
50315 + "tpe_restrict_all" is created.
50316 +
50317 +config GRKERNSEC_TPE_INVERT
50318 + bool "Invert GID option"
50319 + depends on GRKERNSEC_TPE
50320 + help
50321 + If you say Y here, the group you specify in the TPE configuration will
50322 + decide what group TPE restrictions will be *disabled* for. This
50323 + option is useful if you want TPE restrictions to be applied to most
50324 + users on the system. If the sysctl option is enabled, a sysctl option
50325 + with name "tpe_invert" is created. Unlike other sysctl options, this
50326 + entry will default to on for backward-compatibility.
50327 +
50328 +config GRKERNSEC_TPE_GID
50329 + int "GID for untrusted users"
50330 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50331 + default 1005
50332 + help
50333 + Setting this GID determines what group TPE restrictions will be
50334 + *enabled* for. If the sysctl option is enabled, a sysctl option
50335 + with name "tpe_gid" is created.
50336 +
50337 +config GRKERNSEC_TPE_GID
50338 + int "GID for trusted users"
50339 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50340 + default 1005
50341 + help
50342 + Setting this GID determines what group TPE restrictions will be
50343 + *disabled* for. If the sysctl option is enabled, a sysctl option
50344 + with name "tpe_gid" is created.
50345 +
50346 +endmenu
50347 +menu "Network Protections"
50348 +depends on GRKERNSEC
50349 +
50350 +config GRKERNSEC_RANDNET
50351 + bool "Larger entropy pools"
50352 + help
50353 + If you say Y here, the entropy pools used for many features of Linux
50354 + and grsecurity will be doubled in size. Since several grsecurity
50355 + features use additional randomness, it is recommended that you say Y
50356 + here. Saying Y here has a similar effect as modifying
50357 + /proc/sys/kernel/random/poolsize.
50358 +
50359 +config GRKERNSEC_BLACKHOLE
50360 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50361 + depends on NET
50362 + help
50363 + If you say Y here, neither TCP resets nor ICMP
50364 + destination-unreachable packets will be sent in response to packets
50365 + sent to ports for which no associated listening process exists.
50366 + This feature supports both IPV4 and IPV6 and exempts the
50367 + loopback interface from blackholing. Enabling this feature
50368 + makes a host more resilient to DoS attacks and reduces network
50369 + visibility against scanners.
50370 +
50371 + The blackhole feature as-implemented is equivalent to the FreeBSD
50372 + blackhole feature, as it prevents RST responses to all packets, not
50373 + just SYNs. Under most application behavior this causes no
50374 + problems, but applications (like haproxy) may not close certain
50375 + connections in a way that cleanly terminates them on the remote
50376 + end, leaving the remote host in LAST_ACK state. Because of this
50377 + side-effect and to prevent intentional LAST_ACK DoSes, this
50378 + feature also adds automatic mitigation against such attacks.
50379 + The mitigation drastically reduces the amount of time a socket
50380 + can spend in LAST_ACK state. If you're using haproxy and not
50381 + all servers it connects to have this option enabled, consider
50382 + disabling this feature on the haproxy host.
50383 +
50384 + If the sysctl option is enabled, two sysctl options with names
50385 + "ip_blackhole" and "lastack_retries" will be created.
50386 + While "ip_blackhole" takes the standard zero/non-zero on/off
50387 + toggle, "lastack_retries" uses the same kinds of values as
50388 + "tcp_retries1" and "tcp_retries2". The default value of 4
50389 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50390 + state.
50391 +
50392 +config GRKERNSEC_SOCKET
50393 + bool "Socket restrictions"
50394 + depends on NET
50395 + help
50396 + If you say Y here, you will be able to choose from several options.
50397 + If you assign a GID on your system and add it to the supplementary
50398 + groups of users you want to restrict socket access to, this patch
50399 + will perform up to three things, based on the option(s) you choose.
50400 +
50401 +config GRKERNSEC_SOCKET_ALL
50402 + bool "Deny any sockets to group"
50403 + depends on GRKERNSEC_SOCKET
50404 + help
50405 + If you say Y here, you will be able to choose a GID of whose users will
50406 + be unable to connect to other hosts from your machine or run server
50407 + applications from your machine. If the sysctl option is enabled, a
50408 + sysctl option with name "socket_all" is created.
50409 +
50410 +config GRKERNSEC_SOCKET_ALL_GID
50411 + int "GID to deny all sockets for"
50412 + depends on GRKERNSEC_SOCKET_ALL
50413 + default 1004
50414 + help
50415 + Here you can choose the GID to disable socket access for. Remember to
50416 + add the users you want socket access disabled for to the GID
50417 + specified here. If the sysctl option is enabled, a sysctl option
50418 + with name "socket_all_gid" is created.
50419 +
50420 +config GRKERNSEC_SOCKET_CLIENT
50421 + bool "Deny client 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, but will be
50426 + able to run servers. If this option is enabled, all users in the group
50427 + you specify will have to use passive mode when initiating ftp transfers
50428 + from the shell on your machine. If the sysctl option is enabled, a
50429 + sysctl option with name "socket_client" is created.
50430 +
50431 +config GRKERNSEC_SOCKET_CLIENT_GID
50432 + int "GID to deny client sockets for"
50433 + depends on GRKERNSEC_SOCKET_CLIENT
50434 + default 1003
50435 + help
50436 + Here you can choose the GID to disable client socket access for.
50437 + Remember to add the users you want client socket access disabled for to
50438 + the GID specified here. If the sysctl option is enabled, a sysctl
50439 + option with name "socket_client_gid" is created.
50440 +
50441 +config GRKERNSEC_SOCKET_SERVER
50442 + bool "Deny server sockets to group"
50443 + depends on GRKERNSEC_SOCKET
50444 + help
50445 + If you say Y here, you will be able to choose a GID of whose users will
50446 + be unable to run server applications from your machine. If the sysctl
50447 + option is enabled, a sysctl option with name "socket_server" is created.
50448 +
50449 +config GRKERNSEC_SOCKET_SERVER_GID
50450 + int "GID to deny server sockets for"
50451 + depends on GRKERNSEC_SOCKET_SERVER
50452 + default 1002
50453 + help
50454 + Here you can choose the GID to disable server socket access for.
50455 + Remember to add the users you want server socket access disabled for to
50456 + the GID specified here. If the sysctl option is enabled, a sysctl
50457 + option with name "socket_server_gid" is created.
50458 +
50459 +endmenu
50460 +menu "Sysctl support"
50461 +depends on GRKERNSEC && SYSCTL
50462 +
50463 +config GRKERNSEC_SYSCTL
50464 + bool "Sysctl support"
50465 + help
50466 + If you say Y here, you will be able to change the options that
50467 + grsecurity runs with at bootup, without having to recompile your
50468 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50469 + to enable (1) or disable (0) various features. All the sysctl entries
50470 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50471 + All features enabled in the kernel configuration are disabled at boot
50472 + if you do not say Y to the "Turn on features by default" option.
50473 + All options should be set at startup, and the grsec_lock entry should
50474 + be set to a non-zero value after all the options are set.
50475 + *THIS IS EXTREMELY IMPORTANT*
50476 +
50477 +config GRKERNSEC_SYSCTL_DISTRO
50478 + bool "Extra sysctl support for distro makers (READ HELP)"
50479 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50480 + help
50481 + If you say Y here, additional sysctl options will be created
50482 + for features that affect processes running as root. Therefore,
50483 + it is critical when using this option that the grsec_lock entry be
50484 + enabled after boot. Only distros with prebuilt kernel packages
50485 + with this option enabled that can ensure grsec_lock is enabled
50486 + after boot should use this option.
50487 + *Failure to set grsec_lock after boot makes all grsec features
50488 + this option covers useless*
50489 +
50490 + Currently this option creates the following sysctl entries:
50491 + "Disable Privileged I/O": "disable_priv_io"
50492 +
50493 +config GRKERNSEC_SYSCTL_ON
50494 + bool "Turn on features by default"
50495 + depends on GRKERNSEC_SYSCTL
50496 + help
50497 + If you say Y here, instead of having all features enabled in the
50498 + kernel configuration disabled at boot time, the features will be
50499 + enabled at boot time. It is recommended you say Y here unless
50500 + there is some reason you would want all sysctl-tunable features to
50501 + be disabled by default. As mentioned elsewhere, it is important
50502 + to enable the grsec_lock entry once you have finished modifying
50503 + the sysctl entries.
50504 +
50505 +endmenu
50506 +menu "Logging Options"
50507 +depends on GRKERNSEC
50508 +
50509 +config GRKERNSEC_FLOODTIME
50510 + int "Seconds in between log messages (minimum)"
50511 + default 10
50512 + help
50513 + This option allows you to enforce the number of seconds between
50514 + grsecurity log messages. The default should be suitable for most
50515 + people, however, if you choose to change it, choose a value small enough
50516 + to allow informative logs to be produced, but large enough to
50517 + prevent flooding.
50518 +
50519 +config GRKERNSEC_FLOODBURST
50520 + int "Number of messages in a burst (maximum)"
50521 + default 6
50522 + help
50523 + This option allows you to choose the maximum number of messages allowed
50524 + within the flood time interval you chose in a separate option. The
50525 + default should be suitable for most people, however if you find that
50526 + many of your logs are being interpreted as flooding, you may want to
50527 + raise this value.
50528 +
50529 +endmenu
50530 +
50531 +endmenu
50532 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50533 new file mode 100644
50534 index 0000000..1b9afa9
50535 --- /dev/null
50536 +++ b/grsecurity/Makefile
50537 @@ -0,0 +1,38 @@
50538 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50539 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50540 +# into an RBAC system
50541 +#
50542 +# All code in this directory and various hooks inserted throughout the kernel
50543 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50544 +# under the GPL v2 or higher
50545 +
50546 +KBUILD_CFLAGS += -Werror
50547 +
50548 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50549 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50550 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50551 +
50552 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50553 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50554 + gracl_learn.o grsec_log.o
50555 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50556 +
50557 +ifdef CONFIG_NET
50558 +obj-y += grsec_sock.o
50559 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50560 +endif
50561 +
50562 +ifndef CONFIG_GRKERNSEC
50563 +obj-y += grsec_disabled.o
50564 +endif
50565 +
50566 +ifdef CONFIG_GRKERNSEC_HIDESYM
50567 +extra-y := grsec_hidesym.o
50568 +$(obj)/grsec_hidesym.o:
50569 + @-chmod -f 500 /boot
50570 + @-chmod -f 500 /lib/modules
50571 + @-chmod -f 500 /lib64/modules
50572 + @-chmod -f 500 /lib32/modules
50573 + @-chmod -f 700 .
50574 + @echo ' grsec: protected kernel image paths'
50575 +endif
50576 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50577 new file mode 100644
50578 index 0000000..42813ac
50579 --- /dev/null
50580 +++ b/grsecurity/gracl.c
50581 @@ -0,0 +1,4192 @@
50582 +#include <linux/kernel.h>
50583 +#include <linux/module.h>
50584 +#include <linux/sched.h>
50585 +#include <linux/mm.h>
50586 +#include <linux/file.h>
50587 +#include <linux/fs.h>
50588 +#include <linux/namei.h>
50589 +#include <linux/mount.h>
50590 +#include <linux/tty.h>
50591 +#include <linux/proc_fs.h>
50592 +#include <linux/lglock.h>
50593 +#include <linux/slab.h>
50594 +#include <linux/vmalloc.h>
50595 +#include <linux/types.h>
50596 +#include <linux/sysctl.h>
50597 +#include <linux/netdevice.h>
50598 +#include <linux/ptrace.h>
50599 +#include <linux/gracl.h>
50600 +#include <linux/gralloc.h>
50601 +#include <linux/security.h>
50602 +#include <linux/grinternal.h>
50603 +#include <linux/pid_namespace.h>
50604 +#include <linux/fdtable.h>
50605 +#include <linux/percpu.h>
50606 +#include "../fs/mount.h"
50607 +
50608 +#include <asm/uaccess.h>
50609 +#include <asm/errno.h>
50610 +#include <asm/mman.h>
50611 +
50612 +static struct acl_role_db acl_role_set;
50613 +static struct name_db name_set;
50614 +static struct inodev_db inodev_set;
50615 +
50616 +/* for keeping track of userspace pointers used for subjects, so we
50617 + can share references in the kernel as well
50618 +*/
50619 +
50620 +static struct path real_root;
50621 +
50622 +static struct acl_subj_map_db subj_map_set;
50623 +
50624 +static struct acl_role_label *default_role;
50625 +
50626 +static struct acl_role_label *role_list;
50627 +
50628 +static u16 acl_sp_role_value;
50629 +
50630 +extern char *gr_shared_page[4];
50631 +static DEFINE_MUTEX(gr_dev_mutex);
50632 +DEFINE_RWLOCK(gr_inode_lock);
50633 +
50634 +struct gr_arg *gr_usermode;
50635 +
50636 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50637 +
50638 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50639 +extern void gr_clear_learn_entries(void);
50640 +
50641 +#ifdef CONFIG_GRKERNSEC_RESLOG
50642 +extern void gr_log_resource(const struct task_struct *task,
50643 + const int res, const unsigned long wanted, const int gt);
50644 +#endif
50645 +
50646 +unsigned char *gr_system_salt;
50647 +unsigned char *gr_system_sum;
50648 +
50649 +static struct sprole_pw **acl_special_roles = NULL;
50650 +static __u16 num_sprole_pws = 0;
50651 +
50652 +static struct acl_role_label *kernel_role = NULL;
50653 +
50654 +static unsigned int gr_auth_attempts = 0;
50655 +static unsigned long gr_auth_expires = 0UL;
50656 +
50657 +#ifdef CONFIG_NET
50658 +extern struct vfsmount *sock_mnt;
50659 +#endif
50660 +
50661 +extern struct vfsmount *pipe_mnt;
50662 +extern struct vfsmount *shm_mnt;
50663 +#ifdef CONFIG_HUGETLBFS
50664 +extern struct vfsmount *hugetlbfs_vfsmount;
50665 +#endif
50666 +
50667 +static struct acl_object_label *fakefs_obj_rw;
50668 +static struct acl_object_label *fakefs_obj_rwx;
50669 +
50670 +extern int gr_init_uidset(void);
50671 +extern void gr_free_uidset(void);
50672 +extern void gr_remove_uid(uid_t uid);
50673 +extern int gr_find_uid(uid_t uid);
50674 +
50675 +DECLARE_BRLOCK(vfsmount_lock);
50676 +
50677 +__inline__ int
50678 +gr_acl_is_enabled(void)
50679 +{
50680 + return (gr_status & GR_READY);
50681 +}
50682 +
50683 +#ifdef CONFIG_BTRFS_FS
50684 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50685 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50686 +#endif
50687 +
50688 +static inline dev_t __get_dev(const struct dentry *dentry)
50689 +{
50690 +#ifdef CONFIG_BTRFS_FS
50691 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50692 + return get_btrfs_dev_from_inode(dentry->d_inode);
50693 + else
50694 +#endif
50695 + return dentry->d_inode->i_sb->s_dev;
50696 +}
50697 +
50698 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50699 +{
50700 + return __get_dev(dentry);
50701 +}
50702 +
50703 +static char gr_task_roletype_to_char(struct task_struct *task)
50704 +{
50705 + switch (task->role->roletype &
50706 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50707 + GR_ROLE_SPECIAL)) {
50708 + case GR_ROLE_DEFAULT:
50709 + return 'D';
50710 + case GR_ROLE_USER:
50711 + return 'U';
50712 + case GR_ROLE_GROUP:
50713 + return 'G';
50714 + case GR_ROLE_SPECIAL:
50715 + return 'S';
50716 + }
50717 +
50718 + return 'X';
50719 +}
50720 +
50721 +char gr_roletype_to_char(void)
50722 +{
50723 + return gr_task_roletype_to_char(current);
50724 +}
50725 +
50726 +__inline__ int
50727 +gr_acl_tpe_check(void)
50728 +{
50729 + if (unlikely(!(gr_status & GR_READY)))
50730 + return 0;
50731 + if (current->role->roletype & GR_ROLE_TPE)
50732 + return 1;
50733 + else
50734 + return 0;
50735 +}
50736 +
50737 +int
50738 +gr_handle_rawio(const struct inode *inode)
50739 +{
50740 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50741 + if (inode && S_ISBLK(inode->i_mode) &&
50742 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50743 + !capable(CAP_SYS_RAWIO))
50744 + return 1;
50745 +#endif
50746 + return 0;
50747 +}
50748 +
50749 +static int
50750 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50751 +{
50752 + if (likely(lena != lenb))
50753 + return 0;
50754 +
50755 + return !memcmp(a, b, lena);
50756 +}
50757 +
50758 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50759 +{
50760 + *buflen -= namelen;
50761 + if (*buflen < 0)
50762 + return -ENAMETOOLONG;
50763 + *buffer -= namelen;
50764 + memcpy(*buffer, str, namelen);
50765 + return 0;
50766 +}
50767 +
50768 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50769 +{
50770 + return prepend(buffer, buflen, name->name, name->len);
50771 +}
50772 +
50773 +static int prepend_path(const struct path *path, struct path *root,
50774 + char **buffer, int *buflen)
50775 +{
50776 + struct dentry *dentry = path->dentry;
50777 + struct vfsmount *vfsmnt = path->mnt;
50778 + struct mount *mnt = real_mount(vfsmnt);
50779 + bool slash = false;
50780 + int error = 0;
50781 +
50782 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50783 + struct dentry * parent;
50784 +
50785 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50786 + /* Global root? */
50787 + if (!mnt_has_parent(mnt)) {
50788 + goto out;
50789 + }
50790 + dentry = mnt->mnt_mountpoint;
50791 + mnt = mnt->mnt_parent;
50792 + vfsmnt = &mnt->mnt;
50793 + continue;
50794 + }
50795 + parent = dentry->d_parent;
50796 + prefetch(parent);
50797 + spin_lock(&dentry->d_lock);
50798 + error = prepend_name(buffer, buflen, &dentry->d_name);
50799 + spin_unlock(&dentry->d_lock);
50800 + if (!error)
50801 + error = prepend(buffer, buflen, "/", 1);
50802 + if (error)
50803 + break;
50804 +
50805 + slash = true;
50806 + dentry = parent;
50807 + }
50808 +
50809 +out:
50810 + if (!error && !slash)
50811 + error = prepend(buffer, buflen, "/", 1);
50812 +
50813 + return error;
50814 +}
50815 +
50816 +/* this must be called with vfsmount_lock and rename_lock held */
50817 +
50818 +static char *__our_d_path(const struct path *path, struct path *root,
50819 + char *buf, int buflen)
50820 +{
50821 + char *res = buf + buflen;
50822 + int error;
50823 +
50824 + prepend(&res, &buflen, "\0", 1);
50825 + error = prepend_path(path, root, &res, &buflen);
50826 + if (error)
50827 + return ERR_PTR(error);
50828 +
50829 + return res;
50830 +}
50831 +
50832 +static char *
50833 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50834 +{
50835 + char *retval;
50836 +
50837 + retval = __our_d_path(path, root, buf, buflen);
50838 + if (unlikely(IS_ERR(retval)))
50839 + retval = strcpy(buf, "<path too long>");
50840 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50841 + retval[1] = '\0';
50842 +
50843 + return retval;
50844 +}
50845 +
50846 +static char *
50847 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50848 + char *buf, int buflen)
50849 +{
50850 + struct path path;
50851 + char *res;
50852 +
50853 + path.dentry = (struct dentry *)dentry;
50854 + path.mnt = (struct vfsmount *)vfsmnt;
50855 +
50856 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50857 + by the RBAC system */
50858 + res = gen_full_path(&path, &real_root, buf, buflen);
50859 +
50860 + return res;
50861 +}
50862 +
50863 +static char *
50864 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50865 + char *buf, int buflen)
50866 +{
50867 + char *res;
50868 + struct path path;
50869 + struct path root;
50870 + struct task_struct *reaper = &init_task;
50871 +
50872 + path.dentry = (struct dentry *)dentry;
50873 + path.mnt = (struct vfsmount *)vfsmnt;
50874 +
50875 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50876 + get_fs_root(reaper->fs, &root);
50877 +
50878 + write_seqlock(&rename_lock);
50879 + br_read_lock(vfsmount_lock);
50880 + res = gen_full_path(&path, &root, buf, buflen);
50881 + br_read_unlock(vfsmount_lock);
50882 + write_sequnlock(&rename_lock);
50883 +
50884 + path_put(&root);
50885 + return res;
50886 +}
50887 +
50888 +static char *
50889 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50890 +{
50891 + char *ret;
50892 + write_seqlock(&rename_lock);
50893 + br_read_lock(vfsmount_lock);
50894 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50895 + PAGE_SIZE);
50896 + br_read_unlock(vfsmount_lock);
50897 + write_sequnlock(&rename_lock);
50898 + return ret;
50899 +}
50900 +
50901 +static char *
50902 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50903 +{
50904 + char *ret;
50905 + char *buf;
50906 + int buflen;
50907 +
50908 + write_seqlock(&rename_lock);
50909 + br_read_lock(vfsmount_lock);
50910 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50911 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50912 + buflen = (int)(ret - buf);
50913 + if (buflen >= 5)
50914 + prepend(&ret, &buflen, "/proc", 5);
50915 + else
50916 + ret = strcpy(buf, "<path too long>");
50917 + br_read_unlock(vfsmount_lock);
50918 + write_sequnlock(&rename_lock);
50919 + return ret;
50920 +}
50921 +
50922 +char *
50923 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50924 +{
50925 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50926 + PAGE_SIZE);
50927 +}
50928 +
50929 +char *
50930 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50931 +{
50932 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50933 + PAGE_SIZE);
50934 +}
50935 +
50936 +char *
50937 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50938 +{
50939 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50940 + PAGE_SIZE);
50941 +}
50942 +
50943 +char *
50944 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50945 +{
50946 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50947 + PAGE_SIZE);
50948 +}
50949 +
50950 +char *
50951 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50952 +{
50953 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50954 + PAGE_SIZE);
50955 +}
50956 +
50957 +__inline__ __u32
50958 +to_gr_audit(const __u32 reqmode)
50959 +{
50960 + /* masks off auditable permission flags, then shifts them to create
50961 + auditing flags, and adds the special case of append auditing if
50962 + we're requesting write */
50963 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50964 +}
50965 +
50966 +struct acl_subject_label *
50967 +lookup_subject_map(const struct acl_subject_label *userp)
50968 +{
50969 + unsigned int index = shash(userp, subj_map_set.s_size);
50970 + struct subject_map *match;
50971 +
50972 + match = subj_map_set.s_hash[index];
50973 +
50974 + while (match && match->user != userp)
50975 + match = match->next;
50976 +
50977 + if (match != NULL)
50978 + return match->kernel;
50979 + else
50980 + return NULL;
50981 +}
50982 +
50983 +static void
50984 +insert_subj_map_entry(struct subject_map *subjmap)
50985 +{
50986 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50987 + struct subject_map **curr;
50988 +
50989 + subjmap->prev = NULL;
50990 +
50991 + curr = &subj_map_set.s_hash[index];
50992 + if (*curr != NULL)
50993 + (*curr)->prev = subjmap;
50994 +
50995 + subjmap->next = *curr;
50996 + *curr = subjmap;
50997 +
50998 + return;
50999 +}
51000 +
51001 +static struct acl_role_label *
51002 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51003 + const gid_t gid)
51004 +{
51005 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51006 + struct acl_role_label *match;
51007 + struct role_allowed_ip *ipp;
51008 + unsigned int x;
51009 + u32 curr_ip = task->signal->curr_ip;
51010 +
51011 + task->signal->saved_ip = curr_ip;
51012 +
51013 + match = acl_role_set.r_hash[index];
51014 +
51015 + while (match) {
51016 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51017 + for (x = 0; x < match->domain_child_num; x++) {
51018 + if (match->domain_children[x] == uid)
51019 + goto found;
51020 + }
51021 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51022 + break;
51023 + match = match->next;
51024 + }
51025 +found:
51026 + if (match == NULL) {
51027 + try_group:
51028 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51029 + match = acl_role_set.r_hash[index];
51030 +
51031 + while (match) {
51032 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51033 + for (x = 0; x < match->domain_child_num; x++) {
51034 + if (match->domain_children[x] == gid)
51035 + goto found2;
51036 + }
51037 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51038 + break;
51039 + match = match->next;
51040 + }
51041 +found2:
51042 + if (match == NULL)
51043 + match = default_role;
51044 + if (match->allowed_ips == NULL)
51045 + return match;
51046 + else {
51047 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51048 + if (likely
51049 + ((ntohl(curr_ip) & ipp->netmask) ==
51050 + (ntohl(ipp->addr) & ipp->netmask)))
51051 + return match;
51052 + }
51053 + match = default_role;
51054 + }
51055 + } else if (match->allowed_ips == NULL) {
51056 + return match;
51057 + } else {
51058 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51059 + if (likely
51060 + ((ntohl(curr_ip) & ipp->netmask) ==
51061 + (ntohl(ipp->addr) & ipp->netmask)))
51062 + return match;
51063 + }
51064 + goto try_group;
51065 + }
51066 +
51067 + return match;
51068 +}
51069 +
51070 +struct acl_subject_label *
51071 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51072 + const struct acl_role_label *role)
51073 +{
51074 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51075 + struct acl_subject_label *match;
51076 +
51077 + match = role->subj_hash[index];
51078 +
51079 + while (match && (match->inode != ino || match->device != dev ||
51080 + (match->mode & GR_DELETED))) {
51081 + match = match->next;
51082 + }
51083 +
51084 + if (match && !(match->mode & GR_DELETED))
51085 + return match;
51086 + else
51087 + return NULL;
51088 +}
51089 +
51090 +struct acl_subject_label *
51091 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51092 + const struct acl_role_label *role)
51093 +{
51094 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51095 + struct acl_subject_label *match;
51096 +
51097 + match = role->subj_hash[index];
51098 +
51099 + while (match && (match->inode != ino || match->device != dev ||
51100 + !(match->mode & GR_DELETED))) {
51101 + match = match->next;
51102 + }
51103 +
51104 + if (match && (match->mode & GR_DELETED))
51105 + return match;
51106 + else
51107 + return NULL;
51108 +}
51109 +
51110 +static struct acl_object_label *
51111 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51112 + const struct acl_subject_label *subj)
51113 +{
51114 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51115 + struct acl_object_label *match;
51116 +
51117 + match = subj->obj_hash[index];
51118 +
51119 + while (match && (match->inode != ino || match->device != dev ||
51120 + (match->mode & GR_DELETED))) {
51121 + match = match->next;
51122 + }
51123 +
51124 + if (match && !(match->mode & GR_DELETED))
51125 + return match;
51126 + else
51127 + return NULL;
51128 +}
51129 +
51130 +static struct acl_object_label *
51131 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51132 + const struct acl_subject_label *subj)
51133 +{
51134 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51135 + struct acl_object_label *match;
51136 +
51137 + match = subj->obj_hash[index];
51138 +
51139 + while (match && (match->inode != ino || match->device != dev ||
51140 + !(match->mode & GR_DELETED))) {
51141 + match = match->next;
51142 + }
51143 +
51144 + if (match && (match->mode & GR_DELETED))
51145 + return match;
51146 +
51147 + match = subj->obj_hash[index];
51148 +
51149 + while (match && (match->inode != ino || match->device != dev ||
51150 + (match->mode & GR_DELETED))) {
51151 + match = match->next;
51152 + }
51153 +
51154 + if (match && !(match->mode & GR_DELETED))
51155 + return match;
51156 + else
51157 + return NULL;
51158 +}
51159 +
51160 +static struct name_entry *
51161 +lookup_name_entry(const char *name)
51162 +{
51163 + unsigned int len = strlen(name);
51164 + unsigned int key = full_name_hash(name, len);
51165 + unsigned int index = key % name_set.n_size;
51166 + struct name_entry *match;
51167 +
51168 + match = name_set.n_hash[index];
51169 +
51170 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51171 + match = match->next;
51172 +
51173 + return match;
51174 +}
51175 +
51176 +static struct name_entry *
51177 +lookup_name_entry_create(const char *name)
51178 +{
51179 + unsigned int len = strlen(name);
51180 + unsigned int key = full_name_hash(name, len);
51181 + unsigned int index = key % name_set.n_size;
51182 + struct name_entry *match;
51183 +
51184 + match = name_set.n_hash[index];
51185 +
51186 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51187 + !match->deleted))
51188 + match = match->next;
51189 +
51190 + if (match && match->deleted)
51191 + return match;
51192 +
51193 + match = name_set.n_hash[index];
51194 +
51195 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51196 + match->deleted))
51197 + match = match->next;
51198 +
51199 + if (match && !match->deleted)
51200 + return match;
51201 + else
51202 + return NULL;
51203 +}
51204 +
51205 +static struct inodev_entry *
51206 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51207 +{
51208 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51209 + struct inodev_entry *match;
51210 +
51211 + match = inodev_set.i_hash[index];
51212 +
51213 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51214 + match = match->next;
51215 +
51216 + return match;
51217 +}
51218 +
51219 +static void
51220 +insert_inodev_entry(struct inodev_entry *entry)
51221 +{
51222 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51223 + inodev_set.i_size);
51224 + struct inodev_entry **curr;
51225 +
51226 + entry->prev = NULL;
51227 +
51228 + curr = &inodev_set.i_hash[index];
51229 + if (*curr != NULL)
51230 + (*curr)->prev = entry;
51231 +
51232 + entry->next = *curr;
51233 + *curr = entry;
51234 +
51235 + return;
51236 +}
51237 +
51238 +static void
51239 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51240 +{
51241 + unsigned int index =
51242 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51243 + struct acl_role_label **curr;
51244 + struct acl_role_label *tmp, *tmp2;
51245 +
51246 + curr = &acl_role_set.r_hash[index];
51247 +
51248 + /* simple case, slot is empty, just set it to our role */
51249 + if (*curr == NULL) {
51250 + *curr = role;
51251 + } else {
51252 + /* example:
51253 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51254 + 2 -> 3
51255 + */
51256 + /* first check to see if we can already be reached via this slot */
51257 + tmp = *curr;
51258 + while (tmp && tmp != role)
51259 + tmp = tmp->next;
51260 + if (tmp == role) {
51261 + /* we don't need to add ourselves to this slot's chain */
51262 + return;
51263 + }
51264 + /* we need to add ourselves to this chain, two cases */
51265 + if (role->next == NULL) {
51266 + /* simple case, append the current chain to our role */
51267 + role->next = *curr;
51268 + *curr = role;
51269 + } else {
51270 + /* 1 -> 2 -> 3 -> 4
51271 + 2 -> 3 -> 4
51272 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51273 + */
51274 + /* trickier case: walk our role's chain until we find
51275 + the role for the start of the current slot's chain */
51276 + tmp = role;
51277 + tmp2 = *curr;
51278 + while (tmp->next && tmp->next != tmp2)
51279 + tmp = tmp->next;
51280 + if (tmp->next == tmp2) {
51281 + /* from example above, we found 3, so just
51282 + replace this slot's chain with ours */
51283 + *curr = role;
51284 + } else {
51285 + /* we didn't find a subset of our role's chain
51286 + in the current slot's chain, so append their
51287 + chain to ours, and set us as the first role in
51288 + the slot's chain
51289 +
51290 + we could fold this case with the case above,
51291 + but making it explicit for clarity
51292 + */
51293 + tmp->next = tmp2;
51294 + *curr = role;
51295 + }
51296 + }
51297 + }
51298 +
51299 + return;
51300 +}
51301 +
51302 +static void
51303 +insert_acl_role_label(struct acl_role_label *role)
51304 +{
51305 + int i;
51306 +
51307 + if (role_list == NULL) {
51308 + role_list = role;
51309 + role->prev = NULL;
51310 + } else {
51311 + role->prev = role_list;
51312 + role_list = role;
51313 + }
51314 +
51315 + /* used for hash chains */
51316 + role->next = NULL;
51317 +
51318 + if (role->roletype & GR_ROLE_DOMAIN) {
51319 + for (i = 0; i < role->domain_child_num; i++)
51320 + __insert_acl_role_label(role, role->domain_children[i]);
51321 + } else
51322 + __insert_acl_role_label(role, role->uidgid);
51323 +}
51324 +
51325 +static int
51326 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51327 +{
51328 + struct name_entry **curr, *nentry;
51329 + struct inodev_entry *ientry;
51330 + unsigned int len = strlen(name);
51331 + unsigned int key = full_name_hash(name, len);
51332 + unsigned int index = key % name_set.n_size;
51333 +
51334 + curr = &name_set.n_hash[index];
51335 +
51336 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51337 + curr = &((*curr)->next);
51338 +
51339 + if (*curr != NULL)
51340 + return 1;
51341 +
51342 + nentry = acl_alloc(sizeof (struct name_entry));
51343 + if (nentry == NULL)
51344 + return 0;
51345 + ientry = acl_alloc(sizeof (struct inodev_entry));
51346 + if (ientry == NULL)
51347 + return 0;
51348 + ientry->nentry = nentry;
51349 +
51350 + nentry->key = key;
51351 + nentry->name = name;
51352 + nentry->inode = inode;
51353 + nentry->device = device;
51354 + nentry->len = len;
51355 + nentry->deleted = deleted;
51356 +
51357 + nentry->prev = NULL;
51358 + curr = &name_set.n_hash[index];
51359 + if (*curr != NULL)
51360 + (*curr)->prev = nentry;
51361 + nentry->next = *curr;
51362 + *curr = nentry;
51363 +
51364 + /* insert us into the table searchable by inode/dev */
51365 + insert_inodev_entry(ientry);
51366 +
51367 + return 1;
51368 +}
51369 +
51370 +static void
51371 +insert_acl_obj_label(struct acl_object_label *obj,
51372 + struct acl_subject_label *subj)
51373 +{
51374 + unsigned int index =
51375 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51376 + struct acl_object_label **curr;
51377 +
51378 +
51379 + obj->prev = NULL;
51380 +
51381 + curr = &subj->obj_hash[index];
51382 + if (*curr != NULL)
51383 + (*curr)->prev = obj;
51384 +
51385 + obj->next = *curr;
51386 + *curr = obj;
51387 +
51388 + return;
51389 +}
51390 +
51391 +static void
51392 +insert_acl_subj_label(struct acl_subject_label *obj,
51393 + struct acl_role_label *role)
51394 +{
51395 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51396 + struct acl_subject_label **curr;
51397 +
51398 + obj->prev = NULL;
51399 +
51400 + curr = &role->subj_hash[index];
51401 + if (*curr != NULL)
51402 + (*curr)->prev = obj;
51403 +
51404 + obj->next = *curr;
51405 + *curr = obj;
51406 +
51407 + return;
51408 +}
51409 +
51410 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51411 +
51412 +static void *
51413 +create_table(__u32 * len, int elementsize)
51414 +{
51415 + unsigned int table_sizes[] = {
51416 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51417 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51418 + 4194301, 8388593, 16777213, 33554393, 67108859
51419 + };
51420 + void *newtable = NULL;
51421 + unsigned int pwr = 0;
51422 +
51423 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51424 + table_sizes[pwr] <= *len)
51425 + pwr++;
51426 +
51427 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51428 + return newtable;
51429 +
51430 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51431 + newtable =
51432 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51433 + else
51434 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51435 +
51436 + *len = table_sizes[pwr];
51437 +
51438 + return newtable;
51439 +}
51440 +
51441 +static int
51442 +init_variables(const struct gr_arg *arg)
51443 +{
51444 + struct task_struct *reaper = &init_task;
51445 + unsigned int stacksize;
51446 +
51447 + subj_map_set.s_size = arg->role_db.num_subjects;
51448 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51449 + name_set.n_size = arg->role_db.num_objects;
51450 + inodev_set.i_size = arg->role_db.num_objects;
51451 +
51452 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51453 + !name_set.n_size || !inodev_set.i_size)
51454 + return 1;
51455 +
51456 + if (!gr_init_uidset())
51457 + return 1;
51458 +
51459 + /* set up the stack that holds allocation info */
51460 +
51461 + stacksize = arg->role_db.num_pointers + 5;
51462 +
51463 + if (!acl_alloc_stack_init(stacksize))
51464 + return 1;
51465 +
51466 + /* grab reference for the real root dentry and vfsmount */
51467 + get_fs_root(reaper->fs, &real_root);
51468 +
51469 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51470 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51471 +#endif
51472 +
51473 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51474 + if (fakefs_obj_rw == NULL)
51475 + return 1;
51476 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51477 +
51478 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51479 + if (fakefs_obj_rwx == NULL)
51480 + return 1;
51481 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51482 +
51483 + subj_map_set.s_hash =
51484 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51485 + acl_role_set.r_hash =
51486 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51487 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51488 + inodev_set.i_hash =
51489 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51490 +
51491 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51492 + !name_set.n_hash || !inodev_set.i_hash)
51493 + return 1;
51494 +
51495 + memset(subj_map_set.s_hash, 0,
51496 + sizeof(struct subject_map *) * subj_map_set.s_size);
51497 + memset(acl_role_set.r_hash, 0,
51498 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51499 + memset(name_set.n_hash, 0,
51500 + sizeof (struct name_entry *) * name_set.n_size);
51501 + memset(inodev_set.i_hash, 0,
51502 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51503 +
51504 + return 0;
51505 +}
51506 +
51507 +/* free information not needed after startup
51508 + currently contains user->kernel pointer mappings for subjects
51509 +*/
51510 +
51511 +static void
51512 +free_init_variables(void)
51513 +{
51514 + __u32 i;
51515 +
51516 + if (subj_map_set.s_hash) {
51517 + for (i = 0; i < subj_map_set.s_size; i++) {
51518 + if (subj_map_set.s_hash[i]) {
51519 + kfree(subj_map_set.s_hash[i]);
51520 + subj_map_set.s_hash[i] = NULL;
51521 + }
51522 + }
51523 +
51524 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51525 + PAGE_SIZE)
51526 + kfree(subj_map_set.s_hash);
51527 + else
51528 + vfree(subj_map_set.s_hash);
51529 + }
51530 +
51531 + return;
51532 +}
51533 +
51534 +static void
51535 +free_variables(void)
51536 +{
51537 + struct acl_subject_label *s;
51538 + struct acl_role_label *r;
51539 + struct task_struct *task, *task2;
51540 + unsigned int x;
51541 +
51542 + gr_clear_learn_entries();
51543 +
51544 + read_lock(&tasklist_lock);
51545 + do_each_thread(task2, task) {
51546 + task->acl_sp_role = 0;
51547 + task->acl_role_id = 0;
51548 + task->acl = NULL;
51549 + task->role = NULL;
51550 + } while_each_thread(task2, task);
51551 + read_unlock(&tasklist_lock);
51552 +
51553 + /* release the reference to the real root dentry and vfsmount */
51554 + path_put(&real_root);
51555 + memset(&real_root, 0, sizeof(real_root));
51556 +
51557 + /* free all object hash tables */
51558 +
51559 + FOR_EACH_ROLE_START(r)
51560 + if (r->subj_hash == NULL)
51561 + goto next_role;
51562 + FOR_EACH_SUBJECT_START(r, s, x)
51563 + if (s->obj_hash == NULL)
51564 + break;
51565 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51566 + kfree(s->obj_hash);
51567 + else
51568 + vfree(s->obj_hash);
51569 + FOR_EACH_SUBJECT_END(s, x)
51570 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51571 + if (s->obj_hash == NULL)
51572 + break;
51573 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51574 + kfree(s->obj_hash);
51575 + else
51576 + vfree(s->obj_hash);
51577 + FOR_EACH_NESTED_SUBJECT_END(s)
51578 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51579 + kfree(r->subj_hash);
51580 + else
51581 + vfree(r->subj_hash);
51582 + r->subj_hash = NULL;
51583 +next_role:
51584 + FOR_EACH_ROLE_END(r)
51585 +
51586 + acl_free_all();
51587 +
51588 + if (acl_role_set.r_hash) {
51589 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51590 + PAGE_SIZE)
51591 + kfree(acl_role_set.r_hash);
51592 + else
51593 + vfree(acl_role_set.r_hash);
51594 + }
51595 + if (name_set.n_hash) {
51596 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51597 + PAGE_SIZE)
51598 + kfree(name_set.n_hash);
51599 + else
51600 + vfree(name_set.n_hash);
51601 + }
51602 +
51603 + if (inodev_set.i_hash) {
51604 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51605 + PAGE_SIZE)
51606 + kfree(inodev_set.i_hash);
51607 + else
51608 + vfree(inodev_set.i_hash);
51609 + }
51610 +
51611 + gr_free_uidset();
51612 +
51613 + memset(&name_set, 0, sizeof (struct name_db));
51614 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51615 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51616 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51617 +
51618 + default_role = NULL;
51619 + kernel_role = NULL;
51620 + role_list = NULL;
51621 +
51622 + return;
51623 +}
51624 +
51625 +static __u32
51626 +count_user_objs(struct acl_object_label *userp)
51627 +{
51628 + struct acl_object_label o_tmp;
51629 + __u32 num = 0;
51630 +
51631 + while (userp) {
51632 + if (copy_from_user(&o_tmp, userp,
51633 + sizeof (struct acl_object_label)))
51634 + break;
51635 +
51636 + userp = o_tmp.prev;
51637 + num++;
51638 + }
51639 +
51640 + return num;
51641 +}
51642 +
51643 +static struct acl_subject_label *
51644 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51645 +
51646 +static int
51647 +copy_user_glob(struct acl_object_label *obj)
51648 +{
51649 + struct acl_object_label *g_tmp, **guser;
51650 + unsigned int len;
51651 + char *tmp;
51652 +
51653 + if (obj->globbed == NULL)
51654 + return 0;
51655 +
51656 + guser = &obj->globbed;
51657 + while (*guser) {
51658 + g_tmp = (struct acl_object_label *)
51659 + acl_alloc(sizeof (struct acl_object_label));
51660 + if (g_tmp == NULL)
51661 + return -ENOMEM;
51662 +
51663 + if (copy_from_user(g_tmp, *guser,
51664 + sizeof (struct acl_object_label)))
51665 + return -EFAULT;
51666 +
51667 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51668 +
51669 + if (!len || len >= PATH_MAX)
51670 + return -EINVAL;
51671 +
51672 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51673 + return -ENOMEM;
51674 +
51675 + if (copy_from_user(tmp, g_tmp->filename, len))
51676 + return -EFAULT;
51677 + tmp[len-1] = '\0';
51678 + g_tmp->filename = tmp;
51679 +
51680 + *guser = g_tmp;
51681 + guser = &(g_tmp->next);
51682 + }
51683 +
51684 + return 0;
51685 +}
51686 +
51687 +static int
51688 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51689 + struct acl_role_label *role)
51690 +{
51691 + struct acl_object_label *o_tmp;
51692 + unsigned int len;
51693 + int ret;
51694 + char *tmp;
51695 +
51696 + while (userp) {
51697 + if ((o_tmp = (struct acl_object_label *)
51698 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51699 + return -ENOMEM;
51700 +
51701 + if (copy_from_user(o_tmp, userp,
51702 + sizeof (struct acl_object_label)))
51703 + return -EFAULT;
51704 +
51705 + userp = o_tmp->prev;
51706 +
51707 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51708 +
51709 + if (!len || len >= PATH_MAX)
51710 + return -EINVAL;
51711 +
51712 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51713 + return -ENOMEM;
51714 +
51715 + if (copy_from_user(tmp, o_tmp->filename, len))
51716 + return -EFAULT;
51717 + tmp[len-1] = '\0';
51718 + o_tmp->filename = tmp;
51719 +
51720 + insert_acl_obj_label(o_tmp, subj);
51721 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51722 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51723 + return -ENOMEM;
51724 +
51725 + ret = copy_user_glob(o_tmp);
51726 + if (ret)
51727 + return ret;
51728 +
51729 + if (o_tmp->nested) {
51730 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51731 + if (IS_ERR(o_tmp->nested))
51732 + return PTR_ERR(o_tmp->nested);
51733 +
51734 + /* insert into nested subject list */
51735 + o_tmp->nested->next = role->hash->first;
51736 + role->hash->first = o_tmp->nested;
51737 + }
51738 + }
51739 +
51740 + return 0;
51741 +}
51742 +
51743 +static __u32
51744 +count_user_subjs(struct acl_subject_label *userp)
51745 +{
51746 + struct acl_subject_label s_tmp;
51747 + __u32 num = 0;
51748 +
51749 + while (userp) {
51750 + if (copy_from_user(&s_tmp, userp,
51751 + sizeof (struct acl_subject_label)))
51752 + break;
51753 +
51754 + userp = s_tmp.prev;
51755 + /* do not count nested subjects against this count, since
51756 + they are not included in the hash table, but are
51757 + attached to objects. We have already counted
51758 + the subjects in userspace for the allocation
51759 + stack
51760 + */
51761 + if (!(s_tmp.mode & GR_NESTED))
51762 + num++;
51763 + }
51764 +
51765 + return num;
51766 +}
51767 +
51768 +static int
51769 +copy_user_allowedips(struct acl_role_label *rolep)
51770 +{
51771 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51772 +
51773 + ruserip = rolep->allowed_ips;
51774 +
51775 + while (ruserip) {
51776 + rlast = rtmp;
51777 +
51778 + if ((rtmp = (struct role_allowed_ip *)
51779 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51780 + return -ENOMEM;
51781 +
51782 + if (copy_from_user(rtmp, ruserip,
51783 + sizeof (struct role_allowed_ip)))
51784 + return -EFAULT;
51785 +
51786 + ruserip = rtmp->prev;
51787 +
51788 + if (!rlast) {
51789 + rtmp->prev = NULL;
51790 + rolep->allowed_ips = rtmp;
51791 + } else {
51792 + rlast->next = rtmp;
51793 + rtmp->prev = rlast;
51794 + }
51795 +
51796 + if (!ruserip)
51797 + rtmp->next = NULL;
51798 + }
51799 +
51800 + return 0;
51801 +}
51802 +
51803 +static int
51804 +copy_user_transitions(struct acl_role_label *rolep)
51805 +{
51806 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51807 +
51808 + unsigned int len;
51809 + char *tmp;
51810 +
51811 + rusertp = rolep->transitions;
51812 +
51813 + while (rusertp) {
51814 + rlast = rtmp;
51815 +
51816 + if ((rtmp = (struct role_transition *)
51817 + acl_alloc(sizeof (struct role_transition))) == NULL)
51818 + return -ENOMEM;
51819 +
51820 + if (copy_from_user(rtmp, rusertp,
51821 + sizeof (struct role_transition)))
51822 + return -EFAULT;
51823 +
51824 + rusertp = rtmp->prev;
51825 +
51826 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51827 +
51828 + if (!len || len >= GR_SPROLE_LEN)
51829 + return -EINVAL;
51830 +
51831 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51832 + return -ENOMEM;
51833 +
51834 + if (copy_from_user(tmp, rtmp->rolename, len))
51835 + return -EFAULT;
51836 + tmp[len-1] = '\0';
51837 + rtmp->rolename = tmp;
51838 +
51839 + if (!rlast) {
51840 + rtmp->prev = NULL;
51841 + rolep->transitions = rtmp;
51842 + } else {
51843 + rlast->next = rtmp;
51844 + rtmp->prev = rlast;
51845 + }
51846 +
51847 + if (!rusertp)
51848 + rtmp->next = NULL;
51849 + }
51850 +
51851 + return 0;
51852 +}
51853 +
51854 +static struct acl_subject_label *
51855 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51856 +{
51857 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51858 + unsigned int len;
51859 + char *tmp;
51860 + __u32 num_objs;
51861 + struct acl_ip_label **i_tmp, *i_utmp2;
51862 + struct gr_hash_struct ghash;
51863 + struct subject_map *subjmap;
51864 + unsigned int i_num;
51865 + int err;
51866 +
51867 + s_tmp = lookup_subject_map(userp);
51868 +
51869 + /* we've already copied this subject into the kernel, just return
51870 + the reference to it, and don't copy it over again
51871 + */
51872 + if (s_tmp)
51873 + return(s_tmp);
51874 +
51875 + if ((s_tmp = (struct acl_subject_label *)
51876 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51877 + return ERR_PTR(-ENOMEM);
51878 +
51879 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51880 + if (subjmap == NULL)
51881 + return ERR_PTR(-ENOMEM);
51882 +
51883 + subjmap->user = userp;
51884 + subjmap->kernel = s_tmp;
51885 + insert_subj_map_entry(subjmap);
51886 +
51887 + if (copy_from_user(s_tmp, userp,
51888 + sizeof (struct acl_subject_label)))
51889 + return ERR_PTR(-EFAULT);
51890 +
51891 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51892 +
51893 + if (!len || len >= PATH_MAX)
51894 + return ERR_PTR(-EINVAL);
51895 +
51896 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51897 + return ERR_PTR(-ENOMEM);
51898 +
51899 + if (copy_from_user(tmp, s_tmp->filename, len))
51900 + return ERR_PTR(-EFAULT);
51901 + tmp[len-1] = '\0';
51902 + s_tmp->filename = tmp;
51903 +
51904 + if (!strcmp(s_tmp->filename, "/"))
51905 + role->root_label = s_tmp;
51906 +
51907 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51908 + return ERR_PTR(-EFAULT);
51909 +
51910 + /* copy user and group transition tables */
51911 +
51912 + if (s_tmp->user_trans_num) {
51913 + uid_t *uidlist;
51914 +
51915 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51916 + if (uidlist == NULL)
51917 + return ERR_PTR(-ENOMEM);
51918 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51919 + return ERR_PTR(-EFAULT);
51920 +
51921 + s_tmp->user_transitions = uidlist;
51922 + }
51923 +
51924 + if (s_tmp->group_trans_num) {
51925 + gid_t *gidlist;
51926 +
51927 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51928 + if (gidlist == NULL)
51929 + return ERR_PTR(-ENOMEM);
51930 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51931 + return ERR_PTR(-EFAULT);
51932 +
51933 + s_tmp->group_transitions = gidlist;
51934 + }
51935 +
51936 + /* set up object hash table */
51937 + num_objs = count_user_objs(ghash.first);
51938 +
51939 + s_tmp->obj_hash_size = num_objs;
51940 + s_tmp->obj_hash =
51941 + (struct acl_object_label **)
51942 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51943 +
51944 + if (!s_tmp->obj_hash)
51945 + return ERR_PTR(-ENOMEM);
51946 +
51947 + memset(s_tmp->obj_hash, 0,
51948 + s_tmp->obj_hash_size *
51949 + sizeof (struct acl_object_label *));
51950 +
51951 + /* add in objects */
51952 + err = copy_user_objs(ghash.first, s_tmp, role);
51953 +
51954 + if (err)
51955 + return ERR_PTR(err);
51956 +
51957 + /* set pointer for parent subject */
51958 + if (s_tmp->parent_subject) {
51959 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51960 +
51961 + if (IS_ERR(s_tmp2))
51962 + return s_tmp2;
51963 +
51964 + s_tmp->parent_subject = s_tmp2;
51965 + }
51966 +
51967 + /* add in ip acls */
51968 +
51969 + if (!s_tmp->ip_num) {
51970 + s_tmp->ips = NULL;
51971 + goto insert;
51972 + }
51973 +
51974 + i_tmp =
51975 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51976 + sizeof (struct acl_ip_label *));
51977 +
51978 + if (!i_tmp)
51979 + return ERR_PTR(-ENOMEM);
51980 +
51981 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51982 + *(i_tmp + i_num) =
51983 + (struct acl_ip_label *)
51984 + acl_alloc(sizeof (struct acl_ip_label));
51985 + if (!*(i_tmp + i_num))
51986 + return ERR_PTR(-ENOMEM);
51987 +
51988 + if (copy_from_user
51989 + (&i_utmp2, s_tmp->ips + i_num,
51990 + sizeof (struct acl_ip_label *)))
51991 + return ERR_PTR(-EFAULT);
51992 +
51993 + if (copy_from_user
51994 + (*(i_tmp + i_num), i_utmp2,
51995 + sizeof (struct acl_ip_label)))
51996 + return ERR_PTR(-EFAULT);
51997 +
51998 + if ((*(i_tmp + i_num))->iface == NULL)
51999 + continue;
52000 +
52001 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52002 + if (!len || len >= IFNAMSIZ)
52003 + return ERR_PTR(-EINVAL);
52004 + tmp = acl_alloc(len);
52005 + if (tmp == NULL)
52006 + return ERR_PTR(-ENOMEM);
52007 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52008 + return ERR_PTR(-EFAULT);
52009 + (*(i_tmp + i_num))->iface = tmp;
52010 + }
52011 +
52012 + s_tmp->ips = i_tmp;
52013 +
52014 +insert:
52015 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52016 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52017 + return ERR_PTR(-ENOMEM);
52018 +
52019 + return s_tmp;
52020 +}
52021 +
52022 +static int
52023 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52024 +{
52025 + struct acl_subject_label s_pre;
52026 + struct acl_subject_label * ret;
52027 + int err;
52028 +
52029 + while (userp) {
52030 + if (copy_from_user(&s_pre, userp,
52031 + sizeof (struct acl_subject_label)))
52032 + return -EFAULT;
52033 +
52034 + /* do not add nested subjects here, add
52035 + while parsing objects
52036 + */
52037 +
52038 + if (s_pre.mode & GR_NESTED) {
52039 + userp = s_pre.prev;
52040 + continue;
52041 + }
52042 +
52043 + ret = do_copy_user_subj(userp, role);
52044 +
52045 + err = PTR_ERR(ret);
52046 + if (IS_ERR(ret))
52047 + return err;
52048 +
52049 + insert_acl_subj_label(ret, role);
52050 +
52051 + userp = s_pre.prev;
52052 + }
52053 +
52054 + return 0;
52055 +}
52056 +
52057 +static int
52058 +copy_user_acl(struct gr_arg *arg)
52059 +{
52060 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52061 + struct sprole_pw *sptmp;
52062 + struct gr_hash_struct *ghash;
52063 + uid_t *domainlist;
52064 + unsigned int r_num;
52065 + unsigned int len;
52066 + char *tmp;
52067 + int err = 0;
52068 + __u16 i;
52069 + __u32 num_subjs;
52070 +
52071 + /* we need a default and kernel role */
52072 + if (arg->role_db.num_roles < 2)
52073 + return -EINVAL;
52074 +
52075 + /* copy special role authentication info from userspace */
52076 +
52077 + num_sprole_pws = arg->num_sprole_pws;
52078 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52079 +
52080 + if (!acl_special_roles && num_sprole_pws)
52081 + return -ENOMEM;
52082 +
52083 + for (i = 0; i < num_sprole_pws; i++) {
52084 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52085 + if (!sptmp)
52086 + return -ENOMEM;
52087 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52088 + sizeof (struct sprole_pw)))
52089 + return -EFAULT;
52090 +
52091 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52092 +
52093 + if (!len || len >= GR_SPROLE_LEN)
52094 + return -EINVAL;
52095 +
52096 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52097 + return -ENOMEM;
52098 +
52099 + if (copy_from_user(tmp, sptmp->rolename, len))
52100 + return -EFAULT;
52101 +
52102 + tmp[len-1] = '\0';
52103 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52104 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52105 +#endif
52106 + sptmp->rolename = tmp;
52107 + acl_special_roles[i] = sptmp;
52108 + }
52109 +
52110 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52111 +
52112 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52113 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52114 +
52115 + if (!r_tmp)
52116 + return -ENOMEM;
52117 +
52118 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52119 + sizeof (struct acl_role_label *)))
52120 + return -EFAULT;
52121 +
52122 + if (copy_from_user(r_tmp, r_utmp2,
52123 + sizeof (struct acl_role_label)))
52124 + return -EFAULT;
52125 +
52126 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52127 +
52128 + if (!len || len >= PATH_MAX)
52129 + return -EINVAL;
52130 +
52131 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52132 + return -ENOMEM;
52133 +
52134 + if (copy_from_user(tmp, r_tmp->rolename, len))
52135 + return -EFAULT;
52136 +
52137 + tmp[len-1] = '\0';
52138 + r_tmp->rolename = tmp;
52139 +
52140 + if (!strcmp(r_tmp->rolename, "default")
52141 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52142 + default_role = r_tmp;
52143 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52144 + kernel_role = r_tmp;
52145 + }
52146 +
52147 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52148 + return -ENOMEM;
52149 +
52150 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52151 + return -EFAULT;
52152 +
52153 + r_tmp->hash = ghash;
52154 +
52155 + num_subjs = count_user_subjs(r_tmp->hash->first);
52156 +
52157 + r_tmp->subj_hash_size = num_subjs;
52158 + r_tmp->subj_hash =
52159 + (struct acl_subject_label **)
52160 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52161 +
52162 + if (!r_tmp->subj_hash)
52163 + return -ENOMEM;
52164 +
52165 + err = copy_user_allowedips(r_tmp);
52166 + if (err)
52167 + return err;
52168 +
52169 + /* copy domain info */
52170 + if (r_tmp->domain_children != NULL) {
52171 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52172 + if (domainlist == NULL)
52173 + return -ENOMEM;
52174 +
52175 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52176 + return -EFAULT;
52177 +
52178 + r_tmp->domain_children = domainlist;
52179 + }
52180 +
52181 + err = copy_user_transitions(r_tmp);
52182 + if (err)
52183 + return err;
52184 +
52185 + memset(r_tmp->subj_hash, 0,
52186 + r_tmp->subj_hash_size *
52187 + sizeof (struct acl_subject_label *));
52188 +
52189 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52190 +
52191 + if (err)
52192 + return err;
52193 +
52194 + /* set nested subject list to null */
52195 + r_tmp->hash->first = NULL;
52196 +
52197 + insert_acl_role_label(r_tmp);
52198 + }
52199 +
52200 + if (default_role == NULL || kernel_role == NULL)
52201 + return -EINVAL;
52202 +
52203 + return err;
52204 +}
52205 +
52206 +static int
52207 +gracl_init(struct gr_arg *args)
52208 +{
52209 + int error = 0;
52210 +
52211 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52212 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52213 +
52214 + if (init_variables(args)) {
52215 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52216 + error = -ENOMEM;
52217 + free_variables();
52218 + goto out;
52219 + }
52220 +
52221 + error = copy_user_acl(args);
52222 + free_init_variables();
52223 + if (error) {
52224 + free_variables();
52225 + goto out;
52226 + }
52227 +
52228 + if ((error = gr_set_acls(0))) {
52229 + free_variables();
52230 + goto out;
52231 + }
52232 +
52233 + pax_open_kernel();
52234 + gr_status |= GR_READY;
52235 + pax_close_kernel();
52236 +
52237 + out:
52238 + return error;
52239 +}
52240 +
52241 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52242 +
52243 +static int
52244 +glob_match(const char *p, const char *n)
52245 +{
52246 + char c;
52247 +
52248 + while ((c = *p++) != '\0') {
52249 + switch (c) {
52250 + case '?':
52251 + if (*n == '\0')
52252 + return 1;
52253 + else if (*n == '/')
52254 + return 1;
52255 + break;
52256 + case '\\':
52257 + if (*n != c)
52258 + return 1;
52259 + break;
52260 + case '*':
52261 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52262 + if (*n == '/')
52263 + return 1;
52264 + else if (c == '?') {
52265 + if (*n == '\0')
52266 + return 1;
52267 + else
52268 + ++n;
52269 + }
52270 + }
52271 + if (c == '\0') {
52272 + return 0;
52273 + } else {
52274 + const char *endp;
52275 +
52276 + if ((endp = strchr(n, '/')) == NULL)
52277 + endp = n + strlen(n);
52278 +
52279 + if (c == '[') {
52280 + for (--p; n < endp; ++n)
52281 + if (!glob_match(p, n))
52282 + return 0;
52283 + } else if (c == '/') {
52284 + while (*n != '\0' && *n != '/')
52285 + ++n;
52286 + if (*n == '/' && !glob_match(p, n + 1))
52287 + return 0;
52288 + } else {
52289 + for (--p; n < endp; ++n)
52290 + if (*n == c && !glob_match(p, n))
52291 + return 0;
52292 + }
52293 +
52294 + return 1;
52295 + }
52296 + case '[':
52297 + {
52298 + int not;
52299 + char cold;
52300 +
52301 + if (*n == '\0' || *n == '/')
52302 + return 1;
52303 +
52304 + not = (*p == '!' || *p == '^');
52305 + if (not)
52306 + ++p;
52307 +
52308 + c = *p++;
52309 + for (;;) {
52310 + unsigned char fn = (unsigned char)*n;
52311 +
52312 + if (c == '\0')
52313 + return 1;
52314 + else {
52315 + if (c == fn)
52316 + goto matched;
52317 + cold = c;
52318 + c = *p++;
52319 +
52320 + if (c == '-' && *p != ']') {
52321 + unsigned char cend = *p++;
52322 +
52323 + if (cend == '\0')
52324 + return 1;
52325 +
52326 + if (cold <= fn && fn <= cend)
52327 + goto matched;
52328 +
52329 + c = *p++;
52330 + }
52331 + }
52332 +
52333 + if (c == ']')
52334 + break;
52335 + }
52336 + if (!not)
52337 + return 1;
52338 + break;
52339 + matched:
52340 + while (c != ']') {
52341 + if (c == '\0')
52342 + return 1;
52343 +
52344 + c = *p++;
52345 + }
52346 + if (not)
52347 + return 1;
52348 + }
52349 + break;
52350 + default:
52351 + if (c != *n)
52352 + return 1;
52353 + }
52354 +
52355 + ++n;
52356 + }
52357 +
52358 + if (*n == '\0')
52359 + return 0;
52360 +
52361 + if (*n == '/')
52362 + return 0;
52363 +
52364 + return 1;
52365 +}
52366 +
52367 +static struct acl_object_label *
52368 +chk_glob_label(struct acl_object_label *globbed,
52369 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52370 +{
52371 + struct acl_object_label *tmp;
52372 +
52373 + if (*path == NULL)
52374 + *path = gr_to_filename_nolock(dentry, mnt);
52375 +
52376 + tmp = globbed;
52377 +
52378 + while (tmp) {
52379 + if (!glob_match(tmp->filename, *path))
52380 + return tmp;
52381 + tmp = tmp->next;
52382 + }
52383 +
52384 + return NULL;
52385 +}
52386 +
52387 +static struct acl_object_label *
52388 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52389 + const ino_t curr_ino, const dev_t curr_dev,
52390 + const struct acl_subject_label *subj, char **path, const int checkglob)
52391 +{
52392 + struct acl_subject_label *tmpsubj;
52393 + struct acl_object_label *retval;
52394 + struct acl_object_label *retval2;
52395 +
52396 + tmpsubj = (struct acl_subject_label *) subj;
52397 + read_lock(&gr_inode_lock);
52398 + do {
52399 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52400 + if (retval) {
52401 + if (checkglob && retval->globbed) {
52402 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52403 + if (retval2)
52404 + retval = retval2;
52405 + }
52406 + break;
52407 + }
52408 + } while ((tmpsubj = tmpsubj->parent_subject));
52409 + read_unlock(&gr_inode_lock);
52410 +
52411 + return retval;
52412 +}
52413 +
52414 +static __inline__ struct acl_object_label *
52415 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52416 + struct dentry *curr_dentry,
52417 + const struct acl_subject_label *subj, char **path, const int checkglob)
52418 +{
52419 + int newglob = checkglob;
52420 + ino_t inode;
52421 + dev_t device;
52422 +
52423 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52424 + as we don't want a / * rule to match instead of the / object
52425 + don't do this for create lookups that call this function though, since they're looking up
52426 + on the parent and thus need globbing checks on all paths
52427 + */
52428 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52429 + newglob = GR_NO_GLOB;
52430 +
52431 + spin_lock(&curr_dentry->d_lock);
52432 + inode = curr_dentry->d_inode->i_ino;
52433 + device = __get_dev(curr_dentry);
52434 + spin_unlock(&curr_dentry->d_lock);
52435 +
52436 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52437 +}
52438 +
52439 +static struct acl_object_label *
52440 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52441 + const struct acl_subject_label *subj, char *path, const int checkglob)
52442 +{
52443 + struct dentry *dentry = (struct dentry *) l_dentry;
52444 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52445 + struct mount *real_mnt = real_mount(mnt);
52446 + struct acl_object_label *retval;
52447 + struct dentry *parent;
52448 +
52449 + write_seqlock(&rename_lock);
52450 + br_read_lock(vfsmount_lock);
52451 +
52452 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52453 +#ifdef CONFIG_NET
52454 + mnt == sock_mnt ||
52455 +#endif
52456 +#ifdef CONFIG_HUGETLBFS
52457 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52458 +#endif
52459 + /* ignore Eric Biederman */
52460 + IS_PRIVATE(l_dentry->d_inode))) {
52461 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52462 + goto out;
52463 + }
52464 +
52465 + for (;;) {
52466 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52467 + break;
52468 +
52469 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52470 + if (!mnt_has_parent(real_mnt))
52471 + break;
52472 +
52473 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52474 + if (retval != NULL)
52475 + goto out;
52476 +
52477 + dentry = real_mnt->mnt_mountpoint;
52478 + real_mnt = real_mnt->mnt_parent;
52479 + mnt = &real_mnt->mnt;
52480 + continue;
52481 + }
52482 +
52483 + parent = dentry->d_parent;
52484 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52485 + if (retval != NULL)
52486 + goto out;
52487 +
52488 + dentry = parent;
52489 + }
52490 +
52491 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52492 +
52493 + /* real_root is pinned so we don't have to hold a reference */
52494 + if (retval == NULL)
52495 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52496 +out:
52497 + br_read_unlock(vfsmount_lock);
52498 + write_sequnlock(&rename_lock);
52499 +
52500 + BUG_ON(retval == NULL);
52501 +
52502 + return retval;
52503 +}
52504 +
52505 +static __inline__ struct acl_object_label *
52506 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52507 + const struct acl_subject_label *subj)
52508 +{
52509 + char *path = NULL;
52510 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52511 +}
52512 +
52513 +static __inline__ struct acl_object_label *
52514 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52515 + const struct acl_subject_label *subj)
52516 +{
52517 + char *path = NULL;
52518 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52519 +}
52520 +
52521 +static __inline__ struct acl_object_label *
52522 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52523 + const struct acl_subject_label *subj, char *path)
52524 +{
52525 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52526 +}
52527 +
52528 +static struct acl_subject_label *
52529 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52530 + const struct acl_role_label *role)
52531 +{
52532 + struct dentry *dentry = (struct dentry *) l_dentry;
52533 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52534 + struct mount *real_mnt = real_mount(mnt);
52535 + struct acl_subject_label *retval;
52536 + struct dentry *parent;
52537 +
52538 + write_seqlock(&rename_lock);
52539 + br_read_lock(vfsmount_lock);
52540 +
52541 + for (;;) {
52542 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52543 + break;
52544 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52545 + if (!mnt_has_parent(real_mnt))
52546 + break;
52547 +
52548 + spin_lock(&dentry->d_lock);
52549 + read_lock(&gr_inode_lock);
52550 + retval =
52551 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52552 + __get_dev(dentry), role);
52553 + read_unlock(&gr_inode_lock);
52554 + spin_unlock(&dentry->d_lock);
52555 + if (retval != NULL)
52556 + goto out;
52557 +
52558 + dentry = real_mnt->mnt_mountpoint;
52559 + real_mnt = real_mnt->mnt_parent;
52560 + mnt = &real_mnt->mnt;
52561 + continue;
52562 + }
52563 +
52564 + spin_lock(&dentry->d_lock);
52565 + read_lock(&gr_inode_lock);
52566 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52567 + __get_dev(dentry), role);
52568 + read_unlock(&gr_inode_lock);
52569 + parent = dentry->d_parent;
52570 + spin_unlock(&dentry->d_lock);
52571 +
52572 + if (retval != NULL)
52573 + goto out;
52574 +
52575 + dentry = parent;
52576 + }
52577 +
52578 + spin_lock(&dentry->d_lock);
52579 + read_lock(&gr_inode_lock);
52580 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52581 + __get_dev(dentry), role);
52582 + read_unlock(&gr_inode_lock);
52583 + spin_unlock(&dentry->d_lock);
52584 +
52585 + if (unlikely(retval == NULL)) {
52586 + /* real_root is pinned, we don't need to hold a reference */
52587 + read_lock(&gr_inode_lock);
52588 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52589 + __get_dev(real_root.dentry), role);
52590 + read_unlock(&gr_inode_lock);
52591 + }
52592 +out:
52593 + br_read_unlock(vfsmount_lock);
52594 + write_sequnlock(&rename_lock);
52595 +
52596 + BUG_ON(retval == NULL);
52597 +
52598 + return retval;
52599 +}
52600 +
52601 +static void
52602 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52603 +{
52604 + struct task_struct *task = current;
52605 + const struct cred *cred = current_cred();
52606 +
52607 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52608 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52609 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52610 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52611 +
52612 + return;
52613 +}
52614 +
52615 +static void
52616 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52617 +{
52618 + struct task_struct *task = current;
52619 + const struct cred *cred = current_cred();
52620 +
52621 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52622 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52623 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52624 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52625 +
52626 + return;
52627 +}
52628 +
52629 +static void
52630 +gr_log_learn_id_change(const char type, const unsigned int real,
52631 + const unsigned int effective, const unsigned int fs)
52632 +{
52633 + struct task_struct *task = current;
52634 + const struct cred *cred = current_cred();
52635 +
52636 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52637 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52638 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52639 + type, real, effective, fs, &task->signal->saved_ip);
52640 +
52641 + return;
52642 +}
52643 +
52644 +__u32
52645 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52646 + const struct vfsmount * mnt)
52647 +{
52648 + __u32 retval = mode;
52649 + struct acl_subject_label *curracl;
52650 + struct acl_object_label *currobj;
52651 +
52652 + if (unlikely(!(gr_status & GR_READY)))
52653 + return (mode & ~GR_AUDITS);
52654 +
52655 + curracl = current->acl;
52656 +
52657 + currobj = chk_obj_label(dentry, mnt, curracl);
52658 + retval = currobj->mode & mode;
52659 +
52660 + /* if we're opening a specified transfer file for writing
52661 + (e.g. /dev/initctl), then transfer our role to init
52662 + */
52663 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52664 + current->role->roletype & GR_ROLE_PERSIST)) {
52665 + struct task_struct *task = init_pid_ns.child_reaper;
52666 +
52667 + if (task->role != current->role) {
52668 + task->acl_sp_role = 0;
52669 + task->acl_role_id = current->acl_role_id;
52670 + task->role = current->role;
52671 + rcu_read_lock();
52672 + read_lock(&grsec_exec_file_lock);
52673 + gr_apply_subject_to_task(task);
52674 + read_unlock(&grsec_exec_file_lock);
52675 + rcu_read_unlock();
52676 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52677 + }
52678 + }
52679 +
52680 + if (unlikely
52681 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52682 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52683 + __u32 new_mode = mode;
52684 +
52685 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52686 +
52687 + retval = new_mode;
52688 +
52689 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52690 + new_mode |= GR_INHERIT;
52691 +
52692 + if (!(mode & GR_NOLEARN))
52693 + gr_log_learn(dentry, mnt, new_mode);
52694 + }
52695 +
52696 + return retval;
52697 +}
52698 +
52699 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52700 + const struct dentry *parent,
52701 + const struct vfsmount *mnt)
52702 +{
52703 + struct name_entry *match;
52704 + struct acl_object_label *matchpo;
52705 + struct acl_subject_label *curracl;
52706 + char *path;
52707 +
52708 + if (unlikely(!(gr_status & GR_READY)))
52709 + return NULL;
52710 +
52711 + preempt_disable();
52712 + path = gr_to_filename_rbac(new_dentry, mnt);
52713 + match = lookup_name_entry_create(path);
52714 +
52715 + curracl = current->acl;
52716 +
52717 + if (match) {
52718 + read_lock(&gr_inode_lock);
52719 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52720 + read_unlock(&gr_inode_lock);
52721 +
52722 + if (matchpo) {
52723 + preempt_enable();
52724 + return matchpo;
52725 + }
52726 + }
52727 +
52728 + // lookup parent
52729 +
52730 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52731 +
52732 + preempt_enable();
52733 + return matchpo;
52734 +}
52735 +
52736 +__u32
52737 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52738 + const struct vfsmount * mnt, const __u32 mode)
52739 +{
52740 + struct acl_object_label *matchpo;
52741 + __u32 retval;
52742 +
52743 + if (unlikely(!(gr_status & GR_READY)))
52744 + return (mode & ~GR_AUDITS);
52745 +
52746 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52747 +
52748 + retval = matchpo->mode & mode;
52749 +
52750 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52751 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52752 + __u32 new_mode = mode;
52753 +
52754 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52755 +
52756 + gr_log_learn(new_dentry, mnt, new_mode);
52757 + return new_mode;
52758 + }
52759 +
52760 + return retval;
52761 +}
52762 +
52763 +__u32
52764 +gr_check_link(const struct dentry * new_dentry,
52765 + const struct dentry * parent_dentry,
52766 + const struct vfsmount * parent_mnt,
52767 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52768 +{
52769 + struct acl_object_label *obj;
52770 + __u32 oldmode, newmode;
52771 + __u32 needmode;
52772 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52773 + GR_DELETE | GR_INHERIT;
52774 +
52775 + if (unlikely(!(gr_status & GR_READY)))
52776 + return (GR_CREATE | GR_LINK);
52777 +
52778 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52779 + oldmode = obj->mode;
52780 +
52781 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52782 + newmode = obj->mode;
52783 +
52784 + needmode = newmode & checkmodes;
52785 +
52786 + // old name for hardlink must have at least the permissions of the new name
52787 + if ((oldmode & needmode) != needmode)
52788 + goto bad;
52789 +
52790 + // if old name had restrictions/auditing, make sure the new name does as well
52791 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52792 +
52793 + // don't allow hardlinking of suid/sgid files without permission
52794 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52795 + needmode |= GR_SETID;
52796 +
52797 + if ((newmode & needmode) != needmode)
52798 + goto bad;
52799 +
52800 + // enforce minimum permissions
52801 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52802 + return newmode;
52803 +bad:
52804 + needmode = oldmode;
52805 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52806 + needmode |= GR_SETID;
52807 +
52808 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52809 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52810 + return (GR_CREATE | GR_LINK);
52811 + } else if (newmode & GR_SUPPRESS)
52812 + return GR_SUPPRESS;
52813 + else
52814 + return 0;
52815 +}
52816 +
52817 +int
52818 +gr_check_hidden_task(const struct task_struct *task)
52819 +{
52820 + if (unlikely(!(gr_status & GR_READY)))
52821 + return 0;
52822 +
52823 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52824 + return 1;
52825 +
52826 + return 0;
52827 +}
52828 +
52829 +int
52830 +gr_check_protected_task(const struct task_struct *task)
52831 +{
52832 + if (unlikely(!(gr_status & GR_READY) || !task))
52833 + return 0;
52834 +
52835 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52836 + task->acl != current->acl)
52837 + return 1;
52838 +
52839 + return 0;
52840 +}
52841 +
52842 +int
52843 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52844 +{
52845 + struct task_struct *p;
52846 + int ret = 0;
52847 +
52848 + if (unlikely(!(gr_status & GR_READY) || !pid))
52849 + return ret;
52850 +
52851 + read_lock(&tasklist_lock);
52852 + do_each_pid_task(pid, type, p) {
52853 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52854 + p->acl != current->acl) {
52855 + ret = 1;
52856 + goto out;
52857 + }
52858 + } while_each_pid_task(pid, type, p);
52859 +out:
52860 + read_unlock(&tasklist_lock);
52861 +
52862 + return ret;
52863 +}
52864 +
52865 +void
52866 +gr_copy_label(struct task_struct *tsk)
52867 +{
52868 + /* plain copying of fields is already done by dup_task_struct */
52869 + tsk->signal->used_accept = 0;
52870 + tsk->acl_sp_role = 0;
52871 + //tsk->acl_role_id = current->acl_role_id;
52872 + //tsk->acl = current->acl;
52873 + //tsk->role = current->role;
52874 + tsk->signal->curr_ip = current->signal->curr_ip;
52875 + tsk->signal->saved_ip = current->signal->saved_ip;
52876 + if (current->exec_file)
52877 + get_file(current->exec_file);
52878 + //tsk->exec_file = current->exec_file;
52879 + //tsk->is_writable = current->is_writable;
52880 + if (unlikely(current->signal->used_accept)) {
52881 + current->signal->curr_ip = 0;
52882 + current->signal->saved_ip = 0;
52883 + }
52884 +
52885 + return;
52886 +}
52887 +
52888 +static void
52889 +gr_set_proc_res(struct task_struct *task)
52890 +{
52891 + struct acl_subject_label *proc;
52892 + unsigned short i;
52893 +
52894 + proc = task->acl;
52895 +
52896 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52897 + return;
52898 +
52899 + for (i = 0; i < RLIM_NLIMITS; i++) {
52900 + if (!(proc->resmask & (1 << i)))
52901 + continue;
52902 +
52903 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52904 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52905 + }
52906 +
52907 + return;
52908 +}
52909 +
52910 +extern int __gr_process_user_ban(struct user_struct *user);
52911 +
52912 +int
52913 +gr_check_user_change(int real, int effective, int fs)
52914 +{
52915 + unsigned int i;
52916 + __u16 num;
52917 + uid_t *uidlist;
52918 + int curuid;
52919 + int realok = 0;
52920 + int effectiveok = 0;
52921 + int fsok = 0;
52922 +
52923 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52924 + struct user_struct *user;
52925 +
52926 + if (real == -1)
52927 + goto skipit;
52928 +
52929 + user = find_user(real);
52930 + if (user == NULL)
52931 + goto skipit;
52932 +
52933 + if (__gr_process_user_ban(user)) {
52934 + /* for find_user */
52935 + free_uid(user);
52936 + return 1;
52937 + }
52938 +
52939 + /* for find_user */
52940 + free_uid(user);
52941 +
52942 +skipit:
52943 +#endif
52944 +
52945 + if (unlikely(!(gr_status & GR_READY)))
52946 + return 0;
52947 +
52948 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52949 + gr_log_learn_id_change('u', real, effective, fs);
52950 +
52951 + num = current->acl->user_trans_num;
52952 + uidlist = current->acl->user_transitions;
52953 +
52954 + if (uidlist == NULL)
52955 + return 0;
52956 +
52957 + if (real == -1)
52958 + realok = 1;
52959 + if (effective == -1)
52960 + effectiveok = 1;
52961 + if (fs == -1)
52962 + fsok = 1;
52963 +
52964 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52965 + for (i = 0; i < num; i++) {
52966 + curuid = (int)uidlist[i];
52967 + if (real == curuid)
52968 + realok = 1;
52969 + if (effective == curuid)
52970 + effectiveok = 1;
52971 + if (fs == curuid)
52972 + fsok = 1;
52973 + }
52974 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52975 + for (i = 0; i < num; i++) {
52976 + curuid = (int)uidlist[i];
52977 + if (real == curuid)
52978 + break;
52979 + if (effective == curuid)
52980 + break;
52981 + if (fs == curuid)
52982 + break;
52983 + }
52984 + /* not in deny list */
52985 + if (i == num) {
52986 + realok = 1;
52987 + effectiveok = 1;
52988 + fsok = 1;
52989 + }
52990 + }
52991 +
52992 + if (realok && effectiveok && fsok)
52993 + return 0;
52994 + else {
52995 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52996 + return 1;
52997 + }
52998 +}
52999 +
53000 +int
53001 +gr_check_group_change(int real, int effective, int fs)
53002 +{
53003 + unsigned int i;
53004 + __u16 num;
53005 + gid_t *gidlist;
53006 + int curgid;
53007 + int realok = 0;
53008 + int effectiveok = 0;
53009 + int fsok = 0;
53010 +
53011 + if (unlikely(!(gr_status & GR_READY)))
53012 + return 0;
53013 +
53014 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53015 + gr_log_learn_id_change('g', real, effective, fs);
53016 +
53017 + num = current->acl->group_trans_num;
53018 + gidlist = current->acl->group_transitions;
53019 +
53020 + if (gidlist == NULL)
53021 + return 0;
53022 +
53023 + if (real == -1)
53024 + realok = 1;
53025 + if (effective == -1)
53026 + effectiveok = 1;
53027 + if (fs == -1)
53028 + fsok = 1;
53029 +
53030 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53031 + for (i = 0; i < num; i++) {
53032 + curgid = (int)gidlist[i];
53033 + if (real == curgid)
53034 + realok = 1;
53035 + if (effective == curgid)
53036 + effectiveok = 1;
53037 + if (fs == curgid)
53038 + fsok = 1;
53039 + }
53040 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53041 + for (i = 0; i < num; i++) {
53042 + curgid = (int)gidlist[i];
53043 + if (real == curgid)
53044 + break;
53045 + if (effective == curgid)
53046 + break;
53047 + if (fs == curgid)
53048 + break;
53049 + }
53050 + /* not in deny list */
53051 + if (i == num) {
53052 + realok = 1;
53053 + effectiveok = 1;
53054 + fsok = 1;
53055 + }
53056 + }
53057 +
53058 + if (realok && effectiveok && fsok)
53059 + return 0;
53060 + else {
53061 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53062 + return 1;
53063 + }
53064 +}
53065 +
53066 +extern int gr_acl_is_capable(const int cap);
53067 +
53068 +void
53069 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53070 +{
53071 + struct acl_role_label *role = task->role;
53072 + struct acl_subject_label *subj = NULL;
53073 + struct acl_object_label *obj;
53074 + struct file *filp;
53075 +
53076 + if (unlikely(!(gr_status & GR_READY)))
53077 + return;
53078 +
53079 + filp = task->exec_file;
53080 +
53081 + /* kernel process, we'll give them the kernel role */
53082 + if (unlikely(!filp)) {
53083 + task->role = kernel_role;
53084 + task->acl = kernel_role->root_label;
53085 + return;
53086 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53087 + role = lookup_acl_role_label(task, uid, gid);
53088 +
53089 + /* don't change the role if we're not a privileged process */
53090 + if (role && task->role != role &&
53091 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53092 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53093 + return;
53094 +
53095 + /* perform subject lookup in possibly new role
53096 + we can use this result below in the case where role == task->role
53097 + */
53098 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53099 +
53100 + /* if we changed uid/gid, but result in the same role
53101 + and are using inheritance, don't lose the inherited subject
53102 + if current subject is other than what normal lookup
53103 + would result in, we arrived via inheritance, don't
53104 + lose subject
53105 + */
53106 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53107 + (subj == task->acl)))
53108 + task->acl = subj;
53109 +
53110 + task->role = role;
53111 +
53112 + task->is_writable = 0;
53113 +
53114 + /* ignore additional mmap checks for processes that are writable
53115 + by the default ACL */
53116 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53117 + if (unlikely(obj->mode & GR_WRITE))
53118 + task->is_writable = 1;
53119 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53120 + if (unlikely(obj->mode & GR_WRITE))
53121 + task->is_writable = 1;
53122 +
53123 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53124 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53125 +#endif
53126 +
53127 + gr_set_proc_res(task);
53128 +
53129 + return;
53130 +}
53131 +
53132 +int
53133 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53134 + const int unsafe_flags)
53135 +{
53136 + struct task_struct *task = current;
53137 + struct acl_subject_label *newacl;
53138 + struct acl_object_label *obj;
53139 + __u32 retmode;
53140 +
53141 + if (unlikely(!(gr_status & GR_READY)))
53142 + return 0;
53143 +
53144 + newacl = chk_subj_label(dentry, mnt, task->role);
53145 +
53146 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53147 + did an exec
53148 + */
53149 + rcu_read_lock();
53150 + read_lock(&tasklist_lock);
53151 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53152 + (task->parent->acl->mode & GR_POVERRIDE))) {
53153 + read_unlock(&tasklist_lock);
53154 + rcu_read_unlock();
53155 + goto skip_check;
53156 + }
53157 + read_unlock(&tasklist_lock);
53158 + rcu_read_unlock();
53159 +
53160 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53161 + !(task->role->roletype & GR_ROLE_GOD) &&
53162 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53163 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53164 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53165 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53166 + else
53167 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53168 + return -EACCES;
53169 + }
53170 +
53171 +skip_check:
53172 +
53173 + obj = chk_obj_label(dentry, mnt, task->acl);
53174 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53175 +
53176 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53177 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53178 + if (obj->nested)
53179 + task->acl = obj->nested;
53180 + else
53181 + task->acl = newacl;
53182 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53183 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53184 +
53185 + task->is_writable = 0;
53186 +
53187 + /* ignore additional mmap checks for processes that are writable
53188 + by the default ACL */
53189 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53190 + if (unlikely(obj->mode & GR_WRITE))
53191 + task->is_writable = 1;
53192 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53193 + if (unlikely(obj->mode & GR_WRITE))
53194 + task->is_writable = 1;
53195 +
53196 + gr_set_proc_res(task);
53197 +
53198 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53199 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53200 +#endif
53201 + return 0;
53202 +}
53203 +
53204 +/* always called with valid inodev ptr */
53205 +static void
53206 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53207 +{
53208 + struct acl_object_label *matchpo;
53209 + struct acl_subject_label *matchps;
53210 + struct acl_subject_label *subj;
53211 + struct acl_role_label *role;
53212 + unsigned int x;
53213 +
53214 + FOR_EACH_ROLE_START(role)
53215 + FOR_EACH_SUBJECT_START(role, subj, x)
53216 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53217 + matchpo->mode |= GR_DELETED;
53218 + FOR_EACH_SUBJECT_END(subj,x)
53219 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53220 + if (subj->inode == ino && subj->device == dev)
53221 + subj->mode |= GR_DELETED;
53222 + FOR_EACH_NESTED_SUBJECT_END(subj)
53223 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53224 + matchps->mode |= GR_DELETED;
53225 + FOR_EACH_ROLE_END(role)
53226 +
53227 + inodev->nentry->deleted = 1;
53228 +
53229 + return;
53230 +}
53231 +
53232 +void
53233 +gr_handle_delete(const ino_t ino, const dev_t dev)
53234 +{
53235 + struct inodev_entry *inodev;
53236 +
53237 + if (unlikely(!(gr_status & GR_READY)))
53238 + return;
53239 +
53240 + write_lock(&gr_inode_lock);
53241 + inodev = lookup_inodev_entry(ino, dev);
53242 + if (inodev != NULL)
53243 + do_handle_delete(inodev, ino, dev);
53244 + write_unlock(&gr_inode_lock);
53245 +
53246 + return;
53247 +}
53248 +
53249 +static void
53250 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53251 + const ino_t newinode, const dev_t newdevice,
53252 + struct acl_subject_label *subj)
53253 +{
53254 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53255 + struct acl_object_label *match;
53256 +
53257 + match = subj->obj_hash[index];
53258 +
53259 + while (match && (match->inode != oldinode ||
53260 + match->device != olddevice ||
53261 + !(match->mode & GR_DELETED)))
53262 + match = match->next;
53263 +
53264 + if (match && (match->inode == oldinode)
53265 + && (match->device == olddevice)
53266 + && (match->mode & GR_DELETED)) {
53267 + if (match->prev == NULL) {
53268 + subj->obj_hash[index] = match->next;
53269 + if (match->next != NULL)
53270 + match->next->prev = NULL;
53271 + } else {
53272 + match->prev->next = match->next;
53273 + if (match->next != NULL)
53274 + match->next->prev = match->prev;
53275 + }
53276 + match->prev = NULL;
53277 + match->next = NULL;
53278 + match->inode = newinode;
53279 + match->device = newdevice;
53280 + match->mode &= ~GR_DELETED;
53281 +
53282 + insert_acl_obj_label(match, subj);
53283 + }
53284 +
53285 + return;
53286 +}
53287 +
53288 +static void
53289 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53290 + const ino_t newinode, const dev_t newdevice,
53291 + struct acl_role_label *role)
53292 +{
53293 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53294 + struct acl_subject_label *match;
53295 +
53296 + match = role->subj_hash[index];
53297 +
53298 + while (match && (match->inode != oldinode ||
53299 + match->device != olddevice ||
53300 + !(match->mode & GR_DELETED)))
53301 + match = match->next;
53302 +
53303 + if (match && (match->inode == oldinode)
53304 + && (match->device == olddevice)
53305 + && (match->mode & GR_DELETED)) {
53306 + if (match->prev == NULL) {
53307 + role->subj_hash[index] = match->next;
53308 + if (match->next != NULL)
53309 + match->next->prev = NULL;
53310 + } else {
53311 + match->prev->next = match->next;
53312 + if (match->next != NULL)
53313 + match->next->prev = match->prev;
53314 + }
53315 + match->prev = NULL;
53316 + match->next = NULL;
53317 + match->inode = newinode;
53318 + match->device = newdevice;
53319 + match->mode &= ~GR_DELETED;
53320 +
53321 + insert_acl_subj_label(match, role);
53322 + }
53323 +
53324 + return;
53325 +}
53326 +
53327 +static void
53328 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53329 + const ino_t newinode, const dev_t newdevice)
53330 +{
53331 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53332 + struct inodev_entry *match;
53333 +
53334 + match = inodev_set.i_hash[index];
53335 +
53336 + while (match && (match->nentry->inode != oldinode ||
53337 + match->nentry->device != olddevice || !match->nentry->deleted))
53338 + match = match->next;
53339 +
53340 + if (match && (match->nentry->inode == oldinode)
53341 + && (match->nentry->device == olddevice) &&
53342 + match->nentry->deleted) {
53343 + if (match->prev == NULL) {
53344 + inodev_set.i_hash[index] = match->next;
53345 + if (match->next != NULL)
53346 + match->next->prev = NULL;
53347 + } else {
53348 + match->prev->next = match->next;
53349 + if (match->next != NULL)
53350 + match->next->prev = match->prev;
53351 + }
53352 + match->prev = NULL;
53353 + match->next = NULL;
53354 + match->nentry->inode = newinode;
53355 + match->nentry->device = newdevice;
53356 + match->nentry->deleted = 0;
53357 +
53358 + insert_inodev_entry(match);
53359 + }
53360 +
53361 + return;
53362 +}
53363 +
53364 +static void
53365 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53366 +{
53367 + struct acl_subject_label *subj;
53368 + struct acl_role_label *role;
53369 + unsigned int x;
53370 +
53371 + FOR_EACH_ROLE_START(role)
53372 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53373 +
53374 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53375 + if ((subj->inode == ino) && (subj->device == dev)) {
53376 + subj->inode = ino;
53377 + subj->device = dev;
53378 + }
53379 + FOR_EACH_NESTED_SUBJECT_END(subj)
53380 + FOR_EACH_SUBJECT_START(role, subj, x)
53381 + update_acl_obj_label(matchn->inode, matchn->device,
53382 + ino, dev, subj);
53383 + FOR_EACH_SUBJECT_END(subj,x)
53384 + FOR_EACH_ROLE_END(role)
53385 +
53386 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53387 +
53388 + return;
53389 +}
53390 +
53391 +static void
53392 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53393 + const struct vfsmount *mnt)
53394 +{
53395 + ino_t ino = dentry->d_inode->i_ino;
53396 + dev_t dev = __get_dev(dentry);
53397 +
53398 + __do_handle_create(matchn, ino, dev);
53399 +
53400 + return;
53401 +}
53402 +
53403 +void
53404 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53405 +{
53406 + struct name_entry *matchn;
53407 +
53408 + if (unlikely(!(gr_status & GR_READY)))
53409 + return;
53410 +
53411 + preempt_disable();
53412 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53413 +
53414 + if (unlikely((unsigned long)matchn)) {
53415 + write_lock(&gr_inode_lock);
53416 + do_handle_create(matchn, dentry, mnt);
53417 + write_unlock(&gr_inode_lock);
53418 + }
53419 + preempt_enable();
53420 +
53421 + return;
53422 +}
53423 +
53424 +void
53425 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53426 +{
53427 + struct name_entry *matchn;
53428 +
53429 + if (unlikely(!(gr_status & GR_READY)))
53430 + return;
53431 +
53432 + preempt_disable();
53433 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53434 +
53435 + if (unlikely((unsigned long)matchn)) {
53436 + write_lock(&gr_inode_lock);
53437 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53438 + write_unlock(&gr_inode_lock);
53439 + }
53440 + preempt_enable();
53441 +
53442 + return;
53443 +}
53444 +
53445 +void
53446 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53447 + struct dentry *old_dentry,
53448 + struct dentry *new_dentry,
53449 + struct vfsmount *mnt, const __u8 replace)
53450 +{
53451 + struct name_entry *matchn;
53452 + struct inodev_entry *inodev;
53453 + struct inode *inode = new_dentry->d_inode;
53454 + ino_t old_ino = old_dentry->d_inode->i_ino;
53455 + dev_t old_dev = __get_dev(old_dentry);
53456 +
53457 + /* vfs_rename swaps the name and parent link for old_dentry and
53458 + new_dentry
53459 + at this point, old_dentry has the new name, parent link, and inode
53460 + for the renamed file
53461 + if a file is being replaced by a rename, new_dentry has the inode
53462 + and name for the replaced file
53463 + */
53464 +
53465 + if (unlikely(!(gr_status & GR_READY)))
53466 + return;
53467 +
53468 + preempt_disable();
53469 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53470 +
53471 + /* we wouldn't have to check d_inode if it weren't for
53472 + NFS silly-renaming
53473 + */
53474 +
53475 + write_lock(&gr_inode_lock);
53476 + if (unlikely(replace && inode)) {
53477 + ino_t new_ino = inode->i_ino;
53478 + dev_t new_dev = __get_dev(new_dentry);
53479 +
53480 + inodev = lookup_inodev_entry(new_ino, new_dev);
53481 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53482 + do_handle_delete(inodev, new_ino, new_dev);
53483 + }
53484 +
53485 + inodev = lookup_inodev_entry(old_ino, old_dev);
53486 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53487 + do_handle_delete(inodev, old_ino, old_dev);
53488 +
53489 + if (unlikely((unsigned long)matchn))
53490 + do_handle_create(matchn, old_dentry, mnt);
53491 +
53492 + write_unlock(&gr_inode_lock);
53493 + preempt_enable();
53494 +
53495 + return;
53496 +}
53497 +
53498 +static int
53499 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53500 + unsigned char **sum)
53501 +{
53502 + struct acl_role_label *r;
53503 + struct role_allowed_ip *ipp;
53504 + struct role_transition *trans;
53505 + unsigned int i;
53506 + int found = 0;
53507 + u32 curr_ip = current->signal->curr_ip;
53508 +
53509 + current->signal->saved_ip = curr_ip;
53510 +
53511 + /* check transition table */
53512 +
53513 + for (trans = current->role->transitions; trans; trans = trans->next) {
53514 + if (!strcmp(rolename, trans->rolename)) {
53515 + found = 1;
53516 + break;
53517 + }
53518 + }
53519 +
53520 + if (!found)
53521 + return 0;
53522 +
53523 + /* handle special roles that do not require authentication
53524 + and check ip */
53525 +
53526 + FOR_EACH_ROLE_START(r)
53527 + if (!strcmp(rolename, r->rolename) &&
53528 + (r->roletype & GR_ROLE_SPECIAL)) {
53529 + found = 0;
53530 + if (r->allowed_ips != NULL) {
53531 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53532 + if ((ntohl(curr_ip) & ipp->netmask) ==
53533 + (ntohl(ipp->addr) & ipp->netmask))
53534 + found = 1;
53535 + }
53536 + } else
53537 + found = 2;
53538 + if (!found)
53539 + return 0;
53540 +
53541 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53542 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53543 + *salt = NULL;
53544 + *sum = NULL;
53545 + return 1;
53546 + }
53547 + }
53548 + FOR_EACH_ROLE_END(r)
53549 +
53550 + for (i = 0; i < num_sprole_pws; i++) {
53551 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53552 + *salt = acl_special_roles[i]->salt;
53553 + *sum = acl_special_roles[i]->sum;
53554 + return 1;
53555 + }
53556 + }
53557 +
53558 + return 0;
53559 +}
53560 +
53561 +static void
53562 +assign_special_role(char *rolename)
53563 +{
53564 + struct acl_object_label *obj;
53565 + struct acl_role_label *r;
53566 + struct acl_role_label *assigned = NULL;
53567 + struct task_struct *tsk;
53568 + struct file *filp;
53569 +
53570 + FOR_EACH_ROLE_START(r)
53571 + if (!strcmp(rolename, r->rolename) &&
53572 + (r->roletype & GR_ROLE_SPECIAL)) {
53573 + assigned = r;
53574 + break;
53575 + }
53576 + FOR_EACH_ROLE_END(r)
53577 +
53578 + if (!assigned)
53579 + return;
53580 +
53581 + read_lock(&tasklist_lock);
53582 + read_lock(&grsec_exec_file_lock);
53583 +
53584 + tsk = current->real_parent;
53585 + if (tsk == NULL)
53586 + goto out_unlock;
53587 +
53588 + filp = tsk->exec_file;
53589 + if (filp == NULL)
53590 + goto out_unlock;
53591 +
53592 + tsk->is_writable = 0;
53593 +
53594 + tsk->acl_sp_role = 1;
53595 + tsk->acl_role_id = ++acl_sp_role_value;
53596 + tsk->role = assigned;
53597 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53598 +
53599 + /* ignore additional mmap checks for processes that are writable
53600 + by the default ACL */
53601 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53602 + if (unlikely(obj->mode & GR_WRITE))
53603 + tsk->is_writable = 1;
53604 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53605 + if (unlikely(obj->mode & GR_WRITE))
53606 + tsk->is_writable = 1;
53607 +
53608 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53609 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53610 +#endif
53611 +
53612 +out_unlock:
53613 + read_unlock(&grsec_exec_file_lock);
53614 + read_unlock(&tasklist_lock);
53615 + return;
53616 +}
53617 +
53618 +int gr_check_secure_terminal(struct task_struct *task)
53619 +{
53620 + struct task_struct *p, *p2, *p3;
53621 + struct files_struct *files;
53622 + struct fdtable *fdt;
53623 + struct file *our_file = NULL, *file;
53624 + int i;
53625 +
53626 + if (task->signal->tty == NULL)
53627 + return 1;
53628 +
53629 + files = get_files_struct(task);
53630 + if (files != NULL) {
53631 + rcu_read_lock();
53632 + fdt = files_fdtable(files);
53633 + for (i=0; i < fdt->max_fds; i++) {
53634 + file = fcheck_files(files, i);
53635 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53636 + get_file(file);
53637 + our_file = file;
53638 + }
53639 + }
53640 + rcu_read_unlock();
53641 + put_files_struct(files);
53642 + }
53643 +
53644 + if (our_file == NULL)
53645 + return 1;
53646 +
53647 + read_lock(&tasklist_lock);
53648 + do_each_thread(p2, p) {
53649 + files = get_files_struct(p);
53650 + if (files == NULL ||
53651 + (p->signal && p->signal->tty == task->signal->tty)) {
53652 + if (files != NULL)
53653 + put_files_struct(files);
53654 + continue;
53655 + }
53656 + rcu_read_lock();
53657 + fdt = files_fdtable(files);
53658 + for (i=0; i < fdt->max_fds; i++) {
53659 + file = fcheck_files(files, i);
53660 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53661 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53662 + p3 = task;
53663 + while (p3->pid > 0) {
53664 + if (p3 == p)
53665 + break;
53666 + p3 = p3->real_parent;
53667 + }
53668 + if (p3 == p)
53669 + break;
53670 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53671 + gr_handle_alertkill(p);
53672 + rcu_read_unlock();
53673 + put_files_struct(files);
53674 + read_unlock(&tasklist_lock);
53675 + fput(our_file);
53676 + return 0;
53677 + }
53678 + }
53679 + rcu_read_unlock();
53680 + put_files_struct(files);
53681 + } while_each_thread(p2, p);
53682 + read_unlock(&tasklist_lock);
53683 +
53684 + fput(our_file);
53685 + return 1;
53686 +}
53687 +
53688 +ssize_t
53689 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53690 +{
53691 + struct gr_arg_wrapper uwrap;
53692 + unsigned char *sprole_salt = NULL;
53693 + unsigned char *sprole_sum = NULL;
53694 + int error = sizeof (struct gr_arg_wrapper);
53695 + int error2 = 0;
53696 +
53697 + mutex_lock(&gr_dev_mutex);
53698 +
53699 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53700 + error = -EPERM;
53701 + goto out;
53702 + }
53703 +
53704 + if (count != sizeof (struct gr_arg_wrapper)) {
53705 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53706 + error = -EINVAL;
53707 + goto out;
53708 + }
53709 +
53710 +
53711 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53712 + gr_auth_expires = 0;
53713 + gr_auth_attempts = 0;
53714 + }
53715 +
53716 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53717 + error = -EFAULT;
53718 + goto out;
53719 + }
53720 +
53721 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53722 + error = -EINVAL;
53723 + goto out;
53724 + }
53725 +
53726 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53727 + error = -EFAULT;
53728 + goto out;
53729 + }
53730 +
53731 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53732 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53733 + time_after(gr_auth_expires, get_seconds())) {
53734 + error = -EBUSY;
53735 + goto out;
53736 + }
53737 +
53738 + /* if non-root trying to do anything other than use a special role,
53739 + do not attempt authentication, do not count towards authentication
53740 + locking
53741 + */
53742 +
53743 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53744 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53745 + current_uid()) {
53746 + error = -EPERM;
53747 + goto out;
53748 + }
53749 +
53750 + /* ensure pw and special role name are null terminated */
53751 +
53752 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53753 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53754 +
53755 + /* Okay.
53756 + * We have our enough of the argument structure..(we have yet
53757 + * to copy_from_user the tables themselves) . Copy the tables
53758 + * only if we need them, i.e. for loading operations. */
53759 +
53760 + switch (gr_usermode->mode) {
53761 + case GR_STATUS:
53762 + if (gr_status & GR_READY) {
53763 + error = 1;
53764 + if (!gr_check_secure_terminal(current))
53765 + error = 3;
53766 + } else
53767 + error = 2;
53768 + goto out;
53769 + case GR_SHUTDOWN:
53770 + if ((gr_status & GR_READY)
53771 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53772 + pax_open_kernel();
53773 + gr_status &= ~GR_READY;
53774 + pax_close_kernel();
53775 +
53776 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53777 + free_variables();
53778 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53779 + memset(gr_system_salt, 0, GR_SALT_LEN);
53780 + memset(gr_system_sum, 0, GR_SHA_LEN);
53781 + } else if (gr_status & GR_READY) {
53782 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53783 + error = -EPERM;
53784 + } else {
53785 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53786 + error = -EAGAIN;
53787 + }
53788 + break;
53789 + case GR_ENABLE:
53790 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53791 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53792 + else {
53793 + if (gr_status & GR_READY)
53794 + error = -EAGAIN;
53795 + else
53796 + error = error2;
53797 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53798 + }
53799 + break;
53800 + case GR_RELOAD:
53801 + if (!(gr_status & GR_READY)) {
53802 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53803 + error = -EAGAIN;
53804 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53805 + preempt_disable();
53806 +
53807 + pax_open_kernel();
53808 + gr_status &= ~GR_READY;
53809 + pax_close_kernel();
53810 +
53811 + free_variables();
53812 + if (!(error2 = gracl_init(gr_usermode))) {
53813 + preempt_enable();
53814 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53815 + } else {
53816 + preempt_enable();
53817 + error = error2;
53818 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53819 + }
53820 + } else {
53821 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53822 + error = -EPERM;
53823 + }
53824 + break;
53825 + case GR_SEGVMOD:
53826 + if (unlikely(!(gr_status & GR_READY))) {
53827 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53828 + error = -EAGAIN;
53829 + break;
53830 + }
53831 +
53832 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53833 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53834 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53835 + struct acl_subject_label *segvacl;
53836 + segvacl =
53837 + lookup_acl_subj_label(gr_usermode->segv_inode,
53838 + gr_usermode->segv_device,
53839 + current->role);
53840 + if (segvacl) {
53841 + segvacl->crashes = 0;
53842 + segvacl->expires = 0;
53843 + }
53844 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53845 + gr_remove_uid(gr_usermode->segv_uid);
53846 + }
53847 + } else {
53848 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53849 + error = -EPERM;
53850 + }
53851 + break;
53852 + case GR_SPROLE:
53853 + case GR_SPROLEPAM:
53854 + if (unlikely(!(gr_status & GR_READY))) {
53855 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53856 + error = -EAGAIN;
53857 + break;
53858 + }
53859 +
53860 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53861 + current->role->expires = 0;
53862 + current->role->auth_attempts = 0;
53863 + }
53864 +
53865 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53866 + time_after(current->role->expires, get_seconds())) {
53867 + error = -EBUSY;
53868 + goto out;
53869 + }
53870 +
53871 + if (lookup_special_role_auth
53872 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53873 + && ((!sprole_salt && !sprole_sum)
53874 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53875 + char *p = "";
53876 + assign_special_role(gr_usermode->sp_role);
53877 + read_lock(&tasklist_lock);
53878 + if (current->real_parent)
53879 + p = current->real_parent->role->rolename;
53880 + read_unlock(&tasklist_lock);
53881 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53882 + p, acl_sp_role_value);
53883 + } else {
53884 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53885 + error = -EPERM;
53886 + if(!(current->role->auth_attempts++))
53887 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53888 +
53889 + goto out;
53890 + }
53891 + break;
53892 + case GR_UNSPROLE:
53893 + if (unlikely(!(gr_status & GR_READY))) {
53894 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53895 + error = -EAGAIN;
53896 + break;
53897 + }
53898 +
53899 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53900 + char *p = "";
53901 + int i = 0;
53902 +
53903 + read_lock(&tasklist_lock);
53904 + if (current->real_parent) {
53905 + p = current->real_parent->role->rolename;
53906 + i = current->real_parent->acl_role_id;
53907 + }
53908 + read_unlock(&tasklist_lock);
53909 +
53910 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53911 + gr_set_acls(1);
53912 + } else {
53913 + error = -EPERM;
53914 + goto out;
53915 + }
53916 + break;
53917 + default:
53918 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53919 + error = -EINVAL;
53920 + break;
53921 + }
53922 +
53923 + if (error != -EPERM)
53924 + goto out;
53925 +
53926 + if(!(gr_auth_attempts++))
53927 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53928 +
53929 + out:
53930 + mutex_unlock(&gr_dev_mutex);
53931 + return error;
53932 +}
53933 +
53934 +/* must be called with
53935 + rcu_read_lock();
53936 + read_lock(&tasklist_lock);
53937 + read_lock(&grsec_exec_file_lock);
53938 +*/
53939 +int gr_apply_subject_to_task(struct task_struct *task)
53940 +{
53941 + struct acl_object_label *obj;
53942 + char *tmpname;
53943 + struct acl_subject_label *tmpsubj;
53944 + struct file *filp;
53945 + struct name_entry *nmatch;
53946 +
53947 + filp = task->exec_file;
53948 + if (filp == NULL)
53949 + return 0;
53950 +
53951 + /* the following is to apply the correct subject
53952 + on binaries running when the RBAC system
53953 + is enabled, when the binaries have been
53954 + replaced or deleted since their execution
53955 + -----
53956 + when the RBAC system starts, the inode/dev
53957 + from exec_file will be one the RBAC system
53958 + is unaware of. It only knows the inode/dev
53959 + of the present file on disk, or the absence
53960 + of it.
53961 + */
53962 + preempt_disable();
53963 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53964 +
53965 + nmatch = lookup_name_entry(tmpname);
53966 + preempt_enable();
53967 + tmpsubj = NULL;
53968 + if (nmatch) {
53969 + if (nmatch->deleted)
53970 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53971 + else
53972 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53973 + if (tmpsubj != NULL)
53974 + task->acl = tmpsubj;
53975 + }
53976 + if (tmpsubj == NULL)
53977 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53978 + task->role);
53979 + if (task->acl) {
53980 + task->is_writable = 0;
53981 + /* ignore additional mmap checks for processes that are writable
53982 + by the default ACL */
53983 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53984 + if (unlikely(obj->mode & GR_WRITE))
53985 + task->is_writable = 1;
53986 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53987 + if (unlikely(obj->mode & GR_WRITE))
53988 + task->is_writable = 1;
53989 +
53990 + gr_set_proc_res(task);
53991 +
53992 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53993 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53994 +#endif
53995 + } else {
53996 + return 1;
53997 + }
53998 +
53999 + return 0;
54000 +}
54001 +
54002 +int
54003 +gr_set_acls(const int type)
54004 +{
54005 + struct task_struct *task, *task2;
54006 + struct acl_role_label *role = current->role;
54007 + __u16 acl_role_id = current->acl_role_id;
54008 + const struct cred *cred;
54009 + int ret;
54010 +
54011 + rcu_read_lock();
54012 + read_lock(&tasklist_lock);
54013 + read_lock(&grsec_exec_file_lock);
54014 + do_each_thread(task2, task) {
54015 + /* check to see if we're called from the exit handler,
54016 + if so, only replace ACLs that have inherited the admin
54017 + ACL */
54018 +
54019 + if (type && (task->role != role ||
54020 + task->acl_role_id != acl_role_id))
54021 + continue;
54022 +
54023 + task->acl_role_id = 0;
54024 + task->acl_sp_role = 0;
54025 +
54026 + if (task->exec_file) {
54027 + cred = __task_cred(task);
54028 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54029 + ret = gr_apply_subject_to_task(task);
54030 + if (ret) {
54031 + read_unlock(&grsec_exec_file_lock);
54032 + read_unlock(&tasklist_lock);
54033 + rcu_read_unlock();
54034 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54035 + return ret;
54036 + }
54037 + } else {
54038 + // it's a kernel process
54039 + task->role = kernel_role;
54040 + task->acl = kernel_role->root_label;
54041 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54042 + task->acl->mode &= ~GR_PROCFIND;
54043 +#endif
54044 + }
54045 + } while_each_thread(task2, task);
54046 + read_unlock(&grsec_exec_file_lock);
54047 + read_unlock(&tasklist_lock);
54048 + rcu_read_unlock();
54049 +
54050 + return 0;
54051 +}
54052 +
54053 +void
54054 +gr_learn_resource(const struct task_struct *task,
54055 + const int res, const unsigned long wanted, const int gt)
54056 +{
54057 + struct acl_subject_label *acl;
54058 + const struct cred *cred;
54059 +
54060 + if (unlikely((gr_status & GR_READY) &&
54061 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54062 + goto skip_reslog;
54063 +
54064 +#ifdef CONFIG_GRKERNSEC_RESLOG
54065 + gr_log_resource(task, res, wanted, gt);
54066 +#endif
54067 + skip_reslog:
54068 +
54069 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54070 + return;
54071 +
54072 + acl = task->acl;
54073 +
54074 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54075 + !(acl->resmask & (1 << (unsigned short) res))))
54076 + return;
54077 +
54078 + if (wanted >= acl->res[res].rlim_cur) {
54079 + unsigned long res_add;
54080 +
54081 + res_add = wanted;
54082 + switch (res) {
54083 + case RLIMIT_CPU:
54084 + res_add += GR_RLIM_CPU_BUMP;
54085 + break;
54086 + case RLIMIT_FSIZE:
54087 + res_add += GR_RLIM_FSIZE_BUMP;
54088 + break;
54089 + case RLIMIT_DATA:
54090 + res_add += GR_RLIM_DATA_BUMP;
54091 + break;
54092 + case RLIMIT_STACK:
54093 + res_add += GR_RLIM_STACK_BUMP;
54094 + break;
54095 + case RLIMIT_CORE:
54096 + res_add += GR_RLIM_CORE_BUMP;
54097 + break;
54098 + case RLIMIT_RSS:
54099 + res_add += GR_RLIM_RSS_BUMP;
54100 + break;
54101 + case RLIMIT_NPROC:
54102 + res_add += GR_RLIM_NPROC_BUMP;
54103 + break;
54104 + case RLIMIT_NOFILE:
54105 + res_add += GR_RLIM_NOFILE_BUMP;
54106 + break;
54107 + case RLIMIT_MEMLOCK:
54108 + res_add += GR_RLIM_MEMLOCK_BUMP;
54109 + break;
54110 + case RLIMIT_AS:
54111 + res_add += GR_RLIM_AS_BUMP;
54112 + break;
54113 + case RLIMIT_LOCKS:
54114 + res_add += GR_RLIM_LOCKS_BUMP;
54115 + break;
54116 + case RLIMIT_SIGPENDING:
54117 + res_add += GR_RLIM_SIGPENDING_BUMP;
54118 + break;
54119 + case RLIMIT_MSGQUEUE:
54120 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54121 + break;
54122 + case RLIMIT_NICE:
54123 + res_add += GR_RLIM_NICE_BUMP;
54124 + break;
54125 + case RLIMIT_RTPRIO:
54126 + res_add += GR_RLIM_RTPRIO_BUMP;
54127 + break;
54128 + case RLIMIT_RTTIME:
54129 + res_add += GR_RLIM_RTTIME_BUMP;
54130 + break;
54131 + }
54132 +
54133 + acl->res[res].rlim_cur = res_add;
54134 +
54135 + if (wanted > acl->res[res].rlim_max)
54136 + acl->res[res].rlim_max = res_add;
54137 +
54138 + /* only log the subject filename, since resource logging is supported for
54139 + single-subject learning only */
54140 + rcu_read_lock();
54141 + cred = __task_cred(task);
54142 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54143 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54144 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54145 + "", (unsigned long) res, &task->signal->saved_ip);
54146 + rcu_read_unlock();
54147 + }
54148 +
54149 + return;
54150 +}
54151 +
54152 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54153 +void
54154 +pax_set_initial_flags(struct linux_binprm *bprm)
54155 +{
54156 + struct task_struct *task = current;
54157 + struct acl_subject_label *proc;
54158 + unsigned long flags;
54159 +
54160 + if (unlikely(!(gr_status & GR_READY)))
54161 + return;
54162 +
54163 + flags = pax_get_flags(task);
54164 +
54165 + proc = task->acl;
54166 +
54167 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54168 + flags &= ~MF_PAX_PAGEEXEC;
54169 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54170 + flags &= ~MF_PAX_SEGMEXEC;
54171 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54172 + flags &= ~MF_PAX_RANDMMAP;
54173 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54174 + flags &= ~MF_PAX_EMUTRAMP;
54175 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54176 + flags &= ~MF_PAX_MPROTECT;
54177 +
54178 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54179 + flags |= MF_PAX_PAGEEXEC;
54180 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54181 + flags |= MF_PAX_SEGMEXEC;
54182 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54183 + flags |= MF_PAX_RANDMMAP;
54184 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54185 + flags |= MF_PAX_EMUTRAMP;
54186 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54187 + flags |= MF_PAX_MPROTECT;
54188 +
54189 + pax_set_flags(task, flags);
54190 +
54191 + return;
54192 +}
54193 +#endif
54194 +
54195 +#ifdef CONFIG_SYSCTL
54196 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54197 + system to save 35kb of memory */
54198 +
54199 +/* we modify the passed in filename, but adjust it back before returning */
54200 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54201 +{
54202 + struct name_entry *nmatch;
54203 + char *p, *lastp = NULL;
54204 + struct acl_object_label *obj = NULL, *tmp;
54205 + struct acl_subject_label *tmpsubj;
54206 + char c = '\0';
54207 +
54208 + read_lock(&gr_inode_lock);
54209 +
54210 + p = name + len - 1;
54211 + do {
54212 + nmatch = lookup_name_entry(name);
54213 + if (lastp != NULL)
54214 + *lastp = c;
54215 +
54216 + if (nmatch == NULL)
54217 + goto next_component;
54218 + tmpsubj = current->acl;
54219 + do {
54220 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54221 + if (obj != NULL) {
54222 + tmp = obj->globbed;
54223 + while (tmp) {
54224 + if (!glob_match(tmp->filename, name)) {
54225 + obj = tmp;
54226 + goto found_obj;
54227 + }
54228 + tmp = tmp->next;
54229 + }
54230 + goto found_obj;
54231 + }
54232 + } while ((tmpsubj = tmpsubj->parent_subject));
54233 +next_component:
54234 + /* end case */
54235 + if (p == name)
54236 + break;
54237 +
54238 + while (*p != '/')
54239 + p--;
54240 + if (p == name)
54241 + lastp = p + 1;
54242 + else {
54243 + lastp = p;
54244 + p--;
54245 + }
54246 + c = *lastp;
54247 + *lastp = '\0';
54248 + } while (1);
54249 +found_obj:
54250 + read_unlock(&gr_inode_lock);
54251 + /* obj returned will always be non-null */
54252 + return obj;
54253 +}
54254 +
54255 +/* returns 0 when allowing, non-zero on error
54256 + op of 0 is used for readdir, so we don't log the names of hidden files
54257 +*/
54258 +__u32
54259 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54260 +{
54261 + struct ctl_table *tmp;
54262 + const char *proc_sys = "/proc/sys";
54263 + char *path;
54264 + struct acl_object_label *obj;
54265 + unsigned short len = 0, pos = 0, depth = 0, i;
54266 + __u32 err = 0;
54267 + __u32 mode = 0;
54268 +
54269 + if (unlikely(!(gr_status & GR_READY)))
54270 + return 0;
54271 +
54272 + /* for now, ignore operations on non-sysctl entries if it's not a
54273 + readdir*/
54274 + if (table->child != NULL && op != 0)
54275 + return 0;
54276 +
54277 + mode |= GR_FIND;
54278 + /* it's only a read if it's an entry, read on dirs is for readdir */
54279 + if (op & MAY_READ)
54280 + mode |= GR_READ;
54281 + if (op & MAY_WRITE)
54282 + mode |= GR_WRITE;
54283 +
54284 + preempt_disable();
54285 +
54286 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54287 +
54288 + /* it's only a read/write if it's an actual entry, not a dir
54289 + (which are opened for readdir)
54290 + */
54291 +
54292 + /* convert the requested sysctl entry into a pathname */
54293 +
54294 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54295 + len += strlen(tmp->procname);
54296 + len++;
54297 + depth++;
54298 + }
54299 +
54300 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54301 + /* deny */
54302 + goto out;
54303 + }
54304 +
54305 + memset(path, 0, PAGE_SIZE);
54306 +
54307 + memcpy(path, proc_sys, strlen(proc_sys));
54308 +
54309 + pos += strlen(proc_sys);
54310 +
54311 + for (; depth > 0; depth--) {
54312 + path[pos] = '/';
54313 + pos++;
54314 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54315 + if (depth == i) {
54316 + memcpy(path + pos, tmp->procname,
54317 + strlen(tmp->procname));
54318 + pos += strlen(tmp->procname);
54319 + }
54320 + i++;
54321 + }
54322 + }
54323 +
54324 + obj = gr_lookup_by_name(path, pos);
54325 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54326 +
54327 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54328 + ((err & mode) != mode))) {
54329 + __u32 new_mode = mode;
54330 +
54331 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54332 +
54333 + err = 0;
54334 + gr_log_learn_sysctl(path, new_mode);
54335 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54336 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54337 + err = -ENOENT;
54338 + } else if (!(err & GR_FIND)) {
54339 + err = -ENOENT;
54340 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54341 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54342 + path, (mode & GR_READ) ? " reading" : "",
54343 + (mode & GR_WRITE) ? " writing" : "");
54344 + err = -EACCES;
54345 + } else if ((err & mode) != mode) {
54346 + err = -EACCES;
54347 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54348 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54349 + path, (mode & GR_READ) ? " reading" : "",
54350 + (mode & GR_WRITE) ? " writing" : "");
54351 + err = 0;
54352 + } else
54353 + err = 0;
54354 +
54355 + out:
54356 + preempt_enable();
54357 +
54358 + return err;
54359 +}
54360 +#endif
54361 +
54362 +int
54363 +gr_handle_proc_ptrace(struct task_struct *task)
54364 +{
54365 + struct file *filp;
54366 + struct task_struct *tmp = task;
54367 + struct task_struct *curtemp = current;
54368 + __u32 retmode;
54369 +
54370 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54371 + if (unlikely(!(gr_status & GR_READY)))
54372 + return 0;
54373 +#endif
54374 +
54375 + read_lock(&tasklist_lock);
54376 + read_lock(&grsec_exec_file_lock);
54377 + filp = task->exec_file;
54378 +
54379 + while (tmp->pid > 0) {
54380 + if (tmp == curtemp)
54381 + break;
54382 + tmp = tmp->real_parent;
54383 + }
54384 +
54385 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54386 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54387 + read_unlock(&grsec_exec_file_lock);
54388 + read_unlock(&tasklist_lock);
54389 + return 1;
54390 + }
54391 +
54392 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54393 + if (!(gr_status & GR_READY)) {
54394 + read_unlock(&grsec_exec_file_lock);
54395 + read_unlock(&tasklist_lock);
54396 + return 0;
54397 + }
54398 +#endif
54399 +
54400 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54401 + read_unlock(&grsec_exec_file_lock);
54402 + read_unlock(&tasklist_lock);
54403 +
54404 + if (retmode & GR_NOPTRACE)
54405 + return 1;
54406 +
54407 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54408 + && (current->acl != task->acl || (current->acl != current->role->root_label
54409 + && current->pid != task->pid)))
54410 + return 1;
54411 +
54412 + return 0;
54413 +}
54414 +
54415 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54416 +{
54417 + if (unlikely(!(gr_status & GR_READY)))
54418 + return;
54419 +
54420 + if (!(current->role->roletype & GR_ROLE_GOD))
54421 + return;
54422 +
54423 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54424 + p->role->rolename, gr_task_roletype_to_char(p),
54425 + p->acl->filename);
54426 +}
54427 +
54428 +int
54429 +gr_handle_ptrace(struct task_struct *task, const long request)
54430 +{
54431 + struct task_struct *tmp = task;
54432 + struct task_struct *curtemp = current;
54433 + __u32 retmode;
54434 +
54435 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54436 + if (unlikely(!(gr_status & GR_READY)))
54437 + return 0;
54438 +#endif
54439 +
54440 + read_lock(&tasklist_lock);
54441 + while (tmp->pid > 0) {
54442 + if (tmp == curtemp)
54443 + break;
54444 + tmp = tmp->real_parent;
54445 + }
54446 +
54447 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54448 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54449 + read_unlock(&tasklist_lock);
54450 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54451 + return 1;
54452 + }
54453 + read_unlock(&tasklist_lock);
54454 +
54455 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54456 + if (!(gr_status & GR_READY))
54457 + return 0;
54458 +#endif
54459 +
54460 + read_lock(&grsec_exec_file_lock);
54461 + if (unlikely(!task->exec_file)) {
54462 + read_unlock(&grsec_exec_file_lock);
54463 + return 0;
54464 + }
54465 +
54466 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54467 + read_unlock(&grsec_exec_file_lock);
54468 +
54469 + if (retmode & GR_NOPTRACE) {
54470 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54471 + return 1;
54472 + }
54473 +
54474 + if (retmode & GR_PTRACERD) {
54475 + switch (request) {
54476 + case PTRACE_SEIZE:
54477 + case PTRACE_POKETEXT:
54478 + case PTRACE_POKEDATA:
54479 + case PTRACE_POKEUSR:
54480 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54481 + case PTRACE_SETREGS:
54482 + case PTRACE_SETFPREGS:
54483 +#endif
54484 +#ifdef CONFIG_X86
54485 + case PTRACE_SETFPXREGS:
54486 +#endif
54487 +#ifdef CONFIG_ALTIVEC
54488 + case PTRACE_SETVRREGS:
54489 +#endif
54490 + return 1;
54491 + default:
54492 + return 0;
54493 + }
54494 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54495 + !(current->role->roletype & GR_ROLE_GOD) &&
54496 + (current->acl != task->acl)) {
54497 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54498 + return 1;
54499 + }
54500 +
54501 + return 0;
54502 +}
54503 +
54504 +static int is_writable_mmap(const struct file *filp)
54505 +{
54506 + struct task_struct *task = current;
54507 + struct acl_object_label *obj, *obj2;
54508 +
54509 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54510 + !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))) {
54511 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54512 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54513 + task->role->root_label);
54514 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54515 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54516 + return 1;
54517 + }
54518 + }
54519 + return 0;
54520 +}
54521 +
54522 +int
54523 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54524 +{
54525 + __u32 mode;
54526 +
54527 + if (unlikely(!file || !(prot & PROT_EXEC)))
54528 + return 1;
54529 +
54530 + if (is_writable_mmap(file))
54531 + return 0;
54532 +
54533 + mode =
54534 + gr_search_file(file->f_path.dentry,
54535 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54536 + file->f_path.mnt);
54537 +
54538 + if (!gr_tpe_allow(file))
54539 + return 0;
54540 +
54541 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54542 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54543 + return 0;
54544 + } else if (unlikely(!(mode & GR_EXEC))) {
54545 + return 0;
54546 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54547 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54548 + return 1;
54549 + }
54550 +
54551 + return 1;
54552 +}
54553 +
54554 +int
54555 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54556 +{
54557 + __u32 mode;
54558 +
54559 + if (unlikely(!file || !(prot & PROT_EXEC)))
54560 + return 1;
54561 +
54562 + if (is_writable_mmap(file))
54563 + return 0;
54564 +
54565 + mode =
54566 + gr_search_file(file->f_path.dentry,
54567 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54568 + file->f_path.mnt);
54569 +
54570 + if (!gr_tpe_allow(file))
54571 + return 0;
54572 +
54573 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54574 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54575 + return 0;
54576 + } else if (unlikely(!(mode & GR_EXEC))) {
54577 + return 0;
54578 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54579 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54580 + return 1;
54581 + }
54582 +
54583 + return 1;
54584 +}
54585 +
54586 +void
54587 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54588 +{
54589 + unsigned long runtime;
54590 + unsigned long cputime;
54591 + unsigned int wday, cday;
54592 + __u8 whr, chr;
54593 + __u8 wmin, cmin;
54594 + __u8 wsec, csec;
54595 + struct timespec timeval;
54596 +
54597 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54598 + !(task->acl->mode & GR_PROCACCT)))
54599 + return;
54600 +
54601 + do_posix_clock_monotonic_gettime(&timeval);
54602 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54603 + wday = runtime / (3600 * 24);
54604 + runtime -= wday * (3600 * 24);
54605 + whr = runtime / 3600;
54606 + runtime -= whr * 3600;
54607 + wmin = runtime / 60;
54608 + runtime -= wmin * 60;
54609 + wsec = runtime;
54610 +
54611 + cputime = (task->utime + task->stime) / HZ;
54612 + cday = cputime / (3600 * 24);
54613 + cputime -= cday * (3600 * 24);
54614 + chr = cputime / 3600;
54615 + cputime -= chr * 3600;
54616 + cmin = cputime / 60;
54617 + cputime -= cmin * 60;
54618 + csec = cputime;
54619 +
54620 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54621 +
54622 + return;
54623 +}
54624 +
54625 +void gr_set_kernel_label(struct task_struct *task)
54626 +{
54627 + if (gr_status & GR_READY) {
54628 + task->role = kernel_role;
54629 + task->acl = kernel_role->root_label;
54630 + }
54631 + return;
54632 +}
54633 +
54634 +#ifdef CONFIG_TASKSTATS
54635 +int gr_is_taskstats_denied(int pid)
54636 +{
54637 + struct task_struct *task;
54638 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54639 + const struct cred *cred;
54640 +#endif
54641 + int ret = 0;
54642 +
54643 + /* restrict taskstats viewing to un-chrooted root users
54644 + who have the 'view' subject flag if the RBAC system is enabled
54645 + */
54646 +
54647 + rcu_read_lock();
54648 + read_lock(&tasklist_lock);
54649 + task = find_task_by_vpid(pid);
54650 + if (task) {
54651 +#ifdef CONFIG_GRKERNSEC_CHROOT
54652 + if (proc_is_chrooted(task))
54653 + ret = -EACCES;
54654 +#endif
54655 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54656 + cred = __task_cred(task);
54657 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54658 + if (cred->uid != 0)
54659 + ret = -EACCES;
54660 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54661 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54662 + ret = -EACCES;
54663 +#endif
54664 +#endif
54665 + if (gr_status & GR_READY) {
54666 + if (!(task->acl->mode & GR_VIEW))
54667 + ret = -EACCES;
54668 + }
54669 + } else
54670 + ret = -ENOENT;
54671 +
54672 + read_unlock(&tasklist_lock);
54673 + rcu_read_unlock();
54674 +
54675 + return ret;
54676 +}
54677 +#endif
54678 +
54679 +/* AUXV entries are filled via a descendant of search_binary_handler
54680 + after we've already applied the subject for the target
54681 +*/
54682 +int gr_acl_enable_at_secure(void)
54683 +{
54684 + if (unlikely(!(gr_status & GR_READY)))
54685 + return 0;
54686 +
54687 + if (current->acl->mode & GR_ATSECURE)
54688 + return 1;
54689 +
54690 + return 0;
54691 +}
54692 +
54693 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54694 +{
54695 + struct task_struct *task = current;
54696 + struct dentry *dentry = file->f_path.dentry;
54697 + struct vfsmount *mnt = file->f_path.mnt;
54698 + struct acl_object_label *obj, *tmp;
54699 + struct acl_subject_label *subj;
54700 + unsigned int bufsize;
54701 + int is_not_root;
54702 + char *path;
54703 + dev_t dev = __get_dev(dentry);
54704 +
54705 + if (unlikely(!(gr_status & GR_READY)))
54706 + return 1;
54707 +
54708 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54709 + return 1;
54710 +
54711 + /* ignore Eric Biederman */
54712 + if (IS_PRIVATE(dentry->d_inode))
54713 + return 1;
54714 +
54715 + subj = task->acl;
54716 + do {
54717 + obj = lookup_acl_obj_label(ino, dev, subj);
54718 + if (obj != NULL)
54719 + return (obj->mode & GR_FIND) ? 1 : 0;
54720 + } while ((subj = subj->parent_subject));
54721 +
54722 + /* this is purely an optimization since we're looking for an object
54723 + for the directory we're doing a readdir on
54724 + if it's possible for any globbed object to match the entry we're
54725 + filling into the directory, then the object we find here will be
54726 + an anchor point with attached globbed objects
54727 + */
54728 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54729 + if (obj->globbed == NULL)
54730 + return (obj->mode & GR_FIND) ? 1 : 0;
54731 +
54732 + is_not_root = ((obj->filename[0] == '/') &&
54733 + (obj->filename[1] == '\0')) ? 0 : 1;
54734 + bufsize = PAGE_SIZE - namelen - is_not_root;
54735 +
54736 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54737 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54738 + return 1;
54739 +
54740 + preempt_disable();
54741 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54742 + bufsize);
54743 +
54744 + bufsize = strlen(path);
54745 +
54746 + /* if base is "/", don't append an additional slash */
54747 + if (is_not_root)
54748 + *(path + bufsize) = '/';
54749 + memcpy(path + bufsize + is_not_root, name, namelen);
54750 + *(path + bufsize + namelen + is_not_root) = '\0';
54751 +
54752 + tmp = obj->globbed;
54753 + while (tmp) {
54754 + if (!glob_match(tmp->filename, path)) {
54755 + preempt_enable();
54756 + return (tmp->mode & GR_FIND) ? 1 : 0;
54757 + }
54758 + tmp = tmp->next;
54759 + }
54760 + preempt_enable();
54761 + return (obj->mode & GR_FIND) ? 1 : 0;
54762 +}
54763 +
54764 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54765 +EXPORT_SYMBOL(gr_acl_is_enabled);
54766 +#endif
54767 +EXPORT_SYMBOL(gr_learn_resource);
54768 +EXPORT_SYMBOL(gr_set_kernel_label);
54769 +#ifdef CONFIG_SECURITY
54770 +EXPORT_SYMBOL(gr_check_user_change);
54771 +EXPORT_SYMBOL(gr_check_group_change);
54772 +#endif
54773 +
54774 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54775 new file mode 100644
54776 index 0000000..34fefda
54777 --- /dev/null
54778 +++ b/grsecurity/gracl_alloc.c
54779 @@ -0,0 +1,105 @@
54780 +#include <linux/kernel.h>
54781 +#include <linux/mm.h>
54782 +#include <linux/slab.h>
54783 +#include <linux/vmalloc.h>
54784 +#include <linux/gracl.h>
54785 +#include <linux/grsecurity.h>
54786 +
54787 +static unsigned long alloc_stack_next = 1;
54788 +static unsigned long alloc_stack_size = 1;
54789 +static void **alloc_stack;
54790 +
54791 +static __inline__ int
54792 +alloc_pop(void)
54793 +{
54794 + if (alloc_stack_next == 1)
54795 + return 0;
54796 +
54797 + kfree(alloc_stack[alloc_stack_next - 2]);
54798 +
54799 + alloc_stack_next--;
54800 +
54801 + return 1;
54802 +}
54803 +
54804 +static __inline__ int
54805 +alloc_push(void *buf)
54806 +{
54807 + if (alloc_stack_next >= alloc_stack_size)
54808 + return 1;
54809 +
54810 + alloc_stack[alloc_stack_next - 1] = buf;
54811 +
54812 + alloc_stack_next++;
54813 +
54814 + return 0;
54815 +}
54816 +
54817 +void *
54818 +acl_alloc(unsigned long len)
54819 +{
54820 + void *ret = NULL;
54821 +
54822 + if (!len || len > PAGE_SIZE)
54823 + goto out;
54824 +
54825 + ret = kmalloc(len, GFP_KERNEL);
54826 +
54827 + if (ret) {
54828 + if (alloc_push(ret)) {
54829 + kfree(ret);
54830 + ret = NULL;
54831 + }
54832 + }
54833 +
54834 +out:
54835 + return ret;
54836 +}
54837 +
54838 +void *
54839 +acl_alloc_num(unsigned long num, unsigned long len)
54840 +{
54841 + if (!len || (num > (PAGE_SIZE / len)))
54842 + return NULL;
54843 +
54844 + return acl_alloc(num * len);
54845 +}
54846 +
54847 +void
54848 +acl_free_all(void)
54849 +{
54850 + if (gr_acl_is_enabled() || !alloc_stack)
54851 + return;
54852 +
54853 + while (alloc_pop()) ;
54854 +
54855 + if (alloc_stack) {
54856 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54857 + kfree(alloc_stack);
54858 + else
54859 + vfree(alloc_stack);
54860 + }
54861 +
54862 + alloc_stack = NULL;
54863 + alloc_stack_size = 1;
54864 + alloc_stack_next = 1;
54865 +
54866 + return;
54867 +}
54868 +
54869 +int
54870 +acl_alloc_stack_init(unsigned long size)
54871 +{
54872 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54873 + alloc_stack =
54874 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54875 + else
54876 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54877 +
54878 + alloc_stack_size = size;
54879 +
54880 + if (!alloc_stack)
54881 + return 0;
54882 + else
54883 + return 1;
54884 +}
54885 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54886 new file mode 100644
54887 index 0000000..6d21049
54888 --- /dev/null
54889 +++ b/grsecurity/gracl_cap.c
54890 @@ -0,0 +1,110 @@
54891 +#include <linux/kernel.h>
54892 +#include <linux/module.h>
54893 +#include <linux/sched.h>
54894 +#include <linux/gracl.h>
54895 +#include <linux/grsecurity.h>
54896 +#include <linux/grinternal.h>
54897 +
54898 +extern const char *captab_log[];
54899 +extern int captab_log_entries;
54900 +
54901 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54902 +{
54903 + struct acl_subject_label *curracl;
54904 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54905 + kernel_cap_t cap_audit = __cap_empty_set;
54906 +
54907 + if (!gr_acl_is_enabled())
54908 + return 1;
54909 +
54910 + curracl = task->acl;
54911 +
54912 + cap_drop = curracl->cap_lower;
54913 + cap_mask = curracl->cap_mask;
54914 + cap_audit = curracl->cap_invert_audit;
54915 +
54916 + while ((curracl = curracl->parent_subject)) {
54917 + /* if the cap isn't specified in the current computed mask but is specified in the
54918 + current level subject, and is lowered in the current level subject, then add
54919 + it to the set of dropped capabilities
54920 + otherwise, add the current level subject's mask to the current computed mask
54921 + */
54922 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54923 + cap_raise(cap_mask, cap);
54924 + if (cap_raised(curracl->cap_lower, cap))
54925 + cap_raise(cap_drop, cap);
54926 + if (cap_raised(curracl->cap_invert_audit, cap))
54927 + cap_raise(cap_audit, cap);
54928 + }
54929 + }
54930 +
54931 + if (!cap_raised(cap_drop, cap)) {
54932 + if (cap_raised(cap_audit, cap))
54933 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54934 + return 1;
54935 + }
54936 +
54937 + curracl = task->acl;
54938 +
54939 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54940 + && cap_raised(cred->cap_effective, cap)) {
54941 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54942 + task->role->roletype, cred->uid,
54943 + cred->gid, task->exec_file ?
54944 + gr_to_filename(task->exec_file->f_path.dentry,
54945 + task->exec_file->f_path.mnt) : curracl->filename,
54946 + curracl->filename, 0UL,
54947 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54948 + return 1;
54949 + }
54950 +
54951 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54952 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54953 +
54954 + return 0;
54955 +}
54956 +
54957 +int
54958 +gr_acl_is_capable(const int cap)
54959 +{
54960 + return gr_task_acl_is_capable(current, current_cred(), cap);
54961 +}
54962 +
54963 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54964 +{
54965 + struct acl_subject_label *curracl;
54966 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54967 +
54968 + if (!gr_acl_is_enabled())
54969 + return 1;
54970 +
54971 + curracl = task->acl;
54972 +
54973 + cap_drop = curracl->cap_lower;
54974 + cap_mask = curracl->cap_mask;
54975 +
54976 + while ((curracl = curracl->parent_subject)) {
54977 + /* if the cap isn't specified in the current computed mask but is specified in the
54978 + current level subject, and is lowered in the current level subject, then add
54979 + it to the set of dropped capabilities
54980 + otherwise, add the current level subject's mask to the current computed mask
54981 + */
54982 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54983 + cap_raise(cap_mask, cap);
54984 + if (cap_raised(curracl->cap_lower, cap))
54985 + cap_raise(cap_drop, cap);
54986 + }
54987 + }
54988 +
54989 + if (!cap_raised(cap_drop, cap))
54990 + return 1;
54991 +
54992 + return 0;
54993 +}
54994 +
54995 +int
54996 +gr_acl_is_capable_nolog(const int cap)
54997 +{
54998 + return gr_task_acl_is_capable_nolog(current, cap);
54999 +}
55000 +
55001 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55002 new file mode 100644
55003 index 0000000..88d0e87
55004 --- /dev/null
55005 +++ b/grsecurity/gracl_fs.c
55006 @@ -0,0 +1,435 @@
55007 +#include <linux/kernel.h>
55008 +#include <linux/sched.h>
55009 +#include <linux/types.h>
55010 +#include <linux/fs.h>
55011 +#include <linux/file.h>
55012 +#include <linux/stat.h>
55013 +#include <linux/grsecurity.h>
55014 +#include <linux/grinternal.h>
55015 +#include <linux/gracl.h>
55016 +
55017 +umode_t
55018 +gr_acl_umask(void)
55019 +{
55020 + if (unlikely(!gr_acl_is_enabled()))
55021 + return 0;
55022 +
55023 + return current->role->umask;
55024 +}
55025 +
55026 +__u32
55027 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55028 + const struct vfsmount * mnt)
55029 +{
55030 + __u32 mode;
55031 +
55032 + if (unlikely(!dentry->d_inode))
55033 + return GR_FIND;
55034 +
55035 + mode =
55036 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55037 +
55038 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55039 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55040 + return mode;
55041 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55042 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55043 + return 0;
55044 + } else if (unlikely(!(mode & GR_FIND)))
55045 + return 0;
55046 +
55047 + return GR_FIND;
55048 +}
55049 +
55050 +__u32
55051 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55052 + int acc_mode)
55053 +{
55054 + __u32 reqmode = GR_FIND;
55055 + __u32 mode;
55056 +
55057 + if (unlikely(!dentry->d_inode))
55058 + return reqmode;
55059 +
55060 + if (acc_mode & MAY_APPEND)
55061 + reqmode |= GR_APPEND;
55062 + else if (acc_mode & MAY_WRITE)
55063 + reqmode |= GR_WRITE;
55064 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55065 + reqmode |= GR_READ;
55066 +
55067 + mode =
55068 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55069 + mnt);
55070 +
55071 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55072 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55073 + reqmode & GR_READ ? " reading" : "",
55074 + reqmode & GR_WRITE ? " writing" : reqmode &
55075 + GR_APPEND ? " appending" : "");
55076 + return reqmode;
55077 + } else
55078 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55079 + {
55080 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55081 + reqmode & GR_READ ? " reading" : "",
55082 + reqmode & GR_WRITE ? " writing" : reqmode &
55083 + GR_APPEND ? " appending" : "");
55084 + return 0;
55085 + } else if (unlikely((mode & reqmode) != reqmode))
55086 + return 0;
55087 +
55088 + return reqmode;
55089 +}
55090 +
55091 +__u32
55092 +gr_acl_handle_creat(const struct dentry * dentry,
55093 + const struct dentry * p_dentry,
55094 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55095 + const int imode)
55096 +{
55097 + __u32 reqmode = GR_WRITE | GR_CREATE;
55098 + __u32 mode;
55099 +
55100 + if (acc_mode & MAY_APPEND)
55101 + reqmode |= GR_APPEND;
55102 + // if a directory was required or the directory already exists, then
55103 + // don't count this open as a read
55104 + if ((acc_mode & MAY_READ) &&
55105 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55106 + reqmode |= GR_READ;
55107 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55108 + reqmode |= GR_SETID;
55109 +
55110 + mode =
55111 + gr_check_create(dentry, p_dentry, p_mnt,
55112 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55113 +
55114 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55115 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55116 + reqmode & GR_READ ? " reading" : "",
55117 + reqmode & GR_WRITE ? " writing" : reqmode &
55118 + GR_APPEND ? " appending" : "");
55119 + return reqmode;
55120 + } else
55121 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55122 + {
55123 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55124 + reqmode & GR_READ ? " reading" : "",
55125 + reqmode & GR_WRITE ? " writing" : reqmode &
55126 + GR_APPEND ? " appending" : "");
55127 + return 0;
55128 + } else if (unlikely((mode & reqmode) != reqmode))
55129 + return 0;
55130 +
55131 + return reqmode;
55132 +}
55133 +
55134 +__u32
55135 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55136 + const int fmode)
55137 +{
55138 + __u32 mode, reqmode = GR_FIND;
55139 +
55140 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55141 + reqmode |= GR_EXEC;
55142 + if (fmode & S_IWOTH)
55143 + reqmode |= GR_WRITE;
55144 + if (fmode & S_IROTH)
55145 + reqmode |= GR_READ;
55146 +
55147 + mode =
55148 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55149 + mnt);
55150 +
55151 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55152 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55153 + reqmode & GR_READ ? " reading" : "",
55154 + reqmode & GR_WRITE ? " writing" : "",
55155 + reqmode & GR_EXEC ? " executing" : "");
55156 + return reqmode;
55157 + } else
55158 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55159 + {
55160 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55161 + reqmode & GR_READ ? " reading" : "",
55162 + reqmode & GR_WRITE ? " writing" : "",
55163 + reqmode & GR_EXEC ? " executing" : "");
55164 + return 0;
55165 + } else if (unlikely((mode & reqmode) != reqmode))
55166 + return 0;
55167 +
55168 + return reqmode;
55169 +}
55170 +
55171 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55172 +{
55173 + __u32 mode;
55174 +
55175 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55176 +
55177 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55178 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55179 + return mode;
55180 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55181 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55182 + return 0;
55183 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55184 + return 0;
55185 +
55186 + return (reqmode);
55187 +}
55188 +
55189 +__u32
55190 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55191 +{
55192 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55193 +}
55194 +
55195 +__u32
55196 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55197 +{
55198 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55199 +}
55200 +
55201 +__u32
55202 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55203 +{
55204 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55205 +}
55206 +
55207 +__u32
55208 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55209 +{
55210 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55211 +}
55212 +
55213 +__u32
55214 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55215 + umode_t *modeptr)
55216 +{
55217 + umode_t mode;
55218 +
55219 + *modeptr &= ~gr_acl_umask();
55220 + mode = *modeptr;
55221 +
55222 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55223 + return 1;
55224 +
55225 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55226 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55227 + GR_CHMOD_ACL_MSG);
55228 + } else {
55229 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55230 + }
55231 +}
55232 +
55233 +__u32
55234 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55235 +{
55236 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55237 +}
55238 +
55239 +__u32
55240 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55241 +{
55242 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55243 +}
55244 +
55245 +__u32
55246 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55247 +{
55248 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55249 +}
55250 +
55251 +__u32
55252 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55253 +{
55254 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55255 + GR_UNIXCONNECT_ACL_MSG);
55256 +}
55257 +
55258 +/* hardlinks require at minimum create and link permission,
55259 + any additional privilege required is based on the
55260 + privilege of the file being linked to
55261 +*/
55262 +__u32
55263 +gr_acl_handle_link(const struct dentry * new_dentry,
55264 + const struct dentry * parent_dentry,
55265 + const struct vfsmount * parent_mnt,
55266 + const struct dentry * old_dentry,
55267 + const struct vfsmount * old_mnt, const char *to)
55268 +{
55269 + __u32 mode;
55270 + __u32 needmode = GR_CREATE | GR_LINK;
55271 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55272 +
55273 + mode =
55274 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55275 + old_mnt);
55276 +
55277 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55278 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55279 + return mode;
55280 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55281 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55282 + return 0;
55283 + } else if (unlikely((mode & needmode) != needmode))
55284 + return 0;
55285 +
55286 + return 1;
55287 +}
55288 +
55289 +__u32
55290 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55291 + const struct dentry * parent_dentry,
55292 + const struct vfsmount * parent_mnt, const char *from)
55293 +{
55294 + __u32 needmode = GR_WRITE | GR_CREATE;
55295 + __u32 mode;
55296 +
55297 + mode =
55298 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55299 + GR_CREATE | GR_AUDIT_CREATE |
55300 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55301 +
55302 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55303 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55304 + return mode;
55305 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55306 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55307 + return 0;
55308 + } else if (unlikely((mode & needmode) != needmode))
55309 + return 0;
55310 +
55311 + return (GR_WRITE | GR_CREATE);
55312 +}
55313 +
55314 +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)
55315 +{
55316 + __u32 mode;
55317 +
55318 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55319 +
55320 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55321 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55322 + return mode;
55323 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55324 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55325 + return 0;
55326 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55327 + return 0;
55328 +
55329 + return (reqmode);
55330 +}
55331 +
55332 +__u32
55333 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55334 + const struct dentry * parent_dentry,
55335 + const struct vfsmount * parent_mnt,
55336 + const int mode)
55337 +{
55338 + __u32 reqmode = GR_WRITE | GR_CREATE;
55339 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55340 + reqmode |= GR_SETID;
55341 +
55342 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55343 + reqmode, GR_MKNOD_ACL_MSG);
55344 +}
55345 +
55346 +__u32
55347 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55348 + const struct dentry *parent_dentry,
55349 + const struct vfsmount *parent_mnt)
55350 +{
55351 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55352 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55353 +}
55354 +
55355 +#define RENAME_CHECK_SUCCESS(old, new) \
55356 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55357 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55358 +
55359 +int
55360 +gr_acl_handle_rename(struct dentry *new_dentry,
55361 + struct dentry *parent_dentry,
55362 + const struct vfsmount *parent_mnt,
55363 + struct dentry *old_dentry,
55364 + struct inode *old_parent_inode,
55365 + struct vfsmount *old_mnt, const char *newname)
55366 +{
55367 + __u32 comp1, comp2;
55368 + int error = 0;
55369 +
55370 + if (unlikely(!gr_acl_is_enabled()))
55371 + return 0;
55372 +
55373 + if (!new_dentry->d_inode) {
55374 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55375 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55376 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55377 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55378 + GR_DELETE | GR_AUDIT_DELETE |
55379 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55380 + GR_SUPPRESS, old_mnt);
55381 + } else {
55382 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55383 + GR_CREATE | GR_DELETE |
55384 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55385 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55386 + GR_SUPPRESS, parent_mnt);
55387 + comp2 =
55388 + gr_search_file(old_dentry,
55389 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55390 + GR_DELETE | GR_AUDIT_DELETE |
55391 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55392 + }
55393 +
55394 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55395 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55396 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55397 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55398 + && !(comp2 & GR_SUPPRESS)) {
55399 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55400 + error = -EACCES;
55401 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55402 + error = -EACCES;
55403 +
55404 + return error;
55405 +}
55406 +
55407 +void
55408 +gr_acl_handle_exit(void)
55409 +{
55410 + u16 id;
55411 + char *rolename;
55412 + struct file *exec_file;
55413 +
55414 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55415 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55416 + id = current->acl_role_id;
55417 + rolename = current->role->rolename;
55418 + gr_set_acls(1);
55419 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55420 + }
55421 +
55422 + write_lock(&grsec_exec_file_lock);
55423 + exec_file = current->exec_file;
55424 + current->exec_file = NULL;
55425 + write_unlock(&grsec_exec_file_lock);
55426 +
55427 + if (exec_file)
55428 + fput(exec_file);
55429 +}
55430 +
55431 +int
55432 +gr_acl_handle_procpidmem(const struct task_struct *task)
55433 +{
55434 + if (unlikely(!gr_acl_is_enabled()))
55435 + return 0;
55436 +
55437 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55438 + return -EACCES;
55439 +
55440 + return 0;
55441 +}
55442 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55443 new file mode 100644
55444 index 0000000..58800a7
55445 --- /dev/null
55446 +++ b/grsecurity/gracl_ip.c
55447 @@ -0,0 +1,384 @@
55448 +#include <linux/kernel.h>
55449 +#include <asm/uaccess.h>
55450 +#include <asm/errno.h>
55451 +#include <net/sock.h>
55452 +#include <linux/file.h>
55453 +#include <linux/fs.h>
55454 +#include <linux/net.h>
55455 +#include <linux/in.h>
55456 +#include <linux/skbuff.h>
55457 +#include <linux/ip.h>
55458 +#include <linux/udp.h>
55459 +#include <linux/types.h>
55460 +#include <linux/sched.h>
55461 +#include <linux/netdevice.h>
55462 +#include <linux/inetdevice.h>
55463 +#include <linux/gracl.h>
55464 +#include <linux/grsecurity.h>
55465 +#include <linux/grinternal.h>
55466 +
55467 +#define GR_BIND 0x01
55468 +#define GR_CONNECT 0x02
55469 +#define GR_INVERT 0x04
55470 +#define GR_BINDOVERRIDE 0x08
55471 +#define GR_CONNECTOVERRIDE 0x10
55472 +#define GR_SOCK_FAMILY 0x20
55473 +
55474 +static const char * gr_protocols[IPPROTO_MAX] = {
55475 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55476 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55477 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55478 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55479 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55480 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55481 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55482 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55483 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55484 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55485 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55486 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55487 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55488 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55489 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55490 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55491 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55492 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55493 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55494 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55495 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55496 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55497 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55498 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55499 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55500 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55501 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55502 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55503 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55504 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55505 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55506 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55507 + };
55508 +
55509 +static const char * gr_socktypes[SOCK_MAX] = {
55510 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55511 + "unknown:7", "unknown:8", "unknown:9", "packet"
55512 + };
55513 +
55514 +static const char * gr_sockfamilies[AF_MAX+1] = {
55515 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55516 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55517 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55518 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55519 + };
55520 +
55521 +const char *
55522 +gr_proto_to_name(unsigned char proto)
55523 +{
55524 + return gr_protocols[proto];
55525 +}
55526 +
55527 +const char *
55528 +gr_socktype_to_name(unsigned char type)
55529 +{
55530 + return gr_socktypes[type];
55531 +}
55532 +
55533 +const char *
55534 +gr_sockfamily_to_name(unsigned char family)
55535 +{
55536 + return gr_sockfamilies[family];
55537 +}
55538 +
55539 +int
55540 +gr_search_socket(const int domain, const int type, const int protocol)
55541 +{
55542 + struct acl_subject_label *curr;
55543 + const struct cred *cred = current_cred();
55544 +
55545 + if (unlikely(!gr_acl_is_enabled()))
55546 + goto exit;
55547 +
55548 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55549 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55550 + goto exit; // let the kernel handle it
55551 +
55552 + curr = current->acl;
55553 +
55554 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55555 + /* the family is allowed, if this is PF_INET allow it only if
55556 + the extra sock type/protocol checks pass */
55557 + if (domain == PF_INET)
55558 + goto inet_check;
55559 + goto exit;
55560 + } else {
55561 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55562 + __u32 fakeip = 0;
55563 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55564 + current->role->roletype, cred->uid,
55565 + cred->gid, current->exec_file ?
55566 + gr_to_filename(current->exec_file->f_path.dentry,
55567 + current->exec_file->f_path.mnt) :
55568 + curr->filename, curr->filename,
55569 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55570 + &current->signal->saved_ip);
55571 + goto exit;
55572 + }
55573 + goto exit_fail;
55574 + }
55575 +
55576 +inet_check:
55577 + /* the rest of this checking is for IPv4 only */
55578 + if (!curr->ips)
55579 + goto exit;
55580 +
55581 + if ((curr->ip_type & (1 << type)) &&
55582 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55583 + goto exit;
55584 +
55585 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55586 + /* we don't place acls on raw sockets , and sometimes
55587 + dgram/ip sockets are opened for ioctl and not
55588 + bind/connect, so we'll fake a bind learn log */
55589 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55590 + __u32 fakeip = 0;
55591 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55592 + current->role->roletype, cred->uid,
55593 + cred->gid, current->exec_file ?
55594 + gr_to_filename(current->exec_file->f_path.dentry,
55595 + current->exec_file->f_path.mnt) :
55596 + curr->filename, curr->filename,
55597 + &fakeip, 0, type,
55598 + protocol, GR_CONNECT, &current->signal->saved_ip);
55599 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55600 + __u32 fakeip = 0;
55601 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55602 + current->role->roletype, cred->uid,
55603 + cred->gid, current->exec_file ?
55604 + gr_to_filename(current->exec_file->f_path.dentry,
55605 + current->exec_file->f_path.mnt) :
55606 + curr->filename, curr->filename,
55607 + &fakeip, 0, type,
55608 + protocol, GR_BIND, &current->signal->saved_ip);
55609 + }
55610 + /* we'll log when they use connect or bind */
55611 + goto exit;
55612 + }
55613 +
55614 +exit_fail:
55615 + if (domain == PF_INET)
55616 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55617 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55618 + else
55619 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55620 + gr_socktype_to_name(type), protocol);
55621 +
55622 + return 0;
55623 +exit:
55624 + return 1;
55625 +}
55626 +
55627 +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)
55628 +{
55629 + if ((ip->mode & mode) &&
55630 + (ip_port >= ip->low) &&
55631 + (ip_port <= ip->high) &&
55632 + ((ntohl(ip_addr) & our_netmask) ==
55633 + (ntohl(our_addr) & our_netmask))
55634 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55635 + && (ip->type & (1 << type))) {
55636 + if (ip->mode & GR_INVERT)
55637 + return 2; // specifically denied
55638 + else
55639 + return 1; // allowed
55640 + }
55641 +
55642 + return 0; // not specifically allowed, may continue parsing
55643 +}
55644 +
55645 +static int
55646 +gr_search_connectbind(const int full_mode, struct sock *sk,
55647 + struct sockaddr_in *addr, const int type)
55648 +{
55649 + char iface[IFNAMSIZ] = {0};
55650 + struct acl_subject_label *curr;
55651 + struct acl_ip_label *ip;
55652 + struct inet_sock *isk;
55653 + struct net_device *dev;
55654 + struct in_device *idev;
55655 + unsigned long i;
55656 + int ret;
55657 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55658 + __u32 ip_addr = 0;
55659 + __u32 our_addr;
55660 + __u32 our_netmask;
55661 + char *p;
55662 + __u16 ip_port = 0;
55663 + const struct cred *cred = current_cred();
55664 +
55665 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55666 + return 0;
55667 +
55668 + curr = current->acl;
55669 + isk = inet_sk(sk);
55670 +
55671 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55672 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55673 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55674 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55675 + struct sockaddr_in saddr;
55676 + int err;
55677 +
55678 + saddr.sin_family = AF_INET;
55679 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55680 + saddr.sin_port = isk->inet_sport;
55681 +
55682 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55683 + if (err)
55684 + return err;
55685 +
55686 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55687 + if (err)
55688 + return err;
55689 + }
55690 +
55691 + if (!curr->ips)
55692 + return 0;
55693 +
55694 + ip_addr = addr->sin_addr.s_addr;
55695 + ip_port = ntohs(addr->sin_port);
55696 +
55697 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55698 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55699 + current->role->roletype, cred->uid,
55700 + cred->gid, current->exec_file ?
55701 + gr_to_filename(current->exec_file->f_path.dentry,
55702 + current->exec_file->f_path.mnt) :
55703 + curr->filename, curr->filename,
55704 + &ip_addr, ip_port, type,
55705 + sk->sk_protocol, mode, &current->signal->saved_ip);
55706 + return 0;
55707 + }
55708 +
55709 + for (i = 0; i < curr->ip_num; i++) {
55710 + ip = *(curr->ips + i);
55711 + if (ip->iface != NULL) {
55712 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55713 + p = strchr(iface, ':');
55714 + if (p != NULL)
55715 + *p = '\0';
55716 + dev = dev_get_by_name(sock_net(sk), iface);
55717 + if (dev == NULL)
55718 + continue;
55719 + idev = in_dev_get(dev);
55720 + if (idev == NULL) {
55721 + dev_put(dev);
55722 + continue;
55723 + }
55724 + rcu_read_lock();
55725 + for_ifa(idev) {
55726 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55727 + our_addr = ifa->ifa_address;
55728 + our_netmask = 0xffffffff;
55729 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55730 + if (ret == 1) {
55731 + rcu_read_unlock();
55732 + in_dev_put(idev);
55733 + dev_put(dev);
55734 + return 0;
55735 + } else if (ret == 2) {
55736 + rcu_read_unlock();
55737 + in_dev_put(idev);
55738 + dev_put(dev);
55739 + goto denied;
55740 + }
55741 + }
55742 + } endfor_ifa(idev);
55743 + rcu_read_unlock();
55744 + in_dev_put(idev);
55745 + dev_put(dev);
55746 + } else {
55747 + our_addr = ip->addr;
55748 + our_netmask = ip->netmask;
55749 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55750 + if (ret == 1)
55751 + return 0;
55752 + else if (ret == 2)
55753 + goto denied;
55754 + }
55755 + }
55756 +
55757 +denied:
55758 + if (mode == GR_BIND)
55759 + 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));
55760 + else if (mode == GR_CONNECT)
55761 + 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));
55762 +
55763 + return -EACCES;
55764 +}
55765 +
55766 +int
55767 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55768 +{
55769 + /* always allow disconnection of dgram sockets with connect */
55770 + if (addr->sin_family == AF_UNSPEC)
55771 + return 0;
55772 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55773 +}
55774 +
55775 +int
55776 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55777 +{
55778 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55779 +}
55780 +
55781 +int gr_search_listen(struct socket *sock)
55782 +{
55783 + struct sock *sk = sock->sk;
55784 + struct sockaddr_in addr;
55785 +
55786 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55787 + addr.sin_port = inet_sk(sk)->inet_sport;
55788 +
55789 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55790 +}
55791 +
55792 +int gr_search_accept(struct socket *sock)
55793 +{
55794 + struct sock *sk = sock->sk;
55795 + struct sockaddr_in addr;
55796 +
55797 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55798 + addr.sin_port = inet_sk(sk)->inet_sport;
55799 +
55800 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55801 +}
55802 +
55803 +int
55804 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55805 +{
55806 + if (addr)
55807 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55808 + else {
55809 + struct sockaddr_in sin;
55810 + const struct inet_sock *inet = inet_sk(sk);
55811 +
55812 + sin.sin_addr.s_addr = inet->inet_daddr;
55813 + sin.sin_port = inet->inet_dport;
55814 +
55815 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55816 + }
55817 +}
55818 +
55819 +int
55820 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55821 +{
55822 + struct sockaddr_in sin;
55823 +
55824 + if (unlikely(skb->len < sizeof (struct udphdr)))
55825 + return 0; // skip this packet
55826 +
55827 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55828 + sin.sin_port = udp_hdr(skb)->source;
55829 +
55830 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55831 +}
55832 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55833 new file mode 100644
55834 index 0000000..25f54ef
55835 --- /dev/null
55836 +++ b/grsecurity/gracl_learn.c
55837 @@ -0,0 +1,207 @@
55838 +#include <linux/kernel.h>
55839 +#include <linux/mm.h>
55840 +#include <linux/sched.h>
55841 +#include <linux/poll.h>
55842 +#include <linux/string.h>
55843 +#include <linux/file.h>
55844 +#include <linux/types.h>
55845 +#include <linux/vmalloc.h>
55846 +#include <linux/grinternal.h>
55847 +
55848 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55849 + size_t count, loff_t *ppos);
55850 +extern int gr_acl_is_enabled(void);
55851 +
55852 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55853 +static int gr_learn_attached;
55854 +
55855 +/* use a 512k buffer */
55856 +#define LEARN_BUFFER_SIZE (512 * 1024)
55857 +
55858 +static DEFINE_SPINLOCK(gr_learn_lock);
55859 +static DEFINE_MUTEX(gr_learn_user_mutex);
55860 +
55861 +/* we need to maintain two buffers, so that the kernel context of grlearn
55862 + uses a semaphore around the userspace copying, and the other kernel contexts
55863 + use a spinlock when copying into the buffer, since they cannot sleep
55864 +*/
55865 +static char *learn_buffer;
55866 +static char *learn_buffer_user;
55867 +static int learn_buffer_len;
55868 +static int learn_buffer_user_len;
55869 +
55870 +static ssize_t
55871 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55872 +{
55873 + DECLARE_WAITQUEUE(wait, current);
55874 + ssize_t retval = 0;
55875 +
55876 + add_wait_queue(&learn_wait, &wait);
55877 + set_current_state(TASK_INTERRUPTIBLE);
55878 + do {
55879 + mutex_lock(&gr_learn_user_mutex);
55880 + spin_lock(&gr_learn_lock);
55881 + if (learn_buffer_len)
55882 + break;
55883 + spin_unlock(&gr_learn_lock);
55884 + mutex_unlock(&gr_learn_user_mutex);
55885 + if (file->f_flags & O_NONBLOCK) {
55886 + retval = -EAGAIN;
55887 + goto out;
55888 + }
55889 + if (signal_pending(current)) {
55890 + retval = -ERESTARTSYS;
55891 + goto out;
55892 + }
55893 +
55894 + schedule();
55895 + } while (1);
55896 +
55897 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55898 + learn_buffer_user_len = learn_buffer_len;
55899 + retval = learn_buffer_len;
55900 + learn_buffer_len = 0;
55901 +
55902 + spin_unlock(&gr_learn_lock);
55903 +
55904 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55905 + retval = -EFAULT;
55906 +
55907 + mutex_unlock(&gr_learn_user_mutex);
55908 +out:
55909 + set_current_state(TASK_RUNNING);
55910 + remove_wait_queue(&learn_wait, &wait);
55911 + return retval;
55912 +}
55913 +
55914 +static unsigned int
55915 +poll_learn(struct file * file, poll_table * wait)
55916 +{
55917 + poll_wait(file, &learn_wait, wait);
55918 +
55919 + if (learn_buffer_len)
55920 + return (POLLIN | POLLRDNORM);
55921 +
55922 + return 0;
55923 +}
55924 +
55925 +void
55926 +gr_clear_learn_entries(void)
55927 +{
55928 + char *tmp;
55929 +
55930 + mutex_lock(&gr_learn_user_mutex);
55931 + spin_lock(&gr_learn_lock);
55932 + tmp = learn_buffer;
55933 + learn_buffer = NULL;
55934 + spin_unlock(&gr_learn_lock);
55935 + if (tmp)
55936 + vfree(tmp);
55937 + if (learn_buffer_user != NULL) {
55938 + vfree(learn_buffer_user);
55939 + learn_buffer_user = NULL;
55940 + }
55941 + learn_buffer_len = 0;
55942 + mutex_unlock(&gr_learn_user_mutex);
55943 +
55944 + return;
55945 +}
55946 +
55947 +void
55948 +gr_add_learn_entry(const char *fmt, ...)
55949 +{
55950 + va_list args;
55951 + unsigned int len;
55952 +
55953 + if (!gr_learn_attached)
55954 + return;
55955 +
55956 + spin_lock(&gr_learn_lock);
55957 +
55958 + /* leave a gap at the end so we know when it's "full" but don't have to
55959 + compute the exact length of the string we're trying to append
55960 + */
55961 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55962 + spin_unlock(&gr_learn_lock);
55963 + wake_up_interruptible(&learn_wait);
55964 + return;
55965 + }
55966 + if (learn_buffer == NULL) {
55967 + spin_unlock(&gr_learn_lock);
55968 + return;
55969 + }
55970 +
55971 + va_start(args, fmt);
55972 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55973 + va_end(args);
55974 +
55975 + learn_buffer_len += len + 1;
55976 +
55977 + spin_unlock(&gr_learn_lock);
55978 + wake_up_interruptible(&learn_wait);
55979 +
55980 + return;
55981 +}
55982 +
55983 +static int
55984 +open_learn(struct inode *inode, struct file *file)
55985 +{
55986 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55987 + return -EBUSY;
55988 + if (file->f_mode & FMODE_READ) {
55989 + int retval = 0;
55990 + mutex_lock(&gr_learn_user_mutex);
55991 + if (learn_buffer == NULL)
55992 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55993 + if (learn_buffer_user == NULL)
55994 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55995 + if (learn_buffer == NULL) {
55996 + retval = -ENOMEM;
55997 + goto out_error;
55998 + }
55999 + if (learn_buffer_user == NULL) {
56000 + retval = -ENOMEM;
56001 + goto out_error;
56002 + }
56003 + learn_buffer_len = 0;
56004 + learn_buffer_user_len = 0;
56005 + gr_learn_attached = 1;
56006 +out_error:
56007 + mutex_unlock(&gr_learn_user_mutex);
56008 + return retval;
56009 + }
56010 + return 0;
56011 +}
56012 +
56013 +static int
56014 +close_learn(struct inode *inode, struct file *file)
56015 +{
56016 + if (file->f_mode & FMODE_READ) {
56017 + char *tmp = NULL;
56018 + mutex_lock(&gr_learn_user_mutex);
56019 + spin_lock(&gr_learn_lock);
56020 + tmp = learn_buffer;
56021 + learn_buffer = NULL;
56022 + spin_unlock(&gr_learn_lock);
56023 + if (tmp)
56024 + vfree(tmp);
56025 + if (learn_buffer_user != NULL) {
56026 + vfree(learn_buffer_user);
56027 + learn_buffer_user = NULL;
56028 + }
56029 + learn_buffer_len = 0;
56030 + learn_buffer_user_len = 0;
56031 + gr_learn_attached = 0;
56032 + mutex_unlock(&gr_learn_user_mutex);
56033 + }
56034 +
56035 + return 0;
56036 +}
56037 +
56038 +const struct file_operations grsec_fops = {
56039 + .read = read_learn,
56040 + .write = write_grsec_handler,
56041 + .open = open_learn,
56042 + .release = close_learn,
56043 + .poll = poll_learn,
56044 +};
56045 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56046 new file mode 100644
56047 index 0000000..39645c9
56048 --- /dev/null
56049 +++ b/grsecurity/gracl_res.c
56050 @@ -0,0 +1,68 @@
56051 +#include <linux/kernel.h>
56052 +#include <linux/sched.h>
56053 +#include <linux/gracl.h>
56054 +#include <linux/grinternal.h>
56055 +
56056 +static const char *restab_log[] = {
56057 + [RLIMIT_CPU] = "RLIMIT_CPU",
56058 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56059 + [RLIMIT_DATA] = "RLIMIT_DATA",
56060 + [RLIMIT_STACK] = "RLIMIT_STACK",
56061 + [RLIMIT_CORE] = "RLIMIT_CORE",
56062 + [RLIMIT_RSS] = "RLIMIT_RSS",
56063 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56064 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56065 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56066 + [RLIMIT_AS] = "RLIMIT_AS",
56067 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56068 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56069 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56070 + [RLIMIT_NICE] = "RLIMIT_NICE",
56071 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56072 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56073 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56074 +};
56075 +
56076 +void
56077 +gr_log_resource(const struct task_struct *task,
56078 + const int res, const unsigned long wanted, const int gt)
56079 +{
56080 + const struct cred *cred;
56081 + unsigned long rlim;
56082 +
56083 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56084 + return;
56085 +
56086 + // not yet supported resource
56087 + if (unlikely(!restab_log[res]))
56088 + return;
56089 +
56090 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56091 + rlim = task_rlimit_max(task, res);
56092 + else
56093 + rlim = task_rlimit(task, res);
56094 +
56095 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56096 + return;
56097 +
56098 + rcu_read_lock();
56099 + cred = __task_cred(task);
56100 +
56101 + if (res == RLIMIT_NPROC &&
56102 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56103 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56104 + goto out_rcu_unlock;
56105 + else if (res == RLIMIT_MEMLOCK &&
56106 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56107 + goto out_rcu_unlock;
56108 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56109 + goto out_rcu_unlock;
56110 + rcu_read_unlock();
56111 +
56112 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56113 +
56114 + return;
56115 +out_rcu_unlock:
56116 + rcu_read_unlock();
56117 + return;
56118 +}
56119 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56120 new file mode 100644
56121 index 0000000..5556be3
56122 --- /dev/null
56123 +++ b/grsecurity/gracl_segv.c
56124 @@ -0,0 +1,299 @@
56125 +#include <linux/kernel.h>
56126 +#include <linux/mm.h>
56127 +#include <asm/uaccess.h>
56128 +#include <asm/errno.h>
56129 +#include <asm/mman.h>
56130 +#include <net/sock.h>
56131 +#include <linux/file.h>
56132 +#include <linux/fs.h>
56133 +#include <linux/net.h>
56134 +#include <linux/in.h>
56135 +#include <linux/slab.h>
56136 +#include <linux/types.h>
56137 +#include <linux/sched.h>
56138 +#include <linux/timer.h>
56139 +#include <linux/gracl.h>
56140 +#include <linux/grsecurity.h>
56141 +#include <linux/grinternal.h>
56142 +
56143 +static struct crash_uid *uid_set;
56144 +static unsigned short uid_used;
56145 +static DEFINE_SPINLOCK(gr_uid_lock);
56146 +extern rwlock_t gr_inode_lock;
56147 +extern struct acl_subject_label *
56148 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56149 + struct acl_role_label *role);
56150 +
56151 +#ifdef CONFIG_BTRFS_FS
56152 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56153 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56154 +#endif
56155 +
56156 +static inline dev_t __get_dev(const struct dentry *dentry)
56157 +{
56158 +#ifdef CONFIG_BTRFS_FS
56159 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56160 + return get_btrfs_dev_from_inode(dentry->d_inode);
56161 + else
56162 +#endif
56163 + return dentry->d_inode->i_sb->s_dev;
56164 +}
56165 +
56166 +int
56167 +gr_init_uidset(void)
56168 +{
56169 + uid_set =
56170 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56171 + uid_used = 0;
56172 +
56173 + return uid_set ? 1 : 0;
56174 +}
56175 +
56176 +void
56177 +gr_free_uidset(void)
56178 +{
56179 + if (uid_set)
56180 + kfree(uid_set);
56181 +
56182 + return;
56183 +}
56184 +
56185 +int
56186 +gr_find_uid(const uid_t uid)
56187 +{
56188 + struct crash_uid *tmp = uid_set;
56189 + uid_t buid;
56190 + int low = 0, high = uid_used - 1, mid;
56191 +
56192 + while (high >= low) {
56193 + mid = (low + high) >> 1;
56194 + buid = tmp[mid].uid;
56195 + if (buid == uid)
56196 + return mid;
56197 + if (buid > uid)
56198 + high = mid - 1;
56199 + if (buid < uid)
56200 + low = mid + 1;
56201 + }
56202 +
56203 + return -1;
56204 +}
56205 +
56206 +static __inline__ void
56207 +gr_insertsort(void)
56208 +{
56209 + unsigned short i, j;
56210 + struct crash_uid index;
56211 +
56212 + for (i = 1; i < uid_used; i++) {
56213 + index = uid_set[i];
56214 + j = i;
56215 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56216 + uid_set[j] = uid_set[j - 1];
56217 + j--;
56218 + }
56219 + uid_set[j] = index;
56220 + }
56221 +
56222 + return;
56223 +}
56224 +
56225 +static __inline__ void
56226 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56227 +{
56228 + int loc;
56229 +
56230 + if (uid_used == GR_UIDTABLE_MAX)
56231 + return;
56232 +
56233 + loc = gr_find_uid(uid);
56234 +
56235 + if (loc >= 0) {
56236 + uid_set[loc].expires = expires;
56237 + return;
56238 + }
56239 +
56240 + uid_set[uid_used].uid = uid;
56241 + uid_set[uid_used].expires = expires;
56242 + uid_used++;
56243 +
56244 + gr_insertsort();
56245 +
56246 + return;
56247 +}
56248 +
56249 +void
56250 +gr_remove_uid(const unsigned short loc)
56251 +{
56252 + unsigned short i;
56253 +
56254 + for (i = loc + 1; i < uid_used; i++)
56255 + uid_set[i - 1] = uid_set[i];
56256 +
56257 + uid_used--;
56258 +
56259 + return;
56260 +}
56261 +
56262 +int
56263 +gr_check_crash_uid(const uid_t uid)
56264 +{
56265 + int loc;
56266 + int ret = 0;
56267 +
56268 + if (unlikely(!gr_acl_is_enabled()))
56269 + return 0;
56270 +
56271 + spin_lock(&gr_uid_lock);
56272 + loc = gr_find_uid(uid);
56273 +
56274 + if (loc < 0)
56275 + goto out_unlock;
56276 +
56277 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56278 + gr_remove_uid(loc);
56279 + else
56280 + ret = 1;
56281 +
56282 +out_unlock:
56283 + spin_unlock(&gr_uid_lock);
56284 + return ret;
56285 +}
56286 +
56287 +static __inline__ int
56288 +proc_is_setxid(const struct cred *cred)
56289 +{
56290 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56291 + cred->uid != cred->fsuid)
56292 + return 1;
56293 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56294 + cred->gid != cred->fsgid)
56295 + return 1;
56296 +
56297 + return 0;
56298 +}
56299 +
56300 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56301 +
56302 +void
56303 +gr_handle_crash(struct task_struct *task, const int sig)
56304 +{
56305 + struct acl_subject_label *curr;
56306 + struct task_struct *tsk, *tsk2;
56307 + const struct cred *cred;
56308 + const struct cred *cred2;
56309 +
56310 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56311 + return;
56312 +
56313 + if (unlikely(!gr_acl_is_enabled()))
56314 + return;
56315 +
56316 + curr = task->acl;
56317 +
56318 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56319 + return;
56320 +
56321 + if (time_before_eq(curr->expires, get_seconds())) {
56322 + curr->expires = 0;
56323 + curr->crashes = 0;
56324 + }
56325 +
56326 + curr->crashes++;
56327 +
56328 + if (!curr->expires)
56329 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56330 +
56331 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56332 + time_after(curr->expires, get_seconds())) {
56333 + rcu_read_lock();
56334 + cred = __task_cred(task);
56335 + if (cred->uid && proc_is_setxid(cred)) {
56336 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56337 + spin_lock(&gr_uid_lock);
56338 + gr_insert_uid(cred->uid, curr->expires);
56339 + spin_unlock(&gr_uid_lock);
56340 + curr->expires = 0;
56341 + curr->crashes = 0;
56342 + read_lock(&tasklist_lock);
56343 + do_each_thread(tsk2, tsk) {
56344 + cred2 = __task_cred(tsk);
56345 + if (tsk != task && cred2->uid == cred->uid)
56346 + gr_fake_force_sig(SIGKILL, tsk);
56347 + } while_each_thread(tsk2, tsk);
56348 + read_unlock(&tasklist_lock);
56349 + } else {
56350 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56351 + read_lock(&tasklist_lock);
56352 + read_lock(&grsec_exec_file_lock);
56353 + do_each_thread(tsk2, tsk) {
56354 + if (likely(tsk != task)) {
56355 + // if this thread has the same subject as the one that triggered
56356 + // RES_CRASH and it's the same binary, kill it
56357 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56358 + gr_fake_force_sig(SIGKILL, tsk);
56359 + }
56360 + } while_each_thread(tsk2, tsk);
56361 + read_unlock(&grsec_exec_file_lock);
56362 + read_unlock(&tasklist_lock);
56363 + }
56364 + rcu_read_unlock();
56365 + }
56366 +
56367 + return;
56368 +}
56369 +
56370 +int
56371 +gr_check_crash_exec(const struct file *filp)
56372 +{
56373 + struct acl_subject_label *curr;
56374 +
56375 + if (unlikely(!gr_acl_is_enabled()))
56376 + return 0;
56377 +
56378 + read_lock(&gr_inode_lock);
56379 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56380 + __get_dev(filp->f_path.dentry),
56381 + current->role);
56382 + read_unlock(&gr_inode_lock);
56383 +
56384 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56385 + (!curr->crashes && !curr->expires))
56386 + return 0;
56387 +
56388 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56389 + time_after(curr->expires, get_seconds()))
56390 + return 1;
56391 + else if (time_before_eq(curr->expires, get_seconds())) {
56392 + curr->crashes = 0;
56393 + curr->expires = 0;
56394 + }
56395 +
56396 + return 0;
56397 +}
56398 +
56399 +void
56400 +gr_handle_alertkill(struct task_struct *task)
56401 +{
56402 + struct acl_subject_label *curracl;
56403 + __u32 curr_ip;
56404 + struct task_struct *p, *p2;
56405 +
56406 + if (unlikely(!gr_acl_is_enabled()))
56407 + return;
56408 +
56409 + curracl = task->acl;
56410 + curr_ip = task->signal->curr_ip;
56411 +
56412 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56413 + read_lock(&tasklist_lock);
56414 + do_each_thread(p2, p) {
56415 + if (p->signal->curr_ip == curr_ip)
56416 + gr_fake_force_sig(SIGKILL, p);
56417 + } while_each_thread(p2, p);
56418 + read_unlock(&tasklist_lock);
56419 + } else if (curracl->mode & GR_KILLPROC)
56420 + gr_fake_force_sig(SIGKILL, task);
56421 +
56422 + return;
56423 +}
56424 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56425 new file mode 100644
56426 index 0000000..9d83a69
56427 --- /dev/null
56428 +++ b/grsecurity/gracl_shm.c
56429 @@ -0,0 +1,40 @@
56430 +#include <linux/kernel.h>
56431 +#include <linux/mm.h>
56432 +#include <linux/sched.h>
56433 +#include <linux/file.h>
56434 +#include <linux/ipc.h>
56435 +#include <linux/gracl.h>
56436 +#include <linux/grsecurity.h>
56437 +#include <linux/grinternal.h>
56438 +
56439 +int
56440 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56441 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56442 +{
56443 + struct task_struct *task;
56444 +
56445 + if (!gr_acl_is_enabled())
56446 + return 1;
56447 +
56448 + rcu_read_lock();
56449 + read_lock(&tasklist_lock);
56450 +
56451 + task = find_task_by_vpid(shm_cprid);
56452 +
56453 + if (unlikely(!task))
56454 + task = find_task_by_vpid(shm_lapid);
56455 +
56456 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56457 + (task->pid == shm_lapid)) &&
56458 + (task->acl->mode & GR_PROTSHM) &&
56459 + (task->acl != current->acl))) {
56460 + read_unlock(&tasklist_lock);
56461 + rcu_read_unlock();
56462 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56463 + return 0;
56464 + }
56465 + read_unlock(&tasklist_lock);
56466 + rcu_read_unlock();
56467 +
56468 + return 1;
56469 +}
56470 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56471 new file mode 100644
56472 index 0000000..bc0be01
56473 --- /dev/null
56474 +++ b/grsecurity/grsec_chdir.c
56475 @@ -0,0 +1,19 @@
56476 +#include <linux/kernel.h>
56477 +#include <linux/sched.h>
56478 +#include <linux/fs.h>
56479 +#include <linux/file.h>
56480 +#include <linux/grsecurity.h>
56481 +#include <linux/grinternal.h>
56482 +
56483 +void
56484 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56485 +{
56486 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56487 + if ((grsec_enable_chdir && grsec_enable_group &&
56488 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56489 + !grsec_enable_group)) {
56490 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56491 + }
56492 +#endif
56493 + return;
56494 +}
56495 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56496 new file mode 100644
56497 index 0000000..9807ee2
56498 --- /dev/null
56499 +++ b/grsecurity/grsec_chroot.c
56500 @@ -0,0 +1,368 @@
56501 +#include <linux/kernel.h>
56502 +#include <linux/module.h>
56503 +#include <linux/sched.h>
56504 +#include <linux/file.h>
56505 +#include <linux/fs.h>
56506 +#include <linux/mount.h>
56507 +#include <linux/types.h>
56508 +#include "../fs/mount.h"
56509 +#include <linux/grsecurity.h>
56510 +#include <linux/grinternal.h>
56511 +
56512 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56513 +{
56514 +#ifdef CONFIG_GRKERNSEC
56515 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56516 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56517 + task->gr_is_chrooted = 1;
56518 + else
56519 + task->gr_is_chrooted = 0;
56520 +
56521 + task->gr_chroot_dentry = path->dentry;
56522 +#endif
56523 + return;
56524 +}
56525 +
56526 +void gr_clear_chroot_entries(struct task_struct *task)
56527 +{
56528 +#ifdef CONFIG_GRKERNSEC
56529 + task->gr_is_chrooted = 0;
56530 + task->gr_chroot_dentry = NULL;
56531 +#endif
56532 + return;
56533 +}
56534 +
56535 +int
56536 +gr_handle_chroot_unix(const pid_t pid)
56537 +{
56538 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56539 + struct task_struct *p;
56540 +
56541 + if (unlikely(!grsec_enable_chroot_unix))
56542 + return 1;
56543 +
56544 + if (likely(!proc_is_chrooted(current)))
56545 + return 1;
56546 +
56547 + rcu_read_lock();
56548 + read_lock(&tasklist_lock);
56549 + p = find_task_by_vpid_unrestricted(pid);
56550 + if (unlikely(p && !have_same_root(current, p))) {
56551 + read_unlock(&tasklist_lock);
56552 + rcu_read_unlock();
56553 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56554 + return 0;
56555 + }
56556 + read_unlock(&tasklist_lock);
56557 + rcu_read_unlock();
56558 +#endif
56559 + return 1;
56560 +}
56561 +
56562 +int
56563 +gr_handle_chroot_nice(void)
56564 +{
56565 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56566 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56567 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56568 + return -EPERM;
56569 + }
56570 +#endif
56571 + return 0;
56572 +}
56573 +
56574 +int
56575 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56576 +{
56577 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56578 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56579 + && proc_is_chrooted(current)) {
56580 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56581 + return -EACCES;
56582 + }
56583 +#endif
56584 + return 0;
56585 +}
56586 +
56587 +int
56588 +gr_handle_chroot_rawio(const struct inode *inode)
56589 +{
56590 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56591 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56592 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56593 + return 1;
56594 +#endif
56595 + return 0;
56596 +}
56597 +
56598 +int
56599 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56600 +{
56601 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56602 + struct task_struct *p;
56603 + int ret = 0;
56604 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56605 + return ret;
56606 +
56607 + read_lock(&tasklist_lock);
56608 + do_each_pid_task(pid, type, p) {
56609 + if (!have_same_root(current, p)) {
56610 + ret = 1;
56611 + goto out;
56612 + }
56613 + } while_each_pid_task(pid, type, p);
56614 +out:
56615 + read_unlock(&tasklist_lock);
56616 + return ret;
56617 +#endif
56618 + return 0;
56619 +}
56620 +
56621 +int
56622 +gr_pid_is_chrooted(struct task_struct *p)
56623 +{
56624 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56625 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56626 + return 0;
56627 +
56628 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56629 + !have_same_root(current, p)) {
56630 + return 1;
56631 + }
56632 +#endif
56633 + return 0;
56634 +}
56635 +
56636 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56637 +
56638 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56639 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56640 +{
56641 + struct path path, currentroot;
56642 + int ret = 0;
56643 +
56644 + path.dentry = (struct dentry *)u_dentry;
56645 + path.mnt = (struct vfsmount *)u_mnt;
56646 + get_fs_root(current->fs, &currentroot);
56647 + if (path_is_under(&path, &currentroot))
56648 + ret = 1;
56649 + path_put(&currentroot);
56650 +
56651 + return ret;
56652 +}
56653 +#endif
56654 +
56655 +int
56656 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56657 +{
56658 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56659 + if (!grsec_enable_chroot_fchdir)
56660 + return 1;
56661 +
56662 + if (!proc_is_chrooted(current))
56663 + return 1;
56664 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56665 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56666 + return 0;
56667 + }
56668 +#endif
56669 + return 1;
56670 +}
56671 +
56672 +int
56673 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56674 + const time_t shm_createtime)
56675 +{
56676 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56677 + struct task_struct *p;
56678 + time_t starttime;
56679 +
56680 + if (unlikely(!grsec_enable_chroot_shmat))
56681 + return 1;
56682 +
56683 + if (likely(!proc_is_chrooted(current)))
56684 + return 1;
56685 +
56686 + rcu_read_lock();
56687 + read_lock(&tasklist_lock);
56688 +
56689 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56690 + starttime = p->start_time.tv_sec;
56691 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56692 + if (have_same_root(current, p)) {
56693 + goto allow;
56694 + } else {
56695 + read_unlock(&tasklist_lock);
56696 + rcu_read_unlock();
56697 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56698 + return 0;
56699 + }
56700 + }
56701 + /* creator exited, pid reuse, fall through to next check */
56702 + }
56703 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56704 + if (unlikely(!have_same_root(current, p))) {
56705 + read_unlock(&tasklist_lock);
56706 + rcu_read_unlock();
56707 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56708 + return 0;
56709 + }
56710 + }
56711 +
56712 +allow:
56713 + read_unlock(&tasklist_lock);
56714 + rcu_read_unlock();
56715 +#endif
56716 + return 1;
56717 +}
56718 +
56719 +void
56720 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56721 +{
56722 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56723 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56724 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56725 +#endif
56726 + return;
56727 +}
56728 +
56729 +int
56730 +gr_handle_chroot_mknod(const struct dentry *dentry,
56731 + const struct vfsmount *mnt, const int mode)
56732 +{
56733 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56734 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56735 + proc_is_chrooted(current)) {
56736 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56737 + return -EPERM;
56738 + }
56739 +#endif
56740 + return 0;
56741 +}
56742 +
56743 +int
56744 +gr_handle_chroot_mount(const struct dentry *dentry,
56745 + const struct vfsmount *mnt, const char *dev_name)
56746 +{
56747 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56748 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56749 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56750 + return -EPERM;
56751 + }
56752 +#endif
56753 + return 0;
56754 +}
56755 +
56756 +int
56757 +gr_handle_chroot_pivot(void)
56758 +{
56759 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56760 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56761 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56762 + return -EPERM;
56763 + }
56764 +#endif
56765 + return 0;
56766 +}
56767 +
56768 +int
56769 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56770 +{
56771 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56772 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56773 + !gr_is_outside_chroot(dentry, mnt)) {
56774 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56775 + return -EPERM;
56776 + }
56777 +#endif
56778 + return 0;
56779 +}
56780 +
56781 +extern const char *captab_log[];
56782 +extern int captab_log_entries;
56783 +
56784 +int
56785 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56786 +{
56787 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56788 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56789 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56790 + if (cap_raised(chroot_caps, cap)) {
56791 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56792 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56793 + }
56794 + return 0;
56795 + }
56796 + }
56797 +#endif
56798 + return 1;
56799 +}
56800 +
56801 +int
56802 +gr_chroot_is_capable(const int cap)
56803 +{
56804 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56805 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56806 +#endif
56807 + return 1;
56808 +}
56809 +
56810 +int
56811 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56812 +{
56813 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56814 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56815 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56816 + if (cap_raised(chroot_caps, cap)) {
56817 + return 0;
56818 + }
56819 + }
56820 +#endif
56821 + return 1;
56822 +}
56823 +
56824 +int
56825 +gr_chroot_is_capable_nolog(const int cap)
56826 +{
56827 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56828 + return gr_task_chroot_is_capable_nolog(current, cap);
56829 +#endif
56830 + return 1;
56831 +}
56832 +
56833 +int
56834 +gr_handle_chroot_sysctl(const int op)
56835 +{
56836 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56837 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56838 + proc_is_chrooted(current))
56839 + return -EACCES;
56840 +#endif
56841 + return 0;
56842 +}
56843 +
56844 +void
56845 +gr_handle_chroot_chdir(struct path *path)
56846 +{
56847 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56848 + if (grsec_enable_chroot_chdir)
56849 + set_fs_pwd(current->fs, path);
56850 +#endif
56851 + return;
56852 +}
56853 +
56854 +int
56855 +gr_handle_chroot_chmod(const struct dentry *dentry,
56856 + const struct vfsmount *mnt, const int mode)
56857 +{
56858 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56859 + /* allow chmod +s on directories, but not files */
56860 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56861 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56862 + proc_is_chrooted(current)) {
56863 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56864 + return -EPERM;
56865 + }
56866 +#endif
56867 + return 0;
56868 +}
56869 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56870 new file mode 100644
56871 index 0000000..213ad8b
56872 --- /dev/null
56873 +++ b/grsecurity/grsec_disabled.c
56874 @@ -0,0 +1,437 @@
56875 +#include <linux/kernel.h>
56876 +#include <linux/module.h>
56877 +#include <linux/sched.h>
56878 +#include <linux/file.h>
56879 +#include <linux/fs.h>
56880 +#include <linux/kdev_t.h>
56881 +#include <linux/net.h>
56882 +#include <linux/in.h>
56883 +#include <linux/ip.h>
56884 +#include <linux/skbuff.h>
56885 +#include <linux/sysctl.h>
56886 +
56887 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56888 +void
56889 +pax_set_initial_flags(struct linux_binprm *bprm)
56890 +{
56891 + return;
56892 +}
56893 +#endif
56894 +
56895 +#ifdef CONFIG_SYSCTL
56896 +__u32
56897 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56898 +{
56899 + return 0;
56900 +}
56901 +#endif
56902 +
56903 +#ifdef CONFIG_TASKSTATS
56904 +int gr_is_taskstats_denied(int pid)
56905 +{
56906 + return 0;
56907 +}
56908 +#endif
56909 +
56910 +int
56911 +gr_acl_is_enabled(void)
56912 +{
56913 + return 0;
56914 +}
56915 +
56916 +void
56917 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56918 +{
56919 + return;
56920 +}
56921 +
56922 +int
56923 +gr_handle_rawio(const struct inode *inode)
56924 +{
56925 + return 0;
56926 +}
56927 +
56928 +void
56929 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56930 +{
56931 + return;
56932 +}
56933 +
56934 +int
56935 +gr_handle_ptrace(struct task_struct *task, const long request)
56936 +{
56937 + return 0;
56938 +}
56939 +
56940 +int
56941 +gr_handle_proc_ptrace(struct task_struct *task)
56942 +{
56943 + return 0;
56944 +}
56945 +
56946 +void
56947 +gr_learn_resource(const struct task_struct *task,
56948 + const int res, const unsigned long wanted, const int gt)
56949 +{
56950 + return;
56951 +}
56952 +
56953 +int
56954 +gr_set_acls(const int type)
56955 +{
56956 + return 0;
56957 +}
56958 +
56959 +int
56960 +gr_check_hidden_task(const struct task_struct *tsk)
56961 +{
56962 + return 0;
56963 +}
56964 +
56965 +int
56966 +gr_check_protected_task(const struct task_struct *task)
56967 +{
56968 + return 0;
56969 +}
56970 +
56971 +int
56972 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56973 +{
56974 + return 0;
56975 +}
56976 +
56977 +void
56978 +gr_copy_label(struct task_struct *tsk)
56979 +{
56980 + return;
56981 +}
56982 +
56983 +void
56984 +gr_set_pax_flags(struct task_struct *task)
56985 +{
56986 + return;
56987 +}
56988 +
56989 +int
56990 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56991 + const int unsafe_share)
56992 +{
56993 + return 0;
56994 +}
56995 +
56996 +void
56997 +gr_handle_delete(const ino_t ino, const dev_t dev)
56998 +{
56999 + return;
57000 +}
57001 +
57002 +void
57003 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57004 +{
57005 + return;
57006 +}
57007 +
57008 +void
57009 +gr_handle_crash(struct task_struct *task, const int sig)
57010 +{
57011 + return;
57012 +}
57013 +
57014 +int
57015 +gr_check_crash_exec(const struct file *filp)
57016 +{
57017 + return 0;
57018 +}
57019 +
57020 +int
57021 +gr_check_crash_uid(const uid_t uid)
57022 +{
57023 + return 0;
57024 +}
57025 +
57026 +void
57027 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57028 + struct dentry *old_dentry,
57029 + struct dentry *new_dentry,
57030 + struct vfsmount *mnt, const __u8 replace)
57031 +{
57032 + return;
57033 +}
57034 +
57035 +int
57036 +gr_search_socket(const int family, const int type, const int protocol)
57037 +{
57038 + return 1;
57039 +}
57040 +
57041 +int
57042 +gr_search_connectbind(const int mode, const struct socket *sock,
57043 + const struct sockaddr_in *addr)
57044 +{
57045 + return 0;
57046 +}
57047 +
57048 +void
57049 +gr_handle_alertkill(struct task_struct *task)
57050 +{
57051 + return;
57052 +}
57053 +
57054 +__u32
57055 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57056 +{
57057 + return 1;
57058 +}
57059 +
57060 +__u32
57061 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57062 + const struct vfsmount * mnt)
57063 +{
57064 + return 1;
57065 +}
57066 +
57067 +__u32
57068 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57069 + int acc_mode)
57070 +{
57071 + return 1;
57072 +}
57073 +
57074 +__u32
57075 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57076 +{
57077 + return 1;
57078 +}
57079 +
57080 +__u32
57081 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57082 +{
57083 + return 1;
57084 +}
57085 +
57086 +int
57087 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57088 + unsigned int *vm_flags)
57089 +{
57090 + return 1;
57091 +}
57092 +
57093 +__u32
57094 +gr_acl_handle_truncate(const struct dentry * dentry,
57095 + const struct vfsmount * mnt)
57096 +{
57097 + return 1;
57098 +}
57099 +
57100 +__u32
57101 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57102 +{
57103 + return 1;
57104 +}
57105 +
57106 +__u32
57107 +gr_acl_handle_access(const struct dentry * dentry,
57108 + const struct vfsmount * mnt, const int fmode)
57109 +{
57110 + return 1;
57111 +}
57112 +
57113 +__u32
57114 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57115 + umode_t *mode)
57116 +{
57117 + return 1;
57118 +}
57119 +
57120 +__u32
57121 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57122 +{
57123 + return 1;
57124 +}
57125 +
57126 +__u32
57127 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57128 +{
57129 + return 1;
57130 +}
57131 +
57132 +void
57133 +grsecurity_init(void)
57134 +{
57135 + return;
57136 +}
57137 +
57138 +umode_t gr_acl_umask(void)
57139 +{
57140 + return 0;
57141 +}
57142 +
57143 +__u32
57144 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57145 + const struct dentry * parent_dentry,
57146 + const struct vfsmount * parent_mnt,
57147 + const int mode)
57148 +{
57149 + return 1;
57150 +}
57151 +
57152 +__u32
57153 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57154 + const struct dentry * parent_dentry,
57155 + const struct vfsmount * parent_mnt)
57156 +{
57157 + return 1;
57158 +}
57159 +
57160 +__u32
57161 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57162 + const struct dentry * parent_dentry,
57163 + const struct vfsmount * parent_mnt, const char *from)
57164 +{
57165 + return 1;
57166 +}
57167 +
57168 +__u32
57169 +gr_acl_handle_link(const struct dentry * new_dentry,
57170 + const struct dentry * parent_dentry,
57171 + const struct vfsmount * parent_mnt,
57172 + const struct dentry * old_dentry,
57173 + const struct vfsmount * old_mnt, const char *to)
57174 +{
57175 + return 1;
57176 +}
57177 +
57178 +int
57179 +gr_acl_handle_rename(const struct dentry *new_dentry,
57180 + const struct dentry *parent_dentry,
57181 + const struct vfsmount *parent_mnt,
57182 + const struct dentry *old_dentry,
57183 + const struct inode *old_parent_inode,
57184 + const struct vfsmount *old_mnt, const char *newname)
57185 +{
57186 + return 0;
57187 +}
57188 +
57189 +int
57190 +gr_acl_handle_filldir(const struct file *file, const char *name,
57191 + const int namelen, const ino_t ino)
57192 +{
57193 + return 1;
57194 +}
57195 +
57196 +int
57197 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57198 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57199 +{
57200 + return 1;
57201 +}
57202 +
57203 +int
57204 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57205 +{
57206 + return 0;
57207 +}
57208 +
57209 +int
57210 +gr_search_accept(const struct socket *sock)
57211 +{
57212 + return 0;
57213 +}
57214 +
57215 +int
57216 +gr_search_listen(const struct socket *sock)
57217 +{
57218 + return 0;
57219 +}
57220 +
57221 +int
57222 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57223 +{
57224 + return 0;
57225 +}
57226 +
57227 +__u32
57228 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57229 +{
57230 + return 1;
57231 +}
57232 +
57233 +__u32
57234 +gr_acl_handle_creat(const struct dentry * dentry,
57235 + const struct dentry * p_dentry,
57236 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57237 + const int imode)
57238 +{
57239 + return 1;
57240 +}
57241 +
57242 +void
57243 +gr_acl_handle_exit(void)
57244 +{
57245 + return;
57246 +}
57247 +
57248 +int
57249 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57250 +{
57251 + return 1;
57252 +}
57253 +
57254 +void
57255 +gr_set_role_label(const uid_t uid, const gid_t gid)
57256 +{
57257 + return;
57258 +}
57259 +
57260 +int
57261 +gr_acl_handle_procpidmem(const struct task_struct *task)
57262 +{
57263 + return 0;
57264 +}
57265 +
57266 +int
57267 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57268 +{
57269 + return 0;
57270 +}
57271 +
57272 +int
57273 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57274 +{
57275 + return 0;
57276 +}
57277 +
57278 +void
57279 +gr_set_kernel_label(struct task_struct *task)
57280 +{
57281 + return;
57282 +}
57283 +
57284 +int
57285 +gr_check_user_change(int real, int effective, int fs)
57286 +{
57287 + return 0;
57288 +}
57289 +
57290 +int
57291 +gr_check_group_change(int real, int effective, int fs)
57292 +{
57293 + return 0;
57294 +}
57295 +
57296 +int gr_acl_enable_at_secure(void)
57297 +{
57298 + return 0;
57299 +}
57300 +
57301 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57302 +{
57303 + return dentry->d_inode->i_sb->s_dev;
57304 +}
57305 +
57306 +EXPORT_SYMBOL(gr_learn_resource);
57307 +EXPORT_SYMBOL(gr_set_kernel_label);
57308 +#ifdef CONFIG_SECURITY
57309 +EXPORT_SYMBOL(gr_check_user_change);
57310 +EXPORT_SYMBOL(gr_check_group_change);
57311 +#endif
57312 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57313 new file mode 100644
57314 index 0000000..abfa971
57315 --- /dev/null
57316 +++ b/grsecurity/grsec_exec.c
57317 @@ -0,0 +1,174 @@
57318 +#include <linux/kernel.h>
57319 +#include <linux/sched.h>
57320 +#include <linux/file.h>
57321 +#include <linux/binfmts.h>
57322 +#include <linux/fs.h>
57323 +#include <linux/types.h>
57324 +#include <linux/grdefs.h>
57325 +#include <linux/grsecurity.h>
57326 +#include <linux/grinternal.h>
57327 +#include <linux/capability.h>
57328 +#include <linux/module.h>
57329 +
57330 +#include <asm/uaccess.h>
57331 +
57332 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57333 +static char gr_exec_arg_buf[132];
57334 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57335 +#endif
57336 +
57337 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57338 +
57339 +void
57340 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57341 +{
57342 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57343 + char *grarg = gr_exec_arg_buf;
57344 + unsigned int i, x, execlen = 0;
57345 + char c;
57346 +
57347 + if (!((grsec_enable_execlog && grsec_enable_group &&
57348 + in_group_p(grsec_audit_gid))
57349 + || (grsec_enable_execlog && !grsec_enable_group)))
57350 + return;
57351 +
57352 + mutex_lock(&gr_exec_arg_mutex);
57353 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57354 +
57355 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57356 + const char __user *p;
57357 + unsigned int len;
57358 +
57359 + p = get_user_arg_ptr(argv, i);
57360 + if (IS_ERR(p))
57361 + goto log;
57362 +
57363 + len = strnlen_user(p, 128 - execlen);
57364 + if (len > 128 - execlen)
57365 + len = 128 - execlen;
57366 + else if (len > 0)
57367 + len--;
57368 + if (copy_from_user(grarg + execlen, p, len))
57369 + goto log;
57370 +
57371 + /* rewrite unprintable characters */
57372 + for (x = 0; x < len; x++) {
57373 + c = *(grarg + execlen + x);
57374 + if (c < 32 || c > 126)
57375 + *(grarg + execlen + x) = ' ';
57376 + }
57377 +
57378 + execlen += len;
57379 + *(grarg + execlen) = ' ';
57380 + *(grarg + execlen + 1) = '\0';
57381 + execlen++;
57382 + }
57383 +
57384 + log:
57385 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57386 + bprm->file->f_path.mnt, grarg);
57387 + mutex_unlock(&gr_exec_arg_mutex);
57388 +#endif
57389 + return;
57390 +}
57391 +
57392 +#ifdef CONFIG_GRKERNSEC
57393 +extern int gr_acl_is_capable(const int cap);
57394 +extern int gr_acl_is_capable_nolog(const int cap);
57395 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57396 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57397 +extern int gr_chroot_is_capable(const int cap);
57398 +extern int gr_chroot_is_capable_nolog(const int cap);
57399 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57400 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57401 +#endif
57402 +
57403 +const char *captab_log[] = {
57404 + "CAP_CHOWN",
57405 + "CAP_DAC_OVERRIDE",
57406 + "CAP_DAC_READ_SEARCH",
57407 + "CAP_FOWNER",
57408 + "CAP_FSETID",
57409 + "CAP_KILL",
57410 + "CAP_SETGID",
57411 + "CAP_SETUID",
57412 + "CAP_SETPCAP",
57413 + "CAP_LINUX_IMMUTABLE",
57414 + "CAP_NET_BIND_SERVICE",
57415 + "CAP_NET_BROADCAST",
57416 + "CAP_NET_ADMIN",
57417 + "CAP_NET_RAW",
57418 + "CAP_IPC_LOCK",
57419 + "CAP_IPC_OWNER",
57420 + "CAP_SYS_MODULE",
57421 + "CAP_SYS_RAWIO",
57422 + "CAP_SYS_CHROOT",
57423 + "CAP_SYS_PTRACE",
57424 + "CAP_SYS_PACCT",
57425 + "CAP_SYS_ADMIN",
57426 + "CAP_SYS_BOOT",
57427 + "CAP_SYS_NICE",
57428 + "CAP_SYS_RESOURCE",
57429 + "CAP_SYS_TIME",
57430 + "CAP_SYS_TTY_CONFIG",
57431 + "CAP_MKNOD",
57432 + "CAP_LEASE",
57433 + "CAP_AUDIT_WRITE",
57434 + "CAP_AUDIT_CONTROL",
57435 + "CAP_SETFCAP",
57436 + "CAP_MAC_OVERRIDE",
57437 + "CAP_MAC_ADMIN",
57438 + "CAP_SYSLOG",
57439 + "CAP_WAKE_ALARM"
57440 +};
57441 +
57442 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57443 +
57444 +int gr_is_capable(const int cap)
57445 +{
57446 +#ifdef CONFIG_GRKERNSEC
57447 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57448 + return 1;
57449 + return 0;
57450 +#else
57451 + return 1;
57452 +#endif
57453 +}
57454 +
57455 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57456 +{
57457 +#ifdef CONFIG_GRKERNSEC
57458 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57459 + return 1;
57460 + return 0;
57461 +#else
57462 + return 1;
57463 +#endif
57464 +}
57465 +
57466 +int gr_is_capable_nolog(const int cap)
57467 +{
57468 +#ifdef CONFIG_GRKERNSEC
57469 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57470 + return 1;
57471 + return 0;
57472 +#else
57473 + return 1;
57474 +#endif
57475 +}
57476 +
57477 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57478 +{
57479 +#ifdef CONFIG_GRKERNSEC
57480 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57481 + return 1;
57482 + return 0;
57483 +#else
57484 + return 1;
57485 +#endif
57486 +}
57487 +
57488 +EXPORT_SYMBOL(gr_is_capable);
57489 +EXPORT_SYMBOL(gr_is_capable_nolog);
57490 +EXPORT_SYMBOL(gr_task_is_capable);
57491 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57492 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57493 new file mode 100644
57494 index 0000000..d3ee748
57495 --- /dev/null
57496 +++ b/grsecurity/grsec_fifo.c
57497 @@ -0,0 +1,24 @@
57498 +#include <linux/kernel.h>
57499 +#include <linux/sched.h>
57500 +#include <linux/fs.h>
57501 +#include <linux/file.h>
57502 +#include <linux/grinternal.h>
57503 +
57504 +int
57505 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57506 + const struct dentry *dir, const int flag, const int acc_mode)
57507 +{
57508 +#ifdef CONFIG_GRKERNSEC_FIFO
57509 + const struct cred *cred = current_cred();
57510 +
57511 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57512 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57513 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57514 + (cred->fsuid != dentry->d_inode->i_uid)) {
57515 + if (!inode_permission(dentry->d_inode, acc_mode))
57516 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57517 + return -EACCES;
57518 + }
57519 +#endif
57520 + return 0;
57521 +}
57522 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57523 new file mode 100644
57524 index 0000000..8ca18bf
57525 --- /dev/null
57526 +++ b/grsecurity/grsec_fork.c
57527 @@ -0,0 +1,23 @@
57528 +#include <linux/kernel.h>
57529 +#include <linux/sched.h>
57530 +#include <linux/grsecurity.h>
57531 +#include <linux/grinternal.h>
57532 +#include <linux/errno.h>
57533 +
57534 +void
57535 +gr_log_forkfail(const int retval)
57536 +{
57537 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57538 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57539 + switch (retval) {
57540 + case -EAGAIN:
57541 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57542 + break;
57543 + case -ENOMEM:
57544 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57545 + break;
57546 + }
57547 + }
57548 +#endif
57549 + return;
57550 +}
57551 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57552 new file mode 100644
57553 index 0000000..01ddde4
57554 --- /dev/null
57555 +++ b/grsecurity/grsec_init.c
57556 @@ -0,0 +1,277 @@
57557 +#include <linux/kernel.h>
57558 +#include <linux/sched.h>
57559 +#include <linux/mm.h>
57560 +#include <linux/gracl.h>
57561 +#include <linux/slab.h>
57562 +#include <linux/vmalloc.h>
57563 +#include <linux/percpu.h>
57564 +#include <linux/module.h>
57565 +
57566 +int grsec_enable_ptrace_readexec;
57567 +int grsec_enable_setxid;
57568 +int grsec_enable_brute;
57569 +int grsec_enable_link;
57570 +int grsec_enable_dmesg;
57571 +int grsec_enable_harden_ptrace;
57572 +int grsec_enable_fifo;
57573 +int grsec_enable_execlog;
57574 +int grsec_enable_signal;
57575 +int grsec_enable_forkfail;
57576 +int grsec_enable_audit_ptrace;
57577 +int grsec_enable_time;
57578 +int grsec_enable_audit_textrel;
57579 +int grsec_enable_group;
57580 +int grsec_audit_gid;
57581 +int grsec_enable_chdir;
57582 +int grsec_enable_mount;
57583 +int grsec_enable_rofs;
57584 +int grsec_enable_chroot_findtask;
57585 +int grsec_enable_chroot_mount;
57586 +int grsec_enable_chroot_shmat;
57587 +int grsec_enable_chroot_fchdir;
57588 +int grsec_enable_chroot_double;
57589 +int grsec_enable_chroot_pivot;
57590 +int grsec_enable_chroot_chdir;
57591 +int grsec_enable_chroot_chmod;
57592 +int grsec_enable_chroot_mknod;
57593 +int grsec_enable_chroot_nice;
57594 +int grsec_enable_chroot_execlog;
57595 +int grsec_enable_chroot_caps;
57596 +int grsec_enable_chroot_sysctl;
57597 +int grsec_enable_chroot_unix;
57598 +int grsec_enable_tpe;
57599 +int grsec_tpe_gid;
57600 +int grsec_enable_blackhole;
57601 +#ifdef CONFIG_IPV6_MODULE
57602 +EXPORT_SYMBOL(grsec_enable_blackhole);
57603 +#endif
57604 +int grsec_lastack_retries;
57605 +int grsec_enable_tpe_all;
57606 +int grsec_enable_tpe_invert;
57607 +int grsec_enable_socket_all;
57608 +int grsec_socket_all_gid;
57609 +int grsec_enable_socket_client;
57610 +int grsec_socket_client_gid;
57611 +int grsec_enable_socket_server;
57612 +int grsec_socket_server_gid;
57613 +int grsec_resource_logging;
57614 +int grsec_disable_privio;
57615 +int grsec_enable_log_rwxmaps;
57616 +int grsec_lock;
57617 +
57618 +DEFINE_SPINLOCK(grsec_alert_lock);
57619 +unsigned long grsec_alert_wtime = 0;
57620 +unsigned long grsec_alert_fyet = 0;
57621 +
57622 +DEFINE_SPINLOCK(grsec_audit_lock);
57623 +
57624 +DEFINE_RWLOCK(grsec_exec_file_lock);
57625 +
57626 +char *gr_shared_page[4];
57627 +
57628 +char *gr_alert_log_fmt;
57629 +char *gr_audit_log_fmt;
57630 +char *gr_alert_log_buf;
57631 +char *gr_audit_log_buf;
57632 +
57633 +extern struct gr_arg *gr_usermode;
57634 +extern unsigned char *gr_system_salt;
57635 +extern unsigned char *gr_system_sum;
57636 +
57637 +void __init
57638 +grsecurity_init(void)
57639 +{
57640 + int j;
57641 + /* create the per-cpu shared pages */
57642 +
57643 +#ifdef CONFIG_X86
57644 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57645 +#endif
57646 +
57647 + for (j = 0; j < 4; j++) {
57648 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57649 + if (gr_shared_page[j] == NULL) {
57650 + panic("Unable to allocate grsecurity shared page");
57651 + return;
57652 + }
57653 + }
57654 +
57655 + /* allocate log buffers */
57656 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57657 + if (!gr_alert_log_fmt) {
57658 + panic("Unable to allocate grsecurity alert log format buffer");
57659 + return;
57660 + }
57661 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57662 + if (!gr_audit_log_fmt) {
57663 + panic("Unable to allocate grsecurity audit log format buffer");
57664 + return;
57665 + }
57666 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57667 + if (!gr_alert_log_buf) {
57668 + panic("Unable to allocate grsecurity alert log buffer");
57669 + return;
57670 + }
57671 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57672 + if (!gr_audit_log_buf) {
57673 + panic("Unable to allocate grsecurity audit log buffer");
57674 + return;
57675 + }
57676 +
57677 + /* allocate memory for authentication structure */
57678 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57679 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57680 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57681 +
57682 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57683 + panic("Unable to allocate grsecurity authentication structure");
57684 + return;
57685 + }
57686 +
57687 +
57688 +#ifdef CONFIG_GRKERNSEC_IO
57689 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57690 + grsec_disable_privio = 1;
57691 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57692 + grsec_disable_privio = 1;
57693 +#else
57694 + grsec_disable_privio = 0;
57695 +#endif
57696 +#endif
57697 +
57698 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57699 + /* for backward compatibility, tpe_invert always defaults to on if
57700 + enabled in the kernel
57701 + */
57702 + grsec_enable_tpe_invert = 1;
57703 +#endif
57704 +
57705 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57706 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57707 + grsec_lock = 1;
57708 +#endif
57709 +
57710 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57711 + grsec_enable_audit_textrel = 1;
57712 +#endif
57713 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57714 + grsec_enable_log_rwxmaps = 1;
57715 +#endif
57716 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57717 + grsec_enable_group = 1;
57718 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57719 +#endif
57720 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57721 + grsec_enable_ptrace_readexec = 1;
57722 +#endif
57723 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57724 + grsec_enable_chdir = 1;
57725 +#endif
57726 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57727 + grsec_enable_harden_ptrace = 1;
57728 +#endif
57729 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57730 + grsec_enable_mount = 1;
57731 +#endif
57732 +#ifdef CONFIG_GRKERNSEC_LINK
57733 + grsec_enable_link = 1;
57734 +#endif
57735 +#ifdef CONFIG_GRKERNSEC_BRUTE
57736 + grsec_enable_brute = 1;
57737 +#endif
57738 +#ifdef CONFIG_GRKERNSEC_DMESG
57739 + grsec_enable_dmesg = 1;
57740 +#endif
57741 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57742 + grsec_enable_blackhole = 1;
57743 + grsec_lastack_retries = 4;
57744 +#endif
57745 +#ifdef CONFIG_GRKERNSEC_FIFO
57746 + grsec_enable_fifo = 1;
57747 +#endif
57748 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57749 + grsec_enable_execlog = 1;
57750 +#endif
57751 +#ifdef CONFIG_GRKERNSEC_SETXID
57752 + grsec_enable_setxid = 1;
57753 +#endif
57754 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57755 + grsec_enable_signal = 1;
57756 +#endif
57757 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57758 + grsec_enable_forkfail = 1;
57759 +#endif
57760 +#ifdef CONFIG_GRKERNSEC_TIME
57761 + grsec_enable_time = 1;
57762 +#endif
57763 +#ifdef CONFIG_GRKERNSEC_RESLOG
57764 + grsec_resource_logging = 1;
57765 +#endif
57766 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57767 + grsec_enable_chroot_findtask = 1;
57768 +#endif
57769 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57770 + grsec_enable_chroot_unix = 1;
57771 +#endif
57772 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57773 + grsec_enable_chroot_mount = 1;
57774 +#endif
57775 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57776 + grsec_enable_chroot_fchdir = 1;
57777 +#endif
57778 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57779 + grsec_enable_chroot_shmat = 1;
57780 +#endif
57781 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57782 + grsec_enable_audit_ptrace = 1;
57783 +#endif
57784 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57785 + grsec_enable_chroot_double = 1;
57786 +#endif
57787 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57788 + grsec_enable_chroot_pivot = 1;
57789 +#endif
57790 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57791 + grsec_enable_chroot_chdir = 1;
57792 +#endif
57793 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57794 + grsec_enable_chroot_chmod = 1;
57795 +#endif
57796 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57797 + grsec_enable_chroot_mknod = 1;
57798 +#endif
57799 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57800 + grsec_enable_chroot_nice = 1;
57801 +#endif
57802 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57803 + grsec_enable_chroot_execlog = 1;
57804 +#endif
57805 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57806 + grsec_enable_chroot_caps = 1;
57807 +#endif
57808 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57809 + grsec_enable_chroot_sysctl = 1;
57810 +#endif
57811 +#ifdef CONFIG_GRKERNSEC_TPE
57812 + grsec_enable_tpe = 1;
57813 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57814 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57815 + grsec_enable_tpe_all = 1;
57816 +#endif
57817 +#endif
57818 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57819 + grsec_enable_socket_all = 1;
57820 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57821 +#endif
57822 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57823 + grsec_enable_socket_client = 1;
57824 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57825 +#endif
57826 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57827 + grsec_enable_socket_server = 1;
57828 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57829 +#endif
57830 +#endif
57831 +
57832 + return;
57833 +}
57834 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57835 new file mode 100644
57836 index 0000000..3efe141
57837 --- /dev/null
57838 +++ b/grsecurity/grsec_link.c
57839 @@ -0,0 +1,43 @@
57840 +#include <linux/kernel.h>
57841 +#include <linux/sched.h>
57842 +#include <linux/fs.h>
57843 +#include <linux/file.h>
57844 +#include <linux/grinternal.h>
57845 +
57846 +int
57847 +gr_handle_follow_link(const struct inode *parent,
57848 + const struct inode *inode,
57849 + const struct dentry *dentry, const struct vfsmount *mnt)
57850 +{
57851 +#ifdef CONFIG_GRKERNSEC_LINK
57852 + const struct cred *cred = current_cred();
57853 +
57854 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57855 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57856 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57857 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57858 + return -EACCES;
57859 + }
57860 +#endif
57861 + return 0;
57862 +}
57863 +
57864 +int
57865 +gr_handle_hardlink(const struct dentry *dentry,
57866 + const struct vfsmount *mnt,
57867 + struct inode *inode, const int mode, const char *to)
57868 +{
57869 +#ifdef CONFIG_GRKERNSEC_LINK
57870 + const struct cred *cred = current_cred();
57871 +
57872 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57873 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57874 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57875 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57876 + !capable(CAP_FOWNER) && cred->uid) {
57877 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57878 + return -EPERM;
57879 + }
57880 +#endif
57881 + return 0;
57882 +}
57883 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57884 new file mode 100644
57885 index 0000000..a45d2e9
57886 --- /dev/null
57887 +++ b/grsecurity/grsec_log.c
57888 @@ -0,0 +1,322 @@
57889 +#include <linux/kernel.h>
57890 +#include <linux/sched.h>
57891 +#include <linux/file.h>
57892 +#include <linux/tty.h>
57893 +#include <linux/fs.h>
57894 +#include <linux/grinternal.h>
57895 +
57896 +#ifdef CONFIG_TREE_PREEMPT_RCU
57897 +#define DISABLE_PREEMPT() preempt_disable()
57898 +#define ENABLE_PREEMPT() preempt_enable()
57899 +#else
57900 +#define DISABLE_PREEMPT()
57901 +#define ENABLE_PREEMPT()
57902 +#endif
57903 +
57904 +#define BEGIN_LOCKS(x) \
57905 + DISABLE_PREEMPT(); \
57906 + rcu_read_lock(); \
57907 + read_lock(&tasklist_lock); \
57908 + read_lock(&grsec_exec_file_lock); \
57909 + if (x != GR_DO_AUDIT) \
57910 + spin_lock(&grsec_alert_lock); \
57911 + else \
57912 + spin_lock(&grsec_audit_lock)
57913 +
57914 +#define END_LOCKS(x) \
57915 + if (x != GR_DO_AUDIT) \
57916 + spin_unlock(&grsec_alert_lock); \
57917 + else \
57918 + spin_unlock(&grsec_audit_lock); \
57919 + read_unlock(&grsec_exec_file_lock); \
57920 + read_unlock(&tasklist_lock); \
57921 + rcu_read_unlock(); \
57922 + ENABLE_PREEMPT(); \
57923 + if (x == GR_DONT_AUDIT) \
57924 + gr_handle_alertkill(current)
57925 +
57926 +enum {
57927 + FLOODING,
57928 + NO_FLOODING
57929 +};
57930 +
57931 +extern char *gr_alert_log_fmt;
57932 +extern char *gr_audit_log_fmt;
57933 +extern char *gr_alert_log_buf;
57934 +extern char *gr_audit_log_buf;
57935 +
57936 +static int gr_log_start(int audit)
57937 +{
57938 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57939 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57940 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57941 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57942 + unsigned long curr_secs = get_seconds();
57943 +
57944 + if (audit == GR_DO_AUDIT)
57945 + goto set_fmt;
57946 +
57947 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57948 + grsec_alert_wtime = curr_secs;
57949 + grsec_alert_fyet = 0;
57950 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57951 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57952 + grsec_alert_fyet++;
57953 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57954 + grsec_alert_wtime = curr_secs;
57955 + grsec_alert_fyet++;
57956 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57957 + return FLOODING;
57958 + }
57959 + else return FLOODING;
57960 +
57961 +set_fmt:
57962 +#endif
57963 + memset(buf, 0, PAGE_SIZE);
57964 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57965 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57966 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57967 + } else if (current->signal->curr_ip) {
57968 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57969 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57970 + } else if (gr_acl_is_enabled()) {
57971 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57972 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57973 + } else {
57974 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57975 + strcpy(buf, fmt);
57976 + }
57977 +
57978 + return NO_FLOODING;
57979 +}
57980 +
57981 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57982 + __attribute__ ((format (printf, 2, 0)));
57983 +
57984 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57985 +{
57986 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57987 + unsigned int len = strlen(buf);
57988 +
57989 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57990 +
57991 + return;
57992 +}
57993 +
57994 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57995 + __attribute__ ((format (printf, 2, 3)));
57996 +
57997 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57998 +{
57999 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58000 + unsigned int len = strlen(buf);
58001 + va_list ap;
58002 +
58003 + va_start(ap, msg);
58004 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58005 + va_end(ap);
58006 +
58007 + return;
58008 +}
58009 +
58010 +static void gr_log_end(int audit, int append_default)
58011 +{
58012 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58013 +
58014 + if (append_default) {
58015 + unsigned int len = strlen(buf);
58016 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58017 + }
58018 +
58019 + printk("%s\n", buf);
58020 +
58021 + return;
58022 +}
58023 +
58024 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58025 +{
58026 + int logtype;
58027 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58028 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58029 + void *voidptr = NULL;
58030 + int num1 = 0, num2 = 0;
58031 + unsigned long ulong1 = 0, ulong2 = 0;
58032 + struct dentry *dentry = NULL;
58033 + struct vfsmount *mnt = NULL;
58034 + struct file *file = NULL;
58035 + struct task_struct *task = NULL;
58036 + const struct cred *cred, *pcred;
58037 + va_list ap;
58038 +
58039 + BEGIN_LOCKS(audit);
58040 + logtype = gr_log_start(audit);
58041 + if (logtype == FLOODING) {
58042 + END_LOCKS(audit);
58043 + return;
58044 + }
58045 + va_start(ap, argtypes);
58046 + switch (argtypes) {
58047 + case GR_TTYSNIFF:
58048 + task = va_arg(ap, struct task_struct *);
58049 + 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);
58050 + break;
58051 + case GR_SYSCTL_HIDDEN:
58052 + str1 = va_arg(ap, char *);
58053 + gr_log_middle_varargs(audit, msg, result, str1);
58054 + break;
58055 + case GR_RBAC:
58056 + dentry = va_arg(ap, struct dentry *);
58057 + mnt = va_arg(ap, struct vfsmount *);
58058 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58059 + break;
58060 + case GR_RBAC_STR:
58061 + dentry = va_arg(ap, struct dentry *);
58062 + mnt = va_arg(ap, struct vfsmount *);
58063 + str1 = va_arg(ap, char *);
58064 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58065 + break;
58066 + case GR_STR_RBAC:
58067 + str1 = va_arg(ap, char *);
58068 + dentry = va_arg(ap, struct dentry *);
58069 + mnt = va_arg(ap, struct vfsmount *);
58070 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58071 + break;
58072 + case GR_RBAC_MODE2:
58073 + dentry = va_arg(ap, struct dentry *);
58074 + mnt = va_arg(ap, struct vfsmount *);
58075 + str1 = va_arg(ap, char *);
58076 + str2 = va_arg(ap, char *);
58077 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58078 + break;
58079 + case GR_RBAC_MODE3:
58080 + dentry = va_arg(ap, struct dentry *);
58081 + mnt = va_arg(ap, struct vfsmount *);
58082 + str1 = va_arg(ap, char *);
58083 + str2 = va_arg(ap, char *);
58084 + str3 = va_arg(ap, char *);
58085 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58086 + break;
58087 + case GR_FILENAME:
58088 + dentry = va_arg(ap, struct dentry *);
58089 + mnt = va_arg(ap, struct vfsmount *);
58090 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58091 + break;
58092 + case GR_STR_FILENAME:
58093 + str1 = va_arg(ap, char *);
58094 + dentry = va_arg(ap, struct dentry *);
58095 + mnt = va_arg(ap, struct vfsmount *);
58096 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58097 + break;
58098 + case GR_FILENAME_STR:
58099 + dentry = va_arg(ap, struct dentry *);
58100 + mnt = va_arg(ap, struct vfsmount *);
58101 + str1 = va_arg(ap, char *);
58102 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58103 + break;
58104 + case GR_FILENAME_TWO_INT:
58105 + dentry = va_arg(ap, struct dentry *);
58106 + mnt = va_arg(ap, struct vfsmount *);
58107 + num1 = va_arg(ap, int);
58108 + num2 = va_arg(ap, int);
58109 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58110 + break;
58111 + case GR_FILENAME_TWO_INT_STR:
58112 + dentry = va_arg(ap, struct dentry *);
58113 + mnt = va_arg(ap, struct vfsmount *);
58114 + num1 = va_arg(ap, int);
58115 + num2 = va_arg(ap, int);
58116 + str1 = va_arg(ap, char *);
58117 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58118 + break;
58119 + case GR_TEXTREL:
58120 + file = va_arg(ap, struct file *);
58121 + ulong1 = va_arg(ap, unsigned long);
58122 + ulong2 = va_arg(ap, unsigned long);
58123 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58124 + break;
58125 + case GR_PTRACE:
58126 + task = va_arg(ap, struct task_struct *);
58127 + 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);
58128 + break;
58129 + case GR_RESOURCE:
58130 + task = va_arg(ap, struct task_struct *);
58131 + cred = __task_cred(task);
58132 + pcred = __task_cred(task->real_parent);
58133 + ulong1 = va_arg(ap, unsigned long);
58134 + str1 = va_arg(ap, char *);
58135 + ulong2 = va_arg(ap, unsigned long);
58136 + 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);
58137 + break;
58138 + case GR_CAP:
58139 + task = va_arg(ap, struct task_struct *);
58140 + cred = __task_cred(task);
58141 + pcred = __task_cred(task->real_parent);
58142 + str1 = va_arg(ap, char *);
58143 + 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);
58144 + break;
58145 + case GR_SIG:
58146 + str1 = va_arg(ap, char *);
58147 + voidptr = va_arg(ap, void *);
58148 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58149 + break;
58150 + case GR_SIG2:
58151 + task = va_arg(ap, struct task_struct *);
58152 + cred = __task_cred(task);
58153 + pcred = __task_cred(task->real_parent);
58154 + num1 = va_arg(ap, int);
58155 + 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);
58156 + break;
58157 + case GR_CRASH1:
58158 + task = va_arg(ap, struct task_struct *);
58159 + cred = __task_cred(task);
58160 + pcred = __task_cred(task->real_parent);
58161 + ulong1 = va_arg(ap, unsigned long);
58162 + 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);
58163 + break;
58164 + case GR_CRASH2:
58165 + task = va_arg(ap, struct task_struct *);
58166 + cred = __task_cred(task);
58167 + pcred = __task_cred(task->real_parent);
58168 + ulong1 = va_arg(ap, unsigned long);
58169 + 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);
58170 + break;
58171 + case GR_RWXMAP:
58172 + file = va_arg(ap, struct file *);
58173 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58174 + break;
58175 + case GR_PSACCT:
58176 + {
58177 + unsigned int wday, cday;
58178 + __u8 whr, chr;
58179 + __u8 wmin, cmin;
58180 + __u8 wsec, csec;
58181 + char cur_tty[64] = { 0 };
58182 + char parent_tty[64] = { 0 };
58183 +
58184 + task = va_arg(ap, struct task_struct *);
58185 + wday = va_arg(ap, unsigned int);
58186 + cday = va_arg(ap, unsigned int);
58187 + whr = va_arg(ap, int);
58188 + chr = va_arg(ap, int);
58189 + wmin = va_arg(ap, int);
58190 + cmin = va_arg(ap, int);
58191 + wsec = va_arg(ap, int);
58192 + csec = va_arg(ap, int);
58193 + ulong1 = va_arg(ap, unsigned long);
58194 + cred = __task_cred(task);
58195 + pcred = __task_cred(task->real_parent);
58196 +
58197 + 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);
58198 + }
58199 + break;
58200 + default:
58201 + gr_log_middle(audit, msg, ap);
58202 + }
58203 + va_end(ap);
58204 + // these don't need DEFAULTSECARGS printed on the end
58205 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58206 + gr_log_end(audit, 0);
58207 + else
58208 + gr_log_end(audit, 1);
58209 + END_LOCKS(audit);
58210 +}
58211 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58212 new file mode 100644
58213 index 0000000..f536303
58214 --- /dev/null
58215 +++ b/grsecurity/grsec_mem.c
58216 @@ -0,0 +1,40 @@
58217 +#include <linux/kernel.h>
58218 +#include <linux/sched.h>
58219 +#include <linux/mm.h>
58220 +#include <linux/mman.h>
58221 +#include <linux/grinternal.h>
58222 +
58223 +void
58224 +gr_handle_ioperm(void)
58225 +{
58226 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58227 + return;
58228 +}
58229 +
58230 +void
58231 +gr_handle_iopl(void)
58232 +{
58233 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58234 + return;
58235 +}
58236 +
58237 +void
58238 +gr_handle_mem_readwrite(u64 from, u64 to)
58239 +{
58240 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58241 + return;
58242 +}
58243 +
58244 +void
58245 +gr_handle_vm86(void)
58246 +{
58247 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58248 + return;
58249 +}
58250 +
58251 +void
58252 +gr_log_badprocpid(const char *entry)
58253 +{
58254 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58255 + return;
58256 +}
58257 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58258 new file mode 100644
58259 index 0000000..2131422
58260 --- /dev/null
58261 +++ b/grsecurity/grsec_mount.c
58262 @@ -0,0 +1,62 @@
58263 +#include <linux/kernel.h>
58264 +#include <linux/sched.h>
58265 +#include <linux/mount.h>
58266 +#include <linux/grsecurity.h>
58267 +#include <linux/grinternal.h>
58268 +
58269 +void
58270 +gr_log_remount(const char *devname, const int retval)
58271 +{
58272 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58273 + if (grsec_enable_mount && (retval >= 0))
58274 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58275 +#endif
58276 + return;
58277 +}
58278 +
58279 +void
58280 +gr_log_unmount(const char *devname, const int retval)
58281 +{
58282 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58283 + if (grsec_enable_mount && (retval >= 0))
58284 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58285 +#endif
58286 + return;
58287 +}
58288 +
58289 +void
58290 +gr_log_mount(const char *from, const char *to, const int retval)
58291 +{
58292 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58293 + if (grsec_enable_mount && (retval >= 0))
58294 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58295 +#endif
58296 + return;
58297 +}
58298 +
58299 +int
58300 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58301 +{
58302 +#ifdef CONFIG_GRKERNSEC_ROFS
58303 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58304 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58305 + return -EPERM;
58306 + } else
58307 + return 0;
58308 +#endif
58309 + return 0;
58310 +}
58311 +
58312 +int
58313 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58314 +{
58315 +#ifdef CONFIG_GRKERNSEC_ROFS
58316 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58317 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58318 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58319 + return -EPERM;
58320 + } else
58321 + return 0;
58322 +#endif
58323 + return 0;
58324 +}
58325 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58326 new file mode 100644
58327 index 0000000..a3b12a0
58328 --- /dev/null
58329 +++ b/grsecurity/grsec_pax.c
58330 @@ -0,0 +1,36 @@
58331 +#include <linux/kernel.h>
58332 +#include <linux/sched.h>
58333 +#include <linux/mm.h>
58334 +#include <linux/file.h>
58335 +#include <linux/grinternal.h>
58336 +#include <linux/grsecurity.h>
58337 +
58338 +void
58339 +gr_log_textrel(struct vm_area_struct * vma)
58340 +{
58341 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58342 + if (grsec_enable_audit_textrel)
58343 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58344 +#endif
58345 + return;
58346 +}
58347 +
58348 +void
58349 +gr_log_rwxmmap(struct file *file)
58350 +{
58351 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58352 + if (grsec_enable_log_rwxmaps)
58353 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58354 +#endif
58355 + return;
58356 +}
58357 +
58358 +void
58359 +gr_log_rwxmprotect(struct file *file)
58360 +{
58361 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58362 + if (grsec_enable_log_rwxmaps)
58363 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58364 +#endif
58365 + return;
58366 +}
58367 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58368 new file mode 100644
58369 index 0000000..f7f29aa
58370 --- /dev/null
58371 +++ b/grsecurity/grsec_ptrace.c
58372 @@ -0,0 +1,30 @@
58373 +#include <linux/kernel.h>
58374 +#include <linux/sched.h>
58375 +#include <linux/grinternal.h>
58376 +#include <linux/security.h>
58377 +
58378 +void
58379 +gr_audit_ptrace(struct task_struct *task)
58380 +{
58381 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58382 + if (grsec_enable_audit_ptrace)
58383 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58384 +#endif
58385 + return;
58386 +}
58387 +
58388 +int
58389 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58390 +{
58391 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58392 + const struct dentry *dentry = file->f_path.dentry;
58393 + const struct vfsmount *mnt = file->f_path.mnt;
58394 +
58395 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58396 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58397 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58398 + return -EACCES;
58399 + }
58400 +#endif
58401 + return 0;
58402 +}
58403 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58404 new file mode 100644
58405 index 0000000..7a5b2de
58406 --- /dev/null
58407 +++ b/grsecurity/grsec_sig.c
58408 @@ -0,0 +1,207 @@
58409 +#include <linux/kernel.h>
58410 +#include <linux/sched.h>
58411 +#include <linux/delay.h>
58412 +#include <linux/grsecurity.h>
58413 +#include <linux/grinternal.h>
58414 +#include <linux/hardirq.h>
58415 +
58416 +char *signames[] = {
58417 + [SIGSEGV] = "Segmentation fault",
58418 + [SIGILL] = "Illegal instruction",
58419 + [SIGABRT] = "Abort",
58420 + [SIGBUS] = "Invalid alignment/Bus error"
58421 +};
58422 +
58423 +void
58424 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58425 +{
58426 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58427 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58428 + (sig == SIGABRT) || (sig == SIGBUS))) {
58429 + if (t->pid == current->pid) {
58430 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58431 + } else {
58432 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58433 + }
58434 + }
58435 +#endif
58436 + return;
58437 +}
58438 +
58439 +int
58440 +gr_handle_signal(const struct task_struct *p, const int sig)
58441 +{
58442 +#ifdef CONFIG_GRKERNSEC
58443 + /* ignore the 0 signal for protected task checks */
58444 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58445 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58446 + return -EPERM;
58447 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58448 + return -EPERM;
58449 + }
58450 +#endif
58451 + return 0;
58452 +}
58453 +
58454 +#ifdef CONFIG_GRKERNSEC
58455 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58456 +
58457 +int gr_fake_force_sig(int sig, struct task_struct *t)
58458 +{
58459 + unsigned long int flags;
58460 + int ret, blocked, ignored;
58461 + struct k_sigaction *action;
58462 +
58463 + spin_lock_irqsave(&t->sighand->siglock, flags);
58464 + action = &t->sighand->action[sig-1];
58465 + ignored = action->sa.sa_handler == SIG_IGN;
58466 + blocked = sigismember(&t->blocked, sig);
58467 + if (blocked || ignored) {
58468 + action->sa.sa_handler = SIG_DFL;
58469 + if (blocked) {
58470 + sigdelset(&t->blocked, sig);
58471 + recalc_sigpending_and_wake(t);
58472 + }
58473 + }
58474 + if (action->sa.sa_handler == SIG_DFL)
58475 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58476 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58477 +
58478 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58479 +
58480 + return ret;
58481 +}
58482 +#endif
58483 +
58484 +#ifdef CONFIG_GRKERNSEC_BRUTE
58485 +#define GR_USER_BAN_TIME (15 * 60)
58486 +
58487 +static int __get_dumpable(unsigned long mm_flags)
58488 +{
58489 + int ret;
58490 +
58491 + ret = mm_flags & MMF_DUMPABLE_MASK;
58492 + return (ret >= 2) ? 2 : ret;
58493 +}
58494 +#endif
58495 +
58496 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58497 +{
58498 +#ifdef CONFIG_GRKERNSEC_BRUTE
58499 + uid_t uid = 0;
58500 +
58501 + if (!grsec_enable_brute)
58502 + return;
58503 +
58504 + rcu_read_lock();
58505 + read_lock(&tasklist_lock);
58506 + read_lock(&grsec_exec_file_lock);
58507 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58508 + p->real_parent->brute = 1;
58509 + else {
58510 + const struct cred *cred = __task_cred(p), *cred2;
58511 + struct task_struct *tsk, *tsk2;
58512 +
58513 + if (!__get_dumpable(mm_flags) && cred->uid) {
58514 + struct user_struct *user;
58515 +
58516 + uid = cred->uid;
58517 +
58518 + /* this is put upon execution past expiration */
58519 + user = find_user(uid);
58520 + if (user == NULL)
58521 + goto unlock;
58522 + user->banned = 1;
58523 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58524 + if (user->ban_expires == ~0UL)
58525 + user->ban_expires--;
58526 +
58527 + do_each_thread(tsk2, tsk) {
58528 + cred2 = __task_cred(tsk);
58529 + if (tsk != p && cred2->uid == uid)
58530 + gr_fake_force_sig(SIGKILL, tsk);
58531 + } while_each_thread(tsk2, tsk);
58532 + }
58533 + }
58534 +unlock:
58535 + read_unlock(&grsec_exec_file_lock);
58536 + read_unlock(&tasklist_lock);
58537 + rcu_read_unlock();
58538 +
58539 + if (uid)
58540 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58541 +
58542 +#endif
58543 + return;
58544 +}
58545 +
58546 +void gr_handle_brute_check(void)
58547 +{
58548 +#ifdef CONFIG_GRKERNSEC_BRUTE
58549 + if (current->brute)
58550 + msleep(30 * 1000);
58551 +#endif
58552 + return;
58553 +}
58554 +
58555 +void gr_handle_kernel_exploit(void)
58556 +{
58557 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58558 + const struct cred *cred;
58559 + struct task_struct *tsk, *tsk2;
58560 + struct user_struct *user;
58561 + uid_t uid;
58562 +
58563 + if (in_irq() || in_serving_softirq() || in_nmi())
58564 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58565 +
58566 + uid = current_uid();
58567 +
58568 + if (uid == 0)
58569 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58570 + else {
58571 + /* kill all the processes of this user, hold a reference
58572 + to their creds struct, and prevent them from creating
58573 + another process until system reset
58574 + */
58575 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58576 + /* we intentionally leak this ref */
58577 + user = get_uid(current->cred->user);
58578 + if (user) {
58579 + user->banned = 1;
58580 + user->ban_expires = ~0UL;
58581 + }
58582 +
58583 + read_lock(&tasklist_lock);
58584 + do_each_thread(tsk2, tsk) {
58585 + cred = __task_cred(tsk);
58586 + if (cred->uid == uid)
58587 + gr_fake_force_sig(SIGKILL, tsk);
58588 + } while_each_thread(tsk2, tsk);
58589 + read_unlock(&tasklist_lock);
58590 + }
58591 +#endif
58592 +}
58593 +
58594 +int __gr_process_user_ban(struct user_struct *user)
58595 +{
58596 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58597 + if (unlikely(user->banned)) {
58598 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58599 + user->banned = 0;
58600 + user->ban_expires = 0;
58601 + free_uid(user);
58602 + } else
58603 + return -EPERM;
58604 + }
58605 +#endif
58606 + return 0;
58607 +}
58608 +
58609 +int gr_process_user_ban(void)
58610 +{
58611 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58612 + return __gr_process_user_ban(current->cred->user);
58613 +#endif
58614 + return 0;
58615 +}
58616 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58617 new file mode 100644
58618 index 0000000..4030d57
58619 --- /dev/null
58620 +++ b/grsecurity/grsec_sock.c
58621 @@ -0,0 +1,244 @@
58622 +#include <linux/kernel.h>
58623 +#include <linux/module.h>
58624 +#include <linux/sched.h>
58625 +#include <linux/file.h>
58626 +#include <linux/net.h>
58627 +#include <linux/in.h>
58628 +#include <linux/ip.h>
58629 +#include <net/sock.h>
58630 +#include <net/inet_sock.h>
58631 +#include <linux/grsecurity.h>
58632 +#include <linux/grinternal.h>
58633 +#include <linux/gracl.h>
58634 +
58635 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58636 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58637 +
58638 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58639 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58640 +
58641 +#ifdef CONFIG_UNIX_MODULE
58642 +EXPORT_SYMBOL(gr_acl_handle_unix);
58643 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58644 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58645 +EXPORT_SYMBOL(gr_handle_create);
58646 +#endif
58647 +
58648 +#ifdef CONFIG_GRKERNSEC
58649 +#define gr_conn_table_size 32749
58650 +struct conn_table_entry {
58651 + struct conn_table_entry *next;
58652 + struct signal_struct *sig;
58653 +};
58654 +
58655 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58656 +DEFINE_SPINLOCK(gr_conn_table_lock);
58657 +
58658 +extern const char * gr_socktype_to_name(unsigned char type);
58659 +extern const char * gr_proto_to_name(unsigned char proto);
58660 +extern const char * gr_sockfamily_to_name(unsigned char family);
58661 +
58662 +static __inline__ int
58663 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58664 +{
58665 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58666 +}
58667 +
58668 +static __inline__ int
58669 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58670 + __u16 sport, __u16 dport)
58671 +{
58672 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58673 + sig->gr_sport == sport && sig->gr_dport == dport))
58674 + return 1;
58675 + else
58676 + return 0;
58677 +}
58678 +
58679 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58680 +{
58681 + struct conn_table_entry **match;
58682 + unsigned int index;
58683 +
58684 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58685 + sig->gr_sport, sig->gr_dport,
58686 + gr_conn_table_size);
58687 +
58688 + newent->sig = sig;
58689 +
58690 + match = &gr_conn_table[index];
58691 + newent->next = *match;
58692 + *match = newent;
58693 +
58694 + return;
58695 +}
58696 +
58697 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58698 +{
58699 + struct conn_table_entry *match, *last = NULL;
58700 + unsigned int index;
58701 +
58702 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58703 + sig->gr_sport, sig->gr_dport,
58704 + gr_conn_table_size);
58705 +
58706 + match = gr_conn_table[index];
58707 + while (match && !conn_match(match->sig,
58708 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58709 + sig->gr_dport)) {
58710 + last = match;
58711 + match = match->next;
58712 + }
58713 +
58714 + if (match) {
58715 + if (last)
58716 + last->next = match->next;
58717 + else
58718 + gr_conn_table[index] = NULL;
58719 + kfree(match);
58720 + }
58721 +
58722 + return;
58723 +}
58724 +
58725 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58726 + __u16 sport, __u16 dport)
58727 +{
58728 + struct conn_table_entry *match;
58729 + unsigned int index;
58730 +
58731 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58732 +
58733 + match = gr_conn_table[index];
58734 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58735 + match = match->next;
58736 +
58737 + if (match)
58738 + return match->sig;
58739 + else
58740 + return NULL;
58741 +}
58742 +
58743 +#endif
58744 +
58745 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58746 +{
58747 +#ifdef CONFIG_GRKERNSEC
58748 + struct signal_struct *sig = task->signal;
58749 + struct conn_table_entry *newent;
58750 +
58751 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58752 + if (newent == NULL)
58753 + return;
58754 + /* no bh lock needed since we are called with bh disabled */
58755 + spin_lock(&gr_conn_table_lock);
58756 + gr_del_task_from_ip_table_nolock(sig);
58757 + sig->gr_saddr = inet->inet_rcv_saddr;
58758 + sig->gr_daddr = inet->inet_daddr;
58759 + sig->gr_sport = inet->inet_sport;
58760 + sig->gr_dport = inet->inet_dport;
58761 + gr_add_to_task_ip_table_nolock(sig, newent);
58762 + spin_unlock(&gr_conn_table_lock);
58763 +#endif
58764 + return;
58765 +}
58766 +
58767 +void gr_del_task_from_ip_table(struct task_struct *task)
58768 +{
58769 +#ifdef CONFIG_GRKERNSEC
58770 + spin_lock_bh(&gr_conn_table_lock);
58771 + gr_del_task_from_ip_table_nolock(task->signal);
58772 + spin_unlock_bh(&gr_conn_table_lock);
58773 +#endif
58774 + return;
58775 +}
58776 +
58777 +void
58778 +gr_attach_curr_ip(const struct sock *sk)
58779 +{
58780 +#ifdef CONFIG_GRKERNSEC
58781 + struct signal_struct *p, *set;
58782 + const struct inet_sock *inet = inet_sk(sk);
58783 +
58784 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58785 + return;
58786 +
58787 + set = current->signal;
58788 +
58789 + spin_lock_bh(&gr_conn_table_lock);
58790 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58791 + inet->inet_dport, inet->inet_sport);
58792 + if (unlikely(p != NULL)) {
58793 + set->curr_ip = p->curr_ip;
58794 + set->used_accept = 1;
58795 + gr_del_task_from_ip_table_nolock(p);
58796 + spin_unlock_bh(&gr_conn_table_lock);
58797 + return;
58798 + }
58799 + spin_unlock_bh(&gr_conn_table_lock);
58800 +
58801 + set->curr_ip = inet->inet_daddr;
58802 + set->used_accept = 1;
58803 +#endif
58804 + return;
58805 +}
58806 +
58807 +int
58808 +gr_handle_sock_all(const int family, const int type, const int protocol)
58809 +{
58810 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58811 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58812 + (family != AF_UNIX)) {
58813 + if (family == AF_INET)
58814 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58815 + else
58816 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58817 + return -EACCES;
58818 + }
58819 +#endif
58820 + return 0;
58821 +}
58822 +
58823 +int
58824 +gr_handle_sock_server(const struct sockaddr *sck)
58825 +{
58826 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58827 + if (grsec_enable_socket_server &&
58828 + in_group_p(grsec_socket_server_gid) &&
58829 + sck && (sck->sa_family != AF_UNIX) &&
58830 + (sck->sa_family != AF_LOCAL)) {
58831 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58832 + return -EACCES;
58833 + }
58834 +#endif
58835 + return 0;
58836 +}
58837 +
58838 +int
58839 +gr_handle_sock_server_other(const struct sock *sck)
58840 +{
58841 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58842 + if (grsec_enable_socket_server &&
58843 + in_group_p(grsec_socket_server_gid) &&
58844 + sck && (sck->sk_family != AF_UNIX) &&
58845 + (sck->sk_family != AF_LOCAL)) {
58846 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58847 + return -EACCES;
58848 + }
58849 +#endif
58850 + return 0;
58851 +}
58852 +
58853 +int
58854 +gr_handle_sock_client(const struct sockaddr *sck)
58855 +{
58856 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58857 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58858 + sck && (sck->sa_family != AF_UNIX) &&
58859 + (sck->sa_family != AF_LOCAL)) {
58860 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58861 + return -EACCES;
58862 + }
58863 +#endif
58864 + return 0;
58865 +}
58866 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58867 new file mode 100644
58868 index 0000000..a1aedd7
58869 --- /dev/null
58870 +++ b/grsecurity/grsec_sysctl.c
58871 @@ -0,0 +1,451 @@
58872 +#include <linux/kernel.h>
58873 +#include <linux/sched.h>
58874 +#include <linux/sysctl.h>
58875 +#include <linux/grsecurity.h>
58876 +#include <linux/grinternal.h>
58877 +
58878 +int
58879 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58880 +{
58881 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58882 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58883 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58884 + return -EACCES;
58885 + }
58886 +#endif
58887 + return 0;
58888 +}
58889 +
58890 +#ifdef CONFIG_GRKERNSEC_ROFS
58891 +static int __maybe_unused one = 1;
58892 +#endif
58893 +
58894 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58895 +struct ctl_table grsecurity_table[] = {
58896 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58897 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58898 +#ifdef CONFIG_GRKERNSEC_IO
58899 + {
58900 + .procname = "disable_priv_io",
58901 + .data = &grsec_disable_privio,
58902 + .maxlen = sizeof(int),
58903 + .mode = 0600,
58904 + .proc_handler = &proc_dointvec,
58905 + },
58906 +#endif
58907 +#endif
58908 +#ifdef CONFIG_GRKERNSEC_LINK
58909 + {
58910 + .procname = "linking_restrictions",
58911 + .data = &grsec_enable_link,
58912 + .maxlen = sizeof(int),
58913 + .mode = 0600,
58914 + .proc_handler = &proc_dointvec,
58915 + },
58916 +#endif
58917 +#ifdef CONFIG_GRKERNSEC_BRUTE
58918 + {
58919 + .procname = "deter_bruteforce",
58920 + .data = &grsec_enable_brute,
58921 + .maxlen = sizeof(int),
58922 + .mode = 0600,
58923 + .proc_handler = &proc_dointvec,
58924 + },
58925 +#endif
58926 +#ifdef CONFIG_GRKERNSEC_FIFO
58927 + {
58928 + .procname = "fifo_restrictions",
58929 + .data = &grsec_enable_fifo,
58930 + .maxlen = sizeof(int),
58931 + .mode = 0600,
58932 + .proc_handler = &proc_dointvec,
58933 + },
58934 +#endif
58935 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58936 + {
58937 + .procname = "ptrace_readexec",
58938 + .data = &grsec_enable_ptrace_readexec,
58939 + .maxlen = sizeof(int),
58940 + .mode = 0600,
58941 + .proc_handler = &proc_dointvec,
58942 + },
58943 +#endif
58944 +#ifdef CONFIG_GRKERNSEC_SETXID
58945 + {
58946 + .procname = "consistent_setxid",
58947 + .data = &grsec_enable_setxid,
58948 + .maxlen = sizeof(int),
58949 + .mode = 0600,
58950 + .proc_handler = &proc_dointvec,
58951 + },
58952 +#endif
58953 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58954 + {
58955 + .procname = "ip_blackhole",
58956 + .data = &grsec_enable_blackhole,
58957 + .maxlen = sizeof(int),
58958 + .mode = 0600,
58959 + .proc_handler = &proc_dointvec,
58960 + },
58961 + {
58962 + .procname = "lastack_retries",
58963 + .data = &grsec_lastack_retries,
58964 + .maxlen = sizeof(int),
58965 + .mode = 0600,
58966 + .proc_handler = &proc_dointvec,
58967 + },
58968 +#endif
58969 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58970 + {
58971 + .procname = "exec_logging",
58972 + .data = &grsec_enable_execlog,
58973 + .maxlen = sizeof(int),
58974 + .mode = 0600,
58975 + .proc_handler = &proc_dointvec,
58976 + },
58977 +#endif
58978 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58979 + {
58980 + .procname = "rwxmap_logging",
58981 + .data = &grsec_enable_log_rwxmaps,
58982 + .maxlen = sizeof(int),
58983 + .mode = 0600,
58984 + .proc_handler = &proc_dointvec,
58985 + },
58986 +#endif
58987 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58988 + {
58989 + .procname = "signal_logging",
58990 + .data = &grsec_enable_signal,
58991 + .maxlen = sizeof(int),
58992 + .mode = 0600,
58993 + .proc_handler = &proc_dointvec,
58994 + },
58995 +#endif
58996 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58997 + {
58998 + .procname = "forkfail_logging",
58999 + .data = &grsec_enable_forkfail,
59000 + .maxlen = sizeof(int),
59001 + .mode = 0600,
59002 + .proc_handler = &proc_dointvec,
59003 + },
59004 +#endif
59005 +#ifdef CONFIG_GRKERNSEC_TIME
59006 + {
59007 + .procname = "timechange_logging",
59008 + .data = &grsec_enable_time,
59009 + .maxlen = sizeof(int),
59010 + .mode = 0600,
59011 + .proc_handler = &proc_dointvec,
59012 + },
59013 +#endif
59014 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59015 + {
59016 + .procname = "chroot_deny_shmat",
59017 + .data = &grsec_enable_chroot_shmat,
59018 + .maxlen = sizeof(int),
59019 + .mode = 0600,
59020 + .proc_handler = &proc_dointvec,
59021 + },
59022 +#endif
59023 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59024 + {
59025 + .procname = "chroot_deny_unix",
59026 + .data = &grsec_enable_chroot_unix,
59027 + .maxlen = sizeof(int),
59028 + .mode = 0600,
59029 + .proc_handler = &proc_dointvec,
59030 + },
59031 +#endif
59032 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59033 + {
59034 + .procname = "chroot_deny_mount",
59035 + .data = &grsec_enable_chroot_mount,
59036 + .maxlen = sizeof(int),
59037 + .mode = 0600,
59038 + .proc_handler = &proc_dointvec,
59039 + },
59040 +#endif
59041 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59042 + {
59043 + .procname = "chroot_deny_fchdir",
59044 + .data = &grsec_enable_chroot_fchdir,
59045 + .maxlen = sizeof(int),
59046 + .mode = 0600,
59047 + .proc_handler = &proc_dointvec,
59048 + },
59049 +#endif
59050 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59051 + {
59052 + .procname = "chroot_deny_chroot",
59053 + .data = &grsec_enable_chroot_double,
59054 + .maxlen = sizeof(int),
59055 + .mode = 0600,
59056 + .proc_handler = &proc_dointvec,
59057 + },
59058 +#endif
59059 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59060 + {
59061 + .procname = "chroot_deny_pivot",
59062 + .data = &grsec_enable_chroot_pivot,
59063 + .maxlen = sizeof(int),
59064 + .mode = 0600,
59065 + .proc_handler = &proc_dointvec,
59066 + },
59067 +#endif
59068 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59069 + {
59070 + .procname = "chroot_enforce_chdir",
59071 + .data = &grsec_enable_chroot_chdir,
59072 + .maxlen = sizeof(int),
59073 + .mode = 0600,
59074 + .proc_handler = &proc_dointvec,
59075 + },
59076 +#endif
59077 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59078 + {
59079 + .procname = "chroot_deny_chmod",
59080 + .data = &grsec_enable_chroot_chmod,
59081 + .maxlen = sizeof(int),
59082 + .mode = 0600,
59083 + .proc_handler = &proc_dointvec,
59084 + },
59085 +#endif
59086 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59087 + {
59088 + .procname = "chroot_deny_mknod",
59089 + .data = &grsec_enable_chroot_mknod,
59090 + .maxlen = sizeof(int),
59091 + .mode = 0600,
59092 + .proc_handler = &proc_dointvec,
59093 + },
59094 +#endif
59095 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59096 + {
59097 + .procname = "chroot_restrict_nice",
59098 + .data = &grsec_enable_chroot_nice,
59099 + .maxlen = sizeof(int),
59100 + .mode = 0600,
59101 + .proc_handler = &proc_dointvec,
59102 + },
59103 +#endif
59104 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59105 + {
59106 + .procname = "chroot_execlog",
59107 + .data = &grsec_enable_chroot_execlog,
59108 + .maxlen = sizeof(int),
59109 + .mode = 0600,
59110 + .proc_handler = &proc_dointvec,
59111 + },
59112 +#endif
59113 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59114 + {
59115 + .procname = "chroot_caps",
59116 + .data = &grsec_enable_chroot_caps,
59117 + .maxlen = sizeof(int),
59118 + .mode = 0600,
59119 + .proc_handler = &proc_dointvec,
59120 + },
59121 +#endif
59122 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59123 + {
59124 + .procname = "chroot_deny_sysctl",
59125 + .data = &grsec_enable_chroot_sysctl,
59126 + .maxlen = sizeof(int),
59127 + .mode = 0600,
59128 + .proc_handler = &proc_dointvec,
59129 + },
59130 +#endif
59131 +#ifdef CONFIG_GRKERNSEC_TPE
59132 + {
59133 + .procname = "tpe",
59134 + .data = &grsec_enable_tpe,
59135 + .maxlen = sizeof(int),
59136 + .mode = 0600,
59137 + .proc_handler = &proc_dointvec,
59138 + },
59139 + {
59140 + .procname = "tpe_gid",
59141 + .data = &grsec_tpe_gid,
59142 + .maxlen = sizeof(int),
59143 + .mode = 0600,
59144 + .proc_handler = &proc_dointvec,
59145 + },
59146 +#endif
59147 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59148 + {
59149 + .procname = "tpe_invert",
59150 + .data = &grsec_enable_tpe_invert,
59151 + .maxlen = sizeof(int),
59152 + .mode = 0600,
59153 + .proc_handler = &proc_dointvec,
59154 + },
59155 +#endif
59156 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59157 + {
59158 + .procname = "tpe_restrict_all",
59159 + .data = &grsec_enable_tpe_all,
59160 + .maxlen = sizeof(int),
59161 + .mode = 0600,
59162 + .proc_handler = &proc_dointvec,
59163 + },
59164 +#endif
59165 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59166 + {
59167 + .procname = "socket_all",
59168 + .data = &grsec_enable_socket_all,
59169 + .maxlen = sizeof(int),
59170 + .mode = 0600,
59171 + .proc_handler = &proc_dointvec,
59172 + },
59173 + {
59174 + .procname = "socket_all_gid",
59175 + .data = &grsec_socket_all_gid,
59176 + .maxlen = sizeof(int),
59177 + .mode = 0600,
59178 + .proc_handler = &proc_dointvec,
59179 + },
59180 +#endif
59181 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59182 + {
59183 + .procname = "socket_client",
59184 + .data = &grsec_enable_socket_client,
59185 + .maxlen = sizeof(int),
59186 + .mode = 0600,
59187 + .proc_handler = &proc_dointvec,
59188 + },
59189 + {
59190 + .procname = "socket_client_gid",
59191 + .data = &grsec_socket_client_gid,
59192 + .maxlen = sizeof(int),
59193 + .mode = 0600,
59194 + .proc_handler = &proc_dointvec,
59195 + },
59196 +#endif
59197 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59198 + {
59199 + .procname = "socket_server",
59200 + .data = &grsec_enable_socket_server,
59201 + .maxlen = sizeof(int),
59202 + .mode = 0600,
59203 + .proc_handler = &proc_dointvec,
59204 + },
59205 + {
59206 + .procname = "socket_server_gid",
59207 + .data = &grsec_socket_server_gid,
59208 + .maxlen = sizeof(int),
59209 + .mode = 0600,
59210 + .proc_handler = &proc_dointvec,
59211 + },
59212 +#endif
59213 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59214 + {
59215 + .procname = "audit_group",
59216 + .data = &grsec_enable_group,
59217 + .maxlen = sizeof(int),
59218 + .mode = 0600,
59219 + .proc_handler = &proc_dointvec,
59220 + },
59221 + {
59222 + .procname = "audit_gid",
59223 + .data = &grsec_audit_gid,
59224 + .maxlen = sizeof(int),
59225 + .mode = 0600,
59226 + .proc_handler = &proc_dointvec,
59227 + },
59228 +#endif
59229 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59230 + {
59231 + .procname = "audit_chdir",
59232 + .data = &grsec_enable_chdir,
59233 + .maxlen = sizeof(int),
59234 + .mode = 0600,
59235 + .proc_handler = &proc_dointvec,
59236 + },
59237 +#endif
59238 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59239 + {
59240 + .procname = "audit_mount",
59241 + .data = &grsec_enable_mount,
59242 + .maxlen = sizeof(int),
59243 + .mode = 0600,
59244 + .proc_handler = &proc_dointvec,
59245 + },
59246 +#endif
59247 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59248 + {
59249 + .procname = "audit_textrel",
59250 + .data = &grsec_enable_audit_textrel,
59251 + .maxlen = sizeof(int),
59252 + .mode = 0600,
59253 + .proc_handler = &proc_dointvec,
59254 + },
59255 +#endif
59256 +#ifdef CONFIG_GRKERNSEC_DMESG
59257 + {
59258 + .procname = "dmesg",
59259 + .data = &grsec_enable_dmesg,
59260 + .maxlen = sizeof(int),
59261 + .mode = 0600,
59262 + .proc_handler = &proc_dointvec,
59263 + },
59264 +#endif
59265 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59266 + {
59267 + .procname = "chroot_findtask",
59268 + .data = &grsec_enable_chroot_findtask,
59269 + .maxlen = sizeof(int),
59270 + .mode = 0600,
59271 + .proc_handler = &proc_dointvec,
59272 + },
59273 +#endif
59274 +#ifdef CONFIG_GRKERNSEC_RESLOG
59275 + {
59276 + .procname = "resource_logging",
59277 + .data = &grsec_resource_logging,
59278 + .maxlen = sizeof(int),
59279 + .mode = 0600,
59280 + .proc_handler = &proc_dointvec,
59281 + },
59282 +#endif
59283 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59284 + {
59285 + .procname = "audit_ptrace",
59286 + .data = &grsec_enable_audit_ptrace,
59287 + .maxlen = sizeof(int),
59288 + .mode = 0600,
59289 + .proc_handler = &proc_dointvec,
59290 + },
59291 +#endif
59292 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59293 + {
59294 + .procname = "harden_ptrace",
59295 + .data = &grsec_enable_harden_ptrace,
59296 + .maxlen = sizeof(int),
59297 + .mode = 0600,
59298 + .proc_handler = &proc_dointvec,
59299 + },
59300 +#endif
59301 + {
59302 + .procname = "grsec_lock",
59303 + .data = &grsec_lock,
59304 + .maxlen = sizeof(int),
59305 + .mode = 0600,
59306 + .proc_handler = &proc_dointvec,
59307 + },
59308 +#endif
59309 +#ifdef CONFIG_GRKERNSEC_ROFS
59310 + {
59311 + .procname = "romount_protect",
59312 + .data = &grsec_enable_rofs,
59313 + .maxlen = sizeof(int),
59314 + .mode = 0600,
59315 + .proc_handler = &proc_dointvec_minmax,
59316 + .extra1 = &one,
59317 + .extra2 = &one,
59318 + },
59319 +#endif
59320 + { }
59321 +};
59322 +#endif
59323 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59324 new file mode 100644
59325 index 0000000..0dc13c3
59326 --- /dev/null
59327 +++ b/grsecurity/grsec_time.c
59328 @@ -0,0 +1,16 @@
59329 +#include <linux/kernel.h>
59330 +#include <linux/sched.h>
59331 +#include <linux/grinternal.h>
59332 +#include <linux/module.h>
59333 +
59334 +void
59335 +gr_log_timechange(void)
59336 +{
59337 +#ifdef CONFIG_GRKERNSEC_TIME
59338 + if (grsec_enable_time)
59339 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59340 +#endif
59341 + return;
59342 +}
59343 +
59344 +EXPORT_SYMBOL(gr_log_timechange);
59345 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59346 new file mode 100644
59347 index 0000000..07e0dc0
59348 --- /dev/null
59349 +++ b/grsecurity/grsec_tpe.c
59350 @@ -0,0 +1,73 @@
59351 +#include <linux/kernel.h>
59352 +#include <linux/sched.h>
59353 +#include <linux/file.h>
59354 +#include <linux/fs.h>
59355 +#include <linux/grinternal.h>
59356 +
59357 +extern int gr_acl_tpe_check(void);
59358 +
59359 +int
59360 +gr_tpe_allow(const struct file *file)
59361 +{
59362 +#ifdef CONFIG_GRKERNSEC
59363 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59364 + const struct cred *cred = current_cred();
59365 + char *msg = NULL;
59366 + char *msg2 = NULL;
59367 +
59368 + // never restrict root
59369 + if (!cred->uid)
59370 + return 1;
59371 +
59372 + if (grsec_enable_tpe) {
59373 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59374 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59375 + msg = "not being in trusted group";
59376 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59377 + msg = "being in untrusted group";
59378 +#else
59379 + if (in_group_p(grsec_tpe_gid))
59380 + msg = "being in untrusted group";
59381 +#endif
59382 + }
59383 + if (!msg && gr_acl_tpe_check())
59384 + msg = "being in untrusted role";
59385 +
59386 + // not in any affected group/role
59387 + if (!msg)
59388 + goto next_check;
59389 +
59390 + if (inode->i_uid)
59391 + msg2 = "file in non-root-owned directory";
59392 + else if (inode->i_mode & S_IWOTH)
59393 + msg2 = "file in world-writable directory";
59394 + else if (inode->i_mode & S_IWGRP)
59395 + msg2 = "file in group-writable directory";
59396 +
59397 + if (msg && msg2) {
59398 + char fullmsg[70] = {0};
59399 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59400 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59401 + return 0;
59402 + }
59403 + msg = NULL;
59404 +next_check:
59405 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59406 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59407 + return 1;
59408 +
59409 + if (inode->i_uid && (inode->i_uid != cred->uid))
59410 + msg = "directory not owned by user";
59411 + else if (inode->i_mode & S_IWOTH)
59412 + msg = "file in world-writable directory";
59413 + else if (inode->i_mode & S_IWGRP)
59414 + msg = "file in group-writable directory";
59415 +
59416 + if (msg) {
59417 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59418 + return 0;
59419 + }
59420 +#endif
59421 +#endif
59422 + return 1;
59423 +}
59424 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59425 new file mode 100644
59426 index 0000000..9f7b1ac
59427 --- /dev/null
59428 +++ b/grsecurity/grsum.c
59429 @@ -0,0 +1,61 @@
59430 +#include <linux/err.h>
59431 +#include <linux/kernel.h>
59432 +#include <linux/sched.h>
59433 +#include <linux/mm.h>
59434 +#include <linux/scatterlist.h>
59435 +#include <linux/crypto.h>
59436 +#include <linux/gracl.h>
59437 +
59438 +
59439 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59440 +#error "crypto and sha256 must be built into the kernel"
59441 +#endif
59442 +
59443 +int
59444 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59445 +{
59446 + char *p;
59447 + struct crypto_hash *tfm;
59448 + struct hash_desc desc;
59449 + struct scatterlist sg;
59450 + unsigned char temp_sum[GR_SHA_LEN];
59451 + volatile int retval = 0;
59452 + volatile int dummy = 0;
59453 + unsigned int i;
59454 +
59455 + sg_init_table(&sg, 1);
59456 +
59457 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59458 + if (IS_ERR(tfm)) {
59459 + /* should never happen, since sha256 should be built in */
59460 + return 1;
59461 + }
59462 +
59463 + desc.tfm = tfm;
59464 + desc.flags = 0;
59465 +
59466 + crypto_hash_init(&desc);
59467 +
59468 + p = salt;
59469 + sg_set_buf(&sg, p, GR_SALT_LEN);
59470 + crypto_hash_update(&desc, &sg, sg.length);
59471 +
59472 + p = entry->pw;
59473 + sg_set_buf(&sg, p, strlen(p));
59474 +
59475 + crypto_hash_update(&desc, &sg, sg.length);
59476 +
59477 + crypto_hash_final(&desc, temp_sum);
59478 +
59479 + memset(entry->pw, 0, GR_PW_LEN);
59480 +
59481 + for (i = 0; i < GR_SHA_LEN; i++)
59482 + if (sum[i] != temp_sum[i])
59483 + retval = 1;
59484 + else
59485 + dummy = 1; // waste a cycle
59486 +
59487 + crypto_free_hash(tfm);
59488 +
59489 + return retval;
59490 +}
59491 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59492 index 6cd5b64..f620d2d 100644
59493 --- a/include/acpi/acpi_bus.h
59494 +++ b/include/acpi/acpi_bus.h
59495 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59496 acpi_op_bind bind;
59497 acpi_op_unbind unbind;
59498 acpi_op_notify notify;
59499 -};
59500 +} __no_const;
59501
59502 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59503
59504 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59505 index b7babf0..71e4e74 100644
59506 --- a/include/asm-generic/atomic-long.h
59507 +++ b/include/asm-generic/atomic-long.h
59508 @@ -22,6 +22,12 @@
59509
59510 typedef atomic64_t atomic_long_t;
59511
59512 +#ifdef CONFIG_PAX_REFCOUNT
59513 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59514 +#else
59515 +typedef atomic64_t atomic_long_unchecked_t;
59516 +#endif
59517 +
59518 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59519
59520 static inline long atomic_long_read(atomic_long_t *l)
59521 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59522 return (long)atomic64_read(v);
59523 }
59524
59525 +#ifdef CONFIG_PAX_REFCOUNT
59526 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59527 +{
59528 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59529 +
59530 + return (long)atomic64_read_unchecked(v);
59531 +}
59532 +#endif
59533 +
59534 static inline void atomic_long_set(atomic_long_t *l, long i)
59535 {
59536 atomic64_t *v = (atomic64_t *)l;
59537 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59538 atomic64_set(v, i);
59539 }
59540
59541 +#ifdef CONFIG_PAX_REFCOUNT
59542 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59543 +{
59544 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59545 +
59546 + atomic64_set_unchecked(v, i);
59547 +}
59548 +#endif
59549 +
59550 static inline void atomic_long_inc(atomic_long_t *l)
59551 {
59552 atomic64_t *v = (atomic64_t *)l;
59553 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59554 atomic64_inc(v);
59555 }
59556
59557 +#ifdef CONFIG_PAX_REFCOUNT
59558 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59559 +{
59560 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59561 +
59562 + atomic64_inc_unchecked(v);
59563 +}
59564 +#endif
59565 +
59566 static inline void atomic_long_dec(atomic_long_t *l)
59567 {
59568 atomic64_t *v = (atomic64_t *)l;
59569 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59570 atomic64_dec(v);
59571 }
59572
59573 +#ifdef CONFIG_PAX_REFCOUNT
59574 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59575 +{
59576 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59577 +
59578 + atomic64_dec_unchecked(v);
59579 +}
59580 +#endif
59581 +
59582 static inline void atomic_long_add(long i, atomic_long_t *l)
59583 {
59584 atomic64_t *v = (atomic64_t *)l;
59585 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59586 atomic64_add(i, v);
59587 }
59588
59589 +#ifdef CONFIG_PAX_REFCOUNT
59590 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59591 +{
59592 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59593 +
59594 + atomic64_add_unchecked(i, v);
59595 +}
59596 +#endif
59597 +
59598 static inline void atomic_long_sub(long i, atomic_long_t *l)
59599 {
59600 atomic64_t *v = (atomic64_t *)l;
59601 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59602 atomic64_sub(i, v);
59603 }
59604
59605 +#ifdef CONFIG_PAX_REFCOUNT
59606 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59607 +{
59608 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59609 +
59610 + atomic64_sub_unchecked(i, v);
59611 +}
59612 +#endif
59613 +
59614 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59615 {
59616 atomic64_t *v = (atomic64_t *)l;
59617 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59618 return (long)atomic64_inc_return(v);
59619 }
59620
59621 +#ifdef CONFIG_PAX_REFCOUNT
59622 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59623 +{
59624 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59625 +
59626 + return (long)atomic64_inc_return_unchecked(v);
59627 +}
59628 +#endif
59629 +
59630 static inline long atomic_long_dec_return(atomic_long_t *l)
59631 {
59632 atomic64_t *v = (atomic64_t *)l;
59633 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59634
59635 typedef atomic_t atomic_long_t;
59636
59637 +#ifdef CONFIG_PAX_REFCOUNT
59638 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59639 +#else
59640 +typedef atomic_t atomic_long_unchecked_t;
59641 +#endif
59642 +
59643 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59644 static inline long atomic_long_read(atomic_long_t *l)
59645 {
59646 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59647 return (long)atomic_read(v);
59648 }
59649
59650 +#ifdef CONFIG_PAX_REFCOUNT
59651 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59652 +{
59653 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59654 +
59655 + return (long)atomic_read_unchecked(v);
59656 +}
59657 +#endif
59658 +
59659 static inline void atomic_long_set(atomic_long_t *l, long i)
59660 {
59661 atomic_t *v = (atomic_t *)l;
59662 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59663 atomic_set(v, i);
59664 }
59665
59666 +#ifdef CONFIG_PAX_REFCOUNT
59667 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59668 +{
59669 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59670 +
59671 + atomic_set_unchecked(v, i);
59672 +}
59673 +#endif
59674 +
59675 static inline void atomic_long_inc(atomic_long_t *l)
59676 {
59677 atomic_t *v = (atomic_t *)l;
59678 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59679 atomic_inc(v);
59680 }
59681
59682 +#ifdef CONFIG_PAX_REFCOUNT
59683 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59684 +{
59685 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59686 +
59687 + atomic_inc_unchecked(v);
59688 +}
59689 +#endif
59690 +
59691 static inline void atomic_long_dec(atomic_long_t *l)
59692 {
59693 atomic_t *v = (atomic_t *)l;
59694 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59695 atomic_dec(v);
59696 }
59697
59698 +#ifdef CONFIG_PAX_REFCOUNT
59699 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59700 +{
59701 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59702 +
59703 + atomic_dec_unchecked(v);
59704 +}
59705 +#endif
59706 +
59707 static inline void atomic_long_add(long i, atomic_long_t *l)
59708 {
59709 atomic_t *v = (atomic_t *)l;
59710 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59711 atomic_add(i, v);
59712 }
59713
59714 +#ifdef CONFIG_PAX_REFCOUNT
59715 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59716 +{
59717 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59718 +
59719 + atomic_add_unchecked(i, v);
59720 +}
59721 +#endif
59722 +
59723 static inline void atomic_long_sub(long i, atomic_long_t *l)
59724 {
59725 atomic_t *v = (atomic_t *)l;
59726 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59727 atomic_sub(i, v);
59728 }
59729
59730 +#ifdef CONFIG_PAX_REFCOUNT
59731 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59732 +{
59733 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59734 +
59735 + atomic_sub_unchecked(i, v);
59736 +}
59737 +#endif
59738 +
59739 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59740 {
59741 atomic_t *v = (atomic_t *)l;
59742 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59743 return (long)atomic_inc_return(v);
59744 }
59745
59746 +#ifdef CONFIG_PAX_REFCOUNT
59747 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59748 +{
59749 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59750 +
59751 + return (long)atomic_inc_return_unchecked(v);
59752 +}
59753 +#endif
59754 +
59755 static inline long atomic_long_dec_return(atomic_long_t *l)
59756 {
59757 atomic_t *v = (atomic_t *)l;
59758 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59759
59760 #endif /* BITS_PER_LONG == 64 */
59761
59762 +#ifdef CONFIG_PAX_REFCOUNT
59763 +static inline void pax_refcount_needs_these_functions(void)
59764 +{
59765 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59766 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59767 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59768 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59769 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59770 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59771 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59772 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59773 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59774 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59775 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59776 +
59777 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59778 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59779 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59780 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59781 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59782 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59783 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59784 +}
59785 +#else
59786 +#define atomic_read_unchecked(v) atomic_read(v)
59787 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59788 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59789 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59790 +#define atomic_inc_unchecked(v) atomic_inc(v)
59791 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59792 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59793 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59794 +#define atomic_dec_unchecked(v) atomic_dec(v)
59795 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59796 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59797 +
59798 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59799 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59800 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59801 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59802 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59803 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59804 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59805 +#endif
59806 +
59807 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59808 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59809 index b18ce4f..2ee2843 100644
59810 --- a/include/asm-generic/atomic64.h
59811 +++ b/include/asm-generic/atomic64.h
59812 @@ -16,6 +16,8 @@ typedef struct {
59813 long long counter;
59814 } atomic64_t;
59815
59816 +typedef atomic64_t atomic64_unchecked_t;
59817 +
59818 #define ATOMIC64_INIT(i) { (i) }
59819
59820 extern long long atomic64_read(const atomic64_t *v);
59821 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59822 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59823 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59824
59825 +#define atomic64_read_unchecked(v) atomic64_read(v)
59826 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59827 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59828 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59829 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59830 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59831 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59832 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59833 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59834 +
59835 #endif /* _ASM_GENERIC_ATOMIC64_H */
59836 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59837 index 1bfcfe5..e04c5c9 100644
59838 --- a/include/asm-generic/cache.h
59839 +++ b/include/asm-generic/cache.h
59840 @@ -6,7 +6,7 @@
59841 * cache lines need to provide their own cache.h.
59842 */
59843
59844 -#define L1_CACHE_SHIFT 5
59845 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59846 +#define L1_CACHE_SHIFT 5UL
59847 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59848
59849 #endif /* __ASM_GENERIC_CACHE_H */
59850 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59851 index 0d68a1e..b74a761 100644
59852 --- a/include/asm-generic/emergency-restart.h
59853 +++ b/include/asm-generic/emergency-restart.h
59854 @@ -1,7 +1,7 @@
59855 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59856 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59857
59858 -static inline void machine_emergency_restart(void)
59859 +static inline __noreturn void machine_emergency_restart(void)
59860 {
59861 machine_restart(NULL);
59862 }
59863 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59864 index 0232ccb..13d9165 100644
59865 --- a/include/asm-generic/kmap_types.h
59866 +++ b/include/asm-generic/kmap_types.h
59867 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59868 KMAP_D(17) KM_NMI,
59869 KMAP_D(18) KM_NMI_PTE,
59870 KMAP_D(19) KM_KDB,
59871 +KMAP_D(20) KM_CLEARPAGE,
59872 /*
59873 * Remember to update debug_kmap_atomic() when adding new kmap types!
59874 */
59875 -KMAP_D(20) KM_TYPE_NR
59876 +KMAP_D(21) KM_TYPE_NR
59877 };
59878
59879 #undef KMAP_D
59880 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59881 index 9ceb03b..2efbcbd 100644
59882 --- a/include/asm-generic/local.h
59883 +++ b/include/asm-generic/local.h
59884 @@ -39,6 +39,7 @@ typedef struct
59885 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59886 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59887 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59888 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59889
59890 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59891 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59892 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59893 index 725612b..9cc513a 100644
59894 --- a/include/asm-generic/pgtable-nopmd.h
59895 +++ b/include/asm-generic/pgtable-nopmd.h
59896 @@ -1,14 +1,19 @@
59897 #ifndef _PGTABLE_NOPMD_H
59898 #define _PGTABLE_NOPMD_H
59899
59900 -#ifndef __ASSEMBLY__
59901 -
59902 #include <asm-generic/pgtable-nopud.h>
59903
59904 -struct mm_struct;
59905 -
59906 #define __PAGETABLE_PMD_FOLDED
59907
59908 +#define PMD_SHIFT PUD_SHIFT
59909 +#define PTRS_PER_PMD 1
59910 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59911 +#define PMD_MASK (~(PMD_SIZE-1))
59912 +
59913 +#ifndef __ASSEMBLY__
59914 +
59915 +struct mm_struct;
59916 +
59917 /*
59918 * Having the pmd type consist of a pud gets the size right, and allows
59919 * us to conceptually access the pud entry that this pmd is folded into
59920 @@ -16,11 +21,6 @@ struct mm_struct;
59921 */
59922 typedef struct { pud_t pud; } pmd_t;
59923
59924 -#define PMD_SHIFT PUD_SHIFT
59925 -#define PTRS_PER_PMD 1
59926 -#define PMD_SIZE (1UL << PMD_SHIFT)
59927 -#define PMD_MASK (~(PMD_SIZE-1))
59928 -
59929 /*
59930 * The "pud_xxx()" functions here are trivial for a folded two-level
59931 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59932 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59933 index 810431d..ccc3638 100644
59934 --- a/include/asm-generic/pgtable-nopud.h
59935 +++ b/include/asm-generic/pgtable-nopud.h
59936 @@ -1,10 +1,15 @@
59937 #ifndef _PGTABLE_NOPUD_H
59938 #define _PGTABLE_NOPUD_H
59939
59940 -#ifndef __ASSEMBLY__
59941 -
59942 #define __PAGETABLE_PUD_FOLDED
59943
59944 +#define PUD_SHIFT PGDIR_SHIFT
59945 +#define PTRS_PER_PUD 1
59946 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59947 +#define PUD_MASK (~(PUD_SIZE-1))
59948 +
59949 +#ifndef __ASSEMBLY__
59950 +
59951 /*
59952 * Having the pud type consist of a pgd gets the size right, and allows
59953 * us to conceptually access the pgd entry that this pud is folded into
59954 @@ -12,11 +17,6 @@
59955 */
59956 typedef struct { pgd_t pgd; } pud_t;
59957
59958 -#define PUD_SHIFT PGDIR_SHIFT
59959 -#define PTRS_PER_PUD 1
59960 -#define PUD_SIZE (1UL << PUD_SHIFT)
59961 -#define PUD_MASK (~(PUD_SIZE-1))
59962 -
59963 /*
59964 * The "pgd_xxx()" functions here are trivial for a folded two-level
59965 * setup: the pud is never bad, and a pud always exists (as it's folded
59966 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59967 index a03c098..9624b83 100644
59968 --- a/include/asm-generic/pgtable.h
59969 +++ b/include/asm-generic/pgtable.h
59970 @@ -504,6 +504,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59971
59972 #endif /* CONFIG_MMU */
59973
59974 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59975 +static inline unsigned long pax_open_kernel(void) { return 0; }
59976 +#endif
59977 +
59978 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59979 +static inline unsigned long pax_close_kernel(void) { return 0; }
59980 +#endif
59981 +
59982 #endif /* !__ASSEMBLY__ */
59983
59984 #endif /* _ASM_GENERIC_PGTABLE_H */
59985 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
59986 index 9788568..510dece 100644
59987 --- a/include/asm-generic/uaccess.h
59988 +++ b/include/asm-generic/uaccess.h
59989 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
59990 */
59991 #ifndef __copy_from_user
59992 static inline __must_check long __copy_from_user(void *to,
59993 + const void __user * from, unsigned long n) __size_overflow(3);
59994 +static inline __must_check long __copy_from_user(void *to,
59995 const void __user * from, unsigned long n)
59996 {
59997 if (__builtin_constant_p(n)) {
59998 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
59999
60000 #ifndef __copy_to_user
60001 static inline __must_check long __copy_to_user(void __user *to,
60002 + const void *from, unsigned long n) __size_overflow(3);
60003 +static inline __must_check long __copy_to_user(void __user *to,
60004 const void *from, unsigned long n)
60005 {
60006 if (__builtin_constant_p(n)) {
60007 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60008 -EFAULT; \
60009 })
60010
60011 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60012 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60013 {
60014 size = __copy_from_user(x, ptr, size);
60015 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60016 #define __copy_to_user_inatomic __copy_to_user
60017 #endif
60018
60019 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60020 static inline long copy_from_user(void *to,
60021 const void __user * from, unsigned long n)
60022 {
60023 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60024 return n;
60025 }
60026
60027 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60028 static inline long copy_to_user(void __user *to,
60029 const void *from, unsigned long n)
60030 {
60031 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
60032 */
60033 #ifndef __clear_user
60034 static inline __must_check unsigned long
60035 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60036 +static inline __must_check unsigned long
60037 __clear_user(void __user *to, unsigned long n)
60038 {
60039 memset((void __force *)to, 0, n);
60040 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
60041 #endif
60042
60043 static inline __must_check unsigned long
60044 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60045 +static inline __must_check unsigned long
60046 clear_user(void __user *to, unsigned long n)
60047 {
60048 might_sleep();
60049 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60050 index b5e2e4c..6a5373e 100644
60051 --- a/include/asm-generic/vmlinux.lds.h
60052 +++ b/include/asm-generic/vmlinux.lds.h
60053 @@ -217,6 +217,7 @@
60054 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60055 VMLINUX_SYMBOL(__start_rodata) = .; \
60056 *(.rodata) *(.rodata.*) \
60057 + *(.data..read_only) \
60058 *(__vermagic) /* Kernel version magic */ \
60059 . = ALIGN(8); \
60060 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60061 @@ -722,17 +723,18 @@
60062 * section in the linker script will go there too. @phdr should have
60063 * a leading colon.
60064 *
60065 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60066 + * Note that this macros defines per_cpu_load as an absolute symbol.
60067 * If there is no need to put the percpu section at a predetermined
60068 * address, use PERCPU_SECTION.
60069 */
60070 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60071 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60072 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60073 + per_cpu_load = .; \
60074 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60075 - LOAD_OFFSET) { \
60076 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60077 PERCPU_INPUT(cacheline) \
60078 } phdr \
60079 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60080 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60081
60082 /**
60083 * PERCPU_SECTION - define output section for percpu area, simple version
60084 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60085 index 92f0981..d44a37c 100644
60086 --- a/include/drm/drmP.h
60087 +++ b/include/drm/drmP.h
60088 @@ -72,6 +72,7 @@
60089 #include <linux/workqueue.h>
60090 #include <linux/poll.h>
60091 #include <asm/pgalloc.h>
60092 +#include <asm/local.h>
60093 #include "drm.h"
60094
60095 #include <linux/idr.h>
60096 @@ -1038,7 +1039,7 @@ struct drm_device {
60097
60098 /** \name Usage Counters */
60099 /*@{ */
60100 - int open_count; /**< Outstanding files open */
60101 + local_t open_count; /**< Outstanding files open */
60102 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60103 atomic_t vma_count; /**< Outstanding vma areas open */
60104 int buf_use; /**< Buffers in use -- cannot alloc */
60105 @@ -1049,7 +1050,7 @@ struct drm_device {
60106 /*@{ */
60107 unsigned long counters;
60108 enum drm_stat_type types[15];
60109 - atomic_t counts[15];
60110 + atomic_unchecked_t counts[15];
60111 /*@} */
60112
60113 struct list_head filelist;
60114 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60115 index 37515d1..34fa8b0 100644
60116 --- a/include/drm/drm_crtc_helper.h
60117 +++ b/include/drm/drm_crtc_helper.h
60118 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60119
60120 /* disable crtc when not in use - more explicit than dpms off */
60121 void (*disable)(struct drm_crtc *crtc);
60122 -};
60123 +} __no_const;
60124
60125 struct drm_encoder_helper_funcs {
60126 void (*dpms)(struct drm_encoder *encoder, int mode);
60127 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60128 struct drm_connector *connector);
60129 /* disable encoder when not in use - more explicit than dpms off */
60130 void (*disable)(struct drm_encoder *encoder);
60131 -};
60132 +} __no_const;
60133
60134 struct drm_connector_helper_funcs {
60135 int (*get_modes)(struct drm_connector *connector);
60136 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60137 index 26c1f78..6722682 100644
60138 --- a/include/drm/ttm/ttm_memory.h
60139 +++ b/include/drm/ttm/ttm_memory.h
60140 @@ -47,7 +47,7 @@
60141
60142 struct ttm_mem_shrink {
60143 int (*do_shrink) (struct ttm_mem_shrink *);
60144 -};
60145 +} __no_const;
60146
60147 /**
60148 * struct ttm_mem_global - Global memory accounting structure.
60149 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60150 index e86dfca..40cc55f 100644
60151 --- a/include/linux/a.out.h
60152 +++ b/include/linux/a.out.h
60153 @@ -39,6 +39,14 @@ enum machine_type {
60154 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60155 };
60156
60157 +/* Constants for the N_FLAGS field */
60158 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60159 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60160 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60161 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60162 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60163 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60164 +
60165 #if !defined (N_MAGIC)
60166 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60167 #endif
60168 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60169 index f4ff882..84b53a6 100644
60170 --- a/include/linux/atmdev.h
60171 +++ b/include/linux/atmdev.h
60172 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60173 #endif
60174
60175 struct k_atm_aal_stats {
60176 -#define __HANDLE_ITEM(i) atomic_t i
60177 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60178 __AAL_STAT_ITEMS
60179 #undef __HANDLE_ITEM
60180 };
60181 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60182 index 0092102..8a801b4 100644
60183 --- a/include/linux/binfmts.h
60184 +++ b/include/linux/binfmts.h
60185 @@ -89,6 +89,7 @@ struct linux_binfmt {
60186 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60187 int (*load_shlib)(struct file *);
60188 int (*core_dump)(struct coredump_params *cprm);
60189 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60190 unsigned long min_coredump; /* minimal dump size */
60191 };
60192
60193 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60194 index 606cf33..b72c577 100644
60195 --- a/include/linux/blkdev.h
60196 +++ b/include/linux/blkdev.h
60197 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60198 /* this callback is with swap_lock and sometimes page table lock held */
60199 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60200 struct module *owner;
60201 -};
60202 +} __do_const;
60203
60204 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60205 unsigned long);
60206 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60207 index 4d1a074..88f929a 100644
60208 --- a/include/linux/blktrace_api.h
60209 +++ b/include/linux/blktrace_api.h
60210 @@ -162,7 +162,7 @@ struct blk_trace {
60211 struct dentry *dir;
60212 struct dentry *dropped_file;
60213 struct dentry *msg_file;
60214 - atomic_t dropped;
60215 + atomic_unchecked_t dropped;
60216 };
60217
60218 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60219 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60220 index 83195fb..0b0f77d 100644
60221 --- a/include/linux/byteorder/little_endian.h
60222 +++ b/include/linux/byteorder/little_endian.h
60223 @@ -42,51 +42,51 @@
60224
60225 static inline __le64 __cpu_to_le64p(const __u64 *p)
60226 {
60227 - return (__force __le64)*p;
60228 + return (__force const __le64)*p;
60229 }
60230 static inline __u64 __le64_to_cpup(const __le64 *p)
60231 {
60232 - return (__force __u64)*p;
60233 + return (__force const __u64)*p;
60234 }
60235 static inline __le32 __cpu_to_le32p(const __u32 *p)
60236 {
60237 - return (__force __le32)*p;
60238 + return (__force const __le32)*p;
60239 }
60240 static inline __u32 __le32_to_cpup(const __le32 *p)
60241 {
60242 - return (__force __u32)*p;
60243 + return (__force const __u32)*p;
60244 }
60245 static inline __le16 __cpu_to_le16p(const __u16 *p)
60246 {
60247 - return (__force __le16)*p;
60248 + return (__force const __le16)*p;
60249 }
60250 static inline __u16 __le16_to_cpup(const __le16 *p)
60251 {
60252 - return (__force __u16)*p;
60253 + return (__force const __u16)*p;
60254 }
60255 static inline __be64 __cpu_to_be64p(const __u64 *p)
60256 {
60257 - return (__force __be64)__swab64p(p);
60258 + return (__force const __be64)__swab64p(p);
60259 }
60260 static inline __u64 __be64_to_cpup(const __be64 *p)
60261 {
60262 - return __swab64p((__u64 *)p);
60263 + return __swab64p((const __u64 *)p);
60264 }
60265 static inline __be32 __cpu_to_be32p(const __u32 *p)
60266 {
60267 - return (__force __be32)__swab32p(p);
60268 + return (__force const __be32)__swab32p(p);
60269 }
60270 static inline __u32 __be32_to_cpup(const __be32 *p)
60271 {
60272 - return __swab32p((__u32 *)p);
60273 + return __swab32p((const __u32 *)p);
60274 }
60275 static inline __be16 __cpu_to_be16p(const __u16 *p)
60276 {
60277 - return (__force __be16)__swab16p(p);
60278 + return (__force const __be16)__swab16p(p);
60279 }
60280 static inline __u16 __be16_to_cpup(const __be16 *p)
60281 {
60282 - return __swab16p((__u16 *)p);
60283 + return __swab16p((const __u16 *)p);
60284 }
60285 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60286 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60287 diff --git a/include/linux/cache.h b/include/linux/cache.h
60288 index 4c57065..4307975 100644
60289 --- a/include/linux/cache.h
60290 +++ b/include/linux/cache.h
60291 @@ -16,6 +16,10 @@
60292 #define __read_mostly
60293 #endif
60294
60295 +#ifndef __read_only
60296 +#define __read_only __read_mostly
60297 +#endif
60298 +
60299 #ifndef ____cacheline_aligned
60300 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60301 #endif
60302 diff --git a/include/linux/capability.h b/include/linux/capability.h
60303 index 12d52de..b5f7fa7 100644
60304 --- a/include/linux/capability.h
60305 +++ b/include/linux/capability.h
60306 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60307 extern bool capable(int cap);
60308 extern bool ns_capable(struct user_namespace *ns, int cap);
60309 extern bool nsown_capable(int cap);
60310 +extern bool capable_nolog(int cap);
60311 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60312
60313 /* audit system wants to get cap info from files as well */
60314 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60315 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60316 index 04ffb2e..6799180 100644
60317 --- a/include/linux/cleancache.h
60318 +++ b/include/linux/cleancache.h
60319 @@ -31,7 +31,7 @@ struct cleancache_ops {
60320 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60321 void (*flush_inode)(int, struct cleancache_filekey);
60322 void (*flush_fs)(int);
60323 -};
60324 +} __no_const;
60325
60326 extern struct cleancache_ops
60327 cleancache_register_ops(struct cleancache_ops *ops);
60328 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60329 index 2f40791..567b215 100644
60330 --- a/include/linux/compiler-gcc4.h
60331 +++ b/include/linux/compiler-gcc4.h
60332 @@ -32,6 +32,15 @@
60333 #define __linktime_error(message) __attribute__((__error__(message)))
60334
60335 #if __GNUC_MINOR__ >= 5
60336 +
60337 +#ifdef CONSTIFY_PLUGIN
60338 +#define __no_const __attribute__((no_const))
60339 +#define __do_const __attribute__((do_const))
60340 +#endif
60341 +
60342 +#ifdef SIZE_OVERFLOW_PLUGIN
60343 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60344 +#endif
60345 /*
60346 * Mark a position in code as unreachable. This can be used to
60347 * suppress control flow warnings after asm blocks that transfer
60348 @@ -47,6 +56,11 @@
60349 #define __noclone __attribute__((__noclone__))
60350
60351 #endif
60352 +
60353 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60354 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60355 +#define __bos0(ptr) __bos((ptr), 0)
60356 +#define __bos1(ptr) __bos((ptr), 1)
60357 #endif
60358
60359 #if __GNUC_MINOR__ > 0
60360 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60361 index 4a24354..ecaff7a 100644
60362 --- a/include/linux/compiler.h
60363 +++ b/include/linux/compiler.h
60364 @@ -5,31 +5,62 @@
60365
60366 #ifdef __CHECKER__
60367 # define __user __attribute__((noderef, address_space(1)))
60368 +# define __force_user __force __user
60369 # define __kernel __attribute__((address_space(0)))
60370 +# define __force_kernel __force __kernel
60371 # define __safe __attribute__((safe))
60372 # define __force __attribute__((force))
60373 # define __nocast __attribute__((nocast))
60374 # define __iomem __attribute__((noderef, address_space(2)))
60375 +# define __force_iomem __force __iomem
60376 # define __acquires(x) __attribute__((context(x,0,1)))
60377 # define __releases(x) __attribute__((context(x,1,0)))
60378 # define __acquire(x) __context__(x,1)
60379 # define __release(x) __context__(x,-1)
60380 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60381 # define __percpu __attribute__((noderef, address_space(3)))
60382 +# define __force_percpu __force __percpu
60383 #ifdef CONFIG_SPARSE_RCU_POINTER
60384 # define __rcu __attribute__((noderef, address_space(4)))
60385 +# define __force_rcu __force __rcu
60386 #else
60387 # define __rcu
60388 +# define __force_rcu
60389 #endif
60390 extern void __chk_user_ptr(const volatile void __user *);
60391 extern void __chk_io_ptr(const volatile void __iomem *);
60392 +#elif defined(CHECKER_PLUGIN)
60393 +//# define __user
60394 +//# define __force_user
60395 +//# define __kernel
60396 +//# define __force_kernel
60397 +# define __safe
60398 +# define __force
60399 +# define __nocast
60400 +# define __iomem
60401 +# define __force_iomem
60402 +# define __chk_user_ptr(x) (void)0
60403 +# define __chk_io_ptr(x) (void)0
60404 +# define __builtin_warning(x, y...) (1)
60405 +# define __acquires(x)
60406 +# define __releases(x)
60407 +# define __acquire(x) (void)0
60408 +# define __release(x) (void)0
60409 +# define __cond_lock(x,c) (c)
60410 +# define __percpu
60411 +# define __force_percpu
60412 +# define __rcu
60413 +# define __force_rcu
60414 #else
60415 # define __user
60416 +# define __force_user
60417 # define __kernel
60418 +# define __force_kernel
60419 # define __safe
60420 # define __force
60421 # define __nocast
60422 # define __iomem
60423 +# define __force_iomem
60424 # define __chk_user_ptr(x) (void)0
60425 # define __chk_io_ptr(x) (void)0
60426 # define __builtin_warning(x, y...) (1)
60427 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60428 # define __release(x) (void)0
60429 # define __cond_lock(x,c) (c)
60430 # define __percpu
60431 +# define __force_percpu
60432 # define __rcu
60433 +# define __force_rcu
60434 #endif
60435
60436 #ifdef __KERNEL__
60437 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60438 # define __attribute_const__ /* unimplemented */
60439 #endif
60440
60441 +#ifndef __no_const
60442 +# define __no_const
60443 +#endif
60444 +
60445 +#ifndef __do_const
60446 +# define __do_const
60447 +#endif
60448 +
60449 +#ifndef __size_overflow
60450 +# define __size_overflow(...)
60451 +#endif
60452 /*
60453 * Tell gcc if a function is cold. The compiler will assume any path
60454 * directly leading to the call is unlikely.
60455 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60456 #define __cold
60457 #endif
60458
60459 +#ifndef __alloc_size
60460 +#define __alloc_size(...)
60461 +#endif
60462 +
60463 +#ifndef __bos
60464 +#define __bos(ptr, arg)
60465 +#endif
60466 +
60467 +#ifndef __bos0
60468 +#define __bos0(ptr)
60469 +#endif
60470 +
60471 +#ifndef __bos1
60472 +#define __bos1(ptr)
60473 +#endif
60474 +
60475 /* Simple shorthand for a section definition */
60476 #ifndef __section
60477 # define __section(S) __attribute__ ((__section__(#S)))
60478 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60479 * use is to mediate communication between process-level code and irq/NMI
60480 * handlers, all running on the same CPU.
60481 */
60482 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60483 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60484 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60485
60486 #endif /* __LINUX_COMPILER_H */
60487 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60488 index e9eaec5..bfeb9bb 100644
60489 --- a/include/linux/cpuset.h
60490 +++ b/include/linux/cpuset.h
60491 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60492 * nodemask.
60493 */
60494 smp_mb();
60495 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60496 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60497 }
60498
60499 static inline void set_mems_allowed(nodemask_t nodemask)
60500 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60501 index b936763..48685ee 100644
60502 --- a/include/linux/crash_dump.h
60503 +++ b/include/linux/crash_dump.h
60504 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60505 extern unsigned long long elfcorehdr_size;
60506
60507 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60508 - unsigned long, int);
60509 + unsigned long, int) __size_overflow(3);
60510
60511 /* Architecture code defines this if there are other possible ELF
60512 * machine types, e.g. on bi-arch capable hardware. */
60513 diff --git a/include/linux/cred.h b/include/linux/cred.h
60514 index adadf71..6af5560 100644
60515 --- a/include/linux/cred.h
60516 +++ b/include/linux/cred.h
60517 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60518 static inline void validate_process_creds(void)
60519 {
60520 }
60521 +static inline void validate_task_creds(struct task_struct *task)
60522 +{
60523 +}
60524 #endif
60525
60526 /**
60527 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60528 index 8a94217..15d49e3 100644
60529 --- a/include/linux/crypto.h
60530 +++ b/include/linux/crypto.h
60531 @@ -365,7 +365,7 @@ struct cipher_tfm {
60532 const u8 *key, unsigned int keylen);
60533 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60534 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60535 -};
60536 +} __no_const;
60537
60538 struct hash_tfm {
60539 int (*init)(struct hash_desc *desc);
60540 @@ -386,13 +386,13 @@ struct compress_tfm {
60541 int (*cot_decompress)(struct crypto_tfm *tfm,
60542 const u8 *src, unsigned int slen,
60543 u8 *dst, unsigned int *dlen);
60544 -};
60545 +} __no_const;
60546
60547 struct rng_tfm {
60548 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60549 unsigned int dlen);
60550 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60551 -};
60552 +} __no_const;
60553
60554 #define crt_ablkcipher crt_u.ablkcipher
60555 #define crt_aead crt_u.aead
60556 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60557 index 7925bf0..d5143d2 100644
60558 --- a/include/linux/decompress/mm.h
60559 +++ b/include/linux/decompress/mm.h
60560 @@ -77,7 +77,7 @@ static void free(void *where)
60561 * warnings when not needed (indeed large_malloc / large_free are not
60562 * needed by inflate */
60563
60564 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60565 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60566 #define free(a) kfree(a)
60567
60568 #define large_malloc(a) vmalloc(a)
60569 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60570 index e13117c..e9fc938 100644
60571 --- a/include/linux/dma-mapping.h
60572 +++ b/include/linux/dma-mapping.h
60573 @@ -46,7 +46,7 @@ struct dma_map_ops {
60574 u64 (*get_required_mask)(struct device *dev);
60575 #endif
60576 int is_phys;
60577 -};
60578 +} __do_const;
60579
60580 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60581
60582 diff --git a/include/linux/efi.h b/include/linux/efi.h
60583 index 37c3007..92ab679 100644
60584 --- a/include/linux/efi.h
60585 +++ b/include/linux/efi.h
60586 @@ -580,7 +580,7 @@ struct efivar_operations {
60587 efi_get_variable_t *get_variable;
60588 efi_get_next_variable_t *get_next_variable;
60589 efi_set_variable_t *set_variable;
60590 -};
60591 +} __no_const;
60592
60593 struct efivars {
60594 /*
60595 diff --git a/include/linux/elf.h b/include/linux/elf.h
60596 index 999b4f5..57753b4 100644
60597 --- a/include/linux/elf.h
60598 +++ b/include/linux/elf.h
60599 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60600 #define PT_GNU_EH_FRAME 0x6474e550
60601
60602 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60603 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60604 +
60605 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60606 +
60607 +/* Constants for the e_flags field */
60608 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60609 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60610 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60611 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60612 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60613 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60614
60615 /*
60616 * Extended Numbering
60617 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60618 #define DT_DEBUG 21
60619 #define DT_TEXTREL 22
60620 #define DT_JMPREL 23
60621 +#define DT_FLAGS 30
60622 + #define DF_TEXTREL 0x00000004
60623 #define DT_ENCODING 32
60624 #define OLD_DT_LOOS 0x60000000
60625 #define DT_LOOS 0x6000000d
60626 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60627 #define PF_W 0x2
60628 #define PF_X 0x1
60629
60630 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60631 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60632 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60633 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60634 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60635 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60636 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60637 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60638 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60639 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60640 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60641 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60642 +
60643 typedef struct elf32_phdr{
60644 Elf32_Word p_type;
60645 Elf32_Off p_offset;
60646 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60647 #define EI_OSABI 7
60648 #define EI_PAD 8
60649
60650 +#define EI_PAX 14
60651 +
60652 #define ELFMAG0 0x7f /* EI_MAG */
60653 #define ELFMAG1 'E'
60654 #define ELFMAG2 'L'
60655 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60656 #define elf_note elf32_note
60657 #define elf_addr_t Elf32_Off
60658 #define Elf_Half Elf32_Half
60659 +#define elf_dyn Elf32_Dyn
60660
60661 #else
60662
60663 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60664 #define elf_note elf64_note
60665 #define elf_addr_t Elf64_Off
60666 #define Elf_Half Elf64_Half
60667 +#define elf_dyn Elf64_Dyn
60668
60669 #endif
60670
60671 diff --git a/include/linux/filter.h b/include/linux/filter.h
60672 index 8eeb205..d59bfa2 100644
60673 --- a/include/linux/filter.h
60674 +++ b/include/linux/filter.h
60675 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60676
60677 struct sk_buff;
60678 struct sock;
60679 +struct bpf_jit_work;
60680
60681 struct sk_filter
60682 {
60683 @@ -141,6 +142,9 @@ struct sk_filter
60684 unsigned int len; /* Number of filter blocks */
60685 unsigned int (*bpf_func)(const struct sk_buff *skb,
60686 const struct sock_filter *filter);
60687 +#ifdef CONFIG_BPF_JIT
60688 + struct bpf_jit_work *work;
60689 +#endif
60690 struct rcu_head rcu;
60691 struct sock_filter insns[0];
60692 };
60693 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60694 index 84ccf8e..2e9b14c 100644
60695 --- a/include/linux/firewire.h
60696 +++ b/include/linux/firewire.h
60697 @@ -428,7 +428,7 @@ struct fw_iso_context {
60698 union {
60699 fw_iso_callback_t sc;
60700 fw_iso_mc_callback_t mc;
60701 - } callback;
60702 + } __no_const callback;
60703 void *callback_data;
60704 };
60705
60706 diff --git a/include/linux/fs.h b/include/linux/fs.h
60707 index 69cd5bb..58425c2 100644
60708 --- a/include/linux/fs.h
60709 +++ b/include/linux/fs.h
60710 @@ -1623,7 +1623,8 @@ struct file_operations {
60711 int (*setlease)(struct file *, long, struct file_lock **);
60712 long (*fallocate)(struct file *file, int mode, loff_t offset,
60713 loff_t len);
60714 -};
60715 +} __do_const;
60716 +typedef struct file_operations __no_const file_operations_no_const;
60717
60718 struct inode_operations {
60719 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60720 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60721 index 003dc0f..3c4ea97 100644
60722 --- a/include/linux/fs_struct.h
60723 +++ b/include/linux/fs_struct.h
60724 @@ -6,7 +6,7 @@
60725 #include <linux/seqlock.h>
60726
60727 struct fs_struct {
60728 - int users;
60729 + atomic_t users;
60730 spinlock_t lock;
60731 seqcount_t seq;
60732 int umask;
60733 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60734 index ce31408..b1ad003 100644
60735 --- a/include/linux/fscache-cache.h
60736 +++ b/include/linux/fscache-cache.h
60737 @@ -102,7 +102,7 @@ struct fscache_operation {
60738 fscache_operation_release_t release;
60739 };
60740
60741 -extern atomic_t fscache_op_debug_id;
60742 +extern atomic_unchecked_t fscache_op_debug_id;
60743 extern void fscache_op_work_func(struct work_struct *work);
60744
60745 extern void fscache_enqueue_operation(struct fscache_operation *);
60746 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60747 {
60748 INIT_WORK(&op->work, fscache_op_work_func);
60749 atomic_set(&op->usage, 1);
60750 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60751 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60752 op->processor = processor;
60753 op->release = release;
60754 INIT_LIST_HEAD(&op->pend_link);
60755 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60756 index 2a53f10..0187fdf 100644
60757 --- a/include/linux/fsnotify.h
60758 +++ b/include/linux/fsnotify.h
60759 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60760 */
60761 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60762 {
60763 - return kstrdup(name, GFP_KERNEL);
60764 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60765 }
60766
60767 /*
60768 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60769 index 91d0e0a3..035666b 100644
60770 --- a/include/linux/fsnotify_backend.h
60771 +++ b/include/linux/fsnotify_backend.h
60772 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60773 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60774 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60775 };
60776 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60777
60778 /*
60779 * A group is a "thing" that wants to receive notification about filesystem
60780 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60781 index c3da42d..c70e0df 100644
60782 --- a/include/linux/ftrace_event.h
60783 +++ b/include/linux/ftrace_event.h
60784 @@ -97,7 +97,7 @@ struct trace_event_functions {
60785 trace_print_func raw;
60786 trace_print_func hex;
60787 trace_print_func binary;
60788 -};
60789 +} __no_const;
60790
60791 struct trace_event {
60792 struct hlist_node node;
60793 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60794 extern int trace_add_event_call(struct ftrace_event_call *call);
60795 extern void trace_remove_event_call(struct ftrace_event_call *call);
60796
60797 -#define is_signed_type(type) (((type)(-1)) < 0)
60798 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60799
60800 int trace_set_clr_event(const char *system, const char *event, int set);
60801
60802 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60803 index e61d319..0da8505 100644
60804 --- a/include/linux/genhd.h
60805 +++ b/include/linux/genhd.h
60806 @@ -185,7 +185,7 @@ struct gendisk {
60807 struct kobject *slave_dir;
60808
60809 struct timer_rand_state *random;
60810 - atomic_t sync_io; /* RAID */
60811 + atomic_unchecked_t sync_io; /* RAID */
60812 struct disk_events *ev;
60813 #ifdef CONFIG_BLK_DEV_INTEGRITY
60814 struct blk_integrity *integrity;
60815 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60816 new file mode 100644
60817 index 0000000..8a130b6
60818 --- /dev/null
60819 +++ b/include/linux/gracl.h
60820 @@ -0,0 +1,319 @@
60821 +#ifndef GR_ACL_H
60822 +#define GR_ACL_H
60823 +
60824 +#include <linux/grdefs.h>
60825 +#include <linux/resource.h>
60826 +#include <linux/capability.h>
60827 +#include <linux/dcache.h>
60828 +#include <asm/resource.h>
60829 +
60830 +/* Major status information */
60831 +
60832 +#define GR_VERSION "grsecurity 2.9"
60833 +#define GRSECURITY_VERSION 0x2900
60834 +
60835 +enum {
60836 + GR_SHUTDOWN = 0,
60837 + GR_ENABLE = 1,
60838 + GR_SPROLE = 2,
60839 + GR_RELOAD = 3,
60840 + GR_SEGVMOD = 4,
60841 + GR_STATUS = 5,
60842 + GR_UNSPROLE = 6,
60843 + GR_PASSSET = 7,
60844 + GR_SPROLEPAM = 8,
60845 +};
60846 +
60847 +/* Password setup definitions
60848 + * kernel/grhash.c */
60849 +enum {
60850 + GR_PW_LEN = 128,
60851 + GR_SALT_LEN = 16,
60852 + GR_SHA_LEN = 32,
60853 +};
60854 +
60855 +enum {
60856 + GR_SPROLE_LEN = 64,
60857 +};
60858 +
60859 +enum {
60860 + GR_NO_GLOB = 0,
60861 + GR_REG_GLOB,
60862 + GR_CREATE_GLOB
60863 +};
60864 +
60865 +#define GR_NLIMITS 32
60866 +
60867 +/* Begin Data Structures */
60868 +
60869 +struct sprole_pw {
60870 + unsigned char *rolename;
60871 + unsigned char salt[GR_SALT_LEN];
60872 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60873 +};
60874 +
60875 +struct name_entry {
60876 + __u32 key;
60877 + ino_t inode;
60878 + dev_t device;
60879 + char *name;
60880 + __u16 len;
60881 + __u8 deleted;
60882 + struct name_entry *prev;
60883 + struct name_entry *next;
60884 +};
60885 +
60886 +struct inodev_entry {
60887 + struct name_entry *nentry;
60888 + struct inodev_entry *prev;
60889 + struct inodev_entry *next;
60890 +};
60891 +
60892 +struct acl_role_db {
60893 + struct acl_role_label **r_hash;
60894 + __u32 r_size;
60895 +};
60896 +
60897 +struct inodev_db {
60898 + struct inodev_entry **i_hash;
60899 + __u32 i_size;
60900 +};
60901 +
60902 +struct name_db {
60903 + struct name_entry **n_hash;
60904 + __u32 n_size;
60905 +};
60906 +
60907 +struct crash_uid {
60908 + uid_t uid;
60909 + unsigned long expires;
60910 +};
60911 +
60912 +struct gr_hash_struct {
60913 + void **table;
60914 + void **nametable;
60915 + void *first;
60916 + __u32 table_size;
60917 + __u32 used_size;
60918 + int type;
60919 +};
60920 +
60921 +/* Userspace Grsecurity ACL data structures */
60922 +
60923 +struct acl_subject_label {
60924 + char *filename;
60925 + ino_t inode;
60926 + dev_t device;
60927 + __u32 mode;
60928 + kernel_cap_t cap_mask;
60929 + kernel_cap_t cap_lower;
60930 + kernel_cap_t cap_invert_audit;
60931 +
60932 + struct rlimit res[GR_NLIMITS];
60933 + __u32 resmask;
60934 +
60935 + __u8 user_trans_type;
60936 + __u8 group_trans_type;
60937 + uid_t *user_transitions;
60938 + gid_t *group_transitions;
60939 + __u16 user_trans_num;
60940 + __u16 group_trans_num;
60941 +
60942 + __u32 sock_families[2];
60943 + __u32 ip_proto[8];
60944 + __u32 ip_type;
60945 + struct acl_ip_label **ips;
60946 + __u32 ip_num;
60947 + __u32 inaddr_any_override;
60948 +
60949 + __u32 crashes;
60950 + unsigned long expires;
60951 +
60952 + struct acl_subject_label *parent_subject;
60953 + struct gr_hash_struct *hash;
60954 + struct acl_subject_label *prev;
60955 + struct acl_subject_label *next;
60956 +
60957 + struct acl_object_label **obj_hash;
60958 + __u32 obj_hash_size;
60959 + __u16 pax_flags;
60960 +};
60961 +
60962 +struct role_allowed_ip {
60963 + __u32 addr;
60964 + __u32 netmask;
60965 +
60966 + struct role_allowed_ip *prev;
60967 + struct role_allowed_ip *next;
60968 +};
60969 +
60970 +struct role_transition {
60971 + char *rolename;
60972 +
60973 + struct role_transition *prev;
60974 + struct role_transition *next;
60975 +};
60976 +
60977 +struct acl_role_label {
60978 + char *rolename;
60979 + uid_t uidgid;
60980 + __u16 roletype;
60981 +
60982 + __u16 auth_attempts;
60983 + unsigned long expires;
60984 +
60985 + struct acl_subject_label *root_label;
60986 + struct gr_hash_struct *hash;
60987 +
60988 + struct acl_role_label *prev;
60989 + struct acl_role_label *next;
60990 +
60991 + struct role_transition *transitions;
60992 + struct role_allowed_ip *allowed_ips;
60993 + uid_t *domain_children;
60994 + __u16 domain_child_num;
60995 +
60996 + umode_t umask;
60997 +
60998 + struct acl_subject_label **subj_hash;
60999 + __u32 subj_hash_size;
61000 +};
61001 +
61002 +struct user_acl_role_db {
61003 + struct acl_role_label **r_table;
61004 + __u32 num_pointers; /* Number of allocations to track */
61005 + __u32 num_roles; /* Number of roles */
61006 + __u32 num_domain_children; /* Number of domain children */
61007 + __u32 num_subjects; /* Number of subjects */
61008 + __u32 num_objects; /* Number of objects */
61009 +};
61010 +
61011 +struct acl_object_label {
61012 + char *filename;
61013 + ino_t inode;
61014 + dev_t device;
61015 + __u32 mode;
61016 +
61017 + struct acl_subject_label *nested;
61018 + struct acl_object_label *globbed;
61019 +
61020 + /* next two structures not used */
61021 +
61022 + struct acl_object_label *prev;
61023 + struct acl_object_label *next;
61024 +};
61025 +
61026 +struct acl_ip_label {
61027 + char *iface;
61028 + __u32 addr;
61029 + __u32 netmask;
61030 + __u16 low, high;
61031 + __u8 mode;
61032 + __u32 type;
61033 + __u32 proto[8];
61034 +
61035 + /* next two structures not used */
61036 +
61037 + struct acl_ip_label *prev;
61038 + struct acl_ip_label *next;
61039 +};
61040 +
61041 +struct gr_arg {
61042 + struct user_acl_role_db role_db;
61043 + unsigned char pw[GR_PW_LEN];
61044 + unsigned char salt[GR_SALT_LEN];
61045 + unsigned char sum[GR_SHA_LEN];
61046 + unsigned char sp_role[GR_SPROLE_LEN];
61047 + struct sprole_pw *sprole_pws;
61048 + dev_t segv_device;
61049 + ino_t segv_inode;
61050 + uid_t segv_uid;
61051 + __u16 num_sprole_pws;
61052 + __u16 mode;
61053 +};
61054 +
61055 +struct gr_arg_wrapper {
61056 + struct gr_arg *arg;
61057 + __u32 version;
61058 + __u32 size;
61059 +};
61060 +
61061 +struct subject_map {
61062 + struct acl_subject_label *user;
61063 + struct acl_subject_label *kernel;
61064 + struct subject_map *prev;
61065 + struct subject_map *next;
61066 +};
61067 +
61068 +struct acl_subj_map_db {
61069 + struct subject_map **s_hash;
61070 + __u32 s_size;
61071 +};
61072 +
61073 +/* End Data Structures Section */
61074 +
61075 +/* Hash functions generated by empirical testing by Brad Spengler
61076 + Makes good use of the low bits of the inode. Generally 0-1 times
61077 + in loop for successful match. 0-3 for unsuccessful match.
61078 + Shift/add algorithm with modulus of table size and an XOR*/
61079 +
61080 +static __inline__ unsigned int
61081 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61082 +{
61083 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61084 +}
61085 +
61086 + static __inline__ unsigned int
61087 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61088 +{
61089 + return ((const unsigned long)userp % sz);
61090 +}
61091 +
61092 +static __inline__ unsigned int
61093 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61094 +{
61095 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61096 +}
61097 +
61098 +static __inline__ unsigned int
61099 +nhash(const char *name, const __u16 len, const unsigned int sz)
61100 +{
61101 + return full_name_hash((const unsigned char *)name, len) % sz;
61102 +}
61103 +
61104 +#define FOR_EACH_ROLE_START(role) \
61105 + role = role_list; \
61106 + while (role) {
61107 +
61108 +#define FOR_EACH_ROLE_END(role) \
61109 + role = role->prev; \
61110 + }
61111 +
61112 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61113 + subj = NULL; \
61114 + iter = 0; \
61115 + while (iter < role->subj_hash_size) { \
61116 + if (subj == NULL) \
61117 + subj = role->subj_hash[iter]; \
61118 + if (subj == NULL) { \
61119 + iter++; \
61120 + continue; \
61121 + }
61122 +
61123 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61124 + subj = subj->next; \
61125 + if (subj == NULL) \
61126 + iter++; \
61127 + }
61128 +
61129 +
61130 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61131 + subj = role->hash->first; \
61132 + while (subj != NULL) {
61133 +
61134 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61135 + subj = subj->next; \
61136 + }
61137 +
61138 +#endif
61139 +
61140 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61141 new file mode 100644
61142 index 0000000..323ecf2
61143 --- /dev/null
61144 +++ b/include/linux/gralloc.h
61145 @@ -0,0 +1,9 @@
61146 +#ifndef __GRALLOC_H
61147 +#define __GRALLOC_H
61148 +
61149 +void acl_free_all(void);
61150 +int acl_alloc_stack_init(unsigned long size);
61151 +void *acl_alloc(unsigned long len);
61152 +void *acl_alloc_num(unsigned long num, unsigned long len);
61153 +
61154 +#endif
61155 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61156 new file mode 100644
61157 index 0000000..b30e9bc
61158 --- /dev/null
61159 +++ b/include/linux/grdefs.h
61160 @@ -0,0 +1,140 @@
61161 +#ifndef GRDEFS_H
61162 +#define GRDEFS_H
61163 +
61164 +/* Begin grsecurity status declarations */
61165 +
61166 +enum {
61167 + GR_READY = 0x01,
61168 + GR_STATUS_INIT = 0x00 // disabled state
61169 +};
61170 +
61171 +/* Begin ACL declarations */
61172 +
61173 +/* Role flags */
61174 +
61175 +enum {
61176 + GR_ROLE_USER = 0x0001,
61177 + GR_ROLE_GROUP = 0x0002,
61178 + GR_ROLE_DEFAULT = 0x0004,
61179 + GR_ROLE_SPECIAL = 0x0008,
61180 + GR_ROLE_AUTH = 0x0010,
61181 + GR_ROLE_NOPW = 0x0020,
61182 + GR_ROLE_GOD = 0x0040,
61183 + GR_ROLE_LEARN = 0x0080,
61184 + GR_ROLE_TPE = 0x0100,
61185 + GR_ROLE_DOMAIN = 0x0200,
61186 + GR_ROLE_PAM = 0x0400,
61187 + GR_ROLE_PERSIST = 0x0800
61188 +};
61189 +
61190 +/* ACL Subject and Object mode flags */
61191 +enum {
61192 + GR_DELETED = 0x80000000
61193 +};
61194 +
61195 +/* ACL Object-only mode flags */
61196 +enum {
61197 + GR_READ = 0x00000001,
61198 + GR_APPEND = 0x00000002,
61199 + GR_WRITE = 0x00000004,
61200 + GR_EXEC = 0x00000008,
61201 + GR_FIND = 0x00000010,
61202 + GR_INHERIT = 0x00000020,
61203 + GR_SETID = 0x00000040,
61204 + GR_CREATE = 0x00000080,
61205 + GR_DELETE = 0x00000100,
61206 + GR_LINK = 0x00000200,
61207 + GR_AUDIT_READ = 0x00000400,
61208 + GR_AUDIT_APPEND = 0x00000800,
61209 + GR_AUDIT_WRITE = 0x00001000,
61210 + GR_AUDIT_EXEC = 0x00002000,
61211 + GR_AUDIT_FIND = 0x00004000,
61212 + GR_AUDIT_INHERIT= 0x00008000,
61213 + GR_AUDIT_SETID = 0x00010000,
61214 + GR_AUDIT_CREATE = 0x00020000,
61215 + GR_AUDIT_DELETE = 0x00040000,
61216 + GR_AUDIT_LINK = 0x00080000,
61217 + GR_PTRACERD = 0x00100000,
61218 + GR_NOPTRACE = 0x00200000,
61219 + GR_SUPPRESS = 0x00400000,
61220 + GR_NOLEARN = 0x00800000,
61221 + GR_INIT_TRANSFER= 0x01000000
61222 +};
61223 +
61224 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61225 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61226 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61227 +
61228 +/* ACL subject-only mode flags */
61229 +enum {
61230 + GR_KILL = 0x00000001,
61231 + GR_VIEW = 0x00000002,
61232 + GR_PROTECTED = 0x00000004,
61233 + GR_LEARN = 0x00000008,
61234 + GR_OVERRIDE = 0x00000010,
61235 + /* just a placeholder, this mode is only used in userspace */
61236 + GR_DUMMY = 0x00000020,
61237 + GR_PROTSHM = 0x00000040,
61238 + GR_KILLPROC = 0x00000080,
61239 + GR_KILLIPPROC = 0x00000100,
61240 + /* just a placeholder, this mode is only used in userspace */
61241 + GR_NOTROJAN = 0x00000200,
61242 + GR_PROTPROCFD = 0x00000400,
61243 + GR_PROCACCT = 0x00000800,
61244 + GR_RELAXPTRACE = 0x00001000,
61245 + GR_NESTED = 0x00002000,
61246 + GR_INHERITLEARN = 0x00004000,
61247 + GR_PROCFIND = 0x00008000,
61248 + GR_POVERRIDE = 0x00010000,
61249 + GR_KERNELAUTH = 0x00020000,
61250 + GR_ATSECURE = 0x00040000,
61251 + GR_SHMEXEC = 0x00080000
61252 +};
61253 +
61254 +enum {
61255 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61256 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61257 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61258 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61259 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61260 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61261 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61262 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61263 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61264 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61265 +};
61266 +
61267 +enum {
61268 + GR_ID_USER = 0x01,
61269 + GR_ID_GROUP = 0x02,
61270 +};
61271 +
61272 +enum {
61273 + GR_ID_ALLOW = 0x01,
61274 + GR_ID_DENY = 0x02,
61275 +};
61276 +
61277 +#define GR_CRASH_RES 31
61278 +#define GR_UIDTABLE_MAX 500
61279 +
61280 +/* begin resource learning section */
61281 +enum {
61282 + GR_RLIM_CPU_BUMP = 60,
61283 + GR_RLIM_FSIZE_BUMP = 50000,
61284 + GR_RLIM_DATA_BUMP = 10000,
61285 + GR_RLIM_STACK_BUMP = 1000,
61286 + GR_RLIM_CORE_BUMP = 10000,
61287 + GR_RLIM_RSS_BUMP = 500000,
61288 + GR_RLIM_NPROC_BUMP = 1,
61289 + GR_RLIM_NOFILE_BUMP = 5,
61290 + GR_RLIM_MEMLOCK_BUMP = 50000,
61291 + GR_RLIM_AS_BUMP = 500000,
61292 + GR_RLIM_LOCKS_BUMP = 2,
61293 + GR_RLIM_SIGPENDING_BUMP = 5,
61294 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61295 + GR_RLIM_NICE_BUMP = 1,
61296 + GR_RLIM_RTPRIO_BUMP = 1,
61297 + GR_RLIM_RTTIME_BUMP = 1000000
61298 +};
61299 +
61300 +#endif
61301 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61302 new file mode 100644
61303 index 0000000..da390f1
61304 --- /dev/null
61305 +++ b/include/linux/grinternal.h
61306 @@ -0,0 +1,221 @@
61307 +#ifndef __GRINTERNAL_H
61308 +#define __GRINTERNAL_H
61309 +
61310 +#ifdef CONFIG_GRKERNSEC
61311 +
61312 +#include <linux/fs.h>
61313 +#include <linux/mnt_namespace.h>
61314 +#include <linux/nsproxy.h>
61315 +#include <linux/gracl.h>
61316 +#include <linux/grdefs.h>
61317 +#include <linux/grmsg.h>
61318 +
61319 +void gr_add_learn_entry(const char *fmt, ...)
61320 + __attribute__ ((format (printf, 1, 2)));
61321 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61322 + const struct vfsmount *mnt);
61323 +__u32 gr_check_create(const struct dentry *new_dentry,
61324 + const struct dentry *parent,
61325 + const struct vfsmount *mnt, const __u32 mode);
61326 +int gr_check_protected_task(const struct task_struct *task);
61327 +__u32 to_gr_audit(const __u32 reqmode);
61328 +int gr_set_acls(const int type);
61329 +int gr_apply_subject_to_task(struct task_struct *task);
61330 +int gr_acl_is_enabled(void);
61331 +char gr_roletype_to_char(void);
61332 +
61333 +void gr_handle_alertkill(struct task_struct *task);
61334 +char *gr_to_filename(const struct dentry *dentry,
61335 + const struct vfsmount *mnt);
61336 +char *gr_to_filename1(const struct dentry *dentry,
61337 + const struct vfsmount *mnt);
61338 +char *gr_to_filename2(const struct dentry *dentry,
61339 + const struct vfsmount *mnt);
61340 +char *gr_to_filename3(const struct dentry *dentry,
61341 + const struct vfsmount *mnt);
61342 +
61343 +extern int grsec_enable_ptrace_readexec;
61344 +extern int grsec_enable_harden_ptrace;
61345 +extern int grsec_enable_link;
61346 +extern int grsec_enable_fifo;
61347 +extern int grsec_enable_execve;
61348 +extern int grsec_enable_shm;
61349 +extern int grsec_enable_execlog;
61350 +extern int grsec_enable_signal;
61351 +extern int grsec_enable_audit_ptrace;
61352 +extern int grsec_enable_forkfail;
61353 +extern int grsec_enable_time;
61354 +extern int grsec_enable_rofs;
61355 +extern int grsec_enable_chroot_shmat;
61356 +extern int grsec_enable_chroot_mount;
61357 +extern int grsec_enable_chroot_double;
61358 +extern int grsec_enable_chroot_pivot;
61359 +extern int grsec_enable_chroot_chdir;
61360 +extern int grsec_enable_chroot_chmod;
61361 +extern int grsec_enable_chroot_mknod;
61362 +extern int grsec_enable_chroot_fchdir;
61363 +extern int grsec_enable_chroot_nice;
61364 +extern int grsec_enable_chroot_execlog;
61365 +extern int grsec_enable_chroot_caps;
61366 +extern int grsec_enable_chroot_sysctl;
61367 +extern int grsec_enable_chroot_unix;
61368 +extern int grsec_enable_tpe;
61369 +extern int grsec_tpe_gid;
61370 +extern int grsec_enable_tpe_all;
61371 +extern int grsec_enable_tpe_invert;
61372 +extern int grsec_enable_socket_all;
61373 +extern int grsec_socket_all_gid;
61374 +extern int grsec_enable_socket_client;
61375 +extern int grsec_socket_client_gid;
61376 +extern int grsec_enable_socket_server;
61377 +extern int grsec_socket_server_gid;
61378 +extern int grsec_audit_gid;
61379 +extern int grsec_enable_group;
61380 +extern int grsec_enable_audit_textrel;
61381 +extern int grsec_enable_log_rwxmaps;
61382 +extern int grsec_enable_mount;
61383 +extern int grsec_enable_chdir;
61384 +extern int grsec_resource_logging;
61385 +extern int grsec_enable_blackhole;
61386 +extern int grsec_lastack_retries;
61387 +extern int grsec_enable_brute;
61388 +extern int grsec_lock;
61389 +
61390 +extern spinlock_t grsec_alert_lock;
61391 +extern unsigned long grsec_alert_wtime;
61392 +extern unsigned long grsec_alert_fyet;
61393 +
61394 +extern spinlock_t grsec_audit_lock;
61395 +
61396 +extern rwlock_t grsec_exec_file_lock;
61397 +
61398 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61399 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61400 + (tsk)->exec_file->f_vfsmnt) : "/")
61401 +
61402 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61403 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61404 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61405 +
61406 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61407 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61408 + (tsk)->exec_file->f_vfsmnt) : "/")
61409 +
61410 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61411 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61412 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61413 +
61414 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61415 +
61416 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61417 +
61418 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61419 + (task)->pid, (cred)->uid, \
61420 + (cred)->euid, (cred)->gid, (cred)->egid, \
61421 + gr_parent_task_fullpath(task), \
61422 + (task)->real_parent->comm, (task)->real_parent->pid, \
61423 + (pcred)->uid, (pcred)->euid, \
61424 + (pcred)->gid, (pcred)->egid
61425 +
61426 +#define GR_CHROOT_CAPS {{ \
61427 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61428 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61429 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61430 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61431 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61432 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61433 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61434 +
61435 +#define security_learn(normal_msg,args...) \
61436 +({ \
61437 + read_lock(&grsec_exec_file_lock); \
61438 + gr_add_learn_entry(normal_msg "\n", ## args); \
61439 + read_unlock(&grsec_exec_file_lock); \
61440 +})
61441 +
61442 +enum {
61443 + GR_DO_AUDIT,
61444 + GR_DONT_AUDIT,
61445 + /* used for non-audit messages that we shouldn't kill the task on */
61446 + GR_DONT_AUDIT_GOOD
61447 +};
61448 +
61449 +enum {
61450 + GR_TTYSNIFF,
61451 + GR_RBAC,
61452 + GR_RBAC_STR,
61453 + GR_STR_RBAC,
61454 + GR_RBAC_MODE2,
61455 + GR_RBAC_MODE3,
61456 + GR_FILENAME,
61457 + GR_SYSCTL_HIDDEN,
61458 + GR_NOARGS,
61459 + GR_ONE_INT,
61460 + GR_ONE_INT_TWO_STR,
61461 + GR_ONE_STR,
61462 + GR_STR_INT,
61463 + GR_TWO_STR_INT,
61464 + GR_TWO_INT,
61465 + GR_TWO_U64,
61466 + GR_THREE_INT,
61467 + GR_FIVE_INT_TWO_STR,
61468 + GR_TWO_STR,
61469 + GR_THREE_STR,
61470 + GR_FOUR_STR,
61471 + GR_STR_FILENAME,
61472 + GR_FILENAME_STR,
61473 + GR_FILENAME_TWO_INT,
61474 + GR_FILENAME_TWO_INT_STR,
61475 + GR_TEXTREL,
61476 + GR_PTRACE,
61477 + GR_RESOURCE,
61478 + GR_CAP,
61479 + GR_SIG,
61480 + GR_SIG2,
61481 + GR_CRASH1,
61482 + GR_CRASH2,
61483 + GR_PSACCT,
61484 + GR_RWXMAP
61485 +};
61486 +
61487 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61488 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61489 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61490 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61491 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61492 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61493 +#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)
61494 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61495 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61496 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61497 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61498 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61499 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61500 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61501 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61502 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61503 +#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)
61504 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61505 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61506 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61507 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61508 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61509 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61510 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61511 +#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)
61512 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61513 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61514 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61515 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61516 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61517 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61518 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61519 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61520 +#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)
61521 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61522 +
61523 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61524 +
61525 +#endif
61526 +
61527 +#endif
61528 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61529 new file mode 100644
61530 index 0000000..ae576a1
61531 --- /dev/null
61532 +++ b/include/linux/grmsg.h
61533 @@ -0,0 +1,109 @@
61534 +#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"
61535 +#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"
61536 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61537 +#define GR_STOPMOD_MSG "denied modification of module state by "
61538 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61539 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61540 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61541 +#define GR_IOPL_MSG "denied use of iopl() by "
61542 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61543 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61544 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61545 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61546 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61547 +#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"
61548 +#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"
61549 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61550 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61551 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61552 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61553 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61554 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61555 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61556 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61557 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61558 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61559 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61560 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61561 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61562 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61563 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61564 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61565 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61566 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61567 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61568 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61569 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61570 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61571 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61572 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61573 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61574 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61575 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61576 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61577 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61578 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61579 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61580 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61581 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61582 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61583 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61584 +#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"
61585 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61586 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61587 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61588 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61589 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61590 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61591 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61592 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61593 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61594 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61595 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61596 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61597 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61598 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61599 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61600 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61601 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61602 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61603 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61604 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61605 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61606 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61607 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61608 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61609 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61610 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61611 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61612 +#define GR_TIME_MSG "time set by "
61613 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61614 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61615 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61616 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61617 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61618 +#define GR_BIND_MSG "denied bind() by "
61619 +#define GR_CONNECT_MSG "denied connect() by "
61620 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61621 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61622 +#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"
61623 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61624 +#define GR_CAP_ACL_MSG "use of %s denied for "
61625 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61626 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61627 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61628 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61629 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61630 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61631 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61632 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61633 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61634 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61635 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61636 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61637 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61638 +#define GR_VM86_MSG "denied use of vm86 by "
61639 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61640 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61641 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61642 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61643 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61644 new file mode 100644
61645 index 0000000..acd05db
61646 --- /dev/null
61647 +++ b/include/linux/grsecurity.h
61648 @@ -0,0 +1,232 @@
61649 +#ifndef GR_SECURITY_H
61650 +#define GR_SECURITY_H
61651 +#include <linux/fs.h>
61652 +#include <linux/fs_struct.h>
61653 +#include <linux/binfmts.h>
61654 +#include <linux/gracl.h>
61655 +
61656 +/* notify of brain-dead configs */
61657 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61658 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61659 +#endif
61660 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61661 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61662 +#endif
61663 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61664 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61665 +#endif
61666 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61667 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61668 +#endif
61669 +
61670 +#include <linux/compat.h>
61671 +
61672 +struct user_arg_ptr {
61673 +#ifdef CONFIG_COMPAT
61674 + bool is_compat;
61675 +#endif
61676 + union {
61677 + const char __user *const __user *native;
61678 +#ifdef CONFIG_COMPAT
61679 + compat_uptr_t __user *compat;
61680 +#endif
61681 + } ptr;
61682 +};
61683 +
61684 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61685 +void gr_handle_brute_check(void);
61686 +void gr_handle_kernel_exploit(void);
61687 +int gr_process_user_ban(void);
61688 +
61689 +char gr_roletype_to_char(void);
61690 +
61691 +int gr_acl_enable_at_secure(void);
61692 +
61693 +int gr_check_user_change(int real, int effective, int fs);
61694 +int gr_check_group_change(int real, int effective, int fs);
61695 +
61696 +void gr_del_task_from_ip_table(struct task_struct *p);
61697 +
61698 +int gr_pid_is_chrooted(struct task_struct *p);
61699 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61700 +int gr_handle_chroot_nice(void);
61701 +int gr_handle_chroot_sysctl(const int op);
61702 +int gr_handle_chroot_setpriority(struct task_struct *p,
61703 + const int niceval);
61704 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61705 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61706 + const struct vfsmount *mnt);
61707 +void gr_handle_chroot_chdir(struct path *path);
61708 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61709 + const struct vfsmount *mnt, const int mode);
61710 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61711 + const struct vfsmount *mnt, const int mode);
61712 +int gr_handle_chroot_mount(const struct dentry *dentry,
61713 + const struct vfsmount *mnt,
61714 + const char *dev_name);
61715 +int gr_handle_chroot_pivot(void);
61716 +int gr_handle_chroot_unix(const pid_t pid);
61717 +
61718 +int gr_handle_rawio(const struct inode *inode);
61719 +
61720 +void gr_handle_ioperm(void);
61721 +void gr_handle_iopl(void);
61722 +
61723 +umode_t gr_acl_umask(void);
61724 +
61725 +int gr_tpe_allow(const struct file *file);
61726 +
61727 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61728 +void gr_clear_chroot_entries(struct task_struct *task);
61729 +
61730 +void gr_log_forkfail(const int retval);
61731 +void gr_log_timechange(void);
61732 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61733 +void gr_log_chdir(const struct dentry *dentry,
61734 + const struct vfsmount *mnt);
61735 +void gr_log_chroot_exec(const struct dentry *dentry,
61736 + const struct vfsmount *mnt);
61737 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61738 +void gr_log_remount(const char *devname, const int retval);
61739 +void gr_log_unmount(const char *devname, const int retval);
61740 +void gr_log_mount(const char *from, const char *to, const int retval);
61741 +void gr_log_textrel(struct vm_area_struct *vma);
61742 +void gr_log_rwxmmap(struct file *file);
61743 +void gr_log_rwxmprotect(struct file *file);
61744 +
61745 +int gr_handle_follow_link(const struct inode *parent,
61746 + const struct inode *inode,
61747 + const struct dentry *dentry,
61748 + const struct vfsmount *mnt);
61749 +int gr_handle_fifo(const struct dentry *dentry,
61750 + const struct vfsmount *mnt,
61751 + const struct dentry *dir, const int flag,
61752 + const int acc_mode);
61753 +int gr_handle_hardlink(const struct dentry *dentry,
61754 + const struct vfsmount *mnt,
61755 + struct inode *inode,
61756 + const int mode, const char *to);
61757 +
61758 +int gr_is_capable(const int cap);
61759 +int gr_is_capable_nolog(const int cap);
61760 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61761 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61762 +
61763 +void gr_learn_resource(const struct task_struct *task, const int limit,
61764 + const unsigned long wanted, const int gt);
61765 +void gr_copy_label(struct task_struct *tsk);
61766 +void gr_handle_crash(struct task_struct *task, const int sig);
61767 +int gr_handle_signal(const struct task_struct *p, const int sig);
61768 +int gr_check_crash_uid(const uid_t uid);
61769 +int gr_check_protected_task(const struct task_struct *task);
61770 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61771 +int gr_acl_handle_mmap(const struct file *file,
61772 + const unsigned long prot);
61773 +int gr_acl_handle_mprotect(const struct file *file,
61774 + const unsigned long prot);
61775 +int gr_check_hidden_task(const struct task_struct *tsk);
61776 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61777 + const struct vfsmount *mnt);
61778 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61779 + const struct vfsmount *mnt);
61780 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61781 + const struct vfsmount *mnt, const int fmode);
61782 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61783 + const struct vfsmount *mnt, umode_t *mode);
61784 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61785 + const struct vfsmount *mnt);
61786 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61787 + const struct vfsmount *mnt);
61788 +int gr_handle_ptrace(struct task_struct *task, const long request);
61789 +int gr_handle_proc_ptrace(struct task_struct *task);
61790 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61791 + const struct vfsmount *mnt);
61792 +int gr_check_crash_exec(const struct file *filp);
61793 +int gr_acl_is_enabled(void);
61794 +void gr_set_kernel_label(struct task_struct *task);
61795 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61796 + const gid_t gid);
61797 +int gr_set_proc_label(const struct dentry *dentry,
61798 + const struct vfsmount *mnt,
61799 + const int unsafe_flags);
61800 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61801 + const struct vfsmount *mnt);
61802 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61803 + const struct vfsmount *mnt, int acc_mode);
61804 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61805 + const struct dentry *p_dentry,
61806 + const struct vfsmount *p_mnt,
61807 + int open_flags, int acc_mode, const int imode);
61808 +void gr_handle_create(const struct dentry *dentry,
61809 + const struct vfsmount *mnt);
61810 +void gr_handle_proc_create(const struct dentry *dentry,
61811 + const struct inode *inode);
61812 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61813 + const struct dentry *parent_dentry,
61814 + const struct vfsmount *parent_mnt,
61815 + const int mode);
61816 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61817 + const struct dentry *parent_dentry,
61818 + const struct vfsmount *parent_mnt);
61819 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61820 + const struct vfsmount *mnt);
61821 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61822 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61823 + const struct vfsmount *mnt);
61824 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61825 + const struct dentry *parent_dentry,
61826 + const struct vfsmount *parent_mnt,
61827 + const char *from);
61828 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61829 + const struct dentry *parent_dentry,
61830 + const struct vfsmount *parent_mnt,
61831 + const struct dentry *old_dentry,
61832 + const struct vfsmount *old_mnt, const char *to);
61833 +int gr_acl_handle_rename(struct dentry *new_dentry,
61834 + struct dentry *parent_dentry,
61835 + const struct vfsmount *parent_mnt,
61836 + struct dentry *old_dentry,
61837 + struct inode *old_parent_inode,
61838 + struct vfsmount *old_mnt, const char *newname);
61839 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61840 + struct dentry *old_dentry,
61841 + struct dentry *new_dentry,
61842 + struct vfsmount *mnt, const __u8 replace);
61843 +__u32 gr_check_link(const struct dentry *new_dentry,
61844 + const struct dentry *parent_dentry,
61845 + const struct vfsmount *parent_mnt,
61846 + const struct dentry *old_dentry,
61847 + const struct vfsmount *old_mnt);
61848 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61849 + const unsigned int namelen, const ino_t ino);
61850 +
61851 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61852 + const struct vfsmount *mnt);
61853 +void gr_acl_handle_exit(void);
61854 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61855 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61856 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61857 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61858 +void gr_audit_ptrace(struct task_struct *task);
61859 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61860 +
61861 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61862 +
61863 +#ifdef CONFIG_GRKERNSEC
61864 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61865 +void gr_handle_vm86(void);
61866 +void gr_handle_mem_readwrite(u64 from, u64 to);
61867 +
61868 +void gr_log_badprocpid(const char *entry);
61869 +
61870 +extern int grsec_enable_dmesg;
61871 +extern int grsec_disable_privio;
61872 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61873 +extern int grsec_enable_chroot_findtask;
61874 +#endif
61875 +#ifdef CONFIG_GRKERNSEC_SETXID
61876 +extern int grsec_enable_setxid;
61877 +#endif
61878 +#endif
61879 +
61880 +#endif
61881 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61882 new file mode 100644
61883 index 0000000..e7ffaaf
61884 --- /dev/null
61885 +++ b/include/linux/grsock.h
61886 @@ -0,0 +1,19 @@
61887 +#ifndef __GRSOCK_H
61888 +#define __GRSOCK_H
61889 +
61890 +extern void gr_attach_curr_ip(const struct sock *sk);
61891 +extern int gr_handle_sock_all(const int family, const int type,
61892 + const int protocol);
61893 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61894 +extern int gr_handle_sock_server_other(const struct sock *sck);
61895 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61896 +extern int gr_search_connect(struct socket * sock,
61897 + struct sockaddr_in * addr);
61898 +extern int gr_search_bind(struct socket * sock,
61899 + struct sockaddr_in * addr);
61900 +extern int gr_search_listen(struct socket * sock);
61901 +extern int gr_search_accept(struct socket * sock);
61902 +extern int gr_search_socket(const int domain, const int type,
61903 + const int protocol);
61904 +
61905 +#endif
61906 diff --git a/include/linux/hid.h b/include/linux/hid.h
61907 index 3a95da6..51986f1 100644
61908 --- a/include/linux/hid.h
61909 +++ b/include/linux/hid.h
61910 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61911 unsigned int code, int value);
61912
61913 int (*parse)(struct hid_device *hdev);
61914 -};
61915 +} __no_const;
61916
61917 #define PM_HINT_FULLON 1<<5
61918 #define PM_HINT_NORMAL 1<<1
61919 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61920 index 3a93f73..b19d0b3 100644
61921 --- a/include/linux/highmem.h
61922 +++ b/include/linux/highmem.h
61923 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61924 kunmap_atomic(kaddr, KM_USER0);
61925 }
61926
61927 +static inline void sanitize_highpage(struct page *page)
61928 +{
61929 + void *kaddr;
61930 + unsigned long flags;
61931 +
61932 + local_irq_save(flags);
61933 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
61934 + clear_page(kaddr);
61935 + kunmap_atomic(kaddr, KM_CLEARPAGE);
61936 + local_irq_restore(flags);
61937 +}
61938 +
61939 static inline void zero_user_segments(struct page *page,
61940 unsigned start1, unsigned end1,
61941 unsigned start2, unsigned end2)
61942 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61943 index 8e25a91..551b161 100644
61944 --- a/include/linux/i2c.h
61945 +++ b/include/linux/i2c.h
61946 @@ -364,6 +364,7 @@ struct i2c_algorithm {
61947 /* To determine what the adapter supports */
61948 u32 (*functionality) (struct i2c_adapter *);
61949 };
61950 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61951
61952 /*
61953 * i2c_adapter is the structure used to identify a physical i2c bus along
61954 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61955 index a6deef4..c56a7f2 100644
61956 --- a/include/linux/i2o.h
61957 +++ b/include/linux/i2o.h
61958 @@ -564,7 +564,7 @@ struct i2o_controller {
61959 struct i2o_device *exec; /* Executive */
61960 #if BITS_PER_LONG == 64
61961 spinlock_t context_list_lock; /* lock for context_list */
61962 - atomic_t context_list_counter; /* needed for unique contexts */
61963 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61964 struct list_head context_list; /* list of context id's
61965 and pointers */
61966 #endif
61967 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61968 index 58404b0..439ed95 100644
61969 --- a/include/linux/if_team.h
61970 +++ b/include/linux/if_team.h
61971 @@ -64,6 +64,7 @@ struct team_mode_ops {
61972 void (*port_leave)(struct team *team, struct team_port *port);
61973 void (*port_change_mac)(struct team *team, struct team_port *port);
61974 };
61975 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61976
61977 enum team_option_type {
61978 TEAM_OPTION_TYPE_U32,
61979 @@ -112,7 +113,7 @@ struct team {
61980 struct list_head option_list;
61981
61982 const struct team_mode *mode;
61983 - struct team_mode_ops ops;
61984 + team_mode_ops_no_const ops;
61985 long mode_priv[TEAM_MODE_PRIV_LONGS];
61986 };
61987
61988 diff --git a/include/linux/init.h b/include/linux/init.h
61989 index 6b95109..4aca62c 100644
61990 --- a/include/linux/init.h
61991 +++ b/include/linux/init.h
61992 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61993
61994 /* Each module must use one module_init(). */
61995 #define module_init(initfn) \
61996 - static inline initcall_t __inittest(void) \
61997 + static inline __used initcall_t __inittest(void) \
61998 { return initfn; } \
61999 int init_module(void) __attribute__((alias(#initfn)));
62000
62001 /* This is only required if you want to be unloadable. */
62002 #define module_exit(exitfn) \
62003 - static inline exitcall_t __exittest(void) \
62004 + static inline __used exitcall_t __exittest(void) \
62005 { return exitfn; } \
62006 void cleanup_module(void) __attribute__((alias(#exitfn)));
62007
62008 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62009 index 9c66b1a..a3fdded 100644
62010 --- a/include/linux/init_task.h
62011 +++ b/include/linux/init_task.h
62012 @@ -127,6 +127,12 @@ extern struct cred init_cred;
62013
62014 #define INIT_TASK_COMM "swapper"
62015
62016 +#ifdef CONFIG_X86
62017 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62018 +#else
62019 +#define INIT_TASK_THREAD_INFO
62020 +#endif
62021 +
62022 /*
62023 * INIT_TASK is used to set up the first task table, touch at
62024 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62025 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62026 RCU_INIT_POINTER(.cred, &init_cred), \
62027 .comm = INIT_TASK_COMM, \
62028 .thread = INIT_THREAD, \
62029 + INIT_TASK_THREAD_INFO \
62030 .fs = &init_fs, \
62031 .files = &init_files, \
62032 .signal = &init_signals, \
62033 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62034 index e6ca56d..8583707 100644
62035 --- a/include/linux/intel-iommu.h
62036 +++ b/include/linux/intel-iommu.h
62037 @@ -296,7 +296,7 @@ struct iommu_flush {
62038 u8 fm, u64 type);
62039 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62040 unsigned int size_order, u64 type);
62041 -};
62042 +} __no_const;
62043
62044 enum {
62045 SR_DMAR_FECTL_REG,
62046 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62047 index a64b00e..464d8bc 100644
62048 --- a/include/linux/interrupt.h
62049 +++ b/include/linux/interrupt.h
62050 @@ -441,7 +441,7 @@ enum
62051 /* map softirq index to softirq name. update 'softirq_to_name' in
62052 * kernel/softirq.c when adding a new softirq.
62053 */
62054 -extern char *softirq_to_name[NR_SOFTIRQS];
62055 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62056
62057 /* softirq mask and active fields moved to irq_cpustat_t in
62058 * asm/hardirq.h to get better cache usage. KAO
62059 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62060
62061 struct softirq_action
62062 {
62063 - void (*action)(struct softirq_action *);
62064 + void (*action)(void);
62065 };
62066
62067 asmlinkage void do_softirq(void);
62068 asmlinkage void __do_softirq(void);
62069 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62070 +extern void open_softirq(int nr, void (*action)(void));
62071 extern void softirq_init(void);
62072 static inline void __raise_softirq_irqoff(unsigned int nr)
62073 {
62074 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62075 index 3875719..4cd454c 100644
62076 --- a/include/linux/kallsyms.h
62077 +++ b/include/linux/kallsyms.h
62078 @@ -15,7 +15,8 @@
62079
62080 struct module;
62081
62082 -#ifdef CONFIG_KALLSYMS
62083 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62084 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62085 /* Lookup the address for a symbol. Returns 0 if not found. */
62086 unsigned long kallsyms_lookup_name(const char *name);
62087
62088 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62089 /* Stupid that this does nothing, but I didn't create this mess. */
62090 #define __print_symbol(fmt, addr)
62091 #endif /*CONFIG_KALLSYMS*/
62092 +#else /* when included by kallsyms.c, vsnprintf.c, or
62093 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62094 +extern void __print_symbol(const char *fmt, unsigned long address);
62095 +extern int sprint_backtrace(char *buffer, unsigned long address);
62096 +extern int sprint_symbol(char *buffer, unsigned long address);
62097 +const char *kallsyms_lookup(unsigned long addr,
62098 + unsigned long *symbolsize,
62099 + unsigned long *offset,
62100 + char **modname, char *namebuf);
62101 +#endif
62102
62103 /* This macro allows us to keep printk typechecking */
62104 static __printf(1, 2)
62105 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62106 index fa39183..40160be 100644
62107 --- a/include/linux/kgdb.h
62108 +++ b/include/linux/kgdb.h
62109 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62110 extern int kgdb_io_module_registered;
62111
62112 extern atomic_t kgdb_setting_breakpoint;
62113 -extern atomic_t kgdb_cpu_doing_single_step;
62114 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62115
62116 extern struct task_struct *kgdb_usethread;
62117 extern struct task_struct *kgdb_contthread;
62118 @@ -251,7 +251,7 @@ struct kgdb_arch {
62119 void (*disable_hw_break)(struct pt_regs *regs);
62120 void (*remove_all_hw_break)(void);
62121 void (*correct_hw_break)(void);
62122 -};
62123 +} __do_const;
62124
62125 /**
62126 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62127 @@ -276,7 +276,7 @@ struct kgdb_io {
62128 void (*pre_exception) (void);
62129 void (*post_exception) (void);
62130 int is_console;
62131 -};
62132 +} __do_const;
62133
62134 extern struct kgdb_arch arch_kgdb_ops;
62135
62136 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62137 index 722f477..eef2a27 100644
62138 --- a/include/linux/kmod.h
62139 +++ b/include/linux/kmod.h
62140 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62141 * usually useless though. */
62142 extern __printf(2, 3)
62143 int __request_module(bool wait, const char *name, ...);
62144 +extern __printf(3, 4)
62145 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62146 #define request_module(mod...) __request_module(true, mod)
62147 #define request_module_nowait(mod...) __request_module(false, mod)
62148 #define try_then_request_module(x, mod...) \
62149 diff --git a/include/linux/kref.h b/include/linux/kref.h
62150 index 9c07dce..a92fa71 100644
62151 --- a/include/linux/kref.h
62152 +++ b/include/linux/kref.h
62153 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62154 static inline int kref_sub(struct kref *kref, unsigned int count,
62155 void (*release)(struct kref *kref))
62156 {
62157 - WARN_ON(release == NULL);
62158 + BUG_ON(release == NULL);
62159
62160 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62161 release(kref);
62162 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62163 index 900c763..3287a0b 100644
62164 --- a/include/linux/kvm_host.h
62165 +++ b/include/linux/kvm_host.h
62166 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62167 void vcpu_load(struct kvm_vcpu *vcpu);
62168 void vcpu_put(struct kvm_vcpu *vcpu);
62169
62170 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62171 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62172 struct module *module);
62173 void kvm_exit(void);
62174
62175 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
62176 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62177 int len);
62178 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62179 - unsigned long len);
62180 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62181 + unsigned long len) __size_overflow(4);
62182 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62183 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62184 - void *data, unsigned long len);
62185 + void *data, unsigned long len) __size_overflow(4);
62186 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62187 int offset, int len);
62188 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62189 - unsigned long len);
62190 + unsigned long len) __size_overflow(2,4);
62191 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62192 - void *data, unsigned long len);
62193 + void *data, unsigned long len) __size_overflow(4);
62194 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62195 gpa_t gpa);
62196 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62197 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62198 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62199 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62200 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62201 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62202 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62203 struct kvm_guest_debug *dbg);
62204 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62205
62206 -int kvm_arch_init(void *opaque);
62207 +int kvm_arch_init(const void *opaque);
62208 void kvm_arch_exit(void);
62209
62210 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62211 @@ -721,7 +721,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62212 int kvm_set_irq_routing(struct kvm *kvm,
62213 const struct kvm_irq_routing_entry *entries,
62214 unsigned nr,
62215 - unsigned flags);
62216 + unsigned flags) __size_overflow(3);
62217 void kvm_free_irq_routing(struct kvm *kvm);
62218
62219 #else
62220 diff --git a/include/linux/libata.h b/include/linux/libata.h
62221 index cafc09a..d7e7829 100644
62222 --- a/include/linux/libata.h
62223 +++ b/include/linux/libata.h
62224 @@ -909,7 +909,7 @@ struct ata_port_operations {
62225 * fields must be pointers.
62226 */
62227 const struct ata_port_operations *inherits;
62228 -};
62229 +} __do_const;
62230
62231 struct ata_port_info {
62232 unsigned long flags;
62233 diff --git a/include/linux/mca.h b/include/linux/mca.h
62234 index 3797270..7765ede 100644
62235 --- a/include/linux/mca.h
62236 +++ b/include/linux/mca.h
62237 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62238 int region);
62239 void * (*mca_transform_memory)(struct mca_device *,
62240 void *memory);
62241 -};
62242 +} __no_const;
62243
62244 struct mca_bus {
62245 u64 default_dma_mask;
62246 diff --git a/include/linux/memory.h b/include/linux/memory.h
62247 index 1ac7f6e..a5794d0 100644
62248 --- a/include/linux/memory.h
62249 +++ b/include/linux/memory.h
62250 @@ -143,7 +143,7 @@ struct memory_accessor {
62251 size_t count);
62252 ssize_t (*write)(struct memory_accessor *, const char *buf,
62253 off_t offset, size_t count);
62254 -};
62255 +} __no_const;
62256
62257 /*
62258 * Kernel text modification mutex, used for code patching. Users of this lock
62259 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62260 index 9970337..9444122 100644
62261 --- a/include/linux/mfd/abx500.h
62262 +++ b/include/linux/mfd/abx500.h
62263 @@ -188,6 +188,7 @@ struct abx500_ops {
62264 int (*event_registers_startup_state_get) (struct device *, u8 *);
62265 int (*startup_irq_enabled) (struct device *, unsigned int);
62266 };
62267 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62268
62269 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62270 void abx500_remove_ops(struct device *dev);
62271 diff --git a/include/linux/mm.h b/include/linux/mm.h
62272 index 17b27cd..467ba2f 100644
62273 --- a/include/linux/mm.h
62274 +++ b/include/linux/mm.h
62275 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62276
62277 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62278 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62279 +
62280 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62281 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62282 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62283 +#else
62284 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62285 +#endif
62286 +
62287 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62288 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62289
62290 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62291 int set_page_dirty_lock(struct page *page);
62292 int clear_page_dirty_for_io(struct page *page);
62293
62294 -/* Is the vma a continuation of the stack vma above it? */
62295 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62296 -{
62297 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62298 -}
62299 -
62300 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62301 - unsigned long addr)
62302 -{
62303 - return (vma->vm_flags & VM_GROWSDOWN) &&
62304 - (vma->vm_start == addr) &&
62305 - !vma_growsdown(vma->vm_prev, addr);
62306 -}
62307 -
62308 -/* Is the vma a continuation of the stack vma below it? */
62309 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62310 -{
62311 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62312 -}
62313 -
62314 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62315 - unsigned long addr)
62316 -{
62317 - return (vma->vm_flags & VM_GROWSUP) &&
62318 - (vma->vm_end == addr) &&
62319 - !vma_growsup(vma->vm_next, addr);
62320 -}
62321 -
62322 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62323 unsigned long old_addr, struct vm_area_struct *new_vma,
62324 unsigned long new_addr, unsigned long len);
62325 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62326 }
62327 #endif
62328
62329 +#ifdef CONFIG_MMU
62330 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62331 +#else
62332 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62333 +{
62334 + return __pgprot(0);
62335 +}
62336 +#endif
62337 +
62338 int vma_wants_writenotify(struct vm_area_struct *vma);
62339
62340 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62341 @@ -1409,6 +1397,7 @@ out:
62342 }
62343
62344 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62345 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62346
62347 extern unsigned long do_brk(unsigned long, unsigned long);
62348
62349 @@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62350 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62351 struct vm_area_struct **pprev);
62352
62353 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62354 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62355 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62356 +
62357 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62358 NULL if none. Assume start_addr < end_addr. */
62359 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62360 @@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62361 return vma;
62362 }
62363
62364 -#ifdef CONFIG_MMU
62365 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62366 -#else
62367 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62368 -{
62369 - return __pgprot(0);
62370 -}
62371 -#endif
62372 -
62373 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62374 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62375 unsigned long pfn, unsigned long size, pgprot_t);
62376 @@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
62377 extern int sysctl_memory_failure_early_kill;
62378 extern int sysctl_memory_failure_recovery;
62379 extern void shake_page(struct page *p, int access);
62380 -extern atomic_long_t mce_bad_pages;
62381 +extern atomic_long_unchecked_t mce_bad_pages;
62382 extern int soft_offline_page(struct page *page, int flags);
62383
62384 extern void dump_page(struct page *page);
62385 @@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62386 static inline bool page_is_guard(struct page *page) { return false; }
62387 #endif /* CONFIG_DEBUG_PAGEALLOC */
62388
62389 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62390 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62391 +#else
62392 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62393 +#endif
62394 +
62395 #endif /* __KERNEL__ */
62396 #endif /* _LINUX_MM_H */
62397 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62398 index 3cc3062..efeaeb7 100644
62399 --- a/include/linux/mm_types.h
62400 +++ b/include/linux/mm_types.h
62401 @@ -252,6 +252,8 @@ struct vm_area_struct {
62402 #ifdef CONFIG_NUMA
62403 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62404 #endif
62405 +
62406 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62407 };
62408
62409 struct core_thread {
62410 @@ -326,7 +328,7 @@ struct mm_struct {
62411 unsigned long def_flags;
62412 unsigned long nr_ptes; /* Page table pages */
62413 unsigned long start_code, end_code, start_data, end_data;
62414 - unsigned long start_brk, brk, start_stack;
62415 + unsigned long brk_gap, start_brk, brk, start_stack;
62416 unsigned long arg_start, arg_end, env_start, env_end;
62417
62418 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62419 @@ -388,6 +390,24 @@ struct mm_struct {
62420 #ifdef CONFIG_CPUMASK_OFFSTACK
62421 struct cpumask cpumask_allocation;
62422 #endif
62423 +
62424 +#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)
62425 + unsigned long pax_flags;
62426 +#endif
62427 +
62428 +#ifdef CONFIG_PAX_DLRESOLVE
62429 + unsigned long call_dl_resolve;
62430 +#endif
62431 +
62432 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62433 + unsigned long call_syscall;
62434 +#endif
62435 +
62436 +#ifdef CONFIG_PAX_ASLR
62437 + unsigned long delta_mmap; /* randomized offset */
62438 + unsigned long delta_stack; /* randomized offset */
62439 +#endif
62440 +
62441 };
62442
62443 static inline void mm_init_cpumask(struct mm_struct *mm)
62444 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62445 index 1d1b1e1..2a13c78 100644
62446 --- a/include/linux/mmu_notifier.h
62447 +++ b/include/linux/mmu_notifier.h
62448 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62449 */
62450 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62451 ({ \
62452 - pte_t __pte; \
62453 + pte_t ___pte; \
62454 struct vm_area_struct *___vma = __vma; \
62455 unsigned long ___address = __address; \
62456 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62457 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62458 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62459 - __pte; \
62460 + ___pte; \
62461 })
62462
62463 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62464 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62465 index 650ba2f..af0a58c 100644
62466 --- a/include/linux/mmzone.h
62467 +++ b/include/linux/mmzone.h
62468 @@ -379,7 +379,7 @@ struct zone {
62469 unsigned long flags; /* zone flags, see below */
62470
62471 /* Zone statistics */
62472 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62473 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62474
62475 /*
62476 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62477 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62478 index 83ac071..2656e0e 100644
62479 --- a/include/linux/mod_devicetable.h
62480 +++ b/include/linux/mod_devicetable.h
62481 @@ -12,7 +12,7 @@
62482 typedef unsigned long kernel_ulong_t;
62483 #endif
62484
62485 -#define PCI_ANY_ID (~0)
62486 +#define PCI_ANY_ID ((__u16)~0)
62487
62488 struct pci_device_id {
62489 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62490 @@ -131,7 +131,7 @@ struct usb_device_id {
62491 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62492 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62493
62494 -#define HID_ANY_ID (~0)
62495 +#define HID_ANY_ID (~0U)
62496
62497 struct hid_device_id {
62498 __u16 bus;
62499 diff --git a/include/linux/module.h b/include/linux/module.h
62500 index 4598bf0..e069d7f 100644
62501 --- a/include/linux/module.h
62502 +++ b/include/linux/module.h
62503 @@ -17,6 +17,7 @@
62504 #include <linux/moduleparam.h>
62505 #include <linux/tracepoint.h>
62506 #include <linux/export.h>
62507 +#include <linux/fs.h>
62508
62509 #include <linux/percpu.h>
62510 #include <asm/module.h>
62511 @@ -275,19 +276,16 @@ struct module
62512 int (*init)(void);
62513
62514 /* If this is non-NULL, vfree after init() returns */
62515 - void *module_init;
62516 + void *module_init_rx, *module_init_rw;
62517
62518 /* Here is the actual code + data, vfree'd on unload. */
62519 - void *module_core;
62520 + void *module_core_rx, *module_core_rw;
62521
62522 /* Here are the sizes of the init and core sections */
62523 - unsigned int init_size, core_size;
62524 + unsigned int init_size_rw, core_size_rw;
62525
62526 /* The size of the executable code in each section. */
62527 - unsigned int init_text_size, core_text_size;
62528 -
62529 - /* Size of RO sections of the module (text+rodata) */
62530 - unsigned int init_ro_size, core_ro_size;
62531 + unsigned int init_size_rx, core_size_rx;
62532
62533 /* Arch-specific module values */
62534 struct mod_arch_specific arch;
62535 @@ -343,6 +341,10 @@ struct module
62536 #ifdef CONFIG_EVENT_TRACING
62537 struct ftrace_event_call **trace_events;
62538 unsigned int num_trace_events;
62539 + struct file_operations trace_id;
62540 + struct file_operations trace_enable;
62541 + struct file_operations trace_format;
62542 + struct file_operations trace_filter;
62543 #endif
62544 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62545 unsigned int num_ftrace_callsites;
62546 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62547 bool is_module_percpu_address(unsigned long addr);
62548 bool is_module_text_address(unsigned long addr);
62549
62550 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62551 +{
62552 +
62553 +#ifdef CONFIG_PAX_KERNEXEC
62554 + if (ktla_ktva(addr) >= (unsigned long)start &&
62555 + ktla_ktva(addr) < (unsigned long)start + size)
62556 + return 1;
62557 +#endif
62558 +
62559 + return ((void *)addr >= start && (void *)addr < start + size);
62560 +}
62561 +
62562 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62563 +{
62564 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62565 +}
62566 +
62567 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62568 +{
62569 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62570 +}
62571 +
62572 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62573 +{
62574 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62575 +}
62576 +
62577 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62578 +{
62579 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62580 +}
62581 +
62582 static inline int within_module_core(unsigned long addr, struct module *mod)
62583 {
62584 - return (unsigned long)mod->module_core <= addr &&
62585 - addr < (unsigned long)mod->module_core + mod->core_size;
62586 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62587 }
62588
62589 static inline int within_module_init(unsigned long addr, struct module *mod)
62590 {
62591 - return (unsigned long)mod->module_init <= addr &&
62592 - addr < (unsigned long)mod->module_init + mod->init_size;
62593 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62594 }
62595
62596 /* Search for module by name: must hold module_mutex. */
62597 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62598 index b2be02e..72d2f78 100644
62599 --- a/include/linux/moduleloader.h
62600 +++ b/include/linux/moduleloader.h
62601 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62602
62603 /* Allocator used for allocating struct module, core sections and init
62604 sections. Returns NULL on failure. */
62605 -void *module_alloc(unsigned long size);
62606 +void *module_alloc(unsigned long size) __size_overflow(1);
62607 +
62608 +#ifdef CONFIG_PAX_KERNEXEC
62609 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62610 +#else
62611 +#define module_alloc_exec(x) module_alloc(x)
62612 +#endif
62613
62614 /* Free memory returned from module_alloc. */
62615 void module_free(struct module *mod, void *module_region);
62616
62617 +#ifdef CONFIG_PAX_KERNEXEC
62618 +void module_free_exec(struct module *mod, void *module_region);
62619 +#else
62620 +#define module_free_exec(x, y) module_free((x), (y))
62621 +#endif
62622 +
62623 /* Apply the given relocation to the (simplified) ELF. Return -error
62624 or 0. */
62625 int apply_relocate(Elf_Shdr *sechdrs,
62626 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62627 index c47f4d6..23f9bdb 100644
62628 --- a/include/linux/moduleparam.h
62629 +++ b/include/linux/moduleparam.h
62630 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62631 * @len is usually just sizeof(string).
62632 */
62633 #define module_param_string(name, string, len, perm) \
62634 - static const struct kparam_string __param_string_##name \
62635 + static const struct kparam_string __param_string_##name __used \
62636 = { len, string }; \
62637 __module_param_call(MODULE_PARAM_PREFIX, name, \
62638 &param_ops_string, \
62639 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62640 */
62641 #define module_param_array_named(name, array, type, nump, perm) \
62642 param_check_##type(name, &(array)[0]); \
62643 - static const struct kparam_array __param_arr_##name \
62644 + static const struct kparam_array __param_arr_##name __used \
62645 = { .max = ARRAY_SIZE(array), .num = nump, \
62646 .ops = &param_ops_##type, \
62647 .elemsize = sizeof(array[0]), .elem = array }; \
62648 diff --git a/include/linux/namei.h b/include/linux/namei.h
62649 index ffc0213..2c1f2cb 100644
62650 --- a/include/linux/namei.h
62651 +++ b/include/linux/namei.h
62652 @@ -24,7 +24,7 @@ struct nameidata {
62653 unsigned seq;
62654 int last_type;
62655 unsigned depth;
62656 - char *saved_names[MAX_NESTED_LINKS + 1];
62657 + const char *saved_names[MAX_NESTED_LINKS + 1];
62658
62659 /* Intent data */
62660 union {
62661 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62662 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62663 extern void unlock_rename(struct dentry *, struct dentry *);
62664
62665 -static inline void nd_set_link(struct nameidata *nd, char *path)
62666 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62667 {
62668 nd->saved_names[nd->depth] = path;
62669 }
62670
62671 -static inline char *nd_get_link(struct nameidata *nd)
62672 +static inline const char *nd_get_link(const struct nameidata *nd)
62673 {
62674 return nd->saved_names[nd->depth];
62675 }
62676 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62677 index 0eac07c..a59f6a8 100644
62678 --- a/include/linux/netdevice.h
62679 +++ b/include/linux/netdevice.h
62680 @@ -1002,6 +1002,7 @@ struct net_device_ops {
62681 int (*ndo_neigh_construct)(struct neighbour *n);
62682 void (*ndo_neigh_destroy)(struct neighbour *n);
62683 };
62684 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62685
62686 /*
62687 * The DEVICE structure.
62688 @@ -1063,7 +1064,7 @@ struct net_device {
62689 int iflink;
62690
62691 struct net_device_stats stats;
62692 - atomic_long_t rx_dropped; /* dropped packets by core network
62693 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62694 * Do not use this in drivers.
62695 */
62696
62697 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62698 new file mode 100644
62699 index 0000000..33f4af8
62700 --- /dev/null
62701 +++ b/include/linux/netfilter/xt_gradm.h
62702 @@ -0,0 +1,9 @@
62703 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62704 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62705 +
62706 +struct xt_gradm_mtinfo {
62707 + __u16 flags;
62708 + __u16 invflags;
62709 +};
62710 +
62711 +#endif
62712 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62713 index c65a18a..0c05f3a 100644
62714 --- a/include/linux/of_pdt.h
62715 +++ b/include/linux/of_pdt.h
62716 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62717
62718 /* return 0 on success; fill in 'len' with number of bytes in path */
62719 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62720 -};
62721 +} __no_const;
62722
62723 extern void *prom_early_alloc(unsigned long size);
62724
62725 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62726 index a4c5624..2dabfb7 100644
62727 --- a/include/linux/oprofile.h
62728 +++ b/include/linux/oprofile.h
62729 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62730 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62731 char const * name, ulong * val);
62732
62733 -/** Create a file for read-only access to an atomic_t. */
62734 +/** Create a file for read-only access to an atomic_unchecked_t. */
62735 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62736 - char const * name, atomic_t * val);
62737 + char const * name, atomic_unchecked_t * val);
62738
62739 /** create a directory */
62740 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62741 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
62742 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
62743 * Returns 0 on success, < 0 on error.
62744 */
62745 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
62746 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
62747
62748 /** lock for read/write safety */
62749 extern raw_spinlock_t oprofilefs_lock;
62750 diff --git a/include/linux/padata.h b/include/linux/padata.h
62751 index 4633b2f..988bc08 100644
62752 --- a/include/linux/padata.h
62753 +++ b/include/linux/padata.h
62754 @@ -129,7 +129,7 @@ struct parallel_data {
62755 struct padata_instance *pinst;
62756 struct padata_parallel_queue __percpu *pqueue;
62757 struct padata_serial_queue __percpu *squeue;
62758 - atomic_t seq_nr;
62759 + atomic_unchecked_t seq_nr;
62760 atomic_t reorder_objects;
62761 atomic_t refcnt;
62762 unsigned int max_seq_nr;
62763 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62764 index abb2776..d8b8e15 100644
62765 --- a/include/linux/perf_event.h
62766 +++ b/include/linux/perf_event.h
62767 @@ -750,8 +750,8 @@ struct perf_event {
62768
62769 enum perf_event_active_state state;
62770 unsigned int attach_state;
62771 - local64_t count;
62772 - atomic64_t child_count;
62773 + local64_t count; /* PaX: fix it one day */
62774 + atomic64_unchecked_t child_count;
62775
62776 /*
62777 * These are the total time in nanoseconds that the event
62778 @@ -802,8 +802,8 @@ struct perf_event {
62779 * These accumulate total time (in nanoseconds) that children
62780 * events have been enabled and running, respectively.
62781 */
62782 - atomic64_t child_total_time_enabled;
62783 - atomic64_t child_total_time_running;
62784 + atomic64_unchecked_t child_total_time_enabled;
62785 + atomic64_unchecked_t child_total_time_running;
62786
62787 /*
62788 * Protect attach/detach and child_list:
62789 diff --git a/include/linux/personality.h b/include/linux/personality.h
62790 index 8fc7dd1a..c19d89e 100644
62791 --- a/include/linux/personality.h
62792 +++ b/include/linux/personality.h
62793 @@ -44,6 +44,7 @@ enum {
62794 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62795 ADDR_NO_RANDOMIZE | \
62796 ADDR_COMPAT_LAYOUT | \
62797 + ADDR_LIMIT_3GB | \
62798 MMAP_PAGE_ZERO)
62799
62800 /*
62801 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62802 index 77257c9..51d473a 100644
62803 --- a/include/linux/pipe_fs_i.h
62804 +++ b/include/linux/pipe_fs_i.h
62805 @@ -46,9 +46,9 @@ struct pipe_buffer {
62806 struct pipe_inode_info {
62807 wait_queue_head_t wait;
62808 unsigned int nrbufs, curbuf, buffers;
62809 - unsigned int readers;
62810 - unsigned int writers;
62811 - unsigned int waiting_writers;
62812 + atomic_t readers;
62813 + atomic_t writers;
62814 + atomic_t waiting_writers;
62815 unsigned int r_counter;
62816 unsigned int w_counter;
62817 struct page *tmp_page;
62818 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62819 index 609daae..5392427 100644
62820 --- a/include/linux/pm_runtime.h
62821 +++ b/include/linux/pm_runtime.h
62822 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62823
62824 static inline void pm_runtime_mark_last_busy(struct device *dev)
62825 {
62826 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62827 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62828 }
62829
62830 #else /* !CONFIG_PM_RUNTIME */
62831 diff --git a/include/linux/poison.h b/include/linux/poison.h
62832 index 2110a81..13a11bb 100644
62833 --- a/include/linux/poison.h
62834 +++ b/include/linux/poison.h
62835 @@ -19,8 +19,8 @@
62836 * under normal circumstances, used to verify that nobody uses
62837 * non-initialized list entries.
62838 */
62839 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62840 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62841 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62842 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62843
62844 /********** include/linux/timer.h **********/
62845 /*
62846 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62847 index 58969b2..ead129b 100644
62848 --- a/include/linux/preempt.h
62849 +++ b/include/linux/preempt.h
62850 @@ -123,7 +123,7 @@ struct preempt_ops {
62851 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62852 void (*sched_out)(struct preempt_notifier *notifier,
62853 struct task_struct *next);
62854 -};
62855 +} __no_const;
62856
62857 /**
62858 * preempt_notifier - key for installing preemption notifiers
62859 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62860 index 85c5073..51fac8b 100644
62861 --- a/include/linux/proc_fs.h
62862 +++ b/include/linux/proc_fs.h
62863 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62864 return proc_create_data(name, mode, parent, proc_fops, NULL);
62865 }
62866
62867 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62868 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62869 +{
62870 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62871 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62872 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62873 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62874 +#else
62875 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62876 +#endif
62877 +}
62878 +
62879 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62880 umode_t mode, struct proc_dir_entry *base,
62881 read_proc_t *read_proc, void * data)
62882 @@ -258,7 +270,7 @@ union proc_op {
62883 int (*proc_show)(struct seq_file *m,
62884 struct pid_namespace *ns, struct pid *pid,
62885 struct task_struct *task);
62886 -};
62887 +} __no_const;
62888
62889 struct ctl_table_header;
62890 struct ctl_table;
62891 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62892 index c2f1f6a..6fdb196 100644
62893 --- a/include/linux/ptrace.h
62894 +++ b/include/linux/ptrace.h
62895 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62896 if (unlikely(ptrace_event_enabled(current, event))) {
62897 current->ptrace_message = message;
62898 ptrace_notify((event << 8) | SIGTRAP);
62899 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62900 + } else if (event == PTRACE_EVENT_EXEC) {
62901 /* legacy EXEC report via SIGTRAP */
62902 - send_sig(SIGTRAP, current, 0);
62903 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62904 + send_sig(SIGTRAP, current, 0);
62905 }
62906 }
62907
62908 diff --git a/include/linux/random.h b/include/linux/random.h
62909 index 8f74538..02a1012 100644
62910 --- a/include/linux/random.h
62911 +++ b/include/linux/random.h
62912 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62913
62914 u32 prandom32(struct rnd_state *);
62915
62916 +static inline unsigned long pax_get_random_long(void)
62917 +{
62918 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62919 +}
62920 +
62921 /*
62922 * Handle minimum values for seeds
62923 */
62924 static inline u32 __seed(u32 x, u32 m)
62925 {
62926 - return (x < m) ? x + m : x;
62927 + return (x <= m) ? x + m + 1 : x;
62928 }
62929
62930 /**
62931 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62932 index e0879a7..a12f962 100644
62933 --- a/include/linux/reboot.h
62934 +++ b/include/linux/reboot.h
62935 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62936 * Architecture-specific implementations of sys_reboot commands.
62937 */
62938
62939 -extern void machine_restart(char *cmd);
62940 -extern void machine_halt(void);
62941 -extern void machine_power_off(void);
62942 +extern void machine_restart(char *cmd) __noreturn;
62943 +extern void machine_halt(void) __noreturn;
62944 +extern void machine_power_off(void) __noreturn;
62945
62946 extern void machine_shutdown(void);
62947 struct pt_regs;
62948 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62949 */
62950
62951 extern void kernel_restart_prepare(char *cmd);
62952 -extern void kernel_restart(char *cmd);
62953 -extern void kernel_halt(void);
62954 -extern void kernel_power_off(void);
62955 +extern void kernel_restart(char *cmd) __noreturn;
62956 +extern void kernel_halt(void) __noreturn;
62957 +extern void kernel_power_off(void) __noreturn;
62958
62959 extern int C_A_D; /* for sysctl */
62960 void ctrl_alt_del(void);
62961 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62962 * Emergency restart, callable from an interrupt handler.
62963 */
62964
62965 -extern void emergency_restart(void);
62966 +extern void emergency_restart(void) __noreturn;
62967 #include <asm/emergency-restart.h>
62968
62969 #endif
62970 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62971 index 2213ddc..650212a 100644
62972 --- a/include/linux/reiserfs_fs.h
62973 +++ b/include/linux/reiserfs_fs.h
62974 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
62975 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
62976
62977 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
62978 -#define get_generation(s) atomic_read (&fs_generation(s))
62979 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
62980 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
62981 #define __fs_changed(gen,s) (gen != get_generation (s))
62982 #define fs_changed(gen,s) \
62983 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
62984 index 8c9e85c..1698e9a 100644
62985 --- a/include/linux/reiserfs_fs_sb.h
62986 +++ b/include/linux/reiserfs_fs_sb.h
62987 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
62988 /* Comment? -Hans */
62989 wait_queue_head_t s_wait;
62990 /* To be obsoleted soon by per buffer seals.. -Hans */
62991 - atomic_t s_generation_counter; // increased by one every time the
62992 + atomic_unchecked_t s_generation_counter; // increased by one every time the
62993 // tree gets re-balanced
62994 unsigned long s_properties; /* File system properties. Currently holds
62995 on-disk FS format */
62996 diff --git a/include/linux/relay.h b/include/linux/relay.h
62997 index a822fd7..62b70f6 100644
62998 --- a/include/linux/relay.h
62999 +++ b/include/linux/relay.h
63000 @@ -159,7 +159,7 @@ struct rchan_callbacks
63001 * The callback should return 0 if successful, negative if not.
63002 */
63003 int (*remove_buf_file)(struct dentry *dentry);
63004 -};
63005 +} __no_const;
63006
63007 /*
63008 * CONFIG_RELAY kernel API, kernel/relay.c
63009 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63010 index c6c6084..5bf1212 100644
63011 --- a/include/linux/rfkill.h
63012 +++ b/include/linux/rfkill.h
63013 @@ -147,6 +147,7 @@ struct rfkill_ops {
63014 void (*query)(struct rfkill *rfkill, void *data);
63015 int (*set_block)(void *data, bool blocked);
63016 };
63017 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63018
63019 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63020 /**
63021 diff --git a/include/linux/rio.h b/include/linux/rio.h
63022 index 4d50611..c6858a2 100644
63023 --- a/include/linux/rio.h
63024 +++ b/include/linux/rio.h
63025 @@ -315,7 +315,7 @@ struct rio_ops {
63026 int mbox, void *buffer, size_t len);
63027 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63028 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63029 -};
63030 +} __no_const;
63031
63032 #define RIO_RESOURCE_MEM 0x00000100
63033 #define RIO_RESOURCE_DOORBELL 0x00000200
63034 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63035 index 1cdd62a..e399f0d 100644
63036 --- a/include/linux/rmap.h
63037 +++ b/include/linux/rmap.h
63038 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63039 void anon_vma_init(void); /* create anon_vma_cachep */
63040 int anon_vma_prepare(struct vm_area_struct *);
63041 void unlink_anon_vmas(struct vm_area_struct *);
63042 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63043 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63044 void anon_vma_moveto_tail(struct vm_area_struct *);
63045 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63046 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63047 void __anon_vma_link(struct vm_area_struct *);
63048
63049 static inline void anon_vma_merge(struct vm_area_struct *vma,
63050 diff --git a/include/linux/sched.h b/include/linux/sched.h
63051 index 0657368..765f70f 100644
63052 --- a/include/linux/sched.h
63053 +++ b/include/linux/sched.h
63054 @@ -101,6 +101,7 @@ struct bio_list;
63055 struct fs_struct;
63056 struct perf_event_context;
63057 struct blk_plug;
63058 +struct linux_binprm;
63059
63060 /*
63061 * List of flags we want to share for kernel threads,
63062 @@ -382,10 +383,13 @@ struct user_namespace;
63063 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63064
63065 extern int sysctl_max_map_count;
63066 +extern unsigned long sysctl_heap_stack_gap;
63067
63068 #include <linux/aio.h>
63069
63070 #ifdef CONFIG_MMU
63071 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63072 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63073 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63074 extern unsigned long
63075 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63076 @@ -631,6 +635,17 @@ struct signal_struct {
63077 #ifdef CONFIG_TASKSTATS
63078 struct taskstats *stats;
63079 #endif
63080 +
63081 +#ifdef CONFIG_GRKERNSEC
63082 + u32 curr_ip;
63083 + u32 saved_ip;
63084 + u32 gr_saddr;
63085 + u32 gr_daddr;
63086 + u16 gr_sport;
63087 + u16 gr_dport;
63088 + u8 used_accept:1;
63089 +#endif
63090 +
63091 #ifdef CONFIG_AUDIT
63092 unsigned audit_tty;
63093 struct tty_audit_buf *tty_audit_buf;
63094 @@ -714,6 +729,11 @@ struct user_struct {
63095 struct key *session_keyring; /* UID's default session keyring */
63096 #endif
63097
63098 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63099 + unsigned int banned;
63100 + unsigned long ban_expires;
63101 +#endif
63102 +
63103 /* Hash table maintenance information */
63104 struct hlist_node uidhash_node;
63105 uid_t uid;
63106 @@ -1354,8 +1374,8 @@ struct task_struct {
63107 struct list_head thread_group;
63108
63109 struct completion *vfork_done; /* for vfork() */
63110 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63111 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63112 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63113 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63114
63115 cputime_t utime, stime, utimescaled, stimescaled;
63116 cputime_t gtime;
63117 @@ -1371,13 +1391,6 @@ struct task_struct {
63118 struct task_cputime cputime_expires;
63119 struct list_head cpu_timers[3];
63120
63121 -/* process credentials */
63122 - const struct cred __rcu *real_cred; /* objective and real subjective task
63123 - * credentials (COW) */
63124 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63125 - * credentials (COW) */
63126 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63127 -
63128 char comm[TASK_COMM_LEN]; /* executable name excluding path
63129 - access with [gs]et_task_comm (which lock
63130 it with task_lock())
63131 @@ -1394,8 +1407,16 @@ struct task_struct {
63132 #endif
63133 /* CPU-specific state of this task */
63134 struct thread_struct thread;
63135 +/* thread_info moved to task_struct */
63136 +#ifdef CONFIG_X86
63137 + struct thread_info tinfo;
63138 +#endif
63139 /* filesystem information */
63140 struct fs_struct *fs;
63141 +
63142 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63143 + * credentials (COW) */
63144 +
63145 /* open file information */
63146 struct files_struct *files;
63147 /* namespaces */
63148 @@ -1442,6 +1463,11 @@ struct task_struct {
63149 struct rt_mutex_waiter *pi_blocked_on;
63150 #endif
63151
63152 +/* process credentials */
63153 + const struct cred __rcu *real_cred; /* objective and real subjective task
63154 + * credentials (COW) */
63155 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63156 +
63157 #ifdef CONFIG_DEBUG_MUTEXES
63158 /* mutex deadlock detection */
63159 struct mutex_waiter *blocked_on;
63160 @@ -1558,6 +1584,27 @@ struct task_struct {
63161 unsigned long default_timer_slack_ns;
63162
63163 struct list_head *scm_work_list;
63164 +
63165 +#ifdef CONFIG_GRKERNSEC
63166 + /* grsecurity */
63167 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63168 + u64 exec_id;
63169 +#endif
63170 +#ifdef CONFIG_GRKERNSEC_SETXID
63171 + const struct cred *delayed_cred;
63172 +#endif
63173 + struct dentry *gr_chroot_dentry;
63174 + struct acl_subject_label *acl;
63175 + struct acl_role_label *role;
63176 + struct file *exec_file;
63177 + u16 acl_role_id;
63178 + /* is this the task that authenticated to the special role */
63179 + u8 acl_sp_role;
63180 + u8 is_writable;
63181 + u8 brute;
63182 + u8 gr_is_chrooted;
63183 +#endif
63184 +
63185 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63186 /* Index of current stored address in ret_stack */
63187 int curr_ret_stack;
63188 @@ -1592,6 +1639,51 @@ struct task_struct {
63189 #endif
63190 };
63191
63192 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63193 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63194 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63195 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63196 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63197 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63198 +
63199 +#ifdef CONFIG_PAX_SOFTMODE
63200 +extern int pax_softmode;
63201 +#endif
63202 +
63203 +extern int pax_check_flags(unsigned long *);
63204 +
63205 +/* if tsk != current then task_lock must be held on it */
63206 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63207 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63208 +{
63209 + if (likely(tsk->mm))
63210 + return tsk->mm->pax_flags;
63211 + else
63212 + return 0UL;
63213 +}
63214 +
63215 +/* if tsk != current then task_lock must be held on it */
63216 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63217 +{
63218 + if (likely(tsk->mm)) {
63219 + tsk->mm->pax_flags = flags;
63220 + return 0;
63221 + }
63222 + return -EINVAL;
63223 +}
63224 +#endif
63225 +
63226 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63227 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63228 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63229 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63230 +#endif
63231 +
63232 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63233 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63234 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63235 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63236 +
63237 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63238 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63239
63240 @@ -2104,7 +2196,9 @@ void yield(void);
63241 extern struct exec_domain default_exec_domain;
63242
63243 union thread_union {
63244 +#ifndef CONFIG_X86
63245 struct thread_info thread_info;
63246 +#endif
63247 unsigned long stack[THREAD_SIZE/sizeof(long)];
63248 };
63249
63250 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63251 */
63252
63253 extern struct task_struct *find_task_by_vpid(pid_t nr);
63254 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63255 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63256 struct pid_namespace *ns);
63257
63258 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63259 extern void exit_itimers(struct signal_struct *);
63260 extern void flush_itimer_signals(void);
63261
63262 -extern void do_group_exit(int);
63263 +extern __noreturn void do_group_exit(int);
63264
63265 extern void daemonize(const char *, ...);
63266 extern int allow_signal(int);
63267 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63268
63269 #endif
63270
63271 -static inline int object_is_on_stack(void *obj)
63272 +static inline int object_starts_on_stack(void *obj)
63273 {
63274 - void *stack = task_stack_page(current);
63275 + const void *stack = task_stack_page(current);
63276
63277 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63278 }
63279
63280 +#ifdef CONFIG_PAX_USERCOPY
63281 +extern int object_is_on_stack(const void *obj, unsigned long len);
63282 +#endif
63283 +
63284 extern void thread_info_cache_init(void);
63285
63286 #ifdef CONFIG_DEBUG_STACK_USAGE
63287 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63288 index 899fbb4..1cb4138 100644
63289 --- a/include/linux/screen_info.h
63290 +++ b/include/linux/screen_info.h
63291 @@ -43,7 +43,8 @@ struct screen_info {
63292 __u16 pages; /* 0x32 */
63293 __u16 vesa_attributes; /* 0x34 */
63294 __u32 capabilities; /* 0x36 */
63295 - __u8 _reserved[6]; /* 0x3a */
63296 + __u16 vesapm_size; /* 0x3a */
63297 + __u8 _reserved[4]; /* 0x3c */
63298 } __attribute__((packed));
63299
63300 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63301 diff --git a/include/linux/security.h b/include/linux/security.h
63302 index 83c18e8..2d98860 100644
63303 --- a/include/linux/security.h
63304 +++ b/include/linux/security.h
63305 @@ -37,6 +37,7 @@
63306 #include <linux/xfrm.h>
63307 #include <linux/slab.h>
63308 #include <linux/xattr.h>
63309 +#include <linux/grsecurity.h>
63310 #include <net/flow.h>
63311
63312 /* Maximum number of letters for an LSM name string */
63313 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63314 index 44f1514..2bbf6c1 100644
63315 --- a/include/linux/seq_file.h
63316 +++ b/include/linux/seq_file.h
63317 @@ -24,6 +24,9 @@ struct seq_file {
63318 struct mutex lock;
63319 const struct seq_operations *op;
63320 int poll_event;
63321 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63322 + u64 exec_id;
63323 +#endif
63324 void *private;
63325 };
63326
63327 @@ -33,6 +36,7 @@ struct seq_operations {
63328 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63329 int (*show) (struct seq_file *m, void *v);
63330 };
63331 +typedef struct seq_operations __no_const seq_operations_no_const;
63332
63333 #define SEQ_SKIP 1
63334
63335 diff --git a/include/linux/shm.h b/include/linux/shm.h
63336 index 92808b8..c28cac4 100644
63337 --- a/include/linux/shm.h
63338 +++ b/include/linux/shm.h
63339 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63340
63341 /* The task created the shm object. NULL if the task is dead. */
63342 struct task_struct *shm_creator;
63343 +#ifdef CONFIG_GRKERNSEC
63344 + time_t shm_createtime;
63345 + pid_t shm_lapid;
63346 +#endif
63347 };
63348
63349 /* shm_mode upper byte flags */
63350 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63351 index ae86ade..2b51468 100644
63352 --- a/include/linux/skbuff.h
63353 +++ b/include/linux/skbuff.h
63354 @@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63355 */
63356 static inline int skb_queue_empty(const struct sk_buff_head *list)
63357 {
63358 - return list->next == (struct sk_buff *)list;
63359 + return list->next == (const struct sk_buff *)list;
63360 }
63361
63362 /**
63363 @@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63364 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63365 const struct sk_buff *skb)
63366 {
63367 - return skb->next == (struct sk_buff *)list;
63368 + return skb->next == (const struct sk_buff *)list;
63369 }
63370
63371 /**
63372 @@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63373 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63374 const struct sk_buff *skb)
63375 {
63376 - return skb->prev == (struct sk_buff *)list;
63377 + return skb->prev == (const struct sk_buff *)list;
63378 }
63379
63380 /**
63381 @@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63382 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63383 */
63384 #ifndef NET_SKB_PAD
63385 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63386 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63387 #endif
63388
63389 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63390 diff --git a/include/linux/slab.h b/include/linux/slab.h
63391 index 573c809..07e1f43 100644
63392 --- a/include/linux/slab.h
63393 +++ b/include/linux/slab.h
63394 @@ -11,12 +11,20 @@
63395
63396 #include <linux/gfp.h>
63397 #include <linux/types.h>
63398 +#include <linux/err.h>
63399
63400 /*
63401 * Flags to pass to kmem_cache_create().
63402 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63403 */
63404 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63405 +
63406 +#ifdef CONFIG_PAX_USERCOPY
63407 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63408 +#else
63409 +#define SLAB_USERCOPY 0x00000000UL
63410 +#endif
63411 +
63412 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63413 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63414 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63415 @@ -87,10 +95,13 @@
63416 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63417 * Both make kfree a no-op.
63418 */
63419 -#define ZERO_SIZE_PTR ((void *)16)
63420 +#define ZERO_SIZE_PTR \
63421 +({ \
63422 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63423 + (void *)(-MAX_ERRNO-1L); \
63424 +})
63425
63426 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63427 - (unsigned long)ZERO_SIZE_PTR)
63428 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63429
63430 /*
63431 * struct kmem_cache related prototypes
63432 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63433 /*
63434 * Common kmalloc functions provided by all allocators
63435 */
63436 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63437 -void * __must_check krealloc(const void *, size_t, gfp_t);
63438 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63439 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63440 void kfree(const void *);
63441 void kzfree(const void *);
63442 size_t ksize(const void *);
63443 +void check_object_size(const void *ptr, unsigned long n, bool to);
63444
63445 /*
63446 * Allocator specific definitions. These are mainly used to establish optimized
63447 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63448 */
63449 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63450 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63451 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63452 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63453 #define kmalloc_track_caller(size, flags) \
63454 __kmalloc_track_caller(size, flags, _RET_IP_)
63455 #else
63456 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63457 */
63458 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63459 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63460 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63461 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63462 #define kmalloc_node_track_caller(size, flags, node) \
63463 __kmalloc_node_track_caller(size, flags, node, \
63464 _RET_IP_)
63465 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63466 index fbd1117..c0bd874 100644
63467 --- a/include/linux/slab_def.h
63468 +++ b/include/linux/slab_def.h
63469 @@ -66,10 +66,10 @@ struct kmem_cache {
63470 unsigned long node_allocs;
63471 unsigned long node_frees;
63472 unsigned long node_overflow;
63473 - atomic_t allochit;
63474 - atomic_t allocmiss;
63475 - atomic_t freehit;
63476 - atomic_t freemiss;
63477 + atomic_unchecked_t allochit;
63478 + atomic_unchecked_t allocmiss;
63479 + atomic_unchecked_t freehit;
63480 + atomic_unchecked_t freemiss;
63481
63482 /*
63483 * If debugging is enabled, then the allocator can add additional
63484 @@ -107,7 +107,7 @@ struct cache_sizes {
63485 extern struct cache_sizes malloc_sizes[];
63486
63487 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63488 -void *__kmalloc(size_t size, gfp_t flags);
63489 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63490
63491 #ifdef CONFIG_TRACING
63492 extern void *kmem_cache_alloc_trace(size_t size,
63493 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63494 }
63495 #endif
63496
63497 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63498 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63499 {
63500 struct kmem_cache *cachep;
63501 @@ -160,7 +161,7 @@ found:
63502 }
63503
63504 #ifdef CONFIG_NUMA
63505 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63506 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63507 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63508
63509 #ifdef CONFIG_TRACING
63510 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
63511 }
63512 #endif
63513
63514 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63515 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63516 {
63517 struct kmem_cache *cachep;
63518 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63519 index 0ec00b3..65e7e0e 100644
63520 --- a/include/linux/slob_def.h
63521 +++ b/include/linux/slob_def.h
63522 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63523 return kmem_cache_alloc_node(cachep, flags, -1);
63524 }
63525
63526 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63527 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63528
63529 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63530 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63531 {
63532 return __kmalloc_node(size, flags, node);
63533 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63534 * kmalloc is the normal method of allocating memory
63535 * in the kernel.
63536 */
63537 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63538 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63539 {
63540 return __kmalloc_node(size, flags, -1);
63541 }
63542
63543 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63544 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63545 {
63546 return kmalloc(size, flags);
63547 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63548 index a32bcfd..d26bd6e 100644
63549 --- a/include/linux/slub_def.h
63550 +++ b/include/linux/slub_def.h
63551 @@ -89,7 +89,7 @@ struct kmem_cache {
63552 struct kmem_cache_order_objects max;
63553 struct kmem_cache_order_objects min;
63554 gfp_t allocflags; /* gfp flags to use on each alloc */
63555 - int refcount; /* Refcount for slab cache destroy */
63556 + atomic_t refcount; /* Refcount for slab cache destroy */
63557 void (*ctor)(void *);
63558 int inuse; /* Offset to metadata */
63559 int align; /* Alignment */
63560 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
63561 * This ought to end up with a global pointer to the right cache
63562 * in kmalloc_caches.
63563 */
63564 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
63565 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63566 {
63567 int index = kmalloc_index(size);
63568 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63569 }
63570
63571 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63572 -void *__kmalloc(size_t size, gfp_t flags);
63573 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63574
63575 static __always_inline void *
63576 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
63577 +static __always_inline void *
63578 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63579 {
63580 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
63581 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63582 }
63583 #endif
63584
63585 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63586 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63587 {
63588 unsigned int order = get_order(size);
63589 return kmalloc_order_trace(size, flags, order);
63590 }
63591
63592 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63593 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63594 {
63595 if (__builtin_constant_p(size)) {
63596 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63597 }
63598
63599 #ifdef CONFIG_NUMA
63600 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63601 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63602 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63603
63604 #ifdef CONFIG_TRACING
63605 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
63606 }
63607 #endif
63608
63609 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63610 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63611 {
63612 if (__builtin_constant_p(size) &&
63613 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63614 index de8832d..0147b46 100644
63615 --- a/include/linux/sonet.h
63616 +++ b/include/linux/sonet.h
63617 @@ -61,7 +61,7 @@ struct sonet_stats {
63618 #include <linux/atomic.h>
63619
63620 struct k_sonet_stats {
63621 -#define __HANDLE_ITEM(i) atomic_t i
63622 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63623 __SONET_ITEMS
63624 #undef __HANDLE_ITEM
63625 };
63626 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63627 index 2c5993a..b0e79f0 100644
63628 --- a/include/linux/sunrpc/clnt.h
63629 +++ b/include/linux/sunrpc/clnt.h
63630 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63631 {
63632 switch (sap->sa_family) {
63633 case AF_INET:
63634 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63635 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63636 case AF_INET6:
63637 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63638 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63639 }
63640 return 0;
63641 }
63642 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63643 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63644 const struct sockaddr *src)
63645 {
63646 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63647 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63648 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63649
63650 dsin->sin_family = ssin->sin_family;
63651 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63652 if (sa->sa_family != AF_INET6)
63653 return 0;
63654
63655 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63656 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63657 }
63658
63659 #endif /* __KERNEL__ */
63660 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63661 index e775689..9e206d9 100644
63662 --- a/include/linux/sunrpc/sched.h
63663 +++ b/include/linux/sunrpc/sched.h
63664 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63665 void (*rpc_call_done)(struct rpc_task *, void *);
63666 void (*rpc_release)(void *);
63667 };
63668 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63669
63670 struct rpc_task_setup {
63671 struct rpc_task *task;
63672 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63673 index c14fe86..393245e 100644
63674 --- a/include/linux/sunrpc/svc_rdma.h
63675 +++ b/include/linux/sunrpc/svc_rdma.h
63676 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63677 extern unsigned int svcrdma_max_requests;
63678 extern unsigned int svcrdma_max_req_size;
63679
63680 -extern atomic_t rdma_stat_recv;
63681 -extern atomic_t rdma_stat_read;
63682 -extern atomic_t rdma_stat_write;
63683 -extern atomic_t rdma_stat_sq_starve;
63684 -extern atomic_t rdma_stat_rq_starve;
63685 -extern atomic_t rdma_stat_rq_poll;
63686 -extern atomic_t rdma_stat_rq_prod;
63687 -extern atomic_t rdma_stat_sq_poll;
63688 -extern atomic_t rdma_stat_sq_prod;
63689 +extern atomic_unchecked_t rdma_stat_recv;
63690 +extern atomic_unchecked_t rdma_stat_read;
63691 +extern atomic_unchecked_t rdma_stat_write;
63692 +extern atomic_unchecked_t rdma_stat_sq_starve;
63693 +extern atomic_unchecked_t rdma_stat_rq_starve;
63694 +extern atomic_unchecked_t rdma_stat_rq_poll;
63695 +extern atomic_unchecked_t rdma_stat_rq_prod;
63696 +extern atomic_unchecked_t rdma_stat_sq_poll;
63697 +extern atomic_unchecked_t rdma_stat_sq_prod;
63698
63699 #define RPCRDMA_VERSION 1
63700
63701 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63702 index bb9127d..34ab358 100644
63703 --- a/include/linux/sysctl.h
63704 +++ b/include/linux/sysctl.h
63705 @@ -155,7 +155,11 @@ enum
63706 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63707 };
63708
63709 -
63710 +#ifdef CONFIG_PAX_SOFTMODE
63711 +enum {
63712 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63713 +};
63714 +#endif
63715
63716 /* CTL_VM names: */
63717 enum
63718 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63719
63720 extern int proc_dostring(struct ctl_table *, int,
63721 void __user *, size_t *, loff_t *);
63722 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63723 + void __user *, size_t *, loff_t *);
63724 extern int proc_dointvec(struct ctl_table *, int,
63725 void __user *, size_t *, loff_t *);
63726 extern int proc_dointvec_minmax(struct ctl_table *, int,
63727 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63728 index a71a292..51bd91d 100644
63729 --- a/include/linux/tracehook.h
63730 +++ b/include/linux/tracehook.h
63731 @@ -54,12 +54,12 @@ struct linux_binprm;
63732 /*
63733 * ptrace report for syscall entry and exit looks identical.
63734 */
63735 -static inline void ptrace_report_syscall(struct pt_regs *regs)
63736 +static inline int ptrace_report_syscall(struct pt_regs *regs)
63737 {
63738 int ptrace = current->ptrace;
63739
63740 if (!(ptrace & PT_PTRACED))
63741 - return;
63742 + return 0;
63743
63744 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63745
63746 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63747 send_sig(current->exit_code, current, 1);
63748 current->exit_code = 0;
63749 }
63750 +
63751 + return fatal_signal_pending(current);
63752 }
63753
63754 /**
63755 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63756 static inline __must_check int tracehook_report_syscall_entry(
63757 struct pt_regs *regs)
63758 {
63759 - ptrace_report_syscall(regs);
63760 - return 0;
63761 + return ptrace_report_syscall(regs);
63762 }
63763
63764 /**
63765 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63766 index ff7dc08..893e1bd 100644
63767 --- a/include/linux/tty_ldisc.h
63768 +++ b/include/linux/tty_ldisc.h
63769 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63770
63771 struct module *owner;
63772
63773 - int refcount;
63774 + atomic_t refcount;
63775 };
63776
63777 struct tty_ldisc {
63778 diff --git a/include/linux/types.h b/include/linux/types.h
63779 index e5fa503..df6e8a4 100644
63780 --- a/include/linux/types.h
63781 +++ b/include/linux/types.h
63782 @@ -214,10 +214,26 @@ typedef struct {
63783 int counter;
63784 } atomic_t;
63785
63786 +#ifdef CONFIG_PAX_REFCOUNT
63787 +typedef struct {
63788 + int counter;
63789 +} atomic_unchecked_t;
63790 +#else
63791 +typedef atomic_t atomic_unchecked_t;
63792 +#endif
63793 +
63794 #ifdef CONFIG_64BIT
63795 typedef struct {
63796 long counter;
63797 } atomic64_t;
63798 +
63799 +#ifdef CONFIG_PAX_REFCOUNT
63800 +typedef struct {
63801 + long counter;
63802 +} atomic64_unchecked_t;
63803 +#else
63804 +typedef atomic64_t atomic64_unchecked_t;
63805 +#endif
63806 #endif
63807
63808 struct list_head {
63809 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63810 index 5ca0951..53a2fff 100644
63811 --- a/include/linux/uaccess.h
63812 +++ b/include/linux/uaccess.h
63813 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63814 long ret; \
63815 mm_segment_t old_fs = get_fs(); \
63816 \
63817 - set_fs(KERNEL_DS); \
63818 pagefault_disable(); \
63819 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63820 - pagefault_enable(); \
63821 + set_fs(KERNEL_DS); \
63822 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63823 set_fs(old_fs); \
63824 + pagefault_enable(); \
63825 ret; \
63826 })
63827
63828 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
63829 * Safely write to address @dst from the buffer at @src. If a kernel fault
63830 * happens, handle that and return -EFAULT.
63831 */
63832 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
63833 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
63834 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
63835
63836 #endif /* __LINUX_UACCESS_H__ */
63837 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63838 index 99c1b4d..bb94261 100644
63839 --- a/include/linux/unaligned/access_ok.h
63840 +++ b/include/linux/unaligned/access_ok.h
63841 @@ -6,32 +6,32 @@
63842
63843 static inline u16 get_unaligned_le16(const void *p)
63844 {
63845 - return le16_to_cpup((__le16 *)p);
63846 + return le16_to_cpup((const __le16 *)p);
63847 }
63848
63849 static inline u32 get_unaligned_le32(const void *p)
63850 {
63851 - return le32_to_cpup((__le32 *)p);
63852 + return le32_to_cpup((const __le32 *)p);
63853 }
63854
63855 static inline u64 get_unaligned_le64(const void *p)
63856 {
63857 - return le64_to_cpup((__le64 *)p);
63858 + return le64_to_cpup((const __le64 *)p);
63859 }
63860
63861 static inline u16 get_unaligned_be16(const void *p)
63862 {
63863 - return be16_to_cpup((__be16 *)p);
63864 + return be16_to_cpup((const __be16 *)p);
63865 }
63866
63867 static inline u32 get_unaligned_be32(const void *p)
63868 {
63869 - return be32_to_cpup((__be32 *)p);
63870 + return be32_to_cpup((const __be32 *)p);
63871 }
63872
63873 static inline u64 get_unaligned_be64(const void *p)
63874 {
63875 - return be64_to_cpup((__be64 *)p);
63876 + return be64_to_cpup((const __be64 *)p);
63877 }
63878
63879 static inline void put_unaligned_le16(u16 val, void *p)
63880 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63881 index 0d3f988..000f101 100644
63882 --- a/include/linux/usb/renesas_usbhs.h
63883 +++ b/include/linux/usb/renesas_usbhs.h
63884 @@ -39,7 +39,7 @@ enum {
63885 */
63886 struct renesas_usbhs_driver_callback {
63887 int (*notify_hotplug)(struct platform_device *pdev);
63888 -};
63889 +} __no_const;
63890
63891 /*
63892 * callback functions for platform
63893 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63894 * VBUS control is needed for Host
63895 */
63896 int (*set_vbus)(struct platform_device *pdev, int enable);
63897 -};
63898 +} __no_const;
63899
63900 /*
63901 * parameters for renesas usbhs
63902 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63903 index 6f8fbcf..8259001 100644
63904 --- a/include/linux/vermagic.h
63905 +++ b/include/linux/vermagic.h
63906 @@ -25,9 +25,35 @@
63907 #define MODULE_ARCH_VERMAGIC ""
63908 #endif
63909
63910 +#ifdef CONFIG_PAX_REFCOUNT
63911 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63912 +#else
63913 +#define MODULE_PAX_REFCOUNT ""
63914 +#endif
63915 +
63916 +#ifdef CONSTIFY_PLUGIN
63917 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63918 +#else
63919 +#define MODULE_CONSTIFY_PLUGIN ""
63920 +#endif
63921 +
63922 +#ifdef STACKLEAK_PLUGIN
63923 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63924 +#else
63925 +#define MODULE_STACKLEAK_PLUGIN ""
63926 +#endif
63927 +
63928 +#ifdef CONFIG_GRKERNSEC
63929 +#define MODULE_GRSEC "GRSEC "
63930 +#else
63931 +#define MODULE_GRSEC ""
63932 +#endif
63933 +
63934 #define VERMAGIC_STRING \
63935 UTS_RELEASE " " \
63936 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63937 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63938 - MODULE_ARCH_VERMAGIC
63939 + MODULE_ARCH_VERMAGIC \
63940 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63941 + MODULE_GRSEC
63942
63943 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63944 index dcdfc2b..cce598d 100644
63945 --- a/include/linux/vmalloc.h
63946 +++ b/include/linux/vmalloc.h
63947 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63948 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63949 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63950 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63951 +
63952 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63953 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63954 +#endif
63955 +
63956 /* bits [20..32] reserved for arch specific ioremap internals */
63957
63958 /*
63959 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
63960 }
63961 #endif
63962
63963 -extern void *vmalloc(unsigned long size);
63964 -extern void *vzalloc(unsigned long size);
63965 -extern void *vmalloc_user(unsigned long size);
63966 -extern void *vmalloc_node(unsigned long size, int node);
63967 -extern void *vzalloc_node(unsigned long size, int node);
63968 -extern void *vmalloc_exec(unsigned long size);
63969 -extern void *vmalloc_32(unsigned long size);
63970 -extern void *vmalloc_32_user(unsigned long size);
63971 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63972 +extern void *vmalloc(unsigned long size) __size_overflow(1);
63973 +extern void *vzalloc(unsigned long size) __size_overflow(1);
63974 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
63975 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
63976 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
63977 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
63978 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
63979 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
63980 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
63981 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63982 unsigned long start, unsigned long end, gfp_t gfp_mask,
63983 - pgprot_t prot, int node, void *caller);
63984 + pgprot_t prot, int node, void *caller) __size_overflow(1);
63985 extern void vfree(const void *addr);
63986
63987 extern void *vmap(struct page **pages, unsigned int count,
63988 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63989 extern void free_vm_area(struct vm_struct *area);
63990
63991 /* for /dev/kmem */
63992 -extern long vread(char *buf, char *addr, unsigned long count);
63993 -extern long vwrite(char *buf, char *addr, unsigned long count);
63994 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63995 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63996
63997 /*
63998 * Internals. Dont't use..
63999 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64000 index 65efb92..137adbb 100644
64001 --- a/include/linux/vmstat.h
64002 +++ b/include/linux/vmstat.h
64003 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64004 /*
64005 * Zone based page accounting with per cpu differentials.
64006 */
64007 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64008 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64009
64010 static inline void zone_page_state_add(long x, struct zone *zone,
64011 enum zone_stat_item item)
64012 {
64013 - atomic_long_add(x, &zone->vm_stat[item]);
64014 - atomic_long_add(x, &vm_stat[item]);
64015 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64016 + atomic_long_add_unchecked(x, &vm_stat[item]);
64017 }
64018
64019 static inline unsigned long global_page_state(enum zone_stat_item item)
64020 {
64021 - long x = atomic_long_read(&vm_stat[item]);
64022 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64023 #ifdef CONFIG_SMP
64024 if (x < 0)
64025 x = 0;
64026 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64027 static inline unsigned long zone_page_state(struct zone *zone,
64028 enum zone_stat_item item)
64029 {
64030 - long x = atomic_long_read(&zone->vm_stat[item]);
64031 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64032 #ifdef CONFIG_SMP
64033 if (x < 0)
64034 x = 0;
64035 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64036 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64037 enum zone_stat_item item)
64038 {
64039 - long x = atomic_long_read(&zone->vm_stat[item]);
64040 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64041
64042 #ifdef CONFIG_SMP
64043 int cpu;
64044 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64045
64046 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64047 {
64048 - atomic_long_inc(&zone->vm_stat[item]);
64049 - atomic_long_inc(&vm_stat[item]);
64050 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64051 + atomic_long_inc_unchecked(&vm_stat[item]);
64052 }
64053
64054 static inline void __inc_zone_page_state(struct page *page,
64055 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64056
64057 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64058 {
64059 - atomic_long_dec(&zone->vm_stat[item]);
64060 - atomic_long_dec(&vm_stat[item]);
64061 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64062 + atomic_long_dec_unchecked(&vm_stat[item]);
64063 }
64064
64065 static inline void __dec_zone_page_state(struct page *page,
64066 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64067 index e5d1220..ef6e406 100644
64068 --- a/include/linux/xattr.h
64069 +++ b/include/linux/xattr.h
64070 @@ -57,6 +57,11 @@
64071 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64072 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64073
64074 +/* User namespace */
64075 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64076 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64077 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64078 +
64079 #ifdef __KERNEL__
64080
64081 #include <linux/types.h>
64082 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64083 index 4aeff96..b378cdc 100644
64084 --- a/include/media/saa7146_vv.h
64085 +++ b/include/media/saa7146_vv.h
64086 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64087 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64088
64089 /* the extension can override this */
64090 - struct v4l2_ioctl_ops ops;
64091 + v4l2_ioctl_ops_no_const ops;
64092 /* pointer to the saa7146 core ops */
64093 const struct v4l2_ioctl_ops *core_ops;
64094
64095 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64096 index c7c40f1..4f01585 100644
64097 --- a/include/media/v4l2-dev.h
64098 +++ b/include/media/v4l2-dev.h
64099 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64100
64101
64102 struct v4l2_file_operations {
64103 - struct module *owner;
64104 + struct module * const owner;
64105 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64106 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64107 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64108 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64109 int (*open) (struct file *);
64110 int (*release) (struct file *);
64111 };
64112 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64113
64114 /*
64115 * Newer version of video_device, handled by videodev2.c
64116 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64117 index 3f5d60f..44210ed 100644
64118 --- a/include/media/v4l2-ioctl.h
64119 +++ b/include/media/v4l2-ioctl.h
64120 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64121 long (*vidioc_default) (struct file *file, void *fh,
64122 bool valid_prio, int cmd, void *arg);
64123 };
64124 -
64125 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64126
64127 /* v4l debugging and diagnostics */
64128
64129 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64130 index 8d55251..dfe5b0a 100644
64131 --- a/include/net/caif/caif_hsi.h
64132 +++ b/include/net/caif/caif_hsi.h
64133 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64134 void (*rx_done_cb) (struct cfhsi_drv *drv);
64135 void (*wake_up_cb) (struct cfhsi_drv *drv);
64136 void (*wake_down_cb) (struct cfhsi_drv *drv);
64137 -};
64138 +} __no_const;
64139
64140 /* Structure implemented by HSI device. */
64141 struct cfhsi_dev {
64142 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64143 index 9e5425b..8136ffc 100644
64144 --- a/include/net/caif/cfctrl.h
64145 +++ b/include/net/caif/cfctrl.h
64146 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64147 void (*radioset_rsp)(void);
64148 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64149 struct cflayer *client_layer);
64150 -};
64151 +} __no_const;
64152
64153 /* Link Setup Parameters for CAIF-Links. */
64154 struct cfctrl_link_param {
64155 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64156 struct cfctrl {
64157 struct cfsrvl serv;
64158 struct cfctrl_rsp res;
64159 - atomic_t req_seq_no;
64160 - atomic_t rsp_seq_no;
64161 + atomic_unchecked_t req_seq_no;
64162 + atomic_unchecked_t rsp_seq_no;
64163 struct list_head list;
64164 /* Protects from simultaneous access to first_req list */
64165 spinlock_t info_list_lock;
64166 diff --git a/include/net/flow.h b/include/net/flow.h
64167 index 6c469db..7743b8e 100644
64168 --- a/include/net/flow.h
64169 +++ b/include/net/flow.h
64170 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64171
64172 extern void flow_cache_flush(void);
64173 extern void flow_cache_flush_deferred(void);
64174 -extern atomic_t flow_cache_genid;
64175 +extern atomic_unchecked_t flow_cache_genid;
64176
64177 #endif
64178 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64179 index b94765e..053f68b 100644
64180 --- a/include/net/inetpeer.h
64181 +++ b/include/net/inetpeer.h
64182 @@ -48,8 +48,8 @@ struct inet_peer {
64183 */
64184 union {
64185 struct {
64186 - atomic_t rid; /* Frag reception counter */
64187 - atomic_t ip_id_count; /* IP ID for the next packet */
64188 + atomic_unchecked_t rid; /* Frag reception counter */
64189 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64190 __u32 tcp_ts;
64191 __u32 tcp_ts_stamp;
64192 };
64193 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64194 more++;
64195 inet_peer_refcheck(p);
64196 do {
64197 - old = atomic_read(&p->ip_id_count);
64198 + old = atomic_read_unchecked(&p->ip_id_count);
64199 new = old + more;
64200 if (!new)
64201 new = 1;
64202 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64203 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64204 return new;
64205 }
64206
64207 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64208 index 10422ef..662570f 100644
64209 --- a/include/net/ip_fib.h
64210 +++ b/include/net/ip_fib.h
64211 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64212
64213 #define FIB_RES_SADDR(net, res) \
64214 ((FIB_RES_NH(res).nh_saddr_genid == \
64215 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64216 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64217 FIB_RES_NH(res).nh_saddr : \
64218 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64219 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64220 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64221 index ebe517f..1bd286b 100644
64222 --- a/include/net/ip_vs.h
64223 +++ b/include/net/ip_vs.h
64224 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64225 struct ip_vs_conn *control; /* Master control connection */
64226 atomic_t n_control; /* Number of controlled ones */
64227 struct ip_vs_dest *dest; /* real server */
64228 - atomic_t in_pkts; /* incoming packet counter */
64229 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64230
64231 /* packet transmitter for different forwarding methods. If it
64232 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64233 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64234 __be16 port; /* port number of the server */
64235 union nf_inet_addr addr; /* IP address of the server */
64236 volatile unsigned flags; /* dest status flags */
64237 - atomic_t conn_flags; /* flags to copy to conn */
64238 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64239 atomic_t weight; /* server weight */
64240
64241 atomic_t refcnt; /* reference counter */
64242 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64243 index 69b610a..fe3962c 100644
64244 --- a/include/net/irda/ircomm_core.h
64245 +++ b/include/net/irda/ircomm_core.h
64246 @@ -51,7 +51,7 @@ typedef struct {
64247 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64248 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64249 struct ircomm_info *);
64250 -} call_t;
64251 +} __no_const call_t;
64252
64253 struct ircomm_cb {
64254 irda_queue_t queue;
64255 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64256 index 59ba38bc..d515662 100644
64257 --- a/include/net/irda/ircomm_tty.h
64258 +++ b/include/net/irda/ircomm_tty.h
64259 @@ -35,6 +35,7 @@
64260 #include <linux/termios.h>
64261 #include <linux/timer.h>
64262 #include <linux/tty.h> /* struct tty_struct */
64263 +#include <asm/local.h>
64264
64265 #include <net/irda/irias_object.h>
64266 #include <net/irda/ircomm_core.h>
64267 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64268 unsigned short close_delay;
64269 unsigned short closing_wait; /* time to wait before closing */
64270
64271 - int open_count;
64272 - int blocked_open; /* # of blocked opens */
64273 + local_t open_count;
64274 + local_t blocked_open; /* # of blocked opens */
64275
64276 /* Protect concurent access to :
64277 * o self->open_count
64278 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64279 index 0954ec9..7413562 100644
64280 --- a/include/net/iucv/af_iucv.h
64281 +++ b/include/net/iucv/af_iucv.h
64282 @@ -138,7 +138,7 @@ struct iucv_sock {
64283 struct iucv_sock_list {
64284 struct hlist_head head;
64285 rwlock_t lock;
64286 - atomic_t autobind_name;
64287 + atomic_unchecked_t autobind_name;
64288 };
64289
64290 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64291 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64292 index 34c996f..bb3b4d4 100644
64293 --- a/include/net/neighbour.h
64294 +++ b/include/net/neighbour.h
64295 @@ -123,7 +123,7 @@ struct neigh_ops {
64296 void (*error_report)(struct neighbour *, struct sk_buff *);
64297 int (*output)(struct neighbour *, struct sk_buff *);
64298 int (*connected_output)(struct neighbour *, struct sk_buff *);
64299 -};
64300 +} __do_const;
64301
64302 struct pneigh_entry {
64303 struct pneigh_entry *next;
64304 diff --git a/include/net/netlink.h b/include/net/netlink.h
64305 index cb1f350..3279d2c 100644
64306 --- a/include/net/netlink.h
64307 +++ b/include/net/netlink.h
64308 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64309 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64310 {
64311 if (mark)
64312 - skb_trim(skb, (unsigned char *) mark - skb->data);
64313 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64314 }
64315
64316 /**
64317 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64318 index bbd023a..97c6d0d 100644
64319 --- a/include/net/netns/ipv4.h
64320 +++ b/include/net/netns/ipv4.h
64321 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64322 unsigned int sysctl_ping_group_range[2];
64323 long sysctl_tcp_mem[3];
64324
64325 - atomic_t rt_genid;
64326 - atomic_t dev_addr_genid;
64327 + atomic_unchecked_t rt_genid;
64328 + atomic_unchecked_t dev_addr_genid;
64329
64330 #ifdef CONFIG_IP_MROUTE
64331 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64332 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64333 index d368561..96aaa17 100644
64334 --- a/include/net/sctp/sctp.h
64335 +++ b/include/net/sctp/sctp.h
64336 @@ -318,9 +318,9 @@ do { \
64337
64338 #else /* SCTP_DEBUG */
64339
64340 -#define SCTP_DEBUG_PRINTK(whatever...)
64341 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64342 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64343 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64344 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64345 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64346 #define SCTP_ENABLE_DEBUG
64347 #define SCTP_DISABLE_DEBUG
64348 #define SCTP_ASSERT(expr, str, func)
64349 diff --git a/include/net/sock.h b/include/net/sock.h
64350 index 91c1c8b..15ae923 100644
64351 --- a/include/net/sock.h
64352 +++ b/include/net/sock.h
64353 @@ -299,7 +299,7 @@ struct sock {
64354 #ifdef CONFIG_RPS
64355 __u32 sk_rxhash;
64356 #endif
64357 - atomic_t sk_drops;
64358 + atomic_unchecked_t sk_drops;
64359 int sk_rcvbuf;
64360
64361 struct sk_filter __rcu *sk_filter;
64362 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64363 }
64364
64365 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64366 - char __user *from, char *to,
64367 + char __user *from, unsigned char *to,
64368 int copy, int offset)
64369 {
64370 if (skb->ip_summed == CHECKSUM_NONE) {
64371 diff --git a/include/net/tcp.h b/include/net/tcp.h
64372 index 2d80c29..aa07caf 100644
64373 --- a/include/net/tcp.h
64374 +++ b/include/net/tcp.h
64375 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64376 char *name;
64377 sa_family_t family;
64378 const struct file_operations *seq_fops;
64379 - struct seq_operations seq_ops;
64380 + seq_operations_no_const seq_ops;
64381 };
64382
64383 struct tcp_iter_state {
64384 diff --git a/include/net/udp.h b/include/net/udp.h
64385 index e39592f..fef9680 100644
64386 --- a/include/net/udp.h
64387 +++ b/include/net/udp.h
64388 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64389 sa_family_t family;
64390 struct udp_table *udp_table;
64391 const struct file_operations *seq_fops;
64392 - struct seq_operations seq_ops;
64393 + seq_operations_no_const seq_ops;
64394 };
64395
64396 struct udp_iter_state {
64397 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64398 index 89174e2..1f82598 100644
64399 --- a/include/net/xfrm.h
64400 +++ b/include/net/xfrm.h
64401 @@ -505,7 +505,7 @@ struct xfrm_policy {
64402 struct timer_list timer;
64403
64404 struct flow_cache_object flo;
64405 - atomic_t genid;
64406 + atomic_unchecked_t genid;
64407 u32 priority;
64408 u32 index;
64409 struct xfrm_mark mark;
64410 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64411 index 1a046b1..ee0bef0 100644
64412 --- a/include/rdma/iw_cm.h
64413 +++ b/include/rdma/iw_cm.h
64414 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64415 int backlog);
64416
64417 int (*destroy_listen)(struct iw_cm_id *cm_id);
64418 -};
64419 +} __no_const;
64420
64421 /**
64422 * iw_create_cm_id - Create an IW CM identifier.
64423 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64424 index 6a3922f..0b73022 100644
64425 --- a/include/scsi/libfc.h
64426 +++ b/include/scsi/libfc.h
64427 @@ -748,6 +748,7 @@ struct libfc_function_template {
64428 */
64429 void (*disc_stop_final) (struct fc_lport *);
64430 };
64431 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64432
64433 /**
64434 * struct fc_disc - Discovery context
64435 @@ -851,7 +852,7 @@ struct fc_lport {
64436 struct fc_vport *vport;
64437
64438 /* Operational Information */
64439 - struct libfc_function_template tt;
64440 + libfc_function_template_no_const tt;
64441 u8 link_up;
64442 u8 qfull;
64443 enum fc_lport_state state;
64444 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64445 index 77273f2..dd4031f 100644
64446 --- a/include/scsi/scsi_device.h
64447 +++ b/include/scsi/scsi_device.h
64448 @@ -161,9 +161,9 @@ struct scsi_device {
64449 unsigned int max_device_blocked; /* what device_blocked counts down from */
64450 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64451
64452 - atomic_t iorequest_cnt;
64453 - atomic_t iodone_cnt;
64454 - atomic_t ioerr_cnt;
64455 + atomic_unchecked_t iorequest_cnt;
64456 + atomic_unchecked_t iodone_cnt;
64457 + atomic_unchecked_t ioerr_cnt;
64458
64459 struct device sdev_gendev,
64460 sdev_dev;
64461 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64462 index 2a65167..91e01f8 100644
64463 --- a/include/scsi/scsi_transport_fc.h
64464 +++ b/include/scsi/scsi_transport_fc.h
64465 @@ -711,7 +711,7 @@ struct fc_function_template {
64466 unsigned long show_host_system_hostname:1;
64467
64468 unsigned long disable_target_scan:1;
64469 -};
64470 +} __do_const;
64471
64472
64473 /**
64474 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64475 index 030b87c..98a6954 100644
64476 --- a/include/sound/ak4xxx-adda.h
64477 +++ b/include/sound/ak4xxx-adda.h
64478 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64479 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64480 unsigned char val);
64481 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64482 -};
64483 +} __no_const;
64484
64485 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64486
64487 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64488 index 8c05e47..2b5df97 100644
64489 --- a/include/sound/hwdep.h
64490 +++ b/include/sound/hwdep.h
64491 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64492 struct snd_hwdep_dsp_status *status);
64493 int (*dsp_load)(struct snd_hwdep *hw,
64494 struct snd_hwdep_dsp_image *image);
64495 -};
64496 +} __no_const;
64497
64498 struct snd_hwdep {
64499 struct snd_card *card;
64500 diff --git a/include/sound/info.h b/include/sound/info.h
64501 index 9ca1a49..aba1728 100644
64502 --- a/include/sound/info.h
64503 +++ b/include/sound/info.h
64504 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64505 struct snd_info_buffer *buffer);
64506 void (*write)(struct snd_info_entry *entry,
64507 struct snd_info_buffer *buffer);
64508 -};
64509 +} __no_const;
64510
64511 struct snd_info_entry_ops {
64512 int (*open)(struct snd_info_entry *entry,
64513 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64514 index 0cf91b2..b70cae4 100644
64515 --- a/include/sound/pcm.h
64516 +++ b/include/sound/pcm.h
64517 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64518 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64519 int (*ack)(struct snd_pcm_substream *substream);
64520 };
64521 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64522
64523 /*
64524 *
64525 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64526 index af1b49e..a5d55a5 100644
64527 --- a/include/sound/sb16_csp.h
64528 +++ b/include/sound/sb16_csp.h
64529 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64530 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64531 int (*csp_stop) (struct snd_sb_csp * p);
64532 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64533 -};
64534 +} __no_const;
64535
64536 /*
64537 * CSP private data
64538 diff --git a/include/sound/soc.h b/include/sound/soc.h
64539 index 0992dff..bb366fe 100644
64540 --- a/include/sound/soc.h
64541 +++ b/include/sound/soc.h
64542 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64543 /* platform IO - used for platform DAPM */
64544 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64545 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64546 -};
64547 +} __do_const;
64548
64549 struct snd_soc_platform {
64550 const char *name;
64551 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64552 struct snd_soc_dai_link *dai_link;
64553 struct mutex pcm_mutex;
64554 enum snd_soc_pcm_subclass pcm_subclass;
64555 - struct snd_pcm_ops ops;
64556 + snd_pcm_ops_no_const ops;
64557
64558 unsigned int complete:1;
64559 unsigned int dev_registered:1;
64560 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64561 index 444cd6b..3327cc5 100644
64562 --- a/include/sound/ymfpci.h
64563 +++ b/include/sound/ymfpci.h
64564 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64565 spinlock_t reg_lock;
64566 spinlock_t voice_lock;
64567 wait_queue_head_t interrupt_sleep;
64568 - atomic_t interrupt_sleep_count;
64569 + atomic_unchecked_t interrupt_sleep_count;
64570 struct snd_info_entry *proc_entry;
64571 const struct firmware *dsp_microcode;
64572 const struct firmware *controller_microcode;
64573 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64574 index fe73eb8..56388b1 100644
64575 --- a/include/target/target_core_base.h
64576 +++ b/include/target/target_core_base.h
64577 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
64578 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64579 int (*t10_pr_register)(struct se_cmd *);
64580 int (*t10_pr_clear)(struct se_cmd *);
64581 -};
64582 +} __no_const;
64583
64584 struct t10_reservation {
64585 /* Reservation effects all target ports */
64586 @@ -561,8 +561,8 @@ struct se_cmd {
64587 atomic_t t_se_count;
64588 atomic_t t_task_cdbs_left;
64589 atomic_t t_task_cdbs_ex_left;
64590 - atomic_t t_task_cdbs_sent;
64591 - atomic_t t_transport_aborted;
64592 + atomic_unchecked_t t_task_cdbs_sent;
64593 + atomic_unchecked_t t_transport_aborted;
64594 atomic_t t_transport_active;
64595 atomic_t t_transport_complete;
64596 atomic_t t_transport_queue_active;
64597 @@ -799,7 +799,7 @@ struct se_device {
64598 spinlock_t stats_lock;
64599 /* Active commands on this virtual SE device */
64600 atomic_t simple_cmds;
64601 - atomic_t dev_ordered_id;
64602 + atomic_unchecked_t dev_ordered_id;
64603 atomic_t execute_tasks;
64604 atomic_t dev_ordered_sync;
64605 atomic_t dev_qf_count;
64606 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64607 index 1c09820..7f5ec79 100644
64608 --- a/include/trace/events/irq.h
64609 +++ b/include/trace/events/irq.h
64610 @@ -36,7 +36,7 @@ struct softirq_action;
64611 */
64612 TRACE_EVENT(irq_handler_entry,
64613
64614 - TP_PROTO(int irq, struct irqaction *action),
64615 + TP_PROTO(int irq, const struct irqaction *action),
64616
64617 TP_ARGS(irq, action),
64618
64619 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64620 */
64621 TRACE_EVENT(irq_handler_exit,
64622
64623 - TP_PROTO(int irq, struct irqaction *action, int ret),
64624 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64625
64626 TP_ARGS(irq, action, ret),
64627
64628 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64629 index c41f308..6918de3 100644
64630 --- a/include/video/udlfb.h
64631 +++ b/include/video/udlfb.h
64632 @@ -52,10 +52,10 @@ struct dlfb_data {
64633 u32 pseudo_palette[256];
64634 int blank_mode; /*one of FB_BLANK_ */
64635 /* blit-only rendering path metrics, exposed through sysfs */
64636 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64637 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64638 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64639 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64640 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64641 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64642 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64643 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64644 };
64645
64646 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64647 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64648 index 0993a22..32ba2fe 100644
64649 --- a/include/video/uvesafb.h
64650 +++ b/include/video/uvesafb.h
64651 @@ -177,6 +177,7 @@ struct uvesafb_par {
64652 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64653 u8 pmi_setpal; /* PMI for palette changes */
64654 u16 *pmi_base; /* protected mode interface location */
64655 + u8 *pmi_code; /* protected mode code location */
64656 void *pmi_start;
64657 void *pmi_pal;
64658 u8 *vbe_state_orig; /*
64659 diff --git a/init/Kconfig b/init/Kconfig
64660 index 3f42cd6..613f41d 100644
64661 --- a/init/Kconfig
64662 +++ b/init/Kconfig
64663 @@ -799,6 +799,7 @@ endif # CGROUPS
64664
64665 config CHECKPOINT_RESTORE
64666 bool "Checkpoint/restore support" if EXPERT
64667 + depends on !GRKERNSEC
64668 default n
64669 help
64670 Enables additional kernel features in a sake of checkpoint/restore.
64671 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64672
64673 config COMPAT_BRK
64674 bool "Disable heap randomization"
64675 - default y
64676 + default n
64677 help
64678 Randomizing heap placement makes heap exploits harder, but it
64679 also breaks ancient binaries (including anything libc5 based).
64680 diff --git a/init/do_mounts.c b/init/do_mounts.c
64681 index 2974c8b..0b863ae 100644
64682 --- a/init/do_mounts.c
64683 +++ b/init/do_mounts.c
64684 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64685 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64686 {
64687 struct super_block *s;
64688 - int err = sys_mount(name, "/root", fs, flags, data);
64689 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64690 if (err)
64691 return err;
64692
64693 - sys_chdir((const char __user __force *)"/root");
64694 + sys_chdir((const char __force_user *)"/root");
64695 s = current->fs->pwd.dentry->d_sb;
64696 ROOT_DEV = s->s_dev;
64697 printk(KERN_INFO
64698 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64699 va_start(args, fmt);
64700 vsprintf(buf, fmt, args);
64701 va_end(args);
64702 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64703 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64704 if (fd >= 0) {
64705 sys_ioctl(fd, FDEJECT, 0);
64706 sys_close(fd);
64707 }
64708 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64709 - fd = sys_open("/dev/console", O_RDWR, 0);
64710 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64711 if (fd >= 0) {
64712 sys_ioctl(fd, TCGETS, (long)&termios);
64713 termios.c_lflag &= ~ICANON;
64714 sys_ioctl(fd, TCSETSF, (long)&termios);
64715 - sys_read(fd, &c, 1);
64716 + sys_read(fd, (char __user *)&c, 1);
64717 termios.c_lflag |= ICANON;
64718 sys_ioctl(fd, TCSETSF, (long)&termios);
64719 sys_close(fd);
64720 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64721 mount_root();
64722 out:
64723 devtmpfs_mount("dev");
64724 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64725 - sys_chroot((const char __user __force *)".");
64726 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64727 + sys_chroot((const char __force_user *)".");
64728 }
64729 diff --git a/init/do_mounts.h b/init/do_mounts.h
64730 index f5b978a..69dbfe8 100644
64731 --- a/init/do_mounts.h
64732 +++ b/init/do_mounts.h
64733 @@ -15,15 +15,15 @@ extern int root_mountflags;
64734
64735 static inline int create_dev(char *name, dev_t dev)
64736 {
64737 - sys_unlink(name);
64738 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64739 + sys_unlink((char __force_user *)name);
64740 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64741 }
64742
64743 #if BITS_PER_LONG == 32
64744 static inline u32 bstat(char *name)
64745 {
64746 struct stat64 stat;
64747 - if (sys_stat64(name, &stat) != 0)
64748 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64749 return 0;
64750 if (!S_ISBLK(stat.st_mode))
64751 return 0;
64752 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64753 static inline u32 bstat(char *name)
64754 {
64755 struct stat stat;
64756 - if (sys_newstat(name, &stat) != 0)
64757 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64758 return 0;
64759 if (!S_ISBLK(stat.st_mode))
64760 return 0;
64761 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64762 index 3098a38..253064e 100644
64763 --- a/init/do_mounts_initrd.c
64764 +++ b/init/do_mounts_initrd.c
64765 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64766 create_dev("/dev/root.old", Root_RAM0);
64767 /* mount initrd on rootfs' /root */
64768 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64769 - sys_mkdir("/old", 0700);
64770 - root_fd = sys_open("/", 0, 0);
64771 - old_fd = sys_open("/old", 0, 0);
64772 + sys_mkdir((const char __force_user *)"/old", 0700);
64773 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64774 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64775 /* move initrd over / and chdir/chroot in initrd root */
64776 - sys_chdir("/root");
64777 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64778 - sys_chroot(".");
64779 + sys_chdir((const char __force_user *)"/root");
64780 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64781 + sys_chroot((const char __force_user *)".");
64782
64783 /*
64784 * In case that a resume from disk is carried out by linuxrc or one of
64785 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64786
64787 /* move initrd to rootfs' /old */
64788 sys_fchdir(old_fd);
64789 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64790 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64791 /* switch root and cwd back to / of rootfs */
64792 sys_fchdir(root_fd);
64793 - sys_chroot(".");
64794 + sys_chroot((const char __force_user *)".");
64795 sys_close(old_fd);
64796 sys_close(root_fd);
64797
64798 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64799 - sys_chdir("/old");
64800 + sys_chdir((const char __force_user *)"/old");
64801 return;
64802 }
64803
64804 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64805 mount_root();
64806
64807 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64808 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64809 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64810 if (!error)
64811 printk("okay\n");
64812 else {
64813 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64814 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64815 if (error == -ENOENT)
64816 printk("/initrd does not exist. Ignored.\n");
64817 else
64818 printk("failed\n");
64819 printk(KERN_NOTICE "Unmounting old root\n");
64820 - sys_umount("/old", MNT_DETACH);
64821 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64822 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64823 if (fd < 0) {
64824 error = fd;
64825 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64826 * mounted in the normal path.
64827 */
64828 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64829 - sys_unlink("/initrd.image");
64830 + sys_unlink((const char __force_user *)"/initrd.image");
64831 handle_initrd();
64832 return 1;
64833 }
64834 }
64835 - sys_unlink("/initrd.image");
64836 + sys_unlink((const char __force_user *)"/initrd.image");
64837 return 0;
64838 }
64839 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64840 index 32c4799..c27ee74 100644
64841 --- a/init/do_mounts_md.c
64842 +++ b/init/do_mounts_md.c
64843 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64844 partitioned ? "_d" : "", minor,
64845 md_setup_args[ent].device_names);
64846
64847 - fd = sys_open(name, 0, 0);
64848 + fd = sys_open((char __force_user *)name, 0, 0);
64849 if (fd < 0) {
64850 printk(KERN_ERR "md: open failed - cannot start "
64851 "array %s\n", name);
64852 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64853 * array without it
64854 */
64855 sys_close(fd);
64856 - fd = sys_open(name, 0, 0);
64857 + fd = sys_open((char __force_user *)name, 0, 0);
64858 sys_ioctl(fd, BLKRRPART, 0);
64859 }
64860 sys_close(fd);
64861 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64862
64863 wait_for_device_probe();
64864
64865 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64866 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64867 if (fd >= 0) {
64868 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64869 sys_close(fd);
64870 diff --git a/init/initramfs.c b/init/initramfs.c
64871 index 8216c30..25e8e32 100644
64872 --- a/init/initramfs.c
64873 +++ b/init/initramfs.c
64874 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64875 }
64876 }
64877
64878 -static long __init do_utime(char __user *filename, time_t mtime)
64879 +static long __init do_utime(__force char __user *filename, time_t mtime)
64880 {
64881 struct timespec t[2];
64882
64883 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64884 struct dir_entry *de, *tmp;
64885 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64886 list_del(&de->list);
64887 - do_utime(de->name, de->mtime);
64888 + do_utime((char __force_user *)de->name, de->mtime);
64889 kfree(de->name);
64890 kfree(de);
64891 }
64892 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64893 if (nlink >= 2) {
64894 char *old = find_link(major, minor, ino, mode, collected);
64895 if (old)
64896 - return (sys_link(old, collected) < 0) ? -1 : 1;
64897 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64898 }
64899 return 0;
64900 }
64901 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64902 {
64903 struct stat st;
64904
64905 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64906 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64907 if (S_ISDIR(st.st_mode))
64908 - sys_rmdir(path);
64909 + sys_rmdir((char __force_user *)path);
64910 else
64911 - sys_unlink(path);
64912 + sys_unlink((char __force_user *)path);
64913 }
64914 }
64915
64916 @@ -305,7 +305,7 @@ static int __init do_name(void)
64917 int openflags = O_WRONLY|O_CREAT;
64918 if (ml != 1)
64919 openflags |= O_TRUNC;
64920 - wfd = sys_open(collected, openflags, mode);
64921 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64922
64923 if (wfd >= 0) {
64924 sys_fchown(wfd, uid, gid);
64925 @@ -317,17 +317,17 @@ static int __init do_name(void)
64926 }
64927 }
64928 } else if (S_ISDIR(mode)) {
64929 - sys_mkdir(collected, mode);
64930 - sys_chown(collected, uid, gid);
64931 - sys_chmod(collected, mode);
64932 + sys_mkdir((char __force_user *)collected, mode);
64933 + sys_chown((char __force_user *)collected, uid, gid);
64934 + sys_chmod((char __force_user *)collected, mode);
64935 dir_add(collected, mtime);
64936 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64937 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64938 if (maybe_link() == 0) {
64939 - sys_mknod(collected, mode, rdev);
64940 - sys_chown(collected, uid, gid);
64941 - sys_chmod(collected, mode);
64942 - do_utime(collected, mtime);
64943 + sys_mknod((char __force_user *)collected, mode, rdev);
64944 + sys_chown((char __force_user *)collected, uid, gid);
64945 + sys_chmod((char __force_user *)collected, mode);
64946 + do_utime((char __force_user *)collected, mtime);
64947 }
64948 }
64949 return 0;
64950 @@ -336,15 +336,15 @@ static int __init do_name(void)
64951 static int __init do_copy(void)
64952 {
64953 if (count >= body_len) {
64954 - sys_write(wfd, victim, body_len);
64955 + sys_write(wfd, (char __force_user *)victim, body_len);
64956 sys_close(wfd);
64957 - do_utime(vcollected, mtime);
64958 + do_utime((char __force_user *)vcollected, mtime);
64959 kfree(vcollected);
64960 eat(body_len);
64961 state = SkipIt;
64962 return 0;
64963 } else {
64964 - sys_write(wfd, victim, count);
64965 + sys_write(wfd, (char __force_user *)victim, count);
64966 body_len -= count;
64967 eat(count);
64968 return 1;
64969 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64970 {
64971 collected[N_ALIGN(name_len) + body_len] = '\0';
64972 clean_path(collected, 0);
64973 - sys_symlink(collected + N_ALIGN(name_len), collected);
64974 - sys_lchown(collected, uid, gid);
64975 - do_utime(collected, mtime);
64976 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64977 + sys_lchown((char __force_user *)collected, uid, gid);
64978 + do_utime((char __force_user *)collected, mtime);
64979 state = SkipIt;
64980 next_state = Reset;
64981 return 0;
64982 diff --git a/init/main.c b/init/main.c
64983 index ff49a6d..5fa0429 100644
64984 --- a/init/main.c
64985 +++ b/init/main.c
64986 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64987 extern void tc_init(void);
64988 #endif
64989
64990 +extern void grsecurity_init(void);
64991 +
64992 /*
64993 * Debug helper: via this flag we know that we are in 'early bootup code'
64994 * where only the boot processor is running with IRQ disabled. This means
64995 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64996
64997 __setup("reset_devices", set_reset_devices);
64998
64999 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65000 +extern char pax_enter_kernel_user[];
65001 +extern char pax_exit_kernel_user[];
65002 +extern pgdval_t clone_pgd_mask;
65003 +#endif
65004 +
65005 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65006 +static int __init setup_pax_nouderef(char *str)
65007 +{
65008 +#ifdef CONFIG_X86_32
65009 + unsigned int cpu;
65010 + struct desc_struct *gdt;
65011 +
65012 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65013 + gdt = get_cpu_gdt_table(cpu);
65014 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65015 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65016 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65017 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65018 + }
65019 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65020 +#else
65021 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65022 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65023 + clone_pgd_mask = ~(pgdval_t)0UL;
65024 +#endif
65025 +
65026 + return 0;
65027 +}
65028 +early_param("pax_nouderef", setup_pax_nouderef);
65029 +#endif
65030 +
65031 +#ifdef CONFIG_PAX_SOFTMODE
65032 +int pax_softmode;
65033 +
65034 +static int __init setup_pax_softmode(char *str)
65035 +{
65036 + get_option(&str, &pax_softmode);
65037 + return 1;
65038 +}
65039 +__setup("pax_softmode=", setup_pax_softmode);
65040 +#endif
65041 +
65042 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65043 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65044 static const char *panic_later, *panic_param;
65045 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65046 {
65047 int count = preempt_count();
65048 int ret;
65049 + const char *msg1 = "", *msg2 = "";
65050
65051 if (initcall_debug)
65052 ret = do_one_initcall_debug(fn);
65053 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65054 sprintf(msgbuf, "error code %d ", ret);
65055
65056 if (preempt_count() != count) {
65057 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65058 + msg1 = " preemption imbalance";
65059 preempt_count() = count;
65060 }
65061 if (irqs_disabled()) {
65062 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65063 + msg2 = " disabled interrupts";
65064 local_irq_enable();
65065 }
65066 - if (msgbuf[0]) {
65067 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65068 + if (msgbuf[0] || *msg1 || *msg2) {
65069 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65070 }
65071
65072 return ret;
65073 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65074 do_basic_setup();
65075
65076 /* Open the /dev/console on the rootfs, this should never fail */
65077 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65078 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65079 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65080
65081 (void) sys_dup(0);
65082 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65083 if (!ramdisk_execute_command)
65084 ramdisk_execute_command = "/init";
65085
65086 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65087 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65088 ramdisk_execute_command = NULL;
65089 prepare_namespace();
65090 }
65091
65092 + grsecurity_init();
65093 +
65094 /*
65095 * Ok, we have completed the initial bootup, and
65096 * we're essentially up and running. Get rid of the
65097 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65098 index 86ee272..773d937 100644
65099 --- a/ipc/mqueue.c
65100 +++ b/ipc/mqueue.c
65101 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65102 mq_bytes = (mq_msg_tblsz +
65103 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65104
65105 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65106 spin_lock(&mq_lock);
65107 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65108 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65109 diff --git a/ipc/msg.c b/ipc/msg.c
65110 index 7385de2..a8180e08 100644
65111 --- a/ipc/msg.c
65112 +++ b/ipc/msg.c
65113 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65114 return security_msg_queue_associate(msq, msgflg);
65115 }
65116
65117 +static struct ipc_ops msg_ops = {
65118 + .getnew = newque,
65119 + .associate = msg_security,
65120 + .more_checks = NULL
65121 +};
65122 +
65123 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65124 {
65125 struct ipc_namespace *ns;
65126 - struct ipc_ops msg_ops;
65127 struct ipc_params msg_params;
65128
65129 ns = current->nsproxy->ipc_ns;
65130
65131 - msg_ops.getnew = newque;
65132 - msg_ops.associate = msg_security;
65133 - msg_ops.more_checks = NULL;
65134 -
65135 msg_params.key = key;
65136 msg_params.flg = msgflg;
65137
65138 diff --git a/ipc/sem.c b/ipc/sem.c
65139 index 5215a81..cfc0cac 100644
65140 --- a/ipc/sem.c
65141 +++ b/ipc/sem.c
65142 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65143 return 0;
65144 }
65145
65146 +static struct ipc_ops sem_ops = {
65147 + .getnew = newary,
65148 + .associate = sem_security,
65149 + .more_checks = sem_more_checks
65150 +};
65151 +
65152 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65153 {
65154 struct ipc_namespace *ns;
65155 - struct ipc_ops sem_ops;
65156 struct ipc_params sem_params;
65157
65158 ns = current->nsproxy->ipc_ns;
65159 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65160 if (nsems < 0 || nsems > ns->sc_semmsl)
65161 return -EINVAL;
65162
65163 - sem_ops.getnew = newary;
65164 - sem_ops.associate = sem_security;
65165 - sem_ops.more_checks = sem_more_checks;
65166 -
65167 sem_params.key = key;
65168 sem_params.flg = semflg;
65169 sem_params.u.nsems = nsems;
65170 diff --git a/ipc/shm.c b/ipc/shm.c
65171 index b76be5b..859e750 100644
65172 --- a/ipc/shm.c
65173 +++ b/ipc/shm.c
65174 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65175 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65176 #endif
65177
65178 +#ifdef CONFIG_GRKERNSEC
65179 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65180 + const time_t shm_createtime, const uid_t cuid,
65181 + const int shmid);
65182 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65183 + const time_t shm_createtime);
65184 +#endif
65185 +
65186 void shm_init_ns(struct ipc_namespace *ns)
65187 {
65188 ns->shm_ctlmax = SHMMAX;
65189 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65190 shp->shm_lprid = 0;
65191 shp->shm_atim = shp->shm_dtim = 0;
65192 shp->shm_ctim = get_seconds();
65193 +#ifdef CONFIG_GRKERNSEC
65194 + {
65195 + struct timespec timeval;
65196 + do_posix_clock_monotonic_gettime(&timeval);
65197 +
65198 + shp->shm_createtime = timeval.tv_sec;
65199 + }
65200 +#endif
65201 shp->shm_segsz = size;
65202 shp->shm_nattch = 0;
65203 shp->shm_file = file;
65204 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65205 return 0;
65206 }
65207
65208 +static struct ipc_ops shm_ops = {
65209 + .getnew = newseg,
65210 + .associate = shm_security,
65211 + .more_checks = shm_more_checks
65212 +};
65213 +
65214 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65215 {
65216 struct ipc_namespace *ns;
65217 - struct ipc_ops shm_ops;
65218 struct ipc_params shm_params;
65219
65220 ns = current->nsproxy->ipc_ns;
65221
65222 - shm_ops.getnew = newseg;
65223 - shm_ops.associate = shm_security;
65224 - shm_ops.more_checks = shm_more_checks;
65225 -
65226 shm_params.key = key;
65227 shm_params.flg = shmflg;
65228 shm_params.u.size = size;
65229 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65230 f_mode = FMODE_READ | FMODE_WRITE;
65231 }
65232 if (shmflg & SHM_EXEC) {
65233 +
65234 +#ifdef CONFIG_PAX_MPROTECT
65235 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65236 + goto out;
65237 +#endif
65238 +
65239 prot |= PROT_EXEC;
65240 acc_mode |= S_IXUGO;
65241 }
65242 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65243 if (err)
65244 goto out_unlock;
65245
65246 +#ifdef CONFIG_GRKERNSEC
65247 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65248 + shp->shm_perm.cuid, shmid) ||
65249 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65250 + err = -EACCES;
65251 + goto out_unlock;
65252 + }
65253 +#endif
65254 +
65255 path = shp->shm_file->f_path;
65256 path_get(&path);
65257 shp->shm_nattch++;
65258 +#ifdef CONFIG_GRKERNSEC
65259 + shp->shm_lapid = current->pid;
65260 +#endif
65261 size = i_size_read(path.dentry->d_inode);
65262 shm_unlock(shp);
65263
65264 diff --git a/kernel/acct.c b/kernel/acct.c
65265 index 02e6167..54824f7 100644
65266 --- a/kernel/acct.c
65267 +++ b/kernel/acct.c
65268 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65269 */
65270 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65271 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65272 - file->f_op->write(file, (char *)&ac,
65273 + file->f_op->write(file, (char __force_user *)&ac,
65274 sizeof(acct_t), &file->f_pos);
65275 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65276 set_fs(fs);
65277 diff --git a/kernel/audit.c b/kernel/audit.c
65278 index bb0eb5b..cf2a03a 100644
65279 --- a/kernel/audit.c
65280 +++ b/kernel/audit.c
65281 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65282 3) suppressed due to audit_rate_limit
65283 4) suppressed due to audit_backlog_limit
65284 */
65285 -static atomic_t audit_lost = ATOMIC_INIT(0);
65286 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65287
65288 /* The netlink socket. */
65289 static struct sock *audit_sock;
65290 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65291 unsigned long now;
65292 int print;
65293
65294 - atomic_inc(&audit_lost);
65295 + atomic_inc_unchecked(&audit_lost);
65296
65297 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65298
65299 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65300 printk(KERN_WARNING
65301 "audit: audit_lost=%d audit_rate_limit=%d "
65302 "audit_backlog_limit=%d\n",
65303 - atomic_read(&audit_lost),
65304 + atomic_read_unchecked(&audit_lost),
65305 audit_rate_limit,
65306 audit_backlog_limit);
65307 audit_panic(message);
65308 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65309 status_set.pid = audit_pid;
65310 status_set.rate_limit = audit_rate_limit;
65311 status_set.backlog_limit = audit_backlog_limit;
65312 - status_set.lost = atomic_read(&audit_lost);
65313 + status_set.lost = atomic_read_unchecked(&audit_lost);
65314 status_set.backlog = skb_queue_len(&audit_skb_queue);
65315 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65316 &status_set, sizeof(status_set));
65317 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65318 index af1de0f..06dfe57 100644
65319 --- a/kernel/auditsc.c
65320 +++ b/kernel/auditsc.c
65321 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65322 }
65323
65324 /* global counter which is incremented every time something logs in */
65325 -static atomic_t session_id = ATOMIC_INIT(0);
65326 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65327
65328 /**
65329 * audit_set_loginuid - set current task's audit_context loginuid
65330 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65331 return -EPERM;
65332 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65333
65334 - sessionid = atomic_inc_return(&session_id);
65335 + sessionid = atomic_inc_return_unchecked(&session_id);
65336 if (context && context->in_syscall) {
65337 struct audit_buffer *ab;
65338
65339 diff --git a/kernel/capability.c b/kernel/capability.c
65340 index 3f1adb6..c564db0 100644
65341 --- a/kernel/capability.c
65342 +++ b/kernel/capability.c
65343 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65344 * before modification is attempted and the application
65345 * fails.
65346 */
65347 + if (tocopy > ARRAY_SIZE(kdata))
65348 + return -EFAULT;
65349 +
65350 if (copy_to_user(dataptr, kdata, tocopy
65351 * sizeof(struct __user_cap_data_struct))) {
65352 return -EFAULT;
65353 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65354 int ret;
65355
65356 rcu_read_lock();
65357 - ret = security_capable(__task_cred(t), ns, cap);
65358 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65359 + gr_task_is_capable(t, __task_cred(t), cap);
65360 rcu_read_unlock();
65361
65362 - return (ret == 0);
65363 + return ret;
65364 }
65365
65366 /**
65367 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65368 int ret;
65369
65370 rcu_read_lock();
65371 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65372 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65373 rcu_read_unlock();
65374
65375 - return (ret == 0);
65376 + return ret;
65377 }
65378
65379 /**
65380 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65381 BUG();
65382 }
65383
65384 - if (security_capable(current_cred(), ns, cap) == 0) {
65385 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65386 current->flags |= PF_SUPERPRIV;
65387 return true;
65388 }
65389 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65390 }
65391 EXPORT_SYMBOL(ns_capable);
65392
65393 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65394 +{
65395 + if (unlikely(!cap_valid(cap))) {
65396 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65397 + BUG();
65398 + }
65399 +
65400 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65401 + current->flags |= PF_SUPERPRIV;
65402 + return true;
65403 + }
65404 + return false;
65405 +}
65406 +EXPORT_SYMBOL(ns_capable_nolog);
65407 +
65408 /**
65409 * capable - Determine if the current task has a superior capability in effect
65410 * @cap: The capability to be tested for
65411 @@ -408,6 +427,12 @@ bool capable(int cap)
65412 }
65413 EXPORT_SYMBOL(capable);
65414
65415 +bool capable_nolog(int cap)
65416 +{
65417 + return ns_capable_nolog(&init_user_ns, cap);
65418 +}
65419 +EXPORT_SYMBOL(capable_nolog);
65420 +
65421 /**
65422 * nsown_capable - Check superior capability to one's own user_ns
65423 * @cap: The capability in question
65424 diff --git a/kernel/compat.c b/kernel/compat.c
65425 index f346ced..aa2b1f4 100644
65426 --- a/kernel/compat.c
65427 +++ b/kernel/compat.c
65428 @@ -13,6 +13,7 @@
65429
65430 #include <linux/linkage.h>
65431 #include <linux/compat.h>
65432 +#include <linux/module.h>
65433 #include <linux/errno.h>
65434 #include <linux/time.h>
65435 #include <linux/signal.h>
65436 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65437 mm_segment_t oldfs;
65438 long ret;
65439
65440 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65441 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65442 oldfs = get_fs();
65443 set_fs(KERNEL_DS);
65444 ret = hrtimer_nanosleep_restart(restart);
65445 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65446 oldfs = get_fs();
65447 set_fs(KERNEL_DS);
65448 ret = hrtimer_nanosleep(&tu,
65449 - rmtp ? (struct timespec __user *)&rmt : NULL,
65450 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65451 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65452 set_fs(oldfs);
65453
65454 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65455 mm_segment_t old_fs = get_fs();
65456
65457 set_fs(KERNEL_DS);
65458 - ret = sys_sigpending((old_sigset_t __user *) &s);
65459 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65460 set_fs(old_fs);
65461 if (ret == 0)
65462 ret = put_user(s, set);
65463 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65464 old_fs = get_fs();
65465 set_fs(KERNEL_DS);
65466 ret = sys_sigprocmask(how,
65467 - set ? (old_sigset_t __user *) &s : NULL,
65468 - oset ? (old_sigset_t __user *) &s : NULL);
65469 + set ? (old_sigset_t __force_user *) &s : NULL,
65470 + oset ? (old_sigset_t __force_user *) &s : NULL);
65471 set_fs(old_fs);
65472 if (ret == 0)
65473 if (oset)
65474 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65475 mm_segment_t old_fs = get_fs();
65476
65477 set_fs(KERNEL_DS);
65478 - ret = sys_old_getrlimit(resource, &r);
65479 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65480 set_fs(old_fs);
65481
65482 if (!ret) {
65483 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65484 mm_segment_t old_fs = get_fs();
65485
65486 set_fs(KERNEL_DS);
65487 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65488 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65489 set_fs(old_fs);
65490
65491 if (ret)
65492 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65493 set_fs (KERNEL_DS);
65494 ret = sys_wait4(pid,
65495 (stat_addr ?
65496 - (unsigned int __user *) &status : NULL),
65497 - options, (struct rusage __user *) &r);
65498 + (unsigned int __force_user *) &status : NULL),
65499 + options, (struct rusage __force_user *) &r);
65500 set_fs (old_fs);
65501
65502 if (ret > 0) {
65503 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65504 memset(&info, 0, sizeof(info));
65505
65506 set_fs(KERNEL_DS);
65507 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65508 - uru ? (struct rusage __user *)&ru : NULL);
65509 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65510 + uru ? (struct rusage __force_user *)&ru : NULL);
65511 set_fs(old_fs);
65512
65513 if ((ret < 0) || (info.si_signo == 0))
65514 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65515 oldfs = get_fs();
65516 set_fs(KERNEL_DS);
65517 err = sys_timer_settime(timer_id, flags,
65518 - (struct itimerspec __user *) &newts,
65519 - (struct itimerspec __user *) &oldts);
65520 + (struct itimerspec __force_user *) &newts,
65521 + (struct itimerspec __force_user *) &oldts);
65522 set_fs(oldfs);
65523 if (!err && old && put_compat_itimerspec(old, &oldts))
65524 return -EFAULT;
65525 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65526 oldfs = get_fs();
65527 set_fs(KERNEL_DS);
65528 err = sys_timer_gettime(timer_id,
65529 - (struct itimerspec __user *) &ts);
65530 + (struct itimerspec __force_user *) &ts);
65531 set_fs(oldfs);
65532 if (!err && put_compat_itimerspec(setting, &ts))
65533 return -EFAULT;
65534 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65535 oldfs = get_fs();
65536 set_fs(KERNEL_DS);
65537 err = sys_clock_settime(which_clock,
65538 - (struct timespec __user *) &ts);
65539 + (struct timespec __force_user *) &ts);
65540 set_fs(oldfs);
65541 return err;
65542 }
65543 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65544 oldfs = get_fs();
65545 set_fs(KERNEL_DS);
65546 err = sys_clock_gettime(which_clock,
65547 - (struct timespec __user *) &ts);
65548 + (struct timespec __force_user *) &ts);
65549 set_fs(oldfs);
65550 if (!err && put_compat_timespec(&ts, tp))
65551 return -EFAULT;
65552 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65553
65554 oldfs = get_fs();
65555 set_fs(KERNEL_DS);
65556 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65557 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65558 set_fs(oldfs);
65559
65560 err = compat_put_timex(utp, &txc);
65561 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65562 oldfs = get_fs();
65563 set_fs(KERNEL_DS);
65564 err = sys_clock_getres(which_clock,
65565 - (struct timespec __user *) &ts);
65566 + (struct timespec __force_user *) &ts);
65567 set_fs(oldfs);
65568 if (!err && tp && put_compat_timespec(&ts, tp))
65569 return -EFAULT;
65570 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65571 long err;
65572 mm_segment_t oldfs;
65573 struct timespec tu;
65574 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65575 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65576
65577 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65578 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65579 oldfs = get_fs();
65580 set_fs(KERNEL_DS);
65581 err = clock_nanosleep_restart(restart);
65582 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65583 oldfs = get_fs();
65584 set_fs(KERNEL_DS);
65585 err = sys_clock_nanosleep(which_clock, flags,
65586 - (struct timespec __user *) &in,
65587 - (struct timespec __user *) &out);
65588 + (struct timespec __force_user *) &in,
65589 + (struct timespec __force_user *) &out);
65590 set_fs(oldfs);
65591
65592 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65593 diff --git a/kernel/configs.c b/kernel/configs.c
65594 index 42e8fa0..9e7406b 100644
65595 --- a/kernel/configs.c
65596 +++ b/kernel/configs.c
65597 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65598 struct proc_dir_entry *entry;
65599
65600 /* create the current config file */
65601 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65602 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65603 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65604 + &ikconfig_file_ops);
65605 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65606 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65607 + &ikconfig_file_ops);
65608 +#endif
65609 +#else
65610 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65611 &ikconfig_file_ops);
65612 +#endif
65613 +
65614 if (!entry)
65615 return -ENOMEM;
65616
65617 diff --git a/kernel/cred.c b/kernel/cred.c
65618 index 5791612..a3c04dc 100644
65619 --- a/kernel/cred.c
65620 +++ b/kernel/cred.c
65621 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65622 validate_creds(cred);
65623 put_cred(cred);
65624 }
65625 +
65626 +#ifdef CONFIG_GRKERNSEC_SETXID
65627 + cred = (struct cred *) tsk->delayed_cred;
65628 + if (cred) {
65629 + tsk->delayed_cred = NULL;
65630 + validate_creds(cred);
65631 + put_cred(cred);
65632 + }
65633 +#endif
65634 }
65635
65636 /**
65637 @@ -470,7 +479,7 @@ error_put:
65638 * Always returns 0 thus allowing this function to be tail-called at the end
65639 * of, say, sys_setgid().
65640 */
65641 -int commit_creds(struct cred *new)
65642 +static int __commit_creds(struct cred *new)
65643 {
65644 struct task_struct *task = current;
65645 const struct cred *old = task->real_cred;
65646 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
65647
65648 get_cred(new); /* we will require a ref for the subj creds too */
65649
65650 + gr_set_role_label(task, new->uid, new->gid);
65651 +
65652 /* dumpability changes */
65653 if (old->euid != new->euid ||
65654 old->egid != new->egid ||
65655 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
65656 put_cred(old);
65657 return 0;
65658 }
65659 +#ifdef CONFIG_GRKERNSEC_SETXID
65660 +extern int set_user(struct cred *new);
65661 +
65662 +void gr_delayed_cred_worker(void)
65663 +{
65664 + const struct cred *new = current->delayed_cred;
65665 + struct cred *ncred;
65666 +
65667 + current->delayed_cred = NULL;
65668 +
65669 + if (current_uid() && new != NULL) {
65670 + // from doing get_cred on it when queueing this
65671 + put_cred(new);
65672 + return;
65673 + } else if (new == NULL)
65674 + return;
65675 +
65676 + ncred = prepare_creds();
65677 + if (!ncred)
65678 + goto die;
65679 + // uids
65680 + ncred->uid = new->uid;
65681 + ncred->euid = new->euid;
65682 + ncred->suid = new->suid;
65683 + ncred->fsuid = new->fsuid;
65684 + // gids
65685 + ncred->gid = new->gid;
65686 + ncred->egid = new->egid;
65687 + ncred->sgid = new->sgid;
65688 + ncred->fsgid = new->fsgid;
65689 + // groups
65690 + if (set_groups(ncred, new->group_info) < 0) {
65691 + abort_creds(ncred);
65692 + goto die;
65693 + }
65694 + // caps
65695 + ncred->securebits = new->securebits;
65696 + ncred->cap_inheritable = new->cap_inheritable;
65697 + ncred->cap_permitted = new->cap_permitted;
65698 + ncred->cap_effective = new->cap_effective;
65699 + ncred->cap_bset = new->cap_bset;
65700 +
65701 + if (set_user(ncred)) {
65702 + abort_creds(ncred);
65703 + goto die;
65704 + }
65705 +
65706 + // from doing get_cred on it when queueing this
65707 + put_cred(new);
65708 +
65709 + __commit_creds(ncred);
65710 + return;
65711 +die:
65712 + // from doing get_cred on it when queueing this
65713 + put_cred(new);
65714 + do_group_exit(SIGKILL);
65715 +}
65716 +#endif
65717 +
65718 +int commit_creds(struct cred *new)
65719 +{
65720 +#ifdef CONFIG_GRKERNSEC_SETXID
65721 + struct task_struct *t;
65722 +
65723 + /* we won't get called with tasklist_lock held for writing
65724 + and interrupts disabled as the cred struct in that case is
65725 + init_cred
65726 + */
65727 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65728 + !current_uid() && new->uid) {
65729 + rcu_read_lock();
65730 + read_lock(&tasklist_lock);
65731 + for (t = next_thread(current); t != current;
65732 + t = next_thread(t)) {
65733 + if (t->delayed_cred == NULL) {
65734 + t->delayed_cred = get_cred(new);
65735 + set_tsk_need_resched(t);
65736 + }
65737 + }
65738 + read_unlock(&tasklist_lock);
65739 + rcu_read_unlock();
65740 + }
65741 +#endif
65742 + return __commit_creds(new);
65743 +}
65744 +
65745 EXPORT_SYMBOL(commit_creds);
65746
65747 /**
65748 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65749 index 0d7c087..01b8cef 100644
65750 --- a/kernel/debug/debug_core.c
65751 +++ b/kernel/debug/debug_core.c
65752 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65753 */
65754 static atomic_t masters_in_kgdb;
65755 static atomic_t slaves_in_kgdb;
65756 -static atomic_t kgdb_break_tasklet_var;
65757 +static atomic_unchecked_t kgdb_break_tasklet_var;
65758 atomic_t kgdb_setting_breakpoint;
65759
65760 struct task_struct *kgdb_usethread;
65761 @@ -129,7 +129,7 @@ int kgdb_single_step;
65762 static pid_t kgdb_sstep_pid;
65763
65764 /* to keep track of the CPU which is doing the single stepping*/
65765 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65766 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65767
65768 /*
65769 * If you are debugging a problem where roundup (the collection of
65770 @@ -542,7 +542,7 @@ return_normal:
65771 * kernel will only try for the value of sstep_tries before
65772 * giving up and continuing on.
65773 */
65774 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65775 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65776 (kgdb_info[cpu].task &&
65777 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65778 atomic_set(&kgdb_active, -1);
65779 @@ -636,8 +636,8 @@ cpu_master_loop:
65780 }
65781
65782 kgdb_restore:
65783 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65784 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65785 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65786 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65787 if (kgdb_info[sstep_cpu].task)
65788 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65789 else
65790 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
65791 static void kgdb_tasklet_bpt(unsigned long ing)
65792 {
65793 kgdb_breakpoint();
65794 - atomic_set(&kgdb_break_tasklet_var, 0);
65795 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65796 }
65797
65798 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65799
65800 void kgdb_schedule_breakpoint(void)
65801 {
65802 - if (atomic_read(&kgdb_break_tasklet_var) ||
65803 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65804 atomic_read(&kgdb_active) != -1 ||
65805 atomic_read(&kgdb_setting_breakpoint))
65806 return;
65807 - atomic_inc(&kgdb_break_tasklet_var);
65808 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65809 tasklet_schedule(&kgdb_tasklet_breakpoint);
65810 }
65811 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65812 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65813 index e2ae734..08a4c5c 100644
65814 --- a/kernel/debug/kdb/kdb_main.c
65815 +++ b/kernel/debug/kdb/kdb_main.c
65816 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65817 list_for_each_entry(mod, kdb_modules, list) {
65818
65819 kdb_printf("%-20s%8u 0x%p ", mod->name,
65820 - mod->core_size, (void *)mod);
65821 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65822 #ifdef CONFIG_MODULE_UNLOAD
65823 kdb_printf("%4ld ", module_refcount(mod));
65824 #endif
65825 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65826 kdb_printf(" (Loading)");
65827 else
65828 kdb_printf(" (Live)");
65829 - kdb_printf(" 0x%p", mod->module_core);
65830 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65831
65832 #ifdef CONFIG_MODULE_UNLOAD
65833 {
65834 diff --git a/kernel/events/core.c b/kernel/events/core.c
65835 index 1b5c081..c375f83 100644
65836 --- a/kernel/events/core.c
65837 +++ b/kernel/events/core.c
65838 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65839 return 0;
65840 }
65841
65842 -static atomic64_t perf_event_id;
65843 +static atomic64_unchecked_t perf_event_id;
65844
65845 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65846 enum event_type_t event_type);
65847 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65848
65849 static inline u64 perf_event_count(struct perf_event *event)
65850 {
65851 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65852 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65853 }
65854
65855 static u64 perf_event_read(struct perf_event *event)
65856 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65857 mutex_lock(&event->child_mutex);
65858 total += perf_event_read(event);
65859 *enabled += event->total_time_enabled +
65860 - atomic64_read(&event->child_total_time_enabled);
65861 + atomic64_read_unchecked(&event->child_total_time_enabled);
65862 *running += event->total_time_running +
65863 - atomic64_read(&event->child_total_time_running);
65864 + atomic64_read_unchecked(&event->child_total_time_running);
65865
65866 list_for_each_entry(child, &event->child_list, child_list) {
65867 total += perf_event_read(child);
65868 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65869 userpg->offset -= local64_read(&event->hw.prev_count);
65870
65871 userpg->time_enabled = enabled +
65872 - atomic64_read(&event->child_total_time_enabled);
65873 + atomic64_read_unchecked(&event->child_total_time_enabled);
65874
65875 userpg->time_running = running +
65876 - atomic64_read(&event->child_total_time_running);
65877 + atomic64_read_unchecked(&event->child_total_time_running);
65878
65879 barrier();
65880 ++userpg->lock;
65881 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65882 values[n++] = perf_event_count(event);
65883 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65884 values[n++] = enabled +
65885 - atomic64_read(&event->child_total_time_enabled);
65886 + atomic64_read_unchecked(&event->child_total_time_enabled);
65887 }
65888 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65889 values[n++] = running +
65890 - atomic64_read(&event->child_total_time_running);
65891 + atomic64_read_unchecked(&event->child_total_time_running);
65892 }
65893 if (read_format & PERF_FORMAT_ID)
65894 values[n++] = primary_event_id(event);
65895 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65896 * need to add enough zero bytes after the string to handle
65897 * the 64bit alignment we do later.
65898 */
65899 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65900 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65901 if (!buf) {
65902 name = strncpy(tmp, "//enomem", sizeof(tmp));
65903 goto got_name;
65904 }
65905 - name = d_path(&file->f_path, buf, PATH_MAX);
65906 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65907 if (IS_ERR(name)) {
65908 name = strncpy(tmp, "//toolong", sizeof(tmp));
65909 goto got_name;
65910 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65911 event->parent = parent_event;
65912
65913 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65914 - event->id = atomic64_inc_return(&perf_event_id);
65915 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65916
65917 event->state = PERF_EVENT_STATE_INACTIVE;
65918
65919 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65920 /*
65921 * Add back the child's count to the parent's count:
65922 */
65923 - atomic64_add(child_val, &parent_event->child_count);
65924 - atomic64_add(child_event->total_time_enabled,
65925 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65926 + atomic64_add_unchecked(child_event->total_time_enabled,
65927 &parent_event->child_total_time_enabled);
65928 - atomic64_add(child_event->total_time_running,
65929 + atomic64_add_unchecked(child_event->total_time_running,
65930 &parent_event->child_total_time_running);
65931
65932 /*
65933 diff --git a/kernel/exit.c b/kernel/exit.c
65934 index 4b4042f..5bdd8d5 100644
65935 --- a/kernel/exit.c
65936 +++ b/kernel/exit.c
65937 @@ -58,6 +58,10 @@
65938 #include <asm/pgtable.h>
65939 #include <asm/mmu_context.h>
65940
65941 +#ifdef CONFIG_GRKERNSEC
65942 +extern rwlock_t grsec_exec_file_lock;
65943 +#endif
65944 +
65945 static void exit_mm(struct task_struct * tsk);
65946
65947 static void __unhash_process(struct task_struct *p, bool group_dead)
65948 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
65949 struct task_struct *leader;
65950 int zap_leader;
65951 repeat:
65952 +#ifdef CONFIG_NET
65953 + gr_del_task_from_ip_table(p);
65954 +#endif
65955 +
65956 /* don't need to get the RCU readlock here - the process is dead and
65957 * can't be modifying its own credentials. But shut RCU-lockdep up */
65958 rcu_read_lock();
65959 @@ -381,7 +389,7 @@ int allow_signal(int sig)
65960 * know it'll be handled, so that they don't get converted to
65961 * SIGKILL or just silently dropped.
65962 */
65963 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65964 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65965 recalc_sigpending();
65966 spin_unlock_irq(&current->sighand->siglock);
65967 return 0;
65968 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
65969 vsnprintf(current->comm, sizeof(current->comm), name, args);
65970 va_end(args);
65971
65972 +#ifdef CONFIG_GRKERNSEC
65973 + write_lock(&grsec_exec_file_lock);
65974 + if (current->exec_file) {
65975 + fput(current->exec_file);
65976 + current->exec_file = NULL;
65977 + }
65978 + write_unlock(&grsec_exec_file_lock);
65979 +#endif
65980 +
65981 + gr_set_kernel_label(current);
65982 +
65983 /*
65984 * If we were started as result of loading a module, close all of the
65985 * user space pages. We don't need them, and if we didn't close them
65986 @@ -892,6 +911,8 @@ void do_exit(long code)
65987 struct task_struct *tsk = current;
65988 int group_dead;
65989
65990 + set_fs(USER_DS);
65991 +
65992 profile_task_exit(tsk);
65993
65994 WARN_ON(blk_needs_flush_plug(tsk));
65995 @@ -908,7 +929,6 @@ void do_exit(long code)
65996 * mm_release()->clear_child_tid() from writing to a user-controlled
65997 * kernel address.
65998 */
65999 - set_fs(USER_DS);
66000
66001 ptrace_event(PTRACE_EVENT_EXIT, code);
66002
66003 @@ -969,6 +989,9 @@ void do_exit(long code)
66004 tsk->exit_code = code;
66005 taskstats_exit(tsk, group_dead);
66006
66007 + gr_acl_handle_psacct(tsk, code);
66008 + gr_acl_handle_exit();
66009 +
66010 exit_mm(tsk);
66011
66012 if (group_dead)
66013 @@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66014 * Take down every thread in the group. This is called by fatal signals
66015 * as well as by sys_exit_group (below).
66016 */
66017 -void
66018 +__noreturn void
66019 do_group_exit(int exit_code)
66020 {
66021 struct signal_struct *sig = current->signal;
66022 diff --git a/kernel/fork.c b/kernel/fork.c
66023 index 26a7a67..a1053f9 100644
66024 --- a/kernel/fork.c
66025 +++ b/kernel/fork.c
66026 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66027 *stackend = STACK_END_MAGIC; /* for overflow detection */
66028
66029 #ifdef CONFIG_CC_STACKPROTECTOR
66030 - tsk->stack_canary = get_random_int();
66031 + tsk->stack_canary = pax_get_random_long();
66032 #endif
66033
66034 /*
66035 @@ -308,13 +308,77 @@ out:
66036 }
66037
66038 #ifdef CONFIG_MMU
66039 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66040 +{
66041 + struct vm_area_struct *tmp;
66042 + unsigned long charge;
66043 + struct mempolicy *pol;
66044 + struct file *file;
66045 +
66046 + charge = 0;
66047 + if (mpnt->vm_flags & VM_ACCOUNT) {
66048 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66049 + if (security_vm_enough_memory(len))
66050 + goto fail_nomem;
66051 + charge = len;
66052 + }
66053 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66054 + if (!tmp)
66055 + goto fail_nomem;
66056 + *tmp = *mpnt;
66057 + tmp->vm_mm = mm;
66058 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66059 + pol = mpol_dup(vma_policy(mpnt));
66060 + if (IS_ERR(pol))
66061 + goto fail_nomem_policy;
66062 + vma_set_policy(tmp, pol);
66063 + if (anon_vma_fork(tmp, mpnt))
66064 + goto fail_nomem_anon_vma_fork;
66065 + tmp->vm_flags &= ~VM_LOCKED;
66066 + tmp->vm_next = tmp->vm_prev = NULL;
66067 + tmp->vm_mirror = NULL;
66068 + file = tmp->vm_file;
66069 + if (file) {
66070 + struct inode *inode = file->f_path.dentry->d_inode;
66071 + struct address_space *mapping = file->f_mapping;
66072 +
66073 + get_file(file);
66074 + if (tmp->vm_flags & VM_DENYWRITE)
66075 + atomic_dec(&inode->i_writecount);
66076 + mutex_lock(&mapping->i_mmap_mutex);
66077 + if (tmp->vm_flags & VM_SHARED)
66078 + mapping->i_mmap_writable++;
66079 + flush_dcache_mmap_lock(mapping);
66080 + /* insert tmp into the share list, just after mpnt */
66081 + vma_prio_tree_add(tmp, mpnt);
66082 + flush_dcache_mmap_unlock(mapping);
66083 + mutex_unlock(&mapping->i_mmap_mutex);
66084 + }
66085 +
66086 + /*
66087 + * Clear hugetlb-related page reserves for children. This only
66088 + * affects MAP_PRIVATE mappings. Faults generated by the child
66089 + * are not guaranteed to succeed, even if read-only
66090 + */
66091 + if (is_vm_hugetlb_page(tmp))
66092 + reset_vma_resv_huge_pages(tmp);
66093 +
66094 + return tmp;
66095 +
66096 +fail_nomem_anon_vma_fork:
66097 + mpol_put(pol);
66098 +fail_nomem_policy:
66099 + kmem_cache_free(vm_area_cachep, tmp);
66100 +fail_nomem:
66101 + vm_unacct_memory(charge);
66102 + return NULL;
66103 +}
66104 +
66105 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66106 {
66107 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66108 struct rb_node **rb_link, *rb_parent;
66109 int retval;
66110 - unsigned long charge;
66111 - struct mempolicy *pol;
66112
66113 down_write(&oldmm->mmap_sem);
66114 flush_cache_dup_mm(oldmm);
66115 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66116 mm->locked_vm = 0;
66117 mm->mmap = NULL;
66118 mm->mmap_cache = NULL;
66119 - mm->free_area_cache = oldmm->mmap_base;
66120 - mm->cached_hole_size = ~0UL;
66121 + mm->free_area_cache = oldmm->free_area_cache;
66122 + mm->cached_hole_size = oldmm->cached_hole_size;
66123 mm->map_count = 0;
66124 cpumask_clear(mm_cpumask(mm));
66125 mm->mm_rb = RB_ROOT;
66126 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66127
66128 prev = NULL;
66129 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66130 - struct file *file;
66131 -
66132 if (mpnt->vm_flags & VM_DONTCOPY) {
66133 long pages = vma_pages(mpnt);
66134 mm->total_vm -= pages;
66135 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66136 -pages);
66137 continue;
66138 }
66139 - charge = 0;
66140 - if (mpnt->vm_flags & VM_ACCOUNT) {
66141 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66142 - if (security_vm_enough_memory(len))
66143 - goto fail_nomem;
66144 - charge = len;
66145 + tmp = dup_vma(mm, mpnt);
66146 + if (!tmp) {
66147 + retval = -ENOMEM;
66148 + goto out;
66149 }
66150 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66151 - if (!tmp)
66152 - goto fail_nomem;
66153 - *tmp = *mpnt;
66154 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66155 - pol = mpol_dup(vma_policy(mpnt));
66156 - retval = PTR_ERR(pol);
66157 - if (IS_ERR(pol))
66158 - goto fail_nomem_policy;
66159 - vma_set_policy(tmp, pol);
66160 - tmp->vm_mm = mm;
66161 - if (anon_vma_fork(tmp, mpnt))
66162 - goto fail_nomem_anon_vma_fork;
66163 - tmp->vm_flags &= ~VM_LOCKED;
66164 - tmp->vm_next = tmp->vm_prev = NULL;
66165 - file = tmp->vm_file;
66166 - if (file) {
66167 - struct inode *inode = file->f_path.dentry->d_inode;
66168 - struct address_space *mapping = file->f_mapping;
66169 -
66170 - get_file(file);
66171 - if (tmp->vm_flags & VM_DENYWRITE)
66172 - atomic_dec(&inode->i_writecount);
66173 - mutex_lock(&mapping->i_mmap_mutex);
66174 - if (tmp->vm_flags & VM_SHARED)
66175 - mapping->i_mmap_writable++;
66176 - flush_dcache_mmap_lock(mapping);
66177 - /* insert tmp into the share list, just after mpnt */
66178 - vma_prio_tree_add(tmp, mpnt);
66179 - flush_dcache_mmap_unlock(mapping);
66180 - mutex_unlock(&mapping->i_mmap_mutex);
66181 - }
66182 -
66183 - /*
66184 - * Clear hugetlb-related page reserves for children. This only
66185 - * affects MAP_PRIVATE mappings. Faults generated by the child
66186 - * are not guaranteed to succeed, even if read-only
66187 - */
66188 - if (is_vm_hugetlb_page(tmp))
66189 - reset_vma_resv_huge_pages(tmp);
66190
66191 /*
66192 * Link in the new vma and copy the page table entries.
66193 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66194 if (retval)
66195 goto out;
66196 }
66197 +
66198 +#ifdef CONFIG_PAX_SEGMEXEC
66199 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66200 + struct vm_area_struct *mpnt_m;
66201 +
66202 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66203 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66204 +
66205 + if (!mpnt->vm_mirror)
66206 + continue;
66207 +
66208 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66209 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66210 + mpnt->vm_mirror = mpnt_m;
66211 + } else {
66212 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66213 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66214 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66215 + mpnt->vm_mirror->vm_mirror = mpnt;
66216 + }
66217 + }
66218 + BUG_ON(mpnt_m);
66219 + }
66220 +#endif
66221 +
66222 /* a new mm has just been created */
66223 arch_dup_mmap(oldmm, mm);
66224 retval = 0;
66225 @@ -429,14 +474,6 @@ out:
66226 flush_tlb_mm(oldmm);
66227 up_write(&oldmm->mmap_sem);
66228 return retval;
66229 -fail_nomem_anon_vma_fork:
66230 - mpol_put(pol);
66231 -fail_nomem_policy:
66232 - kmem_cache_free(vm_area_cachep, tmp);
66233 -fail_nomem:
66234 - retval = -ENOMEM;
66235 - vm_unacct_memory(charge);
66236 - goto out;
66237 }
66238
66239 static inline int mm_alloc_pgd(struct mm_struct *mm)
66240 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66241 return ERR_PTR(err);
66242
66243 mm = get_task_mm(task);
66244 - if (mm && mm != current->mm &&
66245 - !ptrace_may_access(task, mode)) {
66246 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66247 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66248 mmput(mm);
66249 mm = ERR_PTR(-EACCES);
66250 }
66251 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66252 spin_unlock(&fs->lock);
66253 return -EAGAIN;
66254 }
66255 - fs->users++;
66256 + atomic_inc(&fs->users);
66257 spin_unlock(&fs->lock);
66258 return 0;
66259 }
66260 tsk->fs = copy_fs_struct(fs);
66261 if (!tsk->fs)
66262 return -ENOMEM;
66263 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66264 return 0;
66265 }
66266
66267 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66268 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66269 #endif
66270 retval = -EAGAIN;
66271 +
66272 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66273 +
66274 if (atomic_read(&p->real_cred->user->processes) >=
66275 task_rlimit(p, RLIMIT_NPROC)) {
66276 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66277 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66278 if (clone_flags & CLONE_THREAD)
66279 p->tgid = current->tgid;
66280
66281 + gr_copy_label(p);
66282 +
66283 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66284 /*
66285 * Clear TID on mm_release()?
66286 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
66287 bad_fork_free:
66288 free_task(p);
66289 fork_out:
66290 + gr_log_forkfail(retval);
66291 +
66292 return ERR_PTR(retval);
66293 }
66294
66295 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
66296 if (clone_flags & CLONE_PARENT_SETTID)
66297 put_user(nr, parent_tidptr);
66298
66299 + gr_handle_brute_check();
66300 +
66301 if (clone_flags & CLONE_VFORK) {
66302 p->vfork_done = &vfork;
66303 init_completion(&vfork);
66304 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66305 return 0;
66306
66307 /* don't need lock here; in the worst case we'll do useless copy */
66308 - if (fs->users == 1)
66309 + if (atomic_read(&fs->users) == 1)
66310 return 0;
66311
66312 *new_fsp = copy_fs_struct(fs);
66313 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66314 fs = current->fs;
66315 spin_lock(&fs->lock);
66316 current->fs = new_fs;
66317 - if (--fs->users)
66318 + gr_set_chroot_entries(current, &current->fs->root);
66319 + if (atomic_dec_return(&fs->users))
66320 new_fs = NULL;
66321 else
66322 new_fs = fs;
66323 diff --git a/kernel/futex.c b/kernel/futex.c
66324 index 0677023..f3c3b79 100644
66325 --- a/kernel/futex.c
66326 +++ b/kernel/futex.c
66327 @@ -54,6 +54,7 @@
66328 #include <linux/mount.h>
66329 #include <linux/pagemap.h>
66330 #include <linux/syscalls.h>
66331 +#include <linux/ptrace.h>
66332 #include <linux/signal.h>
66333 #include <linux/export.h>
66334 #include <linux/magic.h>
66335 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66336 struct page *page, *page_head;
66337 int err, ro = 0;
66338
66339 +#ifdef CONFIG_PAX_SEGMEXEC
66340 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66341 + return -EFAULT;
66342 +#endif
66343 +
66344 /*
66345 * The futex address must be "naturally" aligned.
66346 */
66347 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66348 if (!p)
66349 goto err_unlock;
66350 ret = -EPERM;
66351 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66352 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66353 + goto err_unlock;
66354 +#endif
66355 pcred = __task_cred(p);
66356 /* If victim is in different user_ns, then uids are not
66357 comparable, so we must have CAP_SYS_PTRACE */
66358 @@ -2731,6 +2741,7 @@ static int __init futex_init(void)
66359 {
66360 u32 curval;
66361 int i;
66362 + mm_segment_t oldfs;
66363
66364 /*
66365 * This will fail and we want it. Some arch implementations do
66366 @@ -2742,8 +2753,11 @@ static int __init futex_init(void)
66367 * implementation, the non-functional ones will return
66368 * -ENOSYS.
66369 */
66370 + oldfs = get_fs();
66371 + set_fs(USER_DS);
66372 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66373 futex_cmpxchg_enabled = 1;
66374 + set_fs(oldfs);
66375
66376 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66377 plist_head_init(&futex_queues[i].chain);
66378 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66379 index 5f9e689..582d46d 100644
66380 --- a/kernel/futex_compat.c
66381 +++ b/kernel/futex_compat.c
66382 @@ -10,6 +10,7 @@
66383 #include <linux/compat.h>
66384 #include <linux/nsproxy.h>
66385 #include <linux/futex.h>
66386 +#include <linux/ptrace.h>
66387
66388 #include <asm/uaccess.h>
66389
66390 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66391 {
66392 struct compat_robust_list_head __user *head;
66393 unsigned long ret;
66394 - const struct cred *cred = current_cred(), *pcred;
66395 + const struct cred *cred = current_cred();
66396 + const struct cred *pcred;
66397
66398 if (!futex_cmpxchg_enabled)
66399 return -ENOSYS;
66400 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66401 if (!p)
66402 goto err_unlock;
66403 ret = -EPERM;
66404 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66405 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66406 + goto err_unlock;
66407 +#endif
66408 pcred = __task_cred(p);
66409 /* If victim is in different user_ns, then uids are not
66410 comparable, so we must have CAP_SYS_PTRACE */
66411 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66412 index 9b22d03..6295b62 100644
66413 --- a/kernel/gcov/base.c
66414 +++ b/kernel/gcov/base.c
66415 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66416 }
66417
66418 #ifdef CONFIG_MODULES
66419 -static inline int within(void *addr, void *start, unsigned long size)
66420 -{
66421 - return ((addr >= start) && (addr < start + size));
66422 -}
66423 -
66424 /* Update list and generate events when modules are unloaded. */
66425 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66426 void *data)
66427 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66428 prev = NULL;
66429 /* Remove entries located in module from linked list. */
66430 for (info = gcov_info_head; info; info = info->next) {
66431 - if (within(info, mod->module_core, mod->core_size)) {
66432 + if (within_module_core_rw((unsigned long)info, mod)) {
66433 if (prev)
66434 prev->next = info->next;
66435 else
66436 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66437 index ae34bf5..4e2f3d0 100644
66438 --- a/kernel/hrtimer.c
66439 +++ b/kernel/hrtimer.c
66440 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66441 local_irq_restore(flags);
66442 }
66443
66444 -static void run_hrtimer_softirq(struct softirq_action *h)
66445 +static void run_hrtimer_softirq(void)
66446 {
66447 hrtimer_peek_ahead_timers();
66448 }
66449 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66450 index 01d3b70..9e4d098 100644
66451 --- a/kernel/jump_label.c
66452 +++ b/kernel/jump_label.c
66453 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66454
66455 size = (((unsigned long)stop - (unsigned long)start)
66456 / sizeof(struct jump_entry));
66457 + pax_open_kernel();
66458 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66459 + pax_close_kernel();
66460 }
66461
66462 static void jump_label_update(struct jump_label_key *key, int enable);
66463 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66464 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66465 struct jump_entry *iter;
66466
66467 + pax_open_kernel();
66468 for (iter = iter_start; iter < iter_stop; iter++) {
66469 if (within_module_init(iter->code, mod))
66470 iter->code = 0;
66471 }
66472 + pax_close_kernel();
66473 }
66474
66475 static int
66476 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66477 index 079f1d3..a407562 100644
66478 --- a/kernel/kallsyms.c
66479 +++ b/kernel/kallsyms.c
66480 @@ -11,6 +11,9 @@
66481 * Changed the compression method from stem compression to "table lookup"
66482 * compression (see scripts/kallsyms.c for a more complete description)
66483 */
66484 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66485 +#define __INCLUDED_BY_HIDESYM 1
66486 +#endif
66487 #include <linux/kallsyms.h>
66488 #include <linux/module.h>
66489 #include <linux/init.h>
66490 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66491
66492 static inline int is_kernel_inittext(unsigned long addr)
66493 {
66494 + if (system_state != SYSTEM_BOOTING)
66495 + return 0;
66496 +
66497 if (addr >= (unsigned long)_sinittext
66498 && addr <= (unsigned long)_einittext)
66499 return 1;
66500 return 0;
66501 }
66502
66503 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66504 +#ifdef CONFIG_MODULES
66505 +static inline int is_module_text(unsigned long addr)
66506 +{
66507 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66508 + return 1;
66509 +
66510 + addr = ktla_ktva(addr);
66511 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66512 +}
66513 +#else
66514 +static inline int is_module_text(unsigned long addr)
66515 +{
66516 + return 0;
66517 +}
66518 +#endif
66519 +#endif
66520 +
66521 static inline int is_kernel_text(unsigned long addr)
66522 {
66523 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66524 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66525
66526 static inline int is_kernel(unsigned long addr)
66527 {
66528 +
66529 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66530 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66531 + return 1;
66532 +
66533 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66534 +#else
66535 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66536 +#endif
66537 +
66538 return 1;
66539 return in_gate_area_no_mm(addr);
66540 }
66541
66542 static int is_ksym_addr(unsigned long addr)
66543 {
66544 +
66545 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66546 + if (is_module_text(addr))
66547 + return 0;
66548 +#endif
66549 +
66550 if (all_var)
66551 return is_kernel(addr);
66552
66553 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66554
66555 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66556 {
66557 - iter->name[0] = '\0';
66558 iter->nameoff = get_symbol_offset(new_pos);
66559 iter->pos = new_pos;
66560 }
66561 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66562 {
66563 struct kallsym_iter *iter = m->private;
66564
66565 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66566 + if (current_uid())
66567 + return 0;
66568 +#endif
66569 +
66570 /* Some debugging symbols have no name. Ignore them. */
66571 if (!iter->name[0])
66572 return 0;
66573 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66574 struct kallsym_iter *iter;
66575 int ret;
66576
66577 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66578 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66579 if (!iter)
66580 return -ENOMEM;
66581 reset_iter(iter, 0);
66582 diff --git a/kernel/kexec.c b/kernel/kexec.c
66583 index 7b08867..3bac516 100644
66584 --- a/kernel/kexec.c
66585 +++ b/kernel/kexec.c
66586 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66587 unsigned long flags)
66588 {
66589 struct compat_kexec_segment in;
66590 - struct kexec_segment out, __user *ksegments;
66591 + struct kexec_segment out;
66592 + struct kexec_segment __user *ksegments;
66593 unsigned long i, result;
66594
66595 /* Don't allow clients that don't understand the native
66596 diff --git a/kernel/kmod.c b/kernel/kmod.c
66597 index a0a8854..642b106 100644
66598 --- a/kernel/kmod.c
66599 +++ b/kernel/kmod.c
66600 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66601 * If module auto-loading support is disabled then this function
66602 * becomes a no-operation.
66603 */
66604 -int __request_module(bool wait, const char *fmt, ...)
66605 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66606 {
66607 - va_list args;
66608 char module_name[MODULE_NAME_LEN];
66609 unsigned int max_modprobes;
66610 int ret;
66611 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66612 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66613 static char *envp[] = { "HOME=/",
66614 "TERM=linux",
66615 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66616 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66617 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66618 static int kmod_loop_msg;
66619
66620 - va_start(args, fmt);
66621 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66622 - va_end(args);
66623 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66624 if (ret >= MODULE_NAME_LEN)
66625 return -ENAMETOOLONG;
66626
66627 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66628 if (ret)
66629 return ret;
66630
66631 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66632 + if (!current_uid()) {
66633 + /* hack to workaround consolekit/udisks stupidity */
66634 + read_lock(&tasklist_lock);
66635 + if (!strcmp(current->comm, "mount") &&
66636 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66637 + read_unlock(&tasklist_lock);
66638 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66639 + return -EPERM;
66640 + }
66641 + read_unlock(&tasklist_lock);
66642 + }
66643 +#endif
66644 +
66645 /* If modprobe needs a service that is in a module, we get a recursive
66646 * loop. Limit the number of running kmod threads to max_threads/2 or
66647 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66648 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66649 atomic_dec(&kmod_concurrent);
66650 return ret;
66651 }
66652 +
66653 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66654 +{
66655 + va_list args;
66656 + int ret;
66657 +
66658 + va_start(args, fmt);
66659 + ret = ____request_module(wait, module_param, fmt, args);
66660 + va_end(args);
66661 +
66662 + return ret;
66663 +}
66664 +
66665 +int __request_module(bool wait, const char *fmt, ...)
66666 +{
66667 + va_list args;
66668 + int ret;
66669 +
66670 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66671 + if (current_uid()) {
66672 + char module_param[MODULE_NAME_LEN];
66673 +
66674 + memset(module_param, 0, sizeof(module_param));
66675 +
66676 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66677 +
66678 + va_start(args, fmt);
66679 + ret = ____request_module(wait, module_param, fmt, args);
66680 + va_end(args);
66681 +
66682 + return ret;
66683 + }
66684 +#endif
66685 +
66686 + va_start(args, fmt);
66687 + ret = ____request_module(wait, NULL, fmt, args);
66688 + va_end(args);
66689 +
66690 + return ret;
66691 +}
66692 +
66693 EXPORT_SYMBOL(__request_module);
66694 #endif /* CONFIG_MODULES */
66695
66696 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66697 *
66698 * Thus the __user pointer cast is valid here.
66699 */
66700 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66701 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66702
66703 /*
66704 * If ret is 0, either ____call_usermodehelper failed and the
66705 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66706 index c62b854..cb67968 100644
66707 --- a/kernel/kprobes.c
66708 +++ b/kernel/kprobes.c
66709 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66710 * kernel image and loaded module images reside. This is required
66711 * so x86_64 can correctly handle the %rip-relative fixups.
66712 */
66713 - kip->insns = module_alloc(PAGE_SIZE);
66714 + kip->insns = module_alloc_exec(PAGE_SIZE);
66715 if (!kip->insns) {
66716 kfree(kip);
66717 return NULL;
66718 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66719 */
66720 if (!list_is_singular(&kip->list)) {
66721 list_del(&kip->list);
66722 - module_free(NULL, kip->insns);
66723 + module_free_exec(NULL, kip->insns);
66724 kfree(kip);
66725 }
66726 return 1;
66727 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66728 {
66729 int i, err = 0;
66730 unsigned long offset = 0, size = 0;
66731 - char *modname, namebuf[128];
66732 + char *modname, namebuf[KSYM_NAME_LEN];
66733 const char *symbol_name;
66734 void *addr;
66735 struct kprobe_blackpoint *kb;
66736 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66737 const char *sym = NULL;
66738 unsigned int i = *(loff_t *) v;
66739 unsigned long offset = 0;
66740 - char *modname, namebuf[128];
66741 + char *modname, namebuf[KSYM_NAME_LEN];
66742
66743 head = &kprobe_table[i];
66744 preempt_disable();
66745 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66746 index 4e316e1..5501eef 100644
66747 --- a/kernel/ksysfs.c
66748 +++ b/kernel/ksysfs.c
66749 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66750 {
66751 if (count+1 > UEVENT_HELPER_PATH_LEN)
66752 return -ENOENT;
66753 + if (!capable(CAP_SYS_ADMIN))
66754 + return -EPERM;
66755 memcpy(uevent_helper, buf, count);
66756 uevent_helper[count] = '\0';
66757 if (count && uevent_helper[count-1] == '\n')
66758 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66759 index 8889f7d..95319b7 100644
66760 --- a/kernel/lockdep.c
66761 +++ b/kernel/lockdep.c
66762 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66763 end = (unsigned long) &_end,
66764 addr = (unsigned long) obj;
66765
66766 +#ifdef CONFIG_PAX_KERNEXEC
66767 + start = ktla_ktva(start);
66768 +#endif
66769 +
66770 /*
66771 * static variable?
66772 */
66773 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66774 if (!static_obj(lock->key)) {
66775 debug_locks_off();
66776 printk("INFO: trying to register non-static key.\n");
66777 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66778 printk("the code is fine but needs lockdep annotation.\n");
66779 printk("turning off the locking correctness validator.\n");
66780 dump_stack();
66781 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66782 if (!class)
66783 return 0;
66784 }
66785 - atomic_inc((atomic_t *)&class->ops);
66786 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66787 if (very_verbose(class)) {
66788 printk("\nacquire class [%p] %s", class->key, class->name);
66789 if (class->name_version > 1)
66790 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66791 index 91c32a0..b2c71c5 100644
66792 --- a/kernel/lockdep_proc.c
66793 +++ b/kernel/lockdep_proc.c
66794 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66795
66796 static void print_name(struct seq_file *m, struct lock_class *class)
66797 {
66798 - char str[128];
66799 + char str[KSYM_NAME_LEN];
66800 const char *name = class->name;
66801
66802 if (!name) {
66803 diff --git a/kernel/module.c b/kernel/module.c
66804 index 3d56b6f..2a22bd0 100644
66805 --- a/kernel/module.c
66806 +++ b/kernel/module.c
66807 @@ -58,6 +58,7 @@
66808 #include <linux/jump_label.h>
66809 #include <linux/pfn.h>
66810 #include <linux/bsearch.h>
66811 +#include <linux/grsecurity.h>
66812
66813 #define CREATE_TRACE_POINTS
66814 #include <trace/events/module.h>
66815 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66816
66817 /* Bounds of module allocation, for speeding __module_address.
66818 * Protected by module_mutex. */
66819 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66820 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66821 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66822
66823 int register_module_notifier(struct notifier_block * nb)
66824 {
66825 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66826 return true;
66827
66828 list_for_each_entry_rcu(mod, &modules, list) {
66829 - struct symsearch arr[] = {
66830 + struct symsearch modarr[] = {
66831 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66832 NOT_GPL_ONLY, false },
66833 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66834 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66835 #endif
66836 };
66837
66838 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66839 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66840 return true;
66841 }
66842 return false;
66843 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66844 static int percpu_modalloc(struct module *mod,
66845 unsigned long size, unsigned long align)
66846 {
66847 - if (align > PAGE_SIZE) {
66848 + if (align-1 >= PAGE_SIZE) {
66849 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66850 mod->name, align, PAGE_SIZE);
66851 align = PAGE_SIZE;
66852 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66853 static ssize_t show_coresize(struct module_attribute *mattr,
66854 struct module_kobject *mk, char *buffer)
66855 {
66856 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66857 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66858 }
66859
66860 static struct module_attribute modinfo_coresize =
66861 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66862 static ssize_t show_initsize(struct module_attribute *mattr,
66863 struct module_kobject *mk, char *buffer)
66864 {
66865 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66866 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66867 }
66868
66869 static struct module_attribute modinfo_initsize =
66870 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66871 */
66872 #ifdef CONFIG_SYSFS
66873
66874 -#ifdef CONFIG_KALLSYMS
66875 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66876 static inline bool sect_empty(const Elf_Shdr *sect)
66877 {
66878 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66879 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66880
66881 static void unset_module_core_ro_nx(struct module *mod)
66882 {
66883 - set_page_attributes(mod->module_core + mod->core_text_size,
66884 - mod->module_core + mod->core_size,
66885 + set_page_attributes(mod->module_core_rw,
66886 + mod->module_core_rw + mod->core_size_rw,
66887 set_memory_x);
66888 - set_page_attributes(mod->module_core,
66889 - mod->module_core + mod->core_ro_size,
66890 + set_page_attributes(mod->module_core_rx,
66891 + mod->module_core_rx + mod->core_size_rx,
66892 set_memory_rw);
66893 }
66894
66895 static void unset_module_init_ro_nx(struct module *mod)
66896 {
66897 - set_page_attributes(mod->module_init + mod->init_text_size,
66898 - mod->module_init + mod->init_size,
66899 + set_page_attributes(mod->module_init_rw,
66900 + mod->module_init_rw + mod->init_size_rw,
66901 set_memory_x);
66902 - set_page_attributes(mod->module_init,
66903 - mod->module_init + mod->init_ro_size,
66904 + set_page_attributes(mod->module_init_rx,
66905 + mod->module_init_rx + mod->init_size_rx,
66906 set_memory_rw);
66907 }
66908
66909 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66910
66911 mutex_lock(&module_mutex);
66912 list_for_each_entry_rcu(mod, &modules, list) {
66913 - if ((mod->module_core) && (mod->core_text_size)) {
66914 - set_page_attributes(mod->module_core,
66915 - mod->module_core + mod->core_text_size,
66916 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66917 + set_page_attributes(mod->module_core_rx,
66918 + mod->module_core_rx + mod->core_size_rx,
66919 set_memory_rw);
66920 }
66921 - if ((mod->module_init) && (mod->init_text_size)) {
66922 - set_page_attributes(mod->module_init,
66923 - mod->module_init + mod->init_text_size,
66924 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66925 + set_page_attributes(mod->module_init_rx,
66926 + mod->module_init_rx + mod->init_size_rx,
66927 set_memory_rw);
66928 }
66929 }
66930 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66931
66932 mutex_lock(&module_mutex);
66933 list_for_each_entry_rcu(mod, &modules, list) {
66934 - if ((mod->module_core) && (mod->core_text_size)) {
66935 - set_page_attributes(mod->module_core,
66936 - mod->module_core + mod->core_text_size,
66937 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66938 + set_page_attributes(mod->module_core_rx,
66939 + mod->module_core_rx + mod->core_size_rx,
66940 set_memory_ro);
66941 }
66942 - if ((mod->module_init) && (mod->init_text_size)) {
66943 - set_page_attributes(mod->module_init,
66944 - mod->module_init + mod->init_text_size,
66945 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66946 + set_page_attributes(mod->module_init_rx,
66947 + mod->module_init_rx + mod->init_size_rx,
66948 set_memory_ro);
66949 }
66950 }
66951 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66952
66953 /* This may be NULL, but that's OK */
66954 unset_module_init_ro_nx(mod);
66955 - module_free(mod, mod->module_init);
66956 + module_free(mod, mod->module_init_rw);
66957 + module_free_exec(mod, mod->module_init_rx);
66958 kfree(mod->args);
66959 percpu_modfree(mod);
66960
66961 /* Free lock-classes: */
66962 - lockdep_free_key_range(mod->module_core, mod->core_size);
66963 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66964 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66965
66966 /* Finally, free the core (containing the module structure) */
66967 unset_module_core_ro_nx(mod);
66968 - module_free(mod, mod->module_core);
66969 + module_free_exec(mod, mod->module_core_rx);
66970 + module_free(mod, mod->module_core_rw);
66971
66972 #ifdef CONFIG_MPU
66973 update_protections(current->mm);
66974 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66975 unsigned int i;
66976 int ret = 0;
66977 const struct kernel_symbol *ksym;
66978 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66979 + int is_fs_load = 0;
66980 + int register_filesystem_found = 0;
66981 + char *p;
66982 +
66983 + p = strstr(mod->args, "grsec_modharden_fs");
66984 + if (p) {
66985 + char *endptr = p + strlen("grsec_modharden_fs");
66986 + /* copy \0 as well */
66987 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66988 + is_fs_load = 1;
66989 + }
66990 +#endif
66991
66992 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66993 const char *name = info->strtab + sym[i].st_name;
66994
66995 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66996 + /* it's a real shame this will never get ripped and copied
66997 + upstream! ;(
66998 + */
66999 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67000 + register_filesystem_found = 1;
67001 +#endif
67002 +
67003 switch (sym[i].st_shndx) {
67004 case SHN_COMMON:
67005 /* We compiled with -fno-common. These are not
67006 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67007 ksym = resolve_symbol_wait(mod, info, name);
67008 /* Ok if resolved. */
67009 if (ksym && !IS_ERR(ksym)) {
67010 + pax_open_kernel();
67011 sym[i].st_value = ksym->value;
67012 + pax_close_kernel();
67013 break;
67014 }
67015
67016 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67017 secbase = (unsigned long)mod_percpu(mod);
67018 else
67019 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67020 + pax_open_kernel();
67021 sym[i].st_value += secbase;
67022 + pax_close_kernel();
67023 break;
67024 }
67025 }
67026
67027 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67028 + if (is_fs_load && !register_filesystem_found) {
67029 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67030 + ret = -EPERM;
67031 + }
67032 +#endif
67033 +
67034 return ret;
67035 }
67036
67037 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67038 || s->sh_entsize != ~0UL
67039 || strstarts(sname, ".init"))
67040 continue;
67041 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67042 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67043 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67044 + else
67045 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67046 pr_debug("\t%s\n", sname);
67047 }
67048 - switch (m) {
67049 - case 0: /* executable */
67050 - mod->core_size = debug_align(mod->core_size);
67051 - mod->core_text_size = mod->core_size;
67052 - break;
67053 - case 1: /* RO: text and ro-data */
67054 - mod->core_size = debug_align(mod->core_size);
67055 - mod->core_ro_size = mod->core_size;
67056 - break;
67057 - case 3: /* whole core */
67058 - mod->core_size = debug_align(mod->core_size);
67059 - break;
67060 - }
67061 }
67062
67063 pr_debug("Init section allocation order:\n");
67064 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67065 || s->sh_entsize != ~0UL
67066 || !strstarts(sname, ".init"))
67067 continue;
67068 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67069 - | INIT_OFFSET_MASK);
67070 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67071 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67072 + else
67073 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67074 + s->sh_entsize |= INIT_OFFSET_MASK;
67075 pr_debug("\t%s\n", sname);
67076 }
67077 - switch (m) {
67078 - case 0: /* executable */
67079 - mod->init_size = debug_align(mod->init_size);
67080 - mod->init_text_size = mod->init_size;
67081 - break;
67082 - case 1: /* RO: text and ro-data */
67083 - mod->init_size = debug_align(mod->init_size);
67084 - mod->init_ro_size = mod->init_size;
67085 - break;
67086 - case 3: /* whole init */
67087 - mod->init_size = debug_align(mod->init_size);
67088 - break;
67089 - }
67090 }
67091 }
67092
67093 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67094
67095 /* Put symbol section at end of init part of module. */
67096 symsect->sh_flags |= SHF_ALLOC;
67097 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67098 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67099 info->index.sym) | INIT_OFFSET_MASK;
67100 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67101
67102 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67103 }
67104
67105 /* Append room for core symbols at end of core part. */
67106 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67107 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67108 - mod->core_size += strtab_size;
67109 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67110 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67111 + mod->core_size_rx += strtab_size;
67112
67113 /* Put string table section at end of init part of module. */
67114 strsect->sh_flags |= SHF_ALLOC;
67115 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67116 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67117 info->index.str) | INIT_OFFSET_MASK;
67118 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67119 }
67120 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67121 /* Make sure we get permanent strtab: don't use info->strtab. */
67122 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67123
67124 + pax_open_kernel();
67125 +
67126 /* Set types up while we still have access to sections. */
67127 for (i = 0; i < mod->num_symtab; i++)
67128 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67129
67130 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67131 - mod->core_strtab = s = mod->module_core + info->stroffs;
67132 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67133 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67134 src = mod->symtab;
67135 *dst = *src;
67136 *s++ = 0;
67137 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67138 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67139 }
67140 mod->core_num_syms = ndst;
67141 +
67142 + pax_close_kernel();
67143 }
67144 #else
67145 static inline void layout_symtab(struct module *mod, struct load_info *info)
67146 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67147 return size == 0 ? NULL : vmalloc_exec(size);
67148 }
67149
67150 -static void *module_alloc_update_bounds(unsigned long size)
67151 +static void *module_alloc_update_bounds_rw(unsigned long size)
67152 {
67153 void *ret = module_alloc(size);
67154
67155 if (ret) {
67156 mutex_lock(&module_mutex);
67157 /* Update module bounds. */
67158 - if ((unsigned long)ret < module_addr_min)
67159 - module_addr_min = (unsigned long)ret;
67160 - if ((unsigned long)ret + size > module_addr_max)
67161 - module_addr_max = (unsigned long)ret + size;
67162 + if ((unsigned long)ret < module_addr_min_rw)
67163 + module_addr_min_rw = (unsigned long)ret;
67164 + if ((unsigned long)ret + size > module_addr_max_rw)
67165 + module_addr_max_rw = (unsigned long)ret + size;
67166 + mutex_unlock(&module_mutex);
67167 + }
67168 + return ret;
67169 +}
67170 +
67171 +static void *module_alloc_update_bounds_rx(unsigned long size)
67172 +{
67173 + void *ret = module_alloc_exec(size);
67174 +
67175 + if (ret) {
67176 + mutex_lock(&module_mutex);
67177 + /* Update module bounds. */
67178 + if ((unsigned long)ret < module_addr_min_rx)
67179 + module_addr_min_rx = (unsigned long)ret;
67180 + if ((unsigned long)ret + size > module_addr_max_rx)
67181 + module_addr_max_rx = (unsigned long)ret + size;
67182 mutex_unlock(&module_mutex);
67183 }
67184 return ret;
67185 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67186 static int check_modinfo(struct module *mod, struct load_info *info)
67187 {
67188 const char *modmagic = get_modinfo(info, "vermagic");
67189 + const char *license = get_modinfo(info, "license");
67190 int err;
67191
67192 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67193 + if (!license || !license_is_gpl_compatible(license))
67194 + return -ENOEXEC;
67195 +#endif
67196 +
67197 /* This is allowed: modprobe --force will invalidate it. */
67198 if (!modmagic) {
67199 err = try_to_force_load(mod, "bad vermagic");
67200 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67201 }
67202
67203 /* Set up license info based on the info section */
67204 - set_license(mod, get_modinfo(info, "license"));
67205 + set_license(mod, license);
67206
67207 return 0;
67208 }
67209 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67210 void *ptr;
67211
67212 /* Do the allocs. */
67213 - ptr = module_alloc_update_bounds(mod->core_size);
67214 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67215 /*
67216 * The pointer to this block is stored in the module structure
67217 * which is inside the block. Just mark it as not being a
67218 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67219 if (!ptr)
67220 return -ENOMEM;
67221
67222 - memset(ptr, 0, mod->core_size);
67223 - mod->module_core = ptr;
67224 + memset(ptr, 0, mod->core_size_rw);
67225 + mod->module_core_rw = ptr;
67226
67227 - ptr = module_alloc_update_bounds(mod->init_size);
67228 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67229 /*
67230 * The pointer to this block is stored in the module structure
67231 * which is inside the block. This block doesn't need to be
67232 * scanned as it contains data and code that will be freed
67233 * after the module is initialized.
67234 */
67235 - kmemleak_ignore(ptr);
67236 - if (!ptr && mod->init_size) {
67237 - module_free(mod, mod->module_core);
67238 + kmemleak_not_leak(ptr);
67239 + if (!ptr && mod->init_size_rw) {
67240 + module_free(mod, mod->module_core_rw);
67241 return -ENOMEM;
67242 }
67243 - memset(ptr, 0, mod->init_size);
67244 - mod->module_init = ptr;
67245 + memset(ptr, 0, mod->init_size_rw);
67246 + mod->module_init_rw = ptr;
67247 +
67248 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67249 + kmemleak_not_leak(ptr);
67250 + if (!ptr) {
67251 + module_free(mod, mod->module_init_rw);
67252 + module_free(mod, mod->module_core_rw);
67253 + return -ENOMEM;
67254 + }
67255 +
67256 + pax_open_kernel();
67257 + memset(ptr, 0, mod->core_size_rx);
67258 + pax_close_kernel();
67259 + mod->module_core_rx = ptr;
67260 +
67261 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67262 + kmemleak_not_leak(ptr);
67263 + if (!ptr && mod->init_size_rx) {
67264 + module_free_exec(mod, mod->module_core_rx);
67265 + module_free(mod, mod->module_init_rw);
67266 + module_free(mod, mod->module_core_rw);
67267 + return -ENOMEM;
67268 + }
67269 +
67270 + pax_open_kernel();
67271 + memset(ptr, 0, mod->init_size_rx);
67272 + pax_close_kernel();
67273 + mod->module_init_rx = ptr;
67274
67275 /* Transfer each section which specifies SHF_ALLOC */
67276 pr_debug("final section addresses:\n");
67277 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67278 if (!(shdr->sh_flags & SHF_ALLOC))
67279 continue;
67280
67281 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67282 - dest = mod->module_init
67283 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67284 - else
67285 - dest = mod->module_core + shdr->sh_entsize;
67286 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67287 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67288 + dest = mod->module_init_rw
67289 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67290 + else
67291 + dest = mod->module_init_rx
67292 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67293 + } else {
67294 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67295 + dest = mod->module_core_rw + shdr->sh_entsize;
67296 + else
67297 + dest = mod->module_core_rx + shdr->sh_entsize;
67298 + }
67299 +
67300 + if (shdr->sh_type != SHT_NOBITS) {
67301 +
67302 +#ifdef CONFIG_PAX_KERNEXEC
67303 +#ifdef CONFIG_X86_64
67304 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67305 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67306 +#endif
67307 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67308 + pax_open_kernel();
67309 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67310 + pax_close_kernel();
67311 + } else
67312 +#endif
67313
67314 - if (shdr->sh_type != SHT_NOBITS)
67315 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67316 + }
67317 /* Update sh_addr to point to copy in image. */
67318 - shdr->sh_addr = (unsigned long)dest;
67319 +
67320 +#ifdef CONFIG_PAX_KERNEXEC
67321 + if (shdr->sh_flags & SHF_EXECINSTR)
67322 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67323 + else
67324 +#endif
67325 +
67326 + shdr->sh_addr = (unsigned long)dest;
67327 pr_debug("\t0x%lx %s\n",
67328 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67329 }
67330 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67331 * Do it before processing of module parameters, so the module
67332 * can provide parameter accessor functions of its own.
67333 */
67334 - if (mod->module_init)
67335 - flush_icache_range((unsigned long)mod->module_init,
67336 - (unsigned long)mod->module_init
67337 - + mod->init_size);
67338 - flush_icache_range((unsigned long)mod->module_core,
67339 - (unsigned long)mod->module_core + mod->core_size);
67340 + if (mod->module_init_rx)
67341 + flush_icache_range((unsigned long)mod->module_init_rx,
67342 + (unsigned long)mod->module_init_rx
67343 + + mod->init_size_rx);
67344 + flush_icache_range((unsigned long)mod->module_core_rx,
67345 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67346
67347 set_fs(old_fs);
67348 }
67349 @@ -2802,8 +2901,10 @@ out:
67350 static void module_deallocate(struct module *mod, struct load_info *info)
67351 {
67352 percpu_modfree(mod);
67353 - module_free(mod, mod->module_init);
67354 - module_free(mod, mod->module_core);
67355 + module_free_exec(mod, mod->module_init_rx);
67356 + module_free_exec(mod, mod->module_core_rx);
67357 + module_free(mod, mod->module_init_rw);
67358 + module_free(mod, mod->module_core_rw);
67359 }
67360
67361 int __weak module_finalize(const Elf_Ehdr *hdr,
67362 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67363 if (err)
67364 goto free_unload;
67365
67366 + /* Now copy in args */
67367 + mod->args = strndup_user(uargs, ~0UL >> 1);
67368 + if (IS_ERR(mod->args)) {
67369 + err = PTR_ERR(mod->args);
67370 + goto free_unload;
67371 + }
67372 +
67373 /* Set up MODINFO_ATTR fields */
67374 setup_modinfo(mod, &info);
67375
67376 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67377 + {
67378 + char *p, *p2;
67379 +
67380 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67381 + 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);
67382 + err = -EPERM;
67383 + goto free_modinfo;
67384 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67385 + p += strlen("grsec_modharden_normal");
67386 + p2 = strstr(p, "_");
67387 + if (p2) {
67388 + *p2 = '\0';
67389 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67390 + *p2 = '_';
67391 + }
67392 + err = -EPERM;
67393 + goto free_modinfo;
67394 + }
67395 + }
67396 +#endif
67397 +
67398 /* Fix up syms, so that st_value is a pointer to location. */
67399 err = simplify_symbols(mod, &info);
67400 if (err < 0)
67401 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67402
67403 flush_module_icache(mod);
67404
67405 - /* Now copy in args */
67406 - mod->args = strndup_user(uargs, ~0UL >> 1);
67407 - if (IS_ERR(mod->args)) {
67408 - err = PTR_ERR(mod->args);
67409 - goto free_arch_cleanup;
67410 - }
67411 -
67412 /* Mark state as coming so strong_try_module_get() ignores us. */
67413 mod->state = MODULE_STATE_COMING;
67414
67415 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67416 unlock:
67417 mutex_unlock(&module_mutex);
67418 synchronize_sched();
67419 - kfree(mod->args);
67420 - free_arch_cleanup:
67421 module_arch_cleanup(mod);
67422 free_modinfo:
67423 free_modinfo(mod);
67424 + kfree(mod->args);
67425 free_unload:
67426 module_unload_free(mod);
67427 free_module:
67428 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67429 MODULE_STATE_COMING, mod);
67430
67431 /* Set RO and NX regions for core */
67432 - set_section_ro_nx(mod->module_core,
67433 - mod->core_text_size,
67434 - mod->core_ro_size,
67435 - mod->core_size);
67436 + set_section_ro_nx(mod->module_core_rx,
67437 + mod->core_size_rx,
67438 + mod->core_size_rx,
67439 + mod->core_size_rx);
67440
67441 /* Set RO and NX regions for init */
67442 - set_section_ro_nx(mod->module_init,
67443 - mod->init_text_size,
67444 - mod->init_ro_size,
67445 - mod->init_size);
67446 + set_section_ro_nx(mod->module_init_rx,
67447 + mod->init_size_rx,
67448 + mod->init_size_rx,
67449 + mod->init_size_rx);
67450
67451 do_mod_ctors(mod);
67452 /* Start the module */
67453 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67454 mod->strtab = mod->core_strtab;
67455 #endif
67456 unset_module_init_ro_nx(mod);
67457 - module_free(mod, mod->module_init);
67458 - mod->module_init = NULL;
67459 - mod->init_size = 0;
67460 - mod->init_ro_size = 0;
67461 - mod->init_text_size = 0;
67462 + module_free(mod, mod->module_init_rw);
67463 + module_free_exec(mod, mod->module_init_rx);
67464 + mod->module_init_rw = NULL;
67465 + mod->module_init_rx = NULL;
67466 + mod->init_size_rw = 0;
67467 + mod->init_size_rx = 0;
67468 mutex_unlock(&module_mutex);
67469
67470 return 0;
67471 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67472 unsigned long nextval;
67473
67474 /* At worse, next value is at end of module */
67475 - if (within_module_init(addr, mod))
67476 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67477 + if (within_module_init_rx(addr, mod))
67478 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67479 + else if (within_module_init_rw(addr, mod))
67480 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67481 + else if (within_module_core_rx(addr, mod))
67482 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67483 + else if (within_module_core_rw(addr, mod))
67484 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67485 else
67486 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67487 + return NULL;
67488
67489 /* Scan for closest preceding symbol, and next symbol. (ELF
67490 starts real symbols at 1). */
67491 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67492 char buf[8];
67493
67494 seq_printf(m, "%s %u",
67495 - mod->name, mod->init_size + mod->core_size);
67496 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67497 print_unload_info(m, mod);
67498
67499 /* Informative for users. */
67500 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67501 mod->state == MODULE_STATE_COMING ? "Loading":
67502 "Live");
67503 /* Used by oprofile and other similar tools. */
67504 - seq_printf(m, " 0x%pK", mod->module_core);
67505 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67506
67507 /* Taints info */
67508 if (mod->taints)
67509 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67510
67511 static int __init proc_modules_init(void)
67512 {
67513 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67514 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67515 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67516 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67517 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67518 +#else
67519 proc_create("modules", 0, NULL, &proc_modules_operations);
67520 +#endif
67521 +#else
67522 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67523 +#endif
67524 return 0;
67525 }
67526 module_init(proc_modules_init);
67527 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67528 {
67529 struct module *mod;
67530
67531 - if (addr < module_addr_min || addr > module_addr_max)
67532 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67533 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67534 return NULL;
67535
67536 list_for_each_entry_rcu(mod, &modules, list)
67537 - if (within_module_core(addr, mod)
67538 - || within_module_init(addr, mod))
67539 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67540 return mod;
67541 return NULL;
67542 }
67543 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67544 */
67545 struct module *__module_text_address(unsigned long addr)
67546 {
67547 - struct module *mod = __module_address(addr);
67548 + struct module *mod;
67549 +
67550 +#ifdef CONFIG_X86_32
67551 + addr = ktla_ktva(addr);
67552 +#endif
67553 +
67554 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67555 + return NULL;
67556 +
67557 + mod = __module_address(addr);
67558 +
67559 if (mod) {
67560 /* Make sure it's within the text section. */
67561 - if (!within(addr, mod->module_init, mod->init_text_size)
67562 - && !within(addr, mod->module_core, mod->core_text_size))
67563 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67564 mod = NULL;
67565 }
67566 return mod;
67567 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67568 index 7e3443f..b2a1e6b 100644
67569 --- a/kernel/mutex-debug.c
67570 +++ b/kernel/mutex-debug.c
67571 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67572 }
67573
67574 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67575 - struct thread_info *ti)
67576 + struct task_struct *task)
67577 {
67578 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67579
67580 /* Mark the current thread as blocked on the lock: */
67581 - ti->task->blocked_on = waiter;
67582 + task->blocked_on = waiter;
67583 }
67584
67585 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67586 - struct thread_info *ti)
67587 + struct task_struct *task)
67588 {
67589 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67590 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67591 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67592 - ti->task->blocked_on = NULL;
67593 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67594 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67595 + task->blocked_on = NULL;
67596
67597 list_del_init(&waiter->list);
67598 waiter->task = NULL;
67599 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67600 index 0799fd3..d06ae3b 100644
67601 --- a/kernel/mutex-debug.h
67602 +++ b/kernel/mutex-debug.h
67603 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67604 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67605 extern void debug_mutex_add_waiter(struct mutex *lock,
67606 struct mutex_waiter *waiter,
67607 - struct thread_info *ti);
67608 + struct task_struct *task);
67609 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67610 - struct thread_info *ti);
67611 + struct task_struct *task);
67612 extern void debug_mutex_unlock(struct mutex *lock);
67613 extern void debug_mutex_init(struct mutex *lock, const char *name,
67614 struct lock_class_key *key);
67615 diff --git a/kernel/mutex.c b/kernel/mutex.c
67616 index 89096dd..f91ebc5 100644
67617 --- a/kernel/mutex.c
67618 +++ b/kernel/mutex.c
67619 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67620 spin_lock_mutex(&lock->wait_lock, flags);
67621
67622 debug_mutex_lock_common(lock, &waiter);
67623 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67624 + debug_mutex_add_waiter(lock, &waiter, task);
67625
67626 /* add waiting tasks to the end of the waitqueue (FIFO): */
67627 list_add_tail(&waiter.list, &lock->wait_list);
67628 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67629 * TASK_UNINTERRUPTIBLE case.)
67630 */
67631 if (unlikely(signal_pending_state(state, task))) {
67632 - mutex_remove_waiter(lock, &waiter,
67633 - task_thread_info(task));
67634 + mutex_remove_waiter(lock, &waiter, task);
67635 mutex_release(&lock->dep_map, 1, ip);
67636 spin_unlock_mutex(&lock->wait_lock, flags);
67637
67638 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67639 done:
67640 lock_acquired(&lock->dep_map, ip);
67641 /* got the lock - rejoice! */
67642 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67643 + mutex_remove_waiter(lock, &waiter, task);
67644 mutex_set_owner(lock);
67645
67646 /* set it to 0 if there are no waiters left: */
67647 diff --git a/kernel/padata.c b/kernel/padata.c
67648 index b452599..5d68f4e 100644
67649 --- a/kernel/padata.c
67650 +++ b/kernel/padata.c
67651 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67652 padata->pd = pd;
67653 padata->cb_cpu = cb_cpu;
67654
67655 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67656 - atomic_set(&pd->seq_nr, -1);
67657 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67658 + atomic_set_unchecked(&pd->seq_nr, -1);
67659
67660 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67661 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67662
67663 target_cpu = padata_cpu_hash(padata);
67664 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67665 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67666 padata_init_pqueues(pd);
67667 padata_init_squeues(pd);
67668 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67669 - atomic_set(&pd->seq_nr, -1);
67670 + atomic_set_unchecked(&pd->seq_nr, -1);
67671 atomic_set(&pd->reorder_objects, 0);
67672 atomic_set(&pd->refcnt, 0);
67673 pd->pinst = pinst;
67674 diff --git a/kernel/panic.c b/kernel/panic.c
67675 index 80aed44..f291d37 100644
67676 --- a/kernel/panic.c
67677 +++ b/kernel/panic.c
67678 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67679 const char *board;
67680
67681 printk(KERN_WARNING "------------[ cut here ]------------\n");
67682 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67683 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67684 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67685 if (board)
67686 printk(KERN_WARNING "Hardware name: %s\n", board);
67687 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67688 */
67689 void __stack_chk_fail(void)
67690 {
67691 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67692 + dump_stack();
67693 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67694 __builtin_return_address(0));
67695 }
67696 EXPORT_SYMBOL(__stack_chk_fail);
67697 diff --git a/kernel/pid.c b/kernel/pid.c
67698 index 9f08dfa..6765c40 100644
67699 --- a/kernel/pid.c
67700 +++ b/kernel/pid.c
67701 @@ -33,6 +33,7 @@
67702 #include <linux/rculist.h>
67703 #include <linux/bootmem.h>
67704 #include <linux/hash.h>
67705 +#include <linux/security.h>
67706 #include <linux/pid_namespace.h>
67707 #include <linux/init_task.h>
67708 #include <linux/syscalls.h>
67709 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67710
67711 int pid_max = PID_MAX_DEFAULT;
67712
67713 -#define RESERVED_PIDS 300
67714 +#define RESERVED_PIDS 500
67715
67716 int pid_max_min = RESERVED_PIDS + 1;
67717 int pid_max_max = PID_MAX_LIMIT;
67718 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67719 */
67720 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67721 {
67722 + struct task_struct *task;
67723 +
67724 rcu_lockdep_assert(rcu_read_lock_held(),
67725 "find_task_by_pid_ns() needs rcu_read_lock()"
67726 " protection");
67727 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67728 +
67729 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67730 +
67731 + if (gr_pid_is_chrooted(task))
67732 + return NULL;
67733 +
67734 + return task;
67735 }
67736
67737 struct task_struct *find_task_by_vpid(pid_t vnr)
67738 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67739 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67740 }
67741
67742 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67743 +{
67744 + rcu_lockdep_assert(rcu_read_lock_held(),
67745 + "find_task_by_pid_ns() needs rcu_read_lock()"
67746 + " protection");
67747 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67748 +}
67749 +
67750 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67751 {
67752 struct pid *pid;
67753 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67754 index 125cb67..a4d1c30 100644
67755 --- a/kernel/posix-cpu-timers.c
67756 +++ b/kernel/posix-cpu-timers.c
67757 @@ -6,6 +6,7 @@
67758 #include <linux/posix-timers.h>
67759 #include <linux/errno.h>
67760 #include <linux/math64.h>
67761 +#include <linux/security.h>
67762 #include <asm/uaccess.h>
67763 #include <linux/kernel_stat.h>
67764 #include <trace/events/timer.h>
67765 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67766
67767 static __init int init_posix_cpu_timers(void)
67768 {
67769 - struct k_clock process = {
67770 + static struct k_clock process = {
67771 .clock_getres = process_cpu_clock_getres,
67772 .clock_get = process_cpu_clock_get,
67773 .timer_create = process_cpu_timer_create,
67774 .nsleep = process_cpu_nsleep,
67775 .nsleep_restart = process_cpu_nsleep_restart,
67776 };
67777 - struct k_clock thread = {
67778 + static struct k_clock thread = {
67779 .clock_getres = thread_cpu_clock_getres,
67780 .clock_get = thread_cpu_clock_get,
67781 .timer_create = thread_cpu_timer_create,
67782 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67783 index 69185ae..cc2847a 100644
67784 --- a/kernel/posix-timers.c
67785 +++ b/kernel/posix-timers.c
67786 @@ -43,6 +43,7 @@
67787 #include <linux/idr.h>
67788 #include <linux/posix-clock.h>
67789 #include <linux/posix-timers.h>
67790 +#include <linux/grsecurity.h>
67791 #include <linux/syscalls.h>
67792 #include <linux/wait.h>
67793 #include <linux/workqueue.h>
67794 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67795 * which we beg off on and pass to do_sys_settimeofday().
67796 */
67797
67798 -static struct k_clock posix_clocks[MAX_CLOCKS];
67799 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67800
67801 /*
67802 * These ones are defined below.
67803 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67804 */
67805 static __init int init_posix_timers(void)
67806 {
67807 - struct k_clock clock_realtime = {
67808 + static struct k_clock clock_realtime = {
67809 .clock_getres = hrtimer_get_res,
67810 .clock_get = posix_clock_realtime_get,
67811 .clock_set = posix_clock_realtime_set,
67812 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67813 .timer_get = common_timer_get,
67814 .timer_del = common_timer_del,
67815 };
67816 - struct k_clock clock_monotonic = {
67817 + static struct k_clock clock_monotonic = {
67818 .clock_getres = hrtimer_get_res,
67819 .clock_get = posix_ktime_get_ts,
67820 .nsleep = common_nsleep,
67821 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67822 .timer_get = common_timer_get,
67823 .timer_del = common_timer_del,
67824 };
67825 - struct k_clock clock_monotonic_raw = {
67826 + static struct k_clock clock_monotonic_raw = {
67827 .clock_getres = hrtimer_get_res,
67828 .clock_get = posix_get_monotonic_raw,
67829 };
67830 - struct k_clock clock_realtime_coarse = {
67831 + static struct k_clock clock_realtime_coarse = {
67832 .clock_getres = posix_get_coarse_res,
67833 .clock_get = posix_get_realtime_coarse,
67834 };
67835 - struct k_clock clock_monotonic_coarse = {
67836 + static struct k_clock clock_monotonic_coarse = {
67837 .clock_getres = posix_get_coarse_res,
67838 .clock_get = posix_get_monotonic_coarse,
67839 };
67840 - struct k_clock clock_boottime = {
67841 + static struct k_clock clock_boottime = {
67842 .clock_getres = hrtimer_get_res,
67843 .clock_get = posix_get_boottime,
67844 .nsleep = common_nsleep,
67845 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67846 return;
67847 }
67848
67849 - posix_clocks[clock_id] = *new_clock;
67850 + posix_clocks[clock_id] = new_clock;
67851 }
67852 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67853
67854 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67855 return (id & CLOCKFD_MASK) == CLOCKFD ?
67856 &clock_posix_dynamic : &clock_posix_cpu;
67857
67858 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67859 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67860 return NULL;
67861 - return &posix_clocks[id];
67862 + return posix_clocks[id];
67863 }
67864
67865 static int common_timer_create(struct k_itimer *new_timer)
67866 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67867 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67868 return -EFAULT;
67869
67870 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67871 + have their clock_set fptr set to a nosettime dummy function
67872 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67873 + call common_clock_set, which calls do_sys_settimeofday, which
67874 + we hook
67875 + */
67876 +
67877 return kc->clock_set(which_clock, &new_tp);
67878 }
67879
67880 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67881 index d523593..68197a4 100644
67882 --- a/kernel/power/poweroff.c
67883 +++ b/kernel/power/poweroff.c
67884 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67885 .enable_mask = SYSRQ_ENABLE_BOOT,
67886 };
67887
67888 -static int pm_sysrq_init(void)
67889 +static int __init pm_sysrq_init(void)
67890 {
67891 register_sysrq_key('o', &sysrq_poweroff_op);
67892 return 0;
67893 diff --git a/kernel/power/process.c b/kernel/power/process.c
67894 index 7e42645..3d43df1 100644
67895 --- a/kernel/power/process.c
67896 +++ b/kernel/power/process.c
67897 @@ -32,6 +32,7 @@ static int try_to_freeze_tasks(bool user_only)
67898 u64 elapsed_csecs64;
67899 unsigned int elapsed_csecs;
67900 bool wakeup = false;
67901 + bool timedout = false;
67902
67903 do_gettimeofday(&start);
67904
67905 @@ -42,6 +43,8 @@ static int try_to_freeze_tasks(bool user_only)
67906
67907 while (true) {
67908 todo = 0;
67909 + if (time_after(jiffies, end_time))
67910 + timedout = true;
67911 read_lock(&tasklist_lock);
67912 do_each_thread(g, p) {
67913 if (p == current || !freeze_task(p))
67914 @@ -59,9 +62,13 @@ static int try_to_freeze_tasks(bool user_only)
67915 * try_to_stop() after schedule() in ptrace/signal
67916 * stop sees TIF_FREEZE.
67917 */
67918 - if (!task_is_stopped_or_traced(p) &&
67919 - !freezer_should_skip(p))
67920 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67921 todo++;
67922 + if (timedout) {
67923 + printk(KERN_ERR "Task refusing to freeze:\n");
67924 + sched_show_task(p);
67925 + }
67926 + }
67927 } while_each_thread(g, p);
67928 read_unlock(&tasklist_lock);
67929
67930 @@ -70,7 +77,7 @@ static int try_to_freeze_tasks(bool user_only)
67931 todo += wq_busy;
67932 }
67933
67934 - if (!todo || time_after(jiffies, end_time))
67935 + if (!todo || timedout)
67936 break;
67937
67938 if (pm_wakeup_pending()) {
67939 diff --git a/kernel/printk.c b/kernel/printk.c
67940 index 32690a0..cd7c798 100644
67941 --- a/kernel/printk.c
67942 +++ b/kernel/printk.c
67943 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67944 if (from_file && type != SYSLOG_ACTION_OPEN)
67945 return 0;
67946
67947 +#ifdef CONFIG_GRKERNSEC_DMESG
67948 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67949 + return -EPERM;
67950 +#endif
67951 +
67952 if (syslog_action_restricted(type)) {
67953 if (capable(CAP_SYSLOG))
67954 return 0;
67955 diff --git a/kernel/profile.c b/kernel/profile.c
67956 index 76b8e77..a2930e8 100644
67957 --- a/kernel/profile.c
67958 +++ b/kernel/profile.c
67959 @@ -39,7 +39,7 @@ struct profile_hit {
67960 /* Oprofile timer tick hook */
67961 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67962
67963 -static atomic_t *prof_buffer;
67964 +static atomic_unchecked_t *prof_buffer;
67965 static unsigned long prof_len, prof_shift;
67966
67967 int prof_on __read_mostly;
67968 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67969 hits[i].pc = 0;
67970 continue;
67971 }
67972 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67973 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67974 hits[i].hits = hits[i].pc = 0;
67975 }
67976 }
67977 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67978 * Add the current hit(s) and flush the write-queue out
67979 * to the global buffer:
67980 */
67981 - atomic_add(nr_hits, &prof_buffer[pc]);
67982 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67983 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67984 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67985 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67986 hits[i].pc = hits[i].hits = 0;
67987 }
67988 out:
67989 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67990 {
67991 unsigned long pc;
67992 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67993 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67994 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67995 }
67996 #endif /* !CONFIG_SMP */
67997
67998 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67999 return -EFAULT;
68000 buf++; p++; count--; read++;
68001 }
68002 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68003 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68004 if (copy_to_user(buf, (void *)pnt, count))
68005 return -EFAULT;
68006 read += count;
68007 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68008 }
68009 #endif
68010 profile_discard_flip_buffers();
68011 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68012 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68013 return count;
68014 }
68015
68016 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68017 index 00ab2ca..d237f61 100644
68018 --- a/kernel/ptrace.c
68019 +++ b/kernel/ptrace.c
68020 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68021 task->ptrace = PT_PTRACED;
68022 if (seize)
68023 task->ptrace |= PT_SEIZED;
68024 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68025 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68026 task->ptrace |= PT_PTRACE_CAP;
68027
68028 __ptrace_link(task, current);
68029 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68030 break;
68031 return -EIO;
68032 }
68033 - if (copy_to_user(dst, buf, retval))
68034 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68035 return -EFAULT;
68036 copied += retval;
68037 src += retval;
68038 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
68039 bool seized = child->ptrace & PT_SEIZED;
68040 int ret = -EIO;
68041 siginfo_t siginfo, *si;
68042 - void __user *datavp = (void __user *) data;
68043 + void __user *datavp = (__force void __user *) data;
68044 unsigned long __user *datalp = datavp;
68045 unsigned long flags;
68046
68047 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68048 goto out;
68049 }
68050
68051 + if (gr_handle_ptrace(child, request)) {
68052 + ret = -EPERM;
68053 + goto out_put_task_struct;
68054 + }
68055 +
68056 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68057 ret = ptrace_attach(child, request, data);
68058 /*
68059 * Some architectures need to do book-keeping after
68060 * a ptrace attach.
68061 */
68062 - if (!ret)
68063 + if (!ret) {
68064 arch_ptrace_attach(child);
68065 + gr_audit_ptrace(child);
68066 + }
68067 goto out_put_task_struct;
68068 }
68069
68070 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68071 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68072 if (copied != sizeof(tmp))
68073 return -EIO;
68074 - return put_user(tmp, (unsigned long __user *)data);
68075 + return put_user(tmp, (__force unsigned long __user *)data);
68076 }
68077
68078 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68079 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68080 goto out;
68081 }
68082
68083 + if (gr_handle_ptrace(child, request)) {
68084 + ret = -EPERM;
68085 + goto out_put_task_struct;
68086 + }
68087 +
68088 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68089 ret = ptrace_attach(child, request, data);
68090 /*
68091 * Some architectures need to do book-keeping after
68092 * a ptrace attach.
68093 */
68094 - if (!ret)
68095 + if (!ret) {
68096 arch_ptrace_attach(child);
68097 + gr_audit_ptrace(child);
68098 + }
68099 goto out_put_task_struct;
68100 }
68101
68102 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68103 index 977296d..c4744dc 100644
68104 --- a/kernel/rcutiny.c
68105 +++ b/kernel/rcutiny.c
68106 @@ -46,7 +46,7 @@
68107 struct rcu_ctrlblk;
68108 static void invoke_rcu_callbacks(void);
68109 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68110 -static void rcu_process_callbacks(struct softirq_action *unused);
68111 +static void rcu_process_callbacks(void);
68112 static void __call_rcu(struct rcu_head *head,
68113 void (*func)(struct rcu_head *rcu),
68114 struct rcu_ctrlblk *rcp);
68115 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68116 rcu_is_callbacks_kthread()));
68117 }
68118
68119 -static void rcu_process_callbacks(struct softirq_action *unused)
68120 +static void rcu_process_callbacks(void)
68121 {
68122 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68123 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68124 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68125 index 9cb1ae4..aac7d3e 100644
68126 --- a/kernel/rcutiny_plugin.h
68127 +++ b/kernel/rcutiny_plugin.h
68128 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68129 have_rcu_kthread_work = morework;
68130 local_irq_restore(flags);
68131 if (work)
68132 - rcu_process_callbacks(NULL);
68133 + rcu_process_callbacks();
68134 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68135 }
68136
68137 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68138 index a58ac28..196a3d8 100644
68139 --- a/kernel/rcutorture.c
68140 +++ b/kernel/rcutorture.c
68141 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68142 { 0 };
68143 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68144 { 0 };
68145 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68146 -static atomic_t n_rcu_torture_alloc;
68147 -static atomic_t n_rcu_torture_alloc_fail;
68148 -static atomic_t n_rcu_torture_free;
68149 -static atomic_t n_rcu_torture_mberror;
68150 -static atomic_t n_rcu_torture_error;
68151 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68152 +static atomic_unchecked_t n_rcu_torture_alloc;
68153 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68154 +static atomic_unchecked_t n_rcu_torture_free;
68155 +static atomic_unchecked_t n_rcu_torture_mberror;
68156 +static atomic_unchecked_t n_rcu_torture_error;
68157 static long n_rcu_torture_boost_ktrerror;
68158 static long n_rcu_torture_boost_rterror;
68159 static long n_rcu_torture_boost_failure;
68160 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68161
68162 spin_lock_bh(&rcu_torture_lock);
68163 if (list_empty(&rcu_torture_freelist)) {
68164 - atomic_inc(&n_rcu_torture_alloc_fail);
68165 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68166 spin_unlock_bh(&rcu_torture_lock);
68167 return NULL;
68168 }
68169 - atomic_inc(&n_rcu_torture_alloc);
68170 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68171 p = rcu_torture_freelist.next;
68172 list_del_init(p);
68173 spin_unlock_bh(&rcu_torture_lock);
68174 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68175 static void
68176 rcu_torture_free(struct rcu_torture *p)
68177 {
68178 - atomic_inc(&n_rcu_torture_free);
68179 + atomic_inc_unchecked(&n_rcu_torture_free);
68180 spin_lock_bh(&rcu_torture_lock);
68181 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68182 spin_unlock_bh(&rcu_torture_lock);
68183 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68184 i = rp->rtort_pipe_count;
68185 if (i > RCU_TORTURE_PIPE_LEN)
68186 i = RCU_TORTURE_PIPE_LEN;
68187 - atomic_inc(&rcu_torture_wcount[i]);
68188 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68189 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68190 rp->rtort_mbtest = 0;
68191 rcu_torture_free(rp);
68192 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68193 i = rp->rtort_pipe_count;
68194 if (i > RCU_TORTURE_PIPE_LEN)
68195 i = RCU_TORTURE_PIPE_LEN;
68196 - atomic_inc(&rcu_torture_wcount[i]);
68197 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68198 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68199 rp->rtort_mbtest = 0;
68200 list_del(&rp->rtort_free);
68201 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68202 i = old_rp->rtort_pipe_count;
68203 if (i > RCU_TORTURE_PIPE_LEN)
68204 i = RCU_TORTURE_PIPE_LEN;
68205 - atomic_inc(&rcu_torture_wcount[i]);
68206 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68207 old_rp->rtort_pipe_count++;
68208 cur_ops->deferred_free(old_rp);
68209 }
68210 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68211 return;
68212 }
68213 if (p->rtort_mbtest == 0)
68214 - atomic_inc(&n_rcu_torture_mberror);
68215 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68216 spin_lock(&rand_lock);
68217 cur_ops->read_delay(&rand);
68218 n_rcu_torture_timers++;
68219 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68220 continue;
68221 }
68222 if (p->rtort_mbtest == 0)
68223 - atomic_inc(&n_rcu_torture_mberror);
68224 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68225 cur_ops->read_delay(&rand);
68226 preempt_disable();
68227 pipe_count = p->rtort_pipe_count;
68228 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68229 rcu_torture_current,
68230 rcu_torture_current_version,
68231 list_empty(&rcu_torture_freelist),
68232 - atomic_read(&n_rcu_torture_alloc),
68233 - atomic_read(&n_rcu_torture_alloc_fail),
68234 - atomic_read(&n_rcu_torture_free),
68235 - atomic_read(&n_rcu_torture_mberror),
68236 + atomic_read_unchecked(&n_rcu_torture_alloc),
68237 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68238 + atomic_read_unchecked(&n_rcu_torture_free),
68239 + atomic_read_unchecked(&n_rcu_torture_mberror),
68240 n_rcu_torture_boost_ktrerror,
68241 n_rcu_torture_boost_rterror,
68242 n_rcu_torture_boost_failure,
68243 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68244 n_online_attempts,
68245 n_offline_successes,
68246 n_offline_attempts);
68247 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68248 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68249 n_rcu_torture_boost_ktrerror != 0 ||
68250 n_rcu_torture_boost_rterror != 0 ||
68251 n_rcu_torture_boost_failure != 0)
68252 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68253 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68254 if (i > 1) {
68255 cnt += sprintf(&page[cnt], "!!! ");
68256 - atomic_inc(&n_rcu_torture_error);
68257 + atomic_inc_unchecked(&n_rcu_torture_error);
68258 WARN_ON_ONCE(1);
68259 }
68260 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68261 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68262 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68263 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68264 cnt += sprintf(&page[cnt], " %d",
68265 - atomic_read(&rcu_torture_wcount[i]));
68266 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68267 }
68268 cnt += sprintf(&page[cnt], "\n");
68269 if (cur_ops->stats)
68270 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68271
68272 if (cur_ops->cleanup)
68273 cur_ops->cleanup();
68274 - if (atomic_read(&n_rcu_torture_error))
68275 + if (atomic_read_unchecked(&n_rcu_torture_error))
68276 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68277 else
68278 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68279 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68280
68281 rcu_torture_current = NULL;
68282 rcu_torture_current_version = 0;
68283 - atomic_set(&n_rcu_torture_alloc, 0);
68284 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68285 - atomic_set(&n_rcu_torture_free, 0);
68286 - atomic_set(&n_rcu_torture_mberror, 0);
68287 - atomic_set(&n_rcu_torture_error, 0);
68288 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68289 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68290 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68291 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68292 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68293 n_rcu_torture_boost_ktrerror = 0;
68294 n_rcu_torture_boost_rterror = 0;
68295 n_rcu_torture_boost_failure = 0;
68296 n_rcu_torture_boosts = 0;
68297 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68298 - atomic_set(&rcu_torture_wcount[i], 0);
68299 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68300 for_each_possible_cpu(cpu) {
68301 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68302 per_cpu(rcu_torture_count, cpu)[i] = 0;
68303 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68304 index 6c4a672..70f3202 100644
68305 --- a/kernel/rcutree.c
68306 +++ b/kernel/rcutree.c
68307 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68308 rcu_prepare_for_idle(smp_processor_id());
68309 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68310 smp_mb__before_atomic_inc(); /* See above. */
68311 - atomic_inc(&rdtp->dynticks);
68312 + atomic_inc_unchecked(&rdtp->dynticks);
68313 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68314 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68315 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68316 }
68317
68318 /**
68319 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68320 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68321 {
68322 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68323 - atomic_inc(&rdtp->dynticks);
68324 + atomic_inc_unchecked(&rdtp->dynticks);
68325 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68326 smp_mb__after_atomic_inc(); /* See above. */
68327 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68328 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68329 rcu_cleanup_after_idle(smp_processor_id());
68330 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68331 if (!is_idle_task(current)) {
68332 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68333 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68334
68335 if (rdtp->dynticks_nmi_nesting == 0 &&
68336 - (atomic_read(&rdtp->dynticks) & 0x1))
68337 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68338 return;
68339 rdtp->dynticks_nmi_nesting++;
68340 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68341 - atomic_inc(&rdtp->dynticks);
68342 + atomic_inc_unchecked(&rdtp->dynticks);
68343 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68344 smp_mb__after_atomic_inc(); /* See above. */
68345 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68346 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68347 }
68348
68349 /**
68350 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68351 return;
68352 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68353 smp_mb__before_atomic_inc(); /* See above. */
68354 - atomic_inc(&rdtp->dynticks);
68355 + atomic_inc_unchecked(&rdtp->dynticks);
68356 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68357 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68358 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68359 }
68360
68361 #ifdef CONFIG_PROVE_RCU
68362 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68363 int ret;
68364
68365 preempt_disable();
68366 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68367 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68368 preempt_enable();
68369 return ret;
68370 }
68371 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68372 */
68373 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68374 {
68375 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68376 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68377 return (rdp->dynticks_snap & 0x1) == 0;
68378 }
68379
68380 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68381 unsigned int curr;
68382 unsigned int snap;
68383
68384 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68385 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68386 snap = (unsigned int)rdp->dynticks_snap;
68387
68388 /*
68389 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68390 /*
68391 * Do RCU core processing for the current CPU.
68392 */
68393 -static void rcu_process_callbacks(struct softirq_action *unused)
68394 +static void rcu_process_callbacks(void)
68395 {
68396 trace_rcu_utilization("Start RCU core");
68397 __rcu_process_callbacks(&rcu_sched_state,
68398 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68399 rdp->qlen = 0;
68400 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68401 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68402 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68403 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68404 rdp->cpu = cpu;
68405 rdp->rsp = rsp;
68406 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68407 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68408 rdp->n_force_qs_snap = rsp->n_force_qs;
68409 rdp->blimit = blimit;
68410 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68411 - atomic_set(&rdp->dynticks->dynticks,
68412 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68413 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68414 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68415 rcu_prepare_for_idle_init(cpu);
68416 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68417
68418 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68419 index fddff92..2c08359 100644
68420 --- a/kernel/rcutree.h
68421 +++ b/kernel/rcutree.h
68422 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68423 long long dynticks_nesting; /* Track irq/process nesting level. */
68424 /* Process level is worth LLONG_MAX/2. */
68425 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68426 - atomic_t dynticks; /* Even value for idle, else odd. */
68427 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68428 };
68429
68430 /* RCU's kthread states for tracing. */
68431 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68432 index 8bb35d7..6ea0a463 100644
68433 --- a/kernel/rcutree_plugin.h
68434 +++ b/kernel/rcutree_plugin.h
68435 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68436
68437 /* Clean up and exit. */
68438 smp_mb(); /* ensure expedited GP seen before counter increment. */
68439 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68440 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68441 unlock_mb_ret:
68442 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68443 mb_ret:
68444 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68445
68446 #else /* #ifndef CONFIG_SMP */
68447
68448 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68449 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68450 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68451 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68452
68453 static int synchronize_sched_expedited_cpu_stop(void *data)
68454 {
68455 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68456 int firstsnap, s, snap, trycount = 0;
68457
68458 /* Note that atomic_inc_return() implies full memory barrier. */
68459 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68460 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68461 get_online_cpus();
68462
68463 /*
68464 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68465 }
68466
68467 /* Check to see if someone else did our work for us. */
68468 - s = atomic_read(&sync_sched_expedited_done);
68469 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68470 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68471 smp_mb(); /* ensure test happens before caller kfree */
68472 return;
68473 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68474 * grace period works for us.
68475 */
68476 get_online_cpus();
68477 - snap = atomic_read(&sync_sched_expedited_started);
68478 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68479 smp_mb(); /* ensure read is before try_stop_cpus(). */
68480 }
68481
68482 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68483 * than we did beat us to the punch.
68484 */
68485 do {
68486 - s = atomic_read(&sync_sched_expedited_done);
68487 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68488 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68489 smp_mb(); /* ensure test happens before caller kfree */
68490 break;
68491 }
68492 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68493 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68494
68495 put_online_cpus();
68496 }
68497 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68498 index 654cfe6..c0b28e2 100644
68499 --- a/kernel/rcutree_trace.c
68500 +++ b/kernel/rcutree_trace.c
68501 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68502 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68503 rdp->qs_pending);
68504 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68505 - atomic_read(&rdp->dynticks->dynticks),
68506 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68507 rdp->dynticks->dynticks_nesting,
68508 rdp->dynticks->dynticks_nmi_nesting,
68509 rdp->dynticks_fqs);
68510 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68511 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68512 rdp->qs_pending);
68513 seq_printf(m, ",%d,%llx,%d,%lu",
68514 - atomic_read(&rdp->dynticks->dynticks),
68515 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68516 rdp->dynticks->dynticks_nesting,
68517 rdp->dynticks->dynticks_nmi_nesting,
68518 rdp->dynticks_fqs);
68519 diff --git a/kernel/resource.c b/kernel/resource.c
68520 index 7640b3a..5879283 100644
68521 --- a/kernel/resource.c
68522 +++ b/kernel/resource.c
68523 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68524
68525 static int __init ioresources_init(void)
68526 {
68527 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68528 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68529 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68530 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68531 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68532 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68533 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68534 +#endif
68535 +#else
68536 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68537 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68538 +#endif
68539 return 0;
68540 }
68541 __initcall(ioresources_init);
68542 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68543 index 98ec494..4241d6d 100644
68544 --- a/kernel/rtmutex-tester.c
68545 +++ b/kernel/rtmutex-tester.c
68546 @@ -20,7 +20,7 @@
68547 #define MAX_RT_TEST_MUTEXES 8
68548
68549 static spinlock_t rttest_lock;
68550 -static atomic_t rttest_event;
68551 +static atomic_unchecked_t rttest_event;
68552
68553 struct test_thread_data {
68554 int opcode;
68555 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68556
68557 case RTTEST_LOCKCONT:
68558 td->mutexes[td->opdata] = 1;
68559 - td->event = atomic_add_return(1, &rttest_event);
68560 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68561 return 0;
68562
68563 case RTTEST_RESET:
68564 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68565 return 0;
68566
68567 case RTTEST_RESETEVENT:
68568 - atomic_set(&rttest_event, 0);
68569 + atomic_set_unchecked(&rttest_event, 0);
68570 return 0;
68571
68572 default:
68573 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68574 return ret;
68575
68576 td->mutexes[id] = 1;
68577 - td->event = atomic_add_return(1, &rttest_event);
68578 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68579 rt_mutex_lock(&mutexes[id]);
68580 - td->event = atomic_add_return(1, &rttest_event);
68581 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68582 td->mutexes[id] = 4;
68583 return 0;
68584
68585 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68586 return ret;
68587
68588 td->mutexes[id] = 1;
68589 - td->event = atomic_add_return(1, &rttest_event);
68590 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68591 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68592 - td->event = atomic_add_return(1, &rttest_event);
68593 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68594 td->mutexes[id] = ret ? 0 : 4;
68595 return ret ? -EINTR : 0;
68596
68597 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68598 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68599 return ret;
68600
68601 - td->event = atomic_add_return(1, &rttest_event);
68602 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68603 rt_mutex_unlock(&mutexes[id]);
68604 - td->event = atomic_add_return(1, &rttest_event);
68605 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68606 td->mutexes[id] = 0;
68607 return 0;
68608
68609 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68610 break;
68611
68612 td->mutexes[dat] = 2;
68613 - td->event = atomic_add_return(1, &rttest_event);
68614 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68615 break;
68616
68617 default:
68618 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68619 return;
68620
68621 td->mutexes[dat] = 3;
68622 - td->event = atomic_add_return(1, &rttest_event);
68623 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68624 break;
68625
68626 case RTTEST_LOCKNOWAIT:
68627 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68628 return;
68629
68630 td->mutexes[dat] = 1;
68631 - td->event = atomic_add_return(1, &rttest_event);
68632 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68633 return;
68634
68635 default:
68636 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68637 index e8a1f83..363d17d 100644
68638 --- a/kernel/sched/auto_group.c
68639 +++ b/kernel/sched/auto_group.c
68640 @@ -11,7 +11,7 @@
68641
68642 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68643 static struct autogroup autogroup_default;
68644 -static atomic_t autogroup_seq_nr;
68645 +static atomic_unchecked_t autogroup_seq_nr;
68646
68647 void __init autogroup_init(struct task_struct *init_task)
68648 {
68649 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68650
68651 kref_init(&ag->kref);
68652 init_rwsem(&ag->lock);
68653 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68654 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68655 ag->tg = tg;
68656 #ifdef CONFIG_RT_GROUP_SCHED
68657 /*
68658 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68659 index b342f57..00324a0 100644
68660 --- a/kernel/sched/core.c
68661 +++ b/kernel/sched/core.c
68662 @@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
68663 BUG(); /* the idle class will always have a runnable task */
68664 }
68665
68666 +#ifdef CONFIG_GRKERNSEC_SETXID
68667 +extern void gr_delayed_cred_worker(void);
68668 +static inline void gr_cred_schedule(void)
68669 +{
68670 + if (unlikely(current->delayed_cred))
68671 + gr_delayed_cred_worker();
68672 +}
68673 +#else
68674 +static inline void gr_cred_schedule(void)
68675 +{
68676 +}
68677 +#endif
68678 +
68679 /*
68680 * __schedule() is the main scheduler function.
68681 */
68682 @@ -3162,6 +3175,8 @@ need_resched:
68683
68684 schedule_debug(prev);
68685
68686 + gr_cred_schedule();
68687 +
68688 if (sched_feat(HRTICK))
68689 hrtick_clear(rq);
68690
68691 @@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
68692 /* convert nice value [19,-20] to rlimit style value [1,40] */
68693 int nice_rlim = 20 - nice;
68694
68695 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68696 +
68697 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68698 capable(CAP_SYS_NICE));
68699 }
68700 @@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68701 if (nice > 19)
68702 nice = 19;
68703
68704 - if (increment < 0 && !can_nice(current, nice))
68705 + if (increment < 0 && (!can_nice(current, nice) ||
68706 + gr_handle_chroot_nice()))
68707 return -EPERM;
68708
68709 retval = security_task_setnice(current, nice);
68710 @@ -4042,6 +4060,7 @@ recheck:
68711 unsigned long rlim_rtprio =
68712 task_rlimit(p, RLIMIT_RTPRIO);
68713
68714 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68715 /* can't set/change the rt policy */
68716 if (policy != p->policy && !rlim_rtprio)
68717 return -EPERM;
68718 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68719 index aca16b8..8e3acc4 100644
68720 --- a/kernel/sched/fair.c
68721 +++ b/kernel/sched/fair.c
68722 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68723 * run_rebalance_domains is triggered when needed from the scheduler tick.
68724 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68725 */
68726 -static void run_rebalance_domains(struct softirq_action *h)
68727 +static void run_rebalance_domains(void)
68728 {
68729 int this_cpu = smp_processor_id();
68730 struct rq *this_rq = cpu_rq(this_cpu);
68731 diff --git a/kernel/signal.c b/kernel/signal.c
68732 index c73c428..7040057 100644
68733 --- a/kernel/signal.c
68734 +++ b/kernel/signal.c
68735 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68736
68737 int print_fatal_signals __read_mostly;
68738
68739 -static void __user *sig_handler(struct task_struct *t, int sig)
68740 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68741 {
68742 return t->sighand->action[sig - 1].sa.sa_handler;
68743 }
68744
68745 -static int sig_handler_ignored(void __user *handler, int sig)
68746 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68747 {
68748 /* Is it explicitly or implicitly ignored? */
68749 return handler == SIG_IGN ||
68750 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68751 static int sig_task_ignored(struct task_struct *t, int sig,
68752 int from_ancestor_ns)
68753 {
68754 - void __user *handler;
68755 + __sighandler_t handler;
68756
68757 handler = sig_handler(t, sig);
68758
68759 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68760 atomic_inc(&user->sigpending);
68761 rcu_read_unlock();
68762
68763 + if (!override_rlimit)
68764 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68765 +
68766 if (override_rlimit ||
68767 atomic_read(&user->sigpending) <=
68768 task_rlimit(t, RLIMIT_SIGPENDING)) {
68769 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68770
68771 int unhandled_signal(struct task_struct *tsk, int sig)
68772 {
68773 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68774 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68775 if (is_global_init(tsk))
68776 return 1;
68777 if (handler != SIG_IGN && handler != SIG_DFL)
68778 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68779 }
68780 }
68781
68782 + /* allow glibc communication via tgkill to other threads in our
68783 + thread group */
68784 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68785 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68786 + && gr_handle_signal(t, sig))
68787 + return -EPERM;
68788 +
68789 return security_task_kill(t, info, sig, 0);
68790 }
68791
68792 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68793 return send_signal(sig, info, p, 1);
68794 }
68795
68796 -static int
68797 +int
68798 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68799 {
68800 return send_signal(sig, info, t, 0);
68801 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68802 unsigned long int flags;
68803 int ret, blocked, ignored;
68804 struct k_sigaction *action;
68805 + int is_unhandled = 0;
68806
68807 spin_lock_irqsave(&t->sighand->siglock, flags);
68808 action = &t->sighand->action[sig-1];
68809 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68810 }
68811 if (action->sa.sa_handler == SIG_DFL)
68812 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68813 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68814 + is_unhandled = 1;
68815 ret = specific_send_sig_info(sig, info, t);
68816 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68817
68818 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68819 + normal operation */
68820 + if (is_unhandled) {
68821 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68822 + gr_handle_crash(t, sig);
68823 + }
68824 +
68825 return ret;
68826 }
68827
68828 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68829 ret = check_kill_permission(sig, info, p);
68830 rcu_read_unlock();
68831
68832 - if (!ret && sig)
68833 + if (!ret && sig) {
68834 ret = do_send_sig_info(sig, info, p, true);
68835 + if (!ret)
68836 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68837 + }
68838
68839 return ret;
68840 }
68841 @@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68842 int error = -ESRCH;
68843
68844 rcu_read_lock();
68845 - p = find_task_by_vpid(pid);
68846 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68847 + /* allow glibc communication via tgkill to other threads in our
68848 + thread group */
68849 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68850 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68851 + p = find_task_by_vpid_unrestricted(pid);
68852 + else
68853 +#endif
68854 + p = find_task_by_vpid(pid);
68855 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68856 error = check_kill_permission(sig, info, p);
68857 /*
68858 diff --git a/kernel/smp.c b/kernel/smp.c
68859 index db197d6..17aef0b 100644
68860 --- a/kernel/smp.c
68861 +++ b/kernel/smp.c
68862 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68863 }
68864 EXPORT_SYMBOL(smp_call_function);
68865
68866 -void ipi_call_lock(void)
68867 +void ipi_call_lock(void) __acquires(call_function.lock)
68868 {
68869 raw_spin_lock(&call_function.lock);
68870 }
68871
68872 -void ipi_call_unlock(void)
68873 +void ipi_call_unlock(void) __releases(call_function.lock)
68874 {
68875 raw_spin_unlock(&call_function.lock);
68876 }
68877
68878 -void ipi_call_lock_irq(void)
68879 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68880 {
68881 raw_spin_lock_irq(&call_function.lock);
68882 }
68883
68884 -void ipi_call_unlock_irq(void)
68885 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68886 {
68887 raw_spin_unlock_irq(&call_function.lock);
68888 }
68889 diff --git a/kernel/softirq.c b/kernel/softirq.c
68890 index 4eb3a0f..6f1fa81 100644
68891 --- a/kernel/softirq.c
68892 +++ b/kernel/softirq.c
68893 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68894
68895 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68896
68897 -char *softirq_to_name[NR_SOFTIRQS] = {
68898 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68899 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68900 "TASKLET", "SCHED", "HRTIMER", "RCU"
68901 };
68902 @@ -235,7 +235,7 @@ restart:
68903 kstat_incr_softirqs_this_cpu(vec_nr);
68904
68905 trace_softirq_entry(vec_nr);
68906 - h->action(h);
68907 + h->action();
68908 trace_softirq_exit(vec_nr);
68909 if (unlikely(prev_count != preempt_count())) {
68910 printk(KERN_ERR "huh, entered softirq %u %s %p"
68911 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68912 local_irq_restore(flags);
68913 }
68914
68915 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68916 +void open_softirq(int nr, void (*action)(void))
68917 {
68918 - softirq_vec[nr].action = action;
68919 + pax_open_kernel();
68920 + *(void **)&softirq_vec[nr].action = action;
68921 + pax_close_kernel();
68922 }
68923
68924 /*
68925 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68926
68927 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68928
68929 -static void tasklet_action(struct softirq_action *a)
68930 +static void tasklet_action(void)
68931 {
68932 struct tasklet_struct *list;
68933
68934 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68935 }
68936 }
68937
68938 -static void tasklet_hi_action(struct softirq_action *a)
68939 +static void tasklet_hi_action(void)
68940 {
68941 struct tasklet_struct *list;
68942
68943 diff --git a/kernel/sys.c b/kernel/sys.c
68944 index 888d227..f04b318 100644
68945 --- a/kernel/sys.c
68946 +++ b/kernel/sys.c
68947 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68948 error = -EACCES;
68949 goto out;
68950 }
68951 +
68952 + if (gr_handle_chroot_setpriority(p, niceval)) {
68953 + error = -EACCES;
68954 + goto out;
68955 + }
68956 +
68957 no_nice = security_task_setnice(p, niceval);
68958 if (no_nice) {
68959 error = no_nice;
68960 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68961 goto error;
68962 }
68963
68964 + if (gr_check_group_change(new->gid, new->egid, -1))
68965 + goto error;
68966 +
68967 if (rgid != (gid_t) -1 ||
68968 (egid != (gid_t) -1 && egid != old->gid))
68969 new->sgid = new->egid;
68970 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68971 old = current_cred();
68972
68973 retval = -EPERM;
68974 +
68975 + if (gr_check_group_change(gid, gid, gid))
68976 + goto error;
68977 +
68978 if (nsown_capable(CAP_SETGID))
68979 new->gid = new->egid = new->sgid = new->fsgid = gid;
68980 else if (gid == old->gid || gid == old->sgid)
68981 @@ -618,7 +631,7 @@ error:
68982 /*
68983 * change the user struct in a credentials set to match the new UID
68984 */
68985 -static int set_user(struct cred *new)
68986 +int set_user(struct cred *new)
68987 {
68988 struct user_struct *new_user;
68989
68990 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68991 goto error;
68992 }
68993
68994 + if (gr_check_user_change(new->uid, new->euid, -1))
68995 + goto error;
68996 +
68997 if (new->uid != old->uid) {
68998 retval = set_user(new);
68999 if (retval < 0)
69000 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69001 old = current_cred();
69002
69003 retval = -EPERM;
69004 +
69005 + if (gr_check_crash_uid(uid))
69006 + goto error;
69007 + if (gr_check_user_change(uid, uid, uid))
69008 + goto error;
69009 +
69010 if (nsown_capable(CAP_SETUID)) {
69011 new->suid = new->uid = uid;
69012 if (uid != old->uid) {
69013 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69014 goto error;
69015 }
69016
69017 + if (gr_check_user_change(ruid, euid, -1))
69018 + goto error;
69019 +
69020 if (ruid != (uid_t) -1) {
69021 new->uid = ruid;
69022 if (ruid != old->uid) {
69023 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69024 goto error;
69025 }
69026
69027 + if (gr_check_group_change(rgid, egid, -1))
69028 + goto error;
69029 +
69030 if (rgid != (gid_t) -1)
69031 new->gid = rgid;
69032 if (egid != (gid_t) -1)
69033 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69034 old = current_cred();
69035 old_fsuid = old->fsuid;
69036
69037 + if (gr_check_user_change(-1, -1, uid))
69038 + goto error;
69039 +
69040 if (uid == old->uid || uid == old->euid ||
69041 uid == old->suid || uid == old->fsuid ||
69042 nsown_capable(CAP_SETUID)) {
69043 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69044 }
69045 }
69046
69047 +error:
69048 abort_creds(new);
69049 return old_fsuid;
69050
69051 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69052 if (gid == old->gid || gid == old->egid ||
69053 gid == old->sgid || gid == old->fsgid ||
69054 nsown_capable(CAP_SETGID)) {
69055 + if (gr_check_group_change(-1, -1, gid))
69056 + goto error;
69057 +
69058 if (gid != old_fsgid) {
69059 new->fsgid = gid;
69060 goto change_okay;
69061 }
69062 }
69063
69064 +error:
69065 abort_creds(new);
69066 return old_fsgid;
69067
69068 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69069 }
69070 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69071 snprintf(buf, len, "2.6.%u%s", v, rest);
69072 - ret = copy_to_user(release, buf, len);
69073 + if (len > sizeof(buf))
69074 + ret = -EFAULT;
69075 + else
69076 + ret = copy_to_user(release, buf, len);
69077 }
69078 return ret;
69079 }
69080 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69081 return -EFAULT;
69082
69083 down_read(&uts_sem);
69084 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69085 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69086 __OLD_UTS_LEN);
69087 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69088 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69089 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69090 __OLD_UTS_LEN);
69091 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69092 - error |= __copy_to_user(&name->release, &utsname()->release,
69093 + error |= __copy_to_user(name->release, &utsname()->release,
69094 __OLD_UTS_LEN);
69095 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69096 - error |= __copy_to_user(&name->version, &utsname()->version,
69097 + error |= __copy_to_user(name->version, &utsname()->version,
69098 __OLD_UTS_LEN);
69099 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69100 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69101 + error |= __copy_to_user(name->machine, &utsname()->machine,
69102 __OLD_UTS_LEN);
69103 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69104 up_read(&uts_sem);
69105 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69106 error = get_dumpable(me->mm);
69107 break;
69108 case PR_SET_DUMPABLE:
69109 - if (arg2 < 0 || arg2 > 1) {
69110 + if (arg2 > 1) {
69111 error = -EINVAL;
69112 break;
69113 }
69114 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69115 index f487f25..9056a9e 100644
69116 --- a/kernel/sysctl.c
69117 +++ b/kernel/sysctl.c
69118 @@ -86,6 +86,13 @@
69119
69120
69121 #if defined(CONFIG_SYSCTL)
69122 +#include <linux/grsecurity.h>
69123 +#include <linux/grinternal.h>
69124 +
69125 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69126 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69127 + const int op);
69128 +extern int gr_handle_chroot_sysctl(const int op);
69129
69130 /* External variables not in a header file. */
69131 extern int sysctl_overcommit_memory;
69132 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69133 }
69134
69135 #endif
69136 +extern struct ctl_table grsecurity_table[];
69137
69138 static struct ctl_table root_table[];
69139 static struct ctl_table_root sysctl_table_root;
69140 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69141 int sysctl_legacy_va_layout;
69142 #endif
69143
69144 +#ifdef CONFIG_PAX_SOFTMODE
69145 +static ctl_table pax_table[] = {
69146 + {
69147 + .procname = "softmode",
69148 + .data = &pax_softmode,
69149 + .maxlen = sizeof(unsigned int),
69150 + .mode = 0600,
69151 + .proc_handler = &proc_dointvec,
69152 + },
69153 +
69154 + { }
69155 +};
69156 +#endif
69157 +
69158 /* The default sysctl tables: */
69159
69160 static struct ctl_table root_table[] = {
69161 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69162 #endif
69163
69164 static struct ctl_table kern_table[] = {
69165 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69166 + {
69167 + .procname = "grsecurity",
69168 + .mode = 0500,
69169 + .child = grsecurity_table,
69170 + },
69171 +#endif
69172 +
69173 +#ifdef CONFIG_PAX_SOFTMODE
69174 + {
69175 + .procname = "pax",
69176 + .mode = 0500,
69177 + .child = pax_table,
69178 + },
69179 +#endif
69180 +
69181 {
69182 .procname = "sched_child_runs_first",
69183 .data = &sysctl_sched_child_runs_first,
69184 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69185 .data = &modprobe_path,
69186 .maxlen = KMOD_PATH_LEN,
69187 .mode = 0644,
69188 - .proc_handler = proc_dostring,
69189 + .proc_handler = proc_dostring_modpriv,
69190 },
69191 {
69192 .procname = "modules_disabled",
69193 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69194 .extra1 = &zero,
69195 .extra2 = &one,
69196 },
69197 +#endif
69198 {
69199 .procname = "kptr_restrict",
69200 .data = &kptr_restrict,
69201 .maxlen = sizeof(int),
69202 .mode = 0644,
69203 .proc_handler = proc_dmesg_restrict,
69204 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69205 + .extra1 = &two,
69206 +#else
69207 .extra1 = &zero,
69208 +#endif
69209 .extra2 = &two,
69210 },
69211 -#endif
69212 {
69213 .procname = "ngroups_max",
69214 .data = &ngroups_max,
69215 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
69216 .proc_handler = proc_dointvec_minmax,
69217 .extra1 = &zero,
69218 },
69219 + {
69220 + .procname = "heap_stack_gap",
69221 + .data = &sysctl_heap_stack_gap,
69222 + .maxlen = sizeof(sysctl_heap_stack_gap),
69223 + .mode = 0644,
69224 + .proc_handler = proc_doulongvec_minmax,
69225 + },
69226 #else
69227 {
69228 .procname = "nr_trim_pages",
69229 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
69230 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69231 {
69232 int mode;
69233 + int error;
69234 +
69235 + if (table->parent != NULL && table->parent->procname != NULL &&
69236 + table->procname != NULL &&
69237 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69238 + return -EACCES;
69239 + if (gr_handle_chroot_sysctl(op))
69240 + return -EACCES;
69241 + error = gr_handle_sysctl(table, op);
69242 + if (error)
69243 + return error;
69244
69245 if (root->permissions)
69246 mode = root->permissions(root, current->nsproxy, table);
69247 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
69248 buffer, lenp, ppos);
69249 }
69250
69251 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69252 + void __user *buffer, size_t *lenp, loff_t *ppos)
69253 +{
69254 + if (write && !capable(CAP_SYS_MODULE))
69255 + return -EPERM;
69256 +
69257 + return _proc_do_string(table->data, table->maxlen, write,
69258 + buffer, lenp, ppos);
69259 +}
69260 +
69261 static size_t proc_skip_spaces(char **buf)
69262 {
69263 size_t ret;
69264 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69265 len = strlen(tmp);
69266 if (len > *size)
69267 len = *size;
69268 + if (len > sizeof(tmp))
69269 + len = sizeof(tmp);
69270 if (copy_to_user(*buf, tmp, len))
69271 return -EFAULT;
69272 *size -= len;
69273 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69274 *i = val;
69275 } else {
69276 val = convdiv * (*i) / convmul;
69277 - if (!first)
69278 + if (!first) {
69279 err = proc_put_char(&buffer, &left, '\t');
69280 + if (err)
69281 + break;
69282 + }
69283 err = proc_put_long(&buffer, &left, val, false);
69284 if (err)
69285 break;
69286 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
69287 return -ENOSYS;
69288 }
69289
69290 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69291 + void __user *buffer, size_t *lenp, loff_t *ppos)
69292 +{
69293 + return -ENOSYS;
69294 +}
69295 +
69296 int proc_dointvec(struct ctl_table *table, int write,
69297 void __user *buffer, size_t *lenp, loff_t *ppos)
69298 {
69299 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69300 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69301 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69302 EXPORT_SYMBOL(proc_dostring);
69303 +EXPORT_SYMBOL(proc_dostring_modpriv);
69304 EXPORT_SYMBOL(proc_doulongvec_minmax);
69305 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69306 EXPORT_SYMBOL(register_sysctl_table);
69307 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69308 index a650694..aaeeb20 100644
69309 --- a/kernel/sysctl_binary.c
69310 +++ b/kernel/sysctl_binary.c
69311 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69312 int i;
69313
69314 set_fs(KERNEL_DS);
69315 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69316 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69317 set_fs(old_fs);
69318 if (result < 0)
69319 goto out_kfree;
69320 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69321 }
69322
69323 set_fs(KERNEL_DS);
69324 - result = vfs_write(file, buffer, str - buffer, &pos);
69325 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69326 set_fs(old_fs);
69327 if (result < 0)
69328 goto out_kfree;
69329 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69330 int i;
69331
69332 set_fs(KERNEL_DS);
69333 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69334 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69335 set_fs(old_fs);
69336 if (result < 0)
69337 goto out_kfree;
69338 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69339 }
69340
69341 set_fs(KERNEL_DS);
69342 - result = vfs_write(file, buffer, str - buffer, &pos);
69343 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69344 set_fs(old_fs);
69345 if (result < 0)
69346 goto out_kfree;
69347 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69348 int i;
69349
69350 set_fs(KERNEL_DS);
69351 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69352 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69353 set_fs(old_fs);
69354 if (result < 0)
69355 goto out;
69356 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69357 __le16 dnaddr;
69358
69359 set_fs(KERNEL_DS);
69360 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69361 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69362 set_fs(old_fs);
69363 if (result < 0)
69364 goto out;
69365 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69366 le16_to_cpu(dnaddr) & 0x3ff);
69367
69368 set_fs(KERNEL_DS);
69369 - result = vfs_write(file, buf, len, &pos);
69370 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69371 set_fs(old_fs);
69372 if (result < 0)
69373 goto out;
69374 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69375 index 362da65..ab8ef8c 100644
69376 --- a/kernel/sysctl_check.c
69377 +++ b/kernel/sysctl_check.c
69378 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69379 set_fail(&fail, table, "Directory with extra2");
69380 } else {
69381 if ((table->proc_handler == proc_dostring) ||
69382 + (table->proc_handler == proc_dostring_modpriv) ||
69383 (table->proc_handler == proc_dointvec) ||
69384 (table->proc_handler == proc_dointvec_minmax) ||
69385 (table->proc_handler == proc_dointvec_jiffies) ||
69386 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69387 index e660464..c8b9e67 100644
69388 --- a/kernel/taskstats.c
69389 +++ b/kernel/taskstats.c
69390 @@ -27,9 +27,12 @@
69391 #include <linux/cgroup.h>
69392 #include <linux/fs.h>
69393 #include <linux/file.h>
69394 +#include <linux/grsecurity.h>
69395 #include <net/genetlink.h>
69396 #include <linux/atomic.h>
69397
69398 +extern int gr_is_taskstats_denied(int pid);
69399 +
69400 /*
69401 * Maximum length of a cpumask that can be specified in
69402 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69403 @@ -556,6 +559,9 @@ err:
69404
69405 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69406 {
69407 + if (gr_is_taskstats_denied(current->pid))
69408 + return -EACCES;
69409 +
69410 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69411 return cmd_attr_register_cpumask(info);
69412 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69413 diff --git a/kernel/time.c b/kernel/time.c
69414 index 73e416d..cfc6f69 100644
69415 --- a/kernel/time.c
69416 +++ b/kernel/time.c
69417 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69418 return error;
69419
69420 if (tz) {
69421 + /* we log in do_settimeofday called below, so don't log twice
69422 + */
69423 + if (!tv)
69424 + gr_log_timechange();
69425 +
69426 /* SMP safe, global irq locking makes it work. */
69427 sys_tz = *tz;
69428 update_vsyscall_tz();
69429 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69430 index 8a46f5d..bbe6f9c 100644
69431 --- a/kernel/time/alarmtimer.c
69432 +++ b/kernel/time/alarmtimer.c
69433 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69434 struct platform_device *pdev;
69435 int error = 0;
69436 int i;
69437 - struct k_clock alarm_clock = {
69438 + static struct k_clock alarm_clock = {
69439 .clock_getres = alarm_clock_getres,
69440 .clock_get = alarm_clock_get,
69441 .timer_create = alarm_timer_create,
69442 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69443 index fd4a7b1..fae5c2a 100644
69444 --- a/kernel/time/tick-broadcast.c
69445 +++ b/kernel/time/tick-broadcast.c
69446 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69447 * then clear the broadcast bit.
69448 */
69449 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69450 - int cpu = smp_processor_id();
69451 + cpu = smp_processor_id();
69452
69453 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69454 tick_broadcast_clear_oneshot(cpu);
69455 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69456 index 0c63581..e25dcb6 100644
69457 --- a/kernel/time/timekeeping.c
69458 +++ b/kernel/time/timekeeping.c
69459 @@ -14,6 +14,7 @@
69460 #include <linux/init.h>
69461 #include <linux/mm.h>
69462 #include <linux/sched.h>
69463 +#include <linux/grsecurity.h>
69464 #include <linux/syscore_ops.h>
69465 #include <linux/clocksource.h>
69466 #include <linux/jiffies.h>
69467 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69468 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69469 return -EINVAL;
69470
69471 + gr_log_timechange();
69472 +
69473 write_seqlock_irqsave(&xtime_lock, flags);
69474
69475 timekeeping_forward_now();
69476 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69477 index 3258455..f35227d 100644
69478 --- a/kernel/time/timer_list.c
69479 +++ b/kernel/time/timer_list.c
69480 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69481
69482 static void print_name_offset(struct seq_file *m, void *sym)
69483 {
69484 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69485 + SEQ_printf(m, "<%p>", NULL);
69486 +#else
69487 char symname[KSYM_NAME_LEN];
69488
69489 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69490 SEQ_printf(m, "<%pK>", sym);
69491 else
69492 SEQ_printf(m, "%s", symname);
69493 +#endif
69494 }
69495
69496 static void
69497 @@ -112,7 +116,11 @@ next_one:
69498 static void
69499 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69500 {
69501 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69502 + SEQ_printf(m, " .base: %p\n", NULL);
69503 +#else
69504 SEQ_printf(m, " .base: %pK\n", base);
69505 +#endif
69506 SEQ_printf(m, " .index: %d\n",
69507 base->index);
69508 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69509 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69510 {
69511 struct proc_dir_entry *pe;
69512
69513 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69514 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69515 +#else
69516 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69517 +#endif
69518 if (!pe)
69519 return -ENOMEM;
69520 return 0;
69521 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69522 index 0b537f2..9e71eca 100644
69523 --- a/kernel/time/timer_stats.c
69524 +++ b/kernel/time/timer_stats.c
69525 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69526 static unsigned long nr_entries;
69527 static struct entry entries[MAX_ENTRIES];
69528
69529 -static atomic_t overflow_count;
69530 +static atomic_unchecked_t overflow_count;
69531
69532 /*
69533 * The entries are in a hash-table, for fast lookup:
69534 @@ -140,7 +140,7 @@ static void reset_entries(void)
69535 nr_entries = 0;
69536 memset(entries, 0, sizeof(entries));
69537 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69538 - atomic_set(&overflow_count, 0);
69539 + atomic_set_unchecked(&overflow_count, 0);
69540 }
69541
69542 static struct entry *alloc_entry(void)
69543 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69544 if (likely(entry))
69545 entry->count++;
69546 else
69547 - atomic_inc(&overflow_count);
69548 + atomic_inc_unchecked(&overflow_count);
69549
69550 out_unlock:
69551 raw_spin_unlock_irqrestore(lock, flags);
69552 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69553
69554 static void print_name_offset(struct seq_file *m, unsigned long addr)
69555 {
69556 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69557 + seq_printf(m, "<%p>", NULL);
69558 +#else
69559 char symname[KSYM_NAME_LEN];
69560
69561 if (lookup_symbol_name(addr, symname) < 0)
69562 seq_printf(m, "<%p>", (void *)addr);
69563 else
69564 seq_printf(m, "%s", symname);
69565 +#endif
69566 }
69567
69568 static int tstats_show(struct seq_file *m, void *v)
69569 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69570
69571 seq_puts(m, "Timer Stats Version: v0.2\n");
69572 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69573 - if (atomic_read(&overflow_count))
69574 + if (atomic_read_unchecked(&overflow_count))
69575 seq_printf(m, "Overflow: %d entries\n",
69576 - atomic_read(&overflow_count));
69577 + atomic_read_unchecked(&overflow_count));
69578
69579 for (i = 0; i < nr_entries; i++) {
69580 entry = entries + i;
69581 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69582 {
69583 struct proc_dir_entry *pe;
69584
69585 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69586 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69587 +#else
69588 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69589 +#endif
69590 if (!pe)
69591 return -ENOMEM;
69592 return 0;
69593 diff --git a/kernel/timer.c b/kernel/timer.c
69594 index a297ffc..5e16b0b 100644
69595 --- a/kernel/timer.c
69596 +++ b/kernel/timer.c
69597 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69598 /*
69599 * This function runs timers and the timer-tq in bottom half context.
69600 */
69601 -static void run_timer_softirq(struct softirq_action *h)
69602 +static void run_timer_softirq(void)
69603 {
69604 struct tvec_base *base = __this_cpu_read(tvec_bases);
69605
69606 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69607 index cdea7b5..9b820d4 100644
69608 --- a/kernel/trace/blktrace.c
69609 +++ b/kernel/trace/blktrace.c
69610 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69611 struct blk_trace *bt = filp->private_data;
69612 char buf[16];
69613
69614 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69615 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69616
69617 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69618 }
69619 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69620 return 1;
69621
69622 bt = buf->chan->private_data;
69623 - atomic_inc(&bt->dropped);
69624 + atomic_inc_unchecked(&bt->dropped);
69625 return 0;
69626 }
69627
69628 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69629
69630 bt->dir = dir;
69631 bt->dev = dev;
69632 - atomic_set(&bt->dropped, 0);
69633 + atomic_set_unchecked(&bt->dropped, 0);
69634
69635 ret = -EIO;
69636 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69637 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69638 index 683d559..d70d914 100644
69639 --- a/kernel/trace/ftrace.c
69640 +++ b/kernel/trace/ftrace.c
69641 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69642 if (unlikely(ftrace_disabled))
69643 return 0;
69644
69645 + ret = ftrace_arch_code_modify_prepare();
69646 + FTRACE_WARN_ON(ret);
69647 + if (ret)
69648 + return 0;
69649 +
69650 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69651 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69652 if (ret) {
69653 ftrace_bug(ret, ip);
69654 - return 0;
69655 }
69656 - return 1;
69657 + return ret ? 0 : 1;
69658 }
69659
69660 /*
69661 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69662
69663 int
69664 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69665 - void *data)
69666 + void *data)
69667 {
69668 struct ftrace_func_probe *entry;
69669 struct ftrace_page *pg;
69670 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69671 index a3f1bc5..5e651718 100644
69672 --- a/kernel/trace/trace.c
69673 +++ b/kernel/trace/trace.c
69674 @@ -4254,10 +4254,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69675 };
69676 #endif
69677
69678 -static struct dentry *d_tracer;
69679 -
69680 struct dentry *tracing_init_dentry(void)
69681 {
69682 + static struct dentry *d_tracer;
69683 static int once;
69684
69685 if (d_tracer)
69686 @@ -4277,10 +4276,9 @@ struct dentry *tracing_init_dentry(void)
69687 return d_tracer;
69688 }
69689
69690 -static struct dentry *d_percpu;
69691 -
69692 struct dentry *tracing_dentry_percpu(void)
69693 {
69694 + static struct dentry *d_percpu;
69695 static int once;
69696 struct dentry *d_tracer;
69697
69698 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69699 index c212a7f..7b02394 100644
69700 --- a/kernel/trace/trace_events.c
69701 +++ b/kernel/trace/trace_events.c
69702 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69703 struct ftrace_module_file_ops {
69704 struct list_head list;
69705 struct module *mod;
69706 - struct file_operations id;
69707 - struct file_operations enable;
69708 - struct file_operations format;
69709 - struct file_operations filter;
69710 };
69711
69712 static struct ftrace_module_file_ops *
69713 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69714
69715 file_ops->mod = mod;
69716
69717 - file_ops->id = ftrace_event_id_fops;
69718 - file_ops->id.owner = mod;
69719 -
69720 - file_ops->enable = ftrace_enable_fops;
69721 - file_ops->enable.owner = mod;
69722 -
69723 - file_ops->filter = ftrace_event_filter_fops;
69724 - file_ops->filter.owner = mod;
69725 -
69726 - file_ops->format = ftrace_event_format_fops;
69727 - file_ops->format.owner = mod;
69728 + pax_open_kernel();
69729 + *(void **)&mod->trace_id.owner = mod;
69730 + *(void **)&mod->trace_enable.owner = mod;
69731 + *(void **)&mod->trace_filter.owner = mod;
69732 + *(void **)&mod->trace_format.owner = mod;
69733 + pax_close_kernel();
69734
69735 list_add(&file_ops->list, &ftrace_module_file_list);
69736
69737 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69738
69739 for_each_event(call, start, end) {
69740 __trace_add_event_call(*call, mod,
69741 - &file_ops->id, &file_ops->enable,
69742 - &file_ops->filter, &file_ops->format);
69743 + &mod->trace_id, &mod->trace_enable,
69744 + &mod->trace_filter, &mod->trace_format);
69745 }
69746 }
69747
69748 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69749 index 00d527c..7c5b1a3 100644
69750 --- a/kernel/trace/trace_kprobe.c
69751 +++ b/kernel/trace/trace_kprobe.c
69752 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69753 long ret;
69754 int maxlen = get_rloc_len(*(u32 *)dest);
69755 u8 *dst = get_rloc_data(dest);
69756 - u8 *src = addr;
69757 + const u8 __user *src = (const u8 __force_user *)addr;
69758 mm_segment_t old_fs = get_fs();
69759 if (!maxlen)
69760 return;
69761 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69762 pagefault_disable();
69763 do
69764 ret = __copy_from_user_inatomic(dst++, src++, 1);
69765 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69766 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69767 dst[-1] = '\0';
69768 pagefault_enable();
69769 set_fs(old_fs);
69770 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69771 ((u8 *)get_rloc_data(dest))[0] = '\0';
69772 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69773 } else
69774 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69775 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69776 get_rloc_offs(*(u32 *)dest));
69777 }
69778 /* Return the length of string -- including null terminal byte */
69779 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69780 set_fs(KERNEL_DS);
69781 pagefault_disable();
69782 do {
69783 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69784 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69785 len++;
69786 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69787 pagefault_enable();
69788 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69789 index fd3c8aa..5f324a6 100644
69790 --- a/kernel/trace/trace_mmiotrace.c
69791 +++ b/kernel/trace/trace_mmiotrace.c
69792 @@ -24,7 +24,7 @@ struct header_iter {
69793 static struct trace_array *mmio_trace_array;
69794 static bool overrun_detected;
69795 static unsigned long prev_overruns;
69796 -static atomic_t dropped_count;
69797 +static atomic_unchecked_t dropped_count;
69798
69799 static void mmio_reset_data(struct trace_array *tr)
69800 {
69801 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69802
69803 static unsigned long count_overruns(struct trace_iterator *iter)
69804 {
69805 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69806 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69807 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69808
69809 if (over > prev_overruns)
69810 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69811 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69812 sizeof(*entry), 0, pc);
69813 if (!event) {
69814 - atomic_inc(&dropped_count);
69815 + atomic_inc_unchecked(&dropped_count);
69816 return;
69817 }
69818 entry = ring_buffer_event_data(event);
69819 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69820 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69821 sizeof(*entry), 0, pc);
69822 if (!event) {
69823 - atomic_inc(&dropped_count);
69824 + atomic_inc_unchecked(&dropped_count);
69825 return;
69826 }
69827 entry = ring_buffer_event_data(event);
69828 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69829 index 0d6ff35..67e0ed7 100644
69830 --- a/kernel/trace/trace_output.c
69831 +++ b/kernel/trace/trace_output.c
69832 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69833
69834 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69835 if (!IS_ERR(p)) {
69836 - p = mangle_path(s->buffer + s->len, p, "\n");
69837 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69838 if (p) {
69839 s->len = p - s->buffer;
69840 return 1;
69841 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69842 index d4545f4..a9010a1 100644
69843 --- a/kernel/trace/trace_stack.c
69844 +++ b/kernel/trace/trace_stack.c
69845 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69846 return;
69847
69848 /* we do not handle interrupt stacks yet */
69849 - if (!object_is_on_stack(&this_size))
69850 + if (!object_starts_on_stack(&this_size))
69851 return;
69852
69853 local_irq_save(flags);
69854 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69855 index 209b379..7f76423 100644
69856 --- a/kernel/trace/trace_workqueue.c
69857 +++ b/kernel/trace/trace_workqueue.c
69858 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69859 int cpu;
69860 pid_t pid;
69861 /* Can be inserted from interrupt or user context, need to be atomic */
69862 - atomic_t inserted;
69863 + atomic_unchecked_t inserted;
69864 /*
69865 * Don't need to be atomic, works are serialized in a single workqueue thread
69866 * on a single CPU.
69867 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69868 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69869 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69870 if (node->pid == wq_thread->pid) {
69871 - atomic_inc(&node->inserted);
69872 + atomic_inc_unchecked(&node->inserted);
69873 goto found;
69874 }
69875 }
69876 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69877 tsk = get_pid_task(pid, PIDTYPE_PID);
69878 if (tsk) {
69879 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69880 - atomic_read(&cws->inserted), cws->executed,
69881 + atomic_read_unchecked(&cws->inserted), cws->executed,
69882 tsk->comm);
69883 put_task_struct(tsk);
69884 }
69885 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69886 index 8745ac7..d144e37 100644
69887 --- a/lib/Kconfig.debug
69888 +++ b/lib/Kconfig.debug
69889 @@ -1103,6 +1103,7 @@ config LATENCYTOP
69890 depends on DEBUG_KERNEL
69891 depends on STACKTRACE_SUPPORT
69892 depends on PROC_FS
69893 + depends on !GRKERNSEC_HIDESYM
69894 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69895 select KALLSYMS
69896 select KALLSYMS_ALL
69897 diff --git a/lib/bitmap.c b/lib/bitmap.c
69898 index 0d4a127..33a06c7 100644
69899 --- a/lib/bitmap.c
69900 +++ b/lib/bitmap.c
69901 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69902 {
69903 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69904 u32 chunk;
69905 - const char __user __force *ubuf = (const char __user __force *)buf;
69906 + const char __user *ubuf = (const char __force_user *)buf;
69907
69908 bitmap_zero(maskp, nmaskbits);
69909
69910 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69911 {
69912 if (!access_ok(VERIFY_READ, ubuf, ulen))
69913 return -EFAULT;
69914 - return __bitmap_parse((const char __force *)ubuf,
69915 + return __bitmap_parse((const char __force_kernel *)ubuf,
69916 ulen, 1, maskp, nmaskbits);
69917
69918 }
69919 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69920 {
69921 unsigned a, b;
69922 int c, old_c, totaldigits;
69923 - const char __user __force *ubuf = (const char __user __force *)buf;
69924 + const char __user *ubuf = (const char __force_user *)buf;
69925 int exp_digit, in_range;
69926
69927 totaldigits = c = 0;
69928 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69929 {
69930 if (!access_ok(VERIFY_READ, ubuf, ulen))
69931 return -EFAULT;
69932 - return __bitmap_parselist((const char __force *)ubuf,
69933 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69934 ulen, 1, maskp, nmaskbits);
69935 }
69936 EXPORT_SYMBOL(bitmap_parselist_user);
69937 diff --git a/lib/bug.c b/lib/bug.c
69938 index a28c141..2bd3d95 100644
69939 --- a/lib/bug.c
69940 +++ b/lib/bug.c
69941 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69942 return BUG_TRAP_TYPE_NONE;
69943
69944 bug = find_bug(bugaddr);
69945 + if (!bug)
69946 + return BUG_TRAP_TYPE_NONE;
69947
69948 file = NULL;
69949 line = 0;
69950 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69951 index 0ab9ae8..f01ceca 100644
69952 --- a/lib/debugobjects.c
69953 +++ b/lib/debugobjects.c
69954 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69955 if (limit > 4)
69956 return;
69957
69958 - is_on_stack = object_is_on_stack(addr);
69959 + is_on_stack = object_starts_on_stack(addr);
69960 if (is_on_stack == onstack)
69961 return;
69962
69963 diff --git a/lib/devres.c b/lib/devres.c
69964 index 9676617..5149e15 100644
69965 --- a/lib/devres.c
69966 +++ b/lib/devres.c
69967 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69968 void devm_iounmap(struct device *dev, void __iomem *addr)
69969 {
69970 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69971 - (void *)addr));
69972 + (void __force *)addr));
69973 iounmap(addr);
69974 }
69975 EXPORT_SYMBOL(devm_iounmap);
69976 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69977 {
69978 ioport_unmap(addr);
69979 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69980 - devm_ioport_map_match, (void *)addr));
69981 + devm_ioport_map_match, (void __force *)addr));
69982 }
69983 EXPORT_SYMBOL(devm_ioport_unmap);
69984
69985 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69986 index fea790a..ebb0e82 100644
69987 --- a/lib/dma-debug.c
69988 +++ b/lib/dma-debug.c
69989 @@ -925,7 +925,7 @@ out:
69990
69991 static void check_for_stack(struct device *dev, void *addr)
69992 {
69993 - if (object_is_on_stack(addr))
69994 + if (object_starts_on_stack(addr))
69995 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69996 "stack [addr=%p]\n", addr);
69997 }
69998 diff --git a/lib/extable.c b/lib/extable.c
69999 index 4cac81e..63e9b8f 100644
70000 --- a/lib/extable.c
70001 +++ b/lib/extable.c
70002 @@ -13,6 +13,7 @@
70003 #include <linux/init.h>
70004 #include <linux/sort.h>
70005 #include <asm/uaccess.h>
70006 +#include <asm/pgtable.h>
70007
70008 #ifndef ARCH_HAS_SORT_EXTABLE
70009 /*
70010 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70011 void sort_extable(struct exception_table_entry *start,
70012 struct exception_table_entry *finish)
70013 {
70014 + pax_open_kernel();
70015 sort(start, finish - start, sizeof(struct exception_table_entry),
70016 cmp_ex, NULL);
70017 + pax_close_kernel();
70018 }
70019
70020 #ifdef CONFIG_MODULES
70021 diff --git a/lib/inflate.c b/lib/inflate.c
70022 index 013a761..c28f3fc 100644
70023 --- a/lib/inflate.c
70024 +++ b/lib/inflate.c
70025 @@ -269,7 +269,7 @@ static void free(void *where)
70026 malloc_ptr = free_mem_ptr;
70027 }
70028 #else
70029 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70030 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70031 #define free(a) kfree(a)
70032 #endif
70033
70034 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70035 index bd2bea9..6b3c95e 100644
70036 --- a/lib/is_single_threaded.c
70037 +++ b/lib/is_single_threaded.c
70038 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70039 struct task_struct *p, *t;
70040 bool ret;
70041
70042 + if (!mm)
70043 + return true;
70044 +
70045 if (atomic_read(&task->signal->live) != 1)
70046 return false;
70047
70048 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70049 index dc63d08..95ae14a 100644
70050 --- a/lib/radix-tree.c
70051 +++ b/lib/radix-tree.c
70052 @@ -78,7 +78,7 @@ struct radix_tree_preload {
70053 int nr;
70054 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70055 };
70056 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70057 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70058
70059 static inline void *ptr_to_indirect(void *ptr)
70060 {
70061 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70062 index 38e612e..4fb99a8 100644
70063 --- a/lib/vsprintf.c
70064 +++ b/lib/vsprintf.c
70065 @@ -16,6 +16,9 @@
70066 * - scnprintf and vscnprintf
70067 */
70068
70069 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70070 +#define __INCLUDED_BY_HIDESYM 1
70071 +#endif
70072 #include <stdarg.h>
70073 #include <linux/module.h>
70074 #include <linux/types.h>
70075 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70076 char sym[KSYM_SYMBOL_LEN];
70077 if (ext == 'B')
70078 sprint_backtrace(sym, value);
70079 - else if (ext != 'f' && ext != 's')
70080 + else if (ext != 'f' && ext != 's' && ext != 'a')
70081 sprint_symbol(sym, value);
70082 else
70083 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70084 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70085 return number(buf, end, *(const netdev_features_t *)addr, spec);
70086 }
70087
70088 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70089 +int kptr_restrict __read_mostly = 2;
70090 +#else
70091 int kptr_restrict __read_mostly;
70092 +#endif
70093
70094 /*
70095 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70096 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70097 * - 'S' For symbolic direct pointers with offset
70098 * - 's' For symbolic direct pointers without offset
70099 * - 'B' For backtraced symbolic direct pointers with offset
70100 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70101 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70102 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70103 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70104 * - 'M' For a 6-byte MAC address, it prints the address in the
70105 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70106 {
70107 if (!ptr && *fmt != 'K') {
70108 /*
70109 - * Print (null) with the same width as a pointer so it makes
70110 + * Print (nil) with the same width as a pointer so it makes
70111 * tabular output look nice.
70112 */
70113 if (spec.field_width == -1)
70114 spec.field_width = 2 * sizeof(void *);
70115 - return string(buf, end, "(null)", spec);
70116 + return string(buf, end, "(nil)", spec);
70117 }
70118
70119 switch (*fmt) {
70120 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70121 /* Fallthrough */
70122 case 'S':
70123 case 's':
70124 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70125 + break;
70126 +#else
70127 + return symbol_string(buf, end, ptr, spec, *fmt);
70128 +#endif
70129 + case 'A':
70130 + case 'a':
70131 case 'B':
70132 return symbol_string(buf, end, ptr, spec, *fmt);
70133 case 'R':
70134 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70135 typeof(type) value; \
70136 if (sizeof(type) == 8) { \
70137 args = PTR_ALIGN(args, sizeof(u32)); \
70138 - *(u32 *)&value = *(u32 *)args; \
70139 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70140 + *(u32 *)&value = *(const u32 *)args; \
70141 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70142 } else { \
70143 args = PTR_ALIGN(args, sizeof(type)); \
70144 - value = *(typeof(type) *)args; \
70145 + value = *(const typeof(type) *)args; \
70146 } \
70147 args += sizeof(type); \
70148 value; \
70149 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70150 case FORMAT_TYPE_STR: {
70151 const char *str_arg = args;
70152 args += strlen(str_arg) + 1;
70153 - str = string(str, end, (char *)str_arg, spec);
70154 + str = string(str, end, str_arg, spec);
70155 break;
70156 }
70157
70158 diff --git a/localversion-grsec b/localversion-grsec
70159 new file mode 100644
70160 index 0000000..7cd6065
70161 --- /dev/null
70162 +++ b/localversion-grsec
70163 @@ -0,0 +1 @@
70164 +-grsec
70165 diff --git a/mm/Kconfig b/mm/Kconfig
70166 index e338407..49b5b7a 100644
70167 --- a/mm/Kconfig
70168 +++ b/mm/Kconfig
70169 @@ -247,10 +247,10 @@ config KSM
70170 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70171
70172 config DEFAULT_MMAP_MIN_ADDR
70173 - int "Low address space to protect from user allocation"
70174 + int "Low address space to protect from user allocation"
70175 depends on MMU
70176 - default 4096
70177 - help
70178 + default 65536
70179 + help
70180 This is the portion of low virtual memory which should be protected
70181 from userspace allocation. Keeping a user from writing to low pages
70182 can help reduce the impact of kernel NULL pointer bugs.
70183 diff --git a/mm/filemap.c b/mm/filemap.c
70184 index b662757..3081ddd 100644
70185 --- a/mm/filemap.c
70186 +++ b/mm/filemap.c
70187 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70188 struct address_space *mapping = file->f_mapping;
70189
70190 if (!mapping->a_ops->readpage)
70191 - return -ENOEXEC;
70192 + return -ENODEV;
70193 file_accessed(file);
70194 vma->vm_ops = &generic_file_vm_ops;
70195 vma->vm_flags |= VM_CAN_NONLINEAR;
70196 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70197 *pos = i_size_read(inode);
70198
70199 if (limit != RLIM_INFINITY) {
70200 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70201 if (*pos >= limit) {
70202 send_sig(SIGXFSZ, current, 0);
70203 return -EFBIG;
70204 diff --git a/mm/fremap.c b/mm/fremap.c
70205 index 9ed4fd4..c42648d 100644
70206 --- a/mm/fremap.c
70207 +++ b/mm/fremap.c
70208 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70209 retry:
70210 vma = find_vma(mm, start);
70211
70212 +#ifdef CONFIG_PAX_SEGMEXEC
70213 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70214 + goto out;
70215 +#endif
70216 +
70217 /*
70218 * Make sure the vma is shared, that it supports prefaulting,
70219 * and that the remapped range is valid and fully within
70220 diff --git a/mm/highmem.c b/mm/highmem.c
70221 index 57d82c6..e9e0552 100644
70222 --- a/mm/highmem.c
70223 +++ b/mm/highmem.c
70224 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70225 * So no dangers, even with speculative execution.
70226 */
70227 page = pte_page(pkmap_page_table[i]);
70228 + pax_open_kernel();
70229 pte_clear(&init_mm, (unsigned long)page_address(page),
70230 &pkmap_page_table[i]);
70231 -
70232 + pax_close_kernel();
70233 set_page_address(page, NULL);
70234 need_flush = 1;
70235 }
70236 @@ -186,9 +187,11 @@ start:
70237 }
70238 }
70239 vaddr = PKMAP_ADDR(last_pkmap_nr);
70240 +
70241 + pax_open_kernel();
70242 set_pte_at(&init_mm, vaddr,
70243 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70244 -
70245 + pax_close_kernel();
70246 pkmap_count[last_pkmap_nr] = 1;
70247 set_page_address(page, (void *)vaddr);
70248
70249 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70250 index 8f7fc39..69bf1e9 100644
70251 --- a/mm/huge_memory.c
70252 +++ b/mm/huge_memory.c
70253 @@ -733,7 +733,7 @@ out:
70254 * run pte_offset_map on the pmd, if an huge pmd could
70255 * materialize from under us from a different thread.
70256 */
70257 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70258 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70259 return VM_FAULT_OOM;
70260 /* if an huge pmd materialized from under us just retry later */
70261 if (unlikely(pmd_trans_huge(*pmd)))
70262 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70263 index a876871..132cde0 100644
70264 --- a/mm/hugetlb.c
70265 +++ b/mm/hugetlb.c
70266 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70267 return 1;
70268 }
70269
70270 +#ifdef CONFIG_PAX_SEGMEXEC
70271 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70272 +{
70273 + struct mm_struct *mm = vma->vm_mm;
70274 + struct vm_area_struct *vma_m;
70275 + unsigned long address_m;
70276 + pte_t *ptep_m;
70277 +
70278 + vma_m = pax_find_mirror_vma(vma);
70279 + if (!vma_m)
70280 + return;
70281 +
70282 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70283 + address_m = address + SEGMEXEC_TASK_SIZE;
70284 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70285 + get_page(page_m);
70286 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70287 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70288 +}
70289 +#endif
70290 +
70291 /*
70292 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70293 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70294 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
70295 make_huge_pte(vma, new_page, 1));
70296 page_remove_rmap(old_page);
70297 hugepage_add_new_anon_rmap(new_page, vma, address);
70298 +
70299 +#ifdef CONFIG_PAX_SEGMEXEC
70300 + pax_mirror_huge_pte(vma, address, new_page);
70301 +#endif
70302 +
70303 /* Make the old page be freed below */
70304 new_page = old_page;
70305 mmu_notifier_invalidate_range_end(mm,
70306 @@ -2613,6 +2639,10 @@ retry:
70307 && (vma->vm_flags & VM_SHARED)));
70308 set_huge_pte_at(mm, address, ptep, new_pte);
70309
70310 +#ifdef CONFIG_PAX_SEGMEXEC
70311 + pax_mirror_huge_pte(vma, address, page);
70312 +#endif
70313 +
70314 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70315 /* Optimization, do the COW without a second fault */
70316 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70317 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70318 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70319 struct hstate *h = hstate_vma(vma);
70320
70321 +#ifdef CONFIG_PAX_SEGMEXEC
70322 + struct vm_area_struct *vma_m;
70323 +#endif
70324 +
70325 address &= huge_page_mask(h);
70326
70327 ptep = huge_pte_offset(mm, address);
70328 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70329 VM_FAULT_SET_HINDEX(h - hstates);
70330 }
70331
70332 +#ifdef CONFIG_PAX_SEGMEXEC
70333 + vma_m = pax_find_mirror_vma(vma);
70334 + if (vma_m) {
70335 + unsigned long address_m;
70336 +
70337 + if (vma->vm_start > vma_m->vm_start) {
70338 + address_m = address;
70339 + address -= SEGMEXEC_TASK_SIZE;
70340 + vma = vma_m;
70341 + h = hstate_vma(vma);
70342 + } else
70343 + address_m = address + SEGMEXEC_TASK_SIZE;
70344 +
70345 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70346 + return VM_FAULT_OOM;
70347 + address_m &= HPAGE_MASK;
70348 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70349 + }
70350 +#endif
70351 +
70352 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70353 if (!ptep)
70354 return VM_FAULT_OOM;
70355 diff --git a/mm/internal.h b/mm/internal.h
70356 index 2189af4..f2ca332 100644
70357 --- a/mm/internal.h
70358 +++ b/mm/internal.h
70359 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70360 * in mm/page_alloc.c
70361 */
70362 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70363 +extern void free_compound_page(struct page *page);
70364 extern void prep_compound_page(struct page *page, unsigned long order);
70365 #ifdef CONFIG_MEMORY_FAILURE
70366 extern bool is_free_buddy_page(struct page *page);
70367 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70368 index 45eb621..6ccd8ea 100644
70369 --- a/mm/kmemleak.c
70370 +++ b/mm/kmemleak.c
70371 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70372
70373 for (i = 0; i < object->trace_len; i++) {
70374 void *ptr = (void *)object->trace[i];
70375 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70376 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70377 }
70378 }
70379
70380 diff --git a/mm/maccess.c b/mm/maccess.c
70381 index d53adf9..03a24bf 100644
70382 --- a/mm/maccess.c
70383 +++ b/mm/maccess.c
70384 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70385 set_fs(KERNEL_DS);
70386 pagefault_disable();
70387 ret = __copy_from_user_inatomic(dst,
70388 - (__force const void __user *)src, size);
70389 + (const void __force_user *)src, size);
70390 pagefault_enable();
70391 set_fs(old_fs);
70392
70393 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70394
70395 set_fs(KERNEL_DS);
70396 pagefault_disable();
70397 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70398 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70399 pagefault_enable();
70400 set_fs(old_fs);
70401
70402 diff --git a/mm/madvise.c b/mm/madvise.c
70403 index 74bf193..feb6fd3 100644
70404 --- a/mm/madvise.c
70405 +++ b/mm/madvise.c
70406 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70407 pgoff_t pgoff;
70408 unsigned long new_flags = vma->vm_flags;
70409
70410 +#ifdef CONFIG_PAX_SEGMEXEC
70411 + struct vm_area_struct *vma_m;
70412 +#endif
70413 +
70414 switch (behavior) {
70415 case MADV_NORMAL:
70416 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70417 @@ -110,6 +114,13 @@ success:
70418 /*
70419 * vm_flags is protected by the mmap_sem held in write mode.
70420 */
70421 +
70422 +#ifdef CONFIG_PAX_SEGMEXEC
70423 + vma_m = pax_find_mirror_vma(vma);
70424 + if (vma_m)
70425 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70426 +#endif
70427 +
70428 vma->vm_flags = new_flags;
70429
70430 out:
70431 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70432 struct vm_area_struct ** prev,
70433 unsigned long start, unsigned long end)
70434 {
70435 +
70436 +#ifdef CONFIG_PAX_SEGMEXEC
70437 + struct vm_area_struct *vma_m;
70438 +#endif
70439 +
70440 *prev = vma;
70441 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70442 return -EINVAL;
70443 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70444 zap_page_range(vma, start, end - start, &details);
70445 } else
70446 zap_page_range(vma, start, end - start, NULL);
70447 +
70448 +#ifdef CONFIG_PAX_SEGMEXEC
70449 + vma_m = pax_find_mirror_vma(vma);
70450 + if (vma_m) {
70451 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70452 + struct zap_details details = {
70453 + .nonlinear_vma = vma_m,
70454 + .last_index = ULONG_MAX,
70455 + };
70456 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70457 + } else
70458 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70459 + }
70460 +#endif
70461 +
70462 return 0;
70463 }
70464
70465 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70466 if (end < start)
70467 goto out;
70468
70469 +#ifdef CONFIG_PAX_SEGMEXEC
70470 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70471 + if (end > SEGMEXEC_TASK_SIZE)
70472 + goto out;
70473 + } else
70474 +#endif
70475 +
70476 + if (end > TASK_SIZE)
70477 + goto out;
70478 +
70479 error = 0;
70480 if (end == start)
70481 goto out;
70482 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70483 index 56080ea..115071e 100644
70484 --- a/mm/memory-failure.c
70485 +++ b/mm/memory-failure.c
70486 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70487
70488 int sysctl_memory_failure_recovery __read_mostly = 1;
70489
70490 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70491 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70492
70493 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70494
70495 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70496 si.si_signo = SIGBUS;
70497 si.si_errno = 0;
70498 si.si_code = BUS_MCEERR_AO;
70499 - si.si_addr = (void *)addr;
70500 + si.si_addr = (void __user *)addr;
70501 #ifdef __ARCH_SI_TRAPNO
70502 si.si_trapno = trapno;
70503 #endif
70504 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70505 }
70506
70507 nr_pages = 1 << compound_trans_order(hpage);
70508 - atomic_long_add(nr_pages, &mce_bad_pages);
70509 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70510
70511 /*
70512 * We need/can do nothing about count=0 pages.
70513 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70514 if (!PageHWPoison(hpage)
70515 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70516 || (p != hpage && TestSetPageHWPoison(hpage))) {
70517 - atomic_long_sub(nr_pages, &mce_bad_pages);
70518 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70519 return 0;
70520 }
70521 set_page_hwpoison_huge_page(hpage);
70522 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70523 }
70524 if (hwpoison_filter(p)) {
70525 if (TestClearPageHWPoison(p))
70526 - atomic_long_sub(nr_pages, &mce_bad_pages);
70527 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70528 unlock_page(hpage);
70529 put_page(hpage);
70530 return 0;
70531 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70532 return 0;
70533 }
70534 if (TestClearPageHWPoison(p))
70535 - atomic_long_sub(nr_pages, &mce_bad_pages);
70536 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70537 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70538 return 0;
70539 }
70540 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70541 */
70542 if (TestClearPageHWPoison(page)) {
70543 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70544 - atomic_long_sub(nr_pages, &mce_bad_pages);
70545 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70546 freeit = 1;
70547 if (PageHuge(page))
70548 clear_page_hwpoison_huge_page(page);
70549 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70550 }
70551 done:
70552 if (!PageHWPoison(hpage))
70553 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70554 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70555 set_page_hwpoison_huge_page(hpage);
70556 dequeue_hwpoisoned_huge_page(hpage);
70557 /* keep elevated page count for bad page */
70558 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70559 return ret;
70560
70561 done:
70562 - atomic_long_add(1, &mce_bad_pages);
70563 + atomic_long_add_unchecked(1, &mce_bad_pages);
70564 SetPageHWPoison(page);
70565 /* keep elevated page count for bad page */
70566 return ret;
70567 diff --git a/mm/memory.c b/mm/memory.c
70568 index 10b4dda..764ee07 100644
70569 --- a/mm/memory.c
70570 +++ b/mm/memory.c
70571 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70572 return;
70573
70574 pmd = pmd_offset(pud, start);
70575 +
70576 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70577 pud_clear(pud);
70578 pmd_free_tlb(tlb, pmd, start);
70579 +#endif
70580 +
70581 }
70582
70583 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70584 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70585 if (end - 1 > ceiling - 1)
70586 return;
70587
70588 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70589 pud = pud_offset(pgd, start);
70590 pgd_clear(pgd);
70591 pud_free_tlb(tlb, pud, start);
70592 +#endif
70593 +
70594 }
70595
70596 /*
70597 @@ -1593,12 +1600,6 @@ no_page_table:
70598 return page;
70599 }
70600
70601 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70602 -{
70603 - return stack_guard_page_start(vma, addr) ||
70604 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70605 -}
70606 -
70607 /**
70608 * __get_user_pages() - pin user pages in memory
70609 * @tsk: task_struct of target task
70610 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70611 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70612 i = 0;
70613
70614 - do {
70615 + while (nr_pages) {
70616 struct vm_area_struct *vma;
70617
70618 - vma = find_extend_vma(mm, start);
70619 + vma = find_vma(mm, start);
70620 if (!vma && in_gate_area(mm, start)) {
70621 unsigned long pg = start & PAGE_MASK;
70622 pgd_t *pgd;
70623 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70624 goto next_page;
70625 }
70626
70627 - if (!vma ||
70628 + if (!vma || start < vma->vm_start ||
70629 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70630 !(vm_flags & vma->vm_flags))
70631 return i ? : -EFAULT;
70632 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70633 int ret;
70634 unsigned int fault_flags = 0;
70635
70636 - /* For mlock, just skip the stack guard page. */
70637 - if (foll_flags & FOLL_MLOCK) {
70638 - if (stack_guard_page(vma, start))
70639 - goto next_page;
70640 - }
70641 if (foll_flags & FOLL_WRITE)
70642 fault_flags |= FAULT_FLAG_WRITE;
70643 if (nonblocking)
70644 @@ -1827,7 +1823,7 @@ next_page:
70645 start += PAGE_SIZE;
70646 nr_pages--;
70647 } while (nr_pages && start < vma->vm_end);
70648 - } while (nr_pages);
70649 + }
70650 return i;
70651 }
70652 EXPORT_SYMBOL(__get_user_pages);
70653 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70654 page_add_file_rmap(page);
70655 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70656
70657 +#ifdef CONFIG_PAX_SEGMEXEC
70658 + pax_mirror_file_pte(vma, addr, page, ptl);
70659 +#endif
70660 +
70661 retval = 0;
70662 pte_unmap_unlock(pte, ptl);
70663 return retval;
70664 @@ -2068,10 +2068,22 @@ out:
70665 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70666 struct page *page)
70667 {
70668 +
70669 +#ifdef CONFIG_PAX_SEGMEXEC
70670 + struct vm_area_struct *vma_m;
70671 +#endif
70672 +
70673 if (addr < vma->vm_start || addr >= vma->vm_end)
70674 return -EFAULT;
70675 if (!page_count(page))
70676 return -EINVAL;
70677 +
70678 +#ifdef CONFIG_PAX_SEGMEXEC
70679 + vma_m = pax_find_mirror_vma(vma);
70680 + if (vma_m)
70681 + vma_m->vm_flags |= VM_INSERTPAGE;
70682 +#endif
70683 +
70684 vma->vm_flags |= VM_INSERTPAGE;
70685 return insert_page(vma, addr, page, vma->vm_page_prot);
70686 }
70687 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70688 unsigned long pfn)
70689 {
70690 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70691 + BUG_ON(vma->vm_mirror);
70692
70693 if (addr < vma->vm_start || addr >= vma->vm_end)
70694 return -EFAULT;
70695 @@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70696 copy_user_highpage(dst, src, va, vma);
70697 }
70698
70699 +#ifdef CONFIG_PAX_SEGMEXEC
70700 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70701 +{
70702 + struct mm_struct *mm = vma->vm_mm;
70703 + spinlock_t *ptl;
70704 + pte_t *pte, entry;
70705 +
70706 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70707 + entry = *pte;
70708 + if (!pte_present(entry)) {
70709 + if (!pte_none(entry)) {
70710 + BUG_ON(pte_file(entry));
70711 + free_swap_and_cache(pte_to_swp_entry(entry));
70712 + pte_clear_not_present_full(mm, address, pte, 0);
70713 + }
70714 + } else {
70715 + struct page *page;
70716 +
70717 + flush_cache_page(vma, address, pte_pfn(entry));
70718 + entry = ptep_clear_flush(vma, address, pte);
70719 + BUG_ON(pte_dirty(entry));
70720 + page = vm_normal_page(vma, address, entry);
70721 + if (page) {
70722 + update_hiwater_rss(mm);
70723 + if (PageAnon(page))
70724 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70725 + else
70726 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70727 + page_remove_rmap(page);
70728 + page_cache_release(page);
70729 + }
70730 + }
70731 + pte_unmap_unlock(pte, ptl);
70732 +}
70733 +
70734 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70735 + *
70736 + * the ptl of the lower mapped page is held on entry and is not released on exit
70737 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70738 + */
70739 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70740 +{
70741 + struct mm_struct *mm = vma->vm_mm;
70742 + unsigned long address_m;
70743 + spinlock_t *ptl_m;
70744 + struct vm_area_struct *vma_m;
70745 + pmd_t *pmd_m;
70746 + pte_t *pte_m, entry_m;
70747 +
70748 + BUG_ON(!page_m || !PageAnon(page_m));
70749 +
70750 + vma_m = pax_find_mirror_vma(vma);
70751 + if (!vma_m)
70752 + return;
70753 +
70754 + BUG_ON(!PageLocked(page_m));
70755 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70756 + address_m = address + SEGMEXEC_TASK_SIZE;
70757 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70758 + pte_m = pte_offset_map(pmd_m, address_m);
70759 + ptl_m = pte_lockptr(mm, pmd_m);
70760 + if (ptl != ptl_m) {
70761 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70762 + if (!pte_none(*pte_m))
70763 + goto out;
70764 + }
70765 +
70766 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70767 + page_cache_get(page_m);
70768 + page_add_anon_rmap(page_m, vma_m, address_m);
70769 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70770 + set_pte_at(mm, address_m, pte_m, entry_m);
70771 + update_mmu_cache(vma_m, address_m, entry_m);
70772 +out:
70773 + if (ptl != ptl_m)
70774 + spin_unlock(ptl_m);
70775 + pte_unmap(pte_m);
70776 + unlock_page(page_m);
70777 +}
70778 +
70779 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70780 +{
70781 + struct mm_struct *mm = vma->vm_mm;
70782 + unsigned long address_m;
70783 + spinlock_t *ptl_m;
70784 + struct vm_area_struct *vma_m;
70785 + pmd_t *pmd_m;
70786 + pte_t *pte_m, entry_m;
70787 +
70788 + BUG_ON(!page_m || PageAnon(page_m));
70789 +
70790 + vma_m = pax_find_mirror_vma(vma);
70791 + if (!vma_m)
70792 + return;
70793 +
70794 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70795 + address_m = address + SEGMEXEC_TASK_SIZE;
70796 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70797 + pte_m = pte_offset_map(pmd_m, address_m);
70798 + ptl_m = pte_lockptr(mm, pmd_m);
70799 + if (ptl != ptl_m) {
70800 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70801 + if (!pte_none(*pte_m))
70802 + goto out;
70803 + }
70804 +
70805 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70806 + page_cache_get(page_m);
70807 + page_add_file_rmap(page_m);
70808 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70809 + set_pte_at(mm, address_m, pte_m, entry_m);
70810 + update_mmu_cache(vma_m, address_m, entry_m);
70811 +out:
70812 + if (ptl != ptl_m)
70813 + spin_unlock(ptl_m);
70814 + pte_unmap(pte_m);
70815 +}
70816 +
70817 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70818 +{
70819 + struct mm_struct *mm = vma->vm_mm;
70820 + unsigned long address_m;
70821 + spinlock_t *ptl_m;
70822 + struct vm_area_struct *vma_m;
70823 + pmd_t *pmd_m;
70824 + pte_t *pte_m, entry_m;
70825 +
70826 + vma_m = pax_find_mirror_vma(vma);
70827 + if (!vma_m)
70828 + return;
70829 +
70830 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70831 + address_m = address + SEGMEXEC_TASK_SIZE;
70832 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70833 + pte_m = pte_offset_map(pmd_m, address_m);
70834 + ptl_m = pte_lockptr(mm, pmd_m);
70835 + if (ptl != ptl_m) {
70836 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70837 + if (!pte_none(*pte_m))
70838 + goto out;
70839 + }
70840 +
70841 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70842 + set_pte_at(mm, address_m, pte_m, entry_m);
70843 +out:
70844 + if (ptl != ptl_m)
70845 + spin_unlock(ptl_m);
70846 + pte_unmap(pte_m);
70847 +}
70848 +
70849 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70850 +{
70851 + struct page *page_m;
70852 + pte_t entry;
70853 +
70854 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70855 + goto out;
70856 +
70857 + entry = *pte;
70858 + page_m = vm_normal_page(vma, address, entry);
70859 + if (!page_m)
70860 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70861 + else if (PageAnon(page_m)) {
70862 + if (pax_find_mirror_vma(vma)) {
70863 + pte_unmap_unlock(pte, ptl);
70864 + lock_page(page_m);
70865 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70866 + if (pte_same(entry, *pte))
70867 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70868 + else
70869 + unlock_page(page_m);
70870 + }
70871 + } else
70872 + pax_mirror_file_pte(vma, address, page_m, ptl);
70873 +
70874 +out:
70875 + pte_unmap_unlock(pte, ptl);
70876 +}
70877 +#endif
70878 +
70879 /*
70880 * This routine handles present pages, when users try to write
70881 * to a shared page. It is done by copying the page to a new address
70882 @@ -2683,6 +2876,12 @@ gotten:
70883 */
70884 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70885 if (likely(pte_same(*page_table, orig_pte))) {
70886 +
70887 +#ifdef CONFIG_PAX_SEGMEXEC
70888 + if (pax_find_mirror_vma(vma))
70889 + BUG_ON(!trylock_page(new_page));
70890 +#endif
70891 +
70892 if (old_page) {
70893 if (!PageAnon(old_page)) {
70894 dec_mm_counter_fast(mm, MM_FILEPAGES);
70895 @@ -2734,6 +2933,10 @@ gotten:
70896 page_remove_rmap(old_page);
70897 }
70898
70899 +#ifdef CONFIG_PAX_SEGMEXEC
70900 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70901 +#endif
70902 +
70903 /* Free the old page.. */
70904 new_page = old_page;
70905 ret |= VM_FAULT_WRITE;
70906 @@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70907 swap_free(entry);
70908 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70909 try_to_free_swap(page);
70910 +
70911 +#ifdef CONFIG_PAX_SEGMEXEC
70912 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70913 +#endif
70914 +
70915 unlock_page(page);
70916 if (swapcache) {
70917 /*
70918 @@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70919
70920 /* No need to invalidate - it was non-present before */
70921 update_mmu_cache(vma, address, page_table);
70922 +
70923 +#ifdef CONFIG_PAX_SEGMEXEC
70924 + pax_mirror_anon_pte(vma, address, page, ptl);
70925 +#endif
70926 +
70927 unlock:
70928 pte_unmap_unlock(page_table, ptl);
70929 out:
70930 @@ -3055,40 +3268,6 @@ out_release:
70931 }
70932
70933 /*
70934 - * This is like a special single-page "expand_{down|up}wards()",
70935 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70936 - * doesn't hit another vma.
70937 - */
70938 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70939 -{
70940 - address &= PAGE_MASK;
70941 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70942 - struct vm_area_struct *prev = vma->vm_prev;
70943 -
70944 - /*
70945 - * Is there a mapping abutting this one below?
70946 - *
70947 - * That's only ok if it's the same stack mapping
70948 - * that has gotten split..
70949 - */
70950 - if (prev && prev->vm_end == address)
70951 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70952 -
70953 - expand_downwards(vma, address - PAGE_SIZE);
70954 - }
70955 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70956 - struct vm_area_struct *next = vma->vm_next;
70957 -
70958 - /* As VM_GROWSDOWN but s/below/above/ */
70959 - if (next && next->vm_start == address + PAGE_SIZE)
70960 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70961 -
70962 - expand_upwards(vma, address + PAGE_SIZE);
70963 - }
70964 - return 0;
70965 -}
70966 -
70967 -/*
70968 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70969 * but allow concurrent faults), and pte mapped but not yet locked.
70970 * We return with mmap_sem still held, but pte unmapped and unlocked.
70971 @@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70972 unsigned long address, pte_t *page_table, pmd_t *pmd,
70973 unsigned int flags)
70974 {
70975 - struct page *page;
70976 + struct page *page = NULL;
70977 spinlock_t *ptl;
70978 pte_t entry;
70979
70980 - pte_unmap(page_table);
70981 -
70982 - /* Check if we need to add a guard page to the stack */
70983 - if (check_stack_guard_page(vma, address) < 0)
70984 - return VM_FAULT_SIGBUS;
70985 -
70986 - /* Use the zero-page for reads */
70987 if (!(flags & FAULT_FLAG_WRITE)) {
70988 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70989 vma->vm_page_prot));
70990 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70991 + ptl = pte_lockptr(mm, pmd);
70992 + spin_lock(ptl);
70993 if (!pte_none(*page_table))
70994 goto unlock;
70995 goto setpte;
70996 }
70997
70998 /* Allocate our own private page. */
70999 + pte_unmap(page_table);
71000 +
71001 if (unlikely(anon_vma_prepare(vma)))
71002 goto oom;
71003 page = alloc_zeroed_user_highpage_movable(vma, address);
71004 @@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71005 if (!pte_none(*page_table))
71006 goto release;
71007
71008 +#ifdef CONFIG_PAX_SEGMEXEC
71009 + if (pax_find_mirror_vma(vma))
71010 + BUG_ON(!trylock_page(page));
71011 +#endif
71012 +
71013 inc_mm_counter_fast(mm, MM_ANONPAGES);
71014 page_add_new_anon_rmap(page, vma, address);
71015 setpte:
71016 @@ -3143,6 +3323,12 @@ setpte:
71017
71018 /* No need to invalidate - it was non-present before */
71019 update_mmu_cache(vma, address, page_table);
71020 +
71021 +#ifdef CONFIG_PAX_SEGMEXEC
71022 + if (page)
71023 + pax_mirror_anon_pte(vma, address, page, ptl);
71024 +#endif
71025 +
71026 unlock:
71027 pte_unmap_unlock(page_table, ptl);
71028 return 0;
71029 @@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71030 */
71031 /* Only go through if we didn't race with anybody else... */
71032 if (likely(pte_same(*page_table, orig_pte))) {
71033 +
71034 +#ifdef CONFIG_PAX_SEGMEXEC
71035 + if (anon && pax_find_mirror_vma(vma))
71036 + BUG_ON(!trylock_page(page));
71037 +#endif
71038 +
71039 flush_icache_page(vma, page);
71040 entry = mk_pte(page, vma->vm_page_prot);
71041 if (flags & FAULT_FLAG_WRITE)
71042 @@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71043
71044 /* no need to invalidate: a not-present page won't be cached */
71045 update_mmu_cache(vma, address, page_table);
71046 +
71047 +#ifdef CONFIG_PAX_SEGMEXEC
71048 + if (anon)
71049 + pax_mirror_anon_pte(vma, address, page, ptl);
71050 + else
71051 + pax_mirror_file_pte(vma, address, page, ptl);
71052 +#endif
71053 +
71054 } else {
71055 if (cow_page)
71056 mem_cgroup_uncharge_page(cow_page);
71057 @@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
71058 if (flags & FAULT_FLAG_WRITE)
71059 flush_tlb_fix_spurious_fault(vma, address);
71060 }
71061 +
71062 +#ifdef CONFIG_PAX_SEGMEXEC
71063 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71064 + return 0;
71065 +#endif
71066 +
71067 unlock:
71068 pte_unmap_unlock(pte, ptl);
71069 return 0;
71070 @@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71071 pmd_t *pmd;
71072 pte_t *pte;
71073
71074 +#ifdef CONFIG_PAX_SEGMEXEC
71075 + struct vm_area_struct *vma_m;
71076 +#endif
71077 +
71078 __set_current_state(TASK_RUNNING);
71079
71080 count_vm_event(PGFAULT);
71081 @@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71082 if (unlikely(is_vm_hugetlb_page(vma)))
71083 return hugetlb_fault(mm, vma, address, flags);
71084
71085 +#ifdef CONFIG_PAX_SEGMEXEC
71086 + vma_m = pax_find_mirror_vma(vma);
71087 + if (vma_m) {
71088 + unsigned long address_m;
71089 + pgd_t *pgd_m;
71090 + pud_t *pud_m;
71091 + pmd_t *pmd_m;
71092 +
71093 + if (vma->vm_start > vma_m->vm_start) {
71094 + address_m = address;
71095 + address -= SEGMEXEC_TASK_SIZE;
71096 + vma = vma_m;
71097 + } else
71098 + address_m = address + SEGMEXEC_TASK_SIZE;
71099 +
71100 + pgd_m = pgd_offset(mm, address_m);
71101 + pud_m = pud_alloc(mm, pgd_m, address_m);
71102 + if (!pud_m)
71103 + return VM_FAULT_OOM;
71104 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71105 + if (!pmd_m)
71106 + return VM_FAULT_OOM;
71107 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71108 + return VM_FAULT_OOM;
71109 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71110 + }
71111 +#endif
71112 +
71113 pgd = pgd_offset(mm, address);
71114 pud = pud_alloc(mm, pgd, address);
71115 if (!pud)
71116 @@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71117 * run pte_offset_map on the pmd, if an huge pmd could
71118 * materialize from under us from a different thread.
71119 */
71120 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71121 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71122 return VM_FAULT_OOM;
71123 /* if an huge pmd materialized from under us just retry later */
71124 if (unlikely(pmd_trans_huge(*pmd)))
71125 @@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
71126 gate_vma.vm_start = FIXADDR_USER_START;
71127 gate_vma.vm_end = FIXADDR_USER_END;
71128 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71129 - gate_vma.vm_page_prot = __P101;
71130 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71131 /*
71132 * Make sure the vDSO gets into every core dump.
71133 * Dumping its contents makes post-mortem fully interpretable later
71134 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71135 index 0a37570..2048346 100644
71136 --- a/mm/mempolicy.c
71137 +++ b/mm/mempolicy.c
71138 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71139 unsigned long vmstart;
71140 unsigned long vmend;
71141
71142 +#ifdef CONFIG_PAX_SEGMEXEC
71143 + struct vm_area_struct *vma_m;
71144 +#endif
71145 +
71146 vma = find_vma(mm, start);
71147 if (!vma || vma->vm_start > start)
71148 return -EFAULT;
71149 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71150 err = policy_vma(vma, new_pol);
71151 if (err)
71152 goto out;
71153 +
71154 +#ifdef CONFIG_PAX_SEGMEXEC
71155 + vma_m = pax_find_mirror_vma(vma);
71156 + if (vma_m) {
71157 + err = policy_vma(vma_m, new_pol);
71158 + if (err)
71159 + goto out;
71160 + }
71161 +#endif
71162 +
71163 }
71164
71165 out:
71166 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71167
71168 if (end < start)
71169 return -EINVAL;
71170 +
71171 +#ifdef CONFIG_PAX_SEGMEXEC
71172 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71173 + if (end > SEGMEXEC_TASK_SIZE)
71174 + return -EINVAL;
71175 + } else
71176 +#endif
71177 +
71178 + if (end > TASK_SIZE)
71179 + return -EINVAL;
71180 +
71181 if (end == start)
71182 return 0;
71183
71184 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71185 if (!mm)
71186 goto out;
71187
71188 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71189 + if (mm != current->mm &&
71190 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71191 + err = -EPERM;
71192 + goto out;
71193 + }
71194 +#endif
71195 +
71196 /*
71197 * Check if this process has the right to modify the specified
71198 * process. The right exists if the process has administrative
71199 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71200 rcu_read_lock();
71201 tcred = __task_cred(task);
71202 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71203 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71204 - !capable(CAP_SYS_NICE)) {
71205 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71206 rcu_read_unlock();
71207 err = -EPERM;
71208 goto out;
71209 diff --git a/mm/migrate.c b/mm/migrate.c
71210 index 1503b6b..156c672 100644
71211 --- a/mm/migrate.c
71212 +++ b/mm/migrate.c
71213 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71214 if (!mm)
71215 return -EINVAL;
71216
71217 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71218 + if (mm != current->mm &&
71219 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71220 + err = -EPERM;
71221 + goto out;
71222 + }
71223 +#endif
71224 +
71225 /*
71226 * Check if this process has the right to modify the specified
71227 * process. The right exists if the process has administrative
71228 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71229 rcu_read_lock();
71230 tcred = __task_cred(task);
71231 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71232 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71233 - !capable(CAP_SYS_NICE)) {
71234 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71235 rcu_read_unlock();
71236 err = -EPERM;
71237 goto out;
71238 diff --git a/mm/mlock.c b/mm/mlock.c
71239 index ef726e8..13e0901 100644
71240 --- a/mm/mlock.c
71241 +++ b/mm/mlock.c
71242 @@ -13,6 +13,7 @@
71243 #include <linux/pagemap.h>
71244 #include <linux/mempolicy.h>
71245 #include <linux/syscalls.h>
71246 +#include <linux/security.h>
71247 #include <linux/sched.h>
71248 #include <linux/export.h>
71249 #include <linux/rmap.h>
71250 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71251 return -EINVAL;
71252 if (end == start)
71253 return 0;
71254 + if (end > TASK_SIZE)
71255 + return -EINVAL;
71256 +
71257 vma = find_vma(current->mm, start);
71258 if (!vma || vma->vm_start > start)
71259 return -ENOMEM;
71260 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71261 for (nstart = start ; ; ) {
71262 vm_flags_t newflags;
71263
71264 +#ifdef CONFIG_PAX_SEGMEXEC
71265 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71266 + break;
71267 +#endif
71268 +
71269 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71270
71271 newflags = vma->vm_flags | VM_LOCKED;
71272 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71273 lock_limit >>= PAGE_SHIFT;
71274
71275 /* check against resource limits */
71276 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71277 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71278 error = do_mlock(start, len, 1);
71279 up_write(&current->mm->mmap_sem);
71280 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71281 static int do_mlockall(int flags)
71282 {
71283 struct vm_area_struct * vma, * prev = NULL;
71284 - unsigned int def_flags = 0;
71285
71286 if (flags & MCL_FUTURE)
71287 - def_flags = VM_LOCKED;
71288 - current->mm->def_flags = def_flags;
71289 + current->mm->def_flags |= VM_LOCKED;
71290 + else
71291 + current->mm->def_flags &= ~VM_LOCKED;
71292 if (flags == MCL_FUTURE)
71293 goto out;
71294
71295 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71296 vm_flags_t newflags;
71297
71298 +#ifdef CONFIG_PAX_SEGMEXEC
71299 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71300 + break;
71301 +#endif
71302 +
71303 + BUG_ON(vma->vm_end > TASK_SIZE);
71304 newflags = vma->vm_flags | VM_LOCKED;
71305 if (!(flags & MCL_CURRENT))
71306 newflags &= ~VM_LOCKED;
71307 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71308 lock_limit >>= PAGE_SHIFT;
71309
71310 ret = -ENOMEM;
71311 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71312 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71313 capable(CAP_IPC_LOCK))
71314 ret = do_mlockall(flags);
71315 diff --git a/mm/mmap.c b/mm/mmap.c
71316 index da15a79..314aef3 100644
71317 --- a/mm/mmap.c
71318 +++ b/mm/mmap.c
71319 @@ -46,6 +46,16 @@
71320 #define arch_rebalance_pgtables(addr, len) (addr)
71321 #endif
71322
71323 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71324 +{
71325 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71326 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71327 + up_read(&mm->mmap_sem);
71328 + BUG();
71329 + }
71330 +#endif
71331 +}
71332 +
71333 static void unmap_region(struct mm_struct *mm,
71334 struct vm_area_struct *vma, struct vm_area_struct *prev,
71335 unsigned long start, unsigned long end);
71336 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71337 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71338 *
71339 */
71340 -pgprot_t protection_map[16] = {
71341 +pgprot_t protection_map[16] __read_only = {
71342 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71343 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71344 };
71345
71346 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71347 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71348 {
71349 - return __pgprot(pgprot_val(protection_map[vm_flags &
71350 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71351 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71352 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71353 +
71354 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71355 + if (!(__supported_pte_mask & _PAGE_NX) &&
71356 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71357 + (vm_flags & (VM_READ | VM_WRITE)))
71358 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71359 +#endif
71360 +
71361 + return prot;
71362 }
71363 EXPORT_SYMBOL(vm_get_page_prot);
71364
71365 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71366 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71367 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71368 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71369 /*
71370 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71371 * other variables. It can be updated by several CPUs frequently.
71372 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71373 struct vm_area_struct *next = vma->vm_next;
71374
71375 might_sleep();
71376 + BUG_ON(vma->vm_mirror);
71377 if (vma->vm_ops && vma->vm_ops->close)
71378 vma->vm_ops->close(vma);
71379 if (vma->vm_file) {
71380 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71381 * not page aligned -Ram Gupta
71382 */
71383 rlim = rlimit(RLIMIT_DATA);
71384 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71385 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71386 (mm->end_data - mm->start_data) > rlim)
71387 goto out;
71388 @@ -689,6 +711,12 @@ static int
71389 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71390 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71391 {
71392 +
71393 +#ifdef CONFIG_PAX_SEGMEXEC
71394 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71395 + return 0;
71396 +#endif
71397 +
71398 if (is_mergeable_vma(vma, file, vm_flags) &&
71399 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71400 if (vma->vm_pgoff == vm_pgoff)
71401 @@ -708,6 +736,12 @@ static int
71402 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71403 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71404 {
71405 +
71406 +#ifdef CONFIG_PAX_SEGMEXEC
71407 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71408 + return 0;
71409 +#endif
71410 +
71411 if (is_mergeable_vma(vma, file, vm_flags) &&
71412 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71413 pgoff_t vm_pglen;
71414 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71415 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71416 struct vm_area_struct *prev, unsigned long addr,
71417 unsigned long end, unsigned long vm_flags,
71418 - struct anon_vma *anon_vma, struct file *file,
71419 + struct anon_vma *anon_vma, struct file *file,
71420 pgoff_t pgoff, struct mempolicy *policy)
71421 {
71422 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71423 struct vm_area_struct *area, *next;
71424 int err;
71425
71426 +#ifdef CONFIG_PAX_SEGMEXEC
71427 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71428 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71429 +
71430 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71431 +#endif
71432 +
71433 /*
71434 * We later require that vma->vm_flags == vm_flags,
71435 * so this tests vma->vm_flags & VM_SPECIAL, too.
71436 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71437 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71438 next = next->vm_next;
71439
71440 +#ifdef CONFIG_PAX_SEGMEXEC
71441 + if (prev)
71442 + prev_m = pax_find_mirror_vma(prev);
71443 + if (area)
71444 + area_m = pax_find_mirror_vma(area);
71445 + if (next)
71446 + next_m = pax_find_mirror_vma(next);
71447 +#endif
71448 +
71449 /*
71450 * Can it merge with the predecessor?
71451 */
71452 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71453 /* cases 1, 6 */
71454 err = vma_adjust(prev, prev->vm_start,
71455 next->vm_end, prev->vm_pgoff, NULL);
71456 - } else /* cases 2, 5, 7 */
71457 +
71458 +#ifdef CONFIG_PAX_SEGMEXEC
71459 + if (!err && prev_m)
71460 + err = vma_adjust(prev_m, prev_m->vm_start,
71461 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71462 +#endif
71463 +
71464 + } else { /* cases 2, 5, 7 */
71465 err = vma_adjust(prev, prev->vm_start,
71466 end, prev->vm_pgoff, NULL);
71467 +
71468 +#ifdef CONFIG_PAX_SEGMEXEC
71469 + if (!err && prev_m)
71470 + err = vma_adjust(prev_m, prev_m->vm_start,
71471 + end_m, prev_m->vm_pgoff, NULL);
71472 +#endif
71473 +
71474 + }
71475 if (err)
71476 return NULL;
71477 khugepaged_enter_vma_merge(prev);
71478 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71479 mpol_equal(policy, vma_policy(next)) &&
71480 can_vma_merge_before(next, vm_flags,
71481 anon_vma, file, pgoff+pglen)) {
71482 - if (prev && addr < prev->vm_end) /* case 4 */
71483 + if (prev && addr < prev->vm_end) { /* case 4 */
71484 err = vma_adjust(prev, prev->vm_start,
71485 addr, prev->vm_pgoff, NULL);
71486 - else /* cases 3, 8 */
71487 +
71488 +#ifdef CONFIG_PAX_SEGMEXEC
71489 + if (!err && prev_m)
71490 + err = vma_adjust(prev_m, prev_m->vm_start,
71491 + addr_m, prev_m->vm_pgoff, NULL);
71492 +#endif
71493 +
71494 + } else { /* cases 3, 8 */
71495 err = vma_adjust(area, addr, next->vm_end,
71496 next->vm_pgoff - pglen, NULL);
71497 +
71498 +#ifdef CONFIG_PAX_SEGMEXEC
71499 + if (!err && area_m)
71500 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71501 + next_m->vm_pgoff - pglen, NULL);
71502 +#endif
71503 +
71504 + }
71505 if (err)
71506 return NULL;
71507 khugepaged_enter_vma_merge(area);
71508 @@ -921,14 +1001,11 @@ none:
71509 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71510 struct file *file, long pages)
71511 {
71512 - const unsigned long stack_flags
71513 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71514 -
71515 if (file) {
71516 mm->shared_vm += pages;
71517 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71518 mm->exec_vm += pages;
71519 - } else if (flags & stack_flags)
71520 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71521 mm->stack_vm += pages;
71522 if (flags & (VM_RESERVED|VM_IO))
71523 mm->reserved_vm += pages;
71524 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71525 * (the exception is when the underlying filesystem is noexec
71526 * mounted, in which case we dont add PROT_EXEC.)
71527 */
71528 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71529 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71530 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71531 prot |= PROT_EXEC;
71532
71533 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71534 /* Obtain the address to map to. we verify (or select) it and ensure
71535 * that it represents a valid section of the address space.
71536 */
71537 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71538 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71539 if (addr & ~PAGE_MASK)
71540 return addr;
71541
71542 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71543 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71544 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71545
71546 +#ifdef CONFIG_PAX_MPROTECT
71547 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71548 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71549 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71550 + gr_log_rwxmmap(file);
71551 +
71552 +#ifdef CONFIG_PAX_EMUPLT
71553 + vm_flags &= ~VM_EXEC;
71554 +#else
71555 + return -EPERM;
71556 +#endif
71557 +
71558 + }
71559 +
71560 + if (!(vm_flags & VM_EXEC))
71561 + vm_flags &= ~VM_MAYEXEC;
71562 +#else
71563 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71564 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71565 +#endif
71566 + else
71567 + vm_flags &= ~VM_MAYWRITE;
71568 + }
71569 +#endif
71570 +
71571 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71572 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71573 + vm_flags &= ~VM_PAGEEXEC;
71574 +#endif
71575 +
71576 if (flags & MAP_LOCKED)
71577 if (!can_do_mlock())
71578 return -EPERM;
71579 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71580 locked += mm->locked_vm;
71581 lock_limit = rlimit(RLIMIT_MEMLOCK);
71582 lock_limit >>= PAGE_SHIFT;
71583 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71584 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71585 return -EAGAIN;
71586 }
71587 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71588 if (error)
71589 return error;
71590
71591 + if (!gr_acl_handle_mmap(file, prot))
71592 + return -EACCES;
71593 +
71594 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71595 }
71596 EXPORT_SYMBOL(do_mmap_pgoff);
71597 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71598 vm_flags_t vm_flags = vma->vm_flags;
71599
71600 /* If it was private or non-writable, the write bit is already clear */
71601 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71602 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71603 return 0;
71604
71605 /* The backer wishes to know when pages are first written to? */
71606 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71607 unsigned long charged = 0;
71608 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71609
71610 +#ifdef CONFIG_PAX_SEGMEXEC
71611 + struct vm_area_struct *vma_m = NULL;
71612 +#endif
71613 +
71614 + /*
71615 + * mm->mmap_sem is required to protect against another thread
71616 + * changing the mappings in case we sleep.
71617 + */
71618 + verify_mm_writelocked(mm);
71619 +
71620 /* Clear old maps */
71621 error = -ENOMEM;
71622 -munmap_back:
71623 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71624 if (vma && vma->vm_start < addr + len) {
71625 if (do_munmap(mm, addr, len))
71626 return -ENOMEM;
71627 - goto munmap_back;
71628 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71629 + BUG_ON(vma && vma->vm_start < addr + len);
71630 }
71631
71632 /* Check against address space limit. */
71633 @@ -1258,6 +1379,16 @@ munmap_back:
71634 goto unacct_error;
71635 }
71636
71637 +#ifdef CONFIG_PAX_SEGMEXEC
71638 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71639 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71640 + if (!vma_m) {
71641 + error = -ENOMEM;
71642 + goto free_vma;
71643 + }
71644 + }
71645 +#endif
71646 +
71647 vma->vm_mm = mm;
71648 vma->vm_start = addr;
71649 vma->vm_end = addr + len;
71650 @@ -1282,6 +1413,19 @@ munmap_back:
71651 error = file->f_op->mmap(file, vma);
71652 if (error)
71653 goto unmap_and_free_vma;
71654 +
71655 +#ifdef CONFIG_PAX_SEGMEXEC
71656 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71657 + added_exe_file_vma(mm);
71658 +#endif
71659 +
71660 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71661 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71662 + vma->vm_flags |= VM_PAGEEXEC;
71663 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71664 + }
71665 +#endif
71666 +
71667 if (vm_flags & VM_EXECUTABLE)
71668 added_exe_file_vma(mm);
71669
71670 @@ -1319,6 +1463,11 @@ munmap_back:
71671 vma_link(mm, vma, prev, rb_link, rb_parent);
71672 file = vma->vm_file;
71673
71674 +#ifdef CONFIG_PAX_SEGMEXEC
71675 + if (vma_m)
71676 + BUG_ON(pax_mirror_vma(vma_m, vma));
71677 +#endif
71678 +
71679 /* Once vma denies write, undo our temporary denial count */
71680 if (correct_wcount)
71681 atomic_inc(&inode->i_writecount);
71682 @@ -1327,6 +1476,7 @@ out:
71683
71684 mm->total_vm += len >> PAGE_SHIFT;
71685 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71686 + track_exec_limit(mm, addr, addr + len, vm_flags);
71687 if (vm_flags & VM_LOCKED) {
71688 if (!mlock_vma_pages_range(vma, addr, addr + len))
71689 mm->locked_vm += (len >> PAGE_SHIFT);
71690 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71691 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71692 charged = 0;
71693 free_vma:
71694 +
71695 +#ifdef CONFIG_PAX_SEGMEXEC
71696 + if (vma_m)
71697 + kmem_cache_free(vm_area_cachep, vma_m);
71698 +#endif
71699 +
71700 kmem_cache_free(vm_area_cachep, vma);
71701 unacct_error:
71702 if (charged)
71703 @@ -1351,6 +1507,44 @@ unacct_error:
71704 return error;
71705 }
71706
71707 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71708 +{
71709 + if (!vma) {
71710 +#ifdef CONFIG_STACK_GROWSUP
71711 + if (addr > sysctl_heap_stack_gap)
71712 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71713 + else
71714 + vma = find_vma(current->mm, 0);
71715 + if (vma && (vma->vm_flags & VM_GROWSUP))
71716 + return false;
71717 +#endif
71718 + return true;
71719 + }
71720 +
71721 + if (addr + len > vma->vm_start)
71722 + return false;
71723 +
71724 + if (vma->vm_flags & VM_GROWSDOWN)
71725 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71726 +#ifdef CONFIG_STACK_GROWSUP
71727 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71728 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71729 +#endif
71730 +
71731 + return true;
71732 +}
71733 +
71734 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71735 +{
71736 + if (vma->vm_start < len)
71737 + return -ENOMEM;
71738 + if (!(vma->vm_flags & VM_GROWSDOWN))
71739 + return vma->vm_start - len;
71740 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71741 + return vma->vm_start - len - sysctl_heap_stack_gap;
71742 + return -ENOMEM;
71743 +}
71744 +
71745 /* Get an address range which is currently unmapped.
71746 * For shmat() with addr=0.
71747 *
71748 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71749 if (flags & MAP_FIXED)
71750 return addr;
71751
71752 +#ifdef CONFIG_PAX_RANDMMAP
71753 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71754 +#endif
71755 +
71756 if (addr) {
71757 addr = PAGE_ALIGN(addr);
71758 - vma = find_vma(mm, addr);
71759 - if (TASK_SIZE - len >= addr &&
71760 - (!vma || addr + len <= vma->vm_start))
71761 - return addr;
71762 + if (TASK_SIZE - len >= addr) {
71763 + vma = find_vma(mm, addr);
71764 + if (check_heap_stack_gap(vma, addr, len))
71765 + return addr;
71766 + }
71767 }
71768 if (len > mm->cached_hole_size) {
71769 - start_addr = addr = mm->free_area_cache;
71770 + start_addr = addr = mm->free_area_cache;
71771 } else {
71772 - start_addr = addr = TASK_UNMAPPED_BASE;
71773 - mm->cached_hole_size = 0;
71774 + start_addr = addr = mm->mmap_base;
71775 + mm->cached_hole_size = 0;
71776 }
71777
71778 full_search:
71779 @@ -1399,34 +1598,40 @@ full_search:
71780 * Start a new search - just in case we missed
71781 * some holes.
71782 */
71783 - if (start_addr != TASK_UNMAPPED_BASE) {
71784 - addr = TASK_UNMAPPED_BASE;
71785 - start_addr = addr;
71786 + if (start_addr != mm->mmap_base) {
71787 + start_addr = addr = mm->mmap_base;
71788 mm->cached_hole_size = 0;
71789 goto full_search;
71790 }
71791 return -ENOMEM;
71792 }
71793 - if (!vma || addr + len <= vma->vm_start) {
71794 - /*
71795 - * Remember the place where we stopped the search:
71796 - */
71797 - mm->free_area_cache = addr + len;
71798 - return addr;
71799 - }
71800 + if (check_heap_stack_gap(vma, addr, len))
71801 + break;
71802 if (addr + mm->cached_hole_size < vma->vm_start)
71803 mm->cached_hole_size = vma->vm_start - addr;
71804 addr = vma->vm_end;
71805 }
71806 +
71807 + /*
71808 + * Remember the place where we stopped the search:
71809 + */
71810 + mm->free_area_cache = addr + len;
71811 + return addr;
71812 }
71813 #endif
71814
71815 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71816 {
71817 +
71818 +#ifdef CONFIG_PAX_SEGMEXEC
71819 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71820 + return;
71821 +#endif
71822 +
71823 /*
71824 * Is this a new hole at the lowest possible address?
71825 */
71826 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71827 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71828 mm->free_area_cache = addr;
71829 mm->cached_hole_size = ~0UL;
71830 }
71831 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71832 {
71833 struct vm_area_struct *vma;
71834 struct mm_struct *mm = current->mm;
71835 - unsigned long addr = addr0;
71836 + unsigned long base = mm->mmap_base, addr = addr0;
71837
71838 /* requested length too big for entire address space */
71839 if (len > TASK_SIZE)
71840 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71841 if (flags & MAP_FIXED)
71842 return addr;
71843
71844 +#ifdef CONFIG_PAX_RANDMMAP
71845 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71846 +#endif
71847 +
71848 /* requesting a specific address */
71849 if (addr) {
71850 addr = PAGE_ALIGN(addr);
71851 - vma = find_vma(mm, addr);
71852 - if (TASK_SIZE - len >= addr &&
71853 - (!vma || addr + len <= vma->vm_start))
71854 - return addr;
71855 + if (TASK_SIZE - len >= addr) {
71856 + vma = find_vma(mm, addr);
71857 + if (check_heap_stack_gap(vma, addr, len))
71858 + return addr;
71859 + }
71860 }
71861
71862 /* check if free_area_cache is useful for us */
71863 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71864 /* make sure it can fit in the remaining address space */
71865 if (addr > len) {
71866 vma = find_vma(mm, addr-len);
71867 - if (!vma || addr <= vma->vm_start)
71868 + if (check_heap_stack_gap(vma, addr - len, len))
71869 /* remember the address as a hint for next time */
71870 return (mm->free_area_cache = addr-len);
71871 }
71872 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71873 * return with success:
71874 */
71875 vma = find_vma(mm, addr);
71876 - if (!vma || addr+len <= vma->vm_start)
71877 + if (check_heap_stack_gap(vma, addr, len))
71878 /* remember the address as a hint for next time */
71879 return (mm->free_area_cache = addr);
71880
71881 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71882 mm->cached_hole_size = vma->vm_start - addr;
71883
71884 /* try just below the current vma->vm_start */
71885 - addr = vma->vm_start-len;
71886 - } while (len < vma->vm_start);
71887 + addr = skip_heap_stack_gap(vma, len);
71888 + } while (!IS_ERR_VALUE(addr));
71889
71890 bottomup:
71891 /*
71892 @@ -1510,13 +1720,21 @@ bottomup:
71893 * can happen with large stack limits and large mmap()
71894 * allocations.
71895 */
71896 + mm->mmap_base = TASK_UNMAPPED_BASE;
71897 +
71898 +#ifdef CONFIG_PAX_RANDMMAP
71899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71900 + mm->mmap_base += mm->delta_mmap;
71901 +#endif
71902 +
71903 + mm->free_area_cache = mm->mmap_base;
71904 mm->cached_hole_size = ~0UL;
71905 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71906 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71907 /*
71908 * Restore the topdown base:
71909 */
71910 - mm->free_area_cache = mm->mmap_base;
71911 + mm->mmap_base = base;
71912 + mm->free_area_cache = base;
71913 mm->cached_hole_size = ~0UL;
71914
71915 return addr;
71916 @@ -1525,6 +1743,12 @@ bottomup:
71917
71918 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71919 {
71920 +
71921 +#ifdef CONFIG_PAX_SEGMEXEC
71922 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71923 + return;
71924 +#endif
71925 +
71926 /*
71927 * Is this a new hole at the highest possible address?
71928 */
71929 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71930 mm->free_area_cache = addr;
71931
71932 /* dont allow allocations above current base */
71933 - if (mm->free_area_cache > mm->mmap_base)
71934 + if (mm->free_area_cache > mm->mmap_base) {
71935 mm->free_area_cache = mm->mmap_base;
71936 + mm->cached_hole_size = ~0UL;
71937 + }
71938 }
71939
71940 unsigned long
71941 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71942 return vma;
71943 }
71944
71945 +#ifdef CONFIG_PAX_SEGMEXEC
71946 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71947 +{
71948 + struct vm_area_struct *vma_m;
71949 +
71950 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71951 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71952 + BUG_ON(vma->vm_mirror);
71953 + return NULL;
71954 + }
71955 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71956 + vma_m = vma->vm_mirror;
71957 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71958 + BUG_ON(vma->vm_file != vma_m->vm_file);
71959 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71960 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71961 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71962 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71963 + return vma_m;
71964 +}
71965 +#endif
71966 +
71967 /*
71968 * Verify that the stack growth is acceptable and
71969 * update accounting. This is shared with both the
71970 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71971 return -ENOMEM;
71972
71973 /* Stack limit test */
71974 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71975 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71976 return -ENOMEM;
71977
71978 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71979 locked = mm->locked_vm + grow;
71980 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71981 limit >>= PAGE_SHIFT;
71982 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71983 if (locked > limit && !capable(CAP_IPC_LOCK))
71984 return -ENOMEM;
71985 }
71986 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71987 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71988 * vma is the last one with address > vma->vm_end. Have to extend vma.
71989 */
71990 +#ifndef CONFIG_IA64
71991 +static
71992 +#endif
71993 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71994 {
71995 int error;
71996 + bool locknext;
71997
71998 if (!(vma->vm_flags & VM_GROWSUP))
71999 return -EFAULT;
72000
72001 + /* Also guard against wrapping around to address 0. */
72002 + if (address < PAGE_ALIGN(address+1))
72003 + address = PAGE_ALIGN(address+1);
72004 + else
72005 + return -ENOMEM;
72006 +
72007 /*
72008 * We must make sure the anon_vma is allocated
72009 * so that the anon_vma locking is not a noop.
72010 */
72011 if (unlikely(anon_vma_prepare(vma)))
72012 return -ENOMEM;
72013 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72014 + if (locknext && anon_vma_prepare(vma->vm_next))
72015 + return -ENOMEM;
72016 vma_lock_anon_vma(vma);
72017 + if (locknext)
72018 + vma_lock_anon_vma(vma->vm_next);
72019
72020 /*
72021 * vma->vm_start/vm_end cannot change under us because the caller
72022 * is required to hold the mmap_sem in read mode. We need the
72023 - * anon_vma lock to serialize against concurrent expand_stacks.
72024 - * Also guard against wrapping around to address 0.
72025 + * anon_vma locks to serialize against concurrent expand_stacks
72026 + * and expand_upwards.
72027 */
72028 - if (address < PAGE_ALIGN(address+4))
72029 - address = PAGE_ALIGN(address+4);
72030 - else {
72031 - vma_unlock_anon_vma(vma);
72032 - return -ENOMEM;
72033 - }
72034 error = 0;
72035
72036 /* Somebody else might have raced and expanded it already */
72037 - if (address > vma->vm_end) {
72038 + 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)
72039 + error = -ENOMEM;
72040 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72041 unsigned long size, grow;
72042
72043 size = address - vma->vm_start;
72044 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72045 }
72046 }
72047 }
72048 + if (locknext)
72049 + vma_unlock_anon_vma(vma->vm_next);
72050 vma_unlock_anon_vma(vma);
72051 khugepaged_enter_vma_merge(vma);
72052 return error;
72053 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72054 unsigned long address)
72055 {
72056 int error;
72057 + bool lockprev = false;
72058 + struct vm_area_struct *prev;
72059
72060 /*
72061 * We must make sure the anon_vma is allocated
72062 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72063 if (error)
72064 return error;
72065
72066 + prev = vma->vm_prev;
72067 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72068 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72069 +#endif
72070 + if (lockprev && anon_vma_prepare(prev))
72071 + return -ENOMEM;
72072 + if (lockprev)
72073 + vma_lock_anon_vma(prev);
72074 +
72075 vma_lock_anon_vma(vma);
72076
72077 /*
72078 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72079 */
72080
72081 /* Somebody else might have raced and expanded it already */
72082 - if (address < vma->vm_start) {
72083 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72084 + error = -ENOMEM;
72085 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72086 unsigned long size, grow;
72087
72088 +#ifdef CONFIG_PAX_SEGMEXEC
72089 + struct vm_area_struct *vma_m;
72090 +
72091 + vma_m = pax_find_mirror_vma(vma);
72092 +#endif
72093 +
72094 size = vma->vm_end - address;
72095 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72096
72097 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72098 if (!error) {
72099 vma->vm_start = address;
72100 vma->vm_pgoff -= grow;
72101 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72102 +
72103 +#ifdef CONFIG_PAX_SEGMEXEC
72104 + if (vma_m) {
72105 + vma_m->vm_start -= grow << PAGE_SHIFT;
72106 + vma_m->vm_pgoff -= grow;
72107 + }
72108 +#endif
72109 +
72110 perf_event_mmap(vma);
72111 }
72112 }
72113 }
72114 vma_unlock_anon_vma(vma);
72115 + if (lockprev)
72116 + vma_unlock_anon_vma(prev);
72117 khugepaged_enter_vma_merge(vma);
72118 return error;
72119 }
72120 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72121 do {
72122 long nrpages = vma_pages(vma);
72123
72124 +#ifdef CONFIG_PAX_SEGMEXEC
72125 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72126 + vma = remove_vma(vma);
72127 + continue;
72128 + }
72129 +#endif
72130 +
72131 mm->total_vm -= nrpages;
72132 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72133 vma = remove_vma(vma);
72134 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72135 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72136 vma->vm_prev = NULL;
72137 do {
72138 +
72139 +#ifdef CONFIG_PAX_SEGMEXEC
72140 + if (vma->vm_mirror) {
72141 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72142 + vma->vm_mirror->vm_mirror = NULL;
72143 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72144 + vma->vm_mirror = NULL;
72145 + }
72146 +#endif
72147 +
72148 rb_erase(&vma->vm_rb, &mm->mm_rb);
72149 mm->map_count--;
72150 tail_vma = vma;
72151 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72152 struct vm_area_struct *new;
72153 int err = -ENOMEM;
72154
72155 +#ifdef CONFIG_PAX_SEGMEXEC
72156 + struct vm_area_struct *vma_m, *new_m = NULL;
72157 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72158 +#endif
72159 +
72160 if (is_vm_hugetlb_page(vma) && (addr &
72161 ~(huge_page_mask(hstate_vma(vma)))))
72162 return -EINVAL;
72163
72164 +#ifdef CONFIG_PAX_SEGMEXEC
72165 + vma_m = pax_find_mirror_vma(vma);
72166 +#endif
72167 +
72168 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72169 if (!new)
72170 goto out_err;
72171
72172 +#ifdef CONFIG_PAX_SEGMEXEC
72173 + if (vma_m) {
72174 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72175 + if (!new_m) {
72176 + kmem_cache_free(vm_area_cachep, new);
72177 + goto out_err;
72178 + }
72179 + }
72180 +#endif
72181 +
72182 /* most fields are the same, copy all, and then fixup */
72183 *new = *vma;
72184
72185 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72186 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72187 }
72188
72189 +#ifdef CONFIG_PAX_SEGMEXEC
72190 + if (vma_m) {
72191 + *new_m = *vma_m;
72192 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72193 + new_m->vm_mirror = new;
72194 + new->vm_mirror = new_m;
72195 +
72196 + if (new_below)
72197 + new_m->vm_end = addr_m;
72198 + else {
72199 + new_m->vm_start = addr_m;
72200 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72201 + }
72202 + }
72203 +#endif
72204 +
72205 pol = mpol_dup(vma_policy(vma));
72206 if (IS_ERR(pol)) {
72207 err = PTR_ERR(pol);
72208 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72209 else
72210 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72211
72212 +#ifdef CONFIG_PAX_SEGMEXEC
72213 + if (!err && vma_m) {
72214 + if (anon_vma_clone(new_m, vma_m))
72215 + goto out_free_mpol;
72216 +
72217 + mpol_get(pol);
72218 + vma_set_policy(new_m, pol);
72219 +
72220 + if (new_m->vm_file) {
72221 + get_file(new_m->vm_file);
72222 + if (vma_m->vm_flags & VM_EXECUTABLE)
72223 + added_exe_file_vma(mm);
72224 + }
72225 +
72226 + if (new_m->vm_ops && new_m->vm_ops->open)
72227 + new_m->vm_ops->open(new_m);
72228 +
72229 + if (new_below)
72230 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72231 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72232 + else
72233 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72234 +
72235 + if (err) {
72236 + if (new_m->vm_ops && new_m->vm_ops->close)
72237 + new_m->vm_ops->close(new_m);
72238 + if (new_m->vm_file) {
72239 + if (vma_m->vm_flags & VM_EXECUTABLE)
72240 + removed_exe_file_vma(mm);
72241 + fput(new_m->vm_file);
72242 + }
72243 + mpol_put(pol);
72244 + }
72245 + }
72246 +#endif
72247 +
72248 /* Success. */
72249 if (!err)
72250 return 0;
72251 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72252 removed_exe_file_vma(mm);
72253 fput(new->vm_file);
72254 }
72255 - unlink_anon_vmas(new);
72256 out_free_mpol:
72257 mpol_put(pol);
72258 out_free_vma:
72259 +
72260 +#ifdef CONFIG_PAX_SEGMEXEC
72261 + if (new_m) {
72262 + unlink_anon_vmas(new_m);
72263 + kmem_cache_free(vm_area_cachep, new_m);
72264 + }
72265 +#endif
72266 +
72267 + unlink_anon_vmas(new);
72268 kmem_cache_free(vm_area_cachep, new);
72269 out_err:
72270 return err;
72271 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72272 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72273 unsigned long addr, int new_below)
72274 {
72275 +
72276 +#ifdef CONFIG_PAX_SEGMEXEC
72277 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72278 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72279 + if (mm->map_count >= sysctl_max_map_count-1)
72280 + return -ENOMEM;
72281 + } else
72282 +#endif
72283 +
72284 if (mm->map_count >= sysctl_max_map_count)
72285 return -ENOMEM;
72286
72287 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72288 * work. This now handles partial unmappings.
72289 * Jeremy Fitzhardinge <jeremy@goop.org>
72290 */
72291 +#ifdef CONFIG_PAX_SEGMEXEC
72292 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72293 {
72294 + int ret = __do_munmap(mm, start, len);
72295 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72296 + return ret;
72297 +
72298 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72299 +}
72300 +
72301 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72302 +#else
72303 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72304 +#endif
72305 +{
72306 unsigned long end;
72307 struct vm_area_struct *vma, *prev, *last;
72308
72309 + /*
72310 + * mm->mmap_sem is required to protect against another thread
72311 + * changing the mappings in case we sleep.
72312 + */
72313 + verify_mm_writelocked(mm);
72314 +
72315 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72316 return -EINVAL;
72317
72318 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72319 /* Fix up all other VM information */
72320 remove_vma_list(mm, vma);
72321
72322 + track_exec_limit(mm, start, end, 0UL);
72323 +
72324 return 0;
72325 }
72326
72327 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72328
72329 profile_munmap(addr);
72330
72331 +#ifdef CONFIG_PAX_SEGMEXEC
72332 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72333 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72334 + return -EINVAL;
72335 +#endif
72336 +
72337 down_write(&mm->mmap_sem);
72338 ret = do_munmap(mm, addr, len);
72339 up_write(&mm->mmap_sem);
72340 return ret;
72341 }
72342
72343 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72344 -{
72345 -#ifdef CONFIG_DEBUG_VM
72346 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72347 - WARN_ON(1);
72348 - up_read(&mm->mmap_sem);
72349 - }
72350 -#endif
72351 -}
72352 -
72353 /*
72354 * this is really a simplified "do_mmap". it only handles
72355 * anonymous maps. eventually we may be able to do some
72356 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72357 struct rb_node ** rb_link, * rb_parent;
72358 pgoff_t pgoff = addr >> PAGE_SHIFT;
72359 int error;
72360 + unsigned long charged;
72361
72362 len = PAGE_ALIGN(len);
72363 if (!len)
72364 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72365
72366 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72367
72368 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72369 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72370 + flags &= ~VM_EXEC;
72371 +
72372 +#ifdef CONFIG_PAX_MPROTECT
72373 + if (mm->pax_flags & MF_PAX_MPROTECT)
72374 + flags &= ~VM_MAYEXEC;
72375 +#endif
72376 +
72377 + }
72378 +#endif
72379 +
72380 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72381 if (error & ~PAGE_MASK)
72382 return error;
72383
72384 + charged = len >> PAGE_SHIFT;
72385 +
72386 /*
72387 * mlock MCL_FUTURE?
72388 */
72389 if (mm->def_flags & VM_LOCKED) {
72390 unsigned long locked, lock_limit;
72391 - locked = len >> PAGE_SHIFT;
72392 + locked = charged;
72393 locked += mm->locked_vm;
72394 lock_limit = rlimit(RLIMIT_MEMLOCK);
72395 lock_limit >>= PAGE_SHIFT;
72396 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72397 /*
72398 * Clear old maps. this also does some error checking for us
72399 */
72400 - munmap_back:
72401 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72402 if (vma && vma->vm_start < addr + len) {
72403 if (do_munmap(mm, addr, len))
72404 return -ENOMEM;
72405 - goto munmap_back;
72406 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72407 + BUG_ON(vma && vma->vm_start < addr + len);
72408 }
72409
72410 /* Check against address space limits *after* clearing old maps... */
72411 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72412 + if (!may_expand_vm(mm, charged))
72413 return -ENOMEM;
72414
72415 if (mm->map_count > sysctl_max_map_count)
72416 return -ENOMEM;
72417
72418 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72419 + if (security_vm_enough_memory(charged))
72420 return -ENOMEM;
72421
72422 /* Can we just expand an old private anonymous mapping? */
72423 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72424 */
72425 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72426 if (!vma) {
72427 - vm_unacct_memory(len >> PAGE_SHIFT);
72428 + vm_unacct_memory(charged);
72429 return -ENOMEM;
72430 }
72431
72432 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72433 vma_link(mm, vma, prev, rb_link, rb_parent);
72434 out:
72435 perf_event_mmap(vma);
72436 - mm->total_vm += len >> PAGE_SHIFT;
72437 + mm->total_vm += charged;
72438 if (flags & VM_LOCKED) {
72439 if (!mlock_vma_pages_range(vma, addr, addr + len))
72440 - mm->locked_vm += (len >> PAGE_SHIFT);
72441 + mm->locked_vm += charged;
72442 }
72443 + track_exec_limit(mm, addr, addr + len, flags);
72444 return addr;
72445 }
72446
72447 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72448 * Walk the list again, actually closing and freeing it,
72449 * with preemption enabled, without holding any MM locks.
72450 */
72451 - while (vma)
72452 + while (vma) {
72453 + vma->vm_mirror = NULL;
72454 vma = remove_vma(vma);
72455 + }
72456
72457 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72458 }
72459 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72460 struct vm_area_struct * __vma, * prev;
72461 struct rb_node ** rb_link, * rb_parent;
72462
72463 +#ifdef CONFIG_PAX_SEGMEXEC
72464 + struct vm_area_struct *vma_m = NULL;
72465 +#endif
72466 +
72467 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72468 + return -EPERM;
72469 +
72470 /*
72471 * The vm_pgoff of a purely anonymous vma should be irrelevant
72472 * until its first write fault, when page's anon_vma and index
72473 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72474 if ((vma->vm_flags & VM_ACCOUNT) &&
72475 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72476 return -ENOMEM;
72477 +
72478 +#ifdef CONFIG_PAX_SEGMEXEC
72479 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72480 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72481 + if (!vma_m)
72482 + return -ENOMEM;
72483 + }
72484 +#endif
72485 +
72486 vma_link(mm, vma, prev, rb_link, rb_parent);
72487 +
72488 +#ifdef CONFIG_PAX_SEGMEXEC
72489 + if (vma_m)
72490 + BUG_ON(pax_mirror_vma(vma_m, vma));
72491 +#endif
72492 +
72493 return 0;
72494 }
72495
72496 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72497 struct mempolicy *pol;
72498 bool faulted_in_anon_vma = true;
72499
72500 + BUG_ON(vma->vm_mirror);
72501 +
72502 /*
72503 * If anonymous vma has not yet been faulted, update new pgoff
72504 * to match new location, to increase its chance of merging.
72505 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72506 return NULL;
72507 }
72508
72509 +#ifdef CONFIG_PAX_SEGMEXEC
72510 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72511 +{
72512 + struct vm_area_struct *prev_m;
72513 + struct rb_node **rb_link_m, *rb_parent_m;
72514 + struct mempolicy *pol_m;
72515 +
72516 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72517 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72518 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72519 + *vma_m = *vma;
72520 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72521 + if (anon_vma_clone(vma_m, vma))
72522 + return -ENOMEM;
72523 + pol_m = vma_policy(vma_m);
72524 + mpol_get(pol_m);
72525 + vma_set_policy(vma_m, pol_m);
72526 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72527 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72528 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72529 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72530 + if (vma_m->vm_file)
72531 + get_file(vma_m->vm_file);
72532 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72533 + vma_m->vm_ops->open(vma_m);
72534 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72535 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72536 + vma_m->vm_mirror = vma;
72537 + vma->vm_mirror = vma_m;
72538 + return 0;
72539 +}
72540 +#endif
72541 +
72542 /*
72543 * Return true if the calling process may expand its vm space by the passed
72544 * number of pages
72545 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72546
72547 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72548
72549 +#ifdef CONFIG_PAX_RANDMMAP
72550 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72551 + cur -= mm->brk_gap;
72552 +#endif
72553 +
72554 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72555 if (cur + npages > lim)
72556 return 0;
72557 return 1;
72558 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72559 vma->vm_start = addr;
72560 vma->vm_end = addr + len;
72561
72562 +#ifdef CONFIG_PAX_MPROTECT
72563 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72564 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72565 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72566 + return -EPERM;
72567 + if (!(vm_flags & VM_EXEC))
72568 + vm_flags &= ~VM_MAYEXEC;
72569 +#else
72570 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72571 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72572 +#endif
72573 + else
72574 + vm_flags &= ~VM_MAYWRITE;
72575 + }
72576 +#endif
72577 +
72578 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72579 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72580
72581 diff --git a/mm/mprotect.c b/mm/mprotect.c
72582 index f437d05..e3763f6 100644
72583 --- a/mm/mprotect.c
72584 +++ b/mm/mprotect.c
72585 @@ -23,10 +23,16 @@
72586 #include <linux/mmu_notifier.h>
72587 #include <linux/migrate.h>
72588 #include <linux/perf_event.h>
72589 +
72590 +#ifdef CONFIG_PAX_MPROTECT
72591 +#include <linux/elf.h>
72592 +#endif
72593 +
72594 #include <asm/uaccess.h>
72595 #include <asm/pgtable.h>
72596 #include <asm/cacheflush.h>
72597 #include <asm/tlbflush.h>
72598 +#include <asm/mmu_context.h>
72599
72600 #ifndef pgprot_modify
72601 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72602 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72603 flush_tlb_range(vma, start, end);
72604 }
72605
72606 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72607 +/* called while holding the mmap semaphor for writing except stack expansion */
72608 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72609 +{
72610 + unsigned long oldlimit, newlimit = 0UL;
72611 +
72612 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72613 + return;
72614 +
72615 + spin_lock(&mm->page_table_lock);
72616 + oldlimit = mm->context.user_cs_limit;
72617 + if ((prot & VM_EXEC) && oldlimit < end)
72618 + /* USER_CS limit moved up */
72619 + newlimit = end;
72620 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72621 + /* USER_CS limit moved down */
72622 + newlimit = start;
72623 +
72624 + if (newlimit) {
72625 + mm->context.user_cs_limit = newlimit;
72626 +
72627 +#ifdef CONFIG_SMP
72628 + wmb();
72629 + cpus_clear(mm->context.cpu_user_cs_mask);
72630 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72631 +#endif
72632 +
72633 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72634 + }
72635 + spin_unlock(&mm->page_table_lock);
72636 + if (newlimit == end) {
72637 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72638 +
72639 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72640 + if (is_vm_hugetlb_page(vma))
72641 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72642 + else
72643 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72644 + }
72645 +}
72646 +#endif
72647 +
72648 int
72649 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72650 unsigned long start, unsigned long end, unsigned long newflags)
72651 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72652 int error;
72653 int dirty_accountable = 0;
72654
72655 +#ifdef CONFIG_PAX_SEGMEXEC
72656 + struct vm_area_struct *vma_m = NULL;
72657 + unsigned long start_m, end_m;
72658 +
72659 + start_m = start + SEGMEXEC_TASK_SIZE;
72660 + end_m = end + SEGMEXEC_TASK_SIZE;
72661 +#endif
72662 +
72663 if (newflags == oldflags) {
72664 *pprev = vma;
72665 return 0;
72666 }
72667
72668 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72669 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72670 +
72671 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72672 + return -ENOMEM;
72673 +
72674 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72675 + return -ENOMEM;
72676 + }
72677 +
72678 /*
72679 * If we make a private mapping writable we increase our commit;
72680 * but (without finer accounting) cannot reduce our commit if we
72681 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72682 }
72683 }
72684
72685 +#ifdef CONFIG_PAX_SEGMEXEC
72686 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72687 + if (start != vma->vm_start) {
72688 + error = split_vma(mm, vma, start, 1);
72689 + if (error)
72690 + goto fail;
72691 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72692 + *pprev = (*pprev)->vm_next;
72693 + }
72694 +
72695 + if (end != vma->vm_end) {
72696 + error = split_vma(mm, vma, end, 0);
72697 + if (error)
72698 + goto fail;
72699 + }
72700 +
72701 + if (pax_find_mirror_vma(vma)) {
72702 + error = __do_munmap(mm, start_m, end_m - start_m);
72703 + if (error)
72704 + goto fail;
72705 + } else {
72706 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72707 + if (!vma_m) {
72708 + error = -ENOMEM;
72709 + goto fail;
72710 + }
72711 + vma->vm_flags = newflags;
72712 + error = pax_mirror_vma(vma_m, vma);
72713 + if (error) {
72714 + vma->vm_flags = oldflags;
72715 + goto fail;
72716 + }
72717 + }
72718 + }
72719 +#endif
72720 +
72721 /*
72722 * First try to merge with previous and/or next vma.
72723 */
72724 @@ -204,9 +306,21 @@ success:
72725 * vm_flags and vm_page_prot are protected by the mmap_sem
72726 * held in write mode.
72727 */
72728 +
72729 +#ifdef CONFIG_PAX_SEGMEXEC
72730 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72731 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72732 +#endif
72733 +
72734 vma->vm_flags = newflags;
72735 +
72736 +#ifdef CONFIG_PAX_MPROTECT
72737 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72738 + mm->binfmt->handle_mprotect(vma, newflags);
72739 +#endif
72740 +
72741 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72742 - vm_get_page_prot(newflags));
72743 + vm_get_page_prot(vma->vm_flags));
72744
72745 if (vma_wants_writenotify(vma)) {
72746 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72747 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72748 end = start + len;
72749 if (end <= start)
72750 return -ENOMEM;
72751 +
72752 +#ifdef CONFIG_PAX_SEGMEXEC
72753 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72754 + if (end > SEGMEXEC_TASK_SIZE)
72755 + return -EINVAL;
72756 + } else
72757 +#endif
72758 +
72759 + if (end > TASK_SIZE)
72760 + return -EINVAL;
72761 +
72762 if (!arch_validate_prot(prot))
72763 return -EINVAL;
72764
72765 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72766 /*
72767 * Does the application expect PROT_READ to imply PROT_EXEC:
72768 */
72769 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72770 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72771 prot |= PROT_EXEC;
72772
72773 vm_flags = calc_vm_prot_bits(prot);
72774 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72775 if (start > vma->vm_start)
72776 prev = vma;
72777
72778 +#ifdef CONFIG_PAX_MPROTECT
72779 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72780 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72781 +#endif
72782 +
72783 for (nstart = start ; ; ) {
72784 unsigned long newflags;
72785
72786 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72787
72788 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72789 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72790 + if (prot & (PROT_WRITE | PROT_EXEC))
72791 + gr_log_rwxmprotect(vma->vm_file);
72792 +
72793 + error = -EACCES;
72794 + goto out;
72795 + }
72796 +
72797 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72798 error = -EACCES;
72799 goto out;
72800 }
72801 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72802 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72803 if (error)
72804 goto out;
72805 +
72806 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72807 +
72808 nstart = tmp;
72809
72810 if (nstart < prev->vm_end)
72811 diff --git a/mm/mremap.c b/mm/mremap.c
72812 index 87bb839..c3bfadb 100644
72813 --- a/mm/mremap.c
72814 +++ b/mm/mremap.c
72815 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72816 continue;
72817 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72818 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72819 +
72820 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72821 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72822 + pte = pte_exprotect(pte);
72823 +#endif
72824 +
72825 set_pte_at(mm, new_addr, new_pte, pte);
72826 }
72827
72828 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72829 if (is_vm_hugetlb_page(vma))
72830 goto Einval;
72831
72832 +#ifdef CONFIG_PAX_SEGMEXEC
72833 + if (pax_find_mirror_vma(vma))
72834 + goto Einval;
72835 +#endif
72836 +
72837 /* We can't remap across vm area boundaries */
72838 if (old_len > vma->vm_end - addr)
72839 goto Efault;
72840 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72841 unsigned long ret = -EINVAL;
72842 unsigned long charged = 0;
72843 unsigned long map_flags;
72844 + unsigned long pax_task_size = TASK_SIZE;
72845
72846 if (new_addr & ~PAGE_MASK)
72847 goto out;
72848
72849 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72850 +#ifdef CONFIG_PAX_SEGMEXEC
72851 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72852 + pax_task_size = SEGMEXEC_TASK_SIZE;
72853 +#endif
72854 +
72855 + pax_task_size -= PAGE_SIZE;
72856 +
72857 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72858 goto out;
72859
72860 /* Check if the location we're moving into overlaps the
72861 * old location at all, and fail if it does.
72862 */
72863 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72864 - goto out;
72865 -
72866 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72867 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72868 goto out;
72869
72870 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72871 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72872 struct vm_area_struct *vma;
72873 unsigned long ret = -EINVAL;
72874 unsigned long charged = 0;
72875 + unsigned long pax_task_size = TASK_SIZE;
72876
72877 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72878 goto out;
72879 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72880 if (!new_len)
72881 goto out;
72882
72883 +#ifdef CONFIG_PAX_SEGMEXEC
72884 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72885 + pax_task_size = SEGMEXEC_TASK_SIZE;
72886 +#endif
72887 +
72888 + pax_task_size -= PAGE_SIZE;
72889 +
72890 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72891 + old_len > pax_task_size || addr > pax_task_size-old_len)
72892 + goto out;
72893 +
72894 if (flags & MREMAP_FIXED) {
72895 if (flags & MREMAP_MAYMOVE)
72896 ret = mremap_to(addr, old_len, new_addr, new_len);
72897 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72898 addr + new_len);
72899 }
72900 ret = addr;
72901 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72902 goto out;
72903 }
72904 }
72905 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72906 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72907 if (ret)
72908 goto out;
72909 +
72910 + map_flags = vma->vm_flags;
72911 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72912 + if (!(ret & ~PAGE_MASK)) {
72913 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72914 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72915 + }
72916 }
72917 out:
72918 if (ret & ~PAGE_MASK)
72919 diff --git a/mm/nommu.c b/mm/nommu.c
72920 index f59e170..34e2a2b 100644
72921 --- a/mm/nommu.c
72922 +++ b/mm/nommu.c
72923 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72924 int sysctl_overcommit_ratio = 50; /* default is 50% */
72925 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72926 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72927 -int heap_stack_gap = 0;
72928
72929 atomic_long_t mmap_pages_allocated;
72930
72931 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72932 EXPORT_SYMBOL(find_vma);
72933
72934 /*
72935 - * find a VMA
72936 - * - we don't extend stack VMAs under NOMMU conditions
72937 - */
72938 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72939 -{
72940 - return find_vma(mm, addr);
72941 -}
72942 -
72943 -/*
72944 * expand a stack to a given address
72945 * - not supported under NOMMU conditions
72946 */
72947 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72948
72949 /* most fields are the same, copy all, and then fixup */
72950 *new = *vma;
72951 + INIT_LIST_HEAD(&new->anon_vma_chain);
72952 *region = *vma->vm_region;
72953 new->vm_region = region;
72954
72955 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72956 index a13ded1..b949d15 100644
72957 --- a/mm/page_alloc.c
72958 +++ b/mm/page_alloc.c
72959 @@ -335,7 +335,7 @@ out:
72960 * This usage means that zero-order pages may not be compound.
72961 */
72962
72963 -static void free_compound_page(struct page *page)
72964 +void free_compound_page(struct page *page)
72965 {
72966 __free_pages_ok(page, compound_order(page));
72967 }
72968 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72969 int i;
72970 int bad = 0;
72971
72972 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72973 + unsigned long index = 1UL << order;
72974 +#endif
72975 +
72976 trace_mm_page_free(page, order);
72977 kmemcheck_free_shadow(page, order);
72978
72979 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72980 debug_check_no_obj_freed(page_address(page),
72981 PAGE_SIZE << order);
72982 }
72983 +
72984 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72985 + for (; index; --index)
72986 + sanitize_highpage(page + index - 1);
72987 +#endif
72988 +
72989 arch_free_page(page, order);
72990 kernel_map_pages(page, 1 << order, 0);
72991
72992 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72993 arch_alloc_page(page, order);
72994 kernel_map_pages(page, 1 << order, 1);
72995
72996 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
72997 if (gfp_flags & __GFP_ZERO)
72998 prep_zero_page(page, order, gfp_flags);
72999 +#endif
73000
73001 if (order && (gfp_flags & __GFP_COMP))
73002 prep_compound_page(page, order);
73003 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73004 unsigned long pfn;
73005
73006 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73007 +#ifdef CONFIG_X86_32
73008 + /* boot failures in VMware 8 on 32bit vanilla since
73009 + this change */
73010 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73011 +#else
73012 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73013 +#endif
73014 return 1;
73015 }
73016 return 0;
73017 diff --git a/mm/percpu.c b/mm/percpu.c
73018 index f47af91..7eeef99 100644
73019 --- a/mm/percpu.c
73020 +++ b/mm/percpu.c
73021 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73022 static unsigned int pcpu_high_unit_cpu __read_mostly;
73023
73024 /* the address of the first chunk which starts with the kernel static area */
73025 -void *pcpu_base_addr __read_mostly;
73026 +void *pcpu_base_addr __read_only;
73027 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73028
73029 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73030 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73031 index c20ff48..137702a 100644
73032 --- a/mm/process_vm_access.c
73033 +++ b/mm/process_vm_access.c
73034 @@ -13,6 +13,7 @@
73035 #include <linux/uio.h>
73036 #include <linux/sched.h>
73037 #include <linux/highmem.h>
73038 +#include <linux/security.h>
73039 #include <linux/ptrace.h>
73040 #include <linux/slab.h>
73041 #include <linux/syscalls.h>
73042 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73043 size_t iov_l_curr_offset = 0;
73044 ssize_t iov_len;
73045
73046 + return -ENOSYS; // PaX: until properly audited
73047 +
73048 /*
73049 * Work out how many pages of struct pages we're going to need
73050 * when eventually calling get_user_pages
73051 */
73052 for (i = 0; i < riovcnt; i++) {
73053 iov_len = rvec[i].iov_len;
73054 - if (iov_len > 0) {
73055 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73056 - + iov_len)
73057 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73058 - / PAGE_SIZE + 1;
73059 - nr_pages = max(nr_pages, nr_pages_iov);
73060 - }
73061 + if (iov_len <= 0)
73062 + continue;
73063 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73064 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73065 + nr_pages = max(nr_pages, nr_pages_iov);
73066 }
73067
73068 if (nr_pages == 0)
73069 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73070 goto free_proc_pages;
73071 }
73072
73073 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73074 + rc = -EPERM;
73075 + goto put_task_struct;
73076 + }
73077 +
73078 mm = mm_access(task, PTRACE_MODE_ATTACH);
73079 if (!mm || IS_ERR(mm)) {
73080 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73081 diff --git a/mm/rmap.c b/mm/rmap.c
73082 index c8454e0..b04f3a2 100644
73083 --- a/mm/rmap.c
73084 +++ b/mm/rmap.c
73085 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73086 struct anon_vma *anon_vma = vma->anon_vma;
73087 struct anon_vma_chain *avc;
73088
73089 +#ifdef CONFIG_PAX_SEGMEXEC
73090 + struct anon_vma_chain *avc_m = NULL;
73091 +#endif
73092 +
73093 might_sleep();
73094 if (unlikely(!anon_vma)) {
73095 struct mm_struct *mm = vma->vm_mm;
73096 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73097 if (!avc)
73098 goto out_enomem;
73099
73100 +#ifdef CONFIG_PAX_SEGMEXEC
73101 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73102 + if (!avc_m)
73103 + goto out_enomem_free_avc;
73104 +#endif
73105 +
73106 anon_vma = find_mergeable_anon_vma(vma);
73107 allocated = NULL;
73108 if (!anon_vma) {
73109 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73110 /* page_table_lock to protect against threads */
73111 spin_lock(&mm->page_table_lock);
73112 if (likely(!vma->anon_vma)) {
73113 +
73114 +#ifdef CONFIG_PAX_SEGMEXEC
73115 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73116 +
73117 + if (vma_m) {
73118 + BUG_ON(vma_m->anon_vma);
73119 + vma_m->anon_vma = anon_vma;
73120 + avc_m->anon_vma = anon_vma;
73121 + avc_m->vma = vma;
73122 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73123 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73124 + avc_m = NULL;
73125 + }
73126 +#endif
73127 +
73128 vma->anon_vma = anon_vma;
73129 avc->anon_vma = anon_vma;
73130 avc->vma = vma;
73131 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73132
73133 if (unlikely(allocated))
73134 put_anon_vma(allocated);
73135 +
73136 +#ifdef CONFIG_PAX_SEGMEXEC
73137 + if (unlikely(avc_m))
73138 + anon_vma_chain_free(avc_m);
73139 +#endif
73140 +
73141 if (unlikely(avc))
73142 anon_vma_chain_free(avc);
73143 }
73144 return 0;
73145
73146 out_enomem_free_avc:
73147 +
73148 +#ifdef CONFIG_PAX_SEGMEXEC
73149 + if (avc_m)
73150 + anon_vma_chain_free(avc_m);
73151 +#endif
73152 +
73153 anon_vma_chain_free(avc);
73154 out_enomem:
73155 return -ENOMEM;
73156 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73157 * Attach the anon_vmas from src to dst.
73158 * Returns 0 on success, -ENOMEM on failure.
73159 */
73160 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73161 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73162 {
73163 struct anon_vma_chain *avc, *pavc;
73164 struct anon_vma *root = NULL;
73165 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73166 * the corresponding VMA in the parent process is attached to.
73167 * Returns 0 on success, non-zero on failure.
73168 */
73169 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73170 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73171 {
73172 struct anon_vma_chain *avc;
73173 struct anon_vma *anon_vma;
73174 diff --git a/mm/shmem.c b/mm/shmem.c
73175 index 269d049..a9d2b50 100644
73176 --- a/mm/shmem.c
73177 +++ b/mm/shmem.c
73178 @@ -31,7 +31,7 @@
73179 #include <linux/export.h>
73180 #include <linux/swap.h>
73181
73182 -static struct vfsmount *shm_mnt;
73183 +struct vfsmount *shm_mnt;
73184
73185 #ifdef CONFIG_SHMEM
73186 /*
73187 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73188 #define BOGO_DIRENT_SIZE 20
73189
73190 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73191 -#define SHORT_SYMLINK_LEN 128
73192 +#define SHORT_SYMLINK_LEN 64
73193
73194 struct shmem_xattr {
73195 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73196 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73197 int err = -ENOMEM;
73198
73199 /* Round up to L1_CACHE_BYTES to resist false sharing */
73200 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73201 - L1_CACHE_BYTES), GFP_KERNEL);
73202 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73203 if (!sbinfo)
73204 return -ENOMEM;
73205
73206 diff --git a/mm/slab.c b/mm/slab.c
73207 index f0bd785..348b96a 100644
73208 --- a/mm/slab.c
73209 +++ b/mm/slab.c
73210 @@ -153,7 +153,7 @@
73211
73212 /* Legal flag mask for kmem_cache_create(). */
73213 #if DEBUG
73214 -# define CREATE_MASK (SLAB_RED_ZONE | \
73215 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73216 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73217 SLAB_CACHE_DMA | \
73218 SLAB_STORE_USER | \
73219 @@ -161,7 +161,7 @@
73220 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73221 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73222 #else
73223 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73224 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73225 SLAB_CACHE_DMA | \
73226 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73227 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73228 @@ -290,7 +290,7 @@ struct kmem_list3 {
73229 * Need this for bootstrapping a per node allocator.
73230 */
73231 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73232 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73233 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73234 #define CACHE_CACHE 0
73235 #define SIZE_AC MAX_NUMNODES
73236 #define SIZE_L3 (2 * MAX_NUMNODES)
73237 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73238 if ((x)->max_freeable < i) \
73239 (x)->max_freeable = i; \
73240 } while (0)
73241 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73242 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73243 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73244 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73245 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73246 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73247 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73248 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73249 #else
73250 #define STATS_INC_ACTIVE(x) do { } while (0)
73251 #define STATS_DEC_ACTIVE(x) do { } while (0)
73252 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73253 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73254 */
73255 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73256 - const struct slab *slab, void *obj)
73257 + const struct slab *slab, const void *obj)
73258 {
73259 u32 offset = (obj - slab->s_mem);
73260 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73261 @@ -568,7 +568,7 @@ struct cache_names {
73262 static struct cache_names __initdata cache_names[] = {
73263 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73264 #include <linux/kmalloc_sizes.h>
73265 - {NULL,}
73266 + {NULL}
73267 #undef CACHE
73268 };
73269
73270 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73271 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73272 sizes[INDEX_AC].cs_size,
73273 ARCH_KMALLOC_MINALIGN,
73274 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73275 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73276 NULL);
73277
73278 if (INDEX_AC != INDEX_L3) {
73279 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73280 kmem_cache_create(names[INDEX_L3].name,
73281 sizes[INDEX_L3].cs_size,
73282 ARCH_KMALLOC_MINALIGN,
73283 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73284 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73285 NULL);
73286 }
73287
73288 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73289 sizes->cs_cachep = kmem_cache_create(names->name,
73290 sizes->cs_size,
73291 ARCH_KMALLOC_MINALIGN,
73292 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73293 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73294 NULL);
73295 }
73296 #ifdef CONFIG_ZONE_DMA
73297 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73298 }
73299 /* cpu stats */
73300 {
73301 - unsigned long allochit = atomic_read(&cachep->allochit);
73302 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73303 - unsigned long freehit = atomic_read(&cachep->freehit);
73304 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73305 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73306 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73307 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73308 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73309
73310 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73311 allochit, allocmiss, freehit, freemiss);
73312 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73313 {
73314 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73315 #ifdef CONFIG_DEBUG_SLAB_LEAK
73316 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73317 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73318 #endif
73319 return 0;
73320 }
73321 module_init(slab_proc_init);
73322 #endif
73323
73324 +void check_object_size(const void *ptr, unsigned long n, bool to)
73325 +{
73326 +
73327 +#ifdef CONFIG_PAX_USERCOPY
73328 + struct page *page;
73329 + struct kmem_cache *cachep = NULL;
73330 + struct slab *slabp;
73331 + unsigned int objnr;
73332 + unsigned long offset;
73333 + const char *type;
73334 +
73335 + if (!n)
73336 + return;
73337 +
73338 + type = "<null>";
73339 + if (ZERO_OR_NULL_PTR(ptr))
73340 + goto report;
73341 +
73342 + if (!virt_addr_valid(ptr))
73343 + return;
73344 +
73345 + page = virt_to_head_page(ptr);
73346 +
73347 + type = "<process stack>";
73348 + if (!PageSlab(page)) {
73349 + if (object_is_on_stack(ptr, n) == -1)
73350 + goto report;
73351 + return;
73352 + }
73353 +
73354 + cachep = page_get_cache(page);
73355 + type = cachep->name;
73356 + if (!(cachep->flags & SLAB_USERCOPY))
73357 + goto report;
73358 +
73359 + slabp = page_get_slab(page);
73360 + objnr = obj_to_index(cachep, slabp, ptr);
73361 + BUG_ON(objnr >= cachep->num);
73362 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73363 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73364 + return;
73365 +
73366 +report:
73367 + pax_report_usercopy(ptr, n, to, type);
73368 +#endif
73369 +
73370 +}
73371 +EXPORT_SYMBOL(check_object_size);
73372 +
73373 /**
73374 * ksize - get the actual amount of memory allocated for a given object
73375 * @objp: Pointer to the object
73376 diff --git a/mm/slob.c b/mm/slob.c
73377 index 8105be4..e045f96 100644
73378 --- a/mm/slob.c
73379 +++ b/mm/slob.c
73380 @@ -29,7 +29,7 @@
73381 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73382 * alloc_pages() directly, allocating compound pages so the page order
73383 * does not have to be separately tracked, and also stores the exact
73384 - * allocation size in page->private so that it can be used to accurately
73385 + * allocation size in slob_page->size so that it can be used to accurately
73386 * provide ksize(). These objects are detected in kfree() because slob_page()
73387 * is false for them.
73388 *
73389 @@ -58,6 +58,7 @@
73390 */
73391
73392 #include <linux/kernel.h>
73393 +#include <linux/sched.h>
73394 #include <linux/slab.h>
73395 #include <linux/mm.h>
73396 #include <linux/swap.h> /* struct reclaim_state */
73397 @@ -102,7 +103,8 @@ struct slob_page {
73398 unsigned long flags; /* mandatory */
73399 atomic_t _count; /* mandatory */
73400 slobidx_t units; /* free units left in page */
73401 - unsigned long pad[2];
73402 + unsigned long pad[1];
73403 + unsigned long size; /* size when >=PAGE_SIZE */
73404 slob_t *free; /* first free slob_t in page */
73405 struct list_head list; /* linked list of free pages */
73406 };
73407 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73408 */
73409 static inline int is_slob_page(struct slob_page *sp)
73410 {
73411 - return PageSlab((struct page *)sp);
73412 + return PageSlab((struct page *)sp) && !sp->size;
73413 }
73414
73415 static inline void set_slob_page(struct slob_page *sp)
73416 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73417
73418 static inline struct slob_page *slob_page(const void *addr)
73419 {
73420 - return (struct slob_page *)virt_to_page(addr);
73421 + return (struct slob_page *)virt_to_head_page(addr);
73422 }
73423
73424 /*
73425 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73426 /*
73427 * Return the size of a slob block.
73428 */
73429 -static slobidx_t slob_units(slob_t *s)
73430 +static slobidx_t slob_units(const slob_t *s)
73431 {
73432 if (s->units > 0)
73433 return s->units;
73434 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73435 /*
73436 * Return the next free slob block pointer after this one.
73437 */
73438 -static slob_t *slob_next(slob_t *s)
73439 +static slob_t *slob_next(const slob_t *s)
73440 {
73441 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73442 slobidx_t next;
73443 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73444 /*
73445 * Returns true if s is the last free block in its page.
73446 */
73447 -static int slob_last(slob_t *s)
73448 +static int slob_last(const slob_t *s)
73449 {
73450 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73451 }
73452 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73453 if (!page)
73454 return NULL;
73455
73456 + set_slob_page(page);
73457 return page_address(page);
73458 }
73459
73460 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73461 if (!b)
73462 return NULL;
73463 sp = slob_page(b);
73464 - set_slob_page(sp);
73465
73466 spin_lock_irqsave(&slob_lock, flags);
73467 sp->units = SLOB_UNITS(PAGE_SIZE);
73468 sp->free = b;
73469 + sp->size = 0;
73470 INIT_LIST_HEAD(&sp->list);
73471 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73472 set_slob_page_free(sp, slob_list);
73473 @@ -476,10 +479,9 @@ out:
73474 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73475 */
73476
73477 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73478 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73479 {
73480 - unsigned int *m;
73481 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73482 + slob_t *m;
73483 void *ret;
73484
73485 gfp &= gfp_allowed_mask;
73486 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73487
73488 if (!m)
73489 return NULL;
73490 - *m = size;
73491 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73492 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73493 + m[0].units = size;
73494 + m[1].units = align;
73495 ret = (void *)m + align;
73496
73497 trace_kmalloc_node(_RET_IP_, ret,
73498 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73499 gfp |= __GFP_COMP;
73500 ret = slob_new_pages(gfp, order, node);
73501 if (ret) {
73502 - struct page *page;
73503 - page = virt_to_page(ret);
73504 - page->private = size;
73505 + struct slob_page *sp;
73506 + sp = slob_page(ret);
73507 + sp->size = size;
73508 }
73509
73510 trace_kmalloc_node(_RET_IP_, ret,
73511 size, PAGE_SIZE << order, gfp, node);
73512 }
73513
73514 - kmemleak_alloc(ret, size, 1, gfp);
73515 + return ret;
73516 +}
73517 +
73518 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73519 +{
73520 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73521 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73522 +
73523 + if (!ZERO_OR_NULL_PTR(ret))
73524 + kmemleak_alloc(ret, size, 1, gfp);
73525 return ret;
73526 }
73527 EXPORT_SYMBOL(__kmalloc_node);
73528 @@ -533,13 +547,92 @@ void kfree(const void *block)
73529 sp = slob_page(block);
73530 if (is_slob_page(sp)) {
73531 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73532 - unsigned int *m = (unsigned int *)(block - align);
73533 - slob_free(m, *m + align);
73534 - } else
73535 + slob_t *m = (slob_t *)(block - align);
73536 + slob_free(m, m[0].units + align);
73537 + } else {
73538 + clear_slob_page(sp);
73539 + free_slob_page(sp);
73540 + sp->size = 0;
73541 put_page(&sp->page);
73542 + }
73543 }
73544 EXPORT_SYMBOL(kfree);
73545
73546 +void check_object_size(const void *ptr, unsigned long n, bool to)
73547 +{
73548 +
73549 +#ifdef CONFIG_PAX_USERCOPY
73550 + struct slob_page *sp;
73551 + const slob_t *free;
73552 + const void *base;
73553 + unsigned long flags;
73554 + const char *type;
73555 +
73556 + if (!n)
73557 + return;
73558 +
73559 + type = "<null>";
73560 + if (ZERO_OR_NULL_PTR(ptr))
73561 + goto report;
73562 +
73563 + if (!virt_addr_valid(ptr))
73564 + return;
73565 +
73566 + type = "<process stack>";
73567 + sp = slob_page(ptr);
73568 + if (!PageSlab((struct page *)sp)) {
73569 + if (object_is_on_stack(ptr, n) == -1)
73570 + goto report;
73571 + return;
73572 + }
73573 +
73574 + type = "<slob>";
73575 + if (sp->size) {
73576 + base = page_address(&sp->page);
73577 + if (base <= ptr && n <= sp->size - (ptr - base))
73578 + return;
73579 + goto report;
73580 + }
73581 +
73582 + /* some tricky double walking to find the chunk */
73583 + spin_lock_irqsave(&slob_lock, flags);
73584 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73585 + free = sp->free;
73586 +
73587 + while (!slob_last(free) && (void *)free <= ptr) {
73588 + base = free + slob_units(free);
73589 + free = slob_next(free);
73590 + }
73591 +
73592 + while (base < (void *)free) {
73593 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73594 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73595 + int offset;
73596 +
73597 + if (ptr < base + align)
73598 + break;
73599 +
73600 + offset = ptr - base - align;
73601 + if (offset >= m) {
73602 + base += size;
73603 + continue;
73604 + }
73605 +
73606 + if (n > m - offset)
73607 + break;
73608 +
73609 + spin_unlock_irqrestore(&slob_lock, flags);
73610 + return;
73611 + }
73612 +
73613 + spin_unlock_irqrestore(&slob_lock, flags);
73614 +report:
73615 + pax_report_usercopy(ptr, n, to, type);
73616 +#endif
73617 +
73618 +}
73619 +EXPORT_SYMBOL(check_object_size);
73620 +
73621 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73622 size_t ksize(const void *block)
73623 {
73624 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73625 sp = slob_page(block);
73626 if (is_slob_page(sp)) {
73627 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73628 - unsigned int *m = (unsigned int *)(block - align);
73629 - return SLOB_UNITS(*m) * SLOB_UNIT;
73630 + slob_t *m = (slob_t *)(block - align);
73631 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73632 } else
73633 - return sp->page.private;
73634 + return sp->size;
73635 }
73636 EXPORT_SYMBOL(ksize);
73637
73638 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73639 {
73640 struct kmem_cache *c;
73641
73642 +#ifdef CONFIG_PAX_USERCOPY
73643 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73644 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73645 +#else
73646 c = slob_alloc(sizeof(struct kmem_cache),
73647 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73648 +#endif
73649
73650 if (c) {
73651 c->name = name;
73652 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73653
73654 lockdep_trace_alloc(flags);
73655
73656 +#ifdef CONFIG_PAX_USERCOPY
73657 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73658 +#else
73659 if (c->size < PAGE_SIZE) {
73660 b = slob_alloc(c->size, flags, c->align, node);
73661 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73662 SLOB_UNITS(c->size) * SLOB_UNIT,
73663 flags, node);
73664 } else {
73665 + struct slob_page *sp;
73666 +
73667 b = slob_new_pages(flags, get_order(c->size), node);
73668 + sp = slob_page(b);
73669 + sp->size = c->size;
73670 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73671 PAGE_SIZE << get_order(c->size),
73672 flags, node);
73673 }
73674 +#endif
73675
73676 if (c->ctor)
73677 c->ctor(b);
73678 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73679
73680 static void __kmem_cache_free(void *b, int size)
73681 {
73682 - if (size < PAGE_SIZE)
73683 + struct slob_page *sp = slob_page(b);
73684 +
73685 + if (is_slob_page(sp))
73686 slob_free(b, size);
73687 - else
73688 + else {
73689 + clear_slob_page(sp);
73690 + free_slob_page(sp);
73691 + sp->size = 0;
73692 slob_free_pages(b, get_order(size));
73693 + }
73694 }
73695
73696 static void kmem_rcu_free(struct rcu_head *head)
73697 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73698
73699 void kmem_cache_free(struct kmem_cache *c, void *b)
73700 {
73701 + int size = c->size;
73702 +
73703 +#ifdef CONFIG_PAX_USERCOPY
73704 + if (size + c->align < PAGE_SIZE) {
73705 + size += c->align;
73706 + b -= c->align;
73707 + }
73708 +#endif
73709 +
73710 kmemleak_free_recursive(b, c->flags);
73711 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73712 struct slob_rcu *slob_rcu;
73713 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73714 - slob_rcu->size = c->size;
73715 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73716 + slob_rcu->size = size;
73717 call_rcu(&slob_rcu->head, kmem_rcu_free);
73718 } else {
73719 - __kmem_cache_free(b, c->size);
73720 + __kmem_cache_free(b, size);
73721 }
73722
73723 +#ifdef CONFIG_PAX_USERCOPY
73724 + trace_kfree(_RET_IP_, b);
73725 +#else
73726 trace_kmem_cache_free(_RET_IP_, b);
73727 +#endif
73728 +
73729 }
73730 EXPORT_SYMBOL(kmem_cache_free);
73731
73732 diff --git a/mm/slub.c b/mm/slub.c
73733 index 0342a5d..8180ae9 100644
73734 --- a/mm/slub.c
73735 +++ b/mm/slub.c
73736 @@ -208,7 +208,7 @@ struct track {
73737
73738 enum track_item { TRACK_ALLOC, TRACK_FREE };
73739
73740 -#ifdef CONFIG_SYSFS
73741 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73742 static int sysfs_slab_add(struct kmem_cache *);
73743 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73744 static void sysfs_slab_remove(struct kmem_cache *);
73745 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73746 if (!t->addr)
73747 return;
73748
73749 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73750 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73751 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73752 #ifdef CONFIG_STACKTRACE
73753 {
73754 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73755
73756 page = virt_to_head_page(x);
73757
73758 + BUG_ON(!PageSlab(page));
73759 +
73760 slab_free(s, page, x, _RET_IP_);
73761
73762 trace_kmem_cache_free(_RET_IP_, x);
73763 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
73764 * Merge control. If this is set then no merging of slab caches will occur.
73765 * (Could be removed. This was introduced to pacify the merge skeptics.)
73766 */
73767 -static int slub_nomerge;
73768 +static int slub_nomerge = 1;
73769
73770 /*
73771 * Calculate the order of allocation given an slab object size.
73772 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73773 else
73774 s->cpu_partial = 30;
73775
73776 - s->refcount = 1;
73777 + atomic_set(&s->refcount, 1);
73778 #ifdef CONFIG_NUMA
73779 s->remote_node_defrag_ratio = 1000;
73780 #endif
73781 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73782 void kmem_cache_destroy(struct kmem_cache *s)
73783 {
73784 down_write(&slub_lock);
73785 - s->refcount--;
73786 - if (!s->refcount) {
73787 + if (atomic_dec_and_test(&s->refcount)) {
73788 list_del(&s->list);
73789 up_write(&slub_lock);
73790 if (kmem_cache_close(s)) {
73791 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73792 EXPORT_SYMBOL(__kmalloc_node);
73793 #endif
73794
73795 +void check_object_size(const void *ptr, unsigned long n, bool to)
73796 +{
73797 +
73798 +#ifdef CONFIG_PAX_USERCOPY
73799 + struct page *page;
73800 + struct kmem_cache *s = NULL;
73801 + unsigned long offset;
73802 + const char *type;
73803 +
73804 + if (!n)
73805 + return;
73806 +
73807 + type = "<null>";
73808 + if (ZERO_OR_NULL_PTR(ptr))
73809 + goto report;
73810 +
73811 + if (!virt_addr_valid(ptr))
73812 + return;
73813 +
73814 + page = virt_to_head_page(ptr);
73815 +
73816 + type = "<process stack>";
73817 + if (!PageSlab(page)) {
73818 + if (object_is_on_stack(ptr, n) == -1)
73819 + goto report;
73820 + return;
73821 + }
73822 +
73823 + s = page->slab;
73824 + type = s->name;
73825 + if (!(s->flags & SLAB_USERCOPY))
73826 + goto report;
73827 +
73828 + offset = (ptr - page_address(page)) % s->size;
73829 + if (offset <= s->objsize && n <= s->objsize - offset)
73830 + return;
73831 +
73832 +report:
73833 + pax_report_usercopy(ptr, n, to, type);
73834 +#endif
73835 +
73836 +}
73837 +EXPORT_SYMBOL(check_object_size);
73838 +
73839 size_t ksize(const void *object)
73840 {
73841 struct page *page;
73842 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73843 int node;
73844
73845 list_add(&s->list, &slab_caches);
73846 - s->refcount = -1;
73847 + atomic_set(&s->refcount, -1);
73848
73849 for_each_node_state(node, N_NORMAL_MEMORY) {
73850 struct kmem_cache_node *n = get_node(s, node);
73851 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73852
73853 /* Caches that are not of the two-to-the-power-of size */
73854 if (KMALLOC_MIN_SIZE <= 32) {
73855 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73856 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73857 caches++;
73858 }
73859
73860 if (KMALLOC_MIN_SIZE <= 64) {
73861 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73862 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73863 caches++;
73864 }
73865
73866 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73867 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73868 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73869 caches++;
73870 }
73871
73872 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73873 /*
73874 * We may have set a slab to be unmergeable during bootstrap.
73875 */
73876 - if (s->refcount < 0)
73877 + if (atomic_read(&s->refcount) < 0)
73878 return 1;
73879
73880 return 0;
73881 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73882 down_write(&slub_lock);
73883 s = find_mergeable(size, align, flags, name, ctor);
73884 if (s) {
73885 - s->refcount++;
73886 + atomic_inc(&s->refcount);
73887 /*
73888 * Adjust the object sizes so that we clear
73889 * the complete object on kzalloc.
73890 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73891 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73892
73893 if (sysfs_slab_alias(s, name)) {
73894 - s->refcount--;
73895 + atomic_dec(&s->refcount);
73896 goto err;
73897 }
73898 up_write(&slub_lock);
73899 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73900 }
73901 #endif
73902
73903 -#ifdef CONFIG_SYSFS
73904 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73905 static int count_inuse(struct page *page)
73906 {
73907 return page->inuse;
73908 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
73909 validate_slab_cache(kmalloc_caches[9]);
73910 }
73911 #else
73912 -#ifdef CONFIG_SYSFS
73913 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73914 static void resiliency_test(void) {};
73915 #endif
73916 #endif
73917
73918 -#ifdef CONFIG_SYSFS
73919 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73920 enum slab_stat_type {
73921 SL_ALL, /* All slabs */
73922 SL_PARTIAL, /* Only partially allocated slabs */
73923 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
73924
73925 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73926 {
73927 - return sprintf(buf, "%d\n", s->refcount - 1);
73928 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73929 }
73930 SLAB_ATTR_RO(aliases);
73931
73932 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
73933 return name;
73934 }
73935
73936 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73937 static int sysfs_slab_add(struct kmem_cache *s)
73938 {
73939 int err;
73940 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73941 kobject_del(&s->kobj);
73942 kobject_put(&s->kobj);
73943 }
73944 +#endif
73945
73946 /*
73947 * Need to buffer aliases during bootup until sysfs becomes
73948 @@ -5319,6 +5366,7 @@ struct saved_alias {
73949
73950 static struct saved_alias *alias_list;
73951
73952 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73953 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73954 {
73955 struct saved_alias *al;
73956 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73957 alias_list = al;
73958 return 0;
73959 }
73960 +#endif
73961
73962 static int __init slab_sysfs_init(void)
73963 {
73964 diff --git a/mm/swap.c b/mm/swap.c
73965 index 14380e9..e244704 100644
73966 --- a/mm/swap.c
73967 +++ b/mm/swap.c
73968 @@ -30,6 +30,7 @@
73969 #include <linux/backing-dev.h>
73970 #include <linux/memcontrol.h>
73971 #include <linux/gfp.h>
73972 +#include <linux/hugetlb.h>
73973
73974 #include "internal.h"
73975
73976 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73977
73978 __page_cache_release(page);
73979 dtor = get_compound_page_dtor(page);
73980 + if (!PageHuge(page))
73981 + BUG_ON(dtor != free_compound_page);
73982 (*dtor)(page);
73983 }
73984
73985 diff --git a/mm/swapfile.c b/mm/swapfile.c
73986 index f31b29d..8bdcae2 100644
73987 --- a/mm/swapfile.c
73988 +++ b/mm/swapfile.c
73989 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73990
73991 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73992 /* Activity counter to indicate that a swapon or swapoff has occurred */
73993 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
73994 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73995
73996 static inline unsigned char swap_count(unsigned char ent)
73997 {
73998 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73999 }
74000 filp_close(swap_file, NULL);
74001 err = 0;
74002 - atomic_inc(&proc_poll_event);
74003 + atomic_inc_unchecked(&proc_poll_event);
74004 wake_up_interruptible(&proc_poll_wait);
74005
74006 out_dput:
74007 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74008
74009 poll_wait(file, &proc_poll_wait, wait);
74010
74011 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74012 - seq->poll_event = atomic_read(&proc_poll_event);
74013 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74014 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74015 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74016 }
74017
74018 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74019 return ret;
74020
74021 seq = file->private_data;
74022 - seq->poll_event = atomic_read(&proc_poll_event);
74023 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74024 return 0;
74025 }
74026
74027 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74028 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74029
74030 mutex_unlock(&swapon_mutex);
74031 - atomic_inc(&proc_poll_event);
74032 + atomic_inc_unchecked(&proc_poll_event);
74033 wake_up_interruptible(&proc_poll_wait);
74034
74035 if (S_ISREG(inode->i_mode))
74036 diff --git a/mm/util.c b/mm/util.c
74037 index 136ac4f..f917fa9 100644
74038 --- a/mm/util.c
74039 +++ b/mm/util.c
74040 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74041 void arch_pick_mmap_layout(struct mm_struct *mm)
74042 {
74043 mm->mmap_base = TASK_UNMAPPED_BASE;
74044 +
74045 +#ifdef CONFIG_PAX_RANDMMAP
74046 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74047 + mm->mmap_base += mm->delta_mmap;
74048 +#endif
74049 +
74050 mm->get_unmapped_area = arch_get_unmapped_area;
74051 mm->unmap_area = arch_unmap_area;
74052 }
74053 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74054 index 86ce9a5..bc498f3 100644
74055 --- a/mm/vmalloc.c
74056 +++ b/mm/vmalloc.c
74057 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74058
74059 pte = pte_offset_kernel(pmd, addr);
74060 do {
74061 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74062 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74063 +
74064 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74065 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74066 + BUG_ON(!pte_exec(*pte));
74067 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74068 + continue;
74069 + }
74070 +#endif
74071 +
74072 + {
74073 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74074 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74075 + }
74076 } while (pte++, addr += PAGE_SIZE, addr != end);
74077 }
74078
74079 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74080 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74081 {
74082 pte_t *pte;
74083 + int ret = -ENOMEM;
74084
74085 /*
74086 * nr is a running index into the array which helps higher level
74087 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74088 pte = pte_alloc_kernel(pmd, addr);
74089 if (!pte)
74090 return -ENOMEM;
74091 +
74092 + pax_open_kernel();
74093 do {
74094 struct page *page = pages[*nr];
74095
74096 - if (WARN_ON(!pte_none(*pte)))
74097 - return -EBUSY;
74098 - if (WARN_ON(!page))
74099 - return -ENOMEM;
74100 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74101 + if (pgprot_val(prot) & _PAGE_NX)
74102 +#endif
74103 +
74104 + if (WARN_ON(!pte_none(*pte))) {
74105 + ret = -EBUSY;
74106 + goto out;
74107 + }
74108 + if (WARN_ON(!page)) {
74109 + ret = -ENOMEM;
74110 + goto out;
74111 + }
74112 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74113 (*nr)++;
74114 } while (pte++, addr += PAGE_SIZE, addr != end);
74115 - return 0;
74116 + ret = 0;
74117 +out:
74118 + pax_close_kernel();
74119 + return ret;
74120 }
74121
74122 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74123 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74124 * and fall back on vmalloc() if that fails. Others
74125 * just put it in the vmalloc space.
74126 */
74127 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74128 +#ifdef CONFIG_MODULES
74129 +#ifdef MODULES_VADDR
74130 unsigned long addr = (unsigned long)x;
74131 if (addr >= MODULES_VADDR && addr < MODULES_END)
74132 return 1;
74133 #endif
74134 +
74135 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74136 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74137 + return 1;
74138 +#endif
74139 +
74140 +#endif
74141 +
74142 return is_vmalloc_addr(x);
74143 }
74144
74145 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74146
74147 if (!pgd_none(*pgd)) {
74148 pud_t *pud = pud_offset(pgd, addr);
74149 +#ifdef CONFIG_X86
74150 + if (!pud_large(*pud))
74151 +#endif
74152 if (!pud_none(*pud)) {
74153 pmd_t *pmd = pmd_offset(pud, addr);
74154 +#ifdef CONFIG_X86
74155 + if (!pmd_large(*pmd))
74156 +#endif
74157 if (!pmd_none(*pmd)) {
74158 pte_t *ptep, pte;
74159
74160 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74161 struct vm_struct *area;
74162
74163 BUG_ON(in_interrupt());
74164 +
74165 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74166 + if (flags & VM_KERNEXEC) {
74167 + if (start != VMALLOC_START || end != VMALLOC_END)
74168 + return NULL;
74169 + start = (unsigned long)MODULES_EXEC_VADDR;
74170 + end = (unsigned long)MODULES_EXEC_END;
74171 + }
74172 +#endif
74173 +
74174 if (flags & VM_IOREMAP) {
74175 int bit = fls(size);
74176
74177 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
74178 if (count > totalram_pages)
74179 return NULL;
74180
74181 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74182 + if (!(pgprot_val(prot) & _PAGE_NX))
74183 + flags |= VM_KERNEXEC;
74184 +#endif
74185 +
74186 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74187 __builtin_return_address(0));
74188 if (!area)
74189 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74190 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74191 goto fail;
74192
74193 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74194 + if (!(pgprot_val(prot) & _PAGE_NX))
74195 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74196 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74197 + else
74198 +#endif
74199 +
74200 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74201 start, end, node, gfp_mask, caller);
74202 if (!area)
74203 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
74204 * For tight control over page level allocator and protection flags
74205 * use __vmalloc() instead.
74206 */
74207 -
74208 void *vmalloc_exec(unsigned long size)
74209 {
74210 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74211 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74212 -1, __builtin_return_address(0));
74213 }
74214
74215 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74216 unsigned long uaddr = vma->vm_start;
74217 unsigned long usize = vma->vm_end - vma->vm_start;
74218
74219 + BUG_ON(vma->vm_mirror);
74220 +
74221 if ((PAGE_SIZE-1) & (unsigned long)addr)
74222 return -EINVAL;
74223
74224 diff --git a/mm/vmstat.c b/mm/vmstat.c
74225 index f600557..1459fc8 100644
74226 --- a/mm/vmstat.c
74227 +++ b/mm/vmstat.c
74228 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74229 *
74230 * vm_stat contains the global counters
74231 */
74232 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74233 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74234 EXPORT_SYMBOL(vm_stat);
74235
74236 #ifdef CONFIG_SMP
74237 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74238 v = p->vm_stat_diff[i];
74239 p->vm_stat_diff[i] = 0;
74240 local_irq_restore(flags);
74241 - atomic_long_add(v, &zone->vm_stat[i]);
74242 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74243 global_diff[i] += v;
74244 #ifdef CONFIG_NUMA
74245 /* 3 seconds idle till flush */
74246 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74247
74248 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74249 if (global_diff[i])
74250 - atomic_long_add(global_diff[i], &vm_stat[i]);
74251 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74252 }
74253
74254 #endif
74255 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74256 start_cpu_timer(cpu);
74257 #endif
74258 #ifdef CONFIG_PROC_FS
74259 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74260 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74261 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74262 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74263 + {
74264 + mode_t gr_mode = S_IRUGO;
74265 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74266 + gr_mode = S_IRUSR;
74267 +#endif
74268 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74269 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74270 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74271 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74272 +#else
74273 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74274 +#endif
74275 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74276 + }
74277 #endif
74278 return 0;
74279 }
74280 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74281 index efea35b..9c8dd0b 100644
74282 --- a/net/8021q/vlan.c
74283 +++ b/net/8021q/vlan.c
74284 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74285 err = -EPERM;
74286 if (!capable(CAP_NET_ADMIN))
74287 break;
74288 - if ((args.u.name_type >= 0) &&
74289 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74290 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74291 struct vlan_net *vn;
74292
74293 vn = net_generic(net, vlan_net_id);
74294 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74295 index fccae26..e7ece2f 100644
74296 --- a/net/9p/trans_fd.c
74297 +++ b/net/9p/trans_fd.c
74298 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74299 oldfs = get_fs();
74300 set_fs(get_ds());
74301 /* The cast to a user pointer is valid due to the set_fs() */
74302 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74303 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74304 set_fs(oldfs);
74305
74306 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74307 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74308 index 876fbe8..8bbea9f 100644
74309 --- a/net/atm/atm_misc.c
74310 +++ b/net/atm/atm_misc.c
74311 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74312 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74313 return 1;
74314 atm_return(vcc, truesize);
74315 - atomic_inc(&vcc->stats->rx_drop);
74316 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74317 return 0;
74318 }
74319 EXPORT_SYMBOL(atm_charge);
74320 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74321 }
74322 }
74323 atm_return(vcc, guess);
74324 - atomic_inc(&vcc->stats->rx_drop);
74325 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74326 return NULL;
74327 }
74328 EXPORT_SYMBOL(atm_alloc_charge);
74329 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74330
74331 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74332 {
74333 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74334 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74335 __SONET_ITEMS
74336 #undef __HANDLE_ITEM
74337 }
74338 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74339
74340 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74341 {
74342 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74343 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74344 __SONET_ITEMS
74345 #undef __HANDLE_ITEM
74346 }
74347 diff --git a/net/atm/lec.h b/net/atm/lec.h
74348 index dfc0719..47c5322 100644
74349 --- a/net/atm/lec.h
74350 +++ b/net/atm/lec.h
74351 @@ -48,7 +48,7 @@ struct lane2_ops {
74352 const u8 *tlvs, u32 sizeoftlvs);
74353 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74354 const u8 *tlvs, u32 sizeoftlvs);
74355 -};
74356 +} __no_const;
74357
74358 /*
74359 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74360 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74361 index 0919a88..a23d54e 100644
74362 --- a/net/atm/mpc.h
74363 +++ b/net/atm/mpc.h
74364 @@ -33,7 +33,7 @@ struct mpoa_client {
74365 struct mpc_parameters parameters; /* parameters for this client */
74366
74367 const struct net_device_ops *old_ops;
74368 - struct net_device_ops new_ops;
74369 + net_device_ops_no_const new_ops;
74370 };
74371
74372
74373 diff --git a/net/atm/proc.c b/net/atm/proc.c
74374 index 0d020de..011c7bb 100644
74375 --- a/net/atm/proc.c
74376 +++ b/net/atm/proc.c
74377 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74378 const struct k_atm_aal_stats *stats)
74379 {
74380 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74381 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74382 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74383 - atomic_read(&stats->rx_drop));
74384 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74385 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74386 + atomic_read_unchecked(&stats->rx_drop));
74387 }
74388
74389 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74390 diff --git a/net/atm/resources.c b/net/atm/resources.c
74391 index 23f45ce..c748f1a 100644
74392 --- a/net/atm/resources.c
74393 +++ b/net/atm/resources.c
74394 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74395 static void copy_aal_stats(struct k_atm_aal_stats *from,
74396 struct atm_aal_stats *to)
74397 {
74398 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74399 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74400 __AAL_STAT_ITEMS
74401 #undef __HANDLE_ITEM
74402 }
74403 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74404 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74405 struct atm_aal_stats *to)
74406 {
74407 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74408 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74409 __AAL_STAT_ITEMS
74410 #undef __HANDLE_ITEM
74411 }
74412 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74413 index 3512e25..2b33401 100644
74414 --- a/net/batman-adv/bat_iv_ogm.c
74415 +++ b/net/batman-adv/bat_iv_ogm.c
74416 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74417
74418 /* change sequence number to network order */
74419 batman_ogm_packet->seqno =
74420 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74421 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74422
74423 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74424 batman_ogm_packet->tt_crc = htons((uint16_t)
74425 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74426 else
74427 batman_ogm_packet->gw_flags = NO_FLAGS;
74428
74429 - atomic_inc(&hard_iface->seqno);
74430 + atomic_inc_unchecked(&hard_iface->seqno);
74431
74432 slide_own_bcast_window(hard_iface);
74433 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74434 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74435 return;
74436
74437 /* could be changed by schedule_own_packet() */
74438 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74439 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74440
74441 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74442
74443 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74444 index 7704df4..beb4e16 100644
74445 --- a/net/batman-adv/hard-interface.c
74446 +++ b/net/batman-adv/hard-interface.c
74447 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74448 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74449 dev_add_pack(&hard_iface->batman_adv_ptype);
74450
74451 - atomic_set(&hard_iface->seqno, 1);
74452 - atomic_set(&hard_iface->frag_seqno, 1);
74453 + atomic_set_unchecked(&hard_iface->seqno, 1);
74454 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74455 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74456 hard_iface->net_dev->name);
74457
74458 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74459 index 987c75a..20d6f36 100644
74460 --- a/net/batman-adv/soft-interface.c
74461 +++ b/net/batman-adv/soft-interface.c
74462 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74463
74464 /* set broadcast sequence number */
74465 bcast_packet->seqno =
74466 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74467 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74468
74469 add_bcast_packet_to_list(bat_priv, skb, 1);
74470
74471 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74472 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74473
74474 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74475 - atomic_set(&bat_priv->bcast_seqno, 1);
74476 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74477 atomic_set(&bat_priv->ttvn, 0);
74478 atomic_set(&bat_priv->tt_local_changes, 0);
74479 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74480 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74481 index e9eb043..d174eeb 100644
74482 --- a/net/batman-adv/types.h
74483 +++ b/net/batman-adv/types.h
74484 @@ -38,8 +38,8 @@ struct hard_iface {
74485 int16_t if_num;
74486 char if_status;
74487 struct net_device *net_dev;
74488 - atomic_t seqno;
74489 - atomic_t frag_seqno;
74490 + atomic_unchecked_t seqno;
74491 + atomic_unchecked_t frag_seqno;
74492 unsigned char *packet_buff;
74493 int packet_len;
74494 struct kobject *hardif_obj;
74495 @@ -154,7 +154,7 @@ struct bat_priv {
74496 atomic_t orig_interval; /* uint */
74497 atomic_t hop_penalty; /* uint */
74498 atomic_t log_level; /* uint */
74499 - atomic_t bcast_seqno;
74500 + atomic_unchecked_t bcast_seqno;
74501 atomic_t bcast_queue_left;
74502 atomic_t batman_queue_left;
74503 atomic_t ttvn; /* translation table version number */
74504 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74505 index 07d1c1d..7e9bea9 100644
74506 --- a/net/batman-adv/unicast.c
74507 +++ b/net/batman-adv/unicast.c
74508 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74509 frag1->flags = UNI_FRAG_HEAD | large_tail;
74510 frag2->flags = large_tail;
74511
74512 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74513 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74514 frag1->seqno = htons(seqno - 1);
74515 frag2->seqno = htons(seqno);
74516
74517 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74518 index 07bc69e..21e76b1 100644
74519 --- a/net/bluetooth/hci_conn.c
74520 +++ b/net/bluetooth/hci_conn.c
74521 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74522 memset(&cp, 0, sizeof(cp));
74523
74524 cp.handle = cpu_to_le16(conn->handle);
74525 - memcpy(cp.ltk, ltk, sizeof(ltk));
74526 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74527
74528 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74529 }
74530 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74531 index 32d338c..d24bcdb 100644
74532 --- a/net/bluetooth/l2cap_core.c
74533 +++ b/net/bluetooth/l2cap_core.c
74534 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74535 break;
74536
74537 case L2CAP_CONF_RFC:
74538 - if (olen == sizeof(rfc))
74539 - memcpy(&rfc, (void *)val, olen);
74540 + if (olen != sizeof(rfc))
74541 + break;
74542 +
74543 + memcpy(&rfc, (void *)val, olen);
74544
74545 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74546 rfc.mode != chan->mode)
74547 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74548
74549 switch (type) {
74550 case L2CAP_CONF_RFC:
74551 - if (olen == sizeof(rfc))
74552 - memcpy(&rfc, (void *)val, olen);
74553 + if (olen != sizeof(rfc))
74554 + break;
74555 +
74556 + memcpy(&rfc, (void *)val, olen);
74557 goto done;
74558 }
74559 }
74560 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
74561 index 5449294..7da9a5f 100644
74562 --- a/net/bridge/netfilter/ebt_ulog.c
74563 +++ b/net/bridge/netfilter/ebt_ulog.c
74564 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
74565 spin_unlock_bh(&ulog_buffers[data].lock);
74566 }
74567
74568 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
74569 static struct sk_buff *ulog_alloc_skb(unsigned int size)
74570 {
74571 struct sk_buff *skb;
74572 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74573 index 5fe2ff3..10968b5 100644
74574 --- a/net/bridge/netfilter/ebtables.c
74575 +++ b/net/bridge/netfilter/ebtables.c
74576 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74577 tmp.valid_hooks = t->table->valid_hooks;
74578 }
74579 mutex_unlock(&ebt_mutex);
74580 - if (copy_to_user(user, &tmp, *len) != 0){
74581 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74582 BUGPRINT("c2u Didn't work\n");
74583 ret = -EFAULT;
74584 break;
74585 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74586 index a97d97a..6f679ed 100644
74587 --- a/net/caif/caif_socket.c
74588 +++ b/net/caif/caif_socket.c
74589 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74590 #ifdef CONFIG_DEBUG_FS
74591 struct debug_fs_counter {
74592 atomic_t caif_nr_socks;
74593 - atomic_t caif_sock_create;
74594 - atomic_t num_connect_req;
74595 - atomic_t num_connect_resp;
74596 - atomic_t num_connect_fail_resp;
74597 - atomic_t num_disconnect;
74598 - atomic_t num_remote_shutdown_ind;
74599 - atomic_t num_tx_flow_off_ind;
74600 - atomic_t num_tx_flow_on_ind;
74601 - atomic_t num_rx_flow_off;
74602 - atomic_t num_rx_flow_on;
74603 + atomic_unchecked_t caif_sock_create;
74604 + atomic_unchecked_t num_connect_req;
74605 + atomic_unchecked_t num_connect_resp;
74606 + atomic_unchecked_t num_connect_fail_resp;
74607 + atomic_unchecked_t num_disconnect;
74608 + atomic_unchecked_t num_remote_shutdown_ind;
74609 + atomic_unchecked_t num_tx_flow_off_ind;
74610 + atomic_unchecked_t num_tx_flow_on_ind;
74611 + atomic_unchecked_t num_rx_flow_off;
74612 + atomic_unchecked_t num_rx_flow_on;
74613 };
74614 static struct debug_fs_counter cnt;
74615 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74616 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74617 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74618 #else
74619 #define dbfs_atomic_inc(v) 0
74620 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74621 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74622 sk_rcvbuf_lowwater(cf_sk));
74623 set_rx_flow_off(cf_sk);
74624 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74625 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74626 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74627 }
74628
74629 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74630 set_rx_flow_off(cf_sk);
74631 if (net_ratelimit())
74632 pr_debug("sending flow OFF due to rmem_schedule\n");
74633 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74634 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74635 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74636 }
74637 skb->dev = NULL;
74638 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74639 switch (flow) {
74640 case CAIF_CTRLCMD_FLOW_ON_IND:
74641 /* OK from modem to start sending again */
74642 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74643 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74644 set_tx_flow_on(cf_sk);
74645 cf_sk->sk.sk_state_change(&cf_sk->sk);
74646 break;
74647
74648 case CAIF_CTRLCMD_FLOW_OFF_IND:
74649 /* Modem asks us to shut up */
74650 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74651 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74652 set_tx_flow_off(cf_sk);
74653 cf_sk->sk.sk_state_change(&cf_sk->sk);
74654 break;
74655 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74656 /* We're now connected */
74657 caif_client_register_refcnt(&cf_sk->layer,
74658 cfsk_hold, cfsk_put);
74659 - dbfs_atomic_inc(&cnt.num_connect_resp);
74660 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74661 cf_sk->sk.sk_state = CAIF_CONNECTED;
74662 set_tx_flow_on(cf_sk);
74663 cf_sk->sk.sk_state_change(&cf_sk->sk);
74664 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74665
74666 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74667 /* Connect request failed */
74668 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74669 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74670 cf_sk->sk.sk_err = ECONNREFUSED;
74671 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74672 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74673 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74674
74675 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74676 /* Modem has closed this connection, or device is down. */
74677 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74678 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74679 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74680 cf_sk->sk.sk_err = ECONNRESET;
74681 set_rx_flow_on(cf_sk);
74682 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74683 return;
74684
74685 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74686 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74687 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74688 set_rx_flow_on(cf_sk);
74689 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74690 }
74691 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74692 /*ifindex = id of the interface.*/
74693 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74694
74695 - dbfs_atomic_inc(&cnt.num_connect_req);
74696 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74697 cf_sk->layer.receive = caif_sktrecv_cb;
74698
74699 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74700 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74701 spin_unlock_bh(&sk->sk_receive_queue.lock);
74702 sock->sk = NULL;
74703
74704 - dbfs_atomic_inc(&cnt.num_disconnect);
74705 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74706
74707 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74708 if (cf_sk->debugfs_socket_dir != NULL)
74709 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74710 cf_sk->conn_req.protocol = protocol;
74711 /* Increase the number of sockets created. */
74712 dbfs_atomic_inc(&cnt.caif_nr_socks);
74713 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74714 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74715 #ifdef CONFIG_DEBUG_FS
74716 if (!IS_ERR(debugfsdir)) {
74717
74718 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74719 index 5cf5222..6f704ad 100644
74720 --- a/net/caif/cfctrl.c
74721 +++ b/net/caif/cfctrl.c
74722 @@ -9,6 +9,7 @@
74723 #include <linux/stddef.h>
74724 #include <linux/spinlock.h>
74725 #include <linux/slab.h>
74726 +#include <linux/sched.h>
74727 #include <net/caif/caif_layer.h>
74728 #include <net/caif/cfpkt.h>
74729 #include <net/caif/cfctrl.h>
74730 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74731 memset(&dev_info, 0, sizeof(dev_info));
74732 dev_info.id = 0xff;
74733 cfsrvl_init(&this->serv, 0, &dev_info, false);
74734 - atomic_set(&this->req_seq_no, 1);
74735 - atomic_set(&this->rsp_seq_no, 1);
74736 + atomic_set_unchecked(&this->req_seq_no, 1);
74737 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74738 this->serv.layer.receive = cfctrl_recv;
74739 sprintf(this->serv.layer.name, "ctrl");
74740 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74741 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74742 struct cfctrl_request_info *req)
74743 {
74744 spin_lock_bh(&ctrl->info_list_lock);
74745 - atomic_inc(&ctrl->req_seq_no);
74746 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74747 + atomic_inc_unchecked(&ctrl->req_seq_no);
74748 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74749 list_add_tail(&req->list, &ctrl->list);
74750 spin_unlock_bh(&ctrl->info_list_lock);
74751 }
74752 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74753 if (p != first)
74754 pr_warn("Requests are not received in order\n");
74755
74756 - atomic_set(&ctrl->rsp_seq_no,
74757 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74758 p->sequence_no);
74759 list_del(&p->list);
74760 goto out;
74761 diff --git a/net/can/gw.c b/net/can/gw.c
74762 index 3d79b12..8de85fa 100644
74763 --- a/net/can/gw.c
74764 +++ b/net/can/gw.c
74765 @@ -96,7 +96,7 @@ struct cf_mod {
74766 struct {
74767 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74768 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74769 - } csumfunc;
74770 + } __no_const csumfunc;
74771 };
74772
74773
74774 diff --git a/net/compat.c b/net/compat.c
74775 index 6def90e..c6992fa 100644
74776 --- a/net/compat.c
74777 +++ b/net/compat.c
74778 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74779 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74780 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74781 return -EFAULT;
74782 - kmsg->msg_name = compat_ptr(tmp1);
74783 - kmsg->msg_iov = compat_ptr(tmp2);
74784 - kmsg->msg_control = compat_ptr(tmp3);
74785 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74786 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74787 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74788 return 0;
74789 }
74790
74791 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74792
74793 if (kern_msg->msg_namelen) {
74794 if (mode == VERIFY_READ) {
74795 - int err = move_addr_to_kernel(kern_msg->msg_name,
74796 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74797 kern_msg->msg_namelen,
74798 kern_address);
74799 if (err < 0)
74800 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74801 kern_msg->msg_name = NULL;
74802
74803 tot_len = iov_from_user_compat_to_kern(kern_iov,
74804 - (struct compat_iovec __user *)kern_msg->msg_iov,
74805 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74806 kern_msg->msg_iovlen);
74807 if (tot_len >= 0)
74808 kern_msg->msg_iov = kern_iov;
74809 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74810
74811 #define CMSG_COMPAT_FIRSTHDR(msg) \
74812 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74813 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74814 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74815 (struct compat_cmsghdr __user *)NULL)
74816
74817 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74818 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74819 (ucmlen) <= (unsigned long) \
74820 ((mhdr)->msg_controllen - \
74821 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74822 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74823
74824 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74825 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74826 {
74827 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74828 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74829 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74830 msg->msg_controllen)
74831 return NULL;
74832 return (struct compat_cmsghdr __user *)ptr;
74833 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74834 {
74835 struct compat_timeval ctv;
74836 struct compat_timespec cts[3];
74837 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74838 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74839 struct compat_cmsghdr cmhdr;
74840 int cmlen;
74841
74842 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74843
74844 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74845 {
74846 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74847 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74848 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74849 int fdnum = scm->fp->count;
74850 struct file **fp = scm->fp->fp;
74851 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74852 return -EFAULT;
74853 old_fs = get_fs();
74854 set_fs(KERNEL_DS);
74855 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74856 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74857 set_fs(old_fs);
74858
74859 return err;
74860 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74861 len = sizeof(ktime);
74862 old_fs = get_fs();
74863 set_fs(KERNEL_DS);
74864 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74865 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74866 set_fs(old_fs);
74867
74868 if (!err) {
74869 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74870 case MCAST_JOIN_GROUP:
74871 case MCAST_LEAVE_GROUP:
74872 {
74873 - struct compat_group_req __user *gr32 = (void *)optval;
74874 + struct compat_group_req __user *gr32 = (void __user *)optval;
74875 struct group_req __user *kgr =
74876 compat_alloc_user_space(sizeof(struct group_req));
74877 u32 interface;
74878 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74879 case MCAST_BLOCK_SOURCE:
74880 case MCAST_UNBLOCK_SOURCE:
74881 {
74882 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74883 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74884 struct group_source_req __user *kgsr = compat_alloc_user_space(
74885 sizeof(struct group_source_req));
74886 u32 interface;
74887 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74888 }
74889 case MCAST_MSFILTER:
74890 {
74891 - struct compat_group_filter __user *gf32 = (void *)optval;
74892 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74893 struct group_filter __user *kgf;
74894 u32 interface, fmode, numsrc;
74895
74896 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74897 char __user *optval, int __user *optlen,
74898 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74899 {
74900 - struct compat_group_filter __user *gf32 = (void *)optval;
74901 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74902 struct group_filter __user *kgf;
74903 int __user *koptlen;
74904 u32 interface, fmode, numsrc;
74905 diff --git a/net/core/datagram.c b/net/core/datagram.c
74906 index 68bbf9f..5ef0d12 100644
74907 --- a/net/core/datagram.c
74908 +++ b/net/core/datagram.c
74909 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74910 }
74911
74912 kfree_skb(skb);
74913 - atomic_inc(&sk->sk_drops);
74914 + atomic_inc_unchecked(&sk->sk_drops);
74915 sk_mem_reclaim_partial(sk);
74916
74917 return err;
74918 diff --git a/net/core/dev.c b/net/core/dev.c
74919 index a4bf943..9c83051 100644
74920 --- a/net/core/dev.c
74921 +++ b/net/core/dev.c
74922 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
74923 if (no_module && capable(CAP_NET_ADMIN))
74924 no_module = request_module("netdev-%s", name);
74925 if (no_module && capable(CAP_SYS_MODULE)) {
74926 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74927 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74928 +#else
74929 if (!request_module("%s", name))
74930 pr_err("Loading kernel module for a network device "
74931 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
74932 "instead\n", name);
74933 +#endif
74934 }
74935 }
74936 EXPORT_SYMBOL(dev_load);
74937 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74938 {
74939 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74940 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74941 - atomic_long_inc(&dev->rx_dropped);
74942 + atomic_long_inc_unchecked(&dev->rx_dropped);
74943 kfree_skb(skb);
74944 return NET_RX_DROP;
74945 }
74946 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74947 nf_reset(skb);
74948
74949 if (unlikely(!is_skb_forwardable(dev, skb))) {
74950 - atomic_long_inc(&dev->rx_dropped);
74951 + atomic_long_inc_unchecked(&dev->rx_dropped);
74952 kfree_skb(skb);
74953 return NET_RX_DROP;
74954 }
74955 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74956
74957 struct dev_gso_cb {
74958 void (*destructor)(struct sk_buff *skb);
74959 -};
74960 +} __no_const;
74961
74962 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74963
74964 @@ -2913,7 +2917,7 @@ enqueue:
74965
74966 local_irq_restore(flags);
74967
74968 - atomic_long_inc(&skb->dev->rx_dropped);
74969 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74970 kfree_skb(skb);
74971 return NET_RX_DROP;
74972 }
74973 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
74974 }
74975 EXPORT_SYMBOL(netif_rx_ni);
74976
74977 -static void net_tx_action(struct softirq_action *h)
74978 +static void net_tx_action(void)
74979 {
74980 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74981
74982 @@ -3273,7 +3277,7 @@ ncls:
74983 if (pt_prev) {
74984 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74985 } else {
74986 - atomic_long_inc(&skb->dev->rx_dropped);
74987 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74988 kfree_skb(skb);
74989 /* Jamal, now you will not able to escape explaining
74990 * me how you were going to use this. :-)
74991 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
74992 }
74993 EXPORT_SYMBOL(netif_napi_del);
74994
74995 -static void net_rx_action(struct softirq_action *h)
74996 +static void net_rx_action(void)
74997 {
74998 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74999 unsigned long time_limit = jiffies + 2;
75000 @@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75001 } else {
75002 netdev_stats_to_stats64(storage, &dev->stats);
75003 }
75004 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75005 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75006 return storage;
75007 }
75008 EXPORT_SYMBOL(dev_get_stats);
75009 diff --git a/net/core/flow.c b/net/core/flow.c
75010 index e318c7e..168b1d0 100644
75011 --- a/net/core/flow.c
75012 +++ b/net/core/flow.c
75013 @@ -61,7 +61,7 @@ struct flow_cache {
75014 struct timer_list rnd_timer;
75015 };
75016
75017 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75018 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75019 EXPORT_SYMBOL(flow_cache_genid);
75020 static struct flow_cache flow_cache_global;
75021 static struct kmem_cache *flow_cachep __read_mostly;
75022 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75023
75024 static int flow_entry_valid(struct flow_cache_entry *fle)
75025 {
75026 - if (atomic_read(&flow_cache_genid) != fle->genid)
75027 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75028 return 0;
75029 if (fle->object && !fle->object->ops->check(fle->object))
75030 return 0;
75031 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75032 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75033 fcp->hash_count++;
75034 }
75035 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75036 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75037 flo = fle->object;
75038 if (!flo)
75039 goto ret_object;
75040 @@ -280,7 +280,7 @@ nocache:
75041 }
75042 flo = resolver(net, key, family, dir, flo, ctx);
75043 if (fle) {
75044 - fle->genid = atomic_read(&flow_cache_genid);
75045 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75046 if (!IS_ERR(flo))
75047 fle->object = flo;
75048 else
75049 diff --git a/net/core/iovec.c b/net/core/iovec.c
75050 index c40f27e..7f49254 100644
75051 --- a/net/core/iovec.c
75052 +++ b/net/core/iovec.c
75053 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75054 if (m->msg_namelen) {
75055 if (mode == VERIFY_READ) {
75056 void __user *namep;
75057 - namep = (void __user __force *) m->msg_name;
75058 + namep = (void __force_user *) m->msg_name;
75059 err = move_addr_to_kernel(namep, m->msg_namelen,
75060 address);
75061 if (err < 0)
75062 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75063 }
75064
75065 size = m->msg_iovlen * sizeof(struct iovec);
75066 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75067 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75068 return -EFAULT;
75069
75070 m->msg_iov = iov;
75071 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75072 index 5c30296..ebe7b61 100644
75073 --- a/net/core/rtnetlink.c
75074 +++ b/net/core/rtnetlink.c
75075 @@ -57,7 +57,7 @@ struct rtnl_link {
75076 rtnl_doit_func doit;
75077 rtnl_dumpit_func dumpit;
75078 rtnl_calcit_func calcit;
75079 -};
75080 +} __no_const;
75081
75082 static DEFINE_MUTEX(rtnl_mutex);
75083
75084 diff --git a/net/core/scm.c b/net/core/scm.c
75085 index ff52ad0..aff1c0f 100644
75086 --- a/net/core/scm.c
75087 +++ b/net/core/scm.c
75088 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75089 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75090 {
75091 struct cmsghdr __user *cm
75092 - = (__force struct cmsghdr __user *)msg->msg_control;
75093 + = (struct cmsghdr __force_user *)msg->msg_control;
75094 struct cmsghdr cmhdr;
75095 int cmlen = CMSG_LEN(len);
75096 int err;
75097 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75098 err = -EFAULT;
75099 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75100 goto out;
75101 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75102 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75103 goto out;
75104 cmlen = CMSG_SPACE(len);
75105 if (msg->msg_controllen < cmlen)
75106 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75107 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75108 {
75109 struct cmsghdr __user *cm
75110 - = (__force struct cmsghdr __user*)msg->msg_control;
75111 + = (struct cmsghdr __force_user *)msg->msg_control;
75112
75113 int fdmax = 0;
75114 int fdnum = scm->fp->count;
75115 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75116 if (fdnum < fdmax)
75117 fdmax = fdnum;
75118
75119 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75120 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75121 i++, cmfptr++)
75122 {
75123 int new_fd;
75124 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75125 index da0c97f..8253632 100644
75126 --- a/net/core/skbuff.c
75127 +++ b/net/core/skbuff.c
75128 @@ -3160,6 +3160,8 @@ static void sock_rmem_free(struct sk_buff *skb)
75129 */
75130 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75131 {
75132 + int len = skb->len;
75133 +
75134 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75135 (unsigned)sk->sk_rcvbuf)
75136 return -ENOMEM;
75137 @@ -3174,7 +3176,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75138
75139 skb_queue_tail(&sk->sk_error_queue, skb);
75140 if (!sock_flag(sk, SOCK_DEAD))
75141 - sk->sk_data_ready(sk, skb->len);
75142 + sk->sk_data_ready(sk, len);
75143 return 0;
75144 }
75145 EXPORT_SYMBOL(sock_queue_err_skb);
75146 diff --git a/net/core/sock.c b/net/core/sock.c
75147 index 02f8dfe..86dfd4a 100644
75148 --- a/net/core/sock.c
75149 +++ b/net/core/sock.c
75150 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75151 struct sk_buff_head *list = &sk->sk_receive_queue;
75152
75153 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75154 - atomic_inc(&sk->sk_drops);
75155 + atomic_inc_unchecked(&sk->sk_drops);
75156 trace_sock_rcvqueue_full(sk, skb);
75157 return -ENOMEM;
75158 }
75159 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75160 return err;
75161
75162 if (!sk_rmem_schedule(sk, skb->truesize)) {
75163 - atomic_inc(&sk->sk_drops);
75164 + atomic_inc_unchecked(&sk->sk_drops);
75165 return -ENOBUFS;
75166 }
75167
75168 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75169 skb_dst_force(skb);
75170
75171 spin_lock_irqsave(&list->lock, flags);
75172 - skb->dropcount = atomic_read(&sk->sk_drops);
75173 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75174 __skb_queue_tail(list, skb);
75175 spin_unlock_irqrestore(&list->lock, flags);
75176
75177 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75178 skb->dev = NULL;
75179
75180 if (sk_rcvqueues_full(sk, skb)) {
75181 - atomic_inc(&sk->sk_drops);
75182 + atomic_inc_unchecked(&sk->sk_drops);
75183 goto discard_and_relse;
75184 }
75185 if (nested)
75186 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75187 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75188 } else if (sk_add_backlog(sk, skb)) {
75189 bh_unlock_sock(sk);
75190 - atomic_inc(&sk->sk_drops);
75191 + atomic_inc_unchecked(&sk->sk_drops);
75192 goto discard_and_relse;
75193 }
75194
75195 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75196 if (len > sizeof(peercred))
75197 len = sizeof(peercred);
75198 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75199 - if (copy_to_user(optval, &peercred, len))
75200 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75201 return -EFAULT;
75202 goto lenout;
75203 }
75204 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75205 return -ENOTCONN;
75206 if (lv < len)
75207 return -EINVAL;
75208 - if (copy_to_user(optval, address, len))
75209 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75210 return -EFAULT;
75211 goto lenout;
75212 }
75213 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75214
75215 if (len > lv)
75216 len = lv;
75217 - if (copy_to_user(optval, &v, len))
75218 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75219 return -EFAULT;
75220 lenout:
75221 if (put_user(len, optlen))
75222 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75223 */
75224 smp_wmb();
75225 atomic_set(&sk->sk_refcnt, 1);
75226 - atomic_set(&sk->sk_drops, 0);
75227 + atomic_set_unchecked(&sk->sk_drops, 0);
75228 }
75229 EXPORT_SYMBOL(sock_init_data);
75230
75231 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75232 index b9868e1..849f809 100644
75233 --- a/net/core/sock_diag.c
75234 +++ b/net/core/sock_diag.c
75235 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75236
75237 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75238 {
75239 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75240 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75241 cookie[1] != INET_DIAG_NOCOOKIE) &&
75242 ((u32)(unsigned long)sk != cookie[0] ||
75243 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75244 return -ESTALE;
75245 else
75246 +#endif
75247 return 0;
75248 }
75249 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75250
75251 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75252 {
75253 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75254 + cookie[0] = 0;
75255 + cookie[1] = 0;
75256 +#else
75257 cookie[0] = (u32)(unsigned long)sk;
75258 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75259 +#endif
75260 }
75261 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75262
75263 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75264 index 02e75d1..9a57a7c 100644
75265 --- a/net/decnet/sysctl_net_decnet.c
75266 +++ b/net/decnet/sysctl_net_decnet.c
75267 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75268
75269 if (len > *lenp) len = *lenp;
75270
75271 - if (copy_to_user(buffer, addr, len))
75272 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75273 return -EFAULT;
75274
75275 *lenp = len;
75276 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75277
75278 if (len > *lenp) len = *lenp;
75279
75280 - if (copy_to_user(buffer, devname, len))
75281 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75282 return -EFAULT;
75283
75284 *lenp = len;
75285 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75286 index 39a2d29..f39c0fe 100644
75287 --- a/net/econet/Kconfig
75288 +++ b/net/econet/Kconfig
75289 @@ -4,7 +4,7 @@
75290
75291 config ECONET
75292 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75293 - depends on EXPERIMENTAL && INET
75294 + depends on EXPERIMENTAL && INET && BROKEN
75295 ---help---
75296 Econet is a fairly old and slow networking protocol mainly used by
75297 Acorn computers to access file and print servers. It uses native
75298 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75299 index 36d1440..44ff28b 100644
75300 --- a/net/ipv4/ah4.c
75301 +++ b/net/ipv4/ah4.c
75302 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75303 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75304
75305 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75306 + unsigned int size) __size_overflow(3);
75307 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75308 unsigned int size)
75309 {
75310 unsigned int len;
75311 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75312 index 92fc5f6..b790d91 100644
75313 --- a/net/ipv4/fib_frontend.c
75314 +++ b/net/ipv4/fib_frontend.c
75315 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75316 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75317 fib_sync_up(dev);
75318 #endif
75319 - atomic_inc(&net->ipv4.dev_addr_genid);
75320 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75321 rt_cache_flush(dev_net(dev), -1);
75322 break;
75323 case NETDEV_DOWN:
75324 fib_del_ifaddr(ifa, NULL);
75325 - atomic_inc(&net->ipv4.dev_addr_genid);
75326 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75327 if (ifa->ifa_dev->ifa_list == NULL) {
75328 /* Last address was deleted from this interface.
75329 * Disable IP.
75330 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75331 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75332 fib_sync_up(dev);
75333 #endif
75334 - atomic_inc(&net->ipv4.dev_addr_genid);
75335 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75336 rt_cache_flush(dev_net(dev), -1);
75337 break;
75338 case NETDEV_DOWN:
75339 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75340 index 80106d8..232e898 100644
75341 --- a/net/ipv4/fib_semantics.c
75342 +++ b/net/ipv4/fib_semantics.c
75343 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75344 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75345 nh->nh_gw,
75346 nh->nh_parent->fib_scope);
75347 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75348 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75349
75350 return nh->nh_saddr;
75351 }
75352 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75353 index 984ec65..97ac518 100644
75354 --- a/net/ipv4/inet_hashtables.c
75355 +++ b/net/ipv4/inet_hashtables.c
75356 @@ -18,12 +18,15 @@
75357 #include <linux/sched.h>
75358 #include <linux/slab.h>
75359 #include <linux/wait.h>
75360 +#include <linux/security.h>
75361
75362 #include <net/inet_connection_sock.h>
75363 #include <net/inet_hashtables.h>
75364 #include <net/secure_seq.h>
75365 #include <net/ip.h>
75366
75367 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75368 +
75369 /*
75370 * Allocate and initialize a new local port bind bucket.
75371 * The bindhash mutex for snum's hash chain must be held here.
75372 @@ -530,6 +533,8 @@ ok:
75373 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75374 spin_unlock(&head->lock);
75375
75376 + gr_update_task_in_ip_table(current, inet_sk(sk));
75377 +
75378 if (tw) {
75379 inet_twsk_deschedule(tw, death_row);
75380 while (twrefcnt) {
75381 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75382 index d4d61b6..b81aec8 100644
75383 --- a/net/ipv4/inetpeer.c
75384 +++ b/net/ipv4/inetpeer.c
75385 @@ -487,8 +487,8 @@ relookup:
75386 if (p) {
75387 p->daddr = *daddr;
75388 atomic_set(&p->refcnt, 1);
75389 - atomic_set(&p->rid, 0);
75390 - atomic_set(&p->ip_id_count,
75391 + atomic_set_unchecked(&p->rid, 0);
75392 + atomic_set_unchecked(&p->ip_id_count,
75393 (daddr->family == AF_INET) ?
75394 secure_ip_id(daddr->addr.a4) :
75395 secure_ipv6_id(daddr->addr.a6));
75396 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75397 index 1f23a57..7180dfe 100644
75398 --- a/net/ipv4/ip_fragment.c
75399 +++ b/net/ipv4/ip_fragment.c
75400 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75401 return 0;
75402
75403 start = qp->rid;
75404 - end = atomic_inc_return(&peer->rid);
75405 + end = atomic_inc_return_unchecked(&peer->rid);
75406 qp->rid = end;
75407
75408 rc = qp->q.fragments && (end - start) > max;
75409 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75410 index 8aa87c1..35c3248 100644
75411 --- a/net/ipv4/ip_sockglue.c
75412 +++ b/net/ipv4/ip_sockglue.c
75413 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75414 len = min_t(unsigned int, len, opt->optlen);
75415 if (put_user(len, optlen))
75416 return -EFAULT;
75417 - if (copy_to_user(optval, opt->__data, len))
75418 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75419 + copy_to_user(optval, opt->__data, len))
75420 return -EFAULT;
75421 return 0;
75422 }
75423 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75424 if (sk->sk_type != SOCK_STREAM)
75425 return -ENOPROTOOPT;
75426
75427 - msg.msg_control = optval;
75428 + msg.msg_control = (void __force_kernel *)optval;
75429 msg.msg_controllen = len;
75430 msg.msg_flags = flags;
75431
75432 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75433 index 6e412a6..6640538 100644
75434 --- a/net/ipv4/ipconfig.c
75435 +++ b/net/ipv4/ipconfig.c
75436 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75437
75438 mm_segment_t oldfs = get_fs();
75439 set_fs(get_ds());
75440 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75441 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75442 set_fs(oldfs);
75443 return res;
75444 }
75445 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75446
75447 mm_segment_t oldfs = get_fs();
75448 set_fs(get_ds());
75449 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75450 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75451 set_fs(oldfs);
75452 return res;
75453 }
75454 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75455
75456 mm_segment_t oldfs = get_fs();
75457 set_fs(get_ds());
75458 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75459 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75460 set_fs(oldfs);
75461 return res;
75462 }
75463 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
75464 index fd7a3f6..a1b1013 100644
75465 --- a/net/ipv4/netfilter/arp_tables.c
75466 +++ b/net/ipv4/netfilter/arp_tables.c
75467 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75468
75469 static int copy_entries_to_user(unsigned int total_size,
75470 const struct xt_table *table,
75471 + void __user *userptr) __size_overflow(1);
75472 +static int copy_entries_to_user(unsigned int total_size,
75473 + const struct xt_table *table,
75474 void __user *userptr)
75475 {
75476 unsigned int off, num;
75477 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
75478 unsigned int valid_hooks,
75479 struct xt_table_info *newinfo,
75480 unsigned int num_counters,
75481 + void __user *counters_ptr) __size_overflow(5);
75482 +static int __do_replace(struct net *net, const char *name,
75483 + unsigned int valid_hooks,
75484 + struct xt_table_info *newinfo,
75485 + unsigned int num_counters,
75486 void __user *counters_ptr)
75487 {
75488 int ret;
75489 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
75490 }
75491
75492 static int do_add_counters(struct net *net, const void __user *user,
75493 + unsigned int len, int compat) __size_overflow(3);
75494 +static int do_add_counters(struct net *net, const void __user *user,
75495 unsigned int len, int compat)
75496 {
75497 unsigned int i, curcpu;
75498 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
75499 index 24e556e..b073356 100644
75500 --- a/net/ipv4/netfilter/ip_tables.c
75501 +++ b/net/ipv4/netfilter/ip_tables.c
75502 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75503 static int
75504 copy_entries_to_user(unsigned int total_size,
75505 const struct xt_table *table,
75506 + void __user *userptr) __size_overflow(1);
75507 +static int
75508 +copy_entries_to_user(unsigned int total_size,
75509 + const struct xt_table *table,
75510 void __user *userptr)
75511 {
75512 unsigned int off, num;
75513 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
75514 static int
75515 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75516 struct xt_table_info *newinfo, unsigned int num_counters,
75517 + void __user *counters_ptr) __size_overflow(5);
75518 +static int
75519 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75520 + struct xt_table_info *newinfo, unsigned int num_counters,
75521 void __user *counters_ptr)
75522 {
75523 int ret;
75524 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
75525
75526 static int
75527 do_add_counters(struct net *net, const void __user *user,
75528 + unsigned int len, int compat) __size_overflow(3);
75529 +static int
75530 +do_add_counters(struct net *net, const void __user *user,
75531 unsigned int len, int compat)
75532 {
75533 unsigned int i, curcpu;
75534 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
75535 index ba5756d..8d34d74 100644
75536 --- a/net/ipv4/netfilter/ipt_ULOG.c
75537 +++ b/net/ipv4/netfilter/ipt_ULOG.c
75538 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
75539 spin_unlock_bh(&ulog_lock);
75540 }
75541
75542 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75543 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75544 {
75545 struct sk_buff *skb;
75546 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75547 index 2133c30..0e8047e 100644
75548 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75549 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75550 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
75551 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75552 unsigned char *eoc,
75553 unsigned long **oid,
75554 + unsigned int *len) __size_overflow(2);
75555 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75556 + unsigned char *eoc,
75557 + unsigned long **oid,
75558 unsigned int *len)
75559 {
75560 unsigned long subid;
75561 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75562 index b072386..abdebcf 100644
75563 --- a/net/ipv4/ping.c
75564 +++ b/net/ipv4/ping.c
75565 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75566 sk_rmem_alloc_get(sp),
75567 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75568 atomic_read(&sp->sk_refcnt), sp,
75569 - atomic_read(&sp->sk_drops), len);
75570 + atomic_read_unchecked(&sp->sk_drops), len);
75571 }
75572
75573 static int ping_seq_show(struct seq_file *seq, void *v)
75574 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75575 index 3ccda5a..3c1e61d 100644
75576 --- a/net/ipv4/raw.c
75577 +++ b/net/ipv4/raw.c
75578 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75579 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75580 {
75581 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75582 - atomic_inc(&sk->sk_drops);
75583 + atomic_inc_unchecked(&sk->sk_drops);
75584 kfree_skb(skb);
75585 return NET_RX_DROP;
75586 }
75587 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75588
75589 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75590 {
75591 + struct icmp_filter filter;
75592 +
75593 if (optlen > sizeof(struct icmp_filter))
75594 optlen = sizeof(struct icmp_filter);
75595 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75596 + if (copy_from_user(&filter, optval, optlen))
75597 return -EFAULT;
75598 + raw_sk(sk)->filter = filter;
75599 return 0;
75600 }
75601
75602 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75603 {
75604 int len, ret = -EFAULT;
75605 + struct icmp_filter filter;
75606
75607 if (get_user(len, optlen))
75608 goto out;
75609 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75610 if (len > sizeof(struct icmp_filter))
75611 len = sizeof(struct icmp_filter);
75612 ret = -EFAULT;
75613 - if (put_user(len, optlen) ||
75614 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75615 + filter = raw_sk(sk)->filter;
75616 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75617 goto out;
75618 ret = 0;
75619 out: return ret;
75620 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75621 sk_wmem_alloc_get(sp),
75622 sk_rmem_alloc_get(sp),
75623 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75624 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75625 + atomic_read(&sp->sk_refcnt),
75626 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75627 + NULL,
75628 +#else
75629 + sp,
75630 +#endif
75631 + atomic_read_unchecked(&sp->sk_drops));
75632 }
75633
75634 static int raw_seq_show(struct seq_file *seq, void *v)
75635 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75636 index 0197747..7adb0dc 100644
75637 --- a/net/ipv4/route.c
75638 +++ b/net/ipv4/route.c
75639 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75640
75641 static inline int rt_genid(struct net *net)
75642 {
75643 - return atomic_read(&net->ipv4.rt_genid);
75644 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75645 }
75646
75647 #ifdef CONFIG_PROC_FS
75648 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75649 unsigned char shuffle;
75650
75651 get_random_bytes(&shuffle, sizeof(shuffle));
75652 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75653 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75654 inetpeer_invalidate_tree(AF_INET);
75655 }
75656
75657 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75658 error = rt->dst.error;
75659 if (peer) {
75660 inet_peer_refcheck(rt->peer);
75661 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75662 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75663 if (peer->tcp_ts_stamp) {
75664 ts = peer->tcp_ts;
75665 tsage = get_seconds() - peer->tcp_ts_stamp;
75666 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75667 index fd54c5f..96d6407 100644
75668 --- a/net/ipv4/tcp_ipv4.c
75669 +++ b/net/ipv4/tcp_ipv4.c
75670 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75671 int sysctl_tcp_low_latency __read_mostly;
75672 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75673
75674 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75675 +extern int grsec_enable_blackhole;
75676 +#endif
75677
75678 #ifdef CONFIG_TCP_MD5SIG
75679 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75680 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75681 return 0;
75682
75683 reset:
75684 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75685 + if (!grsec_enable_blackhole)
75686 +#endif
75687 tcp_v4_send_reset(rsk, skb);
75688 discard:
75689 kfree_skb(skb);
75690 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75691 TCP_SKB_CB(skb)->sacked = 0;
75692
75693 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75694 - if (!sk)
75695 + if (!sk) {
75696 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75697 + ret = 1;
75698 +#endif
75699 goto no_tcp_socket;
75700 -
75701 + }
75702 process:
75703 - if (sk->sk_state == TCP_TIME_WAIT)
75704 + if (sk->sk_state == TCP_TIME_WAIT) {
75705 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75706 + ret = 2;
75707 +#endif
75708 goto do_time_wait;
75709 + }
75710
75711 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75712 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75713 @@ -1755,6 +1768,10 @@ no_tcp_socket:
75714 bad_packet:
75715 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75716 } else {
75717 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75718 + if (!grsec_enable_blackhole || (ret == 1 &&
75719 + (skb->dev->flags & IFF_LOOPBACK)))
75720 +#endif
75721 tcp_v4_send_reset(NULL, skb);
75722 }
75723
75724 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75725 0, /* non standard timer */
75726 0, /* open_requests have no inode */
75727 atomic_read(&sk->sk_refcnt),
75728 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75729 + NULL,
75730 +#else
75731 req,
75732 +#endif
75733 len);
75734 }
75735
75736 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75737 sock_i_uid(sk),
75738 icsk->icsk_probes_out,
75739 sock_i_ino(sk),
75740 - atomic_read(&sk->sk_refcnt), sk,
75741 + atomic_read(&sk->sk_refcnt),
75742 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75743 + NULL,
75744 +#else
75745 + sk,
75746 +#endif
75747 jiffies_to_clock_t(icsk->icsk_rto),
75748 jiffies_to_clock_t(icsk->icsk_ack.ato),
75749 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75750 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75751 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75752 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75753 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75754 - atomic_read(&tw->tw_refcnt), tw, len);
75755 + atomic_read(&tw->tw_refcnt),
75756 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75757 + NULL,
75758 +#else
75759 + tw,
75760 +#endif
75761 + len);
75762 }
75763
75764 #define TMPSZ 150
75765 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75766 index 550e755..25721b3 100644
75767 --- a/net/ipv4/tcp_minisocks.c
75768 +++ b/net/ipv4/tcp_minisocks.c
75769 @@ -27,6 +27,10 @@
75770 #include <net/inet_common.h>
75771 #include <net/xfrm.h>
75772
75773 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75774 +extern int grsec_enable_blackhole;
75775 +#endif
75776 +
75777 int sysctl_tcp_syncookies __read_mostly = 1;
75778 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75779
75780 @@ -753,6 +757,10 @@ listen_overflow:
75781
75782 embryonic_reset:
75783 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75784 +
75785 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75786 + if (!grsec_enable_blackhole)
75787 +#endif
75788 if (!(flg & TCP_FLAG_RST))
75789 req->rsk_ops->send_reset(sk, skb);
75790
75791 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75792 index 85ee7eb..53277ab 100644
75793 --- a/net/ipv4/tcp_probe.c
75794 +++ b/net/ipv4/tcp_probe.c
75795 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75796 if (cnt + width >= len)
75797 break;
75798
75799 - if (copy_to_user(buf + cnt, tbuf, width))
75800 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75801 return -EFAULT;
75802 cnt += width;
75803 }
75804 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75805 index cd2e072..1fffee2 100644
75806 --- a/net/ipv4/tcp_timer.c
75807 +++ b/net/ipv4/tcp_timer.c
75808 @@ -22,6 +22,10 @@
75809 #include <linux/gfp.h>
75810 #include <net/tcp.h>
75811
75812 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75813 +extern int grsec_lastack_retries;
75814 +#endif
75815 +
75816 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75817 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75818 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75819 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75820 }
75821 }
75822
75823 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75824 + if ((sk->sk_state == TCP_LAST_ACK) &&
75825 + (grsec_lastack_retries > 0) &&
75826 + (grsec_lastack_retries < retry_until))
75827 + retry_until = grsec_lastack_retries;
75828 +#endif
75829 +
75830 if (retransmits_timed_out(sk, retry_until,
75831 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75832 /* Has it gone just too far? */
75833 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75834 index 5d075b5..d907d5f 100644
75835 --- a/net/ipv4/udp.c
75836 +++ b/net/ipv4/udp.c
75837 @@ -86,6 +86,7 @@
75838 #include <linux/types.h>
75839 #include <linux/fcntl.h>
75840 #include <linux/module.h>
75841 +#include <linux/security.h>
75842 #include <linux/socket.h>
75843 #include <linux/sockios.h>
75844 #include <linux/igmp.h>
75845 @@ -108,6 +109,10 @@
75846 #include <trace/events/udp.h>
75847 #include "udp_impl.h"
75848
75849 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75850 +extern int grsec_enable_blackhole;
75851 +#endif
75852 +
75853 struct udp_table udp_table __read_mostly;
75854 EXPORT_SYMBOL(udp_table);
75855
75856 @@ -566,6 +571,9 @@ found:
75857 return s;
75858 }
75859
75860 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75861 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75862 +
75863 /*
75864 * This routine is called by the ICMP module when it gets some
75865 * sort of error condition. If err < 0 then the socket should
75866 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75867 dport = usin->sin_port;
75868 if (dport == 0)
75869 return -EINVAL;
75870 +
75871 + err = gr_search_udp_sendmsg(sk, usin);
75872 + if (err)
75873 + return err;
75874 } else {
75875 if (sk->sk_state != TCP_ESTABLISHED)
75876 return -EDESTADDRREQ;
75877 +
75878 + err = gr_search_udp_sendmsg(sk, NULL);
75879 + if (err)
75880 + return err;
75881 +
75882 daddr = inet->inet_daddr;
75883 dport = inet->inet_dport;
75884 /* Open fast path for connected socket.
75885 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75886 udp_lib_checksum_complete(skb)) {
75887 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75888 IS_UDPLITE(sk));
75889 - atomic_inc(&sk->sk_drops);
75890 + atomic_inc_unchecked(&sk->sk_drops);
75891 __skb_unlink(skb, rcvq);
75892 __skb_queue_tail(&list_kill, skb);
75893 }
75894 @@ -1186,6 +1203,10 @@ try_again:
75895 if (!skb)
75896 goto out;
75897
75898 + err = gr_search_udp_recvmsg(sk, skb);
75899 + if (err)
75900 + goto out_free;
75901 +
75902 ulen = skb->len - sizeof(struct udphdr);
75903 copied = len;
75904 if (copied > ulen)
75905 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75906
75907 drop:
75908 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75909 - atomic_inc(&sk->sk_drops);
75910 + atomic_inc_unchecked(&sk->sk_drops);
75911 kfree_skb(skb);
75912 return -1;
75913 }
75914 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75915 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75916
75917 if (!skb1) {
75918 - atomic_inc(&sk->sk_drops);
75919 + atomic_inc_unchecked(&sk->sk_drops);
75920 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75921 IS_UDPLITE(sk));
75922 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75923 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75924 goto csum_error;
75925
75926 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75927 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75928 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75929 +#endif
75930 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75931
75932 /*
75933 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75934 sk_wmem_alloc_get(sp),
75935 sk_rmem_alloc_get(sp),
75936 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75937 - atomic_read(&sp->sk_refcnt), sp,
75938 - atomic_read(&sp->sk_drops), len);
75939 + atomic_read(&sp->sk_refcnt),
75940 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75941 + NULL,
75942 +#else
75943 + sp,
75944 +#endif
75945 + atomic_read_unchecked(&sp->sk_drops), len);
75946 }
75947
75948 int udp4_seq_show(struct seq_file *seq, void *v)
75949 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75950 index 6b8ebc5..1d624f4 100644
75951 --- a/net/ipv6/addrconf.c
75952 +++ b/net/ipv6/addrconf.c
75953 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75954 p.iph.ihl = 5;
75955 p.iph.protocol = IPPROTO_IPV6;
75956 p.iph.ttl = 64;
75957 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75958 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75959
75960 if (ops->ndo_do_ioctl) {
75961 mm_segment_t oldfs = get_fs();
75962 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
75963 index 2ae79db..8f101bf 100644
75964 --- a/net/ipv6/ah6.c
75965 +++ b/net/ipv6/ah6.c
75966 @@ -56,6 +56,8 @@ struct ah_skb_cb {
75967 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75968
75969 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75970 + unsigned int size) __size_overflow(3);
75971 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75972 unsigned int size)
75973 {
75974 unsigned int len;
75975 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75976 index 02dd203..e03fcc9 100644
75977 --- a/net/ipv6/inet6_connection_sock.c
75978 +++ b/net/ipv6/inet6_connection_sock.c
75979 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75980 #ifdef CONFIG_XFRM
75981 {
75982 struct rt6_info *rt = (struct rt6_info *)dst;
75983 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75984 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75985 }
75986 #endif
75987 }
75988 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75989 #ifdef CONFIG_XFRM
75990 if (dst) {
75991 struct rt6_info *rt = (struct rt6_info *)dst;
75992 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75993 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75994 __sk_dst_reset(sk);
75995 dst = NULL;
75996 }
75997 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75998 index 18a2719..779f36a 100644
75999 --- a/net/ipv6/ipv6_sockglue.c
76000 +++ b/net/ipv6/ipv6_sockglue.c
76001 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76002 if (sk->sk_type != SOCK_STREAM)
76003 return -ENOPROTOOPT;
76004
76005 - msg.msg_control = optval;
76006 + msg.msg_control = (void __force_kernel *)optval;
76007 msg.msg_controllen = len;
76008 msg.msg_flags = flags;
76009
76010 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76011 index 94874b0..108a94d 100644
76012 --- a/net/ipv6/netfilter/ip6_tables.c
76013 +++ b/net/ipv6/netfilter/ip6_tables.c
76014 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76015 static int
76016 copy_entries_to_user(unsigned int total_size,
76017 const struct xt_table *table,
76018 + void __user *userptr) __size_overflow(1);
76019 +static int
76020 +copy_entries_to_user(unsigned int total_size,
76021 + const struct xt_table *table,
76022 void __user *userptr)
76023 {
76024 unsigned int off, num;
76025 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76026 static int
76027 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76028 struct xt_table_info *newinfo, unsigned int num_counters,
76029 + void __user *counters_ptr) __size_overflow(5);
76030 +static int
76031 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76032 + struct xt_table_info *newinfo, unsigned int num_counters,
76033 void __user *counters_ptr)
76034 {
76035 int ret;
76036 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76037
76038 static int
76039 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76040 + int compat) __size_overflow(3);
76041 +static int
76042 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76043 int compat)
76044 {
76045 unsigned int i, curcpu;
76046 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76047 index d02f7e4..2d2a0f1 100644
76048 --- a/net/ipv6/raw.c
76049 +++ b/net/ipv6/raw.c
76050 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76051 {
76052 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76053 skb_checksum_complete(skb)) {
76054 - atomic_inc(&sk->sk_drops);
76055 + atomic_inc_unchecked(&sk->sk_drops);
76056 kfree_skb(skb);
76057 return NET_RX_DROP;
76058 }
76059 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76060 struct raw6_sock *rp = raw6_sk(sk);
76061
76062 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76063 - atomic_inc(&sk->sk_drops);
76064 + atomic_inc_unchecked(&sk->sk_drops);
76065 kfree_skb(skb);
76066 return NET_RX_DROP;
76067 }
76068 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76069
76070 if (inet->hdrincl) {
76071 if (skb_checksum_complete(skb)) {
76072 - atomic_inc(&sk->sk_drops);
76073 + atomic_inc_unchecked(&sk->sk_drops);
76074 kfree_skb(skb);
76075 return NET_RX_DROP;
76076 }
76077 @@ -602,7 +602,7 @@ out:
76078 return err;
76079 }
76080
76081 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76082 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76083 struct flowi6 *fl6, struct dst_entry **dstp,
76084 unsigned int flags)
76085 {
76086 @@ -912,12 +912,15 @@ do_confirm:
76087 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76088 char __user *optval, int optlen)
76089 {
76090 + struct icmp6_filter filter;
76091 +
76092 switch (optname) {
76093 case ICMPV6_FILTER:
76094 if (optlen > sizeof(struct icmp6_filter))
76095 optlen = sizeof(struct icmp6_filter);
76096 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76097 + if (copy_from_user(&filter, optval, optlen))
76098 return -EFAULT;
76099 + raw6_sk(sk)->filter = filter;
76100 return 0;
76101 default:
76102 return -ENOPROTOOPT;
76103 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76104 char __user *optval, int __user *optlen)
76105 {
76106 int len;
76107 + struct icmp6_filter filter;
76108
76109 switch (optname) {
76110 case ICMPV6_FILTER:
76111 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76112 len = sizeof(struct icmp6_filter);
76113 if (put_user(len, optlen))
76114 return -EFAULT;
76115 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76116 + filter = raw6_sk(sk)->filter;
76117 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76118 return -EFAULT;
76119 return 0;
76120 default:
76121 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76122 0, 0L, 0,
76123 sock_i_uid(sp), 0,
76124 sock_i_ino(sp),
76125 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76126 + atomic_read(&sp->sk_refcnt),
76127 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76128 + NULL,
76129 +#else
76130 + sp,
76131 +#endif
76132 + atomic_read_unchecked(&sp->sk_drops));
76133 }
76134
76135 static int raw6_seq_show(struct seq_file *seq, void *v)
76136 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76137 index 3edd05a..63aad01 100644
76138 --- a/net/ipv6/tcp_ipv6.c
76139 +++ b/net/ipv6/tcp_ipv6.c
76140 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76141 }
76142 #endif
76143
76144 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76145 +extern int grsec_enable_blackhole;
76146 +#endif
76147 +
76148 static void tcp_v6_hash(struct sock *sk)
76149 {
76150 if (sk->sk_state != TCP_CLOSE) {
76151 @@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76152 return 0;
76153
76154 reset:
76155 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76156 + if (!grsec_enable_blackhole)
76157 +#endif
76158 tcp_v6_send_reset(sk, skb);
76159 discard:
76160 if (opt_skb)
76161 @@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76162 TCP_SKB_CB(skb)->sacked = 0;
76163
76164 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76165 - if (!sk)
76166 + if (!sk) {
76167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76168 + ret = 1;
76169 +#endif
76170 goto no_tcp_socket;
76171 + }
76172
76173 process:
76174 - if (sk->sk_state == TCP_TIME_WAIT)
76175 + if (sk->sk_state == TCP_TIME_WAIT) {
76176 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76177 + ret = 2;
76178 +#endif
76179 goto do_time_wait;
76180 + }
76181
76182 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76183 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76184 @@ -1782,6 +1797,10 @@ no_tcp_socket:
76185 bad_packet:
76186 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76187 } else {
76188 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76189 + if (!grsec_enable_blackhole || (ret == 1 &&
76190 + (skb->dev->flags & IFF_LOOPBACK)))
76191 +#endif
76192 tcp_v6_send_reset(NULL, skb);
76193 }
76194
76195 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
76196 uid,
76197 0, /* non standard timer */
76198 0, /* open_requests have no inode */
76199 - 0, req);
76200 + 0,
76201 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76202 + NULL
76203 +#else
76204 + req
76205 +#endif
76206 + );
76207 }
76208
76209 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76210 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76211 sock_i_uid(sp),
76212 icsk->icsk_probes_out,
76213 sock_i_ino(sp),
76214 - atomic_read(&sp->sk_refcnt), sp,
76215 + atomic_read(&sp->sk_refcnt),
76216 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76217 + NULL,
76218 +#else
76219 + sp,
76220 +#endif
76221 jiffies_to_clock_t(icsk->icsk_rto),
76222 jiffies_to_clock_t(icsk->icsk_ack.ato),
76223 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76224 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76225 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76226 tw->tw_substate, 0, 0,
76227 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76228 - atomic_read(&tw->tw_refcnt), tw);
76229 + atomic_read(&tw->tw_refcnt),
76230 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76231 + NULL
76232 +#else
76233 + tw
76234 +#endif
76235 + );
76236 }
76237
76238 static int tcp6_seq_show(struct seq_file *seq, void *v)
76239 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76240 index 4f96b5c..75543d7 100644
76241 --- a/net/ipv6/udp.c
76242 +++ b/net/ipv6/udp.c
76243 @@ -50,6 +50,10 @@
76244 #include <linux/seq_file.h>
76245 #include "udp_impl.h"
76246
76247 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76248 +extern int grsec_enable_blackhole;
76249 +#endif
76250 +
76251 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76252 {
76253 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76254 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76255
76256 return 0;
76257 drop:
76258 - atomic_inc(&sk->sk_drops);
76259 + atomic_inc_unchecked(&sk->sk_drops);
76260 drop_no_sk_drops_inc:
76261 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76262 kfree_skb(skb);
76263 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76264 continue;
76265 }
76266 drop:
76267 - atomic_inc(&sk->sk_drops);
76268 + atomic_inc_unchecked(&sk->sk_drops);
76269 UDP6_INC_STATS_BH(sock_net(sk),
76270 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76271 UDP6_INC_STATS_BH(sock_net(sk),
76272 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76273 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76274 proto == IPPROTO_UDPLITE);
76275
76276 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76277 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76278 +#endif
76279 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76280
76281 kfree_skb(skb);
76282 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76283 if (!sock_owned_by_user(sk))
76284 udpv6_queue_rcv_skb(sk, skb);
76285 else if (sk_add_backlog(sk, skb)) {
76286 - atomic_inc(&sk->sk_drops);
76287 + atomic_inc_unchecked(&sk->sk_drops);
76288 bh_unlock_sock(sk);
76289 sock_put(sk);
76290 goto discard;
76291 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76292 0, 0L, 0,
76293 sock_i_uid(sp), 0,
76294 sock_i_ino(sp),
76295 - atomic_read(&sp->sk_refcnt), sp,
76296 - atomic_read(&sp->sk_drops));
76297 + atomic_read(&sp->sk_refcnt),
76298 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76299 + NULL,
76300 +#else
76301 + sp,
76302 +#endif
76303 + atomic_read_unchecked(&sp->sk_drops));
76304 }
76305
76306 int udp6_seq_show(struct seq_file *seq, void *v)
76307 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76308 index 253695d..9481ce8 100644
76309 --- a/net/irda/ircomm/ircomm_tty.c
76310 +++ b/net/irda/ircomm/ircomm_tty.c
76311 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76312 add_wait_queue(&self->open_wait, &wait);
76313
76314 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76315 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76316 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76317
76318 /* As far as I can see, we protect open_count - Jean II */
76319 spin_lock_irqsave(&self->spinlock, flags);
76320 if (!tty_hung_up_p(filp)) {
76321 extra_count = 1;
76322 - self->open_count--;
76323 + local_dec(&self->open_count);
76324 }
76325 spin_unlock_irqrestore(&self->spinlock, flags);
76326 - self->blocked_open++;
76327 + local_inc(&self->blocked_open);
76328
76329 while (1) {
76330 if (tty->termios->c_cflag & CBAUD) {
76331 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76332 }
76333
76334 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76335 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76336 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76337
76338 schedule();
76339 }
76340 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76341 if (extra_count) {
76342 /* ++ is not atomic, so this should be protected - Jean II */
76343 spin_lock_irqsave(&self->spinlock, flags);
76344 - self->open_count++;
76345 + local_inc(&self->open_count);
76346 spin_unlock_irqrestore(&self->spinlock, flags);
76347 }
76348 - self->blocked_open--;
76349 + local_dec(&self->blocked_open);
76350
76351 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76352 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76353 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76354
76355 if (!retval)
76356 self->flags |= ASYNC_NORMAL_ACTIVE;
76357 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76358 }
76359 /* ++ is not atomic, so this should be protected - Jean II */
76360 spin_lock_irqsave(&self->spinlock, flags);
76361 - self->open_count++;
76362 + local_inc(&self->open_count);
76363
76364 tty->driver_data = self;
76365 self->tty = tty;
76366 spin_unlock_irqrestore(&self->spinlock, flags);
76367
76368 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76369 - self->line, self->open_count);
76370 + self->line, local_read(&self->open_count));
76371
76372 /* Not really used by us, but lets do it anyway */
76373 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76374 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76375 return;
76376 }
76377
76378 - if ((tty->count == 1) && (self->open_count != 1)) {
76379 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76380 /*
76381 * Uh, oh. tty->count is 1, which means that the tty
76382 * structure will be freed. state->count should always
76383 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76384 */
76385 IRDA_DEBUG(0, "%s(), bad serial port count; "
76386 "tty->count is 1, state->count is %d\n", __func__ ,
76387 - self->open_count);
76388 - self->open_count = 1;
76389 + local_read(&self->open_count));
76390 + local_set(&self->open_count, 1);
76391 }
76392
76393 - if (--self->open_count < 0) {
76394 + if (local_dec_return(&self->open_count) < 0) {
76395 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76396 - __func__, self->line, self->open_count);
76397 - self->open_count = 0;
76398 + __func__, self->line, local_read(&self->open_count));
76399 + local_set(&self->open_count, 0);
76400 }
76401 - if (self->open_count) {
76402 + if (local_read(&self->open_count)) {
76403 spin_unlock_irqrestore(&self->spinlock, flags);
76404
76405 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76406 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76407 tty->closing = 0;
76408 self->tty = NULL;
76409
76410 - if (self->blocked_open) {
76411 + if (local_read(&self->blocked_open)) {
76412 if (self->close_delay)
76413 schedule_timeout_interruptible(self->close_delay);
76414 wake_up_interruptible(&self->open_wait);
76415 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76416 spin_lock_irqsave(&self->spinlock, flags);
76417 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76418 self->tty = NULL;
76419 - self->open_count = 0;
76420 + local_set(&self->open_count, 0);
76421 spin_unlock_irqrestore(&self->spinlock, flags);
76422
76423 wake_up_interruptible(&self->open_wait);
76424 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76425 seq_putc(m, '\n');
76426
76427 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76428 - seq_printf(m, "Open count: %d\n", self->open_count);
76429 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76430 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76431 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76432
76433 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76434 index d5c5b8f..33beff0 100644
76435 --- a/net/iucv/af_iucv.c
76436 +++ b/net/iucv/af_iucv.c
76437 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76438
76439 write_lock_bh(&iucv_sk_list.lock);
76440
76441 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76442 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76443 while (__iucv_get_sock_by_name(name)) {
76444 sprintf(name, "%08x",
76445 - atomic_inc_return(&iucv_sk_list.autobind_name));
76446 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76447 }
76448
76449 write_unlock_bh(&iucv_sk_list.lock);
76450 diff --git a/net/key/af_key.c b/net/key/af_key.c
76451 index 11dbb22..c20f667 100644
76452 --- a/net/key/af_key.c
76453 +++ b/net/key/af_key.c
76454 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76455 static u32 get_acqseq(void)
76456 {
76457 u32 res;
76458 - static atomic_t acqseq;
76459 + static atomic_unchecked_t acqseq;
76460
76461 do {
76462 - res = atomic_inc_return(&acqseq);
76463 + res = atomic_inc_return_unchecked(&acqseq);
76464 } while (!res);
76465 return res;
76466 }
76467 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76468 index 2f0642d..e5c6fba 100644
76469 --- a/net/mac80211/ieee80211_i.h
76470 +++ b/net/mac80211/ieee80211_i.h
76471 @@ -28,6 +28,7 @@
76472 #include <net/ieee80211_radiotap.h>
76473 #include <net/cfg80211.h>
76474 #include <net/mac80211.h>
76475 +#include <asm/local.h>
76476 #include "key.h"
76477 #include "sta_info.h"
76478
76479 @@ -781,7 +782,7 @@ struct ieee80211_local {
76480 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76481 spinlock_t queue_stop_reason_lock;
76482
76483 - int open_count;
76484 + local_t open_count;
76485 int monitors, cooked_mntrs;
76486 /* number of interfaces with corresponding FIF_ flags */
76487 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76488 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76489 index 8e2137b..2974283 100644
76490 --- a/net/mac80211/iface.c
76491 +++ b/net/mac80211/iface.c
76492 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76493 break;
76494 }
76495
76496 - if (local->open_count == 0) {
76497 + if (local_read(&local->open_count) == 0) {
76498 res = drv_start(local);
76499 if (res)
76500 goto err_del_bss;
76501 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76502 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76503
76504 if (!is_valid_ether_addr(dev->dev_addr)) {
76505 - if (!local->open_count)
76506 + if (!local_read(&local->open_count))
76507 drv_stop(local);
76508 return -EADDRNOTAVAIL;
76509 }
76510 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76511 mutex_unlock(&local->mtx);
76512
76513 if (coming_up)
76514 - local->open_count++;
76515 + local_inc(&local->open_count);
76516
76517 if (hw_reconf_flags)
76518 ieee80211_hw_config(local, hw_reconf_flags);
76519 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76520 err_del_interface:
76521 drv_remove_interface(local, sdata);
76522 err_stop:
76523 - if (!local->open_count)
76524 + if (!local_read(&local->open_count))
76525 drv_stop(local);
76526 err_del_bss:
76527 sdata->bss = NULL;
76528 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76529 }
76530
76531 if (going_down)
76532 - local->open_count--;
76533 + local_dec(&local->open_count);
76534
76535 switch (sdata->vif.type) {
76536 case NL80211_IFTYPE_AP_VLAN:
76537 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76538
76539 ieee80211_recalc_ps(local, -1);
76540
76541 - if (local->open_count == 0) {
76542 + if (local_read(&local->open_count) == 0) {
76543 if (local->ops->napi_poll)
76544 napi_disable(&local->napi);
76545 ieee80211_clear_tx_pending(local);
76546 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76547 index b142bd4..a651749 100644
76548 --- a/net/mac80211/main.c
76549 +++ b/net/mac80211/main.c
76550 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76551 local->hw.conf.power_level = power;
76552 }
76553
76554 - if (changed && local->open_count) {
76555 + if (changed && local_read(&local->open_count)) {
76556 ret = drv_config(local, changed);
76557 /*
76558 * Goal:
76559 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76560 index 596efaf..8f1911f 100644
76561 --- a/net/mac80211/pm.c
76562 +++ b/net/mac80211/pm.c
76563 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76564 struct ieee80211_sub_if_data *sdata;
76565 struct sta_info *sta;
76566
76567 - if (!local->open_count)
76568 + if (!local_read(&local->open_count))
76569 goto suspend;
76570
76571 ieee80211_scan_cancel(local);
76572 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76573 cancel_work_sync(&local->dynamic_ps_enable_work);
76574 del_timer_sync(&local->dynamic_ps_timer);
76575
76576 - local->wowlan = wowlan && local->open_count;
76577 + local->wowlan = wowlan && local_read(&local->open_count);
76578 if (local->wowlan) {
76579 int err = drv_suspend(local, wowlan);
76580 if (err < 0) {
76581 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76582 }
76583
76584 /* stop hardware - this must stop RX */
76585 - if (local->open_count)
76586 + if (local_read(&local->open_count))
76587 ieee80211_stop_device(local);
76588
76589 suspend:
76590 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76591 index f9b8e81..bb89b46 100644
76592 --- a/net/mac80211/rate.c
76593 +++ b/net/mac80211/rate.c
76594 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76595
76596 ASSERT_RTNL();
76597
76598 - if (local->open_count)
76599 + if (local_read(&local->open_count))
76600 return -EBUSY;
76601
76602 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76603 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76604 index c97a065..ff61928 100644
76605 --- a/net/mac80211/rc80211_pid_debugfs.c
76606 +++ b/net/mac80211/rc80211_pid_debugfs.c
76607 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76608
76609 spin_unlock_irqrestore(&events->lock, status);
76610
76611 - if (copy_to_user(buf, pb, p))
76612 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76613 return -EFAULT;
76614
76615 return p;
76616 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76617 index 9919892..8c49803 100644
76618 --- a/net/mac80211/util.c
76619 +++ b/net/mac80211/util.c
76620 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76621 }
76622 #endif
76623 /* everything else happens only if HW was up & running */
76624 - if (!local->open_count)
76625 + if (!local_read(&local->open_count))
76626 goto wake_up;
76627
76628 /*
76629 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76630 index f8ac4ef..b02560b 100644
76631 --- a/net/netfilter/Kconfig
76632 +++ b/net/netfilter/Kconfig
76633 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76634
76635 To compile it as a module, choose M here. If unsure, say N.
76636
76637 +config NETFILTER_XT_MATCH_GRADM
76638 + tristate '"gradm" match support'
76639 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76640 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76641 + ---help---
76642 + The gradm match allows to match on grsecurity RBAC being enabled.
76643 + It is useful when iptables rules are applied early on bootup to
76644 + prevent connections to the machine (except from a trusted host)
76645 + while the RBAC system is disabled.
76646 +
76647 config NETFILTER_XT_MATCH_HASHLIMIT
76648 tristate '"hashlimit" match support'
76649 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76650 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76651 index 40f4c3d..0d5dd6b 100644
76652 --- a/net/netfilter/Makefile
76653 +++ b/net/netfilter/Makefile
76654 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76655 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76656 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76657 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76658 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76659 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76660 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76661 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76662 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76663 index 29fa5ba..8debc79 100644
76664 --- a/net/netfilter/ipvs/ip_vs_conn.c
76665 +++ b/net/netfilter/ipvs/ip_vs_conn.c
76666 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76667 /* Increase the refcnt counter of the dest */
76668 atomic_inc(&dest->refcnt);
76669
76670 - conn_flags = atomic_read(&dest->conn_flags);
76671 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
76672 if (cp->protocol != IPPROTO_UDP)
76673 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76674 /* Bind with the destination and its corresponding transmitter */
76675 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76676 atomic_set(&cp->refcnt, 1);
76677
76678 atomic_set(&cp->n_control, 0);
76679 - atomic_set(&cp->in_pkts, 0);
76680 + atomic_set_unchecked(&cp->in_pkts, 0);
76681
76682 atomic_inc(&ipvs->conn_count);
76683 if (flags & IP_VS_CONN_F_NO_CPORT)
76684 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76685
76686 /* Don't drop the entry if its number of incoming packets is not
76687 located in [0, 8] */
76688 - i = atomic_read(&cp->in_pkts);
76689 + i = atomic_read_unchecked(&cp->in_pkts);
76690 if (i > 8 || i < 0) return 0;
76691
76692 if (!todrop_rate[i]) return 0;
76693 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76694 index 2555816..31492d9 100644
76695 --- a/net/netfilter/ipvs/ip_vs_core.c
76696 +++ b/net/netfilter/ipvs/ip_vs_core.c
76697 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76698 ret = cp->packet_xmit(skb, cp, pd->pp);
76699 /* do not touch skb anymore */
76700
76701 - atomic_inc(&cp->in_pkts);
76702 + atomic_inc_unchecked(&cp->in_pkts);
76703 ip_vs_conn_put(cp);
76704 return ret;
76705 }
76706 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76707 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76708 pkts = sysctl_sync_threshold(ipvs);
76709 else
76710 - pkts = atomic_add_return(1, &cp->in_pkts);
76711 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76712
76713 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76714 cp->protocol == IPPROTO_SCTP) {
76715 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76716 index b3afe18..08ec940 100644
76717 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76718 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76719 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76720 ip_vs_rs_hash(ipvs, dest);
76721 write_unlock_bh(&ipvs->rs_lock);
76722 }
76723 - atomic_set(&dest->conn_flags, conn_flags);
76724 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76725
76726 /* bind the service */
76727 if (!dest->svc) {
76728 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76729 " %-7s %-6d %-10d %-10d\n",
76730 &dest->addr.in6,
76731 ntohs(dest->port),
76732 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76733 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76734 atomic_read(&dest->weight),
76735 atomic_read(&dest->activeconns),
76736 atomic_read(&dest->inactconns));
76737 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76738 "%-7s %-6d %-10d %-10d\n",
76739 ntohl(dest->addr.ip),
76740 ntohs(dest->port),
76741 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76742 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76743 atomic_read(&dest->weight),
76744 atomic_read(&dest->activeconns),
76745 atomic_read(&dest->inactconns));
76746 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76747
76748 entry.addr = dest->addr.ip;
76749 entry.port = dest->port;
76750 - entry.conn_flags = atomic_read(&dest->conn_flags);
76751 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76752 entry.weight = atomic_read(&dest->weight);
76753 entry.u_threshold = dest->u_threshold;
76754 entry.l_threshold = dest->l_threshold;
76755 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76756 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76757
76758 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76759 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76760 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76761 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76762 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76763 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76764 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76765 index 8a0d6d6..90ec197 100644
76766 --- a/net/netfilter/ipvs/ip_vs_sync.c
76767 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76768 @@ -649,7 +649,7 @@ control:
76769 * i.e only increment in_pkts for Templates.
76770 */
76771 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76772 - int pkts = atomic_add_return(1, &cp->in_pkts);
76773 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76774
76775 if (pkts % sysctl_sync_period(ipvs) != 1)
76776 return;
76777 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76778
76779 if (opt)
76780 memcpy(&cp->in_seq, opt, sizeof(*opt));
76781 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76782 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76783 cp->state = state;
76784 cp->old_state = cp->state;
76785 /*
76786 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76787 index 7fd66de..e6fb361 100644
76788 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76789 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76790 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76791 else
76792 rc = NF_ACCEPT;
76793 /* do not touch skb anymore */
76794 - atomic_inc(&cp->in_pkts);
76795 + atomic_inc_unchecked(&cp->in_pkts);
76796 goto out;
76797 }
76798
76799 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76800 else
76801 rc = NF_ACCEPT;
76802 /* do not touch skb anymore */
76803 - atomic_inc(&cp->in_pkts);
76804 + atomic_inc_unchecked(&cp->in_pkts);
76805 goto out;
76806 }
76807
76808 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76809 index 66b2c54..c7884e3 100644
76810 --- a/net/netfilter/nfnetlink_log.c
76811 +++ b/net/netfilter/nfnetlink_log.c
76812 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76813 };
76814
76815 static DEFINE_SPINLOCK(instances_lock);
76816 -static atomic_t global_seq;
76817 +static atomic_unchecked_t global_seq;
76818
76819 #define INSTANCE_BUCKETS 16
76820 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76821 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76822 /* global sequence number */
76823 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76824 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76825 - htonl(atomic_inc_return(&global_seq)));
76826 + htonl(atomic_inc_return_unchecked(&global_seq)));
76827
76828 if (data_len) {
76829 struct nlattr *nla;
76830 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76831 new file mode 100644
76832 index 0000000..6905327
76833 --- /dev/null
76834 +++ b/net/netfilter/xt_gradm.c
76835 @@ -0,0 +1,51 @@
76836 +/*
76837 + * gradm match for netfilter
76838 + * Copyright © Zbigniew Krzystolik, 2010
76839 + *
76840 + * This program is free software; you can redistribute it and/or modify
76841 + * it under the terms of the GNU General Public License; either version
76842 + * 2 or 3 as published by the Free Software Foundation.
76843 + */
76844 +#include <linux/module.h>
76845 +#include <linux/moduleparam.h>
76846 +#include <linux/skbuff.h>
76847 +#include <linux/netfilter/x_tables.h>
76848 +#include <linux/grsecurity.h>
76849 +#include <linux/netfilter/xt_gradm.h>
76850 +
76851 +static bool
76852 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76853 +{
76854 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76855 + bool retval = false;
76856 + if (gr_acl_is_enabled())
76857 + retval = true;
76858 + return retval ^ info->invflags;
76859 +}
76860 +
76861 +static struct xt_match gradm_mt_reg __read_mostly = {
76862 + .name = "gradm",
76863 + .revision = 0,
76864 + .family = NFPROTO_UNSPEC,
76865 + .match = gradm_mt,
76866 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76867 + .me = THIS_MODULE,
76868 +};
76869 +
76870 +static int __init gradm_mt_init(void)
76871 +{
76872 + return xt_register_match(&gradm_mt_reg);
76873 +}
76874 +
76875 +static void __exit gradm_mt_exit(void)
76876 +{
76877 + xt_unregister_match(&gradm_mt_reg);
76878 +}
76879 +
76880 +module_init(gradm_mt_init);
76881 +module_exit(gradm_mt_exit);
76882 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76883 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76884 +MODULE_LICENSE("GPL");
76885 +MODULE_ALIAS("ipt_gradm");
76886 +MODULE_ALIAS("ip6t_gradm");
76887 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76888 index 4fe4fb4..87a89e5 100644
76889 --- a/net/netfilter/xt_statistic.c
76890 +++ b/net/netfilter/xt_statistic.c
76891 @@ -19,7 +19,7 @@
76892 #include <linux/module.h>
76893
76894 struct xt_statistic_priv {
76895 - atomic_t count;
76896 + atomic_unchecked_t count;
76897 } ____cacheline_aligned_in_smp;
76898
76899 MODULE_LICENSE("GPL");
76900 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76901 break;
76902 case XT_STATISTIC_MODE_NTH:
76903 do {
76904 - oval = atomic_read(&info->master->count);
76905 + oval = atomic_read_unchecked(&info->master->count);
76906 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76907 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76908 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76909 if (nval == 0)
76910 ret = !ret;
76911 break;
76912 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76913 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76914 if (info->master == NULL)
76915 return -ENOMEM;
76916 - atomic_set(&info->master->count, info->u.nth.count);
76917 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76918
76919 return 0;
76920 }
76921 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76922 index 629b061..8f415cc 100644
76923 --- a/net/netlink/af_netlink.c
76924 +++ b/net/netlink/af_netlink.c
76925 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76926 sk->sk_error_report(sk);
76927 }
76928 }
76929 - atomic_inc(&sk->sk_drops);
76930 + atomic_inc_unchecked(&sk->sk_drops);
76931 }
76932
76933 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76934 @@ -829,12 +829,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
76935 return 0;
76936 }
76937
76938 -int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76939 +static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76940 {
76941 int len = skb->len;
76942
76943 skb_queue_tail(&sk->sk_receive_queue, skb);
76944 sk->sk_data_ready(sk, len);
76945 + return len;
76946 +}
76947 +
76948 +int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76949 +{
76950 + int len = __netlink_sendskb(sk, skb);
76951 +
76952 sock_put(sk);
76953 return len;
76954 }
76955 @@ -957,8 +964,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
76956 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
76957 !test_bit(0, &nlk->state)) {
76958 skb_set_owner_r(skb, sk);
76959 - skb_queue_tail(&sk->sk_receive_queue, skb);
76960 - sk->sk_data_ready(sk, skb->len);
76961 + __netlink_sendskb(sk, skb);
76962 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
76963 }
76964 return -1;
76965 @@ -1680,10 +1686,8 @@ static int netlink_dump(struct sock *sk)
76966
76967 if (sk_filter(sk, skb))
76968 kfree_skb(skb);
76969 - else {
76970 - skb_queue_tail(&sk->sk_receive_queue, skb);
76971 - sk->sk_data_ready(sk, skb->len);
76972 - }
76973 + else
76974 + __netlink_sendskb(sk, skb);
76975 return 0;
76976 }
76977
76978 @@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk)
76979
76980 if (sk_filter(sk, skb))
76981 kfree_skb(skb);
76982 - else {
76983 - skb_queue_tail(&sk->sk_receive_queue, skb);
76984 - sk->sk_data_ready(sk, skb->len);
76985 - }
76986 + else
76987 + __netlink_sendskb(sk, skb);
76988
76989 if (cb->done)
76990 cb->done(cb);
76991 @@ -1995,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76992 sk_wmem_alloc_get(s),
76993 nlk->cb,
76994 atomic_read(&s->sk_refcnt),
76995 - atomic_read(&s->sk_drops),
76996 + atomic_read_unchecked(&s->sk_drops),
76997 sock_i_ino(s)
76998 );
76999
77000 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77001 index 7dab229..212156f 100644
77002 --- a/net/netrom/af_netrom.c
77003 +++ b/net/netrom/af_netrom.c
77004 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77005 struct sock *sk = sock->sk;
77006 struct nr_sock *nr = nr_sk(sk);
77007
77008 + memset(sax, 0, sizeof(*sax));
77009 lock_sock(sk);
77010 if (peer != 0) {
77011 if (sk->sk_state != TCP_ESTABLISHED) {
77012 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77013 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77014 } else {
77015 sax->fsa_ax25.sax25_family = AF_NETROM;
77016 - sax->fsa_ax25.sax25_ndigis = 0;
77017 sax->fsa_ax25.sax25_call = nr->source_addr;
77018 *uaddr_len = sizeof(struct sockaddr_ax25);
77019 }
77020 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77021 index 2dbb32b..a1b4722 100644
77022 --- a/net/packet/af_packet.c
77023 +++ b/net/packet/af_packet.c
77024 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77025
77026 spin_lock(&sk->sk_receive_queue.lock);
77027 po->stats.tp_packets++;
77028 - skb->dropcount = atomic_read(&sk->sk_drops);
77029 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77030 __skb_queue_tail(&sk->sk_receive_queue, skb);
77031 spin_unlock(&sk->sk_receive_queue.lock);
77032 sk->sk_data_ready(sk, skb->len);
77033 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77034 drop_n_acct:
77035 spin_lock(&sk->sk_receive_queue.lock);
77036 po->stats.tp_drops++;
77037 - atomic_inc(&sk->sk_drops);
77038 + atomic_inc_unchecked(&sk->sk_drops);
77039 spin_unlock(&sk->sk_receive_queue.lock);
77040
77041 drop_n_restore:
77042 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77043 case PACKET_HDRLEN:
77044 if (len > sizeof(int))
77045 len = sizeof(int);
77046 - if (copy_from_user(&val, optval, len))
77047 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77048 return -EFAULT;
77049 switch (val) {
77050 case TPACKET_V1:
77051 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77052
77053 if (put_user(len, optlen))
77054 return -EFAULT;
77055 - if (copy_to_user(optval, data, len))
77056 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77057 return -EFAULT;
77058 return 0;
77059 }
77060 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77061 index d65f699..05aa6ce 100644
77062 --- a/net/phonet/af_phonet.c
77063 +++ b/net/phonet/af_phonet.c
77064 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77065 {
77066 struct phonet_protocol *pp;
77067
77068 - if (protocol >= PHONET_NPROTO)
77069 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77070 return NULL;
77071
77072 rcu_read_lock();
77073 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77074 {
77075 int err = 0;
77076
77077 - if (protocol >= PHONET_NPROTO)
77078 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77079 return -EINVAL;
77080
77081 err = proto_register(pp->prot, 1);
77082 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77083 index 9f60008..ae96f04 100644
77084 --- a/net/phonet/pep.c
77085 +++ b/net/phonet/pep.c
77086 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77087
77088 case PNS_PEP_CTRL_REQ:
77089 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77090 - atomic_inc(&sk->sk_drops);
77091 + atomic_inc_unchecked(&sk->sk_drops);
77092 break;
77093 }
77094 __skb_pull(skb, 4);
77095 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77096 }
77097
77098 if (pn->rx_credits == 0) {
77099 - atomic_inc(&sk->sk_drops);
77100 + atomic_inc_unchecked(&sk->sk_drops);
77101 err = -ENOBUFS;
77102 break;
77103 }
77104 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77105 }
77106
77107 if (pn->rx_credits == 0) {
77108 - atomic_inc(&sk->sk_drops);
77109 + atomic_inc_unchecked(&sk->sk_drops);
77110 err = NET_RX_DROP;
77111 break;
77112 }
77113 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77114 index 4c7eff3..59c727f 100644
77115 --- a/net/phonet/socket.c
77116 +++ b/net/phonet/socket.c
77117 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77118 pn->resource, sk->sk_state,
77119 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77120 sock_i_uid(sk), sock_i_ino(sk),
77121 - atomic_read(&sk->sk_refcnt), sk,
77122 - atomic_read(&sk->sk_drops), &len);
77123 + atomic_read(&sk->sk_refcnt),
77124 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77125 + NULL,
77126 +#else
77127 + sk,
77128 +#endif
77129 + atomic_read_unchecked(&sk->sk_drops), &len);
77130 }
77131 seq_printf(seq, "%*s\n", 127 - len, "");
77132 return 0;
77133 diff --git a/net/rds/cong.c b/net/rds/cong.c
77134 index e5b65ac..f3b6fb7 100644
77135 --- a/net/rds/cong.c
77136 +++ b/net/rds/cong.c
77137 @@ -78,7 +78,7 @@
77138 * finds that the saved generation number is smaller than the global generation
77139 * number, it wakes up the process.
77140 */
77141 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77142 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77143
77144 /*
77145 * Congestion monitoring
77146 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77147 rdsdebug("waking map %p for %pI4\n",
77148 map, &map->m_addr);
77149 rds_stats_inc(s_cong_update_received);
77150 - atomic_inc(&rds_cong_generation);
77151 + atomic_inc_unchecked(&rds_cong_generation);
77152 if (waitqueue_active(&map->m_waitq))
77153 wake_up(&map->m_waitq);
77154 if (waitqueue_active(&rds_poll_waitq))
77155 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77156
77157 int rds_cong_updated_since(unsigned long *recent)
77158 {
77159 - unsigned long gen = atomic_read(&rds_cong_generation);
77160 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77161
77162 if (likely(*recent == gen))
77163 return 0;
77164 diff --git a/net/rds/ib.h b/net/rds/ib.h
77165 index edfaaaf..8c89879 100644
77166 --- a/net/rds/ib.h
77167 +++ b/net/rds/ib.h
77168 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77169 /* sending acks */
77170 unsigned long i_ack_flags;
77171 #ifdef KERNEL_HAS_ATOMIC64
77172 - atomic64_t i_ack_next; /* next ACK to send */
77173 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77174 #else
77175 spinlock_t i_ack_lock; /* protect i_ack_next */
77176 u64 i_ack_next; /* next ACK to send */
77177 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77178 index 51c8689..36c555f 100644
77179 --- a/net/rds/ib_cm.c
77180 +++ b/net/rds/ib_cm.c
77181 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77182 /* Clear the ACK state */
77183 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77184 #ifdef KERNEL_HAS_ATOMIC64
77185 - atomic64_set(&ic->i_ack_next, 0);
77186 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77187 #else
77188 ic->i_ack_next = 0;
77189 #endif
77190 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77191 index e29e0ca..fa3a6a3 100644
77192 --- a/net/rds/ib_recv.c
77193 +++ b/net/rds/ib_recv.c
77194 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77195 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77196 int ack_required)
77197 {
77198 - atomic64_set(&ic->i_ack_next, seq);
77199 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77200 if (ack_required) {
77201 smp_mb__before_clear_bit();
77202 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77203 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77204 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77205 smp_mb__after_clear_bit();
77206
77207 - return atomic64_read(&ic->i_ack_next);
77208 + return atomic64_read_unchecked(&ic->i_ack_next);
77209 }
77210 #endif
77211
77212 diff --git a/net/rds/iw.h b/net/rds/iw.h
77213 index 04ce3b1..48119a6 100644
77214 --- a/net/rds/iw.h
77215 +++ b/net/rds/iw.h
77216 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77217 /* sending acks */
77218 unsigned long i_ack_flags;
77219 #ifdef KERNEL_HAS_ATOMIC64
77220 - atomic64_t i_ack_next; /* next ACK to send */
77221 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77222 #else
77223 spinlock_t i_ack_lock; /* protect i_ack_next */
77224 u64 i_ack_next; /* next ACK to send */
77225 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77226 index 9556d28..f046d0e 100644
77227 --- a/net/rds/iw_cm.c
77228 +++ b/net/rds/iw_cm.c
77229 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77230 /* Clear the ACK state */
77231 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77232 #ifdef KERNEL_HAS_ATOMIC64
77233 - atomic64_set(&ic->i_ack_next, 0);
77234 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77235 #else
77236 ic->i_ack_next = 0;
77237 #endif
77238 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77239 index 5e57347..3916042 100644
77240 --- a/net/rds/iw_recv.c
77241 +++ b/net/rds/iw_recv.c
77242 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77243 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77244 int ack_required)
77245 {
77246 - atomic64_set(&ic->i_ack_next, seq);
77247 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77248 if (ack_required) {
77249 smp_mb__before_clear_bit();
77250 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77251 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77252 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77253 smp_mb__after_clear_bit();
77254
77255 - return atomic64_read(&ic->i_ack_next);
77256 + return atomic64_read_unchecked(&ic->i_ack_next);
77257 }
77258 #endif
77259
77260 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77261 index edac9ef..16bcb98 100644
77262 --- a/net/rds/tcp.c
77263 +++ b/net/rds/tcp.c
77264 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77265 int val = 1;
77266
77267 set_fs(KERNEL_DS);
77268 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77269 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77270 sizeof(val));
77271 set_fs(oldfs);
77272 }
77273 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77274 index 1b4fd68..2234175 100644
77275 --- a/net/rds/tcp_send.c
77276 +++ b/net/rds/tcp_send.c
77277 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77278
77279 oldfs = get_fs();
77280 set_fs(KERNEL_DS);
77281 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77282 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77283 sizeof(val));
77284 set_fs(oldfs);
77285 }
77286 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77287 index 74c064c..fdec26f 100644
77288 --- a/net/rxrpc/af_rxrpc.c
77289 +++ b/net/rxrpc/af_rxrpc.c
77290 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77291 __be32 rxrpc_epoch;
77292
77293 /* current debugging ID */
77294 -atomic_t rxrpc_debug_id;
77295 +atomic_unchecked_t rxrpc_debug_id;
77296
77297 /* count of skbs currently in use */
77298 atomic_t rxrpc_n_skbs;
77299 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77300 index c3126e8..21facc7 100644
77301 --- a/net/rxrpc/ar-ack.c
77302 +++ b/net/rxrpc/ar-ack.c
77303 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77304
77305 _enter("{%d,%d,%d,%d},",
77306 call->acks_hard, call->acks_unacked,
77307 - atomic_read(&call->sequence),
77308 + atomic_read_unchecked(&call->sequence),
77309 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77310
77311 stop = 0;
77312 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77313
77314 /* each Tx packet has a new serial number */
77315 sp->hdr.serial =
77316 - htonl(atomic_inc_return(&call->conn->serial));
77317 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77318
77319 hdr = (struct rxrpc_header *) txb->head;
77320 hdr->serial = sp->hdr.serial;
77321 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77322 */
77323 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77324 {
77325 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77326 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77327 }
77328
77329 /*
77330 @@ -629,7 +629,7 @@ process_further:
77331
77332 latest = ntohl(sp->hdr.serial);
77333 hard = ntohl(ack.firstPacket);
77334 - tx = atomic_read(&call->sequence);
77335 + tx = atomic_read_unchecked(&call->sequence);
77336
77337 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77338 latest,
77339 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77340 goto maybe_reschedule;
77341
77342 send_ACK_with_skew:
77343 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77344 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77345 ntohl(ack.serial));
77346 send_ACK:
77347 mtu = call->conn->trans->peer->if_mtu;
77348 @@ -1173,7 +1173,7 @@ send_ACK:
77349 ackinfo.rxMTU = htonl(5692);
77350 ackinfo.jumbo_max = htonl(4);
77351
77352 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77353 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77354 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77355 ntohl(hdr.serial),
77356 ntohs(ack.maxSkew),
77357 @@ -1191,7 +1191,7 @@ send_ACK:
77358 send_message:
77359 _debug("send message");
77360
77361 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77362 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77363 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77364 send_message_2:
77365
77366 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77367 index bf656c2..48f9d27 100644
77368 --- a/net/rxrpc/ar-call.c
77369 +++ b/net/rxrpc/ar-call.c
77370 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77371 spin_lock_init(&call->lock);
77372 rwlock_init(&call->state_lock);
77373 atomic_set(&call->usage, 1);
77374 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77375 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77376 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77377
77378 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77379 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77380 index 4106ca9..a338d7a 100644
77381 --- a/net/rxrpc/ar-connection.c
77382 +++ b/net/rxrpc/ar-connection.c
77383 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77384 rwlock_init(&conn->lock);
77385 spin_lock_init(&conn->state_lock);
77386 atomic_set(&conn->usage, 1);
77387 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77388 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77389 conn->avail_calls = RXRPC_MAXCALLS;
77390 conn->size_align = 4;
77391 conn->header_size = sizeof(struct rxrpc_header);
77392 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77393 index e7ed43a..6afa140 100644
77394 --- a/net/rxrpc/ar-connevent.c
77395 +++ b/net/rxrpc/ar-connevent.c
77396 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77397
77398 len = iov[0].iov_len + iov[1].iov_len;
77399
77400 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77401 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77402 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77403
77404 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77405 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77406 index 1a2b0633..e8d1382 100644
77407 --- a/net/rxrpc/ar-input.c
77408 +++ b/net/rxrpc/ar-input.c
77409 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77410 /* track the latest serial number on this connection for ACK packet
77411 * information */
77412 serial = ntohl(sp->hdr.serial);
77413 - hi_serial = atomic_read(&call->conn->hi_serial);
77414 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77415 while (serial > hi_serial)
77416 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77417 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77418 serial);
77419
77420 /* request ACK generation for any ACK or DATA packet that requests
77421 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77422 index 8e22bd3..f66d1c0 100644
77423 --- a/net/rxrpc/ar-internal.h
77424 +++ b/net/rxrpc/ar-internal.h
77425 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77426 int error; /* error code for local abort */
77427 int debug_id; /* debug ID for printks */
77428 unsigned call_counter; /* call ID counter */
77429 - atomic_t serial; /* packet serial number counter */
77430 - atomic_t hi_serial; /* highest serial number received */
77431 + atomic_unchecked_t serial; /* packet serial number counter */
77432 + atomic_unchecked_t hi_serial; /* highest serial number received */
77433 u8 avail_calls; /* number of calls available */
77434 u8 size_align; /* data size alignment (for security) */
77435 u8 header_size; /* rxrpc + security header size */
77436 @@ -346,7 +346,7 @@ struct rxrpc_call {
77437 spinlock_t lock;
77438 rwlock_t state_lock; /* lock for state transition */
77439 atomic_t usage;
77440 - atomic_t sequence; /* Tx data packet sequence counter */
77441 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77442 u32 abort_code; /* local/remote abort code */
77443 enum { /* current state of call */
77444 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77445 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77446 */
77447 extern atomic_t rxrpc_n_skbs;
77448 extern __be32 rxrpc_epoch;
77449 -extern atomic_t rxrpc_debug_id;
77450 +extern atomic_unchecked_t rxrpc_debug_id;
77451 extern struct workqueue_struct *rxrpc_workqueue;
77452
77453 /*
77454 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77455 index 87f7135..74d3703 100644
77456 --- a/net/rxrpc/ar-local.c
77457 +++ b/net/rxrpc/ar-local.c
77458 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77459 spin_lock_init(&local->lock);
77460 rwlock_init(&local->services_lock);
77461 atomic_set(&local->usage, 1);
77462 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77463 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77464 memcpy(&local->srx, srx, sizeof(*srx));
77465 }
77466
77467 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77468 index 16ae887..d24f12b 100644
77469 --- a/net/rxrpc/ar-output.c
77470 +++ b/net/rxrpc/ar-output.c
77471 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77472 sp->hdr.cid = call->cid;
77473 sp->hdr.callNumber = call->call_id;
77474 sp->hdr.seq =
77475 - htonl(atomic_inc_return(&call->sequence));
77476 + htonl(atomic_inc_return_unchecked(&call->sequence));
77477 sp->hdr.serial =
77478 - htonl(atomic_inc_return(&conn->serial));
77479 + htonl(atomic_inc_return_unchecked(&conn->serial));
77480 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77481 sp->hdr.userStatus = 0;
77482 sp->hdr.securityIndex = conn->security_ix;
77483 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77484 index 2754f09..b20e38f 100644
77485 --- a/net/rxrpc/ar-peer.c
77486 +++ b/net/rxrpc/ar-peer.c
77487 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77488 INIT_LIST_HEAD(&peer->error_targets);
77489 spin_lock_init(&peer->lock);
77490 atomic_set(&peer->usage, 1);
77491 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77492 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77493 memcpy(&peer->srx, srx, sizeof(*srx));
77494
77495 rxrpc_assess_MTU_size(peer);
77496 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77497 index 38047f7..9f48511 100644
77498 --- a/net/rxrpc/ar-proc.c
77499 +++ b/net/rxrpc/ar-proc.c
77500 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77501 atomic_read(&conn->usage),
77502 rxrpc_conn_states[conn->state],
77503 key_serial(conn->key),
77504 - atomic_read(&conn->serial),
77505 - atomic_read(&conn->hi_serial));
77506 + atomic_read_unchecked(&conn->serial),
77507 + atomic_read_unchecked(&conn->hi_serial));
77508
77509 return 0;
77510 }
77511 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77512 index 92df566..87ec1bf 100644
77513 --- a/net/rxrpc/ar-transport.c
77514 +++ b/net/rxrpc/ar-transport.c
77515 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77516 spin_lock_init(&trans->client_lock);
77517 rwlock_init(&trans->conn_lock);
77518 atomic_set(&trans->usage, 1);
77519 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77520 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77521
77522 if (peer->srx.transport.family == AF_INET) {
77523 switch (peer->srx.transport_type) {
77524 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77525 index 7635107..4670276 100644
77526 --- a/net/rxrpc/rxkad.c
77527 +++ b/net/rxrpc/rxkad.c
77528 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77529
77530 len = iov[0].iov_len + iov[1].iov_len;
77531
77532 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77533 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77534 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77535
77536 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77537 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77538
77539 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77540
77541 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77542 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77543 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77544
77545 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77546 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77547 index 1e2eee8..ce3967e 100644
77548 --- a/net/sctp/proc.c
77549 +++ b/net/sctp/proc.c
77550 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77551 seq_printf(seq,
77552 "%8pK %8pK %-3d %-3d %-2d %-4d "
77553 "%4d %8d %8d %7d %5lu %-5d %5d ",
77554 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77555 + assoc, sk,
77556 + sctp_sk(sk)->type, sk->sk_state,
77557 assoc->state, hash,
77558 assoc->assoc_id,
77559 assoc->sndbuf_used,
77560 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77561 index 408ebd0..202aa85 100644
77562 --- a/net/sctp/socket.c
77563 +++ b/net/sctp/socket.c
77564 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77565 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77566 if (space_left < addrlen)
77567 return -ENOMEM;
77568 - if (copy_to_user(to, &temp, addrlen))
77569 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77570 return -EFAULT;
77571 to += addrlen;
77572 cnt++;
77573 diff --git a/net/socket.c b/net/socket.c
77574 index 28a96af..61a7a06 100644
77575 --- a/net/socket.c
77576 +++ b/net/socket.c
77577 @@ -88,6 +88,7 @@
77578 #include <linux/nsproxy.h>
77579 #include <linux/magic.h>
77580 #include <linux/slab.h>
77581 +#include <linux/in.h>
77582
77583 #include <asm/uaccess.h>
77584 #include <asm/unistd.h>
77585 @@ -105,6 +106,8 @@
77586 #include <linux/sockios.h>
77587 #include <linux/atalk.h>
77588
77589 +#include <linux/grsock.h>
77590 +
77591 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77592 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77593 unsigned long nr_segs, loff_t pos);
77594 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77595 &sockfs_dentry_operations, SOCKFS_MAGIC);
77596 }
77597
77598 -static struct vfsmount *sock_mnt __read_mostly;
77599 +struct vfsmount *sock_mnt __read_mostly;
77600
77601 static struct file_system_type sock_fs_type = {
77602 .name = "sockfs",
77603 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77604 return -EAFNOSUPPORT;
77605 if (type < 0 || type >= SOCK_MAX)
77606 return -EINVAL;
77607 + if (protocol < 0)
77608 + return -EINVAL;
77609
77610 /* Compatibility.
77611
77612 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77613 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77614 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77615
77616 + if(!gr_search_socket(family, type, protocol)) {
77617 + retval = -EACCES;
77618 + goto out;
77619 + }
77620 +
77621 + if (gr_handle_sock_all(family, type, protocol)) {
77622 + retval = -EACCES;
77623 + goto out;
77624 + }
77625 +
77626 retval = sock_create(family, type, protocol, &sock);
77627 if (retval < 0)
77628 goto out;
77629 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77630 if (sock) {
77631 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
77632 if (err >= 0) {
77633 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77634 + err = -EACCES;
77635 + goto error;
77636 + }
77637 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77638 + if (err)
77639 + goto error;
77640 +
77641 err = security_socket_bind(sock,
77642 (struct sockaddr *)&address,
77643 addrlen);
77644 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77645 (struct sockaddr *)
77646 &address, addrlen);
77647 }
77648 +error:
77649 fput_light(sock->file, fput_needed);
77650 }
77651 return err;
77652 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77653 if ((unsigned)backlog > somaxconn)
77654 backlog = somaxconn;
77655
77656 + if (gr_handle_sock_server_other(sock->sk)) {
77657 + err = -EPERM;
77658 + goto error;
77659 + }
77660 +
77661 + err = gr_search_listen(sock);
77662 + if (err)
77663 + goto error;
77664 +
77665 err = security_socket_listen(sock, backlog);
77666 if (!err)
77667 err = sock->ops->listen(sock, backlog);
77668
77669 +error:
77670 fput_light(sock->file, fput_needed);
77671 }
77672 return err;
77673 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77674 newsock->type = sock->type;
77675 newsock->ops = sock->ops;
77676
77677 + if (gr_handle_sock_server_other(sock->sk)) {
77678 + err = -EPERM;
77679 + sock_release(newsock);
77680 + goto out_put;
77681 + }
77682 +
77683 + err = gr_search_accept(sock);
77684 + if (err) {
77685 + sock_release(newsock);
77686 + goto out_put;
77687 + }
77688 +
77689 /*
77690 * We don't need try_module_get here, as the listening socket (sock)
77691 * has the protocol module (sock->ops->owner) held.
77692 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77693 fd_install(newfd, newfile);
77694 err = newfd;
77695
77696 + gr_attach_curr_ip(newsock->sk);
77697 +
77698 out_put:
77699 fput_light(sock->file, fput_needed);
77700 out:
77701 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77702 int, addrlen)
77703 {
77704 struct socket *sock;
77705 + struct sockaddr *sck;
77706 struct sockaddr_storage address;
77707 int err, fput_needed;
77708
77709 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77710 if (err < 0)
77711 goto out_put;
77712
77713 + sck = (struct sockaddr *)&address;
77714 +
77715 + if (gr_handle_sock_client(sck)) {
77716 + err = -EACCES;
77717 + goto out_put;
77718 + }
77719 +
77720 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77721 + if (err)
77722 + goto out_put;
77723 +
77724 err =
77725 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77726 if (err)
77727 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77728 * checking falls down on this.
77729 */
77730 if (copy_from_user(ctl_buf,
77731 - (void __user __force *)msg_sys->msg_control,
77732 + (void __force_user *)msg_sys->msg_control,
77733 ctl_len))
77734 goto out_freectl;
77735 msg_sys->msg_control = ctl_buf;
77736 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77737 * kernel msghdr to use the kernel address space)
77738 */
77739
77740 - uaddr = (__force void __user *)msg_sys->msg_name;
77741 + uaddr = (void __force_user *)msg_sys->msg_name;
77742 uaddr_len = COMPAT_NAMELEN(msg);
77743 if (MSG_CMSG_COMPAT & flags) {
77744 err = verify_compat_iovec(msg_sys, iov,
77745 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77746 }
77747
77748 ifr = compat_alloc_user_space(buf_size);
77749 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77750 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77751
77752 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77753 return -EFAULT;
77754 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77755 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77756
77757 if (copy_in_user(rxnfc, compat_rxnfc,
77758 - (void *)(&rxnfc->fs.m_ext + 1) -
77759 - (void *)rxnfc) ||
77760 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77761 + (void __user *)rxnfc) ||
77762 copy_in_user(&rxnfc->fs.ring_cookie,
77763 &compat_rxnfc->fs.ring_cookie,
77764 - (void *)(&rxnfc->fs.location + 1) -
77765 - (void *)&rxnfc->fs.ring_cookie) ||
77766 + (void __user *)(&rxnfc->fs.location + 1) -
77767 + (void __user *)&rxnfc->fs.ring_cookie) ||
77768 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77769 sizeof(rxnfc->rule_cnt)))
77770 return -EFAULT;
77771 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77772
77773 if (convert_out) {
77774 if (copy_in_user(compat_rxnfc, rxnfc,
77775 - (const void *)(&rxnfc->fs.m_ext + 1) -
77776 - (const void *)rxnfc) ||
77777 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77778 + (const void __user *)rxnfc) ||
77779 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77780 &rxnfc->fs.ring_cookie,
77781 - (const void *)(&rxnfc->fs.location + 1) -
77782 - (const void *)&rxnfc->fs.ring_cookie) ||
77783 + (const void __user *)(&rxnfc->fs.location + 1) -
77784 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77785 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77786 sizeof(rxnfc->rule_cnt)))
77787 return -EFAULT;
77788 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77789 old_fs = get_fs();
77790 set_fs(KERNEL_DS);
77791 err = dev_ioctl(net, cmd,
77792 - (struct ifreq __user __force *) &kifr);
77793 + (struct ifreq __force_user *) &kifr);
77794 set_fs(old_fs);
77795
77796 return err;
77797 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77798
77799 old_fs = get_fs();
77800 set_fs(KERNEL_DS);
77801 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77802 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77803 set_fs(old_fs);
77804
77805 if (cmd == SIOCGIFMAP && !err) {
77806 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77807 ret |= __get_user(rtdev, &(ur4->rt_dev));
77808 if (rtdev) {
77809 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77810 - r4.rt_dev = (char __user __force *)devname;
77811 + r4.rt_dev = (char __force_user *)devname;
77812 devname[15] = 0;
77813 } else
77814 r4.rt_dev = NULL;
77815 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77816 int __user *uoptlen;
77817 int err;
77818
77819 - uoptval = (char __user __force *) optval;
77820 - uoptlen = (int __user __force *) optlen;
77821 + uoptval = (char __force_user *) optval;
77822 + uoptlen = (int __force_user *) optlen;
77823
77824 set_fs(KERNEL_DS);
77825 if (level == SOL_SOCKET)
77826 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77827 char __user *uoptval;
77828 int err;
77829
77830 - uoptval = (char __user __force *) optval;
77831 + uoptval = (char __force_user *) optval;
77832
77833 set_fs(KERNEL_DS);
77834 if (level == SOL_SOCKET)
77835 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77836 index 8efd96c..b492ab2 100644
77837 --- a/net/sunrpc/sched.c
77838 +++ b/net/sunrpc/sched.c
77839 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
77840 #ifdef RPC_DEBUG
77841 static void rpc_task_set_debuginfo(struct rpc_task *task)
77842 {
77843 - static atomic_t rpc_pid;
77844 + static atomic_unchecked_t rpc_pid;
77845
77846 - task->tk_pid = atomic_inc_return(&rpc_pid);
77847 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77848 }
77849 #else
77850 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77851 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77852 index 4645709..d41d668 100644
77853 --- a/net/sunrpc/svcsock.c
77854 +++ b/net/sunrpc/svcsock.c
77855 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77856 int buflen, unsigned int base)
77857 {
77858 size_t save_iovlen;
77859 - void __user *save_iovbase;
77860 + void *save_iovbase;
77861 unsigned int i;
77862 int ret;
77863
77864 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77865 index 09af4fa..77110a9 100644
77866 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77867 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77868 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77869 static unsigned int min_max_inline = 4096;
77870 static unsigned int max_max_inline = 65536;
77871
77872 -atomic_t rdma_stat_recv;
77873 -atomic_t rdma_stat_read;
77874 -atomic_t rdma_stat_write;
77875 -atomic_t rdma_stat_sq_starve;
77876 -atomic_t rdma_stat_rq_starve;
77877 -atomic_t rdma_stat_rq_poll;
77878 -atomic_t rdma_stat_rq_prod;
77879 -atomic_t rdma_stat_sq_poll;
77880 -atomic_t rdma_stat_sq_prod;
77881 +atomic_unchecked_t rdma_stat_recv;
77882 +atomic_unchecked_t rdma_stat_read;
77883 +atomic_unchecked_t rdma_stat_write;
77884 +atomic_unchecked_t rdma_stat_sq_starve;
77885 +atomic_unchecked_t rdma_stat_rq_starve;
77886 +atomic_unchecked_t rdma_stat_rq_poll;
77887 +atomic_unchecked_t rdma_stat_rq_prod;
77888 +atomic_unchecked_t rdma_stat_sq_poll;
77889 +atomic_unchecked_t rdma_stat_sq_prod;
77890
77891 /* Temporary NFS request map and context caches */
77892 struct kmem_cache *svc_rdma_map_cachep;
77893 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
77894 len -= *ppos;
77895 if (len > *lenp)
77896 len = *lenp;
77897 - if (len && copy_to_user(buffer, str_buf, len))
77898 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77899 return -EFAULT;
77900 *lenp = len;
77901 *ppos += len;
77902 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
77903 {
77904 .procname = "rdma_stat_read",
77905 .data = &rdma_stat_read,
77906 - .maxlen = sizeof(atomic_t),
77907 + .maxlen = sizeof(atomic_unchecked_t),
77908 .mode = 0644,
77909 .proc_handler = read_reset_stat,
77910 },
77911 {
77912 .procname = "rdma_stat_recv",
77913 .data = &rdma_stat_recv,
77914 - .maxlen = sizeof(atomic_t),
77915 + .maxlen = sizeof(atomic_unchecked_t),
77916 .mode = 0644,
77917 .proc_handler = read_reset_stat,
77918 },
77919 {
77920 .procname = "rdma_stat_write",
77921 .data = &rdma_stat_write,
77922 - .maxlen = sizeof(atomic_t),
77923 + .maxlen = sizeof(atomic_unchecked_t),
77924 .mode = 0644,
77925 .proc_handler = read_reset_stat,
77926 },
77927 {
77928 .procname = "rdma_stat_sq_starve",
77929 .data = &rdma_stat_sq_starve,
77930 - .maxlen = sizeof(atomic_t),
77931 + .maxlen = sizeof(atomic_unchecked_t),
77932 .mode = 0644,
77933 .proc_handler = read_reset_stat,
77934 },
77935 {
77936 .procname = "rdma_stat_rq_starve",
77937 .data = &rdma_stat_rq_starve,
77938 - .maxlen = sizeof(atomic_t),
77939 + .maxlen = sizeof(atomic_unchecked_t),
77940 .mode = 0644,
77941 .proc_handler = read_reset_stat,
77942 },
77943 {
77944 .procname = "rdma_stat_rq_poll",
77945 .data = &rdma_stat_rq_poll,
77946 - .maxlen = sizeof(atomic_t),
77947 + .maxlen = sizeof(atomic_unchecked_t),
77948 .mode = 0644,
77949 .proc_handler = read_reset_stat,
77950 },
77951 {
77952 .procname = "rdma_stat_rq_prod",
77953 .data = &rdma_stat_rq_prod,
77954 - .maxlen = sizeof(atomic_t),
77955 + .maxlen = sizeof(atomic_unchecked_t),
77956 .mode = 0644,
77957 .proc_handler = read_reset_stat,
77958 },
77959 {
77960 .procname = "rdma_stat_sq_poll",
77961 .data = &rdma_stat_sq_poll,
77962 - .maxlen = sizeof(atomic_t),
77963 + .maxlen = sizeof(atomic_unchecked_t),
77964 .mode = 0644,
77965 .proc_handler = read_reset_stat,
77966 },
77967 {
77968 .procname = "rdma_stat_sq_prod",
77969 .data = &rdma_stat_sq_prod,
77970 - .maxlen = sizeof(atomic_t),
77971 + .maxlen = sizeof(atomic_unchecked_t),
77972 .mode = 0644,
77973 .proc_handler = read_reset_stat,
77974 },
77975 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77976 index df67211..c354b13 100644
77977 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77978 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77979 @@ -499,7 +499,7 @@ next_sge:
77980 svc_rdma_put_context(ctxt, 0);
77981 goto out;
77982 }
77983 - atomic_inc(&rdma_stat_read);
77984 + atomic_inc_unchecked(&rdma_stat_read);
77985
77986 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77987 chl_map->ch[ch_no].count -= read_wr.num_sge;
77988 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77989 dto_q);
77990 list_del_init(&ctxt->dto_q);
77991 } else {
77992 - atomic_inc(&rdma_stat_rq_starve);
77993 + atomic_inc_unchecked(&rdma_stat_rq_starve);
77994 clear_bit(XPT_DATA, &xprt->xpt_flags);
77995 ctxt = NULL;
77996 }
77997 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77998 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
77999 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78000 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78001 - atomic_inc(&rdma_stat_recv);
78002 + atomic_inc_unchecked(&rdma_stat_recv);
78003
78004 /* Build up the XDR from the receive buffers. */
78005 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78006 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78007 index 249a835..fb2794b 100644
78008 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78009 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78010 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78011 write_wr.wr.rdma.remote_addr = to;
78012
78013 /* Post It */
78014 - atomic_inc(&rdma_stat_write);
78015 + atomic_inc_unchecked(&rdma_stat_write);
78016 if (svc_rdma_send(xprt, &write_wr))
78017 goto err;
78018 return 0;
78019 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78020 index 894cb42..cf5bafb 100644
78021 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78022 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78023 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78024 return;
78025
78026 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78027 - atomic_inc(&rdma_stat_rq_poll);
78028 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78029
78030 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78031 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78032 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78033 }
78034
78035 if (ctxt)
78036 - atomic_inc(&rdma_stat_rq_prod);
78037 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78038
78039 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78040 /*
78041 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78042 return;
78043
78044 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78045 - atomic_inc(&rdma_stat_sq_poll);
78046 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78047 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78048 if (wc.status != IB_WC_SUCCESS)
78049 /* Close the transport */
78050 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78051 }
78052
78053 if (ctxt)
78054 - atomic_inc(&rdma_stat_sq_prod);
78055 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78056 }
78057
78058 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78059 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78060 spin_lock_bh(&xprt->sc_lock);
78061 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78062 spin_unlock_bh(&xprt->sc_lock);
78063 - atomic_inc(&rdma_stat_sq_starve);
78064 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78065
78066 /* See if we can opportunistically reap SQ WR to make room */
78067 sq_cq_reap(xprt);
78068 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78069 index e758139..d29ea47 100644
78070 --- a/net/sysctl_net.c
78071 +++ b/net/sysctl_net.c
78072 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78073 struct ctl_table *table)
78074 {
78075 /* Allow network administrator to have same access as root. */
78076 - if (capable(CAP_NET_ADMIN)) {
78077 + if (capable_nolog(CAP_NET_ADMIN)) {
78078 int mode = (table->mode >> 6) & 7;
78079 return (mode << 6) | (mode << 3) | mode;
78080 }
78081 diff --git a/net/tipc/link.c b/net/tipc/link.c
78082 index ac1832a..533ed97 100644
78083 --- a/net/tipc/link.c
78084 +++ b/net/tipc/link.c
78085 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78086 struct tipc_msg fragm_hdr;
78087 struct sk_buff *buf, *buf_chain, *prev;
78088 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78089 - const unchar *sect_crs;
78090 + const unchar __user *sect_crs;
78091 int curr_sect;
78092 u32 fragm_no;
78093
78094 @@ -1249,7 +1249,7 @@ again:
78095
78096 if (!sect_rest) {
78097 sect_rest = msg_sect[++curr_sect].iov_len;
78098 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78099 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78100 }
78101
78102 if (sect_rest < fragm_rest)
78103 @@ -1268,7 +1268,7 @@ error:
78104 }
78105 } else
78106 skb_copy_to_linear_data_offset(buf, fragm_crs,
78107 - sect_crs, sz);
78108 + (const void __force_kernel *)sect_crs, sz);
78109 sect_crs += sz;
78110 sect_rest -= sz;
78111 fragm_crs += sz;
78112 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78113 index 3e4d3e2..27b55dc 100644
78114 --- a/net/tipc/msg.c
78115 +++ b/net/tipc/msg.c
78116 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78117 msg_sect[cnt].iov_len);
78118 else
78119 skb_copy_to_linear_data_offset(*buf, pos,
78120 - msg_sect[cnt].iov_base,
78121 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78122 msg_sect[cnt].iov_len);
78123 pos += msg_sect[cnt].iov_len;
78124 }
78125 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78126 index 8c49566..14510cb 100644
78127 --- a/net/tipc/subscr.c
78128 +++ b/net/tipc/subscr.c
78129 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78130 {
78131 struct iovec msg_sect;
78132
78133 - msg_sect.iov_base = (void *)&sub->evt;
78134 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78135 msg_sect.iov_len = sizeof(struct tipc_event);
78136
78137 sub->evt.event = htohl(event, sub->swap);
78138 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78139 index 85d3bb7..79f4487 100644
78140 --- a/net/unix/af_unix.c
78141 +++ b/net/unix/af_unix.c
78142 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78143 err = -ECONNREFUSED;
78144 if (!S_ISSOCK(inode->i_mode))
78145 goto put_fail;
78146 +
78147 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78148 + err = -EACCES;
78149 + goto put_fail;
78150 + }
78151 +
78152 u = unix_find_socket_byinode(inode);
78153 if (!u)
78154 goto put_fail;
78155 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78156 if (u) {
78157 struct dentry *dentry;
78158 dentry = unix_sk(u)->dentry;
78159 +
78160 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78161 + err = -EPERM;
78162 + sock_put(u);
78163 + goto fail;
78164 + }
78165 +
78166 if (dentry)
78167 touch_atime(unix_sk(u)->mnt, dentry);
78168 } else
78169 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78170 err = security_path_mknod(&path, dentry, mode, 0);
78171 if (err)
78172 goto out_mknod_drop_write;
78173 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78174 + err = -EACCES;
78175 + goto out_mknod_drop_write;
78176 + }
78177 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78178 out_mknod_drop_write:
78179 mnt_drop_write(path.mnt);
78180 if (err)
78181 goto out_mknod_dput;
78182 +
78183 + gr_handle_create(dentry, path.mnt);
78184 +
78185 mutex_unlock(&path.dentry->d_inode->i_mutex);
78186 dput(path.dentry);
78187 path.dentry = dentry;
78188 diff --git a/net/wireless/core.h b/net/wireless/core.h
78189 index 43ad9c8..ab5127c 100644
78190 --- a/net/wireless/core.h
78191 +++ b/net/wireless/core.h
78192 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78193 struct mutex mtx;
78194
78195 /* rfkill support */
78196 - struct rfkill_ops rfkill_ops;
78197 + rfkill_ops_no_const rfkill_ops;
78198 struct rfkill *rfkill;
78199 struct work_struct rfkill_sync;
78200
78201 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78202 index 0af7f54..c916d2f 100644
78203 --- a/net/wireless/wext-core.c
78204 +++ b/net/wireless/wext-core.c
78205 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78206 */
78207
78208 /* Support for very large requests */
78209 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78210 - (user_length > descr->max_tokens)) {
78211 + if (user_length > descr->max_tokens) {
78212 /* Allow userspace to GET more than max so
78213 * we can support any size GET requests.
78214 * There is still a limit : -ENOMEM.
78215 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78216 }
78217 }
78218
78219 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78220 - /*
78221 - * If this is a GET, but not NOMAX, it means that the extra
78222 - * data is not bounded by userspace, but by max_tokens. Thus
78223 - * set the length to max_tokens. This matches the extra data
78224 - * allocation.
78225 - * The driver should fill it with the number of tokens it
78226 - * provided, and it may check iwp->length rather than having
78227 - * knowledge of max_tokens. If the driver doesn't change the
78228 - * iwp->length, this ioctl just copies back max_token tokens
78229 - * filled with zeroes. Hopefully the driver isn't claiming
78230 - * them to be valid data.
78231 - */
78232 - iwp->length = descr->max_tokens;
78233 - }
78234 -
78235 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78236
78237 iwp->length += essid_compat;
78238 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78239 index 7661576..80f7627 100644
78240 --- a/net/xfrm/xfrm_policy.c
78241 +++ b/net/xfrm/xfrm_policy.c
78242 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78243 {
78244 policy->walk.dead = 1;
78245
78246 - atomic_inc(&policy->genid);
78247 + atomic_inc_unchecked(&policy->genid);
78248
78249 if (del_timer(&policy->timer))
78250 xfrm_pol_put(policy);
78251 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78252 hlist_add_head(&policy->bydst, chain);
78253 xfrm_pol_hold(policy);
78254 net->xfrm.policy_count[dir]++;
78255 - atomic_inc(&flow_cache_genid);
78256 + atomic_inc_unchecked(&flow_cache_genid);
78257 if (delpol)
78258 __xfrm_policy_unlink(delpol, dir);
78259 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78260 @@ -1530,7 +1530,7 @@ free_dst:
78261 goto out;
78262 }
78263
78264 -static int inline
78265 +static inline int
78266 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78267 {
78268 if (!*target) {
78269 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78270 return 0;
78271 }
78272
78273 -static int inline
78274 +static inline int
78275 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78276 {
78277 #ifdef CONFIG_XFRM_SUB_POLICY
78278 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78279 #endif
78280 }
78281
78282 -static int inline
78283 +static inline int
78284 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78285 {
78286 #ifdef CONFIG_XFRM_SUB_POLICY
78287 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78288
78289 xdst->num_pols = num_pols;
78290 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78291 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78292 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78293
78294 return xdst;
78295 }
78296 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78297 if (xdst->xfrm_genid != dst->xfrm->genid)
78298 return 0;
78299 if (xdst->num_pols > 0 &&
78300 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78301 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78302 return 0;
78303
78304 mtu = dst_mtu(dst->child);
78305 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78306 sizeof(pol->xfrm_vec[i].saddr));
78307 pol->xfrm_vec[i].encap_family = mp->new_family;
78308 /* flush bundles */
78309 - atomic_inc(&pol->genid);
78310 + atomic_inc_unchecked(&pol->genid);
78311 }
78312 }
78313
78314 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78315 index d2b366c..51ff91ebc 100644
78316 --- a/scripts/Makefile.build
78317 +++ b/scripts/Makefile.build
78318 @@ -109,7 +109,7 @@ endif
78319 endif
78320
78321 # Do not include host rules unless needed
78322 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78323 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78324 include scripts/Makefile.host
78325 endif
78326
78327 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78328 index 686cb0d..9d653bf 100644
78329 --- a/scripts/Makefile.clean
78330 +++ b/scripts/Makefile.clean
78331 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78332 __clean-files := $(extra-y) $(always) \
78333 $(targets) $(clean-files) \
78334 $(host-progs) \
78335 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78336 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78337 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78338
78339 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78340
78341 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78342 index 1ac414f..a1c1451 100644
78343 --- a/scripts/Makefile.host
78344 +++ b/scripts/Makefile.host
78345 @@ -31,6 +31,7 @@
78346 # Note: Shared libraries consisting of C++ files are not supported
78347
78348 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78349 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78350
78351 # C code
78352 # Executables compiled from a single .c file
78353 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78354 # Shared libaries (only .c supported)
78355 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78356 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78357 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78358 # Remove .so files from "xxx-objs"
78359 host-cobjs := $(filter-out %.so,$(host-cobjs))
78360
78361 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78362 index cb1f50c..cef2a7c 100644
78363 --- a/scripts/basic/fixdep.c
78364 +++ b/scripts/basic/fixdep.c
78365 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78366 /*
78367 * Lookup a value in the configuration string.
78368 */
78369 -static int is_defined_config(const char *name, int len, unsigned int hash)
78370 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78371 {
78372 struct item *aux;
78373
78374 @@ -211,10 +211,10 @@ static void clear_config(void)
78375 /*
78376 * Record the use of a CONFIG_* word.
78377 */
78378 -static void use_config(const char *m, int slen)
78379 +static void use_config(const char *m, unsigned int slen)
78380 {
78381 unsigned int hash = strhash(m, slen);
78382 - int c, i;
78383 + unsigned int c, i;
78384
78385 if (is_defined_config(m, slen, hash))
78386 return;
78387 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78388
78389 static void parse_config_file(const char *map, size_t len)
78390 {
78391 - const int *end = (const int *) (map + len);
78392 + const unsigned int *end = (const unsigned int *) (map + len);
78393 /* start at +1, so that p can never be < map */
78394 - const int *m = (const int *) map + 1;
78395 + const unsigned int *m = (const unsigned int *) map + 1;
78396 const char *p, *q;
78397
78398 for (; m < end; m++) {
78399 @@ -406,7 +406,7 @@ static void print_deps(void)
78400 static void traps(void)
78401 {
78402 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78403 - int *p = (int *)test;
78404 + unsigned int *p = (unsigned int *)test;
78405
78406 if (*p != INT_CONF) {
78407 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78408 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78409 new file mode 100644
78410 index 0000000..8729101
78411 --- /dev/null
78412 +++ b/scripts/gcc-plugin.sh
78413 @@ -0,0 +1,2 @@
78414 +#!/bin/sh
78415 +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"
78416 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78417 index b89efe6..2c30808 100644
78418 --- a/scripts/mod/file2alias.c
78419 +++ b/scripts/mod/file2alias.c
78420 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78421 unsigned long size, unsigned long id_size,
78422 void *symval)
78423 {
78424 - int i;
78425 + unsigned int i;
78426
78427 if (size % id_size || size < id_size) {
78428 if (cross_build != 0)
78429 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78430 /* USB is special because the bcdDevice can be matched against a numeric range */
78431 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78432 static void do_usb_entry(struct usb_device_id *id,
78433 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78434 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78435 unsigned char range_lo, unsigned char range_hi,
78436 unsigned char max, struct module *mod)
78437 {
78438 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78439 {
78440 unsigned int devlo, devhi;
78441 unsigned char chi, clo, max;
78442 - int ndigits;
78443 + unsigned int ndigits;
78444
78445 id->match_flags = TO_NATIVE(id->match_flags);
78446 id->idVendor = TO_NATIVE(id->idVendor);
78447 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78448 for (i = 0; i < count; i++) {
78449 const char *id = (char *)devs[i].id;
78450 char acpi_id[sizeof(devs[0].id)];
78451 - int j;
78452 + unsigned int j;
78453
78454 buf_printf(&mod->dev_table_buf,
78455 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78456 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78457
78458 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78459 const char *id = (char *)card->devs[j].id;
78460 - int i2, j2;
78461 + unsigned int i2, j2;
78462 int dup = 0;
78463
78464 if (!id[0])
78465 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78466 /* add an individual alias for every device entry */
78467 if (!dup) {
78468 char acpi_id[sizeof(card->devs[0].id)];
78469 - int k;
78470 + unsigned int k;
78471
78472 buf_printf(&mod->dev_table_buf,
78473 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78474 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78475 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78476 char *alias)
78477 {
78478 - int i, j;
78479 + unsigned int i, j;
78480
78481 sprintf(alias, "dmi*");
78482
78483 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78484 index 9adb667..dda7076 100644
78485 --- a/scripts/mod/modpost.c
78486 +++ b/scripts/mod/modpost.c
78487 @@ -849,7 +849,7 @@ static void check_section(const char *modname, struct elf_info *elf,
78488
78489 #define ALL_INIT_DATA_SECTIONS \
78490 ".init.setup$", ".init.rodata$", \
78491 - ".devinit.rodata$", ".cpuinit.rodata$", ".meminit.rodata$" \
78492 + ".devinit.rodata$", ".cpuinit.rodata$", ".meminit.rodata$", \
78493 ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$"
78494 #define ALL_EXIT_DATA_SECTIONS \
78495 ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$"
78496 @@ -919,6 +919,7 @@ enum mismatch {
78497 ANY_INIT_TO_ANY_EXIT,
78498 ANY_EXIT_TO_ANY_INIT,
78499 EXPORT_TO_INIT_EXIT,
78500 + DATA_TO_TEXT
78501 };
78502
78503 struct sectioncheck {
78504 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
78505 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78506 .mismatch = EXPORT_TO_INIT_EXIT,
78507 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78508 +},
78509 +/* Do not reference code from writable data */
78510 +{
78511 + .fromsec = { DATA_SECTIONS, NULL },
78512 + .tosec = { TEXT_SECTIONS, NULL },
78513 + .mismatch = DATA_TO_TEXT
78514 }
78515 };
78516
78517 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78518 continue;
78519 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78520 continue;
78521 - if (sym->st_value == addr)
78522 - return sym;
78523 /* Find a symbol nearby - addr are maybe negative */
78524 d = sym->st_value - addr;
78525 + if (d == 0)
78526 + return sym;
78527 if (d < 0)
78528 d = addr - sym->st_value;
78529 if (d < distance) {
78530 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
78531 tosym, prl_to, prl_to, tosym);
78532 free(prl_to);
78533 break;
78534 + case DATA_TO_TEXT:
78535 +/*
78536 + fprintf(stderr,
78537 + "The variable %s references\n"
78538 + "the %s %s%s%s\n",
78539 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78540 +*/
78541 + break;
78542 }
78543 fprintf(stderr, "\n");
78544 }
78545 @@ -1665,7 +1680,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78546 static void check_sec_ref(struct module *mod, const char *modname,
78547 struct elf_info *elf)
78548 {
78549 - int i;
78550 + unsigned int i;
78551 Elf_Shdr *sechdrs = elf->sechdrs;
78552
78553 /* Walk through all sections */
78554 @@ -1763,7 +1778,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78555 va_end(ap);
78556 }
78557
78558 -void buf_write(struct buffer *buf, const char *s, int len)
78559 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78560 {
78561 if (buf->size - buf->pos < len) {
78562 buf->size += len + SZ;
78563 @@ -1981,7 +1996,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78564 if (fstat(fileno(file), &st) < 0)
78565 goto close_write;
78566
78567 - if (st.st_size != b->pos)
78568 + if (st.st_size != (off_t)b->pos)
78569 goto close_write;
78570
78571 tmp = NOFAIL(malloc(b->pos));
78572 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78573 index 2031119..b5433af 100644
78574 --- a/scripts/mod/modpost.h
78575 +++ b/scripts/mod/modpost.h
78576 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78577
78578 struct buffer {
78579 char *p;
78580 - int pos;
78581 - int size;
78582 + unsigned int pos;
78583 + unsigned int size;
78584 };
78585
78586 void __attribute__((format(printf, 2, 3)))
78587 buf_printf(struct buffer *buf, const char *fmt, ...);
78588
78589 void
78590 -buf_write(struct buffer *buf, const char *s, int len);
78591 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78592
78593 struct module {
78594 struct module *next;
78595 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78596 index 9dfcd6d..099068e 100644
78597 --- a/scripts/mod/sumversion.c
78598 +++ b/scripts/mod/sumversion.c
78599 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78600 goto out;
78601 }
78602
78603 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78604 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78605 warn("writing sum in %s failed: %s\n",
78606 filename, strerror(errno));
78607 goto out;
78608 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78609 index 5c11312..72742b5 100644
78610 --- a/scripts/pnmtologo.c
78611 +++ b/scripts/pnmtologo.c
78612 @@ -237,14 +237,14 @@ static void write_header(void)
78613 fprintf(out, " * Linux logo %s\n", logoname);
78614 fputs(" */\n\n", out);
78615 fputs("#include <linux/linux_logo.h>\n\n", out);
78616 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78617 + fprintf(out, "static unsigned char %s_data[] = {\n",
78618 logoname);
78619 }
78620
78621 static void write_footer(void)
78622 {
78623 fputs("\n};\n\n", out);
78624 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78625 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78626 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78627 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78628 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78629 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78630 fputs("\n};\n\n", out);
78631
78632 /* write logo clut */
78633 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78634 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78635 logoname);
78636 write_hex_cnt = 0;
78637 for (i = 0; i < logo_clutsize; i++) {
78638 diff --git a/scripts/tags.sh b/scripts/tags.sh
78639 index 833813a..0bc8588 100755
78640 --- a/scripts/tags.sh
78641 +++ b/scripts/tags.sh
78642 @@ -116,7 +116,7 @@ docscope()
78643
78644 dogtags()
78645 {
78646 - all_sources | gtags -f -
78647 + all_sources | gtags -i -f -
78648 }
78649
78650 exuberant()
78651 diff --git a/security/Kconfig b/security/Kconfig
78652 index 51bd5a0..c37f5e6 100644
78653 --- a/security/Kconfig
78654 +++ b/security/Kconfig
78655 @@ -4,6 +4,640 @@
78656
78657 menu "Security options"
78658
78659 +source grsecurity/Kconfig
78660 +
78661 +menu "PaX"
78662 +
78663 + config ARCH_TRACK_EXEC_LIMIT
78664 + bool
78665 +
78666 + config PAX_KERNEXEC_PLUGIN
78667 + bool
78668 +
78669 + config PAX_PER_CPU_PGD
78670 + bool
78671 +
78672 + config TASK_SIZE_MAX_SHIFT
78673 + int
78674 + depends on X86_64
78675 + default 47 if !PAX_PER_CPU_PGD
78676 + default 42 if PAX_PER_CPU_PGD
78677 +
78678 + config PAX_ENABLE_PAE
78679 + bool
78680 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78681 +
78682 +config PAX
78683 + bool "Enable various PaX features"
78684 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78685 + help
78686 + This allows you to enable various PaX features. PaX adds
78687 + intrusion prevention mechanisms to the kernel that reduce
78688 + the risks posed by exploitable memory corruption bugs.
78689 +
78690 +menu "PaX Control"
78691 + depends on PAX
78692 +
78693 +config PAX_SOFTMODE
78694 + bool 'Support soft mode'
78695 + help
78696 + Enabling this option will allow you to run PaX in soft mode, that
78697 + is, PaX features will not be enforced by default, only on executables
78698 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78699 + support as they are the only way to mark executables for soft mode use.
78700 +
78701 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78702 + line option on boot. Furthermore you can control various PaX features
78703 + at runtime via the entries in /proc/sys/kernel/pax.
78704 +
78705 +config PAX_EI_PAX
78706 + bool 'Use legacy ELF header marking'
78707 + help
78708 + Enabling this option will allow you to control PaX features on
78709 + a per executable basis via the 'chpax' utility available at
78710 + http://pax.grsecurity.net/. The control flags will be read from
78711 + an otherwise reserved part of the ELF header. This marking has
78712 + numerous drawbacks (no support for soft-mode, toolchain does not
78713 + know about the non-standard use of the ELF header) therefore it
78714 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78715 + support.
78716 +
78717 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78718 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78719 + option otherwise they will not get any protection.
78720 +
78721 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78722 + support as well, they will override the legacy EI_PAX marks.
78723 +
78724 +config PAX_PT_PAX_FLAGS
78725 + bool 'Use ELF program header marking'
78726 + help
78727 + Enabling this option will allow you to control PaX features on
78728 + a per executable basis via the 'paxctl' utility available at
78729 + http://pax.grsecurity.net/. The control flags will be read from
78730 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78731 + has the benefits of supporting both soft mode and being fully
78732 + integrated into the toolchain (the binutils patch is available
78733 + from http://pax.grsecurity.net).
78734 +
78735 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78736 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78737 + support otherwise they will not get any protection.
78738 +
78739 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78740 + must make sure that the marks are the same if a binary has both marks.
78741 +
78742 + Note that if you enable the legacy EI_PAX marking support as well,
78743 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78744 +
78745 +config PAX_XATTR_PAX_FLAGS
78746 + bool 'Use filesystem extended attributes marking'
78747 + select CIFS_XATTR if CIFS
78748 + select EXT2_FS_XATTR if EXT2_FS
78749 + select EXT3_FS_XATTR if EXT3_FS
78750 + select EXT4_FS_XATTR if EXT4_FS
78751 + select JFFS2_FS_XATTR if JFFS2_FS
78752 + select REISERFS_FS_XATTR if REISERFS_FS
78753 + select SQUASHFS_XATTR if SQUASHFS
78754 + select TMPFS_XATTR if TMPFS
78755 + select UBIFS_FS_XATTR if UBIFS_FS
78756 + help
78757 + Enabling this option will allow you to control PaX features on
78758 + a per executable basis via the 'setfattr' utility. The control
78759 + flags will be read from the user.pax.flags extended attribute of
78760 + the file. This marking has the benefit of supporting binary-only
78761 + applications that self-check themselves (e.g., skype) and would
78762 + not tolerate chpax/paxctl changes. The main drawback is that
78763 + extended attributes are not supported by some filesystems (e.g.,
78764 + isofs, udf, vfat) so copying files through such filesystems will
78765 + lose the extended attributes and these PaX markings.
78766 +
78767 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78768 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78769 + support otherwise they will not get any protection.
78770 +
78771 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78772 + must make sure that the marks are the same if a binary has both marks.
78773 +
78774 + Note that if you enable the legacy EI_PAX marking support as well,
78775 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78776 +
78777 +choice
78778 + prompt 'MAC system integration'
78779 + default PAX_HAVE_ACL_FLAGS
78780 + help
78781 + Mandatory Access Control systems have the option of controlling
78782 + PaX flags on a per executable basis, choose the method supported
78783 + by your particular system.
78784 +
78785 + - "none": if your MAC system does not interact with PaX,
78786 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78787 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78788 +
78789 + NOTE: this option is for developers/integrators only.
78790 +
78791 + config PAX_NO_ACL_FLAGS
78792 + bool 'none'
78793 +
78794 + config PAX_HAVE_ACL_FLAGS
78795 + bool 'direct'
78796 +
78797 + config PAX_HOOK_ACL_FLAGS
78798 + bool 'hook'
78799 +endchoice
78800 +
78801 +endmenu
78802 +
78803 +menu "Non-executable pages"
78804 + depends on PAX
78805 +
78806 +config PAX_NOEXEC
78807 + bool "Enforce non-executable pages"
78808 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78809 + help
78810 + By design some architectures do not allow for protecting memory
78811 + pages against execution or even if they do, Linux does not make
78812 + use of this feature. In practice this means that if a page is
78813 + readable (such as the stack or heap) it is also executable.
78814 +
78815 + There is a well known exploit technique that makes use of this
78816 + fact and a common programming mistake where an attacker can
78817 + introduce code of his choice somewhere in the attacked program's
78818 + memory (typically the stack or the heap) and then execute it.
78819 +
78820 + If the attacked program was running with different (typically
78821 + higher) privileges than that of the attacker, then he can elevate
78822 + his own privilege level (e.g. get a root shell, write to files for
78823 + which he does not have write access to, etc).
78824 +
78825 + Enabling this option will let you choose from various features
78826 + that prevent the injection and execution of 'foreign' code in
78827 + a program.
78828 +
78829 + This will also break programs that rely on the old behaviour and
78830 + expect that dynamically allocated memory via the malloc() family
78831 + of functions is executable (which it is not). Notable examples
78832 + are the XFree86 4.x server, the java runtime and wine.
78833 +
78834 +config PAX_PAGEEXEC
78835 + bool "Paging based non-executable pages"
78836 + 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)
78837 + select S390_SWITCH_AMODE if S390
78838 + select S390_EXEC_PROTECT if S390
78839 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78840 + help
78841 + This implementation is based on the paging feature of the CPU.
78842 + On i386 without hardware non-executable bit support there is a
78843 + variable but usually low performance impact, however on Intel's
78844 + P4 core based CPUs it is very high so you should not enable this
78845 + for kernels meant to be used on such CPUs.
78846 +
78847 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78848 + with hardware non-executable bit support there is no performance
78849 + impact, on ppc the impact is negligible.
78850 +
78851 + Note that several architectures require various emulations due to
78852 + badly designed userland ABIs, this will cause a performance impact
78853 + but will disappear as soon as userland is fixed. For example, ppc
78854 + userland MUST have been built with secure-plt by a recent toolchain.
78855 +
78856 +config PAX_SEGMEXEC
78857 + bool "Segmentation based non-executable pages"
78858 + depends on PAX_NOEXEC && X86_32
78859 + help
78860 + This implementation is based on the segmentation feature of the
78861 + CPU and has a very small performance impact, however applications
78862 + will be limited to a 1.5 GB address space instead of the normal
78863 + 3 GB.
78864 +
78865 +config PAX_EMUTRAMP
78866 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78867 + default y if PARISC
78868 + help
78869 + There are some programs and libraries that for one reason or
78870 + another attempt to execute special small code snippets from
78871 + non-executable memory pages. Most notable examples are the
78872 + signal handler return code generated by the kernel itself and
78873 + the GCC trampolines.
78874 +
78875 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78876 + such programs will no longer work under your kernel.
78877 +
78878 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78879 + utilities to enable trampoline emulation for the affected programs
78880 + yet still have the protection provided by the non-executable pages.
78881 +
78882 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78883 + your system will not even boot.
78884 +
78885 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78886 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78887 + for the affected files.
78888 +
78889 + NOTE: enabling this feature *may* open up a loophole in the
78890 + protection provided by non-executable pages that an attacker
78891 + could abuse. Therefore the best solution is to not have any
78892 + files on your system that would require this option. This can
78893 + be achieved by not using libc5 (which relies on the kernel
78894 + signal handler return code) and not using or rewriting programs
78895 + that make use of the nested function implementation of GCC.
78896 + Skilled users can just fix GCC itself so that it implements
78897 + nested function calls in a way that does not interfere with PaX.
78898 +
78899 +config PAX_EMUSIGRT
78900 + bool "Automatically emulate sigreturn trampolines"
78901 + depends on PAX_EMUTRAMP && PARISC
78902 + default y
78903 + help
78904 + Enabling this option will have the kernel automatically detect
78905 + and emulate signal return trampolines executing on the stack
78906 + that would otherwise lead to task termination.
78907 +
78908 + This solution is intended as a temporary one for users with
78909 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78910 + Modula-3 runtime, etc) or executables linked to such, basically
78911 + everything that does not specify its own SA_RESTORER function in
78912 + normal executable memory like glibc 2.1+ does.
78913 +
78914 + On parisc you MUST enable this option, otherwise your system will
78915 + not even boot.
78916 +
78917 + NOTE: this feature cannot be disabled on a per executable basis
78918 + and since it *does* open up a loophole in the protection provided
78919 + by non-executable pages, the best solution is to not have any
78920 + files on your system that would require this option.
78921 +
78922 +config PAX_MPROTECT
78923 + bool "Restrict mprotect()"
78924 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78925 + help
78926 + Enabling this option will prevent programs from
78927 + - changing the executable status of memory pages that were
78928 + not originally created as executable,
78929 + - making read-only executable pages writable again,
78930 + - creating executable pages from anonymous memory,
78931 + - making read-only-after-relocations (RELRO) data pages writable again.
78932 +
78933 + You should say Y here to complete the protection provided by
78934 + the enforcement of non-executable pages.
78935 +
78936 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78937 + this feature on a per file basis.
78938 +
78939 +config PAX_MPROTECT_COMPAT
78940 + bool "Use legacy/compat protection demoting (read help)"
78941 + depends on PAX_MPROTECT
78942 + default n
78943 + help
78944 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78945 + by sending the proper error code to the application. For some broken
78946 + userland, this can cause problems with Python or other applications. The
78947 + current implementation however allows for applications like clamav to
78948 + detect if JIT compilation/execution is allowed and to fall back gracefully
78949 + to an interpreter-based mode if it does not. While we encourage everyone
78950 + to use the current implementation as-is and push upstream to fix broken
78951 + userland (note that the RWX logging option can assist with this), in some
78952 + environments this may not be possible. Having to disable MPROTECT
78953 + completely on certain binaries reduces the security benefit of PaX,
78954 + so this option is provided for those environments to revert to the old
78955 + behavior.
78956 +
78957 +config PAX_ELFRELOCS
78958 + bool "Allow ELF text relocations (read help)"
78959 + depends on PAX_MPROTECT
78960 + default n
78961 + help
78962 + Non-executable pages and mprotect() restrictions are effective
78963 + in preventing the introduction of new executable code into an
78964 + attacked task's address space. There remain only two venues
78965 + for this kind of attack: if the attacker can execute already
78966 + existing code in the attacked task then he can either have it
78967 + create and mmap() a file containing his code or have it mmap()
78968 + an already existing ELF library that does not have position
78969 + independent code in it and use mprotect() on it to make it
78970 + writable and copy his code there. While protecting against
78971 + the former approach is beyond PaX, the latter can be prevented
78972 + by having only PIC ELF libraries on one's system (which do not
78973 + need to relocate their code). If you are sure this is your case,
78974 + as is the case with all modern Linux distributions, then leave
78975 + this option disabled. You should say 'n' here.
78976 +
78977 +config PAX_ETEXECRELOCS
78978 + bool "Allow ELF ET_EXEC text relocations"
78979 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78980 + select PAX_ELFRELOCS
78981 + default y
78982 + help
78983 + On some architectures there are incorrectly created applications
78984 + that require text relocations and would not work without enabling
78985 + this option. If you are an alpha, ia64 or parisc user, you should
78986 + enable this option and disable it once you have made sure that
78987 + none of your applications need it.
78988 +
78989 +config PAX_EMUPLT
78990 + bool "Automatically emulate ELF PLT"
78991 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78992 + default y
78993 + help
78994 + Enabling this option will have the kernel automatically detect
78995 + and emulate the Procedure Linkage Table entries in ELF files.
78996 + On some architectures such entries are in writable memory, and
78997 + become non-executable leading to task termination. Therefore
78998 + it is mandatory that you enable this option on alpha, parisc,
78999 + sparc and sparc64, otherwise your system would not even boot.
79000 +
79001 + NOTE: this feature *does* open up a loophole in the protection
79002 + provided by the non-executable pages, therefore the proper
79003 + solution is to modify the toolchain to produce a PLT that does
79004 + not need to be writable.
79005 +
79006 +config PAX_DLRESOLVE
79007 + bool 'Emulate old glibc resolver stub'
79008 + depends on PAX_EMUPLT && SPARC
79009 + default n
79010 + help
79011 + This option is needed if userland has an old glibc (before 2.4)
79012 + that puts a 'save' instruction into the runtime generated resolver
79013 + stub that needs special emulation.
79014 +
79015 +config PAX_KERNEXEC
79016 + bool "Enforce non-executable kernel pages"
79017 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79018 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79019 + select PAX_KERNEXEC_PLUGIN if X86_64
79020 + help
79021 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79022 + that is, enabling this option will make it harder to inject
79023 + and execute 'foreign' code in kernel memory itself.
79024 +
79025 + Note that on x86_64 kernels there is a known regression when
79026 + this feature and KVM/VMX are both enabled in the host kernel.
79027 +
79028 +choice
79029 + prompt "Return Address Instrumentation Method"
79030 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79031 + depends on PAX_KERNEXEC_PLUGIN
79032 + help
79033 + Select the method used to instrument function pointer dereferences.
79034 + Note that binary modules cannot be instrumented by this approach.
79035 +
79036 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79037 + bool "bts"
79038 + help
79039 + This method is compatible with binary only modules but has
79040 + a higher runtime overhead.
79041 +
79042 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79043 + bool "or"
79044 + depends on !PARAVIRT
79045 + help
79046 + This method is incompatible with binary only modules but has
79047 + a lower runtime overhead.
79048 +endchoice
79049 +
79050 +config PAX_KERNEXEC_PLUGIN_METHOD
79051 + string
79052 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79053 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79054 + default ""
79055 +
79056 +config PAX_KERNEXEC_MODULE_TEXT
79057 + int "Minimum amount of memory reserved for module code"
79058 + default "4"
79059 + depends on PAX_KERNEXEC && X86_32 && MODULES
79060 + help
79061 + Due to implementation details the kernel must reserve a fixed
79062 + amount of memory for module code at compile time that cannot be
79063 + changed at runtime. Here you can specify the minimum amount
79064 + in MB that will be reserved. Due to the same implementation
79065 + details this size will always be rounded up to the next 2/4 MB
79066 + boundary (depends on PAE) so the actually available memory for
79067 + module code will usually be more than this minimum.
79068 +
79069 + The default 4 MB should be enough for most users but if you have
79070 + an excessive number of modules (e.g., most distribution configs
79071 + compile many drivers as modules) or use huge modules such as
79072 + nvidia's kernel driver, you will need to adjust this amount.
79073 + A good rule of thumb is to look at your currently loaded kernel
79074 + modules and add up their sizes.
79075 +
79076 +endmenu
79077 +
79078 +menu "Address Space Layout Randomization"
79079 + depends on PAX
79080 +
79081 +config PAX_ASLR
79082 + bool "Address Space Layout Randomization"
79083 + help
79084 + Many if not most exploit techniques rely on the knowledge of
79085 + certain addresses in the attacked program. The following options
79086 + will allow the kernel to apply a certain amount of randomization
79087 + to specific parts of the program thereby forcing an attacker to
79088 + guess them in most cases. Any failed guess will most likely crash
79089 + the attacked program which allows the kernel to detect such attempts
79090 + and react on them. PaX itself provides no reaction mechanisms,
79091 + instead it is strongly encouraged that you make use of Nergal's
79092 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79093 + (http://www.grsecurity.net/) built-in crash detection features or
79094 + develop one yourself.
79095 +
79096 + By saying Y here you can choose to randomize the following areas:
79097 + - top of the task's kernel stack
79098 + - top of the task's userland stack
79099 + - base address for mmap() requests that do not specify one
79100 + (this includes all libraries)
79101 + - base address of the main executable
79102 +
79103 + It is strongly recommended to say Y here as address space layout
79104 + randomization has negligible impact on performance yet it provides
79105 + a very effective protection.
79106 +
79107 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79108 + this feature on a per file basis.
79109 +
79110 +config PAX_RANDKSTACK
79111 + bool "Randomize kernel stack base"
79112 + depends on X86_TSC && X86
79113 + help
79114 + By saying Y here the kernel will randomize every task's kernel
79115 + stack on every system call. This will not only force an attacker
79116 + to guess it but also prevent him from making use of possible
79117 + leaked information about it.
79118 +
79119 + Since the kernel stack is a rather scarce resource, randomization
79120 + may cause unexpected stack overflows, therefore you should very
79121 + carefully test your system. Note that once enabled in the kernel
79122 + configuration, this feature cannot be disabled on a per file basis.
79123 +
79124 +config PAX_RANDUSTACK
79125 + bool "Randomize user stack base"
79126 + depends on PAX_ASLR
79127 + help
79128 + By saying Y here the kernel will randomize every task's userland
79129 + stack. The randomization is done in two steps where the second
79130 + one may apply a big amount of shift to the top of the stack and
79131 + cause problems for programs that want to use lots of memory (more
79132 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79133 + For this reason the second step can be controlled by 'chpax' or
79134 + 'paxctl' on a per file basis.
79135 +
79136 +config PAX_RANDMMAP
79137 + bool "Randomize mmap() base"
79138 + depends on PAX_ASLR
79139 + help
79140 + By saying Y here the kernel will use a randomized base address for
79141 + mmap() requests that do not specify one themselves. As a result
79142 + all dynamically loaded libraries will appear at random addresses
79143 + and therefore be harder to exploit by a technique where an attacker
79144 + attempts to execute library code for his purposes (e.g. spawn a
79145 + shell from an exploited program that is running at an elevated
79146 + privilege level).
79147 +
79148 + Furthermore, if a program is relinked as a dynamic ELF file, its
79149 + base address will be randomized as well, completing the full
79150 + randomization of the address space layout. Attacking such programs
79151 + becomes a guess game. You can find an example of doing this at
79152 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79153 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79154 +
79155 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79156 + feature on a per file basis.
79157 +
79158 +endmenu
79159 +
79160 +menu "Miscellaneous hardening features"
79161 +
79162 +config PAX_MEMORY_SANITIZE
79163 + bool "Sanitize all freed memory"
79164 + depends on !HIBERNATION
79165 + help
79166 + By saying Y here the kernel will erase memory pages as soon as they
79167 + are freed. This in turn reduces the lifetime of data stored in the
79168 + pages, making it less likely that sensitive information such as
79169 + passwords, cryptographic secrets, etc stay in memory for too long.
79170 +
79171 + This is especially useful for programs whose runtime is short, long
79172 + lived processes and the kernel itself benefit from this as long as
79173 + they operate on whole memory pages and ensure timely freeing of pages
79174 + that may hold sensitive information.
79175 +
79176 + The tradeoff is performance impact, on a single CPU system kernel
79177 + compilation sees a 3% slowdown, other systems and workloads may vary
79178 + and you are advised to test this feature on your expected workload
79179 + before deploying it.
79180 +
79181 + Note that this feature does not protect data stored in live pages,
79182 + e.g., process memory swapped to disk may stay there for a long time.
79183 +
79184 +config PAX_MEMORY_STACKLEAK
79185 + bool "Sanitize kernel stack"
79186 + depends on X86
79187 + help
79188 + By saying Y here the kernel will erase the kernel stack before it
79189 + returns from a system call. This in turn reduces the information
79190 + that a kernel stack leak bug can reveal.
79191 +
79192 + Note that such a bug can still leak information that was put on
79193 + the stack by the current system call (the one eventually triggering
79194 + the bug) but traces of earlier system calls on the kernel stack
79195 + cannot leak anymore.
79196 +
79197 + The tradeoff is performance impact: on a single CPU system kernel
79198 + compilation sees a 1% slowdown, other systems and workloads may vary
79199 + and you are advised to test this feature on your expected workload
79200 + before deploying it.
79201 +
79202 + Note: full support for this feature requires gcc with plugin support
79203 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79204 + versions means that functions with large enough stack frames may
79205 + leave uninitialized memory behind that may be exposed to a later
79206 + syscall leaking the stack.
79207 +
79208 +config PAX_MEMORY_UDEREF
79209 + bool "Prevent invalid userland pointer dereference"
79210 + depends on X86 && !UML_X86 && !XEN
79211 + select PAX_PER_CPU_PGD if X86_64
79212 + help
79213 + By saying Y here the kernel will be prevented from dereferencing
79214 + userland pointers in contexts where the kernel expects only kernel
79215 + pointers. This is both a useful runtime debugging feature and a
79216 + security measure that prevents exploiting a class of kernel bugs.
79217 +
79218 + The tradeoff is that some virtualization solutions may experience
79219 + a huge slowdown and therefore you should not enable this feature
79220 + for kernels meant to run in such environments. Whether a given VM
79221 + solution is affected or not is best determined by simply trying it
79222 + out, the performance impact will be obvious right on boot as this
79223 + mechanism engages from very early on. A good rule of thumb is that
79224 + VMs running on CPUs without hardware virtualization support (i.e.,
79225 + the majority of IA-32 CPUs) will likely experience the slowdown.
79226 +
79227 +config PAX_REFCOUNT
79228 + bool "Prevent various kernel object reference counter overflows"
79229 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79230 + help
79231 + By saying Y here the kernel will detect and prevent overflowing
79232 + various (but not all) kinds of object reference counters. Such
79233 + overflows can normally occur due to bugs only and are often, if
79234 + not always, exploitable.
79235 +
79236 + The tradeoff is that data structures protected by an overflowed
79237 + refcount will never be freed and therefore will leak memory. Note
79238 + that this leak also happens even without this protection but in
79239 + that case the overflow can eventually trigger the freeing of the
79240 + data structure while it is still being used elsewhere, resulting
79241 + in the exploitable situation that this feature prevents.
79242 +
79243 + Since this has a negligible performance impact, you should enable
79244 + this feature.
79245 +
79246 +config PAX_USERCOPY
79247 + bool "Harden heap object copies between kernel and userland"
79248 + depends on X86 || PPC || SPARC || ARM
79249 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79250 + help
79251 + By saying Y here the kernel will enforce the size of heap objects
79252 + when they are copied in either direction between the kernel and
79253 + userland, even if only a part of the heap object is copied.
79254 +
79255 + Specifically, this checking prevents information leaking from the
79256 + kernel heap during kernel to userland copies (if the kernel heap
79257 + object is otherwise fully initialized) and prevents kernel heap
79258 + overflows during userland to kernel copies.
79259 +
79260 + Note that the current implementation provides the strictest bounds
79261 + checks for the SLUB allocator.
79262 +
79263 + Enabling this option also enables per-slab cache protection against
79264 + data in a given cache being copied into/out of via userland
79265 + accessors. Though the whitelist of regions will be reduced over
79266 + time, it notably protects important data structures like task structs.
79267 +
79268 + If frame pointers are enabled on x86, this option will also restrict
79269 + copies into and out of the kernel stack to local variables within a
79270 + single frame.
79271 +
79272 + Since this has a negligible performance impact, you should enable
79273 + this feature.
79274 +
79275 +config PAX_SIZE_OVERFLOW
79276 + bool "Prevent various integer overflows in function size parameters"
79277 + depends on X86
79278 + help
79279 + By saying Y here the kernel recomputes expressions of function
79280 + arguments marked by a size_overflow attribute with double integer
79281 + precision (DImode/TImode for 32/64 bit integer types).
79282 +
79283 + The recomputed argument is checked against INT_MAX and an event
79284 + is logged on overflow and the triggering process is killed.
79285 +
79286 + Homepage:
79287 + http://www.grsecurity.net/~ephox/overflow_plugin/
79288 +
79289 +endmenu
79290 +
79291 +endmenu
79292 +
79293 config KEYS
79294 bool "Enable access key retention support"
79295 help
79296 @@ -169,7 +803,7 @@ config INTEL_TXT
79297 config LSM_MMAP_MIN_ADDR
79298 int "Low address space for LSM to protect from user allocation"
79299 depends on SECURITY && SECURITY_SELINUX
79300 - default 32768 if ARM
79301 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79302 default 65536
79303 help
79304 This is the portion of low virtual memory which should be protected
79305 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79306 index 97ce8fa..23dad96 100644
79307 --- a/security/apparmor/lsm.c
79308 +++ b/security/apparmor/lsm.c
79309 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79310 return error;
79311 }
79312
79313 -static struct security_operations apparmor_ops = {
79314 +static struct security_operations apparmor_ops __read_only = {
79315 .name = "apparmor",
79316
79317 .ptrace_access_check = apparmor_ptrace_access_check,
79318 diff --git a/security/commoncap.c b/security/commoncap.c
79319 index 7ce191e..6c29c34 100644
79320 --- a/security/commoncap.c
79321 +++ b/security/commoncap.c
79322 @@ -28,6 +28,7 @@
79323 #include <linux/prctl.h>
79324 #include <linux/securebits.h>
79325 #include <linux/user_namespace.h>
79326 +#include <net/sock.h>
79327
79328 /*
79329 * If a non-root user executes a setuid-root binary in
79330 @@ -569,6 +570,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79331 {
79332 const struct cred *cred = current_cred();
79333
79334 + if (gr_acl_enable_at_secure())
79335 + return 1;
79336 +
79337 if (cred->uid != 0) {
79338 if (bprm->cap_effective)
79339 return 1;
79340 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79341 index 3ccf7ac..d73ad64 100644
79342 --- a/security/integrity/ima/ima.h
79343 +++ b/security/integrity/ima/ima.h
79344 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79345 extern spinlock_t ima_queue_lock;
79346
79347 struct ima_h_table {
79348 - atomic_long_t len; /* number of stored measurements in the list */
79349 - atomic_long_t violations;
79350 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79351 + atomic_long_unchecked_t violations;
79352 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79353 };
79354 extern struct ima_h_table ima_htable;
79355 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79356 index 88a2788..581ab92 100644
79357 --- a/security/integrity/ima/ima_api.c
79358 +++ b/security/integrity/ima/ima_api.c
79359 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79360 int result;
79361
79362 /* can overflow, only indicator */
79363 - atomic_long_inc(&ima_htable.violations);
79364 + atomic_long_inc_unchecked(&ima_htable.violations);
79365
79366 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79367 if (!entry) {
79368 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79369 index e1aa2b4..52027bf 100644
79370 --- a/security/integrity/ima/ima_fs.c
79371 +++ b/security/integrity/ima/ima_fs.c
79372 @@ -28,12 +28,12 @@
79373 static int valid_policy = 1;
79374 #define TMPBUFLEN 12
79375 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79376 - loff_t *ppos, atomic_long_t *val)
79377 + loff_t *ppos, atomic_long_unchecked_t *val)
79378 {
79379 char tmpbuf[TMPBUFLEN];
79380 ssize_t len;
79381
79382 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79383 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79384 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79385 }
79386
79387 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79388 index 55a6271..ad829c3 100644
79389 --- a/security/integrity/ima/ima_queue.c
79390 +++ b/security/integrity/ima/ima_queue.c
79391 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79392 INIT_LIST_HEAD(&qe->later);
79393 list_add_tail_rcu(&qe->later, &ima_measurements);
79394
79395 - atomic_long_inc(&ima_htable.len);
79396 + atomic_long_inc_unchecked(&ima_htable.len);
79397 key = ima_hash_key(entry->digest);
79398 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79399 return 0;
79400 diff --git a/security/keys/compat.c b/security/keys/compat.c
79401 index 4c48e13..7abdac9 100644
79402 --- a/security/keys/compat.c
79403 +++ b/security/keys/compat.c
79404 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79405 if (ret == 0)
79406 goto no_payload_free;
79407
79408 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79409 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79410
79411 if (iov != iovstack)
79412 kfree(iov);
79413 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79414 index 0b3f5d7..892c8a6 100644
79415 --- a/security/keys/keyctl.c
79416 +++ b/security/keys/keyctl.c
79417 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79418 /*
79419 * Copy the iovec data from userspace
79420 */
79421 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79422 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79423 unsigned ioc)
79424 {
79425 for (; ioc > 0; ioc--) {
79426 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79427 * If successful, 0 will be returned.
79428 */
79429 long keyctl_instantiate_key_common(key_serial_t id,
79430 - const struct iovec *payload_iov,
79431 + const struct iovec __user *payload_iov,
79432 unsigned ioc,
79433 size_t plen,
79434 key_serial_t ringid)
79435 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79436 [0].iov_len = plen
79437 };
79438
79439 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79440 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79441 }
79442
79443 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79444 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79445 if (ret == 0)
79446 goto no_payload_free;
79447
79448 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79449 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79450
79451 if (iov != iovstack)
79452 kfree(iov);
79453 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79454 index d605f75..2bc6be9 100644
79455 --- a/security/keys/keyring.c
79456 +++ b/security/keys/keyring.c
79457 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79458 ret = -EFAULT;
79459
79460 for (loop = 0; loop < klist->nkeys; loop++) {
79461 + key_serial_t serial;
79462 key = klist->keys[loop];
79463 + serial = key->serial;
79464
79465 tmp = sizeof(key_serial_t);
79466 if (tmp > buflen)
79467 tmp = buflen;
79468
79469 - if (copy_to_user(buffer,
79470 - &key->serial,
79471 - tmp) != 0)
79472 + if (copy_to_user(buffer, &serial, tmp))
79473 goto error;
79474
79475 buflen -= tmp;
79476 diff --git a/security/min_addr.c b/security/min_addr.c
79477 index f728728..6457a0c 100644
79478 --- a/security/min_addr.c
79479 +++ b/security/min_addr.c
79480 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79481 */
79482 static void update_mmap_min_addr(void)
79483 {
79484 +#ifndef SPARC
79485 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79486 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79487 mmap_min_addr = dac_mmap_min_addr;
79488 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79489 #else
79490 mmap_min_addr = dac_mmap_min_addr;
79491 #endif
79492 +#endif
79493 }
79494
79495 /*
79496 diff --git a/security/security.c b/security/security.c
79497 index d754249..8bf426e 100644
79498 --- a/security/security.c
79499 +++ b/security/security.c
79500 @@ -26,8 +26,8 @@
79501 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79502 CONFIG_DEFAULT_SECURITY;
79503
79504 -static struct security_operations *security_ops;
79505 -static struct security_operations default_security_ops = {
79506 +static struct security_operations *security_ops __read_only;
79507 +static struct security_operations default_security_ops __read_only = {
79508 .name = "default",
79509 };
79510
79511 @@ -68,7 +68,9 @@ int __init security_init(void)
79512
79513 void reset_security_ops(void)
79514 {
79515 + pax_open_kernel();
79516 security_ops = &default_security_ops;
79517 + pax_close_kernel();
79518 }
79519
79520 /* Save user chosen LSM */
79521 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79522 index 6a3683e..f52f4c0 100644
79523 --- a/security/selinux/hooks.c
79524 +++ b/security/selinux/hooks.c
79525 @@ -94,8 +94,6 @@
79526
79527 #define NUM_SEL_MNT_OPTS 5
79528
79529 -extern struct security_operations *security_ops;
79530 -
79531 /* SECMARK reference count */
79532 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79533
79534 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79535
79536 #endif
79537
79538 -static struct security_operations selinux_ops = {
79539 +static struct security_operations selinux_ops __read_only = {
79540 .name = "selinux",
79541
79542 .ptrace_access_check = selinux_ptrace_access_check,
79543 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79544 index b43813c..74be837 100644
79545 --- a/security/selinux/include/xfrm.h
79546 +++ b/security/selinux/include/xfrm.h
79547 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79548
79549 static inline void selinux_xfrm_notify_policyload(void)
79550 {
79551 - atomic_inc(&flow_cache_genid);
79552 + atomic_inc_unchecked(&flow_cache_genid);
79553 }
79554 #else
79555 static inline int selinux_xfrm_enabled(void)
79556 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79557 index e8af5b0b..78527ef 100644
79558 --- a/security/smack/smack_lsm.c
79559 +++ b/security/smack/smack_lsm.c
79560 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79561 return 0;
79562 }
79563
79564 -struct security_operations smack_ops = {
79565 +struct security_operations smack_ops __read_only = {
79566 .name = "smack",
79567
79568 .ptrace_access_check = smack_ptrace_access_check,
79569 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79570 index 620d37c..e2ad89b 100644
79571 --- a/security/tomoyo/tomoyo.c
79572 +++ b/security/tomoyo/tomoyo.c
79573 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79574 * tomoyo_security_ops is a "struct security_operations" which is used for
79575 * registering TOMOYO.
79576 */
79577 -static struct security_operations tomoyo_security_ops = {
79578 +static struct security_operations tomoyo_security_ops __read_only = {
79579 .name = "tomoyo",
79580 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79581 .cred_prepare = tomoyo_cred_prepare,
79582 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79583 index 762af68..7103453 100644
79584 --- a/sound/aoa/codecs/onyx.c
79585 +++ b/sound/aoa/codecs/onyx.c
79586 @@ -54,7 +54,7 @@ struct onyx {
79587 spdif_locked:1,
79588 analog_locked:1,
79589 original_mute:2;
79590 - int open_count;
79591 + local_t open_count;
79592 struct codec_info *codec_info;
79593
79594 /* mutex serializes concurrent access to the device
79595 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79596 struct onyx *onyx = cii->codec_data;
79597
79598 mutex_lock(&onyx->mutex);
79599 - onyx->open_count++;
79600 + local_inc(&onyx->open_count);
79601 mutex_unlock(&onyx->mutex);
79602
79603 return 0;
79604 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79605 struct onyx *onyx = cii->codec_data;
79606
79607 mutex_lock(&onyx->mutex);
79608 - onyx->open_count--;
79609 - if (!onyx->open_count)
79610 + if (local_dec_and_test(&onyx->open_count))
79611 onyx->spdif_locked = onyx->analog_locked = 0;
79612 mutex_unlock(&onyx->mutex);
79613
79614 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79615 index ffd2025..df062c9 100644
79616 --- a/sound/aoa/codecs/onyx.h
79617 +++ b/sound/aoa/codecs/onyx.h
79618 @@ -11,6 +11,7 @@
79619 #include <linux/i2c.h>
79620 #include <asm/pmac_low_i2c.h>
79621 #include <asm/prom.h>
79622 +#include <asm/local.h>
79623
79624 /* PCM3052 register definitions */
79625
79626 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79627 index 08fde00..0bf641a 100644
79628 --- a/sound/core/oss/pcm_oss.c
79629 +++ b/sound/core/oss/pcm_oss.c
79630 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79631 if (in_kernel) {
79632 mm_segment_t fs;
79633 fs = snd_enter_user();
79634 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79635 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79636 snd_leave_user(fs);
79637 } else {
79638 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79639 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79640 }
79641 if (ret != -EPIPE && ret != -ESTRPIPE)
79642 break;
79643 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79644 if (in_kernel) {
79645 mm_segment_t fs;
79646 fs = snd_enter_user();
79647 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79648 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79649 snd_leave_user(fs);
79650 } else {
79651 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79652 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79653 }
79654 if (ret == -EPIPE) {
79655 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79656 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79657 struct snd_pcm_plugin_channel *channels;
79658 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79659 if (!in_kernel) {
79660 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79661 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79662 return -EFAULT;
79663 buf = runtime->oss.buffer;
79664 }
79665 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79666 }
79667 } else {
79668 tmp = snd_pcm_oss_write2(substream,
79669 - (const char __force *)buf,
79670 + (const char __force_kernel *)buf,
79671 runtime->oss.period_bytes, 0);
79672 if (tmp <= 0)
79673 goto err;
79674 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79675 struct snd_pcm_runtime *runtime = substream->runtime;
79676 snd_pcm_sframes_t frames, frames1;
79677 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79678 - char __user *final_dst = (char __force __user *)buf;
79679 + char __user *final_dst = (char __force_user *)buf;
79680 if (runtime->oss.plugin_first) {
79681 struct snd_pcm_plugin_channel *channels;
79682 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79683 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79684 xfer += tmp;
79685 runtime->oss.buffer_used -= tmp;
79686 } else {
79687 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79688 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79689 runtime->oss.period_bytes, 0);
79690 if (tmp <= 0)
79691 goto err;
79692 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79693 size1);
79694 size1 /= runtime->channels; /* frames */
79695 fs = snd_enter_user();
79696 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79697 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79698 snd_leave_user(fs);
79699 }
79700 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79701 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79702 index 91cdf94..4085161 100644
79703 --- a/sound/core/pcm_compat.c
79704 +++ b/sound/core/pcm_compat.c
79705 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79706 int err;
79707
79708 fs = snd_enter_user();
79709 - err = snd_pcm_delay(substream, &delay);
79710 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79711 snd_leave_user(fs);
79712 if (err < 0)
79713 return err;
79714 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79715 index 25ed9fe..24c46e9 100644
79716 --- a/sound/core/pcm_native.c
79717 +++ b/sound/core/pcm_native.c
79718 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79719 switch (substream->stream) {
79720 case SNDRV_PCM_STREAM_PLAYBACK:
79721 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79722 - (void __user *)arg);
79723 + (void __force_user *)arg);
79724 break;
79725 case SNDRV_PCM_STREAM_CAPTURE:
79726 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79727 - (void __user *)arg);
79728 + (void __force_user *)arg);
79729 break;
79730 default:
79731 result = -EINVAL;
79732 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79733 index 5cf8d65..912a79c 100644
79734 --- a/sound/core/seq/seq_device.c
79735 +++ b/sound/core/seq/seq_device.c
79736 @@ -64,7 +64,7 @@ struct ops_list {
79737 int argsize; /* argument size */
79738
79739 /* operators */
79740 - struct snd_seq_dev_ops ops;
79741 + struct snd_seq_dev_ops *ops;
79742
79743 /* registred devices */
79744 struct list_head dev_list; /* list of devices */
79745 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79746
79747 mutex_lock(&ops->reg_mutex);
79748 /* copy driver operators */
79749 - ops->ops = *entry;
79750 + ops->ops = entry;
79751 ops->driver |= DRIVER_LOADED;
79752 ops->argsize = argsize;
79753
79754 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79755 dev->name, ops->id, ops->argsize, dev->argsize);
79756 return -EINVAL;
79757 }
79758 - if (ops->ops.init_device(dev) >= 0) {
79759 + if (ops->ops->init_device(dev) >= 0) {
79760 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79761 ops->num_init_devices++;
79762 } else {
79763 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79764 dev->name, ops->id, ops->argsize, dev->argsize);
79765 return -EINVAL;
79766 }
79767 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79768 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79769 dev->status = SNDRV_SEQ_DEVICE_FREE;
79770 dev->driver_data = NULL;
79771 ops->num_init_devices--;
79772 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79773 index 621e60e..f4543f5 100644
79774 --- a/sound/drivers/mts64.c
79775 +++ b/sound/drivers/mts64.c
79776 @@ -29,6 +29,7 @@
79777 #include <sound/initval.h>
79778 #include <sound/rawmidi.h>
79779 #include <sound/control.h>
79780 +#include <asm/local.h>
79781
79782 #define CARD_NAME "Miditerminal 4140"
79783 #define DRIVER_NAME "MTS64"
79784 @@ -67,7 +68,7 @@ struct mts64 {
79785 struct pardevice *pardev;
79786 int pardev_claimed;
79787
79788 - int open_count;
79789 + local_t open_count;
79790 int current_midi_output_port;
79791 int current_midi_input_port;
79792 u8 mode[MTS64_NUM_INPUT_PORTS];
79793 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79794 {
79795 struct mts64 *mts = substream->rmidi->private_data;
79796
79797 - if (mts->open_count == 0) {
79798 + if (local_read(&mts->open_count) == 0) {
79799 /* We don't need a spinlock here, because this is just called
79800 if the device has not been opened before.
79801 So there aren't any IRQs from the device */
79802 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79803
79804 msleep(50);
79805 }
79806 - ++(mts->open_count);
79807 + local_inc(&mts->open_count);
79808
79809 return 0;
79810 }
79811 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79812 struct mts64 *mts = substream->rmidi->private_data;
79813 unsigned long flags;
79814
79815 - --(mts->open_count);
79816 - if (mts->open_count == 0) {
79817 + if (local_dec_return(&mts->open_count) == 0) {
79818 /* We need the spinlock_irqsave here because we can still
79819 have IRQs at this point */
79820 spin_lock_irqsave(&mts->lock, flags);
79821 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79822
79823 msleep(500);
79824
79825 - } else if (mts->open_count < 0)
79826 - mts->open_count = 0;
79827 + } else if (local_read(&mts->open_count) < 0)
79828 + local_set(&mts->open_count, 0);
79829
79830 return 0;
79831 }
79832 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79833 index b953fb4..1999c01 100644
79834 --- a/sound/drivers/opl4/opl4_lib.c
79835 +++ b/sound/drivers/opl4/opl4_lib.c
79836 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79837 MODULE_DESCRIPTION("OPL4 driver");
79838 MODULE_LICENSE("GPL");
79839
79840 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79841 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79842 {
79843 int timeout = 10;
79844 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79845 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79846 index 3e32bd3..46fc152 100644
79847 --- a/sound/drivers/portman2x4.c
79848 +++ b/sound/drivers/portman2x4.c
79849 @@ -48,6 +48,7 @@
79850 #include <sound/initval.h>
79851 #include <sound/rawmidi.h>
79852 #include <sound/control.h>
79853 +#include <asm/local.h>
79854
79855 #define CARD_NAME "Portman 2x4"
79856 #define DRIVER_NAME "portman"
79857 @@ -85,7 +86,7 @@ struct portman {
79858 struct pardevice *pardev;
79859 int pardev_claimed;
79860
79861 - int open_count;
79862 + local_t open_count;
79863 int mode[PORTMAN_NUM_INPUT_PORTS];
79864 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79865 };
79866 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79867 index 87657dd..a8268d4 100644
79868 --- a/sound/firewire/amdtp.c
79869 +++ b/sound/firewire/amdtp.c
79870 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79871 ptr = s->pcm_buffer_pointer + data_blocks;
79872 if (ptr >= pcm->runtime->buffer_size)
79873 ptr -= pcm->runtime->buffer_size;
79874 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79875 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79876
79877 s->pcm_period_pointer += data_blocks;
79878 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79879 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79880 */
79881 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79882 {
79883 - ACCESS_ONCE(s->source_node_id_field) =
79884 + ACCESS_ONCE_RW(s->source_node_id_field) =
79885 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79886 }
79887 EXPORT_SYMBOL(amdtp_out_stream_update);
79888 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79889 index 537a9cb..8e8c8e9 100644
79890 --- a/sound/firewire/amdtp.h
79891 +++ b/sound/firewire/amdtp.h
79892 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79893 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79894 struct snd_pcm_substream *pcm)
79895 {
79896 - ACCESS_ONCE(s->pcm) = pcm;
79897 + ACCESS_ONCE_RW(s->pcm) = pcm;
79898 }
79899
79900 /**
79901 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79902 index cd094ec..eca1277 100644
79903 --- a/sound/firewire/isight.c
79904 +++ b/sound/firewire/isight.c
79905 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79906 ptr += count;
79907 if (ptr >= runtime->buffer_size)
79908 ptr -= runtime->buffer_size;
79909 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79910 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79911
79912 isight->period_counter += count;
79913 if (isight->period_counter >= runtime->period_size) {
79914 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79915 if (err < 0)
79916 return err;
79917
79918 - ACCESS_ONCE(isight->pcm_active) = true;
79919 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79920
79921 return 0;
79922 }
79923 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79924 {
79925 struct isight *isight = substream->private_data;
79926
79927 - ACCESS_ONCE(isight->pcm_active) = false;
79928 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79929
79930 mutex_lock(&isight->mutex);
79931 isight_stop_streaming(isight);
79932 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79933
79934 switch (cmd) {
79935 case SNDRV_PCM_TRIGGER_START:
79936 - ACCESS_ONCE(isight->pcm_running) = true;
79937 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79938 break;
79939 case SNDRV_PCM_TRIGGER_STOP:
79940 - ACCESS_ONCE(isight->pcm_running) = false;
79941 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79942 break;
79943 default:
79944 return -EINVAL;
79945 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79946 index 7bd5e33..1fcab12 100644
79947 --- a/sound/isa/cmi8330.c
79948 +++ b/sound/isa/cmi8330.c
79949 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79950
79951 struct snd_pcm *pcm;
79952 struct snd_cmi8330_stream {
79953 - struct snd_pcm_ops ops;
79954 + snd_pcm_ops_no_const ops;
79955 snd_pcm_open_callback_t open;
79956 void *private_data; /* sb or wss */
79957 } streams[2];
79958 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79959 index 733b014..56ce96f 100644
79960 --- a/sound/oss/sb_audio.c
79961 +++ b/sound/oss/sb_audio.c
79962 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79963 buf16 = (signed short *)(localbuf + localoffs);
79964 while (c)
79965 {
79966 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79967 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79968 if (copy_from_user(lbuf8,
79969 userbuf+useroffs + p,
79970 locallen))
79971 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79972 index 09d4648..cf234c7 100644
79973 --- a/sound/oss/swarm_cs4297a.c
79974 +++ b/sound/oss/swarm_cs4297a.c
79975 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79976 {
79977 struct cs4297a_state *s;
79978 u32 pwr, id;
79979 - mm_segment_t fs;
79980 int rval;
79981 #ifndef CONFIG_BCM_CS4297A_CSWARM
79982 u64 cfg;
79983 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79984 if (!rval) {
79985 char *sb1250_duart_present;
79986
79987 +#if 0
79988 + mm_segment_t fs;
79989 fs = get_fs();
79990 set_fs(KERNEL_DS);
79991 -#if 0
79992 val = SOUND_MASK_LINE;
79993 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79994 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79995 val = initvol[i].vol;
79996 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79997 }
79998 + set_fs(fs);
79999 // cs4297a_write_ac97(s, 0x18, 0x0808);
80000 #else
80001 // cs4297a_write_ac97(s, 0x5e, 0x180);
80002 cs4297a_write_ac97(s, 0x02, 0x0808);
80003 cs4297a_write_ac97(s, 0x18, 0x0808);
80004 #endif
80005 - set_fs(fs);
80006
80007 list_add(&s->list, &cs4297a_devs);
80008
80009 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80010 index f0f1943..8e1f96c 100644
80011 --- a/sound/pci/hda/hda_codec.h
80012 +++ b/sound/pci/hda/hda_codec.h
80013 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80014 /* notify power-up/down from codec to controller */
80015 void (*pm_notify)(struct hda_bus *bus);
80016 #endif
80017 -};
80018 +} __no_const;
80019
80020 /* template to pass to the bus constructor */
80021 struct hda_bus_template {
80022 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80023 #endif
80024 void (*reboot_notify)(struct hda_codec *codec);
80025 };
80026 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80027
80028 /* record for amp information cache */
80029 struct hda_cache_head {
80030 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80031 struct snd_pcm_substream *substream);
80032 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80033 struct snd_pcm_substream *substream);
80034 -};
80035 +} __no_const;
80036
80037 /* PCM information for each substream */
80038 struct hda_pcm_stream {
80039 @@ -801,7 +802,7 @@ struct hda_codec {
80040 const char *modelname; /* model name for preset */
80041
80042 /* set by patch */
80043 - struct hda_codec_ops patch_ops;
80044 + hda_codec_ops_no_const patch_ops;
80045
80046 /* PCM to create, set by patch_ops.build_pcms callback */
80047 unsigned int num_pcms;
80048 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80049 index 0da778a..bc38b84 100644
80050 --- a/sound/pci/ice1712/ice1712.h
80051 +++ b/sound/pci/ice1712/ice1712.h
80052 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80053 unsigned int mask_flags; /* total mask bits */
80054 struct snd_akm4xxx_ops {
80055 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80056 - } ops;
80057 + } __no_const ops;
80058 };
80059
80060 struct snd_ice1712_spdif {
80061 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80062 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80063 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80064 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80065 - } ops;
80066 + } __no_const ops;
80067 };
80068
80069
80070 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80071 index 12a9a2b..2b6138f 100644
80072 --- a/sound/pci/ymfpci/ymfpci_main.c
80073 +++ b/sound/pci/ymfpci/ymfpci_main.c
80074 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80075 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80076 break;
80077 }
80078 - if (atomic_read(&chip->interrupt_sleep_count)) {
80079 - atomic_set(&chip->interrupt_sleep_count, 0);
80080 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80081 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80082 wake_up(&chip->interrupt_sleep);
80083 }
80084 __end:
80085 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80086 continue;
80087 init_waitqueue_entry(&wait, current);
80088 add_wait_queue(&chip->interrupt_sleep, &wait);
80089 - atomic_inc(&chip->interrupt_sleep_count);
80090 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80091 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80092 remove_wait_queue(&chip->interrupt_sleep, &wait);
80093 }
80094 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80095 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80096 spin_unlock(&chip->reg_lock);
80097
80098 - if (atomic_read(&chip->interrupt_sleep_count)) {
80099 - atomic_set(&chip->interrupt_sleep_count, 0);
80100 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80101 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80102 wake_up(&chip->interrupt_sleep);
80103 }
80104 }
80105 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80106 spin_lock_init(&chip->reg_lock);
80107 spin_lock_init(&chip->voice_lock);
80108 init_waitqueue_head(&chip->interrupt_sleep);
80109 - atomic_set(&chip->interrupt_sleep_count, 0);
80110 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80111 chip->card = card;
80112 chip->pci = pci;
80113 chip->irq = -1;
80114 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80115 index cdc860a..db34a93 100644
80116 --- a/sound/soc/soc-pcm.c
80117 +++ b/sound/soc/soc-pcm.c
80118 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80119 struct snd_soc_platform *platform = rtd->platform;
80120 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80121 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80122 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80123 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80124 struct snd_pcm *pcm;
80125 char new_name[64];
80126 int ret = 0, playback = 0, capture = 0;
80127 diff --git a/sound/usb/card.h b/sound/usb/card.h
80128 index da5fa1a..113cd02 100644
80129 --- a/sound/usb/card.h
80130 +++ b/sound/usb/card.h
80131 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80132 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80133 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80134 };
80135 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80136
80137 struct snd_usb_substream {
80138 struct snd_usb_stream *stream;
80139 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80140 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80141 spinlock_t lock;
80142
80143 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80144 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80145 int last_frame_number; /* stored frame number */
80146 int last_delay; /* stored delay */
80147 };
80148 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80149 new file mode 100644
80150 index 0000000..ca64170
80151 --- /dev/null
80152 +++ b/tools/gcc/Makefile
80153 @@ -0,0 +1,26 @@
80154 +#CC := gcc
80155 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80156 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80157 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80158 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80159 +
80160 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80161 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80162 +
80163 +hostlibs-y := constify_plugin.so
80164 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80165 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80166 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80167 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80168 +hostlibs-y += colorize_plugin.so
80169 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80170 +
80171 +always := $(hostlibs-y)
80172 +
80173 +constify_plugin-objs := constify_plugin.o
80174 +stackleak_plugin-objs := stackleak_plugin.o
80175 +kallocstat_plugin-objs := kallocstat_plugin.o
80176 +kernexec_plugin-objs := kernexec_plugin.o
80177 +checker_plugin-objs := checker_plugin.o
80178 +colorize_plugin-objs := colorize_plugin.o
80179 +size_overflow_plugin-objs := size_overflow_plugin.o
80180 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80181 new file mode 100644
80182 index 0000000..d41b5af
80183 --- /dev/null
80184 +++ b/tools/gcc/checker_plugin.c
80185 @@ -0,0 +1,171 @@
80186 +/*
80187 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80188 + * Licensed under the GPL v2
80189 + *
80190 + * Note: the choice of the license means that the compilation process is
80191 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80192 + * but for the kernel it doesn't matter since it doesn't link against
80193 + * any of the gcc libraries
80194 + *
80195 + * gcc plugin to implement various sparse (source code checker) features
80196 + *
80197 + * TODO:
80198 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80199 + *
80200 + * BUGS:
80201 + * - none known
80202 + */
80203 +#include "gcc-plugin.h"
80204 +#include "config.h"
80205 +#include "system.h"
80206 +#include "coretypes.h"
80207 +#include "tree.h"
80208 +#include "tree-pass.h"
80209 +#include "flags.h"
80210 +#include "intl.h"
80211 +#include "toplev.h"
80212 +#include "plugin.h"
80213 +//#include "expr.h" where are you...
80214 +#include "diagnostic.h"
80215 +#include "plugin-version.h"
80216 +#include "tm.h"
80217 +#include "function.h"
80218 +#include "basic-block.h"
80219 +#include "gimple.h"
80220 +#include "rtl.h"
80221 +#include "emit-rtl.h"
80222 +#include "tree-flow.h"
80223 +#include "target.h"
80224 +
80225 +extern void c_register_addr_space (const char *str, addr_space_t as);
80226 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80227 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80228 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80229 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80230 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80231 +
80232 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80233 +extern rtx emit_move_insn(rtx x, rtx y);
80234 +
80235 +int plugin_is_GPL_compatible;
80236 +
80237 +static struct plugin_info checker_plugin_info = {
80238 + .version = "201111150100",
80239 +};
80240 +
80241 +#define ADDR_SPACE_KERNEL 0
80242 +#define ADDR_SPACE_FORCE_KERNEL 1
80243 +#define ADDR_SPACE_USER 2
80244 +#define ADDR_SPACE_FORCE_USER 3
80245 +#define ADDR_SPACE_IOMEM 0
80246 +#define ADDR_SPACE_FORCE_IOMEM 0
80247 +#define ADDR_SPACE_PERCPU 0
80248 +#define ADDR_SPACE_FORCE_PERCPU 0
80249 +#define ADDR_SPACE_RCU 0
80250 +#define ADDR_SPACE_FORCE_RCU 0
80251 +
80252 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80253 +{
80254 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80255 +}
80256 +
80257 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80258 +{
80259 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80260 +}
80261 +
80262 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80263 +{
80264 + return default_addr_space_valid_pointer_mode(mode, as);
80265 +}
80266 +
80267 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80268 +{
80269 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80270 +}
80271 +
80272 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80273 +{
80274 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80275 +}
80276 +
80277 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80278 +{
80279 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80280 + return true;
80281 +
80282 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80283 + return true;
80284 +
80285 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80286 + return true;
80287 +
80288 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80289 + return true;
80290 +
80291 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80292 + return true;
80293 +
80294 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80295 + return true;
80296 +
80297 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80298 + return true;
80299 +
80300 + return subset == superset;
80301 +}
80302 +
80303 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80304 +{
80305 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80306 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80307 +
80308 + return op;
80309 +}
80310 +
80311 +static void register_checker_address_spaces(void *event_data, void *data)
80312 +{
80313 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80314 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80315 + c_register_addr_space("__user", ADDR_SPACE_USER);
80316 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80317 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80318 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80319 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80320 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80321 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80322 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80323 +
80324 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80325 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80326 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80327 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80328 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80329 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80330 + targetm.addr_space.convert = checker_addr_space_convert;
80331 +}
80332 +
80333 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80334 +{
80335 + const char * const plugin_name = plugin_info->base_name;
80336 + const int argc = plugin_info->argc;
80337 + const struct plugin_argument * const argv = plugin_info->argv;
80338 + int i;
80339 +
80340 + if (!plugin_default_version_check(version, &gcc_version)) {
80341 + error(G_("incompatible gcc/plugin versions"));
80342 + return 1;
80343 + }
80344 +
80345 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80346 +
80347 + for (i = 0; i < argc; ++i)
80348 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80349 +
80350 + if (TARGET_64BIT == 0)
80351 + return 0;
80352 +
80353 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80354 +
80355 + return 0;
80356 +}
80357 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80358 new file mode 100644
80359 index 0000000..ee950d0
80360 --- /dev/null
80361 +++ b/tools/gcc/colorize_plugin.c
80362 @@ -0,0 +1,147 @@
80363 +/*
80364 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80365 + * Licensed under the GPL v2
80366 + *
80367 + * Note: the choice of the license means that the compilation process is
80368 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80369 + * but for the kernel it doesn't matter since it doesn't link against
80370 + * any of the gcc libraries
80371 + *
80372 + * gcc plugin to colorize diagnostic output
80373 + *
80374 + */
80375 +
80376 +#include "gcc-plugin.h"
80377 +#include "config.h"
80378 +#include "system.h"
80379 +#include "coretypes.h"
80380 +#include "tree.h"
80381 +#include "tree-pass.h"
80382 +#include "flags.h"
80383 +#include "intl.h"
80384 +#include "toplev.h"
80385 +#include "plugin.h"
80386 +#include "diagnostic.h"
80387 +#include "plugin-version.h"
80388 +#include "tm.h"
80389 +
80390 +int plugin_is_GPL_compatible;
80391 +
80392 +static struct plugin_info colorize_plugin_info = {
80393 + .version = "201203092200",
80394 +};
80395 +
80396 +#define GREEN "\033[32m\033[2m"
80397 +#define LIGHTGREEN "\033[32m\033[1m"
80398 +#define YELLOW "\033[33m\033[2m"
80399 +#define LIGHTYELLOW "\033[33m\033[1m"
80400 +#define RED "\033[31m\033[2m"
80401 +#define LIGHTRED "\033[31m\033[1m"
80402 +#define BLUE "\033[34m\033[2m"
80403 +#define LIGHTBLUE "\033[34m\033[1m"
80404 +#define BRIGHT "\033[m\033[1m"
80405 +#define NORMAL "\033[m"
80406 +
80407 +static diagnostic_starter_fn old_starter;
80408 +static diagnostic_finalizer_fn old_finalizer;
80409 +
80410 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80411 +{
80412 + const char *color;
80413 + char *newprefix;
80414 +
80415 + switch (diagnostic->kind) {
80416 + case DK_NOTE:
80417 + color = LIGHTBLUE;
80418 + break;
80419 +
80420 + case DK_PEDWARN:
80421 + case DK_WARNING:
80422 + color = LIGHTYELLOW;
80423 + break;
80424 +
80425 + case DK_ERROR:
80426 + case DK_FATAL:
80427 + case DK_ICE:
80428 + case DK_PERMERROR:
80429 + case DK_SORRY:
80430 + color = LIGHTRED;
80431 + break;
80432 +
80433 + default:
80434 + color = NORMAL;
80435 + }
80436 +
80437 + old_starter(context, diagnostic);
80438 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80439 + return;
80440 + pp_destroy_prefix(context->printer);
80441 + pp_set_prefix(context->printer, newprefix);
80442 +}
80443 +
80444 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80445 +{
80446 + old_finalizer(context, diagnostic);
80447 +}
80448 +
80449 +static void colorize_arm(void)
80450 +{
80451 + old_starter = diagnostic_starter(global_dc);
80452 + old_finalizer = diagnostic_finalizer(global_dc);
80453 +
80454 + diagnostic_starter(global_dc) = start_colorize;
80455 + diagnostic_finalizer(global_dc) = finalize_colorize;
80456 +}
80457 +
80458 +static unsigned int execute_colorize_rearm(void)
80459 +{
80460 + if (diagnostic_starter(global_dc) == start_colorize)
80461 + return 0;
80462 +
80463 + colorize_arm();
80464 + return 0;
80465 +}
80466 +
80467 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80468 + .pass = {
80469 + .type = SIMPLE_IPA_PASS,
80470 + .name = "colorize_rearm",
80471 + .gate = NULL,
80472 + .execute = execute_colorize_rearm,
80473 + .sub = NULL,
80474 + .next = NULL,
80475 + .static_pass_number = 0,
80476 + .tv_id = TV_NONE,
80477 + .properties_required = 0,
80478 + .properties_provided = 0,
80479 + .properties_destroyed = 0,
80480 + .todo_flags_start = 0,
80481 + .todo_flags_finish = 0
80482 + }
80483 +};
80484 +
80485 +static void colorize_start_unit(void *gcc_data, void *user_data)
80486 +{
80487 + colorize_arm();
80488 +}
80489 +
80490 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80491 +{
80492 + const char * const plugin_name = plugin_info->base_name;
80493 + struct register_pass_info colorize_rearm_pass_info = {
80494 + .pass = &pass_ipa_colorize_rearm.pass,
80495 + .reference_pass_name = "*free_lang_data",
80496 + .ref_pass_instance_number = 0,
80497 + .pos_op = PASS_POS_INSERT_AFTER
80498 + };
80499 +
80500 + if (!plugin_default_version_check(version, &gcc_version)) {
80501 + error(G_("incompatible gcc/plugin versions"));
80502 + return 1;
80503 + }
80504 +
80505 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80506 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80507 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80508 + return 0;
80509 +}
80510 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80511 new file mode 100644
80512 index 0000000..704a564
80513 --- /dev/null
80514 +++ b/tools/gcc/constify_plugin.c
80515 @@ -0,0 +1,303 @@
80516 +/*
80517 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80518 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80519 + * Licensed under the GPL v2, or (at your option) v3
80520 + *
80521 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80522 + *
80523 + * Homepage:
80524 + * http://www.grsecurity.net/~ephox/const_plugin/
80525 + *
80526 + * Usage:
80527 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80528 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80529 + */
80530 +
80531 +#include "gcc-plugin.h"
80532 +#include "config.h"
80533 +#include "system.h"
80534 +#include "coretypes.h"
80535 +#include "tree.h"
80536 +#include "tree-pass.h"
80537 +#include "flags.h"
80538 +#include "intl.h"
80539 +#include "toplev.h"
80540 +#include "plugin.h"
80541 +#include "diagnostic.h"
80542 +#include "plugin-version.h"
80543 +#include "tm.h"
80544 +#include "function.h"
80545 +#include "basic-block.h"
80546 +#include "gimple.h"
80547 +#include "rtl.h"
80548 +#include "emit-rtl.h"
80549 +#include "tree-flow.h"
80550 +
80551 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80552 +
80553 +int plugin_is_GPL_compatible;
80554 +
80555 +static struct plugin_info const_plugin_info = {
80556 + .version = "201111150100",
80557 + .help = "no-constify\tturn off constification\n",
80558 +};
80559 +
80560 +static void constify_type(tree type);
80561 +static bool walk_struct(tree node);
80562 +
80563 +static tree deconstify_type(tree old_type)
80564 +{
80565 + tree new_type, field;
80566 +
80567 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80568 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80569 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80570 + DECL_FIELD_CONTEXT(field) = new_type;
80571 + TYPE_READONLY(new_type) = 0;
80572 + C_TYPE_FIELDS_READONLY(new_type) = 0;
80573 + return new_type;
80574 +}
80575 +
80576 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80577 +{
80578 + tree type;
80579 +
80580 + *no_add_attrs = true;
80581 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80582 + error("%qE attribute does not apply to functions", name);
80583 + return NULL_TREE;
80584 + }
80585 +
80586 + if (TREE_CODE(*node) == VAR_DECL) {
80587 + error("%qE attribute does not apply to variables", name);
80588 + return NULL_TREE;
80589 + }
80590 +
80591 + if (TYPE_P(*node)) {
80592 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80593 + *no_add_attrs = false;
80594 + else
80595 + error("%qE attribute applies to struct and union types only", name);
80596 + return NULL_TREE;
80597 + }
80598 +
80599 + type = TREE_TYPE(*node);
80600 +
80601 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80602 + error("%qE attribute applies to struct and union types only", name);
80603 + return NULL_TREE;
80604 + }
80605 +
80606 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80607 + error("%qE attribute is already applied to the type", name);
80608 + return NULL_TREE;
80609 + }
80610 +
80611 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80612 + error("%qE attribute used on type that is not constified", name);
80613 + return NULL_TREE;
80614 + }
80615 +
80616 + if (TREE_CODE(*node) == TYPE_DECL) {
80617 + TREE_TYPE(*node) = deconstify_type(type);
80618 + TREE_READONLY(*node) = 0;
80619 + return NULL_TREE;
80620 + }
80621 +
80622 + return NULL_TREE;
80623 +}
80624 +
80625 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80626 +{
80627 + *no_add_attrs = true;
80628 + if (!TYPE_P(*node)) {
80629 + error("%qE attribute applies to types only", name);
80630 + return NULL_TREE;
80631 + }
80632 +
80633 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80634 + error("%qE attribute applies to struct and union types only", name);
80635 + return NULL_TREE;
80636 + }
80637 +
80638 + *no_add_attrs = false;
80639 + constify_type(*node);
80640 + return NULL_TREE;
80641 +}
80642 +
80643 +static struct attribute_spec no_const_attr = {
80644 + .name = "no_const",
80645 + .min_length = 0,
80646 + .max_length = 0,
80647 + .decl_required = false,
80648 + .type_required = false,
80649 + .function_type_required = false,
80650 + .handler = handle_no_const_attribute,
80651 +#if BUILDING_GCC_VERSION >= 4007
80652 + .affects_type_identity = true
80653 +#endif
80654 +};
80655 +
80656 +static struct attribute_spec do_const_attr = {
80657 + .name = "do_const",
80658 + .min_length = 0,
80659 + .max_length = 0,
80660 + .decl_required = false,
80661 + .type_required = false,
80662 + .function_type_required = false,
80663 + .handler = handle_do_const_attribute,
80664 +#if BUILDING_GCC_VERSION >= 4007
80665 + .affects_type_identity = true
80666 +#endif
80667 +};
80668 +
80669 +static void register_attributes(void *event_data, void *data)
80670 +{
80671 + register_attribute(&no_const_attr);
80672 + register_attribute(&do_const_attr);
80673 +}
80674 +
80675 +static void constify_type(tree type)
80676 +{
80677 + TYPE_READONLY(type) = 1;
80678 + C_TYPE_FIELDS_READONLY(type) = 1;
80679 +}
80680 +
80681 +static bool is_fptr(tree field)
80682 +{
80683 + tree ptr = TREE_TYPE(field);
80684 +
80685 + if (TREE_CODE(ptr) != POINTER_TYPE)
80686 + return false;
80687 +
80688 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80689 +}
80690 +
80691 +static bool walk_struct(tree node)
80692 +{
80693 + tree field;
80694 +
80695 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
80696 + return false;
80697 +
80698 + if (TYPE_FIELDS(node) == NULL_TREE)
80699 + return false;
80700 +
80701 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80702 + tree type = TREE_TYPE(field);
80703 + enum tree_code code = TREE_CODE(type);
80704 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80705 + if (!(walk_struct(type)))
80706 + return false;
80707 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80708 + return false;
80709 + }
80710 + return true;
80711 +}
80712 +
80713 +static void finish_type(void *event_data, void *data)
80714 +{
80715 + tree type = (tree)event_data;
80716 +
80717 + if (type == NULL_TREE)
80718 + return;
80719 +
80720 + if (TYPE_READONLY(type))
80721 + return;
80722 +
80723 + if (walk_struct(type))
80724 + constify_type(type);
80725 +}
80726 +
80727 +static unsigned int check_local_variables(void);
80728 +
80729 +struct gimple_opt_pass pass_local_variable = {
80730 + {
80731 + .type = GIMPLE_PASS,
80732 + .name = "check_local_variables",
80733 + .gate = NULL,
80734 + .execute = check_local_variables,
80735 + .sub = NULL,
80736 + .next = NULL,
80737 + .static_pass_number = 0,
80738 + .tv_id = TV_NONE,
80739 + .properties_required = 0,
80740 + .properties_provided = 0,
80741 + .properties_destroyed = 0,
80742 + .todo_flags_start = 0,
80743 + .todo_flags_finish = 0
80744 + }
80745 +};
80746 +
80747 +static unsigned int check_local_variables(void)
80748 +{
80749 + tree var;
80750 + referenced_var_iterator rvi;
80751 +
80752 +#if BUILDING_GCC_VERSION == 4005
80753 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80754 +#else
80755 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80756 +#endif
80757 + tree type = TREE_TYPE(var);
80758 +
80759 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80760 + continue;
80761 +
80762 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80763 + continue;
80764 +
80765 + if (!TYPE_READONLY(type))
80766 + continue;
80767 +
80768 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80769 +// continue;
80770 +
80771 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80772 +// continue;
80773 +
80774 + if (walk_struct(type)) {
80775 + error("constified variable %qE cannot be local", var);
80776 + return 1;
80777 + }
80778 + }
80779 + return 0;
80780 +}
80781 +
80782 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80783 +{
80784 + const char * const plugin_name = plugin_info->base_name;
80785 + const int argc = plugin_info->argc;
80786 + const struct plugin_argument * const argv = plugin_info->argv;
80787 + int i;
80788 + bool constify = true;
80789 +
80790 + struct register_pass_info local_variable_pass_info = {
80791 + .pass = &pass_local_variable.pass,
80792 + .reference_pass_name = "*referenced_vars",
80793 + .ref_pass_instance_number = 0,
80794 + .pos_op = PASS_POS_INSERT_AFTER
80795 + };
80796 +
80797 + if (!plugin_default_version_check(version, &gcc_version)) {
80798 + error(G_("incompatible gcc/plugin versions"));
80799 + return 1;
80800 + }
80801 +
80802 + for (i = 0; i < argc; ++i) {
80803 + if (!(strcmp(argv[i].key, "no-constify"))) {
80804 + constify = false;
80805 + continue;
80806 + }
80807 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80808 + }
80809 +
80810 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80811 + if (constify) {
80812 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80813 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80814 + }
80815 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80816 +
80817 + return 0;
80818 +}
80819 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80820 new file mode 100644
80821 index 0000000..a5eabce
80822 --- /dev/null
80823 +++ b/tools/gcc/kallocstat_plugin.c
80824 @@ -0,0 +1,167 @@
80825 +/*
80826 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80827 + * Licensed under the GPL v2
80828 + *
80829 + * Note: the choice of the license means that the compilation process is
80830 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80831 + * but for the kernel it doesn't matter since it doesn't link against
80832 + * any of the gcc libraries
80833 + *
80834 + * gcc plugin to find the distribution of k*alloc sizes
80835 + *
80836 + * TODO:
80837 + *
80838 + * BUGS:
80839 + * - none known
80840 + */
80841 +#include "gcc-plugin.h"
80842 +#include "config.h"
80843 +#include "system.h"
80844 +#include "coretypes.h"
80845 +#include "tree.h"
80846 +#include "tree-pass.h"
80847 +#include "flags.h"
80848 +#include "intl.h"
80849 +#include "toplev.h"
80850 +#include "plugin.h"
80851 +//#include "expr.h" where are you...
80852 +#include "diagnostic.h"
80853 +#include "plugin-version.h"
80854 +#include "tm.h"
80855 +#include "function.h"
80856 +#include "basic-block.h"
80857 +#include "gimple.h"
80858 +#include "rtl.h"
80859 +#include "emit-rtl.h"
80860 +
80861 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80862 +
80863 +int plugin_is_GPL_compatible;
80864 +
80865 +static const char * const kalloc_functions[] = {
80866 + "__kmalloc",
80867 + "kmalloc",
80868 + "kmalloc_large",
80869 + "kmalloc_node",
80870 + "kmalloc_order",
80871 + "kmalloc_order_trace",
80872 + "kmalloc_slab",
80873 + "kzalloc",
80874 + "kzalloc_node",
80875 +};
80876 +
80877 +static struct plugin_info kallocstat_plugin_info = {
80878 + .version = "201111150100",
80879 +};
80880 +
80881 +static unsigned int execute_kallocstat(void);
80882 +
80883 +static struct gimple_opt_pass kallocstat_pass = {
80884 + .pass = {
80885 + .type = GIMPLE_PASS,
80886 + .name = "kallocstat",
80887 + .gate = NULL,
80888 + .execute = execute_kallocstat,
80889 + .sub = NULL,
80890 + .next = NULL,
80891 + .static_pass_number = 0,
80892 + .tv_id = TV_NONE,
80893 + .properties_required = 0,
80894 + .properties_provided = 0,
80895 + .properties_destroyed = 0,
80896 + .todo_flags_start = 0,
80897 + .todo_flags_finish = 0
80898 + }
80899 +};
80900 +
80901 +static bool is_kalloc(const char *fnname)
80902 +{
80903 + size_t i;
80904 +
80905 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80906 + if (!strcmp(fnname, kalloc_functions[i]))
80907 + return true;
80908 + return false;
80909 +}
80910 +
80911 +static unsigned int execute_kallocstat(void)
80912 +{
80913 + basic_block bb;
80914 +
80915 + // 1. loop through BBs and GIMPLE statements
80916 + FOR_EACH_BB(bb) {
80917 + gimple_stmt_iterator gsi;
80918 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80919 + // gimple match:
80920 + tree fndecl, size;
80921 + gimple call_stmt;
80922 + const char *fnname;
80923 +
80924 + // is it a call
80925 + call_stmt = gsi_stmt(gsi);
80926 + if (!is_gimple_call(call_stmt))
80927 + continue;
80928 + fndecl = gimple_call_fndecl(call_stmt);
80929 + if (fndecl == NULL_TREE)
80930 + continue;
80931 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80932 + continue;
80933 +
80934 + // is it a call to k*alloc
80935 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80936 + if (!is_kalloc(fnname))
80937 + continue;
80938 +
80939 + // is the size arg the result of a simple const assignment
80940 + size = gimple_call_arg(call_stmt, 0);
80941 + while (true) {
80942 + gimple def_stmt;
80943 + expanded_location xloc;
80944 + size_t size_val;
80945 +
80946 + if (TREE_CODE(size) != SSA_NAME)
80947 + break;
80948 + def_stmt = SSA_NAME_DEF_STMT(size);
80949 + if (!def_stmt || !is_gimple_assign(def_stmt))
80950 + break;
80951 + if (gimple_num_ops(def_stmt) != 2)
80952 + break;
80953 + size = gimple_assign_rhs1(def_stmt);
80954 + if (!TREE_CONSTANT(size))
80955 + continue;
80956 + xloc = expand_location(gimple_location(def_stmt));
80957 + if (!xloc.file)
80958 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80959 + size_val = TREE_INT_CST_LOW(size);
80960 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80961 + break;
80962 + }
80963 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80964 +//debug_tree(gimple_call_fn(call_stmt));
80965 +//print_node(stderr, "pax", fndecl, 4);
80966 + }
80967 + }
80968 +
80969 + return 0;
80970 +}
80971 +
80972 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80973 +{
80974 + const char * const plugin_name = plugin_info->base_name;
80975 + struct register_pass_info kallocstat_pass_info = {
80976 + .pass = &kallocstat_pass.pass,
80977 + .reference_pass_name = "ssa",
80978 + .ref_pass_instance_number = 0,
80979 + .pos_op = PASS_POS_INSERT_AFTER
80980 + };
80981 +
80982 + if (!plugin_default_version_check(version, &gcc_version)) {
80983 + error(G_("incompatible gcc/plugin versions"));
80984 + return 1;
80985 + }
80986 +
80987 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80988 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80989 +
80990 + return 0;
80991 +}
80992 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80993 new file mode 100644
80994 index 0000000..d8a8da2
80995 --- /dev/null
80996 +++ b/tools/gcc/kernexec_plugin.c
80997 @@ -0,0 +1,427 @@
80998 +/*
80999 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81000 + * Licensed under the GPL v2
81001 + *
81002 + * Note: the choice of the license means that the compilation process is
81003 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81004 + * but for the kernel it doesn't matter since it doesn't link against
81005 + * any of the gcc libraries
81006 + *
81007 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81008 + *
81009 + * TODO:
81010 + *
81011 + * BUGS:
81012 + * - none known
81013 + */
81014 +#include "gcc-plugin.h"
81015 +#include "config.h"
81016 +#include "system.h"
81017 +#include "coretypes.h"
81018 +#include "tree.h"
81019 +#include "tree-pass.h"
81020 +#include "flags.h"
81021 +#include "intl.h"
81022 +#include "toplev.h"
81023 +#include "plugin.h"
81024 +//#include "expr.h" where are you...
81025 +#include "diagnostic.h"
81026 +#include "plugin-version.h"
81027 +#include "tm.h"
81028 +#include "function.h"
81029 +#include "basic-block.h"
81030 +#include "gimple.h"
81031 +#include "rtl.h"
81032 +#include "emit-rtl.h"
81033 +#include "tree-flow.h"
81034 +
81035 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81036 +extern rtx emit_move_insn(rtx x, rtx y);
81037 +
81038 +int plugin_is_GPL_compatible;
81039 +
81040 +static struct plugin_info kernexec_plugin_info = {
81041 + .version = "201111291120",
81042 + .help = "method=[bts|or]\tinstrumentation method\n"
81043 +};
81044 +
81045 +static unsigned int execute_kernexec_reload(void);
81046 +static unsigned int execute_kernexec_fptr(void);
81047 +static unsigned int execute_kernexec_retaddr(void);
81048 +static bool kernexec_cmodel_check(void);
81049 +
81050 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81051 +static void (*kernexec_instrument_retaddr)(rtx);
81052 +
81053 +static struct gimple_opt_pass kernexec_reload_pass = {
81054 + .pass = {
81055 + .type = GIMPLE_PASS,
81056 + .name = "kernexec_reload",
81057 + .gate = kernexec_cmodel_check,
81058 + .execute = execute_kernexec_reload,
81059 + .sub = NULL,
81060 + .next = NULL,
81061 + .static_pass_number = 0,
81062 + .tv_id = TV_NONE,
81063 + .properties_required = 0,
81064 + .properties_provided = 0,
81065 + .properties_destroyed = 0,
81066 + .todo_flags_start = 0,
81067 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81068 + }
81069 +};
81070 +
81071 +static struct gimple_opt_pass kernexec_fptr_pass = {
81072 + .pass = {
81073 + .type = GIMPLE_PASS,
81074 + .name = "kernexec_fptr",
81075 + .gate = kernexec_cmodel_check,
81076 + .execute = execute_kernexec_fptr,
81077 + .sub = NULL,
81078 + .next = NULL,
81079 + .static_pass_number = 0,
81080 + .tv_id = TV_NONE,
81081 + .properties_required = 0,
81082 + .properties_provided = 0,
81083 + .properties_destroyed = 0,
81084 + .todo_flags_start = 0,
81085 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81086 + }
81087 +};
81088 +
81089 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81090 + .pass = {
81091 + .type = RTL_PASS,
81092 + .name = "kernexec_retaddr",
81093 + .gate = kernexec_cmodel_check,
81094 + .execute = execute_kernexec_retaddr,
81095 + .sub = NULL,
81096 + .next = NULL,
81097 + .static_pass_number = 0,
81098 + .tv_id = TV_NONE,
81099 + .properties_required = 0,
81100 + .properties_provided = 0,
81101 + .properties_destroyed = 0,
81102 + .todo_flags_start = 0,
81103 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81104 + }
81105 +};
81106 +
81107 +static bool kernexec_cmodel_check(void)
81108 +{
81109 + tree section;
81110 +
81111 + if (ix86_cmodel != CM_KERNEL)
81112 + return false;
81113 +
81114 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81115 + if (!section || !TREE_VALUE(section))
81116 + return true;
81117 +
81118 + section = TREE_VALUE(TREE_VALUE(section));
81119 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81120 + return true;
81121 +
81122 + return false;
81123 +}
81124 +
81125 +/*
81126 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81127 + */
81128 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81129 +{
81130 + gimple asm_movabs_stmt;
81131 +
81132 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81133 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81134 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81135 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81136 + update_stmt(asm_movabs_stmt);
81137 +}
81138 +
81139 +/*
81140 + * find all asm() stmts that clobber r10 and add a reload of r10
81141 + */
81142 +static unsigned int execute_kernexec_reload(void)
81143 +{
81144 + basic_block bb;
81145 +
81146 + // 1. loop through BBs and GIMPLE statements
81147 + FOR_EACH_BB(bb) {
81148 + gimple_stmt_iterator gsi;
81149 +
81150 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81151 + // gimple match: __asm__ ("" : : : "r10");
81152 + gimple asm_stmt;
81153 + size_t nclobbers;
81154 +
81155 + // is it an asm ...
81156 + asm_stmt = gsi_stmt(gsi);
81157 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81158 + continue;
81159 +
81160 + // ... clobbering r10
81161 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81162 + while (nclobbers--) {
81163 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81164 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81165 + continue;
81166 + kernexec_reload_fptr_mask(&gsi);
81167 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81168 + break;
81169 + }
81170 + }
81171 + }
81172 +
81173 + return 0;
81174 +}
81175 +
81176 +/*
81177 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81178 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81179 + */
81180 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81181 +{
81182 + gimple assign_intptr, assign_new_fptr, call_stmt;
81183 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81184 +
81185 + call_stmt = gsi_stmt(*gsi);
81186 + old_fptr = gimple_call_fn(call_stmt);
81187 +
81188 + // create temporary unsigned long variable used for bitops and cast fptr to it
81189 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81190 + add_referenced_var(intptr);
81191 + mark_sym_for_renaming(intptr);
81192 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81193 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81194 + update_stmt(assign_intptr);
81195 +
81196 + // apply logical or to temporary unsigned long and bitmask
81197 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81198 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81199 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81200 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81201 + update_stmt(assign_intptr);
81202 +
81203 + // cast temporary unsigned long back to a temporary fptr variable
81204 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81205 + add_referenced_var(new_fptr);
81206 + mark_sym_for_renaming(new_fptr);
81207 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81208 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81209 + update_stmt(assign_new_fptr);
81210 +
81211 + // replace call stmt fn with the new fptr
81212 + gimple_call_set_fn(call_stmt, new_fptr);
81213 + update_stmt(call_stmt);
81214 +}
81215 +
81216 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81217 +{
81218 + gimple asm_or_stmt, call_stmt;
81219 + tree old_fptr, new_fptr, input, output;
81220 + VEC(tree, gc) *inputs = NULL;
81221 + VEC(tree, gc) *outputs = NULL;
81222 +
81223 + call_stmt = gsi_stmt(*gsi);
81224 + old_fptr = gimple_call_fn(call_stmt);
81225 +
81226 + // create temporary fptr variable
81227 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81228 + add_referenced_var(new_fptr);
81229 + mark_sym_for_renaming(new_fptr);
81230 +
81231 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81232 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81233 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81234 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81235 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81236 + VEC_safe_push(tree, gc, inputs, input);
81237 + VEC_safe_push(tree, gc, outputs, output);
81238 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81239 + gimple_asm_set_volatile(asm_or_stmt, true);
81240 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81241 + update_stmt(asm_or_stmt);
81242 +
81243 + // replace call stmt fn with the new fptr
81244 + gimple_call_set_fn(call_stmt, new_fptr);
81245 + update_stmt(call_stmt);
81246 +}
81247 +
81248 +/*
81249 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81250 + */
81251 +static unsigned int execute_kernexec_fptr(void)
81252 +{
81253 + basic_block bb;
81254 +
81255 + // 1. loop through BBs and GIMPLE statements
81256 + FOR_EACH_BB(bb) {
81257 + gimple_stmt_iterator gsi;
81258 +
81259 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81260 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81261 + tree fn;
81262 + gimple call_stmt;
81263 +
81264 + // is it a call ...
81265 + call_stmt = gsi_stmt(gsi);
81266 + if (!is_gimple_call(call_stmt))
81267 + continue;
81268 + fn = gimple_call_fn(call_stmt);
81269 + if (TREE_CODE(fn) == ADDR_EXPR)
81270 + continue;
81271 + if (TREE_CODE(fn) != SSA_NAME)
81272 + gcc_unreachable();
81273 +
81274 + // ... through a function pointer
81275 + fn = SSA_NAME_VAR(fn);
81276 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81277 + continue;
81278 + fn = TREE_TYPE(fn);
81279 + if (TREE_CODE(fn) != POINTER_TYPE)
81280 + continue;
81281 + fn = TREE_TYPE(fn);
81282 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81283 + continue;
81284 +
81285 + kernexec_instrument_fptr(&gsi);
81286 +
81287 +//debug_tree(gimple_call_fn(call_stmt));
81288 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81289 + }
81290 + }
81291 +
81292 + return 0;
81293 +}
81294 +
81295 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81296 +static void kernexec_instrument_retaddr_bts(rtx insn)
81297 +{
81298 + rtx btsq;
81299 + rtvec argvec, constraintvec, labelvec;
81300 + int line;
81301 +
81302 + // create asm volatile("btsq $63,(%%rsp)":::)
81303 + argvec = rtvec_alloc(0);
81304 + constraintvec = rtvec_alloc(0);
81305 + labelvec = rtvec_alloc(0);
81306 + line = expand_location(RTL_LOCATION(insn)).line;
81307 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81308 + MEM_VOLATILE_P(btsq) = 1;
81309 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81310 + emit_insn_before(btsq, insn);
81311 +}
81312 +
81313 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81314 +static void kernexec_instrument_retaddr_or(rtx insn)
81315 +{
81316 + rtx orq;
81317 + rtvec argvec, constraintvec, labelvec;
81318 + int line;
81319 +
81320 + // create asm volatile("orq %%r10,(%%rsp)":::)
81321 + argvec = rtvec_alloc(0);
81322 + constraintvec = rtvec_alloc(0);
81323 + labelvec = rtvec_alloc(0);
81324 + line = expand_location(RTL_LOCATION(insn)).line;
81325 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81326 + MEM_VOLATILE_P(orq) = 1;
81327 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81328 + emit_insn_before(orq, insn);
81329 +}
81330 +
81331 +/*
81332 + * find all asm level function returns and forcibly set the highest bit of the return address
81333 + */
81334 +static unsigned int execute_kernexec_retaddr(void)
81335 +{
81336 + rtx insn;
81337 +
81338 + // 1. find function returns
81339 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81340 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81341 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81342 + rtx body;
81343 +
81344 + // is it a retn
81345 + if (!JUMP_P(insn))
81346 + continue;
81347 + body = PATTERN(insn);
81348 + if (GET_CODE(body) == PARALLEL)
81349 + body = XVECEXP(body, 0, 0);
81350 + if (GET_CODE(body) != RETURN)
81351 + continue;
81352 + kernexec_instrument_retaddr(insn);
81353 + }
81354 +
81355 +// print_simple_rtl(stderr, get_insns());
81356 +// print_rtl(stderr, get_insns());
81357 +
81358 + return 0;
81359 +}
81360 +
81361 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81362 +{
81363 + const char * const plugin_name = plugin_info->base_name;
81364 + const int argc = plugin_info->argc;
81365 + const struct plugin_argument * const argv = plugin_info->argv;
81366 + int i;
81367 + struct register_pass_info kernexec_reload_pass_info = {
81368 + .pass = &kernexec_reload_pass.pass,
81369 + .reference_pass_name = "ssa",
81370 + .ref_pass_instance_number = 0,
81371 + .pos_op = PASS_POS_INSERT_AFTER
81372 + };
81373 + struct register_pass_info kernexec_fptr_pass_info = {
81374 + .pass = &kernexec_fptr_pass.pass,
81375 + .reference_pass_name = "ssa",
81376 + .ref_pass_instance_number = 0,
81377 + .pos_op = PASS_POS_INSERT_AFTER
81378 + };
81379 + struct register_pass_info kernexec_retaddr_pass_info = {
81380 + .pass = &kernexec_retaddr_pass.pass,
81381 + .reference_pass_name = "pro_and_epilogue",
81382 + .ref_pass_instance_number = 0,
81383 + .pos_op = PASS_POS_INSERT_AFTER
81384 + };
81385 +
81386 + if (!plugin_default_version_check(version, &gcc_version)) {
81387 + error(G_("incompatible gcc/plugin versions"));
81388 + return 1;
81389 + }
81390 +
81391 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81392 +
81393 + if (TARGET_64BIT == 0)
81394 + return 0;
81395 +
81396 + for (i = 0; i < argc; ++i) {
81397 + if (!strcmp(argv[i].key, "method")) {
81398 + if (!argv[i].value) {
81399 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81400 + continue;
81401 + }
81402 + if (!strcmp(argv[i].value, "bts")) {
81403 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81404 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81405 + } else if (!strcmp(argv[i].value, "or")) {
81406 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81407 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81408 + fix_register("r10", 1, 1);
81409 + } else
81410 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81411 + continue;
81412 + }
81413 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81414 + }
81415 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81416 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81417 +
81418 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81419 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81420 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81421 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81422 +
81423 + return 0;
81424 +}
81425 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81426 new file mode 100644
81427 index 0000000..16ccac1
81428 --- /dev/null
81429 +++ b/tools/gcc/size_overflow_hash1.h
81430 @@ -0,0 +1,3047 @@
81431 +struct size_overflow_hash size_overflow_hash1[65536] = {
81432 + [10013].file = "security/smack/smackfs.c",
81433 + [10013].name = "smk_write_direct",
81434 + [10013].param3 = 1,
81435 + [10167].file = "sound/core/oss/pcm_plugin.c",
81436 + [10167].name = "snd_pcm_plugin_build",
81437 + [10167].param5 = 1,
81438 + [1020].file = "drivers/usb/misc/usbtest.c",
81439 + [1020].name = "test_unaligned_bulk",
81440 + [1020].param3 = 1,
81441 + [1022].file = "sound/pci/rme9652/rme9652.c",
81442 + [1022].name = "snd_rme9652_playback_copy",
81443 + [1022].param5 = 1,
81444 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
81445 + [10321].name = "create_attr_set",
81446 + [10321].param1 = 1,
81447 + [10341].file = "fs/nfsd/nfs4xdr.c",
81448 + [10341].name = "read_buf",
81449 + [10341].param2 = 1,
81450 + [10357].file = "net/sunrpc/cache.c",
81451 + [10357].name = "cache_read",
81452 + [10357].param3 = 1,
81453 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81454 + [10397].name = "i915_wedged_write",
81455 + [10397].param3 = 1,
81456 + [10399].file = "kernel/trace/trace.c",
81457 + [10399].name = "trace_seq_to_user",
81458 + [10399].param3 = 1,
81459 + [10414].file = "drivers/tty/vt/vt.c",
81460 + [10414].name = "vc_do_resize",
81461 + [10414].param3 = 1,
81462 + [10414].param4 = 1,
81463 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81464 + [10565].name = "ad7879_spi_multi_read",
81465 + [10565].param3 = 1,
81466 + [10623].file = "drivers/infiniband/core/user_mad.c",
81467 + [10623].name = "ib_umad_write",
81468 + [10623].param3 = 1,
81469 + [10707].file = "fs/nfs/idmap.c",
81470 + [10707].name = "nfs_idmap_request_key",
81471 + [10707].param2 = 1,
81472 + [1073].file = "drivers/block/aoe/aoecmd.c",
81473 + [1073].name = "addtgt",
81474 + [1073].param3 = 1,
81475 + [10745].file = "fs/cifs/connect.c",
81476 + [10745].name = "get_server_iovec",
81477 + [10745].param2 = 1,
81478 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
81479 + [10750].name = "iwm_ntf_calib_res",
81480 + [10750].param3 = 1,
81481 + [10773].file = "drivers/input/mousedev.c",
81482 + [10773].name = "mousedev_read",
81483 + [10773].param3 = 1,
81484 + [10777].file = "fs/ntfs/file.c",
81485 + [10777].name = "ntfs_file_buffered_write",
81486 + [10777].param6 = 1,
81487 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
81488 + [10893].name = "options_write",
81489 + [10893].param3 = 1,
81490 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81491 + [10919].name = "do_arpt_set_ctl",
81492 + [10919].param4 = 1,
81493 + [1107].file = "mm/process_vm_access.c",
81494 + [1107].name = "process_vm_rw_single_vec",
81495 + [1107].param1 = 1,
81496 + [1107].param2 = 1,
81497 + [11230].file = "net/core/neighbour.c",
81498 + [11230].name = "neigh_hash_grow",
81499 + [11230].param2 = 1,
81500 + [11364].file = "fs/ext4/super.c",
81501 + [11364].name = "ext4_kvzalloc",
81502 + [11364].param1 = 1,
81503 + [114].file = "security/selinux/selinuxfs.c",
81504 + [114].name = "sel_write_relabel",
81505 + [114].param3 = 1,
81506 + [11549].file = "drivers/media/rc/redrat3.c",
81507 + [11549].name = "redrat3_transmit_ir",
81508 + [11549].param3 = 1,
81509 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
81510 + [11568].name = "drm_vmalloc_dma",
81511 + [11568].param1 = 1,
81512 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
81513 + [11582].name = "lpfc_sli4_queue_alloc",
81514 + [11582].param3 = 1,
81515 + [11616].file = "security/selinux/selinuxfs.c",
81516 + [11616].name = "sel_write_enforce",
81517 + [11616].param3 = 1,
81518 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81519 + [11699].name = "vxge_os_dma_malloc",
81520 + [11699].param2 = 1,
81521 + [11766].file = "drivers/block/paride/pt.c",
81522 + [11766].name = "pt_read",
81523 + [11766].param3 = 1,
81524 + [11784].file = "fs/bio.c",
81525 + [11784].name = "bio_kmalloc",
81526 + [11784].param2 = 1,
81527 + [11919].file = "drivers/lguest/core.c",
81528 + [11919].name = "__lgread",
81529 + [11919].param4 = 1,
81530 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
81531 + [11925].name = "cx18_copy_mdl_to_user",
81532 + [11925].param4 = 1,
81533 + [11985].file = "drivers/block/floppy.c",
81534 + [11985].name = "fd_copyin",
81535 + [11985].param3 = 1,
81536 + [11986].file = "drivers/net/usb/asix.c",
81537 + [11986].name = "asix_read_cmd",
81538 + [11986].param5 = 1,
81539 + [12018].file = "sound/core/oss/pcm_oss.c",
81540 + [12018].name = "snd_pcm_oss_read1",
81541 + [12018].param3 = 1,
81542 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
81543 + [12059].name = "lbs_debugfs_write",
81544 + [12059].param3 = 1,
81545 + [12151].file = "fs/compat.c",
81546 + [12151].name = "compat_rw_copy_check_uvector",
81547 + [12151].param3 = 1,
81548 + [12205].file = "fs/reiserfs/journal.c",
81549 + [12205].name = "reiserfs_allocate_list_bitmaps",
81550 + [12205].param3 = 1,
81551 + [12234].file = "include/acpi/platform/aclinux.h",
81552 + [12234].name = "acpi_os_allocate",
81553 + [12234].param1 = 1,
81554 + [1227].file = "lib/cpu_rmap.c",
81555 + [1227].name = "alloc_cpu_rmap",
81556 + [1227].param1 = 1,
81557 + [12395].file = "drivers/char/hw_random/core.c",
81558 + [12395].name = "rng_dev_read",
81559 + [12395].param3 = 1,
81560 + [12602].file = "net/sunrpc/cache.c",
81561 + [12602].name = "cache_downcall",
81562 + [12602].param3 = 1,
81563 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
81564 + [12712].name = "i2400m_zrealloc_2x",
81565 + [12712].param3 = 1,
81566 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
81567 + [12755].name = "snd_opl4_mem_proc_read",
81568 + [12755].param5 = 1,
81569 + [12833].file = "net/sctp/auth.c",
81570 + [12833].name = "sctp_auth_create_key",
81571 + [12833].param1 = 1,
81572 + [12840].file = "net/sctp/tsnmap.c",
81573 + [12840].name = "sctp_tsnmap_mark",
81574 + [12840].param2 = 1,
81575 + [12931].file = "drivers/hid/hid-roccat.c",
81576 + [12931].name = "roccat_read",
81577 + [12931].param3 = 1,
81578 + [12954].file = "fs/proc/base.c",
81579 + [12954].name = "oom_adjust_write",
81580 + [12954].param3 = 1,
81581 + [13103].file = "drivers/acpi/acpica/utobject.c",
81582 + [13103].name = "acpi_ut_create_string_object",
81583 + [13103].param1 = 1,
81584 + [13121].file = "net/ipv4/ip_sockglue.c",
81585 + [13121].name = "do_ip_setsockopt",
81586 + [13121].param5 = 1,
81587 + [1327].file = "net/netfilter/nfnetlink_log.c",
81588 + [1327].name = "nfulnl_alloc_skb",
81589 + [1327].param2 = 1,
81590 + [13337].file = "net/core/iovec.c",
81591 + [13337].name = "csum_partial_copy_fromiovecend",
81592 + [13337].param4 = 1,
81593 + [13339].file = "security/smack/smackfs.c",
81594 + [13339].name = "smk_write_netlbladdr",
81595 + [13339].param3 = 1,
81596 + [13342].file = "fs/jbd2/journal.c",
81597 + [13342].name = "jbd2_alloc",
81598 + [13342].param1 = 1,
81599 + [13384].file = "drivers/char/virtio_console.c",
81600 + [13384].name = "alloc_buf",
81601 + [13384].param1 = 1,
81602 + [13412].file = "fs/proc/base.c",
81603 + [13412].name = "oom_score_adj_write",
81604 + [13412].param3 = 1,
81605 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
81606 + [13559].name = "ivtv_read",
81607 + [13559].param3 = 1,
81608 + [13618].file = "drivers/net/team/team.c",
81609 + [13618].name = "team_options_register",
81610 + [13618].param3 = 1,
81611 + [13659].file = "drivers/net/wan/hdlc.c",
81612 + [13659].name = "attach_hdlc_protocol",
81613 + [13659].param3 = 1,
81614 + [13708].file = "drivers/usb/misc/usbtest.c",
81615 + [13708].name = "simple_alloc_urb",
81616 + [13708].param3 = 1,
81617 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
81618 + [13805].name = "altera_swap_dr",
81619 + [13805].param2 = 1,
81620 + [13868].file = "fs/lockd/mon.c",
81621 + [13868].name = "nsm_create_handle",
81622 + [13868].param4 = 1,
81623 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
81624 + [13924].name = "do_ipt_set_ctl",
81625 + [13924].param4 = 1,
81626 + [14019].file = "net/dns_resolver/dns_key.c",
81627 + [14019].name = "dns_resolver_instantiate",
81628 + [14019].param2 = 1,
81629 + [14019].param3 = 1,
81630 + [14025].file = "net/ax25/af_ax25.c",
81631 + [14025].name = "ax25_setsockopt",
81632 + [14025].param5 = 1,
81633 + [14029].file = "drivers/spi/spidev.c",
81634 + [14029].name = "spidev_compat_ioctl",
81635 + [14029].param2 = 1,
81636 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
81637 + [14090].name = "btmrvl_hsmode_write",
81638 + [14090].param3 = 1,
81639 + [14149].file = "drivers/hid/hidraw.c",
81640 + [14149].name = "hidraw_ioctl",
81641 + [14149].param2 = 1,
81642 + [14153].file = "drivers/staging/bcm/led_control.c",
81643 + [14153].name = "ValidateDSDParamsChecksum",
81644 + [14153].param3 = 1,
81645 + [14174].file = "sound/pci/es1938.c",
81646 + [14174].name = "snd_es1938_capture_copy",
81647 + [14174].param5 = 1,
81648 + [14207].file = "drivers/media/video/v4l2-event.c",
81649 + [14207].name = "v4l2_event_subscribe",
81650 + [14207].param3 = 1,
81651 + [14241].file = "drivers/platform/x86/asus_acpi.c",
81652 + [14241].name = "brn_proc_write",
81653 + [14241].param3 = 1,
81654 + [14345].file = "fs/cachefiles/daemon.c",
81655 + [14345].name = "cachefiles_daemon_write",
81656 + [14345].param3 = 1,
81657 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
81658 + [14347].name = "dvb_ca_en50221_io_write",
81659 + [14347].param3 = 1,
81660 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
81661 + [14566].name = "alloc_ebda_hpc",
81662 + [14566].param1 = 1,
81663 + [14566].param2 = 1,
81664 + [1458].file = "drivers/misc/lkdtm.c",
81665 + [1458].name = "direct_entry",
81666 + [1458].param3 = 1,
81667 + [14646].file = "fs/compat.c",
81668 + [14646].name = "compat_writev",
81669 + [14646].param3 = 1,
81670 + [14684].file = "drivers/media/video/stk-webcam.c",
81671 + [14684].name = "stk_allocate_buffers",
81672 + [14684].param2 = 1,
81673 + [14736].file = "drivers/usb/misc/usbtest.c",
81674 + [14736].name = "unlink_queued",
81675 + [14736].param3 = 1,
81676 + [1482].file = "drivers/scsi/scsi_netlink.c",
81677 + [1482].name = "scsi_nl_send_vendor_msg",
81678 + [1482].param5 = 1,
81679 + [15017].file = "drivers/edac/edac_device.c",
81680 + [15017].name = "edac_device_alloc_ctl_info",
81681 + [15017].param1 = 1,
81682 + [15044].file = "drivers/uio/uio.c",
81683 + [15044].name = "uio_write",
81684 + [15044].param3 = 1,
81685 + [15087].file = "fs/bio.c",
81686 + [15087].name = "bio_map_kern",
81687 + [15087].param2 = 1,
81688 + [15087].param3 = 1,
81689 + [15112].file = "drivers/xen/evtchn.c",
81690 + [15112].name = "evtchn_write",
81691 + [15112].param3 = 1,
81692 + [15130].file = "net/bluetooth/hci_core.c",
81693 + [15130].name = "hci_send_cmd",
81694 + [15130].param3 = 1,
81695 + [15202].file = "net/bluetooth/rfcomm/tty.c",
81696 + [15202].name = "rfcomm_wmalloc",
81697 + [15202].param2 = 1,
81698 + [15274].file = "crypto/shash.c",
81699 + [15274].name = "crypto_shash_setkey",
81700 + [15274].param3 = 1,
81701 + [15354].file = "drivers/isdn/mISDN/socket.c",
81702 + [15354].name = "mISDN_sock_sendmsg",
81703 + [15354].param4 = 1,
81704 + [15361].file = "drivers/char/agp/generic.c",
81705 + [15361].name = "agp_allocate_memory",
81706 + [15361].param2 = 1,
81707 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
81708 + [15497].name = "ts_read",
81709 + [15497].param3 = 1,
81710 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
81711 + [15551].name = "clusterip_proc_write",
81712 + [15551].param3 = 1,
81713 + [15701].file = "drivers/hid/hid-roccat-common.c",
81714 + [15701].name = "roccat_common_receive",
81715 + [15701].param4 = 1,
81716 + [1572].file = "net/ceph/pagevec.c",
81717 + [1572].name = "ceph_copy_page_vector_to_user",
81718 + [1572].param4 = 1,
81719 + [15814].file = "net/mac80211/debugfs_netdev.c",
81720 + [15814].name = "ieee80211_if_write",
81721 + [15814].param3 = 1,
81722 + [15883].file = "security/keys/keyctl.c",
81723 + [15883].name = "sys_add_key",
81724 + [15883].param4 = 1,
81725 + [15884].file = "fs/exofs/super.c",
81726 + [15884].name = "exofs_read_lookup_dev_table",
81727 + [15884].param3 = 1,
81728 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
81729 + [16037].name = "easycap_alsa_vmalloc",
81730 + [16037].param2 = 1,
81731 + [16073].file = "net/sctp/socket.c",
81732 + [16073].name = "sctp_setsockopt",
81733 + [16073].param5 = 1,
81734 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
81735 + [16132].name = "buffer_from_user",
81736 + [16132].param3 = 1,
81737 + [16138].file = "security/selinux/ss/services.c",
81738 + [16138].name = "security_context_to_sid_force",
81739 + [16138].param2 = 1,
81740 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
81741 + [16166].name = "dispatch_proc_write",
81742 + [16166].param3 = 1,
81743 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
81744 + [16229].name = "iscsi_offload_mesg",
81745 + [16229].param5 = 1,
81746 + [16353].file = "drivers/base/regmap/regmap.c",
81747 + [16353].name = "regmap_raw_write",
81748 + [16353].param4 = 1,
81749 + [16383].file = "fs/proc/base.c",
81750 + [16383].name = "comm_write",
81751 + [16383].param3 = 1,
81752 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
81753 + [16396].name = "altera_irscan",
81754 + [16396].param2 = 1,
81755 + [16447].file = "drivers/hid/usbhid/hiddev.c",
81756 + [16447].name = "hiddev_ioctl",
81757 + [16447].param2 = 1,
81758 + [16453].file = "include/linux/slab.h",
81759 + [16453].name = "kzalloc",
81760 + [16453].param1 = 1,
81761 + [16605].file = "fs/ecryptfs/miscdev.c",
81762 + [16605].name = "ecryptfs_send_miscdev",
81763 + [16605].param2 = 1,
81764 + [16606].file = "drivers/ide/ide-tape.c",
81765 + [16606].name = "idetape_chrdev_write",
81766 + [16606].param3 = 1,
81767 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
81768 + [16637].name = "datablob_hmac_verify",
81769 + [16637].param4 = 1,
81770 + [16828].file = "net/batman-adv/hash.c",
81771 + [16828].name = "hash_new",
81772 + [16828].param1 = 1,
81773 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
81774 + [16853].name = "t4vf_pktgl_to_skb",
81775 + [16853].param2 = 1,
81776 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
81777 + [16911].name = "LoadBitmap",
81778 + [16911].param2 = 1,
81779 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
81780 + [169].name = "pcnet32_realloc_rx_ring",
81781 + [169].param3 = 1,
81782 + [17075].file = "sound/isa/gus/gus_dram.c",
81783 + [17075].name = "snd_gus_dram_write",
81784 + [17075].param4 = 1,
81785 + [17133].file = "drivers/usb/misc/iowarrior.c",
81786 + [17133].name = "iowarrior_read",
81787 + [17133].param3 = 1,
81788 + [17185].file = "net/wireless/scan.c",
81789 + [17185].name = "cfg80211_inform_bss",
81790 + [17185].param8 = 1,
81791 + [17349].file = "net/tipc/link.c",
81792 + [17349].name = "tipc_link_send_sections_fast",
81793 + [17349].param4 = 1,
81794 + [17377].file = "drivers/usb/class/cdc-wdm.c",
81795 + [17377].name = "wdm_write",
81796 + [17377].param3 = 1,
81797 + [17459].file = "drivers/usb/misc/rio500.c",
81798 + [17459].name = "write_rio",
81799 + [17459].param3 = 1,
81800 + [17460].file = "fs/nfsd/nfscache.c",
81801 + [17460].name = "nfsd_cache_update",
81802 + [17460].param3 = 1,
81803 + [17492].file = "net/dccp/proto.c",
81804 + [17492].name = "do_dccp_setsockopt",
81805 + [17492].param5 = 1,
81806 + [1754].file = "sound/core/oss/pcm_oss.c",
81807 + [1754].name = "snd_pcm_oss_write",
81808 + [1754].param3 = 1,
81809 + [17604].file = "fs/proc/generic.c",
81810 + [17604].name = "__proc_file_read",
81811 + [17604].param3 = 1,
81812 + [17718].file = "net/caif/caif_socket.c",
81813 + [17718].name = "setsockopt",
81814 + [17718].param5 = 1,
81815 + [17828].file = "kernel/sched/core.c",
81816 + [17828].name = "sched_feat_write",
81817 + [17828].param3 = 1,
81818 + [17841].file = "drivers/misc/tifm_core.c",
81819 + [17841].name = "tifm_alloc_adapter",
81820 + [17841].param1 = 1,
81821 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
81822 + [17946].name = "if_spi_host_to_card",
81823 + [17946].param4 = 1,
81824 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
81825 + [1800].name = "dvb_dvr_do_ioctl",
81826 + [1800].param3 = 1,
81827 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
81828 + [18119].name = "iwmct_fw_parser_init",
81829 + [18119].param4 = 1,
81830 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
81831 + [18140].name = "pm8001_store_update_fw",
81832 + [18140].param4 = 1,
81833 + [18191].file = "sound/pci/hda/patch_realtek.c",
81834 + [18191].name = "new_bind_ctl",
81835 + [18191].param2 = 1,
81836 + [18224].file = "drivers/xen/grant-table.c",
81837 + [18224].name = "gnttab_map",
81838 + [18224].param2 = 1,
81839 + [18232].file = "fs/nfs/write.c",
81840 + [18232].name = "nfs_writedata_alloc",
81841 + [18232].param1 = 1,
81842 + [18247].file = "drivers/char/agp/generic.c",
81843 + [18247].name = "agp_create_user_memory",
81844 + [18247].param1 = 1,
81845 + [18303].file = "fs/xattr.c",
81846 + [18303].name = "getxattr",
81847 + [18303].param4 = 1,
81848 + [18353].file = "net/rfkill/core.c",
81849 + [18353].name = "rfkill_fop_read",
81850 + [18353].param3 = 1,
81851 + [18386].file = "fs/read_write.c",
81852 + [18386].name = "vfs_readv",
81853 + [18386].param3 = 1,
81854 + [18391].file = "fs/ocfs2/stack_user.c",
81855 + [18391].name = "ocfs2_control_write",
81856 + [18391].param3 = 1,
81857 + [183].file = "crypto/ahash.c",
81858 + [183].name = "crypto_ahash_setkey",
81859 + [183].param3 = 1,
81860 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
81861 + [18406].name = "tm6000_read_write_usb",
81862 + [18406].param7 = 1,
81863 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
81864 + [1845].name = "rt2x00debug_write_rf",
81865 + [1845].param3 = 1,
81866 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
81867 + [18465].name = "cxgb_alloc_mem",
81868 + [18465].param1 = 1,
81869 + [184].file = "drivers/firewire/nosy.c",
81870 + [184].name = "packet_buffer_init",
81871 + [184].param2 = 1,
81872 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
81873 + [1858].name = "do_ip6t_set_ctl",
81874 + [1858].param4 = 1,
81875 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
81876 + [18659].name = "dvb_usercopy",
81877 + [18659].param2 = 1,
81878 + [18722].file = "security/tomoyo/condition.c",
81879 + [18722].name = "tomoyo_scan_bprm",
81880 + [18722].param2 = 1,
81881 + [18722].param4 = 1,
81882 + [18775].file = "include/linux/textsearch.h",
81883 + [18775].name = "alloc_ts_config",
81884 + [18775].param1 = 1,
81885 + [18940].file = "drivers/usb/host/hwa-hc.c",
81886 + [18940].name = "__hwahc_op_set_gtk",
81887 + [18940].param4 = 1,
81888 + [19012].file = "drivers/acpi/event.c",
81889 + [19012].name = "acpi_system_read_event",
81890 + [19012].param3 = 1,
81891 + [19028].file = "mm/filemap.c",
81892 + [19028].name = "iov_iter_copy_from_user_atomic",
81893 + [19028].param4 = 1,
81894 + [19107].file = "security/smack/smackfs.c",
81895 + [19107].name = "smk_write_load_list",
81896 + [19107].param3 = 1,
81897 + [19240].file = "net/sctp/socket.c",
81898 + [19240].name = "sctp_setsockopt_delayed_ack",
81899 + [19240].param3 = 1,
81900 + [19274].file = "net/core/pktgen.c",
81901 + [19274].name = "pktgen_if_write",
81902 + [19274].param3 = 1,
81903 + [19286].file = "drivers/base/regmap/regmap.c",
81904 + [19286].name = "_regmap_raw_write",
81905 + [19286].param4 = 1,
81906 + [19308].file = "drivers/char/mem.c",
81907 + [19308].name = "read_oldmem",
81908 + [19308].param3 = 1,
81909 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
81910 + [19343].name = "datablob_hmac_append",
81911 + [19343].param3 = 1,
81912 + [19349].file = "drivers/acpi/acpica/utobject.c",
81913 + [19349].name = "acpi_ut_create_package_object",
81914 + [19349].param1 = 1,
81915 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
81916 + [19453].name = "sge_rx",
81917 + [19453].param3 = 1,
81918 + [19504].file = "drivers/usb/serial/garmin_gps.c",
81919 + [19504].name = "pkt_add",
81920 + [19504].param3 = 1,
81921 + [19522].file = "mm/percpu.c",
81922 + [19522].name = "pcpu_mem_zalloc",
81923 + [19522].param1 = 1,
81924 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
81925 + [19548].name = "qla2x00_get_ctx_sp",
81926 + [19548].param3 = 1,
81927 + [19592].file = "net/dccp/proto.c",
81928 + [19592].name = "dccp_setsockopt_service",
81929 + [19592].param4 = 1,
81930 + [19726].file = "kernel/trace/trace.c",
81931 + [19726].name = "tracing_set_trace_write",
81932 + [19726].param3 = 1,
81933 + [19738].file = "fs/sysfs/file.c",
81934 + [19738].name = "sysfs_write_file",
81935 + [19738].param3 = 1,
81936 + [19833].file = "drivers/xen/privcmd.c",
81937 + [19833].name = "gather_array",
81938 + [19833].param3 = 1,
81939 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
81940 + [19910].name = "saa7164_buffer_alloc_user",
81941 + [19910].param2 = 1,
81942 + [19920].file = "drivers/input/joydev.c",
81943 + [19920].name = "joydev_ioctl",
81944 + [19920].param2 = 1,
81945 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
81946 + [19931].name = "ftdi_elan_write",
81947 + [19931].param3 = 1,
81948 + [19960].file = "drivers/usb/class/usblp.c",
81949 + [19960].name = "usblp_read",
81950 + [19960].param3 = 1,
81951 + [1996].file = "drivers/scsi/libsrp.c",
81952 + [1996].name = "srp_target_alloc",
81953 + [1996].param3 = 1,
81954 + [20023].file = "drivers/media/video/gspca/gspca.c",
81955 + [20023].name = "dev_read",
81956 + [20023].param3 = 1,
81957 + [20207].file = "net/core/sock.c",
81958 + [20207].name = "sock_alloc_send_pskb",
81959 + [20207].param2 = 1,
81960 + [20263].file = "kernel/trace/trace_events.c",
81961 + [20263].name = "event_filter_write",
81962 + [20263].param3 = 1,
81963 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
81964 + [20314].name = "drm_ht_create",
81965 + [20314].param2 = 1,
81966 + [20320].file = "drivers/mfd/sm501.c",
81967 + [20320].name = "sm501_create_subdev",
81968 + [20320].param3 = 1,
81969 + [20320].param4 = 1,
81970 + [20376].file = "mm/nobootmem.c",
81971 + [20376].name = "__alloc_bootmem_nopanic",
81972 + [20376].param1 = 1,
81973 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
81974 + [20409].name = "opera1_usb_i2c_msgxfer",
81975 + [20409].param4 = 1,
81976 + [20473].file = "drivers/mtd/mtdchar.c",
81977 + [20473].name = "mtdchar_write",
81978 + [20473].param3 = 1,
81979 + [20611].file = "net/netfilter/x_tables.c",
81980 + [20611].name = "xt_alloc_table_info",
81981 + [20611].param1 = 1,
81982 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
81983 + [20618].name = "chd_dec_fetch_cdata",
81984 + [20618].param3 = 1,
81985 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
81986 + [20713].name = "ttm_bo_io",
81987 + [20713].param5 = 1,
81988 + [20801].file = "drivers/vhost/vhost.c",
81989 + [20801].name = "vhost_add_used_n",
81990 + [20801].param3 = 1,
81991 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
81992 + [20835].name = "isdn_read",
81993 + [20835].param3 = 1,
81994 + [20951].file = "crypto/rng.c",
81995 + [20951].name = "rngapi_reset",
81996 + [20951].param3 = 1,
81997 + [21125].file = "fs/gfs2/dir.c",
81998 + [21125].name = "gfs2_alloc_sort_buffer",
81999 + [21125].param1 = 1,
82000 + [21132].file = "kernel/cgroup.c",
82001 + [21132].name = "cgroup_write_X64",
82002 + [21132].param5 = 1,
82003 + [21138].file = "drivers/uio/uio.c",
82004 + [21138].name = "uio_read",
82005 + [21138].param3 = 1,
82006 + [21193].file = "net/wireless/sme.c",
82007 + [21193].name = "cfg80211_disconnected",
82008 + [21193].param4 = 1,
82009 + [21312].file = "lib/ts_kmp.c",
82010 + [21312].name = "kmp_init",
82011 + [21312].param2 = 1,
82012 + [21335].file = "net/econet/af_econet.c",
82013 + [21335].name = "econet_sendmsg",
82014 + [21335].param4 = 1,
82015 + [21406].file = "fs/libfs.c",
82016 + [21406].name = "simple_write_to_buffer",
82017 + [21406].param2 = 1,
82018 + [21406].param5 = 1,
82019 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82020 + [21451].name = "do_ip_vs_set_ctl",
82021 + [21451].param4 = 1,
82022 + [21459].file = "security/smack/smackfs.c",
82023 + [21459].name = "smk_write_doi",
82024 + [21459].param3 = 1,
82025 + [21508].file = "include/linux/usb/wusb.h",
82026 + [21508].name = "wusb_prf_64",
82027 + [21508].param7 = 1,
82028 + [21511].file = "drivers/input/ff-core.c",
82029 + [21511].name = "input_ff_create",
82030 + [21511].param2 = 1,
82031 + [21538].file = "net/bluetooth/l2cap_sock.c",
82032 + [21538].name = "l2cap_sock_setsockopt",
82033 + [21538].param5 = 1,
82034 + [21543].file = "drivers/media/video/gspca/gspca.c",
82035 + [21543].name = "frame_alloc",
82036 + [21543].param4 = 1,
82037 + [21608].file = "drivers/char/tpm/tpm.c",
82038 + [21608].name = "tpm_write",
82039 + [21608].param3 = 1,
82040 + [2160].file = "drivers/net/wireless/ray_cs.c",
82041 + [2160].name = "int_proc_write",
82042 + [2160].param3 = 1,
82043 + [21632].file = "fs/afs/cell.c",
82044 + [21632].name = "afs_cell_create",
82045 + [21632].param2 = 1,
82046 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82047 + [21679].name = "carl9170_debugfs_write",
82048 + [21679].param3 = 1,
82049 + [21784].file = "crypto/ahash.c",
82050 + [21784].name = "ahash_setkey_unaligned",
82051 + [21784].param3 = 1,
82052 + [2180].file = "drivers/char/ppdev.c",
82053 + [2180].name = "pp_write",
82054 + [2180].param3 = 1,
82055 + [21810].file = "net/core/netprio_cgroup.c",
82056 + [21810].name = "extend_netdev_table",
82057 + [21810].param2 = 1,
82058 + [21906].file = "net/atm/mpc.c",
82059 + [21906].name = "copy_macs",
82060 + [21906].param4 = 1,
82061 + [21946].file = "fs/nfs/idmap.c",
82062 + [21946].name = "nfs_map_name_to_uid",
82063 + [21946].param3 = 1,
82064 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
82065 + [22052].name = "get_packet_pg",
82066 + [22052].param4 = 1,
82067 + [22085].file = "drivers/staging/sep/sep_driver.c",
82068 + [22085].name = "sep_lock_user_pages",
82069 + [22085].param2 = 1,
82070 + [22085].param3 = 1,
82071 + [22190].file = "drivers/char/tpm/tpm.c",
82072 + [22190].name = "tpm_read",
82073 + [22190].param3 = 1,
82074 + [22291].file = "net/core/pktgen.c",
82075 + [22291].name = "pgctrl_write",
82076 + [22291].param3 = 1,
82077 + [22439].file = "fs/afs/rxrpc.c",
82078 + [22439].name = "afs_alloc_flat_call",
82079 + [22439].param2 = 1,
82080 + [22439].param3 = 1,
82081 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82082 + [2243].name = "scsi_tgt_kspace_exec",
82083 + [2243].param8 = 1,
82084 + [22440].file = "drivers/uwb/neh.c",
82085 + [22440].name = "uwb_rc_neh_grok_event",
82086 + [22440].param3 = 1,
82087 + [22611].file = "drivers/staging/android/logger.c",
82088 + [22611].name = "do_write_log_from_user",
82089 + [22611].param3 = 1,
82090 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
82091 + [22614].name = "cx18_copy_buf_to_user",
82092 + [22614].param4 = 1,
82093 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
82094 + [22667].name = "altera_set_ir_post",
82095 + [22667].param2 = 1,
82096 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82097 + [22772].name = "iscsit_dump_data_payload",
82098 + [22772].param2 = 1,
82099 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
82100 + [22777].name = "srp_alloc_iu",
82101 + [22777].param2 = 1,
82102 + [22811].file = "drivers/usb/dwc3/debugfs.c",
82103 + [22811].name = "dwc3_mode_write",
82104 + [22811].param3 = 1,
82105 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
82106 + [22817].name = "usbvision_rvmalloc",
82107 + [22817].param1 = 1,
82108 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82109 + [22864].name = "ath6kl_add_bss_if_needed",
82110 + [22864].param6 = 1,
82111 + [2286].file = "drivers/scsi/mvumi.c",
82112 + [2286].name = "mvumi_alloc_mem_resource",
82113 + [2286].param3 = 1,
82114 + [22904].file = "security/selinux/ss/services.c",
82115 + [22904].name = "security_context_to_sid_default",
82116 + [22904].param2 = 1,
82117 + [22932].file = "fs/compat.c",
82118 + [22932].name = "compat_sys_writev",
82119 + [22932].param3 = 1,
82120 + [2302].file = "drivers/media/video/stk-webcam.c",
82121 + [2302].name = "v4l_stk_read",
82122 + [2302].param3 = 1,
82123 + [2307].file = "drivers/pcmcia/cistpl.c",
82124 + [2307].name = "pcmcia_replace_cis",
82125 + [2307].param3 = 1,
82126 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82127 + [23117].name = "dvb_audio_write",
82128 + [23117].param3 = 1,
82129 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82130 + [23220].name = "do_dmabuf_dirty_sou",
82131 + [23220].param7 = 1,
82132 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
82133 + [23232].name = "sm_checker_extend",
82134 + [23232].param2 = 1,
82135 + [2324].file = "net/ieee802154/wpan-class.c",
82136 + [2324].name = "wpan_phy_alloc",
82137 + [2324].param1 = 1,
82138 + [2328].file = "kernel/trace/ftrace.c",
82139 + [2328].name = "ftrace_pid_write",
82140 + [2328].param3 = 1,
82141 + [23290].file = "fs/proc/base.c",
82142 + [23290].name = "mem_rw",
82143 + [23290].param3 = 1,
82144 + [23449].file = "crypto/blkcipher.c",
82145 + [23449].name = "blkcipher_next_slow",
82146 + [23449].param3 = 1,
82147 + [23449].param4 = 1,
82148 + [23535].file = "ipc/sem.c",
82149 + [23535].name = "sys_semtimedop",
82150 + [23535].param3 = 1,
82151 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82152 + [2357].name = "garmin_read_process",
82153 + [2357].param3 = 1,
82154 + [23589].file = "kernel/relay.c",
82155 + [23589].name = "subbuf_read_actor",
82156 + [23589].param3 = 1,
82157 + [23848].file = "crypto/blkcipher.c",
82158 + [23848].name = "async_setkey",
82159 + [23848].param3 = 1,
82160 + [2386].file = "drivers/acpi/acpica/exnames.c",
82161 + [2386].name = "acpi_ex_allocate_name_string",
82162 + [2386].param2 = 1,
82163 + [2389].file = "net/core/sock.c",
82164 + [2389].name = "sock_rmalloc",
82165 + [2389].param2 = 1,
82166 + [23994].file = "net/bluetooth/mgmt.c",
82167 + [23994].name = "set_powered",
82168 + [23994].param4 = 1,
82169 + [23999].file = "sound/pci/rme9652/hdsp.c",
82170 + [23999].name = "snd_hdsp_capture_copy",
82171 + [23999].param5 = 1,
82172 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82173 + [24233].name = "aer_inject_write",
82174 + [24233].param3 = 1,
82175 + [24359].file = "kernel/power/qos.c",
82176 + [24359].name = "pm_qos_power_write",
82177 + [24359].param3 = 1,
82178 + [24457].file = "fs/btrfs/backref.c",
82179 + [24457].name = "init_data_container",
82180 + [24457].param1 = 1,
82181 + [24719].file = "drivers/input/evdev.c",
82182 + [24719].name = "bits_to_user",
82183 + [24719].param3 = 1,
82184 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82185 + [2472].name = "compat_do_ipt_set_ctl",
82186 + [2472].param4 = 1,
82187 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82188 + [24755].name = "qib_diag_write",
82189 + [24755].param3 = 1,
82190 + [24805].file = "security/keys/user_defined.c",
82191 + [24805].name = "user_update",
82192 + [24805].param3 = 1,
82193 + [25036].file = "fs/pipe.c",
82194 + [25036].name = "pipe_iov_copy_from_user",
82195 + [25036].param3 = 1,
82196 + [25078].file = "drivers/net/wireless/p54/fwio.c",
82197 + [25078].name = "p54_download_eeprom",
82198 + [25078].param4 = 1,
82199 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82200 + [25127].name = "realloc_buffer",
82201 + [25127].param2 = 1,
82202 + [25145].file = "net/tipc/link.c",
82203 + [25145].name = "link_send_sections_long",
82204 + [25145].param4 = 1,
82205 + [25157].file = "security/keys/request_key_auth.c",
82206 + [25157].name = "request_key_auth_new",
82207 + [25157].param3 = 1,
82208 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82209 + [25158].name = "mlx4_en_create_rx_ring",
82210 + [25158].param3 = 1,
82211 + [25267].file = "fs/configfs/file.c",
82212 + [25267].name = "configfs_write_file",
82213 + [25267].param3 = 1,
82214 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82215 + [25495].name = "bfad_debugfs_write_regwr",
82216 + [25495].param3 = 1,
82217 + [25558].file = "fs/proc/task_mmu.c",
82218 + [25558].name = "clear_refs_write",
82219 + [25558].param3 = 1,
82220 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82221 + [25692].name = "ath6kl_wmi_send_action_cmd",
82222 + [25692].param7 = 1,
82223 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
82224 + [25765].name = "flexcop_device_kmalloc",
82225 + [25765].param1 = 1,
82226 + [26100].file = "sound/core/info.c",
82227 + [26100].name = "snd_info_entry_write",
82228 + [26100].param3 = 1,
82229 + [26256].file = "fs/hpfs/name.c",
82230 + [26256].name = "hpfs_translate_name",
82231 + [26256].param3 = 1,
82232 + [26394].file = "drivers/hid/hidraw.c",
82233 + [26394].name = "hidraw_get_report",
82234 + [26394].param3 = 1,
82235 + [26494].file = "kernel/signal.c",
82236 + [26494].name = "sys_rt_sigpending",
82237 + [26494].param2 = 1,
82238 + [26497].file = "security/keys/keyctl.c",
82239 + [26497].name = "sys_keyctl",
82240 + [26497].param4 = 1,
82241 + [26533].file = "drivers/block/aoe/aoechr.c",
82242 + [26533].name = "aoechr_write",
82243 + [26533].param3 = 1,
82244 + [26560].file = "crypto/algapi.c",
82245 + [26560].name = "crypto_alloc_instance2",
82246 + [26560].param3 = 1,
82247 + [26605].file = "security/selinux/selinuxfs.c",
82248 + [26605].name = "sel_write_user",
82249 + [26605].param3 = 1,
82250 + [26620].file = "net/bluetooth/mgmt.c",
82251 + [26620].name = "mgmt_control",
82252 + [26620].param3 = 1,
82253 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82254 + [26701].name = "cfi_read_pri",
82255 + [26701].param3 = 1,
82256 + [26757].file = "fs/xattr.c",
82257 + [26757].name = "sys_fgetxattr",
82258 + [26757].param4 = 1,
82259 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82260 + [2678].name = "disp_proc_write",
82261 + [2678].param3 = 1,
82262 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82263 + [26834].name = "drm_ioctl",
82264 + [26834].param2 = 1,
82265 + [26843].file = "drivers/firewire/core-cdev.c",
82266 + [26843].name = "fw_device_op_compat_ioctl",
82267 + [26843].param2 = 1,
82268 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82269 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82270 + [26845].param3 = 1,
82271 + [26888].file = "net/bridge/br_ioctl.c",
82272 + [26888].name = "get_fdb_entries",
82273 + [26888].param3 = 1,
82274 + [26962].file = "drivers/usb/class/usbtmc.c",
82275 + [26962].name = "usbtmc_write",
82276 + [26962].param3 = 1,
82277 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82278 + [26966].name = "ts_write",
82279 + [26966].param3 = 1,
82280 + [27004].file = "drivers/misc/hpilo.c",
82281 + [27004].name = "ilo_write",
82282 + [27004].param3 = 1,
82283 + [27025].file = "fs/ntfs/file.c",
82284 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82285 + [27025].param3 = 1,
82286 + [27025].param4 = 1,
82287 + [27061].file = "drivers/firewire/core-cdev.c",
82288 + [27061].name = "iso_callback",
82289 + [27061].param3 = 1,
82290 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82291 + [2711].name = "dvb_ringbuffer_read_user",
82292 + [2711].param3 = 1,
82293 + [27129].file = "fs/lockd/mon.c",
82294 + [27129].name = "nsm_get_handle",
82295 + [27129].param4 = 1,
82296 + [27142].file = "fs/proc/kcore.c",
82297 + [27142].name = "read_kcore",
82298 + [27142].param3 = 1,
82299 + [27164].file = "include/drm/drm_mem_util.h",
82300 + [27164].name = "drm_calloc_large",
82301 + [27164].param1 = 1,
82302 + [27164].param2 = 1,
82303 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
82304 + [27176].name = "otp_read",
82305 + [27176].param2 = 1,
82306 + [27176].param5 = 1,
82307 + [27232].file = "security/apparmor/lib.c",
82308 + [27232].name = "kvmalloc",
82309 + [27232].param1 = 1,
82310 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82311 + [27275].name = "cxgbi_ddp_reserve",
82312 + [27275].param4 = 1,
82313 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82314 + [27280].name = "mlx4_en_create_tx_ring",
82315 + [27280].param4 = 1,
82316 + [27290].file = "security/selinux/ss/services.c",
82317 + [27290].name = "security_context_to_sid_core",
82318 + [27290].param2 = 1,
82319 + [27302].file = "fs/proc/base.c",
82320 + [27302].name = "proc_loginuid_write",
82321 + [27302].param3 = 1,
82322 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
82323 + [2730].name = "iscsi_decode_text_input",
82324 + [2730].param4 = 1,
82325 + [27314].file = "net/bluetooth/mgmt.c",
82326 + [27314].name = "cmd_complete",
82327 + [27314].param5 = 1,
82328 + [27472].file = "security/selinux/selinuxfs.c",
82329 + [27472].name = "sel_write_load",
82330 + [27472].param3 = 1,
82331 + [27491].file = "fs/proc/base.c",
82332 + [27491].name = "proc_pid_attr_write",
82333 + [27491].param3 = 1,
82334 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82335 + [27568].name = "t4_alloc_mem",
82336 + [27568].param1 = 1,
82337 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82338 + [27582].name = "ledd_proc_write",
82339 + [27582].param3 = 1,
82340 + [27595].file = "net/core/sock.c",
82341 + [27595].name = "sock_alloc_send_skb",
82342 + [27595].param2 = 1,
82343 + [27648].file = "net/bluetooth/l2cap_core.c",
82344 + [27648].name = "l2cap_bredr_sig_cmd",
82345 + [27648].param3 = 1,
82346 + [27697].file = "drivers/staging/mei/iorw.c",
82347 + [27697].name = "amthi_read",
82348 + [27697].param4 = 1,
82349 + [27911].file = "fs/ext4/resize.c",
82350 + [27911].name = "alloc_flex_gd",
82351 + [27911].param1 = 1,
82352 + [27927].file = "drivers/tty/tty_io.c",
82353 + [27927].name = "redirected_tty_write",
82354 + [27927].param3 = 1,
82355 + [28040].file = "kernel/kfifo.c",
82356 + [28040].name = "__kfifo_alloc",
82357 + [28040].param2 = 1,
82358 + [28040].param3 = 1,
82359 + [28151].file = "mm/filemap_xip.c",
82360 + [28151].name = "do_xip_mapping_read",
82361 + [28151].param5 = 1,
82362 + [28247].file = "net/sctp/tsnmap.c",
82363 + [28247].name = "sctp_tsnmap_init",
82364 + [28247].param2 = 1,
82365 + [28253].file = "include/linux/fb.h",
82366 + [28253].name = "alloc_apertures",
82367 + [28253].param1 = 1,
82368 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82369 + [28265].name = "fanotify_write",
82370 + [28265].param3 = 1,
82371 + [28316].file = "drivers/input/joydev.c",
82372 + [28316].name = "joydev_ioctl_common",
82373 + [28316].param2 = 1,
82374 + [28359].file = "drivers/spi/spidev.c",
82375 + [28359].name = "spidev_message",
82376 + [28359].param3 = 1,
82377 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82378 + [28360].name = "hiddev_compat_ioctl",
82379 + [28360].param2 = 1,
82380 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82381 + [28407].name = "rt2x00debug_write_csr",
82382 + [28407].param3 = 1,
82383 + [2847].file = "fs/ntfs/file.c",
82384 + [2847].name = "ntfs_copy_from_user",
82385 + [2847].param3 = 1,
82386 + [2847].param5 = 1,
82387 + [28584].file = "drivers/memstick/core/memstick.c",
82388 + [28584].name = "memstick_alloc_host",
82389 + [28584].param1 = 1,
82390 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82391 + [28783].name = "i915_cache_sharing_write",
82392 + [28783].param3 = 1,
82393 + [28787].file = "drivers/media/video/videobuf2-core.c",
82394 + [28787].name = "vb2_write",
82395 + [28787].param3 = 1,
82396 + [28879].file = "drivers/base/map.c",
82397 + [28879].name = "kobj_map",
82398 + [28879].param2 = 1,
82399 + [28879].param3 = 1,
82400 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82401 + [28889].name = "cm4040_write",
82402 + [28889].param3 = 1,
82403 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82404 + [29073].name = "vmw_kms_readback",
82405 + [29073].param6 = 1,
82406 + [29085].file = "security/apparmor/apparmorfs.c",
82407 + [29085].name = "profile_load",
82408 + [29085].param3 = 1,
82409 + [29092].file = "lib/lru_cache.c",
82410 + [29092].name = "lc_create",
82411 + [29092].param3 = 1,
82412 + [29257].file = "drivers/vhost/vhost.c",
82413 + [29257].name = "vhost_add_used_and_signal_n",
82414 + [29257].param4 = 1,
82415 + [29267].file = "net/ipv4/fib_trie.c",
82416 + [29267].name = "tnode_alloc",
82417 + [29267].param1 = 1,
82418 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82419 + [29338].name = "bnad_debugfs_write_regwr",
82420 + [29338].param3 = 1,
82421 + [29353].file = "net/sctp/socket.c",
82422 + [29353].name = "sctp_setsockopt_del_key",
82423 + [29353].param3 = 1,
82424 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82425 + [29405].name = "dw210x_op_rw",
82426 + [29405].param6 = 1,
82427 + [29542].file = "net/nfc/nci/core.c",
82428 + [29542].name = "nci_send_cmd",
82429 + [29542].param3 = 1,
82430 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82431 + [29714].name = "cxgbi_device_register",
82432 + [29714].param1 = 1,
82433 + [29714].param2 = 1,
82434 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
82435 + [2972].name = "crystalhd_create_dio_pool",
82436 + [2972].param2 = 1,
82437 + [29769].file = "drivers/misc/iwmc3200top/log.c",
82438 + [29769].name = "store_iwmct_log_level",
82439 + [29769].param4 = 1,
82440 + [29792].file = "drivers/staging/bcm/nvm.c",
82441 + [29792].name = "BcmCopySection",
82442 + [29792].param5 = 1,
82443 + [29859].file = "net/rds/page.c",
82444 + [29859].name = "rds_page_copy_user",
82445 + [29859].param4 = 1,
82446 + [29905].file = "mm/nobootmem.c",
82447 + [29905].name = "___alloc_bootmem",
82448 + [29905].param1 = 1,
82449 + [2995].file = "mm/page_alloc.c",
82450 + [2995].name = "alloc_large_system_hash",
82451 + [2995].param2 = 1,
82452 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
82453 + [30000].name = "wlc_phy_loadsampletable_nphy",
82454 + [30000].param3 = 1,
82455 + [30242].file = "fs/cifs/cifssmb.c",
82456 + [30242].name = "cifs_readdata_alloc",
82457 + [30242].param1 = 1,
82458 + [30494].file = "net/ceph/buffer.c",
82459 + [30494].name = "ceph_buffer_new",
82460 + [30494].param1 = 1,
82461 + [30590].file = "security/tomoyo/memory.c",
82462 + [30590].name = "tomoyo_commit_ok",
82463 + [30590].param2 = 1,
82464 + [3060].file = "lib/mpi/mpiutil.c",
82465 + [3060].name = "mpi_alloc_limb_space",
82466 + [3060].param1 = 1,
82467 + [30687].file = "drivers/uwb/uwb-debug.c",
82468 + [30687].name = "command_write",
82469 + [30687].param3 = 1,
82470 + [30726].file = "drivers/bluetooth/hci_vhci.c",
82471 + [30726].name = "vhci_get_user",
82472 + [30726].param3 = 1,
82473 + [30873].file = "net/packet/af_packet.c",
82474 + [30873].name = "alloc_one_pg_vec_page",
82475 + [30873].param1 = 1,
82476 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
82477 + [30970].name = "create_bounce_buffer",
82478 + [30970].param3 = 1,
82479 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
82480 + [310].name = "bm_realloc_pages",
82481 + [310].param2 = 1,
82482 + [3119].file = "drivers/misc/ibmasm/command.c",
82483 + [3119].name = "ibmasm_new_command",
82484 + [3119].param2 = 1,
82485 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82486 + [31207].name = "parse_arg",
82487 + [31207].param2 = 1,
82488 + [31287].file = "drivers/scsi/libsrp.c",
82489 + [31287].name = "srp_iu_pool_alloc",
82490 + [31287].param2 = 1,
82491 + [31291].file = "sound/pci/rme9652/rme9652.c",
82492 + [31291].name = "snd_rme9652_capture_copy",
82493 + [31291].param5 = 1,
82494 + [31348].file = "kernel/sched/core.c",
82495 + [31348].name = "sys_sched_getaffinity",
82496 + [31348].param2 = 1,
82497 + [31492].file = "drivers/hid/hidraw.c",
82498 + [31492].name = "hidraw_read",
82499 + [31492].param3 = 1,
82500 + [3170].file = "security/integrity/ima/ima_fs.c",
82501 + [3170].name = "ima_write_policy",
82502 + [3170].param3 = 1,
82503 + [31782].file = "drivers/misc/pti.c",
82504 + [31782].name = "pti_char_write",
82505 + [31782].param3 = 1,
82506 + [31789].file = "fs/file.c",
82507 + [31789].name = "alloc_fdmem",
82508 + [31789].param1 = 1,
82509 + [31957].file = "fs/afs/proc.c",
82510 + [31957].name = "afs_proc_cells_write",
82511 + [31957].param3 = 1,
82512 + [32002].file = "net/sctp/socket.c",
82513 + [32002].name = "sctp_setsockopt_active_key",
82514 + [32002].param3 = 1,
82515 + [32182].file = "net/sunrpc/cache.c",
82516 + [32182].name = "cache_write",
82517 + [32182].param3 = 1,
82518 + [32278].file = "kernel/time/timer_stats.c",
82519 + [32278].name = "tstats_write",
82520 + [32278].param3 = 1,
82521 + [32326].file = "drivers/tty/n_r3964.c",
82522 + [32326].name = "r3964_write",
82523 + [32326].param4 = 1,
82524 + [32399].file = "drivers/net/phy/mdio_bus.c",
82525 + [32399].name = "mdiobus_alloc_size",
82526 + [32399].param1 = 1,
82527 + [32402].file = "net/ceph/pagevec.c",
82528 + [32402].name = "ceph_copy_user_to_page_vector",
82529 + [32402].param4 = 1,
82530 + [3241].file = "drivers/usb/wusbcore/crypto.c",
82531 + [3241].name = "wusb_prf",
82532 + [3241].param7 = 1,
82533 + [32459].file = "drivers/media/radio/radio-wl1273.c",
82534 + [32459].name = "wl1273_fm_fops_write",
82535 + [32459].param3 = 1,
82536 + [32531].file = "fs/bio.c",
82537 + [32531].name = "__bio_map_kern",
82538 + [32531].param2 = 1,
82539 + [32531].param3 = 1,
82540 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
82541 + [32537].name = "buffer_to_user",
82542 + [32537].param3 = 1,
82543 + [32560].file = "drivers/input/input-mt.c",
82544 + [32560].name = "input_mt_init_slots",
82545 + [32560].param2 = 1,
82546 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82547 + [32600].name = "ath6kl_set_assoc_req_ies",
82548 + [32600].param3 = 1,
82549 + [32608].file = "security/selinux/selinuxfs.c",
82550 + [32608].name = "sel_write_checkreqprot",
82551 + [32608].param3 = 1,
82552 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82553 + [32812].name = "__vxge_hw_channel_allocate",
82554 + [32812].param3 = 1,
82555 + [32950].file = "fs/reiserfs/resize.c",
82556 + [32950].name = "reiserfs_resize",
82557 + [32950].param2 = 1,
82558 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82559 + [33010].name = "dvb_ringbuffer_pkt_read_user",
82560 + [33010].param5 = 1,
82561 + [33130].file = "net/llc/llc_sap.c",
82562 + [33130].name = "llc_alloc_frame",
82563 + [33130].param4 = 1,
82564 + [33221].file = "crypto/ablkcipher.c",
82565 + [33221].name = "ablkcipher_copy_iv",
82566 + [33221].param3 = 1,
82567 + [33268].file = "mm/maccess.c",
82568 + [33268].name = "__probe_kernel_write",
82569 + [33268].param3 = 1,
82570 + [33280].file = "fs/xfs/kmem.c",
82571 + [33280].name = "kmem_realloc",
82572 + [33280].param2 = 1,
82573 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
82574 + [33375].name = "_malloc",
82575 + [33375].param1 = 1,
82576 + [33420].file = "drivers/net/team/team.c",
82577 + [33420].name = "__team_options_register",
82578 + [33420].param3 = 1,
82579 + [33489].file = "fs/binfmt_misc.c",
82580 + [33489].name = "create_entry",
82581 + [33489].param2 = 1,
82582 + [33637].file = "net/9p/client.c",
82583 + [33637].name = "p9_client_read",
82584 + [33637].param5 = 1,
82585 + [33669].file = "fs/gfs2/glock.c",
82586 + [33669].name = "gfs2_glock_nq_m",
82587 + [33669].param1 = 1,
82588 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
82589 + [33704].name = "ttm_dma_page_pool_free",
82590 + [33704].param2 = 1,
82591 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
82592 + [33779].name = "resource_from_user",
82593 + [33779].param3 = 1,
82594 + [33810].file = "net/mac80211/util.c",
82595 + [33810].name = "ieee80211_send_probe_req",
82596 + [33810].param6 = 1,
82597 + [3384].file = "drivers/block/paride/pg.c",
82598 + [3384].name = "pg_write",
82599 + [3384].param3 = 1,
82600 + [34105].file = "fs/libfs.c",
82601 + [34105].name = "simple_read_from_buffer",
82602 + [34105].param2 = 1,
82603 + [34105].param5 = 1,
82604 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
82605 + [34120].name = "pvr2_stream_buffer_count",
82606 + [34120].param2 = 1,
82607 + [34226].file = "mm/shmem.c",
82608 + [34226].name = "shmem_xattr_set",
82609 + [34226].param4 = 1,
82610 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
82611 + [34251].name = "OS_kmalloc",
82612 + [34251].param1 = 1,
82613 + [34276].file = "drivers/media/video/videobuf2-core.c",
82614 + [34276].name = "__vb2_perform_fileio",
82615 + [34276].param3 = 1,
82616 + [34278].file = "fs/ubifs/debug.c",
82617 + [34278].name = "dfs_global_file_write",
82618 + [34278].param3 = 1,
82619 + [34432].file = "drivers/edac/edac_pci.c",
82620 + [34432].name = "edac_pci_alloc_ctl_info",
82621 + [34432].param1 = 1,
82622 + [34532].file = "drivers/virtio/virtio_ring.c",
82623 + [34532].name = "vring_add_indirect",
82624 + [34532].param3 = 1,
82625 + [34532].param4 = 1,
82626 + [34543].file = "net/sctp/tsnmap.c",
82627 + [34543].name = "sctp_tsnmap_grow",
82628 + [34543].param2 = 1,
82629 + [34551].file = "fs/ocfs2/stack_user.c",
82630 + [34551].name = "ocfs2_control_cfu",
82631 + [34551].param2 = 1,
82632 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82633 + [34634].name = "ath6kl_send_go_probe_resp",
82634 + [34634].param3 = 1,
82635 + [34666].file = "fs/cifs/cifs_debug.c",
82636 + [34666].name = "cifs_security_flags_proc_write",
82637 + [34666].param3 = 1,
82638 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
82639 + [3466].name = "altera_drscan",
82640 + [3466].param2 = 1,
82641 + [34672].file = "drivers/tty/tty_io.c",
82642 + [34672].name = "tty_write",
82643 + [34672].param3 = 1,
82644 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82645 + [34679].name = "ivtv_copy_buf_to_user",
82646 + [34679].param4 = 1,
82647 + [34721].file = "drivers/usb/host/hwa-hc.c",
82648 + [34721].name = "__hwahc_dev_set_key",
82649 + [34721].param5 = 1,
82650 + [34749].file = "mm/nobootmem.c",
82651 + [34749].name = "__alloc_bootmem_low_node",
82652 + [34749].param2 = 1,
82653 + [34760].file = "include/acpi/platform/aclinux.h",
82654 + [34760].name = "acpi_os_allocate_zeroed",
82655 + [34760].param1 = 1,
82656 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
82657 + [34802].name = "cxgbi_alloc_big_mem",
82658 + [34802].param1 = 1,
82659 + [34863].file = "drivers/video/fbsysfs.c",
82660 + [34863].name = "framebuffer_alloc",
82661 + [34863].param1 = 1,
82662 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82663 + [34868].name = "bnad_debugfs_write_regrd",
82664 + [34868].param3 = 1,
82665 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
82666 + [34882].name = "video_proc_write",
82667 + [34882].param3 = 1,
82668 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
82669 + [35050].name = "dlmfs_file_write",
82670 + [35050].param3 = 1,
82671 + [35119].file = "fs/xattr.c",
82672 + [35119].name = "sys_llistxattr",
82673 + [35119].param3 = 1,
82674 + [35129].file = "mm/nobootmem.c",
82675 + [35129].name = "___alloc_bootmem_nopanic",
82676 + [35129].param1 = 1,
82677 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
82678 + [35159].name = "__i2400mu_send_barker",
82679 + [35159].param3 = 1,
82680 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
82681 + [35232].name = "cx18_read",
82682 + [35232].param3 = 1,
82683 + [35234].file = "net/irda/irnet/irnet_ppp.c",
82684 + [35234].name = "irnet_ctrl_write",
82685 + [35234].param3 = 1,
82686 + [35256].file = "sound/core/memory.c",
82687 + [35256].name = "copy_from_user_toio",
82688 + [35256].param3 = 1,
82689 + [35268].file = "security/keys/request_key_auth.c",
82690 + [35268].name = "request_key_auth_read",
82691 + [35268].param3 = 1,
82692 + [3538].file = "net/bluetooth/mgmt.c",
82693 + [3538].name = "disconnect",
82694 + [3538].param4 = 1,
82695 + [35443].file = "sound/core/pcm_memory.c",
82696 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
82697 + [35443].param2 = 1,
82698 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82699 + [35468].name = "xenbus_file_write",
82700 + [35468].param3 = 1,
82701 + [35536].file = "kernel/sysctl_binary.c",
82702 + [35536].name = "bin_uuid",
82703 + [35536].param3 = 1,
82704 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82705 + [35551].name = "ivtv_read_pos",
82706 + [35551].param3 = 1,
82707 + [35556].file = "fs/read_write.c",
82708 + [35556].name = "sys_readv",
82709 + [35556].param3 = 1,
82710 + [35693].file = "drivers/staging/mei/main.c",
82711 + [35693].name = "mei_read",
82712 + [35693].param3 = 1,
82713 + [35703].file = "crypto/ablkcipher.c",
82714 + [35703].name = "ablkcipher_next_slow",
82715 + [35703].param3 = 1,
82716 + [35703].param4 = 1,
82717 + [35729].file = "include/linux/skbuff.h",
82718 + [35729].name = "__dev_alloc_skb",
82719 + [35729].param1 = 1,
82720 + [35731].file = "drivers/usb/class/cdc-wdm.c",
82721 + [35731].name = "wdm_read",
82722 + [35731].param3 = 1,
82723 + [35796].file = "drivers/mtd/nand/nand_bch.c",
82724 + [35796].name = "nand_bch_init",
82725 + [35796].param2 = 1,
82726 + [35796].param3 = 1,
82727 + [35880].file = "fs/ecryptfs/crypto.c",
82728 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
82729 + [35880].param6 = 1,
82730 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
82731 + [36076].name = "efx_tsoh_heap_alloc",
82732 + [36076].param2 = 1,
82733 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
82734 + [36080].name = "video_usercopy",
82735 + [36080].param2 = 1,
82736 + [36149].file = "fs/udf/inode.c",
82737 + [36149].name = "udf_alloc_i_data",
82738 + [36149].param2 = 1,
82739 + [36183].file = "drivers/tty/vt/vc_screen.c",
82740 + [36183].name = "vcs_read",
82741 + [36183].param3 = 1,
82742 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
82743 + [36199].name = "gss_pipe_downcall",
82744 + [36199].param3 = 1,
82745 + [36206].file = "net/ipv4/tcp_input.c",
82746 + [36206].name = "tcp_collapse",
82747 + [36206].param5 = 1,
82748 + [36206].param6 = 1,
82749 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
82750 + [36230].name = "ppp_cp_parse_cr",
82751 + [36230].param4 = 1,
82752 + [36284].file = "drivers/spi/spi.c",
82753 + [36284].name = "spi_register_board_info",
82754 + [36284].param2 = 1,
82755 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82756 + [36490].name = "ath6kl_cfg80211_connect_event",
82757 + [36490].param7 = 1,
82758 + [36522].file = "drivers/hid/hidraw.c",
82759 + [36522].name = "hidraw_send_report",
82760 + [36522].param3 = 1,
82761 + [36560].file = "net/sunrpc/cache.c",
82762 + [36560].name = "write_flush",
82763 + [36560].param3 = 1,
82764 + [36807].file = "drivers/usb/mon/mon_bin.c",
82765 + [36807].name = "mon_bin_get_event",
82766 + [36807].param4 = 1,
82767 + [37034].file = "fs/cifs/cifssmb.c",
82768 + [37034].name = "cifs_writedata_alloc",
82769 + [37034].param1 = 1,
82770 + [37044].file = "sound/firewire/packets-buffer.c",
82771 + [37044].name = "iso_packets_buffer_init",
82772 + [37044].param3 = 1,
82773 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
82774 + [37108].name = "dvb_video_write",
82775 + [37108].param3 = 1,
82776 + [37154].file = "net/nfc/llcp/commands.c",
82777 + [37154].name = "nfc_llcp_build_tlv",
82778 + [37154].param3 = 1,
82779 + [37163].file = "net/core/skbuff.c",
82780 + [37163].name = "__netdev_alloc_skb",
82781 + [37163].param2 = 1,
82782 + [37233].file = "fs/ocfs2/cluster/tcp.c",
82783 + [37233].name = "o2net_send_message_vec",
82784 + [37233].param4 = 1,
82785 + [37241].file = "net/atm/lec.c",
82786 + [37241].name = "lane2_associate_req",
82787 + [37241].param4 = 1,
82788 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
82789 + [37384].name = "vmw_fifo_reserve",
82790 + [37384].param2 = 1,
82791 + [37497].file = "net/mac80211/util.c",
82792 + [37497].name = "ieee80211_build_probe_req",
82793 + [37497].param7 = 1,
82794 + [37535].file = "kernel/trace/trace.c",
82795 + [37535].name = "tracing_trace_options_write",
82796 + [37535].param3 = 1,
82797 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
82798 + [37611].name = "split",
82799 + [37611].param2 = 1,
82800 + [37661].file = "mm/filemap.c",
82801 + [37661].name = "file_read_actor",
82802 + [37661].param4 = 1,
82803 + [37852].file = "drivers/staging/android/logger.c",
82804 + [37852].name = "do_read_log_to_user",
82805 + [37852].param4 = 1,
82806 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
82807 + [37921].name = "wl1271_rx_handle_data",
82808 + [37921].param3 = 1,
82809 + [37976].file = "drivers/platform/x86/asus_acpi.c",
82810 + [37976].name = "bluetooth_proc_write",
82811 + [37976].param3 = 1,
82812 + [3797].file = "sound/pci/asihpi/hpicmn.c",
82813 + [3797].name = "hpi_alloc_control_cache",
82814 + [3797].param1 = 1,
82815 + [3801].file = "drivers/block/paride/pt.c",
82816 + [3801].name = "pt_write",
82817 + [3801].param3 = 1,
82818 + [38052].file = "kernel/kexec.c",
82819 + [38052].name = "kimage_normal_alloc",
82820 + [38052].param3 = 1,
82821 + [38057].file = "fs/coda/psdev.c",
82822 + [38057].name = "coda_psdev_write",
82823 + [38057].param3 = 1,
82824 + [38186].file = "kernel/signal.c",
82825 + [38186].name = "do_sigpending",
82826 + [38186].param2 = 1,
82827 + [38314].file = "fs/nfs/read.c",
82828 + [38314].name = "nfs_readdata_alloc",
82829 + [38314].param1 = 1,
82830 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82831 + [38401].name = "queue_reply",
82832 + [38401].param3 = 1,
82833 + [3841].file = "drivers/platform/x86/asus_acpi.c",
82834 + [3841].name = "write_led",
82835 + [3841].param2 = 1,
82836 + [38532].file = "fs/afs/cell.c",
82837 + [38532].name = "afs_cell_lookup",
82838 + [38532].param2 = 1,
82839 + [38564].file = "fs/nfs/nfs4proc.c",
82840 + [38564].name = "nfs4_realloc_slot_table",
82841 + [38564].param2 = 1,
82842 + [38576].file = "drivers/i2c/i2c-dev.c",
82843 + [38576].name = "i2cdev_read",
82844 + [38576].param3 = 1,
82845 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
82846 + [38704].name = "uvc_alloc_entity",
82847 + [38704].param3 = 1,
82848 + [38704].param4 = 1,
82849 + [38747].file = "fs/xattr.c",
82850 + [38747].name = "sys_lgetxattr",
82851 + [38747].param4 = 1,
82852 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
82853 + [38867].name = "fc_host_post_vendor_event",
82854 + [38867].param3 = 1,
82855 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
82856 + [38931].name = "diva_os_alloc_message_buffer",
82857 + [38931].param1 = 1,
82858 + [38972].file = "security/smack/smackfs.c",
82859 + [38972].name = "smk_write_logging",
82860 + [38972].param3 = 1,
82861 + [39001].file = "net/xfrm/xfrm_hash.c",
82862 + [39001].name = "xfrm_hash_alloc",
82863 + [39001].param1 = 1,
82864 + [39052].file = "drivers/input/evdev.c",
82865 + [39052].name = "evdev_ioctl",
82866 + [39052].param2 = 1,
82867 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
82868 + [39066].name = "tda10048_writeregbulk",
82869 + [39066].param4 = 1,
82870 + [39118].file = "drivers/misc/iwmc3200top/log.c",
82871 + [39118].name = "store_iwmct_log_level_fw",
82872 + [39118].param4 = 1,
82873 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
82874 + [39254].name = "cmm_write",
82875 + [39254].param3 = 1,
82876 + [39392].file = "drivers/atm/solos-pci.c",
82877 + [39392].name = "send_command",
82878 + [39392].param4 = 1,
82879 + [39415].file = "fs/pstore/inode.c",
82880 + [39415].name = "pstore_mkfile",
82881 + [39415].param5 = 1,
82882 + [39417].file = "drivers/block/DAC960.c",
82883 + [39417].name = "dac960_user_command_proc_write",
82884 + [39417].param3 = 1,
82885 + [39460].file = "fs/btrfs/volumes.c",
82886 + [39460].name = "btrfs_map_block",
82887 + [39460].param3 = 1,
82888 + [39479].file = "drivers/ide/ide-tape.c",
82889 + [39479].name = "idetape_chrdev_read",
82890 + [39479].param3 = 1,
82891 + [39586].file = "drivers/hv/channel.c",
82892 + [39586].name = "create_gpadl_header",
82893 + [39586].param2 = 1,
82894 + [39638].file = "security/selinux/selinuxfs.c",
82895 + [39638].name = "sel_write_avc_cache_threshold",
82896 + [39638].param3 = 1,
82897 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
82898 + [39645].name = "dvb_generic_ioctl",
82899 + [39645].param2 = 1,
82900 + [39770].file = "include/linux/mISDNif.h",
82901 + [39770].name = "mI_alloc_skb",
82902 + [39770].param1 = 1,
82903 + [39813].file = "fs/ocfs2/stack_user.c",
82904 + [39813].name = "ocfs2_control_message",
82905 + [39813].param3 = 1,
82906 + [39888].file = "net/core/skbuff.c",
82907 + [39888].name = "__alloc_skb",
82908 + [39888].param1 = 1,
82909 + [39980].file = "net/bluetooth/mgmt.c",
82910 + [39980].name = "pair_device",
82911 + [39980].param4 = 1,
82912 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
82913 + [40043].name = "video_ioctl2",
82914 + [40043].param2 = 1,
82915 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
82916 + [40049].name = "btmrvl_psmode_write",
82917 + [40049].param3 = 1,
82918 + [40075].file = "drivers/media/video/c-qcam.c",
82919 + [40075].name = "qc_capture",
82920 + [40075].param3 = 1,
82921 + [40163].file = "fs/ncpfs/file.c",
82922 + [40163].name = "ncp_file_write",
82923 + [40163].param3 = 1,
82924 + [40240].file = "drivers/char/nvram.c",
82925 + [40240].name = "nvram_write",
82926 + [40240].param3 = 1,
82927 + [40256].file = "drivers/tty/vt/vc_screen.c",
82928 + [40256].name = "vcs_write",
82929 + [40256].param3 = 1,
82930 + [40302].file = "sound/isa/gus/gus_dram.c",
82931 + [40302].name = "snd_gus_dram_poke",
82932 + [40302].param4 = 1,
82933 + [40339].file = "drivers/acpi/apei/hest.c",
82934 + [40339].name = "hest_ghes_dev_register",
82935 + [40339].param1 = 1,
82936 + [40355].file = "drivers/staging/mei/main.c",
82937 + [40355].name = "mei_write",
82938 + [40355].param3 = 1,
82939 + [40373].file = "fs/cifs/cifs_spnego.c",
82940 + [40373].name = "cifs_spnego_key_instantiate",
82941 + [40373].param3 = 1,
82942 + [40519].file = "net/sctp/socket.c",
82943 + [40519].name = "sctp_setsockopt_events",
82944 + [40519].param3 = 1,
82945 + [40694].file = "mm/page_cgroup.c",
82946 + [40694].name = "alloc_page_cgroup",
82947 + [40694].param1 = 1,
82948 + [40731].file = "drivers/tty/tty_io.c",
82949 + [40731].name = "do_tty_write",
82950 + [40731].param5 = 1,
82951 + [40754].file = "fs/btrfs/delayed-inode.c",
82952 + [40754].name = "btrfs_alloc_delayed_item",
82953 + [40754].param1 = 1,
82954 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
82955 + [40786].name = "asn1_octets_decode",
82956 + [40786].param2 = 1,
82957 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
82958 + [40901].name = "drbd_bm_resize",
82959 + [40901].param2 = 1,
82960 + [40951].file = "drivers/xen/evtchn.c",
82961 + [40951].name = "evtchn_read",
82962 + [40951].param3 = 1,
82963 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
82964 + [40952].name = "xpc_kmalloc_cacheline_aligned",
82965 + [40952].param1 = 1,
82966 + [41000].file = "sound/core/pcm_native.c",
82967 + [41000].name = "snd_pcm_aio_read",
82968 + [41000].param3 = 1,
82969 + [41005].file = "net/bridge/netfilter/ebtables.c",
82970 + [41005].name = "copy_counters_to_user",
82971 + [41005].param5 = 1,
82972 + [41041].file = "net/core/sock.c",
82973 + [41041].name = "sock_wmalloc",
82974 + [41041].param2 = 1,
82975 + [41122].file = "fs/binfmt_misc.c",
82976 + [41122].name = "bm_status_write",
82977 + [41122].param3 = 1,
82978 + [41176].file = "kernel/trace/trace_events.c",
82979 + [41176].name = "subsystem_filter_write",
82980 + [41176].param3 = 1,
82981 + [41249].file = "drivers/media/video/zr364xx.c",
82982 + [41249].name = "send_control_msg",
82983 + [41249].param6 = 1,
82984 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82985 + [41287].name = "vxge_os_dma_malloc_async",
82986 + [41287].param3 = 1,
82987 + [41302].file = "net/dns_resolver/dns_query.c",
82988 + [41302].name = "dns_query",
82989 + [41302].param3 = 1,
82990 + [41408].file = "mm/filemap_xip.c",
82991 + [41408].name = "__xip_file_write",
82992 + [41408].param3 = 1,
82993 + [41547].file = "net/bluetooth/smp.c",
82994 + [41547].name = "smp_build_cmd",
82995 + [41547].param3 = 1,
82996 + [4155].file = "kernel/kexec.c",
82997 + [4155].name = "do_kimage_alloc",
82998 + [4155].param3 = 1,
82999 + [41676].file = "fs/compat.c",
83000 + [41676].name = "compat_sys_preadv",
83001 + [41676].param3 = 1,
83002 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
83003 + [4167].name = "cx24116_writeregN",
83004 + [4167].param4 = 1,
83005 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83006 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
83007 + [41793].param7 = 1,
83008 + [41924].file = "security/keys/keyctl.c",
83009 + [41924].name = "keyctl_get_security",
83010 + [41924].param3 = 1,
83011 + [41968].file = "fs/btrfs/volumes.c",
83012 + [41968].name = "__btrfs_map_block",
83013 + [41968].param3 = 1,
83014 + [4202].file = "drivers/edac/edac_mc.c",
83015 + [4202].name = "edac_mc_alloc",
83016 + [4202].param1 = 1,
83017 + [42081].file = "net/econet/af_econet.c",
83018 + [42081].name = "aun_incoming",
83019 + [42081].param3 = 1,
83020 + [42143].file = "drivers/media/video/c-qcam.c",
83021 + [42143].name = "qcam_read",
83022 + [42143].param3 = 1,
83023 + [42206].file = "fs/quota/quota_tree.c",
83024 + [42206].name = "getdqbuf",
83025 + [42206].param1 = 1,
83026 + [42270].file = "net/wireless/scan.c",
83027 + [42270].name = "cfg80211_inform_bss_frame",
83028 + [42270].param4 = 1,
83029 + [42281].file = "include/linux/mISDNif.h",
83030 + [42281].name = "_queue_data",
83031 + [42281].param4 = 1,
83032 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83033 + [42420].name = "prism2_set_genericelement",
83034 + [42420].param3 = 1,
83035 + [42472].file = "fs/compat.c",
83036 + [42472].name = "compat_readv",
83037 + [42472].param3 = 1,
83038 + [42473].file = "net/tipc/name_table.c",
83039 + [42473].name = "tipc_subseq_alloc",
83040 + [42473].param1 = 1,
83041 + [42562].file = "kernel/kfifo.c",
83042 + [42562].name = "__kfifo_to_user_r",
83043 + [42562].param3 = 1,
83044 + [42666].file = "drivers/pcmcia/cistpl.c",
83045 + [42666].name = "read_cis_cache",
83046 + [42666].param4 = 1,
83047 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
83048 + [42714].name = "scsi_tgt_copy_sense",
83049 + [42714].param3 = 1,
83050 + [42833].file = "kernel/trace/blktrace.c",
83051 + [42833].name = "blk_msg_write",
83052 + [42833].param3 = 1,
83053 + [42857].file = "security/selinux/selinuxfs.c",
83054 + [42857].name = "sel_write_member",
83055 + [42857].param3 = 1,
83056 + [42882].file = "security/keys/user_defined.c",
83057 + [42882].name = "user_instantiate",
83058 + [42882].param3 = 1,
83059 + [42930].file = "net/caif/cfpkt_skbuff.c",
83060 + [42930].name = "cfpkt_create_pfx",
83061 + [42930].param1 = 1,
83062 + [42930].param2 = 1,
83063 + [43023].file = "drivers/usb/misc/usblcd.c",
83064 + [43023].name = "lcd_write",
83065 + [43023].param3 = 1,
83066 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
83067 + [43104].name = "dataflash_read_user_otp",
83068 + [43104].param3 = 1,
83069 + [43133].file = "lib/mpi/mpiutil.c",
83070 + [43133].name = "mpi_resize",
83071 + [43133].param2 = 1,
83072 + [4324].file = "drivers/video/fbmem.c",
83073 + [4324].name = "fb_read",
83074 + [4324].param3 = 1,
83075 + [43266].file = "fs/afs/cell.c",
83076 + [43266].name = "afs_cell_alloc",
83077 + [43266].param2 = 1,
83078 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
83079 + [4328].name = "musb_test_mode_write",
83080 + [4328].param3 = 1,
83081 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83082 + [43380].name = "bfad_debugfs_write_regrd",
83083 + [43380].param3 = 1,
83084 + [43510].file = "kernel/kexec.c",
83085 + [43510].name = "compat_sys_kexec_load",
83086 + [43510].param2 = 1,
83087 + [43540].file = "include/rdma/ib_verbs.h",
83088 + [43540].name = "ib_copy_to_udata",
83089 + [43540].param3 = 1,
83090 + [4357].file = "security/tomoyo/securityfs_if.c",
83091 + [4357].name = "tomoyo_read_self",
83092 + [4357].param3 = 1,
83093 + [43590].file = "security/smack/smackfs.c",
83094 + [43590].name = "smk_write_onlycap",
83095 + [43590].param3 = 1,
83096 + [43596].file = "drivers/usb/core/buffer.c",
83097 + [43596].name = "hcd_buffer_alloc",
83098 + [43596].param2 = 1,
83099 + [43632].file = "drivers/media/video/videobuf2-core.c",
83100 + [43632].name = "vb2_read",
83101 + [43632].param3 = 1,
83102 + [43659].file = "drivers/firmware/efivars.c",
83103 + [43659].name = "efivar_create_sysfs_entry",
83104 + [43659].param2 = 1,
83105 + [43731].file = "drivers/hid/hid-picolcd.c",
83106 + [43731].name = "picolcd_debug_eeprom_read",
83107 + [43731].param3 = 1,
83108 + [43777].file = "drivers/acpi/acpica/utobject.c",
83109 + [43777].name = "acpi_ut_create_buffer_object",
83110 + [43777].param1 = 1,
83111 + [43798].file = "net/bluetooth/mgmt.c",
83112 + [43798].name = "set_local_name",
83113 + [43798].param4 = 1,
83114 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
83115 + [4380].name = "dataflash_read_fact_otp",
83116 + [4380].param3 = 1,
83117 + [43834].file = "security/apparmor/apparmorfs.c",
83118 + [43834].name = "profile_replace",
83119 + [43834].param3 = 1,
83120 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83121 + [43895].name = "ddb_output_write",
83122 + [43895].param3 = 1,
83123 + [43899].file = "drivers/media/rc/imon.c",
83124 + [43899].name = "vfd_write",
83125 + [43899].param3 = 1,
83126 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
83127 + [43900].name = "cxgbi_device_portmap_create",
83128 + [43900].param3 = 1,
83129 + [43922].file = "drivers/mmc/card/mmc_test.c",
83130 + [43922].name = "mmc_test_alloc_mem",
83131 + [43922].param3 = 1,
83132 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
83133 + [43946].name = "aggr_recv_addba_req_evt",
83134 + [43946].param4 = 1,
83135 + [44006].file = "mm/process_vm_access.c",
83136 + [44006].name = "process_vm_rw_pages",
83137 + [44006].param5 = 1,
83138 + [44006].param6 = 1,
83139 + [44050].file = "fs/nfs/idmap.c",
83140 + [44050].name = "nfs_map_group_to_gid",
83141 + [44050].param3 = 1,
83142 + [44125].file = "fs/ext4/super.c",
83143 + [44125].name = "ext4_kvmalloc",
83144 + [44125].param1 = 1,
83145 + [44266].file = "kernel/cgroup.c",
83146 + [44266].name = "cgroup_write_string",
83147 + [44266].param5 = 1,
83148 + [44290].file = "drivers/net/usb/dm9601.c",
83149 + [44290].name = "dm_read",
83150 + [44290].param3 = 1,
83151 + [44308].file = "crypto/af_alg.c",
83152 + [44308].name = "alg_setkey",
83153 + [44308].param3 = 1,
83154 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
83155 + [44510].name = "bnx2_nvram_write",
83156 + [44510].param2 = 1,
83157 + [44625].file = "net/bluetooth/mgmt.c",
83158 + [44625].name = "set_connectable",
83159 + [44625].param4 = 1,
83160 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
83161 + [44642].name = "iwm_umac_set_config_var",
83162 + [44642].param4 = 1,
83163 + [44698].file = "net/sctp/socket.c",
83164 + [44698].name = "sctp_setsockopt_context",
83165 + [44698].param3 = 1,
83166 + [4471].file = "fs/ntfs/malloc.h",
83167 + [4471].name = "__ntfs_malloc",
83168 + [4471].param1 = 1,
83169 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83170 + [44773].name = "vme_user_write",
83171 + [44773].param3 = 1,
83172 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83173 + [44825].name = "_osd_realloc_seg",
83174 + [44825].param3 = 1,
83175 + [44852].file = "net/sctp/socket.c",
83176 + [44852].name = "sctp_setsockopt_rtoinfo",
83177 + [44852].param3 = 1,
83178 + [44936].file = "drivers/md/dm-raid.c",
83179 + [44936].name = "context_alloc",
83180 + [44936].param3 = 1,
83181 + [44943].file = "mm/util.c",
83182 + [44943].name = "kmemdup",
83183 + [44943].param2 = 1,
83184 + [44946].file = "net/sctp/socket.c",
83185 + [44946].name = "sctp_setsockopt_auth_chunk",
83186 + [44946].param3 = 1,
83187 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83188 + [44990].name = "pvr2_ioread_set_sync_key",
83189 + [44990].param3 = 1,
83190 + [45000].file = "fs/afs/proc.c",
83191 + [45000].name = "afs_proc_rootcell_write",
83192 + [45000].param3 = 1,
83193 + [45117].file = "drivers/staging/winbond/wb35reg.c",
83194 + [45117].name = "Wb35Reg_BurstWrite",
83195 + [45117].param4 = 1,
83196 + [45200].file = "drivers/scsi/scsi_proc.c",
83197 + [45200].name = "proc_scsi_write_proc",
83198 + [45200].param3 = 1,
83199 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83200 + [45217].name = "iwl_dbgfs_debug_level_write",
83201 + [45217].param3 = 1,
83202 + [45233].file = "net/rds/info.c",
83203 + [45233].name = "rds_info_getsockopt",
83204 + [45233].param3 = 1,
83205 + [45326].file = "drivers/mtd/ubi/cdev.c",
83206 + [45326].name = "vol_cdev_read",
83207 + [45326].param3 = 1,
83208 + [45335].file = "fs/read_write.c",
83209 + [45335].name = "vfs_writev",
83210 + [45335].param3 = 1,
83211 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83212 + [45366].name = "init_tid_tabs",
83213 + [45366].param2 = 1,
83214 + [45366].param3 = 1,
83215 + [45366].param4 = 1,
83216 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83217 + [45534].name = "carl9170_cmd_buf",
83218 + [45534].param3 = 1,
83219 + [45576].file = "net/netfilter/xt_recent.c",
83220 + [45576].name = "recent_mt_proc_write",
83221 + [45576].param3 = 1,
83222 + [45583].file = "fs/gfs2/dir.c",
83223 + [45583].name = "leaf_dealloc",
83224 + [45583].param3 = 1,
83225 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83226 + [45586].name = "rt2x00debug_write_bbp",
83227 + [45586].param3 = 1,
83228 + [45629].file = "lib/bch.c",
83229 + [45629].name = "bch_alloc",
83230 + [45629].param1 = 1,
83231 + [45633].file = "drivers/input/evdev.c",
83232 + [45633].name = "evdev_do_ioctl",
83233 + [45633].param2 = 1,
83234 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
83235 + [45743].name = "qlcnic_alloc_msix_entries",
83236 + [45743].param2 = 1,
83237 + [45864].file = "drivers/atm/ambassador.c",
83238 + [45864].name = "create_queues",
83239 + [45864].param2 = 1,
83240 + [45864].param3 = 1,
83241 + [45930].file = "security/apparmor/apparmorfs.c",
83242 + [45930].name = "profile_remove",
83243 + [45930].param3 = 1,
83244 + [45954].file = "drivers/usb/misc/legousbtower.c",
83245 + [45954].name = "tower_write",
83246 + [45954].param3 = 1,
83247 + [46140].file = "sound/core/memalloc.c",
83248 + [46140].name = "snd_mem_proc_write",
83249 + [46140].param3 = 1,
83250 + [4616].file = "net/sunrpc/cache.c",
83251 + [4616].name = "cache_do_downcall",
83252 + [4616].param3 = 1,
83253 + [46243].file = "fs/binfmt_misc.c",
83254 + [46243].name = "bm_register_write",
83255 + [46243].param3 = 1,
83256 + [46250].file = "fs/xattr.c",
83257 + [46250].name = "sys_getxattr",
83258 + [46250].param4 = 1,
83259 + [46343].file = "fs/compat.c",
83260 + [46343].name = "compat_do_readv_writev",
83261 + [46343].param4 = 1,
83262 + [46400].file = "drivers/staging/sep/sep_driver.c",
83263 + [46400].name = "sep_prepare_input_output_dma_table",
83264 + [46400].param2 = 1,
83265 + [46400].param3 = 1,
83266 + [46400].param4 = 1,
83267 + [4644].file = "drivers/net/usb/mcs7830.c",
83268 + [4644].name = "mcs7830_get_reg",
83269 + [4644].param3 = 1,
83270 + [46605].file = "sound/core/oss/pcm_oss.c",
83271 + [46605].name = "snd_pcm_oss_sync1",
83272 + [46605].param2 = 1,
83273 + [46630].file = "net/decnet/af_decnet.c",
83274 + [46630].name = "__dn_setsockopt",
83275 + [46630].param5 = 1,
83276 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83277 + [46655].name = "hdpvr_read",
83278 + [46655].param3 = 1,
83279 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83280 + [46685].name = "ttm_bo_fbdev_io",
83281 + [46685].param4 = 1,
83282 + [46742].file = "drivers/scsi/st.c",
83283 + [46742].name = "sgl_map_user_pages",
83284 + [46742].param2 = 1,
83285 + [46881].file = "drivers/char/lp.c",
83286 + [46881].name = "lp_write",
83287 + [46881].param3 = 1,
83288 + [47130].file = "kernel/kfifo.c",
83289 + [47130].name = "kfifo_copy_to_user",
83290 + [47130].param3 = 1,
83291 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83292 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83293 + [47265].param2 = 1,
83294 + [47265].param3 = 1,
83295 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
83296 + [47309].name = "asd_store_update_bios",
83297 + [47309].param4 = 1,
83298 + [47342].file = "fs/proc/base.c",
83299 + [47342].name = "sched_autogroup_write",
83300 + [47342].param3 = 1,
83301 + [47363].file = "drivers/input/evdev.c",
83302 + [47363].name = "evdev_ioctl_handler",
83303 + [47363].param2 = 1,
83304 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83305 + [47385].name = "zd_usb_iowrite16v",
83306 + [47385].param3 = 1,
83307 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83308 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
83309 + [4738].param3 = 1,
83310 + [47393].file = "drivers/net/wireless/ath/main.c",
83311 + [47393].name = "ath_rxbuf_alloc",
83312 + [47393].param2 = 1,
83313 + [47463].file = "fs/xfs/kmem.c",
83314 + [47463].name = "kmem_zalloc",
83315 + [47463].param1 = 1,
83316 + [47474].file = "kernel/trace/trace.c",
83317 + [47474].name = "tracing_buffers_read",
83318 + [47474].param3 = 1,
83319 + [47636].file = "drivers/usb/class/usblp.c",
83320 + [47636].name = "usblp_ioctl",
83321 + [47636].param2 = 1,
83322 + [47637].file = "drivers/block/cciss.c",
83323 + [47637].name = "cciss_proc_write",
83324 + [47637].param3 = 1,
83325 + [47712].file = "net/sctp/socket.c",
83326 + [47712].name = "sctp_setsockopt_maxburst",
83327 + [47712].param3 = 1,
83328 + [47728].file = "drivers/char/agp/isoch.c",
83329 + [47728].name = "agp_3_5_isochronous_node_enable",
83330 + [47728].param3 = 1,
83331 + [4779].file = "fs/pipe.c",
83332 + [4779].name = "pipe_set_size",
83333 + [4779].param2 = 1,
83334 + [47881].file = "security/selinux/selinuxfs.c",
83335 + [47881].name = "sel_write_disable",
83336 + [47881].param3 = 1,
83337 + [48111].file = "net/wireless/sme.c",
83338 + [48111].name = "cfg80211_roamed_bss",
83339 + [48111].param4 = 1,
83340 + [48111].param6 = 1,
83341 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
83342 + [48124].name = "iwm_notif_send",
83343 + [48124].param6 = 1,
83344 + [48155].file = "net/sctp/sm_make_chunk.c",
83345 + [48155].name = "sctp_make_abort_user",
83346 + [48155].param3 = 1,
83347 + [48182].file = "crypto/cryptd.c",
83348 + [48182].name = "cryptd_alloc_instance",
83349 + [48182].param2 = 1,
83350 + [48182].param3 = 1,
83351 + [48248].file = "security/keys/keyctl.c",
83352 + [48248].name = "keyctl_instantiate_key",
83353 + [48248].param3 = 1,
83354 + [4829].file = "drivers/block/floppy.c",
83355 + [4829].name = "fd_copyout",
83356 + [4829].param3 = 1,
83357 + [48632].file = "net/bluetooth/l2cap_core.c",
83358 + [48632].name = "l2cap_build_cmd",
83359 + [48632].param4 = 1,
83360 + [48642].file = "fs/hugetlbfs/inode.c",
83361 + [48642].name = "hugetlbfs_read",
83362 + [48642].param3 = 1,
83363 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83364 + [48720].name = "i915_max_freq_write",
83365 + [48720].param3 = 1,
83366 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83367 + [48768].name = "dev_irnet_write",
83368 + [48768].param3 = 1,
83369 + [48818].file = "net/sunrpc/svc.c",
83370 + [48818].name = "svc_pool_map_alloc_arrays",
83371 + [48818].param2 = 1,
83372 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83373 + [48856].name = "acpi_ut_initialize_buffer",
83374 + [48856].param2 = 1,
83375 + [48862].file = "net/sctp/socket.c",
83376 + [48862].name = "sctp_setsockopt_adaptation_layer",
83377 + [48862].param3 = 1,
83378 + [49126].file = "lib/prio_heap.c",
83379 + [49126].name = "heap_init",
83380 + [49126].param2 = 1,
83381 + [49143].file = "sound/core/oss/pcm_oss.c",
83382 + [49143].name = "snd_pcm_oss_write2",
83383 + [49143].param3 = 1,
83384 + [49216].file = "fs/read_write.c",
83385 + [49216].name = "do_readv_writev",
83386 + [49216].param4 = 1,
83387 + [49426].file = "net/bluetooth/l2cap_sock.c",
83388 + [49426].name = "l2cap_sock_setsockopt_old",
83389 + [49426].param4 = 1,
83390 + [49448].file = "drivers/isdn/gigaset/common.c",
83391 + [49448].name = "gigaset_initdriver",
83392 + [49448].param2 = 1,
83393 + [49494].file = "drivers/virtio/virtio_ring.c",
83394 + [49494].name = "vring_new_virtqueue",
83395 + [49494].param1 = 1,
83396 + [49499].file = "drivers/block/nvme.c",
83397 + [49499].name = "nvme_alloc_iod",
83398 + [49499].param1 = 1,
83399 + [49510].file = "net/sctp/socket.c",
83400 + [49510].name = "sctp_setsockopt_autoclose",
83401 + [49510].param3 = 1,
83402 + [4958].file = "drivers/net/wireless/p54/fwio.c",
83403 + [4958].name = "p54_alloc_skb",
83404 + [4958].param3 = 1,
83405 + [49604].file = "crypto/af_alg.c",
83406 + [49604].name = "alg_setsockopt",
83407 + [49604].param5 = 1,
83408 + [49646].file = "drivers/tty/vt/vt.c",
83409 + [49646].name = "vc_resize",
83410 + [49646].param2 = 1,
83411 + [49646].param3 = 1,
83412 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
83413 + [49658].name = "dma_attach",
83414 + [49658].param6 = 1,
83415 + [49658].param7 = 1,
83416 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83417 + [49663].name = "uvc_simplify_fraction",
83418 + [49663].param3 = 1,
83419 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83420 + [49746].name = "compat_do_arpt_set_ctl",
83421 + [49746].param4 = 1,
83422 + [49780].file = "net/mac80211/key.c",
83423 + [49780].name = "ieee80211_key_alloc",
83424 + [49780].param3 = 1,
83425 + [49805].file = "drivers/pci/pci.c",
83426 + [49805].name = "pci_add_cap_save_buffer",
83427 + [49805].param3 = 1,
83428 + [49845].file = "mm/vmalloc.c",
83429 + [49845].name = "__vmalloc_node",
83430 + [49845].param1 = 1,
83431 + [49929].file = "drivers/mtd/ubi/cdev.c",
83432 + [49929].name = "vol_cdev_direct_write",
83433 + [49929].param3 = 1,
83434 + [49935].file = "fs/xfs/kmem.c",
83435 + [49935].name = "kmem_zalloc_greedy",
83436 + [49935].param2 = 1,
83437 + [49935].param3 = 1,
83438 + [49].file = "net/atm/svc.c",
83439 + [49].name = "svc_setsockopt",
83440 + [49].param5 = 1,
83441 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83442 + [50518].name = "u_memcpya",
83443 + [50518].param2 = 1,
83444 + [50518].param3 = 1,
83445 + [5052].file = "drivers/char/ppdev.c",
83446 + [5052].name = "pp_read",
83447 + [5052].param3 = 1,
83448 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83449 + [50562].name = "zoran_write",
83450 + [50562].param3 = 1,
83451 + [50617].file = "fs/hugetlbfs/inode.c",
83452 + [50617].name = "hugetlbfs_read_actor",
83453 + [50617].param2 = 1,
83454 + [50617].param4 = 1,
83455 + [50617].param5 = 1,
83456 + [50692].file = "lib/ts_bm.c",
83457 + [50692].name = "bm_init",
83458 + [50692].param2 = 1,
83459 + [50813].file = "mm/vmalloc.c",
83460 + [50813].name = "__vmalloc_node_flags",
83461 + [50813].param1 = 1,
83462 + [5087].file = "drivers/atm/solos-pci.c",
83463 + [5087].name = "console_store",
83464 + [5087].param4 = 1,
83465 + [5102].file = "drivers/usb/misc/usbtest.c",
83466 + [5102].name = "usbtest_alloc_urb",
83467 + [5102].param3 = 1,
83468 + [5102].param5 = 1,
83469 + [51061].file = "net/bluetooth/mgmt.c",
83470 + [51061].name = "pin_code_reply",
83471 + [51061].param4 = 1,
83472 + [51139].file = "fs/pipe.c",
83473 + [51139].name = "pipe_iov_copy_to_user",
83474 + [51139].param3 = 1,
83475 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83476 + [51177].name = "xprt_rdma_allocate",
83477 + [51177].param2 = 1,
83478 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83479 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83480 + [51182].param1 = 1,
83481 + [51250].file = "fs/read_write.c",
83482 + [51250].name = "rw_copy_check_uvector",
83483 + [51250].param3 = 1,
83484 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83485 + [51253].name = "rt2x00debug_write_eeprom",
83486 + [51253].param3 = 1,
83487 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83488 + [51323].name = "snd_ac97_pcm_assign",
83489 + [51323].param2 = 1,
83490 + [51340].file = "drivers/usb/class/usblp.c",
83491 + [51340].name = "usblp_write",
83492 + [51340].param3 = 1,
83493 + [51499].file = "net/802/garp.c",
83494 + [51499].name = "garp_attr_create",
83495 + [51499].param3 = 1,
83496 + [51842].file = "drivers/hid/hid-core.c",
83497 + [51842].name = "hid_register_field",
83498 + [51842].param2 = 1,
83499 + [51842].param3 = 1,
83500 + [5197].file = "net/core/dev.c",
83501 + [5197].name = "dev_set_alias",
83502 + [5197].param3 = 1,
83503 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83504 + [5204].name = "usbvision_v4l2_read",
83505 + [5204].param3 = 1,
83506 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
83507 + [5206].name = "av7110_vbi_write",
83508 + [5206].param3 = 1,
83509 + [52086].file = "drivers/usb/image/mdc800.c",
83510 + [52086].name = "mdc800_device_read",
83511 + [52086].param3 = 1,
83512 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83513 + [52099].name = "do_surface_dirty_sou",
83514 + [52099].param7 = 1,
83515 + [52172].file = "drivers/pcmcia/cistpl.c",
83516 + [52172].name = "pccard_store_cis",
83517 + [52172].param6 = 1,
83518 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83519 + [52173].name = "remote_settings_file_write",
83520 + [52173].param3 = 1,
83521 + [52199].file = "mm/nobootmem.c",
83522 + [52199].name = "__alloc_bootmem",
83523 + [52199].param1 = 1,
83524 + [52343].file = "drivers/usb/misc/adutux.c",
83525 + [52343].name = "adu_read",
83526 + [52343].param3 = 1,
83527 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
83528 + [52401].name = "r871x_set_wpa_ie",
83529 + [52401].param3 = 1,
83530 + [52699].file = "lib/ts_fsm.c",
83531 + [52699].name = "fsm_init",
83532 + [52699].param2 = 1,
83533 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
83534 + [52721].name = "encrypted_instantiate",
83535 + [52721].param3 = 1,
83536 + [52902].file = "fs/xfs/kmem.h",
83537 + [52902].name = "kmem_zalloc_large",
83538 + [52902].param1 = 1,
83539 + [52950].file = "net/bluetooth/mgmt.c",
83540 + [52950].name = "set_discoverable",
83541 + [52950].param4 = 1,
83542 + [53041].file = "fs/libfs.c",
83543 + [53041].name = "simple_transaction_get",
83544 + [53041].param3 = 1,
83545 + [5313].file = "fs/gfs2/quota.c",
83546 + [5313].name = "do_sync",
83547 + [5313].param1 = 1,
83548 + [53209].file = "drivers/usb/host/ehci-sched.c",
83549 + [53209].name = "iso_sched_alloc",
83550 + [53209].param1 = 1,
83551 + [53302].file = "drivers/firewire/core-cdev.c",
83552 + [53302].name = "dispatch_ioctl",
83553 + [53302].param2 = 1,
83554 + [53355].file = "fs/ceph/dir.c",
83555 + [53355].name = "ceph_read_dir",
83556 + [53355].param3 = 1,
83557 + [53405].file = "drivers/media/video/videobuf-core.c",
83558 + [53405].name = "__videobuf_copy_to_user",
83559 + [53405].param4 = 1,
83560 + [53407].file = "net/wireless/sme.c",
83561 + [53407].name = "cfg80211_connect_result",
83562 + [53407].param4 = 1,
83563 + [53407].param6 = 1,
83564 + [53426].file = "fs/libfs.c",
83565 + [53426].name = "simple_transaction_read",
83566 + [53426].param3 = 1,
83567 + [5344].file = "security/selinux/ss/hashtab.c",
83568 + [5344].name = "hashtab_create",
83569 + [5344].param3 = 1,
83570 + [53513].file = "drivers/mmc/core/mmc_ops.c",
83571 + [53513].name = "mmc_send_bus_test",
83572 + [53513].param4 = 1,
83573 + [53626].file = "drivers/block/paride/pg.c",
83574 + [53626].name = "pg_read",
83575 + [53626].param3 = 1,
83576 + [53631].file = "mm/util.c",
83577 + [53631].name = "memdup_user",
83578 + [53631].param2 = 1,
83579 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
83580 + [53674].name = "ci_ll_write",
83581 + [53674].param4 = 1,
83582 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
83583 + [5389].name = "ib_uverbs_unmarshall_recv",
83584 + [5389].param5 = 1,
83585 + [53901].file = "net/rds/message.c",
83586 + [53901].name = "rds_message_alloc",
83587 + [53901].param1 = 1,
83588 + [53902].file = "net/sctp/socket.c",
83589 + [53902].name = "sctp_setsockopt_initmsg",
83590 + [53902].param3 = 1,
83591 + [5410].file = "kernel/kexec.c",
83592 + [5410].name = "sys_kexec_load",
83593 + [5410].param2 = 1,
83594 + [54172].file = "net/nfc/core.c",
83595 + [54172].name = "nfc_alloc_recv_skb",
83596 + [54172].param1 = 1,
83597 + [54182].file = "drivers/block/rbd.c",
83598 + [54182].name = "rbd_snap_add",
83599 + [54182].param4 = 1,
83600 + [54201].file = "drivers/platform/x86/asus_acpi.c",
83601 + [54201].name = "mled_proc_write",
83602 + [54201].param3 = 1,
83603 + [54263].file = "security/keys/trusted.c",
83604 + [54263].name = "trusted_instantiate",
83605 + [54263].param3 = 1,
83606 + [54296].file = "include/linux/mISDNif.h",
83607 + [54296].name = "_alloc_mISDN_skb",
83608 + [54296].param3 = 1,
83609 + [54298].file = "drivers/usb/wusbcore/crypto.c",
83610 + [54298].name = "wusb_ccm_mac",
83611 + [54298].param7 = 1,
83612 + [54318].file = "include/drm/drm_mem_util.h",
83613 + [54318].name = "drm_malloc_ab",
83614 + [54318].param1 = 1,
83615 + [54318].param2 = 1,
83616 + [54335].file = "drivers/md/dm-table.c",
83617 + [54335].name = "dm_vcalloc",
83618 + [54335].param1 = 1,
83619 + [54335].param2 = 1,
83620 + [54338].file = "fs/ntfs/malloc.h",
83621 + [54338].name = "ntfs_malloc_nofs",
83622 + [54338].param1 = 1,
83623 + [54339].file = "security/smack/smackfs.c",
83624 + [54339].name = "smk_write_cipso",
83625 + [54339].param3 = 1,
83626 + [54369].file = "drivers/usb/storage/realtek_cr.c",
83627 + [54369].name = "rts51x_read_mem",
83628 + [54369].param4 = 1,
83629 + [5438].file = "sound/core/memory.c",
83630 + [5438].name = "copy_to_user_fromio",
83631 + [5438].param3 = 1,
83632 + [54401].file = "lib/dynamic_debug.c",
83633 + [54401].name = "ddebug_proc_write",
83634 + [54401].param3 = 1,
83635 + [54467].file = "net/packet/af_packet.c",
83636 + [54467].name = "packet_setsockopt",
83637 + [54467].param5 = 1,
83638 + [54573].file = "ipc/sem.c",
83639 + [54573].name = "sys_semop",
83640 + [54573].param3 = 1,
83641 + [54583].file = "net/sctp/socket.c",
83642 + [54583].name = "sctp_setsockopt_peer_addr_params",
83643 + [54583].param3 = 1,
83644 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
83645 + [54643].name = "um_idi_write",
83646 + [54643].param3 = 1,
83647 + [54657].file = "mm/migrate.c",
83648 + [54657].name = "do_pages_stat",
83649 + [54657].param2 = 1,
83650 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
83651 + [54663].name = "diva_os_malloc",
83652 + [54663].param2 = 1,
83653 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
83654 + [54701].name = "altera_swap_ir",
83655 + [54701].param2 = 1,
83656 + [54751].file = "drivers/infiniband/core/device.c",
83657 + [54751].name = "ib_alloc_device",
83658 + [54751].param1 = 1,
83659 + [54771].file = "drivers/isdn/mISDN/socket.c",
83660 + [54771].name = "_l2_alloc_skb",
83661 + [54771].param1 = 1,
83662 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83663 + [54777].name = "ath6kl_debug_roam_tbl_event",
83664 + [54777].param3 = 1,
83665 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83666 + [54806].name = "lpfc_debugfs_dif_err_write",
83667 + [54806].param3 = 1,
83668 + [5494].file = "fs/cifs/cifsacl.c",
83669 + [5494].name = "cifs_idmap_key_instantiate",
83670 + [5494].param3 = 1,
83671 + [55066].file = "net/ipv6/ipv6_sockglue.c",
83672 + [55066].name = "do_ipv6_setsockopt",
83673 + [55066].param5 = 1,
83674 + [55105].file = "drivers/base/devres.c",
83675 + [55105].name = "devres_alloc",
83676 + [55105].param2 = 1,
83677 + [55115].file = "net/sctp/probe.c",
83678 + [55115].name = "sctpprobe_read",
83679 + [55115].param3 = 1,
83680 + [55155].file = "net/bluetooth/rfcomm/sock.c",
83681 + [55155].name = "rfcomm_sock_setsockopt",
83682 + [55155].param5 = 1,
83683 + [55187].file = "security/keys/keyctl.c",
83684 + [55187].name = "keyctl_describe_key",
83685 + [55187].param3 = 1,
83686 + [55253].file = "drivers/net/wireless/ray_cs.c",
83687 + [55253].name = "ray_cs_essid_proc_write",
83688 + [55253].param3 = 1,
83689 + [55341].file = "drivers/staging/sep/sep_driver.c",
83690 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
83691 + [55341].param4 = 1,
83692 + [55341].param5 = 1,
83693 + [55417].file = "drivers/hv/channel.c",
83694 + [55417].name = "vmbus_open",
83695 + [55417].param2 = 1,
83696 + [55417].param3 = 1,
83697 + [5548].file = "drivers/media/media-entity.c",
83698 + [5548].name = "media_entity_init",
83699 + [5548].param2 = 1,
83700 + [5548].param4 = 1,
83701 + [55546].file = "drivers/spi/spi.c",
83702 + [55546].name = "spi_alloc_master",
83703 + [55546].param2 = 1,
83704 + [55580].file = "drivers/usb/mon/mon_bin.c",
83705 + [55580].name = "copy_from_buf",
83706 + [55580].param2 = 1,
83707 + [55584].file = "drivers/tty/tty_buffer.c",
83708 + [55584].name = "tty_buffer_alloc",
83709 + [55584].param2 = 1,
83710 + [55712].file = "drivers/char/mem.c",
83711 + [55712].name = "read_zero",
83712 + [55712].param3 = 1,
83713 + [55727].file = "drivers/media/video/stk-webcam.c",
83714 + [55727].name = "stk_prepare_sio_buffers",
83715 + [55727].param2 = 1,
83716 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
83717 + [55816].name = "altera_set_ir_pre",
83718 + [55816].param2 = 1,
83719 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
83720 + [55826].name = "ipath_get_base_info",
83721 + [55826].param3 = 1,
83722 + [5586].file = "net/atm/common.c",
83723 + [5586].name = "alloc_tx",
83724 + [5586].param2 = 1,
83725 + [55978].file = "drivers/usb/misc/iowarrior.c",
83726 + [55978].name = "iowarrior_write",
83727 + [55978].param3 = 1,
83728 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
83729 + [56170].name = "__wa_xfer_setup_segs",
83730 + [56170].param2 = 1,
83731 + [56199].file = "fs/binfmt_misc.c",
83732 + [56199].name = "parse_command",
83733 + [56199].param2 = 1,
83734 + [56218].file = "drivers/mmc/card/mmc_test.c",
83735 + [56218].name = "mtf_test_write",
83736 + [56218].param3 = 1,
83737 + [56239].file = "fs/sysfs/file.c",
83738 + [56239].name = "fill_write_buffer",
83739 + [56239].param3 = 1,
83740 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
83741 + [5624].name = "ath9k_wmi_cmd",
83742 + [5624].param4 = 1,
83743 + [56416].file = "drivers/misc/lkdtm.c",
83744 + [56416].name = "do_register_entry",
83745 + [56416].param4 = 1,
83746 + [56458].file = "drivers/usb/host/hwa-hc.c",
83747 + [56458].name = "__hwahc_op_set_ptk",
83748 + [56458].param5 = 1,
83749 + [56471].file = "include/linux/slab.h",
83750 + [56471].name = "kcalloc",
83751 + [56471].param1 = 1,
83752 + [56471].param2 = 1,
83753 + [56513].file = "fs/cifs/connect.c",
83754 + [56513].name = "cifs_readv_from_socket",
83755 + [56513].param3 = 1,
83756 + [56531].file = "net/bluetooth/l2cap_core.c",
83757 + [56531].name = "l2cap_send_cmd",
83758 + [56531].param4 = 1,
83759 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
83760 + [56544].name = "receive_DataRequest",
83761 + [56544].param3 = 1,
83762 + [56609].file = "lib/mpi/mpi-internal.h",
83763 + [56609].name = "RESIZE_IF_NEEDED",
83764 + [56609].param2 = 1,
83765 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
83766 + [56652].name = "altera_set_dr_post",
83767 + [56652].param2 = 1,
83768 + [56653].file = "net/irda/af_irda.c",
83769 + [56653].name = "irda_setsockopt",
83770 + [56653].param5 = 1,
83771 + [56672].file = "drivers/char/agp/generic.c",
83772 + [56672].name = "agp_alloc_page_array",
83773 + [56672].param1 = 1,
83774 + [56798].file = "fs/bio.c",
83775 + [56798].name = "bio_alloc_map_data",
83776 + [56798].param2 = 1,
83777 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
83778 + [56843].name = "iscsi_recv_pdu",
83779 + [56843].param4 = 1,
83780 + [56903].file = "drivers/mtd/mtdchar.c",
83781 + [56903].name = "mtdchar_readoob",
83782 + [56903].param4 = 1,
83783 + [5699].file = "net/sctp/socket.c",
83784 + [5699].name = "sctp_setsockopt_default_send_param",
83785 + [5699].param3 = 1,
83786 + [5704].file = "drivers/mtd/mtdswap.c",
83787 + [5704].name = "mtdswap_init",
83788 + [5704].param2 = 1,
83789 + [57128].file = "drivers/pnp/pnpbios/proc.c",
83790 + [57128].name = "pnpbios_proc_write",
83791 + [57128].param3 = 1,
83792 + [57190].file = "drivers/char/agp/generic.c",
83793 + [57190].name = "agp_generic_alloc_user",
83794 + [57190].param1 = 1,
83795 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
83796 + [57252].name = "dvb_dmxdev_set_buffer_size",
83797 + [57252].param2 = 1,
83798 + [57392].file = "drivers/block/aoe/aoecmd.c",
83799 + [57392].name = "new_skb",
83800 + [57392].param1 = 1,
83801 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
83802 + [57471].name = "sn9c102_read",
83803 + [57471].param3 = 1,
83804 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
83805 + [57547].name = "get_derived_key",
83806 + [57547].param4 = 1,
83807 + [57552].file = "net/sunrpc/cache.c",
83808 + [57552].name = "cache_slow_downcall",
83809 + [57552].param2 = 1,
83810 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
83811 + [57670].name = "btmrvl_pscmd_write",
83812 + [57670].param3 = 1,
83813 + [57710].file = "include/linux/usb/wusb.h",
83814 + [57710].name = "wusb_prf_256",
83815 + [57710].param7 = 1,
83816 + [57724].file = "net/bluetooth/hci_sock.c",
83817 + [57724].name = "hci_sock_setsockopt",
83818 + [57724].param5 = 1,
83819 + [57761].file = "kernel/kexec.c",
83820 + [57761].name = "kimage_crash_alloc",
83821 + [57761].param3 = 1,
83822 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
83823 + [57786].name = "compat_do_ip6t_set_ctl",
83824 + [57786].param4 = 1,
83825 + [57872].file = "fs/ceph/xattr.c",
83826 + [57872].name = "ceph_setxattr",
83827 + [57872].param4 = 1,
83828 + [57927].file = "fs/read_write.c",
83829 + [57927].name = "sys_preadv",
83830 + [57927].param3 = 1,
83831 + [58012].file = "include/net/bluetooth/bluetooth.h",
83832 + [58012].name = "bt_skb_alloc",
83833 + [58012].param1 = 1,
83834 + [58020].file = "drivers/firewire/core-cdev.c",
83835 + [58020].name = "fw_device_op_ioctl",
83836 + [58020].param2 = 1,
83837 + [58043].file = "kernel/auditfilter.c",
83838 + [58043].name = "audit_unpack_string",
83839 + [58043].param3 = 1,
83840 + [58087].file = "kernel/module.c",
83841 + [58087].name = "module_alloc_update_bounds_rw",
83842 + [58087].param1 = 1,
83843 + [58124].file = "drivers/usb/misc/usbtest.c",
83844 + [58124].name = "ctrl_out",
83845 + [58124].param3 = 1,
83846 + [58124].param5 = 1,
83847 + [58217].file = "net/sctp/socket.c",
83848 + [58217].name = "sctp_setsockopt_peer_primary_addr",
83849 + [58217].param3 = 1,
83850 + [58263].file = "security/keys/keyring.c",
83851 + [58263].name = "keyring_read",
83852 + [58263].param3 = 1,
83853 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
83854 + [5830].name = "vga_switcheroo_debugfs_write",
83855 + [5830].param3 = 1,
83856 + [58320].file = "drivers/scsi/scsi_proc.c",
83857 + [58320].name = "proc_scsi_write",
83858 + [58320].param3 = 1,
83859 + [58344].file = "net/sunrpc/cache.c",
83860 + [58344].name = "read_flush",
83861 + [58344].param3 = 1,
83862 + [58379].file = "mm/nobootmem.c",
83863 + [58379].name = "__alloc_bootmem_node",
83864 + [58379].param2 = 1,
83865 + [58597].file = "kernel/kfifo.c",
83866 + [58597].name = "__kfifo_to_user",
83867 + [58597].param3 = 1,
83868 + [58641].file = "drivers/usb/misc/adutux.c",
83869 + [58641].name = "adu_write",
83870 + [58641].param3 = 1,
83871 + [58709].file = "fs/compat.c",
83872 + [58709].name = "compat_sys_pwritev",
83873 + [58709].param3 = 1,
83874 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83875 + [58769].name = "zd_usb_read_fw",
83876 + [58769].param4 = 1,
83877 + [5876].file = "drivers/net/ppp/ppp_generic.c",
83878 + [5876].name = "ppp_write",
83879 + [5876].param3 = 1,
83880 + [58826].file = "net/sunrpc/xprt.c",
83881 + [58826].name = "xprt_alloc",
83882 + [58826].param2 = 1,
83883 + [58865].file = "include/linux/slub_def.h",
83884 + [58865].name = "kmalloc_order_trace",
83885 + [58865].param1 = 1,
83886 + [58867].file = "drivers/platform/x86/asus_acpi.c",
83887 + [58867].name = "wled_proc_write",
83888 + [58867].param3 = 1,
83889 + [58888].file = "fs/xattr.c",
83890 + [58888].name = "listxattr",
83891 + [58888].param3 = 1,
83892 + [58889].file = "kernel/trace/trace_kprobe.c",
83893 + [58889].name = "probes_write",
83894 + [58889].param3 = 1,
83895 + [58912].file = "drivers/lguest/core.c",
83896 + [58912].name = "__lgwrite",
83897 + [58912].param4 = 1,
83898 + [58918].file = "sound/core/pcm_native.c",
83899 + [58918].name = "snd_pcm_aio_write",
83900 + [58918].param3 = 1,
83901 + [58942].file = "drivers/block/aoe/aoedev.c",
83902 + [58942].name = "aoedev_flush",
83903 + [58942].param2 = 1,
83904 + [58958].file = "fs/fuse/control.c",
83905 + [58958].name = "fuse_conn_limit_write",
83906 + [58958].param3 = 1,
83907 + [59005].file = "drivers/staging/sep/sep_driver.c",
83908 + [59005].name = "sep_prepare_input_dma_table",
83909 + [59005].param2 = 1,
83910 + [59005].param3 = 1,
83911 + [59013].file = "fs/xfs/xfs_ioctl.c",
83912 + [59013].name = "xfs_handle_to_dentry",
83913 + [59013].param3 = 1,
83914 + [59034].file = "drivers/acpi/acpica/dsobject.c",
83915 + [59034].name = "acpi_ds_build_internal_package_obj",
83916 + [59034].param3 = 1,
83917 + [59073].file = "drivers/staging/speakup/i18n.c",
83918 + [59073].name = "msg_set",
83919 + [59073].param3 = 1,
83920 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
83921 + [59074].name = "ddp_make_gl",
83922 + [59074].param1 = 1,
83923 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
83924 + [59297].name = "dvb_play",
83925 + [59297].param3 = 1,
83926 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
83927 + [59472].name = "command_file_write",
83928 + [59472].param3 = 1,
83929 + [59504].file = "fs/exofs/super.c",
83930 + [59504].name = "__alloc_dev_table",
83931 + [59504].param2 = 1,
83932 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83933 + [59505].name = "pvr2_ioread_read",
83934 + [59505].param3 = 1,
83935 + [59681].file = "fs/xfs/kmem.c",
83936 + [59681].name = "kmem_alloc",
83937 + [59681].param1 = 1,
83938 + [5968].file = "net/sunrpc/sched.c",
83939 + [5968].name = "rpc_malloc",
83940 + [5968].param2 = 1,
83941 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
83942 + [59695].name = "ulog_alloc_skb",
83943 + [59695].param1 = 1,
83944 + [59838].file = "net/netlink/af_netlink.c",
83945 + [59838].name = "nl_pid_hash_zalloc",
83946 + [59838].param1 = 1,
83947 + [59856].file = "drivers/base/devres.c",
83948 + [59856].name = "devm_kzalloc",
83949 + [59856].param2 = 1,
83950 + [60066].file = "mm/filemap.c",
83951 + [60066].name = "iov_iter_copy_from_user",
83952 + [60066].param4 = 1,
83953 + [60185].file = "kernel/params.c",
83954 + [60185].name = "kmalloc_parameter",
83955 + [60185].param1 = 1,
83956 + [60198].file = "fs/nfs/nfs4proc.c",
83957 + [60198].name = "nfs4_write_cached_acl",
83958 + [60198].param3 = 1,
83959 + [60330].file = "drivers/media/video/w9966.c",
83960 + [60330].name = "w9966_v4l_read",
83961 + [60330].param3 = 1,
83962 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
83963 + [604].name = "r8712_usbctrl_vendorreq",
83964 + [604].param6 = 1,
83965 + [60543].file = "drivers/usb/class/usbtmc.c",
83966 + [60543].name = "usbtmc_read",
83967 + [60543].param3 = 1,
83968 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
83969 + [60683].name = "snd_opl4_mem_proc_write",
83970 + [60683].param5 = 1,
83971 + [60693].file = "drivers/misc/hpilo.c",
83972 + [60693].name = "ilo_read",
83973 + [60693].param3 = 1,
83974 + [60744].file = "sound/pci/emu10k1/emuproc.c",
83975 + [60744].name = "snd_emu10k1_fx8010_read",
83976 + [60744].param5 = 1,
83977 + [60777].file = "fs/ntfs/malloc.h",
83978 + [60777].name = "ntfs_malloc_nofs_nofail",
83979 + [60777].param1 = 1,
83980 + [60833].file = "drivers/block/aoe/aoenet.c",
83981 + [60833].name = "set_aoe_iflist",
83982 + [60833].param2 = 1,
83983 + [60882].file = "drivers/input/joydev.c",
83984 + [60882].name = "joydev_compat_ioctl",
83985 + [60882].param2 = 1,
83986 + [60891].file = "kernel/sched/core.c",
83987 + [60891].name = "sys_sched_setaffinity",
83988 + [60891].param2 = 1,
83989 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
83990 + [60920].name = "qib_get_base_info",
83991 + [60920].param3 = 1,
83992 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
83993 + [60928].name = "bcm_char_read",
83994 + [60928].param3 = 1,
83995 + [61122].file = "drivers/base/devres.c",
83996 + [61122].name = "alloc_dr",
83997 + [61122].param2 = 1,
83998 + [61254].file = "drivers/scsi/scsi_devinfo.c",
83999 + [61254].name = "proc_scsi_devinfo_write",
84000 + [61254].param3 = 1,
84001 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84002 + [61283].name = "ath6kl_fwlog_read",
84003 + [61283].param3 = 1,
84004 + [61289].file = "security/apparmor/apparmorfs.c",
84005 + [61289].name = "aa_simple_write_to_buffer",
84006 + [61289].param4 = 1,
84007 + [61389].file = "include/linux/slab.h",
84008 + [61389].name = "kzalloc_node",
84009 + [61389].param1 = 1,
84010 + [61441].file = "fs/ntfs/file.c",
84011 + [61441].name = "ntfs_copy_from_user_iovec",
84012 + [61441].param3 = 1,
84013 + [61441].param6 = 1,
84014 + [61552].file = "drivers/input/evdev.c",
84015 + [61552].name = "str_to_user",
84016 + [61552].param2 = 1,
84017 + [61673].file = "security/keys/trusted.c",
84018 + [61673].name = "trusted_update",
84019 + [61673].param3 = 1,
84020 + [61676].file = "kernel/module.c",
84021 + [61676].name = "module_alloc_update_bounds_rx",
84022 + [61676].param1 = 1,
84023 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84024 + [61684].name = "cxgb3_get_cpl_reply_skb",
84025 + [61684].param2 = 1,
84026 + [6173].file = "net/netlink/af_netlink.c",
84027 + [6173].name = "netlink_sendmsg",
84028 + [6173].param4 = 1,
84029 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84030 + [61770].name = "et61x251_read",
84031 + [61770].param3 = 1,
84032 + [61772].file = "fs/exofs/ore_raid.c",
84033 + [61772].name = "_sp2d_alloc",
84034 + [61772].param1 = 1,
84035 + [61772].param2 = 1,
84036 + [61772].param3 = 1,
84037 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84038 + [61926].name = "ddb_input_read",
84039 + [61926].param3 = 1,
84040 + [61932].file = "drivers/message/fusion/mptctl.c",
84041 + [61932].name = "__mptctl_ioctl",
84042 + [61932].param2 = 1,
84043 + [61966].file = "fs/nfs/nfs4proc.c",
84044 + [61966].name = "nfs4_alloc_slots",
84045 + [61966].param1 = 1,
84046 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84047 + [62081].name = "vlsi_alloc_ring",
84048 + [62081].param3 = 1,
84049 + [62081].param4 = 1,
84050 + [62116].file = "fs/libfs.c",
84051 + [62116].name = "simple_attr_read",
84052 + [62116].param3 = 1,
84053 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
84054 + [6211].name = "pcnet32_realloc_tx_ring",
84055 + [6211].param3 = 1,
84056 + [62294].file = "sound/core/info.c",
84057 + [62294].name = "resize_info_buffer",
84058 + [62294].param2 = 1,
84059 + [62387].file = "fs/nfs/idmap.c",
84060 + [62387].name = "nfs_idmap_lookup_id",
84061 + [62387].param2 = 1,
84062 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
84063 + [62465].name = "altera_set_dr_pre",
84064 + [62465].param2 = 1,
84065 + [62466].file = "lib/mpi/mpiutil.c",
84066 + [62466].name = "mpi_alloc",
84067 + [62466].param1 = 1,
84068 + [62495].file = "drivers/block/floppy.c",
84069 + [62495].name = "fallback_on_nodma_alloc",
84070 + [62495].param2 = 1,
84071 + [62498].file = "fs/xattr.c",
84072 + [62498].name = "sys_listxattr",
84073 + [62498].param3 = 1,
84074 + [625].file = "fs/read_write.c",
84075 + [625].name = "sys_pwritev",
84076 + [625].param3 = 1,
84077 + [62662].file = "drivers/message/fusion/mptctl.c",
84078 + [62662].name = "mptctl_getiocinfo",
84079 + [62662].param2 = 1,
84080 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84081 + [62669].name = "tled_proc_write",
84082 + [62669].param3 = 1,
84083 + [62714].file = "security/keys/keyctl.c",
84084 + [62714].name = "keyctl_update_key",
84085 + [62714].param3 = 1,
84086 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
84087 + [62760].name = "play_iframe",
84088 + [62760].param3 = 1,
84089 + [62851].file = "fs/proc/vmcore.c",
84090 + [62851].name = "read_vmcore",
84091 + [62851].param3 = 1,
84092 + [62870].file = "fs/nfs/idmap.c",
84093 + [62870].name = "nfs_idmap_get_desc",
84094 + [62870].param2 = 1,
84095 + [62870].param4 = 1,
84096 + [62905].file = "net/caif/cfpkt_skbuff.c",
84097 + [62905].name = "cfpkt_create",
84098 + [62905].param1 = 1,
84099 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
84100 + [62920].name = "b43_nphy_load_samples",
84101 + [62920].param3 = 1,
84102 + [62925].file = "include/rdma/ib_verbs.h",
84103 + [62925].name = "ib_copy_from_udata",
84104 + [62925].param3 = 1,
84105 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
84106 + [62934].name = "wl1251_cmd_template_set",
84107 + [62934].param4 = 1,
84108 + [62940].file = "drivers/scsi/libsrp.c",
84109 + [62940].name = "srp_ring_alloc",
84110 + [62940].param2 = 1,
84111 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84112 + [62967].name = "encrypted_update",
84113 + [62967].param3 = 1,
84114 + [62970].file = "net/sched/sch_api.c",
84115 + [62970].name = "qdisc_class_hash_alloc",
84116 + [62970].param1 = 1,
84117 + [62999].file = "net/core/neighbour.c",
84118 + [62999].name = "neigh_hash_alloc",
84119 + [62999].param1 = 1,
84120 + [63007].file = "fs/proc/base.c",
84121 + [63007].name = "proc_coredump_filter_write",
84122 + [63007].param3 = 1,
84123 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84124 + [63010].name = "ttm_page_pool_free",
84125 + [63010].param2 = 1,
84126 + [63045].file = "crypto/shash.c",
84127 + [63045].name = "shash_setkey_unaligned",
84128 + [63045].param3 = 1,
84129 + [63075].file = "kernel/relay.c",
84130 + [63075].name = "relay_alloc_page_array",
84131 + [63075].param1 = 1,
84132 + [63076].file = "fs/cifs/xattr.c",
84133 + [63076].name = "cifs_setxattr",
84134 + [63076].param4 = 1,
84135 + [63091].file = "drivers/net/usb/pegasus.c",
84136 + [63091].name = "get_registers",
84137 + [63091].param3 = 1,
84138 + [6331].file = "drivers/atm/solos-pci.c",
84139 + [6331].name = "solos_param_store",
84140 + [6331].param4 = 1,
84141 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84142 + [63367].name = "ip_set_alloc",
84143 + [63367].param1 = 1,
84144 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84145 + [63489].name = "btmrvl_hscfgcmd_write",
84146 + [63489].param3 = 1,
84147 + [63490].file = "crypto/shash.c",
84148 + [63490].name = "shash_compat_setkey",
84149 + [63490].param3 = 1,
84150 + [63605].file = "mm/mempool.c",
84151 + [63605].name = "mempool_kmalloc",
84152 + [63605].param2 = 1,
84153 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
84154 + [63633].name = "btmrvl_sdio_host_to_card",
84155 + [63633].param3 = 1,
84156 + [63961].file = "fs/xattr.c",
84157 + [63961].name = "sys_flistxattr",
84158 + [63961].param3 = 1,
84159 + [63964].file = "net/sctp/socket.c",
84160 + [63964].name = "sctp_setsockopt_maxseg",
84161 + [63964].param3 = 1,
84162 + [63988].file = "drivers/input/evdev.c",
84163 + [63988].name = "evdev_ioctl_compat",
84164 + [63988].param2 = 1,
84165 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
84166 + [64055].name = "dvb_aplay",
84167 + [64055].param3 = 1,
84168 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84169 + [64156].name = "ath6kl_mgmt_tx",
84170 + [64156].param9 = 1,
84171 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
84172 + [64226].name = "ca_extend",
84173 + [64226].param2 = 1,
84174 + [64227].file = "mm/nobootmem.c",
84175 + [64227].name = "__alloc_bootmem_node_nopanic",
84176 + [64227].param2 = 1,
84177 + [64351].file = "kernel/kfifo.c",
84178 + [64351].name = "kfifo_copy_from_user",
84179 + [64351].param3 = 1,
84180 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84181 + [64392].name = "mmc_send_cxd_data",
84182 + [64392].param5 = 1,
84183 + [64423].file = "kernel/sched/core.c",
84184 + [64423].name = "get_user_cpu_mask",
84185 + [64423].param2 = 1,
84186 + [64432].file = "security/selinux/selinuxfs.c",
84187 + [64432].name = "sel_write_create",
84188 + [64432].param3 = 1,
84189 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84190 + [64471].name = "btmrvl_hscmd_write",
84191 + [64471].param3 = 1,
84192 + [64667].file = "sound/core/oss/pcm_oss.c",
84193 + [64667].name = "snd_pcm_oss_read",
84194 + [64667].param3 = 1,
84195 + [64689].file = "sound/isa/gus/gus_dram.c",
84196 + [64689].name = "snd_gus_dram_read",
84197 + [64689].param4 = 1,
84198 + [64692].file = "fs/binfmt_misc.c",
84199 + [64692].name = "bm_entry_write",
84200 + [64692].param3 = 1,
84201 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84202 + [64705].name = "sca3000_read_first_n_hw_rb",
84203 + [64705].param2 = 1,
84204 + [64713].file = "fs/cifs/connect.c",
84205 + [64713].name = "extract_hostname",
84206 + [64713].param1 = 1,
84207 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84208 + [64743].name = "dlmfs_file_read",
84209 + [64743].param3 = 1,
84210 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
84211 + [64771].name = "datablob_format",
84212 + [64771].param2 = 1,
84213 + [6477].file = "net/bluetooth/mgmt.c",
84214 + [6477].name = "mgmt_pending_add",
84215 + [6477].param5 = 1,
84216 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84217 + [64906].name = "b43legacy_debugfs_write",
84218 + [64906].param3 = 1,
84219 + [64913].file = "sound/core/oss/pcm_oss.c",
84220 + [64913].name = "snd_pcm_oss_write1",
84221 + [64913].param3 = 1,
84222 + [64961].file = "drivers/spi/spidev.c",
84223 + [64961].name = "spidev_ioctl",
84224 + [64961].param2 = 1,
84225 + [65033].file = "crypto/shash.c",
84226 + [65033].name = "shash_async_setkey",
84227 + [65033].param3 = 1,
84228 + [65093].file = "security/integrity/evm/evm_secfs.c",
84229 + [65093].name = "evm_write_key",
84230 + [65093].param3 = 1,
84231 + [6514].file = "mm/nobootmem.c",
84232 + [6514].name = "__alloc_bootmem_low",
84233 + [6514].param1 = 1,
84234 + [65169].file = "net/core/skbuff.c",
84235 + [65169].name = "dev_alloc_skb",
84236 + [65169].param1 = 1,
84237 + [6517].file = "drivers/md/dm-table.c",
84238 + [6517].name = "alloc_targets",
84239 + [6517].param2 = 1,
84240 + [65205].file = "drivers/input/evdev.c",
84241 + [65205].name = "handle_eviocgbit",
84242 + [65205].param3 = 1,
84243 + [65237].file = "kernel/profile.c",
84244 + [65237].name = "read_profile",
84245 + [65237].param3 = 1,
84246 + [65343].file = "kernel/trace/trace.c",
84247 + [65343].name = "tracing_clock_write",
84248 + [65343].param3 = 1,
84249 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84250 + [65345].name = "xz_dec_lzma2_create",
84251 + [65345].param2 = 1,
84252 + [65409].file = "net/802/garp.c",
84253 + [65409].name = "garp_request_join",
84254 + [65409].param4 = 1,
84255 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84256 + [65432].name = "kone_receive",
84257 + [65432].param4 = 1,
84258 + [65514].file = "drivers/media/video/gspca/t613.c",
84259 + [65514].name = "reg_w_ixbuf",
84260 + [65514].param4 = 1,
84261 + [6551].file = "drivers/usb/host/xhci-mem.c",
84262 + [6551].name = "xhci_alloc_stream_info",
84263 + [6551].param3 = 1,
84264 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84265 + [65535].name = "opera1_xilinx_rw",
84266 + [65535].param5 = 1,
84267 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84268 + [6672].name = "b43_debugfs_write",
84269 + [6672].param3 = 1,
84270 + [6691].file = "drivers/acpi/proc.c",
84271 + [6691].name = "acpi_system_write_wakeup_device",
84272 + [6691].param3 = 1,
84273 + [6865].file = "drivers/staging/iio/ring_sw.c",
84274 + [6865].name = "iio_read_first_n_sw_rb",
84275 + [6865].param2 = 1,
84276 + [6867].file = "fs/coda/psdev.c",
84277 + [6867].name = "coda_psdev_read",
84278 + [6867].param3 = 1,
84279 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84280 + [6891].name = "btmrvl_gpiogap_write",
84281 + [6891].param3 = 1,
84282 + [6944].file = "drivers/ide/ide-proc.c",
84283 + [6944].name = "ide_settings_proc_write",
84284 + [6944].param3 = 1,
84285 + [6950].file = "drivers/isdn/capi/capi.c",
84286 + [6950].name = "capi_write",
84287 + [6950].param3 = 1,
84288 + [697].file = "sound/isa/gus/gus_dram.c",
84289 + [697].name = "snd_gus_dram_peek",
84290 + [697].param4 = 1,
84291 + [7066].file = "security/keys/keyctl.c",
84292 + [7066].name = "keyctl_instantiate_key_common",
84293 + [7066].param4 = 1,
84294 + [7125].file = "include/net/nfc/nci_core.h",
84295 + [7125].name = "nci_skb_alloc",
84296 + [7125].param2 = 1,
84297 + [7129].file = "mm/maccess.c",
84298 + [7129].name = "__probe_kernel_read",
84299 + [7129].param3 = 1,
84300 + [7158].file = "kernel/trace/trace.c",
84301 + [7158].name = "tracing_read_pipe",
84302 + [7158].param3 = 1,
84303 + [720].file = "sound/pci/rme9652/hdsp.c",
84304 + [720].name = "snd_hdsp_playback_copy",
84305 + [720].param5 = 1,
84306 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
84307 + [7236].name = "drm_plane_init",
84308 + [7236].param6 = 1,
84309 + [7411].file = "drivers/vhost/vhost.c",
84310 + [7411].name = "__vhost_add_used_n",
84311 + [7411].param3 = 1,
84312 + [7432].file = "net/bluetooth/mgmt.c",
84313 + [7432].name = "mgmt_event",
84314 + [7432].param4 = 1,
84315 + [7488].file = "security/keys/user_defined.c",
84316 + [7488].name = "user_read",
84317 + [7488].param3 = 1,
84318 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84319 + [7551].name = "ad7879_spi_xfer",
84320 + [7551].param3 = 1,
84321 + [7671].file = "mm/nobootmem.c",
84322 + [7671].name = "__alloc_bootmem_node_high",
84323 + [7671].param2 = 1,
84324 + [7676].file = "drivers/acpi/custom_method.c",
84325 + [7676].name = "cm_write",
84326 + [7676].param3 = 1,
84327 + [7693].file = "net/sctp/socket.c",
84328 + [7693].name = "sctp_setsockopt_associnfo",
84329 + [7693].param3 = 1,
84330 + [7697].file = "security/selinux/selinuxfs.c",
84331 + [7697].name = "sel_write_access",
84332 + [7697].param3 = 1,
84333 + [7843].file = "fs/compat.c",
84334 + [7843].name = "compat_sys_readv",
84335 + [7843].param3 = 1,
84336 + [7883].file = "net/sched/sch_sfq.c",
84337 + [7883].name = "sfq_alloc",
84338 + [7883].param1 = 1,
84339 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
84340 + [7924].name = "cx18_read_pos",
84341 + [7924].param3 = 1,
84342 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84343 + [7958].name = "vga_arb_write",
84344 + [7958].param3 = 1,
84345 + [7976].file = "drivers/usb/gadget/rndis.c",
84346 + [7976].name = "rndis_add_response",
84347 + [7976].param2 = 1,
84348 + [7985].file = "net/mac80211/cfg.c",
84349 + [7985].name = "ieee80211_mgmt_tx",
84350 + [7985].param9 = 1,
84351 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84352 + [8014].name = "init_list_set",
84353 + [8014].param2 = 1,
84354 + [8014].param3 = 1,
84355 + [8126].file = "sound/soc/soc-core.c",
84356 + [8126].name = "codec_reg_read_file",
84357 + [8126].param3 = 1,
84358 + [8317].file = "security/smack/smackfs.c",
84359 + [8317].name = "smk_write_ambient",
84360 + [8317].param3 = 1,
84361 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84362 + [8335].name = "dvb_dvr_set_buffer_size",
84363 + [8335].param2 = 1,
84364 + [8383].file = "kernel/module.c",
84365 + [8383].name = "copy_and_check",
84366 + [8383].param3 = 1,
84367 + [8411].file = "net/caif/cfpkt_skbuff.c",
84368 + [8411].name = "cfpkt_append",
84369 + [8411].param3 = 1,
84370 + [8536].file = "fs/cifs/dns_resolve.c",
84371 + [8536].name = "dns_resolve_server_name_to_ip",
84372 + [8536].param1 = 1,
84373 + [857].file = "drivers/virtio/virtio_ring.c",
84374 + [857].name = "virtqueue_add_buf",
84375 + [857].param3 = 1,
84376 + [857].param4 = 1,
84377 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84378 + [8650].name = "vmw_kms_present",
84379 + [8650].param9 = 1,
84380 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
84381 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
84382 + [8654].param2 = 1,
84383 + [8654].param3 = 1,
84384 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84385 + [865].name = "regmap_access_read_file",
84386 + [865].param3 = 1,
84387 + [8663].file = "net/bridge/netfilter/ebtables.c",
84388 + [8663].name = "do_update_counters",
84389 + [8663].param4 = 1,
84390 + [8684].file = "fs/read_write.c",
84391 + [8684].name = "sys_writev",
84392 + [8684].param3 = 1,
84393 + [8699].file = "security/selinux/selinuxfs.c",
84394 + [8699].name = "sel_commit_bools_write",
84395 + [8699].param3 = 1,
84396 + [8764].file = "drivers/usb/core/devio.c",
84397 + [8764].name = "usbdev_read",
84398 + [8764].param3 = 1,
84399 + [8802].file = "fs/dlm/user.c",
84400 + [8802].name = "device_write",
84401 + [8802].param3 = 1,
84402 + [8810].file = "net/mac80211/debugfs_sta.c",
84403 + [8810].name = "sta_agg_status_write",
84404 + [8810].param3 = 1,
84405 + [8815].file = "security/tomoyo/securityfs_if.c",
84406 + [8815].name = "tomoyo_write_self",
84407 + [8815].param3 = 1,
84408 + [8821].file = "net/wireless/sme.c",
84409 + [8821].name = "cfg80211_roamed",
84410 + [8821].param5 = 1,
84411 + [8821].param7 = 1,
84412 + [8833].file = "security/selinux/ss/services.c",
84413 + [8833].name = "security_context_to_sid",
84414 + [8833].param2 = 1,
84415 + [8838].file = "lib/mpi/mpi-bit.c",
84416 + [8838].name = "mpi_lshift_limbs",
84417 + [8838].param2 = 1,
84418 + [8851].file = "net/key/af_key.c",
84419 + [8851].name = "pfkey_sendmsg",
84420 + [8851].param4 = 1,
84421 + [8917].file = "net/can/raw.c",
84422 + [8917].name = "raw_setsockopt",
84423 + [8917].param5 = 1,
84424 + [8983].file = "include/linux/skbuff.h",
84425 + [8983].name = "alloc_skb",
84426 + [8983].param1 = 1,
84427 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
84428 + [9117].name = "regcache_rbtree_insert_to_block",
84429 + [9117].param5 = 1,
84430 + [9226].file = "mm/migrate.c",
84431 + [9226].name = "sys_move_pages",
84432 + [9226].param2 = 1,
84433 + [9304].file = "kernel/auditfilter.c",
84434 + [9304].name = "audit_init_entry",
84435 + [9304].param1 = 1,
84436 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
84437 + [9317].name = "wa_nep_queue",
84438 + [9317].param2 = 1,
84439 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84440 + [9341].name = "erst_dbg_write",
84441 + [9341].param3 = 1,
84442 + [9386].file = "fs/exofs/ore.c",
84443 + [9386].name = "_ore_get_io_state",
84444 + [9386].param3 = 1,
84445 + [9386].param4 = 1,
84446 + [9386].param5 = 1,
84447 + [9538].file = "crypto/blkcipher.c",
84448 + [9538].name = "blkcipher_copy_iv",
84449 + [9538].param3 = 1,
84450 + [9546].file = "drivers/video/fbmem.c",
84451 + [9546].name = "fb_write",
84452 + [9546].param3 = 1,
84453 + [9601].file = "kernel/kfifo.c",
84454 + [9601].name = "__kfifo_from_user",
84455 + [9601].param3 = 1,
84456 + [9618].file = "security/selinux/selinuxfs.c",
84457 + [9618].name = "sel_write_bool",
84458 + [9618].param3 = 1,
84459 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84460 + [9768].name = "vmw_execbuf_process",
84461 + [9768].param5 = 1,
84462 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84463 + [9828].name = "dvb_demux_do_ioctl",
84464 + [9828].param3 = 1,
84465 + [9870].file = "net/atm/addr.c",
84466 + [9870].name = "atm_get_addr",
84467 + [9870].param3 = 1,
84468 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84469 + [9977].name = "zd_usb_iowrite16v_async",
84470 + [9977].param3 = 1,
84471 + [16344].collision = 1,
84472 + [307].collision = 1,
84473 + [31649].collision = 1,
84474 + [33040].collision = 1,
84475 + [45231].collision = 1,
84476 + [60651].collision = 1,
84477 +};
84478 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84479 new file mode 100644
84480 index 0000000..9ec45ae
84481 --- /dev/null
84482 +++ b/tools/gcc/size_overflow_hash2.h
84483 @@ -0,0 +1,35 @@
84484 +struct size_overflow_hash size_overflow_hash2[65536] = {
84485 + [22224].file = "fs/proc/vmcore.c",
84486 + [22224].name = "read_from_oldmem",
84487 + [22224].param2 = 1,
84488 + [2344].file = "fs/ecryptfs/crypto.c",
84489 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
84490 + [2344].param5 = 1,
84491 + [2515].file = "fs/ecryptfs/crypto.c",
84492 + [2515].name = "ecryptfs_copy_filename",
84493 + [2515].param4 = 1,
84494 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84495 + [26518].name = "vga_arb_read",
84496 + [26518].param3 = 1,
84497 + [30632].file = "drivers/ide/ide-proc.c",
84498 + [30632].name = "ide_driver_proc_write",
84499 + [30632].param3 = 1,
84500 + [39024].file = "lib/scatterlist.c",
84501 + [39024].name = "sg_kmalloc",
84502 + [39024].param1 = 1,
84503 + [50359].file = "kernel/sched/core.c",
84504 + [50359].name = "alloc_sched_domains",
84505 + [50359].param1 = 1,
84506 + [53262].file = "drivers/block/aoe/aoechr.c",
84507 + [53262].name = "revalidate",
84508 + [53262].param2 = 1,
84509 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
84510 + [56432].name = "regmap_map_read_file",
84511 + [56432].param3 = 1,
84512 + [57500].file = "drivers/spi/spidev.c",
84513 + [57500].name = "spidev_write",
84514 + [57500].param3 = 1,
84515 + [8155].file = "drivers/hv/channel.c",
84516 + [8155].name = "vmbus_establish_gpadl",
84517 + [8155].param3 = 1,
84518 +};
84519 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84520 new file mode 100644
84521 index 0000000..255439f
84522 --- /dev/null
84523 +++ b/tools/gcc/size_overflow_plugin.c
84524 @@ -0,0 +1,1110 @@
84525 +/*
84526 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84527 + * Licensed under the GPL v2, or (at your option) v3
84528 + *
84529 + * Homepage:
84530 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84531 + *
84532 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84533 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84534 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
84535 + *
84536 + * Usage:
84537 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
84538 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84539 + */
84540 +
84541 +#include "gcc-plugin.h"
84542 +#include "config.h"
84543 +#include "system.h"
84544 +#include "coretypes.h"
84545 +#include "tree.h"
84546 +#include "tree-pass.h"
84547 +#include "intl.h"
84548 +#include "plugin-version.h"
84549 +#include "tm.h"
84550 +#include "toplev.h"
84551 +#include "function.h"
84552 +#include "tree-flow.h"
84553 +#include "plugin.h"
84554 +#include "gimple.h"
84555 +#include "c-common.h"
84556 +#include "diagnostic.h"
84557 +#include "cfgloop.h"
84558 +
84559 +struct size_overflow_hash {
84560 + const char *name;
84561 + const char *file;
84562 + unsigned short collision:1;
84563 + unsigned short param1:1;
84564 + unsigned short param2:1;
84565 + unsigned short param3:1;
84566 + unsigned short param4:1;
84567 + unsigned short param5:1;
84568 + unsigned short param6:1;
84569 + unsigned short param7:1;
84570 + unsigned short param8:1;
84571 + unsigned short param9:1;
84572 +};
84573 +
84574 +#include "size_overflow_hash1.h"
84575 +#include "size_overflow_hash2.h"
84576 +
84577 +#define __unused __attribute__((__unused__))
84578 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
84579 +#define BEFORE_STMT true
84580 +#define AFTER_STMT false
84581 +#define CREATE_NEW_VAR NULL_TREE
84582 +
84583 +int plugin_is_GPL_compatible;
84584 +void debug_gimple_stmt (gimple gs);
84585 +
84586 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
84587 +static tree signed_size_overflow_type;
84588 +static tree unsigned_size_overflow_type;
84589 +static tree report_size_overflow_decl;
84590 +static tree const_char_ptr_type_node;
84591 +static unsigned int handle_function(void);
84592 +
84593 +static struct plugin_info size_overflow_plugin_info = {
84594 + .version = "20120409beta",
84595 + .help = "no-size_overflow\tturn off size overflow checking\n",
84596 +};
84597 +
84598 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
84599 +{
84600 + unsigned int arg_count = type_num_arguments(*node);
84601 +
84602 + for (; args; args = TREE_CHAIN(args)) {
84603 + tree position = TREE_VALUE(args);
84604 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
84605 + error("handle_size_overflow_attribute: overflow parameter outside range.");
84606 + *no_add_attrs = true;
84607 + }
84608 + }
84609 + return NULL_TREE;
84610 +}
84611 +
84612 +static struct attribute_spec no_size_overflow_attr = {
84613 + .name = "size_overflow",
84614 + .min_length = 1,
84615 + .max_length = -1,
84616 + .decl_required = false,
84617 + .type_required = true,
84618 + .function_type_required = true,
84619 + .handler = handle_size_overflow_attribute
84620 +};
84621 +
84622 +static void register_attributes(void __unused *event_data, void __unused *data)
84623 +{
84624 + register_attribute(&no_size_overflow_attr);
84625 +}
84626 +
84627 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
84628 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
84629 +{
84630 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
84631 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
84632 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
84633 +
84634 + const unsigned int m = 0x57559429;
84635 + const unsigned int n = 0x5052acdb;
84636 + const unsigned int *key4 = (const unsigned int *)key;
84637 + unsigned int h = len;
84638 + unsigned int k = len + seed + n;
84639 + unsigned long long p;
84640 +
84641 + while (len >= 8) {
84642 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
84643 + len -= 8;
84644 + }
84645 + if (len >= 4) {
84646 + cwmixb(key4[0]) key4 += 1;
84647 + len -= 4;
84648 + }
84649 + if (len)
84650 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
84651 + cwmixb(h ^ (k + n));
84652 + return k ^ h;
84653 +
84654 +#undef cwfold
84655 +#undef cwmixa
84656 +#undef cwmixb
84657 +}
84658 +
84659 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
84660 +{
84661 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
84662 +}
84663 +
84664 +static inline tree get_original_function_decl(tree fndecl)
84665 +{
84666 + if (DECL_ABSTRACT_ORIGIN(fndecl))
84667 + return DECL_ABSTRACT_ORIGIN(fndecl);
84668 + return fndecl;
84669 +}
84670 +
84671 +static inline gimple get_def_stmt(tree node)
84672 +{
84673 + gcc_assert(TREE_CODE(node) == SSA_NAME);
84674 + return SSA_NAME_DEF_STMT(node);
84675 +}
84676 +
84677 +static struct size_overflow_hash *get_function_hash(tree fndecl)
84678 +{
84679 + unsigned int hash;
84680 + const char *func = NAME(fndecl);
84681 +
84682 + hash = size_overflow_hash(func, 0);
84683 +
84684 + if (size_overflow_hash1[hash].collision) {
84685 + hash = size_overflow_hash(func, 23432);
84686 + return &size_overflow_hash2[hash];
84687 + }
84688 + return &size_overflow_hash1[hash];
84689 +}
84690 +
84691 +static void check_arg_type(tree var)
84692 +{
84693 + tree type = TREE_TYPE(var);
84694 + enum tree_code code = TREE_CODE(type);
84695 +
84696 + gcc_assert(code == INTEGER_TYPE ||
84697 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
84698 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
84699 +}
84700 +
84701 +static void check_missing_attribute(tree arg)
84702 +{
84703 + tree var, type, func = get_original_function_decl(current_function_decl);
84704 + const char *curfunc = NAME(func);
84705 + unsigned int new_hash, argnum = 1;
84706 + struct size_overflow_hash *hash;
84707 + location_t loc;
84708 + expanded_location xloc;
84709 + bool match = false;
84710 +
84711 + type = TREE_TYPE(arg);
84712 + // skip function pointers
84713 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
84714 + return;
84715 +
84716 + loc = DECL_SOURCE_LOCATION(func);
84717 + xloc = expand_location(loc);
84718 +
84719 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
84720 + return;
84721 +
84722 + hash = get_function_hash(func);
84723 + if (hash->name && !strcmp(hash->name, NAME(func)) && !strcmp(hash->file, xloc.file))
84724 + return;
84725 +
84726 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
84727 +
84728 + if (TREE_CODE(arg) == SSA_NAME)
84729 + arg = SSA_NAME_VAR(arg);
84730 +
84731 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
84732 + if (strcmp(NAME(arg), NAME(var))) {
84733 + argnum++;
84734 + continue;
84735 + }
84736 + check_arg_type(var);
84737 +
84738 + match = true;
84739 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
84740 + return;
84741 + break;
84742 + }
84743 + if (!match) {
84744 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
84745 + return;
84746 + }
84747 +
84748 +#define check_param(num) \
84749 + if (num == argnum && hash->param##num) \
84750 + return;
84751 + check_param(1);
84752 + check_param(2);
84753 + check_param(3);
84754 + check_param(4);
84755 + check_param(5);
84756 + check_param(6);
84757 + check_param(7);
84758 + check_param(8);
84759 + check_param(9);
84760 +#undef check_param
84761 +
84762 + new_hash = size_overflow_hash(curfunc, 0);
84763 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
84764 +}
84765 +
84766 +static tree create_new_var(tree type)
84767 +{
84768 + tree new_var = create_tmp_var(type, "cicus");
84769 +
84770 + add_referenced_var(new_var);
84771 + mark_sym_for_renaming(new_var);
84772 + return new_var;
84773 +}
84774 +
84775 +static bool is_bool(tree node)
84776 +{
84777 + tree type;
84778 +
84779 + if (node == NULL_TREE)
84780 + return false;
84781 +
84782 + type = TREE_TYPE(node);
84783 + if (!INTEGRAL_TYPE_P(type))
84784 + return false;
84785 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84786 + return true;
84787 + if (TYPE_PRECISION(type) == 1)
84788 + return true;
84789 + return false;
84790 +}
84791 +
84792 +static tree cast_a_tree(tree type, tree var)
84793 +{
84794 + gcc_assert(fold_convertible_p(type, var));
84795 +
84796 + return fold_convert(type, var);
84797 +}
84798 +
84799 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84800 +{
84801 + gimple assign;
84802 +
84803 + if (new_var == CREATE_NEW_VAR)
84804 + new_var = create_new_var(type);
84805 +
84806 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
84807 + gimple_set_location(assign, loc);
84808 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84809 +
84810 + return assign;
84811 +}
84812 +
84813 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
84814 +{
84815 + tree oldstmt_rhs1;
84816 + enum tree_code code;
84817 + gimple stmt;
84818 + gimple_stmt_iterator gsi;
84819 +
84820 + if (!*potentionally_overflowed)
84821 + return NULL_TREE;
84822 +
84823 + if (rhs1 == NULL_TREE) {
84824 + debug_gimple_stmt(oldstmt);
84825 + error("create_assign: rhs1 is NULL_TREE");
84826 + gcc_unreachable();
84827 + }
84828 +
84829 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
84830 + code = TREE_CODE(oldstmt_rhs1);
84831 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
84832 + check_missing_attribute(oldstmt_rhs1);
84833 +
84834 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
84835 + gsi = gsi_for_stmt(oldstmt);
84836 + if (before)
84837 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
84838 + else
84839 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
84840 + update_stmt(stmt);
84841 + pointer_set_insert(visited, oldstmt);
84842 + return gimple_get_lhs(stmt);
84843 +}
84844 +
84845 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
84846 +{
84847 + tree new_var, lhs = gimple_get_lhs(oldstmt);
84848 + gimple stmt;
84849 + gimple_stmt_iterator gsi;
84850 +
84851 + if (!*potentionally_overflowed)
84852 + return NULL_TREE;
84853 +
84854 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
84855 + rhs1 = gimple_assign_rhs1(oldstmt);
84856 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
84857 + }
84858 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
84859 + rhs2 = gimple_assign_rhs2(oldstmt);
84860 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
84861 + }
84862 +
84863 + stmt = gimple_copy(oldstmt);
84864 + gimple_set_location(stmt, gimple_location(oldstmt));
84865 +
84866 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
84867 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
84868 +
84869 + if (is_bool(lhs))
84870 + new_var = SSA_NAME_VAR(lhs);
84871 + else
84872 + new_var = create_new_var(signed_size_overflow_type);
84873 + new_var = make_ssa_name(new_var, stmt);
84874 + gimple_set_lhs(stmt, new_var);
84875 +
84876 + if (rhs1 != NULL_TREE) {
84877 + if (!gimple_assign_cast_p(oldstmt))
84878 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
84879 + gimple_assign_set_rhs1(stmt, rhs1);
84880 + }
84881 +
84882 + if (rhs2 != NULL_TREE)
84883 + gimple_assign_set_rhs2(stmt, rhs2);
84884 +#if BUILDING_GCC_VERSION >= 4007
84885 + if (rhs3 != NULL_TREE)
84886 + gimple_assign_set_rhs3(stmt, rhs3);
84887 +#endif
84888 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
84889 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
84890 +
84891 + gsi = gsi_for_stmt(oldstmt);
84892 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
84893 + update_stmt(stmt);
84894 + pointer_set_insert(visited, oldstmt);
84895 + return gimple_get_lhs(stmt);
84896 +}
84897 +
84898 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
84899 +{
84900 + basic_block bb;
84901 + gimple phi;
84902 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
84903 +
84904 + bb = gsi_bb(gsi);
84905 +
84906 + phi = create_phi_node(var, bb);
84907 + gsi = gsi_last(phi_nodes(bb));
84908 + gsi_remove(&gsi, false);
84909 +
84910 + gsi = gsi_for_stmt(oldstmt);
84911 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
84912 + gimple_set_bb(phi, bb);
84913 + return phi;
84914 +}
84915 +
84916 +static tree signed_cast_constant(tree node)
84917 +{
84918 + gcc_assert(is_gimple_constant(node));
84919 +
84920 + return cast_a_tree(signed_size_overflow_type, node);
84921 +}
84922 +
84923 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
84924 +{
84925 + basic_block bb;
84926 + gimple newstmt, def_stmt;
84927 + gimple_stmt_iterator gsi;
84928 +
84929 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
84930 + if (TREE_CODE(arg) == SSA_NAME) {
84931 + def_stmt = get_def_stmt(arg);
84932 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
84933 + gsi = gsi_for_stmt(def_stmt);
84934 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
84935 + return newstmt;
84936 + }
84937 + }
84938 +
84939 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
84940 + gsi = gsi_after_labels(bb);
84941 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
84942 + return newstmt;
84943 +}
84944 +
84945 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
84946 +{
84947 + gimple newstmt;
84948 + gimple_stmt_iterator gsi;
84949 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
84950 + gimple def_newstmt = get_def_stmt(new_rhs);
84951 +
84952 + gsi_insert = gsi_insert_after;
84953 + gsi = gsi_for_stmt(def_newstmt);
84954 +
84955 + switch (gimple_code(get_def_stmt(arg))) {
84956 + case GIMPLE_PHI:
84957 + newstmt = gimple_build_assign(new_var, new_rhs);
84958 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
84959 + gsi_insert = gsi_insert_before;
84960 + break;
84961 + case GIMPLE_ASM:
84962 + case GIMPLE_CALL:
84963 + newstmt = gimple_build_assign(new_var, new_rhs);
84964 + break;
84965 + case GIMPLE_ASSIGN:
84966 + newstmt = gimple_copy(def_newstmt);
84967 + break;
84968 + default:
84969 + /* unknown gimple_code (handle_build_new_phi_arg) */
84970 + gcc_unreachable();
84971 + }
84972 +
84973 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
84974 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
84975 + return newstmt;
84976 +}
84977 +
84978 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
84979 +{
84980 + gimple newstmt;
84981 + tree new_rhs;
84982 +
84983 + new_rhs = expand(visited, potentionally_overflowed, arg);
84984 +
84985 + if (new_rhs == NULL_TREE)
84986 + return NULL_TREE;
84987 +
84988 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
84989 + update_stmt(newstmt);
84990 + return gimple_get_lhs(newstmt);
84991 +}
84992 +
84993 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
84994 +{
84995 + gimple phi;
84996 + tree new_var = create_new_var(signed_size_overflow_type);
84997 + unsigned int i, n = gimple_phi_num_args(oldstmt);
84998 +
84999 + pointer_set_insert(visited, oldstmt);
85000 + phi = overflow_create_phi_node(oldstmt, new_var);
85001 + for (i = 0; i < n; i++) {
85002 + tree arg, lhs;
85003 +
85004 + arg = gimple_phi_arg_def(oldstmt, i);
85005 + if (is_gimple_constant(arg))
85006 + arg = signed_cast_constant(arg);
85007 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85008 + if (lhs == NULL_TREE)
85009 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85010 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85011 + }
85012 +
85013 + update_stmt(phi);
85014 + return gimple_phi_result(phi);
85015 +}
85016 +
85017 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85018 +{
85019 + gimple def_stmt = get_def_stmt(var);
85020 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85021 +
85022 + *potentionally_overflowed = true;
85023 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85024 + if (new_rhs1 == NULL_TREE) {
85025 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85026 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85027 + else
85028 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85029 + }
85030 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85031 +}
85032 +
85033 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85034 +{
85035 + gimple def_stmt = get_def_stmt(var);
85036 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85037 +
85038 + if (is_gimple_constant(rhs1))
85039 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85040 +
85041 + switch (TREE_CODE(rhs1)) {
85042 + case SSA_NAME:
85043 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85044 +
85045 + case ARRAY_REF:
85046 + case ADDR_EXPR:
85047 + case COMPONENT_REF:
85048 + case COND_EXPR:
85049 + case INDIRECT_REF:
85050 +#if BUILDING_GCC_VERSION >= 4006
85051 + case MEM_REF:
85052 +#endif
85053 + case PARM_DECL:
85054 + case TARGET_MEM_REF:
85055 + case VAR_DECL:
85056 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85057 +
85058 + default:
85059 + debug_gimple_stmt(def_stmt);
85060 + debug_tree(rhs1);
85061 + gcc_unreachable();
85062 + }
85063 +}
85064 +
85065 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85066 +{
85067 + gimple cond_stmt;
85068 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85069 +
85070 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85071 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85072 + update_stmt(cond_stmt);
85073 +}
85074 +
85075 +static tree create_string_param(tree string)
85076 +{
85077 + tree array_ref = build4(ARRAY_REF, TREE_TYPE(string), string, integer_zero_node, NULL, NULL);
85078 +
85079 + return build1(ADDR_EXPR, ptr_type_node, array_ref);
85080 +}
85081 +
85082 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85083 +{
85084 + gimple func_stmt, def_stmt;
85085 + tree current_func, loc_file, loc_line;
85086 + expanded_location xloc;
85087 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85088 +
85089 + def_stmt = get_def_stmt(arg);
85090 + xloc = expand_location(gimple_location(def_stmt));
85091 +
85092 + if (!gimple_has_location(def_stmt)) {
85093 + xloc = expand_location(gimple_location(stmt));
85094 + if (!gimple_has_location(stmt))
85095 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85096 + }
85097 +
85098 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85099 +
85100 + loc_file = build_string(strlen(xloc.file), xloc.file);
85101 + TREE_TYPE(loc_file) = char_array_type_node;
85102 + loc_file = create_string_param(loc_file);
85103 +
85104 + current_func = build_string(IDENTIFIER_LENGTH(DECL_NAME(current_function_decl)), NAME(current_function_decl));
85105 + TREE_TYPE(current_func) = char_array_type_node;
85106 + current_func = create_string_param(current_func);
85107 +
85108 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85109 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85110 +
85111 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85112 +}
85113 +
85114 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85115 +{
85116 + basic_block cond_bb, join_bb, bb_true;
85117 + edge e;
85118 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85119 +// location_t loc = gimple_location(stmt);
85120 +
85121 + cond_bb = gimple_bb(stmt);
85122 + gsi_prev(&gsi);
85123 + if (gsi_end_p(gsi))
85124 + e = split_block_after_labels(cond_bb);
85125 + else
85126 + e = split_block(cond_bb, gsi_stmt(gsi));
85127 + cond_bb = e->src;
85128 + join_bb = e->dest;
85129 + e->flags = EDGE_FALSE_VALUE;
85130 + e->probability = REG_BR_PROB_BASE;
85131 +
85132 + bb_true = create_empty_bb(cond_bb);
85133 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85134 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85135 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85136 +
85137 + if (dom_info_available_p(CDI_DOMINATORS)) {
85138 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85139 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85140 + }
85141 +
85142 + if (current_loops != NULL) {
85143 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85144 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85145 + }
85146 +
85147 + insert_cond(cond_bb, arg, cond_code, type_value);
85148 + insert_cond_result(bb_true, stmt, arg);
85149 +
85150 +// inform(loc, "Integer size_overflow check applied here.");
85151 +}
85152 +
85153 +static tree get_type_for_check(tree rhs)
85154 +{
85155 + tree def_rhs;
85156 + gimple def_stmt = get_def_stmt(rhs);
85157 +
85158 + if (!gimple_assign_cast_p(def_stmt))
85159 + return TREE_TYPE(rhs);
85160 + def_rhs = gimple_assign_rhs1(def_stmt);
85161 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
85162 + return TREE_TYPE(def_rhs);
85163 + return TREE_TYPE(rhs);
85164 +}
85165 +
85166 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85167 +{
85168 + gimple ucast_stmt;
85169 + gimple_stmt_iterator gsi;
85170 + location_t loc = gimple_location(stmt);
85171 +
85172 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85173 + gsi = gsi_for_stmt(stmt);
85174 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85175 + return ucast_stmt;
85176 +}
85177 +
85178 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85179 +{
85180 + tree type_max, type_min, rhs_type;
85181 + gimple ucast_stmt;
85182 +
85183 + if (!*potentionally_overflowed)
85184 + return;
85185 +
85186 + rhs_type = get_type_for_check(rhs);
85187 +
85188 + if (TYPE_UNSIGNED(rhs_type)) {
85189 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85190 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85191 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85192 + } else {
85193 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85194 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85195 +
85196 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
85197 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85198 + }
85199 +}
85200 +
85201 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
85202 +{
85203 + gimple assign;
85204 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85205 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
85206 +
85207 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85208 +
85209 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
85210 + if (new_rhs == NULL_TREE)
85211 + return NULL_TREE;
85212 +
85213 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85214 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85215 + update_stmt(assign);
85216 + return gimple_get_lhs(assign);
85217 +}
85218 +
85219 +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))
85220 +{
85221 + tree new_rhs, cast_rhs;
85222 +
85223 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85224 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85225 +
85226 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
85227 + if (new_rhs != NULL_TREE) {
85228 + gimple_assign_set_rhs(def_stmt, new_rhs);
85229 + update_stmt(def_stmt);
85230 +
85231 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
85232 +
85233 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
85234 + }
85235 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85236 +}
85237 +
85238 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85239 +{
85240 + tree rhs1, rhs2;
85241 + gimple def_stmt = get_def_stmt(var);
85242 + tree new_rhs1 = NULL_TREE;
85243 + tree new_rhs2 = NULL_TREE;
85244 +
85245 + rhs1 = gimple_assign_rhs1(def_stmt);
85246 + rhs2 = gimple_assign_rhs2(def_stmt);
85247 +
85248 + /* no DImode/TImode division in the 32/64 bit kernel */
85249 + switch (gimple_assign_rhs_code(def_stmt)) {
85250 + case RDIV_EXPR:
85251 + case TRUNC_DIV_EXPR:
85252 + case CEIL_DIV_EXPR:
85253 + case FLOOR_DIV_EXPR:
85254 + case ROUND_DIV_EXPR:
85255 + case TRUNC_MOD_EXPR:
85256 + case CEIL_MOD_EXPR:
85257 + case FLOOR_MOD_EXPR:
85258 + case ROUND_MOD_EXPR:
85259 + case EXACT_DIV_EXPR:
85260 + case POINTER_PLUS_EXPR:
85261 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85262 + default:
85263 + break;
85264 + }
85265 +
85266 + *potentionally_overflowed = true;
85267 +
85268 + if (TREE_CODE(rhs1) == SSA_NAME)
85269 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85270 + if (TREE_CODE(rhs2) == SSA_NAME)
85271 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85272 +
85273 + if (is_gimple_constant(rhs2))
85274 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
85275 +
85276 + if (is_gimple_constant(rhs1))
85277 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85278 +
85279 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85280 +}
85281 +
85282 +#if BUILDING_GCC_VERSION >= 4007
85283 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85284 +{
85285 + if (is_gimple_constant(rhs))
85286 + return signed_cast_constant(rhs);
85287 + if (TREE_CODE(rhs) != SSA_NAME)
85288 + return NULL_TREE;
85289 + return expand(visited, potentionally_overflowed, rhs);
85290 +}
85291 +
85292 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85293 +{
85294 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85295 + gimple def_stmt = get_def_stmt(var);
85296 +
85297 + *potentionally_overflowed = true;
85298 +
85299 + rhs1 = gimple_assign_rhs1(def_stmt);
85300 + rhs2 = gimple_assign_rhs2(def_stmt);
85301 + rhs3 = gimple_assign_rhs3(def_stmt);
85302 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85303 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85304 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85305 +
85306 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85307 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85308 + error("handle_ternary_ops: unknown rhs");
85309 + gcc_unreachable();
85310 +}
85311 +#endif
85312 +
85313 +static void set_size_overflow_type(tree node)
85314 +{
85315 + switch (TYPE_MODE(TREE_TYPE(node))) {
85316 + case SImode:
85317 + signed_size_overflow_type = intDI_type_node;
85318 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85319 + break;
85320 + case DImode:
85321 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85322 + signed_size_overflow_type = intDI_type_node;
85323 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85324 + } else {
85325 + signed_size_overflow_type = intTI_type_node;
85326 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85327 + }
85328 + break;
85329 + default:
85330 + error("set_size_overflow_type: unsupported gcc configuration.");
85331 + gcc_unreachable();
85332 + }
85333 +}
85334 +
85335 +static tree expand_visited(gimple def_stmt)
85336 +{
85337 + gimple tmp;
85338 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85339 +
85340 + gsi_next(&gsi);
85341 + tmp = gsi_stmt(gsi);
85342 + switch (gimple_code(tmp)) {
85343 + case GIMPLE_ASSIGN:
85344 + return gimple_get_lhs(tmp);
85345 + case GIMPLE_PHI:
85346 + return gimple_phi_result(tmp);
85347 + case GIMPLE_CALL:
85348 + return gimple_call_lhs(tmp);
85349 + default:
85350 + return NULL_TREE;
85351 + }
85352 +}
85353 +
85354 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85355 +{
85356 + gimple def_stmt;
85357 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85358 +
85359 + if (is_gimple_constant(var))
85360 + return NULL_TREE;
85361 +
85362 + if (TREE_CODE(var) == ADDR_EXPR)
85363 + return NULL_TREE;
85364 +
85365 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
85366 + if (code != INTEGER_TYPE)
85367 + return NULL_TREE;
85368 +
85369 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85370 + check_missing_attribute(var);
85371 + return NULL_TREE;
85372 + }
85373 +
85374 + def_stmt = get_def_stmt(var);
85375 +
85376 + if (!def_stmt)
85377 + return NULL_TREE;
85378 +
85379 + if (pointer_set_contains(visited, def_stmt))
85380 + return expand_visited(def_stmt);
85381 +
85382 + switch (gimple_code(def_stmt)) {
85383 + case GIMPLE_NOP:
85384 + check_missing_attribute(var);
85385 + return NULL_TREE;
85386 + case GIMPLE_PHI:
85387 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85388 + case GIMPLE_CALL:
85389 + case GIMPLE_ASM:
85390 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85391 + case GIMPLE_ASSIGN:
85392 + switch (gimple_num_ops(def_stmt)) {
85393 + case 2:
85394 + return handle_unary_ops(visited, potentionally_overflowed, var);
85395 + case 3:
85396 + return handle_binary_ops(visited, potentionally_overflowed, var);
85397 +#if BUILDING_GCC_VERSION >= 4007
85398 + case 4:
85399 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85400 +#endif
85401 + }
85402 + default:
85403 + debug_gimple_stmt(def_stmt);
85404 + error("expand: unknown gimple code");
85405 + gcc_unreachable();
85406 + }
85407 +}
85408 +
85409 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85410 +{
85411 + gimple assign;
85412 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85413 + tree origtype = TREE_TYPE(origarg);
85414 +
85415 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85416 +
85417 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85418 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85419 + update_stmt(assign);
85420 +
85421 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85422 + update_stmt(stmt);
85423 +}
85424 +
85425 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85426 +{
85427 + const char *origid;
85428 + tree arg, origarg;
85429 +
85430 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85431 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85432 + return gimple_call_arg(stmt, argnum);
85433 + }
85434 +
85435 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85436 + while (origarg && argnum) {
85437 + argnum--;
85438 + origarg = TREE_CHAIN(origarg);
85439 + }
85440 +
85441 + gcc_assert(argnum == 0);
85442 +
85443 + gcc_assert(origarg != NULL_TREE);
85444 + origid = NAME(origarg);
85445 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85446 + if (!strcmp(origid, NAME(arg)))
85447 + return arg;
85448 + }
85449 + return NULL_TREE;
85450 +}
85451 +
85452 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85453 +{
85454 + struct pointer_set_t *visited;
85455 + tree arg, newarg, type_max;
85456 + gimple ucast_stmt;
85457 + bool potentionally_overflowed;
85458 +
85459 + arg = get_function_arg(argnum, stmt, fndecl);
85460 + if (arg == NULL_TREE)
85461 + return;
85462 +
85463 + if (is_gimple_constant(arg))
85464 + return;
85465 + if (TREE_CODE(arg) != SSA_NAME)
85466 + return;
85467 +
85468 + check_arg_type(arg);
85469 +
85470 + set_size_overflow_type(arg);
85471 +
85472 + visited = pointer_set_create();
85473 + potentionally_overflowed = false;
85474 + newarg = expand(visited, &potentionally_overflowed, arg);
85475 + pointer_set_destroy(visited);
85476 +
85477 + if (newarg == NULL_TREE || !potentionally_overflowed)
85478 + return;
85479 +
85480 + change_function_arg(stmt, arg, argnum, newarg);
85481 +
85482 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
85483 +
85484 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
85485 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85486 +}
85487 +
85488 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85489 +{
85490 + tree p = TREE_VALUE(attr);
85491 + do {
85492 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85493 + p = TREE_CHAIN(p);
85494 + } while (p);
85495 +}
85496 +
85497 +static void handle_function_by_hash(gimple stmt, tree fndecl)
85498 +{
85499 + struct size_overflow_hash *hash;
85500 + expanded_location xloc;
85501 +
85502 + hash = get_function_hash(fndecl);
85503 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
85504 +
85505 + fndecl = get_original_function_decl(fndecl);
85506 + if (!hash->name || !hash->file)
85507 + return;
85508 + if (strcmp(hash->name, NAME(fndecl)) || strcmp(hash->file, xloc.file))
85509 + return;
85510 +
85511 +#define search_param(argnum) \
85512 + if (hash->param##argnum) \
85513 + handle_function_arg(stmt, fndecl, argnum - 1);
85514 +
85515 + search_param(1);
85516 + search_param(2);
85517 + search_param(3);
85518 + search_param(4);
85519 + search_param(5);
85520 + search_param(6);
85521 + search_param(7);
85522 + search_param(8);
85523 + search_param(9);
85524 +#undef search_param
85525 +}
85526 +
85527 +static unsigned int handle_function(void)
85528 +{
85529 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
85530 + int saved_last_basic_block = last_basic_block;
85531 +
85532 + do {
85533 + gimple_stmt_iterator gsi;
85534 + basic_block next = bb->next_bb;
85535 +
85536 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85537 + tree fndecl, attr;
85538 + gimple stmt = gsi_stmt(gsi);
85539 +
85540 + if (!(is_gimple_call(stmt)))
85541 + continue;
85542 + fndecl = gimple_call_fndecl(stmt);
85543 + if (fndecl == NULL_TREE)
85544 + continue;
85545 + if (gimple_call_num_args(stmt) == 0)
85546 + continue;
85547 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
85548 + if (!attr || !TREE_VALUE(attr))
85549 + handle_function_by_hash(stmt, fndecl);
85550 + else
85551 + handle_function_by_attribute(stmt, attr, fndecl);
85552 + gsi = gsi_for_stmt(stmt);
85553 + }
85554 + bb = next;
85555 + } while (bb && bb->index <= saved_last_basic_block);
85556 + return 0;
85557 +}
85558 +
85559 +static struct gimple_opt_pass size_overflow_pass = {
85560 + .pass = {
85561 + .type = GIMPLE_PASS,
85562 + .name = "size_overflow",
85563 + .gate = NULL,
85564 + .execute = handle_function,
85565 + .sub = NULL,
85566 + .next = NULL,
85567 + .static_pass_number = 0,
85568 + .tv_id = TV_NONE,
85569 + .properties_required = PROP_cfg | PROP_referenced_vars,
85570 + .properties_provided = 0,
85571 + .properties_destroyed = 0,
85572 + .todo_flags_start = 0,
85573 + .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
85574 + }
85575 +};
85576 +
85577 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
85578 +{
85579 + tree fntype;
85580 +
85581 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
85582 +
85583 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
85584 + fntype = build_function_type_list(void_type_node,
85585 + const_char_ptr_type_node,
85586 + unsigned_type_node,
85587 + const_char_ptr_type_node,
85588 + NULL_TREE);
85589 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
85590 +
85591 + TREE_PUBLIC(report_size_overflow_decl) = 1;
85592 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
85593 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
85594 +}
85595 +
85596 +extern struct gimple_opt_pass pass_dce;
85597 +
85598 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85599 +{
85600 + int i;
85601 + const char * const plugin_name = plugin_info->base_name;
85602 + const int argc = plugin_info->argc;
85603 + const struct plugin_argument * const argv = plugin_info->argv;
85604 + bool enable = true;
85605 +
85606 + struct register_pass_info size_overflow_pass_info = {
85607 + .pass = &size_overflow_pass.pass,
85608 + .reference_pass_name = "ssa",
85609 + .ref_pass_instance_number = 1,
85610 + .pos_op = PASS_POS_INSERT_AFTER
85611 + };
85612 +
85613 + if (!plugin_default_version_check(version, &gcc_version)) {
85614 + error(G_("incompatible gcc/plugin versions"));
85615 + return 1;
85616 + }
85617 +
85618 + for (i = 0; i < argc; ++i) {
85619 + if (!(strcmp(argv[i].key, "no-size_overflow"))) {
85620 + enable = false;
85621 + continue;
85622 + }
85623 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85624 + }
85625 +
85626 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
85627 + if (enable) {
85628 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85629 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
85630 + }
85631 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85632 +
85633 + return 0;
85634 +}
85635 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
85636 new file mode 100644
85637 index 0000000..b87ec9d
85638 --- /dev/null
85639 +++ b/tools/gcc/stackleak_plugin.c
85640 @@ -0,0 +1,313 @@
85641 +/*
85642 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85643 + * Licensed under the GPL v2
85644 + *
85645 + * Note: the choice of the license means that the compilation process is
85646 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85647 + * but for the kernel it doesn't matter since it doesn't link against
85648 + * any of the gcc libraries
85649 + *
85650 + * gcc plugin to help implement various PaX features
85651 + *
85652 + * - track lowest stack pointer
85653 + *
85654 + * TODO:
85655 + * - initialize all local variables
85656 + *
85657 + * BUGS:
85658 + * - none known
85659 + */
85660 +#include "gcc-plugin.h"
85661 +#include "config.h"
85662 +#include "system.h"
85663 +#include "coretypes.h"
85664 +#include "tree.h"
85665 +#include "tree-pass.h"
85666 +#include "flags.h"
85667 +#include "intl.h"
85668 +#include "toplev.h"
85669 +#include "plugin.h"
85670 +//#include "expr.h" where are you...
85671 +#include "diagnostic.h"
85672 +#include "plugin-version.h"
85673 +#include "tm.h"
85674 +#include "function.h"
85675 +#include "basic-block.h"
85676 +#include "gimple.h"
85677 +#include "rtl.h"
85678 +#include "emit-rtl.h"
85679 +
85680 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85681 +
85682 +int plugin_is_GPL_compatible;
85683 +
85684 +static int track_frame_size = -1;
85685 +static const char track_function[] = "pax_track_stack";
85686 +static const char check_function[] = "pax_check_alloca";
85687 +static bool init_locals;
85688 +
85689 +static struct plugin_info stackleak_plugin_info = {
85690 + .version = "201203140940",
85691 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
85692 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
85693 +};
85694 +
85695 +static bool gate_stackleak_track_stack(void);
85696 +static unsigned int execute_stackleak_tree_instrument(void);
85697 +static unsigned int execute_stackleak_final(void);
85698 +
85699 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
85700 + .pass = {
85701 + .type = GIMPLE_PASS,
85702 + .name = "stackleak_tree_instrument",
85703 + .gate = gate_stackleak_track_stack,
85704 + .execute = execute_stackleak_tree_instrument,
85705 + .sub = NULL,
85706 + .next = NULL,
85707 + .static_pass_number = 0,
85708 + .tv_id = TV_NONE,
85709 + .properties_required = PROP_gimple_leh | PROP_cfg,
85710 + .properties_provided = 0,
85711 + .properties_destroyed = 0,
85712 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85713 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85714 + }
85715 +};
85716 +
85717 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
85718 + .pass = {
85719 + .type = RTL_PASS,
85720 + .name = "stackleak_final",
85721 + .gate = gate_stackleak_track_stack,
85722 + .execute = execute_stackleak_final,
85723 + .sub = NULL,
85724 + .next = NULL,
85725 + .static_pass_number = 0,
85726 + .tv_id = TV_NONE,
85727 + .properties_required = 0,
85728 + .properties_provided = 0,
85729 + .properties_destroyed = 0,
85730 + .todo_flags_start = 0,
85731 + .todo_flags_finish = TODO_dump_func
85732 + }
85733 +};
85734 +
85735 +static bool gate_stackleak_track_stack(void)
85736 +{
85737 + return track_frame_size >= 0;
85738 +}
85739 +
85740 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
85741 +{
85742 + gimple check_alloca;
85743 + tree fntype, fndecl, alloca_size;
85744 +
85745 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
85746 + fndecl = build_fn_decl(check_function, fntype);
85747 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85748 +
85749 + // insert call to void pax_check_alloca(unsigned long size)
85750 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
85751 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
85752 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
85753 +}
85754 +
85755 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
85756 +{
85757 + gimple track_stack;
85758 + tree fntype, fndecl;
85759 +
85760 + fntype = build_function_type_list(void_type_node, NULL_TREE);
85761 + fndecl = build_fn_decl(track_function, fntype);
85762 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85763 +
85764 + // insert call to void pax_track_stack(void)
85765 + track_stack = gimple_build_call(fndecl, 0);
85766 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
85767 +}
85768 +
85769 +#if BUILDING_GCC_VERSION == 4005
85770 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
85771 +{
85772 + tree fndecl;
85773 +
85774 + if (!is_gimple_call(stmt))
85775 + return false;
85776 + fndecl = gimple_call_fndecl(stmt);
85777 + if (!fndecl)
85778 + return false;
85779 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85780 + return false;
85781 +// print_node(stderr, "pax", fndecl, 4);
85782 + return DECL_FUNCTION_CODE(fndecl) == code;
85783 +}
85784 +#endif
85785 +
85786 +static bool is_alloca(gimple stmt)
85787 +{
85788 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85789 + return true;
85790 +
85791 +#if BUILDING_GCC_VERSION >= 4007
85792 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85793 + return true;
85794 +#endif
85795 +
85796 + return false;
85797 +}
85798 +
85799 +static unsigned int execute_stackleak_tree_instrument(void)
85800 +{
85801 + basic_block bb, entry_bb;
85802 + bool prologue_instrumented = false, is_leaf = true;
85803 +
85804 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85805 +
85806 + // 1. loop through BBs and GIMPLE statements
85807 + FOR_EACH_BB(bb) {
85808 + gimple_stmt_iterator gsi;
85809 +
85810 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85811 + gimple stmt;
85812 +
85813 + stmt = gsi_stmt(gsi);
85814 +
85815 + if (is_gimple_call(stmt))
85816 + is_leaf = false;
85817 +
85818 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85819 + if (!is_alloca(stmt))
85820 + continue;
85821 +
85822 + // 2. insert stack overflow check before each __builtin_alloca call
85823 + stackleak_check_alloca(&gsi);
85824 +
85825 + // 3. insert track call after each __builtin_alloca call
85826 + stackleak_add_instrumentation(&gsi);
85827 + if (bb == entry_bb)
85828 + prologue_instrumented = true;
85829 + }
85830 + }
85831 +
85832 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85833 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85834 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85835 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85836 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85837 + return 0;
85838 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85839 + return 0;
85840 +
85841 + // 4. insert track call at the beginning
85842 + if (!prologue_instrumented) {
85843 + gimple_stmt_iterator gsi;
85844 +
85845 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85846 + if (dom_info_available_p(CDI_DOMINATORS))
85847 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85848 + gsi = gsi_start_bb(bb);
85849 + stackleak_add_instrumentation(&gsi);
85850 + }
85851 +
85852 + return 0;
85853 +}
85854 +
85855 +static unsigned int execute_stackleak_final(void)
85856 +{
85857 + rtx insn;
85858 +
85859 + if (cfun->calls_alloca)
85860 + return 0;
85861 +
85862 + // keep calls only if function frame is big enough
85863 + if (get_frame_size() >= track_frame_size)
85864 + return 0;
85865 +
85866 + // 1. find pax_track_stack calls
85867 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85868 + // 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))
85869 + rtx body;
85870 +
85871 + if (!CALL_P(insn))
85872 + continue;
85873 + body = PATTERN(insn);
85874 + if (GET_CODE(body) != CALL)
85875 + continue;
85876 + body = XEXP(body, 0);
85877 + if (GET_CODE(body) != MEM)
85878 + continue;
85879 + body = XEXP(body, 0);
85880 + if (GET_CODE(body) != SYMBOL_REF)
85881 + continue;
85882 + if (strcmp(XSTR(body, 0), track_function))
85883 + continue;
85884 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85885 + // 2. delete call
85886 + insn = delete_insn_and_edges(insn);
85887 +#if BUILDING_GCC_VERSION >= 4007
85888 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
85889 + insn = delete_insn_and_edges(insn);
85890 +#endif
85891 + }
85892 +
85893 +// print_simple_rtl(stderr, get_insns());
85894 +// print_rtl(stderr, get_insns());
85895 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85896 +
85897 + return 0;
85898 +}
85899 +
85900 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85901 +{
85902 + const char * const plugin_name = plugin_info->base_name;
85903 + const int argc = plugin_info->argc;
85904 + const struct plugin_argument * const argv = plugin_info->argv;
85905 + int i;
85906 + struct register_pass_info stackleak_tree_instrument_pass_info = {
85907 + .pass = &stackleak_tree_instrument_pass.pass,
85908 +// .reference_pass_name = "tree_profile",
85909 + .reference_pass_name = "optimized",
85910 + .ref_pass_instance_number = 0,
85911 + .pos_op = PASS_POS_INSERT_BEFORE
85912 + };
85913 + struct register_pass_info stackleak_final_pass_info = {
85914 + .pass = &stackleak_final_rtl_opt_pass.pass,
85915 + .reference_pass_name = "final",
85916 + .ref_pass_instance_number = 0,
85917 + .pos_op = PASS_POS_INSERT_BEFORE
85918 + };
85919 +
85920 + if (!plugin_default_version_check(version, &gcc_version)) {
85921 + error(G_("incompatible gcc/plugin versions"));
85922 + return 1;
85923 + }
85924 +
85925 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
85926 +
85927 + for (i = 0; i < argc; ++i) {
85928 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85929 + if (!argv[i].value) {
85930 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85931 + continue;
85932 + }
85933 + track_frame_size = atoi(argv[i].value);
85934 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85935 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85936 + continue;
85937 + }
85938 + if (!strcmp(argv[i].key, "initialize-locals")) {
85939 + if (argv[i].value) {
85940 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85941 + continue;
85942 + }
85943 + init_locals = true;
85944 + continue;
85945 + }
85946 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85947 + }
85948 +
85949 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
85950 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
85951 +
85952 + return 0;
85953 +}
85954 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
85955 index 6789d78..4afd019 100644
85956 --- a/tools/perf/util/include/asm/alternative-asm.h
85957 +++ b/tools/perf/util/include/asm/alternative-asm.h
85958 @@ -5,4 +5,7 @@
85959
85960 #define altinstruction_entry #
85961
85962 + .macro pax_force_retaddr rip=0, reload=0
85963 + .endm
85964 +
85965 #endif
85966 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
85967 index af0f22f..9a7d479 100644
85968 --- a/usr/gen_init_cpio.c
85969 +++ b/usr/gen_init_cpio.c
85970 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
85971 int retval;
85972 int rc = -1;
85973 int namesize;
85974 - int i;
85975 + unsigned int i;
85976
85977 mode |= S_IFREG;
85978
85979 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
85980 *env_var = *expanded = '\0';
85981 strncat(env_var, start + 2, end - start - 2);
85982 strncat(expanded, new_location, start - new_location);
85983 - strncat(expanded, getenv(env_var), PATH_MAX);
85984 - strncat(expanded, end + 1, PATH_MAX);
85985 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
85986 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
85987 strncpy(new_location, expanded, PATH_MAX);
85988 + new_location[PATH_MAX] = 0;
85989 } else
85990 break;
85991 }
85992 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
85993 index a91f980..a58d32c 100644
85994 --- a/virt/kvm/kvm_main.c
85995 +++ b/virt/kvm/kvm_main.c
85996 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
85997
85998 static cpumask_var_t cpus_hardware_enabled;
85999 static int kvm_usage_count = 0;
86000 -static atomic_t hardware_enable_failed;
86001 +static atomic_unchecked_t hardware_enable_failed;
86002
86003 struct kmem_cache *kvm_vcpu_cache;
86004 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86005 @@ -2312,7 +2312,7 @@ static void hardware_enable_nolock(void *junk)
86006
86007 if (r) {
86008 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86009 - atomic_inc(&hardware_enable_failed);
86010 + atomic_inc_unchecked(&hardware_enable_failed);
86011 printk(KERN_INFO "kvm: enabling virtualization on "
86012 "CPU%d failed\n", cpu);
86013 }
86014 @@ -2366,10 +2366,10 @@ static int hardware_enable_all(void)
86015
86016 kvm_usage_count++;
86017 if (kvm_usage_count == 1) {
86018 - atomic_set(&hardware_enable_failed, 0);
86019 + atomic_set_unchecked(&hardware_enable_failed, 0);
86020 on_each_cpu(hardware_enable_nolock, NULL, 1);
86021
86022 - if (atomic_read(&hardware_enable_failed)) {
86023 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86024 hardware_disable_all_nolock();
86025 r = -EBUSY;
86026 }
86027 @@ -2732,7 +2732,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86028 kvm_arch_vcpu_put(vcpu);
86029 }
86030
86031 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86032 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86033 struct module *module)
86034 {
86035 int r;
86036 @@ -2795,7 +2795,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86037 if (!vcpu_align)
86038 vcpu_align = __alignof__(struct kvm_vcpu);
86039 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86040 - 0, NULL);
86041 + SLAB_USERCOPY, NULL);
86042 if (!kvm_vcpu_cache) {
86043 r = -ENOMEM;
86044 goto out_free_3;
86045 @@ -2805,9 +2805,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86046 if (r)
86047 goto out_free;
86048
86049 - kvm_chardev_ops.owner = module;
86050 - kvm_vm_fops.owner = module;
86051 - kvm_vcpu_fops.owner = module;
86052 + pax_open_kernel();
86053 + *(void **)&kvm_chardev_ops.owner = module;
86054 + *(void **)&kvm_vm_fops.owner = module;
86055 + *(void **)&kvm_vcpu_fops.owner = module;
86056 + pax_close_kernel();
86057
86058 r = misc_register(&kvm_dev);
86059 if (r) {