]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.2-201204192144.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.2-201204192144.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 0c083c5..bf13011 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,9 +51,11 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 @@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41 +PERF*
42 SCCS
43 System.map*
44 TAGS
45 @@ -92,19 +98,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49 +builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55 +clut_vga16.c
56 +common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63 +config.c
64 config.mak
65 config.mak.autogen
66 +config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70 @@ -115,9 +126,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74 +dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78 +exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82 @@ -125,12 +138,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86 +gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93 +hash
94 +hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98 @@ -145,7 +161,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102 -kconfig
103 +kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107 @@ -153,7 +169,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111 -linux
112 +lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116 @@ -165,14 +181,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120 -media
121 mconf
122 +mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129 +mkpiggy
130 mkprep
131 mkregtable
132 mktables
133 @@ -208,6 +225,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137 +regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141 @@ -218,6 +236,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145 +slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149 @@ -228,6 +247,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153 +user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157 @@ -245,7 +265,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161 +vmlinux.bin.bz2
162 vmlinux.lds
163 +vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167 @@ -253,9 +275,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171 +utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177 +zconf.lex.c
178 zoffset.h
179 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180 index d99fd9c..8689fef 100644
181 --- a/Documentation/kernel-parameters.txt
182 +++ b/Documentation/kernel-parameters.txt
183 @@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188 + virtualization environments that don't cope well with the
189 + expand down segment used by UDEREF on X86-32 or the frequent
190 + page table updates on X86-64.
191 +
192 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193 +
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197 diff --git a/Makefile b/Makefile
198 index ddcb70a..32da20d 100644
199 --- a/Makefile
200 +++ b/Makefile
201 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206 -HOSTCXXFLAGS = -O2
207 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
214 # Rules shared between *config targets and build targets
215
216 # Basic helpers built in scripts/
217 -PHONY += scripts_basic
218 -scripts_basic:
219 +PHONY += scripts_basic gcc-plugins
220 +scripts_basic: gcc-plugins
221 $(Q)$(MAKE) $(build)=scripts/basic
222 $(Q)rm -f .tmp_quiet_recordmcount
223
224 @@ -564,6 +565,53 @@ else
225 KBUILD_CFLAGS += -O2
226 endif
227
228 +ifndef DISABLE_PAX_PLUGINS
229 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
230 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
231 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
232 +endif
233 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
234 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
235 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
236 +endif
237 +ifdef CONFIG_KALLOCSTAT_PLUGIN
238 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
239 +endif
240 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
241 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
242 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
243 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
244 +endif
245 +ifdef CONFIG_CHECKER_PLUGIN
246 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
247 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
248 +endif
249 +endif
250 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
251 +ifdef CONFIG_PAX_SIZE_OVERFLOW
252 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
253 +endif
254 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
255 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
256 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
257 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
258 +ifeq ($(KBUILD_EXTMOD),)
259 +gcc-plugins:
260 + $(Q)$(MAKE) $(build)=tools/gcc
261 +else
262 +gcc-plugins: ;
263 +endif
264 +else
265 +gcc-plugins:
266 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
267 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
268 +else
269 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
270 +endif
271 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
272 +endif
273 +endif
274 +
275 include $(srctree)/arch/$(SRCARCH)/Makefile
276
277 ifneq ($(CONFIG_FRAME_WARN),0)
278 @@ -708,7 +756,7 @@ export mod_strip_cmd
279
280
281 ifeq ($(KBUILD_EXTMOD),)
282 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
283 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
284
285 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
286 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
287 @@ -932,6 +980,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
288
289 # The actual objects are generated when descending,
290 # make sure no implicit rule kicks in
291 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
292 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
293 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
294
295 # Handle descending into subdirectories listed in $(vmlinux-dirs)
296 @@ -941,7 +991,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
297 # Error messages still appears in the original language
298
299 PHONY += $(vmlinux-dirs)
300 -$(vmlinux-dirs): prepare scripts
301 +$(vmlinux-dirs): gcc-plugins prepare scripts
302 $(Q)$(MAKE) $(build)=$@
303
304 # Store (new) KERNELRELASE string in include/config/kernel.release
305 @@ -985,6 +1035,7 @@ prepare0: archprepare FORCE
306 $(Q)$(MAKE) $(build)=.
307
308 # All the preparing..
309 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
310 prepare: prepare0
311
312 # Generate some files
313 @@ -1089,6 +1140,8 @@ all: modules
314 # using awk while concatenating to the final file.
315
316 PHONY += modules
317 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
318 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
319 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
320 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
321 @$(kecho) ' Building modules, stage 2.';
322 @@ -1104,7 +1157,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
323
324 # Target to prepare building external modules
325 PHONY += modules_prepare
326 -modules_prepare: prepare scripts
327 +modules_prepare: gcc-plugins prepare scripts
328
329 # Target to install modules
330 PHONY += modules_install
331 @@ -1201,6 +1254,7 @@ distclean: mrproper
332 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
333 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
334 -o -name '.*.rej' \
335 + -o -name '.*.rej' -o -name '*.so' \
336 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
337 -type f -print | xargs rm -f
338
339 @@ -1361,6 +1415,8 @@ PHONY += $(module-dirs) modules
340 $(module-dirs): crmodverdir $(objtree)/Module.symvers
341 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
342
343 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
344 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
345 modules: $(module-dirs)
346 @$(kecho) ' Building modules, stage 2.';
347 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
348 @@ -1487,17 +1543,21 @@ else
349 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
350 endif
351
352 -%.s: %.c prepare scripts FORCE
353 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355 +%.s: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.i: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 -%.o: %.c prepare scripts FORCE
360 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
361 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
362 +%.o: %.c gcc-plugins prepare scripts FORCE
363 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
364 %.lst: %.c prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 -%.s: %.S prepare scripts FORCE
367 +%.s: %.S gcc-plugins prepare scripts FORCE
368 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
369 -%.o: %.S prepare scripts FORCE
370 +%.o: %.S gcc-plugins prepare scripts FORCE
371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
372 %.symtypes: %.c prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 @@ -1507,11 +1567,15 @@ endif
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378 -%/: prepare scripts FORCE
379 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381 +%/: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir)
385 -%.ko: prepare scripts FORCE
386 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
387 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
388 +%.ko: gcc-plugins prepare scripts FORCE
389 $(cmd_crmodverdir)
390 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
391 $(build)=$(build-dir) $(@:.ko=.o)
392 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
393 index 640f909..48b6597 100644
394 --- a/arch/alpha/include/asm/atomic.h
395 +++ b/arch/alpha/include/asm/atomic.h
396 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
397 #define atomic_dec(v) atomic_sub(1,(v))
398 #define atomic64_dec(v) atomic64_sub(1,(v))
399
400 +#define atomic64_read_unchecked(v) atomic64_read(v)
401 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
402 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
403 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
404 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
405 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
406 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
407 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
408 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
409 +
410 #define smp_mb__before_atomic_dec() smp_mb()
411 #define smp_mb__after_atomic_dec() smp_mb()
412 #define smp_mb__before_atomic_inc() smp_mb()
413 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
414 index ad368a9..fbe0f25 100644
415 --- a/arch/alpha/include/asm/cache.h
416 +++ b/arch/alpha/include/asm/cache.h
417 @@ -4,19 +4,19 @@
418 #ifndef __ARCH_ALPHA_CACHE_H
419 #define __ARCH_ALPHA_CACHE_H
420
421 +#include <linux/const.h>
422
423 /* Bytes per L1 (data) cache line. */
424 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
425 -# define L1_CACHE_BYTES 64
426 # define L1_CACHE_SHIFT 6
427 #else
428 /* Both EV4 and EV5 are write-through, read-allocate,
429 direct-mapped, physical.
430 */
431 -# define L1_CACHE_BYTES 32
432 # define L1_CACHE_SHIFT 5
433 #endif
434
435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
436 #define SMP_CACHE_BYTES L1_CACHE_BYTES
437
438 #endif
439 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
440 index da5449e..7418343 100644
441 --- a/arch/alpha/include/asm/elf.h
442 +++ b/arch/alpha/include/asm/elf.h
443 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
444
445 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
446
447 +#ifdef CONFIG_PAX_ASLR
448 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
449 +
450 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
451 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
452 +#endif
453 +
454 /* $0 is set by ld.so to a pointer to a function which might be
455 registered using atexit. This provides a mean for the dynamic
456 linker to call DT_FINI functions for shared libraries that have
457 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
458 index de98a73..bd4f1f8 100644
459 --- a/arch/alpha/include/asm/pgtable.h
460 +++ b/arch/alpha/include/asm/pgtable.h
461 @@ -101,6 +101,17 @@ struct vm_area_struct;
462 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
463 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
464 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
465 +
466 +#ifdef CONFIG_PAX_PAGEEXEC
467 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
468 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
469 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
470 +#else
471 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
472 +# define PAGE_COPY_NOEXEC PAGE_COPY
473 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
474 +#endif
475 +
476 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
477
478 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
479 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
480 index 2fd00b7..cfd5069 100644
481 --- a/arch/alpha/kernel/module.c
482 +++ b/arch/alpha/kernel/module.c
483 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
484
485 /* The small sections were sorted to the end of the segment.
486 The following should definitely cover them. */
487 - gp = (u64)me->module_core + me->core_size - 0x8000;
488 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
489 got = sechdrs[me->arch.gotsecindex].sh_addr;
490
491 for (i = 0; i < n; i++) {
492 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
493 index 01e8715..be0e80f 100644
494 --- a/arch/alpha/kernel/osf_sys.c
495 +++ b/arch/alpha/kernel/osf_sys.c
496 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
497 /* At this point: (!vma || addr < vma->vm_end). */
498 if (limit - len < addr)
499 return -ENOMEM;
500 - if (!vma || addr + len <= vma->vm_start)
501 + if (check_heap_stack_gap(vma, addr, len))
502 return addr;
503 addr = vma->vm_end;
504 vma = vma->vm_next;
505 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
506 merely specific addresses, but regions of memory -- perhaps
507 this feature should be incorporated into all ports? */
508
509 +#ifdef CONFIG_PAX_RANDMMAP
510 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
511 +#endif
512 +
513 if (addr) {
514 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
515 if (addr != (unsigned long) -ENOMEM)
516 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
517 }
518
519 /* Next, try allocating at TASK_UNMAPPED_BASE. */
520 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
521 - len, limit);
522 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
523 +
524 if (addr != (unsigned long) -ENOMEM)
525 return addr;
526
527 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
528 index fadd5f8..904e73a 100644
529 --- a/arch/alpha/mm/fault.c
530 +++ b/arch/alpha/mm/fault.c
531 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
532 __reload_thread(pcb);
533 }
534
535 +#ifdef CONFIG_PAX_PAGEEXEC
536 +/*
537 + * PaX: decide what to do with offenders (regs->pc = fault address)
538 + *
539 + * returns 1 when task should be killed
540 + * 2 when patched PLT trampoline was detected
541 + * 3 when unpatched PLT trampoline was detected
542 + */
543 +static int pax_handle_fetch_fault(struct pt_regs *regs)
544 +{
545 +
546 +#ifdef CONFIG_PAX_EMUPLT
547 + int err;
548 +
549 + do { /* PaX: patched PLT emulation #1 */
550 + unsigned int ldah, ldq, jmp;
551 +
552 + err = get_user(ldah, (unsigned int *)regs->pc);
553 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
554 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
555 +
556 + if (err)
557 + break;
558 +
559 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
560 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
561 + jmp == 0x6BFB0000U)
562 + {
563 + unsigned long r27, addr;
564 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
565 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
566 +
567 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
568 + err = get_user(r27, (unsigned long *)addr);
569 + if (err)
570 + break;
571 +
572 + regs->r27 = r27;
573 + regs->pc = r27;
574 + return 2;
575 + }
576 + } while (0);
577 +
578 + do { /* PaX: patched PLT emulation #2 */
579 + unsigned int ldah, lda, br;
580 +
581 + err = get_user(ldah, (unsigned int *)regs->pc);
582 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
583 + err |= get_user(br, (unsigned int *)(regs->pc+8));
584 +
585 + if (err)
586 + break;
587 +
588 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
589 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
590 + (br & 0xFFE00000U) == 0xC3E00000U)
591 + {
592 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
593 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
594 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
595 +
596 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
597 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
598 + return 2;
599 + }
600 + } while (0);
601 +
602 + do { /* PaX: unpatched PLT emulation */
603 + unsigned int br;
604 +
605 + err = get_user(br, (unsigned int *)regs->pc);
606 +
607 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
608 + unsigned int br2, ldq, nop, jmp;
609 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
610 +
611 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
612 + err = get_user(br2, (unsigned int *)addr);
613 + err |= get_user(ldq, (unsigned int *)(addr+4));
614 + err |= get_user(nop, (unsigned int *)(addr+8));
615 + err |= get_user(jmp, (unsigned int *)(addr+12));
616 + err |= get_user(resolver, (unsigned long *)(addr+16));
617 +
618 + if (err)
619 + break;
620 +
621 + if (br2 == 0xC3600000U &&
622 + ldq == 0xA77B000CU &&
623 + nop == 0x47FF041FU &&
624 + jmp == 0x6B7B0000U)
625 + {
626 + regs->r28 = regs->pc+4;
627 + regs->r27 = addr+16;
628 + regs->pc = resolver;
629 + return 3;
630 + }
631 + }
632 + } while (0);
633 +#endif
634 +
635 + return 1;
636 +}
637 +
638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
639 +{
640 + unsigned long i;
641 +
642 + printk(KERN_ERR "PAX: bytes at PC: ");
643 + for (i = 0; i < 5; i++) {
644 + unsigned int c;
645 + if (get_user(c, (unsigned int *)pc+i))
646 + printk(KERN_CONT "???????? ");
647 + else
648 + printk(KERN_CONT "%08x ", c);
649 + }
650 + printk("\n");
651 +}
652 +#endif
653
654 /*
655 * This routine handles page faults. It determines the address,
656 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
657 good_area:
658 si_code = SEGV_ACCERR;
659 if (cause < 0) {
660 - if (!(vma->vm_flags & VM_EXEC))
661 + if (!(vma->vm_flags & VM_EXEC)) {
662 +
663 +#ifdef CONFIG_PAX_PAGEEXEC
664 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
665 + goto bad_area;
666 +
667 + up_read(&mm->mmap_sem);
668 + switch (pax_handle_fetch_fault(regs)) {
669 +
670 +#ifdef CONFIG_PAX_EMUPLT
671 + case 2:
672 + case 3:
673 + return;
674 +#endif
675 +
676 + }
677 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
678 + do_group_exit(SIGKILL);
679 +#else
680 goto bad_area;
681 +#endif
682 +
683 + }
684 } else if (!cause) {
685 /* Allow reads even for write-only mappings */
686 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
687 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
688 index 86976d0..8e07f84 100644
689 --- a/arch/arm/include/asm/atomic.h
690 +++ b/arch/arm/include/asm/atomic.h
691 @@ -15,6 +15,10 @@
692 #include <linux/types.h>
693 #include <asm/system.h>
694
695 +#ifdef CONFIG_GENERIC_ATOMIC64
696 +#include <asm-generic/atomic64.h>
697 +#endif
698 +
699 #define ATOMIC_INIT(i) { (i) }
700
701 #ifdef __KERNEL__
702 @@ -25,7 +29,15 @@
703 * atomic_set() is the clrex or dummy strex done on every exception return.
704 */
705 #define atomic_read(v) (*(volatile int *)&(v)->counter)
706 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
707 +{
708 + return v->counter;
709 +}
710 #define atomic_set(v,i) (((v)->counter) = (i))
711 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
712 +{
713 + v->counter = i;
714 +}
715
716 #if __LINUX_ARM_ARCH__ >= 6
717
718 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
719 int result;
720
721 __asm__ __volatile__("@ atomic_add\n"
722 +"1: ldrex %1, [%3]\n"
723 +" adds %0, %1, %4\n"
724 +
725 +#ifdef CONFIG_PAX_REFCOUNT
726 +" bvc 3f\n"
727 +"2: bkpt 0xf103\n"
728 +"3:\n"
729 +#endif
730 +
731 +" strex %1, %0, [%3]\n"
732 +" teq %1, #0\n"
733 +" bne 1b"
734 +
735 +#ifdef CONFIG_PAX_REFCOUNT
736 +"\n4:\n"
737 + _ASM_EXTABLE(2b, 4b)
738 +#endif
739 +
740 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
741 + : "r" (&v->counter), "Ir" (i)
742 + : "cc");
743 +}
744 +
745 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
746 +{
747 + unsigned long tmp;
748 + int result;
749 +
750 + __asm__ __volatile__("@ atomic_add_unchecked\n"
751 "1: ldrex %0, [%3]\n"
752 " add %0, %0, %4\n"
753 " strex %1, %0, [%3]\n"
754 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
755 smp_mb();
756
757 __asm__ __volatile__("@ atomic_add_return\n"
758 +"1: ldrex %1, [%3]\n"
759 +" adds %0, %1, %4\n"
760 +
761 +#ifdef CONFIG_PAX_REFCOUNT
762 +" bvc 3f\n"
763 +" mov %0, %1\n"
764 +"2: bkpt 0xf103\n"
765 +"3:\n"
766 +#endif
767 +
768 +" strex %1, %0, [%3]\n"
769 +" teq %1, #0\n"
770 +" bne 1b"
771 +
772 +#ifdef CONFIG_PAX_REFCOUNT
773 +"\n4:\n"
774 + _ASM_EXTABLE(2b, 4b)
775 +#endif
776 +
777 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
778 + : "r" (&v->counter), "Ir" (i)
779 + : "cc");
780 +
781 + smp_mb();
782 +
783 + return result;
784 +}
785 +
786 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
787 +{
788 + unsigned long tmp;
789 + int result;
790 +
791 + smp_mb();
792 +
793 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
794 "1: ldrex %0, [%3]\n"
795 " add %0, %0, %4\n"
796 " strex %1, %0, [%3]\n"
797 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
798 int result;
799
800 __asm__ __volatile__("@ atomic_sub\n"
801 +"1: ldrex %1, [%3]\n"
802 +" subs %0, %1, %4\n"
803 +
804 +#ifdef CONFIG_PAX_REFCOUNT
805 +" bvc 3f\n"
806 +"2: bkpt 0xf103\n"
807 +"3:\n"
808 +#endif
809 +
810 +" strex %1, %0, [%3]\n"
811 +" teq %1, #0\n"
812 +" bne 1b"
813 +
814 +#ifdef CONFIG_PAX_REFCOUNT
815 +"\n4:\n"
816 + _ASM_EXTABLE(2b, 4b)
817 +#endif
818 +
819 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
820 + : "r" (&v->counter), "Ir" (i)
821 + : "cc");
822 +}
823 +
824 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
825 +{
826 + unsigned long tmp;
827 + int result;
828 +
829 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
830 "1: ldrex %0, [%3]\n"
831 " sub %0, %0, %4\n"
832 " strex %1, %0, [%3]\n"
833 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
834 smp_mb();
835
836 __asm__ __volatile__("@ atomic_sub_return\n"
837 -"1: ldrex %0, [%3]\n"
838 -" sub %0, %0, %4\n"
839 +"1: ldrex %1, [%3]\n"
840 +" sub %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +" mov %0, %1\n"
845 +"2: bkpt 0xf103\n"
846 +"3:\n"
847 +#endif
848 +
849 " strex %1, %0, [%3]\n"
850 " teq %1, #0\n"
851 " bne 1b"
852 +
853 +#ifdef CONFIG_PAX_REFCOUNT
854 +"\n4:\n"
855 + _ASM_EXTABLE(2b, 4b)
856 +#endif
857 +
858 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
859 : "r" (&v->counter), "Ir" (i)
860 : "cc");
861 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
862 return oldval;
863 }
864
865 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
866 +{
867 + unsigned long oldval, res;
868 +
869 + smp_mb();
870 +
871 + do {
872 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
873 + "ldrex %1, [%3]\n"
874 + "mov %0, #0\n"
875 + "teq %1, %4\n"
876 + "strexeq %0, %5, [%3]\n"
877 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
878 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
879 + : "cc");
880 + } while (res);
881 +
882 + smp_mb();
883 +
884 + return oldval;
885 +}
886 +
887 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
888 {
889 unsigned long tmp, tmp2;
890 @@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
891
892 return val;
893 }
894 +#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
895 #define atomic_add(i, v) (void) atomic_add_return(i, v)
896 +#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
897
898 static inline int atomic_sub_return(int i, atomic_t *v)
899 {
900 @@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
901
902 return val;
903 }
904 +#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
905 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
906 +#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
907
908 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
909 {
910 @@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
911
912 return ret;
913 }
914 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
915
916 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
917 {
918 @@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
919 #endif /* __LINUX_ARM_ARCH__ */
920
921 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
922 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
923 +{
924 + return xchg(&v->counter, new);
925 +}
926
927 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
928 {
929 @@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
930 }
931
932 #define atomic_inc(v) atomic_add(1, v)
933 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
934 +{
935 + atomic_add_unchecked(1, v);
936 +}
937 #define atomic_dec(v) atomic_sub(1, v)
938 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
939 +{
940 + atomic_sub_unchecked(1, v);
941 +}
942
943 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
944 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
945 +{
946 + return atomic_add_return_unchecked(1, v) == 0;
947 +}
948 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
949 #define atomic_inc_return(v) (atomic_add_return(1, v))
950 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
951 +{
952 + return atomic_add_return_unchecked(1, v);
953 +}
954 #define atomic_dec_return(v) (atomic_sub_return(1, v))
955 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
956
957 @@ -239,6 +406,14 @@ typedef struct {
958 u64 __aligned(8) counter;
959 } atomic64_t;
960
961 +#ifdef CONFIG_PAX_REFCOUNT
962 +typedef struct {
963 + u64 __aligned(8) counter;
964 +} atomic64_unchecked_t;
965 +#else
966 +typedef atomic64_t atomic64_unchecked_t;
967 +#endif
968 +
969 #define ATOMIC64_INIT(i) { (i) }
970
971 static inline u64 atomic64_read(atomic64_t *v)
972 @@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
973 return result;
974 }
975
976 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
977 +{
978 + u64 result;
979 +
980 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
981 +" ldrexd %0, %H0, [%1]"
982 + : "=&r" (result)
983 + : "r" (&v->counter), "Qo" (v->counter)
984 + );
985 +
986 + return result;
987 +}
988 +
989 static inline void atomic64_set(atomic64_t *v, u64 i)
990 {
991 u64 tmp;
992 @@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
993 : "cc");
994 }
995
996 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
997 +{
998 + u64 tmp;
999 +
1000 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1001 +"1: ldrexd %0, %H0, [%2]\n"
1002 +" strexd %0, %3, %H3, [%2]\n"
1003 +" teq %0, #0\n"
1004 +" bne 1b"
1005 + : "=&r" (tmp), "=Qo" (v->counter)
1006 + : "r" (&v->counter), "r" (i)
1007 + : "cc");
1008 +}
1009 +
1010 static inline void atomic64_add(u64 i, atomic64_t *v)
1011 {
1012 u64 result;
1013 @@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1014 __asm__ __volatile__("@ atomic64_add\n"
1015 "1: ldrexd %0, %H0, [%3]\n"
1016 " adds %0, %0, %4\n"
1017 +" adcs %H0, %H0, %H4\n"
1018 +
1019 +#ifdef CONFIG_PAX_REFCOUNT
1020 +" bvc 3f\n"
1021 +"2: bkpt 0xf103\n"
1022 +"3:\n"
1023 +#endif
1024 +
1025 +" strexd %1, %0, %H0, [%3]\n"
1026 +" teq %1, #0\n"
1027 +" bne 1b"
1028 +
1029 +#ifdef CONFIG_PAX_REFCOUNT
1030 +"\n4:\n"
1031 + _ASM_EXTABLE(2b, 4b)
1032 +#endif
1033 +
1034 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1035 + : "r" (&v->counter), "r" (i)
1036 + : "cc");
1037 +}
1038 +
1039 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1040 +{
1041 + u64 result;
1042 + unsigned long tmp;
1043 +
1044 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1045 +"1: ldrexd %0, %H0, [%3]\n"
1046 +" adds %0, %0, %4\n"
1047 " adc %H0, %H0, %H4\n"
1048 " strexd %1, %0, %H0, [%3]\n"
1049 " teq %1, #0\n"
1050 @@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1051
1052 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1053 {
1054 - u64 result;
1055 - unsigned long tmp;
1056 + u64 result, tmp;
1057
1058 smp_mb();
1059
1060 __asm__ __volatile__("@ atomic64_add_return\n"
1061 +"1: ldrexd %1, %H1, [%3]\n"
1062 +" adds %0, %1, %4\n"
1063 +" adcs %H0, %H1, %H4\n"
1064 +
1065 +#ifdef CONFIG_PAX_REFCOUNT
1066 +" bvc 3f\n"
1067 +" mov %0, %1\n"
1068 +" mov %H0, %H1\n"
1069 +"2: bkpt 0xf103\n"
1070 +"3:\n"
1071 +#endif
1072 +
1073 +" strexd %1, %0, %H0, [%3]\n"
1074 +" teq %1, #0\n"
1075 +" bne 1b"
1076 +
1077 +#ifdef CONFIG_PAX_REFCOUNT
1078 +"\n4:\n"
1079 + _ASM_EXTABLE(2b, 4b)
1080 +#endif
1081 +
1082 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1083 + : "r" (&v->counter), "r" (i)
1084 + : "cc");
1085 +
1086 + smp_mb();
1087 +
1088 + return result;
1089 +}
1090 +
1091 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1092 +{
1093 + u64 result;
1094 + unsigned long tmp;
1095 +
1096 + smp_mb();
1097 +
1098 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1099 "1: ldrexd %0, %H0, [%3]\n"
1100 " adds %0, %0, %4\n"
1101 " adc %H0, %H0, %H4\n"
1102 @@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1103 __asm__ __volatile__("@ atomic64_sub\n"
1104 "1: ldrexd %0, %H0, [%3]\n"
1105 " subs %0, %0, %4\n"
1106 +" sbcs %H0, %H0, %H4\n"
1107 +
1108 +#ifdef CONFIG_PAX_REFCOUNT
1109 +" bvc 3f\n"
1110 +"2: bkpt 0xf103\n"
1111 +"3:\n"
1112 +#endif
1113 +
1114 +" strexd %1, %0, %H0, [%3]\n"
1115 +" teq %1, #0\n"
1116 +" bne 1b"
1117 +
1118 +#ifdef CONFIG_PAX_REFCOUNT
1119 +"\n4:\n"
1120 + _ASM_EXTABLE(2b, 4b)
1121 +#endif
1122 +
1123 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1124 + : "r" (&v->counter), "r" (i)
1125 + : "cc");
1126 +}
1127 +
1128 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1129 +{
1130 + u64 result;
1131 + unsigned long tmp;
1132 +
1133 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1134 +"1: ldrexd %0, %H0, [%3]\n"
1135 +" subs %0, %0, %4\n"
1136 " sbc %H0, %H0, %H4\n"
1137 " strexd %1, %0, %H0, [%3]\n"
1138 " teq %1, #0\n"
1139 @@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1140
1141 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1142 {
1143 - u64 result;
1144 - unsigned long tmp;
1145 + u64 result, tmp;
1146
1147 smp_mb();
1148
1149 __asm__ __volatile__("@ atomic64_sub_return\n"
1150 -"1: ldrexd %0, %H0, [%3]\n"
1151 -" subs %0, %0, %4\n"
1152 -" sbc %H0, %H0, %H4\n"
1153 +"1: ldrexd %1, %H1, [%3]\n"
1154 +" subs %0, %1, %4\n"
1155 +" sbc %H0, %H1, %H4\n"
1156 +
1157 +#ifdef CONFIG_PAX_REFCOUNT
1158 +" bvc 3f\n"
1159 +" mov %0, %1\n"
1160 +" mov %H0, %H1\n"
1161 +"2: bkpt 0xf103\n"
1162 +"3:\n"
1163 +#endif
1164 +
1165 " strexd %1, %0, %H0, [%3]\n"
1166 " teq %1, #0\n"
1167 " bne 1b"
1168 +
1169 +#ifdef CONFIG_PAX_REFCOUNT
1170 +"\n4:\n"
1171 + _ASM_EXTABLE(2b, 4b)
1172 +#endif
1173 +
1174 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1175 : "r" (&v->counter), "r" (i)
1176 : "cc");
1177 @@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1178 return oldval;
1179 }
1180
1181 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1182 +{
1183 + u64 oldval;
1184 + unsigned long res;
1185 +
1186 + smp_mb();
1187 +
1188 + do {
1189 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1190 + "ldrexd %1, %H1, [%3]\n"
1191 + "mov %0, #0\n"
1192 + "teq %1, %4\n"
1193 + "teqeq %H1, %H4\n"
1194 + "strexdeq %0, %5, %H5, [%3]"
1195 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1196 + : "r" (&ptr->counter), "r" (old), "r" (new)
1197 + : "cc");
1198 + } while (res);
1199 +
1200 + smp_mb();
1201 +
1202 + return oldval;
1203 +}
1204 +
1205 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1206 {
1207 u64 result;
1208 @@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1209
1210 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1211 {
1212 - u64 result;
1213 - unsigned long tmp;
1214 + u64 result, tmp;
1215
1216 smp_mb();
1217
1218 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1219 -"1: ldrexd %0, %H0, [%3]\n"
1220 -" subs %0, %0, #1\n"
1221 -" sbc %H0, %H0, #0\n"
1222 +"1: ldrexd %1, %H1, [%3]\n"
1223 +" subs %0, %1, #1\n"
1224 +" sbc %H0, %H1, #0\n"
1225 +
1226 +#ifdef CONFIG_PAX_REFCOUNT
1227 +" bvc 3f\n"
1228 +" mov %0, %1\n"
1229 +" mov %H0, %H1\n"
1230 +"2: bkpt 0xf103\n"
1231 +"3:\n"
1232 +#endif
1233 +
1234 " teq %H0, #0\n"
1235 -" bmi 2f\n"
1236 +" bmi 4f\n"
1237 " strexd %1, %0, %H0, [%3]\n"
1238 " teq %1, #0\n"
1239 " bne 1b\n"
1240 -"2:"
1241 +"4:\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 + _ASM_EXTABLE(2b, 4b)
1245 +#endif
1246 +
1247 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1248 : "r" (&v->counter)
1249 : "cc");
1250 @@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1251 " teq %0, %5\n"
1252 " teqeq %H0, %H5\n"
1253 " moveq %1, #0\n"
1254 -" beq 2f\n"
1255 +" beq 4f\n"
1256 " adds %0, %0, %6\n"
1257 " adc %H0, %H0, %H6\n"
1258 +
1259 +#ifdef CONFIG_PAX_REFCOUNT
1260 +" bvc 3f\n"
1261 +"2: bkpt 0xf103\n"
1262 +"3:\n"
1263 +#endif
1264 +
1265 " strexd %2, %0, %H0, [%4]\n"
1266 " teq %2, #0\n"
1267 " bne 1b\n"
1268 -"2:"
1269 +"4:\n"
1270 +
1271 +#ifdef CONFIG_PAX_REFCOUNT
1272 + _ASM_EXTABLE(2b, 4b)
1273 +#endif
1274 +
1275 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1276 : "r" (&v->counter), "r" (u), "r" (a)
1277 : "cc");
1278 @@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1279
1280 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1281 #define atomic64_inc(v) atomic64_add(1LL, (v))
1282 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1283 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1284 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1285 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1286 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1287 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1288 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1289 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1290 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1291 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1292 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1293 index 75fe66b..2255c86 100644
1294 --- a/arch/arm/include/asm/cache.h
1295 +++ b/arch/arm/include/asm/cache.h
1296 @@ -4,8 +4,10 @@
1297 #ifndef __ASMARM_CACHE_H
1298 #define __ASMARM_CACHE_H
1299
1300 +#include <linux/const.h>
1301 +
1302 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1303 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1304 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1305
1306 /*
1307 * Memory returned by kmalloc() may be used for DMA, so we must make
1308 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1309 index d5d8d5c..ad92c96 100644
1310 --- a/arch/arm/include/asm/cacheflush.h
1311 +++ b/arch/arm/include/asm/cacheflush.h
1312 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1313 void (*dma_unmap_area)(const void *, size_t, int);
1314
1315 void (*dma_flush_range)(const void *, const void *);
1316 -};
1317 +} __no_const;
1318
1319 /*
1320 * Select the calling method
1321 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1322 index 0e9ce8d..6ef1e03 100644
1323 --- a/arch/arm/include/asm/elf.h
1324 +++ b/arch/arm/include/asm/elf.h
1325 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1326 the loader. We need to make sure that it is out of the way of the program
1327 that it will "exec", and that there is sufficient room for the brk. */
1328
1329 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1330 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1331 +
1332 +#ifdef CONFIG_PAX_ASLR
1333 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1334 +
1335 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1336 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1337 +#endif
1338
1339 /* When the program starts, a1 contains a pointer to a function to be
1340 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1341 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1342 extern void elf_set_personality(const struct elf32_hdr *);
1343 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1344
1345 -struct mm_struct;
1346 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1347 -#define arch_randomize_brk arch_randomize_brk
1348 -
1349 extern int vectors_user_mapping(void);
1350 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1351 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1352 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1353 index e51b1e8..32a3113 100644
1354 --- a/arch/arm/include/asm/kmap_types.h
1355 +++ b/arch/arm/include/asm/kmap_types.h
1356 @@ -21,6 +21,7 @@ enum km_type {
1357 KM_L1_CACHE,
1358 KM_L2_CACHE,
1359 KM_KDB,
1360 + KM_CLEARPAGE,
1361 KM_TYPE_NR
1362 };
1363
1364 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1365 index 53426c6..c7baff3 100644
1366 --- a/arch/arm/include/asm/outercache.h
1367 +++ b/arch/arm/include/asm/outercache.h
1368 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1369 #endif
1370 void (*set_debug)(unsigned long);
1371 void (*resume)(void);
1372 -};
1373 +} __no_const;
1374
1375 #ifdef CONFIG_OUTER_CACHE
1376
1377 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1378 index 97b440c..b7ff179 100644
1379 --- a/arch/arm/include/asm/page.h
1380 +++ b/arch/arm/include/asm/page.h
1381 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1382 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1383 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1384 unsigned long vaddr, struct vm_area_struct *vma);
1385 -};
1386 +} __no_const;
1387
1388 #ifdef MULTI_USER
1389 extern struct cpu_user_fns cpu_user;
1390 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1391 index e4c96cc..1145653 100644
1392 --- a/arch/arm/include/asm/system.h
1393 +++ b/arch/arm/include/asm/system.h
1394 @@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1395
1396 #define xchg(ptr,x) \
1397 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1398 +#define xchg_unchecked(ptr,x) \
1399 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1400
1401 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1402
1403 @@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1404
1405 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1406
1407 +#define _ASM_EXTABLE(from, to) \
1408 +" .pushsection __ex_table,\"a\"\n"\
1409 +" .align 3\n" \
1410 +" .long " #from ", " #to"\n" \
1411 +" .popsection"
1412 +
1413 +
1414 #endif /* __ASSEMBLY__ */
1415
1416 #define arch_align_stack(x) (x)
1417 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1418 index 2958976..12ccac4 100644
1419 --- a/arch/arm/include/asm/uaccess.h
1420 +++ b/arch/arm/include/asm/uaccess.h
1421 @@ -22,6 +22,8 @@
1422 #define VERIFY_READ 0
1423 #define VERIFY_WRITE 1
1424
1425 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1426 +
1427 /*
1428 * The exception table consists of pairs of addresses: the first is the
1429 * address of an instruction that is allowed to fault, and the second is
1430 @@ -387,8 +389,23 @@ do { \
1431
1432
1433 #ifdef CONFIG_MMU
1434 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1435 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1436 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1437 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1438 +
1439 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1440 +{
1441 + if (!__builtin_constant_p(n))
1442 + check_object_size(to, n, false);
1443 + return ___copy_from_user(to, from, n);
1444 +}
1445 +
1446 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1447 +{
1448 + if (!__builtin_constant_p(n))
1449 + check_object_size(from, n, true);
1450 + return ___copy_to_user(to, from, n);
1451 +}
1452 +
1453 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1454 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1455 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1456 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1457
1458 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1459 {
1460 + if ((long)n < 0)
1461 + return n;
1462 +
1463 if (access_ok(VERIFY_READ, from, n))
1464 n = __copy_from_user(to, from, n);
1465 else /* security hole - plug it */
1466 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1467
1468 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1469 {
1470 + if ((long)n < 0)
1471 + return n;
1472 +
1473 if (access_ok(VERIFY_WRITE, to, n))
1474 n = __copy_to_user(to, from, n);
1475 return n;
1476 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1477 index 5b0bce6..becd81c 100644
1478 --- a/arch/arm/kernel/armksyms.c
1479 +++ b/arch/arm/kernel/armksyms.c
1480 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1481 #ifdef CONFIG_MMU
1482 EXPORT_SYMBOL(copy_page);
1483
1484 -EXPORT_SYMBOL(__copy_from_user);
1485 -EXPORT_SYMBOL(__copy_to_user);
1486 +EXPORT_SYMBOL(___copy_from_user);
1487 +EXPORT_SYMBOL(___copy_to_user);
1488 EXPORT_SYMBOL(__clear_user);
1489
1490 EXPORT_SYMBOL(__get_user_1);
1491 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1492 index 971d65c..cc936fb 100644
1493 --- a/arch/arm/kernel/process.c
1494 +++ b/arch/arm/kernel/process.c
1495 @@ -28,7 +28,6 @@
1496 #include <linux/tick.h>
1497 #include <linux/utsname.h>
1498 #include <linux/uaccess.h>
1499 -#include <linux/random.h>
1500 #include <linux/hw_breakpoint.h>
1501 #include <linux/cpuidle.h>
1502
1503 @@ -273,9 +272,10 @@ void machine_power_off(void)
1504 machine_shutdown();
1505 if (pm_power_off)
1506 pm_power_off();
1507 + BUG();
1508 }
1509
1510 -void machine_restart(char *cmd)
1511 +__noreturn void machine_restart(char *cmd)
1512 {
1513 machine_shutdown();
1514
1515 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1516 return 0;
1517 }
1518
1519 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1520 -{
1521 - unsigned long range_end = mm->brk + 0x02000000;
1522 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1523 -}
1524 -
1525 #ifdef CONFIG_MMU
1526 /*
1527 * The vectors page is always readable from user space for the
1528 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1529 index a255c39..4a19b25 100644
1530 --- a/arch/arm/kernel/setup.c
1531 +++ b/arch/arm/kernel/setup.c
1532 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1533 struct cpu_tlb_fns cpu_tlb __read_mostly;
1534 #endif
1535 #ifdef MULTI_USER
1536 -struct cpu_user_fns cpu_user __read_mostly;
1537 +struct cpu_user_fns cpu_user __read_only;
1538 #endif
1539 #ifdef MULTI_CACHE
1540 -struct cpu_cache_fns cpu_cache __read_mostly;
1541 +struct cpu_cache_fns cpu_cache __read_only;
1542 #endif
1543 #ifdef CONFIG_OUTER_CACHE
1544 -struct outer_cache_fns outer_cache __read_mostly;
1545 +struct outer_cache_fns outer_cache __read_only;
1546 EXPORT_SYMBOL(outer_cache);
1547 #endif
1548
1549 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1550 index f84dfe6..13e94f7 100644
1551 --- a/arch/arm/kernel/traps.c
1552 +++ b/arch/arm/kernel/traps.c
1553 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1554
1555 static DEFINE_RAW_SPINLOCK(die_lock);
1556
1557 +extern void gr_handle_kernel_exploit(void);
1558 +
1559 /*
1560 * This function is protected against re-entrancy.
1561 */
1562 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1563 panic("Fatal exception in interrupt");
1564 if (panic_on_oops)
1565 panic("Fatal exception");
1566 +
1567 + gr_handle_kernel_exploit();
1568 +
1569 if (ret != NOTIFY_STOP)
1570 do_exit(SIGSEGV);
1571 }
1572 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1573 index 66a477a..bee61d3 100644
1574 --- a/arch/arm/lib/copy_from_user.S
1575 +++ b/arch/arm/lib/copy_from_user.S
1576 @@ -16,7 +16,7 @@
1577 /*
1578 * Prototype:
1579 *
1580 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1581 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1582 *
1583 * Purpose:
1584 *
1585 @@ -84,11 +84,11 @@
1586
1587 .text
1588
1589 -ENTRY(__copy_from_user)
1590 +ENTRY(___copy_from_user)
1591
1592 #include "copy_template.S"
1593
1594 -ENDPROC(__copy_from_user)
1595 +ENDPROC(___copy_from_user)
1596
1597 .pushsection .fixup,"ax"
1598 .align 0
1599 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1600 index 6ee2f67..d1cce76 100644
1601 --- a/arch/arm/lib/copy_page.S
1602 +++ b/arch/arm/lib/copy_page.S
1603 @@ -10,6 +10,7 @@
1604 * ASM optimised string functions
1605 */
1606 #include <linux/linkage.h>
1607 +#include <linux/const.h>
1608 #include <asm/assembler.h>
1609 #include <asm/asm-offsets.h>
1610 #include <asm/cache.h>
1611 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1612 index d066df6..df28194 100644
1613 --- a/arch/arm/lib/copy_to_user.S
1614 +++ b/arch/arm/lib/copy_to_user.S
1615 @@ -16,7 +16,7 @@
1616 /*
1617 * Prototype:
1618 *
1619 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1620 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1621 *
1622 * Purpose:
1623 *
1624 @@ -88,11 +88,11 @@
1625 .text
1626
1627 ENTRY(__copy_to_user_std)
1628 -WEAK(__copy_to_user)
1629 +WEAK(___copy_to_user)
1630
1631 #include "copy_template.S"
1632
1633 -ENDPROC(__copy_to_user)
1634 +ENDPROC(___copy_to_user)
1635 ENDPROC(__copy_to_user_std)
1636
1637 .pushsection .fixup,"ax"
1638 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1639 index 5c908b1..e712687 100644
1640 --- a/arch/arm/lib/uaccess.S
1641 +++ b/arch/arm/lib/uaccess.S
1642 @@ -20,7 +20,7 @@
1643
1644 #define PAGE_SHIFT 12
1645
1646 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1647 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1648 * Purpose : copy a block to user memory from kernel memory
1649 * Params : to - user memory
1650 * : from - kernel memory
1651 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1652 sub r2, r2, ip
1653 b .Lc2u_dest_aligned
1654
1655 -ENTRY(__copy_to_user)
1656 +ENTRY(___copy_to_user)
1657 stmfd sp!, {r2, r4 - r7, lr}
1658 cmp r2, #4
1659 blt .Lc2u_not_enough
1660 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1661 ldrgtb r3, [r1], #0
1662 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1663 b .Lc2u_finished
1664 -ENDPROC(__copy_to_user)
1665 +ENDPROC(___copy_to_user)
1666
1667 .pushsection .fixup,"ax"
1668 .align 0
1669 9001: ldmfd sp!, {r0, r4 - r7, pc}
1670 .popsection
1671
1672 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1673 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1674 * Purpose : copy a block from user memory to kernel memory
1675 * Params : to - kernel memory
1676 * : from - user memory
1677 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1678 sub r2, r2, ip
1679 b .Lcfu_dest_aligned
1680
1681 -ENTRY(__copy_from_user)
1682 +ENTRY(___copy_from_user)
1683 stmfd sp!, {r0, r2, r4 - r7, lr}
1684 cmp r2, #4
1685 blt .Lcfu_not_enough
1686 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1687 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1688 strgtb r3, [r0], #1
1689 b .Lcfu_finished
1690 -ENDPROC(__copy_from_user)
1691 +ENDPROC(___copy_from_user)
1692
1693 .pushsection .fixup,"ax"
1694 .align 0
1695 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1696 index 025f742..8432b08 100644
1697 --- a/arch/arm/lib/uaccess_with_memcpy.c
1698 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1699 @@ -104,7 +104,7 @@ out:
1700 }
1701
1702 unsigned long
1703 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1704 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1705 {
1706 /*
1707 * This test is stubbed out of the main function above to keep
1708 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1709 index 6722627..8f97548c 100644
1710 --- a/arch/arm/mach-omap2/board-n8x0.c
1711 +++ b/arch/arm/mach-omap2/board-n8x0.c
1712 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1713 }
1714 #endif
1715
1716 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1717 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1718 .late_init = n8x0_menelaus_late_init,
1719 };
1720
1721 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1722 index 2b2d51c..0127490 100644
1723 --- a/arch/arm/mach-ux500/mbox-db5500.c
1724 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1725 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1726 return sprintf(buf, "0x%X\n", mbox_value);
1727 }
1728
1729 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1730 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1731
1732 static int mbox_show(struct seq_file *s, void *data)
1733 {
1734 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1735 index bb7eac3..3bade16 100644
1736 --- a/arch/arm/mm/fault.c
1737 +++ b/arch/arm/mm/fault.c
1738 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1739 }
1740 #endif
1741
1742 +#ifdef CONFIG_PAX_PAGEEXEC
1743 + if (fsr & FSR_LNX_PF) {
1744 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1745 + do_group_exit(SIGKILL);
1746 + }
1747 +#endif
1748 +
1749 tsk->thread.address = addr;
1750 tsk->thread.error_code = fsr;
1751 tsk->thread.trap_no = 14;
1752 @@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1753 }
1754 #endif /* CONFIG_MMU */
1755
1756 +#ifdef CONFIG_PAX_PAGEEXEC
1757 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1758 +{
1759 + long i;
1760 +
1761 + printk(KERN_ERR "PAX: bytes at PC: ");
1762 + for (i = 0; i < 20; i++) {
1763 + unsigned char c;
1764 + if (get_user(c, (__force unsigned char __user *)pc+i))
1765 + printk(KERN_CONT "?? ");
1766 + else
1767 + printk(KERN_CONT "%02x ", c);
1768 + }
1769 + printk("\n");
1770 +
1771 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1772 + for (i = -1; i < 20; i++) {
1773 + unsigned long c;
1774 + if (get_user(c, (__force unsigned long __user *)sp+i))
1775 + printk(KERN_CONT "???????? ");
1776 + else
1777 + printk(KERN_CONT "%08lx ", c);
1778 + }
1779 + printk("\n");
1780 +}
1781 +#endif
1782 +
1783 /*
1784 * First Level Translation Fault Handler
1785 *
1786 @@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1787 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1788 struct siginfo info;
1789
1790 +#ifdef CONFIG_PAX_REFCOUNT
1791 + if (fsr_fs(ifsr) == 2) {
1792 + unsigned int bkpt;
1793 +
1794 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1795 + current->thread.error_code = ifsr;
1796 + current->thread.trap_no = 0;
1797 + pax_report_refcount_overflow(regs);
1798 + fixup_exception(regs);
1799 + return;
1800 + }
1801 + }
1802 +#endif
1803 +
1804 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1805 return;
1806
1807 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1808 index ce8cb19..3ec539d 100644
1809 --- a/arch/arm/mm/mmap.c
1810 +++ b/arch/arm/mm/mmap.c
1811 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1812 if (len > TASK_SIZE)
1813 return -ENOMEM;
1814
1815 +#ifdef CONFIG_PAX_RANDMMAP
1816 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1817 +#endif
1818 +
1819 if (addr) {
1820 if (do_align)
1821 addr = COLOUR_ALIGN(addr, pgoff);
1822 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1823 addr = PAGE_ALIGN(addr);
1824
1825 vma = find_vma(mm, addr);
1826 - if (TASK_SIZE - len >= addr &&
1827 - (!vma || addr + len <= vma->vm_start))
1828 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1829 return addr;
1830 }
1831 if (len > mm->cached_hole_size) {
1832 - start_addr = addr = mm->free_area_cache;
1833 + start_addr = addr = mm->free_area_cache;
1834 } else {
1835 - start_addr = addr = mm->mmap_base;
1836 - mm->cached_hole_size = 0;
1837 + start_addr = addr = mm->mmap_base;
1838 + mm->cached_hole_size = 0;
1839 }
1840
1841 full_search:
1842 @@ -124,14 +127,14 @@ full_search:
1843 * Start a new search - just in case we missed
1844 * some holes.
1845 */
1846 - if (start_addr != TASK_UNMAPPED_BASE) {
1847 - start_addr = addr = TASK_UNMAPPED_BASE;
1848 + if (start_addr != mm->mmap_base) {
1849 + start_addr = addr = mm->mmap_base;
1850 mm->cached_hole_size = 0;
1851 goto full_search;
1852 }
1853 return -ENOMEM;
1854 }
1855 - if (!vma || addr + len <= vma->vm_start) {
1856 + if (check_heap_stack_gap(vma, addr, len)) {
1857 /*
1858 * Remember the place where we stopped the search:
1859 */
1860 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1861
1862 if (mmap_is_legacy()) {
1863 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1864 +
1865 +#ifdef CONFIG_PAX_RANDMMAP
1866 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1867 + mm->mmap_base += mm->delta_mmap;
1868 +#endif
1869 +
1870 mm->get_unmapped_area = arch_get_unmapped_area;
1871 mm->unmap_area = arch_unmap_area;
1872 } else {
1873 mm->mmap_base = mmap_base(random_factor);
1874 +
1875 +#ifdef CONFIG_PAX_RANDMMAP
1876 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1877 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1878 +#endif
1879 +
1880 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1881 mm->unmap_area = arch_unmap_area_topdown;
1882 }
1883 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1884 index 71a6827..e7fbc23 100644
1885 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1886 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1887 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1888 int (*started)(unsigned ch);
1889 int (*flush)(unsigned ch);
1890 int (*stop)(unsigned ch);
1891 -};
1892 +} __no_const;
1893
1894 extern void *samsung_dmadev_get_ops(void);
1895 extern void *s3c_dma_get_ops(void);
1896 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1897 index 5f28cae..3d23723 100644
1898 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1899 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1900 @@ -14,7 +14,7 @@
1901 struct s5p_ehci_platdata {
1902 int (*phy_init)(struct platform_device *pdev, int type);
1903 int (*phy_exit)(struct platform_device *pdev, int type);
1904 -};
1905 +} __no_const;
1906
1907 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1908
1909 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1910 index c3a58a1..78fbf54 100644
1911 --- a/arch/avr32/include/asm/cache.h
1912 +++ b/arch/avr32/include/asm/cache.h
1913 @@ -1,8 +1,10 @@
1914 #ifndef __ASM_AVR32_CACHE_H
1915 #define __ASM_AVR32_CACHE_H
1916
1917 +#include <linux/const.h>
1918 +
1919 #define L1_CACHE_SHIFT 5
1920 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1921 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1922
1923 /*
1924 * Memory returned by kmalloc() may be used for DMA, so we must make
1925 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1926 index 3b3159b..425ea94 100644
1927 --- a/arch/avr32/include/asm/elf.h
1928 +++ b/arch/avr32/include/asm/elf.h
1929 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1930 the loader. We need to make sure that it is out of the way of the program
1931 that it will "exec", and that there is sufficient room for the brk. */
1932
1933 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1934 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1935
1936 +#ifdef CONFIG_PAX_ASLR
1937 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1938 +
1939 +#define PAX_DELTA_MMAP_LEN 15
1940 +#define PAX_DELTA_STACK_LEN 15
1941 +#endif
1942
1943 /* This yields a mask that user programs can use to figure out what
1944 instruction set this CPU supports. This could be done in user space,
1945 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1946 index b7f5c68..556135c 100644
1947 --- a/arch/avr32/include/asm/kmap_types.h
1948 +++ b/arch/avr32/include/asm/kmap_types.h
1949 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1950 D(11) KM_IRQ1,
1951 D(12) KM_SOFTIRQ0,
1952 D(13) KM_SOFTIRQ1,
1953 -D(14) KM_TYPE_NR
1954 +D(14) KM_CLEARPAGE,
1955 +D(15) KM_TYPE_NR
1956 };
1957
1958 #undef D
1959 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1960 index f7040a1..db9f300 100644
1961 --- a/arch/avr32/mm/fault.c
1962 +++ b/arch/avr32/mm/fault.c
1963 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1964
1965 int exception_trace = 1;
1966
1967 +#ifdef CONFIG_PAX_PAGEEXEC
1968 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1969 +{
1970 + unsigned long i;
1971 +
1972 + printk(KERN_ERR "PAX: bytes at PC: ");
1973 + for (i = 0; i < 20; i++) {
1974 + unsigned char c;
1975 + if (get_user(c, (unsigned char *)pc+i))
1976 + printk(KERN_CONT "???????? ");
1977 + else
1978 + printk(KERN_CONT "%02x ", c);
1979 + }
1980 + printk("\n");
1981 +}
1982 +#endif
1983 +
1984 /*
1985 * This routine handles page faults. It determines the address and the
1986 * problem, and then passes it off to one of the appropriate routines.
1987 @@ -156,6 +173,16 @@ bad_area:
1988 up_read(&mm->mmap_sem);
1989
1990 if (user_mode(regs)) {
1991 +
1992 +#ifdef CONFIG_PAX_PAGEEXEC
1993 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1994 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1995 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1996 + do_group_exit(SIGKILL);
1997 + }
1998 + }
1999 +#endif
2000 +
2001 if (exception_trace && printk_ratelimit())
2002 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2003 "sp %08lx ecr %lu\n",
2004 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2005 index 568885a..f8008df 100644
2006 --- a/arch/blackfin/include/asm/cache.h
2007 +++ b/arch/blackfin/include/asm/cache.h
2008 @@ -7,6 +7,7 @@
2009 #ifndef __ARCH_BLACKFIN_CACHE_H
2010 #define __ARCH_BLACKFIN_CACHE_H
2011
2012 +#include <linux/const.h>
2013 #include <linux/linkage.h> /* for asmlinkage */
2014
2015 /*
2016 @@ -14,7 +15,7 @@
2017 * Blackfin loads 32 bytes for cache
2018 */
2019 #define L1_CACHE_SHIFT 5
2020 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2021 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2022 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2023
2024 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2025 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2026 index aea2718..3639a60 100644
2027 --- a/arch/cris/include/arch-v10/arch/cache.h
2028 +++ b/arch/cris/include/arch-v10/arch/cache.h
2029 @@ -1,8 +1,9 @@
2030 #ifndef _ASM_ARCH_CACHE_H
2031 #define _ASM_ARCH_CACHE_H
2032
2033 +#include <linux/const.h>
2034 /* Etrax 100LX have 32-byte cache-lines. */
2035 -#define L1_CACHE_BYTES 32
2036 #define L1_CACHE_SHIFT 5
2037 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2038
2039 #endif /* _ASM_ARCH_CACHE_H */
2040 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2041 index 1de779f..336fad3 100644
2042 --- a/arch/cris/include/arch-v32/arch/cache.h
2043 +++ b/arch/cris/include/arch-v32/arch/cache.h
2044 @@ -1,11 +1,12 @@
2045 #ifndef _ASM_CRIS_ARCH_CACHE_H
2046 #define _ASM_CRIS_ARCH_CACHE_H
2047
2048 +#include <linux/const.h>
2049 #include <arch/hwregs/dma.h>
2050
2051 /* A cache-line is 32 bytes. */
2052 -#define L1_CACHE_BYTES 32
2053 #define L1_CACHE_SHIFT 5
2054 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2055
2056 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2057
2058 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2059 index 0d8a7d6..d0c9ff5 100644
2060 --- a/arch/frv/include/asm/atomic.h
2061 +++ b/arch/frv/include/asm/atomic.h
2062 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2063 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2064 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2065
2066 +#define atomic64_read_unchecked(v) atomic64_read(v)
2067 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2068 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2069 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2070 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2071 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2072 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2073 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2074 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2075 +
2076 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2077 {
2078 int c, old;
2079 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2080 index 2797163..c2a401d 100644
2081 --- a/arch/frv/include/asm/cache.h
2082 +++ b/arch/frv/include/asm/cache.h
2083 @@ -12,10 +12,11 @@
2084 #ifndef __ASM_CACHE_H
2085 #define __ASM_CACHE_H
2086
2087 +#include <linux/const.h>
2088
2089 /* bytes per L1 cache line */
2090 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2091 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2092 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2093
2094 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2095 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2096 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2097 index f8e16b2..c73ff79 100644
2098 --- a/arch/frv/include/asm/kmap_types.h
2099 +++ b/arch/frv/include/asm/kmap_types.h
2100 @@ -23,6 +23,7 @@ enum km_type {
2101 KM_IRQ1,
2102 KM_SOFTIRQ0,
2103 KM_SOFTIRQ1,
2104 + KM_CLEARPAGE,
2105 KM_TYPE_NR
2106 };
2107
2108 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2109 index 385fd30..6c3d97e 100644
2110 --- a/arch/frv/mm/elf-fdpic.c
2111 +++ b/arch/frv/mm/elf-fdpic.c
2112 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2113 if (addr) {
2114 addr = PAGE_ALIGN(addr);
2115 vma = find_vma(current->mm, addr);
2116 - if (TASK_SIZE - len >= addr &&
2117 - (!vma || addr + len <= vma->vm_start))
2118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2119 goto success;
2120 }
2121
2122 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2123 for (; vma; vma = vma->vm_next) {
2124 if (addr > limit)
2125 break;
2126 - if (addr + len <= vma->vm_start)
2127 + if (check_heap_stack_gap(vma, addr, len))
2128 goto success;
2129 addr = vma->vm_end;
2130 }
2131 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2132 for (; vma; vma = vma->vm_next) {
2133 if (addr > limit)
2134 break;
2135 - if (addr + len <= vma->vm_start)
2136 + if (check_heap_stack_gap(vma, addr, len))
2137 goto success;
2138 addr = vma->vm_end;
2139 }
2140 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2141 index c635028..6d9445a 100644
2142 --- a/arch/h8300/include/asm/cache.h
2143 +++ b/arch/h8300/include/asm/cache.h
2144 @@ -1,8 +1,10 @@
2145 #ifndef __ARCH_H8300_CACHE_H
2146 #define __ARCH_H8300_CACHE_H
2147
2148 +#include <linux/const.h>
2149 +
2150 /* bytes per L1 cache line */
2151 -#define L1_CACHE_BYTES 4
2152 +#define L1_CACHE_BYTES _AC(4,UL)
2153
2154 /* m68k-elf-gcc 2.95.2 doesn't like these */
2155
2156 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2157 index 0f01de2..d37d309 100644
2158 --- a/arch/hexagon/include/asm/cache.h
2159 +++ b/arch/hexagon/include/asm/cache.h
2160 @@ -21,9 +21,11 @@
2161 #ifndef __ASM_CACHE_H
2162 #define __ASM_CACHE_H
2163
2164 +#include <linux/const.h>
2165 +
2166 /* Bytes per L1 cache line */
2167 -#define L1_CACHE_SHIFT (5)
2168 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2169 +#define L1_CACHE_SHIFT 5
2170 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2173 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2174 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2175 index 3fad89e..3047da5 100644
2176 --- a/arch/ia64/include/asm/atomic.h
2177 +++ b/arch/ia64/include/asm/atomic.h
2178 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2179 #define atomic64_inc(v) atomic64_add(1, (v))
2180 #define atomic64_dec(v) atomic64_sub(1, (v))
2181
2182 +#define atomic64_read_unchecked(v) atomic64_read(v)
2183 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2184 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2185 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2186 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2187 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2188 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2189 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2190 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2191 +
2192 /* Atomic operations are already serializing */
2193 #define smp_mb__before_atomic_dec() barrier()
2194 #define smp_mb__after_atomic_dec() barrier()
2195 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2196 index 988254a..e1ee885 100644
2197 --- a/arch/ia64/include/asm/cache.h
2198 +++ b/arch/ia64/include/asm/cache.h
2199 @@ -1,6 +1,7 @@
2200 #ifndef _ASM_IA64_CACHE_H
2201 #define _ASM_IA64_CACHE_H
2202
2203 +#include <linux/const.h>
2204
2205 /*
2206 * Copyright (C) 1998-2000 Hewlett-Packard Co
2207 @@ -9,7 +10,7 @@
2208
2209 /* Bytes per L1 (data) cache line. */
2210 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2211 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2212 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2213
2214 #ifdef CONFIG_SMP
2215 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2216 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2217 index b5298eb..67c6e62 100644
2218 --- a/arch/ia64/include/asm/elf.h
2219 +++ b/arch/ia64/include/asm/elf.h
2220 @@ -42,6 +42,13 @@
2221 */
2222 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2223
2224 +#ifdef CONFIG_PAX_ASLR
2225 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2226 +
2227 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2228 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2229 +#endif
2230 +
2231 #define PT_IA_64_UNWIND 0x70000001
2232
2233 /* IA-64 relocations: */
2234 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2235 index 1a97af3..7529d31 100644
2236 --- a/arch/ia64/include/asm/pgtable.h
2237 +++ b/arch/ia64/include/asm/pgtable.h
2238 @@ -12,7 +12,7 @@
2239 * David Mosberger-Tang <davidm@hpl.hp.com>
2240 */
2241
2242 -
2243 +#include <linux/const.h>
2244 #include <asm/mman.h>
2245 #include <asm/page.h>
2246 #include <asm/processor.h>
2247 @@ -143,6 +143,17 @@
2248 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2249 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2250 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2251 +
2252 +#ifdef CONFIG_PAX_PAGEEXEC
2253 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2254 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2255 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2256 +#else
2257 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2258 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2259 +# define PAGE_COPY_NOEXEC PAGE_COPY
2260 +#endif
2261 +
2262 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2263 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2264 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2265 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2266 index b77768d..e0795eb 100644
2267 --- a/arch/ia64/include/asm/spinlock.h
2268 +++ b/arch/ia64/include/asm/spinlock.h
2269 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2270 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2271
2272 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2273 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2274 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2275 }
2276
2277 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2278 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2279 index 449c8c0..432a3d2 100644
2280 --- a/arch/ia64/include/asm/uaccess.h
2281 +++ b/arch/ia64/include/asm/uaccess.h
2282 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2283 const void *__cu_from = (from); \
2284 long __cu_len = (n); \
2285 \
2286 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2287 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2288 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2289 __cu_len; \
2290 })
2291 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2292 long __cu_len = (n); \
2293 \
2294 __chk_user_ptr(__cu_from); \
2295 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2296 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2297 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2298 __cu_len; \
2299 })
2300 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2301 index 24603be..948052d 100644
2302 --- a/arch/ia64/kernel/module.c
2303 +++ b/arch/ia64/kernel/module.c
2304 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2305 void
2306 module_free (struct module *mod, void *module_region)
2307 {
2308 - if (mod && mod->arch.init_unw_table &&
2309 - module_region == mod->module_init) {
2310 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2311 unw_remove_unwind_table(mod->arch.init_unw_table);
2312 mod->arch.init_unw_table = NULL;
2313 }
2314 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2315 }
2316
2317 static inline int
2318 +in_init_rx (const struct module *mod, uint64_t addr)
2319 +{
2320 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2321 +}
2322 +
2323 +static inline int
2324 +in_init_rw (const struct module *mod, uint64_t addr)
2325 +{
2326 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2327 +}
2328 +
2329 +static inline int
2330 in_init (const struct module *mod, uint64_t addr)
2331 {
2332 - return addr - (uint64_t) mod->module_init < mod->init_size;
2333 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2334 +}
2335 +
2336 +static inline int
2337 +in_core_rx (const struct module *mod, uint64_t addr)
2338 +{
2339 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2340 +}
2341 +
2342 +static inline int
2343 +in_core_rw (const struct module *mod, uint64_t addr)
2344 +{
2345 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2346 }
2347
2348 static inline int
2349 in_core (const struct module *mod, uint64_t addr)
2350 {
2351 - return addr - (uint64_t) mod->module_core < mod->core_size;
2352 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2353 }
2354
2355 static inline int
2356 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2357 break;
2358
2359 case RV_BDREL:
2360 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2361 + if (in_init_rx(mod, val))
2362 + val -= (uint64_t) mod->module_init_rx;
2363 + else if (in_init_rw(mod, val))
2364 + val -= (uint64_t) mod->module_init_rw;
2365 + else if (in_core_rx(mod, val))
2366 + val -= (uint64_t) mod->module_core_rx;
2367 + else if (in_core_rw(mod, val))
2368 + val -= (uint64_t) mod->module_core_rw;
2369 break;
2370
2371 case RV_LTV:
2372 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2373 * addresses have been selected...
2374 */
2375 uint64_t gp;
2376 - if (mod->core_size > MAX_LTOFF)
2377 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2378 /*
2379 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2380 * at the end of the module.
2381 */
2382 - gp = mod->core_size - MAX_LTOFF / 2;
2383 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2384 else
2385 - gp = mod->core_size / 2;
2386 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2387 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2388 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2389 mod->arch.gp = gp;
2390 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2391 }
2392 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2393 index 609d500..7dde2a8 100644
2394 --- a/arch/ia64/kernel/sys_ia64.c
2395 +++ b/arch/ia64/kernel/sys_ia64.c
2396 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2397 if (REGION_NUMBER(addr) == RGN_HPAGE)
2398 addr = 0;
2399 #endif
2400 +
2401 +#ifdef CONFIG_PAX_RANDMMAP
2402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2403 + addr = mm->free_area_cache;
2404 + else
2405 +#endif
2406 +
2407 if (!addr)
2408 addr = mm->free_area_cache;
2409
2410 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2411 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2412 /* At this point: (!vma || addr < vma->vm_end). */
2413 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2414 - if (start_addr != TASK_UNMAPPED_BASE) {
2415 + if (start_addr != mm->mmap_base) {
2416 /* Start a new search --- just in case we missed some holes. */
2417 - addr = TASK_UNMAPPED_BASE;
2418 + addr = mm->mmap_base;
2419 goto full_search;
2420 }
2421 return -ENOMEM;
2422 }
2423 - if (!vma || addr + len <= vma->vm_start) {
2424 + if (check_heap_stack_gap(vma, addr, len)) {
2425 /* Remember the address where we stopped this search: */
2426 mm->free_area_cache = addr + len;
2427 return addr;
2428 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2429 index 53c0ba0..2accdde 100644
2430 --- a/arch/ia64/kernel/vmlinux.lds.S
2431 +++ b/arch/ia64/kernel/vmlinux.lds.S
2432 @@ -199,7 +199,7 @@ SECTIONS {
2433 /* Per-cpu data: */
2434 . = ALIGN(PERCPU_PAGE_SIZE);
2435 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2436 - __phys_per_cpu_start = __per_cpu_load;
2437 + __phys_per_cpu_start = per_cpu_load;
2438 /*
2439 * ensure percpu data fits
2440 * into percpu page size
2441 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2442 index 20b3593..1ce77f0 100644
2443 --- a/arch/ia64/mm/fault.c
2444 +++ b/arch/ia64/mm/fault.c
2445 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2446 return pte_present(pte);
2447 }
2448
2449 +#ifdef CONFIG_PAX_PAGEEXEC
2450 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2451 +{
2452 + unsigned long i;
2453 +
2454 + printk(KERN_ERR "PAX: bytes at PC: ");
2455 + for (i = 0; i < 8; i++) {
2456 + unsigned int c;
2457 + if (get_user(c, (unsigned int *)pc+i))
2458 + printk(KERN_CONT "???????? ");
2459 + else
2460 + printk(KERN_CONT "%08x ", c);
2461 + }
2462 + printk("\n");
2463 +}
2464 +#endif
2465 +
2466 void __kprobes
2467 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2468 {
2469 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2470 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2471 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2472
2473 - if ((vma->vm_flags & mask) != mask)
2474 + if ((vma->vm_flags & mask) != mask) {
2475 +
2476 +#ifdef CONFIG_PAX_PAGEEXEC
2477 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2478 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2479 + goto bad_area;
2480 +
2481 + up_read(&mm->mmap_sem);
2482 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2483 + do_group_exit(SIGKILL);
2484 + }
2485 +#endif
2486 +
2487 goto bad_area;
2488
2489 + }
2490 +
2491 /*
2492 * If for any reason at all we couldn't handle the fault, make
2493 * sure we exit gracefully rather than endlessly redo the
2494 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2495 index 5ca674b..e0e1b70 100644
2496 --- a/arch/ia64/mm/hugetlbpage.c
2497 +++ b/arch/ia64/mm/hugetlbpage.c
2498 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2499 /* At this point: (!vmm || addr < vmm->vm_end). */
2500 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2501 return -ENOMEM;
2502 - if (!vmm || (addr + len) <= vmm->vm_start)
2503 + if (check_heap_stack_gap(vmm, addr, len))
2504 return addr;
2505 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2506 }
2507 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2508 index 13df239d..cb52116 100644
2509 --- a/arch/ia64/mm/init.c
2510 +++ b/arch/ia64/mm/init.c
2511 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2512 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2513 vma->vm_end = vma->vm_start + PAGE_SIZE;
2514 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2515 +
2516 +#ifdef CONFIG_PAX_PAGEEXEC
2517 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2518 + vma->vm_flags &= ~VM_EXEC;
2519 +
2520 +#ifdef CONFIG_PAX_MPROTECT
2521 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2522 + vma->vm_flags &= ~VM_MAYEXEC;
2523 +#endif
2524 +
2525 + }
2526 +#endif
2527 +
2528 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2529 down_write(&current->mm->mmap_sem);
2530 if (insert_vm_struct(current->mm, vma)) {
2531 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2532 index 40b3ee9..8c2c112 100644
2533 --- a/arch/m32r/include/asm/cache.h
2534 +++ b/arch/m32r/include/asm/cache.h
2535 @@ -1,8 +1,10 @@
2536 #ifndef _ASM_M32R_CACHE_H
2537 #define _ASM_M32R_CACHE_H
2538
2539 +#include <linux/const.h>
2540 +
2541 /* L1 cache line size */
2542 #define L1_CACHE_SHIFT 4
2543 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2544 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2545
2546 #endif /* _ASM_M32R_CACHE_H */
2547 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2548 index 82abd15..d95ae5d 100644
2549 --- a/arch/m32r/lib/usercopy.c
2550 +++ b/arch/m32r/lib/usercopy.c
2551 @@ -14,6 +14,9 @@
2552 unsigned long
2553 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2554 {
2555 + if ((long)n < 0)
2556 + return n;
2557 +
2558 prefetch(from);
2559 if (access_ok(VERIFY_WRITE, to, n))
2560 __copy_user(to,from,n);
2561 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2562 unsigned long
2563 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2564 {
2565 + if ((long)n < 0)
2566 + return n;
2567 +
2568 prefetchw(to);
2569 if (access_ok(VERIFY_READ, from, n))
2570 __copy_user_zeroing(to,from,n);
2571 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2572 index 0395c51..5f26031 100644
2573 --- a/arch/m68k/include/asm/cache.h
2574 +++ b/arch/m68k/include/asm/cache.h
2575 @@ -4,9 +4,11 @@
2576 #ifndef __ARCH_M68K_CACHE_H
2577 #define __ARCH_M68K_CACHE_H
2578
2579 +#include <linux/const.h>
2580 +
2581 /* bytes per L1 cache line */
2582 #define L1_CACHE_SHIFT 4
2583 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2584 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2585
2586 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2587
2588 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2589 index 4efe96a..60e8699 100644
2590 --- a/arch/microblaze/include/asm/cache.h
2591 +++ b/arch/microblaze/include/asm/cache.h
2592 @@ -13,11 +13,12 @@
2593 #ifndef _ASM_MICROBLAZE_CACHE_H
2594 #define _ASM_MICROBLAZE_CACHE_H
2595
2596 +#include <linux/const.h>
2597 #include <asm/registers.h>
2598
2599 #define L1_CACHE_SHIFT 5
2600 /* word-granular cache in microblaze */
2601 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2602 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2603
2604 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2605
2606 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2607 index 1d93f81..67794d0 100644
2608 --- a/arch/mips/include/asm/atomic.h
2609 +++ b/arch/mips/include/asm/atomic.h
2610 @@ -21,6 +21,10 @@
2611 #include <asm/war.h>
2612 #include <asm/system.h>
2613
2614 +#ifdef CONFIG_GENERIC_ATOMIC64
2615 +#include <asm-generic/atomic64.h>
2616 +#endif
2617 +
2618 #define ATOMIC_INIT(i) { (i) }
2619
2620 /*
2621 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2622 */
2623 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2624
2625 +#define atomic64_read_unchecked(v) atomic64_read(v)
2626 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2627 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2628 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2629 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2630 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2631 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2632 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2633 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2634 +
2635 #endif /* CONFIG_64BIT */
2636
2637 /*
2638 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2639 index b4db69f..8f3b093 100644
2640 --- a/arch/mips/include/asm/cache.h
2641 +++ b/arch/mips/include/asm/cache.h
2642 @@ -9,10 +9,11 @@
2643 #ifndef _ASM_CACHE_H
2644 #define _ASM_CACHE_H
2645
2646 +#include <linux/const.h>
2647 #include <kmalloc.h>
2648
2649 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2650 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2651 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2652
2653 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2654 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2655 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2656 index 455c0ac..ad65fbe 100644
2657 --- a/arch/mips/include/asm/elf.h
2658 +++ b/arch/mips/include/asm/elf.h
2659 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2660 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2661 #endif
2662
2663 +#ifdef CONFIG_PAX_ASLR
2664 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2665 +
2666 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2667 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2668 +#endif
2669 +
2670 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2671 struct linux_binprm;
2672 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2673 int uses_interp);
2674
2675 -struct mm_struct;
2676 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2677 -#define arch_randomize_brk arch_randomize_brk
2678 -
2679 #endif /* _ASM_ELF_H */
2680 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2681 index da9bd7d..91aa7ab 100644
2682 --- a/arch/mips/include/asm/page.h
2683 +++ b/arch/mips/include/asm/page.h
2684 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2685 #ifdef CONFIG_CPU_MIPS32
2686 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2687 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2688 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2689 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2690 #else
2691 typedef struct { unsigned long long pte; } pte_t;
2692 #define pte_val(x) ((x).pte)
2693 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2694 index 6018c80..7c37203 100644
2695 --- a/arch/mips/include/asm/system.h
2696 +++ b/arch/mips/include/asm/system.h
2697 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2698 */
2699 #define __ARCH_WANT_UNLOCKED_CTXSW
2700
2701 -extern unsigned long arch_align_stack(unsigned long sp);
2702 +#define arch_align_stack(x) ((x) & ~0xfUL)
2703
2704 #endif /* _ASM_SYSTEM_H */
2705 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2706 index 9fdd8bc..4bd7f1a 100644
2707 --- a/arch/mips/kernel/binfmt_elfn32.c
2708 +++ b/arch/mips/kernel/binfmt_elfn32.c
2709 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2710 #undef ELF_ET_DYN_BASE
2711 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2712
2713 +#ifdef CONFIG_PAX_ASLR
2714 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2715 +
2716 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2717 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2718 +#endif
2719 +
2720 #include <asm/processor.h>
2721 #include <linux/module.h>
2722 #include <linux/elfcore.h>
2723 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2724 index ff44823..97f8906 100644
2725 --- a/arch/mips/kernel/binfmt_elfo32.c
2726 +++ b/arch/mips/kernel/binfmt_elfo32.c
2727 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2728 #undef ELF_ET_DYN_BASE
2729 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2730
2731 +#ifdef CONFIG_PAX_ASLR
2732 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2733 +
2734 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2735 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2736 +#endif
2737 +
2738 #include <asm/processor.h>
2739
2740 /*
2741 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2742 index 7955409..ceaea7c 100644
2743 --- a/arch/mips/kernel/process.c
2744 +++ b/arch/mips/kernel/process.c
2745 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2746 out:
2747 return pc;
2748 }
2749 -
2750 -/*
2751 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2752 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2753 - */
2754 -unsigned long arch_align_stack(unsigned long sp)
2755 -{
2756 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2757 - sp -= get_random_int() & ~PAGE_MASK;
2758 -
2759 - return sp & ALMASK;
2760 -}
2761 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2762 index 69ebd58..e4bff83 100644
2763 --- a/arch/mips/mm/fault.c
2764 +++ b/arch/mips/mm/fault.c
2765 @@ -28,6 +28,23 @@
2766 #include <asm/highmem.h> /* For VMALLOC_END */
2767 #include <linux/kdebug.h>
2768
2769 +#ifdef CONFIG_PAX_PAGEEXEC
2770 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2771 +{
2772 + unsigned long i;
2773 +
2774 + printk(KERN_ERR "PAX: bytes at PC: ");
2775 + for (i = 0; i < 5; i++) {
2776 + unsigned int c;
2777 + if (get_user(c, (unsigned int *)pc+i))
2778 + printk(KERN_CONT "???????? ");
2779 + else
2780 + printk(KERN_CONT "%08x ", c);
2781 + }
2782 + printk("\n");
2783 +}
2784 +#endif
2785 +
2786 /*
2787 * This routine handles page faults. It determines the address,
2788 * and the problem, and then passes it off to one of the appropriate
2789 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2790 index 302d779..7d35bf8 100644
2791 --- a/arch/mips/mm/mmap.c
2792 +++ b/arch/mips/mm/mmap.c
2793 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2794 do_color_align = 1;
2795
2796 /* requesting a specific address */
2797 +
2798 +#ifdef CONFIG_PAX_RANDMMAP
2799 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2800 +#endif
2801 +
2802 if (addr) {
2803 if (do_color_align)
2804 addr = COLOUR_ALIGN(addr, pgoff);
2805 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2806 addr = PAGE_ALIGN(addr);
2807
2808 vma = find_vma(mm, addr);
2809 - if (TASK_SIZE - len >= addr &&
2810 - (!vma || addr + len <= vma->vm_start))
2811 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2812 return addr;
2813 }
2814
2815 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2816 /* At this point: (!vma || addr < vma->vm_end). */
2817 if (TASK_SIZE - len < addr)
2818 return -ENOMEM;
2819 - if (!vma || addr + len <= vma->vm_start)
2820 + if (check_heap_stack_gap(vmm, addr, len))
2821 return addr;
2822 addr = vma->vm_end;
2823 if (do_color_align)
2824 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2825 /* make sure it can fit in the remaining address space */
2826 if (likely(addr > len)) {
2827 vma = find_vma(mm, addr - len);
2828 - if (!vma || addr <= vma->vm_start) {
2829 + if (check_heap_stack_gap(vmm, addr - len, len))
2830 /* cache the address as a hint for next time */
2831 return mm->free_area_cache = addr - len;
2832 }
2833 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2834 * return with success:
2835 */
2836 vma = find_vma(mm, addr);
2837 - if (likely(!vma || addr + len <= vma->vm_start)) {
2838 + if (check_heap_stack_gap(vmm, addr, len)) {
2839 /* cache the address as a hint for next time */
2840 return mm->free_area_cache = addr;
2841 }
2842 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2843 mm->unmap_area = arch_unmap_area_topdown;
2844 }
2845 }
2846 -
2847 -static inline unsigned long brk_rnd(void)
2848 -{
2849 - unsigned long rnd = get_random_int();
2850 -
2851 - rnd = rnd << PAGE_SHIFT;
2852 - /* 8MB for 32bit, 256MB for 64bit */
2853 - if (TASK_IS_32BIT_ADDR)
2854 - rnd = rnd & 0x7ffffful;
2855 - else
2856 - rnd = rnd & 0xffffffful;
2857 -
2858 - return rnd;
2859 -}
2860 -
2861 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2862 -{
2863 - unsigned long base = mm->brk;
2864 - unsigned long ret;
2865 -
2866 - ret = PAGE_ALIGN(base + brk_rnd());
2867 -
2868 - if (ret < mm->brk)
2869 - return mm->brk;
2870 -
2871 - return ret;
2872 -}
2873 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2874 index 967d144..db12197 100644
2875 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2876 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2877 @@ -11,12 +11,14 @@
2878 #ifndef _ASM_PROC_CACHE_H
2879 #define _ASM_PROC_CACHE_H
2880
2881 +#include <linux/const.h>
2882 +
2883 /* L1 cache */
2884
2885 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2886 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2887 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2888 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2889 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2890 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2891
2892 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2893 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2894 index bcb5df2..84fabd2 100644
2895 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2896 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2897 @@ -16,13 +16,15 @@
2898 #ifndef _ASM_PROC_CACHE_H
2899 #define _ASM_PROC_CACHE_H
2900
2901 +#include <linux/const.h>
2902 +
2903 /*
2904 * L1 cache
2905 */
2906 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2907 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2908 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2909 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2910 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2911 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2912
2913 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2914 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2915 index 4ce7a01..449202a 100644
2916 --- a/arch/openrisc/include/asm/cache.h
2917 +++ b/arch/openrisc/include/asm/cache.h
2918 @@ -19,11 +19,13 @@
2919 #ifndef __ASM_OPENRISC_CACHE_H
2920 #define __ASM_OPENRISC_CACHE_H
2921
2922 +#include <linux/const.h>
2923 +
2924 /* FIXME: How can we replace these with values from the CPU...
2925 * they shouldn't be hard-coded!
2926 */
2927
2928 -#define L1_CACHE_BYTES 16
2929 #define L1_CACHE_SHIFT 4
2930 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2931
2932 #endif /* __ASM_OPENRISC_CACHE_H */
2933 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2934 index 4054b31..a10c105 100644
2935 --- a/arch/parisc/include/asm/atomic.h
2936 +++ b/arch/parisc/include/asm/atomic.h
2937 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2938
2939 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2940
2941 +#define atomic64_read_unchecked(v) atomic64_read(v)
2942 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2943 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2944 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2945 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2946 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2947 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2948 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2949 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2950 +
2951 #endif /* !CONFIG_64BIT */
2952
2953
2954 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2955 index 47f11c7..3420df2 100644
2956 --- a/arch/parisc/include/asm/cache.h
2957 +++ b/arch/parisc/include/asm/cache.h
2958 @@ -5,6 +5,7 @@
2959 #ifndef __ARCH_PARISC_CACHE_H
2960 #define __ARCH_PARISC_CACHE_H
2961
2962 +#include <linux/const.h>
2963
2964 /*
2965 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2966 @@ -15,13 +16,13 @@
2967 * just ruin performance.
2968 */
2969 #ifdef CONFIG_PA20
2970 -#define L1_CACHE_BYTES 64
2971 #define L1_CACHE_SHIFT 6
2972 #else
2973 -#define L1_CACHE_BYTES 32
2974 #define L1_CACHE_SHIFT 5
2975 #endif
2976
2977 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2978 +
2979 #ifndef __ASSEMBLY__
2980
2981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2982 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2983 index 19f6cb1..6c78cf2 100644
2984 --- a/arch/parisc/include/asm/elf.h
2985 +++ b/arch/parisc/include/asm/elf.h
2986 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2987
2988 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2989
2990 +#ifdef CONFIG_PAX_ASLR
2991 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2992 +
2993 +#define PAX_DELTA_MMAP_LEN 16
2994 +#define PAX_DELTA_STACK_LEN 16
2995 +#endif
2996 +
2997 /* This yields a mask that user programs can use to figure out what
2998 instruction set this CPU supports. This could be done in user space,
2999 but it's not easy, and we've already done it here. */
3000 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3001 index 22dadeb..f6c2be4 100644
3002 --- a/arch/parisc/include/asm/pgtable.h
3003 +++ b/arch/parisc/include/asm/pgtable.h
3004 @@ -210,6 +210,17 @@ struct vm_area_struct;
3005 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3006 #define PAGE_COPY PAGE_EXECREAD
3007 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3008 +
3009 +#ifdef CONFIG_PAX_PAGEEXEC
3010 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3011 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3012 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3013 +#else
3014 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3015 +# define PAGE_COPY_NOEXEC PAGE_COPY
3016 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3017 +#endif
3018 +
3019 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3020 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3021 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3022 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3023 index 5e34ccf..672bc9c 100644
3024 --- a/arch/parisc/kernel/module.c
3025 +++ b/arch/parisc/kernel/module.c
3026 @@ -98,16 +98,38 @@
3027
3028 /* three functions to determine where in the module core
3029 * or init pieces the location is */
3030 +static inline int in_init_rx(struct module *me, void *loc)
3031 +{
3032 + return (loc >= me->module_init_rx &&
3033 + loc < (me->module_init_rx + me->init_size_rx));
3034 +}
3035 +
3036 +static inline int in_init_rw(struct module *me, void *loc)
3037 +{
3038 + return (loc >= me->module_init_rw &&
3039 + loc < (me->module_init_rw + me->init_size_rw));
3040 +}
3041 +
3042 static inline int in_init(struct module *me, void *loc)
3043 {
3044 - return (loc >= me->module_init &&
3045 - loc <= (me->module_init + me->init_size));
3046 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3047 +}
3048 +
3049 +static inline int in_core_rx(struct module *me, void *loc)
3050 +{
3051 + return (loc >= me->module_core_rx &&
3052 + loc < (me->module_core_rx + me->core_size_rx));
3053 +}
3054 +
3055 +static inline int in_core_rw(struct module *me, void *loc)
3056 +{
3057 + return (loc >= me->module_core_rw &&
3058 + loc < (me->module_core_rw + me->core_size_rw));
3059 }
3060
3061 static inline int in_core(struct module *me, void *loc)
3062 {
3063 - return (loc >= me->module_core &&
3064 - loc <= (me->module_core + me->core_size));
3065 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3066 }
3067
3068 static inline int in_local(struct module *me, void *loc)
3069 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3070 }
3071
3072 /* align things a bit */
3073 - me->core_size = ALIGN(me->core_size, 16);
3074 - me->arch.got_offset = me->core_size;
3075 - me->core_size += gots * sizeof(struct got_entry);
3076 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3077 + me->arch.got_offset = me->core_size_rw;
3078 + me->core_size_rw += gots * sizeof(struct got_entry);
3079
3080 - me->core_size = ALIGN(me->core_size, 16);
3081 - me->arch.fdesc_offset = me->core_size;
3082 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3083 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3084 + me->arch.fdesc_offset = me->core_size_rw;
3085 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3086
3087 me->arch.got_max = gots;
3088 me->arch.fdesc_max = fdescs;
3089 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3090
3091 BUG_ON(value == 0);
3092
3093 - got = me->module_core + me->arch.got_offset;
3094 + got = me->module_core_rw + me->arch.got_offset;
3095 for (i = 0; got[i].addr; i++)
3096 if (got[i].addr == value)
3097 goto out;
3098 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3099 #ifdef CONFIG_64BIT
3100 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3101 {
3102 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3103 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3104
3105 if (!value) {
3106 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3107 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3108
3109 /* Create new one */
3110 fdesc->addr = value;
3111 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3112 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3113 return (Elf_Addr)fdesc;
3114 }
3115 #endif /* CONFIG_64BIT */
3116 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3117
3118 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3119 end = table + sechdrs[me->arch.unwind_section].sh_size;
3120 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3121 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3122
3123 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3124 me->arch.unwind_section, table, end, gp);
3125 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3126 index c9b9322..02d8940 100644
3127 --- a/arch/parisc/kernel/sys_parisc.c
3128 +++ b/arch/parisc/kernel/sys_parisc.c
3129 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3130 /* At this point: (!vma || addr < vma->vm_end). */
3131 if (TASK_SIZE - len < addr)
3132 return -ENOMEM;
3133 - if (!vma || addr + len <= vma->vm_start)
3134 + if (check_heap_stack_gap(vma, addr, len))
3135 return addr;
3136 addr = vma->vm_end;
3137 }
3138 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3139 /* At this point: (!vma || addr < vma->vm_end). */
3140 if (TASK_SIZE - len < addr)
3141 return -ENOMEM;
3142 - if (!vma || addr + len <= vma->vm_start)
3143 + if (check_heap_stack_gap(vma, addr, len))
3144 return addr;
3145 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3146 if (addr < vma->vm_end) /* handle wraparound */
3147 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3148 if (flags & MAP_FIXED)
3149 return addr;
3150 if (!addr)
3151 - addr = TASK_UNMAPPED_BASE;
3152 + addr = current->mm->mmap_base;
3153
3154 if (filp) {
3155 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3156 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3157 index f19e660..414fe24 100644
3158 --- a/arch/parisc/kernel/traps.c
3159 +++ b/arch/parisc/kernel/traps.c
3160 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3161
3162 down_read(&current->mm->mmap_sem);
3163 vma = find_vma(current->mm,regs->iaoq[0]);
3164 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3165 - && (vma->vm_flags & VM_EXEC)) {
3166 -
3167 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3168 fault_address = regs->iaoq[0];
3169 fault_space = regs->iasq[0];
3170
3171 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3172 index 18162ce..94de376 100644
3173 --- a/arch/parisc/mm/fault.c
3174 +++ b/arch/parisc/mm/fault.c
3175 @@ -15,6 +15,7 @@
3176 #include <linux/sched.h>
3177 #include <linux/interrupt.h>
3178 #include <linux/module.h>
3179 +#include <linux/unistd.h>
3180
3181 #include <asm/uaccess.h>
3182 #include <asm/traps.h>
3183 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3184 static unsigned long
3185 parisc_acctyp(unsigned long code, unsigned int inst)
3186 {
3187 - if (code == 6 || code == 16)
3188 + if (code == 6 || code == 7 || code == 16)
3189 return VM_EXEC;
3190
3191 switch (inst & 0xf0000000) {
3192 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3193 }
3194 #endif
3195
3196 +#ifdef CONFIG_PAX_PAGEEXEC
3197 +/*
3198 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3199 + *
3200 + * returns 1 when task should be killed
3201 + * 2 when rt_sigreturn trampoline was detected
3202 + * 3 when unpatched PLT trampoline was detected
3203 + */
3204 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3205 +{
3206 +
3207 +#ifdef CONFIG_PAX_EMUPLT
3208 + int err;
3209 +
3210 + do { /* PaX: unpatched PLT emulation */
3211 + unsigned int bl, depwi;
3212 +
3213 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3214 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3215 +
3216 + if (err)
3217 + break;
3218 +
3219 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3220 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3221 +
3222 + err = get_user(ldw, (unsigned int *)addr);
3223 + err |= get_user(bv, (unsigned int *)(addr+4));
3224 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3225 +
3226 + if (err)
3227 + break;
3228 +
3229 + if (ldw == 0x0E801096U &&
3230 + bv == 0xEAC0C000U &&
3231 + ldw2 == 0x0E881095U)
3232 + {
3233 + unsigned int resolver, map;
3234 +
3235 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3236 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3237 + if (err)
3238 + break;
3239 +
3240 + regs->gr[20] = instruction_pointer(regs)+8;
3241 + regs->gr[21] = map;
3242 + regs->gr[22] = resolver;
3243 + regs->iaoq[0] = resolver | 3UL;
3244 + regs->iaoq[1] = regs->iaoq[0] + 4;
3245 + return 3;
3246 + }
3247 + }
3248 + } while (0);
3249 +#endif
3250 +
3251 +#ifdef CONFIG_PAX_EMUTRAMP
3252 +
3253 +#ifndef CONFIG_PAX_EMUSIGRT
3254 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3255 + return 1;
3256 +#endif
3257 +
3258 + do { /* PaX: rt_sigreturn emulation */
3259 + unsigned int ldi1, ldi2, bel, nop;
3260 +
3261 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3262 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3263 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3264 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3265 +
3266 + if (err)
3267 + break;
3268 +
3269 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3270 + ldi2 == 0x3414015AU &&
3271 + bel == 0xE4008200U &&
3272 + nop == 0x08000240U)
3273 + {
3274 + regs->gr[25] = (ldi1 & 2) >> 1;
3275 + regs->gr[20] = __NR_rt_sigreturn;
3276 + regs->gr[31] = regs->iaoq[1] + 16;
3277 + regs->sr[0] = regs->iasq[1];
3278 + regs->iaoq[0] = 0x100UL;
3279 + regs->iaoq[1] = regs->iaoq[0] + 4;
3280 + regs->iasq[0] = regs->sr[2];
3281 + regs->iasq[1] = regs->sr[2];
3282 + return 2;
3283 + }
3284 + } while (0);
3285 +#endif
3286 +
3287 + return 1;
3288 +}
3289 +
3290 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3291 +{
3292 + unsigned long i;
3293 +
3294 + printk(KERN_ERR "PAX: bytes at PC: ");
3295 + for (i = 0; i < 5; i++) {
3296 + unsigned int c;
3297 + if (get_user(c, (unsigned int *)pc+i))
3298 + printk(KERN_CONT "???????? ");
3299 + else
3300 + printk(KERN_CONT "%08x ", c);
3301 + }
3302 + printk("\n");
3303 +}
3304 +#endif
3305 +
3306 int fixup_exception(struct pt_regs *regs)
3307 {
3308 const struct exception_table_entry *fix;
3309 @@ -192,8 +303,33 @@ good_area:
3310
3311 acc_type = parisc_acctyp(code,regs->iir);
3312
3313 - if ((vma->vm_flags & acc_type) != acc_type)
3314 + if ((vma->vm_flags & acc_type) != acc_type) {
3315 +
3316 +#ifdef CONFIG_PAX_PAGEEXEC
3317 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3318 + (address & ~3UL) == instruction_pointer(regs))
3319 + {
3320 + up_read(&mm->mmap_sem);
3321 + switch (pax_handle_fetch_fault(regs)) {
3322 +
3323 +#ifdef CONFIG_PAX_EMUPLT
3324 + case 3:
3325 + return;
3326 +#endif
3327 +
3328 +#ifdef CONFIG_PAX_EMUTRAMP
3329 + case 2:
3330 + return;
3331 +#endif
3332 +
3333 + }
3334 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3335 + do_group_exit(SIGKILL);
3336 + }
3337 +#endif
3338 +
3339 goto bad_area;
3340 + }
3341
3342 /*
3343 * If for any reason at all we couldn't handle the fault, make
3344 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3345 index 02e41b5..ec6e26c 100644
3346 --- a/arch/powerpc/include/asm/atomic.h
3347 +++ b/arch/powerpc/include/asm/atomic.h
3348 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3349
3350 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3351
3352 +#define atomic64_read_unchecked(v) atomic64_read(v)
3353 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3354 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3355 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3356 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3357 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3358 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3359 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3360 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3361 +
3362 #endif /* __powerpc64__ */
3363
3364 #endif /* __KERNEL__ */
3365 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3366 index 4b50941..5605819 100644
3367 --- a/arch/powerpc/include/asm/cache.h
3368 +++ b/arch/powerpc/include/asm/cache.h
3369 @@ -3,6 +3,7 @@
3370
3371 #ifdef __KERNEL__
3372
3373 +#include <linux/const.h>
3374
3375 /* bytes per L1 cache line */
3376 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3377 @@ -22,7 +23,7 @@
3378 #define L1_CACHE_SHIFT 7
3379 #endif
3380
3381 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3382 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3383
3384 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3385
3386 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3387 index 3bf9cca..e7457d0 100644
3388 --- a/arch/powerpc/include/asm/elf.h
3389 +++ b/arch/powerpc/include/asm/elf.h
3390 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3391 the loader. We need to make sure that it is out of the way of the program
3392 that it will "exec", and that there is sufficient room for the brk. */
3393
3394 -extern unsigned long randomize_et_dyn(unsigned long base);
3395 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3396 +#define ELF_ET_DYN_BASE (0x20000000)
3397 +
3398 +#ifdef CONFIG_PAX_ASLR
3399 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3400 +
3401 +#ifdef __powerpc64__
3402 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3403 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3404 +#else
3405 +#define PAX_DELTA_MMAP_LEN 15
3406 +#define PAX_DELTA_STACK_LEN 15
3407 +#endif
3408 +#endif
3409
3410 /*
3411 * Our registers are always unsigned longs, whether we're a 32 bit
3412 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3413 (0x7ff >> (PAGE_SHIFT - 12)) : \
3414 (0x3ffff >> (PAGE_SHIFT - 12)))
3415
3416 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3417 -#define arch_randomize_brk arch_randomize_brk
3418 -
3419 #endif /* __KERNEL__ */
3420
3421 /*
3422 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3423 index bca8fdc..61e9580 100644
3424 --- a/arch/powerpc/include/asm/kmap_types.h
3425 +++ b/arch/powerpc/include/asm/kmap_types.h
3426 @@ -27,6 +27,7 @@ enum km_type {
3427 KM_PPC_SYNC_PAGE,
3428 KM_PPC_SYNC_ICACHE,
3429 KM_KDB,
3430 + KM_CLEARPAGE,
3431 KM_TYPE_NR
3432 };
3433
3434 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3435 index d4a7f64..451de1c 100644
3436 --- a/arch/powerpc/include/asm/mman.h
3437 +++ b/arch/powerpc/include/asm/mman.h
3438 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3439 }
3440 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3441
3442 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3443 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3444 {
3445 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3446 }
3447 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3448 index f072e97..b436dee 100644
3449 --- a/arch/powerpc/include/asm/page.h
3450 +++ b/arch/powerpc/include/asm/page.h
3451 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3452 * and needs to be executable. This means the whole heap ends
3453 * up being executable.
3454 */
3455 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3456 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3457 +#define VM_DATA_DEFAULT_FLAGS32 \
3458 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3459 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3460
3461 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3462 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3463 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3464 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3465 #endif
3466
3467 +#define ktla_ktva(addr) (addr)
3468 +#define ktva_ktla(addr) (addr)
3469 +
3470 /*
3471 * Use the top bit of the higher-level page table entries to indicate whether
3472 * the entries we point to contain hugepages. This works because we know that
3473 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3474 index fed85e6..da5c71b 100644
3475 --- a/arch/powerpc/include/asm/page_64.h
3476 +++ b/arch/powerpc/include/asm/page_64.h
3477 @@ -146,15 +146,18 @@ do { \
3478 * stack by default, so in the absence of a PT_GNU_STACK program header
3479 * we turn execute permission off.
3480 */
3481 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3482 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3483 +#define VM_STACK_DEFAULT_FLAGS32 \
3484 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3485 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3486
3487 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3488 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3489
3490 +#ifndef CONFIG_PAX_PAGEEXEC
3491 #define VM_STACK_DEFAULT_FLAGS \
3492 (is_32bit_task() ? \
3493 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3494 +#endif
3495
3496 #include <asm-generic/getorder.h>
3497
3498 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3499 index 2e0e411..7899c68 100644
3500 --- a/arch/powerpc/include/asm/pgtable.h
3501 +++ b/arch/powerpc/include/asm/pgtable.h
3502 @@ -2,6 +2,7 @@
3503 #define _ASM_POWERPC_PGTABLE_H
3504 #ifdef __KERNEL__
3505
3506 +#include <linux/const.h>
3507 #ifndef __ASSEMBLY__
3508 #include <asm/processor.h> /* For TASK_SIZE */
3509 #include <asm/mmu.h>
3510 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3511 index 4aad413..85d86bf 100644
3512 --- a/arch/powerpc/include/asm/pte-hash32.h
3513 +++ b/arch/powerpc/include/asm/pte-hash32.h
3514 @@ -21,6 +21,7 @@
3515 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3516 #define _PAGE_USER 0x004 /* usermode access allowed */
3517 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3518 +#define _PAGE_EXEC _PAGE_GUARDED
3519 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3520 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3521 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3522 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3523 index 7fdc2c0..e47a9b02d3 100644
3524 --- a/arch/powerpc/include/asm/reg.h
3525 +++ b/arch/powerpc/include/asm/reg.h
3526 @@ -212,6 +212,7 @@
3527 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3528 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3529 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3530 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3531 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3532 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3533 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3534 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3535 index c377457..3c69fbc 100644
3536 --- a/arch/powerpc/include/asm/system.h
3537 +++ b/arch/powerpc/include/asm/system.h
3538 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3539 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3540 #endif
3541
3542 -extern unsigned long arch_align_stack(unsigned long sp);
3543 +#define arch_align_stack(x) ((x) & ~0xfUL)
3544
3545 /* Used in very early kernel initialization. */
3546 extern unsigned long reloc_offset(void);
3547 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3548 index bd0fb84..a42a14b 100644
3549 --- a/arch/powerpc/include/asm/uaccess.h
3550 +++ b/arch/powerpc/include/asm/uaccess.h
3551 @@ -13,6 +13,8 @@
3552 #define VERIFY_READ 0
3553 #define VERIFY_WRITE 1
3554
3555 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3556 +
3557 /*
3558 * The fs value determines whether argument validity checking should be
3559 * performed or not. If get_fs() == USER_DS, checking is performed, with
3560 @@ -327,52 +329,6 @@ do { \
3561 extern unsigned long __copy_tofrom_user(void __user *to,
3562 const void __user *from, unsigned long size);
3563
3564 -#ifndef __powerpc64__
3565 -
3566 -static inline unsigned long copy_from_user(void *to,
3567 - const void __user *from, unsigned long n)
3568 -{
3569 - unsigned long over;
3570 -
3571 - if (access_ok(VERIFY_READ, from, n))
3572 - return __copy_tofrom_user((__force void __user *)to, from, n);
3573 - if ((unsigned long)from < TASK_SIZE) {
3574 - over = (unsigned long)from + n - TASK_SIZE;
3575 - return __copy_tofrom_user((__force void __user *)to, from,
3576 - n - over) + over;
3577 - }
3578 - return n;
3579 -}
3580 -
3581 -static inline unsigned long copy_to_user(void __user *to,
3582 - const void *from, unsigned long n)
3583 -{
3584 - unsigned long over;
3585 -
3586 - if (access_ok(VERIFY_WRITE, to, n))
3587 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3588 - if ((unsigned long)to < TASK_SIZE) {
3589 - over = (unsigned long)to + n - TASK_SIZE;
3590 - return __copy_tofrom_user(to, (__force void __user *)from,
3591 - n - over) + over;
3592 - }
3593 - return n;
3594 -}
3595 -
3596 -#else /* __powerpc64__ */
3597 -
3598 -#define __copy_in_user(to, from, size) \
3599 - __copy_tofrom_user((to), (from), (size))
3600 -
3601 -extern unsigned long copy_from_user(void *to, const void __user *from,
3602 - unsigned long n);
3603 -extern unsigned long copy_to_user(void __user *to, const void *from,
3604 - unsigned long n);
3605 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3606 - unsigned long n);
3607 -
3608 -#endif /* __powerpc64__ */
3609 -
3610 static inline unsigned long __copy_from_user_inatomic(void *to,
3611 const void __user *from, unsigned long n)
3612 {
3613 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3614 if (ret == 0)
3615 return 0;
3616 }
3617 +
3618 + if (!__builtin_constant_p(n))
3619 + check_object_size(to, n, false);
3620 +
3621 return __copy_tofrom_user((__force void __user *)to, from, n);
3622 }
3623
3624 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3625 if (ret == 0)
3626 return 0;
3627 }
3628 +
3629 + if (!__builtin_constant_p(n))
3630 + check_object_size(from, n, true);
3631 +
3632 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3633 }
3634
3635 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3636 return __copy_to_user_inatomic(to, from, size);
3637 }
3638
3639 +#ifndef __powerpc64__
3640 +
3641 +static inline unsigned long __must_check copy_from_user(void *to,
3642 + const void __user *from, unsigned long n)
3643 +{
3644 + unsigned long over;
3645 +
3646 + if ((long)n < 0)
3647 + return n;
3648 +
3649 + if (access_ok(VERIFY_READ, from, n)) {
3650 + if (!__builtin_constant_p(n))
3651 + check_object_size(to, n, false);
3652 + return __copy_tofrom_user((__force void __user *)to, from, n);
3653 + }
3654 + if ((unsigned long)from < TASK_SIZE) {
3655 + over = (unsigned long)from + n - TASK_SIZE;
3656 + if (!__builtin_constant_p(n - over))
3657 + check_object_size(to, n - over, false);
3658 + return __copy_tofrom_user((__force void __user *)to, from,
3659 + n - over) + over;
3660 + }
3661 + return n;
3662 +}
3663 +
3664 +static inline unsigned long __must_check copy_to_user(void __user *to,
3665 + const void *from, unsigned long n)
3666 +{
3667 + unsigned long over;
3668 +
3669 + if ((long)n < 0)
3670 + return n;
3671 +
3672 + if (access_ok(VERIFY_WRITE, to, n)) {
3673 + if (!__builtin_constant_p(n))
3674 + check_object_size(from, n, true);
3675 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3676 + }
3677 + if ((unsigned long)to < TASK_SIZE) {
3678 + over = (unsigned long)to + n - TASK_SIZE;
3679 + if (!__builtin_constant_p(n))
3680 + check_object_size(from, n - over, true);
3681 + return __copy_tofrom_user(to, (__force void __user *)from,
3682 + n - over) + over;
3683 + }
3684 + return n;
3685 +}
3686 +
3687 +#else /* __powerpc64__ */
3688 +
3689 +#define __copy_in_user(to, from, size) \
3690 + __copy_tofrom_user((to), (from), (size))
3691 +
3692 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3693 +{
3694 + if ((long)n < 0 || n > INT_MAX)
3695 + return n;
3696 +
3697 + if (!__builtin_constant_p(n))
3698 + check_object_size(to, n, false);
3699 +
3700 + if (likely(access_ok(VERIFY_READ, from, n)))
3701 + n = __copy_from_user(to, from, n);
3702 + else
3703 + memset(to, 0, n);
3704 + return n;
3705 +}
3706 +
3707 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3708 +{
3709 + if ((long)n < 0 || n > INT_MAX)
3710 + return n;
3711 +
3712 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3713 + if (!__builtin_constant_p(n))
3714 + check_object_size(from, n, true);
3715 + n = __copy_to_user(to, from, n);
3716 + }
3717 + return n;
3718 +}
3719 +
3720 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3721 + unsigned long n);
3722 +
3723 +#endif /* __powerpc64__ */
3724 +
3725 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3726
3727 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3728 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3729 index 429983c..7af363b 100644
3730 --- a/arch/powerpc/kernel/exceptions-64e.S
3731 +++ b/arch/powerpc/kernel/exceptions-64e.S
3732 @@ -587,6 +587,7 @@ storage_fault_common:
3733 std r14,_DAR(r1)
3734 std r15,_DSISR(r1)
3735 addi r3,r1,STACK_FRAME_OVERHEAD
3736 + bl .save_nvgprs
3737 mr r4,r14
3738 mr r5,r15
3739 ld r14,PACA_EXGEN+EX_R14(r13)
3740 @@ -596,8 +597,7 @@ storage_fault_common:
3741 cmpdi r3,0
3742 bne- 1f
3743 b .ret_from_except_lite
3744 -1: bl .save_nvgprs
3745 - mr r5,r3
3746 +1: mr r5,r3
3747 addi r3,r1,STACK_FRAME_OVERHEAD
3748 ld r4,_DAR(r1)
3749 bl .bad_page_fault
3750 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3751 index 15c5a4f..22a4000 100644
3752 --- a/arch/powerpc/kernel/exceptions-64s.S
3753 +++ b/arch/powerpc/kernel/exceptions-64s.S
3754 @@ -1004,10 +1004,10 @@ handle_page_fault:
3755 11: ld r4,_DAR(r1)
3756 ld r5,_DSISR(r1)
3757 addi r3,r1,STACK_FRAME_OVERHEAD
3758 + bl .save_nvgprs
3759 bl .do_page_fault
3760 cmpdi r3,0
3761 beq+ 13f
3762 - bl .save_nvgprs
3763 mr r5,r3
3764 addi r3,r1,STACK_FRAME_OVERHEAD
3765 lwz r4,_DAR(r1)
3766 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3767 index 01e2877..a1ba360 100644
3768 --- a/arch/powerpc/kernel/irq.c
3769 +++ b/arch/powerpc/kernel/irq.c
3770 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3771 host->ops = ops;
3772 host->of_node = of_node_get(of_node);
3773
3774 - if (host->ops->match == NULL)
3775 - host->ops->match = default_irq_host_match;
3776 -
3777 raw_spin_lock_irqsave(&irq_big_lock, flags);
3778
3779 /* If it's a legacy controller, check for duplicates and
3780 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3781 */
3782 raw_spin_lock_irqsave(&irq_big_lock, flags);
3783 list_for_each_entry(h, &irq_hosts, link)
3784 - if (h->ops->match(h, node)) {
3785 + if (h->ops->match) {
3786 + if (h->ops->match(h, node)) {
3787 + found = h;
3788 + break;
3789 + }
3790 + } else if (default_irq_host_match(h, node)) {
3791 found = h;
3792 break;
3793 }
3794 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3795 index 0b6d796..d760ddb 100644
3796 --- a/arch/powerpc/kernel/module_32.c
3797 +++ b/arch/powerpc/kernel/module_32.c
3798 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3799 me->arch.core_plt_section = i;
3800 }
3801 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3802 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3803 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3804 return -ENOEXEC;
3805 }
3806
3807 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3808
3809 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3810 /* Init, or core PLT? */
3811 - if (location >= mod->module_core
3812 - && location < mod->module_core + mod->core_size)
3813 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3814 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3815 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3816 - else
3817 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3818 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3819 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3820 + else {
3821 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3822 + return ~0UL;
3823 + }
3824
3825 /* Find this entry, or if that fails, the next avail. entry */
3826 while (entry->jump[0]) {
3827 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3828 index d817ab0..b23b18e 100644
3829 --- a/arch/powerpc/kernel/process.c
3830 +++ b/arch/powerpc/kernel/process.c
3831 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
3832 * Lookup NIP late so we have the best change of getting the
3833 * above info out without failing
3834 */
3835 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3836 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3837 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3838 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3839 #endif
3840 show_stack(current, (unsigned long *) regs->gpr[1]);
3841 if (!user_mode(regs))
3842 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3843 newsp = stack[0];
3844 ip = stack[STACK_FRAME_LR_SAVE];
3845 if (!firstframe || ip != lr) {
3846 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3847 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3848 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3849 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3850 - printk(" (%pS)",
3851 + printk(" (%pA)",
3852 (void *)current->ret_stack[curr_frame].ret);
3853 curr_frame--;
3854 }
3855 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3856 struct pt_regs *regs = (struct pt_regs *)
3857 (sp + STACK_FRAME_OVERHEAD);
3858 lr = regs->link;
3859 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3860 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3861 regs->trap, (void *)regs->nip, (void *)lr);
3862 firstframe = 1;
3863 }
3864 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
3865 }
3866
3867 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3868 -
3869 -unsigned long arch_align_stack(unsigned long sp)
3870 -{
3871 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3872 - sp -= get_random_int() & ~PAGE_MASK;
3873 - return sp & ~0xf;
3874 -}
3875 -
3876 -static inline unsigned long brk_rnd(void)
3877 -{
3878 - unsigned long rnd = 0;
3879 -
3880 - /* 8MB for 32bit, 1GB for 64bit */
3881 - if (is_32bit_task())
3882 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3883 - else
3884 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3885 -
3886 - return rnd << PAGE_SHIFT;
3887 -}
3888 -
3889 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3890 -{
3891 - unsigned long base = mm->brk;
3892 - unsigned long ret;
3893 -
3894 -#ifdef CONFIG_PPC_STD_MMU_64
3895 - /*
3896 - * If we are using 1TB segments and we are allowed to randomise
3897 - * the heap, we can put it above 1TB so it is backed by a 1TB
3898 - * segment. Otherwise the heap will be in the bottom 1TB
3899 - * which always uses 256MB segments and this may result in a
3900 - * performance penalty.
3901 - */
3902 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3903 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3904 -#endif
3905 -
3906 - ret = PAGE_ALIGN(base + brk_rnd());
3907 -
3908 - if (ret < mm->brk)
3909 - return mm->brk;
3910 -
3911 - return ret;
3912 -}
3913 -
3914 -unsigned long randomize_et_dyn(unsigned long base)
3915 -{
3916 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3917 -
3918 - if (ret < base)
3919 - return base;
3920 -
3921 - return ret;
3922 -}
3923 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3924 index 836a5a1..27289a3 100644
3925 --- a/arch/powerpc/kernel/signal_32.c
3926 +++ b/arch/powerpc/kernel/signal_32.c
3927 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3928 /* Save user registers on the stack */
3929 frame = &rt_sf->uc.uc_mcontext;
3930 addr = frame;
3931 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3932 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3933 if (save_user_regs(regs, frame, 0, 1))
3934 goto badframe;
3935 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3936 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3937 index a50b5ec..547078a 100644
3938 --- a/arch/powerpc/kernel/signal_64.c
3939 +++ b/arch/powerpc/kernel/signal_64.c
3940 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3941 current->thread.fpscr.val = 0;
3942
3943 /* Set up to return from userspace. */
3944 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3945 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3946 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3947 } else {
3948 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3949 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3950 index c091527..5592625 100644
3951 --- a/arch/powerpc/kernel/traps.c
3952 +++ b/arch/powerpc/kernel/traps.c
3953 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
3954 return flags;
3955 }
3956
3957 +extern void gr_handle_kernel_exploit(void);
3958 +
3959 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3960 int signr)
3961 {
3962 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3963 panic("Fatal exception in interrupt");
3964 if (panic_on_oops)
3965 panic("Fatal exception");
3966 +
3967 + gr_handle_kernel_exploit();
3968 +
3969 do_exit(signr);
3970 }
3971
3972 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3973 index 7d14bb6..1305601 100644
3974 --- a/arch/powerpc/kernel/vdso.c
3975 +++ b/arch/powerpc/kernel/vdso.c
3976 @@ -35,6 +35,7 @@
3977 #include <asm/firmware.h>
3978 #include <asm/vdso.h>
3979 #include <asm/vdso_datapage.h>
3980 +#include <asm/mman.h>
3981
3982 #include "setup.h"
3983
3984 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3985 vdso_base = VDSO32_MBASE;
3986 #endif
3987
3988 - current->mm->context.vdso_base = 0;
3989 + current->mm->context.vdso_base = ~0UL;
3990
3991 /* vDSO has a problem and was disabled, just don't "enable" it for the
3992 * process
3993 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3994 vdso_base = get_unmapped_area(NULL, vdso_base,
3995 (vdso_pages << PAGE_SHIFT) +
3996 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3997 - 0, 0);
3998 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3999 if (IS_ERR_VALUE(vdso_base)) {
4000 rc = vdso_base;
4001 goto fail_mmapsem;
4002 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4003 index 5eea6f3..5d10396 100644
4004 --- a/arch/powerpc/lib/usercopy_64.c
4005 +++ b/arch/powerpc/lib/usercopy_64.c
4006 @@ -9,22 +9,6 @@
4007 #include <linux/module.h>
4008 #include <asm/uaccess.h>
4009
4010 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4011 -{
4012 - if (likely(access_ok(VERIFY_READ, from, n)))
4013 - n = __copy_from_user(to, from, n);
4014 - else
4015 - memset(to, 0, n);
4016 - return n;
4017 -}
4018 -
4019 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4020 -{
4021 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4022 - n = __copy_to_user(to, from, n);
4023 - return n;
4024 -}
4025 -
4026 unsigned long copy_in_user(void __user *to, const void __user *from,
4027 unsigned long n)
4028 {
4029 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4030 return n;
4031 }
4032
4033 -EXPORT_SYMBOL(copy_from_user);
4034 -EXPORT_SYMBOL(copy_to_user);
4035 EXPORT_SYMBOL(copy_in_user);
4036
4037 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4038 index 2f0d1b0..36fb5cc 100644
4039 --- a/arch/powerpc/mm/fault.c
4040 +++ b/arch/powerpc/mm/fault.c
4041 @@ -32,6 +32,10 @@
4042 #include <linux/perf_event.h>
4043 #include <linux/magic.h>
4044 #include <linux/ratelimit.h>
4045 +#include <linux/slab.h>
4046 +#include <linux/pagemap.h>
4047 +#include <linux/compiler.h>
4048 +#include <linux/unistd.h>
4049
4050 #include <asm/firmware.h>
4051 #include <asm/page.h>
4052 @@ -43,6 +47,7 @@
4053 #include <asm/tlbflush.h>
4054 #include <asm/siginfo.h>
4055 #include <mm/mmu_decl.h>
4056 +#include <asm/ptrace.h>
4057
4058 #include "icswx.h"
4059
4060 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4061 }
4062 #endif
4063
4064 +#ifdef CONFIG_PAX_PAGEEXEC
4065 +/*
4066 + * PaX: decide what to do with offenders (regs->nip = fault address)
4067 + *
4068 + * returns 1 when task should be killed
4069 + */
4070 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4071 +{
4072 + return 1;
4073 +}
4074 +
4075 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4076 +{
4077 + unsigned long i;
4078 +
4079 + printk(KERN_ERR "PAX: bytes at PC: ");
4080 + for (i = 0; i < 5; i++) {
4081 + unsigned int c;
4082 + if (get_user(c, (unsigned int __user *)pc+i))
4083 + printk(KERN_CONT "???????? ");
4084 + else
4085 + printk(KERN_CONT "%08x ", c);
4086 + }
4087 + printk("\n");
4088 +}
4089 +#endif
4090 +
4091 /*
4092 * Check whether the instruction at regs->nip is a store using
4093 * an update addressing form which will update r1.
4094 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4095 * indicate errors in DSISR but can validly be set in SRR1.
4096 */
4097 if (trap == 0x400)
4098 - error_code &= 0x48200000;
4099 + error_code &= 0x58200000;
4100 else
4101 is_write = error_code & DSISR_ISSTORE;
4102 #else
4103 @@ -276,7 +308,7 @@ good_area:
4104 * "undefined". Of those that can be set, this is the only
4105 * one which seems bad.
4106 */
4107 - if (error_code & 0x10000000)
4108 + if (error_code & DSISR_GUARDED)
4109 /* Guarded storage error. */
4110 goto bad_area;
4111 #endif /* CONFIG_8xx */
4112 @@ -291,7 +323,7 @@ good_area:
4113 * processors use the same I/D cache coherency mechanism
4114 * as embedded.
4115 */
4116 - if (error_code & DSISR_PROTFAULT)
4117 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4118 goto bad_area;
4119 #endif /* CONFIG_PPC_STD_MMU */
4120
4121 @@ -360,6 +392,23 @@ bad_area:
4122 bad_area_nosemaphore:
4123 /* User mode accesses cause a SIGSEGV */
4124 if (user_mode(regs)) {
4125 +
4126 +#ifdef CONFIG_PAX_PAGEEXEC
4127 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4128 +#ifdef CONFIG_PPC_STD_MMU
4129 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4130 +#else
4131 + if (is_exec && regs->nip == address) {
4132 +#endif
4133 + switch (pax_handle_fetch_fault(regs)) {
4134 + }
4135 +
4136 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4137 + do_group_exit(SIGKILL);
4138 + }
4139 + }
4140 +#endif
4141 +
4142 _exception(SIGSEGV, regs, code, address);
4143 return 0;
4144 }
4145 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4146 index 67a42ed..1c7210c 100644
4147 --- a/arch/powerpc/mm/mmap_64.c
4148 +++ b/arch/powerpc/mm/mmap_64.c
4149 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4150 */
4151 if (mmap_is_legacy()) {
4152 mm->mmap_base = TASK_UNMAPPED_BASE;
4153 +
4154 +#ifdef CONFIG_PAX_RANDMMAP
4155 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4156 + mm->mmap_base += mm->delta_mmap;
4157 +#endif
4158 +
4159 mm->get_unmapped_area = arch_get_unmapped_area;
4160 mm->unmap_area = arch_unmap_area;
4161 } else {
4162 mm->mmap_base = mmap_base();
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4170 mm->unmap_area = arch_unmap_area_topdown;
4171 }
4172 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4173 index 73709f7..6b90313 100644
4174 --- a/arch/powerpc/mm/slice.c
4175 +++ b/arch/powerpc/mm/slice.c
4176 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4177 if ((mm->task_size - len) < addr)
4178 return 0;
4179 vma = find_vma(mm, addr);
4180 - return (!vma || (addr + len) <= vma->vm_start);
4181 + return check_heap_stack_gap(vma, addr, len);
4182 }
4183
4184 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4185 @@ -256,7 +256,7 @@ full_search:
4186 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4187 continue;
4188 }
4189 - if (!vma || addr + len <= vma->vm_start) {
4190 + if (check_heap_stack_gap(vma, addr, len)) {
4191 /*
4192 * Remember the place where we stopped the search:
4193 */
4194 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4195 }
4196 }
4197
4198 - addr = mm->mmap_base;
4199 - while (addr > len) {
4200 + if (mm->mmap_base < len)
4201 + addr = -ENOMEM;
4202 + else
4203 + addr = mm->mmap_base - len;
4204 +
4205 + while (!IS_ERR_VALUE(addr)) {
4206 /* Go down by chunk size */
4207 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4208 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4209
4210 /* Check for hit with different page size */
4211 mask = slice_range_to_mask(addr, len);
4212 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4213 * return with success:
4214 */
4215 vma = find_vma(mm, addr);
4216 - if (!vma || (addr + len) <= vma->vm_start) {
4217 + if (check_heap_stack_gap(vma, addr, len)) {
4218 /* remember the address as a hint for next time */
4219 if (use_cache)
4220 mm->free_area_cache = addr;
4221 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4222 mm->cached_hole_size = vma->vm_start - addr;
4223
4224 /* try just below the current vma->vm_start */
4225 - addr = vma->vm_start;
4226 + addr = skip_heap_stack_gap(vma, len);
4227 }
4228
4229 /*
4230 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4231 if (fixed && addr > (mm->task_size - len))
4232 return -EINVAL;
4233
4234 +#ifdef CONFIG_PAX_RANDMMAP
4235 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4236 + addr = 0;
4237 +#endif
4238 +
4239 /* If hint, make sure it matches our alignment restrictions */
4240 if (!fixed && addr) {
4241 addr = _ALIGN_UP(addr, 1ul << pshift);
4242 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4243 index 8517d2a..d2738d4 100644
4244 --- a/arch/s390/include/asm/atomic.h
4245 +++ b/arch/s390/include/asm/atomic.h
4246 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4247 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4248 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4249
4250 +#define atomic64_read_unchecked(v) atomic64_read(v)
4251 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4252 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4253 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4254 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4255 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4256 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4257 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4258 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4259 +
4260 #define smp_mb__before_atomic_dec() smp_mb()
4261 #define smp_mb__after_atomic_dec() smp_mb()
4262 #define smp_mb__before_atomic_inc() smp_mb()
4263 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4264 index 2a30d5a..5e5586f 100644
4265 --- a/arch/s390/include/asm/cache.h
4266 +++ b/arch/s390/include/asm/cache.h
4267 @@ -11,8 +11,10 @@
4268 #ifndef __ARCH_S390_CACHE_H
4269 #define __ARCH_S390_CACHE_H
4270
4271 -#define L1_CACHE_BYTES 256
4272 +#include <linux/const.h>
4273 +
4274 #define L1_CACHE_SHIFT 8
4275 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4276 #define NET_SKB_PAD 32
4277
4278 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4279 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4280 index 547f1a6..0b22b53 100644
4281 --- a/arch/s390/include/asm/elf.h
4282 +++ b/arch/s390/include/asm/elf.h
4283 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4284 the loader. We need to make sure that it is out of the way of the program
4285 that it will "exec", and that there is sufficient room for the brk. */
4286
4287 -extern unsigned long randomize_et_dyn(unsigned long base);
4288 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4289 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4290 +
4291 +#ifdef CONFIG_PAX_ASLR
4292 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4293 +
4294 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4295 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4296 +#endif
4297
4298 /* This yields a mask that user programs can use to figure out what
4299 instruction set this CPU supports. */
4300 @@ -211,7 +217,4 @@ struct linux_binprm;
4301 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4302 int arch_setup_additional_pages(struct linux_binprm *, int);
4303
4304 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4305 -#define arch_randomize_brk arch_randomize_brk
4306 -
4307 #endif
4308 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4309 index d73cc6b..1a296ad 100644
4310 --- a/arch/s390/include/asm/system.h
4311 +++ b/arch/s390/include/asm/system.h
4312 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4313 extern void (*_machine_halt)(void);
4314 extern void (*_machine_power_off)(void);
4315
4316 -extern unsigned long arch_align_stack(unsigned long sp);
4317 +#define arch_align_stack(x) ((x) & ~0xfUL)
4318
4319 static inline int tprot(unsigned long addr)
4320 {
4321 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4322 index 2b23885..e136e31 100644
4323 --- a/arch/s390/include/asm/uaccess.h
4324 +++ b/arch/s390/include/asm/uaccess.h
4325 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4326 copy_to_user(void __user *to, const void *from, unsigned long n)
4327 {
4328 might_fault();
4329 +
4330 + if ((long)n < 0)
4331 + return n;
4332 +
4333 if (access_ok(VERIFY_WRITE, to, n))
4334 n = __copy_to_user(to, from, n);
4335 return n;
4336 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4337 static inline unsigned long __must_check
4338 __copy_from_user(void *to, const void __user *from, unsigned long n)
4339 {
4340 + if ((long)n < 0)
4341 + return n;
4342 +
4343 if (__builtin_constant_p(n) && (n <= 256))
4344 return uaccess.copy_from_user_small(n, from, to);
4345 else
4346 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4347 unsigned int sz = __compiletime_object_size(to);
4348
4349 might_fault();
4350 +
4351 + if ((long)n < 0)
4352 + return n;
4353 +
4354 if (unlikely(sz != -1 && sz < n)) {
4355 copy_from_user_overflow();
4356 return n;
4357 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4358 index dfcb343..eda788a 100644
4359 --- a/arch/s390/kernel/module.c
4360 +++ b/arch/s390/kernel/module.c
4361 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4362
4363 /* Increase core size by size of got & plt and set start
4364 offsets for got and plt. */
4365 - me->core_size = ALIGN(me->core_size, 4);
4366 - me->arch.got_offset = me->core_size;
4367 - me->core_size += me->arch.got_size;
4368 - me->arch.plt_offset = me->core_size;
4369 - me->core_size += me->arch.plt_size;
4370 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4371 + me->arch.got_offset = me->core_size_rw;
4372 + me->core_size_rw += me->arch.got_size;
4373 + me->arch.plt_offset = me->core_size_rx;
4374 + me->core_size_rx += me->arch.plt_size;
4375 return 0;
4376 }
4377
4378 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4379 if (info->got_initialized == 0) {
4380 Elf_Addr *gotent;
4381
4382 - gotent = me->module_core + me->arch.got_offset +
4383 + gotent = me->module_core_rw + me->arch.got_offset +
4384 info->got_offset;
4385 *gotent = val;
4386 info->got_initialized = 1;
4387 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4388 else if (r_type == R_390_GOTENT ||
4389 r_type == R_390_GOTPLTENT)
4390 *(unsigned int *) loc =
4391 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4392 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4393 else if (r_type == R_390_GOT64 ||
4394 r_type == R_390_GOTPLT64)
4395 *(unsigned long *) loc = val;
4396 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4397 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4398 if (info->plt_initialized == 0) {
4399 unsigned int *ip;
4400 - ip = me->module_core + me->arch.plt_offset +
4401 + ip = me->module_core_rx + me->arch.plt_offset +
4402 info->plt_offset;
4403 #ifndef CONFIG_64BIT
4404 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4405 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4406 val - loc + 0xffffUL < 0x1ffffeUL) ||
4407 (r_type == R_390_PLT32DBL &&
4408 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4409 - val = (Elf_Addr) me->module_core +
4410 + val = (Elf_Addr) me->module_core_rx +
4411 me->arch.plt_offset +
4412 info->plt_offset;
4413 val += rela->r_addend - loc;
4414 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4415 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4416 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4417 val = val + rela->r_addend -
4418 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4419 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4420 if (r_type == R_390_GOTOFF16)
4421 *(unsigned short *) loc = val;
4422 else if (r_type == R_390_GOTOFF32)
4423 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4424 break;
4425 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4426 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4427 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4428 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4429 rela->r_addend - loc;
4430 if (r_type == R_390_GOTPC)
4431 *(unsigned int *) loc = val;
4432 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4433 index e795933..b32563c 100644
4434 --- a/arch/s390/kernel/process.c
4435 +++ b/arch/s390/kernel/process.c
4436 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4437 }
4438 return 0;
4439 }
4440 -
4441 -unsigned long arch_align_stack(unsigned long sp)
4442 -{
4443 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4444 - sp -= get_random_int() & ~PAGE_MASK;
4445 - return sp & ~0xf;
4446 -}
4447 -
4448 -static inline unsigned long brk_rnd(void)
4449 -{
4450 - /* 8MB for 32bit, 1GB for 64bit */
4451 - if (is_32bit_task())
4452 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4453 - else
4454 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4455 -}
4456 -
4457 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4458 -{
4459 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4460 -
4461 - if (ret < mm->brk)
4462 - return mm->brk;
4463 - return ret;
4464 -}
4465 -
4466 -unsigned long randomize_et_dyn(unsigned long base)
4467 -{
4468 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4469 -
4470 - if (!(current->flags & PF_RANDOMIZE))
4471 - return base;
4472 - if (ret < base)
4473 - return base;
4474 - return ret;
4475 -}
4476 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4477 index a0155c0..34cc491 100644
4478 --- a/arch/s390/mm/mmap.c
4479 +++ b/arch/s390/mm/mmap.c
4480 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4481 */
4482 if (mmap_is_legacy()) {
4483 mm->mmap_base = TASK_UNMAPPED_BASE;
4484 +
4485 +#ifdef CONFIG_PAX_RANDMMAP
4486 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4487 + mm->mmap_base += mm->delta_mmap;
4488 +#endif
4489 +
4490 mm->get_unmapped_area = arch_get_unmapped_area;
4491 mm->unmap_area = arch_unmap_area;
4492 } else {
4493 mm->mmap_base = mmap_base();
4494 +
4495 +#ifdef CONFIG_PAX_RANDMMAP
4496 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4497 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4498 +#endif
4499 +
4500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4501 mm->unmap_area = arch_unmap_area_topdown;
4502 }
4503 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4504 */
4505 if (mmap_is_legacy()) {
4506 mm->mmap_base = TASK_UNMAPPED_BASE;
4507 +
4508 +#ifdef CONFIG_PAX_RANDMMAP
4509 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4510 + mm->mmap_base += mm->delta_mmap;
4511 +#endif
4512 +
4513 mm->get_unmapped_area = s390_get_unmapped_area;
4514 mm->unmap_area = arch_unmap_area;
4515 } else {
4516 mm->mmap_base = mmap_base();
4517 +
4518 +#ifdef CONFIG_PAX_RANDMMAP
4519 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4520 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4521 +#endif
4522 +
4523 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4524 mm->unmap_area = arch_unmap_area_topdown;
4525 }
4526 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4527 index ae3d59f..f65f075 100644
4528 --- a/arch/score/include/asm/cache.h
4529 +++ b/arch/score/include/asm/cache.h
4530 @@ -1,7 +1,9 @@
4531 #ifndef _ASM_SCORE_CACHE_H
4532 #define _ASM_SCORE_CACHE_H
4533
4534 +#include <linux/const.h>
4535 +
4536 #define L1_CACHE_SHIFT 4
4537 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4538 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4539
4540 #endif /* _ASM_SCORE_CACHE_H */
4541 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4542 index 589d5c7..669e274 100644
4543 --- a/arch/score/include/asm/system.h
4544 +++ b/arch/score/include/asm/system.h
4545 @@ -17,7 +17,7 @@ do { \
4546 #define finish_arch_switch(prev) do {} while (0)
4547
4548 typedef void (*vi_handler_t)(void);
4549 -extern unsigned long arch_align_stack(unsigned long sp);
4550 +#define arch_align_stack(x) (x)
4551
4552 #define mb() barrier()
4553 #define rmb() barrier()
4554 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4555 index 25d0803..d6c8e36 100644
4556 --- a/arch/score/kernel/process.c
4557 +++ b/arch/score/kernel/process.c
4558 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4559
4560 return task_pt_regs(task)->cp0_epc;
4561 }
4562 -
4563 -unsigned long arch_align_stack(unsigned long sp)
4564 -{
4565 - return sp;
4566 -}
4567 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4568 index ef9e555..331bd29 100644
4569 --- a/arch/sh/include/asm/cache.h
4570 +++ b/arch/sh/include/asm/cache.h
4571 @@ -9,10 +9,11 @@
4572 #define __ASM_SH_CACHE_H
4573 #ifdef __KERNEL__
4574
4575 +#include <linux/const.h>
4576 #include <linux/init.h>
4577 #include <cpu/cache.h>
4578
4579 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4580 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4581
4582 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4583
4584 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4585 index afeb710..d1d1289 100644
4586 --- a/arch/sh/mm/mmap.c
4587 +++ b/arch/sh/mm/mmap.c
4588 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4589 addr = PAGE_ALIGN(addr);
4590
4591 vma = find_vma(mm, addr);
4592 - if (TASK_SIZE - len >= addr &&
4593 - (!vma || addr + len <= vma->vm_start))
4594 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4595 return addr;
4596 }
4597
4598 @@ -106,7 +105,7 @@ full_search:
4599 }
4600 return -ENOMEM;
4601 }
4602 - if (likely(!vma || addr + len <= vma->vm_start)) {
4603 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4604 /*
4605 * Remember the place where we stopped the search:
4606 */
4607 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4608 addr = PAGE_ALIGN(addr);
4609
4610 vma = find_vma(mm, addr);
4611 - if (TASK_SIZE - len >= addr &&
4612 - (!vma || addr + len <= vma->vm_start))
4613 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4614 return addr;
4615 }
4616
4617 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4618 /* make sure it can fit in the remaining address space */
4619 if (likely(addr > len)) {
4620 vma = find_vma(mm, addr-len);
4621 - if (!vma || addr <= vma->vm_start) {
4622 + if (check_heap_stack_gap(vma, addr - len, len)) {
4623 /* remember the address as a hint for next time */
4624 return (mm->free_area_cache = addr-len);
4625 }
4626 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4627 if (unlikely(mm->mmap_base < len))
4628 goto bottomup;
4629
4630 - addr = mm->mmap_base-len;
4631 - if (do_colour_align)
4632 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4633 + addr = mm->mmap_base - len;
4634
4635 do {
4636 + if (do_colour_align)
4637 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4638 /*
4639 * Lookup failure means no vma is above this address,
4640 * else if new region fits below vma->vm_start,
4641 * return with success:
4642 */
4643 vma = find_vma(mm, addr);
4644 - if (likely(!vma || addr+len <= vma->vm_start)) {
4645 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4646 /* remember the address as a hint for next time */
4647 return (mm->free_area_cache = addr);
4648 }
4649 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4650 mm->cached_hole_size = vma->vm_start - addr;
4651
4652 /* try just below the current vma->vm_start */
4653 - addr = vma->vm_start-len;
4654 - if (do_colour_align)
4655 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4656 - } while (likely(len < vma->vm_start));
4657 + addr = skip_heap_stack_gap(vma, len);
4658 + } while (!IS_ERR_VALUE(addr));
4659
4660 bottomup:
4661 /*
4662 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4663 index eddcfb3..b117d90 100644
4664 --- a/arch/sparc/Makefile
4665 +++ b/arch/sparc/Makefile
4666 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4667 # Export what is needed by arch/sparc/boot/Makefile
4668 export VMLINUX_INIT VMLINUX_MAIN
4669 VMLINUX_INIT := $(head-y) $(init-y)
4670 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4671 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4672 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4673 VMLINUX_MAIN += $(drivers-y) $(net-y)
4674
4675 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4676 index 9f421df..b81fc12 100644
4677 --- a/arch/sparc/include/asm/atomic_64.h
4678 +++ b/arch/sparc/include/asm/atomic_64.h
4679 @@ -14,18 +14,40 @@
4680 #define ATOMIC64_INIT(i) { (i) }
4681
4682 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4683 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4684 +{
4685 + return v->counter;
4686 +}
4687 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4688 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4689 +{
4690 + return v->counter;
4691 +}
4692
4693 #define atomic_set(v, i) (((v)->counter) = i)
4694 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4695 +{
4696 + v->counter = i;
4697 +}
4698 #define atomic64_set(v, i) (((v)->counter) = i)
4699 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4700 +{
4701 + v->counter = i;
4702 +}
4703
4704 extern void atomic_add(int, atomic_t *);
4705 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4706 extern void atomic64_add(long, atomic64_t *);
4707 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4708 extern void atomic_sub(int, atomic_t *);
4709 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4710 extern void atomic64_sub(long, atomic64_t *);
4711 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4712
4713 extern int atomic_add_ret(int, atomic_t *);
4714 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4715 extern long atomic64_add_ret(long, atomic64_t *);
4716 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4717 extern int atomic_sub_ret(int, atomic_t *);
4718 extern long atomic64_sub_ret(long, atomic64_t *);
4719
4720 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4721 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4722
4723 #define atomic_inc_return(v) atomic_add_ret(1, v)
4724 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4725 +{
4726 + return atomic_add_ret_unchecked(1, v);
4727 +}
4728 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4729 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4730 +{
4731 + return atomic64_add_ret_unchecked(1, v);
4732 +}
4733
4734 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4735 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4736
4737 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4738 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4739 +{
4740 + return atomic_add_ret_unchecked(i, v);
4741 +}
4742 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4743 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4744 +{
4745 + return atomic64_add_ret_unchecked(i, v);
4746 +}
4747
4748 /*
4749 * atomic_inc_and_test - increment and test
4750 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4751 * other cases.
4752 */
4753 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4754 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4755 +{
4756 + return atomic_inc_return_unchecked(v) == 0;
4757 +}
4758 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4759
4760 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4761 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4762 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4763
4764 #define atomic_inc(v) atomic_add(1, v)
4765 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4766 +{
4767 + atomic_add_unchecked(1, v);
4768 +}
4769 #define atomic64_inc(v) atomic64_add(1, v)
4770 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4771 +{
4772 + atomic64_add_unchecked(1, v);
4773 +}
4774
4775 #define atomic_dec(v) atomic_sub(1, v)
4776 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4777 +{
4778 + atomic_sub_unchecked(1, v);
4779 +}
4780 #define atomic64_dec(v) atomic64_sub(1, v)
4781 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4782 +{
4783 + atomic64_sub_unchecked(1, v);
4784 +}
4785
4786 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4787 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4788
4789 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4790 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4791 +{
4792 + return cmpxchg(&v->counter, old, new);
4793 +}
4794 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4795 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4796 +{
4797 + return xchg(&v->counter, new);
4798 +}
4799
4800 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4801 {
4802 - int c, old;
4803 + int c, old, new;
4804 c = atomic_read(v);
4805 for (;;) {
4806 - if (unlikely(c == (u)))
4807 + if (unlikely(c == u))
4808 break;
4809 - old = atomic_cmpxchg((v), c, c + (a));
4810 +
4811 + asm volatile("addcc %2, %0, %0\n"
4812 +
4813 +#ifdef CONFIG_PAX_REFCOUNT
4814 + "tvs %%icc, 6\n"
4815 +#endif
4816 +
4817 + : "=r" (new)
4818 + : "0" (c), "ir" (a)
4819 + : "cc");
4820 +
4821 + old = atomic_cmpxchg(v, c, new);
4822 if (likely(old == c))
4823 break;
4824 c = old;
4825 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4826 #define atomic64_cmpxchg(v, o, n) \
4827 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4828 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4829 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4830 +{
4831 + return xchg(&v->counter, new);
4832 +}
4833
4834 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4835 {
4836 - long c, old;
4837 + long c, old, new;
4838 c = atomic64_read(v);
4839 for (;;) {
4840 - if (unlikely(c == (u)))
4841 + if (unlikely(c == u))
4842 break;
4843 - old = atomic64_cmpxchg((v), c, c + (a));
4844 +
4845 + asm volatile("addcc %2, %0, %0\n"
4846 +
4847 +#ifdef CONFIG_PAX_REFCOUNT
4848 + "tvs %%xcc, 6\n"
4849 +#endif
4850 +
4851 + : "=r" (new)
4852 + : "0" (c), "ir" (a)
4853 + : "cc");
4854 +
4855 + old = atomic64_cmpxchg(v, c, new);
4856 if (likely(old == c))
4857 break;
4858 c = old;
4859 }
4860 - return c != (u);
4861 + return c != u;
4862 }
4863
4864 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4865 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4866 index 69358b5..9d0d492 100644
4867 --- a/arch/sparc/include/asm/cache.h
4868 +++ b/arch/sparc/include/asm/cache.h
4869 @@ -7,10 +7,12 @@
4870 #ifndef _SPARC_CACHE_H
4871 #define _SPARC_CACHE_H
4872
4873 +#include <linux/const.h>
4874 +
4875 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4876
4877 #define L1_CACHE_SHIFT 5
4878 -#define L1_CACHE_BYTES 32
4879 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4880
4881 #ifdef CONFIG_SPARC32
4882 #define SMP_CACHE_BYTES_SHIFT 5
4883 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4884 index 4269ca6..e3da77f 100644
4885 --- a/arch/sparc/include/asm/elf_32.h
4886 +++ b/arch/sparc/include/asm/elf_32.h
4887 @@ -114,6 +114,13 @@ typedef struct {
4888
4889 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4890
4891 +#ifdef CONFIG_PAX_ASLR
4892 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4893 +
4894 +#define PAX_DELTA_MMAP_LEN 16
4895 +#define PAX_DELTA_STACK_LEN 16
4896 +#endif
4897 +
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this cpu supports. This can NOT be done in userspace
4900 on Sparc. */
4901 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4902 index 7df8b7f..4946269 100644
4903 --- a/arch/sparc/include/asm/elf_64.h
4904 +++ b/arch/sparc/include/asm/elf_64.h
4905 @@ -180,6 +180,13 @@ typedef struct {
4906 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4907 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4908
4909 +#ifdef CONFIG_PAX_ASLR
4910 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4911 +
4912 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4913 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4914 +#endif
4915 +
4916 extern unsigned long sparc64_elf_hwcap;
4917 #define ELF_HWCAP sparc64_elf_hwcap
4918
4919 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4920 index a790cc6..091ed94 100644
4921 --- a/arch/sparc/include/asm/pgtable_32.h
4922 +++ b/arch/sparc/include/asm/pgtable_32.h
4923 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4924 BTFIXUPDEF_INT(page_none)
4925 BTFIXUPDEF_INT(page_copy)
4926 BTFIXUPDEF_INT(page_readonly)
4927 +
4928 +#ifdef CONFIG_PAX_PAGEEXEC
4929 +BTFIXUPDEF_INT(page_shared_noexec)
4930 +BTFIXUPDEF_INT(page_copy_noexec)
4931 +BTFIXUPDEF_INT(page_readonly_noexec)
4932 +#endif
4933 +
4934 BTFIXUPDEF_INT(page_kernel)
4935
4936 #define PMD_SHIFT SUN4C_PMD_SHIFT
4937 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4938 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4939 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4940
4941 +#ifdef CONFIG_PAX_PAGEEXEC
4942 +extern pgprot_t PAGE_SHARED_NOEXEC;
4943 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4944 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4945 +#else
4946 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4947 +# define PAGE_COPY_NOEXEC PAGE_COPY
4948 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4949 +#endif
4950 +
4951 extern unsigned long page_kernel;
4952
4953 #ifdef MODULE
4954 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4955 index f6ae2b2..b03ffc7 100644
4956 --- a/arch/sparc/include/asm/pgtsrmmu.h
4957 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4958 @@ -115,6 +115,13 @@
4959 SRMMU_EXEC | SRMMU_REF)
4960 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4961 SRMMU_EXEC | SRMMU_REF)
4962 +
4963 +#ifdef CONFIG_PAX_PAGEEXEC
4964 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4965 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4966 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4967 +#endif
4968 +
4969 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4970 SRMMU_DIRTY | SRMMU_REF)
4971
4972 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4973 index 9689176..63c18ea 100644
4974 --- a/arch/sparc/include/asm/spinlock_64.h
4975 +++ b/arch/sparc/include/asm/spinlock_64.h
4976 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4977
4978 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4979
4980 -static void inline arch_read_lock(arch_rwlock_t *lock)
4981 +static inline void arch_read_lock(arch_rwlock_t *lock)
4982 {
4983 unsigned long tmp1, tmp2;
4984
4985 __asm__ __volatile__ (
4986 "1: ldsw [%2], %0\n"
4987 " brlz,pn %0, 2f\n"
4988 -"4: add %0, 1, %1\n"
4989 +"4: addcc %0, 1, %1\n"
4990 +
4991 +#ifdef CONFIG_PAX_REFCOUNT
4992 +" tvs %%icc, 6\n"
4993 +#endif
4994 +
4995 " cas [%2], %0, %1\n"
4996 " cmp %0, %1\n"
4997 " bne,pn %%icc, 1b\n"
4998 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
4999 " .previous"
5000 : "=&r" (tmp1), "=&r" (tmp2)
5001 : "r" (lock)
5002 - : "memory");
5003 + : "memory", "cc");
5004 }
5005
5006 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5007 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5008 {
5009 int tmp1, tmp2;
5010
5011 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5012 "1: ldsw [%2], %0\n"
5013 " brlz,a,pn %0, 2f\n"
5014 " mov 0, %0\n"
5015 -" add %0, 1, %1\n"
5016 +" addcc %0, 1, %1\n"
5017 +
5018 +#ifdef CONFIG_PAX_REFCOUNT
5019 +" tvs %%icc, 6\n"
5020 +#endif
5021 +
5022 " cas [%2], %0, %1\n"
5023 " cmp %0, %1\n"
5024 " bne,pn %%icc, 1b\n"
5025 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5026 return tmp1;
5027 }
5028
5029 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5030 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5031 {
5032 unsigned long tmp1, tmp2;
5033
5034 __asm__ __volatile__(
5035 "1: lduw [%2], %0\n"
5036 -" sub %0, 1, %1\n"
5037 +" subcc %0, 1, %1\n"
5038 +
5039 +#ifdef CONFIG_PAX_REFCOUNT
5040 +" tvs %%icc, 6\n"
5041 +#endif
5042 +
5043 " cas [%2], %0, %1\n"
5044 " cmp %0, %1\n"
5045 " bne,pn %%xcc, 1b\n"
5046 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5047 : "memory");
5048 }
5049
5050 -static void inline arch_write_lock(arch_rwlock_t *lock)
5051 +static inline void arch_write_lock(arch_rwlock_t *lock)
5052 {
5053 unsigned long mask, tmp1, tmp2;
5054
5055 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5056 : "memory");
5057 }
5058
5059 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5060 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5061 {
5062 __asm__ __volatile__(
5063 " stw %%g0, [%0]"
5064 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5065 : "memory");
5066 }
5067
5068 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5069 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5070 {
5071 unsigned long mask, tmp1, tmp2, result;
5072
5073 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5074 index c2a1080..21ed218 100644
5075 --- a/arch/sparc/include/asm/thread_info_32.h
5076 +++ b/arch/sparc/include/asm/thread_info_32.h
5077 @@ -50,6 +50,8 @@ struct thread_info {
5078 unsigned long w_saved;
5079
5080 struct restart_block restart_block;
5081 +
5082 + unsigned long lowest_stack;
5083 };
5084
5085 /*
5086 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5087 index 01d057f..0a02f7e 100644
5088 --- a/arch/sparc/include/asm/thread_info_64.h
5089 +++ b/arch/sparc/include/asm/thread_info_64.h
5090 @@ -63,6 +63,8 @@ struct thread_info {
5091 struct pt_regs *kern_una_regs;
5092 unsigned int kern_una_insn;
5093
5094 + unsigned long lowest_stack;
5095 +
5096 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5097 };
5098
5099 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5100 index e88fbe5..96b0ce5 100644
5101 --- a/arch/sparc/include/asm/uaccess.h
5102 +++ b/arch/sparc/include/asm/uaccess.h
5103 @@ -1,5 +1,13 @@
5104 #ifndef ___ASM_SPARC_UACCESS_H
5105 #define ___ASM_SPARC_UACCESS_H
5106 +
5107 +#ifdef __KERNEL__
5108 +#ifndef __ASSEMBLY__
5109 +#include <linux/types.h>
5110 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5111 +#endif
5112 +#endif
5113 +
5114 #if defined(__sparc__) && defined(__arch64__)
5115 #include <asm/uaccess_64.h>
5116 #else
5117 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5118 index 8303ac4..07f333d 100644
5119 --- a/arch/sparc/include/asm/uaccess_32.h
5120 +++ b/arch/sparc/include/asm/uaccess_32.h
5121 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5122
5123 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5124 {
5125 - if (n && __access_ok((unsigned long) to, n))
5126 + if ((long)n < 0)
5127 + return n;
5128 +
5129 + if (n && __access_ok((unsigned long) to, n)) {
5130 + if (!__builtin_constant_p(n))
5131 + check_object_size(from, n, true);
5132 return __copy_user(to, (__force void __user *) from, n);
5133 - else
5134 + } else
5135 return n;
5136 }
5137
5138 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5139 {
5140 + if ((long)n < 0)
5141 + return n;
5142 +
5143 + if (!__builtin_constant_p(n))
5144 + check_object_size(from, n, true);
5145 +
5146 return __copy_user(to, (__force void __user *) from, n);
5147 }
5148
5149 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5150 {
5151 - if (n && __access_ok((unsigned long) from, n))
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (n && __access_ok((unsigned long) from, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(to, n, false);
5158 return __copy_user((__force void __user *) to, from, n);
5159 - else
5160 + } else
5161 return n;
5162 }
5163
5164 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5165 {
5166 + if ((long)n < 0)
5167 + return n;
5168 +
5169 return __copy_user((__force void __user *) to, from, n);
5170 }
5171
5172 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5173 index 3e1449f..5293a0e 100644
5174 --- a/arch/sparc/include/asm/uaccess_64.h
5175 +++ b/arch/sparc/include/asm/uaccess_64.h
5176 @@ -10,6 +10,7 @@
5177 #include <linux/compiler.h>
5178 #include <linux/string.h>
5179 #include <linux/thread_info.h>
5180 +#include <linux/kernel.h>
5181 #include <asm/asi.h>
5182 #include <asm/system.h>
5183 #include <asm/spitfire.h>
5184 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5185 static inline unsigned long __must_check
5186 copy_from_user(void *to, const void __user *from, unsigned long size)
5187 {
5188 - unsigned long ret = ___copy_from_user(to, from, size);
5189 + unsigned long ret;
5190
5191 + if ((long)size < 0 || size > INT_MAX)
5192 + return size;
5193 +
5194 + if (!__builtin_constant_p(size))
5195 + check_object_size(to, size, false);
5196 +
5197 + ret = ___copy_from_user(to, from, size);
5198 if (unlikely(ret))
5199 ret = copy_from_user_fixup(to, from, size);
5200
5201 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5202 static inline unsigned long __must_check
5203 copy_to_user(void __user *to, const void *from, unsigned long size)
5204 {
5205 - unsigned long ret = ___copy_to_user(to, from, size);
5206 + unsigned long ret;
5207
5208 + if ((long)size < 0 || size > INT_MAX)
5209 + return size;
5210 +
5211 + if (!__builtin_constant_p(size))
5212 + check_object_size(from, size, true);
5213 +
5214 + ret = ___copy_to_user(to, from, size);
5215 if (unlikely(ret))
5216 ret = copy_to_user_fixup(to, from, size);
5217 return ret;
5218 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5219 index cb85458..e063f17 100644
5220 --- a/arch/sparc/kernel/Makefile
5221 +++ b/arch/sparc/kernel/Makefile
5222 @@ -3,7 +3,7 @@
5223 #
5224
5225 asflags-y := -ansi
5226 -ccflags-y := -Werror
5227 +#ccflags-y := -Werror
5228
5229 extra-y := head_$(BITS).o
5230 extra-y += init_task.o
5231 diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
5232 index 381edcd..27728e1 100644
5233 --- a/arch/sparc/kernel/ds.c
5234 +++ b/arch/sparc/kernel/ds.c
5235 @@ -1267,4 +1267,4 @@ static int __init ds_init(void)
5236 return vio_register_driver(&ds_driver);
5237 }
5238
5239 -subsys_initcall(ds_init);
5240 +fs_initcall(ds_init);
5241 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5242 index f793742..4d880af 100644
5243 --- a/arch/sparc/kernel/process_32.c
5244 +++ b/arch/sparc/kernel/process_32.c
5245 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5246 rw->ins[4], rw->ins[5],
5247 rw->ins[6],
5248 rw->ins[7]);
5249 - printk("%pS\n", (void *) rw->ins[7]);
5250 + printk("%pA\n", (void *) rw->ins[7]);
5251 rw = (struct reg_window32 *) rw->ins[6];
5252 }
5253 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5254 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5255
5256 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5257 r->psr, r->pc, r->npc, r->y, print_tainted());
5258 - printk("PC: <%pS>\n", (void *) r->pc);
5259 + printk("PC: <%pA>\n", (void *) r->pc);
5260 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5261 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5262 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5263 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5264 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5265 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5266 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5267 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5268
5269 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5270 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5271 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5272 rw = (struct reg_window32 *) fp;
5273 pc = rw->ins[7];
5274 printk("[%08lx : ", pc);
5275 - printk("%pS ] ", (void *) pc);
5276 + printk("%pA ] ", (void *) pc);
5277 fp = rw->ins[6];
5278 } while (++count < 16);
5279 printk("\n");
5280 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5281 index 39d8b05..d1a7d90 100644
5282 --- a/arch/sparc/kernel/process_64.c
5283 +++ b/arch/sparc/kernel/process_64.c
5284 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5285 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5286 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5287 if (regs->tstate & TSTATE_PRIV)
5288 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5289 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5290 }
5291
5292 void show_regs(struct pt_regs *regs)
5293 {
5294 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5295 regs->tpc, regs->tnpc, regs->y, print_tainted());
5296 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5297 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5298 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5299 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5300 regs->u_regs[3]);
5301 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5302 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5303 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5304 regs->u_regs[15]);
5305 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5306 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5307 show_regwindow(regs);
5308 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5309 }
5310 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5311 ((tp && tp->task) ? tp->task->pid : -1));
5312
5313 if (gp->tstate & TSTATE_PRIV) {
5314 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5315 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5316 (void *) gp->tpc,
5317 (void *) gp->o7,
5318 (void *) gp->i7,
5319 diff --git a/arch/sparc/kernel/rtrap_64.S b/arch/sparc/kernel/rtrap_64.S
5320 index 77f1b95..9171fc2 100644
5321 --- a/arch/sparc/kernel/rtrap_64.S
5322 +++ b/arch/sparc/kernel/rtrap_64.S
5323 @@ -20,11 +20,6 @@
5324
5325 .text
5326 .align 32
5327 -__handle_softirq:
5328 - call do_softirq
5329 - nop
5330 - ba,a,pt %xcc, __handle_softirq_continue
5331 - nop
5332 __handle_preemption:
5333 call schedule
5334 wrpr %g0, RTRAP_PSTATE, %pstate
5335 @@ -89,9 +84,7 @@ rtrap:
5336 cmp %l1, 0
5337
5338 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
5339 - bne,pn %icc, __handle_softirq
5340 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
5341 -__handle_softirq_continue:
5342 rtrap_xcall:
5343 sethi %hi(0xf << 20), %l4
5344 and %l1, %l4, %l4
5345 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5346 index 42b282f..28ce9f2 100644
5347 --- a/arch/sparc/kernel/sys_sparc_32.c
5348 +++ b/arch/sparc/kernel/sys_sparc_32.c
5349 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5350 if (ARCH_SUN4C && len > 0x20000000)
5351 return -ENOMEM;
5352 if (!addr)
5353 - addr = TASK_UNMAPPED_BASE;
5354 + addr = current->mm->mmap_base;
5355
5356 if (flags & MAP_SHARED)
5357 addr = COLOUR_ALIGN(addr);
5358 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5359 }
5360 if (TASK_SIZE - PAGE_SIZE - len < addr)
5361 return -ENOMEM;
5362 - if (!vmm || addr + len <= vmm->vm_start)
5363 + if (check_heap_stack_gap(vmm, addr, len))
5364 return addr;
5365 addr = vmm->vm_end;
5366 if (flags & MAP_SHARED)
5367 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5368 index 232df99..cee1f9c 100644
5369 --- a/arch/sparc/kernel/sys_sparc_64.c
5370 +++ b/arch/sparc/kernel/sys_sparc_64.c
5371 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5372 /* We do not accept a shared mapping if it would violate
5373 * cache aliasing constraints.
5374 */
5375 - if ((flags & MAP_SHARED) &&
5376 + if ((filp || (flags & MAP_SHARED)) &&
5377 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5378 return -EINVAL;
5379 return addr;
5380 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5381 if (filp || (flags & MAP_SHARED))
5382 do_color_align = 1;
5383
5384 +#ifdef CONFIG_PAX_RANDMMAP
5385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5386 +#endif
5387 +
5388 if (addr) {
5389 if (do_color_align)
5390 addr = COLOUR_ALIGN(addr, pgoff);
5391 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5392 addr = PAGE_ALIGN(addr);
5393
5394 vma = find_vma(mm, addr);
5395 - if (task_size - len >= addr &&
5396 - (!vma || addr + len <= vma->vm_start))
5397 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5398 return addr;
5399 }
5400
5401 if (len > mm->cached_hole_size) {
5402 - start_addr = addr = mm->free_area_cache;
5403 + start_addr = addr = mm->free_area_cache;
5404 } else {
5405 - start_addr = addr = TASK_UNMAPPED_BASE;
5406 + start_addr = addr = mm->mmap_base;
5407 mm->cached_hole_size = 0;
5408 }
5409
5410 @@ -174,14 +177,14 @@ full_search:
5411 vma = find_vma(mm, VA_EXCLUDE_END);
5412 }
5413 if (unlikely(task_size < addr)) {
5414 - if (start_addr != TASK_UNMAPPED_BASE) {
5415 - start_addr = addr = TASK_UNMAPPED_BASE;
5416 + if (start_addr != mm->mmap_base) {
5417 + start_addr = addr = mm->mmap_base;
5418 mm->cached_hole_size = 0;
5419 goto full_search;
5420 }
5421 return -ENOMEM;
5422 }
5423 - if (likely(!vma || addr + len <= vma->vm_start)) {
5424 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5425 /*
5426 * Remember the place where we stopped the search:
5427 */
5428 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5429 /* We do not accept a shared mapping if it would violate
5430 * cache aliasing constraints.
5431 */
5432 - if ((flags & MAP_SHARED) &&
5433 + if ((filp || (flags & MAP_SHARED)) &&
5434 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5435 return -EINVAL;
5436 return addr;
5437 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5438 addr = PAGE_ALIGN(addr);
5439
5440 vma = find_vma(mm, addr);
5441 - if (task_size - len >= addr &&
5442 - (!vma || addr + len <= vma->vm_start))
5443 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5444 return addr;
5445 }
5446
5447 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5448 /* make sure it can fit in the remaining address space */
5449 if (likely(addr > len)) {
5450 vma = find_vma(mm, addr-len);
5451 - if (!vma || addr <= vma->vm_start) {
5452 + if (check_heap_stack_gap(vma, addr - len, len)) {
5453 /* remember the address as a hint for next time */
5454 return (mm->free_area_cache = addr-len);
5455 }
5456 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5457 if (unlikely(mm->mmap_base < len))
5458 goto bottomup;
5459
5460 - addr = mm->mmap_base-len;
5461 - if (do_color_align)
5462 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5463 + addr = mm->mmap_base - len;
5464
5465 do {
5466 + if (do_color_align)
5467 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5468 /*
5469 * Lookup failure means no vma is above this address,
5470 * else if new region fits below vma->vm_start,
5471 * return with success:
5472 */
5473 vma = find_vma(mm, addr);
5474 - if (likely(!vma || addr+len <= vma->vm_start)) {
5475 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5476 /* remember the address as a hint for next time */
5477 return (mm->free_area_cache = addr);
5478 }
5479 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5480 mm->cached_hole_size = vma->vm_start - addr;
5481
5482 /* try just below the current vma->vm_start */
5483 - addr = vma->vm_start-len;
5484 - if (do_color_align)
5485 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5486 - } while (likely(len < vma->vm_start));
5487 + addr = skip_heap_stack_gap(vma, len);
5488 + } while (!IS_ERR_VALUE(addr));
5489
5490 bottomup:
5491 /*
5492 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5493 gap == RLIM_INFINITY ||
5494 sysctl_legacy_va_layout) {
5495 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5496 +
5497 +#ifdef CONFIG_PAX_RANDMMAP
5498 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5499 + mm->mmap_base += mm->delta_mmap;
5500 +#endif
5501 +
5502 mm->get_unmapped_area = arch_get_unmapped_area;
5503 mm->unmap_area = arch_unmap_area;
5504 } else {
5505 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5506 gap = (task_size / 6 * 5);
5507
5508 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5509 +
5510 +#ifdef CONFIG_PAX_RANDMMAP
5511 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5512 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5513 +#endif
5514 +
5515 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5516 mm->unmap_area = arch_unmap_area_topdown;
5517 }
5518 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5519 index 591f20c..0f1b925 100644
5520 --- a/arch/sparc/kernel/traps_32.c
5521 +++ b/arch/sparc/kernel/traps_32.c
5522 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5523 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5524 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5525
5526 +extern void gr_handle_kernel_exploit(void);
5527 +
5528 void die_if_kernel(char *str, struct pt_regs *regs)
5529 {
5530 static int die_counter;
5531 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5532 count++ < 30 &&
5533 (((unsigned long) rw) >= PAGE_OFFSET) &&
5534 !(((unsigned long) rw) & 0x7)) {
5535 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5536 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5537 (void *) rw->ins[7]);
5538 rw = (struct reg_window32 *)rw->ins[6];
5539 }
5540 }
5541 printk("Instruction DUMP:");
5542 instruction_dump ((unsigned long *) regs->pc);
5543 - if(regs->psr & PSR_PS)
5544 + if(regs->psr & PSR_PS) {
5545 + gr_handle_kernel_exploit();
5546 do_exit(SIGKILL);
5547 + }
5548 do_exit(SIGSEGV);
5549 }
5550
5551 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5552 index 0cbdaa4..438e4c9 100644
5553 --- a/arch/sparc/kernel/traps_64.c
5554 +++ b/arch/sparc/kernel/traps_64.c
5555 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5556 i + 1,
5557 p->trapstack[i].tstate, p->trapstack[i].tpc,
5558 p->trapstack[i].tnpc, p->trapstack[i].tt);
5559 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5560 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5561 }
5562 }
5563
5564 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5565
5566 lvl -= 0x100;
5567 if (regs->tstate & TSTATE_PRIV) {
5568 +
5569 +#ifdef CONFIG_PAX_REFCOUNT
5570 + if (lvl == 6)
5571 + pax_report_refcount_overflow(regs);
5572 +#endif
5573 +
5574 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5575 die_if_kernel(buffer, regs);
5576 }
5577 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5578 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5579 {
5580 char buffer[32];
5581 -
5582 +
5583 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5584 0, lvl, SIGTRAP) == NOTIFY_STOP)
5585 return;
5586
5587 +#ifdef CONFIG_PAX_REFCOUNT
5588 + if (lvl == 6)
5589 + pax_report_refcount_overflow(regs);
5590 +#endif
5591 +
5592 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5593
5594 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5595 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5596 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5597 printk("%s" "ERROR(%d): ",
5598 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5599 - printk("TPC<%pS>\n", (void *) regs->tpc);
5600 + printk("TPC<%pA>\n", (void *) regs->tpc);
5601 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5602 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5603 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5604 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5605 smp_processor_id(),
5606 (type & 0x1) ? 'I' : 'D',
5607 regs->tpc);
5608 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5609 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5610 panic("Irrecoverable Cheetah+ parity error.");
5611 }
5612
5613 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5614 smp_processor_id(),
5615 (type & 0x1) ? 'I' : 'D',
5616 regs->tpc);
5617 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5618 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5619 }
5620
5621 struct sun4v_error_entry {
5622 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5623
5624 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5625 regs->tpc, tl);
5626 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5627 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5628 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5629 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5630 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5631 (void *) regs->u_regs[UREG_I7]);
5632 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5633 "pte[%lx] error[%lx]\n",
5634 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5635
5636 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5637 regs->tpc, tl);
5638 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5639 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5640 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5641 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5642 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5643 (void *) regs->u_regs[UREG_I7]);
5644 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5645 "pte[%lx] error[%lx]\n",
5646 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5647 fp = (unsigned long)sf->fp + STACK_BIAS;
5648 }
5649
5650 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5651 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5652 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5653 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5654 int index = tsk->curr_ret_stack;
5655 if (tsk->ret_stack && index >= graph) {
5656 pc = tsk->ret_stack[index - graph].ret;
5657 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5658 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5659 graph++;
5660 }
5661 }
5662 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5663 return (struct reg_window *) (fp + STACK_BIAS);
5664 }
5665
5666 +extern void gr_handle_kernel_exploit(void);
5667 +
5668 void die_if_kernel(char *str, struct pt_regs *regs)
5669 {
5670 static int die_counter;
5671 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5672 while (rw &&
5673 count++ < 30 &&
5674 kstack_valid(tp, (unsigned long) rw)) {
5675 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5676 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5677 (void *) rw->ins[7]);
5678
5679 rw = kernel_stack_up(rw);
5680 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5681 }
5682 user_instruction_dump ((unsigned int __user *) regs->tpc);
5683 }
5684 - if (regs->tstate & TSTATE_PRIV)
5685 + if (regs->tstate & TSTATE_PRIV) {
5686 + gr_handle_kernel_exploit();
5687 do_exit(SIGKILL);
5688 + }
5689 do_exit(SIGSEGV);
5690 }
5691 EXPORT_SYMBOL(die_if_kernel);
5692 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5693 index 76e4ac1..78f8bb1 100644
5694 --- a/arch/sparc/kernel/unaligned_64.c
5695 +++ b/arch/sparc/kernel/unaligned_64.c
5696 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5697 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5698
5699 if (__ratelimit(&ratelimit)) {
5700 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5701 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5702 regs->tpc, (void *) regs->tpc);
5703 }
5704 }
5705 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5706 index a3fc437..fea9957 100644
5707 --- a/arch/sparc/lib/Makefile
5708 +++ b/arch/sparc/lib/Makefile
5709 @@ -2,7 +2,7 @@
5710 #
5711
5712 asflags-y := -ansi -DST_DIV0=0x02
5713 -ccflags-y := -Werror
5714 +#ccflags-y := -Werror
5715
5716 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5717 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5718 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5719 index 59186e0..f747d7a 100644
5720 --- a/arch/sparc/lib/atomic_64.S
5721 +++ b/arch/sparc/lib/atomic_64.S
5722 @@ -18,7 +18,12 @@
5723 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5724 BACKOFF_SETUP(%o2)
5725 1: lduw [%o1], %g1
5726 - add %g1, %o0, %g7
5727 + addcc %g1, %o0, %g7
5728 +
5729 +#ifdef CONFIG_PAX_REFCOUNT
5730 + tvs %icc, 6
5731 +#endif
5732 +
5733 cas [%o1], %g1, %g7
5734 cmp %g1, %g7
5735 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5736 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5737 2: BACKOFF_SPIN(%o2, %o3, 1b)
5738 .size atomic_add, .-atomic_add
5739
5740 + .globl atomic_add_unchecked
5741 + .type atomic_add_unchecked,#function
5742 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5743 + BACKOFF_SETUP(%o2)
5744 +1: lduw [%o1], %g1
5745 + add %g1, %o0, %g7
5746 + cas [%o1], %g1, %g7
5747 + cmp %g1, %g7
5748 + bne,pn %icc, 2f
5749 + nop
5750 + retl
5751 + nop
5752 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5753 + .size atomic_add_unchecked, .-atomic_add_unchecked
5754 +
5755 .globl atomic_sub
5756 .type atomic_sub,#function
5757 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5758 BACKOFF_SETUP(%o2)
5759 1: lduw [%o1], %g1
5760 - sub %g1, %o0, %g7
5761 + subcc %g1, %o0, %g7
5762 +
5763 +#ifdef CONFIG_PAX_REFCOUNT
5764 + tvs %icc, 6
5765 +#endif
5766 +
5767 cas [%o1], %g1, %g7
5768 cmp %g1, %g7
5769 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5770 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5771 2: BACKOFF_SPIN(%o2, %o3, 1b)
5772 .size atomic_sub, .-atomic_sub
5773
5774 + .globl atomic_sub_unchecked
5775 + .type atomic_sub_unchecked,#function
5776 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5777 + BACKOFF_SETUP(%o2)
5778 +1: lduw [%o1], %g1
5779 + sub %g1, %o0, %g7
5780 + cas [%o1], %g1, %g7
5781 + cmp %g1, %g7
5782 + bne,pn %icc, 2f
5783 + nop
5784 + retl
5785 + nop
5786 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5787 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5788 +
5789 .globl atomic_add_ret
5790 .type atomic_add_ret,#function
5791 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5792 BACKOFF_SETUP(%o2)
5793 1: lduw [%o1], %g1
5794 - add %g1, %o0, %g7
5795 + addcc %g1, %o0, %g7
5796 +
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + tvs %icc, 6
5799 +#endif
5800 +
5801 cas [%o1], %g1, %g7
5802 cmp %g1, %g7
5803 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5804 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5805 2: BACKOFF_SPIN(%o2, %o3, 1b)
5806 .size atomic_add_ret, .-atomic_add_ret
5807
5808 + .globl atomic_add_ret_unchecked
5809 + .type atomic_add_ret_unchecked,#function
5810 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5811 + BACKOFF_SETUP(%o2)
5812 +1: lduw [%o1], %g1
5813 + addcc %g1, %o0, %g7
5814 + cas [%o1], %g1, %g7
5815 + cmp %g1, %g7
5816 + bne,pn %icc, 2f
5817 + add %g7, %o0, %g7
5818 + sra %g7, 0, %o0
5819 + retl
5820 + nop
5821 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5822 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5823 +
5824 .globl atomic_sub_ret
5825 .type atomic_sub_ret,#function
5826 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5827 BACKOFF_SETUP(%o2)
5828 1: lduw [%o1], %g1
5829 - sub %g1, %o0, %g7
5830 + subcc %g1, %o0, %g7
5831 +
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + tvs %icc, 6
5834 +#endif
5835 +
5836 cas [%o1], %g1, %g7
5837 cmp %g1, %g7
5838 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5839 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5840 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5841 BACKOFF_SETUP(%o2)
5842 1: ldx [%o1], %g1
5843 - add %g1, %o0, %g7
5844 + addcc %g1, %o0, %g7
5845 +
5846 +#ifdef CONFIG_PAX_REFCOUNT
5847 + tvs %xcc, 6
5848 +#endif
5849 +
5850 casx [%o1], %g1, %g7
5851 cmp %g1, %g7
5852 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5853 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5854 2: BACKOFF_SPIN(%o2, %o3, 1b)
5855 .size atomic64_add, .-atomic64_add
5856
5857 + .globl atomic64_add_unchecked
5858 + .type atomic64_add_unchecked,#function
5859 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5860 + BACKOFF_SETUP(%o2)
5861 +1: ldx [%o1], %g1
5862 + addcc %g1, %o0, %g7
5863 + casx [%o1], %g1, %g7
5864 + cmp %g1, %g7
5865 + bne,pn %xcc, 2f
5866 + nop
5867 + retl
5868 + nop
5869 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5870 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5871 +
5872 .globl atomic64_sub
5873 .type atomic64_sub,#function
5874 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5875 BACKOFF_SETUP(%o2)
5876 1: ldx [%o1], %g1
5877 - sub %g1, %o0, %g7
5878 + subcc %g1, %o0, %g7
5879 +
5880 +#ifdef CONFIG_PAX_REFCOUNT
5881 + tvs %xcc, 6
5882 +#endif
5883 +
5884 casx [%o1], %g1, %g7
5885 cmp %g1, %g7
5886 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5887 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5888 2: BACKOFF_SPIN(%o2, %o3, 1b)
5889 .size atomic64_sub, .-atomic64_sub
5890
5891 + .globl atomic64_sub_unchecked
5892 + .type atomic64_sub_unchecked,#function
5893 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5894 + BACKOFF_SETUP(%o2)
5895 +1: ldx [%o1], %g1
5896 + subcc %g1, %o0, %g7
5897 + casx [%o1], %g1, %g7
5898 + cmp %g1, %g7
5899 + bne,pn %xcc, 2f
5900 + nop
5901 + retl
5902 + nop
5903 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5904 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5905 +
5906 .globl atomic64_add_ret
5907 .type atomic64_add_ret,#function
5908 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5909 BACKOFF_SETUP(%o2)
5910 1: ldx [%o1], %g1
5911 - add %g1, %o0, %g7
5912 + addcc %g1, %o0, %g7
5913 +
5914 +#ifdef CONFIG_PAX_REFCOUNT
5915 + tvs %xcc, 6
5916 +#endif
5917 +
5918 casx [%o1], %g1, %g7
5919 cmp %g1, %g7
5920 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5921 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5922 2: BACKOFF_SPIN(%o2, %o3, 1b)
5923 .size atomic64_add_ret, .-atomic64_add_ret
5924
5925 + .globl atomic64_add_ret_unchecked
5926 + .type atomic64_add_ret_unchecked,#function
5927 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5928 + BACKOFF_SETUP(%o2)
5929 +1: ldx [%o1], %g1
5930 + addcc %g1, %o0, %g7
5931 + casx [%o1], %g1, %g7
5932 + cmp %g1, %g7
5933 + bne,pn %xcc, 2f
5934 + add %g7, %o0, %g7
5935 + mov %g7, %o0
5936 + retl
5937 + nop
5938 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5939 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5940 +
5941 .globl atomic64_sub_ret
5942 .type atomic64_sub_ret,#function
5943 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5944 BACKOFF_SETUP(%o2)
5945 1: ldx [%o1], %g1
5946 - sub %g1, %o0, %g7
5947 + subcc %g1, %o0, %g7
5948 +
5949 +#ifdef CONFIG_PAX_REFCOUNT
5950 + tvs %xcc, 6
5951 +#endif
5952 +
5953 casx [%o1], %g1, %g7
5954 cmp %g1, %g7
5955 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5956 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5957 index f73c224..662af10 100644
5958 --- a/arch/sparc/lib/ksyms.c
5959 +++ b/arch/sparc/lib/ksyms.c
5960 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
5961
5962 /* Atomic counter implementation. */
5963 EXPORT_SYMBOL(atomic_add);
5964 +EXPORT_SYMBOL(atomic_add_unchecked);
5965 EXPORT_SYMBOL(atomic_add_ret);
5966 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5967 EXPORT_SYMBOL(atomic_sub);
5968 +EXPORT_SYMBOL(atomic_sub_unchecked);
5969 EXPORT_SYMBOL(atomic_sub_ret);
5970 EXPORT_SYMBOL(atomic64_add);
5971 +EXPORT_SYMBOL(atomic64_add_unchecked);
5972 EXPORT_SYMBOL(atomic64_add_ret);
5973 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5974 EXPORT_SYMBOL(atomic64_sub);
5975 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5976 EXPORT_SYMBOL(atomic64_sub_ret);
5977
5978 /* Atomic bit operations. */
5979 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5980 index 301421c..e2535d1 100644
5981 --- a/arch/sparc/mm/Makefile
5982 +++ b/arch/sparc/mm/Makefile
5983 @@ -2,7 +2,7 @@
5984 #
5985
5986 asflags-y := -ansi
5987 -ccflags-y := -Werror
5988 +#ccflags-y := -Werror
5989
5990 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5991 obj-y += fault_$(BITS).o
5992 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5993 index 8023fd7..c8e89e9 100644
5994 --- a/arch/sparc/mm/fault_32.c
5995 +++ b/arch/sparc/mm/fault_32.c
5996 @@ -21,6 +21,9 @@
5997 #include <linux/perf_event.h>
5998 #include <linux/interrupt.h>
5999 #include <linux/kdebug.h>
6000 +#include <linux/slab.h>
6001 +#include <linux/pagemap.h>
6002 +#include <linux/compiler.h>
6003
6004 #include <asm/system.h>
6005 #include <asm/page.h>
6006 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6007 return safe_compute_effective_address(regs, insn);
6008 }
6009
6010 +#ifdef CONFIG_PAX_PAGEEXEC
6011 +#ifdef CONFIG_PAX_DLRESOLVE
6012 +static void pax_emuplt_close(struct vm_area_struct *vma)
6013 +{
6014 + vma->vm_mm->call_dl_resolve = 0UL;
6015 +}
6016 +
6017 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6018 +{
6019 + unsigned int *kaddr;
6020 +
6021 + vmf->page = alloc_page(GFP_HIGHUSER);
6022 + if (!vmf->page)
6023 + return VM_FAULT_OOM;
6024 +
6025 + kaddr = kmap(vmf->page);
6026 + memset(kaddr, 0, PAGE_SIZE);
6027 + kaddr[0] = 0x9DE3BFA8U; /* save */
6028 + flush_dcache_page(vmf->page);
6029 + kunmap(vmf->page);
6030 + return VM_FAULT_MAJOR;
6031 +}
6032 +
6033 +static const struct vm_operations_struct pax_vm_ops = {
6034 + .close = pax_emuplt_close,
6035 + .fault = pax_emuplt_fault
6036 +};
6037 +
6038 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6039 +{
6040 + int ret;
6041 +
6042 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6043 + vma->vm_mm = current->mm;
6044 + vma->vm_start = addr;
6045 + vma->vm_end = addr + PAGE_SIZE;
6046 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6047 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6048 + vma->vm_ops = &pax_vm_ops;
6049 +
6050 + ret = insert_vm_struct(current->mm, vma);
6051 + if (ret)
6052 + return ret;
6053 +
6054 + ++current->mm->total_vm;
6055 + return 0;
6056 +}
6057 +#endif
6058 +
6059 +/*
6060 + * PaX: decide what to do with offenders (regs->pc = fault address)
6061 + *
6062 + * returns 1 when task should be killed
6063 + * 2 when patched PLT trampoline was detected
6064 + * 3 when unpatched PLT trampoline was detected
6065 + */
6066 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6067 +{
6068 +
6069 +#ifdef CONFIG_PAX_EMUPLT
6070 + int err;
6071 +
6072 + do { /* PaX: patched PLT emulation #1 */
6073 + unsigned int sethi1, sethi2, jmpl;
6074 +
6075 + err = get_user(sethi1, (unsigned int *)regs->pc);
6076 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6077 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6078 +
6079 + if (err)
6080 + break;
6081 +
6082 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6083 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6084 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6085 + {
6086 + unsigned int addr;
6087 +
6088 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6089 + addr = regs->u_regs[UREG_G1];
6090 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6091 + regs->pc = addr;
6092 + regs->npc = addr+4;
6093 + return 2;
6094 + }
6095 + } while (0);
6096 +
6097 + { /* PaX: patched PLT emulation #2 */
6098 + unsigned int ba;
6099 +
6100 + err = get_user(ba, (unsigned int *)regs->pc);
6101 +
6102 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6103 + unsigned int addr;
6104 +
6105 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6106 + regs->pc = addr;
6107 + regs->npc = addr+4;
6108 + return 2;
6109 + }
6110 + }
6111 +
6112 + do { /* PaX: patched PLT emulation #3 */
6113 + unsigned int sethi, jmpl, nop;
6114 +
6115 + err = get_user(sethi, (unsigned int *)regs->pc);
6116 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6117 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6118 +
6119 + if (err)
6120 + break;
6121 +
6122 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6123 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6124 + nop == 0x01000000U)
6125 + {
6126 + unsigned int addr;
6127 +
6128 + addr = (sethi & 0x003FFFFFU) << 10;
6129 + regs->u_regs[UREG_G1] = addr;
6130 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6131 + regs->pc = addr;
6132 + regs->npc = addr+4;
6133 + return 2;
6134 + }
6135 + } while (0);
6136 +
6137 + do { /* PaX: unpatched PLT emulation step 1 */
6138 + unsigned int sethi, ba, nop;
6139 +
6140 + err = get_user(sethi, (unsigned int *)regs->pc);
6141 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6142 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6143 +
6144 + if (err)
6145 + break;
6146 +
6147 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6148 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6149 + nop == 0x01000000U)
6150 + {
6151 + unsigned int addr, save, call;
6152 +
6153 + if ((ba & 0xFFC00000U) == 0x30800000U)
6154 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6155 + else
6156 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6157 +
6158 + err = get_user(save, (unsigned int *)addr);
6159 + err |= get_user(call, (unsigned int *)(addr+4));
6160 + err |= get_user(nop, (unsigned int *)(addr+8));
6161 + if (err)
6162 + break;
6163 +
6164 +#ifdef CONFIG_PAX_DLRESOLVE
6165 + if (save == 0x9DE3BFA8U &&
6166 + (call & 0xC0000000U) == 0x40000000U &&
6167 + nop == 0x01000000U)
6168 + {
6169 + struct vm_area_struct *vma;
6170 + unsigned long call_dl_resolve;
6171 +
6172 + down_read(&current->mm->mmap_sem);
6173 + call_dl_resolve = current->mm->call_dl_resolve;
6174 + up_read(&current->mm->mmap_sem);
6175 + if (likely(call_dl_resolve))
6176 + goto emulate;
6177 +
6178 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6179 +
6180 + down_write(&current->mm->mmap_sem);
6181 + if (current->mm->call_dl_resolve) {
6182 + call_dl_resolve = current->mm->call_dl_resolve;
6183 + up_write(&current->mm->mmap_sem);
6184 + if (vma)
6185 + kmem_cache_free(vm_area_cachep, vma);
6186 + goto emulate;
6187 + }
6188 +
6189 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6190 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6191 + up_write(&current->mm->mmap_sem);
6192 + if (vma)
6193 + kmem_cache_free(vm_area_cachep, vma);
6194 + return 1;
6195 + }
6196 +
6197 + if (pax_insert_vma(vma, call_dl_resolve)) {
6198 + up_write(&current->mm->mmap_sem);
6199 + kmem_cache_free(vm_area_cachep, vma);
6200 + return 1;
6201 + }
6202 +
6203 + current->mm->call_dl_resolve = call_dl_resolve;
6204 + up_write(&current->mm->mmap_sem);
6205 +
6206 +emulate:
6207 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6208 + regs->pc = call_dl_resolve;
6209 + regs->npc = addr+4;
6210 + return 3;
6211 + }
6212 +#endif
6213 +
6214 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6215 + if ((save & 0xFFC00000U) == 0x05000000U &&
6216 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6217 + nop == 0x01000000U)
6218 + {
6219 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6220 + regs->u_regs[UREG_G2] = addr + 4;
6221 + addr = (save & 0x003FFFFFU) << 10;
6222 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6223 + regs->pc = addr;
6224 + regs->npc = addr+4;
6225 + return 3;
6226 + }
6227 + }
6228 + } while (0);
6229 +
6230 + do { /* PaX: unpatched PLT emulation step 2 */
6231 + unsigned int save, call, nop;
6232 +
6233 + err = get_user(save, (unsigned int *)(regs->pc-4));
6234 + err |= get_user(call, (unsigned int *)regs->pc);
6235 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6236 + if (err)
6237 + break;
6238 +
6239 + if (save == 0x9DE3BFA8U &&
6240 + (call & 0xC0000000U) == 0x40000000U &&
6241 + nop == 0x01000000U)
6242 + {
6243 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6244 +
6245 + regs->u_regs[UREG_RETPC] = regs->pc;
6246 + regs->pc = dl_resolve;
6247 + regs->npc = dl_resolve+4;
6248 + return 3;
6249 + }
6250 + } while (0);
6251 +#endif
6252 +
6253 + return 1;
6254 +}
6255 +
6256 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6257 +{
6258 + unsigned long i;
6259 +
6260 + printk(KERN_ERR "PAX: bytes at PC: ");
6261 + for (i = 0; i < 8; i++) {
6262 + unsigned int c;
6263 + if (get_user(c, (unsigned int *)pc+i))
6264 + printk(KERN_CONT "???????? ");
6265 + else
6266 + printk(KERN_CONT "%08x ", c);
6267 + }
6268 + printk("\n");
6269 +}
6270 +#endif
6271 +
6272 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6273 int text_fault)
6274 {
6275 @@ -280,6 +545,24 @@ good_area:
6276 if(!(vma->vm_flags & VM_WRITE))
6277 goto bad_area;
6278 } else {
6279 +
6280 +#ifdef CONFIG_PAX_PAGEEXEC
6281 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6282 + up_read(&mm->mmap_sem);
6283 + switch (pax_handle_fetch_fault(regs)) {
6284 +
6285 +#ifdef CONFIG_PAX_EMUPLT
6286 + case 2:
6287 + case 3:
6288 + return;
6289 +#endif
6290 +
6291 + }
6292 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6293 + do_group_exit(SIGKILL);
6294 + }
6295 +#endif
6296 +
6297 /* Allow reads even for write-only mappings */
6298 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6299 goto bad_area;
6300 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6301 index 504c062..6fcb9c6 100644
6302 --- a/arch/sparc/mm/fault_64.c
6303 +++ b/arch/sparc/mm/fault_64.c
6304 @@ -21,6 +21,9 @@
6305 #include <linux/kprobes.h>
6306 #include <linux/kdebug.h>
6307 #include <linux/percpu.h>
6308 +#include <linux/slab.h>
6309 +#include <linux/pagemap.h>
6310 +#include <linux/compiler.h>
6311
6312 #include <asm/page.h>
6313 #include <asm/pgtable.h>
6314 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6315 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6316 regs->tpc);
6317 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6318 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6319 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6320 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6321 dump_stack();
6322 unhandled_fault(regs->tpc, current, regs);
6323 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6324 show_regs(regs);
6325 }
6326
6327 +#ifdef CONFIG_PAX_PAGEEXEC
6328 +#ifdef CONFIG_PAX_DLRESOLVE
6329 +static void pax_emuplt_close(struct vm_area_struct *vma)
6330 +{
6331 + vma->vm_mm->call_dl_resolve = 0UL;
6332 +}
6333 +
6334 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6335 +{
6336 + unsigned int *kaddr;
6337 +
6338 + vmf->page = alloc_page(GFP_HIGHUSER);
6339 + if (!vmf->page)
6340 + return VM_FAULT_OOM;
6341 +
6342 + kaddr = kmap(vmf->page);
6343 + memset(kaddr, 0, PAGE_SIZE);
6344 + kaddr[0] = 0x9DE3BFA8U; /* save */
6345 + flush_dcache_page(vmf->page);
6346 + kunmap(vmf->page);
6347 + return VM_FAULT_MAJOR;
6348 +}
6349 +
6350 +static const struct vm_operations_struct pax_vm_ops = {
6351 + .close = pax_emuplt_close,
6352 + .fault = pax_emuplt_fault
6353 +};
6354 +
6355 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6356 +{
6357 + int ret;
6358 +
6359 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6360 + vma->vm_mm = current->mm;
6361 + vma->vm_start = addr;
6362 + vma->vm_end = addr + PAGE_SIZE;
6363 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6364 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6365 + vma->vm_ops = &pax_vm_ops;
6366 +
6367 + ret = insert_vm_struct(current->mm, vma);
6368 + if (ret)
6369 + return ret;
6370 +
6371 + ++current->mm->total_vm;
6372 + return 0;
6373 +}
6374 +#endif
6375 +
6376 +/*
6377 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6378 + *
6379 + * returns 1 when task should be killed
6380 + * 2 when patched PLT trampoline was detected
6381 + * 3 when unpatched PLT trampoline was detected
6382 + */
6383 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6384 +{
6385 +
6386 +#ifdef CONFIG_PAX_EMUPLT
6387 + int err;
6388 +
6389 + do { /* PaX: patched PLT emulation #1 */
6390 + unsigned int sethi1, sethi2, jmpl;
6391 +
6392 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6393 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6394 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6395 +
6396 + if (err)
6397 + break;
6398 +
6399 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6400 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6401 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6402 + {
6403 + unsigned long addr;
6404 +
6405 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6406 + addr = regs->u_regs[UREG_G1];
6407 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6408 +
6409 + if (test_thread_flag(TIF_32BIT))
6410 + addr &= 0xFFFFFFFFUL;
6411 +
6412 + regs->tpc = addr;
6413 + regs->tnpc = addr+4;
6414 + return 2;
6415 + }
6416 + } while (0);
6417 +
6418 + { /* PaX: patched PLT emulation #2 */
6419 + unsigned int ba;
6420 +
6421 + err = get_user(ba, (unsigned int *)regs->tpc);
6422 +
6423 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6424 + unsigned long addr;
6425 +
6426 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6427 +
6428 + if (test_thread_flag(TIF_32BIT))
6429 + addr &= 0xFFFFFFFFUL;
6430 +
6431 + regs->tpc = addr;
6432 + regs->tnpc = addr+4;
6433 + return 2;
6434 + }
6435 + }
6436 +
6437 + do { /* PaX: patched PLT emulation #3 */
6438 + unsigned int sethi, jmpl, nop;
6439 +
6440 + err = get_user(sethi, (unsigned int *)regs->tpc);
6441 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6442 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6443 +
6444 + if (err)
6445 + break;
6446 +
6447 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6448 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6449 + nop == 0x01000000U)
6450 + {
6451 + unsigned long addr;
6452 +
6453 + addr = (sethi & 0x003FFFFFU) << 10;
6454 + regs->u_regs[UREG_G1] = addr;
6455 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6456 +
6457 + if (test_thread_flag(TIF_32BIT))
6458 + addr &= 0xFFFFFFFFUL;
6459 +
6460 + regs->tpc = addr;
6461 + regs->tnpc = addr+4;
6462 + return 2;
6463 + }
6464 + } while (0);
6465 +
6466 + do { /* PaX: patched PLT emulation #4 */
6467 + unsigned int sethi, mov1, call, mov2;
6468 +
6469 + err = get_user(sethi, (unsigned int *)regs->tpc);
6470 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6471 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6472 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6473 +
6474 + if (err)
6475 + break;
6476 +
6477 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6478 + mov1 == 0x8210000FU &&
6479 + (call & 0xC0000000U) == 0x40000000U &&
6480 + mov2 == 0x9E100001U)
6481 + {
6482 + unsigned long addr;
6483 +
6484 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6485 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6486 +
6487 + if (test_thread_flag(TIF_32BIT))
6488 + addr &= 0xFFFFFFFFUL;
6489 +
6490 + regs->tpc = addr;
6491 + regs->tnpc = addr+4;
6492 + return 2;
6493 + }
6494 + } while (0);
6495 +
6496 + do { /* PaX: patched PLT emulation #5 */
6497 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, 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(or1, (unsigned int *)(regs->tpc+12));
6503 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6504 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6505 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6506 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6507 +
6508 + if (err)
6509 + break;
6510 +
6511 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6512 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6513 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6514 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6515 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6516 + sllx == 0x83287020U &&
6517 + jmpl == 0x81C04005U &&
6518 + nop == 0x01000000U)
6519 + {
6520 + unsigned long addr;
6521 +
6522 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6523 + regs->u_regs[UREG_G1] <<= 32;
6524 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6525 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6526 + regs->tpc = addr;
6527 + regs->tnpc = addr+4;
6528 + return 2;
6529 + }
6530 + } while (0);
6531 +
6532 + do { /* PaX: patched PLT emulation #6 */
6533 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6534 +
6535 + err = get_user(sethi, (unsigned int *)regs->tpc);
6536 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6537 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6538 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6539 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6540 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6541 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6542 +
6543 + if (err)
6544 + break;
6545 +
6546 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6547 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6548 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6549 + sllx == 0x83287020U &&
6550 + (or & 0xFFFFE000U) == 0x8A116000U &&
6551 + jmpl == 0x81C04005U &&
6552 + nop == 0x01000000U)
6553 + {
6554 + unsigned long addr;
6555 +
6556 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6557 + regs->u_regs[UREG_G1] <<= 32;
6558 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6559 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6560 + regs->tpc = addr;
6561 + regs->tnpc = addr+4;
6562 + return 2;
6563 + }
6564 + } while (0);
6565 +
6566 + do { /* PaX: unpatched PLT emulation step 1 */
6567 + unsigned int sethi, ba, nop;
6568 +
6569 + err = get_user(sethi, (unsigned int *)regs->tpc);
6570 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6571 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6572 +
6573 + if (err)
6574 + break;
6575 +
6576 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6577 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6578 + nop == 0x01000000U)
6579 + {
6580 + unsigned long addr;
6581 + unsigned int save, call;
6582 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6583 +
6584 + if ((ba & 0xFFC00000U) == 0x30800000U)
6585 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6586 + else
6587 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6588 +
6589 + if (test_thread_flag(TIF_32BIT))
6590 + addr &= 0xFFFFFFFFUL;
6591 +
6592 + err = get_user(save, (unsigned int *)addr);
6593 + err |= get_user(call, (unsigned int *)(addr+4));
6594 + err |= get_user(nop, (unsigned int *)(addr+8));
6595 + if (err)
6596 + break;
6597 +
6598 +#ifdef CONFIG_PAX_DLRESOLVE
6599 + if (save == 0x9DE3BFA8U &&
6600 + (call & 0xC0000000U) == 0x40000000U &&
6601 + nop == 0x01000000U)
6602 + {
6603 + struct vm_area_struct *vma;
6604 + unsigned long call_dl_resolve;
6605 +
6606 + down_read(&current->mm->mmap_sem);
6607 + call_dl_resolve = current->mm->call_dl_resolve;
6608 + up_read(&current->mm->mmap_sem);
6609 + if (likely(call_dl_resolve))
6610 + goto emulate;
6611 +
6612 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6613 +
6614 + down_write(&current->mm->mmap_sem);
6615 + if (current->mm->call_dl_resolve) {
6616 + call_dl_resolve = current->mm->call_dl_resolve;
6617 + up_write(&current->mm->mmap_sem);
6618 + if (vma)
6619 + kmem_cache_free(vm_area_cachep, vma);
6620 + goto emulate;
6621 + }
6622 +
6623 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6624 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6625 + up_write(&current->mm->mmap_sem);
6626 + if (vma)
6627 + kmem_cache_free(vm_area_cachep, vma);
6628 + return 1;
6629 + }
6630 +
6631 + if (pax_insert_vma(vma, call_dl_resolve)) {
6632 + up_write(&current->mm->mmap_sem);
6633 + kmem_cache_free(vm_area_cachep, vma);
6634 + return 1;
6635 + }
6636 +
6637 + current->mm->call_dl_resolve = call_dl_resolve;
6638 + up_write(&current->mm->mmap_sem);
6639 +
6640 +emulate:
6641 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6642 + regs->tpc = call_dl_resolve;
6643 + regs->tnpc = addr+4;
6644 + return 3;
6645 + }
6646 +#endif
6647 +
6648 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6649 + if ((save & 0xFFC00000U) == 0x05000000U &&
6650 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6651 + nop == 0x01000000U)
6652 + {
6653 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6654 + regs->u_regs[UREG_G2] = addr + 4;
6655 + addr = (save & 0x003FFFFFU) << 10;
6656 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6657 +
6658 + if (test_thread_flag(TIF_32BIT))
6659 + addr &= 0xFFFFFFFFUL;
6660 +
6661 + regs->tpc = addr;
6662 + regs->tnpc = addr+4;
6663 + return 3;
6664 + }
6665 +
6666 + /* PaX: 64-bit PLT stub */
6667 + err = get_user(sethi1, (unsigned int *)addr);
6668 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6669 + err |= get_user(or1, (unsigned int *)(addr+8));
6670 + err |= get_user(or2, (unsigned int *)(addr+12));
6671 + err |= get_user(sllx, (unsigned int *)(addr+16));
6672 + err |= get_user(add, (unsigned int *)(addr+20));
6673 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6674 + err |= get_user(nop, (unsigned int *)(addr+28));
6675 + if (err)
6676 + break;
6677 +
6678 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6679 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6680 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6681 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6682 + sllx == 0x89293020U &&
6683 + add == 0x8A010005U &&
6684 + jmpl == 0x89C14000U &&
6685 + nop == 0x01000000U)
6686 + {
6687 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6688 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6689 + regs->u_regs[UREG_G4] <<= 32;
6690 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6691 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6692 + regs->u_regs[UREG_G4] = addr + 24;
6693 + addr = regs->u_regs[UREG_G5];
6694 + regs->tpc = addr;
6695 + regs->tnpc = addr+4;
6696 + return 3;
6697 + }
6698 + }
6699 + } while (0);
6700 +
6701 +#ifdef CONFIG_PAX_DLRESOLVE
6702 + do { /* PaX: unpatched PLT emulation step 2 */
6703 + unsigned int save, call, nop;
6704 +
6705 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6706 + err |= get_user(call, (unsigned int *)regs->tpc);
6707 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6708 + if (err)
6709 + break;
6710 +
6711 + if (save == 0x9DE3BFA8U &&
6712 + (call & 0xC0000000U) == 0x40000000U &&
6713 + nop == 0x01000000U)
6714 + {
6715 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6716 +
6717 + if (test_thread_flag(TIF_32BIT))
6718 + dl_resolve &= 0xFFFFFFFFUL;
6719 +
6720 + regs->u_regs[UREG_RETPC] = regs->tpc;
6721 + regs->tpc = dl_resolve;
6722 + regs->tnpc = dl_resolve+4;
6723 + return 3;
6724 + }
6725 + } while (0);
6726 +#endif
6727 +
6728 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6729 + unsigned int sethi, ba, nop;
6730 +
6731 + err = get_user(sethi, (unsigned int *)regs->tpc);
6732 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6733 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6734 +
6735 + if (err)
6736 + break;
6737 +
6738 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6739 + (ba & 0xFFF00000U) == 0x30600000U &&
6740 + nop == 0x01000000U)
6741 + {
6742 + unsigned long addr;
6743 +
6744 + addr = (sethi & 0x003FFFFFU) << 10;
6745 + regs->u_regs[UREG_G1] = addr;
6746 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6747 +
6748 + if (test_thread_flag(TIF_32BIT))
6749 + addr &= 0xFFFFFFFFUL;
6750 +
6751 + regs->tpc = addr;
6752 + regs->tnpc = addr+4;
6753 + return 2;
6754 + }
6755 + } while (0);
6756 +
6757 +#endif
6758 +
6759 + return 1;
6760 +}
6761 +
6762 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6763 +{
6764 + unsigned long i;
6765 +
6766 + printk(KERN_ERR "PAX: bytes at PC: ");
6767 + for (i = 0; i < 8; i++) {
6768 + unsigned int c;
6769 + if (get_user(c, (unsigned int *)pc+i))
6770 + printk(KERN_CONT "???????? ");
6771 + else
6772 + printk(KERN_CONT "%08x ", c);
6773 + }
6774 + printk("\n");
6775 +}
6776 +#endif
6777 +
6778 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6779 {
6780 struct mm_struct *mm = current->mm;
6781 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6782 if (!vma)
6783 goto bad_area;
6784
6785 +#ifdef CONFIG_PAX_PAGEEXEC
6786 + /* PaX: detect ITLB misses on non-exec pages */
6787 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6788 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6789 + {
6790 + if (address != regs->tpc)
6791 + goto good_area;
6792 +
6793 + up_read(&mm->mmap_sem);
6794 + switch (pax_handle_fetch_fault(regs)) {
6795 +
6796 +#ifdef CONFIG_PAX_EMUPLT
6797 + case 2:
6798 + case 3:
6799 + return;
6800 +#endif
6801 +
6802 + }
6803 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6804 + do_group_exit(SIGKILL);
6805 + }
6806 +#endif
6807 +
6808 /* Pure DTLB misses do not tell us whether the fault causing
6809 * load/store/atomic was a write or not, it only says that there
6810 * was no match. So in such a case we (carefully) read the
6811 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6812 index 07e1453..0a7d9e9 100644
6813 --- a/arch/sparc/mm/hugetlbpage.c
6814 +++ b/arch/sparc/mm/hugetlbpage.c
6815 @@ -67,7 +67,7 @@ full_search:
6816 }
6817 return -ENOMEM;
6818 }
6819 - if (likely(!vma || addr + len <= vma->vm_start)) {
6820 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6821 /*
6822 * Remember the place where we stopped the search:
6823 */
6824 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6825 /* make sure it can fit in the remaining address space */
6826 if (likely(addr > len)) {
6827 vma = find_vma(mm, addr-len);
6828 - if (!vma || addr <= vma->vm_start) {
6829 + if (check_heap_stack_gap(vma, addr - len, len)) {
6830 /* remember the address as a hint for next time */
6831 return (mm->free_area_cache = addr-len);
6832 }
6833 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6834 if (unlikely(mm->mmap_base < len))
6835 goto bottomup;
6836
6837 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6838 + addr = mm->mmap_base - len;
6839
6840 do {
6841 + addr &= HPAGE_MASK;
6842 /*
6843 * Lookup failure means no vma is above this address,
6844 * else if new region fits below vma->vm_start,
6845 * return with success:
6846 */
6847 vma = find_vma(mm, addr);
6848 - if (likely(!vma || addr+len <= vma->vm_start)) {
6849 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6850 /* remember the address as a hint for next time */
6851 return (mm->free_area_cache = addr);
6852 }
6853 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6854 mm->cached_hole_size = vma->vm_start - addr;
6855
6856 /* try just below the current vma->vm_start */
6857 - addr = (vma->vm_start-len) & HPAGE_MASK;
6858 - } while (likely(len < vma->vm_start));
6859 + addr = skip_heap_stack_gap(vma, len);
6860 + } while (!IS_ERR_VALUE(addr));
6861
6862 bottomup:
6863 /*
6864 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6865 if (addr) {
6866 addr = ALIGN(addr, HPAGE_SIZE);
6867 vma = find_vma(mm, addr);
6868 - if (task_size - len >= addr &&
6869 - (!vma || addr + len <= vma->vm_start))
6870 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6871 return addr;
6872 }
6873 if (mm->get_unmapped_area == arch_get_unmapped_area)
6874 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6875 index 7b00de6..78239f4 100644
6876 --- a/arch/sparc/mm/init_32.c
6877 +++ b/arch/sparc/mm/init_32.c
6878 @@ -316,6 +316,9 @@ extern void device_scan(void);
6879 pgprot_t PAGE_SHARED __read_mostly;
6880 EXPORT_SYMBOL(PAGE_SHARED);
6881
6882 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6883 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6884 +
6885 void __init paging_init(void)
6886 {
6887 switch(sparc_cpu_model) {
6888 @@ -344,17 +347,17 @@ void __init paging_init(void)
6889
6890 /* Initialize the protection map with non-constant, MMU dependent values. */
6891 protection_map[0] = PAGE_NONE;
6892 - protection_map[1] = PAGE_READONLY;
6893 - protection_map[2] = PAGE_COPY;
6894 - protection_map[3] = PAGE_COPY;
6895 + protection_map[1] = PAGE_READONLY_NOEXEC;
6896 + protection_map[2] = PAGE_COPY_NOEXEC;
6897 + protection_map[3] = PAGE_COPY_NOEXEC;
6898 protection_map[4] = PAGE_READONLY;
6899 protection_map[5] = PAGE_READONLY;
6900 protection_map[6] = PAGE_COPY;
6901 protection_map[7] = PAGE_COPY;
6902 protection_map[8] = PAGE_NONE;
6903 - protection_map[9] = PAGE_READONLY;
6904 - protection_map[10] = PAGE_SHARED;
6905 - protection_map[11] = PAGE_SHARED;
6906 + protection_map[9] = PAGE_READONLY_NOEXEC;
6907 + protection_map[10] = PAGE_SHARED_NOEXEC;
6908 + protection_map[11] = PAGE_SHARED_NOEXEC;
6909 protection_map[12] = PAGE_READONLY;
6910 protection_map[13] = PAGE_READONLY;
6911 protection_map[14] = PAGE_SHARED;
6912 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6913 index cbef74e..c38fead 100644
6914 --- a/arch/sparc/mm/srmmu.c
6915 +++ b/arch/sparc/mm/srmmu.c
6916 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6917 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6918 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6919 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6920 +
6921 +#ifdef CONFIG_PAX_PAGEEXEC
6922 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6923 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6924 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6925 +#endif
6926 +
6927 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6928 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6929
6930 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6931 index 27fe667..36d474c 100644
6932 --- a/arch/tile/include/asm/atomic_64.h
6933 +++ b/arch/tile/include/asm/atomic_64.h
6934 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6935
6936 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6937
6938 +#define atomic64_read_unchecked(v) atomic64_read(v)
6939 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6940 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6941 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6942 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6943 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6944 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6945 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6946 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6947 +
6948 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6949 #define smp_mb__before_atomic_dec() smp_mb()
6950 #define smp_mb__after_atomic_dec() smp_mb()
6951 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6952 index 392e533..536b092 100644
6953 --- a/arch/tile/include/asm/cache.h
6954 +++ b/arch/tile/include/asm/cache.h
6955 @@ -15,11 +15,12 @@
6956 #ifndef _ASM_TILE_CACHE_H
6957 #define _ASM_TILE_CACHE_H
6958
6959 +#include <linux/const.h>
6960 #include <arch/chip.h>
6961
6962 /* bytes per L1 data cache line */
6963 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6966
6967 /* bytes per L2 cache line */
6968 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6969 diff --git a/arch/um/Makefile b/arch/um/Makefile
6970 index 28688e6..4c0aa1c 100644
6971 --- a/arch/um/Makefile
6972 +++ b/arch/um/Makefile
6973 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6974 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6975 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6976
6977 +ifdef CONSTIFY_PLUGIN
6978 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6979 +endif
6980 +
6981 #This will adjust *FLAGS accordingly to the platform.
6982 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6983
6984 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6985 index 19e1bdd..3665b77 100644
6986 --- a/arch/um/include/asm/cache.h
6987 +++ b/arch/um/include/asm/cache.h
6988 @@ -1,6 +1,7 @@
6989 #ifndef __UM_CACHE_H
6990 #define __UM_CACHE_H
6991
6992 +#include <linux/const.h>
6993
6994 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6995 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6996 @@ -12,6 +13,6 @@
6997 # define L1_CACHE_SHIFT 5
6998 #endif
6999
7000 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7001 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7002
7003 #endif
7004 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7005 index 6c03acd..a5e0215 100644
7006 --- a/arch/um/include/asm/kmap_types.h
7007 +++ b/arch/um/include/asm/kmap_types.h
7008 @@ -23,6 +23,7 @@ enum km_type {
7009 KM_IRQ1,
7010 KM_SOFTIRQ0,
7011 KM_SOFTIRQ1,
7012 + KM_CLEARPAGE,
7013 KM_TYPE_NR
7014 };
7015
7016 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7017 index 7cfc3ce..cbd1a58 100644
7018 --- a/arch/um/include/asm/page.h
7019 +++ b/arch/um/include/asm/page.h
7020 @@ -14,6 +14,9 @@
7021 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7022 #define PAGE_MASK (~(PAGE_SIZE-1))
7023
7024 +#define ktla_ktva(addr) (addr)
7025 +#define ktva_ktla(addr) (addr)
7026 +
7027 #ifndef __ASSEMBLY__
7028
7029 struct page;
7030 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7031 index 69f2490..2634831 100644
7032 --- a/arch/um/kernel/process.c
7033 +++ b/arch/um/kernel/process.c
7034 @@ -408,22 +408,6 @@ int singlestepping(void * t)
7035 return 2;
7036 }
7037
7038 -/*
7039 - * Only x86 and x86_64 have an arch_align_stack().
7040 - * All other arches have "#define arch_align_stack(x) (x)"
7041 - * in their asm/system.h
7042 - * As this is included in UML from asm-um/system-generic.h,
7043 - * we can use it to behave as the subarch does.
7044 - */
7045 -#ifndef arch_align_stack
7046 -unsigned long arch_align_stack(unsigned long sp)
7047 -{
7048 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7049 - sp -= get_random_int() % 8192;
7050 - return sp & ~0xf;
7051 -}
7052 -#endif
7053 -
7054 unsigned long get_wchan(struct task_struct *p)
7055 {
7056 unsigned long stack_page, sp, ip;
7057 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7058 index ad8f795..2c7eec6 100644
7059 --- a/arch/unicore32/include/asm/cache.h
7060 +++ b/arch/unicore32/include/asm/cache.h
7061 @@ -12,8 +12,10 @@
7062 #ifndef __UNICORE_CACHE_H__
7063 #define __UNICORE_CACHE_H__
7064
7065 -#define L1_CACHE_SHIFT (5)
7066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7067 +#include <linux/const.h>
7068 +
7069 +#define L1_CACHE_SHIFT 5
7070 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7071
7072 /*
7073 * Memory returned by kmalloc() may be used for DMA, so we must make
7074 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7075 index 5bed94e..fbcf200 100644
7076 --- a/arch/x86/Kconfig
7077 +++ b/arch/x86/Kconfig
7078 @@ -226,7 +226,7 @@ config X86_HT
7079
7080 config X86_32_LAZY_GS
7081 def_bool y
7082 - depends on X86_32 && !CC_STACKPROTECTOR
7083 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7084
7085 config ARCH_HWEIGHT_CFLAGS
7086 string
7087 @@ -1058,7 +1058,7 @@ choice
7088
7089 config NOHIGHMEM
7090 bool "off"
7091 - depends on !X86_NUMAQ
7092 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7093 ---help---
7094 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7095 However, the address space of 32-bit x86 processors is only 4
7096 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7097
7098 config HIGHMEM4G
7099 bool "4GB"
7100 - depends on !X86_NUMAQ
7101 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7102 ---help---
7103 Select this if you have a 32-bit processor and between 1 and 4
7104 gigabytes of physical RAM.
7105 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7106 hex
7107 default 0xB0000000 if VMSPLIT_3G_OPT
7108 default 0x80000000 if VMSPLIT_2G
7109 - default 0x78000000 if VMSPLIT_2G_OPT
7110 + default 0x70000000 if VMSPLIT_2G_OPT
7111 default 0x40000000 if VMSPLIT_1G
7112 default 0xC0000000
7113 depends on X86_32
7114 @@ -1539,6 +1539,7 @@ config SECCOMP
7115
7116 config CC_STACKPROTECTOR
7117 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7118 + depends on X86_64 || !PAX_MEMORY_UDEREF
7119 ---help---
7120 This option turns on the -fstack-protector GCC feature. This
7121 feature puts, at the beginning of functions, a canary value on
7122 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7123 config PHYSICAL_START
7124 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7125 default "0x1000000"
7126 + range 0x400000 0x40000000
7127 ---help---
7128 This gives the physical address where the kernel is loaded.
7129
7130 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7131 config PHYSICAL_ALIGN
7132 hex "Alignment value to which kernel should be aligned" if X86_32
7133 default "0x1000000"
7134 + range 0x400000 0x1000000 if PAX_KERNEXEC
7135 range 0x2000 0x1000000
7136 ---help---
7137 This value puts the alignment restrictions on physical address
7138 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7139 Say N if you want to disable CPU hotplug.
7140
7141 config COMPAT_VDSO
7142 - def_bool y
7143 + def_bool n
7144 prompt "Compat VDSO support"
7145 depends on X86_32 || IA32_EMULATION
7146 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7147 ---help---
7148 Map the 32-bit VDSO to the predictable old-style address too.
7149
7150 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7151 index 3c57033..22d44aa 100644
7152 --- a/arch/x86/Kconfig.cpu
7153 +++ b/arch/x86/Kconfig.cpu
7154 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7155
7156 config X86_F00F_BUG
7157 def_bool y
7158 - depends on M586MMX || M586TSC || M586 || M486 || M386
7159 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7160
7161 config X86_INVD_BUG
7162 def_bool y
7163 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7164
7165 config X86_ALIGNMENT_16
7166 def_bool y
7167 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7168 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7169
7170 config X86_INTEL_USERCOPY
7171 def_bool y
7172 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7173 # generates cmov.
7174 config X86_CMOV
7175 def_bool y
7176 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7177 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7178
7179 config X86_MINIMUM_CPU_FAMILY
7180 int
7181 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7182 index e46c214..7c72b55 100644
7183 --- a/arch/x86/Kconfig.debug
7184 +++ b/arch/x86/Kconfig.debug
7185 @@ -84,7 +84,7 @@ config X86_PTDUMP
7186 config DEBUG_RODATA
7187 bool "Write protect kernel read-only data structures"
7188 default y
7189 - depends on DEBUG_KERNEL
7190 + depends on DEBUG_KERNEL && BROKEN
7191 ---help---
7192 Mark the kernel read-only data as write-protected in the pagetables,
7193 in order to catch accidental (and incorrect) writes to such const
7194 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7195
7196 config DEBUG_SET_MODULE_RONX
7197 bool "Set loadable kernel module data as NX and text as RO"
7198 - depends on MODULES
7199 + depends on MODULES && BROKEN
7200 ---help---
7201 This option helps catch unintended modifications to loadable
7202 kernel module's text and read-only data. It also prevents execution
7203 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7204 index 209ba12..15140db 100644
7205 --- a/arch/x86/Makefile
7206 +++ b/arch/x86/Makefile
7207 @@ -46,6 +46,7 @@ else
7208 UTS_MACHINE := x86_64
7209 CHECKFLAGS += -D__x86_64__ -m64
7210
7211 + biarch := $(call cc-option,-m64)
7212 KBUILD_AFLAGS += -m64
7213 KBUILD_CFLAGS += -m64
7214
7215 @@ -201,3 +202,12 @@ define archhelp
7216 echo ' FDARGS="..." arguments for the booted kernel'
7217 echo ' FDINITRD=file initrd for the booted kernel'
7218 endef
7219 +
7220 +define OLD_LD
7221 +
7222 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7223 +*** Please upgrade your binutils to 2.18 or newer
7224 +endef
7225 +
7226 +archprepare:
7227 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7228 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7229 index 95365a8..52f857b 100644
7230 --- a/arch/x86/boot/Makefile
7231 +++ b/arch/x86/boot/Makefile
7232 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7233 $(call cc-option, -fno-stack-protector) \
7234 $(call cc-option, -mpreferred-stack-boundary=2)
7235 KBUILD_CFLAGS += $(call cc-option, -m32)
7236 +ifdef CONSTIFY_PLUGIN
7237 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7238 +endif
7239 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7240 GCOV_PROFILE := n
7241
7242 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7243 index 878e4b9..20537ab 100644
7244 --- a/arch/x86/boot/bitops.h
7245 +++ b/arch/x86/boot/bitops.h
7246 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7247 u8 v;
7248 const u32 *p = (const u32 *)addr;
7249
7250 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7251 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7252 return v;
7253 }
7254
7255 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7256
7257 static inline void set_bit(int nr, void *addr)
7258 {
7259 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7260 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7261 }
7262
7263 #endif /* BOOT_BITOPS_H */
7264 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7265 index c7093bd..d4247ffe0 100644
7266 --- a/arch/x86/boot/boot.h
7267 +++ b/arch/x86/boot/boot.h
7268 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7269 static inline u16 ds(void)
7270 {
7271 u16 seg;
7272 - asm("movw %%ds,%0" : "=rm" (seg));
7273 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7274 return seg;
7275 }
7276
7277 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7278 static inline int memcmp(const void *s1, const void *s2, size_t len)
7279 {
7280 u8 diff;
7281 - asm("repe; cmpsb; setnz %0"
7282 + asm volatile("repe; cmpsb; setnz %0"
7283 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7284 return diff;
7285 }
7286 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7287 index b123b9a..2cf2f23 100644
7288 --- a/arch/x86/boot/compressed/Makefile
7289 +++ b/arch/x86/boot/compressed/Makefile
7290 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7291 KBUILD_CFLAGS += $(cflags-y)
7292 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7293 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7294 +ifdef CONSTIFY_PLUGIN
7295 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7296 +endif
7297
7298 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7299 GCOV_PROFILE := n
7300 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7301 index a055993..47e126c 100644
7302 --- a/arch/x86/boot/compressed/head_32.S
7303 +++ b/arch/x86/boot/compressed/head_32.S
7304 @@ -98,7 +98,7 @@ preferred_addr:
7305 notl %eax
7306 andl %eax, %ebx
7307 #else
7308 - movl $LOAD_PHYSICAL_ADDR, %ebx
7309 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7310 #endif
7311
7312 /* Target address to relocate to for decompression */
7313 @@ -184,7 +184,7 @@ relocated:
7314 * and where it was actually loaded.
7315 */
7316 movl %ebp, %ebx
7317 - subl $LOAD_PHYSICAL_ADDR, %ebx
7318 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7319 jz 2f /* Nothing to be done if loaded at compiled addr. */
7320 /*
7321 * Process relocations.
7322 @@ -192,8 +192,7 @@ relocated:
7323
7324 1: subl $4, %edi
7325 movl (%edi), %ecx
7326 - testl %ecx, %ecx
7327 - jz 2f
7328 + jecxz 2f
7329 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7330 jmp 1b
7331 2:
7332 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7333 index 558d76c..606aa24 100644
7334 --- a/arch/x86/boot/compressed/head_64.S
7335 +++ b/arch/x86/boot/compressed/head_64.S
7336 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7337 notl %eax
7338 andl %eax, %ebx
7339 #else
7340 - movl $LOAD_PHYSICAL_ADDR, %ebx
7341 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7342 #endif
7343
7344 /* Target address to relocate to for decompression */
7345 @@ -253,7 +253,7 @@ preferred_addr:
7346 notq %rax
7347 andq %rax, %rbp
7348 #else
7349 - movq $LOAD_PHYSICAL_ADDR, %rbp
7350 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7351 #endif
7352
7353 /* Target address to relocate to for decompression */
7354 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7355 index 7116dcb..d9ae1d7 100644
7356 --- a/arch/x86/boot/compressed/misc.c
7357 +++ b/arch/x86/boot/compressed/misc.c
7358 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7359 case PT_LOAD:
7360 #ifdef CONFIG_RELOCATABLE
7361 dest = output;
7362 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7363 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7364 #else
7365 dest = (void *)(phdr->p_paddr);
7366 #endif
7367 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7368 error("Destination address too large");
7369 #endif
7370 #ifndef CONFIG_RELOCATABLE
7371 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7372 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7373 error("Wrong destination address");
7374 #endif
7375
7376 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7377 index 89bbf4e..869908e 100644
7378 --- a/arch/x86/boot/compressed/relocs.c
7379 +++ b/arch/x86/boot/compressed/relocs.c
7380 @@ -13,8 +13,11 @@
7381
7382 static void die(char *fmt, ...);
7383
7384 +#include "../../../../include/generated/autoconf.h"
7385 +
7386 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7387 static Elf32_Ehdr ehdr;
7388 +static Elf32_Phdr *phdr;
7389 static unsigned long reloc_count, reloc_idx;
7390 static unsigned long *relocs;
7391
7392 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7393 }
7394 }
7395
7396 +static void read_phdrs(FILE *fp)
7397 +{
7398 + unsigned int i;
7399 +
7400 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7401 + if (!phdr) {
7402 + die("Unable to allocate %d program headers\n",
7403 + ehdr.e_phnum);
7404 + }
7405 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7406 + die("Seek to %d failed: %s\n",
7407 + ehdr.e_phoff, strerror(errno));
7408 + }
7409 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7410 + die("Cannot read ELF program headers: %s\n",
7411 + strerror(errno));
7412 + }
7413 + for(i = 0; i < ehdr.e_phnum; i++) {
7414 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7415 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7416 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7417 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7418 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7419 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7420 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7421 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7422 + }
7423 +
7424 +}
7425 +
7426 static void read_shdrs(FILE *fp)
7427 {
7428 - int i;
7429 + unsigned int i;
7430 Elf32_Shdr shdr;
7431
7432 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7433 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7434
7435 static void read_strtabs(FILE *fp)
7436 {
7437 - int i;
7438 + unsigned int i;
7439 for (i = 0; i < ehdr.e_shnum; i++) {
7440 struct section *sec = &secs[i];
7441 if (sec->shdr.sh_type != SHT_STRTAB) {
7442 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7443
7444 static void read_symtabs(FILE *fp)
7445 {
7446 - int i,j;
7447 + unsigned int i,j;
7448 for (i = 0; i < ehdr.e_shnum; i++) {
7449 struct section *sec = &secs[i];
7450 if (sec->shdr.sh_type != SHT_SYMTAB) {
7451 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7452
7453 static void read_relocs(FILE *fp)
7454 {
7455 - int i,j;
7456 + unsigned int i,j;
7457 + uint32_t base;
7458 +
7459 for (i = 0; i < ehdr.e_shnum; i++) {
7460 struct section *sec = &secs[i];
7461 if (sec->shdr.sh_type != SHT_REL) {
7462 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7463 die("Cannot read symbol table: %s\n",
7464 strerror(errno));
7465 }
7466 + base = 0;
7467 + for (j = 0; j < ehdr.e_phnum; j++) {
7468 + if (phdr[j].p_type != PT_LOAD )
7469 + continue;
7470 + 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)
7471 + continue;
7472 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7473 + break;
7474 + }
7475 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7476 Elf32_Rel *rel = &sec->reltab[j];
7477 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7478 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7479 rel->r_info = elf32_to_cpu(rel->r_info);
7480 }
7481 }
7482 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7483
7484 static void print_absolute_symbols(void)
7485 {
7486 - int i;
7487 + unsigned int i;
7488 printf("Absolute symbols\n");
7489 printf(" Num: Value Size Type Bind Visibility Name\n");
7490 for (i = 0; i < ehdr.e_shnum; i++) {
7491 struct section *sec = &secs[i];
7492 char *sym_strtab;
7493 Elf32_Sym *sh_symtab;
7494 - int j;
7495 + unsigned int j;
7496
7497 if (sec->shdr.sh_type != SHT_SYMTAB) {
7498 continue;
7499 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7500
7501 static void print_absolute_relocs(void)
7502 {
7503 - int i, printed = 0;
7504 + unsigned int i, printed = 0;
7505
7506 for (i = 0; i < ehdr.e_shnum; i++) {
7507 struct section *sec = &secs[i];
7508 struct section *sec_applies, *sec_symtab;
7509 char *sym_strtab;
7510 Elf32_Sym *sh_symtab;
7511 - int j;
7512 + unsigned int j;
7513 if (sec->shdr.sh_type != SHT_REL) {
7514 continue;
7515 }
7516 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7517
7518 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7519 {
7520 - int i;
7521 + unsigned int i;
7522 /* Walk through the relocations */
7523 for (i = 0; i < ehdr.e_shnum; i++) {
7524 char *sym_strtab;
7525 Elf32_Sym *sh_symtab;
7526 struct section *sec_applies, *sec_symtab;
7527 - int j;
7528 + unsigned int j;
7529 struct section *sec = &secs[i];
7530
7531 if (sec->shdr.sh_type != SHT_REL) {
7532 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7533 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7534 continue;
7535 }
7536 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7537 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7538 + continue;
7539 +
7540 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7541 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7542 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7543 + continue;
7544 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7545 + continue;
7546 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7547 + continue;
7548 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7549 + continue;
7550 +#endif
7551 +
7552 switch (r_type) {
7553 case R_386_NONE:
7554 case R_386_PC32:
7555 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7556
7557 static void emit_relocs(int as_text)
7558 {
7559 - int i;
7560 + unsigned int i;
7561 /* Count how many relocations I have and allocate space for them. */
7562 reloc_count = 0;
7563 walk_relocs(count_reloc);
7564 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7565 fname, strerror(errno));
7566 }
7567 read_ehdr(fp);
7568 + read_phdrs(fp);
7569 read_shdrs(fp);
7570 read_strtabs(fp);
7571 read_symtabs(fp);
7572 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7573 index 4d3ff03..e4972ff 100644
7574 --- a/arch/x86/boot/cpucheck.c
7575 +++ b/arch/x86/boot/cpucheck.c
7576 @@ -74,7 +74,7 @@ static int has_fpu(void)
7577 u16 fcw = -1, fsw = -1;
7578 u32 cr0;
7579
7580 - asm("movl %%cr0,%0" : "=r" (cr0));
7581 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7582 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7583 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7584 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7585 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7586 {
7587 u32 f0, f1;
7588
7589 - asm("pushfl ; "
7590 + asm volatile("pushfl ; "
7591 "pushfl ; "
7592 "popl %0 ; "
7593 "movl %0,%1 ; "
7594 @@ -115,7 +115,7 @@ static void get_flags(void)
7595 set_bit(X86_FEATURE_FPU, cpu.flags);
7596
7597 if (has_eflag(X86_EFLAGS_ID)) {
7598 - asm("cpuid"
7599 + asm volatile("cpuid"
7600 : "=a" (max_intel_level),
7601 "=b" (cpu_vendor[0]),
7602 "=d" (cpu_vendor[1]),
7603 @@ -124,7 +124,7 @@ static void get_flags(void)
7604
7605 if (max_intel_level >= 0x00000001 &&
7606 max_intel_level <= 0x0000ffff) {
7607 - asm("cpuid"
7608 + asm volatile("cpuid"
7609 : "=a" (tfms),
7610 "=c" (cpu.flags[4]),
7611 "=d" (cpu.flags[0])
7612 @@ -136,7 +136,7 @@ static void get_flags(void)
7613 cpu.model += ((tfms >> 16) & 0xf) << 4;
7614 }
7615
7616 - asm("cpuid"
7617 + asm volatile("cpuid"
7618 : "=a" (max_amd_level)
7619 : "a" (0x80000000)
7620 : "ebx", "ecx", "edx");
7621 @@ -144,7 +144,7 @@ static void get_flags(void)
7622 if (max_amd_level >= 0x80000001 &&
7623 max_amd_level <= 0x8000ffff) {
7624 u32 eax = 0x80000001;
7625 - asm("cpuid"
7626 + asm volatile("cpuid"
7627 : "+a" (eax),
7628 "=c" (cpu.flags[6]),
7629 "=d" (cpu.flags[1])
7630 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7631 u32 ecx = MSR_K7_HWCR;
7632 u32 eax, edx;
7633
7634 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7635 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7636 eax &= ~(1 << 15);
7637 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7638 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7639
7640 get_flags(); /* Make sure it really did something */
7641 err = check_flags();
7642 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7643 u32 ecx = MSR_VIA_FCR;
7644 u32 eax, edx;
7645
7646 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7647 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7648 eax |= (1<<1)|(1<<7);
7649 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7650 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7651
7652 set_bit(X86_FEATURE_CX8, cpu.flags);
7653 err = check_flags();
7654 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7655 u32 eax, edx;
7656 u32 level = 1;
7657
7658 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7659 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7660 - asm("cpuid"
7661 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7662 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7663 + asm volatile("cpuid"
7664 : "+a" (level), "=d" (cpu.flags[0])
7665 : : "ecx", "ebx");
7666 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7667 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7668
7669 err = check_flags();
7670 }
7671 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7672 index f1bbeeb..aff09cb 100644
7673 --- a/arch/x86/boot/header.S
7674 +++ b/arch/x86/boot/header.S
7675 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7676 # single linked list of
7677 # struct setup_data
7678
7679 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7680 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7681
7682 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7683 #define VO_INIT_SIZE (VO__end - VO__text)
7684 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7685 index db75d07..8e6d0af 100644
7686 --- a/arch/x86/boot/memory.c
7687 +++ b/arch/x86/boot/memory.c
7688 @@ -19,7 +19,7 @@
7689
7690 static int detect_memory_e820(void)
7691 {
7692 - int count = 0;
7693 + unsigned int count = 0;
7694 struct biosregs ireg, oreg;
7695 struct e820entry *desc = boot_params.e820_map;
7696 static struct e820entry buf; /* static so it is zeroed */
7697 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7698 index 11e8c6e..fdbb1ed 100644
7699 --- a/arch/x86/boot/video-vesa.c
7700 +++ b/arch/x86/boot/video-vesa.c
7701 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7702
7703 boot_params.screen_info.vesapm_seg = oreg.es;
7704 boot_params.screen_info.vesapm_off = oreg.di;
7705 + boot_params.screen_info.vesapm_size = oreg.cx;
7706 }
7707
7708 /*
7709 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7710 index 43eda28..5ab5fdb 100644
7711 --- a/arch/x86/boot/video.c
7712 +++ b/arch/x86/boot/video.c
7713 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7714 static unsigned int get_entry(void)
7715 {
7716 char entry_buf[4];
7717 - int i, len = 0;
7718 + unsigned int i, len = 0;
7719 int key;
7720 unsigned int v;
7721
7722 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7723 index 5b577d5..3c1fed4 100644
7724 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7725 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7726 @@ -8,6 +8,8 @@
7727 * including this sentence is retained in full.
7728 */
7729
7730 +#include <asm/alternative-asm.h>
7731 +
7732 .extern crypto_ft_tab
7733 .extern crypto_it_tab
7734 .extern crypto_fl_tab
7735 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7736 je B192; \
7737 leaq 32(r9),r9;
7738
7739 +#define ret pax_force_retaddr 0, 1; ret
7740 +
7741 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7742 movq r1,r2; \
7743 movq r3,r4; \
7744 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7745 index be6d9e3..21fbbca 100644
7746 --- a/arch/x86/crypto/aesni-intel_asm.S
7747 +++ b/arch/x86/crypto/aesni-intel_asm.S
7748 @@ -31,6 +31,7 @@
7749
7750 #include <linux/linkage.h>
7751 #include <asm/inst.h>
7752 +#include <asm/alternative-asm.h>
7753
7754 #ifdef __x86_64__
7755 .data
7756 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7757 pop %r14
7758 pop %r13
7759 pop %r12
7760 + pax_force_retaddr 0, 1
7761 ret
7762 +ENDPROC(aesni_gcm_dec)
7763
7764
7765 /*****************************************************************************
7766 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7767 pop %r14
7768 pop %r13
7769 pop %r12
7770 + pax_force_retaddr 0, 1
7771 ret
7772 +ENDPROC(aesni_gcm_enc)
7773
7774 #endif
7775
7776 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7777 pxor %xmm1, %xmm0
7778 movaps %xmm0, (TKEYP)
7779 add $0x10, TKEYP
7780 + pax_force_retaddr_bts
7781 ret
7782
7783 .align 4
7784 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7785 shufps $0b01001110, %xmm2, %xmm1
7786 movaps %xmm1, 0x10(TKEYP)
7787 add $0x20, TKEYP
7788 + pax_force_retaddr_bts
7789 ret
7790
7791 .align 4
7792 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7793
7794 movaps %xmm0, (TKEYP)
7795 add $0x10, TKEYP
7796 + pax_force_retaddr_bts
7797 ret
7798
7799 .align 4
7800 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7801 pxor %xmm1, %xmm2
7802 movaps %xmm2, (TKEYP)
7803 add $0x10, TKEYP
7804 + pax_force_retaddr_bts
7805 ret
7806
7807 /*
7808 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7809 #ifndef __x86_64__
7810 popl KEYP
7811 #endif
7812 + pax_force_retaddr 0, 1
7813 ret
7814 +ENDPROC(aesni_set_key)
7815
7816 /*
7817 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7818 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7819 popl KLEN
7820 popl KEYP
7821 #endif
7822 + pax_force_retaddr 0, 1
7823 ret
7824 +ENDPROC(aesni_enc)
7825
7826 /*
7827 * _aesni_enc1: internal ABI
7828 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7829 AESENC KEY STATE
7830 movaps 0x70(TKEYP), KEY
7831 AESENCLAST KEY STATE
7832 + pax_force_retaddr_bts
7833 ret
7834
7835 /*
7836 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7837 AESENCLAST KEY STATE2
7838 AESENCLAST KEY STATE3
7839 AESENCLAST KEY STATE4
7840 + pax_force_retaddr_bts
7841 ret
7842
7843 /*
7844 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7845 popl KLEN
7846 popl KEYP
7847 #endif
7848 + pax_force_retaddr 0, 1
7849 ret
7850 +ENDPROC(aesni_dec)
7851
7852 /*
7853 * _aesni_dec1: internal ABI
7854 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7855 AESDEC KEY STATE
7856 movaps 0x70(TKEYP), KEY
7857 AESDECLAST KEY STATE
7858 + pax_force_retaddr_bts
7859 ret
7860
7861 /*
7862 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7863 AESDECLAST KEY STATE2
7864 AESDECLAST KEY STATE3
7865 AESDECLAST KEY STATE4
7866 + pax_force_retaddr_bts
7867 ret
7868
7869 /*
7870 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7871 popl KEYP
7872 popl LEN
7873 #endif
7874 + pax_force_retaddr 0, 1
7875 ret
7876 +ENDPROC(aesni_ecb_enc)
7877
7878 /*
7879 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7880 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7881 popl KEYP
7882 popl LEN
7883 #endif
7884 + pax_force_retaddr 0, 1
7885 ret
7886 +ENDPROC(aesni_ecb_dec)
7887
7888 /*
7889 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7890 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7891 popl LEN
7892 popl IVP
7893 #endif
7894 + pax_force_retaddr 0, 1
7895 ret
7896 +ENDPROC(aesni_cbc_enc)
7897
7898 /*
7899 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7900 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7901 popl LEN
7902 popl IVP
7903 #endif
7904 + pax_force_retaddr 0, 1
7905 ret
7906 +ENDPROC(aesni_cbc_dec)
7907
7908 #ifdef __x86_64__
7909 .align 16
7910 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7911 mov $1, TCTR_LOW
7912 MOVQ_R64_XMM TCTR_LOW INC
7913 MOVQ_R64_XMM CTR TCTR_LOW
7914 + pax_force_retaddr_bts
7915 ret
7916
7917 /*
7918 @@ -2552,6 +2580,7 @@ _aesni_inc:
7919 .Linc_low:
7920 movaps CTR, IV
7921 PSHUFB_XMM BSWAP_MASK IV
7922 + pax_force_retaddr_bts
7923 ret
7924
7925 /*
7926 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7927 .Lctr_enc_ret:
7928 movups IV, (IVP)
7929 .Lctr_enc_just_ret:
7930 + pax_force_retaddr 0, 1
7931 ret
7932 +ENDPROC(aesni_ctr_enc)
7933 #endif
7934 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
7935 index 545d0ce..14841a6 100644
7936 --- a/arch/x86/crypto/aesni-intel_glue.c
7937 +++ b/arch/x86/crypto/aesni-intel_glue.c
7938 @@ -929,6 +929,8 @@ out_free_ablkcipher:
7939 }
7940
7941 static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
7942 + unsigned int key_len) __size_overflow(3);
7943 +static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
7944 unsigned int key_len)
7945 {
7946 int ret = 0;
7947 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7948 index 391d245..67f35c2 100644
7949 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7950 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7951 @@ -20,6 +20,8 @@
7952 *
7953 */
7954
7955 +#include <asm/alternative-asm.h>
7956 +
7957 .file "blowfish-x86_64-asm.S"
7958 .text
7959
7960 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7961 jnz __enc_xor;
7962
7963 write_block();
7964 + pax_force_retaddr 0, 1
7965 ret;
7966 __enc_xor:
7967 xor_block();
7968 + pax_force_retaddr 0, 1
7969 ret;
7970
7971 .align 8
7972 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7973
7974 movq %r11, %rbp;
7975
7976 + pax_force_retaddr 0, 1
7977 ret;
7978
7979 /**********************************************************************
7980 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7981
7982 popq %rbx;
7983 popq %rbp;
7984 + pax_force_retaddr 0, 1
7985 ret;
7986
7987 __enc_xor4:
7988 @@ -349,6 +355,7 @@ __enc_xor4:
7989
7990 popq %rbx;
7991 popq %rbp;
7992 + pax_force_retaddr 0, 1
7993 ret;
7994
7995 .align 8
7996 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7997 popq %rbx;
7998 popq %rbp;
7999
8000 + pax_force_retaddr 0, 1
8001 ret;
8002
8003 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8004 index 6214a9b..1f4fc9a 100644
8005 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8006 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8007 @@ -1,3 +1,5 @@
8008 +#include <asm/alternative-asm.h>
8009 +
8010 # enter ECRYPT_encrypt_bytes
8011 .text
8012 .p2align 5
8013 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8014 add %r11,%rsp
8015 mov %rdi,%rax
8016 mov %rsi,%rdx
8017 + pax_force_retaddr 0, 1
8018 ret
8019 # bytesatleast65:
8020 ._bytesatleast65:
8021 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8022 add %r11,%rsp
8023 mov %rdi,%rax
8024 mov %rsi,%rdx
8025 + pax_force_retaddr
8026 ret
8027 # enter ECRYPT_ivsetup
8028 .text
8029 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8030 add %r11,%rsp
8031 mov %rdi,%rax
8032 mov %rsi,%rdx
8033 + pax_force_retaddr
8034 ret
8035 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8036 index 7f24a15..9cd3ffe 100644
8037 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8038 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8039 @@ -24,6 +24,8 @@
8040 *
8041 */
8042
8043 +#include <asm/alternative-asm.h>
8044 +
8045 .file "serpent-sse2-x86_64-asm_64.S"
8046 .text
8047
8048 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8049 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8050 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8051
8052 + pax_force_retaddr
8053 ret;
8054
8055 __enc_xor8:
8056 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8057 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8058
8059 + pax_force_retaddr
8060 ret;
8061
8062 .align 8
8063 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8064 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8065 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8066
8067 + pax_force_retaddr
8068 ret;
8069 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8070 index b2c2f57..8470cab 100644
8071 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8072 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8073 @@ -28,6 +28,8 @@
8074 * (at your option) any later version.
8075 */
8076
8077 +#include <asm/alternative-asm.h>
8078 +
8079 #define CTX %rdi // arg1
8080 #define BUF %rsi // arg2
8081 #define CNT %rdx // arg3
8082 @@ -104,6 +106,7 @@
8083 pop %r12
8084 pop %rbp
8085 pop %rbx
8086 + pax_force_retaddr 0, 1
8087 ret
8088
8089 .size \name, .-\name
8090 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8091 index 5b012a2..36d5364 100644
8092 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8093 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8094 @@ -20,6 +20,8 @@
8095 *
8096 */
8097
8098 +#include <asm/alternative-asm.h>
8099 +
8100 .file "twofish-x86_64-asm-3way.S"
8101 .text
8102
8103 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8104 popq %r13;
8105 popq %r14;
8106 popq %r15;
8107 + pax_force_retaddr 0, 1
8108 ret;
8109
8110 __enc_xor3:
8111 @@ -271,6 +274,7 @@ __enc_xor3:
8112 popq %r13;
8113 popq %r14;
8114 popq %r15;
8115 + pax_force_retaddr 0, 1
8116 ret;
8117
8118 .global twofish_dec_blk_3way
8119 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8120 popq %r13;
8121 popq %r14;
8122 popq %r15;
8123 + pax_force_retaddr 0, 1
8124 ret;
8125
8126 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8127 index 7bcf3fc..f53832f 100644
8128 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8129 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8130 @@ -21,6 +21,7 @@
8131 .text
8132
8133 #include <asm/asm-offsets.h>
8134 +#include <asm/alternative-asm.h>
8135
8136 #define a_offset 0
8137 #define b_offset 4
8138 @@ -268,6 +269,7 @@ twofish_enc_blk:
8139
8140 popq R1
8141 movq $1,%rax
8142 + pax_force_retaddr 0, 1
8143 ret
8144
8145 twofish_dec_blk:
8146 @@ -319,4 +321,5 @@ twofish_dec_blk:
8147
8148 popq R1
8149 movq $1,%rax
8150 + pax_force_retaddr 0, 1
8151 ret
8152 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8153 index 39e4909..887aa7e 100644
8154 --- a/arch/x86/ia32/ia32_aout.c
8155 +++ b/arch/x86/ia32/ia32_aout.c
8156 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8157 unsigned long dump_start, dump_size;
8158 struct user32 dump;
8159
8160 + memset(&dump, 0, sizeof(dump));
8161 +
8162 fs = get_fs();
8163 set_fs(KERNEL_DS);
8164 has_dumped = 1;
8165 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8166 index 6557769..ef6ae89 100644
8167 --- a/arch/x86/ia32/ia32_signal.c
8168 +++ b/arch/x86/ia32/ia32_signal.c
8169 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8170 }
8171 seg = get_fs();
8172 set_fs(KERNEL_DS);
8173 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8174 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8175 set_fs(seg);
8176 if (ret >= 0 && uoss_ptr) {
8177 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8178 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8179 */
8180 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8181 size_t frame_size,
8182 - void **fpstate)
8183 + void __user **fpstate)
8184 {
8185 unsigned long sp;
8186
8187 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8188
8189 if (used_math()) {
8190 sp = sp - sig_xstate_ia32_size;
8191 - *fpstate = (struct _fpstate_ia32 *) sp;
8192 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8193 if (save_i387_xstate_ia32(*fpstate) < 0)
8194 return (void __user *) -1L;
8195 }
8196 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8197 sp -= frame_size;
8198 /* Align the stack pointer according to the i386 ABI,
8199 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8200 - sp = ((sp + 4) & -16ul) - 4;
8201 + sp = ((sp - 12) & -16ul) - 4;
8202 return (void __user *) sp;
8203 }
8204
8205 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8206 * These are actually not used anymore, but left because some
8207 * gdb versions depend on them as a marker.
8208 */
8209 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8210 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8211 } put_user_catch(err);
8212
8213 if (err)
8214 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8215 0xb8,
8216 __NR_ia32_rt_sigreturn,
8217 0x80cd,
8218 - 0,
8219 + 0
8220 };
8221
8222 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8223 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8224
8225 if (ka->sa.sa_flags & SA_RESTORER)
8226 restorer = ka->sa.sa_restorer;
8227 + else if (current->mm->context.vdso)
8228 + /* Return stub is in 32bit vsyscall page */
8229 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8230 else
8231 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8232 - rt_sigreturn);
8233 + restorer = &frame->retcode;
8234 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8235
8236 /*
8237 * Not actually used anymore, but left because some gdb
8238 * versions need it.
8239 */
8240 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8241 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8242 } put_user_catch(err);
8243
8244 if (err)
8245 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8246 index e3e7340..05ed805 100644
8247 --- a/arch/x86/ia32/ia32entry.S
8248 +++ b/arch/x86/ia32/ia32entry.S
8249 @@ -13,8 +13,10 @@
8250 #include <asm/thread_info.h>
8251 #include <asm/segment.h>
8252 #include <asm/irqflags.h>
8253 +#include <asm/pgtable.h>
8254 #include <linux/linkage.h>
8255 #include <linux/err.h>
8256 +#include <asm/alternative-asm.h>
8257
8258 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8259 #include <linux/elf-em.h>
8260 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8261 ENDPROC(native_irq_enable_sysexit)
8262 #endif
8263
8264 + .macro pax_enter_kernel_user
8265 + pax_set_fptr_mask
8266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8267 + call pax_enter_kernel_user
8268 +#endif
8269 + .endm
8270 +
8271 + .macro pax_exit_kernel_user
8272 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8273 + call pax_exit_kernel_user
8274 +#endif
8275 +#ifdef CONFIG_PAX_RANDKSTACK
8276 + pushq %rax
8277 + pushq %r11
8278 + call pax_randomize_kstack
8279 + popq %r11
8280 + popq %rax
8281 +#endif
8282 + .endm
8283 +
8284 +.macro pax_erase_kstack
8285 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8286 + call pax_erase_kstack
8287 +#endif
8288 +.endm
8289 +
8290 /*
8291 * 32bit SYSENTER instruction entry.
8292 *
8293 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8294 CFI_REGISTER rsp,rbp
8295 SWAPGS_UNSAFE_STACK
8296 movq PER_CPU_VAR(kernel_stack), %rsp
8297 - addq $(KERNEL_STACK_OFFSET),%rsp
8298 - /*
8299 - * No need to follow this irqs on/off section: the syscall
8300 - * disabled irqs, here we enable it straight after entry:
8301 - */
8302 - ENABLE_INTERRUPTS(CLBR_NONE)
8303 movl %ebp,%ebp /* zero extension */
8304 pushq_cfi $__USER32_DS
8305 /*CFI_REL_OFFSET ss,0*/
8306 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8307 CFI_REL_OFFSET rsp,0
8308 pushfq_cfi
8309 /*CFI_REL_OFFSET rflags,0*/
8310 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8311 - CFI_REGISTER rip,r10
8312 + orl $X86_EFLAGS_IF,(%rsp)
8313 + GET_THREAD_INFO(%r11)
8314 + movl TI_sysenter_return(%r11), %r11d
8315 + CFI_REGISTER rip,r11
8316 pushq_cfi $__USER32_CS
8317 /*CFI_REL_OFFSET cs,0*/
8318 movl %eax, %eax
8319 - pushq_cfi %r10
8320 + pushq_cfi %r11
8321 CFI_REL_OFFSET rip,0
8322 pushq_cfi %rax
8323 cld
8324 SAVE_ARGS 0,1,0
8325 + pax_enter_kernel_user
8326 + /*
8327 + * No need to follow this irqs on/off section: the syscall
8328 + * disabled irqs, here we enable it straight after entry:
8329 + */
8330 + ENABLE_INTERRUPTS(CLBR_NONE)
8331 /* no need to do an access_ok check here because rbp has been
8332 32bit zero extended */
8333 +
8334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8335 + mov $PAX_USER_SHADOW_BASE,%r11
8336 + add %r11,%rbp
8337 +#endif
8338 +
8339 1: movl (%rbp),%ebp
8340 .section __ex_table,"a"
8341 .quad 1b,ia32_badarg
8342 .previous
8343 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8344 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8345 + GET_THREAD_INFO(%r11)
8346 + orl $TS_COMPAT,TI_status(%r11)
8347 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8348 CFI_REMEMBER_STATE
8349 jnz sysenter_tracesys
8350 cmpq $(IA32_NR_syscalls-1),%rax
8351 @@ -160,12 +197,15 @@ sysenter_do_call:
8352 sysenter_dispatch:
8353 call *ia32_sys_call_table(,%rax,8)
8354 movq %rax,RAX-ARGOFFSET(%rsp)
8355 + GET_THREAD_INFO(%r11)
8356 DISABLE_INTERRUPTS(CLBR_NONE)
8357 TRACE_IRQS_OFF
8358 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8359 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8360 jnz sysexit_audit
8361 sysexit_from_sys_call:
8362 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8363 + pax_exit_kernel_user
8364 + pax_erase_kstack
8365 + andl $~TS_COMPAT,TI_status(%r11)
8366 /* clear IF, that popfq doesn't enable interrupts early */
8367 andl $~0x200,EFLAGS-R11(%rsp)
8368 movl RIP-R11(%rsp),%edx /* User %eip */
8369 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8370 movl %eax,%esi /* 2nd arg: syscall number */
8371 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8372 call __audit_syscall_entry
8373 +
8374 + pax_erase_kstack
8375 +
8376 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8377 cmpq $(IA32_NR_syscalls-1),%rax
8378 ja ia32_badsys
8379 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8380 .endm
8381
8382 .macro auditsys_exit exit
8383 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8384 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8385 jnz ia32_ret_from_sys_call
8386 TRACE_IRQS_ON
8387 sti
8388 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8389 1: setbe %al /* 1 if error, 0 if not */
8390 movzbl %al,%edi /* zero-extend that into %edi */
8391 call __audit_syscall_exit
8392 + GET_THREAD_INFO(%r11)
8393 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8394 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8395 cli
8396 TRACE_IRQS_OFF
8397 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8398 + testl %edi,TI_flags(%r11)
8399 jz \exit
8400 CLEAR_RREGS -ARGOFFSET
8401 jmp int_with_check
8402 @@ -235,7 +279,7 @@ sysexit_audit:
8403
8404 sysenter_tracesys:
8405 #ifdef CONFIG_AUDITSYSCALL
8406 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8407 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8408 jz sysenter_auditsys
8409 #endif
8410 SAVE_REST
8411 @@ -243,6 +287,9 @@ sysenter_tracesys:
8412 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8413 movq %rsp,%rdi /* &pt_regs -> arg1 */
8414 call syscall_trace_enter
8415 +
8416 + pax_erase_kstack
8417 +
8418 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8419 RESTORE_REST
8420 cmpq $(IA32_NR_syscalls-1),%rax
8421 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8422 ENTRY(ia32_cstar_target)
8423 CFI_STARTPROC32 simple
8424 CFI_SIGNAL_FRAME
8425 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8426 + CFI_DEF_CFA rsp,0
8427 CFI_REGISTER rip,rcx
8428 /*CFI_REGISTER rflags,r11*/
8429 SWAPGS_UNSAFE_STACK
8430 movl %esp,%r8d
8431 CFI_REGISTER rsp,r8
8432 movq PER_CPU_VAR(kernel_stack),%rsp
8433 + SAVE_ARGS 8*6,0,0
8434 + pax_enter_kernel_user
8435 /*
8436 * No need to follow this irqs on/off section: the syscall
8437 * disabled irqs and here we enable it straight after entry:
8438 */
8439 ENABLE_INTERRUPTS(CLBR_NONE)
8440 - SAVE_ARGS 8,0,0
8441 movl %eax,%eax /* zero extension */
8442 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8443 movq %rcx,RIP-ARGOFFSET(%rsp)
8444 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8445 /* no need to do an access_ok check here because r8 has been
8446 32bit zero extended */
8447 /* hardware stack frame is complete now */
8448 +
8449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8450 + mov $PAX_USER_SHADOW_BASE,%r11
8451 + add %r11,%r8
8452 +#endif
8453 +
8454 1: movl (%r8),%r9d
8455 .section __ex_table,"a"
8456 .quad 1b,ia32_badarg
8457 .previous
8458 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8459 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8460 + GET_THREAD_INFO(%r11)
8461 + orl $TS_COMPAT,TI_status(%r11)
8462 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8463 CFI_REMEMBER_STATE
8464 jnz cstar_tracesys
8465 cmpq $IA32_NR_syscalls-1,%rax
8466 @@ -317,12 +372,15 @@ cstar_do_call:
8467 cstar_dispatch:
8468 call *ia32_sys_call_table(,%rax,8)
8469 movq %rax,RAX-ARGOFFSET(%rsp)
8470 + GET_THREAD_INFO(%r11)
8471 DISABLE_INTERRUPTS(CLBR_NONE)
8472 TRACE_IRQS_OFF
8473 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8474 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8475 jnz sysretl_audit
8476 sysretl_from_sys_call:
8477 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8478 + pax_exit_kernel_user
8479 + pax_erase_kstack
8480 + andl $~TS_COMPAT,TI_status(%r11)
8481 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8482 movl RIP-ARGOFFSET(%rsp),%ecx
8483 CFI_REGISTER rip,rcx
8484 @@ -350,7 +408,7 @@ sysretl_audit:
8485
8486 cstar_tracesys:
8487 #ifdef CONFIG_AUDITSYSCALL
8488 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8489 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8490 jz cstar_auditsys
8491 #endif
8492 xchgl %r9d,%ebp
8493 @@ -359,6 +417,9 @@ cstar_tracesys:
8494 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8495 movq %rsp,%rdi /* &pt_regs -> arg1 */
8496 call syscall_trace_enter
8497 +
8498 + pax_erase_kstack
8499 +
8500 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8501 RESTORE_REST
8502 xchgl %ebp,%r9d
8503 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8504 CFI_REL_OFFSET rip,RIP-RIP
8505 PARAVIRT_ADJUST_EXCEPTION_FRAME
8506 SWAPGS
8507 - /*
8508 - * No need to follow this irqs on/off section: the syscall
8509 - * disabled irqs and here we enable it straight after entry:
8510 - */
8511 - ENABLE_INTERRUPTS(CLBR_NONE)
8512 movl %eax,%eax
8513 pushq_cfi %rax
8514 cld
8515 /* note the registers are not zero extended to the sf.
8516 this could be a problem. */
8517 SAVE_ARGS 0,1,0
8518 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8519 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8520 + pax_enter_kernel_user
8521 + /*
8522 + * No need to follow this irqs on/off section: the syscall
8523 + * disabled irqs and here we enable it straight after entry:
8524 + */
8525 + ENABLE_INTERRUPTS(CLBR_NONE)
8526 + GET_THREAD_INFO(%r11)
8527 + orl $TS_COMPAT,TI_status(%r11)
8528 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8529 jnz ia32_tracesys
8530 cmpq $(IA32_NR_syscalls-1),%rax
8531 ja ia32_badsys
8532 @@ -435,6 +498,9 @@ ia32_tracesys:
8533 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8534 movq %rsp,%rdi /* &pt_regs -> arg1 */
8535 call syscall_trace_enter
8536 +
8537 + pax_erase_kstack
8538 +
8539 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8540 RESTORE_REST
8541 cmpq $(IA32_NR_syscalls-1),%rax
8542 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8543 index f6f5c53..b358b28 100644
8544 --- a/arch/x86/ia32/sys_ia32.c
8545 +++ b/arch/x86/ia32/sys_ia32.c
8546 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8547 */
8548 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8549 {
8550 - typeof(ubuf->st_uid) uid = 0;
8551 - typeof(ubuf->st_gid) gid = 0;
8552 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8553 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8554 SET_UID(uid, stat->uid);
8555 SET_GID(gid, stat->gid);
8556 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8557 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8558 }
8559 set_fs(KERNEL_DS);
8560 ret = sys_rt_sigprocmask(how,
8561 - set ? (sigset_t __user *)&s : NULL,
8562 - oset ? (sigset_t __user *)&s : NULL,
8563 + set ? (sigset_t __force_user *)&s : NULL,
8564 + oset ? (sigset_t __force_user *)&s : NULL,
8565 sigsetsize);
8566 set_fs(old_fs);
8567 if (ret)
8568 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8569 return alarm_setitimer(seconds);
8570 }
8571
8572 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8573 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8574 int options)
8575 {
8576 return compat_sys_wait4(pid, stat_addr, options, NULL);
8577 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8578 mm_segment_t old_fs = get_fs();
8579
8580 set_fs(KERNEL_DS);
8581 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8582 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8583 set_fs(old_fs);
8584 if (put_compat_timespec(&t, interval))
8585 return -EFAULT;
8586 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8587 mm_segment_t old_fs = get_fs();
8588
8589 set_fs(KERNEL_DS);
8590 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8591 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8592 set_fs(old_fs);
8593 if (!ret) {
8594 switch (_NSIG_WORDS) {
8595 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8596 if (copy_siginfo_from_user32(&info, uinfo))
8597 return -EFAULT;
8598 set_fs(KERNEL_DS);
8599 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8600 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8601 set_fs(old_fs);
8602 return ret;
8603 }
8604 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8605 return -EFAULT;
8606
8607 set_fs(KERNEL_DS);
8608 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8609 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8610 count);
8611 set_fs(old_fs);
8612
8613 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8614 index 952bd01..7692c6f 100644
8615 --- a/arch/x86/include/asm/alternative-asm.h
8616 +++ b/arch/x86/include/asm/alternative-asm.h
8617 @@ -15,6 +15,45 @@
8618 .endm
8619 #endif
8620
8621 +#ifdef KERNEXEC_PLUGIN
8622 + .macro pax_force_retaddr_bts rip=0
8623 + btsq $63,\rip(%rsp)
8624 + .endm
8625 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8626 + .macro pax_force_retaddr rip=0, reload=0
8627 + btsq $63,\rip(%rsp)
8628 + .endm
8629 + .macro pax_force_fptr ptr
8630 + btsq $63,\ptr
8631 + .endm
8632 + .macro pax_set_fptr_mask
8633 + .endm
8634 +#endif
8635 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8636 + .macro pax_force_retaddr rip=0, reload=0
8637 + .if \reload
8638 + pax_set_fptr_mask
8639 + .endif
8640 + orq %r10,\rip(%rsp)
8641 + .endm
8642 + .macro pax_force_fptr ptr
8643 + orq %r10,\ptr
8644 + .endm
8645 + .macro pax_set_fptr_mask
8646 + movabs $0x8000000000000000,%r10
8647 + .endm
8648 +#endif
8649 +#else
8650 + .macro pax_force_retaddr rip=0, reload=0
8651 + .endm
8652 + .macro pax_force_fptr ptr
8653 + .endm
8654 + .macro pax_force_retaddr_bts rip=0
8655 + .endm
8656 + .macro pax_set_fptr_mask
8657 + .endm
8658 +#endif
8659 +
8660 .macro altinstruction_entry orig alt feature orig_len alt_len
8661 .long \orig - .
8662 .long \alt - .
8663 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8664 index 37ad100..7d47faa 100644
8665 --- a/arch/x86/include/asm/alternative.h
8666 +++ b/arch/x86/include/asm/alternative.h
8667 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8668 ".section .discard,\"aw\",@progbits\n" \
8669 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8670 ".previous\n" \
8671 - ".section .altinstr_replacement, \"ax\"\n" \
8672 + ".section .altinstr_replacement, \"a\"\n" \
8673 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8674 ".previous"
8675
8676 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8677 index 3ab9bdd..238033e 100644
8678 --- a/arch/x86/include/asm/apic.h
8679 +++ b/arch/x86/include/asm/apic.h
8680 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8681
8682 #ifdef CONFIG_X86_LOCAL_APIC
8683
8684 -extern unsigned int apic_verbosity;
8685 +extern int apic_verbosity;
8686 extern int local_apic_timer_c2_ok;
8687
8688 extern int disable_apic;
8689 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8690 index 20370c6..a2eb9b0 100644
8691 --- a/arch/x86/include/asm/apm.h
8692 +++ b/arch/x86/include/asm/apm.h
8693 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8694 __asm__ __volatile__(APM_DO_ZERO_SEGS
8695 "pushl %%edi\n\t"
8696 "pushl %%ebp\n\t"
8697 - "lcall *%%cs:apm_bios_entry\n\t"
8698 + "lcall *%%ss:apm_bios_entry\n\t"
8699 "setc %%al\n\t"
8700 "popl %%ebp\n\t"
8701 "popl %%edi\n\t"
8702 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8703 __asm__ __volatile__(APM_DO_ZERO_SEGS
8704 "pushl %%edi\n\t"
8705 "pushl %%ebp\n\t"
8706 - "lcall *%%cs:apm_bios_entry\n\t"
8707 + "lcall *%%ss:apm_bios_entry\n\t"
8708 "setc %%bl\n\t"
8709 "popl %%ebp\n\t"
8710 "popl %%edi\n\t"
8711 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8712 index 58cb6d4..ca9010d 100644
8713 --- a/arch/x86/include/asm/atomic.h
8714 +++ b/arch/x86/include/asm/atomic.h
8715 @@ -22,7 +22,18 @@
8716 */
8717 static inline int atomic_read(const atomic_t *v)
8718 {
8719 - return (*(volatile int *)&(v)->counter);
8720 + return (*(volatile const int *)&(v)->counter);
8721 +}
8722 +
8723 +/**
8724 + * atomic_read_unchecked - read atomic variable
8725 + * @v: pointer of type atomic_unchecked_t
8726 + *
8727 + * Atomically reads the value of @v.
8728 + */
8729 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8730 +{
8731 + return (*(volatile const int *)&(v)->counter);
8732 }
8733
8734 /**
8735 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8736 }
8737
8738 /**
8739 + * atomic_set_unchecked - set atomic variable
8740 + * @v: pointer of type atomic_unchecked_t
8741 + * @i: required value
8742 + *
8743 + * Atomically sets the value of @v to @i.
8744 + */
8745 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8746 +{
8747 + v->counter = i;
8748 +}
8749 +
8750 +/**
8751 * atomic_add - add integer to atomic variable
8752 * @i: integer value to add
8753 * @v: pointer of type atomic_t
8754 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8755 */
8756 static inline void atomic_add(int i, atomic_t *v)
8757 {
8758 - asm volatile(LOCK_PREFIX "addl %1,%0"
8759 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8760 +
8761 +#ifdef CONFIG_PAX_REFCOUNT
8762 + "jno 0f\n"
8763 + LOCK_PREFIX "subl %1,%0\n"
8764 + "int $4\n0:\n"
8765 + _ASM_EXTABLE(0b, 0b)
8766 +#endif
8767 +
8768 + : "+m" (v->counter)
8769 + : "ir" (i));
8770 +}
8771 +
8772 +/**
8773 + * atomic_add_unchecked - add integer to atomic variable
8774 + * @i: integer value to add
8775 + * @v: pointer of type atomic_unchecked_t
8776 + *
8777 + * Atomically adds @i to @v.
8778 + */
8779 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8780 +{
8781 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8782 : "+m" (v->counter)
8783 : "ir" (i));
8784 }
8785 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8786 */
8787 static inline void atomic_sub(int i, atomic_t *v)
8788 {
8789 - asm volatile(LOCK_PREFIX "subl %1,%0"
8790 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8791 +
8792 +#ifdef CONFIG_PAX_REFCOUNT
8793 + "jno 0f\n"
8794 + LOCK_PREFIX "addl %1,%0\n"
8795 + "int $4\n0:\n"
8796 + _ASM_EXTABLE(0b, 0b)
8797 +#endif
8798 +
8799 + : "+m" (v->counter)
8800 + : "ir" (i));
8801 +}
8802 +
8803 +/**
8804 + * atomic_sub_unchecked - subtract integer from atomic variable
8805 + * @i: integer value to subtract
8806 + * @v: pointer of type atomic_unchecked_t
8807 + *
8808 + * Atomically subtracts @i from @v.
8809 + */
8810 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8811 +{
8812 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8813 : "+m" (v->counter)
8814 : "ir" (i));
8815 }
8816 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8817 {
8818 unsigned char c;
8819
8820 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8821 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8822 +
8823 +#ifdef CONFIG_PAX_REFCOUNT
8824 + "jno 0f\n"
8825 + LOCK_PREFIX "addl %2,%0\n"
8826 + "int $4\n0:\n"
8827 + _ASM_EXTABLE(0b, 0b)
8828 +#endif
8829 +
8830 + "sete %1\n"
8831 : "+m" (v->counter), "=qm" (c)
8832 : "ir" (i) : "memory");
8833 return c;
8834 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8835 */
8836 static inline void atomic_inc(atomic_t *v)
8837 {
8838 - asm volatile(LOCK_PREFIX "incl %0"
8839 + asm volatile(LOCK_PREFIX "incl %0\n"
8840 +
8841 +#ifdef CONFIG_PAX_REFCOUNT
8842 + "jno 0f\n"
8843 + LOCK_PREFIX "decl %0\n"
8844 + "int $4\n0:\n"
8845 + _ASM_EXTABLE(0b, 0b)
8846 +#endif
8847 +
8848 + : "+m" (v->counter));
8849 +}
8850 +
8851 +/**
8852 + * atomic_inc_unchecked - increment atomic variable
8853 + * @v: pointer of type atomic_unchecked_t
8854 + *
8855 + * Atomically increments @v by 1.
8856 + */
8857 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8858 +{
8859 + asm volatile(LOCK_PREFIX "incl %0\n"
8860 : "+m" (v->counter));
8861 }
8862
8863 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8864 */
8865 static inline void atomic_dec(atomic_t *v)
8866 {
8867 - asm volatile(LOCK_PREFIX "decl %0"
8868 + asm volatile(LOCK_PREFIX "decl %0\n"
8869 +
8870 +#ifdef CONFIG_PAX_REFCOUNT
8871 + "jno 0f\n"
8872 + LOCK_PREFIX "incl %0\n"
8873 + "int $4\n0:\n"
8874 + _ASM_EXTABLE(0b, 0b)
8875 +#endif
8876 +
8877 + : "+m" (v->counter));
8878 +}
8879 +
8880 +/**
8881 + * atomic_dec_unchecked - decrement atomic variable
8882 + * @v: pointer of type atomic_unchecked_t
8883 + *
8884 + * Atomically decrements @v by 1.
8885 + */
8886 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8887 +{
8888 + asm volatile(LOCK_PREFIX "decl %0\n"
8889 : "+m" (v->counter));
8890 }
8891
8892 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8893 {
8894 unsigned char c;
8895
8896 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8897 + asm volatile(LOCK_PREFIX "decl %0\n"
8898 +
8899 +#ifdef CONFIG_PAX_REFCOUNT
8900 + "jno 0f\n"
8901 + LOCK_PREFIX "incl %0\n"
8902 + "int $4\n0:\n"
8903 + _ASM_EXTABLE(0b, 0b)
8904 +#endif
8905 +
8906 + "sete %1\n"
8907 : "+m" (v->counter), "=qm" (c)
8908 : : "memory");
8909 return c != 0;
8910 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8911 {
8912 unsigned char c;
8913
8914 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8915 + asm volatile(LOCK_PREFIX "incl %0\n"
8916 +
8917 +#ifdef CONFIG_PAX_REFCOUNT
8918 + "jno 0f\n"
8919 + LOCK_PREFIX "decl %0\n"
8920 + "int $4\n0:\n"
8921 + _ASM_EXTABLE(0b, 0b)
8922 +#endif
8923 +
8924 + "sete %1\n"
8925 + : "+m" (v->counter), "=qm" (c)
8926 + : : "memory");
8927 + return c != 0;
8928 +}
8929 +
8930 +/**
8931 + * atomic_inc_and_test_unchecked - increment and test
8932 + * @v: pointer of type atomic_unchecked_t
8933 + *
8934 + * Atomically increments @v by 1
8935 + * and returns true if the result is zero, or false for all
8936 + * other cases.
8937 + */
8938 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8939 +{
8940 + unsigned char c;
8941 +
8942 + asm volatile(LOCK_PREFIX "incl %0\n"
8943 + "sete %1\n"
8944 : "+m" (v->counter), "=qm" (c)
8945 : : "memory");
8946 return c != 0;
8947 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8948 {
8949 unsigned char c;
8950
8951 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8952 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8953 +
8954 +#ifdef CONFIG_PAX_REFCOUNT
8955 + "jno 0f\n"
8956 + LOCK_PREFIX "subl %2,%0\n"
8957 + "int $4\n0:\n"
8958 + _ASM_EXTABLE(0b, 0b)
8959 +#endif
8960 +
8961 + "sets %1\n"
8962 : "+m" (v->counter), "=qm" (c)
8963 : "ir" (i) : "memory");
8964 return c;
8965 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8966 goto no_xadd;
8967 #endif
8968 /* Modern 486+ processor */
8969 - return i + xadd(&v->counter, i);
8970 + return i + xadd_check_overflow(&v->counter, i);
8971
8972 #ifdef CONFIG_M386
8973 no_xadd: /* Legacy 386 processor */
8974 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8975 }
8976
8977 /**
8978 + * atomic_add_return_unchecked - add integer and return
8979 + * @i: integer value to add
8980 + * @v: pointer of type atomic_unchecked_t
8981 + *
8982 + * Atomically adds @i to @v and returns @i + @v
8983 + */
8984 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8985 +{
8986 +#ifdef CONFIG_M386
8987 + int __i;
8988 + unsigned long flags;
8989 + if (unlikely(boot_cpu_data.x86 <= 3))
8990 + goto no_xadd;
8991 +#endif
8992 + /* Modern 486+ processor */
8993 + return i + xadd(&v->counter, i);
8994 +
8995 +#ifdef CONFIG_M386
8996 +no_xadd: /* Legacy 386 processor */
8997 + raw_local_irq_save(flags);
8998 + __i = atomic_read_unchecked(v);
8999 + atomic_set_unchecked(v, i + __i);
9000 + raw_local_irq_restore(flags);
9001 + return i + __i;
9002 +#endif
9003 +}
9004 +
9005 +/**
9006 * atomic_sub_return - subtract integer and return
9007 * @v: pointer of type atomic_t
9008 * @i: integer value to subtract
9009 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9010 }
9011
9012 #define atomic_inc_return(v) (atomic_add_return(1, v))
9013 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9014 +{
9015 + return atomic_add_return_unchecked(1, v);
9016 +}
9017 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9018
9019 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9020 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9021 return cmpxchg(&v->counter, old, new);
9022 }
9023
9024 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9025 +{
9026 + return cmpxchg(&v->counter, old, new);
9027 +}
9028 +
9029 static inline int atomic_xchg(atomic_t *v, int new)
9030 {
9031 return xchg(&v->counter, new);
9032 }
9033
9034 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9035 +{
9036 + return xchg(&v->counter, new);
9037 +}
9038 +
9039 /**
9040 * __atomic_add_unless - add unless the number is already a given value
9041 * @v: pointer of type atomic_t
9042 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9043 */
9044 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9045 {
9046 - int c, old;
9047 + int c, old, new;
9048 c = atomic_read(v);
9049 for (;;) {
9050 - if (unlikely(c == (u)))
9051 + if (unlikely(c == u))
9052 break;
9053 - old = atomic_cmpxchg((v), c, c + (a));
9054 +
9055 + asm volatile("addl %2,%0\n"
9056 +
9057 +#ifdef CONFIG_PAX_REFCOUNT
9058 + "jno 0f\n"
9059 + "subl %2,%0\n"
9060 + "int $4\n0:\n"
9061 + _ASM_EXTABLE(0b, 0b)
9062 +#endif
9063 +
9064 + : "=r" (new)
9065 + : "0" (c), "ir" (a));
9066 +
9067 + old = atomic_cmpxchg(v, c, new);
9068 if (likely(old == c))
9069 break;
9070 c = old;
9071 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9072 return c;
9073 }
9074
9075 +/**
9076 + * atomic_inc_not_zero_hint - increment if not null
9077 + * @v: pointer of type atomic_t
9078 + * @hint: probable value of the atomic before the increment
9079 + *
9080 + * This version of atomic_inc_not_zero() gives a hint of probable
9081 + * value of the atomic. This helps processor to not read the memory
9082 + * before doing the atomic read/modify/write cycle, lowering
9083 + * number of bus transactions on some arches.
9084 + *
9085 + * Returns: 0 if increment was not done, 1 otherwise.
9086 + */
9087 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9088 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9089 +{
9090 + int val, c = hint, new;
9091 +
9092 + /* sanity test, should be removed by compiler if hint is a constant */
9093 + if (!hint)
9094 + return __atomic_add_unless(v, 1, 0);
9095 +
9096 + do {
9097 + asm volatile("incl %0\n"
9098 +
9099 +#ifdef CONFIG_PAX_REFCOUNT
9100 + "jno 0f\n"
9101 + "decl %0\n"
9102 + "int $4\n0:\n"
9103 + _ASM_EXTABLE(0b, 0b)
9104 +#endif
9105 +
9106 + : "=r" (new)
9107 + : "0" (c));
9108 +
9109 + val = atomic_cmpxchg(v, c, new);
9110 + if (val == c)
9111 + return 1;
9112 + c = val;
9113 + } while (c);
9114 +
9115 + return 0;
9116 +}
9117
9118 /*
9119 * atomic_dec_if_positive - decrement by 1 if old value positive
9120 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9121 index fa13f0e..27c2e08 100644
9122 --- a/arch/x86/include/asm/atomic64_32.h
9123 +++ b/arch/x86/include/asm/atomic64_32.h
9124 @@ -12,6 +12,14 @@ typedef struct {
9125 u64 __aligned(8) counter;
9126 } atomic64_t;
9127
9128 +#ifdef CONFIG_PAX_REFCOUNT
9129 +typedef struct {
9130 + u64 __aligned(8) counter;
9131 +} atomic64_unchecked_t;
9132 +#else
9133 +typedef atomic64_t atomic64_unchecked_t;
9134 +#endif
9135 +
9136 #define ATOMIC64_INIT(val) { (val) }
9137
9138 #ifdef CONFIG_X86_CMPXCHG64
9139 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9140 }
9141
9142 /**
9143 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9144 + * @p: pointer to type atomic64_unchecked_t
9145 + * @o: expected value
9146 + * @n: new value
9147 + *
9148 + * Atomically sets @v to @n if it was equal to @o and returns
9149 + * the old value.
9150 + */
9151 +
9152 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9153 +{
9154 + return cmpxchg64(&v->counter, o, n);
9155 +}
9156 +
9157 +/**
9158 * atomic64_xchg - xchg atomic64 variable
9159 * @v: pointer to type atomic64_t
9160 * @n: value to assign
9161 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9162 }
9163
9164 /**
9165 + * atomic64_set_unchecked - set atomic64 variable
9166 + * @v: pointer to type atomic64_unchecked_t
9167 + * @n: value to assign
9168 + *
9169 + * Atomically sets the value of @v to @n.
9170 + */
9171 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9172 +{
9173 + unsigned high = (unsigned)(i >> 32);
9174 + unsigned low = (unsigned)i;
9175 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9176 + : "+b" (low), "+c" (high)
9177 + : "S" (v)
9178 + : "eax", "edx", "memory"
9179 + );
9180 +}
9181 +
9182 +/**
9183 * atomic64_read - read atomic64 variable
9184 * @v: pointer to type atomic64_t
9185 *
9186 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9187 }
9188
9189 /**
9190 + * atomic64_read_unchecked - read atomic64 variable
9191 + * @v: pointer to type atomic64_unchecked_t
9192 + *
9193 + * Atomically reads the value of @v and returns it.
9194 + */
9195 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9196 +{
9197 + long long r;
9198 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9199 + : "=A" (r), "+c" (v)
9200 + : : "memory"
9201 + );
9202 + return r;
9203 + }
9204 +
9205 +/**
9206 * atomic64_add_return - add and return
9207 * @i: integer value to add
9208 * @v: pointer to type atomic64_t
9209 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9210 return i;
9211 }
9212
9213 +/**
9214 + * atomic64_add_return_unchecked - add and return
9215 + * @i: integer value to add
9216 + * @v: pointer to type atomic64_unchecked_t
9217 + *
9218 + * Atomically adds @i to @v and returns @i + *@v
9219 + */
9220 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9221 +{
9222 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9223 + : "+A" (i), "+c" (v)
9224 + : : "memory"
9225 + );
9226 + return i;
9227 +}
9228 +
9229 /*
9230 * Other variants with different arithmetic operators:
9231 */
9232 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9233 return a;
9234 }
9235
9236 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9237 +{
9238 + long long a;
9239 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9240 + : "=A" (a)
9241 + : "S" (v)
9242 + : "memory", "ecx"
9243 + );
9244 + return a;
9245 +}
9246 +
9247 static inline long long atomic64_dec_return(atomic64_t *v)
9248 {
9249 long long a;
9250 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9251 }
9252
9253 /**
9254 + * atomic64_add_unchecked - add integer to atomic64 variable
9255 + * @i: integer value to add
9256 + * @v: pointer to type atomic64_unchecked_t
9257 + *
9258 + * Atomically adds @i to @v.
9259 + */
9260 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9261 +{
9262 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9263 + : "+A" (i), "+c" (v)
9264 + : : "memory"
9265 + );
9266 + return i;
9267 +}
9268 +
9269 +/**
9270 * atomic64_sub - subtract the atomic64 variable
9271 * @i: integer value to subtract
9272 * @v: pointer to type atomic64_t
9273 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9274 index 0e1cbfc..5623683 100644
9275 --- a/arch/x86/include/asm/atomic64_64.h
9276 +++ b/arch/x86/include/asm/atomic64_64.h
9277 @@ -18,7 +18,19 @@
9278 */
9279 static inline long atomic64_read(const atomic64_t *v)
9280 {
9281 - return (*(volatile long *)&(v)->counter);
9282 + return (*(volatile const long *)&(v)->counter);
9283 +}
9284 +
9285 +/**
9286 + * atomic64_read_unchecked - read atomic64 variable
9287 + * @v: pointer of type atomic64_unchecked_t
9288 + *
9289 + * Atomically reads the value of @v.
9290 + * Doesn't imply a read memory barrier.
9291 + */
9292 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9293 +{
9294 + return (*(volatile const long *)&(v)->counter);
9295 }
9296
9297 /**
9298 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9299 }
9300
9301 /**
9302 + * atomic64_set_unchecked - set atomic64 variable
9303 + * @v: pointer to type atomic64_unchecked_t
9304 + * @i: required value
9305 + *
9306 + * Atomically sets the value of @v to @i.
9307 + */
9308 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9309 +{
9310 + v->counter = i;
9311 +}
9312 +
9313 +/**
9314 * atomic64_add - add integer to atomic64 variable
9315 * @i: integer value to add
9316 * @v: pointer to type atomic64_t
9317 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9318 */
9319 static inline void atomic64_add(long i, atomic64_t *v)
9320 {
9321 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9322 +
9323 +#ifdef CONFIG_PAX_REFCOUNT
9324 + "jno 0f\n"
9325 + LOCK_PREFIX "subq %1,%0\n"
9326 + "int $4\n0:\n"
9327 + _ASM_EXTABLE(0b, 0b)
9328 +#endif
9329 +
9330 + : "=m" (v->counter)
9331 + : "er" (i), "m" (v->counter));
9332 +}
9333 +
9334 +/**
9335 + * atomic64_add_unchecked - add integer to atomic64 variable
9336 + * @i: integer value to add
9337 + * @v: pointer to type atomic64_unchecked_t
9338 + *
9339 + * Atomically adds @i to @v.
9340 + */
9341 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9342 +{
9343 asm volatile(LOCK_PREFIX "addq %1,%0"
9344 : "=m" (v->counter)
9345 : "er" (i), "m" (v->counter));
9346 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9347 */
9348 static inline void atomic64_sub(long i, atomic64_t *v)
9349 {
9350 - asm volatile(LOCK_PREFIX "subq %1,%0"
9351 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9352 +
9353 +#ifdef CONFIG_PAX_REFCOUNT
9354 + "jno 0f\n"
9355 + LOCK_PREFIX "addq %1,%0\n"
9356 + "int $4\n0:\n"
9357 + _ASM_EXTABLE(0b, 0b)
9358 +#endif
9359 +
9360 + : "=m" (v->counter)
9361 + : "er" (i), "m" (v->counter));
9362 +}
9363 +
9364 +/**
9365 + * atomic64_sub_unchecked - subtract the atomic64 variable
9366 + * @i: integer value to subtract
9367 + * @v: pointer to type atomic64_unchecked_t
9368 + *
9369 + * Atomically subtracts @i from @v.
9370 + */
9371 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9372 +{
9373 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9374 : "=m" (v->counter)
9375 : "er" (i), "m" (v->counter));
9376 }
9377 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9378 {
9379 unsigned char c;
9380
9381 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9382 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9383 +
9384 +#ifdef CONFIG_PAX_REFCOUNT
9385 + "jno 0f\n"
9386 + LOCK_PREFIX "addq %2,%0\n"
9387 + "int $4\n0:\n"
9388 + _ASM_EXTABLE(0b, 0b)
9389 +#endif
9390 +
9391 + "sete %1\n"
9392 : "=m" (v->counter), "=qm" (c)
9393 : "er" (i), "m" (v->counter) : "memory");
9394 return c;
9395 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9396 */
9397 static inline void atomic64_inc(atomic64_t *v)
9398 {
9399 + asm volatile(LOCK_PREFIX "incq %0\n"
9400 +
9401 +#ifdef CONFIG_PAX_REFCOUNT
9402 + "jno 0f\n"
9403 + LOCK_PREFIX "decq %0\n"
9404 + "int $4\n0:\n"
9405 + _ASM_EXTABLE(0b, 0b)
9406 +#endif
9407 +
9408 + : "=m" (v->counter)
9409 + : "m" (v->counter));
9410 +}
9411 +
9412 +/**
9413 + * atomic64_inc_unchecked - increment atomic64 variable
9414 + * @v: pointer to type atomic64_unchecked_t
9415 + *
9416 + * Atomically increments @v by 1.
9417 + */
9418 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9419 +{
9420 asm volatile(LOCK_PREFIX "incq %0"
9421 : "=m" (v->counter)
9422 : "m" (v->counter));
9423 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9424 */
9425 static inline void atomic64_dec(atomic64_t *v)
9426 {
9427 - asm volatile(LOCK_PREFIX "decq %0"
9428 + asm volatile(LOCK_PREFIX "decq %0\n"
9429 +
9430 +#ifdef CONFIG_PAX_REFCOUNT
9431 + "jno 0f\n"
9432 + LOCK_PREFIX "incq %0\n"
9433 + "int $4\n0:\n"
9434 + _ASM_EXTABLE(0b, 0b)
9435 +#endif
9436 +
9437 + : "=m" (v->counter)
9438 + : "m" (v->counter));
9439 +}
9440 +
9441 +/**
9442 + * atomic64_dec_unchecked - decrement atomic64 variable
9443 + * @v: pointer to type atomic64_t
9444 + *
9445 + * Atomically decrements @v by 1.
9446 + */
9447 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9448 +{
9449 + asm volatile(LOCK_PREFIX "decq %0\n"
9450 : "=m" (v->counter)
9451 : "m" (v->counter));
9452 }
9453 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9454 {
9455 unsigned char c;
9456
9457 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9458 + asm volatile(LOCK_PREFIX "decq %0\n"
9459 +
9460 +#ifdef CONFIG_PAX_REFCOUNT
9461 + "jno 0f\n"
9462 + LOCK_PREFIX "incq %0\n"
9463 + "int $4\n0:\n"
9464 + _ASM_EXTABLE(0b, 0b)
9465 +#endif
9466 +
9467 + "sete %1\n"
9468 : "=m" (v->counter), "=qm" (c)
9469 : "m" (v->counter) : "memory");
9470 return c != 0;
9471 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9472 {
9473 unsigned char c;
9474
9475 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9476 + asm volatile(LOCK_PREFIX "incq %0\n"
9477 +
9478 +#ifdef CONFIG_PAX_REFCOUNT
9479 + "jno 0f\n"
9480 + LOCK_PREFIX "decq %0\n"
9481 + "int $4\n0:\n"
9482 + _ASM_EXTABLE(0b, 0b)
9483 +#endif
9484 +
9485 + "sete %1\n"
9486 : "=m" (v->counter), "=qm" (c)
9487 : "m" (v->counter) : "memory");
9488 return c != 0;
9489 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9490 {
9491 unsigned char c;
9492
9493 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9494 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9495 +
9496 +#ifdef CONFIG_PAX_REFCOUNT
9497 + "jno 0f\n"
9498 + LOCK_PREFIX "subq %2,%0\n"
9499 + "int $4\n0:\n"
9500 + _ASM_EXTABLE(0b, 0b)
9501 +#endif
9502 +
9503 + "sets %1\n"
9504 : "=m" (v->counter), "=qm" (c)
9505 : "er" (i), "m" (v->counter) : "memory");
9506 return c;
9507 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9508 */
9509 static inline long atomic64_add_return(long i, atomic64_t *v)
9510 {
9511 + return i + xadd_check_overflow(&v->counter, i);
9512 +}
9513 +
9514 +/**
9515 + * atomic64_add_return_unchecked - add and return
9516 + * @i: integer value to add
9517 + * @v: pointer to type atomic64_unchecked_t
9518 + *
9519 + * Atomically adds @i to @v and returns @i + @v
9520 + */
9521 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9522 +{
9523 return i + xadd(&v->counter, i);
9524 }
9525
9526 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9527 }
9528
9529 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9530 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9531 +{
9532 + return atomic64_add_return_unchecked(1, v);
9533 +}
9534 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9535
9536 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9537 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9538 return cmpxchg(&v->counter, old, new);
9539 }
9540
9541 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9542 +{
9543 + return cmpxchg(&v->counter, old, new);
9544 +}
9545 +
9546 static inline long atomic64_xchg(atomic64_t *v, long new)
9547 {
9548 return xchg(&v->counter, new);
9549 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9550 */
9551 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9552 {
9553 - long c, old;
9554 + long c, old, new;
9555 c = atomic64_read(v);
9556 for (;;) {
9557 - if (unlikely(c == (u)))
9558 + if (unlikely(c == u))
9559 break;
9560 - old = atomic64_cmpxchg((v), c, c + (a));
9561 +
9562 + asm volatile("add %2,%0\n"
9563 +
9564 +#ifdef CONFIG_PAX_REFCOUNT
9565 + "jno 0f\n"
9566 + "sub %2,%0\n"
9567 + "int $4\n0:\n"
9568 + _ASM_EXTABLE(0b, 0b)
9569 +#endif
9570 +
9571 + : "=r" (new)
9572 + : "0" (c), "ir" (a));
9573 +
9574 + old = atomic64_cmpxchg(v, c, new);
9575 if (likely(old == c))
9576 break;
9577 c = old;
9578 }
9579 - return c != (u);
9580 + return c != u;
9581 }
9582
9583 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9584 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9585 index b97596e..9bd48b06 100644
9586 --- a/arch/x86/include/asm/bitops.h
9587 +++ b/arch/x86/include/asm/bitops.h
9588 @@ -38,7 +38,7 @@
9589 * a mask operation on a byte.
9590 */
9591 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9592 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9593 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9594 #define CONST_MASK(nr) (1 << ((nr) & 7))
9595
9596 /**
9597 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9598 index 5e1a2ee..c9f9533 100644
9599 --- a/arch/x86/include/asm/boot.h
9600 +++ b/arch/x86/include/asm/boot.h
9601 @@ -11,10 +11,15 @@
9602 #include <asm/pgtable_types.h>
9603
9604 /* Physical address where kernel should be loaded. */
9605 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9606 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9607 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9608 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9609
9610 +#ifndef __ASSEMBLY__
9611 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9612 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9613 +#endif
9614 +
9615 /* Minimum kernel alignment, as a power of two */
9616 #ifdef CONFIG_X86_64
9617 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9618 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9619 index 48f99f1..d78ebf9 100644
9620 --- a/arch/x86/include/asm/cache.h
9621 +++ b/arch/x86/include/asm/cache.h
9622 @@ -5,12 +5,13 @@
9623
9624 /* L1 cache line size */
9625 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9626 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9627 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9628
9629 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9630 +#define __read_only __attribute__((__section__(".data..read_only")))
9631
9632 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9633 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9634 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9635
9636 #ifdef CONFIG_X86_VSMP
9637 #ifdef CONFIG_SMP
9638 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9639 index 4e12668..501d239 100644
9640 --- a/arch/x86/include/asm/cacheflush.h
9641 +++ b/arch/x86/include/asm/cacheflush.h
9642 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9643 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9644
9645 if (pg_flags == _PGMT_DEFAULT)
9646 - return -1;
9647 + return ~0UL;
9648 else if (pg_flags == _PGMT_WC)
9649 return _PAGE_CACHE_WC;
9650 else if (pg_flags == _PGMT_UC_MINUS)
9651 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9652 index 46fc474..b02b0f9 100644
9653 --- a/arch/x86/include/asm/checksum_32.h
9654 +++ b/arch/x86/include/asm/checksum_32.h
9655 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9656 int len, __wsum sum,
9657 int *src_err_ptr, int *dst_err_ptr);
9658
9659 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9660 + int len, __wsum sum,
9661 + int *src_err_ptr, int *dst_err_ptr);
9662 +
9663 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9664 + int len, __wsum sum,
9665 + int *src_err_ptr, int *dst_err_ptr);
9666 +
9667 /*
9668 * Note: when you get a NULL pointer exception here this means someone
9669 * passed in an incorrect kernel address to one of these functions.
9670 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9671 int *err_ptr)
9672 {
9673 might_sleep();
9674 - return csum_partial_copy_generic((__force void *)src, dst,
9675 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9676 len, sum, err_ptr, NULL);
9677 }
9678
9679 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9680 {
9681 might_sleep();
9682 if (access_ok(VERIFY_WRITE, dst, len))
9683 - return csum_partial_copy_generic(src, (__force void *)dst,
9684 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9685 len, sum, NULL, err_ptr);
9686
9687 if (len)
9688 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9689 index b3b7332..d81165b 100644
9690 --- a/arch/x86/include/asm/cmpxchg.h
9691 +++ b/arch/x86/include/asm/cmpxchg.h
9692 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9693 __compiletime_error("Bad argument size for cmpxchg");
9694 extern void __xadd_wrong_size(void)
9695 __compiletime_error("Bad argument size for xadd");
9696 +extern void __xadd_check_overflow_wrong_size(void)
9697 + __compiletime_error("Bad argument size for xadd_check_overflow");
9698 extern void __add_wrong_size(void)
9699 __compiletime_error("Bad argument size for add");
9700 +extern void __add_check_overflow_wrong_size(void)
9701 + __compiletime_error("Bad argument size for add_check_overflow");
9702
9703 /*
9704 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9705 @@ -43,7 +47,7 @@ extern void __add_wrong_size(void)
9706 switch (sizeof(*(ptr))) { \
9707 case __X86_CASE_B: \
9708 asm volatile (lock #op "b %b0, %1\n" \
9709 - : "+r" (__ret), "+m" (*(ptr)) \
9710 + : "+q" (__ret), "+m" (*(ptr)) \
9711 : : "memory", "cc"); \
9712 break; \
9713 case __X86_CASE_W: \
9714 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9715 __ret; \
9716 })
9717
9718 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9719 + ({ \
9720 + __typeof__ (*(ptr)) __ret = (arg); \
9721 + switch (sizeof(*(ptr))) { \
9722 + case __X86_CASE_L: \
9723 + asm volatile (lock #op "l %0, %1\n" \
9724 + "jno 0f\n" \
9725 + "mov %0,%1\n" \
9726 + "int $4\n0:\n" \
9727 + _ASM_EXTABLE(0b, 0b) \
9728 + : "+r" (__ret), "+m" (*(ptr)) \
9729 + : : "memory", "cc"); \
9730 + break; \
9731 + case __X86_CASE_Q: \
9732 + asm volatile (lock #op "q %q0, %1\n" \
9733 + "jno 0f\n" \
9734 + "mov %0,%1\n" \
9735 + "int $4\n0:\n" \
9736 + _ASM_EXTABLE(0b, 0b) \
9737 + : "+r" (__ret), "+m" (*(ptr)) \
9738 + : : "memory", "cc"); \
9739 + break; \
9740 + default: \
9741 + __ ## op ## _check_overflow_wrong_size(); \
9742 + } \
9743 + __ret; \
9744 + })
9745 +
9746 /*
9747 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9748 * Since this is generally used to protect other memory information, we
9749 @@ -167,13 +199,16 @@ extern void __add_wrong_size(void)
9750 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9751 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9752
9753 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9754 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9755 +
9756 #define __add(ptr, inc, lock) \
9757 ({ \
9758 __typeof__ (*(ptr)) __ret = (inc); \
9759 switch (sizeof(*(ptr))) { \
9760 case __X86_CASE_B: \
9761 asm volatile (lock "addb %b1, %0\n" \
9762 - : "+m" (*(ptr)) : "ri" (inc) \
9763 + : "+m" (*(ptr)) : "qi" (inc) \
9764 : "memory", "cc"); \
9765 break; \
9766 case __X86_CASE_W: \
9767 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9768 index 8d67d42..183d0eb 100644
9769 --- a/arch/x86/include/asm/cpufeature.h
9770 +++ b/arch/x86/include/asm/cpufeature.h
9771 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9772 ".section .discard,\"aw\",@progbits\n"
9773 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9774 ".previous\n"
9775 - ".section .altinstr_replacement,\"ax\"\n"
9776 + ".section .altinstr_replacement,\"a\"\n"
9777 "3: movb $1,%0\n"
9778 "4:\n"
9779 ".previous\n"
9780 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9781 index e95822d..a90010e 100644
9782 --- a/arch/x86/include/asm/desc.h
9783 +++ b/arch/x86/include/asm/desc.h
9784 @@ -4,6 +4,7 @@
9785 #include <asm/desc_defs.h>
9786 #include <asm/ldt.h>
9787 #include <asm/mmu.h>
9788 +#include <asm/pgtable.h>
9789
9790 #include <linux/smp.h>
9791
9792 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9793
9794 desc->type = (info->read_exec_only ^ 1) << 1;
9795 desc->type |= info->contents << 2;
9796 + desc->type |= info->seg_not_present ^ 1;
9797
9798 desc->s = 1;
9799 desc->dpl = 0x3;
9800 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9801 }
9802
9803 extern struct desc_ptr idt_descr;
9804 -extern gate_desc idt_table[];
9805 extern struct desc_ptr nmi_idt_descr;
9806 -extern gate_desc nmi_idt_table[];
9807 -
9808 -struct gdt_page {
9809 - struct desc_struct gdt[GDT_ENTRIES];
9810 -} __attribute__((aligned(PAGE_SIZE)));
9811 -
9812 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9813 +extern gate_desc idt_table[256];
9814 +extern gate_desc nmi_idt_table[256];
9815
9816 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9817 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9818 {
9819 - return per_cpu(gdt_page, cpu).gdt;
9820 + return cpu_gdt_table[cpu];
9821 }
9822
9823 #ifdef CONFIG_X86_64
9824 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9825 unsigned long base, unsigned dpl, unsigned flags,
9826 unsigned short seg)
9827 {
9828 - gate->a = (seg << 16) | (base & 0xffff);
9829 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9830 + gate->gate.offset_low = base;
9831 + gate->gate.seg = seg;
9832 + gate->gate.reserved = 0;
9833 + gate->gate.type = type;
9834 + gate->gate.s = 0;
9835 + gate->gate.dpl = dpl;
9836 + gate->gate.p = 1;
9837 + gate->gate.offset_high = base >> 16;
9838 }
9839
9840 #endif
9841 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9842
9843 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9844 {
9845 + pax_open_kernel();
9846 memcpy(&idt[entry], gate, sizeof(*gate));
9847 + pax_close_kernel();
9848 }
9849
9850 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9851 {
9852 + pax_open_kernel();
9853 memcpy(&ldt[entry], desc, 8);
9854 + pax_close_kernel();
9855 }
9856
9857 static inline void
9858 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9859 default: size = sizeof(*gdt); break;
9860 }
9861
9862 + pax_open_kernel();
9863 memcpy(&gdt[entry], desc, size);
9864 + pax_close_kernel();
9865 }
9866
9867 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9868 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9869
9870 static inline void native_load_tr_desc(void)
9871 {
9872 + pax_open_kernel();
9873 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9874 + pax_close_kernel();
9875 }
9876
9877 static inline void native_load_gdt(const struct desc_ptr *dtr)
9878 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9879 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9880 unsigned int i;
9881
9882 + pax_open_kernel();
9883 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9884 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9885 + pax_close_kernel();
9886 }
9887
9888 #define _LDT_empty(info) \
9889 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9890 }
9891
9892 #ifdef CONFIG_X86_64
9893 -static inline void set_nmi_gate(int gate, void *addr)
9894 +static inline void set_nmi_gate(int gate, const void *addr)
9895 {
9896 gate_desc s;
9897
9898 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9899 }
9900 #endif
9901
9902 -static inline void _set_gate(int gate, unsigned type, void *addr,
9903 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9904 unsigned dpl, unsigned ist, unsigned seg)
9905 {
9906 gate_desc s;
9907 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9908 * Pentium F0 0F bugfix can have resulted in the mapped
9909 * IDT being write-protected.
9910 */
9911 -static inline void set_intr_gate(unsigned int n, void *addr)
9912 +static inline void set_intr_gate(unsigned int n, const void *addr)
9913 {
9914 BUG_ON((unsigned)n > 0xFF);
9915 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9916 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9917 /*
9918 * This routine sets up an interrupt gate at directory privilege level 3.
9919 */
9920 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9921 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9922 {
9923 BUG_ON((unsigned)n > 0xFF);
9924 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9925 }
9926
9927 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9928 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9929 {
9930 BUG_ON((unsigned)n > 0xFF);
9931 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9932 }
9933
9934 -static inline void set_trap_gate(unsigned int n, void *addr)
9935 +static inline void set_trap_gate(unsigned int n, const void *addr)
9936 {
9937 BUG_ON((unsigned)n > 0xFF);
9938 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9939 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9940 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9941 {
9942 BUG_ON((unsigned)n > 0xFF);
9943 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9944 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9945 }
9946
9947 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9948 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9949 {
9950 BUG_ON((unsigned)n > 0xFF);
9951 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9952 }
9953
9954 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9955 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9956 {
9957 BUG_ON((unsigned)n > 0xFF);
9958 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9959 }
9960
9961 +#ifdef CONFIG_X86_32
9962 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9963 +{
9964 + struct desc_struct d;
9965 +
9966 + if (likely(limit))
9967 + limit = (limit - 1UL) >> PAGE_SHIFT;
9968 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9969 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9970 +}
9971 +#endif
9972 +
9973 #endif /* _ASM_X86_DESC_H */
9974 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9975 index 278441f..b95a174 100644
9976 --- a/arch/x86/include/asm/desc_defs.h
9977 +++ b/arch/x86/include/asm/desc_defs.h
9978 @@ -31,6 +31,12 @@ struct desc_struct {
9979 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9980 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9981 };
9982 + struct {
9983 + u16 offset_low;
9984 + u16 seg;
9985 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9986 + unsigned offset_high: 16;
9987 + } gate;
9988 };
9989 } __attribute__((packed));
9990
9991 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9992 index 3778256..c5d4fce 100644
9993 --- a/arch/x86/include/asm/e820.h
9994 +++ b/arch/x86/include/asm/e820.h
9995 @@ -69,7 +69,7 @@ struct e820map {
9996 #define ISA_START_ADDRESS 0xa0000
9997 #define ISA_END_ADDRESS 0x100000
9998
9999 -#define BIOS_BEGIN 0x000a0000
10000 +#define BIOS_BEGIN 0x000c0000
10001 #define BIOS_END 0x00100000
10002
10003 #define BIOS_ROM_BASE 0xffe00000
10004 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10005 index 5f962df..7289f09 100644
10006 --- a/arch/x86/include/asm/elf.h
10007 +++ b/arch/x86/include/asm/elf.h
10008 @@ -238,7 +238,25 @@ extern int force_personality32;
10009 the loader. We need to make sure that it is out of the way of the program
10010 that it will "exec", and that there is sufficient room for the brk. */
10011
10012 +#ifdef CONFIG_PAX_SEGMEXEC
10013 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10014 +#else
10015 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10016 +#endif
10017 +
10018 +#ifdef CONFIG_PAX_ASLR
10019 +#ifdef CONFIG_X86_32
10020 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10021 +
10022 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10023 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10024 +#else
10025 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10026 +
10027 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10028 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10029 +#endif
10030 +#endif
10031
10032 /* This yields a mask that user programs can use to figure out what
10033 instruction set this CPU supports. This could be done in user space,
10034 @@ -291,9 +309,7 @@ do { \
10035
10036 #define ARCH_DLINFO \
10037 do { \
10038 - if (vdso_enabled) \
10039 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10040 - (unsigned long)current->mm->context.vdso); \
10041 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10042 } while (0)
10043
10044 #define AT_SYSINFO 32
10045 @@ -304,7 +320,7 @@ do { \
10046
10047 #endif /* !CONFIG_X86_32 */
10048
10049 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10050 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10051
10052 #define VDSO_ENTRY \
10053 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10054 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10055 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10056 #define compat_arch_setup_additional_pages syscall32_setup_pages
10057
10058 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10059 -#define arch_randomize_brk arch_randomize_brk
10060 -
10061 /*
10062 * True on X86_32 or when emulating IA32 on X86_64
10063 */
10064 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10065 index cc70c1c..d96d011 100644
10066 --- a/arch/x86/include/asm/emergency-restart.h
10067 +++ b/arch/x86/include/asm/emergency-restart.h
10068 @@ -15,6 +15,6 @@ enum reboot_type {
10069
10070 extern enum reboot_type reboot_type;
10071
10072 -extern void machine_emergency_restart(void);
10073 +extern void machine_emergency_restart(void) __noreturn;
10074
10075 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10076 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10077 index dbe82a5..c6d8a00 100644
10078 --- a/arch/x86/include/asm/floppy.h
10079 +++ b/arch/x86/include/asm/floppy.h
10080 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10081 }
10082
10083
10084 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10085 static unsigned long vdma_mem_alloc(unsigned long size)
10086 {
10087 return (unsigned long)vmalloc(size);
10088 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10089 index d09bb03..4ea4194 100644
10090 --- a/arch/x86/include/asm/futex.h
10091 +++ b/arch/x86/include/asm/futex.h
10092 @@ -12,16 +12,18 @@
10093 #include <asm/system.h>
10094
10095 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10096 + typecheck(u32 __user *, uaddr); \
10097 asm volatile("1:\t" insn "\n" \
10098 "2:\t.section .fixup,\"ax\"\n" \
10099 "3:\tmov\t%3, %1\n" \
10100 "\tjmp\t2b\n" \
10101 "\t.previous\n" \
10102 _ASM_EXTABLE(1b, 3b) \
10103 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10104 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10105 : "i" (-EFAULT), "0" (oparg), "1" (0))
10106
10107 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10108 + typecheck(u32 __user *, uaddr); \
10109 asm volatile("1:\tmovl %2, %0\n" \
10110 "\tmovl\t%0, %3\n" \
10111 "\t" insn "\n" \
10112 @@ -34,7 +36,7 @@
10113 _ASM_EXTABLE(1b, 4b) \
10114 _ASM_EXTABLE(2b, 4b) \
10115 : "=&a" (oldval), "=&r" (ret), \
10116 - "+m" (*uaddr), "=&r" (tem) \
10117 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10118 : "r" (oparg), "i" (-EFAULT), "1" (0))
10119
10120 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10121 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10122
10123 switch (op) {
10124 case FUTEX_OP_SET:
10125 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10126 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10127 break;
10128 case FUTEX_OP_ADD:
10129 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10130 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10131 uaddr, oparg);
10132 break;
10133 case FUTEX_OP_OR:
10134 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10135 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10136 return -EFAULT;
10137
10138 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10139 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10140 "2:\t.section .fixup, \"ax\"\n"
10141 "3:\tmov %3, %0\n"
10142 "\tjmp 2b\n"
10143 "\t.previous\n"
10144 _ASM_EXTABLE(1b, 3b)
10145 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10146 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10147 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10148 : "memory"
10149 );
10150 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10151 index eb92a6e..b98b2f4 100644
10152 --- a/arch/x86/include/asm/hw_irq.h
10153 +++ b/arch/x86/include/asm/hw_irq.h
10154 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10155 extern void enable_IO_APIC(void);
10156
10157 /* Statistics */
10158 -extern atomic_t irq_err_count;
10159 -extern atomic_t irq_mis_count;
10160 +extern atomic_unchecked_t irq_err_count;
10161 +extern atomic_unchecked_t irq_mis_count;
10162
10163 /* EISA */
10164 extern void eisa_set_level_irq(unsigned int irq);
10165 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10166 index 2479049..3fb9795 100644
10167 --- a/arch/x86/include/asm/i387.h
10168 +++ b/arch/x86/include/asm/i387.h
10169 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10170 {
10171 int err;
10172
10173 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10174 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10175 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10176 +#endif
10177 +
10178 /* See comment in fxsave() below. */
10179 #ifdef CONFIG_AS_FXSAVEQ
10180 asm volatile("1: fxrstorq %[fx]\n\t"
10181 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10182 {
10183 int err;
10184
10185 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10186 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10187 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10188 +#endif
10189 +
10190 /*
10191 * Clear the bytes not touched by the fxsave and reserved
10192 * for the SW usage.
10193 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10194 "emms\n\t" /* clear stack tags */
10195 "fildl %P[addr]", /* set F?P to defined value */
10196 X86_FEATURE_FXSAVE_LEAK,
10197 - [addr] "m" (tsk->thread.fpu.has_fpu));
10198 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10199
10200 return fpu_restore_checking(&tsk->thread.fpu);
10201 }
10202 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10203 static inline bool interrupted_user_mode(void)
10204 {
10205 struct pt_regs *regs = get_irq_regs();
10206 - return regs && user_mode_vm(regs);
10207 + return regs && user_mode(regs);
10208 }
10209
10210 /*
10211 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10212 index d8e8eef..99f81ae 100644
10213 --- a/arch/x86/include/asm/io.h
10214 +++ b/arch/x86/include/asm/io.h
10215 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10216
10217 #include <linux/vmalloc.h>
10218
10219 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10220 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10221 +{
10222 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10223 +}
10224 +
10225 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10226 +{
10227 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10228 +}
10229 +
10230 /*
10231 * Convert a virtual cached pointer to an uncached pointer
10232 */
10233 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10234 index bba3cf8..06bc8da 100644
10235 --- a/arch/x86/include/asm/irqflags.h
10236 +++ b/arch/x86/include/asm/irqflags.h
10237 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10238 sti; \
10239 sysexit
10240
10241 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10242 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10243 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10244 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10245 +
10246 #else
10247 #define INTERRUPT_RETURN iret
10248 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10249 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10250 index 5478825..839e88c 100644
10251 --- a/arch/x86/include/asm/kprobes.h
10252 +++ b/arch/x86/include/asm/kprobes.h
10253 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10254 #define RELATIVEJUMP_SIZE 5
10255 #define RELATIVECALL_OPCODE 0xe8
10256 #define RELATIVE_ADDR_SIZE 4
10257 -#define MAX_STACK_SIZE 64
10258 -#define MIN_STACK_SIZE(ADDR) \
10259 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10260 - THREAD_SIZE - (unsigned long)(ADDR))) \
10261 - ? (MAX_STACK_SIZE) \
10262 - : (((unsigned long)current_thread_info()) + \
10263 - THREAD_SIZE - (unsigned long)(ADDR)))
10264 +#define MAX_STACK_SIZE 64UL
10265 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10266
10267 #define flush_insn_slot(p) do { } while (0)
10268
10269 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10270 index 52d6640..136b3bd 100644
10271 --- a/arch/x86/include/asm/kvm_host.h
10272 +++ b/arch/x86/include/asm/kvm_host.h
10273 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10274 int (*check_intercept)(struct kvm_vcpu *vcpu,
10275 struct x86_instruction_info *info,
10276 enum x86_intercept_stage stage);
10277 -};
10278 +} __do_const;
10279
10280 struct kvm_arch_async_pf {
10281 u32 token;
10282 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10283 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10284
10285 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10286 - const void *val, int bytes);
10287 + const void *val, int bytes) __size_overflow(2);
10288 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10289
10290 extern bool tdp_enabled;
10291 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10292
10293 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10294 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10295 - const u8 *new, int bytes);
10296 + const u8 *new, int bytes) __size_overflow(2);
10297 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10298 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10299 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10300 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10301 index 9cdae5d..300d20f 100644
10302 --- a/arch/x86/include/asm/local.h
10303 +++ b/arch/x86/include/asm/local.h
10304 @@ -18,26 +18,58 @@ typedef struct {
10305
10306 static inline void local_inc(local_t *l)
10307 {
10308 - asm volatile(_ASM_INC "%0"
10309 + asm volatile(_ASM_INC "%0\n"
10310 +
10311 +#ifdef CONFIG_PAX_REFCOUNT
10312 + "jno 0f\n"
10313 + _ASM_DEC "%0\n"
10314 + "int $4\n0:\n"
10315 + _ASM_EXTABLE(0b, 0b)
10316 +#endif
10317 +
10318 : "+m" (l->a.counter));
10319 }
10320
10321 static inline void local_dec(local_t *l)
10322 {
10323 - asm volatile(_ASM_DEC "%0"
10324 + asm volatile(_ASM_DEC "%0\n"
10325 +
10326 +#ifdef CONFIG_PAX_REFCOUNT
10327 + "jno 0f\n"
10328 + _ASM_INC "%0\n"
10329 + "int $4\n0:\n"
10330 + _ASM_EXTABLE(0b, 0b)
10331 +#endif
10332 +
10333 : "+m" (l->a.counter));
10334 }
10335
10336 static inline void local_add(long i, local_t *l)
10337 {
10338 - asm volatile(_ASM_ADD "%1,%0"
10339 + asm volatile(_ASM_ADD "%1,%0\n"
10340 +
10341 +#ifdef CONFIG_PAX_REFCOUNT
10342 + "jno 0f\n"
10343 + _ASM_SUB "%1,%0\n"
10344 + "int $4\n0:\n"
10345 + _ASM_EXTABLE(0b, 0b)
10346 +#endif
10347 +
10348 : "+m" (l->a.counter)
10349 : "ir" (i));
10350 }
10351
10352 static inline void local_sub(long i, local_t *l)
10353 {
10354 - asm volatile(_ASM_SUB "%1,%0"
10355 + asm volatile(_ASM_SUB "%1,%0\n"
10356 +
10357 +#ifdef CONFIG_PAX_REFCOUNT
10358 + "jno 0f\n"
10359 + _ASM_ADD "%1,%0\n"
10360 + "int $4\n0:\n"
10361 + _ASM_EXTABLE(0b, 0b)
10362 +#endif
10363 +
10364 : "+m" (l->a.counter)
10365 : "ir" (i));
10366 }
10367 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10368 {
10369 unsigned char c;
10370
10371 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10372 + asm volatile(_ASM_SUB "%2,%0\n"
10373 +
10374 +#ifdef CONFIG_PAX_REFCOUNT
10375 + "jno 0f\n"
10376 + _ASM_ADD "%2,%0\n"
10377 + "int $4\n0:\n"
10378 + _ASM_EXTABLE(0b, 0b)
10379 +#endif
10380 +
10381 + "sete %1\n"
10382 : "+m" (l->a.counter), "=qm" (c)
10383 : "ir" (i) : "memory");
10384 return c;
10385 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10386 {
10387 unsigned char c;
10388
10389 - asm volatile(_ASM_DEC "%0; sete %1"
10390 + asm volatile(_ASM_DEC "%0\n"
10391 +
10392 +#ifdef CONFIG_PAX_REFCOUNT
10393 + "jno 0f\n"
10394 + _ASM_INC "%0\n"
10395 + "int $4\n0:\n"
10396 + _ASM_EXTABLE(0b, 0b)
10397 +#endif
10398 +
10399 + "sete %1\n"
10400 : "+m" (l->a.counter), "=qm" (c)
10401 : : "memory");
10402 return c != 0;
10403 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10404 {
10405 unsigned char c;
10406
10407 - asm volatile(_ASM_INC "%0; sete %1"
10408 + asm volatile(_ASM_INC "%0\n"
10409 +
10410 +#ifdef CONFIG_PAX_REFCOUNT
10411 + "jno 0f\n"
10412 + _ASM_DEC "%0\n"
10413 + "int $4\n0:\n"
10414 + _ASM_EXTABLE(0b, 0b)
10415 +#endif
10416 +
10417 + "sete %1\n"
10418 : "+m" (l->a.counter), "=qm" (c)
10419 : : "memory");
10420 return c != 0;
10421 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10422 {
10423 unsigned char c;
10424
10425 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10426 + asm volatile(_ASM_ADD "%2,%0\n"
10427 +
10428 +#ifdef CONFIG_PAX_REFCOUNT
10429 + "jno 0f\n"
10430 + _ASM_SUB "%2,%0\n"
10431 + "int $4\n0:\n"
10432 + _ASM_EXTABLE(0b, 0b)
10433 +#endif
10434 +
10435 + "sets %1\n"
10436 : "+m" (l->a.counter), "=qm" (c)
10437 : "ir" (i) : "memory");
10438 return c;
10439 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10440 #endif
10441 /* Modern 486+ processor */
10442 __i = i;
10443 - asm volatile(_ASM_XADD "%0, %1;"
10444 + asm volatile(_ASM_XADD "%0, %1\n"
10445 +
10446 +#ifdef CONFIG_PAX_REFCOUNT
10447 + "jno 0f\n"
10448 + _ASM_MOV "%0,%1\n"
10449 + "int $4\n0:\n"
10450 + _ASM_EXTABLE(0b, 0b)
10451 +#endif
10452 +
10453 : "+r" (i), "+m" (l->a.counter)
10454 : : "memory");
10455 return i + __i;
10456 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10457 index 593e51d..fa69c9a 100644
10458 --- a/arch/x86/include/asm/mman.h
10459 +++ b/arch/x86/include/asm/mman.h
10460 @@ -5,4 +5,14 @@
10461
10462 #include <asm-generic/mman.h>
10463
10464 +#ifdef __KERNEL__
10465 +#ifndef __ASSEMBLY__
10466 +#ifdef CONFIG_X86_32
10467 +#define arch_mmap_check i386_mmap_check
10468 +int i386_mmap_check(unsigned long addr, unsigned long len,
10469 + unsigned long flags);
10470 +#endif
10471 +#endif
10472 +#endif
10473 +
10474 #endif /* _ASM_X86_MMAN_H */
10475 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10476 index 5f55e69..e20bfb1 100644
10477 --- a/arch/x86/include/asm/mmu.h
10478 +++ b/arch/x86/include/asm/mmu.h
10479 @@ -9,7 +9,7 @@
10480 * we put the segment information here.
10481 */
10482 typedef struct {
10483 - void *ldt;
10484 + struct desc_struct *ldt;
10485 int size;
10486
10487 #ifdef CONFIG_X86_64
10488 @@ -18,7 +18,19 @@ typedef struct {
10489 #endif
10490
10491 struct mutex lock;
10492 - void *vdso;
10493 + unsigned long vdso;
10494 +
10495 +#ifdef CONFIG_X86_32
10496 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10497 + unsigned long user_cs_base;
10498 + unsigned long user_cs_limit;
10499 +
10500 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10501 + cpumask_t cpu_user_cs_mask;
10502 +#endif
10503 +
10504 +#endif
10505 +#endif
10506 } mm_context_t;
10507
10508 #ifdef CONFIG_SMP
10509 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10510 index 6902152..399f3a2 100644
10511 --- a/arch/x86/include/asm/mmu_context.h
10512 +++ b/arch/x86/include/asm/mmu_context.h
10513 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10514
10515 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10516 {
10517 +
10518 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10519 + unsigned int i;
10520 + pgd_t *pgd;
10521 +
10522 + pax_open_kernel();
10523 + pgd = get_cpu_pgd(smp_processor_id());
10524 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10525 + set_pgd_batched(pgd+i, native_make_pgd(0));
10526 + pax_close_kernel();
10527 +#endif
10528 +
10529 #ifdef CONFIG_SMP
10530 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10531 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10532 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10533 struct task_struct *tsk)
10534 {
10535 unsigned cpu = smp_processor_id();
10536 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10537 + int tlbstate = TLBSTATE_OK;
10538 +#endif
10539
10540 if (likely(prev != next)) {
10541 #ifdef CONFIG_SMP
10542 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10543 + tlbstate = percpu_read(cpu_tlbstate.state);
10544 +#endif
10545 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10546 percpu_write(cpu_tlbstate.active_mm, next);
10547 #endif
10548 cpumask_set_cpu(cpu, mm_cpumask(next));
10549
10550 /* Re-load page tables */
10551 +#ifdef CONFIG_PAX_PER_CPU_PGD
10552 + pax_open_kernel();
10553 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10554 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10555 + pax_close_kernel();
10556 + load_cr3(get_cpu_pgd(cpu));
10557 +#else
10558 load_cr3(next->pgd);
10559 +#endif
10560
10561 /* stop flush ipis for the previous mm */
10562 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10563 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10564 */
10565 if (unlikely(prev->context.ldt != next->context.ldt))
10566 load_LDT_nolock(&next->context);
10567 - }
10568 +
10569 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10570 + if (!(__supported_pte_mask & _PAGE_NX)) {
10571 + smp_mb__before_clear_bit();
10572 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10573 + smp_mb__after_clear_bit();
10574 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10575 + }
10576 +#endif
10577 +
10578 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10579 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10580 + prev->context.user_cs_limit != next->context.user_cs_limit))
10581 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10582 #ifdef CONFIG_SMP
10583 + else if (unlikely(tlbstate != TLBSTATE_OK))
10584 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10585 +#endif
10586 +#endif
10587 +
10588 + }
10589 else {
10590 +
10591 +#ifdef CONFIG_PAX_PER_CPU_PGD
10592 + pax_open_kernel();
10593 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10594 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10595 + pax_close_kernel();
10596 + load_cr3(get_cpu_pgd(cpu));
10597 +#endif
10598 +
10599 +#ifdef CONFIG_SMP
10600 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10601 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10602
10603 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10604 * tlb flush IPI delivery. We must reload CR3
10605 * to make sure to use no freed page tables.
10606 */
10607 +
10608 +#ifndef CONFIG_PAX_PER_CPU_PGD
10609 load_cr3(next->pgd);
10610 +#endif
10611 +
10612 load_LDT_nolock(&next->context);
10613 +
10614 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10615 + if (!(__supported_pte_mask & _PAGE_NX))
10616 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10617 +#endif
10618 +
10619 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10620 +#ifdef CONFIG_PAX_PAGEEXEC
10621 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10622 +#endif
10623 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10624 +#endif
10625 +
10626 }
10627 +#endif
10628 }
10629 -#endif
10630 }
10631
10632 #define activate_mm(prev, next) \
10633 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10634 index 9eae775..c914fea 100644
10635 --- a/arch/x86/include/asm/module.h
10636 +++ b/arch/x86/include/asm/module.h
10637 @@ -5,6 +5,7 @@
10638
10639 #ifdef CONFIG_X86_64
10640 /* X86_64 does not define MODULE_PROC_FAMILY */
10641 +#define MODULE_PROC_FAMILY ""
10642 #elif defined CONFIG_M386
10643 #define MODULE_PROC_FAMILY "386 "
10644 #elif defined CONFIG_M486
10645 @@ -59,8 +60,20 @@
10646 #error unknown processor family
10647 #endif
10648
10649 -#ifdef CONFIG_X86_32
10650 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10651 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10652 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10653 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10654 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10655 +#else
10656 +#define MODULE_PAX_KERNEXEC ""
10657 #endif
10658
10659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10660 +#define MODULE_PAX_UDEREF "UDEREF "
10661 +#else
10662 +#define MODULE_PAX_UDEREF ""
10663 +#endif
10664 +
10665 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10666 +
10667 #endif /* _ASM_X86_MODULE_H */
10668 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10669 index 7639dbf..e08a58c 100644
10670 --- a/arch/x86/include/asm/page_64_types.h
10671 +++ b/arch/x86/include/asm/page_64_types.h
10672 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10673
10674 /* duplicated to the one in bootmem.h */
10675 extern unsigned long max_pfn;
10676 -extern unsigned long phys_base;
10677 +extern const unsigned long phys_base;
10678
10679 extern unsigned long __phys_addr(unsigned long);
10680 #define __phys_reloc_hide(x) (x)
10681 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10682 index a7d2db9..edb023e 100644
10683 --- a/arch/x86/include/asm/paravirt.h
10684 +++ b/arch/x86/include/asm/paravirt.h
10685 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10686 val);
10687 }
10688
10689 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10690 +{
10691 + pgdval_t val = native_pgd_val(pgd);
10692 +
10693 + if (sizeof(pgdval_t) > sizeof(long))
10694 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10695 + val, (u64)val >> 32);
10696 + else
10697 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10698 + val);
10699 +}
10700 +
10701 static inline void pgd_clear(pgd_t *pgdp)
10702 {
10703 set_pgd(pgdp, __pgd(0));
10704 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10705 pv_mmu_ops.set_fixmap(idx, phys, flags);
10706 }
10707
10708 +#ifdef CONFIG_PAX_KERNEXEC
10709 +static inline unsigned long pax_open_kernel(void)
10710 +{
10711 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10712 +}
10713 +
10714 +static inline unsigned long pax_close_kernel(void)
10715 +{
10716 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10717 +}
10718 +#else
10719 +static inline unsigned long pax_open_kernel(void) { return 0; }
10720 +static inline unsigned long pax_close_kernel(void) { return 0; }
10721 +#endif
10722 +
10723 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10724
10725 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10726 @@ -964,7 +991,7 @@ extern void default_banner(void);
10727
10728 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10729 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10730 -#define PARA_INDIRECT(addr) *%cs:addr
10731 +#define PARA_INDIRECT(addr) *%ss:addr
10732 #endif
10733
10734 #define INTERRUPT_RETURN \
10735 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10736 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10737 CLBR_NONE, \
10738 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10739 +
10740 +#define GET_CR0_INTO_RDI \
10741 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10742 + mov %rax,%rdi
10743 +
10744 +#define SET_RDI_INTO_CR0 \
10745 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10746 +
10747 +#define GET_CR3_INTO_RDI \
10748 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10749 + mov %rax,%rdi
10750 +
10751 +#define SET_RDI_INTO_CR3 \
10752 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10753 +
10754 #endif /* CONFIG_X86_32 */
10755
10756 #endif /* __ASSEMBLY__ */
10757 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10758 index 8e8b9a4..f07d725 100644
10759 --- a/arch/x86/include/asm/paravirt_types.h
10760 +++ b/arch/x86/include/asm/paravirt_types.h
10761 @@ -84,20 +84,20 @@ struct pv_init_ops {
10762 */
10763 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10764 unsigned long addr, unsigned len);
10765 -};
10766 +} __no_const;
10767
10768
10769 struct pv_lazy_ops {
10770 /* Set deferred update mode, used for batching operations. */
10771 void (*enter)(void);
10772 void (*leave)(void);
10773 -};
10774 +} __no_const;
10775
10776 struct pv_time_ops {
10777 unsigned long long (*sched_clock)(void);
10778 unsigned long long (*steal_clock)(int cpu);
10779 unsigned long (*get_tsc_khz)(void);
10780 -};
10781 +} __no_const;
10782
10783 struct pv_cpu_ops {
10784 /* hooks for various privileged instructions */
10785 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10786
10787 void (*start_context_switch)(struct task_struct *prev);
10788 void (*end_context_switch)(struct task_struct *next);
10789 -};
10790 +} __no_const;
10791
10792 struct pv_irq_ops {
10793 /*
10794 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10795 unsigned long start_eip,
10796 unsigned long start_esp);
10797 #endif
10798 -};
10799 +} __no_const;
10800
10801 struct pv_mmu_ops {
10802 unsigned long (*read_cr2)(void);
10803 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10804 struct paravirt_callee_save make_pud;
10805
10806 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10807 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10808 #endif /* PAGETABLE_LEVELS == 4 */
10809 #endif /* PAGETABLE_LEVELS >= 3 */
10810
10811 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10812 an mfn. We can tell which is which from the index. */
10813 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10814 phys_addr_t phys, pgprot_t flags);
10815 +
10816 +#ifdef CONFIG_PAX_KERNEXEC
10817 + unsigned long (*pax_open_kernel)(void);
10818 + unsigned long (*pax_close_kernel)(void);
10819 +#endif
10820 +
10821 };
10822
10823 struct arch_spinlock;
10824 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10825 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10826 int (*spin_trylock)(struct arch_spinlock *lock);
10827 void (*spin_unlock)(struct arch_spinlock *lock);
10828 -};
10829 +} __no_const;
10830
10831 /* This contains all the paravirt structures: we get a convenient
10832 * number for each function using the offset which we use to indicate
10833 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10834 index b4389a4..b7ff22c 100644
10835 --- a/arch/x86/include/asm/pgalloc.h
10836 +++ b/arch/x86/include/asm/pgalloc.h
10837 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10838 pmd_t *pmd, pte_t *pte)
10839 {
10840 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10841 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10842 +}
10843 +
10844 +static inline void pmd_populate_user(struct mm_struct *mm,
10845 + pmd_t *pmd, pte_t *pte)
10846 +{
10847 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10848 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10849 }
10850
10851 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10852 index 98391db..8f6984e 100644
10853 --- a/arch/x86/include/asm/pgtable-2level.h
10854 +++ b/arch/x86/include/asm/pgtable-2level.h
10855 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10856
10857 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10858 {
10859 + pax_open_kernel();
10860 *pmdp = pmd;
10861 + pax_close_kernel();
10862 }
10863
10864 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10865 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10866 index effff47..f9e4035 100644
10867 --- a/arch/x86/include/asm/pgtable-3level.h
10868 +++ b/arch/x86/include/asm/pgtable-3level.h
10869 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10870
10871 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10872 {
10873 + pax_open_kernel();
10874 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10875 + pax_close_kernel();
10876 }
10877
10878 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10879 {
10880 + pax_open_kernel();
10881 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10882 + pax_close_kernel();
10883 }
10884
10885 /*
10886 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10887 index 49afb3f..ed14d07 100644
10888 --- a/arch/x86/include/asm/pgtable.h
10889 +++ b/arch/x86/include/asm/pgtable.h
10890 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10891
10892 #ifndef __PAGETABLE_PUD_FOLDED
10893 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10894 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10895 #define pgd_clear(pgd) native_pgd_clear(pgd)
10896 #endif
10897
10898 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10899
10900 #define arch_end_context_switch(prev) do {} while(0)
10901
10902 +#define pax_open_kernel() native_pax_open_kernel()
10903 +#define pax_close_kernel() native_pax_close_kernel()
10904 #endif /* CONFIG_PARAVIRT */
10905
10906 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10907 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10908 +
10909 +#ifdef CONFIG_PAX_KERNEXEC
10910 +static inline unsigned long native_pax_open_kernel(void)
10911 +{
10912 + unsigned long cr0;
10913 +
10914 + preempt_disable();
10915 + barrier();
10916 + cr0 = read_cr0() ^ X86_CR0_WP;
10917 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10918 + write_cr0(cr0);
10919 + return cr0 ^ X86_CR0_WP;
10920 +}
10921 +
10922 +static inline unsigned long native_pax_close_kernel(void)
10923 +{
10924 + unsigned long cr0;
10925 +
10926 + cr0 = read_cr0() ^ X86_CR0_WP;
10927 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10928 + write_cr0(cr0);
10929 + barrier();
10930 + preempt_enable_no_resched();
10931 + return cr0 ^ X86_CR0_WP;
10932 +}
10933 +#else
10934 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10935 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10936 +#endif
10937 +
10938 /*
10939 * The following only work if pte_present() is true.
10940 * Undefined behaviour if not..
10941 */
10942 +static inline int pte_user(pte_t pte)
10943 +{
10944 + return pte_val(pte) & _PAGE_USER;
10945 +}
10946 +
10947 static inline int pte_dirty(pte_t pte)
10948 {
10949 return pte_flags(pte) & _PAGE_DIRTY;
10950 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10951 return pte_clear_flags(pte, _PAGE_RW);
10952 }
10953
10954 +static inline pte_t pte_mkread(pte_t pte)
10955 +{
10956 + return __pte(pte_val(pte) | _PAGE_USER);
10957 +}
10958 +
10959 static inline pte_t pte_mkexec(pte_t pte)
10960 {
10961 - return pte_clear_flags(pte, _PAGE_NX);
10962 +#ifdef CONFIG_X86_PAE
10963 + if (__supported_pte_mask & _PAGE_NX)
10964 + return pte_clear_flags(pte, _PAGE_NX);
10965 + else
10966 +#endif
10967 + return pte_set_flags(pte, _PAGE_USER);
10968 +}
10969 +
10970 +static inline pte_t pte_exprotect(pte_t pte)
10971 +{
10972 +#ifdef CONFIG_X86_PAE
10973 + if (__supported_pte_mask & _PAGE_NX)
10974 + return pte_set_flags(pte, _PAGE_NX);
10975 + else
10976 +#endif
10977 + return pte_clear_flags(pte, _PAGE_USER);
10978 }
10979
10980 static inline pte_t pte_mkdirty(pte_t pte)
10981 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10982 #endif
10983
10984 #ifndef __ASSEMBLY__
10985 +
10986 +#ifdef CONFIG_PAX_PER_CPU_PGD
10987 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10988 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10989 +{
10990 + return cpu_pgd[cpu];
10991 +}
10992 +#endif
10993 +
10994 #include <linux/mm_types.h>
10995
10996 static inline int pte_none(pte_t pte)
10997 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10998
10999 static inline int pgd_bad(pgd_t pgd)
11000 {
11001 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11002 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11003 }
11004
11005 static inline int pgd_none(pgd_t pgd)
11006 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11007 * pgd_offset() returns a (pgd_t *)
11008 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11009 */
11010 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11011 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11012 +
11013 +#ifdef CONFIG_PAX_PER_CPU_PGD
11014 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11015 +#endif
11016 +
11017 /*
11018 * a shortcut which implies the use of the kernel's pgd, instead
11019 * of a process's
11020 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11021 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11022 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11023
11024 +#ifdef CONFIG_X86_32
11025 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11026 +#else
11027 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11028 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11029 +
11030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11031 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11032 +#else
11033 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11034 +#endif
11035 +
11036 +#endif
11037 +
11038 #ifndef __ASSEMBLY__
11039
11040 extern int direct_gbpages;
11041 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11042 * dst and src can be on the same page, but the range must not overlap,
11043 * and must not cross a page boundary.
11044 */
11045 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11046 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11047 {
11048 - memcpy(dst, src, count * sizeof(pgd_t));
11049 + pax_open_kernel();
11050 + while (count--)
11051 + *dst++ = *src++;
11052 + pax_close_kernel();
11053 }
11054
11055 +#ifdef CONFIG_PAX_PER_CPU_PGD
11056 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11057 +#endif
11058 +
11059 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11060 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11061 +#else
11062 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11063 +#endif
11064
11065 #include <asm-generic/pgtable.h>
11066 #endif /* __ASSEMBLY__ */
11067 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11068 index 0c92113..34a77c6 100644
11069 --- a/arch/x86/include/asm/pgtable_32.h
11070 +++ b/arch/x86/include/asm/pgtable_32.h
11071 @@ -25,9 +25,6 @@
11072 struct mm_struct;
11073 struct vm_area_struct;
11074
11075 -extern pgd_t swapper_pg_dir[1024];
11076 -extern pgd_t initial_page_table[1024];
11077 -
11078 static inline void pgtable_cache_init(void) { }
11079 static inline void check_pgt_cache(void) { }
11080 void paging_init(void);
11081 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11082 # include <asm/pgtable-2level.h>
11083 #endif
11084
11085 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11086 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11087 +#ifdef CONFIG_X86_PAE
11088 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11089 +#endif
11090 +
11091 #if defined(CONFIG_HIGHPTE)
11092 #define pte_offset_map(dir, address) \
11093 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11094 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11095 /* Clear a kernel PTE and flush it from the TLB */
11096 #define kpte_clear_flush(ptep, vaddr) \
11097 do { \
11098 + pax_open_kernel(); \
11099 pte_clear(&init_mm, (vaddr), (ptep)); \
11100 + pax_close_kernel(); \
11101 __flush_tlb_one((vaddr)); \
11102 } while (0)
11103
11104 @@ -74,6 +79,9 @@ do { \
11105
11106 #endif /* !__ASSEMBLY__ */
11107
11108 +#define HAVE_ARCH_UNMAPPED_AREA
11109 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11110 +
11111 /*
11112 * kern_addr_valid() is (1) for FLATMEM and (0) for
11113 * SPARSEMEM and DISCONTIGMEM
11114 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11115 index ed5903b..c7fe163 100644
11116 --- a/arch/x86/include/asm/pgtable_32_types.h
11117 +++ b/arch/x86/include/asm/pgtable_32_types.h
11118 @@ -8,7 +8,7 @@
11119 */
11120 #ifdef CONFIG_X86_PAE
11121 # include <asm/pgtable-3level_types.h>
11122 -# define PMD_SIZE (1UL << PMD_SHIFT)
11123 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11124 # define PMD_MASK (~(PMD_SIZE - 1))
11125 #else
11126 # include <asm/pgtable-2level_types.h>
11127 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11128 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11129 #endif
11130
11131 +#ifdef CONFIG_PAX_KERNEXEC
11132 +#ifndef __ASSEMBLY__
11133 +extern unsigned char MODULES_EXEC_VADDR[];
11134 +extern unsigned char MODULES_EXEC_END[];
11135 +#endif
11136 +#include <asm/boot.h>
11137 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11138 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11139 +#else
11140 +#define ktla_ktva(addr) (addr)
11141 +#define ktva_ktla(addr) (addr)
11142 +#endif
11143 +
11144 #define MODULES_VADDR VMALLOC_START
11145 #define MODULES_END VMALLOC_END
11146 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11147 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11148 index 975f709..107976d 100644
11149 --- a/arch/x86/include/asm/pgtable_64.h
11150 +++ b/arch/x86/include/asm/pgtable_64.h
11151 @@ -16,10 +16,14 @@
11152
11153 extern pud_t level3_kernel_pgt[512];
11154 extern pud_t level3_ident_pgt[512];
11155 +extern pud_t level3_vmalloc_start_pgt[512];
11156 +extern pud_t level3_vmalloc_end_pgt[512];
11157 +extern pud_t level3_vmemmap_pgt[512];
11158 +extern pud_t level2_vmemmap_pgt[512];
11159 extern pmd_t level2_kernel_pgt[512];
11160 extern pmd_t level2_fixmap_pgt[512];
11161 -extern pmd_t level2_ident_pgt[512];
11162 -extern pgd_t init_level4_pgt[];
11163 +extern pmd_t level2_ident_pgt[512*2];
11164 +extern pgd_t init_level4_pgt[512];
11165
11166 #define swapper_pg_dir init_level4_pgt
11167
11168 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11169
11170 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11171 {
11172 + pax_open_kernel();
11173 *pmdp = pmd;
11174 + pax_close_kernel();
11175 }
11176
11177 static inline void native_pmd_clear(pmd_t *pmd)
11178 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11179
11180 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11181 {
11182 + pax_open_kernel();
11183 + *pgdp = pgd;
11184 + pax_close_kernel();
11185 +}
11186 +
11187 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11188 +{
11189 *pgdp = pgd;
11190 }
11191
11192 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11193 index 766ea16..5b96cb3 100644
11194 --- a/arch/x86/include/asm/pgtable_64_types.h
11195 +++ b/arch/x86/include/asm/pgtable_64_types.h
11196 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11197 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11198 #define MODULES_END _AC(0xffffffffff000000, UL)
11199 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11200 +#define MODULES_EXEC_VADDR MODULES_VADDR
11201 +#define MODULES_EXEC_END MODULES_END
11202 +
11203 +#define ktla_ktva(addr) (addr)
11204 +#define ktva_ktla(addr) (addr)
11205
11206 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11207 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11208 index 013286a..8b42f4f 100644
11209 --- a/arch/x86/include/asm/pgtable_types.h
11210 +++ b/arch/x86/include/asm/pgtable_types.h
11211 @@ -16,13 +16,12 @@
11212 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11213 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11214 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11215 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11216 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11217 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11218 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11219 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11220 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11221 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11222 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11223 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11224 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11225 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11226
11227 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11228 @@ -40,7 +39,6 @@
11229 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11230 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11231 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11232 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11233 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11234 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11235 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11236 @@ -57,8 +55,10 @@
11237
11238 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11239 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11240 -#else
11241 +#elif defined(CONFIG_KMEMCHECK)
11242 #define _PAGE_NX (_AT(pteval_t, 0))
11243 +#else
11244 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11245 #endif
11246
11247 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11248 @@ -96,6 +96,9 @@
11249 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11250 _PAGE_ACCESSED)
11251
11252 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11253 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11254 +
11255 #define __PAGE_KERNEL_EXEC \
11256 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11257 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11258 @@ -106,7 +109,7 @@
11259 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11260 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11261 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11262 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11263 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11264 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11265 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11266 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11267 @@ -168,8 +171,8 @@
11268 * bits are combined, this will alow user to access the high address mapped
11269 * VDSO in the presence of CONFIG_COMPAT_VDSO
11270 */
11271 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11272 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11273 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11274 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11275 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11276 #endif
11277
11278 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11279 {
11280 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11281 }
11282 +#endif
11283
11284 +#if PAGETABLE_LEVELS == 3
11285 +#include <asm-generic/pgtable-nopud.h>
11286 +#endif
11287 +
11288 +#if PAGETABLE_LEVELS == 2
11289 +#include <asm-generic/pgtable-nopmd.h>
11290 +#endif
11291 +
11292 +#ifndef __ASSEMBLY__
11293 #if PAGETABLE_LEVELS > 3
11294 typedef struct { pudval_t pud; } pud_t;
11295
11296 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11297 return pud.pud;
11298 }
11299 #else
11300 -#include <asm-generic/pgtable-nopud.h>
11301 -
11302 static inline pudval_t native_pud_val(pud_t pud)
11303 {
11304 return native_pgd_val(pud.pgd);
11305 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11306 return pmd.pmd;
11307 }
11308 #else
11309 -#include <asm-generic/pgtable-nopmd.h>
11310 -
11311 static inline pmdval_t native_pmd_val(pmd_t pmd)
11312 {
11313 return native_pgd_val(pmd.pud.pgd);
11314 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11315
11316 extern pteval_t __supported_pte_mask;
11317 extern void set_nx(void);
11318 -extern int nx_enabled;
11319
11320 #define pgprot_writecombine pgprot_writecombine
11321 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11322 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11323 index 58545c9..fe6fc38e 100644
11324 --- a/arch/x86/include/asm/processor.h
11325 +++ b/arch/x86/include/asm/processor.h
11326 @@ -266,7 +266,7 @@ struct tss_struct {
11327
11328 } ____cacheline_aligned;
11329
11330 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11331 +extern struct tss_struct init_tss[NR_CPUS];
11332
11333 /*
11334 * Save the original ist values for checking stack pointers during debugging
11335 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11336 */
11337 #define TASK_SIZE PAGE_OFFSET
11338 #define TASK_SIZE_MAX TASK_SIZE
11339 +
11340 +#ifdef CONFIG_PAX_SEGMEXEC
11341 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11342 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11343 +#else
11344 #define STACK_TOP TASK_SIZE
11345 -#define STACK_TOP_MAX STACK_TOP
11346 +#endif
11347 +
11348 +#define STACK_TOP_MAX TASK_SIZE
11349
11350 #define INIT_THREAD { \
11351 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11352 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11353 .vm86_info = NULL, \
11354 .sysenter_cs = __KERNEL_CS, \
11355 .io_bitmap_ptr = NULL, \
11356 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11357 */
11358 #define INIT_TSS { \
11359 .x86_tss = { \
11360 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11361 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11362 .ss0 = __KERNEL_DS, \
11363 .ss1 = __KERNEL_CS, \
11364 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11365 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11366 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11367
11368 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11369 -#define KSTK_TOP(info) \
11370 -({ \
11371 - unsigned long *__ptr = (unsigned long *)(info); \
11372 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11373 -})
11374 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11375
11376 /*
11377 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11378 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11379 #define task_pt_regs(task) \
11380 ({ \
11381 struct pt_regs *__regs__; \
11382 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11383 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11384 __regs__ - 1; \
11385 })
11386
11387 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11388 /*
11389 * User space process size. 47bits minus one guard page.
11390 */
11391 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11392 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11393
11394 /* This decides where the kernel will search for a free chunk of vm
11395 * space during mmap's.
11396 */
11397 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11398 - 0xc0000000 : 0xFFFFe000)
11399 + 0xc0000000 : 0xFFFFf000)
11400
11401 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11402 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11403 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11404 #define STACK_TOP_MAX TASK_SIZE_MAX
11405
11406 #define INIT_THREAD { \
11407 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11408 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11409 }
11410
11411 #define INIT_TSS { \
11412 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11413 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11414 }
11415
11416 /*
11417 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11418 */
11419 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11420
11421 +#ifdef CONFIG_PAX_SEGMEXEC
11422 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11423 +#endif
11424 +
11425 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11426
11427 /* Get/set a process' ability to use the timestamp counter instruction */
11428 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11429 index 3566454..4bdfb8c 100644
11430 --- a/arch/x86/include/asm/ptrace.h
11431 +++ b/arch/x86/include/asm/ptrace.h
11432 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11433 }
11434
11435 /*
11436 - * user_mode_vm(regs) determines whether a register set came from user mode.
11437 + * user_mode(regs) determines whether a register set came from user mode.
11438 * This is true if V8086 mode was enabled OR if the register set was from
11439 * protected mode with RPL-3 CS value. This tricky test checks that with
11440 * one comparison. Many places in the kernel can bypass this full check
11441 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11442 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11443 + * be used.
11444 */
11445 -static inline int user_mode(struct pt_regs *regs)
11446 +static inline int user_mode_novm(struct pt_regs *regs)
11447 {
11448 #ifdef CONFIG_X86_32
11449 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11450 #else
11451 - return !!(regs->cs & 3);
11452 + return !!(regs->cs & SEGMENT_RPL_MASK);
11453 #endif
11454 }
11455
11456 -static inline int user_mode_vm(struct pt_regs *regs)
11457 +static inline int user_mode(struct pt_regs *regs)
11458 {
11459 #ifdef CONFIG_X86_32
11460 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11461 USER_RPL;
11462 #else
11463 - return user_mode(regs);
11464 + return user_mode_novm(regs);
11465 #endif
11466 }
11467
11468 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11469 #ifdef CONFIG_X86_64
11470 static inline bool user_64bit_mode(struct pt_regs *regs)
11471 {
11472 + unsigned long cs = regs->cs & 0xffff;
11473 #ifndef CONFIG_PARAVIRT
11474 /*
11475 * On non-paravirt systems, this is the only long mode CPL 3
11476 * selector. We do not allow long mode selectors in the LDT.
11477 */
11478 - return regs->cs == __USER_CS;
11479 + return cs == __USER_CS;
11480 #else
11481 /* Headers are too twisted for this to go in paravirt.h. */
11482 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11483 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11484 #endif
11485 }
11486 #endif
11487 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11488 index 92f29706..a79cbbb 100644
11489 --- a/arch/x86/include/asm/reboot.h
11490 +++ b/arch/x86/include/asm/reboot.h
11491 @@ -6,19 +6,19 @@
11492 struct pt_regs;
11493
11494 struct machine_ops {
11495 - void (*restart)(char *cmd);
11496 - void (*halt)(void);
11497 - void (*power_off)(void);
11498 + void (* __noreturn restart)(char *cmd);
11499 + void (* __noreturn halt)(void);
11500 + void (* __noreturn power_off)(void);
11501 void (*shutdown)(void);
11502 void (*crash_shutdown)(struct pt_regs *);
11503 - void (*emergency_restart)(void);
11504 -};
11505 + void (* __noreturn emergency_restart)(void);
11506 +} __no_const;
11507
11508 extern struct machine_ops machine_ops;
11509
11510 void native_machine_crash_shutdown(struct pt_regs *regs);
11511 void native_machine_shutdown(void);
11512 -void machine_real_restart(unsigned int type);
11513 +void machine_real_restart(unsigned int type) __noreturn;
11514 /* These must match dispatch_table in reboot_32.S */
11515 #define MRR_BIOS 0
11516 #define MRR_APM 1
11517 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11518 index 2dbe4a7..ce1db00 100644
11519 --- a/arch/x86/include/asm/rwsem.h
11520 +++ b/arch/x86/include/asm/rwsem.h
11521 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11522 {
11523 asm volatile("# beginning down_read\n\t"
11524 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11525 +
11526 +#ifdef CONFIG_PAX_REFCOUNT
11527 + "jno 0f\n"
11528 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11529 + "int $4\n0:\n"
11530 + _ASM_EXTABLE(0b, 0b)
11531 +#endif
11532 +
11533 /* adds 0x00000001 */
11534 " jns 1f\n"
11535 " call call_rwsem_down_read_failed\n"
11536 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11537 "1:\n\t"
11538 " mov %1,%2\n\t"
11539 " add %3,%2\n\t"
11540 +
11541 +#ifdef CONFIG_PAX_REFCOUNT
11542 + "jno 0f\n"
11543 + "sub %3,%2\n"
11544 + "int $4\n0:\n"
11545 + _ASM_EXTABLE(0b, 0b)
11546 +#endif
11547 +
11548 " jle 2f\n\t"
11549 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11550 " jnz 1b\n\t"
11551 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11552 long tmp;
11553 asm volatile("# beginning down_write\n\t"
11554 LOCK_PREFIX " xadd %1,(%2)\n\t"
11555 +
11556 +#ifdef CONFIG_PAX_REFCOUNT
11557 + "jno 0f\n"
11558 + "mov %1,(%2)\n"
11559 + "int $4\n0:\n"
11560 + _ASM_EXTABLE(0b, 0b)
11561 +#endif
11562 +
11563 /* adds 0xffff0001, returns the old value */
11564 " test %1,%1\n\t"
11565 /* was the count 0 before? */
11566 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11567 long tmp;
11568 asm volatile("# beginning __up_read\n\t"
11569 LOCK_PREFIX " xadd %1,(%2)\n\t"
11570 +
11571 +#ifdef CONFIG_PAX_REFCOUNT
11572 + "jno 0f\n"
11573 + "mov %1,(%2)\n"
11574 + "int $4\n0:\n"
11575 + _ASM_EXTABLE(0b, 0b)
11576 +#endif
11577 +
11578 /* subtracts 1, returns the old value */
11579 " jns 1f\n\t"
11580 " call call_rwsem_wake\n" /* expects old value in %edx */
11581 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11582 long tmp;
11583 asm volatile("# beginning __up_write\n\t"
11584 LOCK_PREFIX " xadd %1,(%2)\n\t"
11585 +
11586 +#ifdef CONFIG_PAX_REFCOUNT
11587 + "jno 0f\n"
11588 + "mov %1,(%2)\n"
11589 + "int $4\n0:\n"
11590 + _ASM_EXTABLE(0b, 0b)
11591 +#endif
11592 +
11593 /* subtracts 0xffff0001, returns the old value */
11594 " jns 1f\n\t"
11595 " call call_rwsem_wake\n" /* expects old value in %edx */
11596 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11597 {
11598 asm volatile("# beginning __downgrade_write\n\t"
11599 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11600 +
11601 +#ifdef CONFIG_PAX_REFCOUNT
11602 + "jno 0f\n"
11603 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11604 + "int $4\n0:\n"
11605 + _ASM_EXTABLE(0b, 0b)
11606 +#endif
11607 +
11608 /*
11609 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11610 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11611 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11612 */
11613 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11614 {
11615 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11616 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11617 +
11618 +#ifdef CONFIG_PAX_REFCOUNT
11619 + "jno 0f\n"
11620 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11621 + "int $4\n0:\n"
11622 + _ASM_EXTABLE(0b, 0b)
11623 +#endif
11624 +
11625 : "+m" (sem->count)
11626 : "er" (delta));
11627 }
11628 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11629 */
11630 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11631 {
11632 - return delta + xadd(&sem->count, delta);
11633 + return delta + xadd_check_overflow(&sem->count, delta);
11634 }
11635
11636 #endif /* __KERNEL__ */
11637 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11638 index 5e64171..f58957e 100644
11639 --- a/arch/x86/include/asm/segment.h
11640 +++ b/arch/x86/include/asm/segment.h
11641 @@ -64,10 +64,15 @@
11642 * 26 - ESPFIX small SS
11643 * 27 - per-cpu [ offset to per-cpu data area ]
11644 * 28 - stack_canary-20 [ for stack protector ]
11645 - * 29 - unused
11646 - * 30 - unused
11647 + * 29 - PCI BIOS CS
11648 + * 30 - PCI BIOS DS
11649 * 31 - TSS for double fault handler
11650 */
11651 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11652 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11653 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11654 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11655 +
11656 #define GDT_ENTRY_TLS_MIN 6
11657 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11658
11659 @@ -79,6 +84,8 @@
11660
11661 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11662
11663 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11664 +
11665 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11666
11667 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11668 @@ -104,6 +111,12 @@
11669 #define __KERNEL_STACK_CANARY 0
11670 #endif
11671
11672 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11673 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11674 +
11675 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11676 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11677 +
11678 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11679
11680 /*
11681 @@ -141,7 +154,7 @@
11682 */
11683
11684 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11685 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11686 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11687
11688
11689 #else
11690 @@ -165,6 +178,8 @@
11691 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11692 #define __USER32_DS __USER_DS
11693
11694 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11695 +
11696 #define GDT_ENTRY_TSS 8 /* needs two entries */
11697 #define GDT_ENTRY_LDT 10 /* needs two entries */
11698 #define GDT_ENTRY_TLS_MIN 12
11699 @@ -185,6 +200,7 @@
11700 #endif
11701
11702 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11703 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11704 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11705 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11706 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11707 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11708 index 0434c40..1714bf0 100644
11709 --- a/arch/x86/include/asm/smp.h
11710 +++ b/arch/x86/include/asm/smp.h
11711 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11712 /* cpus sharing the last level cache: */
11713 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11714 DECLARE_PER_CPU(u16, cpu_llc_id);
11715 -DECLARE_PER_CPU(int, cpu_number);
11716 +DECLARE_PER_CPU(unsigned int, cpu_number);
11717
11718 static inline struct cpumask *cpu_sibling_mask(int cpu)
11719 {
11720 @@ -77,7 +77,7 @@ struct smp_ops {
11721
11722 void (*send_call_func_ipi)(const struct cpumask *mask);
11723 void (*send_call_func_single_ipi)(int cpu);
11724 -};
11725 +} __no_const;
11726
11727 /* Globals due to paravirt */
11728 extern void set_cpu_sibling_map(int cpu);
11729 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11730 extern int safe_smp_processor_id(void);
11731
11732 #elif defined(CONFIG_X86_64_SMP)
11733 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11734 -
11735 -#define stack_smp_processor_id() \
11736 -({ \
11737 - struct thread_info *ti; \
11738 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11739 - ti->cpu; \
11740 -})
11741 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11742 +#define stack_smp_processor_id() raw_smp_processor_id()
11743 #define safe_smp_processor_id() smp_processor_id()
11744
11745 #endif
11746 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11747 index a82c2bf..2198f61 100644
11748 --- a/arch/x86/include/asm/spinlock.h
11749 +++ b/arch/x86/include/asm/spinlock.h
11750 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11751 static inline void arch_read_lock(arch_rwlock_t *rw)
11752 {
11753 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11754 +
11755 +#ifdef CONFIG_PAX_REFCOUNT
11756 + "jno 0f\n"
11757 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11758 + "int $4\n0:\n"
11759 + _ASM_EXTABLE(0b, 0b)
11760 +#endif
11761 +
11762 "jns 1f\n"
11763 "call __read_lock_failed\n\t"
11764 "1:\n"
11765 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11766 static inline void arch_write_lock(arch_rwlock_t *rw)
11767 {
11768 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11769 +
11770 +#ifdef CONFIG_PAX_REFCOUNT
11771 + "jno 0f\n"
11772 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11773 + "int $4\n0:\n"
11774 + _ASM_EXTABLE(0b, 0b)
11775 +#endif
11776 +
11777 "jz 1f\n"
11778 "call __write_lock_failed\n\t"
11779 "1:\n"
11780 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11781
11782 static inline void arch_read_unlock(arch_rwlock_t *rw)
11783 {
11784 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11785 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11786 +
11787 +#ifdef CONFIG_PAX_REFCOUNT
11788 + "jno 0f\n"
11789 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11790 + "int $4\n0:\n"
11791 + _ASM_EXTABLE(0b, 0b)
11792 +#endif
11793 +
11794 :"+m" (rw->lock) : : "memory");
11795 }
11796
11797 static inline void arch_write_unlock(arch_rwlock_t *rw)
11798 {
11799 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11800 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11801 +
11802 +#ifdef CONFIG_PAX_REFCOUNT
11803 + "jno 0f\n"
11804 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11805 + "int $4\n0:\n"
11806 + _ASM_EXTABLE(0b, 0b)
11807 +#endif
11808 +
11809 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11810 }
11811
11812 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11813 index 1575177..cb23f52 100644
11814 --- a/arch/x86/include/asm/stackprotector.h
11815 +++ b/arch/x86/include/asm/stackprotector.h
11816 @@ -48,7 +48,7 @@
11817 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11818 */
11819 #define GDT_STACK_CANARY_INIT \
11820 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11821 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11822
11823 /*
11824 * Initialize the stackprotector canary value.
11825 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11826
11827 static inline void load_stack_canary_segment(void)
11828 {
11829 -#ifdef CONFIG_X86_32
11830 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11831 asm volatile ("mov %0, %%gs" : : "r" (0));
11832 #endif
11833 }
11834 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11835 index 70bbe39..4ae2bd4 100644
11836 --- a/arch/x86/include/asm/stacktrace.h
11837 +++ b/arch/x86/include/asm/stacktrace.h
11838 @@ -11,28 +11,20 @@
11839
11840 extern int kstack_depth_to_print;
11841
11842 -struct thread_info;
11843 +struct task_struct;
11844 struct stacktrace_ops;
11845
11846 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11847 - unsigned long *stack,
11848 - unsigned long bp,
11849 - const struct stacktrace_ops *ops,
11850 - void *data,
11851 - unsigned long *end,
11852 - int *graph);
11853 +typedef unsigned long walk_stack_t(struct task_struct *task,
11854 + void *stack_start,
11855 + unsigned long *stack,
11856 + unsigned long bp,
11857 + const struct stacktrace_ops *ops,
11858 + void *data,
11859 + unsigned long *end,
11860 + int *graph);
11861
11862 -extern unsigned long
11863 -print_context_stack(struct thread_info *tinfo,
11864 - unsigned long *stack, unsigned long bp,
11865 - const struct stacktrace_ops *ops, void *data,
11866 - unsigned long *end, int *graph);
11867 -
11868 -extern unsigned long
11869 -print_context_stack_bp(struct thread_info *tinfo,
11870 - unsigned long *stack, unsigned long bp,
11871 - const struct stacktrace_ops *ops, void *data,
11872 - unsigned long *end, int *graph);
11873 +extern walk_stack_t print_context_stack;
11874 +extern walk_stack_t print_context_stack_bp;
11875
11876 /* Generic stack tracer with callbacks */
11877
11878 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11879 void (*address)(void *data, unsigned long address, int reliable);
11880 /* On negative return stop dumping */
11881 int (*stack)(void *data, char *name);
11882 - walk_stack_t walk_stack;
11883 + walk_stack_t *walk_stack;
11884 };
11885
11886 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11887 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11888 index cb23852..2dde194 100644
11889 --- a/arch/x86/include/asm/sys_ia32.h
11890 +++ b/arch/x86/include/asm/sys_ia32.h
11891 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11892 compat_sigset_t __user *, unsigned int);
11893 asmlinkage long sys32_alarm(unsigned int);
11894
11895 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11896 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11897 asmlinkage long sys32_sysfs(int, u32, u32);
11898
11899 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11900 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
11901 index f1d8b44..a4de8b7 100644
11902 --- a/arch/x86/include/asm/syscalls.h
11903 +++ b/arch/x86/include/asm/syscalls.h
11904 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
11905 void __user *, struct pt_regs *);
11906
11907 /* kernel/ldt.c */
11908 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
11909 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
11910
11911 /* kernel/signal.c */
11912 long sys_rt_sigreturn(struct pt_regs *);
11913 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11914 index 2d2f01c..f985723 100644
11915 --- a/arch/x86/include/asm/system.h
11916 +++ b/arch/x86/include/asm/system.h
11917 @@ -129,7 +129,7 @@ do { \
11918 "call __switch_to\n\t" \
11919 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11920 __switch_canary \
11921 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11922 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11923 "movq %%rax,%%rdi\n\t" \
11924 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11925 "jnz ret_from_fork\n\t" \
11926 @@ -140,7 +140,7 @@ do { \
11927 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11928 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11929 [_tif_fork] "i" (_TIF_FORK), \
11930 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11931 + [thread_info] "m" (current_tinfo), \
11932 [current_task] "m" (current_task) \
11933 __switch_canary_iparam \
11934 : "memory", "cc" __EXTRA_CLOBBER)
11935 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11936 {
11937 unsigned long __limit;
11938 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11939 - return __limit + 1;
11940 + return __limit;
11941 }
11942
11943 static inline void native_clts(void)
11944 @@ -397,13 +397,13 @@ void enable_hlt(void);
11945
11946 void cpu_idle_wait(void);
11947
11948 -extern unsigned long arch_align_stack(unsigned long sp);
11949 +#define arch_align_stack(x) ((x) & ~0xfUL)
11950 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11951
11952 void default_idle(void);
11953 bool set_pm_idle_to_default(void);
11954
11955 -void stop_this_cpu(void *dummy);
11956 +void stop_this_cpu(void *dummy) __noreturn;
11957
11958 /*
11959 * Force strict CPU ordering.
11960 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11961 index cfd8144..1b1127d 100644
11962 --- a/arch/x86/include/asm/thread_info.h
11963 +++ b/arch/x86/include/asm/thread_info.h
11964 @@ -10,6 +10,7 @@
11965 #include <linux/compiler.h>
11966 #include <asm/page.h>
11967 #include <asm/types.h>
11968 +#include <asm/percpu.h>
11969
11970 /*
11971 * low level task data that entry.S needs immediate access to
11972 @@ -24,7 +25,6 @@ struct exec_domain;
11973 #include <linux/atomic.h>
11974
11975 struct thread_info {
11976 - struct task_struct *task; /* main task structure */
11977 struct exec_domain *exec_domain; /* execution domain */
11978 __u32 flags; /* low level flags */
11979 __u32 status; /* thread synchronous flags */
11980 @@ -34,19 +34,13 @@ struct thread_info {
11981 mm_segment_t addr_limit;
11982 struct restart_block restart_block;
11983 void __user *sysenter_return;
11984 -#ifdef CONFIG_X86_32
11985 - unsigned long previous_esp; /* ESP of the previous stack in
11986 - case of nested (IRQ) stacks
11987 - */
11988 - __u8 supervisor_stack[0];
11989 -#endif
11990 + unsigned long lowest_stack;
11991 unsigned int sig_on_uaccess_error:1;
11992 unsigned int uaccess_err:1; /* uaccess failed */
11993 };
11994
11995 -#define INIT_THREAD_INFO(tsk) \
11996 +#define INIT_THREAD_INFO \
11997 { \
11998 - .task = &tsk, \
11999 .exec_domain = &default_exec_domain, \
12000 .flags = 0, \
12001 .cpu = 0, \
12002 @@ -57,7 +51,7 @@ struct thread_info {
12003 }, \
12004 }
12005
12006 -#define init_thread_info (init_thread_union.thread_info)
12007 +#define init_thread_info (init_thread_union.stack)
12008 #define init_stack (init_thread_union.stack)
12009
12010 #else /* !__ASSEMBLY__ */
12011 @@ -169,45 +163,40 @@ struct thread_info {
12012 ret; \
12013 })
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 -
12026 -/* how to get the current stack pointer from C */
12027 -register unsigned long current_stack_pointer asm("esp") __used;
12028 -
12029 -/* how to get the thread information struct from C */
12030 -static inline struct thread_info *current_thread_info(void)
12031 -{
12032 - return (struct thread_info *)
12033 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12034 -}
12035 -
12036 -#else /* !__ASSEMBLY__ */
12037 -
12038 +#ifdef __ASSEMBLY__
12039 /* how to get the thread information struct from ASM */
12040 #define GET_THREAD_INFO(reg) \
12041 - movl $-THREAD_SIZE, reg; \
12042 - andl %esp, reg
12043 + mov PER_CPU_VAR(current_tinfo), reg
12044
12045 /* use this one if reg already contains %esp */
12046 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12047 - andl $-THREAD_SIZE, reg
12048 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12049 +#else
12050 +/* how to get the thread information struct from C */
12051 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12052 +
12053 +static __always_inline struct thread_info *current_thread_info(void)
12054 +{
12055 + return percpu_read_stable(current_tinfo);
12056 +}
12057 +#endif
12058 +
12059 +#ifdef CONFIG_X86_32
12060 +
12061 +#define STACK_WARN (THREAD_SIZE/8)
12062 +/*
12063 + * macros/functions for gaining access to the thread information structure
12064 + *
12065 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12066 + */
12067 +#ifndef __ASSEMBLY__
12068 +
12069 +/* how to get the current stack pointer from C */
12070 +register unsigned long current_stack_pointer asm("esp") __used;
12071
12072 #endif
12073
12074 #else /* X86_32 */
12075
12076 -#include <asm/percpu.h>
12077 -#define KERNEL_STACK_OFFSET (5*8)
12078 -
12079 /*
12080 * macros/functions for gaining access to the thread information structure
12081 * preempt_count needs to be 1 initially, until the scheduler is functional.
12082 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
12083 #ifndef __ASSEMBLY__
12084 DECLARE_PER_CPU(unsigned long, kernel_stack);
12085
12086 -static inline struct thread_info *current_thread_info(void)
12087 -{
12088 - struct thread_info *ti;
12089 - ti = (void *)(percpu_read_stable(kernel_stack) +
12090 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12091 - return ti;
12092 -}
12093 -
12094 -#else /* !__ASSEMBLY__ */
12095 -
12096 -/* how to get the thread information struct from ASM */
12097 -#define GET_THREAD_INFO(reg) \
12098 - movq PER_CPU_VAR(kernel_stack),reg ; \
12099 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12100 -
12101 -/*
12102 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12103 - * a certain register (to be used in assembler memory operands).
12104 - */
12105 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12106 -
12107 +/* how to get the current stack pointer from C */
12108 +register unsigned long current_stack_pointer asm("rsp") __used;
12109 #endif
12110
12111 #endif /* !X86_32 */
12112 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
12113 extern void free_thread_info(struct thread_info *ti);
12114 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12115 #define arch_task_cache_init arch_task_cache_init
12116 +
12117 +#define __HAVE_THREAD_FUNCTIONS
12118 +#define task_thread_info(task) (&(task)->tinfo)
12119 +#define task_stack_page(task) ((task)->stack)
12120 +#define setup_thread_stack(p, org) do {} while (0)
12121 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12122 +
12123 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12124 +extern struct task_struct *alloc_task_struct_node(int node);
12125 +extern void free_task_struct(struct task_struct *);
12126 +
12127 #endif
12128 #endif /* _ASM_X86_THREAD_INFO_H */
12129 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12130 index 8be5f54..7ae826d 100644
12131 --- a/arch/x86/include/asm/uaccess.h
12132 +++ b/arch/x86/include/asm/uaccess.h
12133 @@ -7,12 +7,15 @@
12134 #include <linux/compiler.h>
12135 #include <linux/thread_info.h>
12136 #include <linux/string.h>
12137 +#include <linux/sched.h>
12138 #include <asm/asm.h>
12139 #include <asm/page.h>
12140
12141 #define VERIFY_READ 0
12142 #define VERIFY_WRITE 1
12143
12144 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12145 +
12146 /*
12147 * The fs value determines whether argument validity checking should be
12148 * performed or not. If get_fs() == USER_DS, checking is performed, with
12149 @@ -28,7 +31,12 @@
12150
12151 #define get_ds() (KERNEL_DS)
12152 #define get_fs() (current_thread_info()->addr_limit)
12153 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12154 +void __set_fs(mm_segment_t x);
12155 +void set_fs(mm_segment_t x);
12156 +#else
12157 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12158 +#endif
12159
12160 #define segment_eq(a, b) ((a).seg == (b).seg)
12161
12162 @@ -76,7 +84,33 @@
12163 * checks that the pointer is in the user space range - after calling
12164 * this function, memory access functions may still return -EFAULT.
12165 */
12166 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12167 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12168 +#define access_ok(type, addr, size) \
12169 +({ \
12170 + long __size = size; \
12171 + unsigned long __addr = (unsigned long)addr; \
12172 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12173 + unsigned long __end_ao = __addr + __size - 1; \
12174 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12175 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12176 + while(__addr_ao <= __end_ao) { \
12177 + char __c_ao; \
12178 + __addr_ao += PAGE_SIZE; \
12179 + if (__size > PAGE_SIZE) \
12180 + cond_resched(); \
12181 + if (__get_user(__c_ao, (char __user *)__addr)) \
12182 + break; \
12183 + if (type != VERIFY_WRITE) { \
12184 + __addr = __addr_ao; \
12185 + continue; \
12186 + } \
12187 + if (__put_user(__c_ao, (char __user *)__addr)) \
12188 + break; \
12189 + __addr = __addr_ao; \
12190 + } \
12191 + } \
12192 + __ret_ao; \
12193 +})
12194
12195 /*
12196 * The exception table consists of pairs of addresses: the first is the
12197 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12198 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12199 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12200
12201 -
12202 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12203 +#define __copyuser_seg "gs;"
12204 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12205 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12206 +#else
12207 +#define __copyuser_seg
12208 +#define __COPYUSER_SET_ES
12209 +#define __COPYUSER_RESTORE_ES
12210 +#endif
12211
12212 #ifdef CONFIG_X86_32
12213 #define __put_user_asm_u64(x, addr, err, errret) \
12214 - asm volatile("1: movl %%eax,0(%2)\n" \
12215 - "2: movl %%edx,4(%2)\n" \
12216 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12217 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12218 "3:\n" \
12219 ".section .fixup,\"ax\"\n" \
12220 "4: movl %3,%0\n" \
12221 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12222 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12223
12224 #define __put_user_asm_ex_u64(x, addr) \
12225 - asm volatile("1: movl %%eax,0(%1)\n" \
12226 - "2: movl %%edx,4(%1)\n" \
12227 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12228 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12229 "3:\n" \
12230 _ASM_EXTABLE(1b, 2b - 1b) \
12231 _ASM_EXTABLE(2b, 3b - 2b) \
12232 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12233 __typeof__(*(ptr)) __pu_val; \
12234 __chk_user_ptr(ptr); \
12235 might_fault(); \
12236 - __pu_val = x; \
12237 + __pu_val = (x); \
12238 switch (sizeof(*(ptr))) { \
12239 case 1: \
12240 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12241 @@ -373,7 +415,7 @@ do { \
12242 } while (0)
12243
12244 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12245 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12246 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12247 "2:\n" \
12248 ".section .fixup,\"ax\"\n" \
12249 "3: mov %3,%0\n" \
12250 @@ -381,7 +423,7 @@ do { \
12251 " jmp 2b\n" \
12252 ".previous\n" \
12253 _ASM_EXTABLE(1b, 3b) \
12254 - : "=r" (err), ltype(x) \
12255 + : "=r" (err), ltype (x) \
12256 : "m" (__m(addr)), "i" (errret), "0" (err))
12257
12258 #define __get_user_size_ex(x, ptr, size) \
12259 @@ -406,7 +448,7 @@ do { \
12260 } while (0)
12261
12262 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12263 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12264 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12265 "2:\n" \
12266 _ASM_EXTABLE(1b, 2b - 1b) \
12267 : ltype(x) : "m" (__m(addr)))
12268 @@ -423,13 +465,24 @@ do { \
12269 int __gu_err; \
12270 unsigned long __gu_val; \
12271 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12272 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12273 + (x) = (__typeof__(*(ptr)))__gu_val; \
12274 __gu_err; \
12275 })
12276
12277 /* FIXME: this hack is definitely wrong -AK */
12278 struct __large_struct { unsigned long buf[100]; };
12279 -#define __m(x) (*(struct __large_struct __user *)(x))
12280 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12281 +#define ____m(x) \
12282 +({ \
12283 + unsigned long ____x = (unsigned long)(x); \
12284 + if (____x < PAX_USER_SHADOW_BASE) \
12285 + ____x += PAX_USER_SHADOW_BASE; \
12286 + (void __user *)____x; \
12287 +})
12288 +#else
12289 +#define ____m(x) (x)
12290 +#endif
12291 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12292
12293 /*
12294 * Tell gcc we read from memory instead of writing: this is because
12295 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12296 * aliasing issues.
12297 */
12298 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12299 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12300 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12301 "2:\n" \
12302 ".section .fixup,\"ax\"\n" \
12303 "3: mov %3,%0\n" \
12304 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12305 ".previous\n" \
12306 _ASM_EXTABLE(1b, 3b) \
12307 : "=r"(err) \
12308 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12309 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12310
12311 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12312 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12313 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12314 "2:\n" \
12315 _ASM_EXTABLE(1b, 2b - 1b) \
12316 : : ltype(x), "m" (__m(addr)))
12317 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12318 * On error, the variable @x is set to zero.
12319 */
12320
12321 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12322 +#define __get_user(x, ptr) get_user((x), (ptr))
12323 +#else
12324 #define __get_user(x, ptr) \
12325 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12326 +#endif
12327
12328 /**
12329 * __put_user: - Write a simple value into user space, with less checking.
12330 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12331 * Returns zero on success, or -EFAULT on error.
12332 */
12333
12334 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12335 +#define __put_user(x, ptr) put_user((x), (ptr))
12336 +#else
12337 #define __put_user(x, ptr) \
12338 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12339 +#endif
12340
12341 #define __get_user_unaligned __get_user
12342 #define __put_user_unaligned __put_user
12343 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12344 #define get_user_ex(x, ptr) do { \
12345 unsigned long __gue_val; \
12346 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12347 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12348 + (x) = (__typeof__(*(ptr)))__gue_val; \
12349 } while (0)
12350
12351 #ifdef CONFIG_X86_WP_WORKS_OK
12352 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12353 index 566e803..7183d0b 100644
12354 --- a/arch/x86/include/asm/uaccess_32.h
12355 +++ b/arch/x86/include/asm/uaccess_32.h
12356 @@ -11,15 +11,15 @@
12357 #include <asm/page.h>
12358
12359 unsigned long __must_check __copy_to_user_ll
12360 - (void __user *to, const void *from, unsigned long n);
12361 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12362 unsigned long __must_check __copy_from_user_ll
12363 - (void *to, const void __user *from, unsigned long n);
12364 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12365 unsigned long __must_check __copy_from_user_ll_nozero
12366 - (void *to, const void __user *from, unsigned long n);
12367 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12368 unsigned long __must_check __copy_from_user_ll_nocache
12369 - (void *to, const void __user *from, unsigned long n);
12370 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12371 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12372 - (void *to, const void __user *from, unsigned long n);
12373 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12374
12375 /**
12376 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12377 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12378 */
12379
12380 static __always_inline unsigned long __must_check
12381 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12382 +static __always_inline unsigned long __must_check
12383 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12384 {
12385 + if ((long)n < 0)
12386 + return n;
12387 +
12388 if (__builtin_constant_p(n)) {
12389 unsigned long ret;
12390
12391 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12392 return ret;
12393 }
12394 }
12395 + if (!__builtin_constant_p(n))
12396 + check_object_size(from, n, true);
12397 return __copy_to_user_ll(to, from, n);
12398 }
12399
12400 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12401 * On success, this will be zero.
12402 */
12403 static __always_inline unsigned long __must_check
12404 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12405 +static __always_inline unsigned long __must_check
12406 __copy_to_user(void __user *to, const void *from, unsigned long n)
12407 {
12408 might_fault();
12409 +
12410 return __copy_to_user_inatomic(to, from, n);
12411 }
12412
12413 static __always_inline unsigned long
12414 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12415 +static __always_inline unsigned long
12416 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12417 {
12418 + if ((long)n < 0)
12419 + return n;
12420 +
12421 /* Avoid zeroing the tail if the copy fails..
12422 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12423 * but as the zeroing behaviour is only significant when n is not
12424 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12425 * for explanation of why this is needed.
12426 */
12427 static __always_inline unsigned long
12428 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12429 +static __always_inline unsigned long
12430 __copy_from_user(void *to, const void __user *from, unsigned long n)
12431 {
12432 might_fault();
12433 +
12434 + if ((long)n < 0)
12435 + return n;
12436 +
12437 if (__builtin_constant_p(n)) {
12438 unsigned long ret;
12439
12440 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12441 return ret;
12442 }
12443 }
12444 + if (!__builtin_constant_p(n))
12445 + check_object_size(to, n, false);
12446 return __copy_from_user_ll(to, from, n);
12447 }
12448
12449 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12450 + const void __user *from, unsigned long n) __size_overflow(3);
12451 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12452 const void __user *from, unsigned long n)
12453 {
12454 might_fault();
12455 +
12456 + if ((long)n < 0)
12457 + return n;
12458 +
12459 if (__builtin_constant_p(n)) {
12460 unsigned long ret;
12461
12462 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12463
12464 static __always_inline unsigned long
12465 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12466 + unsigned long n) __size_overflow(3);
12467 +static __always_inline unsigned long
12468 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12469 unsigned long n)
12470 {
12471 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12472 + if ((long)n < 0)
12473 + return n;
12474 +
12475 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12476 }
12477
12478 -unsigned long __must_check copy_to_user(void __user *to,
12479 - const void *from, unsigned long n);
12480 -unsigned long __must_check _copy_from_user(void *to,
12481 - const void __user *from,
12482 - unsigned long n);
12483 -
12484 +extern void copy_to_user_overflow(void)
12485 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12486 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12487 +#else
12488 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12489 +#endif
12490 +;
12491
12492 extern void copy_from_user_overflow(void)
12493 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12494 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
12495 #endif
12496 ;
12497
12498 -static inline unsigned long __must_check copy_from_user(void *to,
12499 - const void __user *from,
12500 - unsigned long n)
12501 +/**
12502 + * copy_to_user: - Copy a block of data into user space.
12503 + * @to: Destination address, in user space.
12504 + * @from: Source address, in kernel space.
12505 + * @n: Number of bytes to copy.
12506 + *
12507 + * Context: User context only. This function may sleep.
12508 + *
12509 + * Copy data from kernel space to user space.
12510 + *
12511 + * Returns number of bytes that could not be copied.
12512 + * On success, this will be zero.
12513 + */
12514 +static inline unsigned long __must_check
12515 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12516 +static inline unsigned long __must_check
12517 +copy_to_user(void __user *to, const void *from, unsigned long n)
12518 +{
12519 + int sz = __compiletime_object_size(from);
12520 +
12521 + if (unlikely(sz != -1 && sz < n))
12522 + copy_to_user_overflow();
12523 + else if (access_ok(VERIFY_WRITE, to, n))
12524 + n = __copy_to_user(to, from, n);
12525 + return n;
12526 +}
12527 +
12528 +/**
12529 + * copy_from_user: - Copy a block of data from user space.
12530 + * @to: Destination address, in kernel space.
12531 + * @from: Source address, in user space.
12532 + * @n: Number of bytes to copy.
12533 + *
12534 + * Context: User context only. This function may sleep.
12535 + *
12536 + * Copy data from user space to kernel space.
12537 + *
12538 + * Returns number of bytes that could not be copied.
12539 + * On success, this will be zero.
12540 + *
12541 + * If some data could not be copied, this function will pad the copied
12542 + * data to the requested size using zero bytes.
12543 + */
12544 +static inline unsigned long __must_check
12545 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12546 +static inline unsigned long __must_check
12547 +copy_from_user(void *to, const void __user *from, unsigned long n)
12548 {
12549 int sz = __compiletime_object_size(to);
12550
12551 - if (likely(sz == -1 || sz >= n))
12552 - n = _copy_from_user(to, from, n);
12553 - else
12554 + if (unlikely(sz != -1 && sz < n))
12555 copy_from_user_overflow();
12556 -
12557 + else if (access_ok(VERIFY_READ, from, n))
12558 + n = __copy_from_user(to, from, n);
12559 + else if ((long)n > 0) {
12560 + if (!__builtin_constant_p(n))
12561 + check_object_size(to, n, false);
12562 + memset(to, 0, n);
12563 + }
12564 return n;
12565 }
12566
12567 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
12568 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12569
12570 long strnlen_user(const char __user *str, long n);
12571 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12572 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12573 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12574 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12575
12576 #endif /* _ASM_X86_UACCESS_32_H */
12577 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12578 index 1c66d30..e294b5f 100644
12579 --- a/arch/x86/include/asm/uaccess_64.h
12580 +++ b/arch/x86/include/asm/uaccess_64.h
12581 @@ -10,6 +10,9 @@
12582 #include <asm/alternative.h>
12583 #include <asm/cpufeature.h>
12584 #include <asm/page.h>
12585 +#include <asm/pgtable.h>
12586 +
12587 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12588
12589 /*
12590 * Copy To/From Userspace
12591 @@ -17,12 +20,14 @@
12592
12593 /* Handles exceptions in both to and from, but doesn't do access_ok */
12594 __must_check unsigned long
12595 -copy_user_generic_string(void *to, const void *from, unsigned len);
12596 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12597 __must_check unsigned long
12598 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12599 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12600
12601 static __always_inline __must_check unsigned long
12602 -copy_user_generic(void *to, const void *from, unsigned len)
12603 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12604 +static __always_inline __must_check unsigned long
12605 +copy_user_generic(void *to, const void *from, unsigned long len)
12606 {
12607 unsigned ret;
12608
12609 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12610 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12611 "=d" (len)),
12612 "1" (to), "2" (from), "3" (len)
12613 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12614 + : "memory", "rcx", "r8", "r9", "r11");
12615 return ret;
12616 }
12617
12618 +static __always_inline __must_check unsigned long
12619 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12620 +static __always_inline __must_check unsigned long
12621 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12622 __must_check unsigned long
12623 -_copy_to_user(void __user *to, const void *from, unsigned len);
12624 -__must_check unsigned long
12625 -_copy_from_user(void *to, const void __user *from, unsigned len);
12626 -__must_check unsigned long
12627 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12628 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12629
12630 static inline unsigned long __must_check copy_from_user(void *to,
12631 const void __user *from,
12632 + unsigned long n) __size_overflow(3);
12633 +static inline unsigned long __must_check copy_from_user(void *to,
12634 + const void __user *from,
12635 unsigned long n)
12636 {
12637 - int sz = __compiletime_object_size(to);
12638 -
12639 might_fault();
12640 - if (likely(sz == -1 || sz >= n))
12641 - n = _copy_from_user(to, from, n);
12642 -#ifdef CONFIG_DEBUG_VM
12643 - else
12644 - WARN(1, "Buffer overflow detected!\n");
12645 -#endif
12646 +
12647 + if (access_ok(VERIFY_READ, from, n))
12648 + n = __copy_from_user(to, from, n);
12649 + else if (n < INT_MAX) {
12650 + if (!__builtin_constant_p(n))
12651 + check_object_size(to, n, false);
12652 + memset(to, 0, n);
12653 + }
12654 return n;
12655 }
12656
12657 static __always_inline __must_check
12658 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12659 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12660 +static __always_inline __must_check
12661 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12662 {
12663 might_fault();
12664
12665 - return _copy_to_user(dst, src, size);
12666 + if (access_ok(VERIFY_WRITE, dst, size))
12667 + size = __copy_to_user(dst, src, size);
12668 + return size;
12669 }
12670
12671 static __always_inline __must_check
12672 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12673 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12674 +static __always_inline __must_check
12675 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12676 {
12677 - int ret = 0;
12678 + int sz = __compiletime_object_size(dst);
12679 + unsigned ret = 0;
12680
12681 might_fault();
12682 - if (!__builtin_constant_p(size))
12683 - return copy_user_generic(dst, (__force void *)src, size);
12684 +
12685 + if (size > INT_MAX)
12686 + return size;
12687 +
12688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12689 + if (!__access_ok(VERIFY_READ, src, size))
12690 + return size;
12691 +#endif
12692 +
12693 + if (unlikely(sz != -1 && sz < size)) {
12694 +#ifdef CONFIG_DEBUG_VM
12695 + WARN(1, "Buffer overflow detected!\n");
12696 +#endif
12697 + return size;
12698 + }
12699 +
12700 + if (!__builtin_constant_p(size)) {
12701 + check_object_size(dst, size, false);
12702 +
12703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12704 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12705 + src += PAX_USER_SHADOW_BASE;
12706 +#endif
12707 +
12708 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12709 + }
12710 switch (size) {
12711 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12712 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12713 ret, "b", "b", "=q", 1);
12714 return ret;
12715 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12716 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12717 ret, "w", "w", "=r", 2);
12718 return ret;
12719 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12720 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12721 ret, "l", "k", "=r", 4);
12722 return ret;
12723 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12724 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12725 ret, "q", "", "=r", 8);
12726 return ret;
12727 case 10:
12728 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12729 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12730 ret, "q", "", "=r", 10);
12731 if (unlikely(ret))
12732 return ret;
12733 __get_user_asm(*(u16 *)(8 + (char *)dst),
12734 - (u16 __user *)(8 + (char __user *)src),
12735 + (const u16 __user *)(8 + (const char __user *)src),
12736 ret, "w", "w", "=r", 2);
12737 return ret;
12738 case 16:
12739 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12740 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12741 ret, "q", "", "=r", 16);
12742 if (unlikely(ret))
12743 return ret;
12744 __get_user_asm(*(u64 *)(8 + (char *)dst),
12745 - (u64 __user *)(8 + (char __user *)src),
12746 + (const u64 __user *)(8 + (const char __user *)src),
12747 ret, "q", "", "=r", 8);
12748 return ret;
12749 default:
12750 - return copy_user_generic(dst, (__force void *)src, size);
12751 +
12752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12753 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12754 + src += PAX_USER_SHADOW_BASE;
12755 +#endif
12756 +
12757 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12758 }
12759 }
12760
12761 static __always_inline __must_check
12762 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12763 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12764 +static __always_inline __must_check
12765 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12766 {
12767 - int ret = 0;
12768 + int sz = __compiletime_object_size(src);
12769 + unsigned ret = 0;
12770
12771 might_fault();
12772 - if (!__builtin_constant_p(size))
12773 - return copy_user_generic((__force void *)dst, src, size);
12774 +
12775 + if (size > INT_MAX)
12776 + return size;
12777 +
12778 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12779 + if (!__access_ok(VERIFY_WRITE, dst, size))
12780 + return size;
12781 +#endif
12782 +
12783 + if (unlikely(sz != -1 && sz < size)) {
12784 +#ifdef CONFIG_DEBUG_VM
12785 + WARN(1, "Buffer overflow detected!\n");
12786 +#endif
12787 + return size;
12788 + }
12789 +
12790 + if (!__builtin_constant_p(size)) {
12791 + check_object_size(src, size, true);
12792 +
12793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12794 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12795 + dst += PAX_USER_SHADOW_BASE;
12796 +#endif
12797 +
12798 + return copy_user_generic((__force_kernel void *)dst, src, size);
12799 + }
12800 switch (size) {
12801 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12802 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12803 ret, "b", "b", "iq", 1);
12804 return ret;
12805 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12806 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12807 ret, "w", "w", "ir", 2);
12808 return ret;
12809 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12810 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12811 ret, "l", "k", "ir", 4);
12812 return ret;
12813 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12814 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12815 ret, "q", "", "er", 8);
12816 return ret;
12817 case 10:
12818 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12819 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12820 ret, "q", "", "er", 10);
12821 if (unlikely(ret))
12822 return ret;
12823 asm("":::"memory");
12824 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12825 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12826 ret, "w", "w", "ir", 2);
12827 return ret;
12828 case 16:
12829 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12830 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12831 ret, "q", "", "er", 16);
12832 if (unlikely(ret))
12833 return ret;
12834 asm("":::"memory");
12835 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12836 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12837 ret, "q", "", "er", 8);
12838 return ret;
12839 default:
12840 - return copy_user_generic((__force void *)dst, src, size);
12841 +
12842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12843 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12844 + dst += PAX_USER_SHADOW_BASE;
12845 +#endif
12846 +
12847 + return copy_user_generic((__force_kernel void *)dst, src, size);
12848 }
12849 }
12850
12851 static __always_inline __must_check
12852 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12853 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
12854 +static __always_inline __must_check
12855 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12856 {
12857 - int ret = 0;
12858 + unsigned ret = 0;
12859
12860 might_fault();
12861 - if (!__builtin_constant_p(size))
12862 - return copy_user_generic((__force void *)dst,
12863 - (__force void *)src, size);
12864 +
12865 + if (size > INT_MAX)
12866 + return size;
12867 +
12868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12869 + if (!__access_ok(VERIFY_READ, src, size))
12870 + return size;
12871 + if (!__access_ok(VERIFY_WRITE, dst, size))
12872 + return size;
12873 +#endif
12874 +
12875 + if (!__builtin_constant_p(size)) {
12876 +
12877 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12878 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12879 + src += PAX_USER_SHADOW_BASE;
12880 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12881 + dst += PAX_USER_SHADOW_BASE;
12882 +#endif
12883 +
12884 + return copy_user_generic((__force_kernel void *)dst,
12885 + (__force_kernel const void *)src, size);
12886 + }
12887 switch (size) {
12888 case 1: {
12889 u8 tmp;
12890 - __get_user_asm(tmp, (u8 __user *)src,
12891 + __get_user_asm(tmp, (const u8 __user *)src,
12892 ret, "b", "b", "=q", 1);
12893 if (likely(!ret))
12894 __put_user_asm(tmp, (u8 __user *)dst,
12895 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12896 }
12897 case 2: {
12898 u16 tmp;
12899 - __get_user_asm(tmp, (u16 __user *)src,
12900 + __get_user_asm(tmp, (const u16 __user *)src,
12901 ret, "w", "w", "=r", 2);
12902 if (likely(!ret))
12903 __put_user_asm(tmp, (u16 __user *)dst,
12904 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12905
12906 case 4: {
12907 u32 tmp;
12908 - __get_user_asm(tmp, (u32 __user *)src,
12909 + __get_user_asm(tmp, (const u32 __user *)src,
12910 ret, "l", "k", "=r", 4);
12911 if (likely(!ret))
12912 __put_user_asm(tmp, (u32 __user *)dst,
12913 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12914 }
12915 case 8: {
12916 u64 tmp;
12917 - __get_user_asm(tmp, (u64 __user *)src,
12918 + __get_user_asm(tmp, (const u64 __user *)src,
12919 ret, "q", "", "=r", 8);
12920 if (likely(!ret))
12921 __put_user_asm(tmp, (u64 __user *)dst,
12922 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12923 return ret;
12924 }
12925 default:
12926 - return copy_user_generic((__force void *)dst,
12927 - (__force void *)src, size);
12928 +
12929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12930 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12931 + src += PAX_USER_SHADOW_BASE;
12932 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12933 + dst += PAX_USER_SHADOW_BASE;
12934 +#endif
12935 +
12936 + return copy_user_generic((__force_kernel void *)dst,
12937 + (__force_kernel const void *)src, size);
12938 }
12939 }
12940
12941 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
12942 __must_check long strnlen_user(const char __user *str, long n);
12943 __must_check long __strnlen_user(const char __user *str, long n);
12944 __must_check long strlen_user(const char __user *str);
12945 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
12946 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12947 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12948 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12949
12950 static __must_check __always_inline int
12951 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12952 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12953 +static __must_check __always_inline int
12954 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12955 {
12956 - return copy_user_generic(dst, (__force const void *)src, size);
12957 + if (size > INT_MAX)
12958 + return size;
12959 +
12960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12961 + if (!__access_ok(VERIFY_READ, src, size))
12962 + return size;
12963 +
12964 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12965 + src += PAX_USER_SHADOW_BASE;
12966 +#endif
12967 +
12968 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12969 }
12970
12971 -static __must_check __always_inline int
12972 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12973 +static __must_check __always_inline unsigned long
12974 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12975 +static __must_check __always_inline unsigned long
12976 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12977 {
12978 - return copy_user_generic((__force void *)dst, src, size);
12979 + if (size > INT_MAX)
12980 + return size;
12981 +
12982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12983 + if (!__access_ok(VERIFY_WRITE, dst, size))
12984 + return size;
12985 +
12986 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12987 + dst += PAX_USER_SHADOW_BASE;
12988 +#endif
12989 +
12990 + return copy_user_generic((__force_kernel void *)dst, src, size);
12991 }
12992
12993 -extern long __copy_user_nocache(void *dst, const void __user *src,
12994 - unsigned size, int zerorest);
12995 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12996 + unsigned long size, int zerorest) __size_overflow(3);
12997
12998 -static inline int
12999 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13000 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13001 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13002 {
13003 might_sleep();
13004 +
13005 + if (size > INT_MAX)
13006 + return size;
13007 +
13008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13009 + if (!__access_ok(VERIFY_READ, src, size))
13010 + return size;
13011 +#endif
13012 +
13013 return __copy_user_nocache(dst, src, size, 1);
13014 }
13015
13016 -static inline int
13017 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13018 - unsigned size)
13019 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13020 + unsigned long size) __size_overflow(3);
13021 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13022 + unsigned long size)
13023 {
13024 + if (size > INT_MAX)
13025 + return size;
13026 +
13027 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13028 + if (!__access_ok(VERIFY_READ, src, size))
13029 + return size;
13030 +#endif
13031 +
13032 return __copy_user_nocache(dst, src, size, 0);
13033 }
13034
13035 -unsigned long
13036 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13037 +extern unsigned long
13038 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13039
13040 #endif /* _ASM_X86_UACCESS_64_H */
13041 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13042 index bb05228..d763d5b 100644
13043 --- a/arch/x86/include/asm/vdso.h
13044 +++ b/arch/x86/include/asm/vdso.h
13045 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13046 #define VDSO32_SYMBOL(base, name) \
13047 ({ \
13048 extern const char VDSO32_##name[]; \
13049 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13050 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13051 })
13052 #endif
13053
13054 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13055 index 517d476..a1cb4d9 100644
13056 --- a/arch/x86/include/asm/x86_init.h
13057 +++ b/arch/x86/include/asm/x86_init.h
13058 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13059 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13060 void (*find_smp_config)(void);
13061 void (*get_smp_config)(unsigned int early);
13062 -};
13063 +} __no_const;
13064
13065 /**
13066 * struct x86_init_resources - platform specific resource related ops
13067 @@ -43,7 +43,7 @@ struct x86_init_resources {
13068 void (*probe_roms)(void);
13069 void (*reserve_resources)(void);
13070 char *(*memory_setup)(void);
13071 -};
13072 +} __no_const;
13073
13074 /**
13075 * struct x86_init_irqs - platform specific interrupt setup
13076 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13077 void (*pre_vector_init)(void);
13078 void (*intr_init)(void);
13079 void (*trap_init)(void);
13080 -};
13081 +} __no_const;
13082
13083 /**
13084 * struct x86_init_oem - oem platform specific customizing functions
13085 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13086 struct x86_init_oem {
13087 void (*arch_setup)(void);
13088 void (*banner)(void);
13089 -};
13090 +} __no_const;
13091
13092 /**
13093 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13094 @@ -77,7 +77,7 @@ struct x86_init_oem {
13095 */
13096 struct x86_init_mapping {
13097 void (*pagetable_reserve)(u64 start, u64 end);
13098 -};
13099 +} __no_const;
13100
13101 /**
13102 * struct x86_init_paging - platform specific paging functions
13103 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13104 struct x86_init_paging {
13105 void (*pagetable_setup_start)(pgd_t *base);
13106 void (*pagetable_setup_done)(pgd_t *base);
13107 -};
13108 +} __no_const;
13109
13110 /**
13111 * struct x86_init_timers - platform specific timer setup
13112 @@ -102,7 +102,7 @@ struct x86_init_timers {
13113 void (*tsc_pre_init)(void);
13114 void (*timer_init)(void);
13115 void (*wallclock_init)(void);
13116 -};
13117 +} __no_const;
13118
13119 /**
13120 * struct x86_init_iommu - platform specific iommu setup
13121 @@ -110,7 +110,7 @@ struct x86_init_timers {
13122 */
13123 struct x86_init_iommu {
13124 int (*iommu_init)(void);
13125 -};
13126 +} __no_const;
13127
13128 /**
13129 * struct x86_init_pci - platform specific pci init functions
13130 @@ -124,7 +124,7 @@ struct x86_init_pci {
13131 int (*init)(void);
13132 void (*init_irq)(void);
13133 void (*fixup_irqs)(void);
13134 -};
13135 +} __no_const;
13136
13137 /**
13138 * struct x86_init_ops - functions for platform specific setup
13139 @@ -140,7 +140,7 @@ struct x86_init_ops {
13140 struct x86_init_timers timers;
13141 struct x86_init_iommu iommu;
13142 struct x86_init_pci pci;
13143 -};
13144 +} __no_const;
13145
13146 /**
13147 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13148 @@ -149,7 +149,7 @@ struct x86_init_ops {
13149 struct x86_cpuinit_ops {
13150 void (*setup_percpu_clockev)(void);
13151 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13152 -};
13153 +} __no_const;
13154
13155 /**
13156 * struct x86_platform_ops - platform specific runtime functions
13157 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13158 void (*nmi_init)(void);
13159 unsigned char (*get_nmi_reason)(void);
13160 int (*i8042_detect)(void);
13161 -};
13162 +} __no_const;
13163
13164 struct pci_dev;
13165
13166 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13167 void (*teardown_msi_irq)(unsigned int irq);
13168 void (*teardown_msi_irqs)(struct pci_dev *dev);
13169 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13170 -};
13171 +} __no_const;
13172
13173 extern struct x86_init_ops x86_init;
13174 extern struct x86_cpuinit_ops x86_cpuinit;
13175 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13176 index c6ce245..ffbdab7 100644
13177 --- a/arch/x86/include/asm/xsave.h
13178 +++ b/arch/x86/include/asm/xsave.h
13179 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13180 {
13181 int err;
13182
13183 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13184 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13185 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13186 +#endif
13187 +
13188 /*
13189 * Clear the xsave header first, so that reserved fields are
13190 * initialized to zero.
13191 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13192 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13193 {
13194 int err;
13195 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13196 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13197 u32 lmask = mask;
13198 u32 hmask = mask >> 32;
13199
13200 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13201 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13202 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13203 +#endif
13204 +
13205 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13206 "2:\n"
13207 ".section .fixup,\"ax\"\n"
13208 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13209 index 6a564ac..9b1340c 100644
13210 --- a/arch/x86/kernel/acpi/realmode/Makefile
13211 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13212 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13213 $(call cc-option, -fno-stack-protector) \
13214 $(call cc-option, -mpreferred-stack-boundary=2)
13215 KBUILD_CFLAGS += $(call cc-option, -m32)
13216 +ifdef CONSTIFY_PLUGIN
13217 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13218 +endif
13219 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13220 GCOV_PROFILE := n
13221
13222 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13223 index b4fd836..4358fe3 100644
13224 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13225 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13226 @@ -108,6 +108,9 @@ wakeup_code:
13227 /* Do any other stuff... */
13228
13229 #ifndef CONFIG_64BIT
13230 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13231 + call verify_cpu
13232 +
13233 /* This could also be done in C code... */
13234 movl pmode_cr3, %eax
13235 movl %eax, %cr3
13236 @@ -131,6 +134,7 @@ wakeup_code:
13237 movl pmode_cr0, %eax
13238 movl %eax, %cr0
13239 jmp pmode_return
13240 +# include "../../verify_cpu.S"
13241 #else
13242 pushw $0
13243 pushw trampoline_segment
13244 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13245 index 103b6ab..2004d0a 100644
13246 --- a/arch/x86/kernel/acpi/sleep.c
13247 +++ b/arch/x86/kernel/acpi/sleep.c
13248 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13249 header->trampoline_segment = trampoline_address() >> 4;
13250 #ifdef CONFIG_SMP
13251 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13252 +
13253 + pax_open_kernel();
13254 early_gdt_descr.address =
13255 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13256 + pax_close_kernel();
13257 +
13258 initial_gs = per_cpu_offset(smp_processor_id());
13259 #endif
13260 initial_code = (unsigned long)wakeup_long64;
13261 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13262 index 13ab720..95d5442 100644
13263 --- a/arch/x86/kernel/acpi/wakeup_32.S
13264 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13265 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13266 # and restore the stack ... but you need gdt for this to work
13267 movl saved_context_esp, %esp
13268
13269 - movl %cs:saved_magic, %eax
13270 - cmpl $0x12345678, %eax
13271 + cmpl $0x12345678, saved_magic
13272 jne bogus_magic
13273
13274 # jump to place where we left off
13275 - movl saved_eip, %eax
13276 - jmp *%eax
13277 + jmp *(saved_eip)
13278
13279 bogus_magic:
13280 jmp bogus_magic
13281 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13282 index 1f84794..e23f862 100644
13283 --- a/arch/x86/kernel/alternative.c
13284 +++ b/arch/x86/kernel/alternative.c
13285 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13286 */
13287 for (a = start; a < end; a++) {
13288 instr = (u8 *)&a->instr_offset + a->instr_offset;
13289 +
13290 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13291 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13292 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13293 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13294 +#endif
13295 +
13296 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13297 BUG_ON(a->replacementlen > a->instrlen);
13298 BUG_ON(a->instrlen > sizeof(insnbuf));
13299 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13300 for (poff = start; poff < end; poff++) {
13301 u8 *ptr = (u8 *)poff + *poff;
13302
13303 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13304 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13305 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13306 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13307 +#endif
13308 +
13309 if (!*poff || ptr < text || ptr >= text_end)
13310 continue;
13311 /* turn DS segment override prefix into lock prefix */
13312 - if (*ptr == 0x3e)
13313 + if (*ktla_ktva(ptr) == 0x3e)
13314 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13315 };
13316 mutex_unlock(&text_mutex);
13317 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13318 for (poff = start; poff < end; poff++) {
13319 u8 *ptr = (u8 *)poff + *poff;
13320
13321 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13322 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13323 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13324 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13325 +#endif
13326 +
13327 if (!*poff || ptr < text || ptr >= text_end)
13328 continue;
13329 /* turn lock prefix into DS segment override prefix */
13330 - if (*ptr == 0xf0)
13331 + if (*ktla_ktva(ptr) == 0xf0)
13332 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13333 };
13334 mutex_unlock(&text_mutex);
13335 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13336
13337 BUG_ON(p->len > MAX_PATCH_LEN);
13338 /* prep the buffer with the original instructions */
13339 - memcpy(insnbuf, p->instr, p->len);
13340 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13341 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13342 (unsigned long)p->instr, p->len);
13343
13344 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13345 if (smp_alt_once)
13346 free_init_pages("SMP alternatives",
13347 (unsigned long)__smp_locks,
13348 - (unsigned long)__smp_locks_end);
13349 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13350
13351 restart_nmi();
13352 }
13353 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13354 * instructions. And on the local CPU you need to be protected again NMI or MCE
13355 * handlers seeing an inconsistent instruction while you patch.
13356 */
13357 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13358 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13359 size_t len)
13360 {
13361 unsigned long flags;
13362 local_irq_save(flags);
13363 - memcpy(addr, opcode, len);
13364 +
13365 + pax_open_kernel();
13366 + memcpy(ktla_ktva(addr), opcode, len);
13367 sync_core();
13368 + pax_close_kernel();
13369 +
13370 local_irq_restore(flags);
13371 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13372 that causes hangs on some VIA CPUs. */
13373 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13374 */
13375 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13376 {
13377 - unsigned long flags;
13378 - char *vaddr;
13379 + unsigned char *vaddr = ktla_ktva(addr);
13380 struct page *pages[2];
13381 - int i;
13382 + size_t i;
13383
13384 if (!core_kernel_text((unsigned long)addr)) {
13385 - pages[0] = vmalloc_to_page(addr);
13386 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13387 + pages[0] = vmalloc_to_page(vaddr);
13388 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13389 } else {
13390 - pages[0] = virt_to_page(addr);
13391 + pages[0] = virt_to_page(vaddr);
13392 WARN_ON(!PageReserved(pages[0]));
13393 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13394 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13395 }
13396 BUG_ON(!pages[0]);
13397 - local_irq_save(flags);
13398 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13399 - if (pages[1])
13400 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13401 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13402 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13403 - clear_fixmap(FIX_TEXT_POKE0);
13404 - if (pages[1])
13405 - clear_fixmap(FIX_TEXT_POKE1);
13406 - local_flush_tlb();
13407 - sync_core();
13408 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13409 - that causes hangs on some VIA CPUs. */
13410 + text_poke_early(addr, opcode, len);
13411 for (i = 0; i < len; i++)
13412 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13413 - local_irq_restore(flags);
13414 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13415 return addr;
13416 }
13417
13418 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13419 index 2eec05b..fef012b 100644
13420 --- a/arch/x86/kernel/apic/apic.c
13421 +++ b/arch/x86/kernel/apic/apic.c
13422 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13423 /*
13424 * Debug level, exported for io_apic.c
13425 */
13426 -unsigned int apic_verbosity;
13427 +int apic_verbosity;
13428
13429 int pic_mode;
13430
13431 @@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13432 apic_write(APIC_ESR, 0);
13433 v1 = apic_read(APIC_ESR);
13434 ack_APIC_irq();
13435 - atomic_inc(&irq_err_count);
13436 + atomic_inc_unchecked(&irq_err_count);
13437
13438 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13439 smp_processor_id(), v0 , v1);
13440 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13441 index fb07275..e06bb59 100644
13442 --- a/arch/x86/kernel/apic/io_apic.c
13443 +++ b/arch/x86/kernel/apic/io_apic.c
13444 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13445 }
13446 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13447
13448 -void lock_vector_lock(void)
13449 +void lock_vector_lock(void) __acquires(vector_lock)
13450 {
13451 /* Used to the online set of cpus does not change
13452 * during assign_irq_vector.
13453 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13454 raw_spin_lock(&vector_lock);
13455 }
13456
13457 -void unlock_vector_lock(void)
13458 +void unlock_vector_lock(void) __releases(vector_lock)
13459 {
13460 raw_spin_unlock(&vector_lock);
13461 }
13462 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13463 ack_APIC_irq();
13464 }
13465
13466 -atomic_t irq_mis_count;
13467 +atomic_unchecked_t irq_mis_count;
13468
13469 static void ack_apic_level(struct irq_data *data)
13470 {
13471 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13472 * at the cpu.
13473 */
13474 if (!(v & (1 << (i & 0x1f)))) {
13475 - atomic_inc(&irq_mis_count);
13476 + atomic_inc_unchecked(&irq_mis_count);
13477
13478 eoi_ioapic_irq(irq, cfg);
13479 }
13480 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13481 index f76623c..aab694f 100644
13482 --- a/arch/x86/kernel/apm_32.c
13483 +++ b/arch/x86/kernel/apm_32.c
13484 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13485 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13486 * even though they are called in protected mode.
13487 */
13488 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13489 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13490 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13491
13492 static const char driver_version[] = "1.16ac"; /* no spaces */
13493 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13494 BUG_ON(cpu != 0);
13495 gdt = get_cpu_gdt_table(cpu);
13496 save_desc_40 = gdt[0x40 / 8];
13497 +
13498 + pax_open_kernel();
13499 gdt[0x40 / 8] = bad_bios_desc;
13500 + pax_close_kernel();
13501
13502 apm_irq_save(flags);
13503 APM_DO_SAVE_SEGS;
13504 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13505 &call->esi);
13506 APM_DO_RESTORE_SEGS;
13507 apm_irq_restore(flags);
13508 +
13509 + pax_open_kernel();
13510 gdt[0x40 / 8] = save_desc_40;
13511 + pax_close_kernel();
13512 +
13513 put_cpu();
13514
13515 return call->eax & 0xff;
13516 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13517 BUG_ON(cpu != 0);
13518 gdt = get_cpu_gdt_table(cpu);
13519 save_desc_40 = gdt[0x40 / 8];
13520 +
13521 + pax_open_kernel();
13522 gdt[0x40 / 8] = bad_bios_desc;
13523 + pax_close_kernel();
13524
13525 apm_irq_save(flags);
13526 APM_DO_SAVE_SEGS;
13527 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13528 &call->eax);
13529 APM_DO_RESTORE_SEGS;
13530 apm_irq_restore(flags);
13531 +
13532 + pax_open_kernel();
13533 gdt[0x40 / 8] = save_desc_40;
13534 + pax_close_kernel();
13535 +
13536 put_cpu();
13537 return error;
13538 }
13539 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13540 * code to that CPU.
13541 */
13542 gdt = get_cpu_gdt_table(0);
13543 +
13544 + pax_open_kernel();
13545 set_desc_base(&gdt[APM_CS >> 3],
13546 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13547 set_desc_base(&gdt[APM_CS_16 >> 3],
13548 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13549 set_desc_base(&gdt[APM_DS >> 3],
13550 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13551 + pax_close_kernel();
13552
13553 proc_create("apm", 0, NULL, &apm_file_ops);
13554
13555 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13556 index 68de2dc..1f3c720 100644
13557 --- a/arch/x86/kernel/asm-offsets.c
13558 +++ b/arch/x86/kernel/asm-offsets.c
13559 @@ -33,6 +33,8 @@ void common(void) {
13560 OFFSET(TI_status, thread_info, status);
13561 OFFSET(TI_addr_limit, thread_info, addr_limit);
13562 OFFSET(TI_preempt_count, thread_info, preempt_count);
13563 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13564 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13565
13566 BLANK();
13567 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13568 @@ -53,8 +55,26 @@ void common(void) {
13569 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13570 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13571 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13572 +
13573 +#ifdef CONFIG_PAX_KERNEXEC
13574 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13575 #endif
13576
13577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13578 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13579 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13580 +#ifdef CONFIG_X86_64
13581 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13582 +#endif
13583 +#endif
13584 +
13585 +#endif
13586 +
13587 + BLANK();
13588 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13589 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13590 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13591 +
13592 #ifdef CONFIG_XEN
13593 BLANK();
13594 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13595 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13596 index 834e897..dacddc8 100644
13597 --- a/arch/x86/kernel/asm-offsets_64.c
13598 +++ b/arch/x86/kernel/asm-offsets_64.c
13599 @@ -70,6 +70,7 @@ int main(void)
13600 BLANK();
13601 #undef ENTRY
13602
13603 + DEFINE(TSS_size, sizeof(struct tss_struct));
13604 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13605 BLANK();
13606
13607 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13608 index 25f24dc..4094a7f 100644
13609 --- a/arch/x86/kernel/cpu/Makefile
13610 +++ b/arch/x86/kernel/cpu/Makefile
13611 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13612 CFLAGS_REMOVE_perf_event.o = -pg
13613 endif
13614
13615 -# Make sure load_percpu_segment has no stackprotector
13616 -nostackp := $(call cc-option, -fno-stack-protector)
13617 -CFLAGS_common.o := $(nostackp)
13618 -
13619 obj-y := intel_cacheinfo.o scattered.o topology.o
13620 obj-y += proc.o capflags.o powerflags.o common.o
13621 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13622 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13623 index f4773f4..b3fb13c 100644
13624 --- a/arch/x86/kernel/cpu/amd.c
13625 +++ b/arch/x86/kernel/cpu/amd.c
13626 @@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13627 unsigned int size)
13628 {
13629 /* AMD errata T13 (order #21922) */
13630 - if ((c->x86 == 6)) {
13631 + if (c->x86 == 6) {
13632 /* Duron Rev A0 */
13633 if (c->x86_model == 3 && c->x86_mask == 0)
13634 size = 64;
13635 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13636 index c0f7d68..aa418f9 100644
13637 --- a/arch/x86/kernel/cpu/common.c
13638 +++ b/arch/x86/kernel/cpu/common.c
13639 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13640
13641 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13642
13643 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13644 -#ifdef CONFIG_X86_64
13645 - /*
13646 - * We need valid kernel segments for data and code in long mode too
13647 - * IRET will check the segment types kkeil 2000/10/28
13648 - * Also sysret mandates a special GDT layout
13649 - *
13650 - * TLS descriptors are currently at a different place compared to i386.
13651 - * Hopefully nobody expects them at a fixed place (Wine?)
13652 - */
13653 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13654 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13655 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13656 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13657 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13658 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13659 -#else
13660 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13661 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13662 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13663 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13664 - /*
13665 - * Segments used for calling PnP BIOS have byte granularity.
13666 - * They code segments and data segments have fixed 64k limits,
13667 - * the transfer segment sizes are set at run time.
13668 - */
13669 - /* 32-bit code */
13670 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13671 - /* 16-bit code */
13672 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13673 - /* 16-bit data */
13674 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13675 - /* 16-bit data */
13676 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13677 - /* 16-bit data */
13678 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13679 - /*
13680 - * The APM segments have byte granularity and their bases
13681 - * are set at run time. All have 64k limits.
13682 - */
13683 - /* 32-bit code */
13684 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13685 - /* 16-bit code */
13686 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13687 - /* data */
13688 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13689 -
13690 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13691 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13692 - GDT_STACK_CANARY_INIT
13693 -#endif
13694 -} };
13695 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13696 -
13697 static int __init x86_xsave_setup(char *s)
13698 {
13699 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13700 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13701 {
13702 struct desc_ptr gdt_descr;
13703
13704 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13705 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13706 gdt_descr.size = GDT_SIZE - 1;
13707 load_gdt(&gdt_descr);
13708 /* Reload the per-cpu base */
13709 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13710 /* Filter out anything that depends on CPUID levels we don't have */
13711 filter_cpuid_features(c, true);
13712
13713 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13714 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13715 +#endif
13716 +
13717 /* If the model name is still unset, do table lookup. */
13718 if (!c->x86_model_id[0]) {
13719 const char *p;
13720 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13721 }
13722 __setup("clearcpuid=", setup_disablecpuid);
13723
13724 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13725 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13726 +
13727 #ifdef CONFIG_X86_64
13728 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13729 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13730 - (unsigned long) nmi_idt_table };
13731 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13732
13733 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13734 irq_stack_union) __aligned(PAGE_SIZE);
13735 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13736 EXPORT_PER_CPU_SYMBOL(current_task);
13737
13738 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13739 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13740 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13741 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13742
13743 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13744 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13745 {
13746 memset(regs, 0, sizeof(struct pt_regs));
13747 regs->fs = __KERNEL_PERCPU;
13748 - regs->gs = __KERNEL_STACK_CANARY;
13749 + savesegment(gs, regs->gs);
13750
13751 return regs;
13752 }
13753 @@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13754 int i;
13755
13756 cpu = stack_smp_processor_id();
13757 - t = &per_cpu(init_tss, cpu);
13758 + t = init_tss + cpu;
13759 oist = &per_cpu(orig_ist, cpu);
13760
13761 #ifdef CONFIG_NUMA
13762 @@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13763 switch_to_new_gdt(cpu);
13764 loadsegment(fs, 0);
13765
13766 - load_idt((const struct desc_ptr *)&idt_descr);
13767 + load_idt(&idt_descr);
13768
13769 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13770 syscall_init();
13771 @@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13772 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13773 barrier();
13774
13775 - x86_configure_nx();
13776 if (cpu != 0)
13777 enable_x2apic();
13778
13779 @@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13780 {
13781 int cpu = smp_processor_id();
13782 struct task_struct *curr = current;
13783 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13784 + struct tss_struct *t = init_tss + cpu;
13785 struct thread_struct *thread = &curr->thread;
13786
13787 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13788 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13789 index 3e6ff6c..54b4992 100644
13790 --- a/arch/x86/kernel/cpu/intel.c
13791 +++ b/arch/x86/kernel/cpu/intel.c
13792 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13793 * Update the IDT descriptor and reload the IDT so that
13794 * it uses the read-only mapped virtual address.
13795 */
13796 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13797 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13798 load_idt(&idt_descr);
13799 }
13800 #endif
13801 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13802 index fc4beb3..f20a5a7 100644
13803 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13804 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13805 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
13806
13807 /* Error injection interface */
13808 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13809 + size_t usize, loff_t *off) __size_overflow(3);
13810 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13811 size_t usize, loff_t *off)
13812 {
13813 struct mce m;
13814 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13815 index 5a11ae2..a1a1c8a 100644
13816 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13817 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13818 @@ -42,6 +42,7 @@
13819 #include <asm/processor.h>
13820 #include <asm/mce.h>
13821 #include <asm/msr.h>
13822 +#include <asm/local.h>
13823
13824 #include "mce-internal.h"
13825
13826 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13827 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13828 m->cs, m->ip);
13829
13830 - if (m->cs == __KERNEL_CS)
13831 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13832 print_symbol("{%s}", m->ip);
13833 pr_cont("\n");
13834 }
13835 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13836
13837 #define PANIC_TIMEOUT 5 /* 5 seconds */
13838
13839 -static atomic_t mce_paniced;
13840 +static atomic_unchecked_t mce_paniced;
13841
13842 static int fake_panic;
13843 -static atomic_t mce_fake_paniced;
13844 +static atomic_unchecked_t mce_fake_paniced;
13845
13846 /* Panic in progress. Enable interrupts and wait for final IPI */
13847 static void wait_for_panic(void)
13848 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13849 /*
13850 * Make sure only one CPU runs in machine check panic
13851 */
13852 - if (atomic_inc_return(&mce_paniced) > 1)
13853 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13854 wait_for_panic();
13855 barrier();
13856
13857 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13858 console_verbose();
13859 } else {
13860 /* Don't log too much for fake panic */
13861 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13862 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13863 return;
13864 }
13865 /* First print corrected ones that are still unlogged */
13866 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13867 * might have been modified by someone else.
13868 */
13869 rmb();
13870 - if (atomic_read(&mce_paniced))
13871 + if (atomic_read_unchecked(&mce_paniced))
13872 wait_for_panic();
13873 if (!monarch_timeout)
13874 goto out;
13875 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13876 }
13877
13878 /* Call the installed machine check handler for this CPU setup. */
13879 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13880 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13881 unexpected_machine_check;
13882
13883 /*
13884 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13885 return;
13886 }
13887
13888 + pax_open_kernel();
13889 machine_check_vector = do_machine_check;
13890 + pax_close_kernel();
13891
13892 __mcheck_cpu_init_generic();
13893 __mcheck_cpu_init_vendor(c);
13894 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13895 */
13896
13897 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13898 -static int mce_chrdev_open_count; /* #times opened */
13899 +static local_t mce_chrdev_open_count; /* #times opened */
13900 static int mce_chrdev_open_exclu; /* already open exclusive? */
13901
13902 static int mce_chrdev_open(struct inode *inode, struct file *file)
13903 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13904 spin_lock(&mce_chrdev_state_lock);
13905
13906 if (mce_chrdev_open_exclu ||
13907 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13908 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13909 spin_unlock(&mce_chrdev_state_lock);
13910
13911 return -EBUSY;
13912 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13913
13914 if (file->f_flags & O_EXCL)
13915 mce_chrdev_open_exclu = 1;
13916 - mce_chrdev_open_count++;
13917 + local_inc(&mce_chrdev_open_count);
13918
13919 spin_unlock(&mce_chrdev_state_lock);
13920
13921 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13922 {
13923 spin_lock(&mce_chrdev_state_lock);
13924
13925 - mce_chrdev_open_count--;
13926 + local_dec(&mce_chrdev_open_count);
13927 mce_chrdev_open_exclu = 0;
13928
13929 spin_unlock(&mce_chrdev_state_lock);
13930 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13931 static void mce_reset(void)
13932 {
13933 cpu_missing = 0;
13934 - atomic_set(&mce_fake_paniced, 0);
13935 + atomic_set_unchecked(&mce_fake_paniced, 0);
13936 atomic_set(&mce_executing, 0);
13937 atomic_set(&mce_callin, 0);
13938 atomic_set(&global_nwo, 0);
13939 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13940 index 5c0e653..0882b0a 100644
13941 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13942 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13943 @@ -12,6 +12,7 @@
13944 #include <asm/system.h>
13945 #include <asm/mce.h>
13946 #include <asm/msr.h>
13947 +#include <asm/pgtable.h>
13948
13949 /* By default disabled */
13950 int mce_p5_enabled __read_mostly;
13951 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13952 if (!cpu_has(c, X86_FEATURE_MCE))
13953 return;
13954
13955 + pax_open_kernel();
13956 machine_check_vector = pentium_machine_check;
13957 + pax_close_kernel();
13958 /* Make sure the vector pointer is visible before we enable MCEs: */
13959 wmb();
13960
13961 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13962 index 54060f5..c1a7577 100644
13963 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13964 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13965 @@ -11,6 +11,7 @@
13966 #include <asm/system.h>
13967 #include <asm/mce.h>
13968 #include <asm/msr.h>
13969 +#include <asm/pgtable.h>
13970
13971 /* Machine check handler for WinChip C6: */
13972 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13973 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13974 {
13975 u32 lo, hi;
13976
13977 + pax_open_kernel();
13978 machine_check_vector = winchip_machine_check;
13979 + pax_close_kernel();
13980 /* Make sure the vector pointer is visible before we enable MCEs: */
13981 wmb();
13982
13983 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
13984 index 7928963..1b16001 100644
13985 --- a/arch/x86/kernel/cpu/mtrr/if.c
13986 +++ b/arch/x86/kernel/cpu/mtrr/if.c
13987 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
13988 * "base=%Lx size=%Lx type=%s" or "disable=%d"
13989 */
13990 static ssize_t
13991 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
13992 +static ssize_t
13993 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
13994 {
13995 int i, err;
13996 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13997 index 6b96110..0da73eb 100644
13998 --- a/arch/x86/kernel/cpu/mtrr/main.c
13999 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14000 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14001 u64 size_or_mask, size_and_mask;
14002 static bool mtrr_aps_delayed_init;
14003
14004 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14005 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14006
14007 const struct mtrr_ops *mtrr_if;
14008
14009 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14010 index df5e41f..816c719 100644
14011 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14012 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14013 @@ -25,7 +25,7 @@ struct mtrr_ops {
14014 int (*validate_add_page)(unsigned long base, unsigned long size,
14015 unsigned int type);
14016 int (*have_wrcomb)(void);
14017 -};
14018 +} __do_const;
14019
14020 extern int generic_get_free_region(unsigned long base, unsigned long size,
14021 int replace_reg);
14022 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14023 index 5adce10..99284ec 100644
14024 --- a/arch/x86/kernel/cpu/perf_event.c
14025 +++ b/arch/x86/kernel/cpu/perf_event.c
14026 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14027 break;
14028
14029 perf_callchain_store(entry, frame.return_address);
14030 - fp = frame.next_frame;
14031 + fp = (const void __force_user *)frame.next_frame;
14032 }
14033 }
14034
14035 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14036 index 13ad899..f642b9a 100644
14037 --- a/arch/x86/kernel/crash.c
14038 +++ b/arch/x86/kernel/crash.c
14039 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14040 {
14041 #ifdef CONFIG_X86_32
14042 struct pt_regs fixed_regs;
14043 -#endif
14044
14045 -#ifdef CONFIG_X86_32
14046 - if (!user_mode_vm(regs)) {
14047 + if (!user_mode(regs)) {
14048 crash_fixup_ss_esp(&fixed_regs, regs);
14049 regs = &fixed_regs;
14050 }
14051 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14052 index 37250fe..bf2ec74 100644
14053 --- a/arch/x86/kernel/doublefault_32.c
14054 +++ b/arch/x86/kernel/doublefault_32.c
14055 @@ -11,7 +11,7 @@
14056
14057 #define DOUBLEFAULT_STACKSIZE (1024)
14058 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14059 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14060 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14061
14062 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14063
14064 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14065 unsigned long gdt, tss;
14066
14067 store_gdt(&gdt_desc);
14068 - gdt = gdt_desc.address;
14069 + gdt = (unsigned long)gdt_desc.address;
14070
14071 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14072
14073 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14074 /* 0x2 bit is always set */
14075 .flags = X86_EFLAGS_SF | 0x2,
14076 .sp = STACK_START,
14077 - .es = __USER_DS,
14078 + .es = __KERNEL_DS,
14079 .cs = __KERNEL_CS,
14080 .ss = __KERNEL_DS,
14081 - .ds = __USER_DS,
14082 + .ds = __KERNEL_DS,
14083 .fs = __KERNEL_PERCPU,
14084
14085 .__cr3 = __pa_nodebug(swapper_pg_dir),
14086 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14087 index 4025fe4..d8451c6 100644
14088 --- a/arch/x86/kernel/dumpstack.c
14089 +++ b/arch/x86/kernel/dumpstack.c
14090 @@ -2,6 +2,9 @@
14091 * Copyright (C) 1991, 1992 Linus Torvalds
14092 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14093 */
14094 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14095 +#define __INCLUDED_BY_HIDESYM 1
14096 +#endif
14097 #include <linux/kallsyms.h>
14098 #include <linux/kprobes.h>
14099 #include <linux/uaccess.h>
14100 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14101 static void
14102 print_ftrace_graph_addr(unsigned long addr, void *data,
14103 const struct stacktrace_ops *ops,
14104 - struct thread_info *tinfo, int *graph)
14105 + struct task_struct *task, int *graph)
14106 {
14107 - struct task_struct *task = tinfo->task;
14108 unsigned long ret_addr;
14109 int index = task->curr_ret_stack;
14110
14111 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14112 static inline void
14113 print_ftrace_graph_addr(unsigned long addr, void *data,
14114 const struct stacktrace_ops *ops,
14115 - struct thread_info *tinfo, int *graph)
14116 + struct task_struct *task, int *graph)
14117 { }
14118 #endif
14119
14120 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14121 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14122 */
14123
14124 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14125 - void *p, unsigned int size, void *end)
14126 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14127 {
14128 - void *t = tinfo;
14129 if (end) {
14130 if (p < end && p >= (end-THREAD_SIZE))
14131 return 1;
14132 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14133 }
14134
14135 unsigned long
14136 -print_context_stack(struct thread_info *tinfo,
14137 +print_context_stack(struct task_struct *task, void *stack_start,
14138 unsigned long *stack, unsigned long bp,
14139 const struct stacktrace_ops *ops, void *data,
14140 unsigned long *end, int *graph)
14141 {
14142 struct stack_frame *frame = (struct stack_frame *)bp;
14143
14144 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14145 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14146 unsigned long addr;
14147
14148 addr = *stack;
14149 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14150 } else {
14151 ops->address(data, addr, 0);
14152 }
14153 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14154 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14155 }
14156 stack++;
14157 }
14158 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14159 EXPORT_SYMBOL_GPL(print_context_stack);
14160
14161 unsigned long
14162 -print_context_stack_bp(struct thread_info *tinfo,
14163 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14164 unsigned long *stack, unsigned long bp,
14165 const struct stacktrace_ops *ops, void *data,
14166 unsigned long *end, int *graph)
14167 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14168 struct stack_frame *frame = (struct stack_frame *)bp;
14169 unsigned long *ret_addr = &frame->return_address;
14170
14171 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14172 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14173 unsigned long addr = *ret_addr;
14174
14175 if (!__kernel_text_address(addr))
14176 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14177 ops->address(data, addr, 1);
14178 frame = frame->next_frame;
14179 ret_addr = &frame->return_address;
14180 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14181 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14182 }
14183
14184 return (unsigned long)frame;
14185 @@ -186,7 +186,7 @@ void dump_stack(void)
14186
14187 bp = stack_frame(current, NULL);
14188 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14189 - current->pid, current->comm, print_tainted(),
14190 + task_pid_nr(current), current->comm, print_tainted(),
14191 init_utsname()->release,
14192 (int)strcspn(init_utsname()->version, " "),
14193 init_utsname()->version);
14194 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14195 }
14196 EXPORT_SYMBOL_GPL(oops_begin);
14197
14198 +extern void gr_handle_kernel_exploit(void);
14199 +
14200 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14201 {
14202 if (regs && kexec_should_crash(current))
14203 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14204 panic("Fatal exception in interrupt");
14205 if (panic_on_oops)
14206 panic("Fatal exception");
14207 - do_exit(signr);
14208 +
14209 + gr_handle_kernel_exploit();
14210 +
14211 + do_group_exit(signr);
14212 }
14213
14214 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14215 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14216
14217 show_registers(regs);
14218 #ifdef CONFIG_X86_32
14219 - if (user_mode_vm(regs)) {
14220 + if (user_mode(regs)) {
14221 sp = regs->sp;
14222 ss = regs->ss & 0xffff;
14223 } else {
14224 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14225 unsigned long flags = oops_begin();
14226 int sig = SIGSEGV;
14227
14228 - if (!user_mode_vm(regs))
14229 + if (!user_mode(regs))
14230 report_bug(regs->ip, regs);
14231
14232 if (__die(str, regs, err))
14233 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14234 index c99f9ed..2a15d80 100644
14235 --- a/arch/x86/kernel/dumpstack_32.c
14236 +++ b/arch/x86/kernel/dumpstack_32.c
14237 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14238 bp = stack_frame(task, regs);
14239
14240 for (;;) {
14241 - struct thread_info *context;
14242 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14243
14244 - context = (struct thread_info *)
14245 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14246 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14247 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14248
14249 - stack = (unsigned long *)context->previous_esp;
14250 - if (!stack)
14251 + if (stack_start == task_stack_page(task))
14252 break;
14253 + stack = *(unsigned long **)stack_start;
14254 if (ops->stack(data, "IRQ") < 0)
14255 break;
14256 touch_nmi_watchdog();
14257 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14258 * When in-kernel, we also print out the stack and code at the
14259 * time of the fault..
14260 */
14261 - if (!user_mode_vm(regs)) {
14262 + if (!user_mode(regs)) {
14263 unsigned int code_prologue = code_bytes * 43 / 64;
14264 unsigned int code_len = code_bytes;
14265 unsigned char c;
14266 u8 *ip;
14267 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14268
14269 printk(KERN_EMERG "Stack:\n");
14270 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14271
14272 printk(KERN_EMERG "Code: ");
14273
14274 - ip = (u8 *)regs->ip - code_prologue;
14275 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14276 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14277 /* try starting at IP */
14278 - ip = (u8 *)regs->ip;
14279 + ip = (u8 *)regs->ip + cs_base;
14280 code_len = code_len - code_prologue + 1;
14281 }
14282 for (i = 0; i < code_len; i++, ip++) {
14283 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14284 printk(KERN_CONT " Bad EIP value.");
14285 break;
14286 }
14287 - if (ip == (u8 *)regs->ip)
14288 + if (ip == (u8 *)regs->ip + cs_base)
14289 printk(KERN_CONT "<%02x> ", c);
14290 else
14291 printk(KERN_CONT "%02x ", c);
14292 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14293 {
14294 unsigned short ud2;
14295
14296 + ip = ktla_ktva(ip);
14297 if (ip < PAGE_OFFSET)
14298 return 0;
14299 if (probe_kernel_address((unsigned short *)ip, ud2))
14300 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14301
14302 return ud2 == 0x0b0f;
14303 }
14304 +
14305 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14306 +void pax_check_alloca(unsigned long size)
14307 +{
14308 + unsigned long sp = (unsigned long)&sp, stack_left;
14309 +
14310 + /* all kernel stacks are of the same size */
14311 + stack_left = sp & (THREAD_SIZE - 1);
14312 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14313 +}
14314 +EXPORT_SYMBOL(pax_check_alloca);
14315 +#endif
14316 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14317 index 17107bd..b2deecf 100644
14318 --- a/arch/x86/kernel/dumpstack_64.c
14319 +++ b/arch/x86/kernel/dumpstack_64.c
14320 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14321 unsigned long *irq_stack_end =
14322 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14323 unsigned used = 0;
14324 - struct thread_info *tinfo;
14325 int graph = 0;
14326 unsigned long dummy;
14327 + void *stack_start;
14328
14329 if (!task)
14330 task = current;
14331 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14332 * current stack address. If the stacks consist of nested
14333 * exceptions
14334 */
14335 - tinfo = task_thread_info(task);
14336 for (;;) {
14337 char *id;
14338 unsigned long *estack_end;
14339 +
14340 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14341 &used, &id);
14342
14343 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14344 if (ops->stack(data, id) < 0)
14345 break;
14346
14347 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14348 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14349 data, estack_end, &graph);
14350 ops->stack(data, "<EOE>");
14351 /*
14352 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14353 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14354 if (ops->stack(data, "IRQ") < 0)
14355 break;
14356 - bp = ops->walk_stack(tinfo, stack, bp,
14357 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14358 ops, data, irq_stack_end, &graph);
14359 /*
14360 * We link to the next stack (which would be
14361 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14362 /*
14363 * This handles the process stack:
14364 */
14365 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14366 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14367 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14368 put_cpu();
14369 }
14370 EXPORT_SYMBOL(dump_trace);
14371 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14372
14373 return ud2 == 0x0b0f;
14374 }
14375 +
14376 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14377 +void pax_check_alloca(unsigned long size)
14378 +{
14379 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14380 + unsigned cpu, used;
14381 + char *id;
14382 +
14383 + /* check the process stack first */
14384 + stack_start = (unsigned long)task_stack_page(current);
14385 + stack_end = stack_start + THREAD_SIZE;
14386 + if (likely(stack_start <= sp && sp < stack_end)) {
14387 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14388 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14389 + return;
14390 + }
14391 +
14392 + cpu = get_cpu();
14393 +
14394 + /* check the irq stacks */
14395 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14396 + stack_start = stack_end - IRQ_STACK_SIZE;
14397 + if (stack_start <= sp && sp < stack_end) {
14398 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14399 + put_cpu();
14400 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14401 + return;
14402 + }
14403 +
14404 + /* check the exception stacks */
14405 + used = 0;
14406 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14407 + stack_start = stack_end - EXCEPTION_STKSZ;
14408 + if (stack_end && stack_start <= sp && sp < stack_end) {
14409 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14410 + put_cpu();
14411 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14412 + return;
14413 + }
14414 +
14415 + put_cpu();
14416 +
14417 + /* unknown stack */
14418 + BUG();
14419 +}
14420 +EXPORT_SYMBOL(pax_check_alloca);
14421 +#endif
14422 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14423 index 9b9f18b..9fcaa04 100644
14424 --- a/arch/x86/kernel/early_printk.c
14425 +++ b/arch/x86/kernel/early_printk.c
14426 @@ -7,6 +7,7 @@
14427 #include <linux/pci_regs.h>
14428 #include <linux/pci_ids.h>
14429 #include <linux/errno.h>
14430 +#include <linux/sched.h>
14431 #include <asm/io.h>
14432 #include <asm/processor.h>
14433 #include <asm/fcntl.h>
14434 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14435 index 7b784f4..76aaad7 100644
14436 --- a/arch/x86/kernel/entry_32.S
14437 +++ b/arch/x86/kernel/entry_32.S
14438 @@ -179,13 +179,146 @@
14439 /*CFI_REL_OFFSET gs, PT_GS*/
14440 .endm
14441 .macro SET_KERNEL_GS reg
14442 +
14443 +#ifdef CONFIG_CC_STACKPROTECTOR
14444 movl $(__KERNEL_STACK_CANARY), \reg
14445 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14446 + movl $(__USER_DS), \reg
14447 +#else
14448 + xorl \reg, \reg
14449 +#endif
14450 +
14451 movl \reg, %gs
14452 .endm
14453
14454 #endif /* CONFIG_X86_32_LAZY_GS */
14455
14456 -.macro SAVE_ALL
14457 +.macro pax_enter_kernel
14458 +#ifdef CONFIG_PAX_KERNEXEC
14459 + call pax_enter_kernel
14460 +#endif
14461 +.endm
14462 +
14463 +.macro pax_exit_kernel
14464 +#ifdef CONFIG_PAX_KERNEXEC
14465 + call pax_exit_kernel
14466 +#endif
14467 +.endm
14468 +
14469 +#ifdef CONFIG_PAX_KERNEXEC
14470 +ENTRY(pax_enter_kernel)
14471 +#ifdef CONFIG_PARAVIRT
14472 + pushl %eax
14473 + pushl %ecx
14474 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14475 + mov %eax, %esi
14476 +#else
14477 + mov %cr0, %esi
14478 +#endif
14479 + bts $16, %esi
14480 + jnc 1f
14481 + mov %cs, %esi
14482 + cmp $__KERNEL_CS, %esi
14483 + jz 3f
14484 + ljmp $__KERNEL_CS, $3f
14485 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14486 +2:
14487 +#ifdef CONFIG_PARAVIRT
14488 + mov %esi, %eax
14489 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14490 +#else
14491 + mov %esi, %cr0
14492 +#endif
14493 +3:
14494 +#ifdef CONFIG_PARAVIRT
14495 + popl %ecx
14496 + popl %eax
14497 +#endif
14498 + ret
14499 +ENDPROC(pax_enter_kernel)
14500 +
14501 +ENTRY(pax_exit_kernel)
14502 +#ifdef CONFIG_PARAVIRT
14503 + pushl %eax
14504 + pushl %ecx
14505 +#endif
14506 + mov %cs, %esi
14507 + cmp $__KERNEXEC_KERNEL_CS, %esi
14508 + jnz 2f
14509 +#ifdef CONFIG_PARAVIRT
14510 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14511 + mov %eax, %esi
14512 +#else
14513 + mov %cr0, %esi
14514 +#endif
14515 + btr $16, %esi
14516 + ljmp $__KERNEL_CS, $1f
14517 +1:
14518 +#ifdef CONFIG_PARAVIRT
14519 + mov %esi, %eax
14520 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14521 +#else
14522 + mov %esi, %cr0
14523 +#endif
14524 +2:
14525 +#ifdef CONFIG_PARAVIRT
14526 + popl %ecx
14527 + popl %eax
14528 +#endif
14529 + ret
14530 +ENDPROC(pax_exit_kernel)
14531 +#endif
14532 +
14533 +.macro pax_erase_kstack
14534 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14535 + call pax_erase_kstack
14536 +#endif
14537 +.endm
14538 +
14539 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14540 +/*
14541 + * ebp: thread_info
14542 + * ecx, edx: can be clobbered
14543 + */
14544 +ENTRY(pax_erase_kstack)
14545 + pushl %edi
14546 + pushl %eax
14547 +
14548 + mov TI_lowest_stack(%ebp), %edi
14549 + mov $-0xBEEF, %eax
14550 + std
14551 +
14552 +1: mov %edi, %ecx
14553 + and $THREAD_SIZE_asm - 1, %ecx
14554 + shr $2, %ecx
14555 + repne scasl
14556 + jecxz 2f
14557 +
14558 + cmp $2*16, %ecx
14559 + jc 2f
14560 +
14561 + mov $2*16, %ecx
14562 + repe scasl
14563 + jecxz 2f
14564 + jne 1b
14565 +
14566 +2: cld
14567 + mov %esp, %ecx
14568 + sub %edi, %ecx
14569 + shr $2, %ecx
14570 + rep stosl
14571 +
14572 + mov TI_task_thread_sp0(%ebp), %edi
14573 + sub $128, %edi
14574 + mov %edi, TI_lowest_stack(%ebp)
14575 +
14576 + popl %eax
14577 + popl %edi
14578 + ret
14579 +ENDPROC(pax_erase_kstack)
14580 +#endif
14581 +
14582 +.macro __SAVE_ALL _DS
14583 cld
14584 PUSH_GS
14585 pushl_cfi %fs
14586 @@ -208,7 +341,7 @@
14587 CFI_REL_OFFSET ecx, 0
14588 pushl_cfi %ebx
14589 CFI_REL_OFFSET ebx, 0
14590 - movl $(__USER_DS), %edx
14591 + movl $\_DS, %edx
14592 movl %edx, %ds
14593 movl %edx, %es
14594 movl $(__KERNEL_PERCPU), %edx
14595 @@ -216,6 +349,15 @@
14596 SET_KERNEL_GS %edx
14597 .endm
14598
14599 +.macro SAVE_ALL
14600 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14601 + __SAVE_ALL __KERNEL_DS
14602 + pax_enter_kernel
14603 +#else
14604 + __SAVE_ALL __USER_DS
14605 +#endif
14606 +.endm
14607 +
14608 .macro RESTORE_INT_REGS
14609 popl_cfi %ebx
14610 CFI_RESTORE ebx
14611 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14612 popfl_cfi
14613 jmp syscall_exit
14614 CFI_ENDPROC
14615 -END(ret_from_fork)
14616 +ENDPROC(ret_from_fork)
14617
14618 /*
14619 * Interrupt exit functions should be protected against kprobes
14620 @@ -335,7 +477,15 @@ resume_userspace_sig:
14621 andl $SEGMENT_RPL_MASK, %eax
14622 #endif
14623 cmpl $USER_RPL, %eax
14624 +
14625 +#ifdef CONFIG_PAX_KERNEXEC
14626 + jae resume_userspace
14627 +
14628 + PAX_EXIT_KERNEL
14629 + jmp resume_kernel
14630 +#else
14631 jb resume_kernel # not returning to v8086 or userspace
14632 +#endif
14633
14634 ENTRY(resume_userspace)
14635 LOCKDEP_SYS_EXIT
14636 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14637 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14638 # int/exception return?
14639 jne work_pending
14640 - jmp restore_all
14641 -END(ret_from_exception)
14642 + jmp restore_all_pax
14643 +ENDPROC(ret_from_exception)
14644
14645 #ifdef CONFIG_PREEMPT
14646 ENTRY(resume_kernel)
14647 @@ -363,7 +513,7 @@ need_resched:
14648 jz restore_all
14649 call preempt_schedule_irq
14650 jmp need_resched
14651 -END(resume_kernel)
14652 +ENDPROC(resume_kernel)
14653 #endif
14654 CFI_ENDPROC
14655 /*
14656 @@ -397,23 +547,34 @@ sysenter_past_esp:
14657 /*CFI_REL_OFFSET cs, 0*/
14658 /*
14659 * Push current_thread_info()->sysenter_return to the stack.
14660 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14661 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14662 */
14663 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14664 + pushl_cfi $0
14665 CFI_REL_OFFSET eip, 0
14666
14667 pushl_cfi %eax
14668 SAVE_ALL
14669 + GET_THREAD_INFO(%ebp)
14670 + movl TI_sysenter_return(%ebp),%ebp
14671 + movl %ebp,PT_EIP(%esp)
14672 ENABLE_INTERRUPTS(CLBR_NONE)
14673
14674 /*
14675 * Load the potential sixth argument from user stack.
14676 * Careful about security.
14677 */
14678 + movl PT_OLDESP(%esp),%ebp
14679 +
14680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14681 + mov PT_OLDSS(%esp),%ds
14682 +1: movl %ds:(%ebp),%ebp
14683 + push %ss
14684 + pop %ds
14685 +#else
14686 cmpl $__PAGE_OFFSET-3,%ebp
14687 jae syscall_fault
14688 1: movl (%ebp),%ebp
14689 +#endif
14690 +
14691 movl %ebp,PT_EBP(%esp)
14692 .section __ex_table,"a"
14693 .align 4
14694 @@ -436,12 +597,24 @@ sysenter_do_call:
14695 testl $_TIF_ALLWORK_MASK, %ecx
14696 jne sysexit_audit
14697 sysenter_exit:
14698 +
14699 +#ifdef CONFIG_PAX_RANDKSTACK
14700 + pushl_cfi %eax
14701 + movl %esp, %eax
14702 + call pax_randomize_kstack
14703 + popl_cfi %eax
14704 +#endif
14705 +
14706 + pax_erase_kstack
14707 +
14708 /* if something modifies registers it must also disable sysexit */
14709 movl PT_EIP(%esp), %edx
14710 movl PT_OLDESP(%esp), %ecx
14711 xorl %ebp,%ebp
14712 TRACE_IRQS_ON
14713 1: mov PT_FS(%esp), %fs
14714 +2: mov PT_DS(%esp), %ds
14715 +3: mov PT_ES(%esp), %es
14716 PTGS_TO_GS
14717 ENABLE_INTERRUPTS_SYSEXIT
14718
14719 @@ -458,6 +631,9 @@ sysenter_audit:
14720 movl %eax,%edx /* 2nd arg: syscall number */
14721 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14722 call __audit_syscall_entry
14723 +
14724 + pax_erase_kstack
14725 +
14726 pushl_cfi %ebx
14727 movl PT_EAX(%esp),%eax /* reload syscall number */
14728 jmp sysenter_do_call
14729 @@ -483,11 +659,17 @@ sysexit_audit:
14730
14731 CFI_ENDPROC
14732 .pushsection .fixup,"ax"
14733 -2: movl $0,PT_FS(%esp)
14734 +4: movl $0,PT_FS(%esp)
14735 + jmp 1b
14736 +5: movl $0,PT_DS(%esp)
14737 + jmp 1b
14738 +6: movl $0,PT_ES(%esp)
14739 jmp 1b
14740 .section __ex_table,"a"
14741 .align 4
14742 - .long 1b,2b
14743 + .long 1b,4b
14744 + .long 2b,5b
14745 + .long 3b,6b
14746 .popsection
14747 PTGS_TO_GS_EX
14748 ENDPROC(ia32_sysenter_target)
14749 @@ -520,6 +702,15 @@ syscall_exit:
14750 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14751 jne syscall_exit_work
14752
14753 +restore_all_pax:
14754 +
14755 +#ifdef CONFIG_PAX_RANDKSTACK
14756 + movl %esp, %eax
14757 + call pax_randomize_kstack
14758 +#endif
14759 +
14760 + pax_erase_kstack
14761 +
14762 restore_all:
14763 TRACE_IRQS_IRET
14764 restore_all_notrace:
14765 @@ -579,14 +770,34 @@ ldt_ss:
14766 * compensating for the offset by changing to the ESPFIX segment with
14767 * a base address that matches for the difference.
14768 */
14769 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14770 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14771 mov %esp, %edx /* load kernel esp */
14772 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14773 mov %dx, %ax /* eax: new kernel esp */
14774 sub %eax, %edx /* offset (low word is 0) */
14775 +#ifdef CONFIG_SMP
14776 + movl PER_CPU_VAR(cpu_number), %ebx
14777 + shll $PAGE_SHIFT_asm, %ebx
14778 + addl $cpu_gdt_table, %ebx
14779 +#else
14780 + movl $cpu_gdt_table, %ebx
14781 +#endif
14782 shr $16, %edx
14783 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14784 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14785 +
14786 +#ifdef CONFIG_PAX_KERNEXEC
14787 + mov %cr0, %esi
14788 + btr $16, %esi
14789 + mov %esi, %cr0
14790 +#endif
14791 +
14792 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14793 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14794 +
14795 +#ifdef CONFIG_PAX_KERNEXEC
14796 + bts $16, %esi
14797 + mov %esi, %cr0
14798 +#endif
14799 +
14800 pushl_cfi $__ESPFIX_SS
14801 pushl_cfi %eax /* new kernel esp */
14802 /* Disable interrupts, but do not irqtrace this section: we
14803 @@ -615,38 +826,30 @@ work_resched:
14804 movl TI_flags(%ebp), %ecx
14805 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14806 # than syscall tracing?
14807 - jz restore_all
14808 + jz restore_all_pax
14809 testb $_TIF_NEED_RESCHED, %cl
14810 jnz work_resched
14811
14812 work_notifysig: # deal with pending signals and
14813 # notify-resume requests
14814 + movl %esp, %eax
14815 #ifdef CONFIG_VM86
14816 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14817 - movl %esp, %eax
14818 - jne work_notifysig_v86 # returning to kernel-space or
14819 + jz 1f # returning to kernel-space or
14820 # vm86-space
14821 - TRACE_IRQS_ON
14822 - ENABLE_INTERRUPTS(CLBR_NONE)
14823 - xorl %edx, %edx
14824 - call do_notify_resume
14825 - jmp resume_userspace_sig
14826
14827 - ALIGN
14828 -work_notifysig_v86:
14829 pushl_cfi %ecx # save ti_flags for do_notify_resume
14830 call save_v86_state # %eax contains pt_regs pointer
14831 popl_cfi %ecx
14832 movl %eax, %esp
14833 -#else
14834 - movl %esp, %eax
14835 +1:
14836 #endif
14837 TRACE_IRQS_ON
14838 ENABLE_INTERRUPTS(CLBR_NONE)
14839 xorl %edx, %edx
14840 call do_notify_resume
14841 jmp resume_userspace_sig
14842 -END(work_pending)
14843 +ENDPROC(work_pending)
14844
14845 # perform syscall exit tracing
14846 ALIGN
14847 @@ -654,11 +857,14 @@ syscall_trace_entry:
14848 movl $-ENOSYS,PT_EAX(%esp)
14849 movl %esp, %eax
14850 call syscall_trace_enter
14851 +
14852 + pax_erase_kstack
14853 +
14854 /* What it returned is what we'll actually use. */
14855 cmpl $(NR_syscalls), %eax
14856 jnae syscall_call
14857 jmp syscall_exit
14858 -END(syscall_trace_entry)
14859 +ENDPROC(syscall_trace_entry)
14860
14861 # perform syscall exit tracing
14862 ALIGN
14863 @@ -671,20 +877,24 @@ syscall_exit_work:
14864 movl %esp, %eax
14865 call syscall_trace_leave
14866 jmp resume_userspace
14867 -END(syscall_exit_work)
14868 +ENDPROC(syscall_exit_work)
14869 CFI_ENDPROC
14870
14871 RING0_INT_FRAME # can't unwind into user space anyway
14872 syscall_fault:
14873 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14874 + push %ss
14875 + pop %ds
14876 +#endif
14877 GET_THREAD_INFO(%ebp)
14878 movl $-EFAULT,PT_EAX(%esp)
14879 jmp resume_userspace
14880 -END(syscall_fault)
14881 +ENDPROC(syscall_fault)
14882
14883 syscall_badsys:
14884 movl $-ENOSYS,PT_EAX(%esp)
14885 jmp resume_userspace
14886 -END(syscall_badsys)
14887 +ENDPROC(syscall_badsys)
14888 CFI_ENDPROC
14889 /*
14890 * End of kprobes section
14891 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14892 CFI_ENDPROC
14893 ENDPROC(ptregs_clone)
14894
14895 + ALIGN;
14896 +ENTRY(kernel_execve)
14897 + CFI_STARTPROC
14898 + pushl_cfi %ebp
14899 + sub $PT_OLDSS+4,%esp
14900 + pushl_cfi %edi
14901 + pushl_cfi %ecx
14902 + pushl_cfi %eax
14903 + lea 3*4(%esp),%edi
14904 + mov $PT_OLDSS/4+1,%ecx
14905 + xorl %eax,%eax
14906 + rep stosl
14907 + popl_cfi %eax
14908 + popl_cfi %ecx
14909 + popl_cfi %edi
14910 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14911 + pushl_cfi %esp
14912 + call sys_execve
14913 + add $4,%esp
14914 + CFI_ADJUST_CFA_OFFSET -4
14915 + GET_THREAD_INFO(%ebp)
14916 + test %eax,%eax
14917 + jz syscall_exit
14918 + add $PT_OLDSS+4,%esp
14919 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14920 + popl_cfi %ebp
14921 + ret
14922 + CFI_ENDPROC
14923 +ENDPROC(kernel_execve)
14924 +
14925 .macro FIXUP_ESPFIX_STACK
14926 /*
14927 * Switch back for ESPFIX stack to the normal zerobased stack
14928 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14929 * normal stack and adjusts ESP with the matching offset.
14930 */
14931 /* fixup the stack */
14932 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14933 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14934 +#ifdef CONFIG_SMP
14935 + movl PER_CPU_VAR(cpu_number), %ebx
14936 + shll $PAGE_SHIFT_asm, %ebx
14937 + addl $cpu_gdt_table, %ebx
14938 +#else
14939 + movl $cpu_gdt_table, %ebx
14940 +#endif
14941 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14942 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14943 shl $16, %eax
14944 addl %esp, %eax /* the adjusted stack pointer */
14945 pushl_cfi $__KERNEL_DS
14946 @@ -819,7 +1066,7 @@ vector=vector+1
14947 .endr
14948 2: jmp common_interrupt
14949 .endr
14950 -END(irq_entries_start)
14951 +ENDPROC(irq_entries_start)
14952
14953 .previous
14954 END(interrupt)
14955 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14956 pushl_cfi $do_coprocessor_error
14957 jmp error_code
14958 CFI_ENDPROC
14959 -END(coprocessor_error)
14960 +ENDPROC(coprocessor_error)
14961
14962 ENTRY(simd_coprocessor_error)
14963 RING0_INT_FRAME
14964 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14965 #endif
14966 jmp error_code
14967 CFI_ENDPROC
14968 -END(simd_coprocessor_error)
14969 +ENDPROC(simd_coprocessor_error)
14970
14971 ENTRY(device_not_available)
14972 RING0_INT_FRAME
14973 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14974 pushl_cfi $do_device_not_available
14975 jmp error_code
14976 CFI_ENDPROC
14977 -END(device_not_available)
14978 +ENDPROC(device_not_available)
14979
14980 #ifdef CONFIG_PARAVIRT
14981 ENTRY(native_iret)
14982 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
14983 .align 4
14984 .long native_iret, iret_exc
14985 .previous
14986 -END(native_iret)
14987 +ENDPROC(native_iret)
14988
14989 ENTRY(native_irq_enable_sysexit)
14990 sti
14991 sysexit
14992 -END(native_irq_enable_sysexit)
14993 +ENDPROC(native_irq_enable_sysexit)
14994 #endif
14995
14996 ENTRY(overflow)
14997 @@ -919,7 +1166,7 @@ ENTRY(overflow)
14998 pushl_cfi $do_overflow
14999 jmp error_code
15000 CFI_ENDPROC
15001 -END(overflow)
15002 +ENDPROC(overflow)
15003
15004 ENTRY(bounds)
15005 RING0_INT_FRAME
15006 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15007 pushl_cfi $do_bounds
15008 jmp error_code
15009 CFI_ENDPROC
15010 -END(bounds)
15011 +ENDPROC(bounds)
15012
15013 ENTRY(invalid_op)
15014 RING0_INT_FRAME
15015 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15016 pushl_cfi $do_invalid_op
15017 jmp error_code
15018 CFI_ENDPROC
15019 -END(invalid_op)
15020 +ENDPROC(invalid_op)
15021
15022 ENTRY(coprocessor_segment_overrun)
15023 RING0_INT_FRAME
15024 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15025 pushl_cfi $do_coprocessor_segment_overrun
15026 jmp error_code
15027 CFI_ENDPROC
15028 -END(coprocessor_segment_overrun)
15029 +ENDPROC(coprocessor_segment_overrun)
15030
15031 ENTRY(invalid_TSS)
15032 RING0_EC_FRAME
15033 pushl_cfi $do_invalid_TSS
15034 jmp error_code
15035 CFI_ENDPROC
15036 -END(invalid_TSS)
15037 +ENDPROC(invalid_TSS)
15038
15039 ENTRY(segment_not_present)
15040 RING0_EC_FRAME
15041 pushl_cfi $do_segment_not_present
15042 jmp error_code
15043 CFI_ENDPROC
15044 -END(segment_not_present)
15045 +ENDPROC(segment_not_present)
15046
15047 ENTRY(stack_segment)
15048 RING0_EC_FRAME
15049 pushl_cfi $do_stack_segment
15050 jmp error_code
15051 CFI_ENDPROC
15052 -END(stack_segment)
15053 +ENDPROC(stack_segment)
15054
15055 ENTRY(alignment_check)
15056 RING0_EC_FRAME
15057 pushl_cfi $do_alignment_check
15058 jmp error_code
15059 CFI_ENDPROC
15060 -END(alignment_check)
15061 +ENDPROC(alignment_check)
15062
15063 ENTRY(divide_error)
15064 RING0_INT_FRAME
15065 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15066 pushl_cfi $do_divide_error
15067 jmp error_code
15068 CFI_ENDPROC
15069 -END(divide_error)
15070 +ENDPROC(divide_error)
15071
15072 #ifdef CONFIG_X86_MCE
15073 ENTRY(machine_check)
15074 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15075 pushl_cfi machine_check_vector
15076 jmp error_code
15077 CFI_ENDPROC
15078 -END(machine_check)
15079 +ENDPROC(machine_check)
15080 #endif
15081
15082 ENTRY(spurious_interrupt_bug)
15083 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15084 pushl_cfi $do_spurious_interrupt_bug
15085 jmp error_code
15086 CFI_ENDPROC
15087 -END(spurious_interrupt_bug)
15088 +ENDPROC(spurious_interrupt_bug)
15089 /*
15090 * End of kprobes section
15091 */
15092 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15093
15094 ENTRY(mcount)
15095 ret
15096 -END(mcount)
15097 +ENDPROC(mcount)
15098
15099 ENTRY(ftrace_caller)
15100 cmpl $0, function_trace_stop
15101 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15102 .globl ftrace_stub
15103 ftrace_stub:
15104 ret
15105 -END(ftrace_caller)
15106 +ENDPROC(ftrace_caller)
15107
15108 #else /* ! CONFIG_DYNAMIC_FTRACE */
15109
15110 @@ -1177,7 +1424,7 @@ trace:
15111 popl %ecx
15112 popl %eax
15113 jmp ftrace_stub
15114 -END(mcount)
15115 +ENDPROC(mcount)
15116 #endif /* CONFIG_DYNAMIC_FTRACE */
15117 #endif /* CONFIG_FUNCTION_TRACER */
15118
15119 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15120 popl %ecx
15121 popl %eax
15122 ret
15123 -END(ftrace_graph_caller)
15124 +ENDPROC(ftrace_graph_caller)
15125
15126 .globl return_to_handler
15127 return_to_handler:
15128 @@ -1253,15 +1500,18 @@ error_code:
15129 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15130 REG_TO_PTGS %ecx
15131 SET_KERNEL_GS %ecx
15132 - movl $(__USER_DS), %ecx
15133 + movl $(__KERNEL_DS), %ecx
15134 movl %ecx, %ds
15135 movl %ecx, %es
15136 +
15137 + pax_enter_kernel
15138 +
15139 TRACE_IRQS_OFF
15140 movl %esp,%eax # pt_regs pointer
15141 call *%edi
15142 jmp ret_from_exception
15143 CFI_ENDPROC
15144 -END(page_fault)
15145 +ENDPROC(page_fault)
15146
15147 /*
15148 * Debug traps and NMI can happen at the one SYSENTER instruction
15149 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15150 call do_debug
15151 jmp ret_from_exception
15152 CFI_ENDPROC
15153 -END(debug)
15154 +ENDPROC(debug)
15155
15156 /*
15157 * NMI is doubly nasty. It can happen _while_ we're handling
15158 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15159 xorl %edx,%edx # zero error code
15160 movl %esp,%eax # pt_regs pointer
15161 call do_nmi
15162 +
15163 + pax_exit_kernel
15164 +
15165 jmp restore_all_notrace
15166 CFI_ENDPROC
15167
15168 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15169 FIXUP_ESPFIX_STACK # %eax == %esp
15170 xorl %edx,%edx # zero error code
15171 call do_nmi
15172 +
15173 + pax_exit_kernel
15174 +
15175 RESTORE_REGS
15176 lss 12+4(%esp), %esp # back to espfix stack
15177 CFI_ADJUST_CFA_OFFSET -24
15178 jmp irq_return
15179 CFI_ENDPROC
15180 -END(nmi)
15181 +ENDPROC(nmi)
15182
15183 ENTRY(int3)
15184 RING0_INT_FRAME
15185 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15186 call do_int3
15187 jmp ret_from_exception
15188 CFI_ENDPROC
15189 -END(int3)
15190 +ENDPROC(int3)
15191
15192 ENTRY(general_protection)
15193 RING0_EC_FRAME
15194 pushl_cfi $do_general_protection
15195 jmp error_code
15196 CFI_ENDPROC
15197 -END(general_protection)
15198 +ENDPROC(general_protection)
15199
15200 #ifdef CONFIG_KVM_GUEST
15201 ENTRY(async_page_fault)
15202 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15203 pushl_cfi $do_async_page_fault
15204 jmp error_code
15205 CFI_ENDPROC
15206 -END(async_page_fault)
15207 +ENDPROC(async_page_fault)
15208 #endif
15209
15210 /*
15211 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15212 index 1333d98..b340ca2 100644
15213 --- a/arch/x86/kernel/entry_64.S
15214 +++ b/arch/x86/kernel/entry_64.S
15215 @@ -56,6 +56,8 @@
15216 #include <asm/ftrace.h>
15217 #include <asm/percpu.h>
15218 #include <linux/err.h>
15219 +#include <asm/pgtable.h>
15220 +#include <asm/alternative-asm.h>
15221
15222 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15223 #include <linux/elf-em.h>
15224 @@ -69,8 +71,9 @@
15225 #ifdef CONFIG_FUNCTION_TRACER
15226 #ifdef CONFIG_DYNAMIC_FTRACE
15227 ENTRY(mcount)
15228 + pax_force_retaddr
15229 retq
15230 -END(mcount)
15231 +ENDPROC(mcount)
15232
15233 ENTRY(ftrace_caller)
15234 cmpl $0, function_trace_stop
15235 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15236 #endif
15237
15238 GLOBAL(ftrace_stub)
15239 + pax_force_retaddr
15240 retq
15241 -END(ftrace_caller)
15242 +ENDPROC(ftrace_caller)
15243
15244 #else /* ! CONFIG_DYNAMIC_FTRACE */
15245 ENTRY(mcount)
15246 @@ -113,6 +117,7 @@ ENTRY(mcount)
15247 #endif
15248
15249 GLOBAL(ftrace_stub)
15250 + pax_force_retaddr
15251 retq
15252
15253 trace:
15254 @@ -122,12 +127,13 @@ trace:
15255 movq 8(%rbp), %rsi
15256 subq $MCOUNT_INSN_SIZE, %rdi
15257
15258 + pax_force_fptr ftrace_trace_function
15259 call *ftrace_trace_function
15260
15261 MCOUNT_RESTORE_FRAME
15262
15263 jmp ftrace_stub
15264 -END(mcount)
15265 +ENDPROC(mcount)
15266 #endif /* CONFIG_DYNAMIC_FTRACE */
15267 #endif /* CONFIG_FUNCTION_TRACER */
15268
15269 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15270
15271 MCOUNT_RESTORE_FRAME
15272
15273 + pax_force_retaddr
15274 retq
15275 -END(ftrace_graph_caller)
15276 +ENDPROC(ftrace_graph_caller)
15277
15278 GLOBAL(return_to_handler)
15279 subq $24, %rsp
15280 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15281 movq 8(%rsp), %rdx
15282 movq (%rsp), %rax
15283 addq $24, %rsp
15284 + pax_force_fptr %rdi
15285 jmp *%rdi
15286 #endif
15287
15288 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15289 ENDPROC(native_usergs_sysret64)
15290 #endif /* CONFIG_PARAVIRT */
15291
15292 + .macro ljmpq sel, off
15293 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15294 + .byte 0x48; ljmp *1234f(%rip)
15295 + .pushsection .rodata
15296 + .align 16
15297 + 1234: .quad \off; .word \sel
15298 + .popsection
15299 +#else
15300 + pushq $\sel
15301 + pushq $\off
15302 + lretq
15303 +#endif
15304 + .endm
15305 +
15306 + .macro pax_enter_kernel
15307 + pax_set_fptr_mask
15308 +#ifdef CONFIG_PAX_KERNEXEC
15309 + call pax_enter_kernel
15310 +#endif
15311 + .endm
15312 +
15313 + .macro pax_exit_kernel
15314 +#ifdef CONFIG_PAX_KERNEXEC
15315 + call pax_exit_kernel
15316 +#endif
15317 + .endm
15318 +
15319 +#ifdef CONFIG_PAX_KERNEXEC
15320 +ENTRY(pax_enter_kernel)
15321 + pushq %rdi
15322 +
15323 +#ifdef CONFIG_PARAVIRT
15324 + PV_SAVE_REGS(CLBR_RDI)
15325 +#endif
15326 +
15327 + GET_CR0_INTO_RDI
15328 + bts $16,%rdi
15329 + jnc 3f
15330 + mov %cs,%edi
15331 + cmp $__KERNEL_CS,%edi
15332 + jnz 2f
15333 +1:
15334 +
15335 +#ifdef CONFIG_PARAVIRT
15336 + PV_RESTORE_REGS(CLBR_RDI)
15337 +#endif
15338 +
15339 + popq %rdi
15340 + pax_force_retaddr
15341 + retq
15342 +
15343 +2: ljmpq __KERNEL_CS,1f
15344 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15345 +4: SET_RDI_INTO_CR0
15346 + jmp 1b
15347 +ENDPROC(pax_enter_kernel)
15348 +
15349 +ENTRY(pax_exit_kernel)
15350 + pushq %rdi
15351 +
15352 +#ifdef CONFIG_PARAVIRT
15353 + PV_SAVE_REGS(CLBR_RDI)
15354 +#endif
15355 +
15356 + mov %cs,%rdi
15357 + cmp $__KERNEXEC_KERNEL_CS,%edi
15358 + jz 2f
15359 +1:
15360 +
15361 +#ifdef CONFIG_PARAVIRT
15362 + PV_RESTORE_REGS(CLBR_RDI);
15363 +#endif
15364 +
15365 + popq %rdi
15366 + pax_force_retaddr
15367 + retq
15368 +
15369 +2: GET_CR0_INTO_RDI
15370 + btr $16,%rdi
15371 + ljmpq __KERNEL_CS,3f
15372 +3: SET_RDI_INTO_CR0
15373 + jmp 1b
15374 +#ifdef CONFIG_PARAVIRT
15375 + PV_RESTORE_REGS(CLBR_RDI);
15376 +#endif
15377 +
15378 + popq %rdi
15379 + pax_force_retaddr
15380 + retq
15381 +ENDPROC(pax_exit_kernel)
15382 +#endif
15383 +
15384 + .macro pax_enter_kernel_user
15385 + pax_set_fptr_mask
15386 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15387 + call pax_enter_kernel_user
15388 +#endif
15389 + .endm
15390 +
15391 + .macro pax_exit_kernel_user
15392 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15393 + call pax_exit_kernel_user
15394 +#endif
15395 +#ifdef CONFIG_PAX_RANDKSTACK
15396 + pushq %rax
15397 + call pax_randomize_kstack
15398 + popq %rax
15399 +#endif
15400 + .endm
15401 +
15402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15403 +ENTRY(pax_enter_kernel_user)
15404 + pushq %rdi
15405 + pushq %rbx
15406 +
15407 +#ifdef CONFIG_PARAVIRT
15408 + PV_SAVE_REGS(CLBR_RDI)
15409 +#endif
15410 +
15411 + GET_CR3_INTO_RDI
15412 + mov %rdi,%rbx
15413 + add $__START_KERNEL_map,%rbx
15414 + sub phys_base(%rip),%rbx
15415 +
15416 +#ifdef CONFIG_PARAVIRT
15417 + pushq %rdi
15418 + cmpl $0, pv_info+PARAVIRT_enabled
15419 + jz 1f
15420 + i = 0
15421 + .rept USER_PGD_PTRS
15422 + mov i*8(%rbx),%rsi
15423 + mov $0,%sil
15424 + lea i*8(%rbx),%rdi
15425 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15426 + i = i + 1
15427 + .endr
15428 + jmp 2f
15429 +1:
15430 +#endif
15431 +
15432 + i = 0
15433 + .rept USER_PGD_PTRS
15434 + movb $0,i*8(%rbx)
15435 + i = i + 1
15436 + .endr
15437 +
15438 +#ifdef CONFIG_PARAVIRT
15439 +2: popq %rdi
15440 +#endif
15441 + SET_RDI_INTO_CR3
15442 +
15443 +#ifdef CONFIG_PAX_KERNEXEC
15444 + GET_CR0_INTO_RDI
15445 + bts $16,%rdi
15446 + SET_RDI_INTO_CR0
15447 +#endif
15448 +
15449 +#ifdef CONFIG_PARAVIRT
15450 + PV_RESTORE_REGS(CLBR_RDI)
15451 +#endif
15452 +
15453 + popq %rbx
15454 + popq %rdi
15455 + pax_force_retaddr
15456 + retq
15457 +ENDPROC(pax_enter_kernel_user)
15458 +
15459 +ENTRY(pax_exit_kernel_user)
15460 + push %rdi
15461 +
15462 +#ifdef CONFIG_PARAVIRT
15463 + pushq %rbx
15464 + PV_SAVE_REGS(CLBR_RDI)
15465 +#endif
15466 +
15467 +#ifdef CONFIG_PAX_KERNEXEC
15468 + GET_CR0_INTO_RDI
15469 + btr $16,%rdi
15470 + SET_RDI_INTO_CR0
15471 +#endif
15472 +
15473 + GET_CR3_INTO_RDI
15474 + add $__START_KERNEL_map,%rdi
15475 + sub phys_base(%rip),%rdi
15476 +
15477 +#ifdef CONFIG_PARAVIRT
15478 + cmpl $0, pv_info+PARAVIRT_enabled
15479 + jz 1f
15480 + mov %rdi,%rbx
15481 + i = 0
15482 + .rept USER_PGD_PTRS
15483 + mov i*8(%rbx),%rsi
15484 + mov $0x67,%sil
15485 + lea i*8(%rbx),%rdi
15486 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15487 + i = i + 1
15488 + .endr
15489 + jmp 2f
15490 +1:
15491 +#endif
15492 +
15493 + i = 0
15494 + .rept USER_PGD_PTRS
15495 + movb $0x67,i*8(%rdi)
15496 + i = i + 1
15497 + .endr
15498 +
15499 +#ifdef CONFIG_PARAVIRT
15500 +2: PV_RESTORE_REGS(CLBR_RDI)
15501 + popq %rbx
15502 +#endif
15503 +
15504 + popq %rdi
15505 + pax_force_retaddr
15506 + retq
15507 +ENDPROC(pax_exit_kernel_user)
15508 +#endif
15509 +
15510 +.macro pax_erase_kstack
15511 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15512 + call pax_erase_kstack
15513 +#endif
15514 +.endm
15515 +
15516 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15517 +/*
15518 + * r11: thread_info
15519 + * rcx, rdx: can be clobbered
15520 + */
15521 +ENTRY(pax_erase_kstack)
15522 + pushq %rdi
15523 + pushq %rax
15524 + pushq %r11
15525 +
15526 + GET_THREAD_INFO(%r11)
15527 + mov TI_lowest_stack(%r11), %rdi
15528 + mov $-0xBEEF, %rax
15529 + std
15530 +
15531 +1: mov %edi, %ecx
15532 + and $THREAD_SIZE_asm - 1, %ecx
15533 + shr $3, %ecx
15534 + repne scasq
15535 + jecxz 2f
15536 +
15537 + cmp $2*8, %ecx
15538 + jc 2f
15539 +
15540 + mov $2*8, %ecx
15541 + repe scasq
15542 + jecxz 2f
15543 + jne 1b
15544 +
15545 +2: cld
15546 + mov %esp, %ecx
15547 + sub %edi, %ecx
15548 +
15549 + cmp $THREAD_SIZE_asm, %rcx
15550 + jb 3f
15551 + ud2
15552 +3:
15553 +
15554 + shr $3, %ecx
15555 + rep stosq
15556 +
15557 + mov TI_task_thread_sp0(%r11), %rdi
15558 + sub $256, %rdi
15559 + mov %rdi, TI_lowest_stack(%r11)
15560 +
15561 + popq %r11
15562 + popq %rax
15563 + popq %rdi
15564 + pax_force_retaddr
15565 + ret
15566 +ENDPROC(pax_erase_kstack)
15567 +#endif
15568
15569 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15570 #ifdef CONFIG_TRACE_IRQFLAGS
15571 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15572 .endm
15573
15574 .macro UNFAKE_STACK_FRAME
15575 - addq $8*6, %rsp
15576 - CFI_ADJUST_CFA_OFFSET -(6*8)
15577 + addq $8*6 + ARG_SKIP, %rsp
15578 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15579 .endm
15580
15581 /*
15582 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15583 movq %rsp, %rsi
15584
15585 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15586 - testl $3, CS(%rdi)
15587 + testb $3, CS(%rdi)
15588 je 1f
15589 SWAPGS
15590 /*
15591 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15592 movq_cfi r15, R15+16
15593 movq %r11, 8(%rsp) /* return address */
15594 FIXUP_TOP_OF_STACK %r11, 16
15595 + pax_force_retaddr
15596 ret
15597 CFI_ENDPROC
15598 -END(save_rest)
15599 +ENDPROC(save_rest)
15600
15601 /* save complete stack frame */
15602 .pushsection .kprobes.text, "ax"
15603 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15604 js 1f /* negative -> in kernel */
15605 SWAPGS
15606 xorl %ebx,%ebx
15607 -1: ret
15608 +1: pax_force_retaddr_bts
15609 + ret
15610 CFI_ENDPROC
15611 -END(save_paranoid)
15612 +ENDPROC(save_paranoid)
15613 .popsection
15614
15615 /*
15616 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15617
15618 RESTORE_REST
15619
15620 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15621 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15622 jz retint_restore_args
15623
15624 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15625 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15626 jmp ret_from_sys_call # go to the SYSRET fastpath
15627
15628 CFI_ENDPROC
15629 -END(ret_from_fork)
15630 +ENDPROC(ret_from_fork)
15631
15632 /*
15633 * System call entry. Up to 6 arguments in registers are supported.
15634 @@ -457,7 +743,7 @@ END(ret_from_fork)
15635 ENTRY(system_call)
15636 CFI_STARTPROC simple
15637 CFI_SIGNAL_FRAME
15638 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15639 + CFI_DEF_CFA rsp,0
15640 CFI_REGISTER rip,rcx
15641 /*CFI_REGISTER rflags,r11*/
15642 SWAPGS_UNSAFE_STACK
15643 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15644
15645 movq %rsp,PER_CPU_VAR(old_rsp)
15646 movq PER_CPU_VAR(kernel_stack),%rsp
15647 + SAVE_ARGS 8*6,0
15648 + pax_enter_kernel_user
15649 /*
15650 * No need to follow this irqs off/on section - it's straight
15651 * and short:
15652 */
15653 ENABLE_INTERRUPTS(CLBR_NONE)
15654 - SAVE_ARGS 8,0
15655 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15656 movq %rcx,RIP-ARGOFFSET(%rsp)
15657 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15658 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15659 + GET_THREAD_INFO(%rcx)
15660 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15661 jnz tracesys
15662 system_call_fastpath:
15663 cmpq $__NR_syscall_max,%rax
15664 ja badsys
15665 - movq %r10,%rcx
15666 + movq R10-ARGOFFSET(%rsp),%rcx
15667 call *sys_call_table(,%rax,8) # XXX: rip relative
15668 movq %rax,RAX-ARGOFFSET(%rsp)
15669 /*
15670 @@ -498,10 +786,13 @@ sysret_check:
15671 LOCKDEP_SYS_EXIT
15672 DISABLE_INTERRUPTS(CLBR_NONE)
15673 TRACE_IRQS_OFF
15674 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15675 + GET_THREAD_INFO(%rcx)
15676 + movl TI_flags(%rcx),%edx
15677 andl %edi,%edx
15678 jnz sysret_careful
15679 CFI_REMEMBER_STATE
15680 + pax_exit_kernel_user
15681 + pax_erase_kstack
15682 /*
15683 * sysretq will re-enable interrupts:
15684 */
15685 @@ -553,14 +844,18 @@ badsys:
15686 * jump back to the normal fast path.
15687 */
15688 auditsys:
15689 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15690 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15691 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15692 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15693 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15694 movq %rax,%rsi /* 2nd arg: syscall number */
15695 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15696 call __audit_syscall_entry
15697 +
15698 + pax_erase_kstack
15699 +
15700 LOAD_ARGS 0 /* reload call-clobbered registers */
15701 + pax_set_fptr_mask
15702 jmp system_call_fastpath
15703
15704 /*
15705 @@ -581,7 +876,7 @@ sysret_audit:
15706 /* Do syscall tracing */
15707 tracesys:
15708 #ifdef CONFIG_AUDITSYSCALL
15709 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15710 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15711 jz auditsys
15712 #endif
15713 SAVE_REST
15714 @@ -589,16 +884,20 @@ tracesys:
15715 FIXUP_TOP_OF_STACK %rdi
15716 movq %rsp,%rdi
15717 call syscall_trace_enter
15718 +
15719 + pax_erase_kstack
15720 +
15721 /*
15722 * Reload arg registers from stack in case ptrace changed them.
15723 * We don't reload %rax because syscall_trace_enter() returned
15724 * the value it wants us to use in the table lookup.
15725 */
15726 LOAD_ARGS ARGOFFSET, 1
15727 + pax_set_fptr_mask
15728 RESTORE_REST
15729 cmpq $__NR_syscall_max,%rax
15730 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15731 - movq %r10,%rcx /* fixup for C */
15732 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15733 call *sys_call_table(,%rax,8)
15734 movq %rax,RAX-ARGOFFSET(%rsp)
15735 /* Use IRET because user could have changed frame */
15736 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15737 andl %edi,%edx
15738 jnz int_careful
15739 andl $~TS_COMPAT,TI_status(%rcx)
15740 + pax_erase_kstack
15741 jmp retint_swapgs
15742
15743 /* Either reschedule or signal or syscall exit tracking needed. */
15744 @@ -665,7 +965,7 @@ int_restore_rest:
15745 TRACE_IRQS_OFF
15746 jmp int_with_check
15747 CFI_ENDPROC
15748 -END(system_call)
15749 +ENDPROC(system_call)
15750
15751 /*
15752 * Certain special system calls that need to save a complete full stack frame.
15753 @@ -681,7 +981,7 @@ ENTRY(\label)
15754 call \func
15755 jmp ptregscall_common
15756 CFI_ENDPROC
15757 -END(\label)
15758 +ENDPROC(\label)
15759 .endm
15760
15761 PTREGSCALL stub_clone, sys_clone, %r8
15762 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15763 movq_cfi_restore R12+8, r12
15764 movq_cfi_restore RBP+8, rbp
15765 movq_cfi_restore RBX+8, rbx
15766 + pax_force_retaddr
15767 ret $REST_SKIP /* pop extended registers */
15768 CFI_ENDPROC
15769 -END(ptregscall_common)
15770 +ENDPROC(ptregscall_common)
15771
15772 ENTRY(stub_execve)
15773 CFI_STARTPROC
15774 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15775 RESTORE_REST
15776 jmp int_ret_from_sys_call
15777 CFI_ENDPROC
15778 -END(stub_execve)
15779 +ENDPROC(stub_execve)
15780
15781 /*
15782 * sigreturn is special because it needs to restore all registers on return.
15783 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15784 RESTORE_REST
15785 jmp int_ret_from_sys_call
15786 CFI_ENDPROC
15787 -END(stub_rt_sigreturn)
15788 +ENDPROC(stub_rt_sigreturn)
15789
15790 /*
15791 * Build the entry stubs and pointer table with some assembler magic.
15792 @@ -769,7 +1070,7 @@ vector=vector+1
15793 2: jmp common_interrupt
15794 .endr
15795 CFI_ENDPROC
15796 -END(irq_entries_start)
15797 +ENDPROC(irq_entries_start)
15798
15799 .previous
15800 END(interrupt)
15801 @@ -789,6 +1090,16 @@ END(interrupt)
15802 subq $ORIG_RAX-RBP, %rsp
15803 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15804 SAVE_ARGS_IRQ
15805 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15806 + testb $3, CS(%rdi)
15807 + jnz 1f
15808 + pax_enter_kernel
15809 + jmp 2f
15810 +1: pax_enter_kernel_user
15811 +2:
15812 +#else
15813 + pax_enter_kernel
15814 +#endif
15815 call \func
15816 .endm
15817
15818 @@ -820,7 +1131,7 @@ ret_from_intr:
15819
15820 exit_intr:
15821 GET_THREAD_INFO(%rcx)
15822 - testl $3,CS-ARGOFFSET(%rsp)
15823 + testb $3,CS-ARGOFFSET(%rsp)
15824 je retint_kernel
15825
15826 /* Interrupt came from user space */
15827 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15828 * The iretq could re-enable interrupts:
15829 */
15830 DISABLE_INTERRUPTS(CLBR_ANY)
15831 + pax_exit_kernel_user
15832 TRACE_IRQS_IRETQ
15833 SWAPGS
15834 jmp restore_args
15835
15836 retint_restore_args: /* return to kernel space */
15837 DISABLE_INTERRUPTS(CLBR_ANY)
15838 + pax_exit_kernel
15839 + pax_force_retaddr RIP-ARGOFFSET
15840 /*
15841 * The iretq could re-enable interrupts:
15842 */
15843 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15844 #endif
15845
15846 CFI_ENDPROC
15847 -END(common_interrupt)
15848 +ENDPROC(common_interrupt)
15849 /*
15850 * End of kprobes section
15851 */
15852 @@ -953,7 +1267,7 @@ ENTRY(\sym)
15853 interrupt \do_sym
15854 jmp ret_from_intr
15855 CFI_ENDPROC
15856 -END(\sym)
15857 +ENDPROC(\sym)
15858 .endm
15859
15860 #ifdef CONFIG_SMP
15861 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
15862 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15863 call error_entry
15864 DEFAULT_FRAME 0
15865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15866 + testb $3, CS(%rsp)
15867 + jnz 1f
15868 + pax_enter_kernel
15869 + jmp 2f
15870 +1: pax_enter_kernel_user
15871 +2:
15872 +#else
15873 + pax_enter_kernel
15874 +#endif
15875 movq %rsp,%rdi /* pt_regs pointer */
15876 xorl %esi,%esi /* no error code */
15877 call \do_sym
15878 jmp error_exit /* %ebx: no swapgs flag */
15879 CFI_ENDPROC
15880 -END(\sym)
15881 +ENDPROC(\sym)
15882 .endm
15883
15884 .macro paranoidzeroentry sym do_sym
15885 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
15886 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15887 call save_paranoid
15888 TRACE_IRQS_OFF
15889 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15890 + testb $3, CS(%rsp)
15891 + jnz 1f
15892 + pax_enter_kernel
15893 + jmp 2f
15894 +1: pax_enter_kernel_user
15895 +2:
15896 +#else
15897 + pax_enter_kernel
15898 +#endif
15899 movq %rsp,%rdi /* pt_regs pointer */
15900 xorl %esi,%esi /* no error code */
15901 call \do_sym
15902 jmp paranoid_exit /* %ebx: no swapgs flag */
15903 CFI_ENDPROC
15904 -END(\sym)
15905 +ENDPROC(\sym)
15906 .endm
15907
15908 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15909 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15910 .macro paranoidzeroentry_ist sym do_sym ist
15911 ENTRY(\sym)
15912 INTR_FRAME
15913 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
15914 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15915 call save_paranoid
15916 TRACE_IRQS_OFF
15917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15918 + testb $3, CS(%rsp)
15919 + jnz 1f
15920 + pax_enter_kernel
15921 + jmp 2f
15922 +1: pax_enter_kernel_user
15923 +2:
15924 +#else
15925 + pax_enter_kernel
15926 +#endif
15927 movq %rsp,%rdi /* pt_regs pointer */
15928 xorl %esi,%esi /* no error code */
15929 +#ifdef CONFIG_SMP
15930 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15931 + lea init_tss(%r12), %r12
15932 +#else
15933 + lea init_tss(%rip), %r12
15934 +#endif
15935 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15936 call \do_sym
15937 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15938 jmp paranoid_exit /* %ebx: no swapgs flag */
15939 CFI_ENDPROC
15940 -END(\sym)
15941 +ENDPROC(\sym)
15942 .endm
15943
15944 .macro errorentry sym do_sym
15945 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
15946 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15947 call error_entry
15948 DEFAULT_FRAME 0
15949 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15950 + testb $3, CS(%rsp)
15951 + jnz 1f
15952 + pax_enter_kernel
15953 + jmp 2f
15954 +1: pax_enter_kernel_user
15955 +2:
15956 +#else
15957 + pax_enter_kernel
15958 +#endif
15959 movq %rsp,%rdi /* pt_regs pointer */
15960 movq ORIG_RAX(%rsp),%rsi /* get error code */
15961 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15962 call \do_sym
15963 jmp error_exit /* %ebx: no swapgs flag */
15964 CFI_ENDPROC
15965 -END(\sym)
15966 +ENDPROC(\sym)
15967 .endm
15968
15969 /* error code is on the stack already */
15970 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
15971 call save_paranoid
15972 DEFAULT_FRAME 0
15973 TRACE_IRQS_OFF
15974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15975 + testb $3, CS(%rsp)
15976 + jnz 1f
15977 + pax_enter_kernel
15978 + jmp 2f
15979 +1: pax_enter_kernel_user
15980 +2:
15981 +#else
15982 + pax_enter_kernel
15983 +#endif
15984 movq %rsp,%rdi /* pt_regs pointer */
15985 movq ORIG_RAX(%rsp),%rsi /* get error code */
15986 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15987 call \do_sym
15988 jmp paranoid_exit /* %ebx: no swapgs flag */
15989 CFI_ENDPROC
15990 -END(\sym)
15991 +ENDPROC(\sym)
15992 .endm
15993
15994 zeroentry divide_error do_divide_error
15995 @@ -1134,9 +1504,10 @@ gs_change:
15996 2: mfence /* workaround */
15997 SWAPGS
15998 popfq_cfi
15999 + pax_force_retaddr
16000 ret
16001 CFI_ENDPROC
16002 -END(native_load_gs_index)
16003 +ENDPROC(native_load_gs_index)
16004
16005 .section __ex_table,"a"
16006 .align 8
16007 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16008 * Here we are in the child and the registers are set as they were
16009 * at kernel_thread() invocation in the parent.
16010 */
16011 + pax_force_fptr %rsi
16012 call *%rsi
16013 # exit
16014 mov %eax, %edi
16015 call do_exit
16016 ud2 # padding for call trace
16017 CFI_ENDPROC
16018 -END(kernel_thread_helper)
16019 +ENDPROC(kernel_thread_helper)
16020
16021 /*
16022 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16023 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16024 RESTORE_REST
16025 testq %rax,%rax
16026 je int_ret_from_sys_call
16027 - RESTORE_ARGS
16028 UNFAKE_STACK_FRAME
16029 + pax_force_retaddr
16030 ret
16031 CFI_ENDPROC
16032 -END(kernel_execve)
16033 +ENDPROC(kernel_execve)
16034
16035 /* Call softirq on interrupt stack. Interrupts are off. */
16036 ENTRY(call_softirq)
16037 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16038 CFI_DEF_CFA_REGISTER rsp
16039 CFI_ADJUST_CFA_OFFSET -8
16040 decl PER_CPU_VAR(irq_count)
16041 + pax_force_retaddr
16042 ret
16043 CFI_ENDPROC
16044 -END(call_softirq)
16045 +ENDPROC(call_softirq)
16046
16047 #ifdef CONFIG_XEN
16048 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16049 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16050 decl PER_CPU_VAR(irq_count)
16051 jmp error_exit
16052 CFI_ENDPROC
16053 -END(xen_do_hypervisor_callback)
16054 +ENDPROC(xen_do_hypervisor_callback)
16055
16056 /*
16057 * Hypervisor uses this for application faults while it executes.
16058 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16059 SAVE_ALL
16060 jmp error_exit
16061 CFI_ENDPROC
16062 -END(xen_failsafe_callback)
16063 +ENDPROC(xen_failsafe_callback)
16064
16065 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16066 xen_hvm_callback_vector xen_evtchn_do_upcall
16067 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16068 TRACE_IRQS_OFF
16069 testl %ebx,%ebx /* swapgs needed? */
16070 jnz paranoid_restore
16071 - testl $3,CS(%rsp)
16072 + testb $3,CS(%rsp)
16073 jnz paranoid_userspace
16074 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16075 + pax_exit_kernel
16076 + TRACE_IRQS_IRETQ 0
16077 + SWAPGS_UNSAFE_STACK
16078 + RESTORE_ALL 8
16079 + pax_force_retaddr_bts
16080 + jmp irq_return
16081 +#endif
16082 paranoid_swapgs:
16083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16084 + pax_exit_kernel_user
16085 +#else
16086 + pax_exit_kernel
16087 +#endif
16088 TRACE_IRQS_IRETQ 0
16089 SWAPGS_UNSAFE_STACK
16090 RESTORE_ALL 8
16091 jmp irq_return
16092 paranoid_restore:
16093 + pax_exit_kernel
16094 TRACE_IRQS_IRETQ 0
16095 RESTORE_ALL 8
16096 + pax_force_retaddr_bts
16097 jmp irq_return
16098 paranoid_userspace:
16099 GET_THREAD_INFO(%rcx)
16100 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16101 TRACE_IRQS_OFF
16102 jmp paranoid_userspace
16103 CFI_ENDPROC
16104 -END(paranoid_exit)
16105 +ENDPROC(paranoid_exit)
16106
16107 /*
16108 * Exception entry point. This expects an error code/orig_rax on the stack.
16109 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16110 movq_cfi r14, R14+8
16111 movq_cfi r15, R15+8
16112 xorl %ebx,%ebx
16113 - testl $3,CS+8(%rsp)
16114 + testb $3,CS+8(%rsp)
16115 je error_kernelspace
16116 error_swapgs:
16117 SWAPGS
16118 error_sti:
16119 TRACE_IRQS_OFF
16120 + pax_force_retaddr_bts
16121 ret
16122
16123 /*
16124 @@ -1458,7 +1847,7 @@ bstep_iret:
16125 movq %rcx,RIP+8(%rsp)
16126 jmp error_swapgs
16127 CFI_ENDPROC
16128 -END(error_entry)
16129 +ENDPROC(error_entry)
16130
16131
16132 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16133 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16134 jnz retint_careful
16135 jmp retint_swapgs
16136 CFI_ENDPROC
16137 -END(error_exit)
16138 +ENDPROC(error_exit)
16139
16140 /*
16141 * Test if a given stack is an NMI stack or not.
16142 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16143 * If %cs was not the kernel segment, then the NMI triggered in user
16144 * space, which means it is definitely not nested.
16145 */
16146 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16147 + je 1f
16148 cmpl $__KERNEL_CS, 16(%rsp)
16149 jne first_nmi
16150 -
16151 +1:
16152 /*
16153 * Check the special variable on the stack to see if NMIs are
16154 * executing.
16155 @@ -1659,6 +2050,16 @@ restart_nmi:
16156 */
16157 call save_paranoid
16158 DEFAULT_FRAME 0
16159 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16160 + testb $3, CS(%rsp)
16161 + jnz 1f
16162 + pax_enter_kernel
16163 + jmp 2f
16164 +1: pax_enter_kernel_user
16165 +2:
16166 +#else
16167 + pax_enter_kernel
16168 +#endif
16169 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16170 movq %rsp,%rdi
16171 movq $-1,%rsi
16172 @@ -1666,14 +2067,25 @@ restart_nmi:
16173 testl %ebx,%ebx /* swapgs needed? */
16174 jnz nmi_restore
16175 nmi_swapgs:
16176 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16177 + pax_exit_kernel_user
16178 +#else
16179 + pax_exit_kernel
16180 +#endif
16181 SWAPGS_UNSAFE_STACK
16182 + RESTORE_ALL 8
16183 + /* Clear the NMI executing stack variable */
16184 + movq $0, 10*8(%rsp)
16185 + jmp irq_return
16186 nmi_restore:
16187 + pax_exit_kernel
16188 RESTORE_ALL 8
16189 + pax_force_retaddr_bts
16190 /* Clear the NMI executing stack variable */
16191 movq $0, 10*8(%rsp)
16192 jmp irq_return
16193 CFI_ENDPROC
16194 -END(nmi)
16195 +ENDPROC(nmi)
16196
16197 /*
16198 * If an NMI hit an iret because of an exception or breakpoint,
16199 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16200 mov $-ENOSYS,%eax
16201 sysret
16202 CFI_ENDPROC
16203 -END(ignore_sysret)
16204 +ENDPROC(ignore_sysret)
16205
16206 /*
16207 * End of kprobes section
16208 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16209 index c9a281f..ce2f317 100644
16210 --- a/arch/x86/kernel/ftrace.c
16211 +++ b/arch/x86/kernel/ftrace.c
16212 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16213 static const void *mod_code_newcode; /* holds the text to write to the IP */
16214
16215 static unsigned nmi_wait_count;
16216 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16217 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16218
16219 int ftrace_arch_read_dyn_info(char *buf, int size)
16220 {
16221 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16222
16223 r = snprintf(buf, size, "%u %u",
16224 nmi_wait_count,
16225 - atomic_read(&nmi_update_count));
16226 + atomic_read_unchecked(&nmi_update_count));
16227 return r;
16228 }
16229
16230 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16231
16232 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16233 smp_rmb();
16234 + pax_open_kernel();
16235 ftrace_mod_code();
16236 - atomic_inc(&nmi_update_count);
16237 + pax_close_kernel();
16238 + atomic_inc_unchecked(&nmi_update_count);
16239 }
16240 /* Must have previous changes seen before executions */
16241 smp_mb();
16242 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16243 {
16244 unsigned char replaced[MCOUNT_INSN_SIZE];
16245
16246 + ip = ktla_ktva(ip);
16247 +
16248 /*
16249 * Note: Due to modules and __init, code can
16250 * disappear and change, we need to protect against faulting
16251 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16252 unsigned char old[MCOUNT_INSN_SIZE], *new;
16253 int ret;
16254
16255 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16256 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16257 new = ftrace_call_replace(ip, (unsigned long)func);
16258 ret = ftrace_modify_code(ip, old, new);
16259
16260 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16261 {
16262 unsigned char code[MCOUNT_INSN_SIZE];
16263
16264 + ip = ktla_ktva(ip);
16265 +
16266 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16267 return -EFAULT;
16268
16269 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16270 index 51ff186..9e77418 100644
16271 --- a/arch/x86/kernel/head32.c
16272 +++ b/arch/x86/kernel/head32.c
16273 @@ -19,6 +19,7 @@
16274 #include <asm/io_apic.h>
16275 #include <asm/bios_ebda.h>
16276 #include <asm/tlbflush.h>
16277 +#include <asm/boot.h>
16278
16279 static void __init i386_default_early_setup(void)
16280 {
16281 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16282
16283 void __init i386_start_kernel(void)
16284 {
16285 - memblock_reserve(__pa_symbol(&_text),
16286 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16287 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16288
16289 #ifdef CONFIG_BLK_DEV_INITRD
16290 /* Reserve INITRD */
16291 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16292 index ce0be7c..c41476e 100644
16293 --- a/arch/x86/kernel/head_32.S
16294 +++ b/arch/x86/kernel/head_32.S
16295 @@ -25,6 +25,12 @@
16296 /* Physical address */
16297 #define pa(X) ((X) - __PAGE_OFFSET)
16298
16299 +#ifdef CONFIG_PAX_KERNEXEC
16300 +#define ta(X) (X)
16301 +#else
16302 +#define ta(X) ((X) - __PAGE_OFFSET)
16303 +#endif
16304 +
16305 /*
16306 * References to members of the new_cpu_data structure.
16307 */
16308 @@ -54,11 +60,7 @@
16309 * and small than max_low_pfn, otherwise will waste some page table entries
16310 */
16311
16312 -#if PTRS_PER_PMD > 1
16313 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16314 -#else
16315 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16316 -#endif
16317 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16318
16319 /* Number of possible pages in the lowmem region */
16320 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16321 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16322 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16323
16324 /*
16325 + * Real beginning of normal "text" segment
16326 + */
16327 +ENTRY(stext)
16328 +ENTRY(_stext)
16329 +
16330 +/*
16331 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16332 * %esi points to the real-mode code as a 32-bit pointer.
16333 * CS and DS must be 4 GB flat segments, but we don't depend on
16334 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16335 * can.
16336 */
16337 __HEAD
16338 +
16339 +#ifdef CONFIG_PAX_KERNEXEC
16340 + jmp startup_32
16341 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16342 +.fill PAGE_SIZE-5,1,0xcc
16343 +#endif
16344 +
16345 ENTRY(startup_32)
16346 movl pa(stack_start),%ecx
16347
16348 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16349 2:
16350 leal -__PAGE_OFFSET(%ecx),%esp
16351
16352 +#ifdef CONFIG_SMP
16353 + movl $pa(cpu_gdt_table),%edi
16354 + movl $__per_cpu_load,%eax
16355 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16356 + rorl $16,%eax
16357 + movb %al,__KERNEL_PERCPU + 4(%edi)
16358 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16359 + movl $__per_cpu_end - 1,%eax
16360 + subl $__per_cpu_start,%eax
16361 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16362 +#endif
16363 +
16364 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16365 + movl $NR_CPUS,%ecx
16366 + movl $pa(cpu_gdt_table),%edi
16367 +1:
16368 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16369 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16370 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16371 + addl $PAGE_SIZE_asm,%edi
16372 + loop 1b
16373 +#endif
16374 +
16375 +#ifdef CONFIG_PAX_KERNEXEC
16376 + movl $pa(boot_gdt),%edi
16377 + movl $__LOAD_PHYSICAL_ADDR,%eax
16378 + movw %ax,__BOOT_CS + 2(%edi)
16379 + rorl $16,%eax
16380 + movb %al,__BOOT_CS + 4(%edi)
16381 + movb %ah,__BOOT_CS + 7(%edi)
16382 + rorl $16,%eax
16383 +
16384 + ljmp $(__BOOT_CS),$1f
16385 +1:
16386 +
16387 + movl $NR_CPUS,%ecx
16388 + movl $pa(cpu_gdt_table),%edi
16389 + addl $__PAGE_OFFSET,%eax
16390 +1:
16391 + movw %ax,__KERNEL_CS + 2(%edi)
16392 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16393 + rorl $16,%eax
16394 + movb %al,__KERNEL_CS + 4(%edi)
16395 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16396 + movb %ah,__KERNEL_CS + 7(%edi)
16397 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16398 + rorl $16,%eax
16399 + addl $PAGE_SIZE_asm,%edi
16400 + loop 1b
16401 +#endif
16402 +
16403 /*
16404 * Clear BSS first so that there are no surprises...
16405 */
16406 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16407 movl %eax, pa(max_pfn_mapped)
16408
16409 /* Do early initialization of the fixmap area */
16410 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16411 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16412 +#ifdef CONFIG_COMPAT_VDSO
16413 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16414 +#else
16415 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16416 +#endif
16417 #else /* Not PAE */
16418
16419 page_pde_offset = (__PAGE_OFFSET >> 20);
16420 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16421 movl %eax, pa(max_pfn_mapped)
16422
16423 /* Do early initialization of the fixmap area */
16424 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16425 - movl %eax,pa(initial_page_table+0xffc)
16426 +#ifdef CONFIG_COMPAT_VDSO
16427 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16428 +#else
16429 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16430 +#endif
16431 #endif
16432
16433 #ifdef CONFIG_PARAVIRT
16434 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16435 cmpl $num_subarch_entries, %eax
16436 jae bad_subarch
16437
16438 - movl pa(subarch_entries)(,%eax,4), %eax
16439 - subl $__PAGE_OFFSET, %eax
16440 - jmp *%eax
16441 + jmp *pa(subarch_entries)(,%eax,4)
16442
16443 bad_subarch:
16444 WEAK(lguest_entry)
16445 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16446 __INITDATA
16447
16448 subarch_entries:
16449 - .long default_entry /* normal x86/PC */
16450 - .long lguest_entry /* lguest hypervisor */
16451 - .long xen_entry /* Xen hypervisor */
16452 - .long default_entry /* Moorestown MID */
16453 + .long ta(default_entry) /* normal x86/PC */
16454 + .long ta(lguest_entry) /* lguest hypervisor */
16455 + .long ta(xen_entry) /* Xen hypervisor */
16456 + .long ta(default_entry) /* Moorestown MID */
16457 num_subarch_entries = (. - subarch_entries) / 4
16458 .previous
16459 #else
16460 @@ -312,6 +382,7 @@ default_entry:
16461 orl %edx,%eax
16462 movl %eax,%cr4
16463
16464 +#ifdef CONFIG_X86_PAE
16465 testb $X86_CR4_PAE, %al # check if PAE is enabled
16466 jz 6f
16467
16468 @@ -340,6 +411,9 @@ default_entry:
16469 /* Make changes effective */
16470 wrmsr
16471
16472 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16473 +#endif
16474 +
16475 6:
16476
16477 /*
16478 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16479 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16480 movl %eax,%ss # after changing gdt.
16481
16482 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16483 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16484 movl %eax,%ds
16485 movl %eax,%es
16486
16487 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16488 */
16489 cmpb $0,ready
16490 jne 1f
16491 - movl $gdt_page,%eax
16492 + movl $cpu_gdt_table,%eax
16493 movl $stack_canary,%ecx
16494 +#ifdef CONFIG_SMP
16495 + addl $__per_cpu_load,%ecx
16496 +#endif
16497 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16498 shrl $16, %ecx
16499 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16500 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16501 1:
16502 -#endif
16503 movl $(__KERNEL_STACK_CANARY),%eax
16504 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16505 + movl $(__USER_DS),%eax
16506 +#else
16507 + xorl %eax,%eax
16508 +#endif
16509 movl %eax,%gs
16510
16511 xorl %eax,%eax # Clear LDT
16512 @@ -558,22 +639,22 @@ early_page_fault:
16513 jmp early_fault
16514
16515 early_fault:
16516 - cld
16517 #ifdef CONFIG_PRINTK
16518 + cmpl $1,%ss:early_recursion_flag
16519 + je hlt_loop
16520 + incl %ss:early_recursion_flag
16521 + cld
16522 pusha
16523 movl $(__KERNEL_DS),%eax
16524 movl %eax,%ds
16525 movl %eax,%es
16526 - cmpl $2,early_recursion_flag
16527 - je hlt_loop
16528 - incl early_recursion_flag
16529 movl %cr2,%eax
16530 pushl %eax
16531 pushl %edx /* trapno */
16532 pushl $fault_msg
16533 call printk
16534 +; call dump_stack
16535 #endif
16536 - call dump_stack
16537 hlt_loop:
16538 hlt
16539 jmp hlt_loop
16540 @@ -581,8 +662,11 @@ hlt_loop:
16541 /* This is the default interrupt "handler" :-) */
16542 ALIGN
16543 ignore_int:
16544 - cld
16545 #ifdef CONFIG_PRINTK
16546 + cmpl $2,%ss:early_recursion_flag
16547 + je hlt_loop
16548 + incl %ss:early_recursion_flag
16549 + cld
16550 pushl %eax
16551 pushl %ecx
16552 pushl %edx
16553 @@ -591,9 +675,6 @@ ignore_int:
16554 movl $(__KERNEL_DS),%eax
16555 movl %eax,%ds
16556 movl %eax,%es
16557 - cmpl $2,early_recursion_flag
16558 - je hlt_loop
16559 - incl early_recursion_flag
16560 pushl 16(%esp)
16561 pushl 24(%esp)
16562 pushl 32(%esp)
16563 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16564 /*
16565 * BSS section
16566 */
16567 -__PAGE_ALIGNED_BSS
16568 - .align PAGE_SIZE
16569 #ifdef CONFIG_X86_PAE
16570 +.section .initial_pg_pmd,"a",@progbits
16571 initial_pg_pmd:
16572 .fill 1024*KPMDS,4,0
16573 #else
16574 +.section .initial_page_table,"a",@progbits
16575 ENTRY(initial_page_table)
16576 .fill 1024,4,0
16577 #endif
16578 +.section .initial_pg_fixmap,"a",@progbits
16579 initial_pg_fixmap:
16580 .fill 1024,4,0
16581 +.section .empty_zero_page,"a",@progbits
16582 ENTRY(empty_zero_page)
16583 .fill 4096,1,0
16584 +.section .swapper_pg_dir,"a",@progbits
16585 ENTRY(swapper_pg_dir)
16586 +#ifdef CONFIG_X86_PAE
16587 + .fill 4,8,0
16588 +#else
16589 .fill 1024,4,0
16590 +#endif
16591 +
16592 +/*
16593 + * The IDT has to be page-aligned to simplify the Pentium
16594 + * F0 0F bug workaround.. We have a special link segment
16595 + * for this.
16596 + */
16597 +.section .idt,"a",@progbits
16598 +ENTRY(idt_table)
16599 + .fill 256,8,0
16600
16601 /*
16602 * This starts the data section.
16603 */
16604 #ifdef CONFIG_X86_PAE
16605 -__PAGE_ALIGNED_DATA
16606 - /* Page-aligned for the benefit of paravirt? */
16607 - .align PAGE_SIZE
16608 +.section .initial_page_table,"a",@progbits
16609 ENTRY(initial_page_table)
16610 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16611 # if KPMDS == 3
16612 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16613 # error "Kernel PMDs should be 1, 2 or 3"
16614 # endif
16615 .align PAGE_SIZE /* needs to be page-sized too */
16616 +
16617 +#ifdef CONFIG_PAX_PER_CPU_PGD
16618 +ENTRY(cpu_pgd)
16619 + .rept NR_CPUS
16620 + .fill 4,8,0
16621 + .endr
16622 +#endif
16623 +
16624 #endif
16625
16626 .data
16627 .balign 4
16628 ENTRY(stack_start)
16629 - .long init_thread_union+THREAD_SIZE
16630 + .long init_thread_union+THREAD_SIZE-8
16631
16632 +ready: .byte 0
16633 +
16634 +.section .rodata,"a",@progbits
16635 early_recursion_flag:
16636 .long 0
16637
16638 -ready: .byte 0
16639 -
16640 int_msg:
16641 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16642
16643 @@ -707,7 +811,7 @@ fault_msg:
16644 .word 0 # 32 bit align gdt_desc.address
16645 boot_gdt_descr:
16646 .word __BOOT_DS+7
16647 - .long boot_gdt - __PAGE_OFFSET
16648 + .long pa(boot_gdt)
16649
16650 .word 0 # 32-bit align idt_desc.address
16651 idt_descr:
16652 @@ -718,7 +822,7 @@ idt_descr:
16653 .word 0 # 32 bit align gdt_desc.address
16654 ENTRY(early_gdt_descr)
16655 .word GDT_ENTRIES*8-1
16656 - .long gdt_page /* Overwritten for secondary CPUs */
16657 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16658
16659 /*
16660 * The boot_gdt must mirror the equivalent in setup.S and is
16661 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16662 .align L1_CACHE_BYTES
16663 ENTRY(boot_gdt)
16664 .fill GDT_ENTRY_BOOT_CS,8,0
16665 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16666 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16667 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16668 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16669 +
16670 + .align PAGE_SIZE_asm
16671 +ENTRY(cpu_gdt_table)
16672 + .rept NR_CPUS
16673 + .quad 0x0000000000000000 /* NULL descriptor */
16674 + .quad 0x0000000000000000 /* 0x0b reserved */
16675 + .quad 0x0000000000000000 /* 0x13 reserved */
16676 + .quad 0x0000000000000000 /* 0x1b reserved */
16677 +
16678 +#ifdef CONFIG_PAX_KERNEXEC
16679 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16680 +#else
16681 + .quad 0x0000000000000000 /* 0x20 unused */
16682 +#endif
16683 +
16684 + .quad 0x0000000000000000 /* 0x28 unused */
16685 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16686 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16687 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16688 + .quad 0x0000000000000000 /* 0x4b reserved */
16689 + .quad 0x0000000000000000 /* 0x53 reserved */
16690 + .quad 0x0000000000000000 /* 0x5b reserved */
16691 +
16692 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16693 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16694 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16695 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16696 +
16697 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16698 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16699 +
16700 + /*
16701 + * Segments used for calling PnP BIOS have byte granularity.
16702 + * The code segments and data segments have fixed 64k limits,
16703 + * the transfer segment sizes are set at run time.
16704 + */
16705 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16706 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16707 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16708 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16709 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16710 +
16711 + /*
16712 + * The APM segments have byte granularity and their bases
16713 + * are set at run time. All have 64k limits.
16714 + */
16715 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16716 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16717 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16718 +
16719 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16720 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16721 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16722 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16723 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16724 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16725 +
16726 + /* Be sure this is zeroed to avoid false validations in Xen */
16727 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16728 + .endr
16729 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16730 index 40f4eb3..6d24d9d 100644
16731 --- a/arch/x86/kernel/head_64.S
16732 +++ b/arch/x86/kernel/head_64.S
16733 @@ -19,6 +19,8 @@
16734 #include <asm/cache.h>
16735 #include <asm/processor-flags.h>
16736 #include <asm/percpu.h>
16737 +#include <asm/cpufeature.h>
16738 +#include <asm/alternative-asm.h>
16739
16740 #ifdef CONFIG_PARAVIRT
16741 #include <asm/asm-offsets.h>
16742 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16743 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16744 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16745 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16746 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16747 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16748 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16749 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16750 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16751 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16752
16753 .text
16754 __HEAD
16755 @@ -85,35 +93,23 @@ startup_64:
16756 */
16757 addq %rbp, init_level4_pgt + 0(%rip)
16758 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16759 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16760 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16761 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16762 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16763
16764 addq %rbp, level3_ident_pgt + 0(%rip)
16765 +#ifndef CONFIG_XEN
16766 + addq %rbp, level3_ident_pgt + 8(%rip)
16767 +#endif
16768
16769 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16770 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16771 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16772 +
16773 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16774 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16775
16776 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16777 -
16778 - /* Add an Identity mapping if I am above 1G */
16779 - leaq _text(%rip), %rdi
16780 - andq $PMD_PAGE_MASK, %rdi
16781 -
16782 - movq %rdi, %rax
16783 - shrq $PUD_SHIFT, %rax
16784 - andq $(PTRS_PER_PUD - 1), %rax
16785 - jz ident_complete
16786 -
16787 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16788 - leaq level3_ident_pgt(%rip), %rbx
16789 - movq %rdx, 0(%rbx, %rax, 8)
16790 -
16791 - movq %rdi, %rax
16792 - shrq $PMD_SHIFT, %rax
16793 - andq $(PTRS_PER_PMD - 1), %rax
16794 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16795 - leaq level2_spare_pgt(%rip), %rbx
16796 - movq %rdx, 0(%rbx, %rax, 8)
16797 -ident_complete:
16798 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16799
16800 /*
16801 * Fixup the kernel text+data virtual addresses. Note that
16802 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16803 * after the boot processor executes this code.
16804 */
16805
16806 - /* Enable PAE mode and PGE */
16807 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16808 + /* Enable PAE mode and PSE/PGE */
16809 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16810 movq %rax, %cr4
16811
16812 /* Setup early boot stage 4 level pagetables. */
16813 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16814 movl $MSR_EFER, %ecx
16815 rdmsr
16816 btsl $_EFER_SCE, %eax /* Enable System Call */
16817 - btl $20,%edi /* No Execute supported? */
16818 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16819 jnc 1f
16820 btsl $_EFER_NX, %eax
16821 + leaq init_level4_pgt(%rip), %rdi
16822 +#ifndef CONFIG_EFI
16823 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16824 +#endif
16825 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16826 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16827 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16828 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16829 1: wrmsr /* Make changes effective */
16830
16831 /* Setup cr0 */
16832 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16833 * jump. In addition we need to ensure %cs is set so we make this
16834 * a far return.
16835 */
16836 + pax_set_fptr_mask
16837 movq initial_code(%rip),%rax
16838 pushq $0 # fake return address to stop unwinder
16839 pushq $__KERNEL_CS # set correct cs
16840 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16841 bad_address:
16842 jmp bad_address
16843
16844 - .section ".init.text","ax"
16845 + __INIT
16846 #ifdef CONFIG_EARLY_PRINTK
16847 .globl early_idt_handlers
16848 early_idt_handlers:
16849 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16850 #endif /* EARLY_PRINTK */
16851 1: hlt
16852 jmp 1b
16853 + .previous
16854
16855 #ifdef CONFIG_EARLY_PRINTK
16856 + __INITDATA
16857 early_recursion_flag:
16858 .long 0
16859 + .previous
16860
16861 + .section .rodata,"a",@progbits
16862 early_idt_msg:
16863 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16864 early_idt_ripmsg:
16865 .asciz "RIP %s\n"
16866 + .previous
16867 #endif /* CONFIG_EARLY_PRINTK */
16868 - .previous
16869
16870 + .section .rodata,"a",@progbits
16871 #define NEXT_PAGE(name) \
16872 .balign PAGE_SIZE; \
16873 ENTRY(name)
16874 @@ -338,7 +348,6 @@ ENTRY(name)
16875 i = i + 1 ; \
16876 .endr
16877
16878 - .data
16879 /*
16880 * This default setting generates an ident mapping at address 0x100000
16881 * and a mapping for the kernel that precisely maps virtual address
16882 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16883 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16884 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16885 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16886 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16887 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16888 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16889 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16890 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16891 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16892 .org init_level4_pgt + L4_START_KERNEL*8, 0
16893 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16894 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16895
16896 +#ifdef CONFIG_PAX_PER_CPU_PGD
16897 +NEXT_PAGE(cpu_pgd)
16898 + .rept NR_CPUS
16899 + .fill 512,8,0
16900 + .endr
16901 +#endif
16902 +
16903 NEXT_PAGE(level3_ident_pgt)
16904 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16905 +#ifdef CONFIG_XEN
16906 .fill 511,8,0
16907 +#else
16908 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16909 + .fill 510,8,0
16910 +#endif
16911 +
16912 +NEXT_PAGE(level3_vmalloc_start_pgt)
16913 + .fill 512,8,0
16914 +
16915 +NEXT_PAGE(level3_vmalloc_end_pgt)
16916 + .fill 512,8,0
16917 +
16918 +NEXT_PAGE(level3_vmemmap_pgt)
16919 + .fill L3_VMEMMAP_START,8,0
16920 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16921
16922 NEXT_PAGE(level3_kernel_pgt)
16923 .fill L3_START_KERNEL,8,0
16924 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16925 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16926 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16927
16928 +NEXT_PAGE(level2_vmemmap_pgt)
16929 + .fill 512,8,0
16930 +
16931 NEXT_PAGE(level2_fixmap_pgt)
16932 - .fill 506,8,0
16933 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16934 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16935 - .fill 5,8,0
16936 + .fill 507,8,0
16937 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16938 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16939 + .fill 4,8,0
16940
16941 -NEXT_PAGE(level1_fixmap_pgt)
16942 +NEXT_PAGE(level1_vsyscall_pgt)
16943 .fill 512,8,0
16944
16945 -NEXT_PAGE(level2_ident_pgt)
16946 - /* Since I easily can, map the first 1G.
16947 + /* Since I easily can, map the first 2G.
16948 * Don't set NX because code runs from these pages.
16949 */
16950 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16951 +NEXT_PAGE(level2_ident_pgt)
16952 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16953
16954 NEXT_PAGE(level2_kernel_pgt)
16955 /*
16956 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16957 * If you want to increase this then increase MODULES_VADDR
16958 * too.)
16959 */
16960 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16961 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16962 -
16963 -NEXT_PAGE(level2_spare_pgt)
16964 - .fill 512, 8, 0
16965 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16966
16967 #undef PMDS
16968 #undef NEXT_PAGE
16969
16970 - .data
16971 + .align PAGE_SIZE
16972 +ENTRY(cpu_gdt_table)
16973 + .rept NR_CPUS
16974 + .quad 0x0000000000000000 /* NULL descriptor */
16975 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16976 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16977 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16978 + .quad 0x00cffb000000ffff /* __USER32_CS */
16979 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16980 + .quad 0x00affb000000ffff /* __USER_CS */
16981 +
16982 +#ifdef CONFIG_PAX_KERNEXEC
16983 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16984 +#else
16985 + .quad 0x0 /* unused */
16986 +#endif
16987 +
16988 + .quad 0,0 /* TSS */
16989 + .quad 0,0 /* LDT */
16990 + .quad 0,0,0 /* three TLS descriptors */
16991 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16992 + /* asm/segment.h:GDT_ENTRIES must match this */
16993 +
16994 + /* zero the remaining page */
16995 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16996 + .endr
16997 +
16998 .align 16
16999 .globl early_gdt_descr
17000 early_gdt_descr:
17001 .word GDT_ENTRIES*8-1
17002 early_gdt_descr_base:
17003 - .quad INIT_PER_CPU_VAR(gdt_page)
17004 + .quad cpu_gdt_table
17005
17006 ENTRY(phys_base)
17007 /* This must match the first entry in level2_kernel_pgt */
17008 .quad 0x0000000000000000
17009
17010 #include "../../x86/xen/xen-head.S"
17011 -
17012 - .section .bss, "aw", @nobits
17013 +
17014 + .section .rodata,"a",@progbits
17015 .align L1_CACHE_BYTES
17016 ENTRY(idt_table)
17017 - .skip IDT_ENTRIES * 16
17018 + .fill 512,8,0
17019
17020 .align L1_CACHE_BYTES
17021 ENTRY(nmi_idt_table)
17022 - .skip IDT_ENTRIES * 16
17023 + .fill 512,8,0
17024
17025 __PAGE_ALIGNED_BSS
17026 .align PAGE_SIZE
17027 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17028 index 9c3bd4a..e1d9b35 100644
17029 --- a/arch/x86/kernel/i386_ksyms_32.c
17030 +++ b/arch/x86/kernel/i386_ksyms_32.c
17031 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17032 EXPORT_SYMBOL(cmpxchg8b_emu);
17033 #endif
17034
17035 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17036 +
17037 /* Networking helper routines. */
17038 EXPORT_SYMBOL(csum_partial_copy_generic);
17039 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17040 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17041
17042 EXPORT_SYMBOL(__get_user_1);
17043 EXPORT_SYMBOL(__get_user_2);
17044 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17045
17046 EXPORT_SYMBOL(csum_partial);
17047 EXPORT_SYMBOL(empty_zero_page);
17048 +
17049 +#ifdef CONFIG_PAX_KERNEXEC
17050 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17051 +#endif
17052 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17053 index 739d859..d1d6be7 100644
17054 --- a/arch/x86/kernel/i387.c
17055 +++ b/arch/x86/kernel/i387.c
17056 @@ -188,6 +188,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17057
17058 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17059 unsigned int pos, unsigned int count,
17060 + void *kbuf, void __user *ubuf) __size_overflow(4);
17061 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17062 + unsigned int pos, unsigned int count,
17063 void *kbuf, void __user *ubuf)
17064 {
17065 int ret;
17066 @@ -207,6 +210,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17067
17068 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17069 unsigned int pos, unsigned int count,
17070 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17071 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17072 + unsigned int pos, unsigned int count,
17073 const void *kbuf, const void __user *ubuf)
17074 {
17075 int ret;
17076 @@ -240,6 +246,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17077
17078 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17079 unsigned int pos, unsigned int count,
17080 + void *kbuf, void __user *ubuf) __size_overflow(4);
17081 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17082 + unsigned int pos, unsigned int count,
17083 void *kbuf, void __user *ubuf)
17084 {
17085 int ret;
17086 @@ -269,6 +278,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17087
17088 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17089 unsigned int pos, unsigned int count,
17090 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17091 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17092 + unsigned int pos, unsigned int count,
17093 const void *kbuf, const void __user *ubuf)
17094 {
17095 int ret;
17096 @@ -439,6 +451,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17097
17098 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17099 unsigned int pos, unsigned int count,
17100 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17101 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17102 + unsigned int pos, unsigned int count,
17103 void *kbuf, void __user *ubuf)
17104 {
17105 struct user_i387_ia32_struct env;
17106 @@ -471,6 +486,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17107
17108 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17109 unsigned int pos, unsigned int count,
17110 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17111 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17112 + unsigned int pos, unsigned int count,
17113 const void *kbuf, const void __user *ubuf)
17114 {
17115 struct user_i387_ia32_struct env;
17116 @@ -619,6 +637,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17117 }
17118
17119 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17120 + unsigned int size) __size_overflow(2);
17121 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17122 unsigned int size)
17123 {
17124 struct task_struct *tsk = current;
17125 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17126 index 6104852..6114160 100644
17127 --- a/arch/x86/kernel/i8259.c
17128 +++ b/arch/x86/kernel/i8259.c
17129 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17130 "spurious 8259A interrupt: IRQ%d.\n", irq);
17131 spurious_irq_mask |= irqmask;
17132 }
17133 - atomic_inc(&irq_err_count);
17134 + atomic_inc_unchecked(&irq_err_count);
17135 /*
17136 * Theoretically we do not have to handle this IRQ,
17137 * but in Linux this does not cause problems and is
17138 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17139 index 43e9ccf..44ccf6f 100644
17140 --- a/arch/x86/kernel/init_task.c
17141 +++ b/arch/x86/kernel/init_task.c
17142 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17143 * way process stacks are handled. This is done by having a special
17144 * "init_task" linker map entry..
17145 */
17146 -union thread_union init_thread_union __init_task_data =
17147 - { INIT_THREAD_INFO(init_task) };
17148 +union thread_union init_thread_union __init_task_data;
17149
17150 /*
17151 * Initial task structure.
17152 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17153 * section. Since TSS's are completely CPU-local, we want them
17154 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17155 */
17156 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17157 -
17158 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17159 +EXPORT_SYMBOL(init_tss);
17160 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17161 index 8c96897..be66bfa 100644
17162 --- a/arch/x86/kernel/ioport.c
17163 +++ b/arch/x86/kernel/ioport.c
17164 @@ -6,6 +6,7 @@
17165 #include <linux/sched.h>
17166 #include <linux/kernel.h>
17167 #include <linux/capability.h>
17168 +#include <linux/security.h>
17169 #include <linux/errno.h>
17170 #include <linux/types.h>
17171 #include <linux/ioport.h>
17172 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17173
17174 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17175 return -EINVAL;
17176 +#ifdef CONFIG_GRKERNSEC_IO
17177 + if (turn_on && grsec_disable_privio) {
17178 + gr_handle_ioperm();
17179 + return -EPERM;
17180 + }
17181 +#endif
17182 if (turn_on && !capable(CAP_SYS_RAWIO))
17183 return -EPERM;
17184
17185 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17186 * because the ->io_bitmap_max value must match the bitmap
17187 * contents:
17188 */
17189 - tss = &per_cpu(init_tss, get_cpu());
17190 + tss = init_tss + get_cpu();
17191
17192 if (turn_on)
17193 bitmap_clear(t->io_bitmap_ptr, from, num);
17194 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17195 return -EINVAL;
17196 /* Trying to gain more privileges? */
17197 if (level > old) {
17198 +#ifdef CONFIG_GRKERNSEC_IO
17199 + if (grsec_disable_privio) {
17200 + gr_handle_iopl();
17201 + return -EPERM;
17202 + }
17203 +#endif
17204 if (!capable(CAP_SYS_RAWIO))
17205 return -EPERM;
17206 }
17207 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17208 index 7943e0c..dd32c5c 100644
17209 --- a/arch/x86/kernel/irq.c
17210 +++ b/arch/x86/kernel/irq.c
17211 @@ -18,7 +18,7 @@
17212 #include <asm/mce.h>
17213 #include <asm/hw_irq.h>
17214
17215 -atomic_t irq_err_count;
17216 +atomic_unchecked_t irq_err_count;
17217
17218 /* Function pointer for generic interrupt vector handling */
17219 void (*x86_platform_ipi_callback)(void) = NULL;
17220 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17221 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17222 seq_printf(p, " Machine check polls\n");
17223 #endif
17224 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17225 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17226 #if defined(CONFIG_X86_IO_APIC)
17227 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17228 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17229 #endif
17230 return 0;
17231 }
17232 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17233
17234 u64 arch_irq_stat(void)
17235 {
17236 - u64 sum = atomic_read(&irq_err_count);
17237 + u64 sum = atomic_read_unchecked(&irq_err_count);
17238
17239 #ifdef CONFIG_X86_IO_APIC
17240 - sum += atomic_read(&irq_mis_count);
17241 + sum += atomic_read_unchecked(&irq_mis_count);
17242 #endif
17243 return sum;
17244 }
17245 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17246 index 40fc861..9b8739b 100644
17247 --- a/arch/x86/kernel/irq_32.c
17248 +++ b/arch/x86/kernel/irq_32.c
17249 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17250 __asm__ __volatile__("andl %%esp,%0" :
17251 "=r" (sp) : "0" (THREAD_SIZE - 1));
17252
17253 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17254 + return sp < STACK_WARN;
17255 }
17256
17257 static void print_stack_overflow(void)
17258 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17259 * per-CPU IRQ handling contexts (thread information and stack)
17260 */
17261 union irq_ctx {
17262 - struct thread_info tinfo;
17263 - u32 stack[THREAD_SIZE/sizeof(u32)];
17264 + unsigned long previous_esp;
17265 + u32 stack[THREAD_SIZE/sizeof(u32)];
17266 } __attribute__((aligned(THREAD_SIZE)));
17267
17268 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17269 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17270 static inline int
17271 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17272 {
17273 - union irq_ctx *curctx, *irqctx;
17274 + union irq_ctx *irqctx;
17275 u32 *isp, arg1, arg2;
17276
17277 - curctx = (union irq_ctx *) current_thread_info();
17278 irqctx = __this_cpu_read(hardirq_ctx);
17279
17280 /*
17281 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17282 * handler) we can't do that and just have to keep using the
17283 * current stack (which is the irq stack already after all)
17284 */
17285 - if (unlikely(curctx == irqctx))
17286 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17287 return 0;
17288
17289 /* build the stack frame on the IRQ stack */
17290 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17291 - irqctx->tinfo.task = curctx->tinfo.task;
17292 - irqctx->tinfo.previous_esp = current_stack_pointer;
17293 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17294 + irqctx->previous_esp = current_stack_pointer;
17295
17296 - /*
17297 - * Copy the softirq bits in preempt_count so that the
17298 - * softirq checks work in the hardirq context.
17299 - */
17300 - irqctx->tinfo.preempt_count =
17301 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17302 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17303 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17304 + __set_fs(MAKE_MM_SEG(0));
17305 +#endif
17306
17307 if (unlikely(overflow))
17308 call_on_stack(print_stack_overflow, isp);
17309 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17310 : "0" (irq), "1" (desc), "2" (isp),
17311 "D" (desc->handle_irq)
17312 : "memory", "cc", "ecx");
17313 +
17314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17315 + __set_fs(current_thread_info()->addr_limit);
17316 +#endif
17317 +
17318 return 1;
17319 }
17320
17321 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17322 */
17323 void __cpuinit irq_ctx_init(int cpu)
17324 {
17325 - union irq_ctx *irqctx;
17326 -
17327 if (per_cpu(hardirq_ctx, cpu))
17328 return;
17329
17330 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17331 - THREAD_FLAGS,
17332 - THREAD_ORDER));
17333 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17334 - irqctx->tinfo.cpu = cpu;
17335 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17336 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17337 -
17338 - per_cpu(hardirq_ctx, cpu) = irqctx;
17339 -
17340 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17341 - THREAD_FLAGS,
17342 - THREAD_ORDER));
17343 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17344 - irqctx->tinfo.cpu = cpu;
17345 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17346 -
17347 - per_cpu(softirq_ctx, cpu) = irqctx;
17348 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17349 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17350
17351 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17352 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17353 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17354 asmlinkage void do_softirq(void)
17355 {
17356 unsigned long flags;
17357 - struct thread_info *curctx;
17358 union irq_ctx *irqctx;
17359 u32 *isp;
17360
17361 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17362 local_irq_save(flags);
17363
17364 if (local_softirq_pending()) {
17365 - curctx = current_thread_info();
17366 irqctx = __this_cpu_read(softirq_ctx);
17367 - irqctx->tinfo.task = curctx->task;
17368 - irqctx->tinfo.previous_esp = current_stack_pointer;
17369 + irqctx->previous_esp = current_stack_pointer;
17370
17371 /* build the stack frame on the softirq stack */
17372 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17373 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17374 +
17375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17376 + __set_fs(MAKE_MM_SEG(0));
17377 +#endif
17378
17379 call_on_stack(__do_softirq, isp);
17380 +
17381 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17382 + __set_fs(current_thread_info()->addr_limit);
17383 +#endif
17384 +
17385 /*
17386 * Shouldn't happen, we returned above if in_interrupt():
17387 */
17388 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17389 index d04d3ec..ea4b374 100644
17390 --- a/arch/x86/kernel/irq_64.c
17391 +++ b/arch/x86/kernel/irq_64.c
17392 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17393 u64 estack_top, estack_bottom;
17394 u64 curbase = (u64)task_stack_page(current);
17395
17396 - if (user_mode_vm(regs))
17397 + if (user_mode(regs))
17398 return;
17399
17400 if (regs->sp >= curbase + sizeof(struct thread_info) +
17401 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17402 index 90fcf62..e682cdd 100644
17403 --- a/arch/x86/kernel/kdebugfs.c
17404 +++ b/arch/x86/kernel/kdebugfs.c
17405 @@ -28,6 +28,8 @@ struct setup_data_node {
17406 };
17407
17408 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17409 + size_t count, loff_t *ppos) __size_overflow(3);
17410 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17411 size_t count, loff_t *ppos)
17412 {
17413 struct setup_data_node *node = file->private_data;
17414 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17415 index 2f45c4c..d95504f 100644
17416 --- a/arch/x86/kernel/kgdb.c
17417 +++ b/arch/x86/kernel/kgdb.c
17418 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17419 #ifdef CONFIG_X86_32
17420 switch (regno) {
17421 case GDB_SS:
17422 - if (!user_mode_vm(regs))
17423 + if (!user_mode(regs))
17424 *(unsigned long *)mem = __KERNEL_DS;
17425 break;
17426 case GDB_SP:
17427 - if (!user_mode_vm(regs))
17428 + if (!user_mode(regs))
17429 *(unsigned long *)mem = kernel_stack_pointer(regs);
17430 break;
17431 case GDB_GS:
17432 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17433 case 'k':
17434 /* clear the trace bit */
17435 linux_regs->flags &= ~X86_EFLAGS_TF;
17436 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17437 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17438
17439 /* set the trace bit if we're stepping */
17440 if (remcomInBuffer[0] == 's') {
17441 linux_regs->flags |= X86_EFLAGS_TF;
17442 - atomic_set(&kgdb_cpu_doing_single_step,
17443 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17444 raw_smp_processor_id());
17445 }
17446
17447 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17448
17449 switch (cmd) {
17450 case DIE_DEBUG:
17451 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17452 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17453 if (user_mode(regs))
17454 return single_step_cont(regs, args);
17455 break;
17456 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17457 index 7da647d..56fe348 100644
17458 --- a/arch/x86/kernel/kprobes.c
17459 +++ b/arch/x86/kernel/kprobes.c
17460 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17461 } __attribute__((packed)) *insn;
17462
17463 insn = (struct __arch_relative_insn *)from;
17464 +
17465 + pax_open_kernel();
17466 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17467 insn->op = op;
17468 + pax_close_kernel();
17469 }
17470
17471 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17472 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17473 kprobe_opcode_t opcode;
17474 kprobe_opcode_t *orig_opcodes = opcodes;
17475
17476 - if (search_exception_tables((unsigned long)opcodes))
17477 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17478 return 0; /* Page fault may occur on this address. */
17479
17480 retry:
17481 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17482 }
17483 }
17484 insn_get_length(&insn);
17485 + pax_open_kernel();
17486 memcpy(dest, insn.kaddr, insn.length);
17487 + pax_close_kernel();
17488
17489 #ifdef CONFIG_X86_64
17490 if (insn_rip_relative(&insn)) {
17491 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17492 (u8 *) dest;
17493 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17494 disp = (u8 *) dest + insn_offset_displacement(&insn);
17495 + pax_open_kernel();
17496 *(s32 *) disp = (s32) newdisp;
17497 + pax_close_kernel();
17498 }
17499 #endif
17500 return insn.length;
17501 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17502 */
17503 __copy_instruction(p->ainsn.insn, p->addr, 0);
17504
17505 - if (can_boost(p->addr))
17506 + if (can_boost(ktla_ktva(p->addr)))
17507 p->ainsn.boostable = 0;
17508 else
17509 p->ainsn.boostable = -1;
17510
17511 - p->opcode = *p->addr;
17512 + p->opcode = *(ktla_ktva(p->addr));
17513 }
17514
17515 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17516 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17517 * nor set current_kprobe, because it doesn't use single
17518 * stepping.
17519 */
17520 - regs->ip = (unsigned long)p->ainsn.insn;
17521 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17522 preempt_enable_no_resched();
17523 return;
17524 }
17525 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17526 if (p->opcode == BREAKPOINT_INSTRUCTION)
17527 regs->ip = (unsigned long)p->addr;
17528 else
17529 - regs->ip = (unsigned long)p->ainsn.insn;
17530 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17531 }
17532
17533 /*
17534 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17535 setup_singlestep(p, regs, kcb, 0);
17536 return 1;
17537 }
17538 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17539 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17540 /*
17541 * The breakpoint instruction was removed right
17542 * after we hit it. Another cpu has removed
17543 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17544 " movq %rax, 152(%rsp)\n"
17545 RESTORE_REGS_STRING
17546 " popfq\n"
17547 +#ifdef KERNEXEC_PLUGIN
17548 + " btsq $63,(%rsp)\n"
17549 +#endif
17550 #else
17551 " pushf\n"
17552 SAVE_REGS_STRING
17553 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17554 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17555 {
17556 unsigned long *tos = stack_addr(regs);
17557 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17558 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17559 unsigned long orig_ip = (unsigned long)p->addr;
17560 kprobe_opcode_t *insn = p->ainsn.insn;
17561
17562 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17563 struct die_args *args = data;
17564 int ret = NOTIFY_DONE;
17565
17566 - if (args->regs && user_mode_vm(args->regs))
17567 + if (args->regs && user_mode(args->regs))
17568 return ret;
17569
17570 switch (val) {
17571 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17572 * Verify if the address gap is in 2GB range, because this uses
17573 * a relative jump.
17574 */
17575 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17576 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17577 if (abs(rel) > 0x7fffffff)
17578 return -ERANGE;
17579
17580 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17581 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17582
17583 /* Set probe function call */
17584 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17585 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17586
17587 /* Set returning jmp instruction at the tail of out-of-line buffer */
17588 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17589 - (u8 *)op->kp.addr + op->optinsn.size);
17590 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17591
17592 flush_icache_range((unsigned long) buf,
17593 (unsigned long) buf + TMPL_END_IDX +
17594 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17595 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17596
17597 /* Backup instructions which will be replaced by jump address */
17598 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17599 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17600 RELATIVE_ADDR_SIZE);
17601
17602 insn_buf[0] = RELATIVEJUMP_OPCODE;
17603 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17604 index ea69726..a305f16 100644
17605 --- a/arch/x86/kernel/ldt.c
17606 +++ b/arch/x86/kernel/ldt.c
17607 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17608 if (reload) {
17609 #ifdef CONFIG_SMP
17610 preempt_disable();
17611 - load_LDT(pc);
17612 + load_LDT_nolock(pc);
17613 if (!cpumask_equal(mm_cpumask(current->mm),
17614 cpumask_of(smp_processor_id())))
17615 smp_call_function(flush_ldt, current->mm, 1);
17616 preempt_enable();
17617 #else
17618 - load_LDT(pc);
17619 + load_LDT_nolock(pc);
17620 #endif
17621 }
17622 if (oldsize) {
17623 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17624 return err;
17625
17626 for (i = 0; i < old->size; i++)
17627 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17628 + write_ldt_entry(new->ldt, i, old->ldt + i);
17629 return 0;
17630 }
17631
17632 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17633 retval = copy_ldt(&mm->context, &old_mm->context);
17634 mutex_unlock(&old_mm->context.lock);
17635 }
17636 +
17637 + if (tsk == current) {
17638 + mm->context.vdso = 0;
17639 +
17640 +#ifdef CONFIG_X86_32
17641 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17642 + mm->context.user_cs_base = 0UL;
17643 + mm->context.user_cs_limit = ~0UL;
17644 +
17645 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17646 + cpus_clear(mm->context.cpu_user_cs_mask);
17647 +#endif
17648 +
17649 +#endif
17650 +#endif
17651 +
17652 + }
17653 +
17654 return retval;
17655 }
17656
17657 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17658 }
17659 }
17660
17661 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17662 static int read_ldt(void __user *ptr, unsigned long bytecount)
17663 {
17664 int err;
17665 @@ -175,6 +194,7 @@ error_return:
17666 return err;
17667 }
17668
17669 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17670 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
17671 {
17672 /* CHECKME: Can we use _one_ random number ? */
17673 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17674 }
17675 }
17676
17677 +#ifdef CONFIG_PAX_SEGMEXEC
17678 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17679 + error = -EINVAL;
17680 + goto out_unlock;
17681 + }
17682 +#endif
17683 +
17684 fill_ldt(&ldt, &ldt_info);
17685 if (oldmode)
17686 ldt.avl = 0;
17687 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17688 index a3fa43b..8966f4c 100644
17689 --- a/arch/x86/kernel/machine_kexec_32.c
17690 +++ b/arch/x86/kernel/machine_kexec_32.c
17691 @@ -27,7 +27,7 @@
17692 #include <asm/cacheflush.h>
17693 #include <asm/debugreg.h>
17694
17695 -static void set_idt(void *newidt, __u16 limit)
17696 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17697 {
17698 struct desc_ptr curidt;
17699
17700 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17701 }
17702
17703
17704 -static void set_gdt(void *newgdt, __u16 limit)
17705 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17706 {
17707 struct desc_ptr curgdt;
17708
17709 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17710 }
17711
17712 control_page = page_address(image->control_code_page);
17713 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17714 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17715
17716 relocate_kernel_ptr = control_page;
17717 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17718 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17719 index 3ca42d0..79d24cd 100644
17720 --- a/arch/x86/kernel/microcode_intel.c
17721 +++ b/arch/x86/kernel/microcode_intel.c
17722 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17723 return ret;
17724 }
17725
17726 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17727 static int get_ucode_user(void *to, const void *from, size_t n)
17728 {
17729 - return copy_from_user(to, from, n);
17730 + return copy_from_user(to, (const void __force_user *)from, n);
17731 }
17732
17733 static enum ucode_state
17734 request_microcode_user(int cpu, const void __user *buf, size_t size)
17735 {
17736 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17737 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17738 }
17739
17740 static void microcode_fini_cpu(int cpu)
17741 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17742 index 925179f..1f0d561 100644
17743 --- a/arch/x86/kernel/module.c
17744 +++ b/arch/x86/kernel/module.c
17745 @@ -36,15 +36,61 @@
17746 #define DEBUGP(fmt...)
17747 #endif
17748
17749 -void *module_alloc(unsigned long size)
17750 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
17751 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17752 {
17753 - if (PAGE_ALIGN(size) > MODULES_LEN)
17754 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17755 return NULL;
17756 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17757 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17758 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17759 -1, __builtin_return_address(0));
17760 }
17761
17762 +void *module_alloc(unsigned long size)
17763 +{
17764 +
17765 +#ifdef CONFIG_PAX_KERNEXEC
17766 + return __module_alloc(size, PAGE_KERNEL);
17767 +#else
17768 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17769 +#endif
17770 +
17771 +}
17772 +
17773 +#ifdef CONFIG_PAX_KERNEXEC
17774 +#ifdef CONFIG_X86_32
17775 +void *module_alloc_exec(unsigned long size)
17776 +{
17777 + struct vm_struct *area;
17778 +
17779 + if (size == 0)
17780 + return NULL;
17781 +
17782 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17783 + return area ? area->addr : NULL;
17784 +}
17785 +EXPORT_SYMBOL(module_alloc_exec);
17786 +
17787 +void module_free_exec(struct module *mod, void *module_region)
17788 +{
17789 + vunmap(module_region);
17790 +}
17791 +EXPORT_SYMBOL(module_free_exec);
17792 +#else
17793 +void module_free_exec(struct module *mod, void *module_region)
17794 +{
17795 + module_free(mod, module_region);
17796 +}
17797 +EXPORT_SYMBOL(module_free_exec);
17798 +
17799 +void *module_alloc_exec(unsigned long size)
17800 +{
17801 + return __module_alloc(size, PAGE_KERNEL_RX);
17802 +}
17803 +EXPORT_SYMBOL(module_alloc_exec);
17804 +#endif
17805 +#endif
17806 +
17807 #ifdef CONFIG_X86_32
17808 int apply_relocate(Elf32_Shdr *sechdrs,
17809 const char *strtab,
17810 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17811 unsigned int i;
17812 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17813 Elf32_Sym *sym;
17814 - uint32_t *location;
17815 + uint32_t *plocation, location;
17816
17817 DEBUGP("Applying relocate section %u to %u\n", relsec,
17818 sechdrs[relsec].sh_info);
17819 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17820 /* This is where to make the change */
17821 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17822 - + rel[i].r_offset;
17823 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17824 + location = (uint32_t)plocation;
17825 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17826 + plocation = ktla_ktva((void *)plocation);
17827 /* This is the symbol it is referring to. Note that all
17828 undefined symbols have been resolved. */
17829 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17830 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17831 switch (ELF32_R_TYPE(rel[i].r_info)) {
17832 case R_386_32:
17833 /* We add the value into the location given */
17834 - *location += sym->st_value;
17835 + pax_open_kernel();
17836 + *plocation += sym->st_value;
17837 + pax_close_kernel();
17838 break;
17839 case R_386_PC32:
17840 /* Add the value, subtract its postition */
17841 - *location += sym->st_value - (uint32_t)location;
17842 + pax_open_kernel();
17843 + *plocation += sym->st_value - location;
17844 + pax_close_kernel();
17845 break;
17846 default:
17847 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17848 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17849 case R_X86_64_NONE:
17850 break;
17851 case R_X86_64_64:
17852 + pax_open_kernel();
17853 *(u64 *)loc = val;
17854 + pax_close_kernel();
17855 break;
17856 case R_X86_64_32:
17857 + pax_open_kernel();
17858 *(u32 *)loc = val;
17859 + pax_close_kernel();
17860 if (val != *(u32 *)loc)
17861 goto overflow;
17862 break;
17863 case R_X86_64_32S:
17864 + pax_open_kernel();
17865 *(s32 *)loc = val;
17866 + pax_close_kernel();
17867 if ((s64)val != *(s32 *)loc)
17868 goto overflow;
17869 break;
17870 case R_X86_64_PC32:
17871 val -= (u64)loc;
17872 + pax_open_kernel();
17873 *(u32 *)loc = val;
17874 + pax_close_kernel();
17875 +
17876 #if 0
17877 if ((s64)val != *(s32 *)loc)
17878 goto overflow;
17879 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17880 index 47acaf3..ec48ab6 100644
17881 --- a/arch/x86/kernel/nmi.c
17882 +++ b/arch/x86/kernel/nmi.c
17883 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17884 dotraplinkage notrace __kprobes void
17885 do_nmi(struct pt_regs *regs, long error_code)
17886 {
17887 +
17888 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17889 + if (!user_mode(regs)) {
17890 + unsigned long cs = regs->cs & 0xFFFF;
17891 + unsigned long ip = ktva_ktla(regs->ip);
17892 +
17893 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17894 + regs->ip = ip;
17895 + }
17896 +#endif
17897 +
17898 nmi_nesting_preprocess(regs);
17899
17900 nmi_enter();
17901 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17902 index 676b8c7..870ba04 100644
17903 --- a/arch/x86/kernel/paravirt-spinlocks.c
17904 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17905 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17906 arch_spin_lock(lock);
17907 }
17908
17909 -struct pv_lock_ops pv_lock_ops = {
17910 +struct pv_lock_ops pv_lock_ops __read_only = {
17911 #ifdef CONFIG_SMP
17912 .spin_is_locked = __ticket_spin_is_locked,
17913 .spin_is_contended = __ticket_spin_is_contended,
17914 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17915 index d90272e..6bb013b 100644
17916 --- a/arch/x86/kernel/paravirt.c
17917 +++ b/arch/x86/kernel/paravirt.c
17918 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17919 {
17920 return x;
17921 }
17922 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17923 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17924 +#endif
17925
17926 void __init default_banner(void)
17927 {
17928 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17929 if (opfunc == NULL)
17930 /* If there's no function, patch it with a ud2a (BUG) */
17931 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17932 - else if (opfunc == _paravirt_nop)
17933 + else if (opfunc == (void *)_paravirt_nop)
17934 /* If the operation is a nop, then nop the callsite */
17935 ret = paravirt_patch_nop();
17936
17937 /* identity functions just return their single argument */
17938 - else if (opfunc == _paravirt_ident_32)
17939 + else if (opfunc == (void *)_paravirt_ident_32)
17940 ret = paravirt_patch_ident_32(insnbuf, len);
17941 - else if (opfunc == _paravirt_ident_64)
17942 + else if (opfunc == (void *)_paravirt_ident_64)
17943 ret = paravirt_patch_ident_64(insnbuf, len);
17944 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17945 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17946 + ret = paravirt_patch_ident_64(insnbuf, len);
17947 +#endif
17948
17949 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17950 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17951 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17952 if (insn_len > len || start == NULL)
17953 insn_len = len;
17954 else
17955 - memcpy(insnbuf, start, insn_len);
17956 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17957
17958 return insn_len;
17959 }
17960 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17961 preempt_enable();
17962 }
17963
17964 -struct pv_info pv_info = {
17965 +struct pv_info pv_info __read_only = {
17966 .name = "bare hardware",
17967 .paravirt_enabled = 0,
17968 .kernel_rpl = 0,
17969 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17970 #endif
17971 };
17972
17973 -struct pv_init_ops pv_init_ops = {
17974 +struct pv_init_ops pv_init_ops __read_only = {
17975 .patch = native_patch,
17976 };
17977
17978 -struct pv_time_ops pv_time_ops = {
17979 +struct pv_time_ops pv_time_ops __read_only = {
17980 .sched_clock = native_sched_clock,
17981 .steal_clock = native_steal_clock,
17982 };
17983
17984 -struct pv_irq_ops pv_irq_ops = {
17985 +struct pv_irq_ops pv_irq_ops __read_only = {
17986 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17987 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17988 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17989 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17990 #endif
17991 };
17992
17993 -struct pv_cpu_ops pv_cpu_ops = {
17994 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17995 .cpuid = native_cpuid,
17996 .get_debugreg = native_get_debugreg,
17997 .set_debugreg = native_set_debugreg,
17998 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17999 .end_context_switch = paravirt_nop,
18000 };
18001
18002 -struct pv_apic_ops pv_apic_ops = {
18003 +struct pv_apic_ops pv_apic_ops __read_only = {
18004 #ifdef CONFIG_X86_LOCAL_APIC
18005 .startup_ipi_hook = paravirt_nop,
18006 #endif
18007 };
18008
18009 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18010 +#ifdef CONFIG_X86_32
18011 +#ifdef CONFIG_X86_PAE
18012 +/* 64-bit pagetable entries */
18013 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18014 +#else
18015 /* 32-bit pagetable entries */
18016 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18017 +#endif
18018 #else
18019 /* 64-bit pagetable entries */
18020 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18021 #endif
18022
18023 -struct pv_mmu_ops pv_mmu_ops = {
18024 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18025
18026 .read_cr2 = native_read_cr2,
18027 .write_cr2 = native_write_cr2,
18028 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18029 .make_pud = PTE_IDENT,
18030
18031 .set_pgd = native_set_pgd,
18032 + .set_pgd_batched = native_set_pgd_batched,
18033 #endif
18034 #endif /* PAGETABLE_LEVELS >= 3 */
18035
18036 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18037 },
18038
18039 .set_fixmap = native_set_fixmap,
18040 +
18041 +#ifdef CONFIG_PAX_KERNEXEC
18042 + .pax_open_kernel = native_pax_open_kernel,
18043 + .pax_close_kernel = native_pax_close_kernel,
18044 +#endif
18045 +
18046 };
18047
18048 EXPORT_SYMBOL_GPL(pv_time_ops);
18049 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18050 index 35ccf75..7a15747 100644
18051 --- a/arch/x86/kernel/pci-iommu_table.c
18052 +++ b/arch/x86/kernel/pci-iommu_table.c
18053 @@ -2,7 +2,7 @@
18054 #include <asm/iommu_table.h>
18055 #include <linux/string.h>
18056 #include <linux/kallsyms.h>
18057 -
18058 +#include <linux/sched.h>
18059
18060 #define DEBUG 1
18061
18062 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18063 index 15763af..da59ada 100644
18064 --- a/arch/x86/kernel/process.c
18065 +++ b/arch/x86/kernel/process.c
18066 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18067
18068 void free_thread_info(struct thread_info *ti)
18069 {
18070 - free_thread_xstate(ti->task);
18071 free_pages((unsigned long)ti, THREAD_ORDER);
18072 }
18073
18074 +static struct kmem_cache *task_struct_cachep;
18075 +
18076 void arch_task_cache_init(void)
18077 {
18078 - task_xstate_cachep =
18079 - kmem_cache_create("task_xstate", xstate_size,
18080 + /* create a slab on which task_structs can be allocated */
18081 + task_struct_cachep =
18082 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18083 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18084 +
18085 + task_xstate_cachep =
18086 + kmem_cache_create("task_xstate", xstate_size,
18087 __alignof__(union thread_xstate),
18088 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18089 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18090 +}
18091 +
18092 +struct task_struct *alloc_task_struct_node(int node)
18093 +{
18094 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18095 +}
18096 +
18097 +void free_task_struct(struct task_struct *task)
18098 +{
18099 + free_thread_xstate(task);
18100 + kmem_cache_free(task_struct_cachep, task);
18101 }
18102
18103 /*
18104 @@ -70,7 +87,7 @@ void exit_thread(void)
18105 unsigned long *bp = t->io_bitmap_ptr;
18106
18107 if (bp) {
18108 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18109 + struct tss_struct *tss = init_tss + get_cpu();
18110
18111 t->io_bitmap_ptr = NULL;
18112 clear_thread_flag(TIF_IO_BITMAP);
18113 @@ -106,7 +123,7 @@ void show_regs_common(void)
18114
18115 printk(KERN_CONT "\n");
18116 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18117 - current->pid, current->comm, print_tainted(),
18118 + task_pid_nr(current), current->comm, print_tainted(),
18119 init_utsname()->release,
18120 (int)strcspn(init_utsname()->version, " "),
18121 init_utsname()->version);
18122 @@ -120,6 +137,9 @@ void flush_thread(void)
18123 {
18124 struct task_struct *tsk = current;
18125
18126 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18127 + loadsegment(gs, 0);
18128 +#endif
18129 flush_ptrace_hw_breakpoint(tsk);
18130 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18131 /*
18132 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18133 regs.di = (unsigned long) arg;
18134
18135 #ifdef CONFIG_X86_32
18136 - regs.ds = __USER_DS;
18137 - regs.es = __USER_DS;
18138 + regs.ds = __KERNEL_DS;
18139 + regs.es = __KERNEL_DS;
18140 regs.fs = __KERNEL_PERCPU;
18141 - regs.gs = __KERNEL_STACK_CANARY;
18142 + savesegment(gs, regs.gs);
18143 #else
18144 regs.ss = __KERNEL_DS;
18145 #endif
18146 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18147
18148 return ret;
18149 }
18150 -void stop_this_cpu(void *dummy)
18151 +__noreturn void stop_this_cpu(void *dummy)
18152 {
18153 local_irq_disable();
18154 /*
18155 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18156 }
18157 early_param("idle", idle_setup);
18158
18159 -unsigned long arch_align_stack(unsigned long sp)
18160 +#ifdef CONFIG_PAX_RANDKSTACK
18161 +void pax_randomize_kstack(struct pt_regs *regs)
18162 {
18163 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18164 - sp -= get_random_int() % 8192;
18165 - return sp & ~0xf;
18166 -}
18167 + struct thread_struct *thread = &current->thread;
18168 + unsigned long time;
18169
18170 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18171 -{
18172 - unsigned long range_end = mm->brk + 0x02000000;
18173 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18174 -}
18175 + if (!randomize_va_space)
18176 + return;
18177 +
18178 + if (v8086_mode(regs))
18179 + return;
18180
18181 + rdtscl(time);
18182 +
18183 + /* P4 seems to return a 0 LSB, ignore it */
18184 +#ifdef CONFIG_MPENTIUM4
18185 + time &= 0x3EUL;
18186 + time <<= 2;
18187 +#elif defined(CONFIG_X86_64)
18188 + time &= 0xFUL;
18189 + time <<= 4;
18190 +#else
18191 + time &= 0x1FUL;
18192 + time <<= 3;
18193 +#endif
18194 +
18195 + thread->sp0 ^= time;
18196 + load_sp0(init_tss + smp_processor_id(), thread);
18197 +
18198 +#ifdef CONFIG_X86_64
18199 + percpu_write(kernel_stack, thread->sp0);
18200 +#endif
18201 +}
18202 +#endif
18203 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18204 index c08d1ff..6ae1c81 100644
18205 --- a/arch/x86/kernel/process_32.c
18206 +++ b/arch/x86/kernel/process_32.c
18207 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18208 unsigned long thread_saved_pc(struct task_struct *tsk)
18209 {
18210 return ((unsigned long *)tsk->thread.sp)[3];
18211 +//XXX return tsk->thread.eip;
18212 }
18213
18214 #ifndef CONFIG_SMP
18215 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18216 unsigned long sp;
18217 unsigned short ss, gs;
18218
18219 - if (user_mode_vm(regs)) {
18220 + if (user_mode(regs)) {
18221 sp = regs->sp;
18222 ss = regs->ss & 0xffff;
18223 - gs = get_user_gs(regs);
18224 } else {
18225 sp = kernel_stack_pointer(regs);
18226 savesegment(ss, ss);
18227 - savesegment(gs, gs);
18228 }
18229 + gs = get_user_gs(regs);
18230
18231 show_regs_common();
18232
18233 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18234 struct task_struct *tsk;
18235 int err;
18236
18237 - childregs = task_pt_regs(p);
18238 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18239 *childregs = *regs;
18240 childregs->ax = 0;
18241 childregs->sp = sp;
18242
18243 p->thread.sp = (unsigned long) childregs;
18244 p->thread.sp0 = (unsigned long) (childregs+1);
18245 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18246
18247 p->thread.ip = (unsigned long) ret_from_fork;
18248
18249 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18250 struct thread_struct *prev = &prev_p->thread,
18251 *next = &next_p->thread;
18252 int cpu = smp_processor_id();
18253 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18254 + struct tss_struct *tss = init_tss + cpu;
18255 fpu_switch_t fpu;
18256
18257 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18258 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18259 */
18260 lazy_save_gs(prev->gs);
18261
18262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18263 + __set_fs(task_thread_info(next_p)->addr_limit);
18264 +#endif
18265 +
18266 /*
18267 * Load the per-thread Thread-Local Storage descriptor.
18268 */
18269 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18270 */
18271 arch_end_context_switch(next_p);
18272
18273 + percpu_write(current_task, next_p);
18274 + percpu_write(current_tinfo, &next_p->tinfo);
18275 +
18276 /*
18277 * Restore %gs if needed (which is common)
18278 */
18279 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18280
18281 switch_fpu_finish(next_p, fpu);
18282
18283 - percpu_write(current_task, next_p);
18284 -
18285 return prev_p;
18286 }
18287
18288 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18289 } while (count++ < 16);
18290 return 0;
18291 }
18292 -
18293 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18294 index cfa5c90..4facd28 100644
18295 --- a/arch/x86/kernel/process_64.c
18296 +++ b/arch/x86/kernel/process_64.c
18297 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18298 void exit_idle(void)
18299 {
18300 /* idle loop has pid 0 */
18301 - if (current->pid)
18302 + if (task_pid_nr(current))
18303 return;
18304 __exit_idle();
18305 }
18306 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18307 struct pt_regs *childregs;
18308 struct task_struct *me = current;
18309
18310 - childregs = ((struct pt_regs *)
18311 - (THREAD_SIZE + task_stack_page(p))) - 1;
18312 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18313 *childregs = *regs;
18314
18315 childregs->ax = 0;
18316 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18317 p->thread.sp = (unsigned long) childregs;
18318 p->thread.sp0 = (unsigned long) (childregs+1);
18319 p->thread.usersp = me->thread.usersp;
18320 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18321
18322 set_tsk_thread_flag(p, TIF_FORK);
18323
18324 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18325 struct thread_struct *prev = &prev_p->thread;
18326 struct thread_struct *next = &next_p->thread;
18327 int cpu = smp_processor_id();
18328 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18329 + struct tss_struct *tss = init_tss + cpu;
18330 unsigned fsindex, gsindex;
18331 fpu_switch_t fpu;
18332
18333 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18334 prev->usersp = percpu_read(old_rsp);
18335 percpu_write(old_rsp, next->usersp);
18336 percpu_write(current_task, next_p);
18337 + percpu_write(current_tinfo, &next_p->tinfo);
18338
18339 - percpu_write(kernel_stack,
18340 - (unsigned long)task_stack_page(next_p) +
18341 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18342 + percpu_write(kernel_stack, next->sp0);
18343
18344 /*
18345 * Now maybe reload the debug registers and handle I/O bitmaps
18346 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18347 if (!p || p == current || p->state == TASK_RUNNING)
18348 return 0;
18349 stack = (unsigned long)task_stack_page(p);
18350 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18351 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18352 return 0;
18353 fp = *(u64 *)(p->thread.sp);
18354 do {
18355 - if (fp < (unsigned long)stack ||
18356 - fp >= (unsigned long)stack+THREAD_SIZE)
18357 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18358 return 0;
18359 ip = *(u64 *)(fp+8);
18360 if (!in_sched_functions(ip))
18361 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18362 index 5026738..e1b5aa8 100644
18363 --- a/arch/x86/kernel/ptrace.c
18364 +++ b/arch/x86/kernel/ptrace.c
18365 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18366 static int ioperm_get(struct task_struct *target,
18367 const struct user_regset *regset,
18368 unsigned int pos, unsigned int count,
18369 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18370 +static int ioperm_get(struct task_struct *target,
18371 + const struct user_regset *regset,
18372 + unsigned int pos, unsigned int count,
18373 void *kbuf, void __user *ubuf)
18374 {
18375 if (!target->thread.io_bitmap_ptr)
18376 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
18377 unsigned long addr, unsigned long data)
18378 {
18379 int ret;
18380 - unsigned long __user *datap = (unsigned long __user *)data;
18381 + unsigned long __user *datap = (__force unsigned long __user *)data;
18382
18383 switch (request) {
18384 /* read the word at location addr in the USER area. */
18385 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
18386 if ((int) addr < 0)
18387 return -EIO;
18388 ret = do_get_thread_area(child, addr,
18389 - (struct user_desc __user *)data);
18390 + (__force struct user_desc __user *) data);
18391 break;
18392
18393 case PTRACE_SET_THREAD_AREA:
18394 if ((int) addr < 0)
18395 return -EIO;
18396 ret = do_set_thread_area(child, addr,
18397 - (struct user_desc __user *)data, 0);
18398 + (__force struct user_desc __user *) data, 0);
18399 break;
18400 #endif
18401
18402 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18403 memset(info, 0, sizeof(*info));
18404 info->si_signo = SIGTRAP;
18405 info->si_code = si_code;
18406 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18407 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18408 }
18409
18410 void user_single_step_siginfo(struct task_struct *tsk,
18411 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18412 index 42eb330..139955c 100644
18413 --- a/arch/x86/kernel/pvclock.c
18414 +++ b/arch/x86/kernel/pvclock.c
18415 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18416 return pv_tsc_khz;
18417 }
18418
18419 -static atomic64_t last_value = ATOMIC64_INIT(0);
18420 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18421
18422 void pvclock_resume(void)
18423 {
18424 - atomic64_set(&last_value, 0);
18425 + atomic64_set_unchecked(&last_value, 0);
18426 }
18427
18428 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18429 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18430 * updating at the same time, and one of them could be slightly behind,
18431 * making the assumption that last_value always go forward fail to hold.
18432 */
18433 - last = atomic64_read(&last_value);
18434 + last = atomic64_read_unchecked(&last_value);
18435 do {
18436 if (ret < last)
18437 return last;
18438 - last = atomic64_cmpxchg(&last_value, last, ret);
18439 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18440 } while (unlikely(last != ret));
18441
18442 return ret;
18443 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18444 index d840e69..98e9581 100644
18445 --- a/arch/x86/kernel/reboot.c
18446 +++ b/arch/x86/kernel/reboot.c
18447 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18448 EXPORT_SYMBOL(pm_power_off);
18449
18450 static const struct desc_ptr no_idt = {};
18451 -static int reboot_mode;
18452 +static unsigned short reboot_mode;
18453 enum reboot_type reboot_type = BOOT_ACPI;
18454 int reboot_force;
18455
18456 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18457 extern const unsigned char machine_real_restart_asm[];
18458 extern const u64 machine_real_restart_gdt[3];
18459
18460 -void machine_real_restart(unsigned int type)
18461 +__noreturn void machine_real_restart(unsigned int type)
18462 {
18463 void *restart_va;
18464 unsigned long restart_pa;
18465 - void (*restart_lowmem)(unsigned int);
18466 + void (* __noreturn restart_lowmem)(unsigned int);
18467 u64 *lowmem_gdt;
18468
18469 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18470 + struct desc_struct *gdt;
18471 +#endif
18472 +
18473 local_irq_disable();
18474
18475 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18476 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18477 boot)". This seems like a fairly standard thing that gets set by
18478 REBOOT.COM programs, and the previous reset routine did this
18479 too. */
18480 - *((unsigned short *)0x472) = reboot_mode;
18481 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18482
18483 /* Patch the GDT in the low memory trampoline */
18484 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18485
18486 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18487 restart_pa = virt_to_phys(restart_va);
18488 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18489 + restart_lowmem = (void *)restart_pa;
18490
18491 /* GDT[0]: GDT self-pointer */
18492 lowmem_gdt[0] =
18493 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18494 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18495
18496 /* Jump to the identity-mapped low memory code */
18497 +
18498 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18499 + gdt = get_cpu_gdt_table(smp_processor_id());
18500 + pax_open_kernel();
18501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18502 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18503 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18504 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18505 +#endif
18506 +#ifdef CONFIG_PAX_KERNEXEC
18507 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18508 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18509 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18510 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18511 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18512 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18513 +#endif
18514 + pax_close_kernel();
18515 +#endif
18516 +
18517 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18518 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18519 + unreachable();
18520 +#else
18521 restart_lowmem(type);
18522 +#endif
18523 +
18524 }
18525 #ifdef CONFIG_APM_MODULE
18526 EXPORT_SYMBOL(machine_real_restart);
18527 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18528 * try to force a triple fault and then cycle between hitting the keyboard
18529 * controller and doing that
18530 */
18531 -static void native_machine_emergency_restart(void)
18532 +__noreturn static void native_machine_emergency_restart(void)
18533 {
18534 int i;
18535 int attempt = 0;
18536 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18537 #endif
18538 }
18539
18540 -static void __machine_emergency_restart(int emergency)
18541 +static __noreturn void __machine_emergency_restart(int emergency)
18542 {
18543 reboot_emergency = emergency;
18544 machine_ops.emergency_restart();
18545 }
18546
18547 -static void native_machine_restart(char *__unused)
18548 +static __noreturn void native_machine_restart(char *__unused)
18549 {
18550 printk("machine restart\n");
18551
18552 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18553 __machine_emergency_restart(0);
18554 }
18555
18556 -static void native_machine_halt(void)
18557 +static __noreturn void native_machine_halt(void)
18558 {
18559 /* stop other cpus and apics */
18560 machine_shutdown();
18561 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18562 stop_this_cpu(NULL);
18563 }
18564
18565 -static void native_machine_power_off(void)
18566 +__noreturn static void native_machine_power_off(void)
18567 {
18568 if (pm_power_off) {
18569 if (!reboot_force)
18570 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18571 }
18572 /* a fallback in case there is no PM info available */
18573 tboot_shutdown(TB_SHUTDOWN_HALT);
18574 + unreachable();
18575 }
18576
18577 struct machine_ops machine_ops = {
18578 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18579 index 7a6f3b3..bed145d7 100644
18580 --- a/arch/x86/kernel/relocate_kernel_64.S
18581 +++ b/arch/x86/kernel/relocate_kernel_64.S
18582 @@ -11,6 +11,7 @@
18583 #include <asm/kexec.h>
18584 #include <asm/processor-flags.h>
18585 #include <asm/pgtable_types.h>
18586 +#include <asm/alternative-asm.h>
18587
18588 /*
18589 * Must be relocatable PIC code callable as a C function
18590 @@ -160,13 +161,14 @@ identity_mapped:
18591 xorq %rbp, %rbp
18592 xorq %r8, %r8
18593 xorq %r9, %r9
18594 - xorq %r10, %r9
18595 + xorq %r10, %r10
18596 xorq %r11, %r11
18597 xorq %r12, %r12
18598 xorq %r13, %r13
18599 xorq %r14, %r14
18600 xorq %r15, %r15
18601
18602 + pax_force_retaddr 0, 1
18603 ret
18604
18605 1:
18606 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18607 index d7d5099..28555d0 100644
18608 --- a/arch/x86/kernel/setup.c
18609 +++ b/arch/x86/kernel/setup.c
18610 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18611
18612 switch (data->type) {
18613 case SETUP_E820_EXT:
18614 - parse_e820_ext(data);
18615 + parse_e820_ext((struct setup_data __force_kernel *)data);
18616 break;
18617 case SETUP_DTB:
18618 add_dtb(pa_data);
18619 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18620 * area (640->1Mb) as ram even though it is not.
18621 * take them out.
18622 */
18623 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18624 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18625 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18626 }
18627
18628 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18629
18630 if (!boot_params.hdr.root_flags)
18631 root_mountflags &= ~MS_RDONLY;
18632 - init_mm.start_code = (unsigned long) _text;
18633 - init_mm.end_code = (unsigned long) _etext;
18634 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18635 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18636 init_mm.end_data = (unsigned long) _edata;
18637 init_mm.brk = _brk_end;
18638
18639 - code_resource.start = virt_to_phys(_text);
18640 - code_resource.end = virt_to_phys(_etext)-1;
18641 - data_resource.start = virt_to_phys(_etext);
18642 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18643 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18644 + data_resource.start = virt_to_phys(_sdata);
18645 data_resource.end = virt_to_phys(_edata)-1;
18646 bss_resource.start = virt_to_phys(&__bss_start);
18647 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18648 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18649 index 71f4727..217419b 100644
18650 --- a/arch/x86/kernel/setup_percpu.c
18651 +++ b/arch/x86/kernel/setup_percpu.c
18652 @@ -21,19 +21,17 @@
18653 #include <asm/cpu.h>
18654 #include <asm/stackprotector.h>
18655
18656 -DEFINE_PER_CPU(int, cpu_number);
18657 +#ifdef CONFIG_SMP
18658 +DEFINE_PER_CPU(unsigned int, cpu_number);
18659 EXPORT_PER_CPU_SYMBOL(cpu_number);
18660 +#endif
18661
18662 -#ifdef CONFIG_X86_64
18663 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18664 -#else
18665 -#define BOOT_PERCPU_OFFSET 0
18666 -#endif
18667
18668 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18669 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18670
18671 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18672 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18673 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18674 };
18675 EXPORT_SYMBOL(__per_cpu_offset);
18676 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18677 * Pointer to the allocated area on success, NULL on failure.
18678 */
18679 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18680 + unsigned long align) __size_overflow(2);
18681 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18682 unsigned long align)
18683 {
18684 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18685 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18686 /*
18687 * Helpers for first chunk memory allocation
18688 */
18689 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18690 +
18691 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18692 {
18693 return pcpu_alloc_bootmem(cpu, size, align);
18694 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18695 {
18696 #ifdef CONFIG_X86_32
18697 struct desc_struct gdt;
18698 + unsigned long base = per_cpu_offset(cpu);
18699
18700 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18701 - 0x2 | DESCTYPE_S, 0x8);
18702 - gdt.s = 1;
18703 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18704 + 0x83 | DESCTYPE_S, 0xC);
18705 write_gdt_entry(get_cpu_gdt_table(cpu),
18706 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18707 #endif
18708 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18709 /* alrighty, percpu areas up and running */
18710 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18711 for_each_possible_cpu(cpu) {
18712 +#ifdef CONFIG_CC_STACKPROTECTOR
18713 +#ifdef CONFIG_X86_32
18714 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18715 +#endif
18716 +#endif
18717 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18718 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18719 per_cpu(cpu_number, cpu) = cpu;
18720 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18721 */
18722 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18723 #endif
18724 +#ifdef CONFIG_CC_STACKPROTECTOR
18725 +#ifdef CONFIG_X86_32
18726 + if (!cpu)
18727 + per_cpu(stack_canary.canary, cpu) = canary;
18728 +#endif
18729 +#endif
18730 /*
18731 * Up to this point, the boot CPU has been using .init.data
18732 * area. Reload any changed state for the boot CPU.
18733 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18734 index 46a01bd..2e88e6d 100644
18735 --- a/arch/x86/kernel/signal.c
18736 +++ b/arch/x86/kernel/signal.c
18737 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18738 * Align the stack pointer according to the i386 ABI,
18739 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18740 */
18741 - sp = ((sp + 4) & -16ul) - 4;
18742 + sp = ((sp - 12) & -16ul) - 4;
18743 #else /* !CONFIG_X86_32 */
18744 sp = round_down(sp, 16) - 8;
18745 #endif
18746 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18747 * Return an always-bogus address instead so we will die with SIGSEGV.
18748 */
18749 if (onsigstack && !likely(on_sig_stack(sp)))
18750 - return (void __user *)-1L;
18751 + return (__force void __user *)-1L;
18752
18753 /* save i387 state */
18754 if (used_math() && save_i387_xstate(*fpstate) < 0)
18755 - return (void __user *)-1L;
18756 + return (__force void __user *)-1L;
18757
18758 return (void __user *)sp;
18759 }
18760 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18761 }
18762
18763 if (current->mm->context.vdso)
18764 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18765 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18766 else
18767 - restorer = &frame->retcode;
18768 + restorer = (void __user *)&frame->retcode;
18769 if (ka->sa.sa_flags & SA_RESTORER)
18770 restorer = ka->sa.sa_restorer;
18771
18772 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18773 * reasons and because gdb uses it as a signature to notice
18774 * signal handler stack frames.
18775 */
18776 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18777 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18778
18779 if (err)
18780 return -EFAULT;
18781 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18782 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18783
18784 /* Set up to return from userspace. */
18785 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18786 + if (current->mm->context.vdso)
18787 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18788 + else
18789 + restorer = (void __user *)&frame->retcode;
18790 if (ka->sa.sa_flags & SA_RESTORER)
18791 restorer = ka->sa.sa_restorer;
18792 put_user_ex(restorer, &frame->pretcode);
18793 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18794 * reasons and because gdb uses it as a signature to notice
18795 * signal handler stack frames.
18796 */
18797 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18798 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18799 } put_user_catch(err);
18800
18801 if (err)
18802 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18803 * X86_32: vm86 regs switched out by assembly code before reaching
18804 * here, so testing against kernel CS suffices.
18805 */
18806 - if (!user_mode(regs))
18807 + if (!user_mode_novm(regs))
18808 return;
18809
18810 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18811 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18812 index 66d250c..f1b10bd 100644
18813 --- a/arch/x86/kernel/smpboot.c
18814 +++ b/arch/x86/kernel/smpboot.c
18815 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18816 set_idle_for_cpu(cpu, c_idle.idle);
18817 do_rest:
18818 per_cpu(current_task, cpu) = c_idle.idle;
18819 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18820 #ifdef CONFIG_X86_32
18821 /* Stack for startup_32 can be just as for start_secondary onwards */
18822 irq_ctx_init(cpu);
18823 #else
18824 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18825 initial_gs = per_cpu_offset(cpu);
18826 - per_cpu(kernel_stack, cpu) =
18827 - (unsigned long)task_stack_page(c_idle.idle) -
18828 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18829 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18830 #endif
18831 +
18832 + pax_open_kernel();
18833 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18834 + pax_close_kernel();
18835 +
18836 initial_code = (unsigned long)start_secondary;
18837 stack_start = c_idle.idle->thread.sp;
18838
18839 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18840
18841 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18842
18843 +#ifdef CONFIG_PAX_PER_CPU_PGD
18844 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18845 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18846 + KERNEL_PGD_PTRS);
18847 +#endif
18848 +
18849 err = do_boot_cpu(apicid, cpu);
18850 if (err) {
18851 pr_debug("do_boot_cpu failed %d\n", err);
18852 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18853 index c346d11..d43b163 100644
18854 --- a/arch/x86/kernel/step.c
18855 +++ b/arch/x86/kernel/step.c
18856 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18857 struct desc_struct *desc;
18858 unsigned long base;
18859
18860 - seg &= ~7UL;
18861 + seg >>= 3;
18862
18863 mutex_lock(&child->mm->context.lock);
18864 - if (unlikely((seg >> 3) >= child->mm->context.size))
18865 + if (unlikely(seg >= child->mm->context.size))
18866 addr = -1L; /* bogus selector, access would fault */
18867 else {
18868 desc = child->mm->context.ldt + seg;
18869 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18870 addr += base;
18871 }
18872 mutex_unlock(&child->mm->context.lock);
18873 - }
18874 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18875 + addr = ktla_ktva(addr);
18876
18877 return addr;
18878 }
18879 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18880 unsigned char opcode[15];
18881 unsigned long addr = convert_ip_to_linear(child, regs);
18882
18883 + if (addr == -EINVAL)
18884 + return 0;
18885 +
18886 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18887 for (i = 0; i < copied; i++) {
18888 switch (opcode[i]) {
18889 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18890 index 0b0cb5f..db6b9ed 100644
18891 --- a/arch/x86/kernel/sys_i386_32.c
18892 +++ b/arch/x86/kernel/sys_i386_32.c
18893 @@ -24,17 +24,224 @@
18894
18895 #include <asm/syscalls.h>
18896
18897 -/*
18898 - * Do a system call from kernel instead of calling sys_execve so we
18899 - * end up with proper pt_regs.
18900 - */
18901 -int kernel_execve(const char *filename,
18902 - const char *const argv[],
18903 - const char *const envp[])
18904 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18905 {
18906 - long __res;
18907 - asm volatile ("int $0x80"
18908 - : "=a" (__res)
18909 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18910 - return __res;
18911 + unsigned long pax_task_size = TASK_SIZE;
18912 +
18913 +#ifdef CONFIG_PAX_SEGMEXEC
18914 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18915 + pax_task_size = SEGMEXEC_TASK_SIZE;
18916 +#endif
18917 +
18918 + if (len > pax_task_size || addr > pax_task_size - len)
18919 + return -EINVAL;
18920 +
18921 + return 0;
18922 +}
18923 +
18924 +unsigned long
18925 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18926 + unsigned long len, unsigned long pgoff, unsigned long flags)
18927 +{
18928 + struct mm_struct *mm = current->mm;
18929 + struct vm_area_struct *vma;
18930 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18931 +
18932 +#ifdef CONFIG_PAX_SEGMEXEC
18933 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18934 + pax_task_size = SEGMEXEC_TASK_SIZE;
18935 +#endif
18936 +
18937 + pax_task_size -= PAGE_SIZE;
18938 +
18939 + if (len > pax_task_size)
18940 + return -ENOMEM;
18941 +
18942 + if (flags & MAP_FIXED)
18943 + return addr;
18944 +
18945 +#ifdef CONFIG_PAX_RANDMMAP
18946 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18947 +#endif
18948 +
18949 + if (addr) {
18950 + addr = PAGE_ALIGN(addr);
18951 + if (pax_task_size - len >= addr) {
18952 + vma = find_vma(mm, addr);
18953 + if (check_heap_stack_gap(vma, addr, len))
18954 + return addr;
18955 + }
18956 + }
18957 + if (len > mm->cached_hole_size) {
18958 + start_addr = addr = mm->free_area_cache;
18959 + } else {
18960 + start_addr = addr = mm->mmap_base;
18961 + mm->cached_hole_size = 0;
18962 + }
18963 +
18964 +#ifdef CONFIG_PAX_PAGEEXEC
18965 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18966 + start_addr = 0x00110000UL;
18967 +
18968 +#ifdef CONFIG_PAX_RANDMMAP
18969 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18970 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18971 +#endif
18972 +
18973 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18974 + start_addr = addr = mm->mmap_base;
18975 + else
18976 + addr = start_addr;
18977 + }
18978 +#endif
18979 +
18980 +full_search:
18981 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18982 + /* At this point: (!vma || addr < vma->vm_end). */
18983 + if (pax_task_size - len < addr) {
18984 + /*
18985 + * Start a new search - just in case we missed
18986 + * some holes.
18987 + */
18988 + if (start_addr != mm->mmap_base) {
18989 + start_addr = addr = mm->mmap_base;
18990 + mm->cached_hole_size = 0;
18991 + goto full_search;
18992 + }
18993 + return -ENOMEM;
18994 + }
18995 + if (check_heap_stack_gap(vma, addr, len))
18996 + break;
18997 + if (addr + mm->cached_hole_size < vma->vm_start)
18998 + mm->cached_hole_size = vma->vm_start - addr;
18999 + addr = vma->vm_end;
19000 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19001 + start_addr = addr = mm->mmap_base;
19002 + mm->cached_hole_size = 0;
19003 + goto full_search;
19004 + }
19005 + }
19006 +
19007 + /*
19008 + * Remember the place where we stopped the search:
19009 + */
19010 + mm->free_area_cache = addr + len;
19011 + return addr;
19012 +}
19013 +
19014 +unsigned long
19015 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19016 + const unsigned long len, const unsigned long pgoff,
19017 + const unsigned long flags)
19018 +{
19019 + struct vm_area_struct *vma;
19020 + struct mm_struct *mm = current->mm;
19021 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19022 +
19023 +#ifdef CONFIG_PAX_SEGMEXEC
19024 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19025 + pax_task_size = SEGMEXEC_TASK_SIZE;
19026 +#endif
19027 +
19028 + pax_task_size -= PAGE_SIZE;
19029 +
19030 + /* requested length too big for entire address space */
19031 + if (len > pax_task_size)
19032 + return -ENOMEM;
19033 +
19034 + if (flags & MAP_FIXED)
19035 + return addr;
19036 +
19037 +#ifdef CONFIG_PAX_PAGEEXEC
19038 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19039 + goto bottomup;
19040 +#endif
19041 +
19042 +#ifdef CONFIG_PAX_RANDMMAP
19043 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19044 +#endif
19045 +
19046 + /* requesting a specific address */
19047 + if (addr) {
19048 + addr = PAGE_ALIGN(addr);
19049 + if (pax_task_size - len >= addr) {
19050 + vma = find_vma(mm, addr);
19051 + if (check_heap_stack_gap(vma, addr, len))
19052 + return addr;
19053 + }
19054 + }
19055 +
19056 + /* check if free_area_cache is useful for us */
19057 + if (len <= mm->cached_hole_size) {
19058 + mm->cached_hole_size = 0;
19059 + mm->free_area_cache = mm->mmap_base;
19060 + }
19061 +
19062 + /* either no address requested or can't fit in requested address hole */
19063 + addr = mm->free_area_cache;
19064 +
19065 + /* make sure it can fit in the remaining address space */
19066 + if (addr > len) {
19067 + vma = find_vma(mm, addr-len);
19068 + if (check_heap_stack_gap(vma, addr - len, len))
19069 + /* remember the address as a hint for next time */
19070 + return (mm->free_area_cache = addr-len);
19071 + }
19072 +
19073 + if (mm->mmap_base < len)
19074 + goto bottomup;
19075 +
19076 + addr = mm->mmap_base-len;
19077 +
19078 + do {
19079 + /*
19080 + * Lookup failure means no vma is above this address,
19081 + * else if new region fits below vma->vm_start,
19082 + * return with success:
19083 + */
19084 + vma = find_vma(mm, addr);
19085 + if (check_heap_stack_gap(vma, addr, len))
19086 + /* remember the address as a hint for next time */
19087 + return (mm->free_area_cache = addr);
19088 +
19089 + /* remember the largest hole we saw so far */
19090 + if (addr + mm->cached_hole_size < vma->vm_start)
19091 + mm->cached_hole_size = vma->vm_start - addr;
19092 +
19093 + /* try just below the current vma->vm_start */
19094 + addr = skip_heap_stack_gap(vma, len);
19095 + } while (!IS_ERR_VALUE(addr));
19096 +
19097 +bottomup:
19098 + /*
19099 + * A failed mmap() very likely causes application failure,
19100 + * so fall back to the bottom-up function here. This scenario
19101 + * can happen with large stack limits and large mmap()
19102 + * allocations.
19103 + */
19104 +
19105 +#ifdef CONFIG_PAX_SEGMEXEC
19106 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19107 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19108 + else
19109 +#endif
19110 +
19111 + mm->mmap_base = TASK_UNMAPPED_BASE;
19112 +
19113 +#ifdef CONFIG_PAX_RANDMMAP
19114 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19115 + mm->mmap_base += mm->delta_mmap;
19116 +#endif
19117 +
19118 + mm->free_area_cache = mm->mmap_base;
19119 + mm->cached_hole_size = ~0UL;
19120 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19121 + /*
19122 + * Restore the topdown base:
19123 + */
19124 + mm->mmap_base = base;
19125 + mm->free_area_cache = base;
19126 + mm->cached_hole_size = ~0UL;
19127 +
19128 + return addr;
19129 }
19130 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19131 index 0514890..3dbebce 100644
19132 --- a/arch/x86/kernel/sys_x86_64.c
19133 +++ b/arch/x86/kernel/sys_x86_64.c
19134 @@ -95,8 +95,8 @@ out:
19135 return error;
19136 }
19137
19138 -static void find_start_end(unsigned long flags, unsigned long *begin,
19139 - unsigned long *end)
19140 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19141 + unsigned long *begin, unsigned long *end)
19142 {
19143 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19144 unsigned long new_begin;
19145 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19146 *begin = new_begin;
19147 }
19148 } else {
19149 - *begin = TASK_UNMAPPED_BASE;
19150 + *begin = mm->mmap_base;
19151 *end = TASK_SIZE;
19152 }
19153 }
19154 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19155 if (flags & MAP_FIXED)
19156 return addr;
19157
19158 - find_start_end(flags, &begin, &end);
19159 + find_start_end(mm, flags, &begin, &end);
19160
19161 if (len > end)
19162 return -ENOMEM;
19163
19164 +#ifdef CONFIG_PAX_RANDMMAP
19165 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19166 +#endif
19167 +
19168 if (addr) {
19169 addr = PAGE_ALIGN(addr);
19170 vma = find_vma(mm, addr);
19171 - if (end - len >= addr &&
19172 - (!vma || addr + len <= vma->vm_start))
19173 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19174 return addr;
19175 }
19176 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19177 @@ -172,7 +175,7 @@ full_search:
19178 }
19179 return -ENOMEM;
19180 }
19181 - if (!vma || addr + len <= vma->vm_start) {
19182 + if (check_heap_stack_gap(vma, addr, len)) {
19183 /*
19184 * Remember the place where we stopped the search:
19185 */
19186 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19187 {
19188 struct vm_area_struct *vma;
19189 struct mm_struct *mm = current->mm;
19190 - unsigned long addr = addr0;
19191 + unsigned long base = mm->mmap_base, addr = addr0;
19192
19193 /* requested length too big for entire address space */
19194 if (len > TASK_SIZE)
19195 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19196 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19197 goto bottomup;
19198
19199 +#ifdef CONFIG_PAX_RANDMMAP
19200 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19201 +#endif
19202 +
19203 /* requesting a specific address */
19204 if (addr) {
19205 addr = PAGE_ALIGN(addr);
19206 - vma = find_vma(mm, addr);
19207 - if (TASK_SIZE - len >= addr &&
19208 - (!vma || addr + len <= vma->vm_start))
19209 - return addr;
19210 + if (TASK_SIZE - len >= addr) {
19211 + vma = find_vma(mm, addr);
19212 + if (check_heap_stack_gap(vma, addr, len))
19213 + return addr;
19214 + }
19215 }
19216
19217 /* check if free_area_cache is useful for us */
19218 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19219 ALIGN_TOPDOWN);
19220
19221 vma = find_vma(mm, tmp_addr);
19222 - if (!vma || tmp_addr + len <= vma->vm_start)
19223 + if (check_heap_stack_gap(vma, tmp_addr, len))
19224 /* remember the address as a hint for next time */
19225 return mm->free_area_cache = tmp_addr;
19226 }
19227 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19228 * return with success:
19229 */
19230 vma = find_vma(mm, addr);
19231 - if (!vma || addr+len <= vma->vm_start)
19232 + if (check_heap_stack_gap(vma, addr, len))
19233 /* remember the address as a hint for next time */
19234 return mm->free_area_cache = addr;
19235
19236 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19237 mm->cached_hole_size = vma->vm_start - addr;
19238
19239 /* try just below the current vma->vm_start */
19240 - addr = vma->vm_start-len;
19241 - } while (len < vma->vm_start);
19242 + addr = skip_heap_stack_gap(vma, len);
19243 + } while (!IS_ERR_VALUE(addr));
19244
19245 bottomup:
19246 /*
19247 @@ -270,13 +278,21 @@ bottomup:
19248 * can happen with large stack limits and large mmap()
19249 * allocations.
19250 */
19251 + mm->mmap_base = TASK_UNMAPPED_BASE;
19252 +
19253 +#ifdef CONFIG_PAX_RANDMMAP
19254 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19255 + mm->mmap_base += mm->delta_mmap;
19256 +#endif
19257 +
19258 + mm->free_area_cache = mm->mmap_base;
19259 mm->cached_hole_size = ~0UL;
19260 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19261 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19262 /*
19263 * Restore the topdown base:
19264 */
19265 - mm->free_area_cache = mm->mmap_base;
19266 + mm->mmap_base = base;
19267 + mm->free_area_cache = base;
19268 mm->cached_hole_size = ~0UL;
19269
19270 return addr;
19271 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19272 index e2410e2..4fe3fbc 100644
19273 --- a/arch/x86/kernel/tboot.c
19274 +++ b/arch/x86/kernel/tboot.c
19275 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19276
19277 void tboot_shutdown(u32 shutdown_type)
19278 {
19279 - void (*shutdown)(void);
19280 + void (* __noreturn shutdown)(void);
19281
19282 if (!tboot_enabled())
19283 return;
19284 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19285
19286 switch_to_tboot_pt();
19287
19288 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19289 + shutdown = (void *)tboot->shutdown_entry;
19290 shutdown();
19291
19292 /* should not reach here */
19293 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19294 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19295 }
19296
19297 -static atomic_t ap_wfs_count;
19298 +static atomic_unchecked_t ap_wfs_count;
19299
19300 static int tboot_wait_for_aps(int num_aps)
19301 {
19302 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19303 {
19304 switch (action) {
19305 case CPU_DYING:
19306 - atomic_inc(&ap_wfs_count);
19307 + atomic_inc_unchecked(&ap_wfs_count);
19308 if (num_online_cpus() == 1)
19309 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19310 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19311 return NOTIFY_BAD;
19312 break;
19313 }
19314 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19315
19316 tboot_create_trampoline();
19317
19318 - atomic_set(&ap_wfs_count, 0);
19319 + atomic_set_unchecked(&ap_wfs_count, 0);
19320 register_hotcpu_notifier(&tboot_cpu_notifier);
19321 return 0;
19322 }
19323 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19324 index dd5fbf4..b7f2232 100644
19325 --- a/arch/x86/kernel/time.c
19326 +++ b/arch/x86/kernel/time.c
19327 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19328 {
19329 unsigned long pc = instruction_pointer(regs);
19330
19331 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19332 + if (!user_mode(regs) && in_lock_functions(pc)) {
19333 #ifdef CONFIG_FRAME_POINTER
19334 - return *(unsigned long *)(regs->bp + sizeof(long));
19335 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19336 #else
19337 unsigned long *sp =
19338 (unsigned long *)kernel_stack_pointer(regs);
19339 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19340 * or above a saved flags. Eflags has bits 22-31 zero,
19341 * kernel addresses don't.
19342 */
19343 +
19344 +#ifdef CONFIG_PAX_KERNEXEC
19345 + return ktla_ktva(sp[0]);
19346 +#else
19347 if (sp[0] >> 22)
19348 return sp[0];
19349 if (sp[1] >> 22)
19350 return sp[1];
19351 #endif
19352 +
19353 +#endif
19354 }
19355 return pc;
19356 }
19357 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19358 index bcfec2d..8f88b4a 100644
19359 --- a/arch/x86/kernel/tls.c
19360 +++ b/arch/x86/kernel/tls.c
19361 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19362 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19363 return -EINVAL;
19364
19365 +#ifdef CONFIG_PAX_SEGMEXEC
19366 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19367 + return -EINVAL;
19368 +#endif
19369 +
19370 set_tls_desc(p, idx, &info, 1);
19371
19372 return 0;
19373 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19374 index 2f083a2..7d3fecc 100644
19375 --- a/arch/x86/kernel/tls.h
19376 +++ b/arch/x86/kernel/tls.h
19377 @@ -16,6 +16,6 @@
19378
19379 extern user_regset_active_fn regset_tls_active;
19380 extern user_regset_get_fn regset_tls_get;
19381 -extern user_regset_set_fn regset_tls_set;
19382 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19383
19384 #endif /* _ARCH_X86_KERNEL_TLS_H */
19385 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19386 index 451c0a7..e57f551 100644
19387 --- a/arch/x86/kernel/trampoline_32.S
19388 +++ b/arch/x86/kernel/trampoline_32.S
19389 @@ -32,6 +32,12 @@
19390 #include <asm/segment.h>
19391 #include <asm/page_types.h>
19392
19393 +#ifdef CONFIG_PAX_KERNEXEC
19394 +#define ta(X) (X)
19395 +#else
19396 +#define ta(X) ((X) - __PAGE_OFFSET)
19397 +#endif
19398 +
19399 #ifdef CONFIG_SMP
19400
19401 .section ".x86_trampoline","a"
19402 @@ -62,7 +68,7 @@ r_base = .
19403 inc %ax # protected mode (PE) bit
19404 lmsw %ax # into protected mode
19405 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19406 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19407 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19408
19409 # These need to be in the same 64K segment as the above;
19410 # hence we don't use the boot_gdt_descr defined in head.S
19411 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19412 index 09ff517..df19fbff 100644
19413 --- a/arch/x86/kernel/trampoline_64.S
19414 +++ b/arch/x86/kernel/trampoline_64.S
19415 @@ -90,7 +90,7 @@ startup_32:
19416 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19417 movl %eax, %ds
19418
19419 - movl $X86_CR4_PAE, %eax
19420 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19421 movl %eax, %cr4 # Enable PAE mode
19422
19423 # Setup trampoline 4 level pagetables
19424 @@ -138,7 +138,7 @@ tidt:
19425 # so the kernel can live anywhere
19426 .balign 4
19427 tgdt:
19428 - .short tgdt_end - tgdt # gdt limit
19429 + .short tgdt_end - tgdt - 1 # gdt limit
19430 .long tgdt - r_base
19431 .short 0
19432 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19433 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19434 index 4bbe04d..41d0943 100644
19435 --- a/arch/x86/kernel/traps.c
19436 +++ b/arch/x86/kernel/traps.c
19437 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19438
19439 /* Do we ignore FPU interrupts ? */
19440 char ignore_fpu_irq;
19441 -
19442 -/*
19443 - * The IDT has to be page-aligned to simplify the Pentium
19444 - * F0 0F bug workaround.
19445 - */
19446 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19447 #endif
19448
19449 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19450 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19451 }
19452
19453 static void __kprobes
19454 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19455 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19456 long error_code, siginfo_t *info)
19457 {
19458 struct task_struct *tsk = current;
19459
19460 #ifdef CONFIG_X86_32
19461 - if (regs->flags & X86_VM_MASK) {
19462 + if (v8086_mode(regs)) {
19463 /*
19464 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19465 * On nmi (interrupt 2), do_trap should not be called.
19466 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19467 }
19468 #endif
19469
19470 - if (!user_mode(regs))
19471 + if (!user_mode_novm(regs))
19472 goto kernel_trap;
19473
19474 #ifdef CONFIG_X86_32
19475 @@ -148,7 +142,7 @@ trap_signal:
19476 printk_ratelimit()) {
19477 printk(KERN_INFO
19478 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19479 - tsk->comm, tsk->pid, str,
19480 + tsk->comm, task_pid_nr(tsk), str,
19481 regs->ip, regs->sp, error_code);
19482 print_vma_addr(" in ", regs->ip);
19483 printk("\n");
19484 @@ -165,8 +159,20 @@ kernel_trap:
19485 if (!fixup_exception(regs)) {
19486 tsk->thread.error_code = error_code;
19487 tsk->thread.trap_no = trapnr;
19488 +
19489 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19490 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19491 + str = "PAX: suspicious stack segment fault";
19492 +#endif
19493 +
19494 die(str, regs, error_code);
19495 }
19496 +
19497 +#ifdef CONFIG_PAX_REFCOUNT
19498 + if (trapnr == 4)
19499 + pax_report_refcount_overflow(regs);
19500 +#endif
19501 +
19502 return;
19503
19504 #ifdef CONFIG_X86_32
19505 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19506 conditional_sti(regs);
19507
19508 #ifdef CONFIG_X86_32
19509 - if (regs->flags & X86_VM_MASK)
19510 + if (v8086_mode(regs))
19511 goto gp_in_vm86;
19512 #endif
19513
19514 tsk = current;
19515 - if (!user_mode(regs))
19516 + if (!user_mode_novm(regs))
19517 goto gp_in_kernel;
19518
19519 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19520 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19521 + struct mm_struct *mm = tsk->mm;
19522 + unsigned long limit;
19523 +
19524 + down_write(&mm->mmap_sem);
19525 + limit = mm->context.user_cs_limit;
19526 + if (limit < TASK_SIZE) {
19527 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19528 + up_write(&mm->mmap_sem);
19529 + return;
19530 + }
19531 + up_write(&mm->mmap_sem);
19532 + }
19533 +#endif
19534 +
19535 tsk->thread.error_code = error_code;
19536 tsk->thread.trap_no = 13;
19537
19538 @@ -295,6 +317,13 @@ gp_in_kernel:
19539 if (notify_die(DIE_GPF, "general protection fault", regs,
19540 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19541 return;
19542 +
19543 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19544 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19545 + die("PAX: suspicious general protection fault", regs, error_code);
19546 + else
19547 +#endif
19548 +
19549 die("general protection fault", regs, error_code);
19550 }
19551
19552 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19553 /* It's safe to allow irq's after DR6 has been saved */
19554 preempt_conditional_sti(regs);
19555
19556 - if (regs->flags & X86_VM_MASK) {
19557 + if (v8086_mode(regs)) {
19558 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19559 error_code, 1);
19560 preempt_conditional_cli(regs);
19561 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19562 * We already checked v86 mode above, so we can check for kernel mode
19563 * by just checking the CPL of CS.
19564 */
19565 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19566 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19567 tsk->thread.debugreg6 &= ~DR_STEP;
19568 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19569 regs->flags &= ~X86_EFLAGS_TF;
19570 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19571 return;
19572 conditional_sti(regs);
19573
19574 - if (!user_mode_vm(regs))
19575 + if (!user_mode(regs))
19576 {
19577 if (!fixup_exception(regs)) {
19578 task->thread.error_code = error_code;
19579 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19580 index b9242ba..50c5edd 100644
19581 --- a/arch/x86/kernel/verify_cpu.S
19582 +++ b/arch/x86/kernel/verify_cpu.S
19583 @@ -20,6 +20,7 @@
19584 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19585 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19586 * arch/x86/kernel/head_32.S: processor startup
19587 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19588 *
19589 * verify_cpu, returns the status of longmode and SSE in register %eax.
19590 * 0: Success 1: Failure
19591 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19592 index 328cb37..f37fee1 100644
19593 --- a/arch/x86/kernel/vm86_32.c
19594 +++ b/arch/x86/kernel/vm86_32.c
19595 @@ -41,6 +41,7 @@
19596 #include <linux/ptrace.h>
19597 #include <linux/audit.h>
19598 #include <linux/stddef.h>
19599 +#include <linux/grsecurity.h>
19600
19601 #include <asm/uaccess.h>
19602 #include <asm/io.h>
19603 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
19604 /* convert vm86_regs to kernel_vm86_regs */
19605 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19606 const struct vm86_regs __user *user,
19607 + unsigned extra) __size_overflow(3);
19608 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19609 + const struct vm86_regs __user *user,
19610 unsigned extra)
19611 {
19612 int ret = 0;
19613 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19614 do_exit(SIGSEGV);
19615 }
19616
19617 - tss = &per_cpu(init_tss, get_cpu());
19618 + tss = init_tss + get_cpu();
19619 current->thread.sp0 = current->thread.saved_sp0;
19620 current->thread.sysenter_cs = __KERNEL_CS;
19621 load_sp0(tss, &current->thread);
19622 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19623 struct task_struct *tsk;
19624 int tmp, ret = -EPERM;
19625
19626 +#ifdef CONFIG_GRKERNSEC_VM86
19627 + if (!capable(CAP_SYS_RAWIO)) {
19628 + gr_handle_vm86();
19629 + goto out;
19630 + }
19631 +#endif
19632 +
19633 tsk = current;
19634 if (tsk->thread.saved_sp0)
19635 goto out;
19636 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19637 int tmp, ret;
19638 struct vm86plus_struct __user *v86;
19639
19640 +#ifdef CONFIG_GRKERNSEC_VM86
19641 + if (!capable(CAP_SYS_RAWIO)) {
19642 + gr_handle_vm86();
19643 + ret = -EPERM;
19644 + goto out;
19645 + }
19646 +#endif
19647 +
19648 tsk = current;
19649 switch (cmd) {
19650 case VM86_REQUEST_IRQ:
19651 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19652 tsk->thread.saved_fs = info->regs32->fs;
19653 tsk->thread.saved_gs = get_user_gs(info->regs32);
19654
19655 - tss = &per_cpu(init_tss, get_cpu());
19656 + tss = init_tss + get_cpu();
19657 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19658 if (cpu_has_sep)
19659 tsk->thread.sysenter_cs = 0;
19660 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19661 goto cannot_handle;
19662 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19663 goto cannot_handle;
19664 - intr_ptr = (unsigned long __user *) (i << 2);
19665 + intr_ptr = (__force unsigned long __user *) (i << 2);
19666 if (get_user(segoffs, intr_ptr))
19667 goto cannot_handle;
19668 if ((segoffs >> 16) == BIOSSEG)
19669 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19670 index 0f703f1..9e15f64 100644
19671 --- a/arch/x86/kernel/vmlinux.lds.S
19672 +++ b/arch/x86/kernel/vmlinux.lds.S
19673 @@ -26,6 +26,13 @@
19674 #include <asm/page_types.h>
19675 #include <asm/cache.h>
19676 #include <asm/boot.h>
19677 +#include <asm/segment.h>
19678 +
19679 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19680 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19681 +#else
19682 +#define __KERNEL_TEXT_OFFSET 0
19683 +#endif
19684
19685 #undef i386 /* in case the preprocessor is a 32bit one */
19686
19687 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19688
19689 PHDRS {
19690 text PT_LOAD FLAGS(5); /* R_E */
19691 +#ifdef CONFIG_X86_32
19692 + module PT_LOAD FLAGS(5); /* R_E */
19693 +#endif
19694 +#ifdef CONFIG_XEN
19695 + rodata PT_LOAD FLAGS(5); /* R_E */
19696 +#else
19697 + rodata PT_LOAD FLAGS(4); /* R__ */
19698 +#endif
19699 data PT_LOAD FLAGS(6); /* RW_ */
19700 -#ifdef CONFIG_X86_64
19701 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19702 #ifdef CONFIG_SMP
19703 percpu PT_LOAD FLAGS(6); /* RW_ */
19704 #endif
19705 + text.init PT_LOAD FLAGS(5); /* R_E */
19706 + text.exit PT_LOAD FLAGS(5); /* R_E */
19707 init PT_LOAD FLAGS(7); /* RWE */
19708 -#endif
19709 note PT_NOTE FLAGS(0); /* ___ */
19710 }
19711
19712 SECTIONS
19713 {
19714 #ifdef CONFIG_X86_32
19715 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19716 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19717 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19718 #else
19719 - . = __START_KERNEL;
19720 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19721 + . = __START_KERNEL;
19722 #endif
19723
19724 /* Text and read-only data */
19725 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19726 - _text = .;
19727 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19728 /* bootstrapping code */
19729 +#ifdef CONFIG_X86_32
19730 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19731 +#else
19732 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19733 +#endif
19734 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19735 + _text = .;
19736 HEAD_TEXT
19737 #ifdef CONFIG_X86_32
19738 . = ALIGN(PAGE_SIZE);
19739 @@ -108,13 +128,47 @@ SECTIONS
19740 IRQENTRY_TEXT
19741 *(.fixup)
19742 *(.gnu.warning)
19743 - /* End of text section */
19744 - _etext = .;
19745 } :text = 0x9090
19746
19747 - NOTES :text :note
19748 + . += __KERNEL_TEXT_OFFSET;
19749
19750 - EXCEPTION_TABLE(16) :text = 0x9090
19751 +#ifdef CONFIG_X86_32
19752 + . = ALIGN(PAGE_SIZE);
19753 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19754 +
19755 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19756 + MODULES_EXEC_VADDR = .;
19757 + BYTE(0)
19758 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19759 + . = ALIGN(HPAGE_SIZE);
19760 + MODULES_EXEC_END = . - 1;
19761 +#endif
19762 +
19763 + } :module
19764 +#endif
19765 +
19766 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19767 + /* End of text section */
19768 + _etext = . - __KERNEL_TEXT_OFFSET;
19769 + }
19770 +
19771 +#ifdef CONFIG_X86_32
19772 + . = ALIGN(PAGE_SIZE);
19773 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19774 + *(.idt)
19775 + . = ALIGN(PAGE_SIZE);
19776 + *(.empty_zero_page)
19777 + *(.initial_pg_fixmap)
19778 + *(.initial_pg_pmd)
19779 + *(.initial_page_table)
19780 + *(.swapper_pg_dir)
19781 + } :rodata
19782 +#endif
19783 +
19784 + . = ALIGN(PAGE_SIZE);
19785 + NOTES :rodata :note
19786 +
19787 + EXCEPTION_TABLE(16) :rodata
19788
19789 #if defined(CONFIG_DEBUG_RODATA)
19790 /* .text should occupy whole number of pages */
19791 @@ -126,16 +180,20 @@ SECTIONS
19792
19793 /* Data */
19794 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19795 +
19796 +#ifdef CONFIG_PAX_KERNEXEC
19797 + . = ALIGN(HPAGE_SIZE);
19798 +#else
19799 + . = ALIGN(PAGE_SIZE);
19800 +#endif
19801 +
19802 /* Start of data section */
19803 _sdata = .;
19804
19805 /* init_task */
19806 INIT_TASK_DATA(THREAD_SIZE)
19807
19808 -#ifdef CONFIG_X86_32
19809 - /* 32 bit has nosave before _edata */
19810 NOSAVE_DATA
19811 -#endif
19812
19813 PAGE_ALIGNED_DATA(PAGE_SIZE)
19814
19815 @@ -176,12 +234,19 @@ SECTIONS
19816 #endif /* CONFIG_X86_64 */
19817
19818 /* Init code and data - will be freed after init */
19819 - . = ALIGN(PAGE_SIZE);
19820 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19821 + BYTE(0)
19822 +
19823 +#ifdef CONFIG_PAX_KERNEXEC
19824 + . = ALIGN(HPAGE_SIZE);
19825 +#else
19826 + . = ALIGN(PAGE_SIZE);
19827 +#endif
19828 +
19829 __init_begin = .; /* paired with __init_end */
19830 - }
19831 + } :init.begin
19832
19833 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19834 +#ifdef CONFIG_SMP
19835 /*
19836 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19837 * output PHDR, so the next output section - .init.text - should
19838 @@ -190,12 +255,27 @@ SECTIONS
19839 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19840 #endif
19841
19842 - INIT_TEXT_SECTION(PAGE_SIZE)
19843 -#ifdef CONFIG_X86_64
19844 - :init
19845 -#endif
19846 + . = ALIGN(PAGE_SIZE);
19847 + init_begin = .;
19848 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19849 + VMLINUX_SYMBOL(_sinittext) = .;
19850 + INIT_TEXT
19851 + VMLINUX_SYMBOL(_einittext) = .;
19852 + . = ALIGN(PAGE_SIZE);
19853 + } :text.init
19854
19855 - INIT_DATA_SECTION(16)
19856 + /*
19857 + * .exit.text is discard at runtime, not link time, to deal with
19858 + * references from .altinstructions and .eh_frame
19859 + */
19860 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19861 + EXIT_TEXT
19862 + . = ALIGN(16);
19863 + } :text.exit
19864 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19865 +
19866 + . = ALIGN(PAGE_SIZE);
19867 + INIT_DATA_SECTION(16) :init
19868
19869 /*
19870 * Code and data for a variety of lowlevel trampolines, to be
19871 @@ -269,19 +349,12 @@ SECTIONS
19872 }
19873
19874 . = ALIGN(8);
19875 - /*
19876 - * .exit.text is discard at runtime, not link time, to deal with
19877 - * references from .altinstructions and .eh_frame
19878 - */
19879 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19880 - EXIT_TEXT
19881 - }
19882
19883 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19884 EXIT_DATA
19885 }
19886
19887 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19888 +#ifndef CONFIG_SMP
19889 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19890 #endif
19891
19892 @@ -300,16 +373,10 @@ SECTIONS
19893 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19894 __smp_locks = .;
19895 *(.smp_locks)
19896 - . = ALIGN(PAGE_SIZE);
19897 __smp_locks_end = .;
19898 + . = ALIGN(PAGE_SIZE);
19899 }
19900
19901 -#ifdef CONFIG_X86_64
19902 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19903 - NOSAVE_DATA
19904 - }
19905 -#endif
19906 -
19907 /* BSS */
19908 . = ALIGN(PAGE_SIZE);
19909 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19910 @@ -325,6 +392,7 @@ SECTIONS
19911 __brk_base = .;
19912 . += 64 * 1024; /* 64k alignment slop space */
19913 *(.brk_reservation) /* areas brk users have reserved */
19914 + . = ALIGN(HPAGE_SIZE);
19915 __brk_limit = .;
19916 }
19917
19918 @@ -351,13 +419,12 @@ SECTIONS
19919 * for the boot processor.
19920 */
19921 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19922 -INIT_PER_CPU(gdt_page);
19923 INIT_PER_CPU(irq_stack_union);
19924
19925 /*
19926 * Build-time check on the image size:
19927 */
19928 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19929 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19930 "kernel image bigger than KERNEL_IMAGE_SIZE");
19931
19932 #ifdef CONFIG_SMP
19933 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19934 index b07ba93..a212969 100644
19935 --- a/arch/x86/kernel/vsyscall_64.c
19936 +++ b/arch/x86/kernel/vsyscall_64.c
19937 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19938 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19939 };
19940
19941 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19942 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19943
19944 static int __init vsyscall_setup(char *str)
19945 {
19946 if (str) {
19947 if (!strcmp("emulate", str))
19948 vsyscall_mode = EMULATE;
19949 - else if (!strcmp("native", str))
19950 - vsyscall_mode = NATIVE;
19951 else if (!strcmp("none", str))
19952 vsyscall_mode = NONE;
19953 else
19954 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19955
19956 tsk = current;
19957 if (seccomp_mode(&tsk->seccomp))
19958 - do_exit(SIGKILL);
19959 + do_group_exit(SIGKILL);
19960
19961 /*
19962 * With a real vsyscall, page faults cause SIGSEGV. We want to
19963 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19964 return true;
19965
19966 sigsegv:
19967 - force_sig(SIGSEGV, current);
19968 - return true;
19969 + do_group_exit(SIGKILL);
19970 }
19971
19972 /*
19973 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19974 extern char __vvar_page;
19975 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19976
19977 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19978 - vsyscall_mode == NATIVE
19979 - ? PAGE_KERNEL_VSYSCALL
19980 - : PAGE_KERNEL_VVAR);
19981 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19982 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19983 (unsigned long)VSYSCALL_START);
19984
19985 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19986 index 9796c2f..f686fbf 100644
19987 --- a/arch/x86/kernel/x8664_ksyms_64.c
19988 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19989 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19990 EXPORT_SYMBOL(copy_user_generic_string);
19991 EXPORT_SYMBOL(copy_user_generic_unrolled);
19992 EXPORT_SYMBOL(__copy_user_nocache);
19993 -EXPORT_SYMBOL(_copy_from_user);
19994 -EXPORT_SYMBOL(_copy_to_user);
19995
19996 EXPORT_SYMBOL(copy_page);
19997 EXPORT_SYMBOL(clear_page);
19998 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19999 index 7110911..e8cdee5 100644
20000 --- a/arch/x86/kernel/xsave.c
20001 +++ b/arch/x86/kernel/xsave.c
20002 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20003 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20004 return -EINVAL;
20005
20006 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20007 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20008 fx_sw_user->extended_size -
20009 FP_XSTATE_MAGIC2_SIZE));
20010 if (err)
20011 @@ -266,7 +266,7 @@ fx_only:
20012 * the other extended state.
20013 */
20014 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20015 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20016 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20017 }
20018
20019 /*
20020 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20021 if (use_xsave())
20022 err = restore_user_xstate(buf);
20023 else
20024 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20025 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20026 buf);
20027 if (unlikely(err)) {
20028 /*
20029 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20030 index 89b02bf..0f6511d 100644
20031 --- a/arch/x86/kvm/cpuid.c
20032 +++ b/arch/x86/kvm/cpuid.c
20033 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20034 struct kvm_cpuid2 *cpuid,
20035 struct kvm_cpuid_entry2 __user *entries)
20036 {
20037 - int r;
20038 + int r, i;
20039
20040 r = -E2BIG;
20041 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20042 goto out;
20043 r = -EFAULT;
20044 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20045 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20046 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20047 goto out;
20048 + for (i = 0; i < cpuid->nent; ++i) {
20049 + struct kvm_cpuid_entry2 cpuid_entry;
20050 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20051 + goto out;
20052 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20053 + }
20054 vcpu->arch.cpuid_nent = cpuid->nent;
20055 kvm_apic_set_version(vcpu);
20056 kvm_x86_ops->cpuid_update(vcpu);
20057 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20058 struct kvm_cpuid2 *cpuid,
20059 struct kvm_cpuid_entry2 __user *entries)
20060 {
20061 - int r;
20062 + int r, i;
20063
20064 r = -E2BIG;
20065 if (cpuid->nent < vcpu->arch.cpuid_nent)
20066 goto out;
20067 r = -EFAULT;
20068 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20069 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20070 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20071 goto out;
20072 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20073 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20074 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20075 + goto out;
20076 + }
20077 return 0;
20078
20079 out:
20080 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20081 index 0982507..7f6d72f 100644
20082 --- a/arch/x86/kvm/emulate.c
20083 +++ b/arch/x86/kvm/emulate.c
20084 @@ -250,6 +250,7 @@ struct gprefix {
20085
20086 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20087 do { \
20088 + unsigned long _tmp; \
20089 __asm__ __volatile__ ( \
20090 _PRE_EFLAGS("0", "4", "2") \
20091 _op _suffix " %"_x"3,%1; " \
20092 @@ -264,8 +265,6 @@ struct gprefix {
20093 /* Raw emulation: instruction has two explicit operands. */
20094 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20095 do { \
20096 - unsigned long _tmp; \
20097 - \
20098 switch ((ctxt)->dst.bytes) { \
20099 case 2: \
20100 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20101 @@ -281,7 +280,6 @@ struct gprefix {
20102
20103 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20104 do { \
20105 - unsigned long _tmp; \
20106 switch ((ctxt)->dst.bytes) { \
20107 case 1: \
20108 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20109 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20110 index cfdc6e0..ab92e84 100644
20111 --- a/arch/x86/kvm/lapic.c
20112 +++ b/arch/x86/kvm/lapic.c
20113 @@ -54,7 +54,7 @@
20114 #define APIC_BUS_CYCLE_NS 1
20115
20116 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20117 -#define apic_debug(fmt, arg...)
20118 +#define apic_debug(fmt, arg...) do {} while (0)
20119
20120 #define APIC_LVT_NUM 6
20121 /* 14 is the version for Xeon and Pentium 8.4.8*/
20122 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20123 index 1561028..0ed7f14 100644
20124 --- a/arch/x86/kvm/paging_tmpl.h
20125 +++ b/arch/x86/kvm/paging_tmpl.h
20126 @@ -197,7 +197,7 @@ retry_walk:
20127 if (unlikely(kvm_is_error_hva(host_addr)))
20128 goto error;
20129
20130 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20131 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20132 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20133 goto error;
20134
20135 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20136 index e385214..029e9dd 100644
20137 --- a/arch/x86/kvm/svm.c
20138 +++ b/arch/x86/kvm/svm.c
20139 @@ -3051,6 +3051,7 @@ static int svm_set_vm_cr(struct kvm_vcpu *vcpu, u64 data)
20140 return 0;
20141 }
20142
20143 +static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) __size_overflow(3);
20144 static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
20145 {
20146 struct vcpu_svm *svm = to_svm(vcpu);
20147 @@ -3420,7 +3421,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20148 int cpu = raw_smp_processor_id();
20149
20150 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20151 +
20152 + pax_open_kernel();
20153 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20154 + pax_close_kernel();
20155 +
20156 load_TR_desc();
20157 }
20158
20159 @@ -3798,6 +3803,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20160 #endif
20161 #endif
20162
20163 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20164 + __set_fs(current_thread_info()->addr_limit);
20165 +#endif
20166 +
20167 reload_tss(vcpu);
20168
20169 local_irq_disable();
20170 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20171 index 3b4c8d8..f457b63 100644
20172 --- a/arch/x86/kvm/vmx.c
20173 +++ b/arch/x86/kvm/vmx.c
20174 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20175 struct desc_struct *descs;
20176
20177 descs = (void *)gdt->address;
20178 +
20179 + pax_open_kernel();
20180 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20181 + pax_close_kernel();
20182 +
20183 load_TR_desc();
20184 }
20185
20186 @@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
20187 if (!cpu_has_vmx_flexpriority())
20188 flexpriority_enabled = 0;
20189
20190 - if (!cpu_has_vmx_tpr_shadow())
20191 - kvm_x86_ops->update_cr8_intercept = NULL;
20192 + if (!cpu_has_vmx_tpr_shadow()) {
20193 + pax_open_kernel();
20194 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20195 + pax_close_kernel();
20196 + }
20197
20198 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20199 kvm_disable_largepages();
20200 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
20201 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20202
20203 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20204 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20205 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20206
20207 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20208 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20209 @@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20210 "jmp .Lkvm_vmx_return \n\t"
20211 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20212 ".Lkvm_vmx_return: "
20213 +
20214 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20215 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20216 + ".Lkvm_vmx_return2: "
20217 +#endif
20218 +
20219 /* Save guest registers, load host registers, keep flags */
20220 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20221 "pop %0 \n\t"
20222 @@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20223 #endif
20224 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20225 [wordsize]"i"(sizeof(ulong))
20226 +
20227 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20228 + ,[cs]"i"(__KERNEL_CS)
20229 +#endif
20230 +
20231 : "cc", "memory"
20232 , R"ax", R"bx", R"di", R"si"
20233 #ifdef CONFIG_X86_64
20234 @@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20235 }
20236 }
20237
20238 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20239 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20240 +
20241 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20242 + loadsegment(fs, __KERNEL_PERCPU);
20243 +#endif
20244 +
20245 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20246 + __set_fs(current_thread_info()->addr_limit);
20247 +#endif
20248 +
20249 vmx->loaded_vmcs->launched = 1;
20250
20251 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20252 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20253 index 9cbfc06..943ffa6 100644
20254 --- a/arch/x86/kvm/x86.c
20255 +++ b/arch/x86/kvm/x86.c
20256 @@ -873,6 +873,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20257 return kvm_set_msr(vcpu, index, *data);
20258 }
20259
20260 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20261 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20262 {
20263 int version;
20264 @@ -1307,12 +1308,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
20265 return 0;
20266 }
20267
20268 +static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) __size_overflow(2);
20269 static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20270 {
20271 struct kvm *kvm = vcpu->kvm;
20272 int lm = is_long_mode(vcpu);
20273 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20274 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20275 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20276 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20277 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20278 : kvm->arch.xen_hvm_config.blob_size_32;
20279 u32 page_num = data & ~PAGE_MASK;
20280 @@ -2145,6 +2147,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20281 if (n < msr_list.nmsrs)
20282 goto out;
20283 r = -EFAULT;
20284 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20285 + goto out;
20286 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20287 num_msrs_to_save * sizeof(u32)))
20288 goto out;
20289 @@ -2266,7 +2270,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20290 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20291 struct kvm_interrupt *irq)
20292 {
20293 - if (irq->irq < 0 || irq->irq >= 256)
20294 + if (irq->irq >= 256)
20295 return -EINVAL;
20296 if (irqchip_in_kernel(vcpu->kvm))
20297 return -ENXIO;
20298 @@ -3497,6 +3501,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20299
20300 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20301 struct kvm_vcpu *vcpu, u32 access,
20302 + struct x86_exception *exception) __size_overflow(1,3);
20303 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20304 + struct kvm_vcpu *vcpu, u32 access,
20305 struct x86_exception *exception)
20306 {
20307 void *data = val;
20308 @@ -3528,6 +3535,9 @@ out:
20309 /* used for instruction fetching */
20310 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20311 gva_t addr, void *val, unsigned int bytes,
20312 + struct x86_exception *exception) __size_overflow(2,4);
20313 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20314 + gva_t addr, void *val, unsigned int bytes,
20315 struct x86_exception *exception)
20316 {
20317 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20318 @@ -3552,6 +3562,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20319
20320 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20321 gva_t addr, void *val, unsigned int bytes,
20322 + struct x86_exception *exception) __size_overflow(2,4);
20323 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20324 + gva_t addr, void *val, unsigned int bytes,
20325 struct x86_exception *exception)
20326 {
20327 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20328 @@ -3665,12 +3678,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20329 }
20330
20331 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20332 + void *val, int bytes) __size_overflow(2);
20333 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20334 void *val, int bytes)
20335 {
20336 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20337 }
20338
20339 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20340 + void *val, int bytes) __size_overflow(2);
20341 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20342 void *val, int bytes)
20343 {
20344 return emulator_write_phys(vcpu, gpa, val, bytes);
20345 @@ -3821,6 +3838,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20346 const void *old,
20347 const void *new,
20348 unsigned int bytes,
20349 + struct x86_exception *exception) __size_overflow(5);
20350 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20351 + unsigned long addr,
20352 + const void *old,
20353 + const void *new,
20354 + unsigned int bytes,
20355 struct x86_exception *exception)
20356 {
20357 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20358 @@ -4780,7 +4803,7 @@ static void kvm_set_mmio_spte_mask(void)
20359 kvm_mmu_set_mmio_spte_mask(mask);
20360 }
20361
20362 -int kvm_arch_init(void *opaque)
20363 +int kvm_arch_init(const void *opaque)
20364 {
20365 int r;
20366 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20367 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
20368 index cb80c29..aeee86c 100644
20369 --- a/arch/x86/kvm/x86.h
20370 +++ b/arch/x86/kvm/x86.h
20371 @@ -116,11 +116,11 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
20372
20373 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
20374 gva_t addr, void *val, unsigned int bytes,
20375 - struct x86_exception *exception);
20376 + struct x86_exception *exception) __size_overflow(2,4);
20377
20378 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20379 gva_t addr, void *val, unsigned int bytes,
20380 - struct x86_exception *exception);
20381 + struct x86_exception *exception) __size_overflow(2,4);
20382
20383 extern u64 host_xcr0;
20384
20385 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20386 index 642d880..44e0f3f 100644
20387 --- a/arch/x86/lguest/boot.c
20388 +++ b/arch/x86/lguest/boot.c
20389 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20390 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20391 * Launcher to reboot us.
20392 */
20393 -static void lguest_restart(char *reason)
20394 +static __noreturn void lguest_restart(char *reason)
20395 {
20396 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20397 + BUG();
20398 }
20399
20400 /*G:050
20401 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20402 index 042f682..c92afb6 100644
20403 --- a/arch/x86/lib/atomic64_32.c
20404 +++ b/arch/x86/lib/atomic64_32.c
20405 @@ -8,18 +8,30 @@
20406
20407 long long atomic64_read_cx8(long long, const atomic64_t *v);
20408 EXPORT_SYMBOL(atomic64_read_cx8);
20409 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20410 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20411 long long atomic64_set_cx8(long long, const atomic64_t *v);
20412 EXPORT_SYMBOL(atomic64_set_cx8);
20413 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20414 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20415 long long atomic64_xchg_cx8(long long, unsigned high);
20416 EXPORT_SYMBOL(atomic64_xchg_cx8);
20417 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20418 EXPORT_SYMBOL(atomic64_add_return_cx8);
20419 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20420 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20421 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20422 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20423 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20424 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20425 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20426 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20427 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20428 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20429 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20430 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20431 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20432 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20433 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20434 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20435 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20436 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20437 #ifndef CONFIG_X86_CMPXCHG64
20438 long long atomic64_read_386(long long, const atomic64_t *v);
20439 EXPORT_SYMBOL(atomic64_read_386);
20440 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20441 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20442 long long atomic64_set_386(long long, const atomic64_t *v);
20443 EXPORT_SYMBOL(atomic64_set_386);
20444 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20445 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20446 long long atomic64_xchg_386(long long, unsigned high);
20447 EXPORT_SYMBOL(atomic64_xchg_386);
20448 long long atomic64_add_return_386(long long a, atomic64_t *v);
20449 EXPORT_SYMBOL(atomic64_add_return_386);
20450 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20451 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20452 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20453 EXPORT_SYMBOL(atomic64_sub_return_386);
20454 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20455 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20456 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20457 EXPORT_SYMBOL(atomic64_inc_return_386);
20458 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20459 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20460 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20461 EXPORT_SYMBOL(atomic64_dec_return_386);
20462 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20463 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20464 long long atomic64_add_386(long long a, atomic64_t *v);
20465 EXPORT_SYMBOL(atomic64_add_386);
20466 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20467 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20468 long long atomic64_sub_386(long long a, atomic64_t *v);
20469 EXPORT_SYMBOL(atomic64_sub_386);
20470 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20471 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20472 long long atomic64_inc_386(long long a, atomic64_t *v);
20473 EXPORT_SYMBOL(atomic64_inc_386);
20474 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20475 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20476 long long atomic64_dec_386(long long a, atomic64_t *v);
20477 EXPORT_SYMBOL(atomic64_dec_386);
20478 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20479 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20480 long long atomic64_dec_if_positive_386(atomic64_t *v);
20481 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20482 int atomic64_inc_not_zero_386(atomic64_t *v);
20483 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20484 index e8e7e0d..56fd1b0 100644
20485 --- a/arch/x86/lib/atomic64_386_32.S
20486 +++ b/arch/x86/lib/atomic64_386_32.S
20487 @@ -48,6 +48,10 @@ BEGIN(read)
20488 movl (v), %eax
20489 movl 4(v), %edx
20490 RET_ENDP
20491 +BEGIN(read_unchecked)
20492 + movl (v), %eax
20493 + movl 4(v), %edx
20494 +RET_ENDP
20495 #undef v
20496
20497 #define v %esi
20498 @@ -55,6 +59,10 @@ BEGIN(set)
20499 movl %ebx, (v)
20500 movl %ecx, 4(v)
20501 RET_ENDP
20502 +BEGIN(set_unchecked)
20503 + movl %ebx, (v)
20504 + movl %ecx, 4(v)
20505 +RET_ENDP
20506 #undef v
20507
20508 #define v %esi
20509 @@ -70,6 +78,20 @@ RET_ENDP
20510 BEGIN(add)
20511 addl %eax, (v)
20512 adcl %edx, 4(v)
20513 +
20514 +#ifdef CONFIG_PAX_REFCOUNT
20515 + jno 0f
20516 + subl %eax, (v)
20517 + sbbl %edx, 4(v)
20518 + int $4
20519 +0:
20520 + _ASM_EXTABLE(0b, 0b)
20521 +#endif
20522 +
20523 +RET_ENDP
20524 +BEGIN(add_unchecked)
20525 + addl %eax, (v)
20526 + adcl %edx, 4(v)
20527 RET_ENDP
20528 #undef v
20529
20530 @@ -77,6 +99,24 @@ RET_ENDP
20531 BEGIN(add_return)
20532 addl (v), %eax
20533 adcl 4(v), %edx
20534 +
20535 +#ifdef CONFIG_PAX_REFCOUNT
20536 + into
20537 +1234:
20538 + _ASM_EXTABLE(1234b, 2f)
20539 +#endif
20540 +
20541 + movl %eax, (v)
20542 + movl %edx, 4(v)
20543 +
20544 +#ifdef CONFIG_PAX_REFCOUNT
20545 +2:
20546 +#endif
20547 +
20548 +RET_ENDP
20549 +BEGIN(add_return_unchecked)
20550 + addl (v), %eax
20551 + adcl 4(v), %edx
20552 movl %eax, (v)
20553 movl %edx, 4(v)
20554 RET_ENDP
20555 @@ -86,6 +126,20 @@ RET_ENDP
20556 BEGIN(sub)
20557 subl %eax, (v)
20558 sbbl %edx, 4(v)
20559 +
20560 +#ifdef CONFIG_PAX_REFCOUNT
20561 + jno 0f
20562 + addl %eax, (v)
20563 + adcl %edx, 4(v)
20564 + int $4
20565 +0:
20566 + _ASM_EXTABLE(0b, 0b)
20567 +#endif
20568 +
20569 +RET_ENDP
20570 +BEGIN(sub_unchecked)
20571 + subl %eax, (v)
20572 + sbbl %edx, 4(v)
20573 RET_ENDP
20574 #undef v
20575
20576 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20577 sbbl $0, %edx
20578 addl (v), %eax
20579 adcl 4(v), %edx
20580 +
20581 +#ifdef CONFIG_PAX_REFCOUNT
20582 + into
20583 +1234:
20584 + _ASM_EXTABLE(1234b, 2f)
20585 +#endif
20586 +
20587 + movl %eax, (v)
20588 + movl %edx, 4(v)
20589 +
20590 +#ifdef CONFIG_PAX_REFCOUNT
20591 +2:
20592 +#endif
20593 +
20594 +RET_ENDP
20595 +BEGIN(sub_return_unchecked)
20596 + negl %edx
20597 + negl %eax
20598 + sbbl $0, %edx
20599 + addl (v), %eax
20600 + adcl 4(v), %edx
20601 movl %eax, (v)
20602 movl %edx, 4(v)
20603 RET_ENDP
20604 @@ -105,6 +180,20 @@ RET_ENDP
20605 BEGIN(inc)
20606 addl $1, (v)
20607 adcl $0, 4(v)
20608 +
20609 +#ifdef CONFIG_PAX_REFCOUNT
20610 + jno 0f
20611 + subl $1, (v)
20612 + sbbl $0, 4(v)
20613 + int $4
20614 +0:
20615 + _ASM_EXTABLE(0b, 0b)
20616 +#endif
20617 +
20618 +RET_ENDP
20619 +BEGIN(inc_unchecked)
20620 + addl $1, (v)
20621 + adcl $0, 4(v)
20622 RET_ENDP
20623 #undef v
20624
20625 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20626 movl 4(v), %edx
20627 addl $1, %eax
20628 adcl $0, %edx
20629 +
20630 +#ifdef CONFIG_PAX_REFCOUNT
20631 + into
20632 +1234:
20633 + _ASM_EXTABLE(1234b, 2f)
20634 +#endif
20635 +
20636 + movl %eax, (v)
20637 + movl %edx, 4(v)
20638 +
20639 +#ifdef CONFIG_PAX_REFCOUNT
20640 +2:
20641 +#endif
20642 +
20643 +RET_ENDP
20644 +BEGIN(inc_return_unchecked)
20645 + movl (v), %eax
20646 + movl 4(v), %edx
20647 + addl $1, %eax
20648 + adcl $0, %edx
20649 movl %eax, (v)
20650 movl %edx, 4(v)
20651 RET_ENDP
20652 @@ -123,6 +232,20 @@ RET_ENDP
20653 BEGIN(dec)
20654 subl $1, (v)
20655 sbbl $0, 4(v)
20656 +
20657 +#ifdef CONFIG_PAX_REFCOUNT
20658 + jno 0f
20659 + addl $1, (v)
20660 + adcl $0, 4(v)
20661 + int $4
20662 +0:
20663 + _ASM_EXTABLE(0b, 0b)
20664 +#endif
20665 +
20666 +RET_ENDP
20667 +BEGIN(dec_unchecked)
20668 + subl $1, (v)
20669 + sbbl $0, 4(v)
20670 RET_ENDP
20671 #undef v
20672
20673 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20674 movl 4(v), %edx
20675 subl $1, %eax
20676 sbbl $0, %edx
20677 +
20678 +#ifdef CONFIG_PAX_REFCOUNT
20679 + into
20680 +1234:
20681 + _ASM_EXTABLE(1234b, 2f)
20682 +#endif
20683 +
20684 + movl %eax, (v)
20685 + movl %edx, 4(v)
20686 +
20687 +#ifdef CONFIG_PAX_REFCOUNT
20688 +2:
20689 +#endif
20690 +
20691 +RET_ENDP
20692 +BEGIN(dec_return_unchecked)
20693 + movl (v), %eax
20694 + movl 4(v), %edx
20695 + subl $1, %eax
20696 + sbbl $0, %edx
20697 movl %eax, (v)
20698 movl %edx, 4(v)
20699 RET_ENDP
20700 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20701 adcl %edx, %edi
20702 addl (v), %eax
20703 adcl 4(v), %edx
20704 +
20705 +#ifdef CONFIG_PAX_REFCOUNT
20706 + into
20707 +1234:
20708 + _ASM_EXTABLE(1234b, 2f)
20709 +#endif
20710 +
20711 cmpl %eax, %esi
20712 je 3f
20713 1:
20714 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20715 1:
20716 addl $1, %eax
20717 adcl $0, %edx
20718 +
20719 +#ifdef CONFIG_PAX_REFCOUNT
20720 + into
20721 +1234:
20722 + _ASM_EXTABLE(1234b, 2f)
20723 +#endif
20724 +
20725 movl %eax, (v)
20726 movl %edx, 4(v)
20727 movl $1, %eax
20728 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20729 movl 4(v), %edx
20730 subl $1, %eax
20731 sbbl $0, %edx
20732 +
20733 +#ifdef CONFIG_PAX_REFCOUNT
20734 + into
20735 +1234:
20736 + _ASM_EXTABLE(1234b, 1f)
20737 +#endif
20738 +
20739 js 1f
20740 movl %eax, (v)
20741 movl %edx, 4(v)
20742 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20743 index 391a083..d658e9f 100644
20744 --- a/arch/x86/lib/atomic64_cx8_32.S
20745 +++ b/arch/x86/lib/atomic64_cx8_32.S
20746 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20747 CFI_STARTPROC
20748
20749 read64 %ecx
20750 + pax_force_retaddr
20751 ret
20752 CFI_ENDPROC
20753 ENDPROC(atomic64_read_cx8)
20754
20755 +ENTRY(atomic64_read_unchecked_cx8)
20756 + CFI_STARTPROC
20757 +
20758 + read64 %ecx
20759 + pax_force_retaddr
20760 + ret
20761 + CFI_ENDPROC
20762 +ENDPROC(atomic64_read_unchecked_cx8)
20763 +
20764 ENTRY(atomic64_set_cx8)
20765 CFI_STARTPROC
20766
20767 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20768 cmpxchg8b (%esi)
20769 jne 1b
20770
20771 + pax_force_retaddr
20772 ret
20773 CFI_ENDPROC
20774 ENDPROC(atomic64_set_cx8)
20775
20776 +ENTRY(atomic64_set_unchecked_cx8)
20777 + CFI_STARTPROC
20778 +
20779 +1:
20780 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20781 + * are atomic on 586 and newer */
20782 + cmpxchg8b (%esi)
20783 + jne 1b
20784 +
20785 + pax_force_retaddr
20786 + ret
20787 + CFI_ENDPROC
20788 +ENDPROC(atomic64_set_unchecked_cx8)
20789 +
20790 ENTRY(atomic64_xchg_cx8)
20791 CFI_STARTPROC
20792
20793 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20794 cmpxchg8b (%esi)
20795 jne 1b
20796
20797 + pax_force_retaddr
20798 ret
20799 CFI_ENDPROC
20800 ENDPROC(atomic64_xchg_cx8)
20801
20802 -.macro addsub_return func ins insc
20803 -ENTRY(atomic64_\func\()_return_cx8)
20804 +.macro addsub_return func ins insc unchecked=""
20805 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20806 CFI_STARTPROC
20807 SAVE ebp
20808 SAVE ebx
20809 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20810 movl %edx, %ecx
20811 \ins\()l %esi, %ebx
20812 \insc\()l %edi, %ecx
20813 +
20814 +.ifb \unchecked
20815 +#ifdef CONFIG_PAX_REFCOUNT
20816 + into
20817 +2:
20818 + _ASM_EXTABLE(2b, 3f)
20819 +#endif
20820 +.endif
20821 +
20822 LOCK_PREFIX
20823 cmpxchg8b (%ebp)
20824 jne 1b
20825 -
20826 -10:
20827 movl %ebx, %eax
20828 movl %ecx, %edx
20829 +
20830 +.ifb \unchecked
20831 +#ifdef CONFIG_PAX_REFCOUNT
20832 +3:
20833 +#endif
20834 +.endif
20835 +
20836 RESTORE edi
20837 RESTORE esi
20838 RESTORE ebx
20839 RESTORE ebp
20840 + pax_force_retaddr
20841 ret
20842 CFI_ENDPROC
20843 -ENDPROC(atomic64_\func\()_return_cx8)
20844 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20845 .endm
20846
20847 addsub_return add add adc
20848 addsub_return sub sub sbb
20849 +addsub_return add add adc _unchecked
20850 +addsub_return sub sub sbb _unchecked
20851
20852 -.macro incdec_return func ins insc
20853 -ENTRY(atomic64_\func\()_return_cx8)
20854 +.macro incdec_return func ins insc unchecked
20855 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20856 CFI_STARTPROC
20857 SAVE ebx
20858
20859 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20860 movl %edx, %ecx
20861 \ins\()l $1, %ebx
20862 \insc\()l $0, %ecx
20863 +
20864 +.ifb \unchecked
20865 +#ifdef CONFIG_PAX_REFCOUNT
20866 + into
20867 +2:
20868 + _ASM_EXTABLE(2b, 3f)
20869 +#endif
20870 +.endif
20871 +
20872 LOCK_PREFIX
20873 cmpxchg8b (%esi)
20874 jne 1b
20875
20876 -10:
20877 movl %ebx, %eax
20878 movl %ecx, %edx
20879 +
20880 +.ifb \unchecked
20881 +#ifdef CONFIG_PAX_REFCOUNT
20882 +3:
20883 +#endif
20884 +.endif
20885 +
20886 RESTORE ebx
20887 + pax_force_retaddr
20888 ret
20889 CFI_ENDPROC
20890 -ENDPROC(atomic64_\func\()_return_cx8)
20891 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20892 .endm
20893
20894 incdec_return inc add adc
20895 incdec_return dec sub sbb
20896 +incdec_return inc add adc _unchecked
20897 +incdec_return dec sub sbb _unchecked
20898
20899 ENTRY(atomic64_dec_if_positive_cx8)
20900 CFI_STARTPROC
20901 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20902 movl %edx, %ecx
20903 subl $1, %ebx
20904 sbb $0, %ecx
20905 +
20906 +#ifdef CONFIG_PAX_REFCOUNT
20907 + into
20908 +1234:
20909 + _ASM_EXTABLE(1234b, 2f)
20910 +#endif
20911 +
20912 js 2f
20913 LOCK_PREFIX
20914 cmpxchg8b (%esi)
20915 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20916 movl %ebx, %eax
20917 movl %ecx, %edx
20918 RESTORE ebx
20919 + pax_force_retaddr
20920 ret
20921 CFI_ENDPROC
20922 ENDPROC(atomic64_dec_if_positive_cx8)
20923 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20924 movl %edx, %ecx
20925 addl %esi, %ebx
20926 adcl %edi, %ecx
20927 +
20928 +#ifdef CONFIG_PAX_REFCOUNT
20929 + into
20930 +1234:
20931 + _ASM_EXTABLE(1234b, 3f)
20932 +#endif
20933 +
20934 LOCK_PREFIX
20935 cmpxchg8b (%ebp)
20936 jne 1b
20937 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20938 CFI_ADJUST_CFA_OFFSET -8
20939 RESTORE ebx
20940 RESTORE ebp
20941 + pax_force_retaddr
20942 ret
20943 4:
20944 cmpl %edx, 4(%esp)
20945 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20946 movl %edx, %ecx
20947 addl $1, %ebx
20948 adcl $0, %ecx
20949 +
20950 +#ifdef CONFIG_PAX_REFCOUNT
20951 + into
20952 +1234:
20953 + _ASM_EXTABLE(1234b, 3f)
20954 +#endif
20955 +
20956 LOCK_PREFIX
20957 cmpxchg8b (%esi)
20958 jne 1b
20959 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20960 movl $1, %eax
20961 3:
20962 RESTORE ebx
20963 + pax_force_retaddr
20964 ret
20965 4:
20966 testl %edx, %edx
20967 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20968 index 78d16a5..fbcf666 100644
20969 --- a/arch/x86/lib/checksum_32.S
20970 +++ b/arch/x86/lib/checksum_32.S
20971 @@ -28,7 +28,8 @@
20972 #include <linux/linkage.h>
20973 #include <asm/dwarf2.h>
20974 #include <asm/errno.h>
20975 -
20976 +#include <asm/segment.h>
20977 +
20978 /*
20979 * computes a partial checksum, e.g. for TCP/UDP fragments
20980 */
20981 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20982
20983 #define ARGBASE 16
20984 #define FP 12
20985 -
20986 -ENTRY(csum_partial_copy_generic)
20987 +
20988 +ENTRY(csum_partial_copy_generic_to_user)
20989 CFI_STARTPROC
20990 +
20991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20992 + pushl_cfi %gs
20993 + popl_cfi %es
20994 + jmp csum_partial_copy_generic
20995 +#endif
20996 +
20997 +ENTRY(csum_partial_copy_generic_from_user)
20998 +
20999 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21000 + pushl_cfi %gs
21001 + popl_cfi %ds
21002 +#endif
21003 +
21004 +ENTRY(csum_partial_copy_generic)
21005 subl $4,%esp
21006 CFI_ADJUST_CFA_OFFSET 4
21007 pushl_cfi %edi
21008 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21009 jmp 4f
21010 SRC(1: movw (%esi), %bx )
21011 addl $2, %esi
21012 -DST( movw %bx, (%edi) )
21013 +DST( movw %bx, %es:(%edi) )
21014 addl $2, %edi
21015 addw %bx, %ax
21016 adcl $0, %eax
21017 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21018 SRC(1: movl (%esi), %ebx )
21019 SRC( movl 4(%esi), %edx )
21020 adcl %ebx, %eax
21021 -DST( movl %ebx, (%edi) )
21022 +DST( movl %ebx, %es:(%edi) )
21023 adcl %edx, %eax
21024 -DST( movl %edx, 4(%edi) )
21025 +DST( movl %edx, %es:4(%edi) )
21026
21027 SRC( movl 8(%esi), %ebx )
21028 SRC( movl 12(%esi), %edx )
21029 adcl %ebx, %eax
21030 -DST( movl %ebx, 8(%edi) )
21031 +DST( movl %ebx, %es:8(%edi) )
21032 adcl %edx, %eax
21033 -DST( movl %edx, 12(%edi) )
21034 +DST( movl %edx, %es:12(%edi) )
21035
21036 SRC( movl 16(%esi), %ebx )
21037 SRC( movl 20(%esi), %edx )
21038 adcl %ebx, %eax
21039 -DST( movl %ebx, 16(%edi) )
21040 +DST( movl %ebx, %es:16(%edi) )
21041 adcl %edx, %eax
21042 -DST( movl %edx, 20(%edi) )
21043 +DST( movl %edx, %es:20(%edi) )
21044
21045 SRC( movl 24(%esi), %ebx )
21046 SRC( movl 28(%esi), %edx )
21047 adcl %ebx, %eax
21048 -DST( movl %ebx, 24(%edi) )
21049 +DST( movl %ebx, %es:24(%edi) )
21050 adcl %edx, %eax
21051 -DST( movl %edx, 28(%edi) )
21052 +DST( movl %edx, %es:28(%edi) )
21053
21054 lea 32(%esi), %esi
21055 lea 32(%edi), %edi
21056 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21057 shrl $2, %edx # This clears CF
21058 SRC(3: movl (%esi), %ebx )
21059 adcl %ebx, %eax
21060 -DST( movl %ebx, (%edi) )
21061 +DST( movl %ebx, %es:(%edi) )
21062 lea 4(%esi), %esi
21063 lea 4(%edi), %edi
21064 dec %edx
21065 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21066 jb 5f
21067 SRC( movw (%esi), %cx )
21068 leal 2(%esi), %esi
21069 -DST( movw %cx, (%edi) )
21070 +DST( movw %cx, %es:(%edi) )
21071 leal 2(%edi), %edi
21072 je 6f
21073 shll $16,%ecx
21074 SRC(5: movb (%esi), %cl )
21075 -DST( movb %cl, (%edi) )
21076 +DST( movb %cl, %es:(%edi) )
21077 6: addl %ecx, %eax
21078 adcl $0, %eax
21079 7:
21080 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21081
21082 6001:
21083 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21084 - movl $-EFAULT, (%ebx)
21085 + movl $-EFAULT, %ss:(%ebx)
21086
21087 # zero the complete destination - computing the rest
21088 # is too much work
21089 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21090
21091 6002:
21092 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21093 - movl $-EFAULT,(%ebx)
21094 + movl $-EFAULT,%ss:(%ebx)
21095 jmp 5000b
21096
21097 .previous
21098
21099 + pushl_cfi %ss
21100 + popl_cfi %ds
21101 + pushl_cfi %ss
21102 + popl_cfi %es
21103 popl_cfi %ebx
21104 CFI_RESTORE ebx
21105 popl_cfi %esi
21106 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21107 popl_cfi %ecx # equivalent to addl $4,%esp
21108 ret
21109 CFI_ENDPROC
21110 -ENDPROC(csum_partial_copy_generic)
21111 +ENDPROC(csum_partial_copy_generic_to_user)
21112
21113 #else
21114
21115 /* Version for PentiumII/PPro */
21116
21117 #define ROUND1(x) \
21118 + nop; nop; nop; \
21119 SRC(movl x(%esi), %ebx ) ; \
21120 addl %ebx, %eax ; \
21121 - DST(movl %ebx, x(%edi) ) ;
21122 + DST(movl %ebx, %es:x(%edi)) ;
21123
21124 #define ROUND(x) \
21125 + nop; nop; nop; \
21126 SRC(movl x(%esi), %ebx ) ; \
21127 adcl %ebx, %eax ; \
21128 - DST(movl %ebx, x(%edi) ) ;
21129 + DST(movl %ebx, %es:x(%edi)) ;
21130
21131 #define ARGBASE 12
21132 -
21133 -ENTRY(csum_partial_copy_generic)
21134 +
21135 +ENTRY(csum_partial_copy_generic_to_user)
21136 CFI_STARTPROC
21137 +
21138 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21139 + pushl_cfi %gs
21140 + popl_cfi %es
21141 + jmp csum_partial_copy_generic
21142 +#endif
21143 +
21144 +ENTRY(csum_partial_copy_generic_from_user)
21145 +
21146 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21147 + pushl_cfi %gs
21148 + popl_cfi %ds
21149 +#endif
21150 +
21151 +ENTRY(csum_partial_copy_generic)
21152 pushl_cfi %ebx
21153 CFI_REL_OFFSET ebx, 0
21154 pushl_cfi %edi
21155 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21156 subl %ebx, %edi
21157 lea -1(%esi),%edx
21158 andl $-32,%edx
21159 - lea 3f(%ebx,%ebx), %ebx
21160 + lea 3f(%ebx,%ebx,2), %ebx
21161 testl %esi, %esi
21162 jmp *%ebx
21163 1: addl $64,%esi
21164 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21165 jb 5f
21166 SRC( movw (%esi), %dx )
21167 leal 2(%esi), %esi
21168 -DST( movw %dx, (%edi) )
21169 +DST( movw %dx, %es:(%edi) )
21170 leal 2(%edi), %edi
21171 je 6f
21172 shll $16,%edx
21173 5:
21174 SRC( movb (%esi), %dl )
21175 -DST( movb %dl, (%edi) )
21176 +DST( movb %dl, %es:(%edi) )
21177 6: addl %edx, %eax
21178 adcl $0, %eax
21179 7:
21180 .section .fixup, "ax"
21181 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21182 - movl $-EFAULT, (%ebx)
21183 + movl $-EFAULT, %ss:(%ebx)
21184 # zero the complete destination (computing the rest is too much work)
21185 movl ARGBASE+8(%esp),%edi # dst
21186 movl ARGBASE+12(%esp),%ecx # len
21187 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21188 rep; stosb
21189 jmp 7b
21190 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21191 - movl $-EFAULT, (%ebx)
21192 + movl $-EFAULT, %ss:(%ebx)
21193 jmp 7b
21194 .previous
21195
21196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21197 + pushl_cfi %ss
21198 + popl_cfi %ds
21199 + pushl_cfi %ss
21200 + popl_cfi %es
21201 +#endif
21202 +
21203 popl_cfi %esi
21204 CFI_RESTORE esi
21205 popl_cfi %edi
21206 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21207 CFI_RESTORE ebx
21208 ret
21209 CFI_ENDPROC
21210 -ENDPROC(csum_partial_copy_generic)
21211 +ENDPROC(csum_partial_copy_generic_to_user)
21212
21213 #undef ROUND
21214 #undef ROUND1
21215 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21216 index f2145cf..cea889d 100644
21217 --- a/arch/x86/lib/clear_page_64.S
21218 +++ b/arch/x86/lib/clear_page_64.S
21219 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21220 movl $4096/8,%ecx
21221 xorl %eax,%eax
21222 rep stosq
21223 + pax_force_retaddr
21224 ret
21225 CFI_ENDPROC
21226 ENDPROC(clear_page_c)
21227 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21228 movl $4096,%ecx
21229 xorl %eax,%eax
21230 rep stosb
21231 + pax_force_retaddr
21232 ret
21233 CFI_ENDPROC
21234 ENDPROC(clear_page_c_e)
21235 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21236 leaq 64(%rdi),%rdi
21237 jnz .Lloop
21238 nop
21239 + pax_force_retaddr
21240 ret
21241 CFI_ENDPROC
21242 .Lclear_page_end:
21243 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21244
21245 #include <asm/cpufeature.h>
21246
21247 - .section .altinstr_replacement,"ax"
21248 + .section .altinstr_replacement,"a"
21249 1: .byte 0xeb /* jmp <disp8> */
21250 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21251 2: .byte 0xeb /* jmp <disp8> */
21252 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21253 index 1e572c5..2a162cd 100644
21254 --- a/arch/x86/lib/cmpxchg16b_emu.S
21255 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21256 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21257
21258 popf
21259 mov $1, %al
21260 + pax_force_retaddr
21261 ret
21262
21263 not_same:
21264 popf
21265 xor %al,%al
21266 + pax_force_retaddr
21267 ret
21268
21269 CFI_ENDPROC
21270 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21271 index 01c805b..dccb07f 100644
21272 --- a/arch/x86/lib/copy_page_64.S
21273 +++ b/arch/x86/lib/copy_page_64.S
21274 @@ -9,6 +9,7 @@ copy_page_c:
21275 CFI_STARTPROC
21276 movl $4096/8,%ecx
21277 rep movsq
21278 + pax_force_retaddr
21279 ret
21280 CFI_ENDPROC
21281 ENDPROC(copy_page_c)
21282 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21283 movq 16 (%rsi), %rdx
21284 movq 24 (%rsi), %r8
21285 movq 32 (%rsi), %r9
21286 - movq 40 (%rsi), %r10
21287 + movq 40 (%rsi), %r13
21288 movq 48 (%rsi), %r11
21289 movq 56 (%rsi), %r12
21290
21291 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21292 movq %rdx, 16 (%rdi)
21293 movq %r8, 24 (%rdi)
21294 movq %r9, 32 (%rdi)
21295 - movq %r10, 40 (%rdi)
21296 + movq %r13, 40 (%rdi)
21297 movq %r11, 48 (%rdi)
21298 movq %r12, 56 (%rdi)
21299
21300 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21301 movq 16 (%rsi), %rdx
21302 movq 24 (%rsi), %r8
21303 movq 32 (%rsi), %r9
21304 - movq 40 (%rsi), %r10
21305 + movq 40 (%rsi), %r13
21306 movq 48 (%rsi), %r11
21307 movq 56 (%rsi), %r12
21308
21309 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21310 movq %rdx, 16 (%rdi)
21311 movq %r8, 24 (%rdi)
21312 movq %r9, 32 (%rdi)
21313 - movq %r10, 40 (%rdi)
21314 + movq %r13, 40 (%rdi)
21315 movq %r11, 48 (%rdi)
21316 movq %r12, 56 (%rdi)
21317
21318 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21319 CFI_RESTORE r13
21320 addq $3*8,%rsp
21321 CFI_ADJUST_CFA_OFFSET -3*8
21322 + pax_force_retaddr
21323 ret
21324 .Lcopy_page_end:
21325 CFI_ENDPROC
21326 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21327
21328 #include <asm/cpufeature.h>
21329
21330 - .section .altinstr_replacement,"ax"
21331 + .section .altinstr_replacement,"a"
21332 1: .byte 0xeb /* jmp <disp8> */
21333 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21334 2:
21335 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21336 index 0248402..821c786 100644
21337 --- a/arch/x86/lib/copy_user_64.S
21338 +++ b/arch/x86/lib/copy_user_64.S
21339 @@ -16,6 +16,7 @@
21340 #include <asm/thread_info.h>
21341 #include <asm/cpufeature.h>
21342 #include <asm/alternative-asm.h>
21343 +#include <asm/pgtable.h>
21344
21345 /*
21346 * By placing feature2 after feature1 in altinstructions section, we logically
21347 @@ -29,7 +30,7 @@
21348 .byte 0xe9 /* 32bit jump */
21349 .long \orig-1f /* by default jump to orig */
21350 1:
21351 - .section .altinstr_replacement,"ax"
21352 + .section .altinstr_replacement,"a"
21353 2: .byte 0xe9 /* near jump with 32bit immediate */
21354 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21355 3: .byte 0xe9 /* near jump with 32bit immediate */
21356 @@ -71,47 +72,20 @@
21357 #endif
21358 .endm
21359
21360 -/* Standard copy_to_user with segment limit checking */
21361 -ENTRY(_copy_to_user)
21362 - CFI_STARTPROC
21363 - GET_THREAD_INFO(%rax)
21364 - movq %rdi,%rcx
21365 - addq %rdx,%rcx
21366 - jc bad_to_user
21367 - cmpq TI_addr_limit(%rax),%rcx
21368 - ja bad_to_user
21369 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21370 - copy_user_generic_unrolled,copy_user_generic_string, \
21371 - copy_user_enhanced_fast_string
21372 - CFI_ENDPROC
21373 -ENDPROC(_copy_to_user)
21374 -
21375 -/* Standard copy_from_user with segment limit checking */
21376 -ENTRY(_copy_from_user)
21377 - CFI_STARTPROC
21378 - GET_THREAD_INFO(%rax)
21379 - movq %rsi,%rcx
21380 - addq %rdx,%rcx
21381 - jc bad_from_user
21382 - cmpq TI_addr_limit(%rax),%rcx
21383 - ja bad_from_user
21384 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21385 - copy_user_generic_unrolled,copy_user_generic_string, \
21386 - copy_user_enhanced_fast_string
21387 - CFI_ENDPROC
21388 -ENDPROC(_copy_from_user)
21389 -
21390 .section .fixup,"ax"
21391 /* must zero dest */
21392 ENTRY(bad_from_user)
21393 bad_from_user:
21394 CFI_STARTPROC
21395 + testl %edx,%edx
21396 + js bad_to_user
21397 movl %edx,%ecx
21398 xorl %eax,%eax
21399 rep
21400 stosb
21401 bad_to_user:
21402 movl %edx,%eax
21403 + pax_force_retaddr
21404 ret
21405 CFI_ENDPROC
21406 ENDPROC(bad_from_user)
21407 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21408 jz 17f
21409 1: movq (%rsi),%r8
21410 2: movq 1*8(%rsi),%r9
21411 -3: movq 2*8(%rsi),%r10
21412 +3: movq 2*8(%rsi),%rax
21413 4: movq 3*8(%rsi),%r11
21414 5: movq %r8,(%rdi)
21415 6: movq %r9,1*8(%rdi)
21416 -7: movq %r10,2*8(%rdi)
21417 +7: movq %rax,2*8(%rdi)
21418 8: movq %r11,3*8(%rdi)
21419 9: movq 4*8(%rsi),%r8
21420 10: movq 5*8(%rsi),%r9
21421 -11: movq 6*8(%rsi),%r10
21422 +11: movq 6*8(%rsi),%rax
21423 12: movq 7*8(%rsi),%r11
21424 13: movq %r8,4*8(%rdi)
21425 14: movq %r9,5*8(%rdi)
21426 -15: movq %r10,6*8(%rdi)
21427 +15: movq %rax,6*8(%rdi)
21428 16: movq %r11,7*8(%rdi)
21429 leaq 64(%rsi),%rsi
21430 leaq 64(%rdi),%rdi
21431 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21432 decl %ecx
21433 jnz 21b
21434 23: xor %eax,%eax
21435 + pax_force_retaddr
21436 ret
21437
21438 .section .fixup,"ax"
21439 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21440 3: rep
21441 movsb
21442 4: xorl %eax,%eax
21443 + pax_force_retaddr
21444 ret
21445
21446 .section .fixup,"ax"
21447 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21448 1: rep
21449 movsb
21450 2: xorl %eax,%eax
21451 + pax_force_retaddr
21452 ret
21453
21454 .section .fixup,"ax"
21455 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21456 index cb0c112..e3a6895 100644
21457 --- a/arch/x86/lib/copy_user_nocache_64.S
21458 +++ b/arch/x86/lib/copy_user_nocache_64.S
21459 @@ -8,12 +8,14 @@
21460
21461 #include <linux/linkage.h>
21462 #include <asm/dwarf2.h>
21463 +#include <asm/alternative-asm.h>
21464
21465 #define FIX_ALIGNMENT 1
21466
21467 #include <asm/current.h>
21468 #include <asm/asm-offsets.h>
21469 #include <asm/thread_info.h>
21470 +#include <asm/pgtable.h>
21471
21472 .macro ALIGN_DESTINATION
21473 #ifdef FIX_ALIGNMENT
21474 @@ -50,6 +52,15 @@
21475 */
21476 ENTRY(__copy_user_nocache)
21477 CFI_STARTPROC
21478 +
21479 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21480 + mov $PAX_USER_SHADOW_BASE,%rcx
21481 + cmp %rcx,%rsi
21482 + jae 1f
21483 + add %rcx,%rsi
21484 +1:
21485 +#endif
21486 +
21487 cmpl $8,%edx
21488 jb 20f /* less then 8 bytes, go to byte copy loop */
21489 ALIGN_DESTINATION
21490 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21491 jz 17f
21492 1: movq (%rsi),%r8
21493 2: movq 1*8(%rsi),%r9
21494 -3: movq 2*8(%rsi),%r10
21495 +3: movq 2*8(%rsi),%rax
21496 4: movq 3*8(%rsi),%r11
21497 5: movnti %r8,(%rdi)
21498 6: movnti %r9,1*8(%rdi)
21499 -7: movnti %r10,2*8(%rdi)
21500 +7: movnti %rax,2*8(%rdi)
21501 8: movnti %r11,3*8(%rdi)
21502 9: movq 4*8(%rsi),%r8
21503 10: movq 5*8(%rsi),%r9
21504 -11: movq 6*8(%rsi),%r10
21505 +11: movq 6*8(%rsi),%rax
21506 12: movq 7*8(%rsi),%r11
21507 13: movnti %r8,4*8(%rdi)
21508 14: movnti %r9,5*8(%rdi)
21509 -15: movnti %r10,6*8(%rdi)
21510 +15: movnti %rax,6*8(%rdi)
21511 16: movnti %r11,7*8(%rdi)
21512 leaq 64(%rsi),%rsi
21513 leaq 64(%rdi),%rdi
21514 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21515 jnz 21b
21516 23: xorl %eax,%eax
21517 sfence
21518 + pax_force_retaddr
21519 ret
21520
21521 .section .fixup,"ax"
21522 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21523 index fb903b7..c92b7f7 100644
21524 --- a/arch/x86/lib/csum-copy_64.S
21525 +++ b/arch/x86/lib/csum-copy_64.S
21526 @@ -8,6 +8,7 @@
21527 #include <linux/linkage.h>
21528 #include <asm/dwarf2.h>
21529 #include <asm/errno.h>
21530 +#include <asm/alternative-asm.h>
21531
21532 /*
21533 * Checksum copy with exception handling.
21534 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21535 CFI_RESTORE rbp
21536 addq $7*8, %rsp
21537 CFI_ADJUST_CFA_OFFSET -7*8
21538 + pax_force_retaddr 0, 1
21539 ret
21540 CFI_RESTORE_STATE
21541
21542 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21543 index 459b58a..9570bc7 100644
21544 --- a/arch/x86/lib/csum-wrappers_64.c
21545 +++ b/arch/x86/lib/csum-wrappers_64.c
21546 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21547 len -= 2;
21548 }
21549 }
21550 - isum = csum_partial_copy_generic((__force const void *)src,
21551 +
21552 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21553 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21554 + src += PAX_USER_SHADOW_BASE;
21555 +#endif
21556 +
21557 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21558 dst, len, isum, errp, NULL);
21559 if (unlikely(*errp))
21560 goto out_err;
21561 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21562 }
21563
21564 *errp = 0;
21565 - return csum_partial_copy_generic(src, (void __force *)dst,
21566 +
21567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21568 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21569 + dst += PAX_USER_SHADOW_BASE;
21570 +#endif
21571 +
21572 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21573 len, isum, NULL, errp);
21574 }
21575 EXPORT_SYMBOL(csum_partial_copy_to_user);
21576 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21577 index 51f1504..ddac4c1 100644
21578 --- a/arch/x86/lib/getuser.S
21579 +++ b/arch/x86/lib/getuser.S
21580 @@ -33,15 +33,38 @@
21581 #include <asm/asm-offsets.h>
21582 #include <asm/thread_info.h>
21583 #include <asm/asm.h>
21584 +#include <asm/segment.h>
21585 +#include <asm/pgtable.h>
21586 +#include <asm/alternative-asm.h>
21587 +
21588 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21589 +#define __copyuser_seg gs;
21590 +#else
21591 +#define __copyuser_seg
21592 +#endif
21593
21594 .text
21595 ENTRY(__get_user_1)
21596 CFI_STARTPROC
21597 +
21598 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21599 GET_THREAD_INFO(%_ASM_DX)
21600 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21601 jae bad_get_user
21602 -1: movzb (%_ASM_AX),%edx
21603 +
21604 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21605 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21606 + cmp %_ASM_DX,%_ASM_AX
21607 + jae 1234f
21608 + add %_ASM_DX,%_ASM_AX
21609 +1234:
21610 +#endif
21611 +
21612 +#endif
21613 +
21614 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21615 xor %eax,%eax
21616 + pax_force_retaddr
21617 ret
21618 CFI_ENDPROC
21619 ENDPROC(__get_user_1)
21620 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21621 ENTRY(__get_user_2)
21622 CFI_STARTPROC
21623 add $1,%_ASM_AX
21624 +
21625 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21626 jc bad_get_user
21627 GET_THREAD_INFO(%_ASM_DX)
21628 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21629 jae bad_get_user
21630 -2: movzwl -1(%_ASM_AX),%edx
21631 +
21632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21633 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21634 + cmp %_ASM_DX,%_ASM_AX
21635 + jae 1234f
21636 + add %_ASM_DX,%_ASM_AX
21637 +1234:
21638 +#endif
21639 +
21640 +#endif
21641 +
21642 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21643 xor %eax,%eax
21644 + pax_force_retaddr
21645 ret
21646 CFI_ENDPROC
21647 ENDPROC(__get_user_2)
21648 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21649 ENTRY(__get_user_4)
21650 CFI_STARTPROC
21651 add $3,%_ASM_AX
21652 +
21653 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21654 jc bad_get_user
21655 GET_THREAD_INFO(%_ASM_DX)
21656 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21657 jae bad_get_user
21658 -3: mov -3(%_ASM_AX),%edx
21659 +
21660 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21661 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21662 + cmp %_ASM_DX,%_ASM_AX
21663 + jae 1234f
21664 + add %_ASM_DX,%_ASM_AX
21665 +1234:
21666 +#endif
21667 +
21668 +#endif
21669 +
21670 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21671 xor %eax,%eax
21672 + pax_force_retaddr
21673 ret
21674 CFI_ENDPROC
21675 ENDPROC(__get_user_4)
21676 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21677 GET_THREAD_INFO(%_ASM_DX)
21678 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21679 jae bad_get_user
21680 +
21681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21682 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21683 + cmp %_ASM_DX,%_ASM_AX
21684 + jae 1234f
21685 + add %_ASM_DX,%_ASM_AX
21686 +1234:
21687 +#endif
21688 +
21689 4: movq -7(%_ASM_AX),%_ASM_DX
21690 xor %eax,%eax
21691 + pax_force_retaddr
21692 ret
21693 CFI_ENDPROC
21694 ENDPROC(__get_user_8)
21695 @@ -91,6 +152,7 @@ bad_get_user:
21696 CFI_STARTPROC
21697 xor %edx,%edx
21698 mov $(-EFAULT),%_ASM_AX
21699 + pax_force_retaddr
21700 ret
21701 CFI_ENDPROC
21702 END(bad_get_user)
21703 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21704 index 5a1f9f3..ba9f577 100644
21705 --- a/arch/x86/lib/insn.c
21706 +++ b/arch/x86/lib/insn.c
21707 @@ -21,6 +21,11 @@
21708 #include <linux/string.h>
21709 #include <asm/inat.h>
21710 #include <asm/insn.h>
21711 +#ifdef __KERNEL__
21712 +#include <asm/pgtable_types.h>
21713 +#else
21714 +#define ktla_ktva(addr) addr
21715 +#endif
21716
21717 /* Verify next sizeof(t) bytes can be on the same instruction */
21718 #define validate_next(t, insn, n) \
21719 @@ -49,8 +54,8 @@
21720 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21721 {
21722 memset(insn, 0, sizeof(*insn));
21723 - insn->kaddr = kaddr;
21724 - insn->next_byte = kaddr;
21725 + insn->kaddr = ktla_ktva(kaddr);
21726 + insn->next_byte = ktla_ktva(kaddr);
21727 insn->x86_64 = x86_64 ? 1 : 0;
21728 insn->opnd_bytes = 4;
21729 if (x86_64)
21730 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21731 index 05a95e7..326f2fa 100644
21732 --- a/arch/x86/lib/iomap_copy_64.S
21733 +++ b/arch/x86/lib/iomap_copy_64.S
21734 @@ -17,6 +17,7 @@
21735
21736 #include <linux/linkage.h>
21737 #include <asm/dwarf2.h>
21738 +#include <asm/alternative-asm.h>
21739
21740 /*
21741 * override generic version in lib/iomap_copy.c
21742 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21743 CFI_STARTPROC
21744 movl %edx,%ecx
21745 rep movsd
21746 + pax_force_retaddr
21747 ret
21748 CFI_ENDPROC
21749 ENDPROC(__iowrite32_copy)
21750 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21751 index efbf2a0..8893637 100644
21752 --- a/arch/x86/lib/memcpy_64.S
21753 +++ b/arch/x86/lib/memcpy_64.S
21754 @@ -34,6 +34,7 @@
21755 rep movsq
21756 movl %edx, %ecx
21757 rep movsb
21758 + pax_force_retaddr
21759 ret
21760 .Lmemcpy_e:
21761 .previous
21762 @@ -51,6 +52,7 @@
21763
21764 movl %edx, %ecx
21765 rep movsb
21766 + pax_force_retaddr
21767 ret
21768 .Lmemcpy_e_e:
21769 .previous
21770 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21771 */
21772 movq 0*8(%rsi), %r8
21773 movq 1*8(%rsi), %r9
21774 - movq 2*8(%rsi), %r10
21775 + movq 2*8(%rsi), %rcx
21776 movq 3*8(%rsi), %r11
21777 leaq 4*8(%rsi), %rsi
21778
21779 movq %r8, 0*8(%rdi)
21780 movq %r9, 1*8(%rdi)
21781 - movq %r10, 2*8(%rdi)
21782 + movq %rcx, 2*8(%rdi)
21783 movq %r11, 3*8(%rdi)
21784 leaq 4*8(%rdi), %rdi
21785 jae .Lcopy_forward_loop
21786 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21787 subq $0x20, %rdx
21788 movq -1*8(%rsi), %r8
21789 movq -2*8(%rsi), %r9
21790 - movq -3*8(%rsi), %r10
21791 + movq -3*8(%rsi), %rcx
21792 movq -4*8(%rsi), %r11
21793 leaq -4*8(%rsi), %rsi
21794 movq %r8, -1*8(%rdi)
21795 movq %r9, -2*8(%rdi)
21796 - movq %r10, -3*8(%rdi)
21797 + movq %rcx, -3*8(%rdi)
21798 movq %r11, -4*8(%rdi)
21799 leaq -4*8(%rdi), %rdi
21800 jae .Lcopy_backward_loop
21801 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21802 */
21803 movq 0*8(%rsi), %r8
21804 movq 1*8(%rsi), %r9
21805 - movq -2*8(%rsi, %rdx), %r10
21806 + movq -2*8(%rsi, %rdx), %rcx
21807 movq -1*8(%rsi, %rdx), %r11
21808 movq %r8, 0*8(%rdi)
21809 movq %r9, 1*8(%rdi)
21810 - movq %r10, -2*8(%rdi, %rdx)
21811 + movq %rcx, -2*8(%rdi, %rdx)
21812 movq %r11, -1*8(%rdi, %rdx)
21813 + pax_force_retaddr
21814 retq
21815 .p2align 4
21816 .Lless_16bytes:
21817 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21818 movq -1*8(%rsi, %rdx), %r9
21819 movq %r8, 0*8(%rdi)
21820 movq %r9, -1*8(%rdi, %rdx)
21821 + pax_force_retaddr
21822 retq
21823 .p2align 4
21824 .Lless_8bytes:
21825 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21826 movl -4(%rsi, %rdx), %r8d
21827 movl %ecx, (%rdi)
21828 movl %r8d, -4(%rdi, %rdx)
21829 + pax_force_retaddr
21830 retq
21831 .p2align 4
21832 .Lless_3bytes:
21833 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21834 jnz .Lloop_1
21835
21836 .Lend:
21837 + pax_force_retaddr
21838 retq
21839 CFI_ENDPROC
21840 ENDPROC(memcpy)
21841 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21842 index ee16461..c39c199 100644
21843 --- a/arch/x86/lib/memmove_64.S
21844 +++ b/arch/x86/lib/memmove_64.S
21845 @@ -61,13 +61,13 @@ ENTRY(memmove)
21846 5:
21847 sub $0x20, %rdx
21848 movq 0*8(%rsi), %r11
21849 - movq 1*8(%rsi), %r10
21850 + movq 1*8(%rsi), %rcx
21851 movq 2*8(%rsi), %r9
21852 movq 3*8(%rsi), %r8
21853 leaq 4*8(%rsi), %rsi
21854
21855 movq %r11, 0*8(%rdi)
21856 - movq %r10, 1*8(%rdi)
21857 + movq %rcx, 1*8(%rdi)
21858 movq %r9, 2*8(%rdi)
21859 movq %r8, 3*8(%rdi)
21860 leaq 4*8(%rdi), %rdi
21861 @@ -81,10 +81,10 @@ ENTRY(memmove)
21862 4:
21863 movq %rdx, %rcx
21864 movq -8(%rsi, %rdx), %r11
21865 - lea -8(%rdi, %rdx), %r10
21866 + lea -8(%rdi, %rdx), %r9
21867 shrq $3, %rcx
21868 rep movsq
21869 - movq %r11, (%r10)
21870 + movq %r11, (%r9)
21871 jmp 13f
21872 .Lmemmove_end_forward:
21873
21874 @@ -95,14 +95,14 @@ ENTRY(memmove)
21875 7:
21876 movq %rdx, %rcx
21877 movq (%rsi), %r11
21878 - movq %rdi, %r10
21879 + movq %rdi, %r9
21880 leaq -8(%rsi, %rdx), %rsi
21881 leaq -8(%rdi, %rdx), %rdi
21882 shrq $3, %rcx
21883 std
21884 rep movsq
21885 cld
21886 - movq %r11, (%r10)
21887 + movq %r11, (%r9)
21888 jmp 13f
21889
21890 /*
21891 @@ -127,13 +127,13 @@ ENTRY(memmove)
21892 8:
21893 subq $0x20, %rdx
21894 movq -1*8(%rsi), %r11
21895 - movq -2*8(%rsi), %r10
21896 + movq -2*8(%rsi), %rcx
21897 movq -3*8(%rsi), %r9
21898 movq -4*8(%rsi), %r8
21899 leaq -4*8(%rsi), %rsi
21900
21901 movq %r11, -1*8(%rdi)
21902 - movq %r10, -2*8(%rdi)
21903 + movq %rcx, -2*8(%rdi)
21904 movq %r9, -3*8(%rdi)
21905 movq %r8, -4*8(%rdi)
21906 leaq -4*8(%rdi), %rdi
21907 @@ -151,11 +151,11 @@ ENTRY(memmove)
21908 * Move data from 16 bytes to 31 bytes.
21909 */
21910 movq 0*8(%rsi), %r11
21911 - movq 1*8(%rsi), %r10
21912 + movq 1*8(%rsi), %rcx
21913 movq -2*8(%rsi, %rdx), %r9
21914 movq -1*8(%rsi, %rdx), %r8
21915 movq %r11, 0*8(%rdi)
21916 - movq %r10, 1*8(%rdi)
21917 + movq %rcx, 1*8(%rdi)
21918 movq %r9, -2*8(%rdi, %rdx)
21919 movq %r8, -1*8(%rdi, %rdx)
21920 jmp 13f
21921 @@ -167,9 +167,9 @@ ENTRY(memmove)
21922 * Move data from 8 bytes to 15 bytes.
21923 */
21924 movq 0*8(%rsi), %r11
21925 - movq -1*8(%rsi, %rdx), %r10
21926 + movq -1*8(%rsi, %rdx), %r9
21927 movq %r11, 0*8(%rdi)
21928 - movq %r10, -1*8(%rdi, %rdx)
21929 + movq %r9, -1*8(%rdi, %rdx)
21930 jmp 13f
21931 10:
21932 cmpq $4, %rdx
21933 @@ -178,9 +178,9 @@ ENTRY(memmove)
21934 * Move data from 4 bytes to 7 bytes.
21935 */
21936 movl (%rsi), %r11d
21937 - movl -4(%rsi, %rdx), %r10d
21938 + movl -4(%rsi, %rdx), %r9d
21939 movl %r11d, (%rdi)
21940 - movl %r10d, -4(%rdi, %rdx)
21941 + movl %r9d, -4(%rdi, %rdx)
21942 jmp 13f
21943 11:
21944 cmp $2, %rdx
21945 @@ -189,9 +189,9 @@ ENTRY(memmove)
21946 * Move data from 2 bytes to 3 bytes.
21947 */
21948 movw (%rsi), %r11w
21949 - movw -2(%rsi, %rdx), %r10w
21950 + movw -2(%rsi, %rdx), %r9w
21951 movw %r11w, (%rdi)
21952 - movw %r10w, -2(%rdi, %rdx)
21953 + movw %r9w, -2(%rdi, %rdx)
21954 jmp 13f
21955 12:
21956 cmp $1, %rdx
21957 @@ -202,6 +202,7 @@ ENTRY(memmove)
21958 movb (%rsi), %r11b
21959 movb %r11b, (%rdi)
21960 13:
21961 + pax_force_retaddr
21962 retq
21963 CFI_ENDPROC
21964
21965 @@ -210,6 +211,7 @@ ENTRY(memmove)
21966 /* Forward moving data. */
21967 movq %rdx, %rcx
21968 rep movsb
21969 + pax_force_retaddr
21970 retq
21971 .Lmemmove_end_forward_efs:
21972 .previous
21973 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21974 index 79bd454..dff325a 100644
21975 --- a/arch/x86/lib/memset_64.S
21976 +++ b/arch/x86/lib/memset_64.S
21977 @@ -31,6 +31,7 @@
21978 movl %r8d,%ecx
21979 rep stosb
21980 movq %r9,%rax
21981 + pax_force_retaddr
21982 ret
21983 .Lmemset_e:
21984 .previous
21985 @@ -53,6 +54,7 @@
21986 movl %edx,%ecx
21987 rep stosb
21988 movq %r9,%rax
21989 + pax_force_retaddr
21990 ret
21991 .Lmemset_e_e:
21992 .previous
21993 @@ -60,13 +62,13 @@
21994 ENTRY(memset)
21995 ENTRY(__memset)
21996 CFI_STARTPROC
21997 - movq %rdi,%r10
21998 movq %rdx,%r11
21999
22000 /* expand byte value */
22001 movzbl %sil,%ecx
22002 movabs $0x0101010101010101,%rax
22003 mul %rcx /* with rax, clobbers rdx */
22004 + movq %rdi,%rdx
22005
22006 /* align dst */
22007 movl %edi,%r9d
22008 @@ -120,7 +122,8 @@ ENTRY(__memset)
22009 jnz .Lloop_1
22010
22011 .Lende:
22012 - movq %r10,%rax
22013 + movq %rdx,%rax
22014 + pax_force_retaddr
22015 ret
22016
22017 CFI_RESTORE_STATE
22018 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22019 index c9f2d9b..e7fd2c0 100644
22020 --- a/arch/x86/lib/mmx_32.c
22021 +++ b/arch/x86/lib/mmx_32.c
22022 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22023 {
22024 void *p;
22025 int i;
22026 + unsigned long cr0;
22027
22028 if (unlikely(in_interrupt()))
22029 return __memcpy(to, from, len);
22030 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22031 kernel_fpu_begin();
22032
22033 __asm__ __volatile__ (
22034 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22035 - " prefetch 64(%0)\n"
22036 - " prefetch 128(%0)\n"
22037 - " prefetch 192(%0)\n"
22038 - " prefetch 256(%0)\n"
22039 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22040 + " prefetch 64(%1)\n"
22041 + " prefetch 128(%1)\n"
22042 + " prefetch 192(%1)\n"
22043 + " prefetch 256(%1)\n"
22044 "2: \n"
22045 ".section .fixup, \"ax\"\n"
22046 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22047 + "3: \n"
22048 +
22049 +#ifdef CONFIG_PAX_KERNEXEC
22050 + " movl %%cr0, %0\n"
22051 + " movl %0, %%eax\n"
22052 + " andl $0xFFFEFFFF, %%eax\n"
22053 + " movl %%eax, %%cr0\n"
22054 +#endif
22055 +
22056 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22057 +
22058 +#ifdef CONFIG_PAX_KERNEXEC
22059 + " movl %0, %%cr0\n"
22060 +#endif
22061 +
22062 " jmp 2b\n"
22063 ".previous\n"
22064 _ASM_EXTABLE(1b, 3b)
22065 - : : "r" (from));
22066 + : "=&r" (cr0) : "r" (from) : "ax");
22067
22068 for ( ; i > 5; i--) {
22069 __asm__ __volatile__ (
22070 - "1: prefetch 320(%0)\n"
22071 - "2: movq (%0), %%mm0\n"
22072 - " movq 8(%0), %%mm1\n"
22073 - " movq 16(%0), %%mm2\n"
22074 - " movq 24(%0), %%mm3\n"
22075 - " movq %%mm0, (%1)\n"
22076 - " movq %%mm1, 8(%1)\n"
22077 - " movq %%mm2, 16(%1)\n"
22078 - " movq %%mm3, 24(%1)\n"
22079 - " movq 32(%0), %%mm0\n"
22080 - " movq 40(%0), %%mm1\n"
22081 - " movq 48(%0), %%mm2\n"
22082 - " movq 56(%0), %%mm3\n"
22083 - " movq %%mm0, 32(%1)\n"
22084 - " movq %%mm1, 40(%1)\n"
22085 - " movq %%mm2, 48(%1)\n"
22086 - " movq %%mm3, 56(%1)\n"
22087 + "1: prefetch 320(%1)\n"
22088 + "2: movq (%1), %%mm0\n"
22089 + " movq 8(%1), %%mm1\n"
22090 + " movq 16(%1), %%mm2\n"
22091 + " movq 24(%1), %%mm3\n"
22092 + " movq %%mm0, (%2)\n"
22093 + " movq %%mm1, 8(%2)\n"
22094 + " movq %%mm2, 16(%2)\n"
22095 + " movq %%mm3, 24(%2)\n"
22096 + " movq 32(%1), %%mm0\n"
22097 + " movq 40(%1), %%mm1\n"
22098 + " movq 48(%1), %%mm2\n"
22099 + " movq 56(%1), %%mm3\n"
22100 + " movq %%mm0, 32(%2)\n"
22101 + " movq %%mm1, 40(%2)\n"
22102 + " movq %%mm2, 48(%2)\n"
22103 + " movq %%mm3, 56(%2)\n"
22104 ".section .fixup, \"ax\"\n"
22105 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22106 + "3:\n"
22107 +
22108 +#ifdef CONFIG_PAX_KERNEXEC
22109 + " movl %%cr0, %0\n"
22110 + " movl %0, %%eax\n"
22111 + " andl $0xFFFEFFFF, %%eax\n"
22112 + " movl %%eax, %%cr0\n"
22113 +#endif
22114 +
22115 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22116 +
22117 +#ifdef CONFIG_PAX_KERNEXEC
22118 + " movl %0, %%cr0\n"
22119 +#endif
22120 +
22121 " jmp 2b\n"
22122 ".previous\n"
22123 _ASM_EXTABLE(1b, 3b)
22124 - : : "r" (from), "r" (to) : "memory");
22125 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22126
22127 from += 64;
22128 to += 64;
22129 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22130 static void fast_copy_page(void *to, void *from)
22131 {
22132 int i;
22133 + unsigned long cr0;
22134
22135 kernel_fpu_begin();
22136
22137 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22138 * but that is for later. -AV
22139 */
22140 __asm__ __volatile__(
22141 - "1: prefetch (%0)\n"
22142 - " prefetch 64(%0)\n"
22143 - " prefetch 128(%0)\n"
22144 - " prefetch 192(%0)\n"
22145 - " prefetch 256(%0)\n"
22146 + "1: prefetch (%1)\n"
22147 + " prefetch 64(%1)\n"
22148 + " prefetch 128(%1)\n"
22149 + " prefetch 192(%1)\n"
22150 + " prefetch 256(%1)\n"
22151 "2: \n"
22152 ".section .fixup, \"ax\"\n"
22153 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22154 + "3: \n"
22155 +
22156 +#ifdef CONFIG_PAX_KERNEXEC
22157 + " movl %%cr0, %0\n"
22158 + " movl %0, %%eax\n"
22159 + " andl $0xFFFEFFFF, %%eax\n"
22160 + " movl %%eax, %%cr0\n"
22161 +#endif
22162 +
22163 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22164 +
22165 +#ifdef CONFIG_PAX_KERNEXEC
22166 + " movl %0, %%cr0\n"
22167 +#endif
22168 +
22169 " jmp 2b\n"
22170 ".previous\n"
22171 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22172 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22173
22174 for (i = 0; i < (4096-320)/64; i++) {
22175 __asm__ __volatile__ (
22176 - "1: prefetch 320(%0)\n"
22177 - "2: movq (%0), %%mm0\n"
22178 - " movntq %%mm0, (%1)\n"
22179 - " movq 8(%0), %%mm1\n"
22180 - " movntq %%mm1, 8(%1)\n"
22181 - " movq 16(%0), %%mm2\n"
22182 - " movntq %%mm2, 16(%1)\n"
22183 - " movq 24(%0), %%mm3\n"
22184 - " movntq %%mm3, 24(%1)\n"
22185 - " movq 32(%0), %%mm4\n"
22186 - " movntq %%mm4, 32(%1)\n"
22187 - " movq 40(%0), %%mm5\n"
22188 - " movntq %%mm5, 40(%1)\n"
22189 - " movq 48(%0), %%mm6\n"
22190 - " movntq %%mm6, 48(%1)\n"
22191 - " movq 56(%0), %%mm7\n"
22192 - " movntq %%mm7, 56(%1)\n"
22193 + "1: prefetch 320(%1)\n"
22194 + "2: movq (%1), %%mm0\n"
22195 + " movntq %%mm0, (%2)\n"
22196 + " movq 8(%1), %%mm1\n"
22197 + " movntq %%mm1, 8(%2)\n"
22198 + " movq 16(%1), %%mm2\n"
22199 + " movntq %%mm2, 16(%2)\n"
22200 + " movq 24(%1), %%mm3\n"
22201 + " movntq %%mm3, 24(%2)\n"
22202 + " movq 32(%1), %%mm4\n"
22203 + " movntq %%mm4, 32(%2)\n"
22204 + " movq 40(%1), %%mm5\n"
22205 + " movntq %%mm5, 40(%2)\n"
22206 + " movq 48(%1), %%mm6\n"
22207 + " movntq %%mm6, 48(%2)\n"
22208 + " movq 56(%1), %%mm7\n"
22209 + " movntq %%mm7, 56(%2)\n"
22210 ".section .fixup, \"ax\"\n"
22211 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22212 + "3:\n"
22213 +
22214 +#ifdef CONFIG_PAX_KERNEXEC
22215 + " movl %%cr0, %0\n"
22216 + " movl %0, %%eax\n"
22217 + " andl $0xFFFEFFFF, %%eax\n"
22218 + " movl %%eax, %%cr0\n"
22219 +#endif
22220 +
22221 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22222 +
22223 +#ifdef CONFIG_PAX_KERNEXEC
22224 + " movl %0, %%cr0\n"
22225 +#endif
22226 +
22227 " jmp 2b\n"
22228 ".previous\n"
22229 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22230 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22231
22232 from += 64;
22233 to += 64;
22234 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22235 static void fast_copy_page(void *to, void *from)
22236 {
22237 int i;
22238 + unsigned long cr0;
22239
22240 kernel_fpu_begin();
22241
22242 __asm__ __volatile__ (
22243 - "1: prefetch (%0)\n"
22244 - " prefetch 64(%0)\n"
22245 - " prefetch 128(%0)\n"
22246 - " prefetch 192(%0)\n"
22247 - " prefetch 256(%0)\n"
22248 + "1: prefetch (%1)\n"
22249 + " prefetch 64(%1)\n"
22250 + " prefetch 128(%1)\n"
22251 + " prefetch 192(%1)\n"
22252 + " prefetch 256(%1)\n"
22253 "2: \n"
22254 ".section .fixup, \"ax\"\n"
22255 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22256 + "3: \n"
22257 +
22258 +#ifdef CONFIG_PAX_KERNEXEC
22259 + " movl %%cr0, %0\n"
22260 + " movl %0, %%eax\n"
22261 + " andl $0xFFFEFFFF, %%eax\n"
22262 + " movl %%eax, %%cr0\n"
22263 +#endif
22264 +
22265 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22266 +
22267 +#ifdef CONFIG_PAX_KERNEXEC
22268 + " movl %0, %%cr0\n"
22269 +#endif
22270 +
22271 " jmp 2b\n"
22272 ".previous\n"
22273 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22274 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22275
22276 for (i = 0; i < 4096/64; i++) {
22277 __asm__ __volatile__ (
22278 - "1: prefetch 320(%0)\n"
22279 - "2: movq (%0), %%mm0\n"
22280 - " movq 8(%0), %%mm1\n"
22281 - " movq 16(%0), %%mm2\n"
22282 - " movq 24(%0), %%mm3\n"
22283 - " movq %%mm0, (%1)\n"
22284 - " movq %%mm1, 8(%1)\n"
22285 - " movq %%mm2, 16(%1)\n"
22286 - " movq %%mm3, 24(%1)\n"
22287 - " movq 32(%0), %%mm0\n"
22288 - " movq 40(%0), %%mm1\n"
22289 - " movq 48(%0), %%mm2\n"
22290 - " movq 56(%0), %%mm3\n"
22291 - " movq %%mm0, 32(%1)\n"
22292 - " movq %%mm1, 40(%1)\n"
22293 - " movq %%mm2, 48(%1)\n"
22294 - " movq %%mm3, 56(%1)\n"
22295 + "1: prefetch 320(%1)\n"
22296 + "2: movq (%1), %%mm0\n"
22297 + " movq 8(%1), %%mm1\n"
22298 + " movq 16(%1), %%mm2\n"
22299 + " movq 24(%1), %%mm3\n"
22300 + " movq %%mm0, (%2)\n"
22301 + " movq %%mm1, 8(%2)\n"
22302 + " movq %%mm2, 16(%2)\n"
22303 + " movq %%mm3, 24(%2)\n"
22304 + " movq 32(%1), %%mm0\n"
22305 + " movq 40(%1), %%mm1\n"
22306 + " movq 48(%1), %%mm2\n"
22307 + " movq 56(%1), %%mm3\n"
22308 + " movq %%mm0, 32(%2)\n"
22309 + " movq %%mm1, 40(%2)\n"
22310 + " movq %%mm2, 48(%2)\n"
22311 + " movq %%mm3, 56(%2)\n"
22312 ".section .fixup, \"ax\"\n"
22313 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22314 + "3:\n"
22315 +
22316 +#ifdef CONFIG_PAX_KERNEXEC
22317 + " movl %%cr0, %0\n"
22318 + " movl %0, %%eax\n"
22319 + " andl $0xFFFEFFFF, %%eax\n"
22320 + " movl %%eax, %%cr0\n"
22321 +#endif
22322 +
22323 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22324 +
22325 +#ifdef CONFIG_PAX_KERNEXEC
22326 + " movl %0, %%cr0\n"
22327 +#endif
22328 +
22329 " jmp 2b\n"
22330 ".previous\n"
22331 _ASM_EXTABLE(1b, 3b)
22332 - : : "r" (from), "r" (to) : "memory");
22333 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22334
22335 from += 64;
22336 to += 64;
22337 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22338 index 69fa106..adda88b 100644
22339 --- a/arch/x86/lib/msr-reg.S
22340 +++ b/arch/x86/lib/msr-reg.S
22341 @@ -3,6 +3,7 @@
22342 #include <asm/dwarf2.h>
22343 #include <asm/asm.h>
22344 #include <asm/msr.h>
22345 +#include <asm/alternative-asm.h>
22346
22347 #ifdef CONFIG_X86_64
22348 /*
22349 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22350 CFI_STARTPROC
22351 pushq_cfi %rbx
22352 pushq_cfi %rbp
22353 - movq %rdi, %r10 /* Save pointer */
22354 + movq %rdi, %r9 /* Save pointer */
22355 xorl %r11d, %r11d /* Return value */
22356 movl (%rdi), %eax
22357 movl 4(%rdi), %ecx
22358 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22359 movl 28(%rdi), %edi
22360 CFI_REMEMBER_STATE
22361 1: \op
22362 -2: movl %eax, (%r10)
22363 +2: movl %eax, (%r9)
22364 movl %r11d, %eax /* Return value */
22365 - movl %ecx, 4(%r10)
22366 - movl %edx, 8(%r10)
22367 - movl %ebx, 12(%r10)
22368 - movl %ebp, 20(%r10)
22369 - movl %esi, 24(%r10)
22370 - movl %edi, 28(%r10)
22371 + movl %ecx, 4(%r9)
22372 + movl %edx, 8(%r9)
22373 + movl %ebx, 12(%r9)
22374 + movl %ebp, 20(%r9)
22375 + movl %esi, 24(%r9)
22376 + movl %edi, 28(%r9)
22377 popq_cfi %rbp
22378 popq_cfi %rbx
22379 + pax_force_retaddr
22380 ret
22381 3:
22382 CFI_RESTORE_STATE
22383 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22384 index 36b0d15..d381858 100644
22385 --- a/arch/x86/lib/putuser.S
22386 +++ b/arch/x86/lib/putuser.S
22387 @@ -15,7 +15,9 @@
22388 #include <asm/thread_info.h>
22389 #include <asm/errno.h>
22390 #include <asm/asm.h>
22391 -
22392 +#include <asm/segment.h>
22393 +#include <asm/pgtable.h>
22394 +#include <asm/alternative-asm.h>
22395
22396 /*
22397 * __put_user_X
22398 @@ -29,52 +31,119 @@
22399 * as they get called from within inline assembly.
22400 */
22401
22402 -#define ENTER CFI_STARTPROC ; \
22403 - GET_THREAD_INFO(%_ASM_BX)
22404 -#define EXIT ret ; \
22405 +#define ENTER CFI_STARTPROC
22406 +#define EXIT pax_force_retaddr; ret ; \
22407 CFI_ENDPROC
22408
22409 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22410 +#define _DEST %_ASM_CX,%_ASM_BX
22411 +#else
22412 +#define _DEST %_ASM_CX
22413 +#endif
22414 +
22415 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22416 +#define __copyuser_seg gs;
22417 +#else
22418 +#define __copyuser_seg
22419 +#endif
22420 +
22421 .text
22422 ENTRY(__put_user_1)
22423 ENTER
22424 +
22425 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22426 + GET_THREAD_INFO(%_ASM_BX)
22427 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22428 jae bad_put_user
22429 -1: movb %al,(%_ASM_CX)
22430 +
22431 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22432 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22433 + cmp %_ASM_BX,%_ASM_CX
22434 + jb 1234f
22435 + xor %ebx,%ebx
22436 +1234:
22437 +#endif
22438 +
22439 +#endif
22440 +
22441 +1: __copyuser_seg movb %al,(_DEST)
22442 xor %eax,%eax
22443 EXIT
22444 ENDPROC(__put_user_1)
22445
22446 ENTRY(__put_user_2)
22447 ENTER
22448 +
22449 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22450 + GET_THREAD_INFO(%_ASM_BX)
22451 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22452 sub $1,%_ASM_BX
22453 cmp %_ASM_BX,%_ASM_CX
22454 jae bad_put_user
22455 -2: movw %ax,(%_ASM_CX)
22456 +
22457 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22458 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22459 + cmp %_ASM_BX,%_ASM_CX
22460 + jb 1234f
22461 + xor %ebx,%ebx
22462 +1234:
22463 +#endif
22464 +
22465 +#endif
22466 +
22467 +2: __copyuser_seg movw %ax,(_DEST)
22468 xor %eax,%eax
22469 EXIT
22470 ENDPROC(__put_user_2)
22471
22472 ENTRY(__put_user_4)
22473 ENTER
22474 +
22475 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22476 + GET_THREAD_INFO(%_ASM_BX)
22477 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22478 sub $3,%_ASM_BX
22479 cmp %_ASM_BX,%_ASM_CX
22480 jae bad_put_user
22481 -3: movl %eax,(%_ASM_CX)
22482 +
22483 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22484 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22485 + cmp %_ASM_BX,%_ASM_CX
22486 + jb 1234f
22487 + xor %ebx,%ebx
22488 +1234:
22489 +#endif
22490 +
22491 +#endif
22492 +
22493 +3: __copyuser_seg movl %eax,(_DEST)
22494 xor %eax,%eax
22495 EXIT
22496 ENDPROC(__put_user_4)
22497
22498 ENTRY(__put_user_8)
22499 ENTER
22500 +
22501 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22502 + GET_THREAD_INFO(%_ASM_BX)
22503 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22504 sub $7,%_ASM_BX
22505 cmp %_ASM_BX,%_ASM_CX
22506 jae bad_put_user
22507 -4: mov %_ASM_AX,(%_ASM_CX)
22508 +
22509 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22510 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22511 + cmp %_ASM_BX,%_ASM_CX
22512 + jb 1234f
22513 + xor %ebx,%ebx
22514 +1234:
22515 +#endif
22516 +
22517 +#endif
22518 +
22519 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22520 #ifdef CONFIG_X86_32
22521 -5: movl %edx,4(%_ASM_CX)
22522 +5: __copyuser_seg movl %edx,4(_DEST)
22523 #endif
22524 xor %eax,%eax
22525 EXIT
22526 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22527 index 1cad221..de671ee 100644
22528 --- a/arch/x86/lib/rwlock.S
22529 +++ b/arch/x86/lib/rwlock.S
22530 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22531 FRAME
22532 0: LOCK_PREFIX
22533 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22534 +
22535 +#ifdef CONFIG_PAX_REFCOUNT
22536 + jno 1234f
22537 + LOCK_PREFIX
22538 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22539 + int $4
22540 +1234:
22541 + _ASM_EXTABLE(1234b, 1234b)
22542 +#endif
22543 +
22544 1: rep; nop
22545 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22546 jne 1b
22547 LOCK_PREFIX
22548 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22549 +
22550 +#ifdef CONFIG_PAX_REFCOUNT
22551 + jno 1234f
22552 + LOCK_PREFIX
22553 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22554 + int $4
22555 +1234:
22556 + _ASM_EXTABLE(1234b, 1234b)
22557 +#endif
22558 +
22559 jnz 0b
22560 ENDFRAME
22561 + pax_force_retaddr
22562 ret
22563 CFI_ENDPROC
22564 END(__write_lock_failed)
22565 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22566 FRAME
22567 0: LOCK_PREFIX
22568 READ_LOCK_SIZE(inc) (%__lock_ptr)
22569 +
22570 +#ifdef CONFIG_PAX_REFCOUNT
22571 + jno 1234f
22572 + LOCK_PREFIX
22573 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22574 + int $4
22575 +1234:
22576 + _ASM_EXTABLE(1234b, 1234b)
22577 +#endif
22578 +
22579 1: rep; nop
22580 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22581 js 1b
22582 LOCK_PREFIX
22583 READ_LOCK_SIZE(dec) (%__lock_ptr)
22584 +
22585 +#ifdef CONFIG_PAX_REFCOUNT
22586 + jno 1234f
22587 + LOCK_PREFIX
22588 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22589 + int $4
22590 +1234:
22591 + _ASM_EXTABLE(1234b, 1234b)
22592 +#endif
22593 +
22594 js 0b
22595 ENDFRAME
22596 + pax_force_retaddr
22597 ret
22598 CFI_ENDPROC
22599 END(__read_lock_failed)
22600 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22601 index 5dff5f0..cadebf4 100644
22602 --- a/arch/x86/lib/rwsem.S
22603 +++ b/arch/x86/lib/rwsem.S
22604 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22605 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22606 CFI_RESTORE __ASM_REG(dx)
22607 restore_common_regs
22608 + pax_force_retaddr
22609 ret
22610 CFI_ENDPROC
22611 ENDPROC(call_rwsem_down_read_failed)
22612 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22613 movq %rax,%rdi
22614 call rwsem_down_write_failed
22615 restore_common_regs
22616 + pax_force_retaddr
22617 ret
22618 CFI_ENDPROC
22619 ENDPROC(call_rwsem_down_write_failed)
22620 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22621 movq %rax,%rdi
22622 call rwsem_wake
22623 restore_common_regs
22624 -1: ret
22625 +1: pax_force_retaddr
22626 + ret
22627 CFI_ENDPROC
22628 ENDPROC(call_rwsem_wake)
22629
22630 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22631 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22632 CFI_RESTORE __ASM_REG(dx)
22633 restore_common_regs
22634 + pax_force_retaddr
22635 ret
22636 CFI_ENDPROC
22637 ENDPROC(call_rwsem_downgrade_wake)
22638 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22639 index a63efd6..ccecad8 100644
22640 --- a/arch/x86/lib/thunk_64.S
22641 +++ b/arch/x86/lib/thunk_64.S
22642 @@ -8,6 +8,7 @@
22643 #include <linux/linkage.h>
22644 #include <asm/dwarf2.h>
22645 #include <asm/calling.h>
22646 +#include <asm/alternative-asm.h>
22647
22648 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22649 .macro THUNK name, func, put_ret_addr_in_rdi=0
22650 @@ -41,5 +42,6 @@
22651 SAVE_ARGS
22652 restore:
22653 RESTORE_ARGS
22654 + pax_force_retaddr
22655 ret
22656 CFI_ENDPROC
22657 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22658 index e218d5d..a99a1eb 100644
22659 --- a/arch/x86/lib/usercopy_32.c
22660 +++ b/arch/x86/lib/usercopy_32.c
22661 @@ -43,7 +43,7 @@ do { \
22662 __asm__ __volatile__( \
22663 " testl %1,%1\n" \
22664 " jz 2f\n" \
22665 - "0: lodsb\n" \
22666 + "0: "__copyuser_seg"lodsb\n" \
22667 " stosb\n" \
22668 " testb %%al,%%al\n" \
22669 " jz 1f\n" \
22670 @@ -128,10 +128,12 @@ do { \
22671 int __d0; \
22672 might_fault(); \
22673 __asm__ __volatile__( \
22674 + __COPYUSER_SET_ES \
22675 "0: rep; stosl\n" \
22676 " movl %2,%0\n" \
22677 "1: rep; stosb\n" \
22678 "2:\n" \
22679 + __COPYUSER_RESTORE_ES \
22680 ".section .fixup,\"ax\"\n" \
22681 "3: lea 0(%2,%0,4),%0\n" \
22682 " jmp 2b\n" \
22683 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22684 might_fault();
22685
22686 __asm__ __volatile__(
22687 + __COPYUSER_SET_ES
22688 " testl %0, %0\n"
22689 " jz 3f\n"
22690 " andl %0,%%ecx\n"
22691 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22692 " subl %%ecx,%0\n"
22693 " addl %0,%%eax\n"
22694 "1:\n"
22695 + __COPYUSER_RESTORE_ES
22696 ".section .fixup,\"ax\"\n"
22697 "2: xorl %%eax,%%eax\n"
22698 " jmp 1b\n"
22699 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22700
22701 #ifdef CONFIG_X86_INTEL_USERCOPY
22702 static unsigned long
22703 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22704 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22705 {
22706 int d0, d1;
22707 __asm__ __volatile__(
22708 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22709 " .align 2,0x90\n"
22710 "3: movl 0(%4), %%eax\n"
22711 "4: movl 4(%4), %%edx\n"
22712 - "5: movl %%eax, 0(%3)\n"
22713 - "6: movl %%edx, 4(%3)\n"
22714 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22715 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22716 "7: movl 8(%4), %%eax\n"
22717 "8: movl 12(%4),%%edx\n"
22718 - "9: movl %%eax, 8(%3)\n"
22719 - "10: movl %%edx, 12(%3)\n"
22720 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22721 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22722 "11: movl 16(%4), %%eax\n"
22723 "12: movl 20(%4), %%edx\n"
22724 - "13: movl %%eax, 16(%3)\n"
22725 - "14: movl %%edx, 20(%3)\n"
22726 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22727 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22728 "15: movl 24(%4), %%eax\n"
22729 "16: movl 28(%4), %%edx\n"
22730 - "17: movl %%eax, 24(%3)\n"
22731 - "18: movl %%edx, 28(%3)\n"
22732 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22733 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22734 "19: movl 32(%4), %%eax\n"
22735 "20: movl 36(%4), %%edx\n"
22736 - "21: movl %%eax, 32(%3)\n"
22737 - "22: movl %%edx, 36(%3)\n"
22738 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22739 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22740 "23: movl 40(%4), %%eax\n"
22741 "24: movl 44(%4), %%edx\n"
22742 - "25: movl %%eax, 40(%3)\n"
22743 - "26: movl %%edx, 44(%3)\n"
22744 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22745 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22746 "27: movl 48(%4), %%eax\n"
22747 "28: movl 52(%4), %%edx\n"
22748 - "29: movl %%eax, 48(%3)\n"
22749 - "30: movl %%edx, 52(%3)\n"
22750 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22751 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22752 "31: movl 56(%4), %%eax\n"
22753 "32: movl 60(%4), %%edx\n"
22754 - "33: movl %%eax, 56(%3)\n"
22755 - "34: movl %%edx, 60(%3)\n"
22756 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22757 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22758 " addl $-64, %0\n"
22759 " addl $64, %4\n"
22760 " addl $64, %3\n"
22761 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22762 " shrl $2, %0\n"
22763 " andl $3, %%eax\n"
22764 " cld\n"
22765 + __COPYUSER_SET_ES
22766 "99: rep; movsl\n"
22767 "36: movl %%eax, %0\n"
22768 "37: rep; movsb\n"
22769 "100:\n"
22770 + __COPYUSER_RESTORE_ES
22771 ".section .fixup,\"ax\"\n"
22772 "101: lea 0(%%eax,%0,4),%0\n"
22773 " jmp 100b\n"
22774 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22775 }
22776
22777 static unsigned long
22778 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22779 +{
22780 + int d0, d1;
22781 + __asm__ __volatile__(
22782 + " .align 2,0x90\n"
22783 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22784 + " cmpl $67, %0\n"
22785 + " jbe 3f\n"
22786 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22787 + " .align 2,0x90\n"
22788 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22789 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22790 + "5: movl %%eax, 0(%3)\n"
22791 + "6: movl %%edx, 4(%3)\n"
22792 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22793 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22794 + "9: movl %%eax, 8(%3)\n"
22795 + "10: movl %%edx, 12(%3)\n"
22796 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22797 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22798 + "13: movl %%eax, 16(%3)\n"
22799 + "14: movl %%edx, 20(%3)\n"
22800 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22801 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22802 + "17: movl %%eax, 24(%3)\n"
22803 + "18: movl %%edx, 28(%3)\n"
22804 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22805 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22806 + "21: movl %%eax, 32(%3)\n"
22807 + "22: movl %%edx, 36(%3)\n"
22808 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22809 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22810 + "25: movl %%eax, 40(%3)\n"
22811 + "26: movl %%edx, 44(%3)\n"
22812 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22813 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22814 + "29: movl %%eax, 48(%3)\n"
22815 + "30: movl %%edx, 52(%3)\n"
22816 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22817 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22818 + "33: movl %%eax, 56(%3)\n"
22819 + "34: movl %%edx, 60(%3)\n"
22820 + " addl $-64, %0\n"
22821 + " addl $64, %4\n"
22822 + " addl $64, %3\n"
22823 + " cmpl $63, %0\n"
22824 + " ja 1b\n"
22825 + "35: movl %0, %%eax\n"
22826 + " shrl $2, %0\n"
22827 + " andl $3, %%eax\n"
22828 + " cld\n"
22829 + "99: rep; "__copyuser_seg" movsl\n"
22830 + "36: movl %%eax, %0\n"
22831 + "37: rep; "__copyuser_seg" movsb\n"
22832 + "100:\n"
22833 + ".section .fixup,\"ax\"\n"
22834 + "101: lea 0(%%eax,%0,4),%0\n"
22835 + " jmp 100b\n"
22836 + ".previous\n"
22837 + ".section __ex_table,\"a\"\n"
22838 + " .align 4\n"
22839 + " .long 1b,100b\n"
22840 + " .long 2b,100b\n"
22841 + " .long 3b,100b\n"
22842 + " .long 4b,100b\n"
22843 + " .long 5b,100b\n"
22844 + " .long 6b,100b\n"
22845 + " .long 7b,100b\n"
22846 + " .long 8b,100b\n"
22847 + " .long 9b,100b\n"
22848 + " .long 10b,100b\n"
22849 + " .long 11b,100b\n"
22850 + " .long 12b,100b\n"
22851 + " .long 13b,100b\n"
22852 + " .long 14b,100b\n"
22853 + " .long 15b,100b\n"
22854 + " .long 16b,100b\n"
22855 + " .long 17b,100b\n"
22856 + " .long 18b,100b\n"
22857 + " .long 19b,100b\n"
22858 + " .long 20b,100b\n"
22859 + " .long 21b,100b\n"
22860 + " .long 22b,100b\n"
22861 + " .long 23b,100b\n"
22862 + " .long 24b,100b\n"
22863 + " .long 25b,100b\n"
22864 + " .long 26b,100b\n"
22865 + " .long 27b,100b\n"
22866 + " .long 28b,100b\n"
22867 + " .long 29b,100b\n"
22868 + " .long 30b,100b\n"
22869 + " .long 31b,100b\n"
22870 + " .long 32b,100b\n"
22871 + " .long 33b,100b\n"
22872 + " .long 34b,100b\n"
22873 + " .long 35b,100b\n"
22874 + " .long 36b,100b\n"
22875 + " .long 37b,100b\n"
22876 + " .long 99b,101b\n"
22877 + ".previous"
22878 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22879 + : "1"(to), "2"(from), "0"(size)
22880 + : "eax", "edx", "memory");
22881 + return size;
22882 +}
22883 +
22884 +static unsigned long
22885 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22886 +static unsigned long
22887 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22888 {
22889 int d0, d1;
22890 __asm__ __volatile__(
22891 " .align 2,0x90\n"
22892 - "0: movl 32(%4), %%eax\n"
22893 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22894 " cmpl $67, %0\n"
22895 " jbe 2f\n"
22896 - "1: movl 64(%4), %%eax\n"
22897 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22898 " .align 2,0x90\n"
22899 - "2: movl 0(%4), %%eax\n"
22900 - "21: movl 4(%4), %%edx\n"
22901 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22902 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22903 " movl %%eax, 0(%3)\n"
22904 " movl %%edx, 4(%3)\n"
22905 - "3: movl 8(%4), %%eax\n"
22906 - "31: movl 12(%4),%%edx\n"
22907 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22908 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22909 " movl %%eax, 8(%3)\n"
22910 " movl %%edx, 12(%3)\n"
22911 - "4: movl 16(%4), %%eax\n"
22912 - "41: movl 20(%4), %%edx\n"
22913 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22914 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22915 " movl %%eax, 16(%3)\n"
22916 " movl %%edx, 20(%3)\n"
22917 - "10: movl 24(%4), %%eax\n"
22918 - "51: movl 28(%4), %%edx\n"
22919 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22920 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22921 " movl %%eax, 24(%3)\n"
22922 " movl %%edx, 28(%3)\n"
22923 - "11: movl 32(%4), %%eax\n"
22924 - "61: movl 36(%4), %%edx\n"
22925 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22926 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22927 " movl %%eax, 32(%3)\n"
22928 " movl %%edx, 36(%3)\n"
22929 - "12: movl 40(%4), %%eax\n"
22930 - "71: movl 44(%4), %%edx\n"
22931 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22932 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22933 " movl %%eax, 40(%3)\n"
22934 " movl %%edx, 44(%3)\n"
22935 - "13: movl 48(%4), %%eax\n"
22936 - "81: movl 52(%4), %%edx\n"
22937 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22938 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22939 " movl %%eax, 48(%3)\n"
22940 " movl %%edx, 52(%3)\n"
22941 - "14: movl 56(%4), %%eax\n"
22942 - "91: movl 60(%4), %%edx\n"
22943 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22944 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22945 " movl %%eax, 56(%3)\n"
22946 " movl %%edx, 60(%3)\n"
22947 " addl $-64, %0\n"
22948 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22949 " shrl $2, %0\n"
22950 " andl $3, %%eax\n"
22951 " cld\n"
22952 - "6: rep; movsl\n"
22953 + "6: rep; "__copyuser_seg" movsl\n"
22954 " movl %%eax,%0\n"
22955 - "7: rep; movsb\n"
22956 + "7: rep; "__copyuser_seg" movsb\n"
22957 "8:\n"
22958 ".section .fixup,\"ax\"\n"
22959 "9: lea 0(%%eax,%0,4),%0\n"
22960 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22961 */
22962
22963 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22964 + const void __user *from, unsigned long size) __size_overflow(3);
22965 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22966 const void __user *from, unsigned long size)
22967 {
22968 int d0, d1;
22969
22970 __asm__ __volatile__(
22971 " .align 2,0x90\n"
22972 - "0: movl 32(%4), %%eax\n"
22973 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22974 " cmpl $67, %0\n"
22975 " jbe 2f\n"
22976 - "1: movl 64(%4), %%eax\n"
22977 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22978 " .align 2,0x90\n"
22979 - "2: movl 0(%4), %%eax\n"
22980 - "21: movl 4(%4), %%edx\n"
22981 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22982 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22983 " movnti %%eax, 0(%3)\n"
22984 " movnti %%edx, 4(%3)\n"
22985 - "3: movl 8(%4), %%eax\n"
22986 - "31: movl 12(%4),%%edx\n"
22987 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22988 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22989 " movnti %%eax, 8(%3)\n"
22990 " movnti %%edx, 12(%3)\n"
22991 - "4: movl 16(%4), %%eax\n"
22992 - "41: movl 20(%4), %%edx\n"
22993 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22994 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22995 " movnti %%eax, 16(%3)\n"
22996 " movnti %%edx, 20(%3)\n"
22997 - "10: movl 24(%4), %%eax\n"
22998 - "51: movl 28(%4), %%edx\n"
22999 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23000 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23001 " movnti %%eax, 24(%3)\n"
23002 " movnti %%edx, 28(%3)\n"
23003 - "11: movl 32(%4), %%eax\n"
23004 - "61: movl 36(%4), %%edx\n"
23005 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23006 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23007 " movnti %%eax, 32(%3)\n"
23008 " movnti %%edx, 36(%3)\n"
23009 - "12: movl 40(%4), %%eax\n"
23010 - "71: movl 44(%4), %%edx\n"
23011 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23012 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23013 " movnti %%eax, 40(%3)\n"
23014 " movnti %%edx, 44(%3)\n"
23015 - "13: movl 48(%4), %%eax\n"
23016 - "81: movl 52(%4), %%edx\n"
23017 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23018 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23019 " movnti %%eax, 48(%3)\n"
23020 " movnti %%edx, 52(%3)\n"
23021 - "14: movl 56(%4), %%eax\n"
23022 - "91: movl 60(%4), %%edx\n"
23023 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23024 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23025 " movnti %%eax, 56(%3)\n"
23026 " movnti %%edx, 60(%3)\n"
23027 " addl $-64, %0\n"
23028 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23029 " shrl $2, %0\n"
23030 " andl $3, %%eax\n"
23031 " cld\n"
23032 - "6: rep; movsl\n"
23033 + "6: rep; "__copyuser_seg" movsl\n"
23034 " movl %%eax,%0\n"
23035 - "7: rep; movsb\n"
23036 + "7: rep; "__copyuser_seg" movsb\n"
23037 "8:\n"
23038 ".section .fixup,\"ax\"\n"
23039 "9: lea 0(%%eax,%0,4),%0\n"
23040 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23041 }
23042
23043 static unsigned long __copy_user_intel_nocache(void *to,
23044 + const void __user *from, unsigned long size) __size_overflow(3);
23045 +static unsigned long __copy_user_intel_nocache(void *to,
23046 const void __user *from, unsigned long size)
23047 {
23048 int d0, d1;
23049
23050 __asm__ __volatile__(
23051 " .align 2,0x90\n"
23052 - "0: movl 32(%4), %%eax\n"
23053 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23054 " cmpl $67, %0\n"
23055 " jbe 2f\n"
23056 - "1: movl 64(%4), %%eax\n"
23057 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23058 " .align 2,0x90\n"
23059 - "2: movl 0(%4), %%eax\n"
23060 - "21: movl 4(%4), %%edx\n"
23061 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23062 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23063 " movnti %%eax, 0(%3)\n"
23064 " movnti %%edx, 4(%3)\n"
23065 - "3: movl 8(%4), %%eax\n"
23066 - "31: movl 12(%4),%%edx\n"
23067 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23068 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23069 " movnti %%eax, 8(%3)\n"
23070 " movnti %%edx, 12(%3)\n"
23071 - "4: movl 16(%4), %%eax\n"
23072 - "41: movl 20(%4), %%edx\n"
23073 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23074 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23075 " movnti %%eax, 16(%3)\n"
23076 " movnti %%edx, 20(%3)\n"
23077 - "10: movl 24(%4), %%eax\n"
23078 - "51: movl 28(%4), %%edx\n"
23079 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23080 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23081 " movnti %%eax, 24(%3)\n"
23082 " movnti %%edx, 28(%3)\n"
23083 - "11: movl 32(%4), %%eax\n"
23084 - "61: movl 36(%4), %%edx\n"
23085 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23086 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23087 " movnti %%eax, 32(%3)\n"
23088 " movnti %%edx, 36(%3)\n"
23089 - "12: movl 40(%4), %%eax\n"
23090 - "71: movl 44(%4), %%edx\n"
23091 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23092 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23093 " movnti %%eax, 40(%3)\n"
23094 " movnti %%edx, 44(%3)\n"
23095 - "13: movl 48(%4), %%eax\n"
23096 - "81: movl 52(%4), %%edx\n"
23097 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23098 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23099 " movnti %%eax, 48(%3)\n"
23100 " movnti %%edx, 52(%3)\n"
23101 - "14: movl 56(%4), %%eax\n"
23102 - "91: movl 60(%4), %%edx\n"
23103 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23104 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23105 " movnti %%eax, 56(%3)\n"
23106 " movnti %%edx, 60(%3)\n"
23107 " addl $-64, %0\n"
23108 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23109 " shrl $2, %0\n"
23110 " andl $3, %%eax\n"
23111 " cld\n"
23112 - "6: rep; movsl\n"
23113 + "6: rep; "__copyuser_seg" movsl\n"
23114 " movl %%eax,%0\n"
23115 - "7: rep; movsb\n"
23116 + "7: rep; "__copyuser_seg" movsb\n"
23117 "8:\n"
23118 ".section .fixup,\"ax\"\n"
23119 "9: lea 0(%%eax,%0,4),%0\n"
23120 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23121 */
23122 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23123 unsigned long size);
23124 -unsigned long __copy_user_intel(void __user *to, const void *from,
23125 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23126 + unsigned long size);
23127 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23128 unsigned long size);
23129 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23130 const void __user *from, unsigned long size);
23131 #endif /* CONFIG_X86_INTEL_USERCOPY */
23132
23133 /* Generic arbitrary sized copy. */
23134 -#define __copy_user(to, from, size) \
23135 +#define __copy_user(to, from, size, prefix, set, restore) \
23136 do { \
23137 int __d0, __d1, __d2; \
23138 __asm__ __volatile__( \
23139 + set \
23140 " cmp $7,%0\n" \
23141 " jbe 1f\n" \
23142 " movl %1,%0\n" \
23143 " negl %0\n" \
23144 " andl $7,%0\n" \
23145 " subl %0,%3\n" \
23146 - "4: rep; movsb\n" \
23147 + "4: rep; "prefix"movsb\n" \
23148 " movl %3,%0\n" \
23149 " shrl $2,%0\n" \
23150 " andl $3,%3\n" \
23151 " .align 2,0x90\n" \
23152 - "0: rep; movsl\n" \
23153 + "0: rep; "prefix"movsl\n" \
23154 " movl %3,%0\n" \
23155 - "1: rep; movsb\n" \
23156 + "1: rep; "prefix"movsb\n" \
23157 "2:\n" \
23158 + restore \
23159 ".section .fixup,\"ax\"\n" \
23160 "5: addl %3,%0\n" \
23161 " jmp 2b\n" \
23162 @@ -682,14 +805,14 @@ do { \
23163 " negl %0\n" \
23164 " andl $7,%0\n" \
23165 " subl %0,%3\n" \
23166 - "4: rep; movsb\n" \
23167 + "4: rep; "__copyuser_seg"movsb\n" \
23168 " movl %3,%0\n" \
23169 " shrl $2,%0\n" \
23170 " andl $3,%3\n" \
23171 " .align 2,0x90\n" \
23172 - "0: rep; movsl\n" \
23173 + "0: rep; "__copyuser_seg"movsl\n" \
23174 " movl %3,%0\n" \
23175 - "1: rep; movsb\n" \
23176 + "1: rep; "__copyuser_seg"movsb\n" \
23177 "2:\n" \
23178 ".section .fixup,\"ax\"\n" \
23179 "5: addl %3,%0\n" \
23180 @@ -775,9 +898,9 @@ survive:
23181 }
23182 #endif
23183 if (movsl_is_ok(to, from, n))
23184 - __copy_user(to, from, n);
23185 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23186 else
23187 - n = __copy_user_intel(to, from, n);
23188 + n = __generic_copy_to_user_intel(to, from, n);
23189 return n;
23190 }
23191 EXPORT_SYMBOL(__copy_to_user_ll);
23192 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23193 unsigned long n)
23194 {
23195 if (movsl_is_ok(to, from, n))
23196 - __copy_user(to, from, n);
23197 + __copy_user(to, from, n, __copyuser_seg, "", "");
23198 else
23199 - n = __copy_user_intel((void __user *)to,
23200 - (const void *)from, n);
23201 + n = __generic_copy_from_user_intel(to, from, n);
23202 return n;
23203 }
23204 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23205 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23206 if (n > 64 && cpu_has_xmm2)
23207 n = __copy_user_intel_nocache(to, from, n);
23208 else
23209 - __copy_user(to, from, n);
23210 + __copy_user(to, from, n, __copyuser_seg, "", "");
23211 #else
23212 - __copy_user(to, from, n);
23213 + __copy_user(to, from, n, __copyuser_seg, "", "");
23214 #endif
23215 return n;
23216 }
23217 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23218
23219 -/**
23220 - * copy_to_user: - Copy a block of data into user space.
23221 - * @to: Destination address, in user space.
23222 - * @from: Source address, in kernel space.
23223 - * @n: Number of bytes to copy.
23224 - *
23225 - * Context: User context only. This function may sleep.
23226 - *
23227 - * Copy data from kernel space to user space.
23228 - *
23229 - * Returns number of bytes that could not be copied.
23230 - * On success, this will be zero.
23231 - */
23232 -unsigned long
23233 -copy_to_user(void __user *to, const void *from, unsigned long n)
23234 -{
23235 - if (access_ok(VERIFY_WRITE, to, n))
23236 - n = __copy_to_user(to, from, n);
23237 - return n;
23238 -}
23239 -EXPORT_SYMBOL(copy_to_user);
23240 -
23241 -/**
23242 - * copy_from_user: - Copy a block of data from user space.
23243 - * @to: Destination address, in kernel space.
23244 - * @from: Source address, in user space.
23245 - * @n: Number of bytes to copy.
23246 - *
23247 - * Context: User context only. This function may sleep.
23248 - *
23249 - * Copy data from user space to kernel space.
23250 - *
23251 - * Returns number of bytes that could not be copied.
23252 - * On success, this will be zero.
23253 - *
23254 - * If some data could not be copied, this function will pad the copied
23255 - * data to the requested size using zero bytes.
23256 - */
23257 -unsigned long
23258 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23259 -{
23260 - if (access_ok(VERIFY_READ, from, n))
23261 - n = __copy_from_user(to, from, n);
23262 - else
23263 - memset(to, 0, n);
23264 - return n;
23265 -}
23266 -EXPORT_SYMBOL(_copy_from_user);
23267 -
23268 void copy_from_user_overflow(void)
23269 {
23270 WARN(1, "Buffer overflow detected!\n");
23271 }
23272 EXPORT_SYMBOL(copy_from_user_overflow);
23273 +
23274 +void copy_to_user_overflow(void)
23275 +{
23276 + WARN(1, "Buffer overflow detected!\n");
23277 +}
23278 +EXPORT_SYMBOL(copy_to_user_overflow);
23279 +
23280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23281 +void __set_fs(mm_segment_t x)
23282 +{
23283 + switch (x.seg) {
23284 + case 0:
23285 + loadsegment(gs, 0);
23286 + break;
23287 + case TASK_SIZE_MAX:
23288 + loadsegment(gs, __USER_DS);
23289 + break;
23290 + case -1UL:
23291 + loadsegment(gs, __KERNEL_DS);
23292 + break;
23293 + default:
23294 + BUG();
23295 + }
23296 + return;
23297 +}
23298 +EXPORT_SYMBOL(__set_fs);
23299 +
23300 +void set_fs(mm_segment_t x)
23301 +{
23302 + current_thread_info()->addr_limit = x;
23303 + __set_fs(x);
23304 +}
23305 +EXPORT_SYMBOL(set_fs);
23306 +#endif
23307 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23308 index b7c2849..8633ad8 100644
23309 --- a/arch/x86/lib/usercopy_64.c
23310 +++ b/arch/x86/lib/usercopy_64.c
23311 @@ -42,6 +42,12 @@ long
23312 __strncpy_from_user(char *dst, const char __user *src, long count)
23313 {
23314 long res;
23315 +
23316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23317 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23318 + src += PAX_USER_SHADOW_BASE;
23319 +#endif
23320 +
23321 __do_strncpy_from_user(dst, src, count, res);
23322 return res;
23323 }
23324 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23325 {
23326 long __d0;
23327 might_fault();
23328 +
23329 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23330 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23331 + addr += PAX_USER_SHADOW_BASE;
23332 +#endif
23333 +
23334 /* no memory constraint because it doesn't change any memory gcc knows
23335 about */
23336 asm volatile(
23337 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23338 }
23339 EXPORT_SYMBOL(strlen_user);
23340
23341 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23342 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23343 {
23344 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23345 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23346 - }
23347 - return len;
23348 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23349 +
23350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23351 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23352 + to += PAX_USER_SHADOW_BASE;
23353 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23354 + from += PAX_USER_SHADOW_BASE;
23355 +#endif
23356 +
23357 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23358 + }
23359 + return len;
23360 }
23361 EXPORT_SYMBOL(copy_in_user);
23362
23363 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23364 * it is not necessary to optimize tail handling.
23365 */
23366 unsigned long
23367 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23368 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23369 {
23370 char c;
23371 unsigned zero_len;
23372 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23373 index 1fb85db..8b3540b 100644
23374 --- a/arch/x86/mm/extable.c
23375 +++ b/arch/x86/mm/extable.c
23376 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23377 const struct exception_table_entry *fixup;
23378
23379 #ifdef CONFIG_PNPBIOS
23380 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23381 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23382 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23383 extern u32 pnp_bios_is_utter_crap;
23384 pnp_bios_is_utter_crap = 1;
23385 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23386 index f0b4caf..d92fd42 100644
23387 --- a/arch/x86/mm/fault.c
23388 +++ b/arch/x86/mm/fault.c
23389 @@ -13,11 +13,18 @@
23390 #include <linux/perf_event.h> /* perf_sw_event */
23391 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23392 #include <linux/prefetch.h> /* prefetchw */
23393 +#include <linux/unistd.h>
23394 +#include <linux/compiler.h>
23395
23396 #include <asm/traps.h> /* dotraplinkage, ... */
23397 #include <asm/pgalloc.h> /* pgd_*(), ... */
23398 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23399 #include <asm/fixmap.h> /* VSYSCALL_START */
23400 +#include <asm/tlbflush.h>
23401 +
23402 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23403 +#include <asm/stacktrace.h>
23404 +#endif
23405
23406 /*
23407 * Page fault error code bits:
23408 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23409 int ret = 0;
23410
23411 /* kprobe_running() needs smp_processor_id() */
23412 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23413 + if (kprobes_built_in() && !user_mode(regs)) {
23414 preempt_disable();
23415 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23416 ret = 1;
23417 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23418 return !instr_lo || (instr_lo>>1) == 1;
23419 case 0x00:
23420 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23421 - if (probe_kernel_address(instr, opcode))
23422 + if (user_mode(regs)) {
23423 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23424 + return 0;
23425 + } else if (probe_kernel_address(instr, opcode))
23426 return 0;
23427
23428 *prefetch = (instr_lo == 0xF) &&
23429 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23430 while (instr < max_instr) {
23431 unsigned char opcode;
23432
23433 - if (probe_kernel_address(instr, opcode))
23434 + if (user_mode(regs)) {
23435 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23436 + break;
23437 + } else if (probe_kernel_address(instr, opcode))
23438 break;
23439
23440 instr++;
23441 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23442 force_sig_info(si_signo, &info, tsk);
23443 }
23444
23445 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23446 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23447 +#endif
23448 +
23449 +#ifdef CONFIG_PAX_EMUTRAMP
23450 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23451 +#endif
23452 +
23453 +#ifdef CONFIG_PAX_PAGEEXEC
23454 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23455 +{
23456 + pgd_t *pgd;
23457 + pud_t *pud;
23458 + pmd_t *pmd;
23459 +
23460 + pgd = pgd_offset(mm, address);
23461 + if (!pgd_present(*pgd))
23462 + return NULL;
23463 + pud = pud_offset(pgd, address);
23464 + if (!pud_present(*pud))
23465 + return NULL;
23466 + pmd = pmd_offset(pud, address);
23467 + if (!pmd_present(*pmd))
23468 + return NULL;
23469 + return pmd;
23470 +}
23471 +#endif
23472 +
23473 DEFINE_SPINLOCK(pgd_lock);
23474 LIST_HEAD(pgd_list);
23475
23476 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23477 for (address = VMALLOC_START & PMD_MASK;
23478 address >= TASK_SIZE && address < FIXADDR_TOP;
23479 address += PMD_SIZE) {
23480 +
23481 +#ifdef CONFIG_PAX_PER_CPU_PGD
23482 + unsigned long cpu;
23483 +#else
23484 struct page *page;
23485 +#endif
23486
23487 spin_lock(&pgd_lock);
23488 +
23489 +#ifdef CONFIG_PAX_PER_CPU_PGD
23490 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23491 + pgd_t *pgd = get_cpu_pgd(cpu);
23492 + pmd_t *ret;
23493 +#else
23494 list_for_each_entry(page, &pgd_list, lru) {
23495 + pgd_t *pgd = page_address(page);
23496 spinlock_t *pgt_lock;
23497 pmd_t *ret;
23498
23499 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23500 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23501
23502 spin_lock(pgt_lock);
23503 - ret = vmalloc_sync_one(page_address(page), address);
23504 +#endif
23505 +
23506 + ret = vmalloc_sync_one(pgd, address);
23507 +
23508 +#ifndef CONFIG_PAX_PER_CPU_PGD
23509 spin_unlock(pgt_lock);
23510 +#endif
23511
23512 if (!ret)
23513 break;
23514 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23515 * an interrupt in the middle of a task switch..
23516 */
23517 pgd_paddr = read_cr3();
23518 +
23519 +#ifdef CONFIG_PAX_PER_CPU_PGD
23520 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23521 +#endif
23522 +
23523 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23524 if (!pmd_k)
23525 return -1;
23526 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23527 * happen within a race in page table update. In the later
23528 * case just flush:
23529 */
23530 +
23531 +#ifdef CONFIG_PAX_PER_CPU_PGD
23532 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23533 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23534 +#else
23535 pgd = pgd_offset(current->active_mm, address);
23536 +#endif
23537 +
23538 pgd_ref = pgd_offset_k(address);
23539 if (pgd_none(*pgd_ref))
23540 return -1;
23541 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23542 static int is_errata100(struct pt_regs *regs, unsigned long address)
23543 {
23544 #ifdef CONFIG_X86_64
23545 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23546 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23547 return 1;
23548 #endif
23549 return 0;
23550 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23551 }
23552
23553 static const char nx_warning[] = KERN_CRIT
23554 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23555 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23556
23557 static void
23558 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23559 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23560 if (!oops_may_print())
23561 return;
23562
23563 - if (error_code & PF_INSTR) {
23564 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23565 unsigned int level;
23566
23567 pte_t *pte = lookup_address(address, &level);
23568
23569 if (pte && pte_present(*pte) && !pte_exec(*pte))
23570 - printk(nx_warning, current_uid());
23571 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23572 }
23573
23574 +#ifdef CONFIG_PAX_KERNEXEC
23575 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23576 + if (current->signal->curr_ip)
23577 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23578 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23579 + else
23580 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23581 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23582 + }
23583 +#endif
23584 +
23585 printk(KERN_ALERT "BUG: unable to handle kernel ");
23586 if (address < PAGE_SIZE)
23587 printk(KERN_CONT "NULL pointer dereference");
23588 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23589 }
23590 #endif
23591
23592 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23593 + if (pax_is_fetch_fault(regs, error_code, address)) {
23594 +
23595 +#ifdef CONFIG_PAX_EMUTRAMP
23596 + switch (pax_handle_fetch_fault(regs)) {
23597 + case 2:
23598 + return;
23599 + }
23600 +#endif
23601 +
23602 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23603 + do_group_exit(SIGKILL);
23604 + }
23605 +#endif
23606 +
23607 if (unlikely(show_unhandled_signals))
23608 show_signal_msg(regs, error_code, address, tsk);
23609
23610 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23611 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23612 printk(KERN_ERR
23613 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23614 - tsk->comm, tsk->pid, address);
23615 + tsk->comm, task_pid_nr(tsk), address);
23616 code = BUS_MCEERR_AR;
23617 }
23618 #endif
23619 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23620 return 1;
23621 }
23622
23623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23624 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23625 +{
23626 + pte_t *pte;
23627 + pmd_t *pmd;
23628 + spinlock_t *ptl;
23629 + unsigned char pte_mask;
23630 +
23631 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23632 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23633 + return 0;
23634 +
23635 + /* PaX: it's our fault, let's handle it if we can */
23636 +
23637 + /* PaX: take a look at read faults before acquiring any locks */
23638 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23639 + /* instruction fetch attempt from a protected page in user mode */
23640 + up_read(&mm->mmap_sem);
23641 +
23642 +#ifdef CONFIG_PAX_EMUTRAMP
23643 + switch (pax_handle_fetch_fault(regs)) {
23644 + case 2:
23645 + return 1;
23646 + }
23647 +#endif
23648 +
23649 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23650 + do_group_exit(SIGKILL);
23651 + }
23652 +
23653 + pmd = pax_get_pmd(mm, address);
23654 + if (unlikely(!pmd))
23655 + return 0;
23656 +
23657 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23658 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23659 + pte_unmap_unlock(pte, ptl);
23660 + return 0;
23661 + }
23662 +
23663 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23664 + /* write attempt to a protected page in user mode */
23665 + pte_unmap_unlock(pte, ptl);
23666 + return 0;
23667 + }
23668 +
23669 +#ifdef CONFIG_SMP
23670 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23671 +#else
23672 + if (likely(address > get_limit(regs->cs)))
23673 +#endif
23674 + {
23675 + set_pte(pte, pte_mkread(*pte));
23676 + __flush_tlb_one(address);
23677 + pte_unmap_unlock(pte, ptl);
23678 + up_read(&mm->mmap_sem);
23679 + return 1;
23680 + }
23681 +
23682 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23683 +
23684 + /*
23685 + * PaX: fill DTLB with user rights and retry
23686 + */
23687 + __asm__ __volatile__ (
23688 + "orb %2,(%1)\n"
23689 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23690 +/*
23691 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23692 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23693 + * page fault when examined during a TLB load attempt. this is true not only
23694 + * for PTEs holding a non-present entry but also present entries that will
23695 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23696 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23697 + * for our target pages since their PTEs are simply not in the TLBs at all.
23698 +
23699 + * the best thing in omitting it is that we gain around 15-20% speed in the
23700 + * fast path of the page fault handler and can get rid of tracing since we
23701 + * can no longer flush unintended entries.
23702 + */
23703 + "invlpg (%0)\n"
23704 +#endif
23705 + __copyuser_seg"testb $0,(%0)\n"
23706 + "xorb %3,(%1)\n"
23707 + :
23708 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23709 + : "memory", "cc");
23710 + pte_unmap_unlock(pte, ptl);
23711 + up_read(&mm->mmap_sem);
23712 + return 1;
23713 +}
23714 +#endif
23715 +
23716 /*
23717 * Handle a spurious fault caused by a stale TLB entry.
23718 *
23719 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23720 static inline int
23721 access_error(unsigned long error_code, struct vm_area_struct *vma)
23722 {
23723 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23724 + return 1;
23725 +
23726 if (error_code & PF_WRITE) {
23727 /* write, present and write, not present: */
23728 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23729 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23730 {
23731 struct vm_area_struct *vma;
23732 struct task_struct *tsk;
23733 - unsigned long address;
23734 struct mm_struct *mm;
23735 int fault;
23736 int write = error_code & PF_WRITE;
23737 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23738 (write ? FAULT_FLAG_WRITE : 0);
23739
23740 - tsk = current;
23741 - mm = tsk->mm;
23742 -
23743 /* Get the faulting address: */
23744 - address = read_cr2();
23745 + unsigned long address = read_cr2();
23746 +
23747 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23748 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23749 + if (!search_exception_tables(regs->ip)) {
23750 + bad_area_nosemaphore(regs, error_code, address);
23751 + return;
23752 + }
23753 + if (address < PAX_USER_SHADOW_BASE) {
23754 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23755 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23756 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23757 + } else
23758 + address -= PAX_USER_SHADOW_BASE;
23759 + }
23760 +#endif
23761 +
23762 + tsk = current;
23763 + mm = tsk->mm;
23764
23765 /*
23766 * Detect and handle instructions that would cause a page fault for
23767 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23768 * User-mode registers count as a user access even for any
23769 * potential system fault or CPU buglet:
23770 */
23771 - if (user_mode_vm(regs)) {
23772 + if (user_mode(regs)) {
23773 local_irq_enable();
23774 error_code |= PF_USER;
23775 } else {
23776 @@ -1132,6 +1338,11 @@ retry:
23777 might_sleep();
23778 }
23779
23780 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23781 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23782 + return;
23783 +#endif
23784 +
23785 vma = find_vma(mm, address);
23786 if (unlikely(!vma)) {
23787 bad_area(regs, error_code, address);
23788 @@ -1143,18 +1354,24 @@ retry:
23789 bad_area(regs, error_code, address);
23790 return;
23791 }
23792 - if (error_code & PF_USER) {
23793 - /*
23794 - * Accessing the stack below %sp is always a bug.
23795 - * The large cushion allows instructions like enter
23796 - * and pusha to work. ("enter $65535, $31" pushes
23797 - * 32 pointers and then decrements %sp by 65535.)
23798 - */
23799 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23800 - bad_area(regs, error_code, address);
23801 - return;
23802 - }
23803 + /*
23804 + * Accessing the stack below %sp is always a bug.
23805 + * The large cushion allows instructions like enter
23806 + * and pusha to work. ("enter $65535, $31" pushes
23807 + * 32 pointers and then decrements %sp by 65535.)
23808 + */
23809 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23810 + bad_area(regs, error_code, address);
23811 + return;
23812 }
23813 +
23814 +#ifdef CONFIG_PAX_SEGMEXEC
23815 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23816 + bad_area(regs, error_code, address);
23817 + return;
23818 + }
23819 +#endif
23820 +
23821 if (unlikely(expand_stack(vma, address))) {
23822 bad_area(regs, error_code, address);
23823 return;
23824 @@ -1209,3 +1426,292 @@ good_area:
23825
23826 up_read(&mm->mmap_sem);
23827 }
23828 +
23829 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23830 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23831 +{
23832 + struct mm_struct *mm = current->mm;
23833 + unsigned long ip = regs->ip;
23834 +
23835 + if (v8086_mode(regs))
23836 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23837 +
23838 +#ifdef CONFIG_PAX_PAGEEXEC
23839 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23840 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23841 + return true;
23842 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23843 + return true;
23844 + return false;
23845 + }
23846 +#endif
23847 +
23848 +#ifdef CONFIG_PAX_SEGMEXEC
23849 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23850 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23851 + return true;
23852 + return false;
23853 + }
23854 +#endif
23855 +
23856 + return false;
23857 +}
23858 +#endif
23859 +
23860 +#ifdef CONFIG_PAX_EMUTRAMP
23861 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23862 +{
23863 + int err;
23864 +
23865 + do { /* PaX: libffi trampoline emulation */
23866 + unsigned char mov, jmp;
23867 + unsigned int addr1, addr2;
23868 +
23869 +#ifdef CONFIG_X86_64
23870 + if ((regs->ip + 9) >> 32)
23871 + break;
23872 +#endif
23873 +
23874 + err = get_user(mov, (unsigned char __user *)regs->ip);
23875 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23876 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23877 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23878 +
23879 + if (err)
23880 + break;
23881 +
23882 + if (mov == 0xB8 && jmp == 0xE9) {
23883 + regs->ax = addr1;
23884 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23885 + return 2;
23886 + }
23887 + } while (0);
23888 +
23889 + do { /* PaX: gcc trampoline emulation #1 */
23890 + unsigned char mov1, mov2;
23891 + unsigned short jmp;
23892 + unsigned int addr1, addr2;
23893 +
23894 +#ifdef CONFIG_X86_64
23895 + if ((regs->ip + 11) >> 32)
23896 + break;
23897 +#endif
23898 +
23899 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23900 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23901 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23902 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23903 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23904 +
23905 + if (err)
23906 + break;
23907 +
23908 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23909 + regs->cx = addr1;
23910 + regs->ax = addr2;
23911 + regs->ip = addr2;
23912 + return 2;
23913 + }
23914 + } while (0);
23915 +
23916 + do { /* PaX: gcc trampoline emulation #2 */
23917 + unsigned char mov, jmp;
23918 + unsigned int addr1, addr2;
23919 +
23920 +#ifdef CONFIG_X86_64
23921 + if ((regs->ip + 9) >> 32)
23922 + break;
23923 +#endif
23924 +
23925 + err = get_user(mov, (unsigned char __user *)regs->ip);
23926 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23927 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23928 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23929 +
23930 + if (err)
23931 + break;
23932 +
23933 + if (mov == 0xB9 && jmp == 0xE9) {
23934 + regs->cx = addr1;
23935 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23936 + return 2;
23937 + }
23938 + } while (0);
23939 +
23940 + return 1; /* PaX in action */
23941 +}
23942 +
23943 +#ifdef CONFIG_X86_64
23944 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23945 +{
23946 + int err;
23947 +
23948 + do { /* PaX: libffi trampoline emulation */
23949 + unsigned short mov1, mov2, jmp1;
23950 + unsigned char stcclc, jmp2;
23951 + unsigned long addr1, addr2;
23952 +
23953 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23954 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23955 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23956 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23957 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23958 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23959 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23960 +
23961 + if (err)
23962 + break;
23963 +
23964 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23965 + regs->r11 = addr1;
23966 + regs->r10 = addr2;
23967 + if (stcclc == 0xF8)
23968 + regs->flags &= ~X86_EFLAGS_CF;
23969 + else
23970 + regs->flags |= X86_EFLAGS_CF;
23971 + regs->ip = addr1;
23972 + return 2;
23973 + }
23974 + } while (0);
23975 +
23976 + do { /* PaX: gcc trampoline emulation #1 */
23977 + unsigned short mov1, mov2, jmp1;
23978 + unsigned char jmp2;
23979 + unsigned int addr1;
23980 + unsigned long addr2;
23981 +
23982 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23983 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23984 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23985 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23986 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23987 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23988 +
23989 + if (err)
23990 + break;
23991 +
23992 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23993 + regs->r11 = addr1;
23994 + regs->r10 = addr2;
23995 + regs->ip = addr1;
23996 + return 2;
23997 + }
23998 + } while (0);
23999 +
24000 + do { /* PaX: gcc trampoline emulation #2 */
24001 + unsigned short mov1, mov2, jmp1;
24002 + unsigned char jmp2;
24003 + unsigned long addr1, addr2;
24004 +
24005 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24006 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24007 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24008 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24009 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24010 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24011 +
24012 + if (err)
24013 + break;
24014 +
24015 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24016 + regs->r11 = addr1;
24017 + regs->r10 = addr2;
24018 + regs->ip = addr1;
24019 + return 2;
24020 + }
24021 + } while (0);
24022 +
24023 + return 1; /* PaX in action */
24024 +}
24025 +#endif
24026 +
24027 +/*
24028 + * PaX: decide what to do with offenders (regs->ip = fault address)
24029 + *
24030 + * returns 1 when task should be killed
24031 + * 2 when gcc trampoline was detected
24032 + */
24033 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24034 +{
24035 + if (v8086_mode(regs))
24036 + return 1;
24037 +
24038 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24039 + return 1;
24040 +
24041 +#ifdef CONFIG_X86_32
24042 + return pax_handle_fetch_fault_32(regs);
24043 +#else
24044 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24045 + return pax_handle_fetch_fault_32(regs);
24046 + else
24047 + return pax_handle_fetch_fault_64(regs);
24048 +#endif
24049 +}
24050 +#endif
24051 +
24052 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24053 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24054 +{
24055 + long i;
24056 +
24057 + printk(KERN_ERR "PAX: bytes at PC: ");
24058 + for (i = 0; i < 20; i++) {
24059 + unsigned char c;
24060 + if (get_user(c, (unsigned char __force_user *)pc+i))
24061 + printk(KERN_CONT "?? ");
24062 + else
24063 + printk(KERN_CONT "%02x ", c);
24064 + }
24065 + printk("\n");
24066 +
24067 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24068 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24069 + unsigned long c;
24070 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24071 +#ifdef CONFIG_X86_32
24072 + printk(KERN_CONT "???????? ");
24073 +#else
24074 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24075 + printk(KERN_CONT "???????? ???????? ");
24076 + else
24077 + printk(KERN_CONT "???????????????? ");
24078 +#endif
24079 + } else {
24080 +#ifdef CONFIG_X86_64
24081 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24082 + printk(KERN_CONT "%08x ", (unsigned int)c);
24083 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24084 + } else
24085 +#endif
24086 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24087 + }
24088 + }
24089 + printk("\n");
24090 +}
24091 +#endif
24092 +
24093 +/**
24094 + * probe_kernel_write(): safely attempt to write to a location
24095 + * @dst: address to write to
24096 + * @src: pointer to the data that shall be written
24097 + * @size: size of the data chunk
24098 + *
24099 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24100 + * happens, handle that and return -EFAULT.
24101 + */
24102 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24103 +{
24104 + long ret;
24105 + mm_segment_t old_fs = get_fs();
24106 +
24107 + set_fs(KERNEL_DS);
24108 + pagefault_disable();
24109 + pax_open_kernel();
24110 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24111 + pax_close_kernel();
24112 + pagefault_enable();
24113 + set_fs(old_fs);
24114 +
24115 + return ret ? -EFAULT : 0;
24116 +}
24117 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24118 index dd74e46..7d26398 100644
24119 --- a/arch/x86/mm/gup.c
24120 +++ b/arch/x86/mm/gup.c
24121 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24122 addr = start;
24123 len = (unsigned long) nr_pages << PAGE_SHIFT;
24124 end = start + len;
24125 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24126 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24127 (void __user *)start, len)))
24128 return 0;
24129
24130 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24131 index f4f29b1..5cac4fb 100644
24132 --- a/arch/x86/mm/highmem_32.c
24133 +++ b/arch/x86/mm/highmem_32.c
24134 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24135 idx = type + KM_TYPE_NR*smp_processor_id();
24136 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24137 BUG_ON(!pte_none(*(kmap_pte-idx)));
24138 +
24139 + pax_open_kernel();
24140 set_pte(kmap_pte-idx, mk_pte(page, prot));
24141 + pax_close_kernel();
24142 +
24143 arch_flush_lazy_mmu_mode();
24144
24145 return (void *)vaddr;
24146 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24147 index 8ecbb4b..29efd37 100644
24148 --- a/arch/x86/mm/hugetlbpage.c
24149 +++ b/arch/x86/mm/hugetlbpage.c
24150 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24151 struct hstate *h = hstate_file(file);
24152 struct mm_struct *mm = current->mm;
24153 struct vm_area_struct *vma;
24154 - unsigned long start_addr;
24155 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24156 +
24157 +#ifdef CONFIG_PAX_SEGMEXEC
24158 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24159 + pax_task_size = SEGMEXEC_TASK_SIZE;
24160 +#endif
24161 +
24162 + pax_task_size -= PAGE_SIZE;
24163
24164 if (len > mm->cached_hole_size) {
24165 - start_addr = mm->free_area_cache;
24166 + start_addr = mm->free_area_cache;
24167 } else {
24168 - start_addr = TASK_UNMAPPED_BASE;
24169 - mm->cached_hole_size = 0;
24170 + start_addr = mm->mmap_base;
24171 + mm->cached_hole_size = 0;
24172 }
24173
24174 full_search:
24175 @@ -280,26 +287,27 @@ full_search:
24176
24177 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24178 /* At this point: (!vma || addr < vma->vm_end). */
24179 - if (TASK_SIZE - len < addr) {
24180 + if (pax_task_size - len < addr) {
24181 /*
24182 * Start a new search - just in case we missed
24183 * some holes.
24184 */
24185 - if (start_addr != TASK_UNMAPPED_BASE) {
24186 - start_addr = TASK_UNMAPPED_BASE;
24187 + if (start_addr != mm->mmap_base) {
24188 + start_addr = mm->mmap_base;
24189 mm->cached_hole_size = 0;
24190 goto full_search;
24191 }
24192 return -ENOMEM;
24193 }
24194 - if (!vma || addr + len <= vma->vm_start) {
24195 - mm->free_area_cache = addr + len;
24196 - return addr;
24197 - }
24198 + if (check_heap_stack_gap(vma, addr, len))
24199 + break;
24200 if (addr + mm->cached_hole_size < vma->vm_start)
24201 mm->cached_hole_size = vma->vm_start - addr;
24202 addr = ALIGN(vma->vm_end, huge_page_size(h));
24203 }
24204 +
24205 + mm->free_area_cache = addr + len;
24206 + return addr;
24207 }
24208
24209 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24210 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24211 {
24212 struct hstate *h = hstate_file(file);
24213 struct mm_struct *mm = current->mm;
24214 - struct vm_area_struct *vma, *prev_vma;
24215 - unsigned long base = mm->mmap_base, addr = addr0;
24216 + struct vm_area_struct *vma;
24217 + unsigned long base = mm->mmap_base, addr;
24218 unsigned long largest_hole = mm->cached_hole_size;
24219 - int first_time = 1;
24220
24221 /* don't allow allocations above current base */
24222 if (mm->free_area_cache > base)
24223 @@ -321,66 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24224 largest_hole = 0;
24225 mm->free_area_cache = base;
24226 }
24227 -try_again:
24228 +
24229 /* make sure it can fit in the remaining address space */
24230 if (mm->free_area_cache < len)
24231 goto fail;
24232
24233 /* either no address requested or can't fit in requested address hole */
24234 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24235 + addr = (mm->free_area_cache - len);
24236 do {
24237 + addr &= huge_page_mask(h);
24238 + vma = find_vma(mm, addr);
24239 /*
24240 * Lookup failure means no vma is above this address,
24241 * i.e. return with success:
24242 - */
24243 - vma = find_vma(mm, addr);
24244 - if (!vma)
24245 - return addr;
24246 -
24247 - /*
24248 * new region fits between prev_vma->vm_end and
24249 * vma->vm_start, use it:
24250 */
24251 - prev_vma = vma->vm_prev;
24252 - if (addr + len <= vma->vm_start &&
24253 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24254 + if (check_heap_stack_gap(vma, addr, len)) {
24255 /* remember the address as a hint for next time */
24256 - mm->cached_hole_size = largest_hole;
24257 - return (mm->free_area_cache = addr);
24258 - } else {
24259 - /* pull free_area_cache down to the first hole */
24260 - if (mm->free_area_cache == vma->vm_end) {
24261 - mm->free_area_cache = vma->vm_start;
24262 - mm->cached_hole_size = largest_hole;
24263 - }
24264 + mm->cached_hole_size = largest_hole;
24265 + return (mm->free_area_cache = addr);
24266 + }
24267 + /* pull free_area_cache down to the first hole */
24268 + if (mm->free_area_cache == vma->vm_end) {
24269 + mm->free_area_cache = vma->vm_start;
24270 + mm->cached_hole_size = largest_hole;
24271 }
24272
24273 /* remember the largest hole we saw so far */
24274 if (addr + largest_hole < vma->vm_start)
24275 - largest_hole = vma->vm_start - addr;
24276 + largest_hole = vma->vm_start - addr;
24277
24278 /* try just below the current vma->vm_start */
24279 - addr = (vma->vm_start - len) & huge_page_mask(h);
24280 - } while (len <= vma->vm_start);
24281 + addr = skip_heap_stack_gap(vma, len);
24282 + } while (!IS_ERR_VALUE(addr));
24283
24284 fail:
24285 /*
24286 - * if hint left us with no space for the requested
24287 - * mapping then try again:
24288 - */
24289 - if (first_time) {
24290 - mm->free_area_cache = base;
24291 - largest_hole = 0;
24292 - first_time = 0;
24293 - goto try_again;
24294 - }
24295 - /*
24296 * A failed mmap() very likely causes application failure,
24297 * so fall back to the bottom-up function here. This scenario
24298 * can happen with large stack limits and large mmap()
24299 * allocations.
24300 */
24301 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24302 +
24303 +#ifdef CONFIG_PAX_SEGMEXEC
24304 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24305 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24306 + else
24307 +#endif
24308 +
24309 + mm->mmap_base = TASK_UNMAPPED_BASE;
24310 +
24311 +#ifdef CONFIG_PAX_RANDMMAP
24312 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24313 + mm->mmap_base += mm->delta_mmap;
24314 +#endif
24315 +
24316 + mm->free_area_cache = mm->mmap_base;
24317 mm->cached_hole_size = ~0UL;
24318 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24319 len, pgoff, flags);
24320 @@ -388,6 +392,7 @@ fail:
24321 /*
24322 * Restore the topdown base:
24323 */
24324 + mm->mmap_base = base;
24325 mm->free_area_cache = base;
24326 mm->cached_hole_size = ~0UL;
24327
24328 @@ -401,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24329 struct hstate *h = hstate_file(file);
24330 struct mm_struct *mm = current->mm;
24331 struct vm_area_struct *vma;
24332 + unsigned long pax_task_size = TASK_SIZE;
24333
24334 if (len & ~huge_page_mask(h))
24335 return -EINVAL;
24336 - if (len > TASK_SIZE)
24337 +
24338 +#ifdef CONFIG_PAX_SEGMEXEC
24339 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24340 + pax_task_size = SEGMEXEC_TASK_SIZE;
24341 +#endif
24342 +
24343 + pax_task_size -= PAGE_SIZE;
24344 +
24345 + if (len > pax_task_size)
24346 return -ENOMEM;
24347
24348 if (flags & MAP_FIXED) {
24349 @@ -416,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24350 if (addr) {
24351 addr = ALIGN(addr, huge_page_size(h));
24352 vma = find_vma(mm, addr);
24353 - if (TASK_SIZE - len >= addr &&
24354 - (!vma || addr + len <= vma->vm_start))
24355 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24356 return addr;
24357 }
24358 if (mm->get_unmapped_area == arch_get_unmapped_area)
24359 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24360 index 6cabf65..77e9c1c 100644
24361 --- a/arch/x86/mm/init.c
24362 +++ b/arch/x86/mm/init.c
24363 @@ -17,6 +17,7 @@
24364 #include <asm/tlb.h>
24365 #include <asm/proto.h>
24366 #include <asm/dma.h> /* for MAX_DMA_PFN */
24367 +#include <asm/desc.h>
24368
24369 unsigned long __initdata pgt_buf_start;
24370 unsigned long __meminitdata pgt_buf_end;
24371 @@ -33,7 +34,7 @@ int direct_gbpages
24372 static void __init find_early_table_space(unsigned long end, int use_pse,
24373 int use_gbpages)
24374 {
24375 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24376 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24377 phys_addr_t base;
24378
24379 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24380 @@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24381 */
24382 int devmem_is_allowed(unsigned long pagenr)
24383 {
24384 +#ifdef CONFIG_GRKERNSEC_KMEM
24385 + /* allow BDA */
24386 + if (!pagenr)
24387 + return 1;
24388 + /* allow EBDA */
24389 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24390 + return 1;
24391 +#else
24392 + if (!pagenr)
24393 + return 1;
24394 +#ifdef CONFIG_VM86
24395 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24396 + return 1;
24397 +#endif
24398 +#endif
24399 +
24400 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24401 + return 1;
24402 +#ifdef CONFIG_GRKERNSEC_KMEM
24403 + /* throw out everything else below 1MB */
24404 if (pagenr <= 256)
24405 - return 1;
24406 + return 0;
24407 +#endif
24408 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24409 return 0;
24410 if (!page_is_ram(pagenr))
24411 @@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24412
24413 void free_initmem(void)
24414 {
24415 +
24416 +#ifdef CONFIG_PAX_KERNEXEC
24417 +#ifdef CONFIG_X86_32
24418 + /* PaX: limit KERNEL_CS to actual size */
24419 + unsigned long addr, limit;
24420 + struct desc_struct d;
24421 + int cpu;
24422 +
24423 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24424 + limit = (limit - 1UL) >> PAGE_SHIFT;
24425 +
24426 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24427 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24428 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24429 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24430 + }
24431 +
24432 + /* PaX: make KERNEL_CS read-only */
24433 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24434 + if (!paravirt_enabled())
24435 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24436 +/*
24437 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24438 + pgd = pgd_offset_k(addr);
24439 + pud = pud_offset(pgd, addr);
24440 + pmd = pmd_offset(pud, addr);
24441 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24442 + }
24443 +*/
24444 +#ifdef CONFIG_X86_PAE
24445 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24446 +/*
24447 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24448 + pgd = pgd_offset_k(addr);
24449 + pud = pud_offset(pgd, addr);
24450 + pmd = pmd_offset(pud, addr);
24451 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24452 + }
24453 +*/
24454 +#endif
24455 +
24456 +#ifdef CONFIG_MODULES
24457 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24458 +#endif
24459 +
24460 +#else
24461 + pgd_t *pgd;
24462 + pud_t *pud;
24463 + pmd_t *pmd;
24464 + unsigned long addr, end;
24465 +
24466 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24467 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24468 + pgd = pgd_offset_k(addr);
24469 + pud = pud_offset(pgd, addr);
24470 + pmd = pmd_offset(pud, addr);
24471 + if (!pmd_present(*pmd))
24472 + continue;
24473 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24474 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24475 + else
24476 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24477 + }
24478 +
24479 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24480 + end = addr + KERNEL_IMAGE_SIZE;
24481 + for (; addr < end; addr += PMD_SIZE) {
24482 + pgd = pgd_offset_k(addr);
24483 + pud = pud_offset(pgd, addr);
24484 + pmd = pmd_offset(pud, addr);
24485 + if (!pmd_present(*pmd))
24486 + continue;
24487 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24488 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24489 + }
24490 +#endif
24491 +
24492 + flush_tlb_all();
24493 +#endif
24494 +
24495 free_init_pages("unused kernel memory",
24496 (unsigned long)(&__init_begin),
24497 (unsigned long)(&__init_end));
24498 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24499 index 8663f6c..829ae76 100644
24500 --- a/arch/x86/mm/init_32.c
24501 +++ b/arch/x86/mm/init_32.c
24502 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24503 }
24504
24505 /*
24506 - * Creates a middle page table and puts a pointer to it in the
24507 - * given global directory entry. This only returns the gd entry
24508 - * in non-PAE compilation mode, since the middle layer is folded.
24509 - */
24510 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24511 -{
24512 - pud_t *pud;
24513 - pmd_t *pmd_table;
24514 -
24515 -#ifdef CONFIG_X86_PAE
24516 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24517 - if (after_bootmem)
24518 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24519 - else
24520 - pmd_table = (pmd_t *)alloc_low_page();
24521 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24522 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24523 - pud = pud_offset(pgd, 0);
24524 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24525 -
24526 - return pmd_table;
24527 - }
24528 -#endif
24529 - pud = pud_offset(pgd, 0);
24530 - pmd_table = pmd_offset(pud, 0);
24531 -
24532 - return pmd_table;
24533 -}
24534 -
24535 -/*
24536 * Create a page table and place a pointer to it in a middle page
24537 * directory entry:
24538 */
24539 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24540 page_table = (pte_t *)alloc_low_page();
24541
24542 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24543 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24544 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24545 +#else
24546 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24547 +#endif
24548 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24549 }
24550
24551 return pte_offset_kernel(pmd, 0);
24552 }
24553
24554 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24555 +{
24556 + pud_t *pud;
24557 + pmd_t *pmd_table;
24558 +
24559 + pud = pud_offset(pgd, 0);
24560 + pmd_table = pmd_offset(pud, 0);
24561 +
24562 + return pmd_table;
24563 +}
24564 +
24565 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24566 {
24567 int pgd_idx = pgd_index(vaddr);
24568 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24569 int pgd_idx, pmd_idx;
24570 unsigned long vaddr;
24571 pgd_t *pgd;
24572 + pud_t *pud;
24573 pmd_t *pmd;
24574 pte_t *pte = NULL;
24575
24576 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24577 pgd = pgd_base + pgd_idx;
24578
24579 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24580 - pmd = one_md_table_init(pgd);
24581 - pmd = pmd + pmd_index(vaddr);
24582 + pud = pud_offset(pgd, vaddr);
24583 + pmd = pmd_offset(pud, vaddr);
24584 +
24585 +#ifdef CONFIG_X86_PAE
24586 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24587 +#endif
24588 +
24589 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24590 pmd++, pmd_idx++) {
24591 pte = page_table_kmap_check(one_page_table_init(pmd),
24592 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24593 }
24594 }
24595
24596 -static inline int is_kernel_text(unsigned long addr)
24597 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24598 {
24599 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24600 - return 1;
24601 - return 0;
24602 + if ((start > ktla_ktva((unsigned long)_etext) ||
24603 + end <= ktla_ktva((unsigned long)_stext)) &&
24604 + (start > ktla_ktva((unsigned long)_einittext) ||
24605 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24606 +
24607 +#ifdef CONFIG_ACPI_SLEEP
24608 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24609 +#endif
24610 +
24611 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24612 + return 0;
24613 + return 1;
24614 }
24615
24616 /*
24617 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24618 unsigned long last_map_addr = end;
24619 unsigned long start_pfn, end_pfn;
24620 pgd_t *pgd_base = swapper_pg_dir;
24621 - int pgd_idx, pmd_idx, pte_ofs;
24622 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24623 unsigned long pfn;
24624 pgd_t *pgd;
24625 + pud_t *pud;
24626 pmd_t *pmd;
24627 pte_t *pte;
24628 unsigned pages_2m, pages_4k;
24629 @@ -281,8 +282,13 @@ repeat:
24630 pfn = start_pfn;
24631 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24632 pgd = pgd_base + pgd_idx;
24633 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24634 - pmd = one_md_table_init(pgd);
24635 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24636 + pud = pud_offset(pgd, 0);
24637 + pmd = pmd_offset(pud, 0);
24638 +
24639 +#ifdef CONFIG_X86_PAE
24640 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24641 +#endif
24642
24643 if (pfn >= end_pfn)
24644 continue;
24645 @@ -294,14 +300,13 @@ repeat:
24646 #endif
24647 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24648 pmd++, pmd_idx++) {
24649 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24650 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24651
24652 /*
24653 * Map with big pages if possible, otherwise
24654 * create normal page tables:
24655 */
24656 if (use_pse) {
24657 - unsigned int addr2;
24658 pgprot_t prot = PAGE_KERNEL_LARGE;
24659 /*
24660 * first pass will use the same initial
24661 @@ -311,11 +316,7 @@ repeat:
24662 __pgprot(PTE_IDENT_ATTR |
24663 _PAGE_PSE);
24664
24665 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24666 - PAGE_OFFSET + PAGE_SIZE-1;
24667 -
24668 - if (is_kernel_text(addr) ||
24669 - is_kernel_text(addr2))
24670 + if (is_kernel_text(address, address + PMD_SIZE))
24671 prot = PAGE_KERNEL_LARGE_EXEC;
24672
24673 pages_2m++;
24674 @@ -332,7 +333,7 @@ repeat:
24675 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24676 pte += pte_ofs;
24677 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24678 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24679 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24680 pgprot_t prot = PAGE_KERNEL;
24681 /*
24682 * first pass will use the same initial
24683 @@ -340,7 +341,7 @@ repeat:
24684 */
24685 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24686
24687 - if (is_kernel_text(addr))
24688 + if (is_kernel_text(address, address + PAGE_SIZE))
24689 prot = PAGE_KERNEL_EXEC;
24690
24691 pages_4k++;
24692 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24693
24694 pud = pud_offset(pgd, va);
24695 pmd = pmd_offset(pud, va);
24696 - if (!pmd_present(*pmd))
24697 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24698 break;
24699
24700 pte = pte_offset_kernel(pmd, va);
24701 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24702
24703 static void __init pagetable_init(void)
24704 {
24705 - pgd_t *pgd_base = swapper_pg_dir;
24706 -
24707 - permanent_kmaps_init(pgd_base);
24708 + permanent_kmaps_init(swapper_pg_dir);
24709 }
24710
24711 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24712 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24713 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24714
24715 /* user-defined highmem size */
24716 @@ -735,6 +734,12 @@ void __init mem_init(void)
24717
24718 pci_iommu_alloc();
24719
24720 +#ifdef CONFIG_PAX_PER_CPU_PGD
24721 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24722 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24723 + KERNEL_PGD_PTRS);
24724 +#endif
24725 +
24726 #ifdef CONFIG_FLATMEM
24727 BUG_ON(!mem_map);
24728 #endif
24729 @@ -761,7 +766,7 @@ void __init mem_init(void)
24730 reservedpages++;
24731
24732 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24733 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24734 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24735 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24736
24737 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24738 @@ -802,10 +807,10 @@ void __init mem_init(void)
24739 ((unsigned long)&__init_end -
24740 (unsigned long)&__init_begin) >> 10,
24741
24742 - (unsigned long)&_etext, (unsigned long)&_edata,
24743 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24744 + (unsigned long)&_sdata, (unsigned long)&_edata,
24745 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24746
24747 - (unsigned long)&_text, (unsigned long)&_etext,
24748 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24749 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24750
24751 /*
24752 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24753 if (!kernel_set_to_readonly)
24754 return;
24755
24756 + start = ktla_ktva(start);
24757 pr_debug("Set kernel text: %lx - %lx for read write\n",
24758 start, start+size);
24759
24760 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24761 if (!kernel_set_to_readonly)
24762 return;
24763
24764 + start = ktla_ktva(start);
24765 pr_debug("Set kernel text: %lx - %lx for read only\n",
24766 start, start+size);
24767
24768 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24769 unsigned long start = PFN_ALIGN(_text);
24770 unsigned long size = PFN_ALIGN(_etext) - start;
24771
24772 + start = ktla_ktva(start);
24773 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24774 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24775 size >> 10);
24776 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24777 index 436a030..b8596b9 100644
24778 --- a/arch/x86/mm/init_64.c
24779 +++ b/arch/x86/mm/init_64.c
24780 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24781 * around without checking the pgd every time.
24782 */
24783
24784 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24785 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24786 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24787
24788 int force_personality32;
24789 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24790
24791 for (address = start; address <= end; address += PGDIR_SIZE) {
24792 const pgd_t *pgd_ref = pgd_offset_k(address);
24793 +
24794 +#ifdef CONFIG_PAX_PER_CPU_PGD
24795 + unsigned long cpu;
24796 +#else
24797 struct page *page;
24798 +#endif
24799
24800 if (pgd_none(*pgd_ref))
24801 continue;
24802
24803 spin_lock(&pgd_lock);
24804 +
24805 +#ifdef CONFIG_PAX_PER_CPU_PGD
24806 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24807 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24808 +#else
24809 list_for_each_entry(page, &pgd_list, lru) {
24810 pgd_t *pgd;
24811 spinlock_t *pgt_lock;
24812 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24813 /* the pgt_lock only for Xen */
24814 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24815 spin_lock(pgt_lock);
24816 +#endif
24817
24818 if (pgd_none(*pgd))
24819 set_pgd(pgd, *pgd_ref);
24820 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24821 BUG_ON(pgd_page_vaddr(*pgd)
24822 != pgd_page_vaddr(*pgd_ref));
24823
24824 +#ifndef CONFIG_PAX_PER_CPU_PGD
24825 spin_unlock(pgt_lock);
24826 +#endif
24827 +
24828 }
24829 spin_unlock(&pgd_lock);
24830 }
24831 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24832 pmd = fill_pmd(pud, vaddr);
24833 pte = fill_pte(pmd, vaddr);
24834
24835 + pax_open_kernel();
24836 set_pte(pte, new_pte);
24837 + pax_close_kernel();
24838
24839 /*
24840 * It's enough to flush this one mapping.
24841 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24842 pgd = pgd_offset_k((unsigned long)__va(phys));
24843 if (pgd_none(*pgd)) {
24844 pud = (pud_t *) spp_getpage();
24845 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24846 - _PAGE_USER));
24847 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24848 }
24849 pud = pud_offset(pgd, (unsigned long)__va(phys));
24850 if (pud_none(*pud)) {
24851 pmd = (pmd_t *) spp_getpage();
24852 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24853 - _PAGE_USER));
24854 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24855 }
24856 pmd = pmd_offset(pud, phys);
24857 BUG_ON(!pmd_none(*pmd));
24858 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24859 if (pfn >= pgt_buf_top)
24860 panic("alloc_low_page: ran out of memory");
24861
24862 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24863 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24864 clear_page(adr);
24865 *phys = pfn * PAGE_SIZE;
24866 return adr;
24867 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24868
24869 phys = __pa(virt);
24870 left = phys & (PAGE_SIZE - 1);
24871 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24872 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24873 adr = (void *)(((unsigned long)adr) | left);
24874
24875 return adr;
24876 @@ -684,6 +698,12 @@ void __init mem_init(void)
24877
24878 pci_iommu_alloc();
24879
24880 +#ifdef CONFIG_PAX_PER_CPU_PGD
24881 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24882 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24883 + KERNEL_PGD_PTRS);
24884 +#endif
24885 +
24886 /* clear_bss() already clear the empty_zero_page */
24887
24888 reservedpages = 0;
24889 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
24890 static struct vm_area_struct gate_vma = {
24891 .vm_start = VSYSCALL_START,
24892 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24893 - .vm_page_prot = PAGE_READONLY_EXEC,
24894 - .vm_flags = VM_READ | VM_EXEC
24895 + .vm_page_prot = PAGE_READONLY,
24896 + .vm_flags = VM_READ
24897 };
24898
24899 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24900 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
24901
24902 const char *arch_vma_name(struct vm_area_struct *vma)
24903 {
24904 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24905 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24906 return "[vdso]";
24907 if (vma == &gate_vma)
24908 return "[vsyscall]";
24909 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24910 index 7b179b4..6bd1777 100644
24911 --- a/arch/x86/mm/iomap_32.c
24912 +++ b/arch/x86/mm/iomap_32.c
24913 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24914 type = kmap_atomic_idx_push();
24915 idx = type + KM_TYPE_NR * smp_processor_id();
24916 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24917 +
24918 + pax_open_kernel();
24919 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24920 + pax_close_kernel();
24921 +
24922 arch_flush_lazy_mmu_mode();
24923
24924 return (void *)vaddr;
24925 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24926 index be1ef57..55f0160 100644
24927 --- a/arch/x86/mm/ioremap.c
24928 +++ b/arch/x86/mm/ioremap.c
24929 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24930 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24931 int is_ram = page_is_ram(pfn);
24932
24933 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24934 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24935 return NULL;
24936 WARN_ON_ONCE(is_ram);
24937 }
24938 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24939
24940 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24941 if (page_is_ram(start >> PAGE_SHIFT))
24942 +#ifdef CONFIG_HIGHMEM
24943 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24944 +#endif
24945 return __va(phys);
24946
24947 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24948 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24949 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24950
24951 static __initdata int after_paging_init;
24952 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24953 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24954
24955 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24956 {
24957 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24958 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24959
24960 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24961 - memset(bm_pte, 0, sizeof(bm_pte));
24962 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24963 + pmd_populate_user(&init_mm, pmd, bm_pte);
24964
24965 /*
24966 * The boot-ioremap range spans multiple pmds, for which
24967 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24968 index d87dd6d..bf3fa66 100644
24969 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24970 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24971 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24972 * memory (e.g. tracked pages)? For now, we need this to avoid
24973 * invoking kmemcheck for PnP BIOS calls.
24974 */
24975 - if (regs->flags & X86_VM_MASK)
24976 + if (v8086_mode(regs))
24977 return false;
24978 - if (regs->cs != __KERNEL_CS)
24979 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24980 return false;
24981
24982 pte = kmemcheck_pte_lookup(address);
24983 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24984 index 845df68..1d8d29f 100644
24985 --- a/arch/x86/mm/mmap.c
24986 +++ b/arch/x86/mm/mmap.c
24987 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24988 * Leave an at least ~128 MB hole with possible stack randomization.
24989 */
24990 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24991 -#define MAX_GAP (TASK_SIZE/6*5)
24992 +#define MAX_GAP (pax_task_size/6*5)
24993
24994 static int mmap_is_legacy(void)
24995 {
24996 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24997 return rnd << PAGE_SHIFT;
24998 }
24999
25000 -static unsigned long mmap_base(void)
25001 +static unsigned long mmap_base(struct mm_struct *mm)
25002 {
25003 unsigned long gap = rlimit(RLIMIT_STACK);
25004 + unsigned long pax_task_size = TASK_SIZE;
25005 +
25006 +#ifdef CONFIG_PAX_SEGMEXEC
25007 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25008 + pax_task_size = SEGMEXEC_TASK_SIZE;
25009 +#endif
25010
25011 if (gap < MIN_GAP)
25012 gap = MIN_GAP;
25013 else if (gap > MAX_GAP)
25014 gap = MAX_GAP;
25015
25016 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25017 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25018 }
25019
25020 /*
25021 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25022 * does, but not when emulating X86_32
25023 */
25024 -static unsigned long mmap_legacy_base(void)
25025 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25026 {
25027 - if (mmap_is_ia32())
25028 + if (mmap_is_ia32()) {
25029 +
25030 +#ifdef CONFIG_PAX_SEGMEXEC
25031 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25032 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25033 + else
25034 +#endif
25035 +
25036 return TASK_UNMAPPED_BASE;
25037 - else
25038 + } else
25039 return TASK_UNMAPPED_BASE + mmap_rnd();
25040 }
25041
25042 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25043 void arch_pick_mmap_layout(struct mm_struct *mm)
25044 {
25045 if (mmap_is_legacy()) {
25046 - mm->mmap_base = mmap_legacy_base();
25047 + mm->mmap_base = mmap_legacy_base(mm);
25048 +
25049 +#ifdef CONFIG_PAX_RANDMMAP
25050 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25051 + mm->mmap_base += mm->delta_mmap;
25052 +#endif
25053 +
25054 mm->get_unmapped_area = arch_get_unmapped_area;
25055 mm->unmap_area = arch_unmap_area;
25056 } else {
25057 - mm->mmap_base = mmap_base();
25058 + mm->mmap_base = mmap_base(mm);
25059 +
25060 +#ifdef CONFIG_PAX_RANDMMAP
25061 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25062 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25063 +#endif
25064 +
25065 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25066 mm->unmap_area = arch_unmap_area_topdown;
25067 }
25068 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25069 index dc0b727..dc9d71a 100644
25070 --- a/arch/x86/mm/mmio-mod.c
25071 +++ b/arch/x86/mm/mmio-mod.c
25072 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25073 break;
25074 default:
25075 {
25076 - unsigned char *ip = (unsigned char *)instptr;
25077 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25078 my_trace->opcode = MMIO_UNKNOWN_OP;
25079 my_trace->width = 0;
25080 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25081 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25082 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25083 void __iomem *addr)
25084 {
25085 - static atomic_t next_id;
25086 + static atomic_unchecked_t next_id;
25087 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25088 /* These are page-unaligned. */
25089 struct mmiotrace_map map = {
25090 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25091 .private = trace
25092 },
25093 .phys = offset,
25094 - .id = atomic_inc_return(&next_id)
25095 + .id = atomic_inc_return_unchecked(&next_id)
25096 };
25097 map.map_id = trace->id;
25098
25099 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25100 index b008656..773eac2 100644
25101 --- a/arch/x86/mm/pageattr-test.c
25102 +++ b/arch/x86/mm/pageattr-test.c
25103 @@ -36,7 +36,7 @@ enum {
25104
25105 static int pte_testbit(pte_t pte)
25106 {
25107 - return pte_flags(pte) & _PAGE_UNUSED1;
25108 + return pte_flags(pte) & _PAGE_CPA_TEST;
25109 }
25110
25111 struct split_state {
25112 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25113 index e1ebde3..b1e1db38 100644
25114 --- a/arch/x86/mm/pageattr.c
25115 +++ b/arch/x86/mm/pageattr.c
25116 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25117 */
25118 #ifdef CONFIG_PCI_BIOS
25119 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25120 - pgprot_val(forbidden) |= _PAGE_NX;
25121 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25122 #endif
25123
25124 /*
25125 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25126 * Does not cover __inittext since that is gone later on. On
25127 * 64bit we do not enforce !NX on the low mapping
25128 */
25129 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25130 - pgprot_val(forbidden) |= _PAGE_NX;
25131 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25132 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25133
25134 +#ifdef CONFIG_DEBUG_RODATA
25135 /*
25136 * The .rodata section needs to be read-only. Using the pfn
25137 * catches all aliases.
25138 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25139 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25140 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25141 pgprot_val(forbidden) |= _PAGE_RW;
25142 +#endif
25143
25144 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25145 /*
25146 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25147 }
25148 #endif
25149
25150 +#ifdef CONFIG_PAX_KERNEXEC
25151 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25152 + pgprot_val(forbidden) |= _PAGE_RW;
25153 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25154 + }
25155 +#endif
25156 +
25157 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25158
25159 return prot;
25160 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25161 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25162 {
25163 /* change init_mm */
25164 + pax_open_kernel();
25165 set_pte_atomic(kpte, pte);
25166 +
25167 #ifdef CONFIG_X86_32
25168 if (!SHARED_KERNEL_PMD) {
25169 +
25170 +#ifdef CONFIG_PAX_PER_CPU_PGD
25171 + unsigned long cpu;
25172 +#else
25173 struct page *page;
25174 +#endif
25175
25176 +#ifdef CONFIG_PAX_PER_CPU_PGD
25177 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25178 + pgd_t *pgd = get_cpu_pgd(cpu);
25179 +#else
25180 list_for_each_entry(page, &pgd_list, lru) {
25181 - pgd_t *pgd;
25182 + pgd_t *pgd = (pgd_t *)page_address(page);
25183 +#endif
25184 +
25185 pud_t *pud;
25186 pmd_t *pmd;
25187
25188 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25189 + pgd += pgd_index(address);
25190 pud = pud_offset(pgd, address);
25191 pmd = pmd_offset(pud, address);
25192 set_pte_atomic((pte_t *)pmd, pte);
25193 }
25194 }
25195 #endif
25196 + pax_close_kernel();
25197 }
25198
25199 static int
25200 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25201 index f6ff57b..481690f 100644
25202 --- a/arch/x86/mm/pat.c
25203 +++ b/arch/x86/mm/pat.c
25204 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25205
25206 if (!entry) {
25207 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25208 - current->comm, current->pid, start, end);
25209 + current->comm, task_pid_nr(current), start, end);
25210 return -EINVAL;
25211 }
25212
25213 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25214 while (cursor < to) {
25215 if (!devmem_is_allowed(pfn)) {
25216 printk(KERN_INFO
25217 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25218 - current->comm, from, to);
25219 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25220 + current->comm, from, to, cursor);
25221 return 0;
25222 }
25223 cursor += PAGE_SIZE;
25224 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25225 printk(KERN_INFO
25226 "%s:%d ioremap_change_attr failed %s "
25227 "for %Lx-%Lx\n",
25228 - current->comm, current->pid,
25229 + current->comm, task_pid_nr(current),
25230 cattr_name(flags),
25231 base, (unsigned long long)(base + size));
25232 return -EINVAL;
25233 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25234 if (want_flags != flags) {
25235 printk(KERN_WARNING
25236 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25237 - current->comm, current->pid,
25238 + current->comm, task_pid_nr(current),
25239 cattr_name(want_flags),
25240 (unsigned long long)paddr,
25241 (unsigned long long)(paddr + size),
25242 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25243 free_memtype(paddr, paddr + size);
25244 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25245 " for %Lx-%Lx, got %s\n",
25246 - current->comm, current->pid,
25247 + current->comm, task_pid_nr(current),
25248 cattr_name(want_flags),
25249 (unsigned long long)paddr,
25250 (unsigned long long)(paddr + size),
25251 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25252 index 9f0614d..92ae64a 100644
25253 --- a/arch/x86/mm/pf_in.c
25254 +++ b/arch/x86/mm/pf_in.c
25255 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25256 int i;
25257 enum reason_type rv = OTHERS;
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
25264 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25265 struct prefix_bits prf;
25266 int i;
25267
25268 - p = (unsigned char *)ins_addr;
25269 + p = (unsigned char *)ktla_ktva(ins_addr);
25270 p += skip_prefix(p, &prf);
25271 p += get_opcode(p, &opcode);
25272
25273 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25274 struct prefix_bits prf;
25275 int i;
25276
25277 - p = (unsigned char *)ins_addr;
25278 + p = (unsigned char *)ktla_ktva(ins_addr);
25279 p += skip_prefix(p, &prf);
25280 p += get_opcode(p, &opcode);
25281
25282 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25283 struct prefix_bits prf;
25284 int i;
25285
25286 - p = (unsigned char *)ins_addr;
25287 + p = (unsigned char *)ktla_ktva(ins_addr);
25288 p += skip_prefix(p, &prf);
25289 p += get_opcode(p, &opcode);
25290 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25291 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25292 struct prefix_bits prf;
25293 int i;
25294
25295 - p = (unsigned char *)ins_addr;
25296 + p = (unsigned char *)ktla_ktva(ins_addr);
25297 p += skip_prefix(p, &prf);
25298 p += get_opcode(p, &opcode);
25299 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25300 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25301 index 8573b83..7d9628f 100644
25302 --- a/arch/x86/mm/pgtable.c
25303 +++ b/arch/x86/mm/pgtable.c
25304 @@ -84,10 +84,60 @@ static inline void pgd_list_del(pgd_t *pgd)
25305 list_del(&page->lru);
25306 }
25307
25308 -#define UNSHARED_PTRS_PER_PGD \
25309 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25310 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25311 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25312
25313 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25314 +{
25315 + while (count--)
25316 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25317 +}
25318 +#endif
25319
25320 +#ifdef CONFIG_PAX_PER_CPU_PGD
25321 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25322 +{
25323 + while (count--) {
25324 + pgd_t pgd;
25325 +
25326 +#ifdef CONFIG_X86_64
25327 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25328 +#else
25329 + pgd = *src++;
25330 +#endif
25331 +
25332 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25333 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25334 +#endif
25335 +
25336 + *dst++ = pgd;
25337 + }
25338 +
25339 +}
25340 +#endif
25341 +
25342 +#ifdef CONFIG_X86_64
25343 +#define pxd_t pud_t
25344 +#define pyd_t pgd_t
25345 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25346 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25347 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25348 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25349 +#define PYD_SIZE PGDIR_SIZE
25350 +#else
25351 +#define pxd_t pmd_t
25352 +#define pyd_t pud_t
25353 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25354 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25355 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25356 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25357 +#define PYD_SIZE PUD_SIZE
25358 +#endif
25359 +
25360 +#ifdef CONFIG_PAX_PER_CPU_PGD
25361 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25362 +static inline void pgd_dtor(pgd_t *pgd) {}
25363 +#else
25364 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25365 {
25366 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25367 @@ -128,6 +178,7 @@ static void pgd_dtor(pgd_t *pgd)
25368 pgd_list_del(pgd);
25369 spin_unlock(&pgd_lock);
25370 }
25371 +#endif
25372
25373 /*
25374 * List of all pgd's needed for non-PAE so it can invalidate entries
25375 @@ -140,7 +191,7 @@ static void pgd_dtor(pgd_t *pgd)
25376 * -- wli
25377 */
25378
25379 -#ifdef CONFIG_X86_PAE
25380 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25381 /*
25382 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25383 * updating the top-level pagetable entries to guarantee the
25384 @@ -152,7 +203,7 @@ static void pgd_dtor(pgd_t *pgd)
25385 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25386 * and initialize the kernel pmds here.
25387 */
25388 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25389 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25390
25391 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25392 {
25393 @@ -170,36 +221,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25394 */
25395 flush_tlb_mm(mm);
25396 }
25397 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25398 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25399 #else /* !CONFIG_X86_PAE */
25400
25401 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25402 -#define PREALLOCATED_PMDS 0
25403 +#define PREALLOCATED_PXDS 0
25404
25405 #endif /* CONFIG_X86_PAE */
25406
25407 -static void free_pmds(pmd_t *pmds[])
25408 +static void free_pxds(pxd_t *pxds[])
25409 {
25410 int i;
25411
25412 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25413 - if (pmds[i])
25414 - free_page((unsigned long)pmds[i]);
25415 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25416 + if (pxds[i])
25417 + free_page((unsigned long)pxds[i]);
25418 }
25419
25420 -static int preallocate_pmds(pmd_t *pmds[])
25421 +static int preallocate_pxds(pxd_t *pxds[])
25422 {
25423 int i;
25424 bool failed = false;
25425
25426 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25427 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25428 - if (pmd == NULL)
25429 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25430 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25431 + if (pxd == NULL)
25432 failed = true;
25433 - pmds[i] = pmd;
25434 + pxds[i] = pxd;
25435 }
25436
25437 if (failed) {
25438 - free_pmds(pmds);
25439 + free_pxds(pxds);
25440 return -ENOMEM;
25441 }
25442
25443 @@ -212,51 +265,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25444 * preallocate which never got a corresponding vma will need to be
25445 * freed manually.
25446 */
25447 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25448 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25449 {
25450 int i;
25451
25452 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25453 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25454 pgd_t pgd = pgdp[i];
25455
25456 if (pgd_val(pgd) != 0) {
25457 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25458 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25459
25460 - pgdp[i] = native_make_pgd(0);
25461 + set_pgd(pgdp + i, native_make_pgd(0));
25462
25463 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25464 - pmd_free(mm, pmd);
25465 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25466 + pxd_free(mm, pxd);
25467 }
25468 }
25469 }
25470
25471 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25472 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25473 {
25474 - pud_t *pud;
25475 + pyd_t *pyd;
25476 unsigned long addr;
25477 int i;
25478
25479 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25480 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25481 return;
25482
25483 - pud = pud_offset(pgd, 0);
25484 +#ifdef CONFIG_X86_64
25485 + pyd = pyd_offset(mm, 0L);
25486 +#else
25487 + pyd = pyd_offset(pgd, 0L);
25488 +#endif
25489
25490 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25491 - i++, pud++, addr += PUD_SIZE) {
25492 - pmd_t *pmd = pmds[i];
25493 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25494 + i++, pyd++, addr += PYD_SIZE) {
25495 + pxd_t *pxd = pxds[i];
25496
25497 if (i >= KERNEL_PGD_BOUNDARY)
25498 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25499 - sizeof(pmd_t) * PTRS_PER_PMD);
25500 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25501 + sizeof(pxd_t) * PTRS_PER_PMD);
25502
25503 - pud_populate(mm, pud, pmd);
25504 + pyd_populate(mm, pyd, pxd);
25505 }
25506 }
25507
25508 pgd_t *pgd_alloc(struct mm_struct *mm)
25509 {
25510 pgd_t *pgd;
25511 - pmd_t *pmds[PREALLOCATED_PMDS];
25512 + pxd_t *pxds[PREALLOCATED_PXDS];
25513
25514 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25515
25516 @@ -265,11 +322,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25517
25518 mm->pgd = pgd;
25519
25520 - if (preallocate_pmds(pmds) != 0)
25521 + if (preallocate_pxds(pxds) != 0)
25522 goto out_free_pgd;
25523
25524 if (paravirt_pgd_alloc(mm) != 0)
25525 - goto out_free_pmds;
25526 + goto out_free_pxds;
25527
25528 /*
25529 * Make sure that pre-populating the pmds is atomic with
25530 @@ -279,14 +336,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25531 spin_lock(&pgd_lock);
25532
25533 pgd_ctor(mm, pgd);
25534 - pgd_prepopulate_pmd(mm, pgd, pmds);
25535 + pgd_prepopulate_pxd(mm, pgd, pxds);
25536
25537 spin_unlock(&pgd_lock);
25538
25539 return pgd;
25540
25541 -out_free_pmds:
25542 - free_pmds(pmds);
25543 +out_free_pxds:
25544 + free_pxds(pxds);
25545 out_free_pgd:
25546 free_page((unsigned long)pgd);
25547 out:
25548 @@ -295,7 +352,7 @@ out:
25549
25550 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25551 {
25552 - pgd_mop_up_pmds(mm, pgd);
25553 + pgd_mop_up_pxds(mm, pgd);
25554 pgd_dtor(pgd);
25555 paravirt_pgd_free(mm, pgd);
25556 free_page((unsigned long)pgd);
25557 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25558 index cac7184..09a39fa 100644
25559 --- a/arch/x86/mm/pgtable_32.c
25560 +++ b/arch/x86/mm/pgtable_32.c
25561 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25562 return;
25563 }
25564 pte = pte_offset_kernel(pmd, vaddr);
25565 +
25566 + pax_open_kernel();
25567 if (pte_val(pteval))
25568 set_pte_at(&init_mm, vaddr, pte, pteval);
25569 else
25570 pte_clear(&init_mm, vaddr, pte);
25571 + pax_close_kernel();
25572
25573 /*
25574 * It's enough to flush this one mapping.
25575 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25576 index 410531d..0f16030 100644
25577 --- a/arch/x86/mm/setup_nx.c
25578 +++ b/arch/x86/mm/setup_nx.c
25579 @@ -5,8 +5,10 @@
25580 #include <asm/pgtable.h>
25581 #include <asm/proto.h>
25582
25583 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25584 static int disable_nx __cpuinitdata;
25585
25586 +#ifndef CONFIG_PAX_PAGEEXEC
25587 /*
25588 * noexec = on|off
25589 *
25590 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25591 return 0;
25592 }
25593 early_param("noexec", noexec_setup);
25594 +#endif
25595 +
25596 +#endif
25597
25598 void __cpuinit x86_configure_nx(void)
25599 {
25600 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25601 if (cpu_has_nx && !disable_nx)
25602 __supported_pte_mask |= _PAGE_NX;
25603 else
25604 +#endif
25605 __supported_pte_mask &= ~_PAGE_NX;
25606 }
25607
25608 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25609 index d6c0418..06a0ad5 100644
25610 --- a/arch/x86/mm/tlb.c
25611 +++ b/arch/x86/mm/tlb.c
25612 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25613 BUG();
25614 cpumask_clear_cpu(cpu,
25615 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25616 +
25617 +#ifndef CONFIG_PAX_PER_CPU_PGD
25618 load_cr3(swapper_pg_dir);
25619 +#endif
25620 +
25621 }
25622 EXPORT_SYMBOL_GPL(leave_mm);
25623
25624 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25625 index 6687022..ceabcfa 100644
25626 --- a/arch/x86/net/bpf_jit.S
25627 +++ b/arch/x86/net/bpf_jit.S
25628 @@ -9,6 +9,7 @@
25629 */
25630 #include <linux/linkage.h>
25631 #include <asm/dwarf2.h>
25632 +#include <asm/alternative-asm.h>
25633
25634 /*
25635 * Calling convention :
25636 @@ -35,6 +36,7 @@ sk_load_word:
25637 jle bpf_slow_path_word
25638 mov (SKBDATA,%rsi),%eax
25639 bswap %eax /* ntohl() */
25640 + pax_force_retaddr
25641 ret
25642
25643
25644 @@ -53,6 +55,7 @@ sk_load_half:
25645 jle bpf_slow_path_half
25646 movzwl (SKBDATA,%rsi),%eax
25647 rol $8,%ax # ntohs()
25648 + pax_force_retaddr
25649 ret
25650
25651 sk_load_byte_ind:
25652 @@ -66,6 +69,7 @@ sk_load_byte:
25653 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25654 jle bpf_slow_path_byte
25655 movzbl (SKBDATA,%rsi),%eax
25656 + pax_force_retaddr
25657 ret
25658
25659 /**
25660 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25661 movzbl (SKBDATA,%rsi),%ebx
25662 and $15,%bl
25663 shl $2,%bl
25664 + pax_force_retaddr
25665 ret
25666 CFI_ENDPROC
25667 ENDPROC(sk_load_byte_msh)
25668 @@ -91,6 +96,7 @@ bpf_error:
25669 xor %eax,%eax
25670 mov -8(%rbp),%rbx
25671 leaveq
25672 + pax_force_retaddr
25673 ret
25674
25675 /* rsi contains offset and can be scratched */
25676 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25677 js bpf_error
25678 mov -12(%rbp),%eax
25679 bswap %eax
25680 + pax_force_retaddr
25681 ret
25682
25683 bpf_slow_path_half:
25684 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25685 mov -12(%rbp),%ax
25686 rol $8,%ax
25687 movzwl %ax,%eax
25688 + pax_force_retaddr
25689 ret
25690
25691 bpf_slow_path_byte:
25692 bpf_slow_path_common(1)
25693 js bpf_error
25694 movzbl -12(%rbp),%eax
25695 + pax_force_retaddr
25696 ret
25697
25698 bpf_slow_path_byte_msh:
25699 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25700 and $15,%al
25701 shl $2,%al
25702 xchg %eax,%ebx
25703 + pax_force_retaddr
25704 ret
25705 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25706 index 5a5b6e4..201d42e 100644
25707 --- a/arch/x86/net/bpf_jit_comp.c
25708 +++ b/arch/x86/net/bpf_jit_comp.c
25709 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25710 set_fs(old_fs);
25711 }
25712
25713 +struct bpf_jit_work {
25714 + struct work_struct work;
25715 + void *image;
25716 +};
25717
25718 void bpf_jit_compile(struct sk_filter *fp)
25719 {
25720 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25721 if (addrs == NULL)
25722 return;
25723
25724 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25725 + if (!fp->work)
25726 + goto out;
25727 +
25728 /* Before first pass, make a rough estimation of addrs[]
25729 * each bpf instruction is translated to less than 64 bytes
25730 */
25731 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25732 common_load: seen |= SEEN_DATAREF;
25733 if ((int)K < 0) {
25734 /* Abort the JIT because __load_pointer() is needed. */
25735 - goto out;
25736 + goto error;
25737 }
25738 t_offset = func - (image + addrs[i]);
25739 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25740 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25741 case BPF_S_LDX_B_MSH:
25742 if ((int)K < 0) {
25743 /* Abort the JIT because __load_pointer() is needed. */
25744 - goto out;
25745 + goto error;
25746 }
25747 seen |= SEEN_DATAREF | SEEN_XREG;
25748 t_offset = sk_load_byte_msh - (image + addrs[i]);
25749 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25750 break;
25751 default:
25752 /* hmm, too complex filter, give up with jit compiler */
25753 - goto out;
25754 + goto error;
25755 }
25756 ilen = prog - temp;
25757 if (image) {
25758 if (unlikely(proglen + ilen > oldproglen)) {
25759 pr_err("bpb_jit_compile fatal error\n");
25760 - kfree(addrs);
25761 - module_free(NULL, image);
25762 - return;
25763 + module_free_exec(NULL, image);
25764 + goto error;
25765 }
25766 + pax_open_kernel();
25767 memcpy(image + proglen, temp, ilen);
25768 + pax_close_kernel();
25769 }
25770 proglen += ilen;
25771 addrs[i] = proglen;
25772 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25773 break;
25774 }
25775 if (proglen == oldproglen) {
25776 - image = module_alloc(max_t(unsigned int,
25777 - proglen,
25778 - sizeof(struct work_struct)));
25779 + image = module_alloc_exec(proglen);
25780 if (!image)
25781 - goto out;
25782 + goto error;
25783 }
25784 oldproglen = proglen;
25785 }
25786 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25787 bpf_flush_icache(image, image + proglen);
25788
25789 fp->bpf_func = (void *)image;
25790 - }
25791 + } else
25792 +error:
25793 + kfree(fp->work);
25794 +
25795 out:
25796 kfree(addrs);
25797 return;
25798 @@ -641,18 +651,20 @@ out:
25799
25800 static void jit_free_defer(struct work_struct *arg)
25801 {
25802 - module_free(NULL, arg);
25803 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25804 + kfree(arg);
25805 }
25806
25807 /* run from softirq, we must use a work_struct to call
25808 - * module_free() from process context
25809 + * module_free_exec() from process context
25810 */
25811 void bpf_jit_free(struct sk_filter *fp)
25812 {
25813 if (fp->bpf_func != sk_run_filter) {
25814 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25815 + struct work_struct *work = &fp->work->work;
25816
25817 INIT_WORK(work, jit_free_defer);
25818 + fp->work->image = fp->bpf_func;
25819 schedule_work(work);
25820 }
25821 }
25822 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25823 index bff89df..377758a 100644
25824 --- a/arch/x86/oprofile/backtrace.c
25825 +++ b/arch/x86/oprofile/backtrace.c
25826 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25827 struct stack_frame_ia32 *fp;
25828 unsigned long bytes;
25829
25830 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25831 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25832 if (bytes != sizeof(bufhead))
25833 return NULL;
25834
25835 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25836 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25837
25838 oprofile_add_trace(bufhead[0].return_address);
25839
25840 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25841 struct stack_frame bufhead[2];
25842 unsigned long bytes;
25843
25844 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25845 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25846 if (bytes != sizeof(bufhead))
25847 return NULL;
25848
25849 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25850 {
25851 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25852
25853 - if (!user_mode_vm(regs)) {
25854 + if (!user_mode(regs)) {
25855 unsigned long stack = kernel_stack_pointer(regs);
25856 if (depth)
25857 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25858 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25859 index cb29191..036766d 100644
25860 --- a/arch/x86/pci/mrst.c
25861 +++ b/arch/x86/pci/mrst.c
25862 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25863 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25864 pci_mmcfg_late_init();
25865 pcibios_enable_irq = mrst_pci_irq_enable;
25866 - pci_root_ops = pci_mrst_ops;
25867 + pax_open_kernel();
25868 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25869 + pax_close_kernel();
25870 /* Continue with standard init */
25871 return 1;
25872 }
25873 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25874 index da8fe05..7ee6704 100644
25875 --- a/arch/x86/pci/pcbios.c
25876 +++ b/arch/x86/pci/pcbios.c
25877 @@ -79,50 +79,93 @@ union bios32 {
25878 static struct {
25879 unsigned long address;
25880 unsigned short segment;
25881 -} bios32_indirect = { 0, __KERNEL_CS };
25882 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25883
25884 /*
25885 * Returns the entry point for the given service, NULL on error
25886 */
25887
25888 -static unsigned long bios32_service(unsigned long service)
25889 +static unsigned long __devinit bios32_service(unsigned long service)
25890 {
25891 unsigned char return_code; /* %al */
25892 unsigned long address; /* %ebx */
25893 unsigned long length; /* %ecx */
25894 unsigned long entry; /* %edx */
25895 unsigned long flags;
25896 + struct desc_struct d, *gdt;
25897
25898 local_irq_save(flags);
25899 - __asm__("lcall *(%%edi); cld"
25900 +
25901 + gdt = get_cpu_gdt_table(smp_processor_id());
25902 +
25903 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25904 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25905 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25906 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25907 +
25908 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25909 : "=a" (return_code),
25910 "=b" (address),
25911 "=c" (length),
25912 "=d" (entry)
25913 : "0" (service),
25914 "1" (0),
25915 - "D" (&bios32_indirect));
25916 + "D" (&bios32_indirect),
25917 + "r"(__PCIBIOS_DS)
25918 + : "memory");
25919 +
25920 + pax_open_kernel();
25921 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25922 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25923 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25924 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25925 + pax_close_kernel();
25926 +
25927 local_irq_restore(flags);
25928
25929 switch (return_code) {
25930 - case 0:
25931 - return address + entry;
25932 - case 0x80: /* Not present */
25933 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25934 - return 0;
25935 - default: /* Shouldn't happen */
25936 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25937 - service, return_code);
25938 + case 0: {
25939 + int cpu;
25940 + unsigned char flags;
25941 +
25942 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25943 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25944 + printk(KERN_WARNING "bios32_service: not valid\n");
25945 return 0;
25946 + }
25947 + address = address + PAGE_OFFSET;
25948 + length += 16UL; /* some BIOSs underreport this... */
25949 + flags = 4;
25950 + if (length >= 64*1024*1024) {
25951 + length >>= PAGE_SHIFT;
25952 + flags |= 8;
25953 + }
25954 +
25955 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25956 + gdt = get_cpu_gdt_table(cpu);
25957 + pack_descriptor(&d, address, length, 0x9b, flags);
25958 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25959 + pack_descriptor(&d, address, length, 0x93, flags);
25960 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25961 + }
25962 + return entry;
25963 + }
25964 + case 0x80: /* Not present */
25965 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25966 + return 0;
25967 + default: /* Shouldn't happen */
25968 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25969 + service, return_code);
25970 + return 0;
25971 }
25972 }
25973
25974 static struct {
25975 unsigned long address;
25976 unsigned short segment;
25977 -} pci_indirect = { 0, __KERNEL_CS };
25978 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25979
25980 -static int pci_bios_present;
25981 +static int pci_bios_present __read_only;
25982
25983 static int __devinit check_pcibios(void)
25984 {
25985 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25986 unsigned long flags, pcibios_entry;
25987
25988 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25989 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25990 + pci_indirect.address = pcibios_entry;
25991
25992 local_irq_save(flags);
25993 - __asm__(
25994 - "lcall *(%%edi); cld\n\t"
25995 + __asm__("movw %w6, %%ds\n\t"
25996 + "lcall *%%ss:(%%edi); cld\n\t"
25997 + "push %%ss\n\t"
25998 + "pop %%ds\n\t"
25999 "jc 1f\n\t"
26000 "xor %%ah, %%ah\n"
26001 "1:"
26002 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26003 "=b" (ebx),
26004 "=c" (ecx)
26005 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26006 - "D" (&pci_indirect)
26007 + "D" (&pci_indirect),
26008 + "r" (__PCIBIOS_DS)
26009 : "memory");
26010 local_irq_restore(flags);
26011
26012 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26013
26014 switch (len) {
26015 case 1:
26016 - __asm__("lcall *(%%esi); cld\n\t"
26017 + __asm__("movw %w6, %%ds\n\t"
26018 + "lcall *%%ss:(%%esi); cld\n\t"
26019 + "push %%ss\n\t"
26020 + "pop %%ds\n\t"
26021 "jc 1f\n\t"
26022 "xor %%ah, %%ah\n"
26023 "1:"
26024 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26025 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26026 "b" (bx),
26027 "D" ((long)reg),
26028 - "S" (&pci_indirect));
26029 + "S" (&pci_indirect),
26030 + "r" (__PCIBIOS_DS));
26031 /*
26032 * Zero-extend the result beyond 8 bits, do not trust the
26033 * BIOS having done it:
26034 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26035 *value &= 0xff;
26036 break;
26037 case 2:
26038 - __asm__("lcall *(%%esi); cld\n\t"
26039 + __asm__("movw %w6, %%ds\n\t"
26040 + "lcall *%%ss:(%%esi); cld\n\t"
26041 + "push %%ss\n\t"
26042 + "pop %%ds\n\t"
26043 "jc 1f\n\t"
26044 "xor %%ah, %%ah\n"
26045 "1:"
26046 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26047 : "1" (PCIBIOS_READ_CONFIG_WORD),
26048 "b" (bx),
26049 "D" ((long)reg),
26050 - "S" (&pci_indirect));
26051 + "S" (&pci_indirect),
26052 + "r" (__PCIBIOS_DS));
26053 /*
26054 * Zero-extend the result beyond 16 bits, do not trust the
26055 * BIOS having done it:
26056 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26057 *value &= 0xffff;
26058 break;
26059 case 4:
26060 - __asm__("lcall *(%%esi); cld\n\t"
26061 + __asm__("movw %w6, %%ds\n\t"
26062 + "lcall *%%ss:(%%esi); cld\n\t"
26063 + "push %%ss\n\t"
26064 + "pop %%ds\n\t"
26065 "jc 1f\n\t"
26066 "xor %%ah, %%ah\n"
26067 "1:"
26068 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26069 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26070 "b" (bx),
26071 "D" ((long)reg),
26072 - "S" (&pci_indirect));
26073 + "S" (&pci_indirect),
26074 + "r" (__PCIBIOS_DS));
26075 break;
26076 }
26077
26078 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26079
26080 switch (len) {
26081 case 1:
26082 - __asm__("lcall *(%%esi); cld\n\t"
26083 + __asm__("movw %w6, %%ds\n\t"
26084 + "lcall *%%ss:(%%esi); cld\n\t"
26085 + "push %%ss\n\t"
26086 + "pop %%ds\n\t"
26087 "jc 1f\n\t"
26088 "xor %%ah, %%ah\n"
26089 "1:"
26090 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26091 "c" (value),
26092 "b" (bx),
26093 "D" ((long)reg),
26094 - "S" (&pci_indirect));
26095 + "S" (&pci_indirect),
26096 + "r" (__PCIBIOS_DS));
26097 break;
26098 case 2:
26099 - __asm__("lcall *(%%esi); cld\n\t"
26100 + __asm__("movw %w6, %%ds\n\t"
26101 + "lcall *%%ss:(%%esi); cld\n\t"
26102 + "push %%ss\n\t"
26103 + "pop %%ds\n\t"
26104 "jc 1f\n\t"
26105 "xor %%ah, %%ah\n"
26106 "1:"
26107 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26108 "c" (value),
26109 "b" (bx),
26110 "D" ((long)reg),
26111 - "S" (&pci_indirect));
26112 + "S" (&pci_indirect),
26113 + "r" (__PCIBIOS_DS));
26114 break;
26115 case 4:
26116 - __asm__("lcall *(%%esi); cld\n\t"
26117 + __asm__("movw %w6, %%ds\n\t"
26118 + "lcall *%%ss:(%%esi); cld\n\t"
26119 + "push %%ss\n\t"
26120 + "pop %%ds\n\t"
26121 "jc 1f\n\t"
26122 "xor %%ah, %%ah\n"
26123 "1:"
26124 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26125 "c" (value),
26126 "b" (bx),
26127 "D" ((long)reg),
26128 - "S" (&pci_indirect));
26129 + "S" (&pci_indirect),
26130 + "r" (__PCIBIOS_DS));
26131 break;
26132 }
26133
26134 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26135
26136 DBG("PCI: Fetching IRQ routing table... ");
26137 __asm__("push %%es\n\t"
26138 + "movw %w8, %%ds\n\t"
26139 "push %%ds\n\t"
26140 "pop %%es\n\t"
26141 - "lcall *(%%esi); cld\n\t"
26142 + "lcall *%%ss:(%%esi); cld\n\t"
26143 "pop %%es\n\t"
26144 + "push %%ss\n\t"
26145 + "pop %%ds\n"
26146 "jc 1f\n\t"
26147 "xor %%ah, %%ah\n"
26148 "1:"
26149 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26150 "1" (0),
26151 "D" ((long) &opt),
26152 "S" (&pci_indirect),
26153 - "m" (opt)
26154 + "m" (opt),
26155 + "r" (__PCIBIOS_DS)
26156 : "memory");
26157 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26158 if (ret & 0xff00)
26159 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26160 {
26161 int ret;
26162
26163 - __asm__("lcall *(%%esi); cld\n\t"
26164 + __asm__("movw %w5, %%ds\n\t"
26165 + "lcall *%%ss:(%%esi); cld\n\t"
26166 + "push %%ss\n\t"
26167 + "pop %%ds\n"
26168 "jc 1f\n\t"
26169 "xor %%ah, %%ah\n"
26170 "1:"
26171 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26172 : "0" (PCIBIOS_SET_PCI_HW_INT),
26173 "b" ((dev->bus->number << 8) | dev->devfn),
26174 "c" ((irq << 8) | (pin + 10)),
26175 - "S" (&pci_indirect));
26176 + "S" (&pci_indirect),
26177 + "r" (__PCIBIOS_DS));
26178 return !(ret & 0xff00);
26179 }
26180 EXPORT_SYMBOL(pcibios_set_irq_routing);
26181 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26182 index 40e4469..1ab536e 100644
26183 --- a/arch/x86/platform/efi/efi_32.c
26184 +++ b/arch/x86/platform/efi/efi_32.c
26185 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26186 {
26187 struct desc_ptr gdt_descr;
26188
26189 +#ifdef CONFIG_PAX_KERNEXEC
26190 + struct desc_struct d;
26191 +#endif
26192 +
26193 local_irq_save(efi_rt_eflags);
26194
26195 load_cr3(initial_page_table);
26196 __flush_tlb_all();
26197
26198 +#ifdef CONFIG_PAX_KERNEXEC
26199 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26200 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26201 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26202 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26203 +#endif
26204 +
26205 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26206 gdt_descr.size = GDT_SIZE - 1;
26207 load_gdt(&gdt_descr);
26208 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26209 {
26210 struct desc_ptr gdt_descr;
26211
26212 +#ifdef CONFIG_PAX_KERNEXEC
26213 + struct desc_struct d;
26214 +
26215 + memset(&d, 0, sizeof d);
26216 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26217 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26218 +#endif
26219 +
26220 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26221 gdt_descr.size = GDT_SIZE - 1;
26222 load_gdt(&gdt_descr);
26223 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26224 index fbe66e6..c5c0dd2 100644
26225 --- a/arch/x86/platform/efi/efi_stub_32.S
26226 +++ b/arch/x86/platform/efi/efi_stub_32.S
26227 @@ -6,7 +6,9 @@
26228 */
26229
26230 #include <linux/linkage.h>
26231 +#include <linux/init.h>
26232 #include <asm/page_types.h>
26233 +#include <asm/segment.h>
26234
26235 /*
26236 * efi_call_phys(void *, ...) is a function with variable parameters.
26237 @@ -20,7 +22,7 @@
26238 * service functions will comply with gcc calling convention, too.
26239 */
26240
26241 -.text
26242 +__INIT
26243 ENTRY(efi_call_phys)
26244 /*
26245 * 0. The function can only be called in Linux kernel. So CS has been
26246 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26247 * The mapping of lower virtual memory has been created in prelog and
26248 * epilog.
26249 */
26250 - movl $1f, %edx
26251 - subl $__PAGE_OFFSET, %edx
26252 - jmp *%edx
26253 + movl $(__KERNEXEC_EFI_DS), %edx
26254 + mov %edx, %ds
26255 + mov %edx, %es
26256 + mov %edx, %ss
26257 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26258 1:
26259
26260 /*
26261 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26262 * parameter 2, ..., param n. To make things easy, we save the return
26263 * address of efi_call_phys in a global variable.
26264 */
26265 - popl %edx
26266 - movl %edx, saved_return_addr
26267 - /* get the function pointer into ECX*/
26268 - popl %ecx
26269 - movl %ecx, efi_rt_function_ptr
26270 - movl $2f, %edx
26271 - subl $__PAGE_OFFSET, %edx
26272 - pushl %edx
26273 + popl (saved_return_addr)
26274 + popl (efi_rt_function_ptr)
26275
26276 /*
26277 * 3. Clear PG bit in %CR0.
26278 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26279 /*
26280 * 5. Call the physical function.
26281 */
26282 - jmp *%ecx
26283 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26284
26285 -2:
26286 /*
26287 * 6. After EFI runtime service returns, control will return to
26288 * following instruction. We'd better readjust stack pointer first.
26289 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26290 movl %cr0, %edx
26291 orl $0x80000000, %edx
26292 movl %edx, %cr0
26293 - jmp 1f
26294 -1:
26295 +
26296 /*
26297 * 8. Now restore the virtual mode from flat mode by
26298 * adding EIP with PAGE_OFFSET.
26299 */
26300 - movl $1f, %edx
26301 - jmp *%edx
26302 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26303 1:
26304 + movl $(__KERNEL_DS), %edx
26305 + mov %edx, %ds
26306 + mov %edx, %es
26307 + mov %edx, %ss
26308
26309 /*
26310 * 9. Balance the stack. And because EAX contain the return value,
26311 * we'd better not clobber it.
26312 */
26313 - leal efi_rt_function_ptr, %edx
26314 - movl (%edx), %ecx
26315 - pushl %ecx
26316 + pushl (efi_rt_function_ptr)
26317
26318 /*
26319 - * 10. Push the saved return address onto the stack and return.
26320 + * 10. Return to the saved return address.
26321 */
26322 - leal saved_return_addr, %edx
26323 - movl (%edx), %ecx
26324 - pushl %ecx
26325 - ret
26326 + jmpl *(saved_return_addr)
26327 ENDPROC(efi_call_phys)
26328 .previous
26329
26330 -.data
26331 +__INITDATA
26332 saved_return_addr:
26333 .long 0
26334 efi_rt_function_ptr:
26335 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26336 index 4c07cca..2c8427d 100644
26337 --- a/arch/x86/platform/efi/efi_stub_64.S
26338 +++ b/arch/x86/platform/efi/efi_stub_64.S
26339 @@ -7,6 +7,7 @@
26340 */
26341
26342 #include <linux/linkage.h>
26343 +#include <asm/alternative-asm.h>
26344
26345 #define SAVE_XMM \
26346 mov %rsp, %rax; \
26347 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26348 call *%rdi
26349 addq $32, %rsp
26350 RESTORE_XMM
26351 + pax_force_retaddr 0, 1
26352 ret
26353 ENDPROC(efi_call0)
26354
26355 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26356 call *%rdi
26357 addq $32, %rsp
26358 RESTORE_XMM
26359 + pax_force_retaddr 0, 1
26360 ret
26361 ENDPROC(efi_call1)
26362
26363 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26364 call *%rdi
26365 addq $32, %rsp
26366 RESTORE_XMM
26367 + pax_force_retaddr 0, 1
26368 ret
26369 ENDPROC(efi_call2)
26370
26371 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26372 call *%rdi
26373 addq $32, %rsp
26374 RESTORE_XMM
26375 + pax_force_retaddr 0, 1
26376 ret
26377 ENDPROC(efi_call3)
26378
26379 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26380 call *%rdi
26381 addq $32, %rsp
26382 RESTORE_XMM
26383 + pax_force_retaddr 0, 1
26384 ret
26385 ENDPROC(efi_call4)
26386
26387 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26388 call *%rdi
26389 addq $48, %rsp
26390 RESTORE_XMM
26391 + pax_force_retaddr 0, 1
26392 ret
26393 ENDPROC(efi_call5)
26394
26395 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26396 call *%rdi
26397 addq $48, %rsp
26398 RESTORE_XMM
26399 + pax_force_retaddr 0, 1
26400 ret
26401 ENDPROC(efi_call6)
26402 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26403 index 475e2cd..1b8e708 100644
26404 --- a/arch/x86/platform/mrst/mrst.c
26405 +++ b/arch/x86/platform/mrst/mrst.c
26406 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26407 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26408 int sfi_mrtc_num;
26409
26410 -static void mrst_power_off(void)
26411 +static __noreturn void mrst_power_off(void)
26412 {
26413 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26414 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26415 + BUG();
26416 }
26417
26418 -static void mrst_reboot(void)
26419 +static __noreturn void mrst_reboot(void)
26420 {
26421 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26422 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26423 else
26424 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26425 + BUG();
26426 }
26427
26428 /* parse all the mtimer info to a static mtimer array */
26429 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
26430 index 3ae0e61..4202d86 100644
26431 --- a/arch/x86/platform/uv/tlb_uv.c
26432 +++ b/arch/x86/platform/uv/tlb_uv.c
26433 @@ -1424,6 +1424,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
26434 * 0: display meaning of the statistics
26435 */
26436 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26437 + size_t count, loff_t *data) __size_overflow(3);
26438 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26439 size_t count, loff_t *data)
26440 {
26441 int cpu;
26442 @@ -1539,6 +1541,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
26443 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
26444 */
26445 static ssize_t tunables_write(struct file *file, const char __user *user,
26446 + size_t count, loff_t *data) __size_overflow(3);
26447 +static ssize_t tunables_write(struct file *file, const char __user *user,
26448 size_t count, loff_t *data)
26449 {
26450 int cpu;
26451 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26452 index f10c0af..3ec1f95 100644
26453 --- a/arch/x86/power/cpu.c
26454 +++ b/arch/x86/power/cpu.c
26455 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26456 static void fix_processor_context(void)
26457 {
26458 int cpu = smp_processor_id();
26459 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26460 + struct tss_struct *t = init_tss + cpu;
26461
26462 set_tss_desc(cpu, t); /*
26463 * This just modifies memory; should not be
26464 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26465 */
26466
26467 #ifdef CONFIG_X86_64
26468 + pax_open_kernel();
26469 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26470 + pax_close_kernel();
26471
26472 syscall_init(); /* This sets MSR_*STAR and related */
26473 #endif
26474 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26475 index 5d17950..2253fc9 100644
26476 --- a/arch/x86/vdso/Makefile
26477 +++ b/arch/x86/vdso/Makefile
26478 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26479 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26480 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26481
26482 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26483 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26484 GCOV_PROFILE := n
26485
26486 #
26487 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26488 index 468d591..8e80a0a 100644
26489 --- a/arch/x86/vdso/vdso32-setup.c
26490 +++ b/arch/x86/vdso/vdso32-setup.c
26491 @@ -25,6 +25,7 @@
26492 #include <asm/tlbflush.h>
26493 #include <asm/vdso.h>
26494 #include <asm/proto.h>
26495 +#include <asm/mman.h>
26496
26497 enum {
26498 VDSO_DISABLED = 0,
26499 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26500 void enable_sep_cpu(void)
26501 {
26502 int cpu = get_cpu();
26503 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26504 + struct tss_struct *tss = init_tss + cpu;
26505
26506 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26507 put_cpu();
26508 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26509 gate_vma.vm_start = FIXADDR_USER_START;
26510 gate_vma.vm_end = FIXADDR_USER_END;
26511 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26512 - gate_vma.vm_page_prot = __P101;
26513 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26514 /*
26515 * Make sure the vDSO gets into every core dump.
26516 * Dumping its contents makes post-mortem fully interpretable later
26517 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26518 if (compat)
26519 addr = VDSO_HIGH_BASE;
26520 else {
26521 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26522 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26523 if (IS_ERR_VALUE(addr)) {
26524 ret = addr;
26525 goto up_fail;
26526 }
26527 }
26528
26529 - current->mm->context.vdso = (void *)addr;
26530 + current->mm->context.vdso = addr;
26531
26532 if (compat_uses_vma || !compat) {
26533 /*
26534 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26535 }
26536
26537 current_thread_info()->sysenter_return =
26538 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26539 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26540
26541 up_fail:
26542 if (ret)
26543 - current->mm->context.vdso = NULL;
26544 + current->mm->context.vdso = 0;
26545
26546 up_write(&mm->mmap_sem);
26547
26548 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26549
26550 const char *arch_vma_name(struct vm_area_struct *vma)
26551 {
26552 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26553 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26554 return "[vdso]";
26555 +
26556 +#ifdef CONFIG_PAX_SEGMEXEC
26557 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26558 + return "[vdso]";
26559 +#endif
26560 +
26561 return NULL;
26562 }
26563
26564 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26565 * Check to see if the corresponding task was created in compat vdso
26566 * mode.
26567 */
26568 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26569 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26570 return &gate_vma;
26571 return NULL;
26572 }
26573 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26574 index 153407c..611cba9 100644
26575 --- a/arch/x86/vdso/vma.c
26576 +++ b/arch/x86/vdso/vma.c
26577 @@ -16,8 +16,6 @@
26578 #include <asm/vdso.h>
26579 #include <asm/page.h>
26580
26581 -unsigned int __read_mostly vdso_enabled = 1;
26582 -
26583 extern char vdso_start[], vdso_end[];
26584 extern unsigned short vdso_sync_cpuid;
26585
26586 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26587 * unaligned here as a result of stack start randomization.
26588 */
26589 addr = PAGE_ALIGN(addr);
26590 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26591
26592 return addr;
26593 }
26594 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26595 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26596 {
26597 struct mm_struct *mm = current->mm;
26598 - unsigned long addr;
26599 + unsigned long addr = 0;
26600 int ret;
26601
26602 - if (!vdso_enabled)
26603 - return 0;
26604 -
26605 down_write(&mm->mmap_sem);
26606 +
26607 +#ifdef CONFIG_PAX_RANDMMAP
26608 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26609 +#endif
26610 +
26611 addr = vdso_addr(mm->start_stack, vdso_size);
26612 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26613 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26614 if (IS_ERR_VALUE(addr)) {
26615 ret = addr;
26616 goto up_fail;
26617 }
26618
26619 - current->mm->context.vdso = (void *)addr;
26620 + mm->context.vdso = addr;
26621
26622 ret = install_special_mapping(mm, addr, vdso_size,
26623 VM_READ|VM_EXEC|
26624 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26625 VM_ALWAYSDUMP,
26626 vdso_pages);
26627 - if (ret) {
26628 - current->mm->context.vdso = NULL;
26629 - goto up_fail;
26630 - }
26631 +
26632 + if (ret)
26633 + mm->context.vdso = 0;
26634
26635 up_fail:
26636 up_write(&mm->mmap_sem);
26637 return ret;
26638 }
26639 -
26640 -static __init int vdso_setup(char *s)
26641 -{
26642 - vdso_enabled = simple_strtoul(s, NULL, 0);
26643 - return 0;
26644 -}
26645 -__setup("vdso=", vdso_setup);
26646 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26647 index 4172af8..2c8ed7f 100644
26648 --- a/arch/x86/xen/enlighten.c
26649 +++ b/arch/x86/xen/enlighten.c
26650 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26651
26652 struct shared_info xen_dummy_shared_info;
26653
26654 -void *xen_initial_gdt;
26655 -
26656 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26657 __read_mostly int xen_have_vector_callback;
26658 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26659 @@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26660 #endif
26661 };
26662
26663 -static void xen_reboot(int reason)
26664 +static __noreturn void xen_reboot(int reason)
26665 {
26666 struct sched_shutdown r = { .reason = reason };
26667
26668 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26669 - BUG();
26670 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26671 + BUG();
26672 }
26673
26674 -static void xen_restart(char *msg)
26675 +static __noreturn void xen_restart(char *msg)
26676 {
26677 xen_reboot(SHUTDOWN_reboot);
26678 }
26679
26680 -static void xen_emergency_restart(void)
26681 +static __noreturn void xen_emergency_restart(void)
26682 {
26683 xen_reboot(SHUTDOWN_reboot);
26684 }
26685
26686 -static void xen_machine_halt(void)
26687 +static __noreturn void xen_machine_halt(void)
26688 {
26689 xen_reboot(SHUTDOWN_poweroff);
26690 }
26691
26692 -static void xen_machine_power_off(void)
26693 +static __noreturn void xen_machine_power_off(void)
26694 {
26695 if (pm_power_off)
26696 pm_power_off();
26697 @@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26698 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26699
26700 /* Work out if we support NX */
26701 - x86_configure_nx();
26702 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26703 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26704 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26705 + unsigned l, h;
26706 +
26707 + __supported_pte_mask |= _PAGE_NX;
26708 + rdmsr(MSR_EFER, l, h);
26709 + l |= EFER_NX;
26710 + wrmsr(MSR_EFER, l, h);
26711 + }
26712 +#endif
26713
26714 xen_setup_features();
26715
26716 @@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26717
26718 machine_ops = xen_machine_ops;
26719
26720 - /*
26721 - * The only reliable way to retain the initial address of the
26722 - * percpu gdt_page is to remember it here, so we can go and
26723 - * mark it RW later, when the initial percpu area is freed.
26724 - */
26725 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26726 -
26727 xen_smp_init();
26728
26729 #ifdef CONFIG_ACPI_NUMA
26730 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26731 index 95c1cf6..4bfa5be 100644
26732 --- a/arch/x86/xen/mmu.c
26733 +++ b/arch/x86/xen/mmu.c
26734 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26735 convert_pfn_mfn(init_level4_pgt);
26736 convert_pfn_mfn(level3_ident_pgt);
26737 convert_pfn_mfn(level3_kernel_pgt);
26738 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26739 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26740 + convert_pfn_mfn(level3_vmemmap_pgt);
26741
26742 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26743 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26744 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26745 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26746 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26747 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26748 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26749 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26750 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26751 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26752 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26753 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26754 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26755
26756 @@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26757 pv_mmu_ops.set_pud = xen_set_pud;
26758 #if PAGETABLE_LEVELS == 4
26759 pv_mmu_ops.set_pgd = xen_set_pgd;
26760 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26761 #endif
26762
26763 /* This will work as long as patching hasn't happened yet
26764 @@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26765 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26766 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26767 .set_pgd = xen_set_pgd_hyper,
26768 + .set_pgd_batched = xen_set_pgd_hyper,
26769
26770 .alloc_pud = xen_alloc_pmd_init,
26771 .release_pud = xen_release_pmd_init,
26772 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26773 index 501d4e0..e877605 100644
26774 --- a/arch/x86/xen/smp.c
26775 +++ b/arch/x86/xen/smp.c
26776 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26777 {
26778 BUG_ON(smp_processor_id() != 0);
26779 native_smp_prepare_boot_cpu();
26780 -
26781 - /* We've switched to the "real" per-cpu gdt, so make sure the
26782 - old memory can be recycled */
26783 - make_lowmem_page_readwrite(xen_initial_gdt);
26784 -
26785 xen_filter_cpu_maps();
26786 xen_setup_vcpu_info_placement();
26787 }
26788 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26789 gdt = get_cpu_gdt_table(cpu);
26790
26791 ctxt->flags = VGCF_IN_KERNEL;
26792 - ctxt->user_regs.ds = __USER_DS;
26793 - ctxt->user_regs.es = __USER_DS;
26794 + ctxt->user_regs.ds = __KERNEL_DS;
26795 + ctxt->user_regs.es = __KERNEL_DS;
26796 ctxt->user_regs.ss = __KERNEL_DS;
26797 #ifdef CONFIG_X86_32
26798 ctxt->user_regs.fs = __KERNEL_PERCPU;
26799 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26800 + savesegment(gs, ctxt->user_regs.gs);
26801 #else
26802 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26803 #endif
26804 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26805 int rc;
26806
26807 per_cpu(current_task, cpu) = idle;
26808 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26809 #ifdef CONFIG_X86_32
26810 irq_ctx_init(cpu);
26811 #else
26812 clear_tsk_thread_flag(idle, TIF_FORK);
26813 - per_cpu(kernel_stack, cpu) =
26814 - (unsigned long)task_stack_page(idle) -
26815 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26816 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26817 #endif
26818 xen_setup_runstate_info(cpu);
26819 xen_setup_timer(cpu);
26820 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26821 index b040b0e..8cc4fe0 100644
26822 --- a/arch/x86/xen/xen-asm_32.S
26823 +++ b/arch/x86/xen/xen-asm_32.S
26824 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26825 ESP_OFFSET=4 # bytes pushed onto stack
26826
26827 /*
26828 - * Store vcpu_info pointer for easy access. Do it this way to
26829 - * avoid having to reload %fs
26830 + * Store vcpu_info pointer for easy access.
26831 */
26832 #ifdef CONFIG_SMP
26833 - GET_THREAD_INFO(%eax)
26834 - movl TI_cpu(%eax), %eax
26835 - movl __per_cpu_offset(,%eax,4), %eax
26836 - mov xen_vcpu(%eax), %eax
26837 + push %fs
26838 + mov $(__KERNEL_PERCPU), %eax
26839 + mov %eax, %fs
26840 + mov PER_CPU_VAR(xen_vcpu), %eax
26841 + pop %fs
26842 #else
26843 movl xen_vcpu, %eax
26844 #endif
26845 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26846 index aaa7291..3f77960 100644
26847 --- a/arch/x86/xen/xen-head.S
26848 +++ b/arch/x86/xen/xen-head.S
26849 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26850 #ifdef CONFIG_X86_32
26851 mov %esi,xen_start_info
26852 mov $init_thread_union+THREAD_SIZE,%esp
26853 +#ifdef CONFIG_SMP
26854 + movl $cpu_gdt_table,%edi
26855 + movl $__per_cpu_load,%eax
26856 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26857 + rorl $16,%eax
26858 + movb %al,__KERNEL_PERCPU + 4(%edi)
26859 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26860 + movl $__per_cpu_end - 1,%eax
26861 + subl $__per_cpu_start,%eax
26862 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26863 +#endif
26864 #else
26865 mov %rsi,xen_start_info
26866 mov $init_thread_union+THREAD_SIZE,%rsp
26867 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26868 index b095739..8c17bcd 100644
26869 --- a/arch/x86/xen/xen-ops.h
26870 +++ b/arch/x86/xen/xen-ops.h
26871 @@ -10,8 +10,6 @@
26872 extern const char xen_hypervisor_callback[];
26873 extern const char xen_failsafe_callback[];
26874
26875 -extern void *xen_initial_gdt;
26876 -
26877 struct trap_info;
26878 void xen_copy_trap_info(struct trap_info *traps);
26879
26880 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26881 index 525bd3d..ef888b1 100644
26882 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26883 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26884 @@ -119,9 +119,9 @@
26885 ----------------------------------------------------------------------*/
26886
26887 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26888 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26889 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26890 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26891 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26892
26893 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26894 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26895 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26896 index 2f33760..835e50a 100644
26897 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26898 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26899 @@ -11,6 +11,7 @@
26900 #ifndef _XTENSA_CORE_H
26901 #define _XTENSA_CORE_H
26902
26903 +#include <linux/const.h>
26904
26905 /****************************************************************************
26906 Parameters Useful for Any Code, USER or PRIVILEGED
26907 @@ -112,9 +113,9 @@
26908 ----------------------------------------------------------------------*/
26909
26910 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26911 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26912 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26913 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26914 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26915
26916 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26917 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26918 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26919 index af00795..2bb8105 100644
26920 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26921 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26922 @@ -11,6 +11,7 @@
26923 #ifndef _XTENSA_CORE_CONFIGURATION_H
26924 #define _XTENSA_CORE_CONFIGURATION_H
26925
26926 +#include <linux/const.h>
26927
26928 /****************************************************************************
26929 Parameters Useful for Any Code, USER or PRIVILEGED
26930 @@ -118,9 +119,9 @@
26931 ----------------------------------------------------------------------*/
26932
26933 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26934 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26935 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26936 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26937 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26938
26939 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26940 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26941 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26942 index 58916af..9cb880b 100644
26943 --- a/block/blk-iopoll.c
26944 +++ b/block/blk-iopoll.c
26945 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26946 }
26947 EXPORT_SYMBOL(blk_iopoll_complete);
26948
26949 -static void blk_iopoll_softirq(struct softirq_action *h)
26950 +static void blk_iopoll_softirq(void)
26951 {
26952 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26953 int rearm = 0, budget = blk_iopoll_budget;
26954 diff --git a/block/blk-map.c b/block/blk-map.c
26955 index 623e1cd..ca1e109 100644
26956 --- a/block/blk-map.c
26957 +++ b/block/blk-map.c
26958 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26959 if (!len || !kbuf)
26960 return -EINVAL;
26961
26962 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26963 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26964 if (do_copy)
26965 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26966 else
26967 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26968 index 1366a89..e17f54b 100644
26969 --- a/block/blk-softirq.c
26970 +++ b/block/blk-softirq.c
26971 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26972 * Softirq action handler - move entries to local list and loop over them
26973 * while passing them to the queue registered handler.
26974 */
26975 -static void blk_done_softirq(struct softirq_action *h)
26976 +static void blk_done_softirq(void)
26977 {
26978 struct list_head *cpu_list, local_list;
26979
26980 diff --git a/block/bsg.c b/block/bsg.c
26981 index ff64ae3..593560c 100644
26982 --- a/block/bsg.c
26983 +++ b/block/bsg.c
26984 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26985 struct sg_io_v4 *hdr, struct bsg_device *bd,
26986 fmode_t has_write_perm)
26987 {
26988 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26989 + unsigned char *cmdptr;
26990 +
26991 if (hdr->request_len > BLK_MAX_CDB) {
26992 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26993 if (!rq->cmd)
26994 return -ENOMEM;
26995 - }
26996 + cmdptr = rq->cmd;
26997 + } else
26998 + cmdptr = tmpcmd;
26999
27000 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27001 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27002 hdr->request_len))
27003 return -EFAULT;
27004
27005 + if (cmdptr != rq->cmd)
27006 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27007 +
27008 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27009 if (blk_verify_command(rq->cmd, has_write_perm))
27010 return -EPERM;
27011 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27012 index 7c668c8..db3521c 100644
27013 --- a/block/compat_ioctl.c
27014 +++ b/block/compat_ioctl.c
27015 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27016 err |= __get_user(f->spec1, &uf->spec1);
27017 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27018 err |= __get_user(name, &uf->name);
27019 - f->name = compat_ptr(name);
27020 + f->name = (void __force_kernel *)compat_ptr(name);
27021 if (err) {
27022 err = -EFAULT;
27023 goto out;
27024 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27025 index 6296b40..417c00f 100644
27026 --- a/block/partitions/efi.c
27027 +++ b/block/partitions/efi.c
27028 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27029 if (!gpt)
27030 return NULL;
27031
27032 + if (!le32_to_cpu(gpt->num_partition_entries))
27033 + return NULL;
27034 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27035 + if (!pte)
27036 + return NULL;
27037 +
27038 count = le32_to_cpu(gpt->num_partition_entries) *
27039 le32_to_cpu(gpt->sizeof_partition_entry);
27040 - if (!count)
27041 - return NULL;
27042 - pte = kzalloc(count, GFP_KERNEL);
27043 - if (!pte)
27044 - return NULL;
27045 -
27046 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27047 (u8 *) pte,
27048 count) < count) {
27049 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27050 index 260fa80..e8f3caf 100644
27051 --- a/block/scsi_ioctl.c
27052 +++ b/block/scsi_ioctl.c
27053 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27054 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27055 struct sg_io_hdr *hdr, fmode_t mode)
27056 {
27057 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27058 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27059 + unsigned char *cmdptr;
27060 +
27061 + if (rq->cmd != rq->__cmd)
27062 + cmdptr = rq->cmd;
27063 + else
27064 + cmdptr = tmpcmd;
27065 +
27066 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27067 return -EFAULT;
27068 +
27069 + if (cmdptr != rq->cmd)
27070 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27071 +
27072 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27073 return -EPERM;
27074
27075 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27076 int err;
27077 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27078 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27079 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27080 + unsigned char *cmdptr;
27081
27082 if (!sic)
27083 return -EINVAL;
27084 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27085 */
27086 err = -EFAULT;
27087 rq->cmd_len = cmdlen;
27088 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27089 +
27090 + if (rq->cmd != rq->__cmd)
27091 + cmdptr = rq->cmd;
27092 + else
27093 + cmdptr = tmpcmd;
27094 +
27095 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27096 goto error;
27097
27098 + if (rq->cmd != cmdptr)
27099 + memcpy(rq->cmd, cmdptr, cmdlen);
27100 +
27101 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27102 goto error;
27103
27104 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27105 index a0f768c..1da9c73 100644
27106 --- a/crypto/ablkcipher.c
27107 +++ b/crypto/ablkcipher.c
27108 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27109 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27110
27111 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27112 + unsigned int keylen) __size_overflow(3);
27113 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27114 unsigned int keylen)
27115 {
27116 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27117 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27118 }
27119
27120 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27121 + unsigned int keylen) __size_overflow(3);
27122 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27123 unsigned int keylen)
27124 {
27125 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27126 diff --git a/crypto/aead.c b/crypto/aead.c
27127 index 04add3dc..983032f 100644
27128 --- a/crypto/aead.c
27129 +++ b/crypto/aead.c
27130 @@ -27,6 +27,8 @@
27131 #include "internal.h"
27132
27133 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27134 + unsigned int keylen) __size_overflow(3);
27135 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27136 unsigned int keylen)
27137 {
27138 struct aead_alg *aead = crypto_aead_alg(tfm);
27139 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27140 return ret;
27141 }
27142
27143 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27144 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27145 {
27146 struct aead_alg *aead = crypto_aead_alg(tfm);
27147 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27148 index 1e61d1a..cf06b86 100644
27149 --- a/crypto/blkcipher.c
27150 +++ b/crypto/blkcipher.c
27151 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27152 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27153
27154 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27155 + unsigned int keylen) __size_overflow(3);
27156 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27157 unsigned int keylen)
27158 {
27159 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27160 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27161 return ret;
27162 }
27163
27164 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27165 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27166 {
27167 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27168 diff --git a/crypto/cipher.c b/crypto/cipher.c
27169 index 39541e0..802d956 100644
27170 --- a/crypto/cipher.c
27171 +++ b/crypto/cipher.c
27172 @@ -21,6 +21,8 @@
27173 #include "internal.h"
27174
27175 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27176 + unsigned int keylen) __size_overflow(3);
27177 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27178 unsigned int keylen)
27179 {
27180 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27181 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27182
27183 }
27184
27185 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27186 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27187 {
27188 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27189 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27190 index 671d4d6..5f24030 100644
27191 --- a/crypto/cryptd.c
27192 +++ b/crypto/cryptd.c
27193 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27194
27195 struct cryptd_blkcipher_request_ctx {
27196 crypto_completion_t complete;
27197 -};
27198 +} __no_const;
27199
27200 struct cryptd_hash_ctx {
27201 struct crypto_shash *child;
27202 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27203
27204 struct cryptd_aead_request_ctx {
27205 crypto_completion_t complete;
27206 -};
27207 +} __no_const;
27208
27209 static void cryptd_queue_worker(struct work_struct *work);
27210
27211 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27212 index 5d41894..22021e4 100644
27213 --- a/drivers/acpi/apei/cper.c
27214 +++ b/drivers/acpi/apei/cper.c
27215 @@ -38,12 +38,12 @@
27216 */
27217 u64 cper_next_record_id(void)
27218 {
27219 - static atomic64_t seq;
27220 + static atomic64_unchecked_t seq;
27221
27222 - if (!atomic64_read(&seq))
27223 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27224 + if (!atomic64_read_unchecked(&seq))
27225 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27226
27227 - return atomic64_inc_return(&seq);
27228 + return atomic64_inc_return_unchecked(&seq);
27229 }
27230 EXPORT_SYMBOL_GPL(cper_next_record_id);
27231
27232 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27233 index 86933ca..5cb1a69 100644
27234 --- a/drivers/acpi/battery.c
27235 +++ b/drivers/acpi/battery.c
27236 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27237
27238 static ssize_t acpi_battery_write_alarm(struct file *file,
27239 const char __user * buffer,
27240 + size_t count, loff_t * ppos) __size_overflow(3);
27241 +static ssize_t acpi_battery_write_alarm(struct file *file,
27242 + const char __user * buffer,
27243 size_t count, loff_t * ppos)
27244 {
27245 int result = 0;
27246 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27247 index b258cab..3fb7da7 100644
27248 --- a/drivers/acpi/ec_sys.c
27249 +++ b/drivers/acpi/ec_sys.c
27250 @@ -12,6 +12,7 @@
27251 #include <linux/acpi.h>
27252 #include <linux/debugfs.h>
27253 #include <linux/module.h>
27254 +#include <linux/uaccess.h>
27255 #include "internal.h"
27256
27257 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27258 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27259 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27260 */
27261 unsigned int size = EC_SPACE_SIZE;
27262 - u8 *data = (u8 *) buf;
27263 + u8 data;
27264 loff_t init_off = *off;
27265 int err = 0;
27266
27267 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27268 size = count;
27269
27270 while (size) {
27271 - err = ec_read(*off, &data[*off - init_off]);
27272 + err = ec_read(*off, &data);
27273 if (err)
27274 return err;
27275 + if (put_user(data, &buf[*off - init_off]))
27276 + return -EFAULT;
27277 *off += 1;
27278 size--;
27279 }
27280 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27281
27282 unsigned int size = count;
27283 loff_t init_off = *off;
27284 - u8 *data = (u8 *) buf;
27285 int err = 0;
27286
27287 if (*off >= EC_SPACE_SIZE)
27288 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27289 }
27290
27291 while (size) {
27292 - u8 byte_write = data[*off - init_off];
27293 + u8 byte_write;
27294 + if (get_user(byte_write, &buf[*off - init_off]))
27295 + return -EFAULT;
27296 err = ec_write(*off, byte_write);
27297 if (err)
27298 return err;
27299 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27300 index 251c7b62..000462d 100644
27301 --- a/drivers/acpi/proc.c
27302 +++ b/drivers/acpi/proc.c
27303 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27304 size_t count, loff_t * ppos)
27305 {
27306 struct list_head *node, *next;
27307 - char strbuf[5];
27308 - char str[5] = "";
27309 - unsigned int len = count;
27310 + char strbuf[5] = {0};
27311
27312 - if (len > 4)
27313 - len = 4;
27314 - if (len < 0)
27315 + if (count > 4)
27316 + count = 4;
27317 + if (copy_from_user(strbuf, buffer, count))
27318 return -EFAULT;
27319 -
27320 - if (copy_from_user(strbuf, buffer, len))
27321 - return -EFAULT;
27322 - strbuf[len] = '\0';
27323 - sscanf(strbuf, "%s", str);
27324 + strbuf[count] = '\0';
27325
27326 mutex_lock(&acpi_device_lock);
27327 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27328 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27329 if (!dev->wakeup.flags.valid)
27330 continue;
27331
27332 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27333 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27334 if (device_can_wakeup(&dev->dev)) {
27335 bool enable = !device_may_wakeup(&dev->dev);
27336 device_set_wakeup_enable(&dev->dev, enable);
27337 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27338 index 8ae05ce..7dbbed9 100644
27339 --- a/drivers/acpi/processor_driver.c
27340 +++ b/drivers/acpi/processor_driver.c
27341 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27342 return 0;
27343 #endif
27344
27345 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27346 + BUG_ON(pr->id >= nr_cpu_ids);
27347
27348 /*
27349 * Buggy BIOS check
27350 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
27351 index 6e36d0c..f319944 100644
27352 --- a/drivers/acpi/sbs.c
27353 +++ b/drivers/acpi/sbs.c
27354 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
27355
27356 static ssize_t
27357 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27358 + size_t count, loff_t * ppos) __size_overflow(3);
27359 +static ssize_t
27360 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27361 size_t count, loff_t * ppos)
27362 {
27363 struct seq_file *seq = file->private_data;
27364 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27365 index c06e0ec..a2c06ba 100644
27366 --- a/drivers/ata/libata-core.c
27367 +++ b/drivers/ata/libata-core.c
27368 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27369 struct ata_port *ap;
27370 unsigned int tag;
27371
27372 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27373 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27374 ap = qc->ap;
27375
27376 qc->flags = 0;
27377 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27378 struct ata_port *ap;
27379 struct ata_link *link;
27380
27381 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27382 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27383 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27384 ap = qc->ap;
27385 link = qc->dev->link;
27386 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27387 return;
27388
27389 spin_lock(&lock);
27390 + pax_open_kernel();
27391
27392 for (cur = ops->inherits; cur; cur = cur->inherits) {
27393 void **inherit = (void **)cur;
27394 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27395 if (IS_ERR(*pp))
27396 *pp = NULL;
27397
27398 - ops->inherits = NULL;
27399 + *(struct ata_port_operations **)&ops->inherits = NULL;
27400
27401 + pax_close_kernel();
27402 spin_unlock(&lock);
27403 }
27404
27405 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27406 index 048589f..4002b98 100644
27407 --- a/drivers/ata/pata_arasan_cf.c
27408 +++ b/drivers/ata/pata_arasan_cf.c
27409 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27410 /* Handle platform specific quirks */
27411 if (pdata->quirk) {
27412 if (pdata->quirk & CF_BROKEN_PIO) {
27413 - ap->ops->set_piomode = NULL;
27414 + pax_open_kernel();
27415 + *(void **)&ap->ops->set_piomode = NULL;
27416 + pax_close_kernel();
27417 ap->pio_mask = 0;
27418 }
27419 if (pdata->quirk & CF_BROKEN_MWDMA)
27420 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27421 index f9b983a..887b9d8 100644
27422 --- a/drivers/atm/adummy.c
27423 +++ b/drivers/atm/adummy.c
27424 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27425 vcc->pop(vcc, skb);
27426 else
27427 dev_kfree_skb_any(skb);
27428 - atomic_inc(&vcc->stats->tx);
27429 + atomic_inc_unchecked(&vcc->stats->tx);
27430
27431 return 0;
27432 }
27433 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27434 index f8f41e0..1f987dd 100644
27435 --- a/drivers/atm/ambassador.c
27436 +++ b/drivers/atm/ambassador.c
27437 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27438 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27439
27440 // VC layer stats
27441 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27442 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27443
27444 // free the descriptor
27445 kfree (tx_descr);
27446 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27447 dump_skb ("<<<", vc, skb);
27448
27449 // VC layer stats
27450 - atomic_inc(&atm_vcc->stats->rx);
27451 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27452 __net_timestamp(skb);
27453 // end of our responsibility
27454 atm_vcc->push (atm_vcc, skb);
27455 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27456 } else {
27457 PRINTK (KERN_INFO, "dropped over-size frame");
27458 // should we count this?
27459 - atomic_inc(&atm_vcc->stats->rx_drop);
27460 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27461 }
27462
27463 } else {
27464 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27465 }
27466
27467 if (check_area (skb->data, skb->len)) {
27468 - atomic_inc(&atm_vcc->stats->tx_err);
27469 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27470 return -ENOMEM; // ?
27471 }
27472
27473 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27474 index b22d71c..d6e1049 100644
27475 --- a/drivers/atm/atmtcp.c
27476 +++ b/drivers/atm/atmtcp.c
27477 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27478 if (vcc->pop) vcc->pop(vcc,skb);
27479 else dev_kfree_skb(skb);
27480 if (dev_data) return 0;
27481 - atomic_inc(&vcc->stats->tx_err);
27482 + atomic_inc_unchecked(&vcc->stats->tx_err);
27483 return -ENOLINK;
27484 }
27485 size = skb->len+sizeof(struct atmtcp_hdr);
27486 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27487 if (!new_skb) {
27488 if (vcc->pop) vcc->pop(vcc,skb);
27489 else dev_kfree_skb(skb);
27490 - atomic_inc(&vcc->stats->tx_err);
27491 + atomic_inc_unchecked(&vcc->stats->tx_err);
27492 return -ENOBUFS;
27493 }
27494 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27495 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27496 if (vcc->pop) vcc->pop(vcc,skb);
27497 else dev_kfree_skb(skb);
27498 out_vcc->push(out_vcc,new_skb);
27499 - atomic_inc(&vcc->stats->tx);
27500 - atomic_inc(&out_vcc->stats->rx);
27501 + atomic_inc_unchecked(&vcc->stats->tx);
27502 + atomic_inc_unchecked(&out_vcc->stats->rx);
27503 return 0;
27504 }
27505
27506 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27507 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27508 read_unlock(&vcc_sklist_lock);
27509 if (!out_vcc) {
27510 - atomic_inc(&vcc->stats->tx_err);
27511 + atomic_inc_unchecked(&vcc->stats->tx_err);
27512 goto done;
27513 }
27514 skb_pull(skb,sizeof(struct atmtcp_hdr));
27515 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27516 __net_timestamp(new_skb);
27517 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27518 out_vcc->push(out_vcc,new_skb);
27519 - atomic_inc(&vcc->stats->tx);
27520 - atomic_inc(&out_vcc->stats->rx);
27521 + atomic_inc_unchecked(&vcc->stats->tx);
27522 + atomic_inc_unchecked(&out_vcc->stats->rx);
27523 done:
27524 if (vcc->pop) vcc->pop(vcc,skb);
27525 else dev_kfree_skb(skb);
27526 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27527 index 956e9ac..133516d 100644
27528 --- a/drivers/atm/eni.c
27529 +++ b/drivers/atm/eni.c
27530 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27531 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27532 vcc->dev->number);
27533 length = 0;
27534 - atomic_inc(&vcc->stats->rx_err);
27535 + atomic_inc_unchecked(&vcc->stats->rx_err);
27536 }
27537 else {
27538 length = ATM_CELL_SIZE-1; /* no HEC */
27539 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27540 size);
27541 }
27542 eff = length = 0;
27543 - atomic_inc(&vcc->stats->rx_err);
27544 + atomic_inc_unchecked(&vcc->stats->rx_err);
27545 }
27546 else {
27547 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27548 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27549 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27550 vcc->dev->number,vcc->vci,length,size << 2,descr);
27551 length = eff = 0;
27552 - atomic_inc(&vcc->stats->rx_err);
27553 + atomic_inc_unchecked(&vcc->stats->rx_err);
27554 }
27555 }
27556 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27557 @@ -771,7 +771,7 @@ rx_dequeued++;
27558 vcc->push(vcc,skb);
27559 pushed++;
27560 }
27561 - atomic_inc(&vcc->stats->rx);
27562 + atomic_inc_unchecked(&vcc->stats->rx);
27563 }
27564 wake_up(&eni_dev->rx_wait);
27565 }
27566 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27567 PCI_DMA_TODEVICE);
27568 if (vcc->pop) vcc->pop(vcc,skb);
27569 else dev_kfree_skb_irq(skb);
27570 - atomic_inc(&vcc->stats->tx);
27571 + atomic_inc_unchecked(&vcc->stats->tx);
27572 wake_up(&eni_dev->tx_wait);
27573 dma_complete++;
27574 }
27575 @@ -1569,7 +1569,7 @@ tx_complete++;
27576 /*--------------------------------- entries ---------------------------------*/
27577
27578
27579 -static const char *media_name[] __devinitdata = {
27580 +static const char *media_name[] __devinitconst = {
27581 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27582 "UTP", "05?", "06?", "07?", /* 4- 7 */
27583 "TAXI","09?", "10?", "11?", /* 8-11 */
27584 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27585 index 5072f8a..fa52520d 100644
27586 --- a/drivers/atm/firestream.c
27587 +++ b/drivers/atm/firestream.c
27588 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27589 }
27590 }
27591
27592 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27593 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27594
27595 fs_dprintk (FS_DEBUG_TXMEM, "i");
27596 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27597 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27598 #endif
27599 skb_put (skb, qe->p1 & 0xffff);
27600 ATM_SKB(skb)->vcc = atm_vcc;
27601 - atomic_inc(&atm_vcc->stats->rx);
27602 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27603 __net_timestamp(skb);
27604 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27605 atm_vcc->push (atm_vcc, skb);
27606 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27607 kfree (pe);
27608 }
27609 if (atm_vcc)
27610 - atomic_inc(&atm_vcc->stats->rx_drop);
27611 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27612 break;
27613 case 0x1f: /* Reassembly abort: no buffers. */
27614 /* Silently increment error counter. */
27615 if (atm_vcc)
27616 - atomic_inc(&atm_vcc->stats->rx_drop);
27617 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27618 break;
27619 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27620 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27621 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27622 index 361f5ae..7fc552d 100644
27623 --- a/drivers/atm/fore200e.c
27624 +++ b/drivers/atm/fore200e.c
27625 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27626 #endif
27627 /* check error condition */
27628 if (*entry->status & STATUS_ERROR)
27629 - atomic_inc(&vcc->stats->tx_err);
27630 + atomic_inc_unchecked(&vcc->stats->tx_err);
27631 else
27632 - atomic_inc(&vcc->stats->tx);
27633 + atomic_inc_unchecked(&vcc->stats->tx);
27634 }
27635 }
27636
27637 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27638 if (skb == NULL) {
27639 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27640
27641 - atomic_inc(&vcc->stats->rx_drop);
27642 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27643 return -ENOMEM;
27644 }
27645
27646 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27647
27648 dev_kfree_skb_any(skb);
27649
27650 - atomic_inc(&vcc->stats->rx_drop);
27651 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27652 return -ENOMEM;
27653 }
27654
27655 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27656
27657 vcc->push(vcc, skb);
27658 - atomic_inc(&vcc->stats->rx);
27659 + atomic_inc_unchecked(&vcc->stats->rx);
27660
27661 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27662
27663 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27664 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27665 fore200e->atm_dev->number,
27666 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27667 - atomic_inc(&vcc->stats->rx_err);
27668 + atomic_inc_unchecked(&vcc->stats->rx_err);
27669 }
27670 }
27671
27672 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27673 goto retry_here;
27674 }
27675
27676 - atomic_inc(&vcc->stats->tx_err);
27677 + atomic_inc_unchecked(&vcc->stats->tx_err);
27678
27679 fore200e->tx_sat++;
27680 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27681 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27682 index b182c2f..1c6fa8a 100644
27683 --- a/drivers/atm/he.c
27684 +++ b/drivers/atm/he.c
27685 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27686
27687 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27688 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27689 - atomic_inc(&vcc->stats->rx_drop);
27690 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27691 goto return_host_buffers;
27692 }
27693
27694 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27695 RBRQ_LEN_ERR(he_dev->rbrq_head)
27696 ? "LEN_ERR" : "",
27697 vcc->vpi, vcc->vci);
27698 - atomic_inc(&vcc->stats->rx_err);
27699 + atomic_inc_unchecked(&vcc->stats->rx_err);
27700 goto return_host_buffers;
27701 }
27702
27703 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27704 vcc->push(vcc, skb);
27705 spin_lock(&he_dev->global_lock);
27706
27707 - atomic_inc(&vcc->stats->rx);
27708 + atomic_inc_unchecked(&vcc->stats->rx);
27709
27710 return_host_buffers:
27711 ++pdus_assembled;
27712 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27713 tpd->vcc->pop(tpd->vcc, tpd->skb);
27714 else
27715 dev_kfree_skb_any(tpd->skb);
27716 - atomic_inc(&tpd->vcc->stats->tx_err);
27717 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27718 }
27719 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27720 return;
27721 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27722 vcc->pop(vcc, skb);
27723 else
27724 dev_kfree_skb_any(skb);
27725 - atomic_inc(&vcc->stats->tx_err);
27726 + atomic_inc_unchecked(&vcc->stats->tx_err);
27727 return -EINVAL;
27728 }
27729
27730 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27731 vcc->pop(vcc, skb);
27732 else
27733 dev_kfree_skb_any(skb);
27734 - atomic_inc(&vcc->stats->tx_err);
27735 + atomic_inc_unchecked(&vcc->stats->tx_err);
27736 return -EINVAL;
27737 }
27738 #endif
27739 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27740 vcc->pop(vcc, skb);
27741 else
27742 dev_kfree_skb_any(skb);
27743 - atomic_inc(&vcc->stats->tx_err);
27744 + atomic_inc_unchecked(&vcc->stats->tx_err);
27745 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27746 return -ENOMEM;
27747 }
27748 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27749 vcc->pop(vcc, skb);
27750 else
27751 dev_kfree_skb_any(skb);
27752 - atomic_inc(&vcc->stats->tx_err);
27753 + atomic_inc_unchecked(&vcc->stats->tx_err);
27754 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27755 return -ENOMEM;
27756 }
27757 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27758 __enqueue_tpd(he_dev, tpd, cid);
27759 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27760
27761 - atomic_inc(&vcc->stats->tx);
27762 + atomic_inc_unchecked(&vcc->stats->tx);
27763
27764 return 0;
27765 }
27766 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27767 index b812103..e391a49 100644
27768 --- a/drivers/atm/horizon.c
27769 +++ b/drivers/atm/horizon.c
27770 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27771 {
27772 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27773 // VC layer stats
27774 - atomic_inc(&vcc->stats->rx);
27775 + atomic_inc_unchecked(&vcc->stats->rx);
27776 __net_timestamp(skb);
27777 // end of our responsibility
27778 vcc->push (vcc, skb);
27779 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27780 dev->tx_iovec = NULL;
27781
27782 // VC layer stats
27783 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27784 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27785
27786 // free the skb
27787 hrz_kfree_skb (skb);
27788 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27789 index 1c05212..c28e200 100644
27790 --- a/drivers/atm/idt77252.c
27791 +++ b/drivers/atm/idt77252.c
27792 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27793 else
27794 dev_kfree_skb(skb);
27795
27796 - atomic_inc(&vcc->stats->tx);
27797 + atomic_inc_unchecked(&vcc->stats->tx);
27798 }
27799
27800 atomic_dec(&scq->used);
27801 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27802 if ((sb = dev_alloc_skb(64)) == NULL) {
27803 printk("%s: Can't allocate buffers for aal0.\n",
27804 card->name);
27805 - atomic_add(i, &vcc->stats->rx_drop);
27806 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27807 break;
27808 }
27809 if (!atm_charge(vcc, sb->truesize)) {
27810 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27811 card->name);
27812 - atomic_add(i - 1, &vcc->stats->rx_drop);
27813 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27814 dev_kfree_skb(sb);
27815 break;
27816 }
27817 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27818 ATM_SKB(sb)->vcc = vcc;
27819 __net_timestamp(sb);
27820 vcc->push(vcc, sb);
27821 - atomic_inc(&vcc->stats->rx);
27822 + atomic_inc_unchecked(&vcc->stats->rx);
27823
27824 cell += ATM_CELL_PAYLOAD;
27825 }
27826 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27827 "(CDC: %08x)\n",
27828 card->name, len, rpp->len, readl(SAR_REG_CDC));
27829 recycle_rx_pool_skb(card, rpp);
27830 - atomic_inc(&vcc->stats->rx_err);
27831 + atomic_inc_unchecked(&vcc->stats->rx_err);
27832 return;
27833 }
27834 if (stat & SAR_RSQE_CRC) {
27835 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27836 recycle_rx_pool_skb(card, rpp);
27837 - atomic_inc(&vcc->stats->rx_err);
27838 + atomic_inc_unchecked(&vcc->stats->rx_err);
27839 return;
27840 }
27841 if (skb_queue_len(&rpp->queue) > 1) {
27842 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27843 RXPRINTK("%s: Can't alloc RX skb.\n",
27844 card->name);
27845 recycle_rx_pool_skb(card, rpp);
27846 - atomic_inc(&vcc->stats->rx_err);
27847 + atomic_inc_unchecked(&vcc->stats->rx_err);
27848 return;
27849 }
27850 if (!atm_charge(vcc, skb->truesize)) {
27851 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27852 __net_timestamp(skb);
27853
27854 vcc->push(vcc, skb);
27855 - atomic_inc(&vcc->stats->rx);
27856 + atomic_inc_unchecked(&vcc->stats->rx);
27857
27858 return;
27859 }
27860 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27861 __net_timestamp(skb);
27862
27863 vcc->push(vcc, skb);
27864 - atomic_inc(&vcc->stats->rx);
27865 + atomic_inc_unchecked(&vcc->stats->rx);
27866
27867 if (skb->truesize > SAR_FB_SIZE_3)
27868 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27869 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27870 if (vcc->qos.aal != ATM_AAL0) {
27871 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27872 card->name, vpi, vci);
27873 - atomic_inc(&vcc->stats->rx_drop);
27874 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27875 goto drop;
27876 }
27877
27878 if ((sb = dev_alloc_skb(64)) == NULL) {
27879 printk("%s: Can't allocate buffers for AAL0.\n",
27880 card->name);
27881 - atomic_inc(&vcc->stats->rx_err);
27882 + atomic_inc_unchecked(&vcc->stats->rx_err);
27883 goto drop;
27884 }
27885
27886 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27887 ATM_SKB(sb)->vcc = vcc;
27888 __net_timestamp(sb);
27889 vcc->push(vcc, sb);
27890 - atomic_inc(&vcc->stats->rx);
27891 + atomic_inc_unchecked(&vcc->stats->rx);
27892
27893 drop:
27894 skb_pull(queue, 64);
27895 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27896
27897 if (vc == NULL) {
27898 printk("%s: NULL connection in send().\n", card->name);
27899 - atomic_inc(&vcc->stats->tx_err);
27900 + atomic_inc_unchecked(&vcc->stats->tx_err);
27901 dev_kfree_skb(skb);
27902 return -EINVAL;
27903 }
27904 if (!test_bit(VCF_TX, &vc->flags)) {
27905 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27906 - atomic_inc(&vcc->stats->tx_err);
27907 + atomic_inc_unchecked(&vcc->stats->tx_err);
27908 dev_kfree_skb(skb);
27909 return -EINVAL;
27910 }
27911 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27912 break;
27913 default:
27914 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27915 - atomic_inc(&vcc->stats->tx_err);
27916 + atomic_inc_unchecked(&vcc->stats->tx_err);
27917 dev_kfree_skb(skb);
27918 return -EINVAL;
27919 }
27920
27921 if (skb_shinfo(skb)->nr_frags != 0) {
27922 printk("%s: No scatter-gather yet.\n", card->name);
27923 - atomic_inc(&vcc->stats->tx_err);
27924 + atomic_inc_unchecked(&vcc->stats->tx_err);
27925 dev_kfree_skb(skb);
27926 return -EINVAL;
27927 }
27928 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27929
27930 err = queue_skb(card, vc, skb, oam);
27931 if (err) {
27932 - atomic_inc(&vcc->stats->tx_err);
27933 + atomic_inc_unchecked(&vcc->stats->tx_err);
27934 dev_kfree_skb(skb);
27935 return err;
27936 }
27937 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27938 skb = dev_alloc_skb(64);
27939 if (!skb) {
27940 printk("%s: Out of memory in send_oam().\n", card->name);
27941 - atomic_inc(&vcc->stats->tx_err);
27942 + atomic_inc_unchecked(&vcc->stats->tx_err);
27943 return -ENOMEM;
27944 }
27945 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27946 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27947 index 9e373ba..cf93727 100644
27948 --- a/drivers/atm/iphase.c
27949 +++ b/drivers/atm/iphase.c
27950 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27951 status = (u_short) (buf_desc_ptr->desc_mode);
27952 if (status & (RX_CER | RX_PTE | RX_OFL))
27953 {
27954 - atomic_inc(&vcc->stats->rx_err);
27955 + atomic_inc_unchecked(&vcc->stats->rx_err);
27956 IF_ERR(printk("IA: bad packet, dropping it");)
27957 if (status & RX_CER) {
27958 IF_ERR(printk(" cause: packet CRC error\n");)
27959 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27960 len = dma_addr - buf_addr;
27961 if (len > iadev->rx_buf_sz) {
27962 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27963 - atomic_inc(&vcc->stats->rx_err);
27964 + atomic_inc_unchecked(&vcc->stats->rx_err);
27965 goto out_free_desc;
27966 }
27967
27968 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27969 ia_vcc = INPH_IA_VCC(vcc);
27970 if (ia_vcc == NULL)
27971 {
27972 - atomic_inc(&vcc->stats->rx_err);
27973 + atomic_inc_unchecked(&vcc->stats->rx_err);
27974 atm_return(vcc, skb->truesize);
27975 dev_kfree_skb_any(skb);
27976 goto INCR_DLE;
27977 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27978 if ((length > iadev->rx_buf_sz) || (length >
27979 (skb->len - sizeof(struct cpcs_trailer))))
27980 {
27981 - atomic_inc(&vcc->stats->rx_err);
27982 + atomic_inc_unchecked(&vcc->stats->rx_err);
27983 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27984 length, skb->len);)
27985 atm_return(vcc, skb->truesize);
27986 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27987
27988 IF_RX(printk("rx_dle_intr: skb push");)
27989 vcc->push(vcc,skb);
27990 - atomic_inc(&vcc->stats->rx);
27991 + atomic_inc_unchecked(&vcc->stats->rx);
27992 iadev->rx_pkt_cnt++;
27993 }
27994 INCR_DLE:
27995 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27996 {
27997 struct k_sonet_stats *stats;
27998 stats = &PRIV(_ia_dev[board])->sonet_stats;
27999 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28000 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28001 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28002 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28003 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28004 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28005 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28006 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28007 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28008 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28009 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28010 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28011 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28012 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28013 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28014 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28015 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28016 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28017 }
28018 ia_cmds.status = 0;
28019 break;
28020 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28021 if ((desc == 0) || (desc > iadev->num_tx_desc))
28022 {
28023 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28024 - atomic_inc(&vcc->stats->tx);
28025 + atomic_inc_unchecked(&vcc->stats->tx);
28026 if (vcc->pop)
28027 vcc->pop(vcc, skb);
28028 else
28029 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28030 ATM_DESC(skb) = vcc->vci;
28031 skb_queue_tail(&iadev->tx_dma_q, skb);
28032
28033 - atomic_inc(&vcc->stats->tx);
28034 + atomic_inc_unchecked(&vcc->stats->tx);
28035 iadev->tx_pkt_cnt++;
28036 /* Increment transaction counter */
28037 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28038
28039 #if 0
28040 /* add flow control logic */
28041 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28042 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28043 if (iavcc->vc_desc_cnt > 10) {
28044 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28045 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28046 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28047 index f556969..0da15eb 100644
28048 --- a/drivers/atm/lanai.c
28049 +++ b/drivers/atm/lanai.c
28050 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28051 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28052 lanai_endtx(lanai, lvcc);
28053 lanai_free_skb(lvcc->tx.atmvcc, skb);
28054 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28055 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28056 }
28057
28058 /* Try to fill the buffer - don't call unless there is backlog */
28059 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28060 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28061 __net_timestamp(skb);
28062 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28063 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28064 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28065 out:
28066 lvcc->rx.buf.ptr = end;
28067 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28068 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28069 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28070 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28071 lanai->stats.service_rxnotaal5++;
28072 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28073 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28074 return 0;
28075 }
28076 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28077 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28078 int bytes;
28079 read_unlock(&vcc_sklist_lock);
28080 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28081 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28082 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28083 lvcc->stats.x.aal5.service_trash++;
28084 bytes = (SERVICE_GET_END(s) * 16) -
28085 (((unsigned long) lvcc->rx.buf.ptr) -
28086 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28087 }
28088 if (s & SERVICE_STREAM) {
28089 read_unlock(&vcc_sklist_lock);
28090 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28091 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28092 lvcc->stats.x.aal5.service_stream++;
28093 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28094 "PDU on VCI %d!\n", lanai->number, vci);
28095 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28096 return 0;
28097 }
28098 DPRINTK("got rx crc error on vci %d\n", vci);
28099 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28100 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28101 lvcc->stats.x.aal5.service_rxcrc++;
28102 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28103 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28104 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28105 index 1c70c45..300718d 100644
28106 --- a/drivers/atm/nicstar.c
28107 +++ b/drivers/atm/nicstar.c
28108 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28109 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28110 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28111 card->index);
28112 - atomic_inc(&vcc->stats->tx_err);
28113 + atomic_inc_unchecked(&vcc->stats->tx_err);
28114 dev_kfree_skb_any(skb);
28115 return -EINVAL;
28116 }
28117 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28118 if (!vc->tx) {
28119 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28120 card->index);
28121 - atomic_inc(&vcc->stats->tx_err);
28122 + atomic_inc_unchecked(&vcc->stats->tx_err);
28123 dev_kfree_skb_any(skb);
28124 return -EINVAL;
28125 }
28126 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28127 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28128 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28129 card->index);
28130 - atomic_inc(&vcc->stats->tx_err);
28131 + atomic_inc_unchecked(&vcc->stats->tx_err);
28132 dev_kfree_skb_any(skb);
28133 return -EINVAL;
28134 }
28135
28136 if (skb_shinfo(skb)->nr_frags != 0) {
28137 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28138 - atomic_inc(&vcc->stats->tx_err);
28139 + atomic_inc_unchecked(&vcc->stats->tx_err);
28140 dev_kfree_skb_any(skb);
28141 return -EINVAL;
28142 }
28143 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28144 }
28145
28146 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28147 - atomic_inc(&vcc->stats->tx_err);
28148 + atomic_inc_unchecked(&vcc->stats->tx_err);
28149 dev_kfree_skb_any(skb);
28150 return -EIO;
28151 }
28152 - atomic_inc(&vcc->stats->tx);
28153 + atomic_inc_unchecked(&vcc->stats->tx);
28154
28155 return 0;
28156 }
28157 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28158 printk
28159 ("nicstar%d: Can't allocate buffers for aal0.\n",
28160 card->index);
28161 - atomic_add(i, &vcc->stats->rx_drop);
28162 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28163 break;
28164 }
28165 if (!atm_charge(vcc, sb->truesize)) {
28166 RXPRINTK
28167 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28168 card->index);
28169 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28170 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28171 dev_kfree_skb_any(sb);
28172 break;
28173 }
28174 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28175 ATM_SKB(sb)->vcc = vcc;
28176 __net_timestamp(sb);
28177 vcc->push(vcc, sb);
28178 - atomic_inc(&vcc->stats->rx);
28179 + atomic_inc_unchecked(&vcc->stats->rx);
28180 cell += ATM_CELL_PAYLOAD;
28181 }
28182
28183 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28184 if (iovb == NULL) {
28185 printk("nicstar%d: Out of iovec buffers.\n",
28186 card->index);
28187 - atomic_inc(&vcc->stats->rx_drop);
28188 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28189 recycle_rx_buf(card, skb);
28190 return;
28191 }
28192 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28193 small or large buffer itself. */
28194 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28195 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28196 - atomic_inc(&vcc->stats->rx_err);
28197 + atomic_inc_unchecked(&vcc->stats->rx_err);
28198 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28199 NS_MAX_IOVECS);
28200 NS_PRV_IOVCNT(iovb) = 0;
28201 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28202 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28203 card->index);
28204 which_list(card, skb);
28205 - atomic_inc(&vcc->stats->rx_err);
28206 + atomic_inc_unchecked(&vcc->stats->rx_err);
28207 recycle_rx_buf(card, skb);
28208 vc->rx_iov = NULL;
28209 recycle_iov_buf(card, iovb);
28210 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28211 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28212 card->index);
28213 which_list(card, skb);
28214 - atomic_inc(&vcc->stats->rx_err);
28215 + atomic_inc_unchecked(&vcc->stats->rx_err);
28216 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28217 NS_PRV_IOVCNT(iovb));
28218 vc->rx_iov = NULL;
28219 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28220 printk(" - PDU size mismatch.\n");
28221 else
28222 printk(".\n");
28223 - atomic_inc(&vcc->stats->rx_err);
28224 + atomic_inc_unchecked(&vcc->stats->rx_err);
28225 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28226 NS_PRV_IOVCNT(iovb));
28227 vc->rx_iov = NULL;
28228 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28229 /* skb points to a small buffer */
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 skb_put(skb, len);
28236 dequeue_sm_buf(card, skb);
28237 @@ -2189,7 +2189,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 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28245 struct sk_buff *sb;
28246 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28247 if (len <= NS_SMBUFSIZE) {
28248 if (!atm_charge(vcc, sb->truesize)) {
28249 push_rxbufs(card, sb);
28250 - atomic_inc(&vcc->stats->rx_drop);
28251 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28252 } else {
28253 skb_put(sb, len);
28254 dequeue_sm_buf(card, sb);
28255 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28256 ATM_SKB(sb)->vcc = vcc;
28257 __net_timestamp(sb);
28258 vcc->push(vcc, sb);
28259 - atomic_inc(&vcc->stats->rx);
28260 + atomic_inc_unchecked(&vcc->stats->rx);
28261 }
28262
28263 push_rxbufs(card, skb);
28264 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28265
28266 if (!atm_charge(vcc, skb->truesize)) {
28267 push_rxbufs(card, skb);
28268 - atomic_inc(&vcc->stats->rx_drop);
28269 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28270 } else {
28271 dequeue_lg_buf(card, skb);
28272 #ifdef NS_USE_DESTRUCTORS
28273 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28274 ATM_SKB(skb)->vcc = vcc;
28275 __net_timestamp(skb);
28276 vcc->push(vcc, skb);
28277 - atomic_inc(&vcc->stats->rx);
28278 + atomic_inc_unchecked(&vcc->stats->rx);
28279 }
28280
28281 push_rxbufs(card, sb);
28282 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28283 printk
28284 ("nicstar%d: Out of huge buffers.\n",
28285 card->index);
28286 - atomic_inc(&vcc->stats->rx_drop);
28287 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28288 recycle_iovec_rx_bufs(card,
28289 (struct iovec *)
28290 iovb->data,
28291 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28292 card->hbpool.count++;
28293 } else
28294 dev_kfree_skb_any(hb);
28295 - atomic_inc(&vcc->stats->rx_drop);
28296 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28297 } else {
28298 /* Copy the small buffer to the huge buffer */
28299 sb = (struct sk_buff *)iov->iov_base;
28300 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28301 #endif /* NS_USE_DESTRUCTORS */
28302 __net_timestamp(hb);
28303 vcc->push(vcc, hb);
28304 - atomic_inc(&vcc->stats->rx);
28305 + atomic_inc_unchecked(&vcc->stats->rx);
28306 }
28307 }
28308
28309 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28310 index e8cd652..bbbd1fc 100644
28311 --- a/drivers/atm/solos-pci.c
28312 +++ b/drivers/atm/solos-pci.c
28313 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28314 }
28315 atm_charge(vcc, skb->truesize);
28316 vcc->push(vcc, skb);
28317 - atomic_inc(&vcc->stats->rx);
28318 + atomic_inc_unchecked(&vcc->stats->rx);
28319 break;
28320
28321 case PKT_STATUS:
28322 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28323 vcc = SKB_CB(oldskb)->vcc;
28324
28325 if (vcc) {
28326 - atomic_inc(&vcc->stats->tx);
28327 + atomic_inc_unchecked(&vcc->stats->tx);
28328 solos_pop(vcc, oldskb);
28329 } else
28330 dev_kfree_skb_irq(oldskb);
28331 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28332 index 90f1ccc..04c4a1e 100644
28333 --- a/drivers/atm/suni.c
28334 +++ b/drivers/atm/suni.c
28335 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28336
28337
28338 #define ADD_LIMITED(s,v) \
28339 - atomic_add((v),&stats->s); \
28340 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28341 + atomic_add_unchecked((v),&stats->s); \
28342 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28343
28344
28345 static void suni_hz(unsigned long from_timer)
28346 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28347 index 5120a96..e2572bd 100644
28348 --- a/drivers/atm/uPD98402.c
28349 +++ b/drivers/atm/uPD98402.c
28350 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28351 struct sonet_stats tmp;
28352 int error = 0;
28353
28354 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28355 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28356 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28357 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28358 if (zero && !error) {
28359 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28360
28361
28362 #define ADD_LIMITED(s,v) \
28363 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28364 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28365 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28366 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28367 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28368 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28369
28370
28371 static void stat_event(struct atm_dev *dev)
28372 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28373 if (reason & uPD98402_INT_PFM) stat_event(dev);
28374 if (reason & uPD98402_INT_PCO) {
28375 (void) GET(PCOCR); /* clear interrupt cause */
28376 - atomic_add(GET(HECCT),
28377 + atomic_add_unchecked(GET(HECCT),
28378 &PRIV(dev)->sonet_stats.uncorr_hcs);
28379 }
28380 if ((reason & uPD98402_INT_RFO) &&
28381 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28382 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28383 uPD98402_INT_LOS),PIMR); /* enable them */
28384 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28385 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28386 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28387 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28388 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28389 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28390 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28391 return 0;
28392 }
28393
28394 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28395 index d889f56..17eb71e 100644
28396 --- a/drivers/atm/zatm.c
28397 +++ b/drivers/atm/zatm.c
28398 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28399 }
28400 if (!size) {
28401 dev_kfree_skb_irq(skb);
28402 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28403 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28404 continue;
28405 }
28406 if (!atm_charge(vcc,skb->truesize)) {
28407 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28408 skb->len = size;
28409 ATM_SKB(skb)->vcc = vcc;
28410 vcc->push(vcc,skb);
28411 - atomic_inc(&vcc->stats->rx);
28412 + atomic_inc_unchecked(&vcc->stats->rx);
28413 }
28414 zout(pos & 0xffff,MTA(mbx));
28415 #if 0 /* probably a stupid idea */
28416 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28417 skb_queue_head(&zatm_vcc->backlog,skb);
28418 break;
28419 }
28420 - atomic_inc(&vcc->stats->tx);
28421 + atomic_inc_unchecked(&vcc->stats->tx);
28422 wake_up(&zatm_vcc->tx_wait);
28423 }
28424
28425 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28426 index 8493536..31adee0 100644
28427 --- a/drivers/base/devtmpfs.c
28428 +++ b/drivers/base/devtmpfs.c
28429 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28430 if (!thread)
28431 return 0;
28432
28433 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28434 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28435 if (err)
28436 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28437 else
28438 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28439 index caf995f..6f76697 100644
28440 --- a/drivers/base/power/wakeup.c
28441 +++ b/drivers/base/power/wakeup.c
28442 @@ -30,14 +30,14 @@ bool events_check_enabled;
28443 * They need to be modified together atomically, so it's better to use one
28444 * atomic variable to hold them both.
28445 */
28446 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28447 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28448
28449 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28450 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28451
28452 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28453 {
28454 - unsigned int comb = atomic_read(&combined_event_count);
28455 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28456
28457 *cnt = (comb >> IN_PROGRESS_BITS);
28458 *inpr = comb & MAX_IN_PROGRESS;
28459 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28460 ws->last_time = ktime_get();
28461
28462 /* Increment the counter of events in progress. */
28463 - atomic_inc(&combined_event_count);
28464 + atomic_inc_unchecked(&combined_event_count);
28465 }
28466
28467 /**
28468 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28469 * Increment the counter of registered wakeup events and decrement the
28470 * couter of wakeup events in progress simultaneously.
28471 */
28472 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28473 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28474 }
28475
28476 /**
28477 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28478 index b0f553b..77b928b 100644
28479 --- a/drivers/block/cciss.c
28480 +++ b/drivers/block/cciss.c
28481 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28482 int err;
28483 u32 cp;
28484
28485 + memset(&arg64, 0, sizeof(arg64));
28486 +
28487 err = 0;
28488 err |=
28489 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28490 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28491 while (!list_empty(&h->reqQ)) {
28492 c = list_entry(h->reqQ.next, CommandList_struct, list);
28493 /* can't do anything if fifo is full */
28494 - if ((h->access.fifo_full(h))) {
28495 + if ((h->access->fifo_full(h))) {
28496 dev_warn(&h->pdev->dev, "fifo full\n");
28497 break;
28498 }
28499 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28500 h->Qdepth--;
28501
28502 /* Tell the controller execute command */
28503 - h->access.submit_command(h, c);
28504 + h->access->submit_command(h, c);
28505
28506 /* Put job onto the completed Q */
28507 addQ(&h->cmpQ, c);
28508 @@ -3443,17 +3445,17 @@ startio:
28509
28510 static inline unsigned long get_next_completion(ctlr_info_t *h)
28511 {
28512 - return h->access.command_completed(h);
28513 + return h->access->command_completed(h);
28514 }
28515
28516 static inline int interrupt_pending(ctlr_info_t *h)
28517 {
28518 - return h->access.intr_pending(h);
28519 + return h->access->intr_pending(h);
28520 }
28521
28522 static inline long interrupt_not_for_us(ctlr_info_t *h)
28523 {
28524 - return ((h->access.intr_pending(h) == 0) ||
28525 + return ((h->access->intr_pending(h) == 0) ||
28526 (h->interrupts_enabled == 0));
28527 }
28528
28529 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28530 u32 a;
28531
28532 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28533 - return h->access.command_completed(h);
28534 + return h->access->command_completed(h);
28535
28536 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28537 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28538 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28539 trans_support & CFGTBL_Trans_use_short_tags);
28540
28541 /* Change the access methods to the performant access methods */
28542 - h->access = SA5_performant_access;
28543 + h->access = &SA5_performant_access;
28544 h->transMethod = CFGTBL_Trans_Performant;
28545
28546 return;
28547 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28548 if (prod_index < 0)
28549 return -ENODEV;
28550 h->product_name = products[prod_index].product_name;
28551 - h->access = *(products[prod_index].access);
28552 + h->access = products[prod_index].access;
28553
28554 if (cciss_board_disabled(h)) {
28555 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28556 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28557 }
28558
28559 /* make sure the board interrupts are off */
28560 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28561 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28562 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28563 if (rc)
28564 goto clean2;
28565 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28566 * fake ones to scoop up any residual completions.
28567 */
28568 spin_lock_irqsave(&h->lock, flags);
28569 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28570 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28571 spin_unlock_irqrestore(&h->lock, flags);
28572 free_irq(h->intr[h->intr_mode], h);
28573 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28574 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28575 dev_info(&h->pdev->dev, "Board READY.\n");
28576 dev_info(&h->pdev->dev,
28577 "Waiting for stale completions to drain.\n");
28578 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28579 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28580 msleep(10000);
28581 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28582 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28583
28584 rc = controller_reset_failed(h->cfgtable);
28585 if (rc)
28586 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28587 cciss_scsi_setup(h);
28588
28589 /* Turn the interrupts on so we can service requests */
28590 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28591 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28592
28593 /* Get the firmware version */
28594 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28595 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28596 kfree(flush_buf);
28597 if (return_code != IO_OK)
28598 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28599 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28600 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28601 free_irq(h->intr[h->intr_mode], h);
28602 }
28603
28604 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28605 index 7fda30e..eb5dfe0 100644
28606 --- a/drivers/block/cciss.h
28607 +++ b/drivers/block/cciss.h
28608 @@ -101,7 +101,7 @@ struct ctlr_info
28609 /* information about each logical volume */
28610 drive_info_struct *drv[CISS_MAX_LUN];
28611
28612 - struct access_method access;
28613 + struct access_method *access;
28614
28615 /* queue and queue Info */
28616 struct list_head reqQ;
28617 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28618 index 9125bbe..eede5c8 100644
28619 --- a/drivers/block/cpqarray.c
28620 +++ b/drivers/block/cpqarray.c
28621 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28622 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28623 goto Enomem4;
28624 }
28625 - hba[i]->access.set_intr_mask(hba[i], 0);
28626 + hba[i]->access->set_intr_mask(hba[i], 0);
28627 if (request_irq(hba[i]->intr, do_ida_intr,
28628 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28629 {
28630 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28631 add_timer(&hba[i]->timer);
28632
28633 /* Enable IRQ now that spinlock and rate limit timer are set up */
28634 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28635 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28636
28637 for(j=0; j<NWD; j++) {
28638 struct gendisk *disk = ida_gendisk[i][j];
28639 @@ -694,7 +694,7 @@ DBGINFO(
28640 for(i=0; i<NR_PRODUCTS; i++) {
28641 if (board_id == products[i].board_id) {
28642 c->product_name = products[i].product_name;
28643 - c->access = *(products[i].access);
28644 + c->access = products[i].access;
28645 break;
28646 }
28647 }
28648 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28649 hba[ctlr]->intr = intr;
28650 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28651 hba[ctlr]->product_name = products[j].product_name;
28652 - hba[ctlr]->access = *(products[j].access);
28653 + hba[ctlr]->access = products[j].access;
28654 hba[ctlr]->ctlr = ctlr;
28655 hba[ctlr]->board_id = board_id;
28656 hba[ctlr]->pci_dev = NULL; /* not PCI */
28657 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28658
28659 while((c = h->reqQ) != NULL) {
28660 /* Can't do anything if we're busy */
28661 - if (h->access.fifo_full(h) == 0)
28662 + if (h->access->fifo_full(h) == 0)
28663 return;
28664
28665 /* Get the first entry from the request Q */
28666 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28667 h->Qdepth--;
28668
28669 /* Tell the controller to do our bidding */
28670 - h->access.submit_command(h, c);
28671 + h->access->submit_command(h, c);
28672
28673 /* Get onto the completion Q */
28674 addQ(&h->cmpQ, c);
28675 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28676 unsigned long flags;
28677 __u32 a,a1;
28678
28679 - istat = h->access.intr_pending(h);
28680 + istat = h->access->intr_pending(h);
28681 /* Is this interrupt for us? */
28682 if (istat == 0)
28683 return IRQ_NONE;
28684 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28685 */
28686 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28687 if (istat & FIFO_NOT_EMPTY) {
28688 - while((a = h->access.command_completed(h))) {
28689 + while((a = h->access->command_completed(h))) {
28690 a1 = a; a &= ~3;
28691 if ((c = h->cmpQ) == NULL)
28692 {
28693 @@ -1449,11 +1449,11 @@ static int sendcmd(
28694 /*
28695 * Disable interrupt
28696 */
28697 - info_p->access.set_intr_mask(info_p, 0);
28698 + info_p->access->set_intr_mask(info_p, 0);
28699 /* Make sure there is room in the command FIFO */
28700 /* Actually it should be completely empty at this time. */
28701 for (i = 200000; i > 0; i--) {
28702 - temp = info_p->access.fifo_full(info_p);
28703 + temp = info_p->access->fifo_full(info_p);
28704 if (temp != 0) {
28705 break;
28706 }
28707 @@ -1466,7 +1466,7 @@ DBG(
28708 /*
28709 * Send the cmd
28710 */
28711 - info_p->access.submit_command(info_p, c);
28712 + info_p->access->submit_command(info_p, c);
28713 complete = pollcomplete(ctlr);
28714
28715 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28716 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28717 * we check the new geometry. Then turn interrupts back on when
28718 * we're done.
28719 */
28720 - host->access.set_intr_mask(host, 0);
28721 + host->access->set_intr_mask(host, 0);
28722 getgeometry(ctlr);
28723 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28724 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28725
28726 for(i=0; i<NWD; i++) {
28727 struct gendisk *disk = ida_gendisk[ctlr][i];
28728 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28729 /* Wait (up to 2 seconds) for a command to complete */
28730
28731 for (i = 200000; i > 0; i--) {
28732 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28733 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28734 if (done == 0) {
28735 udelay(10); /* a short fixed delay */
28736 } else
28737 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28738 index be73e9d..7fbf140 100644
28739 --- a/drivers/block/cpqarray.h
28740 +++ b/drivers/block/cpqarray.h
28741 @@ -99,7 +99,7 @@ struct ctlr_info {
28742 drv_info_t drv[NWD];
28743 struct proc_dir_entry *proc;
28744
28745 - struct access_method access;
28746 + struct access_method *access;
28747
28748 cmdlist_t *reqQ;
28749 cmdlist_t *cmpQ;
28750 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28751 index 8d68056..e67050f 100644
28752 --- a/drivers/block/drbd/drbd_int.h
28753 +++ b/drivers/block/drbd/drbd_int.h
28754 @@ -736,7 +736,7 @@ struct drbd_request;
28755 struct drbd_epoch {
28756 struct list_head list;
28757 unsigned int barrier_nr;
28758 - atomic_t epoch_size; /* increased on every request added. */
28759 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28760 atomic_t active; /* increased on every req. added, and dec on every finished. */
28761 unsigned long flags;
28762 };
28763 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28764 void *int_dig_in;
28765 void *int_dig_vv;
28766 wait_queue_head_t seq_wait;
28767 - atomic_t packet_seq;
28768 + atomic_unchecked_t packet_seq;
28769 unsigned int peer_seq;
28770 spinlock_t peer_seq_lock;
28771 unsigned int minor;
28772 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28773
28774 static inline void drbd_tcp_cork(struct socket *sock)
28775 {
28776 - int __user val = 1;
28777 + int val = 1;
28778 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28779 - (char __user *)&val, sizeof(val));
28780 + (char __force_user *)&val, sizeof(val));
28781 }
28782
28783 static inline void drbd_tcp_uncork(struct socket *sock)
28784 {
28785 - int __user val = 0;
28786 + int val = 0;
28787 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28788 - (char __user *)&val, sizeof(val));
28789 + (char __force_user *)&val, sizeof(val));
28790 }
28791
28792 static inline void drbd_tcp_nodelay(struct socket *sock)
28793 {
28794 - int __user val = 1;
28795 + int val = 1;
28796 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28797 - (char __user *)&val, sizeof(val));
28798 + (char __force_user *)&val, sizeof(val));
28799 }
28800
28801 static inline void drbd_tcp_quickack(struct socket *sock)
28802 {
28803 - int __user val = 2;
28804 + int val = 2;
28805 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28806 - (char __user *)&val, sizeof(val));
28807 + (char __force_user *)&val, sizeof(val));
28808 }
28809
28810 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28811 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28812 index 211fc44..c5116f1 100644
28813 --- a/drivers/block/drbd/drbd_main.c
28814 +++ b/drivers/block/drbd/drbd_main.c
28815 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28816 p.sector = sector;
28817 p.block_id = block_id;
28818 p.blksize = blksize;
28819 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28820 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28821
28822 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28823 return false;
28824 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28825 p.sector = cpu_to_be64(req->sector);
28826 p.block_id = (unsigned long)req;
28827 p.seq_num = cpu_to_be32(req->seq_num =
28828 - atomic_add_return(1, &mdev->packet_seq));
28829 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28830
28831 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28832
28833 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28834 atomic_set(&mdev->unacked_cnt, 0);
28835 atomic_set(&mdev->local_cnt, 0);
28836 atomic_set(&mdev->net_cnt, 0);
28837 - atomic_set(&mdev->packet_seq, 0);
28838 + atomic_set_unchecked(&mdev->packet_seq, 0);
28839 atomic_set(&mdev->pp_in_use, 0);
28840 atomic_set(&mdev->pp_in_use_by_net, 0);
28841 atomic_set(&mdev->rs_sect_in, 0);
28842 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28843 mdev->receiver.t_state);
28844
28845 /* no need to lock it, I'm the only thread alive */
28846 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28847 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28848 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28849 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28850 mdev->al_writ_cnt =
28851 mdev->bm_writ_cnt =
28852 mdev->read_cnt =
28853 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28854 index af2a250..219c74b 100644
28855 --- a/drivers/block/drbd/drbd_nl.c
28856 +++ b/drivers/block/drbd/drbd_nl.c
28857 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28858 module_put(THIS_MODULE);
28859 }
28860
28861 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28862 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28863
28864 static unsigned short *
28865 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28866 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28867 cn_reply->id.idx = CN_IDX_DRBD;
28868 cn_reply->id.val = CN_VAL_DRBD;
28869
28870 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28871 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28872 cn_reply->ack = 0; /* not used here. */
28873 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28874 (int)((char *)tl - (char *)reply->tag_list);
28875 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28876 cn_reply->id.idx = CN_IDX_DRBD;
28877 cn_reply->id.val = CN_VAL_DRBD;
28878
28879 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28880 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28881 cn_reply->ack = 0; /* not used here. */
28882 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28883 (int)((char *)tl - (char *)reply->tag_list);
28884 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28885 cn_reply->id.idx = CN_IDX_DRBD;
28886 cn_reply->id.val = CN_VAL_DRBD;
28887
28888 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28889 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28890 cn_reply->ack = 0; // not used here.
28891 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28892 (int)((char*)tl - (char*)reply->tag_list);
28893 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28894 cn_reply->id.idx = CN_IDX_DRBD;
28895 cn_reply->id.val = CN_VAL_DRBD;
28896
28897 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28898 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28899 cn_reply->ack = 0; /* not used here. */
28900 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28901 (int)((char *)tl - (char *)reply->tag_list);
28902 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28903 index 43beaca..4a5b1dd 100644
28904 --- a/drivers/block/drbd/drbd_receiver.c
28905 +++ b/drivers/block/drbd/drbd_receiver.c
28906 @@ -894,7 +894,7 @@ retry:
28907 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28908 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28909
28910 - atomic_set(&mdev->packet_seq, 0);
28911 + atomic_set_unchecked(&mdev->packet_seq, 0);
28912 mdev->peer_seq = 0;
28913
28914 drbd_thread_start(&mdev->asender);
28915 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28916 do {
28917 next_epoch = NULL;
28918
28919 - epoch_size = atomic_read(&epoch->epoch_size);
28920 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28921
28922 switch (ev & ~EV_CLEANUP) {
28923 case EV_PUT:
28924 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28925 rv = FE_DESTROYED;
28926 } else {
28927 epoch->flags = 0;
28928 - atomic_set(&epoch->epoch_size, 0);
28929 + atomic_set_unchecked(&epoch->epoch_size, 0);
28930 /* atomic_set(&epoch->active, 0); is already zero */
28931 if (rv == FE_STILL_LIVE)
28932 rv = FE_RECYCLED;
28933 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28934 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28935 drbd_flush(mdev);
28936
28937 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28938 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28939 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28940 if (epoch)
28941 break;
28942 }
28943
28944 epoch = mdev->current_epoch;
28945 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28946 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28947
28948 D_ASSERT(atomic_read(&epoch->active) == 0);
28949 D_ASSERT(epoch->flags == 0);
28950 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28951 }
28952
28953 epoch->flags = 0;
28954 - atomic_set(&epoch->epoch_size, 0);
28955 + atomic_set_unchecked(&epoch->epoch_size, 0);
28956 atomic_set(&epoch->active, 0);
28957
28958 spin_lock(&mdev->epoch_lock);
28959 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28960 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28961 list_add(&epoch->list, &mdev->current_epoch->list);
28962 mdev->current_epoch = epoch;
28963 mdev->epochs++;
28964 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28965 spin_unlock(&mdev->peer_seq_lock);
28966
28967 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28968 - atomic_inc(&mdev->current_epoch->epoch_size);
28969 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28970 return drbd_drain_block(mdev, data_size);
28971 }
28972
28973 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28974
28975 spin_lock(&mdev->epoch_lock);
28976 e->epoch = mdev->current_epoch;
28977 - atomic_inc(&e->epoch->epoch_size);
28978 + atomic_inc_unchecked(&e->epoch->epoch_size);
28979 atomic_inc(&e->epoch->active);
28980 spin_unlock(&mdev->epoch_lock);
28981
28982 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28983 D_ASSERT(list_empty(&mdev->done_ee));
28984
28985 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28986 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28987 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28988 D_ASSERT(list_empty(&mdev->current_epoch->list));
28989 }
28990
28991 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28992 index cd50435..ba1ffb5 100644
28993 --- a/drivers/block/loop.c
28994 +++ b/drivers/block/loop.c
28995 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
28996 mm_segment_t old_fs = get_fs();
28997
28998 set_fs(get_ds());
28999 - bw = file->f_op->write(file, buf, len, &pos);
29000 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29001 set_fs(old_fs);
29002 if (likely(bw == len))
29003 return 0;
29004 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29005 index 4364303..9adf4ee 100644
29006 --- a/drivers/char/Kconfig
29007 +++ b/drivers/char/Kconfig
29008 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29009
29010 config DEVKMEM
29011 bool "/dev/kmem virtual device support"
29012 - default y
29013 + default n
29014 + depends on !GRKERNSEC_KMEM
29015 help
29016 Say Y here if you want to support the /dev/kmem device. The
29017 /dev/kmem device is rarely used, but can be used for certain
29018 @@ -596,6 +597,7 @@ config DEVPORT
29019 bool
29020 depends on !M68K
29021 depends on ISA || PCI
29022 + depends on !GRKERNSEC_KMEM
29023 default y
29024
29025 source "drivers/s390/char/Kconfig"
29026 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29027 index 2e04433..22afc64 100644
29028 --- a/drivers/char/agp/frontend.c
29029 +++ b/drivers/char/agp/frontend.c
29030 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29031 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29032 return -EFAULT;
29033
29034 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29035 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29036 return -EFAULT;
29037
29038 client = agp_find_client_by_pid(reserve.pid);
29039 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29040 index 095ab90..afad0a4 100644
29041 --- a/drivers/char/briq_panel.c
29042 +++ b/drivers/char/briq_panel.c
29043 @@ -9,6 +9,7 @@
29044 #include <linux/types.h>
29045 #include <linux/errno.h>
29046 #include <linux/tty.h>
29047 +#include <linux/mutex.h>
29048 #include <linux/timer.h>
29049 #include <linux/kernel.h>
29050 #include <linux/wait.h>
29051 @@ -34,6 +35,7 @@ static int vfd_is_open;
29052 static unsigned char vfd[40];
29053 static int vfd_cursor;
29054 static unsigned char ledpb, led;
29055 +static DEFINE_MUTEX(vfd_mutex);
29056
29057 static void update_vfd(void)
29058 {
29059 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29060 if (!vfd_is_open)
29061 return -EBUSY;
29062
29063 + mutex_lock(&vfd_mutex);
29064 for (;;) {
29065 char c;
29066 if (!indx)
29067 break;
29068 - if (get_user(c, buf))
29069 + if (get_user(c, buf)) {
29070 + mutex_unlock(&vfd_mutex);
29071 return -EFAULT;
29072 + }
29073 if (esc) {
29074 set_led(c);
29075 esc = 0;
29076 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29077 buf++;
29078 }
29079 update_vfd();
29080 + mutex_unlock(&vfd_mutex);
29081
29082 return len;
29083 }
29084 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29085 index f773a9d..65cd683 100644
29086 --- a/drivers/char/genrtc.c
29087 +++ b/drivers/char/genrtc.c
29088 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29089 switch (cmd) {
29090
29091 case RTC_PLL_GET:
29092 + memset(&pll, 0, sizeof(pll));
29093 if (get_rtc_pll(&pll))
29094 return -EINVAL;
29095 else
29096 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29097 index 0833896..cccce52 100644
29098 --- a/drivers/char/hpet.c
29099 +++ b/drivers/char/hpet.c
29100 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29101 }
29102
29103 static int
29104 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29105 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29106 struct hpet_info *info)
29107 {
29108 struct hpet_timer __iomem *timer;
29109 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29110 index 58c0e63..46c16bf 100644
29111 --- a/drivers/char/ipmi/ipmi_msghandler.c
29112 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29113 @@ -415,7 +415,7 @@ struct ipmi_smi {
29114 struct proc_dir_entry *proc_dir;
29115 char proc_dir_name[10];
29116
29117 - atomic_t stats[IPMI_NUM_STATS];
29118 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29119
29120 /*
29121 * run_to_completion duplicate of smb_info, smi_info
29122 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29123
29124
29125 #define ipmi_inc_stat(intf, stat) \
29126 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29127 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29128 #define ipmi_get_stat(intf, stat) \
29129 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29130 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29131
29132 static int is_lan_addr(struct ipmi_addr *addr)
29133 {
29134 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29135 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29136 init_waitqueue_head(&intf->waitq);
29137 for (i = 0; i < IPMI_NUM_STATS; i++)
29138 - atomic_set(&intf->stats[i], 0);
29139 + atomic_set_unchecked(&intf->stats[i], 0);
29140
29141 intf->proc_dir = NULL;
29142
29143 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29144 index 50fcf9c..91b5528 100644
29145 --- a/drivers/char/ipmi/ipmi_si_intf.c
29146 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29147 @@ -277,7 +277,7 @@ struct smi_info {
29148 unsigned char slave_addr;
29149
29150 /* Counters and things for the proc filesystem. */
29151 - atomic_t stats[SI_NUM_STATS];
29152 + atomic_unchecked_t stats[SI_NUM_STATS];
29153
29154 struct task_struct *thread;
29155
29156 @@ -286,9 +286,9 @@ struct smi_info {
29157 };
29158
29159 #define smi_inc_stat(smi, stat) \
29160 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29161 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29162 #define smi_get_stat(smi, stat) \
29163 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29164 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29165
29166 #define SI_MAX_PARMS 4
29167
29168 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29169 atomic_set(&new_smi->req_events, 0);
29170 new_smi->run_to_completion = 0;
29171 for (i = 0; i < SI_NUM_STATS; i++)
29172 - atomic_set(&new_smi->stats[i], 0);
29173 + atomic_set_unchecked(&new_smi->stats[i], 0);
29174
29175 new_smi->interrupt_disabled = 1;
29176 atomic_set(&new_smi->stop_operation, 0);
29177 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29178 index 1aeaaba..e018570 100644
29179 --- a/drivers/char/mbcs.c
29180 +++ b/drivers/char/mbcs.c
29181 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29182 return 0;
29183 }
29184
29185 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29186 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29187 {
29188 .part_num = MBCS_PART_NUM,
29189 .mfg_num = MBCS_MFG_NUM,
29190 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29191 index d6e9d08..4493e89 100644
29192 --- a/drivers/char/mem.c
29193 +++ b/drivers/char/mem.c
29194 @@ -18,6 +18,7 @@
29195 #include <linux/raw.h>
29196 #include <linux/tty.h>
29197 #include <linux/capability.h>
29198 +#include <linux/security.h>
29199 #include <linux/ptrace.h>
29200 #include <linux/device.h>
29201 #include <linux/highmem.h>
29202 @@ -35,6 +36,10 @@
29203 # include <linux/efi.h>
29204 #endif
29205
29206 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29207 +extern const struct file_operations grsec_fops;
29208 +#endif
29209 +
29210 static inline unsigned long size_inside_page(unsigned long start,
29211 unsigned long size)
29212 {
29213 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29214
29215 while (cursor < to) {
29216 if (!devmem_is_allowed(pfn)) {
29217 +#ifdef CONFIG_GRKERNSEC_KMEM
29218 + gr_handle_mem_readwrite(from, to);
29219 +#else
29220 printk(KERN_INFO
29221 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29222 current->comm, from, to);
29223 +#endif
29224 return 0;
29225 }
29226 cursor += PAGE_SIZE;
29227 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29228 }
29229 return 1;
29230 }
29231 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29232 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29233 +{
29234 + return 0;
29235 +}
29236 #else
29237 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29238 {
29239 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29240
29241 while (count > 0) {
29242 unsigned long remaining;
29243 + char *temp;
29244
29245 sz = size_inside_page(p, count);
29246
29247 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29248 if (!ptr)
29249 return -EFAULT;
29250
29251 - remaining = copy_to_user(buf, ptr, sz);
29252 +#ifdef CONFIG_PAX_USERCOPY
29253 + temp = kmalloc(sz, GFP_KERNEL);
29254 + if (!temp) {
29255 + unxlate_dev_mem_ptr(p, ptr);
29256 + return -ENOMEM;
29257 + }
29258 + memcpy(temp, ptr, sz);
29259 +#else
29260 + temp = ptr;
29261 +#endif
29262 +
29263 + remaining = copy_to_user(buf, temp, sz);
29264 +
29265 +#ifdef CONFIG_PAX_USERCOPY
29266 + kfree(temp);
29267 +#endif
29268 +
29269 unxlate_dev_mem_ptr(p, ptr);
29270 if (remaining)
29271 return -EFAULT;
29272 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29273 size_t count, loff_t *ppos)
29274 {
29275 unsigned long p = *ppos;
29276 - ssize_t low_count, read, sz;
29277 + ssize_t low_count, read, sz, err = 0;
29278 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29279 - int err = 0;
29280
29281 read = 0;
29282 if (p < (unsigned long) high_memory) {
29283 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29284 }
29285 #endif
29286 while (low_count > 0) {
29287 + char *temp;
29288 +
29289 sz = size_inside_page(p, low_count);
29290
29291 /*
29292 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29293 */
29294 kbuf = xlate_dev_kmem_ptr((char *)p);
29295
29296 - if (copy_to_user(buf, kbuf, sz))
29297 +#ifdef CONFIG_PAX_USERCOPY
29298 + temp = kmalloc(sz, GFP_KERNEL);
29299 + if (!temp)
29300 + return -ENOMEM;
29301 + memcpy(temp, kbuf, sz);
29302 +#else
29303 + temp = kbuf;
29304 +#endif
29305 +
29306 + err = copy_to_user(buf, temp, sz);
29307 +
29308 +#ifdef CONFIG_PAX_USERCOPY
29309 + kfree(temp);
29310 +#endif
29311 +
29312 + if (err)
29313 return -EFAULT;
29314 buf += sz;
29315 p += sz;
29316 @@ -867,6 +914,9 @@ static const struct memdev {
29317 #ifdef CONFIG_CRASH_DUMP
29318 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29319 #endif
29320 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29321 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29322 +#endif
29323 };
29324
29325 static int memory_open(struct inode *inode, struct file *filp)
29326 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29327 index da3cfee..a5a6606 100644
29328 --- a/drivers/char/nvram.c
29329 +++ b/drivers/char/nvram.c
29330 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29331
29332 spin_unlock_irq(&rtc_lock);
29333
29334 - if (copy_to_user(buf, contents, tmp - contents))
29335 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29336 return -EFAULT;
29337
29338 *ppos = i;
29339 diff --git a/drivers/char/random.c b/drivers/char/random.c
29340 index 54ca8b2..4a092ed 100644
29341 --- a/drivers/char/random.c
29342 +++ b/drivers/char/random.c
29343 @@ -261,8 +261,13 @@
29344 /*
29345 * Configuration information
29346 */
29347 +#ifdef CONFIG_GRKERNSEC_RANDNET
29348 +#define INPUT_POOL_WORDS 512
29349 +#define OUTPUT_POOL_WORDS 128
29350 +#else
29351 #define INPUT_POOL_WORDS 128
29352 #define OUTPUT_POOL_WORDS 32
29353 +#endif
29354 #define SEC_XFER_SIZE 512
29355 #define EXTRACT_SIZE 10
29356
29357 @@ -300,10 +305,17 @@ static struct poolinfo {
29358 int poolwords;
29359 int tap1, tap2, tap3, tap4, tap5;
29360 } poolinfo_table[] = {
29361 +#ifdef CONFIG_GRKERNSEC_RANDNET
29362 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29363 + { 512, 411, 308, 208, 104, 1 },
29364 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29365 + { 128, 103, 76, 51, 25, 1 },
29366 +#else
29367 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29368 { 128, 103, 76, 51, 25, 1 },
29369 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29370 { 32, 26, 20, 14, 7, 1 },
29371 +#endif
29372 #if 0
29373 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29374 { 2048, 1638, 1231, 819, 411, 1 },
29375 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29376
29377 extract_buf(r, tmp);
29378 i = min_t(int, nbytes, EXTRACT_SIZE);
29379 - if (copy_to_user(buf, tmp, i)) {
29380 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29381 ret = -EFAULT;
29382 break;
29383 }
29384 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29385 #include <linux/sysctl.h>
29386
29387 static int min_read_thresh = 8, min_write_thresh;
29388 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29389 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29390 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29391 static char sysctl_bootid[16];
29392
29393 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29394 uuid = table->data;
29395 if (!uuid) {
29396 uuid = tmp_uuid;
29397 - uuid[8] = 0;
29398 - }
29399 - if (uuid[8] == 0)
29400 generate_random_uuid(uuid);
29401 + } else {
29402 + static DEFINE_SPINLOCK(bootid_spinlock);
29403 +
29404 + spin_lock(&bootid_spinlock);
29405 + if (!uuid[8])
29406 + generate_random_uuid(uuid);
29407 + spin_unlock(&bootid_spinlock);
29408 + }
29409
29410 sprintf(buf, "%pU", uuid);
29411
29412 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29413 index 1ee8ce7..b778bef 100644
29414 --- a/drivers/char/sonypi.c
29415 +++ b/drivers/char/sonypi.c
29416 @@ -55,6 +55,7 @@
29417 #include <asm/uaccess.h>
29418 #include <asm/io.h>
29419 #include <asm/system.h>
29420 +#include <asm/local.h>
29421
29422 #include <linux/sonypi.h>
29423
29424 @@ -491,7 +492,7 @@ static struct sonypi_device {
29425 spinlock_t fifo_lock;
29426 wait_queue_head_t fifo_proc_list;
29427 struct fasync_struct *fifo_async;
29428 - int open_count;
29429 + local_t open_count;
29430 int model;
29431 struct input_dev *input_jog_dev;
29432 struct input_dev *input_key_dev;
29433 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29434 static int sonypi_misc_release(struct inode *inode, struct file *file)
29435 {
29436 mutex_lock(&sonypi_device.lock);
29437 - sonypi_device.open_count--;
29438 + local_dec(&sonypi_device.open_count);
29439 mutex_unlock(&sonypi_device.lock);
29440 return 0;
29441 }
29442 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29443 {
29444 mutex_lock(&sonypi_device.lock);
29445 /* Flush input queue on first open */
29446 - if (!sonypi_device.open_count)
29447 + if (!local_read(&sonypi_device.open_count))
29448 kfifo_reset(&sonypi_device.fifo);
29449 - sonypi_device.open_count++;
29450 + local_inc(&sonypi_device.open_count);
29451 mutex_unlock(&sonypi_device.lock);
29452
29453 return 0;
29454 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29455 index ad7c732..5aa8054 100644
29456 --- a/drivers/char/tpm/tpm.c
29457 +++ b/drivers/char/tpm/tpm.c
29458 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29459 chip->vendor.req_complete_val)
29460 goto out_recv;
29461
29462 - if ((status == chip->vendor.req_canceled)) {
29463 + if (status == chip->vendor.req_canceled) {
29464 dev_err(chip->dev, "Operation Canceled\n");
29465 rc = -ECANCELED;
29466 goto out;
29467 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29468 index 0636520..169c1d0 100644
29469 --- a/drivers/char/tpm/tpm_bios.c
29470 +++ b/drivers/char/tpm/tpm_bios.c
29471 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29472 event = addr;
29473
29474 if ((event->event_type == 0 && event->event_size == 0) ||
29475 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29476 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29477 return NULL;
29478
29479 return addr;
29480 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29481 return NULL;
29482
29483 if ((event->event_type == 0 && event->event_size == 0) ||
29484 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29485 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29486 return NULL;
29487
29488 (*pos)++;
29489 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29490 int i;
29491
29492 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29493 - seq_putc(m, data[i]);
29494 + if (!seq_putc(m, data[i]))
29495 + return -EFAULT;
29496
29497 return 0;
29498 }
29499 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29500 log->bios_event_log_end = log->bios_event_log + len;
29501
29502 virt = acpi_os_map_memory(start, len);
29503 + if (!virt) {
29504 + kfree(log->bios_event_log);
29505 + log->bios_event_log = NULL;
29506 + return -EFAULT;
29507 + }
29508
29509 - memcpy(log->bios_event_log, virt, len);
29510 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29511
29512 acpi_os_unmap_memory(virt, len);
29513 return 0;
29514 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29515 index b58b561..c9088c8 100644
29516 --- a/drivers/char/virtio_console.c
29517 +++ b/drivers/char/virtio_console.c
29518 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29519 if (to_user) {
29520 ssize_t ret;
29521
29522 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29523 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29524 if (ret)
29525 return -EFAULT;
29526 } else {
29527 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29528 if (!port_has_data(port) && !port->host_connected)
29529 return 0;
29530
29531 - return fill_readbuf(port, ubuf, count, true);
29532 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29533 }
29534
29535 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29536 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29537 index c9eee6d..f9d5280 100644
29538 --- a/drivers/edac/amd64_edac.c
29539 +++ b/drivers/edac/amd64_edac.c
29540 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29541 * PCI core identifies what devices are on a system during boot, and then
29542 * inquiry this table to see if this driver is for a given device found.
29543 */
29544 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29545 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29546 {
29547 .vendor = PCI_VENDOR_ID_AMD,
29548 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29549 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29550 index e47e73b..348e0bd 100644
29551 --- a/drivers/edac/amd76x_edac.c
29552 +++ b/drivers/edac/amd76x_edac.c
29553 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29554 edac_mc_free(mci);
29555 }
29556
29557 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29558 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29559 {
29560 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29561 AMD762},
29562 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29563 index 1af531a..3a8ff27 100644
29564 --- a/drivers/edac/e752x_edac.c
29565 +++ b/drivers/edac/e752x_edac.c
29566 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29567 edac_mc_free(mci);
29568 }
29569
29570 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29571 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29572 {
29573 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29574 E7520},
29575 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29576 index 6ffb6d2..383d8d7 100644
29577 --- a/drivers/edac/e7xxx_edac.c
29578 +++ b/drivers/edac/e7xxx_edac.c
29579 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29580 edac_mc_free(mci);
29581 }
29582
29583 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29584 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29585 {
29586 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29587 E7205},
29588 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29589 index 97f5064..202b6e6 100644
29590 --- a/drivers/edac/edac_pci_sysfs.c
29591 +++ b/drivers/edac/edac_pci_sysfs.c
29592 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29593 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29594 static int edac_pci_poll_msec = 1000; /* one second workq period */
29595
29596 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29597 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29598 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29599 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29600
29601 static struct kobject *edac_pci_top_main_kobj;
29602 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29603 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29604 edac_printk(KERN_CRIT, EDAC_PCI,
29605 "Signaled System Error on %s\n",
29606 pci_name(dev));
29607 - atomic_inc(&pci_nonparity_count);
29608 + atomic_inc_unchecked(&pci_nonparity_count);
29609 }
29610
29611 if (status & (PCI_STATUS_PARITY)) {
29612 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29613 "Master Data Parity Error on %s\n",
29614 pci_name(dev));
29615
29616 - atomic_inc(&pci_parity_count);
29617 + atomic_inc_unchecked(&pci_parity_count);
29618 }
29619
29620 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29621 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29622 "Detected Parity Error on %s\n",
29623 pci_name(dev));
29624
29625 - atomic_inc(&pci_parity_count);
29626 + atomic_inc_unchecked(&pci_parity_count);
29627 }
29628 }
29629
29630 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29631 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29632 "Signaled System Error on %s\n",
29633 pci_name(dev));
29634 - atomic_inc(&pci_nonparity_count);
29635 + atomic_inc_unchecked(&pci_nonparity_count);
29636 }
29637
29638 if (status & (PCI_STATUS_PARITY)) {
29639 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29640 "Master Data Parity Error on "
29641 "%s\n", pci_name(dev));
29642
29643 - atomic_inc(&pci_parity_count);
29644 + atomic_inc_unchecked(&pci_parity_count);
29645 }
29646
29647 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29648 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29649 "Detected Parity Error on %s\n",
29650 pci_name(dev));
29651
29652 - atomic_inc(&pci_parity_count);
29653 + atomic_inc_unchecked(&pci_parity_count);
29654 }
29655 }
29656 }
29657 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29658 if (!check_pci_errors)
29659 return;
29660
29661 - before_count = atomic_read(&pci_parity_count);
29662 + before_count = atomic_read_unchecked(&pci_parity_count);
29663
29664 /* scan all PCI devices looking for a Parity Error on devices and
29665 * bridges.
29666 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29667 /* Only if operator has selected panic on PCI Error */
29668 if (edac_pci_get_panic_on_pe()) {
29669 /* If the count is different 'after' from 'before' */
29670 - if (before_count != atomic_read(&pci_parity_count))
29671 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29672 panic("EDAC: PCI Parity Error");
29673 }
29674 }
29675 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29676 index c0510b3..6e2a954 100644
29677 --- a/drivers/edac/i3000_edac.c
29678 +++ b/drivers/edac/i3000_edac.c
29679 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29680 edac_mc_free(mci);
29681 }
29682
29683 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29684 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29685 {
29686 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29687 I3000},
29688 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29689 index 73f55e200..5faaf59 100644
29690 --- a/drivers/edac/i3200_edac.c
29691 +++ b/drivers/edac/i3200_edac.c
29692 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29693 edac_mc_free(mci);
29694 }
29695
29696 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29697 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29698 {
29699 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29700 I3200},
29701 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29702 index 4dc3ac2..67d05a6 100644
29703 --- a/drivers/edac/i5000_edac.c
29704 +++ b/drivers/edac/i5000_edac.c
29705 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29706 *
29707 * The "E500P" device is the first device supported.
29708 */
29709 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29710 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29711 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29712 .driver_data = I5000P},
29713
29714 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29715 index bcbdeec..9886d16 100644
29716 --- a/drivers/edac/i5100_edac.c
29717 +++ b/drivers/edac/i5100_edac.c
29718 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29719 edac_mc_free(mci);
29720 }
29721
29722 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29723 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29724 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29725 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29726 { 0, }
29727 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29728 index 74d6ec34..baff517 100644
29729 --- a/drivers/edac/i5400_edac.c
29730 +++ b/drivers/edac/i5400_edac.c
29731 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29732 *
29733 * The "E500P" device is the first device supported.
29734 */
29735 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29736 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29737 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29738 {0,} /* 0 terminated list. */
29739 };
29740 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29741 index 6104dba..e7ea8e1 100644
29742 --- a/drivers/edac/i7300_edac.c
29743 +++ b/drivers/edac/i7300_edac.c
29744 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29745 *
29746 * Has only 8086:360c PCI ID
29747 */
29748 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29749 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29750 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29751 {0,} /* 0 terminated list. */
29752 };
29753 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29754 index 8568d9b..42b2fa8 100644
29755 --- a/drivers/edac/i7core_edac.c
29756 +++ b/drivers/edac/i7core_edac.c
29757 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29758 /*
29759 * pci_device_id table for which devices we are looking for
29760 */
29761 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29762 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29763 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29764 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29765 {0,} /* 0 terminated list. */
29766 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29767 index 4329d39..f3022ef 100644
29768 --- a/drivers/edac/i82443bxgx_edac.c
29769 +++ b/drivers/edac/i82443bxgx_edac.c
29770 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29771
29772 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29773
29774 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29775 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29776 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29777 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29778 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29779 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29780 index 931a057..fd28340 100644
29781 --- a/drivers/edac/i82860_edac.c
29782 +++ b/drivers/edac/i82860_edac.c
29783 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29784 edac_mc_free(mci);
29785 }
29786
29787 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29788 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29789 {
29790 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29791 I82860},
29792 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29793 index 33864c6..01edc61 100644
29794 --- a/drivers/edac/i82875p_edac.c
29795 +++ b/drivers/edac/i82875p_edac.c
29796 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29797 edac_mc_free(mci);
29798 }
29799
29800 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29801 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29802 {
29803 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29804 I82875P},
29805 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29806 index 4184e01..dcb2cd3 100644
29807 --- a/drivers/edac/i82975x_edac.c
29808 +++ b/drivers/edac/i82975x_edac.c
29809 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29810 edac_mc_free(mci);
29811 }
29812
29813 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29814 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29815 {
29816 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29817 I82975X
29818 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29819 index 0106747..0b40417 100644
29820 --- a/drivers/edac/mce_amd.h
29821 +++ b/drivers/edac/mce_amd.h
29822 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29823 bool (*dc_mce)(u16, u8);
29824 bool (*ic_mce)(u16, u8);
29825 bool (*nb_mce)(u16, u8);
29826 -};
29827 +} __no_const;
29828
29829 void amd_report_gart_errors(bool);
29830 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29831 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29832 index e294e1b..a41b05b 100644
29833 --- a/drivers/edac/r82600_edac.c
29834 +++ b/drivers/edac/r82600_edac.c
29835 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29836 edac_mc_free(mci);
29837 }
29838
29839 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29840 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29841 {
29842 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29843 },
29844 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29845 index 1dc118d..8c68af9 100644
29846 --- a/drivers/edac/sb_edac.c
29847 +++ b/drivers/edac/sb_edac.c
29848 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29849 /*
29850 * pci_device_id table for which devices we are looking for
29851 */
29852 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29853 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29854 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29855 {0,} /* 0 terminated list. */
29856 };
29857 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29858 index b6f47de..c5acf3a 100644
29859 --- a/drivers/edac/x38_edac.c
29860 +++ b/drivers/edac/x38_edac.c
29861 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29862 edac_mc_free(mci);
29863 }
29864
29865 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29866 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29867 {
29868 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29869 X38},
29870 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29871 index 85661b0..c784559a 100644
29872 --- a/drivers/firewire/core-card.c
29873 +++ b/drivers/firewire/core-card.c
29874 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29875
29876 void fw_core_remove_card(struct fw_card *card)
29877 {
29878 - struct fw_card_driver dummy_driver = dummy_driver_template;
29879 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29880
29881 card->driver->update_phy_reg(card, 4,
29882 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29883 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29884 index 4799393..37bd3ab 100644
29885 --- a/drivers/firewire/core-cdev.c
29886 +++ b/drivers/firewire/core-cdev.c
29887 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29888 int ret;
29889
29890 if ((request->channels == 0 && request->bandwidth == 0) ||
29891 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29892 - request->bandwidth < 0)
29893 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29894 return -EINVAL;
29895
29896 r = kmalloc(sizeof(*r), GFP_KERNEL);
29897 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29898 index 855ab3f..11f4bbd 100644
29899 --- a/drivers/firewire/core-transaction.c
29900 +++ b/drivers/firewire/core-transaction.c
29901 @@ -37,6 +37,7 @@
29902 #include <linux/timer.h>
29903 #include <linux/types.h>
29904 #include <linux/workqueue.h>
29905 +#include <linux/sched.h>
29906
29907 #include <asm/byteorder.h>
29908
29909 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29910 index b45be57..5fad18b 100644
29911 --- a/drivers/firewire/core.h
29912 +++ b/drivers/firewire/core.h
29913 @@ -101,6 +101,7 @@ struct fw_card_driver {
29914
29915 int (*stop_iso)(struct fw_iso_context *ctx);
29916 };
29917 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29918
29919 void fw_card_initialize(struct fw_card *card,
29920 const struct fw_card_driver *driver, struct device *device);
29921 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29922 index 153980b..4b4d046 100644
29923 --- a/drivers/firmware/dmi_scan.c
29924 +++ b/drivers/firmware/dmi_scan.c
29925 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29926 }
29927 }
29928 else {
29929 - /*
29930 - * no iounmap() for that ioremap(); it would be a no-op, but
29931 - * it's so early in setup that sucker gets confused into doing
29932 - * what it shouldn't if we actually call it.
29933 - */
29934 p = dmi_ioremap(0xF0000, 0x10000);
29935 if (p == NULL)
29936 goto error;
29937 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29938 if (buf == NULL)
29939 return -1;
29940
29941 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29942 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29943
29944 iounmap(buf);
29945 return 0;
29946 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29947 index 82d5c20..44a7177 100644
29948 --- a/drivers/gpio/gpio-vr41xx.c
29949 +++ b/drivers/gpio/gpio-vr41xx.c
29950 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29951 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29952 maskl, pendl, maskh, pendh);
29953
29954 - atomic_inc(&irq_err_count);
29955 + atomic_inc_unchecked(&irq_err_count);
29956
29957 return -EINVAL;
29958 }
29959 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29960 index 84a4a80..ce0306e 100644
29961 --- a/drivers/gpu/drm/drm_crtc_helper.c
29962 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29963 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29964 struct drm_crtc *tmp;
29965 int crtc_mask = 1;
29966
29967 - WARN(!crtc, "checking null crtc?\n");
29968 + BUG_ON(!crtc);
29969
29970 dev = crtc->dev;
29971
29972 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29973 index ebf7d3f..d64c436 100644
29974 --- a/drivers/gpu/drm/drm_drv.c
29975 +++ b/drivers/gpu/drm/drm_drv.c
29976 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29977 /**
29978 * Copy and IOCTL return string to user space
29979 */
29980 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29981 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29982 {
29983 int len;
29984
29985 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29986
29987 dev = file_priv->minor->dev;
29988 atomic_inc(&dev->ioctl_count);
29989 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29990 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29991 ++file_priv->ioctl_count;
29992
29993 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29994 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29995 index 6263b01..7987f55 100644
29996 --- a/drivers/gpu/drm/drm_fops.c
29997 +++ b/drivers/gpu/drm/drm_fops.c
29998 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29999 }
30000
30001 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30002 - atomic_set(&dev->counts[i], 0);
30003 + atomic_set_unchecked(&dev->counts[i], 0);
30004
30005 dev->sigdata.lock = NULL;
30006
30007 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30008
30009 retcode = drm_open_helper(inode, filp, dev);
30010 if (!retcode) {
30011 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30012 - if (!dev->open_count++)
30013 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30014 + if (local_inc_return(&dev->open_count) == 1)
30015 retcode = drm_setup(dev);
30016 }
30017 if (!retcode) {
30018 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30019
30020 mutex_lock(&drm_global_mutex);
30021
30022 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30023 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30024
30025 if (dev->driver->preclose)
30026 dev->driver->preclose(dev, file_priv);
30027 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30028 * Begin inline drm_release
30029 */
30030
30031 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30032 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30033 task_pid_nr(current),
30034 (long)old_encode_dev(file_priv->minor->device),
30035 - dev->open_count);
30036 + local_read(&dev->open_count));
30037
30038 /* Release any auth tokens that might point to this file_priv,
30039 (do that under the drm_global_mutex) */
30040 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30041 * End inline drm_release
30042 */
30043
30044 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30045 - if (!--dev->open_count) {
30046 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30047 + if (local_dec_and_test(&dev->open_count)) {
30048 if (atomic_read(&dev->ioctl_count)) {
30049 DRM_ERROR("Device busy: %d\n",
30050 atomic_read(&dev->ioctl_count));
30051 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30052 index c87dc96..326055d 100644
30053 --- a/drivers/gpu/drm/drm_global.c
30054 +++ b/drivers/gpu/drm/drm_global.c
30055 @@ -36,7 +36,7 @@
30056 struct drm_global_item {
30057 struct mutex mutex;
30058 void *object;
30059 - int refcount;
30060 + atomic_t refcount;
30061 };
30062
30063 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30064 @@ -49,7 +49,7 @@ void drm_global_init(void)
30065 struct drm_global_item *item = &glob[i];
30066 mutex_init(&item->mutex);
30067 item->object = NULL;
30068 - item->refcount = 0;
30069 + atomic_set(&item->refcount, 0);
30070 }
30071 }
30072
30073 @@ -59,7 +59,7 @@ void drm_global_release(void)
30074 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30075 struct drm_global_item *item = &glob[i];
30076 BUG_ON(item->object != NULL);
30077 - BUG_ON(item->refcount != 0);
30078 + BUG_ON(atomic_read(&item->refcount) != 0);
30079 }
30080 }
30081
30082 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30083 void *object;
30084
30085 mutex_lock(&item->mutex);
30086 - if (item->refcount == 0) {
30087 + if (atomic_read(&item->refcount) == 0) {
30088 item->object = kzalloc(ref->size, GFP_KERNEL);
30089 if (unlikely(item->object == NULL)) {
30090 ret = -ENOMEM;
30091 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30092 goto out_err;
30093
30094 }
30095 - ++item->refcount;
30096 + atomic_inc(&item->refcount);
30097 ref->object = item->object;
30098 object = item->object;
30099 mutex_unlock(&item->mutex);
30100 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30101 struct drm_global_item *item = &glob[ref->global_type];
30102
30103 mutex_lock(&item->mutex);
30104 - BUG_ON(item->refcount == 0);
30105 + BUG_ON(atomic_read(&item->refcount) == 0);
30106 BUG_ON(ref->object != item->object);
30107 - if (--item->refcount == 0) {
30108 + if (atomic_dec_and_test(&item->refcount)) {
30109 ref->release(ref);
30110 item->object = NULL;
30111 }
30112 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30113 index ab1162d..42587b2 100644
30114 --- a/drivers/gpu/drm/drm_info.c
30115 +++ b/drivers/gpu/drm/drm_info.c
30116 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30117 struct drm_local_map *map;
30118 struct drm_map_list *r_list;
30119
30120 - /* Hardcoded from _DRM_FRAME_BUFFER,
30121 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30122 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30123 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30124 + static const char * const types[] = {
30125 + [_DRM_FRAME_BUFFER] = "FB",
30126 + [_DRM_REGISTERS] = "REG",
30127 + [_DRM_SHM] = "SHM",
30128 + [_DRM_AGP] = "AGP",
30129 + [_DRM_SCATTER_GATHER] = "SG",
30130 + [_DRM_CONSISTENT] = "PCI",
30131 + [_DRM_GEM] = "GEM" };
30132 const char *type;
30133 int i;
30134
30135 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30136 map = r_list->map;
30137 if (!map)
30138 continue;
30139 - if (map->type < 0 || map->type > 5)
30140 + if (map->type >= ARRAY_SIZE(types))
30141 type = "??";
30142 else
30143 type = types[map->type];
30144 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30145 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30146 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30147 vma->vm_flags & VM_IO ? 'i' : '-',
30148 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30149 + 0);
30150 +#else
30151 vma->vm_pgoff);
30152 +#endif
30153
30154 #if defined(__i386__)
30155 pgprot = pgprot_val(vma->vm_page_prot);
30156 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30157 index 637fcc3..e890b33 100644
30158 --- a/drivers/gpu/drm/drm_ioc32.c
30159 +++ b/drivers/gpu/drm/drm_ioc32.c
30160 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30161 request = compat_alloc_user_space(nbytes);
30162 if (!access_ok(VERIFY_WRITE, request, nbytes))
30163 return -EFAULT;
30164 - list = (struct drm_buf_desc *) (request + 1);
30165 + list = (struct drm_buf_desc __user *) (request + 1);
30166
30167 if (__put_user(count, &request->count)
30168 || __put_user(list, &request->list))
30169 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30170 request = compat_alloc_user_space(nbytes);
30171 if (!access_ok(VERIFY_WRITE, request, nbytes))
30172 return -EFAULT;
30173 - list = (struct drm_buf_pub *) (request + 1);
30174 + list = (struct drm_buf_pub __user *) (request + 1);
30175
30176 if (__put_user(count, &request->count)
30177 || __put_user(list, &request->list))
30178 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30179 index 956fd38..e52167a 100644
30180 --- a/drivers/gpu/drm/drm_ioctl.c
30181 +++ b/drivers/gpu/drm/drm_ioctl.c
30182 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30183 stats->data[i].value =
30184 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30185 else
30186 - stats->data[i].value = atomic_read(&dev->counts[i]);
30187 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30188 stats->data[i].type = dev->types[i];
30189 }
30190
30191 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30192 index c79c713..2048588 100644
30193 --- a/drivers/gpu/drm/drm_lock.c
30194 +++ b/drivers/gpu/drm/drm_lock.c
30195 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30196 if (drm_lock_take(&master->lock, lock->context)) {
30197 master->lock.file_priv = file_priv;
30198 master->lock.lock_time = jiffies;
30199 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30200 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30201 break; /* Got lock */
30202 }
30203
30204 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30205 return -EINVAL;
30206 }
30207
30208 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30209 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30210
30211 if (drm_lock_free(&master->lock, lock->context)) {
30212 /* FIXME: Should really bail out here. */
30213 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30214 index 7f4b4e1..bf4def2 100644
30215 --- a/drivers/gpu/drm/i810/i810_dma.c
30216 +++ b/drivers/gpu/drm/i810/i810_dma.c
30217 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30218 dma->buflist[vertex->idx],
30219 vertex->discard, vertex->used);
30220
30221 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30222 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30223 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30224 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30225 sarea_priv->last_enqueue = dev_priv->counter - 1;
30226 sarea_priv->last_dispatch = (int)hw_status[5];
30227
30228 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30229 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30230 mc->last_render);
30231
30232 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30233 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30234 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30235 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30236 sarea_priv->last_enqueue = dev_priv->counter - 1;
30237 sarea_priv->last_dispatch = (int)hw_status[5];
30238
30239 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30240 index c9339f4..f5e1b9d 100644
30241 --- a/drivers/gpu/drm/i810/i810_drv.h
30242 +++ b/drivers/gpu/drm/i810/i810_drv.h
30243 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30244 int page_flipping;
30245
30246 wait_queue_head_t irq_queue;
30247 - atomic_t irq_received;
30248 - atomic_t irq_emitted;
30249 + atomic_unchecked_t irq_received;
30250 + atomic_unchecked_t irq_emitted;
30251
30252 int front_offset;
30253 } drm_i810_private_t;
30254 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30255 index deaa657..e0fd296 100644
30256 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30257 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30258 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30259 I915_READ(GTIMR));
30260 }
30261 seq_printf(m, "Interrupts received: %d\n",
30262 - atomic_read(&dev_priv->irq_received));
30263 + atomic_read_unchecked(&dev_priv->irq_received));
30264 for (i = 0; i < I915_NUM_RINGS; i++) {
30265 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30266 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30267 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30268 return ret;
30269
30270 if (opregion->header)
30271 - seq_write(m, opregion->header, OPREGION_SIZE);
30272 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30273
30274 mutex_unlock(&dev->struct_mutex);
30275
30276 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30277 index ddfe3d9..f6e6b21 100644
30278 --- a/drivers/gpu/drm/i915/i915_dma.c
30279 +++ b/drivers/gpu/drm/i915/i915_dma.c
30280 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30281 bool can_switch;
30282
30283 spin_lock(&dev->count_lock);
30284 - can_switch = (dev->open_count == 0);
30285 + can_switch = (local_read(&dev->open_count) == 0);
30286 spin_unlock(&dev->count_lock);
30287 return can_switch;
30288 }
30289 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30290 index 9689ca3..294f9c1 100644
30291 --- a/drivers/gpu/drm/i915/i915_drv.h
30292 +++ b/drivers/gpu/drm/i915/i915_drv.h
30293 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30294 /* render clock increase/decrease */
30295 /* display clock increase/decrease */
30296 /* pll clock increase/decrease */
30297 -};
30298 +} __no_const;
30299
30300 struct intel_device_info {
30301 u8 gen;
30302 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30303 int current_page;
30304 int page_flipping;
30305
30306 - atomic_t irq_received;
30307 + atomic_unchecked_t irq_received;
30308
30309 /* protects the irq masks */
30310 spinlock_t irq_lock;
30311 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30312 * will be page flipped away on the next vblank. When it
30313 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30314 */
30315 - atomic_t pending_flip;
30316 + atomic_unchecked_t pending_flip;
30317 };
30318
30319 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30320 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30321 extern void intel_teardown_gmbus(struct drm_device *dev);
30322 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30323 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30324 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30325 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30326 {
30327 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30328 }
30329 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30330 index 65e1f00..a30ef00 100644
30331 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30332 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30333 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30334 i915_gem_clflush_object(obj);
30335
30336 if (obj->base.pending_write_domain)
30337 - cd->flips |= atomic_read(&obj->pending_flip);
30338 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30339
30340 /* The actual obj->write_domain will be updated with
30341 * pending_write_domain after we emit the accumulated flush for all
30342 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30343
30344 static int
30345 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30346 - int count)
30347 + unsigned int count)
30348 {
30349 - int i;
30350 + unsigned int i;
30351
30352 for (i = 0; i < count; i++) {
30353 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30354 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30355 index 5bd4361..0241a42 100644
30356 --- a/drivers/gpu/drm/i915/i915_irq.c
30357 +++ b/drivers/gpu/drm/i915/i915_irq.c
30358 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30359 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30360 struct drm_i915_master_private *master_priv;
30361
30362 - atomic_inc(&dev_priv->irq_received);
30363 + atomic_inc_unchecked(&dev_priv->irq_received);
30364
30365 /* disable master interrupt before clearing iir */
30366 de_ier = I915_READ(DEIER);
30367 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30368 struct drm_i915_master_private *master_priv;
30369 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30370
30371 - atomic_inc(&dev_priv->irq_received);
30372 + atomic_inc_unchecked(&dev_priv->irq_received);
30373
30374 if (IS_GEN6(dev))
30375 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30376 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30377 int ret = IRQ_NONE, pipe;
30378 bool blc_event = false;
30379
30380 - atomic_inc(&dev_priv->irq_received);
30381 + atomic_inc_unchecked(&dev_priv->irq_received);
30382
30383 iir = I915_READ(IIR);
30384
30385 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30386 {
30387 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30388
30389 - atomic_set(&dev_priv->irq_received, 0);
30390 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30391
30392 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30393 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30394 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30395 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30396 int pipe;
30397
30398 - atomic_set(&dev_priv->irq_received, 0);
30399 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30400
30401 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30402 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30403 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30404 index 2163818..e536c3d 100644
30405 --- a/drivers/gpu/drm/i915/intel_display.c
30406 +++ b/drivers/gpu/drm/i915/intel_display.c
30407 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30408
30409 wait_event(dev_priv->pending_flip_queue,
30410 atomic_read(&dev_priv->mm.wedged) ||
30411 - atomic_read(&obj->pending_flip) == 0);
30412 + atomic_read_unchecked(&obj->pending_flip) == 0);
30413
30414 /* Big Hammer, we also need to ensure that any pending
30415 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30416 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30417 obj = to_intel_framebuffer(crtc->fb)->obj;
30418 dev_priv = crtc->dev->dev_private;
30419 wait_event(dev_priv->pending_flip_queue,
30420 - atomic_read(&obj->pending_flip) == 0);
30421 + atomic_read_unchecked(&obj->pending_flip) == 0);
30422 }
30423
30424 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30425 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30426
30427 atomic_clear_mask(1 << intel_crtc->plane,
30428 &obj->pending_flip.counter);
30429 - if (atomic_read(&obj->pending_flip) == 0)
30430 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30431 wake_up(&dev_priv->pending_flip_queue);
30432
30433 schedule_work(&work->work);
30434 @@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30435 /* Block clients from rendering to the new back buffer until
30436 * the flip occurs and the object is no longer visible.
30437 */
30438 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30439 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30440
30441 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30442 if (ret)
30443 @@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30444 return 0;
30445
30446 cleanup_pending:
30447 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30448 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30449 drm_gem_object_unreference(&work->old_fb_obj->base);
30450 drm_gem_object_unreference(&obj->base);
30451 mutex_unlock(&dev->struct_mutex);
30452 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30453 index 54558a0..2d97005 100644
30454 --- a/drivers/gpu/drm/mga/mga_drv.h
30455 +++ b/drivers/gpu/drm/mga/mga_drv.h
30456 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30457 u32 clear_cmd;
30458 u32 maccess;
30459
30460 - atomic_t vbl_received; /**< Number of vblanks received. */
30461 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30462 wait_queue_head_t fence_queue;
30463 - atomic_t last_fence_retired;
30464 + atomic_unchecked_t last_fence_retired;
30465 u32 next_fence_to_post;
30466
30467 unsigned int fb_cpp;
30468 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30469 index 2581202..f230a8d9 100644
30470 --- a/drivers/gpu/drm/mga/mga_irq.c
30471 +++ b/drivers/gpu/drm/mga/mga_irq.c
30472 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30473 if (crtc != 0)
30474 return 0;
30475
30476 - return atomic_read(&dev_priv->vbl_received);
30477 + return atomic_read_unchecked(&dev_priv->vbl_received);
30478 }
30479
30480
30481 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30482 /* VBLANK interrupt */
30483 if (status & MGA_VLINEPEN) {
30484 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30485 - atomic_inc(&dev_priv->vbl_received);
30486 + atomic_inc_unchecked(&dev_priv->vbl_received);
30487 drm_handle_vblank(dev, 0);
30488 handled = 1;
30489 }
30490 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30491 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30492 MGA_WRITE(MGA_PRIMEND, prim_end);
30493
30494 - atomic_inc(&dev_priv->last_fence_retired);
30495 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30496 DRM_WAKEUP(&dev_priv->fence_queue);
30497 handled = 1;
30498 }
30499 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30500 * using fences.
30501 */
30502 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30503 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30504 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30505 - *sequence) <= (1 << 23)));
30506
30507 *sequence = cur_fence;
30508 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30509 index e5cbead..6c354a3 100644
30510 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30511 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30512 @@ -199,7 +199,7 @@ struct methods {
30513 const char desc[8];
30514 void (*loadbios)(struct drm_device *, uint8_t *);
30515 const bool rw;
30516 -};
30517 +} __do_const;
30518
30519 static struct methods shadow_methods[] = {
30520 { "PRAMIN", load_vbios_pramin, true },
30521 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30522 struct bit_table {
30523 const char id;
30524 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30525 -};
30526 +} __no_const;
30527
30528 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30529
30530 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30531 index b827098..c31a797 100644
30532 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30533 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30534 @@ -242,7 +242,7 @@ struct nouveau_channel {
30535 struct list_head pending;
30536 uint32_t sequence;
30537 uint32_t sequence_ack;
30538 - atomic_t last_sequence_irq;
30539 + atomic_unchecked_t last_sequence_irq;
30540 struct nouveau_vma vma;
30541 } fence;
30542
30543 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30544 u32 handle, u16 class);
30545 void (*set_tile_region)(struct drm_device *dev, int i);
30546 void (*tlb_flush)(struct drm_device *, int engine);
30547 -};
30548 +} __no_const;
30549
30550 struct nouveau_instmem_engine {
30551 void *priv;
30552 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30553 struct nouveau_mc_engine {
30554 int (*init)(struct drm_device *dev);
30555 void (*takedown)(struct drm_device *dev);
30556 -};
30557 +} __no_const;
30558
30559 struct nouveau_timer_engine {
30560 int (*init)(struct drm_device *dev);
30561 void (*takedown)(struct drm_device *dev);
30562 uint64_t (*read)(struct drm_device *dev);
30563 -};
30564 +} __no_const;
30565
30566 struct nouveau_fb_engine {
30567 int num_tiles;
30568 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30569 void (*put)(struct drm_device *, struct nouveau_mem **);
30570
30571 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30572 -};
30573 +} __no_const;
30574
30575 struct nouveau_engine {
30576 struct nouveau_instmem_engine instmem;
30577 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30578 struct drm_global_reference mem_global_ref;
30579 struct ttm_bo_global_ref bo_global_ref;
30580 struct ttm_bo_device bdev;
30581 - atomic_t validate_sequence;
30582 + atomic_unchecked_t validate_sequence;
30583 } ttm;
30584
30585 struct {
30586 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30587 index 2f6daae..c9d7b9e 100644
30588 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30589 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30590 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30591 if (USE_REFCNT(dev))
30592 sequence = nvchan_rd32(chan, 0x48);
30593 else
30594 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30595 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30596
30597 if (chan->fence.sequence_ack == sequence)
30598 goto out;
30599 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30600 return ret;
30601 }
30602
30603 - atomic_set(&chan->fence.last_sequence_irq, 0);
30604 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30605 return 0;
30606 }
30607
30608 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30609 index 7ce3fde..cb3ea04 100644
30610 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30611 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30612 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30613 int trycnt = 0;
30614 int ret, i;
30615
30616 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30617 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30618 retry:
30619 if (++trycnt > 100000) {
30620 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30621 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30622 index f80c5e0..936baa7 100644
30623 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30624 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30625 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30626 bool can_switch;
30627
30628 spin_lock(&dev->count_lock);
30629 - can_switch = (dev->open_count == 0);
30630 + can_switch = (local_read(&dev->open_count) == 0);
30631 spin_unlock(&dev->count_lock);
30632 return can_switch;
30633 }
30634 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30635 index dbdea8e..cd6eeeb 100644
30636 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30637 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30638 @@ -554,7 +554,7 @@ static int
30639 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30640 u32 class, u32 mthd, u32 data)
30641 {
30642 - atomic_set(&chan->fence.last_sequence_irq, data);
30643 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30644 return 0;
30645 }
30646
30647 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30648 index bcac90b..53bfc76 100644
30649 --- a/drivers/gpu/drm/r128/r128_cce.c
30650 +++ b/drivers/gpu/drm/r128/r128_cce.c
30651 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30652
30653 /* GH: Simple idle check.
30654 */
30655 - atomic_set(&dev_priv->idle_count, 0);
30656 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30657
30658 /* We don't support anything other than bus-mastering ring mode,
30659 * but the ring can be in either AGP or PCI space for the ring
30660 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30661 index 930c71b..499aded 100644
30662 --- a/drivers/gpu/drm/r128/r128_drv.h
30663 +++ b/drivers/gpu/drm/r128/r128_drv.h
30664 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30665 int is_pci;
30666 unsigned long cce_buffers_offset;
30667
30668 - atomic_t idle_count;
30669 + atomic_unchecked_t idle_count;
30670
30671 int page_flipping;
30672 int current_page;
30673 u32 crtc_offset;
30674 u32 crtc_offset_cntl;
30675
30676 - atomic_t vbl_received;
30677 + atomic_unchecked_t vbl_received;
30678
30679 u32 color_fmt;
30680 unsigned int front_offset;
30681 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30682 index 429d5a0..7e899ed 100644
30683 --- a/drivers/gpu/drm/r128/r128_irq.c
30684 +++ b/drivers/gpu/drm/r128/r128_irq.c
30685 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30686 if (crtc != 0)
30687 return 0;
30688
30689 - return atomic_read(&dev_priv->vbl_received);
30690 + return atomic_read_unchecked(&dev_priv->vbl_received);
30691 }
30692
30693 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30694 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30695 /* VBLANK interrupt */
30696 if (status & R128_CRTC_VBLANK_INT) {
30697 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30698 - atomic_inc(&dev_priv->vbl_received);
30699 + atomic_inc_unchecked(&dev_priv->vbl_received);
30700 drm_handle_vblank(dev, 0);
30701 return IRQ_HANDLED;
30702 }
30703 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30704 index a9e33ce..09edd4b 100644
30705 --- a/drivers/gpu/drm/r128/r128_state.c
30706 +++ b/drivers/gpu/drm/r128/r128_state.c
30707 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30708
30709 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30710 {
30711 - if (atomic_read(&dev_priv->idle_count) == 0)
30712 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30713 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30714 else
30715 - atomic_set(&dev_priv->idle_count, 0);
30716 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30717 }
30718
30719 #endif
30720 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30721 index 5a82b6b..9e69c73 100644
30722 --- a/drivers/gpu/drm/radeon/mkregtable.c
30723 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30724 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30725 regex_t mask_rex;
30726 regmatch_t match[4];
30727 char buf[1024];
30728 - size_t end;
30729 + long end;
30730 int len;
30731 int done = 0;
30732 int r;
30733 unsigned o;
30734 struct offset *offset;
30735 char last_reg_s[10];
30736 - int last_reg;
30737 + unsigned long last_reg;
30738
30739 if (regcomp
30740 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30741 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30742 index 1668ec1..30ebdab 100644
30743 --- a/drivers/gpu/drm/radeon/radeon.h
30744 +++ b/drivers/gpu/drm/radeon/radeon.h
30745 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30746 uint32_t scratch_reg;
30747 uint64_t gpu_addr;
30748 volatile uint32_t *cpu_addr;
30749 - atomic_t seq;
30750 + atomic_unchecked_t seq;
30751 uint32_t last_seq;
30752 unsigned long last_jiffies;
30753 unsigned long last_timeout;
30754 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30755 int x2, int y2);
30756 void (*draw_auto)(struct radeon_device *rdev);
30757 void (*set_default_state)(struct radeon_device *rdev);
30758 -};
30759 +} __no_const;
30760
30761 struct r600_blit {
30762 struct mutex mutex;
30763 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30764 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30765 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30766 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30767 -};
30768 +} __no_const;
30769
30770 /*
30771 * Asic structures
30772 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30773 index 49f7cb7..2fcb48f 100644
30774 --- a/drivers/gpu/drm/radeon/radeon_device.c
30775 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30776 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30777 bool can_switch;
30778
30779 spin_lock(&dev->count_lock);
30780 - can_switch = (dev->open_count == 0);
30781 + can_switch = (local_read(&dev->open_count) == 0);
30782 spin_unlock(&dev->count_lock);
30783 return can_switch;
30784 }
30785 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30786 index a1b59ca..86f2d44 100644
30787 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30788 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30789 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30790
30791 /* SW interrupt */
30792 wait_queue_head_t swi_queue;
30793 - atomic_t swi_emitted;
30794 + atomic_unchecked_t swi_emitted;
30795 int vblank_crtc;
30796 uint32_t irq_enable_reg;
30797 uint32_t r500_disp_irq_reg;
30798 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30799 index 4bd36a3..e66fe9c 100644
30800 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30801 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30802 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30803 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30804 return 0;
30805 }
30806 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30807 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30808 if (!rdev->ring[fence->ring].ready)
30809 /* FIXME: cp is not running assume everythings is done right
30810 * away
30811 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30812 }
30813 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30814 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30815 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30816 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30817 rdev->fence_drv[ring].initialized = true;
30818 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30819 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30820 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30821 rdev->fence_drv[ring].scratch_reg = -1;
30822 rdev->fence_drv[ring].cpu_addr = NULL;
30823 rdev->fence_drv[ring].gpu_addr = 0;
30824 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30825 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30826 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30827 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30828 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30829 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30830 index 48b7cea..342236f 100644
30831 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30832 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30833 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30834 request = compat_alloc_user_space(sizeof(*request));
30835 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30836 || __put_user(req32.param, &request->param)
30837 - || __put_user((void __user *)(unsigned long)req32.value,
30838 + || __put_user((unsigned long)req32.value,
30839 &request->value))
30840 return -EFAULT;
30841
30842 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30843 index 00da384..32f972d 100644
30844 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30845 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30846 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30847 unsigned int ret;
30848 RING_LOCALS;
30849
30850 - atomic_inc(&dev_priv->swi_emitted);
30851 - ret = atomic_read(&dev_priv->swi_emitted);
30852 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30853 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30854
30855 BEGIN_RING(4);
30856 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30857 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30858 drm_radeon_private_t *dev_priv =
30859 (drm_radeon_private_t *) dev->dev_private;
30860
30861 - atomic_set(&dev_priv->swi_emitted, 0);
30862 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30863 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30864
30865 dev->max_vblank_count = 0x001fffff;
30866 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30867 index e8422ae..d22d4a8 100644
30868 --- a/drivers/gpu/drm/radeon/radeon_state.c
30869 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30870 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30871 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30872 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30873
30874 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30875 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30876 sarea_priv->nbox * sizeof(depth_boxes[0])))
30877 return -EFAULT;
30878
30879 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30880 {
30881 drm_radeon_private_t *dev_priv = dev->dev_private;
30882 drm_radeon_getparam_t *param = data;
30883 - int value;
30884 + int value = 0;
30885
30886 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30887
30888 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30889 index c421e77..e6bf2e8 100644
30890 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30891 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30892 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30893 }
30894 if (unlikely(ttm_vm_ops == NULL)) {
30895 ttm_vm_ops = vma->vm_ops;
30896 - radeon_ttm_vm_ops = *ttm_vm_ops;
30897 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30898 + pax_open_kernel();
30899 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30900 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30901 + pax_close_kernel();
30902 }
30903 vma->vm_ops = &radeon_ttm_vm_ops;
30904 return 0;
30905 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30906 index f68dff2..8df955c 100644
30907 --- a/drivers/gpu/drm/radeon/rs690.c
30908 +++ b/drivers/gpu/drm/radeon/rs690.c
30909 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30910 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30911 rdev->pm.sideport_bandwidth.full)
30912 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30913 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30914 + read_delay_latency.full = dfixed_const(800 * 1000);
30915 read_delay_latency.full = dfixed_div(read_delay_latency,
30916 rdev->pm.igp_sideport_mclk);
30917 + a.full = dfixed_const(370);
30918 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30919 } else {
30920 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30921 rdev->pm.k8_bandwidth.full)
30922 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30923 index 499debd..66fce72 100644
30924 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30925 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30926 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30927 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30928 struct shrink_control *sc)
30929 {
30930 - static atomic_t start_pool = ATOMIC_INIT(0);
30931 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30932 unsigned i;
30933 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30934 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30935 struct ttm_page_pool *pool;
30936 int shrink_pages = sc->nr_to_scan;
30937
30938 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30939 index 88edacc..1e5412b 100644
30940 --- a/drivers/gpu/drm/via/via_drv.h
30941 +++ b/drivers/gpu/drm/via/via_drv.h
30942 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30943 typedef uint32_t maskarray_t[5];
30944
30945 typedef struct drm_via_irq {
30946 - atomic_t irq_received;
30947 + atomic_unchecked_t irq_received;
30948 uint32_t pending_mask;
30949 uint32_t enable_mask;
30950 wait_queue_head_t irq_queue;
30951 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30952 struct timeval last_vblank;
30953 int last_vblank_valid;
30954 unsigned usec_per_vblank;
30955 - atomic_t vbl_received;
30956 + atomic_unchecked_t vbl_received;
30957 drm_via_state_t hc_state;
30958 char pci_buf[VIA_PCI_BUF_SIZE];
30959 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30960 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30961 index d391f48..10c8ca3 100644
30962 --- a/drivers/gpu/drm/via/via_irq.c
30963 +++ b/drivers/gpu/drm/via/via_irq.c
30964 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30965 if (crtc != 0)
30966 return 0;
30967
30968 - return atomic_read(&dev_priv->vbl_received);
30969 + return atomic_read_unchecked(&dev_priv->vbl_received);
30970 }
30971
30972 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30973 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30974
30975 status = VIA_READ(VIA_REG_INTERRUPT);
30976 if (status & VIA_IRQ_VBLANK_PENDING) {
30977 - atomic_inc(&dev_priv->vbl_received);
30978 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30979 + atomic_inc_unchecked(&dev_priv->vbl_received);
30980 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30981 do_gettimeofday(&cur_vblank);
30982 if (dev_priv->last_vblank_valid) {
30983 dev_priv->usec_per_vblank =
30984 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30985 dev_priv->last_vblank = cur_vblank;
30986 dev_priv->last_vblank_valid = 1;
30987 }
30988 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30989 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30990 DRM_DEBUG("US per vblank is: %u\n",
30991 dev_priv->usec_per_vblank);
30992 }
30993 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30994
30995 for (i = 0; i < dev_priv->num_irqs; ++i) {
30996 if (status & cur_irq->pending_mask) {
30997 - atomic_inc(&cur_irq->irq_received);
30998 + atomic_inc_unchecked(&cur_irq->irq_received);
30999 DRM_WAKEUP(&cur_irq->irq_queue);
31000 handled = 1;
31001 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31002 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31003 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31004 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31005 masks[irq][4]));
31006 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31007 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31008 } else {
31009 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31010 (((cur_irq_sequence =
31011 - atomic_read(&cur_irq->irq_received)) -
31012 + atomic_read_unchecked(&cur_irq->irq_received)) -
31013 *sequence) <= (1 << 23)));
31014 }
31015 *sequence = cur_irq_sequence;
31016 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31017 }
31018
31019 for (i = 0; i < dev_priv->num_irqs; ++i) {
31020 - atomic_set(&cur_irq->irq_received, 0);
31021 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31022 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31023 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31024 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31025 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31026 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31027 case VIA_IRQ_RELATIVE:
31028 irqwait->request.sequence +=
31029 - atomic_read(&cur_irq->irq_received);
31030 + atomic_read_unchecked(&cur_irq->irq_received);
31031 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31032 case VIA_IRQ_ABSOLUTE:
31033 break;
31034 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31035 index dc27970..f18b008 100644
31036 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31037 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31038 @@ -260,7 +260,7 @@ struct vmw_private {
31039 * Fencing and IRQs.
31040 */
31041
31042 - atomic_t marker_seq;
31043 + atomic_unchecked_t marker_seq;
31044 wait_queue_head_t fence_queue;
31045 wait_queue_head_t fifo_queue;
31046 int fence_queue_waiters; /* Protected by hw_mutex */
31047 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31048 index a0c2f12..68ae6cb 100644
31049 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31050 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31051 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31052 (unsigned int) min,
31053 (unsigned int) fifo->capabilities);
31054
31055 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31056 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31057 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31058 vmw_marker_queue_init(&fifo->marker_queue);
31059 return vmw_fifo_send_fence(dev_priv, &dummy);
31060 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31061 if (reserveable)
31062 iowrite32(bytes, fifo_mem +
31063 SVGA_FIFO_RESERVED);
31064 - return fifo_mem + (next_cmd >> 2);
31065 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31066 } else {
31067 need_bounce = true;
31068 }
31069 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31070
31071 fm = vmw_fifo_reserve(dev_priv, bytes);
31072 if (unlikely(fm == NULL)) {
31073 - *seqno = atomic_read(&dev_priv->marker_seq);
31074 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31075 ret = -ENOMEM;
31076 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31077 false, 3*HZ);
31078 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31079 }
31080
31081 do {
31082 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31083 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31084 } while (*seqno == 0);
31085
31086 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31087 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31088 index cabc95f..14b3d77 100644
31089 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31090 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31091 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31092 * emitted. Then the fence is stale and signaled.
31093 */
31094
31095 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31096 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31097 > VMW_FENCE_WRAP);
31098
31099 return ret;
31100 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31101
31102 if (fifo_idle)
31103 down_read(&fifo_state->rwsem);
31104 - signal_seq = atomic_read(&dev_priv->marker_seq);
31105 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31106 ret = 0;
31107
31108 for (;;) {
31109 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31110 index 8a8725c..afed796 100644
31111 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31112 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31113 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31114 while (!vmw_lag_lt(queue, us)) {
31115 spin_lock(&queue->lock);
31116 if (list_empty(&queue->head))
31117 - seqno = atomic_read(&dev_priv->marker_seq);
31118 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31119 else {
31120 marker = list_first_entry(&queue->head,
31121 struct vmw_marker, head);
31122 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31123 index 75dbe34..f9204a8 100644
31124 --- a/drivers/hid/hid-core.c
31125 +++ b/drivers/hid/hid-core.c
31126 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31127
31128 int hid_add_device(struct hid_device *hdev)
31129 {
31130 - static atomic_t id = ATOMIC_INIT(0);
31131 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31132 int ret;
31133
31134 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31135 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31136 /* XXX hack, any other cleaner solution after the driver core
31137 * is converted to allow more than 20 bytes as the device name? */
31138 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31139 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31140 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31141
31142 hid_debug_register(hdev, dev_name(&hdev->dev));
31143 ret = device_add(&hdev->dev);
31144 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31145 index b1ec0e2..c295a61 100644
31146 --- a/drivers/hid/usbhid/hiddev.c
31147 +++ b/drivers/hid/usbhid/hiddev.c
31148 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31149 break;
31150
31151 case HIDIOCAPPLICATION:
31152 - if (arg < 0 || arg >= hid->maxapplication)
31153 + if (arg >= hid->maxapplication)
31154 break;
31155
31156 for (i = 0; i < hid->maxcollection; i++)
31157 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31158 index 4065374..10ed7dc 100644
31159 --- a/drivers/hv/channel.c
31160 +++ b/drivers/hv/channel.c
31161 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31162 int ret = 0;
31163 int t;
31164
31165 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31166 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31167 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31168 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31169
31170 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31171 if (ret)
31172 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31173 index 12aa97f..c0679f7 100644
31174 --- a/drivers/hv/hv.c
31175 +++ b/drivers/hv/hv.c
31176 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31177 u64 output_address = (output) ? virt_to_phys(output) : 0;
31178 u32 output_address_hi = output_address >> 32;
31179 u32 output_address_lo = output_address & 0xFFFFFFFF;
31180 - void *hypercall_page = hv_context.hypercall_page;
31181 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31182
31183 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31184 "=a"(hv_status_lo) : "d" (control_hi),
31185 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31186 index 6d7d286..92b0873 100644
31187 --- a/drivers/hv/hyperv_vmbus.h
31188 +++ b/drivers/hv/hyperv_vmbus.h
31189 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31190 struct vmbus_connection {
31191 enum vmbus_connect_state conn_state;
31192
31193 - atomic_t next_gpadl_handle;
31194 + atomic_unchecked_t next_gpadl_handle;
31195
31196 /*
31197 * Represents channel interrupts. Each bit position represents a
31198 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31199 index a220e57..428f54d 100644
31200 --- a/drivers/hv/vmbus_drv.c
31201 +++ b/drivers/hv/vmbus_drv.c
31202 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31203 {
31204 int ret = 0;
31205
31206 - static atomic_t device_num = ATOMIC_INIT(0);
31207 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31208
31209 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31210 - atomic_inc_return(&device_num));
31211 + atomic_inc_return_unchecked(&device_num));
31212
31213 child_device_obj->device.bus = &hv_bus;
31214 child_device_obj->device.parent = &hv_acpi_dev->dev;
31215 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31216 index 554f046..f8b4729 100644
31217 --- a/drivers/hwmon/acpi_power_meter.c
31218 +++ b/drivers/hwmon/acpi_power_meter.c
31219 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31220 return res;
31221
31222 temp /= 1000;
31223 - if (temp < 0)
31224 - return -EINVAL;
31225
31226 mutex_lock(&resource->lock);
31227 resource->trip[attr->index - 7] = temp;
31228 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31229 index 91fdd1f..b66a686 100644
31230 --- a/drivers/hwmon/sht15.c
31231 +++ b/drivers/hwmon/sht15.c
31232 @@ -166,7 +166,7 @@ struct sht15_data {
31233 int supply_uV;
31234 bool supply_uV_valid;
31235 struct work_struct update_supply_work;
31236 - atomic_t interrupt_handled;
31237 + atomic_unchecked_t interrupt_handled;
31238 };
31239
31240 /**
31241 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31242 return ret;
31243
31244 gpio_direction_input(data->pdata->gpio_data);
31245 - atomic_set(&data->interrupt_handled, 0);
31246 + atomic_set_unchecked(&data->interrupt_handled, 0);
31247
31248 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31249 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31250 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31251 /* Only relevant if the interrupt hasn't occurred. */
31252 - if (!atomic_read(&data->interrupt_handled))
31253 + if (!atomic_read_unchecked(&data->interrupt_handled))
31254 schedule_work(&data->read_work);
31255 }
31256 ret = wait_event_timeout(data->wait_queue,
31257 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31258
31259 /* First disable the interrupt */
31260 disable_irq_nosync(irq);
31261 - atomic_inc(&data->interrupt_handled);
31262 + atomic_inc_unchecked(&data->interrupt_handled);
31263 /* Then schedule a reading work struct */
31264 if (data->state != SHT15_READING_NOTHING)
31265 schedule_work(&data->read_work);
31266 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31267 * If not, then start the interrupt again - care here as could
31268 * have gone low in meantime so verify it hasn't!
31269 */
31270 - atomic_set(&data->interrupt_handled, 0);
31271 + atomic_set_unchecked(&data->interrupt_handled, 0);
31272 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31273 /* If still not occurred or another handler has been scheduled */
31274 if (gpio_get_value(data->pdata->gpio_data)
31275 - || atomic_read(&data->interrupt_handled))
31276 + || atomic_read_unchecked(&data->interrupt_handled))
31277 return;
31278 }
31279
31280 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31281 index 378fcb5..5e91fa8 100644
31282 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31283 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31284 @@ -43,7 +43,7 @@
31285 extern struct i2c_adapter amd756_smbus;
31286
31287 static struct i2c_adapter *s4882_adapter;
31288 -static struct i2c_algorithm *s4882_algo;
31289 +static i2c_algorithm_no_const *s4882_algo;
31290
31291 /* Wrapper access functions for multiplexed SMBus */
31292 static DEFINE_MUTEX(amd756_lock);
31293 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31294 index 29015eb..af2d8e9 100644
31295 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31296 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31297 @@ -41,7 +41,7 @@
31298 extern struct i2c_adapter *nforce2_smbus;
31299
31300 static struct i2c_adapter *s4985_adapter;
31301 -static struct i2c_algorithm *s4985_algo;
31302 +static i2c_algorithm_no_const *s4985_algo;
31303
31304 /* Wrapper access functions for multiplexed SMBus */
31305 static DEFINE_MUTEX(nforce2_lock);
31306 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31307 index d7a4833..7fae376 100644
31308 --- a/drivers/i2c/i2c-mux.c
31309 +++ b/drivers/i2c/i2c-mux.c
31310 @@ -28,7 +28,7 @@
31311 /* multiplexer per channel data */
31312 struct i2c_mux_priv {
31313 struct i2c_adapter adap;
31314 - struct i2c_algorithm algo;
31315 + i2c_algorithm_no_const algo;
31316
31317 struct i2c_adapter *parent;
31318 void *mux_dev; /* the mux chip/device */
31319 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31320 index 57d00ca..0145194 100644
31321 --- a/drivers/ide/aec62xx.c
31322 +++ b/drivers/ide/aec62xx.c
31323 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31324 .cable_detect = atp86x_cable_detect,
31325 };
31326
31327 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31328 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31329 { /* 0: AEC6210 */
31330 .name = DRV_NAME,
31331 .init_chipset = init_chipset_aec62xx,
31332 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31333 index 2c8016a..911a27c 100644
31334 --- a/drivers/ide/alim15x3.c
31335 +++ b/drivers/ide/alim15x3.c
31336 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31337 .dma_sff_read_status = ide_dma_sff_read_status,
31338 };
31339
31340 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31341 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31342 .name = DRV_NAME,
31343 .init_chipset = init_chipset_ali15x3,
31344 .init_hwif = init_hwif_ali15x3,
31345 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31346 index 3747b25..56fc995 100644
31347 --- a/drivers/ide/amd74xx.c
31348 +++ b/drivers/ide/amd74xx.c
31349 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31350 .udma_mask = udma, \
31351 }
31352
31353 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31354 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31355 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31356 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31357 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31358 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31359 index 15f0ead..cb43480 100644
31360 --- a/drivers/ide/atiixp.c
31361 +++ b/drivers/ide/atiixp.c
31362 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31363 .cable_detect = atiixp_cable_detect,
31364 };
31365
31366 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31367 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31368 { /* 0: IXP200/300/400/700 */
31369 .name = DRV_NAME,
31370 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31371 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31372 index 5f80312..d1fc438 100644
31373 --- a/drivers/ide/cmd64x.c
31374 +++ b/drivers/ide/cmd64x.c
31375 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31376 .dma_sff_read_status = ide_dma_sff_read_status,
31377 };
31378
31379 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31380 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31381 { /* 0: CMD643 */
31382 .name = DRV_NAME,
31383 .init_chipset = init_chipset_cmd64x,
31384 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31385 index 2c1e5f7..1444762 100644
31386 --- a/drivers/ide/cs5520.c
31387 +++ b/drivers/ide/cs5520.c
31388 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31389 .set_dma_mode = cs5520_set_dma_mode,
31390 };
31391
31392 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31393 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31394 .name = DRV_NAME,
31395 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31396 .port_ops = &cs5520_port_ops,
31397 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31398 index 4dc4eb9..49b40ad 100644
31399 --- a/drivers/ide/cs5530.c
31400 +++ b/drivers/ide/cs5530.c
31401 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31402 .udma_filter = cs5530_udma_filter,
31403 };
31404
31405 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31406 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31407 .name = DRV_NAME,
31408 .init_chipset = init_chipset_cs5530,
31409 .init_hwif = init_hwif_cs5530,
31410 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31411 index 5059faf..18d4c85 100644
31412 --- a/drivers/ide/cs5535.c
31413 +++ b/drivers/ide/cs5535.c
31414 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31415 .cable_detect = cs5535_cable_detect,
31416 };
31417
31418 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31419 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31420 .name = DRV_NAME,
31421 .port_ops = &cs5535_port_ops,
31422 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31423 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31424 index 847553f..3ffb49d 100644
31425 --- a/drivers/ide/cy82c693.c
31426 +++ b/drivers/ide/cy82c693.c
31427 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31428 .set_dma_mode = cy82c693_set_dma_mode,
31429 };
31430
31431 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31432 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31433 .name = DRV_NAME,
31434 .init_iops = init_iops_cy82c693,
31435 .port_ops = &cy82c693_port_ops,
31436 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31437 index 58c51cd..4aec3b8 100644
31438 --- a/drivers/ide/hpt366.c
31439 +++ b/drivers/ide/hpt366.c
31440 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31441 }
31442 };
31443
31444 -static const struct hpt_info hpt36x __devinitdata = {
31445 +static const struct hpt_info hpt36x __devinitconst = {
31446 .chip_name = "HPT36x",
31447 .chip_type = HPT36x,
31448 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31449 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31450 .timings = &hpt36x_timings
31451 };
31452
31453 -static const struct hpt_info hpt370 __devinitdata = {
31454 +static const struct hpt_info hpt370 __devinitconst = {
31455 .chip_name = "HPT370",
31456 .chip_type = HPT370,
31457 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31458 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31459 .timings = &hpt37x_timings
31460 };
31461
31462 -static const struct hpt_info hpt370a __devinitdata = {
31463 +static const struct hpt_info hpt370a __devinitconst = {
31464 .chip_name = "HPT370A",
31465 .chip_type = HPT370A,
31466 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31467 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31468 .timings = &hpt37x_timings
31469 };
31470
31471 -static const struct hpt_info hpt374 __devinitdata = {
31472 +static const struct hpt_info hpt374 __devinitconst = {
31473 .chip_name = "HPT374",
31474 .chip_type = HPT374,
31475 .udma_mask = ATA_UDMA5,
31476 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31477 .timings = &hpt37x_timings
31478 };
31479
31480 -static const struct hpt_info hpt372 __devinitdata = {
31481 +static const struct hpt_info hpt372 __devinitconst = {
31482 .chip_name = "HPT372",
31483 .chip_type = HPT372,
31484 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31485 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31486 .timings = &hpt37x_timings
31487 };
31488
31489 -static const struct hpt_info hpt372a __devinitdata = {
31490 +static const struct hpt_info hpt372a __devinitconst = {
31491 .chip_name = "HPT372A",
31492 .chip_type = HPT372A,
31493 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31494 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31495 .timings = &hpt37x_timings
31496 };
31497
31498 -static const struct hpt_info hpt302 __devinitdata = {
31499 +static const struct hpt_info hpt302 __devinitconst = {
31500 .chip_name = "HPT302",
31501 .chip_type = HPT302,
31502 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31503 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31504 .timings = &hpt37x_timings
31505 };
31506
31507 -static const struct hpt_info hpt371 __devinitdata = {
31508 +static const struct hpt_info hpt371 __devinitconst = {
31509 .chip_name = "HPT371",
31510 .chip_type = HPT371,
31511 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31512 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31513 .timings = &hpt37x_timings
31514 };
31515
31516 -static const struct hpt_info hpt372n __devinitdata = {
31517 +static const struct hpt_info hpt372n __devinitconst = {
31518 .chip_name = "HPT372N",
31519 .chip_type = HPT372N,
31520 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31521 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31522 .timings = &hpt37x_timings
31523 };
31524
31525 -static const struct hpt_info hpt302n __devinitdata = {
31526 +static const struct hpt_info hpt302n __devinitconst = {
31527 .chip_name = "HPT302N",
31528 .chip_type = HPT302N,
31529 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31530 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31531 .timings = &hpt37x_timings
31532 };
31533
31534 -static const struct hpt_info hpt371n __devinitdata = {
31535 +static const struct hpt_info hpt371n __devinitconst = {
31536 .chip_name = "HPT371N",
31537 .chip_type = HPT371N,
31538 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31539 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31540 .dma_sff_read_status = ide_dma_sff_read_status,
31541 };
31542
31543 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31544 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31545 { /* 0: HPT36x */
31546 .name = DRV_NAME,
31547 .init_chipset = init_chipset_hpt366,
31548 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31549 index 8126824..55a2798 100644
31550 --- a/drivers/ide/ide-cd.c
31551 +++ b/drivers/ide/ide-cd.c
31552 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31553 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31554 if ((unsigned long)buf & alignment
31555 || blk_rq_bytes(rq) & q->dma_pad_mask
31556 - || object_is_on_stack(buf))
31557 + || object_starts_on_stack(buf))
31558 drive->dma = 0;
31559 }
31560 }
31561 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31562 index 7f56b73..dab5b67 100644
31563 --- a/drivers/ide/ide-pci-generic.c
31564 +++ b/drivers/ide/ide-pci-generic.c
31565 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31566 .udma_mask = ATA_UDMA6, \
31567 }
31568
31569 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31570 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31571 /* 0: Unknown */
31572 DECLARE_GENERIC_PCI_DEV(0),
31573
31574 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31575 index 560e66d..d5dd180 100644
31576 --- a/drivers/ide/it8172.c
31577 +++ b/drivers/ide/it8172.c
31578 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31579 .set_dma_mode = it8172_set_dma_mode,
31580 };
31581
31582 -static const struct ide_port_info it8172_port_info __devinitdata = {
31583 +static const struct ide_port_info it8172_port_info __devinitconst = {
31584 .name = DRV_NAME,
31585 .port_ops = &it8172_port_ops,
31586 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31587 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31588 index 46816ba..1847aeb 100644
31589 --- a/drivers/ide/it8213.c
31590 +++ b/drivers/ide/it8213.c
31591 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31592 .cable_detect = it8213_cable_detect,
31593 };
31594
31595 -static const struct ide_port_info it8213_chipset __devinitdata = {
31596 +static const struct ide_port_info it8213_chipset __devinitconst = {
31597 .name = DRV_NAME,
31598 .enablebits = { {0x41, 0x80, 0x80} },
31599 .port_ops = &it8213_port_ops,
31600 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31601 index 2e3169f..c5611db 100644
31602 --- a/drivers/ide/it821x.c
31603 +++ b/drivers/ide/it821x.c
31604 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31605 .cable_detect = it821x_cable_detect,
31606 };
31607
31608 -static const struct ide_port_info it821x_chipset __devinitdata = {
31609 +static const struct ide_port_info it821x_chipset __devinitconst = {
31610 .name = DRV_NAME,
31611 .init_chipset = init_chipset_it821x,
31612 .init_hwif = init_hwif_it821x,
31613 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31614 index 74c2c4a..efddd7d 100644
31615 --- a/drivers/ide/jmicron.c
31616 +++ b/drivers/ide/jmicron.c
31617 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31618 .cable_detect = jmicron_cable_detect,
31619 };
31620
31621 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31622 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31623 .name = DRV_NAME,
31624 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31625 .port_ops = &jmicron_port_ops,
31626 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31627 index 95327a2..73f78d8 100644
31628 --- a/drivers/ide/ns87415.c
31629 +++ b/drivers/ide/ns87415.c
31630 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31631 .dma_sff_read_status = superio_dma_sff_read_status,
31632 };
31633
31634 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31635 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31636 .name = DRV_NAME,
31637 .init_hwif = init_hwif_ns87415,
31638 .tp_ops = &ns87415_tp_ops,
31639 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31640 index 1a53a4c..39edc66 100644
31641 --- a/drivers/ide/opti621.c
31642 +++ b/drivers/ide/opti621.c
31643 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31644 .set_pio_mode = opti621_set_pio_mode,
31645 };
31646
31647 -static const struct ide_port_info opti621_chipset __devinitdata = {
31648 +static const struct ide_port_info opti621_chipset __devinitconst = {
31649 .name = DRV_NAME,
31650 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31651 .port_ops = &opti621_port_ops,
31652 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31653 index 9546fe2..2e5ceb6 100644
31654 --- a/drivers/ide/pdc202xx_new.c
31655 +++ b/drivers/ide/pdc202xx_new.c
31656 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31657 .udma_mask = udma, \
31658 }
31659
31660 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31661 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31662 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31663 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31664 };
31665 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31666 index 3a35ec6..5634510 100644
31667 --- a/drivers/ide/pdc202xx_old.c
31668 +++ b/drivers/ide/pdc202xx_old.c
31669 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31670 .max_sectors = sectors, \
31671 }
31672
31673 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31674 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31675 { /* 0: PDC20246 */
31676 .name = DRV_NAME,
31677 .init_chipset = init_chipset_pdc202xx,
31678 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31679 index 1892e81..fe0fd60 100644
31680 --- a/drivers/ide/piix.c
31681 +++ b/drivers/ide/piix.c
31682 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31683 .udma_mask = udma, \
31684 }
31685
31686 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31687 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31688 /* 0: MPIIX */
31689 { /*
31690 * MPIIX actually has only a single IDE channel mapped to
31691 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31692 index a6414a8..c04173e 100644
31693 --- a/drivers/ide/rz1000.c
31694 +++ b/drivers/ide/rz1000.c
31695 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31696 }
31697 }
31698
31699 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31700 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31701 .name = DRV_NAME,
31702 .host_flags = IDE_HFLAG_NO_DMA,
31703 };
31704 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31705 index 356b9b5..d4758eb 100644
31706 --- a/drivers/ide/sc1200.c
31707 +++ b/drivers/ide/sc1200.c
31708 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31709 .dma_sff_read_status = ide_dma_sff_read_status,
31710 };
31711
31712 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31713 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31714 .name = DRV_NAME,
31715 .port_ops = &sc1200_port_ops,
31716 .dma_ops = &sc1200_dma_ops,
31717 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31718 index b7f5b0c..9701038 100644
31719 --- a/drivers/ide/scc_pata.c
31720 +++ b/drivers/ide/scc_pata.c
31721 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31722 .dma_sff_read_status = scc_dma_sff_read_status,
31723 };
31724
31725 -static const struct ide_port_info scc_chipset __devinitdata = {
31726 +static const struct ide_port_info scc_chipset __devinitconst = {
31727 .name = "sccIDE",
31728 .init_iops = init_iops_scc,
31729 .init_dma = scc_init_dma,
31730 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31731 index 35fb8da..24d72ef 100644
31732 --- a/drivers/ide/serverworks.c
31733 +++ b/drivers/ide/serverworks.c
31734 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31735 .cable_detect = svwks_cable_detect,
31736 };
31737
31738 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31739 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31740 { /* 0: OSB4 */
31741 .name = DRV_NAME,
31742 .init_chipset = init_chipset_svwks,
31743 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31744 index ddeda44..46f7e30 100644
31745 --- a/drivers/ide/siimage.c
31746 +++ b/drivers/ide/siimage.c
31747 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31748 .udma_mask = ATA_UDMA6, \
31749 }
31750
31751 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31752 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31753 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31754 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31755 };
31756 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31757 index 4a00225..09e61b4 100644
31758 --- a/drivers/ide/sis5513.c
31759 +++ b/drivers/ide/sis5513.c
31760 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31761 .cable_detect = sis_cable_detect,
31762 };
31763
31764 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31765 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31766 .name = DRV_NAME,
31767 .init_chipset = init_chipset_sis5513,
31768 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31769 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31770 index f21dc2a..d051cd2 100644
31771 --- a/drivers/ide/sl82c105.c
31772 +++ b/drivers/ide/sl82c105.c
31773 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31774 .dma_sff_read_status = ide_dma_sff_read_status,
31775 };
31776
31777 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31778 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31779 .name = DRV_NAME,
31780 .init_chipset = init_chipset_sl82c105,
31781 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31782 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31783 index 864ffe0..863a5e9 100644
31784 --- a/drivers/ide/slc90e66.c
31785 +++ b/drivers/ide/slc90e66.c
31786 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31787 .cable_detect = slc90e66_cable_detect,
31788 };
31789
31790 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31791 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31792 .name = DRV_NAME,
31793 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31794 .port_ops = &slc90e66_port_ops,
31795 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31796 index 4799d5c..1794678 100644
31797 --- a/drivers/ide/tc86c001.c
31798 +++ b/drivers/ide/tc86c001.c
31799 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31800 .dma_sff_read_status = ide_dma_sff_read_status,
31801 };
31802
31803 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31804 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31805 .name = DRV_NAME,
31806 .init_hwif = init_hwif_tc86c001,
31807 .port_ops = &tc86c001_port_ops,
31808 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31809 index 281c914..55ce1b8 100644
31810 --- a/drivers/ide/triflex.c
31811 +++ b/drivers/ide/triflex.c
31812 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31813 .set_dma_mode = triflex_set_mode,
31814 };
31815
31816 -static const struct ide_port_info triflex_device __devinitdata = {
31817 +static const struct ide_port_info triflex_device __devinitconst = {
31818 .name = DRV_NAME,
31819 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31820 .port_ops = &triflex_port_ops,
31821 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31822 index 4b42ca0..e494a98 100644
31823 --- a/drivers/ide/trm290.c
31824 +++ b/drivers/ide/trm290.c
31825 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31826 .dma_check = trm290_dma_check,
31827 };
31828
31829 -static const struct ide_port_info trm290_chipset __devinitdata = {
31830 +static const struct ide_port_info trm290_chipset __devinitconst = {
31831 .name = DRV_NAME,
31832 .init_hwif = init_hwif_trm290,
31833 .tp_ops = &trm290_tp_ops,
31834 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31835 index f46f49c..eb77678 100644
31836 --- a/drivers/ide/via82cxxx.c
31837 +++ b/drivers/ide/via82cxxx.c
31838 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31839 .cable_detect = via82cxxx_cable_detect,
31840 };
31841
31842 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31843 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31844 .name = DRV_NAME,
31845 .init_chipset = init_chipset_via82cxxx,
31846 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31847 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31848 index 73d4531..c90cd2d 100644
31849 --- a/drivers/ieee802154/fakehard.c
31850 +++ b/drivers/ieee802154/fakehard.c
31851 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31852 phy->transmit_power = 0xbf;
31853
31854 dev->netdev_ops = &fake_ops;
31855 - dev->ml_priv = &fake_mlme;
31856 + dev->ml_priv = (void *)&fake_mlme;
31857
31858 priv = netdev_priv(dev);
31859 priv->phy = phy;
31860 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31861 index c889aae..6cf5aa7 100644
31862 --- a/drivers/infiniband/core/cm.c
31863 +++ b/drivers/infiniband/core/cm.c
31864 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31865
31866 struct cm_counter_group {
31867 struct kobject obj;
31868 - atomic_long_t counter[CM_ATTR_COUNT];
31869 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31870 };
31871
31872 struct cm_counter_attribute {
31873 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31874 struct ib_mad_send_buf *msg = NULL;
31875 int ret;
31876
31877 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31878 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31879 counter[CM_REQ_COUNTER]);
31880
31881 /* Quick state check to discard duplicate REQs. */
31882 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31883 if (!cm_id_priv)
31884 return;
31885
31886 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31887 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31888 counter[CM_REP_COUNTER]);
31889 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31890 if (ret)
31891 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31892 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31893 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31894 spin_unlock_irq(&cm_id_priv->lock);
31895 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31896 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31897 counter[CM_RTU_COUNTER]);
31898 goto out;
31899 }
31900 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31901 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31902 dreq_msg->local_comm_id);
31903 if (!cm_id_priv) {
31904 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31905 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31906 counter[CM_DREQ_COUNTER]);
31907 cm_issue_drep(work->port, work->mad_recv_wc);
31908 return -EINVAL;
31909 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31910 case IB_CM_MRA_REP_RCVD:
31911 break;
31912 case IB_CM_TIMEWAIT:
31913 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31914 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31915 counter[CM_DREQ_COUNTER]);
31916 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31917 goto unlock;
31918 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31919 cm_free_msg(msg);
31920 goto deref;
31921 case IB_CM_DREQ_RCVD:
31922 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31923 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31924 counter[CM_DREQ_COUNTER]);
31925 goto unlock;
31926 default:
31927 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31928 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31929 cm_id_priv->msg, timeout)) {
31930 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31931 - atomic_long_inc(&work->port->
31932 + atomic_long_inc_unchecked(&work->port->
31933 counter_group[CM_RECV_DUPLICATES].
31934 counter[CM_MRA_COUNTER]);
31935 goto out;
31936 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31937 break;
31938 case IB_CM_MRA_REQ_RCVD:
31939 case IB_CM_MRA_REP_RCVD:
31940 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31941 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31942 counter[CM_MRA_COUNTER]);
31943 /* fall through */
31944 default:
31945 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31946 case IB_CM_LAP_IDLE:
31947 break;
31948 case IB_CM_MRA_LAP_SENT:
31949 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31950 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31951 counter[CM_LAP_COUNTER]);
31952 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31953 goto unlock;
31954 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31955 cm_free_msg(msg);
31956 goto deref;
31957 case IB_CM_LAP_RCVD:
31958 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31959 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31960 counter[CM_LAP_COUNTER]);
31961 goto unlock;
31962 default:
31963 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31964 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31965 if (cur_cm_id_priv) {
31966 spin_unlock_irq(&cm.lock);
31967 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31968 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31969 counter[CM_SIDR_REQ_COUNTER]);
31970 goto out; /* Duplicate message. */
31971 }
31972 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31973 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31974 msg->retries = 1;
31975
31976 - atomic_long_add(1 + msg->retries,
31977 + atomic_long_add_unchecked(1 + msg->retries,
31978 &port->counter_group[CM_XMIT].counter[attr_index]);
31979 if (msg->retries)
31980 - atomic_long_add(msg->retries,
31981 + atomic_long_add_unchecked(msg->retries,
31982 &port->counter_group[CM_XMIT_RETRIES].
31983 counter[attr_index]);
31984
31985 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31986 }
31987
31988 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31989 - atomic_long_inc(&port->counter_group[CM_RECV].
31990 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31991 counter[attr_id - CM_ATTR_ID_OFFSET]);
31992
31993 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31994 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31995 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31996
31997 return sprintf(buf, "%ld\n",
31998 - atomic_long_read(&group->counter[cm_attr->index]));
31999 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32000 }
32001
32002 static const struct sysfs_ops cm_counter_ops = {
32003 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32004 index 176c8f9..2627b62 100644
32005 --- a/drivers/infiniband/core/fmr_pool.c
32006 +++ b/drivers/infiniband/core/fmr_pool.c
32007 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32008
32009 struct task_struct *thread;
32010
32011 - atomic_t req_ser;
32012 - atomic_t flush_ser;
32013 + atomic_unchecked_t req_ser;
32014 + atomic_unchecked_t flush_ser;
32015
32016 wait_queue_head_t force_wait;
32017 };
32018 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32019 struct ib_fmr_pool *pool = pool_ptr;
32020
32021 do {
32022 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32023 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32024 ib_fmr_batch_release(pool);
32025
32026 - atomic_inc(&pool->flush_ser);
32027 + atomic_inc_unchecked(&pool->flush_ser);
32028 wake_up_interruptible(&pool->force_wait);
32029
32030 if (pool->flush_function)
32031 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32032 }
32033
32034 set_current_state(TASK_INTERRUPTIBLE);
32035 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32036 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32037 !kthread_should_stop())
32038 schedule();
32039 __set_current_state(TASK_RUNNING);
32040 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32041 pool->dirty_watermark = params->dirty_watermark;
32042 pool->dirty_len = 0;
32043 spin_lock_init(&pool->pool_lock);
32044 - atomic_set(&pool->req_ser, 0);
32045 - atomic_set(&pool->flush_ser, 0);
32046 + atomic_set_unchecked(&pool->req_ser, 0);
32047 + atomic_set_unchecked(&pool->flush_ser, 0);
32048 init_waitqueue_head(&pool->force_wait);
32049
32050 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32051 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32052 }
32053 spin_unlock_irq(&pool->pool_lock);
32054
32055 - serial = atomic_inc_return(&pool->req_ser);
32056 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32057 wake_up_process(pool->thread);
32058
32059 if (wait_event_interruptible(pool->force_wait,
32060 - atomic_read(&pool->flush_ser) - serial >= 0))
32061 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32062 return -EINTR;
32063
32064 return 0;
32065 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32066 } else {
32067 list_add_tail(&fmr->list, &pool->dirty_list);
32068 if (++pool->dirty_len >= pool->dirty_watermark) {
32069 - atomic_inc(&pool->req_ser);
32070 + atomic_inc_unchecked(&pool->req_ser);
32071 wake_up_process(pool->thread);
32072 }
32073 }
32074 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32075 index 40c8353..946b0e4 100644
32076 --- a/drivers/infiniband/hw/cxgb4/mem.c
32077 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32078 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32079 int err;
32080 struct fw_ri_tpte tpt;
32081 u32 stag_idx;
32082 - static atomic_t key;
32083 + static atomic_unchecked_t key;
32084
32085 if (c4iw_fatal_error(rdev))
32086 return -EIO;
32087 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32088 &rdev->resource.tpt_fifo_lock);
32089 if (!stag_idx)
32090 return -ENOMEM;
32091 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32092 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32093 }
32094 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32095 __func__, stag_state, type, pdid, stag_idx);
32096 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32097 index a4de9d5..5fa20c3 100644
32098 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32099 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32100 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32101 };
32102
32103 static ssize_t flash_read(struct file *file, char __user *buf,
32104 + size_t count, loff_t *ppos) __size_overflow(3);
32105 +static ssize_t flash_read(struct file *file, char __user *buf,
32106 size_t count, loff_t *ppos)
32107 {
32108 struct ipath_devdata *dd;
32109 @@ -177,6 +179,8 @@ bail:
32110 }
32111
32112 static ssize_t flash_write(struct file *file, const char __user *buf,
32113 + size_t count, loff_t *ppos) __size_overflow(3);
32114 +static ssize_t flash_write(struct file *file, const char __user *buf,
32115 size_t count, loff_t *ppos)
32116 {
32117 struct ipath_devdata *dd;
32118 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32119 index 79b3dbc..96e5fcc 100644
32120 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32121 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32122 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32123 struct ib_atomic_eth *ateth;
32124 struct ipath_ack_entry *e;
32125 u64 vaddr;
32126 - atomic64_t *maddr;
32127 + atomic64_unchecked_t *maddr;
32128 u64 sdata;
32129 u32 rkey;
32130 u8 next;
32131 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32132 IB_ACCESS_REMOTE_ATOMIC)))
32133 goto nack_acc_unlck;
32134 /* Perform atomic OP and save result. */
32135 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32136 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32137 sdata = be64_to_cpu(ateth->swap_data);
32138 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32139 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32140 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32141 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32142 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32143 be64_to_cpu(ateth->compare_data),
32144 sdata);
32145 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32146 index 1f95bba..9530f87 100644
32147 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32148 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32149 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32150 unsigned long flags;
32151 struct ib_wc wc;
32152 u64 sdata;
32153 - atomic64_t *maddr;
32154 + atomic64_unchecked_t *maddr;
32155 enum ib_wc_status send_status;
32156
32157 /*
32158 @@ -382,11 +382,11 @@ again:
32159 IB_ACCESS_REMOTE_ATOMIC)))
32160 goto acc_err;
32161 /* Perform atomic OP and save result. */
32162 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32163 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32164 sdata = wqe->wr.wr.atomic.compare_add;
32165 *(u64 *) sqp->s_sge.sge.vaddr =
32166 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32167 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32168 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32169 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32170 sdata, wqe->wr.wr.atomic.swap);
32171 goto send_comp;
32172 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32173 index 7140199..da60063 100644
32174 --- a/drivers/infiniband/hw/nes/nes.c
32175 +++ b/drivers/infiniband/hw/nes/nes.c
32176 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32177 LIST_HEAD(nes_adapter_list);
32178 static LIST_HEAD(nes_dev_list);
32179
32180 -atomic_t qps_destroyed;
32181 +atomic_unchecked_t qps_destroyed;
32182
32183 static unsigned int ee_flsh_adapter;
32184 static unsigned int sysfs_nonidx_addr;
32185 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32186 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32187 struct nes_adapter *nesadapter = nesdev->nesadapter;
32188
32189 - atomic_inc(&qps_destroyed);
32190 + atomic_inc_unchecked(&qps_destroyed);
32191
32192 /* Free the control structures */
32193
32194 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32195 index c438e46..ca30356 100644
32196 --- a/drivers/infiniband/hw/nes/nes.h
32197 +++ b/drivers/infiniband/hw/nes/nes.h
32198 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32199 extern unsigned int wqm_quanta;
32200 extern struct list_head nes_adapter_list;
32201
32202 -extern atomic_t cm_connects;
32203 -extern atomic_t cm_accepts;
32204 -extern atomic_t cm_disconnects;
32205 -extern atomic_t cm_closes;
32206 -extern atomic_t cm_connecteds;
32207 -extern atomic_t cm_connect_reqs;
32208 -extern atomic_t cm_rejects;
32209 -extern atomic_t mod_qp_timouts;
32210 -extern atomic_t qps_created;
32211 -extern atomic_t qps_destroyed;
32212 -extern atomic_t sw_qps_destroyed;
32213 +extern atomic_unchecked_t cm_connects;
32214 +extern atomic_unchecked_t cm_accepts;
32215 +extern atomic_unchecked_t cm_disconnects;
32216 +extern atomic_unchecked_t cm_closes;
32217 +extern atomic_unchecked_t cm_connecteds;
32218 +extern atomic_unchecked_t cm_connect_reqs;
32219 +extern atomic_unchecked_t cm_rejects;
32220 +extern atomic_unchecked_t mod_qp_timouts;
32221 +extern atomic_unchecked_t qps_created;
32222 +extern atomic_unchecked_t qps_destroyed;
32223 +extern atomic_unchecked_t sw_qps_destroyed;
32224 extern u32 mh_detected;
32225 extern u32 mh_pauses_sent;
32226 extern u32 cm_packets_sent;
32227 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32228 extern u32 cm_packets_received;
32229 extern u32 cm_packets_dropped;
32230 extern u32 cm_packets_retrans;
32231 -extern atomic_t cm_listens_created;
32232 -extern atomic_t cm_listens_destroyed;
32233 +extern atomic_unchecked_t cm_listens_created;
32234 +extern atomic_unchecked_t cm_listens_destroyed;
32235 extern u32 cm_backlog_drops;
32236 -extern atomic_t cm_loopbacks;
32237 -extern atomic_t cm_nodes_created;
32238 -extern atomic_t cm_nodes_destroyed;
32239 -extern atomic_t cm_accel_dropped_pkts;
32240 -extern atomic_t cm_resets_recvd;
32241 -extern atomic_t pau_qps_created;
32242 -extern atomic_t pau_qps_destroyed;
32243 +extern atomic_unchecked_t cm_loopbacks;
32244 +extern atomic_unchecked_t cm_nodes_created;
32245 +extern atomic_unchecked_t cm_nodes_destroyed;
32246 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32247 +extern atomic_unchecked_t cm_resets_recvd;
32248 +extern atomic_unchecked_t pau_qps_created;
32249 +extern atomic_unchecked_t pau_qps_destroyed;
32250
32251 extern u32 int_mod_timer_init;
32252 extern u32 int_mod_cq_depth_256;
32253 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32254 index a4972ab..1bcfc31 100644
32255 --- a/drivers/infiniband/hw/nes/nes_cm.c
32256 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32257 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32258 u32 cm_packets_retrans;
32259 u32 cm_packets_created;
32260 u32 cm_packets_received;
32261 -atomic_t cm_listens_created;
32262 -atomic_t cm_listens_destroyed;
32263 +atomic_unchecked_t cm_listens_created;
32264 +atomic_unchecked_t cm_listens_destroyed;
32265 u32 cm_backlog_drops;
32266 -atomic_t cm_loopbacks;
32267 -atomic_t cm_nodes_created;
32268 -atomic_t cm_nodes_destroyed;
32269 -atomic_t cm_accel_dropped_pkts;
32270 -atomic_t cm_resets_recvd;
32271 +atomic_unchecked_t cm_loopbacks;
32272 +atomic_unchecked_t cm_nodes_created;
32273 +atomic_unchecked_t cm_nodes_destroyed;
32274 +atomic_unchecked_t cm_accel_dropped_pkts;
32275 +atomic_unchecked_t cm_resets_recvd;
32276
32277 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32278 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32279 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32280
32281 static struct nes_cm_core *g_cm_core;
32282
32283 -atomic_t cm_connects;
32284 -atomic_t cm_accepts;
32285 -atomic_t cm_disconnects;
32286 -atomic_t cm_closes;
32287 -atomic_t cm_connecteds;
32288 -atomic_t cm_connect_reqs;
32289 -atomic_t cm_rejects;
32290 +atomic_unchecked_t cm_connects;
32291 +atomic_unchecked_t cm_accepts;
32292 +atomic_unchecked_t cm_disconnects;
32293 +atomic_unchecked_t cm_closes;
32294 +atomic_unchecked_t cm_connecteds;
32295 +atomic_unchecked_t cm_connect_reqs;
32296 +atomic_unchecked_t cm_rejects;
32297
32298 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32299 {
32300 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32301 kfree(listener);
32302 listener = NULL;
32303 ret = 0;
32304 - atomic_inc(&cm_listens_destroyed);
32305 + atomic_inc_unchecked(&cm_listens_destroyed);
32306 } else {
32307 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32308 }
32309 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32310 cm_node->rem_mac);
32311
32312 add_hte_node(cm_core, cm_node);
32313 - atomic_inc(&cm_nodes_created);
32314 + atomic_inc_unchecked(&cm_nodes_created);
32315
32316 return cm_node;
32317 }
32318 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32319 }
32320
32321 atomic_dec(&cm_core->node_cnt);
32322 - atomic_inc(&cm_nodes_destroyed);
32323 + atomic_inc_unchecked(&cm_nodes_destroyed);
32324 nesqp = cm_node->nesqp;
32325 if (nesqp) {
32326 nesqp->cm_node = NULL;
32327 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32328
32329 static void drop_packet(struct sk_buff *skb)
32330 {
32331 - atomic_inc(&cm_accel_dropped_pkts);
32332 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32333 dev_kfree_skb_any(skb);
32334 }
32335
32336 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32337 {
32338
32339 int reset = 0; /* whether to send reset in case of err.. */
32340 - atomic_inc(&cm_resets_recvd);
32341 + atomic_inc_unchecked(&cm_resets_recvd);
32342 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32343 " refcnt=%d\n", cm_node, cm_node->state,
32344 atomic_read(&cm_node->ref_count));
32345 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32346 rem_ref_cm_node(cm_node->cm_core, cm_node);
32347 return NULL;
32348 }
32349 - atomic_inc(&cm_loopbacks);
32350 + atomic_inc_unchecked(&cm_loopbacks);
32351 loopbackremotenode->loopbackpartner = cm_node;
32352 loopbackremotenode->tcp_cntxt.rcv_wscale =
32353 NES_CM_DEFAULT_RCV_WND_SCALE;
32354 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32355 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32356 else {
32357 rem_ref_cm_node(cm_core, cm_node);
32358 - atomic_inc(&cm_accel_dropped_pkts);
32359 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32360 dev_kfree_skb_any(skb);
32361 }
32362 break;
32363 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32364
32365 if ((cm_id) && (cm_id->event_handler)) {
32366 if (issue_disconn) {
32367 - atomic_inc(&cm_disconnects);
32368 + atomic_inc_unchecked(&cm_disconnects);
32369 cm_event.event = IW_CM_EVENT_DISCONNECT;
32370 cm_event.status = disconn_status;
32371 cm_event.local_addr = cm_id->local_addr;
32372 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32373 }
32374
32375 if (issue_close) {
32376 - atomic_inc(&cm_closes);
32377 + atomic_inc_unchecked(&cm_closes);
32378 nes_disconnect(nesqp, 1);
32379
32380 cm_id->provider_data = nesqp;
32381 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32382
32383 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32384 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32385 - atomic_inc(&cm_accepts);
32386 + atomic_inc_unchecked(&cm_accepts);
32387
32388 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32389 netdev_refcnt_read(nesvnic->netdev));
32390 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32391 struct nes_cm_core *cm_core;
32392 u8 *start_buff;
32393
32394 - atomic_inc(&cm_rejects);
32395 + atomic_inc_unchecked(&cm_rejects);
32396 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32397 loopback = cm_node->loopbackpartner;
32398 cm_core = cm_node->cm_core;
32399 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32400 ntohl(cm_id->local_addr.sin_addr.s_addr),
32401 ntohs(cm_id->local_addr.sin_port));
32402
32403 - atomic_inc(&cm_connects);
32404 + atomic_inc_unchecked(&cm_connects);
32405 nesqp->active_conn = 1;
32406
32407 /* cache the cm_id in the qp */
32408 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32409 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32410 return err;
32411 }
32412 - atomic_inc(&cm_listens_created);
32413 + atomic_inc_unchecked(&cm_listens_created);
32414 }
32415
32416 cm_id->add_ref(cm_id);
32417 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32418
32419 if (nesqp->destroyed)
32420 return;
32421 - atomic_inc(&cm_connecteds);
32422 + atomic_inc_unchecked(&cm_connecteds);
32423 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32424 " local port 0x%04X. jiffies = %lu.\n",
32425 nesqp->hwqp.qp_id,
32426 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32427
32428 cm_id->add_ref(cm_id);
32429 ret = cm_id->event_handler(cm_id, &cm_event);
32430 - atomic_inc(&cm_closes);
32431 + atomic_inc_unchecked(&cm_closes);
32432 cm_event.event = IW_CM_EVENT_CLOSE;
32433 cm_event.status = 0;
32434 cm_event.provider_data = cm_id->provider_data;
32435 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32436 return;
32437 cm_id = cm_node->cm_id;
32438
32439 - atomic_inc(&cm_connect_reqs);
32440 + atomic_inc_unchecked(&cm_connect_reqs);
32441 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32442 cm_node, cm_id, jiffies);
32443
32444 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32445 return;
32446 cm_id = cm_node->cm_id;
32447
32448 - atomic_inc(&cm_connect_reqs);
32449 + atomic_inc_unchecked(&cm_connect_reqs);
32450 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32451 cm_node, cm_id, jiffies);
32452
32453 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32454 index 3ba7be3..c81f6ff 100644
32455 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32456 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32457 @@ -40,8 +40,8 @@
32458 #include "nes.h"
32459 #include "nes_mgt.h"
32460
32461 -atomic_t pau_qps_created;
32462 -atomic_t pau_qps_destroyed;
32463 +atomic_unchecked_t pau_qps_created;
32464 +atomic_unchecked_t pau_qps_destroyed;
32465
32466 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32467 {
32468 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32469 {
32470 struct sk_buff *skb;
32471 unsigned long flags;
32472 - atomic_inc(&pau_qps_destroyed);
32473 + atomic_inc_unchecked(&pau_qps_destroyed);
32474
32475 /* Free packets that have not yet been forwarded */
32476 /* Lock is acquired by skb_dequeue when removing the skb */
32477 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32478 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32479 skb_queue_head_init(&nesqp->pau_list);
32480 spin_lock_init(&nesqp->pau_lock);
32481 - atomic_inc(&pau_qps_created);
32482 + atomic_inc_unchecked(&pau_qps_created);
32483 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32484 }
32485
32486 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32487 index f3a3ecf..57d311d 100644
32488 --- a/drivers/infiniband/hw/nes/nes_nic.c
32489 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32490 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32491 target_stat_values[++index] = mh_detected;
32492 target_stat_values[++index] = mh_pauses_sent;
32493 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32494 - target_stat_values[++index] = atomic_read(&cm_connects);
32495 - target_stat_values[++index] = atomic_read(&cm_accepts);
32496 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32497 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32498 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32499 - target_stat_values[++index] = atomic_read(&cm_rejects);
32500 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32501 - target_stat_values[++index] = atomic_read(&qps_created);
32502 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32503 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32504 - target_stat_values[++index] = atomic_read(&cm_closes);
32505 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32506 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32507 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32508 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32509 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32510 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32511 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32512 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32513 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32514 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32515 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32516 target_stat_values[++index] = cm_packets_sent;
32517 target_stat_values[++index] = cm_packets_bounced;
32518 target_stat_values[++index] = cm_packets_created;
32519 target_stat_values[++index] = cm_packets_received;
32520 target_stat_values[++index] = cm_packets_dropped;
32521 target_stat_values[++index] = cm_packets_retrans;
32522 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32523 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32524 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32525 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32526 target_stat_values[++index] = cm_backlog_drops;
32527 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32528 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32529 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32530 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32531 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32532 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32533 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32534 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32535 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32536 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32537 target_stat_values[++index] = nesadapter->free_4kpbl;
32538 target_stat_values[++index] = nesadapter->free_256pbl;
32539 target_stat_values[++index] = int_mod_timer_init;
32540 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32541 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32542 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32543 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32544 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32545 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32546 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32547 }
32548
32549 /**
32550 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32551 index 0927b5c..ed67986 100644
32552 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32553 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32554 @@ -46,9 +46,9 @@
32555
32556 #include <rdma/ib_umem.h>
32557
32558 -atomic_t mod_qp_timouts;
32559 -atomic_t qps_created;
32560 -atomic_t sw_qps_destroyed;
32561 +atomic_unchecked_t mod_qp_timouts;
32562 +atomic_unchecked_t qps_created;
32563 +atomic_unchecked_t sw_qps_destroyed;
32564
32565 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32566
32567 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32568 if (init_attr->create_flags)
32569 return ERR_PTR(-EINVAL);
32570
32571 - atomic_inc(&qps_created);
32572 + atomic_inc_unchecked(&qps_created);
32573 switch (init_attr->qp_type) {
32574 case IB_QPT_RC:
32575 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32576 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32577 struct iw_cm_event cm_event;
32578 int ret = 0;
32579
32580 - atomic_inc(&sw_qps_destroyed);
32581 + atomic_inc_unchecked(&sw_qps_destroyed);
32582 nesqp->destroyed = 1;
32583
32584 /* Blow away the connection if it exists. */
32585 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32586 index b881bdc..c2e360c 100644
32587 --- a/drivers/infiniband/hw/qib/qib.h
32588 +++ b/drivers/infiniband/hw/qib/qib.h
32589 @@ -51,6 +51,7 @@
32590 #include <linux/completion.h>
32591 #include <linux/kref.h>
32592 #include <linux/sched.h>
32593 +#include <linux/slab.h>
32594
32595 #include "qib_common.h"
32596 #include "qib_verbs.h"
32597 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32598 index 05e0f17..0275789 100644
32599 --- a/drivers/infiniband/hw/qib/qib_fs.c
32600 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32601 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32602 };
32603
32604 static ssize_t flash_read(struct file *file, char __user *buf,
32605 + size_t count, loff_t *ppos) __size_overflow(3);
32606 +static ssize_t flash_read(struct file *file, char __user *buf,
32607 size_t count, loff_t *ppos)
32608 {
32609 struct qib_devdata *dd;
32610 @@ -318,6 +320,8 @@ bail:
32611 }
32612
32613 static ssize_t flash_write(struct file *file, const char __user *buf,
32614 + size_t count, loff_t *ppos) __size_overflow(3);
32615 +static ssize_t flash_write(struct file *file, const char __user *buf,
32616 size_t count, loff_t *ppos)
32617 {
32618 struct qib_devdata *dd;
32619 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32620 index c351aa4..e6967c2 100644
32621 --- a/drivers/input/gameport/gameport.c
32622 +++ b/drivers/input/gameport/gameport.c
32623 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32624 */
32625 static void gameport_init_port(struct gameport *gameport)
32626 {
32627 - static atomic_t gameport_no = ATOMIC_INIT(0);
32628 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32629
32630 __module_get(THIS_MODULE);
32631
32632 mutex_init(&gameport->drv_mutex);
32633 device_initialize(&gameport->dev);
32634 dev_set_name(&gameport->dev, "gameport%lu",
32635 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32636 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32637 gameport->dev.bus = &gameport_bus;
32638 gameport->dev.release = gameport_release_port;
32639 if (gameport->parent)
32640 diff --git a/drivers/input/input.c b/drivers/input/input.c
32641 index 1f78c95..3cddc6c 100644
32642 --- a/drivers/input/input.c
32643 +++ b/drivers/input/input.c
32644 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32645 */
32646 int input_register_device(struct input_dev *dev)
32647 {
32648 - static atomic_t input_no = ATOMIC_INIT(0);
32649 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32650 struct input_handler *handler;
32651 const char *path;
32652 int error;
32653 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32654 dev->setkeycode = input_default_setkeycode;
32655
32656 dev_set_name(&dev->dev, "input%ld",
32657 - (unsigned long) atomic_inc_return(&input_no) - 1);
32658 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32659
32660 error = device_add(&dev->dev);
32661 if (error)
32662 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32663 index b8d8611..7a4a04b 100644
32664 --- a/drivers/input/joystick/sidewinder.c
32665 +++ b/drivers/input/joystick/sidewinder.c
32666 @@ -30,6 +30,7 @@
32667 #include <linux/kernel.h>
32668 #include <linux/module.h>
32669 #include <linux/slab.h>
32670 +#include <linux/sched.h>
32671 #include <linux/init.h>
32672 #include <linux/input.h>
32673 #include <linux/gameport.h>
32674 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32675 index fd7a0d5..a4af10c 100644
32676 --- a/drivers/input/joystick/xpad.c
32677 +++ b/drivers/input/joystick/xpad.c
32678 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32679
32680 static int xpad_led_probe(struct usb_xpad *xpad)
32681 {
32682 - static atomic_t led_seq = ATOMIC_INIT(0);
32683 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32684 long led_no;
32685 struct xpad_led *led;
32686 struct led_classdev *led_cdev;
32687 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32688 if (!led)
32689 return -ENOMEM;
32690
32691 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32692 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32693
32694 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32695 led->xpad = xpad;
32696 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32697 index 0110b5a..d3ad144 100644
32698 --- a/drivers/input/mousedev.c
32699 +++ b/drivers/input/mousedev.c
32700 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32701
32702 spin_unlock_irq(&client->packet_lock);
32703
32704 - if (copy_to_user(buffer, data, count))
32705 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32706 return -EFAULT;
32707
32708 return count;
32709 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32710 index ba70058..571d25d 100644
32711 --- a/drivers/input/serio/serio.c
32712 +++ b/drivers/input/serio/serio.c
32713 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32714 */
32715 static void serio_init_port(struct serio *serio)
32716 {
32717 - static atomic_t serio_no = ATOMIC_INIT(0);
32718 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32719
32720 __module_get(THIS_MODULE);
32721
32722 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32723 mutex_init(&serio->drv_mutex);
32724 device_initialize(&serio->dev);
32725 dev_set_name(&serio->dev, "serio%ld",
32726 - (long)atomic_inc_return(&serio_no) - 1);
32727 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32728 serio->dev.bus = &serio_bus;
32729 serio->dev.release = serio_release_port;
32730 serio->dev.groups = serio_device_attr_groups;
32731 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32732 index e44933d..9ba484a 100644
32733 --- a/drivers/isdn/capi/capi.c
32734 +++ b/drivers/isdn/capi/capi.c
32735 @@ -83,8 +83,8 @@ struct capiminor {
32736
32737 struct capi20_appl *ap;
32738 u32 ncci;
32739 - atomic_t datahandle;
32740 - atomic_t msgid;
32741 + atomic_unchecked_t datahandle;
32742 + atomic_unchecked_t msgid;
32743
32744 struct tty_port port;
32745 int ttyinstop;
32746 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32747 capimsg_setu16(s, 2, mp->ap->applid);
32748 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32749 capimsg_setu8 (s, 5, CAPI_RESP);
32750 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32751 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32752 capimsg_setu32(s, 8, mp->ncci);
32753 capimsg_setu16(s, 12, datahandle);
32754 }
32755 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32756 mp->outbytes -= len;
32757 spin_unlock_bh(&mp->outlock);
32758
32759 - datahandle = atomic_inc_return(&mp->datahandle);
32760 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32761 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32762 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32763 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32764 capimsg_setu16(skb->data, 2, mp->ap->applid);
32765 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32766 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32767 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32768 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32769 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32770 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32771 capimsg_setu16(skb->data, 16, len); /* Data length */
32772 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32773 index db621db..825ea1a 100644
32774 --- a/drivers/isdn/gigaset/common.c
32775 +++ b/drivers/isdn/gigaset/common.c
32776 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32777 cs->commands_pending = 0;
32778 cs->cur_at_seq = 0;
32779 cs->gotfwver = -1;
32780 - cs->open_count = 0;
32781 + local_set(&cs->open_count, 0);
32782 cs->dev = NULL;
32783 cs->tty = NULL;
32784 cs->tty_dev = NULL;
32785 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32786 index 212efaf..f187c6b 100644
32787 --- a/drivers/isdn/gigaset/gigaset.h
32788 +++ b/drivers/isdn/gigaset/gigaset.h
32789 @@ -35,6 +35,7 @@
32790 #include <linux/tty_driver.h>
32791 #include <linux/list.h>
32792 #include <linux/atomic.h>
32793 +#include <asm/local.h>
32794
32795 #define GIG_VERSION {0, 5, 0, 0}
32796 #define GIG_COMPAT {0, 4, 0, 0}
32797 @@ -433,7 +434,7 @@ struct cardstate {
32798 spinlock_t cmdlock;
32799 unsigned curlen, cmdbytes;
32800
32801 - unsigned open_count;
32802 + local_t open_count;
32803 struct tty_struct *tty;
32804 struct tasklet_struct if_wake_tasklet;
32805 unsigned control_state;
32806 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32807 index ee0a549..a7c9798 100644
32808 --- a/drivers/isdn/gigaset/interface.c
32809 +++ b/drivers/isdn/gigaset/interface.c
32810 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32811 }
32812 tty->driver_data = cs;
32813
32814 - ++cs->open_count;
32815 -
32816 - if (cs->open_count == 1) {
32817 + if (local_inc_return(&cs->open_count) == 1) {
32818 spin_lock_irqsave(&cs->lock, flags);
32819 cs->tty = tty;
32820 spin_unlock_irqrestore(&cs->lock, flags);
32821 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32822
32823 if (!cs->connected)
32824 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32825 - else if (!cs->open_count)
32826 + else if (!local_read(&cs->open_count))
32827 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32828 else {
32829 - if (!--cs->open_count) {
32830 + if (!local_dec_return(&cs->open_count)) {
32831 spin_lock_irqsave(&cs->lock, flags);
32832 cs->tty = NULL;
32833 spin_unlock_irqrestore(&cs->lock, flags);
32834 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32835 if (!cs->connected) {
32836 gig_dbg(DEBUG_IF, "not connected");
32837 retval = -ENODEV;
32838 - } else if (!cs->open_count)
32839 + } else if (!local_read(&cs->open_count))
32840 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32841 else {
32842 retval = 0;
32843 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32844 retval = -ENODEV;
32845 goto done;
32846 }
32847 - if (!cs->open_count) {
32848 + if (!local_read(&cs->open_count)) {
32849 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32850 retval = -ENODEV;
32851 goto done;
32852 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32853 if (!cs->connected) {
32854 gig_dbg(DEBUG_IF, "not connected");
32855 retval = -ENODEV;
32856 - } else if (!cs->open_count)
32857 + } else if (!local_read(&cs->open_count))
32858 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32859 else if (cs->mstate != MS_LOCKED) {
32860 dev_warn(cs->dev, "can't write to unlocked device\n");
32861 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32862
32863 if (!cs->connected)
32864 gig_dbg(DEBUG_IF, "not connected");
32865 - else if (!cs->open_count)
32866 + else if (!local_read(&cs->open_count))
32867 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32868 else if (cs->mstate != MS_LOCKED)
32869 dev_warn(cs->dev, "can't write to unlocked device\n");
32870 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32871
32872 if (!cs->connected)
32873 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32874 - else if (!cs->open_count)
32875 + else if (!local_read(&cs->open_count))
32876 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32877 else
32878 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32879 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32880
32881 if (!cs->connected)
32882 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32883 - else if (!cs->open_count)
32884 + else if (!local_read(&cs->open_count))
32885 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32886 else
32887 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32888 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32889 goto out;
32890 }
32891
32892 - if (!cs->open_count) {
32893 + if (!local_read(&cs->open_count)) {
32894 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32895 goto out;
32896 }
32897 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32898 index 2a57da59..e7a12ed 100644
32899 --- a/drivers/isdn/hardware/avm/b1.c
32900 +++ b/drivers/isdn/hardware/avm/b1.c
32901 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32902 }
32903 if (left) {
32904 if (t4file->user) {
32905 - if (copy_from_user(buf, dp, left))
32906 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32907 return -EFAULT;
32908 } else {
32909 memcpy(buf, dp, left);
32910 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32911 }
32912 if (left) {
32913 if (config->user) {
32914 - if (copy_from_user(buf, dp, left))
32915 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32916 return -EFAULT;
32917 } else {
32918 memcpy(buf, dp, left);
32919 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32920 index 85784a7..a19ca98 100644
32921 --- a/drivers/isdn/hardware/eicon/divasync.h
32922 +++ b/drivers/isdn/hardware/eicon/divasync.h
32923 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32924 } diva_didd_add_adapter_t;
32925 typedef struct _diva_didd_remove_adapter {
32926 IDI_CALL p_request;
32927 -} diva_didd_remove_adapter_t;
32928 +} __no_const diva_didd_remove_adapter_t;
32929 typedef struct _diva_didd_read_adapter_array {
32930 void * buffer;
32931 dword length;
32932 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32933 index a3bd163..8956575 100644
32934 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32935 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32936 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32937 typedef struct _diva_os_idi_adapter_interface {
32938 diva_init_card_proc_t cleanup_adapter_proc;
32939 diva_cmd_card_proc_t cmd_proc;
32940 -} diva_os_idi_adapter_interface_t;
32941 +} __no_const diva_os_idi_adapter_interface_t;
32942
32943 typedef struct _diva_os_xdi_adapter {
32944 struct list_head link;
32945 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32946 index 1f355bb..43f1fea 100644
32947 --- a/drivers/isdn/icn/icn.c
32948 +++ b/drivers/isdn/icn/icn.c
32949 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32950 if (count > len)
32951 count = len;
32952 if (user) {
32953 - if (copy_from_user(msg, buf, count))
32954 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32955 return -EFAULT;
32956 } else
32957 memcpy(msg, buf, count);
32958 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32959 index b5fdcb7..5b6c59f 100644
32960 --- a/drivers/lguest/core.c
32961 +++ b/drivers/lguest/core.c
32962 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32963 * it's worked so far. The end address needs +1 because __get_vm_area
32964 * allocates an extra guard page, so we need space for that.
32965 */
32966 +
32967 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32968 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32969 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32970 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32971 +#else
32972 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32973 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32974 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32975 +#endif
32976 +
32977 if (!switcher_vma) {
32978 err = -ENOMEM;
32979 printk("lguest: could not map switcher pages high\n");
32980 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32981 * Now the Switcher is mapped at the right address, we can't fail!
32982 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32983 */
32984 - memcpy(switcher_vma->addr, start_switcher_text,
32985 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32986 end_switcher_text - start_switcher_text);
32987
32988 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32989 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
32990 index ff4a0bc..f5fdd9c 100644
32991 --- a/drivers/lguest/lguest_user.c
32992 +++ b/drivers/lguest/lguest_user.c
32993 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
32994 * Once our Guest is initialized, the Launcher makes it run by reading
32995 * from /dev/lguest.
32996 */
32997 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
32998 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
32999 {
33000 struct lguest *lg = file->private_data;
33001 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33002 index 3980903..ce25c5e 100644
33003 --- a/drivers/lguest/x86/core.c
33004 +++ b/drivers/lguest/x86/core.c
33005 @@ -59,7 +59,7 @@ static struct {
33006 /* Offset from where switcher.S was compiled to where we've copied it */
33007 static unsigned long switcher_offset(void)
33008 {
33009 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33010 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33011 }
33012
33013 /* This cpu's struct lguest_pages. */
33014 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33015 * These copies are pretty cheap, so we do them unconditionally: */
33016 /* Save the current Host top-level page directory.
33017 */
33018 +
33019 +#ifdef CONFIG_PAX_PER_CPU_PGD
33020 + pages->state.host_cr3 = read_cr3();
33021 +#else
33022 pages->state.host_cr3 = __pa(current->mm->pgd);
33023 +#endif
33024 +
33025 /*
33026 * Set up the Guest's page tables to see this CPU's pages (and no
33027 * other CPU's pages).
33028 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33029 * compiled-in switcher code and the high-mapped copy we just made.
33030 */
33031 for (i = 0; i < IDT_ENTRIES; i++)
33032 - default_idt_entries[i] += switcher_offset();
33033 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33034
33035 /*
33036 * Set up the Switcher's per-cpu areas.
33037 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33038 * it will be undisturbed when we switch. To change %cs and jump we
33039 * need this structure to feed to Intel's "lcall" instruction.
33040 */
33041 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33042 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33043 lguest_entry.segment = LGUEST_CS;
33044
33045 /*
33046 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33047 index 40634b0..4f5855e 100644
33048 --- a/drivers/lguest/x86/switcher_32.S
33049 +++ b/drivers/lguest/x86/switcher_32.S
33050 @@ -87,6 +87,7 @@
33051 #include <asm/page.h>
33052 #include <asm/segment.h>
33053 #include <asm/lguest.h>
33054 +#include <asm/processor-flags.h>
33055
33056 // We mark the start of the code to copy
33057 // It's placed in .text tho it's never run here
33058 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33059 // Changes type when we load it: damn Intel!
33060 // For after we switch over our page tables
33061 // That entry will be read-only: we'd crash.
33062 +
33063 +#ifdef CONFIG_PAX_KERNEXEC
33064 + mov %cr0, %edx
33065 + xor $X86_CR0_WP, %edx
33066 + mov %edx, %cr0
33067 +#endif
33068 +
33069 movl $(GDT_ENTRY_TSS*8), %edx
33070 ltr %dx
33071
33072 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33073 // Let's clear it again for our return.
33074 // The GDT descriptor of the Host
33075 // Points to the table after two "size" bytes
33076 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33077 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33078 // Clear "used" from type field (byte 5, bit 2)
33079 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33080 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33081 +
33082 +#ifdef CONFIG_PAX_KERNEXEC
33083 + mov %cr0, %eax
33084 + xor $X86_CR0_WP, %eax
33085 + mov %eax, %cr0
33086 +#endif
33087
33088 // Once our page table's switched, the Guest is live!
33089 // The Host fades as we run this final step.
33090 @@ -295,13 +309,12 @@ deliver_to_host:
33091 // I consulted gcc, and it gave
33092 // These instructions, which I gladly credit:
33093 leal (%edx,%ebx,8), %eax
33094 - movzwl (%eax),%edx
33095 - movl 4(%eax), %eax
33096 - xorw %ax, %ax
33097 - orl %eax, %edx
33098 + movl 4(%eax), %edx
33099 + movw (%eax), %dx
33100 // Now the address of the handler's in %edx
33101 // We call it now: its "iret" drops us home.
33102 - jmp *%edx
33103 + ljmp $__KERNEL_CS, $1f
33104 +1: jmp *%edx
33105
33106 // Every interrupt can come to us here
33107 // But we must truly tell each apart.
33108 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33109 index 4daf9e5..b8d1d0f 100644
33110 --- a/drivers/macintosh/macio_asic.c
33111 +++ b/drivers/macintosh/macio_asic.c
33112 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33113 * MacIO is matched against any Apple ID, it's probe() function
33114 * will then decide wether it applies or not
33115 */
33116 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33117 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33118 .vendor = PCI_VENDOR_ID_APPLE,
33119 .device = PCI_ANY_ID,
33120 .subvendor = PCI_ANY_ID,
33121 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33122 index 1ce84ed..0fdd40a 100644
33123 --- a/drivers/md/dm-ioctl.c
33124 +++ b/drivers/md/dm-ioctl.c
33125 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33126 cmd == DM_LIST_VERSIONS_CMD)
33127 return 0;
33128
33129 - if ((cmd == DM_DEV_CREATE_CMD)) {
33130 + if (cmd == DM_DEV_CREATE_CMD) {
33131 if (!*param->name) {
33132 DMWARN("name not supplied when creating device");
33133 return -EINVAL;
33134 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33135 index 9bfd057..5373ff3 100644
33136 --- a/drivers/md/dm-raid1.c
33137 +++ b/drivers/md/dm-raid1.c
33138 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33139
33140 struct mirror {
33141 struct mirror_set *ms;
33142 - atomic_t error_count;
33143 + atomic_unchecked_t error_count;
33144 unsigned long error_type;
33145 struct dm_dev *dev;
33146 sector_t offset;
33147 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33148 struct mirror *m;
33149
33150 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33151 - if (!atomic_read(&m->error_count))
33152 + if (!atomic_read_unchecked(&m->error_count))
33153 return m;
33154
33155 return NULL;
33156 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33157 * simple way to tell if a device has encountered
33158 * errors.
33159 */
33160 - atomic_inc(&m->error_count);
33161 + atomic_inc_unchecked(&m->error_count);
33162
33163 if (test_and_set_bit(error_type, &m->error_type))
33164 return;
33165 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33166 struct mirror *m = get_default_mirror(ms);
33167
33168 do {
33169 - if (likely(!atomic_read(&m->error_count)))
33170 + if (likely(!atomic_read_unchecked(&m->error_count)))
33171 return m;
33172
33173 if (m-- == ms->mirror)
33174 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33175 {
33176 struct mirror *default_mirror = get_default_mirror(m->ms);
33177
33178 - return !atomic_read(&default_mirror->error_count);
33179 + return !atomic_read_unchecked(&default_mirror->error_count);
33180 }
33181
33182 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33183 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33184 */
33185 if (likely(region_in_sync(ms, region, 1)))
33186 m = choose_mirror(ms, bio->bi_sector);
33187 - else if (m && atomic_read(&m->error_count))
33188 + else if (m && atomic_read_unchecked(&m->error_count))
33189 m = NULL;
33190
33191 if (likely(m))
33192 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33193 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33194 uint32_t region_size,
33195 struct dm_target *ti,
33196 + struct dm_dirty_log *dl) __size_overflow(1);
33197 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33198 + uint32_t region_size,
33199 + struct dm_target *ti,
33200 struct dm_dirty_log *dl)
33201 {
33202 size_t len;
33203 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33204 }
33205
33206 ms->mirror[mirror].ms = ms;
33207 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33208 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33209 ms->mirror[mirror].error_type = 0;
33210 ms->mirror[mirror].offset = offset;
33211
33212 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33213 */
33214 static char device_status_char(struct mirror *m)
33215 {
33216 - if (!atomic_read(&(m->error_count)))
33217 + if (!atomic_read_unchecked(&(m->error_count)))
33218 return 'A';
33219
33220 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33221 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33222 index 3d80cf0..7d98e1a 100644
33223 --- a/drivers/md/dm-stripe.c
33224 +++ b/drivers/md/dm-stripe.c
33225 @@ -20,7 +20,7 @@ struct stripe {
33226 struct dm_dev *dev;
33227 sector_t physical_start;
33228
33229 - atomic_t error_count;
33230 + atomic_unchecked_t error_count;
33231 };
33232
33233 struct stripe_c {
33234 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33235 dm_table_event(sc->ti->table);
33236 }
33237
33238 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
33239 static inline struct stripe_c *alloc_context(unsigned int stripes)
33240 {
33241 size_t len;
33242 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33243 kfree(sc);
33244 return r;
33245 }
33246 - atomic_set(&(sc->stripe[i].error_count), 0);
33247 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33248 }
33249
33250 ti->private = sc;
33251 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33252 DMEMIT("%d ", sc->stripes);
33253 for (i = 0; i < sc->stripes; i++) {
33254 DMEMIT("%s ", sc->stripe[i].dev->name);
33255 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33256 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33257 'D' : 'A';
33258 }
33259 buffer[i] = '\0';
33260 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33261 */
33262 for (i = 0; i < sc->stripes; i++)
33263 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33264 - atomic_inc(&(sc->stripe[i].error_count));
33265 - if (atomic_read(&(sc->stripe[i].error_count)) <
33266 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33267 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33268 DM_IO_ERROR_THRESHOLD)
33269 schedule_work(&sc->trigger_event);
33270 }
33271 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33272 index 63cc542..8d45caf3 100644
33273 --- a/drivers/md/dm-table.c
33274 +++ b/drivers/md/dm-table.c
33275 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33276 if (!dev_size)
33277 return 0;
33278
33279 - if ((start >= dev_size) || (start + len > dev_size)) {
33280 + if ((start >= dev_size) || (len > dev_size - start)) {
33281 DMWARN("%s: %s too small for target: "
33282 "start=%llu, len=%llu, dev_size=%llu",
33283 dm_device_name(ti->table->md), bdevname(bdev, b),
33284 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33285 index 237571a..fb6d19b 100644
33286 --- a/drivers/md/dm-thin-metadata.c
33287 +++ b/drivers/md/dm-thin-metadata.c
33288 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33289
33290 pmd->info.tm = tm;
33291 pmd->info.levels = 2;
33292 - pmd->info.value_type.context = pmd->data_sm;
33293 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33294 pmd->info.value_type.size = sizeof(__le64);
33295 pmd->info.value_type.inc = data_block_inc;
33296 pmd->info.value_type.dec = data_block_dec;
33297 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33298
33299 pmd->bl_info.tm = tm;
33300 pmd->bl_info.levels = 1;
33301 - pmd->bl_info.value_type.context = pmd->data_sm;
33302 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33303 pmd->bl_info.value_type.size = sizeof(__le64);
33304 pmd->bl_info.value_type.inc = data_block_inc;
33305 pmd->bl_info.value_type.dec = data_block_dec;
33306 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33307 index b89c548..2af3ce4 100644
33308 --- a/drivers/md/dm.c
33309 +++ b/drivers/md/dm.c
33310 @@ -176,9 +176,9 @@ struct mapped_device {
33311 /*
33312 * Event handling.
33313 */
33314 - atomic_t event_nr;
33315 + atomic_unchecked_t event_nr;
33316 wait_queue_head_t eventq;
33317 - atomic_t uevent_seq;
33318 + atomic_unchecked_t uevent_seq;
33319 struct list_head uevent_list;
33320 spinlock_t uevent_lock; /* Protect access to uevent_list */
33321
33322 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33323 rwlock_init(&md->map_lock);
33324 atomic_set(&md->holders, 1);
33325 atomic_set(&md->open_count, 0);
33326 - atomic_set(&md->event_nr, 0);
33327 - atomic_set(&md->uevent_seq, 0);
33328 + atomic_set_unchecked(&md->event_nr, 0);
33329 + atomic_set_unchecked(&md->uevent_seq, 0);
33330 INIT_LIST_HEAD(&md->uevent_list);
33331 spin_lock_init(&md->uevent_lock);
33332
33333 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33334
33335 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33336
33337 - atomic_inc(&md->event_nr);
33338 + atomic_inc_unchecked(&md->event_nr);
33339 wake_up(&md->eventq);
33340 }
33341
33342 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33343
33344 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33345 {
33346 - return atomic_add_return(1, &md->uevent_seq);
33347 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33348 }
33349
33350 uint32_t dm_get_event_nr(struct mapped_device *md)
33351 {
33352 - return atomic_read(&md->event_nr);
33353 + return atomic_read_unchecked(&md->event_nr);
33354 }
33355
33356 int dm_wait_event(struct mapped_device *md, int event_nr)
33357 {
33358 return wait_event_interruptible(md->eventq,
33359 - (event_nr != atomic_read(&md->event_nr)));
33360 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33361 }
33362
33363 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33364 diff --git a/drivers/md/md.c b/drivers/md/md.c
33365 index 6acc846..80a6b96 100644
33366 --- a/drivers/md/md.c
33367 +++ b/drivers/md/md.c
33368 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33369 * start build, activate spare
33370 */
33371 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33372 -static atomic_t md_event_count;
33373 +static atomic_unchecked_t md_event_count;
33374 void md_new_event(struct mddev *mddev)
33375 {
33376 - atomic_inc(&md_event_count);
33377 + atomic_inc_unchecked(&md_event_count);
33378 wake_up(&md_event_waiters);
33379 }
33380 EXPORT_SYMBOL_GPL(md_new_event);
33381 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33382 */
33383 static void md_new_event_inintr(struct mddev *mddev)
33384 {
33385 - atomic_inc(&md_event_count);
33386 + atomic_inc_unchecked(&md_event_count);
33387 wake_up(&md_event_waiters);
33388 }
33389
33390 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33391
33392 rdev->preferred_minor = 0xffff;
33393 rdev->data_offset = le64_to_cpu(sb->data_offset);
33394 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33395 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33396
33397 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33398 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33399 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33400 else
33401 sb->resync_offset = cpu_to_le64(0);
33402
33403 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33404 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33405
33406 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33407 sb->size = cpu_to_le64(mddev->dev_sectors);
33408 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33409 static ssize_t
33410 errors_show(struct md_rdev *rdev, char *page)
33411 {
33412 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33413 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33414 }
33415
33416 static ssize_t
33417 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33418 char *e;
33419 unsigned long n = simple_strtoul(buf, &e, 10);
33420 if (*buf && (*e == 0 || *e == '\n')) {
33421 - atomic_set(&rdev->corrected_errors, n);
33422 + atomic_set_unchecked(&rdev->corrected_errors, n);
33423 return len;
33424 }
33425 return -EINVAL;
33426 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
33427 rdev->sb_loaded = 0;
33428 rdev->bb_page = NULL;
33429 atomic_set(&rdev->nr_pending, 0);
33430 - atomic_set(&rdev->read_errors, 0);
33431 - atomic_set(&rdev->corrected_errors, 0);
33432 + atomic_set_unchecked(&rdev->read_errors, 0);
33433 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33434
33435 INIT_LIST_HEAD(&rdev->same_set);
33436 init_waitqueue_head(&rdev->blocked_wait);
33437 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33438
33439 spin_unlock(&pers_lock);
33440 seq_printf(seq, "\n");
33441 - seq->poll_event = atomic_read(&md_event_count);
33442 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33443 return 0;
33444 }
33445 if (v == (void*)2) {
33446 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33447 chunk_kb ? "KB" : "B");
33448 if (bitmap->file) {
33449 seq_printf(seq, ", file: ");
33450 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33451 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33452 }
33453
33454 seq_printf(seq, "\n");
33455 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33456 return error;
33457
33458 seq = file->private_data;
33459 - seq->poll_event = atomic_read(&md_event_count);
33460 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33461 return error;
33462 }
33463
33464 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33465 /* always allow read */
33466 mask = POLLIN | POLLRDNORM;
33467
33468 - if (seq->poll_event != atomic_read(&md_event_count))
33469 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33470 mask |= POLLERR | POLLPRI;
33471 return mask;
33472 }
33473 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33474 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33475 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33476 (int)part_stat_read(&disk->part0, sectors[1]) -
33477 - atomic_read(&disk->sync_io);
33478 + atomic_read_unchecked(&disk->sync_io);
33479 /* sync IO will cause sync_io to increase before the disk_stats
33480 * as sync_io is counted when a request starts, and
33481 * disk_stats is counted when it completes.
33482 diff --git a/drivers/md/md.h b/drivers/md/md.h
33483 index 44c63df..b795d1a 100644
33484 --- a/drivers/md/md.h
33485 +++ b/drivers/md/md.h
33486 @@ -93,13 +93,13 @@ struct md_rdev {
33487 * only maintained for arrays that
33488 * support hot removal
33489 */
33490 - atomic_t read_errors; /* number of consecutive read errors that
33491 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33492 * we have tried to ignore.
33493 */
33494 struct timespec last_read_error; /* monotonic time since our
33495 * last read error
33496 */
33497 - atomic_t corrected_errors; /* number of corrected read errors,
33498 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33499 * for reporting to userspace and storing
33500 * in superblock.
33501 */
33502 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33503
33504 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33505 {
33506 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33507 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33508 }
33509
33510 struct md_personality
33511 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33512 index 50ed53b..4f29d7d 100644
33513 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33514 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33515 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33516 /*----------------------------------------------------------------*/
33517
33518 struct sm_checker {
33519 - struct dm_space_map sm;
33520 + dm_space_map_no_const sm;
33521
33522 struct count_array old_counts;
33523 struct count_array counts;
33524 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33525 index fc469ba..2d91555 100644
33526 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33527 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33528 @@ -23,7 +23,7 @@
33529 * Space map interface.
33530 */
33531 struct sm_disk {
33532 - struct dm_space_map sm;
33533 + dm_space_map_no_const sm;
33534
33535 struct ll_disk ll;
33536 struct ll_disk old_ll;
33537 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33538 index e89ae5e..062e4c2 100644
33539 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33540 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33541 @@ -43,7 +43,7 @@ struct block_op {
33542 };
33543
33544 struct sm_metadata {
33545 - struct dm_space_map sm;
33546 + dm_space_map_no_const sm;
33547
33548 struct ll_disk ll;
33549 struct ll_disk old_ll;
33550 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33551 index 1cbfc6b..56e1dbb 100644
33552 --- a/drivers/md/persistent-data/dm-space-map.h
33553 +++ b/drivers/md/persistent-data/dm-space-map.h
33554 @@ -60,6 +60,7 @@ struct dm_space_map {
33555 int (*root_size)(struct dm_space_map *sm, size_t *result);
33556 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33557 };
33558 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33559
33560 /*----------------------------------------------------------------*/
33561
33562 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33563 index 118e0f6..210c4d7 100644
33564 --- a/drivers/md/raid1.c
33565 +++ b/drivers/md/raid1.c
33566 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33567 if (r1_sync_page_io(rdev, sect, s,
33568 bio->bi_io_vec[idx].bv_page,
33569 READ) != 0)
33570 - atomic_add(s, &rdev->corrected_errors);
33571 + atomic_add_unchecked(s, &rdev->corrected_errors);
33572 }
33573 sectors -= s;
33574 sect += s;
33575 @@ -1858,7 +1858,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33576 test_bit(In_sync, &rdev->flags)) {
33577 if (r1_sync_page_io(rdev, sect, s,
33578 conf->tmppage, READ)) {
33579 - atomic_add(s, &rdev->corrected_errors);
33580 + atomic_add_unchecked(s, &rdev->corrected_errors);
33581 printk(KERN_INFO
33582 "md/raid1:%s: read error corrected "
33583 "(%d sectors at %llu on %s)\n",
33584 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33585 index be7101d..f23ba30 100644
33586 --- a/drivers/md/raid10.c
33587 +++ b/drivers/md/raid10.c
33588 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33589 /* The write handler will notice the lack of
33590 * R10BIO_Uptodate and record any errors etc
33591 */
33592 - atomic_add(r10_bio->sectors,
33593 + atomic_add_unchecked(r10_bio->sectors,
33594 &conf->mirrors[d].rdev->corrected_errors);
33595
33596 /* for reconstruct, we always reschedule after a read.
33597 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33598 {
33599 struct timespec cur_time_mon;
33600 unsigned long hours_since_last;
33601 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33602 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33603
33604 ktime_get_ts(&cur_time_mon);
33605
33606 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33607 * overflowing the shift of read_errors by hours_since_last.
33608 */
33609 if (hours_since_last >= 8 * sizeof(read_errors))
33610 - atomic_set(&rdev->read_errors, 0);
33611 + atomic_set_unchecked(&rdev->read_errors, 0);
33612 else
33613 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33614 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33615 }
33616
33617 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33618 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33619 return;
33620
33621 check_decay_read_errors(mddev, rdev);
33622 - atomic_inc(&rdev->read_errors);
33623 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33624 + atomic_inc_unchecked(&rdev->read_errors);
33625 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33626 char b[BDEVNAME_SIZE];
33627 bdevname(rdev->bdev, b);
33628
33629 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33630 "md/raid10:%s: %s: Raid device exceeded "
33631 "read_error threshold [cur %d:max %d]\n",
33632 mdname(mddev), b,
33633 - atomic_read(&rdev->read_errors), max_read_errors);
33634 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33635 printk(KERN_NOTICE
33636 "md/raid10:%s: %s: Failing raid device\n",
33637 mdname(mddev), b);
33638 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33639 (unsigned long long)(
33640 sect + rdev->data_offset),
33641 bdevname(rdev->bdev, b));
33642 - atomic_add(s, &rdev->corrected_errors);
33643 + atomic_add_unchecked(s, &rdev->corrected_errors);
33644 }
33645
33646 rdev_dec_pending(rdev, mddev);
33647 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33648 index 360f2b9..08b5382 100644
33649 --- a/drivers/md/raid5.c
33650 +++ b/drivers/md/raid5.c
33651 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33652 (unsigned long long)(sh->sector
33653 + rdev->data_offset),
33654 bdevname(rdev->bdev, b));
33655 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33656 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33657 clear_bit(R5_ReadError, &sh->dev[i].flags);
33658 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33659 }
33660 - if (atomic_read(&rdev->read_errors))
33661 - atomic_set(&rdev->read_errors, 0);
33662 + if (atomic_read_unchecked(&rdev->read_errors))
33663 + atomic_set_unchecked(&rdev->read_errors, 0);
33664 } else {
33665 const char *bdn = bdevname(rdev->bdev, b);
33666 int retry = 0;
33667
33668 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33669 - atomic_inc(&rdev->read_errors);
33670 + atomic_inc_unchecked(&rdev->read_errors);
33671 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33672 printk_ratelimited(
33673 KERN_WARNING
33674 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33675 (unsigned long long)(sh->sector
33676 + rdev->data_offset),
33677 bdn);
33678 - else if (atomic_read(&rdev->read_errors)
33679 + else if (atomic_read_unchecked(&rdev->read_errors)
33680 > conf->max_nr_stripes)
33681 printk(KERN_WARNING
33682 "md/raid:%s: Too many read errors, failing device %s.\n",
33683 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33684 index ce4f858..7bcfb46 100644
33685 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33686 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33687 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33688 .subvendor = _subvend, .subdevice = _subdev, \
33689 .driver_data = (unsigned long)&_driverdata }
33690
33691 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33692 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33693 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33694 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33695 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33696 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33697 index a7d876f..8c21b61 100644
33698 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33699 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33700 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33701 union {
33702 dmx_ts_cb ts;
33703 dmx_section_cb sec;
33704 - } cb;
33705 + } __no_const cb;
33706
33707 struct dvb_demux *demux;
33708 void *priv;
33709 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33710 index 00a6732..70a682e 100644
33711 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33712 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33713 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33714 const struct dvb_device *template, void *priv, int type)
33715 {
33716 struct dvb_device *dvbdev;
33717 - struct file_operations *dvbdevfops;
33718 + file_operations_no_const *dvbdevfops;
33719 struct device *clsdev;
33720 int minor;
33721 int id;
33722 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33723 index 3940bb0..fb3952a 100644
33724 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33725 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33726 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33727
33728 struct dib0700_adapter_state {
33729 int (*set_param_save) (struct dvb_frontend *);
33730 -};
33731 +} __no_const;
33732
33733 static int dib7070_set_param_override(struct dvb_frontend *fe)
33734 {
33735 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33736 index 451c5a7..649f711 100644
33737 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33738 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33739 @@ -95,7 +95,7 @@ struct su3000_state {
33740
33741 struct s6x0_state {
33742 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33743 -};
33744 +} __no_const;
33745
33746 /* debug */
33747 static int dvb_usb_dw2102_debug;
33748 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33749 index 404f63a..4796533 100644
33750 --- a/drivers/media/dvb/frontends/dib3000.h
33751 +++ b/drivers/media/dvb/frontends/dib3000.h
33752 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33753 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33754 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33755 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33756 -};
33757 +} __no_const;
33758
33759 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33760 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33761 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33762 index 8418c02..8555013 100644
33763 --- a/drivers/media/dvb/ngene/ngene-cards.c
33764 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33765 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33766
33767 /****************************************************************************/
33768
33769 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33770 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33771 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33772 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33773 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33774 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33775 index 16a089f..ab1667d 100644
33776 --- a/drivers/media/radio/radio-cadet.c
33777 +++ b/drivers/media/radio/radio-cadet.c
33778 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33779 unsigned char readbuf[RDS_BUFFER];
33780 int i = 0;
33781
33782 + if (count > RDS_BUFFER)
33783 + return -EFAULT;
33784 mutex_lock(&dev->lock);
33785 if (dev->rdsstat == 0) {
33786 dev->rdsstat = 1;
33787 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33788 index 9cde353..8c6a1c3 100644
33789 --- a/drivers/media/video/au0828/au0828.h
33790 +++ b/drivers/media/video/au0828/au0828.h
33791 @@ -191,7 +191,7 @@ struct au0828_dev {
33792
33793 /* I2C */
33794 struct i2c_adapter i2c_adap;
33795 - struct i2c_algorithm i2c_algo;
33796 + i2c_algorithm_no_const i2c_algo;
33797 struct i2c_client i2c_client;
33798 u32 i2c_rc;
33799
33800 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
33801 index ee91e295..04ad048 100644
33802 --- a/drivers/media/video/cpia2/cpia2_core.c
33803 +++ b/drivers/media/video/cpia2/cpia2_core.c
33804 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
33805 return ret;
33806 }
33807
33808 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33809 static void *rvmalloc(unsigned long size)
33810 {
33811 void *mem;
33812 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
33813 index 82d195b..181103c 100644
33814 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
33815 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
33816 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
33817
33818
33819 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33820 + size_t size) __size_overflow(2);
33821 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33822 size_t size)
33823 {
33824 struct snd_pcm_runtime *runtime = subs->runtime;
33825 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
33826 index a2c2b7d..8f1bec7 100644
33827 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
33828 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
33829 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
33830 }
33831
33832 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33833 + size_t size) __size_overflow(2);
33834 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33835 size_t size)
33836 {
33837 struct snd_pcm_runtime *runtime = subs->runtime;
33838 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33839 index 04bf662..e0ac026 100644
33840 --- a/drivers/media/video/cx88/cx88-alsa.c
33841 +++ b/drivers/media/video/cx88/cx88-alsa.c
33842 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33843 * Only boards with eeprom and byte 1 at eeprom=1 have it
33844 */
33845
33846 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33847 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33848 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33849 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33850 {0, }
33851 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
33852 index e2a7b77..753d0ee 100644
33853 --- a/drivers/media/video/em28xx/em28xx-audio.c
33854 +++ b/drivers/media/video/em28xx/em28xx-audio.c
33855 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
33856 }
33857
33858 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33859 + size_t size) __size_overflow(2);
33860 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33861 size_t size)
33862 {
33863 struct snd_pcm_runtime *runtime = subs->runtime;
33864 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
33865 index b09a3c8..6dcba0a 100644
33866 --- a/drivers/media/video/meye.c
33867 +++ b/drivers/media/video/meye.c
33868 @@ -72,6 +72,7 @@ static struct meye meye;
33869 /****************************************************************************/
33870 /* Memory allocation routines (stolen from bttv-driver.c) */
33871 /****************************************************************************/
33872 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33873 static void *rvmalloc(unsigned long size)
33874 {
33875 void *mem;
33876 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33877 index 1fb7d5b..3901e77 100644
33878 --- a/drivers/media/video/omap/omap_vout.c
33879 +++ b/drivers/media/video/omap/omap_vout.c
33880 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33881 OMAP_VIDEO2,
33882 };
33883
33884 -static struct videobuf_queue_ops video_vbq_ops;
33885 /* Variables configurable through module params*/
33886 static u32 video1_numbuffers = 3;
33887 static u32 video2_numbuffers = 3;
33888 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33889 {
33890 struct videobuf_queue *q;
33891 struct omap_vout_device *vout = NULL;
33892 + static struct videobuf_queue_ops video_vbq_ops = {
33893 + .buf_setup = omap_vout_buffer_setup,
33894 + .buf_prepare = omap_vout_buffer_prepare,
33895 + .buf_release = omap_vout_buffer_release,
33896 + .buf_queue = omap_vout_buffer_queue,
33897 + };
33898
33899 vout = video_drvdata(file);
33900 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33901 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33902 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33903
33904 q = &vout->vbq;
33905 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33906 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33907 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33908 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33909 spin_lock_init(&vout->vbq_lock);
33910
33911 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33912 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33913 index 305e6aa..0143317 100644
33914 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33915 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33916 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33917
33918 /* I2C stuff */
33919 struct i2c_adapter i2c_adap;
33920 - struct i2c_algorithm i2c_algo;
33921 + i2c_algorithm_no_const i2c_algo;
33922 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33923 int i2c_cx25840_hack_state;
33924 int i2c_linked;
33925 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
33926 index 2fd38a0..ddec3c4 100644
33927 --- a/drivers/media/video/saa7164/saa7164-encoder.c
33928 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
33929 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
33930 }
33931
33932 static ssize_t fops_read(struct file *file, char __user *buffer,
33933 + size_t count, loff_t *pos) __size_overflow(3);
33934 +static ssize_t fops_read(struct file *file, char __user *buffer,
33935 size_t count, loff_t *pos)
33936 {
33937 struct saa7164_encoder_fh *fh = file->private_data;
33938 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
33939 index e2e0341..b80056c 100644
33940 --- a/drivers/media/video/saa7164/saa7164-vbi.c
33941 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
33942 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
33943 }
33944
33945 static ssize_t fops_read(struct file *file, char __user *buffer,
33946 + size_t count, loff_t *pos) __size_overflow(3);
33947 +static ssize_t fops_read(struct file *file, char __user *buffer,
33948 size_t count, loff_t *pos)
33949 {
33950 struct saa7164_vbi_fh *fh = file->private_data;
33951 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33952 index 4ed1c7c2..8f15e13 100644
33953 --- a/drivers/media/video/timblogiw.c
33954 +++ b/drivers/media/video/timblogiw.c
33955 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33956
33957 /* Platform device functions */
33958
33959 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33960 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33961 .vidioc_querycap = timblogiw_querycap,
33962 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33963 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33964 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33965 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33966 };
33967
33968 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33969 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33970 .owner = THIS_MODULE,
33971 .open = timblogiw_open,
33972 .release = timblogiw_close,
33973 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
33974 index c969111..a7910f4 100644
33975 --- a/drivers/media/video/videobuf-dma-contig.c
33976 +++ b/drivers/media/video/videobuf-dma-contig.c
33977 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
33978 return ret;
33979 }
33980
33981 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33982 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33983 {
33984 struct videobuf_dma_contig_memory *mem;
33985 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
33986 index f300dea..5fc9c4a 100644
33987 --- a/drivers/media/video/videobuf-dma-sg.c
33988 +++ b/drivers/media/video/videobuf-dma-sg.c
33989 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33990 struct videobuf_dma_sg_memory
33991 */
33992
33993 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33994 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33995 {
33996 struct videobuf_dma_sg_memory *mem;
33997 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
33998 index df14258..12cc7a3 100644
33999 --- a/drivers/media/video/videobuf-vmalloc.c
34000 +++ b/drivers/media/video/videobuf-vmalloc.c
34001 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
34002 struct videobuf_dma_sg_memory
34003 */
34004
34005 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34006 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34007 {
34008 struct videobuf_vmalloc_memory *mem;
34009 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34010 index a7dc467..a55c423 100644
34011 --- a/drivers/message/fusion/mptbase.c
34012 +++ b/drivers/message/fusion/mptbase.c
34013 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34014 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34015 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34016
34017 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34018 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34019 +#else
34020 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34021 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34022 +#endif
34023 +
34024 /*
34025 * Rounding UP to nearest 4-kB boundary here...
34026 */
34027 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34028 index 551262e..7551198 100644
34029 --- a/drivers/message/fusion/mptsas.c
34030 +++ b/drivers/message/fusion/mptsas.c
34031 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34032 return 0;
34033 }
34034
34035 +static inline void
34036 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34037 +{
34038 + if (phy_info->port_details) {
34039 + phy_info->port_details->rphy = rphy;
34040 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34041 + ioc->name, rphy));
34042 + }
34043 +
34044 + if (rphy) {
34045 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34046 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34047 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34048 + ioc->name, rphy, rphy->dev.release));
34049 + }
34050 +}
34051 +
34052 /* no mutex */
34053 static void
34054 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34055 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34056 return NULL;
34057 }
34058
34059 -static inline void
34060 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34061 -{
34062 - if (phy_info->port_details) {
34063 - phy_info->port_details->rphy = rphy;
34064 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34065 - ioc->name, rphy));
34066 - }
34067 -
34068 - if (rphy) {
34069 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34070 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34071 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34072 - ioc->name, rphy, rphy->dev.release));
34073 - }
34074 -}
34075 -
34076 static inline struct sas_port *
34077 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34078 {
34079 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34080 index 0c3ced7..1fe34ec 100644
34081 --- a/drivers/message/fusion/mptscsih.c
34082 +++ b/drivers/message/fusion/mptscsih.c
34083 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34084
34085 h = shost_priv(SChost);
34086
34087 - if (h) {
34088 - if (h->info_kbuf == NULL)
34089 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34090 - return h->info_kbuf;
34091 - h->info_kbuf[0] = '\0';
34092 + if (!h)
34093 + return NULL;
34094
34095 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34096 - h->info_kbuf[size-1] = '\0';
34097 - }
34098 + if (h->info_kbuf == NULL)
34099 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34100 + return h->info_kbuf;
34101 + h->info_kbuf[0] = '\0';
34102 +
34103 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34104 + h->info_kbuf[size-1] = '\0';
34105
34106 return h->info_kbuf;
34107 }
34108 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34109 index 6d115c7..58ff7fd 100644
34110 --- a/drivers/message/i2o/i2o_proc.c
34111 +++ b/drivers/message/i2o/i2o_proc.c
34112 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34113 "Array Controller Device"
34114 };
34115
34116 -static char *chtostr(u8 * chars, int n)
34117 -{
34118 - char tmp[256];
34119 - tmp[0] = 0;
34120 - return strncat(tmp, (char *)chars, n);
34121 -}
34122 -
34123 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34124 char *group)
34125 {
34126 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34127
34128 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34129 seq_printf(seq, "%-#8x", ddm_table.module_id);
34130 - seq_printf(seq, "%-29s",
34131 - chtostr(ddm_table.module_name_version, 28));
34132 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34133 seq_printf(seq, "%9d ", ddm_table.data_size);
34134 seq_printf(seq, "%8d", ddm_table.code_size);
34135
34136 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34137
34138 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34139 seq_printf(seq, "%-#8x", dst->module_id);
34140 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34141 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34142 + seq_printf(seq, "%-.28s", dst->module_name_version);
34143 + seq_printf(seq, "%-.8s", dst->date);
34144 seq_printf(seq, "%8d ", dst->module_size);
34145 seq_printf(seq, "%8d ", dst->mpb_size);
34146 seq_printf(seq, "0x%04x", dst->module_flags);
34147 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34148 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34149 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34150 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34151 - seq_printf(seq, "Vendor info : %s\n",
34152 - chtostr((u8 *) (work32 + 2), 16));
34153 - seq_printf(seq, "Product info : %s\n",
34154 - chtostr((u8 *) (work32 + 6), 16));
34155 - seq_printf(seq, "Description : %s\n",
34156 - chtostr((u8 *) (work32 + 10), 16));
34157 - seq_printf(seq, "Product rev. : %s\n",
34158 - chtostr((u8 *) (work32 + 14), 8));
34159 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34160 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34161 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34162 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34163
34164 seq_printf(seq, "Serial number : ");
34165 print_serial_number(seq, (u8 *) (work32 + 16),
34166 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34167 }
34168
34169 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34170 - seq_printf(seq, "Module name : %s\n",
34171 - chtostr(result.module_name, 24));
34172 - seq_printf(seq, "Module revision : %s\n",
34173 - chtostr(result.module_rev, 8));
34174 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34175 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34176
34177 seq_printf(seq, "Serial number : ");
34178 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34179 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34180 return 0;
34181 }
34182
34183 - seq_printf(seq, "Device name : %s\n",
34184 - chtostr(result.device_name, 64));
34185 - seq_printf(seq, "Service name : %s\n",
34186 - chtostr(result.service_name, 64));
34187 - seq_printf(seq, "Physical name : %s\n",
34188 - chtostr(result.physical_location, 64));
34189 - seq_printf(seq, "Instance number : %s\n",
34190 - chtostr(result.instance_number, 4));
34191 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34192 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34193 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34194 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34195
34196 return 0;
34197 }
34198 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34199 index a8c08f3..155fe3d 100644
34200 --- a/drivers/message/i2o/iop.c
34201 +++ b/drivers/message/i2o/iop.c
34202 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34203
34204 spin_lock_irqsave(&c->context_list_lock, flags);
34205
34206 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34207 - atomic_inc(&c->context_list_counter);
34208 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34209 + atomic_inc_unchecked(&c->context_list_counter);
34210
34211 - entry->context = atomic_read(&c->context_list_counter);
34212 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34213
34214 list_add(&entry->list, &c->context_list);
34215
34216 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34217
34218 #if BITS_PER_LONG == 64
34219 spin_lock_init(&c->context_list_lock);
34220 - atomic_set(&c->context_list_counter, 0);
34221 + atomic_set_unchecked(&c->context_list_counter, 0);
34222 INIT_LIST_HEAD(&c->context_list);
34223 #endif
34224
34225 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34226 index 7ce65f4..e66e9bc 100644
34227 --- a/drivers/mfd/abx500-core.c
34228 +++ b/drivers/mfd/abx500-core.c
34229 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34230
34231 struct abx500_device_entry {
34232 struct list_head list;
34233 - struct abx500_ops ops;
34234 + abx500_ops_no_const ops;
34235 struct device *dev;
34236 };
34237
34238 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34239 index a9223ed..4127b13 100644
34240 --- a/drivers/mfd/janz-cmodio.c
34241 +++ b/drivers/mfd/janz-cmodio.c
34242 @@ -13,6 +13,7 @@
34243
34244 #include <linux/kernel.h>
34245 #include <linux/module.h>
34246 +#include <linux/slab.h>
34247 #include <linux/init.h>
34248 #include <linux/pci.h>
34249 #include <linux/interrupt.h>
34250 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34251 index a981e2a..5ca0c8b 100644
34252 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34253 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34254 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34255 * the lid is closed. This leads to interrupts as soon as a little move
34256 * is done.
34257 */
34258 - atomic_inc(&lis3->count);
34259 + atomic_inc_unchecked(&lis3->count);
34260
34261 wake_up_interruptible(&lis3->misc_wait);
34262 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34263 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34264 if (lis3->pm_dev)
34265 pm_runtime_get_sync(lis3->pm_dev);
34266
34267 - atomic_set(&lis3->count, 0);
34268 + atomic_set_unchecked(&lis3->count, 0);
34269 return 0;
34270 }
34271
34272 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34273 add_wait_queue(&lis3->misc_wait, &wait);
34274 while (true) {
34275 set_current_state(TASK_INTERRUPTIBLE);
34276 - data = atomic_xchg(&lis3->count, 0);
34277 + data = atomic_xchg_unchecked(&lis3->count, 0);
34278 if (data)
34279 break;
34280
34281 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34282 struct lis3lv02d, miscdev);
34283
34284 poll_wait(file, &lis3->misc_wait, wait);
34285 - if (atomic_read(&lis3->count))
34286 + if (atomic_read_unchecked(&lis3->count))
34287 return POLLIN | POLLRDNORM;
34288 return 0;
34289 }
34290 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34291 index 2b1482a..5d33616 100644
34292 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34293 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34294 @@ -266,7 +266,7 @@ struct lis3lv02d {
34295 struct input_polled_dev *idev; /* input device */
34296 struct platform_device *pdev; /* platform device */
34297 struct regulator_bulk_data regulators[2];
34298 - atomic_t count; /* interrupt count after last read */
34299 + atomic_unchecked_t count; /* interrupt count after last read */
34300 union axis_conversion ac; /* hw -> logical axis */
34301 int mapped_btns[3];
34302
34303 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34304 index 2f30bad..c4c13d0 100644
34305 --- a/drivers/misc/sgi-gru/gruhandles.c
34306 +++ b/drivers/misc/sgi-gru/gruhandles.c
34307 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34308 unsigned long nsec;
34309
34310 nsec = CLKS2NSEC(clks);
34311 - atomic_long_inc(&mcs_op_statistics[op].count);
34312 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34313 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34314 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34315 if (mcs_op_statistics[op].max < nsec)
34316 mcs_op_statistics[op].max = nsec;
34317 }
34318 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34319 index 950dbe9..eeef0f8 100644
34320 --- a/drivers/misc/sgi-gru/gruprocfs.c
34321 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34322 @@ -32,9 +32,9 @@
34323
34324 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34325
34326 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34327 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34328 {
34329 - unsigned long val = atomic_long_read(v);
34330 + unsigned long val = atomic_long_read_unchecked(v);
34331
34332 seq_printf(s, "%16lu %s\n", val, id);
34333 }
34334 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34335
34336 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34337 for (op = 0; op < mcsop_last; op++) {
34338 - count = atomic_long_read(&mcs_op_statistics[op].count);
34339 - total = atomic_long_read(&mcs_op_statistics[op].total);
34340 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34341 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34342 max = mcs_op_statistics[op].max;
34343 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34344 count ? total / count : 0, max);
34345 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34346 index 5c3ce24..4915ccb 100644
34347 --- a/drivers/misc/sgi-gru/grutables.h
34348 +++ b/drivers/misc/sgi-gru/grutables.h
34349 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34350 * GRU statistics.
34351 */
34352 struct gru_stats_s {
34353 - atomic_long_t vdata_alloc;
34354 - atomic_long_t vdata_free;
34355 - atomic_long_t gts_alloc;
34356 - atomic_long_t gts_free;
34357 - atomic_long_t gms_alloc;
34358 - atomic_long_t gms_free;
34359 - atomic_long_t gts_double_allocate;
34360 - atomic_long_t assign_context;
34361 - atomic_long_t assign_context_failed;
34362 - atomic_long_t free_context;
34363 - atomic_long_t load_user_context;
34364 - atomic_long_t load_kernel_context;
34365 - atomic_long_t lock_kernel_context;
34366 - atomic_long_t unlock_kernel_context;
34367 - atomic_long_t steal_user_context;
34368 - atomic_long_t steal_kernel_context;
34369 - atomic_long_t steal_context_failed;
34370 - atomic_long_t nopfn;
34371 - atomic_long_t asid_new;
34372 - atomic_long_t asid_next;
34373 - atomic_long_t asid_wrap;
34374 - atomic_long_t asid_reuse;
34375 - atomic_long_t intr;
34376 - atomic_long_t intr_cbr;
34377 - atomic_long_t intr_tfh;
34378 - atomic_long_t intr_spurious;
34379 - atomic_long_t intr_mm_lock_failed;
34380 - atomic_long_t call_os;
34381 - atomic_long_t call_os_wait_queue;
34382 - atomic_long_t user_flush_tlb;
34383 - atomic_long_t user_unload_context;
34384 - atomic_long_t user_exception;
34385 - atomic_long_t set_context_option;
34386 - atomic_long_t check_context_retarget_intr;
34387 - atomic_long_t check_context_unload;
34388 - atomic_long_t tlb_dropin;
34389 - atomic_long_t tlb_preload_page;
34390 - atomic_long_t tlb_dropin_fail_no_asid;
34391 - atomic_long_t tlb_dropin_fail_upm;
34392 - atomic_long_t tlb_dropin_fail_invalid;
34393 - atomic_long_t tlb_dropin_fail_range_active;
34394 - atomic_long_t tlb_dropin_fail_idle;
34395 - atomic_long_t tlb_dropin_fail_fmm;
34396 - atomic_long_t tlb_dropin_fail_no_exception;
34397 - atomic_long_t tfh_stale_on_fault;
34398 - atomic_long_t mmu_invalidate_range;
34399 - atomic_long_t mmu_invalidate_page;
34400 - atomic_long_t flush_tlb;
34401 - atomic_long_t flush_tlb_gru;
34402 - atomic_long_t flush_tlb_gru_tgh;
34403 - atomic_long_t flush_tlb_gru_zero_asid;
34404 + atomic_long_unchecked_t vdata_alloc;
34405 + atomic_long_unchecked_t vdata_free;
34406 + atomic_long_unchecked_t gts_alloc;
34407 + atomic_long_unchecked_t gts_free;
34408 + atomic_long_unchecked_t gms_alloc;
34409 + atomic_long_unchecked_t gms_free;
34410 + atomic_long_unchecked_t gts_double_allocate;
34411 + atomic_long_unchecked_t assign_context;
34412 + atomic_long_unchecked_t assign_context_failed;
34413 + atomic_long_unchecked_t free_context;
34414 + atomic_long_unchecked_t load_user_context;
34415 + atomic_long_unchecked_t load_kernel_context;
34416 + atomic_long_unchecked_t lock_kernel_context;
34417 + atomic_long_unchecked_t unlock_kernel_context;
34418 + atomic_long_unchecked_t steal_user_context;
34419 + atomic_long_unchecked_t steal_kernel_context;
34420 + atomic_long_unchecked_t steal_context_failed;
34421 + atomic_long_unchecked_t nopfn;
34422 + atomic_long_unchecked_t asid_new;
34423 + atomic_long_unchecked_t asid_next;
34424 + atomic_long_unchecked_t asid_wrap;
34425 + atomic_long_unchecked_t asid_reuse;
34426 + atomic_long_unchecked_t intr;
34427 + atomic_long_unchecked_t intr_cbr;
34428 + atomic_long_unchecked_t intr_tfh;
34429 + atomic_long_unchecked_t intr_spurious;
34430 + atomic_long_unchecked_t intr_mm_lock_failed;
34431 + atomic_long_unchecked_t call_os;
34432 + atomic_long_unchecked_t call_os_wait_queue;
34433 + atomic_long_unchecked_t user_flush_tlb;
34434 + atomic_long_unchecked_t user_unload_context;
34435 + atomic_long_unchecked_t user_exception;
34436 + atomic_long_unchecked_t set_context_option;
34437 + atomic_long_unchecked_t check_context_retarget_intr;
34438 + atomic_long_unchecked_t check_context_unload;
34439 + atomic_long_unchecked_t tlb_dropin;
34440 + atomic_long_unchecked_t tlb_preload_page;
34441 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34442 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34443 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34444 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34445 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34446 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34447 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34448 + atomic_long_unchecked_t tfh_stale_on_fault;
34449 + atomic_long_unchecked_t mmu_invalidate_range;
34450 + atomic_long_unchecked_t mmu_invalidate_page;
34451 + atomic_long_unchecked_t flush_tlb;
34452 + atomic_long_unchecked_t flush_tlb_gru;
34453 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34454 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34455
34456 - atomic_long_t copy_gpa;
34457 - atomic_long_t read_gpa;
34458 + atomic_long_unchecked_t copy_gpa;
34459 + atomic_long_unchecked_t read_gpa;
34460
34461 - atomic_long_t mesq_receive;
34462 - atomic_long_t mesq_receive_none;
34463 - atomic_long_t mesq_send;
34464 - atomic_long_t mesq_send_failed;
34465 - atomic_long_t mesq_noop;
34466 - atomic_long_t mesq_send_unexpected_error;
34467 - atomic_long_t mesq_send_lb_overflow;
34468 - atomic_long_t mesq_send_qlimit_reached;
34469 - atomic_long_t mesq_send_amo_nacked;
34470 - atomic_long_t mesq_send_put_nacked;
34471 - atomic_long_t mesq_page_overflow;
34472 - atomic_long_t mesq_qf_locked;
34473 - atomic_long_t mesq_qf_noop_not_full;
34474 - atomic_long_t mesq_qf_switch_head_failed;
34475 - atomic_long_t mesq_qf_unexpected_error;
34476 - atomic_long_t mesq_noop_unexpected_error;
34477 - atomic_long_t mesq_noop_lb_overflow;
34478 - atomic_long_t mesq_noop_qlimit_reached;
34479 - atomic_long_t mesq_noop_amo_nacked;
34480 - atomic_long_t mesq_noop_put_nacked;
34481 - atomic_long_t mesq_noop_page_overflow;
34482 + atomic_long_unchecked_t mesq_receive;
34483 + atomic_long_unchecked_t mesq_receive_none;
34484 + atomic_long_unchecked_t mesq_send;
34485 + atomic_long_unchecked_t mesq_send_failed;
34486 + atomic_long_unchecked_t mesq_noop;
34487 + atomic_long_unchecked_t mesq_send_unexpected_error;
34488 + atomic_long_unchecked_t mesq_send_lb_overflow;
34489 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34490 + atomic_long_unchecked_t mesq_send_amo_nacked;
34491 + atomic_long_unchecked_t mesq_send_put_nacked;
34492 + atomic_long_unchecked_t mesq_page_overflow;
34493 + atomic_long_unchecked_t mesq_qf_locked;
34494 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34495 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34496 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34497 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34498 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34499 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34500 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34501 + atomic_long_unchecked_t mesq_noop_put_nacked;
34502 + atomic_long_unchecked_t mesq_noop_page_overflow;
34503
34504 };
34505
34506 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34507 tghop_invalidate, mcsop_last};
34508
34509 struct mcs_op_statistic {
34510 - atomic_long_t count;
34511 - atomic_long_t total;
34512 + atomic_long_unchecked_t count;
34513 + atomic_long_unchecked_t total;
34514 unsigned long max;
34515 };
34516
34517 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34518
34519 #define STAT(id) do { \
34520 if (gru_options & OPT_STATS) \
34521 - atomic_long_inc(&gru_stats.id); \
34522 + atomic_long_inc_unchecked(&gru_stats.id); \
34523 } while (0)
34524
34525 #ifdef CONFIG_SGI_GRU_DEBUG
34526 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34527 index 851b2f2..a4ec097 100644
34528 --- a/drivers/misc/sgi-xp/xp.h
34529 +++ b/drivers/misc/sgi-xp/xp.h
34530 @@ -289,7 +289,7 @@ struct xpc_interface {
34531 xpc_notify_func, void *);
34532 void (*received) (short, int, void *);
34533 enum xp_retval (*partid_to_nasids) (short, void *);
34534 -};
34535 +} __no_const;
34536
34537 extern struct xpc_interface xpc_interface;
34538
34539 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34540 index b94d5f7..7f494c5 100644
34541 --- a/drivers/misc/sgi-xp/xpc.h
34542 +++ b/drivers/misc/sgi-xp/xpc.h
34543 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34544 void (*received_payload) (struct xpc_channel *, void *);
34545 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34546 };
34547 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34548
34549 /* struct xpc_partition act_state values (for XPC HB) */
34550
34551 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34552 /* found in xpc_main.c */
34553 extern struct device *xpc_part;
34554 extern struct device *xpc_chan;
34555 -extern struct xpc_arch_operations xpc_arch_ops;
34556 +extern xpc_arch_operations_no_const xpc_arch_ops;
34557 extern int xpc_disengage_timelimit;
34558 extern int xpc_disengage_timedout;
34559 extern int xpc_activate_IRQ_rcvd;
34560 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34561 index 8d082b4..aa749ae 100644
34562 --- a/drivers/misc/sgi-xp/xpc_main.c
34563 +++ b/drivers/misc/sgi-xp/xpc_main.c
34564 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34565 .notifier_call = xpc_system_die,
34566 };
34567
34568 -struct xpc_arch_operations xpc_arch_ops;
34569 +xpc_arch_operations_no_const xpc_arch_ops;
34570
34571 /*
34572 * Timer function to enforce the timelimit on the partition disengage.
34573 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34574 index 6ebdc40..9edf5d8 100644
34575 --- a/drivers/mmc/host/sdhci-pci.c
34576 +++ b/drivers/mmc/host/sdhci-pci.c
34577 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34578 .probe = via_probe,
34579 };
34580
34581 -static const struct pci_device_id pci_ids[] __devinitdata = {
34582 +static const struct pci_device_id pci_ids[] __devinitconst = {
34583 {
34584 .vendor = PCI_VENDOR_ID_RICOH,
34585 .device = PCI_DEVICE_ID_RICOH_R5C822,
34586 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34587 index 87a431c..4959b43 100644
34588 --- a/drivers/mtd/devices/doc2000.c
34589 +++ b/drivers/mtd/devices/doc2000.c
34590 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34591
34592 /* The ECC will not be calculated correctly if less than 512 is written */
34593 /* DBB-
34594 - if (len != 0x200 && eccbuf)
34595 + if (len != 0x200)
34596 printk(KERN_WARNING
34597 "ECC needs a full sector write (adr: %lx size %lx)\n",
34598 (long) to, (long) len);
34599 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34600 index 9eacf67..4534b5b 100644
34601 --- a/drivers/mtd/devices/doc2001.c
34602 +++ b/drivers/mtd/devices/doc2001.c
34603 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34604 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34605
34606 /* Don't allow read past end of device */
34607 - if (from >= this->totlen)
34608 + if (from >= this->totlen || !len)
34609 return -EINVAL;
34610
34611 /* Don't allow a single read to cross a 512-byte block boundary */
34612 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34613 index 3984d48..28aa897 100644
34614 --- a/drivers/mtd/nand/denali.c
34615 +++ b/drivers/mtd/nand/denali.c
34616 @@ -26,6 +26,7 @@
34617 #include <linux/pci.h>
34618 #include <linux/mtd/mtd.h>
34619 #include <linux/module.h>
34620 +#include <linux/slab.h>
34621
34622 #include "denali.h"
34623
34624 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34625 index 51b9d6a..52af9a7 100644
34626 --- a/drivers/mtd/nftlmount.c
34627 +++ b/drivers/mtd/nftlmount.c
34628 @@ -24,6 +24,7 @@
34629 #include <asm/errno.h>
34630 #include <linux/delay.h>
34631 #include <linux/slab.h>
34632 +#include <linux/sched.h>
34633 #include <linux/mtd/mtd.h>
34634 #include <linux/mtd/nand.h>
34635 #include <linux/mtd/nftl.h>
34636 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34637 index e2cdebf..d48183a 100644
34638 --- a/drivers/mtd/ubi/debug.c
34639 +++ b/drivers/mtd/ubi/debug.c
34640 @@ -338,6 +338,8 @@ out:
34641
34642 /* Write an UBI debugfs file */
34643 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34644 + size_t count, loff_t *ppos) __size_overflow(3);
34645 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34646 size_t count, loff_t *ppos)
34647 {
34648 unsigned long ubi_num = (unsigned long)file->private_data;
34649 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34650 index 071f4c8..440862e 100644
34651 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34652 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34653 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34654 */
34655
34656 #define ATL2_PARAM(X, desc) \
34657 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34658 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34659 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34660 MODULE_PARM_DESC(X, desc);
34661 #else
34662 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34663 index 66da39f..5dc436d 100644
34664 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34665 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34666 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34667
34668 int (*wait_comp)(struct bnx2x *bp,
34669 struct bnx2x_rx_mode_ramrod_params *p);
34670 -};
34671 +} __no_const;
34672
34673 /********************** Set multicast group ***********************************/
34674
34675 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34676 index aea8f72..fcebf75 100644
34677 --- a/drivers/net/ethernet/broadcom/tg3.h
34678 +++ b/drivers/net/ethernet/broadcom/tg3.h
34679 @@ -140,6 +140,7 @@
34680 #define CHIPREV_ID_5750_A0 0x4000
34681 #define CHIPREV_ID_5750_A1 0x4001
34682 #define CHIPREV_ID_5750_A3 0x4003
34683 +#define CHIPREV_ID_5750_C1 0x4201
34684 #define CHIPREV_ID_5750_C2 0x4202
34685 #define CHIPREV_ID_5752_A0_HW 0x5000
34686 #define CHIPREV_ID_5752_A0 0x6000
34687 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
34688 index 47a8435..248e4b3 100644
34689 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
34690 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
34691 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
34692 * be copied but there is no memory for the copy.
34693 */
34694 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34695 + struct freelQ *fl, unsigned int len) __size_overflow(3);
34696 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34697 struct freelQ *fl, unsigned int len)
34698 {
34699 struct sk_buff *skb;
34700 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34701 index c4e8643..0979484 100644
34702 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34703 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34704 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34705 */
34706 struct l2t_skb_cb {
34707 arp_failure_handler_func arp_failure_handler;
34708 -};
34709 +} __no_const;
34710
34711 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34712
34713 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34714 index cfb60e1..94af340 100644
34715 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34716 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34717 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34718 * of the SW ring.
34719 */
34720 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34721 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34722 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34723 size_t sw_size, dma_addr_t * phys, void *metadata)
34724 {
34725 size_t len = nelem * elem_size;
34726 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
34727 * be copied but there is no memory for the copy.
34728 */
34729 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34730 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
34731 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34732 unsigned int len, unsigned int drop_thres)
34733 {
34734 struct sk_buff *skb = NULL;
34735 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34736 index 2dae795..73037d2 100644
34737 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34738 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34739 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34740 */
34741 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34742 size_t sw_size, dma_addr_t *phys, void *metadata,
34743 + size_t stat_size, int node) __size_overflow(2,4);
34744 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34745 + size_t sw_size, dma_addr_t *phys, void *metadata,
34746 size_t stat_size, int node)
34747 {
34748 size_t len = nelem * elem_size + stat_size;
34749 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34750 index 0bd585b..d954ca5 100644
34751 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34752 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34753 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34754 */
34755 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34756 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34757 + size_t stat_size) __size_overflow(2,4);
34758 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34759 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34760 size_t stat_size)
34761 {
34762 /*
34763 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34764 index 4d71f5a..8004440 100644
34765 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34766 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34767 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34768 for (i=0; i<ETH_ALEN; i++) {
34769 tmp.addr[i] = dev->dev_addr[i];
34770 }
34771 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34772 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34773 break;
34774
34775 case DE4X5_SET_HWADDR: /* Set the hardware address */
34776 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34777 spin_lock_irqsave(&lp->lock, flags);
34778 memcpy(&statbuf, &lp->pktStats, ioc->len);
34779 spin_unlock_irqrestore(&lp->lock, flags);
34780 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34781 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34782 return -EFAULT;
34783 break;
34784 }
34785 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34786 index 14d5b61..1398636 100644
34787 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34788 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34789 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34790 {NULL}};
34791
34792
34793 -static const char *block_name[] __devinitdata = {
34794 +static const char *block_name[] __devinitconst = {
34795 "21140 non-MII",
34796 "21140 MII PHY",
34797 "21142 Serial PHY",
34798 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34799 index 52da7b2..4ddfe1c 100644
34800 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34801 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34802 @@ -236,7 +236,7 @@ struct pci_id_info {
34803 int drv_flags; /* Driver use, intended as capability flags. */
34804 };
34805
34806 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34807 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34808 { /* Sometime a Level-One switch card. */
34809 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34810 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34811 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34812 index 28a3a9b..d96cb63 100644
34813 --- a/drivers/net/ethernet/dlink/sundance.c
34814 +++ b/drivers/net/ethernet/dlink/sundance.c
34815 @@ -218,7 +218,7 @@ enum {
34816 struct pci_id_info {
34817 const char *name;
34818 };
34819 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34820 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34821 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34822 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34823 {"D-Link DFE-580TX 4 port Server Adapter"},
34824 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34825 index e703d64..d62ecf9 100644
34826 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34827 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34828 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34829
34830 if (wrapped)
34831 newacc += 65536;
34832 - ACCESS_ONCE(*acc) = newacc;
34833 + ACCESS_ONCE_RW(*acc) = newacc;
34834 }
34835
34836 void be_parse_stats(struct be_adapter *adapter)
34837 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34838 index 47f85c3..82ab6c4 100644
34839 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34840 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34841 @@ -31,6 +31,8 @@
34842 #include <linux/netdevice.h>
34843 #include <linux/phy.h>
34844 #include <linux/platform_device.h>
34845 +#include <linux/interrupt.h>
34846 +#include <linux/irqreturn.h>
34847 #include <net/ip.h>
34848
34849 #include "ftgmac100.h"
34850 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34851 index bb336a0..4b472da 100644
34852 --- a/drivers/net/ethernet/faraday/ftmac100.c
34853 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34854 @@ -31,6 +31,8 @@
34855 #include <linux/module.h>
34856 #include <linux/netdevice.h>
34857 #include <linux/platform_device.h>
34858 +#include <linux/interrupt.h>
34859 +#include <linux/irqreturn.h>
34860
34861 #include "ftmac100.h"
34862
34863 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34864 index c82d444..0007fb4 100644
34865 --- a/drivers/net/ethernet/fealnx.c
34866 +++ b/drivers/net/ethernet/fealnx.c
34867 @@ -150,7 +150,7 @@ struct chip_info {
34868 int flags;
34869 };
34870
34871 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34872 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34873 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34874 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34875 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34876 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34877 index e1159e5..e18684d 100644
34878 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34879 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34880 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34881 {
34882 struct e1000_hw *hw = &adapter->hw;
34883 struct e1000_mac_info *mac = &hw->mac;
34884 - struct e1000_mac_operations *func = &mac->ops;
34885 + e1000_mac_operations_no_const *func = &mac->ops;
34886
34887 /* Set media type */
34888 switch (adapter->pdev->device) {
34889 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34890 index a3e65fd..f451444 100644
34891 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34892 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34893 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34894 {
34895 struct e1000_hw *hw = &adapter->hw;
34896 struct e1000_mac_info *mac = &hw->mac;
34897 - struct e1000_mac_operations *func = &mac->ops;
34898 + e1000_mac_operations_no_const *func = &mac->ops;
34899 u32 swsm = 0;
34900 u32 swsm2 = 0;
34901 bool force_clear_smbi = false;
34902 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34903 index 2967039..ca8c40c 100644
34904 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34905 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34906 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34907 void (*write_vfta)(struct e1000_hw *, u32, u32);
34908 s32 (*read_mac_addr)(struct e1000_hw *);
34909 };
34910 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34911
34912 /*
34913 * When to use various PHY register access functions:
34914 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34915 void (*power_up)(struct e1000_hw *);
34916 void (*power_down)(struct e1000_hw *);
34917 };
34918 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34919
34920 /* Function pointers for the NVM. */
34921 struct e1000_nvm_operations {
34922 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34923 s32 (*validate)(struct e1000_hw *);
34924 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34925 };
34926 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34927
34928 struct e1000_mac_info {
34929 - struct e1000_mac_operations ops;
34930 + e1000_mac_operations_no_const ops;
34931 u8 addr[ETH_ALEN];
34932 u8 perm_addr[ETH_ALEN];
34933
34934 @@ -872,7 +875,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 @@ -906,7 +909,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
34950 enum e1000_nvm_type type;
34951 enum e1000_nvm_override override;
34952 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34953 index f67cbd3..cef9e3d 100644
34954 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34955 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34956 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34957 s32 (*read_mac_addr)(struct e1000_hw *);
34958 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34959 };
34960 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34961
34962 struct e1000_phy_operations {
34963 s32 (*acquire)(struct e1000_hw *);
34964 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34965 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34966 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34967 };
34968 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34969
34970 struct e1000_nvm_operations {
34971 s32 (*acquire)(struct e1000_hw *);
34972 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34973 s32 (*update)(struct e1000_hw *);
34974 s32 (*validate)(struct e1000_hw *);
34975 };
34976 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34977
34978 struct e1000_info {
34979 s32 (*get_invariants)(struct e1000_hw *);
34980 @@ -350,7 +353,7 @@ struct e1000_info {
34981 extern const struct e1000_info e1000_82575_info;
34982
34983 struct e1000_mac_info {
34984 - struct e1000_mac_operations ops;
34985 + e1000_mac_operations_no_const ops;
34986
34987 u8 addr[6];
34988 u8 perm_addr[6];
34989 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34990 };
34991
34992 struct e1000_phy_info {
34993 - struct e1000_phy_operations ops;
34994 + e1000_phy_operations_no_const ops;
34995
34996 enum e1000_phy_type type;
34997
34998 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34999 };
35000
35001 struct e1000_nvm_info {
35002 - struct e1000_nvm_operations ops;
35003 + e1000_nvm_operations_no_const ops;
35004 enum e1000_nvm_type type;
35005 enum e1000_nvm_override override;
35006
35007 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35008 s32 (*check_for_ack)(struct e1000_hw *, u16);
35009 s32 (*check_for_rst)(struct e1000_hw *, u16);
35010 };
35011 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35012
35013 struct e1000_mbx_stats {
35014 u32 msgs_tx;
35015 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35016 };
35017
35018 struct e1000_mbx_info {
35019 - struct e1000_mbx_operations ops;
35020 + e1000_mbx_operations_no_const ops;
35021 struct e1000_mbx_stats stats;
35022 u32 timeout;
35023 u32 usec_delay;
35024 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35025 index 57db3c6..aa825fc 100644
35026 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35027 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35028 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35029 s32 (*read_mac_addr)(struct e1000_hw *);
35030 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35031 };
35032 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35033
35034 struct e1000_mac_info {
35035 - struct e1000_mac_operations ops;
35036 + e1000_mac_operations_no_const ops;
35037 u8 addr[6];
35038 u8 perm_addr[6];
35039
35040 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35041 s32 (*check_for_ack)(struct e1000_hw *);
35042 s32 (*check_for_rst)(struct e1000_hw *);
35043 };
35044 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35045
35046 struct e1000_mbx_stats {
35047 u32 msgs_tx;
35048 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35049 };
35050
35051 struct e1000_mbx_info {
35052 - struct e1000_mbx_operations ops;
35053 + e1000_mbx_operations_no_const ops;
35054 struct e1000_mbx_stats stats;
35055 u32 timeout;
35056 u32 usec_delay;
35057 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35058 index 9b95bef..7e254ee 100644
35059 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35060 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35061 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35062 s32 (*update_checksum)(struct ixgbe_hw *);
35063 u16 (*calc_checksum)(struct ixgbe_hw *);
35064 };
35065 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35066
35067 struct ixgbe_mac_operations {
35068 s32 (*init_hw)(struct ixgbe_hw *);
35069 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35070 /* Manageability interface */
35071 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35072 };
35073 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35074
35075 struct ixgbe_phy_operations {
35076 s32 (*identify)(struct ixgbe_hw *);
35077 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35078 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35079 s32 (*check_overtemp)(struct ixgbe_hw *);
35080 };
35081 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35082
35083 struct ixgbe_eeprom_info {
35084 - struct ixgbe_eeprom_operations ops;
35085 + ixgbe_eeprom_operations_no_const ops;
35086 enum ixgbe_eeprom_type type;
35087 u32 semaphore_delay;
35088 u16 word_size;
35089 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35090
35091 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35092 struct ixgbe_mac_info {
35093 - struct ixgbe_mac_operations ops;
35094 + ixgbe_mac_operations_no_const ops;
35095 enum ixgbe_mac_type type;
35096 u8 addr[ETH_ALEN];
35097 u8 perm_addr[ETH_ALEN];
35098 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35099 };
35100
35101 struct ixgbe_phy_info {
35102 - struct ixgbe_phy_operations ops;
35103 + ixgbe_phy_operations_no_const ops;
35104 struct mdio_if_info mdio;
35105 enum ixgbe_phy_type type;
35106 u32 id;
35107 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35108 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35109 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35110 };
35111 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35112
35113 struct ixgbe_mbx_stats {
35114 u32 msgs_tx;
35115 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35116 };
35117
35118 struct ixgbe_mbx_info {
35119 - struct ixgbe_mbx_operations ops;
35120 + ixgbe_mbx_operations_no_const ops;
35121 struct ixgbe_mbx_stats stats;
35122 u32 timeout;
35123 u32 usec_delay;
35124 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35125 index 25c951d..cc7cf33 100644
35126 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35127 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35128 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35129 s32 (*clear_vfta)(struct ixgbe_hw *);
35130 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35131 };
35132 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35133
35134 enum ixgbe_mac_type {
35135 ixgbe_mac_unknown = 0,
35136 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35137 };
35138
35139 struct ixgbe_mac_info {
35140 - struct ixgbe_mac_operations ops;
35141 + ixgbe_mac_operations_no_const ops;
35142 u8 addr[6];
35143 u8 perm_addr[6];
35144
35145 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35146 s32 (*check_for_ack)(struct ixgbe_hw *);
35147 s32 (*check_for_rst)(struct ixgbe_hw *);
35148 };
35149 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35150
35151 struct ixgbe_mbx_stats {
35152 u32 msgs_tx;
35153 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35154 };
35155
35156 struct ixgbe_mbx_info {
35157 - struct ixgbe_mbx_operations ops;
35158 + ixgbe_mbx_operations_no_const ops;
35159 struct ixgbe_mbx_stats stats;
35160 u32 timeout;
35161 u32 udelay;
35162 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35163 index 8bf22b6..7f5baaa 100644
35164 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35165 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35166 @@ -41,6 +41,7 @@
35167 #include <linux/slab.h>
35168 #include <linux/io-mapping.h>
35169 #include <linux/delay.h>
35170 +#include <linux/sched.h>
35171
35172 #include <linux/mlx4/device.h>
35173 #include <linux/mlx4/doorbell.h>
35174 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35175 index 5046a64..71ca936 100644
35176 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35177 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35178 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35179 void (*link_down)(struct __vxge_hw_device *devh);
35180 void (*crit_err)(struct __vxge_hw_device *devh,
35181 enum vxge_hw_event type, u64 ext_data);
35182 -};
35183 +} __no_const;
35184
35185 /*
35186 * struct __vxge_hw_blockpool_entry - Block private data structure
35187 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35188 index 4a518a3..936b334 100644
35189 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35190 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35191 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35192 struct vxge_hw_mempool_dma *dma_object,
35193 u32 index,
35194 u32 is_last);
35195 -};
35196 +} __no_const;
35197
35198 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35199 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35200 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35201 index bbacb37..d60887d 100644
35202 --- a/drivers/net/ethernet/realtek/r8169.c
35203 +++ b/drivers/net/ethernet/realtek/r8169.c
35204 @@ -695,17 +695,17 @@ struct rtl8169_private {
35205 struct mdio_ops {
35206 void (*write)(void __iomem *, int, int);
35207 int (*read)(void __iomem *, int);
35208 - } mdio_ops;
35209 + } __no_const mdio_ops;
35210
35211 struct pll_power_ops {
35212 void (*down)(struct rtl8169_private *);
35213 void (*up)(struct rtl8169_private *);
35214 - } pll_power_ops;
35215 + } __no_const pll_power_ops;
35216
35217 struct jumbo_ops {
35218 void (*enable)(struct rtl8169_private *);
35219 void (*disable)(struct rtl8169_private *);
35220 - } jumbo_ops;
35221 + } __no_const jumbo_ops;
35222
35223 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35224 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35225 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35226 index 5b118cd..858b523 100644
35227 --- a/drivers/net/ethernet/sis/sis190.c
35228 +++ b/drivers/net/ethernet/sis/sis190.c
35229 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35230 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35231 struct net_device *dev)
35232 {
35233 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35234 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35235 struct sis190_private *tp = netdev_priv(dev);
35236 struct pci_dev *isa_bridge;
35237 u8 reg, tmp8;
35238 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35239 index c07cfe9..81cbf7e 100644
35240 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35241 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35242 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35243
35244 writel(value, ioaddr + MMC_CNTRL);
35245
35246 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35247 - MMC_CNTRL, value);
35248 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35249 +// MMC_CNTRL, value);
35250 }
35251
35252 /* To mask all all interrupts.*/
35253 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35254 index dec5836..6d4db7d 100644
35255 --- a/drivers/net/hyperv/hyperv_net.h
35256 +++ b/drivers/net/hyperv/hyperv_net.h
35257 @@ -97,7 +97,7 @@ struct rndis_device {
35258
35259 enum rndis_device_state state;
35260 bool link_state;
35261 - atomic_t new_req_id;
35262 + atomic_unchecked_t new_req_id;
35263
35264 spinlock_t request_lock;
35265 struct list_head req_list;
35266 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35267 index 133b7fb..d58c559 100644
35268 --- a/drivers/net/hyperv/rndis_filter.c
35269 +++ b/drivers/net/hyperv/rndis_filter.c
35270 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35271 * template
35272 */
35273 set = &rndis_msg->msg.set_req;
35274 - set->req_id = atomic_inc_return(&dev->new_req_id);
35275 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35276
35277 /* Add to the request list */
35278 spin_lock_irqsave(&dev->request_lock, flags);
35279 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35280
35281 /* Setup the rndis set */
35282 halt = &request->request_msg.msg.halt_req;
35283 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35284 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35285
35286 /* Ignore return since this msg is optional. */
35287 rndis_filter_send_request(dev, request);
35288 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35289 index 58dc117..f140c77 100644
35290 --- a/drivers/net/macvtap.c
35291 +++ b/drivers/net/macvtap.c
35292 @@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35293 }
35294 base = (unsigned long)from->iov_base + offset1;
35295 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35296 + if (i + size >= MAX_SKB_FRAGS)
35297 + return -EFAULT;
35298 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35299 if ((num_pages != size) ||
35300 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35301 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35302 index 486b404..0d6677d 100644
35303 --- a/drivers/net/ppp/ppp_generic.c
35304 +++ b/drivers/net/ppp/ppp_generic.c
35305 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35306 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35307 struct ppp_stats stats;
35308 struct ppp_comp_stats cstats;
35309 - char *vers;
35310
35311 switch (cmd) {
35312 case SIOCGPPPSTATS:
35313 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35314 break;
35315
35316 case SIOCGPPPVER:
35317 - vers = PPP_VERSION;
35318 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35319 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35320 break;
35321 err = 0;
35322 break;
35323 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35324 index 515f122..41dd273 100644
35325 --- a/drivers/net/tokenring/abyss.c
35326 +++ b/drivers/net/tokenring/abyss.c
35327 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35328
35329 static int __init abyss_init (void)
35330 {
35331 - abyss_netdev_ops = tms380tr_netdev_ops;
35332 + pax_open_kernel();
35333 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35334
35335 - abyss_netdev_ops.ndo_open = abyss_open;
35336 - abyss_netdev_ops.ndo_stop = abyss_close;
35337 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35338 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35339 + pax_close_kernel();
35340
35341 return pci_register_driver(&abyss_driver);
35342 }
35343 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35344 index 6153cfd..cf69c1c 100644
35345 --- a/drivers/net/tokenring/madgemc.c
35346 +++ b/drivers/net/tokenring/madgemc.c
35347 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35348
35349 static int __init madgemc_init (void)
35350 {
35351 - madgemc_netdev_ops = tms380tr_netdev_ops;
35352 - madgemc_netdev_ops.ndo_open = madgemc_open;
35353 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35354 + pax_open_kernel();
35355 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35356 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35357 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35358 + pax_close_kernel();
35359
35360 return mca_register_driver (&madgemc_driver);
35361 }
35362 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35363 index 8d362e6..f91cc52 100644
35364 --- a/drivers/net/tokenring/proteon.c
35365 +++ b/drivers/net/tokenring/proteon.c
35366 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35367 struct platform_device *pdev;
35368 int i, num = 0, err = 0;
35369
35370 - proteon_netdev_ops = tms380tr_netdev_ops;
35371 - proteon_netdev_ops.ndo_open = proteon_open;
35372 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35373 + pax_open_kernel();
35374 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35375 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35376 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35377 + pax_close_kernel();
35378
35379 err = platform_driver_register(&proteon_driver);
35380 if (err)
35381 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35382 index 46db5c5..37c1536 100644
35383 --- a/drivers/net/tokenring/skisa.c
35384 +++ b/drivers/net/tokenring/skisa.c
35385 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35386 struct platform_device *pdev;
35387 int i, num = 0, err = 0;
35388
35389 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35390 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35391 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35392 + pax_open_kernel();
35393 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35394 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35395 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35396 + pax_close_kernel();
35397
35398 err = platform_driver_register(&sk_isa_driver);
35399 if (err)
35400 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35401 index e1324b4..e1b0041 100644
35402 --- a/drivers/net/usb/hso.c
35403 +++ b/drivers/net/usb/hso.c
35404 @@ -71,7 +71,7 @@
35405 #include <asm/byteorder.h>
35406 #include <linux/serial_core.h>
35407 #include <linux/serial.h>
35408 -
35409 +#include <asm/local.h>
35410
35411 #define MOD_AUTHOR "Option Wireless"
35412 #define MOD_DESCRIPTION "USB High Speed Option driver"
35413 @@ -257,7 +257,7 @@ struct hso_serial {
35414
35415 /* from usb_serial_port */
35416 struct tty_struct *tty;
35417 - int open_count;
35418 + local_t open_count;
35419 spinlock_t serial_lock;
35420
35421 int (*write_data) (struct hso_serial *serial);
35422 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35423 struct urb *urb;
35424
35425 urb = serial->rx_urb[0];
35426 - if (serial->open_count > 0) {
35427 + if (local_read(&serial->open_count) > 0) {
35428 count = put_rxbuf_data(urb, serial);
35429 if (count == -1)
35430 return;
35431 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35432 DUMP1(urb->transfer_buffer, urb->actual_length);
35433
35434 /* Anyone listening? */
35435 - if (serial->open_count == 0)
35436 + if (local_read(&serial->open_count) == 0)
35437 return;
35438
35439 if (status == 0) {
35440 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35441 spin_unlock_irq(&serial->serial_lock);
35442
35443 /* check for port already opened, if not set the termios */
35444 - serial->open_count++;
35445 - if (serial->open_count == 1) {
35446 + if (local_inc_return(&serial->open_count) == 1) {
35447 serial->rx_state = RX_IDLE;
35448 /* Force default termio settings */
35449 _hso_serial_set_termios(tty, NULL);
35450 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35451 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35452 if (result) {
35453 hso_stop_serial_device(serial->parent);
35454 - serial->open_count--;
35455 + local_dec(&serial->open_count);
35456 kref_put(&serial->parent->ref, hso_serial_ref_free);
35457 }
35458 } else {
35459 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35460
35461 /* reset the rts and dtr */
35462 /* do the actual close */
35463 - serial->open_count--;
35464 + local_dec(&serial->open_count);
35465
35466 - if (serial->open_count <= 0) {
35467 - serial->open_count = 0;
35468 + if (local_read(&serial->open_count) <= 0) {
35469 + local_set(&serial->open_count, 0);
35470 spin_lock_irq(&serial->serial_lock);
35471 if (serial->tty == tty) {
35472 serial->tty->driver_data = NULL;
35473 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35474
35475 /* the actual setup */
35476 spin_lock_irqsave(&serial->serial_lock, flags);
35477 - if (serial->open_count)
35478 + if (local_read(&serial->open_count))
35479 _hso_serial_set_termios(tty, old);
35480 else
35481 tty->termios = old;
35482 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35483 D1("Pending read interrupt on port %d\n", i);
35484 spin_lock(&serial->serial_lock);
35485 if (serial->rx_state == RX_IDLE &&
35486 - serial->open_count > 0) {
35487 + local_read(&serial->open_count) > 0) {
35488 /* Setup and send a ctrl req read on
35489 * port i */
35490 if (!serial->rx_urb_filled[0]) {
35491 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35492 /* Start all serial ports */
35493 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35494 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35495 - if (dev2ser(serial_table[i])->open_count) {
35496 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35497 result =
35498 hso_start_serial_device(serial_table[i], GFP_NOIO);
35499 hso_kick_transmit(dev2ser(serial_table[i]));
35500 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35501 index efc0111..79c8f5b 100644
35502 --- a/drivers/net/wireless/ath/ath.h
35503 +++ b/drivers/net/wireless/ath/ath.h
35504 @@ -119,6 +119,7 @@ struct ath_ops {
35505 void (*write_flush) (void *);
35506 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35507 };
35508 +typedef struct ath_ops __no_const ath_ops_no_const;
35509
35510 struct ath_common;
35511 struct ath_bus_ops;
35512 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35513 index 8c5ce8b..abf101b 100644
35514 --- a/drivers/net/wireless/ath/ath5k/debug.c
35515 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35516 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35517
35518 static ssize_t write_file_debug(struct file *file,
35519 const char __user *userbuf,
35520 + size_t count, loff_t *ppos) __size_overflow(3);
35521 +static ssize_t write_file_debug(struct file *file,
35522 + const char __user *userbuf,
35523 size_t count, loff_t *ppos)
35524 {
35525 struct ath5k_hw *ah = file->private_data;
35526 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35527 index 7b6417b..ab5db98 100644
35528 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35529 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35530 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35531 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35532 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35533
35534 - ACCESS_ONCE(ads->ds_link) = i->link;
35535 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35536 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35537 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35538
35539 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35540 ctl6 = SM(i->keytype, AR_EncrType);
35541 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35542
35543 if ((i->is_first || i->is_last) &&
35544 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35545 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35546 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35547 | set11nTries(i->rates, 1)
35548 | set11nTries(i->rates, 2)
35549 | set11nTries(i->rates, 3)
35550 | (i->dur_update ? AR_DurUpdateEna : 0)
35551 | SM(0, AR_BurstDur);
35552
35553 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35554 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35555 | set11nRate(i->rates, 1)
35556 | set11nRate(i->rates, 2)
35557 | set11nRate(i->rates, 3);
35558 } else {
35559 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35560 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35561 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35562 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35563 }
35564
35565 if (!i->is_first) {
35566 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35567 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35568 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35569 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35570 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35571 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35572 return;
35573 }
35574
35575 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35576 break;
35577 }
35578
35579 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35580 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35581 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35582 | SM(i->txpower, AR_XmitPower)
35583 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35584 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35585 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35586 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35587
35588 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35589 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35590 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35591 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35592
35593 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35594 return;
35595
35596 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35597 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35598 | set11nPktDurRTSCTS(i->rates, 1);
35599
35600 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35601 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35602 | set11nPktDurRTSCTS(i->rates, 3);
35603
35604 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35605 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35606 | set11nRateFlags(i->rates, 1)
35607 | set11nRateFlags(i->rates, 2)
35608 | set11nRateFlags(i->rates, 3)
35609 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35610 index 09b8c9d..905339e 100644
35611 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35612 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35613 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35614 (i->qcu << AR_TxQcuNum_S) | 0x17;
35615
35616 checksum += val;
35617 - ACCESS_ONCE(ads->info) = val;
35618 + ACCESS_ONCE_RW(ads->info) = val;
35619
35620 checksum += i->link;
35621 - ACCESS_ONCE(ads->link) = i->link;
35622 + ACCESS_ONCE_RW(ads->link) = i->link;
35623
35624 checksum += i->buf_addr[0];
35625 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35626 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35627 checksum += i->buf_addr[1];
35628 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35629 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35630 checksum += i->buf_addr[2];
35631 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35632 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35633 checksum += i->buf_addr[3];
35634 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35635 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35636
35637 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35638 - ACCESS_ONCE(ads->ctl3) = val;
35639 + ACCESS_ONCE_RW(ads->ctl3) = val;
35640 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35641 - ACCESS_ONCE(ads->ctl5) = val;
35642 + ACCESS_ONCE_RW(ads->ctl5) = val;
35643 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35644 - ACCESS_ONCE(ads->ctl7) = val;
35645 + ACCESS_ONCE_RW(ads->ctl7) = val;
35646 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35647 - ACCESS_ONCE(ads->ctl9) = val;
35648 + ACCESS_ONCE_RW(ads->ctl9) = val;
35649
35650 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35651 - ACCESS_ONCE(ads->ctl10) = checksum;
35652 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35653
35654 if (i->is_first || i->is_last) {
35655 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35656 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35657 | set11nTries(i->rates, 1)
35658 | set11nTries(i->rates, 2)
35659 | set11nTries(i->rates, 3)
35660 | (i->dur_update ? AR_DurUpdateEna : 0)
35661 | SM(0, AR_BurstDur);
35662
35663 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35664 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35665 | set11nRate(i->rates, 1)
35666 | set11nRate(i->rates, 2)
35667 | set11nRate(i->rates, 3);
35668 } else {
35669 - ACCESS_ONCE(ads->ctl13) = 0;
35670 - ACCESS_ONCE(ads->ctl14) = 0;
35671 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35672 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35673 }
35674
35675 ads->ctl20 = 0;
35676 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35677
35678 ctl17 = SM(i->keytype, AR_EncrType);
35679 if (!i->is_first) {
35680 - ACCESS_ONCE(ads->ctl11) = 0;
35681 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35682 - ACCESS_ONCE(ads->ctl15) = 0;
35683 - ACCESS_ONCE(ads->ctl16) = 0;
35684 - ACCESS_ONCE(ads->ctl17) = ctl17;
35685 - ACCESS_ONCE(ads->ctl18) = 0;
35686 - ACCESS_ONCE(ads->ctl19) = 0;
35687 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35688 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35689 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35690 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35691 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35692 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35693 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35694 return;
35695 }
35696
35697 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35698 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35699 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35700 | SM(i->txpower, AR_XmitPower)
35701 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35702 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35703 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35704 ctl12 |= SM(val, AR_PAPRDChainMask);
35705
35706 - ACCESS_ONCE(ads->ctl12) = ctl12;
35707 - ACCESS_ONCE(ads->ctl17) = ctl17;
35708 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35709 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35710
35711 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35712 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35713 | set11nPktDurRTSCTS(i->rates, 1);
35714
35715 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35716 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35717 | set11nPktDurRTSCTS(i->rates, 3);
35718
35719 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35720 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35721 | set11nRateFlags(i->rates, 1)
35722 | set11nRateFlags(i->rates, 2)
35723 | set11nRateFlags(i->rates, 3)
35724 | SM(i->rtscts_rate, AR_RTSCTSRate);
35725
35726 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35727 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35728 }
35729
35730 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35731 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
35732 index 68d972b..1d9205b 100644
35733 --- a/drivers/net/wireless/ath/ath9k/debug.c
35734 +++ b/drivers/net/wireless/ath/ath9k/debug.c
35735 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35736 }
35737
35738 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35739 + size_t count, loff_t *ppos) __size_overflow(3);
35740 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35741 size_t count, loff_t *ppos)
35742 {
35743 struct ath_softc *sc = file->private_data;
35744 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35745 index d3ff33c..c98bcda 100644
35746 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35747 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35748 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35749 }
35750
35751 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35752 + size_t count, loff_t *ppos) __size_overflow(3);
35753 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35754 size_t count, loff_t *ppos)
35755 {
35756 struct ath9k_htc_priv *priv = file->private_data;
35757 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35758 index c8261d4..8d88929 100644
35759 --- a/drivers/net/wireless/ath/ath9k/hw.h
35760 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35761 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35762
35763 /* ANI */
35764 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35765 -};
35766 +} __no_const;
35767
35768 /**
35769 * struct ath_hw_ops - callbacks used by hardware code and driver code
35770 @@ -803,7 +803,7 @@ struct ath_hw_ops {
35771 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35772 struct ath_hw_antcomb_conf *antconf);
35773
35774 -};
35775 +} __no_const;
35776
35777 struct ath_nf_limits {
35778 s16 max;
35779 @@ -823,7 +823,7 @@ enum ath_cal_list {
35780 #define AH_FASTCC 0x4
35781
35782 struct ath_hw {
35783 - struct ath_ops reg_ops;
35784 + ath_ops_no_const reg_ops;
35785
35786 struct ieee80211_hw *hw;
35787 struct ath_common common;
35788 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35789 index af00e2c..ab04d34 100644
35790 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35791 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35792 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35793 void (*carrsuppr)(struct brcms_phy *);
35794 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35795 void (*detach)(struct brcms_phy *);
35796 -};
35797 +} __no_const;
35798
35799 struct brcms_phy {
35800 struct brcms_phy_pub pubpi_ro;
35801 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35802 index a2ec369..36fdf14 100644
35803 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35804 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35805 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35806 */
35807 if (il3945_mod_params.disable_hw_scan) {
35808 D_INFO("Disabling hw_scan\n");
35809 - il3945_hw_ops.hw_scan = NULL;
35810 + pax_open_kernel();
35811 + *(void **)&il3945_hw_ops.hw_scan = NULL;
35812 + pax_close_kernel();
35813 }
35814
35815 D_INFO("*** LOAD DRIVER ***\n");
35816 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35817 index f8fc239..8cade22 100644
35818 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35819 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35820 @@ -86,8 +86,8 @@ do { \
35821 } while (0)
35822
35823 #else
35824 -#define IWL_DEBUG(m, level, fmt, args...)
35825 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35826 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35827 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35828 #define iwl_print_hex_dump(m, level, p, len)
35829 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35830 do { \
35831 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35832 index 4b9e730..7603659 100644
35833 --- a/drivers/net/wireless/mac80211_hwsim.c
35834 +++ b/drivers/net/wireless/mac80211_hwsim.c
35835 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35836 return -EINVAL;
35837
35838 if (fake_hw_scan) {
35839 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35840 - mac80211_hwsim_ops.sw_scan_start = NULL;
35841 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35842 + pax_open_kernel();
35843 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35844 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35845 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35846 + pax_close_kernel();
35847 }
35848
35849 spin_lock_init(&hwsim_radio_lock);
35850 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35851 index 3186aa4..b35b09f 100644
35852 --- a/drivers/net/wireless/mwifiex/main.h
35853 +++ b/drivers/net/wireless/mwifiex/main.h
35854 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35855 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35856 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35857 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35858 -};
35859 +} __no_const;
35860
35861 struct mwifiex_adapter {
35862 u8 iface_type;
35863 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35864 index a330c69..a81540f 100644
35865 --- a/drivers/net/wireless/rndis_wlan.c
35866 +++ b/drivers/net/wireless/rndis_wlan.c
35867 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35868
35869 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35870
35871 - if (rts_threshold < 0 || rts_threshold > 2347)
35872 + if (rts_threshold > 2347)
35873 rts_threshold = 2347;
35874
35875 tmp = cpu_to_le32(rts_threshold);
35876 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35877 index a77f1bb..c608b2b 100644
35878 --- a/drivers/net/wireless/wl1251/wl1251.h
35879 +++ b/drivers/net/wireless/wl1251/wl1251.h
35880 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35881 void (*reset)(struct wl1251 *wl);
35882 void (*enable_irq)(struct wl1251 *wl);
35883 void (*disable_irq)(struct wl1251 *wl);
35884 -};
35885 +} __no_const;
35886
35887 struct wl1251 {
35888 struct ieee80211_hw *hw;
35889 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35890 index f34b5b2..b5abb9f 100644
35891 --- a/drivers/oprofile/buffer_sync.c
35892 +++ b/drivers/oprofile/buffer_sync.c
35893 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35894 if (cookie == NO_COOKIE)
35895 offset = pc;
35896 if (cookie == INVALID_COOKIE) {
35897 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35898 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35899 offset = pc;
35900 }
35901 if (cookie != last_cookie) {
35902 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35903 /* add userspace sample */
35904
35905 if (!mm) {
35906 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35907 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35908 return 0;
35909 }
35910
35911 cookie = lookup_dcookie(mm, s->eip, &offset);
35912
35913 if (cookie == INVALID_COOKIE) {
35914 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35915 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35916 return 0;
35917 }
35918
35919 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35920 /* ignore backtraces if failed to add a sample */
35921 if (state == sb_bt_start) {
35922 state = sb_bt_ignore;
35923 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35924 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35925 }
35926 }
35927 release_mm(mm);
35928 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35929 index c0cc4e7..44d4e54 100644
35930 --- a/drivers/oprofile/event_buffer.c
35931 +++ b/drivers/oprofile/event_buffer.c
35932 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35933 }
35934
35935 if (buffer_pos == buffer_size) {
35936 - atomic_inc(&oprofile_stats.event_lost_overflow);
35937 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35938 return;
35939 }
35940
35941 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35942 index ed2c3ec..deda85a 100644
35943 --- a/drivers/oprofile/oprof.c
35944 +++ b/drivers/oprofile/oprof.c
35945 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35946 if (oprofile_ops.switch_events())
35947 return;
35948
35949 - atomic_inc(&oprofile_stats.multiplex_counter);
35950 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35951 start_switch_worker();
35952 }
35953
35954 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
35955 index 84a208d..f07d177 100644
35956 --- a/drivers/oprofile/oprofile_files.c
35957 +++ b/drivers/oprofile/oprofile_files.c
35958 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
35959
35960
35961 static ssize_t timeout_write(struct file *file, char const __user *buf,
35962 + size_t count, loff_t *offset) __size_overflow(3);
35963 +static ssize_t timeout_write(struct file *file, char const __user *buf,
35964 size_t count, loff_t *offset)
35965 {
35966 unsigned long val;
35967 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
35968 }
35969
35970
35971 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35972 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35973 {
35974 unsigned long val;
35975 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
35976 };
35977
35978
35979 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35980 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
35981 {
35982 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
35983 }
35984
35985
35986 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35987 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35988 {
35989 unsigned long val;
35990 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35991 index 917d28e..d62d981 100644
35992 --- a/drivers/oprofile/oprofile_stats.c
35993 +++ b/drivers/oprofile/oprofile_stats.c
35994 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35995 cpu_buf->sample_invalid_eip = 0;
35996 }
35997
35998 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35999 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36000 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36001 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36002 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36003 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36004 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36005 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36006 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36007 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36008 }
36009
36010
36011 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36012 index 38b6fc0..b5cbfce 100644
36013 --- a/drivers/oprofile/oprofile_stats.h
36014 +++ b/drivers/oprofile/oprofile_stats.h
36015 @@ -13,11 +13,11 @@
36016 #include <linux/atomic.h>
36017
36018 struct oprofile_stat_struct {
36019 - atomic_t sample_lost_no_mm;
36020 - atomic_t sample_lost_no_mapping;
36021 - atomic_t bt_lost_no_mapping;
36022 - atomic_t event_lost_overflow;
36023 - atomic_t multiplex_counter;
36024 + atomic_unchecked_t sample_lost_no_mm;
36025 + atomic_unchecked_t sample_lost_no_mapping;
36026 + atomic_unchecked_t bt_lost_no_mapping;
36027 + atomic_unchecked_t event_lost_overflow;
36028 + atomic_unchecked_t multiplex_counter;
36029 };
36030
36031 extern struct oprofile_stat_struct oprofile_stats;
36032 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36033 index 2f0aa0f..d5246c3 100644
36034 --- a/drivers/oprofile/oprofilefs.c
36035 +++ b/drivers/oprofile/oprofilefs.c
36036 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
36037 }
36038
36039
36040 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36041 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36042 {
36043 unsigned long value;
36044 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
36045
36046
36047 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36048 - char const *name, atomic_t *val)
36049 + char const *name, atomic_unchecked_t *val)
36050 {
36051 return __oprofilefs_create_file(sb, root, name,
36052 &atomic_ro_fops, 0444, val);
36053 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36054 index 3f56bc0..707d642 100644
36055 --- a/drivers/parport/procfs.c
36056 +++ b/drivers/parport/procfs.c
36057 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36058
36059 *ppos += len;
36060
36061 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36062 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36063 }
36064
36065 #ifdef CONFIG_PARPORT_1284
36066 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36067
36068 *ppos += len;
36069
36070 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36071 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36072 }
36073 #endif /* IEEE1284.3 support. */
36074
36075 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36076 index 9fff878..ad0ad53 100644
36077 --- a/drivers/pci/hotplug/cpci_hotplug.h
36078 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36079 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36080 int (*hardware_test) (struct slot* slot, u32 value);
36081 u8 (*get_power) (struct slot* slot);
36082 int (*set_power) (struct slot* slot, int value);
36083 -};
36084 +} __no_const;
36085
36086 struct cpci_hp_controller {
36087 unsigned int irq;
36088 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36089 index 76ba8a1..20ca857 100644
36090 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36091 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36092 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36093
36094 void compaq_nvram_init (void __iomem *rom_start)
36095 {
36096 +
36097 +#ifndef CONFIG_PAX_KERNEXEC
36098 if (rom_start) {
36099 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36100 }
36101 +#endif
36102 +
36103 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36104
36105 /* initialize our int15 lock */
36106 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36107 index 2275162..95f1a92 100644
36108 --- a/drivers/pci/pcie/aspm.c
36109 +++ b/drivers/pci/pcie/aspm.c
36110 @@ -27,9 +27,9 @@
36111 #define MODULE_PARAM_PREFIX "pcie_aspm."
36112
36113 /* Note: those are not register definitions */
36114 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36115 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36116 -#define ASPM_STATE_L1 (4) /* L1 state */
36117 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36118 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36119 +#define ASPM_STATE_L1 (4U) /* L1 state */
36120 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36121 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36122
36123 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36124 index 71eac9c..2de27ef 100644
36125 --- a/drivers/pci/probe.c
36126 +++ b/drivers/pci/probe.c
36127 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36128 u32 l, sz, mask;
36129 u16 orig_cmd;
36130
36131 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36132 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36133
36134 if (!dev->mmio_always_on) {
36135 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36136 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36137 index 27911b5..5b6db88 100644
36138 --- a/drivers/pci/proc.c
36139 +++ b/drivers/pci/proc.c
36140 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36141 static int __init pci_proc_init(void)
36142 {
36143 struct pci_dev *dev = NULL;
36144 +
36145 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36146 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36147 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36148 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36149 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36150 +#endif
36151 +#else
36152 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36153 +#endif
36154 proc_create("devices", 0, proc_bus_pci_dir,
36155 &proc_bus_pci_dev_operations);
36156 proc_initialized = 1;
36157 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36158 index 6f966d6..68e18ed 100644
36159 --- a/drivers/platform/x86/asus_acpi.c
36160 +++ b/drivers/platform/x86/asus_acpi.c
36161 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36162 }
36163
36164 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36165 + size_t count, loff_t *pos) __size_overflow(3);
36166 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36167 size_t count, loff_t *pos)
36168 {
36169 int rv, value;
36170 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36171 index ea0c607..58c4628 100644
36172 --- a/drivers/platform/x86/thinkpad_acpi.c
36173 +++ b/drivers/platform/x86/thinkpad_acpi.c
36174 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36175 return 0;
36176 }
36177
36178 -void static hotkey_mask_warn_incomplete_mask(void)
36179 +static void hotkey_mask_warn_incomplete_mask(void)
36180 {
36181 /* log only what the user can fix... */
36182 const u32 wantedmask = hotkey_driver_mask &
36183 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
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 -
36192 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36193 do { \
36194 if ((event_mask & (1 << __scancode)) && \
36195 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36196 tpacpi_hotkey_send_key(__scancode); \
36197 } while (0)
36198
36199 - void issue_volchange(const unsigned int oldvol,
36200 - const unsigned int newvol)
36201 - {
36202 - unsigned int i = oldvol;
36203 +static void issue_volchange(const unsigned int oldvol,
36204 + const unsigned int newvol,
36205 + const u32 event_mask)
36206 +{
36207 + unsigned int i = oldvol;
36208
36209 - while (i > newvol) {
36210 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36211 - i--;
36212 - }
36213 - while (i < newvol) {
36214 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36215 - i++;
36216 - }
36217 + while (i > newvol) {
36218 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36219 + i--;
36220 }
36221 + while (i < newvol) {
36222 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36223 + i++;
36224 + }
36225 +}
36226
36227 - void issue_brightnesschange(const unsigned int oldbrt,
36228 - const unsigned int newbrt)
36229 - {
36230 - unsigned int i = oldbrt;
36231 +static void issue_brightnesschange(const unsigned int oldbrt,
36232 + const unsigned int newbrt,
36233 + const u32 event_mask)
36234 +{
36235 + unsigned int i = oldbrt;
36236
36237 - while (i > newbrt) {
36238 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36239 - i--;
36240 - }
36241 - while (i < newbrt) {
36242 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36243 - i++;
36244 - }
36245 + while (i > newbrt) {
36246 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36247 + i--;
36248 + }
36249 + while (i < newbrt) {
36250 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36251 + i++;
36252 }
36253 +}
36254
36255 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36256 + struct tp_nvram_state *newn,
36257 + const u32 event_mask)
36258 +{
36259 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36260 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36261 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36262 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36263 oldn->volume_level != newn->volume_level) {
36264 /* recently muted, or repeated mute keypress, or
36265 * multiple presses ending in mute */
36266 - issue_volchange(oldn->volume_level, newn->volume_level);
36267 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36268 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36269 }
36270 } else {
36271 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36272 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36273 }
36274 if (oldn->volume_level != newn->volume_level) {
36275 - issue_volchange(oldn->volume_level, newn->volume_level);
36276 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36277 } else if (oldn->volume_toggle != newn->volume_toggle) {
36278 /* repeated vol up/down keypress at end of scale ? */
36279 if (newn->volume_level == 0)
36280 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36281 /* handle brightness */
36282 if (oldn->brightness_level != newn->brightness_level) {
36283 issue_brightnesschange(oldn->brightness_level,
36284 - newn->brightness_level);
36285 + newn->brightness_level,
36286 + event_mask);
36287 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36288 /* repeated key presses that didn't change state */
36289 if (newn->brightness_level == 0)
36290 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36291 && !tp_features.bright_unkfw)
36292 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36293 }
36294 +}
36295
36296 #undef TPACPI_COMPARE_KEY
36297 #undef TPACPI_MAY_SEND_KEY
36298 -}
36299
36300 /*
36301 * Polling driver
36302 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36303 index dcdc1f4..85cee16 100644
36304 --- a/drivers/platform/x86/toshiba_acpi.c
36305 +++ b/drivers/platform/x86/toshiba_acpi.c
36306 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36307 }
36308
36309 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36310 + size_t count, loff_t *pos) __size_overflow(3);
36311 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36312 size_t count, loff_t *pos)
36313 {
36314 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36315 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36316 index b859d16..5cc6b1a 100644
36317 --- a/drivers/pnp/pnpbios/bioscalls.c
36318 +++ b/drivers/pnp/pnpbios/bioscalls.c
36319 @@ -59,7 +59,7 @@ do { \
36320 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36321 } while(0)
36322
36323 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36324 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36325 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36326
36327 /*
36328 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36329
36330 cpu = get_cpu();
36331 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36332 +
36333 + pax_open_kernel();
36334 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36335 + pax_close_kernel();
36336
36337 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36338 spin_lock_irqsave(&pnp_bios_lock, flags);
36339 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36340 :"memory");
36341 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36342
36343 + pax_open_kernel();
36344 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36345 + pax_close_kernel();
36346 +
36347 put_cpu();
36348
36349 /* If we get here and this is set then the PnP BIOS faulted on us. */
36350 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36351 return status;
36352 }
36353
36354 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36355 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36356 {
36357 int i;
36358
36359 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36360 pnp_bios_callpoint.offset = header->fields.pm16offset;
36361 pnp_bios_callpoint.segment = PNP_CS16;
36362
36363 + pax_open_kernel();
36364 +
36365 for_each_possible_cpu(i) {
36366 struct desc_struct *gdt = get_cpu_gdt_table(i);
36367 if (!gdt)
36368 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36369 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36370 (unsigned long)__va(header->fields.pm16dseg));
36371 }
36372 +
36373 + pax_close_kernel();
36374 }
36375 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36376 index b0ecacb..7c9da2e 100644
36377 --- a/drivers/pnp/resource.c
36378 +++ b/drivers/pnp/resource.c
36379 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36380 return 1;
36381
36382 /* check if the resource is valid */
36383 - if (*irq < 0 || *irq > 15)
36384 + if (*irq > 15)
36385 return 0;
36386
36387 /* check if the resource is reserved */
36388 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36389 return 1;
36390
36391 /* check if the resource is valid */
36392 - if (*dma < 0 || *dma == 4 || *dma > 7)
36393 + if (*dma == 4 || *dma > 7)
36394 return 0;
36395
36396 /* check if the resource is reserved */
36397 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36398 index 1ed6ea0..77c0bd2 100644
36399 --- a/drivers/power/bq27x00_battery.c
36400 +++ b/drivers/power/bq27x00_battery.c
36401 @@ -72,7 +72,7 @@
36402 struct bq27x00_device_info;
36403 struct bq27x00_access_methods {
36404 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36405 -};
36406 +} __no_const;
36407
36408 enum bq27x00_chip { BQ27000, BQ27500 };
36409
36410 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36411 index a838e66..a9e1665 100644
36412 --- a/drivers/regulator/max8660.c
36413 +++ b/drivers/regulator/max8660.c
36414 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36415 max8660->shadow_regs[MAX8660_OVER1] = 5;
36416 } else {
36417 /* Otherwise devices can be toggled via software */
36418 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36419 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36420 + pax_open_kernel();
36421 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36422 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36423 + pax_close_kernel();
36424 }
36425
36426 /*
36427 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36428 index e8cfc99..072aee2 100644
36429 --- a/drivers/regulator/mc13892-regulator.c
36430 +++ b/drivers/regulator/mc13892-regulator.c
36431 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36432 }
36433 mc13xxx_unlock(mc13892);
36434
36435 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36436 + pax_open_kernel();
36437 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36438 = mc13892_vcam_set_mode;
36439 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36440 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36441 = mc13892_vcam_get_mode;
36442 + pax_close_kernel();
36443
36444 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36445 ARRAY_SIZE(mc13892_regulators));
36446 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36447 index cace6d3..f623fda 100644
36448 --- a/drivers/rtc/rtc-dev.c
36449 +++ b/drivers/rtc/rtc-dev.c
36450 @@ -14,6 +14,7 @@
36451 #include <linux/module.h>
36452 #include <linux/rtc.h>
36453 #include <linux/sched.h>
36454 +#include <linux/grsecurity.h>
36455 #include "rtc-core.h"
36456
36457 static dev_t rtc_devt;
36458 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36459 if (copy_from_user(&tm, uarg, sizeof(tm)))
36460 return -EFAULT;
36461
36462 + gr_log_timechange();
36463 +
36464 return rtc_set_time(rtc, &tm);
36465
36466 case RTC_PIE_ON:
36467 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36468 index ffb5878..e6d785c 100644
36469 --- a/drivers/scsi/aacraid/aacraid.h
36470 +++ b/drivers/scsi/aacraid/aacraid.h
36471 @@ -492,7 +492,7 @@ struct adapter_ops
36472 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36473 /* Administrative operations */
36474 int (*adapter_comm)(struct aac_dev * dev, int comm);
36475 -};
36476 +} __no_const;
36477
36478 /*
36479 * Define which interrupt handler needs to be installed
36480 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36481 index 705e13e..91c873c 100644
36482 --- a/drivers/scsi/aacraid/linit.c
36483 +++ b/drivers/scsi/aacraid/linit.c
36484 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36485 #elif defined(__devinitconst)
36486 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36487 #else
36488 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36489 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36490 #endif
36491 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36492 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36493 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36494 index d5ff142..49c0ebb 100644
36495 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36496 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36497 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36498 .lldd_control_phy = asd_control_phy,
36499 };
36500
36501 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36502 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36503 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36504 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36505 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36506 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36507 index a796de9..1ef20e1 100644
36508 --- a/drivers/scsi/bfa/bfa.h
36509 +++ b/drivers/scsi/bfa/bfa.h
36510 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36511 u32 *end);
36512 int cpe_vec_q0;
36513 int rme_vec_q0;
36514 -};
36515 +} __no_const;
36516 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36517
36518 struct bfa_faa_cbfn_s {
36519 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36520 index f0f80e2..8ec946b 100644
36521 --- a/drivers/scsi/bfa/bfa_fcpim.c
36522 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36523 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36524
36525 bfa_iotag_attach(fcp);
36526
36527 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36528 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36529 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36530 (fcp->num_itns * sizeof(struct bfa_itn_s));
36531 memset(fcp->itn_arr, 0,
36532 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36533 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36534 {
36535 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36536 - struct bfa_itn_s *itn;
36537 + bfa_itn_s_no_const *itn;
36538
36539 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36540 itn->isr = isr;
36541 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36542 index 36f26da..38a34a8 100644
36543 --- a/drivers/scsi/bfa/bfa_fcpim.h
36544 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36545 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36546 struct bfa_itn_s {
36547 bfa_isr_func_t isr;
36548 };
36549 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36550
36551 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36552 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36553 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36554 struct list_head iotag_tio_free_q; /* free IO resources */
36555 struct list_head iotag_unused_q; /* unused IO resources*/
36556 struct bfa_iotag_s *iotag_arr;
36557 - struct bfa_itn_s *itn_arr;
36558 + bfa_itn_s_no_const *itn_arr;
36559 int num_ioim_reqs;
36560 int num_fwtio_reqs;
36561 int num_itns;
36562 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36563 index 546d46b..642fa5b 100644
36564 --- a/drivers/scsi/bfa/bfa_ioc.h
36565 +++ b/drivers/scsi/bfa/bfa_ioc.h
36566 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36567 bfa_ioc_disable_cbfn_t disable_cbfn;
36568 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36569 bfa_ioc_reset_cbfn_t reset_cbfn;
36570 -};
36571 +} __no_const;
36572
36573 /*
36574 * IOC event notification mechanism.
36575 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36576 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36577 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36578 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36579 -};
36580 +} __no_const;
36581
36582 /*
36583 * Queue element to wait for room in request queue. FIFO order is
36584 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36585 index 351dc0b..951dc32 100644
36586 --- a/drivers/scsi/hosts.c
36587 +++ b/drivers/scsi/hosts.c
36588 @@ -42,7 +42,7 @@
36589 #include "scsi_logging.h"
36590
36591
36592 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36593 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36594
36595
36596 static void scsi_host_cls_release(struct device *dev)
36597 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36598 * subtract one because we increment first then return, but we need to
36599 * know what the next host number was before increment
36600 */
36601 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36602 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36603 shost->dma_channel = 0xff;
36604
36605 /* These three are default values which can be overridden */
36606 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36607 index b96962c..0c82ec2 100644
36608 --- a/drivers/scsi/hpsa.c
36609 +++ b/drivers/scsi/hpsa.c
36610 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36611 u32 a;
36612
36613 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36614 - return h->access.command_completed(h);
36615 + return h->access->command_completed(h);
36616
36617 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36618 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36619 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36620 while (!list_empty(&h->reqQ)) {
36621 c = list_entry(h->reqQ.next, struct CommandList, list);
36622 /* can't do anything if fifo is full */
36623 - if ((h->access.fifo_full(h))) {
36624 + if ((h->access->fifo_full(h))) {
36625 dev_warn(&h->pdev->dev, "fifo full\n");
36626 break;
36627 }
36628 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36629 h->Qdepth--;
36630
36631 /* Tell the controller execute command */
36632 - h->access.submit_command(h, c);
36633 + h->access->submit_command(h, c);
36634
36635 /* Put job onto the completed Q */
36636 addQ(&h->cmpQ, c);
36637 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36638
36639 static inline unsigned long get_next_completion(struct ctlr_info *h)
36640 {
36641 - return h->access.command_completed(h);
36642 + return h->access->command_completed(h);
36643 }
36644
36645 static inline bool interrupt_pending(struct ctlr_info *h)
36646 {
36647 - return h->access.intr_pending(h);
36648 + return h->access->intr_pending(h);
36649 }
36650
36651 static inline long interrupt_not_for_us(struct ctlr_info *h)
36652 {
36653 - return (h->access.intr_pending(h) == 0) ||
36654 + return (h->access->intr_pending(h) == 0) ||
36655 (h->interrupts_enabled == 0);
36656 }
36657
36658 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36659 if (prod_index < 0)
36660 return -ENODEV;
36661 h->product_name = products[prod_index].product_name;
36662 - h->access = *(products[prod_index].access);
36663 + h->access = products[prod_index].access;
36664
36665 if (hpsa_board_disabled(h->pdev)) {
36666 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36667 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36668
36669 assert_spin_locked(&lockup_detector_lock);
36670 remove_ctlr_from_lockup_detector_list(h);
36671 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36672 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36673 spin_lock_irqsave(&h->lock, flags);
36674 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36675 spin_unlock_irqrestore(&h->lock, flags);
36676 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36677 }
36678
36679 /* make sure the board interrupts are off */
36680 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36681 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36682
36683 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36684 goto clean2;
36685 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36686 * fake ones to scoop up any residual completions.
36687 */
36688 spin_lock_irqsave(&h->lock, flags);
36689 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36690 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36691 spin_unlock_irqrestore(&h->lock, flags);
36692 free_irq(h->intr[h->intr_mode], h);
36693 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36694 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36695 dev_info(&h->pdev->dev, "Board READY.\n");
36696 dev_info(&h->pdev->dev,
36697 "Waiting for stale completions to drain.\n");
36698 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36699 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36700 msleep(10000);
36701 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36702 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36703
36704 rc = controller_reset_failed(h->cfgtable);
36705 if (rc)
36706 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36707 }
36708
36709 /* Turn the interrupts on so we can service requests */
36710 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36711 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36712
36713 hpsa_hba_inquiry(h);
36714 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36715 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36716 * To write all data in the battery backed cache to disks
36717 */
36718 hpsa_flush_cache(h);
36719 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36720 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36721 free_irq(h->intr[h->intr_mode], h);
36722 #ifdef CONFIG_PCI_MSI
36723 if (h->msix_vector)
36724 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36725 return;
36726 }
36727 /* Change the access methods to the performant access methods */
36728 - h->access = SA5_performant_access;
36729 + h->access = &SA5_performant_access;
36730 h->transMethod = CFGTBL_Trans_Performant;
36731 }
36732
36733 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36734 index 91edafb..a9b88ec 100644
36735 --- a/drivers/scsi/hpsa.h
36736 +++ b/drivers/scsi/hpsa.h
36737 @@ -73,7 +73,7 @@ struct ctlr_info {
36738 unsigned int msix_vector;
36739 unsigned int msi_vector;
36740 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36741 - struct access_method access;
36742 + struct access_method *access;
36743
36744 /* queue and queue Info */
36745 struct list_head reqQ;
36746 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36747 index f2df059..a3a9930 100644
36748 --- a/drivers/scsi/ips.h
36749 +++ b/drivers/scsi/ips.h
36750 @@ -1027,7 +1027,7 @@ typedef struct {
36751 int (*intr)(struct ips_ha *);
36752 void (*enableint)(struct ips_ha *);
36753 uint32_t (*statupd)(struct ips_ha *);
36754 -} ips_hw_func_t;
36755 +} __no_const ips_hw_func_t;
36756
36757 typedef struct ips_ha {
36758 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36759 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36760 index 4d70d96..84d0573 100644
36761 --- a/drivers/scsi/libfc/fc_exch.c
36762 +++ b/drivers/scsi/libfc/fc_exch.c
36763 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36764 * all together if not used XXX
36765 */
36766 struct {
36767 - atomic_t no_free_exch;
36768 - atomic_t no_free_exch_xid;
36769 - atomic_t xid_not_found;
36770 - atomic_t xid_busy;
36771 - atomic_t seq_not_found;
36772 - atomic_t non_bls_resp;
36773 + atomic_unchecked_t no_free_exch;
36774 + atomic_unchecked_t no_free_exch_xid;
36775 + atomic_unchecked_t xid_not_found;
36776 + atomic_unchecked_t xid_busy;
36777 + atomic_unchecked_t seq_not_found;
36778 + atomic_unchecked_t non_bls_resp;
36779 } stats;
36780 };
36781
36782 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36783 /* allocate memory for exchange */
36784 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36785 if (!ep) {
36786 - atomic_inc(&mp->stats.no_free_exch);
36787 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36788 goto out;
36789 }
36790 memset(ep, 0, sizeof(*ep));
36791 @@ -780,7 +780,7 @@ out:
36792 return ep;
36793 err:
36794 spin_unlock_bh(&pool->lock);
36795 - atomic_inc(&mp->stats.no_free_exch_xid);
36796 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36797 mempool_free(ep, mp->ep_pool);
36798 return NULL;
36799 }
36800 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36801 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36802 ep = fc_exch_find(mp, xid);
36803 if (!ep) {
36804 - atomic_inc(&mp->stats.xid_not_found);
36805 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36806 reject = FC_RJT_OX_ID;
36807 goto out;
36808 }
36809 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36810 ep = fc_exch_find(mp, xid);
36811 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36812 if (ep) {
36813 - atomic_inc(&mp->stats.xid_busy);
36814 + atomic_inc_unchecked(&mp->stats.xid_busy);
36815 reject = FC_RJT_RX_ID;
36816 goto rel;
36817 }
36818 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36819 }
36820 xid = ep->xid; /* get our XID */
36821 } else if (!ep) {
36822 - atomic_inc(&mp->stats.xid_not_found);
36823 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36824 reject = FC_RJT_RX_ID; /* XID not found */
36825 goto out;
36826 }
36827 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36828 } else {
36829 sp = &ep->seq;
36830 if (sp->id != fh->fh_seq_id) {
36831 - atomic_inc(&mp->stats.seq_not_found);
36832 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36833 if (f_ctl & FC_FC_END_SEQ) {
36834 /*
36835 * Update sequence_id based on incoming last
36836 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36837
36838 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36839 if (!ep) {
36840 - atomic_inc(&mp->stats.xid_not_found);
36841 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36842 goto out;
36843 }
36844 if (ep->esb_stat & ESB_ST_COMPLETE) {
36845 - atomic_inc(&mp->stats.xid_not_found);
36846 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36847 goto rel;
36848 }
36849 if (ep->rxid == FC_XID_UNKNOWN)
36850 ep->rxid = ntohs(fh->fh_rx_id);
36851 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36852 - atomic_inc(&mp->stats.xid_not_found);
36853 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36854 goto rel;
36855 }
36856 if (ep->did != ntoh24(fh->fh_s_id) &&
36857 ep->did != FC_FID_FLOGI) {
36858 - atomic_inc(&mp->stats.xid_not_found);
36859 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36860 goto rel;
36861 }
36862 sof = fr_sof(fp);
36863 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36864 sp->ssb_stat |= SSB_ST_RESP;
36865 sp->id = fh->fh_seq_id;
36866 } else if (sp->id != fh->fh_seq_id) {
36867 - atomic_inc(&mp->stats.seq_not_found);
36868 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36869 goto rel;
36870 }
36871
36872 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36873 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36874
36875 if (!sp)
36876 - atomic_inc(&mp->stats.xid_not_found);
36877 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36878 else
36879 - atomic_inc(&mp->stats.non_bls_resp);
36880 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36881
36882 fc_frame_free(fp);
36883 }
36884 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36885 index db9238f..4378ed2 100644
36886 --- a/drivers/scsi/libsas/sas_ata.c
36887 +++ b/drivers/scsi/libsas/sas_ata.c
36888 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36889 .postreset = ata_std_postreset,
36890 .error_handler = ata_std_error_handler,
36891 .post_internal_cmd = sas_ata_post_internal,
36892 - .qc_defer = ata_std_qc_defer,
36893 + .qc_defer = ata_std_qc_defer,
36894 .qc_prep = ata_noop_qc_prep,
36895 .qc_issue = sas_ata_qc_issue,
36896 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36897 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36898 index 825f930..ce42672 100644
36899 --- a/drivers/scsi/lpfc/lpfc.h
36900 +++ b/drivers/scsi/lpfc/lpfc.h
36901 @@ -413,7 +413,7 @@ struct lpfc_vport {
36902 struct dentry *debug_nodelist;
36903 struct dentry *vport_debugfs_root;
36904 struct lpfc_debugfs_trc *disc_trc;
36905 - atomic_t disc_trc_cnt;
36906 + atomic_unchecked_t disc_trc_cnt;
36907 #endif
36908 uint8_t stat_data_enabled;
36909 uint8_t stat_data_blocked;
36910 @@ -821,8 +821,8 @@ struct lpfc_hba {
36911 struct timer_list fabric_block_timer;
36912 unsigned long bit_flags;
36913 #define FABRIC_COMANDS_BLOCKED 0
36914 - atomic_t num_rsrc_err;
36915 - atomic_t num_cmd_success;
36916 + atomic_unchecked_t num_rsrc_err;
36917 + atomic_unchecked_t num_cmd_success;
36918 unsigned long last_rsrc_error_time;
36919 unsigned long last_ramp_down_time;
36920 unsigned long last_ramp_up_time;
36921 @@ -852,7 +852,7 @@ struct lpfc_hba {
36922
36923 struct dentry *debug_slow_ring_trc;
36924 struct lpfc_debugfs_trc *slow_ring_trc;
36925 - atomic_t slow_ring_trc_cnt;
36926 + atomic_unchecked_t slow_ring_trc_cnt;
36927 /* iDiag debugfs sub-directory */
36928 struct dentry *idiag_root;
36929 struct dentry *idiag_pci_cfg;
36930 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36931 index 3587a3f..d45b81b 100644
36932 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36933 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36934 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36935
36936 #include <linux/debugfs.h>
36937
36938 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36939 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36940 static unsigned long lpfc_debugfs_start_time = 0L;
36941
36942 /* iDiag */
36943 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36944 lpfc_debugfs_enable = 0;
36945
36946 len = 0;
36947 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36948 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36949 (lpfc_debugfs_max_disc_trc - 1);
36950 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36951 dtp = vport->disc_trc + i;
36952 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36953 lpfc_debugfs_enable = 0;
36954
36955 len = 0;
36956 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36957 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36958 (lpfc_debugfs_max_slow_ring_trc - 1);
36959 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36960 dtp = phba->slow_ring_trc + i;
36961 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36962 !vport || !vport->disc_trc)
36963 return;
36964
36965 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36966 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36967 (lpfc_debugfs_max_disc_trc - 1);
36968 dtp = vport->disc_trc + index;
36969 dtp->fmt = fmt;
36970 dtp->data1 = data1;
36971 dtp->data2 = data2;
36972 dtp->data3 = data3;
36973 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36974 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36975 dtp->jif = jiffies;
36976 #endif
36977 return;
36978 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36979 !phba || !phba->slow_ring_trc)
36980 return;
36981
36982 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36983 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36984 (lpfc_debugfs_max_slow_ring_trc - 1);
36985 dtp = phba->slow_ring_trc + index;
36986 dtp->fmt = fmt;
36987 dtp->data1 = data1;
36988 dtp->data2 = data2;
36989 dtp->data3 = data3;
36990 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36991 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36992 dtp->jif = jiffies;
36993 #endif
36994 return;
36995 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36996 "slow_ring buffer\n");
36997 goto debug_failed;
36998 }
36999 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37000 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37001 memset(phba->slow_ring_trc, 0,
37002 (sizeof(struct lpfc_debugfs_trc) *
37003 lpfc_debugfs_max_slow_ring_trc));
37004 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37005 "buffer\n");
37006 goto debug_failed;
37007 }
37008 - atomic_set(&vport->disc_trc_cnt, 0);
37009 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37010
37011 snprintf(name, sizeof(name), "discovery_trace");
37012 vport->debug_disc_trc =
37013 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37014 index dfea2da..8e17227 100644
37015 --- a/drivers/scsi/lpfc/lpfc_init.c
37016 +++ b/drivers/scsi/lpfc/lpfc_init.c
37017 @@ -10145,8 +10145,10 @@ lpfc_init(void)
37018 printk(LPFC_COPYRIGHT "\n");
37019
37020 if (lpfc_enable_npiv) {
37021 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37022 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37023 + pax_open_kernel();
37024 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37025 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37026 + pax_close_kernel();
37027 }
37028 lpfc_transport_template =
37029 fc_attach_transport(&lpfc_transport_functions);
37030 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37031 index c60f5d0..751535c 100644
37032 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37033 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37034 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37035 uint32_t evt_posted;
37036
37037 spin_lock_irqsave(&phba->hbalock, flags);
37038 - atomic_inc(&phba->num_rsrc_err);
37039 + atomic_inc_unchecked(&phba->num_rsrc_err);
37040 phba->last_rsrc_error_time = jiffies;
37041
37042 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37043 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37044 unsigned long flags;
37045 struct lpfc_hba *phba = vport->phba;
37046 uint32_t evt_posted;
37047 - atomic_inc(&phba->num_cmd_success);
37048 + atomic_inc_unchecked(&phba->num_cmd_success);
37049
37050 if (vport->cfg_lun_queue_depth <= queue_depth)
37051 return;
37052 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37053 unsigned long num_rsrc_err, num_cmd_success;
37054 int i;
37055
37056 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37057 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37058 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37059 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37060
37061 vports = lpfc_create_vport_work_array(phba);
37062 if (vports != NULL)
37063 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37064 }
37065 }
37066 lpfc_destroy_vport_work_array(phba, vports);
37067 - atomic_set(&phba->num_rsrc_err, 0);
37068 - atomic_set(&phba->num_cmd_success, 0);
37069 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37070 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37071 }
37072
37073 /**
37074 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37075 }
37076 }
37077 lpfc_destroy_vport_work_array(phba, vports);
37078 - atomic_set(&phba->num_rsrc_err, 0);
37079 - atomic_set(&phba->num_cmd_success, 0);
37080 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37081 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37082 }
37083
37084 /**
37085 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37086 index ea8a0b4..812a124 100644
37087 --- a/drivers/scsi/pmcraid.c
37088 +++ b/drivers/scsi/pmcraid.c
37089 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37090 res->scsi_dev = scsi_dev;
37091 scsi_dev->hostdata = res;
37092 res->change_detected = 0;
37093 - atomic_set(&res->read_failures, 0);
37094 - atomic_set(&res->write_failures, 0);
37095 + atomic_set_unchecked(&res->read_failures, 0);
37096 + atomic_set_unchecked(&res->write_failures, 0);
37097 rc = 0;
37098 }
37099 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37100 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37101
37102 /* If this was a SCSI read/write command keep count of errors */
37103 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37104 - atomic_inc(&res->read_failures);
37105 + atomic_inc_unchecked(&res->read_failures);
37106 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37107 - atomic_inc(&res->write_failures);
37108 + atomic_inc_unchecked(&res->write_failures);
37109
37110 if (!RES_IS_GSCSI(res->cfg_entry) &&
37111 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37112 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37113 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37114 * hrrq_id assigned here in queuecommand
37115 */
37116 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37117 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37118 pinstance->num_hrrq;
37119 cmd->cmd_done = pmcraid_io_done;
37120
37121 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37122 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37123 * hrrq_id assigned here in queuecommand
37124 */
37125 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37126 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37127 pinstance->num_hrrq;
37128
37129 if (request_size) {
37130 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37131
37132 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37133 /* add resources only after host is added into system */
37134 - if (!atomic_read(&pinstance->expose_resources))
37135 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37136 return;
37137
37138 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37139 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37140 init_waitqueue_head(&pinstance->reset_wait_q);
37141
37142 atomic_set(&pinstance->outstanding_cmds, 0);
37143 - atomic_set(&pinstance->last_message_id, 0);
37144 - atomic_set(&pinstance->expose_resources, 0);
37145 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37146 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37147
37148 INIT_LIST_HEAD(&pinstance->free_res_q);
37149 INIT_LIST_HEAD(&pinstance->used_res_q);
37150 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37151 /* Schedule worker thread to handle CCN and take care of adding and
37152 * removing devices to OS
37153 */
37154 - atomic_set(&pinstance->expose_resources, 1);
37155 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37156 schedule_work(&pinstance->worker_q);
37157 return rc;
37158
37159 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37160 index ca496c7..9c791d5 100644
37161 --- a/drivers/scsi/pmcraid.h
37162 +++ b/drivers/scsi/pmcraid.h
37163 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37164 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37165
37166 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37167 - atomic_t last_message_id;
37168 + atomic_unchecked_t last_message_id;
37169
37170 /* configuration table */
37171 struct pmcraid_config_table *cfg_table;
37172 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37173 atomic_t outstanding_cmds;
37174
37175 /* should add/delete resources to mid-layer now ?*/
37176 - atomic_t expose_resources;
37177 + atomic_unchecked_t expose_resources;
37178
37179
37180
37181 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37182 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37183 };
37184 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37185 - atomic_t read_failures; /* count of failed READ commands */
37186 - atomic_t write_failures; /* count of failed WRITE commands */
37187 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37188 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37189
37190 /* To indicate add/delete/modify during CCN */
37191 u8 change_detected;
37192 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37193 index af1003f..be55a75 100644
37194 --- a/drivers/scsi/qla2xxx/qla_def.h
37195 +++ b/drivers/scsi/qla2xxx/qla_def.h
37196 @@ -2247,7 +2247,7 @@ struct isp_operations {
37197 int (*start_scsi) (srb_t *);
37198 int (*abort_isp) (struct scsi_qla_host *);
37199 int (*iospace_config)(struct qla_hw_data*);
37200 -};
37201 +} __no_const;
37202
37203 /* MSI-X Support *************************************************************/
37204
37205 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37206 index bfe6854..ceac088 100644
37207 --- a/drivers/scsi/qla4xxx/ql4_def.h
37208 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37209 @@ -261,7 +261,7 @@ struct ddb_entry {
37210 * (4000 only) */
37211 atomic_t relogin_timer; /* Max Time to wait for
37212 * relogin to complete */
37213 - atomic_t relogin_retry_count; /* Num of times relogin has been
37214 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37215 * retried */
37216 uint32_t default_time2wait; /* Default Min time between
37217 * relogins (+aens) */
37218 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37219 index ce6d3b7..73fac54 100644
37220 --- a/drivers/scsi/qla4xxx/ql4_os.c
37221 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37222 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37223 */
37224 if (!iscsi_is_session_online(cls_sess)) {
37225 /* Reset retry relogin timer */
37226 - atomic_inc(&ddb_entry->relogin_retry_count);
37227 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37228 DEBUG2(ql4_printk(KERN_INFO, ha,
37229 "%s: index[%d] relogin timed out-retrying"
37230 " relogin (%d), retry (%d)\n", __func__,
37231 ddb_entry->fw_ddb_index,
37232 - atomic_read(&ddb_entry->relogin_retry_count),
37233 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37234 ddb_entry->default_time2wait + 4));
37235 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37236 atomic_set(&ddb_entry->retry_relogin_timer,
37237 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37238
37239 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37240 atomic_set(&ddb_entry->relogin_timer, 0);
37241 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37242 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37243 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37244 ddb_entry->default_relogin_timeout =
37245 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37246 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37247 index 2aeb2e9..46e3925 100644
37248 --- a/drivers/scsi/scsi.c
37249 +++ b/drivers/scsi/scsi.c
37250 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37251 unsigned long timeout;
37252 int rtn = 0;
37253
37254 - atomic_inc(&cmd->device->iorequest_cnt);
37255 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37256
37257 /* check if the device is still usable */
37258 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37259 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37260 index b2c95db..227d74e 100644
37261 --- a/drivers/scsi/scsi_lib.c
37262 +++ b/drivers/scsi/scsi_lib.c
37263 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37264 shost = sdev->host;
37265 scsi_init_cmd_errh(cmd);
37266 cmd->result = DID_NO_CONNECT << 16;
37267 - atomic_inc(&cmd->device->iorequest_cnt);
37268 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37269
37270 /*
37271 * SCSI request completion path will do scsi_device_unbusy(),
37272 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37273
37274 INIT_LIST_HEAD(&cmd->eh_entry);
37275
37276 - atomic_inc(&cmd->device->iodone_cnt);
37277 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37278 if (cmd->result)
37279 - atomic_inc(&cmd->device->ioerr_cnt);
37280 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37281
37282 disposition = scsi_decide_disposition(cmd);
37283 if (disposition != SUCCESS &&
37284 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37285 index 04c2a27..9d8bd66 100644
37286 --- a/drivers/scsi/scsi_sysfs.c
37287 +++ b/drivers/scsi/scsi_sysfs.c
37288 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37289 char *buf) \
37290 { \
37291 struct scsi_device *sdev = to_scsi_device(dev); \
37292 - unsigned long long count = atomic_read(&sdev->field); \
37293 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37294 return snprintf(buf, 20, "0x%llx\n", count); \
37295 } \
37296 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37297 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37298 index 84a1fdf..693b0d6 100644
37299 --- a/drivers/scsi/scsi_tgt_lib.c
37300 +++ b/drivers/scsi/scsi_tgt_lib.c
37301 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37302 int err;
37303
37304 dprintk("%lx %u\n", uaddr, len);
37305 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37306 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37307 if (err) {
37308 /*
37309 * TODO: need to fixup sg_tablesize, max_segment_size,
37310 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37311 index f59d4a0..1d89407 100644
37312 --- a/drivers/scsi/scsi_transport_fc.c
37313 +++ b/drivers/scsi/scsi_transport_fc.c
37314 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37315 * Netlink Infrastructure
37316 */
37317
37318 -static atomic_t fc_event_seq;
37319 +static atomic_unchecked_t fc_event_seq;
37320
37321 /**
37322 * fc_get_event_number - Obtain the next sequential FC event number
37323 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37324 u32
37325 fc_get_event_number(void)
37326 {
37327 - return atomic_add_return(1, &fc_event_seq);
37328 + return atomic_add_return_unchecked(1, &fc_event_seq);
37329 }
37330 EXPORT_SYMBOL(fc_get_event_number);
37331
37332 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37333 {
37334 int error;
37335
37336 - atomic_set(&fc_event_seq, 0);
37337 + atomic_set_unchecked(&fc_event_seq, 0);
37338
37339 error = transport_class_register(&fc_host_class);
37340 if (error)
37341 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37342 char *cp;
37343
37344 *val = simple_strtoul(buf, &cp, 0);
37345 - if ((*cp && (*cp != '\n')) || (*val < 0))
37346 + if (*cp && (*cp != '\n'))
37347 return -EINVAL;
37348 /*
37349 * Check for overflow; dev_loss_tmo is u32
37350 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37351 index e3e3c7d..ebdab62 100644
37352 --- a/drivers/scsi/scsi_transport_iscsi.c
37353 +++ b/drivers/scsi/scsi_transport_iscsi.c
37354 @@ -79,7 +79,7 @@ struct iscsi_internal {
37355 struct transport_container session_cont;
37356 };
37357
37358 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37359 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37360 static struct workqueue_struct *iscsi_eh_timer_workq;
37361
37362 static DEFINE_IDA(iscsi_sess_ida);
37363 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37364 int err;
37365
37366 ihost = shost->shost_data;
37367 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37368 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37369
37370 if (target_id == ISCSI_MAX_TARGET) {
37371 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37372 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37373 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37374 ISCSI_TRANSPORT_VERSION);
37375
37376 - atomic_set(&iscsi_session_nr, 0);
37377 + atomic_set_unchecked(&iscsi_session_nr, 0);
37378
37379 err = class_register(&iscsi_transport_class);
37380 if (err)
37381 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37382 index 21a045e..ec89e03 100644
37383 --- a/drivers/scsi/scsi_transport_srp.c
37384 +++ b/drivers/scsi/scsi_transport_srp.c
37385 @@ -33,7 +33,7 @@
37386 #include "scsi_transport_srp_internal.h"
37387
37388 struct srp_host_attrs {
37389 - atomic_t next_port_id;
37390 + atomic_unchecked_t next_port_id;
37391 };
37392 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37393
37394 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37395 struct Scsi_Host *shost = dev_to_shost(dev);
37396 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37397
37398 - atomic_set(&srp_host->next_port_id, 0);
37399 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37400 return 0;
37401 }
37402
37403 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37404 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37405 rport->roles = ids->roles;
37406
37407 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37408 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37409 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37410
37411 transport_setup_device(&rport->dev);
37412 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37413 index eacd46b..e3f4d62 100644
37414 --- a/drivers/scsi/sg.c
37415 +++ b/drivers/scsi/sg.c
37416 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37417 sdp->disk->disk_name,
37418 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37419 NULL,
37420 - (char *)arg);
37421 + (char __user *)arg);
37422 case BLKTRACESTART:
37423 return blk_trace_startstop(sdp->device->request_queue, 1);
37424 case BLKTRACESTOP:
37425 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37426 const struct file_operations * fops;
37427 };
37428
37429 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37430 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37431 {"allow_dio", &adio_fops},
37432 {"debug", &debug_fops},
37433 {"def_reserved_size", &dressz_fops},
37434 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37435 if (!sg_proc_sgp)
37436 return 1;
37437 for (k = 0; k < num_leaves; ++k) {
37438 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37439 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37440 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37441 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37442 }
37443 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37444 index f64250e..1ee3049 100644
37445 --- a/drivers/spi/spi-dw-pci.c
37446 +++ b/drivers/spi/spi-dw-pci.c
37447 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37448 #define spi_resume NULL
37449 #endif
37450
37451 -static const struct pci_device_id pci_ids[] __devinitdata = {
37452 +static const struct pci_device_id pci_ids[] __devinitconst = {
37453 /* Intel MID platform SPI controller 0 */
37454 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37455 {},
37456 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37457 index b2ccdea..84cde75 100644
37458 --- a/drivers/spi/spi.c
37459 +++ b/drivers/spi/spi.c
37460 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37461 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37462
37463 /* portable code must never pass more than 32 bytes */
37464 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37465 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37466
37467 static u8 *buf;
37468
37469 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37470 index 400df8c..065d4f4 100644
37471 --- a/drivers/staging/octeon/ethernet-rx.c
37472 +++ b/drivers/staging/octeon/ethernet-rx.c
37473 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37474 /* Increment RX stats for virtual ports */
37475 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37476 #ifdef CONFIG_64BIT
37477 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37478 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37479 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37480 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37481 #else
37482 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37483 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37484 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37485 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37486 #endif
37487 }
37488 netif_receive_skb(skb);
37489 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37490 dev->name);
37491 */
37492 #ifdef CONFIG_64BIT
37493 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37494 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37495 #else
37496 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37497 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37498 #endif
37499 dev_kfree_skb_irq(skb);
37500 }
37501 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37502 index 9112cd8..92f8d51 100644
37503 --- a/drivers/staging/octeon/ethernet.c
37504 +++ b/drivers/staging/octeon/ethernet.c
37505 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37506 * since the RX tasklet also increments it.
37507 */
37508 #ifdef CONFIG_64BIT
37509 - atomic64_add(rx_status.dropped_packets,
37510 - (atomic64_t *)&priv->stats.rx_dropped);
37511 + atomic64_add_unchecked(rx_status.dropped_packets,
37512 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37513 #else
37514 - atomic_add(rx_status.dropped_packets,
37515 - (atomic_t *)&priv->stats.rx_dropped);
37516 + atomic_add_unchecked(rx_status.dropped_packets,
37517 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37518 #endif
37519 }
37520
37521 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37522 index f9dae95..ff48901 100644
37523 --- a/drivers/staging/rtl8192e/rtllib_module.c
37524 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37525 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37526 }
37527
37528 static int store_debug_level(struct file *file, const char __user *buffer,
37529 + unsigned long count, void *data) __size_overflow(3);
37530 +static int store_debug_level(struct file *file, const char __user *buffer,
37531 unsigned long count, void *data)
37532 {
37533 char buf[] = "0x00000000";
37534 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37535 index e3d47bc..85f4d0d 100644
37536 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37537 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37538 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37539 }
37540
37541 static int store_debug_level(struct file *file, const char *buffer,
37542 + unsigned long count, void *data) __size_overflow(3);
37543 +static int store_debug_level(struct file *file, const char *buffer,
37544 unsigned long count, void *data)
37545 {
37546 char buf[] = "0x00000000";
37547 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37548 index 86308a0..feaa925 100644
37549 --- a/drivers/staging/rtl8712/rtl871x_io.h
37550 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37551 @@ -108,7 +108,7 @@ struct _io_ops {
37552 u8 *pmem);
37553 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37554 u8 *pmem);
37555 -};
37556 +} __no_const;
37557
37558 struct io_req {
37559 struct list_head list;
37560 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37561 index c7b5e8b..783d6cb 100644
37562 --- a/drivers/staging/sbe-2t3e3/netdev.c
37563 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37564 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37565 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37566
37567 if (rlen)
37568 - if (copy_to_user(data, &resp, rlen))
37569 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37570 return -EFAULT;
37571
37572 return 0;
37573 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37574 index 42cdafe..2769103 100644
37575 --- a/drivers/staging/speakup/speakup_soft.c
37576 +++ b/drivers/staging/speakup/speakup_soft.c
37577 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37578 break;
37579 } else if (!initialized) {
37580 if (*init) {
37581 - ch = *init;
37582 init++;
37583 } else {
37584 initialized = 1;
37585 }
37586 + ch = *init;
37587 } else {
37588 ch = synth_buffer_getc();
37589 }
37590 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37591 index b8f8c48..1fc5025 100644
37592 --- a/drivers/staging/usbip/usbip_common.h
37593 +++ b/drivers/staging/usbip/usbip_common.h
37594 @@ -289,7 +289,7 @@ struct usbip_device {
37595 void (*shutdown)(struct usbip_device *);
37596 void (*reset)(struct usbip_device *);
37597 void (*unusable)(struct usbip_device *);
37598 - } eh_ops;
37599 + } __no_const eh_ops;
37600 };
37601
37602 /* usbip_common.c */
37603 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37604 index 88b3298..3783eee 100644
37605 --- a/drivers/staging/usbip/vhci.h
37606 +++ b/drivers/staging/usbip/vhci.h
37607 @@ -88,7 +88,7 @@ struct vhci_hcd {
37608 unsigned resuming:1;
37609 unsigned long re_timeout;
37610
37611 - atomic_t seqnum;
37612 + atomic_unchecked_t seqnum;
37613
37614 /*
37615 * NOTE:
37616 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37617 index 2ee97e2..0420b86 100644
37618 --- a/drivers/staging/usbip/vhci_hcd.c
37619 +++ b/drivers/staging/usbip/vhci_hcd.c
37620 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37621 return;
37622 }
37623
37624 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37625 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37626 if (priv->seqnum == 0xffff)
37627 dev_info(&urb->dev->dev, "seqnum max\n");
37628
37629 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37630 return -ENOMEM;
37631 }
37632
37633 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37634 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37635 if (unlink->seqnum == 0xffff)
37636 pr_info("seqnum max\n");
37637
37638 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37639 vdev->rhport = rhport;
37640 }
37641
37642 - atomic_set(&vhci->seqnum, 0);
37643 + atomic_set_unchecked(&vhci->seqnum, 0);
37644 spin_lock_init(&vhci->lock);
37645
37646 hcd->power_budget = 0; /* no limit */
37647 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37648 index 3f511b4..d3dbc1e 100644
37649 --- a/drivers/staging/usbip/vhci_rx.c
37650 +++ b/drivers/staging/usbip/vhci_rx.c
37651 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37652 if (!urb) {
37653 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37654 pr_info("max seqnum %d\n",
37655 - atomic_read(&the_controller->seqnum));
37656 + atomic_read_unchecked(&the_controller->seqnum));
37657 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37658 return;
37659 }
37660 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37661 index 7735027..30eed13 100644
37662 --- a/drivers/staging/vt6655/hostap.c
37663 +++ b/drivers/staging/vt6655/hostap.c
37664 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37665 *
37666 */
37667
37668 +static net_device_ops_no_const apdev_netdev_ops;
37669 +
37670 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37671 {
37672 PSDevice apdev_priv;
37673 struct net_device *dev = pDevice->dev;
37674 int ret;
37675 - const struct net_device_ops apdev_netdev_ops = {
37676 - .ndo_start_xmit = pDevice->tx_80211,
37677 - };
37678
37679 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37680
37681 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37682 *apdev_priv = *pDevice;
37683 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37684
37685 + /* only half broken now */
37686 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37687 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37688
37689 pDevice->apdev->type = ARPHRD_IEEE80211;
37690 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37691 index 51b5adf..098e320 100644
37692 --- a/drivers/staging/vt6656/hostap.c
37693 +++ b/drivers/staging/vt6656/hostap.c
37694 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37695 *
37696 */
37697
37698 +static net_device_ops_no_const apdev_netdev_ops;
37699 +
37700 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37701 {
37702 PSDevice apdev_priv;
37703 struct net_device *dev = pDevice->dev;
37704 int ret;
37705 - const struct net_device_ops apdev_netdev_ops = {
37706 - .ndo_start_xmit = pDevice->tx_80211,
37707 - };
37708
37709 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37710
37711 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37712 *apdev_priv = *pDevice;
37713 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37714
37715 + /* only half broken now */
37716 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37717 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37718
37719 pDevice->apdev->type = ARPHRD_IEEE80211;
37720 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37721 index 7843dfd..3db105f 100644
37722 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37723 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37724 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37725
37726 struct usbctlx_completor {
37727 int (*complete) (struct usbctlx_completor *);
37728 -};
37729 +} __no_const;
37730
37731 static int
37732 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37733 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37734 index 1ca66ea..76f1343 100644
37735 --- a/drivers/staging/zcache/tmem.c
37736 +++ b/drivers/staging/zcache/tmem.c
37737 @@ -39,7 +39,7 @@
37738 * A tmem host implementation must use this function to register callbacks
37739 * for memory allocation.
37740 */
37741 -static struct tmem_hostops tmem_hostops;
37742 +static tmem_hostops_no_const tmem_hostops;
37743
37744 static void tmem_objnode_tree_init(void);
37745
37746 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37747 * A tmem host implementation must use this function to register
37748 * callbacks for a page-accessible memory (PAM) implementation
37749 */
37750 -static struct tmem_pamops tmem_pamops;
37751 +static tmem_pamops_no_const tmem_pamops;
37752
37753 void tmem_register_pamops(struct tmem_pamops *m)
37754 {
37755 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37756 index ed147c4..94fc3c6 100644
37757 --- a/drivers/staging/zcache/tmem.h
37758 +++ b/drivers/staging/zcache/tmem.h
37759 @@ -180,6 +180,7 @@ struct tmem_pamops {
37760 void (*new_obj)(struct tmem_obj *);
37761 int (*replace_in_obj)(void *, struct tmem_obj *);
37762 };
37763 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37764 extern void tmem_register_pamops(struct tmem_pamops *m);
37765
37766 /* memory allocation methods provided by the host implementation */
37767 @@ -189,6 +190,7 @@ struct tmem_hostops {
37768 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37769 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37770 };
37771 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37772 extern void tmem_register_hostops(struct tmem_hostops *m);
37773
37774 /* core tmem accessor functions */
37775 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37776 index 97c74ee..7f6d77d 100644
37777 --- a/drivers/target/iscsi/iscsi_target.c
37778 +++ b/drivers/target/iscsi/iscsi_target.c
37779 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37780 * outstanding_r2ts reaches zero, go ahead and send the delayed
37781 * TASK_ABORTED status.
37782 */
37783 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37784 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37785 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37786 if (--cmd->outstanding_r2ts < 1) {
37787 iscsit_stop_dataout_timer(cmd);
37788 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37789 index dcb0618..97e3d85 100644
37790 --- a/drivers/target/target_core_tmr.c
37791 +++ b/drivers/target/target_core_tmr.c
37792 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37793 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37794 cmd->t_task_list_num,
37795 atomic_read(&cmd->t_task_cdbs_left),
37796 - atomic_read(&cmd->t_task_cdbs_sent),
37797 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37798 atomic_read(&cmd->t_transport_active),
37799 atomic_read(&cmd->t_transport_stop),
37800 atomic_read(&cmd->t_transport_sent));
37801 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37802 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37803 " task: %p, t_fe_count: %d dev: %p\n", task,
37804 fe_count, dev);
37805 - atomic_set(&cmd->t_transport_aborted, 1);
37806 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37807 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37808
37809 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37810 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37811 }
37812 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37813 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37814 - atomic_set(&cmd->t_transport_aborted, 1);
37815 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37816 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37817
37818 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37819 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37820 index cd5cd95..5249d30 100644
37821 --- a/drivers/target/target_core_transport.c
37822 +++ b/drivers/target/target_core_transport.c
37823 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37824 spin_lock_init(&dev->se_port_lock);
37825 spin_lock_init(&dev->se_tmr_lock);
37826 spin_lock_init(&dev->qf_cmd_lock);
37827 - atomic_set(&dev->dev_ordered_id, 0);
37828 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37829
37830 se_dev_set_default_attribs(dev, dev_limits);
37831
37832 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37833 * Used to determine when ORDERED commands should go from
37834 * Dormant to Active status.
37835 */
37836 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37837 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37838 smp_mb__after_atomic_inc();
37839 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37840 cmd->se_ordered_id, cmd->sam_task_attr,
37841 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37842 " t_transport_active: %d t_transport_stop: %d"
37843 " t_transport_sent: %d\n", cmd->t_task_list_num,
37844 atomic_read(&cmd->t_task_cdbs_left),
37845 - atomic_read(&cmd->t_task_cdbs_sent),
37846 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37847 atomic_read(&cmd->t_task_cdbs_ex_left),
37848 atomic_read(&cmd->t_transport_active),
37849 atomic_read(&cmd->t_transport_stop),
37850 @@ -2121,9 +2121,9 @@ check_depth:
37851 cmd = task->task_se_cmd;
37852 spin_lock_irqsave(&cmd->t_state_lock, flags);
37853 task->task_flags |= (TF_ACTIVE | TF_SENT);
37854 - atomic_inc(&cmd->t_task_cdbs_sent);
37855 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37856
37857 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37858 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37859 cmd->t_task_list_num)
37860 atomic_set(&cmd->t_transport_sent, 1);
37861
37862 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37863 atomic_set(&cmd->transport_lun_stop, 0);
37864 }
37865 if (!atomic_read(&cmd->t_transport_active) ||
37866 - atomic_read(&cmd->t_transport_aborted)) {
37867 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37868 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37869 return false;
37870 }
37871 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37872 {
37873 int ret = 0;
37874
37875 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37876 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37877 if (!send_status ||
37878 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37879 return 1;
37880 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37881 */
37882 if (cmd->data_direction == DMA_TO_DEVICE) {
37883 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37884 - atomic_inc(&cmd->t_transport_aborted);
37885 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37886 smp_mb__after_atomic_inc();
37887 }
37888 }
37889 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37890 index b9040be..e3f5aab 100644
37891 --- a/drivers/tty/hvc/hvcs.c
37892 +++ b/drivers/tty/hvc/hvcs.c
37893 @@ -83,6 +83,7 @@
37894 #include <asm/hvcserver.h>
37895 #include <asm/uaccess.h>
37896 #include <asm/vio.h>
37897 +#include <asm/local.h>
37898
37899 /*
37900 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37901 @@ -270,7 +271,7 @@ struct hvcs_struct {
37902 unsigned int index;
37903
37904 struct tty_struct *tty;
37905 - int open_count;
37906 + local_t open_count;
37907
37908 /*
37909 * Used to tell the driver kernel_thread what operations need to take
37910 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37911
37912 spin_lock_irqsave(&hvcsd->lock, flags);
37913
37914 - if (hvcsd->open_count > 0) {
37915 + if (local_read(&hvcsd->open_count) > 0) {
37916 spin_unlock_irqrestore(&hvcsd->lock, flags);
37917 printk(KERN_INFO "HVCS: vterm state unchanged. "
37918 "The hvcs device node is still in use.\n");
37919 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37920 if ((retval = hvcs_partner_connect(hvcsd)))
37921 goto error_release;
37922
37923 - hvcsd->open_count = 1;
37924 + local_set(&hvcsd->open_count, 1);
37925 hvcsd->tty = tty;
37926 tty->driver_data = hvcsd;
37927
37928 @@ -1179,7 +1180,7 @@ fast_open:
37929
37930 spin_lock_irqsave(&hvcsd->lock, flags);
37931 kref_get(&hvcsd->kref);
37932 - hvcsd->open_count++;
37933 + local_inc(&hvcsd->open_count);
37934 hvcsd->todo_mask |= HVCS_SCHED_READ;
37935 spin_unlock_irqrestore(&hvcsd->lock, flags);
37936
37937 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37938 hvcsd = tty->driver_data;
37939
37940 spin_lock_irqsave(&hvcsd->lock, flags);
37941 - if (--hvcsd->open_count == 0) {
37942 + if (local_dec_and_test(&hvcsd->open_count)) {
37943
37944 vio_disable_interrupts(hvcsd->vdev);
37945
37946 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37947 free_irq(irq, hvcsd);
37948 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37949 return;
37950 - } else if (hvcsd->open_count < 0) {
37951 + } else if (local_read(&hvcsd->open_count) < 0) {
37952 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37953 " is missmanaged.\n",
37954 - hvcsd->vdev->unit_address, hvcsd->open_count);
37955 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37956 }
37957
37958 spin_unlock_irqrestore(&hvcsd->lock, flags);
37959 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37960
37961 spin_lock_irqsave(&hvcsd->lock, flags);
37962 /* Preserve this so that we know how many kref refs to put */
37963 - temp_open_count = hvcsd->open_count;
37964 + temp_open_count = local_read(&hvcsd->open_count);
37965
37966 /*
37967 * Don't kref put inside the spinlock because the destruction
37968 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37969 hvcsd->tty->driver_data = NULL;
37970 hvcsd->tty = NULL;
37971
37972 - hvcsd->open_count = 0;
37973 + local_set(&hvcsd->open_count, 0);
37974
37975 /* This will drop any buffered data on the floor which is OK in a hangup
37976 * scenario. */
37977 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37978 * the middle of a write operation? This is a crummy place to do this
37979 * but we want to keep it all in the spinlock.
37980 */
37981 - if (hvcsd->open_count <= 0) {
37982 + if (local_read(&hvcsd->open_count) <= 0) {
37983 spin_unlock_irqrestore(&hvcsd->lock, flags);
37984 return -ENODEV;
37985 }
37986 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37987 {
37988 struct hvcs_struct *hvcsd = tty->driver_data;
37989
37990 - if (!hvcsd || hvcsd->open_count <= 0)
37991 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37992 return 0;
37993
37994 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37995 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37996 index ef92869..f4ebd88 100644
37997 --- a/drivers/tty/ipwireless/tty.c
37998 +++ b/drivers/tty/ipwireless/tty.c
37999 @@ -29,6 +29,7 @@
38000 #include <linux/tty_driver.h>
38001 #include <linux/tty_flip.h>
38002 #include <linux/uaccess.h>
38003 +#include <asm/local.h>
38004
38005 #include "tty.h"
38006 #include "network.h"
38007 @@ -51,7 +52,7 @@ struct ipw_tty {
38008 int tty_type;
38009 struct ipw_network *network;
38010 struct tty_struct *linux_tty;
38011 - int open_count;
38012 + local_t open_count;
38013 unsigned int control_lines;
38014 struct mutex ipw_tty_mutex;
38015 int tx_bytes_queued;
38016 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38017 mutex_unlock(&tty->ipw_tty_mutex);
38018 return -ENODEV;
38019 }
38020 - if (tty->open_count == 0)
38021 + if (local_read(&tty->open_count) == 0)
38022 tty->tx_bytes_queued = 0;
38023
38024 - tty->open_count++;
38025 + local_inc(&tty->open_count);
38026
38027 tty->linux_tty = linux_tty;
38028 linux_tty->driver_data = tty;
38029 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38030
38031 static void do_ipw_close(struct ipw_tty *tty)
38032 {
38033 - tty->open_count--;
38034 -
38035 - if (tty->open_count == 0) {
38036 + if (local_dec_return(&tty->open_count) == 0) {
38037 struct tty_struct *linux_tty = tty->linux_tty;
38038
38039 if (linux_tty != NULL) {
38040 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38041 return;
38042
38043 mutex_lock(&tty->ipw_tty_mutex);
38044 - if (tty->open_count == 0) {
38045 + if (local_read(&tty->open_count) == 0) {
38046 mutex_unlock(&tty->ipw_tty_mutex);
38047 return;
38048 }
38049 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38050 return;
38051 }
38052
38053 - if (!tty->open_count) {
38054 + if (!local_read(&tty->open_count)) {
38055 mutex_unlock(&tty->ipw_tty_mutex);
38056 return;
38057 }
38058 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38059 return -ENODEV;
38060
38061 mutex_lock(&tty->ipw_tty_mutex);
38062 - if (!tty->open_count) {
38063 + if (!local_read(&tty->open_count)) {
38064 mutex_unlock(&tty->ipw_tty_mutex);
38065 return -EINVAL;
38066 }
38067 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38068 if (!tty)
38069 return -ENODEV;
38070
38071 - if (!tty->open_count)
38072 + if (!local_read(&tty->open_count))
38073 return -EINVAL;
38074
38075 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38076 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38077 if (!tty)
38078 return 0;
38079
38080 - if (!tty->open_count)
38081 + if (!local_read(&tty->open_count))
38082 return 0;
38083
38084 return tty->tx_bytes_queued;
38085 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38086 if (!tty)
38087 return -ENODEV;
38088
38089 - if (!tty->open_count)
38090 + if (!local_read(&tty->open_count))
38091 return -EINVAL;
38092
38093 return get_control_lines(tty);
38094 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38095 if (!tty)
38096 return -ENODEV;
38097
38098 - if (!tty->open_count)
38099 + if (!local_read(&tty->open_count))
38100 return -EINVAL;
38101
38102 return set_control_lines(tty, set, clear);
38103 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38104 if (!tty)
38105 return -ENODEV;
38106
38107 - if (!tty->open_count)
38108 + if (!local_read(&tty->open_count))
38109 return -EINVAL;
38110
38111 /* FIXME: Exactly how is the tty object locked here .. */
38112 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38113 against a parallel ioctl etc */
38114 mutex_lock(&ttyj->ipw_tty_mutex);
38115 }
38116 - while (ttyj->open_count)
38117 + while (local_read(&ttyj->open_count))
38118 do_ipw_close(ttyj);
38119 ipwireless_disassociate_network_ttys(network,
38120 ttyj->channel_idx);
38121 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38122 index fc7bbba..9527e93 100644
38123 --- a/drivers/tty/n_gsm.c
38124 +++ b/drivers/tty/n_gsm.c
38125 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38126 kref_init(&dlci->ref);
38127 mutex_init(&dlci->mutex);
38128 dlci->fifo = &dlci->_fifo;
38129 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38130 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38131 kfree(dlci);
38132 return NULL;
38133 }
38134 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38135 index d2256d0..97476fa 100644
38136 --- a/drivers/tty/n_tty.c
38137 +++ b/drivers/tty/n_tty.c
38138 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38139 {
38140 *ops = tty_ldisc_N_TTY;
38141 ops->owner = NULL;
38142 - ops->refcount = ops->flags = 0;
38143 + atomic_set(&ops->refcount, 0);
38144 + ops->flags = 0;
38145 }
38146 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38147 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38148 index d8653ab..f8afd9d 100644
38149 --- a/drivers/tty/pty.c
38150 +++ b/drivers/tty/pty.c
38151 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38152 register_sysctl_table(pty_root_table);
38153
38154 /* Now create the /dev/ptmx special device */
38155 + pax_open_kernel();
38156 tty_default_fops(&ptmx_fops);
38157 - ptmx_fops.open = ptmx_open;
38158 + *(void **)&ptmx_fops.open = ptmx_open;
38159 + pax_close_kernel();
38160
38161 cdev_init(&ptmx_cdev, &ptmx_fops);
38162 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38163 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38164 index 2b42a01..32a2ed3 100644
38165 --- a/drivers/tty/serial/kgdboc.c
38166 +++ b/drivers/tty/serial/kgdboc.c
38167 @@ -24,8 +24,9 @@
38168 #define MAX_CONFIG_LEN 40
38169
38170 static struct kgdb_io kgdboc_io_ops;
38171 +static struct kgdb_io kgdboc_io_ops_console;
38172
38173 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38174 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38175 static int configured = -1;
38176
38177 static char config[MAX_CONFIG_LEN];
38178 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38179 kgdboc_unregister_kbd();
38180 if (configured == 1)
38181 kgdb_unregister_io_module(&kgdboc_io_ops);
38182 + else if (configured == 2)
38183 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38184 }
38185
38186 static int configure_kgdboc(void)
38187 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38188 int err;
38189 char *cptr = config;
38190 struct console *cons;
38191 + int is_console = 0;
38192
38193 err = kgdboc_option_setup(config);
38194 if (err || !strlen(config) || isspace(config[0]))
38195 goto noconfig;
38196
38197 err = -ENODEV;
38198 - kgdboc_io_ops.is_console = 0;
38199 kgdb_tty_driver = NULL;
38200
38201 kgdboc_use_kms = 0;
38202 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38203 int idx;
38204 if (cons->device && cons->device(cons, &idx) == p &&
38205 idx == tty_line) {
38206 - kgdboc_io_ops.is_console = 1;
38207 + is_console = 1;
38208 break;
38209 }
38210 cons = cons->next;
38211 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38212 kgdb_tty_line = tty_line;
38213
38214 do_register:
38215 - err = kgdb_register_io_module(&kgdboc_io_ops);
38216 + if (is_console) {
38217 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38218 + configured = 2;
38219 + } else {
38220 + err = kgdb_register_io_module(&kgdboc_io_ops);
38221 + configured = 1;
38222 + }
38223 if (err)
38224 goto noconfig;
38225
38226 - configured = 1;
38227 -
38228 return 0;
38229
38230 noconfig:
38231 @@ -213,7 +220,7 @@ noconfig:
38232 static int __init init_kgdboc(void)
38233 {
38234 /* Already configured? */
38235 - if (configured == 1)
38236 + if (configured >= 1)
38237 return 0;
38238
38239 return configure_kgdboc();
38240 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38241 if (config[len - 1] == '\n')
38242 config[len - 1] = '\0';
38243
38244 - if (configured == 1)
38245 + if (configured >= 1)
38246 cleanup_kgdboc();
38247
38248 /* Go and configure with the new params. */
38249 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38250 .post_exception = kgdboc_post_exp_handler,
38251 };
38252
38253 +static struct kgdb_io kgdboc_io_ops_console = {
38254 + .name = "kgdboc",
38255 + .read_char = kgdboc_get_char,
38256 + .write_char = kgdboc_put_char,
38257 + .pre_exception = kgdboc_pre_exp_handler,
38258 + .post_exception = kgdboc_post_exp_handler,
38259 + .is_console = 1
38260 +};
38261 +
38262 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38263 /* This is only available if kgdboc is a built in for early debugging */
38264 static int __init kgdboc_early_init(char *opt)
38265 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38266 index 7867b7c..b3c119d 100644
38267 --- a/drivers/tty/sysrq.c
38268 +++ b/drivers/tty/sysrq.c
38269 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38270 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38271 size_t count, loff_t *ppos)
38272 {
38273 - if (count) {
38274 + if (count && capable(CAP_SYS_ADMIN)) {
38275 char c;
38276
38277 if (get_user(c, buf))
38278 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38279 index e41b9bb..84002fb 100644
38280 --- a/drivers/tty/tty_io.c
38281 +++ b/drivers/tty/tty_io.c
38282 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38283
38284 void tty_default_fops(struct file_operations *fops)
38285 {
38286 - *fops = tty_fops;
38287 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38288 }
38289
38290 /*
38291 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38292 index 24b95db..9c078d0 100644
38293 --- a/drivers/tty/tty_ldisc.c
38294 +++ b/drivers/tty/tty_ldisc.c
38295 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38296 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38297 struct tty_ldisc_ops *ldo = ld->ops;
38298
38299 - ldo->refcount--;
38300 + atomic_dec(&ldo->refcount);
38301 module_put(ldo->owner);
38302 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38303
38304 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38305 spin_lock_irqsave(&tty_ldisc_lock, flags);
38306 tty_ldiscs[disc] = new_ldisc;
38307 new_ldisc->num = disc;
38308 - new_ldisc->refcount = 0;
38309 + atomic_set(&new_ldisc->refcount, 0);
38310 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38311
38312 return ret;
38313 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38314 return -EINVAL;
38315
38316 spin_lock_irqsave(&tty_ldisc_lock, flags);
38317 - if (tty_ldiscs[disc]->refcount)
38318 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38319 ret = -EBUSY;
38320 else
38321 tty_ldiscs[disc] = NULL;
38322 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38323 if (ldops) {
38324 ret = ERR_PTR(-EAGAIN);
38325 if (try_module_get(ldops->owner)) {
38326 - ldops->refcount++;
38327 + atomic_inc(&ldops->refcount);
38328 ret = ldops;
38329 }
38330 }
38331 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38332 unsigned long flags;
38333
38334 spin_lock_irqsave(&tty_ldisc_lock, flags);
38335 - ldops->refcount--;
38336 + atomic_dec(&ldops->refcount);
38337 module_put(ldops->owner);
38338 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38339 }
38340 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38341 index a605549..6bd3c96 100644
38342 --- a/drivers/tty/vt/keyboard.c
38343 +++ b/drivers/tty/vt/keyboard.c
38344 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38345 kbd->kbdmode == VC_OFF) &&
38346 value != KVAL(K_SAK))
38347 return; /* SAK is allowed even in raw mode */
38348 +
38349 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38350 + {
38351 + void *func = fn_handler[value];
38352 + if (func == fn_show_state || func == fn_show_ptregs ||
38353 + func == fn_show_mem)
38354 + return;
38355 + }
38356 +#endif
38357 +
38358 fn_handler[value](vc);
38359 }
38360
38361 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38362 index 65447c5..0526f0a 100644
38363 --- a/drivers/tty/vt/vt_ioctl.c
38364 +++ b/drivers/tty/vt/vt_ioctl.c
38365 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38366 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38367 return -EFAULT;
38368
38369 - if (!capable(CAP_SYS_TTY_CONFIG))
38370 - perm = 0;
38371 -
38372 switch (cmd) {
38373 case KDGKBENT:
38374 key_map = key_maps[s];
38375 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38376 val = (i ? K_HOLE : K_NOSUCHMAP);
38377 return put_user(val, &user_kbe->kb_value);
38378 case KDSKBENT:
38379 + if (!capable(CAP_SYS_TTY_CONFIG))
38380 + perm = 0;
38381 +
38382 if (!perm)
38383 return -EPERM;
38384 if (!i && v == K_NOSUCHMAP) {
38385 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38386 int i, j, k;
38387 int ret;
38388
38389 - if (!capable(CAP_SYS_TTY_CONFIG))
38390 - perm = 0;
38391 -
38392 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38393 if (!kbs) {
38394 ret = -ENOMEM;
38395 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38396 kfree(kbs);
38397 return ((p && *p) ? -EOVERFLOW : 0);
38398 case KDSKBSENT:
38399 + if (!capable(CAP_SYS_TTY_CONFIG))
38400 + perm = 0;
38401 +
38402 if (!perm) {
38403 ret = -EPERM;
38404 goto reterr;
38405 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38406 index a783d53..cb30d94 100644
38407 --- a/drivers/uio/uio.c
38408 +++ b/drivers/uio/uio.c
38409 @@ -25,6 +25,7 @@
38410 #include <linux/kobject.h>
38411 #include <linux/cdev.h>
38412 #include <linux/uio_driver.h>
38413 +#include <asm/local.h>
38414
38415 #define UIO_MAX_DEVICES (1U << MINORBITS)
38416
38417 @@ -32,10 +33,10 @@ struct uio_device {
38418 struct module *owner;
38419 struct device *dev;
38420 int minor;
38421 - atomic_t event;
38422 + atomic_unchecked_t event;
38423 struct fasync_struct *async_queue;
38424 wait_queue_head_t wait;
38425 - int vma_count;
38426 + local_t vma_count;
38427 struct uio_info *info;
38428 struct kobject *map_dir;
38429 struct kobject *portio_dir;
38430 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38431 struct device_attribute *attr, char *buf)
38432 {
38433 struct uio_device *idev = dev_get_drvdata(dev);
38434 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38435 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38436 }
38437
38438 static struct device_attribute uio_class_attributes[] = {
38439 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38440 {
38441 struct uio_device *idev = info->uio_dev;
38442
38443 - atomic_inc(&idev->event);
38444 + atomic_inc_unchecked(&idev->event);
38445 wake_up_interruptible(&idev->wait);
38446 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38447 }
38448 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38449 }
38450
38451 listener->dev = idev;
38452 - listener->event_count = atomic_read(&idev->event);
38453 + listener->event_count = atomic_read_unchecked(&idev->event);
38454 filep->private_data = listener;
38455
38456 if (idev->info->open) {
38457 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38458 return -EIO;
38459
38460 poll_wait(filep, &idev->wait, wait);
38461 - if (listener->event_count != atomic_read(&idev->event))
38462 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38463 return POLLIN | POLLRDNORM;
38464 return 0;
38465 }
38466 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38467 do {
38468 set_current_state(TASK_INTERRUPTIBLE);
38469
38470 - event_count = atomic_read(&idev->event);
38471 + event_count = atomic_read_unchecked(&idev->event);
38472 if (event_count != listener->event_count) {
38473 if (copy_to_user(buf, &event_count, count))
38474 retval = -EFAULT;
38475 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38476 static void uio_vma_open(struct vm_area_struct *vma)
38477 {
38478 struct uio_device *idev = vma->vm_private_data;
38479 - idev->vma_count++;
38480 + local_inc(&idev->vma_count);
38481 }
38482
38483 static void uio_vma_close(struct vm_area_struct *vma)
38484 {
38485 struct uio_device *idev = vma->vm_private_data;
38486 - idev->vma_count--;
38487 + local_dec(&idev->vma_count);
38488 }
38489
38490 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38491 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38492 idev->owner = owner;
38493 idev->info = info;
38494 init_waitqueue_head(&idev->wait);
38495 - atomic_set(&idev->event, 0);
38496 + atomic_set_unchecked(&idev->event, 0);
38497
38498 ret = uio_get_minor(idev);
38499 if (ret)
38500 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38501 index 98b89fe..aff824e 100644
38502 --- a/drivers/usb/atm/cxacru.c
38503 +++ b/drivers/usb/atm/cxacru.c
38504 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38505 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38506 if (ret < 2)
38507 return -EINVAL;
38508 - if (index < 0 || index > 0x7f)
38509 + if (index > 0x7f)
38510 return -EINVAL;
38511 pos += tmp;
38512
38513 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38514 index d3448ca..d2864ca 100644
38515 --- a/drivers/usb/atm/usbatm.c
38516 +++ b/drivers/usb/atm/usbatm.c
38517 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38518 if (printk_ratelimit())
38519 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38520 __func__, vpi, vci);
38521 - atomic_inc(&vcc->stats->rx_err);
38522 + atomic_inc_unchecked(&vcc->stats->rx_err);
38523 return;
38524 }
38525
38526 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38527 if (length > ATM_MAX_AAL5_PDU) {
38528 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38529 __func__, length, vcc);
38530 - atomic_inc(&vcc->stats->rx_err);
38531 + atomic_inc_unchecked(&vcc->stats->rx_err);
38532 goto out;
38533 }
38534
38535 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38536 if (sarb->len < pdu_length) {
38537 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38538 __func__, pdu_length, sarb->len, vcc);
38539 - atomic_inc(&vcc->stats->rx_err);
38540 + atomic_inc_unchecked(&vcc->stats->rx_err);
38541 goto out;
38542 }
38543
38544 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38545 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38546 __func__, vcc);
38547 - atomic_inc(&vcc->stats->rx_err);
38548 + atomic_inc_unchecked(&vcc->stats->rx_err);
38549 goto out;
38550 }
38551
38552 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38553 if (printk_ratelimit())
38554 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38555 __func__, length);
38556 - atomic_inc(&vcc->stats->rx_drop);
38557 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38558 goto out;
38559 }
38560
38561 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38562
38563 vcc->push(vcc, skb);
38564
38565 - atomic_inc(&vcc->stats->rx);
38566 + atomic_inc_unchecked(&vcc->stats->rx);
38567 out:
38568 skb_trim(sarb, 0);
38569 }
38570 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38571 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38572
38573 usbatm_pop(vcc, skb);
38574 - atomic_inc(&vcc->stats->tx);
38575 + atomic_inc_unchecked(&vcc->stats->tx);
38576
38577 skb = skb_dequeue(&instance->sndqueue);
38578 }
38579 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38580 if (!left--)
38581 return sprintf(page,
38582 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38583 - atomic_read(&atm_dev->stats.aal5.tx),
38584 - atomic_read(&atm_dev->stats.aal5.tx_err),
38585 - atomic_read(&atm_dev->stats.aal5.rx),
38586 - atomic_read(&atm_dev->stats.aal5.rx_err),
38587 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38588 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38589 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38590 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38591 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38592 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38593
38594 if (!left--) {
38595 if (instance->disconnected)
38596 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38597 index d956965..4179a77 100644
38598 --- a/drivers/usb/core/devices.c
38599 +++ b/drivers/usb/core/devices.c
38600 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38601 * time it gets called.
38602 */
38603 static struct device_connect_event {
38604 - atomic_t count;
38605 + atomic_unchecked_t count;
38606 wait_queue_head_t wait;
38607 } device_event = {
38608 .count = ATOMIC_INIT(1),
38609 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38610
38611 void usbfs_conn_disc_event(void)
38612 {
38613 - atomic_add(2, &device_event.count);
38614 + atomic_add_unchecked(2, &device_event.count);
38615 wake_up(&device_event.wait);
38616 }
38617
38618 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38619
38620 poll_wait(file, &device_event.wait, wait);
38621
38622 - event_count = atomic_read(&device_event.count);
38623 + event_count = atomic_read_unchecked(&device_event.count);
38624 if (file->f_version != event_count) {
38625 file->f_version = event_count;
38626 return POLLIN | POLLRDNORM;
38627 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38628 index 1fc8f12..20647c1 100644
38629 --- a/drivers/usb/early/ehci-dbgp.c
38630 +++ b/drivers/usb/early/ehci-dbgp.c
38631 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38632
38633 #ifdef CONFIG_KGDB
38634 static struct kgdb_io kgdbdbgp_io_ops;
38635 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38636 +static struct kgdb_io kgdbdbgp_io_ops_console;
38637 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38638 #else
38639 #define dbgp_kgdb_mode (0)
38640 #endif
38641 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38642 .write_char = kgdbdbgp_write_char,
38643 };
38644
38645 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38646 + .name = "kgdbdbgp",
38647 + .read_char = kgdbdbgp_read_char,
38648 + .write_char = kgdbdbgp_write_char,
38649 + .is_console = 1
38650 +};
38651 +
38652 static int kgdbdbgp_wait_time;
38653
38654 static int __init kgdbdbgp_parse_config(char *str)
38655 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38656 ptr++;
38657 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38658 }
38659 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38660 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38661 + if (early_dbgp_console.index != -1)
38662 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38663 + else
38664 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38665
38666 return 0;
38667 }
38668 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38669 index d6bea3e..60b250e 100644
38670 --- a/drivers/usb/wusbcore/wa-hc.h
38671 +++ b/drivers/usb/wusbcore/wa-hc.h
38672 @@ -192,7 +192,7 @@ struct wahc {
38673 struct list_head xfer_delayed_list;
38674 spinlock_t xfer_list_lock;
38675 struct work_struct xfer_work;
38676 - atomic_t xfer_id_count;
38677 + atomic_unchecked_t xfer_id_count;
38678 };
38679
38680
38681 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38682 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38683 spin_lock_init(&wa->xfer_list_lock);
38684 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38685 - atomic_set(&wa->xfer_id_count, 1);
38686 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38687 }
38688
38689 /**
38690 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38691 index 57c01ab..8a05959 100644
38692 --- a/drivers/usb/wusbcore/wa-xfer.c
38693 +++ b/drivers/usb/wusbcore/wa-xfer.c
38694 @@ -296,7 +296,7 @@ out:
38695 */
38696 static void wa_xfer_id_init(struct wa_xfer *xfer)
38697 {
38698 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38699 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38700 }
38701
38702 /*
38703 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38704 index c14c42b..f955cc2 100644
38705 --- a/drivers/vhost/vhost.c
38706 +++ b/drivers/vhost/vhost.c
38707 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38708 return 0;
38709 }
38710
38711 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38712 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38713 {
38714 struct file *eventfp, *filep = NULL,
38715 *pollstart = NULL, *pollstop = NULL;
38716 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38717 index b0b2ac3..89a4399 100644
38718 --- a/drivers/video/aty/aty128fb.c
38719 +++ b/drivers/video/aty/aty128fb.c
38720 @@ -148,7 +148,7 @@ enum {
38721 };
38722
38723 /* Must match above enum */
38724 -static const char *r128_family[] __devinitdata = {
38725 +static const char *r128_family[] __devinitconst = {
38726 "AGP",
38727 "PCI",
38728 "PRO AGP",
38729 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38730 index 5c3960d..15cf8fc 100644
38731 --- a/drivers/video/fbcmap.c
38732 +++ b/drivers/video/fbcmap.c
38733 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38734 rc = -ENODEV;
38735 goto out;
38736 }
38737 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38738 - !info->fbops->fb_setcmap)) {
38739 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38740 rc = -EINVAL;
38741 goto out1;
38742 }
38743 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38744 index c6ce416..3b9b642 100644
38745 --- a/drivers/video/fbmem.c
38746 +++ b/drivers/video/fbmem.c
38747 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38748 image->dx += image->width + 8;
38749 }
38750 } else if (rotate == FB_ROTATE_UD) {
38751 - for (x = 0; x < num && image->dx >= 0; x++) {
38752 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38753 info->fbops->fb_imageblit(info, image);
38754 image->dx -= image->width + 8;
38755 }
38756 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38757 image->dy += image->height + 8;
38758 }
38759 } else if (rotate == FB_ROTATE_CCW) {
38760 - for (x = 0; x < num && image->dy >= 0; x++) {
38761 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38762 info->fbops->fb_imageblit(info, image);
38763 image->dy -= image->height + 8;
38764 }
38765 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38766 return -EFAULT;
38767 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38768 return -EINVAL;
38769 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38770 + if (con2fb.framebuffer >= FB_MAX)
38771 return -EINVAL;
38772 if (!registered_fb[con2fb.framebuffer])
38773 request_module("fb%d", con2fb.framebuffer);
38774 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38775 index 5a5d092..265c5ed 100644
38776 --- a/drivers/video/geode/gx1fb_core.c
38777 +++ b/drivers/video/geode/gx1fb_core.c
38778 @@ -29,7 +29,7 @@ static int crt_option = 1;
38779 static char panel_option[32] = "";
38780
38781 /* Modes relevant to the GX1 (taken from modedb.c) */
38782 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38783 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38784 /* 640x480-60 VESA */
38785 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38786 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38787 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38788 index 0fad23f..0e9afa4 100644
38789 --- a/drivers/video/gxt4500.c
38790 +++ b/drivers/video/gxt4500.c
38791 @@ -156,7 +156,7 @@ struct gxt4500_par {
38792 static char *mode_option;
38793
38794 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38795 -static const struct fb_videomode defaultmode __devinitdata = {
38796 +static const struct fb_videomode defaultmode __devinitconst = {
38797 .refresh = 60,
38798 .xres = 1280,
38799 .yres = 1024,
38800 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38801 return 0;
38802 }
38803
38804 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38805 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38806 .id = "IBM GXT4500P",
38807 .type = FB_TYPE_PACKED_PIXELS,
38808 .visual = FB_VISUAL_PSEUDOCOLOR,
38809 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38810 index 7672d2e..b56437f 100644
38811 --- a/drivers/video/i810/i810_accel.c
38812 +++ b/drivers/video/i810/i810_accel.c
38813 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38814 }
38815 }
38816 printk("ringbuffer lockup!!!\n");
38817 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38818 i810_report_error(mmio);
38819 par->dev_flags |= LOCKUP;
38820 info->pixmap.scan_align = 1;
38821 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38822 index b83f361..2b05a91 100644
38823 --- a/drivers/video/i810/i810_main.c
38824 +++ b/drivers/video/i810/i810_main.c
38825 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38826 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38827
38828 /* PCI */
38829 -static const char *i810_pci_list[] __devinitdata = {
38830 +static const char *i810_pci_list[] __devinitconst = {
38831 "Intel(R) 810 Framebuffer Device" ,
38832 "Intel(R) 810-DC100 Framebuffer Device" ,
38833 "Intel(R) 810E Framebuffer Device" ,
38834 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38835 index de36693..3c63fc2 100644
38836 --- a/drivers/video/jz4740_fb.c
38837 +++ b/drivers/video/jz4740_fb.c
38838 @@ -136,7 +136,7 @@ struct jzfb {
38839 uint32_t pseudo_palette[16];
38840 };
38841
38842 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38843 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38844 .id = "JZ4740 FB",
38845 .type = FB_TYPE_PACKED_PIXELS,
38846 .visual = FB_VISUAL_TRUECOLOR,
38847 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38848 index 3c14e43..eafa544 100644
38849 --- a/drivers/video/logo/logo_linux_clut224.ppm
38850 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38851 @@ -1,1604 +1,1123 @@
38852 P3
38853 -# Standard 224-color Linux logo
38854 80 80
38855 255
38856 - 0 0 0 0 0 0 0 0 0 0 0 0
38857 - 0 0 0 0 0 0 0 0 0 0 0 0
38858 - 0 0 0 0 0 0 0 0 0 0 0 0
38859 - 0 0 0 0 0 0 0 0 0 0 0 0
38860 - 0 0 0 0 0 0 0 0 0 0 0 0
38861 - 0 0 0 0 0 0 0 0 0 0 0 0
38862 - 0 0 0 0 0 0 0 0 0 0 0 0
38863 - 0 0 0 0 0 0 0 0 0 0 0 0
38864 - 0 0 0 0 0 0 0 0 0 0 0 0
38865 - 6 6 6 6 6 6 10 10 10 10 10 10
38866 - 10 10 10 6 6 6 6 6 6 6 6 6
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 0 0 0
38877 - 0 0 0 0 0 0 0 0 0 0 0 0
38878 - 0 0 0 0 0 0 0 0 0 0 0 0
38879 - 0 0 0 0 0 0 0 0 0 0 0 0
38880 - 0 0 0 0 0 0 0 0 0 0 0 0
38881 - 0 0 0 0 0 0 0 0 0 0 0 0
38882 - 0 0 0 0 0 0 0 0 0 0 0 0
38883 - 0 0 0 0 0 0 0 0 0 0 0 0
38884 - 0 0 0 6 6 6 10 10 10 14 14 14
38885 - 22 22 22 26 26 26 30 30 30 34 34 34
38886 - 30 30 30 30 30 30 26 26 26 18 18 18
38887 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 0 0 0
38897 - 0 0 0 0 0 1 0 0 1 0 0 0
38898 - 0 0 0 0 0 0 0 0 0 0 0 0
38899 - 0 0 0 0 0 0 0 0 0 0 0 0
38900 - 0 0 0 0 0 0 0 0 0 0 0 0
38901 - 0 0 0 0 0 0 0 0 0 0 0 0
38902 - 0 0 0 0 0 0 0 0 0 0 0 0
38903 - 0 0 0 0 0 0 0 0 0 0 0 0
38904 - 6 6 6 14 14 14 26 26 26 42 42 42
38905 - 54 54 54 66 66 66 78 78 78 78 78 78
38906 - 78 78 78 74 74 74 66 66 66 54 54 54
38907 - 42 42 42 26 26 26 18 18 18 10 10 10
38908 - 6 6 6 0 0 0 0 0 0 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 0 0 0 0 0 0
38911 - 0 0 0 0 0 0 0 0 0 0 0 0
38912 - 0 0 0 0 0 0 0 0 0 0 0 0
38913 - 0 0 0 0 0 0 0 0 0 0 0 0
38914 - 0 0 0 0 0 0 0 0 0 0 0 0
38915 - 0 0 0 0 0 0 0 0 0 0 0 0
38916 - 0 0 0 0 0 0 0 0 0 0 0 0
38917 - 0 0 1 0 0 0 0 0 0 0 0 0
38918 - 0 0 0 0 0 0 0 0 0 0 0 0
38919 - 0 0 0 0 0 0 0 0 0 0 0 0
38920 - 0 0 0 0 0 0 0 0 0 0 0 0
38921 - 0 0 0 0 0 0 0 0 0 0 0 0
38922 - 0 0 0 0 0 0 0 0 0 0 0 0
38923 - 0 0 0 0 0 0 0 0 0 10 10 10
38924 - 22 22 22 42 42 42 66 66 66 86 86 86
38925 - 66 66 66 38 38 38 38 38 38 22 22 22
38926 - 26 26 26 34 34 34 54 54 54 66 66 66
38927 - 86 86 86 70 70 70 46 46 46 26 26 26
38928 - 14 14 14 6 6 6 0 0 0 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 0 0 0 0 0 0 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 0 0 0 0 0 0 0 0 0 0 0 0
38936 - 0 0 0 0 0 0 0 0 0 0 0 0
38937 - 0 0 1 0 0 1 0 0 1 0 0 0
38938 - 0 0 0 0 0 0 0 0 0 0 0 0
38939 - 0 0 0 0 0 0 0 0 0 0 0 0
38940 - 0 0 0 0 0 0 0 0 0 0 0 0
38941 - 0 0 0 0 0 0 0 0 0 0 0 0
38942 - 0 0 0 0 0 0 0 0 0 0 0 0
38943 - 0 0 0 0 0 0 10 10 10 26 26 26
38944 - 50 50 50 82 82 82 58 58 58 6 6 6
38945 - 2 2 6 2 2 6 2 2 6 2 2 6
38946 - 2 2 6 2 2 6 2 2 6 2 2 6
38947 - 6 6 6 54 54 54 86 86 86 66 66 66
38948 - 38 38 38 18 18 18 6 6 6 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 0 0 0 0 0 0 0 0 0 0 0 0
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 0 0 0
38954 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 0 0 0 0 0 0 0 0 0 0 0 0
38956 - 0 0 0 0 0 0 0 0 0 0 0 0
38957 - 0 0 0 0 0 0 0 0 0 0 0 0
38958 - 0 0 0 0 0 0 0 0 0 0 0 0
38959 - 0 0 0 0 0 0 0 0 0 0 0 0
38960 - 0 0 0 0 0 0 0 0 0 0 0 0
38961 - 0 0 0 0 0 0 0 0 0 0 0 0
38962 - 0 0 0 0 0 0 0 0 0 0 0 0
38963 - 0 0 0 6 6 6 22 22 22 50 50 50
38964 - 78 78 78 34 34 34 2 2 6 2 2 6
38965 - 2 2 6 2 2 6 2 2 6 2 2 6
38966 - 2 2 6 2 2 6 2 2 6 2 2 6
38967 - 2 2 6 2 2 6 6 6 6 70 70 70
38968 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
38975 - 0 0 0 0 0 0 0 0 0 0 0 0
38976 - 0 0 0 0 0 0 0 0 0 0 0 0
38977 - 0 0 1 0 0 1 0 0 1 0 0 0
38978 - 0 0 0 0 0 0 0 0 0 0 0 0
38979 - 0 0 0 0 0 0 0 0 0 0 0 0
38980 - 0 0 0 0 0 0 0 0 0 0 0 0
38981 - 0 0 0 0 0 0 0 0 0 0 0 0
38982 - 0 0 0 0 0 0 0 0 0 0 0 0
38983 - 6 6 6 18 18 18 42 42 42 82 82 82
38984 - 26 26 26 2 2 6 2 2 6 2 2 6
38985 - 2 2 6 2 2 6 2 2 6 2 2 6
38986 - 2 2 6 2 2 6 2 2 6 14 14 14
38987 - 46 46 46 34 34 34 6 6 6 2 2 6
38988 - 42 42 42 78 78 78 42 42 42 18 18 18
38989 - 6 6 6 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 0 0 0 0 0 0 0 0 0 0 0 0
38992 - 0 0 0 0 0 0 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 0 0 0 0 0 0 0 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 0 0 0
38997 - 0 0 1 0 0 0 0 0 1 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 0 0 0 0 0 0 0 0 0 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 10 10 10 30 30 30 66 66 66 58 58 58
39004 - 2 2 6 2 2 6 2 2 6 2 2 6
39005 - 2 2 6 2 2 6 2 2 6 2 2 6
39006 - 2 2 6 2 2 6 2 2 6 26 26 26
39007 - 86 86 86 101 101 101 46 46 46 10 10 10
39008 - 2 2 6 58 58 58 70 70 70 34 34 34
39009 - 10 10 10 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 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 0 0 0
39017 - 0 0 1 0 0 1 0 0 1 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 0 0 0
39021 - 0 0 0 0 0 0 0 0 0 0 0 0
39022 - 0 0 0 0 0 0 0 0 0 0 0 0
39023 - 14 14 14 42 42 42 86 86 86 10 10 10
39024 - 2 2 6 2 2 6 2 2 6 2 2 6
39025 - 2 2 6 2 2 6 2 2 6 2 2 6
39026 - 2 2 6 2 2 6 2 2 6 30 30 30
39027 - 94 94 94 94 94 94 58 58 58 26 26 26
39028 - 2 2 6 6 6 6 78 78 78 54 54 54
39029 - 22 22 22 6 6 6 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 0 0 0
39031 - 0 0 0 0 0 0 0 0 0 0 0 0
39032 - 0 0 0 0 0 0 0 0 0 0 0 0
39033 - 0 0 0 0 0 0 0 0 0 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 0 0 0 0 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 0 0 0
39041 - 0 0 0 0 0 0 0 0 0 0 0 0
39042 - 0 0 0 0 0 0 0 0 0 6 6 6
39043 - 22 22 22 62 62 62 62 62 62 2 2 6
39044 - 2 2 6 2 2 6 2 2 6 2 2 6
39045 - 2 2 6 2 2 6 2 2 6 2 2 6
39046 - 2 2 6 2 2 6 2 2 6 26 26 26
39047 - 54 54 54 38 38 38 18 18 18 10 10 10
39048 - 2 2 6 2 2 6 34 34 34 82 82 82
39049 - 38 38 38 14 14 14 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 0 0 0
39055 - 0 0 0 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 0 0 0
39057 - 0 0 0 0 0 1 0 0 1 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 0 0 0
39061 - 0 0 0 0 0 0 0 0 0 0 0 0
39062 - 0 0 0 0 0 0 0 0 0 6 6 6
39063 - 30 30 30 78 78 78 30 30 30 2 2 6
39064 - 2 2 6 2 2 6 2 2 6 2 2 6
39065 - 2 2 6 2 2 6 2 2 6 2 2 6
39066 - 2 2 6 2 2 6 2 2 6 10 10 10
39067 - 10 10 10 2 2 6 2 2 6 2 2 6
39068 - 2 2 6 2 2 6 2 2 6 78 78 78
39069 - 50 50 50 18 18 18 6 6 6 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 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 0 0 0
39077 - 0 0 1 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 10 10 10
39083 - 38 38 38 86 86 86 14 14 14 2 2 6
39084 - 2 2 6 2 2 6 2 2 6 2 2 6
39085 - 2 2 6 2 2 6 2 2 6 2 2 6
39086 - 2 2 6 2 2 6 2 2 6 2 2 6
39087 - 2 2 6 2 2 6 2 2 6 2 2 6
39088 - 2 2 6 2 2 6 2 2 6 54 54 54
39089 - 66 66 66 26 26 26 6 6 6 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 0 0 0
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 0 0 0
39097 - 0 0 0 0 0 1 0 0 1 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 0 0 0
39101 - 0 0 0 0 0 0 0 0 0 0 0 0
39102 - 0 0 0 0 0 0 0 0 0 14 14 14
39103 - 42 42 42 82 82 82 2 2 6 2 2 6
39104 - 2 2 6 6 6 6 10 10 10 2 2 6
39105 - 2 2 6 2 2 6 2 2 6 2 2 6
39106 - 2 2 6 2 2 6 2 2 6 6 6 6
39107 - 14 14 14 10 10 10 2 2 6 2 2 6
39108 - 2 2 6 2 2 6 2 2 6 18 18 18
39109 - 82 82 82 34 34 34 10 10 10 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 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 0 0 1 0 0 0 0 0 0 0 0 0
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 0 0 0
39121 - 0 0 0 0 0 0 0 0 0 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 14 14 14
39123 - 46 46 46 86 86 86 2 2 6 2 2 6
39124 - 6 6 6 6 6 6 22 22 22 34 34 34
39125 - 6 6 6 2 2 6 2 2 6 2 2 6
39126 - 2 2 6 2 2 6 18 18 18 34 34 34
39127 - 10 10 10 50 50 50 22 22 22 2 2 6
39128 - 2 2 6 2 2 6 2 2 6 10 10 10
39129 - 86 86 86 42 42 42 14 14 14 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 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 0 0 0
39137 - 0 0 1 0 0 1 0 0 1 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 0 0 0
39141 - 0 0 0 0 0 0 0 0 0 0 0 0
39142 - 0 0 0 0 0 0 0 0 0 14 14 14
39143 - 46 46 46 86 86 86 2 2 6 2 2 6
39144 - 38 38 38 116 116 116 94 94 94 22 22 22
39145 - 22 22 22 2 2 6 2 2 6 2 2 6
39146 - 14 14 14 86 86 86 138 138 138 162 162 162
39147 -154 154 154 38 38 38 26 26 26 6 6 6
39148 - 2 2 6 2 2 6 2 2 6 2 2 6
39149 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 0 0 0 0 0 0
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 0 0 0 0 0 0 0 0 0
39161 - 0 0 0 0 0 0 0 0 0 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 14 14 14
39163 - 46 46 46 86 86 86 2 2 6 14 14 14
39164 -134 134 134 198 198 198 195 195 195 116 116 116
39165 - 10 10 10 2 2 6 2 2 6 6 6 6
39166 -101 98 89 187 187 187 210 210 210 218 218 218
39167 -214 214 214 134 134 134 14 14 14 6 6 6
39168 - 2 2 6 2 2 6 2 2 6 2 2 6
39169 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 0 0 0 0 0 1 0 0 0
39177 - 0 0 1 0 0 1 0 0 1 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 0 0 0
39181 - 0 0 0 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 0 0 0 0 0 0 14 14 14
39183 - 46 46 46 86 86 86 2 2 6 54 54 54
39184 -218 218 218 195 195 195 226 226 226 246 246 246
39185 - 58 58 58 2 2 6 2 2 6 30 30 30
39186 -210 210 210 253 253 253 174 174 174 123 123 123
39187 -221 221 221 234 234 234 74 74 74 2 2 6
39188 - 2 2 6 2 2 6 2 2 6 2 2 6
39189 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39195 - 0 0 0 0 0 0 0 0 0 0 0 0
39196 - 0 0 0 0 0 0 0 0 0 0 0 0
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 0 0 0
39201 - 0 0 0 0 0 0 0 0 0 0 0 0
39202 - 0 0 0 0 0 0 0 0 0 14 14 14
39203 - 46 46 46 82 82 82 2 2 6 106 106 106
39204 -170 170 170 26 26 26 86 86 86 226 226 226
39205 -123 123 123 10 10 10 14 14 14 46 46 46
39206 -231 231 231 190 190 190 6 6 6 70 70 70
39207 - 90 90 90 238 238 238 158 158 158 2 2 6
39208 - 2 2 6 2 2 6 2 2 6 2 2 6
39209 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39215 - 0 0 0 0 0 0 0 0 0 0 0 0
39216 - 0 0 0 0 0 0 0 0 1 0 0 0
39217 - 0 0 1 0 0 1 0 0 1 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 14 14 14
39223 - 42 42 42 86 86 86 6 6 6 116 116 116
39224 -106 106 106 6 6 6 70 70 70 149 149 149
39225 -128 128 128 18 18 18 38 38 38 54 54 54
39226 -221 221 221 106 106 106 2 2 6 14 14 14
39227 - 46 46 46 190 190 190 198 198 198 2 2 6
39228 - 2 2 6 2 2 6 2 2 6 2 2 6
39229 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
39235 - 0 0 0 0 0 0 0 0 0 0 0 0
39236 - 0 0 0 0 0 0 0 0 1 0 0 0
39237 - 0 0 1 0 0 0 0 0 1 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 14 14 14
39243 - 42 42 42 94 94 94 14 14 14 101 101 101
39244 -128 128 128 2 2 6 18 18 18 116 116 116
39245 -118 98 46 121 92 8 121 92 8 98 78 10
39246 -162 162 162 106 106 106 2 2 6 2 2 6
39247 - 2 2 6 195 195 195 195 195 195 6 6 6
39248 - 2 2 6 2 2 6 2 2 6 2 2 6
39249 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
39255 - 0 0 0 0 0 0 0 0 0 0 0 0
39256 - 0 0 0 0 0 0 0 0 1 0 0 1
39257 - 0 0 1 0 0 0 0 0 1 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 10 10 10
39263 - 38 38 38 90 90 90 14 14 14 58 58 58
39264 -210 210 210 26 26 26 54 38 6 154 114 10
39265 -226 170 11 236 186 11 225 175 15 184 144 12
39266 -215 174 15 175 146 61 37 26 9 2 2 6
39267 - 70 70 70 246 246 246 138 138 138 2 2 6
39268 - 2 2 6 2 2 6 2 2 6 2 2 6
39269 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39275 - 0 0 0 0 0 0 0 0 0 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 10 10 10
39283 - 38 38 38 86 86 86 14 14 14 10 10 10
39284 -195 195 195 188 164 115 192 133 9 225 175 15
39285 -239 182 13 234 190 10 232 195 16 232 200 30
39286 -245 207 45 241 208 19 232 195 16 184 144 12
39287 -218 194 134 211 206 186 42 42 42 2 2 6
39288 - 2 2 6 2 2 6 2 2 6 2 2 6
39289 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
39296 - 0 0 0 0 0 0 0 0 0 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 10 10 10
39303 - 34 34 34 86 86 86 14 14 14 2 2 6
39304 -121 87 25 192 133 9 219 162 10 239 182 13
39305 -236 186 11 232 195 16 241 208 19 244 214 54
39306 -246 218 60 246 218 38 246 215 20 241 208 19
39307 -241 208 19 226 184 13 121 87 25 2 2 6
39308 - 2 2 6 2 2 6 2 2 6 2 2 6
39309 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39315 - 0 0 0 0 0 0 0 0 0 0 0 0
39316 - 0 0 0 0 0 0 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 10 10 10
39323 - 34 34 34 82 82 82 30 30 30 61 42 6
39324 -180 123 7 206 145 10 230 174 11 239 182 13
39325 -234 190 10 238 202 15 241 208 19 246 218 74
39326 -246 218 38 246 215 20 246 215 20 246 215 20
39327 -226 184 13 215 174 15 184 144 12 6 6 6
39328 - 2 2 6 2 2 6 2 2 6 2 2 6
39329 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
39335 - 0 0 0 0 0 0 0 0 0 0 0 0
39336 - 0 0 0 0 0 0 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 10 10 10
39343 - 30 30 30 78 78 78 50 50 50 104 69 6
39344 -192 133 9 216 158 10 236 178 12 236 186 11
39345 -232 195 16 241 208 19 244 214 54 245 215 43
39346 -246 215 20 246 215 20 241 208 19 198 155 10
39347 -200 144 11 216 158 10 156 118 10 2 2 6
39348 - 2 2 6 2 2 6 2 2 6 2 2 6
39349 - 6 6 6 90 90 90 54 54 54 18 18 18
39350 - 6 6 6 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 0 0 0 0 0 0
39355 - 0 0 0 0 0 0 0 0 0 0 0 0
39356 - 0 0 0 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 10 10 10
39363 - 30 30 30 78 78 78 46 46 46 22 22 22
39364 -137 92 6 210 162 10 239 182 13 238 190 10
39365 -238 202 15 241 208 19 246 215 20 246 215 20
39366 -241 208 19 203 166 17 185 133 11 210 150 10
39367 -216 158 10 210 150 10 102 78 10 2 2 6
39368 - 6 6 6 54 54 54 14 14 14 2 2 6
39369 - 2 2 6 62 62 62 74 74 74 30 30 30
39370 - 10 10 10 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 0 0 0 0 0 0
39375 - 0 0 0 0 0 0 0 0 0 0 0 0
39376 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 10 10 10
39383 - 34 34 34 78 78 78 50 50 50 6 6 6
39384 - 94 70 30 139 102 15 190 146 13 226 184 13
39385 -232 200 30 232 195 16 215 174 15 190 146 13
39386 -168 122 10 192 133 9 210 150 10 213 154 11
39387 -202 150 34 182 157 106 101 98 89 2 2 6
39388 - 2 2 6 78 78 78 116 116 116 58 58 58
39389 - 2 2 6 22 22 22 90 90 90 46 46 46
39390 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 0 0 0
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 10 10 10
39403 - 38 38 38 86 86 86 50 50 50 6 6 6
39404 -128 128 128 174 154 114 156 107 11 168 122 10
39405 -198 155 10 184 144 12 197 138 11 200 144 11
39406 -206 145 10 206 145 10 197 138 11 188 164 115
39407 -195 195 195 198 198 198 174 174 174 14 14 14
39408 - 2 2 6 22 22 22 116 116 116 116 116 116
39409 - 22 22 22 2 2 6 74 74 74 70 70 70
39410 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 0 0 0
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 6 6 6 18 18 18
39423 - 50 50 50 101 101 101 26 26 26 10 10 10
39424 -138 138 138 190 190 190 174 154 114 156 107 11
39425 -197 138 11 200 144 11 197 138 11 192 133 9
39426 -180 123 7 190 142 34 190 178 144 187 187 187
39427 -202 202 202 221 221 221 214 214 214 66 66 66
39428 - 2 2 6 2 2 6 50 50 50 62 62 62
39429 - 6 6 6 2 2 6 10 10 10 90 90 90
39430 - 50 50 50 18 18 18 6 6 6 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 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 0 0 0 0 0 0
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 10 10 10 34 34 34
39443 - 74 74 74 74 74 74 2 2 6 6 6 6
39444 -144 144 144 198 198 198 190 190 190 178 166 146
39445 -154 121 60 156 107 11 156 107 11 168 124 44
39446 -174 154 114 187 187 187 190 190 190 210 210 210
39447 -246 246 246 253 253 253 253 253 253 182 182 182
39448 - 6 6 6 2 2 6 2 2 6 2 2 6
39449 - 2 2 6 2 2 6 2 2 6 62 62 62
39450 - 74 74 74 34 34 34 14 14 14 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 0 0 0
39454 - 0 0 0 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 0 0 0 0 0 0 0 0 0
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 10 10 10 22 22 22 54 54 54
39463 - 94 94 94 18 18 18 2 2 6 46 46 46
39464 -234 234 234 221 221 221 190 190 190 190 190 190
39465 -190 190 190 187 187 187 187 187 187 190 190 190
39466 -190 190 190 195 195 195 214 214 214 242 242 242
39467 -253 253 253 253 253 253 253 253 253 253 253 253
39468 - 82 82 82 2 2 6 2 2 6 2 2 6
39469 - 2 2 6 2 2 6 2 2 6 14 14 14
39470 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 0 0 0 0
39475 - 0 0 0 0 0 0 0 0 0 0 0 0
39476 - 0 0 0 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 6 6 6 18 18 18 46 46 46 90 90 90
39483 - 46 46 46 18 18 18 6 6 6 182 182 182
39484 -253 253 253 246 246 246 206 206 206 190 190 190
39485 -190 190 190 190 190 190 190 190 190 190 190 190
39486 -206 206 206 231 231 231 250 250 250 253 253 253
39487 -253 253 253 253 253 253 253 253 253 253 253 253
39488 -202 202 202 14 14 14 2 2 6 2 2 6
39489 - 2 2 6 2 2 6 2 2 6 2 2 6
39490 - 42 42 42 86 86 86 42 42 42 18 18 18
39491 - 6 6 6 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 0 0 0 0 0 0 0 0 0
39494 - 0 0 0 0 0 0 0 0 0 0 0 0
39495 - 0 0 0 0 0 0 0 0 0 0 0 0
39496 - 0 0 0 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 6 6 6
39502 - 14 14 14 38 38 38 74 74 74 66 66 66
39503 - 2 2 6 6 6 6 90 90 90 250 250 250
39504 -253 253 253 253 253 253 238 238 238 198 198 198
39505 -190 190 190 190 190 190 195 195 195 221 221 221
39506 -246 246 246 253 253 253 253 253 253 253 253 253
39507 -253 253 253 253 253 253 253 253 253 253 253 253
39508 -253 253 253 82 82 82 2 2 6 2 2 6
39509 - 2 2 6 2 2 6 2 2 6 2 2 6
39510 - 2 2 6 78 78 78 70 70 70 34 34 34
39511 - 14 14 14 6 6 6 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 0 0 0 0
39515 - 0 0 0 0 0 0 0 0 0 0 0 0
39516 - 0 0 0 0 0 0 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 14 14 14
39522 - 34 34 34 66 66 66 78 78 78 6 6 6
39523 - 2 2 6 18 18 18 218 218 218 253 253 253
39524 -253 253 253 253 253 253 253 253 253 246 246 246
39525 -226 226 226 231 231 231 246 246 246 253 253 253
39526 -253 253 253 253 253 253 253 253 253 253 253 253
39527 -253 253 253 253 253 253 253 253 253 253 253 253
39528 -253 253 253 178 178 178 2 2 6 2 2 6
39529 - 2 2 6 2 2 6 2 2 6 2 2 6
39530 - 2 2 6 18 18 18 90 90 90 62 62 62
39531 - 30 30 30 10 10 10 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 0 0 0 0 0 0 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 10 10 10 26 26 26
39542 - 58 58 58 90 90 90 18 18 18 2 2 6
39543 - 2 2 6 110 110 110 253 253 253 253 253 253
39544 -253 253 253 253 253 253 253 253 253 253 253 253
39545 -250 250 250 253 253 253 253 253 253 253 253 253
39546 -253 253 253 253 253 253 253 253 253 253 253 253
39547 -253 253 253 253 253 253 253 253 253 253 253 253
39548 -253 253 253 231 231 231 18 18 18 2 2 6
39549 - 2 2 6 2 2 6 2 2 6 2 2 6
39550 - 2 2 6 2 2 6 18 18 18 94 94 94
39551 - 54 54 54 26 26 26 10 10 10 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 6 6 6 22 22 22 50 50 50
39562 - 90 90 90 26 26 26 2 2 6 2 2 6
39563 - 14 14 14 195 195 195 250 250 250 253 253 253
39564 -253 253 253 253 253 253 253 253 253 253 253 253
39565 -253 253 253 253 253 253 253 253 253 253 253 253
39566 -253 253 253 253 253 253 253 253 253 253 253 253
39567 -253 253 253 253 253 253 253 253 253 253 253 253
39568 -250 250 250 242 242 242 54 54 54 2 2 6
39569 - 2 2 6 2 2 6 2 2 6 2 2 6
39570 - 2 2 6 2 2 6 2 2 6 38 38 38
39571 - 86 86 86 50 50 50 22 22 22 6 6 6
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 6 6 6 14 14 14 38 38 38 82 82 82
39582 - 34 34 34 2 2 6 2 2 6 2 2 6
39583 - 42 42 42 195 195 195 246 246 246 253 253 253
39584 -253 253 253 253 253 253 253 253 253 250 250 250
39585 -242 242 242 242 242 242 250 250 250 253 253 253
39586 -253 253 253 253 253 253 253 253 253 253 253 253
39587 -253 253 253 250 250 250 246 246 246 238 238 238
39588 -226 226 226 231 231 231 101 101 101 6 6 6
39589 - 2 2 6 2 2 6 2 2 6 2 2 6
39590 - 2 2 6 2 2 6 2 2 6 2 2 6
39591 - 38 38 38 82 82 82 42 42 42 14 14 14
39592 - 6 6 6 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 10 10 10 26 26 26 62 62 62 66 66 66
39602 - 2 2 6 2 2 6 2 2 6 6 6 6
39603 - 70 70 70 170 170 170 206 206 206 234 234 234
39604 -246 246 246 250 250 250 250 250 250 238 238 238
39605 -226 226 226 231 231 231 238 238 238 250 250 250
39606 -250 250 250 250 250 250 246 246 246 231 231 231
39607 -214 214 214 206 206 206 202 202 202 202 202 202
39608 -198 198 198 202 202 202 182 182 182 18 18 18
39609 - 2 2 6 2 2 6 2 2 6 2 2 6
39610 - 2 2 6 2 2 6 2 2 6 2 2 6
39611 - 2 2 6 62 62 62 66 66 66 30 30 30
39612 - 10 10 10 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 14 14 14 42 42 42 82 82 82 18 18 18
39622 - 2 2 6 2 2 6 2 2 6 10 10 10
39623 - 94 94 94 182 182 182 218 218 218 242 242 242
39624 -250 250 250 253 253 253 253 253 253 250 250 250
39625 -234 234 234 253 253 253 253 253 253 253 253 253
39626 -253 253 253 253 253 253 253 253 253 246 246 246
39627 -238 238 238 226 226 226 210 210 210 202 202 202
39628 -195 195 195 195 195 195 210 210 210 158 158 158
39629 - 6 6 6 14 14 14 50 50 50 14 14 14
39630 - 2 2 6 2 2 6 2 2 6 2 2 6
39631 - 2 2 6 6 6 6 86 86 86 46 46 46
39632 - 18 18 18 6 6 6 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 6 6 6
39641 - 22 22 22 54 54 54 70 70 70 2 2 6
39642 - 2 2 6 10 10 10 2 2 6 22 22 22
39643 -166 166 166 231 231 231 250 250 250 253 253 253
39644 -253 253 253 253 253 253 253 253 253 250 250 250
39645 -242 242 242 253 253 253 253 253 253 253 253 253
39646 -253 253 253 253 253 253 253 253 253 253 253 253
39647 -253 253 253 253 253 253 253 253 253 246 246 246
39648 -231 231 231 206 206 206 198 198 198 226 226 226
39649 - 94 94 94 2 2 6 6 6 6 38 38 38
39650 - 30 30 30 2 2 6 2 2 6 2 2 6
39651 - 2 2 6 2 2 6 62 62 62 66 66 66
39652 - 26 26 26 10 10 10 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 10 10 10
39661 - 30 30 30 74 74 74 50 50 50 2 2 6
39662 - 26 26 26 26 26 26 2 2 6 106 106 106
39663 -238 238 238 253 253 253 253 253 253 253 253 253
39664 -253 253 253 253 253 253 253 253 253 253 253 253
39665 -253 253 253 253 253 253 253 253 253 253 253 253
39666 -253 253 253 253 253 253 253 253 253 253 253 253
39667 -253 253 253 253 253 253 253 253 253 253 253 253
39668 -253 253 253 246 246 246 218 218 218 202 202 202
39669 -210 210 210 14 14 14 2 2 6 2 2 6
39670 - 30 30 30 22 22 22 2 2 6 2 2 6
39671 - 2 2 6 2 2 6 18 18 18 86 86 86
39672 - 42 42 42 14 14 14 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 14 14 14
39681 - 42 42 42 90 90 90 22 22 22 2 2 6
39682 - 42 42 42 2 2 6 18 18 18 218 218 218
39683 -253 253 253 253 253 253 253 253 253 253 253 253
39684 -253 253 253 253 253 253 253 253 253 253 253 253
39685 -253 253 253 253 253 253 253 253 253 253 253 253
39686 -253 253 253 253 253 253 253 253 253 253 253 253
39687 -253 253 253 253 253 253 253 253 253 253 253 253
39688 -253 253 253 253 253 253 250 250 250 221 221 221
39689 -218 218 218 101 101 101 2 2 6 14 14 14
39690 - 18 18 18 38 38 38 10 10 10 2 2 6
39691 - 2 2 6 2 2 6 2 2 6 78 78 78
39692 - 58 58 58 22 22 22 6 6 6 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 6 6 6 18 18 18
39701 - 54 54 54 82 82 82 2 2 6 26 26 26
39702 - 22 22 22 2 2 6 123 123 123 253 253 253
39703 -253 253 253 253 253 253 253 253 253 253 253 253
39704 -253 253 253 253 253 253 253 253 253 253 253 253
39705 -253 253 253 253 253 253 253 253 253 253 253 253
39706 -253 253 253 253 253 253 253 253 253 253 253 253
39707 -253 253 253 253 253 253 253 253 253 253 253 253
39708 -253 253 253 253 253 253 253 253 253 250 250 250
39709 -238 238 238 198 198 198 6 6 6 38 38 38
39710 - 58 58 58 26 26 26 38 38 38 2 2 6
39711 - 2 2 6 2 2 6 2 2 6 46 46 46
39712 - 78 78 78 30 30 30 10 10 10 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 10 10 10 30 30 30
39721 - 74 74 74 58 58 58 2 2 6 42 42 42
39722 - 2 2 6 22 22 22 231 231 231 253 253 253
39723 -253 253 253 253 253 253 253 253 253 253 253 253
39724 -253 253 253 253 253 253 253 253 253 250 250 250
39725 -253 253 253 253 253 253 253 253 253 253 253 253
39726 -253 253 253 253 253 253 253 253 253 253 253 253
39727 -253 253 253 253 253 253 253 253 253 253 253 253
39728 -253 253 253 253 253 253 253 253 253 253 253 253
39729 -253 253 253 246 246 246 46 46 46 38 38 38
39730 - 42 42 42 14 14 14 38 38 38 14 14 14
39731 - 2 2 6 2 2 6 2 2 6 6 6 6
39732 - 86 86 86 46 46 46 14 14 14 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 6 6 6 14 14 14 42 42 42
39741 - 90 90 90 18 18 18 18 18 18 26 26 26
39742 - 2 2 6 116 116 116 253 253 253 253 253 253
39743 -253 253 253 253 253 253 253 253 253 253 253 253
39744 -253 253 253 253 253 253 250 250 250 238 238 238
39745 -253 253 253 253 253 253 253 253 253 253 253 253
39746 -253 253 253 253 253 253 253 253 253 253 253 253
39747 -253 253 253 253 253 253 253 253 253 253 253 253
39748 -253 253 253 253 253 253 253 253 253 253 253 253
39749 -253 253 253 253 253 253 94 94 94 6 6 6
39750 - 2 2 6 2 2 6 10 10 10 34 34 34
39751 - 2 2 6 2 2 6 2 2 6 2 2 6
39752 - 74 74 74 58 58 58 22 22 22 6 6 6
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 10 10 10 26 26 26 66 66 66
39761 - 82 82 82 2 2 6 38 38 38 6 6 6
39762 - 14 14 14 210 210 210 253 253 253 253 253 253
39763 -253 253 253 253 253 253 253 253 253 253 253 253
39764 -253 253 253 253 253 253 246 246 246 242 242 242
39765 -253 253 253 253 253 253 253 253 253 253 253 253
39766 -253 253 253 253 253 253 253 253 253 253 253 253
39767 -253 253 253 253 253 253 253 253 253 253 253 253
39768 -253 253 253 253 253 253 253 253 253 253 253 253
39769 -253 253 253 253 253 253 144 144 144 2 2 6
39770 - 2 2 6 2 2 6 2 2 6 46 46 46
39771 - 2 2 6 2 2 6 2 2 6 2 2 6
39772 - 42 42 42 74 74 74 30 30 30 10 10 10
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 6 6 6 14 14 14 42 42 42 90 90 90
39781 - 26 26 26 6 6 6 42 42 42 2 2 6
39782 - 74 74 74 250 250 250 253 253 253 253 253 253
39783 -253 253 253 253 253 253 253 253 253 253 253 253
39784 -253 253 253 253 253 253 242 242 242 242 242 242
39785 -253 253 253 253 253 253 253 253 253 253 253 253
39786 -253 253 253 253 253 253 253 253 253 253 253 253
39787 -253 253 253 253 253 253 253 253 253 253 253 253
39788 -253 253 253 253 253 253 253 253 253 253 253 253
39789 -253 253 253 253 253 253 182 182 182 2 2 6
39790 - 2 2 6 2 2 6 2 2 6 46 46 46
39791 - 2 2 6 2 2 6 2 2 6 2 2 6
39792 - 10 10 10 86 86 86 38 38 38 10 10 10
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 10 10 10 26 26 26 66 66 66 82 82 82
39801 - 2 2 6 22 22 22 18 18 18 2 2 6
39802 -149 149 149 253 253 253 253 253 253 253 253 253
39803 -253 253 253 253 253 253 253 253 253 253 253 253
39804 -253 253 253 253 253 253 234 234 234 242 242 242
39805 -253 253 253 253 253 253 253 253 253 253 253 253
39806 -253 253 253 253 253 253 253 253 253 253 253 253
39807 -253 253 253 253 253 253 253 253 253 253 253 253
39808 -253 253 253 253 253 253 253 253 253 253 253 253
39809 -253 253 253 253 253 253 206 206 206 2 2 6
39810 - 2 2 6 2 2 6 2 2 6 38 38 38
39811 - 2 2 6 2 2 6 2 2 6 2 2 6
39812 - 6 6 6 86 86 86 46 46 46 14 14 14
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 6 6 6
39820 - 18 18 18 46 46 46 86 86 86 18 18 18
39821 - 2 2 6 34 34 34 10 10 10 6 6 6
39822 -210 210 210 253 253 253 253 253 253 253 253 253
39823 -253 253 253 253 253 253 253 253 253 253 253 253
39824 -253 253 253 253 253 253 234 234 234 242 242 242
39825 -253 253 253 253 253 253 253 253 253 253 253 253
39826 -253 253 253 253 253 253 253 253 253 253 253 253
39827 -253 253 253 253 253 253 253 253 253 253 253 253
39828 -253 253 253 253 253 253 253 253 253 253 253 253
39829 -253 253 253 253 253 253 221 221 221 6 6 6
39830 - 2 2 6 2 2 6 6 6 6 30 30 30
39831 - 2 2 6 2 2 6 2 2 6 2 2 6
39832 - 2 2 6 82 82 82 54 54 54 18 18 18
39833 - 6 6 6 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 10 10 10
39840 - 26 26 26 66 66 66 62 62 62 2 2 6
39841 - 2 2 6 38 38 38 10 10 10 26 26 26
39842 -238 238 238 253 253 253 253 253 253 253 253 253
39843 -253 253 253 253 253 253 253 253 253 253 253 253
39844 -253 253 253 253 253 253 231 231 231 238 238 238
39845 -253 253 253 253 253 253 253 253 253 253 253 253
39846 -253 253 253 253 253 253 253 253 253 253 253 253
39847 -253 253 253 253 253 253 253 253 253 253 253 253
39848 -253 253 253 253 253 253 253 253 253 253 253 253
39849 -253 253 253 253 253 253 231 231 231 6 6 6
39850 - 2 2 6 2 2 6 10 10 10 30 30 30
39851 - 2 2 6 2 2 6 2 2 6 2 2 6
39852 - 2 2 6 66 66 66 58 58 58 22 22 22
39853 - 6 6 6 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 10 10 10
39860 - 38 38 38 78 78 78 6 6 6 2 2 6
39861 - 2 2 6 46 46 46 14 14 14 42 42 42
39862 -246 246 246 253 253 253 253 253 253 253 253 253
39863 -253 253 253 253 253 253 253 253 253 253 253 253
39864 -253 253 253 253 253 253 231 231 231 242 242 242
39865 -253 253 253 253 253 253 253 253 253 253 253 253
39866 -253 253 253 253 253 253 253 253 253 253 253 253
39867 -253 253 253 253 253 253 253 253 253 253 253 253
39868 -253 253 253 253 253 253 253 253 253 253 253 253
39869 -253 253 253 253 253 253 234 234 234 10 10 10
39870 - 2 2 6 2 2 6 22 22 22 14 14 14
39871 - 2 2 6 2 2 6 2 2 6 2 2 6
39872 - 2 2 6 66 66 66 62 62 62 22 22 22
39873 - 6 6 6 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 6 6 6 18 18 18
39880 - 50 50 50 74 74 74 2 2 6 2 2 6
39881 - 14 14 14 70 70 70 34 34 34 62 62 62
39882 -250 250 250 253 253 253 253 253 253 253 253 253
39883 -253 253 253 253 253 253 253 253 253 253 253 253
39884 -253 253 253 253 253 253 231 231 231 246 246 246
39885 -253 253 253 253 253 253 253 253 253 253 253 253
39886 -253 253 253 253 253 253 253 253 253 253 253 253
39887 -253 253 253 253 253 253 253 253 253 253 253 253
39888 -253 253 253 253 253 253 253 253 253 253 253 253
39889 -253 253 253 253 253 253 234 234 234 14 14 14
39890 - 2 2 6 2 2 6 30 30 30 2 2 6
39891 - 2 2 6 2 2 6 2 2 6 2 2 6
39892 - 2 2 6 66 66 66 62 62 62 22 22 22
39893 - 6 6 6 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 6 6 6 18 18 18
39900 - 54 54 54 62 62 62 2 2 6 2 2 6
39901 - 2 2 6 30 30 30 46 46 46 70 70 70
39902 -250 250 250 253 253 253 253 253 253 253 253 253
39903 -253 253 253 253 253 253 253 253 253 253 253 253
39904 -253 253 253 253 253 253 231 231 231 246 246 246
39905 -253 253 253 253 253 253 253 253 253 253 253 253
39906 -253 253 253 253 253 253 253 253 253 253 253 253
39907 -253 253 253 253 253 253 253 253 253 253 253 253
39908 -253 253 253 253 253 253 253 253 253 253 253 253
39909 -253 253 253 253 253 253 226 226 226 10 10 10
39910 - 2 2 6 6 6 6 30 30 30 2 2 6
39911 - 2 2 6 2 2 6 2 2 6 2 2 6
39912 - 2 2 6 66 66 66 58 58 58 22 22 22
39913 - 6 6 6 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 6 6 6 22 22 22
39920 - 58 58 58 62 62 62 2 2 6 2 2 6
39921 - 2 2 6 2 2 6 30 30 30 78 78 78
39922 -250 250 250 253 253 253 253 253 253 253 253 253
39923 -253 253 253 253 253 253 253 253 253 253 253 253
39924 -253 253 253 253 253 253 231 231 231 246 246 246
39925 -253 253 253 253 253 253 253 253 253 253 253 253
39926 -253 253 253 253 253 253 253 253 253 253 253 253
39927 -253 253 253 253 253 253 253 253 253 253 253 253
39928 -253 253 253 253 253 253 253 253 253 253 253 253
39929 -253 253 253 253 253 253 206 206 206 2 2 6
39930 - 22 22 22 34 34 34 18 14 6 22 22 22
39931 - 26 26 26 18 18 18 6 6 6 2 2 6
39932 - 2 2 6 82 82 82 54 54 54 18 18 18
39933 - 6 6 6 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 6 6 6 26 26 26
39940 - 62 62 62 106 106 106 74 54 14 185 133 11
39941 -210 162 10 121 92 8 6 6 6 62 62 62
39942 -238 238 238 253 253 253 253 253 253 253 253 253
39943 -253 253 253 253 253 253 253 253 253 253 253 253
39944 -253 253 253 253 253 253 231 231 231 246 246 246
39945 -253 253 253 253 253 253 253 253 253 253 253 253
39946 -253 253 253 253 253 253 253 253 253 253 253 253
39947 -253 253 253 253 253 253 253 253 253 253 253 253
39948 -253 253 253 253 253 253 253 253 253 253 253 253
39949 -253 253 253 253 253 253 158 158 158 18 18 18
39950 - 14 14 14 2 2 6 2 2 6 2 2 6
39951 - 6 6 6 18 18 18 66 66 66 38 38 38
39952 - 6 6 6 94 94 94 50 50 50 18 18 18
39953 - 6 6 6 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 6 6 6
39959 - 10 10 10 10 10 10 18 18 18 38 38 38
39960 - 78 78 78 142 134 106 216 158 10 242 186 14
39961 -246 190 14 246 190 14 156 118 10 10 10 10
39962 - 90 90 90 238 238 238 253 253 253 253 253 253
39963 -253 253 253 253 253 253 253 253 253 253 253 253
39964 -253 253 253 253 253 253 231 231 231 250 250 250
39965 -253 253 253 253 253 253 253 253 253 253 253 253
39966 -253 253 253 253 253 253 253 253 253 253 253 253
39967 -253 253 253 253 253 253 253 253 253 253 253 253
39968 -253 253 253 253 253 253 253 253 253 246 230 190
39969 -238 204 91 238 204 91 181 142 44 37 26 9
39970 - 2 2 6 2 2 6 2 2 6 2 2 6
39971 - 2 2 6 2 2 6 38 38 38 46 46 46
39972 - 26 26 26 106 106 106 54 54 54 18 18 18
39973 - 6 6 6 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 6 6 6 14 14 14 22 22 22
39979 - 30 30 30 38 38 38 50 50 50 70 70 70
39980 -106 106 106 190 142 34 226 170 11 242 186 14
39981 -246 190 14 246 190 14 246 190 14 154 114 10
39982 - 6 6 6 74 74 74 226 226 226 253 253 253
39983 -253 253 253 253 253 253 253 253 253 253 253 253
39984 -253 253 253 253 253 253 231 231 231 250 250 250
39985 -253 253 253 253 253 253 253 253 253 253 253 253
39986 -253 253 253 253 253 253 253 253 253 253 253 253
39987 -253 253 253 253 253 253 253 253 253 253 253 253
39988 -253 253 253 253 253 253 253 253 253 228 184 62
39989 -241 196 14 241 208 19 232 195 16 38 30 10
39990 - 2 2 6 2 2 6 2 2 6 2 2 6
39991 - 2 2 6 6 6 6 30 30 30 26 26 26
39992 -203 166 17 154 142 90 66 66 66 26 26 26
39993 - 6 6 6 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 6 6 6 18 18 18 38 38 38 58 58 58
39999 - 78 78 78 86 86 86 101 101 101 123 123 123
40000 -175 146 61 210 150 10 234 174 13 246 186 14
40001 -246 190 14 246 190 14 246 190 14 238 190 10
40002 -102 78 10 2 2 6 46 46 46 198 198 198
40003 -253 253 253 253 253 253 253 253 253 253 253 253
40004 -253 253 253 253 253 253 234 234 234 242 242 242
40005 -253 253 253 253 253 253 253 253 253 253 253 253
40006 -253 253 253 253 253 253 253 253 253 253 253 253
40007 -253 253 253 253 253 253 253 253 253 253 253 253
40008 -253 253 253 253 253 253 253 253 253 224 178 62
40009 -242 186 14 241 196 14 210 166 10 22 18 6
40010 - 2 2 6 2 2 6 2 2 6 2 2 6
40011 - 2 2 6 2 2 6 6 6 6 121 92 8
40012 -238 202 15 232 195 16 82 82 82 34 34 34
40013 - 10 10 10 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 14 14 14 38 38 38 70 70 70 154 122 46
40019 -190 142 34 200 144 11 197 138 11 197 138 11
40020 -213 154 11 226 170 11 242 186 14 246 190 14
40021 -246 190 14 246 190 14 246 190 14 246 190 14
40022 -225 175 15 46 32 6 2 2 6 22 22 22
40023 -158 158 158 250 250 250 253 253 253 253 253 253
40024 -253 253 253 253 253 253 253 253 253 253 253 253
40025 -253 253 253 253 253 253 253 253 253 253 253 253
40026 -253 253 253 253 253 253 253 253 253 253 253 253
40027 -253 253 253 253 253 253 253 253 253 253 253 253
40028 -253 253 253 250 250 250 242 242 242 224 178 62
40029 -239 182 13 236 186 11 213 154 11 46 32 6
40030 - 2 2 6 2 2 6 2 2 6 2 2 6
40031 - 2 2 6 2 2 6 61 42 6 225 175 15
40032 -238 190 10 236 186 11 112 100 78 42 42 42
40033 - 14 14 14 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 6 6 6
40038 - 22 22 22 54 54 54 154 122 46 213 154 11
40039 -226 170 11 230 174 11 226 170 11 226 170 11
40040 -236 178 12 242 186 14 246 190 14 246 190 14
40041 -246 190 14 246 190 14 246 190 14 246 190 14
40042 -241 196 14 184 144 12 10 10 10 2 2 6
40043 - 6 6 6 116 116 116 242 242 242 253 253 253
40044 -253 253 253 253 253 253 253 253 253 253 253 253
40045 -253 253 253 253 253 253 253 253 253 253 253 253
40046 -253 253 253 253 253 253 253 253 253 253 253 253
40047 -253 253 253 253 253 253 253 253 253 253 253 253
40048 -253 253 253 231 231 231 198 198 198 214 170 54
40049 -236 178 12 236 178 12 210 150 10 137 92 6
40050 - 18 14 6 2 2 6 2 2 6 2 2 6
40051 - 6 6 6 70 47 6 200 144 11 236 178 12
40052 -239 182 13 239 182 13 124 112 88 58 58 58
40053 - 22 22 22 6 6 6 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 10 10 10
40058 - 30 30 30 70 70 70 180 133 36 226 170 11
40059 -239 182 13 242 186 14 242 186 14 246 186 14
40060 -246 190 14 246 190 14 246 190 14 246 190 14
40061 -246 190 14 246 190 14 246 190 14 246 190 14
40062 -246 190 14 232 195 16 98 70 6 2 2 6
40063 - 2 2 6 2 2 6 66 66 66 221 221 221
40064 -253 253 253 253 253 253 253 253 253 253 253 253
40065 -253 253 253 253 253 253 253 253 253 253 253 253
40066 -253 253 253 253 253 253 253 253 253 253 253 253
40067 -253 253 253 253 253 253 253 253 253 253 253 253
40068 -253 253 253 206 206 206 198 198 198 214 166 58
40069 -230 174 11 230 174 11 216 158 10 192 133 9
40070 -163 110 8 116 81 8 102 78 10 116 81 8
40071 -167 114 7 197 138 11 226 170 11 239 182 13
40072 -242 186 14 242 186 14 162 146 94 78 78 78
40073 - 34 34 34 14 14 14 6 6 6 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 6 6 6
40078 - 30 30 30 78 78 78 190 142 34 226 170 11
40079 -239 182 13 246 190 14 246 190 14 246 190 14
40080 -246 190 14 246 190 14 246 190 14 246 190 14
40081 -246 190 14 246 190 14 246 190 14 246 190 14
40082 -246 190 14 241 196 14 203 166 17 22 18 6
40083 - 2 2 6 2 2 6 2 2 6 38 38 38
40084 -218 218 218 253 253 253 253 253 253 253 253 253
40085 -253 253 253 253 253 253 253 253 253 253 253 253
40086 -253 253 253 253 253 253 253 253 253 253 253 253
40087 -253 253 253 253 253 253 253 253 253 253 253 253
40088 -250 250 250 206 206 206 198 198 198 202 162 69
40089 -226 170 11 236 178 12 224 166 10 210 150 10
40090 -200 144 11 197 138 11 192 133 9 197 138 11
40091 -210 150 10 226 170 11 242 186 14 246 190 14
40092 -246 190 14 246 186 14 225 175 15 124 112 88
40093 - 62 62 62 30 30 30 14 14 14 6 6 6
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 10 10 10
40098 - 30 30 30 78 78 78 174 135 50 224 166 10
40099 -239 182 13 246 190 14 246 190 14 246 190 14
40100 -246 190 14 246 190 14 246 190 14 246 190 14
40101 -246 190 14 246 190 14 246 190 14 246 190 14
40102 -246 190 14 246 190 14 241 196 14 139 102 15
40103 - 2 2 6 2 2 6 2 2 6 2 2 6
40104 - 78 78 78 250 250 250 253 253 253 253 253 253
40105 -253 253 253 253 253 253 253 253 253 253 253 253
40106 -253 253 253 253 253 253 253 253 253 253 253 253
40107 -253 253 253 253 253 253 253 253 253 253 253 253
40108 -250 250 250 214 214 214 198 198 198 190 150 46
40109 -219 162 10 236 178 12 234 174 13 224 166 10
40110 -216 158 10 213 154 11 213 154 11 216 158 10
40111 -226 170 11 239 182 13 246 190 14 246 190 14
40112 -246 190 14 246 190 14 242 186 14 206 162 42
40113 -101 101 101 58 58 58 30 30 30 14 14 14
40114 - 6 6 6 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 10 10 10
40118 - 30 30 30 74 74 74 174 135 50 216 158 10
40119 -236 178 12 246 190 14 246 190 14 246 190 14
40120 -246 190 14 246 190 14 246 190 14 246 190 14
40121 -246 190 14 246 190 14 246 190 14 246 190 14
40122 -246 190 14 246 190 14 241 196 14 226 184 13
40123 - 61 42 6 2 2 6 2 2 6 2 2 6
40124 - 22 22 22 238 238 238 253 253 253 253 253 253
40125 -253 253 253 253 253 253 253 253 253 253 253 253
40126 -253 253 253 253 253 253 253 253 253 253 253 253
40127 -253 253 253 253 253 253 253 253 253 253 253 253
40128 -253 253 253 226 226 226 187 187 187 180 133 36
40129 -216 158 10 236 178 12 239 182 13 236 178 12
40130 -230 174 11 226 170 11 226 170 11 230 174 11
40131 -236 178 12 242 186 14 246 190 14 246 190 14
40132 -246 190 14 246 190 14 246 186 14 239 182 13
40133 -206 162 42 106 106 106 66 66 66 34 34 34
40134 - 14 14 14 6 6 6 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 6 6 6
40138 - 26 26 26 70 70 70 163 133 67 213 154 11
40139 -236 178 12 246 190 14 246 190 14 246 190 14
40140 -246 190 14 246 190 14 246 190 14 246 190 14
40141 -246 190 14 246 190 14 246 190 14 246 190 14
40142 -246 190 14 246 190 14 246 190 14 241 196 14
40143 -190 146 13 18 14 6 2 2 6 2 2 6
40144 - 46 46 46 246 246 246 253 253 253 253 253 253
40145 -253 253 253 253 253 253 253 253 253 253 253 253
40146 -253 253 253 253 253 253 253 253 253 253 253 253
40147 -253 253 253 253 253 253 253 253 253 253 253 253
40148 -253 253 253 221 221 221 86 86 86 156 107 11
40149 -216 158 10 236 178 12 242 186 14 246 186 14
40150 -242 186 14 239 182 13 239 182 13 242 186 14
40151 -242 186 14 246 186 14 246 190 14 246 190 14
40152 -246 190 14 246 190 14 246 190 14 246 190 14
40153 -242 186 14 225 175 15 142 122 72 66 66 66
40154 - 30 30 30 10 10 10 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 6 6 6
40158 - 26 26 26 70 70 70 163 133 67 210 150 10
40159 -236 178 12 246 190 14 246 190 14 246 190 14
40160 -246 190 14 246 190 14 246 190 14 246 190 14
40161 -246 190 14 246 190 14 246 190 14 246 190 14
40162 -246 190 14 246 190 14 246 190 14 246 190 14
40163 -232 195 16 121 92 8 34 34 34 106 106 106
40164 -221 221 221 253 253 253 253 253 253 253 253 253
40165 -253 253 253 253 253 253 253 253 253 253 253 253
40166 -253 253 253 253 253 253 253 253 253 253 253 253
40167 -253 253 253 253 253 253 253 253 253 253 253 253
40168 -242 242 242 82 82 82 18 14 6 163 110 8
40169 -216 158 10 236 178 12 242 186 14 246 190 14
40170 -246 190 14 246 190 14 246 190 14 246 190 14
40171 -246 190 14 246 190 14 246 190 14 246 190 14
40172 -246 190 14 246 190 14 246 190 14 246 190 14
40173 -246 190 14 246 190 14 242 186 14 163 133 67
40174 - 46 46 46 18 18 18 6 6 6 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 10 10 10
40178 - 30 30 30 78 78 78 163 133 67 210 150 10
40179 -236 178 12 246 186 14 246 190 14 246 190 14
40180 -246 190 14 246 190 14 246 190 14 246 190 14
40181 -246 190 14 246 190 14 246 190 14 246 190 14
40182 -246 190 14 246 190 14 246 190 14 246 190 14
40183 -241 196 14 215 174 15 190 178 144 253 253 253
40184 -253 253 253 253 253 253 253 253 253 253 253 253
40185 -253 253 253 253 253 253 253 253 253 253 253 253
40186 -253 253 253 253 253 253 253 253 253 253 253 253
40187 -253 253 253 253 253 253 253 253 253 218 218 218
40188 - 58 58 58 2 2 6 22 18 6 167 114 7
40189 -216 158 10 236 178 12 246 186 14 246 190 14
40190 -246 190 14 246 190 14 246 190 14 246 190 14
40191 -246 190 14 246 190 14 246 190 14 246 190 14
40192 -246 190 14 246 190 14 246 190 14 246 190 14
40193 -246 190 14 246 186 14 242 186 14 190 150 46
40194 - 54 54 54 22 22 22 6 6 6 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 14 14 14
40198 - 38 38 38 86 86 86 180 133 36 213 154 11
40199 -236 178 12 246 186 14 246 190 14 246 190 14
40200 -246 190 14 246 190 14 246 190 14 246 190 14
40201 -246 190 14 246 190 14 246 190 14 246 190 14
40202 -246 190 14 246 190 14 246 190 14 246 190 14
40203 -246 190 14 232 195 16 190 146 13 214 214 214
40204 -253 253 253 253 253 253 253 253 253 253 253 253
40205 -253 253 253 253 253 253 253 253 253 253 253 253
40206 -253 253 253 253 253 253 253 253 253 253 253 253
40207 -253 253 253 250 250 250 170 170 170 26 26 26
40208 - 2 2 6 2 2 6 37 26 9 163 110 8
40209 -219 162 10 239 182 13 246 186 14 246 190 14
40210 -246 190 14 246 190 14 246 190 14 246 190 14
40211 -246 190 14 246 190 14 246 190 14 246 190 14
40212 -246 190 14 246 190 14 246 190 14 246 190 14
40213 -246 186 14 236 178 12 224 166 10 142 122 72
40214 - 46 46 46 18 18 18 6 6 6 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 6 6 6 18 18 18
40218 - 50 50 50 109 106 95 192 133 9 224 166 10
40219 -242 186 14 246 190 14 246 190 14 246 190 14
40220 -246 190 14 246 190 14 246 190 14 246 190 14
40221 -246 190 14 246 190 14 246 190 14 246 190 14
40222 -246 190 14 246 190 14 246 190 14 246 190 14
40223 -242 186 14 226 184 13 210 162 10 142 110 46
40224 -226 226 226 253 253 253 253 253 253 253 253 253
40225 -253 253 253 253 253 253 253 253 253 253 253 253
40226 -253 253 253 253 253 253 253 253 253 253 253 253
40227 -198 198 198 66 66 66 2 2 6 2 2 6
40228 - 2 2 6 2 2 6 50 34 6 156 107 11
40229 -219 162 10 239 182 13 246 186 14 246 190 14
40230 -246 190 14 246 190 14 246 190 14 246 190 14
40231 -246 190 14 246 190 14 246 190 14 246 190 14
40232 -246 190 14 246 190 14 246 190 14 242 186 14
40233 -234 174 13 213 154 11 154 122 46 66 66 66
40234 - 30 30 30 10 10 10 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 6 6 6 22 22 22
40238 - 58 58 58 154 121 60 206 145 10 234 174 13
40239 -242 186 14 246 186 14 246 190 14 246 190 14
40240 -246 190 14 246 190 14 246 190 14 246 190 14
40241 -246 190 14 246 190 14 246 190 14 246 190 14
40242 -246 190 14 246 190 14 246 190 14 246 190 14
40243 -246 186 14 236 178 12 210 162 10 163 110 8
40244 - 61 42 6 138 138 138 218 218 218 250 250 250
40245 -253 253 253 253 253 253 253 253 253 250 250 250
40246 -242 242 242 210 210 210 144 144 144 66 66 66
40247 - 6 6 6 2 2 6 2 2 6 2 2 6
40248 - 2 2 6 2 2 6 61 42 6 163 110 8
40249 -216 158 10 236 178 12 246 190 14 246 190 14
40250 -246 190 14 246 190 14 246 190 14 246 190 14
40251 -246 190 14 246 190 14 246 190 14 246 190 14
40252 -246 190 14 239 182 13 230 174 11 216 158 10
40253 -190 142 34 124 112 88 70 70 70 38 38 38
40254 - 18 18 18 6 6 6 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 6 6 6 22 22 22
40258 - 62 62 62 168 124 44 206 145 10 224 166 10
40259 -236 178 12 239 182 13 242 186 14 242 186 14
40260 -246 186 14 246 190 14 246 190 14 246 190 14
40261 -246 190 14 246 190 14 246 190 14 246 190 14
40262 -246 190 14 246 190 14 246 190 14 246 190 14
40263 -246 190 14 236 178 12 216 158 10 175 118 6
40264 - 80 54 7 2 2 6 6 6 6 30 30 30
40265 - 54 54 54 62 62 62 50 50 50 38 38 38
40266 - 14 14 14 2 2 6 2 2 6 2 2 6
40267 - 2 2 6 2 2 6 2 2 6 2 2 6
40268 - 2 2 6 6 6 6 80 54 7 167 114 7
40269 -213 154 11 236 178 12 246 190 14 246 190 14
40270 -246 190 14 246 190 14 246 190 14 246 190 14
40271 -246 190 14 242 186 14 239 182 13 239 182 13
40272 -230 174 11 210 150 10 174 135 50 124 112 88
40273 - 82 82 82 54 54 54 34 34 34 18 18 18
40274 - 6 6 6 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 6 6 6 18 18 18
40278 - 50 50 50 158 118 36 192 133 9 200 144 11
40279 -216 158 10 219 162 10 224 166 10 226 170 11
40280 -230 174 11 236 178 12 239 182 13 239 182 13
40281 -242 186 14 246 186 14 246 190 14 246 190 14
40282 -246 190 14 246 190 14 246 190 14 246 190 14
40283 -246 186 14 230 174 11 210 150 10 163 110 8
40284 -104 69 6 10 10 10 2 2 6 2 2 6
40285 - 2 2 6 2 2 6 2 2 6 2 2 6
40286 - 2 2 6 2 2 6 2 2 6 2 2 6
40287 - 2 2 6 2 2 6 2 2 6 2 2 6
40288 - 2 2 6 6 6 6 91 60 6 167 114 7
40289 -206 145 10 230 174 11 242 186 14 246 190 14
40290 -246 190 14 246 190 14 246 186 14 242 186 14
40291 -239 182 13 230 174 11 224 166 10 213 154 11
40292 -180 133 36 124 112 88 86 86 86 58 58 58
40293 - 38 38 38 22 22 22 10 10 10 6 6 6
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 14 14 14
40298 - 34 34 34 70 70 70 138 110 50 158 118 36
40299 -167 114 7 180 123 7 192 133 9 197 138 11
40300 -200 144 11 206 145 10 213 154 11 219 162 10
40301 -224 166 10 230 174 11 239 182 13 242 186 14
40302 -246 186 14 246 186 14 246 186 14 246 186 14
40303 -239 182 13 216 158 10 185 133 11 152 99 6
40304 -104 69 6 18 14 6 2 2 6 2 2 6
40305 - 2 2 6 2 2 6 2 2 6 2 2 6
40306 - 2 2 6 2 2 6 2 2 6 2 2 6
40307 - 2 2 6 2 2 6 2 2 6 2 2 6
40308 - 2 2 6 6 6 6 80 54 7 152 99 6
40309 -192 133 9 219 162 10 236 178 12 239 182 13
40310 -246 186 14 242 186 14 239 182 13 236 178 12
40311 -224 166 10 206 145 10 192 133 9 154 121 60
40312 - 94 94 94 62 62 62 42 42 42 22 22 22
40313 - 14 14 14 6 6 6 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 6 6 6
40318 - 18 18 18 34 34 34 58 58 58 78 78 78
40319 -101 98 89 124 112 88 142 110 46 156 107 11
40320 -163 110 8 167 114 7 175 118 6 180 123 7
40321 -185 133 11 197 138 11 210 150 10 219 162 10
40322 -226 170 11 236 178 12 236 178 12 234 174 13
40323 -219 162 10 197 138 11 163 110 8 130 83 6
40324 - 91 60 6 10 10 10 2 2 6 2 2 6
40325 - 18 18 18 38 38 38 38 38 38 38 38 38
40326 - 38 38 38 38 38 38 38 38 38 38 38 38
40327 - 38 38 38 38 38 38 26 26 26 2 2 6
40328 - 2 2 6 6 6 6 70 47 6 137 92 6
40329 -175 118 6 200 144 11 219 162 10 230 174 11
40330 -234 174 13 230 174 11 219 162 10 210 150 10
40331 -192 133 9 163 110 8 124 112 88 82 82 82
40332 - 50 50 50 30 30 30 14 14 14 6 6 6
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 6 6 6 14 14 14 22 22 22 34 34 34
40339 - 42 42 42 58 58 58 74 74 74 86 86 86
40340 -101 98 89 122 102 70 130 98 46 121 87 25
40341 -137 92 6 152 99 6 163 110 8 180 123 7
40342 -185 133 11 197 138 11 206 145 10 200 144 11
40343 -180 123 7 156 107 11 130 83 6 104 69 6
40344 - 50 34 6 54 54 54 110 110 110 101 98 89
40345 - 86 86 86 82 82 82 78 78 78 78 78 78
40346 - 78 78 78 78 78 78 78 78 78 78 78 78
40347 - 78 78 78 82 82 82 86 86 86 94 94 94
40348 -106 106 106 101 101 101 86 66 34 124 80 6
40349 -156 107 11 180 123 7 192 133 9 200 144 11
40350 -206 145 10 200 144 11 192 133 9 175 118 6
40351 -139 102 15 109 106 95 70 70 70 42 42 42
40352 - 22 22 22 10 10 10 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 6 6 6 10 10 10
40359 - 14 14 14 22 22 22 30 30 30 38 38 38
40360 - 50 50 50 62 62 62 74 74 74 90 90 90
40361 -101 98 89 112 100 78 121 87 25 124 80 6
40362 -137 92 6 152 99 6 152 99 6 152 99 6
40363 -138 86 6 124 80 6 98 70 6 86 66 30
40364 -101 98 89 82 82 82 58 58 58 46 46 46
40365 - 38 38 38 34 34 34 34 34 34 34 34 34
40366 - 34 34 34 34 34 34 34 34 34 34 34 34
40367 - 34 34 34 34 34 34 38 38 38 42 42 42
40368 - 54 54 54 82 82 82 94 86 76 91 60 6
40369 -134 86 6 156 107 11 167 114 7 175 118 6
40370 -175 118 6 167 114 7 152 99 6 121 87 25
40371 -101 98 89 62 62 62 34 34 34 18 18 18
40372 - 6 6 6 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 6 6 6 6 6 6 10 10 10
40380 - 18 18 18 22 22 22 30 30 30 42 42 42
40381 - 50 50 50 66 66 66 86 86 86 101 98 89
40382 -106 86 58 98 70 6 104 69 6 104 69 6
40383 -104 69 6 91 60 6 82 62 34 90 90 90
40384 - 62 62 62 38 38 38 22 22 22 14 14 14
40385 - 10 10 10 10 10 10 10 10 10 10 10 10
40386 - 10 10 10 10 10 10 6 6 6 10 10 10
40387 - 10 10 10 10 10 10 10 10 10 14 14 14
40388 - 22 22 22 42 42 42 70 70 70 89 81 66
40389 - 80 54 7 104 69 6 124 80 6 137 92 6
40390 -134 86 6 116 81 8 100 82 52 86 86 86
40391 - 58 58 58 30 30 30 14 14 14 6 6 6
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 6 6 6 10 10 10 14 14 14
40401 - 18 18 18 26 26 26 38 38 38 54 54 54
40402 - 70 70 70 86 86 86 94 86 76 89 81 66
40403 - 89 81 66 86 86 86 74 74 74 50 50 50
40404 - 30 30 30 14 14 14 6 6 6 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 0 0 0 0 0 0
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 6 6 6 18 18 18 34 34 34 58 58 58
40409 - 82 82 82 89 81 66 89 81 66 89 81 66
40410 - 94 86 66 94 86 76 74 74 74 50 50 50
40411 - 26 26 26 14 14 14 6 6 6 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 6 6 6 6 6 6 14 14 14 18 18 18
40422 - 30 30 30 38 38 38 46 46 46 54 54 54
40423 - 50 50 50 42 42 42 30 30 30 18 18 18
40424 - 10 10 10 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 0 0 0
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 6 6 6 14 14 14 26 26 26
40429 - 38 38 38 50 50 50 58 58 58 58 58 58
40430 - 54 54 54 42 42 42 30 30 30 18 18 18
40431 - 10 10 10 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 6 6 6
40442 - 6 6 6 10 10 10 14 14 14 18 18 18
40443 - 18 18 18 14 14 14 10 10 10 6 6 6
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 0 0 0 0 0 0 0 0 0 0 0 0
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 6 6 6
40449 - 14 14 14 18 18 18 22 22 22 22 22 22
40450 - 18 18 18 14 14 14 10 10 10 6 6 6
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40462 +4 4 4 4 4 4 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
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483 +4 4 4 4 4 4
40484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497 +4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511 +4 4 4 4 4 4
40512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525 +4 4 4 4 4 4
40526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40528 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40539 +4 4 4 4 4 4
40540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40541 +4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
40545 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40549 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40550 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40551 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40553 +4 4 4 4 4 4
40554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40555 +4 4 4 4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
40559 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40560 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40563 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40564 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40565 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40566 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40567 +4 4 4 4 4 4
40568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40569 +4 4 4 4 4 4 4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40573 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40574 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40577 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40578 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40579 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40580 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40581 +4 4 4 4 4 4
40582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40583 +4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 2 2 2 0 0 0
40586 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40587 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40588 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40591 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40592 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40593 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40594 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40595 +4 4 4 4 4 4
40596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40600 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40601 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40602 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40603 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40604 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40605 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40606 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40607 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40608 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40609 +4 4 4 4 4 4
40610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40613 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40614 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40615 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40616 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40617 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40618 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40619 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40620 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40621 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40622 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40623 +4 4 4 4 4 4
40624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40626 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40627 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40628 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40629 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40630 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40631 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40632 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40633 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40634 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40635 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40636 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40637 +4 4 4 4 4 4
40638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40640 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40641 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40642 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40643 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40644 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40645 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40646 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40647 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40648 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40649 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40650 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40651 +4 4 4 4 4 4
40652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40654 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40655 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40656 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40657 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40658 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40659 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40660 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40661 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40662 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40663 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40664 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40665 +4 4 4 4 4 4
40666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40668 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40669 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40670 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40671 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40672 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40673 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40674 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40675 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40676 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40677 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40678 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40679 +4 4 4 4 4 4
40680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40681 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40682 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40683 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40684 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40685 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40686 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40687 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40688 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40689 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40690 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40691 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40692 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40693 +4 4 4 4 4 4
40694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40695 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40696 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40697 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40698 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40699 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40700 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40701 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40702 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40703 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40704 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40705 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40706 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40707 +0 0 0 4 4 4
40708 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40709 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40710 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40711 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40712 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40713 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40714 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40715 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40716 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40717 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40718 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40719 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40720 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40721 +2 0 0 0 0 0
40722 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40723 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40724 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40725 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40726 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40727 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40728 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40729 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40730 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40731 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40732 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40733 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40734 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40735 +37 38 37 0 0 0
40736 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40737 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40738 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40739 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40740 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40741 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40742 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40743 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40744 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40745 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40746 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40747 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40748 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40749 +85 115 134 4 0 0
40750 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40751 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40752 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40753 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40754 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40755 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40756 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40757 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40758 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40759 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40760 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40761 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40762 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40763 +60 73 81 4 0 0
40764 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40765 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40766 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40767 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40768 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40769 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40770 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40771 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40772 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40773 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40774 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40775 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40776 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40777 +16 19 21 4 0 0
40778 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40779 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40780 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40781 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40782 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40783 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40784 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40785 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40786 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40787 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40788 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40789 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40790 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40791 +4 0 0 4 3 3
40792 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40793 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40794 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40796 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40797 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40798 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40799 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40800 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40801 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40802 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40803 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40804 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40805 +3 2 2 4 4 4
40806 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40807 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40808 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40809 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40810 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40811 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40812 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40813 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40814 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40815 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40816 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40817 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40818 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40819 +4 4 4 4 4 4
40820 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40821 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40822 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40823 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40824 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40825 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40826 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40827 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40828 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40829 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40830 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40831 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40832 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40833 +4 4 4 4 4 4
40834 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40835 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40836 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40837 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40838 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40839 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40840 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40841 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40842 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40843 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40844 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40845 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40846 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40847 +5 5 5 5 5 5
40848 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40849 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40850 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40851 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40852 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40853 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40854 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40855 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40856 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40857 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40858 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40859 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40860 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40861 +5 5 5 4 4 4
40862 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40863 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40864 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40865 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40866 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40867 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40868 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40869 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40870 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40871 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40872 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40873 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40875 +4 4 4 4 4 4
40876 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40877 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40878 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40879 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40880 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40881 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40882 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40883 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40884 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40885 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40886 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40887 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40889 +4 4 4 4 4 4
40890 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40891 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40892 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40893 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40894 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40895 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40896 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40897 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40898 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40899 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40900 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40903 +4 4 4 4 4 4
40904 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40905 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40906 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40907 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40908 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40909 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40910 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40911 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40912 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40913 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40914 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40917 +4 4 4 4 4 4
40918 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40919 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40920 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40921 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40922 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40923 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40924 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40925 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40926 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40927 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40928 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40931 +4 4 4 4 4 4
40932 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40933 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40934 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40935 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40936 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40937 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40938 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40939 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40940 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40941 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40942 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40945 +4 4 4 4 4 4
40946 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40947 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40948 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40949 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40950 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40951 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40952 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40953 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40954 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40955 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40956 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40959 +4 4 4 4 4 4
40960 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40961 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40962 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40963 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40964 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40965 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40966 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40967 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40968 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40969 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40970 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40973 +4 4 4 4 4 4
40974 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40975 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40976 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40977 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40978 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40979 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40980 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40981 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40982 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40983 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40984 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40987 +4 4 4 4 4 4
40988 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40989 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40990 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40991 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40992 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40993 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40994 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40995 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40996 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40997 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40998 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41001 +4 4 4 4 4 4
41002 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41003 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41004 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41005 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41006 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41007 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41008 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41009 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41010 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41011 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41012 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41015 +4 4 4 4 4 4
41016 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41017 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41018 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41019 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41020 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41021 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41022 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41023 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41024 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41025 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41026 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41029 +4 4 4 4 4 4
41030 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41031 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41032 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41033 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41034 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41035 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41036 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41037 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41038 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41039 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41040 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41043 +4 4 4 4 4 4
41044 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41045 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41046 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41047 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41048 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41049 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41050 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41051 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41052 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41053 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41054 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057 +4 4 4 4 4 4
41058 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41059 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41060 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41061 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41062 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41063 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41064 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41065 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41066 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41067 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41068 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41071 +4 4 4 4 4 4
41072 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41073 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41074 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41075 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41076 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41077 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41078 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41079 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41080 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41081 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41082 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41085 +4 4 4 4 4 4
41086 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41087 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41088 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41089 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41090 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41091 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41092 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41093 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41094 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41095 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41096 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41099 +4 4 4 4 4 4
41100 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41101 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41102 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41103 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41104 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41105 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41106 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41107 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41108 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41109 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41110 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41113 +4 4 4 4 4 4
41114 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41115 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41116 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41117 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41118 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41119 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41120 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41121 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41122 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41123 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41124 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41127 +4 4 4 4 4 4
41128 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41129 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41130 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41131 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41132 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41133 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41134 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41135 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41136 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41137 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41138 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4
41142 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41143 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41144 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41145 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41146 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41147 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41148 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41149 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41150 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41151 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41152 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4
41156 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41157 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41158 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41159 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41160 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41161 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41162 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41163 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41164 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41165 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41166 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4
41170 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41171 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41172 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41173 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41174 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41175 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41176 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41177 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41178 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41179 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41180 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4
41184 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41185 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41186 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41187 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41188 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41189 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41190 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41191 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41192 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41193 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41194 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4
41198 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41199 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41200 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41202 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41203 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41204 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41205 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41206 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41207 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41208 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
41212 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41213 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41214 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41215 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41216 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41217 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41218 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41219 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41220 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41221 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41222 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 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
41226 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41227 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41228 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41229 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41230 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41231 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41232 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41233 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41234 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41235 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41236 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 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
41240 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41241 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41242 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41243 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41245 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41246 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41248 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41249 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41250 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 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
41254 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41255 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41256 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41257 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41258 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41259 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41260 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41261 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41262 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41263 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41264 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
41268 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41269 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41270 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41271 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41272 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41273 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41274 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41275 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41276 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41277 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41278 +4 4 4 4 4 4 4 4 4 4 4 4 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
41282 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41283 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41284 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41285 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41286 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41287 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41288 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41289 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41290 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41291 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41292 +4 4 4 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
41296 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41297 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41298 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41299 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41300 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41301 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41302 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41303 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41304 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41305 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
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
41310 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41311 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41312 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41313 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41314 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41315 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41316 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41317 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41318 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41319 +4 3 3 5 5 5 4 4 4 4 4 4 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
41324 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41325 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41326 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41327 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41328 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41329 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41330 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41331 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41332 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41333 +4 4 4 4 4 4 4 4 4 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
41338 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41339 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41340 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41341 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41342 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41343 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41344 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41345 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41346 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 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
41352 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41353 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41354 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41355 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41356 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41357 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41358 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41359 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41360 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 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
41366 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41367 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41368 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41369 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41370 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41371 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41372 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41373 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 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
41380 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41381 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41382 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41383 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41384 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41385 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41386 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41387 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 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
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41395 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41396 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41397 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41398 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41399 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41400 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41401 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41410 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41411 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41412 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41413 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41414 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41415 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 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
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41424 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41425 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41426 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41427 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41428 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41429 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 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
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41439 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41440 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41441 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41442 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41443 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 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
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41453 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41454 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41455 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41456 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41468 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41469 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41470 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 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
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41482 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41483 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41484 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 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
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41496 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41497 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41498 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 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
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41510 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41511 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41512 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41524 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41525 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41526 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533 +4 4 4 4 4 4
41534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41538 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41539 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41540 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547 +4 4 4 4 4 4
41548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41552 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41553 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561 +4 4 4 4 4 4
41562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41566 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41567 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575 +4 4 4 4 4 4
41576 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41577 index a40c05e..785c583 100644
41578 --- a/drivers/video/udlfb.c
41579 +++ b/drivers/video/udlfb.c
41580 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41581 dlfb_urb_completion(urb);
41582
41583 error:
41584 - atomic_add(bytes_sent, &dev->bytes_sent);
41585 - atomic_add(bytes_identical, &dev->bytes_identical);
41586 - atomic_add(width*height*2, &dev->bytes_rendered);
41587 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41588 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41589 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41590 end_cycles = get_cycles();
41591 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41592 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41593 >> 10)), /* Kcycles */
41594 &dev->cpu_kcycles_used);
41595
41596 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41597 dlfb_urb_completion(urb);
41598
41599 error:
41600 - atomic_add(bytes_sent, &dev->bytes_sent);
41601 - atomic_add(bytes_identical, &dev->bytes_identical);
41602 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41603 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41604 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41605 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41606 end_cycles = get_cycles();
41607 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41608 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41609 >> 10)), /* Kcycles */
41610 &dev->cpu_kcycles_used);
41611 }
41612 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41613 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41614 struct dlfb_data *dev = fb_info->par;
41615 return snprintf(buf, PAGE_SIZE, "%u\n",
41616 - atomic_read(&dev->bytes_rendered));
41617 + atomic_read_unchecked(&dev->bytes_rendered));
41618 }
41619
41620 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41621 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41622 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41623 struct dlfb_data *dev = fb_info->par;
41624 return snprintf(buf, PAGE_SIZE, "%u\n",
41625 - atomic_read(&dev->bytes_identical));
41626 + atomic_read_unchecked(&dev->bytes_identical));
41627 }
41628
41629 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41630 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41631 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41632 struct dlfb_data *dev = fb_info->par;
41633 return snprintf(buf, PAGE_SIZE, "%u\n",
41634 - atomic_read(&dev->bytes_sent));
41635 + atomic_read_unchecked(&dev->bytes_sent));
41636 }
41637
41638 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41639 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41640 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41641 struct dlfb_data *dev = fb_info->par;
41642 return snprintf(buf, PAGE_SIZE, "%u\n",
41643 - atomic_read(&dev->cpu_kcycles_used));
41644 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41645 }
41646
41647 static ssize_t edid_show(
41648 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41649 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41650 struct dlfb_data *dev = fb_info->par;
41651
41652 - atomic_set(&dev->bytes_rendered, 0);
41653 - atomic_set(&dev->bytes_identical, 0);
41654 - atomic_set(&dev->bytes_sent, 0);
41655 - atomic_set(&dev->cpu_kcycles_used, 0);
41656 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41657 + atomic_set_unchecked(&dev->bytes_identical, 0);
41658 + atomic_set_unchecked(&dev->bytes_sent, 0);
41659 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41660
41661 return count;
41662 }
41663 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41664 index e7f69ef..83af4fd 100644
41665 --- a/drivers/video/uvesafb.c
41666 +++ b/drivers/video/uvesafb.c
41667 @@ -19,6 +19,7 @@
41668 #include <linux/io.h>
41669 #include <linux/mutex.h>
41670 #include <linux/slab.h>
41671 +#include <linux/moduleloader.h>
41672 #include <video/edid.h>
41673 #include <video/uvesafb.h>
41674 #ifdef CONFIG_X86
41675 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41676 NULL,
41677 };
41678
41679 - return call_usermodehelper(v86d_path, argv, envp, 1);
41680 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41681 }
41682
41683 /*
41684 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41685 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41686 par->pmi_setpal = par->ypan = 0;
41687 } else {
41688 +
41689 +#ifdef CONFIG_PAX_KERNEXEC
41690 +#ifdef CONFIG_MODULES
41691 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41692 +#endif
41693 + if (!par->pmi_code) {
41694 + par->pmi_setpal = par->ypan = 0;
41695 + return 0;
41696 + }
41697 +#endif
41698 +
41699 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41700 + task->t.regs.edi);
41701 +
41702 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41703 + pax_open_kernel();
41704 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41705 + pax_close_kernel();
41706 +
41707 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41708 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41709 +#else
41710 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41711 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41712 +#endif
41713 +
41714 printk(KERN_INFO "uvesafb: protected mode interface info at "
41715 "%04x:%04x\n",
41716 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41717 @@ -1821,6 +1844,11 @@ out:
41718 if (par->vbe_modes)
41719 kfree(par->vbe_modes);
41720
41721 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41722 + if (par->pmi_code)
41723 + module_free_exec(NULL, par->pmi_code);
41724 +#endif
41725 +
41726 framebuffer_release(info);
41727 return err;
41728 }
41729 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41730 kfree(par->vbe_state_orig);
41731 if (par->vbe_state_saved)
41732 kfree(par->vbe_state_saved);
41733 +
41734 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41735 + if (par->pmi_code)
41736 + module_free_exec(NULL, par->pmi_code);
41737 +#endif
41738 +
41739 }
41740
41741 framebuffer_release(info);
41742 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41743 index 501b340..86bd4cf 100644
41744 --- a/drivers/video/vesafb.c
41745 +++ b/drivers/video/vesafb.c
41746 @@ -9,6 +9,7 @@
41747 */
41748
41749 #include <linux/module.h>
41750 +#include <linux/moduleloader.h>
41751 #include <linux/kernel.h>
41752 #include <linux/errno.h>
41753 #include <linux/string.h>
41754 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41755 static int vram_total __initdata; /* Set total amount of memory */
41756 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41757 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41758 -static void (*pmi_start)(void) __read_mostly;
41759 -static void (*pmi_pal) (void) __read_mostly;
41760 +static void (*pmi_start)(void) __read_only;
41761 +static void (*pmi_pal) (void) __read_only;
41762 static int depth __read_mostly;
41763 static int vga_compat __read_mostly;
41764 /* --------------------------------------------------------------------- */
41765 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41766 unsigned int size_vmode;
41767 unsigned int size_remap;
41768 unsigned int size_total;
41769 + void *pmi_code = NULL;
41770
41771 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41772 return -ENODEV;
41773 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41774 size_remap = size_total;
41775 vesafb_fix.smem_len = size_remap;
41776
41777 -#ifndef __i386__
41778 - screen_info.vesapm_seg = 0;
41779 -#endif
41780 -
41781 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41782 printk(KERN_WARNING
41783 "vesafb: cannot reserve video memory at 0x%lx\n",
41784 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41785 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41786 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41787
41788 +#ifdef __i386__
41789 +
41790 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41791 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41792 + if (!pmi_code)
41793 +#elif !defined(CONFIG_PAX_KERNEXEC)
41794 + if (0)
41795 +#endif
41796 +
41797 +#endif
41798 + screen_info.vesapm_seg = 0;
41799 +
41800 if (screen_info.vesapm_seg) {
41801 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41802 - screen_info.vesapm_seg,screen_info.vesapm_off);
41803 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41804 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41805 }
41806
41807 if (screen_info.vesapm_seg < 0xc000)
41808 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41809
41810 if (ypan || pmi_setpal) {
41811 unsigned short *pmi_base;
41812 +
41813 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41814 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41815 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41816 +
41817 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41818 + pax_open_kernel();
41819 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41820 +#else
41821 + pmi_code = pmi_base;
41822 +#endif
41823 +
41824 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41825 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41826 +
41827 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41828 + pmi_start = ktva_ktla(pmi_start);
41829 + pmi_pal = ktva_ktla(pmi_pal);
41830 + pax_close_kernel();
41831 +#endif
41832 +
41833 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41834 if (pmi_base[3]) {
41835 printk(KERN_INFO "vesafb: pmi: ports = ");
41836 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41837 info->node, info->fix.id);
41838 return 0;
41839 err:
41840 +
41841 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41842 + module_free_exec(NULL, pmi_code);
41843 +#endif
41844 +
41845 if (info->screen_base)
41846 iounmap(info->screen_base);
41847 framebuffer_release(info);
41848 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41849 index 88714ae..16c2e11 100644
41850 --- a/drivers/video/via/via_clock.h
41851 +++ b/drivers/video/via/via_clock.h
41852 @@ -56,7 +56,7 @@ struct via_clock {
41853
41854 void (*set_engine_pll_state)(u8 state);
41855 void (*set_engine_pll)(struct via_pll_config config);
41856 -};
41857 +} __no_const;
41858
41859
41860 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41861 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41862 index e56c934..fc22f4b 100644
41863 --- a/drivers/xen/xen-pciback/conf_space.h
41864 +++ b/drivers/xen/xen-pciback/conf_space.h
41865 @@ -44,15 +44,15 @@ struct config_field {
41866 struct {
41867 conf_dword_write write;
41868 conf_dword_read read;
41869 - } dw;
41870 + } __no_const dw;
41871 struct {
41872 conf_word_write write;
41873 conf_word_read read;
41874 - } w;
41875 + } __no_const w;
41876 struct {
41877 conf_byte_write write;
41878 conf_byte_read read;
41879 - } b;
41880 + } __no_const b;
41881 } u;
41882 struct list_head list;
41883 };
41884 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41885 index 014c8dd..6f3dfe6 100644
41886 --- a/fs/9p/vfs_inode.c
41887 +++ b/fs/9p/vfs_inode.c
41888 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41889 void
41890 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41891 {
41892 - char *s = nd_get_link(nd);
41893 + const char *s = nd_get_link(nd);
41894
41895 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41896 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41897 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41898 index e95d1b6..3454244 100644
41899 --- a/fs/Kconfig.binfmt
41900 +++ b/fs/Kconfig.binfmt
41901 @@ -89,7 +89,7 @@ config HAVE_AOUT
41902
41903 config BINFMT_AOUT
41904 tristate "Kernel support for a.out and ECOFF binaries"
41905 - depends on HAVE_AOUT
41906 + depends on HAVE_AOUT && BROKEN
41907 ---help---
41908 A.out (Assembler.OUTput) is a set of formats for libraries and
41909 executables used in the earliest versions of UNIX. Linux used
41910 diff --git a/fs/aio.c b/fs/aio.c
41911 index b9d64d8..86cb1d5 100644
41912 --- a/fs/aio.c
41913 +++ b/fs/aio.c
41914 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41915 size += sizeof(struct io_event) * nr_events;
41916 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41917
41918 - if (nr_pages < 0)
41919 + if (nr_pages <= 0)
41920 return -EINVAL;
41921
41922 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41923 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41924 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41925 {
41926 ssize_t ret;
41927 + struct iovec iovstack;
41928
41929 #ifdef CONFIG_COMPAT
41930 if (compat)
41931 ret = compat_rw_copy_check_uvector(type,
41932 (struct compat_iovec __user *)kiocb->ki_buf,
41933 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41934 + kiocb->ki_nbytes, 1, &iovstack,
41935 &kiocb->ki_iovec, 1);
41936 else
41937 #endif
41938 ret = rw_copy_check_uvector(type,
41939 (struct iovec __user *)kiocb->ki_buf,
41940 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41941 + kiocb->ki_nbytes, 1, &iovstack,
41942 &kiocb->ki_iovec, 1);
41943 if (ret < 0)
41944 goto out;
41945
41946 + if (kiocb->ki_iovec == &iovstack) {
41947 + kiocb->ki_inline_vec = iovstack;
41948 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41949 + }
41950 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41951 kiocb->ki_cur_seg = 0;
41952 /* ki_nbytes/left now reflect bytes instead of segs */
41953 diff --git a/fs/attr.c b/fs/attr.c
41954 index 95053ad..2cc93ca 100644
41955 --- a/fs/attr.c
41956 +++ b/fs/attr.c
41957 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41958 unsigned long limit;
41959
41960 limit = rlimit(RLIMIT_FSIZE);
41961 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41962 if (limit != RLIM_INFINITY && offset > limit)
41963 goto out_sig;
41964 if (offset > inode->i_sb->s_maxbytes)
41965 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41966 index 9c098db..c755da5 100644
41967 --- a/fs/autofs4/waitq.c
41968 +++ b/fs/autofs4/waitq.c
41969 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41970 {
41971 unsigned long sigpipe, flags;
41972 mm_segment_t fs;
41973 - const char *data = (const char *)addr;
41974 + const char __user *data = (const char __force_user *)addr;
41975 ssize_t wr = 0;
41976
41977 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41978 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41979 index 6e6d536..457113a 100644
41980 --- a/fs/befs/linuxvfs.c
41981 +++ b/fs/befs/linuxvfs.c
41982 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41983 {
41984 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41985 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41986 - char *link = nd_get_link(nd);
41987 + const char *link = nd_get_link(nd);
41988 if (!IS_ERR(link))
41989 kfree(link);
41990 }
41991 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41992 index 1ff9405..f1e376a 100644
41993 --- a/fs/binfmt_aout.c
41994 +++ b/fs/binfmt_aout.c
41995 @@ -16,6 +16,7 @@
41996 #include <linux/string.h>
41997 #include <linux/fs.h>
41998 #include <linux/file.h>
41999 +#include <linux/security.h>
42000 #include <linux/stat.h>
42001 #include <linux/fcntl.h>
42002 #include <linux/ptrace.h>
42003 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42004 #endif
42005 # define START_STACK(u) ((void __user *)u.start_stack)
42006
42007 + memset(&dump, 0, sizeof(dump));
42008 +
42009 fs = get_fs();
42010 set_fs(KERNEL_DS);
42011 has_dumped = 1;
42012 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42013
42014 /* If the size of the dump file exceeds the rlimit, then see what would happen
42015 if we wrote the stack, but not the data area. */
42016 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42017 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42018 dump.u_dsize = 0;
42019
42020 /* Make sure we have enough room to write the stack and data areas. */
42021 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42022 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42023 dump.u_ssize = 0;
42024
42025 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42026 rlim = rlimit(RLIMIT_DATA);
42027 if (rlim >= RLIM_INFINITY)
42028 rlim = ~0;
42029 +
42030 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42031 if (ex.a_data + ex.a_bss > rlim)
42032 return -ENOMEM;
42033
42034 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42035 install_exec_creds(bprm);
42036 current->flags &= ~PF_FORKNOEXEC;
42037
42038 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42039 + current->mm->pax_flags = 0UL;
42040 +#endif
42041 +
42042 +#ifdef CONFIG_PAX_PAGEEXEC
42043 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42044 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42045 +
42046 +#ifdef CONFIG_PAX_EMUTRAMP
42047 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42048 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42049 +#endif
42050 +
42051 +#ifdef CONFIG_PAX_MPROTECT
42052 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42053 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42054 +#endif
42055 +
42056 + }
42057 +#endif
42058 +
42059 if (N_MAGIC(ex) == OMAGIC) {
42060 unsigned long text_addr, map_size;
42061 loff_t pos;
42062 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42063
42064 down_write(&current->mm->mmap_sem);
42065 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42066 - PROT_READ | PROT_WRITE | PROT_EXEC,
42067 + PROT_READ | PROT_WRITE,
42068 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42069 fd_offset + ex.a_text);
42070 up_write(&current->mm->mmap_sem);
42071 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42072 index 07d096c..851a18b 100644
42073 --- a/fs/binfmt_elf.c
42074 +++ b/fs/binfmt_elf.c
42075 @@ -32,6 +32,7 @@
42076 #include <linux/elf.h>
42077 #include <linux/utsname.h>
42078 #include <linux/coredump.h>
42079 +#include <linux/xattr.h>
42080 #include <asm/uaccess.h>
42081 #include <asm/param.h>
42082 #include <asm/page.h>
42083 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42084 #define elf_core_dump NULL
42085 #endif
42086
42087 +#ifdef CONFIG_PAX_MPROTECT
42088 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42089 +#endif
42090 +
42091 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42092 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42093 #else
42094 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42095 .load_binary = load_elf_binary,
42096 .load_shlib = load_elf_library,
42097 .core_dump = elf_core_dump,
42098 +
42099 +#ifdef CONFIG_PAX_MPROTECT
42100 + .handle_mprotect= elf_handle_mprotect,
42101 +#endif
42102 +
42103 .min_coredump = ELF_EXEC_PAGESIZE,
42104 };
42105
42106 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42107
42108 static int set_brk(unsigned long start, unsigned long end)
42109 {
42110 + unsigned long e = end;
42111 +
42112 start = ELF_PAGEALIGN(start);
42113 end = ELF_PAGEALIGN(end);
42114 if (end > start) {
42115 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42116 if (BAD_ADDR(addr))
42117 return addr;
42118 }
42119 - current->mm->start_brk = current->mm->brk = end;
42120 + current->mm->start_brk = current->mm->brk = e;
42121 return 0;
42122 }
42123
42124 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42125 elf_addr_t __user *u_rand_bytes;
42126 const char *k_platform = ELF_PLATFORM;
42127 const char *k_base_platform = ELF_BASE_PLATFORM;
42128 - unsigned char k_rand_bytes[16];
42129 + u32 k_rand_bytes[4];
42130 int items;
42131 elf_addr_t *elf_info;
42132 int ei_index = 0;
42133 const struct cred *cred = current_cred();
42134 struct vm_area_struct *vma;
42135 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42136
42137 /*
42138 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42139 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42140 * Generate 16 random bytes for userspace PRNG seeding.
42141 */
42142 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42143 - u_rand_bytes = (elf_addr_t __user *)
42144 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42145 + srandom32(k_rand_bytes[0] ^ random32());
42146 + srandom32(k_rand_bytes[1] ^ random32());
42147 + srandom32(k_rand_bytes[2] ^ random32());
42148 + srandom32(k_rand_bytes[3] ^ random32());
42149 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42150 + u_rand_bytes = (elf_addr_t __user *) p;
42151 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42152 return -EFAULT;
42153
42154 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42155 return -EFAULT;
42156 current->mm->env_end = p;
42157
42158 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42159 +
42160 /* Put the elf_info on the stack in the right place. */
42161 sp = (elf_addr_t __user *)envp + 1;
42162 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42163 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42164 return -EFAULT;
42165 return 0;
42166 }
42167 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42168 {
42169 struct elf_phdr *elf_phdata;
42170 struct elf_phdr *eppnt;
42171 - unsigned long load_addr = 0;
42172 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42173 int load_addr_set = 0;
42174 unsigned long last_bss = 0, elf_bss = 0;
42175 - unsigned long error = ~0UL;
42176 + unsigned long error = -EINVAL;
42177 unsigned long total_size;
42178 int retval, i, size;
42179
42180 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42181 goto out_close;
42182 }
42183
42184 +#ifdef CONFIG_PAX_SEGMEXEC
42185 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42186 + pax_task_size = SEGMEXEC_TASK_SIZE;
42187 +#endif
42188 +
42189 eppnt = elf_phdata;
42190 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42191 if (eppnt->p_type == PT_LOAD) {
42192 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42193 k = load_addr + eppnt->p_vaddr;
42194 if (BAD_ADDR(k) ||
42195 eppnt->p_filesz > eppnt->p_memsz ||
42196 - eppnt->p_memsz > TASK_SIZE ||
42197 - TASK_SIZE - eppnt->p_memsz < k) {
42198 + eppnt->p_memsz > pax_task_size ||
42199 + pax_task_size - eppnt->p_memsz < k) {
42200 error = -ENOMEM;
42201 goto out_close;
42202 }
42203 @@ -528,6 +552,351 @@ out:
42204 return error;
42205 }
42206
42207 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42208 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42209 +{
42210 + unsigned long pax_flags = 0UL;
42211 +
42212 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42213 +
42214 +#ifdef CONFIG_PAX_PAGEEXEC
42215 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42216 + pax_flags |= MF_PAX_PAGEEXEC;
42217 +#endif
42218 +
42219 +#ifdef CONFIG_PAX_SEGMEXEC
42220 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42221 + pax_flags |= MF_PAX_SEGMEXEC;
42222 +#endif
42223 +
42224 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42225 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42226 + if ((__supported_pte_mask & _PAGE_NX))
42227 + pax_flags &= ~MF_PAX_SEGMEXEC;
42228 + else
42229 + pax_flags &= ~MF_PAX_PAGEEXEC;
42230 + }
42231 +#endif
42232 +
42233 +#ifdef CONFIG_PAX_EMUTRAMP
42234 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42235 + pax_flags |= MF_PAX_EMUTRAMP;
42236 +#endif
42237 +
42238 +#ifdef CONFIG_PAX_MPROTECT
42239 + if (elf_phdata->p_flags & PF_MPROTECT)
42240 + pax_flags |= MF_PAX_MPROTECT;
42241 +#endif
42242 +
42243 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42244 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42245 + pax_flags |= MF_PAX_RANDMMAP;
42246 +#endif
42247 +
42248 +#endif
42249 +
42250 + return pax_flags;
42251 +}
42252 +
42253 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42254 +{
42255 + unsigned long pax_flags = 0UL;
42256 +
42257 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42258 +
42259 +#ifdef CONFIG_PAX_PAGEEXEC
42260 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42261 + pax_flags |= MF_PAX_PAGEEXEC;
42262 +#endif
42263 +
42264 +#ifdef CONFIG_PAX_SEGMEXEC
42265 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42266 + pax_flags |= MF_PAX_SEGMEXEC;
42267 +#endif
42268 +
42269 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42270 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42271 + if ((__supported_pte_mask & _PAGE_NX))
42272 + pax_flags &= ~MF_PAX_SEGMEXEC;
42273 + else
42274 + pax_flags &= ~MF_PAX_PAGEEXEC;
42275 + }
42276 +#endif
42277 +
42278 +#ifdef CONFIG_PAX_EMUTRAMP
42279 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42280 + pax_flags |= MF_PAX_EMUTRAMP;
42281 +#endif
42282 +
42283 +#ifdef CONFIG_PAX_MPROTECT
42284 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42285 + pax_flags |= MF_PAX_MPROTECT;
42286 +#endif
42287 +
42288 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42289 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42290 + pax_flags |= MF_PAX_RANDMMAP;
42291 +#endif
42292 +
42293 +#endif
42294 +
42295 + return pax_flags;
42296 +}
42297 +
42298 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42299 +{
42300 + unsigned long pax_flags = 0UL;
42301 +
42302 +#ifdef CONFIG_PAX_EI_PAX
42303 +
42304 +#ifdef CONFIG_PAX_PAGEEXEC
42305 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42306 + pax_flags |= MF_PAX_PAGEEXEC;
42307 +#endif
42308 +
42309 +#ifdef CONFIG_PAX_SEGMEXEC
42310 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42311 + pax_flags |= MF_PAX_SEGMEXEC;
42312 +#endif
42313 +
42314 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42315 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42316 + if ((__supported_pte_mask & _PAGE_NX))
42317 + pax_flags &= ~MF_PAX_SEGMEXEC;
42318 + else
42319 + pax_flags &= ~MF_PAX_PAGEEXEC;
42320 + }
42321 +#endif
42322 +
42323 +#ifdef CONFIG_PAX_EMUTRAMP
42324 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42325 + pax_flags |= MF_PAX_EMUTRAMP;
42326 +#endif
42327 +
42328 +#ifdef CONFIG_PAX_MPROTECT
42329 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42330 + pax_flags |= MF_PAX_MPROTECT;
42331 +#endif
42332 +
42333 +#ifdef CONFIG_PAX_ASLR
42334 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42335 + pax_flags |= MF_PAX_RANDMMAP;
42336 +#endif
42337 +
42338 +#else
42339 +
42340 +#ifdef CONFIG_PAX_PAGEEXEC
42341 + pax_flags |= MF_PAX_PAGEEXEC;
42342 +#endif
42343 +
42344 +#ifdef CONFIG_PAX_MPROTECT
42345 + pax_flags |= MF_PAX_MPROTECT;
42346 +#endif
42347 +
42348 +#ifdef CONFIG_PAX_RANDMMAP
42349 + pax_flags |= MF_PAX_RANDMMAP;
42350 +#endif
42351 +
42352 +#ifdef CONFIG_PAX_SEGMEXEC
42353 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42354 + pax_flags &= ~MF_PAX_PAGEEXEC;
42355 + pax_flags |= MF_PAX_SEGMEXEC;
42356 + }
42357 +#endif
42358 +
42359 +#endif
42360 +
42361 + return pax_flags;
42362 +}
42363 +
42364 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42365 +{
42366 +
42367 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42368 + unsigned long i;
42369 +
42370 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42371 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42372 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42373 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42374 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42375 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42376 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42377 + return ~0UL;
42378 +
42379 +#ifdef CONFIG_PAX_SOFTMODE
42380 + if (pax_softmode)
42381 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42382 + else
42383 +#endif
42384 +
42385 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42386 + break;
42387 + }
42388 +#endif
42389 +
42390 + return ~0UL;
42391 +}
42392 +
42393 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42394 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42395 +{
42396 + unsigned long pax_flags = 0UL;
42397 +
42398 +#ifdef CONFIG_PAX_PAGEEXEC
42399 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42400 + pax_flags |= MF_PAX_PAGEEXEC;
42401 +#endif
42402 +
42403 +#ifdef CONFIG_PAX_SEGMEXEC
42404 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42405 + pax_flags |= MF_PAX_SEGMEXEC;
42406 +#endif
42407 +
42408 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42409 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42410 + if ((__supported_pte_mask & _PAGE_NX))
42411 + pax_flags &= ~MF_PAX_SEGMEXEC;
42412 + else
42413 + pax_flags &= ~MF_PAX_PAGEEXEC;
42414 + }
42415 +#endif
42416 +
42417 +#ifdef CONFIG_PAX_EMUTRAMP
42418 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42419 + pax_flags |= MF_PAX_EMUTRAMP;
42420 +#endif
42421 +
42422 +#ifdef CONFIG_PAX_MPROTECT
42423 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42424 + pax_flags |= MF_PAX_MPROTECT;
42425 +#endif
42426 +
42427 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42428 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42429 + pax_flags |= MF_PAX_RANDMMAP;
42430 +#endif
42431 +
42432 + return pax_flags;
42433 +}
42434 +
42435 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42436 +{
42437 + unsigned long pax_flags = 0UL;
42438 +
42439 +#ifdef CONFIG_PAX_PAGEEXEC
42440 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42441 + pax_flags |= MF_PAX_PAGEEXEC;
42442 +#endif
42443 +
42444 +#ifdef CONFIG_PAX_SEGMEXEC
42445 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42446 + pax_flags |= MF_PAX_SEGMEXEC;
42447 +#endif
42448 +
42449 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42450 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42451 + if ((__supported_pte_mask & _PAGE_NX))
42452 + pax_flags &= ~MF_PAX_SEGMEXEC;
42453 + else
42454 + pax_flags &= ~MF_PAX_PAGEEXEC;
42455 + }
42456 +#endif
42457 +
42458 +#ifdef CONFIG_PAX_EMUTRAMP
42459 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42460 + pax_flags |= MF_PAX_EMUTRAMP;
42461 +#endif
42462 +
42463 +#ifdef CONFIG_PAX_MPROTECT
42464 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42465 + pax_flags |= MF_PAX_MPROTECT;
42466 +#endif
42467 +
42468 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42469 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42470 + pax_flags |= MF_PAX_RANDMMAP;
42471 +#endif
42472 +
42473 + return pax_flags;
42474 +}
42475 +#endif
42476 +
42477 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42478 +{
42479 +
42480 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42481 + ssize_t xattr_size, i;
42482 + unsigned char xattr_value[5];
42483 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42484 +
42485 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42486 + if (xattr_size <= 0)
42487 + return ~0UL;
42488 +
42489 + for (i = 0; i < xattr_size; i++)
42490 + switch (xattr_value[i]) {
42491 + default:
42492 + return ~0UL;
42493 +
42494 +#define parse_flag(option1, option2, flag) \
42495 + case option1: \
42496 + pax_flags_hardmode |= MF_PAX_##flag; \
42497 + break; \
42498 + case option2: \
42499 + pax_flags_softmode |= MF_PAX_##flag; \
42500 + break;
42501 +
42502 + parse_flag('p', 'P', PAGEEXEC);
42503 + parse_flag('e', 'E', EMUTRAMP);
42504 + parse_flag('m', 'M', MPROTECT);
42505 + parse_flag('r', 'R', RANDMMAP);
42506 + parse_flag('s', 'S', SEGMEXEC);
42507 +
42508 +#undef parse_flag
42509 + }
42510 +
42511 + if (pax_flags_hardmode & pax_flags_softmode)
42512 + return ~0UL;
42513 +
42514 +#ifdef CONFIG_PAX_SOFTMODE
42515 + if (pax_softmode)
42516 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42517 + else
42518 +#endif
42519 +
42520 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42521 +#else
42522 + return ~0UL;
42523 +#endif
42524 +
42525 +}
42526 +
42527 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42528 +{
42529 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42530 +
42531 + pax_flags = pax_parse_ei_pax(elf_ex);
42532 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42533 + xattr_pax_flags = pax_parse_xattr_pax(file);
42534 +
42535 + if (pt_pax_flags == ~0UL)
42536 + pt_pax_flags = xattr_pax_flags;
42537 + else if (xattr_pax_flags == ~0UL)
42538 + xattr_pax_flags = pt_pax_flags;
42539 + if (pt_pax_flags != xattr_pax_flags)
42540 + return -EINVAL;
42541 + if (pt_pax_flags != ~0UL)
42542 + pax_flags = pt_pax_flags;
42543 +
42544 + if (0 > pax_check_flags(&pax_flags))
42545 + return -EINVAL;
42546 +
42547 + current->mm->pax_flags = pax_flags;
42548 + return 0;
42549 +}
42550 +#endif
42551 +
42552 /*
42553 * These are the functions used to load ELF style executables and shared
42554 * libraries. There is no binary dependent code anywhere else.
42555 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42556 {
42557 unsigned int random_variable = 0;
42558
42559 +#ifdef CONFIG_PAX_RANDUSTACK
42560 + if (randomize_va_space)
42561 + return stack_top - current->mm->delta_stack;
42562 +#endif
42563 +
42564 if ((current->flags & PF_RANDOMIZE) &&
42565 !(current->personality & ADDR_NO_RANDOMIZE)) {
42566 random_variable = get_random_int() & STACK_RND_MASK;
42567 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42568 unsigned long load_addr = 0, load_bias = 0;
42569 int load_addr_set = 0;
42570 char * elf_interpreter = NULL;
42571 - unsigned long error;
42572 + unsigned long error = 0;
42573 struct elf_phdr *elf_ppnt, *elf_phdata;
42574 unsigned long elf_bss, elf_brk;
42575 int retval, i;
42576 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42577 unsigned long start_code, end_code, start_data, end_data;
42578 unsigned long reloc_func_desc __maybe_unused = 0;
42579 int executable_stack = EXSTACK_DEFAULT;
42580 - unsigned long def_flags = 0;
42581 struct {
42582 struct elfhdr elf_ex;
42583 struct elfhdr interp_elf_ex;
42584 } *loc;
42585 + unsigned long pax_task_size = TASK_SIZE;
42586
42587 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42588 if (!loc) {
42589 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42590
42591 /* OK, This is the point of no return */
42592 current->flags &= ~PF_FORKNOEXEC;
42593 - current->mm->def_flags = def_flags;
42594 +
42595 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42596 + current->mm->pax_flags = 0UL;
42597 +#endif
42598 +
42599 +#ifdef CONFIG_PAX_DLRESOLVE
42600 + current->mm->call_dl_resolve = 0UL;
42601 +#endif
42602 +
42603 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42604 + current->mm->call_syscall = 0UL;
42605 +#endif
42606 +
42607 +#ifdef CONFIG_PAX_ASLR
42608 + current->mm->delta_mmap = 0UL;
42609 + current->mm->delta_stack = 0UL;
42610 +#endif
42611 +
42612 + current->mm->def_flags = 0;
42613 +
42614 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42615 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42616 + send_sig(SIGKILL, current, 0);
42617 + goto out_free_dentry;
42618 + }
42619 +#endif
42620 +
42621 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42622 + pax_set_initial_flags(bprm);
42623 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42624 + if (pax_set_initial_flags_func)
42625 + (pax_set_initial_flags_func)(bprm);
42626 +#endif
42627 +
42628 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42629 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42630 + current->mm->context.user_cs_limit = PAGE_SIZE;
42631 + current->mm->def_flags |= VM_PAGEEXEC;
42632 + }
42633 +#endif
42634 +
42635 +#ifdef CONFIG_PAX_SEGMEXEC
42636 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42637 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42638 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42639 + pax_task_size = SEGMEXEC_TASK_SIZE;
42640 + current->mm->def_flags |= VM_NOHUGEPAGE;
42641 + }
42642 +#endif
42643 +
42644 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42645 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42646 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42647 + put_cpu();
42648 + }
42649 +#endif
42650
42651 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42652 may depend on the personality. */
42653 SET_PERSONALITY(loc->elf_ex);
42654 +
42655 +#ifdef CONFIG_PAX_ASLR
42656 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42657 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42658 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42659 + }
42660 +#endif
42661 +
42662 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42663 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42664 + executable_stack = EXSTACK_DISABLE_X;
42665 + current->personality &= ~READ_IMPLIES_EXEC;
42666 + } else
42667 +#endif
42668 +
42669 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42670 current->personality |= READ_IMPLIES_EXEC;
42671
42672 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42673 #else
42674 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42675 #endif
42676 +
42677 +#ifdef CONFIG_PAX_RANDMMAP
42678 + /* PaX: randomize base address at the default exe base if requested */
42679 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42680 +#ifdef CONFIG_SPARC64
42681 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42682 +#else
42683 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42684 +#endif
42685 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42686 + elf_flags |= MAP_FIXED;
42687 + }
42688 +#endif
42689 +
42690 }
42691
42692 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42693 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42694 * allowed task size. Note that p_filesz must always be
42695 * <= p_memsz so it is only necessary to check p_memsz.
42696 */
42697 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42698 - elf_ppnt->p_memsz > TASK_SIZE ||
42699 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42700 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42701 + elf_ppnt->p_memsz > pax_task_size ||
42702 + pax_task_size - elf_ppnt->p_memsz < k) {
42703 /* set_brk can never work. Avoid overflows. */
42704 send_sig(SIGKILL, current, 0);
42705 retval = -EINVAL;
42706 @@ -881,11 +1339,36 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42707 goto out_free_dentry;
42708 }
42709 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42710 - send_sig(SIGSEGV, current, 0);
42711 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42712 - goto out_free_dentry;
42713 + /*
42714 + * This bss-zeroing can fail if the ELF
42715 + * file specifies odd protections. So
42716 + * we don't check the return value
42717 + */
42718 }
42719
42720 +#ifdef CONFIG_PAX_RANDMMAP
42721 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42722 + unsigned long start, size;
42723 +
42724 + start = ELF_PAGEALIGN(elf_brk);
42725 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42726 + down_write(&current->mm->mmap_sem);
42727 + retval = -ENOMEM;
42728 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42729 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42730 + start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42731 + retval = IS_ERR_VALUE(start) ? start : 0;
42732 + }
42733 + up_write(&current->mm->mmap_sem);
42734 + if (retval == 0)
42735 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42736 + if (retval < 0) {
42737 + send_sig(SIGKILL, current, 0);
42738 + goto out_free_dentry;
42739 + }
42740 + }
42741 +#endif
42742 +
42743 if (elf_interpreter) {
42744 unsigned long uninitialized_var(interp_map_addr);
42745
42746 @@ -1098,7 +1581,7 @@ out:
42747 * Decide what to dump of a segment, part, all or none.
42748 */
42749 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42750 - unsigned long mm_flags)
42751 + unsigned long mm_flags, long signr)
42752 {
42753 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42754
42755 @@ -1132,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42756 if (vma->vm_file == NULL)
42757 return 0;
42758
42759 - if (FILTER(MAPPED_PRIVATE))
42760 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42761 goto whole;
42762
42763 /*
42764 @@ -1354,9 +1837,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42765 {
42766 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42767 int i = 0;
42768 - do
42769 + do {
42770 i += 2;
42771 - while (auxv[i - 2] != AT_NULL);
42772 + } while (auxv[i - 2] != AT_NULL);
42773 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42774 }
42775
42776 @@ -1862,14 +2345,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42777 }
42778
42779 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42780 - unsigned long mm_flags)
42781 + struct coredump_params *cprm)
42782 {
42783 struct vm_area_struct *vma;
42784 size_t size = 0;
42785
42786 for (vma = first_vma(current, gate_vma); vma != NULL;
42787 vma = next_vma(vma, gate_vma))
42788 - size += vma_dump_size(vma, mm_flags);
42789 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42790 return size;
42791 }
42792
42793 @@ -1963,7 +2446,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42794
42795 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42796
42797 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42798 + offset += elf_core_vma_data_size(gate_vma, cprm);
42799 offset += elf_core_extra_data_size();
42800 e_shoff = offset;
42801
42802 @@ -1977,10 +2460,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42803 offset = dataoff;
42804
42805 size += sizeof(*elf);
42806 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42807 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42808 goto end_coredump;
42809
42810 size += sizeof(*phdr4note);
42811 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42812 if (size > cprm->limit
42813 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42814 goto end_coredump;
42815 @@ -1994,7 +2479,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42816 phdr.p_offset = offset;
42817 phdr.p_vaddr = vma->vm_start;
42818 phdr.p_paddr = 0;
42819 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42820 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42821 phdr.p_memsz = vma->vm_end - vma->vm_start;
42822 offset += phdr.p_filesz;
42823 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42824 @@ -2005,6 +2490,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42825 phdr.p_align = ELF_EXEC_PAGESIZE;
42826
42827 size += sizeof(phdr);
42828 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42829 if (size > cprm->limit
42830 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42831 goto end_coredump;
42832 @@ -2029,7 +2515,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42833 unsigned long addr;
42834 unsigned long end;
42835
42836 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42837 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42838
42839 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42840 struct page *page;
42841 @@ -2038,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42842 page = get_dump_page(addr);
42843 if (page) {
42844 void *kaddr = kmap(page);
42845 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42846 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42847 !dump_write(cprm->file, kaddr,
42848 PAGE_SIZE);
42849 @@ -2055,6 +2542,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42850
42851 if (e_phnum == PN_XNUM) {
42852 size += sizeof(*shdr4extnum);
42853 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42854 if (size > cprm->limit
42855 || !dump_write(cprm->file, shdr4extnum,
42856 sizeof(*shdr4extnum)))
42857 @@ -2075,6 +2563,97 @@ out:
42858
42859 #endif /* CONFIG_ELF_CORE */
42860
42861 +#ifdef CONFIG_PAX_MPROTECT
42862 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42863 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42864 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42865 + *
42866 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42867 + * basis because we want to allow the common case and not the special ones.
42868 + */
42869 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42870 +{
42871 + struct elfhdr elf_h;
42872 + struct elf_phdr elf_p;
42873 + unsigned long i;
42874 + unsigned long oldflags;
42875 + bool is_textrel_rw, is_textrel_rx, is_relro;
42876 +
42877 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42878 + return;
42879 +
42880 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42881 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42882 +
42883 +#ifdef CONFIG_PAX_ELFRELOCS
42884 + /* possible TEXTREL */
42885 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42886 + 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);
42887 +#else
42888 + is_textrel_rw = false;
42889 + is_textrel_rx = false;
42890 +#endif
42891 +
42892 + /* possible RELRO */
42893 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42894 +
42895 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42896 + return;
42897 +
42898 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42899 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42900 +
42901 +#ifdef CONFIG_PAX_ETEXECRELOCS
42902 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42903 +#else
42904 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42905 +#endif
42906 +
42907 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42908 + !elf_check_arch(&elf_h) ||
42909 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42910 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42911 + return;
42912 +
42913 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42914 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42915 + return;
42916 + switch (elf_p.p_type) {
42917 + case PT_DYNAMIC:
42918 + if (!is_textrel_rw && !is_textrel_rx)
42919 + continue;
42920 + i = 0UL;
42921 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42922 + elf_dyn dyn;
42923 +
42924 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42925 + return;
42926 + if (dyn.d_tag == DT_NULL)
42927 + return;
42928 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42929 + gr_log_textrel(vma);
42930 + if (is_textrel_rw)
42931 + vma->vm_flags |= VM_MAYWRITE;
42932 + else
42933 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42934 + vma->vm_flags &= ~VM_MAYWRITE;
42935 + return;
42936 + }
42937 + i++;
42938 + }
42939 + return;
42940 +
42941 + case PT_GNU_RELRO:
42942 + if (!is_relro)
42943 + continue;
42944 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42945 + vma->vm_flags &= ~VM_MAYWRITE;
42946 + return;
42947 + }
42948 + }
42949 +}
42950 +#endif
42951 +
42952 static int __init init_elf_binfmt(void)
42953 {
42954 return register_binfmt(&elf_format);
42955 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42956 index 1bffbe0..c8c283e 100644
42957 --- a/fs/binfmt_flat.c
42958 +++ b/fs/binfmt_flat.c
42959 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42960 realdatastart = (unsigned long) -ENOMEM;
42961 printk("Unable to allocate RAM for process data, errno %d\n",
42962 (int)-realdatastart);
42963 + down_write(&current->mm->mmap_sem);
42964 do_munmap(current->mm, textpos, text_len);
42965 + up_write(&current->mm->mmap_sem);
42966 ret = realdatastart;
42967 goto err;
42968 }
42969 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42970 }
42971 if (IS_ERR_VALUE(result)) {
42972 printk("Unable to read data+bss, errno %d\n", (int)-result);
42973 + down_write(&current->mm->mmap_sem);
42974 do_munmap(current->mm, textpos, text_len);
42975 do_munmap(current->mm, realdatastart, len);
42976 + up_write(&current->mm->mmap_sem);
42977 ret = result;
42978 goto err;
42979 }
42980 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42981 }
42982 if (IS_ERR_VALUE(result)) {
42983 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42984 + down_write(&current->mm->mmap_sem);
42985 do_munmap(current->mm, textpos, text_len + data_len + extra +
42986 MAX_SHARED_LIBS * sizeof(unsigned long));
42987 + up_write(&current->mm->mmap_sem);
42988 ret = result;
42989 goto err;
42990 }
42991 diff --git a/fs/bio.c b/fs/bio.c
42992 index b980ecd..74800bf 100644
42993 --- a/fs/bio.c
42994 +++ b/fs/bio.c
42995 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42996 /*
42997 * Overflow, abort
42998 */
42999 - if (end < start)
43000 + if (end < start || end - start > INT_MAX - nr_pages)
43001 return ERR_PTR(-EINVAL);
43002
43003 nr_pages += end - start;
43004 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43005 const int read = bio_data_dir(bio) == READ;
43006 struct bio_map_data *bmd = bio->bi_private;
43007 int i;
43008 - char *p = bmd->sgvecs[0].iov_base;
43009 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43010
43011 __bio_for_each_segment(bvec, bio, i, 0) {
43012 char *addr = page_address(bvec->bv_page);
43013 diff --git a/fs/block_dev.c b/fs/block_dev.c
43014 index 5e9f198..6bf9b1c 100644
43015 --- a/fs/block_dev.c
43016 +++ b/fs/block_dev.c
43017 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43018 else if (bdev->bd_contains == bdev)
43019 return true; /* is a whole device which isn't held */
43020
43021 - else if (whole->bd_holder == bd_may_claim)
43022 + else if (whole->bd_holder == (void *)bd_may_claim)
43023 return true; /* is a partition of a device that is being partitioned */
43024 else if (whole->bd_holder != NULL)
43025 return false; /* is a partition of a held device */
43026 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43027 index d986824..af1befd 100644
43028 --- a/fs/btrfs/check-integrity.c
43029 +++ b/fs/btrfs/check-integrity.c
43030 @@ -157,7 +157,7 @@ struct btrfsic_block {
43031 union {
43032 bio_end_io_t *bio;
43033 bh_end_io_t *bh;
43034 - } orig_bio_bh_end_io;
43035 + } __no_const orig_bio_bh_end_io;
43036 int submit_bio_bh_rw;
43037 u64 flush_gen; /* only valid if !never_written */
43038 };
43039 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43040 index 0639a55..7d9e07f 100644
43041 --- a/fs/btrfs/ctree.c
43042 +++ b/fs/btrfs/ctree.c
43043 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43044 free_extent_buffer(buf);
43045 add_root_to_dirty_list(root);
43046 } else {
43047 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43048 - parent_start = parent->start;
43049 - else
43050 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43051 + if (parent)
43052 + parent_start = parent->start;
43053 + else
43054 + parent_start = 0;
43055 + } else
43056 parent_start = 0;
43057
43058 WARN_ON(trans->transid != btrfs_header_generation(parent));
43059 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43060 index 892b347..b3db246 100644
43061 --- a/fs/btrfs/inode.c
43062 +++ b/fs/btrfs/inode.c
43063 @@ -6930,7 +6930,7 @@ fail:
43064 return -ENOMEM;
43065 }
43066
43067 -static int btrfs_getattr(struct vfsmount *mnt,
43068 +int btrfs_getattr(struct vfsmount *mnt,
43069 struct dentry *dentry, struct kstat *stat)
43070 {
43071 struct inode *inode = dentry->d_inode;
43072 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43073 return 0;
43074 }
43075
43076 +EXPORT_SYMBOL(btrfs_getattr);
43077 +
43078 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43079 +{
43080 + return BTRFS_I(inode)->root->anon_dev;
43081 +}
43082 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43083 +
43084 /*
43085 * If a file is moved, it will inherit the cow and compression flags of the new
43086 * directory.
43087 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43088 index d8b5471..e5463d7 100644
43089 --- a/fs/btrfs/ioctl.c
43090 +++ b/fs/btrfs/ioctl.c
43091 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43092 for (i = 0; i < num_types; i++) {
43093 struct btrfs_space_info *tmp;
43094
43095 + /* Don't copy in more than we allocated */
43096 if (!slot_count)
43097 break;
43098
43099 + slot_count--;
43100 +
43101 info = NULL;
43102 rcu_read_lock();
43103 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43104 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43105 memcpy(dest, &space, sizeof(space));
43106 dest++;
43107 space_args.total_spaces++;
43108 - slot_count--;
43109 }
43110 - if (!slot_count)
43111 - break;
43112 }
43113 up_read(&info->groups_sem);
43114 }
43115
43116 - user_dest = (struct btrfs_ioctl_space_info *)
43117 + user_dest = (struct btrfs_ioctl_space_info __user *)
43118 (arg + sizeof(struct btrfs_ioctl_space_args));
43119
43120 if (copy_to_user(user_dest, dest_orig, alloc_size))
43121 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43122 index 8c1aae2..1e46446 100644
43123 --- a/fs/btrfs/relocation.c
43124 +++ b/fs/btrfs/relocation.c
43125 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43126 }
43127 spin_unlock(&rc->reloc_root_tree.lock);
43128
43129 - BUG_ON((struct btrfs_root *)node->data != root);
43130 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43131
43132 if (!del) {
43133 spin_lock(&rc->reloc_root_tree.lock);
43134 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43135 index 622f469..e8d2d55 100644
43136 --- a/fs/cachefiles/bind.c
43137 +++ b/fs/cachefiles/bind.c
43138 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43139 args);
43140
43141 /* start by checking things over */
43142 - ASSERT(cache->fstop_percent >= 0 &&
43143 - cache->fstop_percent < cache->fcull_percent &&
43144 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43145 cache->fcull_percent < cache->frun_percent &&
43146 cache->frun_percent < 100);
43147
43148 - ASSERT(cache->bstop_percent >= 0 &&
43149 - cache->bstop_percent < cache->bcull_percent &&
43150 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43151 cache->bcull_percent < cache->brun_percent &&
43152 cache->brun_percent < 100);
43153
43154 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43155 index 0a1467b..6a53245 100644
43156 --- a/fs/cachefiles/daemon.c
43157 +++ b/fs/cachefiles/daemon.c
43158 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43159 if (n > buflen)
43160 return -EMSGSIZE;
43161
43162 - if (copy_to_user(_buffer, buffer, n) != 0)
43163 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43164 return -EFAULT;
43165
43166 return n;
43167 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43168 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43169 return -EIO;
43170
43171 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43172 + if (datalen > PAGE_SIZE - 1)
43173 return -EOPNOTSUPP;
43174
43175 /* drag the command string into the kernel so we can parse it */
43176 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43177 if (args[0] != '%' || args[1] != '\0')
43178 return -EINVAL;
43179
43180 - if (fstop < 0 || fstop >= cache->fcull_percent)
43181 + if (fstop >= cache->fcull_percent)
43182 return cachefiles_daemon_range_error(cache, args);
43183
43184 cache->fstop_percent = fstop;
43185 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43186 if (args[0] != '%' || args[1] != '\0')
43187 return -EINVAL;
43188
43189 - if (bstop < 0 || bstop >= cache->bcull_percent)
43190 + if (bstop >= cache->bcull_percent)
43191 return cachefiles_daemon_range_error(cache, args);
43192
43193 cache->bstop_percent = bstop;
43194 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43195 index bd6bc1b..b627b53 100644
43196 --- a/fs/cachefiles/internal.h
43197 +++ b/fs/cachefiles/internal.h
43198 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43199 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43200 struct rb_root active_nodes; /* active nodes (can't be culled) */
43201 rwlock_t active_lock; /* lock for active_nodes */
43202 - atomic_t gravecounter; /* graveyard uniquifier */
43203 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43204 unsigned frun_percent; /* when to stop culling (% files) */
43205 unsigned fcull_percent; /* when to start culling (% files) */
43206 unsigned fstop_percent; /* when to stop allocating (% files) */
43207 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43208 * proc.c
43209 */
43210 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43211 -extern atomic_t cachefiles_lookup_histogram[HZ];
43212 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43213 -extern atomic_t cachefiles_create_histogram[HZ];
43214 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43215 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43216 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43217
43218 extern int __init cachefiles_proc_init(void);
43219 extern void cachefiles_proc_cleanup(void);
43220 static inline
43221 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43222 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43223 {
43224 unsigned long jif = jiffies - start_jif;
43225 if (jif >= HZ)
43226 jif = HZ - 1;
43227 - atomic_inc(&histogram[jif]);
43228 + atomic_inc_unchecked(&histogram[jif]);
43229 }
43230
43231 #else
43232 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43233 index a0358c2..d6137f2 100644
43234 --- a/fs/cachefiles/namei.c
43235 +++ b/fs/cachefiles/namei.c
43236 @@ -318,7 +318,7 @@ try_again:
43237 /* first step is to make up a grave dentry in the graveyard */
43238 sprintf(nbuffer, "%08x%08x",
43239 (uint32_t) get_seconds(),
43240 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43241 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43242
43243 /* do the multiway lock magic */
43244 trap = lock_rename(cache->graveyard, dir);
43245 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43246 index eccd339..4c1d995 100644
43247 --- a/fs/cachefiles/proc.c
43248 +++ b/fs/cachefiles/proc.c
43249 @@ -14,9 +14,9 @@
43250 #include <linux/seq_file.h>
43251 #include "internal.h"
43252
43253 -atomic_t cachefiles_lookup_histogram[HZ];
43254 -atomic_t cachefiles_mkdir_histogram[HZ];
43255 -atomic_t cachefiles_create_histogram[HZ];
43256 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43257 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43258 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43259
43260 /*
43261 * display the latency histogram
43262 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43263 return 0;
43264 default:
43265 index = (unsigned long) v - 3;
43266 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43267 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43268 - z = atomic_read(&cachefiles_create_histogram[index]);
43269 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43270 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43271 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43272 if (x == 0 && y == 0 && z == 0)
43273 return 0;
43274
43275 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43276 index 0e3c092..818480e 100644
43277 --- a/fs/cachefiles/rdwr.c
43278 +++ b/fs/cachefiles/rdwr.c
43279 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43280 old_fs = get_fs();
43281 set_fs(KERNEL_DS);
43282 ret = file->f_op->write(
43283 - file, (const void __user *) data, len, &pos);
43284 + file, (const void __force_user *) data, len, &pos);
43285 set_fs(old_fs);
43286 kunmap(page);
43287 if (ret != len)
43288 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43289 index 3e8094b..cb3ff3d 100644
43290 --- a/fs/ceph/dir.c
43291 +++ b/fs/ceph/dir.c
43292 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43293 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43294 struct ceph_mds_client *mdsc = fsc->mdsc;
43295 unsigned frag = fpos_frag(filp->f_pos);
43296 - int off = fpos_off(filp->f_pos);
43297 + unsigned int off = fpos_off(filp->f_pos);
43298 int err;
43299 u32 ftype;
43300 struct ceph_mds_reply_info_parsed *rinfo;
43301 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43302 if (nd &&
43303 (nd->flags & LOOKUP_OPEN) &&
43304 !(nd->intent.open.flags & O_CREAT)) {
43305 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43306 + int mode = nd->intent.open.create_mode & ~current_umask();
43307 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43308 }
43309
43310 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43311 index cfd1ce3..6b13a74 100644
43312 --- a/fs/cifs/asn1.c
43313 +++ b/fs/cifs/asn1.c
43314 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43315
43316 static int
43317 asn1_oid_decode(struct asn1_ctx *ctx,
43318 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43319 +static int
43320 +asn1_oid_decode(struct asn1_ctx *ctx,
43321 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43322 {
43323 unsigned long subid;
43324 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43325 index 24b3dfc..3cd5454 100644
43326 --- a/fs/cifs/cifs_debug.c
43327 +++ b/fs/cifs/cifs_debug.c
43328 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43329
43330 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43331 #ifdef CONFIG_CIFS_STATS2
43332 - atomic_set(&totBufAllocCount, 0);
43333 - atomic_set(&totSmBufAllocCount, 0);
43334 + atomic_set_unchecked(&totBufAllocCount, 0);
43335 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43336 #endif /* CONFIG_CIFS_STATS2 */
43337 spin_lock(&cifs_tcp_ses_lock);
43338 list_for_each(tmp1, &cifs_tcp_ses_list) {
43339 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43340 tcon = list_entry(tmp3,
43341 struct cifs_tcon,
43342 tcon_list);
43343 - atomic_set(&tcon->num_smbs_sent, 0);
43344 - atomic_set(&tcon->num_writes, 0);
43345 - atomic_set(&tcon->num_reads, 0);
43346 - atomic_set(&tcon->num_oplock_brks, 0);
43347 - atomic_set(&tcon->num_opens, 0);
43348 - atomic_set(&tcon->num_posixopens, 0);
43349 - atomic_set(&tcon->num_posixmkdirs, 0);
43350 - atomic_set(&tcon->num_closes, 0);
43351 - atomic_set(&tcon->num_deletes, 0);
43352 - atomic_set(&tcon->num_mkdirs, 0);
43353 - atomic_set(&tcon->num_rmdirs, 0);
43354 - atomic_set(&tcon->num_renames, 0);
43355 - atomic_set(&tcon->num_t2renames, 0);
43356 - atomic_set(&tcon->num_ffirst, 0);
43357 - atomic_set(&tcon->num_fnext, 0);
43358 - atomic_set(&tcon->num_fclose, 0);
43359 - atomic_set(&tcon->num_hardlinks, 0);
43360 - atomic_set(&tcon->num_symlinks, 0);
43361 - atomic_set(&tcon->num_locks, 0);
43362 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43363 + atomic_set_unchecked(&tcon->num_writes, 0);
43364 + atomic_set_unchecked(&tcon->num_reads, 0);
43365 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43366 + atomic_set_unchecked(&tcon->num_opens, 0);
43367 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43368 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43369 + atomic_set_unchecked(&tcon->num_closes, 0);
43370 + atomic_set_unchecked(&tcon->num_deletes, 0);
43371 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43372 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43373 + atomic_set_unchecked(&tcon->num_renames, 0);
43374 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43375 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43376 + atomic_set_unchecked(&tcon->num_fnext, 0);
43377 + atomic_set_unchecked(&tcon->num_fclose, 0);
43378 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43379 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43380 + atomic_set_unchecked(&tcon->num_locks, 0);
43381 }
43382 }
43383 }
43384 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43385 smBufAllocCount.counter, cifs_min_small);
43386 #ifdef CONFIG_CIFS_STATS2
43387 seq_printf(m, "Total Large %d Small %d Allocations\n",
43388 - atomic_read(&totBufAllocCount),
43389 - atomic_read(&totSmBufAllocCount));
43390 + atomic_read_unchecked(&totBufAllocCount),
43391 + atomic_read_unchecked(&totSmBufAllocCount));
43392 #endif /* CONFIG_CIFS_STATS2 */
43393
43394 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43395 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43396 if (tcon->need_reconnect)
43397 seq_puts(m, "\tDISCONNECTED ");
43398 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43399 - atomic_read(&tcon->num_smbs_sent),
43400 - atomic_read(&tcon->num_oplock_brks));
43401 + atomic_read_unchecked(&tcon->num_smbs_sent),
43402 + atomic_read_unchecked(&tcon->num_oplock_brks));
43403 seq_printf(m, "\nReads: %d Bytes: %lld",
43404 - atomic_read(&tcon->num_reads),
43405 + atomic_read_unchecked(&tcon->num_reads),
43406 (long long)(tcon->bytes_read));
43407 seq_printf(m, "\nWrites: %d Bytes: %lld",
43408 - atomic_read(&tcon->num_writes),
43409 + atomic_read_unchecked(&tcon->num_writes),
43410 (long long)(tcon->bytes_written));
43411 seq_printf(m, "\nFlushes: %d",
43412 - atomic_read(&tcon->num_flushes));
43413 + atomic_read_unchecked(&tcon->num_flushes));
43414 seq_printf(m, "\nLocks: %d HardLinks: %d "
43415 "Symlinks: %d",
43416 - atomic_read(&tcon->num_locks),
43417 - atomic_read(&tcon->num_hardlinks),
43418 - atomic_read(&tcon->num_symlinks));
43419 + atomic_read_unchecked(&tcon->num_locks),
43420 + atomic_read_unchecked(&tcon->num_hardlinks),
43421 + atomic_read_unchecked(&tcon->num_symlinks));
43422 seq_printf(m, "\nOpens: %d Closes: %d "
43423 "Deletes: %d",
43424 - atomic_read(&tcon->num_opens),
43425 - atomic_read(&tcon->num_closes),
43426 - atomic_read(&tcon->num_deletes));
43427 + atomic_read_unchecked(&tcon->num_opens),
43428 + atomic_read_unchecked(&tcon->num_closes),
43429 + atomic_read_unchecked(&tcon->num_deletes));
43430 seq_printf(m, "\nPosix Opens: %d "
43431 "Posix Mkdirs: %d",
43432 - atomic_read(&tcon->num_posixopens),
43433 - atomic_read(&tcon->num_posixmkdirs));
43434 + atomic_read_unchecked(&tcon->num_posixopens),
43435 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43436 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43437 - atomic_read(&tcon->num_mkdirs),
43438 - atomic_read(&tcon->num_rmdirs));
43439 + atomic_read_unchecked(&tcon->num_mkdirs),
43440 + atomic_read_unchecked(&tcon->num_rmdirs));
43441 seq_printf(m, "\nRenames: %d T2 Renames %d",
43442 - atomic_read(&tcon->num_renames),
43443 - atomic_read(&tcon->num_t2renames));
43444 + atomic_read_unchecked(&tcon->num_renames),
43445 + atomic_read_unchecked(&tcon->num_t2renames));
43446 seq_printf(m, "\nFindFirst: %d FNext %d "
43447 "FClose %d",
43448 - atomic_read(&tcon->num_ffirst),
43449 - atomic_read(&tcon->num_fnext),
43450 - atomic_read(&tcon->num_fclose));
43451 + atomic_read_unchecked(&tcon->num_ffirst),
43452 + atomic_read_unchecked(&tcon->num_fnext),
43453 + atomic_read_unchecked(&tcon->num_fclose));
43454 }
43455 }
43456 }
43457 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43458 index 6ee1cb4..8443157 100644
43459 --- a/fs/cifs/cifsfs.c
43460 +++ b/fs/cifs/cifsfs.c
43461 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43462 cifs_req_cachep = kmem_cache_create("cifs_request",
43463 CIFSMaxBufSize +
43464 MAX_CIFS_HDR_SIZE, 0,
43465 - SLAB_HWCACHE_ALIGN, NULL);
43466 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43467 if (cifs_req_cachep == NULL)
43468 return -ENOMEM;
43469
43470 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43471 efficient to alloc 1 per page off the slab compared to 17K (5page)
43472 alloc of large cifs buffers even when page debugging is on */
43473 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43474 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43475 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43476 NULL);
43477 if (cifs_sm_req_cachep == NULL) {
43478 mempool_destroy(cifs_req_poolp);
43479 @@ -1101,8 +1101,8 @@ init_cifs(void)
43480 atomic_set(&bufAllocCount, 0);
43481 atomic_set(&smBufAllocCount, 0);
43482 #ifdef CONFIG_CIFS_STATS2
43483 - atomic_set(&totBufAllocCount, 0);
43484 - atomic_set(&totSmBufAllocCount, 0);
43485 + atomic_set_unchecked(&totBufAllocCount, 0);
43486 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43487 #endif /* CONFIG_CIFS_STATS2 */
43488
43489 atomic_set(&midCount, 0);
43490 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43491 index d47d20a..77e8b33 100644
43492 --- a/fs/cifs/cifsglob.h
43493 +++ b/fs/cifs/cifsglob.h
43494 @@ -388,28 +388,28 @@ struct cifs_tcon {
43495 __u16 Flags; /* optional support bits */
43496 enum statusEnum tidStatus;
43497 #ifdef CONFIG_CIFS_STATS
43498 - atomic_t num_smbs_sent;
43499 - atomic_t num_writes;
43500 - atomic_t num_reads;
43501 - atomic_t num_flushes;
43502 - atomic_t num_oplock_brks;
43503 - atomic_t num_opens;
43504 - atomic_t num_closes;
43505 - atomic_t num_deletes;
43506 - atomic_t num_mkdirs;
43507 - atomic_t num_posixopens;
43508 - atomic_t num_posixmkdirs;
43509 - atomic_t num_rmdirs;
43510 - atomic_t num_renames;
43511 - atomic_t num_t2renames;
43512 - atomic_t num_ffirst;
43513 - atomic_t num_fnext;
43514 - atomic_t num_fclose;
43515 - atomic_t num_hardlinks;
43516 - atomic_t num_symlinks;
43517 - atomic_t num_locks;
43518 - atomic_t num_acl_get;
43519 - atomic_t num_acl_set;
43520 + atomic_unchecked_t num_smbs_sent;
43521 + atomic_unchecked_t num_writes;
43522 + atomic_unchecked_t num_reads;
43523 + atomic_unchecked_t num_flushes;
43524 + atomic_unchecked_t num_oplock_brks;
43525 + atomic_unchecked_t num_opens;
43526 + atomic_unchecked_t num_closes;
43527 + atomic_unchecked_t num_deletes;
43528 + atomic_unchecked_t num_mkdirs;
43529 + atomic_unchecked_t num_posixopens;
43530 + atomic_unchecked_t num_posixmkdirs;
43531 + atomic_unchecked_t num_rmdirs;
43532 + atomic_unchecked_t num_renames;
43533 + atomic_unchecked_t num_t2renames;
43534 + atomic_unchecked_t num_ffirst;
43535 + atomic_unchecked_t num_fnext;
43536 + atomic_unchecked_t num_fclose;
43537 + atomic_unchecked_t num_hardlinks;
43538 + atomic_unchecked_t num_symlinks;
43539 + atomic_unchecked_t num_locks;
43540 + atomic_unchecked_t num_acl_get;
43541 + atomic_unchecked_t num_acl_set;
43542 #ifdef CONFIG_CIFS_STATS2
43543 unsigned long long time_writes;
43544 unsigned long long time_reads;
43545 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43546 }
43547
43548 #ifdef CONFIG_CIFS_STATS
43549 -#define cifs_stats_inc atomic_inc
43550 +#define cifs_stats_inc atomic_inc_unchecked
43551
43552 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43553 unsigned int bytes)
43554 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43555 /* Various Debug counters */
43556 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43557 #ifdef CONFIG_CIFS_STATS2
43558 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43559 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43560 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43561 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43562 #endif
43563 GLOBAL_EXTERN atomic_t smBufAllocCount;
43564 GLOBAL_EXTERN atomic_t midCount;
43565 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43566 index 6b0e064..94e6c3c 100644
43567 --- a/fs/cifs/link.c
43568 +++ b/fs/cifs/link.c
43569 @@ -600,7 +600,7 @@ symlink_exit:
43570
43571 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43572 {
43573 - char *p = nd_get_link(nd);
43574 + const char *p = nd_get_link(nd);
43575 if (!IS_ERR(p))
43576 kfree(p);
43577 }
43578 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43579 index 703ef5c..2a44ed5 100644
43580 --- a/fs/cifs/misc.c
43581 +++ b/fs/cifs/misc.c
43582 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43583 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43584 atomic_inc(&bufAllocCount);
43585 #ifdef CONFIG_CIFS_STATS2
43586 - atomic_inc(&totBufAllocCount);
43587 + atomic_inc_unchecked(&totBufAllocCount);
43588 #endif /* CONFIG_CIFS_STATS2 */
43589 }
43590
43591 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43592 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43593 atomic_inc(&smBufAllocCount);
43594 #ifdef CONFIG_CIFS_STATS2
43595 - atomic_inc(&totSmBufAllocCount);
43596 + atomic_inc_unchecked(&totSmBufAllocCount);
43597 #endif /* CONFIG_CIFS_STATS2 */
43598
43599 }
43600 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43601 index 6901578..d402eb5 100644
43602 --- a/fs/coda/cache.c
43603 +++ b/fs/coda/cache.c
43604 @@ -24,7 +24,7 @@
43605 #include "coda_linux.h"
43606 #include "coda_cache.h"
43607
43608 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43609 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43610
43611 /* replace or extend an acl cache hit */
43612 void coda_cache_enter(struct inode *inode, int mask)
43613 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43614 struct coda_inode_info *cii = ITOC(inode);
43615
43616 spin_lock(&cii->c_lock);
43617 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43618 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43619 if (cii->c_uid != current_fsuid()) {
43620 cii->c_uid = current_fsuid();
43621 cii->c_cached_perm = mask;
43622 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43623 {
43624 struct coda_inode_info *cii = ITOC(inode);
43625 spin_lock(&cii->c_lock);
43626 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43627 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43628 spin_unlock(&cii->c_lock);
43629 }
43630
43631 /* remove all acl caches */
43632 void coda_cache_clear_all(struct super_block *sb)
43633 {
43634 - atomic_inc(&permission_epoch);
43635 + atomic_inc_unchecked(&permission_epoch);
43636 }
43637
43638
43639 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43640 spin_lock(&cii->c_lock);
43641 hit = (mask & cii->c_cached_perm) == mask &&
43642 cii->c_uid == current_fsuid() &&
43643 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43644 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43645 spin_unlock(&cii->c_lock);
43646
43647 return hit;
43648 diff --git a/fs/compat.c b/fs/compat.c
43649 index 07880ba..3fb2862 100644
43650 --- a/fs/compat.c
43651 +++ b/fs/compat.c
43652 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43653
43654 set_fs(KERNEL_DS);
43655 /* The __user pointer cast is valid because of the set_fs() */
43656 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43657 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43658 set_fs(oldfs);
43659 /* truncating is ok because it's a user address */
43660 if (!ret)
43661 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43662 goto out;
43663
43664 ret = -EINVAL;
43665 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43666 + if (nr_segs > UIO_MAXIOV)
43667 goto out;
43668 if (nr_segs > fast_segs) {
43669 ret = -ENOMEM;
43670 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43671
43672 struct compat_readdir_callback {
43673 struct compat_old_linux_dirent __user *dirent;
43674 + struct file * file;
43675 int result;
43676 };
43677
43678 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43679 buf->result = -EOVERFLOW;
43680 return -EOVERFLOW;
43681 }
43682 +
43683 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43684 + return 0;
43685 +
43686 buf->result++;
43687 dirent = buf->dirent;
43688 if (!access_ok(VERIFY_WRITE, dirent,
43689 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43690
43691 buf.result = 0;
43692 buf.dirent = dirent;
43693 + buf.file = file;
43694
43695 error = vfs_readdir(file, compat_fillonedir, &buf);
43696 if (buf.result)
43697 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
43698 struct compat_getdents_callback {
43699 struct compat_linux_dirent __user *current_dir;
43700 struct compat_linux_dirent __user *previous;
43701 + struct file * file;
43702 int count;
43703 int error;
43704 };
43705 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43706 buf->error = -EOVERFLOW;
43707 return -EOVERFLOW;
43708 }
43709 +
43710 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43711 + return 0;
43712 +
43713 dirent = buf->previous;
43714 if (dirent) {
43715 if (__put_user(offset, &dirent->d_off))
43716 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43717 buf.previous = NULL;
43718 buf.count = count;
43719 buf.error = 0;
43720 + buf.file = file;
43721
43722 error = vfs_readdir(file, compat_filldir, &buf);
43723 if (error >= 0)
43724 @@ -990,6 +1002,7 @@ out:
43725 struct compat_getdents_callback64 {
43726 struct linux_dirent64 __user *current_dir;
43727 struct linux_dirent64 __user *previous;
43728 + struct file * file;
43729 int count;
43730 int error;
43731 };
43732 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43733 buf->error = -EINVAL; /* only used if we fail.. */
43734 if (reclen > buf->count)
43735 return -EINVAL;
43736 +
43737 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43738 + return 0;
43739 +
43740 dirent = buf->previous;
43741
43742 if (dirent) {
43743 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43744 buf.previous = NULL;
43745 buf.count = count;
43746 buf.error = 0;
43747 + buf.file = file;
43748
43749 error = vfs_readdir(file, compat_filldir64, &buf);
43750 if (error >= 0)
43751 error = buf.error;
43752 lastdirent = buf.previous;
43753 if (lastdirent) {
43754 - typeof(lastdirent->d_off) d_off = file->f_pos;
43755 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43756 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43757 error = -EFAULT;
43758 else
43759 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43760 index 112e45a..b59845b 100644
43761 --- a/fs/compat_binfmt_elf.c
43762 +++ b/fs/compat_binfmt_elf.c
43763 @@ -30,11 +30,13 @@
43764 #undef elf_phdr
43765 #undef elf_shdr
43766 #undef elf_note
43767 +#undef elf_dyn
43768 #undef elf_addr_t
43769 #define elfhdr elf32_hdr
43770 #define elf_phdr elf32_phdr
43771 #define elf_shdr elf32_shdr
43772 #define elf_note elf32_note
43773 +#define elf_dyn Elf32_Dyn
43774 #define elf_addr_t Elf32_Addr
43775
43776 /*
43777 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43778 index a26bea1..ae23e72 100644
43779 --- a/fs/compat_ioctl.c
43780 +++ b/fs/compat_ioctl.c
43781 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43782
43783 err = get_user(palp, &up->palette);
43784 err |= get_user(length, &up->length);
43785 + if (err)
43786 + return -EFAULT;
43787
43788 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43789 err = put_user(compat_ptr(palp), &up_native->palette);
43790 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43791 return -EFAULT;
43792 if (__get_user(udata, &ss32->iomem_base))
43793 return -EFAULT;
43794 - ss.iomem_base = compat_ptr(udata);
43795 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43796 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43797 __get_user(ss.port_high, &ss32->port_high))
43798 return -EFAULT;
43799 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43800 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43801 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43802 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43803 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43804 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43805 return -EFAULT;
43806
43807 return ioctl_preallocate(file, p);
43808 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43809 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43810 {
43811 unsigned int a, b;
43812 - a = *(unsigned int *)p;
43813 - b = *(unsigned int *)q;
43814 + a = *(const unsigned int *)p;
43815 + b = *(const unsigned int *)q;
43816 if (a > b)
43817 return 1;
43818 if (a < b)
43819 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43820 index 5ddd7eb..c18bf04 100644
43821 --- a/fs/configfs/dir.c
43822 +++ b/fs/configfs/dir.c
43823 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43824 }
43825 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43826 struct configfs_dirent *next;
43827 - const char * name;
43828 + const unsigned char * name;
43829 + char d_name[sizeof(next->s_dentry->d_iname)];
43830 int len;
43831 struct inode *inode = NULL;
43832
43833 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43834 continue;
43835
43836 name = configfs_get_name(next);
43837 - len = strlen(name);
43838 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43839 + len = next->s_dentry->d_name.len;
43840 + memcpy(d_name, name, len);
43841 + name = d_name;
43842 + } else
43843 + len = strlen(name);
43844
43845 /*
43846 * We'll have a dentry and an inode for
43847 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
43848 index 2b6cb23..d76e879 100644
43849 --- a/fs/configfs/file.c
43850 +++ b/fs/configfs/file.c
43851 @@ -135,6 +135,8 @@ out:
43852 */
43853
43854 static int
43855 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
43856 +static int
43857 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
43858 {
43859 int error;
43860 diff --git a/fs/dcache.c b/fs/dcache.c
43861 index 2576d14..0cec38d 100644
43862 --- a/fs/dcache.c
43863 +++ b/fs/dcache.c
43864 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43865 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43866
43867 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43868 - unsigned long hash)
43869 + unsigned int hash)
43870 {
43871 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43872 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43873 + hash += (unsigned long) parent / L1_CACHE_BYTES;
43874 + hash = hash + (hash >> D_HASHBITS);
43875 return dentry_hashtable + (hash & D_HASHMASK);
43876 }
43877
43878 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43879 mempages -= reserve;
43880
43881 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43882 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43883 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43884
43885 dcache_init();
43886 inode_init();
43887 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43888 index 956d5dd..e755e04 100644
43889 --- a/fs/debugfs/inode.c
43890 +++ b/fs/debugfs/inode.c
43891 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43892 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43893 {
43894 return debugfs_create_file(name,
43895 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43896 + S_IFDIR | S_IRWXU,
43897 +#else
43898 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43899 +#endif
43900 parent, NULL, NULL);
43901 }
43902 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43903 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43904 index ab35b11..b30af66 100644
43905 --- a/fs/ecryptfs/inode.c
43906 +++ b/fs/ecryptfs/inode.c
43907 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43908 old_fs = get_fs();
43909 set_fs(get_ds());
43910 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43911 - (char __user *)lower_buf,
43912 + (char __force_user *)lower_buf,
43913 lower_bufsiz);
43914 set_fs(old_fs);
43915 if (rc < 0)
43916 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43917 }
43918 old_fs = get_fs();
43919 set_fs(get_ds());
43920 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43921 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43922 set_fs(old_fs);
43923 if (rc < 0) {
43924 kfree(buf);
43925 @@ -733,7 +733,7 @@ out:
43926 static void
43927 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43928 {
43929 - char *buf = nd_get_link(nd);
43930 + const char *buf = nd_get_link(nd);
43931 if (!IS_ERR(buf)) {
43932 /* Free the char* */
43933 kfree(buf);
43934 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43935 index 3a06f40..f7af544 100644
43936 --- a/fs/ecryptfs/miscdev.c
43937 +++ b/fs/ecryptfs/miscdev.c
43938 @@ -345,7 +345,7 @@ check_list:
43939 goto out_unlock_msg_ctx;
43940 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43941 if (msg_ctx->msg) {
43942 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43943 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43944 goto out_unlock_msg_ctx;
43945 i += packet_length_size;
43946 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43947 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43948 index b2a34a1..162fa69 100644
43949 --- a/fs/ecryptfs/read_write.c
43950 +++ b/fs/ecryptfs/read_write.c
43951 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43952 return -EIO;
43953 fs_save = get_fs();
43954 set_fs(get_ds());
43955 - rc = vfs_write(lower_file, data, size, &offset);
43956 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43957 set_fs(fs_save);
43958 mark_inode_dirty_sync(ecryptfs_inode);
43959 return rc;
43960 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43961 return -EIO;
43962 fs_save = get_fs();
43963 set_fs(get_ds());
43964 - rc = vfs_read(lower_file, data, size, &offset);
43965 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43966 set_fs(fs_save);
43967 return rc;
43968 }
43969 diff --git a/fs/exec.c b/fs/exec.c
43970 index 153dee1..ab4ebe9 100644
43971 --- a/fs/exec.c
43972 +++ b/fs/exec.c
43973 @@ -55,6 +55,13 @@
43974 #include <linux/pipe_fs_i.h>
43975 #include <linux/oom.h>
43976 #include <linux/compat.h>
43977 +#include <linux/random.h>
43978 +#include <linux/seq_file.h>
43979 +
43980 +#ifdef CONFIG_PAX_REFCOUNT
43981 +#include <linux/kallsyms.h>
43982 +#include <linux/kdebug.h>
43983 +#endif
43984
43985 #include <asm/uaccess.h>
43986 #include <asm/mmu_context.h>
43987 @@ -63,6 +70,15 @@
43988 #include <trace/events/task.h>
43989 #include "internal.h"
43990
43991 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43992 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43993 +#endif
43994 +
43995 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43996 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43997 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43998 +#endif
43999 +
44000 int core_uses_pid;
44001 char core_pattern[CORENAME_MAX_SIZE] = "core";
44002 unsigned int core_pipe_limit;
44003 @@ -72,7 +88,7 @@ struct core_name {
44004 char *corename;
44005 int used, size;
44006 };
44007 -static atomic_t call_count = ATOMIC_INIT(1);
44008 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44009
44010 /* The maximal length of core_pattern is also specified in sysctl.c */
44011
44012 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44013 int write)
44014 {
44015 struct page *page;
44016 - int ret;
44017
44018 -#ifdef CONFIG_STACK_GROWSUP
44019 - if (write) {
44020 - ret = expand_downwards(bprm->vma, pos);
44021 - if (ret < 0)
44022 - return NULL;
44023 - }
44024 -#endif
44025 - ret = get_user_pages(current, bprm->mm, pos,
44026 - 1, write, 1, &page, NULL);
44027 - if (ret <= 0)
44028 + if (0 > expand_downwards(bprm->vma, pos))
44029 + return NULL;
44030 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44031 return NULL;
44032
44033 if (write) {
44034 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44035 if (size <= ARG_MAX)
44036 return page;
44037
44038 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44039 + // only allow 512KB for argv+env on suid/sgid binaries
44040 + // to prevent easy ASLR exhaustion
44041 + if (((bprm->cred->euid != current_euid()) ||
44042 + (bprm->cred->egid != current_egid())) &&
44043 + (size > (512 * 1024))) {
44044 + put_page(page);
44045 + return NULL;
44046 + }
44047 +#endif
44048 +
44049 /*
44050 * Limit to 1/4-th the stack size for the argv+env strings.
44051 * This ensures that:
44052 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44053 vma->vm_end = STACK_TOP_MAX;
44054 vma->vm_start = vma->vm_end - PAGE_SIZE;
44055 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44056 +
44057 +#ifdef CONFIG_PAX_SEGMEXEC
44058 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44059 +#endif
44060 +
44061 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44062 INIT_LIST_HEAD(&vma->anon_vma_chain);
44063
44064 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44065 mm->stack_vm = mm->total_vm = 1;
44066 up_write(&mm->mmap_sem);
44067 bprm->p = vma->vm_end - sizeof(void *);
44068 +
44069 +#ifdef CONFIG_PAX_RANDUSTACK
44070 + if (randomize_va_space)
44071 + bprm->p ^= random32() & ~PAGE_MASK;
44072 +#endif
44073 +
44074 return 0;
44075 err:
44076 up_write(&mm->mmap_sem);
44077 @@ -398,19 +428,7 @@ err:
44078 return err;
44079 }
44080
44081 -struct user_arg_ptr {
44082 -#ifdef CONFIG_COMPAT
44083 - bool is_compat;
44084 -#endif
44085 - union {
44086 - const char __user *const __user *native;
44087 -#ifdef CONFIG_COMPAT
44088 - compat_uptr_t __user *compat;
44089 -#endif
44090 - } ptr;
44091 -};
44092 -
44093 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44094 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44095 {
44096 const char __user *native;
44097
44098 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44099 compat_uptr_t compat;
44100
44101 if (get_user(compat, argv.ptr.compat + nr))
44102 - return ERR_PTR(-EFAULT);
44103 + return (const char __force_user *)ERR_PTR(-EFAULT);
44104
44105 return compat_ptr(compat);
44106 }
44107 #endif
44108
44109 if (get_user(native, argv.ptr.native + nr))
44110 - return ERR_PTR(-EFAULT);
44111 + return (const char __force_user *)ERR_PTR(-EFAULT);
44112
44113 return native;
44114 }
44115 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44116 if (!p)
44117 break;
44118
44119 - if (IS_ERR(p))
44120 + if (IS_ERR((const char __force_kernel *)p))
44121 return -EFAULT;
44122
44123 if (i++ >= max)
44124 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44125
44126 ret = -EFAULT;
44127 str = get_user_arg_ptr(argv, argc);
44128 - if (IS_ERR(str))
44129 + if (IS_ERR((const char __force_kernel *)str))
44130 goto out;
44131
44132 len = strnlen_user(str, MAX_ARG_STRLEN);
44133 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44134 int r;
44135 mm_segment_t oldfs = get_fs();
44136 struct user_arg_ptr argv = {
44137 - .ptr.native = (const char __user *const __user *)__argv,
44138 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44139 };
44140
44141 set_fs(KERNEL_DS);
44142 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44143 unsigned long new_end = old_end - shift;
44144 struct mmu_gather tlb;
44145
44146 - BUG_ON(new_start > new_end);
44147 + if (new_start >= new_end || new_start < mmap_min_addr)
44148 + return -ENOMEM;
44149
44150 /*
44151 * ensure there are no vmas between where we want to go
44152 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44153 if (vma != find_vma(mm, new_start))
44154 return -EFAULT;
44155
44156 +#ifdef CONFIG_PAX_SEGMEXEC
44157 + BUG_ON(pax_find_mirror_vma(vma));
44158 +#endif
44159 +
44160 /*
44161 * cover the whole range: [new_start, old_end)
44162 */
44163 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44164 stack_top = arch_align_stack(stack_top);
44165 stack_top = PAGE_ALIGN(stack_top);
44166
44167 - if (unlikely(stack_top < mmap_min_addr) ||
44168 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44169 - return -ENOMEM;
44170 -
44171 stack_shift = vma->vm_end - stack_top;
44172
44173 bprm->p -= stack_shift;
44174 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44175 bprm->exec -= stack_shift;
44176
44177 down_write(&mm->mmap_sem);
44178 +
44179 + /* Move stack pages down in memory. */
44180 + if (stack_shift) {
44181 + ret = shift_arg_pages(vma, stack_shift);
44182 + if (ret)
44183 + goto out_unlock;
44184 + }
44185 +
44186 vm_flags = VM_STACK_FLAGS;
44187
44188 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44189 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44190 + vm_flags &= ~VM_EXEC;
44191 +
44192 +#ifdef CONFIG_PAX_MPROTECT
44193 + if (mm->pax_flags & MF_PAX_MPROTECT)
44194 + vm_flags &= ~VM_MAYEXEC;
44195 +#endif
44196 +
44197 + }
44198 +#endif
44199 +
44200 /*
44201 * Adjust stack execute permissions; explicitly enable for
44202 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44203 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44204 goto out_unlock;
44205 BUG_ON(prev != vma);
44206
44207 - /* Move stack pages down in memory. */
44208 - if (stack_shift) {
44209 - ret = shift_arg_pages(vma, stack_shift);
44210 - if (ret)
44211 - goto out_unlock;
44212 - }
44213 -
44214 /* mprotect_fixup is overkill to remove the temporary stack flags */
44215 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44216
44217 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44218 old_fs = get_fs();
44219 set_fs(get_ds());
44220 /* The cast to a user pointer is valid due to the set_fs() */
44221 - result = vfs_read(file, (void __user *)addr, count, &pos);
44222 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44223 set_fs(old_fs);
44224 return result;
44225 }
44226 @@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44227 }
44228 rcu_read_unlock();
44229
44230 - if (p->fs->users > n_fs) {
44231 + if (atomic_read(&p->fs->users) > n_fs) {
44232 bprm->unsafe |= LSM_UNSAFE_SHARE;
44233 } else {
44234 res = -EAGAIN;
44235 @@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44236
44237 EXPORT_SYMBOL(search_binary_handler);
44238
44239 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44240 +static DEFINE_PER_CPU(u64, exec_counter);
44241 +static int __init init_exec_counters(void)
44242 +{
44243 + unsigned int cpu;
44244 +
44245 + for_each_possible_cpu(cpu) {
44246 + per_cpu(exec_counter, cpu) = (u64)cpu;
44247 + }
44248 +
44249 + return 0;
44250 +}
44251 +early_initcall(init_exec_counters);
44252 +static inline void increment_exec_counter(void)
44253 +{
44254 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44255 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44256 +}
44257 +#else
44258 +static inline void increment_exec_counter(void) {}
44259 +#endif
44260 +
44261 /*
44262 * sys_execve() executes a new program.
44263 */
44264 @@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
44265 struct user_arg_ptr envp,
44266 struct pt_regs *regs)
44267 {
44268 +#ifdef CONFIG_GRKERNSEC
44269 + struct file *old_exec_file;
44270 + struct acl_subject_label *old_acl;
44271 + struct rlimit old_rlim[RLIM_NLIMITS];
44272 +#endif
44273 struct linux_binprm *bprm;
44274 struct file *file;
44275 struct files_struct *displaced;
44276 @@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
44277 int retval;
44278 const struct cred *cred = current_cred();
44279
44280 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44281 +
44282 /*
44283 * We move the actual failure in case of RLIMIT_NPROC excess from
44284 * set*uid() to execve() because too many poorly written programs
44285 @@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
44286 if (IS_ERR(file))
44287 goto out_unmark;
44288
44289 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44290 + retval = -EPERM;
44291 + goto out_file;
44292 + }
44293 +
44294 sched_exec();
44295
44296 bprm->file = file;
44297 bprm->filename = filename;
44298 bprm->interp = filename;
44299
44300 + if (gr_process_user_ban()) {
44301 + retval = -EPERM;
44302 + goto out_file;
44303 + }
44304 +
44305 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44306 + retval = -EACCES;
44307 + goto out_file;
44308 + }
44309 +
44310 retval = bprm_mm_init(bprm);
44311 if (retval)
44312 goto out_file;
44313 @@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
44314 if (retval < 0)
44315 goto out;
44316
44317 +#ifdef CONFIG_GRKERNSEC
44318 + old_acl = current->acl;
44319 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44320 + old_exec_file = current->exec_file;
44321 + get_file(file);
44322 + current->exec_file = file;
44323 +#endif
44324 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44325 + /* limit suid stack to 8MB
44326 + we saved the old limits above and will restore them if this exec fails
44327 + */
44328 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44329 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44330 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44331 +#endif
44332 +
44333 + if (!gr_tpe_allow(file)) {
44334 + retval = -EACCES;
44335 + goto out_fail;
44336 + }
44337 +
44338 + if (gr_check_crash_exec(file)) {
44339 + retval = -EACCES;
44340 + goto out_fail;
44341 + }
44342 +
44343 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44344 + bprm->unsafe);
44345 + if (retval < 0)
44346 + goto out_fail;
44347 +
44348 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44349 if (retval < 0)
44350 - goto out;
44351 + goto out_fail;
44352
44353 bprm->exec = bprm->p;
44354 retval = copy_strings(bprm->envc, envp, bprm);
44355 if (retval < 0)
44356 - goto out;
44357 + goto out_fail;
44358
44359 retval = copy_strings(bprm->argc, argv, bprm);
44360 if (retval < 0)
44361 - goto out;
44362 + goto out_fail;
44363 +
44364 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44365 +
44366 + gr_handle_exec_args(bprm, argv);
44367
44368 retval = search_binary_handler(bprm,regs);
44369 if (retval < 0)
44370 - goto out;
44371 + goto out_fail;
44372 +#ifdef CONFIG_GRKERNSEC
44373 + if (old_exec_file)
44374 + fput(old_exec_file);
44375 +#endif
44376
44377 /* execve succeeded */
44378 +
44379 + increment_exec_counter();
44380 current->fs->in_exec = 0;
44381 current->in_execve = 0;
44382 acct_update_integrals(current);
44383 @@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
44384 put_files_struct(displaced);
44385 return retval;
44386
44387 +out_fail:
44388 +#ifdef CONFIG_GRKERNSEC
44389 + current->acl = old_acl;
44390 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44391 + fput(current->exec_file);
44392 + current->exec_file = old_exec_file;
44393 +#endif
44394 +
44395 out:
44396 if (bprm->mm) {
44397 acct_arg_size(bprm, 0);
44398 @@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
44399 {
44400 char *old_corename = cn->corename;
44401
44402 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44403 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44404 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44405
44406 if (!cn->corename) {
44407 @@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
44408 int pid_in_pattern = 0;
44409 int err = 0;
44410
44411 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44412 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44413 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44414 cn->used = 0;
44415
44416 @@ -1817,6 +1942,228 @@ out:
44417 return ispipe;
44418 }
44419
44420 +int pax_check_flags(unsigned long *flags)
44421 +{
44422 + int retval = 0;
44423 +
44424 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44425 + if (*flags & MF_PAX_SEGMEXEC)
44426 + {
44427 + *flags &= ~MF_PAX_SEGMEXEC;
44428 + retval = -EINVAL;
44429 + }
44430 +#endif
44431 +
44432 + if ((*flags & MF_PAX_PAGEEXEC)
44433 +
44434 +#ifdef CONFIG_PAX_PAGEEXEC
44435 + && (*flags & MF_PAX_SEGMEXEC)
44436 +#endif
44437 +
44438 + )
44439 + {
44440 + *flags &= ~MF_PAX_PAGEEXEC;
44441 + retval = -EINVAL;
44442 + }
44443 +
44444 + if ((*flags & MF_PAX_MPROTECT)
44445 +
44446 +#ifdef CONFIG_PAX_MPROTECT
44447 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44448 +#endif
44449 +
44450 + )
44451 + {
44452 + *flags &= ~MF_PAX_MPROTECT;
44453 + retval = -EINVAL;
44454 + }
44455 +
44456 + if ((*flags & MF_PAX_EMUTRAMP)
44457 +
44458 +#ifdef CONFIG_PAX_EMUTRAMP
44459 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44460 +#endif
44461 +
44462 + )
44463 + {
44464 + *flags &= ~MF_PAX_EMUTRAMP;
44465 + retval = -EINVAL;
44466 + }
44467 +
44468 + return retval;
44469 +}
44470 +
44471 +EXPORT_SYMBOL(pax_check_flags);
44472 +
44473 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44474 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44475 +{
44476 + struct task_struct *tsk = current;
44477 + struct mm_struct *mm = current->mm;
44478 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44479 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44480 + char *path_exec = NULL;
44481 + char *path_fault = NULL;
44482 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44483 +
44484 + if (buffer_exec && buffer_fault) {
44485 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44486 +
44487 + down_read(&mm->mmap_sem);
44488 + vma = mm->mmap;
44489 + while (vma && (!vma_exec || !vma_fault)) {
44490 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44491 + vma_exec = vma;
44492 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44493 + vma_fault = vma;
44494 + vma = vma->vm_next;
44495 + }
44496 + if (vma_exec) {
44497 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44498 + if (IS_ERR(path_exec))
44499 + path_exec = "<path too long>";
44500 + else {
44501 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44502 + if (path_exec) {
44503 + *path_exec = 0;
44504 + path_exec = buffer_exec;
44505 + } else
44506 + path_exec = "<path too long>";
44507 + }
44508 + }
44509 + if (vma_fault) {
44510 + start = vma_fault->vm_start;
44511 + end = vma_fault->vm_end;
44512 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44513 + if (vma_fault->vm_file) {
44514 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44515 + if (IS_ERR(path_fault))
44516 + path_fault = "<path too long>";
44517 + else {
44518 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44519 + if (path_fault) {
44520 + *path_fault = 0;
44521 + path_fault = buffer_fault;
44522 + } else
44523 + path_fault = "<path too long>";
44524 + }
44525 + } else
44526 + path_fault = "<anonymous mapping>";
44527 + }
44528 + up_read(&mm->mmap_sem);
44529 + }
44530 + if (tsk->signal->curr_ip)
44531 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44532 + else
44533 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44534 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44535 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44536 + task_uid(tsk), task_euid(tsk), pc, sp);
44537 + free_page((unsigned long)buffer_exec);
44538 + free_page((unsigned long)buffer_fault);
44539 + pax_report_insns(regs, pc, sp);
44540 + do_coredump(SIGKILL, SIGKILL, regs);
44541 +}
44542 +#endif
44543 +
44544 +#ifdef CONFIG_PAX_REFCOUNT
44545 +void pax_report_refcount_overflow(struct pt_regs *regs)
44546 +{
44547 + if (current->signal->curr_ip)
44548 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44549 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44550 + else
44551 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44552 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44553 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44554 + show_regs(regs);
44555 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44556 +}
44557 +#endif
44558 +
44559 +#ifdef CONFIG_PAX_USERCOPY
44560 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44561 +int object_is_on_stack(const void *obj, unsigned long len)
44562 +{
44563 + const void * const stack = task_stack_page(current);
44564 + const void * const stackend = stack + THREAD_SIZE;
44565 +
44566 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44567 + const void *frame = NULL;
44568 + const void *oldframe;
44569 +#endif
44570 +
44571 + if (obj + len < obj)
44572 + return -1;
44573 +
44574 + if (obj + len <= stack || stackend <= obj)
44575 + return 0;
44576 +
44577 + if (obj < stack || stackend < obj + len)
44578 + return -1;
44579 +
44580 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44581 + oldframe = __builtin_frame_address(1);
44582 + if (oldframe)
44583 + frame = __builtin_frame_address(2);
44584 + /*
44585 + low ----------------------------------------------> high
44586 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44587 + ^----------------^
44588 + allow copies only within here
44589 + */
44590 + while (stack <= frame && frame < stackend) {
44591 + /* if obj + len extends past the last frame, this
44592 + check won't pass and the next frame will be 0,
44593 + causing us to bail out and correctly report
44594 + the copy as invalid
44595 + */
44596 + if (obj + len <= frame)
44597 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44598 + oldframe = frame;
44599 + frame = *(const void * const *)frame;
44600 + }
44601 + return -1;
44602 +#else
44603 + return 1;
44604 +#endif
44605 +}
44606 +
44607 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44608 +{
44609 + if (current->signal->curr_ip)
44610 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44611 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44612 + else
44613 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44614 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44615 + dump_stack();
44616 + gr_handle_kernel_exploit();
44617 + do_group_exit(SIGKILL);
44618 +}
44619 +#endif
44620 +
44621 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44622 +void pax_track_stack(void)
44623 +{
44624 + unsigned long sp = (unsigned long)&sp;
44625 + if (sp < current_thread_info()->lowest_stack &&
44626 + sp > (unsigned long)task_stack_page(current))
44627 + current_thread_info()->lowest_stack = sp;
44628 +}
44629 +EXPORT_SYMBOL(pax_track_stack);
44630 +#endif
44631 +
44632 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44633 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44634 +{
44635 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44636 + dump_stack();
44637 + do_group_exit(SIGKILL);
44638 +}
44639 +EXPORT_SYMBOL(report_size_overflow);
44640 +#endif
44641 +
44642 static int zap_process(struct task_struct *start, int exit_code)
44643 {
44644 struct task_struct *t;
44645 @@ -2014,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
44646 pipe = file->f_path.dentry->d_inode->i_pipe;
44647
44648 pipe_lock(pipe);
44649 - pipe->readers++;
44650 - pipe->writers--;
44651 + atomic_inc(&pipe->readers);
44652 + atomic_dec(&pipe->writers);
44653
44654 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44655 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44656 wake_up_interruptible_sync(&pipe->wait);
44657 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44658 pipe_wait(pipe);
44659 }
44660
44661 - pipe->readers--;
44662 - pipe->writers++;
44663 + atomic_dec(&pipe->readers);
44664 + atomic_inc(&pipe->writers);
44665 pipe_unlock(pipe);
44666
44667 }
44668 @@ -2085,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44669 int retval = 0;
44670 int flag = 0;
44671 int ispipe;
44672 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44673 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44674 struct coredump_params cprm = {
44675 .signr = signr,
44676 .regs = regs,
44677 @@ -2100,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44678
44679 audit_core_dumps(signr);
44680
44681 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44682 + gr_handle_brute_attach(current, cprm.mm_flags);
44683 +
44684 binfmt = mm->binfmt;
44685 if (!binfmt || !binfmt->core_dump)
44686 goto fail;
44687 @@ -2167,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44688 }
44689 cprm.limit = RLIM_INFINITY;
44690
44691 - dump_count = atomic_inc_return(&core_dump_count);
44692 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44693 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44694 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44695 task_tgid_vnr(current), current->comm);
44696 @@ -2194,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44697 } else {
44698 struct inode *inode;
44699
44700 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44701 +
44702 if (cprm.limit < binfmt->min_coredump)
44703 goto fail_unlock;
44704
44705 @@ -2237,7 +2589,7 @@ close_fail:
44706 filp_close(cprm.file, NULL);
44707 fail_dropcount:
44708 if (ispipe)
44709 - atomic_dec(&core_dump_count);
44710 + atomic_dec_unchecked(&core_dump_count);
44711 fail_unlock:
44712 kfree(cn.corename);
44713 fail_corename:
44714 @@ -2256,7 +2608,7 @@ fail:
44715 */
44716 int dump_write(struct file *file, const void *addr, int nr)
44717 {
44718 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44719 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44720 }
44721 EXPORT_SYMBOL(dump_write);
44722
44723 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44724 index a8cbe1b..fed04cb 100644
44725 --- a/fs/ext2/balloc.c
44726 +++ b/fs/ext2/balloc.c
44727 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44728
44729 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44730 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44731 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44732 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44733 sbi->s_resuid != current_fsuid() &&
44734 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44735 return 0;
44736 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44737 index a203892..4e64db5 100644
44738 --- a/fs/ext3/balloc.c
44739 +++ b/fs/ext3/balloc.c
44740 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44741
44742 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44743 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44744 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44745 + if (free_blocks < root_blocks + 1 &&
44746 !use_reservation && sbi->s_resuid != current_fsuid() &&
44747 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44748 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44749 + !capable_nolog(CAP_SYS_RESOURCE)) {
44750 return 0;
44751 }
44752 return 1;
44753 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44754 index f9e2cd8..bfdc476 100644
44755 --- a/fs/ext4/balloc.c
44756 +++ b/fs/ext4/balloc.c
44757 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44758 /* Hm, nope. Are (enough) root reserved clusters available? */
44759 if (sbi->s_resuid == current_fsuid() ||
44760 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44761 - capable(CAP_SYS_RESOURCE) ||
44762 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44763 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44764 + capable_nolog(CAP_SYS_RESOURCE)) {
44765
44766 if (free_clusters >= (nclusters + dirty_clusters))
44767 return 1;
44768 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44769 index 3ce6a0c..0311fe5 100644
44770 --- a/fs/ext4/ext4.h
44771 +++ b/fs/ext4/ext4.h
44772 @@ -1220,19 +1220,19 @@ struct ext4_sb_info {
44773 unsigned long s_mb_last_start;
44774
44775 /* stats for buddy allocator */
44776 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44777 - atomic_t s_bal_success; /* we found long enough chunks */
44778 - atomic_t s_bal_allocated; /* in blocks */
44779 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44780 - atomic_t s_bal_goals; /* goal hits */
44781 - atomic_t s_bal_breaks; /* too long searches */
44782 - atomic_t s_bal_2orders; /* 2^order hits */
44783 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44784 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44785 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44786 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44787 + atomic_unchecked_t s_bal_goals; /* goal hits */
44788 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44789 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44790 spinlock_t s_bal_lock;
44791 unsigned long s_mb_buddies_generated;
44792 unsigned long long s_mb_generation_time;
44793 - atomic_t s_mb_lost_chunks;
44794 - atomic_t s_mb_preallocated;
44795 - atomic_t s_mb_discarded;
44796 + atomic_unchecked_t s_mb_lost_chunks;
44797 + atomic_unchecked_t s_mb_preallocated;
44798 + atomic_unchecked_t s_mb_discarded;
44799 atomic_t s_lock_busy;
44800
44801 /* locality groups */
44802 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44803 index cb990b2..4820141 100644
44804 --- a/fs/ext4/mballoc.c
44805 +++ b/fs/ext4/mballoc.c
44806 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44807 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44808
44809 if (EXT4_SB(sb)->s_mb_stats)
44810 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44811 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44812
44813 break;
44814 }
44815 @@ -2088,7 +2088,7 @@ repeat:
44816 ac->ac_status = AC_STATUS_CONTINUE;
44817 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44818 cr = 3;
44819 - atomic_inc(&sbi->s_mb_lost_chunks);
44820 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44821 goto repeat;
44822 }
44823 }
44824 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44825 if (sbi->s_mb_stats) {
44826 ext4_msg(sb, KERN_INFO,
44827 "mballoc: %u blocks %u reqs (%u success)",
44828 - atomic_read(&sbi->s_bal_allocated),
44829 - atomic_read(&sbi->s_bal_reqs),
44830 - atomic_read(&sbi->s_bal_success));
44831 + atomic_read_unchecked(&sbi->s_bal_allocated),
44832 + atomic_read_unchecked(&sbi->s_bal_reqs),
44833 + atomic_read_unchecked(&sbi->s_bal_success));
44834 ext4_msg(sb, KERN_INFO,
44835 "mballoc: %u extents scanned, %u goal hits, "
44836 "%u 2^N hits, %u breaks, %u lost",
44837 - atomic_read(&sbi->s_bal_ex_scanned),
44838 - atomic_read(&sbi->s_bal_goals),
44839 - atomic_read(&sbi->s_bal_2orders),
44840 - atomic_read(&sbi->s_bal_breaks),
44841 - atomic_read(&sbi->s_mb_lost_chunks));
44842 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44843 + atomic_read_unchecked(&sbi->s_bal_goals),
44844 + atomic_read_unchecked(&sbi->s_bal_2orders),
44845 + atomic_read_unchecked(&sbi->s_bal_breaks),
44846 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44847 ext4_msg(sb, KERN_INFO,
44848 "mballoc: %lu generated and it took %Lu",
44849 sbi->s_mb_buddies_generated,
44850 sbi->s_mb_generation_time);
44851 ext4_msg(sb, KERN_INFO,
44852 "mballoc: %u preallocated, %u discarded",
44853 - atomic_read(&sbi->s_mb_preallocated),
44854 - atomic_read(&sbi->s_mb_discarded));
44855 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44856 + atomic_read_unchecked(&sbi->s_mb_discarded));
44857 }
44858
44859 free_percpu(sbi->s_locality_groups);
44860 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44861 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44862
44863 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44864 - atomic_inc(&sbi->s_bal_reqs);
44865 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44866 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44867 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44868 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44869 - atomic_inc(&sbi->s_bal_success);
44870 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44871 + atomic_inc_unchecked(&sbi->s_bal_success);
44872 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44873 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44874 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44875 - atomic_inc(&sbi->s_bal_goals);
44876 + atomic_inc_unchecked(&sbi->s_bal_goals);
44877 if (ac->ac_found > sbi->s_mb_max_to_scan)
44878 - atomic_inc(&sbi->s_bal_breaks);
44879 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44880 }
44881
44882 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44883 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44884 trace_ext4_mb_new_inode_pa(ac, pa);
44885
44886 ext4_mb_use_inode_pa(ac, pa);
44887 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44888 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44889
44890 ei = EXT4_I(ac->ac_inode);
44891 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44892 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44893 trace_ext4_mb_new_group_pa(ac, pa);
44894
44895 ext4_mb_use_group_pa(ac, pa);
44896 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44897 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44898
44899 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44900 lg = ac->ac_lg;
44901 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44902 * from the bitmap and continue.
44903 */
44904 }
44905 - atomic_add(free, &sbi->s_mb_discarded);
44906 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44907
44908 return err;
44909 }
44910 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44911 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44912 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44913 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44914 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44915 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44916 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44917
44918 return 0;
44919 diff --git a/fs/fcntl.c b/fs/fcntl.c
44920 index 22764c7..86372c9 100644
44921 --- a/fs/fcntl.c
44922 +++ b/fs/fcntl.c
44923 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44924 if (err)
44925 return err;
44926
44927 + if (gr_handle_chroot_fowner(pid, type))
44928 + return -ENOENT;
44929 + if (gr_check_protected_task_fowner(pid, type))
44930 + return -EACCES;
44931 +
44932 f_modown(filp, pid, type, force);
44933 return 0;
44934 }
44935 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44936
44937 static int f_setown_ex(struct file *filp, unsigned long arg)
44938 {
44939 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44940 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44941 struct f_owner_ex owner;
44942 struct pid *pid;
44943 int type;
44944 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44945
44946 static int f_getown_ex(struct file *filp, unsigned long arg)
44947 {
44948 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44949 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44950 struct f_owner_ex owner;
44951 int ret = 0;
44952
44953 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44954 switch (cmd) {
44955 case F_DUPFD:
44956 case F_DUPFD_CLOEXEC:
44957 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44958 if (arg >= rlimit(RLIMIT_NOFILE))
44959 break;
44960 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44961 diff --git a/fs/fifo.c b/fs/fifo.c
44962 index b1a524d..4ee270e 100644
44963 --- a/fs/fifo.c
44964 +++ b/fs/fifo.c
44965 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44966 */
44967 filp->f_op = &read_pipefifo_fops;
44968 pipe->r_counter++;
44969 - if (pipe->readers++ == 0)
44970 + if (atomic_inc_return(&pipe->readers) == 1)
44971 wake_up_partner(inode);
44972
44973 - if (!pipe->writers) {
44974 + if (!atomic_read(&pipe->writers)) {
44975 if ((filp->f_flags & O_NONBLOCK)) {
44976 /* suppress POLLHUP until we have
44977 * seen a writer */
44978 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44979 * errno=ENXIO when there is no process reading the FIFO.
44980 */
44981 ret = -ENXIO;
44982 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44983 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44984 goto err;
44985
44986 filp->f_op = &write_pipefifo_fops;
44987 pipe->w_counter++;
44988 - if (!pipe->writers++)
44989 + if (atomic_inc_return(&pipe->writers) == 1)
44990 wake_up_partner(inode);
44991
44992 - if (!pipe->readers) {
44993 + if (!atomic_read(&pipe->readers)) {
44994 wait_for_partner(inode, &pipe->r_counter);
44995 if (signal_pending(current))
44996 goto err_wr;
44997 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44998 */
44999 filp->f_op = &rdwr_pipefifo_fops;
45000
45001 - pipe->readers++;
45002 - pipe->writers++;
45003 + atomic_inc(&pipe->readers);
45004 + atomic_inc(&pipe->writers);
45005 pipe->r_counter++;
45006 pipe->w_counter++;
45007 - if (pipe->readers == 1 || pipe->writers == 1)
45008 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45009 wake_up_partner(inode);
45010 break;
45011
45012 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45013 return 0;
45014
45015 err_rd:
45016 - if (!--pipe->readers)
45017 + if (atomic_dec_and_test(&pipe->readers))
45018 wake_up_interruptible(&pipe->wait);
45019 ret = -ERESTARTSYS;
45020 goto err;
45021
45022 err_wr:
45023 - if (!--pipe->writers)
45024 + if (atomic_dec_and_test(&pipe->writers))
45025 wake_up_interruptible(&pipe->wait);
45026 ret = -ERESTARTSYS;
45027 goto err;
45028
45029 err:
45030 - if (!pipe->readers && !pipe->writers)
45031 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45032 free_pipe_info(inode);
45033
45034 err_nocleanup:
45035 diff --git a/fs/file.c b/fs/file.c
45036 index 4c6992d..104cdea 100644
45037 --- a/fs/file.c
45038 +++ b/fs/file.c
45039 @@ -15,6 +15,7 @@
45040 #include <linux/slab.h>
45041 #include <linux/vmalloc.h>
45042 #include <linux/file.h>
45043 +#include <linux/security.h>
45044 #include <linux/fdtable.h>
45045 #include <linux/bitops.h>
45046 #include <linux/interrupt.h>
45047 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45048 * N.B. For clone tasks sharing a files structure, this test
45049 * will limit the total number of files that can be opened.
45050 */
45051 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45052 if (nr >= rlimit(RLIMIT_NOFILE))
45053 return -EMFILE;
45054
45055 diff --git a/fs/filesystems.c b/fs/filesystems.c
45056 index 96f2428..f5eeb8e 100644
45057 --- a/fs/filesystems.c
45058 +++ b/fs/filesystems.c
45059 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45060 int len = dot ? dot - name : strlen(name);
45061
45062 fs = __get_fs_type(name, len);
45063 +
45064 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45065 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45066 +#else
45067 if (!fs && (request_module("%.*s", len, name) == 0))
45068 +#endif
45069 fs = __get_fs_type(name, len);
45070
45071 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45072 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45073 index 78b519c..a8b4979 100644
45074 --- a/fs/fs_struct.c
45075 +++ b/fs/fs_struct.c
45076 @@ -4,6 +4,7 @@
45077 #include <linux/path.h>
45078 #include <linux/slab.h>
45079 #include <linux/fs_struct.h>
45080 +#include <linux/grsecurity.h>
45081 #include "internal.h"
45082
45083 static inline void path_get_longterm(struct path *path)
45084 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45085 old_root = fs->root;
45086 fs->root = *path;
45087 path_get_longterm(path);
45088 + gr_set_chroot_entries(current, path);
45089 write_seqcount_end(&fs->seq);
45090 spin_unlock(&fs->lock);
45091 if (old_root.dentry)
45092 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45093 && fs->root.mnt == old_root->mnt) {
45094 path_get_longterm(new_root);
45095 fs->root = *new_root;
45096 + gr_set_chroot_entries(p, new_root);
45097 count++;
45098 }
45099 if (fs->pwd.dentry == old_root->dentry
45100 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45101 spin_lock(&fs->lock);
45102 write_seqcount_begin(&fs->seq);
45103 tsk->fs = NULL;
45104 - kill = !--fs->users;
45105 + gr_clear_chroot_entries(tsk);
45106 + kill = !atomic_dec_return(&fs->users);
45107 write_seqcount_end(&fs->seq);
45108 spin_unlock(&fs->lock);
45109 task_unlock(tsk);
45110 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45111 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45112 /* We don't need to lock fs - think why ;-) */
45113 if (fs) {
45114 - fs->users = 1;
45115 + atomic_set(&fs->users, 1);
45116 fs->in_exec = 0;
45117 spin_lock_init(&fs->lock);
45118 seqcount_init(&fs->seq);
45119 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45120 spin_lock(&old->lock);
45121 fs->root = old->root;
45122 path_get_longterm(&fs->root);
45123 + /* instead of calling gr_set_chroot_entries here,
45124 + we call it from every caller of this function
45125 + */
45126 fs->pwd = old->pwd;
45127 path_get_longterm(&fs->pwd);
45128 spin_unlock(&old->lock);
45129 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45130
45131 task_lock(current);
45132 spin_lock(&fs->lock);
45133 - kill = !--fs->users;
45134 + kill = !atomic_dec_return(&fs->users);
45135 current->fs = new_fs;
45136 + gr_set_chroot_entries(current, &new_fs->root);
45137 spin_unlock(&fs->lock);
45138 task_unlock(current);
45139
45140 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45141
45142 int current_umask(void)
45143 {
45144 - return current->fs->umask;
45145 + return current->fs->umask | gr_acl_umask();
45146 }
45147 EXPORT_SYMBOL(current_umask);
45148
45149 /* to be mentioned only in INIT_TASK */
45150 struct fs_struct init_fs = {
45151 - .users = 1,
45152 + .users = ATOMIC_INIT(1),
45153 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45154 .seq = SEQCNT_ZERO,
45155 .umask = 0022,
45156 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45157 task_lock(current);
45158
45159 spin_lock(&init_fs.lock);
45160 - init_fs.users++;
45161 + atomic_inc(&init_fs.users);
45162 spin_unlock(&init_fs.lock);
45163
45164 spin_lock(&fs->lock);
45165 current->fs = &init_fs;
45166 - kill = !--fs->users;
45167 + gr_set_chroot_entries(current, &current->fs->root);
45168 + kill = !atomic_dec_return(&fs->users);
45169 spin_unlock(&fs->lock);
45170
45171 task_unlock(current);
45172 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45173 index 9905350..02eaec4 100644
45174 --- a/fs/fscache/cookie.c
45175 +++ b/fs/fscache/cookie.c
45176 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45177 parent ? (char *) parent->def->name : "<no-parent>",
45178 def->name, netfs_data);
45179
45180 - fscache_stat(&fscache_n_acquires);
45181 + fscache_stat_unchecked(&fscache_n_acquires);
45182
45183 /* if there's no parent cookie, then we don't create one here either */
45184 if (!parent) {
45185 - fscache_stat(&fscache_n_acquires_null);
45186 + fscache_stat_unchecked(&fscache_n_acquires_null);
45187 _leave(" [no parent]");
45188 return NULL;
45189 }
45190 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45191 /* allocate and initialise a cookie */
45192 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45193 if (!cookie) {
45194 - fscache_stat(&fscache_n_acquires_oom);
45195 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45196 _leave(" [ENOMEM]");
45197 return NULL;
45198 }
45199 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45200
45201 switch (cookie->def->type) {
45202 case FSCACHE_COOKIE_TYPE_INDEX:
45203 - fscache_stat(&fscache_n_cookie_index);
45204 + fscache_stat_unchecked(&fscache_n_cookie_index);
45205 break;
45206 case FSCACHE_COOKIE_TYPE_DATAFILE:
45207 - fscache_stat(&fscache_n_cookie_data);
45208 + fscache_stat_unchecked(&fscache_n_cookie_data);
45209 break;
45210 default:
45211 - fscache_stat(&fscache_n_cookie_special);
45212 + fscache_stat_unchecked(&fscache_n_cookie_special);
45213 break;
45214 }
45215
45216 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45217 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45218 atomic_dec(&parent->n_children);
45219 __fscache_cookie_put(cookie);
45220 - fscache_stat(&fscache_n_acquires_nobufs);
45221 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45222 _leave(" = NULL");
45223 return NULL;
45224 }
45225 }
45226
45227 - fscache_stat(&fscache_n_acquires_ok);
45228 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45229 _leave(" = %p", cookie);
45230 return cookie;
45231 }
45232 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45233 cache = fscache_select_cache_for_object(cookie->parent);
45234 if (!cache) {
45235 up_read(&fscache_addremove_sem);
45236 - fscache_stat(&fscache_n_acquires_no_cache);
45237 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45238 _leave(" = -ENOMEDIUM [no cache]");
45239 return -ENOMEDIUM;
45240 }
45241 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45242 object = cache->ops->alloc_object(cache, cookie);
45243 fscache_stat_d(&fscache_n_cop_alloc_object);
45244 if (IS_ERR(object)) {
45245 - fscache_stat(&fscache_n_object_no_alloc);
45246 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45247 ret = PTR_ERR(object);
45248 goto error;
45249 }
45250
45251 - fscache_stat(&fscache_n_object_alloc);
45252 + fscache_stat_unchecked(&fscache_n_object_alloc);
45253
45254 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45255
45256 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45257 struct fscache_object *object;
45258 struct hlist_node *_p;
45259
45260 - fscache_stat(&fscache_n_updates);
45261 + fscache_stat_unchecked(&fscache_n_updates);
45262
45263 if (!cookie) {
45264 - fscache_stat(&fscache_n_updates_null);
45265 + fscache_stat_unchecked(&fscache_n_updates_null);
45266 _leave(" [no cookie]");
45267 return;
45268 }
45269 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45270 struct fscache_object *object;
45271 unsigned long event;
45272
45273 - fscache_stat(&fscache_n_relinquishes);
45274 + fscache_stat_unchecked(&fscache_n_relinquishes);
45275 if (retire)
45276 - fscache_stat(&fscache_n_relinquishes_retire);
45277 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45278
45279 if (!cookie) {
45280 - fscache_stat(&fscache_n_relinquishes_null);
45281 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45282 _leave(" [no cookie]");
45283 return;
45284 }
45285 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45286
45287 /* wait for the cookie to finish being instantiated (or to fail) */
45288 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45289 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45290 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45291 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45292 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45293 }
45294 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45295 index f6aad48..88dcf26 100644
45296 --- a/fs/fscache/internal.h
45297 +++ b/fs/fscache/internal.h
45298 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45299 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45300 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45301
45302 -extern atomic_t fscache_n_op_pend;
45303 -extern atomic_t fscache_n_op_run;
45304 -extern atomic_t fscache_n_op_enqueue;
45305 -extern atomic_t fscache_n_op_deferred_release;
45306 -extern atomic_t fscache_n_op_release;
45307 -extern atomic_t fscache_n_op_gc;
45308 -extern atomic_t fscache_n_op_cancelled;
45309 -extern atomic_t fscache_n_op_rejected;
45310 +extern atomic_unchecked_t fscache_n_op_pend;
45311 +extern atomic_unchecked_t fscache_n_op_run;
45312 +extern atomic_unchecked_t fscache_n_op_enqueue;
45313 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45314 +extern atomic_unchecked_t fscache_n_op_release;
45315 +extern atomic_unchecked_t fscache_n_op_gc;
45316 +extern atomic_unchecked_t fscache_n_op_cancelled;
45317 +extern atomic_unchecked_t fscache_n_op_rejected;
45318
45319 -extern atomic_t fscache_n_attr_changed;
45320 -extern atomic_t fscache_n_attr_changed_ok;
45321 -extern atomic_t fscache_n_attr_changed_nobufs;
45322 -extern atomic_t fscache_n_attr_changed_nomem;
45323 -extern atomic_t fscache_n_attr_changed_calls;
45324 +extern atomic_unchecked_t fscache_n_attr_changed;
45325 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45326 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45327 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45328 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45329
45330 -extern atomic_t fscache_n_allocs;
45331 -extern atomic_t fscache_n_allocs_ok;
45332 -extern atomic_t fscache_n_allocs_wait;
45333 -extern atomic_t fscache_n_allocs_nobufs;
45334 -extern atomic_t fscache_n_allocs_intr;
45335 -extern atomic_t fscache_n_allocs_object_dead;
45336 -extern atomic_t fscache_n_alloc_ops;
45337 -extern atomic_t fscache_n_alloc_op_waits;
45338 +extern atomic_unchecked_t fscache_n_allocs;
45339 +extern atomic_unchecked_t fscache_n_allocs_ok;
45340 +extern atomic_unchecked_t fscache_n_allocs_wait;
45341 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45342 +extern atomic_unchecked_t fscache_n_allocs_intr;
45343 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45344 +extern atomic_unchecked_t fscache_n_alloc_ops;
45345 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45346
45347 -extern atomic_t fscache_n_retrievals;
45348 -extern atomic_t fscache_n_retrievals_ok;
45349 -extern atomic_t fscache_n_retrievals_wait;
45350 -extern atomic_t fscache_n_retrievals_nodata;
45351 -extern atomic_t fscache_n_retrievals_nobufs;
45352 -extern atomic_t fscache_n_retrievals_intr;
45353 -extern atomic_t fscache_n_retrievals_nomem;
45354 -extern atomic_t fscache_n_retrievals_object_dead;
45355 -extern atomic_t fscache_n_retrieval_ops;
45356 -extern atomic_t fscache_n_retrieval_op_waits;
45357 +extern atomic_unchecked_t fscache_n_retrievals;
45358 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45359 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45360 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45361 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45362 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45363 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45364 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45365 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45366 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45367
45368 -extern atomic_t fscache_n_stores;
45369 -extern atomic_t fscache_n_stores_ok;
45370 -extern atomic_t fscache_n_stores_again;
45371 -extern atomic_t fscache_n_stores_nobufs;
45372 -extern atomic_t fscache_n_stores_oom;
45373 -extern atomic_t fscache_n_store_ops;
45374 -extern atomic_t fscache_n_store_calls;
45375 -extern atomic_t fscache_n_store_pages;
45376 -extern atomic_t fscache_n_store_radix_deletes;
45377 -extern atomic_t fscache_n_store_pages_over_limit;
45378 +extern atomic_unchecked_t fscache_n_stores;
45379 +extern atomic_unchecked_t fscache_n_stores_ok;
45380 +extern atomic_unchecked_t fscache_n_stores_again;
45381 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45382 +extern atomic_unchecked_t fscache_n_stores_oom;
45383 +extern atomic_unchecked_t fscache_n_store_ops;
45384 +extern atomic_unchecked_t fscache_n_store_calls;
45385 +extern atomic_unchecked_t fscache_n_store_pages;
45386 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45387 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45388
45389 -extern atomic_t fscache_n_store_vmscan_not_storing;
45390 -extern atomic_t fscache_n_store_vmscan_gone;
45391 -extern atomic_t fscache_n_store_vmscan_busy;
45392 -extern atomic_t fscache_n_store_vmscan_cancelled;
45393 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45394 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45395 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45396 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45397
45398 -extern atomic_t fscache_n_marks;
45399 -extern atomic_t fscache_n_uncaches;
45400 +extern atomic_unchecked_t fscache_n_marks;
45401 +extern atomic_unchecked_t fscache_n_uncaches;
45402
45403 -extern atomic_t fscache_n_acquires;
45404 -extern atomic_t fscache_n_acquires_null;
45405 -extern atomic_t fscache_n_acquires_no_cache;
45406 -extern atomic_t fscache_n_acquires_ok;
45407 -extern atomic_t fscache_n_acquires_nobufs;
45408 -extern atomic_t fscache_n_acquires_oom;
45409 +extern atomic_unchecked_t fscache_n_acquires;
45410 +extern atomic_unchecked_t fscache_n_acquires_null;
45411 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45412 +extern atomic_unchecked_t fscache_n_acquires_ok;
45413 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45414 +extern atomic_unchecked_t fscache_n_acquires_oom;
45415
45416 -extern atomic_t fscache_n_updates;
45417 -extern atomic_t fscache_n_updates_null;
45418 -extern atomic_t fscache_n_updates_run;
45419 +extern atomic_unchecked_t fscache_n_updates;
45420 +extern atomic_unchecked_t fscache_n_updates_null;
45421 +extern atomic_unchecked_t fscache_n_updates_run;
45422
45423 -extern atomic_t fscache_n_relinquishes;
45424 -extern atomic_t fscache_n_relinquishes_null;
45425 -extern atomic_t fscache_n_relinquishes_waitcrt;
45426 -extern atomic_t fscache_n_relinquishes_retire;
45427 +extern atomic_unchecked_t fscache_n_relinquishes;
45428 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45429 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45430 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45431
45432 -extern atomic_t fscache_n_cookie_index;
45433 -extern atomic_t fscache_n_cookie_data;
45434 -extern atomic_t fscache_n_cookie_special;
45435 +extern atomic_unchecked_t fscache_n_cookie_index;
45436 +extern atomic_unchecked_t fscache_n_cookie_data;
45437 +extern atomic_unchecked_t fscache_n_cookie_special;
45438
45439 -extern atomic_t fscache_n_object_alloc;
45440 -extern atomic_t fscache_n_object_no_alloc;
45441 -extern atomic_t fscache_n_object_lookups;
45442 -extern atomic_t fscache_n_object_lookups_negative;
45443 -extern atomic_t fscache_n_object_lookups_positive;
45444 -extern atomic_t fscache_n_object_lookups_timed_out;
45445 -extern atomic_t fscache_n_object_created;
45446 -extern atomic_t fscache_n_object_avail;
45447 -extern atomic_t fscache_n_object_dead;
45448 +extern atomic_unchecked_t fscache_n_object_alloc;
45449 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45450 +extern atomic_unchecked_t fscache_n_object_lookups;
45451 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45452 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45453 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45454 +extern atomic_unchecked_t fscache_n_object_created;
45455 +extern atomic_unchecked_t fscache_n_object_avail;
45456 +extern atomic_unchecked_t fscache_n_object_dead;
45457
45458 -extern atomic_t fscache_n_checkaux_none;
45459 -extern atomic_t fscache_n_checkaux_okay;
45460 -extern atomic_t fscache_n_checkaux_update;
45461 -extern atomic_t fscache_n_checkaux_obsolete;
45462 +extern atomic_unchecked_t fscache_n_checkaux_none;
45463 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45464 +extern atomic_unchecked_t fscache_n_checkaux_update;
45465 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45466
45467 extern atomic_t fscache_n_cop_alloc_object;
45468 extern atomic_t fscache_n_cop_lookup_object;
45469 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45470 atomic_inc(stat);
45471 }
45472
45473 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45474 +{
45475 + atomic_inc_unchecked(stat);
45476 +}
45477 +
45478 static inline void fscache_stat_d(atomic_t *stat)
45479 {
45480 atomic_dec(stat);
45481 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45482
45483 #define __fscache_stat(stat) (NULL)
45484 #define fscache_stat(stat) do {} while (0)
45485 +#define fscache_stat_unchecked(stat) do {} while (0)
45486 #define fscache_stat_d(stat) do {} while (0)
45487 #endif
45488
45489 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45490 index b6b897c..0ffff9c 100644
45491 --- a/fs/fscache/object.c
45492 +++ b/fs/fscache/object.c
45493 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45494 /* update the object metadata on disk */
45495 case FSCACHE_OBJECT_UPDATING:
45496 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45497 - fscache_stat(&fscache_n_updates_run);
45498 + fscache_stat_unchecked(&fscache_n_updates_run);
45499 fscache_stat(&fscache_n_cop_update_object);
45500 object->cache->ops->update_object(object);
45501 fscache_stat_d(&fscache_n_cop_update_object);
45502 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45503 spin_lock(&object->lock);
45504 object->state = FSCACHE_OBJECT_DEAD;
45505 spin_unlock(&object->lock);
45506 - fscache_stat(&fscache_n_object_dead);
45507 + fscache_stat_unchecked(&fscache_n_object_dead);
45508 goto terminal_transit;
45509
45510 /* handle the parent cache of this object being withdrawn from
45511 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45512 spin_lock(&object->lock);
45513 object->state = FSCACHE_OBJECT_DEAD;
45514 spin_unlock(&object->lock);
45515 - fscache_stat(&fscache_n_object_dead);
45516 + fscache_stat_unchecked(&fscache_n_object_dead);
45517 goto terminal_transit;
45518
45519 /* complain about the object being woken up once it is
45520 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45521 parent->cookie->def->name, cookie->def->name,
45522 object->cache->tag->name);
45523
45524 - fscache_stat(&fscache_n_object_lookups);
45525 + fscache_stat_unchecked(&fscache_n_object_lookups);
45526 fscache_stat(&fscache_n_cop_lookup_object);
45527 ret = object->cache->ops->lookup_object(object);
45528 fscache_stat_d(&fscache_n_cop_lookup_object);
45529 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45530 if (ret == -ETIMEDOUT) {
45531 /* probably stuck behind another object, so move this one to
45532 * the back of the queue */
45533 - fscache_stat(&fscache_n_object_lookups_timed_out);
45534 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45535 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45536 }
45537
45538 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45539
45540 spin_lock(&object->lock);
45541 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45542 - fscache_stat(&fscache_n_object_lookups_negative);
45543 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45544
45545 /* transit here to allow write requests to begin stacking up
45546 * and read requests to begin returning ENODATA */
45547 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45548 * result, in which case there may be data available */
45549 spin_lock(&object->lock);
45550 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45551 - fscache_stat(&fscache_n_object_lookups_positive);
45552 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45553
45554 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45555
45556 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45557 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45558 } else {
45559 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45560 - fscache_stat(&fscache_n_object_created);
45561 + fscache_stat_unchecked(&fscache_n_object_created);
45562
45563 object->state = FSCACHE_OBJECT_AVAILABLE;
45564 spin_unlock(&object->lock);
45565 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45566 fscache_enqueue_dependents(object);
45567
45568 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45569 - fscache_stat(&fscache_n_object_avail);
45570 + fscache_stat_unchecked(&fscache_n_object_avail);
45571
45572 _leave("");
45573 }
45574 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45575 enum fscache_checkaux result;
45576
45577 if (!object->cookie->def->check_aux) {
45578 - fscache_stat(&fscache_n_checkaux_none);
45579 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45580 return FSCACHE_CHECKAUX_OKAY;
45581 }
45582
45583 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45584 switch (result) {
45585 /* entry okay as is */
45586 case FSCACHE_CHECKAUX_OKAY:
45587 - fscache_stat(&fscache_n_checkaux_okay);
45588 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45589 break;
45590
45591 /* entry requires update */
45592 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45593 - fscache_stat(&fscache_n_checkaux_update);
45594 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45595 break;
45596
45597 /* entry requires deletion */
45598 case FSCACHE_CHECKAUX_OBSOLETE:
45599 - fscache_stat(&fscache_n_checkaux_obsolete);
45600 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45601 break;
45602
45603 default:
45604 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45605 index 30afdfa..2256596 100644
45606 --- a/fs/fscache/operation.c
45607 +++ b/fs/fscache/operation.c
45608 @@ -17,7 +17,7 @@
45609 #include <linux/slab.h>
45610 #include "internal.h"
45611
45612 -atomic_t fscache_op_debug_id;
45613 +atomic_unchecked_t fscache_op_debug_id;
45614 EXPORT_SYMBOL(fscache_op_debug_id);
45615
45616 /**
45617 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45618 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45619 ASSERTCMP(atomic_read(&op->usage), >, 0);
45620
45621 - fscache_stat(&fscache_n_op_enqueue);
45622 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45623 switch (op->flags & FSCACHE_OP_TYPE) {
45624 case FSCACHE_OP_ASYNC:
45625 _debug("queue async");
45626 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45627 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45628 if (op->processor)
45629 fscache_enqueue_operation(op);
45630 - fscache_stat(&fscache_n_op_run);
45631 + fscache_stat_unchecked(&fscache_n_op_run);
45632 }
45633
45634 /*
45635 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45636 if (object->n_ops > 1) {
45637 atomic_inc(&op->usage);
45638 list_add_tail(&op->pend_link, &object->pending_ops);
45639 - fscache_stat(&fscache_n_op_pend);
45640 + fscache_stat_unchecked(&fscache_n_op_pend);
45641 } else if (!list_empty(&object->pending_ops)) {
45642 atomic_inc(&op->usage);
45643 list_add_tail(&op->pend_link, &object->pending_ops);
45644 - fscache_stat(&fscache_n_op_pend);
45645 + fscache_stat_unchecked(&fscache_n_op_pend);
45646 fscache_start_operations(object);
45647 } else {
45648 ASSERTCMP(object->n_in_progress, ==, 0);
45649 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45650 object->n_exclusive++; /* reads and writes must wait */
45651 atomic_inc(&op->usage);
45652 list_add_tail(&op->pend_link, &object->pending_ops);
45653 - fscache_stat(&fscache_n_op_pend);
45654 + fscache_stat_unchecked(&fscache_n_op_pend);
45655 ret = 0;
45656 } else {
45657 /* not allowed to submit ops in any other state */
45658 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45659 if (object->n_exclusive > 0) {
45660 atomic_inc(&op->usage);
45661 list_add_tail(&op->pend_link, &object->pending_ops);
45662 - fscache_stat(&fscache_n_op_pend);
45663 + fscache_stat_unchecked(&fscache_n_op_pend);
45664 } else if (!list_empty(&object->pending_ops)) {
45665 atomic_inc(&op->usage);
45666 list_add_tail(&op->pend_link, &object->pending_ops);
45667 - fscache_stat(&fscache_n_op_pend);
45668 + fscache_stat_unchecked(&fscache_n_op_pend);
45669 fscache_start_operations(object);
45670 } else {
45671 ASSERTCMP(object->n_exclusive, ==, 0);
45672 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45673 object->n_ops++;
45674 atomic_inc(&op->usage);
45675 list_add_tail(&op->pend_link, &object->pending_ops);
45676 - fscache_stat(&fscache_n_op_pend);
45677 + fscache_stat_unchecked(&fscache_n_op_pend);
45678 ret = 0;
45679 } else if (object->state == FSCACHE_OBJECT_DYING ||
45680 object->state == FSCACHE_OBJECT_LC_DYING ||
45681 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45682 - fscache_stat(&fscache_n_op_rejected);
45683 + fscache_stat_unchecked(&fscache_n_op_rejected);
45684 ret = -ENOBUFS;
45685 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45686 fscache_report_unexpected_submission(object, op, ostate);
45687 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45688
45689 ret = -EBUSY;
45690 if (!list_empty(&op->pend_link)) {
45691 - fscache_stat(&fscache_n_op_cancelled);
45692 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45693 list_del_init(&op->pend_link);
45694 object->n_ops--;
45695 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45696 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45697 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45698 BUG();
45699
45700 - fscache_stat(&fscache_n_op_release);
45701 + fscache_stat_unchecked(&fscache_n_op_release);
45702
45703 if (op->release) {
45704 op->release(op);
45705 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45706 * lock, and defer it otherwise */
45707 if (!spin_trylock(&object->lock)) {
45708 _debug("defer put");
45709 - fscache_stat(&fscache_n_op_deferred_release);
45710 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45711
45712 cache = object->cache;
45713 spin_lock(&cache->op_gc_list_lock);
45714 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45715
45716 _debug("GC DEFERRED REL OBJ%x OP%x",
45717 object->debug_id, op->debug_id);
45718 - fscache_stat(&fscache_n_op_gc);
45719 + fscache_stat_unchecked(&fscache_n_op_gc);
45720
45721 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45722
45723 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45724 index 3f7a59b..cf196cc 100644
45725 --- a/fs/fscache/page.c
45726 +++ b/fs/fscache/page.c
45727 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45728 val = radix_tree_lookup(&cookie->stores, page->index);
45729 if (!val) {
45730 rcu_read_unlock();
45731 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45732 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45733 __fscache_uncache_page(cookie, page);
45734 return true;
45735 }
45736 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45737 spin_unlock(&cookie->stores_lock);
45738
45739 if (xpage) {
45740 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45741 - fscache_stat(&fscache_n_store_radix_deletes);
45742 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45743 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45744 ASSERTCMP(xpage, ==, page);
45745 } else {
45746 - fscache_stat(&fscache_n_store_vmscan_gone);
45747 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45748 }
45749
45750 wake_up_bit(&cookie->flags, 0);
45751 @@ -107,7 +107,7 @@ page_busy:
45752 /* we might want to wait here, but that could deadlock the allocator as
45753 * the work threads writing to the cache may all end up sleeping
45754 * on memory allocation */
45755 - fscache_stat(&fscache_n_store_vmscan_busy);
45756 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45757 return false;
45758 }
45759 EXPORT_SYMBOL(__fscache_maybe_release_page);
45760 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45761 FSCACHE_COOKIE_STORING_TAG);
45762 if (!radix_tree_tag_get(&cookie->stores, page->index,
45763 FSCACHE_COOKIE_PENDING_TAG)) {
45764 - fscache_stat(&fscache_n_store_radix_deletes);
45765 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45766 xpage = radix_tree_delete(&cookie->stores, page->index);
45767 }
45768 spin_unlock(&cookie->stores_lock);
45769 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45770
45771 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45772
45773 - fscache_stat(&fscache_n_attr_changed_calls);
45774 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45775
45776 if (fscache_object_is_active(object)) {
45777 fscache_stat(&fscache_n_cop_attr_changed);
45778 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45779
45780 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45781
45782 - fscache_stat(&fscache_n_attr_changed);
45783 + fscache_stat_unchecked(&fscache_n_attr_changed);
45784
45785 op = kzalloc(sizeof(*op), GFP_KERNEL);
45786 if (!op) {
45787 - fscache_stat(&fscache_n_attr_changed_nomem);
45788 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45789 _leave(" = -ENOMEM");
45790 return -ENOMEM;
45791 }
45792 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45793 if (fscache_submit_exclusive_op(object, op) < 0)
45794 goto nobufs;
45795 spin_unlock(&cookie->lock);
45796 - fscache_stat(&fscache_n_attr_changed_ok);
45797 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45798 fscache_put_operation(op);
45799 _leave(" = 0");
45800 return 0;
45801 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45802 nobufs:
45803 spin_unlock(&cookie->lock);
45804 kfree(op);
45805 - fscache_stat(&fscache_n_attr_changed_nobufs);
45806 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45807 _leave(" = %d", -ENOBUFS);
45808 return -ENOBUFS;
45809 }
45810 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45811 /* allocate a retrieval operation and attempt to submit it */
45812 op = kzalloc(sizeof(*op), GFP_NOIO);
45813 if (!op) {
45814 - fscache_stat(&fscache_n_retrievals_nomem);
45815 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45816 return NULL;
45817 }
45818
45819 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45820 return 0;
45821 }
45822
45823 - fscache_stat(&fscache_n_retrievals_wait);
45824 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45825
45826 jif = jiffies;
45827 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45828 fscache_wait_bit_interruptible,
45829 TASK_INTERRUPTIBLE) != 0) {
45830 - fscache_stat(&fscache_n_retrievals_intr);
45831 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45832 _leave(" = -ERESTARTSYS");
45833 return -ERESTARTSYS;
45834 }
45835 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45836 */
45837 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45838 struct fscache_retrieval *op,
45839 - atomic_t *stat_op_waits,
45840 - atomic_t *stat_object_dead)
45841 + atomic_unchecked_t *stat_op_waits,
45842 + atomic_unchecked_t *stat_object_dead)
45843 {
45844 int ret;
45845
45846 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45847 goto check_if_dead;
45848
45849 _debug(">>> WT");
45850 - fscache_stat(stat_op_waits);
45851 + fscache_stat_unchecked(stat_op_waits);
45852 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45853 fscache_wait_bit_interruptible,
45854 TASK_INTERRUPTIBLE) < 0) {
45855 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45856
45857 check_if_dead:
45858 if (unlikely(fscache_object_is_dead(object))) {
45859 - fscache_stat(stat_object_dead);
45860 + fscache_stat_unchecked(stat_object_dead);
45861 return -ENOBUFS;
45862 }
45863 return 0;
45864 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45865
45866 _enter("%p,%p,,,", cookie, page);
45867
45868 - fscache_stat(&fscache_n_retrievals);
45869 + fscache_stat_unchecked(&fscache_n_retrievals);
45870
45871 if (hlist_empty(&cookie->backing_objects))
45872 goto nobufs;
45873 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45874 goto nobufs_unlock;
45875 spin_unlock(&cookie->lock);
45876
45877 - fscache_stat(&fscache_n_retrieval_ops);
45878 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45879
45880 /* pin the netfs read context in case we need to do the actual netfs
45881 * read because we've encountered a cache read failure */
45882 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45883
45884 error:
45885 if (ret == -ENOMEM)
45886 - fscache_stat(&fscache_n_retrievals_nomem);
45887 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45888 else if (ret == -ERESTARTSYS)
45889 - fscache_stat(&fscache_n_retrievals_intr);
45890 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45891 else if (ret == -ENODATA)
45892 - fscache_stat(&fscache_n_retrievals_nodata);
45893 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45894 else if (ret < 0)
45895 - fscache_stat(&fscache_n_retrievals_nobufs);
45896 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45897 else
45898 - fscache_stat(&fscache_n_retrievals_ok);
45899 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45900
45901 fscache_put_retrieval(op);
45902 _leave(" = %d", ret);
45903 @@ -429,7 +429,7 @@ nobufs_unlock:
45904 spin_unlock(&cookie->lock);
45905 kfree(op);
45906 nobufs:
45907 - fscache_stat(&fscache_n_retrievals_nobufs);
45908 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45909 _leave(" = -ENOBUFS");
45910 return -ENOBUFS;
45911 }
45912 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45913
45914 _enter("%p,,%d,,,", cookie, *nr_pages);
45915
45916 - fscache_stat(&fscache_n_retrievals);
45917 + fscache_stat_unchecked(&fscache_n_retrievals);
45918
45919 if (hlist_empty(&cookie->backing_objects))
45920 goto nobufs;
45921 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45922 goto nobufs_unlock;
45923 spin_unlock(&cookie->lock);
45924
45925 - fscache_stat(&fscache_n_retrieval_ops);
45926 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45927
45928 /* pin the netfs read context in case we need to do the actual netfs
45929 * read because we've encountered a cache read failure */
45930 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45931
45932 error:
45933 if (ret == -ENOMEM)
45934 - fscache_stat(&fscache_n_retrievals_nomem);
45935 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45936 else if (ret == -ERESTARTSYS)
45937 - fscache_stat(&fscache_n_retrievals_intr);
45938 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45939 else if (ret == -ENODATA)
45940 - fscache_stat(&fscache_n_retrievals_nodata);
45941 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45942 else if (ret < 0)
45943 - fscache_stat(&fscache_n_retrievals_nobufs);
45944 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45945 else
45946 - fscache_stat(&fscache_n_retrievals_ok);
45947 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45948
45949 fscache_put_retrieval(op);
45950 _leave(" = %d", ret);
45951 @@ -545,7 +545,7 @@ nobufs_unlock:
45952 spin_unlock(&cookie->lock);
45953 kfree(op);
45954 nobufs:
45955 - fscache_stat(&fscache_n_retrievals_nobufs);
45956 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45957 _leave(" = -ENOBUFS");
45958 return -ENOBUFS;
45959 }
45960 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45961
45962 _enter("%p,%p,,,", cookie, page);
45963
45964 - fscache_stat(&fscache_n_allocs);
45965 + fscache_stat_unchecked(&fscache_n_allocs);
45966
45967 if (hlist_empty(&cookie->backing_objects))
45968 goto nobufs;
45969 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45970 goto nobufs_unlock;
45971 spin_unlock(&cookie->lock);
45972
45973 - fscache_stat(&fscache_n_alloc_ops);
45974 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45975
45976 ret = fscache_wait_for_retrieval_activation(
45977 object, op,
45978 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45979
45980 error:
45981 if (ret == -ERESTARTSYS)
45982 - fscache_stat(&fscache_n_allocs_intr);
45983 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45984 else if (ret < 0)
45985 - fscache_stat(&fscache_n_allocs_nobufs);
45986 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45987 else
45988 - fscache_stat(&fscache_n_allocs_ok);
45989 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45990
45991 fscache_put_retrieval(op);
45992 _leave(" = %d", ret);
45993 @@ -625,7 +625,7 @@ nobufs_unlock:
45994 spin_unlock(&cookie->lock);
45995 kfree(op);
45996 nobufs:
45997 - fscache_stat(&fscache_n_allocs_nobufs);
45998 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45999 _leave(" = -ENOBUFS");
46000 return -ENOBUFS;
46001 }
46002 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46003
46004 spin_lock(&cookie->stores_lock);
46005
46006 - fscache_stat(&fscache_n_store_calls);
46007 + fscache_stat_unchecked(&fscache_n_store_calls);
46008
46009 /* find a page to store */
46010 page = NULL;
46011 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46012 page = results[0];
46013 _debug("gang %d [%lx]", n, page->index);
46014 if (page->index > op->store_limit) {
46015 - fscache_stat(&fscache_n_store_pages_over_limit);
46016 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46017 goto superseded;
46018 }
46019
46020 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46021 spin_unlock(&cookie->stores_lock);
46022 spin_unlock(&object->lock);
46023
46024 - fscache_stat(&fscache_n_store_pages);
46025 + fscache_stat_unchecked(&fscache_n_store_pages);
46026 fscache_stat(&fscache_n_cop_write_page);
46027 ret = object->cache->ops->write_page(op, page);
46028 fscache_stat_d(&fscache_n_cop_write_page);
46029 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46030 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46031 ASSERT(PageFsCache(page));
46032
46033 - fscache_stat(&fscache_n_stores);
46034 + fscache_stat_unchecked(&fscache_n_stores);
46035
46036 op = kzalloc(sizeof(*op), GFP_NOIO);
46037 if (!op)
46038 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46039 spin_unlock(&cookie->stores_lock);
46040 spin_unlock(&object->lock);
46041
46042 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46043 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46044 op->store_limit = object->store_limit;
46045
46046 if (fscache_submit_op(object, &op->op) < 0)
46047 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46048
46049 spin_unlock(&cookie->lock);
46050 radix_tree_preload_end();
46051 - fscache_stat(&fscache_n_store_ops);
46052 - fscache_stat(&fscache_n_stores_ok);
46053 + fscache_stat_unchecked(&fscache_n_store_ops);
46054 + fscache_stat_unchecked(&fscache_n_stores_ok);
46055
46056 /* the work queue now carries its own ref on the object */
46057 fscache_put_operation(&op->op);
46058 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46059 return 0;
46060
46061 already_queued:
46062 - fscache_stat(&fscache_n_stores_again);
46063 + fscache_stat_unchecked(&fscache_n_stores_again);
46064 already_pending:
46065 spin_unlock(&cookie->stores_lock);
46066 spin_unlock(&object->lock);
46067 spin_unlock(&cookie->lock);
46068 radix_tree_preload_end();
46069 kfree(op);
46070 - fscache_stat(&fscache_n_stores_ok);
46071 + fscache_stat_unchecked(&fscache_n_stores_ok);
46072 _leave(" = 0");
46073 return 0;
46074
46075 @@ -851,14 +851,14 @@ nobufs:
46076 spin_unlock(&cookie->lock);
46077 radix_tree_preload_end();
46078 kfree(op);
46079 - fscache_stat(&fscache_n_stores_nobufs);
46080 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46081 _leave(" = -ENOBUFS");
46082 return -ENOBUFS;
46083
46084 nomem_free:
46085 kfree(op);
46086 nomem:
46087 - fscache_stat(&fscache_n_stores_oom);
46088 + fscache_stat_unchecked(&fscache_n_stores_oom);
46089 _leave(" = -ENOMEM");
46090 return -ENOMEM;
46091 }
46092 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46093 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46094 ASSERTCMP(page, !=, NULL);
46095
46096 - fscache_stat(&fscache_n_uncaches);
46097 + fscache_stat_unchecked(&fscache_n_uncaches);
46098
46099 /* cache withdrawal may beat us to it */
46100 if (!PageFsCache(page))
46101 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46102 unsigned long loop;
46103
46104 #ifdef CONFIG_FSCACHE_STATS
46105 - atomic_add(pagevec->nr, &fscache_n_marks);
46106 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46107 #endif
46108
46109 for (loop = 0; loop < pagevec->nr; loop++) {
46110 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46111 index 4765190..2a067f2 100644
46112 --- a/fs/fscache/stats.c
46113 +++ b/fs/fscache/stats.c
46114 @@ -18,95 +18,95 @@
46115 /*
46116 * operation counters
46117 */
46118 -atomic_t fscache_n_op_pend;
46119 -atomic_t fscache_n_op_run;
46120 -atomic_t fscache_n_op_enqueue;
46121 -atomic_t fscache_n_op_requeue;
46122 -atomic_t fscache_n_op_deferred_release;
46123 -atomic_t fscache_n_op_release;
46124 -atomic_t fscache_n_op_gc;
46125 -atomic_t fscache_n_op_cancelled;
46126 -atomic_t fscache_n_op_rejected;
46127 +atomic_unchecked_t fscache_n_op_pend;
46128 +atomic_unchecked_t fscache_n_op_run;
46129 +atomic_unchecked_t fscache_n_op_enqueue;
46130 +atomic_unchecked_t fscache_n_op_requeue;
46131 +atomic_unchecked_t fscache_n_op_deferred_release;
46132 +atomic_unchecked_t fscache_n_op_release;
46133 +atomic_unchecked_t fscache_n_op_gc;
46134 +atomic_unchecked_t fscache_n_op_cancelled;
46135 +atomic_unchecked_t fscache_n_op_rejected;
46136
46137 -atomic_t fscache_n_attr_changed;
46138 -atomic_t fscache_n_attr_changed_ok;
46139 -atomic_t fscache_n_attr_changed_nobufs;
46140 -atomic_t fscache_n_attr_changed_nomem;
46141 -atomic_t fscache_n_attr_changed_calls;
46142 +atomic_unchecked_t fscache_n_attr_changed;
46143 +atomic_unchecked_t fscache_n_attr_changed_ok;
46144 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46145 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46146 +atomic_unchecked_t fscache_n_attr_changed_calls;
46147
46148 -atomic_t fscache_n_allocs;
46149 -atomic_t fscache_n_allocs_ok;
46150 -atomic_t fscache_n_allocs_wait;
46151 -atomic_t fscache_n_allocs_nobufs;
46152 -atomic_t fscache_n_allocs_intr;
46153 -atomic_t fscache_n_allocs_object_dead;
46154 -atomic_t fscache_n_alloc_ops;
46155 -atomic_t fscache_n_alloc_op_waits;
46156 +atomic_unchecked_t fscache_n_allocs;
46157 +atomic_unchecked_t fscache_n_allocs_ok;
46158 +atomic_unchecked_t fscache_n_allocs_wait;
46159 +atomic_unchecked_t fscache_n_allocs_nobufs;
46160 +atomic_unchecked_t fscache_n_allocs_intr;
46161 +atomic_unchecked_t fscache_n_allocs_object_dead;
46162 +atomic_unchecked_t fscache_n_alloc_ops;
46163 +atomic_unchecked_t fscache_n_alloc_op_waits;
46164
46165 -atomic_t fscache_n_retrievals;
46166 -atomic_t fscache_n_retrievals_ok;
46167 -atomic_t fscache_n_retrievals_wait;
46168 -atomic_t fscache_n_retrievals_nodata;
46169 -atomic_t fscache_n_retrievals_nobufs;
46170 -atomic_t fscache_n_retrievals_intr;
46171 -atomic_t fscache_n_retrievals_nomem;
46172 -atomic_t fscache_n_retrievals_object_dead;
46173 -atomic_t fscache_n_retrieval_ops;
46174 -atomic_t fscache_n_retrieval_op_waits;
46175 +atomic_unchecked_t fscache_n_retrievals;
46176 +atomic_unchecked_t fscache_n_retrievals_ok;
46177 +atomic_unchecked_t fscache_n_retrievals_wait;
46178 +atomic_unchecked_t fscache_n_retrievals_nodata;
46179 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46180 +atomic_unchecked_t fscache_n_retrievals_intr;
46181 +atomic_unchecked_t fscache_n_retrievals_nomem;
46182 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46183 +atomic_unchecked_t fscache_n_retrieval_ops;
46184 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46185
46186 -atomic_t fscache_n_stores;
46187 -atomic_t fscache_n_stores_ok;
46188 -atomic_t fscache_n_stores_again;
46189 -atomic_t fscache_n_stores_nobufs;
46190 -atomic_t fscache_n_stores_oom;
46191 -atomic_t fscache_n_store_ops;
46192 -atomic_t fscache_n_store_calls;
46193 -atomic_t fscache_n_store_pages;
46194 -atomic_t fscache_n_store_radix_deletes;
46195 -atomic_t fscache_n_store_pages_over_limit;
46196 +atomic_unchecked_t fscache_n_stores;
46197 +atomic_unchecked_t fscache_n_stores_ok;
46198 +atomic_unchecked_t fscache_n_stores_again;
46199 +atomic_unchecked_t fscache_n_stores_nobufs;
46200 +atomic_unchecked_t fscache_n_stores_oom;
46201 +atomic_unchecked_t fscache_n_store_ops;
46202 +atomic_unchecked_t fscache_n_store_calls;
46203 +atomic_unchecked_t fscache_n_store_pages;
46204 +atomic_unchecked_t fscache_n_store_radix_deletes;
46205 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46206
46207 -atomic_t fscache_n_store_vmscan_not_storing;
46208 -atomic_t fscache_n_store_vmscan_gone;
46209 -atomic_t fscache_n_store_vmscan_busy;
46210 -atomic_t fscache_n_store_vmscan_cancelled;
46211 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46212 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46213 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46214 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46215
46216 -atomic_t fscache_n_marks;
46217 -atomic_t fscache_n_uncaches;
46218 +atomic_unchecked_t fscache_n_marks;
46219 +atomic_unchecked_t fscache_n_uncaches;
46220
46221 -atomic_t fscache_n_acquires;
46222 -atomic_t fscache_n_acquires_null;
46223 -atomic_t fscache_n_acquires_no_cache;
46224 -atomic_t fscache_n_acquires_ok;
46225 -atomic_t fscache_n_acquires_nobufs;
46226 -atomic_t fscache_n_acquires_oom;
46227 +atomic_unchecked_t fscache_n_acquires;
46228 +atomic_unchecked_t fscache_n_acquires_null;
46229 +atomic_unchecked_t fscache_n_acquires_no_cache;
46230 +atomic_unchecked_t fscache_n_acquires_ok;
46231 +atomic_unchecked_t fscache_n_acquires_nobufs;
46232 +atomic_unchecked_t fscache_n_acquires_oom;
46233
46234 -atomic_t fscache_n_updates;
46235 -atomic_t fscache_n_updates_null;
46236 -atomic_t fscache_n_updates_run;
46237 +atomic_unchecked_t fscache_n_updates;
46238 +atomic_unchecked_t fscache_n_updates_null;
46239 +atomic_unchecked_t fscache_n_updates_run;
46240
46241 -atomic_t fscache_n_relinquishes;
46242 -atomic_t fscache_n_relinquishes_null;
46243 -atomic_t fscache_n_relinquishes_waitcrt;
46244 -atomic_t fscache_n_relinquishes_retire;
46245 +atomic_unchecked_t fscache_n_relinquishes;
46246 +atomic_unchecked_t fscache_n_relinquishes_null;
46247 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46248 +atomic_unchecked_t fscache_n_relinquishes_retire;
46249
46250 -atomic_t fscache_n_cookie_index;
46251 -atomic_t fscache_n_cookie_data;
46252 -atomic_t fscache_n_cookie_special;
46253 +atomic_unchecked_t fscache_n_cookie_index;
46254 +atomic_unchecked_t fscache_n_cookie_data;
46255 +atomic_unchecked_t fscache_n_cookie_special;
46256
46257 -atomic_t fscache_n_object_alloc;
46258 -atomic_t fscache_n_object_no_alloc;
46259 -atomic_t fscache_n_object_lookups;
46260 -atomic_t fscache_n_object_lookups_negative;
46261 -atomic_t fscache_n_object_lookups_positive;
46262 -atomic_t fscache_n_object_lookups_timed_out;
46263 -atomic_t fscache_n_object_created;
46264 -atomic_t fscache_n_object_avail;
46265 -atomic_t fscache_n_object_dead;
46266 +atomic_unchecked_t fscache_n_object_alloc;
46267 +atomic_unchecked_t fscache_n_object_no_alloc;
46268 +atomic_unchecked_t fscache_n_object_lookups;
46269 +atomic_unchecked_t fscache_n_object_lookups_negative;
46270 +atomic_unchecked_t fscache_n_object_lookups_positive;
46271 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46272 +atomic_unchecked_t fscache_n_object_created;
46273 +atomic_unchecked_t fscache_n_object_avail;
46274 +atomic_unchecked_t fscache_n_object_dead;
46275
46276 -atomic_t fscache_n_checkaux_none;
46277 -atomic_t fscache_n_checkaux_okay;
46278 -atomic_t fscache_n_checkaux_update;
46279 -atomic_t fscache_n_checkaux_obsolete;
46280 +atomic_unchecked_t fscache_n_checkaux_none;
46281 +atomic_unchecked_t fscache_n_checkaux_okay;
46282 +atomic_unchecked_t fscache_n_checkaux_update;
46283 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46284
46285 atomic_t fscache_n_cop_alloc_object;
46286 atomic_t fscache_n_cop_lookup_object;
46287 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46288 seq_puts(m, "FS-Cache statistics\n");
46289
46290 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46291 - atomic_read(&fscache_n_cookie_index),
46292 - atomic_read(&fscache_n_cookie_data),
46293 - atomic_read(&fscache_n_cookie_special));
46294 + atomic_read_unchecked(&fscache_n_cookie_index),
46295 + atomic_read_unchecked(&fscache_n_cookie_data),
46296 + atomic_read_unchecked(&fscache_n_cookie_special));
46297
46298 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46299 - atomic_read(&fscache_n_object_alloc),
46300 - atomic_read(&fscache_n_object_no_alloc),
46301 - atomic_read(&fscache_n_object_avail),
46302 - atomic_read(&fscache_n_object_dead));
46303 + atomic_read_unchecked(&fscache_n_object_alloc),
46304 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46305 + atomic_read_unchecked(&fscache_n_object_avail),
46306 + atomic_read_unchecked(&fscache_n_object_dead));
46307 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46308 - atomic_read(&fscache_n_checkaux_none),
46309 - atomic_read(&fscache_n_checkaux_okay),
46310 - atomic_read(&fscache_n_checkaux_update),
46311 - atomic_read(&fscache_n_checkaux_obsolete));
46312 + atomic_read_unchecked(&fscache_n_checkaux_none),
46313 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46314 + atomic_read_unchecked(&fscache_n_checkaux_update),
46315 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46316
46317 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46318 - atomic_read(&fscache_n_marks),
46319 - atomic_read(&fscache_n_uncaches));
46320 + atomic_read_unchecked(&fscache_n_marks),
46321 + atomic_read_unchecked(&fscache_n_uncaches));
46322
46323 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46324 " oom=%u\n",
46325 - atomic_read(&fscache_n_acquires),
46326 - atomic_read(&fscache_n_acquires_null),
46327 - atomic_read(&fscache_n_acquires_no_cache),
46328 - atomic_read(&fscache_n_acquires_ok),
46329 - atomic_read(&fscache_n_acquires_nobufs),
46330 - atomic_read(&fscache_n_acquires_oom));
46331 + atomic_read_unchecked(&fscache_n_acquires),
46332 + atomic_read_unchecked(&fscache_n_acquires_null),
46333 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46334 + atomic_read_unchecked(&fscache_n_acquires_ok),
46335 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46336 + atomic_read_unchecked(&fscache_n_acquires_oom));
46337
46338 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46339 - atomic_read(&fscache_n_object_lookups),
46340 - atomic_read(&fscache_n_object_lookups_negative),
46341 - atomic_read(&fscache_n_object_lookups_positive),
46342 - atomic_read(&fscache_n_object_created),
46343 - atomic_read(&fscache_n_object_lookups_timed_out));
46344 + atomic_read_unchecked(&fscache_n_object_lookups),
46345 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46346 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46347 + atomic_read_unchecked(&fscache_n_object_created),
46348 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46349
46350 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46351 - atomic_read(&fscache_n_updates),
46352 - atomic_read(&fscache_n_updates_null),
46353 - atomic_read(&fscache_n_updates_run));
46354 + atomic_read_unchecked(&fscache_n_updates),
46355 + atomic_read_unchecked(&fscache_n_updates_null),
46356 + atomic_read_unchecked(&fscache_n_updates_run));
46357
46358 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46359 - atomic_read(&fscache_n_relinquishes),
46360 - atomic_read(&fscache_n_relinquishes_null),
46361 - atomic_read(&fscache_n_relinquishes_waitcrt),
46362 - atomic_read(&fscache_n_relinquishes_retire));
46363 + atomic_read_unchecked(&fscache_n_relinquishes),
46364 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46365 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46366 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46367
46368 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46369 - atomic_read(&fscache_n_attr_changed),
46370 - atomic_read(&fscache_n_attr_changed_ok),
46371 - atomic_read(&fscache_n_attr_changed_nobufs),
46372 - atomic_read(&fscache_n_attr_changed_nomem),
46373 - atomic_read(&fscache_n_attr_changed_calls));
46374 + atomic_read_unchecked(&fscache_n_attr_changed),
46375 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46376 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46377 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46378 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46379
46380 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46381 - atomic_read(&fscache_n_allocs),
46382 - atomic_read(&fscache_n_allocs_ok),
46383 - atomic_read(&fscache_n_allocs_wait),
46384 - atomic_read(&fscache_n_allocs_nobufs),
46385 - atomic_read(&fscache_n_allocs_intr));
46386 + atomic_read_unchecked(&fscache_n_allocs),
46387 + atomic_read_unchecked(&fscache_n_allocs_ok),
46388 + atomic_read_unchecked(&fscache_n_allocs_wait),
46389 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46390 + atomic_read_unchecked(&fscache_n_allocs_intr));
46391 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46392 - atomic_read(&fscache_n_alloc_ops),
46393 - atomic_read(&fscache_n_alloc_op_waits),
46394 - atomic_read(&fscache_n_allocs_object_dead));
46395 + atomic_read_unchecked(&fscache_n_alloc_ops),
46396 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46397 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46398
46399 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46400 " int=%u oom=%u\n",
46401 - atomic_read(&fscache_n_retrievals),
46402 - atomic_read(&fscache_n_retrievals_ok),
46403 - atomic_read(&fscache_n_retrievals_wait),
46404 - atomic_read(&fscache_n_retrievals_nodata),
46405 - atomic_read(&fscache_n_retrievals_nobufs),
46406 - atomic_read(&fscache_n_retrievals_intr),
46407 - atomic_read(&fscache_n_retrievals_nomem));
46408 + atomic_read_unchecked(&fscache_n_retrievals),
46409 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46410 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46411 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46412 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46413 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46414 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46415 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46416 - atomic_read(&fscache_n_retrieval_ops),
46417 - atomic_read(&fscache_n_retrieval_op_waits),
46418 - atomic_read(&fscache_n_retrievals_object_dead));
46419 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46420 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46421 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46422
46423 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46424 - atomic_read(&fscache_n_stores),
46425 - atomic_read(&fscache_n_stores_ok),
46426 - atomic_read(&fscache_n_stores_again),
46427 - atomic_read(&fscache_n_stores_nobufs),
46428 - atomic_read(&fscache_n_stores_oom));
46429 + atomic_read_unchecked(&fscache_n_stores),
46430 + atomic_read_unchecked(&fscache_n_stores_ok),
46431 + atomic_read_unchecked(&fscache_n_stores_again),
46432 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46433 + atomic_read_unchecked(&fscache_n_stores_oom));
46434 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46435 - atomic_read(&fscache_n_store_ops),
46436 - atomic_read(&fscache_n_store_calls),
46437 - atomic_read(&fscache_n_store_pages),
46438 - atomic_read(&fscache_n_store_radix_deletes),
46439 - atomic_read(&fscache_n_store_pages_over_limit));
46440 + atomic_read_unchecked(&fscache_n_store_ops),
46441 + atomic_read_unchecked(&fscache_n_store_calls),
46442 + atomic_read_unchecked(&fscache_n_store_pages),
46443 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46444 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46445
46446 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46447 - atomic_read(&fscache_n_store_vmscan_not_storing),
46448 - atomic_read(&fscache_n_store_vmscan_gone),
46449 - atomic_read(&fscache_n_store_vmscan_busy),
46450 - atomic_read(&fscache_n_store_vmscan_cancelled));
46451 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46452 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46453 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46454 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46455
46456 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46457 - atomic_read(&fscache_n_op_pend),
46458 - atomic_read(&fscache_n_op_run),
46459 - atomic_read(&fscache_n_op_enqueue),
46460 - atomic_read(&fscache_n_op_cancelled),
46461 - atomic_read(&fscache_n_op_rejected));
46462 + atomic_read_unchecked(&fscache_n_op_pend),
46463 + atomic_read_unchecked(&fscache_n_op_run),
46464 + atomic_read_unchecked(&fscache_n_op_enqueue),
46465 + atomic_read_unchecked(&fscache_n_op_cancelled),
46466 + atomic_read_unchecked(&fscache_n_op_rejected));
46467 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46468 - atomic_read(&fscache_n_op_deferred_release),
46469 - atomic_read(&fscache_n_op_release),
46470 - atomic_read(&fscache_n_op_gc));
46471 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46472 + atomic_read_unchecked(&fscache_n_op_release),
46473 + atomic_read_unchecked(&fscache_n_op_gc));
46474
46475 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46476 atomic_read(&fscache_n_cop_alloc_object),
46477 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46478 index 3426521..3b75162 100644
46479 --- a/fs/fuse/cuse.c
46480 +++ b/fs/fuse/cuse.c
46481 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46482 INIT_LIST_HEAD(&cuse_conntbl[i]);
46483
46484 /* inherit and extend fuse_dev_operations */
46485 - cuse_channel_fops = fuse_dev_operations;
46486 - cuse_channel_fops.owner = THIS_MODULE;
46487 - cuse_channel_fops.open = cuse_channel_open;
46488 - cuse_channel_fops.release = cuse_channel_release;
46489 + pax_open_kernel();
46490 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46491 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46492 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46493 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46494 + pax_close_kernel();
46495
46496 cuse_class = class_create(THIS_MODULE, "cuse");
46497 if (IS_ERR(cuse_class))
46498 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46499 index 5f3368a..8306426 100644
46500 --- a/fs/fuse/dev.c
46501 +++ b/fs/fuse/dev.c
46502 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46503 ret = 0;
46504 pipe_lock(pipe);
46505
46506 - if (!pipe->readers) {
46507 + if (!atomic_read(&pipe->readers)) {
46508 send_sig(SIGPIPE, current, 0);
46509 if (!ret)
46510 ret = -EPIPE;
46511 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46512 index 2066328..f5add3b 100644
46513 --- a/fs/fuse/dir.c
46514 +++ b/fs/fuse/dir.c
46515 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46516 return link;
46517 }
46518
46519 -static void free_link(char *link)
46520 +static void free_link(const char *link)
46521 {
46522 if (!IS_ERR(link))
46523 free_page((unsigned long) link);
46524 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46525 index 5698746..6086012 100644
46526 --- a/fs/gfs2/inode.c
46527 +++ b/fs/gfs2/inode.c
46528 @@ -1487,7 +1487,7 @@ out:
46529
46530 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46531 {
46532 - char *s = nd_get_link(nd);
46533 + const char *s = nd_get_link(nd);
46534 if (!IS_ERR(s))
46535 kfree(s);
46536 }
46537 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46538 index 3645cd3..786809c 100644
46539 --- a/fs/hugetlbfs/inode.c
46540 +++ b/fs/hugetlbfs/inode.c
46541 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46542 .kill_sb = kill_litter_super,
46543 };
46544
46545 -static struct vfsmount *hugetlbfs_vfsmount;
46546 +struct vfsmount *hugetlbfs_vfsmount;
46547
46548 static int can_do_hugetlb_shm(void)
46549 {
46550 diff --git a/fs/inode.c b/fs/inode.c
46551 index 83ab215..8842101 100644
46552 --- a/fs/inode.c
46553 +++ b/fs/inode.c
46554 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46555
46556 #ifdef CONFIG_SMP
46557 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46558 - static atomic_t shared_last_ino;
46559 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46560 + static atomic_unchecked_t shared_last_ino;
46561 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46562
46563 res = next - LAST_INO_BATCH;
46564 }
46565 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46566 index eafb8d3..f423d37 100644
46567 --- a/fs/jffs2/erase.c
46568 +++ b/fs/jffs2/erase.c
46569 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46570 struct jffs2_unknown_node marker = {
46571 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46572 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46573 - .totlen = cpu_to_je32(c->cleanmarker_size)
46574 + .totlen = cpu_to_je32(c->cleanmarker_size),
46575 + .hdr_crc = cpu_to_je32(0)
46576 };
46577
46578 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46579 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46580 index 30e8f47..21f600c 100644
46581 --- a/fs/jffs2/wbuf.c
46582 +++ b/fs/jffs2/wbuf.c
46583 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46584 {
46585 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46586 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46587 - .totlen = constant_cpu_to_je32(8)
46588 + .totlen = constant_cpu_to_je32(8),
46589 + .hdr_crc = constant_cpu_to_je32(0)
46590 };
46591
46592 /*
46593 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46594 index 682bca6..86b8e6e 100644
46595 --- a/fs/jfs/super.c
46596 +++ b/fs/jfs/super.c
46597 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46598
46599 jfs_inode_cachep =
46600 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46601 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46602 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46603 init_once);
46604 if (jfs_inode_cachep == NULL)
46605 return -ENOMEM;
46606 diff --git a/fs/libfs.c b/fs/libfs.c
46607 index 5b2dbb3..7442d54 100644
46608 --- a/fs/libfs.c
46609 +++ b/fs/libfs.c
46610 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46611
46612 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46613 struct dentry *next;
46614 + char d_name[sizeof(next->d_iname)];
46615 + const unsigned char *name;
46616 +
46617 next = list_entry(p, struct dentry, d_u.d_child);
46618 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46619 if (!simple_positive(next)) {
46620 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46621
46622 spin_unlock(&next->d_lock);
46623 spin_unlock(&dentry->d_lock);
46624 - if (filldir(dirent, next->d_name.name,
46625 + name = next->d_name.name;
46626 + if (name == next->d_iname) {
46627 + memcpy(d_name, name, next->d_name.len);
46628 + name = d_name;
46629 + }
46630 + if (filldir(dirent, name,
46631 next->d_name.len, filp->f_pos,
46632 next->d_inode->i_ino,
46633 dt_type(next->d_inode)) < 0)
46634 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46635 index 8392cb8..80d6193 100644
46636 --- a/fs/lockd/clntproc.c
46637 +++ b/fs/lockd/clntproc.c
46638 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46639 /*
46640 * Cookie counter for NLM requests
46641 */
46642 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46643 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46644
46645 void nlmclnt_next_cookie(struct nlm_cookie *c)
46646 {
46647 - u32 cookie = atomic_inc_return(&nlm_cookie);
46648 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46649
46650 memcpy(c->data, &cookie, 4);
46651 c->len=4;
46652 diff --git a/fs/locks.c b/fs/locks.c
46653 index 0d68f1f..f216b79 100644
46654 --- a/fs/locks.c
46655 +++ b/fs/locks.c
46656 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46657 return;
46658
46659 if (filp->f_op && filp->f_op->flock) {
46660 - struct file_lock fl = {
46661 + struct file_lock flock = {
46662 .fl_pid = current->tgid,
46663 .fl_file = filp,
46664 .fl_flags = FL_FLOCK,
46665 .fl_type = F_UNLCK,
46666 .fl_end = OFFSET_MAX,
46667 };
46668 - filp->f_op->flock(filp, F_SETLKW, &fl);
46669 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46670 - fl.fl_ops->fl_release_private(&fl);
46671 + filp->f_op->flock(filp, F_SETLKW, &flock);
46672 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46673 + flock.fl_ops->fl_release_private(&flock);
46674 }
46675
46676 lock_flocks();
46677 diff --git a/fs/namei.c b/fs/namei.c
46678 index 46ea9cc..c7cf3a3 100644
46679 --- a/fs/namei.c
46680 +++ b/fs/namei.c
46681 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46682 if (ret != -EACCES)
46683 return ret;
46684
46685 +#ifdef CONFIG_GRKERNSEC
46686 + /* we'll block if we have to log due to a denied capability use */
46687 + if (mask & MAY_NOT_BLOCK)
46688 + return -ECHILD;
46689 +#endif
46690 +
46691 if (S_ISDIR(inode->i_mode)) {
46692 /* DACs are overridable for directories */
46693 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46694 - return 0;
46695 if (!(mask & MAY_WRITE))
46696 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46697 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46698 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46699 return 0;
46700 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46701 + return 0;
46702 return -EACCES;
46703 }
46704 /*
46705 + * Searching includes executable on directories, else just read.
46706 + */
46707 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46708 + if (mask == MAY_READ)
46709 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46710 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46711 + return 0;
46712 +
46713 + /*
46714 * Read/write DACs are always overridable.
46715 * Executable DACs are overridable when there is
46716 * at least one exec bit set.
46717 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46718 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46719 return 0;
46720
46721 - /*
46722 - * Searching includes executable on directories, else just read.
46723 - */
46724 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46725 - if (mask == MAY_READ)
46726 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46727 - return 0;
46728 -
46729 return -EACCES;
46730 }
46731
46732 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46733 return error;
46734 }
46735
46736 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46737 + dentry->d_inode, dentry, nd->path.mnt)) {
46738 + error = -EACCES;
46739 + *p = ERR_PTR(error); /* no ->put_link(), please */
46740 + path_put(&nd->path);
46741 + return error;
46742 + }
46743 +
46744 nd->last_type = LAST_BIND;
46745 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46746 error = PTR_ERR(*p);
46747 if (!IS_ERR(*p)) {
46748 - char *s = nd_get_link(nd);
46749 + const char *s = nd_get_link(nd);
46750 error = 0;
46751 if (s)
46752 error = __vfs_follow_link(nd, s);
46753 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46754 if (!err)
46755 err = complete_walk(nd);
46756
46757 + if (!(nd->flags & LOOKUP_PARENT)) {
46758 +#ifdef CONFIG_GRKERNSEC
46759 + if (flags & LOOKUP_RCU) {
46760 + if (!err)
46761 + path_put(&nd->path);
46762 + err = -ECHILD;
46763 + } else
46764 +#endif
46765 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46766 + if (!err)
46767 + path_put(&nd->path);
46768 + err = -ENOENT;
46769 + }
46770 + }
46771 +
46772 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46773 if (!nd->inode->i_op->lookup) {
46774 path_put(&nd->path);
46775 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46776 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46777
46778 if (likely(!retval)) {
46779 + if (*name != '/' && nd->path.dentry && nd->inode) {
46780 +#ifdef CONFIG_GRKERNSEC
46781 + if (flags & LOOKUP_RCU)
46782 + return -ECHILD;
46783 +#endif
46784 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46785 + return -ENOENT;
46786 + }
46787 +
46788 if (unlikely(!audit_dummy_context())) {
46789 if (nd->path.dentry && nd->inode)
46790 audit_inode(name, nd->path.dentry);
46791 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46792 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46793 return -EPERM;
46794
46795 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46796 + return -EPERM;
46797 + if (gr_handle_rawio(inode))
46798 + return -EPERM;
46799 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46800 + return -EACCES;
46801 +
46802 return 0;
46803 }
46804
46805 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46806 error = complete_walk(nd);
46807 if (error)
46808 return ERR_PTR(error);
46809 +#ifdef CONFIG_GRKERNSEC
46810 + if (nd->flags & LOOKUP_RCU) {
46811 + error = -ECHILD;
46812 + goto exit;
46813 + }
46814 +#endif
46815 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46816 + error = -ENOENT;
46817 + goto exit;
46818 + }
46819 audit_inode(pathname, nd->path.dentry);
46820 if (open_flag & O_CREAT) {
46821 error = -EISDIR;
46822 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46823 error = complete_walk(nd);
46824 if (error)
46825 return ERR_PTR(error);
46826 +#ifdef CONFIG_GRKERNSEC
46827 + if (nd->flags & LOOKUP_RCU) {
46828 + error = -ECHILD;
46829 + goto exit;
46830 + }
46831 +#endif
46832 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46833 + error = -ENOENT;
46834 + goto exit;
46835 + }
46836 audit_inode(pathname, dir);
46837 goto ok;
46838 }
46839 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46840 error = complete_walk(nd);
46841 if (error)
46842 return ERR_PTR(error);
46843 +#ifdef CONFIG_GRKERNSEC
46844 + if (nd->flags & LOOKUP_RCU) {
46845 + error = -ECHILD;
46846 + goto exit;
46847 + }
46848 +#endif
46849 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46850 + error = -ENOENT;
46851 + goto exit;
46852 + }
46853
46854 error = -ENOTDIR;
46855 if (nd->flags & LOOKUP_DIRECTORY) {
46856 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46857 /* Negative dentry, just create the file */
46858 if (!dentry->d_inode) {
46859 umode_t mode = op->mode;
46860 +
46861 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46862 + error = -EACCES;
46863 + goto exit_mutex_unlock;
46864 + }
46865 +
46866 if (!IS_POSIXACL(dir->d_inode))
46867 mode &= ~current_umask();
46868 /*
46869 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46870 error = vfs_create(dir->d_inode, dentry, mode, nd);
46871 if (error)
46872 goto exit_mutex_unlock;
46873 + else
46874 + gr_handle_create(path->dentry, path->mnt);
46875 mutex_unlock(&dir->d_inode->i_mutex);
46876 dput(nd->path.dentry);
46877 nd->path.dentry = dentry;
46878 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46879 /*
46880 * It already exists.
46881 */
46882 +
46883 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46884 + error = -ENOENT;
46885 + goto exit_mutex_unlock;
46886 + }
46887 +
46888 + /* only check if O_CREAT is specified, all other checks need to go
46889 + into may_open */
46890 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46891 + error = -EACCES;
46892 + goto exit_mutex_unlock;
46893 + }
46894 +
46895 mutex_unlock(&dir->d_inode->i_mutex);
46896 audit_inode(pathname, path->dentry);
46897
46898 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46899 *path = nd.path;
46900 return dentry;
46901 eexist:
46902 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46903 + dput(dentry);
46904 + dentry = ERR_PTR(-ENOENT);
46905 + goto fail;
46906 + }
46907 dput(dentry);
46908 dentry = ERR_PTR(-EEXIST);
46909 fail:
46910 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46911 }
46912 EXPORT_SYMBOL(user_path_create);
46913
46914 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46915 +{
46916 + char *tmp = getname(pathname);
46917 + struct dentry *res;
46918 + if (IS_ERR(tmp))
46919 + return ERR_CAST(tmp);
46920 + res = kern_path_create(dfd, tmp, path, is_dir);
46921 + if (IS_ERR(res))
46922 + putname(tmp);
46923 + else
46924 + *to = tmp;
46925 + return res;
46926 +}
46927 +
46928 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46929 {
46930 int error = may_create(dir, dentry);
46931 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46932 error = mnt_want_write(path.mnt);
46933 if (error)
46934 goto out_dput;
46935 +
46936 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46937 + error = -EPERM;
46938 + goto out_drop_write;
46939 + }
46940 +
46941 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46942 + error = -EACCES;
46943 + goto out_drop_write;
46944 + }
46945 +
46946 error = security_path_mknod(&path, dentry, mode, dev);
46947 if (error)
46948 goto out_drop_write;
46949 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46950 }
46951 out_drop_write:
46952 mnt_drop_write(path.mnt);
46953 +
46954 + if (!error)
46955 + gr_handle_create(dentry, path.mnt);
46956 out_dput:
46957 dput(dentry);
46958 mutex_unlock(&path.dentry->d_inode->i_mutex);
46959 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46960 error = mnt_want_write(path.mnt);
46961 if (error)
46962 goto out_dput;
46963 +
46964 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46965 + error = -EACCES;
46966 + goto out_drop_write;
46967 + }
46968 +
46969 error = security_path_mkdir(&path, dentry, mode);
46970 if (error)
46971 goto out_drop_write;
46972 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46973 out_drop_write:
46974 mnt_drop_write(path.mnt);
46975 +
46976 + if (!error)
46977 + gr_handle_create(dentry, path.mnt);
46978 out_dput:
46979 dput(dentry);
46980 mutex_unlock(&path.dentry->d_inode->i_mutex);
46981 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46982 char * name;
46983 struct dentry *dentry;
46984 struct nameidata nd;
46985 + ino_t saved_ino = 0;
46986 + dev_t saved_dev = 0;
46987
46988 error = user_path_parent(dfd, pathname, &nd, &name);
46989 if (error)
46990 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46991 error = -ENOENT;
46992 goto exit3;
46993 }
46994 +
46995 + saved_ino = dentry->d_inode->i_ino;
46996 + saved_dev = gr_get_dev_from_dentry(dentry);
46997 +
46998 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46999 + error = -EACCES;
47000 + goto exit3;
47001 + }
47002 +
47003 error = mnt_want_write(nd.path.mnt);
47004 if (error)
47005 goto exit3;
47006 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47007 if (error)
47008 goto exit4;
47009 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47010 + if (!error && (saved_dev || saved_ino))
47011 + gr_handle_delete(saved_ino, saved_dev);
47012 exit4:
47013 mnt_drop_write(nd.path.mnt);
47014 exit3:
47015 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47016 struct dentry *dentry;
47017 struct nameidata nd;
47018 struct inode *inode = NULL;
47019 + ino_t saved_ino = 0;
47020 + dev_t saved_dev = 0;
47021
47022 error = user_path_parent(dfd, pathname, &nd, &name);
47023 if (error)
47024 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47025 if (!inode)
47026 goto slashes;
47027 ihold(inode);
47028 +
47029 + if (inode->i_nlink <= 1) {
47030 + saved_ino = inode->i_ino;
47031 + saved_dev = gr_get_dev_from_dentry(dentry);
47032 + }
47033 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47034 + error = -EACCES;
47035 + goto exit2;
47036 + }
47037 +
47038 error = mnt_want_write(nd.path.mnt);
47039 if (error)
47040 goto exit2;
47041 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47042 if (error)
47043 goto exit3;
47044 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47045 + if (!error && (saved_ino || saved_dev))
47046 + gr_handle_delete(saved_ino, saved_dev);
47047 exit3:
47048 mnt_drop_write(nd.path.mnt);
47049 exit2:
47050 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47051 error = mnt_want_write(path.mnt);
47052 if (error)
47053 goto out_dput;
47054 +
47055 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47056 + error = -EACCES;
47057 + goto out_drop_write;
47058 + }
47059 +
47060 error = security_path_symlink(&path, dentry, from);
47061 if (error)
47062 goto out_drop_write;
47063 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47064 + if (!error)
47065 + gr_handle_create(dentry, path.mnt);
47066 out_drop_write:
47067 mnt_drop_write(path.mnt);
47068 out_dput:
47069 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47070 {
47071 struct dentry *new_dentry;
47072 struct path old_path, new_path;
47073 + char *to = NULL;
47074 int how = 0;
47075 int error;
47076
47077 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47078 if (error)
47079 return error;
47080
47081 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47082 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47083 error = PTR_ERR(new_dentry);
47084 if (IS_ERR(new_dentry))
47085 goto out;
47086 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47087 error = mnt_want_write(new_path.mnt);
47088 if (error)
47089 goto out_dput;
47090 +
47091 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47092 + old_path.dentry->d_inode,
47093 + old_path.dentry->d_inode->i_mode, to)) {
47094 + error = -EACCES;
47095 + goto out_drop_write;
47096 + }
47097 +
47098 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47099 + old_path.dentry, old_path.mnt, to)) {
47100 + error = -EACCES;
47101 + goto out_drop_write;
47102 + }
47103 +
47104 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47105 if (error)
47106 goto out_drop_write;
47107 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47108 + if (!error)
47109 + gr_handle_create(new_dentry, new_path.mnt);
47110 out_drop_write:
47111 mnt_drop_write(new_path.mnt);
47112 out_dput:
47113 + putname(to);
47114 dput(new_dentry);
47115 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47116 path_put(&new_path);
47117 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47118 if (new_dentry == trap)
47119 goto exit5;
47120
47121 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47122 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47123 + to);
47124 + if (error)
47125 + goto exit5;
47126 +
47127 error = mnt_want_write(oldnd.path.mnt);
47128 if (error)
47129 goto exit5;
47130 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47131 goto exit6;
47132 error = vfs_rename(old_dir->d_inode, old_dentry,
47133 new_dir->d_inode, new_dentry);
47134 + if (!error)
47135 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47136 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47137 exit6:
47138 mnt_drop_write(oldnd.path.mnt);
47139 exit5:
47140 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47141
47142 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47143 {
47144 + char tmpbuf[64];
47145 + const char *newlink;
47146 int len;
47147
47148 len = PTR_ERR(link);
47149 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47150 len = strlen(link);
47151 if (len > (unsigned) buflen)
47152 len = buflen;
47153 - if (copy_to_user(buffer, link, len))
47154 +
47155 + if (len < sizeof(tmpbuf)) {
47156 + memcpy(tmpbuf, link, len);
47157 + newlink = tmpbuf;
47158 + } else
47159 + newlink = link;
47160 +
47161 + if (copy_to_user(buffer, newlink, len))
47162 len = -EFAULT;
47163 out:
47164 return len;
47165 diff --git a/fs/namespace.c b/fs/namespace.c
47166 index e608199..9609cb9 100644
47167 --- a/fs/namespace.c
47168 +++ b/fs/namespace.c
47169 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47170 if (!(sb->s_flags & MS_RDONLY))
47171 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47172 up_write(&sb->s_umount);
47173 +
47174 + gr_log_remount(mnt->mnt_devname, retval);
47175 +
47176 return retval;
47177 }
47178
47179 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47180 br_write_unlock(vfsmount_lock);
47181 up_write(&namespace_sem);
47182 release_mounts(&umount_list);
47183 +
47184 + gr_log_unmount(mnt->mnt_devname, retval);
47185 +
47186 return retval;
47187 }
47188
47189 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47190 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47191 MS_STRICTATIME);
47192
47193 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47194 + retval = -EPERM;
47195 + goto dput_out;
47196 + }
47197 +
47198 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47199 + retval = -EPERM;
47200 + goto dput_out;
47201 + }
47202 +
47203 if (flags & MS_REMOUNT)
47204 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47205 data_page);
47206 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47207 dev_name, data_page);
47208 dput_out:
47209 path_put(&path);
47210 +
47211 + gr_log_mount(dev_name, dir_name, retval);
47212 +
47213 return retval;
47214 }
47215
47216 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47217 if (error)
47218 goto out2;
47219
47220 + if (gr_handle_chroot_pivot()) {
47221 + error = -EPERM;
47222 + goto out2;
47223 + }
47224 +
47225 get_fs_root(current->fs, &root);
47226 error = lock_mount(&old);
47227 if (error)
47228 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47229 index 32c0658..b1c2045e 100644
47230 --- a/fs/ncpfs/ncplib_kernel.h
47231 +++ b/fs/ncpfs/ncplib_kernel.h
47232 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47233 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47234 const unsigned char *, unsigned int, int);
47235 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47236 - const unsigned char *, unsigned int, int);
47237 + const unsigned char *, unsigned int, int) __size_overflow(5);
47238
47239 #define NCP_ESC ':'
47240 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47241 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47242 int ncp__io2vol(unsigned char *, unsigned int *,
47243 const unsigned char *, unsigned int, int);
47244 int ncp__vol2io(unsigned char *, unsigned int *,
47245 - const unsigned char *, unsigned int, int);
47246 + const unsigned char *, unsigned int, int) __size_overflow(5);
47247
47248 #define NCP_IO_TABLE(sb) NULL
47249 #define ncp_tolower(t, c) tolower(c)
47250 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47251 index f649fba..236bf92 100644
47252 --- a/fs/nfs/inode.c
47253 +++ b/fs/nfs/inode.c
47254 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47255 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47256 nfsi->attrtimeo_timestamp = jiffies;
47257
47258 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47259 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47260 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47261 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47262 else
47263 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47264 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47265 }
47266
47267 -static atomic_long_t nfs_attr_generation_counter;
47268 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47269
47270 static unsigned long nfs_read_attr_generation_counter(void)
47271 {
47272 - return atomic_long_read(&nfs_attr_generation_counter);
47273 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47274 }
47275
47276 unsigned long nfs_inc_attr_generation_counter(void)
47277 {
47278 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47279 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47280 }
47281
47282 void nfs_fattr_init(struct nfs_fattr *fattr)
47283 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47284 index edf6d3e..bdd1da7 100644
47285 --- a/fs/nfsd/vfs.c
47286 +++ b/fs/nfsd/vfs.c
47287 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47288 } else {
47289 oldfs = get_fs();
47290 set_fs(KERNEL_DS);
47291 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47292 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47293 set_fs(oldfs);
47294 }
47295
47296 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47297
47298 /* Write the data. */
47299 oldfs = get_fs(); set_fs(KERNEL_DS);
47300 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47301 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47302 set_fs(oldfs);
47303 if (host_err < 0)
47304 goto out_nfserr;
47305 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47306 */
47307
47308 oldfs = get_fs(); set_fs(KERNEL_DS);
47309 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47310 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47311 set_fs(oldfs);
47312
47313 if (host_err < 0)
47314 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47315 index 3568c8a..e0240d8 100644
47316 --- a/fs/notify/fanotify/fanotify_user.c
47317 +++ b/fs/notify/fanotify/fanotify_user.c
47318 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47319 goto out_close_fd;
47320
47321 ret = -EFAULT;
47322 - if (copy_to_user(buf, &fanotify_event_metadata,
47323 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47324 + copy_to_user(buf, &fanotify_event_metadata,
47325 fanotify_event_metadata.event_len))
47326 goto out_kill_access_response;
47327
47328 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47329 index ee18815..7aa5d01 100644
47330 --- a/fs/notify/notification.c
47331 +++ b/fs/notify/notification.c
47332 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47333 * get set to 0 so it will never get 'freed'
47334 */
47335 static struct fsnotify_event *q_overflow_event;
47336 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47337 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47338
47339 /**
47340 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47341 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47342 */
47343 u32 fsnotify_get_cookie(void)
47344 {
47345 - return atomic_inc_return(&fsnotify_sync_cookie);
47346 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47347 }
47348 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47349
47350 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47351 index 99e3610..02c1068 100644
47352 --- a/fs/ntfs/dir.c
47353 +++ b/fs/ntfs/dir.c
47354 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47355 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47356 ~(s64)(ndir->itype.index.block_size - 1)));
47357 /* Bounds checks. */
47358 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47359 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47360 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47361 "inode 0x%lx or driver bug.", vdir->i_ino);
47362 goto err_out;
47363 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47364 index c587e2d..3641eaa 100644
47365 --- a/fs/ntfs/file.c
47366 +++ b/fs/ntfs/file.c
47367 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47368 #endif /* NTFS_RW */
47369 };
47370
47371 -const struct file_operations ntfs_empty_file_ops = {};
47372 +const struct file_operations ntfs_empty_file_ops __read_only;
47373
47374 -const struct inode_operations ntfs_empty_inode_ops = {};
47375 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47376 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47377 index 210c352..a174f83 100644
47378 --- a/fs/ocfs2/localalloc.c
47379 +++ b/fs/ocfs2/localalloc.c
47380 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47381 goto bail;
47382 }
47383
47384 - atomic_inc(&osb->alloc_stats.moves);
47385 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47386
47387 bail:
47388 if (handle)
47389 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47390 index d355e6e..578d905 100644
47391 --- a/fs/ocfs2/ocfs2.h
47392 +++ b/fs/ocfs2/ocfs2.h
47393 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47394
47395 struct ocfs2_alloc_stats
47396 {
47397 - atomic_t moves;
47398 - atomic_t local_data;
47399 - atomic_t bitmap_data;
47400 - atomic_t bg_allocs;
47401 - atomic_t bg_extends;
47402 + atomic_unchecked_t moves;
47403 + atomic_unchecked_t local_data;
47404 + atomic_unchecked_t bitmap_data;
47405 + atomic_unchecked_t bg_allocs;
47406 + atomic_unchecked_t bg_extends;
47407 };
47408
47409 enum ocfs2_local_alloc_state
47410 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47411 index ba5d97e..c77db25 100644
47412 --- a/fs/ocfs2/suballoc.c
47413 +++ b/fs/ocfs2/suballoc.c
47414 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47415 mlog_errno(status);
47416 goto bail;
47417 }
47418 - atomic_inc(&osb->alloc_stats.bg_extends);
47419 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47420
47421 /* You should never ask for this much metadata */
47422 BUG_ON(bits_wanted >
47423 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47424 mlog_errno(status);
47425 goto bail;
47426 }
47427 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47428 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47429
47430 *suballoc_loc = res.sr_bg_blkno;
47431 *suballoc_bit_start = res.sr_bit_offset;
47432 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47433 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47434 res->sr_bits);
47435
47436 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47437 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47438
47439 BUG_ON(res->sr_bits != 1);
47440
47441 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47442 mlog_errno(status);
47443 goto bail;
47444 }
47445 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47446 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47447
47448 BUG_ON(res.sr_bits != 1);
47449
47450 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47451 cluster_start,
47452 num_clusters);
47453 if (!status)
47454 - atomic_inc(&osb->alloc_stats.local_data);
47455 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47456 } else {
47457 if (min_clusters > (osb->bitmap_cpg - 1)) {
47458 /* The only paths asking for contiguousness
47459 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47460 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47461 res.sr_bg_blkno,
47462 res.sr_bit_offset);
47463 - atomic_inc(&osb->alloc_stats.bitmap_data);
47464 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47465 *num_clusters = res.sr_bits;
47466 }
47467 }
47468 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47469 index 604e12c..8426483 100644
47470 --- a/fs/ocfs2/super.c
47471 +++ b/fs/ocfs2/super.c
47472 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47473 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47474 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47475 "Stats",
47476 - atomic_read(&osb->alloc_stats.bitmap_data),
47477 - atomic_read(&osb->alloc_stats.local_data),
47478 - atomic_read(&osb->alloc_stats.bg_allocs),
47479 - atomic_read(&osb->alloc_stats.moves),
47480 - atomic_read(&osb->alloc_stats.bg_extends));
47481 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47482 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47483 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47484 + atomic_read_unchecked(&osb->alloc_stats.moves),
47485 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47486
47487 out += snprintf(buf + out, len - out,
47488 "%10s => State: %u Descriptor: %llu Size: %u bits "
47489 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47490 spin_lock_init(&osb->osb_xattr_lock);
47491 ocfs2_init_steal_slots(osb);
47492
47493 - atomic_set(&osb->alloc_stats.moves, 0);
47494 - atomic_set(&osb->alloc_stats.local_data, 0);
47495 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47496 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47497 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47498 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47499 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47500 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47501 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47502 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47503
47504 /* Copy the blockcheck stats from the superblock probe */
47505 osb->osb_ecc_stats = *stats;
47506 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47507 index 5d22872..523db20 100644
47508 --- a/fs/ocfs2/symlink.c
47509 +++ b/fs/ocfs2/symlink.c
47510 @@ -142,7 +142,7 @@ bail:
47511
47512 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47513 {
47514 - char *link = nd_get_link(nd);
47515 + const char *link = nd_get_link(nd);
47516 if (!IS_ERR(link))
47517 kfree(link);
47518 }
47519 diff --git a/fs/open.c b/fs/open.c
47520 index 77becc0..aad7bd9 100644
47521 --- a/fs/open.c
47522 +++ b/fs/open.c
47523 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47524 error = locks_verify_truncate(inode, NULL, length);
47525 if (!error)
47526 error = security_path_truncate(&path);
47527 +
47528 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47529 + error = -EACCES;
47530 +
47531 if (!error)
47532 error = do_truncate(path.dentry, length, 0, NULL);
47533
47534 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47535 if (__mnt_is_readonly(path.mnt))
47536 res = -EROFS;
47537
47538 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47539 + res = -EACCES;
47540 +
47541 out_path_release:
47542 path_put(&path);
47543 out:
47544 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47545 if (error)
47546 goto dput_and_out;
47547
47548 + gr_log_chdir(path.dentry, path.mnt);
47549 +
47550 set_fs_pwd(current->fs, &path);
47551
47552 dput_and_out:
47553 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47554 goto out_putf;
47555
47556 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47557 +
47558 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47559 + error = -EPERM;
47560 +
47561 + if (!error)
47562 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47563 +
47564 if (!error)
47565 set_fs_pwd(current->fs, &file->f_path);
47566 out_putf:
47567 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47568 if (error)
47569 goto dput_and_out;
47570
47571 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47572 + goto dput_and_out;
47573 +
47574 set_fs_root(current->fs, &path);
47575 +
47576 + gr_handle_chroot_chdir(&path);
47577 +
47578 error = 0;
47579 dput_and_out:
47580 path_put(&path);
47581 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47582 if (error)
47583 return error;
47584 mutex_lock(&inode->i_mutex);
47585 +
47586 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47587 + error = -EACCES;
47588 + goto out_unlock;
47589 + }
47590 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47591 + error = -EACCES;
47592 + goto out_unlock;
47593 + }
47594 +
47595 error = security_path_chmod(path, mode);
47596 if (error)
47597 goto out_unlock;
47598 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47599 int error;
47600 struct iattr newattrs;
47601
47602 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47603 + return -EACCES;
47604 +
47605 newattrs.ia_valid = ATTR_CTIME;
47606 if (user != (uid_t) -1) {
47607 newattrs.ia_valid |= ATTR_UID;
47608 diff --git a/fs/pipe.c b/fs/pipe.c
47609 index a932ced..6495412 100644
47610 --- a/fs/pipe.c
47611 +++ b/fs/pipe.c
47612 @@ -420,9 +420,9 @@ redo:
47613 }
47614 if (bufs) /* More to do? */
47615 continue;
47616 - if (!pipe->writers)
47617 + if (!atomic_read(&pipe->writers))
47618 break;
47619 - if (!pipe->waiting_writers) {
47620 + if (!atomic_read(&pipe->waiting_writers)) {
47621 /* syscall merging: Usually we must not sleep
47622 * if O_NONBLOCK is set, or if we got some data.
47623 * But if a writer sleeps in kernel space, then
47624 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47625 mutex_lock(&inode->i_mutex);
47626 pipe = inode->i_pipe;
47627
47628 - if (!pipe->readers) {
47629 + if (!atomic_read(&pipe->readers)) {
47630 send_sig(SIGPIPE, current, 0);
47631 ret = -EPIPE;
47632 goto out;
47633 @@ -530,7 +530,7 @@ redo1:
47634 for (;;) {
47635 int bufs;
47636
47637 - if (!pipe->readers) {
47638 + if (!atomic_read(&pipe->readers)) {
47639 send_sig(SIGPIPE, current, 0);
47640 if (!ret)
47641 ret = -EPIPE;
47642 @@ -616,9 +616,9 @@ redo2:
47643 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47644 do_wakeup = 0;
47645 }
47646 - pipe->waiting_writers++;
47647 + atomic_inc(&pipe->waiting_writers);
47648 pipe_wait(pipe);
47649 - pipe->waiting_writers--;
47650 + atomic_dec(&pipe->waiting_writers);
47651 }
47652 out:
47653 mutex_unlock(&inode->i_mutex);
47654 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47655 mask = 0;
47656 if (filp->f_mode & FMODE_READ) {
47657 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47658 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47659 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47660 mask |= POLLHUP;
47661 }
47662
47663 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47664 * Most Unices do not set POLLERR for FIFOs but on Linux they
47665 * behave exactly like pipes for poll().
47666 */
47667 - if (!pipe->readers)
47668 + if (!atomic_read(&pipe->readers))
47669 mask |= POLLERR;
47670 }
47671
47672 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47673
47674 mutex_lock(&inode->i_mutex);
47675 pipe = inode->i_pipe;
47676 - pipe->readers -= decr;
47677 - pipe->writers -= decw;
47678 + atomic_sub(decr, &pipe->readers);
47679 + atomic_sub(decw, &pipe->writers);
47680
47681 - if (!pipe->readers && !pipe->writers) {
47682 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47683 free_pipe_info(inode);
47684 } else {
47685 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47686 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47687
47688 if (inode->i_pipe) {
47689 ret = 0;
47690 - inode->i_pipe->readers++;
47691 + atomic_inc(&inode->i_pipe->readers);
47692 }
47693
47694 mutex_unlock(&inode->i_mutex);
47695 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47696
47697 if (inode->i_pipe) {
47698 ret = 0;
47699 - inode->i_pipe->writers++;
47700 + atomic_inc(&inode->i_pipe->writers);
47701 }
47702
47703 mutex_unlock(&inode->i_mutex);
47704 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47705 if (inode->i_pipe) {
47706 ret = 0;
47707 if (filp->f_mode & FMODE_READ)
47708 - inode->i_pipe->readers++;
47709 + atomic_inc(&inode->i_pipe->readers);
47710 if (filp->f_mode & FMODE_WRITE)
47711 - inode->i_pipe->writers++;
47712 + atomic_inc(&inode->i_pipe->writers);
47713 }
47714
47715 mutex_unlock(&inode->i_mutex);
47716 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47717 inode->i_pipe = NULL;
47718 }
47719
47720 -static struct vfsmount *pipe_mnt __read_mostly;
47721 +struct vfsmount *pipe_mnt __read_mostly;
47722
47723 /*
47724 * pipefs_dname() is called from d_path().
47725 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47726 goto fail_iput;
47727 inode->i_pipe = pipe;
47728
47729 - pipe->readers = pipe->writers = 1;
47730 + atomic_set(&pipe->readers, 1);
47731 + atomic_set(&pipe->writers, 1);
47732 inode->i_fop = &rdwr_pipefifo_fops;
47733
47734 /*
47735 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47736 index 15af622..0e9f4467 100644
47737 --- a/fs/proc/Kconfig
47738 +++ b/fs/proc/Kconfig
47739 @@ -30,12 +30,12 @@ config PROC_FS
47740
47741 config PROC_KCORE
47742 bool "/proc/kcore support" if !ARM
47743 - depends on PROC_FS && MMU
47744 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47745
47746 config PROC_VMCORE
47747 bool "/proc/vmcore support"
47748 - depends on PROC_FS && CRASH_DUMP
47749 - default y
47750 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47751 + default n
47752 help
47753 Exports the dump image of crashed kernel in ELF format.
47754
47755 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47756 limited in memory.
47757
47758 config PROC_PAGE_MONITOR
47759 - default y
47760 - depends on PROC_FS && MMU
47761 + default n
47762 + depends on PROC_FS && MMU && !GRKERNSEC
47763 bool "Enable /proc page monitoring" if EXPERT
47764 help
47765 Various /proc files exist to monitor process memory utilization:
47766 diff --git a/fs/proc/array.c b/fs/proc/array.c
47767 index c602b8d..a7de642 100644
47768 --- a/fs/proc/array.c
47769 +++ b/fs/proc/array.c
47770 @@ -60,6 +60,7 @@
47771 #include <linux/tty.h>
47772 #include <linux/string.h>
47773 #include <linux/mman.h>
47774 +#include <linux/grsecurity.h>
47775 #include <linux/proc_fs.h>
47776 #include <linux/ioport.h>
47777 #include <linux/uaccess.h>
47778 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47779 seq_putc(m, '\n');
47780 }
47781
47782 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47783 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47784 +{
47785 + if (p->mm)
47786 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47787 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47788 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47789 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47790 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47791 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47792 + else
47793 + seq_printf(m, "PaX:\t-----\n");
47794 +}
47795 +#endif
47796 +
47797 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47798 struct pid *pid, struct task_struct *task)
47799 {
47800 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47801 task_cpus_allowed(m, task);
47802 cpuset_task_status_allowed(m, task);
47803 task_context_switch_counts(m, task);
47804 +
47805 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47806 + task_pax(m, task);
47807 +#endif
47808 +
47809 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47810 + task_grsec_rbac(m, task);
47811 +#endif
47812 +
47813 return 0;
47814 }
47815
47816 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47817 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47818 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47819 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47820 +#endif
47821 +
47822 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47823 struct pid *pid, struct task_struct *task, int whole)
47824 {
47825 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47826 char tcomm[sizeof(task->comm)];
47827 unsigned long flags;
47828
47829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47830 + if (current->exec_id != m->exec_id) {
47831 + gr_log_badprocpid("stat");
47832 + return 0;
47833 + }
47834 +#endif
47835 +
47836 state = *get_task_state(task);
47837 vsize = eip = esp = 0;
47838 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47839 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47840 gtime = task->gtime;
47841 }
47842
47843 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47844 + if (PAX_RAND_FLAGS(mm)) {
47845 + eip = 0;
47846 + esp = 0;
47847 + wchan = 0;
47848 + }
47849 +#endif
47850 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47851 + wchan = 0;
47852 + eip =0;
47853 + esp =0;
47854 +#endif
47855 +
47856 /* scale priority and nice values from timeslices to -20..20 */
47857 /* to make it look like a "normal" Unix priority/nice value */
47858 priority = task_prio(task);
47859 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47860 vsize,
47861 mm ? get_mm_rss(mm) : 0,
47862 rsslim,
47863 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47864 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47865 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47866 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47867 +#else
47868 mm ? (permitted ? mm->start_code : 1) : 0,
47869 mm ? (permitted ? mm->end_code : 1) : 0,
47870 (permitted && mm) ? mm->start_stack : 0,
47871 +#endif
47872 esp,
47873 eip,
47874 /* The signal information here is obsolete.
47875 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47876 struct pid *pid, struct task_struct *task)
47877 {
47878 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47879 - struct mm_struct *mm = get_task_mm(task);
47880 + struct mm_struct *mm;
47881
47882 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47883 + if (current->exec_id != m->exec_id) {
47884 + gr_log_badprocpid("statm");
47885 + return 0;
47886 + }
47887 +#endif
47888 + mm = get_task_mm(task);
47889 if (mm) {
47890 size = task_statm(mm, &shared, &text, &data, &resident);
47891 mmput(mm);
47892 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47893
47894 return 0;
47895 }
47896 +
47897 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47898 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47899 +{
47900 + u32 curr_ip = 0;
47901 + unsigned long flags;
47902 +
47903 + if (lock_task_sighand(task, &flags)) {
47904 + curr_ip = task->signal->curr_ip;
47905 + unlock_task_sighand(task, &flags);
47906 + }
47907 +
47908 + return sprintf(buffer, "%pI4\n", &curr_ip);
47909 +}
47910 +#endif
47911 diff --git a/fs/proc/base.c b/fs/proc/base.c
47912 index d4548dd..d101f84 100644
47913 --- a/fs/proc/base.c
47914 +++ b/fs/proc/base.c
47915 @@ -109,6 +109,14 @@ struct pid_entry {
47916 union proc_op op;
47917 };
47918
47919 +struct getdents_callback {
47920 + struct linux_dirent __user * current_dir;
47921 + struct linux_dirent __user * previous;
47922 + struct file * file;
47923 + int count;
47924 + int error;
47925 +};
47926 +
47927 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47928 .name = (NAME), \
47929 .len = sizeof(NAME) - 1, \
47930 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47931 if (!mm->arg_end)
47932 goto out_mm; /* Shh! No looking before we're done */
47933
47934 + if (gr_acl_handle_procpidmem(task))
47935 + goto out_mm;
47936 +
47937 len = mm->arg_end - mm->arg_start;
47938
47939 if (len > PAGE_SIZE)
47940 @@ -240,12 +251,28 @@ out:
47941 return res;
47942 }
47943
47944 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47945 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47946 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47947 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47948 +#endif
47949 +
47950 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47951 {
47952 struct mm_struct *mm = mm_for_maps(task);
47953 int res = PTR_ERR(mm);
47954 if (mm && !IS_ERR(mm)) {
47955 unsigned int nwords = 0;
47956 +
47957 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47958 + /* allow if we're currently ptracing this task */
47959 + if (PAX_RAND_FLAGS(mm) &&
47960 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47961 + mmput(mm);
47962 + return 0;
47963 + }
47964 +#endif
47965 +
47966 do {
47967 nwords += 2;
47968 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47969 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47970 }
47971
47972
47973 -#ifdef CONFIG_KALLSYMS
47974 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47975 /*
47976 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47977 * Returns the resolved symbol. If that fails, simply return the address.
47978 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47979 mutex_unlock(&task->signal->cred_guard_mutex);
47980 }
47981
47982 -#ifdef CONFIG_STACKTRACE
47983 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47984
47985 #define MAX_STACK_TRACE_DEPTH 64
47986
47987 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47988 return count;
47989 }
47990
47991 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47992 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47993 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47994 {
47995 long nr;
47996 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47997 /************************************************************************/
47998
47999 /* permission checks */
48000 -static int proc_fd_access_allowed(struct inode *inode)
48001 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48002 {
48003 struct task_struct *task;
48004 int allowed = 0;
48005 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48006 */
48007 task = get_proc_task(inode);
48008 if (task) {
48009 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48010 + if (log)
48011 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48012 + else
48013 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48014 put_task_struct(task);
48015 }
48016 return allowed;
48017 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48018 struct task_struct *task,
48019 int hide_pid_min)
48020 {
48021 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48022 + return false;
48023 +
48024 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48025 + rcu_read_lock();
48026 + {
48027 + const struct cred *tmpcred = current_cred();
48028 + const struct cred *cred = __task_cred(task);
48029 +
48030 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48031 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48032 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48033 +#endif
48034 + ) {
48035 + rcu_read_unlock();
48036 + return true;
48037 + }
48038 + }
48039 + rcu_read_unlock();
48040 +
48041 + if (!pid->hide_pid)
48042 + return false;
48043 +#endif
48044 +
48045 if (pid->hide_pid < hide_pid_min)
48046 return true;
48047 if (in_group_p(pid->pid_gid))
48048 return true;
48049 +
48050 return ptrace_may_access(task, PTRACE_MODE_READ);
48051 }
48052
48053 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48054 put_task_struct(task);
48055
48056 if (!has_perms) {
48057 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48058 + {
48059 +#else
48060 if (pid->hide_pid == 2) {
48061 +#endif
48062 /*
48063 * Let's make getdents(), stat(), and open()
48064 * consistent with each other. If a process
48065 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48066 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48067 file->private_data = mm;
48068
48069 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48070 + file->f_version = current->exec_id;
48071 +#endif
48072 +
48073 return 0;
48074 }
48075
48076 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48077 ssize_t copied;
48078 char *page;
48079
48080 +#ifdef CONFIG_GRKERNSEC
48081 + if (write)
48082 + return -EPERM;
48083 +#endif
48084 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48085 + if (file->f_version != current->exec_id) {
48086 + gr_log_badprocpid("mem");
48087 + return 0;
48088 + }
48089 +#endif
48090 +
48091 if (!mm)
48092 return 0;
48093
48094 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48095 if (!task)
48096 goto out_no_task;
48097
48098 + if (gr_acl_handle_procpidmem(task))
48099 + goto out;
48100 +
48101 ret = -ENOMEM;
48102 page = (char *)__get_free_page(GFP_TEMPORARY);
48103 if (!page)
48104 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48105 path_put(&nd->path);
48106
48107 /* Are we allowed to snoop on the tasks file descriptors? */
48108 - if (!proc_fd_access_allowed(inode))
48109 + if (!proc_fd_access_allowed(inode, 0))
48110 goto out;
48111
48112 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48113 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48114 struct path path;
48115
48116 /* Are we allowed to snoop on the tasks file descriptors? */
48117 - if (!proc_fd_access_allowed(inode))
48118 - goto out;
48119 + /* logging this is needed for learning on chromium to work properly,
48120 + but we don't want to flood the logs from 'ps' which does a readlink
48121 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48122 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48123 + */
48124 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48125 + if (!proc_fd_access_allowed(inode,0))
48126 + goto out;
48127 + } else {
48128 + if (!proc_fd_access_allowed(inode,1))
48129 + goto out;
48130 + }
48131
48132 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48133 if (error)
48134 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48135 rcu_read_lock();
48136 cred = __task_cred(task);
48137 inode->i_uid = cred->euid;
48138 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48139 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48140 +#else
48141 inode->i_gid = cred->egid;
48142 +#endif
48143 rcu_read_unlock();
48144 }
48145 security_task_to_inode(task, inode);
48146 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48147 return -ENOENT;
48148 }
48149 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48150 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48151 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48152 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48153 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48154 +#endif
48155 task_dumpable(task)) {
48156 cred = __task_cred(task);
48157 stat->uid = cred->euid;
48158 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48159 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48160 +#else
48161 stat->gid = cred->egid;
48162 +#endif
48163 }
48164 }
48165 rcu_read_unlock();
48166 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48167
48168 if (task) {
48169 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48170 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48171 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48172 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48173 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48174 +#endif
48175 task_dumpable(task)) {
48176 rcu_read_lock();
48177 cred = __task_cred(task);
48178 inode->i_uid = cred->euid;
48179 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48180 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48181 +#else
48182 inode->i_gid = cred->egid;
48183 +#endif
48184 rcu_read_unlock();
48185 } else {
48186 inode->i_uid = 0;
48187 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48188 int fd = proc_fd(inode);
48189
48190 if (task) {
48191 - files = get_files_struct(task);
48192 + if (!gr_acl_handle_procpidmem(task))
48193 + files = get_files_struct(task);
48194 put_task_struct(task);
48195 }
48196 if (files) {
48197 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48198 */
48199 static int proc_fd_permission(struct inode *inode, int mask)
48200 {
48201 + struct task_struct *task;
48202 int rv = generic_permission(inode, mask);
48203 - if (rv == 0)
48204 - return 0;
48205 +
48206 if (task_pid(current) == proc_pid(inode))
48207 rv = 0;
48208 +
48209 + task = get_proc_task(inode);
48210 + if (task == NULL)
48211 + return rv;
48212 +
48213 + if (gr_acl_handle_procpidmem(task))
48214 + rv = -EACCES;
48215 +
48216 + put_task_struct(task);
48217 +
48218 return rv;
48219 }
48220
48221 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48222 if (!task)
48223 goto out_no_task;
48224
48225 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48226 + goto out;
48227 +
48228 /*
48229 * Yes, it does not scale. And it should not. Don't add
48230 * new entries into /proc/<tgid>/ without very good reasons.
48231 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48232 if (!task)
48233 goto out_no_task;
48234
48235 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48236 + goto out;
48237 +
48238 ret = 0;
48239 i = filp->f_pos;
48240 switch (i) {
48241 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48242 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48243 void *cookie)
48244 {
48245 - char *s = nd_get_link(nd);
48246 + const char *s = nd_get_link(nd);
48247 if (!IS_ERR(s))
48248 __putname(s);
48249 }
48250 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48251 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_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 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_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 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48273 #ifdef CONFIG_HARDWALL
48274 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48275 #endif
48276 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48277 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48278 +#endif
48279 };
48280
48281 static int proc_tgid_base_readdir(struct file * filp,
48282 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48283 if (!inode)
48284 goto out;
48285
48286 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48287 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48288 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48289 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48290 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48291 +#else
48292 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48293 +#endif
48294 inode->i_op = &proc_tgid_base_inode_operations;
48295 inode->i_fop = &proc_tgid_base_operations;
48296 inode->i_flags|=S_IMMUTABLE;
48297 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48298 if (!task)
48299 goto out;
48300
48301 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48302 + goto out_put_task;
48303 +
48304 result = proc_pid_instantiate(dir, dentry, task, NULL);
48305 +out_put_task:
48306 put_task_struct(task);
48307 out:
48308 return result;
48309 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48310 static int fake_filldir(void *buf, const char *name, int namelen,
48311 loff_t offset, u64 ino, unsigned d_type)
48312 {
48313 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48314 + __buf->error = -EINVAL;
48315 return 0;
48316 }
48317
48318 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48319 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48320 #endif
48321 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48322 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48323 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48324 INF("syscall", S_IRUGO, proc_pid_syscall),
48325 #endif
48326 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48327 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48328 #ifdef CONFIG_SECURITY
48329 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48330 #endif
48331 -#ifdef CONFIG_KALLSYMS
48332 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48333 INF("wchan", S_IRUGO, proc_pid_wchan),
48334 #endif
48335 -#ifdef CONFIG_STACKTRACE
48336 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48337 ONE("stack", S_IRUGO, proc_pid_stack),
48338 #endif
48339 #ifdef CONFIG_SCHEDSTATS
48340 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48341 index 82676e3..5f8518a 100644
48342 --- a/fs/proc/cmdline.c
48343 +++ b/fs/proc/cmdline.c
48344 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48345
48346 static int __init proc_cmdline_init(void)
48347 {
48348 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48349 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48350 +#else
48351 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48352 +#endif
48353 return 0;
48354 }
48355 module_init(proc_cmdline_init);
48356 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48357 index b143471..bb105e5 100644
48358 --- a/fs/proc/devices.c
48359 +++ b/fs/proc/devices.c
48360 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48361
48362 static int __init proc_devices_init(void)
48363 {
48364 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48365 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48366 +#else
48367 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48368 +#endif
48369 return 0;
48370 }
48371 module_init(proc_devices_init);
48372 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48373 index 84fd323..f698a32 100644
48374 --- a/fs/proc/inode.c
48375 +++ b/fs/proc/inode.c
48376 @@ -21,12 +21,18 @@
48377 #include <linux/seq_file.h>
48378 #include <linux/slab.h>
48379 #include <linux/mount.h>
48380 +#include <linux/grsecurity.h>
48381
48382 #include <asm/system.h>
48383 #include <asm/uaccess.h>
48384
48385 #include "internal.h"
48386
48387 +#ifdef CONFIG_PROC_SYSCTL
48388 +extern const struct inode_operations proc_sys_inode_operations;
48389 +extern const struct inode_operations proc_sys_dir_operations;
48390 +#endif
48391 +
48392 static void proc_evict_inode(struct inode *inode)
48393 {
48394 struct proc_dir_entry *de;
48395 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48396 ns_ops = PROC_I(inode)->ns_ops;
48397 if (ns_ops && ns_ops->put)
48398 ns_ops->put(PROC_I(inode)->ns);
48399 +
48400 +#ifdef CONFIG_PROC_SYSCTL
48401 + if (inode->i_op == &proc_sys_inode_operations ||
48402 + inode->i_op == &proc_sys_dir_operations)
48403 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48404 +#endif
48405 +
48406 }
48407
48408 static struct kmem_cache * proc_inode_cachep;
48409 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48410 if (de->mode) {
48411 inode->i_mode = de->mode;
48412 inode->i_uid = de->uid;
48413 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48414 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48415 +#else
48416 inode->i_gid = de->gid;
48417 +#endif
48418 }
48419 if (de->size)
48420 inode->i_size = de->size;
48421 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48422 index 2925775..4f08fae 100644
48423 --- a/fs/proc/internal.h
48424 +++ b/fs/proc/internal.h
48425 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48426 struct pid *pid, struct task_struct *task);
48427 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48428 struct pid *pid, struct task_struct *task);
48429 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48430 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48431 +#endif
48432 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48433
48434 extern const struct file_operations proc_maps_operations;
48435 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48436 index d245cb2..f4e8498 100644
48437 --- a/fs/proc/kcore.c
48438 +++ b/fs/proc/kcore.c
48439 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48440 * the addresses in the elf_phdr on our list.
48441 */
48442 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48443 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48444 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48445 + if (tsz > buflen)
48446 tsz = buflen;
48447 -
48448 +
48449 while (buflen) {
48450 struct kcore_list *m;
48451
48452 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48453 kfree(elf_buf);
48454 } else {
48455 if (kern_addr_valid(start)) {
48456 - unsigned long n;
48457 + char *elf_buf;
48458 + mm_segment_t oldfs;
48459
48460 - n = copy_to_user(buffer, (char *)start, tsz);
48461 - /*
48462 - * We cannot distingush between fault on source
48463 - * and fault on destination. When this happens
48464 - * we clear too and hope it will trigger the
48465 - * EFAULT again.
48466 - */
48467 - if (n) {
48468 - if (clear_user(buffer + tsz - n,
48469 - n))
48470 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48471 + if (!elf_buf)
48472 + return -ENOMEM;
48473 + oldfs = get_fs();
48474 + set_fs(KERNEL_DS);
48475 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48476 + set_fs(oldfs);
48477 + if (copy_to_user(buffer, elf_buf, tsz)) {
48478 + kfree(elf_buf);
48479 return -EFAULT;
48480 + }
48481 }
48482 + set_fs(oldfs);
48483 + kfree(elf_buf);
48484 } else {
48485 if (clear_user(buffer, tsz))
48486 return -EFAULT;
48487 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48488
48489 static int open_kcore(struct inode *inode, struct file *filp)
48490 {
48491 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48492 + return -EPERM;
48493 +#endif
48494 if (!capable(CAP_SYS_RAWIO))
48495 return -EPERM;
48496 if (kcore_need_update)
48497 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48498 index 80e4645..53e5fcf 100644
48499 --- a/fs/proc/meminfo.c
48500 +++ b/fs/proc/meminfo.c
48501 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48502 vmi.used >> 10,
48503 vmi.largest_chunk >> 10
48504 #ifdef CONFIG_MEMORY_FAILURE
48505 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48506 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48507 #endif
48508 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48509 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48510 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48511 index b1822dd..df622cb 100644
48512 --- a/fs/proc/nommu.c
48513 +++ b/fs/proc/nommu.c
48514 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48515 if (len < 1)
48516 len = 1;
48517 seq_printf(m, "%*c", len, ' ');
48518 - seq_path(m, &file->f_path, "");
48519 + seq_path(m, &file->f_path, "\n\\");
48520 }
48521
48522 seq_putc(m, '\n');
48523 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48524 index 06e1cc1..177cd98 100644
48525 --- a/fs/proc/proc_net.c
48526 +++ b/fs/proc/proc_net.c
48527 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48528 struct task_struct *task;
48529 struct nsproxy *ns;
48530 struct net *net = NULL;
48531 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48532 + const struct cred *cred = current_cred();
48533 +#endif
48534 +
48535 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48536 + if (cred->fsuid)
48537 + return net;
48538 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48539 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48540 + return net;
48541 +#endif
48542
48543 rcu_read_lock();
48544 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48545 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48546 index 53c3bce..10ad159 100644
48547 --- a/fs/proc/proc_sysctl.c
48548 +++ b/fs/proc/proc_sysctl.c
48549 @@ -9,11 +9,13 @@
48550 #include <linux/namei.h>
48551 #include "internal.h"
48552
48553 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48554 +
48555 static const struct dentry_operations proc_sys_dentry_operations;
48556 static const struct file_operations proc_sys_file_operations;
48557 -static const struct inode_operations proc_sys_inode_operations;
48558 +const struct inode_operations proc_sys_inode_operations;
48559 static const struct file_operations proc_sys_dir_file_operations;
48560 -static const struct inode_operations proc_sys_dir_operations;
48561 +const struct inode_operations proc_sys_dir_operations;
48562
48563 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48564 {
48565 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48566
48567 err = NULL;
48568 d_set_d_op(dentry, &proc_sys_dentry_operations);
48569 +
48570 + gr_handle_proc_create(dentry, inode);
48571 +
48572 d_add(dentry, inode);
48573
48574 + if (gr_handle_sysctl(p, MAY_EXEC))
48575 + err = ERR_PTR(-ENOENT);
48576 +
48577 out:
48578 sysctl_head_finish(head);
48579 return err;
48580 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48581 if (!table->proc_handler)
48582 goto out;
48583
48584 +#ifdef CONFIG_GRKERNSEC
48585 + error = -EPERM;
48586 + if (write && !capable(CAP_SYS_ADMIN))
48587 + goto out;
48588 +#endif
48589 +
48590 /* careful: calling conventions are nasty here */
48591 res = count;
48592 error = table->proc_handler(table, write, buf, &res, ppos);
48593 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48594 return -ENOMEM;
48595 } else {
48596 d_set_d_op(child, &proc_sys_dentry_operations);
48597 +
48598 + gr_handle_proc_create(child, inode);
48599 +
48600 d_add(child, inode);
48601 }
48602 } else {
48603 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48604 if (*pos < file->f_pos)
48605 continue;
48606
48607 + if (gr_handle_sysctl(table, 0))
48608 + continue;
48609 +
48610 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48611 if (res)
48612 return res;
48613 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48614 if (IS_ERR(head))
48615 return PTR_ERR(head);
48616
48617 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48618 + return -ENOENT;
48619 +
48620 generic_fillattr(inode, stat);
48621 if (table)
48622 stat->mode = (stat->mode & S_IFMT) | table->mode;
48623 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48624 .llseek = generic_file_llseek,
48625 };
48626
48627 -static const struct inode_operations proc_sys_inode_operations = {
48628 +const struct inode_operations proc_sys_inode_operations = {
48629 .permission = proc_sys_permission,
48630 .setattr = proc_sys_setattr,
48631 .getattr = proc_sys_getattr,
48632 };
48633
48634 -static const struct inode_operations proc_sys_dir_operations = {
48635 +const struct inode_operations proc_sys_dir_operations = {
48636 .lookup = proc_sys_lookup,
48637 .permission = proc_sys_permission,
48638 .setattr = proc_sys_setattr,
48639 diff --git a/fs/proc/root.c b/fs/proc/root.c
48640 index 46a15d8..335631a 100644
48641 --- a/fs/proc/root.c
48642 +++ b/fs/proc/root.c
48643 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48644 #ifdef CONFIG_PROC_DEVICETREE
48645 proc_device_tree_init();
48646 #endif
48647 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48648 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48649 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48650 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48651 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48652 +#endif
48653 +#else
48654 proc_mkdir("bus", NULL);
48655 +#endif
48656 proc_sys_init();
48657 }
48658
48659 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48660 index 3efa725..23c925b 100644
48661 --- a/fs/proc/task_mmu.c
48662 +++ b/fs/proc/task_mmu.c
48663 @@ -11,6 +11,7 @@
48664 #include <linux/rmap.h>
48665 #include <linux/swap.h>
48666 #include <linux/swapops.h>
48667 +#include <linux/grsecurity.h>
48668
48669 #include <asm/elf.h>
48670 #include <asm/uaccess.h>
48671 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48672 "VmExe:\t%8lu kB\n"
48673 "VmLib:\t%8lu kB\n"
48674 "VmPTE:\t%8lu kB\n"
48675 - "VmSwap:\t%8lu kB\n",
48676 - hiwater_vm << (PAGE_SHIFT-10),
48677 + "VmSwap:\t%8lu kB\n"
48678 +
48679 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48680 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48681 +#endif
48682 +
48683 + ,hiwater_vm << (PAGE_SHIFT-10),
48684 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48685 mm->locked_vm << (PAGE_SHIFT-10),
48686 mm->pinned_vm << (PAGE_SHIFT-10),
48687 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48688 data << (PAGE_SHIFT-10),
48689 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48690 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48691 - swap << (PAGE_SHIFT-10));
48692 + swap << (PAGE_SHIFT-10)
48693 +
48694 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48695 + , mm->context.user_cs_base, mm->context.user_cs_limit
48696 +#endif
48697 +
48698 + );
48699 }
48700
48701 unsigned long task_vsize(struct mm_struct *mm)
48702 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48703 return ret;
48704 }
48705
48706 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48707 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48708 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48709 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48710 +#endif
48711 +
48712 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48713 {
48714 struct mm_struct *mm = vma->vm_mm;
48715 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48716 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48717 }
48718
48719 - /* We don't show the stack guard page in /proc/maps */
48720 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48721 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48722 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48723 +#else
48724 start = vma->vm_start;
48725 - if (stack_guard_page_start(vma, start))
48726 - start += PAGE_SIZE;
48727 end = vma->vm_end;
48728 - if (stack_guard_page_end(vma, end))
48729 - end -= PAGE_SIZE;
48730 +#endif
48731
48732 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48733 start,
48734 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48735 flags & VM_WRITE ? 'w' : '-',
48736 flags & VM_EXEC ? 'x' : '-',
48737 flags & VM_MAYSHARE ? 's' : 'p',
48738 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48739 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48740 +#else
48741 pgoff,
48742 +#endif
48743 MAJOR(dev), MINOR(dev), ino, &len);
48744
48745 /*
48746 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48747 */
48748 if (file) {
48749 pad_len_spaces(m, len);
48750 - seq_path(m, &file->f_path, "\n");
48751 + seq_path(m, &file->f_path, "\n\\");
48752 } else {
48753 const char *name = arch_vma_name(vma);
48754 if (!name) {
48755 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48756 if (vma->vm_start <= mm->brk &&
48757 vma->vm_end >= mm->start_brk) {
48758 name = "[heap]";
48759 - } else if (vma->vm_start <= mm->start_stack &&
48760 - vma->vm_end >= mm->start_stack) {
48761 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48762 + (vma->vm_start <= mm->start_stack &&
48763 + vma->vm_end >= mm->start_stack)) {
48764 name = "[stack]";
48765 }
48766 } else {
48767 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48768 struct proc_maps_private *priv = m->private;
48769 struct task_struct *task = priv->task;
48770
48771 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48772 + if (current->exec_id != m->exec_id) {
48773 + gr_log_badprocpid("maps");
48774 + return 0;
48775 + }
48776 +#endif
48777 +
48778 show_map_vma(m, vma);
48779
48780 if (m->count < m->size) /* vma is copied successfully */
48781 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48782 .private = &mss,
48783 };
48784
48785 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48786 + if (current->exec_id != m->exec_id) {
48787 + gr_log_badprocpid("smaps");
48788 + return 0;
48789 + }
48790 +#endif
48791 memset(&mss, 0, sizeof mss);
48792 - mss.vma = vma;
48793 - /* mmap_sem is held in m_start */
48794 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48795 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48796 -
48797 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48798 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48799 +#endif
48800 + mss.vma = vma;
48801 + /* mmap_sem is held in m_start */
48802 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48803 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48804 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48805 + }
48806 +#endif
48807 show_map_vma(m, vma);
48808
48809 seq_printf(m,
48810 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48811 "KernelPageSize: %8lu kB\n"
48812 "MMUPageSize: %8lu kB\n"
48813 "Locked: %8lu kB\n",
48814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48815 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48816 +#else
48817 (vma->vm_end - vma->vm_start) >> 10,
48818 +#endif
48819 mss.resident >> 10,
48820 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48821 mss.shared_clean >> 10,
48822 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48823 int n;
48824 char buffer[50];
48825
48826 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48827 + if (current->exec_id != m->exec_id) {
48828 + gr_log_badprocpid("numa_maps");
48829 + return 0;
48830 + }
48831 +#endif
48832 +
48833 if (!mm)
48834 return 0;
48835
48836 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48837 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48838 mpol_cond_put(pol);
48839
48840 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48841 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48842 +#else
48843 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48844 +#endif
48845
48846 if (file) {
48847 seq_printf(m, " file=");
48848 - seq_path(m, &file->f_path, "\n\t= ");
48849 + seq_path(m, &file->f_path, "\n\t\\= ");
48850 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48851 seq_printf(m, " heap");
48852 } else if (vma->vm_start <= mm->start_stack &&
48853 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48854 index 980de54..2a4db5f 100644
48855 --- a/fs/proc/task_nommu.c
48856 +++ b/fs/proc/task_nommu.c
48857 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48858 else
48859 bytes += kobjsize(mm);
48860
48861 - if (current->fs && current->fs->users > 1)
48862 + if (current->fs && atomic_read(&current->fs->users) > 1)
48863 sbytes += kobjsize(current->fs);
48864 else
48865 bytes += kobjsize(current->fs);
48866 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48867
48868 if (file) {
48869 pad_len_spaces(m, len);
48870 - seq_path(m, &file->f_path, "");
48871 + seq_path(m, &file->f_path, "\n\\");
48872 } else if (mm) {
48873 if (vma->vm_start <= mm->start_stack &&
48874 vma->vm_end >= mm->start_stack) {
48875 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48876 index d67908b..d13f6a6 100644
48877 --- a/fs/quota/netlink.c
48878 +++ b/fs/quota/netlink.c
48879 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48880 void quota_send_warning(short type, unsigned int id, dev_t dev,
48881 const char warntype)
48882 {
48883 - static atomic_t seq;
48884 + static atomic_unchecked_t seq;
48885 struct sk_buff *skb;
48886 void *msg_head;
48887 int ret;
48888 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48889 "VFS: Not enough memory to send quota warning.\n");
48890 return;
48891 }
48892 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48893 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48894 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48895 if (!msg_head) {
48896 printk(KERN_ERR
48897 diff --git a/fs/readdir.c b/fs/readdir.c
48898 index 356f715..c918d38 100644
48899 --- a/fs/readdir.c
48900 +++ b/fs/readdir.c
48901 @@ -17,6 +17,7 @@
48902 #include <linux/security.h>
48903 #include <linux/syscalls.h>
48904 #include <linux/unistd.h>
48905 +#include <linux/namei.h>
48906
48907 #include <asm/uaccess.h>
48908
48909 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48910
48911 struct readdir_callback {
48912 struct old_linux_dirent __user * dirent;
48913 + struct file * file;
48914 int result;
48915 };
48916
48917 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48918 buf->result = -EOVERFLOW;
48919 return -EOVERFLOW;
48920 }
48921 +
48922 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48923 + return 0;
48924 +
48925 buf->result++;
48926 dirent = buf->dirent;
48927 if (!access_ok(VERIFY_WRITE, dirent,
48928 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48929
48930 buf.result = 0;
48931 buf.dirent = dirent;
48932 + buf.file = file;
48933
48934 error = vfs_readdir(file, fillonedir, &buf);
48935 if (buf.result)
48936 @@ -142,6 +149,7 @@ struct linux_dirent {
48937 struct getdents_callback {
48938 struct linux_dirent __user * current_dir;
48939 struct linux_dirent __user * previous;
48940 + struct file * file;
48941 int count;
48942 int error;
48943 };
48944 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48945 buf->error = -EOVERFLOW;
48946 return -EOVERFLOW;
48947 }
48948 +
48949 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48950 + return 0;
48951 +
48952 dirent = buf->previous;
48953 if (dirent) {
48954 if (__put_user(offset, &dirent->d_off))
48955 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48956 buf.previous = NULL;
48957 buf.count = count;
48958 buf.error = 0;
48959 + buf.file = file;
48960
48961 error = vfs_readdir(file, filldir, &buf);
48962 if (error >= 0)
48963 @@ -229,6 +242,7 @@ out:
48964 struct getdents_callback64 {
48965 struct linux_dirent64 __user * current_dir;
48966 struct linux_dirent64 __user * previous;
48967 + struct file *file;
48968 int count;
48969 int error;
48970 };
48971 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48972 buf->error = -EINVAL; /* only used if we fail.. */
48973 if (reclen > buf->count)
48974 return -EINVAL;
48975 +
48976 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48977 + return 0;
48978 +
48979 dirent = buf->previous;
48980 if (dirent) {
48981 if (__put_user(offset, &dirent->d_off))
48982 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48983
48984 buf.current_dir = dirent;
48985 buf.previous = NULL;
48986 + buf.file = file;
48987 buf.count = count;
48988 buf.error = 0;
48989
48990 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48991 error = buf.error;
48992 lastdirent = buf.previous;
48993 if (lastdirent) {
48994 - typeof(lastdirent->d_off) d_off = file->f_pos;
48995 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48996 if (__put_user(d_off, &lastdirent->d_off))
48997 error = -EFAULT;
48998 else
48999 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49000 index 60c0804..d814f98 100644
49001 --- a/fs/reiserfs/do_balan.c
49002 +++ b/fs/reiserfs/do_balan.c
49003 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49004 return;
49005 }
49006
49007 - atomic_inc(&(fs_generation(tb->tb_sb)));
49008 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49009 do_balance_starts(tb);
49010
49011 /* balance leaf returns 0 except if combining L R and S into
49012 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49013 index 7a99811..a7c96c4 100644
49014 --- a/fs/reiserfs/procfs.c
49015 +++ b/fs/reiserfs/procfs.c
49016 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49017 "SMALL_TAILS " : "NO_TAILS ",
49018 replay_only(sb) ? "REPLAY_ONLY " : "",
49019 convert_reiserfs(sb) ? "CONV " : "",
49020 - atomic_read(&r->s_generation_counter),
49021 + atomic_read_unchecked(&r->s_generation_counter),
49022 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49023 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49024 SF(s_good_search_by_key_reada), SF(s_bmaps),
49025 diff --git a/fs/select.c b/fs/select.c
49026 index e782258..3b4b44c 100644
49027 --- a/fs/select.c
49028 +++ b/fs/select.c
49029 @@ -20,6 +20,7 @@
49030 #include <linux/module.h>
49031 #include <linux/slab.h>
49032 #include <linux/poll.h>
49033 +#include <linux/security.h>
49034 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49035 #include <linux/file.h>
49036 #include <linux/fdtable.h>
49037 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49038 struct poll_list *walk = head;
49039 unsigned long todo = nfds;
49040
49041 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49042 if (nfds > rlimit(RLIMIT_NOFILE))
49043 return -EINVAL;
49044
49045 diff --git a/fs/seq_file.c b/fs/seq_file.c
49046 index 4023d6b..ab46c6a 100644
49047 --- a/fs/seq_file.c
49048 +++ b/fs/seq_file.c
49049 @@ -9,6 +9,7 @@
49050 #include <linux/module.h>
49051 #include <linux/seq_file.h>
49052 #include <linux/slab.h>
49053 +#include <linux/sched.h>
49054
49055 #include <asm/uaccess.h>
49056 #include <asm/page.h>
49057 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49058 memset(p, 0, sizeof(*p));
49059 mutex_init(&p->lock);
49060 p->op = op;
49061 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49062 + p->exec_id = current->exec_id;
49063 +#endif
49064
49065 /*
49066 * Wrappers around seq_open(e.g. swaps_open) need to be
49067 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49068 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49069 void *data)
49070 {
49071 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49072 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49073 int res = -ENOMEM;
49074
49075 if (op) {
49076 diff --git a/fs/splice.c b/fs/splice.c
49077 index 1ec0493..d6ab5c2 100644
49078 --- a/fs/splice.c
49079 +++ b/fs/splice.c
49080 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49081 pipe_lock(pipe);
49082
49083 for (;;) {
49084 - if (!pipe->readers) {
49085 + if (!atomic_read(&pipe->readers)) {
49086 send_sig(SIGPIPE, current, 0);
49087 if (!ret)
49088 ret = -EPIPE;
49089 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49090 do_wakeup = 0;
49091 }
49092
49093 - pipe->waiting_writers++;
49094 + atomic_inc(&pipe->waiting_writers);
49095 pipe_wait(pipe);
49096 - pipe->waiting_writers--;
49097 + atomic_dec(&pipe->waiting_writers);
49098 }
49099
49100 pipe_unlock(pipe);
49101 @@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49102 old_fs = get_fs();
49103 set_fs(get_ds());
49104 /* The cast to a user pointer is valid due to the set_fs() */
49105 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49106 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49107 set_fs(old_fs);
49108
49109 return res;
49110 @@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49111 old_fs = get_fs();
49112 set_fs(get_ds());
49113 /* The cast to a user pointer is valid due to the set_fs() */
49114 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49115 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49116 set_fs(old_fs);
49117
49118 return res;
49119 @@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49120 goto err;
49121
49122 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49123 - vec[i].iov_base = (void __user *) page_address(page);
49124 + vec[i].iov_base = (void __force_user *) page_address(page);
49125 vec[i].iov_len = this_len;
49126 spd.pages[i] = page;
49127 spd.nr_pages++;
49128 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49129 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49130 {
49131 while (!pipe->nrbufs) {
49132 - if (!pipe->writers)
49133 + if (!atomic_read(&pipe->writers))
49134 return 0;
49135
49136 - if (!pipe->waiting_writers && sd->num_spliced)
49137 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49138 return 0;
49139
49140 if (sd->flags & SPLICE_F_NONBLOCK)
49141 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49142 * out of the pipe right after the splice_to_pipe(). So set
49143 * PIPE_READERS appropriately.
49144 */
49145 - pipe->readers = 1;
49146 + atomic_set(&pipe->readers, 1);
49147
49148 current->splice_pipe = pipe;
49149 }
49150 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49151 ret = -ERESTARTSYS;
49152 break;
49153 }
49154 - if (!pipe->writers)
49155 + if (!atomic_read(&pipe->writers))
49156 break;
49157 - if (!pipe->waiting_writers) {
49158 + if (!atomic_read(&pipe->waiting_writers)) {
49159 if (flags & SPLICE_F_NONBLOCK) {
49160 ret = -EAGAIN;
49161 break;
49162 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49163 pipe_lock(pipe);
49164
49165 while (pipe->nrbufs >= pipe->buffers) {
49166 - if (!pipe->readers) {
49167 + if (!atomic_read(&pipe->readers)) {
49168 send_sig(SIGPIPE, current, 0);
49169 ret = -EPIPE;
49170 break;
49171 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49172 ret = -ERESTARTSYS;
49173 break;
49174 }
49175 - pipe->waiting_writers++;
49176 + atomic_inc(&pipe->waiting_writers);
49177 pipe_wait(pipe);
49178 - pipe->waiting_writers--;
49179 + atomic_dec(&pipe->waiting_writers);
49180 }
49181
49182 pipe_unlock(pipe);
49183 @@ -1818,14 +1818,14 @@ retry:
49184 pipe_double_lock(ipipe, opipe);
49185
49186 do {
49187 - if (!opipe->readers) {
49188 + if (!atomic_read(&opipe->readers)) {
49189 send_sig(SIGPIPE, current, 0);
49190 if (!ret)
49191 ret = -EPIPE;
49192 break;
49193 }
49194
49195 - if (!ipipe->nrbufs && !ipipe->writers)
49196 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49197 break;
49198
49199 /*
49200 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49201 pipe_double_lock(ipipe, opipe);
49202
49203 do {
49204 - if (!opipe->readers) {
49205 + if (!atomic_read(&opipe->readers)) {
49206 send_sig(SIGPIPE, current, 0);
49207 if (!ret)
49208 ret = -EPIPE;
49209 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49210 * return EAGAIN if we have the potential of some data in the
49211 * future, otherwise just return 0
49212 */
49213 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49214 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49215 ret = -EAGAIN;
49216
49217 pipe_unlock(ipipe);
49218 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49219 index a475983..9c6a1f0 100644
49220 --- a/fs/sysfs/bin.c
49221 +++ b/fs/sysfs/bin.c
49222 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49223 }
49224
49225 static ssize_t
49226 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49227 +static ssize_t
49228 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49229 {
49230 struct bin_buffer *bb = file->private_data;
49231 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49232 index 7fdf6a7..e6cd8ad 100644
49233 --- a/fs/sysfs/dir.c
49234 +++ b/fs/sysfs/dir.c
49235 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49236 struct sysfs_dirent *sd;
49237 int rc;
49238
49239 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49240 + const char *parent_name = parent_sd->s_name;
49241 +
49242 + mode = S_IFDIR | S_IRWXU;
49243 +
49244 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49245 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49246 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49247 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49248 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49249 +#endif
49250 +
49251 /* allocate */
49252 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49253 if (!sd)
49254 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49255 index 00012e3..8392349 100644
49256 --- a/fs/sysfs/file.c
49257 +++ b/fs/sysfs/file.c
49258 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49259
49260 struct sysfs_open_dirent {
49261 atomic_t refcnt;
49262 - atomic_t event;
49263 + atomic_unchecked_t event;
49264 wait_queue_head_t poll;
49265 struct list_head buffers; /* goes through sysfs_buffer.list */
49266 };
49267 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49268 if (!sysfs_get_active(attr_sd))
49269 return -ENODEV;
49270
49271 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49272 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49273 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49274
49275 sysfs_put_active(attr_sd);
49276 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49277 return -ENOMEM;
49278
49279 atomic_set(&new_od->refcnt, 0);
49280 - atomic_set(&new_od->event, 1);
49281 + atomic_set_unchecked(&new_od->event, 1);
49282 init_waitqueue_head(&new_od->poll);
49283 INIT_LIST_HEAD(&new_od->buffers);
49284 goto retry;
49285 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49286
49287 sysfs_put_active(attr_sd);
49288
49289 - if (buffer->event != atomic_read(&od->event))
49290 + if (buffer->event != atomic_read_unchecked(&od->event))
49291 goto trigger;
49292
49293 return DEFAULT_POLLMASK;
49294 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49295
49296 od = sd->s_attr.open;
49297 if (od) {
49298 - atomic_inc(&od->event);
49299 + atomic_inc_unchecked(&od->event);
49300 wake_up_interruptible(&od->poll);
49301 }
49302
49303 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49304 index a7ac78f..02158e1 100644
49305 --- a/fs/sysfs/symlink.c
49306 +++ b/fs/sysfs/symlink.c
49307 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49308
49309 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49310 {
49311 - char *page = nd_get_link(nd);
49312 + const char *page = nd_get_link(nd);
49313 if (!IS_ERR(page))
49314 free_page((unsigned long)page);
49315 }
49316 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49317 index f922cba..062fb02 100644
49318 --- a/fs/ubifs/debug.c
49319 +++ b/fs/ubifs/debug.c
49320 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49321 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49322 * in case of failure.
49323 */
49324 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49325 static int interpret_user_input(const char __user *u, size_t count)
49326 {
49327 size_t buf_size;
49328 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49329 }
49330
49331 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49332 + size_t count, loff_t *ppos) __size_overflow(3);
49333 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49334 size_t count, loff_t *ppos)
49335 {
49336 struct ubifs_info *c = file->private_data;
49337 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49338 index c175b4d..8f36a16 100644
49339 --- a/fs/udf/misc.c
49340 +++ b/fs/udf/misc.c
49341 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49342
49343 u8 udf_tag_checksum(const struct tag *t)
49344 {
49345 - u8 *data = (u8 *)t;
49346 + const u8 *data = (const u8 *)t;
49347 u8 checksum = 0;
49348 int i;
49349 for (i = 0; i < sizeof(struct tag); ++i)
49350 diff --git a/fs/utimes.c b/fs/utimes.c
49351 index ba653f3..06ea4b1 100644
49352 --- a/fs/utimes.c
49353 +++ b/fs/utimes.c
49354 @@ -1,6 +1,7 @@
49355 #include <linux/compiler.h>
49356 #include <linux/file.h>
49357 #include <linux/fs.h>
49358 +#include <linux/security.h>
49359 #include <linux/linkage.h>
49360 #include <linux/mount.h>
49361 #include <linux/namei.h>
49362 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49363 goto mnt_drop_write_and_out;
49364 }
49365 }
49366 +
49367 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49368 + error = -EACCES;
49369 + goto mnt_drop_write_and_out;
49370 + }
49371 +
49372 mutex_lock(&inode->i_mutex);
49373 error = notify_change(path->dentry, &newattrs);
49374 mutex_unlock(&inode->i_mutex);
49375 diff --git a/fs/xattr.c b/fs/xattr.c
49376 index 82f4337..236473c 100644
49377 --- a/fs/xattr.c
49378 +++ b/fs/xattr.c
49379 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49380 * Extended attribute SET operations
49381 */
49382 static long
49383 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49384 +setxattr(struct path *path, const char __user *name, const void __user *value,
49385 size_t size, int flags)
49386 {
49387 int error;
49388 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49389 return PTR_ERR(kvalue);
49390 }
49391
49392 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49393 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49394 + error = -EACCES;
49395 + goto out;
49396 + }
49397 +
49398 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49399 +out:
49400 kfree(kvalue);
49401 return error;
49402 }
49403 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49404 return error;
49405 error = mnt_want_write(path.mnt);
49406 if (!error) {
49407 - error = setxattr(path.dentry, name, value, size, flags);
49408 + error = setxattr(&path, name, value, size, flags);
49409 mnt_drop_write(path.mnt);
49410 }
49411 path_put(&path);
49412 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49413 return error;
49414 error = mnt_want_write(path.mnt);
49415 if (!error) {
49416 - error = setxattr(path.dentry, name, value, size, flags);
49417 + error = setxattr(&path, name, value, size, flags);
49418 mnt_drop_write(path.mnt);
49419 }
49420 path_put(&path);
49421 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49422 const void __user *,value, size_t, size, int, flags)
49423 {
49424 struct file *f;
49425 - struct dentry *dentry;
49426 int error = -EBADF;
49427
49428 f = fget(fd);
49429 if (!f)
49430 return error;
49431 - dentry = f->f_path.dentry;
49432 - audit_inode(NULL, dentry);
49433 + audit_inode(NULL, f->f_path.dentry);
49434 error = mnt_want_write_file(f);
49435 if (!error) {
49436 - error = setxattr(dentry, name, value, size, flags);
49437 + error = setxattr(&f->f_path, name, value, size, flags);
49438 mnt_drop_write_file(f);
49439 }
49440 fput(f);
49441 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49442 index 8d5a506..7f62712 100644
49443 --- a/fs/xattr_acl.c
49444 +++ b/fs/xattr_acl.c
49445 @@ -17,8 +17,8 @@
49446 struct posix_acl *
49447 posix_acl_from_xattr(const void *value, size_t size)
49448 {
49449 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49450 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49451 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49452 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49453 int count;
49454 struct posix_acl *acl;
49455 struct posix_acl_entry *acl_e;
49456 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49457 index 188ef2f..adcf864 100644
49458 --- a/fs/xfs/xfs_bmap.c
49459 +++ b/fs/xfs/xfs_bmap.c
49460 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49461 int nmap,
49462 int ret_nmap);
49463 #else
49464 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49465 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49466 #endif /* DEBUG */
49467
49468 STATIC int
49469 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49470 index 79d05e8..e3e5861 100644
49471 --- a/fs/xfs/xfs_dir2_sf.c
49472 +++ b/fs/xfs/xfs_dir2_sf.c
49473 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49474 }
49475
49476 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49477 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49478 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49479 + char name[sfep->namelen];
49480 + memcpy(name, sfep->name, sfep->namelen);
49481 + if (filldir(dirent, name, sfep->namelen,
49482 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49483 + *offset = off & 0x7fffffff;
49484 + return 0;
49485 + }
49486 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49487 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49488 *offset = off & 0x7fffffff;
49489 return 0;
49490 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49491 index 76f3ca5..f57f712 100644
49492 --- a/fs/xfs/xfs_ioctl.c
49493 +++ b/fs/xfs/xfs_ioctl.c
49494 @@ -128,7 +128,7 @@ xfs_find_handle(
49495 }
49496
49497 error = -EFAULT;
49498 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49499 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49500 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49501 goto out_put;
49502
49503 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49504 index ab30253..4d86958 100644
49505 --- a/fs/xfs/xfs_iops.c
49506 +++ b/fs/xfs/xfs_iops.c
49507 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49508 struct nameidata *nd,
49509 void *p)
49510 {
49511 - char *s = nd_get_link(nd);
49512 + const char *s = nd_get_link(nd);
49513
49514 if (!IS_ERR(s))
49515 kfree(s);
49516 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49517 new file mode 100644
49518 index 0000000..4089e05
49519 --- /dev/null
49520 +++ b/grsecurity/Kconfig
49521 @@ -0,0 +1,1078 @@
49522 +#
49523 +# grecurity configuration
49524 +#
49525 +
49526 +menu "Grsecurity"
49527 +
49528 +config GRKERNSEC
49529 + bool "Grsecurity"
49530 + select CRYPTO
49531 + select CRYPTO_SHA256
49532 + help
49533 + If you say Y here, you will be able to configure many features
49534 + that will enhance the security of your system. It is highly
49535 + recommended that you say Y here and read through the help
49536 + for each option so that you fully understand the features and
49537 + can evaluate their usefulness for your machine.
49538 +
49539 +choice
49540 + prompt "Security Level"
49541 + depends on GRKERNSEC
49542 + default GRKERNSEC_CUSTOM
49543 +
49544 +config GRKERNSEC_LOW
49545 + bool "Low"
49546 + select GRKERNSEC_LINK
49547 + select GRKERNSEC_FIFO
49548 + select GRKERNSEC_RANDNET
49549 + select GRKERNSEC_DMESG
49550 + select GRKERNSEC_CHROOT
49551 + select GRKERNSEC_CHROOT_CHDIR
49552 +
49553 + help
49554 + If you choose this option, several of the grsecurity options will
49555 + be enabled that will give you greater protection against a number
49556 + of attacks, while assuring that none of your software will have any
49557 + conflicts with the additional security measures. If you run a lot
49558 + of unusual software, or you are having problems with the higher
49559 + security levels, you should say Y here. With this option, the
49560 + following features are enabled:
49561 +
49562 + - Linking restrictions
49563 + - FIFO restrictions
49564 + - Restricted dmesg
49565 + - Enforced chdir("/") on chroot
49566 + - Runtime module disabling
49567 +
49568 +config GRKERNSEC_MEDIUM
49569 + bool "Medium"
49570 + select PAX
49571 + select PAX_EI_PAX
49572 + select PAX_PT_PAX_FLAGS
49573 + select PAX_HAVE_ACL_FLAGS
49574 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49575 + select GRKERNSEC_CHROOT
49576 + select GRKERNSEC_CHROOT_SYSCTL
49577 + select GRKERNSEC_LINK
49578 + select GRKERNSEC_FIFO
49579 + select GRKERNSEC_DMESG
49580 + select GRKERNSEC_RANDNET
49581 + select GRKERNSEC_FORKFAIL
49582 + select GRKERNSEC_TIME
49583 + select GRKERNSEC_SIGNAL
49584 + select GRKERNSEC_CHROOT
49585 + select GRKERNSEC_CHROOT_UNIX
49586 + select GRKERNSEC_CHROOT_MOUNT
49587 + select GRKERNSEC_CHROOT_PIVOT
49588 + select GRKERNSEC_CHROOT_DOUBLE
49589 + select GRKERNSEC_CHROOT_CHDIR
49590 + select GRKERNSEC_CHROOT_MKNOD
49591 + select GRKERNSEC_PROC
49592 + select GRKERNSEC_PROC_USERGROUP
49593 + select PAX_RANDUSTACK
49594 + select PAX_ASLR
49595 + select PAX_RANDMMAP
49596 + select PAX_REFCOUNT if (X86 || SPARC64)
49597 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49598 +
49599 + help
49600 + If you say Y here, several features in addition to those included
49601 + in the low additional security level will be enabled. These
49602 + features provide even more security to your system, though in rare
49603 + cases they may be incompatible with very old or poorly written
49604 + software. If you enable this option, make sure that your auth
49605 + service (identd) is running as gid 1001. With this option,
49606 + the following features (in addition to those provided in the
49607 + low additional security level) will be enabled:
49608 +
49609 + - Failed fork logging
49610 + - Time change logging
49611 + - Signal logging
49612 + - Deny mounts in chroot
49613 + - Deny double chrooting
49614 + - Deny sysctl writes in chroot
49615 + - Deny mknod in chroot
49616 + - Deny access to abstract AF_UNIX sockets out of chroot
49617 + - Deny pivot_root in chroot
49618 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49619 + - /proc restrictions with special GID set to 10 (usually wheel)
49620 + - Address Space Layout Randomization (ASLR)
49621 + - Prevent exploitation of most refcount overflows
49622 + - Bounds checking of copying between the kernel and userland
49623 +
49624 +config GRKERNSEC_HIGH
49625 + bool "High"
49626 + select GRKERNSEC_LINK
49627 + select GRKERNSEC_FIFO
49628 + select GRKERNSEC_DMESG
49629 + select GRKERNSEC_FORKFAIL
49630 + select GRKERNSEC_TIME
49631 + select GRKERNSEC_SIGNAL
49632 + select GRKERNSEC_CHROOT
49633 + select GRKERNSEC_CHROOT_SHMAT
49634 + select GRKERNSEC_CHROOT_UNIX
49635 + select GRKERNSEC_CHROOT_MOUNT
49636 + select GRKERNSEC_CHROOT_FCHDIR
49637 + select GRKERNSEC_CHROOT_PIVOT
49638 + select GRKERNSEC_CHROOT_DOUBLE
49639 + select GRKERNSEC_CHROOT_CHDIR
49640 + select GRKERNSEC_CHROOT_MKNOD
49641 + select GRKERNSEC_CHROOT_CAPS
49642 + select GRKERNSEC_CHROOT_SYSCTL
49643 + select GRKERNSEC_CHROOT_FINDTASK
49644 + select GRKERNSEC_SYSFS_RESTRICT
49645 + select GRKERNSEC_PROC
49646 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49647 + select GRKERNSEC_HIDESYM
49648 + select GRKERNSEC_BRUTE
49649 + select GRKERNSEC_PROC_USERGROUP
49650 + select GRKERNSEC_KMEM
49651 + select GRKERNSEC_RESLOG
49652 + select GRKERNSEC_RANDNET
49653 + select GRKERNSEC_PROC_ADD
49654 + select GRKERNSEC_CHROOT_CHMOD
49655 + select GRKERNSEC_CHROOT_NICE
49656 + select GRKERNSEC_SETXID
49657 + select GRKERNSEC_AUDIT_MOUNT
49658 + select GRKERNSEC_MODHARDEN if (MODULES)
49659 + select GRKERNSEC_HARDEN_PTRACE
49660 + select GRKERNSEC_PTRACE_READEXEC
49661 + select GRKERNSEC_VM86 if (X86_32)
49662 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49663 + select PAX
49664 + select PAX_RANDUSTACK
49665 + select PAX_ASLR
49666 + select PAX_RANDMMAP
49667 + select PAX_NOEXEC
49668 + select PAX_MPROTECT
49669 + select PAX_EI_PAX
49670 + select PAX_PT_PAX_FLAGS
49671 + select PAX_HAVE_ACL_FLAGS
49672 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49673 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49674 + select PAX_RANDKSTACK if (X86_TSC && X86)
49675 + select PAX_SEGMEXEC if (X86_32)
49676 + select PAX_PAGEEXEC
49677 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49678 + select PAX_EMUTRAMP if (PARISC)
49679 + select PAX_EMUSIGRT if (PARISC)
49680 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49681 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49682 + select PAX_REFCOUNT if (X86 || SPARC64)
49683 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49684 + help
49685 + If you say Y here, many of the features of grsecurity will be
49686 + enabled, which will protect you against many kinds of attacks
49687 + against your system. The heightened security comes at a cost
49688 + of an increased chance of incompatibilities with rare software
49689 + on your machine. Since this security level enables PaX, you should
49690 + view <http://pax.grsecurity.net> and read about the PaX
49691 + project. While you are there, download chpax and run it on
49692 + binaries that cause problems with PaX. Also remember that
49693 + since the /proc restrictions are enabled, you must run your
49694 + identd as gid 1001. This security level enables the following
49695 + features in addition to those listed in the low and medium
49696 + security levels:
49697 +
49698 + - Additional /proc restrictions
49699 + - Chmod restrictions in chroot
49700 + - No signals, ptrace, or viewing of processes outside of chroot
49701 + - Capability restrictions in chroot
49702 + - Deny fchdir out of chroot
49703 + - Priority restrictions in chroot
49704 + - Segmentation-based implementation of PaX
49705 + - Mprotect restrictions
49706 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49707 + - Kernel stack randomization
49708 + - Mount/unmount/remount logging
49709 + - Kernel symbol hiding
49710 + - Hardening of module auto-loading
49711 + - Ptrace restrictions
49712 + - Restricted vm86 mode
49713 + - Restricted sysfs/debugfs
49714 + - Active kernel exploit response
49715 +
49716 +config GRKERNSEC_CUSTOM
49717 + bool "Custom"
49718 + help
49719 + If you say Y here, you will be able to configure every grsecurity
49720 + option, which allows you to enable many more features that aren't
49721 + covered in the basic security levels. These additional features
49722 + include TPE, socket restrictions, and the sysctl system for
49723 + grsecurity. It is advised that you read through the help for
49724 + each option to determine its usefulness in your situation.
49725 +
49726 +endchoice
49727 +
49728 +menu "Memory Protections"
49729 +depends on GRKERNSEC
49730 +
49731 +config GRKERNSEC_KMEM
49732 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49733 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49734 + help
49735 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49736 + be written to or read from to modify or leak the contents of the running
49737 + kernel. /dev/port will also not be allowed to be opened. If you have module
49738 + support disabled, enabling this will close up four ways that are
49739 + currently used to insert malicious code into the running kernel.
49740 + Even with all these features enabled, we still highly recommend that
49741 + you use the RBAC system, as it is still possible for an attacker to
49742 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49743 + If you are not using XFree86, you may be able to stop this additional
49744 + case by enabling the 'Disable privileged I/O' option. Though nothing
49745 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49746 + but only to video memory, which is the only writing we allow in this
49747 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49748 + not be allowed to mprotect it with PROT_WRITE later.
49749 + It is highly recommended that you say Y here if you meet all the
49750 + conditions above.
49751 +
49752 +config GRKERNSEC_VM86
49753 + bool "Restrict VM86 mode"
49754 + depends on X86_32
49755 +
49756 + help
49757 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49758 + make use of a special execution mode on 32bit x86 processors called
49759 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49760 + video cards and will still work with this option enabled. The purpose
49761 + of the option is to prevent exploitation of emulation errors in
49762 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49763 + Nearly all users should be able to enable this option.
49764 +
49765 +config GRKERNSEC_IO
49766 + bool "Disable privileged I/O"
49767 + depends on X86
49768 + select RTC_CLASS
49769 + select RTC_INTF_DEV
49770 + select RTC_DRV_CMOS
49771 +
49772 + help
49773 + If you say Y here, all ioperm and iopl calls will return an error.
49774 + Ioperm and iopl can be used to modify the running kernel.
49775 + Unfortunately, some programs need this access to operate properly,
49776 + the most notable of which are XFree86 and hwclock. hwclock can be
49777 + remedied by having RTC support in the kernel, so real-time
49778 + clock support is enabled if this option is enabled, to ensure
49779 + that hwclock operates correctly. XFree86 still will not
49780 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49781 + IF YOU USE XFree86. If you use XFree86 and you still want to
49782 + protect your kernel against modification, use the RBAC system.
49783 +
49784 +config GRKERNSEC_PROC_MEMMAP
49785 + bool "Harden ASLR against information leaks and entropy reduction"
49786 + default y if (PAX_NOEXEC || PAX_ASLR)
49787 + depends on PAX_NOEXEC || PAX_ASLR
49788 + help
49789 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49790 + give no information about the addresses of its mappings if
49791 + PaX features that rely on random addresses are enabled on the task.
49792 + In addition to sanitizing this information and disabling other
49793 + dangerous sources of information, this option causes reads of sensitive
49794 + /proc/<pid> entries where the file descriptor was opened in a different
49795 + task than the one performing the read. Such attempts are logged.
49796 + This option also limits argv/env strings for suid/sgid binaries
49797 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49798 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49799 + binaries to prevent alternative mmap layouts from being abused.
49800 +
49801 + If you use PaX it is essential that you say Y here as it closes up
49802 + several holes that make full ASLR useless locally.
49803 +
49804 +config GRKERNSEC_BRUTE
49805 + bool "Deter exploit bruteforcing"
49806 + help
49807 + If you say Y here, attempts to bruteforce exploits against forking
49808 + daemons such as apache or sshd, as well as against suid/sgid binaries
49809 + will be deterred. When a child of a forking daemon is killed by PaX
49810 + or crashes due to an illegal instruction or other suspicious signal,
49811 + the parent process will be delayed 30 seconds upon every subsequent
49812 + fork until the administrator is able to assess the situation and
49813 + restart the daemon.
49814 + In the suid/sgid case, the attempt is logged, the user has all their
49815 + processes terminated, and they are prevented from executing any further
49816 + processes for 15 minutes.
49817 + It is recommended that you also enable signal logging in the auditing
49818 + section so that logs are generated when a process triggers a suspicious
49819 + signal.
49820 + If the sysctl option is enabled, a sysctl option with name
49821 + "deter_bruteforce" is created.
49822 +
49823 +
49824 +config GRKERNSEC_MODHARDEN
49825 + bool "Harden module auto-loading"
49826 + depends on MODULES
49827 + help
49828 + If you say Y here, module auto-loading in response to use of some
49829 + feature implemented by an unloaded module will be restricted to
49830 + root users. Enabling this option helps defend against attacks
49831 + by unprivileged users who abuse the auto-loading behavior to
49832 + cause a vulnerable module to load that is then exploited.
49833 +
49834 + If this option prevents a legitimate use of auto-loading for a
49835 + non-root user, the administrator can execute modprobe manually
49836 + with the exact name of the module mentioned in the alert log.
49837 + Alternatively, the administrator can add the module to the list
49838 + of modules loaded at boot by modifying init scripts.
49839 +
49840 + Modification of init scripts will most likely be needed on
49841 + Ubuntu servers with encrypted home directory support enabled,
49842 + as the first non-root user logging in will cause the ecb(aes),
49843 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49844 +
49845 +config GRKERNSEC_HIDESYM
49846 + bool "Hide kernel symbols"
49847 + help
49848 + If you say Y here, getting information on loaded modules, and
49849 + displaying all kernel symbols through a syscall will be restricted
49850 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49851 + /proc/kallsyms will be restricted to the root user. The RBAC
49852 + system can hide that entry even from root.
49853 +
49854 + This option also prevents leaking of kernel addresses through
49855 + several /proc entries.
49856 +
49857 + Note that this option is only effective provided the following
49858 + conditions are met:
49859 + 1) The kernel using grsecurity is not precompiled by some distribution
49860 + 2) You have also enabled GRKERNSEC_DMESG
49861 + 3) You are using the RBAC system and hiding other files such as your
49862 + kernel image and System.map. Alternatively, enabling this option
49863 + causes the permissions on /boot, /lib/modules, and the kernel
49864 + source directory to change at compile time to prevent
49865 + reading by non-root users.
49866 + If the above conditions are met, this option will aid in providing a
49867 + useful protection against local kernel exploitation of overflows
49868 + and arbitrary read/write vulnerabilities.
49869 +
49870 +config GRKERNSEC_KERN_LOCKOUT
49871 + bool "Active kernel exploit response"
49872 + depends on X86 || ARM || PPC || SPARC
49873 + help
49874 + If you say Y here, when a PaX alert is triggered due to suspicious
49875 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49876 + or an OOPs occurs due to bad memory accesses, instead of just
49877 + terminating the offending process (and potentially allowing
49878 + a subsequent exploit from the same user), we will take one of two
49879 + actions:
49880 + If the user was root, we will panic the system
49881 + If the user was non-root, we will log the attempt, terminate
49882 + all processes owned by the user, then prevent them from creating
49883 + any new processes until the system is restarted
49884 + This deters repeated kernel exploitation/bruteforcing attempts
49885 + and is useful for later forensics.
49886 +
49887 +endmenu
49888 +menu "Role Based Access Control Options"
49889 +depends on GRKERNSEC
49890 +
49891 +config GRKERNSEC_RBAC_DEBUG
49892 + bool
49893 +
49894 +config GRKERNSEC_NO_RBAC
49895 + bool "Disable RBAC system"
49896 + help
49897 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49898 + preventing the RBAC system from being enabled. You should only say Y
49899 + here if you have no intention of using the RBAC system, so as to prevent
49900 + an attacker with root access from misusing the RBAC system to hide files
49901 + and processes when loadable module support and /dev/[k]mem have been
49902 + locked down.
49903 +
49904 +config GRKERNSEC_ACL_HIDEKERN
49905 + bool "Hide kernel processes"
49906 + help
49907 + If you say Y here, all kernel threads will be hidden to all
49908 + processes but those whose subject has the "view hidden processes"
49909 + flag.
49910 +
49911 +config GRKERNSEC_ACL_MAXTRIES
49912 + int "Maximum tries before password lockout"
49913 + default 3
49914 + help
49915 + This option enforces the maximum number of times a user can attempt
49916 + to authorize themselves with the grsecurity RBAC system before being
49917 + denied the ability to attempt authorization again for a specified time.
49918 + The lower the number, the harder it will be to brute-force a password.
49919 +
49920 +config GRKERNSEC_ACL_TIMEOUT
49921 + int "Time to wait after max password tries, in seconds"
49922 + default 30
49923 + help
49924 + This option specifies the time the user must wait after attempting to
49925 + authorize to the RBAC system with the maximum number of invalid
49926 + passwords. The higher the number, the harder it will be to brute-force
49927 + a password.
49928 +
49929 +endmenu
49930 +menu "Filesystem Protections"
49931 +depends on GRKERNSEC
49932 +
49933 +config GRKERNSEC_PROC
49934 + bool "Proc restrictions"
49935 + help
49936 + If you say Y here, the permissions of the /proc filesystem
49937 + will be altered to enhance system security and privacy. You MUST
49938 + choose either a user only restriction or a user and group restriction.
49939 + Depending upon the option you choose, you can either restrict users to
49940 + see only the processes they themselves run, or choose a group that can
49941 + view all processes and files normally restricted to root if you choose
49942 + the "restrict to user only" option. NOTE: If you're running identd or
49943 + ntpd as a non-root user, you will have to run it as the group you
49944 + specify here.
49945 +
49946 +config GRKERNSEC_PROC_USER
49947 + bool "Restrict /proc to user only"
49948 + depends on GRKERNSEC_PROC
49949 + help
49950 + If you say Y here, non-root users will only be able to view their own
49951 + processes, and restricts them from viewing network-related information,
49952 + and viewing kernel symbol and module information.
49953 +
49954 +config GRKERNSEC_PROC_USERGROUP
49955 + bool "Allow special group"
49956 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49957 + help
49958 + If you say Y here, you will be able to select a group that will be
49959 + able to view all processes and network-related information. If you've
49960 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49961 + remain hidden. This option is useful if you want to run identd as
49962 + a non-root user.
49963 +
49964 +config GRKERNSEC_PROC_GID
49965 + int "GID for special group"
49966 + depends on GRKERNSEC_PROC_USERGROUP
49967 + default 1001
49968 +
49969 +config GRKERNSEC_PROC_ADD
49970 + bool "Additional restrictions"
49971 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49972 + help
49973 + If you say Y here, additional restrictions will be placed on
49974 + /proc that keep normal users from viewing device information and
49975 + slabinfo information that could be useful for exploits.
49976 +
49977 +config GRKERNSEC_LINK
49978 + bool "Linking restrictions"
49979 + help
49980 + If you say Y here, /tmp race exploits will be prevented, since users
49981 + will no longer be able to follow symlinks owned by other users in
49982 + world-writable +t directories (e.g. /tmp), unless the owner of the
49983 + symlink is the owner of the directory. users will also not be
49984 + able to hardlink to files they do not own. If the sysctl option is
49985 + enabled, a sysctl option with name "linking_restrictions" is created.
49986 +
49987 +config GRKERNSEC_FIFO
49988 + bool "FIFO restrictions"
49989 + help
49990 + If you say Y here, users will not be able to write to FIFOs they don't
49991 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49992 + the FIFO is the same owner of the directory it's held in. If the sysctl
49993 + option is enabled, a sysctl option with name "fifo_restrictions" is
49994 + created.
49995 +
49996 +config GRKERNSEC_SYSFS_RESTRICT
49997 + bool "Sysfs/debugfs restriction"
49998 + depends on SYSFS
49999 + help
50000 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50001 + any filesystem normally mounted under it (e.g. debugfs) will be
50002 + mostly accessible only by root. These filesystems generally provide access
50003 + to hardware and debug information that isn't appropriate for unprivileged
50004 + users of the system. Sysfs and debugfs have also become a large source
50005 + of new vulnerabilities, ranging from infoleaks to local compromise.
50006 + There has been very little oversight with an eye toward security involved
50007 + in adding new exporters of information to these filesystems, so their
50008 + use is discouraged.
50009 + For reasons of compatibility, a few directories have been whitelisted
50010 + for access by non-root users:
50011 + /sys/fs/selinux
50012 + /sys/fs/fuse
50013 + /sys/devices/system/cpu
50014 +
50015 +config GRKERNSEC_ROFS
50016 + bool "Runtime read-only mount protection"
50017 + help
50018 + If you say Y here, a sysctl option with name "romount_protect" will
50019 + be created. By setting this option to 1 at runtime, filesystems
50020 + will be protected in the following ways:
50021 + * No new writable mounts will be allowed
50022 + * Existing read-only mounts won't be able to be remounted read/write
50023 + * Write operations will be denied on all block devices
50024 + This option acts independently of grsec_lock: once it is set to 1,
50025 + it cannot be turned off. Therefore, please be mindful of the resulting
50026 + behavior if this option is enabled in an init script on a read-only
50027 + filesystem. This feature is mainly intended for secure embedded systems.
50028 +
50029 +config GRKERNSEC_CHROOT
50030 + bool "Chroot jail restrictions"
50031 + help
50032 + If you say Y here, you will be able to choose several options that will
50033 + make breaking out of a chrooted jail much more difficult. If you
50034 + encounter no software incompatibilities with the following options, it
50035 + is recommended that you enable each one.
50036 +
50037 +config GRKERNSEC_CHROOT_MOUNT
50038 + bool "Deny mounts"
50039 + depends on GRKERNSEC_CHROOT
50040 + help
50041 + If you say Y here, processes inside a chroot will not be able to
50042 + mount or remount filesystems. If the sysctl option is enabled, a
50043 + sysctl option with name "chroot_deny_mount" is created.
50044 +
50045 +config GRKERNSEC_CHROOT_DOUBLE
50046 + bool "Deny double-chroots"
50047 + depends on GRKERNSEC_CHROOT
50048 + help
50049 + If you say Y here, processes inside a chroot will not be able to chroot
50050 + again outside the chroot. This is a widely used method of breaking
50051 + out of a chroot jail and should not be allowed. If the sysctl
50052 + option is enabled, a sysctl option with name
50053 + "chroot_deny_chroot" is created.
50054 +
50055 +config GRKERNSEC_CHROOT_PIVOT
50056 + bool "Deny pivot_root in chroot"
50057 + depends on GRKERNSEC_CHROOT
50058 + help
50059 + If you say Y here, processes inside a chroot will not be able to use
50060 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50061 + works similar to chroot in that it changes the root filesystem. This
50062 + function could be misused in a chrooted process to attempt to break out
50063 + of the chroot, and therefore should not be allowed. If the sysctl
50064 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50065 + created.
50066 +
50067 +config GRKERNSEC_CHROOT_CHDIR
50068 + bool "Enforce chdir(\"/\") on all chroots"
50069 + depends on GRKERNSEC_CHROOT
50070 + help
50071 + If you say Y here, the current working directory of all newly-chrooted
50072 + applications will be set to the the root directory of the chroot.
50073 + The man page on chroot(2) states:
50074 + Note that this call does not change the current working
50075 + directory, so that `.' can be outside the tree rooted at
50076 + `/'. In particular, the super-user can escape from a
50077 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50078 +
50079 + It is recommended that you say Y here, since it's not known to break
50080 + any software. If the sysctl option is enabled, a sysctl option with
50081 + name "chroot_enforce_chdir" is created.
50082 +
50083 +config GRKERNSEC_CHROOT_CHMOD
50084 + bool "Deny (f)chmod +s"
50085 + depends on GRKERNSEC_CHROOT
50086 + help
50087 + If you say Y here, processes inside a chroot will not be able to chmod
50088 + or fchmod files to make them have suid or sgid bits. This protects
50089 + against another published method of breaking a chroot. If the sysctl
50090 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50091 + created.
50092 +
50093 +config GRKERNSEC_CHROOT_FCHDIR
50094 + bool "Deny fchdir out of chroot"
50095 + depends on GRKERNSEC_CHROOT
50096 + help
50097 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50098 + to a file descriptor of the chrooting process that points to a directory
50099 + outside the filesystem will be stopped. If the sysctl option
50100 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50101 +
50102 +config GRKERNSEC_CHROOT_MKNOD
50103 + bool "Deny mknod"
50104 + depends on GRKERNSEC_CHROOT
50105 + help
50106 + If you say Y here, processes inside a chroot will not be allowed to
50107 + mknod. The problem with using mknod inside a chroot is that it
50108 + would allow an attacker to create a device entry that is the same
50109 + as one on the physical root of your system, which could range from
50110 + anything from the console device to a device for your harddrive (which
50111 + they could then use to wipe the drive or steal data). It is recommended
50112 + that you say Y here, unless you run into software incompatibilities.
50113 + If the sysctl option is enabled, a sysctl option with name
50114 + "chroot_deny_mknod" is created.
50115 +
50116 +config GRKERNSEC_CHROOT_SHMAT
50117 + bool "Deny shmat() out of chroot"
50118 + depends on GRKERNSEC_CHROOT
50119 + help
50120 + If you say Y here, processes inside a chroot will not be able to attach
50121 + to shared memory segments that were created outside of the chroot jail.
50122 + It is recommended that you say Y here. If the sysctl option is enabled,
50123 + a sysctl option with name "chroot_deny_shmat" is created.
50124 +
50125 +config GRKERNSEC_CHROOT_UNIX
50126 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50127 + depends on GRKERNSEC_CHROOT
50128 + help
50129 + If you say Y here, processes inside a chroot will not be able to
50130 + connect to abstract (meaning not belonging to a filesystem) Unix
50131 + domain sockets that were bound outside of a chroot. It is recommended
50132 + that you say Y here. If the sysctl option is enabled, a sysctl option
50133 + with name "chroot_deny_unix" is created.
50134 +
50135 +config GRKERNSEC_CHROOT_FINDTASK
50136 + bool "Protect outside processes"
50137 + depends on GRKERNSEC_CHROOT
50138 + help
50139 + If you say Y here, processes inside a chroot will not be able to
50140 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50141 + getsid, or view any process outside of the chroot. If the sysctl
50142 + option is enabled, a sysctl option with name "chroot_findtask" is
50143 + created.
50144 +
50145 +config GRKERNSEC_CHROOT_NICE
50146 + bool "Restrict priority changes"
50147 + depends on GRKERNSEC_CHROOT
50148 + help
50149 + If you say Y here, processes inside a chroot will not be able to raise
50150 + the priority of processes in the chroot, or alter the priority of
50151 + processes outside the chroot. This provides more security than simply
50152 + removing CAP_SYS_NICE from the process' capability set. If the
50153 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50154 + is created.
50155 +
50156 +config GRKERNSEC_CHROOT_SYSCTL
50157 + bool "Deny sysctl writes"
50158 + depends on GRKERNSEC_CHROOT
50159 + help
50160 + If you say Y here, an attacker in a chroot will not be able to
50161 + write to sysctl entries, either by sysctl(2) or through a /proc
50162 + interface. It is strongly recommended that you say Y here. If the
50163 + sysctl option is enabled, a sysctl option with name
50164 + "chroot_deny_sysctl" is created.
50165 +
50166 +config GRKERNSEC_CHROOT_CAPS
50167 + bool "Capability restrictions"
50168 + depends on GRKERNSEC_CHROOT
50169 + help
50170 + If you say Y here, the capabilities on all processes within a
50171 + chroot jail will be lowered to stop module insertion, raw i/o,
50172 + system and net admin tasks, rebooting the system, modifying immutable
50173 + files, modifying IPC owned by another, and changing the system time.
50174 + This is left an option because it can break some apps. Disable this
50175 + if your chrooted apps are having problems performing those kinds of
50176 + tasks. If the sysctl option is enabled, a sysctl option with
50177 + name "chroot_caps" is created.
50178 +
50179 +endmenu
50180 +menu "Kernel Auditing"
50181 +depends on GRKERNSEC
50182 +
50183 +config GRKERNSEC_AUDIT_GROUP
50184 + bool "Single group for auditing"
50185 + help
50186 + If you say Y here, the exec, chdir, and (un)mount logging features
50187 + will only operate on a group you specify. This option is recommended
50188 + if you only want to watch certain users instead of having a large
50189 + amount of logs from the entire system. If the sysctl option is enabled,
50190 + a sysctl option with name "audit_group" is created.
50191 +
50192 +config GRKERNSEC_AUDIT_GID
50193 + int "GID for auditing"
50194 + depends on GRKERNSEC_AUDIT_GROUP
50195 + default 1007
50196 +
50197 +config GRKERNSEC_EXECLOG
50198 + bool "Exec logging"
50199 + help
50200 + If you say Y here, all execve() calls will be logged (since the
50201 + other exec*() calls are frontends to execve(), all execution
50202 + will be logged). Useful for shell-servers that like to keep track
50203 + of their users. If the sysctl option is enabled, a sysctl option with
50204 + name "exec_logging" is created.
50205 + WARNING: This option when enabled will produce a LOT of logs, especially
50206 + on an active system.
50207 +
50208 +config GRKERNSEC_RESLOG
50209 + bool "Resource logging"
50210 + help
50211 + If you say Y here, all attempts to overstep resource limits will
50212 + be logged with the resource name, the requested size, and the current
50213 + limit. It is highly recommended that you say Y here. If the sysctl
50214 + option is enabled, a sysctl option with name "resource_logging" is
50215 + created. If the RBAC system is enabled, the sysctl value is ignored.
50216 +
50217 +config GRKERNSEC_CHROOT_EXECLOG
50218 + bool "Log execs within chroot"
50219 + help
50220 + If you say Y here, all executions inside a chroot jail will be logged
50221 + to syslog. This can cause a large amount of logs if certain
50222 + applications (eg. djb's daemontools) are installed on the system, and
50223 + is therefore left as an option. If the sysctl option is enabled, a
50224 + sysctl option with name "chroot_execlog" is created.
50225 +
50226 +config GRKERNSEC_AUDIT_PTRACE
50227 + bool "Ptrace logging"
50228 + help
50229 + If you say Y here, all attempts to attach to a process via ptrace
50230 + will be logged. If the sysctl option is enabled, a sysctl option
50231 + with name "audit_ptrace" is created.
50232 +
50233 +config GRKERNSEC_AUDIT_CHDIR
50234 + bool "Chdir logging"
50235 + help
50236 + If you say Y here, all chdir() calls will be logged. If the sysctl
50237 + option is enabled, a sysctl option with name "audit_chdir" is created.
50238 +
50239 +config GRKERNSEC_AUDIT_MOUNT
50240 + bool "(Un)Mount logging"
50241 + help
50242 + If you say Y here, all mounts and unmounts will be logged. If the
50243 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50244 + created.
50245 +
50246 +config GRKERNSEC_SIGNAL
50247 + bool "Signal logging"
50248 + help
50249 + If you say Y here, certain important signals will be logged, such as
50250 + SIGSEGV, which will as a result inform you of when a error in a program
50251 + occurred, which in some cases could mean a possible exploit attempt.
50252 + If the sysctl option is enabled, a sysctl option with name
50253 + "signal_logging" is created.
50254 +
50255 +config GRKERNSEC_FORKFAIL
50256 + bool "Fork failure logging"
50257 + help
50258 + If you say Y here, all failed fork() attempts will be logged.
50259 + This could suggest a fork bomb, or someone attempting to overstep
50260 + their process limit. If the sysctl option is enabled, a sysctl option
50261 + with name "forkfail_logging" is created.
50262 +
50263 +config GRKERNSEC_TIME
50264 + bool "Time change logging"
50265 + help
50266 + If you say Y here, any changes of the system clock will be logged.
50267 + If the sysctl option is enabled, a sysctl option with name
50268 + "timechange_logging" is created.
50269 +
50270 +config GRKERNSEC_PROC_IPADDR
50271 + bool "/proc/<pid>/ipaddr support"
50272 + help
50273 + If you say Y here, a new entry will be added to each /proc/<pid>
50274 + directory that contains the IP address of the person using the task.
50275 + The IP is carried across local TCP and AF_UNIX stream sockets.
50276 + This information can be useful for IDS/IPSes to perform remote response
50277 + to a local attack. The entry is readable by only the owner of the
50278 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50279 + the RBAC system), and thus does not create privacy concerns.
50280 +
50281 +config GRKERNSEC_RWXMAP_LOG
50282 + bool 'Denied RWX mmap/mprotect logging'
50283 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50284 + help
50285 + If you say Y here, calls to mmap() and mprotect() with explicit
50286 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50287 + denied by the PAX_MPROTECT feature. If the sysctl option is
50288 + enabled, a sysctl option with name "rwxmap_logging" is created.
50289 +
50290 +config GRKERNSEC_AUDIT_TEXTREL
50291 + bool 'ELF text relocations logging (READ HELP)'
50292 + depends on PAX_MPROTECT
50293 + help
50294 + If you say Y here, text relocations will be logged with the filename
50295 + of the offending library or binary. The purpose of the feature is
50296 + to help Linux distribution developers get rid of libraries and
50297 + binaries that need text relocations which hinder the future progress
50298 + of PaX. Only Linux distribution developers should say Y here, and
50299 + never on a production machine, as this option creates an information
50300 + leak that could aid an attacker in defeating the randomization of
50301 + a single memory region. If the sysctl option is enabled, a sysctl
50302 + option with name "audit_textrel" is created.
50303 +
50304 +endmenu
50305 +
50306 +menu "Executable Protections"
50307 +depends on GRKERNSEC
50308 +
50309 +config GRKERNSEC_DMESG
50310 + bool "Dmesg(8) restriction"
50311 + help
50312 + If you say Y here, non-root users will not be able to use dmesg(8)
50313 + to view up to the last 4kb of messages in the kernel's log buffer.
50314 + The kernel's log buffer often contains kernel addresses and other
50315 + identifying information useful to an attacker in fingerprinting a
50316 + system for a targeted exploit.
50317 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50318 + created.
50319 +
50320 +config GRKERNSEC_HARDEN_PTRACE
50321 + bool "Deter ptrace-based process snooping"
50322 + help
50323 + If you say Y here, TTY sniffers and other malicious monitoring
50324 + programs implemented through ptrace will be defeated. If you
50325 + have been using the RBAC system, this option has already been
50326 + enabled for several years for all users, with the ability to make
50327 + fine-grained exceptions.
50328 +
50329 + This option only affects the ability of non-root users to ptrace
50330 + processes that are not a descendent of the ptracing process.
50331 + This means that strace ./binary and gdb ./binary will still work,
50332 + but attaching to arbitrary processes will not. If the sysctl
50333 + option is enabled, a sysctl option with name "harden_ptrace" is
50334 + created.
50335 +
50336 +config GRKERNSEC_PTRACE_READEXEC
50337 + bool "Require read access to ptrace sensitive binaries"
50338 + help
50339 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50340 + binaries. This option is useful in environments that
50341 + remove the read bits (e.g. file mode 4711) from suid binaries to
50342 + prevent infoleaking of their contents. This option adds
50343 + consistency to the use of that file mode, as the binary could normally
50344 + be read out when run without privileges while ptracing.
50345 +
50346 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50347 + is created.
50348 +
50349 +config GRKERNSEC_SETXID
50350 + bool "Enforce consistent multithreaded privileges"
50351 + help
50352 + If you say Y here, a change from a root uid to a non-root uid
50353 + in a multithreaded application will cause the resulting uids,
50354 + gids, supplementary groups, and capabilities in that thread
50355 + to be propagated to the other threads of the process. In most
50356 + cases this is unnecessary, as glibc will emulate this behavior
50357 + on behalf of the application. Other libcs do not act in the
50358 + same way, allowing the other threads of the process to continue
50359 + running with root privileges. If the sysctl option is enabled,
50360 + a sysctl option with name "consistent_setxid" is created.
50361 +
50362 +config GRKERNSEC_TPE
50363 + bool "Trusted Path Execution (TPE)"
50364 + help
50365 + If you say Y here, you will be able to choose a gid to add to the
50366 + supplementary groups of users you want to mark as "untrusted."
50367 + These users will not be able to execute any files that are not in
50368 + root-owned directories writable only by root. If the sysctl option
50369 + is enabled, a sysctl option with name "tpe" is created.
50370 +
50371 +config GRKERNSEC_TPE_ALL
50372 + bool "Partially restrict all non-root users"
50373 + depends on GRKERNSEC_TPE
50374 + help
50375 + If you say Y here, all non-root users will be covered under
50376 + a weaker TPE restriction. This is separate from, and in addition to,
50377 + the main TPE options that you have selected elsewhere. Thus, if a
50378 + "trusted" GID is chosen, this restriction applies to even that GID.
50379 + Under this restriction, all non-root users will only be allowed to
50380 + execute files in directories they own that are not group or
50381 + world-writable, or in directories owned by root and writable only by
50382 + root. If the sysctl option is enabled, a sysctl option with name
50383 + "tpe_restrict_all" is created.
50384 +
50385 +config GRKERNSEC_TPE_INVERT
50386 + bool "Invert GID option"
50387 + depends on GRKERNSEC_TPE
50388 + help
50389 + If you say Y here, the group you specify in the TPE configuration will
50390 + decide what group TPE restrictions will be *disabled* for. This
50391 + option is useful if you want TPE restrictions to be applied to most
50392 + users on the system. If the sysctl option is enabled, a sysctl option
50393 + with name "tpe_invert" is created. Unlike other sysctl options, this
50394 + entry will default to on for backward-compatibility.
50395 +
50396 +config GRKERNSEC_TPE_GID
50397 + int "GID for untrusted users"
50398 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50399 + default 1005
50400 + help
50401 + Setting this GID determines what group TPE restrictions will be
50402 + *enabled* for. If the sysctl option is enabled, a sysctl option
50403 + with name "tpe_gid" is created.
50404 +
50405 +config GRKERNSEC_TPE_GID
50406 + int "GID for trusted users"
50407 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50408 + default 1005
50409 + help
50410 + Setting this GID determines what group TPE restrictions will be
50411 + *disabled* for. If the sysctl option is enabled, a sysctl option
50412 + with name "tpe_gid" is created.
50413 +
50414 +endmenu
50415 +menu "Network Protections"
50416 +depends on GRKERNSEC
50417 +
50418 +config GRKERNSEC_RANDNET
50419 + bool "Larger entropy pools"
50420 + help
50421 + If you say Y here, the entropy pools used for many features of Linux
50422 + and grsecurity will be doubled in size. Since several grsecurity
50423 + features use additional randomness, it is recommended that you say Y
50424 + here. Saying Y here has a similar effect as modifying
50425 + /proc/sys/kernel/random/poolsize.
50426 +
50427 +config GRKERNSEC_BLACKHOLE
50428 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50429 + depends on NET
50430 + help
50431 + If you say Y here, neither TCP resets nor ICMP
50432 + destination-unreachable packets will be sent in response to packets
50433 + sent to ports for which no associated listening process exists.
50434 + This feature supports both IPV4 and IPV6 and exempts the
50435 + loopback interface from blackholing. Enabling this feature
50436 + makes a host more resilient to DoS attacks and reduces network
50437 + visibility against scanners.
50438 +
50439 + The blackhole feature as-implemented is equivalent to the FreeBSD
50440 + blackhole feature, as it prevents RST responses to all packets, not
50441 + just SYNs. Under most application behavior this causes no
50442 + problems, but applications (like haproxy) may not close certain
50443 + connections in a way that cleanly terminates them on the remote
50444 + end, leaving the remote host in LAST_ACK state. Because of this
50445 + side-effect and to prevent intentional LAST_ACK DoSes, this
50446 + feature also adds automatic mitigation against such attacks.
50447 + The mitigation drastically reduces the amount of time a socket
50448 + can spend in LAST_ACK state. If you're using haproxy and not
50449 + all servers it connects to have this option enabled, consider
50450 + disabling this feature on the haproxy host.
50451 +
50452 + If the sysctl option is enabled, two sysctl options with names
50453 + "ip_blackhole" and "lastack_retries" will be created.
50454 + While "ip_blackhole" takes the standard zero/non-zero on/off
50455 + toggle, "lastack_retries" uses the same kinds of values as
50456 + "tcp_retries1" and "tcp_retries2". The default value of 4
50457 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50458 + state.
50459 +
50460 +config GRKERNSEC_SOCKET
50461 + bool "Socket restrictions"
50462 + depends on NET
50463 + help
50464 + If you say Y here, you will be able to choose from several options.
50465 + If you assign a GID on your system and add it to the supplementary
50466 + groups of users you want to restrict socket access to, this patch
50467 + will perform up to three things, based on the option(s) you choose.
50468 +
50469 +config GRKERNSEC_SOCKET_ALL
50470 + bool "Deny any sockets to group"
50471 + depends on GRKERNSEC_SOCKET
50472 + help
50473 + If you say Y here, you will be able to choose a GID of whose users will
50474 + be unable to connect to other hosts from your machine or run server
50475 + applications from your machine. If the sysctl option is enabled, a
50476 + sysctl option with name "socket_all" is created.
50477 +
50478 +config GRKERNSEC_SOCKET_ALL_GID
50479 + int "GID to deny all sockets for"
50480 + depends on GRKERNSEC_SOCKET_ALL
50481 + default 1004
50482 + help
50483 + Here you can choose the GID to disable socket access for. Remember to
50484 + add the users you want socket access disabled for to the GID
50485 + specified here. If the sysctl option is enabled, a sysctl option
50486 + with name "socket_all_gid" is created.
50487 +
50488 +config GRKERNSEC_SOCKET_CLIENT
50489 + bool "Deny client sockets to group"
50490 + depends on GRKERNSEC_SOCKET
50491 + help
50492 + If you say Y here, you will be able to choose a GID of whose users will
50493 + be unable to connect to other hosts from your machine, but will be
50494 + able to run servers. If this option is enabled, all users in the group
50495 + you specify will have to use passive mode when initiating ftp transfers
50496 + from the shell on your machine. If the sysctl option is enabled, a
50497 + sysctl option with name "socket_client" is created.
50498 +
50499 +config GRKERNSEC_SOCKET_CLIENT_GID
50500 + int "GID to deny client sockets for"
50501 + depends on GRKERNSEC_SOCKET_CLIENT
50502 + default 1003
50503 + help
50504 + Here you can choose the GID to disable client socket access for.
50505 + Remember to add the users you want client socket access disabled for to
50506 + the GID specified here. If the sysctl option is enabled, a sysctl
50507 + option with name "socket_client_gid" is created.
50508 +
50509 +config GRKERNSEC_SOCKET_SERVER
50510 + bool "Deny server sockets to group"
50511 + depends on GRKERNSEC_SOCKET
50512 + help
50513 + If you say Y here, you will be able to choose a GID of whose users will
50514 + be unable to run server applications from your machine. If the sysctl
50515 + option is enabled, a sysctl option with name "socket_server" is created.
50516 +
50517 +config GRKERNSEC_SOCKET_SERVER_GID
50518 + int "GID to deny server sockets for"
50519 + depends on GRKERNSEC_SOCKET_SERVER
50520 + default 1002
50521 + help
50522 + Here you can choose the GID to disable server socket access for.
50523 + Remember to add the users you want server socket access disabled for to
50524 + the GID specified here. If the sysctl option is enabled, a sysctl
50525 + option with name "socket_server_gid" is created.
50526 +
50527 +endmenu
50528 +menu "Sysctl support"
50529 +depends on GRKERNSEC && SYSCTL
50530 +
50531 +config GRKERNSEC_SYSCTL
50532 + bool "Sysctl support"
50533 + help
50534 + If you say Y here, you will be able to change the options that
50535 + grsecurity runs with at bootup, without having to recompile your
50536 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50537 + to enable (1) or disable (0) various features. All the sysctl entries
50538 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50539 + All features enabled in the kernel configuration are disabled at boot
50540 + if you do not say Y to the "Turn on features by default" option.
50541 + All options should be set at startup, and the grsec_lock entry should
50542 + be set to a non-zero value after all the options are set.
50543 + *THIS IS EXTREMELY IMPORTANT*
50544 +
50545 +config GRKERNSEC_SYSCTL_DISTRO
50546 + bool "Extra sysctl support for distro makers (READ HELP)"
50547 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50548 + help
50549 + If you say Y here, additional sysctl options will be created
50550 + for features that affect processes running as root. Therefore,
50551 + it is critical when using this option that the grsec_lock entry be
50552 + enabled after boot. Only distros with prebuilt kernel packages
50553 + with this option enabled that can ensure grsec_lock is enabled
50554 + after boot should use this option.
50555 + *Failure to set grsec_lock after boot makes all grsec features
50556 + this option covers useless*
50557 +
50558 + Currently this option creates the following sysctl entries:
50559 + "Disable Privileged I/O": "disable_priv_io"
50560 +
50561 +config GRKERNSEC_SYSCTL_ON
50562 + bool "Turn on features by default"
50563 + depends on GRKERNSEC_SYSCTL
50564 + help
50565 + If you say Y here, instead of having all features enabled in the
50566 + kernel configuration disabled at boot time, the features will be
50567 + enabled at boot time. It is recommended you say Y here unless
50568 + there is some reason you would want all sysctl-tunable features to
50569 + be disabled by default. As mentioned elsewhere, it is important
50570 + to enable the grsec_lock entry once you have finished modifying
50571 + the sysctl entries.
50572 +
50573 +endmenu
50574 +menu "Logging Options"
50575 +depends on GRKERNSEC
50576 +
50577 +config GRKERNSEC_FLOODTIME
50578 + int "Seconds in between log messages (minimum)"
50579 + default 10
50580 + help
50581 + This option allows you to enforce the number of seconds between
50582 + grsecurity log messages. The default should be suitable for most
50583 + people, however, if you choose to change it, choose a value small enough
50584 + to allow informative logs to be produced, but large enough to
50585 + prevent flooding.
50586 +
50587 +config GRKERNSEC_FLOODBURST
50588 + int "Number of messages in a burst (maximum)"
50589 + default 6
50590 + help
50591 + This option allows you to choose the maximum number of messages allowed
50592 + within the flood time interval you chose in a separate option. The
50593 + default should be suitable for most people, however if you find that
50594 + many of your logs are being interpreted as flooding, you may want to
50595 + raise this value.
50596 +
50597 +endmenu
50598 +
50599 +endmenu
50600 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50601 new file mode 100644
50602 index 0000000..1b9afa9
50603 --- /dev/null
50604 +++ b/grsecurity/Makefile
50605 @@ -0,0 +1,38 @@
50606 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50607 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50608 +# into an RBAC system
50609 +#
50610 +# All code in this directory and various hooks inserted throughout the kernel
50611 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50612 +# under the GPL v2 or higher
50613 +
50614 +KBUILD_CFLAGS += -Werror
50615 +
50616 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50617 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50618 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50619 +
50620 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50621 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50622 + gracl_learn.o grsec_log.o
50623 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50624 +
50625 +ifdef CONFIG_NET
50626 +obj-y += grsec_sock.o
50627 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50628 +endif
50629 +
50630 +ifndef CONFIG_GRKERNSEC
50631 +obj-y += grsec_disabled.o
50632 +endif
50633 +
50634 +ifdef CONFIG_GRKERNSEC_HIDESYM
50635 +extra-y := grsec_hidesym.o
50636 +$(obj)/grsec_hidesym.o:
50637 + @-chmod -f 500 /boot
50638 + @-chmod -f 500 /lib/modules
50639 + @-chmod -f 500 /lib64/modules
50640 + @-chmod -f 500 /lib32/modules
50641 + @-chmod -f 700 .
50642 + @echo ' grsec: protected kernel image paths'
50643 +endif
50644 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50645 new file mode 100644
50646 index 0000000..42813ac
50647 --- /dev/null
50648 +++ b/grsecurity/gracl.c
50649 @@ -0,0 +1,4192 @@
50650 +#include <linux/kernel.h>
50651 +#include <linux/module.h>
50652 +#include <linux/sched.h>
50653 +#include <linux/mm.h>
50654 +#include <linux/file.h>
50655 +#include <linux/fs.h>
50656 +#include <linux/namei.h>
50657 +#include <linux/mount.h>
50658 +#include <linux/tty.h>
50659 +#include <linux/proc_fs.h>
50660 +#include <linux/lglock.h>
50661 +#include <linux/slab.h>
50662 +#include <linux/vmalloc.h>
50663 +#include <linux/types.h>
50664 +#include <linux/sysctl.h>
50665 +#include <linux/netdevice.h>
50666 +#include <linux/ptrace.h>
50667 +#include <linux/gracl.h>
50668 +#include <linux/gralloc.h>
50669 +#include <linux/security.h>
50670 +#include <linux/grinternal.h>
50671 +#include <linux/pid_namespace.h>
50672 +#include <linux/fdtable.h>
50673 +#include <linux/percpu.h>
50674 +#include "../fs/mount.h"
50675 +
50676 +#include <asm/uaccess.h>
50677 +#include <asm/errno.h>
50678 +#include <asm/mman.h>
50679 +
50680 +static struct acl_role_db acl_role_set;
50681 +static struct name_db name_set;
50682 +static struct inodev_db inodev_set;
50683 +
50684 +/* for keeping track of userspace pointers used for subjects, so we
50685 + can share references in the kernel as well
50686 +*/
50687 +
50688 +static struct path real_root;
50689 +
50690 +static struct acl_subj_map_db subj_map_set;
50691 +
50692 +static struct acl_role_label *default_role;
50693 +
50694 +static struct acl_role_label *role_list;
50695 +
50696 +static u16 acl_sp_role_value;
50697 +
50698 +extern char *gr_shared_page[4];
50699 +static DEFINE_MUTEX(gr_dev_mutex);
50700 +DEFINE_RWLOCK(gr_inode_lock);
50701 +
50702 +struct gr_arg *gr_usermode;
50703 +
50704 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50705 +
50706 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50707 +extern void gr_clear_learn_entries(void);
50708 +
50709 +#ifdef CONFIG_GRKERNSEC_RESLOG
50710 +extern void gr_log_resource(const struct task_struct *task,
50711 + const int res, const unsigned long wanted, const int gt);
50712 +#endif
50713 +
50714 +unsigned char *gr_system_salt;
50715 +unsigned char *gr_system_sum;
50716 +
50717 +static struct sprole_pw **acl_special_roles = NULL;
50718 +static __u16 num_sprole_pws = 0;
50719 +
50720 +static struct acl_role_label *kernel_role = NULL;
50721 +
50722 +static unsigned int gr_auth_attempts = 0;
50723 +static unsigned long gr_auth_expires = 0UL;
50724 +
50725 +#ifdef CONFIG_NET
50726 +extern struct vfsmount *sock_mnt;
50727 +#endif
50728 +
50729 +extern struct vfsmount *pipe_mnt;
50730 +extern struct vfsmount *shm_mnt;
50731 +#ifdef CONFIG_HUGETLBFS
50732 +extern struct vfsmount *hugetlbfs_vfsmount;
50733 +#endif
50734 +
50735 +static struct acl_object_label *fakefs_obj_rw;
50736 +static struct acl_object_label *fakefs_obj_rwx;
50737 +
50738 +extern int gr_init_uidset(void);
50739 +extern void gr_free_uidset(void);
50740 +extern void gr_remove_uid(uid_t uid);
50741 +extern int gr_find_uid(uid_t uid);
50742 +
50743 +DECLARE_BRLOCK(vfsmount_lock);
50744 +
50745 +__inline__ int
50746 +gr_acl_is_enabled(void)
50747 +{
50748 + return (gr_status & GR_READY);
50749 +}
50750 +
50751 +#ifdef CONFIG_BTRFS_FS
50752 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50753 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50754 +#endif
50755 +
50756 +static inline dev_t __get_dev(const struct dentry *dentry)
50757 +{
50758 +#ifdef CONFIG_BTRFS_FS
50759 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50760 + return get_btrfs_dev_from_inode(dentry->d_inode);
50761 + else
50762 +#endif
50763 + return dentry->d_inode->i_sb->s_dev;
50764 +}
50765 +
50766 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50767 +{
50768 + return __get_dev(dentry);
50769 +}
50770 +
50771 +static char gr_task_roletype_to_char(struct task_struct *task)
50772 +{
50773 + switch (task->role->roletype &
50774 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50775 + GR_ROLE_SPECIAL)) {
50776 + case GR_ROLE_DEFAULT:
50777 + return 'D';
50778 + case GR_ROLE_USER:
50779 + return 'U';
50780 + case GR_ROLE_GROUP:
50781 + return 'G';
50782 + case GR_ROLE_SPECIAL:
50783 + return 'S';
50784 + }
50785 +
50786 + return 'X';
50787 +}
50788 +
50789 +char gr_roletype_to_char(void)
50790 +{
50791 + return gr_task_roletype_to_char(current);
50792 +}
50793 +
50794 +__inline__ int
50795 +gr_acl_tpe_check(void)
50796 +{
50797 + if (unlikely(!(gr_status & GR_READY)))
50798 + return 0;
50799 + if (current->role->roletype & GR_ROLE_TPE)
50800 + return 1;
50801 + else
50802 + return 0;
50803 +}
50804 +
50805 +int
50806 +gr_handle_rawio(const struct inode *inode)
50807 +{
50808 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50809 + if (inode && S_ISBLK(inode->i_mode) &&
50810 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50811 + !capable(CAP_SYS_RAWIO))
50812 + return 1;
50813 +#endif
50814 + return 0;
50815 +}
50816 +
50817 +static int
50818 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50819 +{
50820 + if (likely(lena != lenb))
50821 + return 0;
50822 +
50823 + return !memcmp(a, b, lena);
50824 +}
50825 +
50826 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50827 +{
50828 + *buflen -= namelen;
50829 + if (*buflen < 0)
50830 + return -ENAMETOOLONG;
50831 + *buffer -= namelen;
50832 + memcpy(*buffer, str, namelen);
50833 + return 0;
50834 +}
50835 +
50836 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50837 +{
50838 + return prepend(buffer, buflen, name->name, name->len);
50839 +}
50840 +
50841 +static int prepend_path(const struct path *path, struct path *root,
50842 + char **buffer, int *buflen)
50843 +{
50844 + struct dentry *dentry = path->dentry;
50845 + struct vfsmount *vfsmnt = path->mnt;
50846 + struct mount *mnt = real_mount(vfsmnt);
50847 + bool slash = false;
50848 + int error = 0;
50849 +
50850 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50851 + struct dentry * parent;
50852 +
50853 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50854 + /* Global root? */
50855 + if (!mnt_has_parent(mnt)) {
50856 + goto out;
50857 + }
50858 + dentry = mnt->mnt_mountpoint;
50859 + mnt = mnt->mnt_parent;
50860 + vfsmnt = &mnt->mnt;
50861 + continue;
50862 + }
50863 + parent = dentry->d_parent;
50864 + prefetch(parent);
50865 + spin_lock(&dentry->d_lock);
50866 + error = prepend_name(buffer, buflen, &dentry->d_name);
50867 + spin_unlock(&dentry->d_lock);
50868 + if (!error)
50869 + error = prepend(buffer, buflen, "/", 1);
50870 + if (error)
50871 + break;
50872 +
50873 + slash = true;
50874 + dentry = parent;
50875 + }
50876 +
50877 +out:
50878 + if (!error && !slash)
50879 + error = prepend(buffer, buflen, "/", 1);
50880 +
50881 + return error;
50882 +}
50883 +
50884 +/* this must be called with vfsmount_lock and rename_lock held */
50885 +
50886 +static char *__our_d_path(const struct path *path, struct path *root,
50887 + char *buf, int buflen)
50888 +{
50889 + char *res = buf + buflen;
50890 + int error;
50891 +
50892 + prepend(&res, &buflen, "\0", 1);
50893 + error = prepend_path(path, root, &res, &buflen);
50894 + if (error)
50895 + return ERR_PTR(error);
50896 +
50897 + return res;
50898 +}
50899 +
50900 +static char *
50901 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50902 +{
50903 + char *retval;
50904 +
50905 + retval = __our_d_path(path, root, buf, buflen);
50906 + if (unlikely(IS_ERR(retval)))
50907 + retval = strcpy(buf, "<path too long>");
50908 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50909 + retval[1] = '\0';
50910 +
50911 + return retval;
50912 +}
50913 +
50914 +static char *
50915 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50916 + char *buf, int buflen)
50917 +{
50918 + struct path path;
50919 + char *res;
50920 +
50921 + path.dentry = (struct dentry *)dentry;
50922 + path.mnt = (struct vfsmount *)vfsmnt;
50923 +
50924 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50925 + by the RBAC system */
50926 + res = gen_full_path(&path, &real_root, buf, buflen);
50927 +
50928 + return res;
50929 +}
50930 +
50931 +static char *
50932 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50933 + char *buf, int buflen)
50934 +{
50935 + char *res;
50936 + struct path path;
50937 + struct path root;
50938 + struct task_struct *reaper = &init_task;
50939 +
50940 + path.dentry = (struct dentry *)dentry;
50941 + path.mnt = (struct vfsmount *)vfsmnt;
50942 +
50943 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50944 + get_fs_root(reaper->fs, &root);
50945 +
50946 + write_seqlock(&rename_lock);
50947 + br_read_lock(vfsmount_lock);
50948 + res = gen_full_path(&path, &root, buf, buflen);
50949 + br_read_unlock(vfsmount_lock);
50950 + write_sequnlock(&rename_lock);
50951 +
50952 + path_put(&root);
50953 + return res;
50954 +}
50955 +
50956 +static char *
50957 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50958 +{
50959 + char *ret;
50960 + write_seqlock(&rename_lock);
50961 + br_read_lock(vfsmount_lock);
50962 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50963 + PAGE_SIZE);
50964 + br_read_unlock(vfsmount_lock);
50965 + write_sequnlock(&rename_lock);
50966 + return ret;
50967 +}
50968 +
50969 +static char *
50970 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50971 +{
50972 + char *ret;
50973 + char *buf;
50974 + int buflen;
50975 +
50976 + write_seqlock(&rename_lock);
50977 + br_read_lock(vfsmount_lock);
50978 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50979 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50980 + buflen = (int)(ret - buf);
50981 + if (buflen >= 5)
50982 + prepend(&ret, &buflen, "/proc", 5);
50983 + else
50984 + ret = strcpy(buf, "<path too long>");
50985 + br_read_unlock(vfsmount_lock);
50986 + write_sequnlock(&rename_lock);
50987 + return ret;
50988 +}
50989 +
50990 +char *
50991 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50992 +{
50993 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50994 + PAGE_SIZE);
50995 +}
50996 +
50997 +char *
50998 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50999 +{
51000 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51001 + PAGE_SIZE);
51002 +}
51003 +
51004 +char *
51005 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51006 +{
51007 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51008 + PAGE_SIZE);
51009 +}
51010 +
51011 +char *
51012 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51013 +{
51014 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51015 + PAGE_SIZE);
51016 +}
51017 +
51018 +char *
51019 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51020 +{
51021 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51022 + PAGE_SIZE);
51023 +}
51024 +
51025 +__inline__ __u32
51026 +to_gr_audit(const __u32 reqmode)
51027 +{
51028 + /* masks off auditable permission flags, then shifts them to create
51029 + auditing flags, and adds the special case of append auditing if
51030 + we're requesting write */
51031 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51032 +}
51033 +
51034 +struct acl_subject_label *
51035 +lookup_subject_map(const struct acl_subject_label *userp)
51036 +{
51037 + unsigned int index = shash(userp, subj_map_set.s_size);
51038 + struct subject_map *match;
51039 +
51040 + match = subj_map_set.s_hash[index];
51041 +
51042 + while (match && match->user != userp)
51043 + match = match->next;
51044 +
51045 + if (match != NULL)
51046 + return match->kernel;
51047 + else
51048 + return NULL;
51049 +}
51050 +
51051 +static void
51052 +insert_subj_map_entry(struct subject_map *subjmap)
51053 +{
51054 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51055 + struct subject_map **curr;
51056 +
51057 + subjmap->prev = NULL;
51058 +
51059 + curr = &subj_map_set.s_hash[index];
51060 + if (*curr != NULL)
51061 + (*curr)->prev = subjmap;
51062 +
51063 + subjmap->next = *curr;
51064 + *curr = subjmap;
51065 +
51066 + return;
51067 +}
51068 +
51069 +static struct acl_role_label *
51070 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51071 + const gid_t gid)
51072 +{
51073 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51074 + struct acl_role_label *match;
51075 + struct role_allowed_ip *ipp;
51076 + unsigned int x;
51077 + u32 curr_ip = task->signal->curr_ip;
51078 +
51079 + task->signal->saved_ip = curr_ip;
51080 +
51081 + match = acl_role_set.r_hash[index];
51082 +
51083 + while (match) {
51084 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51085 + for (x = 0; x < match->domain_child_num; x++) {
51086 + if (match->domain_children[x] == uid)
51087 + goto found;
51088 + }
51089 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51090 + break;
51091 + match = match->next;
51092 + }
51093 +found:
51094 + if (match == NULL) {
51095 + try_group:
51096 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51097 + match = acl_role_set.r_hash[index];
51098 +
51099 + while (match) {
51100 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51101 + for (x = 0; x < match->domain_child_num; x++) {
51102 + if (match->domain_children[x] == gid)
51103 + goto found2;
51104 + }
51105 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51106 + break;
51107 + match = match->next;
51108 + }
51109 +found2:
51110 + if (match == NULL)
51111 + match = default_role;
51112 + if (match->allowed_ips == NULL)
51113 + return match;
51114 + else {
51115 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51116 + if (likely
51117 + ((ntohl(curr_ip) & ipp->netmask) ==
51118 + (ntohl(ipp->addr) & ipp->netmask)))
51119 + return match;
51120 + }
51121 + match = default_role;
51122 + }
51123 + } else if (match->allowed_ips == NULL) {
51124 + return match;
51125 + } else {
51126 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51127 + if (likely
51128 + ((ntohl(curr_ip) & ipp->netmask) ==
51129 + (ntohl(ipp->addr) & ipp->netmask)))
51130 + return match;
51131 + }
51132 + goto try_group;
51133 + }
51134 +
51135 + return match;
51136 +}
51137 +
51138 +struct acl_subject_label *
51139 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51140 + const struct acl_role_label *role)
51141 +{
51142 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51143 + struct acl_subject_label *match;
51144 +
51145 + match = role->subj_hash[index];
51146 +
51147 + while (match && (match->inode != ino || match->device != dev ||
51148 + (match->mode & GR_DELETED))) {
51149 + match = match->next;
51150 + }
51151 +
51152 + if (match && !(match->mode & GR_DELETED))
51153 + return match;
51154 + else
51155 + return NULL;
51156 +}
51157 +
51158 +struct acl_subject_label *
51159 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51160 + const struct acl_role_label *role)
51161 +{
51162 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51163 + struct acl_subject_label *match;
51164 +
51165 + match = role->subj_hash[index];
51166 +
51167 + while (match && (match->inode != ino || match->device != dev ||
51168 + !(match->mode & GR_DELETED))) {
51169 + match = match->next;
51170 + }
51171 +
51172 + if (match && (match->mode & GR_DELETED))
51173 + return match;
51174 + else
51175 + return NULL;
51176 +}
51177 +
51178 +static struct acl_object_label *
51179 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51180 + const struct acl_subject_label *subj)
51181 +{
51182 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51183 + struct acl_object_label *match;
51184 +
51185 + match = subj->obj_hash[index];
51186 +
51187 + while (match && (match->inode != ino || match->device != dev ||
51188 + (match->mode & GR_DELETED))) {
51189 + match = match->next;
51190 + }
51191 +
51192 + if (match && !(match->mode & GR_DELETED))
51193 + return match;
51194 + else
51195 + return NULL;
51196 +}
51197 +
51198 +static struct acl_object_label *
51199 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51200 + const struct acl_subject_label *subj)
51201 +{
51202 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51203 + struct acl_object_label *match;
51204 +
51205 + match = subj->obj_hash[index];
51206 +
51207 + while (match && (match->inode != ino || match->device != dev ||
51208 + !(match->mode & GR_DELETED))) {
51209 + match = match->next;
51210 + }
51211 +
51212 + if (match && (match->mode & GR_DELETED))
51213 + return match;
51214 +
51215 + match = subj->obj_hash[index];
51216 +
51217 + while (match && (match->inode != ino || match->device != dev ||
51218 + (match->mode & GR_DELETED))) {
51219 + match = match->next;
51220 + }
51221 +
51222 + if (match && !(match->mode & GR_DELETED))
51223 + return match;
51224 + else
51225 + return NULL;
51226 +}
51227 +
51228 +static struct name_entry *
51229 +lookup_name_entry(const char *name)
51230 +{
51231 + unsigned int len = strlen(name);
51232 + unsigned int key = full_name_hash(name, len);
51233 + unsigned int index = key % name_set.n_size;
51234 + struct name_entry *match;
51235 +
51236 + match = name_set.n_hash[index];
51237 +
51238 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51239 + match = match->next;
51240 +
51241 + return match;
51242 +}
51243 +
51244 +static struct name_entry *
51245 +lookup_name_entry_create(const char *name)
51246 +{
51247 + unsigned int len = strlen(name);
51248 + unsigned int key = full_name_hash(name, len);
51249 + unsigned int index = key % name_set.n_size;
51250 + struct name_entry *match;
51251 +
51252 + match = name_set.n_hash[index];
51253 +
51254 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51255 + !match->deleted))
51256 + match = match->next;
51257 +
51258 + if (match && match->deleted)
51259 + return match;
51260 +
51261 + match = name_set.n_hash[index];
51262 +
51263 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51264 + match->deleted))
51265 + match = match->next;
51266 +
51267 + if (match && !match->deleted)
51268 + return match;
51269 + else
51270 + return NULL;
51271 +}
51272 +
51273 +static struct inodev_entry *
51274 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51275 +{
51276 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51277 + struct inodev_entry *match;
51278 +
51279 + match = inodev_set.i_hash[index];
51280 +
51281 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51282 + match = match->next;
51283 +
51284 + return match;
51285 +}
51286 +
51287 +static void
51288 +insert_inodev_entry(struct inodev_entry *entry)
51289 +{
51290 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51291 + inodev_set.i_size);
51292 + struct inodev_entry **curr;
51293 +
51294 + entry->prev = NULL;
51295 +
51296 + curr = &inodev_set.i_hash[index];
51297 + if (*curr != NULL)
51298 + (*curr)->prev = entry;
51299 +
51300 + entry->next = *curr;
51301 + *curr = entry;
51302 +
51303 + return;
51304 +}
51305 +
51306 +static void
51307 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51308 +{
51309 + unsigned int index =
51310 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51311 + struct acl_role_label **curr;
51312 + struct acl_role_label *tmp, *tmp2;
51313 +
51314 + curr = &acl_role_set.r_hash[index];
51315 +
51316 + /* simple case, slot is empty, just set it to our role */
51317 + if (*curr == NULL) {
51318 + *curr = role;
51319 + } else {
51320 + /* example:
51321 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51322 + 2 -> 3
51323 + */
51324 + /* first check to see if we can already be reached via this slot */
51325 + tmp = *curr;
51326 + while (tmp && tmp != role)
51327 + tmp = tmp->next;
51328 + if (tmp == role) {
51329 + /* we don't need to add ourselves to this slot's chain */
51330 + return;
51331 + }
51332 + /* we need to add ourselves to this chain, two cases */
51333 + if (role->next == NULL) {
51334 + /* simple case, append the current chain to our role */
51335 + role->next = *curr;
51336 + *curr = role;
51337 + } else {
51338 + /* 1 -> 2 -> 3 -> 4
51339 + 2 -> 3 -> 4
51340 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51341 + */
51342 + /* trickier case: walk our role's chain until we find
51343 + the role for the start of the current slot's chain */
51344 + tmp = role;
51345 + tmp2 = *curr;
51346 + while (tmp->next && tmp->next != tmp2)
51347 + tmp = tmp->next;
51348 + if (tmp->next == tmp2) {
51349 + /* from example above, we found 3, so just
51350 + replace this slot's chain with ours */
51351 + *curr = role;
51352 + } else {
51353 + /* we didn't find a subset of our role's chain
51354 + in the current slot's chain, so append their
51355 + chain to ours, and set us as the first role in
51356 + the slot's chain
51357 +
51358 + we could fold this case with the case above,
51359 + but making it explicit for clarity
51360 + */
51361 + tmp->next = tmp2;
51362 + *curr = role;
51363 + }
51364 + }
51365 + }
51366 +
51367 + return;
51368 +}
51369 +
51370 +static void
51371 +insert_acl_role_label(struct acl_role_label *role)
51372 +{
51373 + int i;
51374 +
51375 + if (role_list == NULL) {
51376 + role_list = role;
51377 + role->prev = NULL;
51378 + } else {
51379 + role->prev = role_list;
51380 + role_list = role;
51381 + }
51382 +
51383 + /* used for hash chains */
51384 + role->next = NULL;
51385 +
51386 + if (role->roletype & GR_ROLE_DOMAIN) {
51387 + for (i = 0; i < role->domain_child_num; i++)
51388 + __insert_acl_role_label(role, role->domain_children[i]);
51389 + } else
51390 + __insert_acl_role_label(role, role->uidgid);
51391 +}
51392 +
51393 +static int
51394 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51395 +{
51396 + struct name_entry **curr, *nentry;
51397 + struct inodev_entry *ientry;
51398 + unsigned int len = strlen(name);
51399 + unsigned int key = full_name_hash(name, len);
51400 + unsigned int index = key % name_set.n_size;
51401 +
51402 + curr = &name_set.n_hash[index];
51403 +
51404 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51405 + curr = &((*curr)->next);
51406 +
51407 + if (*curr != NULL)
51408 + return 1;
51409 +
51410 + nentry = acl_alloc(sizeof (struct name_entry));
51411 + if (nentry == NULL)
51412 + return 0;
51413 + ientry = acl_alloc(sizeof (struct inodev_entry));
51414 + if (ientry == NULL)
51415 + return 0;
51416 + ientry->nentry = nentry;
51417 +
51418 + nentry->key = key;
51419 + nentry->name = name;
51420 + nentry->inode = inode;
51421 + nentry->device = device;
51422 + nentry->len = len;
51423 + nentry->deleted = deleted;
51424 +
51425 + nentry->prev = NULL;
51426 + curr = &name_set.n_hash[index];
51427 + if (*curr != NULL)
51428 + (*curr)->prev = nentry;
51429 + nentry->next = *curr;
51430 + *curr = nentry;
51431 +
51432 + /* insert us into the table searchable by inode/dev */
51433 + insert_inodev_entry(ientry);
51434 +
51435 + return 1;
51436 +}
51437 +
51438 +static void
51439 +insert_acl_obj_label(struct acl_object_label *obj,
51440 + struct acl_subject_label *subj)
51441 +{
51442 + unsigned int index =
51443 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51444 + struct acl_object_label **curr;
51445 +
51446 +
51447 + obj->prev = NULL;
51448 +
51449 + curr = &subj->obj_hash[index];
51450 + if (*curr != NULL)
51451 + (*curr)->prev = obj;
51452 +
51453 + obj->next = *curr;
51454 + *curr = obj;
51455 +
51456 + return;
51457 +}
51458 +
51459 +static void
51460 +insert_acl_subj_label(struct acl_subject_label *obj,
51461 + struct acl_role_label *role)
51462 +{
51463 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51464 + struct acl_subject_label **curr;
51465 +
51466 + obj->prev = NULL;
51467 +
51468 + curr = &role->subj_hash[index];
51469 + if (*curr != NULL)
51470 + (*curr)->prev = obj;
51471 +
51472 + obj->next = *curr;
51473 + *curr = obj;
51474 +
51475 + return;
51476 +}
51477 +
51478 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51479 +
51480 +static void *
51481 +create_table(__u32 * len, int elementsize)
51482 +{
51483 + unsigned int table_sizes[] = {
51484 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51485 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51486 + 4194301, 8388593, 16777213, 33554393, 67108859
51487 + };
51488 + void *newtable = NULL;
51489 + unsigned int pwr = 0;
51490 +
51491 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51492 + table_sizes[pwr] <= *len)
51493 + pwr++;
51494 +
51495 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51496 + return newtable;
51497 +
51498 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51499 + newtable =
51500 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51501 + else
51502 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51503 +
51504 + *len = table_sizes[pwr];
51505 +
51506 + return newtable;
51507 +}
51508 +
51509 +static int
51510 +init_variables(const struct gr_arg *arg)
51511 +{
51512 + struct task_struct *reaper = &init_task;
51513 + unsigned int stacksize;
51514 +
51515 + subj_map_set.s_size = arg->role_db.num_subjects;
51516 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51517 + name_set.n_size = arg->role_db.num_objects;
51518 + inodev_set.i_size = arg->role_db.num_objects;
51519 +
51520 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51521 + !name_set.n_size || !inodev_set.i_size)
51522 + return 1;
51523 +
51524 + if (!gr_init_uidset())
51525 + return 1;
51526 +
51527 + /* set up the stack that holds allocation info */
51528 +
51529 + stacksize = arg->role_db.num_pointers + 5;
51530 +
51531 + if (!acl_alloc_stack_init(stacksize))
51532 + return 1;
51533 +
51534 + /* grab reference for the real root dentry and vfsmount */
51535 + get_fs_root(reaper->fs, &real_root);
51536 +
51537 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51538 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51539 +#endif
51540 +
51541 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51542 + if (fakefs_obj_rw == NULL)
51543 + return 1;
51544 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51545 +
51546 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51547 + if (fakefs_obj_rwx == NULL)
51548 + return 1;
51549 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51550 +
51551 + subj_map_set.s_hash =
51552 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51553 + acl_role_set.r_hash =
51554 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51555 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51556 + inodev_set.i_hash =
51557 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51558 +
51559 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51560 + !name_set.n_hash || !inodev_set.i_hash)
51561 + return 1;
51562 +
51563 + memset(subj_map_set.s_hash, 0,
51564 + sizeof(struct subject_map *) * subj_map_set.s_size);
51565 + memset(acl_role_set.r_hash, 0,
51566 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51567 + memset(name_set.n_hash, 0,
51568 + sizeof (struct name_entry *) * name_set.n_size);
51569 + memset(inodev_set.i_hash, 0,
51570 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51571 +
51572 + return 0;
51573 +}
51574 +
51575 +/* free information not needed after startup
51576 + currently contains user->kernel pointer mappings for subjects
51577 +*/
51578 +
51579 +static void
51580 +free_init_variables(void)
51581 +{
51582 + __u32 i;
51583 +
51584 + if (subj_map_set.s_hash) {
51585 + for (i = 0; i < subj_map_set.s_size; i++) {
51586 + if (subj_map_set.s_hash[i]) {
51587 + kfree(subj_map_set.s_hash[i]);
51588 + subj_map_set.s_hash[i] = NULL;
51589 + }
51590 + }
51591 +
51592 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51593 + PAGE_SIZE)
51594 + kfree(subj_map_set.s_hash);
51595 + else
51596 + vfree(subj_map_set.s_hash);
51597 + }
51598 +
51599 + return;
51600 +}
51601 +
51602 +static void
51603 +free_variables(void)
51604 +{
51605 + struct acl_subject_label *s;
51606 + struct acl_role_label *r;
51607 + struct task_struct *task, *task2;
51608 + unsigned int x;
51609 +
51610 + gr_clear_learn_entries();
51611 +
51612 + read_lock(&tasklist_lock);
51613 + do_each_thread(task2, task) {
51614 + task->acl_sp_role = 0;
51615 + task->acl_role_id = 0;
51616 + task->acl = NULL;
51617 + task->role = NULL;
51618 + } while_each_thread(task2, task);
51619 + read_unlock(&tasklist_lock);
51620 +
51621 + /* release the reference to the real root dentry and vfsmount */
51622 + path_put(&real_root);
51623 + memset(&real_root, 0, sizeof(real_root));
51624 +
51625 + /* free all object hash tables */
51626 +
51627 + FOR_EACH_ROLE_START(r)
51628 + if (r->subj_hash == NULL)
51629 + goto next_role;
51630 + FOR_EACH_SUBJECT_START(r, s, x)
51631 + if (s->obj_hash == NULL)
51632 + break;
51633 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51634 + kfree(s->obj_hash);
51635 + else
51636 + vfree(s->obj_hash);
51637 + FOR_EACH_SUBJECT_END(s, x)
51638 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51639 + if (s->obj_hash == NULL)
51640 + break;
51641 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51642 + kfree(s->obj_hash);
51643 + else
51644 + vfree(s->obj_hash);
51645 + FOR_EACH_NESTED_SUBJECT_END(s)
51646 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51647 + kfree(r->subj_hash);
51648 + else
51649 + vfree(r->subj_hash);
51650 + r->subj_hash = NULL;
51651 +next_role:
51652 + FOR_EACH_ROLE_END(r)
51653 +
51654 + acl_free_all();
51655 +
51656 + if (acl_role_set.r_hash) {
51657 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51658 + PAGE_SIZE)
51659 + kfree(acl_role_set.r_hash);
51660 + else
51661 + vfree(acl_role_set.r_hash);
51662 + }
51663 + if (name_set.n_hash) {
51664 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51665 + PAGE_SIZE)
51666 + kfree(name_set.n_hash);
51667 + else
51668 + vfree(name_set.n_hash);
51669 + }
51670 +
51671 + if (inodev_set.i_hash) {
51672 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51673 + PAGE_SIZE)
51674 + kfree(inodev_set.i_hash);
51675 + else
51676 + vfree(inodev_set.i_hash);
51677 + }
51678 +
51679 + gr_free_uidset();
51680 +
51681 + memset(&name_set, 0, sizeof (struct name_db));
51682 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51683 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51684 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51685 +
51686 + default_role = NULL;
51687 + kernel_role = NULL;
51688 + role_list = NULL;
51689 +
51690 + return;
51691 +}
51692 +
51693 +static __u32
51694 +count_user_objs(struct acl_object_label *userp)
51695 +{
51696 + struct acl_object_label o_tmp;
51697 + __u32 num = 0;
51698 +
51699 + while (userp) {
51700 + if (copy_from_user(&o_tmp, userp,
51701 + sizeof (struct acl_object_label)))
51702 + break;
51703 +
51704 + userp = o_tmp.prev;
51705 + num++;
51706 + }
51707 +
51708 + return num;
51709 +}
51710 +
51711 +static struct acl_subject_label *
51712 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51713 +
51714 +static int
51715 +copy_user_glob(struct acl_object_label *obj)
51716 +{
51717 + struct acl_object_label *g_tmp, **guser;
51718 + unsigned int len;
51719 + char *tmp;
51720 +
51721 + if (obj->globbed == NULL)
51722 + return 0;
51723 +
51724 + guser = &obj->globbed;
51725 + while (*guser) {
51726 + g_tmp = (struct acl_object_label *)
51727 + acl_alloc(sizeof (struct acl_object_label));
51728 + if (g_tmp == NULL)
51729 + return -ENOMEM;
51730 +
51731 + if (copy_from_user(g_tmp, *guser,
51732 + sizeof (struct acl_object_label)))
51733 + return -EFAULT;
51734 +
51735 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51736 +
51737 + if (!len || len >= PATH_MAX)
51738 + return -EINVAL;
51739 +
51740 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51741 + return -ENOMEM;
51742 +
51743 + if (copy_from_user(tmp, g_tmp->filename, len))
51744 + return -EFAULT;
51745 + tmp[len-1] = '\0';
51746 + g_tmp->filename = tmp;
51747 +
51748 + *guser = g_tmp;
51749 + guser = &(g_tmp->next);
51750 + }
51751 +
51752 + return 0;
51753 +}
51754 +
51755 +static int
51756 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51757 + struct acl_role_label *role)
51758 +{
51759 + struct acl_object_label *o_tmp;
51760 + unsigned int len;
51761 + int ret;
51762 + char *tmp;
51763 +
51764 + while (userp) {
51765 + if ((o_tmp = (struct acl_object_label *)
51766 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51767 + return -ENOMEM;
51768 +
51769 + if (copy_from_user(o_tmp, userp,
51770 + sizeof (struct acl_object_label)))
51771 + return -EFAULT;
51772 +
51773 + userp = o_tmp->prev;
51774 +
51775 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51776 +
51777 + if (!len || len >= PATH_MAX)
51778 + return -EINVAL;
51779 +
51780 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51781 + return -ENOMEM;
51782 +
51783 + if (copy_from_user(tmp, o_tmp->filename, len))
51784 + return -EFAULT;
51785 + tmp[len-1] = '\0';
51786 + o_tmp->filename = tmp;
51787 +
51788 + insert_acl_obj_label(o_tmp, subj);
51789 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51790 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51791 + return -ENOMEM;
51792 +
51793 + ret = copy_user_glob(o_tmp);
51794 + if (ret)
51795 + return ret;
51796 +
51797 + if (o_tmp->nested) {
51798 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51799 + if (IS_ERR(o_tmp->nested))
51800 + return PTR_ERR(o_tmp->nested);
51801 +
51802 + /* insert into nested subject list */
51803 + o_tmp->nested->next = role->hash->first;
51804 + role->hash->first = o_tmp->nested;
51805 + }
51806 + }
51807 +
51808 + return 0;
51809 +}
51810 +
51811 +static __u32
51812 +count_user_subjs(struct acl_subject_label *userp)
51813 +{
51814 + struct acl_subject_label s_tmp;
51815 + __u32 num = 0;
51816 +
51817 + while (userp) {
51818 + if (copy_from_user(&s_tmp, userp,
51819 + sizeof (struct acl_subject_label)))
51820 + break;
51821 +
51822 + userp = s_tmp.prev;
51823 + /* do not count nested subjects against this count, since
51824 + they are not included in the hash table, but are
51825 + attached to objects. We have already counted
51826 + the subjects in userspace for the allocation
51827 + stack
51828 + */
51829 + if (!(s_tmp.mode & GR_NESTED))
51830 + num++;
51831 + }
51832 +
51833 + return num;
51834 +}
51835 +
51836 +static int
51837 +copy_user_allowedips(struct acl_role_label *rolep)
51838 +{
51839 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51840 +
51841 + ruserip = rolep->allowed_ips;
51842 +
51843 + while (ruserip) {
51844 + rlast = rtmp;
51845 +
51846 + if ((rtmp = (struct role_allowed_ip *)
51847 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51848 + return -ENOMEM;
51849 +
51850 + if (copy_from_user(rtmp, ruserip,
51851 + sizeof (struct role_allowed_ip)))
51852 + return -EFAULT;
51853 +
51854 + ruserip = rtmp->prev;
51855 +
51856 + if (!rlast) {
51857 + rtmp->prev = NULL;
51858 + rolep->allowed_ips = rtmp;
51859 + } else {
51860 + rlast->next = rtmp;
51861 + rtmp->prev = rlast;
51862 + }
51863 +
51864 + if (!ruserip)
51865 + rtmp->next = NULL;
51866 + }
51867 +
51868 + return 0;
51869 +}
51870 +
51871 +static int
51872 +copy_user_transitions(struct acl_role_label *rolep)
51873 +{
51874 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51875 +
51876 + unsigned int len;
51877 + char *tmp;
51878 +
51879 + rusertp = rolep->transitions;
51880 +
51881 + while (rusertp) {
51882 + rlast = rtmp;
51883 +
51884 + if ((rtmp = (struct role_transition *)
51885 + acl_alloc(sizeof (struct role_transition))) == NULL)
51886 + return -ENOMEM;
51887 +
51888 + if (copy_from_user(rtmp, rusertp,
51889 + sizeof (struct role_transition)))
51890 + return -EFAULT;
51891 +
51892 + rusertp = rtmp->prev;
51893 +
51894 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51895 +
51896 + if (!len || len >= GR_SPROLE_LEN)
51897 + return -EINVAL;
51898 +
51899 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51900 + return -ENOMEM;
51901 +
51902 + if (copy_from_user(tmp, rtmp->rolename, len))
51903 + return -EFAULT;
51904 + tmp[len-1] = '\0';
51905 + rtmp->rolename = tmp;
51906 +
51907 + if (!rlast) {
51908 + rtmp->prev = NULL;
51909 + rolep->transitions = rtmp;
51910 + } else {
51911 + rlast->next = rtmp;
51912 + rtmp->prev = rlast;
51913 + }
51914 +
51915 + if (!rusertp)
51916 + rtmp->next = NULL;
51917 + }
51918 +
51919 + return 0;
51920 +}
51921 +
51922 +static struct acl_subject_label *
51923 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51924 +{
51925 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51926 + unsigned int len;
51927 + char *tmp;
51928 + __u32 num_objs;
51929 + struct acl_ip_label **i_tmp, *i_utmp2;
51930 + struct gr_hash_struct ghash;
51931 + struct subject_map *subjmap;
51932 + unsigned int i_num;
51933 + int err;
51934 +
51935 + s_tmp = lookup_subject_map(userp);
51936 +
51937 + /* we've already copied this subject into the kernel, just return
51938 + the reference to it, and don't copy it over again
51939 + */
51940 + if (s_tmp)
51941 + return(s_tmp);
51942 +
51943 + if ((s_tmp = (struct acl_subject_label *)
51944 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51945 + return ERR_PTR(-ENOMEM);
51946 +
51947 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51948 + if (subjmap == NULL)
51949 + return ERR_PTR(-ENOMEM);
51950 +
51951 + subjmap->user = userp;
51952 + subjmap->kernel = s_tmp;
51953 + insert_subj_map_entry(subjmap);
51954 +
51955 + if (copy_from_user(s_tmp, userp,
51956 + sizeof (struct acl_subject_label)))
51957 + return ERR_PTR(-EFAULT);
51958 +
51959 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51960 +
51961 + if (!len || len >= PATH_MAX)
51962 + return ERR_PTR(-EINVAL);
51963 +
51964 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51965 + return ERR_PTR(-ENOMEM);
51966 +
51967 + if (copy_from_user(tmp, s_tmp->filename, len))
51968 + return ERR_PTR(-EFAULT);
51969 + tmp[len-1] = '\0';
51970 + s_tmp->filename = tmp;
51971 +
51972 + if (!strcmp(s_tmp->filename, "/"))
51973 + role->root_label = s_tmp;
51974 +
51975 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51976 + return ERR_PTR(-EFAULT);
51977 +
51978 + /* copy user and group transition tables */
51979 +
51980 + if (s_tmp->user_trans_num) {
51981 + uid_t *uidlist;
51982 +
51983 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51984 + if (uidlist == NULL)
51985 + return ERR_PTR(-ENOMEM);
51986 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51987 + return ERR_PTR(-EFAULT);
51988 +
51989 + s_tmp->user_transitions = uidlist;
51990 + }
51991 +
51992 + if (s_tmp->group_trans_num) {
51993 + gid_t *gidlist;
51994 +
51995 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51996 + if (gidlist == NULL)
51997 + return ERR_PTR(-ENOMEM);
51998 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51999 + return ERR_PTR(-EFAULT);
52000 +
52001 + s_tmp->group_transitions = gidlist;
52002 + }
52003 +
52004 + /* set up object hash table */
52005 + num_objs = count_user_objs(ghash.first);
52006 +
52007 + s_tmp->obj_hash_size = num_objs;
52008 + s_tmp->obj_hash =
52009 + (struct acl_object_label **)
52010 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52011 +
52012 + if (!s_tmp->obj_hash)
52013 + return ERR_PTR(-ENOMEM);
52014 +
52015 + memset(s_tmp->obj_hash, 0,
52016 + s_tmp->obj_hash_size *
52017 + sizeof (struct acl_object_label *));
52018 +
52019 + /* add in objects */
52020 + err = copy_user_objs(ghash.first, s_tmp, role);
52021 +
52022 + if (err)
52023 + return ERR_PTR(err);
52024 +
52025 + /* set pointer for parent subject */
52026 + if (s_tmp->parent_subject) {
52027 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52028 +
52029 + if (IS_ERR(s_tmp2))
52030 + return s_tmp2;
52031 +
52032 + s_tmp->parent_subject = s_tmp2;
52033 + }
52034 +
52035 + /* add in ip acls */
52036 +
52037 + if (!s_tmp->ip_num) {
52038 + s_tmp->ips = NULL;
52039 + goto insert;
52040 + }
52041 +
52042 + i_tmp =
52043 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52044 + sizeof (struct acl_ip_label *));
52045 +
52046 + if (!i_tmp)
52047 + return ERR_PTR(-ENOMEM);
52048 +
52049 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52050 + *(i_tmp + i_num) =
52051 + (struct acl_ip_label *)
52052 + acl_alloc(sizeof (struct acl_ip_label));
52053 + if (!*(i_tmp + i_num))
52054 + return ERR_PTR(-ENOMEM);
52055 +
52056 + if (copy_from_user
52057 + (&i_utmp2, s_tmp->ips + i_num,
52058 + sizeof (struct acl_ip_label *)))
52059 + return ERR_PTR(-EFAULT);
52060 +
52061 + if (copy_from_user
52062 + (*(i_tmp + i_num), i_utmp2,
52063 + sizeof (struct acl_ip_label)))
52064 + return ERR_PTR(-EFAULT);
52065 +
52066 + if ((*(i_tmp + i_num))->iface == NULL)
52067 + continue;
52068 +
52069 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52070 + if (!len || len >= IFNAMSIZ)
52071 + return ERR_PTR(-EINVAL);
52072 + tmp = acl_alloc(len);
52073 + if (tmp == NULL)
52074 + return ERR_PTR(-ENOMEM);
52075 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52076 + return ERR_PTR(-EFAULT);
52077 + (*(i_tmp + i_num))->iface = tmp;
52078 + }
52079 +
52080 + s_tmp->ips = i_tmp;
52081 +
52082 +insert:
52083 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52084 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52085 + return ERR_PTR(-ENOMEM);
52086 +
52087 + return s_tmp;
52088 +}
52089 +
52090 +static int
52091 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52092 +{
52093 + struct acl_subject_label s_pre;
52094 + struct acl_subject_label * ret;
52095 + int err;
52096 +
52097 + while (userp) {
52098 + if (copy_from_user(&s_pre, userp,
52099 + sizeof (struct acl_subject_label)))
52100 + return -EFAULT;
52101 +
52102 + /* do not add nested subjects here, add
52103 + while parsing objects
52104 + */
52105 +
52106 + if (s_pre.mode & GR_NESTED) {
52107 + userp = s_pre.prev;
52108 + continue;
52109 + }
52110 +
52111 + ret = do_copy_user_subj(userp, role);
52112 +
52113 + err = PTR_ERR(ret);
52114 + if (IS_ERR(ret))
52115 + return err;
52116 +
52117 + insert_acl_subj_label(ret, role);
52118 +
52119 + userp = s_pre.prev;
52120 + }
52121 +
52122 + return 0;
52123 +}
52124 +
52125 +static int
52126 +copy_user_acl(struct gr_arg *arg)
52127 +{
52128 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52129 + struct sprole_pw *sptmp;
52130 + struct gr_hash_struct *ghash;
52131 + uid_t *domainlist;
52132 + unsigned int r_num;
52133 + unsigned int len;
52134 + char *tmp;
52135 + int err = 0;
52136 + __u16 i;
52137 + __u32 num_subjs;
52138 +
52139 + /* we need a default and kernel role */
52140 + if (arg->role_db.num_roles < 2)
52141 + return -EINVAL;
52142 +
52143 + /* copy special role authentication info from userspace */
52144 +
52145 + num_sprole_pws = arg->num_sprole_pws;
52146 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52147 +
52148 + if (!acl_special_roles && num_sprole_pws)
52149 + return -ENOMEM;
52150 +
52151 + for (i = 0; i < num_sprole_pws; i++) {
52152 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52153 + if (!sptmp)
52154 + return -ENOMEM;
52155 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52156 + sizeof (struct sprole_pw)))
52157 + return -EFAULT;
52158 +
52159 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52160 +
52161 + if (!len || len >= GR_SPROLE_LEN)
52162 + return -EINVAL;
52163 +
52164 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52165 + return -ENOMEM;
52166 +
52167 + if (copy_from_user(tmp, sptmp->rolename, len))
52168 + return -EFAULT;
52169 +
52170 + tmp[len-1] = '\0';
52171 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52172 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52173 +#endif
52174 + sptmp->rolename = tmp;
52175 + acl_special_roles[i] = sptmp;
52176 + }
52177 +
52178 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52179 +
52180 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52181 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52182 +
52183 + if (!r_tmp)
52184 + return -ENOMEM;
52185 +
52186 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52187 + sizeof (struct acl_role_label *)))
52188 + return -EFAULT;
52189 +
52190 + if (copy_from_user(r_tmp, r_utmp2,
52191 + sizeof (struct acl_role_label)))
52192 + return -EFAULT;
52193 +
52194 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52195 +
52196 + if (!len || len >= PATH_MAX)
52197 + return -EINVAL;
52198 +
52199 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52200 + return -ENOMEM;
52201 +
52202 + if (copy_from_user(tmp, r_tmp->rolename, len))
52203 + return -EFAULT;
52204 +
52205 + tmp[len-1] = '\0';
52206 + r_tmp->rolename = tmp;
52207 +
52208 + if (!strcmp(r_tmp->rolename, "default")
52209 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52210 + default_role = r_tmp;
52211 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52212 + kernel_role = r_tmp;
52213 + }
52214 +
52215 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52216 + return -ENOMEM;
52217 +
52218 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52219 + return -EFAULT;
52220 +
52221 + r_tmp->hash = ghash;
52222 +
52223 + num_subjs = count_user_subjs(r_tmp->hash->first);
52224 +
52225 + r_tmp->subj_hash_size = num_subjs;
52226 + r_tmp->subj_hash =
52227 + (struct acl_subject_label **)
52228 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52229 +
52230 + if (!r_tmp->subj_hash)
52231 + return -ENOMEM;
52232 +
52233 + err = copy_user_allowedips(r_tmp);
52234 + if (err)
52235 + return err;
52236 +
52237 + /* copy domain info */
52238 + if (r_tmp->domain_children != NULL) {
52239 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52240 + if (domainlist == NULL)
52241 + return -ENOMEM;
52242 +
52243 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52244 + return -EFAULT;
52245 +
52246 + r_tmp->domain_children = domainlist;
52247 + }
52248 +
52249 + err = copy_user_transitions(r_tmp);
52250 + if (err)
52251 + return err;
52252 +
52253 + memset(r_tmp->subj_hash, 0,
52254 + r_tmp->subj_hash_size *
52255 + sizeof (struct acl_subject_label *));
52256 +
52257 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52258 +
52259 + if (err)
52260 + return err;
52261 +
52262 + /* set nested subject list to null */
52263 + r_tmp->hash->first = NULL;
52264 +
52265 + insert_acl_role_label(r_tmp);
52266 + }
52267 +
52268 + if (default_role == NULL || kernel_role == NULL)
52269 + return -EINVAL;
52270 +
52271 + return err;
52272 +}
52273 +
52274 +static int
52275 +gracl_init(struct gr_arg *args)
52276 +{
52277 + int error = 0;
52278 +
52279 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52280 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52281 +
52282 + if (init_variables(args)) {
52283 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52284 + error = -ENOMEM;
52285 + free_variables();
52286 + goto out;
52287 + }
52288 +
52289 + error = copy_user_acl(args);
52290 + free_init_variables();
52291 + if (error) {
52292 + free_variables();
52293 + goto out;
52294 + }
52295 +
52296 + if ((error = gr_set_acls(0))) {
52297 + free_variables();
52298 + goto out;
52299 + }
52300 +
52301 + pax_open_kernel();
52302 + gr_status |= GR_READY;
52303 + pax_close_kernel();
52304 +
52305 + out:
52306 + return error;
52307 +}
52308 +
52309 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52310 +
52311 +static int
52312 +glob_match(const char *p, const char *n)
52313 +{
52314 + char c;
52315 +
52316 + while ((c = *p++) != '\0') {
52317 + switch (c) {
52318 + case '?':
52319 + if (*n == '\0')
52320 + return 1;
52321 + else if (*n == '/')
52322 + return 1;
52323 + break;
52324 + case '\\':
52325 + if (*n != c)
52326 + return 1;
52327 + break;
52328 + case '*':
52329 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52330 + if (*n == '/')
52331 + return 1;
52332 + else if (c == '?') {
52333 + if (*n == '\0')
52334 + return 1;
52335 + else
52336 + ++n;
52337 + }
52338 + }
52339 + if (c == '\0') {
52340 + return 0;
52341 + } else {
52342 + const char *endp;
52343 +
52344 + if ((endp = strchr(n, '/')) == NULL)
52345 + endp = n + strlen(n);
52346 +
52347 + if (c == '[') {
52348 + for (--p; n < endp; ++n)
52349 + if (!glob_match(p, n))
52350 + return 0;
52351 + } else if (c == '/') {
52352 + while (*n != '\0' && *n != '/')
52353 + ++n;
52354 + if (*n == '/' && !glob_match(p, n + 1))
52355 + return 0;
52356 + } else {
52357 + for (--p; n < endp; ++n)
52358 + if (*n == c && !glob_match(p, n))
52359 + return 0;
52360 + }
52361 +
52362 + return 1;
52363 + }
52364 + case '[':
52365 + {
52366 + int not;
52367 + char cold;
52368 +
52369 + if (*n == '\0' || *n == '/')
52370 + return 1;
52371 +
52372 + not = (*p == '!' || *p == '^');
52373 + if (not)
52374 + ++p;
52375 +
52376 + c = *p++;
52377 + for (;;) {
52378 + unsigned char fn = (unsigned char)*n;
52379 +
52380 + if (c == '\0')
52381 + return 1;
52382 + else {
52383 + if (c == fn)
52384 + goto matched;
52385 + cold = c;
52386 + c = *p++;
52387 +
52388 + if (c == '-' && *p != ']') {
52389 + unsigned char cend = *p++;
52390 +
52391 + if (cend == '\0')
52392 + return 1;
52393 +
52394 + if (cold <= fn && fn <= cend)
52395 + goto matched;
52396 +
52397 + c = *p++;
52398 + }
52399 + }
52400 +
52401 + if (c == ']')
52402 + break;
52403 + }
52404 + if (!not)
52405 + return 1;
52406 + break;
52407 + matched:
52408 + while (c != ']') {
52409 + if (c == '\0')
52410 + return 1;
52411 +
52412 + c = *p++;
52413 + }
52414 + if (not)
52415 + return 1;
52416 + }
52417 + break;
52418 + default:
52419 + if (c != *n)
52420 + return 1;
52421 + }
52422 +
52423 + ++n;
52424 + }
52425 +
52426 + if (*n == '\0')
52427 + return 0;
52428 +
52429 + if (*n == '/')
52430 + return 0;
52431 +
52432 + return 1;
52433 +}
52434 +
52435 +static struct acl_object_label *
52436 +chk_glob_label(struct acl_object_label *globbed,
52437 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52438 +{
52439 + struct acl_object_label *tmp;
52440 +
52441 + if (*path == NULL)
52442 + *path = gr_to_filename_nolock(dentry, mnt);
52443 +
52444 + tmp = globbed;
52445 +
52446 + while (tmp) {
52447 + if (!glob_match(tmp->filename, *path))
52448 + return tmp;
52449 + tmp = tmp->next;
52450 + }
52451 +
52452 + return NULL;
52453 +}
52454 +
52455 +static struct acl_object_label *
52456 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52457 + const ino_t curr_ino, const dev_t curr_dev,
52458 + const struct acl_subject_label *subj, char **path, const int checkglob)
52459 +{
52460 + struct acl_subject_label *tmpsubj;
52461 + struct acl_object_label *retval;
52462 + struct acl_object_label *retval2;
52463 +
52464 + tmpsubj = (struct acl_subject_label *) subj;
52465 + read_lock(&gr_inode_lock);
52466 + do {
52467 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52468 + if (retval) {
52469 + if (checkglob && retval->globbed) {
52470 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52471 + if (retval2)
52472 + retval = retval2;
52473 + }
52474 + break;
52475 + }
52476 + } while ((tmpsubj = tmpsubj->parent_subject));
52477 + read_unlock(&gr_inode_lock);
52478 +
52479 + return retval;
52480 +}
52481 +
52482 +static __inline__ struct acl_object_label *
52483 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52484 + struct dentry *curr_dentry,
52485 + const struct acl_subject_label *subj, char **path, const int checkglob)
52486 +{
52487 + int newglob = checkglob;
52488 + ino_t inode;
52489 + dev_t device;
52490 +
52491 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52492 + as we don't want a / * rule to match instead of the / object
52493 + don't do this for create lookups that call this function though, since they're looking up
52494 + on the parent and thus need globbing checks on all paths
52495 + */
52496 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52497 + newglob = GR_NO_GLOB;
52498 +
52499 + spin_lock(&curr_dentry->d_lock);
52500 + inode = curr_dentry->d_inode->i_ino;
52501 + device = __get_dev(curr_dentry);
52502 + spin_unlock(&curr_dentry->d_lock);
52503 +
52504 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52505 +}
52506 +
52507 +static struct acl_object_label *
52508 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52509 + const struct acl_subject_label *subj, char *path, const int checkglob)
52510 +{
52511 + struct dentry *dentry = (struct dentry *) l_dentry;
52512 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52513 + struct mount *real_mnt = real_mount(mnt);
52514 + struct acl_object_label *retval;
52515 + struct dentry *parent;
52516 +
52517 + write_seqlock(&rename_lock);
52518 + br_read_lock(vfsmount_lock);
52519 +
52520 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52521 +#ifdef CONFIG_NET
52522 + mnt == sock_mnt ||
52523 +#endif
52524 +#ifdef CONFIG_HUGETLBFS
52525 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52526 +#endif
52527 + /* ignore Eric Biederman */
52528 + IS_PRIVATE(l_dentry->d_inode))) {
52529 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52530 + goto out;
52531 + }
52532 +
52533 + for (;;) {
52534 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52535 + break;
52536 +
52537 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52538 + if (!mnt_has_parent(real_mnt))
52539 + break;
52540 +
52541 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52542 + if (retval != NULL)
52543 + goto out;
52544 +
52545 + dentry = real_mnt->mnt_mountpoint;
52546 + real_mnt = real_mnt->mnt_parent;
52547 + mnt = &real_mnt->mnt;
52548 + continue;
52549 + }
52550 +
52551 + parent = dentry->d_parent;
52552 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52553 + if (retval != NULL)
52554 + goto out;
52555 +
52556 + dentry = parent;
52557 + }
52558 +
52559 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52560 +
52561 + /* real_root is pinned so we don't have to hold a reference */
52562 + if (retval == NULL)
52563 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52564 +out:
52565 + br_read_unlock(vfsmount_lock);
52566 + write_sequnlock(&rename_lock);
52567 +
52568 + BUG_ON(retval == NULL);
52569 +
52570 + return retval;
52571 +}
52572 +
52573 +static __inline__ struct acl_object_label *
52574 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52575 + const struct acl_subject_label *subj)
52576 +{
52577 + char *path = NULL;
52578 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52579 +}
52580 +
52581 +static __inline__ struct acl_object_label *
52582 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52583 + const struct acl_subject_label *subj)
52584 +{
52585 + char *path = NULL;
52586 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52587 +}
52588 +
52589 +static __inline__ struct acl_object_label *
52590 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52591 + const struct acl_subject_label *subj, char *path)
52592 +{
52593 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52594 +}
52595 +
52596 +static struct acl_subject_label *
52597 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52598 + const struct acl_role_label *role)
52599 +{
52600 + struct dentry *dentry = (struct dentry *) l_dentry;
52601 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52602 + struct mount *real_mnt = real_mount(mnt);
52603 + struct acl_subject_label *retval;
52604 + struct dentry *parent;
52605 +
52606 + write_seqlock(&rename_lock);
52607 + br_read_lock(vfsmount_lock);
52608 +
52609 + for (;;) {
52610 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52611 + break;
52612 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52613 + if (!mnt_has_parent(real_mnt))
52614 + break;
52615 +
52616 + spin_lock(&dentry->d_lock);
52617 + read_lock(&gr_inode_lock);
52618 + retval =
52619 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52620 + __get_dev(dentry), role);
52621 + read_unlock(&gr_inode_lock);
52622 + spin_unlock(&dentry->d_lock);
52623 + if (retval != NULL)
52624 + goto out;
52625 +
52626 + dentry = real_mnt->mnt_mountpoint;
52627 + real_mnt = real_mnt->mnt_parent;
52628 + mnt = &real_mnt->mnt;
52629 + continue;
52630 + }
52631 +
52632 + spin_lock(&dentry->d_lock);
52633 + read_lock(&gr_inode_lock);
52634 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52635 + __get_dev(dentry), role);
52636 + read_unlock(&gr_inode_lock);
52637 + parent = dentry->d_parent;
52638 + spin_unlock(&dentry->d_lock);
52639 +
52640 + if (retval != NULL)
52641 + goto out;
52642 +
52643 + dentry = parent;
52644 + }
52645 +
52646 + spin_lock(&dentry->d_lock);
52647 + read_lock(&gr_inode_lock);
52648 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52649 + __get_dev(dentry), role);
52650 + read_unlock(&gr_inode_lock);
52651 + spin_unlock(&dentry->d_lock);
52652 +
52653 + if (unlikely(retval == NULL)) {
52654 + /* real_root is pinned, we don't need to hold a reference */
52655 + read_lock(&gr_inode_lock);
52656 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52657 + __get_dev(real_root.dentry), role);
52658 + read_unlock(&gr_inode_lock);
52659 + }
52660 +out:
52661 + br_read_unlock(vfsmount_lock);
52662 + write_sequnlock(&rename_lock);
52663 +
52664 + BUG_ON(retval == NULL);
52665 +
52666 + return retval;
52667 +}
52668 +
52669 +static void
52670 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52671 +{
52672 + struct task_struct *task = current;
52673 + const struct cred *cred = current_cred();
52674 +
52675 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52676 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52677 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52678 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52679 +
52680 + return;
52681 +}
52682 +
52683 +static void
52684 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52685 +{
52686 + struct task_struct *task = current;
52687 + const struct cred *cred = current_cred();
52688 +
52689 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52690 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52691 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52692 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52693 +
52694 + return;
52695 +}
52696 +
52697 +static void
52698 +gr_log_learn_id_change(const char type, const unsigned int real,
52699 + const unsigned int effective, const unsigned int fs)
52700 +{
52701 + struct task_struct *task = current;
52702 + const struct cred *cred = current_cred();
52703 +
52704 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52705 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52706 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52707 + type, real, effective, fs, &task->signal->saved_ip);
52708 +
52709 + return;
52710 +}
52711 +
52712 +__u32
52713 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52714 + const struct vfsmount * mnt)
52715 +{
52716 + __u32 retval = mode;
52717 + struct acl_subject_label *curracl;
52718 + struct acl_object_label *currobj;
52719 +
52720 + if (unlikely(!(gr_status & GR_READY)))
52721 + return (mode & ~GR_AUDITS);
52722 +
52723 + curracl = current->acl;
52724 +
52725 + currobj = chk_obj_label(dentry, mnt, curracl);
52726 + retval = currobj->mode & mode;
52727 +
52728 + /* if we're opening a specified transfer file for writing
52729 + (e.g. /dev/initctl), then transfer our role to init
52730 + */
52731 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52732 + current->role->roletype & GR_ROLE_PERSIST)) {
52733 + struct task_struct *task = init_pid_ns.child_reaper;
52734 +
52735 + if (task->role != current->role) {
52736 + task->acl_sp_role = 0;
52737 + task->acl_role_id = current->acl_role_id;
52738 + task->role = current->role;
52739 + rcu_read_lock();
52740 + read_lock(&grsec_exec_file_lock);
52741 + gr_apply_subject_to_task(task);
52742 + read_unlock(&grsec_exec_file_lock);
52743 + rcu_read_unlock();
52744 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52745 + }
52746 + }
52747 +
52748 + if (unlikely
52749 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52750 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52751 + __u32 new_mode = mode;
52752 +
52753 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52754 +
52755 + retval = new_mode;
52756 +
52757 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52758 + new_mode |= GR_INHERIT;
52759 +
52760 + if (!(mode & GR_NOLEARN))
52761 + gr_log_learn(dentry, mnt, new_mode);
52762 + }
52763 +
52764 + return retval;
52765 +}
52766 +
52767 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52768 + const struct dentry *parent,
52769 + const struct vfsmount *mnt)
52770 +{
52771 + struct name_entry *match;
52772 + struct acl_object_label *matchpo;
52773 + struct acl_subject_label *curracl;
52774 + char *path;
52775 +
52776 + if (unlikely(!(gr_status & GR_READY)))
52777 + return NULL;
52778 +
52779 + preempt_disable();
52780 + path = gr_to_filename_rbac(new_dentry, mnt);
52781 + match = lookup_name_entry_create(path);
52782 +
52783 + curracl = current->acl;
52784 +
52785 + if (match) {
52786 + read_lock(&gr_inode_lock);
52787 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52788 + read_unlock(&gr_inode_lock);
52789 +
52790 + if (matchpo) {
52791 + preempt_enable();
52792 + return matchpo;
52793 + }
52794 + }
52795 +
52796 + // lookup parent
52797 +
52798 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52799 +
52800 + preempt_enable();
52801 + return matchpo;
52802 +}
52803 +
52804 +__u32
52805 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52806 + const struct vfsmount * mnt, const __u32 mode)
52807 +{
52808 + struct acl_object_label *matchpo;
52809 + __u32 retval;
52810 +
52811 + if (unlikely(!(gr_status & GR_READY)))
52812 + return (mode & ~GR_AUDITS);
52813 +
52814 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52815 +
52816 + retval = matchpo->mode & mode;
52817 +
52818 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52819 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52820 + __u32 new_mode = mode;
52821 +
52822 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52823 +
52824 + gr_log_learn(new_dentry, mnt, new_mode);
52825 + return new_mode;
52826 + }
52827 +
52828 + return retval;
52829 +}
52830 +
52831 +__u32
52832 +gr_check_link(const struct dentry * new_dentry,
52833 + const struct dentry * parent_dentry,
52834 + const struct vfsmount * parent_mnt,
52835 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52836 +{
52837 + struct acl_object_label *obj;
52838 + __u32 oldmode, newmode;
52839 + __u32 needmode;
52840 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52841 + GR_DELETE | GR_INHERIT;
52842 +
52843 + if (unlikely(!(gr_status & GR_READY)))
52844 + return (GR_CREATE | GR_LINK);
52845 +
52846 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52847 + oldmode = obj->mode;
52848 +
52849 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52850 + newmode = obj->mode;
52851 +
52852 + needmode = newmode & checkmodes;
52853 +
52854 + // old name for hardlink must have at least the permissions of the new name
52855 + if ((oldmode & needmode) != needmode)
52856 + goto bad;
52857 +
52858 + // if old name had restrictions/auditing, make sure the new name does as well
52859 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52860 +
52861 + // don't allow hardlinking of suid/sgid files without permission
52862 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52863 + needmode |= GR_SETID;
52864 +
52865 + if ((newmode & needmode) != needmode)
52866 + goto bad;
52867 +
52868 + // enforce minimum permissions
52869 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52870 + return newmode;
52871 +bad:
52872 + needmode = oldmode;
52873 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52874 + needmode |= GR_SETID;
52875 +
52876 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52877 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52878 + return (GR_CREATE | GR_LINK);
52879 + } else if (newmode & GR_SUPPRESS)
52880 + return GR_SUPPRESS;
52881 + else
52882 + return 0;
52883 +}
52884 +
52885 +int
52886 +gr_check_hidden_task(const struct task_struct *task)
52887 +{
52888 + if (unlikely(!(gr_status & GR_READY)))
52889 + return 0;
52890 +
52891 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52892 + return 1;
52893 +
52894 + return 0;
52895 +}
52896 +
52897 +int
52898 +gr_check_protected_task(const struct task_struct *task)
52899 +{
52900 + if (unlikely(!(gr_status & GR_READY) || !task))
52901 + return 0;
52902 +
52903 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52904 + task->acl != current->acl)
52905 + return 1;
52906 +
52907 + return 0;
52908 +}
52909 +
52910 +int
52911 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52912 +{
52913 + struct task_struct *p;
52914 + int ret = 0;
52915 +
52916 + if (unlikely(!(gr_status & GR_READY) || !pid))
52917 + return ret;
52918 +
52919 + read_lock(&tasklist_lock);
52920 + do_each_pid_task(pid, type, p) {
52921 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52922 + p->acl != current->acl) {
52923 + ret = 1;
52924 + goto out;
52925 + }
52926 + } while_each_pid_task(pid, type, p);
52927 +out:
52928 + read_unlock(&tasklist_lock);
52929 +
52930 + return ret;
52931 +}
52932 +
52933 +void
52934 +gr_copy_label(struct task_struct *tsk)
52935 +{
52936 + /* plain copying of fields is already done by dup_task_struct */
52937 + tsk->signal->used_accept = 0;
52938 + tsk->acl_sp_role = 0;
52939 + //tsk->acl_role_id = current->acl_role_id;
52940 + //tsk->acl = current->acl;
52941 + //tsk->role = current->role;
52942 + tsk->signal->curr_ip = current->signal->curr_ip;
52943 + tsk->signal->saved_ip = current->signal->saved_ip;
52944 + if (current->exec_file)
52945 + get_file(current->exec_file);
52946 + //tsk->exec_file = current->exec_file;
52947 + //tsk->is_writable = current->is_writable;
52948 + if (unlikely(current->signal->used_accept)) {
52949 + current->signal->curr_ip = 0;
52950 + current->signal->saved_ip = 0;
52951 + }
52952 +
52953 + return;
52954 +}
52955 +
52956 +static void
52957 +gr_set_proc_res(struct task_struct *task)
52958 +{
52959 + struct acl_subject_label *proc;
52960 + unsigned short i;
52961 +
52962 + proc = task->acl;
52963 +
52964 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52965 + return;
52966 +
52967 + for (i = 0; i < RLIM_NLIMITS; i++) {
52968 + if (!(proc->resmask & (1 << i)))
52969 + continue;
52970 +
52971 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52972 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52973 + }
52974 +
52975 + return;
52976 +}
52977 +
52978 +extern int __gr_process_user_ban(struct user_struct *user);
52979 +
52980 +int
52981 +gr_check_user_change(int real, int effective, int fs)
52982 +{
52983 + unsigned int i;
52984 + __u16 num;
52985 + uid_t *uidlist;
52986 + int curuid;
52987 + int realok = 0;
52988 + int effectiveok = 0;
52989 + int fsok = 0;
52990 +
52991 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52992 + struct user_struct *user;
52993 +
52994 + if (real == -1)
52995 + goto skipit;
52996 +
52997 + user = find_user(real);
52998 + if (user == NULL)
52999 + goto skipit;
53000 +
53001 + if (__gr_process_user_ban(user)) {
53002 + /* for find_user */
53003 + free_uid(user);
53004 + return 1;
53005 + }
53006 +
53007 + /* for find_user */
53008 + free_uid(user);
53009 +
53010 +skipit:
53011 +#endif
53012 +
53013 + if (unlikely(!(gr_status & GR_READY)))
53014 + return 0;
53015 +
53016 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53017 + gr_log_learn_id_change('u', real, effective, fs);
53018 +
53019 + num = current->acl->user_trans_num;
53020 + uidlist = current->acl->user_transitions;
53021 +
53022 + if (uidlist == NULL)
53023 + return 0;
53024 +
53025 + if (real == -1)
53026 + realok = 1;
53027 + if (effective == -1)
53028 + effectiveok = 1;
53029 + if (fs == -1)
53030 + fsok = 1;
53031 +
53032 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53033 + for (i = 0; i < num; i++) {
53034 + curuid = (int)uidlist[i];
53035 + if (real == curuid)
53036 + realok = 1;
53037 + if (effective == curuid)
53038 + effectiveok = 1;
53039 + if (fs == curuid)
53040 + fsok = 1;
53041 + }
53042 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53043 + for (i = 0; i < num; i++) {
53044 + curuid = (int)uidlist[i];
53045 + if (real == curuid)
53046 + break;
53047 + if (effective == curuid)
53048 + break;
53049 + if (fs == curuid)
53050 + break;
53051 + }
53052 + /* not in deny list */
53053 + if (i == num) {
53054 + realok = 1;
53055 + effectiveok = 1;
53056 + fsok = 1;
53057 + }
53058 + }
53059 +
53060 + if (realok && effectiveok && fsok)
53061 + return 0;
53062 + else {
53063 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53064 + return 1;
53065 + }
53066 +}
53067 +
53068 +int
53069 +gr_check_group_change(int real, int effective, int fs)
53070 +{
53071 + unsigned int i;
53072 + __u16 num;
53073 + gid_t *gidlist;
53074 + int curgid;
53075 + int realok = 0;
53076 + int effectiveok = 0;
53077 + int fsok = 0;
53078 +
53079 + if (unlikely(!(gr_status & GR_READY)))
53080 + return 0;
53081 +
53082 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53083 + gr_log_learn_id_change('g', real, effective, fs);
53084 +
53085 + num = current->acl->group_trans_num;
53086 + gidlist = current->acl->group_transitions;
53087 +
53088 + if (gidlist == NULL)
53089 + return 0;
53090 +
53091 + if (real == -1)
53092 + realok = 1;
53093 + if (effective == -1)
53094 + effectiveok = 1;
53095 + if (fs == -1)
53096 + fsok = 1;
53097 +
53098 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53099 + for (i = 0; i < num; i++) {
53100 + curgid = (int)gidlist[i];
53101 + if (real == curgid)
53102 + realok = 1;
53103 + if (effective == curgid)
53104 + effectiveok = 1;
53105 + if (fs == curgid)
53106 + fsok = 1;
53107 + }
53108 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53109 + for (i = 0; i < num; i++) {
53110 + curgid = (int)gidlist[i];
53111 + if (real == curgid)
53112 + break;
53113 + if (effective == curgid)
53114 + break;
53115 + if (fs == curgid)
53116 + break;
53117 + }
53118 + /* not in deny list */
53119 + if (i == num) {
53120 + realok = 1;
53121 + effectiveok = 1;
53122 + fsok = 1;
53123 + }
53124 + }
53125 +
53126 + if (realok && effectiveok && fsok)
53127 + return 0;
53128 + else {
53129 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53130 + return 1;
53131 + }
53132 +}
53133 +
53134 +extern int gr_acl_is_capable(const int cap);
53135 +
53136 +void
53137 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53138 +{
53139 + struct acl_role_label *role = task->role;
53140 + struct acl_subject_label *subj = NULL;
53141 + struct acl_object_label *obj;
53142 + struct file *filp;
53143 +
53144 + if (unlikely(!(gr_status & GR_READY)))
53145 + return;
53146 +
53147 + filp = task->exec_file;
53148 +
53149 + /* kernel process, we'll give them the kernel role */
53150 + if (unlikely(!filp)) {
53151 + task->role = kernel_role;
53152 + task->acl = kernel_role->root_label;
53153 + return;
53154 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53155 + role = lookup_acl_role_label(task, uid, gid);
53156 +
53157 + /* don't change the role if we're not a privileged process */
53158 + if (role && task->role != role &&
53159 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53160 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53161 + return;
53162 +
53163 + /* perform subject lookup in possibly new role
53164 + we can use this result below in the case where role == task->role
53165 + */
53166 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53167 +
53168 + /* if we changed uid/gid, but result in the same role
53169 + and are using inheritance, don't lose the inherited subject
53170 + if current subject is other than what normal lookup
53171 + would result in, we arrived via inheritance, don't
53172 + lose subject
53173 + */
53174 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53175 + (subj == task->acl)))
53176 + task->acl = subj;
53177 +
53178 + task->role = role;
53179 +
53180 + task->is_writable = 0;
53181 +
53182 + /* ignore additional mmap checks for processes that are writable
53183 + by the default ACL */
53184 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53185 + if (unlikely(obj->mode & GR_WRITE))
53186 + task->is_writable = 1;
53187 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53188 + if (unlikely(obj->mode & GR_WRITE))
53189 + task->is_writable = 1;
53190 +
53191 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53192 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53193 +#endif
53194 +
53195 + gr_set_proc_res(task);
53196 +
53197 + return;
53198 +}
53199 +
53200 +int
53201 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53202 + const int unsafe_flags)
53203 +{
53204 + struct task_struct *task = current;
53205 + struct acl_subject_label *newacl;
53206 + struct acl_object_label *obj;
53207 + __u32 retmode;
53208 +
53209 + if (unlikely(!(gr_status & GR_READY)))
53210 + return 0;
53211 +
53212 + newacl = chk_subj_label(dentry, mnt, task->role);
53213 +
53214 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53215 + did an exec
53216 + */
53217 + rcu_read_lock();
53218 + read_lock(&tasklist_lock);
53219 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53220 + (task->parent->acl->mode & GR_POVERRIDE))) {
53221 + read_unlock(&tasklist_lock);
53222 + rcu_read_unlock();
53223 + goto skip_check;
53224 + }
53225 + read_unlock(&tasklist_lock);
53226 + rcu_read_unlock();
53227 +
53228 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53229 + !(task->role->roletype & GR_ROLE_GOD) &&
53230 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53231 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53232 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53233 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53234 + else
53235 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53236 + return -EACCES;
53237 + }
53238 +
53239 +skip_check:
53240 +
53241 + obj = chk_obj_label(dentry, mnt, task->acl);
53242 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53243 +
53244 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53245 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53246 + if (obj->nested)
53247 + task->acl = obj->nested;
53248 + else
53249 + task->acl = newacl;
53250 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53251 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53252 +
53253 + task->is_writable = 0;
53254 +
53255 + /* ignore additional mmap checks for processes that are writable
53256 + by the default ACL */
53257 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53258 + if (unlikely(obj->mode & GR_WRITE))
53259 + task->is_writable = 1;
53260 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53261 + if (unlikely(obj->mode & GR_WRITE))
53262 + task->is_writable = 1;
53263 +
53264 + gr_set_proc_res(task);
53265 +
53266 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53267 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53268 +#endif
53269 + return 0;
53270 +}
53271 +
53272 +/* always called with valid inodev ptr */
53273 +static void
53274 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53275 +{
53276 + struct acl_object_label *matchpo;
53277 + struct acl_subject_label *matchps;
53278 + struct acl_subject_label *subj;
53279 + struct acl_role_label *role;
53280 + unsigned int x;
53281 +
53282 + FOR_EACH_ROLE_START(role)
53283 + FOR_EACH_SUBJECT_START(role, subj, x)
53284 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53285 + matchpo->mode |= GR_DELETED;
53286 + FOR_EACH_SUBJECT_END(subj,x)
53287 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53288 + if (subj->inode == ino && subj->device == dev)
53289 + subj->mode |= GR_DELETED;
53290 + FOR_EACH_NESTED_SUBJECT_END(subj)
53291 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53292 + matchps->mode |= GR_DELETED;
53293 + FOR_EACH_ROLE_END(role)
53294 +
53295 + inodev->nentry->deleted = 1;
53296 +
53297 + return;
53298 +}
53299 +
53300 +void
53301 +gr_handle_delete(const ino_t ino, const dev_t dev)
53302 +{
53303 + struct inodev_entry *inodev;
53304 +
53305 + if (unlikely(!(gr_status & GR_READY)))
53306 + return;
53307 +
53308 + write_lock(&gr_inode_lock);
53309 + inodev = lookup_inodev_entry(ino, dev);
53310 + if (inodev != NULL)
53311 + do_handle_delete(inodev, ino, dev);
53312 + write_unlock(&gr_inode_lock);
53313 +
53314 + return;
53315 +}
53316 +
53317 +static void
53318 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53319 + const ino_t newinode, const dev_t newdevice,
53320 + struct acl_subject_label *subj)
53321 +{
53322 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53323 + struct acl_object_label *match;
53324 +
53325 + match = subj->obj_hash[index];
53326 +
53327 + while (match && (match->inode != oldinode ||
53328 + match->device != olddevice ||
53329 + !(match->mode & GR_DELETED)))
53330 + match = match->next;
53331 +
53332 + if (match && (match->inode == oldinode)
53333 + && (match->device == olddevice)
53334 + && (match->mode & GR_DELETED)) {
53335 + if (match->prev == NULL) {
53336 + subj->obj_hash[index] = match->next;
53337 + if (match->next != NULL)
53338 + match->next->prev = NULL;
53339 + } else {
53340 + match->prev->next = match->next;
53341 + if (match->next != NULL)
53342 + match->next->prev = match->prev;
53343 + }
53344 + match->prev = NULL;
53345 + match->next = NULL;
53346 + match->inode = newinode;
53347 + match->device = newdevice;
53348 + match->mode &= ~GR_DELETED;
53349 +
53350 + insert_acl_obj_label(match, subj);
53351 + }
53352 +
53353 + return;
53354 +}
53355 +
53356 +static void
53357 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53358 + const ino_t newinode, const dev_t newdevice,
53359 + struct acl_role_label *role)
53360 +{
53361 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53362 + struct acl_subject_label *match;
53363 +
53364 + match = role->subj_hash[index];
53365 +
53366 + while (match && (match->inode != oldinode ||
53367 + match->device != olddevice ||
53368 + !(match->mode & GR_DELETED)))
53369 + match = match->next;
53370 +
53371 + if (match && (match->inode == oldinode)
53372 + && (match->device == olddevice)
53373 + && (match->mode & GR_DELETED)) {
53374 + if (match->prev == NULL) {
53375 + role->subj_hash[index] = match->next;
53376 + if (match->next != NULL)
53377 + match->next->prev = NULL;
53378 + } else {
53379 + match->prev->next = match->next;
53380 + if (match->next != NULL)
53381 + match->next->prev = match->prev;
53382 + }
53383 + match->prev = NULL;
53384 + match->next = NULL;
53385 + match->inode = newinode;
53386 + match->device = newdevice;
53387 + match->mode &= ~GR_DELETED;
53388 +
53389 + insert_acl_subj_label(match, role);
53390 + }
53391 +
53392 + return;
53393 +}
53394 +
53395 +static void
53396 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53397 + const ino_t newinode, const dev_t newdevice)
53398 +{
53399 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53400 + struct inodev_entry *match;
53401 +
53402 + match = inodev_set.i_hash[index];
53403 +
53404 + while (match && (match->nentry->inode != oldinode ||
53405 + match->nentry->device != olddevice || !match->nentry->deleted))
53406 + match = match->next;
53407 +
53408 + if (match && (match->nentry->inode == oldinode)
53409 + && (match->nentry->device == olddevice) &&
53410 + match->nentry->deleted) {
53411 + if (match->prev == NULL) {
53412 + inodev_set.i_hash[index] = match->next;
53413 + if (match->next != NULL)
53414 + match->next->prev = NULL;
53415 + } else {
53416 + match->prev->next = match->next;
53417 + if (match->next != NULL)
53418 + match->next->prev = match->prev;
53419 + }
53420 + match->prev = NULL;
53421 + match->next = NULL;
53422 + match->nentry->inode = newinode;
53423 + match->nentry->device = newdevice;
53424 + match->nentry->deleted = 0;
53425 +
53426 + insert_inodev_entry(match);
53427 + }
53428 +
53429 + return;
53430 +}
53431 +
53432 +static void
53433 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53434 +{
53435 + struct acl_subject_label *subj;
53436 + struct acl_role_label *role;
53437 + unsigned int x;
53438 +
53439 + FOR_EACH_ROLE_START(role)
53440 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53441 +
53442 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53443 + if ((subj->inode == ino) && (subj->device == dev)) {
53444 + subj->inode = ino;
53445 + subj->device = dev;
53446 + }
53447 + FOR_EACH_NESTED_SUBJECT_END(subj)
53448 + FOR_EACH_SUBJECT_START(role, subj, x)
53449 + update_acl_obj_label(matchn->inode, matchn->device,
53450 + ino, dev, subj);
53451 + FOR_EACH_SUBJECT_END(subj,x)
53452 + FOR_EACH_ROLE_END(role)
53453 +
53454 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53455 +
53456 + return;
53457 +}
53458 +
53459 +static void
53460 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53461 + const struct vfsmount *mnt)
53462 +{
53463 + ino_t ino = dentry->d_inode->i_ino;
53464 + dev_t dev = __get_dev(dentry);
53465 +
53466 + __do_handle_create(matchn, ino, dev);
53467 +
53468 + return;
53469 +}
53470 +
53471 +void
53472 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53473 +{
53474 + struct name_entry *matchn;
53475 +
53476 + if (unlikely(!(gr_status & GR_READY)))
53477 + return;
53478 +
53479 + preempt_disable();
53480 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53481 +
53482 + if (unlikely((unsigned long)matchn)) {
53483 + write_lock(&gr_inode_lock);
53484 + do_handle_create(matchn, dentry, mnt);
53485 + write_unlock(&gr_inode_lock);
53486 + }
53487 + preempt_enable();
53488 +
53489 + return;
53490 +}
53491 +
53492 +void
53493 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53494 +{
53495 + struct name_entry *matchn;
53496 +
53497 + if (unlikely(!(gr_status & GR_READY)))
53498 + return;
53499 +
53500 + preempt_disable();
53501 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53502 +
53503 + if (unlikely((unsigned long)matchn)) {
53504 + write_lock(&gr_inode_lock);
53505 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53506 + write_unlock(&gr_inode_lock);
53507 + }
53508 + preempt_enable();
53509 +
53510 + return;
53511 +}
53512 +
53513 +void
53514 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53515 + struct dentry *old_dentry,
53516 + struct dentry *new_dentry,
53517 + struct vfsmount *mnt, const __u8 replace)
53518 +{
53519 + struct name_entry *matchn;
53520 + struct inodev_entry *inodev;
53521 + struct inode *inode = new_dentry->d_inode;
53522 + ino_t old_ino = old_dentry->d_inode->i_ino;
53523 + dev_t old_dev = __get_dev(old_dentry);
53524 +
53525 + /* vfs_rename swaps the name and parent link for old_dentry and
53526 + new_dentry
53527 + at this point, old_dentry has the new name, parent link, and inode
53528 + for the renamed file
53529 + if a file is being replaced by a rename, new_dentry has the inode
53530 + and name for the replaced file
53531 + */
53532 +
53533 + if (unlikely(!(gr_status & GR_READY)))
53534 + return;
53535 +
53536 + preempt_disable();
53537 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53538 +
53539 + /* we wouldn't have to check d_inode if it weren't for
53540 + NFS silly-renaming
53541 + */
53542 +
53543 + write_lock(&gr_inode_lock);
53544 + if (unlikely(replace && inode)) {
53545 + ino_t new_ino = inode->i_ino;
53546 + dev_t new_dev = __get_dev(new_dentry);
53547 +
53548 + inodev = lookup_inodev_entry(new_ino, new_dev);
53549 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53550 + do_handle_delete(inodev, new_ino, new_dev);
53551 + }
53552 +
53553 + inodev = lookup_inodev_entry(old_ino, old_dev);
53554 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53555 + do_handle_delete(inodev, old_ino, old_dev);
53556 +
53557 + if (unlikely((unsigned long)matchn))
53558 + do_handle_create(matchn, old_dentry, mnt);
53559 +
53560 + write_unlock(&gr_inode_lock);
53561 + preempt_enable();
53562 +
53563 + return;
53564 +}
53565 +
53566 +static int
53567 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53568 + unsigned char **sum)
53569 +{
53570 + struct acl_role_label *r;
53571 + struct role_allowed_ip *ipp;
53572 + struct role_transition *trans;
53573 + unsigned int i;
53574 + int found = 0;
53575 + u32 curr_ip = current->signal->curr_ip;
53576 +
53577 + current->signal->saved_ip = curr_ip;
53578 +
53579 + /* check transition table */
53580 +
53581 + for (trans = current->role->transitions; trans; trans = trans->next) {
53582 + if (!strcmp(rolename, trans->rolename)) {
53583 + found = 1;
53584 + break;
53585 + }
53586 + }
53587 +
53588 + if (!found)
53589 + return 0;
53590 +
53591 + /* handle special roles that do not require authentication
53592 + and check ip */
53593 +
53594 + FOR_EACH_ROLE_START(r)
53595 + if (!strcmp(rolename, r->rolename) &&
53596 + (r->roletype & GR_ROLE_SPECIAL)) {
53597 + found = 0;
53598 + if (r->allowed_ips != NULL) {
53599 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53600 + if ((ntohl(curr_ip) & ipp->netmask) ==
53601 + (ntohl(ipp->addr) & ipp->netmask))
53602 + found = 1;
53603 + }
53604 + } else
53605 + found = 2;
53606 + if (!found)
53607 + return 0;
53608 +
53609 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53610 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53611 + *salt = NULL;
53612 + *sum = NULL;
53613 + return 1;
53614 + }
53615 + }
53616 + FOR_EACH_ROLE_END(r)
53617 +
53618 + for (i = 0; i < num_sprole_pws; i++) {
53619 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53620 + *salt = acl_special_roles[i]->salt;
53621 + *sum = acl_special_roles[i]->sum;
53622 + return 1;
53623 + }
53624 + }
53625 +
53626 + return 0;
53627 +}
53628 +
53629 +static void
53630 +assign_special_role(char *rolename)
53631 +{
53632 + struct acl_object_label *obj;
53633 + struct acl_role_label *r;
53634 + struct acl_role_label *assigned = NULL;
53635 + struct task_struct *tsk;
53636 + struct file *filp;
53637 +
53638 + FOR_EACH_ROLE_START(r)
53639 + if (!strcmp(rolename, r->rolename) &&
53640 + (r->roletype & GR_ROLE_SPECIAL)) {
53641 + assigned = r;
53642 + break;
53643 + }
53644 + FOR_EACH_ROLE_END(r)
53645 +
53646 + if (!assigned)
53647 + return;
53648 +
53649 + read_lock(&tasklist_lock);
53650 + read_lock(&grsec_exec_file_lock);
53651 +
53652 + tsk = current->real_parent;
53653 + if (tsk == NULL)
53654 + goto out_unlock;
53655 +
53656 + filp = tsk->exec_file;
53657 + if (filp == NULL)
53658 + goto out_unlock;
53659 +
53660 + tsk->is_writable = 0;
53661 +
53662 + tsk->acl_sp_role = 1;
53663 + tsk->acl_role_id = ++acl_sp_role_value;
53664 + tsk->role = assigned;
53665 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53666 +
53667 + /* ignore additional mmap checks for processes that are writable
53668 + by the default ACL */
53669 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53670 + if (unlikely(obj->mode & GR_WRITE))
53671 + tsk->is_writable = 1;
53672 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53673 + if (unlikely(obj->mode & GR_WRITE))
53674 + tsk->is_writable = 1;
53675 +
53676 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53677 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53678 +#endif
53679 +
53680 +out_unlock:
53681 + read_unlock(&grsec_exec_file_lock);
53682 + read_unlock(&tasklist_lock);
53683 + return;
53684 +}
53685 +
53686 +int gr_check_secure_terminal(struct task_struct *task)
53687 +{
53688 + struct task_struct *p, *p2, *p3;
53689 + struct files_struct *files;
53690 + struct fdtable *fdt;
53691 + struct file *our_file = NULL, *file;
53692 + int i;
53693 +
53694 + if (task->signal->tty == NULL)
53695 + return 1;
53696 +
53697 + files = get_files_struct(task);
53698 + if (files != NULL) {
53699 + rcu_read_lock();
53700 + fdt = files_fdtable(files);
53701 + for (i=0; i < fdt->max_fds; i++) {
53702 + file = fcheck_files(files, i);
53703 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53704 + get_file(file);
53705 + our_file = file;
53706 + }
53707 + }
53708 + rcu_read_unlock();
53709 + put_files_struct(files);
53710 + }
53711 +
53712 + if (our_file == NULL)
53713 + return 1;
53714 +
53715 + read_lock(&tasklist_lock);
53716 + do_each_thread(p2, p) {
53717 + files = get_files_struct(p);
53718 + if (files == NULL ||
53719 + (p->signal && p->signal->tty == task->signal->tty)) {
53720 + if (files != NULL)
53721 + put_files_struct(files);
53722 + continue;
53723 + }
53724 + rcu_read_lock();
53725 + fdt = files_fdtable(files);
53726 + for (i=0; i < fdt->max_fds; i++) {
53727 + file = fcheck_files(files, i);
53728 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53729 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53730 + p3 = task;
53731 + while (p3->pid > 0) {
53732 + if (p3 == p)
53733 + break;
53734 + p3 = p3->real_parent;
53735 + }
53736 + if (p3 == p)
53737 + break;
53738 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53739 + gr_handle_alertkill(p);
53740 + rcu_read_unlock();
53741 + put_files_struct(files);
53742 + read_unlock(&tasklist_lock);
53743 + fput(our_file);
53744 + return 0;
53745 + }
53746 + }
53747 + rcu_read_unlock();
53748 + put_files_struct(files);
53749 + } while_each_thread(p2, p);
53750 + read_unlock(&tasklist_lock);
53751 +
53752 + fput(our_file);
53753 + return 1;
53754 +}
53755 +
53756 +ssize_t
53757 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53758 +{
53759 + struct gr_arg_wrapper uwrap;
53760 + unsigned char *sprole_salt = NULL;
53761 + unsigned char *sprole_sum = NULL;
53762 + int error = sizeof (struct gr_arg_wrapper);
53763 + int error2 = 0;
53764 +
53765 + mutex_lock(&gr_dev_mutex);
53766 +
53767 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53768 + error = -EPERM;
53769 + goto out;
53770 + }
53771 +
53772 + if (count != sizeof (struct gr_arg_wrapper)) {
53773 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53774 + error = -EINVAL;
53775 + goto out;
53776 + }
53777 +
53778 +
53779 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53780 + gr_auth_expires = 0;
53781 + gr_auth_attempts = 0;
53782 + }
53783 +
53784 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53785 + error = -EFAULT;
53786 + goto out;
53787 + }
53788 +
53789 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53790 + error = -EINVAL;
53791 + goto out;
53792 + }
53793 +
53794 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53795 + error = -EFAULT;
53796 + goto out;
53797 + }
53798 +
53799 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53800 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53801 + time_after(gr_auth_expires, get_seconds())) {
53802 + error = -EBUSY;
53803 + goto out;
53804 + }
53805 +
53806 + /* if non-root trying to do anything other than use a special role,
53807 + do not attempt authentication, do not count towards authentication
53808 + locking
53809 + */
53810 +
53811 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53812 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53813 + current_uid()) {
53814 + error = -EPERM;
53815 + goto out;
53816 + }
53817 +
53818 + /* ensure pw and special role name are null terminated */
53819 +
53820 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53821 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53822 +
53823 + /* Okay.
53824 + * We have our enough of the argument structure..(we have yet
53825 + * to copy_from_user the tables themselves) . Copy the tables
53826 + * only if we need them, i.e. for loading operations. */
53827 +
53828 + switch (gr_usermode->mode) {
53829 + case GR_STATUS:
53830 + if (gr_status & GR_READY) {
53831 + error = 1;
53832 + if (!gr_check_secure_terminal(current))
53833 + error = 3;
53834 + } else
53835 + error = 2;
53836 + goto out;
53837 + case GR_SHUTDOWN:
53838 + if ((gr_status & GR_READY)
53839 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53840 + pax_open_kernel();
53841 + gr_status &= ~GR_READY;
53842 + pax_close_kernel();
53843 +
53844 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53845 + free_variables();
53846 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53847 + memset(gr_system_salt, 0, GR_SALT_LEN);
53848 + memset(gr_system_sum, 0, GR_SHA_LEN);
53849 + } else if (gr_status & GR_READY) {
53850 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53851 + error = -EPERM;
53852 + } else {
53853 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53854 + error = -EAGAIN;
53855 + }
53856 + break;
53857 + case GR_ENABLE:
53858 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53859 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53860 + else {
53861 + if (gr_status & GR_READY)
53862 + error = -EAGAIN;
53863 + else
53864 + error = error2;
53865 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53866 + }
53867 + break;
53868 + case GR_RELOAD:
53869 + if (!(gr_status & GR_READY)) {
53870 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53871 + error = -EAGAIN;
53872 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53873 + preempt_disable();
53874 +
53875 + pax_open_kernel();
53876 + gr_status &= ~GR_READY;
53877 + pax_close_kernel();
53878 +
53879 + free_variables();
53880 + if (!(error2 = gracl_init(gr_usermode))) {
53881 + preempt_enable();
53882 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53883 + } else {
53884 + preempt_enable();
53885 + error = error2;
53886 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53887 + }
53888 + } else {
53889 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53890 + error = -EPERM;
53891 + }
53892 + break;
53893 + case GR_SEGVMOD:
53894 + if (unlikely(!(gr_status & GR_READY))) {
53895 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53896 + error = -EAGAIN;
53897 + break;
53898 + }
53899 +
53900 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53901 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53902 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53903 + struct acl_subject_label *segvacl;
53904 + segvacl =
53905 + lookup_acl_subj_label(gr_usermode->segv_inode,
53906 + gr_usermode->segv_device,
53907 + current->role);
53908 + if (segvacl) {
53909 + segvacl->crashes = 0;
53910 + segvacl->expires = 0;
53911 + }
53912 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53913 + gr_remove_uid(gr_usermode->segv_uid);
53914 + }
53915 + } else {
53916 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53917 + error = -EPERM;
53918 + }
53919 + break;
53920 + case GR_SPROLE:
53921 + case GR_SPROLEPAM:
53922 + if (unlikely(!(gr_status & GR_READY))) {
53923 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53924 + error = -EAGAIN;
53925 + break;
53926 + }
53927 +
53928 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53929 + current->role->expires = 0;
53930 + current->role->auth_attempts = 0;
53931 + }
53932 +
53933 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53934 + time_after(current->role->expires, get_seconds())) {
53935 + error = -EBUSY;
53936 + goto out;
53937 + }
53938 +
53939 + if (lookup_special_role_auth
53940 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53941 + && ((!sprole_salt && !sprole_sum)
53942 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53943 + char *p = "";
53944 + assign_special_role(gr_usermode->sp_role);
53945 + read_lock(&tasklist_lock);
53946 + if (current->real_parent)
53947 + p = current->real_parent->role->rolename;
53948 + read_unlock(&tasklist_lock);
53949 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53950 + p, acl_sp_role_value);
53951 + } else {
53952 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53953 + error = -EPERM;
53954 + if(!(current->role->auth_attempts++))
53955 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53956 +
53957 + goto out;
53958 + }
53959 + break;
53960 + case GR_UNSPROLE:
53961 + if (unlikely(!(gr_status & GR_READY))) {
53962 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53963 + error = -EAGAIN;
53964 + break;
53965 + }
53966 +
53967 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53968 + char *p = "";
53969 + int i = 0;
53970 +
53971 + read_lock(&tasklist_lock);
53972 + if (current->real_parent) {
53973 + p = current->real_parent->role->rolename;
53974 + i = current->real_parent->acl_role_id;
53975 + }
53976 + read_unlock(&tasklist_lock);
53977 +
53978 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53979 + gr_set_acls(1);
53980 + } else {
53981 + error = -EPERM;
53982 + goto out;
53983 + }
53984 + break;
53985 + default:
53986 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53987 + error = -EINVAL;
53988 + break;
53989 + }
53990 +
53991 + if (error != -EPERM)
53992 + goto out;
53993 +
53994 + if(!(gr_auth_attempts++))
53995 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53996 +
53997 + out:
53998 + mutex_unlock(&gr_dev_mutex);
53999 + return error;
54000 +}
54001 +
54002 +/* must be called with
54003 + rcu_read_lock();
54004 + read_lock(&tasklist_lock);
54005 + read_lock(&grsec_exec_file_lock);
54006 +*/
54007 +int gr_apply_subject_to_task(struct task_struct *task)
54008 +{
54009 + struct acl_object_label *obj;
54010 + char *tmpname;
54011 + struct acl_subject_label *tmpsubj;
54012 + struct file *filp;
54013 + struct name_entry *nmatch;
54014 +
54015 + filp = task->exec_file;
54016 + if (filp == NULL)
54017 + return 0;
54018 +
54019 + /* the following is to apply the correct subject
54020 + on binaries running when the RBAC system
54021 + is enabled, when the binaries have been
54022 + replaced or deleted since their execution
54023 + -----
54024 + when the RBAC system starts, the inode/dev
54025 + from exec_file will be one the RBAC system
54026 + is unaware of. It only knows the inode/dev
54027 + of the present file on disk, or the absence
54028 + of it.
54029 + */
54030 + preempt_disable();
54031 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54032 +
54033 + nmatch = lookup_name_entry(tmpname);
54034 + preempt_enable();
54035 + tmpsubj = NULL;
54036 + if (nmatch) {
54037 + if (nmatch->deleted)
54038 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54039 + else
54040 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54041 + if (tmpsubj != NULL)
54042 + task->acl = tmpsubj;
54043 + }
54044 + if (tmpsubj == NULL)
54045 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54046 + task->role);
54047 + if (task->acl) {
54048 + task->is_writable = 0;
54049 + /* ignore additional mmap checks for processes that are writable
54050 + by the default ACL */
54051 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54052 + if (unlikely(obj->mode & GR_WRITE))
54053 + task->is_writable = 1;
54054 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54055 + if (unlikely(obj->mode & GR_WRITE))
54056 + task->is_writable = 1;
54057 +
54058 + gr_set_proc_res(task);
54059 +
54060 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54061 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54062 +#endif
54063 + } else {
54064 + return 1;
54065 + }
54066 +
54067 + return 0;
54068 +}
54069 +
54070 +int
54071 +gr_set_acls(const int type)
54072 +{
54073 + struct task_struct *task, *task2;
54074 + struct acl_role_label *role = current->role;
54075 + __u16 acl_role_id = current->acl_role_id;
54076 + const struct cred *cred;
54077 + int ret;
54078 +
54079 + rcu_read_lock();
54080 + read_lock(&tasklist_lock);
54081 + read_lock(&grsec_exec_file_lock);
54082 + do_each_thread(task2, task) {
54083 + /* check to see if we're called from the exit handler,
54084 + if so, only replace ACLs that have inherited the admin
54085 + ACL */
54086 +
54087 + if (type && (task->role != role ||
54088 + task->acl_role_id != acl_role_id))
54089 + continue;
54090 +
54091 + task->acl_role_id = 0;
54092 + task->acl_sp_role = 0;
54093 +
54094 + if (task->exec_file) {
54095 + cred = __task_cred(task);
54096 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54097 + ret = gr_apply_subject_to_task(task);
54098 + if (ret) {
54099 + read_unlock(&grsec_exec_file_lock);
54100 + read_unlock(&tasklist_lock);
54101 + rcu_read_unlock();
54102 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54103 + return ret;
54104 + }
54105 + } else {
54106 + // it's a kernel process
54107 + task->role = kernel_role;
54108 + task->acl = kernel_role->root_label;
54109 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54110 + task->acl->mode &= ~GR_PROCFIND;
54111 +#endif
54112 + }
54113 + } while_each_thread(task2, task);
54114 + read_unlock(&grsec_exec_file_lock);
54115 + read_unlock(&tasklist_lock);
54116 + rcu_read_unlock();
54117 +
54118 + return 0;
54119 +}
54120 +
54121 +void
54122 +gr_learn_resource(const struct task_struct *task,
54123 + const int res, const unsigned long wanted, const int gt)
54124 +{
54125 + struct acl_subject_label *acl;
54126 + const struct cred *cred;
54127 +
54128 + if (unlikely((gr_status & GR_READY) &&
54129 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54130 + goto skip_reslog;
54131 +
54132 +#ifdef CONFIG_GRKERNSEC_RESLOG
54133 + gr_log_resource(task, res, wanted, gt);
54134 +#endif
54135 + skip_reslog:
54136 +
54137 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54138 + return;
54139 +
54140 + acl = task->acl;
54141 +
54142 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54143 + !(acl->resmask & (1 << (unsigned short) res))))
54144 + return;
54145 +
54146 + if (wanted >= acl->res[res].rlim_cur) {
54147 + unsigned long res_add;
54148 +
54149 + res_add = wanted;
54150 + switch (res) {
54151 + case RLIMIT_CPU:
54152 + res_add += GR_RLIM_CPU_BUMP;
54153 + break;
54154 + case RLIMIT_FSIZE:
54155 + res_add += GR_RLIM_FSIZE_BUMP;
54156 + break;
54157 + case RLIMIT_DATA:
54158 + res_add += GR_RLIM_DATA_BUMP;
54159 + break;
54160 + case RLIMIT_STACK:
54161 + res_add += GR_RLIM_STACK_BUMP;
54162 + break;
54163 + case RLIMIT_CORE:
54164 + res_add += GR_RLIM_CORE_BUMP;
54165 + break;
54166 + case RLIMIT_RSS:
54167 + res_add += GR_RLIM_RSS_BUMP;
54168 + break;
54169 + case RLIMIT_NPROC:
54170 + res_add += GR_RLIM_NPROC_BUMP;
54171 + break;
54172 + case RLIMIT_NOFILE:
54173 + res_add += GR_RLIM_NOFILE_BUMP;
54174 + break;
54175 + case RLIMIT_MEMLOCK:
54176 + res_add += GR_RLIM_MEMLOCK_BUMP;
54177 + break;
54178 + case RLIMIT_AS:
54179 + res_add += GR_RLIM_AS_BUMP;
54180 + break;
54181 + case RLIMIT_LOCKS:
54182 + res_add += GR_RLIM_LOCKS_BUMP;
54183 + break;
54184 + case RLIMIT_SIGPENDING:
54185 + res_add += GR_RLIM_SIGPENDING_BUMP;
54186 + break;
54187 + case RLIMIT_MSGQUEUE:
54188 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54189 + break;
54190 + case RLIMIT_NICE:
54191 + res_add += GR_RLIM_NICE_BUMP;
54192 + break;
54193 + case RLIMIT_RTPRIO:
54194 + res_add += GR_RLIM_RTPRIO_BUMP;
54195 + break;
54196 + case RLIMIT_RTTIME:
54197 + res_add += GR_RLIM_RTTIME_BUMP;
54198 + break;
54199 + }
54200 +
54201 + acl->res[res].rlim_cur = res_add;
54202 +
54203 + if (wanted > acl->res[res].rlim_max)
54204 + acl->res[res].rlim_max = res_add;
54205 +
54206 + /* only log the subject filename, since resource logging is supported for
54207 + single-subject learning only */
54208 + rcu_read_lock();
54209 + cred = __task_cred(task);
54210 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54211 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54212 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54213 + "", (unsigned long) res, &task->signal->saved_ip);
54214 + rcu_read_unlock();
54215 + }
54216 +
54217 + return;
54218 +}
54219 +
54220 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54221 +void
54222 +pax_set_initial_flags(struct linux_binprm *bprm)
54223 +{
54224 + struct task_struct *task = current;
54225 + struct acl_subject_label *proc;
54226 + unsigned long flags;
54227 +
54228 + if (unlikely(!(gr_status & GR_READY)))
54229 + return;
54230 +
54231 + flags = pax_get_flags(task);
54232 +
54233 + proc = task->acl;
54234 +
54235 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54236 + flags &= ~MF_PAX_PAGEEXEC;
54237 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54238 + flags &= ~MF_PAX_SEGMEXEC;
54239 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54240 + flags &= ~MF_PAX_RANDMMAP;
54241 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54242 + flags &= ~MF_PAX_EMUTRAMP;
54243 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54244 + flags &= ~MF_PAX_MPROTECT;
54245 +
54246 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54247 + flags |= MF_PAX_PAGEEXEC;
54248 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54249 + flags |= MF_PAX_SEGMEXEC;
54250 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54251 + flags |= MF_PAX_RANDMMAP;
54252 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54253 + flags |= MF_PAX_EMUTRAMP;
54254 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54255 + flags |= MF_PAX_MPROTECT;
54256 +
54257 + pax_set_flags(task, flags);
54258 +
54259 + return;
54260 +}
54261 +#endif
54262 +
54263 +#ifdef CONFIG_SYSCTL
54264 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54265 + system to save 35kb of memory */
54266 +
54267 +/* we modify the passed in filename, but adjust it back before returning */
54268 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54269 +{
54270 + struct name_entry *nmatch;
54271 + char *p, *lastp = NULL;
54272 + struct acl_object_label *obj = NULL, *tmp;
54273 + struct acl_subject_label *tmpsubj;
54274 + char c = '\0';
54275 +
54276 + read_lock(&gr_inode_lock);
54277 +
54278 + p = name + len - 1;
54279 + do {
54280 + nmatch = lookup_name_entry(name);
54281 + if (lastp != NULL)
54282 + *lastp = c;
54283 +
54284 + if (nmatch == NULL)
54285 + goto next_component;
54286 + tmpsubj = current->acl;
54287 + do {
54288 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54289 + if (obj != NULL) {
54290 + tmp = obj->globbed;
54291 + while (tmp) {
54292 + if (!glob_match(tmp->filename, name)) {
54293 + obj = tmp;
54294 + goto found_obj;
54295 + }
54296 + tmp = tmp->next;
54297 + }
54298 + goto found_obj;
54299 + }
54300 + } while ((tmpsubj = tmpsubj->parent_subject));
54301 +next_component:
54302 + /* end case */
54303 + if (p == name)
54304 + break;
54305 +
54306 + while (*p != '/')
54307 + p--;
54308 + if (p == name)
54309 + lastp = p + 1;
54310 + else {
54311 + lastp = p;
54312 + p--;
54313 + }
54314 + c = *lastp;
54315 + *lastp = '\0';
54316 + } while (1);
54317 +found_obj:
54318 + read_unlock(&gr_inode_lock);
54319 + /* obj returned will always be non-null */
54320 + return obj;
54321 +}
54322 +
54323 +/* returns 0 when allowing, non-zero on error
54324 + op of 0 is used for readdir, so we don't log the names of hidden files
54325 +*/
54326 +__u32
54327 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54328 +{
54329 + struct ctl_table *tmp;
54330 + const char *proc_sys = "/proc/sys";
54331 + char *path;
54332 + struct acl_object_label *obj;
54333 + unsigned short len = 0, pos = 0, depth = 0, i;
54334 + __u32 err = 0;
54335 + __u32 mode = 0;
54336 +
54337 + if (unlikely(!(gr_status & GR_READY)))
54338 + return 0;
54339 +
54340 + /* for now, ignore operations on non-sysctl entries if it's not a
54341 + readdir*/
54342 + if (table->child != NULL && op != 0)
54343 + return 0;
54344 +
54345 + mode |= GR_FIND;
54346 + /* it's only a read if it's an entry, read on dirs is for readdir */
54347 + if (op & MAY_READ)
54348 + mode |= GR_READ;
54349 + if (op & MAY_WRITE)
54350 + mode |= GR_WRITE;
54351 +
54352 + preempt_disable();
54353 +
54354 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54355 +
54356 + /* it's only a read/write if it's an actual entry, not a dir
54357 + (which are opened for readdir)
54358 + */
54359 +
54360 + /* convert the requested sysctl entry into a pathname */
54361 +
54362 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54363 + len += strlen(tmp->procname);
54364 + len++;
54365 + depth++;
54366 + }
54367 +
54368 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54369 + /* deny */
54370 + goto out;
54371 + }
54372 +
54373 + memset(path, 0, PAGE_SIZE);
54374 +
54375 + memcpy(path, proc_sys, strlen(proc_sys));
54376 +
54377 + pos += strlen(proc_sys);
54378 +
54379 + for (; depth > 0; depth--) {
54380 + path[pos] = '/';
54381 + pos++;
54382 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54383 + if (depth == i) {
54384 + memcpy(path + pos, tmp->procname,
54385 + strlen(tmp->procname));
54386 + pos += strlen(tmp->procname);
54387 + }
54388 + i++;
54389 + }
54390 + }
54391 +
54392 + obj = gr_lookup_by_name(path, pos);
54393 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54394 +
54395 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54396 + ((err & mode) != mode))) {
54397 + __u32 new_mode = mode;
54398 +
54399 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54400 +
54401 + err = 0;
54402 + gr_log_learn_sysctl(path, new_mode);
54403 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54404 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54405 + err = -ENOENT;
54406 + } else if (!(err & GR_FIND)) {
54407 + err = -ENOENT;
54408 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54409 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54410 + path, (mode & GR_READ) ? " reading" : "",
54411 + (mode & GR_WRITE) ? " writing" : "");
54412 + err = -EACCES;
54413 + } else if ((err & mode) != mode) {
54414 + err = -EACCES;
54415 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54416 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54417 + path, (mode & GR_READ) ? " reading" : "",
54418 + (mode & GR_WRITE) ? " writing" : "");
54419 + err = 0;
54420 + } else
54421 + err = 0;
54422 +
54423 + out:
54424 + preempt_enable();
54425 +
54426 + return err;
54427 +}
54428 +#endif
54429 +
54430 +int
54431 +gr_handle_proc_ptrace(struct task_struct *task)
54432 +{
54433 + struct file *filp;
54434 + struct task_struct *tmp = task;
54435 + struct task_struct *curtemp = current;
54436 + __u32 retmode;
54437 +
54438 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54439 + if (unlikely(!(gr_status & GR_READY)))
54440 + return 0;
54441 +#endif
54442 +
54443 + read_lock(&tasklist_lock);
54444 + read_lock(&grsec_exec_file_lock);
54445 + filp = task->exec_file;
54446 +
54447 + while (tmp->pid > 0) {
54448 + if (tmp == curtemp)
54449 + break;
54450 + tmp = tmp->real_parent;
54451 + }
54452 +
54453 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54454 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54455 + read_unlock(&grsec_exec_file_lock);
54456 + read_unlock(&tasklist_lock);
54457 + return 1;
54458 + }
54459 +
54460 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54461 + if (!(gr_status & GR_READY)) {
54462 + read_unlock(&grsec_exec_file_lock);
54463 + read_unlock(&tasklist_lock);
54464 + return 0;
54465 + }
54466 +#endif
54467 +
54468 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54469 + read_unlock(&grsec_exec_file_lock);
54470 + read_unlock(&tasklist_lock);
54471 +
54472 + if (retmode & GR_NOPTRACE)
54473 + return 1;
54474 +
54475 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54476 + && (current->acl != task->acl || (current->acl != current->role->root_label
54477 + && current->pid != task->pid)))
54478 + return 1;
54479 +
54480 + return 0;
54481 +}
54482 +
54483 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54484 +{
54485 + if (unlikely(!(gr_status & GR_READY)))
54486 + return;
54487 +
54488 + if (!(current->role->roletype & GR_ROLE_GOD))
54489 + return;
54490 +
54491 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54492 + p->role->rolename, gr_task_roletype_to_char(p),
54493 + p->acl->filename);
54494 +}
54495 +
54496 +int
54497 +gr_handle_ptrace(struct task_struct *task, const long request)
54498 +{
54499 + struct task_struct *tmp = task;
54500 + struct task_struct *curtemp = current;
54501 + __u32 retmode;
54502 +
54503 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54504 + if (unlikely(!(gr_status & GR_READY)))
54505 + return 0;
54506 +#endif
54507 +
54508 + read_lock(&tasklist_lock);
54509 + while (tmp->pid > 0) {
54510 + if (tmp == curtemp)
54511 + break;
54512 + tmp = tmp->real_parent;
54513 + }
54514 +
54515 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54516 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54517 + read_unlock(&tasklist_lock);
54518 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54519 + return 1;
54520 + }
54521 + read_unlock(&tasklist_lock);
54522 +
54523 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54524 + if (!(gr_status & GR_READY))
54525 + return 0;
54526 +#endif
54527 +
54528 + read_lock(&grsec_exec_file_lock);
54529 + if (unlikely(!task->exec_file)) {
54530 + read_unlock(&grsec_exec_file_lock);
54531 + return 0;
54532 + }
54533 +
54534 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54535 + read_unlock(&grsec_exec_file_lock);
54536 +
54537 + if (retmode & GR_NOPTRACE) {
54538 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54539 + return 1;
54540 + }
54541 +
54542 + if (retmode & GR_PTRACERD) {
54543 + switch (request) {
54544 + case PTRACE_SEIZE:
54545 + case PTRACE_POKETEXT:
54546 + case PTRACE_POKEDATA:
54547 + case PTRACE_POKEUSR:
54548 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54549 + case PTRACE_SETREGS:
54550 + case PTRACE_SETFPREGS:
54551 +#endif
54552 +#ifdef CONFIG_X86
54553 + case PTRACE_SETFPXREGS:
54554 +#endif
54555 +#ifdef CONFIG_ALTIVEC
54556 + case PTRACE_SETVRREGS:
54557 +#endif
54558 + return 1;
54559 + default:
54560 + return 0;
54561 + }
54562 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54563 + !(current->role->roletype & GR_ROLE_GOD) &&
54564 + (current->acl != task->acl)) {
54565 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54566 + return 1;
54567 + }
54568 +
54569 + return 0;
54570 +}
54571 +
54572 +static int is_writable_mmap(const struct file *filp)
54573 +{
54574 + struct task_struct *task = current;
54575 + struct acl_object_label *obj, *obj2;
54576 +
54577 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54578 + !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))) {
54579 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54580 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54581 + task->role->root_label);
54582 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54583 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54584 + return 1;
54585 + }
54586 + }
54587 + return 0;
54588 +}
54589 +
54590 +int
54591 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54592 +{
54593 + __u32 mode;
54594 +
54595 + if (unlikely(!file || !(prot & PROT_EXEC)))
54596 + return 1;
54597 +
54598 + if (is_writable_mmap(file))
54599 + return 0;
54600 +
54601 + mode =
54602 + gr_search_file(file->f_path.dentry,
54603 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54604 + file->f_path.mnt);
54605 +
54606 + if (!gr_tpe_allow(file))
54607 + return 0;
54608 +
54609 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54610 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54611 + return 0;
54612 + } else if (unlikely(!(mode & GR_EXEC))) {
54613 + return 0;
54614 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54615 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54616 + return 1;
54617 + }
54618 +
54619 + return 1;
54620 +}
54621 +
54622 +int
54623 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54624 +{
54625 + __u32 mode;
54626 +
54627 + if (unlikely(!file || !(prot & PROT_EXEC)))
54628 + return 1;
54629 +
54630 + if (is_writable_mmap(file))
54631 + return 0;
54632 +
54633 + mode =
54634 + gr_search_file(file->f_path.dentry,
54635 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54636 + file->f_path.mnt);
54637 +
54638 + if (!gr_tpe_allow(file))
54639 + return 0;
54640 +
54641 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54642 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54643 + return 0;
54644 + } else if (unlikely(!(mode & GR_EXEC))) {
54645 + return 0;
54646 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54647 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54648 + return 1;
54649 + }
54650 +
54651 + return 1;
54652 +}
54653 +
54654 +void
54655 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54656 +{
54657 + unsigned long runtime;
54658 + unsigned long cputime;
54659 + unsigned int wday, cday;
54660 + __u8 whr, chr;
54661 + __u8 wmin, cmin;
54662 + __u8 wsec, csec;
54663 + struct timespec timeval;
54664 +
54665 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54666 + !(task->acl->mode & GR_PROCACCT)))
54667 + return;
54668 +
54669 + do_posix_clock_monotonic_gettime(&timeval);
54670 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54671 + wday = runtime / (3600 * 24);
54672 + runtime -= wday * (3600 * 24);
54673 + whr = runtime / 3600;
54674 + runtime -= whr * 3600;
54675 + wmin = runtime / 60;
54676 + runtime -= wmin * 60;
54677 + wsec = runtime;
54678 +
54679 + cputime = (task->utime + task->stime) / HZ;
54680 + cday = cputime / (3600 * 24);
54681 + cputime -= cday * (3600 * 24);
54682 + chr = cputime / 3600;
54683 + cputime -= chr * 3600;
54684 + cmin = cputime / 60;
54685 + cputime -= cmin * 60;
54686 + csec = cputime;
54687 +
54688 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54689 +
54690 + return;
54691 +}
54692 +
54693 +void gr_set_kernel_label(struct task_struct *task)
54694 +{
54695 + if (gr_status & GR_READY) {
54696 + task->role = kernel_role;
54697 + task->acl = kernel_role->root_label;
54698 + }
54699 + return;
54700 +}
54701 +
54702 +#ifdef CONFIG_TASKSTATS
54703 +int gr_is_taskstats_denied(int pid)
54704 +{
54705 + struct task_struct *task;
54706 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54707 + const struct cred *cred;
54708 +#endif
54709 + int ret = 0;
54710 +
54711 + /* restrict taskstats viewing to un-chrooted root users
54712 + who have the 'view' subject flag if the RBAC system is enabled
54713 + */
54714 +
54715 + rcu_read_lock();
54716 + read_lock(&tasklist_lock);
54717 + task = find_task_by_vpid(pid);
54718 + if (task) {
54719 +#ifdef CONFIG_GRKERNSEC_CHROOT
54720 + if (proc_is_chrooted(task))
54721 + ret = -EACCES;
54722 +#endif
54723 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54724 + cred = __task_cred(task);
54725 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54726 + if (cred->uid != 0)
54727 + ret = -EACCES;
54728 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54729 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54730 + ret = -EACCES;
54731 +#endif
54732 +#endif
54733 + if (gr_status & GR_READY) {
54734 + if (!(task->acl->mode & GR_VIEW))
54735 + ret = -EACCES;
54736 + }
54737 + } else
54738 + ret = -ENOENT;
54739 +
54740 + read_unlock(&tasklist_lock);
54741 + rcu_read_unlock();
54742 +
54743 + return ret;
54744 +}
54745 +#endif
54746 +
54747 +/* AUXV entries are filled via a descendant of search_binary_handler
54748 + after we've already applied the subject for the target
54749 +*/
54750 +int gr_acl_enable_at_secure(void)
54751 +{
54752 + if (unlikely(!(gr_status & GR_READY)))
54753 + return 0;
54754 +
54755 + if (current->acl->mode & GR_ATSECURE)
54756 + return 1;
54757 +
54758 + return 0;
54759 +}
54760 +
54761 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54762 +{
54763 + struct task_struct *task = current;
54764 + struct dentry *dentry = file->f_path.dentry;
54765 + struct vfsmount *mnt = file->f_path.mnt;
54766 + struct acl_object_label *obj, *tmp;
54767 + struct acl_subject_label *subj;
54768 + unsigned int bufsize;
54769 + int is_not_root;
54770 + char *path;
54771 + dev_t dev = __get_dev(dentry);
54772 +
54773 + if (unlikely(!(gr_status & GR_READY)))
54774 + return 1;
54775 +
54776 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54777 + return 1;
54778 +
54779 + /* ignore Eric Biederman */
54780 + if (IS_PRIVATE(dentry->d_inode))
54781 + return 1;
54782 +
54783 + subj = task->acl;
54784 + do {
54785 + obj = lookup_acl_obj_label(ino, dev, subj);
54786 + if (obj != NULL)
54787 + return (obj->mode & GR_FIND) ? 1 : 0;
54788 + } while ((subj = subj->parent_subject));
54789 +
54790 + /* this is purely an optimization since we're looking for an object
54791 + for the directory we're doing a readdir on
54792 + if it's possible for any globbed object to match the entry we're
54793 + filling into the directory, then the object we find here will be
54794 + an anchor point with attached globbed objects
54795 + */
54796 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54797 + if (obj->globbed == NULL)
54798 + return (obj->mode & GR_FIND) ? 1 : 0;
54799 +
54800 + is_not_root = ((obj->filename[0] == '/') &&
54801 + (obj->filename[1] == '\0')) ? 0 : 1;
54802 + bufsize = PAGE_SIZE - namelen - is_not_root;
54803 +
54804 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54805 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54806 + return 1;
54807 +
54808 + preempt_disable();
54809 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54810 + bufsize);
54811 +
54812 + bufsize = strlen(path);
54813 +
54814 + /* if base is "/", don't append an additional slash */
54815 + if (is_not_root)
54816 + *(path + bufsize) = '/';
54817 + memcpy(path + bufsize + is_not_root, name, namelen);
54818 + *(path + bufsize + namelen + is_not_root) = '\0';
54819 +
54820 + tmp = obj->globbed;
54821 + while (tmp) {
54822 + if (!glob_match(tmp->filename, path)) {
54823 + preempt_enable();
54824 + return (tmp->mode & GR_FIND) ? 1 : 0;
54825 + }
54826 + tmp = tmp->next;
54827 + }
54828 + preempt_enable();
54829 + return (obj->mode & GR_FIND) ? 1 : 0;
54830 +}
54831 +
54832 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54833 +EXPORT_SYMBOL(gr_acl_is_enabled);
54834 +#endif
54835 +EXPORT_SYMBOL(gr_learn_resource);
54836 +EXPORT_SYMBOL(gr_set_kernel_label);
54837 +#ifdef CONFIG_SECURITY
54838 +EXPORT_SYMBOL(gr_check_user_change);
54839 +EXPORT_SYMBOL(gr_check_group_change);
54840 +#endif
54841 +
54842 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54843 new file mode 100644
54844 index 0000000..34fefda
54845 --- /dev/null
54846 +++ b/grsecurity/gracl_alloc.c
54847 @@ -0,0 +1,105 @@
54848 +#include <linux/kernel.h>
54849 +#include <linux/mm.h>
54850 +#include <linux/slab.h>
54851 +#include <linux/vmalloc.h>
54852 +#include <linux/gracl.h>
54853 +#include <linux/grsecurity.h>
54854 +
54855 +static unsigned long alloc_stack_next = 1;
54856 +static unsigned long alloc_stack_size = 1;
54857 +static void **alloc_stack;
54858 +
54859 +static __inline__ int
54860 +alloc_pop(void)
54861 +{
54862 + if (alloc_stack_next == 1)
54863 + return 0;
54864 +
54865 + kfree(alloc_stack[alloc_stack_next - 2]);
54866 +
54867 + alloc_stack_next--;
54868 +
54869 + return 1;
54870 +}
54871 +
54872 +static __inline__ int
54873 +alloc_push(void *buf)
54874 +{
54875 + if (alloc_stack_next >= alloc_stack_size)
54876 + return 1;
54877 +
54878 + alloc_stack[alloc_stack_next - 1] = buf;
54879 +
54880 + alloc_stack_next++;
54881 +
54882 + return 0;
54883 +}
54884 +
54885 +void *
54886 +acl_alloc(unsigned long len)
54887 +{
54888 + void *ret = NULL;
54889 +
54890 + if (!len || len > PAGE_SIZE)
54891 + goto out;
54892 +
54893 + ret = kmalloc(len, GFP_KERNEL);
54894 +
54895 + if (ret) {
54896 + if (alloc_push(ret)) {
54897 + kfree(ret);
54898 + ret = NULL;
54899 + }
54900 + }
54901 +
54902 +out:
54903 + return ret;
54904 +}
54905 +
54906 +void *
54907 +acl_alloc_num(unsigned long num, unsigned long len)
54908 +{
54909 + if (!len || (num > (PAGE_SIZE / len)))
54910 + return NULL;
54911 +
54912 + return acl_alloc(num * len);
54913 +}
54914 +
54915 +void
54916 +acl_free_all(void)
54917 +{
54918 + if (gr_acl_is_enabled() || !alloc_stack)
54919 + return;
54920 +
54921 + while (alloc_pop()) ;
54922 +
54923 + if (alloc_stack) {
54924 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54925 + kfree(alloc_stack);
54926 + else
54927 + vfree(alloc_stack);
54928 + }
54929 +
54930 + alloc_stack = NULL;
54931 + alloc_stack_size = 1;
54932 + alloc_stack_next = 1;
54933 +
54934 + return;
54935 +}
54936 +
54937 +int
54938 +acl_alloc_stack_init(unsigned long size)
54939 +{
54940 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54941 + alloc_stack =
54942 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54943 + else
54944 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54945 +
54946 + alloc_stack_size = size;
54947 +
54948 + if (!alloc_stack)
54949 + return 0;
54950 + else
54951 + return 1;
54952 +}
54953 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54954 new file mode 100644
54955 index 0000000..6d21049
54956 --- /dev/null
54957 +++ b/grsecurity/gracl_cap.c
54958 @@ -0,0 +1,110 @@
54959 +#include <linux/kernel.h>
54960 +#include <linux/module.h>
54961 +#include <linux/sched.h>
54962 +#include <linux/gracl.h>
54963 +#include <linux/grsecurity.h>
54964 +#include <linux/grinternal.h>
54965 +
54966 +extern const char *captab_log[];
54967 +extern int captab_log_entries;
54968 +
54969 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54970 +{
54971 + struct acl_subject_label *curracl;
54972 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54973 + kernel_cap_t cap_audit = __cap_empty_set;
54974 +
54975 + if (!gr_acl_is_enabled())
54976 + return 1;
54977 +
54978 + curracl = task->acl;
54979 +
54980 + cap_drop = curracl->cap_lower;
54981 + cap_mask = curracl->cap_mask;
54982 + cap_audit = curracl->cap_invert_audit;
54983 +
54984 + while ((curracl = curracl->parent_subject)) {
54985 + /* if the cap isn't specified in the current computed mask but is specified in the
54986 + current level subject, and is lowered in the current level subject, then add
54987 + it to the set of dropped capabilities
54988 + otherwise, add the current level subject's mask to the current computed mask
54989 + */
54990 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54991 + cap_raise(cap_mask, cap);
54992 + if (cap_raised(curracl->cap_lower, cap))
54993 + cap_raise(cap_drop, cap);
54994 + if (cap_raised(curracl->cap_invert_audit, cap))
54995 + cap_raise(cap_audit, cap);
54996 + }
54997 + }
54998 +
54999 + if (!cap_raised(cap_drop, cap)) {
55000 + if (cap_raised(cap_audit, cap))
55001 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55002 + return 1;
55003 + }
55004 +
55005 + curracl = task->acl;
55006 +
55007 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55008 + && cap_raised(cred->cap_effective, cap)) {
55009 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55010 + task->role->roletype, cred->uid,
55011 + cred->gid, task->exec_file ?
55012 + gr_to_filename(task->exec_file->f_path.dentry,
55013 + task->exec_file->f_path.mnt) : curracl->filename,
55014 + curracl->filename, 0UL,
55015 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55016 + return 1;
55017 + }
55018 +
55019 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55020 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55021 +
55022 + return 0;
55023 +}
55024 +
55025 +int
55026 +gr_acl_is_capable(const int cap)
55027 +{
55028 + return gr_task_acl_is_capable(current, current_cred(), cap);
55029 +}
55030 +
55031 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55032 +{
55033 + struct acl_subject_label *curracl;
55034 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55035 +
55036 + if (!gr_acl_is_enabled())
55037 + return 1;
55038 +
55039 + curracl = task->acl;
55040 +
55041 + cap_drop = curracl->cap_lower;
55042 + cap_mask = curracl->cap_mask;
55043 +
55044 + while ((curracl = curracl->parent_subject)) {
55045 + /* if the cap isn't specified in the current computed mask but is specified in the
55046 + current level subject, and is lowered in the current level subject, then add
55047 + it to the set of dropped capabilities
55048 + otherwise, add the current level subject's mask to the current computed mask
55049 + */
55050 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55051 + cap_raise(cap_mask, cap);
55052 + if (cap_raised(curracl->cap_lower, cap))
55053 + cap_raise(cap_drop, cap);
55054 + }
55055 + }
55056 +
55057 + if (!cap_raised(cap_drop, cap))
55058 + return 1;
55059 +
55060 + return 0;
55061 +}
55062 +
55063 +int
55064 +gr_acl_is_capable_nolog(const int cap)
55065 +{
55066 + return gr_task_acl_is_capable_nolog(current, cap);
55067 +}
55068 +
55069 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55070 new file mode 100644
55071 index 0000000..88d0e87
55072 --- /dev/null
55073 +++ b/grsecurity/gracl_fs.c
55074 @@ -0,0 +1,435 @@
55075 +#include <linux/kernel.h>
55076 +#include <linux/sched.h>
55077 +#include <linux/types.h>
55078 +#include <linux/fs.h>
55079 +#include <linux/file.h>
55080 +#include <linux/stat.h>
55081 +#include <linux/grsecurity.h>
55082 +#include <linux/grinternal.h>
55083 +#include <linux/gracl.h>
55084 +
55085 +umode_t
55086 +gr_acl_umask(void)
55087 +{
55088 + if (unlikely(!gr_acl_is_enabled()))
55089 + return 0;
55090 +
55091 + return current->role->umask;
55092 +}
55093 +
55094 +__u32
55095 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55096 + const struct vfsmount * mnt)
55097 +{
55098 + __u32 mode;
55099 +
55100 + if (unlikely(!dentry->d_inode))
55101 + return GR_FIND;
55102 +
55103 + mode =
55104 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55105 +
55106 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55107 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55108 + return mode;
55109 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55110 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55111 + return 0;
55112 + } else if (unlikely(!(mode & GR_FIND)))
55113 + return 0;
55114 +
55115 + return GR_FIND;
55116 +}
55117 +
55118 +__u32
55119 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55120 + int acc_mode)
55121 +{
55122 + __u32 reqmode = GR_FIND;
55123 + __u32 mode;
55124 +
55125 + if (unlikely(!dentry->d_inode))
55126 + return reqmode;
55127 +
55128 + if (acc_mode & MAY_APPEND)
55129 + reqmode |= GR_APPEND;
55130 + else if (acc_mode & MAY_WRITE)
55131 + reqmode |= GR_WRITE;
55132 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55133 + reqmode |= GR_READ;
55134 +
55135 + mode =
55136 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55137 + mnt);
55138 +
55139 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55140 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55141 + reqmode & GR_READ ? " reading" : "",
55142 + reqmode & GR_WRITE ? " writing" : reqmode &
55143 + GR_APPEND ? " appending" : "");
55144 + return reqmode;
55145 + } else
55146 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55147 + {
55148 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55149 + reqmode & GR_READ ? " reading" : "",
55150 + reqmode & GR_WRITE ? " writing" : reqmode &
55151 + GR_APPEND ? " appending" : "");
55152 + return 0;
55153 + } else if (unlikely((mode & reqmode) != reqmode))
55154 + return 0;
55155 +
55156 + return reqmode;
55157 +}
55158 +
55159 +__u32
55160 +gr_acl_handle_creat(const struct dentry * dentry,
55161 + const struct dentry * p_dentry,
55162 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55163 + const int imode)
55164 +{
55165 + __u32 reqmode = GR_WRITE | GR_CREATE;
55166 + __u32 mode;
55167 +
55168 + if (acc_mode & MAY_APPEND)
55169 + reqmode |= GR_APPEND;
55170 + // if a directory was required or the directory already exists, then
55171 + // don't count this open as a read
55172 + if ((acc_mode & MAY_READ) &&
55173 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55174 + reqmode |= GR_READ;
55175 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55176 + reqmode |= GR_SETID;
55177 +
55178 + mode =
55179 + gr_check_create(dentry, p_dentry, p_mnt,
55180 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55181 +
55182 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55183 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55184 + reqmode & GR_READ ? " reading" : "",
55185 + reqmode & GR_WRITE ? " writing" : reqmode &
55186 + GR_APPEND ? " appending" : "");
55187 + return reqmode;
55188 + } else
55189 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55190 + {
55191 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55192 + reqmode & GR_READ ? " reading" : "",
55193 + reqmode & GR_WRITE ? " writing" : reqmode &
55194 + GR_APPEND ? " appending" : "");
55195 + return 0;
55196 + } else if (unlikely((mode & reqmode) != reqmode))
55197 + return 0;
55198 +
55199 + return reqmode;
55200 +}
55201 +
55202 +__u32
55203 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55204 + const int fmode)
55205 +{
55206 + __u32 mode, reqmode = GR_FIND;
55207 +
55208 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55209 + reqmode |= GR_EXEC;
55210 + if (fmode & S_IWOTH)
55211 + reqmode |= GR_WRITE;
55212 + if (fmode & S_IROTH)
55213 + reqmode |= GR_READ;
55214 +
55215 + mode =
55216 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55217 + mnt);
55218 +
55219 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55220 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55221 + reqmode & GR_READ ? " reading" : "",
55222 + reqmode & GR_WRITE ? " writing" : "",
55223 + reqmode & GR_EXEC ? " executing" : "");
55224 + return reqmode;
55225 + } else
55226 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55227 + {
55228 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55229 + reqmode & GR_READ ? " reading" : "",
55230 + reqmode & GR_WRITE ? " writing" : "",
55231 + reqmode & GR_EXEC ? " executing" : "");
55232 + return 0;
55233 + } else if (unlikely((mode & reqmode) != reqmode))
55234 + return 0;
55235 +
55236 + return reqmode;
55237 +}
55238 +
55239 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55240 +{
55241 + __u32 mode;
55242 +
55243 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55244 +
55245 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55246 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55247 + return mode;
55248 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55249 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55250 + return 0;
55251 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55252 + return 0;
55253 +
55254 + return (reqmode);
55255 +}
55256 +
55257 +__u32
55258 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55259 +{
55260 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55261 +}
55262 +
55263 +__u32
55264 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55265 +{
55266 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55267 +}
55268 +
55269 +__u32
55270 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55271 +{
55272 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55273 +}
55274 +
55275 +__u32
55276 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55277 +{
55278 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55279 +}
55280 +
55281 +__u32
55282 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55283 + umode_t *modeptr)
55284 +{
55285 + umode_t mode;
55286 +
55287 + *modeptr &= ~gr_acl_umask();
55288 + mode = *modeptr;
55289 +
55290 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55291 + return 1;
55292 +
55293 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55294 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55295 + GR_CHMOD_ACL_MSG);
55296 + } else {
55297 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55298 + }
55299 +}
55300 +
55301 +__u32
55302 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55303 +{
55304 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55305 +}
55306 +
55307 +__u32
55308 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55309 +{
55310 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55311 +}
55312 +
55313 +__u32
55314 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55315 +{
55316 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55317 +}
55318 +
55319 +__u32
55320 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55321 +{
55322 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55323 + GR_UNIXCONNECT_ACL_MSG);
55324 +}
55325 +
55326 +/* hardlinks require at minimum create and link permission,
55327 + any additional privilege required is based on the
55328 + privilege of the file being linked to
55329 +*/
55330 +__u32
55331 +gr_acl_handle_link(const struct dentry * new_dentry,
55332 + const struct dentry * parent_dentry,
55333 + const struct vfsmount * parent_mnt,
55334 + const struct dentry * old_dentry,
55335 + const struct vfsmount * old_mnt, const char *to)
55336 +{
55337 + __u32 mode;
55338 + __u32 needmode = GR_CREATE | GR_LINK;
55339 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55340 +
55341 + mode =
55342 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55343 + old_mnt);
55344 +
55345 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55346 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55347 + return mode;
55348 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55349 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55350 + return 0;
55351 + } else if (unlikely((mode & needmode) != needmode))
55352 + return 0;
55353 +
55354 + return 1;
55355 +}
55356 +
55357 +__u32
55358 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55359 + const struct dentry * parent_dentry,
55360 + const struct vfsmount * parent_mnt, const char *from)
55361 +{
55362 + __u32 needmode = GR_WRITE | GR_CREATE;
55363 + __u32 mode;
55364 +
55365 + mode =
55366 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55367 + GR_CREATE | GR_AUDIT_CREATE |
55368 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55369 +
55370 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55371 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55372 + return mode;
55373 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55374 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55375 + return 0;
55376 + } else if (unlikely((mode & needmode) != needmode))
55377 + return 0;
55378 +
55379 + return (GR_WRITE | GR_CREATE);
55380 +}
55381 +
55382 +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)
55383 +{
55384 + __u32 mode;
55385 +
55386 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55387 +
55388 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55389 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55390 + return mode;
55391 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55392 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55393 + return 0;
55394 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55395 + return 0;
55396 +
55397 + return (reqmode);
55398 +}
55399 +
55400 +__u32
55401 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55402 + const struct dentry * parent_dentry,
55403 + const struct vfsmount * parent_mnt,
55404 + const int mode)
55405 +{
55406 + __u32 reqmode = GR_WRITE | GR_CREATE;
55407 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55408 + reqmode |= GR_SETID;
55409 +
55410 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55411 + reqmode, GR_MKNOD_ACL_MSG);
55412 +}
55413 +
55414 +__u32
55415 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55416 + const struct dentry *parent_dentry,
55417 + const struct vfsmount *parent_mnt)
55418 +{
55419 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55420 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55421 +}
55422 +
55423 +#define RENAME_CHECK_SUCCESS(old, new) \
55424 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55425 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55426 +
55427 +int
55428 +gr_acl_handle_rename(struct dentry *new_dentry,
55429 + struct dentry *parent_dentry,
55430 + const struct vfsmount *parent_mnt,
55431 + struct dentry *old_dentry,
55432 + struct inode *old_parent_inode,
55433 + struct vfsmount *old_mnt, const char *newname)
55434 +{
55435 + __u32 comp1, comp2;
55436 + int error = 0;
55437 +
55438 + if (unlikely(!gr_acl_is_enabled()))
55439 + return 0;
55440 +
55441 + if (!new_dentry->d_inode) {
55442 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55443 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55444 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55445 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55446 + GR_DELETE | GR_AUDIT_DELETE |
55447 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55448 + GR_SUPPRESS, old_mnt);
55449 + } else {
55450 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55451 + GR_CREATE | GR_DELETE |
55452 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55453 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55454 + GR_SUPPRESS, parent_mnt);
55455 + comp2 =
55456 + gr_search_file(old_dentry,
55457 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55458 + GR_DELETE | GR_AUDIT_DELETE |
55459 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55460 + }
55461 +
55462 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55463 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55464 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55465 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55466 + && !(comp2 & GR_SUPPRESS)) {
55467 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55468 + error = -EACCES;
55469 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55470 + error = -EACCES;
55471 +
55472 + return error;
55473 +}
55474 +
55475 +void
55476 +gr_acl_handle_exit(void)
55477 +{
55478 + u16 id;
55479 + char *rolename;
55480 + struct file *exec_file;
55481 +
55482 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55483 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55484 + id = current->acl_role_id;
55485 + rolename = current->role->rolename;
55486 + gr_set_acls(1);
55487 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55488 + }
55489 +
55490 + write_lock(&grsec_exec_file_lock);
55491 + exec_file = current->exec_file;
55492 + current->exec_file = NULL;
55493 + write_unlock(&grsec_exec_file_lock);
55494 +
55495 + if (exec_file)
55496 + fput(exec_file);
55497 +}
55498 +
55499 +int
55500 +gr_acl_handle_procpidmem(const struct task_struct *task)
55501 +{
55502 + if (unlikely(!gr_acl_is_enabled()))
55503 + return 0;
55504 +
55505 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55506 + return -EACCES;
55507 +
55508 + return 0;
55509 +}
55510 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55511 new file mode 100644
55512 index 0000000..58800a7
55513 --- /dev/null
55514 +++ b/grsecurity/gracl_ip.c
55515 @@ -0,0 +1,384 @@
55516 +#include <linux/kernel.h>
55517 +#include <asm/uaccess.h>
55518 +#include <asm/errno.h>
55519 +#include <net/sock.h>
55520 +#include <linux/file.h>
55521 +#include <linux/fs.h>
55522 +#include <linux/net.h>
55523 +#include <linux/in.h>
55524 +#include <linux/skbuff.h>
55525 +#include <linux/ip.h>
55526 +#include <linux/udp.h>
55527 +#include <linux/types.h>
55528 +#include <linux/sched.h>
55529 +#include <linux/netdevice.h>
55530 +#include <linux/inetdevice.h>
55531 +#include <linux/gracl.h>
55532 +#include <linux/grsecurity.h>
55533 +#include <linux/grinternal.h>
55534 +
55535 +#define GR_BIND 0x01
55536 +#define GR_CONNECT 0x02
55537 +#define GR_INVERT 0x04
55538 +#define GR_BINDOVERRIDE 0x08
55539 +#define GR_CONNECTOVERRIDE 0x10
55540 +#define GR_SOCK_FAMILY 0x20
55541 +
55542 +static const char * gr_protocols[IPPROTO_MAX] = {
55543 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55544 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55545 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55546 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55547 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55548 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55549 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55550 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55551 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55552 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55553 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55554 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55555 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55556 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55557 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55558 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55559 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55560 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55561 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55562 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55563 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55564 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55565 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55566 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55567 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55568 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55569 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55570 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55571 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55572 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55573 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55574 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55575 + };
55576 +
55577 +static const char * gr_socktypes[SOCK_MAX] = {
55578 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55579 + "unknown:7", "unknown:8", "unknown:9", "packet"
55580 + };
55581 +
55582 +static const char * gr_sockfamilies[AF_MAX+1] = {
55583 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55584 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55585 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55586 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55587 + };
55588 +
55589 +const char *
55590 +gr_proto_to_name(unsigned char proto)
55591 +{
55592 + return gr_protocols[proto];
55593 +}
55594 +
55595 +const char *
55596 +gr_socktype_to_name(unsigned char type)
55597 +{
55598 + return gr_socktypes[type];
55599 +}
55600 +
55601 +const char *
55602 +gr_sockfamily_to_name(unsigned char family)
55603 +{
55604 + return gr_sockfamilies[family];
55605 +}
55606 +
55607 +int
55608 +gr_search_socket(const int domain, const int type, const int protocol)
55609 +{
55610 + struct acl_subject_label *curr;
55611 + const struct cred *cred = current_cred();
55612 +
55613 + if (unlikely(!gr_acl_is_enabled()))
55614 + goto exit;
55615 +
55616 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55617 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55618 + goto exit; // let the kernel handle it
55619 +
55620 + curr = current->acl;
55621 +
55622 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55623 + /* the family is allowed, if this is PF_INET allow it only if
55624 + the extra sock type/protocol checks pass */
55625 + if (domain == PF_INET)
55626 + goto inet_check;
55627 + goto exit;
55628 + } else {
55629 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55630 + __u32 fakeip = 0;
55631 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55632 + current->role->roletype, cred->uid,
55633 + cred->gid, current->exec_file ?
55634 + gr_to_filename(current->exec_file->f_path.dentry,
55635 + current->exec_file->f_path.mnt) :
55636 + curr->filename, curr->filename,
55637 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55638 + &current->signal->saved_ip);
55639 + goto exit;
55640 + }
55641 + goto exit_fail;
55642 + }
55643 +
55644 +inet_check:
55645 + /* the rest of this checking is for IPv4 only */
55646 + if (!curr->ips)
55647 + goto exit;
55648 +
55649 + if ((curr->ip_type & (1 << type)) &&
55650 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55651 + goto exit;
55652 +
55653 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55654 + /* we don't place acls on raw sockets , and sometimes
55655 + dgram/ip sockets are opened for ioctl and not
55656 + bind/connect, so we'll fake a bind learn log */
55657 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55658 + __u32 fakeip = 0;
55659 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55660 + current->role->roletype, cred->uid,
55661 + cred->gid, current->exec_file ?
55662 + gr_to_filename(current->exec_file->f_path.dentry,
55663 + current->exec_file->f_path.mnt) :
55664 + curr->filename, curr->filename,
55665 + &fakeip, 0, type,
55666 + protocol, GR_CONNECT, &current->signal->saved_ip);
55667 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55668 + __u32 fakeip = 0;
55669 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55670 + current->role->roletype, cred->uid,
55671 + cred->gid, current->exec_file ?
55672 + gr_to_filename(current->exec_file->f_path.dentry,
55673 + current->exec_file->f_path.mnt) :
55674 + curr->filename, curr->filename,
55675 + &fakeip, 0, type,
55676 + protocol, GR_BIND, &current->signal->saved_ip);
55677 + }
55678 + /* we'll log when they use connect or bind */
55679 + goto exit;
55680 + }
55681 +
55682 +exit_fail:
55683 + if (domain == PF_INET)
55684 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55685 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55686 + else
55687 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55688 + gr_socktype_to_name(type), protocol);
55689 +
55690 + return 0;
55691 +exit:
55692 + return 1;
55693 +}
55694 +
55695 +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)
55696 +{
55697 + if ((ip->mode & mode) &&
55698 + (ip_port >= ip->low) &&
55699 + (ip_port <= ip->high) &&
55700 + ((ntohl(ip_addr) & our_netmask) ==
55701 + (ntohl(our_addr) & our_netmask))
55702 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55703 + && (ip->type & (1 << type))) {
55704 + if (ip->mode & GR_INVERT)
55705 + return 2; // specifically denied
55706 + else
55707 + return 1; // allowed
55708 + }
55709 +
55710 + return 0; // not specifically allowed, may continue parsing
55711 +}
55712 +
55713 +static int
55714 +gr_search_connectbind(const int full_mode, struct sock *sk,
55715 + struct sockaddr_in *addr, const int type)
55716 +{
55717 + char iface[IFNAMSIZ] = {0};
55718 + struct acl_subject_label *curr;
55719 + struct acl_ip_label *ip;
55720 + struct inet_sock *isk;
55721 + struct net_device *dev;
55722 + struct in_device *idev;
55723 + unsigned long i;
55724 + int ret;
55725 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55726 + __u32 ip_addr = 0;
55727 + __u32 our_addr;
55728 + __u32 our_netmask;
55729 + char *p;
55730 + __u16 ip_port = 0;
55731 + const struct cred *cred = current_cred();
55732 +
55733 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55734 + return 0;
55735 +
55736 + curr = current->acl;
55737 + isk = inet_sk(sk);
55738 +
55739 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55740 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55741 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55742 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55743 + struct sockaddr_in saddr;
55744 + int err;
55745 +
55746 + saddr.sin_family = AF_INET;
55747 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55748 + saddr.sin_port = isk->inet_sport;
55749 +
55750 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55751 + if (err)
55752 + return err;
55753 +
55754 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55755 + if (err)
55756 + return err;
55757 + }
55758 +
55759 + if (!curr->ips)
55760 + return 0;
55761 +
55762 + ip_addr = addr->sin_addr.s_addr;
55763 + ip_port = ntohs(addr->sin_port);
55764 +
55765 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55766 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55767 + current->role->roletype, cred->uid,
55768 + cred->gid, current->exec_file ?
55769 + gr_to_filename(current->exec_file->f_path.dentry,
55770 + current->exec_file->f_path.mnt) :
55771 + curr->filename, curr->filename,
55772 + &ip_addr, ip_port, type,
55773 + sk->sk_protocol, mode, &current->signal->saved_ip);
55774 + return 0;
55775 + }
55776 +
55777 + for (i = 0; i < curr->ip_num; i++) {
55778 + ip = *(curr->ips + i);
55779 + if (ip->iface != NULL) {
55780 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55781 + p = strchr(iface, ':');
55782 + if (p != NULL)
55783 + *p = '\0';
55784 + dev = dev_get_by_name(sock_net(sk), iface);
55785 + if (dev == NULL)
55786 + continue;
55787 + idev = in_dev_get(dev);
55788 + if (idev == NULL) {
55789 + dev_put(dev);
55790 + continue;
55791 + }
55792 + rcu_read_lock();
55793 + for_ifa(idev) {
55794 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55795 + our_addr = ifa->ifa_address;
55796 + our_netmask = 0xffffffff;
55797 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55798 + if (ret == 1) {
55799 + rcu_read_unlock();
55800 + in_dev_put(idev);
55801 + dev_put(dev);
55802 + return 0;
55803 + } else if (ret == 2) {
55804 + rcu_read_unlock();
55805 + in_dev_put(idev);
55806 + dev_put(dev);
55807 + goto denied;
55808 + }
55809 + }
55810 + } endfor_ifa(idev);
55811 + rcu_read_unlock();
55812 + in_dev_put(idev);
55813 + dev_put(dev);
55814 + } else {
55815 + our_addr = ip->addr;
55816 + our_netmask = ip->netmask;
55817 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55818 + if (ret == 1)
55819 + return 0;
55820 + else if (ret == 2)
55821 + goto denied;
55822 + }
55823 + }
55824 +
55825 +denied:
55826 + if (mode == GR_BIND)
55827 + 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));
55828 + else if (mode == GR_CONNECT)
55829 + 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));
55830 +
55831 + return -EACCES;
55832 +}
55833 +
55834 +int
55835 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55836 +{
55837 + /* always allow disconnection of dgram sockets with connect */
55838 + if (addr->sin_family == AF_UNSPEC)
55839 + return 0;
55840 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55841 +}
55842 +
55843 +int
55844 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55845 +{
55846 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55847 +}
55848 +
55849 +int gr_search_listen(struct socket *sock)
55850 +{
55851 + struct sock *sk = sock->sk;
55852 + struct sockaddr_in addr;
55853 +
55854 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55855 + addr.sin_port = inet_sk(sk)->inet_sport;
55856 +
55857 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55858 +}
55859 +
55860 +int gr_search_accept(struct socket *sock)
55861 +{
55862 + struct sock *sk = sock->sk;
55863 + struct sockaddr_in addr;
55864 +
55865 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55866 + addr.sin_port = inet_sk(sk)->inet_sport;
55867 +
55868 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55869 +}
55870 +
55871 +int
55872 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55873 +{
55874 + if (addr)
55875 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55876 + else {
55877 + struct sockaddr_in sin;
55878 + const struct inet_sock *inet = inet_sk(sk);
55879 +
55880 + sin.sin_addr.s_addr = inet->inet_daddr;
55881 + sin.sin_port = inet->inet_dport;
55882 +
55883 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55884 + }
55885 +}
55886 +
55887 +int
55888 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55889 +{
55890 + struct sockaddr_in sin;
55891 +
55892 + if (unlikely(skb->len < sizeof (struct udphdr)))
55893 + return 0; // skip this packet
55894 +
55895 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55896 + sin.sin_port = udp_hdr(skb)->source;
55897 +
55898 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55899 +}
55900 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55901 new file mode 100644
55902 index 0000000..25f54ef
55903 --- /dev/null
55904 +++ b/grsecurity/gracl_learn.c
55905 @@ -0,0 +1,207 @@
55906 +#include <linux/kernel.h>
55907 +#include <linux/mm.h>
55908 +#include <linux/sched.h>
55909 +#include <linux/poll.h>
55910 +#include <linux/string.h>
55911 +#include <linux/file.h>
55912 +#include <linux/types.h>
55913 +#include <linux/vmalloc.h>
55914 +#include <linux/grinternal.h>
55915 +
55916 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55917 + size_t count, loff_t *ppos);
55918 +extern int gr_acl_is_enabled(void);
55919 +
55920 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55921 +static int gr_learn_attached;
55922 +
55923 +/* use a 512k buffer */
55924 +#define LEARN_BUFFER_SIZE (512 * 1024)
55925 +
55926 +static DEFINE_SPINLOCK(gr_learn_lock);
55927 +static DEFINE_MUTEX(gr_learn_user_mutex);
55928 +
55929 +/* we need to maintain two buffers, so that the kernel context of grlearn
55930 + uses a semaphore around the userspace copying, and the other kernel contexts
55931 + use a spinlock when copying into the buffer, since they cannot sleep
55932 +*/
55933 +static char *learn_buffer;
55934 +static char *learn_buffer_user;
55935 +static int learn_buffer_len;
55936 +static int learn_buffer_user_len;
55937 +
55938 +static ssize_t
55939 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55940 +{
55941 + DECLARE_WAITQUEUE(wait, current);
55942 + ssize_t retval = 0;
55943 +
55944 + add_wait_queue(&learn_wait, &wait);
55945 + set_current_state(TASK_INTERRUPTIBLE);
55946 + do {
55947 + mutex_lock(&gr_learn_user_mutex);
55948 + spin_lock(&gr_learn_lock);
55949 + if (learn_buffer_len)
55950 + break;
55951 + spin_unlock(&gr_learn_lock);
55952 + mutex_unlock(&gr_learn_user_mutex);
55953 + if (file->f_flags & O_NONBLOCK) {
55954 + retval = -EAGAIN;
55955 + goto out;
55956 + }
55957 + if (signal_pending(current)) {
55958 + retval = -ERESTARTSYS;
55959 + goto out;
55960 + }
55961 +
55962 + schedule();
55963 + } while (1);
55964 +
55965 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55966 + learn_buffer_user_len = learn_buffer_len;
55967 + retval = learn_buffer_len;
55968 + learn_buffer_len = 0;
55969 +
55970 + spin_unlock(&gr_learn_lock);
55971 +
55972 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55973 + retval = -EFAULT;
55974 +
55975 + mutex_unlock(&gr_learn_user_mutex);
55976 +out:
55977 + set_current_state(TASK_RUNNING);
55978 + remove_wait_queue(&learn_wait, &wait);
55979 + return retval;
55980 +}
55981 +
55982 +static unsigned int
55983 +poll_learn(struct file * file, poll_table * wait)
55984 +{
55985 + poll_wait(file, &learn_wait, wait);
55986 +
55987 + if (learn_buffer_len)
55988 + return (POLLIN | POLLRDNORM);
55989 +
55990 + return 0;
55991 +}
55992 +
55993 +void
55994 +gr_clear_learn_entries(void)
55995 +{
55996 + char *tmp;
55997 +
55998 + mutex_lock(&gr_learn_user_mutex);
55999 + spin_lock(&gr_learn_lock);
56000 + tmp = learn_buffer;
56001 + learn_buffer = NULL;
56002 + spin_unlock(&gr_learn_lock);
56003 + if (tmp)
56004 + vfree(tmp);
56005 + if (learn_buffer_user != NULL) {
56006 + vfree(learn_buffer_user);
56007 + learn_buffer_user = NULL;
56008 + }
56009 + learn_buffer_len = 0;
56010 + mutex_unlock(&gr_learn_user_mutex);
56011 +
56012 + return;
56013 +}
56014 +
56015 +void
56016 +gr_add_learn_entry(const char *fmt, ...)
56017 +{
56018 + va_list args;
56019 + unsigned int len;
56020 +
56021 + if (!gr_learn_attached)
56022 + return;
56023 +
56024 + spin_lock(&gr_learn_lock);
56025 +
56026 + /* leave a gap at the end so we know when it's "full" but don't have to
56027 + compute the exact length of the string we're trying to append
56028 + */
56029 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56030 + spin_unlock(&gr_learn_lock);
56031 + wake_up_interruptible(&learn_wait);
56032 + return;
56033 + }
56034 + if (learn_buffer == NULL) {
56035 + spin_unlock(&gr_learn_lock);
56036 + return;
56037 + }
56038 +
56039 + va_start(args, fmt);
56040 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56041 + va_end(args);
56042 +
56043 + learn_buffer_len += len + 1;
56044 +
56045 + spin_unlock(&gr_learn_lock);
56046 + wake_up_interruptible(&learn_wait);
56047 +
56048 + return;
56049 +}
56050 +
56051 +static int
56052 +open_learn(struct inode *inode, struct file *file)
56053 +{
56054 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56055 + return -EBUSY;
56056 + if (file->f_mode & FMODE_READ) {
56057 + int retval = 0;
56058 + mutex_lock(&gr_learn_user_mutex);
56059 + if (learn_buffer == NULL)
56060 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56061 + if (learn_buffer_user == NULL)
56062 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56063 + if (learn_buffer == NULL) {
56064 + retval = -ENOMEM;
56065 + goto out_error;
56066 + }
56067 + if (learn_buffer_user == NULL) {
56068 + retval = -ENOMEM;
56069 + goto out_error;
56070 + }
56071 + learn_buffer_len = 0;
56072 + learn_buffer_user_len = 0;
56073 + gr_learn_attached = 1;
56074 +out_error:
56075 + mutex_unlock(&gr_learn_user_mutex);
56076 + return retval;
56077 + }
56078 + return 0;
56079 +}
56080 +
56081 +static int
56082 +close_learn(struct inode *inode, struct file *file)
56083 +{
56084 + if (file->f_mode & FMODE_READ) {
56085 + char *tmp = NULL;
56086 + mutex_lock(&gr_learn_user_mutex);
56087 + spin_lock(&gr_learn_lock);
56088 + tmp = learn_buffer;
56089 + learn_buffer = NULL;
56090 + spin_unlock(&gr_learn_lock);
56091 + if (tmp)
56092 + vfree(tmp);
56093 + if (learn_buffer_user != NULL) {
56094 + vfree(learn_buffer_user);
56095 + learn_buffer_user = NULL;
56096 + }
56097 + learn_buffer_len = 0;
56098 + learn_buffer_user_len = 0;
56099 + gr_learn_attached = 0;
56100 + mutex_unlock(&gr_learn_user_mutex);
56101 + }
56102 +
56103 + return 0;
56104 +}
56105 +
56106 +const struct file_operations grsec_fops = {
56107 + .read = read_learn,
56108 + .write = write_grsec_handler,
56109 + .open = open_learn,
56110 + .release = close_learn,
56111 + .poll = poll_learn,
56112 +};
56113 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56114 new file mode 100644
56115 index 0000000..39645c9
56116 --- /dev/null
56117 +++ b/grsecurity/gracl_res.c
56118 @@ -0,0 +1,68 @@
56119 +#include <linux/kernel.h>
56120 +#include <linux/sched.h>
56121 +#include <linux/gracl.h>
56122 +#include <linux/grinternal.h>
56123 +
56124 +static const char *restab_log[] = {
56125 + [RLIMIT_CPU] = "RLIMIT_CPU",
56126 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56127 + [RLIMIT_DATA] = "RLIMIT_DATA",
56128 + [RLIMIT_STACK] = "RLIMIT_STACK",
56129 + [RLIMIT_CORE] = "RLIMIT_CORE",
56130 + [RLIMIT_RSS] = "RLIMIT_RSS",
56131 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56132 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56133 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56134 + [RLIMIT_AS] = "RLIMIT_AS",
56135 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56136 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56137 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56138 + [RLIMIT_NICE] = "RLIMIT_NICE",
56139 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56140 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56141 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56142 +};
56143 +
56144 +void
56145 +gr_log_resource(const struct task_struct *task,
56146 + const int res, const unsigned long wanted, const int gt)
56147 +{
56148 + const struct cred *cred;
56149 + unsigned long rlim;
56150 +
56151 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56152 + return;
56153 +
56154 + // not yet supported resource
56155 + if (unlikely(!restab_log[res]))
56156 + return;
56157 +
56158 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56159 + rlim = task_rlimit_max(task, res);
56160 + else
56161 + rlim = task_rlimit(task, res);
56162 +
56163 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56164 + return;
56165 +
56166 + rcu_read_lock();
56167 + cred = __task_cred(task);
56168 +
56169 + if (res == RLIMIT_NPROC &&
56170 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56171 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56172 + goto out_rcu_unlock;
56173 + else if (res == RLIMIT_MEMLOCK &&
56174 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56175 + goto out_rcu_unlock;
56176 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56177 + goto out_rcu_unlock;
56178 + rcu_read_unlock();
56179 +
56180 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56181 +
56182 + return;
56183 +out_rcu_unlock:
56184 + rcu_read_unlock();
56185 + return;
56186 +}
56187 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56188 new file mode 100644
56189 index 0000000..5556be3
56190 --- /dev/null
56191 +++ b/grsecurity/gracl_segv.c
56192 @@ -0,0 +1,299 @@
56193 +#include <linux/kernel.h>
56194 +#include <linux/mm.h>
56195 +#include <asm/uaccess.h>
56196 +#include <asm/errno.h>
56197 +#include <asm/mman.h>
56198 +#include <net/sock.h>
56199 +#include <linux/file.h>
56200 +#include <linux/fs.h>
56201 +#include <linux/net.h>
56202 +#include <linux/in.h>
56203 +#include <linux/slab.h>
56204 +#include <linux/types.h>
56205 +#include <linux/sched.h>
56206 +#include <linux/timer.h>
56207 +#include <linux/gracl.h>
56208 +#include <linux/grsecurity.h>
56209 +#include <linux/grinternal.h>
56210 +
56211 +static struct crash_uid *uid_set;
56212 +static unsigned short uid_used;
56213 +static DEFINE_SPINLOCK(gr_uid_lock);
56214 +extern rwlock_t gr_inode_lock;
56215 +extern struct acl_subject_label *
56216 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56217 + struct acl_role_label *role);
56218 +
56219 +#ifdef CONFIG_BTRFS_FS
56220 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56221 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56222 +#endif
56223 +
56224 +static inline dev_t __get_dev(const struct dentry *dentry)
56225 +{
56226 +#ifdef CONFIG_BTRFS_FS
56227 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56228 + return get_btrfs_dev_from_inode(dentry->d_inode);
56229 + else
56230 +#endif
56231 + return dentry->d_inode->i_sb->s_dev;
56232 +}
56233 +
56234 +int
56235 +gr_init_uidset(void)
56236 +{
56237 + uid_set =
56238 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56239 + uid_used = 0;
56240 +
56241 + return uid_set ? 1 : 0;
56242 +}
56243 +
56244 +void
56245 +gr_free_uidset(void)
56246 +{
56247 + if (uid_set)
56248 + kfree(uid_set);
56249 +
56250 + return;
56251 +}
56252 +
56253 +int
56254 +gr_find_uid(const uid_t uid)
56255 +{
56256 + struct crash_uid *tmp = uid_set;
56257 + uid_t buid;
56258 + int low = 0, high = uid_used - 1, mid;
56259 +
56260 + while (high >= low) {
56261 + mid = (low + high) >> 1;
56262 + buid = tmp[mid].uid;
56263 + if (buid == uid)
56264 + return mid;
56265 + if (buid > uid)
56266 + high = mid - 1;
56267 + if (buid < uid)
56268 + low = mid + 1;
56269 + }
56270 +
56271 + return -1;
56272 +}
56273 +
56274 +static __inline__ void
56275 +gr_insertsort(void)
56276 +{
56277 + unsigned short i, j;
56278 + struct crash_uid index;
56279 +
56280 + for (i = 1; i < uid_used; i++) {
56281 + index = uid_set[i];
56282 + j = i;
56283 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56284 + uid_set[j] = uid_set[j - 1];
56285 + j--;
56286 + }
56287 + uid_set[j] = index;
56288 + }
56289 +
56290 + return;
56291 +}
56292 +
56293 +static __inline__ void
56294 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56295 +{
56296 + int loc;
56297 +
56298 + if (uid_used == GR_UIDTABLE_MAX)
56299 + return;
56300 +
56301 + loc = gr_find_uid(uid);
56302 +
56303 + if (loc >= 0) {
56304 + uid_set[loc].expires = expires;
56305 + return;
56306 + }
56307 +
56308 + uid_set[uid_used].uid = uid;
56309 + uid_set[uid_used].expires = expires;
56310 + uid_used++;
56311 +
56312 + gr_insertsort();
56313 +
56314 + return;
56315 +}
56316 +
56317 +void
56318 +gr_remove_uid(const unsigned short loc)
56319 +{
56320 + unsigned short i;
56321 +
56322 + for (i = loc + 1; i < uid_used; i++)
56323 + uid_set[i - 1] = uid_set[i];
56324 +
56325 + uid_used--;
56326 +
56327 + return;
56328 +}
56329 +
56330 +int
56331 +gr_check_crash_uid(const uid_t uid)
56332 +{
56333 + int loc;
56334 + int ret = 0;
56335 +
56336 + if (unlikely(!gr_acl_is_enabled()))
56337 + return 0;
56338 +
56339 + spin_lock(&gr_uid_lock);
56340 + loc = gr_find_uid(uid);
56341 +
56342 + if (loc < 0)
56343 + goto out_unlock;
56344 +
56345 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56346 + gr_remove_uid(loc);
56347 + else
56348 + ret = 1;
56349 +
56350 +out_unlock:
56351 + spin_unlock(&gr_uid_lock);
56352 + return ret;
56353 +}
56354 +
56355 +static __inline__ int
56356 +proc_is_setxid(const struct cred *cred)
56357 +{
56358 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56359 + cred->uid != cred->fsuid)
56360 + return 1;
56361 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56362 + cred->gid != cred->fsgid)
56363 + return 1;
56364 +
56365 + return 0;
56366 +}
56367 +
56368 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56369 +
56370 +void
56371 +gr_handle_crash(struct task_struct *task, const int sig)
56372 +{
56373 + struct acl_subject_label *curr;
56374 + struct task_struct *tsk, *tsk2;
56375 + const struct cred *cred;
56376 + const struct cred *cred2;
56377 +
56378 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56379 + return;
56380 +
56381 + if (unlikely(!gr_acl_is_enabled()))
56382 + return;
56383 +
56384 + curr = task->acl;
56385 +
56386 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56387 + return;
56388 +
56389 + if (time_before_eq(curr->expires, get_seconds())) {
56390 + curr->expires = 0;
56391 + curr->crashes = 0;
56392 + }
56393 +
56394 + curr->crashes++;
56395 +
56396 + if (!curr->expires)
56397 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56398 +
56399 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56400 + time_after(curr->expires, get_seconds())) {
56401 + rcu_read_lock();
56402 + cred = __task_cred(task);
56403 + if (cred->uid && proc_is_setxid(cred)) {
56404 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56405 + spin_lock(&gr_uid_lock);
56406 + gr_insert_uid(cred->uid, curr->expires);
56407 + spin_unlock(&gr_uid_lock);
56408 + curr->expires = 0;
56409 + curr->crashes = 0;
56410 + read_lock(&tasklist_lock);
56411 + do_each_thread(tsk2, tsk) {
56412 + cred2 = __task_cred(tsk);
56413 + if (tsk != task && cred2->uid == cred->uid)
56414 + gr_fake_force_sig(SIGKILL, tsk);
56415 + } while_each_thread(tsk2, tsk);
56416 + read_unlock(&tasklist_lock);
56417 + } else {
56418 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56419 + read_lock(&tasklist_lock);
56420 + read_lock(&grsec_exec_file_lock);
56421 + do_each_thread(tsk2, tsk) {
56422 + if (likely(tsk != task)) {
56423 + // if this thread has the same subject as the one that triggered
56424 + // RES_CRASH and it's the same binary, kill it
56425 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56426 + gr_fake_force_sig(SIGKILL, tsk);
56427 + }
56428 + } while_each_thread(tsk2, tsk);
56429 + read_unlock(&grsec_exec_file_lock);
56430 + read_unlock(&tasklist_lock);
56431 + }
56432 + rcu_read_unlock();
56433 + }
56434 +
56435 + return;
56436 +}
56437 +
56438 +int
56439 +gr_check_crash_exec(const struct file *filp)
56440 +{
56441 + struct acl_subject_label *curr;
56442 +
56443 + if (unlikely(!gr_acl_is_enabled()))
56444 + return 0;
56445 +
56446 + read_lock(&gr_inode_lock);
56447 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56448 + __get_dev(filp->f_path.dentry),
56449 + current->role);
56450 + read_unlock(&gr_inode_lock);
56451 +
56452 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56453 + (!curr->crashes && !curr->expires))
56454 + return 0;
56455 +
56456 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56457 + time_after(curr->expires, get_seconds()))
56458 + return 1;
56459 + else if (time_before_eq(curr->expires, get_seconds())) {
56460 + curr->crashes = 0;
56461 + curr->expires = 0;
56462 + }
56463 +
56464 + return 0;
56465 +}
56466 +
56467 +void
56468 +gr_handle_alertkill(struct task_struct *task)
56469 +{
56470 + struct acl_subject_label *curracl;
56471 + __u32 curr_ip;
56472 + struct task_struct *p, *p2;
56473 +
56474 + if (unlikely(!gr_acl_is_enabled()))
56475 + return;
56476 +
56477 + curracl = task->acl;
56478 + curr_ip = task->signal->curr_ip;
56479 +
56480 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56481 + read_lock(&tasklist_lock);
56482 + do_each_thread(p2, p) {
56483 + if (p->signal->curr_ip == curr_ip)
56484 + gr_fake_force_sig(SIGKILL, p);
56485 + } while_each_thread(p2, p);
56486 + read_unlock(&tasklist_lock);
56487 + } else if (curracl->mode & GR_KILLPROC)
56488 + gr_fake_force_sig(SIGKILL, task);
56489 +
56490 + return;
56491 +}
56492 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56493 new file mode 100644
56494 index 0000000..9d83a69
56495 --- /dev/null
56496 +++ b/grsecurity/gracl_shm.c
56497 @@ -0,0 +1,40 @@
56498 +#include <linux/kernel.h>
56499 +#include <linux/mm.h>
56500 +#include <linux/sched.h>
56501 +#include <linux/file.h>
56502 +#include <linux/ipc.h>
56503 +#include <linux/gracl.h>
56504 +#include <linux/grsecurity.h>
56505 +#include <linux/grinternal.h>
56506 +
56507 +int
56508 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56509 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56510 +{
56511 + struct task_struct *task;
56512 +
56513 + if (!gr_acl_is_enabled())
56514 + return 1;
56515 +
56516 + rcu_read_lock();
56517 + read_lock(&tasklist_lock);
56518 +
56519 + task = find_task_by_vpid(shm_cprid);
56520 +
56521 + if (unlikely(!task))
56522 + task = find_task_by_vpid(shm_lapid);
56523 +
56524 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56525 + (task->pid == shm_lapid)) &&
56526 + (task->acl->mode & GR_PROTSHM) &&
56527 + (task->acl != current->acl))) {
56528 + read_unlock(&tasklist_lock);
56529 + rcu_read_unlock();
56530 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56531 + return 0;
56532 + }
56533 + read_unlock(&tasklist_lock);
56534 + rcu_read_unlock();
56535 +
56536 + return 1;
56537 +}
56538 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56539 new file mode 100644
56540 index 0000000..bc0be01
56541 --- /dev/null
56542 +++ b/grsecurity/grsec_chdir.c
56543 @@ -0,0 +1,19 @@
56544 +#include <linux/kernel.h>
56545 +#include <linux/sched.h>
56546 +#include <linux/fs.h>
56547 +#include <linux/file.h>
56548 +#include <linux/grsecurity.h>
56549 +#include <linux/grinternal.h>
56550 +
56551 +void
56552 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56553 +{
56554 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56555 + if ((grsec_enable_chdir && grsec_enable_group &&
56556 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56557 + !grsec_enable_group)) {
56558 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56559 + }
56560 +#endif
56561 + return;
56562 +}
56563 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56564 new file mode 100644
56565 index 0000000..9807ee2
56566 --- /dev/null
56567 +++ b/grsecurity/grsec_chroot.c
56568 @@ -0,0 +1,368 @@
56569 +#include <linux/kernel.h>
56570 +#include <linux/module.h>
56571 +#include <linux/sched.h>
56572 +#include <linux/file.h>
56573 +#include <linux/fs.h>
56574 +#include <linux/mount.h>
56575 +#include <linux/types.h>
56576 +#include "../fs/mount.h"
56577 +#include <linux/grsecurity.h>
56578 +#include <linux/grinternal.h>
56579 +
56580 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56581 +{
56582 +#ifdef CONFIG_GRKERNSEC
56583 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56584 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56585 + task->gr_is_chrooted = 1;
56586 + else
56587 + task->gr_is_chrooted = 0;
56588 +
56589 + task->gr_chroot_dentry = path->dentry;
56590 +#endif
56591 + return;
56592 +}
56593 +
56594 +void gr_clear_chroot_entries(struct task_struct *task)
56595 +{
56596 +#ifdef CONFIG_GRKERNSEC
56597 + task->gr_is_chrooted = 0;
56598 + task->gr_chroot_dentry = NULL;
56599 +#endif
56600 + return;
56601 +}
56602 +
56603 +int
56604 +gr_handle_chroot_unix(const pid_t pid)
56605 +{
56606 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56607 + struct task_struct *p;
56608 +
56609 + if (unlikely(!grsec_enable_chroot_unix))
56610 + return 1;
56611 +
56612 + if (likely(!proc_is_chrooted(current)))
56613 + return 1;
56614 +
56615 + rcu_read_lock();
56616 + read_lock(&tasklist_lock);
56617 + p = find_task_by_vpid_unrestricted(pid);
56618 + if (unlikely(p && !have_same_root(current, p))) {
56619 + read_unlock(&tasklist_lock);
56620 + rcu_read_unlock();
56621 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56622 + return 0;
56623 + }
56624 + read_unlock(&tasklist_lock);
56625 + rcu_read_unlock();
56626 +#endif
56627 + return 1;
56628 +}
56629 +
56630 +int
56631 +gr_handle_chroot_nice(void)
56632 +{
56633 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56634 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56635 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56636 + return -EPERM;
56637 + }
56638 +#endif
56639 + return 0;
56640 +}
56641 +
56642 +int
56643 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56644 +{
56645 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56646 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56647 + && proc_is_chrooted(current)) {
56648 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56649 + return -EACCES;
56650 + }
56651 +#endif
56652 + return 0;
56653 +}
56654 +
56655 +int
56656 +gr_handle_chroot_rawio(const struct inode *inode)
56657 +{
56658 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56659 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56660 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56661 + return 1;
56662 +#endif
56663 + return 0;
56664 +}
56665 +
56666 +int
56667 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56668 +{
56669 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56670 + struct task_struct *p;
56671 + int ret = 0;
56672 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56673 + return ret;
56674 +
56675 + read_lock(&tasklist_lock);
56676 + do_each_pid_task(pid, type, p) {
56677 + if (!have_same_root(current, p)) {
56678 + ret = 1;
56679 + goto out;
56680 + }
56681 + } while_each_pid_task(pid, type, p);
56682 +out:
56683 + read_unlock(&tasklist_lock);
56684 + return ret;
56685 +#endif
56686 + return 0;
56687 +}
56688 +
56689 +int
56690 +gr_pid_is_chrooted(struct task_struct *p)
56691 +{
56692 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56693 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56694 + return 0;
56695 +
56696 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56697 + !have_same_root(current, p)) {
56698 + return 1;
56699 + }
56700 +#endif
56701 + return 0;
56702 +}
56703 +
56704 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56705 +
56706 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56707 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56708 +{
56709 + struct path path, currentroot;
56710 + int ret = 0;
56711 +
56712 + path.dentry = (struct dentry *)u_dentry;
56713 + path.mnt = (struct vfsmount *)u_mnt;
56714 + get_fs_root(current->fs, &currentroot);
56715 + if (path_is_under(&path, &currentroot))
56716 + ret = 1;
56717 + path_put(&currentroot);
56718 +
56719 + return ret;
56720 +}
56721 +#endif
56722 +
56723 +int
56724 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56725 +{
56726 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56727 + if (!grsec_enable_chroot_fchdir)
56728 + return 1;
56729 +
56730 + if (!proc_is_chrooted(current))
56731 + return 1;
56732 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56733 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56734 + return 0;
56735 + }
56736 +#endif
56737 + return 1;
56738 +}
56739 +
56740 +int
56741 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56742 + const time_t shm_createtime)
56743 +{
56744 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56745 + struct task_struct *p;
56746 + time_t starttime;
56747 +
56748 + if (unlikely(!grsec_enable_chroot_shmat))
56749 + return 1;
56750 +
56751 + if (likely(!proc_is_chrooted(current)))
56752 + return 1;
56753 +
56754 + rcu_read_lock();
56755 + read_lock(&tasklist_lock);
56756 +
56757 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56758 + starttime = p->start_time.tv_sec;
56759 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56760 + if (have_same_root(current, p)) {
56761 + goto allow;
56762 + } else {
56763 + read_unlock(&tasklist_lock);
56764 + rcu_read_unlock();
56765 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56766 + return 0;
56767 + }
56768 + }
56769 + /* creator exited, pid reuse, fall through to next check */
56770 + }
56771 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56772 + if (unlikely(!have_same_root(current, p))) {
56773 + read_unlock(&tasklist_lock);
56774 + rcu_read_unlock();
56775 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56776 + return 0;
56777 + }
56778 + }
56779 +
56780 +allow:
56781 + read_unlock(&tasklist_lock);
56782 + rcu_read_unlock();
56783 +#endif
56784 + return 1;
56785 +}
56786 +
56787 +void
56788 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56789 +{
56790 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56791 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56792 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56793 +#endif
56794 + return;
56795 +}
56796 +
56797 +int
56798 +gr_handle_chroot_mknod(const struct dentry *dentry,
56799 + const struct vfsmount *mnt, const int mode)
56800 +{
56801 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56802 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56803 + proc_is_chrooted(current)) {
56804 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56805 + return -EPERM;
56806 + }
56807 +#endif
56808 + return 0;
56809 +}
56810 +
56811 +int
56812 +gr_handle_chroot_mount(const struct dentry *dentry,
56813 + const struct vfsmount *mnt, const char *dev_name)
56814 +{
56815 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56816 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56817 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56818 + return -EPERM;
56819 + }
56820 +#endif
56821 + return 0;
56822 +}
56823 +
56824 +int
56825 +gr_handle_chroot_pivot(void)
56826 +{
56827 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56828 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56829 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56830 + return -EPERM;
56831 + }
56832 +#endif
56833 + return 0;
56834 +}
56835 +
56836 +int
56837 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56838 +{
56839 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56840 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56841 + !gr_is_outside_chroot(dentry, mnt)) {
56842 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56843 + return -EPERM;
56844 + }
56845 +#endif
56846 + return 0;
56847 +}
56848 +
56849 +extern const char *captab_log[];
56850 +extern int captab_log_entries;
56851 +
56852 +int
56853 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56854 +{
56855 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56856 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56857 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56858 + if (cap_raised(chroot_caps, cap)) {
56859 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56860 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56861 + }
56862 + return 0;
56863 + }
56864 + }
56865 +#endif
56866 + return 1;
56867 +}
56868 +
56869 +int
56870 +gr_chroot_is_capable(const int cap)
56871 +{
56872 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56873 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56874 +#endif
56875 + return 1;
56876 +}
56877 +
56878 +int
56879 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56880 +{
56881 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56882 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56883 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56884 + if (cap_raised(chroot_caps, cap)) {
56885 + return 0;
56886 + }
56887 + }
56888 +#endif
56889 + return 1;
56890 +}
56891 +
56892 +int
56893 +gr_chroot_is_capable_nolog(const int cap)
56894 +{
56895 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56896 + return gr_task_chroot_is_capable_nolog(current, cap);
56897 +#endif
56898 + return 1;
56899 +}
56900 +
56901 +int
56902 +gr_handle_chroot_sysctl(const int op)
56903 +{
56904 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56905 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56906 + proc_is_chrooted(current))
56907 + return -EACCES;
56908 +#endif
56909 + return 0;
56910 +}
56911 +
56912 +void
56913 +gr_handle_chroot_chdir(struct path *path)
56914 +{
56915 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56916 + if (grsec_enable_chroot_chdir)
56917 + set_fs_pwd(current->fs, path);
56918 +#endif
56919 + return;
56920 +}
56921 +
56922 +int
56923 +gr_handle_chroot_chmod(const struct dentry *dentry,
56924 + const struct vfsmount *mnt, const int mode)
56925 +{
56926 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56927 + /* allow chmod +s on directories, but not files */
56928 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56929 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56930 + proc_is_chrooted(current)) {
56931 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56932 + return -EPERM;
56933 + }
56934 +#endif
56935 + return 0;
56936 +}
56937 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56938 new file mode 100644
56939 index 0000000..213ad8b
56940 --- /dev/null
56941 +++ b/grsecurity/grsec_disabled.c
56942 @@ -0,0 +1,437 @@
56943 +#include <linux/kernel.h>
56944 +#include <linux/module.h>
56945 +#include <linux/sched.h>
56946 +#include <linux/file.h>
56947 +#include <linux/fs.h>
56948 +#include <linux/kdev_t.h>
56949 +#include <linux/net.h>
56950 +#include <linux/in.h>
56951 +#include <linux/ip.h>
56952 +#include <linux/skbuff.h>
56953 +#include <linux/sysctl.h>
56954 +
56955 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56956 +void
56957 +pax_set_initial_flags(struct linux_binprm *bprm)
56958 +{
56959 + return;
56960 +}
56961 +#endif
56962 +
56963 +#ifdef CONFIG_SYSCTL
56964 +__u32
56965 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56966 +{
56967 + return 0;
56968 +}
56969 +#endif
56970 +
56971 +#ifdef CONFIG_TASKSTATS
56972 +int gr_is_taskstats_denied(int pid)
56973 +{
56974 + return 0;
56975 +}
56976 +#endif
56977 +
56978 +int
56979 +gr_acl_is_enabled(void)
56980 +{
56981 + return 0;
56982 +}
56983 +
56984 +void
56985 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56986 +{
56987 + return;
56988 +}
56989 +
56990 +int
56991 +gr_handle_rawio(const struct inode *inode)
56992 +{
56993 + return 0;
56994 +}
56995 +
56996 +void
56997 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56998 +{
56999 + return;
57000 +}
57001 +
57002 +int
57003 +gr_handle_ptrace(struct task_struct *task, const long request)
57004 +{
57005 + return 0;
57006 +}
57007 +
57008 +int
57009 +gr_handle_proc_ptrace(struct task_struct *task)
57010 +{
57011 + return 0;
57012 +}
57013 +
57014 +void
57015 +gr_learn_resource(const struct task_struct *task,
57016 + const int res, const unsigned long wanted, const int gt)
57017 +{
57018 + return;
57019 +}
57020 +
57021 +int
57022 +gr_set_acls(const int type)
57023 +{
57024 + return 0;
57025 +}
57026 +
57027 +int
57028 +gr_check_hidden_task(const struct task_struct *tsk)
57029 +{
57030 + return 0;
57031 +}
57032 +
57033 +int
57034 +gr_check_protected_task(const struct task_struct *task)
57035 +{
57036 + return 0;
57037 +}
57038 +
57039 +int
57040 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57041 +{
57042 + return 0;
57043 +}
57044 +
57045 +void
57046 +gr_copy_label(struct task_struct *tsk)
57047 +{
57048 + return;
57049 +}
57050 +
57051 +void
57052 +gr_set_pax_flags(struct task_struct *task)
57053 +{
57054 + return;
57055 +}
57056 +
57057 +int
57058 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57059 + const int unsafe_share)
57060 +{
57061 + return 0;
57062 +}
57063 +
57064 +void
57065 +gr_handle_delete(const ino_t ino, const dev_t dev)
57066 +{
57067 + return;
57068 +}
57069 +
57070 +void
57071 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57072 +{
57073 + return;
57074 +}
57075 +
57076 +void
57077 +gr_handle_crash(struct task_struct *task, const int sig)
57078 +{
57079 + return;
57080 +}
57081 +
57082 +int
57083 +gr_check_crash_exec(const struct file *filp)
57084 +{
57085 + return 0;
57086 +}
57087 +
57088 +int
57089 +gr_check_crash_uid(const uid_t uid)
57090 +{
57091 + return 0;
57092 +}
57093 +
57094 +void
57095 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57096 + struct dentry *old_dentry,
57097 + struct dentry *new_dentry,
57098 + struct vfsmount *mnt, const __u8 replace)
57099 +{
57100 + return;
57101 +}
57102 +
57103 +int
57104 +gr_search_socket(const int family, const int type, const int protocol)
57105 +{
57106 + return 1;
57107 +}
57108 +
57109 +int
57110 +gr_search_connectbind(const int mode, const struct socket *sock,
57111 + const struct sockaddr_in *addr)
57112 +{
57113 + return 0;
57114 +}
57115 +
57116 +void
57117 +gr_handle_alertkill(struct task_struct *task)
57118 +{
57119 + return;
57120 +}
57121 +
57122 +__u32
57123 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57124 +{
57125 + return 1;
57126 +}
57127 +
57128 +__u32
57129 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57130 + const struct vfsmount * mnt)
57131 +{
57132 + return 1;
57133 +}
57134 +
57135 +__u32
57136 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57137 + int acc_mode)
57138 +{
57139 + return 1;
57140 +}
57141 +
57142 +__u32
57143 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57144 +{
57145 + return 1;
57146 +}
57147 +
57148 +__u32
57149 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57150 +{
57151 + return 1;
57152 +}
57153 +
57154 +int
57155 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57156 + unsigned int *vm_flags)
57157 +{
57158 + return 1;
57159 +}
57160 +
57161 +__u32
57162 +gr_acl_handle_truncate(const struct dentry * dentry,
57163 + const struct vfsmount * mnt)
57164 +{
57165 + return 1;
57166 +}
57167 +
57168 +__u32
57169 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57170 +{
57171 + return 1;
57172 +}
57173 +
57174 +__u32
57175 +gr_acl_handle_access(const struct dentry * dentry,
57176 + const struct vfsmount * mnt, const int fmode)
57177 +{
57178 + return 1;
57179 +}
57180 +
57181 +__u32
57182 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57183 + umode_t *mode)
57184 +{
57185 + return 1;
57186 +}
57187 +
57188 +__u32
57189 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57190 +{
57191 + return 1;
57192 +}
57193 +
57194 +__u32
57195 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57196 +{
57197 + return 1;
57198 +}
57199 +
57200 +void
57201 +grsecurity_init(void)
57202 +{
57203 + return;
57204 +}
57205 +
57206 +umode_t gr_acl_umask(void)
57207 +{
57208 + return 0;
57209 +}
57210 +
57211 +__u32
57212 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57213 + const struct dentry * parent_dentry,
57214 + const struct vfsmount * parent_mnt,
57215 + const int mode)
57216 +{
57217 + return 1;
57218 +}
57219 +
57220 +__u32
57221 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57222 + const struct dentry * parent_dentry,
57223 + const struct vfsmount * parent_mnt)
57224 +{
57225 + return 1;
57226 +}
57227 +
57228 +__u32
57229 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57230 + const struct dentry * parent_dentry,
57231 + const struct vfsmount * parent_mnt, const char *from)
57232 +{
57233 + return 1;
57234 +}
57235 +
57236 +__u32
57237 +gr_acl_handle_link(const struct dentry * new_dentry,
57238 + const struct dentry * parent_dentry,
57239 + const struct vfsmount * parent_mnt,
57240 + const struct dentry * old_dentry,
57241 + const struct vfsmount * old_mnt, const char *to)
57242 +{
57243 + return 1;
57244 +}
57245 +
57246 +int
57247 +gr_acl_handle_rename(const struct dentry *new_dentry,
57248 + const struct dentry *parent_dentry,
57249 + const struct vfsmount *parent_mnt,
57250 + const struct dentry *old_dentry,
57251 + const struct inode *old_parent_inode,
57252 + const struct vfsmount *old_mnt, const char *newname)
57253 +{
57254 + return 0;
57255 +}
57256 +
57257 +int
57258 +gr_acl_handle_filldir(const struct file *file, const char *name,
57259 + const int namelen, const ino_t ino)
57260 +{
57261 + return 1;
57262 +}
57263 +
57264 +int
57265 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57266 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57267 +{
57268 + return 1;
57269 +}
57270 +
57271 +int
57272 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57273 +{
57274 + return 0;
57275 +}
57276 +
57277 +int
57278 +gr_search_accept(const struct socket *sock)
57279 +{
57280 + return 0;
57281 +}
57282 +
57283 +int
57284 +gr_search_listen(const struct socket *sock)
57285 +{
57286 + return 0;
57287 +}
57288 +
57289 +int
57290 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57291 +{
57292 + return 0;
57293 +}
57294 +
57295 +__u32
57296 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57297 +{
57298 + return 1;
57299 +}
57300 +
57301 +__u32
57302 +gr_acl_handle_creat(const struct dentry * dentry,
57303 + const struct dentry * p_dentry,
57304 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57305 + const int imode)
57306 +{
57307 + return 1;
57308 +}
57309 +
57310 +void
57311 +gr_acl_handle_exit(void)
57312 +{
57313 + return;
57314 +}
57315 +
57316 +int
57317 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57318 +{
57319 + return 1;
57320 +}
57321 +
57322 +void
57323 +gr_set_role_label(const uid_t uid, const gid_t gid)
57324 +{
57325 + return;
57326 +}
57327 +
57328 +int
57329 +gr_acl_handle_procpidmem(const struct task_struct *task)
57330 +{
57331 + return 0;
57332 +}
57333 +
57334 +int
57335 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57336 +{
57337 + return 0;
57338 +}
57339 +
57340 +int
57341 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57342 +{
57343 + return 0;
57344 +}
57345 +
57346 +void
57347 +gr_set_kernel_label(struct task_struct *task)
57348 +{
57349 + return;
57350 +}
57351 +
57352 +int
57353 +gr_check_user_change(int real, int effective, int fs)
57354 +{
57355 + return 0;
57356 +}
57357 +
57358 +int
57359 +gr_check_group_change(int real, int effective, int fs)
57360 +{
57361 + return 0;
57362 +}
57363 +
57364 +int gr_acl_enable_at_secure(void)
57365 +{
57366 + return 0;
57367 +}
57368 +
57369 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57370 +{
57371 + return dentry->d_inode->i_sb->s_dev;
57372 +}
57373 +
57374 +EXPORT_SYMBOL(gr_learn_resource);
57375 +EXPORT_SYMBOL(gr_set_kernel_label);
57376 +#ifdef CONFIG_SECURITY
57377 +EXPORT_SYMBOL(gr_check_user_change);
57378 +EXPORT_SYMBOL(gr_check_group_change);
57379 +#endif
57380 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57381 new file mode 100644
57382 index 0000000..abfa971
57383 --- /dev/null
57384 +++ b/grsecurity/grsec_exec.c
57385 @@ -0,0 +1,174 @@
57386 +#include <linux/kernel.h>
57387 +#include <linux/sched.h>
57388 +#include <linux/file.h>
57389 +#include <linux/binfmts.h>
57390 +#include <linux/fs.h>
57391 +#include <linux/types.h>
57392 +#include <linux/grdefs.h>
57393 +#include <linux/grsecurity.h>
57394 +#include <linux/grinternal.h>
57395 +#include <linux/capability.h>
57396 +#include <linux/module.h>
57397 +
57398 +#include <asm/uaccess.h>
57399 +
57400 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57401 +static char gr_exec_arg_buf[132];
57402 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57403 +#endif
57404 +
57405 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57406 +
57407 +void
57408 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57409 +{
57410 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57411 + char *grarg = gr_exec_arg_buf;
57412 + unsigned int i, x, execlen = 0;
57413 + char c;
57414 +
57415 + if (!((grsec_enable_execlog && grsec_enable_group &&
57416 + in_group_p(grsec_audit_gid))
57417 + || (grsec_enable_execlog && !grsec_enable_group)))
57418 + return;
57419 +
57420 + mutex_lock(&gr_exec_arg_mutex);
57421 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57422 +
57423 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57424 + const char __user *p;
57425 + unsigned int len;
57426 +
57427 + p = get_user_arg_ptr(argv, i);
57428 + if (IS_ERR(p))
57429 + goto log;
57430 +
57431 + len = strnlen_user(p, 128 - execlen);
57432 + if (len > 128 - execlen)
57433 + len = 128 - execlen;
57434 + else if (len > 0)
57435 + len--;
57436 + if (copy_from_user(grarg + execlen, p, len))
57437 + goto log;
57438 +
57439 + /* rewrite unprintable characters */
57440 + for (x = 0; x < len; x++) {
57441 + c = *(grarg + execlen + x);
57442 + if (c < 32 || c > 126)
57443 + *(grarg + execlen + x) = ' ';
57444 + }
57445 +
57446 + execlen += len;
57447 + *(grarg + execlen) = ' ';
57448 + *(grarg + execlen + 1) = '\0';
57449 + execlen++;
57450 + }
57451 +
57452 + log:
57453 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57454 + bprm->file->f_path.mnt, grarg);
57455 + mutex_unlock(&gr_exec_arg_mutex);
57456 +#endif
57457 + return;
57458 +}
57459 +
57460 +#ifdef CONFIG_GRKERNSEC
57461 +extern int gr_acl_is_capable(const int cap);
57462 +extern int gr_acl_is_capable_nolog(const int cap);
57463 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57464 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57465 +extern int gr_chroot_is_capable(const int cap);
57466 +extern int gr_chroot_is_capable_nolog(const int cap);
57467 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57468 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57469 +#endif
57470 +
57471 +const char *captab_log[] = {
57472 + "CAP_CHOWN",
57473 + "CAP_DAC_OVERRIDE",
57474 + "CAP_DAC_READ_SEARCH",
57475 + "CAP_FOWNER",
57476 + "CAP_FSETID",
57477 + "CAP_KILL",
57478 + "CAP_SETGID",
57479 + "CAP_SETUID",
57480 + "CAP_SETPCAP",
57481 + "CAP_LINUX_IMMUTABLE",
57482 + "CAP_NET_BIND_SERVICE",
57483 + "CAP_NET_BROADCAST",
57484 + "CAP_NET_ADMIN",
57485 + "CAP_NET_RAW",
57486 + "CAP_IPC_LOCK",
57487 + "CAP_IPC_OWNER",
57488 + "CAP_SYS_MODULE",
57489 + "CAP_SYS_RAWIO",
57490 + "CAP_SYS_CHROOT",
57491 + "CAP_SYS_PTRACE",
57492 + "CAP_SYS_PACCT",
57493 + "CAP_SYS_ADMIN",
57494 + "CAP_SYS_BOOT",
57495 + "CAP_SYS_NICE",
57496 + "CAP_SYS_RESOURCE",
57497 + "CAP_SYS_TIME",
57498 + "CAP_SYS_TTY_CONFIG",
57499 + "CAP_MKNOD",
57500 + "CAP_LEASE",
57501 + "CAP_AUDIT_WRITE",
57502 + "CAP_AUDIT_CONTROL",
57503 + "CAP_SETFCAP",
57504 + "CAP_MAC_OVERRIDE",
57505 + "CAP_MAC_ADMIN",
57506 + "CAP_SYSLOG",
57507 + "CAP_WAKE_ALARM"
57508 +};
57509 +
57510 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57511 +
57512 +int gr_is_capable(const int cap)
57513 +{
57514 +#ifdef CONFIG_GRKERNSEC
57515 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57516 + return 1;
57517 + return 0;
57518 +#else
57519 + return 1;
57520 +#endif
57521 +}
57522 +
57523 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57524 +{
57525 +#ifdef CONFIG_GRKERNSEC
57526 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57527 + return 1;
57528 + return 0;
57529 +#else
57530 + return 1;
57531 +#endif
57532 +}
57533 +
57534 +int gr_is_capable_nolog(const int cap)
57535 +{
57536 +#ifdef CONFIG_GRKERNSEC
57537 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57538 + return 1;
57539 + return 0;
57540 +#else
57541 + return 1;
57542 +#endif
57543 +}
57544 +
57545 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57546 +{
57547 +#ifdef CONFIG_GRKERNSEC
57548 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57549 + return 1;
57550 + return 0;
57551 +#else
57552 + return 1;
57553 +#endif
57554 +}
57555 +
57556 +EXPORT_SYMBOL(gr_is_capable);
57557 +EXPORT_SYMBOL(gr_is_capable_nolog);
57558 +EXPORT_SYMBOL(gr_task_is_capable);
57559 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57560 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57561 new file mode 100644
57562 index 0000000..d3ee748
57563 --- /dev/null
57564 +++ b/grsecurity/grsec_fifo.c
57565 @@ -0,0 +1,24 @@
57566 +#include <linux/kernel.h>
57567 +#include <linux/sched.h>
57568 +#include <linux/fs.h>
57569 +#include <linux/file.h>
57570 +#include <linux/grinternal.h>
57571 +
57572 +int
57573 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57574 + const struct dentry *dir, const int flag, const int acc_mode)
57575 +{
57576 +#ifdef CONFIG_GRKERNSEC_FIFO
57577 + const struct cred *cred = current_cred();
57578 +
57579 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57580 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57581 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57582 + (cred->fsuid != dentry->d_inode->i_uid)) {
57583 + if (!inode_permission(dentry->d_inode, acc_mode))
57584 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57585 + return -EACCES;
57586 + }
57587 +#endif
57588 + return 0;
57589 +}
57590 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57591 new file mode 100644
57592 index 0000000..8ca18bf
57593 --- /dev/null
57594 +++ b/grsecurity/grsec_fork.c
57595 @@ -0,0 +1,23 @@
57596 +#include <linux/kernel.h>
57597 +#include <linux/sched.h>
57598 +#include <linux/grsecurity.h>
57599 +#include <linux/grinternal.h>
57600 +#include <linux/errno.h>
57601 +
57602 +void
57603 +gr_log_forkfail(const int retval)
57604 +{
57605 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57606 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57607 + switch (retval) {
57608 + case -EAGAIN:
57609 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57610 + break;
57611 + case -ENOMEM:
57612 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57613 + break;
57614 + }
57615 + }
57616 +#endif
57617 + return;
57618 +}
57619 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57620 new file mode 100644
57621 index 0000000..01ddde4
57622 --- /dev/null
57623 +++ b/grsecurity/grsec_init.c
57624 @@ -0,0 +1,277 @@
57625 +#include <linux/kernel.h>
57626 +#include <linux/sched.h>
57627 +#include <linux/mm.h>
57628 +#include <linux/gracl.h>
57629 +#include <linux/slab.h>
57630 +#include <linux/vmalloc.h>
57631 +#include <linux/percpu.h>
57632 +#include <linux/module.h>
57633 +
57634 +int grsec_enable_ptrace_readexec;
57635 +int grsec_enable_setxid;
57636 +int grsec_enable_brute;
57637 +int grsec_enable_link;
57638 +int grsec_enable_dmesg;
57639 +int grsec_enable_harden_ptrace;
57640 +int grsec_enable_fifo;
57641 +int grsec_enable_execlog;
57642 +int grsec_enable_signal;
57643 +int grsec_enable_forkfail;
57644 +int grsec_enable_audit_ptrace;
57645 +int grsec_enable_time;
57646 +int grsec_enable_audit_textrel;
57647 +int grsec_enable_group;
57648 +int grsec_audit_gid;
57649 +int grsec_enable_chdir;
57650 +int grsec_enable_mount;
57651 +int grsec_enable_rofs;
57652 +int grsec_enable_chroot_findtask;
57653 +int grsec_enable_chroot_mount;
57654 +int grsec_enable_chroot_shmat;
57655 +int grsec_enable_chroot_fchdir;
57656 +int grsec_enable_chroot_double;
57657 +int grsec_enable_chroot_pivot;
57658 +int grsec_enable_chroot_chdir;
57659 +int grsec_enable_chroot_chmod;
57660 +int grsec_enable_chroot_mknod;
57661 +int grsec_enable_chroot_nice;
57662 +int grsec_enable_chroot_execlog;
57663 +int grsec_enable_chroot_caps;
57664 +int grsec_enable_chroot_sysctl;
57665 +int grsec_enable_chroot_unix;
57666 +int grsec_enable_tpe;
57667 +int grsec_tpe_gid;
57668 +int grsec_enable_blackhole;
57669 +#ifdef CONFIG_IPV6_MODULE
57670 +EXPORT_SYMBOL(grsec_enable_blackhole);
57671 +#endif
57672 +int grsec_lastack_retries;
57673 +int grsec_enable_tpe_all;
57674 +int grsec_enable_tpe_invert;
57675 +int grsec_enable_socket_all;
57676 +int grsec_socket_all_gid;
57677 +int grsec_enable_socket_client;
57678 +int grsec_socket_client_gid;
57679 +int grsec_enable_socket_server;
57680 +int grsec_socket_server_gid;
57681 +int grsec_resource_logging;
57682 +int grsec_disable_privio;
57683 +int grsec_enable_log_rwxmaps;
57684 +int grsec_lock;
57685 +
57686 +DEFINE_SPINLOCK(grsec_alert_lock);
57687 +unsigned long grsec_alert_wtime = 0;
57688 +unsigned long grsec_alert_fyet = 0;
57689 +
57690 +DEFINE_SPINLOCK(grsec_audit_lock);
57691 +
57692 +DEFINE_RWLOCK(grsec_exec_file_lock);
57693 +
57694 +char *gr_shared_page[4];
57695 +
57696 +char *gr_alert_log_fmt;
57697 +char *gr_audit_log_fmt;
57698 +char *gr_alert_log_buf;
57699 +char *gr_audit_log_buf;
57700 +
57701 +extern struct gr_arg *gr_usermode;
57702 +extern unsigned char *gr_system_salt;
57703 +extern unsigned char *gr_system_sum;
57704 +
57705 +void __init
57706 +grsecurity_init(void)
57707 +{
57708 + int j;
57709 + /* create the per-cpu shared pages */
57710 +
57711 +#ifdef CONFIG_X86
57712 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57713 +#endif
57714 +
57715 + for (j = 0; j < 4; j++) {
57716 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57717 + if (gr_shared_page[j] == NULL) {
57718 + panic("Unable to allocate grsecurity shared page");
57719 + return;
57720 + }
57721 + }
57722 +
57723 + /* allocate log buffers */
57724 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57725 + if (!gr_alert_log_fmt) {
57726 + panic("Unable to allocate grsecurity alert log format buffer");
57727 + return;
57728 + }
57729 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57730 + if (!gr_audit_log_fmt) {
57731 + panic("Unable to allocate grsecurity audit log format buffer");
57732 + return;
57733 + }
57734 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57735 + if (!gr_alert_log_buf) {
57736 + panic("Unable to allocate grsecurity alert log buffer");
57737 + return;
57738 + }
57739 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57740 + if (!gr_audit_log_buf) {
57741 + panic("Unable to allocate grsecurity audit log buffer");
57742 + return;
57743 + }
57744 +
57745 + /* allocate memory for authentication structure */
57746 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57747 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57748 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57749 +
57750 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57751 + panic("Unable to allocate grsecurity authentication structure");
57752 + return;
57753 + }
57754 +
57755 +
57756 +#ifdef CONFIG_GRKERNSEC_IO
57757 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57758 + grsec_disable_privio = 1;
57759 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57760 + grsec_disable_privio = 1;
57761 +#else
57762 + grsec_disable_privio = 0;
57763 +#endif
57764 +#endif
57765 +
57766 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57767 + /* for backward compatibility, tpe_invert always defaults to on if
57768 + enabled in the kernel
57769 + */
57770 + grsec_enable_tpe_invert = 1;
57771 +#endif
57772 +
57773 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57774 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57775 + grsec_lock = 1;
57776 +#endif
57777 +
57778 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57779 + grsec_enable_audit_textrel = 1;
57780 +#endif
57781 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57782 + grsec_enable_log_rwxmaps = 1;
57783 +#endif
57784 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57785 + grsec_enable_group = 1;
57786 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57787 +#endif
57788 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57789 + grsec_enable_ptrace_readexec = 1;
57790 +#endif
57791 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57792 + grsec_enable_chdir = 1;
57793 +#endif
57794 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57795 + grsec_enable_harden_ptrace = 1;
57796 +#endif
57797 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57798 + grsec_enable_mount = 1;
57799 +#endif
57800 +#ifdef CONFIG_GRKERNSEC_LINK
57801 + grsec_enable_link = 1;
57802 +#endif
57803 +#ifdef CONFIG_GRKERNSEC_BRUTE
57804 + grsec_enable_brute = 1;
57805 +#endif
57806 +#ifdef CONFIG_GRKERNSEC_DMESG
57807 + grsec_enable_dmesg = 1;
57808 +#endif
57809 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57810 + grsec_enable_blackhole = 1;
57811 + grsec_lastack_retries = 4;
57812 +#endif
57813 +#ifdef CONFIG_GRKERNSEC_FIFO
57814 + grsec_enable_fifo = 1;
57815 +#endif
57816 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57817 + grsec_enable_execlog = 1;
57818 +#endif
57819 +#ifdef CONFIG_GRKERNSEC_SETXID
57820 + grsec_enable_setxid = 1;
57821 +#endif
57822 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57823 + grsec_enable_signal = 1;
57824 +#endif
57825 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57826 + grsec_enable_forkfail = 1;
57827 +#endif
57828 +#ifdef CONFIG_GRKERNSEC_TIME
57829 + grsec_enable_time = 1;
57830 +#endif
57831 +#ifdef CONFIG_GRKERNSEC_RESLOG
57832 + grsec_resource_logging = 1;
57833 +#endif
57834 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57835 + grsec_enable_chroot_findtask = 1;
57836 +#endif
57837 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57838 + grsec_enable_chroot_unix = 1;
57839 +#endif
57840 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57841 + grsec_enable_chroot_mount = 1;
57842 +#endif
57843 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57844 + grsec_enable_chroot_fchdir = 1;
57845 +#endif
57846 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57847 + grsec_enable_chroot_shmat = 1;
57848 +#endif
57849 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57850 + grsec_enable_audit_ptrace = 1;
57851 +#endif
57852 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57853 + grsec_enable_chroot_double = 1;
57854 +#endif
57855 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57856 + grsec_enable_chroot_pivot = 1;
57857 +#endif
57858 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57859 + grsec_enable_chroot_chdir = 1;
57860 +#endif
57861 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57862 + grsec_enable_chroot_chmod = 1;
57863 +#endif
57864 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57865 + grsec_enable_chroot_mknod = 1;
57866 +#endif
57867 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57868 + grsec_enable_chroot_nice = 1;
57869 +#endif
57870 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57871 + grsec_enable_chroot_execlog = 1;
57872 +#endif
57873 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57874 + grsec_enable_chroot_caps = 1;
57875 +#endif
57876 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57877 + grsec_enable_chroot_sysctl = 1;
57878 +#endif
57879 +#ifdef CONFIG_GRKERNSEC_TPE
57880 + grsec_enable_tpe = 1;
57881 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57882 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57883 + grsec_enable_tpe_all = 1;
57884 +#endif
57885 +#endif
57886 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57887 + grsec_enable_socket_all = 1;
57888 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57889 +#endif
57890 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57891 + grsec_enable_socket_client = 1;
57892 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57893 +#endif
57894 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57895 + grsec_enable_socket_server = 1;
57896 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57897 +#endif
57898 +#endif
57899 +
57900 + return;
57901 +}
57902 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57903 new file mode 100644
57904 index 0000000..3efe141
57905 --- /dev/null
57906 +++ b/grsecurity/grsec_link.c
57907 @@ -0,0 +1,43 @@
57908 +#include <linux/kernel.h>
57909 +#include <linux/sched.h>
57910 +#include <linux/fs.h>
57911 +#include <linux/file.h>
57912 +#include <linux/grinternal.h>
57913 +
57914 +int
57915 +gr_handle_follow_link(const struct inode *parent,
57916 + const struct inode *inode,
57917 + const struct dentry *dentry, const struct vfsmount *mnt)
57918 +{
57919 +#ifdef CONFIG_GRKERNSEC_LINK
57920 + const struct cred *cred = current_cred();
57921 +
57922 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57923 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57924 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57925 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57926 + return -EACCES;
57927 + }
57928 +#endif
57929 + return 0;
57930 +}
57931 +
57932 +int
57933 +gr_handle_hardlink(const struct dentry *dentry,
57934 + const struct vfsmount *mnt,
57935 + struct inode *inode, const int mode, const char *to)
57936 +{
57937 +#ifdef CONFIG_GRKERNSEC_LINK
57938 + const struct cred *cred = current_cred();
57939 +
57940 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57941 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57942 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57943 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57944 + !capable(CAP_FOWNER) && cred->uid) {
57945 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57946 + return -EPERM;
57947 + }
57948 +#endif
57949 + return 0;
57950 +}
57951 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57952 new file mode 100644
57953 index 0000000..a45d2e9
57954 --- /dev/null
57955 +++ b/grsecurity/grsec_log.c
57956 @@ -0,0 +1,322 @@
57957 +#include <linux/kernel.h>
57958 +#include <linux/sched.h>
57959 +#include <linux/file.h>
57960 +#include <linux/tty.h>
57961 +#include <linux/fs.h>
57962 +#include <linux/grinternal.h>
57963 +
57964 +#ifdef CONFIG_TREE_PREEMPT_RCU
57965 +#define DISABLE_PREEMPT() preempt_disable()
57966 +#define ENABLE_PREEMPT() preempt_enable()
57967 +#else
57968 +#define DISABLE_PREEMPT()
57969 +#define ENABLE_PREEMPT()
57970 +#endif
57971 +
57972 +#define BEGIN_LOCKS(x) \
57973 + DISABLE_PREEMPT(); \
57974 + rcu_read_lock(); \
57975 + read_lock(&tasklist_lock); \
57976 + read_lock(&grsec_exec_file_lock); \
57977 + if (x != GR_DO_AUDIT) \
57978 + spin_lock(&grsec_alert_lock); \
57979 + else \
57980 + spin_lock(&grsec_audit_lock)
57981 +
57982 +#define END_LOCKS(x) \
57983 + if (x != GR_DO_AUDIT) \
57984 + spin_unlock(&grsec_alert_lock); \
57985 + else \
57986 + spin_unlock(&grsec_audit_lock); \
57987 + read_unlock(&grsec_exec_file_lock); \
57988 + read_unlock(&tasklist_lock); \
57989 + rcu_read_unlock(); \
57990 + ENABLE_PREEMPT(); \
57991 + if (x == GR_DONT_AUDIT) \
57992 + gr_handle_alertkill(current)
57993 +
57994 +enum {
57995 + FLOODING,
57996 + NO_FLOODING
57997 +};
57998 +
57999 +extern char *gr_alert_log_fmt;
58000 +extern char *gr_audit_log_fmt;
58001 +extern char *gr_alert_log_buf;
58002 +extern char *gr_audit_log_buf;
58003 +
58004 +static int gr_log_start(int audit)
58005 +{
58006 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58007 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58008 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58009 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58010 + unsigned long curr_secs = get_seconds();
58011 +
58012 + if (audit == GR_DO_AUDIT)
58013 + goto set_fmt;
58014 +
58015 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58016 + grsec_alert_wtime = curr_secs;
58017 + grsec_alert_fyet = 0;
58018 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58019 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58020 + grsec_alert_fyet++;
58021 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58022 + grsec_alert_wtime = curr_secs;
58023 + grsec_alert_fyet++;
58024 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58025 + return FLOODING;
58026 + }
58027 + else return FLOODING;
58028 +
58029 +set_fmt:
58030 +#endif
58031 + memset(buf, 0, PAGE_SIZE);
58032 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58033 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58034 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58035 + } else if (current->signal->curr_ip) {
58036 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58037 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58038 + } else if (gr_acl_is_enabled()) {
58039 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58040 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58041 + } else {
58042 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58043 + strcpy(buf, fmt);
58044 + }
58045 +
58046 + return NO_FLOODING;
58047 +}
58048 +
58049 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58050 + __attribute__ ((format (printf, 2, 0)));
58051 +
58052 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58053 +{
58054 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58055 + unsigned int len = strlen(buf);
58056 +
58057 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58058 +
58059 + return;
58060 +}
58061 +
58062 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58063 + __attribute__ ((format (printf, 2, 3)));
58064 +
58065 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58066 +{
58067 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58068 + unsigned int len = strlen(buf);
58069 + va_list ap;
58070 +
58071 + va_start(ap, msg);
58072 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58073 + va_end(ap);
58074 +
58075 + return;
58076 +}
58077 +
58078 +static void gr_log_end(int audit, int append_default)
58079 +{
58080 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58081 +
58082 + if (append_default) {
58083 + unsigned int len = strlen(buf);
58084 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58085 + }
58086 +
58087 + printk("%s\n", buf);
58088 +
58089 + return;
58090 +}
58091 +
58092 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58093 +{
58094 + int logtype;
58095 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58096 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58097 + void *voidptr = NULL;
58098 + int num1 = 0, num2 = 0;
58099 + unsigned long ulong1 = 0, ulong2 = 0;
58100 + struct dentry *dentry = NULL;
58101 + struct vfsmount *mnt = NULL;
58102 + struct file *file = NULL;
58103 + struct task_struct *task = NULL;
58104 + const struct cred *cred, *pcred;
58105 + va_list ap;
58106 +
58107 + BEGIN_LOCKS(audit);
58108 + logtype = gr_log_start(audit);
58109 + if (logtype == FLOODING) {
58110 + END_LOCKS(audit);
58111 + return;
58112 + }
58113 + va_start(ap, argtypes);
58114 + switch (argtypes) {
58115 + case GR_TTYSNIFF:
58116 + task = va_arg(ap, struct task_struct *);
58117 + 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);
58118 + break;
58119 + case GR_SYSCTL_HIDDEN:
58120 + str1 = va_arg(ap, char *);
58121 + gr_log_middle_varargs(audit, msg, result, str1);
58122 + break;
58123 + case GR_RBAC:
58124 + dentry = va_arg(ap, struct dentry *);
58125 + mnt = va_arg(ap, struct vfsmount *);
58126 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58127 + break;
58128 + case GR_RBAC_STR:
58129 + dentry = va_arg(ap, struct dentry *);
58130 + mnt = va_arg(ap, struct vfsmount *);
58131 + str1 = va_arg(ap, char *);
58132 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58133 + break;
58134 + case GR_STR_RBAC:
58135 + str1 = va_arg(ap, char *);
58136 + dentry = va_arg(ap, struct dentry *);
58137 + mnt = va_arg(ap, struct vfsmount *);
58138 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58139 + break;
58140 + case GR_RBAC_MODE2:
58141 + dentry = va_arg(ap, struct dentry *);
58142 + mnt = va_arg(ap, struct vfsmount *);
58143 + str1 = va_arg(ap, char *);
58144 + str2 = va_arg(ap, char *);
58145 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58146 + break;
58147 + case GR_RBAC_MODE3:
58148 + dentry = va_arg(ap, struct dentry *);
58149 + mnt = va_arg(ap, struct vfsmount *);
58150 + str1 = va_arg(ap, char *);
58151 + str2 = va_arg(ap, char *);
58152 + str3 = va_arg(ap, char *);
58153 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58154 + break;
58155 + case GR_FILENAME:
58156 + dentry = va_arg(ap, struct dentry *);
58157 + mnt = va_arg(ap, struct vfsmount *);
58158 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58159 + break;
58160 + case GR_STR_FILENAME:
58161 + str1 = va_arg(ap, char *);
58162 + dentry = va_arg(ap, struct dentry *);
58163 + mnt = va_arg(ap, struct vfsmount *);
58164 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58165 + break;
58166 + case GR_FILENAME_STR:
58167 + dentry = va_arg(ap, struct dentry *);
58168 + mnt = va_arg(ap, struct vfsmount *);
58169 + str1 = va_arg(ap, char *);
58170 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58171 + break;
58172 + case GR_FILENAME_TWO_INT:
58173 + dentry = va_arg(ap, struct dentry *);
58174 + mnt = va_arg(ap, struct vfsmount *);
58175 + num1 = va_arg(ap, int);
58176 + num2 = va_arg(ap, int);
58177 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58178 + break;
58179 + case GR_FILENAME_TWO_INT_STR:
58180 + dentry = va_arg(ap, struct dentry *);
58181 + mnt = va_arg(ap, struct vfsmount *);
58182 + num1 = va_arg(ap, int);
58183 + num2 = va_arg(ap, int);
58184 + str1 = va_arg(ap, char *);
58185 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58186 + break;
58187 + case GR_TEXTREL:
58188 + file = va_arg(ap, struct file *);
58189 + ulong1 = va_arg(ap, unsigned long);
58190 + ulong2 = va_arg(ap, unsigned long);
58191 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58192 + break;
58193 + case GR_PTRACE:
58194 + task = va_arg(ap, struct task_struct *);
58195 + 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);
58196 + break;
58197 + case GR_RESOURCE:
58198 + task = va_arg(ap, struct task_struct *);
58199 + cred = __task_cred(task);
58200 + pcred = __task_cred(task->real_parent);
58201 + ulong1 = va_arg(ap, unsigned long);
58202 + str1 = va_arg(ap, char *);
58203 + ulong2 = va_arg(ap, unsigned long);
58204 + 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);
58205 + break;
58206 + case GR_CAP:
58207 + task = va_arg(ap, struct task_struct *);
58208 + cred = __task_cred(task);
58209 + pcred = __task_cred(task->real_parent);
58210 + str1 = va_arg(ap, char *);
58211 + 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);
58212 + break;
58213 + case GR_SIG:
58214 + str1 = va_arg(ap, char *);
58215 + voidptr = va_arg(ap, void *);
58216 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58217 + break;
58218 + case GR_SIG2:
58219 + task = va_arg(ap, struct task_struct *);
58220 + cred = __task_cred(task);
58221 + pcred = __task_cred(task->real_parent);
58222 + num1 = va_arg(ap, int);
58223 + 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);
58224 + break;
58225 + case GR_CRASH1:
58226 + task = va_arg(ap, struct task_struct *);
58227 + cred = __task_cred(task);
58228 + pcred = __task_cred(task->real_parent);
58229 + ulong1 = va_arg(ap, unsigned long);
58230 + 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);
58231 + break;
58232 + case GR_CRASH2:
58233 + task = va_arg(ap, struct task_struct *);
58234 + cred = __task_cred(task);
58235 + pcred = __task_cred(task->real_parent);
58236 + ulong1 = va_arg(ap, unsigned long);
58237 + 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);
58238 + break;
58239 + case GR_RWXMAP:
58240 + file = va_arg(ap, struct file *);
58241 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58242 + break;
58243 + case GR_PSACCT:
58244 + {
58245 + unsigned int wday, cday;
58246 + __u8 whr, chr;
58247 + __u8 wmin, cmin;
58248 + __u8 wsec, csec;
58249 + char cur_tty[64] = { 0 };
58250 + char parent_tty[64] = { 0 };
58251 +
58252 + task = va_arg(ap, struct task_struct *);
58253 + wday = va_arg(ap, unsigned int);
58254 + cday = va_arg(ap, unsigned int);
58255 + whr = va_arg(ap, int);
58256 + chr = va_arg(ap, int);
58257 + wmin = va_arg(ap, int);
58258 + cmin = va_arg(ap, int);
58259 + wsec = va_arg(ap, int);
58260 + csec = va_arg(ap, int);
58261 + ulong1 = va_arg(ap, unsigned long);
58262 + cred = __task_cred(task);
58263 + pcred = __task_cred(task->real_parent);
58264 +
58265 + 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);
58266 + }
58267 + break;
58268 + default:
58269 + gr_log_middle(audit, msg, ap);
58270 + }
58271 + va_end(ap);
58272 + // these don't need DEFAULTSECARGS printed on the end
58273 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58274 + gr_log_end(audit, 0);
58275 + else
58276 + gr_log_end(audit, 1);
58277 + END_LOCKS(audit);
58278 +}
58279 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58280 new file mode 100644
58281 index 0000000..f536303
58282 --- /dev/null
58283 +++ b/grsecurity/grsec_mem.c
58284 @@ -0,0 +1,40 @@
58285 +#include <linux/kernel.h>
58286 +#include <linux/sched.h>
58287 +#include <linux/mm.h>
58288 +#include <linux/mman.h>
58289 +#include <linux/grinternal.h>
58290 +
58291 +void
58292 +gr_handle_ioperm(void)
58293 +{
58294 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58295 + return;
58296 +}
58297 +
58298 +void
58299 +gr_handle_iopl(void)
58300 +{
58301 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58302 + return;
58303 +}
58304 +
58305 +void
58306 +gr_handle_mem_readwrite(u64 from, u64 to)
58307 +{
58308 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58309 + return;
58310 +}
58311 +
58312 +void
58313 +gr_handle_vm86(void)
58314 +{
58315 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58316 + return;
58317 +}
58318 +
58319 +void
58320 +gr_log_badprocpid(const char *entry)
58321 +{
58322 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58323 + return;
58324 +}
58325 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58326 new file mode 100644
58327 index 0000000..2131422
58328 --- /dev/null
58329 +++ b/grsecurity/grsec_mount.c
58330 @@ -0,0 +1,62 @@
58331 +#include <linux/kernel.h>
58332 +#include <linux/sched.h>
58333 +#include <linux/mount.h>
58334 +#include <linux/grsecurity.h>
58335 +#include <linux/grinternal.h>
58336 +
58337 +void
58338 +gr_log_remount(const char *devname, const int retval)
58339 +{
58340 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58341 + if (grsec_enable_mount && (retval >= 0))
58342 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58343 +#endif
58344 + return;
58345 +}
58346 +
58347 +void
58348 +gr_log_unmount(const char *devname, const int retval)
58349 +{
58350 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58351 + if (grsec_enable_mount && (retval >= 0))
58352 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58353 +#endif
58354 + return;
58355 +}
58356 +
58357 +void
58358 +gr_log_mount(const char *from, const char *to, const int retval)
58359 +{
58360 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58361 + if (grsec_enable_mount && (retval >= 0))
58362 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58363 +#endif
58364 + return;
58365 +}
58366 +
58367 +int
58368 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58369 +{
58370 +#ifdef CONFIG_GRKERNSEC_ROFS
58371 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58372 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58373 + return -EPERM;
58374 + } else
58375 + return 0;
58376 +#endif
58377 + return 0;
58378 +}
58379 +
58380 +int
58381 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58382 +{
58383 +#ifdef CONFIG_GRKERNSEC_ROFS
58384 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58385 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58386 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58387 + return -EPERM;
58388 + } else
58389 + return 0;
58390 +#endif
58391 + return 0;
58392 +}
58393 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58394 new file mode 100644
58395 index 0000000..a3b12a0
58396 --- /dev/null
58397 +++ b/grsecurity/grsec_pax.c
58398 @@ -0,0 +1,36 @@
58399 +#include <linux/kernel.h>
58400 +#include <linux/sched.h>
58401 +#include <linux/mm.h>
58402 +#include <linux/file.h>
58403 +#include <linux/grinternal.h>
58404 +#include <linux/grsecurity.h>
58405 +
58406 +void
58407 +gr_log_textrel(struct vm_area_struct * vma)
58408 +{
58409 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58410 + if (grsec_enable_audit_textrel)
58411 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58412 +#endif
58413 + return;
58414 +}
58415 +
58416 +void
58417 +gr_log_rwxmmap(struct file *file)
58418 +{
58419 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58420 + if (grsec_enable_log_rwxmaps)
58421 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58422 +#endif
58423 + return;
58424 +}
58425 +
58426 +void
58427 +gr_log_rwxmprotect(struct file *file)
58428 +{
58429 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58430 + if (grsec_enable_log_rwxmaps)
58431 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58432 +#endif
58433 + return;
58434 +}
58435 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58436 new file mode 100644
58437 index 0000000..f7f29aa
58438 --- /dev/null
58439 +++ b/grsecurity/grsec_ptrace.c
58440 @@ -0,0 +1,30 @@
58441 +#include <linux/kernel.h>
58442 +#include <linux/sched.h>
58443 +#include <linux/grinternal.h>
58444 +#include <linux/security.h>
58445 +
58446 +void
58447 +gr_audit_ptrace(struct task_struct *task)
58448 +{
58449 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58450 + if (grsec_enable_audit_ptrace)
58451 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58452 +#endif
58453 + return;
58454 +}
58455 +
58456 +int
58457 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58458 +{
58459 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58460 + const struct dentry *dentry = file->f_path.dentry;
58461 + const struct vfsmount *mnt = file->f_path.mnt;
58462 +
58463 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58464 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58465 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58466 + return -EACCES;
58467 + }
58468 +#endif
58469 + return 0;
58470 +}
58471 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58472 new file mode 100644
58473 index 0000000..7a5b2de
58474 --- /dev/null
58475 +++ b/grsecurity/grsec_sig.c
58476 @@ -0,0 +1,207 @@
58477 +#include <linux/kernel.h>
58478 +#include <linux/sched.h>
58479 +#include <linux/delay.h>
58480 +#include <linux/grsecurity.h>
58481 +#include <linux/grinternal.h>
58482 +#include <linux/hardirq.h>
58483 +
58484 +char *signames[] = {
58485 + [SIGSEGV] = "Segmentation fault",
58486 + [SIGILL] = "Illegal instruction",
58487 + [SIGABRT] = "Abort",
58488 + [SIGBUS] = "Invalid alignment/Bus error"
58489 +};
58490 +
58491 +void
58492 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58493 +{
58494 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58495 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58496 + (sig == SIGABRT) || (sig == SIGBUS))) {
58497 + if (t->pid == current->pid) {
58498 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58499 + } else {
58500 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58501 + }
58502 + }
58503 +#endif
58504 + return;
58505 +}
58506 +
58507 +int
58508 +gr_handle_signal(const struct task_struct *p, const int sig)
58509 +{
58510 +#ifdef CONFIG_GRKERNSEC
58511 + /* ignore the 0 signal for protected task checks */
58512 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58513 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58514 + return -EPERM;
58515 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58516 + return -EPERM;
58517 + }
58518 +#endif
58519 + return 0;
58520 +}
58521 +
58522 +#ifdef CONFIG_GRKERNSEC
58523 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58524 +
58525 +int gr_fake_force_sig(int sig, struct task_struct *t)
58526 +{
58527 + unsigned long int flags;
58528 + int ret, blocked, ignored;
58529 + struct k_sigaction *action;
58530 +
58531 + spin_lock_irqsave(&t->sighand->siglock, flags);
58532 + action = &t->sighand->action[sig-1];
58533 + ignored = action->sa.sa_handler == SIG_IGN;
58534 + blocked = sigismember(&t->blocked, sig);
58535 + if (blocked || ignored) {
58536 + action->sa.sa_handler = SIG_DFL;
58537 + if (blocked) {
58538 + sigdelset(&t->blocked, sig);
58539 + recalc_sigpending_and_wake(t);
58540 + }
58541 + }
58542 + if (action->sa.sa_handler == SIG_DFL)
58543 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58544 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58545 +
58546 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58547 +
58548 + return ret;
58549 +}
58550 +#endif
58551 +
58552 +#ifdef CONFIG_GRKERNSEC_BRUTE
58553 +#define GR_USER_BAN_TIME (15 * 60)
58554 +
58555 +static int __get_dumpable(unsigned long mm_flags)
58556 +{
58557 + int ret;
58558 +
58559 + ret = mm_flags & MMF_DUMPABLE_MASK;
58560 + return (ret >= 2) ? 2 : ret;
58561 +}
58562 +#endif
58563 +
58564 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58565 +{
58566 +#ifdef CONFIG_GRKERNSEC_BRUTE
58567 + uid_t uid = 0;
58568 +
58569 + if (!grsec_enable_brute)
58570 + return;
58571 +
58572 + rcu_read_lock();
58573 + read_lock(&tasklist_lock);
58574 + read_lock(&grsec_exec_file_lock);
58575 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58576 + p->real_parent->brute = 1;
58577 + else {
58578 + const struct cred *cred = __task_cred(p), *cred2;
58579 + struct task_struct *tsk, *tsk2;
58580 +
58581 + if (!__get_dumpable(mm_flags) && cred->uid) {
58582 + struct user_struct *user;
58583 +
58584 + uid = cred->uid;
58585 +
58586 + /* this is put upon execution past expiration */
58587 + user = find_user(uid);
58588 + if (user == NULL)
58589 + goto unlock;
58590 + user->banned = 1;
58591 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58592 + if (user->ban_expires == ~0UL)
58593 + user->ban_expires--;
58594 +
58595 + do_each_thread(tsk2, tsk) {
58596 + cred2 = __task_cred(tsk);
58597 + if (tsk != p && cred2->uid == uid)
58598 + gr_fake_force_sig(SIGKILL, tsk);
58599 + } while_each_thread(tsk2, tsk);
58600 + }
58601 + }
58602 +unlock:
58603 + read_unlock(&grsec_exec_file_lock);
58604 + read_unlock(&tasklist_lock);
58605 + rcu_read_unlock();
58606 +
58607 + if (uid)
58608 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58609 +
58610 +#endif
58611 + return;
58612 +}
58613 +
58614 +void gr_handle_brute_check(void)
58615 +{
58616 +#ifdef CONFIG_GRKERNSEC_BRUTE
58617 + if (current->brute)
58618 + msleep(30 * 1000);
58619 +#endif
58620 + return;
58621 +}
58622 +
58623 +void gr_handle_kernel_exploit(void)
58624 +{
58625 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58626 + const struct cred *cred;
58627 + struct task_struct *tsk, *tsk2;
58628 + struct user_struct *user;
58629 + uid_t uid;
58630 +
58631 + if (in_irq() || in_serving_softirq() || in_nmi())
58632 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58633 +
58634 + uid = current_uid();
58635 +
58636 + if (uid == 0)
58637 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58638 + else {
58639 + /* kill all the processes of this user, hold a reference
58640 + to their creds struct, and prevent them from creating
58641 + another process until system reset
58642 + */
58643 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58644 + /* we intentionally leak this ref */
58645 + user = get_uid(current->cred->user);
58646 + if (user) {
58647 + user->banned = 1;
58648 + user->ban_expires = ~0UL;
58649 + }
58650 +
58651 + read_lock(&tasklist_lock);
58652 + do_each_thread(tsk2, tsk) {
58653 + cred = __task_cred(tsk);
58654 + if (cred->uid == uid)
58655 + gr_fake_force_sig(SIGKILL, tsk);
58656 + } while_each_thread(tsk2, tsk);
58657 + read_unlock(&tasklist_lock);
58658 + }
58659 +#endif
58660 +}
58661 +
58662 +int __gr_process_user_ban(struct user_struct *user)
58663 +{
58664 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58665 + if (unlikely(user->banned)) {
58666 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58667 + user->banned = 0;
58668 + user->ban_expires = 0;
58669 + free_uid(user);
58670 + } else
58671 + return -EPERM;
58672 + }
58673 +#endif
58674 + return 0;
58675 +}
58676 +
58677 +int gr_process_user_ban(void)
58678 +{
58679 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58680 + return __gr_process_user_ban(current->cred->user);
58681 +#endif
58682 + return 0;
58683 +}
58684 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58685 new file mode 100644
58686 index 0000000..4030d57
58687 --- /dev/null
58688 +++ b/grsecurity/grsec_sock.c
58689 @@ -0,0 +1,244 @@
58690 +#include <linux/kernel.h>
58691 +#include <linux/module.h>
58692 +#include <linux/sched.h>
58693 +#include <linux/file.h>
58694 +#include <linux/net.h>
58695 +#include <linux/in.h>
58696 +#include <linux/ip.h>
58697 +#include <net/sock.h>
58698 +#include <net/inet_sock.h>
58699 +#include <linux/grsecurity.h>
58700 +#include <linux/grinternal.h>
58701 +#include <linux/gracl.h>
58702 +
58703 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58704 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58705 +
58706 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58707 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58708 +
58709 +#ifdef CONFIG_UNIX_MODULE
58710 +EXPORT_SYMBOL(gr_acl_handle_unix);
58711 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58712 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58713 +EXPORT_SYMBOL(gr_handle_create);
58714 +#endif
58715 +
58716 +#ifdef CONFIG_GRKERNSEC
58717 +#define gr_conn_table_size 32749
58718 +struct conn_table_entry {
58719 + struct conn_table_entry *next;
58720 + struct signal_struct *sig;
58721 +};
58722 +
58723 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58724 +DEFINE_SPINLOCK(gr_conn_table_lock);
58725 +
58726 +extern const char * gr_socktype_to_name(unsigned char type);
58727 +extern const char * gr_proto_to_name(unsigned char proto);
58728 +extern const char * gr_sockfamily_to_name(unsigned char family);
58729 +
58730 +static __inline__ int
58731 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58732 +{
58733 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58734 +}
58735 +
58736 +static __inline__ int
58737 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58738 + __u16 sport, __u16 dport)
58739 +{
58740 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58741 + sig->gr_sport == sport && sig->gr_dport == dport))
58742 + return 1;
58743 + else
58744 + return 0;
58745 +}
58746 +
58747 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58748 +{
58749 + struct conn_table_entry **match;
58750 + unsigned int index;
58751 +
58752 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58753 + sig->gr_sport, sig->gr_dport,
58754 + gr_conn_table_size);
58755 +
58756 + newent->sig = sig;
58757 +
58758 + match = &gr_conn_table[index];
58759 + newent->next = *match;
58760 + *match = newent;
58761 +
58762 + return;
58763 +}
58764 +
58765 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58766 +{
58767 + struct conn_table_entry *match, *last = NULL;
58768 + unsigned int index;
58769 +
58770 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58771 + sig->gr_sport, sig->gr_dport,
58772 + gr_conn_table_size);
58773 +
58774 + match = gr_conn_table[index];
58775 + while (match && !conn_match(match->sig,
58776 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58777 + sig->gr_dport)) {
58778 + last = match;
58779 + match = match->next;
58780 + }
58781 +
58782 + if (match) {
58783 + if (last)
58784 + last->next = match->next;
58785 + else
58786 + gr_conn_table[index] = NULL;
58787 + kfree(match);
58788 + }
58789 +
58790 + return;
58791 +}
58792 +
58793 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58794 + __u16 sport, __u16 dport)
58795 +{
58796 + struct conn_table_entry *match;
58797 + unsigned int index;
58798 +
58799 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58800 +
58801 + match = gr_conn_table[index];
58802 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58803 + match = match->next;
58804 +
58805 + if (match)
58806 + return match->sig;
58807 + else
58808 + return NULL;
58809 +}
58810 +
58811 +#endif
58812 +
58813 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58814 +{
58815 +#ifdef CONFIG_GRKERNSEC
58816 + struct signal_struct *sig = task->signal;
58817 + struct conn_table_entry *newent;
58818 +
58819 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58820 + if (newent == NULL)
58821 + return;
58822 + /* no bh lock needed since we are called with bh disabled */
58823 + spin_lock(&gr_conn_table_lock);
58824 + gr_del_task_from_ip_table_nolock(sig);
58825 + sig->gr_saddr = inet->inet_rcv_saddr;
58826 + sig->gr_daddr = inet->inet_daddr;
58827 + sig->gr_sport = inet->inet_sport;
58828 + sig->gr_dport = inet->inet_dport;
58829 + gr_add_to_task_ip_table_nolock(sig, newent);
58830 + spin_unlock(&gr_conn_table_lock);
58831 +#endif
58832 + return;
58833 +}
58834 +
58835 +void gr_del_task_from_ip_table(struct task_struct *task)
58836 +{
58837 +#ifdef CONFIG_GRKERNSEC
58838 + spin_lock_bh(&gr_conn_table_lock);
58839 + gr_del_task_from_ip_table_nolock(task->signal);
58840 + spin_unlock_bh(&gr_conn_table_lock);
58841 +#endif
58842 + return;
58843 +}
58844 +
58845 +void
58846 +gr_attach_curr_ip(const struct sock *sk)
58847 +{
58848 +#ifdef CONFIG_GRKERNSEC
58849 + struct signal_struct *p, *set;
58850 + const struct inet_sock *inet = inet_sk(sk);
58851 +
58852 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58853 + return;
58854 +
58855 + set = current->signal;
58856 +
58857 + spin_lock_bh(&gr_conn_table_lock);
58858 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58859 + inet->inet_dport, inet->inet_sport);
58860 + if (unlikely(p != NULL)) {
58861 + set->curr_ip = p->curr_ip;
58862 + set->used_accept = 1;
58863 + gr_del_task_from_ip_table_nolock(p);
58864 + spin_unlock_bh(&gr_conn_table_lock);
58865 + return;
58866 + }
58867 + spin_unlock_bh(&gr_conn_table_lock);
58868 +
58869 + set->curr_ip = inet->inet_daddr;
58870 + set->used_accept = 1;
58871 +#endif
58872 + return;
58873 +}
58874 +
58875 +int
58876 +gr_handle_sock_all(const int family, const int type, const int protocol)
58877 +{
58878 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58879 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58880 + (family != AF_UNIX)) {
58881 + if (family == AF_INET)
58882 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58883 + else
58884 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58885 + return -EACCES;
58886 + }
58887 +#endif
58888 + return 0;
58889 +}
58890 +
58891 +int
58892 +gr_handle_sock_server(const struct sockaddr *sck)
58893 +{
58894 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58895 + if (grsec_enable_socket_server &&
58896 + in_group_p(grsec_socket_server_gid) &&
58897 + sck && (sck->sa_family != AF_UNIX) &&
58898 + (sck->sa_family != AF_LOCAL)) {
58899 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58900 + return -EACCES;
58901 + }
58902 +#endif
58903 + return 0;
58904 +}
58905 +
58906 +int
58907 +gr_handle_sock_server_other(const struct sock *sck)
58908 +{
58909 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58910 + if (grsec_enable_socket_server &&
58911 + in_group_p(grsec_socket_server_gid) &&
58912 + sck && (sck->sk_family != AF_UNIX) &&
58913 + (sck->sk_family != AF_LOCAL)) {
58914 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58915 + return -EACCES;
58916 + }
58917 +#endif
58918 + return 0;
58919 +}
58920 +
58921 +int
58922 +gr_handle_sock_client(const struct sockaddr *sck)
58923 +{
58924 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58925 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58926 + sck && (sck->sa_family != AF_UNIX) &&
58927 + (sck->sa_family != AF_LOCAL)) {
58928 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58929 + return -EACCES;
58930 + }
58931 +#endif
58932 + return 0;
58933 +}
58934 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58935 new file mode 100644
58936 index 0000000..a1aedd7
58937 --- /dev/null
58938 +++ b/grsecurity/grsec_sysctl.c
58939 @@ -0,0 +1,451 @@
58940 +#include <linux/kernel.h>
58941 +#include <linux/sched.h>
58942 +#include <linux/sysctl.h>
58943 +#include <linux/grsecurity.h>
58944 +#include <linux/grinternal.h>
58945 +
58946 +int
58947 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58948 +{
58949 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58950 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58951 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58952 + return -EACCES;
58953 + }
58954 +#endif
58955 + return 0;
58956 +}
58957 +
58958 +#ifdef CONFIG_GRKERNSEC_ROFS
58959 +static int __maybe_unused one = 1;
58960 +#endif
58961 +
58962 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58963 +struct ctl_table grsecurity_table[] = {
58964 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58965 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58966 +#ifdef CONFIG_GRKERNSEC_IO
58967 + {
58968 + .procname = "disable_priv_io",
58969 + .data = &grsec_disable_privio,
58970 + .maxlen = sizeof(int),
58971 + .mode = 0600,
58972 + .proc_handler = &proc_dointvec,
58973 + },
58974 +#endif
58975 +#endif
58976 +#ifdef CONFIG_GRKERNSEC_LINK
58977 + {
58978 + .procname = "linking_restrictions",
58979 + .data = &grsec_enable_link,
58980 + .maxlen = sizeof(int),
58981 + .mode = 0600,
58982 + .proc_handler = &proc_dointvec,
58983 + },
58984 +#endif
58985 +#ifdef CONFIG_GRKERNSEC_BRUTE
58986 + {
58987 + .procname = "deter_bruteforce",
58988 + .data = &grsec_enable_brute,
58989 + .maxlen = sizeof(int),
58990 + .mode = 0600,
58991 + .proc_handler = &proc_dointvec,
58992 + },
58993 +#endif
58994 +#ifdef CONFIG_GRKERNSEC_FIFO
58995 + {
58996 + .procname = "fifo_restrictions",
58997 + .data = &grsec_enable_fifo,
58998 + .maxlen = sizeof(int),
58999 + .mode = 0600,
59000 + .proc_handler = &proc_dointvec,
59001 + },
59002 +#endif
59003 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59004 + {
59005 + .procname = "ptrace_readexec",
59006 + .data = &grsec_enable_ptrace_readexec,
59007 + .maxlen = sizeof(int),
59008 + .mode = 0600,
59009 + .proc_handler = &proc_dointvec,
59010 + },
59011 +#endif
59012 +#ifdef CONFIG_GRKERNSEC_SETXID
59013 + {
59014 + .procname = "consistent_setxid",
59015 + .data = &grsec_enable_setxid,
59016 + .maxlen = sizeof(int),
59017 + .mode = 0600,
59018 + .proc_handler = &proc_dointvec,
59019 + },
59020 +#endif
59021 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59022 + {
59023 + .procname = "ip_blackhole",
59024 + .data = &grsec_enable_blackhole,
59025 + .maxlen = sizeof(int),
59026 + .mode = 0600,
59027 + .proc_handler = &proc_dointvec,
59028 + },
59029 + {
59030 + .procname = "lastack_retries",
59031 + .data = &grsec_lastack_retries,
59032 + .maxlen = sizeof(int),
59033 + .mode = 0600,
59034 + .proc_handler = &proc_dointvec,
59035 + },
59036 +#endif
59037 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59038 + {
59039 + .procname = "exec_logging",
59040 + .data = &grsec_enable_execlog,
59041 + .maxlen = sizeof(int),
59042 + .mode = 0600,
59043 + .proc_handler = &proc_dointvec,
59044 + },
59045 +#endif
59046 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59047 + {
59048 + .procname = "rwxmap_logging",
59049 + .data = &grsec_enable_log_rwxmaps,
59050 + .maxlen = sizeof(int),
59051 + .mode = 0600,
59052 + .proc_handler = &proc_dointvec,
59053 + },
59054 +#endif
59055 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59056 + {
59057 + .procname = "signal_logging",
59058 + .data = &grsec_enable_signal,
59059 + .maxlen = sizeof(int),
59060 + .mode = 0600,
59061 + .proc_handler = &proc_dointvec,
59062 + },
59063 +#endif
59064 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59065 + {
59066 + .procname = "forkfail_logging",
59067 + .data = &grsec_enable_forkfail,
59068 + .maxlen = sizeof(int),
59069 + .mode = 0600,
59070 + .proc_handler = &proc_dointvec,
59071 + },
59072 +#endif
59073 +#ifdef CONFIG_GRKERNSEC_TIME
59074 + {
59075 + .procname = "timechange_logging",
59076 + .data = &grsec_enable_time,
59077 + .maxlen = sizeof(int),
59078 + .mode = 0600,
59079 + .proc_handler = &proc_dointvec,
59080 + },
59081 +#endif
59082 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59083 + {
59084 + .procname = "chroot_deny_shmat",
59085 + .data = &grsec_enable_chroot_shmat,
59086 + .maxlen = sizeof(int),
59087 + .mode = 0600,
59088 + .proc_handler = &proc_dointvec,
59089 + },
59090 +#endif
59091 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59092 + {
59093 + .procname = "chroot_deny_unix",
59094 + .data = &grsec_enable_chroot_unix,
59095 + .maxlen = sizeof(int),
59096 + .mode = 0600,
59097 + .proc_handler = &proc_dointvec,
59098 + },
59099 +#endif
59100 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59101 + {
59102 + .procname = "chroot_deny_mount",
59103 + .data = &grsec_enable_chroot_mount,
59104 + .maxlen = sizeof(int),
59105 + .mode = 0600,
59106 + .proc_handler = &proc_dointvec,
59107 + },
59108 +#endif
59109 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59110 + {
59111 + .procname = "chroot_deny_fchdir",
59112 + .data = &grsec_enable_chroot_fchdir,
59113 + .maxlen = sizeof(int),
59114 + .mode = 0600,
59115 + .proc_handler = &proc_dointvec,
59116 + },
59117 +#endif
59118 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59119 + {
59120 + .procname = "chroot_deny_chroot",
59121 + .data = &grsec_enable_chroot_double,
59122 + .maxlen = sizeof(int),
59123 + .mode = 0600,
59124 + .proc_handler = &proc_dointvec,
59125 + },
59126 +#endif
59127 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59128 + {
59129 + .procname = "chroot_deny_pivot",
59130 + .data = &grsec_enable_chroot_pivot,
59131 + .maxlen = sizeof(int),
59132 + .mode = 0600,
59133 + .proc_handler = &proc_dointvec,
59134 + },
59135 +#endif
59136 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59137 + {
59138 + .procname = "chroot_enforce_chdir",
59139 + .data = &grsec_enable_chroot_chdir,
59140 + .maxlen = sizeof(int),
59141 + .mode = 0600,
59142 + .proc_handler = &proc_dointvec,
59143 + },
59144 +#endif
59145 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59146 + {
59147 + .procname = "chroot_deny_chmod",
59148 + .data = &grsec_enable_chroot_chmod,
59149 + .maxlen = sizeof(int),
59150 + .mode = 0600,
59151 + .proc_handler = &proc_dointvec,
59152 + },
59153 +#endif
59154 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59155 + {
59156 + .procname = "chroot_deny_mknod",
59157 + .data = &grsec_enable_chroot_mknod,
59158 + .maxlen = sizeof(int),
59159 + .mode = 0600,
59160 + .proc_handler = &proc_dointvec,
59161 + },
59162 +#endif
59163 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59164 + {
59165 + .procname = "chroot_restrict_nice",
59166 + .data = &grsec_enable_chroot_nice,
59167 + .maxlen = sizeof(int),
59168 + .mode = 0600,
59169 + .proc_handler = &proc_dointvec,
59170 + },
59171 +#endif
59172 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59173 + {
59174 + .procname = "chroot_execlog",
59175 + .data = &grsec_enable_chroot_execlog,
59176 + .maxlen = sizeof(int),
59177 + .mode = 0600,
59178 + .proc_handler = &proc_dointvec,
59179 + },
59180 +#endif
59181 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59182 + {
59183 + .procname = "chroot_caps",
59184 + .data = &grsec_enable_chroot_caps,
59185 + .maxlen = sizeof(int),
59186 + .mode = 0600,
59187 + .proc_handler = &proc_dointvec,
59188 + },
59189 +#endif
59190 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59191 + {
59192 + .procname = "chroot_deny_sysctl",
59193 + .data = &grsec_enable_chroot_sysctl,
59194 + .maxlen = sizeof(int),
59195 + .mode = 0600,
59196 + .proc_handler = &proc_dointvec,
59197 + },
59198 +#endif
59199 +#ifdef CONFIG_GRKERNSEC_TPE
59200 + {
59201 + .procname = "tpe",
59202 + .data = &grsec_enable_tpe,
59203 + .maxlen = sizeof(int),
59204 + .mode = 0600,
59205 + .proc_handler = &proc_dointvec,
59206 + },
59207 + {
59208 + .procname = "tpe_gid",
59209 + .data = &grsec_tpe_gid,
59210 + .maxlen = sizeof(int),
59211 + .mode = 0600,
59212 + .proc_handler = &proc_dointvec,
59213 + },
59214 +#endif
59215 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59216 + {
59217 + .procname = "tpe_invert",
59218 + .data = &grsec_enable_tpe_invert,
59219 + .maxlen = sizeof(int),
59220 + .mode = 0600,
59221 + .proc_handler = &proc_dointvec,
59222 + },
59223 +#endif
59224 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59225 + {
59226 + .procname = "tpe_restrict_all",
59227 + .data = &grsec_enable_tpe_all,
59228 + .maxlen = sizeof(int),
59229 + .mode = 0600,
59230 + .proc_handler = &proc_dointvec,
59231 + },
59232 +#endif
59233 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59234 + {
59235 + .procname = "socket_all",
59236 + .data = &grsec_enable_socket_all,
59237 + .maxlen = sizeof(int),
59238 + .mode = 0600,
59239 + .proc_handler = &proc_dointvec,
59240 + },
59241 + {
59242 + .procname = "socket_all_gid",
59243 + .data = &grsec_socket_all_gid,
59244 + .maxlen = sizeof(int),
59245 + .mode = 0600,
59246 + .proc_handler = &proc_dointvec,
59247 + },
59248 +#endif
59249 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59250 + {
59251 + .procname = "socket_client",
59252 + .data = &grsec_enable_socket_client,
59253 + .maxlen = sizeof(int),
59254 + .mode = 0600,
59255 + .proc_handler = &proc_dointvec,
59256 + },
59257 + {
59258 + .procname = "socket_client_gid",
59259 + .data = &grsec_socket_client_gid,
59260 + .maxlen = sizeof(int),
59261 + .mode = 0600,
59262 + .proc_handler = &proc_dointvec,
59263 + },
59264 +#endif
59265 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59266 + {
59267 + .procname = "socket_server",
59268 + .data = &grsec_enable_socket_server,
59269 + .maxlen = sizeof(int),
59270 + .mode = 0600,
59271 + .proc_handler = &proc_dointvec,
59272 + },
59273 + {
59274 + .procname = "socket_server_gid",
59275 + .data = &grsec_socket_server_gid,
59276 + .maxlen = sizeof(int),
59277 + .mode = 0600,
59278 + .proc_handler = &proc_dointvec,
59279 + },
59280 +#endif
59281 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59282 + {
59283 + .procname = "audit_group",
59284 + .data = &grsec_enable_group,
59285 + .maxlen = sizeof(int),
59286 + .mode = 0600,
59287 + .proc_handler = &proc_dointvec,
59288 + },
59289 + {
59290 + .procname = "audit_gid",
59291 + .data = &grsec_audit_gid,
59292 + .maxlen = sizeof(int),
59293 + .mode = 0600,
59294 + .proc_handler = &proc_dointvec,
59295 + },
59296 +#endif
59297 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59298 + {
59299 + .procname = "audit_chdir",
59300 + .data = &grsec_enable_chdir,
59301 + .maxlen = sizeof(int),
59302 + .mode = 0600,
59303 + .proc_handler = &proc_dointvec,
59304 + },
59305 +#endif
59306 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59307 + {
59308 + .procname = "audit_mount",
59309 + .data = &grsec_enable_mount,
59310 + .maxlen = sizeof(int),
59311 + .mode = 0600,
59312 + .proc_handler = &proc_dointvec,
59313 + },
59314 +#endif
59315 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59316 + {
59317 + .procname = "audit_textrel",
59318 + .data = &grsec_enable_audit_textrel,
59319 + .maxlen = sizeof(int),
59320 + .mode = 0600,
59321 + .proc_handler = &proc_dointvec,
59322 + },
59323 +#endif
59324 +#ifdef CONFIG_GRKERNSEC_DMESG
59325 + {
59326 + .procname = "dmesg",
59327 + .data = &grsec_enable_dmesg,
59328 + .maxlen = sizeof(int),
59329 + .mode = 0600,
59330 + .proc_handler = &proc_dointvec,
59331 + },
59332 +#endif
59333 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59334 + {
59335 + .procname = "chroot_findtask",
59336 + .data = &grsec_enable_chroot_findtask,
59337 + .maxlen = sizeof(int),
59338 + .mode = 0600,
59339 + .proc_handler = &proc_dointvec,
59340 + },
59341 +#endif
59342 +#ifdef CONFIG_GRKERNSEC_RESLOG
59343 + {
59344 + .procname = "resource_logging",
59345 + .data = &grsec_resource_logging,
59346 + .maxlen = sizeof(int),
59347 + .mode = 0600,
59348 + .proc_handler = &proc_dointvec,
59349 + },
59350 +#endif
59351 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59352 + {
59353 + .procname = "audit_ptrace",
59354 + .data = &grsec_enable_audit_ptrace,
59355 + .maxlen = sizeof(int),
59356 + .mode = 0600,
59357 + .proc_handler = &proc_dointvec,
59358 + },
59359 +#endif
59360 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59361 + {
59362 + .procname = "harden_ptrace",
59363 + .data = &grsec_enable_harden_ptrace,
59364 + .maxlen = sizeof(int),
59365 + .mode = 0600,
59366 + .proc_handler = &proc_dointvec,
59367 + },
59368 +#endif
59369 + {
59370 + .procname = "grsec_lock",
59371 + .data = &grsec_lock,
59372 + .maxlen = sizeof(int),
59373 + .mode = 0600,
59374 + .proc_handler = &proc_dointvec,
59375 + },
59376 +#endif
59377 +#ifdef CONFIG_GRKERNSEC_ROFS
59378 + {
59379 + .procname = "romount_protect",
59380 + .data = &grsec_enable_rofs,
59381 + .maxlen = sizeof(int),
59382 + .mode = 0600,
59383 + .proc_handler = &proc_dointvec_minmax,
59384 + .extra1 = &one,
59385 + .extra2 = &one,
59386 + },
59387 +#endif
59388 + { }
59389 +};
59390 +#endif
59391 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59392 new file mode 100644
59393 index 0000000..0dc13c3
59394 --- /dev/null
59395 +++ b/grsecurity/grsec_time.c
59396 @@ -0,0 +1,16 @@
59397 +#include <linux/kernel.h>
59398 +#include <linux/sched.h>
59399 +#include <linux/grinternal.h>
59400 +#include <linux/module.h>
59401 +
59402 +void
59403 +gr_log_timechange(void)
59404 +{
59405 +#ifdef CONFIG_GRKERNSEC_TIME
59406 + if (grsec_enable_time)
59407 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59408 +#endif
59409 + return;
59410 +}
59411 +
59412 +EXPORT_SYMBOL(gr_log_timechange);
59413 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59414 new file mode 100644
59415 index 0000000..07e0dc0
59416 --- /dev/null
59417 +++ b/grsecurity/grsec_tpe.c
59418 @@ -0,0 +1,73 @@
59419 +#include <linux/kernel.h>
59420 +#include <linux/sched.h>
59421 +#include <linux/file.h>
59422 +#include <linux/fs.h>
59423 +#include <linux/grinternal.h>
59424 +
59425 +extern int gr_acl_tpe_check(void);
59426 +
59427 +int
59428 +gr_tpe_allow(const struct file *file)
59429 +{
59430 +#ifdef CONFIG_GRKERNSEC
59431 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59432 + const struct cred *cred = current_cred();
59433 + char *msg = NULL;
59434 + char *msg2 = NULL;
59435 +
59436 + // never restrict root
59437 + if (!cred->uid)
59438 + return 1;
59439 +
59440 + if (grsec_enable_tpe) {
59441 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59442 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59443 + msg = "not being in trusted group";
59444 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59445 + msg = "being in untrusted group";
59446 +#else
59447 + if (in_group_p(grsec_tpe_gid))
59448 + msg = "being in untrusted group";
59449 +#endif
59450 + }
59451 + if (!msg && gr_acl_tpe_check())
59452 + msg = "being in untrusted role";
59453 +
59454 + // not in any affected group/role
59455 + if (!msg)
59456 + goto next_check;
59457 +
59458 + if (inode->i_uid)
59459 + msg2 = "file in non-root-owned directory";
59460 + else if (inode->i_mode & S_IWOTH)
59461 + msg2 = "file in world-writable directory";
59462 + else if (inode->i_mode & S_IWGRP)
59463 + msg2 = "file in group-writable directory";
59464 +
59465 + if (msg && msg2) {
59466 + char fullmsg[70] = {0};
59467 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59468 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59469 + return 0;
59470 + }
59471 + msg = NULL;
59472 +next_check:
59473 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59474 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59475 + return 1;
59476 +
59477 + if (inode->i_uid && (inode->i_uid != cred->uid))
59478 + msg = "directory not owned by user";
59479 + else if (inode->i_mode & S_IWOTH)
59480 + msg = "file in world-writable directory";
59481 + else if (inode->i_mode & S_IWGRP)
59482 + msg = "file in group-writable directory";
59483 +
59484 + if (msg) {
59485 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59486 + return 0;
59487 + }
59488 +#endif
59489 +#endif
59490 + return 1;
59491 +}
59492 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59493 new file mode 100644
59494 index 0000000..9f7b1ac
59495 --- /dev/null
59496 +++ b/grsecurity/grsum.c
59497 @@ -0,0 +1,61 @@
59498 +#include <linux/err.h>
59499 +#include <linux/kernel.h>
59500 +#include <linux/sched.h>
59501 +#include <linux/mm.h>
59502 +#include <linux/scatterlist.h>
59503 +#include <linux/crypto.h>
59504 +#include <linux/gracl.h>
59505 +
59506 +
59507 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59508 +#error "crypto and sha256 must be built into the kernel"
59509 +#endif
59510 +
59511 +int
59512 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59513 +{
59514 + char *p;
59515 + struct crypto_hash *tfm;
59516 + struct hash_desc desc;
59517 + struct scatterlist sg;
59518 + unsigned char temp_sum[GR_SHA_LEN];
59519 + volatile int retval = 0;
59520 + volatile int dummy = 0;
59521 + unsigned int i;
59522 +
59523 + sg_init_table(&sg, 1);
59524 +
59525 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59526 + if (IS_ERR(tfm)) {
59527 + /* should never happen, since sha256 should be built in */
59528 + return 1;
59529 + }
59530 +
59531 + desc.tfm = tfm;
59532 + desc.flags = 0;
59533 +
59534 + crypto_hash_init(&desc);
59535 +
59536 + p = salt;
59537 + sg_set_buf(&sg, p, GR_SALT_LEN);
59538 + crypto_hash_update(&desc, &sg, sg.length);
59539 +
59540 + p = entry->pw;
59541 + sg_set_buf(&sg, p, strlen(p));
59542 +
59543 + crypto_hash_update(&desc, &sg, sg.length);
59544 +
59545 + crypto_hash_final(&desc, temp_sum);
59546 +
59547 + memset(entry->pw, 0, GR_PW_LEN);
59548 +
59549 + for (i = 0; i < GR_SHA_LEN; i++)
59550 + if (sum[i] != temp_sum[i])
59551 + retval = 1;
59552 + else
59553 + dummy = 1; // waste a cycle
59554 +
59555 + crypto_free_hash(tfm);
59556 +
59557 + return retval;
59558 +}
59559 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59560 index 6cd5b64..f620d2d 100644
59561 --- a/include/acpi/acpi_bus.h
59562 +++ b/include/acpi/acpi_bus.h
59563 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59564 acpi_op_bind bind;
59565 acpi_op_unbind unbind;
59566 acpi_op_notify notify;
59567 -};
59568 +} __no_const;
59569
59570 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59571
59572 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59573 index b7babf0..71e4e74 100644
59574 --- a/include/asm-generic/atomic-long.h
59575 +++ b/include/asm-generic/atomic-long.h
59576 @@ -22,6 +22,12 @@
59577
59578 typedef atomic64_t atomic_long_t;
59579
59580 +#ifdef CONFIG_PAX_REFCOUNT
59581 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59582 +#else
59583 +typedef atomic64_t atomic_long_unchecked_t;
59584 +#endif
59585 +
59586 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59587
59588 static inline long atomic_long_read(atomic_long_t *l)
59589 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59590 return (long)atomic64_read(v);
59591 }
59592
59593 +#ifdef CONFIG_PAX_REFCOUNT
59594 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59595 +{
59596 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59597 +
59598 + return (long)atomic64_read_unchecked(v);
59599 +}
59600 +#endif
59601 +
59602 static inline void atomic_long_set(atomic_long_t *l, long i)
59603 {
59604 atomic64_t *v = (atomic64_t *)l;
59605 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59606 atomic64_set(v, i);
59607 }
59608
59609 +#ifdef CONFIG_PAX_REFCOUNT
59610 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59611 +{
59612 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59613 +
59614 + atomic64_set_unchecked(v, i);
59615 +}
59616 +#endif
59617 +
59618 static inline void atomic_long_inc(atomic_long_t *l)
59619 {
59620 atomic64_t *v = (atomic64_t *)l;
59621 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59622 atomic64_inc(v);
59623 }
59624
59625 +#ifdef CONFIG_PAX_REFCOUNT
59626 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59627 +{
59628 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59629 +
59630 + atomic64_inc_unchecked(v);
59631 +}
59632 +#endif
59633 +
59634 static inline void atomic_long_dec(atomic_long_t *l)
59635 {
59636 atomic64_t *v = (atomic64_t *)l;
59637 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59638 atomic64_dec(v);
59639 }
59640
59641 +#ifdef CONFIG_PAX_REFCOUNT
59642 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59643 +{
59644 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59645 +
59646 + atomic64_dec_unchecked(v);
59647 +}
59648 +#endif
59649 +
59650 static inline void atomic_long_add(long i, atomic_long_t *l)
59651 {
59652 atomic64_t *v = (atomic64_t *)l;
59653 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59654 atomic64_add(i, v);
59655 }
59656
59657 +#ifdef CONFIG_PAX_REFCOUNT
59658 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59659 +{
59660 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59661 +
59662 + atomic64_add_unchecked(i, v);
59663 +}
59664 +#endif
59665 +
59666 static inline void atomic_long_sub(long i, atomic_long_t *l)
59667 {
59668 atomic64_t *v = (atomic64_t *)l;
59669 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59670 atomic64_sub(i, v);
59671 }
59672
59673 +#ifdef CONFIG_PAX_REFCOUNT
59674 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59675 +{
59676 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59677 +
59678 + atomic64_sub_unchecked(i, v);
59679 +}
59680 +#endif
59681 +
59682 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59683 {
59684 atomic64_t *v = (atomic64_t *)l;
59685 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59686 return (long)atomic64_inc_return(v);
59687 }
59688
59689 +#ifdef CONFIG_PAX_REFCOUNT
59690 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59691 +{
59692 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59693 +
59694 + return (long)atomic64_inc_return_unchecked(v);
59695 +}
59696 +#endif
59697 +
59698 static inline long atomic_long_dec_return(atomic_long_t *l)
59699 {
59700 atomic64_t *v = (atomic64_t *)l;
59701 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59702
59703 typedef atomic_t atomic_long_t;
59704
59705 +#ifdef CONFIG_PAX_REFCOUNT
59706 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59707 +#else
59708 +typedef atomic_t atomic_long_unchecked_t;
59709 +#endif
59710 +
59711 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59712 static inline long atomic_long_read(atomic_long_t *l)
59713 {
59714 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59715 return (long)atomic_read(v);
59716 }
59717
59718 +#ifdef CONFIG_PAX_REFCOUNT
59719 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59720 +{
59721 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59722 +
59723 + return (long)atomic_read_unchecked(v);
59724 +}
59725 +#endif
59726 +
59727 static inline void atomic_long_set(atomic_long_t *l, long i)
59728 {
59729 atomic_t *v = (atomic_t *)l;
59730 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59731 atomic_set(v, i);
59732 }
59733
59734 +#ifdef CONFIG_PAX_REFCOUNT
59735 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59736 +{
59737 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59738 +
59739 + atomic_set_unchecked(v, i);
59740 +}
59741 +#endif
59742 +
59743 static inline void atomic_long_inc(atomic_long_t *l)
59744 {
59745 atomic_t *v = (atomic_t *)l;
59746 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59747 atomic_inc(v);
59748 }
59749
59750 +#ifdef CONFIG_PAX_REFCOUNT
59751 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59752 +{
59753 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59754 +
59755 + atomic_inc_unchecked(v);
59756 +}
59757 +#endif
59758 +
59759 static inline void atomic_long_dec(atomic_long_t *l)
59760 {
59761 atomic_t *v = (atomic_t *)l;
59762 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59763 atomic_dec(v);
59764 }
59765
59766 +#ifdef CONFIG_PAX_REFCOUNT
59767 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59768 +{
59769 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59770 +
59771 + atomic_dec_unchecked(v);
59772 +}
59773 +#endif
59774 +
59775 static inline void atomic_long_add(long i, atomic_long_t *l)
59776 {
59777 atomic_t *v = (atomic_t *)l;
59778 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59779 atomic_add(i, v);
59780 }
59781
59782 +#ifdef CONFIG_PAX_REFCOUNT
59783 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59784 +{
59785 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59786 +
59787 + atomic_add_unchecked(i, v);
59788 +}
59789 +#endif
59790 +
59791 static inline void atomic_long_sub(long i, atomic_long_t *l)
59792 {
59793 atomic_t *v = (atomic_t *)l;
59794 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59795 atomic_sub(i, v);
59796 }
59797
59798 +#ifdef CONFIG_PAX_REFCOUNT
59799 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59800 +{
59801 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59802 +
59803 + atomic_sub_unchecked(i, v);
59804 +}
59805 +#endif
59806 +
59807 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59808 {
59809 atomic_t *v = (atomic_t *)l;
59810 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59811 return (long)atomic_inc_return(v);
59812 }
59813
59814 +#ifdef CONFIG_PAX_REFCOUNT
59815 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59816 +{
59817 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59818 +
59819 + return (long)atomic_inc_return_unchecked(v);
59820 +}
59821 +#endif
59822 +
59823 static inline long atomic_long_dec_return(atomic_long_t *l)
59824 {
59825 atomic_t *v = (atomic_t *)l;
59826 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59827
59828 #endif /* BITS_PER_LONG == 64 */
59829
59830 +#ifdef CONFIG_PAX_REFCOUNT
59831 +static inline void pax_refcount_needs_these_functions(void)
59832 +{
59833 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59834 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59835 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59836 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59837 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59838 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59839 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59840 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59841 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59842 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59843 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59844 +
59845 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59846 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59847 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59848 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59849 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59850 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59851 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59852 +}
59853 +#else
59854 +#define atomic_read_unchecked(v) atomic_read(v)
59855 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59856 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59857 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59858 +#define atomic_inc_unchecked(v) atomic_inc(v)
59859 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59860 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59861 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59862 +#define atomic_dec_unchecked(v) atomic_dec(v)
59863 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59864 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59865 +
59866 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59867 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59868 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59869 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59870 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59871 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59872 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59873 +#endif
59874 +
59875 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59876 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59877 index b18ce4f..2ee2843 100644
59878 --- a/include/asm-generic/atomic64.h
59879 +++ b/include/asm-generic/atomic64.h
59880 @@ -16,6 +16,8 @@ typedef struct {
59881 long long counter;
59882 } atomic64_t;
59883
59884 +typedef atomic64_t atomic64_unchecked_t;
59885 +
59886 #define ATOMIC64_INIT(i) { (i) }
59887
59888 extern long long atomic64_read(const atomic64_t *v);
59889 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59890 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59891 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59892
59893 +#define atomic64_read_unchecked(v) atomic64_read(v)
59894 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59895 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59896 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59897 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59898 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59899 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59900 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59901 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59902 +
59903 #endif /* _ASM_GENERIC_ATOMIC64_H */
59904 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59905 index 1bfcfe5..e04c5c9 100644
59906 --- a/include/asm-generic/cache.h
59907 +++ b/include/asm-generic/cache.h
59908 @@ -6,7 +6,7 @@
59909 * cache lines need to provide their own cache.h.
59910 */
59911
59912 -#define L1_CACHE_SHIFT 5
59913 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59914 +#define L1_CACHE_SHIFT 5UL
59915 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59916
59917 #endif /* __ASM_GENERIC_CACHE_H */
59918 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59919 index 0d68a1e..b74a761 100644
59920 --- a/include/asm-generic/emergency-restart.h
59921 +++ b/include/asm-generic/emergency-restart.h
59922 @@ -1,7 +1,7 @@
59923 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59924 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59925
59926 -static inline void machine_emergency_restart(void)
59927 +static inline __noreturn void machine_emergency_restart(void)
59928 {
59929 machine_restart(NULL);
59930 }
59931 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59932 index 0232ccb..13d9165 100644
59933 --- a/include/asm-generic/kmap_types.h
59934 +++ b/include/asm-generic/kmap_types.h
59935 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59936 KMAP_D(17) KM_NMI,
59937 KMAP_D(18) KM_NMI_PTE,
59938 KMAP_D(19) KM_KDB,
59939 +KMAP_D(20) KM_CLEARPAGE,
59940 /*
59941 * Remember to update debug_kmap_atomic() when adding new kmap types!
59942 */
59943 -KMAP_D(20) KM_TYPE_NR
59944 +KMAP_D(21) KM_TYPE_NR
59945 };
59946
59947 #undef KMAP_D
59948 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59949 index 9ceb03b..2efbcbd 100644
59950 --- a/include/asm-generic/local.h
59951 +++ b/include/asm-generic/local.h
59952 @@ -39,6 +39,7 @@ typedef struct
59953 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59954 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59955 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59956 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59957
59958 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59959 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59960 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59961 index 725612b..9cc513a 100644
59962 --- a/include/asm-generic/pgtable-nopmd.h
59963 +++ b/include/asm-generic/pgtable-nopmd.h
59964 @@ -1,14 +1,19 @@
59965 #ifndef _PGTABLE_NOPMD_H
59966 #define _PGTABLE_NOPMD_H
59967
59968 -#ifndef __ASSEMBLY__
59969 -
59970 #include <asm-generic/pgtable-nopud.h>
59971
59972 -struct mm_struct;
59973 -
59974 #define __PAGETABLE_PMD_FOLDED
59975
59976 +#define PMD_SHIFT PUD_SHIFT
59977 +#define PTRS_PER_PMD 1
59978 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59979 +#define PMD_MASK (~(PMD_SIZE-1))
59980 +
59981 +#ifndef __ASSEMBLY__
59982 +
59983 +struct mm_struct;
59984 +
59985 /*
59986 * Having the pmd type consist of a pud gets the size right, and allows
59987 * us to conceptually access the pud entry that this pmd is folded into
59988 @@ -16,11 +21,6 @@ struct mm_struct;
59989 */
59990 typedef struct { pud_t pud; } pmd_t;
59991
59992 -#define PMD_SHIFT PUD_SHIFT
59993 -#define PTRS_PER_PMD 1
59994 -#define PMD_SIZE (1UL << PMD_SHIFT)
59995 -#define PMD_MASK (~(PMD_SIZE-1))
59996 -
59997 /*
59998 * The "pud_xxx()" functions here are trivial for a folded two-level
59999 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60000 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60001 index 810431d..ccc3638 100644
60002 --- a/include/asm-generic/pgtable-nopud.h
60003 +++ b/include/asm-generic/pgtable-nopud.h
60004 @@ -1,10 +1,15 @@
60005 #ifndef _PGTABLE_NOPUD_H
60006 #define _PGTABLE_NOPUD_H
60007
60008 -#ifndef __ASSEMBLY__
60009 -
60010 #define __PAGETABLE_PUD_FOLDED
60011
60012 +#define PUD_SHIFT PGDIR_SHIFT
60013 +#define PTRS_PER_PUD 1
60014 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60015 +#define PUD_MASK (~(PUD_SIZE-1))
60016 +
60017 +#ifndef __ASSEMBLY__
60018 +
60019 /*
60020 * Having the pud type consist of a pgd gets the size right, and allows
60021 * us to conceptually access the pgd entry that this pud is folded into
60022 @@ -12,11 +17,6 @@
60023 */
60024 typedef struct { pgd_t pgd; } pud_t;
60025
60026 -#define PUD_SHIFT PGDIR_SHIFT
60027 -#define PTRS_PER_PUD 1
60028 -#define PUD_SIZE (1UL << PUD_SHIFT)
60029 -#define PUD_MASK (~(PUD_SIZE-1))
60030 -
60031 /*
60032 * The "pgd_xxx()" functions here are trivial for a folded two-level
60033 * setup: the pud is never bad, and a pud always exists (as it's folded
60034 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60035 index a03c098..7e5b223 100644
60036 --- a/include/asm-generic/pgtable.h
60037 +++ b/include/asm-generic/pgtable.h
60038 @@ -502,6 +502,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60039 #endif
60040 }
60041
60042 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60043 +static inline unsigned long pax_open_kernel(void) { return 0; }
60044 +#endif
60045 +
60046 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60047 +static inline unsigned long pax_close_kernel(void) { return 0; }
60048 +#endif
60049 +
60050 #endif /* CONFIG_MMU */
60051
60052 #endif /* !__ASSEMBLY__ */
60053 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
60054 index 9788568..510dece 100644
60055 --- a/include/asm-generic/uaccess.h
60056 +++ b/include/asm-generic/uaccess.h
60057 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
60058 */
60059 #ifndef __copy_from_user
60060 static inline __must_check long __copy_from_user(void *to,
60061 + const void __user * from, unsigned long n) __size_overflow(3);
60062 +static inline __must_check long __copy_from_user(void *to,
60063 const void __user * from, unsigned long n)
60064 {
60065 if (__builtin_constant_p(n)) {
60066 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
60067
60068 #ifndef __copy_to_user
60069 static inline __must_check long __copy_to_user(void __user *to,
60070 + const void *from, unsigned long n) __size_overflow(3);
60071 +static inline __must_check long __copy_to_user(void __user *to,
60072 const void *from, unsigned long n)
60073 {
60074 if (__builtin_constant_p(n)) {
60075 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60076 -EFAULT; \
60077 })
60078
60079 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60080 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60081 {
60082 size = __copy_from_user(x, ptr, size);
60083 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60084 #define __copy_to_user_inatomic __copy_to_user
60085 #endif
60086
60087 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60088 static inline long copy_from_user(void *to,
60089 const void __user * from, unsigned long n)
60090 {
60091 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60092 return n;
60093 }
60094
60095 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60096 static inline long copy_to_user(void __user *to,
60097 const void *from, unsigned long n)
60098 {
60099 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
60100 */
60101 #ifndef __clear_user
60102 static inline __must_check unsigned long
60103 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60104 +static inline __must_check unsigned long
60105 __clear_user(void __user *to, unsigned long n)
60106 {
60107 memset((void __force *)to, 0, n);
60108 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
60109 #endif
60110
60111 static inline __must_check unsigned long
60112 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60113 +static inline __must_check unsigned long
60114 clear_user(void __user *to, unsigned long n)
60115 {
60116 might_sleep();
60117 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60118 index b5e2e4c..6a5373e 100644
60119 --- a/include/asm-generic/vmlinux.lds.h
60120 +++ b/include/asm-generic/vmlinux.lds.h
60121 @@ -217,6 +217,7 @@
60122 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60123 VMLINUX_SYMBOL(__start_rodata) = .; \
60124 *(.rodata) *(.rodata.*) \
60125 + *(.data..read_only) \
60126 *(__vermagic) /* Kernel version magic */ \
60127 . = ALIGN(8); \
60128 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60129 @@ -722,17 +723,18 @@
60130 * section in the linker script will go there too. @phdr should have
60131 * a leading colon.
60132 *
60133 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60134 + * Note that this macros defines per_cpu_load as an absolute symbol.
60135 * If there is no need to put the percpu section at a predetermined
60136 * address, use PERCPU_SECTION.
60137 */
60138 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60139 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60140 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60141 + per_cpu_load = .; \
60142 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60143 - LOAD_OFFSET) { \
60144 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60145 PERCPU_INPUT(cacheline) \
60146 } phdr \
60147 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60148 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60149
60150 /**
60151 * PERCPU_SECTION - define output section for percpu area, simple version
60152 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60153 index 92f0981..d44a37c 100644
60154 --- a/include/drm/drmP.h
60155 +++ b/include/drm/drmP.h
60156 @@ -72,6 +72,7 @@
60157 #include <linux/workqueue.h>
60158 #include <linux/poll.h>
60159 #include <asm/pgalloc.h>
60160 +#include <asm/local.h>
60161 #include "drm.h"
60162
60163 #include <linux/idr.h>
60164 @@ -1038,7 +1039,7 @@ struct drm_device {
60165
60166 /** \name Usage Counters */
60167 /*@{ */
60168 - int open_count; /**< Outstanding files open */
60169 + local_t open_count; /**< Outstanding files open */
60170 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60171 atomic_t vma_count; /**< Outstanding vma areas open */
60172 int buf_use; /**< Buffers in use -- cannot alloc */
60173 @@ -1049,7 +1050,7 @@ struct drm_device {
60174 /*@{ */
60175 unsigned long counters;
60176 enum drm_stat_type types[15];
60177 - atomic_t counts[15];
60178 + atomic_unchecked_t counts[15];
60179 /*@} */
60180
60181 struct list_head filelist;
60182 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60183 index 37515d1..34fa8b0 100644
60184 --- a/include/drm/drm_crtc_helper.h
60185 +++ b/include/drm/drm_crtc_helper.h
60186 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60187
60188 /* disable crtc when not in use - more explicit than dpms off */
60189 void (*disable)(struct drm_crtc *crtc);
60190 -};
60191 +} __no_const;
60192
60193 struct drm_encoder_helper_funcs {
60194 void (*dpms)(struct drm_encoder *encoder, int mode);
60195 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60196 struct drm_connector *connector);
60197 /* disable encoder when not in use - more explicit than dpms off */
60198 void (*disable)(struct drm_encoder *encoder);
60199 -};
60200 +} __no_const;
60201
60202 struct drm_connector_helper_funcs {
60203 int (*get_modes)(struct drm_connector *connector);
60204 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60205 index 26c1f78..6722682 100644
60206 --- a/include/drm/ttm/ttm_memory.h
60207 +++ b/include/drm/ttm/ttm_memory.h
60208 @@ -47,7 +47,7 @@
60209
60210 struct ttm_mem_shrink {
60211 int (*do_shrink) (struct ttm_mem_shrink *);
60212 -};
60213 +} __no_const;
60214
60215 /**
60216 * struct ttm_mem_global - Global memory accounting structure.
60217 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60218 index e86dfca..40cc55f 100644
60219 --- a/include/linux/a.out.h
60220 +++ b/include/linux/a.out.h
60221 @@ -39,6 +39,14 @@ enum machine_type {
60222 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60223 };
60224
60225 +/* Constants for the N_FLAGS field */
60226 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60227 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60228 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60229 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60230 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60231 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60232 +
60233 #if !defined (N_MAGIC)
60234 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60235 #endif
60236 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60237 index f4ff882..84b53a6 100644
60238 --- a/include/linux/atmdev.h
60239 +++ b/include/linux/atmdev.h
60240 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60241 #endif
60242
60243 struct k_atm_aal_stats {
60244 -#define __HANDLE_ITEM(i) atomic_t i
60245 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60246 __AAL_STAT_ITEMS
60247 #undef __HANDLE_ITEM
60248 };
60249 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60250 index 0092102..8a801b4 100644
60251 --- a/include/linux/binfmts.h
60252 +++ b/include/linux/binfmts.h
60253 @@ -89,6 +89,7 @@ struct linux_binfmt {
60254 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60255 int (*load_shlib)(struct file *);
60256 int (*core_dump)(struct coredump_params *cprm);
60257 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60258 unsigned long min_coredump; /* minimal dump size */
60259 };
60260
60261 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60262 index 606cf33..b72c577 100644
60263 --- a/include/linux/blkdev.h
60264 +++ b/include/linux/blkdev.h
60265 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60266 /* this callback is with swap_lock and sometimes page table lock held */
60267 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60268 struct module *owner;
60269 -};
60270 +} __do_const;
60271
60272 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60273 unsigned long);
60274 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60275 index 4d1a074..88f929a 100644
60276 --- a/include/linux/blktrace_api.h
60277 +++ b/include/linux/blktrace_api.h
60278 @@ -162,7 +162,7 @@ struct blk_trace {
60279 struct dentry *dir;
60280 struct dentry *dropped_file;
60281 struct dentry *msg_file;
60282 - atomic_t dropped;
60283 + atomic_unchecked_t dropped;
60284 };
60285
60286 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60287 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60288 index 83195fb..0b0f77d 100644
60289 --- a/include/linux/byteorder/little_endian.h
60290 +++ b/include/linux/byteorder/little_endian.h
60291 @@ -42,51 +42,51 @@
60292
60293 static inline __le64 __cpu_to_le64p(const __u64 *p)
60294 {
60295 - return (__force __le64)*p;
60296 + return (__force const __le64)*p;
60297 }
60298 static inline __u64 __le64_to_cpup(const __le64 *p)
60299 {
60300 - return (__force __u64)*p;
60301 + return (__force const __u64)*p;
60302 }
60303 static inline __le32 __cpu_to_le32p(const __u32 *p)
60304 {
60305 - return (__force __le32)*p;
60306 + return (__force const __le32)*p;
60307 }
60308 static inline __u32 __le32_to_cpup(const __le32 *p)
60309 {
60310 - return (__force __u32)*p;
60311 + return (__force const __u32)*p;
60312 }
60313 static inline __le16 __cpu_to_le16p(const __u16 *p)
60314 {
60315 - return (__force __le16)*p;
60316 + return (__force const __le16)*p;
60317 }
60318 static inline __u16 __le16_to_cpup(const __le16 *p)
60319 {
60320 - return (__force __u16)*p;
60321 + return (__force const __u16)*p;
60322 }
60323 static inline __be64 __cpu_to_be64p(const __u64 *p)
60324 {
60325 - return (__force __be64)__swab64p(p);
60326 + return (__force const __be64)__swab64p(p);
60327 }
60328 static inline __u64 __be64_to_cpup(const __be64 *p)
60329 {
60330 - return __swab64p((__u64 *)p);
60331 + return __swab64p((const __u64 *)p);
60332 }
60333 static inline __be32 __cpu_to_be32p(const __u32 *p)
60334 {
60335 - return (__force __be32)__swab32p(p);
60336 + return (__force const __be32)__swab32p(p);
60337 }
60338 static inline __u32 __be32_to_cpup(const __be32 *p)
60339 {
60340 - return __swab32p((__u32 *)p);
60341 + return __swab32p((const __u32 *)p);
60342 }
60343 static inline __be16 __cpu_to_be16p(const __u16 *p)
60344 {
60345 - return (__force __be16)__swab16p(p);
60346 + return (__force const __be16)__swab16p(p);
60347 }
60348 static inline __u16 __be16_to_cpup(const __be16 *p)
60349 {
60350 - return __swab16p((__u16 *)p);
60351 + return __swab16p((const __u16 *)p);
60352 }
60353 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60354 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60355 diff --git a/include/linux/cache.h b/include/linux/cache.h
60356 index 4c57065..4307975 100644
60357 --- a/include/linux/cache.h
60358 +++ b/include/linux/cache.h
60359 @@ -16,6 +16,10 @@
60360 #define __read_mostly
60361 #endif
60362
60363 +#ifndef __read_only
60364 +#define __read_only __read_mostly
60365 +#endif
60366 +
60367 #ifndef ____cacheline_aligned
60368 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60369 #endif
60370 diff --git a/include/linux/capability.h b/include/linux/capability.h
60371 index 12d52de..b5f7fa7 100644
60372 --- a/include/linux/capability.h
60373 +++ b/include/linux/capability.h
60374 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60375 extern bool capable(int cap);
60376 extern bool ns_capable(struct user_namespace *ns, int cap);
60377 extern bool nsown_capable(int cap);
60378 +extern bool capable_nolog(int cap);
60379 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60380
60381 /* audit system wants to get cap info from files as well */
60382 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60383 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60384 index 04ffb2e..6799180 100644
60385 --- a/include/linux/cleancache.h
60386 +++ b/include/linux/cleancache.h
60387 @@ -31,7 +31,7 @@ struct cleancache_ops {
60388 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60389 void (*flush_inode)(int, struct cleancache_filekey);
60390 void (*flush_fs)(int);
60391 -};
60392 +} __no_const;
60393
60394 extern struct cleancache_ops
60395 cleancache_register_ops(struct cleancache_ops *ops);
60396 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60397 index 2f40791..567b215 100644
60398 --- a/include/linux/compiler-gcc4.h
60399 +++ b/include/linux/compiler-gcc4.h
60400 @@ -32,6 +32,15 @@
60401 #define __linktime_error(message) __attribute__((__error__(message)))
60402
60403 #if __GNUC_MINOR__ >= 5
60404 +
60405 +#ifdef CONSTIFY_PLUGIN
60406 +#define __no_const __attribute__((no_const))
60407 +#define __do_const __attribute__((do_const))
60408 +#endif
60409 +
60410 +#ifdef SIZE_OVERFLOW_PLUGIN
60411 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60412 +#endif
60413 /*
60414 * Mark a position in code as unreachable. This can be used to
60415 * suppress control flow warnings after asm blocks that transfer
60416 @@ -47,6 +56,11 @@
60417 #define __noclone __attribute__((__noclone__))
60418
60419 #endif
60420 +
60421 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60422 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60423 +#define __bos0(ptr) __bos((ptr), 0)
60424 +#define __bos1(ptr) __bos((ptr), 1)
60425 #endif
60426
60427 #if __GNUC_MINOR__ > 0
60428 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60429 index 4a24354..ecaff7a 100644
60430 --- a/include/linux/compiler.h
60431 +++ b/include/linux/compiler.h
60432 @@ -5,31 +5,62 @@
60433
60434 #ifdef __CHECKER__
60435 # define __user __attribute__((noderef, address_space(1)))
60436 +# define __force_user __force __user
60437 # define __kernel __attribute__((address_space(0)))
60438 +# define __force_kernel __force __kernel
60439 # define __safe __attribute__((safe))
60440 # define __force __attribute__((force))
60441 # define __nocast __attribute__((nocast))
60442 # define __iomem __attribute__((noderef, address_space(2)))
60443 +# define __force_iomem __force __iomem
60444 # define __acquires(x) __attribute__((context(x,0,1)))
60445 # define __releases(x) __attribute__((context(x,1,0)))
60446 # define __acquire(x) __context__(x,1)
60447 # define __release(x) __context__(x,-1)
60448 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60449 # define __percpu __attribute__((noderef, address_space(3)))
60450 +# define __force_percpu __force __percpu
60451 #ifdef CONFIG_SPARSE_RCU_POINTER
60452 # define __rcu __attribute__((noderef, address_space(4)))
60453 +# define __force_rcu __force __rcu
60454 #else
60455 # define __rcu
60456 +# define __force_rcu
60457 #endif
60458 extern void __chk_user_ptr(const volatile void __user *);
60459 extern void __chk_io_ptr(const volatile void __iomem *);
60460 +#elif defined(CHECKER_PLUGIN)
60461 +//# define __user
60462 +//# define __force_user
60463 +//# define __kernel
60464 +//# define __force_kernel
60465 +# define __safe
60466 +# define __force
60467 +# define __nocast
60468 +# define __iomem
60469 +# define __force_iomem
60470 +# define __chk_user_ptr(x) (void)0
60471 +# define __chk_io_ptr(x) (void)0
60472 +# define __builtin_warning(x, y...) (1)
60473 +# define __acquires(x)
60474 +# define __releases(x)
60475 +# define __acquire(x) (void)0
60476 +# define __release(x) (void)0
60477 +# define __cond_lock(x,c) (c)
60478 +# define __percpu
60479 +# define __force_percpu
60480 +# define __rcu
60481 +# define __force_rcu
60482 #else
60483 # define __user
60484 +# define __force_user
60485 # define __kernel
60486 +# define __force_kernel
60487 # define __safe
60488 # define __force
60489 # define __nocast
60490 # define __iomem
60491 +# define __force_iomem
60492 # define __chk_user_ptr(x) (void)0
60493 # define __chk_io_ptr(x) (void)0
60494 # define __builtin_warning(x, y...) (1)
60495 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60496 # define __release(x) (void)0
60497 # define __cond_lock(x,c) (c)
60498 # define __percpu
60499 +# define __force_percpu
60500 # define __rcu
60501 +# define __force_rcu
60502 #endif
60503
60504 #ifdef __KERNEL__
60505 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60506 # define __attribute_const__ /* unimplemented */
60507 #endif
60508
60509 +#ifndef __no_const
60510 +# define __no_const
60511 +#endif
60512 +
60513 +#ifndef __do_const
60514 +# define __do_const
60515 +#endif
60516 +
60517 +#ifndef __size_overflow
60518 +# define __size_overflow(...)
60519 +#endif
60520 /*
60521 * Tell gcc if a function is cold. The compiler will assume any path
60522 * directly leading to the call is unlikely.
60523 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60524 #define __cold
60525 #endif
60526
60527 +#ifndef __alloc_size
60528 +#define __alloc_size(...)
60529 +#endif
60530 +
60531 +#ifndef __bos
60532 +#define __bos(ptr, arg)
60533 +#endif
60534 +
60535 +#ifndef __bos0
60536 +#define __bos0(ptr)
60537 +#endif
60538 +
60539 +#ifndef __bos1
60540 +#define __bos1(ptr)
60541 +#endif
60542 +
60543 /* Simple shorthand for a section definition */
60544 #ifndef __section
60545 # define __section(S) __attribute__ ((__section__(#S)))
60546 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60547 * use is to mediate communication between process-level code and irq/NMI
60548 * handlers, all running on the same CPU.
60549 */
60550 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60551 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60552 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60553
60554 #endif /* __LINUX_COMPILER_H */
60555 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60556 index e9eaec5..bfeb9bb 100644
60557 --- a/include/linux/cpuset.h
60558 +++ b/include/linux/cpuset.h
60559 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60560 * nodemask.
60561 */
60562 smp_mb();
60563 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60564 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60565 }
60566
60567 static inline void set_mems_allowed(nodemask_t nodemask)
60568 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60569 index b936763..48685ee 100644
60570 --- a/include/linux/crash_dump.h
60571 +++ b/include/linux/crash_dump.h
60572 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60573 extern unsigned long long elfcorehdr_size;
60574
60575 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60576 - unsigned long, int);
60577 + unsigned long, int) __size_overflow(3);
60578
60579 /* Architecture code defines this if there are other possible ELF
60580 * machine types, e.g. on bi-arch capable hardware. */
60581 diff --git a/include/linux/cred.h b/include/linux/cred.h
60582 index adadf71..6af5560 100644
60583 --- a/include/linux/cred.h
60584 +++ b/include/linux/cred.h
60585 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60586 static inline void validate_process_creds(void)
60587 {
60588 }
60589 +static inline void validate_task_creds(struct task_struct *task)
60590 +{
60591 +}
60592 #endif
60593
60594 /**
60595 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60596 index 8a94217..15d49e3 100644
60597 --- a/include/linux/crypto.h
60598 +++ b/include/linux/crypto.h
60599 @@ -365,7 +365,7 @@ struct cipher_tfm {
60600 const u8 *key, unsigned int keylen);
60601 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60602 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60603 -};
60604 +} __no_const;
60605
60606 struct hash_tfm {
60607 int (*init)(struct hash_desc *desc);
60608 @@ -386,13 +386,13 @@ struct compress_tfm {
60609 int (*cot_decompress)(struct crypto_tfm *tfm,
60610 const u8 *src, unsigned int slen,
60611 u8 *dst, unsigned int *dlen);
60612 -};
60613 +} __no_const;
60614
60615 struct rng_tfm {
60616 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60617 unsigned int dlen);
60618 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60619 -};
60620 +} __no_const;
60621
60622 #define crt_ablkcipher crt_u.ablkcipher
60623 #define crt_aead crt_u.aead
60624 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60625 index 7925bf0..d5143d2 100644
60626 --- a/include/linux/decompress/mm.h
60627 +++ b/include/linux/decompress/mm.h
60628 @@ -77,7 +77,7 @@ static void free(void *where)
60629 * warnings when not needed (indeed large_malloc / large_free are not
60630 * needed by inflate */
60631
60632 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60633 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60634 #define free(a) kfree(a)
60635
60636 #define large_malloc(a) vmalloc(a)
60637 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60638 index e13117c..e9fc938 100644
60639 --- a/include/linux/dma-mapping.h
60640 +++ b/include/linux/dma-mapping.h
60641 @@ -46,7 +46,7 @@ struct dma_map_ops {
60642 u64 (*get_required_mask)(struct device *dev);
60643 #endif
60644 int is_phys;
60645 -};
60646 +} __do_const;
60647
60648 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60649
60650 diff --git a/include/linux/efi.h b/include/linux/efi.h
60651 index 37c3007..92ab679 100644
60652 --- a/include/linux/efi.h
60653 +++ b/include/linux/efi.h
60654 @@ -580,7 +580,7 @@ struct efivar_operations {
60655 efi_get_variable_t *get_variable;
60656 efi_get_next_variable_t *get_next_variable;
60657 efi_set_variable_t *set_variable;
60658 -};
60659 +} __no_const;
60660
60661 struct efivars {
60662 /*
60663 diff --git a/include/linux/elf.h b/include/linux/elf.h
60664 index 999b4f5..57753b4 100644
60665 --- a/include/linux/elf.h
60666 +++ b/include/linux/elf.h
60667 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60668 #define PT_GNU_EH_FRAME 0x6474e550
60669
60670 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60671 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60672 +
60673 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60674 +
60675 +/* Constants for the e_flags field */
60676 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60677 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60678 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60679 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60680 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60681 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60682
60683 /*
60684 * Extended Numbering
60685 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60686 #define DT_DEBUG 21
60687 #define DT_TEXTREL 22
60688 #define DT_JMPREL 23
60689 +#define DT_FLAGS 30
60690 + #define DF_TEXTREL 0x00000004
60691 #define DT_ENCODING 32
60692 #define OLD_DT_LOOS 0x60000000
60693 #define DT_LOOS 0x6000000d
60694 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60695 #define PF_W 0x2
60696 #define PF_X 0x1
60697
60698 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60699 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60700 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60701 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60702 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60703 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60704 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60705 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60706 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60707 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60708 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60709 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60710 +
60711 typedef struct elf32_phdr{
60712 Elf32_Word p_type;
60713 Elf32_Off p_offset;
60714 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60715 #define EI_OSABI 7
60716 #define EI_PAD 8
60717
60718 +#define EI_PAX 14
60719 +
60720 #define ELFMAG0 0x7f /* EI_MAG */
60721 #define ELFMAG1 'E'
60722 #define ELFMAG2 'L'
60723 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60724 #define elf_note elf32_note
60725 #define elf_addr_t Elf32_Off
60726 #define Elf_Half Elf32_Half
60727 +#define elf_dyn Elf32_Dyn
60728
60729 #else
60730
60731 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60732 #define elf_note elf64_note
60733 #define elf_addr_t Elf64_Off
60734 #define Elf_Half Elf64_Half
60735 +#define elf_dyn Elf64_Dyn
60736
60737 #endif
60738
60739 diff --git a/include/linux/filter.h b/include/linux/filter.h
60740 index 8eeb205..d59bfa2 100644
60741 --- a/include/linux/filter.h
60742 +++ b/include/linux/filter.h
60743 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60744
60745 struct sk_buff;
60746 struct sock;
60747 +struct bpf_jit_work;
60748
60749 struct sk_filter
60750 {
60751 @@ -141,6 +142,9 @@ struct sk_filter
60752 unsigned int len; /* Number of filter blocks */
60753 unsigned int (*bpf_func)(const struct sk_buff *skb,
60754 const struct sock_filter *filter);
60755 +#ifdef CONFIG_BPF_JIT
60756 + struct bpf_jit_work *work;
60757 +#endif
60758 struct rcu_head rcu;
60759 struct sock_filter insns[0];
60760 };
60761 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60762 index 84ccf8e..2e9b14c 100644
60763 --- a/include/linux/firewire.h
60764 +++ b/include/linux/firewire.h
60765 @@ -428,7 +428,7 @@ struct fw_iso_context {
60766 union {
60767 fw_iso_callback_t sc;
60768 fw_iso_mc_callback_t mc;
60769 - } callback;
60770 + } __no_const callback;
60771 void *callback_data;
60772 };
60773
60774 diff --git a/include/linux/fs.h b/include/linux/fs.h
60775 index f4b6e06..d6ba573 100644
60776 --- a/include/linux/fs.h
60777 +++ b/include/linux/fs.h
60778 @@ -1628,7 +1628,8 @@ struct file_operations {
60779 int (*setlease)(struct file *, long, struct file_lock **);
60780 long (*fallocate)(struct file *file, int mode, loff_t offset,
60781 loff_t len);
60782 -};
60783 +} __do_const;
60784 +typedef struct file_operations __no_const file_operations_no_const;
60785
60786 struct inode_operations {
60787 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60788 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60789 index 003dc0f..3c4ea97 100644
60790 --- a/include/linux/fs_struct.h
60791 +++ b/include/linux/fs_struct.h
60792 @@ -6,7 +6,7 @@
60793 #include <linux/seqlock.h>
60794
60795 struct fs_struct {
60796 - int users;
60797 + atomic_t users;
60798 spinlock_t lock;
60799 seqcount_t seq;
60800 int umask;
60801 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60802 index ce31408..b1ad003 100644
60803 --- a/include/linux/fscache-cache.h
60804 +++ b/include/linux/fscache-cache.h
60805 @@ -102,7 +102,7 @@ struct fscache_operation {
60806 fscache_operation_release_t release;
60807 };
60808
60809 -extern atomic_t fscache_op_debug_id;
60810 +extern atomic_unchecked_t fscache_op_debug_id;
60811 extern void fscache_op_work_func(struct work_struct *work);
60812
60813 extern void fscache_enqueue_operation(struct fscache_operation *);
60814 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60815 {
60816 INIT_WORK(&op->work, fscache_op_work_func);
60817 atomic_set(&op->usage, 1);
60818 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60819 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60820 op->processor = processor;
60821 op->release = release;
60822 INIT_LIST_HEAD(&op->pend_link);
60823 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60824 index 2a53f10..0187fdf 100644
60825 --- a/include/linux/fsnotify.h
60826 +++ b/include/linux/fsnotify.h
60827 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60828 */
60829 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60830 {
60831 - return kstrdup(name, GFP_KERNEL);
60832 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60833 }
60834
60835 /*
60836 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60837 index 91d0e0a3..035666b 100644
60838 --- a/include/linux/fsnotify_backend.h
60839 +++ b/include/linux/fsnotify_backend.h
60840 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60841 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60842 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60843 };
60844 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60845
60846 /*
60847 * A group is a "thing" that wants to receive notification about filesystem
60848 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60849 index c3da42d..c70e0df 100644
60850 --- a/include/linux/ftrace_event.h
60851 +++ b/include/linux/ftrace_event.h
60852 @@ -97,7 +97,7 @@ struct trace_event_functions {
60853 trace_print_func raw;
60854 trace_print_func hex;
60855 trace_print_func binary;
60856 -};
60857 +} __no_const;
60858
60859 struct trace_event {
60860 struct hlist_node node;
60861 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60862 extern int trace_add_event_call(struct ftrace_event_call *call);
60863 extern void trace_remove_event_call(struct ftrace_event_call *call);
60864
60865 -#define is_signed_type(type) (((type)(-1)) < 0)
60866 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60867
60868 int trace_set_clr_event(const char *system, const char *event, int set);
60869
60870 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60871 index e61d319..0da8505 100644
60872 --- a/include/linux/genhd.h
60873 +++ b/include/linux/genhd.h
60874 @@ -185,7 +185,7 @@ struct gendisk {
60875 struct kobject *slave_dir;
60876
60877 struct timer_rand_state *random;
60878 - atomic_t sync_io; /* RAID */
60879 + atomic_unchecked_t sync_io; /* RAID */
60880 struct disk_events *ev;
60881 #ifdef CONFIG_BLK_DEV_INTEGRITY
60882 struct blk_integrity *integrity;
60883 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60884 new file mode 100644
60885 index 0000000..8a130b6
60886 --- /dev/null
60887 +++ b/include/linux/gracl.h
60888 @@ -0,0 +1,319 @@
60889 +#ifndef GR_ACL_H
60890 +#define GR_ACL_H
60891 +
60892 +#include <linux/grdefs.h>
60893 +#include <linux/resource.h>
60894 +#include <linux/capability.h>
60895 +#include <linux/dcache.h>
60896 +#include <asm/resource.h>
60897 +
60898 +/* Major status information */
60899 +
60900 +#define GR_VERSION "grsecurity 2.9"
60901 +#define GRSECURITY_VERSION 0x2900
60902 +
60903 +enum {
60904 + GR_SHUTDOWN = 0,
60905 + GR_ENABLE = 1,
60906 + GR_SPROLE = 2,
60907 + GR_RELOAD = 3,
60908 + GR_SEGVMOD = 4,
60909 + GR_STATUS = 5,
60910 + GR_UNSPROLE = 6,
60911 + GR_PASSSET = 7,
60912 + GR_SPROLEPAM = 8,
60913 +};
60914 +
60915 +/* Password setup definitions
60916 + * kernel/grhash.c */
60917 +enum {
60918 + GR_PW_LEN = 128,
60919 + GR_SALT_LEN = 16,
60920 + GR_SHA_LEN = 32,
60921 +};
60922 +
60923 +enum {
60924 + GR_SPROLE_LEN = 64,
60925 +};
60926 +
60927 +enum {
60928 + GR_NO_GLOB = 0,
60929 + GR_REG_GLOB,
60930 + GR_CREATE_GLOB
60931 +};
60932 +
60933 +#define GR_NLIMITS 32
60934 +
60935 +/* Begin Data Structures */
60936 +
60937 +struct sprole_pw {
60938 + unsigned char *rolename;
60939 + unsigned char salt[GR_SALT_LEN];
60940 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60941 +};
60942 +
60943 +struct name_entry {
60944 + __u32 key;
60945 + ino_t inode;
60946 + dev_t device;
60947 + char *name;
60948 + __u16 len;
60949 + __u8 deleted;
60950 + struct name_entry *prev;
60951 + struct name_entry *next;
60952 +};
60953 +
60954 +struct inodev_entry {
60955 + struct name_entry *nentry;
60956 + struct inodev_entry *prev;
60957 + struct inodev_entry *next;
60958 +};
60959 +
60960 +struct acl_role_db {
60961 + struct acl_role_label **r_hash;
60962 + __u32 r_size;
60963 +};
60964 +
60965 +struct inodev_db {
60966 + struct inodev_entry **i_hash;
60967 + __u32 i_size;
60968 +};
60969 +
60970 +struct name_db {
60971 + struct name_entry **n_hash;
60972 + __u32 n_size;
60973 +};
60974 +
60975 +struct crash_uid {
60976 + uid_t uid;
60977 + unsigned long expires;
60978 +};
60979 +
60980 +struct gr_hash_struct {
60981 + void **table;
60982 + void **nametable;
60983 + void *first;
60984 + __u32 table_size;
60985 + __u32 used_size;
60986 + int type;
60987 +};
60988 +
60989 +/* Userspace Grsecurity ACL data structures */
60990 +
60991 +struct acl_subject_label {
60992 + char *filename;
60993 + ino_t inode;
60994 + dev_t device;
60995 + __u32 mode;
60996 + kernel_cap_t cap_mask;
60997 + kernel_cap_t cap_lower;
60998 + kernel_cap_t cap_invert_audit;
60999 +
61000 + struct rlimit res[GR_NLIMITS];
61001 + __u32 resmask;
61002 +
61003 + __u8 user_trans_type;
61004 + __u8 group_trans_type;
61005 + uid_t *user_transitions;
61006 + gid_t *group_transitions;
61007 + __u16 user_trans_num;
61008 + __u16 group_trans_num;
61009 +
61010 + __u32 sock_families[2];
61011 + __u32 ip_proto[8];
61012 + __u32 ip_type;
61013 + struct acl_ip_label **ips;
61014 + __u32 ip_num;
61015 + __u32 inaddr_any_override;
61016 +
61017 + __u32 crashes;
61018 + unsigned long expires;
61019 +
61020 + struct acl_subject_label *parent_subject;
61021 + struct gr_hash_struct *hash;
61022 + struct acl_subject_label *prev;
61023 + struct acl_subject_label *next;
61024 +
61025 + struct acl_object_label **obj_hash;
61026 + __u32 obj_hash_size;
61027 + __u16 pax_flags;
61028 +};
61029 +
61030 +struct role_allowed_ip {
61031 + __u32 addr;
61032 + __u32 netmask;
61033 +
61034 + struct role_allowed_ip *prev;
61035 + struct role_allowed_ip *next;
61036 +};
61037 +
61038 +struct role_transition {
61039 + char *rolename;
61040 +
61041 + struct role_transition *prev;
61042 + struct role_transition *next;
61043 +};
61044 +
61045 +struct acl_role_label {
61046 + char *rolename;
61047 + uid_t uidgid;
61048 + __u16 roletype;
61049 +
61050 + __u16 auth_attempts;
61051 + unsigned long expires;
61052 +
61053 + struct acl_subject_label *root_label;
61054 + struct gr_hash_struct *hash;
61055 +
61056 + struct acl_role_label *prev;
61057 + struct acl_role_label *next;
61058 +
61059 + struct role_transition *transitions;
61060 + struct role_allowed_ip *allowed_ips;
61061 + uid_t *domain_children;
61062 + __u16 domain_child_num;
61063 +
61064 + umode_t umask;
61065 +
61066 + struct acl_subject_label **subj_hash;
61067 + __u32 subj_hash_size;
61068 +};
61069 +
61070 +struct user_acl_role_db {
61071 + struct acl_role_label **r_table;
61072 + __u32 num_pointers; /* Number of allocations to track */
61073 + __u32 num_roles; /* Number of roles */
61074 + __u32 num_domain_children; /* Number of domain children */
61075 + __u32 num_subjects; /* Number of subjects */
61076 + __u32 num_objects; /* Number of objects */
61077 +};
61078 +
61079 +struct acl_object_label {
61080 + char *filename;
61081 + ino_t inode;
61082 + dev_t device;
61083 + __u32 mode;
61084 +
61085 + struct acl_subject_label *nested;
61086 + struct acl_object_label *globbed;
61087 +
61088 + /* next two structures not used */
61089 +
61090 + struct acl_object_label *prev;
61091 + struct acl_object_label *next;
61092 +};
61093 +
61094 +struct acl_ip_label {
61095 + char *iface;
61096 + __u32 addr;
61097 + __u32 netmask;
61098 + __u16 low, high;
61099 + __u8 mode;
61100 + __u32 type;
61101 + __u32 proto[8];
61102 +
61103 + /* next two structures not used */
61104 +
61105 + struct acl_ip_label *prev;
61106 + struct acl_ip_label *next;
61107 +};
61108 +
61109 +struct gr_arg {
61110 + struct user_acl_role_db role_db;
61111 + unsigned char pw[GR_PW_LEN];
61112 + unsigned char salt[GR_SALT_LEN];
61113 + unsigned char sum[GR_SHA_LEN];
61114 + unsigned char sp_role[GR_SPROLE_LEN];
61115 + struct sprole_pw *sprole_pws;
61116 + dev_t segv_device;
61117 + ino_t segv_inode;
61118 + uid_t segv_uid;
61119 + __u16 num_sprole_pws;
61120 + __u16 mode;
61121 +};
61122 +
61123 +struct gr_arg_wrapper {
61124 + struct gr_arg *arg;
61125 + __u32 version;
61126 + __u32 size;
61127 +};
61128 +
61129 +struct subject_map {
61130 + struct acl_subject_label *user;
61131 + struct acl_subject_label *kernel;
61132 + struct subject_map *prev;
61133 + struct subject_map *next;
61134 +};
61135 +
61136 +struct acl_subj_map_db {
61137 + struct subject_map **s_hash;
61138 + __u32 s_size;
61139 +};
61140 +
61141 +/* End Data Structures Section */
61142 +
61143 +/* Hash functions generated by empirical testing by Brad Spengler
61144 + Makes good use of the low bits of the inode. Generally 0-1 times
61145 + in loop for successful match. 0-3 for unsuccessful match.
61146 + Shift/add algorithm with modulus of table size and an XOR*/
61147 +
61148 +static __inline__ unsigned int
61149 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61150 +{
61151 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61152 +}
61153 +
61154 + static __inline__ unsigned int
61155 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61156 +{
61157 + return ((const unsigned long)userp % sz);
61158 +}
61159 +
61160 +static __inline__ unsigned int
61161 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61162 +{
61163 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61164 +}
61165 +
61166 +static __inline__ unsigned int
61167 +nhash(const char *name, const __u16 len, const unsigned int sz)
61168 +{
61169 + return full_name_hash((const unsigned char *)name, len) % sz;
61170 +}
61171 +
61172 +#define FOR_EACH_ROLE_START(role) \
61173 + role = role_list; \
61174 + while (role) {
61175 +
61176 +#define FOR_EACH_ROLE_END(role) \
61177 + role = role->prev; \
61178 + }
61179 +
61180 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61181 + subj = NULL; \
61182 + iter = 0; \
61183 + while (iter < role->subj_hash_size) { \
61184 + if (subj == NULL) \
61185 + subj = role->subj_hash[iter]; \
61186 + if (subj == NULL) { \
61187 + iter++; \
61188 + continue; \
61189 + }
61190 +
61191 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61192 + subj = subj->next; \
61193 + if (subj == NULL) \
61194 + iter++; \
61195 + }
61196 +
61197 +
61198 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61199 + subj = role->hash->first; \
61200 + while (subj != NULL) {
61201 +
61202 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61203 + subj = subj->next; \
61204 + }
61205 +
61206 +#endif
61207 +
61208 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61209 new file mode 100644
61210 index 0000000..323ecf2
61211 --- /dev/null
61212 +++ b/include/linux/gralloc.h
61213 @@ -0,0 +1,9 @@
61214 +#ifndef __GRALLOC_H
61215 +#define __GRALLOC_H
61216 +
61217 +void acl_free_all(void);
61218 +int acl_alloc_stack_init(unsigned long size);
61219 +void *acl_alloc(unsigned long len);
61220 +void *acl_alloc_num(unsigned long num, unsigned long len);
61221 +
61222 +#endif
61223 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61224 new file mode 100644
61225 index 0000000..b30e9bc
61226 --- /dev/null
61227 +++ b/include/linux/grdefs.h
61228 @@ -0,0 +1,140 @@
61229 +#ifndef GRDEFS_H
61230 +#define GRDEFS_H
61231 +
61232 +/* Begin grsecurity status declarations */
61233 +
61234 +enum {
61235 + GR_READY = 0x01,
61236 + GR_STATUS_INIT = 0x00 // disabled state
61237 +};
61238 +
61239 +/* Begin ACL declarations */
61240 +
61241 +/* Role flags */
61242 +
61243 +enum {
61244 + GR_ROLE_USER = 0x0001,
61245 + GR_ROLE_GROUP = 0x0002,
61246 + GR_ROLE_DEFAULT = 0x0004,
61247 + GR_ROLE_SPECIAL = 0x0008,
61248 + GR_ROLE_AUTH = 0x0010,
61249 + GR_ROLE_NOPW = 0x0020,
61250 + GR_ROLE_GOD = 0x0040,
61251 + GR_ROLE_LEARN = 0x0080,
61252 + GR_ROLE_TPE = 0x0100,
61253 + GR_ROLE_DOMAIN = 0x0200,
61254 + GR_ROLE_PAM = 0x0400,
61255 + GR_ROLE_PERSIST = 0x0800
61256 +};
61257 +
61258 +/* ACL Subject and Object mode flags */
61259 +enum {
61260 + GR_DELETED = 0x80000000
61261 +};
61262 +
61263 +/* ACL Object-only mode flags */
61264 +enum {
61265 + GR_READ = 0x00000001,
61266 + GR_APPEND = 0x00000002,
61267 + GR_WRITE = 0x00000004,
61268 + GR_EXEC = 0x00000008,
61269 + GR_FIND = 0x00000010,
61270 + GR_INHERIT = 0x00000020,
61271 + GR_SETID = 0x00000040,
61272 + GR_CREATE = 0x00000080,
61273 + GR_DELETE = 0x00000100,
61274 + GR_LINK = 0x00000200,
61275 + GR_AUDIT_READ = 0x00000400,
61276 + GR_AUDIT_APPEND = 0x00000800,
61277 + GR_AUDIT_WRITE = 0x00001000,
61278 + GR_AUDIT_EXEC = 0x00002000,
61279 + GR_AUDIT_FIND = 0x00004000,
61280 + GR_AUDIT_INHERIT= 0x00008000,
61281 + GR_AUDIT_SETID = 0x00010000,
61282 + GR_AUDIT_CREATE = 0x00020000,
61283 + GR_AUDIT_DELETE = 0x00040000,
61284 + GR_AUDIT_LINK = 0x00080000,
61285 + GR_PTRACERD = 0x00100000,
61286 + GR_NOPTRACE = 0x00200000,
61287 + GR_SUPPRESS = 0x00400000,
61288 + GR_NOLEARN = 0x00800000,
61289 + GR_INIT_TRANSFER= 0x01000000
61290 +};
61291 +
61292 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61293 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61294 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61295 +
61296 +/* ACL subject-only mode flags */
61297 +enum {
61298 + GR_KILL = 0x00000001,
61299 + GR_VIEW = 0x00000002,
61300 + GR_PROTECTED = 0x00000004,
61301 + GR_LEARN = 0x00000008,
61302 + GR_OVERRIDE = 0x00000010,
61303 + /* just a placeholder, this mode is only used in userspace */
61304 + GR_DUMMY = 0x00000020,
61305 + GR_PROTSHM = 0x00000040,
61306 + GR_KILLPROC = 0x00000080,
61307 + GR_KILLIPPROC = 0x00000100,
61308 + /* just a placeholder, this mode is only used in userspace */
61309 + GR_NOTROJAN = 0x00000200,
61310 + GR_PROTPROCFD = 0x00000400,
61311 + GR_PROCACCT = 0x00000800,
61312 + GR_RELAXPTRACE = 0x00001000,
61313 + GR_NESTED = 0x00002000,
61314 + GR_INHERITLEARN = 0x00004000,
61315 + GR_PROCFIND = 0x00008000,
61316 + GR_POVERRIDE = 0x00010000,
61317 + GR_KERNELAUTH = 0x00020000,
61318 + GR_ATSECURE = 0x00040000,
61319 + GR_SHMEXEC = 0x00080000
61320 +};
61321 +
61322 +enum {
61323 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61324 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61325 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61326 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61327 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61328 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61329 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61330 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61331 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61332 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61333 +};
61334 +
61335 +enum {
61336 + GR_ID_USER = 0x01,
61337 + GR_ID_GROUP = 0x02,
61338 +};
61339 +
61340 +enum {
61341 + GR_ID_ALLOW = 0x01,
61342 + GR_ID_DENY = 0x02,
61343 +};
61344 +
61345 +#define GR_CRASH_RES 31
61346 +#define GR_UIDTABLE_MAX 500
61347 +
61348 +/* begin resource learning section */
61349 +enum {
61350 + GR_RLIM_CPU_BUMP = 60,
61351 + GR_RLIM_FSIZE_BUMP = 50000,
61352 + GR_RLIM_DATA_BUMP = 10000,
61353 + GR_RLIM_STACK_BUMP = 1000,
61354 + GR_RLIM_CORE_BUMP = 10000,
61355 + GR_RLIM_RSS_BUMP = 500000,
61356 + GR_RLIM_NPROC_BUMP = 1,
61357 + GR_RLIM_NOFILE_BUMP = 5,
61358 + GR_RLIM_MEMLOCK_BUMP = 50000,
61359 + GR_RLIM_AS_BUMP = 500000,
61360 + GR_RLIM_LOCKS_BUMP = 2,
61361 + GR_RLIM_SIGPENDING_BUMP = 5,
61362 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61363 + GR_RLIM_NICE_BUMP = 1,
61364 + GR_RLIM_RTPRIO_BUMP = 1,
61365 + GR_RLIM_RTTIME_BUMP = 1000000
61366 +};
61367 +
61368 +#endif
61369 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61370 new file mode 100644
61371 index 0000000..da390f1
61372 --- /dev/null
61373 +++ b/include/linux/grinternal.h
61374 @@ -0,0 +1,221 @@
61375 +#ifndef __GRINTERNAL_H
61376 +#define __GRINTERNAL_H
61377 +
61378 +#ifdef CONFIG_GRKERNSEC
61379 +
61380 +#include <linux/fs.h>
61381 +#include <linux/mnt_namespace.h>
61382 +#include <linux/nsproxy.h>
61383 +#include <linux/gracl.h>
61384 +#include <linux/grdefs.h>
61385 +#include <linux/grmsg.h>
61386 +
61387 +void gr_add_learn_entry(const char *fmt, ...)
61388 + __attribute__ ((format (printf, 1, 2)));
61389 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61390 + const struct vfsmount *mnt);
61391 +__u32 gr_check_create(const struct dentry *new_dentry,
61392 + const struct dentry *parent,
61393 + const struct vfsmount *mnt, const __u32 mode);
61394 +int gr_check_protected_task(const struct task_struct *task);
61395 +__u32 to_gr_audit(const __u32 reqmode);
61396 +int gr_set_acls(const int type);
61397 +int gr_apply_subject_to_task(struct task_struct *task);
61398 +int gr_acl_is_enabled(void);
61399 +char gr_roletype_to_char(void);
61400 +
61401 +void gr_handle_alertkill(struct task_struct *task);
61402 +char *gr_to_filename(const struct dentry *dentry,
61403 + const struct vfsmount *mnt);
61404 +char *gr_to_filename1(const struct dentry *dentry,
61405 + const struct vfsmount *mnt);
61406 +char *gr_to_filename2(const struct dentry *dentry,
61407 + const struct vfsmount *mnt);
61408 +char *gr_to_filename3(const struct dentry *dentry,
61409 + const struct vfsmount *mnt);
61410 +
61411 +extern int grsec_enable_ptrace_readexec;
61412 +extern int grsec_enable_harden_ptrace;
61413 +extern int grsec_enable_link;
61414 +extern int grsec_enable_fifo;
61415 +extern int grsec_enable_execve;
61416 +extern int grsec_enable_shm;
61417 +extern int grsec_enable_execlog;
61418 +extern int grsec_enable_signal;
61419 +extern int grsec_enable_audit_ptrace;
61420 +extern int grsec_enable_forkfail;
61421 +extern int grsec_enable_time;
61422 +extern int grsec_enable_rofs;
61423 +extern int grsec_enable_chroot_shmat;
61424 +extern int grsec_enable_chroot_mount;
61425 +extern int grsec_enable_chroot_double;
61426 +extern int grsec_enable_chroot_pivot;
61427 +extern int grsec_enable_chroot_chdir;
61428 +extern int grsec_enable_chroot_chmod;
61429 +extern int grsec_enable_chroot_mknod;
61430 +extern int grsec_enable_chroot_fchdir;
61431 +extern int grsec_enable_chroot_nice;
61432 +extern int grsec_enable_chroot_execlog;
61433 +extern int grsec_enable_chroot_caps;
61434 +extern int grsec_enable_chroot_sysctl;
61435 +extern int grsec_enable_chroot_unix;
61436 +extern int grsec_enable_tpe;
61437 +extern int grsec_tpe_gid;
61438 +extern int grsec_enable_tpe_all;
61439 +extern int grsec_enable_tpe_invert;
61440 +extern int grsec_enable_socket_all;
61441 +extern int grsec_socket_all_gid;
61442 +extern int grsec_enable_socket_client;
61443 +extern int grsec_socket_client_gid;
61444 +extern int grsec_enable_socket_server;
61445 +extern int grsec_socket_server_gid;
61446 +extern int grsec_audit_gid;
61447 +extern int grsec_enable_group;
61448 +extern int grsec_enable_audit_textrel;
61449 +extern int grsec_enable_log_rwxmaps;
61450 +extern int grsec_enable_mount;
61451 +extern int grsec_enable_chdir;
61452 +extern int grsec_resource_logging;
61453 +extern int grsec_enable_blackhole;
61454 +extern int grsec_lastack_retries;
61455 +extern int grsec_enable_brute;
61456 +extern int grsec_lock;
61457 +
61458 +extern spinlock_t grsec_alert_lock;
61459 +extern unsigned long grsec_alert_wtime;
61460 +extern unsigned long grsec_alert_fyet;
61461 +
61462 +extern spinlock_t grsec_audit_lock;
61463 +
61464 +extern rwlock_t grsec_exec_file_lock;
61465 +
61466 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61467 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61468 + (tsk)->exec_file->f_vfsmnt) : "/")
61469 +
61470 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61471 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61472 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61473 +
61474 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61475 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61476 + (tsk)->exec_file->f_vfsmnt) : "/")
61477 +
61478 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61479 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61480 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61481 +
61482 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61483 +
61484 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61485 +
61486 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61487 + (task)->pid, (cred)->uid, \
61488 + (cred)->euid, (cred)->gid, (cred)->egid, \
61489 + gr_parent_task_fullpath(task), \
61490 + (task)->real_parent->comm, (task)->real_parent->pid, \
61491 + (pcred)->uid, (pcred)->euid, \
61492 + (pcred)->gid, (pcred)->egid
61493 +
61494 +#define GR_CHROOT_CAPS {{ \
61495 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61496 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61497 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61498 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61499 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61500 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61501 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61502 +
61503 +#define security_learn(normal_msg,args...) \
61504 +({ \
61505 + read_lock(&grsec_exec_file_lock); \
61506 + gr_add_learn_entry(normal_msg "\n", ## args); \
61507 + read_unlock(&grsec_exec_file_lock); \
61508 +})
61509 +
61510 +enum {
61511 + GR_DO_AUDIT,
61512 + GR_DONT_AUDIT,
61513 + /* used for non-audit messages that we shouldn't kill the task on */
61514 + GR_DONT_AUDIT_GOOD
61515 +};
61516 +
61517 +enum {
61518 + GR_TTYSNIFF,
61519 + GR_RBAC,
61520 + GR_RBAC_STR,
61521 + GR_STR_RBAC,
61522 + GR_RBAC_MODE2,
61523 + GR_RBAC_MODE3,
61524 + GR_FILENAME,
61525 + GR_SYSCTL_HIDDEN,
61526 + GR_NOARGS,
61527 + GR_ONE_INT,
61528 + GR_ONE_INT_TWO_STR,
61529 + GR_ONE_STR,
61530 + GR_STR_INT,
61531 + GR_TWO_STR_INT,
61532 + GR_TWO_INT,
61533 + GR_TWO_U64,
61534 + GR_THREE_INT,
61535 + GR_FIVE_INT_TWO_STR,
61536 + GR_TWO_STR,
61537 + GR_THREE_STR,
61538 + GR_FOUR_STR,
61539 + GR_STR_FILENAME,
61540 + GR_FILENAME_STR,
61541 + GR_FILENAME_TWO_INT,
61542 + GR_FILENAME_TWO_INT_STR,
61543 + GR_TEXTREL,
61544 + GR_PTRACE,
61545 + GR_RESOURCE,
61546 + GR_CAP,
61547 + GR_SIG,
61548 + GR_SIG2,
61549 + GR_CRASH1,
61550 + GR_CRASH2,
61551 + GR_PSACCT,
61552 + GR_RWXMAP
61553 +};
61554 +
61555 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61556 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61557 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61558 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61559 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61560 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61561 +#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)
61562 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61563 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61564 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61565 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61566 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61567 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61568 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61569 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61570 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61571 +#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)
61572 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61573 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61574 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61575 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61576 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61577 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61578 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61579 +#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)
61580 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61581 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61582 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61583 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61584 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61585 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61586 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61587 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61588 +#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)
61589 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61590 +
61591 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61592 +
61593 +#endif
61594 +
61595 +#endif
61596 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61597 new file mode 100644
61598 index 0000000..ae576a1
61599 --- /dev/null
61600 +++ b/include/linux/grmsg.h
61601 @@ -0,0 +1,109 @@
61602 +#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"
61603 +#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"
61604 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61605 +#define GR_STOPMOD_MSG "denied modification of module state by "
61606 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61607 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61608 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61609 +#define GR_IOPL_MSG "denied use of iopl() by "
61610 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61611 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61612 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61613 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61614 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61615 +#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"
61616 +#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"
61617 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61618 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61619 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61620 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61621 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61622 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61623 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61624 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61625 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61626 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61627 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61628 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61629 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61630 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61631 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61632 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61633 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61634 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61635 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61636 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61637 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61638 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61639 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61640 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61641 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61642 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61643 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61644 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61645 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61646 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61647 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61648 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61649 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61650 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61651 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61652 +#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"
61653 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61654 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61655 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61656 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61657 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61658 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61659 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61660 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61661 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61662 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61663 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61664 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61665 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61666 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61667 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61668 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61669 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61670 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61671 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61672 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61673 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61674 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61675 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61676 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61677 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61678 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61679 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61680 +#define GR_TIME_MSG "time set by "
61681 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61682 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61683 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61684 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61685 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61686 +#define GR_BIND_MSG "denied bind() by "
61687 +#define GR_CONNECT_MSG "denied connect() by "
61688 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61689 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61690 +#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"
61691 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61692 +#define GR_CAP_ACL_MSG "use of %s denied for "
61693 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61694 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61695 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61696 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61697 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61698 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61699 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61700 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61701 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61702 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61703 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61704 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61705 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61706 +#define GR_VM86_MSG "denied use of vm86 by "
61707 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61708 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61709 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61710 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61711 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61712 new file mode 100644
61713 index 0000000..acd05db
61714 --- /dev/null
61715 +++ b/include/linux/grsecurity.h
61716 @@ -0,0 +1,232 @@
61717 +#ifndef GR_SECURITY_H
61718 +#define GR_SECURITY_H
61719 +#include <linux/fs.h>
61720 +#include <linux/fs_struct.h>
61721 +#include <linux/binfmts.h>
61722 +#include <linux/gracl.h>
61723 +
61724 +/* notify of brain-dead configs */
61725 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61726 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61727 +#endif
61728 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61729 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61730 +#endif
61731 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61732 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61733 +#endif
61734 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61735 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61736 +#endif
61737 +
61738 +#include <linux/compat.h>
61739 +
61740 +struct user_arg_ptr {
61741 +#ifdef CONFIG_COMPAT
61742 + bool is_compat;
61743 +#endif
61744 + union {
61745 + const char __user *const __user *native;
61746 +#ifdef CONFIG_COMPAT
61747 + compat_uptr_t __user *compat;
61748 +#endif
61749 + } ptr;
61750 +};
61751 +
61752 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61753 +void gr_handle_brute_check(void);
61754 +void gr_handle_kernel_exploit(void);
61755 +int gr_process_user_ban(void);
61756 +
61757 +char gr_roletype_to_char(void);
61758 +
61759 +int gr_acl_enable_at_secure(void);
61760 +
61761 +int gr_check_user_change(int real, int effective, int fs);
61762 +int gr_check_group_change(int real, int effective, int fs);
61763 +
61764 +void gr_del_task_from_ip_table(struct task_struct *p);
61765 +
61766 +int gr_pid_is_chrooted(struct task_struct *p);
61767 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61768 +int gr_handle_chroot_nice(void);
61769 +int gr_handle_chroot_sysctl(const int op);
61770 +int gr_handle_chroot_setpriority(struct task_struct *p,
61771 + const int niceval);
61772 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61773 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61774 + const struct vfsmount *mnt);
61775 +void gr_handle_chroot_chdir(struct path *path);
61776 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61777 + const struct vfsmount *mnt, const int mode);
61778 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61779 + const struct vfsmount *mnt, const int mode);
61780 +int gr_handle_chroot_mount(const struct dentry *dentry,
61781 + const struct vfsmount *mnt,
61782 + const char *dev_name);
61783 +int gr_handle_chroot_pivot(void);
61784 +int gr_handle_chroot_unix(const pid_t pid);
61785 +
61786 +int gr_handle_rawio(const struct inode *inode);
61787 +
61788 +void gr_handle_ioperm(void);
61789 +void gr_handle_iopl(void);
61790 +
61791 +umode_t gr_acl_umask(void);
61792 +
61793 +int gr_tpe_allow(const struct file *file);
61794 +
61795 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61796 +void gr_clear_chroot_entries(struct task_struct *task);
61797 +
61798 +void gr_log_forkfail(const int retval);
61799 +void gr_log_timechange(void);
61800 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61801 +void gr_log_chdir(const struct dentry *dentry,
61802 + const struct vfsmount *mnt);
61803 +void gr_log_chroot_exec(const struct dentry *dentry,
61804 + const struct vfsmount *mnt);
61805 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61806 +void gr_log_remount(const char *devname, const int retval);
61807 +void gr_log_unmount(const char *devname, const int retval);
61808 +void gr_log_mount(const char *from, const char *to, const int retval);
61809 +void gr_log_textrel(struct vm_area_struct *vma);
61810 +void gr_log_rwxmmap(struct file *file);
61811 +void gr_log_rwxmprotect(struct file *file);
61812 +
61813 +int gr_handle_follow_link(const struct inode *parent,
61814 + const struct inode *inode,
61815 + const struct dentry *dentry,
61816 + const struct vfsmount *mnt);
61817 +int gr_handle_fifo(const struct dentry *dentry,
61818 + const struct vfsmount *mnt,
61819 + const struct dentry *dir, const int flag,
61820 + const int acc_mode);
61821 +int gr_handle_hardlink(const struct dentry *dentry,
61822 + const struct vfsmount *mnt,
61823 + struct inode *inode,
61824 + const int mode, const char *to);
61825 +
61826 +int gr_is_capable(const int cap);
61827 +int gr_is_capable_nolog(const int cap);
61828 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61829 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61830 +
61831 +void gr_learn_resource(const struct task_struct *task, const int limit,
61832 + const unsigned long wanted, const int gt);
61833 +void gr_copy_label(struct task_struct *tsk);
61834 +void gr_handle_crash(struct task_struct *task, const int sig);
61835 +int gr_handle_signal(const struct task_struct *p, const int sig);
61836 +int gr_check_crash_uid(const uid_t uid);
61837 +int gr_check_protected_task(const struct task_struct *task);
61838 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61839 +int gr_acl_handle_mmap(const struct file *file,
61840 + const unsigned long prot);
61841 +int gr_acl_handle_mprotect(const struct file *file,
61842 + const unsigned long prot);
61843 +int gr_check_hidden_task(const struct task_struct *tsk);
61844 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61845 + const struct vfsmount *mnt);
61846 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61847 + const struct vfsmount *mnt);
61848 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61849 + const struct vfsmount *mnt, const int fmode);
61850 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61851 + const struct vfsmount *mnt, umode_t *mode);
61852 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61853 + const struct vfsmount *mnt);
61854 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61855 + const struct vfsmount *mnt);
61856 +int gr_handle_ptrace(struct task_struct *task, const long request);
61857 +int gr_handle_proc_ptrace(struct task_struct *task);
61858 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61859 + const struct vfsmount *mnt);
61860 +int gr_check_crash_exec(const struct file *filp);
61861 +int gr_acl_is_enabled(void);
61862 +void gr_set_kernel_label(struct task_struct *task);
61863 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61864 + const gid_t gid);
61865 +int gr_set_proc_label(const struct dentry *dentry,
61866 + const struct vfsmount *mnt,
61867 + const int unsafe_flags);
61868 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61869 + const struct vfsmount *mnt);
61870 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61871 + const struct vfsmount *mnt, int acc_mode);
61872 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61873 + const struct dentry *p_dentry,
61874 + const struct vfsmount *p_mnt,
61875 + int open_flags, int acc_mode, const int imode);
61876 +void gr_handle_create(const struct dentry *dentry,
61877 + const struct vfsmount *mnt);
61878 +void gr_handle_proc_create(const struct dentry *dentry,
61879 + const struct inode *inode);
61880 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61881 + const struct dentry *parent_dentry,
61882 + const struct vfsmount *parent_mnt,
61883 + const int mode);
61884 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61885 + const struct dentry *parent_dentry,
61886 + const struct vfsmount *parent_mnt);
61887 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61888 + const struct vfsmount *mnt);
61889 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61890 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61891 + const struct vfsmount *mnt);
61892 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61893 + const struct dentry *parent_dentry,
61894 + const struct vfsmount *parent_mnt,
61895 + const char *from);
61896 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61897 + const struct dentry *parent_dentry,
61898 + const struct vfsmount *parent_mnt,
61899 + const struct dentry *old_dentry,
61900 + const struct vfsmount *old_mnt, const char *to);
61901 +int gr_acl_handle_rename(struct dentry *new_dentry,
61902 + struct dentry *parent_dentry,
61903 + const struct vfsmount *parent_mnt,
61904 + struct dentry *old_dentry,
61905 + struct inode *old_parent_inode,
61906 + struct vfsmount *old_mnt, const char *newname);
61907 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61908 + struct dentry *old_dentry,
61909 + struct dentry *new_dentry,
61910 + struct vfsmount *mnt, const __u8 replace);
61911 +__u32 gr_check_link(const struct dentry *new_dentry,
61912 + const struct dentry *parent_dentry,
61913 + const struct vfsmount *parent_mnt,
61914 + const struct dentry *old_dentry,
61915 + const struct vfsmount *old_mnt);
61916 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61917 + const unsigned int namelen, const ino_t ino);
61918 +
61919 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61920 + const struct vfsmount *mnt);
61921 +void gr_acl_handle_exit(void);
61922 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61923 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61924 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61925 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61926 +void gr_audit_ptrace(struct task_struct *task);
61927 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61928 +
61929 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61930 +
61931 +#ifdef CONFIG_GRKERNSEC
61932 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61933 +void gr_handle_vm86(void);
61934 +void gr_handle_mem_readwrite(u64 from, u64 to);
61935 +
61936 +void gr_log_badprocpid(const char *entry);
61937 +
61938 +extern int grsec_enable_dmesg;
61939 +extern int grsec_disable_privio;
61940 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61941 +extern int grsec_enable_chroot_findtask;
61942 +#endif
61943 +#ifdef CONFIG_GRKERNSEC_SETXID
61944 +extern int grsec_enable_setxid;
61945 +#endif
61946 +#endif
61947 +
61948 +#endif
61949 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61950 new file mode 100644
61951 index 0000000..e7ffaaf
61952 --- /dev/null
61953 +++ b/include/linux/grsock.h
61954 @@ -0,0 +1,19 @@
61955 +#ifndef __GRSOCK_H
61956 +#define __GRSOCK_H
61957 +
61958 +extern void gr_attach_curr_ip(const struct sock *sk);
61959 +extern int gr_handle_sock_all(const int family, const int type,
61960 + const int protocol);
61961 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61962 +extern int gr_handle_sock_server_other(const struct sock *sck);
61963 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61964 +extern int gr_search_connect(struct socket * sock,
61965 + struct sockaddr_in * addr);
61966 +extern int gr_search_bind(struct socket * sock,
61967 + struct sockaddr_in * addr);
61968 +extern int gr_search_listen(struct socket * sock);
61969 +extern int gr_search_accept(struct socket * sock);
61970 +extern int gr_search_socket(const int domain, const int type,
61971 + const int protocol);
61972 +
61973 +#endif
61974 diff --git a/include/linux/hid.h b/include/linux/hid.h
61975 index 3a95da6..51986f1 100644
61976 --- a/include/linux/hid.h
61977 +++ b/include/linux/hid.h
61978 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61979 unsigned int code, int value);
61980
61981 int (*parse)(struct hid_device *hdev);
61982 -};
61983 +} __no_const;
61984
61985 #define PM_HINT_FULLON 1<<5
61986 #define PM_HINT_NORMAL 1<<1
61987 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61988 index 3a93f73..b19d0b3 100644
61989 --- a/include/linux/highmem.h
61990 +++ b/include/linux/highmem.h
61991 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61992 kunmap_atomic(kaddr, KM_USER0);
61993 }
61994
61995 +static inline void sanitize_highpage(struct page *page)
61996 +{
61997 + void *kaddr;
61998 + unsigned long flags;
61999 +
62000 + local_irq_save(flags);
62001 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
62002 + clear_page(kaddr);
62003 + kunmap_atomic(kaddr, KM_CLEARPAGE);
62004 + local_irq_restore(flags);
62005 +}
62006 +
62007 static inline void zero_user_segments(struct page *page,
62008 unsigned start1, unsigned end1,
62009 unsigned start2, unsigned end2)
62010 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62011 index 8e25a91..551b161 100644
62012 --- a/include/linux/i2c.h
62013 +++ b/include/linux/i2c.h
62014 @@ -364,6 +364,7 @@ struct i2c_algorithm {
62015 /* To determine what the adapter supports */
62016 u32 (*functionality) (struct i2c_adapter *);
62017 };
62018 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62019
62020 /*
62021 * i2c_adapter is the structure used to identify a physical i2c bus along
62022 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62023 index a6deef4..c56a7f2 100644
62024 --- a/include/linux/i2o.h
62025 +++ b/include/linux/i2o.h
62026 @@ -564,7 +564,7 @@ struct i2o_controller {
62027 struct i2o_device *exec; /* Executive */
62028 #if BITS_PER_LONG == 64
62029 spinlock_t context_list_lock; /* lock for context_list */
62030 - atomic_t context_list_counter; /* needed for unique contexts */
62031 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62032 struct list_head context_list; /* list of context id's
62033 and pointers */
62034 #endif
62035 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62036 index 58404b0..439ed95 100644
62037 --- a/include/linux/if_team.h
62038 +++ b/include/linux/if_team.h
62039 @@ -64,6 +64,7 @@ struct team_mode_ops {
62040 void (*port_leave)(struct team *team, struct team_port *port);
62041 void (*port_change_mac)(struct team *team, struct team_port *port);
62042 };
62043 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62044
62045 enum team_option_type {
62046 TEAM_OPTION_TYPE_U32,
62047 @@ -112,7 +113,7 @@ struct team {
62048 struct list_head option_list;
62049
62050 const struct team_mode *mode;
62051 - struct team_mode_ops ops;
62052 + team_mode_ops_no_const ops;
62053 long mode_priv[TEAM_MODE_PRIV_LONGS];
62054 };
62055
62056 diff --git a/include/linux/init.h b/include/linux/init.h
62057 index 6b95109..4aca62c 100644
62058 --- a/include/linux/init.h
62059 +++ b/include/linux/init.h
62060 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
62061
62062 /* Each module must use one module_init(). */
62063 #define module_init(initfn) \
62064 - static inline initcall_t __inittest(void) \
62065 + static inline __used initcall_t __inittest(void) \
62066 { return initfn; } \
62067 int init_module(void) __attribute__((alias(#initfn)));
62068
62069 /* This is only required if you want to be unloadable. */
62070 #define module_exit(exitfn) \
62071 - static inline exitcall_t __exittest(void) \
62072 + static inline __used exitcall_t __exittest(void) \
62073 { return exitfn; } \
62074 void cleanup_module(void) __attribute__((alias(#exitfn)));
62075
62076 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62077 index 9c66b1a..a3fdded 100644
62078 --- a/include/linux/init_task.h
62079 +++ b/include/linux/init_task.h
62080 @@ -127,6 +127,12 @@ extern struct cred init_cred;
62081
62082 #define INIT_TASK_COMM "swapper"
62083
62084 +#ifdef CONFIG_X86
62085 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62086 +#else
62087 +#define INIT_TASK_THREAD_INFO
62088 +#endif
62089 +
62090 /*
62091 * INIT_TASK is used to set up the first task table, touch at
62092 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62093 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62094 RCU_INIT_POINTER(.cred, &init_cred), \
62095 .comm = INIT_TASK_COMM, \
62096 .thread = INIT_THREAD, \
62097 + INIT_TASK_THREAD_INFO \
62098 .fs = &init_fs, \
62099 .files = &init_files, \
62100 .signal = &init_signals, \
62101 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62102 index e6ca56d..8583707 100644
62103 --- a/include/linux/intel-iommu.h
62104 +++ b/include/linux/intel-iommu.h
62105 @@ -296,7 +296,7 @@ struct iommu_flush {
62106 u8 fm, u64 type);
62107 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62108 unsigned int size_order, u64 type);
62109 -};
62110 +} __no_const;
62111
62112 enum {
62113 SR_DMAR_FECTL_REG,
62114 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62115 index a64b00e..464d8bc 100644
62116 --- a/include/linux/interrupt.h
62117 +++ b/include/linux/interrupt.h
62118 @@ -441,7 +441,7 @@ enum
62119 /* map softirq index to softirq name. update 'softirq_to_name' in
62120 * kernel/softirq.c when adding a new softirq.
62121 */
62122 -extern char *softirq_to_name[NR_SOFTIRQS];
62123 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62124
62125 /* softirq mask and active fields moved to irq_cpustat_t in
62126 * asm/hardirq.h to get better cache usage. KAO
62127 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62128
62129 struct softirq_action
62130 {
62131 - void (*action)(struct softirq_action *);
62132 + void (*action)(void);
62133 };
62134
62135 asmlinkage void do_softirq(void);
62136 asmlinkage void __do_softirq(void);
62137 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62138 +extern void open_softirq(int nr, void (*action)(void));
62139 extern void softirq_init(void);
62140 static inline void __raise_softirq_irqoff(unsigned int nr)
62141 {
62142 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62143 index 3875719..4cd454c 100644
62144 --- a/include/linux/kallsyms.h
62145 +++ b/include/linux/kallsyms.h
62146 @@ -15,7 +15,8 @@
62147
62148 struct module;
62149
62150 -#ifdef CONFIG_KALLSYMS
62151 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62152 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62153 /* Lookup the address for a symbol. Returns 0 if not found. */
62154 unsigned long kallsyms_lookup_name(const char *name);
62155
62156 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62157 /* Stupid that this does nothing, but I didn't create this mess. */
62158 #define __print_symbol(fmt, addr)
62159 #endif /*CONFIG_KALLSYMS*/
62160 +#else /* when included by kallsyms.c, vsnprintf.c, or
62161 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62162 +extern void __print_symbol(const char *fmt, unsigned long address);
62163 +extern int sprint_backtrace(char *buffer, unsigned long address);
62164 +extern int sprint_symbol(char *buffer, unsigned long address);
62165 +const char *kallsyms_lookup(unsigned long addr,
62166 + unsigned long *symbolsize,
62167 + unsigned long *offset,
62168 + char **modname, char *namebuf);
62169 +#endif
62170
62171 /* This macro allows us to keep printk typechecking */
62172 static __printf(1, 2)
62173 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62174 index c4d2fc1..5df9c19 100644
62175 --- a/include/linux/kgdb.h
62176 +++ b/include/linux/kgdb.h
62177 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62178 extern int kgdb_io_module_registered;
62179
62180 extern atomic_t kgdb_setting_breakpoint;
62181 -extern atomic_t kgdb_cpu_doing_single_step;
62182 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62183
62184 extern struct task_struct *kgdb_usethread;
62185 extern struct task_struct *kgdb_contthread;
62186 @@ -252,7 +252,7 @@ struct kgdb_arch {
62187 void (*disable_hw_break)(struct pt_regs *regs);
62188 void (*remove_all_hw_break)(void);
62189 void (*correct_hw_break)(void);
62190 -};
62191 +} __do_const;
62192
62193 /**
62194 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62195 @@ -277,7 +277,7 @@ struct kgdb_io {
62196 void (*pre_exception) (void);
62197 void (*post_exception) (void);
62198 int is_console;
62199 -};
62200 +} __do_const;
62201
62202 extern struct kgdb_arch arch_kgdb_ops;
62203
62204 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62205 index 0fb48ef..1b680b2 100644
62206 --- a/include/linux/kmod.h
62207 +++ b/include/linux/kmod.h
62208 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62209 * usually useless though. */
62210 extern __printf(2, 3)
62211 int __request_module(bool wait, const char *name, ...);
62212 +extern __printf(3, 4)
62213 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62214 #define request_module(mod...) __request_module(true, mod)
62215 #define request_module_nowait(mod...) __request_module(false, mod)
62216 #define try_then_request_module(x, mod...) \
62217 diff --git a/include/linux/kref.h b/include/linux/kref.h
62218 index 9c07dce..a92fa71 100644
62219 --- a/include/linux/kref.h
62220 +++ b/include/linux/kref.h
62221 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62222 static inline int kref_sub(struct kref *kref, unsigned int count,
62223 void (*release)(struct kref *kref))
62224 {
62225 - WARN_ON(release == NULL);
62226 + BUG_ON(release == NULL);
62227
62228 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62229 release(kref);
62230 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62231 index 900c763..098aefa 100644
62232 --- a/include/linux/kvm_host.h
62233 +++ b/include/linux/kvm_host.h
62234 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62235 void vcpu_load(struct kvm_vcpu *vcpu);
62236 void vcpu_put(struct kvm_vcpu *vcpu);
62237
62238 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62239 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62240 struct module *module);
62241 void kvm_exit(void);
62242
62243 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
62244 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62245 int len);
62246 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62247 - unsigned long len);
62248 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62249 + unsigned long len) __size_overflow(4);
62250 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62251 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62252 - void *data, unsigned long len);
62253 + void *data, unsigned long len) __size_overflow(4);
62254 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62255 int offset, int len);
62256 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62257 - unsigned long len);
62258 + unsigned long len) __size_overflow(2,4);
62259 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62260 - void *data, unsigned long len);
62261 + void *data, unsigned long len) __size_overflow(4);
62262 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62263 gpa_t gpa);
62264 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62265 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62266 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62267 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62268 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62269 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62270 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62271 struct kvm_guest_debug *dbg);
62272 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62273
62274 -int kvm_arch_init(void *opaque);
62275 +int kvm_arch_init(const void *opaque);
62276 void kvm_arch_exit(void);
62277
62278 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62279 @@ -593,6 +593,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
62280
62281 #ifdef CONFIG_IOMMU_API
62282 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
62283 +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
62284 int kvm_iommu_map_guest(struct kvm *kvm);
62285 int kvm_iommu_unmap_guest(struct kvm *kvm);
62286 int kvm_assign_device(struct kvm *kvm,
62287 @@ -606,6 +607,11 @@ static inline int kvm_iommu_map_pages(struct kvm *kvm,
62288 return 0;
62289 }
62290
62291 +static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
62292 + struct kvm_memory_slot *slot)
62293 +{
62294 +}
62295 +
62296 static inline int kvm_iommu_map_guest(struct kvm *kvm)
62297 {
62298 return -ENODEV;
62299 @@ -721,7 +727,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62300 int kvm_set_irq_routing(struct kvm *kvm,
62301 const struct kvm_irq_routing_entry *entries,
62302 unsigned nr,
62303 - unsigned flags);
62304 + unsigned flags) __size_overflow(3);
62305 void kvm_free_irq_routing(struct kvm *kvm);
62306
62307 #else
62308 diff --git a/include/linux/libata.h b/include/linux/libata.h
62309 index cafc09a..d7e7829 100644
62310 --- a/include/linux/libata.h
62311 +++ b/include/linux/libata.h
62312 @@ -909,7 +909,7 @@ struct ata_port_operations {
62313 * fields must be pointers.
62314 */
62315 const struct ata_port_operations *inherits;
62316 -};
62317 +} __do_const;
62318
62319 struct ata_port_info {
62320 unsigned long flags;
62321 diff --git a/include/linux/mca.h b/include/linux/mca.h
62322 index 3797270..7765ede 100644
62323 --- a/include/linux/mca.h
62324 +++ b/include/linux/mca.h
62325 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62326 int region);
62327 void * (*mca_transform_memory)(struct mca_device *,
62328 void *memory);
62329 -};
62330 +} __no_const;
62331
62332 struct mca_bus {
62333 u64 default_dma_mask;
62334 diff --git a/include/linux/memory.h b/include/linux/memory.h
62335 index 1ac7f6e..a5794d0 100644
62336 --- a/include/linux/memory.h
62337 +++ b/include/linux/memory.h
62338 @@ -143,7 +143,7 @@ struct memory_accessor {
62339 size_t count);
62340 ssize_t (*write)(struct memory_accessor *, const char *buf,
62341 off_t offset, size_t count);
62342 -};
62343 +} __no_const;
62344
62345 /*
62346 * Kernel text modification mutex, used for code patching. Users of this lock
62347 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62348 index 9970337..9444122 100644
62349 --- a/include/linux/mfd/abx500.h
62350 +++ b/include/linux/mfd/abx500.h
62351 @@ -188,6 +188,7 @@ struct abx500_ops {
62352 int (*event_registers_startup_state_get) (struct device *, u8 *);
62353 int (*startup_irq_enabled) (struct device *, unsigned int);
62354 };
62355 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62356
62357 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62358 void abx500_remove_ops(struct device *dev);
62359 diff --git a/include/linux/mm.h b/include/linux/mm.h
62360 index 17b27cd..467ba2f 100644
62361 --- a/include/linux/mm.h
62362 +++ b/include/linux/mm.h
62363 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62364
62365 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62366 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62367 +
62368 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62369 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62370 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62371 +#else
62372 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62373 +#endif
62374 +
62375 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62376 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62377
62378 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62379 int set_page_dirty_lock(struct page *page);
62380 int clear_page_dirty_for_io(struct page *page);
62381
62382 -/* Is the vma a continuation of the stack vma above it? */
62383 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62384 -{
62385 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62386 -}
62387 -
62388 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62389 - unsigned long addr)
62390 -{
62391 - return (vma->vm_flags & VM_GROWSDOWN) &&
62392 - (vma->vm_start == addr) &&
62393 - !vma_growsdown(vma->vm_prev, addr);
62394 -}
62395 -
62396 -/* Is the vma a continuation of the stack vma below it? */
62397 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62398 -{
62399 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62400 -}
62401 -
62402 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62403 - unsigned long addr)
62404 -{
62405 - return (vma->vm_flags & VM_GROWSUP) &&
62406 - (vma->vm_end == addr) &&
62407 - !vma_growsup(vma->vm_next, addr);
62408 -}
62409 -
62410 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62411 unsigned long old_addr, struct vm_area_struct *new_vma,
62412 unsigned long new_addr, unsigned long len);
62413 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62414 }
62415 #endif
62416
62417 +#ifdef CONFIG_MMU
62418 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62419 +#else
62420 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62421 +{
62422 + return __pgprot(0);
62423 +}
62424 +#endif
62425 +
62426 int vma_wants_writenotify(struct vm_area_struct *vma);
62427
62428 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62429 @@ -1409,6 +1397,7 @@ out:
62430 }
62431
62432 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62433 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62434
62435 extern unsigned long do_brk(unsigned long, unsigned long);
62436
62437 @@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62438 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62439 struct vm_area_struct **pprev);
62440
62441 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62442 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62443 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62444 +
62445 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62446 NULL if none. Assume start_addr < end_addr. */
62447 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62448 @@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62449 return vma;
62450 }
62451
62452 -#ifdef CONFIG_MMU
62453 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62454 -#else
62455 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62456 -{
62457 - return __pgprot(0);
62458 -}
62459 -#endif
62460 -
62461 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62462 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62463 unsigned long pfn, unsigned long size, pgprot_t);
62464 @@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
62465 extern int sysctl_memory_failure_early_kill;
62466 extern int sysctl_memory_failure_recovery;
62467 extern void shake_page(struct page *p, int access);
62468 -extern atomic_long_t mce_bad_pages;
62469 +extern atomic_long_unchecked_t mce_bad_pages;
62470 extern int soft_offline_page(struct page *page, int flags);
62471
62472 extern void dump_page(struct page *page);
62473 @@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62474 static inline bool page_is_guard(struct page *page) { return false; }
62475 #endif /* CONFIG_DEBUG_PAGEALLOC */
62476
62477 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62478 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62479 +#else
62480 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62481 +#endif
62482 +
62483 #endif /* __KERNEL__ */
62484 #endif /* _LINUX_MM_H */
62485 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62486 index 3cc3062..efeaeb7 100644
62487 --- a/include/linux/mm_types.h
62488 +++ b/include/linux/mm_types.h
62489 @@ -252,6 +252,8 @@ struct vm_area_struct {
62490 #ifdef CONFIG_NUMA
62491 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62492 #endif
62493 +
62494 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62495 };
62496
62497 struct core_thread {
62498 @@ -326,7 +328,7 @@ struct mm_struct {
62499 unsigned long def_flags;
62500 unsigned long nr_ptes; /* Page table pages */
62501 unsigned long start_code, end_code, start_data, end_data;
62502 - unsigned long start_brk, brk, start_stack;
62503 + unsigned long brk_gap, start_brk, brk, start_stack;
62504 unsigned long arg_start, arg_end, env_start, env_end;
62505
62506 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62507 @@ -388,6 +390,24 @@ struct mm_struct {
62508 #ifdef CONFIG_CPUMASK_OFFSTACK
62509 struct cpumask cpumask_allocation;
62510 #endif
62511 +
62512 +#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)
62513 + unsigned long pax_flags;
62514 +#endif
62515 +
62516 +#ifdef CONFIG_PAX_DLRESOLVE
62517 + unsigned long call_dl_resolve;
62518 +#endif
62519 +
62520 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62521 + unsigned long call_syscall;
62522 +#endif
62523 +
62524 +#ifdef CONFIG_PAX_ASLR
62525 + unsigned long delta_mmap; /* randomized offset */
62526 + unsigned long delta_stack; /* randomized offset */
62527 +#endif
62528 +
62529 };
62530
62531 static inline void mm_init_cpumask(struct mm_struct *mm)
62532 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62533 index 1d1b1e1..2a13c78 100644
62534 --- a/include/linux/mmu_notifier.h
62535 +++ b/include/linux/mmu_notifier.h
62536 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62537 */
62538 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62539 ({ \
62540 - pte_t __pte; \
62541 + pte_t ___pte; \
62542 struct vm_area_struct *___vma = __vma; \
62543 unsigned long ___address = __address; \
62544 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62545 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62546 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62547 - __pte; \
62548 + ___pte; \
62549 })
62550
62551 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62552 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62553 index 650ba2f..af0a58c 100644
62554 --- a/include/linux/mmzone.h
62555 +++ b/include/linux/mmzone.h
62556 @@ -379,7 +379,7 @@ struct zone {
62557 unsigned long flags; /* zone flags, see below */
62558
62559 /* Zone statistics */
62560 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62561 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62562
62563 /*
62564 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62565 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62566 index 83ac071..2656e0e 100644
62567 --- a/include/linux/mod_devicetable.h
62568 +++ b/include/linux/mod_devicetable.h
62569 @@ -12,7 +12,7 @@
62570 typedef unsigned long kernel_ulong_t;
62571 #endif
62572
62573 -#define PCI_ANY_ID (~0)
62574 +#define PCI_ANY_ID ((__u16)~0)
62575
62576 struct pci_device_id {
62577 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62578 @@ -131,7 +131,7 @@ struct usb_device_id {
62579 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62580 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62581
62582 -#define HID_ANY_ID (~0)
62583 +#define HID_ANY_ID (~0U)
62584
62585 struct hid_device_id {
62586 __u16 bus;
62587 diff --git a/include/linux/module.h b/include/linux/module.h
62588 index 4598bf0..e069d7f 100644
62589 --- a/include/linux/module.h
62590 +++ b/include/linux/module.h
62591 @@ -17,6 +17,7 @@
62592 #include <linux/moduleparam.h>
62593 #include <linux/tracepoint.h>
62594 #include <linux/export.h>
62595 +#include <linux/fs.h>
62596
62597 #include <linux/percpu.h>
62598 #include <asm/module.h>
62599 @@ -275,19 +276,16 @@ struct module
62600 int (*init)(void);
62601
62602 /* If this is non-NULL, vfree after init() returns */
62603 - void *module_init;
62604 + void *module_init_rx, *module_init_rw;
62605
62606 /* Here is the actual code + data, vfree'd on unload. */
62607 - void *module_core;
62608 + void *module_core_rx, *module_core_rw;
62609
62610 /* Here are the sizes of the init and core sections */
62611 - unsigned int init_size, core_size;
62612 + unsigned int init_size_rw, core_size_rw;
62613
62614 /* The size of the executable code in each section. */
62615 - unsigned int init_text_size, core_text_size;
62616 -
62617 - /* Size of RO sections of the module (text+rodata) */
62618 - unsigned int init_ro_size, core_ro_size;
62619 + unsigned int init_size_rx, core_size_rx;
62620
62621 /* Arch-specific module values */
62622 struct mod_arch_specific arch;
62623 @@ -343,6 +341,10 @@ struct module
62624 #ifdef CONFIG_EVENT_TRACING
62625 struct ftrace_event_call **trace_events;
62626 unsigned int num_trace_events;
62627 + struct file_operations trace_id;
62628 + struct file_operations trace_enable;
62629 + struct file_operations trace_format;
62630 + struct file_operations trace_filter;
62631 #endif
62632 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62633 unsigned int num_ftrace_callsites;
62634 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62635 bool is_module_percpu_address(unsigned long addr);
62636 bool is_module_text_address(unsigned long addr);
62637
62638 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62639 +{
62640 +
62641 +#ifdef CONFIG_PAX_KERNEXEC
62642 + if (ktla_ktva(addr) >= (unsigned long)start &&
62643 + ktla_ktva(addr) < (unsigned long)start + size)
62644 + return 1;
62645 +#endif
62646 +
62647 + return ((void *)addr >= start && (void *)addr < start + size);
62648 +}
62649 +
62650 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62651 +{
62652 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62653 +}
62654 +
62655 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62656 +{
62657 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62658 +}
62659 +
62660 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62661 +{
62662 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62663 +}
62664 +
62665 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62666 +{
62667 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62668 +}
62669 +
62670 static inline int within_module_core(unsigned long addr, struct module *mod)
62671 {
62672 - return (unsigned long)mod->module_core <= addr &&
62673 - addr < (unsigned long)mod->module_core + mod->core_size;
62674 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62675 }
62676
62677 static inline int within_module_init(unsigned long addr, struct module *mod)
62678 {
62679 - return (unsigned long)mod->module_init <= addr &&
62680 - addr < (unsigned long)mod->module_init + mod->init_size;
62681 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62682 }
62683
62684 /* Search for module by name: must hold module_mutex. */
62685 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62686 index b2be02e..72d2f78 100644
62687 --- a/include/linux/moduleloader.h
62688 +++ b/include/linux/moduleloader.h
62689 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62690
62691 /* Allocator used for allocating struct module, core sections and init
62692 sections. Returns NULL on failure. */
62693 -void *module_alloc(unsigned long size);
62694 +void *module_alloc(unsigned long size) __size_overflow(1);
62695 +
62696 +#ifdef CONFIG_PAX_KERNEXEC
62697 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62698 +#else
62699 +#define module_alloc_exec(x) module_alloc(x)
62700 +#endif
62701
62702 /* Free memory returned from module_alloc. */
62703 void module_free(struct module *mod, void *module_region);
62704
62705 +#ifdef CONFIG_PAX_KERNEXEC
62706 +void module_free_exec(struct module *mod, void *module_region);
62707 +#else
62708 +#define module_free_exec(x, y) module_free((x), (y))
62709 +#endif
62710 +
62711 /* Apply the given relocation to the (simplified) ELF. Return -error
62712 or 0. */
62713 int apply_relocate(Elf_Shdr *sechdrs,
62714 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62715 index c47f4d6..23f9bdb 100644
62716 --- a/include/linux/moduleparam.h
62717 +++ b/include/linux/moduleparam.h
62718 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62719 * @len is usually just sizeof(string).
62720 */
62721 #define module_param_string(name, string, len, perm) \
62722 - static const struct kparam_string __param_string_##name \
62723 + static const struct kparam_string __param_string_##name __used \
62724 = { len, string }; \
62725 __module_param_call(MODULE_PARAM_PREFIX, name, \
62726 &param_ops_string, \
62727 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62728 */
62729 #define module_param_array_named(name, array, type, nump, perm) \
62730 param_check_##type(name, &(array)[0]); \
62731 - static const struct kparam_array __param_arr_##name \
62732 + static const struct kparam_array __param_arr_##name __used \
62733 = { .max = ARRAY_SIZE(array), .num = nump, \
62734 .ops = &param_ops_##type, \
62735 .elemsize = sizeof(array[0]), .elem = array }; \
62736 diff --git a/include/linux/namei.h b/include/linux/namei.h
62737 index ffc0213..2c1f2cb 100644
62738 --- a/include/linux/namei.h
62739 +++ b/include/linux/namei.h
62740 @@ -24,7 +24,7 @@ struct nameidata {
62741 unsigned seq;
62742 int last_type;
62743 unsigned depth;
62744 - char *saved_names[MAX_NESTED_LINKS + 1];
62745 + const char *saved_names[MAX_NESTED_LINKS + 1];
62746
62747 /* Intent data */
62748 union {
62749 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62750 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62751 extern void unlock_rename(struct dentry *, struct dentry *);
62752
62753 -static inline void nd_set_link(struct nameidata *nd, char *path)
62754 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62755 {
62756 nd->saved_names[nd->depth] = path;
62757 }
62758
62759 -static inline char *nd_get_link(struct nameidata *nd)
62760 +static inline const char *nd_get_link(const struct nameidata *nd)
62761 {
62762 return nd->saved_names[nd->depth];
62763 }
62764 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62765 index 0eac07c..a59f6a8 100644
62766 --- a/include/linux/netdevice.h
62767 +++ b/include/linux/netdevice.h
62768 @@ -1002,6 +1002,7 @@ struct net_device_ops {
62769 int (*ndo_neigh_construct)(struct neighbour *n);
62770 void (*ndo_neigh_destroy)(struct neighbour *n);
62771 };
62772 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62773
62774 /*
62775 * The DEVICE structure.
62776 @@ -1063,7 +1064,7 @@ struct net_device {
62777 int iflink;
62778
62779 struct net_device_stats stats;
62780 - atomic_long_t rx_dropped; /* dropped packets by core network
62781 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62782 * Do not use this in drivers.
62783 */
62784
62785 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62786 new file mode 100644
62787 index 0000000..33f4af8
62788 --- /dev/null
62789 +++ b/include/linux/netfilter/xt_gradm.h
62790 @@ -0,0 +1,9 @@
62791 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62792 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62793 +
62794 +struct xt_gradm_mtinfo {
62795 + __u16 flags;
62796 + __u16 invflags;
62797 +};
62798 +
62799 +#endif
62800 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62801 index c65a18a..0c05f3a 100644
62802 --- a/include/linux/of_pdt.h
62803 +++ b/include/linux/of_pdt.h
62804 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62805
62806 /* return 0 on success; fill in 'len' with number of bytes in path */
62807 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62808 -};
62809 +} __no_const;
62810
62811 extern void *prom_early_alloc(unsigned long size);
62812
62813 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62814 index a4c5624..2dabfb7 100644
62815 --- a/include/linux/oprofile.h
62816 +++ b/include/linux/oprofile.h
62817 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62818 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62819 char const * name, ulong * val);
62820
62821 -/** Create a file for read-only access to an atomic_t. */
62822 +/** Create a file for read-only access to an atomic_unchecked_t. */
62823 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62824 - char const * name, atomic_t * val);
62825 + char const * name, atomic_unchecked_t * val);
62826
62827 /** create a directory */
62828 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62829 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
62830 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
62831 * Returns 0 on success, < 0 on error.
62832 */
62833 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
62834 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
62835
62836 /** lock for read/write safety */
62837 extern raw_spinlock_t oprofilefs_lock;
62838 diff --git a/include/linux/padata.h b/include/linux/padata.h
62839 index 4633b2f..988bc08 100644
62840 --- a/include/linux/padata.h
62841 +++ b/include/linux/padata.h
62842 @@ -129,7 +129,7 @@ struct parallel_data {
62843 struct padata_instance *pinst;
62844 struct padata_parallel_queue __percpu *pqueue;
62845 struct padata_serial_queue __percpu *squeue;
62846 - atomic_t seq_nr;
62847 + atomic_unchecked_t seq_nr;
62848 atomic_t reorder_objects;
62849 atomic_t refcnt;
62850 unsigned int max_seq_nr;
62851 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62852 index abb2776..d8b8e15 100644
62853 --- a/include/linux/perf_event.h
62854 +++ b/include/linux/perf_event.h
62855 @@ -750,8 +750,8 @@ struct perf_event {
62856
62857 enum perf_event_active_state state;
62858 unsigned int attach_state;
62859 - local64_t count;
62860 - atomic64_t child_count;
62861 + local64_t count; /* PaX: fix it one day */
62862 + atomic64_unchecked_t child_count;
62863
62864 /*
62865 * These are the total time in nanoseconds that the event
62866 @@ -802,8 +802,8 @@ struct perf_event {
62867 * These accumulate total time (in nanoseconds) that children
62868 * events have been enabled and running, respectively.
62869 */
62870 - atomic64_t child_total_time_enabled;
62871 - atomic64_t child_total_time_running;
62872 + atomic64_unchecked_t child_total_time_enabled;
62873 + atomic64_unchecked_t child_total_time_running;
62874
62875 /*
62876 * Protect attach/detach and child_list:
62877 diff --git a/include/linux/personality.h b/include/linux/personality.h
62878 index 8fc7dd1a..c19d89e 100644
62879 --- a/include/linux/personality.h
62880 +++ b/include/linux/personality.h
62881 @@ -44,6 +44,7 @@ enum {
62882 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62883 ADDR_NO_RANDOMIZE | \
62884 ADDR_COMPAT_LAYOUT | \
62885 + ADDR_LIMIT_3GB | \
62886 MMAP_PAGE_ZERO)
62887
62888 /*
62889 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62890 index 77257c9..51d473a 100644
62891 --- a/include/linux/pipe_fs_i.h
62892 +++ b/include/linux/pipe_fs_i.h
62893 @@ -46,9 +46,9 @@ struct pipe_buffer {
62894 struct pipe_inode_info {
62895 wait_queue_head_t wait;
62896 unsigned int nrbufs, curbuf, buffers;
62897 - unsigned int readers;
62898 - unsigned int writers;
62899 - unsigned int waiting_writers;
62900 + atomic_t readers;
62901 + atomic_t writers;
62902 + atomic_t waiting_writers;
62903 unsigned int r_counter;
62904 unsigned int w_counter;
62905 struct page *tmp_page;
62906 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62907 index 609daae..5392427 100644
62908 --- a/include/linux/pm_runtime.h
62909 +++ b/include/linux/pm_runtime.h
62910 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62911
62912 static inline void pm_runtime_mark_last_busy(struct device *dev)
62913 {
62914 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62915 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62916 }
62917
62918 #else /* !CONFIG_PM_RUNTIME */
62919 diff --git a/include/linux/poison.h b/include/linux/poison.h
62920 index 2110a81..13a11bb 100644
62921 --- a/include/linux/poison.h
62922 +++ b/include/linux/poison.h
62923 @@ -19,8 +19,8 @@
62924 * under normal circumstances, used to verify that nobody uses
62925 * non-initialized list entries.
62926 */
62927 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62928 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62929 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62930 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62931
62932 /********** include/linux/timer.h **********/
62933 /*
62934 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62935 index 58969b2..ead129b 100644
62936 --- a/include/linux/preempt.h
62937 +++ b/include/linux/preempt.h
62938 @@ -123,7 +123,7 @@ struct preempt_ops {
62939 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62940 void (*sched_out)(struct preempt_notifier *notifier,
62941 struct task_struct *next);
62942 -};
62943 +} __no_const;
62944
62945 /**
62946 * preempt_notifier - key for installing preemption notifiers
62947 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62948 index 85c5073..51fac8b 100644
62949 --- a/include/linux/proc_fs.h
62950 +++ b/include/linux/proc_fs.h
62951 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62952 return proc_create_data(name, mode, parent, proc_fops, NULL);
62953 }
62954
62955 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62956 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62957 +{
62958 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62959 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62960 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62961 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62962 +#else
62963 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62964 +#endif
62965 +}
62966 +
62967 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62968 umode_t mode, struct proc_dir_entry *base,
62969 read_proc_t *read_proc, void * data)
62970 @@ -258,7 +270,7 @@ union proc_op {
62971 int (*proc_show)(struct seq_file *m,
62972 struct pid_namespace *ns, struct pid *pid,
62973 struct task_struct *task);
62974 -};
62975 +} __no_const;
62976
62977 struct ctl_table_header;
62978 struct ctl_table;
62979 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62980 index c2f1f6a..6fdb196 100644
62981 --- a/include/linux/ptrace.h
62982 +++ b/include/linux/ptrace.h
62983 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62984 if (unlikely(ptrace_event_enabled(current, event))) {
62985 current->ptrace_message = message;
62986 ptrace_notify((event << 8) | SIGTRAP);
62987 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62988 + } else if (event == PTRACE_EVENT_EXEC) {
62989 /* legacy EXEC report via SIGTRAP */
62990 - send_sig(SIGTRAP, current, 0);
62991 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62992 + send_sig(SIGTRAP, current, 0);
62993 }
62994 }
62995
62996 diff --git a/include/linux/random.h b/include/linux/random.h
62997 index 8f74538..02a1012 100644
62998 --- a/include/linux/random.h
62999 +++ b/include/linux/random.h
63000 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
63001
63002 u32 prandom32(struct rnd_state *);
63003
63004 +static inline unsigned long pax_get_random_long(void)
63005 +{
63006 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63007 +}
63008 +
63009 /*
63010 * Handle minimum values for seeds
63011 */
63012 static inline u32 __seed(u32 x, u32 m)
63013 {
63014 - return (x < m) ? x + m : x;
63015 + return (x <= m) ? x + m + 1 : x;
63016 }
63017
63018 /**
63019 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63020 index e0879a7..a12f962 100644
63021 --- a/include/linux/reboot.h
63022 +++ b/include/linux/reboot.h
63023 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63024 * Architecture-specific implementations of sys_reboot commands.
63025 */
63026
63027 -extern void machine_restart(char *cmd);
63028 -extern void machine_halt(void);
63029 -extern void machine_power_off(void);
63030 +extern void machine_restart(char *cmd) __noreturn;
63031 +extern void machine_halt(void) __noreturn;
63032 +extern void machine_power_off(void) __noreturn;
63033
63034 extern void machine_shutdown(void);
63035 struct pt_regs;
63036 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63037 */
63038
63039 extern void kernel_restart_prepare(char *cmd);
63040 -extern void kernel_restart(char *cmd);
63041 -extern void kernel_halt(void);
63042 -extern void kernel_power_off(void);
63043 +extern void kernel_restart(char *cmd) __noreturn;
63044 +extern void kernel_halt(void) __noreturn;
63045 +extern void kernel_power_off(void) __noreturn;
63046
63047 extern int C_A_D; /* for sysctl */
63048 void ctrl_alt_del(void);
63049 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63050 * Emergency restart, callable from an interrupt handler.
63051 */
63052
63053 -extern void emergency_restart(void);
63054 +extern void emergency_restart(void) __noreturn;
63055 #include <asm/emergency-restart.h>
63056
63057 #endif
63058 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63059 index 2213ddc..650212a 100644
63060 --- a/include/linux/reiserfs_fs.h
63061 +++ b/include/linux/reiserfs_fs.h
63062 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63063 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63064
63065 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63066 -#define get_generation(s) atomic_read (&fs_generation(s))
63067 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63068 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63069 #define __fs_changed(gen,s) (gen != get_generation (s))
63070 #define fs_changed(gen,s) \
63071 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63072 index 8c9e85c..1698e9a 100644
63073 --- a/include/linux/reiserfs_fs_sb.h
63074 +++ b/include/linux/reiserfs_fs_sb.h
63075 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63076 /* Comment? -Hans */
63077 wait_queue_head_t s_wait;
63078 /* To be obsoleted soon by per buffer seals.. -Hans */
63079 - atomic_t s_generation_counter; // increased by one every time the
63080 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63081 // tree gets re-balanced
63082 unsigned long s_properties; /* File system properties. Currently holds
63083 on-disk FS format */
63084 diff --git a/include/linux/relay.h b/include/linux/relay.h
63085 index a822fd7..62b70f6 100644
63086 --- a/include/linux/relay.h
63087 +++ b/include/linux/relay.h
63088 @@ -159,7 +159,7 @@ struct rchan_callbacks
63089 * The callback should return 0 if successful, negative if not.
63090 */
63091 int (*remove_buf_file)(struct dentry *dentry);
63092 -};
63093 +} __no_const;
63094
63095 /*
63096 * CONFIG_RELAY kernel API, kernel/relay.c
63097 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63098 index c6c6084..5bf1212 100644
63099 --- a/include/linux/rfkill.h
63100 +++ b/include/linux/rfkill.h
63101 @@ -147,6 +147,7 @@ struct rfkill_ops {
63102 void (*query)(struct rfkill *rfkill, void *data);
63103 int (*set_block)(void *data, bool blocked);
63104 };
63105 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63106
63107 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63108 /**
63109 diff --git a/include/linux/rio.h b/include/linux/rio.h
63110 index 4d50611..c6858a2 100644
63111 --- a/include/linux/rio.h
63112 +++ b/include/linux/rio.h
63113 @@ -315,7 +315,7 @@ struct rio_ops {
63114 int mbox, void *buffer, size_t len);
63115 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63116 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63117 -};
63118 +} __no_const;
63119
63120 #define RIO_RESOURCE_MEM 0x00000100
63121 #define RIO_RESOURCE_DOORBELL 0x00000200
63122 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63123 index 1cdd62a..e399f0d 100644
63124 --- a/include/linux/rmap.h
63125 +++ b/include/linux/rmap.h
63126 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63127 void anon_vma_init(void); /* create anon_vma_cachep */
63128 int anon_vma_prepare(struct vm_area_struct *);
63129 void unlink_anon_vmas(struct vm_area_struct *);
63130 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63131 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63132 void anon_vma_moveto_tail(struct vm_area_struct *);
63133 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63134 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63135 void __anon_vma_link(struct vm_area_struct *);
63136
63137 static inline void anon_vma_merge(struct vm_area_struct *vma,
63138 diff --git a/include/linux/sched.h b/include/linux/sched.h
63139 index 0657368..765f70f 100644
63140 --- a/include/linux/sched.h
63141 +++ b/include/linux/sched.h
63142 @@ -101,6 +101,7 @@ struct bio_list;
63143 struct fs_struct;
63144 struct perf_event_context;
63145 struct blk_plug;
63146 +struct linux_binprm;
63147
63148 /*
63149 * List of flags we want to share for kernel threads,
63150 @@ -382,10 +383,13 @@ struct user_namespace;
63151 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63152
63153 extern int sysctl_max_map_count;
63154 +extern unsigned long sysctl_heap_stack_gap;
63155
63156 #include <linux/aio.h>
63157
63158 #ifdef CONFIG_MMU
63159 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63160 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63161 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63162 extern unsigned long
63163 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63164 @@ -631,6 +635,17 @@ struct signal_struct {
63165 #ifdef CONFIG_TASKSTATS
63166 struct taskstats *stats;
63167 #endif
63168 +
63169 +#ifdef CONFIG_GRKERNSEC
63170 + u32 curr_ip;
63171 + u32 saved_ip;
63172 + u32 gr_saddr;
63173 + u32 gr_daddr;
63174 + u16 gr_sport;
63175 + u16 gr_dport;
63176 + u8 used_accept:1;
63177 +#endif
63178 +
63179 #ifdef CONFIG_AUDIT
63180 unsigned audit_tty;
63181 struct tty_audit_buf *tty_audit_buf;
63182 @@ -714,6 +729,11 @@ struct user_struct {
63183 struct key *session_keyring; /* UID's default session keyring */
63184 #endif
63185
63186 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63187 + unsigned int banned;
63188 + unsigned long ban_expires;
63189 +#endif
63190 +
63191 /* Hash table maintenance information */
63192 struct hlist_node uidhash_node;
63193 uid_t uid;
63194 @@ -1354,8 +1374,8 @@ struct task_struct {
63195 struct list_head thread_group;
63196
63197 struct completion *vfork_done; /* for vfork() */
63198 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63199 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63200 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63201 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63202
63203 cputime_t utime, stime, utimescaled, stimescaled;
63204 cputime_t gtime;
63205 @@ -1371,13 +1391,6 @@ struct task_struct {
63206 struct task_cputime cputime_expires;
63207 struct list_head cpu_timers[3];
63208
63209 -/* process credentials */
63210 - const struct cred __rcu *real_cred; /* objective and real subjective task
63211 - * credentials (COW) */
63212 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63213 - * credentials (COW) */
63214 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63215 -
63216 char comm[TASK_COMM_LEN]; /* executable name excluding path
63217 - access with [gs]et_task_comm (which lock
63218 it with task_lock())
63219 @@ -1394,8 +1407,16 @@ struct task_struct {
63220 #endif
63221 /* CPU-specific state of this task */
63222 struct thread_struct thread;
63223 +/* thread_info moved to task_struct */
63224 +#ifdef CONFIG_X86
63225 + struct thread_info tinfo;
63226 +#endif
63227 /* filesystem information */
63228 struct fs_struct *fs;
63229 +
63230 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63231 + * credentials (COW) */
63232 +
63233 /* open file information */
63234 struct files_struct *files;
63235 /* namespaces */
63236 @@ -1442,6 +1463,11 @@ struct task_struct {
63237 struct rt_mutex_waiter *pi_blocked_on;
63238 #endif
63239
63240 +/* process credentials */
63241 + const struct cred __rcu *real_cred; /* objective and real subjective task
63242 + * credentials (COW) */
63243 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63244 +
63245 #ifdef CONFIG_DEBUG_MUTEXES
63246 /* mutex deadlock detection */
63247 struct mutex_waiter *blocked_on;
63248 @@ -1558,6 +1584,27 @@ struct task_struct {
63249 unsigned long default_timer_slack_ns;
63250
63251 struct list_head *scm_work_list;
63252 +
63253 +#ifdef CONFIG_GRKERNSEC
63254 + /* grsecurity */
63255 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63256 + u64 exec_id;
63257 +#endif
63258 +#ifdef CONFIG_GRKERNSEC_SETXID
63259 + const struct cred *delayed_cred;
63260 +#endif
63261 + struct dentry *gr_chroot_dentry;
63262 + struct acl_subject_label *acl;
63263 + struct acl_role_label *role;
63264 + struct file *exec_file;
63265 + u16 acl_role_id;
63266 + /* is this the task that authenticated to the special role */
63267 + u8 acl_sp_role;
63268 + u8 is_writable;
63269 + u8 brute;
63270 + u8 gr_is_chrooted;
63271 +#endif
63272 +
63273 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63274 /* Index of current stored address in ret_stack */
63275 int curr_ret_stack;
63276 @@ -1592,6 +1639,51 @@ struct task_struct {
63277 #endif
63278 };
63279
63280 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63281 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63282 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63283 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63284 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63285 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63286 +
63287 +#ifdef CONFIG_PAX_SOFTMODE
63288 +extern int pax_softmode;
63289 +#endif
63290 +
63291 +extern int pax_check_flags(unsigned long *);
63292 +
63293 +/* if tsk != current then task_lock must be held on it */
63294 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63295 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63296 +{
63297 + if (likely(tsk->mm))
63298 + return tsk->mm->pax_flags;
63299 + else
63300 + return 0UL;
63301 +}
63302 +
63303 +/* if tsk != current then task_lock must be held on it */
63304 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63305 +{
63306 + if (likely(tsk->mm)) {
63307 + tsk->mm->pax_flags = flags;
63308 + return 0;
63309 + }
63310 + return -EINVAL;
63311 +}
63312 +#endif
63313 +
63314 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63315 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63316 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63317 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63318 +#endif
63319 +
63320 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63321 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63322 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63323 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63324 +
63325 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63326 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63327
63328 @@ -2104,7 +2196,9 @@ void yield(void);
63329 extern struct exec_domain default_exec_domain;
63330
63331 union thread_union {
63332 +#ifndef CONFIG_X86
63333 struct thread_info thread_info;
63334 +#endif
63335 unsigned long stack[THREAD_SIZE/sizeof(long)];
63336 };
63337
63338 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63339 */
63340
63341 extern struct task_struct *find_task_by_vpid(pid_t nr);
63342 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63343 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63344 struct pid_namespace *ns);
63345
63346 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63347 extern void exit_itimers(struct signal_struct *);
63348 extern void flush_itimer_signals(void);
63349
63350 -extern void do_group_exit(int);
63351 +extern __noreturn void do_group_exit(int);
63352
63353 extern void daemonize(const char *, ...);
63354 extern int allow_signal(int);
63355 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63356
63357 #endif
63358
63359 -static inline int object_is_on_stack(void *obj)
63360 +static inline int object_starts_on_stack(void *obj)
63361 {
63362 - void *stack = task_stack_page(current);
63363 + const void *stack = task_stack_page(current);
63364
63365 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63366 }
63367
63368 +#ifdef CONFIG_PAX_USERCOPY
63369 +extern int object_is_on_stack(const void *obj, unsigned long len);
63370 +#endif
63371 +
63372 extern void thread_info_cache_init(void);
63373
63374 #ifdef CONFIG_DEBUG_STACK_USAGE
63375 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63376 index 899fbb4..1cb4138 100644
63377 --- a/include/linux/screen_info.h
63378 +++ b/include/linux/screen_info.h
63379 @@ -43,7 +43,8 @@ struct screen_info {
63380 __u16 pages; /* 0x32 */
63381 __u16 vesa_attributes; /* 0x34 */
63382 __u32 capabilities; /* 0x36 */
63383 - __u8 _reserved[6]; /* 0x3a */
63384 + __u16 vesapm_size; /* 0x3a */
63385 + __u8 _reserved[4]; /* 0x3c */
63386 } __attribute__((packed));
63387
63388 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63389 diff --git a/include/linux/security.h b/include/linux/security.h
63390 index 83c18e8..2d98860 100644
63391 --- a/include/linux/security.h
63392 +++ b/include/linux/security.h
63393 @@ -37,6 +37,7 @@
63394 #include <linux/xfrm.h>
63395 #include <linux/slab.h>
63396 #include <linux/xattr.h>
63397 +#include <linux/grsecurity.h>
63398 #include <net/flow.h>
63399
63400 /* Maximum number of letters for an LSM name string */
63401 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63402 index 44f1514..2bbf6c1 100644
63403 --- a/include/linux/seq_file.h
63404 +++ b/include/linux/seq_file.h
63405 @@ -24,6 +24,9 @@ struct seq_file {
63406 struct mutex lock;
63407 const struct seq_operations *op;
63408 int poll_event;
63409 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63410 + u64 exec_id;
63411 +#endif
63412 void *private;
63413 };
63414
63415 @@ -33,6 +36,7 @@ struct seq_operations {
63416 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63417 int (*show) (struct seq_file *m, void *v);
63418 };
63419 +typedef struct seq_operations __no_const seq_operations_no_const;
63420
63421 #define SEQ_SKIP 1
63422
63423 diff --git a/include/linux/shm.h b/include/linux/shm.h
63424 index 92808b8..c28cac4 100644
63425 --- a/include/linux/shm.h
63426 +++ b/include/linux/shm.h
63427 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63428
63429 /* The task created the shm object. NULL if the task is dead. */
63430 struct task_struct *shm_creator;
63431 +#ifdef CONFIG_GRKERNSEC
63432 + time_t shm_createtime;
63433 + pid_t shm_lapid;
63434 +#endif
63435 };
63436
63437 /* shm_mode upper byte flags */
63438 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63439 index ae86ade..2b51468 100644
63440 --- a/include/linux/skbuff.h
63441 +++ b/include/linux/skbuff.h
63442 @@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63443 */
63444 static inline int skb_queue_empty(const struct sk_buff_head *list)
63445 {
63446 - return list->next == (struct sk_buff *)list;
63447 + return list->next == (const struct sk_buff *)list;
63448 }
63449
63450 /**
63451 @@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63452 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63453 const struct sk_buff *skb)
63454 {
63455 - return skb->next == (struct sk_buff *)list;
63456 + return skb->next == (const struct sk_buff *)list;
63457 }
63458
63459 /**
63460 @@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63461 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63462 const struct sk_buff *skb)
63463 {
63464 - return skb->prev == (struct sk_buff *)list;
63465 + return skb->prev == (const struct sk_buff *)list;
63466 }
63467
63468 /**
63469 @@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63470 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63471 */
63472 #ifndef NET_SKB_PAD
63473 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63474 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63475 #endif
63476
63477 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63478 diff --git a/include/linux/slab.h b/include/linux/slab.h
63479 index 573c809..07e1f43 100644
63480 --- a/include/linux/slab.h
63481 +++ b/include/linux/slab.h
63482 @@ -11,12 +11,20 @@
63483
63484 #include <linux/gfp.h>
63485 #include <linux/types.h>
63486 +#include <linux/err.h>
63487
63488 /*
63489 * Flags to pass to kmem_cache_create().
63490 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63491 */
63492 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63493 +
63494 +#ifdef CONFIG_PAX_USERCOPY
63495 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63496 +#else
63497 +#define SLAB_USERCOPY 0x00000000UL
63498 +#endif
63499 +
63500 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63501 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63502 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63503 @@ -87,10 +95,13 @@
63504 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63505 * Both make kfree a no-op.
63506 */
63507 -#define ZERO_SIZE_PTR ((void *)16)
63508 +#define ZERO_SIZE_PTR \
63509 +({ \
63510 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63511 + (void *)(-MAX_ERRNO-1L); \
63512 +})
63513
63514 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63515 - (unsigned long)ZERO_SIZE_PTR)
63516 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63517
63518 /*
63519 * struct kmem_cache related prototypes
63520 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63521 /*
63522 * Common kmalloc functions provided by all allocators
63523 */
63524 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63525 -void * __must_check krealloc(const void *, size_t, gfp_t);
63526 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63527 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63528 void kfree(const void *);
63529 void kzfree(const void *);
63530 size_t ksize(const void *);
63531 +void check_object_size(const void *ptr, unsigned long n, bool to);
63532
63533 /*
63534 * Allocator specific definitions. These are mainly used to establish optimized
63535 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63536 */
63537 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63538 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63539 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63540 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63541 #define kmalloc_track_caller(size, flags) \
63542 __kmalloc_track_caller(size, flags, _RET_IP_)
63543 #else
63544 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63545 */
63546 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63547 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63548 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63549 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63550 #define kmalloc_node_track_caller(size, flags, node) \
63551 __kmalloc_node_track_caller(size, flags, node, \
63552 _RET_IP_)
63553 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63554 index fbd1117..c0bd874 100644
63555 --- a/include/linux/slab_def.h
63556 +++ b/include/linux/slab_def.h
63557 @@ -66,10 +66,10 @@ struct kmem_cache {
63558 unsigned long node_allocs;
63559 unsigned long node_frees;
63560 unsigned long node_overflow;
63561 - atomic_t allochit;
63562 - atomic_t allocmiss;
63563 - atomic_t freehit;
63564 - atomic_t freemiss;
63565 + atomic_unchecked_t allochit;
63566 + atomic_unchecked_t allocmiss;
63567 + atomic_unchecked_t freehit;
63568 + atomic_unchecked_t freemiss;
63569
63570 /*
63571 * If debugging is enabled, then the allocator can add additional
63572 @@ -107,7 +107,7 @@ struct cache_sizes {
63573 extern struct cache_sizes malloc_sizes[];
63574
63575 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63576 -void *__kmalloc(size_t size, gfp_t flags);
63577 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63578
63579 #ifdef CONFIG_TRACING
63580 extern void *kmem_cache_alloc_trace(size_t size,
63581 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63582 }
63583 #endif
63584
63585 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63586 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63587 {
63588 struct kmem_cache *cachep;
63589 @@ -160,7 +161,7 @@ found:
63590 }
63591
63592 #ifdef CONFIG_NUMA
63593 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63594 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63595 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63596
63597 #ifdef CONFIG_TRACING
63598 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
63599 }
63600 #endif
63601
63602 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63603 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63604 {
63605 struct kmem_cache *cachep;
63606 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63607 index 0ec00b3..65e7e0e 100644
63608 --- a/include/linux/slob_def.h
63609 +++ b/include/linux/slob_def.h
63610 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63611 return kmem_cache_alloc_node(cachep, flags, -1);
63612 }
63613
63614 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63615 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63616
63617 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63618 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63619 {
63620 return __kmalloc_node(size, flags, node);
63621 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63622 * kmalloc is the normal method of allocating memory
63623 * in the kernel.
63624 */
63625 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63626 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63627 {
63628 return __kmalloc_node(size, flags, -1);
63629 }
63630
63631 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63632 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63633 {
63634 return kmalloc(size, flags);
63635 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63636 index a32bcfd..d26bd6e 100644
63637 --- a/include/linux/slub_def.h
63638 +++ b/include/linux/slub_def.h
63639 @@ -89,7 +89,7 @@ struct kmem_cache {
63640 struct kmem_cache_order_objects max;
63641 struct kmem_cache_order_objects min;
63642 gfp_t allocflags; /* gfp flags to use on each alloc */
63643 - int refcount; /* Refcount for slab cache destroy */
63644 + atomic_t refcount; /* Refcount for slab cache destroy */
63645 void (*ctor)(void *);
63646 int inuse; /* Offset to metadata */
63647 int align; /* Alignment */
63648 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
63649 * This ought to end up with a global pointer to the right cache
63650 * in kmalloc_caches.
63651 */
63652 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
63653 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63654 {
63655 int index = kmalloc_index(size);
63656 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63657 }
63658
63659 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63660 -void *__kmalloc(size_t size, gfp_t flags);
63661 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63662
63663 static __always_inline void *
63664 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
63665 +static __always_inline void *
63666 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63667 {
63668 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
63669 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63670 }
63671 #endif
63672
63673 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63674 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63675 {
63676 unsigned int order = get_order(size);
63677 return kmalloc_order_trace(size, flags, order);
63678 }
63679
63680 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63681 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63682 {
63683 if (__builtin_constant_p(size)) {
63684 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63685 }
63686
63687 #ifdef CONFIG_NUMA
63688 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63689 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63690 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63691
63692 #ifdef CONFIG_TRACING
63693 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
63694 }
63695 #endif
63696
63697 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63698 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63699 {
63700 if (__builtin_constant_p(size) &&
63701 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63702 index de8832d..0147b46 100644
63703 --- a/include/linux/sonet.h
63704 +++ b/include/linux/sonet.h
63705 @@ -61,7 +61,7 @@ struct sonet_stats {
63706 #include <linux/atomic.h>
63707
63708 struct k_sonet_stats {
63709 -#define __HANDLE_ITEM(i) atomic_t i
63710 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63711 __SONET_ITEMS
63712 #undef __HANDLE_ITEM
63713 };
63714 diff --git a/include/linux/stddef.h b/include/linux/stddef.h
63715 index 6a40c76..1747b67 100644
63716 --- a/include/linux/stddef.h
63717 +++ b/include/linux/stddef.h
63718 @@ -3,14 +3,10 @@
63719
63720 #include <linux/compiler.h>
63721
63722 +#ifdef __KERNEL__
63723 +
63724 #undef NULL
63725 -#if defined(__cplusplus)
63726 -#define NULL 0
63727 -#else
63728 #define NULL ((void *)0)
63729 -#endif
63730 -
63731 -#ifdef __KERNEL__
63732
63733 enum {
63734 false = 0,
63735 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63736 index 2c5993a..b0e79f0 100644
63737 --- a/include/linux/sunrpc/clnt.h
63738 +++ b/include/linux/sunrpc/clnt.h
63739 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63740 {
63741 switch (sap->sa_family) {
63742 case AF_INET:
63743 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63744 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63745 case AF_INET6:
63746 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63747 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63748 }
63749 return 0;
63750 }
63751 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63752 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63753 const struct sockaddr *src)
63754 {
63755 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63756 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63757 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63758
63759 dsin->sin_family = ssin->sin_family;
63760 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63761 if (sa->sa_family != AF_INET6)
63762 return 0;
63763
63764 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63765 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63766 }
63767
63768 #endif /* __KERNEL__ */
63769 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63770 index e775689..9e206d9 100644
63771 --- a/include/linux/sunrpc/sched.h
63772 +++ b/include/linux/sunrpc/sched.h
63773 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63774 void (*rpc_call_done)(struct rpc_task *, void *);
63775 void (*rpc_release)(void *);
63776 };
63777 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63778
63779 struct rpc_task_setup {
63780 struct rpc_task *task;
63781 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63782 index c14fe86..393245e 100644
63783 --- a/include/linux/sunrpc/svc_rdma.h
63784 +++ b/include/linux/sunrpc/svc_rdma.h
63785 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63786 extern unsigned int svcrdma_max_requests;
63787 extern unsigned int svcrdma_max_req_size;
63788
63789 -extern atomic_t rdma_stat_recv;
63790 -extern atomic_t rdma_stat_read;
63791 -extern atomic_t rdma_stat_write;
63792 -extern atomic_t rdma_stat_sq_starve;
63793 -extern atomic_t rdma_stat_rq_starve;
63794 -extern atomic_t rdma_stat_rq_poll;
63795 -extern atomic_t rdma_stat_rq_prod;
63796 -extern atomic_t rdma_stat_sq_poll;
63797 -extern atomic_t rdma_stat_sq_prod;
63798 +extern atomic_unchecked_t rdma_stat_recv;
63799 +extern atomic_unchecked_t rdma_stat_read;
63800 +extern atomic_unchecked_t rdma_stat_write;
63801 +extern atomic_unchecked_t rdma_stat_sq_starve;
63802 +extern atomic_unchecked_t rdma_stat_rq_starve;
63803 +extern atomic_unchecked_t rdma_stat_rq_poll;
63804 +extern atomic_unchecked_t rdma_stat_rq_prod;
63805 +extern atomic_unchecked_t rdma_stat_sq_poll;
63806 +extern atomic_unchecked_t rdma_stat_sq_prod;
63807
63808 #define RPCRDMA_VERSION 1
63809
63810 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63811 index bb9127d..34ab358 100644
63812 --- a/include/linux/sysctl.h
63813 +++ b/include/linux/sysctl.h
63814 @@ -155,7 +155,11 @@ enum
63815 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63816 };
63817
63818 -
63819 +#ifdef CONFIG_PAX_SOFTMODE
63820 +enum {
63821 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63822 +};
63823 +#endif
63824
63825 /* CTL_VM names: */
63826 enum
63827 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63828
63829 extern int proc_dostring(struct ctl_table *, int,
63830 void __user *, size_t *, loff_t *);
63831 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63832 + void __user *, size_t *, loff_t *);
63833 extern int proc_dointvec(struct ctl_table *, int,
63834 void __user *, size_t *, loff_t *);
63835 extern int proc_dointvec_minmax(struct ctl_table *, int,
63836 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63837 index a71a292..51bd91d 100644
63838 --- a/include/linux/tracehook.h
63839 +++ b/include/linux/tracehook.h
63840 @@ -54,12 +54,12 @@ struct linux_binprm;
63841 /*
63842 * ptrace report for syscall entry and exit looks identical.
63843 */
63844 -static inline void ptrace_report_syscall(struct pt_regs *regs)
63845 +static inline int ptrace_report_syscall(struct pt_regs *regs)
63846 {
63847 int ptrace = current->ptrace;
63848
63849 if (!(ptrace & PT_PTRACED))
63850 - return;
63851 + return 0;
63852
63853 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63854
63855 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63856 send_sig(current->exit_code, current, 1);
63857 current->exit_code = 0;
63858 }
63859 +
63860 + return fatal_signal_pending(current);
63861 }
63862
63863 /**
63864 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63865 static inline __must_check int tracehook_report_syscall_entry(
63866 struct pt_regs *regs)
63867 {
63868 - ptrace_report_syscall(regs);
63869 - return 0;
63870 + return ptrace_report_syscall(regs);
63871 }
63872
63873 /**
63874 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63875 index ff7dc08..893e1bd 100644
63876 --- a/include/linux/tty_ldisc.h
63877 +++ b/include/linux/tty_ldisc.h
63878 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63879
63880 struct module *owner;
63881
63882 - int refcount;
63883 + atomic_t refcount;
63884 };
63885
63886 struct tty_ldisc {
63887 diff --git a/include/linux/types.h b/include/linux/types.h
63888 index e5fa503..df6e8a4 100644
63889 --- a/include/linux/types.h
63890 +++ b/include/linux/types.h
63891 @@ -214,10 +214,26 @@ typedef struct {
63892 int counter;
63893 } atomic_t;
63894
63895 +#ifdef CONFIG_PAX_REFCOUNT
63896 +typedef struct {
63897 + int counter;
63898 +} atomic_unchecked_t;
63899 +#else
63900 +typedef atomic_t atomic_unchecked_t;
63901 +#endif
63902 +
63903 #ifdef CONFIG_64BIT
63904 typedef struct {
63905 long counter;
63906 } atomic64_t;
63907 +
63908 +#ifdef CONFIG_PAX_REFCOUNT
63909 +typedef struct {
63910 + long counter;
63911 +} atomic64_unchecked_t;
63912 +#else
63913 +typedef atomic64_t atomic64_unchecked_t;
63914 +#endif
63915 #endif
63916
63917 struct list_head {
63918 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63919 index 5ca0951..53a2fff 100644
63920 --- a/include/linux/uaccess.h
63921 +++ b/include/linux/uaccess.h
63922 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63923 long ret; \
63924 mm_segment_t old_fs = get_fs(); \
63925 \
63926 - set_fs(KERNEL_DS); \
63927 pagefault_disable(); \
63928 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63929 - pagefault_enable(); \
63930 + set_fs(KERNEL_DS); \
63931 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63932 set_fs(old_fs); \
63933 + pagefault_enable(); \
63934 ret; \
63935 })
63936
63937 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
63938 * Safely write to address @dst from the buffer at @src. If a kernel fault
63939 * happens, handle that and return -EFAULT.
63940 */
63941 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
63942 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
63943 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
63944
63945 #endif /* __LINUX_UACCESS_H__ */
63946 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63947 index 99c1b4d..bb94261 100644
63948 --- a/include/linux/unaligned/access_ok.h
63949 +++ b/include/linux/unaligned/access_ok.h
63950 @@ -6,32 +6,32 @@
63951
63952 static inline u16 get_unaligned_le16(const void *p)
63953 {
63954 - return le16_to_cpup((__le16 *)p);
63955 + return le16_to_cpup((const __le16 *)p);
63956 }
63957
63958 static inline u32 get_unaligned_le32(const void *p)
63959 {
63960 - return le32_to_cpup((__le32 *)p);
63961 + return le32_to_cpup((const __le32 *)p);
63962 }
63963
63964 static inline u64 get_unaligned_le64(const void *p)
63965 {
63966 - return le64_to_cpup((__le64 *)p);
63967 + return le64_to_cpup((const __le64 *)p);
63968 }
63969
63970 static inline u16 get_unaligned_be16(const void *p)
63971 {
63972 - return be16_to_cpup((__be16 *)p);
63973 + return be16_to_cpup((const __be16 *)p);
63974 }
63975
63976 static inline u32 get_unaligned_be32(const void *p)
63977 {
63978 - return be32_to_cpup((__be32 *)p);
63979 + return be32_to_cpup((const __be32 *)p);
63980 }
63981
63982 static inline u64 get_unaligned_be64(const void *p)
63983 {
63984 - return be64_to_cpup((__be64 *)p);
63985 + return be64_to_cpup((const __be64 *)p);
63986 }
63987
63988 static inline void put_unaligned_le16(u16 val, void *p)
63989 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63990 index 0d3f988..000f101 100644
63991 --- a/include/linux/usb/renesas_usbhs.h
63992 +++ b/include/linux/usb/renesas_usbhs.h
63993 @@ -39,7 +39,7 @@ enum {
63994 */
63995 struct renesas_usbhs_driver_callback {
63996 int (*notify_hotplug)(struct platform_device *pdev);
63997 -};
63998 +} __no_const;
63999
64000 /*
64001 * callback functions for platform
64002 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64003 * VBUS control is needed for Host
64004 */
64005 int (*set_vbus)(struct platform_device *pdev, int enable);
64006 -};
64007 +} __no_const;
64008
64009 /*
64010 * parameters for renesas usbhs
64011 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64012 index 6f8fbcf..8259001 100644
64013 --- a/include/linux/vermagic.h
64014 +++ b/include/linux/vermagic.h
64015 @@ -25,9 +25,35 @@
64016 #define MODULE_ARCH_VERMAGIC ""
64017 #endif
64018
64019 +#ifdef CONFIG_PAX_REFCOUNT
64020 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64021 +#else
64022 +#define MODULE_PAX_REFCOUNT ""
64023 +#endif
64024 +
64025 +#ifdef CONSTIFY_PLUGIN
64026 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64027 +#else
64028 +#define MODULE_CONSTIFY_PLUGIN ""
64029 +#endif
64030 +
64031 +#ifdef STACKLEAK_PLUGIN
64032 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64033 +#else
64034 +#define MODULE_STACKLEAK_PLUGIN ""
64035 +#endif
64036 +
64037 +#ifdef CONFIG_GRKERNSEC
64038 +#define MODULE_GRSEC "GRSEC "
64039 +#else
64040 +#define MODULE_GRSEC ""
64041 +#endif
64042 +
64043 #define VERMAGIC_STRING \
64044 UTS_RELEASE " " \
64045 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64046 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64047 - MODULE_ARCH_VERMAGIC
64048 + MODULE_ARCH_VERMAGIC \
64049 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64050 + MODULE_GRSEC
64051
64052 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64053 index dcdfc2b..cce598d 100644
64054 --- a/include/linux/vmalloc.h
64055 +++ b/include/linux/vmalloc.h
64056 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64057 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64058 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64059 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64060 +
64061 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64062 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64063 +#endif
64064 +
64065 /* bits [20..32] reserved for arch specific ioremap internals */
64066
64067 /*
64068 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
64069 }
64070 #endif
64071
64072 -extern void *vmalloc(unsigned long size);
64073 -extern void *vzalloc(unsigned long size);
64074 -extern void *vmalloc_user(unsigned long size);
64075 -extern void *vmalloc_node(unsigned long size, int node);
64076 -extern void *vzalloc_node(unsigned long size, int node);
64077 -extern void *vmalloc_exec(unsigned long size);
64078 -extern void *vmalloc_32(unsigned long size);
64079 -extern void *vmalloc_32_user(unsigned long size);
64080 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64081 +extern void *vmalloc(unsigned long size) __size_overflow(1);
64082 +extern void *vzalloc(unsigned long size) __size_overflow(1);
64083 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
64084 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
64085 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
64086 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
64087 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
64088 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
64089 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
64090 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64091 unsigned long start, unsigned long end, gfp_t gfp_mask,
64092 - pgprot_t prot, int node, void *caller);
64093 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64094 extern void vfree(const void *addr);
64095
64096 extern void *vmap(struct page **pages, unsigned int count,
64097 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64098 extern void free_vm_area(struct vm_struct *area);
64099
64100 /* for /dev/kmem */
64101 -extern long vread(char *buf, char *addr, unsigned long count);
64102 -extern long vwrite(char *buf, char *addr, unsigned long count);
64103 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64104 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64105
64106 /*
64107 * Internals. Dont't use..
64108 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64109 index 65efb92..137adbb 100644
64110 --- a/include/linux/vmstat.h
64111 +++ b/include/linux/vmstat.h
64112 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64113 /*
64114 * Zone based page accounting with per cpu differentials.
64115 */
64116 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64117 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64118
64119 static inline void zone_page_state_add(long x, struct zone *zone,
64120 enum zone_stat_item item)
64121 {
64122 - atomic_long_add(x, &zone->vm_stat[item]);
64123 - atomic_long_add(x, &vm_stat[item]);
64124 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64125 + atomic_long_add_unchecked(x, &vm_stat[item]);
64126 }
64127
64128 static inline unsigned long global_page_state(enum zone_stat_item item)
64129 {
64130 - long x = atomic_long_read(&vm_stat[item]);
64131 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64132 #ifdef CONFIG_SMP
64133 if (x < 0)
64134 x = 0;
64135 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64136 static inline unsigned long zone_page_state(struct zone *zone,
64137 enum zone_stat_item item)
64138 {
64139 - long x = atomic_long_read(&zone->vm_stat[item]);
64140 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64141 #ifdef CONFIG_SMP
64142 if (x < 0)
64143 x = 0;
64144 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64145 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64146 enum zone_stat_item item)
64147 {
64148 - long x = atomic_long_read(&zone->vm_stat[item]);
64149 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64150
64151 #ifdef CONFIG_SMP
64152 int cpu;
64153 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64154
64155 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64156 {
64157 - atomic_long_inc(&zone->vm_stat[item]);
64158 - atomic_long_inc(&vm_stat[item]);
64159 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64160 + atomic_long_inc_unchecked(&vm_stat[item]);
64161 }
64162
64163 static inline void __inc_zone_page_state(struct page *page,
64164 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64165
64166 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64167 {
64168 - atomic_long_dec(&zone->vm_stat[item]);
64169 - atomic_long_dec(&vm_stat[item]);
64170 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64171 + atomic_long_dec_unchecked(&vm_stat[item]);
64172 }
64173
64174 static inline void __dec_zone_page_state(struct page *page,
64175 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64176 index e5d1220..ef6e406 100644
64177 --- a/include/linux/xattr.h
64178 +++ b/include/linux/xattr.h
64179 @@ -57,6 +57,11 @@
64180 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64181 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64182
64183 +/* User namespace */
64184 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64185 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64186 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64187 +
64188 #ifdef __KERNEL__
64189
64190 #include <linux/types.h>
64191 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64192 index 4aeff96..b378cdc 100644
64193 --- a/include/media/saa7146_vv.h
64194 +++ b/include/media/saa7146_vv.h
64195 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64196 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64197
64198 /* the extension can override this */
64199 - struct v4l2_ioctl_ops ops;
64200 + v4l2_ioctl_ops_no_const ops;
64201 /* pointer to the saa7146 core ops */
64202 const struct v4l2_ioctl_ops *core_ops;
64203
64204 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64205 index c7c40f1..4f01585 100644
64206 --- a/include/media/v4l2-dev.h
64207 +++ b/include/media/v4l2-dev.h
64208 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64209
64210
64211 struct v4l2_file_operations {
64212 - struct module *owner;
64213 + struct module * const owner;
64214 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64215 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64216 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64217 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64218 int (*open) (struct file *);
64219 int (*release) (struct file *);
64220 };
64221 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64222
64223 /*
64224 * Newer version of video_device, handled by videodev2.c
64225 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64226 index 3f5d60f..44210ed 100644
64227 --- a/include/media/v4l2-ioctl.h
64228 +++ b/include/media/v4l2-ioctl.h
64229 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64230 long (*vidioc_default) (struct file *file, void *fh,
64231 bool valid_prio, int cmd, void *arg);
64232 };
64233 -
64234 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64235
64236 /* v4l debugging and diagnostics */
64237
64238 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64239 index 8d55251..dfe5b0a 100644
64240 --- a/include/net/caif/caif_hsi.h
64241 +++ b/include/net/caif/caif_hsi.h
64242 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64243 void (*rx_done_cb) (struct cfhsi_drv *drv);
64244 void (*wake_up_cb) (struct cfhsi_drv *drv);
64245 void (*wake_down_cb) (struct cfhsi_drv *drv);
64246 -};
64247 +} __no_const;
64248
64249 /* Structure implemented by HSI device. */
64250 struct cfhsi_dev {
64251 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64252 index 9e5425b..8136ffc 100644
64253 --- a/include/net/caif/cfctrl.h
64254 +++ b/include/net/caif/cfctrl.h
64255 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64256 void (*radioset_rsp)(void);
64257 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64258 struct cflayer *client_layer);
64259 -};
64260 +} __no_const;
64261
64262 /* Link Setup Parameters for CAIF-Links. */
64263 struct cfctrl_link_param {
64264 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64265 struct cfctrl {
64266 struct cfsrvl serv;
64267 struct cfctrl_rsp res;
64268 - atomic_t req_seq_no;
64269 - atomic_t rsp_seq_no;
64270 + atomic_unchecked_t req_seq_no;
64271 + atomic_unchecked_t rsp_seq_no;
64272 struct list_head list;
64273 /* Protects from simultaneous access to first_req list */
64274 spinlock_t info_list_lock;
64275 diff --git a/include/net/flow.h b/include/net/flow.h
64276 index 6c469db..7743b8e 100644
64277 --- a/include/net/flow.h
64278 +++ b/include/net/flow.h
64279 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64280
64281 extern void flow_cache_flush(void);
64282 extern void flow_cache_flush_deferred(void);
64283 -extern atomic_t flow_cache_genid;
64284 +extern atomic_unchecked_t flow_cache_genid;
64285
64286 #endif
64287 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64288 index b94765e..053f68b 100644
64289 --- a/include/net/inetpeer.h
64290 +++ b/include/net/inetpeer.h
64291 @@ -48,8 +48,8 @@ struct inet_peer {
64292 */
64293 union {
64294 struct {
64295 - atomic_t rid; /* Frag reception counter */
64296 - atomic_t ip_id_count; /* IP ID for the next packet */
64297 + atomic_unchecked_t rid; /* Frag reception counter */
64298 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64299 __u32 tcp_ts;
64300 __u32 tcp_ts_stamp;
64301 };
64302 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64303 more++;
64304 inet_peer_refcheck(p);
64305 do {
64306 - old = atomic_read(&p->ip_id_count);
64307 + old = atomic_read_unchecked(&p->ip_id_count);
64308 new = old + more;
64309 if (!new)
64310 new = 1;
64311 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64312 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64313 return new;
64314 }
64315
64316 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64317 index 10422ef..662570f 100644
64318 --- a/include/net/ip_fib.h
64319 +++ b/include/net/ip_fib.h
64320 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64321
64322 #define FIB_RES_SADDR(net, res) \
64323 ((FIB_RES_NH(res).nh_saddr_genid == \
64324 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64325 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64326 FIB_RES_NH(res).nh_saddr : \
64327 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64328 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64329 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64330 index ebe517f..1bd286b 100644
64331 --- a/include/net/ip_vs.h
64332 +++ b/include/net/ip_vs.h
64333 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64334 struct ip_vs_conn *control; /* Master control connection */
64335 atomic_t n_control; /* Number of controlled ones */
64336 struct ip_vs_dest *dest; /* real server */
64337 - atomic_t in_pkts; /* incoming packet counter */
64338 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64339
64340 /* packet transmitter for different forwarding methods. If it
64341 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64342 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64343 __be16 port; /* port number of the server */
64344 union nf_inet_addr addr; /* IP address of the server */
64345 volatile unsigned flags; /* dest status flags */
64346 - atomic_t conn_flags; /* flags to copy to conn */
64347 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64348 atomic_t weight; /* server weight */
64349
64350 atomic_t refcnt; /* reference counter */
64351 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64352 index 69b610a..fe3962c 100644
64353 --- a/include/net/irda/ircomm_core.h
64354 +++ b/include/net/irda/ircomm_core.h
64355 @@ -51,7 +51,7 @@ typedef struct {
64356 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64357 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64358 struct ircomm_info *);
64359 -} call_t;
64360 +} __no_const call_t;
64361
64362 struct ircomm_cb {
64363 irda_queue_t queue;
64364 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64365 index 59ba38bc..d515662 100644
64366 --- a/include/net/irda/ircomm_tty.h
64367 +++ b/include/net/irda/ircomm_tty.h
64368 @@ -35,6 +35,7 @@
64369 #include <linux/termios.h>
64370 #include <linux/timer.h>
64371 #include <linux/tty.h> /* struct tty_struct */
64372 +#include <asm/local.h>
64373
64374 #include <net/irda/irias_object.h>
64375 #include <net/irda/ircomm_core.h>
64376 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64377 unsigned short close_delay;
64378 unsigned short closing_wait; /* time to wait before closing */
64379
64380 - int open_count;
64381 - int blocked_open; /* # of blocked opens */
64382 + local_t open_count;
64383 + local_t blocked_open; /* # of blocked opens */
64384
64385 /* Protect concurent access to :
64386 * o self->open_count
64387 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64388 index 0954ec9..7413562 100644
64389 --- a/include/net/iucv/af_iucv.h
64390 +++ b/include/net/iucv/af_iucv.h
64391 @@ -138,7 +138,7 @@ struct iucv_sock {
64392 struct iucv_sock_list {
64393 struct hlist_head head;
64394 rwlock_t lock;
64395 - atomic_t autobind_name;
64396 + atomic_unchecked_t autobind_name;
64397 };
64398
64399 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64400 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64401 index 34c996f..bb3b4d4 100644
64402 --- a/include/net/neighbour.h
64403 +++ b/include/net/neighbour.h
64404 @@ -123,7 +123,7 @@ struct neigh_ops {
64405 void (*error_report)(struct neighbour *, struct sk_buff *);
64406 int (*output)(struct neighbour *, struct sk_buff *);
64407 int (*connected_output)(struct neighbour *, struct sk_buff *);
64408 -};
64409 +} __do_const;
64410
64411 struct pneigh_entry {
64412 struct pneigh_entry *next;
64413 diff --git a/include/net/netlink.h b/include/net/netlink.h
64414 index cb1f350..3279d2c 100644
64415 --- a/include/net/netlink.h
64416 +++ b/include/net/netlink.h
64417 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64418 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64419 {
64420 if (mark)
64421 - skb_trim(skb, (unsigned char *) mark - skb->data);
64422 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64423 }
64424
64425 /**
64426 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64427 index bbd023a..97c6d0d 100644
64428 --- a/include/net/netns/ipv4.h
64429 +++ b/include/net/netns/ipv4.h
64430 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64431 unsigned int sysctl_ping_group_range[2];
64432 long sysctl_tcp_mem[3];
64433
64434 - atomic_t rt_genid;
64435 - atomic_t dev_addr_genid;
64436 + atomic_unchecked_t rt_genid;
64437 + atomic_unchecked_t dev_addr_genid;
64438
64439 #ifdef CONFIG_IP_MROUTE
64440 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64441 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64442 index d368561..96aaa17 100644
64443 --- a/include/net/sctp/sctp.h
64444 +++ b/include/net/sctp/sctp.h
64445 @@ -318,9 +318,9 @@ do { \
64446
64447 #else /* SCTP_DEBUG */
64448
64449 -#define SCTP_DEBUG_PRINTK(whatever...)
64450 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64451 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64452 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64453 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64454 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64455 #define SCTP_ENABLE_DEBUG
64456 #define SCTP_DISABLE_DEBUG
64457 #define SCTP_ASSERT(expr, str, func)
64458 diff --git a/include/net/sock.h b/include/net/sock.h
64459 index 91c1c8b..15ae923 100644
64460 --- a/include/net/sock.h
64461 +++ b/include/net/sock.h
64462 @@ -299,7 +299,7 @@ struct sock {
64463 #ifdef CONFIG_RPS
64464 __u32 sk_rxhash;
64465 #endif
64466 - atomic_t sk_drops;
64467 + atomic_unchecked_t sk_drops;
64468 int sk_rcvbuf;
64469
64470 struct sk_filter __rcu *sk_filter;
64471 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64472 }
64473
64474 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64475 - char __user *from, char *to,
64476 + char __user *from, unsigned char *to,
64477 int copy, int offset)
64478 {
64479 if (skb->ip_summed == CHECKSUM_NONE) {
64480 diff --git a/include/net/tcp.h b/include/net/tcp.h
64481 index 2d80c29..aa07caf 100644
64482 --- a/include/net/tcp.h
64483 +++ b/include/net/tcp.h
64484 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64485 char *name;
64486 sa_family_t family;
64487 const struct file_operations *seq_fops;
64488 - struct seq_operations seq_ops;
64489 + seq_operations_no_const seq_ops;
64490 };
64491
64492 struct tcp_iter_state {
64493 diff --git a/include/net/udp.h b/include/net/udp.h
64494 index e39592f..fef9680 100644
64495 --- a/include/net/udp.h
64496 +++ b/include/net/udp.h
64497 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64498 sa_family_t family;
64499 struct udp_table *udp_table;
64500 const struct file_operations *seq_fops;
64501 - struct seq_operations seq_ops;
64502 + seq_operations_no_const seq_ops;
64503 };
64504
64505 struct udp_iter_state {
64506 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64507 index 89174e2..1f82598 100644
64508 --- a/include/net/xfrm.h
64509 +++ b/include/net/xfrm.h
64510 @@ -505,7 +505,7 @@ struct xfrm_policy {
64511 struct timer_list timer;
64512
64513 struct flow_cache_object flo;
64514 - atomic_t genid;
64515 + atomic_unchecked_t genid;
64516 u32 priority;
64517 u32 index;
64518 struct xfrm_mark mark;
64519 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64520 index 1a046b1..ee0bef0 100644
64521 --- a/include/rdma/iw_cm.h
64522 +++ b/include/rdma/iw_cm.h
64523 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64524 int backlog);
64525
64526 int (*destroy_listen)(struct iw_cm_id *cm_id);
64527 -};
64528 +} __no_const;
64529
64530 /**
64531 * iw_create_cm_id - Create an IW CM identifier.
64532 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64533 index 6a3922f..0b73022 100644
64534 --- a/include/scsi/libfc.h
64535 +++ b/include/scsi/libfc.h
64536 @@ -748,6 +748,7 @@ struct libfc_function_template {
64537 */
64538 void (*disc_stop_final) (struct fc_lport *);
64539 };
64540 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64541
64542 /**
64543 * struct fc_disc - Discovery context
64544 @@ -851,7 +852,7 @@ struct fc_lport {
64545 struct fc_vport *vport;
64546
64547 /* Operational Information */
64548 - struct libfc_function_template tt;
64549 + libfc_function_template_no_const tt;
64550 u8 link_up;
64551 u8 qfull;
64552 enum fc_lport_state state;
64553 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64554 index 77273f2..dd4031f 100644
64555 --- a/include/scsi/scsi_device.h
64556 +++ b/include/scsi/scsi_device.h
64557 @@ -161,9 +161,9 @@ struct scsi_device {
64558 unsigned int max_device_blocked; /* what device_blocked counts down from */
64559 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64560
64561 - atomic_t iorequest_cnt;
64562 - atomic_t iodone_cnt;
64563 - atomic_t ioerr_cnt;
64564 + atomic_unchecked_t iorequest_cnt;
64565 + atomic_unchecked_t iodone_cnt;
64566 + atomic_unchecked_t ioerr_cnt;
64567
64568 struct device sdev_gendev,
64569 sdev_dev;
64570 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64571 index 2a65167..91e01f8 100644
64572 --- a/include/scsi/scsi_transport_fc.h
64573 +++ b/include/scsi/scsi_transport_fc.h
64574 @@ -711,7 +711,7 @@ struct fc_function_template {
64575 unsigned long show_host_system_hostname:1;
64576
64577 unsigned long disable_target_scan:1;
64578 -};
64579 +} __do_const;
64580
64581
64582 /**
64583 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64584 index 030b87c..98a6954 100644
64585 --- a/include/sound/ak4xxx-adda.h
64586 +++ b/include/sound/ak4xxx-adda.h
64587 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64588 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64589 unsigned char val);
64590 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64591 -};
64592 +} __no_const;
64593
64594 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64595
64596 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64597 index 8c05e47..2b5df97 100644
64598 --- a/include/sound/hwdep.h
64599 +++ b/include/sound/hwdep.h
64600 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64601 struct snd_hwdep_dsp_status *status);
64602 int (*dsp_load)(struct snd_hwdep *hw,
64603 struct snd_hwdep_dsp_image *image);
64604 -};
64605 +} __no_const;
64606
64607 struct snd_hwdep {
64608 struct snd_card *card;
64609 diff --git a/include/sound/info.h b/include/sound/info.h
64610 index 9ca1a49..aba1728 100644
64611 --- a/include/sound/info.h
64612 +++ b/include/sound/info.h
64613 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64614 struct snd_info_buffer *buffer);
64615 void (*write)(struct snd_info_entry *entry,
64616 struct snd_info_buffer *buffer);
64617 -};
64618 +} __no_const;
64619
64620 struct snd_info_entry_ops {
64621 int (*open)(struct snd_info_entry *entry,
64622 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64623 index 0cf91b2..b70cae4 100644
64624 --- a/include/sound/pcm.h
64625 +++ b/include/sound/pcm.h
64626 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64627 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64628 int (*ack)(struct snd_pcm_substream *substream);
64629 };
64630 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64631
64632 /*
64633 *
64634 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64635 index af1b49e..a5d55a5 100644
64636 --- a/include/sound/sb16_csp.h
64637 +++ b/include/sound/sb16_csp.h
64638 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64639 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64640 int (*csp_stop) (struct snd_sb_csp * p);
64641 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64642 -};
64643 +} __no_const;
64644
64645 /*
64646 * CSP private data
64647 diff --git a/include/sound/soc.h b/include/sound/soc.h
64648 index 0992dff..bb366fe 100644
64649 --- a/include/sound/soc.h
64650 +++ b/include/sound/soc.h
64651 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64652 /* platform IO - used for platform DAPM */
64653 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64654 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64655 -};
64656 +} __do_const;
64657
64658 struct snd_soc_platform {
64659 const char *name;
64660 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64661 struct snd_soc_dai_link *dai_link;
64662 struct mutex pcm_mutex;
64663 enum snd_soc_pcm_subclass pcm_subclass;
64664 - struct snd_pcm_ops ops;
64665 + snd_pcm_ops_no_const ops;
64666
64667 unsigned int complete:1;
64668 unsigned int dev_registered:1;
64669 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64670 index 444cd6b..3327cc5 100644
64671 --- a/include/sound/ymfpci.h
64672 +++ b/include/sound/ymfpci.h
64673 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64674 spinlock_t reg_lock;
64675 spinlock_t voice_lock;
64676 wait_queue_head_t interrupt_sleep;
64677 - atomic_t interrupt_sleep_count;
64678 + atomic_unchecked_t interrupt_sleep_count;
64679 struct snd_info_entry *proc_entry;
64680 const struct firmware *dsp_microcode;
64681 const struct firmware *controller_microcode;
64682 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64683 index fe73eb8..56388b1 100644
64684 --- a/include/target/target_core_base.h
64685 +++ b/include/target/target_core_base.h
64686 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
64687 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64688 int (*t10_pr_register)(struct se_cmd *);
64689 int (*t10_pr_clear)(struct se_cmd *);
64690 -};
64691 +} __no_const;
64692
64693 struct t10_reservation {
64694 /* Reservation effects all target ports */
64695 @@ -561,8 +561,8 @@ struct se_cmd {
64696 atomic_t t_se_count;
64697 atomic_t t_task_cdbs_left;
64698 atomic_t t_task_cdbs_ex_left;
64699 - atomic_t t_task_cdbs_sent;
64700 - atomic_t t_transport_aborted;
64701 + atomic_unchecked_t t_task_cdbs_sent;
64702 + atomic_unchecked_t t_transport_aborted;
64703 atomic_t t_transport_active;
64704 atomic_t t_transport_complete;
64705 atomic_t t_transport_queue_active;
64706 @@ -799,7 +799,7 @@ struct se_device {
64707 spinlock_t stats_lock;
64708 /* Active commands on this virtual SE device */
64709 atomic_t simple_cmds;
64710 - atomic_t dev_ordered_id;
64711 + atomic_unchecked_t dev_ordered_id;
64712 atomic_t execute_tasks;
64713 atomic_t dev_ordered_sync;
64714 atomic_t dev_qf_count;
64715 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64716 index 1c09820..7f5ec79 100644
64717 --- a/include/trace/events/irq.h
64718 +++ b/include/trace/events/irq.h
64719 @@ -36,7 +36,7 @@ struct softirq_action;
64720 */
64721 TRACE_EVENT(irq_handler_entry,
64722
64723 - TP_PROTO(int irq, struct irqaction *action),
64724 + TP_PROTO(int irq, const struct irqaction *action),
64725
64726 TP_ARGS(irq, action),
64727
64728 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64729 */
64730 TRACE_EVENT(irq_handler_exit,
64731
64732 - TP_PROTO(int irq, struct irqaction *action, int ret),
64733 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64734
64735 TP_ARGS(irq, action, ret),
64736
64737 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64738 index c41f308..6918de3 100644
64739 --- a/include/video/udlfb.h
64740 +++ b/include/video/udlfb.h
64741 @@ -52,10 +52,10 @@ struct dlfb_data {
64742 u32 pseudo_palette[256];
64743 int blank_mode; /*one of FB_BLANK_ */
64744 /* blit-only rendering path metrics, exposed through sysfs */
64745 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64746 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64747 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64748 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64749 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64750 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64751 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64752 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64753 };
64754
64755 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64756 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64757 index 0993a22..32ba2fe 100644
64758 --- a/include/video/uvesafb.h
64759 +++ b/include/video/uvesafb.h
64760 @@ -177,6 +177,7 @@ struct uvesafb_par {
64761 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64762 u8 pmi_setpal; /* PMI for palette changes */
64763 u16 *pmi_base; /* protected mode interface location */
64764 + u8 *pmi_code; /* protected mode code location */
64765 void *pmi_start;
64766 void *pmi_pal;
64767 u8 *vbe_state_orig; /*
64768 diff --git a/init/Kconfig b/init/Kconfig
64769 index 3f42cd6..613f41d 100644
64770 --- a/init/Kconfig
64771 +++ b/init/Kconfig
64772 @@ -799,6 +799,7 @@ endif # CGROUPS
64773
64774 config CHECKPOINT_RESTORE
64775 bool "Checkpoint/restore support" if EXPERT
64776 + depends on !GRKERNSEC
64777 default n
64778 help
64779 Enables additional kernel features in a sake of checkpoint/restore.
64780 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64781
64782 config COMPAT_BRK
64783 bool "Disable heap randomization"
64784 - default y
64785 + default n
64786 help
64787 Randomizing heap placement makes heap exploits harder, but it
64788 also breaks ancient binaries (including anything libc5 based).
64789 diff --git a/init/do_mounts.c b/init/do_mounts.c
64790 index 2974c8b..0b863ae 100644
64791 --- a/init/do_mounts.c
64792 +++ b/init/do_mounts.c
64793 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64794 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64795 {
64796 struct super_block *s;
64797 - int err = sys_mount(name, "/root", fs, flags, data);
64798 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64799 if (err)
64800 return err;
64801
64802 - sys_chdir((const char __user __force *)"/root");
64803 + sys_chdir((const char __force_user *)"/root");
64804 s = current->fs->pwd.dentry->d_sb;
64805 ROOT_DEV = s->s_dev;
64806 printk(KERN_INFO
64807 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64808 va_start(args, fmt);
64809 vsprintf(buf, fmt, args);
64810 va_end(args);
64811 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64812 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64813 if (fd >= 0) {
64814 sys_ioctl(fd, FDEJECT, 0);
64815 sys_close(fd);
64816 }
64817 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64818 - fd = sys_open("/dev/console", O_RDWR, 0);
64819 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64820 if (fd >= 0) {
64821 sys_ioctl(fd, TCGETS, (long)&termios);
64822 termios.c_lflag &= ~ICANON;
64823 sys_ioctl(fd, TCSETSF, (long)&termios);
64824 - sys_read(fd, &c, 1);
64825 + sys_read(fd, (char __user *)&c, 1);
64826 termios.c_lflag |= ICANON;
64827 sys_ioctl(fd, TCSETSF, (long)&termios);
64828 sys_close(fd);
64829 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64830 mount_root();
64831 out:
64832 devtmpfs_mount("dev");
64833 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64834 - sys_chroot((const char __user __force *)".");
64835 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64836 + sys_chroot((const char __force_user *)".");
64837 }
64838 diff --git a/init/do_mounts.h b/init/do_mounts.h
64839 index f5b978a..69dbfe8 100644
64840 --- a/init/do_mounts.h
64841 +++ b/init/do_mounts.h
64842 @@ -15,15 +15,15 @@ extern int root_mountflags;
64843
64844 static inline int create_dev(char *name, dev_t dev)
64845 {
64846 - sys_unlink(name);
64847 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64848 + sys_unlink((char __force_user *)name);
64849 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64850 }
64851
64852 #if BITS_PER_LONG == 32
64853 static inline u32 bstat(char *name)
64854 {
64855 struct stat64 stat;
64856 - if (sys_stat64(name, &stat) != 0)
64857 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64858 return 0;
64859 if (!S_ISBLK(stat.st_mode))
64860 return 0;
64861 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64862 static inline u32 bstat(char *name)
64863 {
64864 struct stat stat;
64865 - if (sys_newstat(name, &stat) != 0)
64866 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64867 return 0;
64868 if (!S_ISBLK(stat.st_mode))
64869 return 0;
64870 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64871 index 3098a38..253064e 100644
64872 --- a/init/do_mounts_initrd.c
64873 +++ b/init/do_mounts_initrd.c
64874 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64875 create_dev("/dev/root.old", Root_RAM0);
64876 /* mount initrd on rootfs' /root */
64877 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64878 - sys_mkdir("/old", 0700);
64879 - root_fd = sys_open("/", 0, 0);
64880 - old_fd = sys_open("/old", 0, 0);
64881 + sys_mkdir((const char __force_user *)"/old", 0700);
64882 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64883 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64884 /* move initrd over / and chdir/chroot in initrd root */
64885 - sys_chdir("/root");
64886 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64887 - sys_chroot(".");
64888 + sys_chdir((const char __force_user *)"/root");
64889 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64890 + sys_chroot((const char __force_user *)".");
64891
64892 /*
64893 * In case that a resume from disk is carried out by linuxrc or one of
64894 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64895
64896 /* move initrd to rootfs' /old */
64897 sys_fchdir(old_fd);
64898 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64899 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64900 /* switch root and cwd back to / of rootfs */
64901 sys_fchdir(root_fd);
64902 - sys_chroot(".");
64903 + sys_chroot((const char __force_user *)".");
64904 sys_close(old_fd);
64905 sys_close(root_fd);
64906
64907 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64908 - sys_chdir("/old");
64909 + sys_chdir((const char __force_user *)"/old");
64910 return;
64911 }
64912
64913 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64914 mount_root();
64915
64916 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64917 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64918 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64919 if (!error)
64920 printk("okay\n");
64921 else {
64922 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64923 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64924 if (error == -ENOENT)
64925 printk("/initrd does not exist. Ignored.\n");
64926 else
64927 printk("failed\n");
64928 printk(KERN_NOTICE "Unmounting old root\n");
64929 - sys_umount("/old", MNT_DETACH);
64930 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64931 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64932 if (fd < 0) {
64933 error = fd;
64934 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64935 * mounted in the normal path.
64936 */
64937 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64938 - sys_unlink("/initrd.image");
64939 + sys_unlink((const char __force_user *)"/initrd.image");
64940 handle_initrd();
64941 return 1;
64942 }
64943 }
64944 - sys_unlink("/initrd.image");
64945 + sys_unlink((const char __force_user *)"/initrd.image");
64946 return 0;
64947 }
64948 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64949 index 32c4799..c27ee74 100644
64950 --- a/init/do_mounts_md.c
64951 +++ b/init/do_mounts_md.c
64952 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64953 partitioned ? "_d" : "", minor,
64954 md_setup_args[ent].device_names);
64955
64956 - fd = sys_open(name, 0, 0);
64957 + fd = sys_open((char __force_user *)name, 0, 0);
64958 if (fd < 0) {
64959 printk(KERN_ERR "md: open failed - cannot start "
64960 "array %s\n", name);
64961 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64962 * array without it
64963 */
64964 sys_close(fd);
64965 - fd = sys_open(name, 0, 0);
64966 + fd = sys_open((char __force_user *)name, 0, 0);
64967 sys_ioctl(fd, BLKRRPART, 0);
64968 }
64969 sys_close(fd);
64970 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64971
64972 wait_for_device_probe();
64973
64974 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64975 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64976 if (fd >= 0) {
64977 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64978 sys_close(fd);
64979 diff --git a/init/initramfs.c b/init/initramfs.c
64980 index 8216c30..25e8e32 100644
64981 --- a/init/initramfs.c
64982 +++ b/init/initramfs.c
64983 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64984 }
64985 }
64986
64987 -static long __init do_utime(char __user *filename, time_t mtime)
64988 +static long __init do_utime(__force char __user *filename, time_t mtime)
64989 {
64990 struct timespec t[2];
64991
64992 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64993 struct dir_entry *de, *tmp;
64994 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64995 list_del(&de->list);
64996 - do_utime(de->name, de->mtime);
64997 + do_utime((char __force_user *)de->name, de->mtime);
64998 kfree(de->name);
64999 kfree(de);
65000 }
65001 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
65002 if (nlink >= 2) {
65003 char *old = find_link(major, minor, ino, mode, collected);
65004 if (old)
65005 - return (sys_link(old, collected) < 0) ? -1 : 1;
65006 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65007 }
65008 return 0;
65009 }
65010 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
65011 {
65012 struct stat st;
65013
65014 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65015 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65016 if (S_ISDIR(st.st_mode))
65017 - sys_rmdir(path);
65018 + sys_rmdir((char __force_user *)path);
65019 else
65020 - sys_unlink(path);
65021 + sys_unlink((char __force_user *)path);
65022 }
65023 }
65024
65025 @@ -305,7 +305,7 @@ static int __init do_name(void)
65026 int openflags = O_WRONLY|O_CREAT;
65027 if (ml != 1)
65028 openflags |= O_TRUNC;
65029 - wfd = sys_open(collected, openflags, mode);
65030 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65031
65032 if (wfd >= 0) {
65033 sys_fchown(wfd, uid, gid);
65034 @@ -317,17 +317,17 @@ static int __init do_name(void)
65035 }
65036 }
65037 } else if (S_ISDIR(mode)) {
65038 - sys_mkdir(collected, mode);
65039 - sys_chown(collected, uid, gid);
65040 - sys_chmod(collected, mode);
65041 + sys_mkdir((char __force_user *)collected, mode);
65042 + sys_chown((char __force_user *)collected, uid, gid);
65043 + sys_chmod((char __force_user *)collected, mode);
65044 dir_add(collected, mtime);
65045 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65046 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65047 if (maybe_link() == 0) {
65048 - sys_mknod(collected, mode, rdev);
65049 - sys_chown(collected, uid, gid);
65050 - sys_chmod(collected, mode);
65051 - do_utime(collected, mtime);
65052 + sys_mknod((char __force_user *)collected, mode, rdev);
65053 + sys_chown((char __force_user *)collected, uid, gid);
65054 + sys_chmod((char __force_user *)collected, mode);
65055 + do_utime((char __force_user *)collected, mtime);
65056 }
65057 }
65058 return 0;
65059 @@ -336,15 +336,15 @@ static int __init do_name(void)
65060 static int __init do_copy(void)
65061 {
65062 if (count >= body_len) {
65063 - sys_write(wfd, victim, body_len);
65064 + sys_write(wfd, (char __force_user *)victim, body_len);
65065 sys_close(wfd);
65066 - do_utime(vcollected, mtime);
65067 + do_utime((char __force_user *)vcollected, mtime);
65068 kfree(vcollected);
65069 eat(body_len);
65070 state = SkipIt;
65071 return 0;
65072 } else {
65073 - sys_write(wfd, victim, count);
65074 + sys_write(wfd, (char __force_user *)victim, count);
65075 body_len -= count;
65076 eat(count);
65077 return 1;
65078 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
65079 {
65080 collected[N_ALIGN(name_len) + body_len] = '\0';
65081 clean_path(collected, 0);
65082 - sys_symlink(collected + N_ALIGN(name_len), collected);
65083 - sys_lchown(collected, uid, gid);
65084 - do_utime(collected, mtime);
65085 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65086 + sys_lchown((char __force_user *)collected, uid, gid);
65087 + do_utime((char __force_user *)collected, mtime);
65088 state = SkipIt;
65089 next_state = Reset;
65090 return 0;
65091 diff --git a/init/main.c b/init/main.c
65092 index ff49a6d..5fa0429 100644
65093 --- a/init/main.c
65094 +++ b/init/main.c
65095 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65096 extern void tc_init(void);
65097 #endif
65098
65099 +extern void grsecurity_init(void);
65100 +
65101 /*
65102 * Debug helper: via this flag we know that we are in 'early bootup code'
65103 * where only the boot processor is running with IRQ disabled. This means
65104 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65105
65106 __setup("reset_devices", set_reset_devices);
65107
65108 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65109 +extern char pax_enter_kernel_user[];
65110 +extern char pax_exit_kernel_user[];
65111 +extern pgdval_t clone_pgd_mask;
65112 +#endif
65113 +
65114 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65115 +static int __init setup_pax_nouderef(char *str)
65116 +{
65117 +#ifdef CONFIG_X86_32
65118 + unsigned int cpu;
65119 + struct desc_struct *gdt;
65120 +
65121 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65122 + gdt = get_cpu_gdt_table(cpu);
65123 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65124 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65125 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65126 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65127 + }
65128 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65129 +#else
65130 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65131 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65132 + clone_pgd_mask = ~(pgdval_t)0UL;
65133 +#endif
65134 +
65135 + return 0;
65136 +}
65137 +early_param("pax_nouderef", setup_pax_nouderef);
65138 +#endif
65139 +
65140 +#ifdef CONFIG_PAX_SOFTMODE
65141 +int pax_softmode;
65142 +
65143 +static int __init setup_pax_softmode(char *str)
65144 +{
65145 + get_option(&str, &pax_softmode);
65146 + return 1;
65147 +}
65148 +__setup("pax_softmode=", setup_pax_softmode);
65149 +#endif
65150 +
65151 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65152 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65153 static const char *panic_later, *panic_param;
65154 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65155 {
65156 int count = preempt_count();
65157 int ret;
65158 + const char *msg1 = "", *msg2 = "";
65159
65160 if (initcall_debug)
65161 ret = do_one_initcall_debug(fn);
65162 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65163 sprintf(msgbuf, "error code %d ", ret);
65164
65165 if (preempt_count() != count) {
65166 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65167 + msg1 = " preemption imbalance";
65168 preempt_count() = count;
65169 }
65170 if (irqs_disabled()) {
65171 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65172 + msg2 = " disabled interrupts";
65173 local_irq_enable();
65174 }
65175 - if (msgbuf[0]) {
65176 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65177 + if (msgbuf[0] || *msg1 || *msg2) {
65178 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65179 }
65180
65181 return ret;
65182 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65183 do_basic_setup();
65184
65185 /* Open the /dev/console on the rootfs, this should never fail */
65186 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65187 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65188 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65189
65190 (void) sys_dup(0);
65191 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65192 if (!ramdisk_execute_command)
65193 ramdisk_execute_command = "/init";
65194
65195 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65196 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65197 ramdisk_execute_command = NULL;
65198 prepare_namespace();
65199 }
65200
65201 + grsecurity_init();
65202 +
65203 /*
65204 * Ok, we have completed the initial bootup, and
65205 * we're essentially up and running. Get rid of the
65206 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65207 index 86ee272..773d937 100644
65208 --- a/ipc/mqueue.c
65209 +++ b/ipc/mqueue.c
65210 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65211 mq_bytes = (mq_msg_tblsz +
65212 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65213
65214 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65215 spin_lock(&mq_lock);
65216 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65217 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65218 diff --git a/ipc/msg.c b/ipc/msg.c
65219 index 7385de2..a8180e08 100644
65220 --- a/ipc/msg.c
65221 +++ b/ipc/msg.c
65222 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65223 return security_msg_queue_associate(msq, msgflg);
65224 }
65225
65226 +static struct ipc_ops msg_ops = {
65227 + .getnew = newque,
65228 + .associate = msg_security,
65229 + .more_checks = NULL
65230 +};
65231 +
65232 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65233 {
65234 struct ipc_namespace *ns;
65235 - struct ipc_ops msg_ops;
65236 struct ipc_params msg_params;
65237
65238 ns = current->nsproxy->ipc_ns;
65239
65240 - msg_ops.getnew = newque;
65241 - msg_ops.associate = msg_security;
65242 - msg_ops.more_checks = NULL;
65243 -
65244 msg_params.key = key;
65245 msg_params.flg = msgflg;
65246
65247 diff --git a/ipc/sem.c b/ipc/sem.c
65248 index 5215a81..cfc0cac 100644
65249 --- a/ipc/sem.c
65250 +++ b/ipc/sem.c
65251 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65252 return 0;
65253 }
65254
65255 +static struct ipc_ops sem_ops = {
65256 + .getnew = newary,
65257 + .associate = sem_security,
65258 + .more_checks = sem_more_checks
65259 +};
65260 +
65261 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65262 {
65263 struct ipc_namespace *ns;
65264 - struct ipc_ops sem_ops;
65265 struct ipc_params sem_params;
65266
65267 ns = current->nsproxy->ipc_ns;
65268 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65269 if (nsems < 0 || nsems > ns->sc_semmsl)
65270 return -EINVAL;
65271
65272 - sem_ops.getnew = newary;
65273 - sem_ops.associate = sem_security;
65274 - sem_ops.more_checks = sem_more_checks;
65275 -
65276 sem_params.key = key;
65277 sem_params.flg = semflg;
65278 sem_params.u.nsems = nsems;
65279 diff --git a/ipc/shm.c b/ipc/shm.c
65280 index b76be5b..859e750 100644
65281 --- a/ipc/shm.c
65282 +++ b/ipc/shm.c
65283 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65284 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65285 #endif
65286
65287 +#ifdef CONFIG_GRKERNSEC
65288 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65289 + const time_t shm_createtime, const uid_t cuid,
65290 + const int shmid);
65291 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65292 + const time_t shm_createtime);
65293 +#endif
65294 +
65295 void shm_init_ns(struct ipc_namespace *ns)
65296 {
65297 ns->shm_ctlmax = SHMMAX;
65298 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65299 shp->shm_lprid = 0;
65300 shp->shm_atim = shp->shm_dtim = 0;
65301 shp->shm_ctim = get_seconds();
65302 +#ifdef CONFIG_GRKERNSEC
65303 + {
65304 + struct timespec timeval;
65305 + do_posix_clock_monotonic_gettime(&timeval);
65306 +
65307 + shp->shm_createtime = timeval.tv_sec;
65308 + }
65309 +#endif
65310 shp->shm_segsz = size;
65311 shp->shm_nattch = 0;
65312 shp->shm_file = file;
65313 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65314 return 0;
65315 }
65316
65317 +static struct ipc_ops shm_ops = {
65318 + .getnew = newseg,
65319 + .associate = shm_security,
65320 + .more_checks = shm_more_checks
65321 +};
65322 +
65323 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65324 {
65325 struct ipc_namespace *ns;
65326 - struct ipc_ops shm_ops;
65327 struct ipc_params shm_params;
65328
65329 ns = current->nsproxy->ipc_ns;
65330
65331 - shm_ops.getnew = newseg;
65332 - shm_ops.associate = shm_security;
65333 - shm_ops.more_checks = shm_more_checks;
65334 -
65335 shm_params.key = key;
65336 shm_params.flg = shmflg;
65337 shm_params.u.size = size;
65338 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65339 f_mode = FMODE_READ | FMODE_WRITE;
65340 }
65341 if (shmflg & SHM_EXEC) {
65342 +
65343 +#ifdef CONFIG_PAX_MPROTECT
65344 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65345 + goto out;
65346 +#endif
65347 +
65348 prot |= PROT_EXEC;
65349 acc_mode |= S_IXUGO;
65350 }
65351 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65352 if (err)
65353 goto out_unlock;
65354
65355 +#ifdef CONFIG_GRKERNSEC
65356 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65357 + shp->shm_perm.cuid, shmid) ||
65358 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65359 + err = -EACCES;
65360 + goto out_unlock;
65361 + }
65362 +#endif
65363 +
65364 path = shp->shm_file->f_path;
65365 path_get(&path);
65366 shp->shm_nattch++;
65367 +#ifdef CONFIG_GRKERNSEC
65368 + shp->shm_lapid = current->pid;
65369 +#endif
65370 size = i_size_read(path.dentry->d_inode);
65371 shm_unlock(shp);
65372
65373 diff --git a/kernel/acct.c b/kernel/acct.c
65374 index 02e6167..54824f7 100644
65375 --- a/kernel/acct.c
65376 +++ b/kernel/acct.c
65377 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65378 */
65379 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65380 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65381 - file->f_op->write(file, (char *)&ac,
65382 + file->f_op->write(file, (char __force_user *)&ac,
65383 sizeof(acct_t), &file->f_pos);
65384 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65385 set_fs(fs);
65386 diff --git a/kernel/audit.c b/kernel/audit.c
65387 index bb0eb5b..cf2a03a 100644
65388 --- a/kernel/audit.c
65389 +++ b/kernel/audit.c
65390 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65391 3) suppressed due to audit_rate_limit
65392 4) suppressed due to audit_backlog_limit
65393 */
65394 -static atomic_t audit_lost = ATOMIC_INIT(0);
65395 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65396
65397 /* The netlink socket. */
65398 static struct sock *audit_sock;
65399 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65400 unsigned long now;
65401 int print;
65402
65403 - atomic_inc(&audit_lost);
65404 + atomic_inc_unchecked(&audit_lost);
65405
65406 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65407
65408 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65409 printk(KERN_WARNING
65410 "audit: audit_lost=%d audit_rate_limit=%d "
65411 "audit_backlog_limit=%d\n",
65412 - atomic_read(&audit_lost),
65413 + atomic_read_unchecked(&audit_lost),
65414 audit_rate_limit,
65415 audit_backlog_limit);
65416 audit_panic(message);
65417 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65418 status_set.pid = audit_pid;
65419 status_set.rate_limit = audit_rate_limit;
65420 status_set.backlog_limit = audit_backlog_limit;
65421 - status_set.lost = atomic_read(&audit_lost);
65422 + status_set.lost = atomic_read_unchecked(&audit_lost);
65423 status_set.backlog = skb_queue_len(&audit_skb_queue);
65424 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65425 &status_set, sizeof(status_set));
65426 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65427 index af1de0f..06dfe57 100644
65428 --- a/kernel/auditsc.c
65429 +++ b/kernel/auditsc.c
65430 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65431 }
65432
65433 /* global counter which is incremented every time something logs in */
65434 -static atomic_t session_id = ATOMIC_INIT(0);
65435 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65436
65437 /**
65438 * audit_set_loginuid - set current task's audit_context loginuid
65439 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65440 return -EPERM;
65441 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65442
65443 - sessionid = atomic_inc_return(&session_id);
65444 + sessionid = atomic_inc_return_unchecked(&session_id);
65445 if (context && context->in_syscall) {
65446 struct audit_buffer *ab;
65447
65448 diff --git a/kernel/capability.c b/kernel/capability.c
65449 index 3f1adb6..c564db0 100644
65450 --- a/kernel/capability.c
65451 +++ b/kernel/capability.c
65452 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65453 * before modification is attempted and the application
65454 * fails.
65455 */
65456 + if (tocopy > ARRAY_SIZE(kdata))
65457 + return -EFAULT;
65458 +
65459 if (copy_to_user(dataptr, kdata, tocopy
65460 * sizeof(struct __user_cap_data_struct))) {
65461 return -EFAULT;
65462 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65463 int ret;
65464
65465 rcu_read_lock();
65466 - ret = security_capable(__task_cred(t), ns, cap);
65467 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65468 + gr_task_is_capable(t, __task_cred(t), cap);
65469 rcu_read_unlock();
65470
65471 - return (ret == 0);
65472 + return ret;
65473 }
65474
65475 /**
65476 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65477 int ret;
65478
65479 rcu_read_lock();
65480 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65481 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65482 rcu_read_unlock();
65483
65484 - return (ret == 0);
65485 + return ret;
65486 }
65487
65488 /**
65489 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65490 BUG();
65491 }
65492
65493 - if (security_capable(current_cred(), ns, cap) == 0) {
65494 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65495 current->flags |= PF_SUPERPRIV;
65496 return true;
65497 }
65498 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65499 }
65500 EXPORT_SYMBOL(ns_capable);
65501
65502 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65503 +{
65504 + if (unlikely(!cap_valid(cap))) {
65505 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65506 + BUG();
65507 + }
65508 +
65509 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65510 + current->flags |= PF_SUPERPRIV;
65511 + return true;
65512 + }
65513 + return false;
65514 +}
65515 +EXPORT_SYMBOL(ns_capable_nolog);
65516 +
65517 /**
65518 * capable - Determine if the current task has a superior capability in effect
65519 * @cap: The capability to be tested for
65520 @@ -408,6 +427,12 @@ bool capable(int cap)
65521 }
65522 EXPORT_SYMBOL(capable);
65523
65524 +bool capable_nolog(int cap)
65525 +{
65526 + return ns_capable_nolog(&init_user_ns, cap);
65527 +}
65528 +EXPORT_SYMBOL(capable_nolog);
65529 +
65530 /**
65531 * nsown_capable - Check superior capability to one's own user_ns
65532 * @cap: The capability in question
65533 diff --git a/kernel/compat.c b/kernel/compat.c
65534 index f346ced..aa2b1f4 100644
65535 --- a/kernel/compat.c
65536 +++ b/kernel/compat.c
65537 @@ -13,6 +13,7 @@
65538
65539 #include <linux/linkage.h>
65540 #include <linux/compat.h>
65541 +#include <linux/module.h>
65542 #include <linux/errno.h>
65543 #include <linux/time.h>
65544 #include <linux/signal.h>
65545 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65546 mm_segment_t oldfs;
65547 long ret;
65548
65549 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65550 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65551 oldfs = get_fs();
65552 set_fs(KERNEL_DS);
65553 ret = hrtimer_nanosleep_restart(restart);
65554 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65555 oldfs = get_fs();
65556 set_fs(KERNEL_DS);
65557 ret = hrtimer_nanosleep(&tu,
65558 - rmtp ? (struct timespec __user *)&rmt : NULL,
65559 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65560 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65561 set_fs(oldfs);
65562
65563 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65564 mm_segment_t old_fs = get_fs();
65565
65566 set_fs(KERNEL_DS);
65567 - ret = sys_sigpending((old_sigset_t __user *) &s);
65568 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65569 set_fs(old_fs);
65570 if (ret == 0)
65571 ret = put_user(s, set);
65572 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65573 old_fs = get_fs();
65574 set_fs(KERNEL_DS);
65575 ret = sys_sigprocmask(how,
65576 - set ? (old_sigset_t __user *) &s : NULL,
65577 - oset ? (old_sigset_t __user *) &s : NULL);
65578 + set ? (old_sigset_t __force_user *) &s : NULL,
65579 + oset ? (old_sigset_t __force_user *) &s : NULL);
65580 set_fs(old_fs);
65581 if (ret == 0)
65582 if (oset)
65583 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65584 mm_segment_t old_fs = get_fs();
65585
65586 set_fs(KERNEL_DS);
65587 - ret = sys_old_getrlimit(resource, &r);
65588 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65589 set_fs(old_fs);
65590
65591 if (!ret) {
65592 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65593 mm_segment_t old_fs = get_fs();
65594
65595 set_fs(KERNEL_DS);
65596 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65597 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65598 set_fs(old_fs);
65599
65600 if (ret)
65601 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65602 set_fs (KERNEL_DS);
65603 ret = sys_wait4(pid,
65604 (stat_addr ?
65605 - (unsigned int __user *) &status : NULL),
65606 - options, (struct rusage __user *) &r);
65607 + (unsigned int __force_user *) &status : NULL),
65608 + options, (struct rusage __force_user *) &r);
65609 set_fs (old_fs);
65610
65611 if (ret > 0) {
65612 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65613 memset(&info, 0, sizeof(info));
65614
65615 set_fs(KERNEL_DS);
65616 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65617 - uru ? (struct rusage __user *)&ru : NULL);
65618 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65619 + uru ? (struct rusage __force_user *)&ru : NULL);
65620 set_fs(old_fs);
65621
65622 if ((ret < 0) || (info.si_signo == 0))
65623 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65624 oldfs = get_fs();
65625 set_fs(KERNEL_DS);
65626 err = sys_timer_settime(timer_id, flags,
65627 - (struct itimerspec __user *) &newts,
65628 - (struct itimerspec __user *) &oldts);
65629 + (struct itimerspec __force_user *) &newts,
65630 + (struct itimerspec __force_user *) &oldts);
65631 set_fs(oldfs);
65632 if (!err && old && put_compat_itimerspec(old, &oldts))
65633 return -EFAULT;
65634 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65635 oldfs = get_fs();
65636 set_fs(KERNEL_DS);
65637 err = sys_timer_gettime(timer_id,
65638 - (struct itimerspec __user *) &ts);
65639 + (struct itimerspec __force_user *) &ts);
65640 set_fs(oldfs);
65641 if (!err && put_compat_itimerspec(setting, &ts))
65642 return -EFAULT;
65643 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65644 oldfs = get_fs();
65645 set_fs(KERNEL_DS);
65646 err = sys_clock_settime(which_clock,
65647 - (struct timespec __user *) &ts);
65648 + (struct timespec __force_user *) &ts);
65649 set_fs(oldfs);
65650 return err;
65651 }
65652 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65653 oldfs = get_fs();
65654 set_fs(KERNEL_DS);
65655 err = sys_clock_gettime(which_clock,
65656 - (struct timespec __user *) &ts);
65657 + (struct timespec __force_user *) &ts);
65658 set_fs(oldfs);
65659 if (!err && put_compat_timespec(&ts, tp))
65660 return -EFAULT;
65661 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65662
65663 oldfs = get_fs();
65664 set_fs(KERNEL_DS);
65665 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65666 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65667 set_fs(oldfs);
65668
65669 err = compat_put_timex(utp, &txc);
65670 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65671 oldfs = get_fs();
65672 set_fs(KERNEL_DS);
65673 err = sys_clock_getres(which_clock,
65674 - (struct timespec __user *) &ts);
65675 + (struct timespec __force_user *) &ts);
65676 set_fs(oldfs);
65677 if (!err && tp && put_compat_timespec(&ts, tp))
65678 return -EFAULT;
65679 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65680 long err;
65681 mm_segment_t oldfs;
65682 struct timespec tu;
65683 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65684 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65685
65686 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65687 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65688 oldfs = get_fs();
65689 set_fs(KERNEL_DS);
65690 err = clock_nanosleep_restart(restart);
65691 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65692 oldfs = get_fs();
65693 set_fs(KERNEL_DS);
65694 err = sys_clock_nanosleep(which_clock, flags,
65695 - (struct timespec __user *) &in,
65696 - (struct timespec __user *) &out);
65697 + (struct timespec __force_user *) &in,
65698 + (struct timespec __force_user *) &out);
65699 set_fs(oldfs);
65700
65701 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65702 diff --git a/kernel/configs.c b/kernel/configs.c
65703 index 42e8fa0..9e7406b 100644
65704 --- a/kernel/configs.c
65705 +++ b/kernel/configs.c
65706 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65707 struct proc_dir_entry *entry;
65708
65709 /* create the current config file */
65710 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65711 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65712 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65713 + &ikconfig_file_ops);
65714 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65715 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65716 + &ikconfig_file_ops);
65717 +#endif
65718 +#else
65719 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65720 &ikconfig_file_ops);
65721 +#endif
65722 +
65723 if (!entry)
65724 return -ENOMEM;
65725
65726 diff --git a/kernel/cred.c b/kernel/cred.c
65727 index 48c6fd3..3342f00 100644
65728 --- a/kernel/cred.c
65729 +++ b/kernel/cred.c
65730 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65731 validate_creds(cred);
65732 put_cred(cred);
65733 }
65734 +
65735 +#ifdef CONFIG_GRKERNSEC_SETXID
65736 + cred = (struct cred *) tsk->delayed_cred;
65737 + if (cred) {
65738 + tsk->delayed_cred = NULL;
65739 + validate_creds(cred);
65740 + put_cred(cred);
65741 + }
65742 +#endif
65743 }
65744
65745 /**
65746 @@ -472,7 +481,7 @@ error_put:
65747 * Always returns 0 thus allowing this function to be tail-called at the end
65748 * of, say, sys_setgid().
65749 */
65750 -int commit_creds(struct cred *new)
65751 +static int __commit_creds(struct cred *new)
65752 {
65753 struct task_struct *task = current;
65754 const struct cred *old = task->real_cred;
65755 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65756
65757 get_cred(new); /* we will require a ref for the subj creds too */
65758
65759 + gr_set_role_label(task, new->uid, new->gid);
65760 +
65761 /* dumpability changes */
65762 if (old->euid != new->euid ||
65763 old->egid != new->egid ||
65764 @@ -540,6 +551,92 @@ int commit_creds(struct cred *new)
65765 put_cred(old);
65766 return 0;
65767 }
65768 +#ifdef CONFIG_GRKERNSEC_SETXID
65769 +extern int set_user(struct cred *new);
65770 +
65771 +void gr_delayed_cred_worker(void)
65772 +{
65773 + const struct cred *new = current->delayed_cred;
65774 + struct cred *ncred;
65775 +
65776 + current->delayed_cred = NULL;
65777 +
65778 + if (current_uid() && new != NULL) {
65779 + // from doing get_cred on it when queueing this
65780 + put_cred(new);
65781 + return;
65782 + } else if (new == NULL)
65783 + return;
65784 +
65785 + ncred = prepare_creds();
65786 + if (!ncred)
65787 + goto die;
65788 + // uids
65789 + ncred->uid = new->uid;
65790 + ncred->euid = new->euid;
65791 + ncred->suid = new->suid;
65792 + ncred->fsuid = new->fsuid;
65793 + // gids
65794 + ncred->gid = new->gid;
65795 + ncred->egid = new->egid;
65796 + ncred->sgid = new->sgid;
65797 + ncred->fsgid = new->fsgid;
65798 + // groups
65799 + if (set_groups(ncred, new->group_info) < 0) {
65800 + abort_creds(ncred);
65801 + goto die;
65802 + }
65803 + // caps
65804 + ncred->securebits = new->securebits;
65805 + ncred->cap_inheritable = new->cap_inheritable;
65806 + ncred->cap_permitted = new->cap_permitted;
65807 + ncred->cap_effective = new->cap_effective;
65808 + ncred->cap_bset = new->cap_bset;
65809 +
65810 + if (set_user(ncred)) {
65811 + abort_creds(ncred);
65812 + goto die;
65813 + }
65814 +
65815 + // from doing get_cred on it when queueing this
65816 + put_cred(new);
65817 +
65818 + __commit_creds(ncred);
65819 + return;
65820 +die:
65821 + // from doing get_cred on it when queueing this
65822 + put_cred(new);
65823 + do_group_exit(SIGKILL);
65824 +}
65825 +#endif
65826 +
65827 +int commit_creds(struct cred *new)
65828 +{
65829 +#ifdef CONFIG_GRKERNSEC_SETXID
65830 + struct task_struct *t;
65831 +
65832 + /* we won't get called with tasklist_lock held for writing
65833 + and interrupts disabled as the cred struct in that case is
65834 + init_cred
65835 + */
65836 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65837 + !current_uid() && new->uid) {
65838 + rcu_read_lock();
65839 + read_lock(&tasklist_lock);
65840 + for (t = next_thread(current); t != current;
65841 + t = next_thread(t)) {
65842 + if (t->delayed_cred == NULL) {
65843 + t->delayed_cred = get_cred(new);
65844 + set_tsk_need_resched(t);
65845 + }
65846 + }
65847 + read_unlock(&tasklist_lock);
65848 + rcu_read_unlock();
65849 + }
65850 +#endif
65851 + return __commit_creds(new);
65852 +}
65853 +
65854 EXPORT_SYMBOL(commit_creds);
65855
65856 /**
65857 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65858 index 7fda904..59f620c 100644
65859 --- a/kernel/debug/debug_core.c
65860 +++ b/kernel/debug/debug_core.c
65861 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65862 */
65863 static atomic_t masters_in_kgdb;
65864 static atomic_t slaves_in_kgdb;
65865 -static atomic_t kgdb_break_tasklet_var;
65866 +static atomic_unchecked_t kgdb_break_tasklet_var;
65867 atomic_t kgdb_setting_breakpoint;
65868
65869 struct task_struct *kgdb_usethread;
65870 @@ -129,7 +129,7 @@ int kgdb_single_step;
65871 static pid_t kgdb_sstep_pid;
65872
65873 /* to keep track of the CPU which is doing the single stepping*/
65874 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65875 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65876
65877 /*
65878 * If you are debugging a problem where roundup (the collection of
65879 @@ -537,7 +537,7 @@ return_normal:
65880 * kernel will only try for the value of sstep_tries before
65881 * giving up and continuing on.
65882 */
65883 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65884 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65885 (kgdb_info[cpu].task &&
65886 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65887 atomic_set(&kgdb_active, -1);
65888 @@ -631,8 +631,8 @@ cpu_master_loop:
65889 }
65890
65891 kgdb_restore:
65892 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65893 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65894 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65895 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65896 if (kgdb_info[sstep_cpu].task)
65897 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65898 else
65899 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65900 static void kgdb_tasklet_bpt(unsigned long ing)
65901 {
65902 kgdb_breakpoint();
65903 - atomic_set(&kgdb_break_tasklet_var, 0);
65904 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65905 }
65906
65907 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65908
65909 void kgdb_schedule_breakpoint(void)
65910 {
65911 - if (atomic_read(&kgdb_break_tasklet_var) ||
65912 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65913 atomic_read(&kgdb_active) != -1 ||
65914 atomic_read(&kgdb_setting_breakpoint))
65915 return;
65916 - atomic_inc(&kgdb_break_tasklet_var);
65917 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65918 tasklet_schedule(&kgdb_tasklet_breakpoint);
65919 }
65920 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65921 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65922 index e2ae734..08a4c5c 100644
65923 --- a/kernel/debug/kdb/kdb_main.c
65924 +++ b/kernel/debug/kdb/kdb_main.c
65925 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65926 list_for_each_entry(mod, kdb_modules, list) {
65927
65928 kdb_printf("%-20s%8u 0x%p ", mod->name,
65929 - mod->core_size, (void *)mod);
65930 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65931 #ifdef CONFIG_MODULE_UNLOAD
65932 kdb_printf("%4ld ", module_refcount(mod));
65933 #endif
65934 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65935 kdb_printf(" (Loading)");
65936 else
65937 kdb_printf(" (Live)");
65938 - kdb_printf(" 0x%p", mod->module_core);
65939 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65940
65941 #ifdef CONFIG_MODULE_UNLOAD
65942 {
65943 diff --git a/kernel/events/core.c b/kernel/events/core.c
65944 index 1b5c081..c375f83 100644
65945 --- a/kernel/events/core.c
65946 +++ b/kernel/events/core.c
65947 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65948 return 0;
65949 }
65950
65951 -static atomic64_t perf_event_id;
65952 +static atomic64_unchecked_t perf_event_id;
65953
65954 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65955 enum event_type_t event_type);
65956 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65957
65958 static inline u64 perf_event_count(struct perf_event *event)
65959 {
65960 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65961 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65962 }
65963
65964 static u64 perf_event_read(struct perf_event *event)
65965 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65966 mutex_lock(&event->child_mutex);
65967 total += perf_event_read(event);
65968 *enabled += event->total_time_enabled +
65969 - atomic64_read(&event->child_total_time_enabled);
65970 + atomic64_read_unchecked(&event->child_total_time_enabled);
65971 *running += event->total_time_running +
65972 - atomic64_read(&event->child_total_time_running);
65973 + atomic64_read_unchecked(&event->child_total_time_running);
65974
65975 list_for_each_entry(child, &event->child_list, child_list) {
65976 total += perf_event_read(child);
65977 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65978 userpg->offset -= local64_read(&event->hw.prev_count);
65979
65980 userpg->time_enabled = enabled +
65981 - atomic64_read(&event->child_total_time_enabled);
65982 + atomic64_read_unchecked(&event->child_total_time_enabled);
65983
65984 userpg->time_running = running +
65985 - atomic64_read(&event->child_total_time_running);
65986 + atomic64_read_unchecked(&event->child_total_time_running);
65987
65988 barrier();
65989 ++userpg->lock;
65990 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65991 values[n++] = perf_event_count(event);
65992 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65993 values[n++] = enabled +
65994 - atomic64_read(&event->child_total_time_enabled);
65995 + atomic64_read_unchecked(&event->child_total_time_enabled);
65996 }
65997 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65998 values[n++] = running +
65999 - atomic64_read(&event->child_total_time_running);
66000 + atomic64_read_unchecked(&event->child_total_time_running);
66001 }
66002 if (read_format & PERF_FORMAT_ID)
66003 values[n++] = primary_event_id(event);
66004 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66005 * need to add enough zero bytes after the string to handle
66006 * the 64bit alignment we do later.
66007 */
66008 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66009 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66010 if (!buf) {
66011 name = strncpy(tmp, "//enomem", sizeof(tmp));
66012 goto got_name;
66013 }
66014 - name = d_path(&file->f_path, buf, PATH_MAX);
66015 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66016 if (IS_ERR(name)) {
66017 name = strncpy(tmp, "//toolong", sizeof(tmp));
66018 goto got_name;
66019 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66020 event->parent = parent_event;
66021
66022 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66023 - event->id = atomic64_inc_return(&perf_event_id);
66024 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66025
66026 event->state = PERF_EVENT_STATE_INACTIVE;
66027
66028 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
66029 /*
66030 * Add back the child's count to the parent's count:
66031 */
66032 - atomic64_add(child_val, &parent_event->child_count);
66033 - atomic64_add(child_event->total_time_enabled,
66034 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66035 + atomic64_add_unchecked(child_event->total_time_enabled,
66036 &parent_event->child_total_time_enabled);
66037 - atomic64_add(child_event->total_time_running,
66038 + atomic64_add_unchecked(child_event->total_time_running,
66039 &parent_event->child_total_time_running);
66040
66041 /*
66042 diff --git a/kernel/exit.c b/kernel/exit.c
66043 index 4b4042f..5bdd8d5 100644
66044 --- a/kernel/exit.c
66045 +++ b/kernel/exit.c
66046 @@ -58,6 +58,10 @@
66047 #include <asm/pgtable.h>
66048 #include <asm/mmu_context.h>
66049
66050 +#ifdef CONFIG_GRKERNSEC
66051 +extern rwlock_t grsec_exec_file_lock;
66052 +#endif
66053 +
66054 static void exit_mm(struct task_struct * tsk);
66055
66056 static void __unhash_process(struct task_struct *p, bool group_dead)
66057 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
66058 struct task_struct *leader;
66059 int zap_leader;
66060 repeat:
66061 +#ifdef CONFIG_NET
66062 + gr_del_task_from_ip_table(p);
66063 +#endif
66064 +
66065 /* don't need to get the RCU readlock here - the process is dead and
66066 * can't be modifying its own credentials. But shut RCU-lockdep up */
66067 rcu_read_lock();
66068 @@ -381,7 +389,7 @@ int allow_signal(int sig)
66069 * know it'll be handled, so that they don't get converted to
66070 * SIGKILL or just silently dropped.
66071 */
66072 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66073 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66074 recalc_sigpending();
66075 spin_unlock_irq(&current->sighand->siglock);
66076 return 0;
66077 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
66078 vsnprintf(current->comm, sizeof(current->comm), name, args);
66079 va_end(args);
66080
66081 +#ifdef CONFIG_GRKERNSEC
66082 + write_lock(&grsec_exec_file_lock);
66083 + if (current->exec_file) {
66084 + fput(current->exec_file);
66085 + current->exec_file = NULL;
66086 + }
66087 + write_unlock(&grsec_exec_file_lock);
66088 +#endif
66089 +
66090 + gr_set_kernel_label(current);
66091 +
66092 /*
66093 * If we were started as result of loading a module, close all of the
66094 * user space pages. We don't need them, and if we didn't close them
66095 @@ -892,6 +911,8 @@ void do_exit(long code)
66096 struct task_struct *tsk = current;
66097 int group_dead;
66098
66099 + set_fs(USER_DS);
66100 +
66101 profile_task_exit(tsk);
66102
66103 WARN_ON(blk_needs_flush_plug(tsk));
66104 @@ -908,7 +929,6 @@ void do_exit(long code)
66105 * mm_release()->clear_child_tid() from writing to a user-controlled
66106 * kernel address.
66107 */
66108 - set_fs(USER_DS);
66109
66110 ptrace_event(PTRACE_EVENT_EXIT, code);
66111
66112 @@ -969,6 +989,9 @@ void do_exit(long code)
66113 tsk->exit_code = code;
66114 taskstats_exit(tsk, group_dead);
66115
66116 + gr_acl_handle_psacct(tsk, code);
66117 + gr_acl_handle_exit();
66118 +
66119 exit_mm(tsk);
66120
66121 if (group_dead)
66122 @@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66123 * Take down every thread in the group. This is called by fatal signals
66124 * as well as by sys_exit_group (below).
66125 */
66126 -void
66127 +__noreturn void
66128 do_group_exit(int exit_code)
66129 {
66130 struct signal_struct *sig = current->signal;
66131 diff --git a/kernel/fork.c b/kernel/fork.c
66132 index 26a7a67..a1053f9 100644
66133 --- a/kernel/fork.c
66134 +++ b/kernel/fork.c
66135 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66136 *stackend = STACK_END_MAGIC; /* for overflow detection */
66137
66138 #ifdef CONFIG_CC_STACKPROTECTOR
66139 - tsk->stack_canary = get_random_int();
66140 + tsk->stack_canary = pax_get_random_long();
66141 #endif
66142
66143 /*
66144 @@ -308,13 +308,77 @@ out:
66145 }
66146
66147 #ifdef CONFIG_MMU
66148 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66149 +{
66150 + struct vm_area_struct *tmp;
66151 + unsigned long charge;
66152 + struct mempolicy *pol;
66153 + struct file *file;
66154 +
66155 + charge = 0;
66156 + if (mpnt->vm_flags & VM_ACCOUNT) {
66157 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66158 + if (security_vm_enough_memory(len))
66159 + goto fail_nomem;
66160 + charge = len;
66161 + }
66162 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66163 + if (!tmp)
66164 + goto fail_nomem;
66165 + *tmp = *mpnt;
66166 + tmp->vm_mm = mm;
66167 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66168 + pol = mpol_dup(vma_policy(mpnt));
66169 + if (IS_ERR(pol))
66170 + goto fail_nomem_policy;
66171 + vma_set_policy(tmp, pol);
66172 + if (anon_vma_fork(tmp, mpnt))
66173 + goto fail_nomem_anon_vma_fork;
66174 + tmp->vm_flags &= ~VM_LOCKED;
66175 + tmp->vm_next = tmp->vm_prev = NULL;
66176 + tmp->vm_mirror = NULL;
66177 + file = tmp->vm_file;
66178 + if (file) {
66179 + struct inode *inode = file->f_path.dentry->d_inode;
66180 + struct address_space *mapping = file->f_mapping;
66181 +
66182 + get_file(file);
66183 + if (tmp->vm_flags & VM_DENYWRITE)
66184 + atomic_dec(&inode->i_writecount);
66185 + mutex_lock(&mapping->i_mmap_mutex);
66186 + if (tmp->vm_flags & VM_SHARED)
66187 + mapping->i_mmap_writable++;
66188 + flush_dcache_mmap_lock(mapping);
66189 + /* insert tmp into the share list, just after mpnt */
66190 + vma_prio_tree_add(tmp, mpnt);
66191 + flush_dcache_mmap_unlock(mapping);
66192 + mutex_unlock(&mapping->i_mmap_mutex);
66193 + }
66194 +
66195 + /*
66196 + * Clear hugetlb-related page reserves for children. This only
66197 + * affects MAP_PRIVATE mappings. Faults generated by the child
66198 + * are not guaranteed to succeed, even if read-only
66199 + */
66200 + if (is_vm_hugetlb_page(tmp))
66201 + reset_vma_resv_huge_pages(tmp);
66202 +
66203 + return tmp;
66204 +
66205 +fail_nomem_anon_vma_fork:
66206 + mpol_put(pol);
66207 +fail_nomem_policy:
66208 + kmem_cache_free(vm_area_cachep, tmp);
66209 +fail_nomem:
66210 + vm_unacct_memory(charge);
66211 + return NULL;
66212 +}
66213 +
66214 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66215 {
66216 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66217 struct rb_node **rb_link, *rb_parent;
66218 int retval;
66219 - unsigned long charge;
66220 - struct mempolicy *pol;
66221
66222 down_write(&oldmm->mmap_sem);
66223 flush_cache_dup_mm(oldmm);
66224 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66225 mm->locked_vm = 0;
66226 mm->mmap = NULL;
66227 mm->mmap_cache = NULL;
66228 - mm->free_area_cache = oldmm->mmap_base;
66229 - mm->cached_hole_size = ~0UL;
66230 + mm->free_area_cache = oldmm->free_area_cache;
66231 + mm->cached_hole_size = oldmm->cached_hole_size;
66232 mm->map_count = 0;
66233 cpumask_clear(mm_cpumask(mm));
66234 mm->mm_rb = RB_ROOT;
66235 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66236
66237 prev = NULL;
66238 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66239 - struct file *file;
66240 -
66241 if (mpnt->vm_flags & VM_DONTCOPY) {
66242 long pages = vma_pages(mpnt);
66243 mm->total_vm -= pages;
66244 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66245 -pages);
66246 continue;
66247 }
66248 - charge = 0;
66249 - if (mpnt->vm_flags & VM_ACCOUNT) {
66250 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66251 - if (security_vm_enough_memory(len))
66252 - goto fail_nomem;
66253 - charge = len;
66254 + tmp = dup_vma(mm, mpnt);
66255 + if (!tmp) {
66256 + retval = -ENOMEM;
66257 + goto out;
66258 }
66259 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66260 - if (!tmp)
66261 - goto fail_nomem;
66262 - *tmp = *mpnt;
66263 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66264 - pol = mpol_dup(vma_policy(mpnt));
66265 - retval = PTR_ERR(pol);
66266 - if (IS_ERR(pol))
66267 - goto fail_nomem_policy;
66268 - vma_set_policy(tmp, pol);
66269 - tmp->vm_mm = mm;
66270 - if (anon_vma_fork(tmp, mpnt))
66271 - goto fail_nomem_anon_vma_fork;
66272 - tmp->vm_flags &= ~VM_LOCKED;
66273 - tmp->vm_next = tmp->vm_prev = NULL;
66274 - file = tmp->vm_file;
66275 - if (file) {
66276 - struct inode *inode = file->f_path.dentry->d_inode;
66277 - struct address_space *mapping = file->f_mapping;
66278 -
66279 - get_file(file);
66280 - if (tmp->vm_flags & VM_DENYWRITE)
66281 - atomic_dec(&inode->i_writecount);
66282 - mutex_lock(&mapping->i_mmap_mutex);
66283 - if (tmp->vm_flags & VM_SHARED)
66284 - mapping->i_mmap_writable++;
66285 - flush_dcache_mmap_lock(mapping);
66286 - /* insert tmp into the share list, just after mpnt */
66287 - vma_prio_tree_add(tmp, mpnt);
66288 - flush_dcache_mmap_unlock(mapping);
66289 - mutex_unlock(&mapping->i_mmap_mutex);
66290 - }
66291 -
66292 - /*
66293 - * Clear hugetlb-related page reserves for children. This only
66294 - * affects MAP_PRIVATE mappings. Faults generated by the child
66295 - * are not guaranteed to succeed, even if read-only
66296 - */
66297 - if (is_vm_hugetlb_page(tmp))
66298 - reset_vma_resv_huge_pages(tmp);
66299
66300 /*
66301 * Link in the new vma and copy the page table entries.
66302 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66303 if (retval)
66304 goto out;
66305 }
66306 +
66307 +#ifdef CONFIG_PAX_SEGMEXEC
66308 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66309 + struct vm_area_struct *mpnt_m;
66310 +
66311 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66312 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66313 +
66314 + if (!mpnt->vm_mirror)
66315 + continue;
66316 +
66317 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66318 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66319 + mpnt->vm_mirror = mpnt_m;
66320 + } else {
66321 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66322 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66323 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66324 + mpnt->vm_mirror->vm_mirror = mpnt;
66325 + }
66326 + }
66327 + BUG_ON(mpnt_m);
66328 + }
66329 +#endif
66330 +
66331 /* a new mm has just been created */
66332 arch_dup_mmap(oldmm, mm);
66333 retval = 0;
66334 @@ -429,14 +474,6 @@ out:
66335 flush_tlb_mm(oldmm);
66336 up_write(&oldmm->mmap_sem);
66337 return retval;
66338 -fail_nomem_anon_vma_fork:
66339 - mpol_put(pol);
66340 -fail_nomem_policy:
66341 - kmem_cache_free(vm_area_cachep, tmp);
66342 -fail_nomem:
66343 - retval = -ENOMEM;
66344 - vm_unacct_memory(charge);
66345 - goto out;
66346 }
66347
66348 static inline int mm_alloc_pgd(struct mm_struct *mm)
66349 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66350 return ERR_PTR(err);
66351
66352 mm = get_task_mm(task);
66353 - if (mm && mm != current->mm &&
66354 - !ptrace_may_access(task, mode)) {
66355 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66356 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66357 mmput(mm);
66358 mm = ERR_PTR(-EACCES);
66359 }
66360 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66361 spin_unlock(&fs->lock);
66362 return -EAGAIN;
66363 }
66364 - fs->users++;
66365 + atomic_inc(&fs->users);
66366 spin_unlock(&fs->lock);
66367 return 0;
66368 }
66369 tsk->fs = copy_fs_struct(fs);
66370 if (!tsk->fs)
66371 return -ENOMEM;
66372 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66373 return 0;
66374 }
66375
66376 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66377 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66378 #endif
66379 retval = -EAGAIN;
66380 +
66381 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66382 +
66383 if (atomic_read(&p->real_cred->user->processes) >=
66384 task_rlimit(p, RLIMIT_NPROC)) {
66385 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66386 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66387 if (clone_flags & CLONE_THREAD)
66388 p->tgid = current->tgid;
66389
66390 + gr_copy_label(p);
66391 +
66392 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66393 /*
66394 * Clear TID on mm_release()?
66395 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
66396 bad_fork_free:
66397 free_task(p);
66398 fork_out:
66399 + gr_log_forkfail(retval);
66400 +
66401 return ERR_PTR(retval);
66402 }
66403
66404 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
66405 if (clone_flags & CLONE_PARENT_SETTID)
66406 put_user(nr, parent_tidptr);
66407
66408 + gr_handle_brute_check();
66409 +
66410 if (clone_flags & CLONE_VFORK) {
66411 p->vfork_done = &vfork;
66412 init_completion(&vfork);
66413 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66414 return 0;
66415
66416 /* don't need lock here; in the worst case we'll do useless copy */
66417 - if (fs->users == 1)
66418 + if (atomic_read(&fs->users) == 1)
66419 return 0;
66420
66421 *new_fsp = copy_fs_struct(fs);
66422 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66423 fs = current->fs;
66424 spin_lock(&fs->lock);
66425 current->fs = new_fs;
66426 - if (--fs->users)
66427 + gr_set_chroot_entries(current, &current->fs->root);
66428 + if (atomic_dec_return(&fs->users))
66429 new_fs = NULL;
66430 else
66431 new_fs = fs;
66432 diff --git a/kernel/futex.c b/kernel/futex.c
66433 index 0677023..f3c3b79 100644
66434 --- a/kernel/futex.c
66435 +++ b/kernel/futex.c
66436 @@ -54,6 +54,7 @@
66437 #include <linux/mount.h>
66438 #include <linux/pagemap.h>
66439 #include <linux/syscalls.h>
66440 +#include <linux/ptrace.h>
66441 #include <linux/signal.h>
66442 #include <linux/export.h>
66443 #include <linux/magic.h>
66444 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66445 struct page *page, *page_head;
66446 int err, ro = 0;
66447
66448 +#ifdef CONFIG_PAX_SEGMEXEC
66449 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66450 + return -EFAULT;
66451 +#endif
66452 +
66453 /*
66454 * The futex address must be "naturally" aligned.
66455 */
66456 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66457 if (!p)
66458 goto err_unlock;
66459 ret = -EPERM;
66460 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66461 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66462 + goto err_unlock;
66463 +#endif
66464 pcred = __task_cred(p);
66465 /* If victim is in different user_ns, then uids are not
66466 comparable, so we must have CAP_SYS_PTRACE */
66467 @@ -2731,6 +2741,7 @@ static int __init futex_init(void)
66468 {
66469 u32 curval;
66470 int i;
66471 + mm_segment_t oldfs;
66472
66473 /*
66474 * This will fail and we want it. Some arch implementations do
66475 @@ -2742,8 +2753,11 @@ static int __init futex_init(void)
66476 * implementation, the non-functional ones will return
66477 * -ENOSYS.
66478 */
66479 + oldfs = get_fs();
66480 + set_fs(USER_DS);
66481 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66482 futex_cmpxchg_enabled = 1;
66483 + set_fs(oldfs);
66484
66485 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66486 plist_head_init(&futex_queues[i].chain);
66487 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66488 index 5f9e689..582d46d 100644
66489 --- a/kernel/futex_compat.c
66490 +++ b/kernel/futex_compat.c
66491 @@ -10,6 +10,7 @@
66492 #include <linux/compat.h>
66493 #include <linux/nsproxy.h>
66494 #include <linux/futex.h>
66495 +#include <linux/ptrace.h>
66496
66497 #include <asm/uaccess.h>
66498
66499 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66500 {
66501 struct compat_robust_list_head __user *head;
66502 unsigned long ret;
66503 - const struct cred *cred = current_cred(), *pcred;
66504 + const struct cred *cred = current_cred();
66505 + const struct cred *pcred;
66506
66507 if (!futex_cmpxchg_enabled)
66508 return -ENOSYS;
66509 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66510 if (!p)
66511 goto err_unlock;
66512 ret = -EPERM;
66513 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66514 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66515 + goto err_unlock;
66516 +#endif
66517 pcred = __task_cred(p);
66518 /* If victim is in different user_ns, then uids are not
66519 comparable, so we must have CAP_SYS_PTRACE */
66520 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66521 index 9b22d03..6295b62 100644
66522 --- a/kernel/gcov/base.c
66523 +++ b/kernel/gcov/base.c
66524 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66525 }
66526
66527 #ifdef CONFIG_MODULES
66528 -static inline int within(void *addr, void *start, unsigned long size)
66529 -{
66530 - return ((addr >= start) && (addr < start + size));
66531 -}
66532 -
66533 /* Update list and generate events when modules are unloaded. */
66534 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66535 void *data)
66536 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66537 prev = NULL;
66538 /* Remove entries located in module from linked list. */
66539 for (info = gcov_info_head; info; info = info->next) {
66540 - if (within(info, mod->module_core, mod->core_size)) {
66541 + if (within_module_core_rw((unsigned long)info, mod)) {
66542 if (prev)
66543 prev->next = info->next;
66544 else
66545 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66546 index ae34bf5..4e2f3d0 100644
66547 --- a/kernel/hrtimer.c
66548 +++ b/kernel/hrtimer.c
66549 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66550 local_irq_restore(flags);
66551 }
66552
66553 -static void run_hrtimer_softirq(struct softirq_action *h)
66554 +static void run_hrtimer_softirq(void)
66555 {
66556 hrtimer_peek_ahead_timers();
66557 }
66558 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66559 index 01d3b70..9e4d098 100644
66560 --- a/kernel/jump_label.c
66561 +++ b/kernel/jump_label.c
66562 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66563
66564 size = (((unsigned long)stop - (unsigned long)start)
66565 / sizeof(struct jump_entry));
66566 + pax_open_kernel();
66567 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66568 + pax_close_kernel();
66569 }
66570
66571 static void jump_label_update(struct jump_label_key *key, int enable);
66572 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66573 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66574 struct jump_entry *iter;
66575
66576 + pax_open_kernel();
66577 for (iter = iter_start; iter < iter_stop; iter++) {
66578 if (within_module_init(iter->code, mod))
66579 iter->code = 0;
66580 }
66581 + pax_close_kernel();
66582 }
66583
66584 static int
66585 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66586 index 079f1d3..a407562 100644
66587 --- a/kernel/kallsyms.c
66588 +++ b/kernel/kallsyms.c
66589 @@ -11,6 +11,9 @@
66590 * Changed the compression method from stem compression to "table lookup"
66591 * compression (see scripts/kallsyms.c for a more complete description)
66592 */
66593 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66594 +#define __INCLUDED_BY_HIDESYM 1
66595 +#endif
66596 #include <linux/kallsyms.h>
66597 #include <linux/module.h>
66598 #include <linux/init.h>
66599 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66600
66601 static inline int is_kernel_inittext(unsigned long addr)
66602 {
66603 + if (system_state != SYSTEM_BOOTING)
66604 + return 0;
66605 +
66606 if (addr >= (unsigned long)_sinittext
66607 && addr <= (unsigned long)_einittext)
66608 return 1;
66609 return 0;
66610 }
66611
66612 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66613 +#ifdef CONFIG_MODULES
66614 +static inline int is_module_text(unsigned long addr)
66615 +{
66616 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66617 + return 1;
66618 +
66619 + addr = ktla_ktva(addr);
66620 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66621 +}
66622 +#else
66623 +static inline int is_module_text(unsigned long addr)
66624 +{
66625 + return 0;
66626 +}
66627 +#endif
66628 +#endif
66629 +
66630 static inline int is_kernel_text(unsigned long addr)
66631 {
66632 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66633 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66634
66635 static inline int is_kernel(unsigned long addr)
66636 {
66637 +
66638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66639 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66640 + return 1;
66641 +
66642 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66643 +#else
66644 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66645 +#endif
66646 +
66647 return 1;
66648 return in_gate_area_no_mm(addr);
66649 }
66650
66651 static int is_ksym_addr(unsigned long addr)
66652 {
66653 +
66654 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66655 + if (is_module_text(addr))
66656 + return 0;
66657 +#endif
66658 +
66659 if (all_var)
66660 return is_kernel(addr);
66661
66662 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66663
66664 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66665 {
66666 - iter->name[0] = '\0';
66667 iter->nameoff = get_symbol_offset(new_pos);
66668 iter->pos = new_pos;
66669 }
66670 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66671 {
66672 struct kallsym_iter *iter = m->private;
66673
66674 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66675 + if (current_uid())
66676 + return 0;
66677 +#endif
66678 +
66679 /* Some debugging symbols have no name. Ignore them. */
66680 if (!iter->name[0])
66681 return 0;
66682 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66683 struct kallsym_iter *iter;
66684 int ret;
66685
66686 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66687 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66688 if (!iter)
66689 return -ENOMEM;
66690 reset_iter(iter, 0);
66691 diff --git a/kernel/kexec.c b/kernel/kexec.c
66692 index 7b08867..3bac516 100644
66693 --- a/kernel/kexec.c
66694 +++ b/kernel/kexec.c
66695 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66696 unsigned long flags)
66697 {
66698 struct compat_kexec_segment in;
66699 - struct kexec_segment out, __user *ksegments;
66700 + struct kexec_segment out;
66701 + struct kexec_segment __user *ksegments;
66702 unsigned long i, result;
66703
66704 /* Don't allow clients that don't understand the native
66705 diff --git a/kernel/kmod.c b/kernel/kmod.c
66706 index a3a46cb..f2e42f8 100644
66707 --- a/kernel/kmod.c
66708 +++ b/kernel/kmod.c
66709 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66710 * If module auto-loading support is disabled then this function
66711 * becomes a no-operation.
66712 */
66713 -int __request_module(bool wait, const char *fmt, ...)
66714 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66715 {
66716 - va_list args;
66717 char module_name[MODULE_NAME_LEN];
66718 unsigned int max_modprobes;
66719 int ret;
66720 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66721 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66722 static char *envp[] = { "HOME=/",
66723 "TERM=linux",
66724 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66725 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66726 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66727 static int kmod_loop_msg;
66728
66729 - va_start(args, fmt);
66730 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66731 - va_end(args);
66732 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66733 if (ret >= MODULE_NAME_LEN)
66734 return -ENAMETOOLONG;
66735
66736 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66737 if (ret)
66738 return ret;
66739
66740 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66741 + if (!current_uid()) {
66742 + /* hack to workaround consolekit/udisks stupidity */
66743 + read_lock(&tasklist_lock);
66744 + if (!strcmp(current->comm, "mount") &&
66745 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66746 + read_unlock(&tasklist_lock);
66747 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66748 + return -EPERM;
66749 + }
66750 + read_unlock(&tasklist_lock);
66751 + }
66752 +#endif
66753 +
66754 /* If modprobe needs a service that is in a module, we get a recursive
66755 * loop. Limit the number of running kmod threads to max_threads/2 or
66756 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66757 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66758 atomic_dec(&kmod_concurrent);
66759 return ret;
66760 }
66761 +
66762 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66763 +{
66764 + va_list args;
66765 + int ret;
66766 +
66767 + va_start(args, fmt);
66768 + ret = ____request_module(wait, module_param, fmt, args);
66769 + va_end(args);
66770 +
66771 + return ret;
66772 +}
66773 +
66774 +int __request_module(bool wait, const char *fmt, ...)
66775 +{
66776 + va_list args;
66777 + int ret;
66778 +
66779 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66780 + if (current_uid()) {
66781 + char module_param[MODULE_NAME_LEN];
66782 +
66783 + memset(module_param, 0, sizeof(module_param));
66784 +
66785 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66786 +
66787 + va_start(args, fmt);
66788 + ret = ____request_module(wait, module_param, fmt, args);
66789 + va_end(args);
66790 +
66791 + return ret;
66792 + }
66793 +#endif
66794 +
66795 + va_start(args, fmt);
66796 + ret = ____request_module(wait, NULL, fmt, args);
66797 + va_end(args);
66798 +
66799 + return ret;
66800 +}
66801 +
66802 EXPORT_SYMBOL(__request_module);
66803 #endif /* CONFIG_MODULES */
66804
66805 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66806 *
66807 * Thus the __user pointer cast is valid here.
66808 */
66809 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66810 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66811
66812 /*
66813 * If ret is 0, either ____call_usermodehelper failed and the
66814 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66815 index c62b854..cb67968 100644
66816 --- a/kernel/kprobes.c
66817 +++ b/kernel/kprobes.c
66818 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66819 * kernel image and loaded module images reside. This is required
66820 * so x86_64 can correctly handle the %rip-relative fixups.
66821 */
66822 - kip->insns = module_alloc(PAGE_SIZE);
66823 + kip->insns = module_alloc_exec(PAGE_SIZE);
66824 if (!kip->insns) {
66825 kfree(kip);
66826 return NULL;
66827 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66828 */
66829 if (!list_is_singular(&kip->list)) {
66830 list_del(&kip->list);
66831 - module_free(NULL, kip->insns);
66832 + module_free_exec(NULL, kip->insns);
66833 kfree(kip);
66834 }
66835 return 1;
66836 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66837 {
66838 int i, err = 0;
66839 unsigned long offset = 0, size = 0;
66840 - char *modname, namebuf[128];
66841 + char *modname, namebuf[KSYM_NAME_LEN];
66842 const char *symbol_name;
66843 void *addr;
66844 struct kprobe_blackpoint *kb;
66845 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66846 const char *sym = NULL;
66847 unsigned int i = *(loff_t *) v;
66848 unsigned long offset = 0;
66849 - char *modname, namebuf[128];
66850 + char *modname, namebuf[KSYM_NAME_LEN];
66851
66852 head = &kprobe_table[i];
66853 preempt_disable();
66854 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66855 index 4e316e1..5501eef 100644
66856 --- a/kernel/ksysfs.c
66857 +++ b/kernel/ksysfs.c
66858 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66859 {
66860 if (count+1 > UEVENT_HELPER_PATH_LEN)
66861 return -ENOENT;
66862 + if (!capable(CAP_SYS_ADMIN))
66863 + return -EPERM;
66864 memcpy(uevent_helper, buf, count);
66865 uevent_helper[count] = '\0';
66866 if (count && uevent_helper[count-1] == '\n')
66867 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66868 index 8889f7d..95319b7 100644
66869 --- a/kernel/lockdep.c
66870 +++ b/kernel/lockdep.c
66871 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66872 end = (unsigned long) &_end,
66873 addr = (unsigned long) obj;
66874
66875 +#ifdef CONFIG_PAX_KERNEXEC
66876 + start = ktla_ktva(start);
66877 +#endif
66878 +
66879 /*
66880 * static variable?
66881 */
66882 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66883 if (!static_obj(lock->key)) {
66884 debug_locks_off();
66885 printk("INFO: trying to register non-static key.\n");
66886 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66887 printk("the code is fine but needs lockdep annotation.\n");
66888 printk("turning off the locking correctness validator.\n");
66889 dump_stack();
66890 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66891 if (!class)
66892 return 0;
66893 }
66894 - atomic_inc((atomic_t *)&class->ops);
66895 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66896 if (very_verbose(class)) {
66897 printk("\nacquire class [%p] %s", class->key, class->name);
66898 if (class->name_version > 1)
66899 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66900 index 91c32a0..b2c71c5 100644
66901 --- a/kernel/lockdep_proc.c
66902 +++ b/kernel/lockdep_proc.c
66903 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66904
66905 static void print_name(struct seq_file *m, struct lock_class *class)
66906 {
66907 - char str[128];
66908 + char str[KSYM_NAME_LEN];
66909 const char *name = class->name;
66910
66911 if (!name) {
66912 diff --git a/kernel/module.c b/kernel/module.c
66913 index 3d56b6f..2a22bd0 100644
66914 --- a/kernel/module.c
66915 +++ b/kernel/module.c
66916 @@ -58,6 +58,7 @@
66917 #include <linux/jump_label.h>
66918 #include <linux/pfn.h>
66919 #include <linux/bsearch.h>
66920 +#include <linux/grsecurity.h>
66921
66922 #define CREATE_TRACE_POINTS
66923 #include <trace/events/module.h>
66924 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66925
66926 /* Bounds of module allocation, for speeding __module_address.
66927 * Protected by module_mutex. */
66928 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66929 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66930 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66931
66932 int register_module_notifier(struct notifier_block * nb)
66933 {
66934 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66935 return true;
66936
66937 list_for_each_entry_rcu(mod, &modules, list) {
66938 - struct symsearch arr[] = {
66939 + struct symsearch modarr[] = {
66940 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66941 NOT_GPL_ONLY, false },
66942 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66943 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66944 #endif
66945 };
66946
66947 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66948 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66949 return true;
66950 }
66951 return false;
66952 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66953 static int percpu_modalloc(struct module *mod,
66954 unsigned long size, unsigned long align)
66955 {
66956 - if (align > PAGE_SIZE) {
66957 + if (align-1 >= PAGE_SIZE) {
66958 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66959 mod->name, align, PAGE_SIZE);
66960 align = PAGE_SIZE;
66961 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66962 static ssize_t show_coresize(struct module_attribute *mattr,
66963 struct module_kobject *mk, char *buffer)
66964 {
66965 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66966 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66967 }
66968
66969 static struct module_attribute modinfo_coresize =
66970 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66971 static ssize_t show_initsize(struct module_attribute *mattr,
66972 struct module_kobject *mk, char *buffer)
66973 {
66974 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66975 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66976 }
66977
66978 static struct module_attribute modinfo_initsize =
66979 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66980 */
66981 #ifdef CONFIG_SYSFS
66982
66983 -#ifdef CONFIG_KALLSYMS
66984 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66985 static inline bool sect_empty(const Elf_Shdr *sect)
66986 {
66987 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66988 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66989
66990 static void unset_module_core_ro_nx(struct module *mod)
66991 {
66992 - set_page_attributes(mod->module_core + mod->core_text_size,
66993 - mod->module_core + mod->core_size,
66994 + set_page_attributes(mod->module_core_rw,
66995 + mod->module_core_rw + mod->core_size_rw,
66996 set_memory_x);
66997 - set_page_attributes(mod->module_core,
66998 - mod->module_core + mod->core_ro_size,
66999 + set_page_attributes(mod->module_core_rx,
67000 + mod->module_core_rx + mod->core_size_rx,
67001 set_memory_rw);
67002 }
67003
67004 static void unset_module_init_ro_nx(struct module *mod)
67005 {
67006 - set_page_attributes(mod->module_init + mod->init_text_size,
67007 - mod->module_init + mod->init_size,
67008 + set_page_attributes(mod->module_init_rw,
67009 + mod->module_init_rw + mod->init_size_rw,
67010 set_memory_x);
67011 - set_page_attributes(mod->module_init,
67012 - mod->module_init + mod->init_ro_size,
67013 + set_page_attributes(mod->module_init_rx,
67014 + mod->module_init_rx + mod->init_size_rx,
67015 set_memory_rw);
67016 }
67017
67018 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
67019
67020 mutex_lock(&module_mutex);
67021 list_for_each_entry_rcu(mod, &modules, list) {
67022 - if ((mod->module_core) && (mod->core_text_size)) {
67023 - set_page_attributes(mod->module_core,
67024 - mod->module_core + mod->core_text_size,
67025 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67026 + set_page_attributes(mod->module_core_rx,
67027 + mod->module_core_rx + mod->core_size_rx,
67028 set_memory_rw);
67029 }
67030 - if ((mod->module_init) && (mod->init_text_size)) {
67031 - set_page_attributes(mod->module_init,
67032 - mod->module_init + mod->init_text_size,
67033 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67034 + set_page_attributes(mod->module_init_rx,
67035 + mod->module_init_rx + mod->init_size_rx,
67036 set_memory_rw);
67037 }
67038 }
67039 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
67040
67041 mutex_lock(&module_mutex);
67042 list_for_each_entry_rcu(mod, &modules, list) {
67043 - if ((mod->module_core) && (mod->core_text_size)) {
67044 - set_page_attributes(mod->module_core,
67045 - mod->module_core + mod->core_text_size,
67046 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67047 + set_page_attributes(mod->module_core_rx,
67048 + mod->module_core_rx + mod->core_size_rx,
67049 set_memory_ro);
67050 }
67051 - if ((mod->module_init) && (mod->init_text_size)) {
67052 - set_page_attributes(mod->module_init,
67053 - mod->module_init + mod->init_text_size,
67054 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67055 + set_page_attributes(mod->module_init_rx,
67056 + mod->module_init_rx + mod->init_size_rx,
67057 set_memory_ro);
67058 }
67059 }
67060 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
67061
67062 /* This may be NULL, but that's OK */
67063 unset_module_init_ro_nx(mod);
67064 - module_free(mod, mod->module_init);
67065 + module_free(mod, mod->module_init_rw);
67066 + module_free_exec(mod, mod->module_init_rx);
67067 kfree(mod->args);
67068 percpu_modfree(mod);
67069
67070 /* Free lock-classes: */
67071 - lockdep_free_key_range(mod->module_core, mod->core_size);
67072 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67073 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67074
67075 /* Finally, free the core (containing the module structure) */
67076 unset_module_core_ro_nx(mod);
67077 - module_free(mod, mod->module_core);
67078 + module_free_exec(mod, mod->module_core_rx);
67079 + module_free(mod, mod->module_core_rw);
67080
67081 #ifdef CONFIG_MPU
67082 update_protections(current->mm);
67083 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67084 unsigned int i;
67085 int ret = 0;
67086 const struct kernel_symbol *ksym;
67087 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67088 + int is_fs_load = 0;
67089 + int register_filesystem_found = 0;
67090 + char *p;
67091 +
67092 + p = strstr(mod->args, "grsec_modharden_fs");
67093 + if (p) {
67094 + char *endptr = p + strlen("grsec_modharden_fs");
67095 + /* copy \0 as well */
67096 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67097 + is_fs_load = 1;
67098 + }
67099 +#endif
67100
67101 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67102 const char *name = info->strtab + sym[i].st_name;
67103
67104 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67105 + /* it's a real shame this will never get ripped and copied
67106 + upstream! ;(
67107 + */
67108 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67109 + register_filesystem_found = 1;
67110 +#endif
67111 +
67112 switch (sym[i].st_shndx) {
67113 case SHN_COMMON:
67114 /* We compiled with -fno-common. These are not
67115 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67116 ksym = resolve_symbol_wait(mod, info, name);
67117 /* Ok if resolved. */
67118 if (ksym && !IS_ERR(ksym)) {
67119 + pax_open_kernel();
67120 sym[i].st_value = ksym->value;
67121 + pax_close_kernel();
67122 break;
67123 }
67124
67125 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67126 secbase = (unsigned long)mod_percpu(mod);
67127 else
67128 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67129 + pax_open_kernel();
67130 sym[i].st_value += secbase;
67131 + pax_close_kernel();
67132 break;
67133 }
67134 }
67135
67136 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67137 + if (is_fs_load && !register_filesystem_found) {
67138 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67139 + ret = -EPERM;
67140 + }
67141 +#endif
67142 +
67143 return ret;
67144 }
67145
67146 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67147 || s->sh_entsize != ~0UL
67148 || strstarts(sname, ".init"))
67149 continue;
67150 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67151 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67152 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67153 + else
67154 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67155 pr_debug("\t%s\n", sname);
67156 }
67157 - switch (m) {
67158 - case 0: /* executable */
67159 - mod->core_size = debug_align(mod->core_size);
67160 - mod->core_text_size = mod->core_size;
67161 - break;
67162 - case 1: /* RO: text and ro-data */
67163 - mod->core_size = debug_align(mod->core_size);
67164 - mod->core_ro_size = mod->core_size;
67165 - break;
67166 - case 3: /* whole core */
67167 - mod->core_size = debug_align(mod->core_size);
67168 - break;
67169 - }
67170 }
67171
67172 pr_debug("Init section allocation order:\n");
67173 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67174 || s->sh_entsize != ~0UL
67175 || !strstarts(sname, ".init"))
67176 continue;
67177 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67178 - | INIT_OFFSET_MASK);
67179 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67180 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67181 + else
67182 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67183 + s->sh_entsize |= INIT_OFFSET_MASK;
67184 pr_debug("\t%s\n", sname);
67185 }
67186 - switch (m) {
67187 - case 0: /* executable */
67188 - mod->init_size = debug_align(mod->init_size);
67189 - mod->init_text_size = mod->init_size;
67190 - break;
67191 - case 1: /* RO: text and ro-data */
67192 - mod->init_size = debug_align(mod->init_size);
67193 - mod->init_ro_size = mod->init_size;
67194 - break;
67195 - case 3: /* whole init */
67196 - mod->init_size = debug_align(mod->init_size);
67197 - break;
67198 - }
67199 }
67200 }
67201
67202 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67203
67204 /* Put symbol section at end of init part of module. */
67205 symsect->sh_flags |= SHF_ALLOC;
67206 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67207 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67208 info->index.sym) | INIT_OFFSET_MASK;
67209 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67210
67211 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67212 }
67213
67214 /* Append room for core symbols at end of core part. */
67215 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67216 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67217 - mod->core_size += strtab_size;
67218 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67219 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67220 + mod->core_size_rx += strtab_size;
67221
67222 /* Put string table section at end of init part of module. */
67223 strsect->sh_flags |= SHF_ALLOC;
67224 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67225 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67226 info->index.str) | INIT_OFFSET_MASK;
67227 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67228 }
67229 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67230 /* Make sure we get permanent strtab: don't use info->strtab. */
67231 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67232
67233 + pax_open_kernel();
67234 +
67235 /* Set types up while we still have access to sections. */
67236 for (i = 0; i < mod->num_symtab; i++)
67237 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67238
67239 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67240 - mod->core_strtab = s = mod->module_core + info->stroffs;
67241 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67242 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67243 src = mod->symtab;
67244 *dst = *src;
67245 *s++ = 0;
67246 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67247 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67248 }
67249 mod->core_num_syms = ndst;
67250 +
67251 + pax_close_kernel();
67252 }
67253 #else
67254 static inline void layout_symtab(struct module *mod, struct load_info *info)
67255 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67256 return size == 0 ? NULL : vmalloc_exec(size);
67257 }
67258
67259 -static void *module_alloc_update_bounds(unsigned long size)
67260 +static void *module_alloc_update_bounds_rw(unsigned long size)
67261 {
67262 void *ret = module_alloc(size);
67263
67264 if (ret) {
67265 mutex_lock(&module_mutex);
67266 /* Update module bounds. */
67267 - if ((unsigned long)ret < module_addr_min)
67268 - module_addr_min = (unsigned long)ret;
67269 - if ((unsigned long)ret + size > module_addr_max)
67270 - module_addr_max = (unsigned long)ret + size;
67271 + if ((unsigned long)ret < module_addr_min_rw)
67272 + module_addr_min_rw = (unsigned long)ret;
67273 + if ((unsigned long)ret + size > module_addr_max_rw)
67274 + module_addr_max_rw = (unsigned long)ret + size;
67275 + mutex_unlock(&module_mutex);
67276 + }
67277 + return ret;
67278 +}
67279 +
67280 +static void *module_alloc_update_bounds_rx(unsigned long size)
67281 +{
67282 + void *ret = module_alloc_exec(size);
67283 +
67284 + if (ret) {
67285 + mutex_lock(&module_mutex);
67286 + /* Update module bounds. */
67287 + if ((unsigned long)ret < module_addr_min_rx)
67288 + module_addr_min_rx = (unsigned long)ret;
67289 + if ((unsigned long)ret + size > module_addr_max_rx)
67290 + module_addr_max_rx = (unsigned long)ret + size;
67291 mutex_unlock(&module_mutex);
67292 }
67293 return ret;
67294 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67295 static int check_modinfo(struct module *mod, struct load_info *info)
67296 {
67297 const char *modmagic = get_modinfo(info, "vermagic");
67298 + const char *license = get_modinfo(info, "license");
67299 int err;
67300
67301 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67302 + if (!license || !license_is_gpl_compatible(license))
67303 + return -ENOEXEC;
67304 +#endif
67305 +
67306 /* This is allowed: modprobe --force will invalidate it. */
67307 if (!modmagic) {
67308 err = try_to_force_load(mod, "bad vermagic");
67309 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67310 }
67311
67312 /* Set up license info based on the info section */
67313 - set_license(mod, get_modinfo(info, "license"));
67314 + set_license(mod, license);
67315
67316 return 0;
67317 }
67318 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67319 void *ptr;
67320
67321 /* Do the allocs. */
67322 - ptr = module_alloc_update_bounds(mod->core_size);
67323 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67324 /*
67325 * The pointer to this block is stored in the module structure
67326 * which is inside the block. Just mark it as not being a
67327 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67328 if (!ptr)
67329 return -ENOMEM;
67330
67331 - memset(ptr, 0, mod->core_size);
67332 - mod->module_core = ptr;
67333 + memset(ptr, 0, mod->core_size_rw);
67334 + mod->module_core_rw = ptr;
67335
67336 - ptr = module_alloc_update_bounds(mod->init_size);
67337 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67338 /*
67339 * The pointer to this block is stored in the module structure
67340 * which is inside the block. This block doesn't need to be
67341 * scanned as it contains data and code that will be freed
67342 * after the module is initialized.
67343 */
67344 - kmemleak_ignore(ptr);
67345 - if (!ptr && mod->init_size) {
67346 - module_free(mod, mod->module_core);
67347 + kmemleak_not_leak(ptr);
67348 + if (!ptr && mod->init_size_rw) {
67349 + module_free(mod, mod->module_core_rw);
67350 return -ENOMEM;
67351 }
67352 - memset(ptr, 0, mod->init_size);
67353 - mod->module_init = ptr;
67354 + memset(ptr, 0, mod->init_size_rw);
67355 + mod->module_init_rw = ptr;
67356 +
67357 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67358 + kmemleak_not_leak(ptr);
67359 + if (!ptr) {
67360 + module_free(mod, mod->module_init_rw);
67361 + module_free(mod, mod->module_core_rw);
67362 + return -ENOMEM;
67363 + }
67364 +
67365 + pax_open_kernel();
67366 + memset(ptr, 0, mod->core_size_rx);
67367 + pax_close_kernel();
67368 + mod->module_core_rx = ptr;
67369 +
67370 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67371 + kmemleak_not_leak(ptr);
67372 + if (!ptr && mod->init_size_rx) {
67373 + module_free_exec(mod, mod->module_core_rx);
67374 + module_free(mod, mod->module_init_rw);
67375 + module_free(mod, mod->module_core_rw);
67376 + return -ENOMEM;
67377 + }
67378 +
67379 + pax_open_kernel();
67380 + memset(ptr, 0, mod->init_size_rx);
67381 + pax_close_kernel();
67382 + mod->module_init_rx = ptr;
67383
67384 /* Transfer each section which specifies SHF_ALLOC */
67385 pr_debug("final section addresses:\n");
67386 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67387 if (!(shdr->sh_flags & SHF_ALLOC))
67388 continue;
67389
67390 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67391 - dest = mod->module_init
67392 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67393 - else
67394 - dest = mod->module_core + shdr->sh_entsize;
67395 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67396 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67397 + dest = mod->module_init_rw
67398 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67399 + else
67400 + dest = mod->module_init_rx
67401 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67402 + } else {
67403 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67404 + dest = mod->module_core_rw + shdr->sh_entsize;
67405 + else
67406 + dest = mod->module_core_rx + shdr->sh_entsize;
67407 + }
67408 +
67409 + if (shdr->sh_type != SHT_NOBITS) {
67410 +
67411 +#ifdef CONFIG_PAX_KERNEXEC
67412 +#ifdef CONFIG_X86_64
67413 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67414 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67415 +#endif
67416 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67417 + pax_open_kernel();
67418 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67419 + pax_close_kernel();
67420 + } else
67421 +#endif
67422
67423 - if (shdr->sh_type != SHT_NOBITS)
67424 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67425 + }
67426 /* Update sh_addr to point to copy in image. */
67427 - shdr->sh_addr = (unsigned long)dest;
67428 +
67429 +#ifdef CONFIG_PAX_KERNEXEC
67430 + if (shdr->sh_flags & SHF_EXECINSTR)
67431 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67432 + else
67433 +#endif
67434 +
67435 + shdr->sh_addr = (unsigned long)dest;
67436 pr_debug("\t0x%lx %s\n",
67437 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67438 }
67439 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67440 * Do it before processing of module parameters, so the module
67441 * can provide parameter accessor functions of its own.
67442 */
67443 - if (mod->module_init)
67444 - flush_icache_range((unsigned long)mod->module_init,
67445 - (unsigned long)mod->module_init
67446 - + mod->init_size);
67447 - flush_icache_range((unsigned long)mod->module_core,
67448 - (unsigned long)mod->module_core + mod->core_size);
67449 + if (mod->module_init_rx)
67450 + flush_icache_range((unsigned long)mod->module_init_rx,
67451 + (unsigned long)mod->module_init_rx
67452 + + mod->init_size_rx);
67453 + flush_icache_range((unsigned long)mod->module_core_rx,
67454 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67455
67456 set_fs(old_fs);
67457 }
67458 @@ -2802,8 +2901,10 @@ out:
67459 static void module_deallocate(struct module *mod, struct load_info *info)
67460 {
67461 percpu_modfree(mod);
67462 - module_free(mod, mod->module_init);
67463 - module_free(mod, mod->module_core);
67464 + module_free_exec(mod, mod->module_init_rx);
67465 + module_free_exec(mod, mod->module_core_rx);
67466 + module_free(mod, mod->module_init_rw);
67467 + module_free(mod, mod->module_core_rw);
67468 }
67469
67470 int __weak module_finalize(const Elf_Ehdr *hdr,
67471 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67472 if (err)
67473 goto free_unload;
67474
67475 + /* Now copy in args */
67476 + mod->args = strndup_user(uargs, ~0UL >> 1);
67477 + if (IS_ERR(mod->args)) {
67478 + err = PTR_ERR(mod->args);
67479 + goto free_unload;
67480 + }
67481 +
67482 /* Set up MODINFO_ATTR fields */
67483 setup_modinfo(mod, &info);
67484
67485 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67486 + {
67487 + char *p, *p2;
67488 +
67489 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67490 + 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);
67491 + err = -EPERM;
67492 + goto free_modinfo;
67493 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67494 + p += strlen("grsec_modharden_normal");
67495 + p2 = strstr(p, "_");
67496 + if (p2) {
67497 + *p2 = '\0';
67498 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67499 + *p2 = '_';
67500 + }
67501 + err = -EPERM;
67502 + goto free_modinfo;
67503 + }
67504 + }
67505 +#endif
67506 +
67507 /* Fix up syms, so that st_value is a pointer to location. */
67508 err = simplify_symbols(mod, &info);
67509 if (err < 0)
67510 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67511
67512 flush_module_icache(mod);
67513
67514 - /* Now copy in args */
67515 - mod->args = strndup_user(uargs, ~0UL >> 1);
67516 - if (IS_ERR(mod->args)) {
67517 - err = PTR_ERR(mod->args);
67518 - goto free_arch_cleanup;
67519 - }
67520 -
67521 /* Mark state as coming so strong_try_module_get() ignores us. */
67522 mod->state = MODULE_STATE_COMING;
67523
67524 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67525 unlock:
67526 mutex_unlock(&module_mutex);
67527 synchronize_sched();
67528 - kfree(mod->args);
67529 - free_arch_cleanup:
67530 module_arch_cleanup(mod);
67531 free_modinfo:
67532 free_modinfo(mod);
67533 + kfree(mod->args);
67534 free_unload:
67535 module_unload_free(mod);
67536 free_module:
67537 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67538 MODULE_STATE_COMING, mod);
67539
67540 /* Set RO and NX regions for core */
67541 - set_section_ro_nx(mod->module_core,
67542 - mod->core_text_size,
67543 - mod->core_ro_size,
67544 - mod->core_size);
67545 + set_section_ro_nx(mod->module_core_rx,
67546 + mod->core_size_rx,
67547 + mod->core_size_rx,
67548 + mod->core_size_rx);
67549
67550 /* Set RO and NX regions for init */
67551 - set_section_ro_nx(mod->module_init,
67552 - mod->init_text_size,
67553 - mod->init_ro_size,
67554 - mod->init_size);
67555 + set_section_ro_nx(mod->module_init_rx,
67556 + mod->init_size_rx,
67557 + mod->init_size_rx,
67558 + mod->init_size_rx);
67559
67560 do_mod_ctors(mod);
67561 /* Start the module */
67562 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67563 mod->strtab = mod->core_strtab;
67564 #endif
67565 unset_module_init_ro_nx(mod);
67566 - module_free(mod, mod->module_init);
67567 - mod->module_init = NULL;
67568 - mod->init_size = 0;
67569 - mod->init_ro_size = 0;
67570 - mod->init_text_size = 0;
67571 + module_free(mod, mod->module_init_rw);
67572 + module_free_exec(mod, mod->module_init_rx);
67573 + mod->module_init_rw = NULL;
67574 + mod->module_init_rx = NULL;
67575 + mod->init_size_rw = 0;
67576 + mod->init_size_rx = 0;
67577 mutex_unlock(&module_mutex);
67578
67579 return 0;
67580 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67581 unsigned long nextval;
67582
67583 /* At worse, next value is at end of module */
67584 - if (within_module_init(addr, mod))
67585 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67586 + if (within_module_init_rx(addr, mod))
67587 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67588 + else if (within_module_init_rw(addr, mod))
67589 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67590 + else if (within_module_core_rx(addr, mod))
67591 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67592 + else if (within_module_core_rw(addr, mod))
67593 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67594 else
67595 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67596 + return NULL;
67597
67598 /* Scan for closest preceding symbol, and next symbol. (ELF
67599 starts real symbols at 1). */
67600 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67601 char buf[8];
67602
67603 seq_printf(m, "%s %u",
67604 - mod->name, mod->init_size + mod->core_size);
67605 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67606 print_unload_info(m, mod);
67607
67608 /* Informative for users. */
67609 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67610 mod->state == MODULE_STATE_COMING ? "Loading":
67611 "Live");
67612 /* Used by oprofile and other similar tools. */
67613 - seq_printf(m, " 0x%pK", mod->module_core);
67614 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67615
67616 /* Taints info */
67617 if (mod->taints)
67618 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67619
67620 static int __init proc_modules_init(void)
67621 {
67622 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67623 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67624 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67625 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67626 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67627 +#else
67628 proc_create("modules", 0, NULL, &proc_modules_operations);
67629 +#endif
67630 +#else
67631 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67632 +#endif
67633 return 0;
67634 }
67635 module_init(proc_modules_init);
67636 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67637 {
67638 struct module *mod;
67639
67640 - if (addr < module_addr_min || addr > module_addr_max)
67641 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67642 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67643 return NULL;
67644
67645 list_for_each_entry_rcu(mod, &modules, list)
67646 - if (within_module_core(addr, mod)
67647 - || within_module_init(addr, mod))
67648 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67649 return mod;
67650 return NULL;
67651 }
67652 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67653 */
67654 struct module *__module_text_address(unsigned long addr)
67655 {
67656 - struct module *mod = __module_address(addr);
67657 + struct module *mod;
67658 +
67659 +#ifdef CONFIG_X86_32
67660 + addr = ktla_ktva(addr);
67661 +#endif
67662 +
67663 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67664 + return NULL;
67665 +
67666 + mod = __module_address(addr);
67667 +
67668 if (mod) {
67669 /* Make sure it's within the text section. */
67670 - if (!within(addr, mod->module_init, mod->init_text_size)
67671 - && !within(addr, mod->module_core, mod->core_text_size))
67672 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67673 mod = NULL;
67674 }
67675 return mod;
67676 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67677 index 7e3443f..b2a1e6b 100644
67678 --- a/kernel/mutex-debug.c
67679 +++ b/kernel/mutex-debug.c
67680 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67681 }
67682
67683 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67684 - struct thread_info *ti)
67685 + struct task_struct *task)
67686 {
67687 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67688
67689 /* Mark the current thread as blocked on the lock: */
67690 - ti->task->blocked_on = waiter;
67691 + task->blocked_on = waiter;
67692 }
67693
67694 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67695 - struct thread_info *ti)
67696 + struct task_struct *task)
67697 {
67698 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67699 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67700 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67701 - ti->task->blocked_on = NULL;
67702 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67703 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67704 + task->blocked_on = NULL;
67705
67706 list_del_init(&waiter->list);
67707 waiter->task = NULL;
67708 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67709 index 0799fd3..d06ae3b 100644
67710 --- a/kernel/mutex-debug.h
67711 +++ b/kernel/mutex-debug.h
67712 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67713 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67714 extern void debug_mutex_add_waiter(struct mutex *lock,
67715 struct mutex_waiter *waiter,
67716 - struct thread_info *ti);
67717 + struct task_struct *task);
67718 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67719 - struct thread_info *ti);
67720 + struct task_struct *task);
67721 extern void debug_mutex_unlock(struct mutex *lock);
67722 extern void debug_mutex_init(struct mutex *lock, const char *name,
67723 struct lock_class_key *key);
67724 diff --git a/kernel/mutex.c b/kernel/mutex.c
67725 index 89096dd..f91ebc5 100644
67726 --- a/kernel/mutex.c
67727 +++ b/kernel/mutex.c
67728 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67729 spin_lock_mutex(&lock->wait_lock, flags);
67730
67731 debug_mutex_lock_common(lock, &waiter);
67732 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67733 + debug_mutex_add_waiter(lock, &waiter, task);
67734
67735 /* add waiting tasks to the end of the waitqueue (FIFO): */
67736 list_add_tail(&waiter.list, &lock->wait_list);
67737 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67738 * TASK_UNINTERRUPTIBLE case.)
67739 */
67740 if (unlikely(signal_pending_state(state, task))) {
67741 - mutex_remove_waiter(lock, &waiter,
67742 - task_thread_info(task));
67743 + mutex_remove_waiter(lock, &waiter, task);
67744 mutex_release(&lock->dep_map, 1, ip);
67745 spin_unlock_mutex(&lock->wait_lock, flags);
67746
67747 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67748 done:
67749 lock_acquired(&lock->dep_map, ip);
67750 /* got the lock - rejoice! */
67751 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67752 + mutex_remove_waiter(lock, &waiter, task);
67753 mutex_set_owner(lock);
67754
67755 /* set it to 0 if there are no waiters left: */
67756 diff --git a/kernel/padata.c b/kernel/padata.c
67757 index b452599..5d68f4e 100644
67758 --- a/kernel/padata.c
67759 +++ b/kernel/padata.c
67760 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67761 padata->pd = pd;
67762 padata->cb_cpu = cb_cpu;
67763
67764 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67765 - atomic_set(&pd->seq_nr, -1);
67766 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67767 + atomic_set_unchecked(&pd->seq_nr, -1);
67768
67769 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67770 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67771
67772 target_cpu = padata_cpu_hash(padata);
67773 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67774 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67775 padata_init_pqueues(pd);
67776 padata_init_squeues(pd);
67777 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67778 - atomic_set(&pd->seq_nr, -1);
67779 + atomic_set_unchecked(&pd->seq_nr, -1);
67780 atomic_set(&pd->reorder_objects, 0);
67781 atomic_set(&pd->refcnt, 0);
67782 pd->pinst = pinst;
67783 diff --git a/kernel/panic.c b/kernel/panic.c
67784 index 80aed44..e83856a 100644
67785 --- a/kernel/panic.c
67786 +++ b/kernel/panic.c
67787 @@ -97,7 +97,7 @@ void panic(const char *fmt, ...)
67788 /*
67789 * Avoid nested stack-dumping if a panic occurs during oops processing
67790 */
67791 - if (!oops_in_progress)
67792 + if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
67793 dump_stack();
67794 #endif
67795
67796 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67797 const char *board;
67798
67799 printk(KERN_WARNING "------------[ cut here ]------------\n");
67800 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67801 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67802 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67803 if (board)
67804 printk(KERN_WARNING "Hardware name: %s\n", board);
67805 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67806 */
67807 void __stack_chk_fail(void)
67808 {
67809 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67810 + dump_stack();
67811 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67812 __builtin_return_address(0));
67813 }
67814 EXPORT_SYMBOL(__stack_chk_fail);
67815 diff --git a/kernel/pid.c b/kernel/pid.c
67816 index 9f08dfa..6765c40 100644
67817 --- a/kernel/pid.c
67818 +++ b/kernel/pid.c
67819 @@ -33,6 +33,7 @@
67820 #include <linux/rculist.h>
67821 #include <linux/bootmem.h>
67822 #include <linux/hash.h>
67823 +#include <linux/security.h>
67824 #include <linux/pid_namespace.h>
67825 #include <linux/init_task.h>
67826 #include <linux/syscalls.h>
67827 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67828
67829 int pid_max = PID_MAX_DEFAULT;
67830
67831 -#define RESERVED_PIDS 300
67832 +#define RESERVED_PIDS 500
67833
67834 int pid_max_min = RESERVED_PIDS + 1;
67835 int pid_max_max = PID_MAX_LIMIT;
67836 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67837 */
67838 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67839 {
67840 + struct task_struct *task;
67841 +
67842 rcu_lockdep_assert(rcu_read_lock_held(),
67843 "find_task_by_pid_ns() needs rcu_read_lock()"
67844 " protection");
67845 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67846 +
67847 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67848 +
67849 + if (gr_pid_is_chrooted(task))
67850 + return NULL;
67851 +
67852 + return task;
67853 }
67854
67855 struct task_struct *find_task_by_vpid(pid_t vnr)
67856 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67857 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67858 }
67859
67860 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67861 +{
67862 + rcu_lockdep_assert(rcu_read_lock_held(),
67863 + "find_task_by_pid_ns() needs rcu_read_lock()"
67864 + " protection");
67865 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67866 +}
67867 +
67868 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67869 {
67870 struct pid *pid;
67871 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67872 index 125cb67..a4d1c30 100644
67873 --- a/kernel/posix-cpu-timers.c
67874 +++ b/kernel/posix-cpu-timers.c
67875 @@ -6,6 +6,7 @@
67876 #include <linux/posix-timers.h>
67877 #include <linux/errno.h>
67878 #include <linux/math64.h>
67879 +#include <linux/security.h>
67880 #include <asm/uaccess.h>
67881 #include <linux/kernel_stat.h>
67882 #include <trace/events/timer.h>
67883 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67884
67885 static __init int init_posix_cpu_timers(void)
67886 {
67887 - struct k_clock process = {
67888 + static struct k_clock process = {
67889 .clock_getres = process_cpu_clock_getres,
67890 .clock_get = process_cpu_clock_get,
67891 .timer_create = process_cpu_timer_create,
67892 .nsleep = process_cpu_nsleep,
67893 .nsleep_restart = process_cpu_nsleep_restart,
67894 };
67895 - struct k_clock thread = {
67896 + static struct k_clock thread = {
67897 .clock_getres = thread_cpu_clock_getres,
67898 .clock_get = thread_cpu_clock_get,
67899 .timer_create = thread_cpu_timer_create,
67900 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67901 index 69185ae..cc2847a 100644
67902 --- a/kernel/posix-timers.c
67903 +++ b/kernel/posix-timers.c
67904 @@ -43,6 +43,7 @@
67905 #include <linux/idr.h>
67906 #include <linux/posix-clock.h>
67907 #include <linux/posix-timers.h>
67908 +#include <linux/grsecurity.h>
67909 #include <linux/syscalls.h>
67910 #include <linux/wait.h>
67911 #include <linux/workqueue.h>
67912 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67913 * which we beg off on and pass to do_sys_settimeofday().
67914 */
67915
67916 -static struct k_clock posix_clocks[MAX_CLOCKS];
67917 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67918
67919 /*
67920 * These ones are defined below.
67921 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67922 */
67923 static __init int init_posix_timers(void)
67924 {
67925 - struct k_clock clock_realtime = {
67926 + static struct k_clock clock_realtime = {
67927 .clock_getres = hrtimer_get_res,
67928 .clock_get = posix_clock_realtime_get,
67929 .clock_set = posix_clock_realtime_set,
67930 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67931 .timer_get = common_timer_get,
67932 .timer_del = common_timer_del,
67933 };
67934 - struct k_clock clock_monotonic = {
67935 + static struct k_clock clock_monotonic = {
67936 .clock_getres = hrtimer_get_res,
67937 .clock_get = posix_ktime_get_ts,
67938 .nsleep = common_nsleep,
67939 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67940 .timer_get = common_timer_get,
67941 .timer_del = common_timer_del,
67942 };
67943 - struct k_clock clock_monotonic_raw = {
67944 + static struct k_clock clock_monotonic_raw = {
67945 .clock_getres = hrtimer_get_res,
67946 .clock_get = posix_get_monotonic_raw,
67947 };
67948 - struct k_clock clock_realtime_coarse = {
67949 + static struct k_clock clock_realtime_coarse = {
67950 .clock_getres = posix_get_coarse_res,
67951 .clock_get = posix_get_realtime_coarse,
67952 };
67953 - struct k_clock clock_monotonic_coarse = {
67954 + static struct k_clock clock_monotonic_coarse = {
67955 .clock_getres = posix_get_coarse_res,
67956 .clock_get = posix_get_monotonic_coarse,
67957 };
67958 - struct k_clock clock_boottime = {
67959 + static struct k_clock clock_boottime = {
67960 .clock_getres = hrtimer_get_res,
67961 .clock_get = posix_get_boottime,
67962 .nsleep = common_nsleep,
67963 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67964 return;
67965 }
67966
67967 - posix_clocks[clock_id] = *new_clock;
67968 + posix_clocks[clock_id] = new_clock;
67969 }
67970 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67971
67972 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67973 return (id & CLOCKFD_MASK) == CLOCKFD ?
67974 &clock_posix_dynamic : &clock_posix_cpu;
67975
67976 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67977 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67978 return NULL;
67979 - return &posix_clocks[id];
67980 + return posix_clocks[id];
67981 }
67982
67983 static int common_timer_create(struct k_itimer *new_timer)
67984 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67985 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67986 return -EFAULT;
67987
67988 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67989 + have their clock_set fptr set to a nosettime dummy function
67990 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67991 + call common_clock_set, which calls do_sys_settimeofday, which
67992 + we hook
67993 + */
67994 +
67995 return kc->clock_set(which_clock, &new_tp);
67996 }
67997
67998 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67999 index d523593..68197a4 100644
68000 --- a/kernel/power/poweroff.c
68001 +++ b/kernel/power/poweroff.c
68002 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68003 .enable_mask = SYSRQ_ENABLE_BOOT,
68004 };
68005
68006 -static int pm_sysrq_init(void)
68007 +static int __init pm_sysrq_init(void)
68008 {
68009 register_sysrq_key('o', &sysrq_poweroff_op);
68010 return 0;
68011 diff --git a/kernel/power/process.c b/kernel/power/process.c
68012 index 7aac07a..2d3c6dc 100644
68013 --- a/kernel/power/process.c
68014 +++ b/kernel/power/process.c
68015 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68016 u64 elapsed_csecs64;
68017 unsigned int elapsed_csecs;
68018 bool wakeup = false;
68019 + bool timedout = false;
68020
68021 do_gettimeofday(&start);
68022
68023 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68024
68025 while (true) {
68026 todo = 0;
68027 + if (time_after(jiffies, end_time))
68028 + timedout = true;
68029 read_lock(&tasklist_lock);
68030 do_each_thread(g, p) {
68031 if (p == current || !freeze_task(p))
68032 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
68033 * try_to_stop() after schedule() in ptrace/signal
68034 * stop sees TIF_FREEZE.
68035 */
68036 - if (!task_is_stopped_or_traced(p) &&
68037 - !freezer_should_skip(p))
68038 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68039 todo++;
68040 + if (timedout) {
68041 + printk(KERN_ERR "Task refusing to freeze:\n");
68042 + sched_show_task(p);
68043 + }
68044 + }
68045 } while_each_thread(g, p);
68046 read_unlock(&tasklist_lock);
68047
68048 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
68049 todo += wq_busy;
68050 }
68051
68052 - if (!todo || time_after(jiffies, end_time))
68053 + if (!todo || timedout)
68054 break;
68055
68056 if (pm_wakeup_pending()) {
68057 diff --git a/kernel/printk.c b/kernel/printk.c
68058 index 32690a0..cd7c798 100644
68059 --- a/kernel/printk.c
68060 +++ b/kernel/printk.c
68061 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
68062 if (from_file && type != SYSLOG_ACTION_OPEN)
68063 return 0;
68064
68065 +#ifdef CONFIG_GRKERNSEC_DMESG
68066 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68067 + return -EPERM;
68068 +#endif
68069 +
68070 if (syslog_action_restricted(type)) {
68071 if (capable(CAP_SYSLOG))
68072 return 0;
68073 diff --git a/kernel/profile.c b/kernel/profile.c
68074 index 76b8e77..a2930e8 100644
68075 --- a/kernel/profile.c
68076 +++ b/kernel/profile.c
68077 @@ -39,7 +39,7 @@ struct profile_hit {
68078 /* Oprofile timer tick hook */
68079 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68080
68081 -static atomic_t *prof_buffer;
68082 +static atomic_unchecked_t *prof_buffer;
68083 static unsigned long prof_len, prof_shift;
68084
68085 int prof_on __read_mostly;
68086 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68087 hits[i].pc = 0;
68088 continue;
68089 }
68090 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68091 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68092 hits[i].hits = hits[i].pc = 0;
68093 }
68094 }
68095 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68096 * Add the current hit(s) and flush the write-queue out
68097 * to the global buffer:
68098 */
68099 - atomic_add(nr_hits, &prof_buffer[pc]);
68100 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68101 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68102 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68103 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68104 hits[i].pc = hits[i].hits = 0;
68105 }
68106 out:
68107 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68108 {
68109 unsigned long pc;
68110 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68111 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68112 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68113 }
68114 #endif /* !CONFIG_SMP */
68115
68116 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68117 return -EFAULT;
68118 buf++; p++; count--; read++;
68119 }
68120 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68121 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68122 if (copy_to_user(buf, (void *)pnt, count))
68123 return -EFAULT;
68124 read += count;
68125 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68126 }
68127 #endif
68128 profile_discard_flip_buffers();
68129 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68130 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68131 return count;
68132 }
68133
68134 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68135 index 00ab2ca..d237f61 100644
68136 --- a/kernel/ptrace.c
68137 +++ b/kernel/ptrace.c
68138 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68139 task->ptrace = PT_PTRACED;
68140 if (seize)
68141 task->ptrace |= PT_SEIZED;
68142 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68143 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68144 task->ptrace |= PT_PTRACE_CAP;
68145
68146 __ptrace_link(task, current);
68147 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68148 break;
68149 return -EIO;
68150 }
68151 - if (copy_to_user(dst, buf, retval))
68152 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68153 return -EFAULT;
68154 copied += retval;
68155 src += retval;
68156 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
68157 bool seized = child->ptrace & PT_SEIZED;
68158 int ret = -EIO;
68159 siginfo_t siginfo, *si;
68160 - void __user *datavp = (void __user *) data;
68161 + void __user *datavp = (__force void __user *) data;
68162 unsigned long __user *datalp = datavp;
68163 unsigned long flags;
68164
68165 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68166 goto out;
68167 }
68168
68169 + if (gr_handle_ptrace(child, request)) {
68170 + ret = -EPERM;
68171 + goto out_put_task_struct;
68172 + }
68173 +
68174 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68175 ret = ptrace_attach(child, request, data);
68176 /*
68177 * Some architectures need to do book-keeping after
68178 * a ptrace attach.
68179 */
68180 - if (!ret)
68181 + if (!ret) {
68182 arch_ptrace_attach(child);
68183 + gr_audit_ptrace(child);
68184 + }
68185 goto out_put_task_struct;
68186 }
68187
68188 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68189 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68190 if (copied != sizeof(tmp))
68191 return -EIO;
68192 - return put_user(tmp, (unsigned long __user *)data);
68193 + return put_user(tmp, (__force unsigned long __user *)data);
68194 }
68195
68196 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68197 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68198 goto out;
68199 }
68200
68201 + if (gr_handle_ptrace(child, request)) {
68202 + ret = -EPERM;
68203 + goto out_put_task_struct;
68204 + }
68205 +
68206 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68207 ret = ptrace_attach(child, request, data);
68208 /*
68209 * Some architectures need to do book-keeping after
68210 * a ptrace attach.
68211 */
68212 - if (!ret)
68213 + if (!ret) {
68214 arch_ptrace_attach(child);
68215 + gr_audit_ptrace(child);
68216 + }
68217 goto out_put_task_struct;
68218 }
68219
68220 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68221 index 977296d..c4744dc 100644
68222 --- a/kernel/rcutiny.c
68223 +++ b/kernel/rcutiny.c
68224 @@ -46,7 +46,7 @@
68225 struct rcu_ctrlblk;
68226 static void invoke_rcu_callbacks(void);
68227 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68228 -static void rcu_process_callbacks(struct softirq_action *unused);
68229 +static void rcu_process_callbacks(void);
68230 static void __call_rcu(struct rcu_head *head,
68231 void (*func)(struct rcu_head *rcu),
68232 struct rcu_ctrlblk *rcp);
68233 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68234 rcu_is_callbacks_kthread()));
68235 }
68236
68237 -static void rcu_process_callbacks(struct softirq_action *unused)
68238 +static void rcu_process_callbacks(void)
68239 {
68240 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68241 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68242 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68243 index 9cb1ae4..aac7d3e 100644
68244 --- a/kernel/rcutiny_plugin.h
68245 +++ b/kernel/rcutiny_plugin.h
68246 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68247 have_rcu_kthread_work = morework;
68248 local_irq_restore(flags);
68249 if (work)
68250 - rcu_process_callbacks(NULL);
68251 + rcu_process_callbacks();
68252 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68253 }
68254
68255 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68256 index a58ac28..196a3d8 100644
68257 --- a/kernel/rcutorture.c
68258 +++ b/kernel/rcutorture.c
68259 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68260 { 0 };
68261 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68262 { 0 };
68263 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68264 -static atomic_t n_rcu_torture_alloc;
68265 -static atomic_t n_rcu_torture_alloc_fail;
68266 -static atomic_t n_rcu_torture_free;
68267 -static atomic_t n_rcu_torture_mberror;
68268 -static atomic_t n_rcu_torture_error;
68269 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68270 +static atomic_unchecked_t n_rcu_torture_alloc;
68271 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68272 +static atomic_unchecked_t n_rcu_torture_free;
68273 +static atomic_unchecked_t n_rcu_torture_mberror;
68274 +static atomic_unchecked_t n_rcu_torture_error;
68275 static long n_rcu_torture_boost_ktrerror;
68276 static long n_rcu_torture_boost_rterror;
68277 static long n_rcu_torture_boost_failure;
68278 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68279
68280 spin_lock_bh(&rcu_torture_lock);
68281 if (list_empty(&rcu_torture_freelist)) {
68282 - atomic_inc(&n_rcu_torture_alloc_fail);
68283 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68284 spin_unlock_bh(&rcu_torture_lock);
68285 return NULL;
68286 }
68287 - atomic_inc(&n_rcu_torture_alloc);
68288 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68289 p = rcu_torture_freelist.next;
68290 list_del_init(p);
68291 spin_unlock_bh(&rcu_torture_lock);
68292 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68293 static void
68294 rcu_torture_free(struct rcu_torture *p)
68295 {
68296 - atomic_inc(&n_rcu_torture_free);
68297 + atomic_inc_unchecked(&n_rcu_torture_free);
68298 spin_lock_bh(&rcu_torture_lock);
68299 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68300 spin_unlock_bh(&rcu_torture_lock);
68301 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68302 i = rp->rtort_pipe_count;
68303 if (i > RCU_TORTURE_PIPE_LEN)
68304 i = RCU_TORTURE_PIPE_LEN;
68305 - atomic_inc(&rcu_torture_wcount[i]);
68306 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68307 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68308 rp->rtort_mbtest = 0;
68309 rcu_torture_free(rp);
68310 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68311 i = rp->rtort_pipe_count;
68312 if (i > RCU_TORTURE_PIPE_LEN)
68313 i = RCU_TORTURE_PIPE_LEN;
68314 - atomic_inc(&rcu_torture_wcount[i]);
68315 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68316 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68317 rp->rtort_mbtest = 0;
68318 list_del(&rp->rtort_free);
68319 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68320 i = old_rp->rtort_pipe_count;
68321 if (i > RCU_TORTURE_PIPE_LEN)
68322 i = RCU_TORTURE_PIPE_LEN;
68323 - atomic_inc(&rcu_torture_wcount[i]);
68324 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68325 old_rp->rtort_pipe_count++;
68326 cur_ops->deferred_free(old_rp);
68327 }
68328 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68329 return;
68330 }
68331 if (p->rtort_mbtest == 0)
68332 - atomic_inc(&n_rcu_torture_mberror);
68333 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68334 spin_lock(&rand_lock);
68335 cur_ops->read_delay(&rand);
68336 n_rcu_torture_timers++;
68337 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68338 continue;
68339 }
68340 if (p->rtort_mbtest == 0)
68341 - atomic_inc(&n_rcu_torture_mberror);
68342 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68343 cur_ops->read_delay(&rand);
68344 preempt_disable();
68345 pipe_count = p->rtort_pipe_count;
68346 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68347 rcu_torture_current,
68348 rcu_torture_current_version,
68349 list_empty(&rcu_torture_freelist),
68350 - atomic_read(&n_rcu_torture_alloc),
68351 - atomic_read(&n_rcu_torture_alloc_fail),
68352 - atomic_read(&n_rcu_torture_free),
68353 - atomic_read(&n_rcu_torture_mberror),
68354 + atomic_read_unchecked(&n_rcu_torture_alloc),
68355 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68356 + atomic_read_unchecked(&n_rcu_torture_free),
68357 + atomic_read_unchecked(&n_rcu_torture_mberror),
68358 n_rcu_torture_boost_ktrerror,
68359 n_rcu_torture_boost_rterror,
68360 n_rcu_torture_boost_failure,
68361 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68362 n_online_attempts,
68363 n_offline_successes,
68364 n_offline_attempts);
68365 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68366 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68367 n_rcu_torture_boost_ktrerror != 0 ||
68368 n_rcu_torture_boost_rterror != 0 ||
68369 n_rcu_torture_boost_failure != 0)
68370 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68371 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68372 if (i > 1) {
68373 cnt += sprintf(&page[cnt], "!!! ");
68374 - atomic_inc(&n_rcu_torture_error);
68375 + atomic_inc_unchecked(&n_rcu_torture_error);
68376 WARN_ON_ONCE(1);
68377 }
68378 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68379 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68380 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68381 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68382 cnt += sprintf(&page[cnt], " %d",
68383 - atomic_read(&rcu_torture_wcount[i]));
68384 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68385 }
68386 cnt += sprintf(&page[cnt], "\n");
68387 if (cur_ops->stats)
68388 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68389
68390 if (cur_ops->cleanup)
68391 cur_ops->cleanup();
68392 - if (atomic_read(&n_rcu_torture_error))
68393 + if (atomic_read_unchecked(&n_rcu_torture_error))
68394 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68395 else
68396 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68397 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68398
68399 rcu_torture_current = NULL;
68400 rcu_torture_current_version = 0;
68401 - atomic_set(&n_rcu_torture_alloc, 0);
68402 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68403 - atomic_set(&n_rcu_torture_free, 0);
68404 - atomic_set(&n_rcu_torture_mberror, 0);
68405 - atomic_set(&n_rcu_torture_error, 0);
68406 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68407 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68408 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68409 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68410 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68411 n_rcu_torture_boost_ktrerror = 0;
68412 n_rcu_torture_boost_rterror = 0;
68413 n_rcu_torture_boost_failure = 0;
68414 n_rcu_torture_boosts = 0;
68415 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68416 - atomic_set(&rcu_torture_wcount[i], 0);
68417 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68418 for_each_possible_cpu(cpu) {
68419 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68420 per_cpu(rcu_torture_count, cpu)[i] = 0;
68421 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68422 index 6c4a672..70f3202 100644
68423 --- a/kernel/rcutree.c
68424 +++ b/kernel/rcutree.c
68425 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68426 rcu_prepare_for_idle(smp_processor_id());
68427 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68428 smp_mb__before_atomic_inc(); /* See above. */
68429 - atomic_inc(&rdtp->dynticks);
68430 + atomic_inc_unchecked(&rdtp->dynticks);
68431 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68432 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68433 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68434 }
68435
68436 /**
68437 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68438 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68439 {
68440 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68441 - atomic_inc(&rdtp->dynticks);
68442 + atomic_inc_unchecked(&rdtp->dynticks);
68443 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68444 smp_mb__after_atomic_inc(); /* See above. */
68445 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68446 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68447 rcu_cleanup_after_idle(smp_processor_id());
68448 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68449 if (!is_idle_task(current)) {
68450 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68451 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68452
68453 if (rdtp->dynticks_nmi_nesting == 0 &&
68454 - (atomic_read(&rdtp->dynticks) & 0x1))
68455 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68456 return;
68457 rdtp->dynticks_nmi_nesting++;
68458 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68459 - atomic_inc(&rdtp->dynticks);
68460 + atomic_inc_unchecked(&rdtp->dynticks);
68461 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68462 smp_mb__after_atomic_inc(); /* See above. */
68463 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68464 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68465 }
68466
68467 /**
68468 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68469 return;
68470 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68471 smp_mb__before_atomic_inc(); /* See above. */
68472 - atomic_inc(&rdtp->dynticks);
68473 + atomic_inc_unchecked(&rdtp->dynticks);
68474 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68475 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68476 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68477 }
68478
68479 #ifdef CONFIG_PROVE_RCU
68480 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68481 int ret;
68482
68483 preempt_disable();
68484 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68485 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68486 preempt_enable();
68487 return ret;
68488 }
68489 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68490 */
68491 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68492 {
68493 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68494 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68495 return (rdp->dynticks_snap & 0x1) == 0;
68496 }
68497
68498 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68499 unsigned int curr;
68500 unsigned int snap;
68501
68502 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68503 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68504 snap = (unsigned int)rdp->dynticks_snap;
68505
68506 /*
68507 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68508 /*
68509 * Do RCU core processing for the current CPU.
68510 */
68511 -static void rcu_process_callbacks(struct softirq_action *unused)
68512 +static void rcu_process_callbacks(void)
68513 {
68514 trace_rcu_utilization("Start RCU core");
68515 __rcu_process_callbacks(&rcu_sched_state,
68516 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68517 rdp->qlen = 0;
68518 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68519 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68520 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68521 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68522 rdp->cpu = cpu;
68523 rdp->rsp = rsp;
68524 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68525 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68526 rdp->n_force_qs_snap = rsp->n_force_qs;
68527 rdp->blimit = blimit;
68528 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68529 - atomic_set(&rdp->dynticks->dynticks,
68530 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68531 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68532 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68533 rcu_prepare_for_idle_init(cpu);
68534 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68535
68536 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68537 index fddff92..2c08359 100644
68538 --- a/kernel/rcutree.h
68539 +++ b/kernel/rcutree.h
68540 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68541 long long dynticks_nesting; /* Track irq/process nesting level. */
68542 /* Process level is worth LLONG_MAX/2. */
68543 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68544 - atomic_t dynticks; /* Even value for idle, else odd. */
68545 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68546 };
68547
68548 /* RCU's kthread states for tracing. */
68549 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68550 index 8bb35d7..6ea0a463 100644
68551 --- a/kernel/rcutree_plugin.h
68552 +++ b/kernel/rcutree_plugin.h
68553 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68554
68555 /* Clean up and exit. */
68556 smp_mb(); /* ensure expedited GP seen before counter increment. */
68557 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68558 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68559 unlock_mb_ret:
68560 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68561 mb_ret:
68562 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68563
68564 #else /* #ifndef CONFIG_SMP */
68565
68566 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68567 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68568 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68569 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68570
68571 static int synchronize_sched_expedited_cpu_stop(void *data)
68572 {
68573 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68574 int firstsnap, s, snap, trycount = 0;
68575
68576 /* Note that atomic_inc_return() implies full memory barrier. */
68577 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68578 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68579 get_online_cpus();
68580
68581 /*
68582 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68583 }
68584
68585 /* Check to see if someone else did our work for us. */
68586 - s = atomic_read(&sync_sched_expedited_done);
68587 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68588 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68589 smp_mb(); /* ensure test happens before caller kfree */
68590 return;
68591 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68592 * grace period works for us.
68593 */
68594 get_online_cpus();
68595 - snap = atomic_read(&sync_sched_expedited_started);
68596 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68597 smp_mb(); /* ensure read is before try_stop_cpus(). */
68598 }
68599
68600 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68601 * than we did beat us to the punch.
68602 */
68603 do {
68604 - s = atomic_read(&sync_sched_expedited_done);
68605 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68606 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68607 smp_mb(); /* ensure test happens before caller kfree */
68608 break;
68609 }
68610 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68611 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68612
68613 put_online_cpus();
68614 }
68615 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68616 index 654cfe6..c0b28e2 100644
68617 --- a/kernel/rcutree_trace.c
68618 +++ b/kernel/rcutree_trace.c
68619 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68620 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68621 rdp->qs_pending);
68622 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68623 - atomic_read(&rdp->dynticks->dynticks),
68624 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68625 rdp->dynticks->dynticks_nesting,
68626 rdp->dynticks->dynticks_nmi_nesting,
68627 rdp->dynticks_fqs);
68628 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68629 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68630 rdp->qs_pending);
68631 seq_printf(m, ",%d,%llx,%d,%lu",
68632 - atomic_read(&rdp->dynticks->dynticks),
68633 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68634 rdp->dynticks->dynticks_nesting,
68635 rdp->dynticks->dynticks_nmi_nesting,
68636 rdp->dynticks_fqs);
68637 diff --git a/kernel/resource.c b/kernel/resource.c
68638 index 7640b3a..5879283 100644
68639 --- a/kernel/resource.c
68640 +++ b/kernel/resource.c
68641 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68642
68643 static int __init ioresources_init(void)
68644 {
68645 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68646 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68647 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68648 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68649 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68650 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68651 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68652 +#endif
68653 +#else
68654 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68655 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68656 +#endif
68657 return 0;
68658 }
68659 __initcall(ioresources_init);
68660 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68661 index 98ec494..4241d6d 100644
68662 --- a/kernel/rtmutex-tester.c
68663 +++ b/kernel/rtmutex-tester.c
68664 @@ -20,7 +20,7 @@
68665 #define MAX_RT_TEST_MUTEXES 8
68666
68667 static spinlock_t rttest_lock;
68668 -static atomic_t rttest_event;
68669 +static atomic_unchecked_t rttest_event;
68670
68671 struct test_thread_data {
68672 int opcode;
68673 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68674
68675 case RTTEST_LOCKCONT:
68676 td->mutexes[td->opdata] = 1;
68677 - td->event = atomic_add_return(1, &rttest_event);
68678 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68679 return 0;
68680
68681 case RTTEST_RESET:
68682 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68683 return 0;
68684
68685 case RTTEST_RESETEVENT:
68686 - atomic_set(&rttest_event, 0);
68687 + atomic_set_unchecked(&rttest_event, 0);
68688 return 0;
68689
68690 default:
68691 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68692 return ret;
68693
68694 td->mutexes[id] = 1;
68695 - td->event = atomic_add_return(1, &rttest_event);
68696 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68697 rt_mutex_lock(&mutexes[id]);
68698 - td->event = atomic_add_return(1, &rttest_event);
68699 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68700 td->mutexes[id] = 4;
68701 return 0;
68702
68703 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68704 return ret;
68705
68706 td->mutexes[id] = 1;
68707 - td->event = atomic_add_return(1, &rttest_event);
68708 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68709 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68710 - td->event = atomic_add_return(1, &rttest_event);
68711 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68712 td->mutexes[id] = ret ? 0 : 4;
68713 return ret ? -EINTR : 0;
68714
68715 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68716 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68717 return ret;
68718
68719 - td->event = atomic_add_return(1, &rttest_event);
68720 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68721 rt_mutex_unlock(&mutexes[id]);
68722 - td->event = atomic_add_return(1, &rttest_event);
68723 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68724 td->mutexes[id] = 0;
68725 return 0;
68726
68727 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68728 break;
68729
68730 td->mutexes[dat] = 2;
68731 - td->event = atomic_add_return(1, &rttest_event);
68732 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68733 break;
68734
68735 default:
68736 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68737 return;
68738
68739 td->mutexes[dat] = 3;
68740 - td->event = atomic_add_return(1, &rttest_event);
68741 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68742 break;
68743
68744 case RTTEST_LOCKNOWAIT:
68745 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68746 return;
68747
68748 td->mutexes[dat] = 1;
68749 - td->event = atomic_add_return(1, &rttest_event);
68750 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68751 return;
68752
68753 default:
68754 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68755 index e8a1f83..363d17d 100644
68756 --- a/kernel/sched/auto_group.c
68757 +++ b/kernel/sched/auto_group.c
68758 @@ -11,7 +11,7 @@
68759
68760 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68761 static struct autogroup autogroup_default;
68762 -static atomic_t autogroup_seq_nr;
68763 +static atomic_unchecked_t autogroup_seq_nr;
68764
68765 void __init autogroup_init(struct task_struct *init_task)
68766 {
68767 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68768
68769 kref_init(&ag->kref);
68770 init_rwsem(&ag->lock);
68771 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68772 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68773 ag->tg = tg;
68774 #ifdef CONFIG_RT_GROUP_SCHED
68775 /*
68776 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68777 index b342f57..00324a0 100644
68778 --- a/kernel/sched/core.c
68779 +++ b/kernel/sched/core.c
68780 @@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
68781 BUG(); /* the idle class will always have a runnable task */
68782 }
68783
68784 +#ifdef CONFIG_GRKERNSEC_SETXID
68785 +extern void gr_delayed_cred_worker(void);
68786 +static inline void gr_cred_schedule(void)
68787 +{
68788 + if (unlikely(current->delayed_cred))
68789 + gr_delayed_cred_worker();
68790 +}
68791 +#else
68792 +static inline void gr_cred_schedule(void)
68793 +{
68794 +}
68795 +#endif
68796 +
68797 /*
68798 * __schedule() is the main scheduler function.
68799 */
68800 @@ -3162,6 +3175,8 @@ need_resched:
68801
68802 schedule_debug(prev);
68803
68804 + gr_cred_schedule();
68805 +
68806 if (sched_feat(HRTICK))
68807 hrtick_clear(rq);
68808
68809 @@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
68810 /* convert nice value [19,-20] to rlimit style value [1,40] */
68811 int nice_rlim = 20 - nice;
68812
68813 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68814 +
68815 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68816 capable(CAP_SYS_NICE));
68817 }
68818 @@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68819 if (nice > 19)
68820 nice = 19;
68821
68822 - if (increment < 0 && !can_nice(current, nice))
68823 + if (increment < 0 && (!can_nice(current, nice) ||
68824 + gr_handle_chroot_nice()))
68825 return -EPERM;
68826
68827 retval = security_task_setnice(current, nice);
68828 @@ -4042,6 +4060,7 @@ recheck:
68829 unsigned long rlim_rtprio =
68830 task_rlimit(p, RLIMIT_RTPRIO);
68831
68832 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68833 /* can't set/change the rt policy */
68834 if (policy != p->policy && !rlim_rtprio)
68835 return -EPERM;
68836 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68837 index aca16b8..8e3acc4 100644
68838 --- a/kernel/sched/fair.c
68839 +++ b/kernel/sched/fair.c
68840 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68841 * run_rebalance_domains is triggered when needed from the scheduler tick.
68842 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68843 */
68844 -static void run_rebalance_domains(struct softirq_action *h)
68845 +static void run_rebalance_domains(void)
68846 {
68847 int this_cpu = smp_processor_id();
68848 struct rq *this_rq = cpu_rq(this_cpu);
68849 diff --git a/kernel/signal.c b/kernel/signal.c
68850 index c73c428..7040057 100644
68851 --- a/kernel/signal.c
68852 +++ b/kernel/signal.c
68853 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68854
68855 int print_fatal_signals __read_mostly;
68856
68857 -static void __user *sig_handler(struct task_struct *t, int sig)
68858 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68859 {
68860 return t->sighand->action[sig - 1].sa.sa_handler;
68861 }
68862
68863 -static int sig_handler_ignored(void __user *handler, int sig)
68864 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68865 {
68866 /* Is it explicitly or implicitly ignored? */
68867 return handler == SIG_IGN ||
68868 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68869 static int sig_task_ignored(struct task_struct *t, int sig,
68870 int from_ancestor_ns)
68871 {
68872 - void __user *handler;
68873 + __sighandler_t handler;
68874
68875 handler = sig_handler(t, sig);
68876
68877 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68878 atomic_inc(&user->sigpending);
68879 rcu_read_unlock();
68880
68881 + if (!override_rlimit)
68882 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68883 +
68884 if (override_rlimit ||
68885 atomic_read(&user->sigpending) <=
68886 task_rlimit(t, RLIMIT_SIGPENDING)) {
68887 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68888
68889 int unhandled_signal(struct task_struct *tsk, int sig)
68890 {
68891 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68892 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68893 if (is_global_init(tsk))
68894 return 1;
68895 if (handler != SIG_IGN && handler != SIG_DFL)
68896 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68897 }
68898 }
68899
68900 + /* allow glibc communication via tgkill to other threads in our
68901 + thread group */
68902 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68903 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68904 + && gr_handle_signal(t, sig))
68905 + return -EPERM;
68906 +
68907 return security_task_kill(t, info, sig, 0);
68908 }
68909
68910 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68911 return send_signal(sig, info, p, 1);
68912 }
68913
68914 -static int
68915 +int
68916 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68917 {
68918 return send_signal(sig, info, t, 0);
68919 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68920 unsigned long int flags;
68921 int ret, blocked, ignored;
68922 struct k_sigaction *action;
68923 + int is_unhandled = 0;
68924
68925 spin_lock_irqsave(&t->sighand->siglock, flags);
68926 action = &t->sighand->action[sig-1];
68927 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68928 }
68929 if (action->sa.sa_handler == SIG_DFL)
68930 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68931 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68932 + is_unhandled = 1;
68933 ret = specific_send_sig_info(sig, info, t);
68934 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68935
68936 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68937 + normal operation */
68938 + if (is_unhandled) {
68939 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68940 + gr_handle_crash(t, sig);
68941 + }
68942 +
68943 return ret;
68944 }
68945
68946 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68947 ret = check_kill_permission(sig, info, p);
68948 rcu_read_unlock();
68949
68950 - if (!ret && sig)
68951 + if (!ret && sig) {
68952 ret = do_send_sig_info(sig, info, p, true);
68953 + if (!ret)
68954 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68955 + }
68956
68957 return ret;
68958 }
68959 @@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68960 int error = -ESRCH;
68961
68962 rcu_read_lock();
68963 - p = find_task_by_vpid(pid);
68964 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68965 + /* allow glibc communication via tgkill to other threads in our
68966 + thread group */
68967 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68968 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68969 + p = find_task_by_vpid_unrestricted(pid);
68970 + else
68971 +#endif
68972 + p = find_task_by_vpid(pid);
68973 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68974 error = check_kill_permission(sig, info, p);
68975 /*
68976 diff --git a/kernel/smp.c b/kernel/smp.c
68977 index db197d6..17aef0b 100644
68978 --- a/kernel/smp.c
68979 +++ b/kernel/smp.c
68980 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68981 }
68982 EXPORT_SYMBOL(smp_call_function);
68983
68984 -void ipi_call_lock(void)
68985 +void ipi_call_lock(void) __acquires(call_function.lock)
68986 {
68987 raw_spin_lock(&call_function.lock);
68988 }
68989
68990 -void ipi_call_unlock(void)
68991 +void ipi_call_unlock(void) __releases(call_function.lock)
68992 {
68993 raw_spin_unlock(&call_function.lock);
68994 }
68995
68996 -void ipi_call_lock_irq(void)
68997 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68998 {
68999 raw_spin_lock_irq(&call_function.lock);
69000 }
69001
69002 -void ipi_call_unlock_irq(void)
69003 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69004 {
69005 raw_spin_unlock_irq(&call_function.lock);
69006 }
69007 diff --git a/kernel/softirq.c b/kernel/softirq.c
69008 index 4eb3a0f..6f1fa81 100644
69009 --- a/kernel/softirq.c
69010 +++ b/kernel/softirq.c
69011 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69012
69013 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69014
69015 -char *softirq_to_name[NR_SOFTIRQS] = {
69016 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69017 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69018 "TASKLET", "SCHED", "HRTIMER", "RCU"
69019 };
69020 @@ -235,7 +235,7 @@ restart:
69021 kstat_incr_softirqs_this_cpu(vec_nr);
69022
69023 trace_softirq_entry(vec_nr);
69024 - h->action(h);
69025 + h->action();
69026 trace_softirq_exit(vec_nr);
69027 if (unlikely(prev_count != preempt_count())) {
69028 printk(KERN_ERR "huh, entered softirq %u %s %p"
69029 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
69030 local_irq_restore(flags);
69031 }
69032
69033 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69034 +void open_softirq(int nr, void (*action)(void))
69035 {
69036 - softirq_vec[nr].action = action;
69037 + pax_open_kernel();
69038 + *(void **)&softirq_vec[nr].action = action;
69039 + pax_close_kernel();
69040 }
69041
69042 /*
69043 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69044
69045 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69046
69047 -static void tasklet_action(struct softirq_action *a)
69048 +static void tasklet_action(void)
69049 {
69050 struct tasklet_struct *list;
69051
69052 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
69053 }
69054 }
69055
69056 -static void tasklet_hi_action(struct softirq_action *a)
69057 +static void tasklet_hi_action(void)
69058 {
69059 struct tasklet_struct *list;
69060
69061 diff --git a/kernel/sys.c b/kernel/sys.c
69062 index 888d227..f04b318 100644
69063 --- a/kernel/sys.c
69064 +++ b/kernel/sys.c
69065 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69066 error = -EACCES;
69067 goto out;
69068 }
69069 +
69070 + if (gr_handle_chroot_setpriority(p, niceval)) {
69071 + error = -EACCES;
69072 + goto out;
69073 + }
69074 +
69075 no_nice = security_task_setnice(p, niceval);
69076 if (no_nice) {
69077 error = no_nice;
69078 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69079 goto error;
69080 }
69081
69082 + if (gr_check_group_change(new->gid, new->egid, -1))
69083 + goto error;
69084 +
69085 if (rgid != (gid_t) -1 ||
69086 (egid != (gid_t) -1 && egid != old->gid))
69087 new->sgid = new->egid;
69088 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69089 old = current_cred();
69090
69091 retval = -EPERM;
69092 +
69093 + if (gr_check_group_change(gid, gid, gid))
69094 + goto error;
69095 +
69096 if (nsown_capable(CAP_SETGID))
69097 new->gid = new->egid = new->sgid = new->fsgid = gid;
69098 else if (gid == old->gid || gid == old->sgid)
69099 @@ -618,7 +631,7 @@ error:
69100 /*
69101 * change the user struct in a credentials set to match the new UID
69102 */
69103 -static int set_user(struct cred *new)
69104 +int set_user(struct cred *new)
69105 {
69106 struct user_struct *new_user;
69107
69108 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69109 goto error;
69110 }
69111
69112 + if (gr_check_user_change(new->uid, new->euid, -1))
69113 + goto error;
69114 +
69115 if (new->uid != old->uid) {
69116 retval = set_user(new);
69117 if (retval < 0)
69118 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69119 old = current_cred();
69120
69121 retval = -EPERM;
69122 +
69123 + if (gr_check_crash_uid(uid))
69124 + goto error;
69125 + if (gr_check_user_change(uid, uid, uid))
69126 + goto error;
69127 +
69128 if (nsown_capable(CAP_SETUID)) {
69129 new->suid = new->uid = uid;
69130 if (uid != old->uid) {
69131 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69132 goto error;
69133 }
69134
69135 + if (gr_check_user_change(ruid, euid, -1))
69136 + goto error;
69137 +
69138 if (ruid != (uid_t) -1) {
69139 new->uid = ruid;
69140 if (ruid != old->uid) {
69141 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69142 goto error;
69143 }
69144
69145 + if (gr_check_group_change(rgid, egid, -1))
69146 + goto error;
69147 +
69148 if (rgid != (gid_t) -1)
69149 new->gid = rgid;
69150 if (egid != (gid_t) -1)
69151 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69152 old = current_cred();
69153 old_fsuid = old->fsuid;
69154
69155 + if (gr_check_user_change(-1, -1, uid))
69156 + goto error;
69157 +
69158 if (uid == old->uid || uid == old->euid ||
69159 uid == old->suid || uid == old->fsuid ||
69160 nsown_capable(CAP_SETUID)) {
69161 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69162 }
69163 }
69164
69165 +error:
69166 abort_creds(new);
69167 return old_fsuid;
69168
69169 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69170 if (gid == old->gid || gid == old->egid ||
69171 gid == old->sgid || gid == old->fsgid ||
69172 nsown_capable(CAP_SETGID)) {
69173 + if (gr_check_group_change(-1, -1, gid))
69174 + goto error;
69175 +
69176 if (gid != old_fsgid) {
69177 new->fsgid = gid;
69178 goto change_okay;
69179 }
69180 }
69181
69182 +error:
69183 abort_creds(new);
69184 return old_fsgid;
69185
69186 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69187 }
69188 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69189 snprintf(buf, len, "2.6.%u%s", v, rest);
69190 - ret = copy_to_user(release, buf, len);
69191 + if (len > sizeof(buf))
69192 + ret = -EFAULT;
69193 + else
69194 + ret = copy_to_user(release, buf, len);
69195 }
69196 return ret;
69197 }
69198 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69199 return -EFAULT;
69200
69201 down_read(&uts_sem);
69202 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69203 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69204 __OLD_UTS_LEN);
69205 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69206 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69207 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69208 __OLD_UTS_LEN);
69209 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69210 - error |= __copy_to_user(&name->release, &utsname()->release,
69211 + error |= __copy_to_user(name->release, &utsname()->release,
69212 __OLD_UTS_LEN);
69213 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69214 - error |= __copy_to_user(&name->version, &utsname()->version,
69215 + error |= __copy_to_user(name->version, &utsname()->version,
69216 __OLD_UTS_LEN);
69217 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69218 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69219 + error |= __copy_to_user(name->machine, &utsname()->machine,
69220 __OLD_UTS_LEN);
69221 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69222 up_read(&uts_sem);
69223 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69224 error = get_dumpable(me->mm);
69225 break;
69226 case PR_SET_DUMPABLE:
69227 - if (arg2 < 0 || arg2 > 1) {
69228 + if (arg2 > 1) {
69229 error = -EINVAL;
69230 break;
69231 }
69232 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69233 index f03a6ef..5fcc8af 100644
69234 --- a/kernel/sysctl.c
69235 +++ b/kernel/sysctl.c
69236 @@ -86,6 +86,13 @@
69237
69238
69239 #if defined(CONFIG_SYSCTL)
69240 +#include <linux/grsecurity.h>
69241 +#include <linux/grinternal.h>
69242 +
69243 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69244 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69245 + const int op);
69246 +extern int gr_handle_chroot_sysctl(const int op);
69247
69248 /* External variables not in a header file. */
69249 extern int sysctl_overcommit_memory;
69250 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69251 }
69252
69253 #endif
69254 +extern struct ctl_table grsecurity_table[];
69255
69256 static struct ctl_table root_table[];
69257 static struct ctl_table_root sysctl_table_root;
69258 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69259 int sysctl_legacy_va_layout;
69260 #endif
69261
69262 +#ifdef CONFIG_PAX_SOFTMODE
69263 +static ctl_table pax_table[] = {
69264 + {
69265 + .procname = "softmode",
69266 + .data = &pax_softmode,
69267 + .maxlen = sizeof(unsigned int),
69268 + .mode = 0600,
69269 + .proc_handler = &proc_dointvec,
69270 + },
69271 +
69272 + { }
69273 +};
69274 +#endif
69275 +
69276 /* The default sysctl tables: */
69277
69278 static struct ctl_table root_table[] = {
69279 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69280 #endif
69281
69282 static struct ctl_table kern_table[] = {
69283 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69284 + {
69285 + .procname = "grsecurity",
69286 + .mode = 0500,
69287 + .child = grsecurity_table,
69288 + },
69289 +#endif
69290 +
69291 +#ifdef CONFIG_PAX_SOFTMODE
69292 + {
69293 + .procname = "pax",
69294 + .mode = 0500,
69295 + .child = pax_table,
69296 + },
69297 +#endif
69298 +
69299 {
69300 .procname = "sched_child_runs_first",
69301 .data = &sysctl_sched_child_runs_first,
69302 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69303 .data = &modprobe_path,
69304 .maxlen = KMOD_PATH_LEN,
69305 .mode = 0644,
69306 - .proc_handler = proc_dostring,
69307 + .proc_handler = proc_dostring_modpriv,
69308 },
69309 {
69310 .procname = "modules_disabled",
69311 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69312 .extra1 = &zero,
69313 .extra2 = &one,
69314 },
69315 +#endif
69316 {
69317 .procname = "kptr_restrict",
69318 .data = &kptr_restrict,
69319 .maxlen = sizeof(int),
69320 .mode = 0644,
69321 .proc_handler = proc_dointvec_minmax_sysadmin,
69322 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69323 + .extra1 = &two,
69324 +#else
69325 .extra1 = &zero,
69326 +#endif
69327 .extra2 = &two,
69328 },
69329 -#endif
69330 {
69331 .procname = "ngroups_max",
69332 .data = &ngroups_max,
69333 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
69334 .proc_handler = proc_dointvec_minmax,
69335 .extra1 = &zero,
69336 },
69337 + {
69338 + .procname = "heap_stack_gap",
69339 + .data = &sysctl_heap_stack_gap,
69340 + .maxlen = sizeof(sysctl_heap_stack_gap),
69341 + .mode = 0644,
69342 + .proc_handler = proc_doulongvec_minmax,
69343 + },
69344 #else
69345 {
69346 .procname = "nr_trim_pages",
69347 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
69348 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69349 {
69350 int mode;
69351 + int error;
69352 +
69353 + if (table->parent != NULL && table->parent->procname != NULL &&
69354 + table->procname != NULL &&
69355 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69356 + return -EACCES;
69357 + if (gr_handle_chroot_sysctl(op))
69358 + return -EACCES;
69359 + error = gr_handle_sysctl(table, op);
69360 + if (error)
69361 + return error;
69362
69363 if (root->permissions)
69364 mode = root->permissions(root, current->nsproxy, table);
69365 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
69366 buffer, lenp, ppos);
69367 }
69368
69369 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69370 + void __user *buffer, size_t *lenp, loff_t *ppos)
69371 +{
69372 + if (write && !capable(CAP_SYS_MODULE))
69373 + return -EPERM;
69374 +
69375 + return _proc_do_string(table->data, table->maxlen, write,
69376 + buffer, lenp, ppos);
69377 +}
69378 +
69379 static size_t proc_skip_spaces(char **buf)
69380 {
69381 size_t ret;
69382 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69383 len = strlen(tmp);
69384 if (len > *size)
69385 len = *size;
69386 + if (len > sizeof(tmp))
69387 + len = sizeof(tmp);
69388 if (copy_to_user(*buf, tmp, len))
69389 return -EFAULT;
69390 *size -= len;
69391 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69392 *i = val;
69393 } else {
69394 val = convdiv * (*i) / convmul;
69395 - if (!first)
69396 + if (!first) {
69397 err = proc_put_char(&buffer, &left, '\t');
69398 + if (err)
69399 + break;
69400 + }
69401 err = proc_put_long(&buffer, &left, val, false);
69402 if (err)
69403 break;
69404 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
69405 return -ENOSYS;
69406 }
69407
69408 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69409 + void __user *buffer, size_t *lenp, loff_t *ppos)
69410 +{
69411 + return -ENOSYS;
69412 +}
69413 +
69414 int proc_dointvec(struct ctl_table *table, int write,
69415 void __user *buffer, size_t *lenp, loff_t *ppos)
69416 {
69417 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69418 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69419 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69420 EXPORT_SYMBOL(proc_dostring);
69421 +EXPORT_SYMBOL(proc_dostring_modpriv);
69422 EXPORT_SYMBOL(proc_doulongvec_minmax);
69423 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69424 EXPORT_SYMBOL(register_sysctl_table);
69425 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69426 index a650694..aaeeb20 100644
69427 --- a/kernel/sysctl_binary.c
69428 +++ b/kernel/sysctl_binary.c
69429 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69430 int i;
69431
69432 set_fs(KERNEL_DS);
69433 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69434 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69435 set_fs(old_fs);
69436 if (result < 0)
69437 goto out_kfree;
69438 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69439 }
69440
69441 set_fs(KERNEL_DS);
69442 - result = vfs_write(file, buffer, str - buffer, &pos);
69443 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69444 set_fs(old_fs);
69445 if (result < 0)
69446 goto out_kfree;
69447 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69448 int i;
69449
69450 set_fs(KERNEL_DS);
69451 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69452 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69453 set_fs(old_fs);
69454 if (result < 0)
69455 goto out_kfree;
69456 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69457 }
69458
69459 set_fs(KERNEL_DS);
69460 - result = vfs_write(file, buffer, str - buffer, &pos);
69461 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69462 set_fs(old_fs);
69463 if (result < 0)
69464 goto out_kfree;
69465 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69466 int i;
69467
69468 set_fs(KERNEL_DS);
69469 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69470 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69471 set_fs(old_fs);
69472 if (result < 0)
69473 goto out;
69474 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69475 __le16 dnaddr;
69476
69477 set_fs(KERNEL_DS);
69478 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69479 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69480 set_fs(old_fs);
69481 if (result < 0)
69482 goto out;
69483 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69484 le16_to_cpu(dnaddr) & 0x3ff);
69485
69486 set_fs(KERNEL_DS);
69487 - result = vfs_write(file, buf, len, &pos);
69488 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69489 set_fs(old_fs);
69490 if (result < 0)
69491 goto out;
69492 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69493 index 362da65..ab8ef8c 100644
69494 --- a/kernel/sysctl_check.c
69495 +++ b/kernel/sysctl_check.c
69496 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69497 set_fail(&fail, table, "Directory with extra2");
69498 } else {
69499 if ((table->proc_handler == proc_dostring) ||
69500 + (table->proc_handler == proc_dostring_modpriv) ||
69501 (table->proc_handler == proc_dointvec) ||
69502 (table->proc_handler == proc_dointvec_minmax) ||
69503 (table->proc_handler == proc_dointvec_jiffies) ||
69504 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69505 index e660464..c8b9e67 100644
69506 --- a/kernel/taskstats.c
69507 +++ b/kernel/taskstats.c
69508 @@ -27,9 +27,12 @@
69509 #include <linux/cgroup.h>
69510 #include <linux/fs.h>
69511 #include <linux/file.h>
69512 +#include <linux/grsecurity.h>
69513 #include <net/genetlink.h>
69514 #include <linux/atomic.h>
69515
69516 +extern int gr_is_taskstats_denied(int pid);
69517 +
69518 /*
69519 * Maximum length of a cpumask that can be specified in
69520 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69521 @@ -556,6 +559,9 @@ err:
69522
69523 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69524 {
69525 + if (gr_is_taskstats_denied(current->pid))
69526 + return -EACCES;
69527 +
69528 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69529 return cmd_attr_register_cpumask(info);
69530 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69531 diff --git a/kernel/time.c b/kernel/time.c
69532 index 73e416d..cfc6f69 100644
69533 --- a/kernel/time.c
69534 +++ b/kernel/time.c
69535 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69536 return error;
69537
69538 if (tz) {
69539 + /* we log in do_settimeofday called below, so don't log twice
69540 + */
69541 + if (!tv)
69542 + gr_log_timechange();
69543 +
69544 /* SMP safe, global irq locking makes it work. */
69545 sys_tz = *tz;
69546 update_vsyscall_tz();
69547 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69548 index 8a46f5d..bbe6f9c 100644
69549 --- a/kernel/time/alarmtimer.c
69550 +++ b/kernel/time/alarmtimer.c
69551 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69552 struct platform_device *pdev;
69553 int error = 0;
69554 int i;
69555 - struct k_clock alarm_clock = {
69556 + static struct k_clock alarm_clock = {
69557 .clock_getres = alarm_clock_getres,
69558 .clock_get = alarm_clock_get,
69559 .timer_create = alarm_timer_create,
69560 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69561 index fd4a7b1..fae5c2a 100644
69562 --- a/kernel/time/tick-broadcast.c
69563 +++ b/kernel/time/tick-broadcast.c
69564 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69565 * then clear the broadcast bit.
69566 */
69567 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69568 - int cpu = smp_processor_id();
69569 + cpu = smp_processor_id();
69570
69571 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69572 tick_broadcast_clear_oneshot(cpu);
69573 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69574 index 0c63581..e25dcb6 100644
69575 --- a/kernel/time/timekeeping.c
69576 +++ b/kernel/time/timekeeping.c
69577 @@ -14,6 +14,7 @@
69578 #include <linux/init.h>
69579 #include <linux/mm.h>
69580 #include <linux/sched.h>
69581 +#include <linux/grsecurity.h>
69582 #include <linux/syscore_ops.h>
69583 #include <linux/clocksource.h>
69584 #include <linux/jiffies.h>
69585 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69586 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69587 return -EINVAL;
69588
69589 + gr_log_timechange();
69590 +
69591 write_seqlock_irqsave(&xtime_lock, flags);
69592
69593 timekeeping_forward_now();
69594 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69595 index 3258455..f35227d 100644
69596 --- a/kernel/time/timer_list.c
69597 +++ b/kernel/time/timer_list.c
69598 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69599
69600 static void print_name_offset(struct seq_file *m, void *sym)
69601 {
69602 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69603 + SEQ_printf(m, "<%p>", NULL);
69604 +#else
69605 char symname[KSYM_NAME_LEN];
69606
69607 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69608 SEQ_printf(m, "<%pK>", sym);
69609 else
69610 SEQ_printf(m, "%s", symname);
69611 +#endif
69612 }
69613
69614 static void
69615 @@ -112,7 +116,11 @@ next_one:
69616 static void
69617 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69618 {
69619 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69620 + SEQ_printf(m, " .base: %p\n", NULL);
69621 +#else
69622 SEQ_printf(m, " .base: %pK\n", base);
69623 +#endif
69624 SEQ_printf(m, " .index: %d\n",
69625 base->index);
69626 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69627 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69628 {
69629 struct proc_dir_entry *pe;
69630
69631 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69632 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69633 +#else
69634 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69635 +#endif
69636 if (!pe)
69637 return -ENOMEM;
69638 return 0;
69639 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69640 index 0b537f2..9e71eca 100644
69641 --- a/kernel/time/timer_stats.c
69642 +++ b/kernel/time/timer_stats.c
69643 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69644 static unsigned long nr_entries;
69645 static struct entry entries[MAX_ENTRIES];
69646
69647 -static atomic_t overflow_count;
69648 +static atomic_unchecked_t overflow_count;
69649
69650 /*
69651 * The entries are in a hash-table, for fast lookup:
69652 @@ -140,7 +140,7 @@ static void reset_entries(void)
69653 nr_entries = 0;
69654 memset(entries, 0, sizeof(entries));
69655 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69656 - atomic_set(&overflow_count, 0);
69657 + atomic_set_unchecked(&overflow_count, 0);
69658 }
69659
69660 static struct entry *alloc_entry(void)
69661 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69662 if (likely(entry))
69663 entry->count++;
69664 else
69665 - atomic_inc(&overflow_count);
69666 + atomic_inc_unchecked(&overflow_count);
69667
69668 out_unlock:
69669 raw_spin_unlock_irqrestore(lock, flags);
69670 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69671
69672 static void print_name_offset(struct seq_file *m, unsigned long addr)
69673 {
69674 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69675 + seq_printf(m, "<%p>", NULL);
69676 +#else
69677 char symname[KSYM_NAME_LEN];
69678
69679 if (lookup_symbol_name(addr, symname) < 0)
69680 seq_printf(m, "<%p>", (void *)addr);
69681 else
69682 seq_printf(m, "%s", symname);
69683 +#endif
69684 }
69685
69686 static int tstats_show(struct seq_file *m, void *v)
69687 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69688
69689 seq_puts(m, "Timer Stats Version: v0.2\n");
69690 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69691 - if (atomic_read(&overflow_count))
69692 + if (atomic_read_unchecked(&overflow_count))
69693 seq_printf(m, "Overflow: %d entries\n",
69694 - atomic_read(&overflow_count));
69695 + atomic_read_unchecked(&overflow_count));
69696
69697 for (i = 0; i < nr_entries; i++) {
69698 entry = entries + i;
69699 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69700 {
69701 struct proc_dir_entry *pe;
69702
69703 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69704 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69705 +#else
69706 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69707 +#endif
69708 if (!pe)
69709 return -ENOMEM;
69710 return 0;
69711 diff --git a/kernel/timer.c b/kernel/timer.c
69712 index a297ffc..5e16b0b 100644
69713 --- a/kernel/timer.c
69714 +++ b/kernel/timer.c
69715 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69716 /*
69717 * This function runs timers and the timer-tq in bottom half context.
69718 */
69719 -static void run_timer_softirq(struct softirq_action *h)
69720 +static void run_timer_softirq(void)
69721 {
69722 struct tvec_base *base = __this_cpu_read(tvec_bases);
69723
69724 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69725 index cdea7b5..9b820d4 100644
69726 --- a/kernel/trace/blktrace.c
69727 +++ b/kernel/trace/blktrace.c
69728 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69729 struct blk_trace *bt = filp->private_data;
69730 char buf[16];
69731
69732 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69733 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69734
69735 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69736 }
69737 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69738 return 1;
69739
69740 bt = buf->chan->private_data;
69741 - atomic_inc(&bt->dropped);
69742 + atomic_inc_unchecked(&bt->dropped);
69743 return 0;
69744 }
69745
69746 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69747
69748 bt->dir = dir;
69749 bt->dev = dev;
69750 - atomic_set(&bt->dropped, 0);
69751 + atomic_set_unchecked(&bt->dropped, 0);
69752
69753 ret = -EIO;
69754 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69755 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69756 index 683d559..d70d914 100644
69757 --- a/kernel/trace/ftrace.c
69758 +++ b/kernel/trace/ftrace.c
69759 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69760 if (unlikely(ftrace_disabled))
69761 return 0;
69762
69763 + ret = ftrace_arch_code_modify_prepare();
69764 + FTRACE_WARN_ON(ret);
69765 + if (ret)
69766 + return 0;
69767 +
69768 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69769 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69770 if (ret) {
69771 ftrace_bug(ret, ip);
69772 - return 0;
69773 }
69774 - return 1;
69775 + return ret ? 0 : 1;
69776 }
69777
69778 /*
69779 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69780
69781 int
69782 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69783 - void *data)
69784 + void *data)
69785 {
69786 struct ftrace_func_probe *entry;
69787 struct ftrace_page *pg;
69788 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69789 index c4579f1..6a439da 100644
69790 --- a/kernel/trace/trace.c
69791 +++ b/kernel/trace/trace.c
69792 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69793 };
69794 #endif
69795
69796 -static struct dentry *d_tracer;
69797 -
69798 struct dentry *tracing_init_dentry(void)
69799 {
69800 + static struct dentry *d_tracer;
69801 static int once;
69802
69803 if (d_tracer)
69804 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69805 return d_tracer;
69806 }
69807
69808 -static struct dentry *d_percpu;
69809 -
69810 struct dentry *tracing_dentry_percpu(void)
69811 {
69812 + static struct dentry *d_percpu;
69813 static int once;
69814 struct dentry *d_tracer;
69815
69816 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69817 index c212a7f..7b02394 100644
69818 --- a/kernel/trace/trace_events.c
69819 +++ b/kernel/trace/trace_events.c
69820 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69821 struct ftrace_module_file_ops {
69822 struct list_head list;
69823 struct module *mod;
69824 - struct file_operations id;
69825 - struct file_operations enable;
69826 - struct file_operations format;
69827 - struct file_operations filter;
69828 };
69829
69830 static struct ftrace_module_file_ops *
69831 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69832
69833 file_ops->mod = mod;
69834
69835 - file_ops->id = ftrace_event_id_fops;
69836 - file_ops->id.owner = mod;
69837 -
69838 - file_ops->enable = ftrace_enable_fops;
69839 - file_ops->enable.owner = mod;
69840 -
69841 - file_ops->filter = ftrace_event_filter_fops;
69842 - file_ops->filter.owner = mod;
69843 -
69844 - file_ops->format = ftrace_event_format_fops;
69845 - file_ops->format.owner = mod;
69846 + pax_open_kernel();
69847 + *(void **)&mod->trace_id.owner = mod;
69848 + *(void **)&mod->trace_enable.owner = mod;
69849 + *(void **)&mod->trace_filter.owner = mod;
69850 + *(void **)&mod->trace_format.owner = mod;
69851 + pax_close_kernel();
69852
69853 list_add(&file_ops->list, &ftrace_module_file_list);
69854
69855 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69856
69857 for_each_event(call, start, end) {
69858 __trace_add_event_call(*call, mod,
69859 - &file_ops->id, &file_ops->enable,
69860 - &file_ops->filter, &file_ops->format);
69861 + &mod->trace_id, &mod->trace_enable,
69862 + &mod->trace_filter, &mod->trace_format);
69863 }
69864 }
69865
69866 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69867 index 00d527c..7c5b1a3 100644
69868 --- a/kernel/trace/trace_kprobe.c
69869 +++ b/kernel/trace/trace_kprobe.c
69870 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69871 long ret;
69872 int maxlen = get_rloc_len(*(u32 *)dest);
69873 u8 *dst = get_rloc_data(dest);
69874 - u8 *src = addr;
69875 + const u8 __user *src = (const u8 __force_user *)addr;
69876 mm_segment_t old_fs = get_fs();
69877 if (!maxlen)
69878 return;
69879 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69880 pagefault_disable();
69881 do
69882 ret = __copy_from_user_inatomic(dst++, src++, 1);
69883 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69884 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69885 dst[-1] = '\0';
69886 pagefault_enable();
69887 set_fs(old_fs);
69888 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69889 ((u8 *)get_rloc_data(dest))[0] = '\0';
69890 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69891 } else
69892 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69893 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69894 get_rloc_offs(*(u32 *)dest));
69895 }
69896 /* Return the length of string -- including null terminal byte */
69897 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69898 set_fs(KERNEL_DS);
69899 pagefault_disable();
69900 do {
69901 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69902 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69903 len++;
69904 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69905 pagefault_enable();
69906 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69907 index fd3c8aa..5f324a6 100644
69908 --- a/kernel/trace/trace_mmiotrace.c
69909 +++ b/kernel/trace/trace_mmiotrace.c
69910 @@ -24,7 +24,7 @@ struct header_iter {
69911 static struct trace_array *mmio_trace_array;
69912 static bool overrun_detected;
69913 static unsigned long prev_overruns;
69914 -static atomic_t dropped_count;
69915 +static atomic_unchecked_t dropped_count;
69916
69917 static void mmio_reset_data(struct trace_array *tr)
69918 {
69919 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69920
69921 static unsigned long count_overruns(struct trace_iterator *iter)
69922 {
69923 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69924 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69925 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69926
69927 if (over > prev_overruns)
69928 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69929 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69930 sizeof(*entry), 0, pc);
69931 if (!event) {
69932 - atomic_inc(&dropped_count);
69933 + atomic_inc_unchecked(&dropped_count);
69934 return;
69935 }
69936 entry = ring_buffer_event_data(event);
69937 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69938 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69939 sizeof(*entry), 0, pc);
69940 if (!event) {
69941 - atomic_inc(&dropped_count);
69942 + atomic_inc_unchecked(&dropped_count);
69943 return;
69944 }
69945 entry = ring_buffer_event_data(event);
69946 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69947 index 0d6ff35..67e0ed7 100644
69948 --- a/kernel/trace/trace_output.c
69949 +++ b/kernel/trace/trace_output.c
69950 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69951
69952 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69953 if (!IS_ERR(p)) {
69954 - p = mangle_path(s->buffer + s->len, p, "\n");
69955 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69956 if (p) {
69957 s->len = p - s->buffer;
69958 return 1;
69959 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69960 index d4545f4..a9010a1 100644
69961 --- a/kernel/trace/trace_stack.c
69962 +++ b/kernel/trace/trace_stack.c
69963 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69964 return;
69965
69966 /* we do not handle interrupt stacks yet */
69967 - if (!object_is_on_stack(&this_size))
69968 + if (!object_starts_on_stack(&this_size))
69969 return;
69970
69971 local_irq_save(flags);
69972 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69973 index 209b379..7f76423 100644
69974 --- a/kernel/trace/trace_workqueue.c
69975 +++ b/kernel/trace/trace_workqueue.c
69976 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69977 int cpu;
69978 pid_t pid;
69979 /* Can be inserted from interrupt or user context, need to be atomic */
69980 - atomic_t inserted;
69981 + atomic_unchecked_t inserted;
69982 /*
69983 * Don't need to be atomic, works are serialized in a single workqueue thread
69984 * on a single CPU.
69985 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69986 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69987 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69988 if (node->pid == wq_thread->pid) {
69989 - atomic_inc(&node->inserted);
69990 + atomic_inc_unchecked(&node->inserted);
69991 goto found;
69992 }
69993 }
69994 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69995 tsk = get_pid_task(pid, PIDTYPE_PID);
69996 if (tsk) {
69997 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69998 - atomic_read(&cws->inserted), cws->executed,
69999 + atomic_read_unchecked(&cws->inserted), cws->executed,
70000 tsk->comm);
70001 put_task_struct(tsk);
70002 }
70003 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70004 index 8745ac7..d144e37 100644
70005 --- a/lib/Kconfig.debug
70006 +++ b/lib/Kconfig.debug
70007 @@ -1103,6 +1103,7 @@ config LATENCYTOP
70008 depends on DEBUG_KERNEL
70009 depends on STACKTRACE_SUPPORT
70010 depends on PROC_FS
70011 + depends on !GRKERNSEC_HIDESYM
70012 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70013 select KALLSYMS
70014 select KALLSYMS_ALL
70015 diff --git a/lib/bitmap.c b/lib/bitmap.c
70016 index 0d4a127..33a06c7 100644
70017 --- a/lib/bitmap.c
70018 +++ b/lib/bitmap.c
70019 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70020 {
70021 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70022 u32 chunk;
70023 - const char __user __force *ubuf = (const char __user __force *)buf;
70024 + const char __user *ubuf = (const char __force_user *)buf;
70025
70026 bitmap_zero(maskp, nmaskbits);
70027
70028 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
70029 {
70030 if (!access_ok(VERIFY_READ, ubuf, ulen))
70031 return -EFAULT;
70032 - return __bitmap_parse((const char __force *)ubuf,
70033 + return __bitmap_parse((const char __force_kernel *)ubuf,
70034 ulen, 1, maskp, nmaskbits);
70035
70036 }
70037 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70038 {
70039 unsigned a, b;
70040 int c, old_c, totaldigits;
70041 - const char __user __force *ubuf = (const char __user __force *)buf;
70042 + const char __user *ubuf = (const char __force_user *)buf;
70043 int exp_digit, in_range;
70044
70045 totaldigits = c = 0;
70046 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70047 {
70048 if (!access_ok(VERIFY_READ, ubuf, ulen))
70049 return -EFAULT;
70050 - return __bitmap_parselist((const char __force *)ubuf,
70051 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70052 ulen, 1, maskp, nmaskbits);
70053 }
70054 EXPORT_SYMBOL(bitmap_parselist_user);
70055 diff --git a/lib/bug.c b/lib/bug.c
70056 index a28c141..2bd3d95 100644
70057 --- a/lib/bug.c
70058 +++ b/lib/bug.c
70059 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70060 return BUG_TRAP_TYPE_NONE;
70061
70062 bug = find_bug(bugaddr);
70063 + if (!bug)
70064 + return BUG_TRAP_TYPE_NONE;
70065
70066 file = NULL;
70067 line = 0;
70068 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70069 index 0ab9ae8..f01ceca 100644
70070 --- a/lib/debugobjects.c
70071 +++ b/lib/debugobjects.c
70072 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70073 if (limit > 4)
70074 return;
70075
70076 - is_on_stack = object_is_on_stack(addr);
70077 + is_on_stack = object_starts_on_stack(addr);
70078 if (is_on_stack == onstack)
70079 return;
70080
70081 diff --git a/lib/devres.c b/lib/devres.c
70082 index 9676617..5149e15 100644
70083 --- a/lib/devres.c
70084 +++ b/lib/devres.c
70085 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70086 void devm_iounmap(struct device *dev, void __iomem *addr)
70087 {
70088 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70089 - (void *)addr));
70090 + (void __force *)addr));
70091 iounmap(addr);
70092 }
70093 EXPORT_SYMBOL(devm_iounmap);
70094 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70095 {
70096 ioport_unmap(addr);
70097 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70098 - devm_ioport_map_match, (void *)addr));
70099 + devm_ioport_map_match, (void __force *)addr));
70100 }
70101 EXPORT_SYMBOL(devm_ioport_unmap);
70102
70103 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70104 index fea790a..ebb0e82 100644
70105 --- a/lib/dma-debug.c
70106 +++ b/lib/dma-debug.c
70107 @@ -925,7 +925,7 @@ out:
70108
70109 static void check_for_stack(struct device *dev, void *addr)
70110 {
70111 - if (object_is_on_stack(addr))
70112 + if (object_starts_on_stack(addr))
70113 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70114 "stack [addr=%p]\n", addr);
70115 }
70116 diff --git a/lib/extable.c b/lib/extable.c
70117 index 4cac81e..63e9b8f 100644
70118 --- a/lib/extable.c
70119 +++ b/lib/extable.c
70120 @@ -13,6 +13,7 @@
70121 #include <linux/init.h>
70122 #include <linux/sort.h>
70123 #include <asm/uaccess.h>
70124 +#include <asm/pgtable.h>
70125
70126 #ifndef ARCH_HAS_SORT_EXTABLE
70127 /*
70128 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70129 void sort_extable(struct exception_table_entry *start,
70130 struct exception_table_entry *finish)
70131 {
70132 + pax_open_kernel();
70133 sort(start, finish - start, sizeof(struct exception_table_entry),
70134 cmp_ex, NULL);
70135 + pax_close_kernel();
70136 }
70137
70138 #ifdef CONFIG_MODULES
70139 diff --git a/lib/inflate.c b/lib/inflate.c
70140 index 013a761..c28f3fc 100644
70141 --- a/lib/inflate.c
70142 +++ b/lib/inflate.c
70143 @@ -269,7 +269,7 @@ static void free(void *where)
70144 malloc_ptr = free_mem_ptr;
70145 }
70146 #else
70147 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70148 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70149 #define free(a) kfree(a)
70150 #endif
70151
70152 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70153 index bd2bea9..6b3c95e 100644
70154 --- a/lib/is_single_threaded.c
70155 +++ b/lib/is_single_threaded.c
70156 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70157 struct task_struct *p, *t;
70158 bool ret;
70159
70160 + if (!mm)
70161 + return true;
70162 +
70163 if (atomic_read(&task->signal->live) != 1)
70164 return false;
70165
70166 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70167 index dc63d08..95ae14a 100644
70168 --- a/lib/radix-tree.c
70169 +++ b/lib/radix-tree.c
70170 @@ -78,7 +78,7 @@ struct radix_tree_preload {
70171 int nr;
70172 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70173 };
70174 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70175 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70176
70177 static inline void *ptr_to_indirect(void *ptr)
70178 {
70179 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70180 index 38e612e..4fb99a8 100644
70181 --- a/lib/vsprintf.c
70182 +++ b/lib/vsprintf.c
70183 @@ -16,6 +16,9 @@
70184 * - scnprintf and vscnprintf
70185 */
70186
70187 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70188 +#define __INCLUDED_BY_HIDESYM 1
70189 +#endif
70190 #include <stdarg.h>
70191 #include <linux/module.h>
70192 #include <linux/types.h>
70193 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70194 char sym[KSYM_SYMBOL_LEN];
70195 if (ext == 'B')
70196 sprint_backtrace(sym, value);
70197 - else if (ext != 'f' && ext != 's')
70198 + else if (ext != 'f' && ext != 's' && ext != 'a')
70199 sprint_symbol(sym, value);
70200 else
70201 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70202 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70203 return number(buf, end, *(const netdev_features_t *)addr, spec);
70204 }
70205
70206 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70207 +int kptr_restrict __read_mostly = 2;
70208 +#else
70209 int kptr_restrict __read_mostly;
70210 +#endif
70211
70212 /*
70213 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70214 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70215 * - 'S' For symbolic direct pointers with offset
70216 * - 's' For symbolic direct pointers without offset
70217 * - 'B' For backtraced symbolic direct pointers with offset
70218 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70219 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70220 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70221 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70222 * - 'M' For a 6-byte MAC address, it prints the address in the
70223 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70224 {
70225 if (!ptr && *fmt != 'K') {
70226 /*
70227 - * Print (null) with the same width as a pointer so it makes
70228 + * Print (nil) with the same width as a pointer so it makes
70229 * tabular output look nice.
70230 */
70231 if (spec.field_width == -1)
70232 spec.field_width = 2 * sizeof(void *);
70233 - return string(buf, end, "(null)", spec);
70234 + return string(buf, end, "(nil)", spec);
70235 }
70236
70237 switch (*fmt) {
70238 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70239 /* Fallthrough */
70240 case 'S':
70241 case 's':
70242 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70243 + break;
70244 +#else
70245 + return symbol_string(buf, end, ptr, spec, *fmt);
70246 +#endif
70247 + case 'A':
70248 + case 'a':
70249 case 'B':
70250 return symbol_string(buf, end, ptr, spec, *fmt);
70251 case 'R':
70252 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70253 typeof(type) value; \
70254 if (sizeof(type) == 8) { \
70255 args = PTR_ALIGN(args, sizeof(u32)); \
70256 - *(u32 *)&value = *(u32 *)args; \
70257 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70258 + *(u32 *)&value = *(const u32 *)args; \
70259 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70260 } else { \
70261 args = PTR_ALIGN(args, sizeof(type)); \
70262 - value = *(typeof(type) *)args; \
70263 + value = *(const typeof(type) *)args; \
70264 } \
70265 args += sizeof(type); \
70266 value; \
70267 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70268 case FORMAT_TYPE_STR: {
70269 const char *str_arg = args;
70270 args += strlen(str_arg) + 1;
70271 - str = string(str, end, (char *)str_arg, spec);
70272 + str = string(str, end, str_arg, spec);
70273 break;
70274 }
70275
70276 diff --git a/localversion-grsec b/localversion-grsec
70277 new file mode 100644
70278 index 0000000..7cd6065
70279 --- /dev/null
70280 +++ b/localversion-grsec
70281 @@ -0,0 +1 @@
70282 +-grsec
70283 diff --git a/mm/Kconfig b/mm/Kconfig
70284 index e338407..49b5b7a 100644
70285 --- a/mm/Kconfig
70286 +++ b/mm/Kconfig
70287 @@ -247,10 +247,10 @@ config KSM
70288 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70289
70290 config DEFAULT_MMAP_MIN_ADDR
70291 - int "Low address space to protect from user allocation"
70292 + int "Low address space to protect from user allocation"
70293 depends on MMU
70294 - default 4096
70295 - help
70296 + default 65536
70297 + help
70298 This is the portion of low virtual memory which should be protected
70299 from userspace allocation. Keeping a user from writing to low pages
70300 can help reduce the impact of kernel NULL pointer bugs.
70301 diff --git a/mm/filemap.c b/mm/filemap.c
70302 index b662757..3081ddd 100644
70303 --- a/mm/filemap.c
70304 +++ b/mm/filemap.c
70305 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70306 struct address_space *mapping = file->f_mapping;
70307
70308 if (!mapping->a_ops->readpage)
70309 - return -ENOEXEC;
70310 + return -ENODEV;
70311 file_accessed(file);
70312 vma->vm_ops = &generic_file_vm_ops;
70313 vma->vm_flags |= VM_CAN_NONLINEAR;
70314 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70315 *pos = i_size_read(inode);
70316
70317 if (limit != RLIM_INFINITY) {
70318 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70319 if (*pos >= limit) {
70320 send_sig(SIGXFSZ, current, 0);
70321 return -EFBIG;
70322 diff --git a/mm/fremap.c b/mm/fremap.c
70323 index 9ed4fd4..c42648d 100644
70324 --- a/mm/fremap.c
70325 +++ b/mm/fremap.c
70326 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70327 retry:
70328 vma = find_vma(mm, start);
70329
70330 +#ifdef CONFIG_PAX_SEGMEXEC
70331 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70332 + goto out;
70333 +#endif
70334 +
70335 /*
70336 * Make sure the vma is shared, that it supports prefaulting,
70337 * and that the remapped range is valid and fully within
70338 diff --git a/mm/highmem.c b/mm/highmem.c
70339 index 57d82c6..e9e0552 100644
70340 --- a/mm/highmem.c
70341 +++ b/mm/highmem.c
70342 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70343 * So no dangers, even with speculative execution.
70344 */
70345 page = pte_page(pkmap_page_table[i]);
70346 + pax_open_kernel();
70347 pte_clear(&init_mm, (unsigned long)page_address(page),
70348 &pkmap_page_table[i]);
70349 -
70350 + pax_close_kernel();
70351 set_page_address(page, NULL);
70352 need_flush = 1;
70353 }
70354 @@ -186,9 +187,11 @@ start:
70355 }
70356 }
70357 vaddr = PKMAP_ADDR(last_pkmap_nr);
70358 +
70359 + pax_open_kernel();
70360 set_pte_at(&init_mm, vaddr,
70361 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70362 -
70363 + pax_close_kernel();
70364 pkmap_count[last_pkmap_nr] = 1;
70365 set_page_address(page, (void *)vaddr);
70366
70367 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70368 index 8f7fc39..69bf1e9 100644
70369 --- a/mm/huge_memory.c
70370 +++ b/mm/huge_memory.c
70371 @@ -733,7 +733,7 @@ out:
70372 * run pte_offset_map on the pmd, if an huge pmd could
70373 * materialize from under us from a different thread.
70374 */
70375 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70376 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70377 return VM_FAULT_OOM;
70378 /* if an huge pmd materialized from under us just retry later */
70379 if (unlikely(pmd_trans_huge(*pmd)))
70380 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70381 index a876871..132cde0 100644
70382 --- a/mm/hugetlb.c
70383 +++ b/mm/hugetlb.c
70384 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70385 return 1;
70386 }
70387
70388 +#ifdef CONFIG_PAX_SEGMEXEC
70389 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70390 +{
70391 + struct mm_struct *mm = vma->vm_mm;
70392 + struct vm_area_struct *vma_m;
70393 + unsigned long address_m;
70394 + pte_t *ptep_m;
70395 +
70396 + vma_m = pax_find_mirror_vma(vma);
70397 + if (!vma_m)
70398 + return;
70399 +
70400 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70401 + address_m = address + SEGMEXEC_TASK_SIZE;
70402 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70403 + get_page(page_m);
70404 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70405 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70406 +}
70407 +#endif
70408 +
70409 /*
70410 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70411 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70412 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
70413 make_huge_pte(vma, new_page, 1));
70414 page_remove_rmap(old_page);
70415 hugepage_add_new_anon_rmap(new_page, vma, address);
70416 +
70417 +#ifdef CONFIG_PAX_SEGMEXEC
70418 + pax_mirror_huge_pte(vma, address, new_page);
70419 +#endif
70420 +
70421 /* Make the old page be freed below */
70422 new_page = old_page;
70423 mmu_notifier_invalidate_range_end(mm,
70424 @@ -2613,6 +2639,10 @@ retry:
70425 && (vma->vm_flags & VM_SHARED)));
70426 set_huge_pte_at(mm, address, ptep, new_pte);
70427
70428 +#ifdef CONFIG_PAX_SEGMEXEC
70429 + pax_mirror_huge_pte(vma, address, page);
70430 +#endif
70431 +
70432 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70433 /* Optimization, do the COW without a second fault */
70434 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70435 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70436 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70437 struct hstate *h = hstate_vma(vma);
70438
70439 +#ifdef CONFIG_PAX_SEGMEXEC
70440 + struct vm_area_struct *vma_m;
70441 +#endif
70442 +
70443 address &= huge_page_mask(h);
70444
70445 ptep = huge_pte_offset(mm, address);
70446 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70447 VM_FAULT_SET_HINDEX(h - hstates);
70448 }
70449
70450 +#ifdef CONFIG_PAX_SEGMEXEC
70451 + vma_m = pax_find_mirror_vma(vma);
70452 + if (vma_m) {
70453 + unsigned long address_m;
70454 +
70455 + if (vma->vm_start > vma_m->vm_start) {
70456 + address_m = address;
70457 + address -= SEGMEXEC_TASK_SIZE;
70458 + vma = vma_m;
70459 + h = hstate_vma(vma);
70460 + } else
70461 + address_m = address + SEGMEXEC_TASK_SIZE;
70462 +
70463 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70464 + return VM_FAULT_OOM;
70465 + address_m &= HPAGE_MASK;
70466 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70467 + }
70468 +#endif
70469 +
70470 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70471 if (!ptep)
70472 return VM_FAULT_OOM;
70473 diff --git a/mm/internal.h b/mm/internal.h
70474 index 2189af4..f2ca332 100644
70475 --- a/mm/internal.h
70476 +++ b/mm/internal.h
70477 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70478 * in mm/page_alloc.c
70479 */
70480 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70481 +extern void free_compound_page(struct page *page);
70482 extern void prep_compound_page(struct page *page, unsigned long order);
70483 #ifdef CONFIG_MEMORY_FAILURE
70484 extern bool is_free_buddy_page(struct page *page);
70485 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70486 index 45eb621..6ccd8ea 100644
70487 --- a/mm/kmemleak.c
70488 +++ b/mm/kmemleak.c
70489 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70490
70491 for (i = 0; i < object->trace_len; i++) {
70492 void *ptr = (void *)object->trace[i];
70493 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70494 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70495 }
70496 }
70497
70498 diff --git a/mm/maccess.c b/mm/maccess.c
70499 index d53adf9..03a24bf 100644
70500 --- a/mm/maccess.c
70501 +++ b/mm/maccess.c
70502 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70503 set_fs(KERNEL_DS);
70504 pagefault_disable();
70505 ret = __copy_from_user_inatomic(dst,
70506 - (__force const void __user *)src, size);
70507 + (const void __force_user *)src, size);
70508 pagefault_enable();
70509 set_fs(old_fs);
70510
70511 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70512
70513 set_fs(KERNEL_DS);
70514 pagefault_disable();
70515 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70516 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70517 pagefault_enable();
70518 set_fs(old_fs);
70519
70520 diff --git a/mm/madvise.c b/mm/madvise.c
70521 index 74bf193..feb6fd3 100644
70522 --- a/mm/madvise.c
70523 +++ b/mm/madvise.c
70524 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70525 pgoff_t pgoff;
70526 unsigned long new_flags = vma->vm_flags;
70527
70528 +#ifdef CONFIG_PAX_SEGMEXEC
70529 + struct vm_area_struct *vma_m;
70530 +#endif
70531 +
70532 switch (behavior) {
70533 case MADV_NORMAL:
70534 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70535 @@ -110,6 +114,13 @@ success:
70536 /*
70537 * vm_flags is protected by the mmap_sem held in write mode.
70538 */
70539 +
70540 +#ifdef CONFIG_PAX_SEGMEXEC
70541 + vma_m = pax_find_mirror_vma(vma);
70542 + if (vma_m)
70543 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70544 +#endif
70545 +
70546 vma->vm_flags = new_flags;
70547
70548 out:
70549 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70550 struct vm_area_struct ** prev,
70551 unsigned long start, unsigned long end)
70552 {
70553 +
70554 +#ifdef CONFIG_PAX_SEGMEXEC
70555 + struct vm_area_struct *vma_m;
70556 +#endif
70557 +
70558 *prev = vma;
70559 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70560 return -EINVAL;
70561 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70562 zap_page_range(vma, start, end - start, &details);
70563 } else
70564 zap_page_range(vma, start, end - start, NULL);
70565 +
70566 +#ifdef CONFIG_PAX_SEGMEXEC
70567 + vma_m = pax_find_mirror_vma(vma);
70568 + if (vma_m) {
70569 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70570 + struct zap_details details = {
70571 + .nonlinear_vma = vma_m,
70572 + .last_index = ULONG_MAX,
70573 + };
70574 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70575 + } else
70576 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70577 + }
70578 +#endif
70579 +
70580 return 0;
70581 }
70582
70583 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70584 if (end < start)
70585 goto out;
70586
70587 +#ifdef CONFIG_PAX_SEGMEXEC
70588 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70589 + if (end > SEGMEXEC_TASK_SIZE)
70590 + goto out;
70591 + } else
70592 +#endif
70593 +
70594 + if (end > TASK_SIZE)
70595 + goto out;
70596 +
70597 error = 0;
70598 if (end == start)
70599 goto out;
70600 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70601 index 56080ea..115071e 100644
70602 --- a/mm/memory-failure.c
70603 +++ b/mm/memory-failure.c
70604 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70605
70606 int sysctl_memory_failure_recovery __read_mostly = 1;
70607
70608 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70609 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70610
70611 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70612
70613 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70614 si.si_signo = SIGBUS;
70615 si.si_errno = 0;
70616 si.si_code = BUS_MCEERR_AO;
70617 - si.si_addr = (void *)addr;
70618 + si.si_addr = (void __user *)addr;
70619 #ifdef __ARCH_SI_TRAPNO
70620 si.si_trapno = trapno;
70621 #endif
70622 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70623 }
70624
70625 nr_pages = 1 << compound_trans_order(hpage);
70626 - atomic_long_add(nr_pages, &mce_bad_pages);
70627 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70628
70629 /*
70630 * We need/can do nothing about count=0 pages.
70631 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70632 if (!PageHWPoison(hpage)
70633 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70634 || (p != hpage && TestSetPageHWPoison(hpage))) {
70635 - atomic_long_sub(nr_pages, &mce_bad_pages);
70636 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70637 return 0;
70638 }
70639 set_page_hwpoison_huge_page(hpage);
70640 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70641 }
70642 if (hwpoison_filter(p)) {
70643 if (TestClearPageHWPoison(p))
70644 - atomic_long_sub(nr_pages, &mce_bad_pages);
70645 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70646 unlock_page(hpage);
70647 put_page(hpage);
70648 return 0;
70649 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70650 return 0;
70651 }
70652 if (TestClearPageHWPoison(p))
70653 - atomic_long_sub(nr_pages, &mce_bad_pages);
70654 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70655 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70656 return 0;
70657 }
70658 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70659 */
70660 if (TestClearPageHWPoison(page)) {
70661 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70662 - atomic_long_sub(nr_pages, &mce_bad_pages);
70663 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70664 freeit = 1;
70665 if (PageHuge(page))
70666 clear_page_hwpoison_huge_page(page);
70667 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70668 }
70669 done:
70670 if (!PageHWPoison(hpage))
70671 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70672 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70673 set_page_hwpoison_huge_page(hpage);
70674 dequeue_hwpoisoned_huge_page(hpage);
70675 /* keep elevated page count for bad page */
70676 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70677 return ret;
70678
70679 done:
70680 - atomic_long_add(1, &mce_bad_pages);
70681 + atomic_long_add_unchecked(1, &mce_bad_pages);
70682 SetPageHWPoison(page);
70683 /* keep elevated page count for bad page */
70684 return ret;
70685 diff --git a/mm/memory.c b/mm/memory.c
70686 index 10b4dda..764ee07 100644
70687 --- a/mm/memory.c
70688 +++ b/mm/memory.c
70689 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70690 return;
70691
70692 pmd = pmd_offset(pud, start);
70693 +
70694 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70695 pud_clear(pud);
70696 pmd_free_tlb(tlb, pmd, start);
70697 +#endif
70698 +
70699 }
70700
70701 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70702 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70703 if (end - 1 > ceiling - 1)
70704 return;
70705
70706 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70707 pud = pud_offset(pgd, start);
70708 pgd_clear(pgd);
70709 pud_free_tlb(tlb, pud, start);
70710 +#endif
70711 +
70712 }
70713
70714 /*
70715 @@ -1593,12 +1600,6 @@ no_page_table:
70716 return page;
70717 }
70718
70719 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70720 -{
70721 - return stack_guard_page_start(vma, addr) ||
70722 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70723 -}
70724 -
70725 /**
70726 * __get_user_pages() - pin user pages in memory
70727 * @tsk: task_struct of target task
70728 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70729 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70730 i = 0;
70731
70732 - do {
70733 + while (nr_pages) {
70734 struct vm_area_struct *vma;
70735
70736 - vma = find_extend_vma(mm, start);
70737 + vma = find_vma(mm, start);
70738 if (!vma && in_gate_area(mm, start)) {
70739 unsigned long pg = start & PAGE_MASK;
70740 pgd_t *pgd;
70741 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70742 goto next_page;
70743 }
70744
70745 - if (!vma ||
70746 + if (!vma || start < vma->vm_start ||
70747 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70748 !(vm_flags & vma->vm_flags))
70749 return i ? : -EFAULT;
70750 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70751 int ret;
70752 unsigned int fault_flags = 0;
70753
70754 - /* For mlock, just skip the stack guard page. */
70755 - if (foll_flags & FOLL_MLOCK) {
70756 - if (stack_guard_page(vma, start))
70757 - goto next_page;
70758 - }
70759 if (foll_flags & FOLL_WRITE)
70760 fault_flags |= FAULT_FLAG_WRITE;
70761 if (nonblocking)
70762 @@ -1827,7 +1823,7 @@ next_page:
70763 start += PAGE_SIZE;
70764 nr_pages--;
70765 } while (nr_pages && start < vma->vm_end);
70766 - } while (nr_pages);
70767 + }
70768 return i;
70769 }
70770 EXPORT_SYMBOL(__get_user_pages);
70771 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70772 page_add_file_rmap(page);
70773 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70774
70775 +#ifdef CONFIG_PAX_SEGMEXEC
70776 + pax_mirror_file_pte(vma, addr, page, ptl);
70777 +#endif
70778 +
70779 retval = 0;
70780 pte_unmap_unlock(pte, ptl);
70781 return retval;
70782 @@ -2068,10 +2068,22 @@ out:
70783 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70784 struct page *page)
70785 {
70786 +
70787 +#ifdef CONFIG_PAX_SEGMEXEC
70788 + struct vm_area_struct *vma_m;
70789 +#endif
70790 +
70791 if (addr < vma->vm_start || addr >= vma->vm_end)
70792 return -EFAULT;
70793 if (!page_count(page))
70794 return -EINVAL;
70795 +
70796 +#ifdef CONFIG_PAX_SEGMEXEC
70797 + vma_m = pax_find_mirror_vma(vma);
70798 + if (vma_m)
70799 + vma_m->vm_flags |= VM_INSERTPAGE;
70800 +#endif
70801 +
70802 vma->vm_flags |= VM_INSERTPAGE;
70803 return insert_page(vma, addr, page, vma->vm_page_prot);
70804 }
70805 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70806 unsigned long pfn)
70807 {
70808 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70809 + BUG_ON(vma->vm_mirror);
70810
70811 if (addr < vma->vm_start || addr >= vma->vm_end)
70812 return -EFAULT;
70813 @@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70814 copy_user_highpage(dst, src, va, vma);
70815 }
70816
70817 +#ifdef CONFIG_PAX_SEGMEXEC
70818 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70819 +{
70820 + struct mm_struct *mm = vma->vm_mm;
70821 + spinlock_t *ptl;
70822 + pte_t *pte, entry;
70823 +
70824 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70825 + entry = *pte;
70826 + if (!pte_present(entry)) {
70827 + if (!pte_none(entry)) {
70828 + BUG_ON(pte_file(entry));
70829 + free_swap_and_cache(pte_to_swp_entry(entry));
70830 + pte_clear_not_present_full(mm, address, pte, 0);
70831 + }
70832 + } else {
70833 + struct page *page;
70834 +
70835 + flush_cache_page(vma, address, pte_pfn(entry));
70836 + entry = ptep_clear_flush(vma, address, pte);
70837 + BUG_ON(pte_dirty(entry));
70838 + page = vm_normal_page(vma, address, entry);
70839 + if (page) {
70840 + update_hiwater_rss(mm);
70841 + if (PageAnon(page))
70842 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70843 + else
70844 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70845 + page_remove_rmap(page);
70846 + page_cache_release(page);
70847 + }
70848 + }
70849 + pte_unmap_unlock(pte, ptl);
70850 +}
70851 +
70852 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70853 + *
70854 + * the ptl of the lower mapped page is held on entry and is not released on exit
70855 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70856 + */
70857 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70858 +{
70859 + struct mm_struct *mm = vma->vm_mm;
70860 + unsigned long address_m;
70861 + spinlock_t *ptl_m;
70862 + struct vm_area_struct *vma_m;
70863 + pmd_t *pmd_m;
70864 + pte_t *pte_m, entry_m;
70865 +
70866 + BUG_ON(!page_m || !PageAnon(page_m));
70867 +
70868 + vma_m = pax_find_mirror_vma(vma);
70869 + if (!vma_m)
70870 + return;
70871 +
70872 + BUG_ON(!PageLocked(page_m));
70873 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70874 + address_m = address + SEGMEXEC_TASK_SIZE;
70875 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70876 + pte_m = pte_offset_map(pmd_m, address_m);
70877 + ptl_m = pte_lockptr(mm, pmd_m);
70878 + if (ptl != ptl_m) {
70879 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70880 + if (!pte_none(*pte_m))
70881 + goto out;
70882 + }
70883 +
70884 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70885 + page_cache_get(page_m);
70886 + page_add_anon_rmap(page_m, vma_m, address_m);
70887 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70888 + set_pte_at(mm, address_m, pte_m, entry_m);
70889 + update_mmu_cache(vma_m, address_m, entry_m);
70890 +out:
70891 + if (ptl != ptl_m)
70892 + spin_unlock(ptl_m);
70893 + pte_unmap(pte_m);
70894 + unlock_page(page_m);
70895 +}
70896 +
70897 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70898 +{
70899 + struct mm_struct *mm = vma->vm_mm;
70900 + unsigned long address_m;
70901 + spinlock_t *ptl_m;
70902 + struct vm_area_struct *vma_m;
70903 + pmd_t *pmd_m;
70904 + pte_t *pte_m, entry_m;
70905 +
70906 + BUG_ON(!page_m || PageAnon(page_m));
70907 +
70908 + vma_m = pax_find_mirror_vma(vma);
70909 + if (!vma_m)
70910 + return;
70911 +
70912 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70913 + address_m = address + SEGMEXEC_TASK_SIZE;
70914 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70915 + pte_m = pte_offset_map(pmd_m, address_m);
70916 + ptl_m = pte_lockptr(mm, pmd_m);
70917 + if (ptl != ptl_m) {
70918 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70919 + if (!pte_none(*pte_m))
70920 + goto out;
70921 + }
70922 +
70923 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70924 + page_cache_get(page_m);
70925 + page_add_file_rmap(page_m);
70926 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70927 + set_pte_at(mm, address_m, pte_m, entry_m);
70928 + update_mmu_cache(vma_m, address_m, entry_m);
70929 +out:
70930 + if (ptl != ptl_m)
70931 + spin_unlock(ptl_m);
70932 + pte_unmap(pte_m);
70933 +}
70934 +
70935 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70936 +{
70937 + struct mm_struct *mm = vma->vm_mm;
70938 + unsigned long address_m;
70939 + spinlock_t *ptl_m;
70940 + struct vm_area_struct *vma_m;
70941 + pmd_t *pmd_m;
70942 + pte_t *pte_m, entry_m;
70943 +
70944 + vma_m = pax_find_mirror_vma(vma);
70945 + if (!vma_m)
70946 + return;
70947 +
70948 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70949 + address_m = address + SEGMEXEC_TASK_SIZE;
70950 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70951 + pte_m = pte_offset_map(pmd_m, address_m);
70952 + ptl_m = pte_lockptr(mm, pmd_m);
70953 + if (ptl != ptl_m) {
70954 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70955 + if (!pte_none(*pte_m))
70956 + goto out;
70957 + }
70958 +
70959 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70960 + set_pte_at(mm, address_m, pte_m, entry_m);
70961 +out:
70962 + if (ptl != ptl_m)
70963 + spin_unlock(ptl_m);
70964 + pte_unmap(pte_m);
70965 +}
70966 +
70967 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70968 +{
70969 + struct page *page_m;
70970 + pte_t entry;
70971 +
70972 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70973 + goto out;
70974 +
70975 + entry = *pte;
70976 + page_m = vm_normal_page(vma, address, entry);
70977 + if (!page_m)
70978 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70979 + else if (PageAnon(page_m)) {
70980 + if (pax_find_mirror_vma(vma)) {
70981 + pte_unmap_unlock(pte, ptl);
70982 + lock_page(page_m);
70983 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70984 + if (pte_same(entry, *pte))
70985 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70986 + else
70987 + unlock_page(page_m);
70988 + }
70989 + } else
70990 + pax_mirror_file_pte(vma, address, page_m, ptl);
70991 +
70992 +out:
70993 + pte_unmap_unlock(pte, ptl);
70994 +}
70995 +#endif
70996 +
70997 /*
70998 * This routine handles present pages, when users try to write
70999 * to a shared page. It is done by copying the page to a new address
71000 @@ -2683,6 +2876,12 @@ gotten:
71001 */
71002 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71003 if (likely(pte_same(*page_table, orig_pte))) {
71004 +
71005 +#ifdef CONFIG_PAX_SEGMEXEC
71006 + if (pax_find_mirror_vma(vma))
71007 + BUG_ON(!trylock_page(new_page));
71008 +#endif
71009 +
71010 if (old_page) {
71011 if (!PageAnon(old_page)) {
71012 dec_mm_counter_fast(mm, MM_FILEPAGES);
71013 @@ -2734,6 +2933,10 @@ gotten:
71014 page_remove_rmap(old_page);
71015 }
71016
71017 +#ifdef CONFIG_PAX_SEGMEXEC
71018 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71019 +#endif
71020 +
71021 /* Free the old page.. */
71022 new_page = old_page;
71023 ret |= VM_FAULT_WRITE;
71024 @@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71025 swap_free(entry);
71026 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71027 try_to_free_swap(page);
71028 +
71029 +#ifdef CONFIG_PAX_SEGMEXEC
71030 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71031 +#endif
71032 +
71033 unlock_page(page);
71034 if (swapcache) {
71035 /*
71036 @@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71037
71038 /* No need to invalidate - it was non-present before */
71039 update_mmu_cache(vma, address, page_table);
71040 +
71041 +#ifdef CONFIG_PAX_SEGMEXEC
71042 + pax_mirror_anon_pte(vma, address, page, ptl);
71043 +#endif
71044 +
71045 unlock:
71046 pte_unmap_unlock(page_table, ptl);
71047 out:
71048 @@ -3055,40 +3268,6 @@ out_release:
71049 }
71050
71051 /*
71052 - * This is like a special single-page "expand_{down|up}wards()",
71053 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71054 - * doesn't hit another vma.
71055 - */
71056 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71057 -{
71058 - address &= PAGE_MASK;
71059 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71060 - struct vm_area_struct *prev = vma->vm_prev;
71061 -
71062 - /*
71063 - * Is there a mapping abutting this one below?
71064 - *
71065 - * That's only ok if it's the same stack mapping
71066 - * that has gotten split..
71067 - */
71068 - if (prev && prev->vm_end == address)
71069 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71070 -
71071 - expand_downwards(vma, address - PAGE_SIZE);
71072 - }
71073 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71074 - struct vm_area_struct *next = vma->vm_next;
71075 -
71076 - /* As VM_GROWSDOWN but s/below/above/ */
71077 - if (next && next->vm_start == address + PAGE_SIZE)
71078 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71079 -
71080 - expand_upwards(vma, address + PAGE_SIZE);
71081 - }
71082 - return 0;
71083 -}
71084 -
71085 -/*
71086 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71087 * but allow concurrent faults), and pte mapped but not yet locked.
71088 * We return with mmap_sem still held, but pte unmapped and unlocked.
71089 @@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71090 unsigned long address, pte_t *page_table, pmd_t *pmd,
71091 unsigned int flags)
71092 {
71093 - struct page *page;
71094 + struct page *page = NULL;
71095 spinlock_t *ptl;
71096 pte_t entry;
71097
71098 - pte_unmap(page_table);
71099 -
71100 - /* Check if we need to add a guard page to the stack */
71101 - if (check_stack_guard_page(vma, address) < 0)
71102 - return VM_FAULT_SIGBUS;
71103 -
71104 - /* Use the zero-page for reads */
71105 if (!(flags & FAULT_FLAG_WRITE)) {
71106 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71107 vma->vm_page_prot));
71108 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71109 + ptl = pte_lockptr(mm, pmd);
71110 + spin_lock(ptl);
71111 if (!pte_none(*page_table))
71112 goto unlock;
71113 goto setpte;
71114 }
71115
71116 /* Allocate our own private page. */
71117 + pte_unmap(page_table);
71118 +
71119 if (unlikely(anon_vma_prepare(vma)))
71120 goto oom;
71121 page = alloc_zeroed_user_highpage_movable(vma, address);
71122 @@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71123 if (!pte_none(*page_table))
71124 goto release;
71125
71126 +#ifdef CONFIG_PAX_SEGMEXEC
71127 + if (pax_find_mirror_vma(vma))
71128 + BUG_ON(!trylock_page(page));
71129 +#endif
71130 +
71131 inc_mm_counter_fast(mm, MM_ANONPAGES);
71132 page_add_new_anon_rmap(page, vma, address);
71133 setpte:
71134 @@ -3143,6 +3323,12 @@ setpte:
71135
71136 /* No need to invalidate - it was non-present before */
71137 update_mmu_cache(vma, address, page_table);
71138 +
71139 +#ifdef CONFIG_PAX_SEGMEXEC
71140 + if (page)
71141 + pax_mirror_anon_pte(vma, address, page, ptl);
71142 +#endif
71143 +
71144 unlock:
71145 pte_unmap_unlock(page_table, ptl);
71146 return 0;
71147 @@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71148 */
71149 /* Only go through if we didn't race with anybody else... */
71150 if (likely(pte_same(*page_table, orig_pte))) {
71151 +
71152 +#ifdef CONFIG_PAX_SEGMEXEC
71153 + if (anon && pax_find_mirror_vma(vma))
71154 + BUG_ON(!trylock_page(page));
71155 +#endif
71156 +
71157 flush_icache_page(vma, page);
71158 entry = mk_pte(page, vma->vm_page_prot);
71159 if (flags & FAULT_FLAG_WRITE)
71160 @@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71161
71162 /* no need to invalidate: a not-present page won't be cached */
71163 update_mmu_cache(vma, address, page_table);
71164 +
71165 +#ifdef CONFIG_PAX_SEGMEXEC
71166 + if (anon)
71167 + pax_mirror_anon_pte(vma, address, page, ptl);
71168 + else
71169 + pax_mirror_file_pte(vma, address, page, ptl);
71170 +#endif
71171 +
71172 } else {
71173 if (cow_page)
71174 mem_cgroup_uncharge_page(cow_page);
71175 @@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
71176 if (flags & FAULT_FLAG_WRITE)
71177 flush_tlb_fix_spurious_fault(vma, address);
71178 }
71179 +
71180 +#ifdef CONFIG_PAX_SEGMEXEC
71181 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71182 + return 0;
71183 +#endif
71184 +
71185 unlock:
71186 pte_unmap_unlock(pte, ptl);
71187 return 0;
71188 @@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71189 pmd_t *pmd;
71190 pte_t *pte;
71191
71192 +#ifdef CONFIG_PAX_SEGMEXEC
71193 + struct vm_area_struct *vma_m;
71194 +#endif
71195 +
71196 __set_current_state(TASK_RUNNING);
71197
71198 count_vm_event(PGFAULT);
71199 @@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71200 if (unlikely(is_vm_hugetlb_page(vma)))
71201 return hugetlb_fault(mm, vma, address, flags);
71202
71203 +#ifdef CONFIG_PAX_SEGMEXEC
71204 + vma_m = pax_find_mirror_vma(vma);
71205 + if (vma_m) {
71206 + unsigned long address_m;
71207 + pgd_t *pgd_m;
71208 + pud_t *pud_m;
71209 + pmd_t *pmd_m;
71210 +
71211 + if (vma->vm_start > vma_m->vm_start) {
71212 + address_m = address;
71213 + address -= SEGMEXEC_TASK_SIZE;
71214 + vma = vma_m;
71215 + } else
71216 + address_m = address + SEGMEXEC_TASK_SIZE;
71217 +
71218 + pgd_m = pgd_offset(mm, address_m);
71219 + pud_m = pud_alloc(mm, pgd_m, address_m);
71220 + if (!pud_m)
71221 + return VM_FAULT_OOM;
71222 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71223 + if (!pmd_m)
71224 + return VM_FAULT_OOM;
71225 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71226 + return VM_FAULT_OOM;
71227 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71228 + }
71229 +#endif
71230 +
71231 pgd = pgd_offset(mm, address);
71232 pud = pud_alloc(mm, pgd, address);
71233 if (!pud)
71234 @@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71235 * run pte_offset_map on the pmd, if an huge pmd could
71236 * materialize from under us from a different thread.
71237 */
71238 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71239 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71240 return VM_FAULT_OOM;
71241 /* if an huge pmd materialized from under us just retry later */
71242 if (unlikely(pmd_trans_huge(*pmd)))
71243 @@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
71244 gate_vma.vm_start = FIXADDR_USER_START;
71245 gate_vma.vm_end = FIXADDR_USER_END;
71246 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71247 - gate_vma.vm_page_prot = __P101;
71248 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71249 /*
71250 * Make sure the vDSO gets into every core dump.
71251 * Dumping its contents makes post-mortem fully interpretable later
71252 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71253 index 0a37570..2048346 100644
71254 --- a/mm/mempolicy.c
71255 +++ b/mm/mempolicy.c
71256 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71257 unsigned long vmstart;
71258 unsigned long vmend;
71259
71260 +#ifdef CONFIG_PAX_SEGMEXEC
71261 + struct vm_area_struct *vma_m;
71262 +#endif
71263 +
71264 vma = find_vma(mm, start);
71265 if (!vma || vma->vm_start > start)
71266 return -EFAULT;
71267 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71268 err = policy_vma(vma, new_pol);
71269 if (err)
71270 goto out;
71271 +
71272 +#ifdef CONFIG_PAX_SEGMEXEC
71273 + vma_m = pax_find_mirror_vma(vma);
71274 + if (vma_m) {
71275 + err = policy_vma(vma_m, new_pol);
71276 + if (err)
71277 + goto out;
71278 + }
71279 +#endif
71280 +
71281 }
71282
71283 out:
71284 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71285
71286 if (end < start)
71287 return -EINVAL;
71288 +
71289 +#ifdef CONFIG_PAX_SEGMEXEC
71290 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71291 + if (end > SEGMEXEC_TASK_SIZE)
71292 + return -EINVAL;
71293 + } else
71294 +#endif
71295 +
71296 + if (end > TASK_SIZE)
71297 + return -EINVAL;
71298 +
71299 if (end == start)
71300 return 0;
71301
71302 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71303 if (!mm)
71304 goto out;
71305
71306 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71307 + if (mm != current->mm &&
71308 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71309 + err = -EPERM;
71310 + goto out;
71311 + }
71312 +#endif
71313 +
71314 /*
71315 * Check if this process has the right to modify the specified
71316 * process. The right exists if the process has administrative
71317 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71318 rcu_read_lock();
71319 tcred = __task_cred(task);
71320 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71321 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71322 - !capable(CAP_SYS_NICE)) {
71323 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71324 rcu_read_unlock();
71325 err = -EPERM;
71326 goto out;
71327 diff --git a/mm/migrate.c b/mm/migrate.c
71328 index 1503b6b..156c672 100644
71329 --- a/mm/migrate.c
71330 +++ b/mm/migrate.c
71331 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71332 if (!mm)
71333 return -EINVAL;
71334
71335 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71336 + if (mm != current->mm &&
71337 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71338 + err = -EPERM;
71339 + goto out;
71340 + }
71341 +#endif
71342 +
71343 /*
71344 * Check if this process has the right to modify the specified
71345 * process. The right exists if the process has administrative
71346 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71347 rcu_read_lock();
71348 tcred = __task_cred(task);
71349 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71350 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71351 - !capable(CAP_SYS_NICE)) {
71352 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71353 rcu_read_unlock();
71354 err = -EPERM;
71355 goto out;
71356 diff --git a/mm/mlock.c b/mm/mlock.c
71357 index ef726e8..13e0901 100644
71358 --- a/mm/mlock.c
71359 +++ b/mm/mlock.c
71360 @@ -13,6 +13,7 @@
71361 #include <linux/pagemap.h>
71362 #include <linux/mempolicy.h>
71363 #include <linux/syscalls.h>
71364 +#include <linux/security.h>
71365 #include <linux/sched.h>
71366 #include <linux/export.h>
71367 #include <linux/rmap.h>
71368 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71369 return -EINVAL;
71370 if (end == start)
71371 return 0;
71372 + if (end > TASK_SIZE)
71373 + return -EINVAL;
71374 +
71375 vma = find_vma(current->mm, start);
71376 if (!vma || vma->vm_start > start)
71377 return -ENOMEM;
71378 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71379 for (nstart = start ; ; ) {
71380 vm_flags_t newflags;
71381
71382 +#ifdef CONFIG_PAX_SEGMEXEC
71383 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71384 + break;
71385 +#endif
71386 +
71387 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71388
71389 newflags = vma->vm_flags | VM_LOCKED;
71390 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71391 lock_limit >>= PAGE_SHIFT;
71392
71393 /* check against resource limits */
71394 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71395 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71396 error = do_mlock(start, len, 1);
71397 up_write(&current->mm->mmap_sem);
71398 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71399 static int do_mlockall(int flags)
71400 {
71401 struct vm_area_struct * vma, * prev = NULL;
71402 - unsigned int def_flags = 0;
71403
71404 if (flags & MCL_FUTURE)
71405 - def_flags = VM_LOCKED;
71406 - current->mm->def_flags = def_flags;
71407 + current->mm->def_flags |= VM_LOCKED;
71408 + else
71409 + current->mm->def_flags &= ~VM_LOCKED;
71410 if (flags == MCL_FUTURE)
71411 goto out;
71412
71413 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71414 vm_flags_t newflags;
71415
71416 +#ifdef CONFIG_PAX_SEGMEXEC
71417 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71418 + break;
71419 +#endif
71420 +
71421 + BUG_ON(vma->vm_end > TASK_SIZE);
71422 newflags = vma->vm_flags | VM_LOCKED;
71423 if (!(flags & MCL_CURRENT))
71424 newflags &= ~VM_LOCKED;
71425 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71426 lock_limit >>= PAGE_SHIFT;
71427
71428 ret = -ENOMEM;
71429 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71430 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71431 capable(CAP_IPC_LOCK))
71432 ret = do_mlockall(flags);
71433 diff --git a/mm/mmap.c b/mm/mmap.c
71434 index da15a79..314aef3 100644
71435 --- a/mm/mmap.c
71436 +++ b/mm/mmap.c
71437 @@ -46,6 +46,16 @@
71438 #define arch_rebalance_pgtables(addr, len) (addr)
71439 #endif
71440
71441 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71442 +{
71443 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71444 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71445 + up_read(&mm->mmap_sem);
71446 + BUG();
71447 + }
71448 +#endif
71449 +}
71450 +
71451 static void unmap_region(struct mm_struct *mm,
71452 struct vm_area_struct *vma, struct vm_area_struct *prev,
71453 unsigned long start, unsigned long end);
71454 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71455 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71456 *
71457 */
71458 -pgprot_t protection_map[16] = {
71459 +pgprot_t protection_map[16] __read_only = {
71460 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71461 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71462 };
71463
71464 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71465 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71466 {
71467 - return __pgprot(pgprot_val(protection_map[vm_flags &
71468 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71469 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71470 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71471 +
71472 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71473 + if (!(__supported_pte_mask & _PAGE_NX) &&
71474 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71475 + (vm_flags & (VM_READ | VM_WRITE)))
71476 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71477 +#endif
71478 +
71479 + return prot;
71480 }
71481 EXPORT_SYMBOL(vm_get_page_prot);
71482
71483 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71484 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71485 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71486 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71487 /*
71488 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71489 * other variables. It can be updated by several CPUs frequently.
71490 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71491 struct vm_area_struct *next = vma->vm_next;
71492
71493 might_sleep();
71494 + BUG_ON(vma->vm_mirror);
71495 if (vma->vm_ops && vma->vm_ops->close)
71496 vma->vm_ops->close(vma);
71497 if (vma->vm_file) {
71498 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71499 * not page aligned -Ram Gupta
71500 */
71501 rlim = rlimit(RLIMIT_DATA);
71502 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71503 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71504 (mm->end_data - mm->start_data) > rlim)
71505 goto out;
71506 @@ -689,6 +711,12 @@ static int
71507 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71508 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71509 {
71510 +
71511 +#ifdef CONFIG_PAX_SEGMEXEC
71512 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71513 + return 0;
71514 +#endif
71515 +
71516 if (is_mergeable_vma(vma, file, vm_flags) &&
71517 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71518 if (vma->vm_pgoff == vm_pgoff)
71519 @@ -708,6 +736,12 @@ static int
71520 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71521 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71522 {
71523 +
71524 +#ifdef CONFIG_PAX_SEGMEXEC
71525 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71526 + return 0;
71527 +#endif
71528 +
71529 if (is_mergeable_vma(vma, file, vm_flags) &&
71530 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71531 pgoff_t vm_pglen;
71532 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71533 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71534 struct vm_area_struct *prev, unsigned long addr,
71535 unsigned long end, unsigned long vm_flags,
71536 - struct anon_vma *anon_vma, struct file *file,
71537 + struct anon_vma *anon_vma, struct file *file,
71538 pgoff_t pgoff, struct mempolicy *policy)
71539 {
71540 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71541 struct vm_area_struct *area, *next;
71542 int err;
71543
71544 +#ifdef CONFIG_PAX_SEGMEXEC
71545 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71546 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71547 +
71548 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71549 +#endif
71550 +
71551 /*
71552 * We later require that vma->vm_flags == vm_flags,
71553 * so this tests vma->vm_flags & VM_SPECIAL, too.
71554 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71555 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71556 next = next->vm_next;
71557
71558 +#ifdef CONFIG_PAX_SEGMEXEC
71559 + if (prev)
71560 + prev_m = pax_find_mirror_vma(prev);
71561 + if (area)
71562 + area_m = pax_find_mirror_vma(area);
71563 + if (next)
71564 + next_m = pax_find_mirror_vma(next);
71565 +#endif
71566 +
71567 /*
71568 * Can it merge with the predecessor?
71569 */
71570 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71571 /* cases 1, 6 */
71572 err = vma_adjust(prev, prev->vm_start,
71573 next->vm_end, prev->vm_pgoff, NULL);
71574 - } else /* cases 2, 5, 7 */
71575 +
71576 +#ifdef CONFIG_PAX_SEGMEXEC
71577 + if (!err && prev_m)
71578 + err = vma_adjust(prev_m, prev_m->vm_start,
71579 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71580 +#endif
71581 +
71582 + } else { /* cases 2, 5, 7 */
71583 err = vma_adjust(prev, prev->vm_start,
71584 end, prev->vm_pgoff, NULL);
71585 +
71586 +#ifdef CONFIG_PAX_SEGMEXEC
71587 + if (!err && prev_m)
71588 + err = vma_adjust(prev_m, prev_m->vm_start,
71589 + end_m, prev_m->vm_pgoff, NULL);
71590 +#endif
71591 +
71592 + }
71593 if (err)
71594 return NULL;
71595 khugepaged_enter_vma_merge(prev);
71596 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71597 mpol_equal(policy, vma_policy(next)) &&
71598 can_vma_merge_before(next, vm_flags,
71599 anon_vma, file, pgoff+pglen)) {
71600 - if (prev && addr < prev->vm_end) /* case 4 */
71601 + if (prev && addr < prev->vm_end) { /* case 4 */
71602 err = vma_adjust(prev, prev->vm_start,
71603 addr, prev->vm_pgoff, NULL);
71604 - else /* cases 3, 8 */
71605 +
71606 +#ifdef CONFIG_PAX_SEGMEXEC
71607 + if (!err && prev_m)
71608 + err = vma_adjust(prev_m, prev_m->vm_start,
71609 + addr_m, prev_m->vm_pgoff, NULL);
71610 +#endif
71611 +
71612 + } else { /* cases 3, 8 */
71613 err = vma_adjust(area, addr, next->vm_end,
71614 next->vm_pgoff - pglen, NULL);
71615 +
71616 +#ifdef CONFIG_PAX_SEGMEXEC
71617 + if (!err && area_m)
71618 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71619 + next_m->vm_pgoff - pglen, NULL);
71620 +#endif
71621 +
71622 + }
71623 if (err)
71624 return NULL;
71625 khugepaged_enter_vma_merge(area);
71626 @@ -921,14 +1001,11 @@ none:
71627 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71628 struct file *file, long pages)
71629 {
71630 - const unsigned long stack_flags
71631 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71632 -
71633 if (file) {
71634 mm->shared_vm += pages;
71635 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71636 mm->exec_vm += pages;
71637 - } else if (flags & stack_flags)
71638 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71639 mm->stack_vm += pages;
71640 if (flags & (VM_RESERVED|VM_IO))
71641 mm->reserved_vm += pages;
71642 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71643 * (the exception is when the underlying filesystem is noexec
71644 * mounted, in which case we dont add PROT_EXEC.)
71645 */
71646 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71647 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71648 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71649 prot |= PROT_EXEC;
71650
71651 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71652 /* Obtain the address to map to. we verify (or select) it and ensure
71653 * that it represents a valid section of the address space.
71654 */
71655 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71656 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71657 if (addr & ~PAGE_MASK)
71658 return addr;
71659
71660 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71661 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71662 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71663
71664 +#ifdef CONFIG_PAX_MPROTECT
71665 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71666 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71667 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71668 + gr_log_rwxmmap(file);
71669 +
71670 +#ifdef CONFIG_PAX_EMUPLT
71671 + vm_flags &= ~VM_EXEC;
71672 +#else
71673 + return -EPERM;
71674 +#endif
71675 +
71676 + }
71677 +
71678 + if (!(vm_flags & VM_EXEC))
71679 + vm_flags &= ~VM_MAYEXEC;
71680 +#else
71681 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71682 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71683 +#endif
71684 + else
71685 + vm_flags &= ~VM_MAYWRITE;
71686 + }
71687 +#endif
71688 +
71689 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71690 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71691 + vm_flags &= ~VM_PAGEEXEC;
71692 +#endif
71693 +
71694 if (flags & MAP_LOCKED)
71695 if (!can_do_mlock())
71696 return -EPERM;
71697 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71698 locked += mm->locked_vm;
71699 lock_limit = rlimit(RLIMIT_MEMLOCK);
71700 lock_limit >>= PAGE_SHIFT;
71701 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71702 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71703 return -EAGAIN;
71704 }
71705 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71706 if (error)
71707 return error;
71708
71709 + if (!gr_acl_handle_mmap(file, prot))
71710 + return -EACCES;
71711 +
71712 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71713 }
71714 EXPORT_SYMBOL(do_mmap_pgoff);
71715 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71716 vm_flags_t vm_flags = vma->vm_flags;
71717
71718 /* If it was private or non-writable, the write bit is already clear */
71719 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71720 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71721 return 0;
71722
71723 /* The backer wishes to know when pages are first written to? */
71724 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71725 unsigned long charged = 0;
71726 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71727
71728 +#ifdef CONFIG_PAX_SEGMEXEC
71729 + struct vm_area_struct *vma_m = NULL;
71730 +#endif
71731 +
71732 + /*
71733 + * mm->mmap_sem is required to protect against another thread
71734 + * changing the mappings in case we sleep.
71735 + */
71736 + verify_mm_writelocked(mm);
71737 +
71738 /* Clear old maps */
71739 error = -ENOMEM;
71740 -munmap_back:
71741 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71742 if (vma && vma->vm_start < addr + len) {
71743 if (do_munmap(mm, addr, len))
71744 return -ENOMEM;
71745 - goto munmap_back;
71746 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71747 + BUG_ON(vma && vma->vm_start < addr + len);
71748 }
71749
71750 /* Check against address space limit. */
71751 @@ -1258,6 +1379,16 @@ munmap_back:
71752 goto unacct_error;
71753 }
71754
71755 +#ifdef CONFIG_PAX_SEGMEXEC
71756 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71757 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71758 + if (!vma_m) {
71759 + error = -ENOMEM;
71760 + goto free_vma;
71761 + }
71762 + }
71763 +#endif
71764 +
71765 vma->vm_mm = mm;
71766 vma->vm_start = addr;
71767 vma->vm_end = addr + len;
71768 @@ -1282,6 +1413,19 @@ munmap_back:
71769 error = file->f_op->mmap(file, vma);
71770 if (error)
71771 goto unmap_and_free_vma;
71772 +
71773 +#ifdef CONFIG_PAX_SEGMEXEC
71774 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71775 + added_exe_file_vma(mm);
71776 +#endif
71777 +
71778 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71779 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71780 + vma->vm_flags |= VM_PAGEEXEC;
71781 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71782 + }
71783 +#endif
71784 +
71785 if (vm_flags & VM_EXECUTABLE)
71786 added_exe_file_vma(mm);
71787
71788 @@ -1319,6 +1463,11 @@ munmap_back:
71789 vma_link(mm, vma, prev, rb_link, rb_parent);
71790 file = vma->vm_file;
71791
71792 +#ifdef CONFIG_PAX_SEGMEXEC
71793 + if (vma_m)
71794 + BUG_ON(pax_mirror_vma(vma_m, vma));
71795 +#endif
71796 +
71797 /* Once vma denies write, undo our temporary denial count */
71798 if (correct_wcount)
71799 atomic_inc(&inode->i_writecount);
71800 @@ -1327,6 +1476,7 @@ out:
71801
71802 mm->total_vm += len >> PAGE_SHIFT;
71803 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71804 + track_exec_limit(mm, addr, addr + len, vm_flags);
71805 if (vm_flags & VM_LOCKED) {
71806 if (!mlock_vma_pages_range(vma, addr, addr + len))
71807 mm->locked_vm += (len >> PAGE_SHIFT);
71808 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71809 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71810 charged = 0;
71811 free_vma:
71812 +
71813 +#ifdef CONFIG_PAX_SEGMEXEC
71814 + if (vma_m)
71815 + kmem_cache_free(vm_area_cachep, vma_m);
71816 +#endif
71817 +
71818 kmem_cache_free(vm_area_cachep, vma);
71819 unacct_error:
71820 if (charged)
71821 @@ -1351,6 +1507,44 @@ unacct_error:
71822 return error;
71823 }
71824
71825 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71826 +{
71827 + if (!vma) {
71828 +#ifdef CONFIG_STACK_GROWSUP
71829 + if (addr > sysctl_heap_stack_gap)
71830 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71831 + else
71832 + vma = find_vma(current->mm, 0);
71833 + if (vma && (vma->vm_flags & VM_GROWSUP))
71834 + return false;
71835 +#endif
71836 + return true;
71837 + }
71838 +
71839 + if (addr + len > vma->vm_start)
71840 + return false;
71841 +
71842 + if (vma->vm_flags & VM_GROWSDOWN)
71843 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71844 +#ifdef CONFIG_STACK_GROWSUP
71845 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71846 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71847 +#endif
71848 +
71849 + return true;
71850 +}
71851 +
71852 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71853 +{
71854 + if (vma->vm_start < len)
71855 + return -ENOMEM;
71856 + if (!(vma->vm_flags & VM_GROWSDOWN))
71857 + return vma->vm_start - len;
71858 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71859 + return vma->vm_start - len - sysctl_heap_stack_gap;
71860 + return -ENOMEM;
71861 +}
71862 +
71863 /* Get an address range which is currently unmapped.
71864 * For shmat() with addr=0.
71865 *
71866 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71867 if (flags & MAP_FIXED)
71868 return addr;
71869
71870 +#ifdef CONFIG_PAX_RANDMMAP
71871 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71872 +#endif
71873 +
71874 if (addr) {
71875 addr = PAGE_ALIGN(addr);
71876 - vma = find_vma(mm, addr);
71877 - if (TASK_SIZE - len >= addr &&
71878 - (!vma || addr + len <= vma->vm_start))
71879 - return addr;
71880 + if (TASK_SIZE - len >= addr) {
71881 + vma = find_vma(mm, addr);
71882 + if (check_heap_stack_gap(vma, addr, len))
71883 + return addr;
71884 + }
71885 }
71886 if (len > mm->cached_hole_size) {
71887 - start_addr = addr = mm->free_area_cache;
71888 + start_addr = addr = mm->free_area_cache;
71889 } else {
71890 - start_addr = addr = TASK_UNMAPPED_BASE;
71891 - mm->cached_hole_size = 0;
71892 + start_addr = addr = mm->mmap_base;
71893 + mm->cached_hole_size = 0;
71894 }
71895
71896 full_search:
71897 @@ -1399,34 +1598,40 @@ full_search:
71898 * Start a new search - just in case we missed
71899 * some holes.
71900 */
71901 - if (start_addr != TASK_UNMAPPED_BASE) {
71902 - addr = TASK_UNMAPPED_BASE;
71903 - start_addr = addr;
71904 + if (start_addr != mm->mmap_base) {
71905 + start_addr = addr = mm->mmap_base;
71906 mm->cached_hole_size = 0;
71907 goto full_search;
71908 }
71909 return -ENOMEM;
71910 }
71911 - if (!vma || addr + len <= vma->vm_start) {
71912 - /*
71913 - * Remember the place where we stopped the search:
71914 - */
71915 - mm->free_area_cache = addr + len;
71916 - return addr;
71917 - }
71918 + if (check_heap_stack_gap(vma, addr, len))
71919 + break;
71920 if (addr + mm->cached_hole_size < vma->vm_start)
71921 mm->cached_hole_size = vma->vm_start - addr;
71922 addr = vma->vm_end;
71923 }
71924 +
71925 + /*
71926 + * Remember the place where we stopped the search:
71927 + */
71928 + mm->free_area_cache = addr + len;
71929 + return addr;
71930 }
71931 #endif
71932
71933 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71934 {
71935 +
71936 +#ifdef CONFIG_PAX_SEGMEXEC
71937 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71938 + return;
71939 +#endif
71940 +
71941 /*
71942 * Is this a new hole at the lowest possible address?
71943 */
71944 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71945 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71946 mm->free_area_cache = addr;
71947 mm->cached_hole_size = ~0UL;
71948 }
71949 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71950 {
71951 struct vm_area_struct *vma;
71952 struct mm_struct *mm = current->mm;
71953 - unsigned long addr = addr0;
71954 + unsigned long base = mm->mmap_base, addr = addr0;
71955
71956 /* requested length too big for entire address space */
71957 if (len > TASK_SIZE)
71958 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71959 if (flags & MAP_FIXED)
71960 return addr;
71961
71962 +#ifdef CONFIG_PAX_RANDMMAP
71963 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71964 +#endif
71965 +
71966 /* requesting a specific address */
71967 if (addr) {
71968 addr = PAGE_ALIGN(addr);
71969 - vma = find_vma(mm, addr);
71970 - if (TASK_SIZE - len >= addr &&
71971 - (!vma || addr + len <= vma->vm_start))
71972 - return addr;
71973 + if (TASK_SIZE - len >= addr) {
71974 + vma = find_vma(mm, addr);
71975 + if (check_heap_stack_gap(vma, addr, len))
71976 + return addr;
71977 + }
71978 }
71979
71980 /* check if free_area_cache is useful for us */
71981 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71982 /* make sure it can fit in the remaining address space */
71983 if (addr > len) {
71984 vma = find_vma(mm, addr-len);
71985 - if (!vma || addr <= vma->vm_start)
71986 + if (check_heap_stack_gap(vma, addr - len, len))
71987 /* remember the address as a hint for next time */
71988 return (mm->free_area_cache = addr-len);
71989 }
71990 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71991 * return with success:
71992 */
71993 vma = find_vma(mm, addr);
71994 - if (!vma || addr+len <= vma->vm_start)
71995 + if (check_heap_stack_gap(vma, addr, len))
71996 /* remember the address as a hint for next time */
71997 return (mm->free_area_cache = addr);
71998
71999 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72000 mm->cached_hole_size = vma->vm_start - addr;
72001
72002 /* try just below the current vma->vm_start */
72003 - addr = vma->vm_start-len;
72004 - } while (len < vma->vm_start);
72005 + addr = skip_heap_stack_gap(vma, len);
72006 + } while (!IS_ERR_VALUE(addr));
72007
72008 bottomup:
72009 /*
72010 @@ -1510,13 +1720,21 @@ bottomup:
72011 * can happen with large stack limits and large mmap()
72012 * allocations.
72013 */
72014 + mm->mmap_base = TASK_UNMAPPED_BASE;
72015 +
72016 +#ifdef CONFIG_PAX_RANDMMAP
72017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72018 + mm->mmap_base += mm->delta_mmap;
72019 +#endif
72020 +
72021 + mm->free_area_cache = mm->mmap_base;
72022 mm->cached_hole_size = ~0UL;
72023 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72024 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72025 /*
72026 * Restore the topdown base:
72027 */
72028 - mm->free_area_cache = mm->mmap_base;
72029 + mm->mmap_base = base;
72030 + mm->free_area_cache = base;
72031 mm->cached_hole_size = ~0UL;
72032
72033 return addr;
72034 @@ -1525,6 +1743,12 @@ bottomup:
72035
72036 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72037 {
72038 +
72039 +#ifdef CONFIG_PAX_SEGMEXEC
72040 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72041 + return;
72042 +#endif
72043 +
72044 /*
72045 * Is this a new hole at the highest possible address?
72046 */
72047 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72048 mm->free_area_cache = addr;
72049
72050 /* dont allow allocations above current base */
72051 - if (mm->free_area_cache > mm->mmap_base)
72052 + if (mm->free_area_cache > mm->mmap_base) {
72053 mm->free_area_cache = mm->mmap_base;
72054 + mm->cached_hole_size = ~0UL;
72055 + }
72056 }
72057
72058 unsigned long
72059 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72060 return vma;
72061 }
72062
72063 +#ifdef CONFIG_PAX_SEGMEXEC
72064 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72065 +{
72066 + struct vm_area_struct *vma_m;
72067 +
72068 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72069 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72070 + BUG_ON(vma->vm_mirror);
72071 + return NULL;
72072 + }
72073 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72074 + vma_m = vma->vm_mirror;
72075 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72076 + BUG_ON(vma->vm_file != vma_m->vm_file);
72077 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72078 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72079 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72080 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72081 + return vma_m;
72082 +}
72083 +#endif
72084 +
72085 /*
72086 * Verify that the stack growth is acceptable and
72087 * update accounting. This is shared with both the
72088 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72089 return -ENOMEM;
72090
72091 /* Stack limit test */
72092 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72093 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72094 return -ENOMEM;
72095
72096 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72097 locked = mm->locked_vm + grow;
72098 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72099 limit >>= PAGE_SHIFT;
72100 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72101 if (locked > limit && !capable(CAP_IPC_LOCK))
72102 return -ENOMEM;
72103 }
72104 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72105 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72106 * vma is the last one with address > vma->vm_end. Have to extend vma.
72107 */
72108 +#ifndef CONFIG_IA64
72109 +static
72110 +#endif
72111 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72112 {
72113 int error;
72114 + bool locknext;
72115
72116 if (!(vma->vm_flags & VM_GROWSUP))
72117 return -EFAULT;
72118
72119 + /* Also guard against wrapping around to address 0. */
72120 + if (address < PAGE_ALIGN(address+1))
72121 + address = PAGE_ALIGN(address+1);
72122 + else
72123 + return -ENOMEM;
72124 +
72125 /*
72126 * We must make sure the anon_vma is allocated
72127 * so that the anon_vma locking is not a noop.
72128 */
72129 if (unlikely(anon_vma_prepare(vma)))
72130 return -ENOMEM;
72131 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72132 + if (locknext && anon_vma_prepare(vma->vm_next))
72133 + return -ENOMEM;
72134 vma_lock_anon_vma(vma);
72135 + if (locknext)
72136 + vma_lock_anon_vma(vma->vm_next);
72137
72138 /*
72139 * vma->vm_start/vm_end cannot change under us because the caller
72140 * is required to hold the mmap_sem in read mode. We need the
72141 - * anon_vma lock to serialize against concurrent expand_stacks.
72142 - * Also guard against wrapping around to address 0.
72143 + * anon_vma locks to serialize against concurrent expand_stacks
72144 + * and expand_upwards.
72145 */
72146 - if (address < PAGE_ALIGN(address+4))
72147 - address = PAGE_ALIGN(address+4);
72148 - else {
72149 - vma_unlock_anon_vma(vma);
72150 - return -ENOMEM;
72151 - }
72152 error = 0;
72153
72154 /* Somebody else might have raced and expanded it already */
72155 - if (address > vma->vm_end) {
72156 + 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)
72157 + error = -ENOMEM;
72158 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72159 unsigned long size, grow;
72160
72161 size = address - vma->vm_start;
72162 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72163 }
72164 }
72165 }
72166 + if (locknext)
72167 + vma_unlock_anon_vma(vma->vm_next);
72168 vma_unlock_anon_vma(vma);
72169 khugepaged_enter_vma_merge(vma);
72170 return error;
72171 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72172 unsigned long address)
72173 {
72174 int error;
72175 + bool lockprev = false;
72176 + struct vm_area_struct *prev;
72177
72178 /*
72179 * We must make sure the anon_vma is allocated
72180 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72181 if (error)
72182 return error;
72183
72184 + prev = vma->vm_prev;
72185 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72186 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72187 +#endif
72188 + if (lockprev && anon_vma_prepare(prev))
72189 + return -ENOMEM;
72190 + if (lockprev)
72191 + vma_lock_anon_vma(prev);
72192 +
72193 vma_lock_anon_vma(vma);
72194
72195 /*
72196 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72197 */
72198
72199 /* Somebody else might have raced and expanded it already */
72200 - if (address < vma->vm_start) {
72201 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72202 + error = -ENOMEM;
72203 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72204 unsigned long size, grow;
72205
72206 +#ifdef CONFIG_PAX_SEGMEXEC
72207 + struct vm_area_struct *vma_m;
72208 +
72209 + vma_m = pax_find_mirror_vma(vma);
72210 +#endif
72211 +
72212 size = vma->vm_end - address;
72213 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72214
72215 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72216 if (!error) {
72217 vma->vm_start = address;
72218 vma->vm_pgoff -= grow;
72219 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72220 +
72221 +#ifdef CONFIG_PAX_SEGMEXEC
72222 + if (vma_m) {
72223 + vma_m->vm_start -= grow << PAGE_SHIFT;
72224 + vma_m->vm_pgoff -= grow;
72225 + }
72226 +#endif
72227 +
72228 perf_event_mmap(vma);
72229 }
72230 }
72231 }
72232 vma_unlock_anon_vma(vma);
72233 + if (lockprev)
72234 + vma_unlock_anon_vma(prev);
72235 khugepaged_enter_vma_merge(vma);
72236 return error;
72237 }
72238 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72239 do {
72240 long nrpages = vma_pages(vma);
72241
72242 +#ifdef CONFIG_PAX_SEGMEXEC
72243 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72244 + vma = remove_vma(vma);
72245 + continue;
72246 + }
72247 +#endif
72248 +
72249 mm->total_vm -= nrpages;
72250 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72251 vma = remove_vma(vma);
72252 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72253 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72254 vma->vm_prev = NULL;
72255 do {
72256 +
72257 +#ifdef CONFIG_PAX_SEGMEXEC
72258 + if (vma->vm_mirror) {
72259 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72260 + vma->vm_mirror->vm_mirror = NULL;
72261 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72262 + vma->vm_mirror = NULL;
72263 + }
72264 +#endif
72265 +
72266 rb_erase(&vma->vm_rb, &mm->mm_rb);
72267 mm->map_count--;
72268 tail_vma = vma;
72269 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72270 struct vm_area_struct *new;
72271 int err = -ENOMEM;
72272
72273 +#ifdef CONFIG_PAX_SEGMEXEC
72274 + struct vm_area_struct *vma_m, *new_m = NULL;
72275 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72276 +#endif
72277 +
72278 if (is_vm_hugetlb_page(vma) && (addr &
72279 ~(huge_page_mask(hstate_vma(vma)))))
72280 return -EINVAL;
72281
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + vma_m = pax_find_mirror_vma(vma);
72284 +#endif
72285 +
72286 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72287 if (!new)
72288 goto out_err;
72289
72290 +#ifdef CONFIG_PAX_SEGMEXEC
72291 + if (vma_m) {
72292 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72293 + if (!new_m) {
72294 + kmem_cache_free(vm_area_cachep, new);
72295 + goto out_err;
72296 + }
72297 + }
72298 +#endif
72299 +
72300 /* most fields are the same, copy all, and then fixup */
72301 *new = *vma;
72302
72303 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72304 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72305 }
72306
72307 +#ifdef CONFIG_PAX_SEGMEXEC
72308 + if (vma_m) {
72309 + *new_m = *vma_m;
72310 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72311 + new_m->vm_mirror = new;
72312 + new->vm_mirror = new_m;
72313 +
72314 + if (new_below)
72315 + new_m->vm_end = addr_m;
72316 + else {
72317 + new_m->vm_start = addr_m;
72318 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72319 + }
72320 + }
72321 +#endif
72322 +
72323 pol = mpol_dup(vma_policy(vma));
72324 if (IS_ERR(pol)) {
72325 err = PTR_ERR(pol);
72326 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72327 else
72328 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72329
72330 +#ifdef CONFIG_PAX_SEGMEXEC
72331 + if (!err && vma_m) {
72332 + if (anon_vma_clone(new_m, vma_m))
72333 + goto out_free_mpol;
72334 +
72335 + mpol_get(pol);
72336 + vma_set_policy(new_m, pol);
72337 +
72338 + if (new_m->vm_file) {
72339 + get_file(new_m->vm_file);
72340 + if (vma_m->vm_flags & VM_EXECUTABLE)
72341 + added_exe_file_vma(mm);
72342 + }
72343 +
72344 + if (new_m->vm_ops && new_m->vm_ops->open)
72345 + new_m->vm_ops->open(new_m);
72346 +
72347 + if (new_below)
72348 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72349 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72350 + else
72351 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72352 +
72353 + if (err) {
72354 + if (new_m->vm_ops && new_m->vm_ops->close)
72355 + new_m->vm_ops->close(new_m);
72356 + if (new_m->vm_file) {
72357 + if (vma_m->vm_flags & VM_EXECUTABLE)
72358 + removed_exe_file_vma(mm);
72359 + fput(new_m->vm_file);
72360 + }
72361 + mpol_put(pol);
72362 + }
72363 + }
72364 +#endif
72365 +
72366 /* Success. */
72367 if (!err)
72368 return 0;
72369 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72370 removed_exe_file_vma(mm);
72371 fput(new->vm_file);
72372 }
72373 - unlink_anon_vmas(new);
72374 out_free_mpol:
72375 mpol_put(pol);
72376 out_free_vma:
72377 +
72378 +#ifdef CONFIG_PAX_SEGMEXEC
72379 + if (new_m) {
72380 + unlink_anon_vmas(new_m);
72381 + kmem_cache_free(vm_area_cachep, new_m);
72382 + }
72383 +#endif
72384 +
72385 + unlink_anon_vmas(new);
72386 kmem_cache_free(vm_area_cachep, new);
72387 out_err:
72388 return err;
72389 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72390 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72391 unsigned long addr, int new_below)
72392 {
72393 +
72394 +#ifdef CONFIG_PAX_SEGMEXEC
72395 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72396 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72397 + if (mm->map_count >= sysctl_max_map_count-1)
72398 + return -ENOMEM;
72399 + } else
72400 +#endif
72401 +
72402 if (mm->map_count >= sysctl_max_map_count)
72403 return -ENOMEM;
72404
72405 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72406 * work. This now handles partial unmappings.
72407 * Jeremy Fitzhardinge <jeremy@goop.org>
72408 */
72409 +#ifdef CONFIG_PAX_SEGMEXEC
72410 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72411 {
72412 + int ret = __do_munmap(mm, start, len);
72413 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72414 + return ret;
72415 +
72416 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72417 +}
72418 +
72419 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72420 +#else
72421 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72422 +#endif
72423 +{
72424 unsigned long end;
72425 struct vm_area_struct *vma, *prev, *last;
72426
72427 + /*
72428 + * mm->mmap_sem is required to protect against another thread
72429 + * changing the mappings in case we sleep.
72430 + */
72431 + verify_mm_writelocked(mm);
72432 +
72433 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72434 return -EINVAL;
72435
72436 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72437 /* Fix up all other VM information */
72438 remove_vma_list(mm, vma);
72439
72440 + track_exec_limit(mm, start, end, 0UL);
72441 +
72442 return 0;
72443 }
72444
72445 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72446
72447 profile_munmap(addr);
72448
72449 +#ifdef CONFIG_PAX_SEGMEXEC
72450 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72451 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72452 + return -EINVAL;
72453 +#endif
72454 +
72455 down_write(&mm->mmap_sem);
72456 ret = do_munmap(mm, addr, len);
72457 up_write(&mm->mmap_sem);
72458 return ret;
72459 }
72460
72461 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72462 -{
72463 -#ifdef CONFIG_DEBUG_VM
72464 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72465 - WARN_ON(1);
72466 - up_read(&mm->mmap_sem);
72467 - }
72468 -#endif
72469 -}
72470 -
72471 /*
72472 * this is really a simplified "do_mmap". it only handles
72473 * anonymous maps. eventually we may be able to do some
72474 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72475 struct rb_node ** rb_link, * rb_parent;
72476 pgoff_t pgoff = addr >> PAGE_SHIFT;
72477 int error;
72478 + unsigned long charged;
72479
72480 len = PAGE_ALIGN(len);
72481 if (!len)
72482 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72483
72484 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72485
72486 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72487 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72488 + flags &= ~VM_EXEC;
72489 +
72490 +#ifdef CONFIG_PAX_MPROTECT
72491 + if (mm->pax_flags & MF_PAX_MPROTECT)
72492 + flags &= ~VM_MAYEXEC;
72493 +#endif
72494 +
72495 + }
72496 +#endif
72497 +
72498 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72499 if (error & ~PAGE_MASK)
72500 return error;
72501
72502 + charged = len >> PAGE_SHIFT;
72503 +
72504 /*
72505 * mlock MCL_FUTURE?
72506 */
72507 if (mm->def_flags & VM_LOCKED) {
72508 unsigned long locked, lock_limit;
72509 - locked = len >> PAGE_SHIFT;
72510 + locked = charged;
72511 locked += mm->locked_vm;
72512 lock_limit = rlimit(RLIMIT_MEMLOCK);
72513 lock_limit >>= PAGE_SHIFT;
72514 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72515 /*
72516 * Clear old maps. this also does some error checking for us
72517 */
72518 - munmap_back:
72519 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72520 if (vma && vma->vm_start < addr + len) {
72521 if (do_munmap(mm, addr, len))
72522 return -ENOMEM;
72523 - goto munmap_back;
72524 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72525 + BUG_ON(vma && vma->vm_start < addr + len);
72526 }
72527
72528 /* Check against address space limits *after* clearing old maps... */
72529 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72530 + if (!may_expand_vm(mm, charged))
72531 return -ENOMEM;
72532
72533 if (mm->map_count > sysctl_max_map_count)
72534 return -ENOMEM;
72535
72536 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72537 + if (security_vm_enough_memory(charged))
72538 return -ENOMEM;
72539
72540 /* Can we just expand an old private anonymous mapping? */
72541 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72542 */
72543 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72544 if (!vma) {
72545 - vm_unacct_memory(len >> PAGE_SHIFT);
72546 + vm_unacct_memory(charged);
72547 return -ENOMEM;
72548 }
72549
72550 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72551 vma_link(mm, vma, prev, rb_link, rb_parent);
72552 out:
72553 perf_event_mmap(vma);
72554 - mm->total_vm += len >> PAGE_SHIFT;
72555 + mm->total_vm += charged;
72556 if (flags & VM_LOCKED) {
72557 if (!mlock_vma_pages_range(vma, addr, addr + len))
72558 - mm->locked_vm += (len >> PAGE_SHIFT);
72559 + mm->locked_vm += charged;
72560 }
72561 + track_exec_limit(mm, addr, addr + len, flags);
72562 return addr;
72563 }
72564
72565 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72566 * Walk the list again, actually closing and freeing it,
72567 * with preemption enabled, without holding any MM locks.
72568 */
72569 - while (vma)
72570 + while (vma) {
72571 + vma->vm_mirror = NULL;
72572 vma = remove_vma(vma);
72573 + }
72574
72575 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72576 }
72577 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72578 struct vm_area_struct * __vma, * prev;
72579 struct rb_node ** rb_link, * rb_parent;
72580
72581 +#ifdef CONFIG_PAX_SEGMEXEC
72582 + struct vm_area_struct *vma_m = NULL;
72583 +#endif
72584 +
72585 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72586 + return -EPERM;
72587 +
72588 /*
72589 * The vm_pgoff of a purely anonymous vma should be irrelevant
72590 * until its first write fault, when page's anon_vma and index
72591 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72592 if ((vma->vm_flags & VM_ACCOUNT) &&
72593 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72594 return -ENOMEM;
72595 +
72596 +#ifdef CONFIG_PAX_SEGMEXEC
72597 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72598 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72599 + if (!vma_m)
72600 + return -ENOMEM;
72601 + }
72602 +#endif
72603 +
72604 vma_link(mm, vma, prev, rb_link, rb_parent);
72605 +
72606 +#ifdef CONFIG_PAX_SEGMEXEC
72607 + if (vma_m)
72608 + BUG_ON(pax_mirror_vma(vma_m, vma));
72609 +#endif
72610 +
72611 return 0;
72612 }
72613
72614 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72615 struct mempolicy *pol;
72616 bool faulted_in_anon_vma = true;
72617
72618 + BUG_ON(vma->vm_mirror);
72619 +
72620 /*
72621 * If anonymous vma has not yet been faulted, update new pgoff
72622 * to match new location, to increase its chance of merging.
72623 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72624 return NULL;
72625 }
72626
72627 +#ifdef CONFIG_PAX_SEGMEXEC
72628 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72629 +{
72630 + struct vm_area_struct *prev_m;
72631 + struct rb_node **rb_link_m, *rb_parent_m;
72632 + struct mempolicy *pol_m;
72633 +
72634 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72635 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72636 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72637 + *vma_m = *vma;
72638 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72639 + if (anon_vma_clone(vma_m, vma))
72640 + return -ENOMEM;
72641 + pol_m = vma_policy(vma_m);
72642 + mpol_get(pol_m);
72643 + vma_set_policy(vma_m, pol_m);
72644 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72645 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72646 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72647 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72648 + if (vma_m->vm_file)
72649 + get_file(vma_m->vm_file);
72650 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72651 + vma_m->vm_ops->open(vma_m);
72652 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72653 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72654 + vma_m->vm_mirror = vma;
72655 + vma->vm_mirror = vma_m;
72656 + return 0;
72657 +}
72658 +#endif
72659 +
72660 /*
72661 * Return true if the calling process may expand its vm space by the passed
72662 * number of pages
72663 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72664
72665 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72666
72667 +#ifdef CONFIG_PAX_RANDMMAP
72668 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72669 + cur -= mm->brk_gap;
72670 +#endif
72671 +
72672 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72673 if (cur + npages > lim)
72674 return 0;
72675 return 1;
72676 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72677 vma->vm_start = addr;
72678 vma->vm_end = addr + len;
72679
72680 +#ifdef CONFIG_PAX_MPROTECT
72681 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72682 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72683 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72684 + return -EPERM;
72685 + if (!(vm_flags & VM_EXEC))
72686 + vm_flags &= ~VM_MAYEXEC;
72687 +#else
72688 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72689 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72690 +#endif
72691 + else
72692 + vm_flags &= ~VM_MAYWRITE;
72693 + }
72694 +#endif
72695 +
72696 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72697 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72698
72699 diff --git a/mm/mprotect.c b/mm/mprotect.c
72700 index f437d05..e3763f6 100644
72701 --- a/mm/mprotect.c
72702 +++ b/mm/mprotect.c
72703 @@ -23,10 +23,16 @@
72704 #include <linux/mmu_notifier.h>
72705 #include <linux/migrate.h>
72706 #include <linux/perf_event.h>
72707 +
72708 +#ifdef CONFIG_PAX_MPROTECT
72709 +#include <linux/elf.h>
72710 +#endif
72711 +
72712 #include <asm/uaccess.h>
72713 #include <asm/pgtable.h>
72714 #include <asm/cacheflush.h>
72715 #include <asm/tlbflush.h>
72716 +#include <asm/mmu_context.h>
72717
72718 #ifndef pgprot_modify
72719 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72720 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72721 flush_tlb_range(vma, start, end);
72722 }
72723
72724 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72725 +/* called while holding the mmap semaphor for writing except stack expansion */
72726 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72727 +{
72728 + unsigned long oldlimit, newlimit = 0UL;
72729 +
72730 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72731 + return;
72732 +
72733 + spin_lock(&mm->page_table_lock);
72734 + oldlimit = mm->context.user_cs_limit;
72735 + if ((prot & VM_EXEC) && oldlimit < end)
72736 + /* USER_CS limit moved up */
72737 + newlimit = end;
72738 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72739 + /* USER_CS limit moved down */
72740 + newlimit = start;
72741 +
72742 + if (newlimit) {
72743 + mm->context.user_cs_limit = newlimit;
72744 +
72745 +#ifdef CONFIG_SMP
72746 + wmb();
72747 + cpus_clear(mm->context.cpu_user_cs_mask);
72748 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72749 +#endif
72750 +
72751 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72752 + }
72753 + spin_unlock(&mm->page_table_lock);
72754 + if (newlimit == end) {
72755 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72756 +
72757 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72758 + if (is_vm_hugetlb_page(vma))
72759 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72760 + else
72761 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72762 + }
72763 +}
72764 +#endif
72765 +
72766 int
72767 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72768 unsigned long start, unsigned long end, unsigned long newflags)
72769 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72770 int error;
72771 int dirty_accountable = 0;
72772
72773 +#ifdef CONFIG_PAX_SEGMEXEC
72774 + struct vm_area_struct *vma_m = NULL;
72775 + unsigned long start_m, end_m;
72776 +
72777 + start_m = start + SEGMEXEC_TASK_SIZE;
72778 + end_m = end + SEGMEXEC_TASK_SIZE;
72779 +#endif
72780 +
72781 if (newflags == oldflags) {
72782 *pprev = vma;
72783 return 0;
72784 }
72785
72786 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72787 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72788 +
72789 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72790 + return -ENOMEM;
72791 +
72792 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72793 + return -ENOMEM;
72794 + }
72795 +
72796 /*
72797 * If we make a private mapping writable we increase our commit;
72798 * but (without finer accounting) cannot reduce our commit if we
72799 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72800 }
72801 }
72802
72803 +#ifdef CONFIG_PAX_SEGMEXEC
72804 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72805 + if (start != vma->vm_start) {
72806 + error = split_vma(mm, vma, start, 1);
72807 + if (error)
72808 + goto fail;
72809 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72810 + *pprev = (*pprev)->vm_next;
72811 + }
72812 +
72813 + if (end != vma->vm_end) {
72814 + error = split_vma(mm, vma, end, 0);
72815 + if (error)
72816 + goto fail;
72817 + }
72818 +
72819 + if (pax_find_mirror_vma(vma)) {
72820 + error = __do_munmap(mm, start_m, end_m - start_m);
72821 + if (error)
72822 + goto fail;
72823 + } else {
72824 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72825 + if (!vma_m) {
72826 + error = -ENOMEM;
72827 + goto fail;
72828 + }
72829 + vma->vm_flags = newflags;
72830 + error = pax_mirror_vma(vma_m, vma);
72831 + if (error) {
72832 + vma->vm_flags = oldflags;
72833 + goto fail;
72834 + }
72835 + }
72836 + }
72837 +#endif
72838 +
72839 /*
72840 * First try to merge with previous and/or next vma.
72841 */
72842 @@ -204,9 +306,21 @@ success:
72843 * vm_flags and vm_page_prot are protected by the mmap_sem
72844 * held in write mode.
72845 */
72846 +
72847 +#ifdef CONFIG_PAX_SEGMEXEC
72848 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72849 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72850 +#endif
72851 +
72852 vma->vm_flags = newflags;
72853 +
72854 +#ifdef CONFIG_PAX_MPROTECT
72855 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72856 + mm->binfmt->handle_mprotect(vma, newflags);
72857 +#endif
72858 +
72859 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72860 - vm_get_page_prot(newflags));
72861 + vm_get_page_prot(vma->vm_flags));
72862
72863 if (vma_wants_writenotify(vma)) {
72864 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72865 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72866 end = start + len;
72867 if (end <= start)
72868 return -ENOMEM;
72869 +
72870 +#ifdef CONFIG_PAX_SEGMEXEC
72871 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72872 + if (end > SEGMEXEC_TASK_SIZE)
72873 + return -EINVAL;
72874 + } else
72875 +#endif
72876 +
72877 + if (end > TASK_SIZE)
72878 + return -EINVAL;
72879 +
72880 if (!arch_validate_prot(prot))
72881 return -EINVAL;
72882
72883 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72884 /*
72885 * Does the application expect PROT_READ to imply PROT_EXEC:
72886 */
72887 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72888 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72889 prot |= PROT_EXEC;
72890
72891 vm_flags = calc_vm_prot_bits(prot);
72892 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72893 if (start > vma->vm_start)
72894 prev = vma;
72895
72896 +#ifdef CONFIG_PAX_MPROTECT
72897 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72898 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72899 +#endif
72900 +
72901 for (nstart = start ; ; ) {
72902 unsigned long newflags;
72903
72904 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72905
72906 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72907 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72908 + if (prot & (PROT_WRITE | PROT_EXEC))
72909 + gr_log_rwxmprotect(vma->vm_file);
72910 +
72911 + error = -EACCES;
72912 + goto out;
72913 + }
72914 +
72915 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72916 error = -EACCES;
72917 goto out;
72918 }
72919 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72920 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72921 if (error)
72922 goto out;
72923 +
72924 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72925 +
72926 nstart = tmp;
72927
72928 if (nstart < prev->vm_end)
72929 diff --git a/mm/mremap.c b/mm/mremap.c
72930 index 87bb839..c3bfadb 100644
72931 --- a/mm/mremap.c
72932 +++ b/mm/mremap.c
72933 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72934 continue;
72935 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72936 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72937 +
72938 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72939 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72940 + pte = pte_exprotect(pte);
72941 +#endif
72942 +
72943 set_pte_at(mm, new_addr, new_pte, pte);
72944 }
72945
72946 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72947 if (is_vm_hugetlb_page(vma))
72948 goto Einval;
72949
72950 +#ifdef CONFIG_PAX_SEGMEXEC
72951 + if (pax_find_mirror_vma(vma))
72952 + goto Einval;
72953 +#endif
72954 +
72955 /* We can't remap across vm area boundaries */
72956 if (old_len > vma->vm_end - addr)
72957 goto Efault;
72958 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72959 unsigned long ret = -EINVAL;
72960 unsigned long charged = 0;
72961 unsigned long map_flags;
72962 + unsigned long pax_task_size = TASK_SIZE;
72963
72964 if (new_addr & ~PAGE_MASK)
72965 goto out;
72966
72967 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72968 +#ifdef CONFIG_PAX_SEGMEXEC
72969 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72970 + pax_task_size = SEGMEXEC_TASK_SIZE;
72971 +#endif
72972 +
72973 + pax_task_size -= PAGE_SIZE;
72974 +
72975 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72976 goto out;
72977
72978 /* Check if the location we're moving into overlaps the
72979 * old location at all, and fail if it does.
72980 */
72981 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72982 - goto out;
72983 -
72984 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72985 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72986 goto out;
72987
72988 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72989 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72990 struct vm_area_struct *vma;
72991 unsigned long ret = -EINVAL;
72992 unsigned long charged = 0;
72993 + unsigned long pax_task_size = TASK_SIZE;
72994
72995 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72996 goto out;
72997 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72998 if (!new_len)
72999 goto out;
73000
73001 +#ifdef CONFIG_PAX_SEGMEXEC
73002 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73003 + pax_task_size = SEGMEXEC_TASK_SIZE;
73004 +#endif
73005 +
73006 + pax_task_size -= PAGE_SIZE;
73007 +
73008 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73009 + old_len > pax_task_size || addr > pax_task_size-old_len)
73010 + goto out;
73011 +
73012 if (flags & MREMAP_FIXED) {
73013 if (flags & MREMAP_MAYMOVE)
73014 ret = mremap_to(addr, old_len, new_addr, new_len);
73015 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
73016 addr + new_len);
73017 }
73018 ret = addr;
73019 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73020 goto out;
73021 }
73022 }
73023 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
73024 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73025 if (ret)
73026 goto out;
73027 +
73028 + map_flags = vma->vm_flags;
73029 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73030 + if (!(ret & ~PAGE_MASK)) {
73031 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73032 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73033 + }
73034 }
73035 out:
73036 if (ret & ~PAGE_MASK)
73037 diff --git a/mm/nommu.c b/mm/nommu.c
73038 index f59e170..34e2a2b 100644
73039 --- a/mm/nommu.c
73040 +++ b/mm/nommu.c
73041 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73042 int sysctl_overcommit_ratio = 50; /* default is 50% */
73043 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73044 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73045 -int heap_stack_gap = 0;
73046
73047 atomic_long_t mmap_pages_allocated;
73048
73049 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73050 EXPORT_SYMBOL(find_vma);
73051
73052 /*
73053 - * find a VMA
73054 - * - we don't extend stack VMAs under NOMMU conditions
73055 - */
73056 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73057 -{
73058 - return find_vma(mm, addr);
73059 -}
73060 -
73061 -/*
73062 * expand a stack to a given address
73063 * - not supported under NOMMU conditions
73064 */
73065 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73066
73067 /* most fields are the same, copy all, and then fixup */
73068 *new = *vma;
73069 + INIT_LIST_HEAD(&new->anon_vma_chain);
73070 *region = *vma->vm_region;
73071 new->vm_region = region;
73072
73073 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73074 index a13ded1..b949d15 100644
73075 --- a/mm/page_alloc.c
73076 +++ b/mm/page_alloc.c
73077 @@ -335,7 +335,7 @@ out:
73078 * This usage means that zero-order pages may not be compound.
73079 */
73080
73081 -static void free_compound_page(struct page *page)
73082 +void free_compound_page(struct page *page)
73083 {
73084 __free_pages_ok(page, compound_order(page));
73085 }
73086 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73087 int i;
73088 int bad = 0;
73089
73090 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73091 + unsigned long index = 1UL << order;
73092 +#endif
73093 +
73094 trace_mm_page_free(page, order);
73095 kmemcheck_free_shadow(page, order);
73096
73097 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73098 debug_check_no_obj_freed(page_address(page),
73099 PAGE_SIZE << order);
73100 }
73101 +
73102 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73103 + for (; index; --index)
73104 + sanitize_highpage(page + index - 1);
73105 +#endif
73106 +
73107 arch_free_page(page, order);
73108 kernel_map_pages(page, 1 << order, 0);
73109
73110 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73111 arch_alloc_page(page, order);
73112 kernel_map_pages(page, 1 << order, 1);
73113
73114 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73115 if (gfp_flags & __GFP_ZERO)
73116 prep_zero_page(page, order, gfp_flags);
73117 +#endif
73118
73119 if (order && (gfp_flags & __GFP_COMP))
73120 prep_compound_page(page, order);
73121 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73122 unsigned long pfn;
73123
73124 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73125 +#ifdef CONFIG_X86_32
73126 + /* boot failures in VMware 8 on 32bit vanilla since
73127 + this change */
73128 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73129 +#else
73130 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73131 +#endif
73132 return 1;
73133 }
73134 return 0;
73135 diff --git a/mm/percpu.c b/mm/percpu.c
73136 index f47af91..7eeef99 100644
73137 --- a/mm/percpu.c
73138 +++ b/mm/percpu.c
73139 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73140 static unsigned int pcpu_high_unit_cpu __read_mostly;
73141
73142 /* the address of the first chunk which starts with the kernel static area */
73143 -void *pcpu_base_addr __read_mostly;
73144 +void *pcpu_base_addr __read_only;
73145 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73146
73147 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73148 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73149 index c20ff48..137702a 100644
73150 --- a/mm/process_vm_access.c
73151 +++ b/mm/process_vm_access.c
73152 @@ -13,6 +13,7 @@
73153 #include <linux/uio.h>
73154 #include <linux/sched.h>
73155 #include <linux/highmem.h>
73156 +#include <linux/security.h>
73157 #include <linux/ptrace.h>
73158 #include <linux/slab.h>
73159 #include <linux/syscalls.h>
73160 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73161 size_t iov_l_curr_offset = 0;
73162 ssize_t iov_len;
73163
73164 + return -ENOSYS; // PaX: until properly audited
73165 +
73166 /*
73167 * Work out how many pages of struct pages we're going to need
73168 * when eventually calling get_user_pages
73169 */
73170 for (i = 0; i < riovcnt; i++) {
73171 iov_len = rvec[i].iov_len;
73172 - if (iov_len > 0) {
73173 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73174 - + iov_len)
73175 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73176 - / PAGE_SIZE + 1;
73177 - nr_pages = max(nr_pages, nr_pages_iov);
73178 - }
73179 + if (iov_len <= 0)
73180 + continue;
73181 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73182 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73183 + nr_pages = max(nr_pages, nr_pages_iov);
73184 }
73185
73186 if (nr_pages == 0)
73187 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73188 goto free_proc_pages;
73189 }
73190
73191 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73192 + rc = -EPERM;
73193 + goto put_task_struct;
73194 + }
73195 +
73196 mm = mm_access(task, PTRACE_MODE_ATTACH);
73197 if (!mm || IS_ERR(mm)) {
73198 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73199 diff --git a/mm/rmap.c b/mm/rmap.c
73200 index c8454e0..b04f3a2 100644
73201 --- a/mm/rmap.c
73202 +++ b/mm/rmap.c
73203 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73204 struct anon_vma *anon_vma = vma->anon_vma;
73205 struct anon_vma_chain *avc;
73206
73207 +#ifdef CONFIG_PAX_SEGMEXEC
73208 + struct anon_vma_chain *avc_m = NULL;
73209 +#endif
73210 +
73211 might_sleep();
73212 if (unlikely(!anon_vma)) {
73213 struct mm_struct *mm = vma->vm_mm;
73214 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73215 if (!avc)
73216 goto out_enomem;
73217
73218 +#ifdef CONFIG_PAX_SEGMEXEC
73219 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73220 + if (!avc_m)
73221 + goto out_enomem_free_avc;
73222 +#endif
73223 +
73224 anon_vma = find_mergeable_anon_vma(vma);
73225 allocated = NULL;
73226 if (!anon_vma) {
73227 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73228 /* page_table_lock to protect against threads */
73229 spin_lock(&mm->page_table_lock);
73230 if (likely(!vma->anon_vma)) {
73231 +
73232 +#ifdef CONFIG_PAX_SEGMEXEC
73233 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73234 +
73235 + if (vma_m) {
73236 + BUG_ON(vma_m->anon_vma);
73237 + vma_m->anon_vma = anon_vma;
73238 + avc_m->anon_vma = anon_vma;
73239 + avc_m->vma = vma;
73240 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73241 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73242 + avc_m = NULL;
73243 + }
73244 +#endif
73245 +
73246 vma->anon_vma = anon_vma;
73247 avc->anon_vma = anon_vma;
73248 avc->vma = vma;
73249 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73250
73251 if (unlikely(allocated))
73252 put_anon_vma(allocated);
73253 +
73254 +#ifdef CONFIG_PAX_SEGMEXEC
73255 + if (unlikely(avc_m))
73256 + anon_vma_chain_free(avc_m);
73257 +#endif
73258 +
73259 if (unlikely(avc))
73260 anon_vma_chain_free(avc);
73261 }
73262 return 0;
73263
73264 out_enomem_free_avc:
73265 +
73266 +#ifdef CONFIG_PAX_SEGMEXEC
73267 + if (avc_m)
73268 + anon_vma_chain_free(avc_m);
73269 +#endif
73270 +
73271 anon_vma_chain_free(avc);
73272 out_enomem:
73273 return -ENOMEM;
73274 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73275 * Attach the anon_vmas from src to dst.
73276 * Returns 0 on success, -ENOMEM on failure.
73277 */
73278 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73279 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73280 {
73281 struct anon_vma_chain *avc, *pavc;
73282 struct anon_vma *root = NULL;
73283 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73284 * the corresponding VMA in the parent process is attached to.
73285 * Returns 0 on success, non-zero on failure.
73286 */
73287 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73288 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73289 {
73290 struct anon_vma_chain *avc;
73291 struct anon_vma *anon_vma;
73292 diff --git a/mm/shmem.c b/mm/shmem.c
73293 index 269d049..a9d2b50 100644
73294 --- a/mm/shmem.c
73295 +++ b/mm/shmem.c
73296 @@ -31,7 +31,7 @@
73297 #include <linux/export.h>
73298 #include <linux/swap.h>
73299
73300 -static struct vfsmount *shm_mnt;
73301 +struct vfsmount *shm_mnt;
73302
73303 #ifdef CONFIG_SHMEM
73304 /*
73305 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73306 #define BOGO_DIRENT_SIZE 20
73307
73308 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73309 -#define SHORT_SYMLINK_LEN 128
73310 +#define SHORT_SYMLINK_LEN 64
73311
73312 struct shmem_xattr {
73313 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73314 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73315 int err = -ENOMEM;
73316
73317 /* Round up to L1_CACHE_BYTES to resist false sharing */
73318 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73319 - L1_CACHE_BYTES), GFP_KERNEL);
73320 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73321 if (!sbinfo)
73322 return -ENOMEM;
73323
73324 diff --git a/mm/slab.c b/mm/slab.c
73325 index f0bd785..348b96a 100644
73326 --- a/mm/slab.c
73327 +++ b/mm/slab.c
73328 @@ -153,7 +153,7 @@
73329
73330 /* Legal flag mask for kmem_cache_create(). */
73331 #if DEBUG
73332 -# define CREATE_MASK (SLAB_RED_ZONE | \
73333 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73334 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73335 SLAB_CACHE_DMA | \
73336 SLAB_STORE_USER | \
73337 @@ -161,7 +161,7 @@
73338 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73339 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73340 #else
73341 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73342 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73343 SLAB_CACHE_DMA | \
73344 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73345 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73346 @@ -290,7 +290,7 @@ struct kmem_list3 {
73347 * Need this for bootstrapping a per node allocator.
73348 */
73349 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73350 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73351 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73352 #define CACHE_CACHE 0
73353 #define SIZE_AC MAX_NUMNODES
73354 #define SIZE_L3 (2 * MAX_NUMNODES)
73355 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73356 if ((x)->max_freeable < i) \
73357 (x)->max_freeable = i; \
73358 } while (0)
73359 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73360 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73361 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73362 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73363 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73364 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73365 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73366 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73367 #else
73368 #define STATS_INC_ACTIVE(x) do { } while (0)
73369 #define STATS_DEC_ACTIVE(x) do { } while (0)
73370 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73371 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73372 */
73373 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73374 - const struct slab *slab, void *obj)
73375 + const struct slab *slab, const void *obj)
73376 {
73377 u32 offset = (obj - slab->s_mem);
73378 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73379 @@ -568,7 +568,7 @@ struct cache_names {
73380 static struct cache_names __initdata cache_names[] = {
73381 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73382 #include <linux/kmalloc_sizes.h>
73383 - {NULL,}
73384 + {NULL}
73385 #undef CACHE
73386 };
73387
73388 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73389 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73390 sizes[INDEX_AC].cs_size,
73391 ARCH_KMALLOC_MINALIGN,
73392 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73393 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73394 NULL);
73395
73396 if (INDEX_AC != INDEX_L3) {
73397 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73398 kmem_cache_create(names[INDEX_L3].name,
73399 sizes[INDEX_L3].cs_size,
73400 ARCH_KMALLOC_MINALIGN,
73401 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73402 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73403 NULL);
73404 }
73405
73406 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73407 sizes->cs_cachep = kmem_cache_create(names->name,
73408 sizes->cs_size,
73409 ARCH_KMALLOC_MINALIGN,
73410 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73411 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73412 NULL);
73413 }
73414 #ifdef CONFIG_ZONE_DMA
73415 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73416 }
73417 /* cpu stats */
73418 {
73419 - unsigned long allochit = atomic_read(&cachep->allochit);
73420 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73421 - unsigned long freehit = atomic_read(&cachep->freehit);
73422 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73423 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73424 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73425 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73426 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73427
73428 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73429 allochit, allocmiss, freehit, freemiss);
73430 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73431 {
73432 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73433 #ifdef CONFIG_DEBUG_SLAB_LEAK
73434 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73435 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73436 #endif
73437 return 0;
73438 }
73439 module_init(slab_proc_init);
73440 #endif
73441
73442 +void check_object_size(const void *ptr, unsigned long n, bool to)
73443 +{
73444 +
73445 +#ifdef CONFIG_PAX_USERCOPY
73446 + struct page *page;
73447 + struct kmem_cache *cachep = NULL;
73448 + struct slab *slabp;
73449 + unsigned int objnr;
73450 + unsigned long offset;
73451 + const char *type;
73452 +
73453 + if (!n)
73454 + return;
73455 +
73456 + type = "<null>";
73457 + if (ZERO_OR_NULL_PTR(ptr))
73458 + goto report;
73459 +
73460 + if (!virt_addr_valid(ptr))
73461 + return;
73462 +
73463 + page = virt_to_head_page(ptr);
73464 +
73465 + type = "<process stack>";
73466 + if (!PageSlab(page)) {
73467 + if (object_is_on_stack(ptr, n) == -1)
73468 + goto report;
73469 + return;
73470 + }
73471 +
73472 + cachep = page_get_cache(page);
73473 + type = cachep->name;
73474 + if (!(cachep->flags & SLAB_USERCOPY))
73475 + goto report;
73476 +
73477 + slabp = page_get_slab(page);
73478 + objnr = obj_to_index(cachep, slabp, ptr);
73479 + BUG_ON(objnr >= cachep->num);
73480 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73481 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73482 + return;
73483 +
73484 +report:
73485 + pax_report_usercopy(ptr, n, to, type);
73486 +#endif
73487 +
73488 +}
73489 +EXPORT_SYMBOL(check_object_size);
73490 +
73491 /**
73492 * ksize - get the actual amount of memory allocated for a given object
73493 * @objp: Pointer to the object
73494 diff --git a/mm/slob.c b/mm/slob.c
73495 index 8105be4..e045f96 100644
73496 --- a/mm/slob.c
73497 +++ b/mm/slob.c
73498 @@ -29,7 +29,7 @@
73499 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73500 * alloc_pages() directly, allocating compound pages so the page order
73501 * does not have to be separately tracked, and also stores the exact
73502 - * allocation size in page->private so that it can be used to accurately
73503 + * allocation size in slob_page->size so that it can be used to accurately
73504 * provide ksize(). These objects are detected in kfree() because slob_page()
73505 * is false for them.
73506 *
73507 @@ -58,6 +58,7 @@
73508 */
73509
73510 #include <linux/kernel.h>
73511 +#include <linux/sched.h>
73512 #include <linux/slab.h>
73513 #include <linux/mm.h>
73514 #include <linux/swap.h> /* struct reclaim_state */
73515 @@ -102,7 +103,8 @@ struct slob_page {
73516 unsigned long flags; /* mandatory */
73517 atomic_t _count; /* mandatory */
73518 slobidx_t units; /* free units left in page */
73519 - unsigned long pad[2];
73520 + unsigned long pad[1];
73521 + unsigned long size; /* size when >=PAGE_SIZE */
73522 slob_t *free; /* first free slob_t in page */
73523 struct list_head list; /* linked list of free pages */
73524 };
73525 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73526 */
73527 static inline int is_slob_page(struct slob_page *sp)
73528 {
73529 - return PageSlab((struct page *)sp);
73530 + return PageSlab((struct page *)sp) && !sp->size;
73531 }
73532
73533 static inline void set_slob_page(struct slob_page *sp)
73534 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73535
73536 static inline struct slob_page *slob_page(const void *addr)
73537 {
73538 - return (struct slob_page *)virt_to_page(addr);
73539 + return (struct slob_page *)virt_to_head_page(addr);
73540 }
73541
73542 /*
73543 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73544 /*
73545 * Return the size of a slob block.
73546 */
73547 -static slobidx_t slob_units(slob_t *s)
73548 +static slobidx_t slob_units(const slob_t *s)
73549 {
73550 if (s->units > 0)
73551 return s->units;
73552 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73553 /*
73554 * Return the next free slob block pointer after this one.
73555 */
73556 -static slob_t *slob_next(slob_t *s)
73557 +static slob_t *slob_next(const slob_t *s)
73558 {
73559 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73560 slobidx_t next;
73561 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73562 /*
73563 * Returns true if s is the last free block in its page.
73564 */
73565 -static int slob_last(slob_t *s)
73566 +static int slob_last(const slob_t *s)
73567 {
73568 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73569 }
73570 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73571 if (!page)
73572 return NULL;
73573
73574 + set_slob_page(page);
73575 return page_address(page);
73576 }
73577
73578 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73579 if (!b)
73580 return NULL;
73581 sp = slob_page(b);
73582 - set_slob_page(sp);
73583
73584 spin_lock_irqsave(&slob_lock, flags);
73585 sp->units = SLOB_UNITS(PAGE_SIZE);
73586 sp->free = b;
73587 + sp->size = 0;
73588 INIT_LIST_HEAD(&sp->list);
73589 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73590 set_slob_page_free(sp, slob_list);
73591 @@ -476,10 +479,9 @@ out:
73592 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73593 */
73594
73595 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73596 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73597 {
73598 - unsigned int *m;
73599 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73600 + slob_t *m;
73601 void *ret;
73602
73603 gfp &= gfp_allowed_mask;
73604 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73605
73606 if (!m)
73607 return NULL;
73608 - *m = size;
73609 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73610 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73611 + m[0].units = size;
73612 + m[1].units = align;
73613 ret = (void *)m + align;
73614
73615 trace_kmalloc_node(_RET_IP_, ret,
73616 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73617 gfp |= __GFP_COMP;
73618 ret = slob_new_pages(gfp, order, node);
73619 if (ret) {
73620 - struct page *page;
73621 - page = virt_to_page(ret);
73622 - page->private = size;
73623 + struct slob_page *sp;
73624 + sp = slob_page(ret);
73625 + sp->size = size;
73626 }
73627
73628 trace_kmalloc_node(_RET_IP_, ret,
73629 size, PAGE_SIZE << order, gfp, node);
73630 }
73631
73632 - kmemleak_alloc(ret, size, 1, gfp);
73633 + return ret;
73634 +}
73635 +
73636 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73637 +{
73638 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73639 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73640 +
73641 + if (!ZERO_OR_NULL_PTR(ret))
73642 + kmemleak_alloc(ret, size, 1, gfp);
73643 return ret;
73644 }
73645 EXPORT_SYMBOL(__kmalloc_node);
73646 @@ -533,13 +547,92 @@ void kfree(const void *block)
73647 sp = slob_page(block);
73648 if (is_slob_page(sp)) {
73649 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73650 - unsigned int *m = (unsigned int *)(block - align);
73651 - slob_free(m, *m + align);
73652 - } else
73653 + slob_t *m = (slob_t *)(block - align);
73654 + slob_free(m, m[0].units + align);
73655 + } else {
73656 + clear_slob_page(sp);
73657 + free_slob_page(sp);
73658 + sp->size = 0;
73659 put_page(&sp->page);
73660 + }
73661 }
73662 EXPORT_SYMBOL(kfree);
73663
73664 +void check_object_size(const void *ptr, unsigned long n, bool to)
73665 +{
73666 +
73667 +#ifdef CONFIG_PAX_USERCOPY
73668 + struct slob_page *sp;
73669 + const slob_t *free;
73670 + const void *base;
73671 + unsigned long flags;
73672 + const char *type;
73673 +
73674 + if (!n)
73675 + return;
73676 +
73677 + type = "<null>";
73678 + if (ZERO_OR_NULL_PTR(ptr))
73679 + goto report;
73680 +
73681 + if (!virt_addr_valid(ptr))
73682 + return;
73683 +
73684 + type = "<process stack>";
73685 + sp = slob_page(ptr);
73686 + if (!PageSlab((struct page *)sp)) {
73687 + if (object_is_on_stack(ptr, n) == -1)
73688 + goto report;
73689 + return;
73690 + }
73691 +
73692 + type = "<slob>";
73693 + if (sp->size) {
73694 + base = page_address(&sp->page);
73695 + if (base <= ptr && n <= sp->size - (ptr - base))
73696 + return;
73697 + goto report;
73698 + }
73699 +
73700 + /* some tricky double walking to find the chunk */
73701 + spin_lock_irqsave(&slob_lock, flags);
73702 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73703 + free = sp->free;
73704 +
73705 + while (!slob_last(free) && (void *)free <= ptr) {
73706 + base = free + slob_units(free);
73707 + free = slob_next(free);
73708 + }
73709 +
73710 + while (base < (void *)free) {
73711 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73712 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73713 + int offset;
73714 +
73715 + if (ptr < base + align)
73716 + break;
73717 +
73718 + offset = ptr - base - align;
73719 + if (offset >= m) {
73720 + base += size;
73721 + continue;
73722 + }
73723 +
73724 + if (n > m - offset)
73725 + break;
73726 +
73727 + spin_unlock_irqrestore(&slob_lock, flags);
73728 + return;
73729 + }
73730 +
73731 + spin_unlock_irqrestore(&slob_lock, flags);
73732 +report:
73733 + pax_report_usercopy(ptr, n, to, type);
73734 +#endif
73735 +
73736 +}
73737 +EXPORT_SYMBOL(check_object_size);
73738 +
73739 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73740 size_t ksize(const void *block)
73741 {
73742 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73743 sp = slob_page(block);
73744 if (is_slob_page(sp)) {
73745 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73746 - unsigned int *m = (unsigned int *)(block - align);
73747 - return SLOB_UNITS(*m) * SLOB_UNIT;
73748 + slob_t *m = (slob_t *)(block - align);
73749 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73750 } else
73751 - return sp->page.private;
73752 + return sp->size;
73753 }
73754 EXPORT_SYMBOL(ksize);
73755
73756 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73757 {
73758 struct kmem_cache *c;
73759
73760 +#ifdef CONFIG_PAX_USERCOPY
73761 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73762 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73763 +#else
73764 c = slob_alloc(sizeof(struct kmem_cache),
73765 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73766 +#endif
73767
73768 if (c) {
73769 c->name = name;
73770 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73771
73772 lockdep_trace_alloc(flags);
73773
73774 +#ifdef CONFIG_PAX_USERCOPY
73775 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73776 +#else
73777 if (c->size < PAGE_SIZE) {
73778 b = slob_alloc(c->size, flags, c->align, node);
73779 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73780 SLOB_UNITS(c->size) * SLOB_UNIT,
73781 flags, node);
73782 } else {
73783 + struct slob_page *sp;
73784 +
73785 b = slob_new_pages(flags, get_order(c->size), node);
73786 + sp = slob_page(b);
73787 + sp->size = c->size;
73788 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73789 PAGE_SIZE << get_order(c->size),
73790 flags, node);
73791 }
73792 +#endif
73793
73794 if (c->ctor)
73795 c->ctor(b);
73796 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73797
73798 static void __kmem_cache_free(void *b, int size)
73799 {
73800 - if (size < PAGE_SIZE)
73801 + struct slob_page *sp = slob_page(b);
73802 +
73803 + if (is_slob_page(sp))
73804 slob_free(b, size);
73805 - else
73806 + else {
73807 + clear_slob_page(sp);
73808 + free_slob_page(sp);
73809 + sp->size = 0;
73810 slob_free_pages(b, get_order(size));
73811 + }
73812 }
73813
73814 static void kmem_rcu_free(struct rcu_head *head)
73815 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73816
73817 void kmem_cache_free(struct kmem_cache *c, void *b)
73818 {
73819 + int size = c->size;
73820 +
73821 +#ifdef CONFIG_PAX_USERCOPY
73822 + if (size + c->align < PAGE_SIZE) {
73823 + size += c->align;
73824 + b -= c->align;
73825 + }
73826 +#endif
73827 +
73828 kmemleak_free_recursive(b, c->flags);
73829 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73830 struct slob_rcu *slob_rcu;
73831 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73832 - slob_rcu->size = c->size;
73833 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73834 + slob_rcu->size = size;
73835 call_rcu(&slob_rcu->head, kmem_rcu_free);
73836 } else {
73837 - __kmem_cache_free(b, c->size);
73838 + __kmem_cache_free(b, size);
73839 }
73840
73841 +#ifdef CONFIG_PAX_USERCOPY
73842 + trace_kfree(_RET_IP_, b);
73843 +#else
73844 trace_kmem_cache_free(_RET_IP_, b);
73845 +#endif
73846 +
73847 }
73848 EXPORT_SYMBOL(kmem_cache_free);
73849
73850 diff --git a/mm/slub.c b/mm/slub.c
73851 index 0342a5d..8180ae9 100644
73852 --- a/mm/slub.c
73853 +++ b/mm/slub.c
73854 @@ -208,7 +208,7 @@ struct track {
73855
73856 enum track_item { TRACK_ALLOC, TRACK_FREE };
73857
73858 -#ifdef CONFIG_SYSFS
73859 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73860 static int sysfs_slab_add(struct kmem_cache *);
73861 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73862 static void sysfs_slab_remove(struct kmem_cache *);
73863 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73864 if (!t->addr)
73865 return;
73866
73867 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73868 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73869 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73870 #ifdef CONFIG_STACKTRACE
73871 {
73872 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73873
73874 page = virt_to_head_page(x);
73875
73876 + BUG_ON(!PageSlab(page));
73877 +
73878 slab_free(s, page, x, _RET_IP_);
73879
73880 trace_kmem_cache_free(_RET_IP_, x);
73881 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
73882 * Merge control. If this is set then no merging of slab caches will occur.
73883 * (Could be removed. This was introduced to pacify the merge skeptics.)
73884 */
73885 -static int slub_nomerge;
73886 +static int slub_nomerge = 1;
73887
73888 /*
73889 * Calculate the order of allocation given an slab object size.
73890 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73891 else
73892 s->cpu_partial = 30;
73893
73894 - s->refcount = 1;
73895 + atomic_set(&s->refcount, 1);
73896 #ifdef CONFIG_NUMA
73897 s->remote_node_defrag_ratio = 1000;
73898 #endif
73899 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73900 void kmem_cache_destroy(struct kmem_cache *s)
73901 {
73902 down_write(&slub_lock);
73903 - s->refcount--;
73904 - if (!s->refcount) {
73905 + if (atomic_dec_and_test(&s->refcount)) {
73906 list_del(&s->list);
73907 up_write(&slub_lock);
73908 if (kmem_cache_close(s)) {
73909 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73910 EXPORT_SYMBOL(__kmalloc_node);
73911 #endif
73912
73913 +void check_object_size(const void *ptr, unsigned long n, bool to)
73914 +{
73915 +
73916 +#ifdef CONFIG_PAX_USERCOPY
73917 + struct page *page;
73918 + struct kmem_cache *s = NULL;
73919 + unsigned long offset;
73920 + const char *type;
73921 +
73922 + if (!n)
73923 + return;
73924 +
73925 + type = "<null>";
73926 + if (ZERO_OR_NULL_PTR(ptr))
73927 + goto report;
73928 +
73929 + if (!virt_addr_valid(ptr))
73930 + return;
73931 +
73932 + page = virt_to_head_page(ptr);
73933 +
73934 + type = "<process stack>";
73935 + if (!PageSlab(page)) {
73936 + if (object_is_on_stack(ptr, n) == -1)
73937 + goto report;
73938 + return;
73939 + }
73940 +
73941 + s = page->slab;
73942 + type = s->name;
73943 + if (!(s->flags & SLAB_USERCOPY))
73944 + goto report;
73945 +
73946 + offset = (ptr - page_address(page)) % s->size;
73947 + if (offset <= s->objsize && n <= s->objsize - offset)
73948 + return;
73949 +
73950 +report:
73951 + pax_report_usercopy(ptr, n, to, type);
73952 +#endif
73953 +
73954 +}
73955 +EXPORT_SYMBOL(check_object_size);
73956 +
73957 size_t ksize(const void *object)
73958 {
73959 struct page *page;
73960 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73961 int node;
73962
73963 list_add(&s->list, &slab_caches);
73964 - s->refcount = -1;
73965 + atomic_set(&s->refcount, -1);
73966
73967 for_each_node_state(node, N_NORMAL_MEMORY) {
73968 struct kmem_cache_node *n = get_node(s, node);
73969 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73970
73971 /* Caches that are not of the two-to-the-power-of size */
73972 if (KMALLOC_MIN_SIZE <= 32) {
73973 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73974 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73975 caches++;
73976 }
73977
73978 if (KMALLOC_MIN_SIZE <= 64) {
73979 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73980 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73981 caches++;
73982 }
73983
73984 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73985 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73986 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73987 caches++;
73988 }
73989
73990 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73991 /*
73992 * We may have set a slab to be unmergeable during bootstrap.
73993 */
73994 - if (s->refcount < 0)
73995 + if (atomic_read(&s->refcount) < 0)
73996 return 1;
73997
73998 return 0;
73999 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74000 down_write(&slub_lock);
74001 s = find_mergeable(size, align, flags, name, ctor);
74002 if (s) {
74003 - s->refcount++;
74004 + atomic_inc(&s->refcount);
74005 /*
74006 * Adjust the object sizes so that we clear
74007 * the complete object on kzalloc.
74008 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74009 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74010
74011 if (sysfs_slab_alias(s, name)) {
74012 - s->refcount--;
74013 + atomic_dec(&s->refcount);
74014 goto err;
74015 }
74016 up_write(&slub_lock);
74017 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74018 }
74019 #endif
74020
74021 -#ifdef CONFIG_SYSFS
74022 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74023 static int count_inuse(struct page *page)
74024 {
74025 return page->inuse;
74026 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
74027 validate_slab_cache(kmalloc_caches[9]);
74028 }
74029 #else
74030 -#ifdef CONFIG_SYSFS
74031 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74032 static void resiliency_test(void) {};
74033 #endif
74034 #endif
74035
74036 -#ifdef CONFIG_SYSFS
74037 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74038 enum slab_stat_type {
74039 SL_ALL, /* All slabs */
74040 SL_PARTIAL, /* Only partially allocated slabs */
74041 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
74042
74043 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74044 {
74045 - return sprintf(buf, "%d\n", s->refcount - 1);
74046 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74047 }
74048 SLAB_ATTR_RO(aliases);
74049
74050 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
74051 return name;
74052 }
74053
74054 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74055 static int sysfs_slab_add(struct kmem_cache *s)
74056 {
74057 int err;
74058 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74059 kobject_del(&s->kobj);
74060 kobject_put(&s->kobj);
74061 }
74062 +#endif
74063
74064 /*
74065 * Need to buffer aliases during bootup until sysfs becomes
74066 @@ -5319,6 +5366,7 @@ struct saved_alias {
74067
74068 static struct saved_alias *alias_list;
74069
74070 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74071 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74072 {
74073 struct saved_alias *al;
74074 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74075 alias_list = al;
74076 return 0;
74077 }
74078 +#endif
74079
74080 static int __init slab_sysfs_init(void)
74081 {
74082 diff --git a/mm/swap.c b/mm/swap.c
74083 index 14380e9..e244704 100644
74084 --- a/mm/swap.c
74085 +++ b/mm/swap.c
74086 @@ -30,6 +30,7 @@
74087 #include <linux/backing-dev.h>
74088 #include <linux/memcontrol.h>
74089 #include <linux/gfp.h>
74090 +#include <linux/hugetlb.h>
74091
74092 #include "internal.h"
74093
74094 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74095
74096 __page_cache_release(page);
74097 dtor = get_compound_page_dtor(page);
74098 + if (!PageHuge(page))
74099 + BUG_ON(dtor != free_compound_page);
74100 (*dtor)(page);
74101 }
74102
74103 diff --git a/mm/swapfile.c b/mm/swapfile.c
74104 index f31b29d..8bdcae2 100644
74105 --- a/mm/swapfile.c
74106 +++ b/mm/swapfile.c
74107 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74108
74109 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74110 /* Activity counter to indicate that a swapon or swapoff has occurred */
74111 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74112 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74113
74114 static inline unsigned char swap_count(unsigned char ent)
74115 {
74116 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74117 }
74118 filp_close(swap_file, NULL);
74119 err = 0;
74120 - atomic_inc(&proc_poll_event);
74121 + atomic_inc_unchecked(&proc_poll_event);
74122 wake_up_interruptible(&proc_poll_wait);
74123
74124 out_dput:
74125 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74126
74127 poll_wait(file, &proc_poll_wait, wait);
74128
74129 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74130 - seq->poll_event = atomic_read(&proc_poll_event);
74131 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74132 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74133 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74134 }
74135
74136 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74137 return ret;
74138
74139 seq = file->private_data;
74140 - seq->poll_event = atomic_read(&proc_poll_event);
74141 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74142 return 0;
74143 }
74144
74145 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74146 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74147
74148 mutex_unlock(&swapon_mutex);
74149 - atomic_inc(&proc_poll_event);
74150 + atomic_inc_unchecked(&proc_poll_event);
74151 wake_up_interruptible(&proc_poll_wait);
74152
74153 if (S_ISREG(inode->i_mode))
74154 diff --git a/mm/util.c b/mm/util.c
74155 index 136ac4f..f917fa9 100644
74156 --- a/mm/util.c
74157 +++ b/mm/util.c
74158 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74159 void arch_pick_mmap_layout(struct mm_struct *mm)
74160 {
74161 mm->mmap_base = TASK_UNMAPPED_BASE;
74162 +
74163 +#ifdef CONFIG_PAX_RANDMMAP
74164 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74165 + mm->mmap_base += mm->delta_mmap;
74166 +#endif
74167 +
74168 mm->get_unmapped_area = arch_get_unmapped_area;
74169 mm->unmap_area = arch_unmap_area;
74170 }
74171 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74172 index 86ce9a5..bc498f3 100644
74173 --- a/mm/vmalloc.c
74174 +++ b/mm/vmalloc.c
74175 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74176
74177 pte = pte_offset_kernel(pmd, addr);
74178 do {
74179 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74180 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74181 +
74182 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74183 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74184 + BUG_ON(!pte_exec(*pte));
74185 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74186 + continue;
74187 + }
74188 +#endif
74189 +
74190 + {
74191 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74192 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74193 + }
74194 } while (pte++, addr += PAGE_SIZE, addr != end);
74195 }
74196
74197 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74198 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74199 {
74200 pte_t *pte;
74201 + int ret = -ENOMEM;
74202
74203 /*
74204 * nr is a running index into the array which helps higher level
74205 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74206 pte = pte_alloc_kernel(pmd, addr);
74207 if (!pte)
74208 return -ENOMEM;
74209 +
74210 + pax_open_kernel();
74211 do {
74212 struct page *page = pages[*nr];
74213
74214 - if (WARN_ON(!pte_none(*pte)))
74215 - return -EBUSY;
74216 - if (WARN_ON(!page))
74217 - return -ENOMEM;
74218 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74219 + if (pgprot_val(prot) & _PAGE_NX)
74220 +#endif
74221 +
74222 + if (WARN_ON(!pte_none(*pte))) {
74223 + ret = -EBUSY;
74224 + goto out;
74225 + }
74226 + if (WARN_ON(!page)) {
74227 + ret = -ENOMEM;
74228 + goto out;
74229 + }
74230 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74231 (*nr)++;
74232 } while (pte++, addr += PAGE_SIZE, addr != end);
74233 - return 0;
74234 + ret = 0;
74235 +out:
74236 + pax_close_kernel();
74237 + return ret;
74238 }
74239
74240 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74241 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74242 * and fall back on vmalloc() if that fails. Others
74243 * just put it in the vmalloc space.
74244 */
74245 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74246 +#ifdef CONFIG_MODULES
74247 +#ifdef MODULES_VADDR
74248 unsigned long addr = (unsigned long)x;
74249 if (addr >= MODULES_VADDR && addr < MODULES_END)
74250 return 1;
74251 #endif
74252 +
74253 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74254 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74255 + return 1;
74256 +#endif
74257 +
74258 +#endif
74259 +
74260 return is_vmalloc_addr(x);
74261 }
74262
74263 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74264
74265 if (!pgd_none(*pgd)) {
74266 pud_t *pud = pud_offset(pgd, addr);
74267 +#ifdef CONFIG_X86
74268 + if (!pud_large(*pud))
74269 +#endif
74270 if (!pud_none(*pud)) {
74271 pmd_t *pmd = pmd_offset(pud, addr);
74272 +#ifdef CONFIG_X86
74273 + if (!pmd_large(*pmd))
74274 +#endif
74275 if (!pmd_none(*pmd)) {
74276 pte_t *ptep, pte;
74277
74278 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74279 struct vm_struct *area;
74280
74281 BUG_ON(in_interrupt());
74282 +
74283 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74284 + if (flags & VM_KERNEXEC) {
74285 + if (start != VMALLOC_START || end != VMALLOC_END)
74286 + return NULL;
74287 + start = (unsigned long)MODULES_EXEC_VADDR;
74288 + end = (unsigned long)MODULES_EXEC_END;
74289 + }
74290 +#endif
74291 +
74292 if (flags & VM_IOREMAP) {
74293 int bit = fls(size);
74294
74295 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
74296 if (count > totalram_pages)
74297 return NULL;
74298
74299 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74300 + if (!(pgprot_val(prot) & _PAGE_NX))
74301 + flags |= VM_KERNEXEC;
74302 +#endif
74303 +
74304 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74305 __builtin_return_address(0));
74306 if (!area)
74307 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74308 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74309 goto fail;
74310
74311 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74312 + if (!(pgprot_val(prot) & _PAGE_NX))
74313 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74314 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74315 + else
74316 +#endif
74317 +
74318 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74319 start, end, node, gfp_mask, caller);
74320 if (!area)
74321 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
74322 * For tight control over page level allocator and protection flags
74323 * use __vmalloc() instead.
74324 */
74325 -
74326 void *vmalloc_exec(unsigned long size)
74327 {
74328 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74329 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74330 -1, __builtin_return_address(0));
74331 }
74332
74333 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74334 unsigned long uaddr = vma->vm_start;
74335 unsigned long usize = vma->vm_end - vma->vm_start;
74336
74337 + BUG_ON(vma->vm_mirror);
74338 +
74339 if ((PAGE_SIZE-1) & (unsigned long)addr)
74340 return -EINVAL;
74341
74342 diff --git a/mm/vmstat.c b/mm/vmstat.c
74343 index f600557..1459fc8 100644
74344 --- a/mm/vmstat.c
74345 +++ b/mm/vmstat.c
74346 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74347 *
74348 * vm_stat contains the global counters
74349 */
74350 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74351 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74352 EXPORT_SYMBOL(vm_stat);
74353
74354 #ifdef CONFIG_SMP
74355 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74356 v = p->vm_stat_diff[i];
74357 p->vm_stat_diff[i] = 0;
74358 local_irq_restore(flags);
74359 - atomic_long_add(v, &zone->vm_stat[i]);
74360 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74361 global_diff[i] += v;
74362 #ifdef CONFIG_NUMA
74363 /* 3 seconds idle till flush */
74364 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74365
74366 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74367 if (global_diff[i])
74368 - atomic_long_add(global_diff[i], &vm_stat[i]);
74369 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74370 }
74371
74372 #endif
74373 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74374 start_cpu_timer(cpu);
74375 #endif
74376 #ifdef CONFIG_PROC_FS
74377 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74378 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74379 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74380 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74381 + {
74382 + mode_t gr_mode = S_IRUGO;
74383 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74384 + gr_mode = S_IRUSR;
74385 +#endif
74386 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74387 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74388 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74389 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74390 +#else
74391 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74392 +#endif
74393 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74394 + }
74395 #endif
74396 return 0;
74397 }
74398 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74399 index efea35b..9c8dd0b 100644
74400 --- a/net/8021q/vlan.c
74401 +++ b/net/8021q/vlan.c
74402 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74403 err = -EPERM;
74404 if (!capable(CAP_NET_ADMIN))
74405 break;
74406 - if ((args.u.name_type >= 0) &&
74407 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74408 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74409 struct vlan_net *vn;
74410
74411 vn = net_generic(net, vlan_net_id);
74412 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74413 index fccae26..e7ece2f 100644
74414 --- a/net/9p/trans_fd.c
74415 +++ b/net/9p/trans_fd.c
74416 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74417 oldfs = get_fs();
74418 set_fs(get_ds());
74419 /* The cast to a user pointer is valid due to the set_fs() */
74420 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74421 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74422 set_fs(oldfs);
74423
74424 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74425 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74426 index 876fbe8..8bbea9f 100644
74427 --- a/net/atm/atm_misc.c
74428 +++ b/net/atm/atm_misc.c
74429 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74430 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74431 return 1;
74432 atm_return(vcc, truesize);
74433 - atomic_inc(&vcc->stats->rx_drop);
74434 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74435 return 0;
74436 }
74437 EXPORT_SYMBOL(atm_charge);
74438 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74439 }
74440 }
74441 atm_return(vcc, guess);
74442 - atomic_inc(&vcc->stats->rx_drop);
74443 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74444 return NULL;
74445 }
74446 EXPORT_SYMBOL(atm_alloc_charge);
74447 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74448
74449 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74450 {
74451 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74452 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74453 __SONET_ITEMS
74454 #undef __HANDLE_ITEM
74455 }
74456 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74457
74458 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74459 {
74460 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74461 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74462 __SONET_ITEMS
74463 #undef __HANDLE_ITEM
74464 }
74465 diff --git a/net/atm/lec.h b/net/atm/lec.h
74466 index dfc0719..47c5322 100644
74467 --- a/net/atm/lec.h
74468 +++ b/net/atm/lec.h
74469 @@ -48,7 +48,7 @@ struct lane2_ops {
74470 const u8 *tlvs, u32 sizeoftlvs);
74471 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74472 const u8 *tlvs, u32 sizeoftlvs);
74473 -};
74474 +} __no_const;
74475
74476 /*
74477 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74478 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74479 index 0919a88..a23d54e 100644
74480 --- a/net/atm/mpc.h
74481 +++ b/net/atm/mpc.h
74482 @@ -33,7 +33,7 @@ struct mpoa_client {
74483 struct mpc_parameters parameters; /* parameters for this client */
74484
74485 const struct net_device_ops *old_ops;
74486 - struct net_device_ops new_ops;
74487 + net_device_ops_no_const new_ops;
74488 };
74489
74490
74491 diff --git a/net/atm/proc.c b/net/atm/proc.c
74492 index 0d020de..011c7bb 100644
74493 --- a/net/atm/proc.c
74494 +++ b/net/atm/proc.c
74495 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74496 const struct k_atm_aal_stats *stats)
74497 {
74498 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74499 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74500 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74501 - atomic_read(&stats->rx_drop));
74502 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74503 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74504 + atomic_read_unchecked(&stats->rx_drop));
74505 }
74506
74507 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74508 diff --git a/net/atm/resources.c b/net/atm/resources.c
74509 index 23f45ce..c748f1a 100644
74510 --- a/net/atm/resources.c
74511 +++ b/net/atm/resources.c
74512 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74513 static void copy_aal_stats(struct k_atm_aal_stats *from,
74514 struct atm_aal_stats *to)
74515 {
74516 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74517 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74518 __AAL_STAT_ITEMS
74519 #undef __HANDLE_ITEM
74520 }
74521 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74522 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74523 struct atm_aal_stats *to)
74524 {
74525 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74526 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74527 __AAL_STAT_ITEMS
74528 #undef __HANDLE_ITEM
74529 }
74530 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74531 index 3512e25..2b33401 100644
74532 --- a/net/batman-adv/bat_iv_ogm.c
74533 +++ b/net/batman-adv/bat_iv_ogm.c
74534 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74535
74536 /* change sequence number to network order */
74537 batman_ogm_packet->seqno =
74538 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74539 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74540
74541 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74542 batman_ogm_packet->tt_crc = htons((uint16_t)
74543 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74544 else
74545 batman_ogm_packet->gw_flags = NO_FLAGS;
74546
74547 - atomic_inc(&hard_iface->seqno);
74548 + atomic_inc_unchecked(&hard_iface->seqno);
74549
74550 slide_own_bcast_window(hard_iface);
74551 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74552 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74553 return;
74554
74555 /* could be changed by schedule_own_packet() */
74556 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74557 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74558
74559 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74560
74561 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74562 index 7704df4..beb4e16 100644
74563 --- a/net/batman-adv/hard-interface.c
74564 +++ b/net/batman-adv/hard-interface.c
74565 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74566 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74567 dev_add_pack(&hard_iface->batman_adv_ptype);
74568
74569 - atomic_set(&hard_iface->seqno, 1);
74570 - atomic_set(&hard_iface->frag_seqno, 1);
74571 + atomic_set_unchecked(&hard_iface->seqno, 1);
74572 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74573 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74574 hard_iface->net_dev->name);
74575
74576 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74577 index 987c75a..20d6f36 100644
74578 --- a/net/batman-adv/soft-interface.c
74579 +++ b/net/batman-adv/soft-interface.c
74580 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74581
74582 /* set broadcast sequence number */
74583 bcast_packet->seqno =
74584 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74585 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74586
74587 add_bcast_packet_to_list(bat_priv, skb, 1);
74588
74589 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74590 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74591
74592 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74593 - atomic_set(&bat_priv->bcast_seqno, 1);
74594 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74595 atomic_set(&bat_priv->ttvn, 0);
74596 atomic_set(&bat_priv->tt_local_changes, 0);
74597 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74598 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74599 index e9eb043..d174eeb 100644
74600 --- a/net/batman-adv/types.h
74601 +++ b/net/batman-adv/types.h
74602 @@ -38,8 +38,8 @@ struct hard_iface {
74603 int16_t if_num;
74604 char if_status;
74605 struct net_device *net_dev;
74606 - atomic_t seqno;
74607 - atomic_t frag_seqno;
74608 + atomic_unchecked_t seqno;
74609 + atomic_unchecked_t frag_seqno;
74610 unsigned char *packet_buff;
74611 int packet_len;
74612 struct kobject *hardif_obj;
74613 @@ -154,7 +154,7 @@ struct bat_priv {
74614 atomic_t orig_interval; /* uint */
74615 atomic_t hop_penalty; /* uint */
74616 atomic_t log_level; /* uint */
74617 - atomic_t bcast_seqno;
74618 + atomic_unchecked_t bcast_seqno;
74619 atomic_t bcast_queue_left;
74620 atomic_t batman_queue_left;
74621 atomic_t ttvn; /* translation table version number */
74622 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74623 index 07d1c1d..7e9bea9 100644
74624 --- a/net/batman-adv/unicast.c
74625 +++ b/net/batman-adv/unicast.c
74626 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74627 frag1->flags = UNI_FRAG_HEAD | large_tail;
74628 frag2->flags = large_tail;
74629
74630 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74631 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74632 frag1->seqno = htons(seqno - 1);
74633 frag2->seqno = htons(seqno);
74634
74635 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74636 index 07bc69e..21e76b1 100644
74637 --- a/net/bluetooth/hci_conn.c
74638 +++ b/net/bluetooth/hci_conn.c
74639 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74640 memset(&cp, 0, sizeof(cp));
74641
74642 cp.handle = cpu_to_le16(conn->handle);
74643 - memcpy(cp.ltk, ltk, sizeof(ltk));
74644 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74645
74646 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74647 }
74648 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74649 index 32d338c..d24bcdb 100644
74650 --- a/net/bluetooth/l2cap_core.c
74651 +++ b/net/bluetooth/l2cap_core.c
74652 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74653 break;
74654
74655 case L2CAP_CONF_RFC:
74656 - if (olen == sizeof(rfc))
74657 - memcpy(&rfc, (void *)val, olen);
74658 + if (olen != sizeof(rfc))
74659 + break;
74660 +
74661 + memcpy(&rfc, (void *)val, olen);
74662
74663 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74664 rfc.mode != chan->mode)
74665 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74666
74667 switch (type) {
74668 case L2CAP_CONF_RFC:
74669 - if (olen == sizeof(rfc))
74670 - memcpy(&rfc, (void *)val, olen);
74671 + if (olen != sizeof(rfc))
74672 + break;
74673 +
74674 + memcpy(&rfc, (void *)val, olen);
74675 goto done;
74676 }
74677 }
74678 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
74679 index 5449294..7da9a5f 100644
74680 --- a/net/bridge/netfilter/ebt_ulog.c
74681 +++ b/net/bridge/netfilter/ebt_ulog.c
74682 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
74683 spin_unlock_bh(&ulog_buffers[data].lock);
74684 }
74685
74686 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
74687 static struct sk_buff *ulog_alloc_skb(unsigned int size)
74688 {
74689 struct sk_buff *skb;
74690 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74691 index 5fe2ff3..10968b5 100644
74692 --- a/net/bridge/netfilter/ebtables.c
74693 +++ b/net/bridge/netfilter/ebtables.c
74694 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74695 tmp.valid_hooks = t->table->valid_hooks;
74696 }
74697 mutex_unlock(&ebt_mutex);
74698 - if (copy_to_user(user, &tmp, *len) != 0){
74699 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74700 BUGPRINT("c2u Didn't work\n");
74701 ret = -EFAULT;
74702 break;
74703 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74704 index a97d97a..6f679ed 100644
74705 --- a/net/caif/caif_socket.c
74706 +++ b/net/caif/caif_socket.c
74707 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74708 #ifdef CONFIG_DEBUG_FS
74709 struct debug_fs_counter {
74710 atomic_t caif_nr_socks;
74711 - atomic_t caif_sock_create;
74712 - atomic_t num_connect_req;
74713 - atomic_t num_connect_resp;
74714 - atomic_t num_connect_fail_resp;
74715 - atomic_t num_disconnect;
74716 - atomic_t num_remote_shutdown_ind;
74717 - atomic_t num_tx_flow_off_ind;
74718 - atomic_t num_tx_flow_on_ind;
74719 - atomic_t num_rx_flow_off;
74720 - atomic_t num_rx_flow_on;
74721 + atomic_unchecked_t caif_sock_create;
74722 + atomic_unchecked_t num_connect_req;
74723 + atomic_unchecked_t num_connect_resp;
74724 + atomic_unchecked_t num_connect_fail_resp;
74725 + atomic_unchecked_t num_disconnect;
74726 + atomic_unchecked_t num_remote_shutdown_ind;
74727 + atomic_unchecked_t num_tx_flow_off_ind;
74728 + atomic_unchecked_t num_tx_flow_on_ind;
74729 + atomic_unchecked_t num_rx_flow_off;
74730 + atomic_unchecked_t num_rx_flow_on;
74731 };
74732 static struct debug_fs_counter cnt;
74733 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74734 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74735 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74736 #else
74737 #define dbfs_atomic_inc(v) 0
74738 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74739 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74740 sk_rcvbuf_lowwater(cf_sk));
74741 set_rx_flow_off(cf_sk);
74742 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74743 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74744 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74745 }
74746
74747 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74748 set_rx_flow_off(cf_sk);
74749 if (net_ratelimit())
74750 pr_debug("sending flow OFF due to rmem_schedule\n");
74751 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74752 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74753 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74754 }
74755 skb->dev = NULL;
74756 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74757 switch (flow) {
74758 case CAIF_CTRLCMD_FLOW_ON_IND:
74759 /* OK from modem to start sending again */
74760 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74761 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74762 set_tx_flow_on(cf_sk);
74763 cf_sk->sk.sk_state_change(&cf_sk->sk);
74764 break;
74765
74766 case CAIF_CTRLCMD_FLOW_OFF_IND:
74767 /* Modem asks us to shut up */
74768 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74769 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74770 set_tx_flow_off(cf_sk);
74771 cf_sk->sk.sk_state_change(&cf_sk->sk);
74772 break;
74773 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74774 /* We're now connected */
74775 caif_client_register_refcnt(&cf_sk->layer,
74776 cfsk_hold, cfsk_put);
74777 - dbfs_atomic_inc(&cnt.num_connect_resp);
74778 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74779 cf_sk->sk.sk_state = CAIF_CONNECTED;
74780 set_tx_flow_on(cf_sk);
74781 cf_sk->sk.sk_state_change(&cf_sk->sk);
74782 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74783
74784 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74785 /* Connect request failed */
74786 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74787 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74788 cf_sk->sk.sk_err = ECONNREFUSED;
74789 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74790 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74791 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74792
74793 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74794 /* Modem has closed this connection, or device is down. */
74795 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74796 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74797 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74798 cf_sk->sk.sk_err = ECONNRESET;
74799 set_rx_flow_on(cf_sk);
74800 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74801 return;
74802
74803 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74804 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74805 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74806 set_rx_flow_on(cf_sk);
74807 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74808 }
74809 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74810 /*ifindex = id of the interface.*/
74811 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74812
74813 - dbfs_atomic_inc(&cnt.num_connect_req);
74814 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74815 cf_sk->layer.receive = caif_sktrecv_cb;
74816
74817 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74818 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74819 spin_unlock_bh(&sk->sk_receive_queue.lock);
74820 sock->sk = NULL;
74821
74822 - dbfs_atomic_inc(&cnt.num_disconnect);
74823 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74824
74825 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74826 if (cf_sk->debugfs_socket_dir != NULL)
74827 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74828 cf_sk->conn_req.protocol = protocol;
74829 /* Increase the number of sockets created. */
74830 dbfs_atomic_inc(&cnt.caif_nr_socks);
74831 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74832 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74833 #ifdef CONFIG_DEBUG_FS
74834 if (!IS_ERR(debugfsdir)) {
74835
74836 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74837 index 5cf5222..6f704ad 100644
74838 --- a/net/caif/cfctrl.c
74839 +++ b/net/caif/cfctrl.c
74840 @@ -9,6 +9,7 @@
74841 #include <linux/stddef.h>
74842 #include <linux/spinlock.h>
74843 #include <linux/slab.h>
74844 +#include <linux/sched.h>
74845 #include <net/caif/caif_layer.h>
74846 #include <net/caif/cfpkt.h>
74847 #include <net/caif/cfctrl.h>
74848 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74849 memset(&dev_info, 0, sizeof(dev_info));
74850 dev_info.id = 0xff;
74851 cfsrvl_init(&this->serv, 0, &dev_info, false);
74852 - atomic_set(&this->req_seq_no, 1);
74853 - atomic_set(&this->rsp_seq_no, 1);
74854 + atomic_set_unchecked(&this->req_seq_no, 1);
74855 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74856 this->serv.layer.receive = cfctrl_recv;
74857 sprintf(this->serv.layer.name, "ctrl");
74858 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74859 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74860 struct cfctrl_request_info *req)
74861 {
74862 spin_lock_bh(&ctrl->info_list_lock);
74863 - atomic_inc(&ctrl->req_seq_no);
74864 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74865 + atomic_inc_unchecked(&ctrl->req_seq_no);
74866 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74867 list_add_tail(&req->list, &ctrl->list);
74868 spin_unlock_bh(&ctrl->info_list_lock);
74869 }
74870 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74871 if (p != first)
74872 pr_warn("Requests are not received in order\n");
74873
74874 - atomic_set(&ctrl->rsp_seq_no,
74875 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74876 p->sequence_no);
74877 list_del(&p->list);
74878 goto out;
74879 diff --git a/net/can/gw.c b/net/can/gw.c
74880 index 3d79b12..8de85fa 100644
74881 --- a/net/can/gw.c
74882 +++ b/net/can/gw.c
74883 @@ -96,7 +96,7 @@ struct cf_mod {
74884 struct {
74885 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74886 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74887 - } csumfunc;
74888 + } __no_const csumfunc;
74889 };
74890
74891
74892 diff --git a/net/compat.c b/net/compat.c
74893 index 6def90e..c6992fa 100644
74894 --- a/net/compat.c
74895 +++ b/net/compat.c
74896 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74897 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74898 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74899 return -EFAULT;
74900 - kmsg->msg_name = compat_ptr(tmp1);
74901 - kmsg->msg_iov = compat_ptr(tmp2);
74902 - kmsg->msg_control = compat_ptr(tmp3);
74903 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74904 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74905 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74906 return 0;
74907 }
74908
74909 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74910
74911 if (kern_msg->msg_namelen) {
74912 if (mode == VERIFY_READ) {
74913 - int err = move_addr_to_kernel(kern_msg->msg_name,
74914 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74915 kern_msg->msg_namelen,
74916 kern_address);
74917 if (err < 0)
74918 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74919 kern_msg->msg_name = NULL;
74920
74921 tot_len = iov_from_user_compat_to_kern(kern_iov,
74922 - (struct compat_iovec __user *)kern_msg->msg_iov,
74923 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74924 kern_msg->msg_iovlen);
74925 if (tot_len >= 0)
74926 kern_msg->msg_iov = kern_iov;
74927 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74928
74929 #define CMSG_COMPAT_FIRSTHDR(msg) \
74930 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74931 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74932 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74933 (struct compat_cmsghdr __user *)NULL)
74934
74935 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74936 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74937 (ucmlen) <= (unsigned long) \
74938 ((mhdr)->msg_controllen - \
74939 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74940 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74941
74942 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74943 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74944 {
74945 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74946 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74947 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74948 msg->msg_controllen)
74949 return NULL;
74950 return (struct compat_cmsghdr __user *)ptr;
74951 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74952 {
74953 struct compat_timeval ctv;
74954 struct compat_timespec cts[3];
74955 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74956 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74957 struct compat_cmsghdr cmhdr;
74958 int cmlen;
74959
74960 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74961
74962 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74963 {
74964 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74965 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74966 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74967 int fdnum = scm->fp->count;
74968 struct file **fp = scm->fp->fp;
74969 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74970 return -EFAULT;
74971 old_fs = get_fs();
74972 set_fs(KERNEL_DS);
74973 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74974 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74975 set_fs(old_fs);
74976
74977 return err;
74978 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74979 len = sizeof(ktime);
74980 old_fs = get_fs();
74981 set_fs(KERNEL_DS);
74982 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74983 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74984 set_fs(old_fs);
74985
74986 if (!err) {
74987 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74988 case MCAST_JOIN_GROUP:
74989 case MCAST_LEAVE_GROUP:
74990 {
74991 - struct compat_group_req __user *gr32 = (void *)optval;
74992 + struct compat_group_req __user *gr32 = (void __user *)optval;
74993 struct group_req __user *kgr =
74994 compat_alloc_user_space(sizeof(struct group_req));
74995 u32 interface;
74996 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74997 case MCAST_BLOCK_SOURCE:
74998 case MCAST_UNBLOCK_SOURCE:
74999 {
75000 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75001 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75002 struct group_source_req __user *kgsr = compat_alloc_user_space(
75003 sizeof(struct group_source_req));
75004 u32 interface;
75005 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75006 }
75007 case MCAST_MSFILTER:
75008 {
75009 - struct compat_group_filter __user *gf32 = (void *)optval;
75010 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75011 struct group_filter __user *kgf;
75012 u32 interface, fmode, numsrc;
75013
75014 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75015 char __user *optval, int __user *optlen,
75016 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75017 {
75018 - struct compat_group_filter __user *gf32 = (void *)optval;
75019 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75020 struct group_filter __user *kgf;
75021 int __user *koptlen;
75022 u32 interface, fmode, numsrc;
75023 diff --git a/net/core/datagram.c b/net/core/datagram.c
75024 index 68bbf9f..5ef0d12 100644
75025 --- a/net/core/datagram.c
75026 +++ b/net/core/datagram.c
75027 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75028 }
75029
75030 kfree_skb(skb);
75031 - atomic_inc(&sk->sk_drops);
75032 + atomic_inc_unchecked(&sk->sk_drops);
75033 sk_mem_reclaim_partial(sk);
75034
75035 return err;
75036 diff --git a/net/core/dev.c b/net/core/dev.c
75037 index a4bf943..9c83051 100644
75038 --- a/net/core/dev.c
75039 +++ b/net/core/dev.c
75040 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
75041 if (no_module && capable(CAP_NET_ADMIN))
75042 no_module = request_module("netdev-%s", name);
75043 if (no_module && capable(CAP_SYS_MODULE)) {
75044 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75045 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75046 +#else
75047 if (!request_module("%s", name))
75048 pr_err("Loading kernel module for a network device "
75049 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75050 "instead\n", name);
75051 +#endif
75052 }
75053 }
75054 EXPORT_SYMBOL(dev_load);
75055 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75056 {
75057 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75058 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75059 - atomic_long_inc(&dev->rx_dropped);
75060 + atomic_long_inc_unchecked(&dev->rx_dropped);
75061 kfree_skb(skb);
75062 return NET_RX_DROP;
75063 }
75064 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75065 nf_reset(skb);
75066
75067 if (unlikely(!is_skb_forwardable(dev, skb))) {
75068 - atomic_long_inc(&dev->rx_dropped);
75069 + atomic_long_inc_unchecked(&dev->rx_dropped);
75070 kfree_skb(skb);
75071 return NET_RX_DROP;
75072 }
75073 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75074
75075 struct dev_gso_cb {
75076 void (*destructor)(struct sk_buff *skb);
75077 -};
75078 +} __no_const;
75079
75080 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75081
75082 @@ -2913,7 +2917,7 @@ enqueue:
75083
75084 local_irq_restore(flags);
75085
75086 - atomic_long_inc(&skb->dev->rx_dropped);
75087 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75088 kfree_skb(skb);
75089 return NET_RX_DROP;
75090 }
75091 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
75092 }
75093 EXPORT_SYMBOL(netif_rx_ni);
75094
75095 -static void net_tx_action(struct softirq_action *h)
75096 +static void net_tx_action(void)
75097 {
75098 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75099
75100 @@ -3273,7 +3277,7 @@ ncls:
75101 if (pt_prev) {
75102 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75103 } else {
75104 - atomic_long_inc(&skb->dev->rx_dropped);
75105 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75106 kfree_skb(skb);
75107 /* Jamal, now you will not able to escape explaining
75108 * me how you were going to use this. :-)
75109 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
75110 }
75111 EXPORT_SYMBOL(netif_napi_del);
75112
75113 -static void net_rx_action(struct softirq_action *h)
75114 +static void net_rx_action(void)
75115 {
75116 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75117 unsigned long time_limit = jiffies + 2;
75118 @@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75119 } else {
75120 netdev_stats_to_stats64(storage, &dev->stats);
75121 }
75122 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75123 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75124 return storage;
75125 }
75126 EXPORT_SYMBOL(dev_get_stats);
75127 diff --git a/net/core/flow.c b/net/core/flow.c
75128 index e318c7e..168b1d0 100644
75129 --- a/net/core/flow.c
75130 +++ b/net/core/flow.c
75131 @@ -61,7 +61,7 @@ struct flow_cache {
75132 struct timer_list rnd_timer;
75133 };
75134
75135 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75136 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75137 EXPORT_SYMBOL(flow_cache_genid);
75138 static struct flow_cache flow_cache_global;
75139 static struct kmem_cache *flow_cachep __read_mostly;
75140 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75141
75142 static int flow_entry_valid(struct flow_cache_entry *fle)
75143 {
75144 - if (atomic_read(&flow_cache_genid) != fle->genid)
75145 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75146 return 0;
75147 if (fle->object && !fle->object->ops->check(fle->object))
75148 return 0;
75149 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75150 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75151 fcp->hash_count++;
75152 }
75153 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75154 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75155 flo = fle->object;
75156 if (!flo)
75157 goto ret_object;
75158 @@ -280,7 +280,7 @@ nocache:
75159 }
75160 flo = resolver(net, key, family, dir, flo, ctx);
75161 if (fle) {
75162 - fle->genid = atomic_read(&flow_cache_genid);
75163 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75164 if (!IS_ERR(flo))
75165 fle->object = flo;
75166 else
75167 diff --git a/net/core/iovec.c b/net/core/iovec.c
75168 index c40f27e..7f49254 100644
75169 --- a/net/core/iovec.c
75170 +++ b/net/core/iovec.c
75171 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75172 if (m->msg_namelen) {
75173 if (mode == VERIFY_READ) {
75174 void __user *namep;
75175 - namep = (void __user __force *) m->msg_name;
75176 + namep = (void __force_user *) m->msg_name;
75177 err = move_addr_to_kernel(namep, m->msg_namelen,
75178 address);
75179 if (err < 0)
75180 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75181 }
75182
75183 size = m->msg_iovlen * sizeof(struct iovec);
75184 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75185 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75186 return -EFAULT;
75187
75188 m->msg_iov = iov;
75189 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75190 index 5c30296..ebe7b61 100644
75191 --- a/net/core/rtnetlink.c
75192 +++ b/net/core/rtnetlink.c
75193 @@ -57,7 +57,7 @@ struct rtnl_link {
75194 rtnl_doit_func doit;
75195 rtnl_dumpit_func dumpit;
75196 rtnl_calcit_func calcit;
75197 -};
75198 +} __no_const;
75199
75200 static DEFINE_MUTEX(rtnl_mutex);
75201
75202 diff --git a/net/core/scm.c b/net/core/scm.c
75203 index ff52ad0..aff1c0f 100644
75204 --- a/net/core/scm.c
75205 +++ b/net/core/scm.c
75206 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75207 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75208 {
75209 struct cmsghdr __user *cm
75210 - = (__force struct cmsghdr __user *)msg->msg_control;
75211 + = (struct cmsghdr __force_user *)msg->msg_control;
75212 struct cmsghdr cmhdr;
75213 int cmlen = CMSG_LEN(len);
75214 int err;
75215 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75216 err = -EFAULT;
75217 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75218 goto out;
75219 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75220 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75221 goto out;
75222 cmlen = CMSG_SPACE(len);
75223 if (msg->msg_controllen < cmlen)
75224 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75225 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75226 {
75227 struct cmsghdr __user *cm
75228 - = (__force struct cmsghdr __user*)msg->msg_control;
75229 + = (struct cmsghdr __force_user *)msg->msg_control;
75230
75231 int fdmax = 0;
75232 int fdnum = scm->fp->count;
75233 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75234 if (fdnum < fdmax)
75235 fdmax = fdnum;
75236
75237 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75238 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75239 i++, cmfptr++)
75240 {
75241 int new_fd;
75242 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75243 index da0c97f..8253632 100644
75244 --- a/net/core/skbuff.c
75245 +++ b/net/core/skbuff.c
75246 @@ -3160,6 +3160,8 @@ static void sock_rmem_free(struct sk_buff *skb)
75247 */
75248 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75249 {
75250 + int len = skb->len;
75251 +
75252 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75253 (unsigned)sk->sk_rcvbuf)
75254 return -ENOMEM;
75255 @@ -3174,7 +3176,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75256
75257 skb_queue_tail(&sk->sk_error_queue, skb);
75258 if (!sock_flag(sk, SOCK_DEAD))
75259 - sk->sk_data_ready(sk, skb->len);
75260 + sk->sk_data_ready(sk, len);
75261 return 0;
75262 }
75263 EXPORT_SYMBOL(sock_queue_err_skb);
75264 diff --git a/net/core/sock.c b/net/core/sock.c
75265 index 02f8dfe..86dfd4a 100644
75266 --- a/net/core/sock.c
75267 +++ b/net/core/sock.c
75268 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75269 struct sk_buff_head *list = &sk->sk_receive_queue;
75270
75271 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75272 - atomic_inc(&sk->sk_drops);
75273 + atomic_inc_unchecked(&sk->sk_drops);
75274 trace_sock_rcvqueue_full(sk, skb);
75275 return -ENOMEM;
75276 }
75277 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75278 return err;
75279
75280 if (!sk_rmem_schedule(sk, skb->truesize)) {
75281 - atomic_inc(&sk->sk_drops);
75282 + atomic_inc_unchecked(&sk->sk_drops);
75283 return -ENOBUFS;
75284 }
75285
75286 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75287 skb_dst_force(skb);
75288
75289 spin_lock_irqsave(&list->lock, flags);
75290 - skb->dropcount = atomic_read(&sk->sk_drops);
75291 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75292 __skb_queue_tail(list, skb);
75293 spin_unlock_irqrestore(&list->lock, flags);
75294
75295 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75296 skb->dev = NULL;
75297
75298 if (sk_rcvqueues_full(sk, skb)) {
75299 - atomic_inc(&sk->sk_drops);
75300 + atomic_inc_unchecked(&sk->sk_drops);
75301 goto discard_and_relse;
75302 }
75303 if (nested)
75304 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75305 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75306 } else if (sk_add_backlog(sk, skb)) {
75307 bh_unlock_sock(sk);
75308 - atomic_inc(&sk->sk_drops);
75309 + atomic_inc_unchecked(&sk->sk_drops);
75310 goto discard_and_relse;
75311 }
75312
75313 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75314 if (len > sizeof(peercred))
75315 len = sizeof(peercred);
75316 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75317 - if (copy_to_user(optval, &peercred, len))
75318 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75319 return -EFAULT;
75320 goto lenout;
75321 }
75322 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75323 return -ENOTCONN;
75324 if (lv < len)
75325 return -EINVAL;
75326 - if (copy_to_user(optval, address, len))
75327 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75328 return -EFAULT;
75329 goto lenout;
75330 }
75331 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75332
75333 if (len > lv)
75334 len = lv;
75335 - if (copy_to_user(optval, &v, len))
75336 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75337 return -EFAULT;
75338 lenout:
75339 if (put_user(len, optlen))
75340 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75341 */
75342 smp_wmb();
75343 atomic_set(&sk->sk_refcnt, 1);
75344 - atomic_set(&sk->sk_drops, 0);
75345 + atomic_set_unchecked(&sk->sk_drops, 0);
75346 }
75347 EXPORT_SYMBOL(sock_init_data);
75348
75349 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75350 index b9868e1..849f809 100644
75351 --- a/net/core/sock_diag.c
75352 +++ b/net/core/sock_diag.c
75353 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75354
75355 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75356 {
75357 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75358 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75359 cookie[1] != INET_DIAG_NOCOOKIE) &&
75360 ((u32)(unsigned long)sk != cookie[0] ||
75361 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75362 return -ESTALE;
75363 else
75364 +#endif
75365 return 0;
75366 }
75367 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75368
75369 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75370 {
75371 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75372 + cookie[0] = 0;
75373 + cookie[1] = 0;
75374 +#else
75375 cookie[0] = (u32)(unsigned long)sk;
75376 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75377 +#endif
75378 }
75379 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75380
75381 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75382 index 02e75d1..9a57a7c 100644
75383 --- a/net/decnet/sysctl_net_decnet.c
75384 +++ b/net/decnet/sysctl_net_decnet.c
75385 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75386
75387 if (len > *lenp) len = *lenp;
75388
75389 - if (copy_to_user(buffer, addr, len))
75390 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75391 return -EFAULT;
75392
75393 *lenp = len;
75394 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75395
75396 if (len > *lenp) len = *lenp;
75397
75398 - if (copy_to_user(buffer, devname, len))
75399 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75400 return -EFAULT;
75401
75402 *lenp = len;
75403 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75404 index 39a2d29..f39c0fe 100644
75405 --- a/net/econet/Kconfig
75406 +++ b/net/econet/Kconfig
75407 @@ -4,7 +4,7 @@
75408
75409 config ECONET
75410 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75411 - depends on EXPERIMENTAL && INET
75412 + depends on EXPERIMENTAL && INET && BROKEN
75413 ---help---
75414 Econet is a fairly old and slow networking protocol mainly used by
75415 Acorn computers to access file and print servers. It uses native
75416 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75417 index 36d1440..44ff28b 100644
75418 --- a/net/ipv4/ah4.c
75419 +++ b/net/ipv4/ah4.c
75420 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75421 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75422
75423 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75424 + unsigned int size) __size_overflow(3);
75425 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75426 unsigned int size)
75427 {
75428 unsigned int len;
75429 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75430 index 92fc5f6..b790d91 100644
75431 --- a/net/ipv4/fib_frontend.c
75432 +++ b/net/ipv4/fib_frontend.c
75433 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75434 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75435 fib_sync_up(dev);
75436 #endif
75437 - atomic_inc(&net->ipv4.dev_addr_genid);
75438 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75439 rt_cache_flush(dev_net(dev), -1);
75440 break;
75441 case NETDEV_DOWN:
75442 fib_del_ifaddr(ifa, NULL);
75443 - atomic_inc(&net->ipv4.dev_addr_genid);
75444 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75445 if (ifa->ifa_dev->ifa_list == NULL) {
75446 /* Last address was deleted from this interface.
75447 * Disable IP.
75448 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75449 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75450 fib_sync_up(dev);
75451 #endif
75452 - atomic_inc(&net->ipv4.dev_addr_genid);
75453 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75454 rt_cache_flush(dev_net(dev), -1);
75455 break;
75456 case NETDEV_DOWN:
75457 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75458 index 80106d8..232e898 100644
75459 --- a/net/ipv4/fib_semantics.c
75460 +++ b/net/ipv4/fib_semantics.c
75461 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75462 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75463 nh->nh_gw,
75464 nh->nh_parent->fib_scope);
75465 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75466 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75467
75468 return nh->nh_saddr;
75469 }
75470 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75471 index 984ec65..97ac518 100644
75472 --- a/net/ipv4/inet_hashtables.c
75473 +++ b/net/ipv4/inet_hashtables.c
75474 @@ -18,12 +18,15 @@
75475 #include <linux/sched.h>
75476 #include <linux/slab.h>
75477 #include <linux/wait.h>
75478 +#include <linux/security.h>
75479
75480 #include <net/inet_connection_sock.h>
75481 #include <net/inet_hashtables.h>
75482 #include <net/secure_seq.h>
75483 #include <net/ip.h>
75484
75485 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75486 +
75487 /*
75488 * Allocate and initialize a new local port bind bucket.
75489 * The bindhash mutex for snum's hash chain must be held here.
75490 @@ -530,6 +533,8 @@ ok:
75491 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75492 spin_unlock(&head->lock);
75493
75494 + gr_update_task_in_ip_table(current, inet_sk(sk));
75495 +
75496 if (tw) {
75497 inet_twsk_deschedule(tw, death_row);
75498 while (twrefcnt) {
75499 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75500 index d4d61b6..b81aec8 100644
75501 --- a/net/ipv4/inetpeer.c
75502 +++ b/net/ipv4/inetpeer.c
75503 @@ -487,8 +487,8 @@ relookup:
75504 if (p) {
75505 p->daddr = *daddr;
75506 atomic_set(&p->refcnt, 1);
75507 - atomic_set(&p->rid, 0);
75508 - atomic_set(&p->ip_id_count,
75509 + atomic_set_unchecked(&p->rid, 0);
75510 + atomic_set_unchecked(&p->ip_id_count,
75511 (daddr->family == AF_INET) ?
75512 secure_ip_id(daddr->addr.a4) :
75513 secure_ipv6_id(daddr->addr.a6));
75514 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75515 index 1f23a57..7180dfe 100644
75516 --- a/net/ipv4/ip_fragment.c
75517 +++ b/net/ipv4/ip_fragment.c
75518 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75519 return 0;
75520
75521 start = qp->rid;
75522 - end = atomic_inc_return(&peer->rid);
75523 + end = atomic_inc_return_unchecked(&peer->rid);
75524 qp->rid = end;
75525
75526 rc = qp->q.fragments && (end - start) > max;
75527 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75528 index 8aa87c1..35c3248 100644
75529 --- a/net/ipv4/ip_sockglue.c
75530 +++ b/net/ipv4/ip_sockglue.c
75531 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75532 len = min_t(unsigned int, len, opt->optlen);
75533 if (put_user(len, optlen))
75534 return -EFAULT;
75535 - if (copy_to_user(optval, opt->__data, len))
75536 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75537 + copy_to_user(optval, opt->__data, len))
75538 return -EFAULT;
75539 return 0;
75540 }
75541 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75542 if (sk->sk_type != SOCK_STREAM)
75543 return -ENOPROTOOPT;
75544
75545 - msg.msg_control = optval;
75546 + msg.msg_control = (void __force_kernel *)optval;
75547 msg.msg_controllen = len;
75548 msg.msg_flags = flags;
75549
75550 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75551 index 6e412a6..6640538 100644
75552 --- a/net/ipv4/ipconfig.c
75553 +++ b/net/ipv4/ipconfig.c
75554 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75555
75556 mm_segment_t oldfs = get_fs();
75557 set_fs(get_ds());
75558 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75559 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75560 set_fs(oldfs);
75561 return res;
75562 }
75563 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75564
75565 mm_segment_t oldfs = get_fs();
75566 set_fs(get_ds());
75567 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75568 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75569 set_fs(oldfs);
75570 return res;
75571 }
75572 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75573
75574 mm_segment_t oldfs = get_fs();
75575 set_fs(get_ds());
75576 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75577 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75578 set_fs(oldfs);
75579 return res;
75580 }
75581 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
75582 index fd7a3f6..a1b1013 100644
75583 --- a/net/ipv4/netfilter/arp_tables.c
75584 +++ b/net/ipv4/netfilter/arp_tables.c
75585 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75586
75587 static int copy_entries_to_user(unsigned int total_size,
75588 const struct xt_table *table,
75589 + void __user *userptr) __size_overflow(1);
75590 +static int copy_entries_to_user(unsigned int total_size,
75591 + const struct xt_table *table,
75592 void __user *userptr)
75593 {
75594 unsigned int off, num;
75595 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
75596 unsigned int valid_hooks,
75597 struct xt_table_info *newinfo,
75598 unsigned int num_counters,
75599 + void __user *counters_ptr) __size_overflow(5);
75600 +static int __do_replace(struct net *net, const char *name,
75601 + unsigned int valid_hooks,
75602 + struct xt_table_info *newinfo,
75603 + unsigned int num_counters,
75604 void __user *counters_ptr)
75605 {
75606 int ret;
75607 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
75608 }
75609
75610 static int do_add_counters(struct net *net, const void __user *user,
75611 + unsigned int len, int compat) __size_overflow(3);
75612 +static int do_add_counters(struct net *net, const void __user *user,
75613 unsigned int len, int compat)
75614 {
75615 unsigned int i, curcpu;
75616 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
75617 index 24e556e..b073356 100644
75618 --- a/net/ipv4/netfilter/ip_tables.c
75619 +++ b/net/ipv4/netfilter/ip_tables.c
75620 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75621 static int
75622 copy_entries_to_user(unsigned int total_size,
75623 const struct xt_table *table,
75624 + void __user *userptr) __size_overflow(1);
75625 +static int
75626 +copy_entries_to_user(unsigned int total_size,
75627 + const struct xt_table *table,
75628 void __user *userptr)
75629 {
75630 unsigned int off, num;
75631 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
75632 static int
75633 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75634 struct xt_table_info *newinfo, unsigned int num_counters,
75635 + void __user *counters_ptr) __size_overflow(5);
75636 +static int
75637 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75638 + struct xt_table_info *newinfo, unsigned int num_counters,
75639 void __user *counters_ptr)
75640 {
75641 int ret;
75642 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
75643
75644 static int
75645 do_add_counters(struct net *net, const void __user *user,
75646 + unsigned int len, int compat) __size_overflow(3);
75647 +static int
75648 +do_add_counters(struct net *net, const void __user *user,
75649 unsigned int len, int compat)
75650 {
75651 unsigned int i, curcpu;
75652 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
75653 index ba5756d..8d34d74 100644
75654 --- a/net/ipv4/netfilter/ipt_ULOG.c
75655 +++ b/net/ipv4/netfilter/ipt_ULOG.c
75656 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
75657 spin_unlock_bh(&ulog_lock);
75658 }
75659
75660 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75661 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75662 {
75663 struct sk_buff *skb;
75664 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75665 index 2133c30..0e8047e 100644
75666 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75667 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75668 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
75669 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75670 unsigned char *eoc,
75671 unsigned long **oid,
75672 + unsigned int *len) __size_overflow(2);
75673 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75674 + unsigned char *eoc,
75675 + unsigned long **oid,
75676 unsigned int *len)
75677 {
75678 unsigned long subid;
75679 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75680 index b072386..abdebcf 100644
75681 --- a/net/ipv4/ping.c
75682 +++ b/net/ipv4/ping.c
75683 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75684 sk_rmem_alloc_get(sp),
75685 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75686 atomic_read(&sp->sk_refcnt), sp,
75687 - atomic_read(&sp->sk_drops), len);
75688 + atomic_read_unchecked(&sp->sk_drops), len);
75689 }
75690
75691 static int ping_seq_show(struct seq_file *seq, void *v)
75692 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75693 index 3ccda5a..3c1e61d 100644
75694 --- a/net/ipv4/raw.c
75695 +++ b/net/ipv4/raw.c
75696 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75697 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75698 {
75699 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75700 - atomic_inc(&sk->sk_drops);
75701 + atomic_inc_unchecked(&sk->sk_drops);
75702 kfree_skb(skb);
75703 return NET_RX_DROP;
75704 }
75705 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75706
75707 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75708 {
75709 + struct icmp_filter filter;
75710 +
75711 if (optlen > sizeof(struct icmp_filter))
75712 optlen = sizeof(struct icmp_filter);
75713 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75714 + if (copy_from_user(&filter, optval, optlen))
75715 return -EFAULT;
75716 + raw_sk(sk)->filter = filter;
75717 return 0;
75718 }
75719
75720 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75721 {
75722 int len, ret = -EFAULT;
75723 + struct icmp_filter filter;
75724
75725 if (get_user(len, optlen))
75726 goto out;
75727 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75728 if (len > sizeof(struct icmp_filter))
75729 len = sizeof(struct icmp_filter);
75730 ret = -EFAULT;
75731 - if (put_user(len, optlen) ||
75732 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75733 + filter = raw_sk(sk)->filter;
75734 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75735 goto out;
75736 ret = 0;
75737 out: return ret;
75738 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75739 sk_wmem_alloc_get(sp),
75740 sk_rmem_alloc_get(sp),
75741 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75742 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75743 + atomic_read(&sp->sk_refcnt),
75744 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75745 + NULL,
75746 +#else
75747 + sp,
75748 +#endif
75749 + atomic_read_unchecked(&sp->sk_drops));
75750 }
75751
75752 static int raw_seq_show(struct seq_file *seq, void *v)
75753 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75754 index 0197747..7adb0dc 100644
75755 --- a/net/ipv4/route.c
75756 +++ b/net/ipv4/route.c
75757 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75758
75759 static inline int rt_genid(struct net *net)
75760 {
75761 - return atomic_read(&net->ipv4.rt_genid);
75762 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75763 }
75764
75765 #ifdef CONFIG_PROC_FS
75766 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75767 unsigned char shuffle;
75768
75769 get_random_bytes(&shuffle, sizeof(shuffle));
75770 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75771 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75772 inetpeer_invalidate_tree(AF_INET);
75773 }
75774
75775 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75776 error = rt->dst.error;
75777 if (peer) {
75778 inet_peer_refcheck(rt->peer);
75779 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75780 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75781 if (peer->tcp_ts_stamp) {
75782 ts = peer->tcp_ts;
75783 tsage = get_seconds() - peer->tcp_ts_stamp;
75784 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75785 index fd54c5f..96d6407 100644
75786 --- a/net/ipv4/tcp_ipv4.c
75787 +++ b/net/ipv4/tcp_ipv4.c
75788 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75789 int sysctl_tcp_low_latency __read_mostly;
75790 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75791
75792 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75793 +extern int grsec_enable_blackhole;
75794 +#endif
75795
75796 #ifdef CONFIG_TCP_MD5SIG
75797 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75798 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75799 return 0;
75800
75801 reset:
75802 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75803 + if (!grsec_enable_blackhole)
75804 +#endif
75805 tcp_v4_send_reset(rsk, skb);
75806 discard:
75807 kfree_skb(skb);
75808 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75809 TCP_SKB_CB(skb)->sacked = 0;
75810
75811 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75812 - if (!sk)
75813 + if (!sk) {
75814 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75815 + ret = 1;
75816 +#endif
75817 goto no_tcp_socket;
75818 -
75819 + }
75820 process:
75821 - if (sk->sk_state == TCP_TIME_WAIT)
75822 + if (sk->sk_state == TCP_TIME_WAIT) {
75823 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75824 + ret = 2;
75825 +#endif
75826 goto do_time_wait;
75827 + }
75828
75829 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75830 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75831 @@ -1755,6 +1768,10 @@ no_tcp_socket:
75832 bad_packet:
75833 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75834 } else {
75835 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75836 + if (!grsec_enable_blackhole || (ret == 1 &&
75837 + (skb->dev->flags & IFF_LOOPBACK)))
75838 +#endif
75839 tcp_v4_send_reset(NULL, skb);
75840 }
75841
75842 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75843 0, /* non standard timer */
75844 0, /* open_requests have no inode */
75845 atomic_read(&sk->sk_refcnt),
75846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75847 + NULL,
75848 +#else
75849 req,
75850 +#endif
75851 len);
75852 }
75853
75854 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75855 sock_i_uid(sk),
75856 icsk->icsk_probes_out,
75857 sock_i_ino(sk),
75858 - atomic_read(&sk->sk_refcnt), sk,
75859 + atomic_read(&sk->sk_refcnt),
75860 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75861 + NULL,
75862 +#else
75863 + sk,
75864 +#endif
75865 jiffies_to_clock_t(icsk->icsk_rto),
75866 jiffies_to_clock_t(icsk->icsk_ack.ato),
75867 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75868 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75869 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75870 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75871 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75872 - atomic_read(&tw->tw_refcnt), tw, len);
75873 + atomic_read(&tw->tw_refcnt),
75874 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75875 + NULL,
75876 +#else
75877 + tw,
75878 +#endif
75879 + len);
75880 }
75881
75882 #define TMPSZ 150
75883 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75884 index 550e755..25721b3 100644
75885 --- a/net/ipv4/tcp_minisocks.c
75886 +++ b/net/ipv4/tcp_minisocks.c
75887 @@ -27,6 +27,10 @@
75888 #include <net/inet_common.h>
75889 #include <net/xfrm.h>
75890
75891 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75892 +extern int grsec_enable_blackhole;
75893 +#endif
75894 +
75895 int sysctl_tcp_syncookies __read_mostly = 1;
75896 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75897
75898 @@ -753,6 +757,10 @@ listen_overflow:
75899
75900 embryonic_reset:
75901 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75902 +
75903 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75904 + if (!grsec_enable_blackhole)
75905 +#endif
75906 if (!(flg & TCP_FLAG_RST))
75907 req->rsk_ops->send_reset(sk, skb);
75908
75909 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75910 index 85ee7eb..53277ab 100644
75911 --- a/net/ipv4/tcp_probe.c
75912 +++ b/net/ipv4/tcp_probe.c
75913 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75914 if (cnt + width >= len)
75915 break;
75916
75917 - if (copy_to_user(buf + cnt, tbuf, width))
75918 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75919 return -EFAULT;
75920 cnt += width;
75921 }
75922 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75923 index cd2e072..1fffee2 100644
75924 --- a/net/ipv4/tcp_timer.c
75925 +++ b/net/ipv4/tcp_timer.c
75926 @@ -22,6 +22,10 @@
75927 #include <linux/gfp.h>
75928 #include <net/tcp.h>
75929
75930 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75931 +extern int grsec_lastack_retries;
75932 +#endif
75933 +
75934 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75935 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75936 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75937 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75938 }
75939 }
75940
75941 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75942 + if ((sk->sk_state == TCP_LAST_ACK) &&
75943 + (grsec_lastack_retries > 0) &&
75944 + (grsec_lastack_retries < retry_until))
75945 + retry_until = grsec_lastack_retries;
75946 +#endif
75947 +
75948 if (retransmits_timed_out(sk, retry_until,
75949 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75950 /* Has it gone just too far? */
75951 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75952 index 5d075b5..d907d5f 100644
75953 --- a/net/ipv4/udp.c
75954 +++ b/net/ipv4/udp.c
75955 @@ -86,6 +86,7 @@
75956 #include <linux/types.h>
75957 #include <linux/fcntl.h>
75958 #include <linux/module.h>
75959 +#include <linux/security.h>
75960 #include <linux/socket.h>
75961 #include <linux/sockios.h>
75962 #include <linux/igmp.h>
75963 @@ -108,6 +109,10 @@
75964 #include <trace/events/udp.h>
75965 #include "udp_impl.h"
75966
75967 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75968 +extern int grsec_enable_blackhole;
75969 +#endif
75970 +
75971 struct udp_table udp_table __read_mostly;
75972 EXPORT_SYMBOL(udp_table);
75973
75974 @@ -566,6 +571,9 @@ found:
75975 return s;
75976 }
75977
75978 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75979 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75980 +
75981 /*
75982 * This routine is called by the ICMP module when it gets some
75983 * sort of error condition. If err < 0 then the socket should
75984 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75985 dport = usin->sin_port;
75986 if (dport == 0)
75987 return -EINVAL;
75988 +
75989 + err = gr_search_udp_sendmsg(sk, usin);
75990 + if (err)
75991 + return err;
75992 } else {
75993 if (sk->sk_state != TCP_ESTABLISHED)
75994 return -EDESTADDRREQ;
75995 +
75996 + err = gr_search_udp_sendmsg(sk, NULL);
75997 + if (err)
75998 + return err;
75999 +
76000 daddr = inet->inet_daddr;
76001 dport = inet->inet_dport;
76002 /* Open fast path for connected socket.
76003 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
76004 udp_lib_checksum_complete(skb)) {
76005 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76006 IS_UDPLITE(sk));
76007 - atomic_inc(&sk->sk_drops);
76008 + atomic_inc_unchecked(&sk->sk_drops);
76009 __skb_unlink(skb, rcvq);
76010 __skb_queue_tail(&list_kill, skb);
76011 }
76012 @@ -1186,6 +1203,10 @@ try_again:
76013 if (!skb)
76014 goto out;
76015
76016 + err = gr_search_udp_recvmsg(sk, skb);
76017 + if (err)
76018 + goto out_free;
76019 +
76020 ulen = skb->len - sizeof(struct udphdr);
76021 copied = len;
76022 if (copied > ulen)
76023 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76024
76025 drop:
76026 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76027 - atomic_inc(&sk->sk_drops);
76028 + atomic_inc_unchecked(&sk->sk_drops);
76029 kfree_skb(skb);
76030 return -1;
76031 }
76032 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76033 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76034
76035 if (!skb1) {
76036 - atomic_inc(&sk->sk_drops);
76037 + atomic_inc_unchecked(&sk->sk_drops);
76038 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76039 IS_UDPLITE(sk));
76040 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76041 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76042 goto csum_error;
76043
76044 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76045 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76046 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76047 +#endif
76048 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76049
76050 /*
76051 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76052 sk_wmem_alloc_get(sp),
76053 sk_rmem_alloc_get(sp),
76054 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76055 - atomic_read(&sp->sk_refcnt), sp,
76056 - atomic_read(&sp->sk_drops), len);
76057 + atomic_read(&sp->sk_refcnt),
76058 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76059 + NULL,
76060 +#else
76061 + sp,
76062 +#endif
76063 + atomic_read_unchecked(&sp->sk_drops), len);
76064 }
76065
76066 int udp4_seq_show(struct seq_file *seq, void *v)
76067 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76068 index 6b8ebc5..1d624f4 100644
76069 --- a/net/ipv6/addrconf.c
76070 +++ b/net/ipv6/addrconf.c
76071 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76072 p.iph.ihl = 5;
76073 p.iph.protocol = IPPROTO_IPV6;
76074 p.iph.ttl = 64;
76075 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76076 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76077
76078 if (ops->ndo_do_ioctl) {
76079 mm_segment_t oldfs = get_fs();
76080 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
76081 index 2ae79db..8f101bf 100644
76082 --- a/net/ipv6/ah6.c
76083 +++ b/net/ipv6/ah6.c
76084 @@ -56,6 +56,8 @@ struct ah_skb_cb {
76085 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
76086
76087 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76088 + unsigned int size) __size_overflow(3);
76089 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76090 unsigned int size)
76091 {
76092 unsigned int len;
76093 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76094 index 02dd203..e03fcc9 100644
76095 --- a/net/ipv6/inet6_connection_sock.c
76096 +++ b/net/ipv6/inet6_connection_sock.c
76097 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76098 #ifdef CONFIG_XFRM
76099 {
76100 struct rt6_info *rt = (struct rt6_info *)dst;
76101 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76102 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76103 }
76104 #endif
76105 }
76106 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76107 #ifdef CONFIG_XFRM
76108 if (dst) {
76109 struct rt6_info *rt = (struct rt6_info *)dst;
76110 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76111 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76112 __sk_dst_reset(sk);
76113 dst = NULL;
76114 }
76115 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76116 index 18a2719..779f36a 100644
76117 --- a/net/ipv6/ipv6_sockglue.c
76118 +++ b/net/ipv6/ipv6_sockglue.c
76119 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76120 if (sk->sk_type != SOCK_STREAM)
76121 return -ENOPROTOOPT;
76122
76123 - msg.msg_control = optval;
76124 + msg.msg_control = (void __force_kernel *)optval;
76125 msg.msg_controllen = len;
76126 msg.msg_flags = flags;
76127
76128 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76129 index 94874b0..108a94d 100644
76130 --- a/net/ipv6/netfilter/ip6_tables.c
76131 +++ b/net/ipv6/netfilter/ip6_tables.c
76132 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76133 static int
76134 copy_entries_to_user(unsigned int total_size,
76135 const struct xt_table *table,
76136 + void __user *userptr) __size_overflow(1);
76137 +static int
76138 +copy_entries_to_user(unsigned int total_size,
76139 + const struct xt_table *table,
76140 void __user *userptr)
76141 {
76142 unsigned int off, num;
76143 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76144 static int
76145 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76146 struct xt_table_info *newinfo, unsigned int num_counters,
76147 + void __user *counters_ptr) __size_overflow(5);
76148 +static int
76149 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76150 + struct xt_table_info *newinfo, unsigned int num_counters,
76151 void __user *counters_ptr)
76152 {
76153 int ret;
76154 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76155
76156 static int
76157 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76158 + int compat) __size_overflow(3);
76159 +static int
76160 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76161 int compat)
76162 {
76163 unsigned int i, curcpu;
76164 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76165 index d02f7e4..2d2a0f1 100644
76166 --- a/net/ipv6/raw.c
76167 +++ b/net/ipv6/raw.c
76168 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76169 {
76170 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76171 skb_checksum_complete(skb)) {
76172 - atomic_inc(&sk->sk_drops);
76173 + atomic_inc_unchecked(&sk->sk_drops);
76174 kfree_skb(skb);
76175 return NET_RX_DROP;
76176 }
76177 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76178 struct raw6_sock *rp = raw6_sk(sk);
76179
76180 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76181 - atomic_inc(&sk->sk_drops);
76182 + atomic_inc_unchecked(&sk->sk_drops);
76183 kfree_skb(skb);
76184 return NET_RX_DROP;
76185 }
76186 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76187
76188 if (inet->hdrincl) {
76189 if (skb_checksum_complete(skb)) {
76190 - atomic_inc(&sk->sk_drops);
76191 + atomic_inc_unchecked(&sk->sk_drops);
76192 kfree_skb(skb);
76193 return NET_RX_DROP;
76194 }
76195 @@ -602,7 +602,7 @@ out:
76196 return err;
76197 }
76198
76199 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76200 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76201 struct flowi6 *fl6, struct dst_entry **dstp,
76202 unsigned int flags)
76203 {
76204 @@ -912,12 +912,15 @@ do_confirm:
76205 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76206 char __user *optval, int optlen)
76207 {
76208 + struct icmp6_filter filter;
76209 +
76210 switch (optname) {
76211 case ICMPV6_FILTER:
76212 if (optlen > sizeof(struct icmp6_filter))
76213 optlen = sizeof(struct icmp6_filter);
76214 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76215 + if (copy_from_user(&filter, optval, optlen))
76216 return -EFAULT;
76217 + raw6_sk(sk)->filter = filter;
76218 return 0;
76219 default:
76220 return -ENOPROTOOPT;
76221 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76222 char __user *optval, int __user *optlen)
76223 {
76224 int len;
76225 + struct icmp6_filter filter;
76226
76227 switch (optname) {
76228 case ICMPV6_FILTER:
76229 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76230 len = sizeof(struct icmp6_filter);
76231 if (put_user(len, optlen))
76232 return -EFAULT;
76233 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76234 + filter = raw6_sk(sk)->filter;
76235 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76236 return -EFAULT;
76237 return 0;
76238 default:
76239 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76240 0, 0L, 0,
76241 sock_i_uid(sp), 0,
76242 sock_i_ino(sp),
76243 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76244 + atomic_read(&sp->sk_refcnt),
76245 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76246 + NULL,
76247 +#else
76248 + sp,
76249 +#endif
76250 + atomic_read_unchecked(&sp->sk_drops));
76251 }
76252
76253 static int raw6_seq_show(struct seq_file *seq, void *v)
76254 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76255 index 3edd05a..63aad01 100644
76256 --- a/net/ipv6/tcp_ipv6.c
76257 +++ b/net/ipv6/tcp_ipv6.c
76258 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76259 }
76260 #endif
76261
76262 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76263 +extern int grsec_enable_blackhole;
76264 +#endif
76265 +
76266 static void tcp_v6_hash(struct sock *sk)
76267 {
76268 if (sk->sk_state != TCP_CLOSE) {
76269 @@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76270 return 0;
76271
76272 reset:
76273 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76274 + if (!grsec_enable_blackhole)
76275 +#endif
76276 tcp_v6_send_reset(sk, skb);
76277 discard:
76278 if (opt_skb)
76279 @@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76280 TCP_SKB_CB(skb)->sacked = 0;
76281
76282 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76283 - if (!sk)
76284 + if (!sk) {
76285 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76286 + ret = 1;
76287 +#endif
76288 goto no_tcp_socket;
76289 + }
76290
76291 process:
76292 - if (sk->sk_state == TCP_TIME_WAIT)
76293 + if (sk->sk_state == TCP_TIME_WAIT) {
76294 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76295 + ret = 2;
76296 +#endif
76297 goto do_time_wait;
76298 + }
76299
76300 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76301 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76302 @@ -1782,6 +1797,10 @@ no_tcp_socket:
76303 bad_packet:
76304 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76305 } else {
76306 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76307 + if (!grsec_enable_blackhole || (ret == 1 &&
76308 + (skb->dev->flags & IFF_LOOPBACK)))
76309 +#endif
76310 tcp_v6_send_reset(NULL, skb);
76311 }
76312
76313 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
76314 uid,
76315 0, /* non standard timer */
76316 0, /* open_requests have no inode */
76317 - 0, req);
76318 + 0,
76319 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76320 + NULL
76321 +#else
76322 + req
76323 +#endif
76324 + );
76325 }
76326
76327 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76328 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76329 sock_i_uid(sp),
76330 icsk->icsk_probes_out,
76331 sock_i_ino(sp),
76332 - atomic_read(&sp->sk_refcnt), sp,
76333 + atomic_read(&sp->sk_refcnt),
76334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76335 + NULL,
76336 +#else
76337 + sp,
76338 +#endif
76339 jiffies_to_clock_t(icsk->icsk_rto),
76340 jiffies_to_clock_t(icsk->icsk_ack.ato),
76341 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76342 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76343 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76344 tw->tw_substate, 0, 0,
76345 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76346 - atomic_read(&tw->tw_refcnt), tw);
76347 + atomic_read(&tw->tw_refcnt),
76348 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76349 + NULL
76350 +#else
76351 + tw
76352 +#endif
76353 + );
76354 }
76355
76356 static int tcp6_seq_show(struct seq_file *seq, void *v)
76357 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76358 index 4f96b5c..75543d7 100644
76359 --- a/net/ipv6/udp.c
76360 +++ b/net/ipv6/udp.c
76361 @@ -50,6 +50,10 @@
76362 #include <linux/seq_file.h>
76363 #include "udp_impl.h"
76364
76365 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76366 +extern int grsec_enable_blackhole;
76367 +#endif
76368 +
76369 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76370 {
76371 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76372 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76373
76374 return 0;
76375 drop:
76376 - atomic_inc(&sk->sk_drops);
76377 + atomic_inc_unchecked(&sk->sk_drops);
76378 drop_no_sk_drops_inc:
76379 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76380 kfree_skb(skb);
76381 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76382 continue;
76383 }
76384 drop:
76385 - atomic_inc(&sk->sk_drops);
76386 + atomic_inc_unchecked(&sk->sk_drops);
76387 UDP6_INC_STATS_BH(sock_net(sk),
76388 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76389 UDP6_INC_STATS_BH(sock_net(sk),
76390 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76391 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76392 proto == IPPROTO_UDPLITE);
76393
76394 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76395 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76396 +#endif
76397 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76398
76399 kfree_skb(skb);
76400 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76401 if (!sock_owned_by_user(sk))
76402 udpv6_queue_rcv_skb(sk, skb);
76403 else if (sk_add_backlog(sk, skb)) {
76404 - atomic_inc(&sk->sk_drops);
76405 + atomic_inc_unchecked(&sk->sk_drops);
76406 bh_unlock_sock(sk);
76407 sock_put(sk);
76408 goto discard;
76409 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76410 0, 0L, 0,
76411 sock_i_uid(sp), 0,
76412 sock_i_ino(sp),
76413 - atomic_read(&sp->sk_refcnt), sp,
76414 - atomic_read(&sp->sk_drops));
76415 + atomic_read(&sp->sk_refcnt),
76416 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76417 + NULL,
76418 +#else
76419 + sp,
76420 +#endif
76421 + atomic_read_unchecked(&sp->sk_drops));
76422 }
76423
76424 int udp6_seq_show(struct seq_file *seq, void *v)
76425 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76426 index 253695d..9481ce8 100644
76427 --- a/net/irda/ircomm/ircomm_tty.c
76428 +++ b/net/irda/ircomm/ircomm_tty.c
76429 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76430 add_wait_queue(&self->open_wait, &wait);
76431
76432 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76433 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76434 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76435
76436 /* As far as I can see, we protect open_count - Jean II */
76437 spin_lock_irqsave(&self->spinlock, flags);
76438 if (!tty_hung_up_p(filp)) {
76439 extra_count = 1;
76440 - self->open_count--;
76441 + local_dec(&self->open_count);
76442 }
76443 spin_unlock_irqrestore(&self->spinlock, flags);
76444 - self->blocked_open++;
76445 + local_inc(&self->blocked_open);
76446
76447 while (1) {
76448 if (tty->termios->c_cflag & CBAUD) {
76449 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76450 }
76451
76452 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76453 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76454 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76455
76456 schedule();
76457 }
76458 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76459 if (extra_count) {
76460 /* ++ is not atomic, so this should be protected - Jean II */
76461 spin_lock_irqsave(&self->spinlock, flags);
76462 - self->open_count++;
76463 + local_inc(&self->open_count);
76464 spin_unlock_irqrestore(&self->spinlock, flags);
76465 }
76466 - self->blocked_open--;
76467 + local_dec(&self->blocked_open);
76468
76469 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76470 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76471 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76472
76473 if (!retval)
76474 self->flags |= ASYNC_NORMAL_ACTIVE;
76475 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76476 }
76477 /* ++ is not atomic, so this should be protected - Jean II */
76478 spin_lock_irqsave(&self->spinlock, flags);
76479 - self->open_count++;
76480 + local_inc(&self->open_count);
76481
76482 tty->driver_data = self;
76483 self->tty = tty;
76484 spin_unlock_irqrestore(&self->spinlock, flags);
76485
76486 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76487 - self->line, self->open_count);
76488 + self->line, local_read(&self->open_count));
76489
76490 /* Not really used by us, but lets do it anyway */
76491 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76492 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76493 return;
76494 }
76495
76496 - if ((tty->count == 1) && (self->open_count != 1)) {
76497 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76498 /*
76499 * Uh, oh. tty->count is 1, which means that the tty
76500 * structure will be freed. state->count should always
76501 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76502 */
76503 IRDA_DEBUG(0, "%s(), bad serial port count; "
76504 "tty->count is 1, state->count is %d\n", __func__ ,
76505 - self->open_count);
76506 - self->open_count = 1;
76507 + local_read(&self->open_count));
76508 + local_set(&self->open_count, 1);
76509 }
76510
76511 - if (--self->open_count < 0) {
76512 + if (local_dec_return(&self->open_count) < 0) {
76513 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76514 - __func__, self->line, self->open_count);
76515 - self->open_count = 0;
76516 + __func__, self->line, local_read(&self->open_count));
76517 + local_set(&self->open_count, 0);
76518 }
76519 - if (self->open_count) {
76520 + if (local_read(&self->open_count)) {
76521 spin_unlock_irqrestore(&self->spinlock, flags);
76522
76523 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76524 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76525 tty->closing = 0;
76526 self->tty = NULL;
76527
76528 - if (self->blocked_open) {
76529 + if (local_read(&self->blocked_open)) {
76530 if (self->close_delay)
76531 schedule_timeout_interruptible(self->close_delay);
76532 wake_up_interruptible(&self->open_wait);
76533 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76534 spin_lock_irqsave(&self->spinlock, flags);
76535 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76536 self->tty = NULL;
76537 - self->open_count = 0;
76538 + local_set(&self->open_count, 0);
76539 spin_unlock_irqrestore(&self->spinlock, flags);
76540
76541 wake_up_interruptible(&self->open_wait);
76542 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76543 seq_putc(m, '\n');
76544
76545 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76546 - seq_printf(m, "Open count: %d\n", self->open_count);
76547 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76548 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76549 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76550
76551 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76552 index d5c5b8f..33beff0 100644
76553 --- a/net/iucv/af_iucv.c
76554 +++ b/net/iucv/af_iucv.c
76555 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76556
76557 write_lock_bh(&iucv_sk_list.lock);
76558
76559 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76560 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76561 while (__iucv_get_sock_by_name(name)) {
76562 sprintf(name, "%08x",
76563 - atomic_inc_return(&iucv_sk_list.autobind_name));
76564 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76565 }
76566
76567 write_unlock_bh(&iucv_sk_list.lock);
76568 diff --git a/net/key/af_key.c b/net/key/af_key.c
76569 index 11dbb22..c20f667 100644
76570 --- a/net/key/af_key.c
76571 +++ b/net/key/af_key.c
76572 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76573 static u32 get_acqseq(void)
76574 {
76575 u32 res;
76576 - static atomic_t acqseq;
76577 + static atomic_unchecked_t acqseq;
76578
76579 do {
76580 - res = atomic_inc_return(&acqseq);
76581 + res = atomic_inc_return_unchecked(&acqseq);
76582 } while (!res);
76583 return res;
76584 }
76585 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76586 index 2f0642d..e5c6fba 100644
76587 --- a/net/mac80211/ieee80211_i.h
76588 +++ b/net/mac80211/ieee80211_i.h
76589 @@ -28,6 +28,7 @@
76590 #include <net/ieee80211_radiotap.h>
76591 #include <net/cfg80211.h>
76592 #include <net/mac80211.h>
76593 +#include <asm/local.h>
76594 #include "key.h"
76595 #include "sta_info.h"
76596
76597 @@ -781,7 +782,7 @@ struct ieee80211_local {
76598 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76599 spinlock_t queue_stop_reason_lock;
76600
76601 - int open_count;
76602 + local_t open_count;
76603 int monitors, cooked_mntrs;
76604 /* number of interfaces with corresponding FIF_ flags */
76605 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76606 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76607 index 8e2137b..2974283 100644
76608 --- a/net/mac80211/iface.c
76609 +++ b/net/mac80211/iface.c
76610 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76611 break;
76612 }
76613
76614 - if (local->open_count == 0) {
76615 + if (local_read(&local->open_count) == 0) {
76616 res = drv_start(local);
76617 if (res)
76618 goto err_del_bss;
76619 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76620 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76621
76622 if (!is_valid_ether_addr(dev->dev_addr)) {
76623 - if (!local->open_count)
76624 + if (!local_read(&local->open_count))
76625 drv_stop(local);
76626 return -EADDRNOTAVAIL;
76627 }
76628 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76629 mutex_unlock(&local->mtx);
76630
76631 if (coming_up)
76632 - local->open_count++;
76633 + local_inc(&local->open_count);
76634
76635 if (hw_reconf_flags)
76636 ieee80211_hw_config(local, hw_reconf_flags);
76637 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76638 err_del_interface:
76639 drv_remove_interface(local, sdata);
76640 err_stop:
76641 - if (!local->open_count)
76642 + if (!local_read(&local->open_count))
76643 drv_stop(local);
76644 err_del_bss:
76645 sdata->bss = NULL;
76646 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76647 }
76648
76649 if (going_down)
76650 - local->open_count--;
76651 + local_dec(&local->open_count);
76652
76653 switch (sdata->vif.type) {
76654 case NL80211_IFTYPE_AP_VLAN:
76655 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76656
76657 ieee80211_recalc_ps(local, -1);
76658
76659 - if (local->open_count == 0) {
76660 + if (local_read(&local->open_count) == 0) {
76661 if (local->ops->napi_poll)
76662 napi_disable(&local->napi);
76663 ieee80211_clear_tx_pending(local);
76664 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76665 index b142bd4..a651749 100644
76666 --- a/net/mac80211/main.c
76667 +++ b/net/mac80211/main.c
76668 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76669 local->hw.conf.power_level = power;
76670 }
76671
76672 - if (changed && local->open_count) {
76673 + if (changed && local_read(&local->open_count)) {
76674 ret = drv_config(local, changed);
76675 /*
76676 * Goal:
76677 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76678 index 596efaf..8f1911f 100644
76679 --- a/net/mac80211/pm.c
76680 +++ b/net/mac80211/pm.c
76681 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76682 struct ieee80211_sub_if_data *sdata;
76683 struct sta_info *sta;
76684
76685 - if (!local->open_count)
76686 + if (!local_read(&local->open_count))
76687 goto suspend;
76688
76689 ieee80211_scan_cancel(local);
76690 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76691 cancel_work_sync(&local->dynamic_ps_enable_work);
76692 del_timer_sync(&local->dynamic_ps_timer);
76693
76694 - local->wowlan = wowlan && local->open_count;
76695 + local->wowlan = wowlan && local_read(&local->open_count);
76696 if (local->wowlan) {
76697 int err = drv_suspend(local, wowlan);
76698 if (err < 0) {
76699 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76700 }
76701
76702 /* stop hardware - this must stop RX */
76703 - if (local->open_count)
76704 + if (local_read(&local->open_count))
76705 ieee80211_stop_device(local);
76706
76707 suspend:
76708 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76709 index f9b8e81..bb89b46 100644
76710 --- a/net/mac80211/rate.c
76711 +++ b/net/mac80211/rate.c
76712 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76713
76714 ASSERT_RTNL();
76715
76716 - if (local->open_count)
76717 + if (local_read(&local->open_count))
76718 return -EBUSY;
76719
76720 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76721 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76722 index c97a065..ff61928 100644
76723 --- a/net/mac80211/rc80211_pid_debugfs.c
76724 +++ b/net/mac80211/rc80211_pid_debugfs.c
76725 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76726
76727 spin_unlock_irqrestore(&events->lock, status);
76728
76729 - if (copy_to_user(buf, pb, p))
76730 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76731 return -EFAULT;
76732
76733 return p;
76734 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76735 index 9919892..8c49803 100644
76736 --- a/net/mac80211/util.c
76737 +++ b/net/mac80211/util.c
76738 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76739 }
76740 #endif
76741 /* everything else happens only if HW was up & running */
76742 - if (!local->open_count)
76743 + if (!local_read(&local->open_count))
76744 goto wake_up;
76745
76746 /*
76747 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76748 index f8ac4ef..b02560b 100644
76749 --- a/net/netfilter/Kconfig
76750 +++ b/net/netfilter/Kconfig
76751 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76752
76753 To compile it as a module, choose M here. If unsure, say N.
76754
76755 +config NETFILTER_XT_MATCH_GRADM
76756 + tristate '"gradm" match support'
76757 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76758 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76759 + ---help---
76760 + The gradm match allows to match on grsecurity RBAC being enabled.
76761 + It is useful when iptables rules are applied early on bootup to
76762 + prevent connections to the machine (except from a trusted host)
76763 + while the RBAC system is disabled.
76764 +
76765 config NETFILTER_XT_MATCH_HASHLIMIT
76766 tristate '"hashlimit" match support'
76767 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76768 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76769 index 40f4c3d..0d5dd6b 100644
76770 --- a/net/netfilter/Makefile
76771 +++ b/net/netfilter/Makefile
76772 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76773 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76774 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76775 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76776 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76777 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76778 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76779 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76780 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76781 index 29fa5ba..8debc79 100644
76782 --- a/net/netfilter/ipvs/ip_vs_conn.c
76783 +++ b/net/netfilter/ipvs/ip_vs_conn.c
76784 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76785 /* Increase the refcnt counter of the dest */
76786 atomic_inc(&dest->refcnt);
76787
76788 - conn_flags = atomic_read(&dest->conn_flags);
76789 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
76790 if (cp->protocol != IPPROTO_UDP)
76791 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76792 /* Bind with the destination and its corresponding transmitter */
76793 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76794 atomic_set(&cp->refcnt, 1);
76795
76796 atomic_set(&cp->n_control, 0);
76797 - atomic_set(&cp->in_pkts, 0);
76798 + atomic_set_unchecked(&cp->in_pkts, 0);
76799
76800 atomic_inc(&ipvs->conn_count);
76801 if (flags & IP_VS_CONN_F_NO_CPORT)
76802 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76803
76804 /* Don't drop the entry if its number of incoming packets is not
76805 located in [0, 8] */
76806 - i = atomic_read(&cp->in_pkts);
76807 + i = atomic_read_unchecked(&cp->in_pkts);
76808 if (i > 8 || i < 0) return 0;
76809
76810 if (!todrop_rate[i]) return 0;
76811 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76812 index 2555816..31492d9 100644
76813 --- a/net/netfilter/ipvs/ip_vs_core.c
76814 +++ b/net/netfilter/ipvs/ip_vs_core.c
76815 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76816 ret = cp->packet_xmit(skb, cp, pd->pp);
76817 /* do not touch skb anymore */
76818
76819 - atomic_inc(&cp->in_pkts);
76820 + atomic_inc_unchecked(&cp->in_pkts);
76821 ip_vs_conn_put(cp);
76822 return ret;
76823 }
76824 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76825 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76826 pkts = sysctl_sync_threshold(ipvs);
76827 else
76828 - pkts = atomic_add_return(1, &cp->in_pkts);
76829 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76830
76831 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76832 cp->protocol == IPPROTO_SCTP) {
76833 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76834 index b3afe18..08ec940 100644
76835 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76836 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76837 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76838 ip_vs_rs_hash(ipvs, dest);
76839 write_unlock_bh(&ipvs->rs_lock);
76840 }
76841 - atomic_set(&dest->conn_flags, conn_flags);
76842 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76843
76844 /* bind the service */
76845 if (!dest->svc) {
76846 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76847 " %-7s %-6d %-10d %-10d\n",
76848 &dest->addr.in6,
76849 ntohs(dest->port),
76850 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76851 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76852 atomic_read(&dest->weight),
76853 atomic_read(&dest->activeconns),
76854 atomic_read(&dest->inactconns));
76855 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76856 "%-7s %-6d %-10d %-10d\n",
76857 ntohl(dest->addr.ip),
76858 ntohs(dest->port),
76859 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76860 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76861 atomic_read(&dest->weight),
76862 atomic_read(&dest->activeconns),
76863 atomic_read(&dest->inactconns));
76864 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76865
76866 entry.addr = dest->addr.ip;
76867 entry.port = dest->port;
76868 - entry.conn_flags = atomic_read(&dest->conn_flags);
76869 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76870 entry.weight = atomic_read(&dest->weight);
76871 entry.u_threshold = dest->u_threshold;
76872 entry.l_threshold = dest->l_threshold;
76873 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76874 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76875
76876 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76877 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76878 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76879 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76880 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76881 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76882 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76883 index 8a0d6d6..90ec197 100644
76884 --- a/net/netfilter/ipvs/ip_vs_sync.c
76885 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76886 @@ -649,7 +649,7 @@ control:
76887 * i.e only increment in_pkts for Templates.
76888 */
76889 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76890 - int pkts = atomic_add_return(1, &cp->in_pkts);
76891 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76892
76893 if (pkts % sysctl_sync_period(ipvs) != 1)
76894 return;
76895 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76896
76897 if (opt)
76898 memcpy(&cp->in_seq, opt, sizeof(*opt));
76899 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76900 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76901 cp->state = state;
76902 cp->old_state = cp->state;
76903 /*
76904 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76905 index 7fd66de..e6fb361 100644
76906 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76907 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76908 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76909 else
76910 rc = NF_ACCEPT;
76911 /* do not touch skb anymore */
76912 - atomic_inc(&cp->in_pkts);
76913 + atomic_inc_unchecked(&cp->in_pkts);
76914 goto out;
76915 }
76916
76917 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76918 else
76919 rc = NF_ACCEPT;
76920 /* do not touch skb anymore */
76921 - atomic_inc(&cp->in_pkts);
76922 + atomic_inc_unchecked(&cp->in_pkts);
76923 goto out;
76924 }
76925
76926 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76927 index 66b2c54..c7884e3 100644
76928 --- a/net/netfilter/nfnetlink_log.c
76929 +++ b/net/netfilter/nfnetlink_log.c
76930 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76931 };
76932
76933 static DEFINE_SPINLOCK(instances_lock);
76934 -static atomic_t global_seq;
76935 +static atomic_unchecked_t global_seq;
76936
76937 #define INSTANCE_BUCKETS 16
76938 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76939 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76940 /* global sequence number */
76941 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76942 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76943 - htonl(atomic_inc_return(&global_seq)));
76944 + htonl(atomic_inc_return_unchecked(&global_seq)));
76945
76946 if (data_len) {
76947 struct nlattr *nla;
76948 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76949 new file mode 100644
76950 index 0000000..6905327
76951 --- /dev/null
76952 +++ b/net/netfilter/xt_gradm.c
76953 @@ -0,0 +1,51 @@
76954 +/*
76955 + * gradm match for netfilter
76956 + * Copyright © Zbigniew Krzystolik, 2010
76957 + *
76958 + * This program is free software; you can redistribute it and/or modify
76959 + * it under the terms of the GNU General Public License; either version
76960 + * 2 or 3 as published by the Free Software Foundation.
76961 + */
76962 +#include <linux/module.h>
76963 +#include <linux/moduleparam.h>
76964 +#include <linux/skbuff.h>
76965 +#include <linux/netfilter/x_tables.h>
76966 +#include <linux/grsecurity.h>
76967 +#include <linux/netfilter/xt_gradm.h>
76968 +
76969 +static bool
76970 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76971 +{
76972 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76973 + bool retval = false;
76974 + if (gr_acl_is_enabled())
76975 + retval = true;
76976 + return retval ^ info->invflags;
76977 +}
76978 +
76979 +static struct xt_match gradm_mt_reg __read_mostly = {
76980 + .name = "gradm",
76981 + .revision = 0,
76982 + .family = NFPROTO_UNSPEC,
76983 + .match = gradm_mt,
76984 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76985 + .me = THIS_MODULE,
76986 +};
76987 +
76988 +static int __init gradm_mt_init(void)
76989 +{
76990 + return xt_register_match(&gradm_mt_reg);
76991 +}
76992 +
76993 +static void __exit gradm_mt_exit(void)
76994 +{
76995 + xt_unregister_match(&gradm_mt_reg);
76996 +}
76997 +
76998 +module_init(gradm_mt_init);
76999 +module_exit(gradm_mt_exit);
77000 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77001 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77002 +MODULE_LICENSE("GPL");
77003 +MODULE_ALIAS("ipt_gradm");
77004 +MODULE_ALIAS("ip6t_gradm");
77005 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77006 index 4fe4fb4..87a89e5 100644
77007 --- a/net/netfilter/xt_statistic.c
77008 +++ b/net/netfilter/xt_statistic.c
77009 @@ -19,7 +19,7 @@
77010 #include <linux/module.h>
77011
77012 struct xt_statistic_priv {
77013 - atomic_t count;
77014 + atomic_unchecked_t count;
77015 } ____cacheline_aligned_in_smp;
77016
77017 MODULE_LICENSE("GPL");
77018 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77019 break;
77020 case XT_STATISTIC_MODE_NTH:
77021 do {
77022 - oval = atomic_read(&info->master->count);
77023 + oval = atomic_read_unchecked(&info->master->count);
77024 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77025 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77026 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77027 if (nval == 0)
77028 ret = !ret;
77029 break;
77030 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77031 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77032 if (info->master == NULL)
77033 return -ENOMEM;
77034 - atomic_set(&info->master->count, info->u.nth.count);
77035 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77036
77037 return 0;
77038 }
77039 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77040 index 629b061..8f415cc 100644
77041 --- a/net/netlink/af_netlink.c
77042 +++ b/net/netlink/af_netlink.c
77043 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
77044 sk->sk_error_report(sk);
77045 }
77046 }
77047 - atomic_inc(&sk->sk_drops);
77048 + atomic_inc_unchecked(&sk->sk_drops);
77049 }
77050
77051 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77052 @@ -829,12 +829,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
77053 return 0;
77054 }
77055
77056 -int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
77057 +static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
77058 {
77059 int len = skb->len;
77060
77061 skb_queue_tail(&sk->sk_receive_queue, skb);
77062 sk->sk_data_ready(sk, len);
77063 + return len;
77064 +}
77065 +
77066 +int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
77067 +{
77068 + int len = __netlink_sendskb(sk, skb);
77069 +
77070 sock_put(sk);
77071 return len;
77072 }
77073 @@ -957,8 +964,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
77074 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
77075 !test_bit(0, &nlk->state)) {
77076 skb_set_owner_r(skb, sk);
77077 - skb_queue_tail(&sk->sk_receive_queue, skb);
77078 - sk->sk_data_ready(sk, skb->len);
77079 + __netlink_sendskb(sk, skb);
77080 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
77081 }
77082 return -1;
77083 @@ -1680,10 +1686,8 @@ static int netlink_dump(struct sock *sk)
77084
77085 if (sk_filter(sk, skb))
77086 kfree_skb(skb);
77087 - else {
77088 - skb_queue_tail(&sk->sk_receive_queue, skb);
77089 - sk->sk_data_ready(sk, skb->len);
77090 - }
77091 + else
77092 + __netlink_sendskb(sk, skb);
77093 return 0;
77094 }
77095
77096 @@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk)
77097
77098 if (sk_filter(sk, skb))
77099 kfree_skb(skb);
77100 - else {
77101 - skb_queue_tail(&sk->sk_receive_queue, skb);
77102 - sk->sk_data_ready(sk, skb->len);
77103 - }
77104 + else
77105 + __netlink_sendskb(sk, skb);
77106
77107 if (cb->done)
77108 cb->done(cb);
77109 @@ -1995,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77110 sk_wmem_alloc_get(s),
77111 nlk->cb,
77112 atomic_read(&s->sk_refcnt),
77113 - atomic_read(&s->sk_drops),
77114 + atomic_read_unchecked(&s->sk_drops),
77115 sock_i_ino(s)
77116 );
77117
77118 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77119 index 7dab229..212156f 100644
77120 --- a/net/netrom/af_netrom.c
77121 +++ b/net/netrom/af_netrom.c
77122 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77123 struct sock *sk = sock->sk;
77124 struct nr_sock *nr = nr_sk(sk);
77125
77126 + memset(sax, 0, sizeof(*sax));
77127 lock_sock(sk);
77128 if (peer != 0) {
77129 if (sk->sk_state != TCP_ESTABLISHED) {
77130 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77131 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77132 } else {
77133 sax->fsa_ax25.sax25_family = AF_NETROM;
77134 - sax->fsa_ax25.sax25_ndigis = 0;
77135 sax->fsa_ax25.sax25_call = nr->source_addr;
77136 *uaddr_len = sizeof(struct sockaddr_ax25);
77137 }
77138 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77139 index 2dbb32b..a1b4722 100644
77140 --- a/net/packet/af_packet.c
77141 +++ b/net/packet/af_packet.c
77142 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77143
77144 spin_lock(&sk->sk_receive_queue.lock);
77145 po->stats.tp_packets++;
77146 - skb->dropcount = atomic_read(&sk->sk_drops);
77147 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77148 __skb_queue_tail(&sk->sk_receive_queue, skb);
77149 spin_unlock(&sk->sk_receive_queue.lock);
77150 sk->sk_data_ready(sk, skb->len);
77151 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77152 drop_n_acct:
77153 spin_lock(&sk->sk_receive_queue.lock);
77154 po->stats.tp_drops++;
77155 - atomic_inc(&sk->sk_drops);
77156 + atomic_inc_unchecked(&sk->sk_drops);
77157 spin_unlock(&sk->sk_receive_queue.lock);
77158
77159 drop_n_restore:
77160 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77161 case PACKET_HDRLEN:
77162 if (len > sizeof(int))
77163 len = sizeof(int);
77164 - if (copy_from_user(&val, optval, len))
77165 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77166 return -EFAULT;
77167 switch (val) {
77168 case TPACKET_V1:
77169 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77170
77171 if (put_user(len, optlen))
77172 return -EFAULT;
77173 - if (copy_to_user(optval, data, len))
77174 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77175 return -EFAULT;
77176 return 0;
77177 }
77178 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77179 index d65f699..05aa6ce 100644
77180 --- a/net/phonet/af_phonet.c
77181 +++ b/net/phonet/af_phonet.c
77182 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77183 {
77184 struct phonet_protocol *pp;
77185
77186 - if (protocol >= PHONET_NPROTO)
77187 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77188 return NULL;
77189
77190 rcu_read_lock();
77191 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77192 {
77193 int err = 0;
77194
77195 - if (protocol >= PHONET_NPROTO)
77196 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77197 return -EINVAL;
77198
77199 err = proto_register(pp->prot, 1);
77200 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77201 index 9f60008..ae96f04 100644
77202 --- a/net/phonet/pep.c
77203 +++ b/net/phonet/pep.c
77204 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77205
77206 case PNS_PEP_CTRL_REQ:
77207 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77208 - atomic_inc(&sk->sk_drops);
77209 + atomic_inc_unchecked(&sk->sk_drops);
77210 break;
77211 }
77212 __skb_pull(skb, 4);
77213 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77214 }
77215
77216 if (pn->rx_credits == 0) {
77217 - atomic_inc(&sk->sk_drops);
77218 + atomic_inc_unchecked(&sk->sk_drops);
77219 err = -ENOBUFS;
77220 break;
77221 }
77222 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77223 }
77224
77225 if (pn->rx_credits == 0) {
77226 - atomic_inc(&sk->sk_drops);
77227 + atomic_inc_unchecked(&sk->sk_drops);
77228 err = NET_RX_DROP;
77229 break;
77230 }
77231 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77232 index 4c7eff3..59c727f 100644
77233 --- a/net/phonet/socket.c
77234 +++ b/net/phonet/socket.c
77235 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77236 pn->resource, sk->sk_state,
77237 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77238 sock_i_uid(sk), sock_i_ino(sk),
77239 - atomic_read(&sk->sk_refcnt), sk,
77240 - atomic_read(&sk->sk_drops), &len);
77241 + atomic_read(&sk->sk_refcnt),
77242 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77243 + NULL,
77244 +#else
77245 + sk,
77246 +#endif
77247 + atomic_read_unchecked(&sk->sk_drops), &len);
77248 }
77249 seq_printf(seq, "%*s\n", 127 - len, "");
77250 return 0;
77251 diff --git a/net/rds/cong.c b/net/rds/cong.c
77252 index e5b65ac..f3b6fb7 100644
77253 --- a/net/rds/cong.c
77254 +++ b/net/rds/cong.c
77255 @@ -78,7 +78,7 @@
77256 * finds that the saved generation number is smaller than the global generation
77257 * number, it wakes up the process.
77258 */
77259 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77260 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77261
77262 /*
77263 * Congestion monitoring
77264 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77265 rdsdebug("waking map %p for %pI4\n",
77266 map, &map->m_addr);
77267 rds_stats_inc(s_cong_update_received);
77268 - atomic_inc(&rds_cong_generation);
77269 + atomic_inc_unchecked(&rds_cong_generation);
77270 if (waitqueue_active(&map->m_waitq))
77271 wake_up(&map->m_waitq);
77272 if (waitqueue_active(&rds_poll_waitq))
77273 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77274
77275 int rds_cong_updated_since(unsigned long *recent)
77276 {
77277 - unsigned long gen = atomic_read(&rds_cong_generation);
77278 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77279
77280 if (likely(*recent == gen))
77281 return 0;
77282 diff --git a/net/rds/ib.h b/net/rds/ib.h
77283 index edfaaaf..8c89879 100644
77284 --- a/net/rds/ib.h
77285 +++ b/net/rds/ib.h
77286 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77287 /* sending acks */
77288 unsigned long i_ack_flags;
77289 #ifdef KERNEL_HAS_ATOMIC64
77290 - atomic64_t i_ack_next; /* next ACK to send */
77291 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77292 #else
77293 spinlock_t i_ack_lock; /* protect i_ack_next */
77294 u64 i_ack_next; /* next ACK to send */
77295 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77296 index 51c8689..36c555f 100644
77297 --- a/net/rds/ib_cm.c
77298 +++ b/net/rds/ib_cm.c
77299 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77300 /* Clear the ACK state */
77301 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77302 #ifdef KERNEL_HAS_ATOMIC64
77303 - atomic64_set(&ic->i_ack_next, 0);
77304 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77305 #else
77306 ic->i_ack_next = 0;
77307 #endif
77308 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77309 index e29e0ca..fa3a6a3 100644
77310 --- a/net/rds/ib_recv.c
77311 +++ b/net/rds/ib_recv.c
77312 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77313 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77314 int ack_required)
77315 {
77316 - atomic64_set(&ic->i_ack_next, seq);
77317 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77318 if (ack_required) {
77319 smp_mb__before_clear_bit();
77320 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77321 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77322 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77323 smp_mb__after_clear_bit();
77324
77325 - return atomic64_read(&ic->i_ack_next);
77326 + return atomic64_read_unchecked(&ic->i_ack_next);
77327 }
77328 #endif
77329
77330 diff --git a/net/rds/iw.h b/net/rds/iw.h
77331 index 04ce3b1..48119a6 100644
77332 --- a/net/rds/iw.h
77333 +++ b/net/rds/iw.h
77334 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77335 /* sending acks */
77336 unsigned long i_ack_flags;
77337 #ifdef KERNEL_HAS_ATOMIC64
77338 - atomic64_t i_ack_next; /* next ACK to send */
77339 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77340 #else
77341 spinlock_t i_ack_lock; /* protect i_ack_next */
77342 u64 i_ack_next; /* next ACK to send */
77343 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77344 index 9556d28..f046d0e 100644
77345 --- a/net/rds/iw_cm.c
77346 +++ b/net/rds/iw_cm.c
77347 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77348 /* Clear the ACK state */
77349 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77350 #ifdef KERNEL_HAS_ATOMIC64
77351 - atomic64_set(&ic->i_ack_next, 0);
77352 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77353 #else
77354 ic->i_ack_next = 0;
77355 #endif
77356 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77357 index 5e57347..3916042 100644
77358 --- a/net/rds/iw_recv.c
77359 +++ b/net/rds/iw_recv.c
77360 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77361 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77362 int ack_required)
77363 {
77364 - atomic64_set(&ic->i_ack_next, seq);
77365 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77366 if (ack_required) {
77367 smp_mb__before_clear_bit();
77368 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77369 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77370 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77371 smp_mb__after_clear_bit();
77372
77373 - return atomic64_read(&ic->i_ack_next);
77374 + return atomic64_read_unchecked(&ic->i_ack_next);
77375 }
77376 #endif
77377
77378 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77379 index edac9ef..16bcb98 100644
77380 --- a/net/rds/tcp.c
77381 +++ b/net/rds/tcp.c
77382 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77383 int val = 1;
77384
77385 set_fs(KERNEL_DS);
77386 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77387 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77388 sizeof(val));
77389 set_fs(oldfs);
77390 }
77391 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77392 index 1b4fd68..2234175 100644
77393 --- a/net/rds/tcp_send.c
77394 +++ b/net/rds/tcp_send.c
77395 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77396
77397 oldfs = get_fs();
77398 set_fs(KERNEL_DS);
77399 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77400 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77401 sizeof(val));
77402 set_fs(oldfs);
77403 }
77404 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77405 index 74c064c..fdec26f 100644
77406 --- a/net/rxrpc/af_rxrpc.c
77407 +++ b/net/rxrpc/af_rxrpc.c
77408 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77409 __be32 rxrpc_epoch;
77410
77411 /* current debugging ID */
77412 -atomic_t rxrpc_debug_id;
77413 +atomic_unchecked_t rxrpc_debug_id;
77414
77415 /* count of skbs currently in use */
77416 atomic_t rxrpc_n_skbs;
77417 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77418 index c3126e8..21facc7 100644
77419 --- a/net/rxrpc/ar-ack.c
77420 +++ b/net/rxrpc/ar-ack.c
77421 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77422
77423 _enter("{%d,%d,%d,%d},",
77424 call->acks_hard, call->acks_unacked,
77425 - atomic_read(&call->sequence),
77426 + atomic_read_unchecked(&call->sequence),
77427 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77428
77429 stop = 0;
77430 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77431
77432 /* each Tx packet has a new serial number */
77433 sp->hdr.serial =
77434 - htonl(atomic_inc_return(&call->conn->serial));
77435 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77436
77437 hdr = (struct rxrpc_header *) txb->head;
77438 hdr->serial = sp->hdr.serial;
77439 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77440 */
77441 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77442 {
77443 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77444 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77445 }
77446
77447 /*
77448 @@ -629,7 +629,7 @@ process_further:
77449
77450 latest = ntohl(sp->hdr.serial);
77451 hard = ntohl(ack.firstPacket);
77452 - tx = atomic_read(&call->sequence);
77453 + tx = atomic_read_unchecked(&call->sequence);
77454
77455 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77456 latest,
77457 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77458 goto maybe_reschedule;
77459
77460 send_ACK_with_skew:
77461 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77462 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77463 ntohl(ack.serial));
77464 send_ACK:
77465 mtu = call->conn->trans->peer->if_mtu;
77466 @@ -1173,7 +1173,7 @@ send_ACK:
77467 ackinfo.rxMTU = htonl(5692);
77468 ackinfo.jumbo_max = htonl(4);
77469
77470 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77471 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77472 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77473 ntohl(hdr.serial),
77474 ntohs(ack.maxSkew),
77475 @@ -1191,7 +1191,7 @@ send_ACK:
77476 send_message:
77477 _debug("send message");
77478
77479 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77480 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77481 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77482 send_message_2:
77483
77484 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77485 index bf656c2..48f9d27 100644
77486 --- a/net/rxrpc/ar-call.c
77487 +++ b/net/rxrpc/ar-call.c
77488 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77489 spin_lock_init(&call->lock);
77490 rwlock_init(&call->state_lock);
77491 atomic_set(&call->usage, 1);
77492 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77493 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77494 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77495
77496 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77497 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77498 index 4106ca9..a338d7a 100644
77499 --- a/net/rxrpc/ar-connection.c
77500 +++ b/net/rxrpc/ar-connection.c
77501 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77502 rwlock_init(&conn->lock);
77503 spin_lock_init(&conn->state_lock);
77504 atomic_set(&conn->usage, 1);
77505 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77506 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77507 conn->avail_calls = RXRPC_MAXCALLS;
77508 conn->size_align = 4;
77509 conn->header_size = sizeof(struct rxrpc_header);
77510 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77511 index e7ed43a..6afa140 100644
77512 --- a/net/rxrpc/ar-connevent.c
77513 +++ b/net/rxrpc/ar-connevent.c
77514 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77515
77516 len = iov[0].iov_len + iov[1].iov_len;
77517
77518 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77519 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77520 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77521
77522 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77523 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77524 index 1a2b0633..e8d1382 100644
77525 --- a/net/rxrpc/ar-input.c
77526 +++ b/net/rxrpc/ar-input.c
77527 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77528 /* track the latest serial number on this connection for ACK packet
77529 * information */
77530 serial = ntohl(sp->hdr.serial);
77531 - hi_serial = atomic_read(&call->conn->hi_serial);
77532 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77533 while (serial > hi_serial)
77534 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77535 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77536 serial);
77537
77538 /* request ACK generation for any ACK or DATA packet that requests
77539 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77540 index 8e22bd3..f66d1c0 100644
77541 --- a/net/rxrpc/ar-internal.h
77542 +++ b/net/rxrpc/ar-internal.h
77543 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77544 int error; /* error code for local abort */
77545 int debug_id; /* debug ID for printks */
77546 unsigned call_counter; /* call ID counter */
77547 - atomic_t serial; /* packet serial number counter */
77548 - atomic_t hi_serial; /* highest serial number received */
77549 + atomic_unchecked_t serial; /* packet serial number counter */
77550 + atomic_unchecked_t hi_serial; /* highest serial number received */
77551 u8 avail_calls; /* number of calls available */
77552 u8 size_align; /* data size alignment (for security) */
77553 u8 header_size; /* rxrpc + security header size */
77554 @@ -346,7 +346,7 @@ struct rxrpc_call {
77555 spinlock_t lock;
77556 rwlock_t state_lock; /* lock for state transition */
77557 atomic_t usage;
77558 - atomic_t sequence; /* Tx data packet sequence counter */
77559 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77560 u32 abort_code; /* local/remote abort code */
77561 enum { /* current state of call */
77562 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77563 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77564 */
77565 extern atomic_t rxrpc_n_skbs;
77566 extern __be32 rxrpc_epoch;
77567 -extern atomic_t rxrpc_debug_id;
77568 +extern atomic_unchecked_t rxrpc_debug_id;
77569 extern struct workqueue_struct *rxrpc_workqueue;
77570
77571 /*
77572 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77573 index 87f7135..74d3703 100644
77574 --- a/net/rxrpc/ar-local.c
77575 +++ b/net/rxrpc/ar-local.c
77576 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77577 spin_lock_init(&local->lock);
77578 rwlock_init(&local->services_lock);
77579 atomic_set(&local->usage, 1);
77580 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77581 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77582 memcpy(&local->srx, srx, sizeof(*srx));
77583 }
77584
77585 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77586 index 16ae887..d24f12b 100644
77587 --- a/net/rxrpc/ar-output.c
77588 +++ b/net/rxrpc/ar-output.c
77589 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77590 sp->hdr.cid = call->cid;
77591 sp->hdr.callNumber = call->call_id;
77592 sp->hdr.seq =
77593 - htonl(atomic_inc_return(&call->sequence));
77594 + htonl(atomic_inc_return_unchecked(&call->sequence));
77595 sp->hdr.serial =
77596 - htonl(atomic_inc_return(&conn->serial));
77597 + htonl(atomic_inc_return_unchecked(&conn->serial));
77598 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77599 sp->hdr.userStatus = 0;
77600 sp->hdr.securityIndex = conn->security_ix;
77601 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77602 index 2754f09..b20e38f 100644
77603 --- a/net/rxrpc/ar-peer.c
77604 +++ b/net/rxrpc/ar-peer.c
77605 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77606 INIT_LIST_HEAD(&peer->error_targets);
77607 spin_lock_init(&peer->lock);
77608 atomic_set(&peer->usage, 1);
77609 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77610 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77611 memcpy(&peer->srx, srx, sizeof(*srx));
77612
77613 rxrpc_assess_MTU_size(peer);
77614 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77615 index 38047f7..9f48511 100644
77616 --- a/net/rxrpc/ar-proc.c
77617 +++ b/net/rxrpc/ar-proc.c
77618 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77619 atomic_read(&conn->usage),
77620 rxrpc_conn_states[conn->state],
77621 key_serial(conn->key),
77622 - atomic_read(&conn->serial),
77623 - atomic_read(&conn->hi_serial));
77624 + atomic_read_unchecked(&conn->serial),
77625 + atomic_read_unchecked(&conn->hi_serial));
77626
77627 return 0;
77628 }
77629 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77630 index 92df566..87ec1bf 100644
77631 --- a/net/rxrpc/ar-transport.c
77632 +++ b/net/rxrpc/ar-transport.c
77633 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77634 spin_lock_init(&trans->client_lock);
77635 rwlock_init(&trans->conn_lock);
77636 atomic_set(&trans->usage, 1);
77637 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77638 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77639
77640 if (peer->srx.transport.family == AF_INET) {
77641 switch (peer->srx.transport_type) {
77642 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77643 index 7635107..4670276 100644
77644 --- a/net/rxrpc/rxkad.c
77645 +++ b/net/rxrpc/rxkad.c
77646 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77647
77648 len = iov[0].iov_len + iov[1].iov_len;
77649
77650 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77651 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77652 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77653
77654 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77655 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77656
77657 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77658
77659 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77660 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77661 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77662
77663 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77664 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77665 index 1e2eee8..ce3967e 100644
77666 --- a/net/sctp/proc.c
77667 +++ b/net/sctp/proc.c
77668 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77669 seq_printf(seq,
77670 "%8pK %8pK %-3d %-3d %-2d %-4d "
77671 "%4d %8d %8d %7d %5lu %-5d %5d ",
77672 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77673 + assoc, sk,
77674 + sctp_sk(sk)->type, sk->sk_state,
77675 assoc->state, hash,
77676 assoc->assoc_id,
77677 assoc->sndbuf_used,
77678 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77679 index 408ebd0..202aa85 100644
77680 --- a/net/sctp/socket.c
77681 +++ b/net/sctp/socket.c
77682 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77683 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77684 if (space_left < addrlen)
77685 return -ENOMEM;
77686 - if (copy_to_user(to, &temp, addrlen))
77687 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77688 return -EFAULT;
77689 to += addrlen;
77690 cnt++;
77691 diff --git a/net/socket.c b/net/socket.c
77692 index 28a96af..61a7a06 100644
77693 --- a/net/socket.c
77694 +++ b/net/socket.c
77695 @@ -88,6 +88,7 @@
77696 #include <linux/nsproxy.h>
77697 #include <linux/magic.h>
77698 #include <linux/slab.h>
77699 +#include <linux/in.h>
77700
77701 #include <asm/uaccess.h>
77702 #include <asm/unistd.h>
77703 @@ -105,6 +106,8 @@
77704 #include <linux/sockios.h>
77705 #include <linux/atalk.h>
77706
77707 +#include <linux/grsock.h>
77708 +
77709 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77710 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77711 unsigned long nr_segs, loff_t pos);
77712 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77713 &sockfs_dentry_operations, SOCKFS_MAGIC);
77714 }
77715
77716 -static struct vfsmount *sock_mnt __read_mostly;
77717 +struct vfsmount *sock_mnt __read_mostly;
77718
77719 static struct file_system_type sock_fs_type = {
77720 .name = "sockfs",
77721 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77722 return -EAFNOSUPPORT;
77723 if (type < 0 || type >= SOCK_MAX)
77724 return -EINVAL;
77725 + if (protocol < 0)
77726 + return -EINVAL;
77727
77728 /* Compatibility.
77729
77730 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77731 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77732 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77733
77734 + if(!gr_search_socket(family, type, protocol)) {
77735 + retval = -EACCES;
77736 + goto out;
77737 + }
77738 +
77739 + if (gr_handle_sock_all(family, type, protocol)) {
77740 + retval = -EACCES;
77741 + goto out;
77742 + }
77743 +
77744 retval = sock_create(family, type, protocol, &sock);
77745 if (retval < 0)
77746 goto out;
77747 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77748 if (sock) {
77749 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
77750 if (err >= 0) {
77751 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77752 + err = -EACCES;
77753 + goto error;
77754 + }
77755 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77756 + if (err)
77757 + goto error;
77758 +
77759 err = security_socket_bind(sock,
77760 (struct sockaddr *)&address,
77761 addrlen);
77762 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77763 (struct sockaddr *)
77764 &address, addrlen);
77765 }
77766 +error:
77767 fput_light(sock->file, fput_needed);
77768 }
77769 return err;
77770 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77771 if ((unsigned)backlog > somaxconn)
77772 backlog = somaxconn;
77773
77774 + if (gr_handle_sock_server_other(sock->sk)) {
77775 + err = -EPERM;
77776 + goto error;
77777 + }
77778 +
77779 + err = gr_search_listen(sock);
77780 + if (err)
77781 + goto error;
77782 +
77783 err = security_socket_listen(sock, backlog);
77784 if (!err)
77785 err = sock->ops->listen(sock, backlog);
77786
77787 +error:
77788 fput_light(sock->file, fput_needed);
77789 }
77790 return err;
77791 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77792 newsock->type = sock->type;
77793 newsock->ops = sock->ops;
77794
77795 + if (gr_handle_sock_server_other(sock->sk)) {
77796 + err = -EPERM;
77797 + sock_release(newsock);
77798 + goto out_put;
77799 + }
77800 +
77801 + err = gr_search_accept(sock);
77802 + if (err) {
77803 + sock_release(newsock);
77804 + goto out_put;
77805 + }
77806 +
77807 /*
77808 * We don't need try_module_get here, as the listening socket (sock)
77809 * has the protocol module (sock->ops->owner) held.
77810 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77811 fd_install(newfd, newfile);
77812 err = newfd;
77813
77814 + gr_attach_curr_ip(newsock->sk);
77815 +
77816 out_put:
77817 fput_light(sock->file, fput_needed);
77818 out:
77819 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77820 int, addrlen)
77821 {
77822 struct socket *sock;
77823 + struct sockaddr *sck;
77824 struct sockaddr_storage address;
77825 int err, fput_needed;
77826
77827 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77828 if (err < 0)
77829 goto out_put;
77830
77831 + sck = (struct sockaddr *)&address;
77832 +
77833 + if (gr_handle_sock_client(sck)) {
77834 + err = -EACCES;
77835 + goto out_put;
77836 + }
77837 +
77838 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77839 + if (err)
77840 + goto out_put;
77841 +
77842 err =
77843 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77844 if (err)
77845 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77846 * checking falls down on this.
77847 */
77848 if (copy_from_user(ctl_buf,
77849 - (void __user __force *)msg_sys->msg_control,
77850 + (void __force_user *)msg_sys->msg_control,
77851 ctl_len))
77852 goto out_freectl;
77853 msg_sys->msg_control = ctl_buf;
77854 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77855 * kernel msghdr to use the kernel address space)
77856 */
77857
77858 - uaddr = (__force void __user *)msg_sys->msg_name;
77859 + uaddr = (void __force_user *)msg_sys->msg_name;
77860 uaddr_len = COMPAT_NAMELEN(msg);
77861 if (MSG_CMSG_COMPAT & flags) {
77862 err = verify_compat_iovec(msg_sys, iov,
77863 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77864 }
77865
77866 ifr = compat_alloc_user_space(buf_size);
77867 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77868 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77869
77870 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77871 return -EFAULT;
77872 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77873 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77874
77875 if (copy_in_user(rxnfc, compat_rxnfc,
77876 - (void *)(&rxnfc->fs.m_ext + 1) -
77877 - (void *)rxnfc) ||
77878 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77879 + (void __user *)rxnfc) ||
77880 copy_in_user(&rxnfc->fs.ring_cookie,
77881 &compat_rxnfc->fs.ring_cookie,
77882 - (void *)(&rxnfc->fs.location + 1) -
77883 - (void *)&rxnfc->fs.ring_cookie) ||
77884 + (void __user *)(&rxnfc->fs.location + 1) -
77885 + (void __user *)&rxnfc->fs.ring_cookie) ||
77886 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77887 sizeof(rxnfc->rule_cnt)))
77888 return -EFAULT;
77889 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77890
77891 if (convert_out) {
77892 if (copy_in_user(compat_rxnfc, rxnfc,
77893 - (const void *)(&rxnfc->fs.m_ext + 1) -
77894 - (const void *)rxnfc) ||
77895 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77896 + (const void __user *)rxnfc) ||
77897 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77898 &rxnfc->fs.ring_cookie,
77899 - (const void *)(&rxnfc->fs.location + 1) -
77900 - (const void *)&rxnfc->fs.ring_cookie) ||
77901 + (const void __user *)(&rxnfc->fs.location + 1) -
77902 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77903 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77904 sizeof(rxnfc->rule_cnt)))
77905 return -EFAULT;
77906 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77907 old_fs = get_fs();
77908 set_fs(KERNEL_DS);
77909 err = dev_ioctl(net, cmd,
77910 - (struct ifreq __user __force *) &kifr);
77911 + (struct ifreq __force_user *) &kifr);
77912 set_fs(old_fs);
77913
77914 return err;
77915 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77916
77917 old_fs = get_fs();
77918 set_fs(KERNEL_DS);
77919 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77920 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77921 set_fs(old_fs);
77922
77923 if (cmd == SIOCGIFMAP && !err) {
77924 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77925 ret |= __get_user(rtdev, &(ur4->rt_dev));
77926 if (rtdev) {
77927 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77928 - r4.rt_dev = (char __user __force *)devname;
77929 + r4.rt_dev = (char __force_user *)devname;
77930 devname[15] = 0;
77931 } else
77932 r4.rt_dev = NULL;
77933 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77934 int __user *uoptlen;
77935 int err;
77936
77937 - uoptval = (char __user __force *) optval;
77938 - uoptlen = (int __user __force *) optlen;
77939 + uoptval = (char __force_user *) optval;
77940 + uoptlen = (int __force_user *) optlen;
77941
77942 set_fs(KERNEL_DS);
77943 if (level == SOL_SOCKET)
77944 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77945 char __user *uoptval;
77946 int err;
77947
77948 - uoptval = (char __user __force *) optval;
77949 + uoptval = (char __force_user *) optval;
77950
77951 set_fs(KERNEL_DS);
77952 if (level == SOL_SOCKET)
77953 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77954 index 8efd96c..b492ab2 100644
77955 --- a/net/sunrpc/sched.c
77956 +++ b/net/sunrpc/sched.c
77957 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
77958 #ifdef RPC_DEBUG
77959 static void rpc_task_set_debuginfo(struct rpc_task *task)
77960 {
77961 - static atomic_t rpc_pid;
77962 + static atomic_unchecked_t rpc_pid;
77963
77964 - task->tk_pid = atomic_inc_return(&rpc_pid);
77965 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77966 }
77967 #else
77968 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77969 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77970 index 4645709..d41d668 100644
77971 --- a/net/sunrpc/svcsock.c
77972 +++ b/net/sunrpc/svcsock.c
77973 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77974 int buflen, unsigned int base)
77975 {
77976 size_t save_iovlen;
77977 - void __user *save_iovbase;
77978 + void *save_iovbase;
77979 unsigned int i;
77980 int ret;
77981
77982 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77983 index 09af4fa..77110a9 100644
77984 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77985 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77986 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77987 static unsigned int min_max_inline = 4096;
77988 static unsigned int max_max_inline = 65536;
77989
77990 -atomic_t rdma_stat_recv;
77991 -atomic_t rdma_stat_read;
77992 -atomic_t rdma_stat_write;
77993 -atomic_t rdma_stat_sq_starve;
77994 -atomic_t rdma_stat_rq_starve;
77995 -atomic_t rdma_stat_rq_poll;
77996 -atomic_t rdma_stat_rq_prod;
77997 -atomic_t rdma_stat_sq_poll;
77998 -atomic_t rdma_stat_sq_prod;
77999 +atomic_unchecked_t rdma_stat_recv;
78000 +atomic_unchecked_t rdma_stat_read;
78001 +atomic_unchecked_t rdma_stat_write;
78002 +atomic_unchecked_t rdma_stat_sq_starve;
78003 +atomic_unchecked_t rdma_stat_rq_starve;
78004 +atomic_unchecked_t rdma_stat_rq_poll;
78005 +atomic_unchecked_t rdma_stat_rq_prod;
78006 +atomic_unchecked_t rdma_stat_sq_poll;
78007 +atomic_unchecked_t rdma_stat_sq_prod;
78008
78009 /* Temporary NFS request map and context caches */
78010 struct kmem_cache *svc_rdma_map_cachep;
78011 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
78012 len -= *ppos;
78013 if (len > *lenp)
78014 len = *lenp;
78015 - if (len && copy_to_user(buffer, str_buf, len))
78016 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78017 return -EFAULT;
78018 *lenp = len;
78019 *ppos += len;
78020 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
78021 {
78022 .procname = "rdma_stat_read",
78023 .data = &rdma_stat_read,
78024 - .maxlen = sizeof(atomic_t),
78025 + .maxlen = sizeof(atomic_unchecked_t),
78026 .mode = 0644,
78027 .proc_handler = read_reset_stat,
78028 },
78029 {
78030 .procname = "rdma_stat_recv",
78031 .data = &rdma_stat_recv,
78032 - .maxlen = sizeof(atomic_t),
78033 + .maxlen = sizeof(atomic_unchecked_t),
78034 .mode = 0644,
78035 .proc_handler = read_reset_stat,
78036 },
78037 {
78038 .procname = "rdma_stat_write",
78039 .data = &rdma_stat_write,
78040 - .maxlen = sizeof(atomic_t),
78041 + .maxlen = sizeof(atomic_unchecked_t),
78042 .mode = 0644,
78043 .proc_handler = read_reset_stat,
78044 },
78045 {
78046 .procname = "rdma_stat_sq_starve",
78047 .data = &rdma_stat_sq_starve,
78048 - .maxlen = sizeof(atomic_t),
78049 + .maxlen = sizeof(atomic_unchecked_t),
78050 .mode = 0644,
78051 .proc_handler = read_reset_stat,
78052 },
78053 {
78054 .procname = "rdma_stat_rq_starve",
78055 .data = &rdma_stat_rq_starve,
78056 - .maxlen = sizeof(atomic_t),
78057 + .maxlen = sizeof(atomic_unchecked_t),
78058 .mode = 0644,
78059 .proc_handler = read_reset_stat,
78060 },
78061 {
78062 .procname = "rdma_stat_rq_poll",
78063 .data = &rdma_stat_rq_poll,
78064 - .maxlen = sizeof(atomic_t),
78065 + .maxlen = sizeof(atomic_unchecked_t),
78066 .mode = 0644,
78067 .proc_handler = read_reset_stat,
78068 },
78069 {
78070 .procname = "rdma_stat_rq_prod",
78071 .data = &rdma_stat_rq_prod,
78072 - .maxlen = sizeof(atomic_t),
78073 + .maxlen = sizeof(atomic_unchecked_t),
78074 .mode = 0644,
78075 .proc_handler = read_reset_stat,
78076 },
78077 {
78078 .procname = "rdma_stat_sq_poll",
78079 .data = &rdma_stat_sq_poll,
78080 - .maxlen = sizeof(atomic_t),
78081 + .maxlen = sizeof(atomic_unchecked_t),
78082 .mode = 0644,
78083 .proc_handler = read_reset_stat,
78084 },
78085 {
78086 .procname = "rdma_stat_sq_prod",
78087 .data = &rdma_stat_sq_prod,
78088 - .maxlen = sizeof(atomic_t),
78089 + .maxlen = sizeof(atomic_unchecked_t),
78090 .mode = 0644,
78091 .proc_handler = read_reset_stat,
78092 },
78093 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78094 index df67211..c354b13 100644
78095 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78096 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78097 @@ -499,7 +499,7 @@ next_sge:
78098 svc_rdma_put_context(ctxt, 0);
78099 goto out;
78100 }
78101 - atomic_inc(&rdma_stat_read);
78102 + atomic_inc_unchecked(&rdma_stat_read);
78103
78104 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78105 chl_map->ch[ch_no].count -= read_wr.num_sge;
78106 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78107 dto_q);
78108 list_del_init(&ctxt->dto_q);
78109 } else {
78110 - atomic_inc(&rdma_stat_rq_starve);
78111 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78112 clear_bit(XPT_DATA, &xprt->xpt_flags);
78113 ctxt = NULL;
78114 }
78115 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78116 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78117 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78118 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78119 - atomic_inc(&rdma_stat_recv);
78120 + atomic_inc_unchecked(&rdma_stat_recv);
78121
78122 /* Build up the XDR from the receive buffers. */
78123 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78124 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78125 index 249a835..fb2794b 100644
78126 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78127 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78128 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78129 write_wr.wr.rdma.remote_addr = to;
78130
78131 /* Post It */
78132 - atomic_inc(&rdma_stat_write);
78133 + atomic_inc_unchecked(&rdma_stat_write);
78134 if (svc_rdma_send(xprt, &write_wr))
78135 goto err;
78136 return 0;
78137 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78138 index 894cb42..cf5bafb 100644
78139 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78140 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78141 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78142 return;
78143
78144 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78145 - atomic_inc(&rdma_stat_rq_poll);
78146 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78147
78148 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78149 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78150 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78151 }
78152
78153 if (ctxt)
78154 - atomic_inc(&rdma_stat_rq_prod);
78155 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78156
78157 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78158 /*
78159 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78160 return;
78161
78162 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78163 - atomic_inc(&rdma_stat_sq_poll);
78164 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78165 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78166 if (wc.status != IB_WC_SUCCESS)
78167 /* Close the transport */
78168 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78169 }
78170
78171 if (ctxt)
78172 - atomic_inc(&rdma_stat_sq_prod);
78173 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78174 }
78175
78176 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78177 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78178 spin_lock_bh(&xprt->sc_lock);
78179 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78180 spin_unlock_bh(&xprt->sc_lock);
78181 - atomic_inc(&rdma_stat_sq_starve);
78182 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78183
78184 /* See if we can opportunistically reap SQ WR to make room */
78185 sq_cq_reap(xprt);
78186 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78187 index e758139..d29ea47 100644
78188 --- a/net/sysctl_net.c
78189 +++ b/net/sysctl_net.c
78190 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78191 struct ctl_table *table)
78192 {
78193 /* Allow network administrator to have same access as root. */
78194 - if (capable(CAP_NET_ADMIN)) {
78195 + if (capable_nolog(CAP_NET_ADMIN)) {
78196 int mode = (table->mode >> 6) & 7;
78197 return (mode << 6) | (mode << 3) | mode;
78198 }
78199 diff --git a/net/tipc/link.c b/net/tipc/link.c
78200 index ac1832a..533ed97 100644
78201 --- a/net/tipc/link.c
78202 +++ b/net/tipc/link.c
78203 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78204 struct tipc_msg fragm_hdr;
78205 struct sk_buff *buf, *buf_chain, *prev;
78206 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78207 - const unchar *sect_crs;
78208 + const unchar __user *sect_crs;
78209 int curr_sect;
78210 u32 fragm_no;
78211
78212 @@ -1249,7 +1249,7 @@ again:
78213
78214 if (!sect_rest) {
78215 sect_rest = msg_sect[++curr_sect].iov_len;
78216 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78217 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78218 }
78219
78220 if (sect_rest < fragm_rest)
78221 @@ -1268,7 +1268,7 @@ error:
78222 }
78223 } else
78224 skb_copy_to_linear_data_offset(buf, fragm_crs,
78225 - sect_crs, sz);
78226 + (const void __force_kernel *)sect_crs, sz);
78227 sect_crs += sz;
78228 sect_rest -= sz;
78229 fragm_crs += sz;
78230 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78231 index 3e4d3e2..27b55dc 100644
78232 --- a/net/tipc/msg.c
78233 +++ b/net/tipc/msg.c
78234 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78235 msg_sect[cnt].iov_len);
78236 else
78237 skb_copy_to_linear_data_offset(*buf, pos,
78238 - msg_sect[cnt].iov_base,
78239 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78240 msg_sect[cnt].iov_len);
78241 pos += msg_sect[cnt].iov_len;
78242 }
78243 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78244 index 8c49566..14510cb 100644
78245 --- a/net/tipc/subscr.c
78246 +++ b/net/tipc/subscr.c
78247 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78248 {
78249 struct iovec msg_sect;
78250
78251 - msg_sect.iov_base = (void *)&sub->evt;
78252 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78253 msg_sect.iov_len = sizeof(struct tipc_event);
78254
78255 sub->evt.event = htohl(event, sub->swap);
78256 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78257 index 85d3bb7..79f4487 100644
78258 --- a/net/unix/af_unix.c
78259 +++ b/net/unix/af_unix.c
78260 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78261 err = -ECONNREFUSED;
78262 if (!S_ISSOCK(inode->i_mode))
78263 goto put_fail;
78264 +
78265 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78266 + err = -EACCES;
78267 + goto put_fail;
78268 + }
78269 +
78270 u = unix_find_socket_byinode(inode);
78271 if (!u)
78272 goto put_fail;
78273 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78274 if (u) {
78275 struct dentry *dentry;
78276 dentry = unix_sk(u)->dentry;
78277 +
78278 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78279 + err = -EPERM;
78280 + sock_put(u);
78281 + goto fail;
78282 + }
78283 +
78284 if (dentry)
78285 touch_atime(unix_sk(u)->mnt, dentry);
78286 } else
78287 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78288 err = security_path_mknod(&path, dentry, mode, 0);
78289 if (err)
78290 goto out_mknod_drop_write;
78291 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78292 + err = -EACCES;
78293 + goto out_mknod_drop_write;
78294 + }
78295 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78296 out_mknod_drop_write:
78297 mnt_drop_write(path.mnt);
78298 if (err)
78299 goto out_mknod_dput;
78300 +
78301 + gr_handle_create(dentry, path.mnt);
78302 +
78303 mutex_unlock(&path.dentry->d_inode->i_mutex);
78304 dput(path.dentry);
78305 path.dentry = dentry;
78306 diff --git a/net/wireless/core.h b/net/wireless/core.h
78307 index 43ad9c8..ab5127c 100644
78308 --- a/net/wireless/core.h
78309 +++ b/net/wireless/core.h
78310 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78311 struct mutex mtx;
78312
78313 /* rfkill support */
78314 - struct rfkill_ops rfkill_ops;
78315 + rfkill_ops_no_const rfkill_ops;
78316 struct rfkill *rfkill;
78317 struct work_struct rfkill_sync;
78318
78319 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78320 index 0af7f54..c916d2f 100644
78321 --- a/net/wireless/wext-core.c
78322 +++ b/net/wireless/wext-core.c
78323 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78324 */
78325
78326 /* Support for very large requests */
78327 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78328 - (user_length > descr->max_tokens)) {
78329 + if (user_length > descr->max_tokens) {
78330 /* Allow userspace to GET more than max so
78331 * we can support any size GET requests.
78332 * There is still a limit : -ENOMEM.
78333 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78334 }
78335 }
78336
78337 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78338 - /*
78339 - * If this is a GET, but not NOMAX, it means that the extra
78340 - * data is not bounded by userspace, but by max_tokens. Thus
78341 - * set the length to max_tokens. This matches the extra data
78342 - * allocation.
78343 - * The driver should fill it with the number of tokens it
78344 - * provided, and it may check iwp->length rather than having
78345 - * knowledge of max_tokens. If the driver doesn't change the
78346 - * iwp->length, this ioctl just copies back max_token tokens
78347 - * filled with zeroes. Hopefully the driver isn't claiming
78348 - * them to be valid data.
78349 - */
78350 - iwp->length = descr->max_tokens;
78351 - }
78352 -
78353 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78354
78355 iwp->length += essid_compat;
78356 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78357 index 7661576..80f7627 100644
78358 --- a/net/xfrm/xfrm_policy.c
78359 +++ b/net/xfrm/xfrm_policy.c
78360 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78361 {
78362 policy->walk.dead = 1;
78363
78364 - atomic_inc(&policy->genid);
78365 + atomic_inc_unchecked(&policy->genid);
78366
78367 if (del_timer(&policy->timer))
78368 xfrm_pol_put(policy);
78369 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78370 hlist_add_head(&policy->bydst, chain);
78371 xfrm_pol_hold(policy);
78372 net->xfrm.policy_count[dir]++;
78373 - atomic_inc(&flow_cache_genid);
78374 + atomic_inc_unchecked(&flow_cache_genid);
78375 if (delpol)
78376 __xfrm_policy_unlink(delpol, dir);
78377 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78378 @@ -1530,7 +1530,7 @@ free_dst:
78379 goto out;
78380 }
78381
78382 -static int inline
78383 +static inline int
78384 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78385 {
78386 if (!*target) {
78387 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78388 return 0;
78389 }
78390
78391 -static int inline
78392 +static inline int
78393 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78394 {
78395 #ifdef CONFIG_XFRM_SUB_POLICY
78396 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78397 #endif
78398 }
78399
78400 -static int inline
78401 +static inline int
78402 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78403 {
78404 #ifdef CONFIG_XFRM_SUB_POLICY
78405 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78406
78407 xdst->num_pols = num_pols;
78408 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78409 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78410 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78411
78412 return xdst;
78413 }
78414 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78415 if (xdst->xfrm_genid != dst->xfrm->genid)
78416 return 0;
78417 if (xdst->num_pols > 0 &&
78418 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78419 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78420 return 0;
78421
78422 mtu = dst_mtu(dst->child);
78423 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78424 sizeof(pol->xfrm_vec[i].saddr));
78425 pol->xfrm_vec[i].encap_family = mp->new_family;
78426 /* flush bundles */
78427 - atomic_inc(&pol->genid);
78428 + atomic_inc_unchecked(&pol->genid);
78429 }
78430 }
78431
78432 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78433 index d2b366c..51ff91ebc 100644
78434 --- a/scripts/Makefile.build
78435 +++ b/scripts/Makefile.build
78436 @@ -109,7 +109,7 @@ endif
78437 endif
78438
78439 # Do not include host rules unless needed
78440 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78441 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78442 include scripts/Makefile.host
78443 endif
78444
78445 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78446 index 686cb0d..9d653bf 100644
78447 --- a/scripts/Makefile.clean
78448 +++ b/scripts/Makefile.clean
78449 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78450 __clean-files := $(extra-y) $(always) \
78451 $(targets) $(clean-files) \
78452 $(host-progs) \
78453 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78454 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78455 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78456
78457 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78458
78459 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78460 index 1ac414f..a1c1451 100644
78461 --- a/scripts/Makefile.host
78462 +++ b/scripts/Makefile.host
78463 @@ -31,6 +31,7 @@
78464 # Note: Shared libraries consisting of C++ files are not supported
78465
78466 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78467 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78468
78469 # C code
78470 # Executables compiled from a single .c file
78471 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78472 # Shared libaries (only .c supported)
78473 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78474 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78475 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78476 # Remove .so files from "xxx-objs"
78477 host-cobjs := $(filter-out %.so,$(host-cobjs))
78478
78479 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78480 index cb1f50c..cef2a7c 100644
78481 --- a/scripts/basic/fixdep.c
78482 +++ b/scripts/basic/fixdep.c
78483 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78484 /*
78485 * Lookup a value in the configuration string.
78486 */
78487 -static int is_defined_config(const char *name, int len, unsigned int hash)
78488 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78489 {
78490 struct item *aux;
78491
78492 @@ -211,10 +211,10 @@ static void clear_config(void)
78493 /*
78494 * Record the use of a CONFIG_* word.
78495 */
78496 -static void use_config(const char *m, int slen)
78497 +static void use_config(const char *m, unsigned int slen)
78498 {
78499 unsigned int hash = strhash(m, slen);
78500 - int c, i;
78501 + unsigned int c, i;
78502
78503 if (is_defined_config(m, slen, hash))
78504 return;
78505 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78506
78507 static void parse_config_file(const char *map, size_t len)
78508 {
78509 - const int *end = (const int *) (map + len);
78510 + const unsigned int *end = (const unsigned int *) (map + len);
78511 /* start at +1, so that p can never be < map */
78512 - const int *m = (const int *) map + 1;
78513 + const unsigned int *m = (const unsigned int *) map + 1;
78514 const char *p, *q;
78515
78516 for (; m < end; m++) {
78517 @@ -406,7 +406,7 @@ static void print_deps(void)
78518 static void traps(void)
78519 {
78520 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78521 - int *p = (int *)test;
78522 + unsigned int *p = (unsigned int *)test;
78523
78524 if (*p != INT_CONF) {
78525 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78526 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78527 new file mode 100644
78528 index 0000000..8729101
78529 --- /dev/null
78530 +++ b/scripts/gcc-plugin.sh
78531 @@ -0,0 +1,2 @@
78532 +#!/bin/sh
78533 +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"
78534 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78535 index b89efe6..2c30808 100644
78536 --- a/scripts/mod/file2alias.c
78537 +++ b/scripts/mod/file2alias.c
78538 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78539 unsigned long size, unsigned long id_size,
78540 void *symval)
78541 {
78542 - int i;
78543 + unsigned int i;
78544
78545 if (size % id_size || size < id_size) {
78546 if (cross_build != 0)
78547 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78548 /* USB is special because the bcdDevice can be matched against a numeric range */
78549 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78550 static void do_usb_entry(struct usb_device_id *id,
78551 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78552 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78553 unsigned char range_lo, unsigned char range_hi,
78554 unsigned char max, struct module *mod)
78555 {
78556 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78557 {
78558 unsigned int devlo, devhi;
78559 unsigned char chi, clo, max;
78560 - int ndigits;
78561 + unsigned int ndigits;
78562
78563 id->match_flags = TO_NATIVE(id->match_flags);
78564 id->idVendor = TO_NATIVE(id->idVendor);
78565 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78566 for (i = 0; i < count; i++) {
78567 const char *id = (char *)devs[i].id;
78568 char acpi_id[sizeof(devs[0].id)];
78569 - int j;
78570 + unsigned int j;
78571
78572 buf_printf(&mod->dev_table_buf,
78573 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78574 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78575
78576 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78577 const char *id = (char *)card->devs[j].id;
78578 - int i2, j2;
78579 + unsigned int i2, j2;
78580 int dup = 0;
78581
78582 if (!id[0])
78583 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78584 /* add an individual alias for every device entry */
78585 if (!dup) {
78586 char acpi_id[sizeof(card->devs[0].id)];
78587 - int k;
78588 + unsigned int k;
78589
78590 buf_printf(&mod->dev_table_buf,
78591 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78592 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78593 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78594 char *alias)
78595 {
78596 - int i, j;
78597 + unsigned int i, j;
78598
78599 sprintf(alias, "dmi*");
78600
78601 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78602 index c4e7d15..4241aef 100644
78603 --- a/scripts/mod/modpost.c
78604 +++ b/scripts/mod/modpost.c
78605 @@ -922,6 +922,7 @@ enum mismatch {
78606 ANY_INIT_TO_ANY_EXIT,
78607 ANY_EXIT_TO_ANY_INIT,
78608 EXPORT_TO_INIT_EXIT,
78609 + DATA_TO_TEXT
78610 };
78611
78612 struct sectioncheck {
78613 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
78614 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78615 .mismatch = EXPORT_TO_INIT_EXIT,
78616 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78617 +},
78618 +/* Do not reference code from writable data */
78619 +{
78620 + .fromsec = { DATA_SECTIONS, NULL },
78621 + .tosec = { TEXT_SECTIONS, NULL },
78622 + .mismatch = DATA_TO_TEXT
78623 }
78624 };
78625
78626 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78627 continue;
78628 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78629 continue;
78630 - if (sym->st_value == addr)
78631 - return sym;
78632 /* Find a symbol nearby - addr are maybe negative */
78633 d = sym->st_value - addr;
78634 + if (d == 0)
78635 + return sym;
78636 if (d < 0)
78637 d = addr - sym->st_value;
78638 if (d < distance) {
78639 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
78640 tosym, prl_to, prl_to, tosym);
78641 free(prl_to);
78642 break;
78643 + case DATA_TO_TEXT:
78644 +/*
78645 + fprintf(stderr,
78646 + "The variable %s references\n"
78647 + "the %s %s%s%s\n",
78648 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78649 +*/
78650 + break;
78651 }
78652 fprintf(stderr, "\n");
78653 }
78654 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78655 static void check_sec_ref(struct module *mod, const char *modname,
78656 struct elf_info *elf)
78657 {
78658 - int i;
78659 + unsigned int i;
78660 Elf_Shdr *sechdrs = elf->sechdrs;
78661
78662 /* Walk through all sections */
78663 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78664 va_end(ap);
78665 }
78666
78667 -void buf_write(struct buffer *buf, const char *s, int len)
78668 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78669 {
78670 if (buf->size - buf->pos < len) {
78671 buf->size += len + SZ;
78672 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78673 if (fstat(fileno(file), &st) < 0)
78674 goto close_write;
78675
78676 - if (st.st_size != b->pos)
78677 + if (st.st_size != (off_t)b->pos)
78678 goto close_write;
78679
78680 tmp = NOFAIL(malloc(b->pos));
78681 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78682 index 51207e4..f7d603d 100644
78683 --- a/scripts/mod/modpost.h
78684 +++ b/scripts/mod/modpost.h
78685 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78686
78687 struct buffer {
78688 char *p;
78689 - int pos;
78690 - int size;
78691 + unsigned int pos;
78692 + unsigned int size;
78693 };
78694
78695 void __attribute__((format(printf, 2, 3)))
78696 buf_printf(struct buffer *buf, const char *fmt, ...);
78697
78698 void
78699 -buf_write(struct buffer *buf, const char *s, int len);
78700 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78701
78702 struct module {
78703 struct module *next;
78704 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78705 index 9dfcd6d..099068e 100644
78706 --- a/scripts/mod/sumversion.c
78707 +++ b/scripts/mod/sumversion.c
78708 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78709 goto out;
78710 }
78711
78712 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78713 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78714 warn("writing sum in %s failed: %s\n",
78715 filename, strerror(errno));
78716 goto out;
78717 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78718 index 5c11312..72742b5 100644
78719 --- a/scripts/pnmtologo.c
78720 +++ b/scripts/pnmtologo.c
78721 @@ -237,14 +237,14 @@ static void write_header(void)
78722 fprintf(out, " * Linux logo %s\n", logoname);
78723 fputs(" */\n\n", out);
78724 fputs("#include <linux/linux_logo.h>\n\n", out);
78725 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78726 + fprintf(out, "static unsigned char %s_data[] = {\n",
78727 logoname);
78728 }
78729
78730 static void write_footer(void)
78731 {
78732 fputs("\n};\n\n", out);
78733 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78734 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78735 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78736 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78737 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78738 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78739 fputs("\n};\n\n", out);
78740
78741 /* write logo clut */
78742 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78743 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78744 logoname);
78745 write_hex_cnt = 0;
78746 for (i = 0; i < logo_clutsize; i++) {
78747 diff --git a/scripts/tags.sh b/scripts/tags.sh
78748 index 833813a..0bc8588 100755
78749 --- a/scripts/tags.sh
78750 +++ b/scripts/tags.sh
78751 @@ -116,7 +116,7 @@ docscope()
78752
78753 dogtags()
78754 {
78755 - all_sources | gtags -f -
78756 + all_sources | gtags -i -f -
78757 }
78758
78759 exuberant()
78760 diff --git a/security/Kconfig b/security/Kconfig
78761 index 51bd5a0..c37f5e6 100644
78762 --- a/security/Kconfig
78763 +++ b/security/Kconfig
78764 @@ -4,6 +4,640 @@
78765
78766 menu "Security options"
78767
78768 +source grsecurity/Kconfig
78769 +
78770 +menu "PaX"
78771 +
78772 + config ARCH_TRACK_EXEC_LIMIT
78773 + bool
78774 +
78775 + config PAX_KERNEXEC_PLUGIN
78776 + bool
78777 +
78778 + config PAX_PER_CPU_PGD
78779 + bool
78780 +
78781 + config TASK_SIZE_MAX_SHIFT
78782 + int
78783 + depends on X86_64
78784 + default 47 if !PAX_PER_CPU_PGD
78785 + default 42 if PAX_PER_CPU_PGD
78786 +
78787 + config PAX_ENABLE_PAE
78788 + bool
78789 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78790 +
78791 +config PAX
78792 + bool "Enable various PaX features"
78793 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78794 + help
78795 + This allows you to enable various PaX features. PaX adds
78796 + intrusion prevention mechanisms to the kernel that reduce
78797 + the risks posed by exploitable memory corruption bugs.
78798 +
78799 +menu "PaX Control"
78800 + depends on PAX
78801 +
78802 +config PAX_SOFTMODE
78803 + bool 'Support soft mode'
78804 + help
78805 + Enabling this option will allow you to run PaX in soft mode, that
78806 + is, PaX features will not be enforced by default, only on executables
78807 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78808 + support as they are the only way to mark executables for soft mode use.
78809 +
78810 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78811 + line option on boot. Furthermore you can control various PaX features
78812 + at runtime via the entries in /proc/sys/kernel/pax.
78813 +
78814 +config PAX_EI_PAX
78815 + bool 'Use legacy ELF header marking'
78816 + help
78817 + Enabling this option will allow you to control PaX features on
78818 + a per executable basis via the 'chpax' utility available at
78819 + http://pax.grsecurity.net/. The control flags will be read from
78820 + an otherwise reserved part of the ELF header. This marking has
78821 + numerous drawbacks (no support for soft-mode, toolchain does not
78822 + know about the non-standard use of the ELF header) therefore it
78823 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78824 + support.
78825 +
78826 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78827 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78828 + option otherwise they will not get any protection.
78829 +
78830 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78831 + support as well, they will override the legacy EI_PAX marks.
78832 +
78833 +config PAX_PT_PAX_FLAGS
78834 + bool 'Use ELF program header marking'
78835 + help
78836 + Enabling this option will allow you to control PaX features on
78837 + a per executable basis via the 'paxctl' utility available at
78838 + http://pax.grsecurity.net/. The control flags will be read from
78839 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78840 + has the benefits of supporting both soft mode and being fully
78841 + integrated into the toolchain (the binutils patch is available
78842 + from http://pax.grsecurity.net).
78843 +
78844 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78845 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78846 + support otherwise they will not get any protection.
78847 +
78848 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78849 + must make sure that the marks are the same if a binary has both marks.
78850 +
78851 + Note that if you enable the legacy EI_PAX marking support as well,
78852 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78853 +
78854 +config PAX_XATTR_PAX_FLAGS
78855 + bool 'Use filesystem extended attributes marking'
78856 + select CIFS_XATTR if CIFS
78857 + select EXT2_FS_XATTR if EXT2_FS
78858 + select EXT3_FS_XATTR if EXT3_FS
78859 + select EXT4_FS_XATTR if EXT4_FS
78860 + select JFFS2_FS_XATTR if JFFS2_FS
78861 + select REISERFS_FS_XATTR if REISERFS_FS
78862 + select SQUASHFS_XATTR if SQUASHFS
78863 + select TMPFS_XATTR if TMPFS
78864 + select UBIFS_FS_XATTR if UBIFS_FS
78865 + help
78866 + Enabling this option will allow you to control PaX features on
78867 + a per executable basis via the 'setfattr' utility. The control
78868 + flags will be read from the user.pax.flags extended attribute of
78869 + the file. This marking has the benefit of supporting binary-only
78870 + applications that self-check themselves (e.g., skype) and would
78871 + not tolerate chpax/paxctl changes. The main drawback is that
78872 + extended attributes are not supported by some filesystems (e.g.,
78873 + isofs, udf, vfat) so copying files through such filesystems will
78874 + lose the extended attributes and these PaX markings.
78875 +
78876 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78877 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78878 + support otherwise they will not get any protection.
78879 +
78880 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78881 + must make sure that the marks are the same if a binary has both marks.
78882 +
78883 + Note that if you enable the legacy EI_PAX marking support as well,
78884 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78885 +
78886 +choice
78887 + prompt 'MAC system integration'
78888 + default PAX_HAVE_ACL_FLAGS
78889 + help
78890 + Mandatory Access Control systems have the option of controlling
78891 + PaX flags on a per executable basis, choose the method supported
78892 + by your particular system.
78893 +
78894 + - "none": if your MAC system does not interact with PaX,
78895 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78896 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78897 +
78898 + NOTE: this option is for developers/integrators only.
78899 +
78900 + config PAX_NO_ACL_FLAGS
78901 + bool 'none'
78902 +
78903 + config PAX_HAVE_ACL_FLAGS
78904 + bool 'direct'
78905 +
78906 + config PAX_HOOK_ACL_FLAGS
78907 + bool 'hook'
78908 +endchoice
78909 +
78910 +endmenu
78911 +
78912 +menu "Non-executable pages"
78913 + depends on PAX
78914 +
78915 +config PAX_NOEXEC
78916 + bool "Enforce non-executable pages"
78917 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78918 + help
78919 + By design some architectures do not allow for protecting memory
78920 + pages against execution or even if they do, Linux does not make
78921 + use of this feature. In practice this means that if a page is
78922 + readable (such as the stack or heap) it is also executable.
78923 +
78924 + There is a well known exploit technique that makes use of this
78925 + fact and a common programming mistake where an attacker can
78926 + introduce code of his choice somewhere in the attacked program's
78927 + memory (typically the stack or the heap) and then execute it.
78928 +
78929 + If the attacked program was running with different (typically
78930 + higher) privileges than that of the attacker, then he can elevate
78931 + his own privilege level (e.g. get a root shell, write to files for
78932 + which he does not have write access to, etc).
78933 +
78934 + Enabling this option will let you choose from various features
78935 + that prevent the injection and execution of 'foreign' code in
78936 + a program.
78937 +
78938 + This will also break programs that rely on the old behaviour and
78939 + expect that dynamically allocated memory via the malloc() family
78940 + of functions is executable (which it is not). Notable examples
78941 + are the XFree86 4.x server, the java runtime and wine.
78942 +
78943 +config PAX_PAGEEXEC
78944 + bool "Paging based non-executable pages"
78945 + 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)
78946 + select S390_SWITCH_AMODE if S390
78947 + select S390_EXEC_PROTECT if S390
78948 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78949 + help
78950 + This implementation is based on the paging feature of the CPU.
78951 + On i386 without hardware non-executable bit support there is a
78952 + variable but usually low performance impact, however on Intel's
78953 + P4 core based CPUs it is very high so you should not enable this
78954 + for kernels meant to be used on such CPUs.
78955 +
78956 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78957 + with hardware non-executable bit support there is no performance
78958 + impact, on ppc the impact is negligible.
78959 +
78960 + Note that several architectures require various emulations due to
78961 + badly designed userland ABIs, this will cause a performance impact
78962 + but will disappear as soon as userland is fixed. For example, ppc
78963 + userland MUST have been built with secure-plt by a recent toolchain.
78964 +
78965 +config PAX_SEGMEXEC
78966 + bool "Segmentation based non-executable pages"
78967 + depends on PAX_NOEXEC && X86_32
78968 + help
78969 + This implementation is based on the segmentation feature of the
78970 + CPU and has a very small performance impact, however applications
78971 + will be limited to a 1.5 GB address space instead of the normal
78972 + 3 GB.
78973 +
78974 +config PAX_EMUTRAMP
78975 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78976 + default y if PARISC
78977 + help
78978 + There are some programs and libraries that for one reason or
78979 + another attempt to execute special small code snippets from
78980 + non-executable memory pages. Most notable examples are the
78981 + signal handler return code generated by the kernel itself and
78982 + the GCC trampolines.
78983 +
78984 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78985 + such programs will no longer work under your kernel.
78986 +
78987 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78988 + utilities to enable trampoline emulation for the affected programs
78989 + yet still have the protection provided by the non-executable pages.
78990 +
78991 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78992 + your system will not even boot.
78993 +
78994 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78995 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78996 + for the affected files.
78997 +
78998 + NOTE: enabling this feature *may* open up a loophole in the
78999 + protection provided by non-executable pages that an attacker
79000 + could abuse. Therefore the best solution is to not have any
79001 + files on your system that would require this option. This can
79002 + be achieved by not using libc5 (which relies on the kernel
79003 + signal handler return code) and not using or rewriting programs
79004 + that make use of the nested function implementation of GCC.
79005 + Skilled users can just fix GCC itself so that it implements
79006 + nested function calls in a way that does not interfere with PaX.
79007 +
79008 +config PAX_EMUSIGRT
79009 + bool "Automatically emulate sigreturn trampolines"
79010 + depends on PAX_EMUTRAMP && PARISC
79011 + default y
79012 + help
79013 + Enabling this option will have the kernel automatically detect
79014 + and emulate signal return trampolines executing on the stack
79015 + that would otherwise lead to task termination.
79016 +
79017 + This solution is intended as a temporary one for users with
79018 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79019 + Modula-3 runtime, etc) or executables linked to such, basically
79020 + everything that does not specify its own SA_RESTORER function in
79021 + normal executable memory like glibc 2.1+ does.
79022 +
79023 + On parisc you MUST enable this option, otherwise your system will
79024 + not even boot.
79025 +
79026 + NOTE: this feature cannot be disabled on a per executable basis
79027 + and since it *does* open up a loophole in the protection provided
79028 + by non-executable pages, the best solution is to not have any
79029 + files on your system that would require this option.
79030 +
79031 +config PAX_MPROTECT
79032 + bool "Restrict mprotect()"
79033 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79034 + help
79035 + Enabling this option will prevent programs from
79036 + - changing the executable status of memory pages that were
79037 + not originally created as executable,
79038 + - making read-only executable pages writable again,
79039 + - creating executable pages from anonymous memory,
79040 + - making read-only-after-relocations (RELRO) data pages writable again.
79041 +
79042 + You should say Y here to complete the protection provided by
79043 + the enforcement of non-executable pages.
79044 +
79045 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79046 + this feature on a per file basis.
79047 +
79048 +config PAX_MPROTECT_COMPAT
79049 + bool "Use legacy/compat protection demoting (read help)"
79050 + depends on PAX_MPROTECT
79051 + default n
79052 + help
79053 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79054 + by sending the proper error code to the application. For some broken
79055 + userland, this can cause problems with Python or other applications. The
79056 + current implementation however allows for applications like clamav to
79057 + detect if JIT compilation/execution is allowed and to fall back gracefully
79058 + to an interpreter-based mode if it does not. While we encourage everyone
79059 + to use the current implementation as-is and push upstream to fix broken
79060 + userland (note that the RWX logging option can assist with this), in some
79061 + environments this may not be possible. Having to disable MPROTECT
79062 + completely on certain binaries reduces the security benefit of PaX,
79063 + so this option is provided for those environments to revert to the old
79064 + behavior.
79065 +
79066 +config PAX_ELFRELOCS
79067 + bool "Allow ELF text relocations (read help)"
79068 + depends on PAX_MPROTECT
79069 + default n
79070 + help
79071 + Non-executable pages and mprotect() restrictions are effective
79072 + in preventing the introduction of new executable code into an
79073 + attacked task's address space. There remain only two venues
79074 + for this kind of attack: if the attacker can execute already
79075 + existing code in the attacked task then he can either have it
79076 + create and mmap() a file containing his code or have it mmap()
79077 + an already existing ELF library that does not have position
79078 + independent code in it and use mprotect() on it to make it
79079 + writable and copy his code there. While protecting against
79080 + the former approach is beyond PaX, the latter can be prevented
79081 + by having only PIC ELF libraries on one's system (which do not
79082 + need to relocate their code). If you are sure this is your case,
79083 + as is the case with all modern Linux distributions, then leave
79084 + this option disabled. You should say 'n' here.
79085 +
79086 +config PAX_ETEXECRELOCS
79087 + bool "Allow ELF ET_EXEC text relocations"
79088 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79089 + select PAX_ELFRELOCS
79090 + default y
79091 + help
79092 + On some architectures there are incorrectly created applications
79093 + that require text relocations and would not work without enabling
79094 + this option. If you are an alpha, ia64 or parisc user, you should
79095 + enable this option and disable it once you have made sure that
79096 + none of your applications need it.
79097 +
79098 +config PAX_EMUPLT
79099 + bool "Automatically emulate ELF PLT"
79100 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79101 + default y
79102 + help
79103 + Enabling this option will have the kernel automatically detect
79104 + and emulate the Procedure Linkage Table entries in ELF files.
79105 + On some architectures such entries are in writable memory, and
79106 + become non-executable leading to task termination. Therefore
79107 + it is mandatory that you enable this option on alpha, parisc,
79108 + sparc and sparc64, otherwise your system would not even boot.
79109 +
79110 + NOTE: this feature *does* open up a loophole in the protection
79111 + provided by the non-executable pages, therefore the proper
79112 + solution is to modify the toolchain to produce a PLT that does
79113 + not need to be writable.
79114 +
79115 +config PAX_DLRESOLVE
79116 + bool 'Emulate old glibc resolver stub'
79117 + depends on PAX_EMUPLT && SPARC
79118 + default n
79119 + help
79120 + This option is needed if userland has an old glibc (before 2.4)
79121 + that puts a 'save' instruction into the runtime generated resolver
79122 + stub that needs special emulation.
79123 +
79124 +config PAX_KERNEXEC
79125 + bool "Enforce non-executable kernel pages"
79126 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79127 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79128 + select PAX_KERNEXEC_PLUGIN if X86_64
79129 + help
79130 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79131 + that is, enabling this option will make it harder to inject
79132 + and execute 'foreign' code in kernel memory itself.
79133 +
79134 + Note that on x86_64 kernels there is a known regression when
79135 + this feature and KVM/VMX are both enabled in the host kernel.
79136 +
79137 +choice
79138 + prompt "Return Address Instrumentation Method"
79139 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79140 + depends on PAX_KERNEXEC_PLUGIN
79141 + help
79142 + Select the method used to instrument function pointer dereferences.
79143 + Note that binary modules cannot be instrumented by this approach.
79144 +
79145 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79146 + bool "bts"
79147 + help
79148 + This method is compatible with binary only modules but has
79149 + a higher runtime overhead.
79150 +
79151 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79152 + bool "or"
79153 + depends on !PARAVIRT
79154 + help
79155 + This method is incompatible with binary only modules but has
79156 + a lower runtime overhead.
79157 +endchoice
79158 +
79159 +config PAX_KERNEXEC_PLUGIN_METHOD
79160 + string
79161 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79162 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79163 + default ""
79164 +
79165 +config PAX_KERNEXEC_MODULE_TEXT
79166 + int "Minimum amount of memory reserved for module code"
79167 + default "4"
79168 + depends on PAX_KERNEXEC && X86_32 && MODULES
79169 + help
79170 + Due to implementation details the kernel must reserve a fixed
79171 + amount of memory for module code at compile time that cannot be
79172 + changed at runtime. Here you can specify the minimum amount
79173 + in MB that will be reserved. Due to the same implementation
79174 + details this size will always be rounded up to the next 2/4 MB
79175 + boundary (depends on PAE) so the actually available memory for
79176 + module code will usually be more than this minimum.
79177 +
79178 + The default 4 MB should be enough for most users but if you have
79179 + an excessive number of modules (e.g., most distribution configs
79180 + compile many drivers as modules) or use huge modules such as
79181 + nvidia's kernel driver, you will need to adjust this amount.
79182 + A good rule of thumb is to look at your currently loaded kernel
79183 + modules and add up their sizes.
79184 +
79185 +endmenu
79186 +
79187 +menu "Address Space Layout Randomization"
79188 + depends on PAX
79189 +
79190 +config PAX_ASLR
79191 + bool "Address Space Layout Randomization"
79192 + help
79193 + Many if not most exploit techniques rely on the knowledge of
79194 + certain addresses in the attacked program. The following options
79195 + will allow the kernel to apply a certain amount of randomization
79196 + to specific parts of the program thereby forcing an attacker to
79197 + guess them in most cases. Any failed guess will most likely crash
79198 + the attacked program which allows the kernel to detect such attempts
79199 + and react on them. PaX itself provides no reaction mechanisms,
79200 + instead it is strongly encouraged that you make use of Nergal's
79201 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79202 + (http://www.grsecurity.net/) built-in crash detection features or
79203 + develop one yourself.
79204 +
79205 + By saying Y here you can choose to randomize the following areas:
79206 + - top of the task's kernel stack
79207 + - top of the task's userland stack
79208 + - base address for mmap() requests that do not specify one
79209 + (this includes all libraries)
79210 + - base address of the main executable
79211 +
79212 + It is strongly recommended to say Y here as address space layout
79213 + randomization has negligible impact on performance yet it provides
79214 + a very effective protection.
79215 +
79216 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79217 + this feature on a per file basis.
79218 +
79219 +config PAX_RANDKSTACK
79220 + bool "Randomize kernel stack base"
79221 + depends on X86_TSC && X86
79222 + help
79223 + By saying Y here the kernel will randomize every task's kernel
79224 + stack on every system call. This will not only force an attacker
79225 + to guess it but also prevent him from making use of possible
79226 + leaked information about it.
79227 +
79228 + Since the kernel stack is a rather scarce resource, randomization
79229 + may cause unexpected stack overflows, therefore you should very
79230 + carefully test your system. Note that once enabled in the kernel
79231 + configuration, this feature cannot be disabled on a per file basis.
79232 +
79233 +config PAX_RANDUSTACK
79234 + bool "Randomize user stack base"
79235 + depends on PAX_ASLR
79236 + help
79237 + By saying Y here the kernel will randomize every task's userland
79238 + stack. The randomization is done in two steps where the second
79239 + one may apply a big amount of shift to the top of the stack and
79240 + cause problems for programs that want to use lots of memory (more
79241 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79242 + For this reason the second step can be controlled by 'chpax' or
79243 + 'paxctl' on a per file basis.
79244 +
79245 +config PAX_RANDMMAP
79246 + bool "Randomize mmap() base"
79247 + depends on PAX_ASLR
79248 + help
79249 + By saying Y here the kernel will use a randomized base address for
79250 + mmap() requests that do not specify one themselves. As a result
79251 + all dynamically loaded libraries will appear at random addresses
79252 + and therefore be harder to exploit by a technique where an attacker
79253 + attempts to execute library code for his purposes (e.g. spawn a
79254 + shell from an exploited program that is running at an elevated
79255 + privilege level).
79256 +
79257 + Furthermore, if a program is relinked as a dynamic ELF file, its
79258 + base address will be randomized as well, completing the full
79259 + randomization of the address space layout. Attacking such programs
79260 + becomes a guess game. You can find an example of doing this at
79261 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79262 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79263 +
79264 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79265 + feature on a per file basis.
79266 +
79267 +endmenu
79268 +
79269 +menu "Miscellaneous hardening features"
79270 +
79271 +config PAX_MEMORY_SANITIZE
79272 + bool "Sanitize all freed memory"
79273 + depends on !HIBERNATION
79274 + help
79275 + By saying Y here the kernel will erase memory pages as soon as they
79276 + are freed. This in turn reduces the lifetime of data stored in the
79277 + pages, making it less likely that sensitive information such as
79278 + passwords, cryptographic secrets, etc stay in memory for too long.
79279 +
79280 + This is especially useful for programs whose runtime is short, long
79281 + lived processes and the kernel itself benefit from this as long as
79282 + they operate on whole memory pages and ensure timely freeing of pages
79283 + that may hold sensitive information.
79284 +
79285 + The tradeoff is performance impact, on a single CPU system kernel
79286 + compilation sees a 3% slowdown, other systems and workloads may vary
79287 + and you are advised to test this feature on your expected workload
79288 + before deploying it.
79289 +
79290 + Note that this feature does not protect data stored in live pages,
79291 + e.g., process memory swapped to disk may stay there for a long time.
79292 +
79293 +config PAX_MEMORY_STACKLEAK
79294 + bool "Sanitize kernel stack"
79295 + depends on X86
79296 + help
79297 + By saying Y here the kernel will erase the kernel stack before it
79298 + returns from a system call. This in turn reduces the information
79299 + that a kernel stack leak bug can reveal.
79300 +
79301 + Note that such a bug can still leak information that was put on
79302 + the stack by the current system call (the one eventually triggering
79303 + the bug) but traces of earlier system calls on the kernel stack
79304 + cannot leak anymore.
79305 +
79306 + The tradeoff is performance impact: on a single CPU system kernel
79307 + compilation sees a 1% slowdown, other systems and workloads may vary
79308 + and you are advised to test this feature on your expected workload
79309 + before deploying it.
79310 +
79311 + Note: full support for this feature requires gcc with plugin support
79312 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79313 + versions means that functions with large enough stack frames may
79314 + leave uninitialized memory behind that may be exposed to a later
79315 + syscall leaking the stack.
79316 +
79317 +config PAX_MEMORY_UDEREF
79318 + bool "Prevent invalid userland pointer dereference"
79319 + depends on X86 && !UML_X86 && !XEN
79320 + select PAX_PER_CPU_PGD if X86_64
79321 + help
79322 + By saying Y here the kernel will be prevented from dereferencing
79323 + userland pointers in contexts where the kernel expects only kernel
79324 + pointers. This is both a useful runtime debugging feature and a
79325 + security measure that prevents exploiting a class of kernel bugs.
79326 +
79327 + The tradeoff is that some virtualization solutions may experience
79328 + a huge slowdown and therefore you should not enable this feature
79329 + for kernels meant to run in such environments. Whether a given VM
79330 + solution is affected or not is best determined by simply trying it
79331 + out, the performance impact will be obvious right on boot as this
79332 + mechanism engages from very early on. A good rule of thumb is that
79333 + VMs running on CPUs without hardware virtualization support (i.e.,
79334 + the majority of IA-32 CPUs) will likely experience the slowdown.
79335 +
79336 +config PAX_REFCOUNT
79337 + bool "Prevent various kernel object reference counter overflows"
79338 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79339 + help
79340 + By saying Y here the kernel will detect and prevent overflowing
79341 + various (but not all) kinds of object reference counters. Such
79342 + overflows can normally occur due to bugs only and are often, if
79343 + not always, exploitable.
79344 +
79345 + The tradeoff is that data structures protected by an overflowed
79346 + refcount will never be freed and therefore will leak memory. Note
79347 + that this leak also happens even without this protection but in
79348 + that case the overflow can eventually trigger the freeing of the
79349 + data structure while it is still being used elsewhere, resulting
79350 + in the exploitable situation that this feature prevents.
79351 +
79352 + Since this has a negligible performance impact, you should enable
79353 + this feature.
79354 +
79355 +config PAX_USERCOPY
79356 + bool "Harden heap object copies between kernel and userland"
79357 + depends on X86 || PPC || SPARC || ARM
79358 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79359 + help
79360 + By saying Y here the kernel will enforce the size of heap objects
79361 + when they are copied in either direction between the kernel and
79362 + userland, even if only a part of the heap object is copied.
79363 +
79364 + Specifically, this checking prevents information leaking from the
79365 + kernel heap during kernel to userland copies (if the kernel heap
79366 + object is otherwise fully initialized) and prevents kernel heap
79367 + overflows during userland to kernel copies.
79368 +
79369 + Note that the current implementation provides the strictest bounds
79370 + checks for the SLUB allocator.
79371 +
79372 + Enabling this option also enables per-slab cache protection against
79373 + data in a given cache being copied into/out of via userland
79374 + accessors. Though the whitelist of regions will be reduced over
79375 + time, it notably protects important data structures like task structs.
79376 +
79377 + If frame pointers are enabled on x86, this option will also restrict
79378 + copies into and out of the kernel stack to local variables within a
79379 + single frame.
79380 +
79381 + Since this has a negligible performance impact, you should enable
79382 + this feature.
79383 +
79384 +config PAX_SIZE_OVERFLOW
79385 + bool "Prevent various integer overflows in function size parameters"
79386 + depends on X86
79387 + help
79388 + By saying Y here the kernel recomputes expressions of function
79389 + arguments marked by a size_overflow attribute with double integer
79390 + precision (DImode/TImode for 32/64 bit integer types).
79391 +
79392 + The recomputed argument is checked against INT_MAX and an event
79393 + is logged on overflow and the triggering process is killed.
79394 +
79395 + Homepage:
79396 + http://www.grsecurity.net/~ephox/overflow_plugin/
79397 +
79398 +endmenu
79399 +
79400 +endmenu
79401 +
79402 config KEYS
79403 bool "Enable access key retention support"
79404 help
79405 @@ -169,7 +803,7 @@ config INTEL_TXT
79406 config LSM_MMAP_MIN_ADDR
79407 int "Low address space for LSM to protect from user allocation"
79408 depends on SECURITY && SECURITY_SELINUX
79409 - default 32768 if ARM
79410 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79411 default 65536
79412 help
79413 This is the portion of low virtual memory which should be protected
79414 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79415 index 97ce8fa..23dad96 100644
79416 --- a/security/apparmor/lsm.c
79417 +++ b/security/apparmor/lsm.c
79418 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79419 return error;
79420 }
79421
79422 -static struct security_operations apparmor_ops = {
79423 +static struct security_operations apparmor_ops __read_only = {
79424 .name = "apparmor",
79425
79426 .ptrace_access_check = apparmor_ptrace_access_check,
79427 diff --git a/security/commoncap.c b/security/commoncap.c
79428 index 7ce191e..f560413 100644
79429 --- a/security/commoncap.c
79430 +++ b/security/commoncap.c
79431 @@ -28,6 +28,7 @@
79432 #include <linux/prctl.h>
79433 #include <linux/securebits.h>
79434 #include <linux/user_namespace.h>
79435 +#include <net/sock.h>
79436
79437 /*
79438 * If a non-root user executes a setuid-root binary in
79439 @@ -504,6 +505,11 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
79440 }
79441 skip:
79442
79443 + /* if we have fs caps, clear dangerous personality flags */
79444 + if (!cap_issubset(new->cap_permitted, old->cap_permitted))
79445 + bprm->per_clear |= PER_CLEAR_ON_SETID;
79446 +
79447 +
79448 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
79449 * credentials unless they have the appropriate permit
79450 */
79451 @@ -569,6 +575,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79452 {
79453 const struct cred *cred = current_cred();
79454
79455 + if (gr_acl_enable_at_secure())
79456 + return 1;
79457 +
79458 if (cred->uid != 0) {
79459 if (bprm->cap_effective)
79460 return 1;
79461 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79462 index 3ccf7ac..d73ad64 100644
79463 --- a/security/integrity/ima/ima.h
79464 +++ b/security/integrity/ima/ima.h
79465 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79466 extern spinlock_t ima_queue_lock;
79467
79468 struct ima_h_table {
79469 - atomic_long_t len; /* number of stored measurements in the list */
79470 - atomic_long_t violations;
79471 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79472 + atomic_long_unchecked_t violations;
79473 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79474 };
79475 extern struct ima_h_table ima_htable;
79476 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79477 index 88a2788..581ab92 100644
79478 --- a/security/integrity/ima/ima_api.c
79479 +++ b/security/integrity/ima/ima_api.c
79480 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79481 int result;
79482
79483 /* can overflow, only indicator */
79484 - atomic_long_inc(&ima_htable.violations);
79485 + atomic_long_inc_unchecked(&ima_htable.violations);
79486
79487 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79488 if (!entry) {
79489 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79490 index e1aa2b4..52027bf 100644
79491 --- a/security/integrity/ima/ima_fs.c
79492 +++ b/security/integrity/ima/ima_fs.c
79493 @@ -28,12 +28,12 @@
79494 static int valid_policy = 1;
79495 #define TMPBUFLEN 12
79496 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79497 - loff_t *ppos, atomic_long_t *val)
79498 + loff_t *ppos, atomic_long_unchecked_t *val)
79499 {
79500 char tmpbuf[TMPBUFLEN];
79501 ssize_t len;
79502
79503 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79504 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79505 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79506 }
79507
79508 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79509 index 55a6271..ad829c3 100644
79510 --- a/security/integrity/ima/ima_queue.c
79511 +++ b/security/integrity/ima/ima_queue.c
79512 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79513 INIT_LIST_HEAD(&qe->later);
79514 list_add_tail_rcu(&qe->later, &ima_measurements);
79515
79516 - atomic_long_inc(&ima_htable.len);
79517 + atomic_long_inc_unchecked(&ima_htable.len);
79518 key = ima_hash_key(entry->digest);
79519 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79520 return 0;
79521 diff --git a/security/keys/compat.c b/security/keys/compat.c
79522 index 4c48e13..7abdac9 100644
79523 --- a/security/keys/compat.c
79524 +++ b/security/keys/compat.c
79525 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79526 if (ret == 0)
79527 goto no_payload_free;
79528
79529 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79530 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79531
79532 if (iov != iovstack)
79533 kfree(iov);
79534 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79535 index 0b3f5d7..892c8a6 100644
79536 --- a/security/keys/keyctl.c
79537 +++ b/security/keys/keyctl.c
79538 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79539 /*
79540 * Copy the iovec data from userspace
79541 */
79542 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79543 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79544 unsigned ioc)
79545 {
79546 for (; ioc > 0; ioc--) {
79547 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79548 * If successful, 0 will be returned.
79549 */
79550 long keyctl_instantiate_key_common(key_serial_t id,
79551 - const struct iovec *payload_iov,
79552 + const struct iovec __user *payload_iov,
79553 unsigned ioc,
79554 size_t plen,
79555 key_serial_t ringid)
79556 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79557 [0].iov_len = plen
79558 };
79559
79560 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79561 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79562 }
79563
79564 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79565 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79566 if (ret == 0)
79567 goto no_payload_free;
79568
79569 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79570 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79571
79572 if (iov != iovstack)
79573 kfree(iov);
79574 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79575 index d605f75..2bc6be9 100644
79576 --- a/security/keys/keyring.c
79577 +++ b/security/keys/keyring.c
79578 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79579 ret = -EFAULT;
79580
79581 for (loop = 0; loop < klist->nkeys; loop++) {
79582 + key_serial_t serial;
79583 key = klist->keys[loop];
79584 + serial = key->serial;
79585
79586 tmp = sizeof(key_serial_t);
79587 if (tmp > buflen)
79588 tmp = buflen;
79589
79590 - if (copy_to_user(buffer,
79591 - &key->serial,
79592 - tmp) != 0)
79593 + if (copy_to_user(buffer, &serial, tmp))
79594 goto error;
79595
79596 buflen -= tmp;
79597 diff --git a/security/min_addr.c b/security/min_addr.c
79598 index f728728..6457a0c 100644
79599 --- a/security/min_addr.c
79600 +++ b/security/min_addr.c
79601 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79602 */
79603 static void update_mmap_min_addr(void)
79604 {
79605 +#ifndef SPARC
79606 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79607 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79608 mmap_min_addr = dac_mmap_min_addr;
79609 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79610 #else
79611 mmap_min_addr = dac_mmap_min_addr;
79612 #endif
79613 +#endif
79614 }
79615
79616 /*
79617 diff --git a/security/security.c b/security/security.c
79618 index d754249..8bf426e 100644
79619 --- a/security/security.c
79620 +++ b/security/security.c
79621 @@ -26,8 +26,8 @@
79622 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79623 CONFIG_DEFAULT_SECURITY;
79624
79625 -static struct security_operations *security_ops;
79626 -static struct security_operations default_security_ops = {
79627 +static struct security_operations *security_ops __read_only;
79628 +static struct security_operations default_security_ops __read_only = {
79629 .name = "default",
79630 };
79631
79632 @@ -68,7 +68,9 @@ int __init security_init(void)
79633
79634 void reset_security_ops(void)
79635 {
79636 + pax_open_kernel();
79637 security_ops = &default_security_ops;
79638 + pax_close_kernel();
79639 }
79640
79641 /* Save user chosen LSM */
79642 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79643 index 6a3683e..f52f4c0 100644
79644 --- a/security/selinux/hooks.c
79645 +++ b/security/selinux/hooks.c
79646 @@ -94,8 +94,6 @@
79647
79648 #define NUM_SEL_MNT_OPTS 5
79649
79650 -extern struct security_operations *security_ops;
79651 -
79652 /* SECMARK reference count */
79653 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79654
79655 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79656
79657 #endif
79658
79659 -static struct security_operations selinux_ops = {
79660 +static struct security_operations selinux_ops __read_only = {
79661 .name = "selinux",
79662
79663 .ptrace_access_check = selinux_ptrace_access_check,
79664 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79665 index b43813c..74be837 100644
79666 --- a/security/selinux/include/xfrm.h
79667 +++ b/security/selinux/include/xfrm.h
79668 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79669
79670 static inline void selinux_xfrm_notify_policyload(void)
79671 {
79672 - atomic_inc(&flow_cache_genid);
79673 + atomic_inc_unchecked(&flow_cache_genid);
79674 }
79675 #else
79676 static inline int selinux_xfrm_enabled(void)
79677 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79678 index e8af5b0b..78527ef 100644
79679 --- a/security/smack/smack_lsm.c
79680 +++ b/security/smack/smack_lsm.c
79681 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79682 return 0;
79683 }
79684
79685 -struct security_operations smack_ops = {
79686 +struct security_operations smack_ops __read_only = {
79687 .name = "smack",
79688
79689 .ptrace_access_check = smack_ptrace_access_check,
79690 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79691 index 620d37c..e2ad89b 100644
79692 --- a/security/tomoyo/tomoyo.c
79693 +++ b/security/tomoyo/tomoyo.c
79694 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79695 * tomoyo_security_ops is a "struct security_operations" which is used for
79696 * registering TOMOYO.
79697 */
79698 -static struct security_operations tomoyo_security_ops = {
79699 +static struct security_operations tomoyo_security_ops __read_only = {
79700 .name = "tomoyo",
79701 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79702 .cred_prepare = tomoyo_cred_prepare,
79703 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79704 index 762af68..7103453 100644
79705 --- a/sound/aoa/codecs/onyx.c
79706 +++ b/sound/aoa/codecs/onyx.c
79707 @@ -54,7 +54,7 @@ struct onyx {
79708 spdif_locked:1,
79709 analog_locked:1,
79710 original_mute:2;
79711 - int open_count;
79712 + local_t open_count;
79713 struct codec_info *codec_info;
79714
79715 /* mutex serializes concurrent access to the device
79716 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79717 struct onyx *onyx = cii->codec_data;
79718
79719 mutex_lock(&onyx->mutex);
79720 - onyx->open_count++;
79721 + local_inc(&onyx->open_count);
79722 mutex_unlock(&onyx->mutex);
79723
79724 return 0;
79725 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79726 struct onyx *onyx = cii->codec_data;
79727
79728 mutex_lock(&onyx->mutex);
79729 - onyx->open_count--;
79730 - if (!onyx->open_count)
79731 + if (local_dec_and_test(&onyx->open_count))
79732 onyx->spdif_locked = onyx->analog_locked = 0;
79733 mutex_unlock(&onyx->mutex);
79734
79735 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79736 index ffd2025..df062c9 100644
79737 --- a/sound/aoa/codecs/onyx.h
79738 +++ b/sound/aoa/codecs/onyx.h
79739 @@ -11,6 +11,7 @@
79740 #include <linux/i2c.h>
79741 #include <asm/pmac_low_i2c.h>
79742 #include <asm/prom.h>
79743 +#include <asm/local.h>
79744
79745 /* PCM3052 register definitions */
79746
79747 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79748 index 08fde00..0bf641a 100644
79749 --- a/sound/core/oss/pcm_oss.c
79750 +++ b/sound/core/oss/pcm_oss.c
79751 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79752 if (in_kernel) {
79753 mm_segment_t fs;
79754 fs = snd_enter_user();
79755 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79756 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79757 snd_leave_user(fs);
79758 } else {
79759 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79760 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79761 }
79762 if (ret != -EPIPE && ret != -ESTRPIPE)
79763 break;
79764 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79765 if (in_kernel) {
79766 mm_segment_t fs;
79767 fs = snd_enter_user();
79768 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79769 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79770 snd_leave_user(fs);
79771 } else {
79772 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79773 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79774 }
79775 if (ret == -EPIPE) {
79776 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79777 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79778 struct snd_pcm_plugin_channel *channels;
79779 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79780 if (!in_kernel) {
79781 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79782 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79783 return -EFAULT;
79784 buf = runtime->oss.buffer;
79785 }
79786 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79787 }
79788 } else {
79789 tmp = snd_pcm_oss_write2(substream,
79790 - (const char __force *)buf,
79791 + (const char __force_kernel *)buf,
79792 runtime->oss.period_bytes, 0);
79793 if (tmp <= 0)
79794 goto err;
79795 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79796 struct snd_pcm_runtime *runtime = substream->runtime;
79797 snd_pcm_sframes_t frames, frames1;
79798 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79799 - char __user *final_dst = (char __force __user *)buf;
79800 + char __user *final_dst = (char __force_user *)buf;
79801 if (runtime->oss.plugin_first) {
79802 struct snd_pcm_plugin_channel *channels;
79803 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79804 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79805 xfer += tmp;
79806 runtime->oss.buffer_used -= tmp;
79807 } else {
79808 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79809 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79810 runtime->oss.period_bytes, 0);
79811 if (tmp <= 0)
79812 goto err;
79813 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79814 size1);
79815 size1 /= runtime->channels; /* frames */
79816 fs = snd_enter_user();
79817 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79818 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79819 snd_leave_user(fs);
79820 }
79821 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79822 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79823 index 91cdf94..4085161 100644
79824 --- a/sound/core/pcm_compat.c
79825 +++ b/sound/core/pcm_compat.c
79826 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79827 int err;
79828
79829 fs = snd_enter_user();
79830 - err = snd_pcm_delay(substream, &delay);
79831 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79832 snd_leave_user(fs);
79833 if (err < 0)
79834 return err;
79835 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79836 index 25ed9fe..24c46e9 100644
79837 --- a/sound/core/pcm_native.c
79838 +++ b/sound/core/pcm_native.c
79839 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79840 switch (substream->stream) {
79841 case SNDRV_PCM_STREAM_PLAYBACK:
79842 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79843 - (void __user *)arg);
79844 + (void __force_user *)arg);
79845 break;
79846 case SNDRV_PCM_STREAM_CAPTURE:
79847 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79848 - (void __user *)arg);
79849 + (void __force_user *)arg);
79850 break;
79851 default:
79852 result = -EINVAL;
79853 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79854 index 5cf8d65..912a79c 100644
79855 --- a/sound/core/seq/seq_device.c
79856 +++ b/sound/core/seq/seq_device.c
79857 @@ -64,7 +64,7 @@ struct ops_list {
79858 int argsize; /* argument size */
79859
79860 /* operators */
79861 - struct snd_seq_dev_ops ops;
79862 + struct snd_seq_dev_ops *ops;
79863
79864 /* registred devices */
79865 struct list_head dev_list; /* list of devices */
79866 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79867
79868 mutex_lock(&ops->reg_mutex);
79869 /* copy driver operators */
79870 - ops->ops = *entry;
79871 + ops->ops = entry;
79872 ops->driver |= DRIVER_LOADED;
79873 ops->argsize = argsize;
79874
79875 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79876 dev->name, ops->id, ops->argsize, dev->argsize);
79877 return -EINVAL;
79878 }
79879 - if (ops->ops.init_device(dev) >= 0) {
79880 + if (ops->ops->init_device(dev) >= 0) {
79881 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79882 ops->num_init_devices++;
79883 } else {
79884 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79885 dev->name, ops->id, ops->argsize, dev->argsize);
79886 return -EINVAL;
79887 }
79888 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79889 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79890 dev->status = SNDRV_SEQ_DEVICE_FREE;
79891 dev->driver_data = NULL;
79892 ops->num_init_devices--;
79893 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79894 index 621e60e..f4543f5 100644
79895 --- a/sound/drivers/mts64.c
79896 +++ b/sound/drivers/mts64.c
79897 @@ -29,6 +29,7 @@
79898 #include <sound/initval.h>
79899 #include <sound/rawmidi.h>
79900 #include <sound/control.h>
79901 +#include <asm/local.h>
79902
79903 #define CARD_NAME "Miditerminal 4140"
79904 #define DRIVER_NAME "MTS64"
79905 @@ -67,7 +68,7 @@ struct mts64 {
79906 struct pardevice *pardev;
79907 int pardev_claimed;
79908
79909 - int open_count;
79910 + local_t open_count;
79911 int current_midi_output_port;
79912 int current_midi_input_port;
79913 u8 mode[MTS64_NUM_INPUT_PORTS];
79914 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79915 {
79916 struct mts64 *mts = substream->rmidi->private_data;
79917
79918 - if (mts->open_count == 0) {
79919 + if (local_read(&mts->open_count) == 0) {
79920 /* We don't need a spinlock here, because this is just called
79921 if the device has not been opened before.
79922 So there aren't any IRQs from the device */
79923 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79924
79925 msleep(50);
79926 }
79927 - ++(mts->open_count);
79928 + local_inc(&mts->open_count);
79929
79930 return 0;
79931 }
79932 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79933 struct mts64 *mts = substream->rmidi->private_data;
79934 unsigned long flags;
79935
79936 - --(mts->open_count);
79937 - if (mts->open_count == 0) {
79938 + if (local_dec_return(&mts->open_count) == 0) {
79939 /* We need the spinlock_irqsave here because we can still
79940 have IRQs at this point */
79941 spin_lock_irqsave(&mts->lock, flags);
79942 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79943
79944 msleep(500);
79945
79946 - } else if (mts->open_count < 0)
79947 - mts->open_count = 0;
79948 + } else if (local_read(&mts->open_count) < 0)
79949 + local_set(&mts->open_count, 0);
79950
79951 return 0;
79952 }
79953 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79954 index b953fb4..1999c01 100644
79955 --- a/sound/drivers/opl4/opl4_lib.c
79956 +++ b/sound/drivers/opl4/opl4_lib.c
79957 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79958 MODULE_DESCRIPTION("OPL4 driver");
79959 MODULE_LICENSE("GPL");
79960
79961 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79962 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79963 {
79964 int timeout = 10;
79965 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79966 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79967 index 3e32bd3..46fc152 100644
79968 --- a/sound/drivers/portman2x4.c
79969 +++ b/sound/drivers/portman2x4.c
79970 @@ -48,6 +48,7 @@
79971 #include <sound/initval.h>
79972 #include <sound/rawmidi.h>
79973 #include <sound/control.h>
79974 +#include <asm/local.h>
79975
79976 #define CARD_NAME "Portman 2x4"
79977 #define DRIVER_NAME "portman"
79978 @@ -85,7 +86,7 @@ struct portman {
79979 struct pardevice *pardev;
79980 int pardev_claimed;
79981
79982 - int open_count;
79983 + local_t open_count;
79984 int mode[PORTMAN_NUM_INPUT_PORTS];
79985 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79986 };
79987 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79988 index 87657dd..a8268d4 100644
79989 --- a/sound/firewire/amdtp.c
79990 +++ b/sound/firewire/amdtp.c
79991 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79992 ptr = s->pcm_buffer_pointer + data_blocks;
79993 if (ptr >= pcm->runtime->buffer_size)
79994 ptr -= pcm->runtime->buffer_size;
79995 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79996 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79997
79998 s->pcm_period_pointer += data_blocks;
79999 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80000 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80001 */
80002 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80003 {
80004 - ACCESS_ONCE(s->source_node_id_field) =
80005 + ACCESS_ONCE_RW(s->source_node_id_field) =
80006 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80007 }
80008 EXPORT_SYMBOL(amdtp_out_stream_update);
80009 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80010 index 537a9cb..8e8c8e9 100644
80011 --- a/sound/firewire/amdtp.h
80012 +++ b/sound/firewire/amdtp.h
80013 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
80014 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80015 struct snd_pcm_substream *pcm)
80016 {
80017 - ACCESS_ONCE(s->pcm) = pcm;
80018 + ACCESS_ONCE_RW(s->pcm) = pcm;
80019 }
80020
80021 /**
80022 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80023 index cd094ec..eca1277 100644
80024 --- a/sound/firewire/isight.c
80025 +++ b/sound/firewire/isight.c
80026 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80027 ptr += count;
80028 if (ptr >= runtime->buffer_size)
80029 ptr -= runtime->buffer_size;
80030 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80031 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80032
80033 isight->period_counter += count;
80034 if (isight->period_counter >= runtime->period_size) {
80035 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80036 if (err < 0)
80037 return err;
80038
80039 - ACCESS_ONCE(isight->pcm_active) = true;
80040 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80041
80042 return 0;
80043 }
80044 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80045 {
80046 struct isight *isight = substream->private_data;
80047
80048 - ACCESS_ONCE(isight->pcm_active) = false;
80049 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80050
80051 mutex_lock(&isight->mutex);
80052 isight_stop_streaming(isight);
80053 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80054
80055 switch (cmd) {
80056 case SNDRV_PCM_TRIGGER_START:
80057 - ACCESS_ONCE(isight->pcm_running) = true;
80058 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80059 break;
80060 case SNDRV_PCM_TRIGGER_STOP:
80061 - ACCESS_ONCE(isight->pcm_running) = false;
80062 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80063 break;
80064 default:
80065 return -EINVAL;
80066 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80067 index 7bd5e33..1fcab12 100644
80068 --- a/sound/isa/cmi8330.c
80069 +++ b/sound/isa/cmi8330.c
80070 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80071
80072 struct snd_pcm *pcm;
80073 struct snd_cmi8330_stream {
80074 - struct snd_pcm_ops ops;
80075 + snd_pcm_ops_no_const ops;
80076 snd_pcm_open_callback_t open;
80077 void *private_data; /* sb or wss */
80078 } streams[2];
80079 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80080 index 733b014..56ce96f 100644
80081 --- a/sound/oss/sb_audio.c
80082 +++ b/sound/oss/sb_audio.c
80083 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80084 buf16 = (signed short *)(localbuf + localoffs);
80085 while (c)
80086 {
80087 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80088 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80089 if (copy_from_user(lbuf8,
80090 userbuf+useroffs + p,
80091 locallen))
80092 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80093 index 09d4648..cf234c7 100644
80094 --- a/sound/oss/swarm_cs4297a.c
80095 +++ b/sound/oss/swarm_cs4297a.c
80096 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80097 {
80098 struct cs4297a_state *s;
80099 u32 pwr, id;
80100 - mm_segment_t fs;
80101 int rval;
80102 #ifndef CONFIG_BCM_CS4297A_CSWARM
80103 u64 cfg;
80104 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80105 if (!rval) {
80106 char *sb1250_duart_present;
80107
80108 +#if 0
80109 + mm_segment_t fs;
80110 fs = get_fs();
80111 set_fs(KERNEL_DS);
80112 -#if 0
80113 val = SOUND_MASK_LINE;
80114 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80115 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80116 val = initvol[i].vol;
80117 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80118 }
80119 + set_fs(fs);
80120 // cs4297a_write_ac97(s, 0x18, 0x0808);
80121 #else
80122 // cs4297a_write_ac97(s, 0x5e, 0x180);
80123 cs4297a_write_ac97(s, 0x02, 0x0808);
80124 cs4297a_write_ac97(s, 0x18, 0x0808);
80125 #endif
80126 - set_fs(fs);
80127
80128 list_add(&s->list, &cs4297a_devs);
80129
80130 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80131 index f0f1943..8e1f96c 100644
80132 --- a/sound/pci/hda/hda_codec.h
80133 +++ b/sound/pci/hda/hda_codec.h
80134 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80135 /* notify power-up/down from codec to controller */
80136 void (*pm_notify)(struct hda_bus *bus);
80137 #endif
80138 -};
80139 +} __no_const;
80140
80141 /* template to pass to the bus constructor */
80142 struct hda_bus_template {
80143 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80144 #endif
80145 void (*reboot_notify)(struct hda_codec *codec);
80146 };
80147 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80148
80149 /* record for amp information cache */
80150 struct hda_cache_head {
80151 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80152 struct snd_pcm_substream *substream);
80153 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80154 struct snd_pcm_substream *substream);
80155 -};
80156 +} __no_const;
80157
80158 /* PCM information for each substream */
80159 struct hda_pcm_stream {
80160 @@ -801,7 +802,7 @@ struct hda_codec {
80161 const char *modelname; /* model name for preset */
80162
80163 /* set by patch */
80164 - struct hda_codec_ops patch_ops;
80165 + hda_codec_ops_no_const patch_ops;
80166
80167 /* PCM to create, set by patch_ops.build_pcms callback */
80168 unsigned int num_pcms;
80169 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80170 index 0da778a..bc38b84 100644
80171 --- a/sound/pci/ice1712/ice1712.h
80172 +++ b/sound/pci/ice1712/ice1712.h
80173 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80174 unsigned int mask_flags; /* total mask bits */
80175 struct snd_akm4xxx_ops {
80176 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80177 - } ops;
80178 + } __no_const ops;
80179 };
80180
80181 struct snd_ice1712_spdif {
80182 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80183 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80184 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80185 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80186 - } ops;
80187 + } __no_const ops;
80188 };
80189
80190
80191 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80192 index 12a9a2b..2b6138f 100644
80193 --- a/sound/pci/ymfpci/ymfpci_main.c
80194 +++ b/sound/pci/ymfpci/ymfpci_main.c
80195 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80196 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80197 break;
80198 }
80199 - if (atomic_read(&chip->interrupt_sleep_count)) {
80200 - atomic_set(&chip->interrupt_sleep_count, 0);
80201 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80202 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80203 wake_up(&chip->interrupt_sleep);
80204 }
80205 __end:
80206 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80207 continue;
80208 init_waitqueue_entry(&wait, current);
80209 add_wait_queue(&chip->interrupt_sleep, &wait);
80210 - atomic_inc(&chip->interrupt_sleep_count);
80211 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80212 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80213 remove_wait_queue(&chip->interrupt_sleep, &wait);
80214 }
80215 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80216 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80217 spin_unlock(&chip->reg_lock);
80218
80219 - if (atomic_read(&chip->interrupt_sleep_count)) {
80220 - atomic_set(&chip->interrupt_sleep_count, 0);
80221 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80222 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80223 wake_up(&chip->interrupt_sleep);
80224 }
80225 }
80226 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80227 spin_lock_init(&chip->reg_lock);
80228 spin_lock_init(&chip->voice_lock);
80229 init_waitqueue_head(&chip->interrupt_sleep);
80230 - atomic_set(&chip->interrupt_sleep_count, 0);
80231 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80232 chip->card = card;
80233 chip->pci = pci;
80234 chip->irq = -1;
80235 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80236 index cdc860a..db34a93 100644
80237 --- a/sound/soc/soc-pcm.c
80238 +++ b/sound/soc/soc-pcm.c
80239 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80240 struct snd_soc_platform *platform = rtd->platform;
80241 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80242 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80243 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80244 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80245 struct snd_pcm *pcm;
80246 char new_name[64];
80247 int ret = 0, playback = 0, capture = 0;
80248 diff --git a/sound/usb/card.h b/sound/usb/card.h
80249 index da5fa1a..113cd02 100644
80250 --- a/sound/usb/card.h
80251 +++ b/sound/usb/card.h
80252 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80253 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80254 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80255 };
80256 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80257
80258 struct snd_usb_substream {
80259 struct snd_usb_stream *stream;
80260 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80261 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80262 spinlock_t lock;
80263
80264 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80265 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80266 int last_frame_number; /* stored frame number */
80267 int last_delay; /* stored delay */
80268 };
80269 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80270 new file mode 100644
80271 index 0000000..ca64170
80272 --- /dev/null
80273 +++ b/tools/gcc/Makefile
80274 @@ -0,0 +1,26 @@
80275 +#CC := gcc
80276 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80277 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80278 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80279 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80280 +
80281 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80282 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80283 +
80284 +hostlibs-y := constify_plugin.so
80285 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80286 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80287 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80288 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80289 +hostlibs-y += colorize_plugin.so
80290 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80291 +
80292 +always := $(hostlibs-y)
80293 +
80294 +constify_plugin-objs := constify_plugin.o
80295 +stackleak_plugin-objs := stackleak_plugin.o
80296 +kallocstat_plugin-objs := kallocstat_plugin.o
80297 +kernexec_plugin-objs := kernexec_plugin.o
80298 +checker_plugin-objs := checker_plugin.o
80299 +colorize_plugin-objs := colorize_plugin.o
80300 +size_overflow_plugin-objs := size_overflow_plugin.o
80301 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80302 new file mode 100644
80303 index 0000000..d41b5af
80304 --- /dev/null
80305 +++ b/tools/gcc/checker_plugin.c
80306 @@ -0,0 +1,171 @@
80307 +/*
80308 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80309 + * Licensed under the GPL v2
80310 + *
80311 + * Note: the choice of the license means that the compilation process is
80312 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80313 + * but for the kernel it doesn't matter since it doesn't link against
80314 + * any of the gcc libraries
80315 + *
80316 + * gcc plugin to implement various sparse (source code checker) features
80317 + *
80318 + * TODO:
80319 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80320 + *
80321 + * BUGS:
80322 + * - none known
80323 + */
80324 +#include "gcc-plugin.h"
80325 +#include "config.h"
80326 +#include "system.h"
80327 +#include "coretypes.h"
80328 +#include "tree.h"
80329 +#include "tree-pass.h"
80330 +#include "flags.h"
80331 +#include "intl.h"
80332 +#include "toplev.h"
80333 +#include "plugin.h"
80334 +//#include "expr.h" where are you...
80335 +#include "diagnostic.h"
80336 +#include "plugin-version.h"
80337 +#include "tm.h"
80338 +#include "function.h"
80339 +#include "basic-block.h"
80340 +#include "gimple.h"
80341 +#include "rtl.h"
80342 +#include "emit-rtl.h"
80343 +#include "tree-flow.h"
80344 +#include "target.h"
80345 +
80346 +extern void c_register_addr_space (const char *str, addr_space_t as);
80347 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80348 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80349 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80350 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80351 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80352 +
80353 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80354 +extern rtx emit_move_insn(rtx x, rtx y);
80355 +
80356 +int plugin_is_GPL_compatible;
80357 +
80358 +static struct plugin_info checker_plugin_info = {
80359 + .version = "201111150100",
80360 +};
80361 +
80362 +#define ADDR_SPACE_KERNEL 0
80363 +#define ADDR_SPACE_FORCE_KERNEL 1
80364 +#define ADDR_SPACE_USER 2
80365 +#define ADDR_SPACE_FORCE_USER 3
80366 +#define ADDR_SPACE_IOMEM 0
80367 +#define ADDR_SPACE_FORCE_IOMEM 0
80368 +#define ADDR_SPACE_PERCPU 0
80369 +#define ADDR_SPACE_FORCE_PERCPU 0
80370 +#define ADDR_SPACE_RCU 0
80371 +#define ADDR_SPACE_FORCE_RCU 0
80372 +
80373 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80374 +{
80375 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80376 +}
80377 +
80378 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80379 +{
80380 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80381 +}
80382 +
80383 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80384 +{
80385 + return default_addr_space_valid_pointer_mode(mode, as);
80386 +}
80387 +
80388 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80389 +{
80390 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80391 +}
80392 +
80393 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80394 +{
80395 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80396 +}
80397 +
80398 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80399 +{
80400 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80401 + return true;
80402 +
80403 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80404 + return true;
80405 +
80406 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80407 + return true;
80408 +
80409 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80410 + return true;
80411 +
80412 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80413 + return true;
80414 +
80415 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80416 + return true;
80417 +
80418 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80419 + return true;
80420 +
80421 + return subset == superset;
80422 +}
80423 +
80424 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80425 +{
80426 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80427 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80428 +
80429 + return op;
80430 +}
80431 +
80432 +static void register_checker_address_spaces(void *event_data, void *data)
80433 +{
80434 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80435 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80436 + c_register_addr_space("__user", ADDR_SPACE_USER);
80437 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80438 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80439 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80440 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80441 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80442 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80443 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80444 +
80445 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80446 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80447 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80448 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80449 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80450 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80451 + targetm.addr_space.convert = checker_addr_space_convert;
80452 +}
80453 +
80454 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80455 +{
80456 + const char * const plugin_name = plugin_info->base_name;
80457 + const int argc = plugin_info->argc;
80458 + const struct plugin_argument * const argv = plugin_info->argv;
80459 + int i;
80460 +
80461 + if (!plugin_default_version_check(version, &gcc_version)) {
80462 + error(G_("incompatible gcc/plugin versions"));
80463 + return 1;
80464 + }
80465 +
80466 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80467 +
80468 + for (i = 0; i < argc; ++i)
80469 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80470 +
80471 + if (TARGET_64BIT == 0)
80472 + return 0;
80473 +
80474 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80475 +
80476 + return 0;
80477 +}
80478 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80479 new file mode 100644
80480 index 0000000..ee950d0
80481 --- /dev/null
80482 +++ b/tools/gcc/colorize_plugin.c
80483 @@ -0,0 +1,147 @@
80484 +/*
80485 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80486 + * Licensed under the GPL v2
80487 + *
80488 + * Note: the choice of the license means that the compilation process is
80489 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80490 + * but for the kernel it doesn't matter since it doesn't link against
80491 + * any of the gcc libraries
80492 + *
80493 + * gcc plugin to colorize diagnostic output
80494 + *
80495 + */
80496 +
80497 +#include "gcc-plugin.h"
80498 +#include "config.h"
80499 +#include "system.h"
80500 +#include "coretypes.h"
80501 +#include "tree.h"
80502 +#include "tree-pass.h"
80503 +#include "flags.h"
80504 +#include "intl.h"
80505 +#include "toplev.h"
80506 +#include "plugin.h"
80507 +#include "diagnostic.h"
80508 +#include "plugin-version.h"
80509 +#include "tm.h"
80510 +
80511 +int plugin_is_GPL_compatible;
80512 +
80513 +static struct plugin_info colorize_plugin_info = {
80514 + .version = "201203092200",
80515 +};
80516 +
80517 +#define GREEN "\033[32m\033[2m"
80518 +#define LIGHTGREEN "\033[32m\033[1m"
80519 +#define YELLOW "\033[33m\033[2m"
80520 +#define LIGHTYELLOW "\033[33m\033[1m"
80521 +#define RED "\033[31m\033[2m"
80522 +#define LIGHTRED "\033[31m\033[1m"
80523 +#define BLUE "\033[34m\033[2m"
80524 +#define LIGHTBLUE "\033[34m\033[1m"
80525 +#define BRIGHT "\033[m\033[1m"
80526 +#define NORMAL "\033[m"
80527 +
80528 +static diagnostic_starter_fn old_starter;
80529 +static diagnostic_finalizer_fn old_finalizer;
80530 +
80531 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80532 +{
80533 + const char *color;
80534 + char *newprefix;
80535 +
80536 + switch (diagnostic->kind) {
80537 + case DK_NOTE:
80538 + color = LIGHTBLUE;
80539 + break;
80540 +
80541 + case DK_PEDWARN:
80542 + case DK_WARNING:
80543 + color = LIGHTYELLOW;
80544 + break;
80545 +
80546 + case DK_ERROR:
80547 + case DK_FATAL:
80548 + case DK_ICE:
80549 + case DK_PERMERROR:
80550 + case DK_SORRY:
80551 + color = LIGHTRED;
80552 + break;
80553 +
80554 + default:
80555 + color = NORMAL;
80556 + }
80557 +
80558 + old_starter(context, diagnostic);
80559 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80560 + return;
80561 + pp_destroy_prefix(context->printer);
80562 + pp_set_prefix(context->printer, newprefix);
80563 +}
80564 +
80565 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80566 +{
80567 + old_finalizer(context, diagnostic);
80568 +}
80569 +
80570 +static void colorize_arm(void)
80571 +{
80572 + old_starter = diagnostic_starter(global_dc);
80573 + old_finalizer = diagnostic_finalizer(global_dc);
80574 +
80575 + diagnostic_starter(global_dc) = start_colorize;
80576 + diagnostic_finalizer(global_dc) = finalize_colorize;
80577 +}
80578 +
80579 +static unsigned int execute_colorize_rearm(void)
80580 +{
80581 + if (diagnostic_starter(global_dc) == start_colorize)
80582 + return 0;
80583 +
80584 + colorize_arm();
80585 + return 0;
80586 +}
80587 +
80588 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80589 + .pass = {
80590 + .type = SIMPLE_IPA_PASS,
80591 + .name = "colorize_rearm",
80592 + .gate = NULL,
80593 + .execute = execute_colorize_rearm,
80594 + .sub = NULL,
80595 + .next = NULL,
80596 + .static_pass_number = 0,
80597 + .tv_id = TV_NONE,
80598 + .properties_required = 0,
80599 + .properties_provided = 0,
80600 + .properties_destroyed = 0,
80601 + .todo_flags_start = 0,
80602 + .todo_flags_finish = 0
80603 + }
80604 +};
80605 +
80606 +static void colorize_start_unit(void *gcc_data, void *user_data)
80607 +{
80608 + colorize_arm();
80609 +}
80610 +
80611 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80612 +{
80613 + const char * const plugin_name = plugin_info->base_name;
80614 + struct register_pass_info colorize_rearm_pass_info = {
80615 + .pass = &pass_ipa_colorize_rearm.pass,
80616 + .reference_pass_name = "*free_lang_data",
80617 + .ref_pass_instance_number = 0,
80618 + .pos_op = PASS_POS_INSERT_AFTER
80619 + };
80620 +
80621 + if (!plugin_default_version_check(version, &gcc_version)) {
80622 + error(G_("incompatible gcc/plugin versions"));
80623 + return 1;
80624 + }
80625 +
80626 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80627 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80628 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80629 + return 0;
80630 +}
80631 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80632 new file mode 100644
80633 index 0000000..704a564
80634 --- /dev/null
80635 +++ b/tools/gcc/constify_plugin.c
80636 @@ -0,0 +1,303 @@
80637 +/*
80638 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80639 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80640 + * Licensed under the GPL v2, or (at your option) v3
80641 + *
80642 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80643 + *
80644 + * Homepage:
80645 + * http://www.grsecurity.net/~ephox/const_plugin/
80646 + *
80647 + * Usage:
80648 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80649 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80650 + */
80651 +
80652 +#include "gcc-plugin.h"
80653 +#include "config.h"
80654 +#include "system.h"
80655 +#include "coretypes.h"
80656 +#include "tree.h"
80657 +#include "tree-pass.h"
80658 +#include "flags.h"
80659 +#include "intl.h"
80660 +#include "toplev.h"
80661 +#include "plugin.h"
80662 +#include "diagnostic.h"
80663 +#include "plugin-version.h"
80664 +#include "tm.h"
80665 +#include "function.h"
80666 +#include "basic-block.h"
80667 +#include "gimple.h"
80668 +#include "rtl.h"
80669 +#include "emit-rtl.h"
80670 +#include "tree-flow.h"
80671 +
80672 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80673 +
80674 +int plugin_is_GPL_compatible;
80675 +
80676 +static struct plugin_info const_plugin_info = {
80677 + .version = "201111150100",
80678 + .help = "no-constify\tturn off constification\n",
80679 +};
80680 +
80681 +static void constify_type(tree type);
80682 +static bool walk_struct(tree node);
80683 +
80684 +static tree deconstify_type(tree old_type)
80685 +{
80686 + tree new_type, field;
80687 +
80688 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80689 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80690 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80691 + DECL_FIELD_CONTEXT(field) = new_type;
80692 + TYPE_READONLY(new_type) = 0;
80693 + C_TYPE_FIELDS_READONLY(new_type) = 0;
80694 + return new_type;
80695 +}
80696 +
80697 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80698 +{
80699 + tree type;
80700 +
80701 + *no_add_attrs = true;
80702 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80703 + error("%qE attribute does not apply to functions", name);
80704 + return NULL_TREE;
80705 + }
80706 +
80707 + if (TREE_CODE(*node) == VAR_DECL) {
80708 + error("%qE attribute does not apply to variables", name);
80709 + return NULL_TREE;
80710 + }
80711 +
80712 + if (TYPE_P(*node)) {
80713 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80714 + *no_add_attrs = false;
80715 + else
80716 + error("%qE attribute applies to struct and union types only", name);
80717 + return NULL_TREE;
80718 + }
80719 +
80720 + type = TREE_TYPE(*node);
80721 +
80722 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80723 + error("%qE attribute applies to struct and union types only", name);
80724 + return NULL_TREE;
80725 + }
80726 +
80727 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80728 + error("%qE attribute is already applied to the type", name);
80729 + return NULL_TREE;
80730 + }
80731 +
80732 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80733 + error("%qE attribute used on type that is not constified", name);
80734 + return NULL_TREE;
80735 + }
80736 +
80737 + if (TREE_CODE(*node) == TYPE_DECL) {
80738 + TREE_TYPE(*node) = deconstify_type(type);
80739 + TREE_READONLY(*node) = 0;
80740 + return NULL_TREE;
80741 + }
80742 +
80743 + return NULL_TREE;
80744 +}
80745 +
80746 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80747 +{
80748 + *no_add_attrs = true;
80749 + if (!TYPE_P(*node)) {
80750 + error("%qE attribute applies to types only", name);
80751 + return NULL_TREE;
80752 + }
80753 +
80754 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80755 + error("%qE attribute applies to struct and union types only", name);
80756 + return NULL_TREE;
80757 + }
80758 +
80759 + *no_add_attrs = false;
80760 + constify_type(*node);
80761 + return NULL_TREE;
80762 +}
80763 +
80764 +static struct attribute_spec no_const_attr = {
80765 + .name = "no_const",
80766 + .min_length = 0,
80767 + .max_length = 0,
80768 + .decl_required = false,
80769 + .type_required = false,
80770 + .function_type_required = false,
80771 + .handler = handle_no_const_attribute,
80772 +#if BUILDING_GCC_VERSION >= 4007
80773 + .affects_type_identity = true
80774 +#endif
80775 +};
80776 +
80777 +static struct attribute_spec do_const_attr = {
80778 + .name = "do_const",
80779 + .min_length = 0,
80780 + .max_length = 0,
80781 + .decl_required = false,
80782 + .type_required = false,
80783 + .function_type_required = false,
80784 + .handler = handle_do_const_attribute,
80785 +#if BUILDING_GCC_VERSION >= 4007
80786 + .affects_type_identity = true
80787 +#endif
80788 +};
80789 +
80790 +static void register_attributes(void *event_data, void *data)
80791 +{
80792 + register_attribute(&no_const_attr);
80793 + register_attribute(&do_const_attr);
80794 +}
80795 +
80796 +static void constify_type(tree type)
80797 +{
80798 + TYPE_READONLY(type) = 1;
80799 + C_TYPE_FIELDS_READONLY(type) = 1;
80800 +}
80801 +
80802 +static bool is_fptr(tree field)
80803 +{
80804 + tree ptr = TREE_TYPE(field);
80805 +
80806 + if (TREE_CODE(ptr) != POINTER_TYPE)
80807 + return false;
80808 +
80809 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80810 +}
80811 +
80812 +static bool walk_struct(tree node)
80813 +{
80814 + tree field;
80815 +
80816 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
80817 + return false;
80818 +
80819 + if (TYPE_FIELDS(node) == NULL_TREE)
80820 + return false;
80821 +
80822 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80823 + tree type = TREE_TYPE(field);
80824 + enum tree_code code = TREE_CODE(type);
80825 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80826 + if (!(walk_struct(type)))
80827 + return false;
80828 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80829 + return false;
80830 + }
80831 + return true;
80832 +}
80833 +
80834 +static void finish_type(void *event_data, void *data)
80835 +{
80836 + tree type = (tree)event_data;
80837 +
80838 + if (type == NULL_TREE)
80839 + return;
80840 +
80841 + if (TYPE_READONLY(type))
80842 + return;
80843 +
80844 + if (walk_struct(type))
80845 + constify_type(type);
80846 +}
80847 +
80848 +static unsigned int check_local_variables(void);
80849 +
80850 +struct gimple_opt_pass pass_local_variable = {
80851 + {
80852 + .type = GIMPLE_PASS,
80853 + .name = "check_local_variables",
80854 + .gate = NULL,
80855 + .execute = check_local_variables,
80856 + .sub = NULL,
80857 + .next = NULL,
80858 + .static_pass_number = 0,
80859 + .tv_id = TV_NONE,
80860 + .properties_required = 0,
80861 + .properties_provided = 0,
80862 + .properties_destroyed = 0,
80863 + .todo_flags_start = 0,
80864 + .todo_flags_finish = 0
80865 + }
80866 +};
80867 +
80868 +static unsigned int check_local_variables(void)
80869 +{
80870 + tree var;
80871 + referenced_var_iterator rvi;
80872 +
80873 +#if BUILDING_GCC_VERSION == 4005
80874 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80875 +#else
80876 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80877 +#endif
80878 + tree type = TREE_TYPE(var);
80879 +
80880 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80881 + continue;
80882 +
80883 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80884 + continue;
80885 +
80886 + if (!TYPE_READONLY(type))
80887 + continue;
80888 +
80889 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80890 +// continue;
80891 +
80892 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80893 +// continue;
80894 +
80895 + if (walk_struct(type)) {
80896 + error("constified variable %qE cannot be local", var);
80897 + return 1;
80898 + }
80899 + }
80900 + return 0;
80901 +}
80902 +
80903 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80904 +{
80905 + const char * const plugin_name = plugin_info->base_name;
80906 + const int argc = plugin_info->argc;
80907 + const struct plugin_argument * const argv = plugin_info->argv;
80908 + int i;
80909 + bool constify = true;
80910 +
80911 + struct register_pass_info local_variable_pass_info = {
80912 + .pass = &pass_local_variable.pass,
80913 + .reference_pass_name = "*referenced_vars",
80914 + .ref_pass_instance_number = 0,
80915 + .pos_op = PASS_POS_INSERT_AFTER
80916 + };
80917 +
80918 + if (!plugin_default_version_check(version, &gcc_version)) {
80919 + error(G_("incompatible gcc/plugin versions"));
80920 + return 1;
80921 + }
80922 +
80923 + for (i = 0; i < argc; ++i) {
80924 + if (!(strcmp(argv[i].key, "no-constify"))) {
80925 + constify = false;
80926 + continue;
80927 + }
80928 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80929 + }
80930 +
80931 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80932 + if (constify) {
80933 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80934 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80935 + }
80936 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80937 +
80938 + return 0;
80939 +}
80940 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80941 new file mode 100644
80942 index 0000000..a5eabce
80943 --- /dev/null
80944 +++ b/tools/gcc/kallocstat_plugin.c
80945 @@ -0,0 +1,167 @@
80946 +/*
80947 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80948 + * Licensed under the GPL v2
80949 + *
80950 + * Note: the choice of the license means that the compilation process is
80951 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80952 + * but for the kernel it doesn't matter since it doesn't link against
80953 + * any of the gcc libraries
80954 + *
80955 + * gcc plugin to find the distribution of k*alloc sizes
80956 + *
80957 + * TODO:
80958 + *
80959 + * BUGS:
80960 + * - none known
80961 + */
80962 +#include "gcc-plugin.h"
80963 +#include "config.h"
80964 +#include "system.h"
80965 +#include "coretypes.h"
80966 +#include "tree.h"
80967 +#include "tree-pass.h"
80968 +#include "flags.h"
80969 +#include "intl.h"
80970 +#include "toplev.h"
80971 +#include "plugin.h"
80972 +//#include "expr.h" where are you...
80973 +#include "diagnostic.h"
80974 +#include "plugin-version.h"
80975 +#include "tm.h"
80976 +#include "function.h"
80977 +#include "basic-block.h"
80978 +#include "gimple.h"
80979 +#include "rtl.h"
80980 +#include "emit-rtl.h"
80981 +
80982 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80983 +
80984 +int plugin_is_GPL_compatible;
80985 +
80986 +static const char * const kalloc_functions[] = {
80987 + "__kmalloc",
80988 + "kmalloc",
80989 + "kmalloc_large",
80990 + "kmalloc_node",
80991 + "kmalloc_order",
80992 + "kmalloc_order_trace",
80993 + "kmalloc_slab",
80994 + "kzalloc",
80995 + "kzalloc_node",
80996 +};
80997 +
80998 +static struct plugin_info kallocstat_plugin_info = {
80999 + .version = "201111150100",
81000 +};
81001 +
81002 +static unsigned int execute_kallocstat(void);
81003 +
81004 +static struct gimple_opt_pass kallocstat_pass = {
81005 + .pass = {
81006 + .type = GIMPLE_PASS,
81007 + .name = "kallocstat",
81008 + .gate = NULL,
81009 + .execute = execute_kallocstat,
81010 + .sub = NULL,
81011 + .next = NULL,
81012 + .static_pass_number = 0,
81013 + .tv_id = TV_NONE,
81014 + .properties_required = 0,
81015 + .properties_provided = 0,
81016 + .properties_destroyed = 0,
81017 + .todo_flags_start = 0,
81018 + .todo_flags_finish = 0
81019 + }
81020 +};
81021 +
81022 +static bool is_kalloc(const char *fnname)
81023 +{
81024 + size_t i;
81025 +
81026 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81027 + if (!strcmp(fnname, kalloc_functions[i]))
81028 + return true;
81029 + return false;
81030 +}
81031 +
81032 +static unsigned int execute_kallocstat(void)
81033 +{
81034 + basic_block bb;
81035 +
81036 + // 1. loop through BBs and GIMPLE statements
81037 + FOR_EACH_BB(bb) {
81038 + gimple_stmt_iterator gsi;
81039 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81040 + // gimple match:
81041 + tree fndecl, size;
81042 + gimple call_stmt;
81043 + const char *fnname;
81044 +
81045 + // is it a call
81046 + call_stmt = gsi_stmt(gsi);
81047 + if (!is_gimple_call(call_stmt))
81048 + continue;
81049 + fndecl = gimple_call_fndecl(call_stmt);
81050 + if (fndecl == NULL_TREE)
81051 + continue;
81052 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81053 + continue;
81054 +
81055 + // is it a call to k*alloc
81056 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81057 + if (!is_kalloc(fnname))
81058 + continue;
81059 +
81060 + // is the size arg the result of a simple const assignment
81061 + size = gimple_call_arg(call_stmt, 0);
81062 + while (true) {
81063 + gimple def_stmt;
81064 + expanded_location xloc;
81065 + size_t size_val;
81066 +
81067 + if (TREE_CODE(size) != SSA_NAME)
81068 + break;
81069 + def_stmt = SSA_NAME_DEF_STMT(size);
81070 + if (!def_stmt || !is_gimple_assign(def_stmt))
81071 + break;
81072 + if (gimple_num_ops(def_stmt) != 2)
81073 + break;
81074 + size = gimple_assign_rhs1(def_stmt);
81075 + if (!TREE_CONSTANT(size))
81076 + continue;
81077 + xloc = expand_location(gimple_location(def_stmt));
81078 + if (!xloc.file)
81079 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81080 + size_val = TREE_INT_CST_LOW(size);
81081 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81082 + break;
81083 + }
81084 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81085 +//debug_tree(gimple_call_fn(call_stmt));
81086 +//print_node(stderr, "pax", fndecl, 4);
81087 + }
81088 + }
81089 +
81090 + return 0;
81091 +}
81092 +
81093 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81094 +{
81095 + const char * const plugin_name = plugin_info->base_name;
81096 + struct register_pass_info kallocstat_pass_info = {
81097 + .pass = &kallocstat_pass.pass,
81098 + .reference_pass_name = "ssa",
81099 + .ref_pass_instance_number = 0,
81100 + .pos_op = PASS_POS_INSERT_AFTER
81101 + };
81102 +
81103 + if (!plugin_default_version_check(version, &gcc_version)) {
81104 + error(G_("incompatible gcc/plugin versions"));
81105 + return 1;
81106 + }
81107 +
81108 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81109 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81110 +
81111 + return 0;
81112 +}
81113 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81114 new file mode 100644
81115 index 0000000..d8a8da2
81116 --- /dev/null
81117 +++ b/tools/gcc/kernexec_plugin.c
81118 @@ -0,0 +1,427 @@
81119 +/*
81120 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81121 + * Licensed under the GPL v2
81122 + *
81123 + * Note: the choice of the license means that the compilation process is
81124 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81125 + * but for the kernel it doesn't matter since it doesn't link against
81126 + * any of the gcc libraries
81127 + *
81128 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81129 + *
81130 + * TODO:
81131 + *
81132 + * BUGS:
81133 + * - none known
81134 + */
81135 +#include "gcc-plugin.h"
81136 +#include "config.h"
81137 +#include "system.h"
81138 +#include "coretypes.h"
81139 +#include "tree.h"
81140 +#include "tree-pass.h"
81141 +#include "flags.h"
81142 +#include "intl.h"
81143 +#include "toplev.h"
81144 +#include "plugin.h"
81145 +//#include "expr.h" where are you...
81146 +#include "diagnostic.h"
81147 +#include "plugin-version.h"
81148 +#include "tm.h"
81149 +#include "function.h"
81150 +#include "basic-block.h"
81151 +#include "gimple.h"
81152 +#include "rtl.h"
81153 +#include "emit-rtl.h"
81154 +#include "tree-flow.h"
81155 +
81156 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81157 +extern rtx emit_move_insn(rtx x, rtx y);
81158 +
81159 +int plugin_is_GPL_compatible;
81160 +
81161 +static struct plugin_info kernexec_plugin_info = {
81162 + .version = "201111291120",
81163 + .help = "method=[bts|or]\tinstrumentation method\n"
81164 +};
81165 +
81166 +static unsigned int execute_kernexec_reload(void);
81167 +static unsigned int execute_kernexec_fptr(void);
81168 +static unsigned int execute_kernexec_retaddr(void);
81169 +static bool kernexec_cmodel_check(void);
81170 +
81171 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81172 +static void (*kernexec_instrument_retaddr)(rtx);
81173 +
81174 +static struct gimple_opt_pass kernexec_reload_pass = {
81175 + .pass = {
81176 + .type = GIMPLE_PASS,
81177 + .name = "kernexec_reload",
81178 + .gate = kernexec_cmodel_check,
81179 + .execute = execute_kernexec_reload,
81180 + .sub = NULL,
81181 + .next = NULL,
81182 + .static_pass_number = 0,
81183 + .tv_id = TV_NONE,
81184 + .properties_required = 0,
81185 + .properties_provided = 0,
81186 + .properties_destroyed = 0,
81187 + .todo_flags_start = 0,
81188 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81189 + }
81190 +};
81191 +
81192 +static struct gimple_opt_pass kernexec_fptr_pass = {
81193 + .pass = {
81194 + .type = GIMPLE_PASS,
81195 + .name = "kernexec_fptr",
81196 + .gate = kernexec_cmodel_check,
81197 + .execute = execute_kernexec_fptr,
81198 + .sub = NULL,
81199 + .next = NULL,
81200 + .static_pass_number = 0,
81201 + .tv_id = TV_NONE,
81202 + .properties_required = 0,
81203 + .properties_provided = 0,
81204 + .properties_destroyed = 0,
81205 + .todo_flags_start = 0,
81206 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81207 + }
81208 +};
81209 +
81210 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81211 + .pass = {
81212 + .type = RTL_PASS,
81213 + .name = "kernexec_retaddr",
81214 + .gate = kernexec_cmodel_check,
81215 + .execute = execute_kernexec_retaddr,
81216 + .sub = NULL,
81217 + .next = NULL,
81218 + .static_pass_number = 0,
81219 + .tv_id = TV_NONE,
81220 + .properties_required = 0,
81221 + .properties_provided = 0,
81222 + .properties_destroyed = 0,
81223 + .todo_flags_start = 0,
81224 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81225 + }
81226 +};
81227 +
81228 +static bool kernexec_cmodel_check(void)
81229 +{
81230 + tree section;
81231 +
81232 + if (ix86_cmodel != CM_KERNEL)
81233 + return false;
81234 +
81235 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81236 + if (!section || !TREE_VALUE(section))
81237 + return true;
81238 +
81239 + section = TREE_VALUE(TREE_VALUE(section));
81240 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81241 + return true;
81242 +
81243 + return false;
81244 +}
81245 +
81246 +/*
81247 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81248 + */
81249 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81250 +{
81251 + gimple asm_movabs_stmt;
81252 +
81253 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81254 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81255 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81256 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81257 + update_stmt(asm_movabs_stmt);
81258 +}
81259 +
81260 +/*
81261 + * find all asm() stmts that clobber r10 and add a reload of r10
81262 + */
81263 +static unsigned int execute_kernexec_reload(void)
81264 +{
81265 + basic_block bb;
81266 +
81267 + // 1. loop through BBs and GIMPLE statements
81268 + FOR_EACH_BB(bb) {
81269 + gimple_stmt_iterator gsi;
81270 +
81271 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81272 + // gimple match: __asm__ ("" : : : "r10");
81273 + gimple asm_stmt;
81274 + size_t nclobbers;
81275 +
81276 + // is it an asm ...
81277 + asm_stmt = gsi_stmt(gsi);
81278 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81279 + continue;
81280 +
81281 + // ... clobbering r10
81282 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81283 + while (nclobbers--) {
81284 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81285 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81286 + continue;
81287 + kernexec_reload_fptr_mask(&gsi);
81288 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81289 + break;
81290 + }
81291 + }
81292 + }
81293 +
81294 + return 0;
81295 +}
81296 +
81297 +/*
81298 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81299 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81300 + */
81301 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81302 +{
81303 + gimple assign_intptr, assign_new_fptr, call_stmt;
81304 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81305 +
81306 + call_stmt = gsi_stmt(*gsi);
81307 + old_fptr = gimple_call_fn(call_stmt);
81308 +
81309 + // create temporary unsigned long variable used for bitops and cast fptr to it
81310 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81311 + add_referenced_var(intptr);
81312 + mark_sym_for_renaming(intptr);
81313 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81314 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81315 + update_stmt(assign_intptr);
81316 +
81317 + // apply logical or to temporary unsigned long and bitmask
81318 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81319 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81320 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81321 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81322 + update_stmt(assign_intptr);
81323 +
81324 + // cast temporary unsigned long back to a temporary fptr variable
81325 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81326 + add_referenced_var(new_fptr);
81327 + mark_sym_for_renaming(new_fptr);
81328 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81329 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81330 + update_stmt(assign_new_fptr);
81331 +
81332 + // replace call stmt fn with the new fptr
81333 + gimple_call_set_fn(call_stmt, new_fptr);
81334 + update_stmt(call_stmt);
81335 +}
81336 +
81337 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81338 +{
81339 + gimple asm_or_stmt, call_stmt;
81340 + tree old_fptr, new_fptr, input, output;
81341 + VEC(tree, gc) *inputs = NULL;
81342 + VEC(tree, gc) *outputs = NULL;
81343 +
81344 + call_stmt = gsi_stmt(*gsi);
81345 + old_fptr = gimple_call_fn(call_stmt);
81346 +
81347 + // create temporary fptr variable
81348 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81349 + add_referenced_var(new_fptr);
81350 + mark_sym_for_renaming(new_fptr);
81351 +
81352 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81353 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81354 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81355 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81356 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81357 + VEC_safe_push(tree, gc, inputs, input);
81358 + VEC_safe_push(tree, gc, outputs, output);
81359 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81360 + gimple_asm_set_volatile(asm_or_stmt, true);
81361 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81362 + update_stmt(asm_or_stmt);
81363 +
81364 + // replace call stmt fn with the new fptr
81365 + gimple_call_set_fn(call_stmt, new_fptr);
81366 + update_stmt(call_stmt);
81367 +}
81368 +
81369 +/*
81370 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81371 + */
81372 +static unsigned int execute_kernexec_fptr(void)
81373 +{
81374 + basic_block bb;
81375 +
81376 + // 1. loop through BBs and GIMPLE statements
81377 + FOR_EACH_BB(bb) {
81378 + gimple_stmt_iterator gsi;
81379 +
81380 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81381 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81382 + tree fn;
81383 + gimple call_stmt;
81384 +
81385 + // is it a call ...
81386 + call_stmt = gsi_stmt(gsi);
81387 + if (!is_gimple_call(call_stmt))
81388 + continue;
81389 + fn = gimple_call_fn(call_stmt);
81390 + if (TREE_CODE(fn) == ADDR_EXPR)
81391 + continue;
81392 + if (TREE_CODE(fn) != SSA_NAME)
81393 + gcc_unreachable();
81394 +
81395 + // ... through a function pointer
81396 + fn = SSA_NAME_VAR(fn);
81397 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81398 + continue;
81399 + fn = TREE_TYPE(fn);
81400 + if (TREE_CODE(fn) != POINTER_TYPE)
81401 + continue;
81402 + fn = TREE_TYPE(fn);
81403 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81404 + continue;
81405 +
81406 + kernexec_instrument_fptr(&gsi);
81407 +
81408 +//debug_tree(gimple_call_fn(call_stmt));
81409 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81410 + }
81411 + }
81412 +
81413 + return 0;
81414 +}
81415 +
81416 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81417 +static void kernexec_instrument_retaddr_bts(rtx insn)
81418 +{
81419 + rtx btsq;
81420 + rtvec argvec, constraintvec, labelvec;
81421 + int line;
81422 +
81423 + // create asm volatile("btsq $63,(%%rsp)":::)
81424 + argvec = rtvec_alloc(0);
81425 + constraintvec = rtvec_alloc(0);
81426 + labelvec = rtvec_alloc(0);
81427 + line = expand_location(RTL_LOCATION(insn)).line;
81428 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81429 + MEM_VOLATILE_P(btsq) = 1;
81430 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81431 + emit_insn_before(btsq, insn);
81432 +}
81433 +
81434 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81435 +static void kernexec_instrument_retaddr_or(rtx insn)
81436 +{
81437 + rtx orq;
81438 + rtvec argvec, constraintvec, labelvec;
81439 + int line;
81440 +
81441 + // create asm volatile("orq %%r10,(%%rsp)":::)
81442 + argvec = rtvec_alloc(0);
81443 + constraintvec = rtvec_alloc(0);
81444 + labelvec = rtvec_alloc(0);
81445 + line = expand_location(RTL_LOCATION(insn)).line;
81446 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81447 + MEM_VOLATILE_P(orq) = 1;
81448 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81449 + emit_insn_before(orq, insn);
81450 +}
81451 +
81452 +/*
81453 + * find all asm level function returns and forcibly set the highest bit of the return address
81454 + */
81455 +static unsigned int execute_kernexec_retaddr(void)
81456 +{
81457 + rtx insn;
81458 +
81459 + // 1. find function returns
81460 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81461 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81462 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81463 + rtx body;
81464 +
81465 + // is it a retn
81466 + if (!JUMP_P(insn))
81467 + continue;
81468 + body = PATTERN(insn);
81469 + if (GET_CODE(body) == PARALLEL)
81470 + body = XVECEXP(body, 0, 0);
81471 + if (GET_CODE(body) != RETURN)
81472 + continue;
81473 + kernexec_instrument_retaddr(insn);
81474 + }
81475 +
81476 +// print_simple_rtl(stderr, get_insns());
81477 +// print_rtl(stderr, get_insns());
81478 +
81479 + return 0;
81480 +}
81481 +
81482 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81483 +{
81484 + const char * const plugin_name = plugin_info->base_name;
81485 + const int argc = plugin_info->argc;
81486 + const struct plugin_argument * const argv = plugin_info->argv;
81487 + int i;
81488 + struct register_pass_info kernexec_reload_pass_info = {
81489 + .pass = &kernexec_reload_pass.pass,
81490 + .reference_pass_name = "ssa",
81491 + .ref_pass_instance_number = 0,
81492 + .pos_op = PASS_POS_INSERT_AFTER
81493 + };
81494 + struct register_pass_info kernexec_fptr_pass_info = {
81495 + .pass = &kernexec_fptr_pass.pass,
81496 + .reference_pass_name = "ssa",
81497 + .ref_pass_instance_number = 0,
81498 + .pos_op = PASS_POS_INSERT_AFTER
81499 + };
81500 + struct register_pass_info kernexec_retaddr_pass_info = {
81501 + .pass = &kernexec_retaddr_pass.pass,
81502 + .reference_pass_name = "pro_and_epilogue",
81503 + .ref_pass_instance_number = 0,
81504 + .pos_op = PASS_POS_INSERT_AFTER
81505 + };
81506 +
81507 + if (!plugin_default_version_check(version, &gcc_version)) {
81508 + error(G_("incompatible gcc/plugin versions"));
81509 + return 1;
81510 + }
81511 +
81512 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81513 +
81514 + if (TARGET_64BIT == 0)
81515 + return 0;
81516 +
81517 + for (i = 0; i < argc; ++i) {
81518 + if (!strcmp(argv[i].key, "method")) {
81519 + if (!argv[i].value) {
81520 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81521 + continue;
81522 + }
81523 + if (!strcmp(argv[i].value, "bts")) {
81524 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81525 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81526 + } else if (!strcmp(argv[i].value, "or")) {
81527 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81528 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81529 + fix_register("r10", 1, 1);
81530 + } else
81531 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81532 + continue;
81533 + }
81534 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81535 + }
81536 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81537 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81538 +
81539 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81540 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81541 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81542 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81543 +
81544 + return 0;
81545 +}
81546 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81547 new file mode 100644
81548 index 0000000..16ccac1
81549 --- /dev/null
81550 +++ b/tools/gcc/size_overflow_hash1.h
81551 @@ -0,0 +1,3047 @@
81552 +struct size_overflow_hash size_overflow_hash1[65536] = {
81553 + [10013].file = "security/smack/smackfs.c",
81554 + [10013].name = "smk_write_direct",
81555 + [10013].param3 = 1,
81556 + [10167].file = "sound/core/oss/pcm_plugin.c",
81557 + [10167].name = "snd_pcm_plugin_build",
81558 + [10167].param5 = 1,
81559 + [1020].file = "drivers/usb/misc/usbtest.c",
81560 + [1020].name = "test_unaligned_bulk",
81561 + [1020].param3 = 1,
81562 + [1022].file = "sound/pci/rme9652/rme9652.c",
81563 + [1022].name = "snd_rme9652_playback_copy",
81564 + [1022].param5 = 1,
81565 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
81566 + [10321].name = "create_attr_set",
81567 + [10321].param1 = 1,
81568 + [10341].file = "fs/nfsd/nfs4xdr.c",
81569 + [10341].name = "read_buf",
81570 + [10341].param2 = 1,
81571 + [10357].file = "net/sunrpc/cache.c",
81572 + [10357].name = "cache_read",
81573 + [10357].param3 = 1,
81574 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81575 + [10397].name = "i915_wedged_write",
81576 + [10397].param3 = 1,
81577 + [10399].file = "kernel/trace/trace.c",
81578 + [10399].name = "trace_seq_to_user",
81579 + [10399].param3 = 1,
81580 + [10414].file = "drivers/tty/vt/vt.c",
81581 + [10414].name = "vc_do_resize",
81582 + [10414].param3 = 1,
81583 + [10414].param4 = 1,
81584 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81585 + [10565].name = "ad7879_spi_multi_read",
81586 + [10565].param3 = 1,
81587 + [10623].file = "drivers/infiniband/core/user_mad.c",
81588 + [10623].name = "ib_umad_write",
81589 + [10623].param3 = 1,
81590 + [10707].file = "fs/nfs/idmap.c",
81591 + [10707].name = "nfs_idmap_request_key",
81592 + [10707].param2 = 1,
81593 + [1073].file = "drivers/block/aoe/aoecmd.c",
81594 + [1073].name = "addtgt",
81595 + [1073].param3 = 1,
81596 + [10745].file = "fs/cifs/connect.c",
81597 + [10745].name = "get_server_iovec",
81598 + [10745].param2 = 1,
81599 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
81600 + [10750].name = "iwm_ntf_calib_res",
81601 + [10750].param3 = 1,
81602 + [10773].file = "drivers/input/mousedev.c",
81603 + [10773].name = "mousedev_read",
81604 + [10773].param3 = 1,
81605 + [10777].file = "fs/ntfs/file.c",
81606 + [10777].name = "ntfs_file_buffered_write",
81607 + [10777].param6 = 1,
81608 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
81609 + [10893].name = "options_write",
81610 + [10893].param3 = 1,
81611 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81612 + [10919].name = "do_arpt_set_ctl",
81613 + [10919].param4 = 1,
81614 + [1107].file = "mm/process_vm_access.c",
81615 + [1107].name = "process_vm_rw_single_vec",
81616 + [1107].param1 = 1,
81617 + [1107].param2 = 1,
81618 + [11230].file = "net/core/neighbour.c",
81619 + [11230].name = "neigh_hash_grow",
81620 + [11230].param2 = 1,
81621 + [11364].file = "fs/ext4/super.c",
81622 + [11364].name = "ext4_kvzalloc",
81623 + [11364].param1 = 1,
81624 + [114].file = "security/selinux/selinuxfs.c",
81625 + [114].name = "sel_write_relabel",
81626 + [114].param3 = 1,
81627 + [11549].file = "drivers/media/rc/redrat3.c",
81628 + [11549].name = "redrat3_transmit_ir",
81629 + [11549].param3 = 1,
81630 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
81631 + [11568].name = "drm_vmalloc_dma",
81632 + [11568].param1 = 1,
81633 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
81634 + [11582].name = "lpfc_sli4_queue_alloc",
81635 + [11582].param3 = 1,
81636 + [11616].file = "security/selinux/selinuxfs.c",
81637 + [11616].name = "sel_write_enforce",
81638 + [11616].param3 = 1,
81639 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81640 + [11699].name = "vxge_os_dma_malloc",
81641 + [11699].param2 = 1,
81642 + [11766].file = "drivers/block/paride/pt.c",
81643 + [11766].name = "pt_read",
81644 + [11766].param3 = 1,
81645 + [11784].file = "fs/bio.c",
81646 + [11784].name = "bio_kmalloc",
81647 + [11784].param2 = 1,
81648 + [11919].file = "drivers/lguest/core.c",
81649 + [11919].name = "__lgread",
81650 + [11919].param4 = 1,
81651 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
81652 + [11925].name = "cx18_copy_mdl_to_user",
81653 + [11925].param4 = 1,
81654 + [11985].file = "drivers/block/floppy.c",
81655 + [11985].name = "fd_copyin",
81656 + [11985].param3 = 1,
81657 + [11986].file = "drivers/net/usb/asix.c",
81658 + [11986].name = "asix_read_cmd",
81659 + [11986].param5 = 1,
81660 + [12018].file = "sound/core/oss/pcm_oss.c",
81661 + [12018].name = "snd_pcm_oss_read1",
81662 + [12018].param3 = 1,
81663 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
81664 + [12059].name = "lbs_debugfs_write",
81665 + [12059].param3 = 1,
81666 + [12151].file = "fs/compat.c",
81667 + [12151].name = "compat_rw_copy_check_uvector",
81668 + [12151].param3 = 1,
81669 + [12205].file = "fs/reiserfs/journal.c",
81670 + [12205].name = "reiserfs_allocate_list_bitmaps",
81671 + [12205].param3 = 1,
81672 + [12234].file = "include/acpi/platform/aclinux.h",
81673 + [12234].name = "acpi_os_allocate",
81674 + [12234].param1 = 1,
81675 + [1227].file = "lib/cpu_rmap.c",
81676 + [1227].name = "alloc_cpu_rmap",
81677 + [1227].param1 = 1,
81678 + [12395].file = "drivers/char/hw_random/core.c",
81679 + [12395].name = "rng_dev_read",
81680 + [12395].param3 = 1,
81681 + [12602].file = "net/sunrpc/cache.c",
81682 + [12602].name = "cache_downcall",
81683 + [12602].param3 = 1,
81684 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
81685 + [12712].name = "i2400m_zrealloc_2x",
81686 + [12712].param3 = 1,
81687 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
81688 + [12755].name = "snd_opl4_mem_proc_read",
81689 + [12755].param5 = 1,
81690 + [12833].file = "net/sctp/auth.c",
81691 + [12833].name = "sctp_auth_create_key",
81692 + [12833].param1 = 1,
81693 + [12840].file = "net/sctp/tsnmap.c",
81694 + [12840].name = "sctp_tsnmap_mark",
81695 + [12840].param2 = 1,
81696 + [12931].file = "drivers/hid/hid-roccat.c",
81697 + [12931].name = "roccat_read",
81698 + [12931].param3 = 1,
81699 + [12954].file = "fs/proc/base.c",
81700 + [12954].name = "oom_adjust_write",
81701 + [12954].param3 = 1,
81702 + [13103].file = "drivers/acpi/acpica/utobject.c",
81703 + [13103].name = "acpi_ut_create_string_object",
81704 + [13103].param1 = 1,
81705 + [13121].file = "net/ipv4/ip_sockglue.c",
81706 + [13121].name = "do_ip_setsockopt",
81707 + [13121].param5 = 1,
81708 + [1327].file = "net/netfilter/nfnetlink_log.c",
81709 + [1327].name = "nfulnl_alloc_skb",
81710 + [1327].param2 = 1,
81711 + [13337].file = "net/core/iovec.c",
81712 + [13337].name = "csum_partial_copy_fromiovecend",
81713 + [13337].param4 = 1,
81714 + [13339].file = "security/smack/smackfs.c",
81715 + [13339].name = "smk_write_netlbladdr",
81716 + [13339].param3 = 1,
81717 + [13342].file = "fs/jbd2/journal.c",
81718 + [13342].name = "jbd2_alloc",
81719 + [13342].param1 = 1,
81720 + [13384].file = "drivers/char/virtio_console.c",
81721 + [13384].name = "alloc_buf",
81722 + [13384].param1 = 1,
81723 + [13412].file = "fs/proc/base.c",
81724 + [13412].name = "oom_score_adj_write",
81725 + [13412].param3 = 1,
81726 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
81727 + [13559].name = "ivtv_read",
81728 + [13559].param3 = 1,
81729 + [13618].file = "drivers/net/team/team.c",
81730 + [13618].name = "team_options_register",
81731 + [13618].param3 = 1,
81732 + [13659].file = "drivers/net/wan/hdlc.c",
81733 + [13659].name = "attach_hdlc_protocol",
81734 + [13659].param3 = 1,
81735 + [13708].file = "drivers/usb/misc/usbtest.c",
81736 + [13708].name = "simple_alloc_urb",
81737 + [13708].param3 = 1,
81738 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
81739 + [13805].name = "altera_swap_dr",
81740 + [13805].param2 = 1,
81741 + [13868].file = "fs/lockd/mon.c",
81742 + [13868].name = "nsm_create_handle",
81743 + [13868].param4 = 1,
81744 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
81745 + [13924].name = "do_ipt_set_ctl",
81746 + [13924].param4 = 1,
81747 + [14019].file = "net/dns_resolver/dns_key.c",
81748 + [14019].name = "dns_resolver_instantiate",
81749 + [14019].param2 = 1,
81750 + [14019].param3 = 1,
81751 + [14025].file = "net/ax25/af_ax25.c",
81752 + [14025].name = "ax25_setsockopt",
81753 + [14025].param5 = 1,
81754 + [14029].file = "drivers/spi/spidev.c",
81755 + [14029].name = "spidev_compat_ioctl",
81756 + [14029].param2 = 1,
81757 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
81758 + [14090].name = "btmrvl_hsmode_write",
81759 + [14090].param3 = 1,
81760 + [14149].file = "drivers/hid/hidraw.c",
81761 + [14149].name = "hidraw_ioctl",
81762 + [14149].param2 = 1,
81763 + [14153].file = "drivers/staging/bcm/led_control.c",
81764 + [14153].name = "ValidateDSDParamsChecksum",
81765 + [14153].param3 = 1,
81766 + [14174].file = "sound/pci/es1938.c",
81767 + [14174].name = "snd_es1938_capture_copy",
81768 + [14174].param5 = 1,
81769 + [14207].file = "drivers/media/video/v4l2-event.c",
81770 + [14207].name = "v4l2_event_subscribe",
81771 + [14207].param3 = 1,
81772 + [14241].file = "drivers/platform/x86/asus_acpi.c",
81773 + [14241].name = "brn_proc_write",
81774 + [14241].param3 = 1,
81775 + [14345].file = "fs/cachefiles/daemon.c",
81776 + [14345].name = "cachefiles_daemon_write",
81777 + [14345].param3 = 1,
81778 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
81779 + [14347].name = "dvb_ca_en50221_io_write",
81780 + [14347].param3 = 1,
81781 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
81782 + [14566].name = "alloc_ebda_hpc",
81783 + [14566].param1 = 1,
81784 + [14566].param2 = 1,
81785 + [1458].file = "drivers/misc/lkdtm.c",
81786 + [1458].name = "direct_entry",
81787 + [1458].param3 = 1,
81788 + [14646].file = "fs/compat.c",
81789 + [14646].name = "compat_writev",
81790 + [14646].param3 = 1,
81791 + [14684].file = "drivers/media/video/stk-webcam.c",
81792 + [14684].name = "stk_allocate_buffers",
81793 + [14684].param2 = 1,
81794 + [14736].file = "drivers/usb/misc/usbtest.c",
81795 + [14736].name = "unlink_queued",
81796 + [14736].param3 = 1,
81797 + [1482].file = "drivers/scsi/scsi_netlink.c",
81798 + [1482].name = "scsi_nl_send_vendor_msg",
81799 + [1482].param5 = 1,
81800 + [15017].file = "drivers/edac/edac_device.c",
81801 + [15017].name = "edac_device_alloc_ctl_info",
81802 + [15017].param1 = 1,
81803 + [15044].file = "drivers/uio/uio.c",
81804 + [15044].name = "uio_write",
81805 + [15044].param3 = 1,
81806 + [15087].file = "fs/bio.c",
81807 + [15087].name = "bio_map_kern",
81808 + [15087].param2 = 1,
81809 + [15087].param3 = 1,
81810 + [15112].file = "drivers/xen/evtchn.c",
81811 + [15112].name = "evtchn_write",
81812 + [15112].param3 = 1,
81813 + [15130].file = "net/bluetooth/hci_core.c",
81814 + [15130].name = "hci_send_cmd",
81815 + [15130].param3 = 1,
81816 + [15202].file = "net/bluetooth/rfcomm/tty.c",
81817 + [15202].name = "rfcomm_wmalloc",
81818 + [15202].param2 = 1,
81819 + [15274].file = "crypto/shash.c",
81820 + [15274].name = "crypto_shash_setkey",
81821 + [15274].param3 = 1,
81822 + [15354].file = "drivers/isdn/mISDN/socket.c",
81823 + [15354].name = "mISDN_sock_sendmsg",
81824 + [15354].param4 = 1,
81825 + [15361].file = "drivers/char/agp/generic.c",
81826 + [15361].name = "agp_allocate_memory",
81827 + [15361].param2 = 1,
81828 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
81829 + [15497].name = "ts_read",
81830 + [15497].param3 = 1,
81831 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
81832 + [15551].name = "clusterip_proc_write",
81833 + [15551].param3 = 1,
81834 + [15701].file = "drivers/hid/hid-roccat-common.c",
81835 + [15701].name = "roccat_common_receive",
81836 + [15701].param4 = 1,
81837 + [1572].file = "net/ceph/pagevec.c",
81838 + [1572].name = "ceph_copy_page_vector_to_user",
81839 + [1572].param4 = 1,
81840 + [15814].file = "net/mac80211/debugfs_netdev.c",
81841 + [15814].name = "ieee80211_if_write",
81842 + [15814].param3 = 1,
81843 + [15883].file = "security/keys/keyctl.c",
81844 + [15883].name = "sys_add_key",
81845 + [15883].param4 = 1,
81846 + [15884].file = "fs/exofs/super.c",
81847 + [15884].name = "exofs_read_lookup_dev_table",
81848 + [15884].param3 = 1,
81849 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
81850 + [16037].name = "easycap_alsa_vmalloc",
81851 + [16037].param2 = 1,
81852 + [16073].file = "net/sctp/socket.c",
81853 + [16073].name = "sctp_setsockopt",
81854 + [16073].param5 = 1,
81855 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
81856 + [16132].name = "buffer_from_user",
81857 + [16132].param3 = 1,
81858 + [16138].file = "security/selinux/ss/services.c",
81859 + [16138].name = "security_context_to_sid_force",
81860 + [16138].param2 = 1,
81861 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
81862 + [16166].name = "dispatch_proc_write",
81863 + [16166].param3 = 1,
81864 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
81865 + [16229].name = "iscsi_offload_mesg",
81866 + [16229].param5 = 1,
81867 + [16353].file = "drivers/base/regmap/regmap.c",
81868 + [16353].name = "regmap_raw_write",
81869 + [16353].param4 = 1,
81870 + [16383].file = "fs/proc/base.c",
81871 + [16383].name = "comm_write",
81872 + [16383].param3 = 1,
81873 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
81874 + [16396].name = "altera_irscan",
81875 + [16396].param2 = 1,
81876 + [16447].file = "drivers/hid/usbhid/hiddev.c",
81877 + [16447].name = "hiddev_ioctl",
81878 + [16447].param2 = 1,
81879 + [16453].file = "include/linux/slab.h",
81880 + [16453].name = "kzalloc",
81881 + [16453].param1 = 1,
81882 + [16605].file = "fs/ecryptfs/miscdev.c",
81883 + [16605].name = "ecryptfs_send_miscdev",
81884 + [16605].param2 = 1,
81885 + [16606].file = "drivers/ide/ide-tape.c",
81886 + [16606].name = "idetape_chrdev_write",
81887 + [16606].param3 = 1,
81888 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
81889 + [16637].name = "datablob_hmac_verify",
81890 + [16637].param4 = 1,
81891 + [16828].file = "net/batman-adv/hash.c",
81892 + [16828].name = "hash_new",
81893 + [16828].param1 = 1,
81894 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
81895 + [16853].name = "t4vf_pktgl_to_skb",
81896 + [16853].param2 = 1,
81897 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
81898 + [16911].name = "LoadBitmap",
81899 + [16911].param2 = 1,
81900 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
81901 + [169].name = "pcnet32_realloc_rx_ring",
81902 + [169].param3 = 1,
81903 + [17075].file = "sound/isa/gus/gus_dram.c",
81904 + [17075].name = "snd_gus_dram_write",
81905 + [17075].param4 = 1,
81906 + [17133].file = "drivers/usb/misc/iowarrior.c",
81907 + [17133].name = "iowarrior_read",
81908 + [17133].param3 = 1,
81909 + [17185].file = "net/wireless/scan.c",
81910 + [17185].name = "cfg80211_inform_bss",
81911 + [17185].param8 = 1,
81912 + [17349].file = "net/tipc/link.c",
81913 + [17349].name = "tipc_link_send_sections_fast",
81914 + [17349].param4 = 1,
81915 + [17377].file = "drivers/usb/class/cdc-wdm.c",
81916 + [17377].name = "wdm_write",
81917 + [17377].param3 = 1,
81918 + [17459].file = "drivers/usb/misc/rio500.c",
81919 + [17459].name = "write_rio",
81920 + [17459].param3 = 1,
81921 + [17460].file = "fs/nfsd/nfscache.c",
81922 + [17460].name = "nfsd_cache_update",
81923 + [17460].param3 = 1,
81924 + [17492].file = "net/dccp/proto.c",
81925 + [17492].name = "do_dccp_setsockopt",
81926 + [17492].param5 = 1,
81927 + [1754].file = "sound/core/oss/pcm_oss.c",
81928 + [1754].name = "snd_pcm_oss_write",
81929 + [1754].param3 = 1,
81930 + [17604].file = "fs/proc/generic.c",
81931 + [17604].name = "__proc_file_read",
81932 + [17604].param3 = 1,
81933 + [17718].file = "net/caif/caif_socket.c",
81934 + [17718].name = "setsockopt",
81935 + [17718].param5 = 1,
81936 + [17828].file = "kernel/sched/core.c",
81937 + [17828].name = "sched_feat_write",
81938 + [17828].param3 = 1,
81939 + [17841].file = "drivers/misc/tifm_core.c",
81940 + [17841].name = "tifm_alloc_adapter",
81941 + [17841].param1 = 1,
81942 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
81943 + [17946].name = "if_spi_host_to_card",
81944 + [17946].param4 = 1,
81945 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
81946 + [1800].name = "dvb_dvr_do_ioctl",
81947 + [1800].param3 = 1,
81948 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
81949 + [18119].name = "iwmct_fw_parser_init",
81950 + [18119].param4 = 1,
81951 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
81952 + [18140].name = "pm8001_store_update_fw",
81953 + [18140].param4 = 1,
81954 + [18191].file = "sound/pci/hda/patch_realtek.c",
81955 + [18191].name = "new_bind_ctl",
81956 + [18191].param2 = 1,
81957 + [18224].file = "drivers/xen/grant-table.c",
81958 + [18224].name = "gnttab_map",
81959 + [18224].param2 = 1,
81960 + [18232].file = "fs/nfs/write.c",
81961 + [18232].name = "nfs_writedata_alloc",
81962 + [18232].param1 = 1,
81963 + [18247].file = "drivers/char/agp/generic.c",
81964 + [18247].name = "agp_create_user_memory",
81965 + [18247].param1 = 1,
81966 + [18303].file = "fs/xattr.c",
81967 + [18303].name = "getxattr",
81968 + [18303].param4 = 1,
81969 + [18353].file = "net/rfkill/core.c",
81970 + [18353].name = "rfkill_fop_read",
81971 + [18353].param3 = 1,
81972 + [18386].file = "fs/read_write.c",
81973 + [18386].name = "vfs_readv",
81974 + [18386].param3 = 1,
81975 + [18391].file = "fs/ocfs2/stack_user.c",
81976 + [18391].name = "ocfs2_control_write",
81977 + [18391].param3 = 1,
81978 + [183].file = "crypto/ahash.c",
81979 + [183].name = "crypto_ahash_setkey",
81980 + [183].param3 = 1,
81981 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
81982 + [18406].name = "tm6000_read_write_usb",
81983 + [18406].param7 = 1,
81984 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
81985 + [1845].name = "rt2x00debug_write_rf",
81986 + [1845].param3 = 1,
81987 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
81988 + [18465].name = "cxgb_alloc_mem",
81989 + [18465].param1 = 1,
81990 + [184].file = "drivers/firewire/nosy.c",
81991 + [184].name = "packet_buffer_init",
81992 + [184].param2 = 1,
81993 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
81994 + [1858].name = "do_ip6t_set_ctl",
81995 + [1858].param4 = 1,
81996 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
81997 + [18659].name = "dvb_usercopy",
81998 + [18659].param2 = 1,
81999 + [18722].file = "security/tomoyo/condition.c",
82000 + [18722].name = "tomoyo_scan_bprm",
82001 + [18722].param2 = 1,
82002 + [18722].param4 = 1,
82003 + [18775].file = "include/linux/textsearch.h",
82004 + [18775].name = "alloc_ts_config",
82005 + [18775].param1 = 1,
82006 + [18940].file = "drivers/usb/host/hwa-hc.c",
82007 + [18940].name = "__hwahc_op_set_gtk",
82008 + [18940].param4 = 1,
82009 + [19012].file = "drivers/acpi/event.c",
82010 + [19012].name = "acpi_system_read_event",
82011 + [19012].param3 = 1,
82012 + [19028].file = "mm/filemap.c",
82013 + [19028].name = "iov_iter_copy_from_user_atomic",
82014 + [19028].param4 = 1,
82015 + [19107].file = "security/smack/smackfs.c",
82016 + [19107].name = "smk_write_load_list",
82017 + [19107].param3 = 1,
82018 + [19240].file = "net/sctp/socket.c",
82019 + [19240].name = "sctp_setsockopt_delayed_ack",
82020 + [19240].param3 = 1,
82021 + [19274].file = "net/core/pktgen.c",
82022 + [19274].name = "pktgen_if_write",
82023 + [19274].param3 = 1,
82024 + [19286].file = "drivers/base/regmap/regmap.c",
82025 + [19286].name = "_regmap_raw_write",
82026 + [19286].param4 = 1,
82027 + [19308].file = "drivers/char/mem.c",
82028 + [19308].name = "read_oldmem",
82029 + [19308].param3 = 1,
82030 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
82031 + [19343].name = "datablob_hmac_append",
82032 + [19343].param3 = 1,
82033 + [19349].file = "drivers/acpi/acpica/utobject.c",
82034 + [19349].name = "acpi_ut_create_package_object",
82035 + [19349].param1 = 1,
82036 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
82037 + [19453].name = "sge_rx",
82038 + [19453].param3 = 1,
82039 + [19504].file = "drivers/usb/serial/garmin_gps.c",
82040 + [19504].name = "pkt_add",
82041 + [19504].param3 = 1,
82042 + [19522].file = "mm/percpu.c",
82043 + [19522].name = "pcpu_mem_zalloc",
82044 + [19522].param1 = 1,
82045 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
82046 + [19548].name = "qla2x00_get_ctx_sp",
82047 + [19548].param3 = 1,
82048 + [19592].file = "net/dccp/proto.c",
82049 + [19592].name = "dccp_setsockopt_service",
82050 + [19592].param4 = 1,
82051 + [19726].file = "kernel/trace/trace.c",
82052 + [19726].name = "tracing_set_trace_write",
82053 + [19726].param3 = 1,
82054 + [19738].file = "fs/sysfs/file.c",
82055 + [19738].name = "sysfs_write_file",
82056 + [19738].param3 = 1,
82057 + [19833].file = "drivers/xen/privcmd.c",
82058 + [19833].name = "gather_array",
82059 + [19833].param3 = 1,
82060 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
82061 + [19910].name = "saa7164_buffer_alloc_user",
82062 + [19910].param2 = 1,
82063 + [19920].file = "drivers/input/joydev.c",
82064 + [19920].name = "joydev_ioctl",
82065 + [19920].param2 = 1,
82066 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
82067 + [19931].name = "ftdi_elan_write",
82068 + [19931].param3 = 1,
82069 + [19960].file = "drivers/usb/class/usblp.c",
82070 + [19960].name = "usblp_read",
82071 + [19960].param3 = 1,
82072 + [1996].file = "drivers/scsi/libsrp.c",
82073 + [1996].name = "srp_target_alloc",
82074 + [1996].param3 = 1,
82075 + [20023].file = "drivers/media/video/gspca/gspca.c",
82076 + [20023].name = "dev_read",
82077 + [20023].param3 = 1,
82078 + [20207].file = "net/core/sock.c",
82079 + [20207].name = "sock_alloc_send_pskb",
82080 + [20207].param2 = 1,
82081 + [20263].file = "kernel/trace/trace_events.c",
82082 + [20263].name = "event_filter_write",
82083 + [20263].param3 = 1,
82084 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
82085 + [20314].name = "drm_ht_create",
82086 + [20314].param2 = 1,
82087 + [20320].file = "drivers/mfd/sm501.c",
82088 + [20320].name = "sm501_create_subdev",
82089 + [20320].param3 = 1,
82090 + [20320].param4 = 1,
82091 + [20376].file = "mm/nobootmem.c",
82092 + [20376].name = "__alloc_bootmem_nopanic",
82093 + [20376].param1 = 1,
82094 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
82095 + [20409].name = "opera1_usb_i2c_msgxfer",
82096 + [20409].param4 = 1,
82097 + [20473].file = "drivers/mtd/mtdchar.c",
82098 + [20473].name = "mtdchar_write",
82099 + [20473].param3 = 1,
82100 + [20611].file = "net/netfilter/x_tables.c",
82101 + [20611].name = "xt_alloc_table_info",
82102 + [20611].param1 = 1,
82103 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
82104 + [20618].name = "chd_dec_fetch_cdata",
82105 + [20618].param3 = 1,
82106 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
82107 + [20713].name = "ttm_bo_io",
82108 + [20713].param5 = 1,
82109 + [20801].file = "drivers/vhost/vhost.c",
82110 + [20801].name = "vhost_add_used_n",
82111 + [20801].param3 = 1,
82112 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
82113 + [20835].name = "isdn_read",
82114 + [20835].param3 = 1,
82115 + [20951].file = "crypto/rng.c",
82116 + [20951].name = "rngapi_reset",
82117 + [20951].param3 = 1,
82118 + [21125].file = "fs/gfs2/dir.c",
82119 + [21125].name = "gfs2_alloc_sort_buffer",
82120 + [21125].param1 = 1,
82121 + [21132].file = "kernel/cgroup.c",
82122 + [21132].name = "cgroup_write_X64",
82123 + [21132].param5 = 1,
82124 + [21138].file = "drivers/uio/uio.c",
82125 + [21138].name = "uio_read",
82126 + [21138].param3 = 1,
82127 + [21193].file = "net/wireless/sme.c",
82128 + [21193].name = "cfg80211_disconnected",
82129 + [21193].param4 = 1,
82130 + [21312].file = "lib/ts_kmp.c",
82131 + [21312].name = "kmp_init",
82132 + [21312].param2 = 1,
82133 + [21335].file = "net/econet/af_econet.c",
82134 + [21335].name = "econet_sendmsg",
82135 + [21335].param4 = 1,
82136 + [21406].file = "fs/libfs.c",
82137 + [21406].name = "simple_write_to_buffer",
82138 + [21406].param2 = 1,
82139 + [21406].param5 = 1,
82140 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82141 + [21451].name = "do_ip_vs_set_ctl",
82142 + [21451].param4 = 1,
82143 + [21459].file = "security/smack/smackfs.c",
82144 + [21459].name = "smk_write_doi",
82145 + [21459].param3 = 1,
82146 + [21508].file = "include/linux/usb/wusb.h",
82147 + [21508].name = "wusb_prf_64",
82148 + [21508].param7 = 1,
82149 + [21511].file = "drivers/input/ff-core.c",
82150 + [21511].name = "input_ff_create",
82151 + [21511].param2 = 1,
82152 + [21538].file = "net/bluetooth/l2cap_sock.c",
82153 + [21538].name = "l2cap_sock_setsockopt",
82154 + [21538].param5 = 1,
82155 + [21543].file = "drivers/media/video/gspca/gspca.c",
82156 + [21543].name = "frame_alloc",
82157 + [21543].param4 = 1,
82158 + [21608].file = "drivers/char/tpm/tpm.c",
82159 + [21608].name = "tpm_write",
82160 + [21608].param3 = 1,
82161 + [2160].file = "drivers/net/wireless/ray_cs.c",
82162 + [2160].name = "int_proc_write",
82163 + [2160].param3 = 1,
82164 + [21632].file = "fs/afs/cell.c",
82165 + [21632].name = "afs_cell_create",
82166 + [21632].param2 = 1,
82167 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82168 + [21679].name = "carl9170_debugfs_write",
82169 + [21679].param3 = 1,
82170 + [21784].file = "crypto/ahash.c",
82171 + [21784].name = "ahash_setkey_unaligned",
82172 + [21784].param3 = 1,
82173 + [2180].file = "drivers/char/ppdev.c",
82174 + [2180].name = "pp_write",
82175 + [2180].param3 = 1,
82176 + [21810].file = "net/core/netprio_cgroup.c",
82177 + [21810].name = "extend_netdev_table",
82178 + [21810].param2 = 1,
82179 + [21906].file = "net/atm/mpc.c",
82180 + [21906].name = "copy_macs",
82181 + [21906].param4 = 1,
82182 + [21946].file = "fs/nfs/idmap.c",
82183 + [21946].name = "nfs_map_name_to_uid",
82184 + [21946].param3 = 1,
82185 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
82186 + [22052].name = "get_packet_pg",
82187 + [22052].param4 = 1,
82188 + [22085].file = "drivers/staging/sep/sep_driver.c",
82189 + [22085].name = "sep_lock_user_pages",
82190 + [22085].param2 = 1,
82191 + [22085].param3 = 1,
82192 + [22190].file = "drivers/char/tpm/tpm.c",
82193 + [22190].name = "tpm_read",
82194 + [22190].param3 = 1,
82195 + [22291].file = "net/core/pktgen.c",
82196 + [22291].name = "pgctrl_write",
82197 + [22291].param3 = 1,
82198 + [22439].file = "fs/afs/rxrpc.c",
82199 + [22439].name = "afs_alloc_flat_call",
82200 + [22439].param2 = 1,
82201 + [22439].param3 = 1,
82202 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82203 + [2243].name = "scsi_tgt_kspace_exec",
82204 + [2243].param8 = 1,
82205 + [22440].file = "drivers/uwb/neh.c",
82206 + [22440].name = "uwb_rc_neh_grok_event",
82207 + [22440].param3 = 1,
82208 + [22611].file = "drivers/staging/android/logger.c",
82209 + [22611].name = "do_write_log_from_user",
82210 + [22611].param3 = 1,
82211 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
82212 + [22614].name = "cx18_copy_buf_to_user",
82213 + [22614].param4 = 1,
82214 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
82215 + [22667].name = "altera_set_ir_post",
82216 + [22667].param2 = 1,
82217 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82218 + [22772].name = "iscsit_dump_data_payload",
82219 + [22772].param2 = 1,
82220 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
82221 + [22777].name = "srp_alloc_iu",
82222 + [22777].param2 = 1,
82223 + [22811].file = "drivers/usb/dwc3/debugfs.c",
82224 + [22811].name = "dwc3_mode_write",
82225 + [22811].param3 = 1,
82226 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
82227 + [22817].name = "usbvision_rvmalloc",
82228 + [22817].param1 = 1,
82229 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82230 + [22864].name = "ath6kl_add_bss_if_needed",
82231 + [22864].param6 = 1,
82232 + [2286].file = "drivers/scsi/mvumi.c",
82233 + [2286].name = "mvumi_alloc_mem_resource",
82234 + [2286].param3 = 1,
82235 + [22904].file = "security/selinux/ss/services.c",
82236 + [22904].name = "security_context_to_sid_default",
82237 + [22904].param2 = 1,
82238 + [22932].file = "fs/compat.c",
82239 + [22932].name = "compat_sys_writev",
82240 + [22932].param3 = 1,
82241 + [2302].file = "drivers/media/video/stk-webcam.c",
82242 + [2302].name = "v4l_stk_read",
82243 + [2302].param3 = 1,
82244 + [2307].file = "drivers/pcmcia/cistpl.c",
82245 + [2307].name = "pcmcia_replace_cis",
82246 + [2307].param3 = 1,
82247 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82248 + [23117].name = "dvb_audio_write",
82249 + [23117].param3 = 1,
82250 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82251 + [23220].name = "do_dmabuf_dirty_sou",
82252 + [23220].param7 = 1,
82253 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
82254 + [23232].name = "sm_checker_extend",
82255 + [23232].param2 = 1,
82256 + [2324].file = "net/ieee802154/wpan-class.c",
82257 + [2324].name = "wpan_phy_alloc",
82258 + [2324].param1 = 1,
82259 + [2328].file = "kernel/trace/ftrace.c",
82260 + [2328].name = "ftrace_pid_write",
82261 + [2328].param3 = 1,
82262 + [23290].file = "fs/proc/base.c",
82263 + [23290].name = "mem_rw",
82264 + [23290].param3 = 1,
82265 + [23449].file = "crypto/blkcipher.c",
82266 + [23449].name = "blkcipher_next_slow",
82267 + [23449].param3 = 1,
82268 + [23449].param4 = 1,
82269 + [23535].file = "ipc/sem.c",
82270 + [23535].name = "sys_semtimedop",
82271 + [23535].param3 = 1,
82272 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82273 + [2357].name = "garmin_read_process",
82274 + [2357].param3 = 1,
82275 + [23589].file = "kernel/relay.c",
82276 + [23589].name = "subbuf_read_actor",
82277 + [23589].param3 = 1,
82278 + [23848].file = "crypto/blkcipher.c",
82279 + [23848].name = "async_setkey",
82280 + [23848].param3 = 1,
82281 + [2386].file = "drivers/acpi/acpica/exnames.c",
82282 + [2386].name = "acpi_ex_allocate_name_string",
82283 + [2386].param2 = 1,
82284 + [2389].file = "net/core/sock.c",
82285 + [2389].name = "sock_rmalloc",
82286 + [2389].param2 = 1,
82287 + [23994].file = "net/bluetooth/mgmt.c",
82288 + [23994].name = "set_powered",
82289 + [23994].param4 = 1,
82290 + [23999].file = "sound/pci/rme9652/hdsp.c",
82291 + [23999].name = "snd_hdsp_capture_copy",
82292 + [23999].param5 = 1,
82293 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82294 + [24233].name = "aer_inject_write",
82295 + [24233].param3 = 1,
82296 + [24359].file = "kernel/power/qos.c",
82297 + [24359].name = "pm_qos_power_write",
82298 + [24359].param3 = 1,
82299 + [24457].file = "fs/btrfs/backref.c",
82300 + [24457].name = "init_data_container",
82301 + [24457].param1 = 1,
82302 + [24719].file = "drivers/input/evdev.c",
82303 + [24719].name = "bits_to_user",
82304 + [24719].param3 = 1,
82305 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82306 + [2472].name = "compat_do_ipt_set_ctl",
82307 + [2472].param4 = 1,
82308 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82309 + [24755].name = "qib_diag_write",
82310 + [24755].param3 = 1,
82311 + [24805].file = "security/keys/user_defined.c",
82312 + [24805].name = "user_update",
82313 + [24805].param3 = 1,
82314 + [25036].file = "fs/pipe.c",
82315 + [25036].name = "pipe_iov_copy_from_user",
82316 + [25036].param3 = 1,
82317 + [25078].file = "drivers/net/wireless/p54/fwio.c",
82318 + [25078].name = "p54_download_eeprom",
82319 + [25078].param4 = 1,
82320 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82321 + [25127].name = "realloc_buffer",
82322 + [25127].param2 = 1,
82323 + [25145].file = "net/tipc/link.c",
82324 + [25145].name = "link_send_sections_long",
82325 + [25145].param4 = 1,
82326 + [25157].file = "security/keys/request_key_auth.c",
82327 + [25157].name = "request_key_auth_new",
82328 + [25157].param3 = 1,
82329 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82330 + [25158].name = "mlx4_en_create_rx_ring",
82331 + [25158].param3 = 1,
82332 + [25267].file = "fs/configfs/file.c",
82333 + [25267].name = "configfs_write_file",
82334 + [25267].param3 = 1,
82335 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82336 + [25495].name = "bfad_debugfs_write_regwr",
82337 + [25495].param3 = 1,
82338 + [25558].file = "fs/proc/task_mmu.c",
82339 + [25558].name = "clear_refs_write",
82340 + [25558].param3 = 1,
82341 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82342 + [25692].name = "ath6kl_wmi_send_action_cmd",
82343 + [25692].param7 = 1,
82344 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
82345 + [25765].name = "flexcop_device_kmalloc",
82346 + [25765].param1 = 1,
82347 + [26100].file = "sound/core/info.c",
82348 + [26100].name = "snd_info_entry_write",
82349 + [26100].param3 = 1,
82350 + [26256].file = "fs/hpfs/name.c",
82351 + [26256].name = "hpfs_translate_name",
82352 + [26256].param3 = 1,
82353 + [26394].file = "drivers/hid/hidraw.c",
82354 + [26394].name = "hidraw_get_report",
82355 + [26394].param3 = 1,
82356 + [26494].file = "kernel/signal.c",
82357 + [26494].name = "sys_rt_sigpending",
82358 + [26494].param2 = 1,
82359 + [26497].file = "security/keys/keyctl.c",
82360 + [26497].name = "sys_keyctl",
82361 + [26497].param4 = 1,
82362 + [26533].file = "drivers/block/aoe/aoechr.c",
82363 + [26533].name = "aoechr_write",
82364 + [26533].param3 = 1,
82365 + [26560].file = "crypto/algapi.c",
82366 + [26560].name = "crypto_alloc_instance2",
82367 + [26560].param3 = 1,
82368 + [26605].file = "security/selinux/selinuxfs.c",
82369 + [26605].name = "sel_write_user",
82370 + [26605].param3 = 1,
82371 + [26620].file = "net/bluetooth/mgmt.c",
82372 + [26620].name = "mgmt_control",
82373 + [26620].param3 = 1,
82374 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82375 + [26701].name = "cfi_read_pri",
82376 + [26701].param3 = 1,
82377 + [26757].file = "fs/xattr.c",
82378 + [26757].name = "sys_fgetxattr",
82379 + [26757].param4 = 1,
82380 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82381 + [2678].name = "disp_proc_write",
82382 + [2678].param3 = 1,
82383 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82384 + [26834].name = "drm_ioctl",
82385 + [26834].param2 = 1,
82386 + [26843].file = "drivers/firewire/core-cdev.c",
82387 + [26843].name = "fw_device_op_compat_ioctl",
82388 + [26843].param2 = 1,
82389 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82390 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82391 + [26845].param3 = 1,
82392 + [26888].file = "net/bridge/br_ioctl.c",
82393 + [26888].name = "get_fdb_entries",
82394 + [26888].param3 = 1,
82395 + [26962].file = "drivers/usb/class/usbtmc.c",
82396 + [26962].name = "usbtmc_write",
82397 + [26962].param3 = 1,
82398 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82399 + [26966].name = "ts_write",
82400 + [26966].param3 = 1,
82401 + [27004].file = "drivers/misc/hpilo.c",
82402 + [27004].name = "ilo_write",
82403 + [27004].param3 = 1,
82404 + [27025].file = "fs/ntfs/file.c",
82405 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82406 + [27025].param3 = 1,
82407 + [27025].param4 = 1,
82408 + [27061].file = "drivers/firewire/core-cdev.c",
82409 + [27061].name = "iso_callback",
82410 + [27061].param3 = 1,
82411 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82412 + [2711].name = "dvb_ringbuffer_read_user",
82413 + [2711].param3 = 1,
82414 + [27129].file = "fs/lockd/mon.c",
82415 + [27129].name = "nsm_get_handle",
82416 + [27129].param4 = 1,
82417 + [27142].file = "fs/proc/kcore.c",
82418 + [27142].name = "read_kcore",
82419 + [27142].param3 = 1,
82420 + [27164].file = "include/drm/drm_mem_util.h",
82421 + [27164].name = "drm_calloc_large",
82422 + [27164].param1 = 1,
82423 + [27164].param2 = 1,
82424 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
82425 + [27176].name = "otp_read",
82426 + [27176].param2 = 1,
82427 + [27176].param5 = 1,
82428 + [27232].file = "security/apparmor/lib.c",
82429 + [27232].name = "kvmalloc",
82430 + [27232].param1 = 1,
82431 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82432 + [27275].name = "cxgbi_ddp_reserve",
82433 + [27275].param4 = 1,
82434 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82435 + [27280].name = "mlx4_en_create_tx_ring",
82436 + [27280].param4 = 1,
82437 + [27290].file = "security/selinux/ss/services.c",
82438 + [27290].name = "security_context_to_sid_core",
82439 + [27290].param2 = 1,
82440 + [27302].file = "fs/proc/base.c",
82441 + [27302].name = "proc_loginuid_write",
82442 + [27302].param3 = 1,
82443 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
82444 + [2730].name = "iscsi_decode_text_input",
82445 + [2730].param4 = 1,
82446 + [27314].file = "net/bluetooth/mgmt.c",
82447 + [27314].name = "cmd_complete",
82448 + [27314].param5 = 1,
82449 + [27472].file = "security/selinux/selinuxfs.c",
82450 + [27472].name = "sel_write_load",
82451 + [27472].param3 = 1,
82452 + [27491].file = "fs/proc/base.c",
82453 + [27491].name = "proc_pid_attr_write",
82454 + [27491].param3 = 1,
82455 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82456 + [27568].name = "t4_alloc_mem",
82457 + [27568].param1 = 1,
82458 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82459 + [27582].name = "ledd_proc_write",
82460 + [27582].param3 = 1,
82461 + [27595].file = "net/core/sock.c",
82462 + [27595].name = "sock_alloc_send_skb",
82463 + [27595].param2 = 1,
82464 + [27648].file = "net/bluetooth/l2cap_core.c",
82465 + [27648].name = "l2cap_bredr_sig_cmd",
82466 + [27648].param3 = 1,
82467 + [27697].file = "drivers/staging/mei/iorw.c",
82468 + [27697].name = "amthi_read",
82469 + [27697].param4 = 1,
82470 + [27911].file = "fs/ext4/resize.c",
82471 + [27911].name = "alloc_flex_gd",
82472 + [27911].param1 = 1,
82473 + [27927].file = "drivers/tty/tty_io.c",
82474 + [27927].name = "redirected_tty_write",
82475 + [27927].param3 = 1,
82476 + [28040].file = "kernel/kfifo.c",
82477 + [28040].name = "__kfifo_alloc",
82478 + [28040].param2 = 1,
82479 + [28040].param3 = 1,
82480 + [28151].file = "mm/filemap_xip.c",
82481 + [28151].name = "do_xip_mapping_read",
82482 + [28151].param5 = 1,
82483 + [28247].file = "net/sctp/tsnmap.c",
82484 + [28247].name = "sctp_tsnmap_init",
82485 + [28247].param2 = 1,
82486 + [28253].file = "include/linux/fb.h",
82487 + [28253].name = "alloc_apertures",
82488 + [28253].param1 = 1,
82489 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82490 + [28265].name = "fanotify_write",
82491 + [28265].param3 = 1,
82492 + [28316].file = "drivers/input/joydev.c",
82493 + [28316].name = "joydev_ioctl_common",
82494 + [28316].param2 = 1,
82495 + [28359].file = "drivers/spi/spidev.c",
82496 + [28359].name = "spidev_message",
82497 + [28359].param3 = 1,
82498 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82499 + [28360].name = "hiddev_compat_ioctl",
82500 + [28360].param2 = 1,
82501 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82502 + [28407].name = "rt2x00debug_write_csr",
82503 + [28407].param3 = 1,
82504 + [2847].file = "fs/ntfs/file.c",
82505 + [2847].name = "ntfs_copy_from_user",
82506 + [2847].param3 = 1,
82507 + [2847].param5 = 1,
82508 + [28584].file = "drivers/memstick/core/memstick.c",
82509 + [28584].name = "memstick_alloc_host",
82510 + [28584].param1 = 1,
82511 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82512 + [28783].name = "i915_cache_sharing_write",
82513 + [28783].param3 = 1,
82514 + [28787].file = "drivers/media/video/videobuf2-core.c",
82515 + [28787].name = "vb2_write",
82516 + [28787].param3 = 1,
82517 + [28879].file = "drivers/base/map.c",
82518 + [28879].name = "kobj_map",
82519 + [28879].param2 = 1,
82520 + [28879].param3 = 1,
82521 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82522 + [28889].name = "cm4040_write",
82523 + [28889].param3 = 1,
82524 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82525 + [29073].name = "vmw_kms_readback",
82526 + [29073].param6 = 1,
82527 + [29085].file = "security/apparmor/apparmorfs.c",
82528 + [29085].name = "profile_load",
82529 + [29085].param3 = 1,
82530 + [29092].file = "lib/lru_cache.c",
82531 + [29092].name = "lc_create",
82532 + [29092].param3 = 1,
82533 + [29257].file = "drivers/vhost/vhost.c",
82534 + [29257].name = "vhost_add_used_and_signal_n",
82535 + [29257].param4 = 1,
82536 + [29267].file = "net/ipv4/fib_trie.c",
82537 + [29267].name = "tnode_alloc",
82538 + [29267].param1 = 1,
82539 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82540 + [29338].name = "bnad_debugfs_write_regwr",
82541 + [29338].param3 = 1,
82542 + [29353].file = "net/sctp/socket.c",
82543 + [29353].name = "sctp_setsockopt_del_key",
82544 + [29353].param3 = 1,
82545 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82546 + [29405].name = "dw210x_op_rw",
82547 + [29405].param6 = 1,
82548 + [29542].file = "net/nfc/nci/core.c",
82549 + [29542].name = "nci_send_cmd",
82550 + [29542].param3 = 1,
82551 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82552 + [29714].name = "cxgbi_device_register",
82553 + [29714].param1 = 1,
82554 + [29714].param2 = 1,
82555 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
82556 + [2972].name = "crystalhd_create_dio_pool",
82557 + [2972].param2 = 1,
82558 + [29769].file = "drivers/misc/iwmc3200top/log.c",
82559 + [29769].name = "store_iwmct_log_level",
82560 + [29769].param4 = 1,
82561 + [29792].file = "drivers/staging/bcm/nvm.c",
82562 + [29792].name = "BcmCopySection",
82563 + [29792].param5 = 1,
82564 + [29859].file = "net/rds/page.c",
82565 + [29859].name = "rds_page_copy_user",
82566 + [29859].param4 = 1,
82567 + [29905].file = "mm/nobootmem.c",
82568 + [29905].name = "___alloc_bootmem",
82569 + [29905].param1 = 1,
82570 + [2995].file = "mm/page_alloc.c",
82571 + [2995].name = "alloc_large_system_hash",
82572 + [2995].param2 = 1,
82573 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
82574 + [30000].name = "wlc_phy_loadsampletable_nphy",
82575 + [30000].param3 = 1,
82576 + [30242].file = "fs/cifs/cifssmb.c",
82577 + [30242].name = "cifs_readdata_alloc",
82578 + [30242].param1 = 1,
82579 + [30494].file = "net/ceph/buffer.c",
82580 + [30494].name = "ceph_buffer_new",
82581 + [30494].param1 = 1,
82582 + [30590].file = "security/tomoyo/memory.c",
82583 + [30590].name = "tomoyo_commit_ok",
82584 + [30590].param2 = 1,
82585 + [3060].file = "lib/mpi/mpiutil.c",
82586 + [3060].name = "mpi_alloc_limb_space",
82587 + [3060].param1 = 1,
82588 + [30687].file = "drivers/uwb/uwb-debug.c",
82589 + [30687].name = "command_write",
82590 + [30687].param3 = 1,
82591 + [30726].file = "drivers/bluetooth/hci_vhci.c",
82592 + [30726].name = "vhci_get_user",
82593 + [30726].param3 = 1,
82594 + [30873].file = "net/packet/af_packet.c",
82595 + [30873].name = "alloc_one_pg_vec_page",
82596 + [30873].param1 = 1,
82597 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
82598 + [30970].name = "create_bounce_buffer",
82599 + [30970].param3 = 1,
82600 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
82601 + [310].name = "bm_realloc_pages",
82602 + [310].param2 = 1,
82603 + [3119].file = "drivers/misc/ibmasm/command.c",
82604 + [3119].name = "ibmasm_new_command",
82605 + [3119].param2 = 1,
82606 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82607 + [31207].name = "parse_arg",
82608 + [31207].param2 = 1,
82609 + [31287].file = "drivers/scsi/libsrp.c",
82610 + [31287].name = "srp_iu_pool_alloc",
82611 + [31287].param2 = 1,
82612 + [31291].file = "sound/pci/rme9652/rme9652.c",
82613 + [31291].name = "snd_rme9652_capture_copy",
82614 + [31291].param5 = 1,
82615 + [31348].file = "kernel/sched/core.c",
82616 + [31348].name = "sys_sched_getaffinity",
82617 + [31348].param2 = 1,
82618 + [31492].file = "drivers/hid/hidraw.c",
82619 + [31492].name = "hidraw_read",
82620 + [31492].param3 = 1,
82621 + [3170].file = "security/integrity/ima/ima_fs.c",
82622 + [3170].name = "ima_write_policy",
82623 + [3170].param3 = 1,
82624 + [31782].file = "drivers/misc/pti.c",
82625 + [31782].name = "pti_char_write",
82626 + [31782].param3 = 1,
82627 + [31789].file = "fs/file.c",
82628 + [31789].name = "alloc_fdmem",
82629 + [31789].param1 = 1,
82630 + [31957].file = "fs/afs/proc.c",
82631 + [31957].name = "afs_proc_cells_write",
82632 + [31957].param3 = 1,
82633 + [32002].file = "net/sctp/socket.c",
82634 + [32002].name = "sctp_setsockopt_active_key",
82635 + [32002].param3 = 1,
82636 + [32182].file = "net/sunrpc/cache.c",
82637 + [32182].name = "cache_write",
82638 + [32182].param3 = 1,
82639 + [32278].file = "kernel/time/timer_stats.c",
82640 + [32278].name = "tstats_write",
82641 + [32278].param3 = 1,
82642 + [32326].file = "drivers/tty/n_r3964.c",
82643 + [32326].name = "r3964_write",
82644 + [32326].param4 = 1,
82645 + [32399].file = "drivers/net/phy/mdio_bus.c",
82646 + [32399].name = "mdiobus_alloc_size",
82647 + [32399].param1 = 1,
82648 + [32402].file = "net/ceph/pagevec.c",
82649 + [32402].name = "ceph_copy_user_to_page_vector",
82650 + [32402].param4 = 1,
82651 + [3241].file = "drivers/usb/wusbcore/crypto.c",
82652 + [3241].name = "wusb_prf",
82653 + [3241].param7 = 1,
82654 + [32459].file = "drivers/media/radio/radio-wl1273.c",
82655 + [32459].name = "wl1273_fm_fops_write",
82656 + [32459].param3 = 1,
82657 + [32531].file = "fs/bio.c",
82658 + [32531].name = "__bio_map_kern",
82659 + [32531].param2 = 1,
82660 + [32531].param3 = 1,
82661 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
82662 + [32537].name = "buffer_to_user",
82663 + [32537].param3 = 1,
82664 + [32560].file = "drivers/input/input-mt.c",
82665 + [32560].name = "input_mt_init_slots",
82666 + [32560].param2 = 1,
82667 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82668 + [32600].name = "ath6kl_set_assoc_req_ies",
82669 + [32600].param3 = 1,
82670 + [32608].file = "security/selinux/selinuxfs.c",
82671 + [32608].name = "sel_write_checkreqprot",
82672 + [32608].param3 = 1,
82673 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82674 + [32812].name = "__vxge_hw_channel_allocate",
82675 + [32812].param3 = 1,
82676 + [32950].file = "fs/reiserfs/resize.c",
82677 + [32950].name = "reiserfs_resize",
82678 + [32950].param2 = 1,
82679 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82680 + [33010].name = "dvb_ringbuffer_pkt_read_user",
82681 + [33010].param5 = 1,
82682 + [33130].file = "net/llc/llc_sap.c",
82683 + [33130].name = "llc_alloc_frame",
82684 + [33130].param4 = 1,
82685 + [33221].file = "crypto/ablkcipher.c",
82686 + [33221].name = "ablkcipher_copy_iv",
82687 + [33221].param3 = 1,
82688 + [33268].file = "mm/maccess.c",
82689 + [33268].name = "__probe_kernel_write",
82690 + [33268].param3 = 1,
82691 + [33280].file = "fs/xfs/kmem.c",
82692 + [33280].name = "kmem_realloc",
82693 + [33280].param2 = 1,
82694 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
82695 + [33375].name = "_malloc",
82696 + [33375].param1 = 1,
82697 + [33420].file = "drivers/net/team/team.c",
82698 + [33420].name = "__team_options_register",
82699 + [33420].param3 = 1,
82700 + [33489].file = "fs/binfmt_misc.c",
82701 + [33489].name = "create_entry",
82702 + [33489].param2 = 1,
82703 + [33637].file = "net/9p/client.c",
82704 + [33637].name = "p9_client_read",
82705 + [33637].param5 = 1,
82706 + [33669].file = "fs/gfs2/glock.c",
82707 + [33669].name = "gfs2_glock_nq_m",
82708 + [33669].param1 = 1,
82709 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
82710 + [33704].name = "ttm_dma_page_pool_free",
82711 + [33704].param2 = 1,
82712 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
82713 + [33779].name = "resource_from_user",
82714 + [33779].param3 = 1,
82715 + [33810].file = "net/mac80211/util.c",
82716 + [33810].name = "ieee80211_send_probe_req",
82717 + [33810].param6 = 1,
82718 + [3384].file = "drivers/block/paride/pg.c",
82719 + [3384].name = "pg_write",
82720 + [3384].param3 = 1,
82721 + [34105].file = "fs/libfs.c",
82722 + [34105].name = "simple_read_from_buffer",
82723 + [34105].param2 = 1,
82724 + [34105].param5 = 1,
82725 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
82726 + [34120].name = "pvr2_stream_buffer_count",
82727 + [34120].param2 = 1,
82728 + [34226].file = "mm/shmem.c",
82729 + [34226].name = "shmem_xattr_set",
82730 + [34226].param4 = 1,
82731 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
82732 + [34251].name = "OS_kmalloc",
82733 + [34251].param1 = 1,
82734 + [34276].file = "drivers/media/video/videobuf2-core.c",
82735 + [34276].name = "__vb2_perform_fileio",
82736 + [34276].param3 = 1,
82737 + [34278].file = "fs/ubifs/debug.c",
82738 + [34278].name = "dfs_global_file_write",
82739 + [34278].param3 = 1,
82740 + [34432].file = "drivers/edac/edac_pci.c",
82741 + [34432].name = "edac_pci_alloc_ctl_info",
82742 + [34432].param1 = 1,
82743 + [34532].file = "drivers/virtio/virtio_ring.c",
82744 + [34532].name = "vring_add_indirect",
82745 + [34532].param3 = 1,
82746 + [34532].param4 = 1,
82747 + [34543].file = "net/sctp/tsnmap.c",
82748 + [34543].name = "sctp_tsnmap_grow",
82749 + [34543].param2 = 1,
82750 + [34551].file = "fs/ocfs2/stack_user.c",
82751 + [34551].name = "ocfs2_control_cfu",
82752 + [34551].param2 = 1,
82753 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82754 + [34634].name = "ath6kl_send_go_probe_resp",
82755 + [34634].param3 = 1,
82756 + [34666].file = "fs/cifs/cifs_debug.c",
82757 + [34666].name = "cifs_security_flags_proc_write",
82758 + [34666].param3 = 1,
82759 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
82760 + [3466].name = "altera_drscan",
82761 + [3466].param2 = 1,
82762 + [34672].file = "drivers/tty/tty_io.c",
82763 + [34672].name = "tty_write",
82764 + [34672].param3 = 1,
82765 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82766 + [34679].name = "ivtv_copy_buf_to_user",
82767 + [34679].param4 = 1,
82768 + [34721].file = "drivers/usb/host/hwa-hc.c",
82769 + [34721].name = "__hwahc_dev_set_key",
82770 + [34721].param5 = 1,
82771 + [34749].file = "mm/nobootmem.c",
82772 + [34749].name = "__alloc_bootmem_low_node",
82773 + [34749].param2 = 1,
82774 + [34760].file = "include/acpi/platform/aclinux.h",
82775 + [34760].name = "acpi_os_allocate_zeroed",
82776 + [34760].param1 = 1,
82777 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
82778 + [34802].name = "cxgbi_alloc_big_mem",
82779 + [34802].param1 = 1,
82780 + [34863].file = "drivers/video/fbsysfs.c",
82781 + [34863].name = "framebuffer_alloc",
82782 + [34863].param1 = 1,
82783 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82784 + [34868].name = "bnad_debugfs_write_regrd",
82785 + [34868].param3 = 1,
82786 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
82787 + [34882].name = "video_proc_write",
82788 + [34882].param3 = 1,
82789 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
82790 + [35050].name = "dlmfs_file_write",
82791 + [35050].param3 = 1,
82792 + [35119].file = "fs/xattr.c",
82793 + [35119].name = "sys_llistxattr",
82794 + [35119].param3 = 1,
82795 + [35129].file = "mm/nobootmem.c",
82796 + [35129].name = "___alloc_bootmem_nopanic",
82797 + [35129].param1 = 1,
82798 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
82799 + [35159].name = "__i2400mu_send_barker",
82800 + [35159].param3 = 1,
82801 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
82802 + [35232].name = "cx18_read",
82803 + [35232].param3 = 1,
82804 + [35234].file = "net/irda/irnet/irnet_ppp.c",
82805 + [35234].name = "irnet_ctrl_write",
82806 + [35234].param3 = 1,
82807 + [35256].file = "sound/core/memory.c",
82808 + [35256].name = "copy_from_user_toio",
82809 + [35256].param3 = 1,
82810 + [35268].file = "security/keys/request_key_auth.c",
82811 + [35268].name = "request_key_auth_read",
82812 + [35268].param3 = 1,
82813 + [3538].file = "net/bluetooth/mgmt.c",
82814 + [3538].name = "disconnect",
82815 + [3538].param4 = 1,
82816 + [35443].file = "sound/core/pcm_memory.c",
82817 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
82818 + [35443].param2 = 1,
82819 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82820 + [35468].name = "xenbus_file_write",
82821 + [35468].param3 = 1,
82822 + [35536].file = "kernel/sysctl_binary.c",
82823 + [35536].name = "bin_uuid",
82824 + [35536].param3 = 1,
82825 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82826 + [35551].name = "ivtv_read_pos",
82827 + [35551].param3 = 1,
82828 + [35556].file = "fs/read_write.c",
82829 + [35556].name = "sys_readv",
82830 + [35556].param3 = 1,
82831 + [35693].file = "drivers/staging/mei/main.c",
82832 + [35693].name = "mei_read",
82833 + [35693].param3 = 1,
82834 + [35703].file = "crypto/ablkcipher.c",
82835 + [35703].name = "ablkcipher_next_slow",
82836 + [35703].param3 = 1,
82837 + [35703].param4 = 1,
82838 + [35729].file = "include/linux/skbuff.h",
82839 + [35729].name = "__dev_alloc_skb",
82840 + [35729].param1 = 1,
82841 + [35731].file = "drivers/usb/class/cdc-wdm.c",
82842 + [35731].name = "wdm_read",
82843 + [35731].param3 = 1,
82844 + [35796].file = "drivers/mtd/nand/nand_bch.c",
82845 + [35796].name = "nand_bch_init",
82846 + [35796].param2 = 1,
82847 + [35796].param3 = 1,
82848 + [35880].file = "fs/ecryptfs/crypto.c",
82849 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
82850 + [35880].param6 = 1,
82851 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
82852 + [36076].name = "efx_tsoh_heap_alloc",
82853 + [36076].param2 = 1,
82854 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
82855 + [36080].name = "video_usercopy",
82856 + [36080].param2 = 1,
82857 + [36149].file = "fs/udf/inode.c",
82858 + [36149].name = "udf_alloc_i_data",
82859 + [36149].param2 = 1,
82860 + [36183].file = "drivers/tty/vt/vc_screen.c",
82861 + [36183].name = "vcs_read",
82862 + [36183].param3 = 1,
82863 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
82864 + [36199].name = "gss_pipe_downcall",
82865 + [36199].param3 = 1,
82866 + [36206].file = "net/ipv4/tcp_input.c",
82867 + [36206].name = "tcp_collapse",
82868 + [36206].param5 = 1,
82869 + [36206].param6 = 1,
82870 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
82871 + [36230].name = "ppp_cp_parse_cr",
82872 + [36230].param4 = 1,
82873 + [36284].file = "drivers/spi/spi.c",
82874 + [36284].name = "spi_register_board_info",
82875 + [36284].param2 = 1,
82876 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82877 + [36490].name = "ath6kl_cfg80211_connect_event",
82878 + [36490].param7 = 1,
82879 + [36522].file = "drivers/hid/hidraw.c",
82880 + [36522].name = "hidraw_send_report",
82881 + [36522].param3 = 1,
82882 + [36560].file = "net/sunrpc/cache.c",
82883 + [36560].name = "write_flush",
82884 + [36560].param3 = 1,
82885 + [36807].file = "drivers/usb/mon/mon_bin.c",
82886 + [36807].name = "mon_bin_get_event",
82887 + [36807].param4 = 1,
82888 + [37034].file = "fs/cifs/cifssmb.c",
82889 + [37034].name = "cifs_writedata_alloc",
82890 + [37034].param1 = 1,
82891 + [37044].file = "sound/firewire/packets-buffer.c",
82892 + [37044].name = "iso_packets_buffer_init",
82893 + [37044].param3 = 1,
82894 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
82895 + [37108].name = "dvb_video_write",
82896 + [37108].param3 = 1,
82897 + [37154].file = "net/nfc/llcp/commands.c",
82898 + [37154].name = "nfc_llcp_build_tlv",
82899 + [37154].param3 = 1,
82900 + [37163].file = "net/core/skbuff.c",
82901 + [37163].name = "__netdev_alloc_skb",
82902 + [37163].param2 = 1,
82903 + [37233].file = "fs/ocfs2/cluster/tcp.c",
82904 + [37233].name = "o2net_send_message_vec",
82905 + [37233].param4 = 1,
82906 + [37241].file = "net/atm/lec.c",
82907 + [37241].name = "lane2_associate_req",
82908 + [37241].param4 = 1,
82909 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
82910 + [37384].name = "vmw_fifo_reserve",
82911 + [37384].param2 = 1,
82912 + [37497].file = "net/mac80211/util.c",
82913 + [37497].name = "ieee80211_build_probe_req",
82914 + [37497].param7 = 1,
82915 + [37535].file = "kernel/trace/trace.c",
82916 + [37535].name = "tracing_trace_options_write",
82917 + [37535].param3 = 1,
82918 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
82919 + [37611].name = "split",
82920 + [37611].param2 = 1,
82921 + [37661].file = "mm/filemap.c",
82922 + [37661].name = "file_read_actor",
82923 + [37661].param4 = 1,
82924 + [37852].file = "drivers/staging/android/logger.c",
82925 + [37852].name = "do_read_log_to_user",
82926 + [37852].param4 = 1,
82927 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
82928 + [37921].name = "wl1271_rx_handle_data",
82929 + [37921].param3 = 1,
82930 + [37976].file = "drivers/platform/x86/asus_acpi.c",
82931 + [37976].name = "bluetooth_proc_write",
82932 + [37976].param3 = 1,
82933 + [3797].file = "sound/pci/asihpi/hpicmn.c",
82934 + [3797].name = "hpi_alloc_control_cache",
82935 + [3797].param1 = 1,
82936 + [3801].file = "drivers/block/paride/pt.c",
82937 + [3801].name = "pt_write",
82938 + [3801].param3 = 1,
82939 + [38052].file = "kernel/kexec.c",
82940 + [38052].name = "kimage_normal_alloc",
82941 + [38052].param3 = 1,
82942 + [38057].file = "fs/coda/psdev.c",
82943 + [38057].name = "coda_psdev_write",
82944 + [38057].param3 = 1,
82945 + [38186].file = "kernel/signal.c",
82946 + [38186].name = "do_sigpending",
82947 + [38186].param2 = 1,
82948 + [38314].file = "fs/nfs/read.c",
82949 + [38314].name = "nfs_readdata_alloc",
82950 + [38314].param1 = 1,
82951 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82952 + [38401].name = "queue_reply",
82953 + [38401].param3 = 1,
82954 + [3841].file = "drivers/platform/x86/asus_acpi.c",
82955 + [3841].name = "write_led",
82956 + [3841].param2 = 1,
82957 + [38532].file = "fs/afs/cell.c",
82958 + [38532].name = "afs_cell_lookup",
82959 + [38532].param2 = 1,
82960 + [38564].file = "fs/nfs/nfs4proc.c",
82961 + [38564].name = "nfs4_realloc_slot_table",
82962 + [38564].param2 = 1,
82963 + [38576].file = "drivers/i2c/i2c-dev.c",
82964 + [38576].name = "i2cdev_read",
82965 + [38576].param3 = 1,
82966 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
82967 + [38704].name = "uvc_alloc_entity",
82968 + [38704].param3 = 1,
82969 + [38704].param4 = 1,
82970 + [38747].file = "fs/xattr.c",
82971 + [38747].name = "sys_lgetxattr",
82972 + [38747].param4 = 1,
82973 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
82974 + [38867].name = "fc_host_post_vendor_event",
82975 + [38867].param3 = 1,
82976 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
82977 + [38931].name = "diva_os_alloc_message_buffer",
82978 + [38931].param1 = 1,
82979 + [38972].file = "security/smack/smackfs.c",
82980 + [38972].name = "smk_write_logging",
82981 + [38972].param3 = 1,
82982 + [39001].file = "net/xfrm/xfrm_hash.c",
82983 + [39001].name = "xfrm_hash_alloc",
82984 + [39001].param1 = 1,
82985 + [39052].file = "drivers/input/evdev.c",
82986 + [39052].name = "evdev_ioctl",
82987 + [39052].param2 = 1,
82988 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
82989 + [39066].name = "tda10048_writeregbulk",
82990 + [39066].param4 = 1,
82991 + [39118].file = "drivers/misc/iwmc3200top/log.c",
82992 + [39118].name = "store_iwmct_log_level_fw",
82993 + [39118].param4 = 1,
82994 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
82995 + [39254].name = "cmm_write",
82996 + [39254].param3 = 1,
82997 + [39392].file = "drivers/atm/solos-pci.c",
82998 + [39392].name = "send_command",
82999 + [39392].param4 = 1,
83000 + [39415].file = "fs/pstore/inode.c",
83001 + [39415].name = "pstore_mkfile",
83002 + [39415].param5 = 1,
83003 + [39417].file = "drivers/block/DAC960.c",
83004 + [39417].name = "dac960_user_command_proc_write",
83005 + [39417].param3 = 1,
83006 + [39460].file = "fs/btrfs/volumes.c",
83007 + [39460].name = "btrfs_map_block",
83008 + [39460].param3 = 1,
83009 + [39479].file = "drivers/ide/ide-tape.c",
83010 + [39479].name = "idetape_chrdev_read",
83011 + [39479].param3 = 1,
83012 + [39586].file = "drivers/hv/channel.c",
83013 + [39586].name = "create_gpadl_header",
83014 + [39586].param2 = 1,
83015 + [39638].file = "security/selinux/selinuxfs.c",
83016 + [39638].name = "sel_write_avc_cache_threshold",
83017 + [39638].param3 = 1,
83018 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
83019 + [39645].name = "dvb_generic_ioctl",
83020 + [39645].param2 = 1,
83021 + [39770].file = "include/linux/mISDNif.h",
83022 + [39770].name = "mI_alloc_skb",
83023 + [39770].param1 = 1,
83024 + [39813].file = "fs/ocfs2/stack_user.c",
83025 + [39813].name = "ocfs2_control_message",
83026 + [39813].param3 = 1,
83027 + [39888].file = "net/core/skbuff.c",
83028 + [39888].name = "__alloc_skb",
83029 + [39888].param1 = 1,
83030 + [39980].file = "net/bluetooth/mgmt.c",
83031 + [39980].name = "pair_device",
83032 + [39980].param4 = 1,
83033 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
83034 + [40043].name = "video_ioctl2",
83035 + [40043].param2 = 1,
83036 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
83037 + [40049].name = "btmrvl_psmode_write",
83038 + [40049].param3 = 1,
83039 + [40075].file = "drivers/media/video/c-qcam.c",
83040 + [40075].name = "qc_capture",
83041 + [40075].param3 = 1,
83042 + [40163].file = "fs/ncpfs/file.c",
83043 + [40163].name = "ncp_file_write",
83044 + [40163].param3 = 1,
83045 + [40240].file = "drivers/char/nvram.c",
83046 + [40240].name = "nvram_write",
83047 + [40240].param3 = 1,
83048 + [40256].file = "drivers/tty/vt/vc_screen.c",
83049 + [40256].name = "vcs_write",
83050 + [40256].param3 = 1,
83051 + [40302].file = "sound/isa/gus/gus_dram.c",
83052 + [40302].name = "snd_gus_dram_poke",
83053 + [40302].param4 = 1,
83054 + [40339].file = "drivers/acpi/apei/hest.c",
83055 + [40339].name = "hest_ghes_dev_register",
83056 + [40339].param1 = 1,
83057 + [40355].file = "drivers/staging/mei/main.c",
83058 + [40355].name = "mei_write",
83059 + [40355].param3 = 1,
83060 + [40373].file = "fs/cifs/cifs_spnego.c",
83061 + [40373].name = "cifs_spnego_key_instantiate",
83062 + [40373].param3 = 1,
83063 + [40519].file = "net/sctp/socket.c",
83064 + [40519].name = "sctp_setsockopt_events",
83065 + [40519].param3 = 1,
83066 + [40694].file = "mm/page_cgroup.c",
83067 + [40694].name = "alloc_page_cgroup",
83068 + [40694].param1 = 1,
83069 + [40731].file = "drivers/tty/tty_io.c",
83070 + [40731].name = "do_tty_write",
83071 + [40731].param5 = 1,
83072 + [40754].file = "fs/btrfs/delayed-inode.c",
83073 + [40754].name = "btrfs_alloc_delayed_item",
83074 + [40754].param1 = 1,
83075 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
83076 + [40786].name = "asn1_octets_decode",
83077 + [40786].param2 = 1,
83078 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
83079 + [40901].name = "drbd_bm_resize",
83080 + [40901].param2 = 1,
83081 + [40951].file = "drivers/xen/evtchn.c",
83082 + [40951].name = "evtchn_read",
83083 + [40951].param3 = 1,
83084 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
83085 + [40952].name = "xpc_kmalloc_cacheline_aligned",
83086 + [40952].param1 = 1,
83087 + [41000].file = "sound/core/pcm_native.c",
83088 + [41000].name = "snd_pcm_aio_read",
83089 + [41000].param3 = 1,
83090 + [41005].file = "net/bridge/netfilter/ebtables.c",
83091 + [41005].name = "copy_counters_to_user",
83092 + [41005].param5 = 1,
83093 + [41041].file = "net/core/sock.c",
83094 + [41041].name = "sock_wmalloc",
83095 + [41041].param2 = 1,
83096 + [41122].file = "fs/binfmt_misc.c",
83097 + [41122].name = "bm_status_write",
83098 + [41122].param3 = 1,
83099 + [41176].file = "kernel/trace/trace_events.c",
83100 + [41176].name = "subsystem_filter_write",
83101 + [41176].param3 = 1,
83102 + [41249].file = "drivers/media/video/zr364xx.c",
83103 + [41249].name = "send_control_msg",
83104 + [41249].param6 = 1,
83105 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
83106 + [41287].name = "vxge_os_dma_malloc_async",
83107 + [41287].param3 = 1,
83108 + [41302].file = "net/dns_resolver/dns_query.c",
83109 + [41302].name = "dns_query",
83110 + [41302].param3 = 1,
83111 + [41408].file = "mm/filemap_xip.c",
83112 + [41408].name = "__xip_file_write",
83113 + [41408].param3 = 1,
83114 + [41547].file = "net/bluetooth/smp.c",
83115 + [41547].name = "smp_build_cmd",
83116 + [41547].param3 = 1,
83117 + [4155].file = "kernel/kexec.c",
83118 + [4155].name = "do_kimage_alloc",
83119 + [4155].param3 = 1,
83120 + [41676].file = "fs/compat.c",
83121 + [41676].name = "compat_sys_preadv",
83122 + [41676].param3 = 1,
83123 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
83124 + [4167].name = "cx24116_writeregN",
83125 + [4167].param4 = 1,
83126 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83127 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
83128 + [41793].param7 = 1,
83129 + [41924].file = "security/keys/keyctl.c",
83130 + [41924].name = "keyctl_get_security",
83131 + [41924].param3 = 1,
83132 + [41968].file = "fs/btrfs/volumes.c",
83133 + [41968].name = "__btrfs_map_block",
83134 + [41968].param3 = 1,
83135 + [4202].file = "drivers/edac/edac_mc.c",
83136 + [4202].name = "edac_mc_alloc",
83137 + [4202].param1 = 1,
83138 + [42081].file = "net/econet/af_econet.c",
83139 + [42081].name = "aun_incoming",
83140 + [42081].param3 = 1,
83141 + [42143].file = "drivers/media/video/c-qcam.c",
83142 + [42143].name = "qcam_read",
83143 + [42143].param3 = 1,
83144 + [42206].file = "fs/quota/quota_tree.c",
83145 + [42206].name = "getdqbuf",
83146 + [42206].param1 = 1,
83147 + [42270].file = "net/wireless/scan.c",
83148 + [42270].name = "cfg80211_inform_bss_frame",
83149 + [42270].param4 = 1,
83150 + [42281].file = "include/linux/mISDNif.h",
83151 + [42281].name = "_queue_data",
83152 + [42281].param4 = 1,
83153 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83154 + [42420].name = "prism2_set_genericelement",
83155 + [42420].param3 = 1,
83156 + [42472].file = "fs/compat.c",
83157 + [42472].name = "compat_readv",
83158 + [42472].param3 = 1,
83159 + [42473].file = "net/tipc/name_table.c",
83160 + [42473].name = "tipc_subseq_alloc",
83161 + [42473].param1 = 1,
83162 + [42562].file = "kernel/kfifo.c",
83163 + [42562].name = "__kfifo_to_user_r",
83164 + [42562].param3 = 1,
83165 + [42666].file = "drivers/pcmcia/cistpl.c",
83166 + [42666].name = "read_cis_cache",
83167 + [42666].param4 = 1,
83168 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
83169 + [42714].name = "scsi_tgt_copy_sense",
83170 + [42714].param3 = 1,
83171 + [42833].file = "kernel/trace/blktrace.c",
83172 + [42833].name = "blk_msg_write",
83173 + [42833].param3 = 1,
83174 + [42857].file = "security/selinux/selinuxfs.c",
83175 + [42857].name = "sel_write_member",
83176 + [42857].param3 = 1,
83177 + [42882].file = "security/keys/user_defined.c",
83178 + [42882].name = "user_instantiate",
83179 + [42882].param3 = 1,
83180 + [42930].file = "net/caif/cfpkt_skbuff.c",
83181 + [42930].name = "cfpkt_create_pfx",
83182 + [42930].param1 = 1,
83183 + [42930].param2 = 1,
83184 + [43023].file = "drivers/usb/misc/usblcd.c",
83185 + [43023].name = "lcd_write",
83186 + [43023].param3 = 1,
83187 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
83188 + [43104].name = "dataflash_read_user_otp",
83189 + [43104].param3 = 1,
83190 + [43133].file = "lib/mpi/mpiutil.c",
83191 + [43133].name = "mpi_resize",
83192 + [43133].param2 = 1,
83193 + [4324].file = "drivers/video/fbmem.c",
83194 + [4324].name = "fb_read",
83195 + [4324].param3 = 1,
83196 + [43266].file = "fs/afs/cell.c",
83197 + [43266].name = "afs_cell_alloc",
83198 + [43266].param2 = 1,
83199 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
83200 + [4328].name = "musb_test_mode_write",
83201 + [4328].param3 = 1,
83202 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83203 + [43380].name = "bfad_debugfs_write_regrd",
83204 + [43380].param3 = 1,
83205 + [43510].file = "kernel/kexec.c",
83206 + [43510].name = "compat_sys_kexec_load",
83207 + [43510].param2 = 1,
83208 + [43540].file = "include/rdma/ib_verbs.h",
83209 + [43540].name = "ib_copy_to_udata",
83210 + [43540].param3 = 1,
83211 + [4357].file = "security/tomoyo/securityfs_if.c",
83212 + [4357].name = "tomoyo_read_self",
83213 + [4357].param3 = 1,
83214 + [43590].file = "security/smack/smackfs.c",
83215 + [43590].name = "smk_write_onlycap",
83216 + [43590].param3 = 1,
83217 + [43596].file = "drivers/usb/core/buffer.c",
83218 + [43596].name = "hcd_buffer_alloc",
83219 + [43596].param2 = 1,
83220 + [43632].file = "drivers/media/video/videobuf2-core.c",
83221 + [43632].name = "vb2_read",
83222 + [43632].param3 = 1,
83223 + [43659].file = "drivers/firmware/efivars.c",
83224 + [43659].name = "efivar_create_sysfs_entry",
83225 + [43659].param2 = 1,
83226 + [43731].file = "drivers/hid/hid-picolcd.c",
83227 + [43731].name = "picolcd_debug_eeprom_read",
83228 + [43731].param3 = 1,
83229 + [43777].file = "drivers/acpi/acpica/utobject.c",
83230 + [43777].name = "acpi_ut_create_buffer_object",
83231 + [43777].param1 = 1,
83232 + [43798].file = "net/bluetooth/mgmt.c",
83233 + [43798].name = "set_local_name",
83234 + [43798].param4 = 1,
83235 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
83236 + [4380].name = "dataflash_read_fact_otp",
83237 + [4380].param3 = 1,
83238 + [43834].file = "security/apparmor/apparmorfs.c",
83239 + [43834].name = "profile_replace",
83240 + [43834].param3 = 1,
83241 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83242 + [43895].name = "ddb_output_write",
83243 + [43895].param3 = 1,
83244 + [43899].file = "drivers/media/rc/imon.c",
83245 + [43899].name = "vfd_write",
83246 + [43899].param3 = 1,
83247 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
83248 + [43900].name = "cxgbi_device_portmap_create",
83249 + [43900].param3 = 1,
83250 + [43922].file = "drivers/mmc/card/mmc_test.c",
83251 + [43922].name = "mmc_test_alloc_mem",
83252 + [43922].param3 = 1,
83253 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
83254 + [43946].name = "aggr_recv_addba_req_evt",
83255 + [43946].param4 = 1,
83256 + [44006].file = "mm/process_vm_access.c",
83257 + [44006].name = "process_vm_rw_pages",
83258 + [44006].param5 = 1,
83259 + [44006].param6 = 1,
83260 + [44050].file = "fs/nfs/idmap.c",
83261 + [44050].name = "nfs_map_group_to_gid",
83262 + [44050].param3 = 1,
83263 + [44125].file = "fs/ext4/super.c",
83264 + [44125].name = "ext4_kvmalloc",
83265 + [44125].param1 = 1,
83266 + [44266].file = "kernel/cgroup.c",
83267 + [44266].name = "cgroup_write_string",
83268 + [44266].param5 = 1,
83269 + [44290].file = "drivers/net/usb/dm9601.c",
83270 + [44290].name = "dm_read",
83271 + [44290].param3 = 1,
83272 + [44308].file = "crypto/af_alg.c",
83273 + [44308].name = "alg_setkey",
83274 + [44308].param3 = 1,
83275 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
83276 + [44510].name = "bnx2_nvram_write",
83277 + [44510].param2 = 1,
83278 + [44625].file = "net/bluetooth/mgmt.c",
83279 + [44625].name = "set_connectable",
83280 + [44625].param4 = 1,
83281 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
83282 + [44642].name = "iwm_umac_set_config_var",
83283 + [44642].param4 = 1,
83284 + [44698].file = "net/sctp/socket.c",
83285 + [44698].name = "sctp_setsockopt_context",
83286 + [44698].param3 = 1,
83287 + [4471].file = "fs/ntfs/malloc.h",
83288 + [4471].name = "__ntfs_malloc",
83289 + [4471].param1 = 1,
83290 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83291 + [44773].name = "vme_user_write",
83292 + [44773].param3 = 1,
83293 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83294 + [44825].name = "_osd_realloc_seg",
83295 + [44825].param3 = 1,
83296 + [44852].file = "net/sctp/socket.c",
83297 + [44852].name = "sctp_setsockopt_rtoinfo",
83298 + [44852].param3 = 1,
83299 + [44936].file = "drivers/md/dm-raid.c",
83300 + [44936].name = "context_alloc",
83301 + [44936].param3 = 1,
83302 + [44943].file = "mm/util.c",
83303 + [44943].name = "kmemdup",
83304 + [44943].param2 = 1,
83305 + [44946].file = "net/sctp/socket.c",
83306 + [44946].name = "sctp_setsockopt_auth_chunk",
83307 + [44946].param3 = 1,
83308 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83309 + [44990].name = "pvr2_ioread_set_sync_key",
83310 + [44990].param3 = 1,
83311 + [45000].file = "fs/afs/proc.c",
83312 + [45000].name = "afs_proc_rootcell_write",
83313 + [45000].param3 = 1,
83314 + [45117].file = "drivers/staging/winbond/wb35reg.c",
83315 + [45117].name = "Wb35Reg_BurstWrite",
83316 + [45117].param4 = 1,
83317 + [45200].file = "drivers/scsi/scsi_proc.c",
83318 + [45200].name = "proc_scsi_write_proc",
83319 + [45200].param3 = 1,
83320 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83321 + [45217].name = "iwl_dbgfs_debug_level_write",
83322 + [45217].param3 = 1,
83323 + [45233].file = "net/rds/info.c",
83324 + [45233].name = "rds_info_getsockopt",
83325 + [45233].param3 = 1,
83326 + [45326].file = "drivers/mtd/ubi/cdev.c",
83327 + [45326].name = "vol_cdev_read",
83328 + [45326].param3 = 1,
83329 + [45335].file = "fs/read_write.c",
83330 + [45335].name = "vfs_writev",
83331 + [45335].param3 = 1,
83332 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83333 + [45366].name = "init_tid_tabs",
83334 + [45366].param2 = 1,
83335 + [45366].param3 = 1,
83336 + [45366].param4 = 1,
83337 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83338 + [45534].name = "carl9170_cmd_buf",
83339 + [45534].param3 = 1,
83340 + [45576].file = "net/netfilter/xt_recent.c",
83341 + [45576].name = "recent_mt_proc_write",
83342 + [45576].param3 = 1,
83343 + [45583].file = "fs/gfs2/dir.c",
83344 + [45583].name = "leaf_dealloc",
83345 + [45583].param3 = 1,
83346 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83347 + [45586].name = "rt2x00debug_write_bbp",
83348 + [45586].param3 = 1,
83349 + [45629].file = "lib/bch.c",
83350 + [45629].name = "bch_alloc",
83351 + [45629].param1 = 1,
83352 + [45633].file = "drivers/input/evdev.c",
83353 + [45633].name = "evdev_do_ioctl",
83354 + [45633].param2 = 1,
83355 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
83356 + [45743].name = "qlcnic_alloc_msix_entries",
83357 + [45743].param2 = 1,
83358 + [45864].file = "drivers/atm/ambassador.c",
83359 + [45864].name = "create_queues",
83360 + [45864].param2 = 1,
83361 + [45864].param3 = 1,
83362 + [45930].file = "security/apparmor/apparmorfs.c",
83363 + [45930].name = "profile_remove",
83364 + [45930].param3 = 1,
83365 + [45954].file = "drivers/usb/misc/legousbtower.c",
83366 + [45954].name = "tower_write",
83367 + [45954].param3 = 1,
83368 + [46140].file = "sound/core/memalloc.c",
83369 + [46140].name = "snd_mem_proc_write",
83370 + [46140].param3 = 1,
83371 + [4616].file = "net/sunrpc/cache.c",
83372 + [4616].name = "cache_do_downcall",
83373 + [4616].param3 = 1,
83374 + [46243].file = "fs/binfmt_misc.c",
83375 + [46243].name = "bm_register_write",
83376 + [46243].param3 = 1,
83377 + [46250].file = "fs/xattr.c",
83378 + [46250].name = "sys_getxattr",
83379 + [46250].param4 = 1,
83380 + [46343].file = "fs/compat.c",
83381 + [46343].name = "compat_do_readv_writev",
83382 + [46343].param4 = 1,
83383 + [46400].file = "drivers/staging/sep/sep_driver.c",
83384 + [46400].name = "sep_prepare_input_output_dma_table",
83385 + [46400].param2 = 1,
83386 + [46400].param3 = 1,
83387 + [46400].param4 = 1,
83388 + [4644].file = "drivers/net/usb/mcs7830.c",
83389 + [4644].name = "mcs7830_get_reg",
83390 + [4644].param3 = 1,
83391 + [46605].file = "sound/core/oss/pcm_oss.c",
83392 + [46605].name = "snd_pcm_oss_sync1",
83393 + [46605].param2 = 1,
83394 + [46630].file = "net/decnet/af_decnet.c",
83395 + [46630].name = "__dn_setsockopt",
83396 + [46630].param5 = 1,
83397 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83398 + [46655].name = "hdpvr_read",
83399 + [46655].param3 = 1,
83400 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83401 + [46685].name = "ttm_bo_fbdev_io",
83402 + [46685].param4 = 1,
83403 + [46742].file = "drivers/scsi/st.c",
83404 + [46742].name = "sgl_map_user_pages",
83405 + [46742].param2 = 1,
83406 + [46881].file = "drivers/char/lp.c",
83407 + [46881].name = "lp_write",
83408 + [46881].param3 = 1,
83409 + [47130].file = "kernel/kfifo.c",
83410 + [47130].name = "kfifo_copy_to_user",
83411 + [47130].param3 = 1,
83412 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83413 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83414 + [47265].param2 = 1,
83415 + [47265].param3 = 1,
83416 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
83417 + [47309].name = "asd_store_update_bios",
83418 + [47309].param4 = 1,
83419 + [47342].file = "fs/proc/base.c",
83420 + [47342].name = "sched_autogroup_write",
83421 + [47342].param3 = 1,
83422 + [47363].file = "drivers/input/evdev.c",
83423 + [47363].name = "evdev_ioctl_handler",
83424 + [47363].param2 = 1,
83425 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83426 + [47385].name = "zd_usb_iowrite16v",
83427 + [47385].param3 = 1,
83428 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83429 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
83430 + [4738].param3 = 1,
83431 + [47393].file = "drivers/net/wireless/ath/main.c",
83432 + [47393].name = "ath_rxbuf_alloc",
83433 + [47393].param2 = 1,
83434 + [47463].file = "fs/xfs/kmem.c",
83435 + [47463].name = "kmem_zalloc",
83436 + [47463].param1 = 1,
83437 + [47474].file = "kernel/trace/trace.c",
83438 + [47474].name = "tracing_buffers_read",
83439 + [47474].param3 = 1,
83440 + [47636].file = "drivers/usb/class/usblp.c",
83441 + [47636].name = "usblp_ioctl",
83442 + [47636].param2 = 1,
83443 + [47637].file = "drivers/block/cciss.c",
83444 + [47637].name = "cciss_proc_write",
83445 + [47637].param3 = 1,
83446 + [47712].file = "net/sctp/socket.c",
83447 + [47712].name = "sctp_setsockopt_maxburst",
83448 + [47712].param3 = 1,
83449 + [47728].file = "drivers/char/agp/isoch.c",
83450 + [47728].name = "agp_3_5_isochronous_node_enable",
83451 + [47728].param3 = 1,
83452 + [4779].file = "fs/pipe.c",
83453 + [4779].name = "pipe_set_size",
83454 + [4779].param2 = 1,
83455 + [47881].file = "security/selinux/selinuxfs.c",
83456 + [47881].name = "sel_write_disable",
83457 + [47881].param3 = 1,
83458 + [48111].file = "net/wireless/sme.c",
83459 + [48111].name = "cfg80211_roamed_bss",
83460 + [48111].param4 = 1,
83461 + [48111].param6 = 1,
83462 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
83463 + [48124].name = "iwm_notif_send",
83464 + [48124].param6 = 1,
83465 + [48155].file = "net/sctp/sm_make_chunk.c",
83466 + [48155].name = "sctp_make_abort_user",
83467 + [48155].param3 = 1,
83468 + [48182].file = "crypto/cryptd.c",
83469 + [48182].name = "cryptd_alloc_instance",
83470 + [48182].param2 = 1,
83471 + [48182].param3 = 1,
83472 + [48248].file = "security/keys/keyctl.c",
83473 + [48248].name = "keyctl_instantiate_key",
83474 + [48248].param3 = 1,
83475 + [4829].file = "drivers/block/floppy.c",
83476 + [4829].name = "fd_copyout",
83477 + [4829].param3 = 1,
83478 + [48632].file = "net/bluetooth/l2cap_core.c",
83479 + [48632].name = "l2cap_build_cmd",
83480 + [48632].param4 = 1,
83481 + [48642].file = "fs/hugetlbfs/inode.c",
83482 + [48642].name = "hugetlbfs_read",
83483 + [48642].param3 = 1,
83484 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83485 + [48720].name = "i915_max_freq_write",
83486 + [48720].param3 = 1,
83487 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83488 + [48768].name = "dev_irnet_write",
83489 + [48768].param3 = 1,
83490 + [48818].file = "net/sunrpc/svc.c",
83491 + [48818].name = "svc_pool_map_alloc_arrays",
83492 + [48818].param2 = 1,
83493 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83494 + [48856].name = "acpi_ut_initialize_buffer",
83495 + [48856].param2 = 1,
83496 + [48862].file = "net/sctp/socket.c",
83497 + [48862].name = "sctp_setsockopt_adaptation_layer",
83498 + [48862].param3 = 1,
83499 + [49126].file = "lib/prio_heap.c",
83500 + [49126].name = "heap_init",
83501 + [49126].param2 = 1,
83502 + [49143].file = "sound/core/oss/pcm_oss.c",
83503 + [49143].name = "snd_pcm_oss_write2",
83504 + [49143].param3 = 1,
83505 + [49216].file = "fs/read_write.c",
83506 + [49216].name = "do_readv_writev",
83507 + [49216].param4 = 1,
83508 + [49426].file = "net/bluetooth/l2cap_sock.c",
83509 + [49426].name = "l2cap_sock_setsockopt_old",
83510 + [49426].param4 = 1,
83511 + [49448].file = "drivers/isdn/gigaset/common.c",
83512 + [49448].name = "gigaset_initdriver",
83513 + [49448].param2 = 1,
83514 + [49494].file = "drivers/virtio/virtio_ring.c",
83515 + [49494].name = "vring_new_virtqueue",
83516 + [49494].param1 = 1,
83517 + [49499].file = "drivers/block/nvme.c",
83518 + [49499].name = "nvme_alloc_iod",
83519 + [49499].param1 = 1,
83520 + [49510].file = "net/sctp/socket.c",
83521 + [49510].name = "sctp_setsockopt_autoclose",
83522 + [49510].param3 = 1,
83523 + [4958].file = "drivers/net/wireless/p54/fwio.c",
83524 + [4958].name = "p54_alloc_skb",
83525 + [4958].param3 = 1,
83526 + [49604].file = "crypto/af_alg.c",
83527 + [49604].name = "alg_setsockopt",
83528 + [49604].param5 = 1,
83529 + [49646].file = "drivers/tty/vt/vt.c",
83530 + [49646].name = "vc_resize",
83531 + [49646].param2 = 1,
83532 + [49646].param3 = 1,
83533 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
83534 + [49658].name = "dma_attach",
83535 + [49658].param6 = 1,
83536 + [49658].param7 = 1,
83537 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83538 + [49663].name = "uvc_simplify_fraction",
83539 + [49663].param3 = 1,
83540 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83541 + [49746].name = "compat_do_arpt_set_ctl",
83542 + [49746].param4 = 1,
83543 + [49780].file = "net/mac80211/key.c",
83544 + [49780].name = "ieee80211_key_alloc",
83545 + [49780].param3 = 1,
83546 + [49805].file = "drivers/pci/pci.c",
83547 + [49805].name = "pci_add_cap_save_buffer",
83548 + [49805].param3 = 1,
83549 + [49845].file = "mm/vmalloc.c",
83550 + [49845].name = "__vmalloc_node",
83551 + [49845].param1 = 1,
83552 + [49929].file = "drivers/mtd/ubi/cdev.c",
83553 + [49929].name = "vol_cdev_direct_write",
83554 + [49929].param3 = 1,
83555 + [49935].file = "fs/xfs/kmem.c",
83556 + [49935].name = "kmem_zalloc_greedy",
83557 + [49935].param2 = 1,
83558 + [49935].param3 = 1,
83559 + [49].file = "net/atm/svc.c",
83560 + [49].name = "svc_setsockopt",
83561 + [49].param5 = 1,
83562 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83563 + [50518].name = "u_memcpya",
83564 + [50518].param2 = 1,
83565 + [50518].param3 = 1,
83566 + [5052].file = "drivers/char/ppdev.c",
83567 + [5052].name = "pp_read",
83568 + [5052].param3 = 1,
83569 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83570 + [50562].name = "zoran_write",
83571 + [50562].param3 = 1,
83572 + [50617].file = "fs/hugetlbfs/inode.c",
83573 + [50617].name = "hugetlbfs_read_actor",
83574 + [50617].param2 = 1,
83575 + [50617].param4 = 1,
83576 + [50617].param5 = 1,
83577 + [50692].file = "lib/ts_bm.c",
83578 + [50692].name = "bm_init",
83579 + [50692].param2 = 1,
83580 + [50813].file = "mm/vmalloc.c",
83581 + [50813].name = "__vmalloc_node_flags",
83582 + [50813].param1 = 1,
83583 + [5087].file = "drivers/atm/solos-pci.c",
83584 + [5087].name = "console_store",
83585 + [5087].param4 = 1,
83586 + [5102].file = "drivers/usb/misc/usbtest.c",
83587 + [5102].name = "usbtest_alloc_urb",
83588 + [5102].param3 = 1,
83589 + [5102].param5 = 1,
83590 + [51061].file = "net/bluetooth/mgmt.c",
83591 + [51061].name = "pin_code_reply",
83592 + [51061].param4 = 1,
83593 + [51139].file = "fs/pipe.c",
83594 + [51139].name = "pipe_iov_copy_to_user",
83595 + [51139].param3 = 1,
83596 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83597 + [51177].name = "xprt_rdma_allocate",
83598 + [51177].param2 = 1,
83599 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83600 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83601 + [51182].param1 = 1,
83602 + [51250].file = "fs/read_write.c",
83603 + [51250].name = "rw_copy_check_uvector",
83604 + [51250].param3 = 1,
83605 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83606 + [51253].name = "rt2x00debug_write_eeprom",
83607 + [51253].param3 = 1,
83608 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83609 + [51323].name = "snd_ac97_pcm_assign",
83610 + [51323].param2 = 1,
83611 + [51340].file = "drivers/usb/class/usblp.c",
83612 + [51340].name = "usblp_write",
83613 + [51340].param3 = 1,
83614 + [51499].file = "net/802/garp.c",
83615 + [51499].name = "garp_attr_create",
83616 + [51499].param3 = 1,
83617 + [51842].file = "drivers/hid/hid-core.c",
83618 + [51842].name = "hid_register_field",
83619 + [51842].param2 = 1,
83620 + [51842].param3 = 1,
83621 + [5197].file = "net/core/dev.c",
83622 + [5197].name = "dev_set_alias",
83623 + [5197].param3 = 1,
83624 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83625 + [5204].name = "usbvision_v4l2_read",
83626 + [5204].param3 = 1,
83627 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
83628 + [5206].name = "av7110_vbi_write",
83629 + [5206].param3 = 1,
83630 + [52086].file = "drivers/usb/image/mdc800.c",
83631 + [52086].name = "mdc800_device_read",
83632 + [52086].param3 = 1,
83633 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83634 + [52099].name = "do_surface_dirty_sou",
83635 + [52099].param7 = 1,
83636 + [52172].file = "drivers/pcmcia/cistpl.c",
83637 + [52172].name = "pccard_store_cis",
83638 + [52172].param6 = 1,
83639 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83640 + [52173].name = "remote_settings_file_write",
83641 + [52173].param3 = 1,
83642 + [52199].file = "mm/nobootmem.c",
83643 + [52199].name = "__alloc_bootmem",
83644 + [52199].param1 = 1,
83645 + [52343].file = "drivers/usb/misc/adutux.c",
83646 + [52343].name = "adu_read",
83647 + [52343].param3 = 1,
83648 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
83649 + [52401].name = "r871x_set_wpa_ie",
83650 + [52401].param3 = 1,
83651 + [52699].file = "lib/ts_fsm.c",
83652 + [52699].name = "fsm_init",
83653 + [52699].param2 = 1,
83654 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
83655 + [52721].name = "encrypted_instantiate",
83656 + [52721].param3 = 1,
83657 + [52902].file = "fs/xfs/kmem.h",
83658 + [52902].name = "kmem_zalloc_large",
83659 + [52902].param1 = 1,
83660 + [52950].file = "net/bluetooth/mgmt.c",
83661 + [52950].name = "set_discoverable",
83662 + [52950].param4 = 1,
83663 + [53041].file = "fs/libfs.c",
83664 + [53041].name = "simple_transaction_get",
83665 + [53041].param3 = 1,
83666 + [5313].file = "fs/gfs2/quota.c",
83667 + [5313].name = "do_sync",
83668 + [5313].param1 = 1,
83669 + [53209].file = "drivers/usb/host/ehci-sched.c",
83670 + [53209].name = "iso_sched_alloc",
83671 + [53209].param1 = 1,
83672 + [53302].file = "drivers/firewire/core-cdev.c",
83673 + [53302].name = "dispatch_ioctl",
83674 + [53302].param2 = 1,
83675 + [53355].file = "fs/ceph/dir.c",
83676 + [53355].name = "ceph_read_dir",
83677 + [53355].param3 = 1,
83678 + [53405].file = "drivers/media/video/videobuf-core.c",
83679 + [53405].name = "__videobuf_copy_to_user",
83680 + [53405].param4 = 1,
83681 + [53407].file = "net/wireless/sme.c",
83682 + [53407].name = "cfg80211_connect_result",
83683 + [53407].param4 = 1,
83684 + [53407].param6 = 1,
83685 + [53426].file = "fs/libfs.c",
83686 + [53426].name = "simple_transaction_read",
83687 + [53426].param3 = 1,
83688 + [5344].file = "security/selinux/ss/hashtab.c",
83689 + [5344].name = "hashtab_create",
83690 + [5344].param3 = 1,
83691 + [53513].file = "drivers/mmc/core/mmc_ops.c",
83692 + [53513].name = "mmc_send_bus_test",
83693 + [53513].param4 = 1,
83694 + [53626].file = "drivers/block/paride/pg.c",
83695 + [53626].name = "pg_read",
83696 + [53626].param3 = 1,
83697 + [53631].file = "mm/util.c",
83698 + [53631].name = "memdup_user",
83699 + [53631].param2 = 1,
83700 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
83701 + [53674].name = "ci_ll_write",
83702 + [53674].param4 = 1,
83703 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
83704 + [5389].name = "ib_uverbs_unmarshall_recv",
83705 + [5389].param5 = 1,
83706 + [53901].file = "net/rds/message.c",
83707 + [53901].name = "rds_message_alloc",
83708 + [53901].param1 = 1,
83709 + [53902].file = "net/sctp/socket.c",
83710 + [53902].name = "sctp_setsockopt_initmsg",
83711 + [53902].param3 = 1,
83712 + [5410].file = "kernel/kexec.c",
83713 + [5410].name = "sys_kexec_load",
83714 + [5410].param2 = 1,
83715 + [54172].file = "net/nfc/core.c",
83716 + [54172].name = "nfc_alloc_recv_skb",
83717 + [54172].param1 = 1,
83718 + [54182].file = "drivers/block/rbd.c",
83719 + [54182].name = "rbd_snap_add",
83720 + [54182].param4 = 1,
83721 + [54201].file = "drivers/platform/x86/asus_acpi.c",
83722 + [54201].name = "mled_proc_write",
83723 + [54201].param3 = 1,
83724 + [54263].file = "security/keys/trusted.c",
83725 + [54263].name = "trusted_instantiate",
83726 + [54263].param3 = 1,
83727 + [54296].file = "include/linux/mISDNif.h",
83728 + [54296].name = "_alloc_mISDN_skb",
83729 + [54296].param3 = 1,
83730 + [54298].file = "drivers/usb/wusbcore/crypto.c",
83731 + [54298].name = "wusb_ccm_mac",
83732 + [54298].param7 = 1,
83733 + [54318].file = "include/drm/drm_mem_util.h",
83734 + [54318].name = "drm_malloc_ab",
83735 + [54318].param1 = 1,
83736 + [54318].param2 = 1,
83737 + [54335].file = "drivers/md/dm-table.c",
83738 + [54335].name = "dm_vcalloc",
83739 + [54335].param1 = 1,
83740 + [54335].param2 = 1,
83741 + [54338].file = "fs/ntfs/malloc.h",
83742 + [54338].name = "ntfs_malloc_nofs",
83743 + [54338].param1 = 1,
83744 + [54339].file = "security/smack/smackfs.c",
83745 + [54339].name = "smk_write_cipso",
83746 + [54339].param3 = 1,
83747 + [54369].file = "drivers/usb/storage/realtek_cr.c",
83748 + [54369].name = "rts51x_read_mem",
83749 + [54369].param4 = 1,
83750 + [5438].file = "sound/core/memory.c",
83751 + [5438].name = "copy_to_user_fromio",
83752 + [5438].param3 = 1,
83753 + [54401].file = "lib/dynamic_debug.c",
83754 + [54401].name = "ddebug_proc_write",
83755 + [54401].param3 = 1,
83756 + [54467].file = "net/packet/af_packet.c",
83757 + [54467].name = "packet_setsockopt",
83758 + [54467].param5 = 1,
83759 + [54573].file = "ipc/sem.c",
83760 + [54573].name = "sys_semop",
83761 + [54573].param3 = 1,
83762 + [54583].file = "net/sctp/socket.c",
83763 + [54583].name = "sctp_setsockopt_peer_addr_params",
83764 + [54583].param3 = 1,
83765 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
83766 + [54643].name = "um_idi_write",
83767 + [54643].param3 = 1,
83768 + [54657].file = "mm/migrate.c",
83769 + [54657].name = "do_pages_stat",
83770 + [54657].param2 = 1,
83771 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
83772 + [54663].name = "diva_os_malloc",
83773 + [54663].param2 = 1,
83774 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
83775 + [54701].name = "altera_swap_ir",
83776 + [54701].param2 = 1,
83777 + [54751].file = "drivers/infiniband/core/device.c",
83778 + [54751].name = "ib_alloc_device",
83779 + [54751].param1 = 1,
83780 + [54771].file = "drivers/isdn/mISDN/socket.c",
83781 + [54771].name = "_l2_alloc_skb",
83782 + [54771].param1 = 1,
83783 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83784 + [54777].name = "ath6kl_debug_roam_tbl_event",
83785 + [54777].param3 = 1,
83786 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83787 + [54806].name = "lpfc_debugfs_dif_err_write",
83788 + [54806].param3 = 1,
83789 + [5494].file = "fs/cifs/cifsacl.c",
83790 + [5494].name = "cifs_idmap_key_instantiate",
83791 + [5494].param3 = 1,
83792 + [55066].file = "net/ipv6/ipv6_sockglue.c",
83793 + [55066].name = "do_ipv6_setsockopt",
83794 + [55066].param5 = 1,
83795 + [55105].file = "drivers/base/devres.c",
83796 + [55105].name = "devres_alloc",
83797 + [55105].param2 = 1,
83798 + [55115].file = "net/sctp/probe.c",
83799 + [55115].name = "sctpprobe_read",
83800 + [55115].param3 = 1,
83801 + [55155].file = "net/bluetooth/rfcomm/sock.c",
83802 + [55155].name = "rfcomm_sock_setsockopt",
83803 + [55155].param5 = 1,
83804 + [55187].file = "security/keys/keyctl.c",
83805 + [55187].name = "keyctl_describe_key",
83806 + [55187].param3 = 1,
83807 + [55253].file = "drivers/net/wireless/ray_cs.c",
83808 + [55253].name = "ray_cs_essid_proc_write",
83809 + [55253].param3 = 1,
83810 + [55341].file = "drivers/staging/sep/sep_driver.c",
83811 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
83812 + [55341].param4 = 1,
83813 + [55341].param5 = 1,
83814 + [55417].file = "drivers/hv/channel.c",
83815 + [55417].name = "vmbus_open",
83816 + [55417].param2 = 1,
83817 + [55417].param3 = 1,
83818 + [5548].file = "drivers/media/media-entity.c",
83819 + [5548].name = "media_entity_init",
83820 + [5548].param2 = 1,
83821 + [5548].param4 = 1,
83822 + [55546].file = "drivers/spi/spi.c",
83823 + [55546].name = "spi_alloc_master",
83824 + [55546].param2 = 1,
83825 + [55580].file = "drivers/usb/mon/mon_bin.c",
83826 + [55580].name = "copy_from_buf",
83827 + [55580].param2 = 1,
83828 + [55584].file = "drivers/tty/tty_buffer.c",
83829 + [55584].name = "tty_buffer_alloc",
83830 + [55584].param2 = 1,
83831 + [55712].file = "drivers/char/mem.c",
83832 + [55712].name = "read_zero",
83833 + [55712].param3 = 1,
83834 + [55727].file = "drivers/media/video/stk-webcam.c",
83835 + [55727].name = "stk_prepare_sio_buffers",
83836 + [55727].param2 = 1,
83837 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
83838 + [55816].name = "altera_set_ir_pre",
83839 + [55816].param2 = 1,
83840 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
83841 + [55826].name = "ipath_get_base_info",
83842 + [55826].param3 = 1,
83843 + [5586].file = "net/atm/common.c",
83844 + [5586].name = "alloc_tx",
83845 + [5586].param2 = 1,
83846 + [55978].file = "drivers/usb/misc/iowarrior.c",
83847 + [55978].name = "iowarrior_write",
83848 + [55978].param3 = 1,
83849 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
83850 + [56170].name = "__wa_xfer_setup_segs",
83851 + [56170].param2 = 1,
83852 + [56199].file = "fs/binfmt_misc.c",
83853 + [56199].name = "parse_command",
83854 + [56199].param2 = 1,
83855 + [56218].file = "drivers/mmc/card/mmc_test.c",
83856 + [56218].name = "mtf_test_write",
83857 + [56218].param3 = 1,
83858 + [56239].file = "fs/sysfs/file.c",
83859 + [56239].name = "fill_write_buffer",
83860 + [56239].param3 = 1,
83861 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
83862 + [5624].name = "ath9k_wmi_cmd",
83863 + [5624].param4 = 1,
83864 + [56416].file = "drivers/misc/lkdtm.c",
83865 + [56416].name = "do_register_entry",
83866 + [56416].param4 = 1,
83867 + [56458].file = "drivers/usb/host/hwa-hc.c",
83868 + [56458].name = "__hwahc_op_set_ptk",
83869 + [56458].param5 = 1,
83870 + [56471].file = "include/linux/slab.h",
83871 + [56471].name = "kcalloc",
83872 + [56471].param1 = 1,
83873 + [56471].param2 = 1,
83874 + [56513].file = "fs/cifs/connect.c",
83875 + [56513].name = "cifs_readv_from_socket",
83876 + [56513].param3 = 1,
83877 + [56531].file = "net/bluetooth/l2cap_core.c",
83878 + [56531].name = "l2cap_send_cmd",
83879 + [56531].param4 = 1,
83880 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
83881 + [56544].name = "receive_DataRequest",
83882 + [56544].param3 = 1,
83883 + [56609].file = "lib/mpi/mpi-internal.h",
83884 + [56609].name = "RESIZE_IF_NEEDED",
83885 + [56609].param2 = 1,
83886 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
83887 + [56652].name = "altera_set_dr_post",
83888 + [56652].param2 = 1,
83889 + [56653].file = "net/irda/af_irda.c",
83890 + [56653].name = "irda_setsockopt",
83891 + [56653].param5 = 1,
83892 + [56672].file = "drivers/char/agp/generic.c",
83893 + [56672].name = "agp_alloc_page_array",
83894 + [56672].param1 = 1,
83895 + [56798].file = "fs/bio.c",
83896 + [56798].name = "bio_alloc_map_data",
83897 + [56798].param2 = 1,
83898 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
83899 + [56843].name = "iscsi_recv_pdu",
83900 + [56843].param4 = 1,
83901 + [56903].file = "drivers/mtd/mtdchar.c",
83902 + [56903].name = "mtdchar_readoob",
83903 + [56903].param4 = 1,
83904 + [5699].file = "net/sctp/socket.c",
83905 + [5699].name = "sctp_setsockopt_default_send_param",
83906 + [5699].param3 = 1,
83907 + [5704].file = "drivers/mtd/mtdswap.c",
83908 + [5704].name = "mtdswap_init",
83909 + [5704].param2 = 1,
83910 + [57128].file = "drivers/pnp/pnpbios/proc.c",
83911 + [57128].name = "pnpbios_proc_write",
83912 + [57128].param3 = 1,
83913 + [57190].file = "drivers/char/agp/generic.c",
83914 + [57190].name = "agp_generic_alloc_user",
83915 + [57190].param1 = 1,
83916 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
83917 + [57252].name = "dvb_dmxdev_set_buffer_size",
83918 + [57252].param2 = 1,
83919 + [57392].file = "drivers/block/aoe/aoecmd.c",
83920 + [57392].name = "new_skb",
83921 + [57392].param1 = 1,
83922 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
83923 + [57471].name = "sn9c102_read",
83924 + [57471].param3 = 1,
83925 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
83926 + [57547].name = "get_derived_key",
83927 + [57547].param4 = 1,
83928 + [57552].file = "net/sunrpc/cache.c",
83929 + [57552].name = "cache_slow_downcall",
83930 + [57552].param2 = 1,
83931 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
83932 + [57670].name = "btmrvl_pscmd_write",
83933 + [57670].param3 = 1,
83934 + [57710].file = "include/linux/usb/wusb.h",
83935 + [57710].name = "wusb_prf_256",
83936 + [57710].param7 = 1,
83937 + [57724].file = "net/bluetooth/hci_sock.c",
83938 + [57724].name = "hci_sock_setsockopt",
83939 + [57724].param5 = 1,
83940 + [57761].file = "kernel/kexec.c",
83941 + [57761].name = "kimage_crash_alloc",
83942 + [57761].param3 = 1,
83943 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
83944 + [57786].name = "compat_do_ip6t_set_ctl",
83945 + [57786].param4 = 1,
83946 + [57872].file = "fs/ceph/xattr.c",
83947 + [57872].name = "ceph_setxattr",
83948 + [57872].param4 = 1,
83949 + [57927].file = "fs/read_write.c",
83950 + [57927].name = "sys_preadv",
83951 + [57927].param3 = 1,
83952 + [58012].file = "include/net/bluetooth/bluetooth.h",
83953 + [58012].name = "bt_skb_alloc",
83954 + [58012].param1 = 1,
83955 + [58020].file = "drivers/firewire/core-cdev.c",
83956 + [58020].name = "fw_device_op_ioctl",
83957 + [58020].param2 = 1,
83958 + [58043].file = "kernel/auditfilter.c",
83959 + [58043].name = "audit_unpack_string",
83960 + [58043].param3 = 1,
83961 + [58087].file = "kernel/module.c",
83962 + [58087].name = "module_alloc_update_bounds_rw",
83963 + [58087].param1 = 1,
83964 + [58124].file = "drivers/usb/misc/usbtest.c",
83965 + [58124].name = "ctrl_out",
83966 + [58124].param3 = 1,
83967 + [58124].param5 = 1,
83968 + [58217].file = "net/sctp/socket.c",
83969 + [58217].name = "sctp_setsockopt_peer_primary_addr",
83970 + [58217].param3 = 1,
83971 + [58263].file = "security/keys/keyring.c",
83972 + [58263].name = "keyring_read",
83973 + [58263].param3 = 1,
83974 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
83975 + [5830].name = "vga_switcheroo_debugfs_write",
83976 + [5830].param3 = 1,
83977 + [58320].file = "drivers/scsi/scsi_proc.c",
83978 + [58320].name = "proc_scsi_write",
83979 + [58320].param3 = 1,
83980 + [58344].file = "net/sunrpc/cache.c",
83981 + [58344].name = "read_flush",
83982 + [58344].param3 = 1,
83983 + [58379].file = "mm/nobootmem.c",
83984 + [58379].name = "__alloc_bootmem_node",
83985 + [58379].param2 = 1,
83986 + [58597].file = "kernel/kfifo.c",
83987 + [58597].name = "__kfifo_to_user",
83988 + [58597].param3 = 1,
83989 + [58641].file = "drivers/usb/misc/adutux.c",
83990 + [58641].name = "adu_write",
83991 + [58641].param3 = 1,
83992 + [58709].file = "fs/compat.c",
83993 + [58709].name = "compat_sys_pwritev",
83994 + [58709].param3 = 1,
83995 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83996 + [58769].name = "zd_usb_read_fw",
83997 + [58769].param4 = 1,
83998 + [5876].file = "drivers/net/ppp/ppp_generic.c",
83999 + [5876].name = "ppp_write",
84000 + [5876].param3 = 1,
84001 + [58826].file = "net/sunrpc/xprt.c",
84002 + [58826].name = "xprt_alloc",
84003 + [58826].param2 = 1,
84004 + [58865].file = "include/linux/slub_def.h",
84005 + [58865].name = "kmalloc_order_trace",
84006 + [58865].param1 = 1,
84007 + [58867].file = "drivers/platform/x86/asus_acpi.c",
84008 + [58867].name = "wled_proc_write",
84009 + [58867].param3 = 1,
84010 + [58888].file = "fs/xattr.c",
84011 + [58888].name = "listxattr",
84012 + [58888].param3 = 1,
84013 + [58889].file = "kernel/trace/trace_kprobe.c",
84014 + [58889].name = "probes_write",
84015 + [58889].param3 = 1,
84016 + [58912].file = "drivers/lguest/core.c",
84017 + [58912].name = "__lgwrite",
84018 + [58912].param4 = 1,
84019 + [58918].file = "sound/core/pcm_native.c",
84020 + [58918].name = "snd_pcm_aio_write",
84021 + [58918].param3 = 1,
84022 + [58942].file = "drivers/block/aoe/aoedev.c",
84023 + [58942].name = "aoedev_flush",
84024 + [58942].param2 = 1,
84025 + [58958].file = "fs/fuse/control.c",
84026 + [58958].name = "fuse_conn_limit_write",
84027 + [58958].param3 = 1,
84028 + [59005].file = "drivers/staging/sep/sep_driver.c",
84029 + [59005].name = "sep_prepare_input_dma_table",
84030 + [59005].param2 = 1,
84031 + [59005].param3 = 1,
84032 + [59013].file = "fs/xfs/xfs_ioctl.c",
84033 + [59013].name = "xfs_handle_to_dentry",
84034 + [59013].param3 = 1,
84035 + [59034].file = "drivers/acpi/acpica/dsobject.c",
84036 + [59034].name = "acpi_ds_build_internal_package_obj",
84037 + [59034].param3 = 1,
84038 + [59073].file = "drivers/staging/speakup/i18n.c",
84039 + [59073].name = "msg_set",
84040 + [59073].param3 = 1,
84041 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
84042 + [59074].name = "ddp_make_gl",
84043 + [59074].param1 = 1,
84044 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
84045 + [59297].name = "dvb_play",
84046 + [59297].param3 = 1,
84047 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
84048 + [59472].name = "command_file_write",
84049 + [59472].param3 = 1,
84050 + [59504].file = "fs/exofs/super.c",
84051 + [59504].name = "__alloc_dev_table",
84052 + [59504].param2 = 1,
84053 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
84054 + [59505].name = "pvr2_ioread_read",
84055 + [59505].param3 = 1,
84056 + [59681].file = "fs/xfs/kmem.c",
84057 + [59681].name = "kmem_alloc",
84058 + [59681].param1 = 1,
84059 + [5968].file = "net/sunrpc/sched.c",
84060 + [5968].name = "rpc_malloc",
84061 + [5968].param2 = 1,
84062 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
84063 + [59695].name = "ulog_alloc_skb",
84064 + [59695].param1 = 1,
84065 + [59838].file = "net/netlink/af_netlink.c",
84066 + [59838].name = "nl_pid_hash_zalloc",
84067 + [59838].param1 = 1,
84068 + [59856].file = "drivers/base/devres.c",
84069 + [59856].name = "devm_kzalloc",
84070 + [59856].param2 = 1,
84071 + [60066].file = "mm/filemap.c",
84072 + [60066].name = "iov_iter_copy_from_user",
84073 + [60066].param4 = 1,
84074 + [60185].file = "kernel/params.c",
84075 + [60185].name = "kmalloc_parameter",
84076 + [60185].param1 = 1,
84077 + [60198].file = "fs/nfs/nfs4proc.c",
84078 + [60198].name = "nfs4_write_cached_acl",
84079 + [60198].param3 = 1,
84080 + [60330].file = "drivers/media/video/w9966.c",
84081 + [60330].name = "w9966_v4l_read",
84082 + [60330].param3 = 1,
84083 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
84084 + [604].name = "r8712_usbctrl_vendorreq",
84085 + [604].param6 = 1,
84086 + [60543].file = "drivers/usb/class/usbtmc.c",
84087 + [60543].name = "usbtmc_read",
84088 + [60543].param3 = 1,
84089 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
84090 + [60683].name = "snd_opl4_mem_proc_write",
84091 + [60683].param5 = 1,
84092 + [60693].file = "drivers/misc/hpilo.c",
84093 + [60693].name = "ilo_read",
84094 + [60693].param3 = 1,
84095 + [60744].file = "sound/pci/emu10k1/emuproc.c",
84096 + [60744].name = "snd_emu10k1_fx8010_read",
84097 + [60744].param5 = 1,
84098 + [60777].file = "fs/ntfs/malloc.h",
84099 + [60777].name = "ntfs_malloc_nofs_nofail",
84100 + [60777].param1 = 1,
84101 + [60833].file = "drivers/block/aoe/aoenet.c",
84102 + [60833].name = "set_aoe_iflist",
84103 + [60833].param2 = 1,
84104 + [60882].file = "drivers/input/joydev.c",
84105 + [60882].name = "joydev_compat_ioctl",
84106 + [60882].param2 = 1,
84107 + [60891].file = "kernel/sched/core.c",
84108 + [60891].name = "sys_sched_setaffinity",
84109 + [60891].param2 = 1,
84110 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
84111 + [60920].name = "qib_get_base_info",
84112 + [60920].param3 = 1,
84113 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
84114 + [60928].name = "bcm_char_read",
84115 + [60928].param3 = 1,
84116 + [61122].file = "drivers/base/devres.c",
84117 + [61122].name = "alloc_dr",
84118 + [61122].param2 = 1,
84119 + [61254].file = "drivers/scsi/scsi_devinfo.c",
84120 + [61254].name = "proc_scsi_devinfo_write",
84121 + [61254].param3 = 1,
84122 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84123 + [61283].name = "ath6kl_fwlog_read",
84124 + [61283].param3 = 1,
84125 + [61289].file = "security/apparmor/apparmorfs.c",
84126 + [61289].name = "aa_simple_write_to_buffer",
84127 + [61289].param4 = 1,
84128 + [61389].file = "include/linux/slab.h",
84129 + [61389].name = "kzalloc_node",
84130 + [61389].param1 = 1,
84131 + [61441].file = "fs/ntfs/file.c",
84132 + [61441].name = "ntfs_copy_from_user_iovec",
84133 + [61441].param3 = 1,
84134 + [61441].param6 = 1,
84135 + [61552].file = "drivers/input/evdev.c",
84136 + [61552].name = "str_to_user",
84137 + [61552].param2 = 1,
84138 + [61673].file = "security/keys/trusted.c",
84139 + [61673].name = "trusted_update",
84140 + [61673].param3 = 1,
84141 + [61676].file = "kernel/module.c",
84142 + [61676].name = "module_alloc_update_bounds_rx",
84143 + [61676].param1 = 1,
84144 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84145 + [61684].name = "cxgb3_get_cpl_reply_skb",
84146 + [61684].param2 = 1,
84147 + [6173].file = "net/netlink/af_netlink.c",
84148 + [6173].name = "netlink_sendmsg",
84149 + [6173].param4 = 1,
84150 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84151 + [61770].name = "et61x251_read",
84152 + [61770].param3 = 1,
84153 + [61772].file = "fs/exofs/ore_raid.c",
84154 + [61772].name = "_sp2d_alloc",
84155 + [61772].param1 = 1,
84156 + [61772].param2 = 1,
84157 + [61772].param3 = 1,
84158 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84159 + [61926].name = "ddb_input_read",
84160 + [61926].param3 = 1,
84161 + [61932].file = "drivers/message/fusion/mptctl.c",
84162 + [61932].name = "__mptctl_ioctl",
84163 + [61932].param2 = 1,
84164 + [61966].file = "fs/nfs/nfs4proc.c",
84165 + [61966].name = "nfs4_alloc_slots",
84166 + [61966].param1 = 1,
84167 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84168 + [62081].name = "vlsi_alloc_ring",
84169 + [62081].param3 = 1,
84170 + [62081].param4 = 1,
84171 + [62116].file = "fs/libfs.c",
84172 + [62116].name = "simple_attr_read",
84173 + [62116].param3 = 1,
84174 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
84175 + [6211].name = "pcnet32_realloc_tx_ring",
84176 + [6211].param3 = 1,
84177 + [62294].file = "sound/core/info.c",
84178 + [62294].name = "resize_info_buffer",
84179 + [62294].param2 = 1,
84180 + [62387].file = "fs/nfs/idmap.c",
84181 + [62387].name = "nfs_idmap_lookup_id",
84182 + [62387].param2 = 1,
84183 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
84184 + [62465].name = "altera_set_dr_pre",
84185 + [62465].param2 = 1,
84186 + [62466].file = "lib/mpi/mpiutil.c",
84187 + [62466].name = "mpi_alloc",
84188 + [62466].param1 = 1,
84189 + [62495].file = "drivers/block/floppy.c",
84190 + [62495].name = "fallback_on_nodma_alloc",
84191 + [62495].param2 = 1,
84192 + [62498].file = "fs/xattr.c",
84193 + [62498].name = "sys_listxattr",
84194 + [62498].param3 = 1,
84195 + [625].file = "fs/read_write.c",
84196 + [625].name = "sys_pwritev",
84197 + [625].param3 = 1,
84198 + [62662].file = "drivers/message/fusion/mptctl.c",
84199 + [62662].name = "mptctl_getiocinfo",
84200 + [62662].param2 = 1,
84201 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84202 + [62669].name = "tled_proc_write",
84203 + [62669].param3 = 1,
84204 + [62714].file = "security/keys/keyctl.c",
84205 + [62714].name = "keyctl_update_key",
84206 + [62714].param3 = 1,
84207 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
84208 + [62760].name = "play_iframe",
84209 + [62760].param3 = 1,
84210 + [62851].file = "fs/proc/vmcore.c",
84211 + [62851].name = "read_vmcore",
84212 + [62851].param3 = 1,
84213 + [62870].file = "fs/nfs/idmap.c",
84214 + [62870].name = "nfs_idmap_get_desc",
84215 + [62870].param2 = 1,
84216 + [62870].param4 = 1,
84217 + [62905].file = "net/caif/cfpkt_skbuff.c",
84218 + [62905].name = "cfpkt_create",
84219 + [62905].param1 = 1,
84220 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
84221 + [62920].name = "b43_nphy_load_samples",
84222 + [62920].param3 = 1,
84223 + [62925].file = "include/rdma/ib_verbs.h",
84224 + [62925].name = "ib_copy_from_udata",
84225 + [62925].param3 = 1,
84226 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
84227 + [62934].name = "wl1251_cmd_template_set",
84228 + [62934].param4 = 1,
84229 + [62940].file = "drivers/scsi/libsrp.c",
84230 + [62940].name = "srp_ring_alloc",
84231 + [62940].param2 = 1,
84232 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84233 + [62967].name = "encrypted_update",
84234 + [62967].param3 = 1,
84235 + [62970].file = "net/sched/sch_api.c",
84236 + [62970].name = "qdisc_class_hash_alloc",
84237 + [62970].param1 = 1,
84238 + [62999].file = "net/core/neighbour.c",
84239 + [62999].name = "neigh_hash_alloc",
84240 + [62999].param1 = 1,
84241 + [63007].file = "fs/proc/base.c",
84242 + [63007].name = "proc_coredump_filter_write",
84243 + [63007].param3 = 1,
84244 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84245 + [63010].name = "ttm_page_pool_free",
84246 + [63010].param2 = 1,
84247 + [63045].file = "crypto/shash.c",
84248 + [63045].name = "shash_setkey_unaligned",
84249 + [63045].param3 = 1,
84250 + [63075].file = "kernel/relay.c",
84251 + [63075].name = "relay_alloc_page_array",
84252 + [63075].param1 = 1,
84253 + [63076].file = "fs/cifs/xattr.c",
84254 + [63076].name = "cifs_setxattr",
84255 + [63076].param4 = 1,
84256 + [63091].file = "drivers/net/usb/pegasus.c",
84257 + [63091].name = "get_registers",
84258 + [63091].param3 = 1,
84259 + [6331].file = "drivers/atm/solos-pci.c",
84260 + [6331].name = "solos_param_store",
84261 + [6331].param4 = 1,
84262 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84263 + [63367].name = "ip_set_alloc",
84264 + [63367].param1 = 1,
84265 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84266 + [63489].name = "btmrvl_hscfgcmd_write",
84267 + [63489].param3 = 1,
84268 + [63490].file = "crypto/shash.c",
84269 + [63490].name = "shash_compat_setkey",
84270 + [63490].param3 = 1,
84271 + [63605].file = "mm/mempool.c",
84272 + [63605].name = "mempool_kmalloc",
84273 + [63605].param2 = 1,
84274 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
84275 + [63633].name = "btmrvl_sdio_host_to_card",
84276 + [63633].param3 = 1,
84277 + [63961].file = "fs/xattr.c",
84278 + [63961].name = "sys_flistxattr",
84279 + [63961].param3 = 1,
84280 + [63964].file = "net/sctp/socket.c",
84281 + [63964].name = "sctp_setsockopt_maxseg",
84282 + [63964].param3 = 1,
84283 + [63988].file = "drivers/input/evdev.c",
84284 + [63988].name = "evdev_ioctl_compat",
84285 + [63988].param2 = 1,
84286 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
84287 + [64055].name = "dvb_aplay",
84288 + [64055].param3 = 1,
84289 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84290 + [64156].name = "ath6kl_mgmt_tx",
84291 + [64156].param9 = 1,
84292 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
84293 + [64226].name = "ca_extend",
84294 + [64226].param2 = 1,
84295 + [64227].file = "mm/nobootmem.c",
84296 + [64227].name = "__alloc_bootmem_node_nopanic",
84297 + [64227].param2 = 1,
84298 + [64351].file = "kernel/kfifo.c",
84299 + [64351].name = "kfifo_copy_from_user",
84300 + [64351].param3 = 1,
84301 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84302 + [64392].name = "mmc_send_cxd_data",
84303 + [64392].param5 = 1,
84304 + [64423].file = "kernel/sched/core.c",
84305 + [64423].name = "get_user_cpu_mask",
84306 + [64423].param2 = 1,
84307 + [64432].file = "security/selinux/selinuxfs.c",
84308 + [64432].name = "sel_write_create",
84309 + [64432].param3 = 1,
84310 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84311 + [64471].name = "btmrvl_hscmd_write",
84312 + [64471].param3 = 1,
84313 + [64667].file = "sound/core/oss/pcm_oss.c",
84314 + [64667].name = "snd_pcm_oss_read",
84315 + [64667].param3 = 1,
84316 + [64689].file = "sound/isa/gus/gus_dram.c",
84317 + [64689].name = "snd_gus_dram_read",
84318 + [64689].param4 = 1,
84319 + [64692].file = "fs/binfmt_misc.c",
84320 + [64692].name = "bm_entry_write",
84321 + [64692].param3 = 1,
84322 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84323 + [64705].name = "sca3000_read_first_n_hw_rb",
84324 + [64705].param2 = 1,
84325 + [64713].file = "fs/cifs/connect.c",
84326 + [64713].name = "extract_hostname",
84327 + [64713].param1 = 1,
84328 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84329 + [64743].name = "dlmfs_file_read",
84330 + [64743].param3 = 1,
84331 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
84332 + [64771].name = "datablob_format",
84333 + [64771].param2 = 1,
84334 + [6477].file = "net/bluetooth/mgmt.c",
84335 + [6477].name = "mgmt_pending_add",
84336 + [6477].param5 = 1,
84337 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84338 + [64906].name = "b43legacy_debugfs_write",
84339 + [64906].param3 = 1,
84340 + [64913].file = "sound/core/oss/pcm_oss.c",
84341 + [64913].name = "snd_pcm_oss_write1",
84342 + [64913].param3 = 1,
84343 + [64961].file = "drivers/spi/spidev.c",
84344 + [64961].name = "spidev_ioctl",
84345 + [64961].param2 = 1,
84346 + [65033].file = "crypto/shash.c",
84347 + [65033].name = "shash_async_setkey",
84348 + [65033].param3 = 1,
84349 + [65093].file = "security/integrity/evm/evm_secfs.c",
84350 + [65093].name = "evm_write_key",
84351 + [65093].param3 = 1,
84352 + [6514].file = "mm/nobootmem.c",
84353 + [6514].name = "__alloc_bootmem_low",
84354 + [6514].param1 = 1,
84355 + [65169].file = "net/core/skbuff.c",
84356 + [65169].name = "dev_alloc_skb",
84357 + [65169].param1 = 1,
84358 + [6517].file = "drivers/md/dm-table.c",
84359 + [6517].name = "alloc_targets",
84360 + [6517].param2 = 1,
84361 + [65205].file = "drivers/input/evdev.c",
84362 + [65205].name = "handle_eviocgbit",
84363 + [65205].param3 = 1,
84364 + [65237].file = "kernel/profile.c",
84365 + [65237].name = "read_profile",
84366 + [65237].param3 = 1,
84367 + [65343].file = "kernel/trace/trace.c",
84368 + [65343].name = "tracing_clock_write",
84369 + [65343].param3 = 1,
84370 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84371 + [65345].name = "xz_dec_lzma2_create",
84372 + [65345].param2 = 1,
84373 + [65409].file = "net/802/garp.c",
84374 + [65409].name = "garp_request_join",
84375 + [65409].param4 = 1,
84376 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84377 + [65432].name = "kone_receive",
84378 + [65432].param4 = 1,
84379 + [65514].file = "drivers/media/video/gspca/t613.c",
84380 + [65514].name = "reg_w_ixbuf",
84381 + [65514].param4 = 1,
84382 + [6551].file = "drivers/usb/host/xhci-mem.c",
84383 + [6551].name = "xhci_alloc_stream_info",
84384 + [6551].param3 = 1,
84385 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84386 + [65535].name = "opera1_xilinx_rw",
84387 + [65535].param5 = 1,
84388 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84389 + [6672].name = "b43_debugfs_write",
84390 + [6672].param3 = 1,
84391 + [6691].file = "drivers/acpi/proc.c",
84392 + [6691].name = "acpi_system_write_wakeup_device",
84393 + [6691].param3 = 1,
84394 + [6865].file = "drivers/staging/iio/ring_sw.c",
84395 + [6865].name = "iio_read_first_n_sw_rb",
84396 + [6865].param2 = 1,
84397 + [6867].file = "fs/coda/psdev.c",
84398 + [6867].name = "coda_psdev_read",
84399 + [6867].param3 = 1,
84400 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84401 + [6891].name = "btmrvl_gpiogap_write",
84402 + [6891].param3 = 1,
84403 + [6944].file = "drivers/ide/ide-proc.c",
84404 + [6944].name = "ide_settings_proc_write",
84405 + [6944].param3 = 1,
84406 + [6950].file = "drivers/isdn/capi/capi.c",
84407 + [6950].name = "capi_write",
84408 + [6950].param3 = 1,
84409 + [697].file = "sound/isa/gus/gus_dram.c",
84410 + [697].name = "snd_gus_dram_peek",
84411 + [697].param4 = 1,
84412 + [7066].file = "security/keys/keyctl.c",
84413 + [7066].name = "keyctl_instantiate_key_common",
84414 + [7066].param4 = 1,
84415 + [7125].file = "include/net/nfc/nci_core.h",
84416 + [7125].name = "nci_skb_alloc",
84417 + [7125].param2 = 1,
84418 + [7129].file = "mm/maccess.c",
84419 + [7129].name = "__probe_kernel_read",
84420 + [7129].param3 = 1,
84421 + [7158].file = "kernel/trace/trace.c",
84422 + [7158].name = "tracing_read_pipe",
84423 + [7158].param3 = 1,
84424 + [720].file = "sound/pci/rme9652/hdsp.c",
84425 + [720].name = "snd_hdsp_playback_copy",
84426 + [720].param5 = 1,
84427 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
84428 + [7236].name = "drm_plane_init",
84429 + [7236].param6 = 1,
84430 + [7411].file = "drivers/vhost/vhost.c",
84431 + [7411].name = "__vhost_add_used_n",
84432 + [7411].param3 = 1,
84433 + [7432].file = "net/bluetooth/mgmt.c",
84434 + [7432].name = "mgmt_event",
84435 + [7432].param4 = 1,
84436 + [7488].file = "security/keys/user_defined.c",
84437 + [7488].name = "user_read",
84438 + [7488].param3 = 1,
84439 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84440 + [7551].name = "ad7879_spi_xfer",
84441 + [7551].param3 = 1,
84442 + [7671].file = "mm/nobootmem.c",
84443 + [7671].name = "__alloc_bootmem_node_high",
84444 + [7671].param2 = 1,
84445 + [7676].file = "drivers/acpi/custom_method.c",
84446 + [7676].name = "cm_write",
84447 + [7676].param3 = 1,
84448 + [7693].file = "net/sctp/socket.c",
84449 + [7693].name = "sctp_setsockopt_associnfo",
84450 + [7693].param3 = 1,
84451 + [7697].file = "security/selinux/selinuxfs.c",
84452 + [7697].name = "sel_write_access",
84453 + [7697].param3 = 1,
84454 + [7843].file = "fs/compat.c",
84455 + [7843].name = "compat_sys_readv",
84456 + [7843].param3 = 1,
84457 + [7883].file = "net/sched/sch_sfq.c",
84458 + [7883].name = "sfq_alloc",
84459 + [7883].param1 = 1,
84460 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
84461 + [7924].name = "cx18_read_pos",
84462 + [7924].param3 = 1,
84463 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84464 + [7958].name = "vga_arb_write",
84465 + [7958].param3 = 1,
84466 + [7976].file = "drivers/usb/gadget/rndis.c",
84467 + [7976].name = "rndis_add_response",
84468 + [7976].param2 = 1,
84469 + [7985].file = "net/mac80211/cfg.c",
84470 + [7985].name = "ieee80211_mgmt_tx",
84471 + [7985].param9 = 1,
84472 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84473 + [8014].name = "init_list_set",
84474 + [8014].param2 = 1,
84475 + [8014].param3 = 1,
84476 + [8126].file = "sound/soc/soc-core.c",
84477 + [8126].name = "codec_reg_read_file",
84478 + [8126].param3 = 1,
84479 + [8317].file = "security/smack/smackfs.c",
84480 + [8317].name = "smk_write_ambient",
84481 + [8317].param3 = 1,
84482 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84483 + [8335].name = "dvb_dvr_set_buffer_size",
84484 + [8335].param2 = 1,
84485 + [8383].file = "kernel/module.c",
84486 + [8383].name = "copy_and_check",
84487 + [8383].param3 = 1,
84488 + [8411].file = "net/caif/cfpkt_skbuff.c",
84489 + [8411].name = "cfpkt_append",
84490 + [8411].param3 = 1,
84491 + [8536].file = "fs/cifs/dns_resolve.c",
84492 + [8536].name = "dns_resolve_server_name_to_ip",
84493 + [8536].param1 = 1,
84494 + [857].file = "drivers/virtio/virtio_ring.c",
84495 + [857].name = "virtqueue_add_buf",
84496 + [857].param3 = 1,
84497 + [857].param4 = 1,
84498 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84499 + [8650].name = "vmw_kms_present",
84500 + [8650].param9 = 1,
84501 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
84502 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
84503 + [8654].param2 = 1,
84504 + [8654].param3 = 1,
84505 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84506 + [865].name = "regmap_access_read_file",
84507 + [865].param3 = 1,
84508 + [8663].file = "net/bridge/netfilter/ebtables.c",
84509 + [8663].name = "do_update_counters",
84510 + [8663].param4 = 1,
84511 + [8684].file = "fs/read_write.c",
84512 + [8684].name = "sys_writev",
84513 + [8684].param3 = 1,
84514 + [8699].file = "security/selinux/selinuxfs.c",
84515 + [8699].name = "sel_commit_bools_write",
84516 + [8699].param3 = 1,
84517 + [8764].file = "drivers/usb/core/devio.c",
84518 + [8764].name = "usbdev_read",
84519 + [8764].param3 = 1,
84520 + [8802].file = "fs/dlm/user.c",
84521 + [8802].name = "device_write",
84522 + [8802].param3 = 1,
84523 + [8810].file = "net/mac80211/debugfs_sta.c",
84524 + [8810].name = "sta_agg_status_write",
84525 + [8810].param3 = 1,
84526 + [8815].file = "security/tomoyo/securityfs_if.c",
84527 + [8815].name = "tomoyo_write_self",
84528 + [8815].param3 = 1,
84529 + [8821].file = "net/wireless/sme.c",
84530 + [8821].name = "cfg80211_roamed",
84531 + [8821].param5 = 1,
84532 + [8821].param7 = 1,
84533 + [8833].file = "security/selinux/ss/services.c",
84534 + [8833].name = "security_context_to_sid",
84535 + [8833].param2 = 1,
84536 + [8838].file = "lib/mpi/mpi-bit.c",
84537 + [8838].name = "mpi_lshift_limbs",
84538 + [8838].param2 = 1,
84539 + [8851].file = "net/key/af_key.c",
84540 + [8851].name = "pfkey_sendmsg",
84541 + [8851].param4 = 1,
84542 + [8917].file = "net/can/raw.c",
84543 + [8917].name = "raw_setsockopt",
84544 + [8917].param5 = 1,
84545 + [8983].file = "include/linux/skbuff.h",
84546 + [8983].name = "alloc_skb",
84547 + [8983].param1 = 1,
84548 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
84549 + [9117].name = "regcache_rbtree_insert_to_block",
84550 + [9117].param5 = 1,
84551 + [9226].file = "mm/migrate.c",
84552 + [9226].name = "sys_move_pages",
84553 + [9226].param2 = 1,
84554 + [9304].file = "kernel/auditfilter.c",
84555 + [9304].name = "audit_init_entry",
84556 + [9304].param1 = 1,
84557 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
84558 + [9317].name = "wa_nep_queue",
84559 + [9317].param2 = 1,
84560 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84561 + [9341].name = "erst_dbg_write",
84562 + [9341].param3 = 1,
84563 + [9386].file = "fs/exofs/ore.c",
84564 + [9386].name = "_ore_get_io_state",
84565 + [9386].param3 = 1,
84566 + [9386].param4 = 1,
84567 + [9386].param5 = 1,
84568 + [9538].file = "crypto/blkcipher.c",
84569 + [9538].name = "blkcipher_copy_iv",
84570 + [9538].param3 = 1,
84571 + [9546].file = "drivers/video/fbmem.c",
84572 + [9546].name = "fb_write",
84573 + [9546].param3 = 1,
84574 + [9601].file = "kernel/kfifo.c",
84575 + [9601].name = "__kfifo_from_user",
84576 + [9601].param3 = 1,
84577 + [9618].file = "security/selinux/selinuxfs.c",
84578 + [9618].name = "sel_write_bool",
84579 + [9618].param3 = 1,
84580 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84581 + [9768].name = "vmw_execbuf_process",
84582 + [9768].param5 = 1,
84583 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84584 + [9828].name = "dvb_demux_do_ioctl",
84585 + [9828].param3 = 1,
84586 + [9870].file = "net/atm/addr.c",
84587 + [9870].name = "atm_get_addr",
84588 + [9870].param3 = 1,
84589 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84590 + [9977].name = "zd_usb_iowrite16v_async",
84591 + [9977].param3 = 1,
84592 + [16344].collision = 1,
84593 + [307].collision = 1,
84594 + [31649].collision = 1,
84595 + [33040].collision = 1,
84596 + [45231].collision = 1,
84597 + [60651].collision = 1,
84598 +};
84599 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84600 new file mode 100644
84601 index 0000000..9ec45ae
84602 --- /dev/null
84603 +++ b/tools/gcc/size_overflow_hash2.h
84604 @@ -0,0 +1,35 @@
84605 +struct size_overflow_hash size_overflow_hash2[65536] = {
84606 + [22224].file = "fs/proc/vmcore.c",
84607 + [22224].name = "read_from_oldmem",
84608 + [22224].param2 = 1,
84609 + [2344].file = "fs/ecryptfs/crypto.c",
84610 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
84611 + [2344].param5 = 1,
84612 + [2515].file = "fs/ecryptfs/crypto.c",
84613 + [2515].name = "ecryptfs_copy_filename",
84614 + [2515].param4 = 1,
84615 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84616 + [26518].name = "vga_arb_read",
84617 + [26518].param3 = 1,
84618 + [30632].file = "drivers/ide/ide-proc.c",
84619 + [30632].name = "ide_driver_proc_write",
84620 + [30632].param3 = 1,
84621 + [39024].file = "lib/scatterlist.c",
84622 + [39024].name = "sg_kmalloc",
84623 + [39024].param1 = 1,
84624 + [50359].file = "kernel/sched/core.c",
84625 + [50359].name = "alloc_sched_domains",
84626 + [50359].param1 = 1,
84627 + [53262].file = "drivers/block/aoe/aoechr.c",
84628 + [53262].name = "revalidate",
84629 + [53262].param2 = 1,
84630 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
84631 + [56432].name = "regmap_map_read_file",
84632 + [56432].param3 = 1,
84633 + [57500].file = "drivers/spi/spidev.c",
84634 + [57500].name = "spidev_write",
84635 + [57500].param3 = 1,
84636 + [8155].file = "drivers/hv/channel.c",
84637 + [8155].name = "vmbus_establish_gpadl",
84638 + [8155].param3 = 1,
84639 +};
84640 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84641 new file mode 100644
84642 index 0000000..255439f
84643 --- /dev/null
84644 +++ b/tools/gcc/size_overflow_plugin.c
84645 @@ -0,0 +1,1110 @@
84646 +/*
84647 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84648 + * Licensed under the GPL v2, or (at your option) v3
84649 + *
84650 + * Homepage:
84651 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84652 + *
84653 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84654 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84655 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
84656 + *
84657 + * Usage:
84658 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
84659 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84660 + */
84661 +
84662 +#include "gcc-plugin.h"
84663 +#include "config.h"
84664 +#include "system.h"
84665 +#include "coretypes.h"
84666 +#include "tree.h"
84667 +#include "tree-pass.h"
84668 +#include "intl.h"
84669 +#include "plugin-version.h"
84670 +#include "tm.h"
84671 +#include "toplev.h"
84672 +#include "function.h"
84673 +#include "tree-flow.h"
84674 +#include "plugin.h"
84675 +#include "gimple.h"
84676 +#include "c-common.h"
84677 +#include "diagnostic.h"
84678 +#include "cfgloop.h"
84679 +
84680 +struct size_overflow_hash {
84681 + const char *name;
84682 + const char *file;
84683 + unsigned short collision:1;
84684 + unsigned short param1:1;
84685 + unsigned short param2:1;
84686 + unsigned short param3:1;
84687 + unsigned short param4:1;
84688 + unsigned short param5:1;
84689 + unsigned short param6:1;
84690 + unsigned short param7:1;
84691 + unsigned short param8:1;
84692 + unsigned short param9:1;
84693 +};
84694 +
84695 +#include "size_overflow_hash1.h"
84696 +#include "size_overflow_hash2.h"
84697 +
84698 +#define __unused __attribute__((__unused__))
84699 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
84700 +#define BEFORE_STMT true
84701 +#define AFTER_STMT false
84702 +#define CREATE_NEW_VAR NULL_TREE
84703 +
84704 +int plugin_is_GPL_compatible;
84705 +void debug_gimple_stmt (gimple gs);
84706 +
84707 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
84708 +static tree signed_size_overflow_type;
84709 +static tree unsigned_size_overflow_type;
84710 +static tree report_size_overflow_decl;
84711 +static tree const_char_ptr_type_node;
84712 +static unsigned int handle_function(void);
84713 +
84714 +static struct plugin_info size_overflow_plugin_info = {
84715 + .version = "20120409beta",
84716 + .help = "no-size_overflow\tturn off size overflow checking\n",
84717 +};
84718 +
84719 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
84720 +{
84721 + unsigned int arg_count = type_num_arguments(*node);
84722 +
84723 + for (; args; args = TREE_CHAIN(args)) {
84724 + tree position = TREE_VALUE(args);
84725 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
84726 + error("handle_size_overflow_attribute: overflow parameter outside range.");
84727 + *no_add_attrs = true;
84728 + }
84729 + }
84730 + return NULL_TREE;
84731 +}
84732 +
84733 +static struct attribute_spec no_size_overflow_attr = {
84734 + .name = "size_overflow",
84735 + .min_length = 1,
84736 + .max_length = -1,
84737 + .decl_required = false,
84738 + .type_required = true,
84739 + .function_type_required = true,
84740 + .handler = handle_size_overflow_attribute
84741 +};
84742 +
84743 +static void register_attributes(void __unused *event_data, void __unused *data)
84744 +{
84745 + register_attribute(&no_size_overflow_attr);
84746 +}
84747 +
84748 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
84749 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
84750 +{
84751 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
84752 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
84753 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
84754 +
84755 + const unsigned int m = 0x57559429;
84756 + const unsigned int n = 0x5052acdb;
84757 + const unsigned int *key4 = (const unsigned int *)key;
84758 + unsigned int h = len;
84759 + unsigned int k = len + seed + n;
84760 + unsigned long long p;
84761 +
84762 + while (len >= 8) {
84763 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
84764 + len -= 8;
84765 + }
84766 + if (len >= 4) {
84767 + cwmixb(key4[0]) key4 += 1;
84768 + len -= 4;
84769 + }
84770 + if (len)
84771 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
84772 + cwmixb(h ^ (k + n));
84773 + return k ^ h;
84774 +
84775 +#undef cwfold
84776 +#undef cwmixa
84777 +#undef cwmixb
84778 +}
84779 +
84780 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
84781 +{
84782 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
84783 +}
84784 +
84785 +static inline tree get_original_function_decl(tree fndecl)
84786 +{
84787 + if (DECL_ABSTRACT_ORIGIN(fndecl))
84788 + return DECL_ABSTRACT_ORIGIN(fndecl);
84789 + return fndecl;
84790 +}
84791 +
84792 +static inline gimple get_def_stmt(tree node)
84793 +{
84794 + gcc_assert(TREE_CODE(node) == SSA_NAME);
84795 + return SSA_NAME_DEF_STMT(node);
84796 +}
84797 +
84798 +static struct size_overflow_hash *get_function_hash(tree fndecl)
84799 +{
84800 + unsigned int hash;
84801 + const char *func = NAME(fndecl);
84802 +
84803 + hash = size_overflow_hash(func, 0);
84804 +
84805 + if (size_overflow_hash1[hash].collision) {
84806 + hash = size_overflow_hash(func, 23432);
84807 + return &size_overflow_hash2[hash];
84808 + }
84809 + return &size_overflow_hash1[hash];
84810 +}
84811 +
84812 +static void check_arg_type(tree var)
84813 +{
84814 + tree type = TREE_TYPE(var);
84815 + enum tree_code code = TREE_CODE(type);
84816 +
84817 + gcc_assert(code == INTEGER_TYPE ||
84818 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
84819 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
84820 +}
84821 +
84822 +static void check_missing_attribute(tree arg)
84823 +{
84824 + tree var, type, func = get_original_function_decl(current_function_decl);
84825 + const char *curfunc = NAME(func);
84826 + unsigned int new_hash, argnum = 1;
84827 + struct size_overflow_hash *hash;
84828 + location_t loc;
84829 + expanded_location xloc;
84830 + bool match = false;
84831 +
84832 + type = TREE_TYPE(arg);
84833 + // skip function pointers
84834 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
84835 + return;
84836 +
84837 + loc = DECL_SOURCE_LOCATION(func);
84838 + xloc = expand_location(loc);
84839 +
84840 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
84841 + return;
84842 +
84843 + hash = get_function_hash(func);
84844 + if (hash->name && !strcmp(hash->name, NAME(func)) && !strcmp(hash->file, xloc.file))
84845 + return;
84846 +
84847 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
84848 +
84849 + if (TREE_CODE(arg) == SSA_NAME)
84850 + arg = SSA_NAME_VAR(arg);
84851 +
84852 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
84853 + if (strcmp(NAME(arg), NAME(var))) {
84854 + argnum++;
84855 + continue;
84856 + }
84857 + check_arg_type(var);
84858 +
84859 + match = true;
84860 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
84861 + return;
84862 + break;
84863 + }
84864 + if (!match) {
84865 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
84866 + return;
84867 + }
84868 +
84869 +#define check_param(num) \
84870 + if (num == argnum && hash->param##num) \
84871 + return;
84872 + check_param(1);
84873 + check_param(2);
84874 + check_param(3);
84875 + check_param(4);
84876 + check_param(5);
84877 + check_param(6);
84878 + check_param(7);
84879 + check_param(8);
84880 + check_param(9);
84881 +#undef check_param
84882 +
84883 + new_hash = size_overflow_hash(curfunc, 0);
84884 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
84885 +}
84886 +
84887 +static tree create_new_var(tree type)
84888 +{
84889 + tree new_var = create_tmp_var(type, "cicus");
84890 +
84891 + add_referenced_var(new_var);
84892 + mark_sym_for_renaming(new_var);
84893 + return new_var;
84894 +}
84895 +
84896 +static bool is_bool(tree node)
84897 +{
84898 + tree type;
84899 +
84900 + if (node == NULL_TREE)
84901 + return false;
84902 +
84903 + type = TREE_TYPE(node);
84904 + if (!INTEGRAL_TYPE_P(type))
84905 + return false;
84906 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84907 + return true;
84908 + if (TYPE_PRECISION(type) == 1)
84909 + return true;
84910 + return false;
84911 +}
84912 +
84913 +static tree cast_a_tree(tree type, tree var)
84914 +{
84915 + gcc_assert(fold_convertible_p(type, var));
84916 +
84917 + return fold_convert(type, var);
84918 +}
84919 +
84920 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84921 +{
84922 + gimple assign;
84923 +
84924 + if (new_var == CREATE_NEW_VAR)
84925 + new_var = create_new_var(type);
84926 +
84927 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
84928 + gimple_set_location(assign, loc);
84929 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84930 +
84931 + return assign;
84932 +}
84933 +
84934 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
84935 +{
84936 + tree oldstmt_rhs1;
84937 + enum tree_code code;
84938 + gimple stmt;
84939 + gimple_stmt_iterator gsi;
84940 +
84941 + if (!*potentionally_overflowed)
84942 + return NULL_TREE;
84943 +
84944 + if (rhs1 == NULL_TREE) {
84945 + debug_gimple_stmt(oldstmt);
84946 + error("create_assign: rhs1 is NULL_TREE");
84947 + gcc_unreachable();
84948 + }
84949 +
84950 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
84951 + code = TREE_CODE(oldstmt_rhs1);
84952 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
84953 + check_missing_attribute(oldstmt_rhs1);
84954 +
84955 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
84956 + gsi = gsi_for_stmt(oldstmt);
84957 + if (before)
84958 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
84959 + else
84960 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
84961 + update_stmt(stmt);
84962 + pointer_set_insert(visited, oldstmt);
84963 + return gimple_get_lhs(stmt);
84964 +}
84965 +
84966 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
84967 +{
84968 + tree new_var, lhs = gimple_get_lhs(oldstmt);
84969 + gimple stmt;
84970 + gimple_stmt_iterator gsi;
84971 +
84972 + if (!*potentionally_overflowed)
84973 + return NULL_TREE;
84974 +
84975 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
84976 + rhs1 = gimple_assign_rhs1(oldstmt);
84977 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
84978 + }
84979 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
84980 + rhs2 = gimple_assign_rhs2(oldstmt);
84981 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
84982 + }
84983 +
84984 + stmt = gimple_copy(oldstmt);
84985 + gimple_set_location(stmt, gimple_location(oldstmt));
84986 +
84987 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
84988 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
84989 +
84990 + if (is_bool(lhs))
84991 + new_var = SSA_NAME_VAR(lhs);
84992 + else
84993 + new_var = create_new_var(signed_size_overflow_type);
84994 + new_var = make_ssa_name(new_var, stmt);
84995 + gimple_set_lhs(stmt, new_var);
84996 +
84997 + if (rhs1 != NULL_TREE) {
84998 + if (!gimple_assign_cast_p(oldstmt))
84999 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
85000 + gimple_assign_set_rhs1(stmt, rhs1);
85001 + }
85002 +
85003 + if (rhs2 != NULL_TREE)
85004 + gimple_assign_set_rhs2(stmt, rhs2);
85005 +#if BUILDING_GCC_VERSION >= 4007
85006 + if (rhs3 != NULL_TREE)
85007 + gimple_assign_set_rhs3(stmt, rhs3);
85008 +#endif
85009 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
85010 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
85011 +
85012 + gsi = gsi_for_stmt(oldstmt);
85013 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
85014 + update_stmt(stmt);
85015 + pointer_set_insert(visited, oldstmt);
85016 + return gimple_get_lhs(stmt);
85017 +}
85018 +
85019 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
85020 +{
85021 + basic_block bb;
85022 + gimple phi;
85023 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
85024 +
85025 + bb = gsi_bb(gsi);
85026 +
85027 + phi = create_phi_node(var, bb);
85028 + gsi = gsi_last(phi_nodes(bb));
85029 + gsi_remove(&gsi, false);
85030 +
85031 + gsi = gsi_for_stmt(oldstmt);
85032 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
85033 + gimple_set_bb(phi, bb);
85034 + return phi;
85035 +}
85036 +
85037 +static tree signed_cast_constant(tree node)
85038 +{
85039 + gcc_assert(is_gimple_constant(node));
85040 +
85041 + return cast_a_tree(signed_size_overflow_type, node);
85042 +}
85043 +
85044 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
85045 +{
85046 + basic_block bb;
85047 + gimple newstmt, def_stmt;
85048 + gimple_stmt_iterator gsi;
85049 +
85050 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
85051 + if (TREE_CODE(arg) == SSA_NAME) {
85052 + def_stmt = get_def_stmt(arg);
85053 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
85054 + gsi = gsi_for_stmt(def_stmt);
85055 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
85056 + return newstmt;
85057 + }
85058 + }
85059 +
85060 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
85061 + gsi = gsi_after_labels(bb);
85062 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
85063 + return newstmt;
85064 +}
85065 +
85066 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
85067 +{
85068 + gimple newstmt;
85069 + gimple_stmt_iterator gsi;
85070 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
85071 + gimple def_newstmt = get_def_stmt(new_rhs);
85072 +
85073 + gsi_insert = gsi_insert_after;
85074 + gsi = gsi_for_stmt(def_newstmt);
85075 +
85076 + switch (gimple_code(get_def_stmt(arg))) {
85077 + case GIMPLE_PHI:
85078 + newstmt = gimple_build_assign(new_var, new_rhs);
85079 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
85080 + gsi_insert = gsi_insert_before;
85081 + break;
85082 + case GIMPLE_ASM:
85083 + case GIMPLE_CALL:
85084 + newstmt = gimple_build_assign(new_var, new_rhs);
85085 + break;
85086 + case GIMPLE_ASSIGN:
85087 + newstmt = gimple_copy(def_newstmt);
85088 + break;
85089 + default:
85090 + /* unknown gimple_code (handle_build_new_phi_arg) */
85091 + gcc_unreachable();
85092 + }
85093 +
85094 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
85095 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
85096 + return newstmt;
85097 +}
85098 +
85099 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
85100 +{
85101 + gimple newstmt;
85102 + tree new_rhs;
85103 +
85104 + new_rhs = expand(visited, potentionally_overflowed, arg);
85105 +
85106 + if (new_rhs == NULL_TREE)
85107 + return NULL_TREE;
85108 +
85109 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85110 + update_stmt(newstmt);
85111 + return gimple_get_lhs(newstmt);
85112 +}
85113 +
85114 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
85115 +{
85116 + gimple phi;
85117 + tree new_var = create_new_var(signed_size_overflow_type);
85118 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85119 +
85120 + pointer_set_insert(visited, oldstmt);
85121 + phi = overflow_create_phi_node(oldstmt, new_var);
85122 + for (i = 0; i < n; i++) {
85123 + tree arg, lhs;
85124 +
85125 + arg = gimple_phi_arg_def(oldstmt, i);
85126 + if (is_gimple_constant(arg))
85127 + arg = signed_cast_constant(arg);
85128 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85129 + if (lhs == NULL_TREE)
85130 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85131 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85132 + }
85133 +
85134 + update_stmt(phi);
85135 + return gimple_phi_result(phi);
85136 +}
85137 +
85138 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85139 +{
85140 + gimple def_stmt = get_def_stmt(var);
85141 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85142 +
85143 + *potentionally_overflowed = true;
85144 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85145 + if (new_rhs1 == NULL_TREE) {
85146 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85147 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85148 + else
85149 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85150 + }
85151 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85152 +}
85153 +
85154 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85155 +{
85156 + gimple def_stmt = get_def_stmt(var);
85157 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85158 +
85159 + if (is_gimple_constant(rhs1))
85160 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85161 +
85162 + switch (TREE_CODE(rhs1)) {
85163 + case SSA_NAME:
85164 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85165 +
85166 + case ARRAY_REF:
85167 + case ADDR_EXPR:
85168 + case COMPONENT_REF:
85169 + case COND_EXPR:
85170 + case INDIRECT_REF:
85171 +#if BUILDING_GCC_VERSION >= 4006
85172 + case MEM_REF:
85173 +#endif
85174 + case PARM_DECL:
85175 + case TARGET_MEM_REF:
85176 + case VAR_DECL:
85177 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85178 +
85179 + default:
85180 + debug_gimple_stmt(def_stmt);
85181 + debug_tree(rhs1);
85182 + gcc_unreachable();
85183 + }
85184 +}
85185 +
85186 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85187 +{
85188 + gimple cond_stmt;
85189 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85190 +
85191 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85192 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85193 + update_stmt(cond_stmt);
85194 +}
85195 +
85196 +static tree create_string_param(tree string)
85197 +{
85198 + tree array_ref = build4(ARRAY_REF, TREE_TYPE(string), string, integer_zero_node, NULL, NULL);
85199 +
85200 + return build1(ADDR_EXPR, ptr_type_node, array_ref);
85201 +}
85202 +
85203 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85204 +{
85205 + gimple func_stmt, def_stmt;
85206 + tree current_func, loc_file, loc_line;
85207 + expanded_location xloc;
85208 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85209 +
85210 + def_stmt = get_def_stmt(arg);
85211 + xloc = expand_location(gimple_location(def_stmt));
85212 +
85213 + if (!gimple_has_location(def_stmt)) {
85214 + xloc = expand_location(gimple_location(stmt));
85215 + if (!gimple_has_location(stmt))
85216 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85217 + }
85218 +
85219 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85220 +
85221 + loc_file = build_string(strlen(xloc.file), xloc.file);
85222 + TREE_TYPE(loc_file) = char_array_type_node;
85223 + loc_file = create_string_param(loc_file);
85224 +
85225 + current_func = build_string(IDENTIFIER_LENGTH(DECL_NAME(current_function_decl)), NAME(current_function_decl));
85226 + TREE_TYPE(current_func) = char_array_type_node;
85227 + current_func = create_string_param(current_func);
85228 +
85229 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85230 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85231 +
85232 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85233 +}
85234 +
85235 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85236 +{
85237 + basic_block cond_bb, join_bb, bb_true;
85238 + edge e;
85239 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85240 +// location_t loc = gimple_location(stmt);
85241 +
85242 + cond_bb = gimple_bb(stmt);
85243 + gsi_prev(&gsi);
85244 + if (gsi_end_p(gsi))
85245 + e = split_block_after_labels(cond_bb);
85246 + else
85247 + e = split_block(cond_bb, gsi_stmt(gsi));
85248 + cond_bb = e->src;
85249 + join_bb = e->dest;
85250 + e->flags = EDGE_FALSE_VALUE;
85251 + e->probability = REG_BR_PROB_BASE;
85252 +
85253 + bb_true = create_empty_bb(cond_bb);
85254 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85255 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85256 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85257 +
85258 + if (dom_info_available_p(CDI_DOMINATORS)) {
85259 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85260 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85261 + }
85262 +
85263 + if (current_loops != NULL) {
85264 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85265 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85266 + }
85267 +
85268 + insert_cond(cond_bb, arg, cond_code, type_value);
85269 + insert_cond_result(bb_true, stmt, arg);
85270 +
85271 +// inform(loc, "Integer size_overflow check applied here.");
85272 +}
85273 +
85274 +static tree get_type_for_check(tree rhs)
85275 +{
85276 + tree def_rhs;
85277 + gimple def_stmt = get_def_stmt(rhs);
85278 +
85279 + if (!gimple_assign_cast_p(def_stmt))
85280 + return TREE_TYPE(rhs);
85281 + def_rhs = gimple_assign_rhs1(def_stmt);
85282 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
85283 + return TREE_TYPE(def_rhs);
85284 + return TREE_TYPE(rhs);
85285 +}
85286 +
85287 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85288 +{
85289 + gimple ucast_stmt;
85290 + gimple_stmt_iterator gsi;
85291 + location_t loc = gimple_location(stmt);
85292 +
85293 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85294 + gsi = gsi_for_stmt(stmt);
85295 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85296 + return ucast_stmt;
85297 +}
85298 +
85299 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85300 +{
85301 + tree type_max, type_min, rhs_type;
85302 + gimple ucast_stmt;
85303 +
85304 + if (!*potentionally_overflowed)
85305 + return;
85306 +
85307 + rhs_type = get_type_for_check(rhs);
85308 +
85309 + if (TYPE_UNSIGNED(rhs_type)) {
85310 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85311 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85312 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85313 + } else {
85314 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85315 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85316 +
85317 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
85318 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85319 + }
85320 +}
85321 +
85322 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
85323 +{
85324 + gimple assign;
85325 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85326 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
85327 +
85328 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85329 +
85330 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
85331 + if (new_rhs == NULL_TREE)
85332 + return NULL_TREE;
85333 +
85334 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85335 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85336 + update_stmt(assign);
85337 + return gimple_get_lhs(assign);
85338 +}
85339 +
85340 +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))
85341 +{
85342 + tree new_rhs, cast_rhs;
85343 +
85344 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85345 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85346 +
85347 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
85348 + if (new_rhs != NULL_TREE) {
85349 + gimple_assign_set_rhs(def_stmt, new_rhs);
85350 + update_stmt(def_stmt);
85351 +
85352 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
85353 +
85354 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
85355 + }
85356 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85357 +}
85358 +
85359 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85360 +{
85361 + tree rhs1, rhs2;
85362 + gimple def_stmt = get_def_stmt(var);
85363 + tree new_rhs1 = NULL_TREE;
85364 + tree new_rhs2 = NULL_TREE;
85365 +
85366 + rhs1 = gimple_assign_rhs1(def_stmt);
85367 + rhs2 = gimple_assign_rhs2(def_stmt);
85368 +
85369 + /* no DImode/TImode division in the 32/64 bit kernel */
85370 + switch (gimple_assign_rhs_code(def_stmt)) {
85371 + case RDIV_EXPR:
85372 + case TRUNC_DIV_EXPR:
85373 + case CEIL_DIV_EXPR:
85374 + case FLOOR_DIV_EXPR:
85375 + case ROUND_DIV_EXPR:
85376 + case TRUNC_MOD_EXPR:
85377 + case CEIL_MOD_EXPR:
85378 + case FLOOR_MOD_EXPR:
85379 + case ROUND_MOD_EXPR:
85380 + case EXACT_DIV_EXPR:
85381 + case POINTER_PLUS_EXPR:
85382 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85383 + default:
85384 + break;
85385 + }
85386 +
85387 + *potentionally_overflowed = true;
85388 +
85389 + if (TREE_CODE(rhs1) == SSA_NAME)
85390 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85391 + if (TREE_CODE(rhs2) == SSA_NAME)
85392 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85393 +
85394 + if (is_gimple_constant(rhs2))
85395 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
85396 +
85397 + if (is_gimple_constant(rhs1))
85398 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85399 +
85400 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85401 +}
85402 +
85403 +#if BUILDING_GCC_VERSION >= 4007
85404 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85405 +{
85406 + if (is_gimple_constant(rhs))
85407 + return signed_cast_constant(rhs);
85408 + if (TREE_CODE(rhs) != SSA_NAME)
85409 + return NULL_TREE;
85410 + return expand(visited, potentionally_overflowed, rhs);
85411 +}
85412 +
85413 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85414 +{
85415 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85416 + gimple def_stmt = get_def_stmt(var);
85417 +
85418 + *potentionally_overflowed = true;
85419 +
85420 + rhs1 = gimple_assign_rhs1(def_stmt);
85421 + rhs2 = gimple_assign_rhs2(def_stmt);
85422 + rhs3 = gimple_assign_rhs3(def_stmt);
85423 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85424 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85425 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85426 +
85427 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85428 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85429 + error("handle_ternary_ops: unknown rhs");
85430 + gcc_unreachable();
85431 +}
85432 +#endif
85433 +
85434 +static void set_size_overflow_type(tree node)
85435 +{
85436 + switch (TYPE_MODE(TREE_TYPE(node))) {
85437 + case SImode:
85438 + signed_size_overflow_type = intDI_type_node;
85439 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85440 + break;
85441 + case DImode:
85442 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85443 + signed_size_overflow_type = intDI_type_node;
85444 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85445 + } else {
85446 + signed_size_overflow_type = intTI_type_node;
85447 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85448 + }
85449 + break;
85450 + default:
85451 + error("set_size_overflow_type: unsupported gcc configuration.");
85452 + gcc_unreachable();
85453 + }
85454 +}
85455 +
85456 +static tree expand_visited(gimple def_stmt)
85457 +{
85458 + gimple tmp;
85459 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85460 +
85461 + gsi_next(&gsi);
85462 + tmp = gsi_stmt(gsi);
85463 + switch (gimple_code(tmp)) {
85464 + case GIMPLE_ASSIGN:
85465 + return gimple_get_lhs(tmp);
85466 + case GIMPLE_PHI:
85467 + return gimple_phi_result(tmp);
85468 + case GIMPLE_CALL:
85469 + return gimple_call_lhs(tmp);
85470 + default:
85471 + return NULL_TREE;
85472 + }
85473 +}
85474 +
85475 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85476 +{
85477 + gimple def_stmt;
85478 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85479 +
85480 + if (is_gimple_constant(var))
85481 + return NULL_TREE;
85482 +
85483 + if (TREE_CODE(var) == ADDR_EXPR)
85484 + return NULL_TREE;
85485 +
85486 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
85487 + if (code != INTEGER_TYPE)
85488 + return NULL_TREE;
85489 +
85490 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85491 + check_missing_attribute(var);
85492 + return NULL_TREE;
85493 + }
85494 +
85495 + def_stmt = get_def_stmt(var);
85496 +
85497 + if (!def_stmt)
85498 + return NULL_TREE;
85499 +
85500 + if (pointer_set_contains(visited, def_stmt))
85501 + return expand_visited(def_stmt);
85502 +
85503 + switch (gimple_code(def_stmt)) {
85504 + case GIMPLE_NOP:
85505 + check_missing_attribute(var);
85506 + return NULL_TREE;
85507 + case GIMPLE_PHI:
85508 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85509 + case GIMPLE_CALL:
85510 + case GIMPLE_ASM:
85511 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85512 + case GIMPLE_ASSIGN:
85513 + switch (gimple_num_ops(def_stmt)) {
85514 + case 2:
85515 + return handle_unary_ops(visited, potentionally_overflowed, var);
85516 + case 3:
85517 + return handle_binary_ops(visited, potentionally_overflowed, var);
85518 +#if BUILDING_GCC_VERSION >= 4007
85519 + case 4:
85520 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85521 +#endif
85522 + }
85523 + default:
85524 + debug_gimple_stmt(def_stmt);
85525 + error("expand: unknown gimple code");
85526 + gcc_unreachable();
85527 + }
85528 +}
85529 +
85530 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85531 +{
85532 + gimple assign;
85533 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85534 + tree origtype = TREE_TYPE(origarg);
85535 +
85536 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85537 +
85538 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85539 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85540 + update_stmt(assign);
85541 +
85542 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85543 + update_stmt(stmt);
85544 +}
85545 +
85546 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85547 +{
85548 + const char *origid;
85549 + tree arg, origarg;
85550 +
85551 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85552 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85553 + return gimple_call_arg(stmt, argnum);
85554 + }
85555 +
85556 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85557 + while (origarg && argnum) {
85558 + argnum--;
85559 + origarg = TREE_CHAIN(origarg);
85560 + }
85561 +
85562 + gcc_assert(argnum == 0);
85563 +
85564 + gcc_assert(origarg != NULL_TREE);
85565 + origid = NAME(origarg);
85566 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85567 + if (!strcmp(origid, NAME(arg)))
85568 + return arg;
85569 + }
85570 + return NULL_TREE;
85571 +}
85572 +
85573 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85574 +{
85575 + struct pointer_set_t *visited;
85576 + tree arg, newarg, type_max;
85577 + gimple ucast_stmt;
85578 + bool potentionally_overflowed;
85579 +
85580 + arg = get_function_arg(argnum, stmt, fndecl);
85581 + if (arg == NULL_TREE)
85582 + return;
85583 +
85584 + if (is_gimple_constant(arg))
85585 + return;
85586 + if (TREE_CODE(arg) != SSA_NAME)
85587 + return;
85588 +
85589 + check_arg_type(arg);
85590 +
85591 + set_size_overflow_type(arg);
85592 +
85593 + visited = pointer_set_create();
85594 + potentionally_overflowed = false;
85595 + newarg = expand(visited, &potentionally_overflowed, arg);
85596 + pointer_set_destroy(visited);
85597 +
85598 + if (newarg == NULL_TREE || !potentionally_overflowed)
85599 + return;
85600 +
85601 + change_function_arg(stmt, arg, argnum, newarg);
85602 +
85603 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
85604 +
85605 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
85606 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85607 +}
85608 +
85609 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85610 +{
85611 + tree p = TREE_VALUE(attr);
85612 + do {
85613 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85614 + p = TREE_CHAIN(p);
85615 + } while (p);
85616 +}
85617 +
85618 +static void handle_function_by_hash(gimple stmt, tree fndecl)
85619 +{
85620 + struct size_overflow_hash *hash;
85621 + expanded_location xloc;
85622 +
85623 + hash = get_function_hash(fndecl);
85624 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
85625 +
85626 + fndecl = get_original_function_decl(fndecl);
85627 + if (!hash->name || !hash->file)
85628 + return;
85629 + if (strcmp(hash->name, NAME(fndecl)) || strcmp(hash->file, xloc.file))
85630 + return;
85631 +
85632 +#define search_param(argnum) \
85633 + if (hash->param##argnum) \
85634 + handle_function_arg(stmt, fndecl, argnum - 1);
85635 +
85636 + search_param(1);
85637 + search_param(2);
85638 + search_param(3);
85639 + search_param(4);
85640 + search_param(5);
85641 + search_param(6);
85642 + search_param(7);
85643 + search_param(8);
85644 + search_param(9);
85645 +#undef search_param
85646 +}
85647 +
85648 +static unsigned int handle_function(void)
85649 +{
85650 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
85651 + int saved_last_basic_block = last_basic_block;
85652 +
85653 + do {
85654 + gimple_stmt_iterator gsi;
85655 + basic_block next = bb->next_bb;
85656 +
85657 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85658 + tree fndecl, attr;
85659 + gimple stmt = gsi_stmt(gsi);
85660 +
85661 + if (!(is_gimple_call(stmt)))
85662 + continue;
85663 + fndecl = gimple_call_fndecl(stmt);
85664 + if (fndecl == NULL_TREE)
85665 + continue;
85666 + if (gimple_call_num_args(stmt) == 0)
85667 + continue;
85668 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
85669 + if (!attr || !TREE_VALUE(attr))
85670 + handle_function_by_hash(stmt, fndecl);
85671 + else
85672 + handle_function_by_attribute(stmt, attr, fndecl);
85673 + gsi = gsi_for_stmt(stmt);
85674 + }
85675 + bb = next;
85676 + } while (bb && bb->index <= saved_last_basic_block);
85677 + return 0;
85678 +}
85679 +
85680 +static struct gimple_opt_pass size_overflow_pass = {
85681 + .pass = {
85682 + .type = GIMPLE_PASS,
85683 + .name = "size_overflow",
85684 + .gate = NULL,
85685 + .execute = handle_function,
85686 + .sub = NULL,
85687 + .next = NULL,
85688 + .static_pass_number = 0,
85689 + .tv_id = TV_NONE,
85690 + .properties_required = PROP_cfg | PROP_referenced_vars,
85691 + .properties_provided = 0,
85692 + .properties_destroyed = 0,
85693 + .todo_flags_start = 0,
85694 + .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
85695 + }
85696 +};
85697 +
85698 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
85699 +{
85700 + tree fntype;
85701 +
85702 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
85703 +
85704 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
85705 + fntype = build_function_type_list(void_type_node,
85706 + const_char_ptr_type_node,
85707 + unsigned_type_node,
85708 + const_char_ptr_type_node,
85709 + NULL_TREE);
85710 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
85711 +
85712 + TREE_PUBLIC(report_size_overflow_decl) = 1;
85713 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
85714 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
85715 +}
85716 +
85717 +extern struct gimple_opt_pass pass_dce;
85718 +
85719 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85720 +{
85721 + int i;
85722 + const char * const plugin_name = plugin_info->base_name;
85723 + const int argc = plugin_info->argc;
85724 + const struct plugin_argument * const argv = plugin_info->argv;
85725 + bool enable = true;
85726 +
85727 + struct register_pass_info size_overflow_pass_info = {
85728 + .pass = &size_overflow_pass.pass,
85729 + .reference_pass_name = "ssa",
85730 + .ref_pass_instance_number = 1,
85731 + .pos_op = PASS_POS_INSERT_AFTER
85732 + };
85733 +
85734 + if (!plugin_default_version_check(version, &gcc_version)) {
85735 + error(G_("incompatible gcc/plugin versions"));
85736 + return 1;
85737 + }
85738 +
85739 + for (i = 0; i < argc; ++i) {
85740 + if (!(strcmp(argv[i].key, "no-size_overflow"))) {
85741 + enable = false;
85742 + continue;
85743 + }
85744 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85745 + }
85746 +
85747 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
85748 + if (enable) {
85749 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85750 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
85751 + }
85752 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85753 +
85754 + return 0;
85755 +}
85756 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
85757 new file mode 100644
85758 index 0000000..b87ec9d
85759 --- /dev/null
85760 +++ b/tools/gcc/stackleak_plugin.c
85761 @@ -0,0 +1,313 @@
85762 +/*
85763 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85764 + * Licensed under the GPL v2
85765 + *
85766 + * Note: the choice of the license means that the compilation process is
85767 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85768 + * but for the kernel it doesn't matter since it doesn't link against
85769 + * any of the gcc libraries
85770 + *
85771 + * gcc plugin to help implement various PaX features
85772 + *
85773 + * - track lowest stack pointer
85774 + *
85775 + * TODO:
85776 + * - initialize all local variables
85777 + *
85778 + * BUGS:
85779 + * - none known
85780 + */
85781 +#include "gcc-plugin.h"
85782 +#include "config.h"
85783 +#include "system.h"
85784 +#include "coretypes.h"
85785 +#include "tree.h"
85786 +#include "tree-pass.h"
85787 +#include "flags.h"
85788 +#include "intl.h"
85789 +#include "toplev.h"
85790 +#include "plugin.h"
85791 +//#include "expr.h" where are you...
85792 +#include "diagnostic.h"
85793 +#include "plugin-version.h"
85794 +#include "tm.h"
85795 +#include "function.h"
85796 +#include "basic-block.h"
85797 +#include "gimple.h"
85798 +#include "rtl.h"
85799 +#include "emit-rtl.h"
85800 +
85801 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85802 +
85803 +int plugin_is_GPL_compatible;
85804 +
85805 +static int track_frame_size = -1;
85806 +static const char track_function[] = "pax_track_stack";
85807 +static const char check_function[] = "pax_check_alloca";
85808 +static bool init_locals;
85809 +
85810 +static struct plugin_info stackleak_plugin_info = {
85811 + .version = "201203140940",
85812 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
85813 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
85814 +};
85815 +
85816 +static bool gate_stackleak_track_stack(void);
85817 +static unsigned int execute_stackleak_tree_instrument(void);
85818 +static unsigned int execute_stackleak_final(void);
85819 +
85820 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
85821 + .pass = {
85822 + .type = GIMPLE_PASS,
85823 + .name = "stackleak_tree_instrument",
85824 + .gate = gate_stackleak_track_stack,
85825 + .execute = execute_stackleak_tree_instrument,
85826 + .sub = NULL,
85827 + .next = NULL,
85828 + .static_pass_number = 0,
85829 + .tv_id = TV_NONE,
85830 + .properties_required = PROP_gimple_leh | PROP_cfg,
85831 + .properties_provided = 0,
85832 + .properties_destroyed = 0,
85833 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85834 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85835 + }
85836 +};
85837 +
85838 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
85839 + .pass = {
85840 + .type = RTL_PASS,
85841 + .name = "stackleak_final",
85842 + .gate = gate_stackleak_track_stack,
85843 + .execute = execute_stackleak_final,
85844 + .sub = NULL,
85845 + .next = NULL,
85846 + .static_pass_number = 0,
85847 + .tv_id = TV_NONE,
85848 + .properties_required = 0,
85849 + .properties_provided = 0,
85850 + .properties_destroyed = 0,
85851 + .todo_flags_start = 0,
85852 + .todo_flags_finish = TODO_dump_func
85853 + }
85854 +};
85855 +
85856 +static bool gate_stackleak_track_stack(void)
85857 +{
85858 + return track_frame_size >= 0;
85859 +}
85860 +
85861 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
85862 +{
85863 + gimple check_alloca;
85864 + tree fntype, fndecl, alloca_size;
85865 +
85866 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
85867 + fndecl = build_fn_decl(check_function, fntype);
85868 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85869 +
85870 + // insert call to void pax_check_alloca(unsigned long size)
85871 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
85872 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
85873 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
85874 +}
85875 +
85876 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
85877 +{
85878 + gimple track_stack;
85879 + tree fntype, fndecl;
85880 +
85881 + fntype = build_function_type_list(void_type_node, NULL_TREE);
85882 + fndecl = build_fn_decl(track_function, fntype);
85883 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85884 +
85885 + // insert call to void pax_track_stack(void)
85886 + track_stack = gimple_build_call(fndecl, 0);
85887 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
85888 +}
85889 +
85890 +#if BUILDING_GCC_VERSION == 4005
85891 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
85892 +{
85893 + tree fndecl;
85894 +
85895 + if (!is_gimple_call(stmt))
85896 + return false;
85897 + fndecl = gimple_call_fndecl(stmt);
85898 + if (!fndecl)
85899 + return false;
85900 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85901 + return false;
85902 +// print_node(stderr, "pax", fndecl, 4);
85903 + return DECL_FUNCTION_CODE(fndecl) == code;
85904 +}
85905 +#endif
85906 +
85907 +static bool is_alloca(gimple stmt)
85908 +{
85909 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85910 + return true;
85911 +
85912 +#if BUILDING_GCC_VERSION >= 4007
85913 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85914 + return true;
85915 +#endif
85916 +
85917 + return false;
85918 +}
85919 +
85920 +static unsigned int execute_stackleak_tree_instrument(void)
85921 +{
85922 + basic_block bb, entry_bb;
85923 + bool prologue_instrumented = false, is_leaf = true;
85924 +
85925 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85926 +
85927 + // 1. loop through BBs and GIMPLE statements
85928 + FOR_EACH_BB(bb) {
85929 + gimple_stmt_iterator gsi;
85930 +
85931 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85932 + gimple stmt;
85933 +
85934 + stmt = gsi_stmt(gsi);
85935 +
85936 + if (is_gimple_call(stmt))
85937 + is_leaf = false;
85938 +
85939 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85940 + if (!is_alloca(stmt))
85941 + continue;
85942 +
85943 + // 2. insert stack overflow check before each __builtin_alloca call
85944 + stackleak_check_alloca(&gsi);
85945 +
85946 + // 3. insert track call after each __builtin_alloca call
85947 + stackleak_add_instrumentation(&gsi);
85948 + if (bb == entry_bb)
85949 + prologue_instrumented = true;
85950 + }
85951 + }
85952 +
85953 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85954 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85955 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85956 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85957 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85958 + return 0;
85959 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85960 + return 0;
85961 +
85962 + // 4. insert track call at the beginning
85963 + if (!prologue_instrumented) {
85964 + gimple_stmt_iterator gsi;
85965 +
85966 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85967 + if (dom_info_available_p(CDI_DOMINATORS))
85968 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85969 + gsi = gsi_start_bb(bb);
85970 + stackleak_add_instrumentation(&gsi);
85971 + }
85972 +
85973 + return 0;
85974 +}
85975 +
85976 +static unsigned int execute_stackleak_final(void)
85977 +{
85978 + rtx insn;
85979 +
85980 + if (cfun->calls_alloca)
85981 + return 0;
85982 +
85983 + // keep calls only if function frame is big enough
85984 + if (get_frame_size() >= track_frame_size)
85985 + return 0;
85986 +
85987 + // 1. find pax_track_stack calls
85988 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85989 + // 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))
85990 + rtx body;
85991 +
85992 + if (!CALL_P(insn))
85993 + continue;
85994 + body = PATTERN(insn);
85995 + if (GET_CODE(body) != CALL)
85996 + continue;
85997 + body = XEXP(body, 0);
85998 + if (GET_CODE(body) != MEM)
85999 + continue;
86000 + body = XEXP(body, 0);
86001 + if (GET_CODE(body) != SYMBOL_REF)
86002 + continue;
86003 + if (strcmp(XSTR(body, 0), track_function))
86004 + continue;
86005 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86006 + // 2. delete call
86007 + insn = delete_insn_and_edges(insn);
86008 +#if BUILDING_GCC_VERSION >= 4007
86009 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86010 + insn = delete_insn_and_edges(insn);
86011 +#endif
86012 + }
86013 +
86014 +// print_simple_rtl(stderr, get_insns());
86015 +// print_rtl(stderr, get_insns());
86016 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86017 +
86018 + return 0;
86019 +}
86020 +
86021 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86022 +{
86023 + const char * const plugin_name = plugin_info->base_name;
86024 + const int argc = plugin_info->argc;
86025 + const struct plugin_argument * const argv = plugin_info->argv;
86026 + int i;
86027 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86028 + .pass = &stackleak_tree_instrument_pass.pass,
86029 +// .reference_pass_name = "tree_profile",
86030 + .reference_pass_name = "optimized",
86031 + .ref_pass_instance_number = 0,
86032 + .pos_op = PASS_POS_INSERT_BEFORE
86033 + };
86034 + struct register_pass_info stackleak_final_pass_info = {
86035 + .pass = &stackleak_final_rtl_opt_pass.pass,
86036 + .reference_pass_name = "final",
86037 + .ref_pass_instance_number = 0,
86038 + .pos_op = PASS_POS_INSERT_BEFORE
86039 + };
86040 +
86041 + if (!plugin_default_version_check(version, &gcc_version)) {
86042 + error(G_("incompatible gcc/plugin versions"));
86043 + return 1;
86044 + }
86045 +
86046 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86047 +
86048 + for (i = 0; i < argc; ++i) {
86049 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86050 + if (!argv[i].value) {
86051 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86052 + continue;
86053 + }
86054 + track_frame_size = atoi(argv[i].value);
86055 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86056 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86057 + continue;
86058 + }
86059 + if (!strcmp(argv[i].key, "initialize-locals")) {
86060 + if (argv[i].value) {
86061 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86062 + continue;
86063 + }
86064 + init_locals = true;
86065 + continue;
86066 + }
86067 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86068 + }
86069 +
86070 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86071 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86072 +
86073 + return 0;
86074 +}
86075 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
86076 index 6789d78..4afd019 100644
86077 --- a/tools/perf/util/include/asm/alternative-asm.h
86078 +++ b/tools/perf/util/include/asm/alternative-asm.h
86079 @@ -5,4 +5,7 @@
86080
86081 #define altinstruction_entry #
86082
86083 + .macro pax_force_retaddr rip=0, reload=0
86084 + .endm
86085 +
86086 #endif
86087 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86088 index af0f22f..9a7d479 100644
86089 --- a/usr/gen_init_cpio.c
86090 +++ b/usr/gen_init_cpio.c
86091 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
86092 int retval;
86093 int rc = -1;
86094 int namesize;
86095 - int i;
86096 + unsigned int i;
86097
86098 mode |= S_IFREG;
86099
86100 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
86101 *env_var = *expanded = '\0';
86102 strncat(env_var, start + 2, end - start - 2);
86103 strncat(expanded, new_location, start - new_location);
86104 - strncat(expanded, getenv(env_var), PATH_MAX);
86105 - strncat(expanded, end + 1, PATH_MAX);
86106 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86107 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86108 strncpy(new_location, expanded, PATH_MAX);
86109 + new_location[PATH_MAX] = 0;
86110 } else
86111 break;
86112 }
86113 diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
86114 index a457d21..fec1723 100644
86115 --- a/virt/kvm/iommu.c
86116 +++ b/virt/kvm/iommu.c
86117 @@ -310,6 +310,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
86118 }
86119 }
86120
86121 +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
86122 +{
86123 + kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages);
86124 +}
86125 +
86126 static int kvm_iommu_unmap_memslots(struct kvm *kvm)
86127 {
86128 int idx;
86129 @@ -320,7 +325,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
86130 slots = kvm_memslots(kvm);
86131
86132 kvm_for_each_memslot(memslot, slots)
86133 - kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages);
86134 + kvm_iommu_unmap_pages(kvm, memslot);
86135
86136 srcu_read_unlock(&kvm->srcu, idx);
86137
86138 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86139 index a91f980..527711d 100644
86140 --- a/virt/kvm/kvm_main.c
86141 +++ b/virt/kvm/kvm_main.c
86142 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86143
86144 static cpumask_var_t cpus_hardware_enabled;
86145 static int kvm_usage_count = 0;
86146 -static atomic_t hardware_enable_failed;
86147 +static atomic_unchecked_t hardware_enable_failed;
86148
86149 struct kmem_cache *kvm_vcpu_cache;
86150 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86151 @@ -873,12 +873,13 @@ skip_lpage:
86152 if (r)
86153 goto out_free;
86154
86155 - /* map the pages in iommu page table */
86156 + /* map/unmap the pages in iommu page table */
86157 if (npages) {
86158 r = kvm_iommu_map_pages(kvm, &new);
86159 if (r)
86160 goto out_free;
86161 - }
86162 + } else
86163 + kvm_iommu_unmap_pages(kvm, &old);
86164
86165 r = -ENOMEM;
86166 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
86167 @@ -2312,7 +2313,7 @@ static void hardware_enable_nolock(void *junk)
86168
86169 if (r) {
86170 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86171 - atomic_inc(&hardware_enable_failed);
86172 + atomic_inc_unchecked(&hardware_enable_failed);
86173 printk(KERN_INFO "kvm: enabling virtualization on "
86174 "CPU%d failed\n", cpu);
86175 }
86176 @@ -2366,10 +2367,10 @@ static int hardware_enable_all(void)
86177
86178 kvm_usage_count++;
86179 if (kvm_usage_count == 1) {
86180 - atomic_set(&hardware_enable_failed, 0);
86181 + atomic_set_unchecked(&hardware_enable_failed, 0);
86182 on_each_cpu(hardware_enable_nolock, NULL, 1);
86183
86184 - if (atomic_read(&hardware_enable_failed)) {
86185 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86186 hardware_disable_all_nolock();
86187 r = -EBUSY;
86188 }
86189 @@ -2732,7 +2733,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86190 kvm_arch_vcpu_put(vcpu);
86191 }
86192
86193 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86194 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86195 struct module *module)
86196 {
86197 int r;
86198 @@ -2795,7 +2796,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86199 if (!vcpu_align)
86200 vcpu_align = __alignof__(struct kvm_vcpu);
86201 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86202 - 0, NULL);
86203 + SLAB_USERCOPY, NULL);
86204 if (!kvm_vcpu_cache) {
86205 r = -ENOMEM;
86206 goto out_free_3;
86207 @@ -2805,9 +2806,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86208 if (r)
86209 goto out_free;
86210
86211 - kvm_chardev_ops.owner = module;
86212 - kvm_vm_fops.owner = module;
86213 - kvm_vcpu_fops.owner = module;
86214 + pax_open_kernel();
86215 + *(void **)&kvm_chardev_ops.owner = module;
86216 + *(void **)&kvm_vm_fops.owner = module;
86217 + *(void **)&kvm_vcpu_fops.owner = module;
86218 + pax_close_kernel();
86219
86220 r = misc_register(&kvm_dev);
86221 if (r) {